Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions src/LuaTransformer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3568,11 +3568,15 @@ export class LuaTransformer {
}

const extendsExpression = typeNode.expression;
let baseClassName: tstl.AssignmentLeftHandSideExpression;
let baseClassName: tstl.AssignmentLeftHandSideExpression | undefined;
if (ts.isIdentifier(extendsExpression)) {
// Use "baseClassName" if base is a simple identifier
baseClassName = this.transformIdentifier(extendsExpression);
} else {
const symbol = this.checker.getSymbolAtLocation(extendsExpression);
if (symbol && !this.isSymbolExported(symbol)) {
// Use "baseClassName" if base is a simple identifier
baseClassName = this.transformIdentifier(extendsExpression);
}
}
if (!baseClassName) {
if (classDeclaration.name === undefined) {
throw TSTLErrors.MissingClassName(expression);
}
Expand Down
21 changes: 21 additions & 0 deletions test/unit/class.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,27 @@ test("SubclassConstructor", () => {
expect(result).toBe(11);
});

test("Subclass constructor across merged namespace", () => {
const tsHeader = `
namespace NS {
export class Super {
prop: string;
constructor() {
this.prop = "foo";
}
}
}
namespace NS {
export class Sub extends Super {
constructor() {
super();
}
}
}`;

expect(util.transpileAndExecute("return (new NS.Sub()).prop", undefined, undefined, tsHeader)).toBe("foo");
});

test("classSuper", () => {
const result = util.transpileAndExecute(
`class a {
Expand Down