Skip to content

Commit b44ac91

Browse files
Added failing test for a before-transform that indirectly replaces a namespace declaration.
1 parent 8f7a582 commit b44ac91

1 file changed

Lines changed: 26 additions & 0 deletions

File tree

src/harness/unittests/transform.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff 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

0 commit comments

Comments
 (0)