Repository navigation
Conversation
Why:
A record field, argument label or JSX prop named like a keyword (type,
open, in, for) has to be renamed and mapped back with @as, or escaped
as \"type". Keys such as type are common in JavaScript objects; the
standard library itself declares `@as("type") type_` in JsxDOM.
Where the grammar expects a name that no variable is bound to, a reserved
word is now that name: a record field (in a type, an expression, a pattern
and after the `.` of a field access), an argument label after `~`, a JSX
prop, a polymorphic variant tag after `#` and a lowercase JSX tag name.
Each of these positions is entered on a token that is not a keyword, so
the reading is unambiguous; the one choice, `{` starting a record or a
block, is made by a reserved word followed by `:`, which no block item
starts with. The parse tree is the one the escaped spelling gives, so type
checking and the generated JavaScript do not change.
A shorthand (`{type}`, `~type`, `<input type />`) stands for a variable of
the same name, and a reserved word still can't be one. After the `.` of a
field access or the `~` of a label a reserved word is taken only on the
same line, so `user.` or `f(~` at the end of a line being written does not
swallow the next `let`, and editor completion still sees the unfinished
argument.
`let?`, one token, is split into the name `let` and `?` where a name is
expected (`{let?: int}`, `x == #let? a : b`).
Format modified (escaped names):
Example:
type t = {\"type": string, mutable \"open": bool}
let get = r => r.\"type"
let call = f(~\"for"="a")
let tag = #"true"
let el = <\"switch" />
Before (rescript):
type t = {\"type": string, mutable \"open": bool}
let get = r => r.\"type"
let call = f(~\"for"="a")
let tag = #"true"
let el = <\"switch" />
After (rescript):
type t = {type: string, mutable open: bool}
let get = r => r.type
let call = f(~for="a")
let tag = #true
let el = <switch />
Diagnostic removed (keyword as a field name):
Example:
let r = {type: 1}
Before (diagnostic):
Cannot use keyword `type` as a record field name. Suggestion: rename it (e.g. `type_`)
After (diagnostic): none, `type` is the field's name
Diagnostic added (shorthand with a reserved word):
Example:
let {type} = r
After (diagnostic):
`type` is a reserved keyword, so it can't be a variable name and this shorthand can't be used.
Write it out instead: `{type: pattern}`
Review: Can a program that parses today change meaning? Every accepted form
was a syntax error before. All 2,948 .res/.resi files in the repository
that the previous parser accepts give the same parse tree (-print ml), and
so do the 33,367 of 199,692 corpus mutants (keywords inserted, removed,
escaped and unescaped, line breaks added) that it accepts. None crashes or
hangs, with or without -recover, beyond the debug -print ml printer and
the JSX transform's errors, which the previous parser reaches the same way.
Formatting every accepted mutant gives the same tree again; the few that
don't fail the same way with an ordinary name in place of the keyword.
Review: Why do runtime and test sources change? They used escaped labels
and tags (`\"type": ...`, `#"true"`), which the formatter now prints bare.
The runtime and tests/tests compile to the same JavaScript.
Review: Why do analysis snapshots change? Hover and completion print the
types with bare tags (`[#and | #or]`, `#switch`).
Review: Does parsing allocate more? The benchmark sources
(tests/compiler_benchmarks/data) allocate within 0.03% of the previous
parser: the new checks use one-token lookahead, no backtracking, and no
closures on the field, label and JSX prop paths.
Review: What checks the two spellings agree? tests/syntax_tests generates
2,000 seeded programs in both spellings and checks that they parse, give
the same tree, format identically and idempotently, and that formatting
adds no escape; every shorthand with each of the 28 words, and every
record row with one of them after a missing comma (`{a type: x}`), must be
rejected.
Co-authored-by: Jaap Frolich <jfrolich@gmail.com>
Session: https://os.submodule.nl/session/os-01a1cf02-c45e-7b38-9d7d-9bb237c29854
Signed-off-by: open-session-submodule[bot] <341020755+open-session-submodule[bot]@users.noreply.github.com>
Why:
`type t = int as '` at the end of a file stopped the parser with an
assertion instead of a syntax error, in the compiler and the editor.
`parse_ident` reported the missing name and then skipped the token in its
place with `Parser.next`, which asserts at the end of the file. It now
uses `Parser.next_unsafe`, as the other error paths do.
Diagnostic added (missing type variable name at the end of a file):
Example:
type t = int as '
Before (diagnostic): none, the parser stops with an assertion
After (diagnostic):
A type param consists of a singlequote followed by a name like `'a` or `'A`
Review: How was it found? Mutation fuzzing of the parser; the input
crashes the parser before this branch too.
Co-authored-by: Jaap Frolich <jfrolich@gmail.com>
Session: https://os.submodule.nl/session/os-01a1cf02-c45e-7b38-9d7d-9bb237c29854
Signed-off-by: open-session-submodule[bot] <341020755+open-session-submodule[bot]@users.noreply.github.com>
Why:
A `'` directly followed by a line break moved every later location one
line down, so syntax errors pointed at the wrong line; at the end of a
file, printing the error crashed.
The scanner reads `'` as a codepoint literal when a character and a closing
`'` follow. When they don't, it went back to the character after the quote,
restoring the offset but not the line: the line break it had stepped over
stayed counted. It now restores the line number and the line's start too.
Diagnostic modified (location after a lone quote):
Example:
let x = y '
let z = 1
let w = )
Before (diagnostic):
ln.res:4:8-9 This let-binding misses an expression
After (diagnostic):
ln.res:3:8-9 This let-binding misses an expression
Review: Why does aliasAtEndOfFile.res.txt change? Its error was reported on
line 3 of a two-line file; it is now on line 2.
Co-authored-by: Jaap Frolich <jfrolich@gmail.com>
Session: https://os.submodule.nl/session/os-01a1cf02-c45e-7b38-9d7d-9bb237c29854
Signed-off-by: open-session-submodule[bot] <341020755+open-session-submodule[bot]@users.noreply.github.com>
Changelog🚀 New Feature
🐛 Bug fix
Semantic Diff3 commits · Full page Accept reserved words as field names, labels, variant tags and JSX namesb0ac12f · open-session-submodule[bot] + Jaap Frolich · Nov 16, 2026, 20:50 UTC
Where the grammar expects a name that no variable is bound to, a reserved word is now that name: a record field (in a type, an expression, a pattern and after the A shorthand ( Format modified (escaped names) type t = {\"type": string, mutable \"open": bool}
let get = r => r.\"type"
let call = f(~\"for"="a")
let tag = #"true"
let el = <\"switch" />
-type t = {\"type": string, mutable \"open": bool}
-let get = r => r.\"type"
-let call = f(~\"for"="a")
-let tag = #"true"
-let el = <\"switch" />
+type t = {type: string, mutable open: bool}
+let get = r => r.type
+let call = f(~for="a")
+let tag = #true
+let el = <switch />Diagnostic removed (keyword as a field name) let r = {type: 1}
-Cannot use keyword `type` as a record field name. Suggestion: rename it (e.g. `type_`)
+none, `type` is the field's nameDiagnostic added (shorthand with a reserved word) let {type} = r
Review
Don't crash on a name missing at the end of a file412e65b · open-session-submodule[bot] + Jaap Frolich · Nov 25, 2026, 20:46 UTC
Diagnostic added (missing type variable name at the end of a file) type t = int as '
-none, the parser stops with an assertion
+A type param consists of a singlequote followed by a name like `'a` or `'A`Review
Keep line numbers right after a quote before a line break6af6ecd · open-session-submodule[bot] + Jaap Frolich · Nov 25, 2026, 20:47 UTC
The scanner reads Diagnostic modified (location after a lone quote) let x = y '
let z = 1
let w = )
-ln.res:4:8-9 This let-binding misses an expression
+ln.res:3:8-9 This let-binding misses an expressionReview
|
✅ Compiler benchmarksAllocated wordsIn total: 638,386,285 → 638,418,973 (+0.01%). Generated projects: 629,069,606 → 629,087,678 (±0.00%). None of the 265 benchmarks changed by 0.1% or more. InstructionsIn total: 9,221,423,192 → 9,225,687,141 (+0.05%).
8 more changes
(inputs changed): this pull request changes runtime or Belt sources, so these benchmarks compile different code than on the base, and their changes don't count as regressions. Output sizeIn total: 26,070,038 → 26,074,057 (+0.02%).
Pull request 6af6ecd compared with base 17874c0 in this run. |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #9435 +/- ##
==========================================
+ Coverage 82.22% 82.25% +0.03%
==========================================
Files 461 462 +1
Lines 65574 65766 +192
==========================================
+ Hits 53916 54098 +182
- Misses 11658 11668 +10
🚀 New features to boost your workflow:
|
rescript
@rescript/belt
@rescript/darwin-arm64
@rescript/linux-arm64
@rescript/linux-x64
@rescript/runtime
@rescript/win32-x64
commit: |
|
Developer playground preview: https://rescript-lang.github.io/rescript/dev-playground/?version=pr-9435 |
|
@codex review |
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
Codex Review: Didn't find any major issues. What shall we delve into next? Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
Recreated from jfrolich/rescript-rust#341 with unchanged commits, on a branch in this repository so CI and benchmark reporting can run here. The validation results below are carried over from the original PR; fresh CI will validate this stack.
Reserved words can now name record fields, argument labels, JSX props, polymorphic variant tags and lowercase JSX elements without an escape:
Today each of these is a syntax error and needs
\"type",#"type"or atype_field mapped back with@as("type"). This is the first part of the RFC in docs/rfcs/reserved-words-as-labels.md.What changes
Only the parser and the printers change. Each of these positions is entered on a token that is not a keyword (
.,~,#,<,{,,), so a reserved word there can only be a name. The parse tree is the one the escaped spelling already gives, so type checking and the generated JavaScript are unchanged.{type: ...}is told apart from a block by the token after the word (:,?,,,}), with one token of lookahead..of a field access or the~of a label, a reserved word is taken only on the same line. Souser.orf(~at the end of a line that is still being written doesn't swallow the nextlet, and editor completion still sees the unfinished argument.{type},~type,<input type />) still need a variable namedtype, so they stay errors, with messages that show the long form. A missing comma before such a field ({a type: x}) is reported as before.let?is a single token. Where a name is expected it is split intoletand?({let?: int},x == #let? a : b).typeas a record field name" recovery is removed, because that input now parses.Two existing parser bugs, found by the fuzzing below, are fixed in separate commits:
type t = int as 'at the end of a file crashed the parser with an assertion.'directly followed by a line break shifted every later syntax error one line down, and crashed the error printer at the end of a file.Tests
tests/syntax_tests/data, plus a Mocha test (tests/tests/src/keyword_labels_test.res) that checks fields, patterns, labels, tags and JSX props at runtime.tests/syntax_tests/res_keyword_name_test.mlis a seeded property test. It writes 2,000 random programs in both spellings (bare and escaped) and checks that both parse, give the same tree, format identically and idempotently, re-parse to the same tree, and that formatting adds no escape. It also checks that every shorthand, and every missing comma before a keyword field, is rejected for each of the 28 words. Breaking the printer's escaping, thelet?split or the missing-comma check makes it fail.master, run out of tree:.res/.resifiles in the repository thatmasteraccepts give an identical-print mltree.masteraccepts give an identical tree.master, with an ordinary name in place of the keyword. These are existing formatter bugs, such as a bare identifier as a JSX child.-recover, except in the debug-print mlprinter and the JSX transform's error reporting, whichmasterreaches the same way.tests/compiler_benchmarks/data) allocates within 0.03% ofmaster, and formatting them within 0.04%.make test-syntaxand its roundtrip mode,dune build @fmt, the Mocha suite, the editor analysis tests,super_errors, the build tests,make dead-code, the changelog check, and therescript-syntaxbuild with OCaml 4.14 all pass. Hover and completion snapshots change only where they now print tags bare (#switch,[#and | #or]).Not included: making keywords usable as variables (#9436, stacked on this one), un-reserving
type, and renamingJsxDOM's@as("type") type_fields, which is a standard library change.Started by Jaap Frolich in this Assistant session