Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit b44ac91

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

1 file changed

+26Lines changed: 26 additions & 0 deletions

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎src/harness/unittests/transform.ts‎

Copy file name to clipboardExpand all lines: src/harness/unittests/transform.ts
+26Lines 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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.