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

Fixed hasInvalidEscape implementation #55373

Merged
merged 2 commits into from
Aug 14, 2023
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
9 changes: 7 additions & 2 deletions src/compiler/utilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -509,6 +509,7 @@ import {
TaggedTemplateExpression,
TemplateLiteral,
TemplateLiteralLikeNode,
TemplateLiteralToken,
TemplateLiteralTypeSpan,
TemplateSpan,
TextRange,
Expand Down Expand Up @@ -5801,11 +5802,15 @@ function escapeTemplateSubstitution(str: string): string {
return str.replace(templateSubstitutionRegExp, "\\${");
}

function containsInvalidEscapeFlag(node: TemplateLiteralToken): boolean {
return !!((node.templateFlags || 0) & TokenFlags.ContainsInvalidEscape);
}

/** @internal */
export function hasInvalidEscape(template: TemplateLiteral): boolean {
return template && !!(isNoSubstitutionTemplateLiteral(template)
? template.templateFlags
: (template.head.templateFlags || some(template.templateSpans, span => !!span.literal.templateFlags)));
? containsInvalidEscapeFlag(template)
: (containsInvalidEscapeFlag(template.head) || some(template.templateSpans, span => containsInvalidEscapeFlag(span.literal))));
}

// This consists of the first 19 unprintable ASCII characters, canonical escapes, lineSeparator,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,11 @@ 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(__makeTemplateObject(["", "\0"], ["", "\\u0000"]), 100); // \u0000
const a7 = tag `${100}\u0000`; // \u0000
const a8 = tag(__makeTemplateObject(["", void 0], ["", "\\u{"]), 100); // \\u{
const a9 = tag(__makeTemplateObject(["", "\uDBFF\uDFFF"], ["", "\\u{10FFFF}"]), 100); // \\u{10FFFF
const a9 = tag `${100}\u{10FFFF}`; // \\u{10FFFF
const a10 = tag(__makeTemplateObject(["", void 0], ["", "\\u{1f622"]), 100); // \\u{1f622
const a11 = tag(__makeTemplateObject(["", "\uD83D\uDE22"], ["", "\\u{1f622}"]), 100); // \u{1f622}
const a11 = tag `${100}\u{1f622}`; // \u{1f622}
const a12 = tag(__makeTemplateObject(["", void 0], ["", "\\x"]), 100); // \\x
const a13 = tag(__makeTemplateObject(["", void 0], ["", "\\x0"]), 100); // \\x0
const a14 = tag(__makeTemplateObject(["", "\0"], ["", "\\x00"]), 100); // \x00
const a14 = tag `${100}\x00`; // \x00
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,6 @@ function f(...args: any[]) {
f `\x0D${ "Interrupted CRLF" }\x0A`;

//// [taggedTemplateStringsHexadecimalEscapesES6.js]
var __makeTemplateObject = (this && this.__makeTemplateObject) || function (cooked, raw) {
if (Object.defineProperty) { Object.defineProperty(cooked, "raw", { value: raw }); } else { cooked.raw = raw; }
return cooked;
};
function f(...args) {
}
f(__makeTemplateObject(["\r", "\n"], ["\\x0D", "\\x0A"]), "Interrupted CRLF");
f `\x0D${"Interrupted CRLF"}\x0A`;
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,6 @@ function f(...args: any[]) {
f `'\u{1f4a9}'${ " should be converted to " }'\uD83D\uDCA9'`;

//// [taggedTemplateStringsWithUnicodeEscapesES6.js]
var __makeTemplateObject = (this && this.__makeTemplateObject) || function (cooked, raw) {
if (Object.defineProperty) { Object.defineProperty(cooked, "raw", { value: raw }); } else { cooked.raw = raw; }
return cooked;
};
function f(...args) {
}
f(__makeTemplateObject(["'\uD83D\uDCA9'", "'\uD83D\uDCA9'"], ["'\\u{1f4a9}'", "'\\uD83D\\uDCA9'"]), " should be converted to ");
f `'\u{1f4a9}'${" should be converted to "}'\uD83D\uDCA9'`;
Loading