Skip to content

fix: allow keywords as property names after . and \.#9

Merged
otnc merged 1 commit into
mainfrom
fix/issue-6-keyword-property-names
Jul 14, 2026
Merged

fix: allow keywords as property names after . and \.#9
otnc merged 1 commit into
mainfrom
fix/issue-6-keyword-property-names

Conversation

@otnc

@otnc otnc commented Jul 13, 2026

Copy link
Copy Markdown
Member

Summary

Property access resolved names through a fixed keyword allowlist, 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.

Changes

  • New keyword_text helper maps every keyword token back to its source text
  • New Parser::parse_property_name used in property position (after . and \.), accepting any keyword — matching JavaScript, which allows reserved words as property names
p.then[f].catch[g].finally[h]
-- before: p.unknown(f).unknown(g).unknown(h)
-- after:  p.then(f).catch(g).finally(h)

Binding positions (destructuring, parameters, import names) keep the previous stricter allowlist.

Known limitation

protected and function lex to the same tokens as private / fn, so obj.protected compiles to obj.private (pre-existing token-level aliasing; unchanged by this fix).

Tests

  • moon test --target js: 322 passed
  • Added parser tests (p.then[f], p.catch[f], p.finally[f], obj.if, obj\.then) and codegen tests for the full promise chain
  • E2E: compiled and executed a real Promise.resolve[...].then/catch chain via pkg/index.js

Fixes #6

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
@otnc otnc merged commit baf04a9 into main Jul 14, 2026
1 check passed
@otnc otnc deleted the fix/issue-6-keyword-property-names branch July 14, 2026 04:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Keyword property names compile to .unknownpromise.then[...] / .catch / .finally broken

1 participant