Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changed template strings to emit void 0 instead of undefined (#38430) #38439

Merged
merged 1 commit into from
May 12, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/compiler/transformers/taggedTemplate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ namespace ts {
}

function createTemplateCooked(template: TemplateHead | TemplateMiddle | TemplateTail | NoSubstitutionTemplateLiteral) {
return template.templateFlags ? createIdentifier("undefined") : createLiteral(template.text);
return template.templateFlags ? createVoidZero() : createLiteral(template.text);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,20 +35,20 @@ function tag(str, ...args) {
}
const a = tag `123`;
const b = tag `123 ${100}`;
const x = tag(__makeTemplateObject([undefined, undefined, " wonderful ", undefined], ["\\u{hello} ", " \\xtraordinary ", " wonderful ", " \\uworld"]), 100, 200, 300);
const x = tag(__makeTemplateObject([void 0, void 0, " wonderful ", void 0], ["\\u{hello} ", " \\xtraordinary ", " wonderful ", " \\uworld"]), 100, 200, 300);
const y = `\u{hello} ${100} \xtraordinary ${200} wonderful ${300} \uworld`; // should error with NoSubstitutionTemplate
const z = tag(__makeTemplateObject([undefined], ["\\u{hello} \\xtraordinary wonderful \\uworld"])); // should work with Tagged NoSubstitutionTemplate
const z = tag(__makeTemplateObject([void 0], ["\\u{hello} \\xtraordinary wonderful \\uworld"])); // should work with Tagged NoSubstitutionTemplate
const a1 = tag `${100}\0`; // \0
const a2 = tag(__makeTemplateObject(["", undefined], ["", "\\00"]), 100); // \\00
const a3 = tag(__makeTemplateObject(["", undefined], ["", "\\u"]), 100); // \\u
const a4 = tag(__makeTemplateObject(["", undefined], ["", "\\u0"]), 100); // \\u0
const a5 = tag(__makeTemplateObject(["", undefined], ["", "\\u00"]), 100); // \\u00
const a6 = tag(__makeTemplateObject(["", undefined], ["", "\\u000"]), 100); // \\u000
const a2 = tag(__makeTemplateObject(["", void 0], ["", "\\00"]), 100); // \\00
const a3 = tag(__makeTemplateObject(["", void 0], ["", "\\u"]), 100); // \\u
const a4 = tag(__makeTemplateObject(["", void 0], ["", "\\u0"]), 100); // \\u0
const a5 = tag(__makeTemplateObject(["", void 0], ["", "\\u00"]), 100); // \\u00
const a6 = tag(__makeTemplateObject(["", void 0], ["", "\\u000"]), 100); // \\u000
const a7 = tag `${100}\u0000`; // \u0000
const a8 = tag(__makeTemplateObject(["", undefined], ["", "\\u{"]), 100); // \\u{
const a8 = tag(__makeTemplateObject(["", void 0], ["", "\\u{"]), 100); // \\u{
const a9 = tag `${100}\u{10FFFF}`; // \\u{10FFFF
const a10 = tag(__makeTemplateObject(["", undefined], ["", "\\u{1f622"]), 100); // \\u{1f622
const a10 = tag(__makeTemplateObject(["", void 0], ["", "\\u{1f622"]), 100); // \\u{1f622
const a11 = tag `${100}\u{1f622}`; // \u{1f622}
const a12 = tag(__makeTemplateObject(["", undefined], ["", "\\x"]), 100); // \\x
const a13 = tag(__makeTemplateObject(["", undefined], ["", "\\x0"]), 100); // \\x0
const a12 = tag(__makeTemplateObject(["", void 0], ["", "\\x"]), 100); // \\x
const a13 = tag(__makeTemplateObject(["", void 0], ["", "\\x0"]), 100); // \\x0
const a14 = tag `${100}\x00`; // \x00
Original file line number Diff line number Diff line change
Expand Up @@ -39,20 +39,20 @@ function tag(str) {
}
var a = tag(__makeTemplateObject(["123"], ["123"]));
var b = tag(__makeTemplateObject(["123 ", ""], ["123 ", ""]), 100);
var x = tag(__makeTemplateObject([undefined, undefined, " wonderful ", undefined], ["\\u{hello} ", " \\xtraordinary ", " wonderful ", " \\uworld"]), 100, 200, 300);
var x = tag(__makeTemplateObject([void 0, void 0, " wonderful ", void 0], ["\\u{hello} ", " \\xtraordinary ", " wonderful ", " \\uworld"]), 100, 200, 300);
var y = "hello} " + 100 + " traordinary " + 200 + " wonderful " + 300 + " world"; // should error with NoSubstitutionTemplate
var z = tag(__makeTemplateObject([undefined], ["\\u{hello} \\xtraordinary wonderful \\uworld"])); // should work with Tagged NoSubstitutionTemplate
var z = tag(__makeTemplateObject([void 0], ["\\u{hello} \\xtraordinary wonderful \\uworld"])); // should work with Tagged NoSubstitutionTemplate
var a1 = tag(__makeTemplateObject(["", "\0"], ["", "\\0"]), 100); // \0
var a2 = tag(__makeTemplateObject(["", undefined], ["", "\\00"]), 100); // \\00
var a3 = tag(__makeTemplateObject(["", undefined], ["", "\\u"]), 100); // \\u
var a4 = tag(__makeTemplateObject(["", undefined], ["", "\\u0"]), 100); // \\u0
var a5 = tag(__makeTemplateObject(["", undefined], ["", "\\u00"]), 100); // \\u00
var a6 = tag(__makeTemplateObject(["", undefined], ["", "\\u000"]), 100); // \\u000
var a2 = tag(__makeTemplateObject(["", void 0], ["", "\\00"]), 100); // \\00
var a3 = tag(__makeTemplateObject(["", void 0], ["", "\\u"]), 100); // \\u
var a4 = tag(__makeTemplateObject(["", void 0], ["", "\\u0"]), 100); // \\u0
var a5 = tag(__makeTemplateObject(["", void 0], ["", "\\u00"]), 100); // \\u00
var a6 = tag(__makeTemplateObject(["", void 0], ["", "\\u000"]), 100); // \\u000
var a7 = tag(__makeTemplateObject(["", "\0"], ["", "\\u0000"]), 100); // \u0000
var a8 = tag(__makeTemplateObject(["", undefined], ["", "\\u{"]), 100); // \\u{
var a8 = tag(__makeTemplateObject(["", void 0], ["", "\\u{"]), 100); // \\u{
var a9 = tag(__makeTemplateObject(["", "\uDBFF\uDFFF"], ["", "\\u{10FFFF}"]), 100); // \\u{10FFFF
var a10 = tag(__makeTemplateObject(["", undefined], ["", "\\u{1f622"]), 100); // \\u{1f622
var a10 = tag(__makeTemplateObject(["", void 0], ["", "\\u{1f622"]), 100); // \\u{1f622
var a11 = tag(__makeTemplateObject(["", "\uD83D\uDE22"], ["", "\\u{1f622}"]), 100); // \u{1f622}
var a12 = tag(__makeTemplateObject(["", undefined], ["", "\\x"]), 100); // \\x
var a13 = tag(__makeTemplateObject(["", undefined], ["", "\\x0"]), 100); // \\x0
var a12 = tag(__makeTemplateObject(["", void 0], ["", "\\x"]), 100); // \\x
var a13 = tag(__makeTemplateObject(["", void 0], ["", "\\x0"]), 100); // \\x0
var a14 = tag(__makeTemplateObject(["", "\0"], ["", "\\x00"]), 100); // \x00
70 changes: 35 additions & 35 deletions tests/baselines/reference/invalidTaggedTemplateEscapeSequences.js
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
//// [invalidTaggedTemplateEscapeSequences.ts]
function tag (str: any, ...args: any[]): any {
return str
}

const a = tag`123`
const b = tag`123 ${100}`
const x = tag`\u{hello} ${ 100 } \xtraordinary ${ 200 } wonderful ${ 300 } \uworld`;
const y = `\u{hello} ${ 100 } \xtraordinary ${ 200 } wonderful ${ 300 } \uworld`; // should error with NoSubstitutionTemplate
const z = tag`\u{hello} \xtraordinary wonderful \uworld` // should work with Tagged NoSubstitutionTemplate

const a1 = tag`${ 100 }\0` // \0
const a2 = tag`${ 100 }\00` // \\00
const a3 = tag`${ 100 }\u` // \\u
const a4 = tag`${ 100 }\u0` // \\u0
const a5 = tag`${ 100 }\u00` // \\u00
const a6 = tag`${ 100 }\u000` // \\u000
const a7 = tag`${ 100 }\u0000` // \u0000
const a8 = tag`${ 100 }\u{` // \\u{
const a9 = tag`${ 100 }\u{10FFFF}` // \\u{10FFFF
const a10 = tag`${ 100 }\u{1f622` // \\u{1f622
const a11 = tag`${ 100 }\u{1f622}` // \u{1f622}
const a12 = tag`${ 100 }\x` // \\x
const a13 = tag`${ 100 }\x0` // \\x0
const a14 = tag`${ 100 }\x00` // \x00
function tag (str: any, ...args: any[]): any {
return str
}
const a = tag`123`
const b = tag`123 ${100}`
const x = tag`\u{hello} ${ 100 } \xtraordinary ${ 200 } wonderful ${ 300 } \uworld`;
const y = `\u{hello} ${ 100 } \xtraordinary ${ 200 } wonderful ${ 300 } \uworld`; // should error with NoSubstitutionTemplate
const z = tag`\u{hello} \xtraordinary wonderful \uworld` // should work with Tagged NoSubstitutionTemplate
const a1 = tag`${ 100 }\0` // \0
const a2 = tag`${ 100 }\00` // \\00
const a3 = tag`${ 100 }\u` // \\u
const a4 = tag`${ 100 }\u0` // \\u0
const a5 = tag`${ 100 }\u00` // \\u00
const a6 = tag`${ 100 }\u000` // \\u000
const a7 = tag`${ 100 }\u0000` // \u0000
const a8 = tag`${ 100 }\u{` // \\u{
const a9 = tag`${ 100 }\u{10FFFF}` // \\u{10FFFF
const a10 = tag`${ 100 }\u{1f622` // \\u{1f622
const a11 = tag`${ 100 }\u{1f622}` // \u{1f622}
const a12 = tag`${ 100 }\x` // \\x
const a13 = tag`${ 100 }\x0` // \\x0
const a14 = tag`${ 100 }\x00` // \x00


//// [invalidTaggedTemplateEscapeSequences.js]
Expand All @@ -39,20 +39,20 @@ function tag(str) {
}
var a = tag(__makeTemplateObject(["123"], ["123"]));
var b = tag(__makeTemplateObject(["123 ", ""], ["123 ", ""]), 100);
var x = tag(__makeTemplateObject([undefined, undefined, " wonderful ", undefined], ["\\u{hello} ", " \\xtraordinary ", " wonderful ", " \\uworld"]), 100, 200, 300);
var x = tag(__makeTemplateObject([void 0, void 0, " wonderful ", void 0], ["\\u{hello} ", " \\xtraordinary ", " wonderful ", " \\uworld"]), 100, 200, 300);
var y = "hello} " + 100 + " traordinary " + 200 + " wonderful " + 300 + " world"; // should error with NoSubstitutionTemplate
var z = tag(__makeTemplateObject([undefined], ["\\u{hello} \\xtraordinary wonderful \\uworld"])); // should work with Tagged NoSubstitutionTemplate
var z = tag(__makeTemplateObject([void 0], ["\\u{hello} \\xtraordinary wonderful \\uworld"])); // should work with Tagged NoSubstitutionTemplate
var a1 = tag(__makeTemplateObject(["", "\0"], ["", "\\0"]), 100); // \0
var a2 = tag(__makeTemplateObject(["", undefined], ["", "\\00"]), 100); // \\00
var a3 = tag(__makeTemplateObject(["", undefined], ["", "\\u"]), 100); // \\u
var a4 = tag(__makeTemplateObject(["", undefined], ["", "\\u0"]), 100); // \\u0
var a5 = tag(__makeTemplateObject(["", undefined], ["", "\\u00"]), 100); // \\u00
var a6 = tag(__makeTemplateObject(["", undefined], ["", "\\u000"]), 100); // \\u000
var a2 = tag(__makeTemplateObject(["", void 0], ["", "\\00"]), 100); // \\00
var a3 = tag(__makeTemplateObject(["", void 0], ["", "\\u"]), 100); // \\u
var a4 = tag(__makeTemplateObject(["", void 0], ["", "\\u0"]), 100); // \\u0
var a5 = tag(__makeTemplateObject(["", void 0], ["", "\\u00"]), 100); // \\u00
var a6 = tag(__makeTemplateObject(["", void 0], ["", "\\u000"]), 100); // \\u000
var a7 = tag(__makeTemplateObject(["", "\0"], ["", "\\u0000"]), 100); // \u0000
var a8 = tag(__makeTemplateObject(["", undefined], ["", "\\u{"]), 100); // \\u{
var a8 = tag(__makeTemplateObject(["", void 0], ["", "\\u{"]), 100); // \\u{
var a9 = tag(__makeTemplateObject(["", "\uDBFF\uDFFF"], ["", "\\u{10FFFF}"]), 100); // \\u{10FFFF
var a10 = tag(__makeTemplateObject(["", undefined], ["", "\\u{1f622"]), 100); // \\u{1f622
var a10 = tag(__makeTemplateObject(["", void 0], ["", "\\u{1f622"]), 100); // \\u{1f622
var a11 = tag(__makeTemplateObject(["", "\uD83D\uDE22"], ["", "\\u{1f622}"]), 100); // \u{1f622}
var a12 = tag(__makeTemplateObject(["", undefined], ["", "\\x"]), 100); // \\x
var a13 = tag(__makeTemplateObject(["", undefined], ["", "\\x0"]), 100); // \\x0
var a12 = tag(__makeTemplateObject(["", void 0], ["", "\\x"]), 100); // \\x
var a13 = tag(__makeTemplateObject(["", void 0], ["", "\\x0"]), 100); // \\x0
var a14 = tag(__makeTemplateObject(["", "\0"], ["", "\\x00"]), 100); // \x00