Repository navigation
fix(compiler,babel-plugin): run later-declarator JSX setup after the declarators before it (#5102) - #5103
Conversation
…declarators before it (#5102) A declaration whose later declarator holds JSX hoisted the element's setup above the whole statement, so it read earlier declarators before initialization (minifiers' joinVars makes this shape). Split the declarators before the JSX into their own statement first, in the DOM, universal and SSR outputs of both compilers. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0117BoWPYxt1bEM9zZ5G6dPL
🦋 Changeset detectedLatest commit: ae43313 The changes in this PR will be included in the next version bump. This PR includes changesets to release 2 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Size (brotli, eager entry chunk)
|
Coverage Report for CI Build 44705089856Coverage remained the same at 79.459%Details
Uncovered ChangesNo uncovered changes found. Coverage RegressionsNo coverage regressions found. Coverage Stats
💛 - Coveralls |
Merging this PR will not alter performance2 warnings
Comparing Footnotes
|
Requested by Ryan · project thread
Fixes #5102.
Summary
When JSX sat in a later declarator of one declaration (
const label = …, onClick = …, view = <div onClick={onClick}/>), both compilers put the element's setup before the whole statement, so it read the earlier declarators before they were initialized. Minifiers make this shape (joinVars), so libraries that ship minified JSX crashed on load.The fix uses the existing statement-position path and splits the declarators before the JSX into their own statement first. The setup then goes between them and the rest:
getSetupStatement(shared by DOM, universal and SSR) does the split.export constkeeps the split part exported.lower_variable_jsx_initializer(DOM and universal) and in the SSR statement flush. It only splits when that JSX actually has setup, the same as Babel._v$ = escape(Foo({ a: label }))) ran beforelabel. That is fixed too.No runtime code changed, so client bundle size is unchanged. RULES-FUNDAMENTALS and RULES-DERIVED don't apply here, because this is compiler statement order and not reactive semantics.
How did you test this change?
packages/babel-plugin/test/declarator-order.spec.jsruns the compiled output against a stub runtime in dom, dom hydratable, universal and ssr. All 8 tests fail on main and pass here. Babel suite: 440 passed, typecheck clean.packages/compiler/__tests__/parity-probes.test.js: native output is identical to Babel in every mode (4125 passed). Compiler vitest: 6952 passed.cargo testpasses for all three feature sets, and clippy-D warningsis clean.Generated by Claude Code