-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
swc_ecma_parser: Unexpected escape sequence in reserved word (2) #9227
Comments
GFI guide
This is about an object lieral, and the relevant code lives at swc/crates/swc_ecma_parser/src/parser/object.rs Lines 183 to 212 in 1ec68cb
It seems like
swc/crates/swc_ecma_parser/src/parser/object.rs Lines 43 to 122 in 1ec68cb
But there's no relevant error reporting logic so my guess is that the error is from lexer. The relevant error reporting logic is at swc/crates/swc_ecma_parser/src/lexer/mod.rs Lines 777 to 780 in 1ec68cb
We need to patch this logic to allow escapes in reserved word in property names. |
I'm going to take a stab at it |
Fixing this bug is not as simple as adding a new context flag. Since swc parser reads next token automatically when last token is taken, we can't figure out where to add the new context flag. Specifically, I think the token reading happens at:
We can't assume the parser is going to parse https://tc39.es/ecma262/#prod-LiteralPropertyName, therefore it is not proper to add the context flag there. |
Yes, that's what I figured. I also tried "forwarding" richer info downstream of the lexer (PR #9236), so that the identifier/keyword ambiguity can be resolved in a later phase, but it seems to be a dead end. (In an unrelated note: I've kind of given up on this bug. I've been focusing on other stuff since, and this bug isn't really bothering me much. I'm not sure how much more I can contribute here; looks like the necessary effort is out of reach for me now.) |
Describe the bug
Have swc_ecma_parser parse this test262 case: test/language/import/import-assertions/json-extensibility-array.js (others also exhibit this behavior).
(This is a re-post of #9214, this time with a proper reproduction link that works on the latest parser version, 0.147.0)
Input code
Config
Playground link (or link to the minimal reproduction)
https://play.swc.rs/?version=1.6.7&code=H4sIAAAAAAAAAytLLFLIT8pSsFXQqFZIKkqNKTUwMDPMtlIwMVKo1bTmAgDLr8KQIAAAAA%3D%3D&config=H4sIAAAAAAAAA1VPSQ7CMAy89xWRzxwACQ78gUdYwa1SZVMcJKKqfyfNUujNs3nsZRACZpbwEEseM%2FAYmMKOM8PJRvxkBkgaZBmUj3Dq6sybNKJmKtRaFYgYJoolxdfz5dYSoJ1j6onGGWXVmP47pTM%2BEPPRuFnRTpqOjUNrBeNe7yK2X2LyVC%2B4w8%2FUy%2FbFoPjZk3Xt%2BgVne8%2FLGAEAAA%3D%3D
SWC Info output
No response
Expected behavior
The above code is parsed as an object literal with property "var" (which is legal JS). This works in node.
Actual behavior
The following error is reported:
Version
0.147.0
Additional context
The relevant code that calls the parser is the following (just an extract; the original with full context is here):
The text was updated successfully, but these errors were encountered: