Skip to content

Commit b51e826

Browse files
authored
fixed instanceof on exported classes (#394)
1 parent 5140ca8 commit b51e826

File tree

4 files changed

+16
-3
lines changed

4 files changed

+16
-3
lines changed

src/LuaTransformer.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -531,7 +531,7 @@ export class LuaTransformer {
531531
);
532532
const assignClassPrototypeConstructor = tstl.createAssignmentStatement(
533533
classPrototypeConstructor,
534-
className,
534+
createClassNameWithExport(),
535535
statement
536536
);
537537
result.push(assignClassPrototypeConstructor);

test/translation/lua/modulesClassExport.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ exports.TestClass = exports.TestClass or {};
33
exports.TestClass.__index = exports.TestClass;
44
exports.TestClass.prototype = exports.TestClass.prototype or {};
55
exports.TestClass.prototype.__index = exports.TestClass.prototype;
6-
exports.TestClass.prototype.constructor = TestClass;
6+
exports.TestClass.prototype.constructor = exports.TestClass;
77
exports.TestClass.new = function(...)
88
local self = setmetatable({}, exports.TestClass.prototype);
99
self:____constructor(...);

test/translation/lua/modulesClassWithMemberExport.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ exports.TestClass = exports.TestClass or {};
33
exports.TestClass.__index = exports.TestClass;
44
exports.TestClass.prototype = exports.TestClass.prototype or {};
55
exports.TestClass.prototype.__index = exports.TestClass.prototype;
6-
exports.TestClass.prototype.constructor = TestClass;
6+
exports.TestClass.prototype.constructor = exports.TestClass;
77
exports.TestClass.new = function(...)
88
local self = setmetatable({}, exports.TestClass.prototype);
99
self:____constructor(...);

test/unit/typechecking.spec.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,4 +133,17 @@ export class TypeCheckingTests {
133133
"Cannot use instanceof on classes with decorator '@extension' or '@metaExtension'."
134134
);
135135
}
136+
137+
@Test("instanceof export")
138+
public instanceOfExport(): void
139+
{
140+
const result = util.transpileExecuteAndReturnExport(
141+
`export class myClass {}
142+
let inst = new myClass();
143+
export const result = inst instanceof myClass;`,
144+
"result"
145+
);
146+
147+
Expect(result).toBeTruthy();
148+
}
136149
}

0 commit comments

Comments
 (0)