-
Notifications
You must be signed in to change notification settings - Fork 13.1k
Closed
Labels
BugA bug in TypeScriptA bug in TypeScriptDomain: APIRelates to the public API for TypeScriptRelates to the public API for TypeScriptFixedA PR has been merged for this issueA PR has been merged for this issue
Milestone
Description
I found this bug when I parse some typescript code into AST (by sf = ts.createSourceFile ) and then ts.createPrinter().printFile(sf) back to typescript (not js) code again.
What's the Problem
You can reproduce this bug online with npm runkit.
Chrome is recommended.
Paste these code and click "Run".
var ts = require("typescript")
var s = "let greeting = `Hi ${name}, how are you?`";
var sf = ts.createSourceFile('', s, ts.ScriptTarget.ES2017, true);
console.info(ts.createPrinter().printFile(sf));
The output is supposed to be the same as s. However, you will see:
"let greeting = \"Hi \"name\", how are you?\";\n"
The printed ts code for the TemplateExpression AST node is completed messed up .
Probably Helpful Info
I did my little investigation in typescript.js.
Finally, I reached the function emitLiteral where a TemplateHead node (such as that of "Hi ") is converted into a string text = getLiteralTextOfNode(node) with double quotes.
I am not sure what to edit to fix this bug. So I stopped and post this issue.
Hope someone kindly fix it.
arosequist
Metadata
Metadata
Assignees
Labels
BugA bug in TypeScriptA bug in TypeScriptDomain: APIRelates to the public API for TypeScriptRelates to the public API for TypeScriptFixedA PR has been merged for this issueA PR has been merged for this issue