fix: allow keywords as property names after . and \.#9
Merged
Conversation
Property access parsed names with a fixed allowlist of keywords, and every other keyword fell through to "unknown" — so `promise.then[f]` compiled to `p.unknown(f)`. The entire Promise chaining API (`then` / `catch` / `finally`) and any keyword-named member was broken. Add `keyword_text` mapping every keyword token back to its source text and use it in property position (after `.` and `\.`), matching JavaScript, which allows reserved words as property names. Notes: - `protected` and `function` lex to the same tokens as `private` / `fn`, so `obj.protected` compiles to `obj.private` (pre-existing aliasing; unchanged by this fix) - binding positions (destructuring, parameters) keep the previous stricter allowlist Fixes #6
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Property access resolved names through a fixed keyword allowlist, and every other keyword fell through to
"unknown"— sopromise.then[f]compiled top.unknown(f). The entire Promise chaining API (then/catch/finally) and any keyword-named member was broken.Changes
keyword_texthelper maps every keyword token back to its source textParser::parse_property_nameused in property position (after.and\.), accepting any keyword — matching JavaScript, which allows reserved words as property namesBinding positions (destructuring, parameters, import names) keep the previous stricter allowlist.
Known limitation
protectedandfunctionlex to the same tokens asprivate/fn, soobj.protectedcompiles toobj.private(pre-existing token-level aliasing; unchanged by this fix).Tests
moon test --target js: 322 passedp.then[f],p.catch[f],p.finally[f],obj.if,obj\.then) and codegen tests for the full promise chainPromise.resolve[...].then/catch chain viapkg/index.jsFixes #6