-
Notifications
You must be signed in to change notification settings - Fork 13k
Closed
Labels
BugA bug in TypeScriptA bug in TypeScriptFixedA PR has been merged for this issueA PR has been merged for this issueGood First IssueWell scoped, documented and has the green lightWell scoped, documented and has the green lightHelp WantedYou can do thisYou can do this
Milestone
Description
TypeScript Version: 3.9.x, 4.0.x-dev
Search Terms: template string emit
Code
From ~/tests/cases/conformance/es2018/invalidTaggedTemplateEscapeSequences.ts
:
const x = tag`\u{hello} ${ 100 } \xtraordinary ${ 200 } wonderful ${ 300 } \uworld`;
Expected behavior:
ES5/ES3 emit:
const x = tag(__makeTemplateObject([void 0, void 0, " wonderful ", void 0], ["\\u{hello} ", " \\xtraordinary ", " wonderful ", " \\uworld"]), 100, 200, 300);
Actual behavior:
ES5/ES3 emit:
const x = tag(__makeTemplateObject([undefined, undefined, " wonderful ", undefined], ["\\u{hello} ", " \\xtraordinary ", " wonderful ", " \\uworld"]), 100, 200, 300);
In ES5, undefined
is an identifier and not a keyword and can be redeclared. In ES3, undefined
isn't declared. In general we emit void 0
in these cases.
This can be easily addressed by changing createTemplateCooked
in ~/src/compiler/transformers/taggedTemplate.ts
to return createVoidZero()
instead of createIdentifier("undefined")
when a template contains an invalid escape sequence..
Playground Link: link
Metadata
Metadata
Assignees
Labels
BugA bug in TypeScriptA bug in TypeScriptFixedA PR has been merged for this issueA PR has been merged for this issueGood First IssueWell scoped, documented and has the green lightWell scoped, documented and has the green lightHelp WantedYou can do thisYou can do this