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.

@typescript-bot typescript-bot added For Uncommitted Bug PR for untriaged, rejected, closed or missing bug For Backlog Bug PRs that fix a backlog bug and removed For Uncommitted Bug PR for untriaged, rejected, closed or missing bug labels Oct 10, 2020
@sandersn sandersn added this to Not started in PR Backlog Oct 20, 2020
@sandersn sandersn moved this from Not started to Needs review in PR Backlog Oct 20, 2020
@Kingwl Kingwl mentioned this pull request Feb 20, 2021
@uhyo
Copy link
Contributor Author

uhyo commented Apr 1, 2021

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

Copy link
Contributor

@elibarzilay elibarzilay left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 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 fix-39175 branch June 3, 2021 08:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
For Backlog Bug PRs that fix a backlog bug
Projects
Archived in project
PR Backlog
  
Done
Development

Successfully merging this pull request may close these issues.

raw tagged string doesn't support for \x
3 participants