Repository navigation
Conversation
In a TypeScript class body, tsc only treats public, private, protected, readonly and override as modifiers when the member name starts on the same line. "public<newline>a = 1" declares a field named "public" and a field "a". Bun skipped the keyword regardless of the newline, so such fields silently disappeared from the emitted class. Add the same has_newline_before check that the declare, abstract and accessor arms already use. static is intentionally left alone: tsc lets it bind across a newline.
|
Warning Review limit reachedYou've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Next included review available in 7 minutes. View limit details
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
Status: ready for review. The branch has main da867c6 merged in. The diff against main is the
|
There was a problem hiding this comment.
LGTM — one-line guard matching the neighboring declare/abstract/accessor/async arms, aligning with tsc's nextTokenIsOnSameLineAndCanFollowModifier.
What was reviewed:
- Fall-through path: with the newline guard failing,
namebecomes anEStringkey,is_shorthand_propertyis gated off byopts.is_class, and the class-field branch terminates viaexpect_or_insert_semicolon(ASI on the samehas_newline_before). staticintentionally left unguarded (matches tsc); test cases coverpublic⏎static⏎x,static⏎public⏎x, andpublic static⏎xinteractions.- Same-line
readonly [key: string]: numberindex signature still erased — regression case is in the new tests. - No CODEOWNERS for
src/js_parser/or the test file.
Extended reasoning...
Overview
Adds && !p.lexer.has_newline_before to the PPrivate | PProtected | PPublic | PReadonly | POverride match arm in src/js_parser/parse/parse_property.rs, so that in a TypeScript class body these words followed by a line terminator are parsed as field names rather than dropped as modifiers of the next member. Adds 13 exp(...) cases to the existing "contextual keywords followed by a newline" block in test/bundler/transpiler/transpiler.test.js.
Security risks
None. Pure parser grammar adjustment with no I/O, allocation-size, or untrusted-length handling changes.
Level of scrutiny
Low-to-medium. The change is a single boolean conjunct that mirrors the identical guard already present on the four adjacent arms (PDeclare, PAbstract, PAccessor, PAsync) in the same match — the file's local convention is followed exactly. The behavioral semantics were cross-checked against the tsc reference (nextTokenIsOnSameLineAndCanFollowModifier) and node --strip-types per the PR description, and the fall-through path was traced: the identifier becomes an EString key, the shorthand-property branch is skipped because opts.is_class is true, and the class-field branch's expect_or_insert_semicolon inserts the ASI on the very newline that tripped the guard.
The PR notes esbuild has the same divergence; REVIEW.md says the reference implementation is the spec for ported code, but for TypeScript syntax tsc is the authority and both tsc and swc agree here, so aligning with tsc is the right call.
Other factors
- Tests are placed alongside the existing
declare/abstract/accessornewline cases in the same file (not a new file), covering all five keywords, method/computed/private-identifier followers, thestaticinteraction in both orders, and two negative cases (same-line modifiers still erased;readonlyindex signature still erased). - PR description states 10 of the 13 new cases fail on bun 1.4.0, satisfying the "test fails without the fix" requirement.
- No CODEOWNERS entry covers either changed file.
- No prior human review comments on the PR.
|
Updated 12:07 PM PT - Oct 29th, 2026
❌ @robobun, your commit b3ada9a has some failures in 🧪 To try this PR locally: bunx bun-pr 38706That installs a local version of the PR into your bun-38706 --bun |
There was a problem hiding this comment.
LGTM — one-line guard mirroring the neighbouring declare/abstract/accessor/async arms, with expectations cross-checked against tsc.
What was reviewed:
- The added
!p.lexer.has_newline_beforematches the identical check on the four sibling arms; fall-through reaches the class-field path and terminates via ASI as described. - Confirmed
static/get/setare unchanged (separate arms, intentionally no newline guard per tsc's grammar); same-linereadonly [k: string]: Tindex signatures still parse. - 13 new cases in the existing "contextual keywords followed by a newline" test cover all five keywords, mixed
staticorderings, computed/private keys, and same-line control cases; mechgate shows they fail on main and pass here.
Extended reasoning...
Overview
The PR adds a single && !p.lexer.has_newline_before clause to the PPrivate | PProtected | PPublic | PReadonly | POverride arm of parse_property (src/js_parser/parse/parse_property.rs:486). This brings that arm in line with the four adjacent arms (PDeclare, PAbstract, PAccessor, PAsync) that already gate on the same flag. When a newline separates the modifier word from the next token, the arm now falls through to the ordinary property-key path, producing a field named public/readonly/etc. that the existing class-field code terminates via expect_or_insert_semicolon. 24 lines of test additions land in the existing "contextual keywords followed by a newline" test in test/bundler/transpiler/transpiler.test.js, using the same ts.expectPrinted_ helper as neighbouring abstract/accessor cases.
Security risks
None. This is a TypeScript-only parser grammar tweak with no memory management, no untrusted-length arithmetic, and no new allocation or I/O.
Level of scrutiny
Low-to-medium. The source change is one boolean clause that copies an established pattern from four sibling arms in the same match. The fix is grounded in tsc's nextTokenIsOnSameLineAndCanFollowModifier and every expected output was cross-checked against tsc 6.0.2 transpileModule and node --strip-types. static, get, and set are handled by separate arms and intentionally left alone (they do bind across a newline in tsc). The readonly [key: string]: number control case confirms same-line index signatures are unaffected.
Other factors
- Mechgate evidence in the PR shows 10/13 new assertions fail on 1.4.0 and all pass with the fix, on both ASAN-debug and release builds.
- The two comment-cop review threads (about a paragraph-long code comment) were addressed in 4550863, which restored the original one-line comment; both threads are marked resolved.
- No CODEOWNERS entry covers
src/js_parser/. - No prior claude[bot] review on this PR.
The class modifier fix changes the text that the runtime transpiler prints. An entry that an older build wrote holds the old text. With the same version, the new build reads that entry and the fix does not reach the file.
There was a problem hiding this comment.
Nothing blocking. The comments below are optional suggestions. There is no need to push a fix for them before merging.
Beyond the inline finding, I also checked three things and ruled them out: the has_newline_before read at parse_property.rs:485 happens after p.lexer.next() on line 343, so it describes the gap after the modifier word exactly as the declare/abstract/accessor/async arms do; leaving static/get/set unguarded matches tsc's nextTokenCanFollowModifier, which only applies the same-line rule to the other modifiers, so static\n public\n x -> static public; x = 1 is the tsc shape; and the bytecode compile cache (src/jsc/NodeCompileCache.rs) is keyed by the build's git SHA, so EXPECTED_VERSION in RuntimeTranspilerCache.rs is the only format constant that needed bumping.
Extended reasoning...
The change is a one-condition parser guard in src/js_parser/parse/parse_property.rs, a runtime transpiler cache version bump 43 to 44, and 13 new transpiler test cases; it touches no security-sensitive surface. A confirmed sibling-site gap in the constructor parameter-property loop is posted inline, which is why this is a defer rather than an approval.
…r name In a constructor parameter list, tsc takes public, private, protected, readonly and override as modifiers only when the parameter name starts on the same line. With a line break after the word, the word is the parameter name, and a name on the next line is a syntax error (TS1005). The modifier loop in parse_fn did not look at the line break. It skipped the word and emitted a parameter property. It now checks has_newline_before, like the class member arm in parse_property.
There was a problem hiding this comment.
LGTM — the latest push brings the constructor-parameter loop in line with the class-member arm, so both sites that treat these five words as modifiers now apply the same newline rule.
What was reviewed:
- Traced
public\n x = 1andreadonly\n [k] = 1throughparse_property.rs: the word falls through to the plain key path andexpect_or_insert_semicolonends the field on the samehas_newline_beforestate, so[,#x, and method names on the next line all split correctly. - Traced
readonly\n x,public readonly\n x,readonly\n, xandreadonly\n = 1through theparse_fn.rsloop: the break lands with the modifier word as the binding and the next token reported by the normal)/,check. - Checked the remaining
PropertyModifierKeywordarms:declare,abstract,accessor,asyncalready carry the newline guard;static/get/setintentionally do not, matching tsc. EXPECTED_VERSIONbump and doc line follow the existing entry format; no CODEOWNERS entry covers the changed files.
Extended reasoning...
The change adds a has_newline_before guard at the two parser sites that treat public/private/protected/readonly/override as TypeScript modifiers (class members in parse_property.rs and constructor parameter properties in parse_fn.rs), bumps the runtime transpiler cache version to 44, and adds 20 exact-output transpiler test cases. It touches no security-sensitive surface; it is a pure syntax-handling change in the TS-only parser path. The decision to approve rests on the diff being two one-line guards that copy a pattern already used by the neighboring declare/abstract/accessor/async arms, the prior inline finding about the parse_fn.rs sibling site being addressed in commit b3ada9a with its own error-case tests, and no outstanding objections from a human reviewer.
|
Closing as stale: this PR conflicts with main, and its last commit is from 2026-10-29. The branch stays, so the work is not lost. To pick it up again, rebase the branch on main and reopen this PR. |
Problem
.tsclass body,public,private,protected,readonlyoroverridealone on a line is dropped. Withpublicon one line anda = 1on the next,Object.keys(new C())is["a"]. tsc 6.0.2 and node 26 give["public","a"].constructor(readonly⏎ x)becomes a parameter property (this.x = x). ⏎ is a line break. tsc rejects it (TS1005).p.lexer.has_newline_before:parse_property.rs:477andparse_fn.rs:255insrc/js_parser/parse/.Fix
static,getandsetdo not change.test/bundler/transpiler/transpiler.test.js(fails on bun 1.4.3-canary.1). Notes lists the other suites.Background
p.lexer.has_newline_beforeis true when a line break precedes the current token.Downsides
constructor(readonly⏎ x)fails withExpected ")" but found "x". Bun 1.4.3-canary.1 and esbuild 0.21.5 accept it.Notes
The snippet.
The rule of tsc. The grammar of tsc (
nextTokenIsOnSameLineAndCanFollowModifier) accepts these words as modifiers only when the member name is on the same line. Otherwise each word is a field namedpublic,readonly, and so on.parseParameterWorkerreads the modifiers of a parameter through the same function.static,getandsetare the exceptions and bind across a line break. esbuild, which this code descends from, has the same difference from tsc at both sites.What the fix does in a class body. With a line break after the word, the arm falls through to the normal key path. The word becomes a field of that name, and the class field code ends it with ASI (
expect_or_insert_semicolonreads the samehas_newline_before). The next line is parsed as its own member. Mixed forms give the member list of tsc:public⏎static⏎xgivespublic; static x;,static⏎public⏎xgivesstatic public; x;, andpublic static⏎xstill givesstatic x;.What the fix does in a constructor.
parse_fnparses the first identifier of a parameter as a binding. The loop took that identifier as a modifier when a name or a pattern followed it, and parsed the binding again. With a line break before that name, the loop now stops. The identifier stays the parameter, and the parameter list then needs,or).TS1005 is "',' expected". Every input that changes is one that tsc rejects.
Where the check lives. The two sites share no helper that sees the lexer.
parse_propertymatchesPropertyModifierKeywordarms after it consumed the word.parse_fnasksis_type_script_accessibility_modifier, a lookup in a set of strings. So each site has its own check. The only other use of these words in the parser is thereadonlytype operator (src/js_parser/typescript.rs). tsc has no same-line rule there (let x: readonly⏎ string[]is valid), and the type is erased.The test. "contextual keywords followed by a newline apply ASI instead of acting as modifiers" in
test/bundler/transpiler/transpiler.test.jshas 13 new cases for class members and 8 for constructor parameters. The first description of this PR recorded that 10 of the 13 fail on bun 1.4.0 and that each expectation was checked against tsc 6.0.2transpileModule. Of the 8, the 5 error cases fail on bun 1.4.3-canary.1, which accepts the input. The other 3 are controls. On bun 1.4.3-canary.1 the test fails.Cache version.
EXPECTED_VERSION(src/jsc/RuntimeTranspilerCache.rs) is 43 in bun 1.4.4 and on main da867c6. The rule at the top ofsrc/js_parser/parser.rsasks for a new version when a parser change alters what runs. Probe: a 5 KB.tsfile withclass C {,public,a = 1,}on four lines that prints the keys ofnew C(), and one cache folder. The older build runs the file first, then the new build runs it. The older build is main da867c6. Both are debug builds, withBUN_DEBUG_ENABLE_RESTORE_FROM_TRANSPILER_CACHE=1(without it a debug build ignores a cache hit).Other open PRs also change this number, and they do not all take the same one. All of them edit the same line, so each PR that lands after the first one conflicts. The rule for that rebase: take the number that main has at that time plus one, never a lower number. #47390 adds a source lint that fails when a merge lowers the number.
Cost of the new cache version. Measured on bun 1.4.4 (release, linux x64):
require()of one file, a cache miss against a cache hit, 15 interleaved runs, median wall clock. The noise floor is the difference between two interleaved series of hits.The cost occurs once per cached file, on its first run after the upgrade. It is shared with any other change in the same release that takes a new version.
perf,valgrindandstraceare not installed in the container, so there is no instruction count.Cost for code without these words. None.
parse_propertyreaches the new condition only for a key that is one of the five words.parse_fnreaches it only when a name or a pattern follows the first identifier of a constructor parameter. Each condition reads oneboolof the lexer.Merge with main. The branch has main da867c6 merged in, with no conflict. The diff against main is the two conditions, the cache version and the test.
Suites run on the branch head b3ada9a (debug build).
test/bundler/transpiler/transpiler.test.js: 258 pass, 1 skip, 21 todo.test/bundler/esbuild/ts.test.ts,test/cli/run/transpiler-cache.test.ts,test/regression/issue/30887.test.ts, and intest/bundler/transpiler/:decorators.test.ts,decorator-metadata.test.ts,es-decorators.test.ts,es-decorators-esbuild.test.ts,property.test.ts,ts-use-define-for-class-fields.test.ts. Together: 703 pass, 17 todo.[auto-merge] gate passed · iteration 6 · 4 files touched
fails on main (without fix)
passes on PR (with fix)
diff hotspot
gate history · 3 passed · 0 rejected · iteration 6
evidence per changed file