File tree Expand file tree Collapse file tree 3 files changed +33
-3
lines changed
Expand file tree Collapse file tree 3 files changed +33
-3
lines changed Original file line number Diff line number Diff line change @@ -20,6 +20,14 @@ export function hasExportModifier(node: ts.Node): boolean {
2020 ) ;
2121}
2222
23+ export function shouldBeExported ( node : ts . Node ) : boolean {
24+ if ( hasExportModifier ( node ) ) {
25+ // Don't export if we're inside a namespace (module declaration)
26+ return ts . findAncestor ( node , ts . isModuleDeclaration ) === undefined ;
27+ }
28+ return false ;
29+ }
30+
2331export const createDefaultExportStringLiteral = ( original ?: ts . Node ) : lua . StringLiteral =>
2432 lua . createStringLiteral ( "default" , original ) ;
2533
Original file line number Diff line number Diff line change 55 createDefaultExportExpression ,
66 createExportedIdentifier ,
77 hasDefaultExportModifier ,
8- hasExportModifier ,
98 isSymbolExported ,
9+ shouldBeExported ,
1010} from "../../utils/export" ;
1111import { createSelfIdentifier } from "../../utils/lua-ast" ;
1212import { createSafeName , isUnsafeName } from "../../utils/safe-names" ;
@@ -214,7 +214,7 @@ function transformClassLikeDeclaration(
214214 const decoratingStatement = lua . createAssignmentStatement ( localClassName , decoratingExpression ) ;
215215 result . push ( decoratingStatement ) ;
216216
217- if ( hasExportModifier ( classDeclaration ) ) {
217+ if ( shouldBeExported ( classDeclaration ) ) {
218218 const exportExpression = hasDefaultExportModifier ( classDeclaration )
219219 ? createDefaultExportExpression ( classDeclaration )
220220 : createExportedIdentifier ( context , className ) ;
Original file line number Diff line number Diff line change @@ -138,7 +138,7 @@ test("Exported class decorator", () => {
138138} ) ;
139139
140140// https://github.com/TypeScriptToLua/TypeScriptToLua/issues/1149
141- test ( "exported class with decorator" , ( ) => {
141+ test ( "exported class with decorator (#1149) " , ( ) => {
142142 util . testModule `
143143 import { MyClass } from "./other";
144144 const inst = new MyClass();
@@ -164,6 +164,28 @@ test("exported class with decorator", () => {
164164 . expectToEqual ( { result : "overridden" } ) ;
165165} ) ;
166166
167+ // https://github.com/TypeScriptToLua/TypeScriptToLua/issues/1634
168+ test ( "namespaced exported class with decorator (#1634)" , ( ) => {
169+ util . testModule `
170+ function myDecorator(target: {new(): any}, context: ClassDecoratorContext) {
171+ return class extends target {
172+ foo() {
173+ return "overridden";
174+ }
175+ }
176+ }
177+
178+ namespace ns {
179+ @myDecorator
180+ export class MyClass {
181+ foo() {
182+ return "foo";
183+ }
184+ }
185+ }
186+ ` . expectNoExecutionError ( ) ;
187+ } ) ;
188+
167189test ( "default exported class with decorator" , ( ) => {
168190 util . testModule `
169191 import MyClass from "./other";
You can’t perform that action at this time.
0 commit comments