@@ -78,28 +78,43 @@ namespace ts {
7878 testBaseline ( "synthesizedNamespace" , ( ) => {
7979 return ts . transpileModule ( `namespace Reflect { const x = 1; }` , {
8080 transformers : {
81- before : [ forceSyntheticModuleDeclaration ] ,
81+ before : [ forceNamespaceRewrite ] ,
8282 } ,
8383 compilerOptions : {
8484 newLine : NewLineKind . CarriageReturnLineFeed ,
8585 }
8686 } ) . outputText ;
87+ } ) ;
8788
88- function forceSyntheticModuleDeclaration ( context : ts . TransformationContext ) {
89- return ( sourceFile : ts . SourceFile ) : ts . SourceFile => {
90- return visitNode ( sourceFile ) ;
89+ testBaseline ( "synthesizedNamespaceFollowingClass" , ( ) => {
90+ return ts . transpileModule ( `
91+ class C { foo = 10; static bar = 20 }
92+ namespace C { export let x = 10; }
93+ ` , {
94+ transformers : {
95+ before : [ forceNamespaceRewrite ] ,
96+ } ,
97+ compilerOptions : {
98+ target : ts . ScriptTarget . ESNext ,
99+ newLine : NewLineKind . CarriageReturnLineFeed ,
100+ }
101+ } ) . outputText ;
102+ } ) ;
103+
104+ function forceNamespaceRewrite ( context : ts . TransformationContext ) {
105+ return ( sourceFile : ts . SourceFile ) : ts . SourceFile => {
106+ return visitNode ( sourceFile ) ;
91107
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 ) ;
108+ function visitNode < T extends ts . Node > ( node : T ) : T {
109+ if ( node . kind === ts . SyntaxKind . ModuleBlock ) {
110+ const block = node as T & ts . ModuleBlock ;
111+ const statements = ts . createNodeArray ( [ ...block . statements ] ) ;
112+ return ts . updateModuleBlock ( block , statements ) as typeof block ;
99113 }
100- } ;
101- }
102- } ) ;
114+ return ts . visitEachChild ( node , visitNode , context ) ;
115+ }
116+ } ;
117+ }
103118 } ) ;
104119}
105120
0 commit comments