Skip to content

Commit 6ef27a4

Browse files
Added test for class/namespace merging with an ESNext target.
1 parent 22e0d9f commit 6ef27a4

1 file changed

Lines changed: 29 additions & 14 deletions

File tree

src/harness/unittests/transform.ts

Lines changed: 29 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)