Skip to content

Commit c557131

Browse files
kriszypmhegazy
authored andcommitted
Ensure that we continue recursing into TS transforms (#19650)
* Ensure that we continue recursing into TS transforms when avoiding export elliding for transformed nodes, fix #19649 * Use more precise fix
1 parent 1a7a587 commit c557131

File tree

3 files changed

+31
-0
lines changed

3 files changed

+31
-0
lines changed

src/compiler/transformers/ts.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,13 @@ namespace ts {
225225
if (parsed !== node) {
226226
// If the node has been transformed by a `before` transformer, perform no ellision on it
227227
// As the type information we would attempt to lookup to perform ellision is potentially unavailable for the synthesized nodes
228+
// We do not reuse `visitorWorker`, as the ellidable statement syntax kinds are technically unrecognized by the switch-case in `visitTypeScript`,
229+
// and will trigger debug failures when debug verbosity is turned up
230+
if (node.transformFlags & TransformFlags.ContainsTypeScript) {
231+
// This node contains TypeScript, so we should visit its children.
232+
return visitEachChild(node, visitor, context);
233+
}
234+
// Otherwise, we can just return the node
228235
return node;
229236
}
230237
switch (node.kind) {

src/harness/unittests/transform.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,15 @@ namespace ts {
2020
};
2121
return (file: ts.SourceFile) => file;
2222
}
23+
function replaceNumberWith2(context: ts.TransformationContext) {
24+
function visitor(node: Node): Node {
25+
if (isNumericLiteral(node)) {
26+
return createNumericLiteral("2");
27+
}
28+
return visitEachChild(node, visitor, context);
29+
}
30+
return (file: ts.SourceFile) => visitNode(file, visitor);
31+
}
2332

2433
function replaceIdentifiersNamedOldNameWithNewName(context: ts.TransformationContext) {
2534
const previousOnSubstituteNode = context.onSubstituteNode;
@@ -101,6 +110,20 @@ namespace ts {
101110
}).outputText;
102111
});
103112

113+
testBaseline("transformTypesInExportDefault", () => {
114+
return ts.transpileModule(`
115+
export default (foo: string) => { return 1; }
116+
`, {
117+
transformers: {
118+
before: [replaceNumberWith2],
119+
},
120+
compilerOptions: {
121+
target: ts.ScriptTarget.ESNext,
122+
newLine: NewLineKind.CarriageReturnLineFeed,
123+
}
124+
}).outputText;
125+
});
126+
104127
testBaseline("synthesizedClassAndNamespaceCombination", () => {
105128
return ts.transpileModule("", {
106129
transformers: {
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export default (foo) => { return 2; };

0 commit comments

Comments
 (0)