Skip to content

Commit 2535f39

Browse files
tomblindPerryvw
authored andcommitted
using full form of 'super' call when base is an exported identfier (#637)
1 parent 3c41892 commit 2535f39

File tree

2 files changed

+29
-4
lines changed

2 files changed

+29
-4
lines changed

src/LuaTransformer.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3568,11 +3568,15 @@ export class LuaTransformer {
35683568
}
35693569

35703570
const extendsExpression = typeNode.expression;
3571-
let baseClassName: tstl.AssignmentLeftHandSideExpression;
3571+
let baseClassName: tstl.AssignmentLeftHandSideExpression | undefined;
35723572
if (ts.isIdentifier(extendsExpression)) {
3573-
// Use "baseClassName" if base is a simple identifier
3574-
baseClassName = this.transformIdentifier(extendsExpression);
3575-
} else {
3573+
const symbol = this.checker.getSymbolAtLocation(extendsExpression);
3574+
if (symbol && !this.isSymbolExported(symbol)) {
3575+
// Use "baseClassName" if base is a simple identifier
3576+
baseClassName = this.transformIdentifier(extendsExpression);
3577+
}
3578+
}
3579+
if (!baseClassName) {
35763580
if (classDeclaration.name === undefined) {
35773581
throw TSTLErrors.MissingClassName(expression);
35783582
}

test/unit/class.spec.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,27 @@ test("SubclassConstructor", () => {
198198
expect(result).toBe(11);
199199
});
200200

201+
test("Subclass constructor across merged namespace", () => {
202+
const tsHeader = `
203+
namespace NS {
204+
export class Super {
205+
prop: string;
206+
constructor() {
207+
this.prop = "foo";
208+
}
209+
}
210+
}
211+
namespace NS {
212+
export class Sub extends Super {
213+
constructor() {
214+
super();
215+
}
216+
}
217+
}`;
218+
219+
expect(util.transpileAndExecute("return (new NS.Sub()).prop", undefined, undefined, tsHeader)).toBe("foo");
220+
});
221+
201222
test("classSuper", () => {
202223
const result = util.transpileAndExecute(
203224
`class a {

0 commit comments

Comments
 (0)