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
PrivateName does not permit escape characters #50851
Comments
Another thing to check class IdentifierNameWithEscape {
x\u{78}: number;
constructor() {
this.x\u{78} = 0;
}
doThing() {
this.xx = 42;
}
}
class PrivateIdentifierWithEscape {
#x\u{78}: number;
constructor() {
this.#x\u{78} = 0;
}
doThing() {
this.#xx = 42;
}
} The first case works perfectly. The second case correctly resolves |
Here are the problems to be solved:
|
Why are these escapes even a thing? They're like a modernized version of C/C++ trigraphs... |
I'm going to guess that auto-generated code was the use-case, and then extended escape sequences were added for parity. |
I believe the main reason is for encodings where unicode isn't available (e.g. ASCII), i.e. if your system only supports ASCII then you can transform any JS source by replacing characters outside of the ASCII range by their escapes. e.g. If you have: const π = 3.14;
const constants = { π: 3.14 };
const s = "π"; Then replacing all non-ASCII characters with their unicode escapes works in any syntatic position: const \u{03C0} = 3.14;
const constants = { \u{03C0}: 3.14 };
const s = "\u{03C0}"; Your conversion doesn't need to be AST aware, because the same escapes that work in string literals also work for identifiers or such, so a simple find and replace will work. |
Okay, allowing a dumb find-and-replace to be fully lossless does make sense. Handling Unicode <-> ASCII is hard enough as it is, so it’s nice that someone wanted to remove at least some of the barriers.
I don’t think I would ever let this pass code review; someone thinks they’re Clever Dan 😄 |
I'm prototyping ES3-ES5 extended escape support in #50918. |
Discovered by @amcasey while running TS on test262.
Currently
IdentifierNameWithEscape
parses and type-checks correctly; however,PrivateIdentifierWithEscape
does not even parse.The text was updated successfully, but these errors were encountered: