Visitar URL original
Fix JSX semicolon insertion by lukastaegert · Pull Request #6241 · rollup/rollup · GitHub
Skip to content

Fix JSX semicolon insertion - #6241

Merged
lukastaegert merged 2 commits into
masterfrom
fix-jsx-semicolon
Jan 21, 2026
Merged

lukastaegert merged 2 commits into
masterfrom
fix-jsx-semicolon

Conversation

@lukastaegert

@lukastaegert lukastaegert commented Jan 19, 2026 •

Copy link
Copy Markdown
Member

This PR contains:

  • bugfix
  • feature
  • refactor
  • documentation
  • other

Are tests included?

  • yes (bugfixes and features will not be merged without tests)
  • no

Breaking Changes?

  • yes (breaking changes will not be merged unless absolutely necessary)
  • no

List any relevant issue numbers:

Description

Previously, we fixed the semicolon insertion issue for ExpressionStatements by changing how the semicolon was inserted. However, we did not perform a similar change for VariableDeclarations, and here, the situation is a bit more complicated to fix.
The core of the problem was that when using automatic rendering mode, the "key" attribute could be moved to the end of a self-closing element, and moved code would always appear after any left-appended code.
This in turn affects ExpressionStatement and VariableDeclaration parents, which may want to append a semicolon.
For VariableDeclarations, rightAppending is not a solution because sometimes, the next declaration is removed, which would also remove the semicolon again.

The fix implemented here is never to move to the last position of the JSXElement but instead to the end of the non-key-attributes, which is always inside the element and does not cause issues.

Also revert previous hack to in ExpressionStatement that fixes the issue in some
situations.
Copilot AI review requested due to automatic review settings January 19, 2026 05:17
@vercel

vercel Bot commented Jan 19, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Review Updated (UTC)
rollup Ready Ready Preview, Comment Jan 19, 2026 5:17am

Request Review

@lukastaegert lukastaegert changed the title Fix JSX semicolon inseration Fix JSX semicolon insertion Jan 19, 2026
@github-actions

github-actions Bot commented Jan 19, 2026 •

Copy link
Copy Markdown

Thank you for your contribution! ❤️

You can try out this pull request locally by installing Rollup via

npm install rollup/rollup#fix-jsx-semicolon

Notice: Ensure you have installed the latest nightly Rust toolchain. If you haven't installed it yet, please see https://www.rust-lang.org/tools/install to learn how to download Rustup and install Rust.

or load it into the REPL:
https://rollup-en6xs0m7b-rollup-js.vercel.app/repl/?pr=6241

@github-actions

Copy link
Copy Markdown

Performance report

  • BUILD: 7055ms, 845 MB
    • initialize: 0ms, 24.6 MB
    • generate module graph: 2656ms, 635 MB
      • generate ast: 1403ms, 623 MB
    • sort and bind modules: 398ms, 698 MB
    • mark included statements: 3937ms, 845 MB
      • treeshaking pass 1: 2313ms, 834 MB
      • treeshaking pass 2: 462ms, 827 MB
      • treeshaking pass 3: 394ms, 846 MB
      • treeshaking pass 4: 382ms, 825 MB
      • treeshaking pass 5: 379ms, 845 MB
  • GENERATE: 682ms, 906 MB
    • initialize render: 0ms, 845 MB
    • generate chunks: 47ms, 827 MB
      • optimize chunks: 0ms, 822 MB
    • render chunks: 619ms, 879 MB
    • transform chunks: 16ms, 906 MB
    • generate bundle: 0ms, 906 MB

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes a bug where semicolons were incorrectly positioned or removed when transpiling JSX elements with key attributes in React's automatic JSX runtime mode. The issue occurred when the key attribute was moved to the end of the element, interfering with parent statement nodes (ExpressionStatement and VariableDeclaration) that needed to append semicolons.

Changes:

  • Fixed typo openindEnd → openingEnd in JSXElement.ts
  • Changed semicolon insertion to use attributesEnd instead of element end position to prevent interference with code movement
  • Changed ExpressionStatement semicolon insertion from appendRight to appendLeft for consistency
  • Added comprehensive test coverage for variable declarations with key attributes

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated no comments.

Show a summary per file
File Description
src/ast/nodes/JSXElement.ts Fixed typo and introduced attributesEnd logic to prevent semicolon removal when key attributes are moved
src/ast/nodes/ExpressionStatement.ts Changed semicolon insertion from appendRight to appendLeft for consistent positioning
test/form/samples/jsx/react-jsx-declarations-with-key-attribute/main.js Added test input with various JSX declaration scenarios with key attributes
test/form/samples/jsx/react-jsx-declarations-with-key-attribute/_expected.js Expected transpilation output showing correct semicolon placement
test/form/samples/jsx/react-jsx-declarations-with-key-attribute/_config.js Test configuration for react-jsx mode with key attribute handling
.github/copilot-instructions.md Added guidance to ignore style issues in test sample files and focus on production code

@codecov

codecov Bot commented Jan 19, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.81%. Comparing base (fc4d8f7) to head (3a45b96).
⚠️ Report is 4 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #6241   +/-   ##
=======================================
  Coverage   98.81%   98.81%           
=======================================
  Files         272      272           
  Lines       10720    10720           
  Branches     2870     2870           
=======================================
  Hits        10593    10593           
  Misses         85       85           
  Partials       42       42           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@lukastaegert
lukastaegert merged commit 726ce5d into master Jan 21, 2026
54 checks passed
@lukastaegert
lukastaegert deleted the fix-jsx-semicolon branch January 21, 2026 05:01
@github-actions

Copy link
Copy Markdown

This PR has been released as part of rollup@4.55.3. You can test it via npm install rollup.

This branch was successfully deployed

1 active deployment
Preview — 3a45b96c Deployed Jan 19, 2026 by vercel[bot]
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.

Extraneous Semicolons in JSX Output Causing Syntax Errors

2 participants