mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-24 20:44:53 -05:00
Move synthetic comments from arrow body expressions to return statement (#24135)
This commit is contained in:
@@ -270,6 +270,35 @@ namespace ts {
|
||||
program.emit(program.getSourceFiles()[1], (p, s, bom) => host.writeFile(p, s, bom), /*cancellationToken*/ undefined, /*onlyDts*/ true, opts.transformers);
|
||||
return fs.readFileSync("/.src/index.d.ts").toString();
|
||||
}
|
||||
|
||||
// https://github.com/Microsoft/TypeScript/issues/24096
|
||||
testBaseline("transformAddCommentToArrowReturnValue", () => {
|
||||
return transpileModule(`const foo = () =>
|
||||
void 0
|
||||
`, {
|
||||
transformers: {
|
||||
before: [addSyntheticComment],
|
||||
},
|
||||
compilerOptions: {
|
||||
target: ScriptTarget.ES5,
|
||||
newLine: NewLineKind.CarriageReturnLineFeed,
|
||||
}
|
||||
}).outputText;
|
||||
|
||||
function addSyntheticComment(context: TransformationContext) {
|
||||
return (sourceFile: SourceFile): SourceFile => {
|
||||
return visitNode(sourceFile, rootTransform, isSourceFile);
|
||||
};
|
||||
function rootTransform<T extends Node>(node: T): VisitResult<T> {
|
||||
if (isVoidExpression(node)) {
|
||||
setEmitFlags(node, EmitFlags.NoLeadingComments);
|
||||
setSyntheticLeadingComments(node, [{ kind: SyntaxKind.SingleLineCommentTrivia, text: "// comment!", pos: -1, end: -1, hasTrailingNewLine: true }]);
|
||||
return node;
|
||||
}
|
||||
return visitEachChild(node, rootTransform, context);
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user