-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Octal escape sequences should be a lexical/syntactic error in strict mode and ES5 #396
Comments
This has become an a problem since 1.8 release. I had ANSI escape codes in my TypeScript files, which were compiled to JS just fine, but 1.8 started adding I think a compiler error is due here if |
I don't quite understand the status of this issue? It is still present in I've run into this a number of times when using @basart's |
Yes, that is what the 'Accepting PRs' label means. |
@sandersn What's the process for adding new error messages? Just make something up? |
See Instructions for Contributing Code for full details, but here's a summary: Create a test file in
Add the error message in Add code in the compiler to add the error. Rerun the test, check |
I've started to read the source for parser.ts and scanner.ts to figure out how/where to implement this. So far I've figured out: The scanner parses The actual check is dependent on whether we are in a strict context, so can't be done in scanner.ts directly, am I correct that it belongs in checker.ts? If so, some pointers as to where exactly it should be added would be appreciated. |
yes. we defer these checks to the binder/checker. |
Would folks be open to a PR which only updates the scanner to correctly interpret octal-escape syntax, but does not go so far as to add warnings about their use? I'm using the Updating the scanner would be required for the warning, so it seems like a step in the right direction. |
The issue is they are allowed in some contexts, i.e. ES3 and ES5 non-strict mode. so the scanner needs to allow all possible strings, the binder is where the error should be reported. |
@mhegazy Sorry for not being clear - I was more asking if a PR adding full support for octal escape sequences to the lexer would be accepted. Someone else can come in later and add an error to the binder if it makes sense. |
how would you test the change then? |
I could add a test for #24209 and verify that |
Note that octals are disallowed completely ( Also this may be obvious but Here's a RegEx that includes all valid octals and excludes all invalid ones with the notable exception of |
List of things to do for resolving this:
One decision to make is whether to allow octal escapes in TS when not producing strict-mode code. It would probably be easier to forbid them anyway (especially since they're never allowed in template strings) but if not, then the scanner mode should also parse the octal escapes in case the output is not strict. |
@elibarzilay |
Yeah, just give it a shot and see how it goes 👍🏻 |
Thank you! I'll try! |
@elibarzilay @orta (Is this a topic that should be discussed in PR rather than in this Issue?) |
I'm afraid that would be over-stepping, as they are allowed in those modes: #396 (comment) |
I see, too much.
#396 (comment) So, is it the policy that octal escaping is allowed (or left allowed) when not in strict-mode? |
@orta |
The following code should be disallowed in strict mode and ES5:
This is disallowed by Annex B.1.2 of the EcmaScript 5 spec.
The text was updated successfully, but these errors were encountered: