File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -74,6 +74,32 @@ namespace ts {
7474 }
7575 } ) . outputText ;
7676 } ) ;
77+
78+ testBaseline ( "synthesizedNamespace" , ( ) => {
79+ return ts . transpileModule ( `namespace Reflect { const x = 1; }` , {
80+ transformers : {
81+ before : [ forceSyntheticModuleDeclaration ] ,
82+ } ,
83+ compilerOptions : {
84+ newLine : NewLineKind . CarriageReturnLineFeed ,
85+ }
86+ } ) . outputText ;
87+
88+ function forceSyntheticModuleDeclaration ( context : ts . TransformationContext ) {
89+ return ( sourceFile : ts . SourceFile ) : ts . SourceFile => {
90+ return visitNode ( sourceFile ) ;
91+
92+ function visitNode < T extends ts . Node > ( node : T ) : T {
93+ if ( node . kind === ts . SyntaxKind . ModuleBlock ) {
94+ const block = node as T & ts . ModuleBlock ;
95+ const statements = ts . createNodeArray ( [ ...block . statements ] ) ;
96+ return ts . updateModuleBlock ( block , statements ) as typeof block ;
97+ }
98+ return ts . visitEachChild ( node , visitNode , context ) ;
99+ }
100+ } ;
101+ }
102+ } )
77103 } ) ;
78104}
79105
You can’t perform that action at this time.
0 commit comments