The Wayback Machine - https://web.archive.org/web/20210603090128/https://github.com/microsoft/TypeScript/pull/41030
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

Remove errors for invalid escape sequences in tagged template literals #41030

Closed
wants to merge 6 commits into from

Conversation

@uhyo
Copy link
Contributor

@uhyo uhyo commented Oct 10, 2020

Happy hacktoberfest! 🎃🥳

Fixes #39715.
Also gives a partial fix to #396.

Example

Code

String.raw`\x \012`;

`\x \012`;

Current Behavior

src/backslashx.ts:1:14 - error TS1125: Hexadecimal digit expected.

1 String.raw`\x \012`;
               

src/backslashx.ts:3:4 - error TS1125: Hexadecimal digit expected.

3 `\x \012`;
     


Found 2 errors.

New Behavior

src/backslashx.ts:3:4 - error TS1125: Hexadecimal digit expected.

3 `\x \012`;
     

src/backslashx.ts:3:7 - error TS1392: Octal escape sequences are not allowed in template strings.

3 `\x \012`;
        


Found 2 errors.

(Error disappeared from tagged template literal, and new error for octal escape sequence in untagged template literal)

Implementation Detail

With this PR, invalid escape sequences do not emit errors when they are first scanned. Untagged template literals with invalid escape sequence in it are re-scanned to emit syntax errors.

@uhyo uhyo force-pushed the uhyo:fix-39175 branch from c14b5ac to 4e43780 Apr 1, 2021
@uhyo
Copy link
Contributor Author

@uhyo uhyo commented Apr 1, 2021

Happy new financial year (in Japan)!! 🌸🥳
A silent remainder on this. I rebased on the latest master.

Copy link
Member

@elibarzilay elibarzilay left a comment

I don't think that this is a good approach since it complicates the template parsing code (and only when tags are used?) but it can be simpler to handle all strings in one place instead since they all go through the same place. I posted a comment listing how this can be done.

(Oh, I'm guessing that the tag thing is to deal with raw-tagged strings (#42887); in any case, I think that it's better to fix that case after dealing with the general string case.)

PR Backlog automation moved this from Needs review to Waiting on author Jun 3, 2021
@uhyo
Copy link
Contributor Author

@uhyo uhyo commented Jun 3, 2021

Thank you for your reviews!
I cannot afford to deal with the new approach though, closing this PR.

@uhyo uhyo closed this Jun 3, 2021
PR Backlog automation moved this from Waiting on author to Done Jun 3, 2021
@uhyo uhyo deleted the uhyo:fix-39175 branch Jun 3, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
PR Backlog
  
Done
Linked issues

Successfully merging this pull request may close these issues.

3 participants