Skip to content

Comments

fix: respect target setting in DCE to prevent modern syntax generation#7128

Merged
shulaoda merged 3 commits intomainfrom
copilot/fix-null-equals-syntax
Nov 23, 2025
Merged

fix: respect target setting in DCE to prevent modern syntax generation#7128
shulaoda merged 3 commits intomainfrom
copilot/fix-null-equals-syntax

Conversation

Copy link
Contributor

Copilot AI commented Nov 19, 2025

When target is set to es2015/es6, Rolldown was generating ES2020+ syntax like nullish coalescing (??, ??=) and optional chaining (?.). This broke output for environments that don't support these features.

Root Cause

The Dead Code Elimination (DCE) stage in pre_process_ecma_ast.rs wasn't passing the target configuration to OXC's CompressOptions, causing it to use modern syntax optimizations regardless of the configured target.

Changes

  • Pass target from transform options to CompressOptions during DCE:
let options = CompressOptions {
  target: bundle_options.transform_options.target.clone(),
  treeshake: TreeShakeOptions::from(&bundle_options.treeshake),
  ..CompressOptions::dce()
};
  • Add test case verifying null == x && (x = true) remains unchanged instead of transforming to x ??= true when target: "es2015"

Note: The minification stage already respects the target setting via minify_options.rs:49 and minify_options.rs:67.

Original prompt

This section details on the original issue you should resolve

<issue_title>[Bug]: generate ?? syntax when set target=es6/es2015</issue_title>
<issue_description>### Reproduction link or steps

index.js

null == e && (e=!0)

rollodown.config.js

export default defineConfig({
    target: 'es6',
    input: 'index.js',
    output: {
        file: 'bundle.js',
        
  
        minify: false 
    }
})

bundle.js

 t ?? !0

REPL

The problem

the syntax null == t && (t=!0) is converted to t ?? !0
es6 does not support ?? syntax .
By setting minify: false , it continues to generate ??

What is expected?

doest not generate ?? syntax

What is actually happening?

the syntax null == t && (t=!0) is converted to t ?? !0

System Info

mac pro M2
nodejs : v24.4.1
rolldown: 1.0.0-beta.51

Any additional comments?

No response</issue_description>

Comments on the Issue (you are @copilot in this section)

@TheAlexLichter Fails in [Rolldown REPL](https://repl.rolldown.rs/#eNptkMFqAyEQhl9l6iHbwiI99SDsMxR63ovNjsGi46Jjm7D47nU1aQvNRZz5v/nQ2YQRahOWFjxLTvudhPqtR3GsJWXnYJoA4XCAR5wenp9qgkJxzFhGEYNzS/gieQxk7OmP6E7SldavITLwZUXY4O2Kva5sAyUoYGLwMNzGh5lmqorE0EXq38gE20wAltbMCrpeemQtW2vcQ46akgnRqw7Xjo4nrPyA6WVoTGlnyNw8V8xYhxV6z7Q4lB9pR3viLVlzUWC0S/gjKHuM5/bFBY3O7vbwmUSpG/usK3CaMbEo3+YWgvQ=)

(Updated to it doesn't use top-level target)

Works fine in Oxc REPL</comment_new>


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

@graphite-app
Copy link
Contributor

graphite-app bot commented Nov 19, 2025

How to use the Graphite Merge Queue

Add the label graphite: merge to this PR to add it to the merge queue.

You must have a Graphite account in order to use the merge queue. Sign up using this link.

An organization admin has enabled the Graphite Merge Queue in this repository.

Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue.

@netlify
Copy link

netlify bot commented Nov 19, 2025

Deploy Preview for rolldown-rs canceled.

Name Link
🔨 Latest commit 0620d45
🔍 Latest deploy log https://app.netlify.com/projects/rolldown-rs/deploys/6922cb3e42a4610008c0d645

Copilot AI changed the title [WIP] Fix generation of invalid ?? syntax for ES6 target Fix: Respect target setting in DCE to prevent modern syntax generation Nov 19, 2025
Copilot AI requested a review from shulaoda November 19, 2025 12:49
@github-actions
Copy link
Contributor

github-actions bot commented Nov 19, 2025

Benchmarks Rust

group                                                        pr                                     target
-----                                                        --                                     ------
bundle/bundle@multi-duplicated-top-level-symbol              1.00     68.9±1.17ms        ? ?/sec    1.07     73.4±2.74ms        ? ?/sec
bundle/bundle@multi-duplicated-top-level-symbol-sourcemap    1.00     75.2±1.00ms        ? ?/sec    1.07     80.3±1.34ms        ? ?/sec
bundle/bundle@rome_ts                                        1.01    114.9±2.32ms        ? ?/sec    1.00    113.3±1.48ms        ? ?/sec
bundle/bundle@rome_ts-sourcemap                              1.00    127.9±2.56ms        ? ?/sec    1.00    127.4±1.52ms        ? ?/sec
bundle/bundle@threejs                                        1.00     42.3±2.26ms        ? ?/sec    1.02     43.2±2.00ms        ? ?/sec
bundle/bundle@threejs-sourcemap                              1.00     46.4±0.43ms        ? ?/sec    1.01     46.7±0.69ms        ? ?/sec
bundle/bundle@threejs10x                                     1.00    419.9±3.99ms        ? ?/sec    1.00    419.6±3.68ms        ? ?/sec
bundle/bundle@threejs10x-sourcemap                           1.05   515.1±11.31ms        ? ?/sec    1.00    490.2±2.80ms        ? ?/sec
scan/scan@rome_ts                                            1.05     90.7±1.55ms        ? ?/sec    1.00     86.5±1.20ms        ? ?/sec
scan/scan@threejs                                            1.04     30.7±1.84ms        ? ?/sec    1.00     29.6±1.83ms        ? ?/sec
scan/scan@threejs10x                                         1.06    315.1±5.26ms        ? ?/sec    1.00    297.0±2.51ms        ? ?/sec

@shulaoda shulaoda force-pushed the copilot/fix-null-equals-syntax branch from 03b7029 to 0620d45 Compare November 23, 2025 08:52
@shulaoda shulaoda marked this pull request as ready for review November 23, 2025 08:52
Copilot AI review requested due to automatic review settings November 23, 2025 08:52
@shulaoda shulaoda changed the title Fix: Respect target setting in DCE to prevent modern syntax generation fix: respect target setting in DCE to prevent modern syntax generation Nov 23, 2025
Copy link
Contributor

Copilot AI left a comment

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 Rolldown was generating ES2020+ syntax (nullish coalescing ?? and optional chaining ?.) even when the target option was set to es2015 or es6. The root cause was that the Dead Code Elimination (DCE) stage wasn't passing the target configuration to OXC's CompressOptions.

Key Changes:

  • Modified the DCE stage to respect the target setting by passing bundle_options.transform_options.target to CompressOptions
  • Added comprehensive test case validating that ES2015-incompatible syntax transformations are prevented

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
crates/rolldown/src/utils/pre_process_ecma_ast.rs Added target field to CompressOptions initialization during DCE stage to match minification stage behavior
crates/rolldown/tests/rolldown/issues/nullish_coalescing_es6/main.js Test input with nullish coalescing pattern and optional chaining pattern that should not be transformed
crates/rolldown/tests/rolldown/issues/nullish_coalescing_es6/_config.json Test configuration setting target: "es2015" and minify: false
crates/rolldown/tests/rolldown/issues/nullish_coalescing_es6/artifacts.snap Expected output snapshot showing no transformation to modern syntax
crates/rolldown/tests/snapshots/integration_rolldown__filename_with_hash.snap Hash snapshot update for new test case

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@shulaoda shulaoda merged commit dcc53bd into main Nov 23, 2025
35 checks passed
@shulaoda shulaoda deleted the copilot/fix-null-equals-syntax branch November 23, 2025 09:27
This was referenced Nov 26, 2025
shulaoda added a commit that referenced this pull request Nov 26, 2025
## [1.0.0-beta.52] - 2025-11-26

💥 Breaking Change

- Change `output.generatedCode.profilerNames` default to `false`

🔧 Vite-Style TypeScript Configuration

- Rolldown now supports Vite-style automatic tsconfig resolution. Use `tsconfig: true` to enable auto-discovery mode where each module finds its nearest `tsconfig.json`. See more details [here](https://rolldown.rs/options/tsconfig)

⚙️ Upgraded to oxc v0.99.0

- Add `TSGlobalDeclaration` type
- More details: https://github.com/oxc-project/oxc/releases/tag/crates_v0.99.0

### 💥 BREAKING CHANGES

- change `output.generatedCode.profilerNames` default to false (#7139) by @Copilot

### 🚀 Features

- support vite-style tsconfig resolution (#6873) by @shulaoda
- rolldown: oxc v0.99.0  (#7165) by @camc314
- browser: export `plugins` (#7210) by @sxzz
- rolldown_plugin_vite_css_post: add `inline` parameter to `cssMinify` callback (#7191) by @shulaoda
- rolldown_plugin_vite_build_import_analysis: implement `render_chunk` to replace `__VITE_IS_MODERN__` flag (#7178) by @shulaoda
- rolldown_plugin_utils: optimize SVG data URL encoding (#7156) by @shulaoda
- dev: replace `DevEngine::hasLatestBuildOutput` with `DevEngine::getBundleState` (#7145) by @sapphi-red
- rolldown_plugin_vite_asset_import_meta_url: support `@vite-ignore` comment (#7141) by @shulaoda
- rolldown_plugin_vite_asset_import_meta_url: implement static URL processing (#7140) by @shulaoda
- rolldown_plugin_vite_asset_import_meta_url: align `asset_resolver` logic (#7137) by @shulaoda
- rolldown_plugin_vite_asset_import_meta_url: align `try_fs_resolve` logic (#7136) by @shulaoda
- rolldown_plugin_vite_asset_import_meta_url: validate relative paths (#7120) by @shulaoda
- export `viteAssetImportMetaUrlPlugin` and add dynamic URL tests (#7119) by @shulaoda

### 🐛 Bug Fixes

- watch overwrite rename event on linux (#7201) by @sapphi-red
- preserve name for parenthesized anonymous default exports and arrow functions with keepNames (#7159) by @Copilot
- rolldown_plugin_vite_html: add missing async attribute for inlined entry scripts (#7202) by @shulaoda
- respect target setting in DCE to prevent modern syntax generation (#7128) by @Copilot
- rolldown_plugin_vite_html: add semicolon to import statement in CSS removal (#7200) by @shulaoda
- rolldown_plugin_vite_html: use correct CSS asset filename in HTML injection (#7199) by @shulaoda
- rolldown_plugin_vite_css_post: handle scoped package names in lib CSS filename (#7198) by @shulaoda
- rolldown_plugin_vite_html: use patched `html5gum` with correct span tracking (#7193) by @shulaoda
- rolldown_plugin_vite_html: handle HTML strings in script tags correctly (#7192) by @shulaoda
- handle JSON import namespace property access correctly (#7190) by @IWANABETHATGUY
- only include runtime helpers from included modules (#7183) by @IWANABETHATGUY
- rolldown_plugin_vite_html: normalize paths to use forward slashes in `original_file_name` (#7175) by @shulaoda
- rolldown_plugin_vite_css_post: use `filename` instead of `reference_id` for imported assets (#7174) by @shulaoda
- rolldown_plugin_vite_css_post: correct regex escaping in pure CSS chunk pruning (#7173) by @shulaoda
- rolldown_plugin_vite_html: use correct dependency path for modulepreload links (#7172) by @shulaoda
- update cur_stmt_index when processing top level statements (#7157) by @IWANABETHATGUY
- rolldown_plugin_utils: strip leading character from public asset URL (#7170) by @shulaoda
- rolldown_plugin_vite_html: use correct `public_base` for `html_result_map` key (#7169) by @shulaoda
- rolldown_plugin_utils: correct runtime handling and escape single quotes in asset paths (#7168) by @shulaoda
- rolldown_plugin_utils: prevent data race in `file_to_url` cache (#7166) by @shulaoda
- rolldown_plugin_vite_asset_import_meta_url: correct glob pattern and query string handling in dynamic URLs (#7162) by @shulaoda
- rolldown_plugin_vite_css_post: use correct start position in magic string updates (#7158) by @shulaoda
- data race in `FileEmitter::emit_file` causing duplicate asset emissions (#7164) by @shulaoda
- dev: watch files even if the build failed (#7149) by @sapphi-red
- rolldown_plugin_utils: always use base64 encoding for data URLs (#7148) by @shulaoda
- preserve "default" name for anonymous default exports with keepNames (#7151) by @Copilot
- correctly handle cjs json module as entry point (#7147) by @IWANABETHATGUY
- rolldown_plugin_utils: correct `reference_id` parsing in `render_asset_url_in_js` (#7143) by @shulaoda
- rolldown_plugin_vite_asset_import_meta_url: exclude quotes from URL span (#7142) by @shulaoda
- rolldown_plugin_vite_asset_import_meta_url: use template literal for glob result indexing (#7134) by @shulaoda
- tree shake unused dynamic entry when `inlineDynamicImports` is enabled (#7129) by @IWANABETHATGUY
- correct return value of `parse` / `parseSync` functions (#7127) by @sapphi-red

### 🚜 Refactor

- rolldown_plugin_vite_transform: use `oxc_resolver` for tsconfig discovery (#7220) by @shulaoda
- rolldown_plugin_vite_resolve: use `resolve_file` for tsconfig discovery (#7216) by @shulaoda
- rolldown_plugin_utils: remove redundant `ViteMetadata::get_or_insert_default()` (#7189) by @shulaoda
- rolldown_plugin_utils: simplify `ViteMetadata::get()` to always return a value (#7188) by @shulaoda
- rolldown_utils: add `guess_mime_skip_utf8_check` for binary assets (#7161) by @shulaoda
- rolldown_plugin_utils: extract asset URL parsing into `AssetUrlIter` (#7144) by @shulaoda
- store pattern name in FilenameTemplate (#7132) by @IWANABETHATGUY

### 📚 Documentation

- tsconfig: document auto-discovery mode and improve structure (#7228) by @shulaoda
- add plugin hook filter compatibility and fallback guide (#7138) by @Copilot
- update top level navigation (#7092) by @mdong1909

### 🧪 Testing

- add tsconfig include/exclude/files matching test cases (#6899) by @shulaoda
- vite-tests: run `playwright install` in case playwright binary is missing (#7226) by @sapphi-red
- watch: close watcher when an error occured in the test cases (#7225) by @sapphi-red
- watch: reject `waitBuildFinished` if `ERROR` event occurs (#7224) by @sapphi-red

### ⚙️ Miscellaneous Tasks

- example: revert accidental changes to basic-typescript (#7227) by @shulaoda
- deps: update oxc apps (#7212) by @renovate[bot]
- deps: update rust crates (#7204) by @renovate[bot]
- deps: update `oxc_resolver_napi` to 11.14.0 (#7217) by @shulaoda
- deps: update oxc_resolver (#6909) by @shulaoda
- deps: update dependency glob to v13 (#7208) by @renovate[bot]
- deps: update actions/checkout action to v6 (#7207) by @renovate[bot]
- deps: update npm packages (#7206) by @renovate[bot]
- deps: update github-actions (#7205) by @renovate[bot]
- add missing status code comment (#7185) by @iiio2
- deps: update dependency oxlint-tsgolint to v0.8.1 (#7197) by @renovate[bot]
- rust: add more tracing log for hmr + dev logic (#7179) by @hyf0
- deps: update dependency oxlint-tsgolint to v0.8.0 (#7167) by @renovate[bot]
- deps: update dependency oxlint-tsgolint to v0.7.3 (#7133) by @renovate[bot]
- merge similar inlineDynamicImports test case (#7131) by @IWANABETHATGUY
- deps: update `rolldown-plugin-dts` to 0.18.0 (#7125) by @shulaoda

Co-authored-by: shulaoda <[email protected]>
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.

[Bug]: generate ?? syntax when set target=es6/es2015

2 participants