feat: add output.strict option to control "use strict" directive emission#8489
feat: add output.strict option to control "use strict" directive emission#8489
output.strict option to control "use strict" directive emission#8489Conversation
✅ Deploy Preview for rolldown-rs ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
output.strict option to control "use strict" directive emission
crates/rolldown/tests/rolldown/misc/use_strict/strict_always_cjs/main.js
Show resolved
Hide resolved
Co-authored-by: shulaoda <165626830+shulaoda@users.noreply.github.com>
… source Co-authored-by: IWANABETHATGUY <17974631+IWANABETHATGUY@users.noreply.github.com>
54e010d to
092b4a1
Compare
ffaa3eb to
828b684
Compare
output.strict option to control "use strict" directive emissionoutput.strict option to control "use strict" directive emission
There was a problem hiding this comment.
Pull request overview
This PR adds a new output.strict option to control whether "use strict" directives are emitted in generated output (primarily affecting non-ESM formats), threading the option through TypeScript options, NAPI bindings, Rust options normalization, and code generation, with new integration tests and snapshot updates.
Changes:
- Introduce
StrictModeinrolldown_commonand plumbstrictthroughBundlerOptions→NormalizedBundlerOptions→ build context preparation. - Expose
strictin TypeScriptOutputOptions, validator schema, and NAPI binding types/normalization. - Update code generation to apply
strictbehavior and reuse a sharedis_use_strict_directivehelper; add/refresh tests & snapshots.
Reviewed changes
Copilot reviewed 31 out of 31 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| packages/rolldown/tests/cli/snapshots/cli-e2e.test.ts.snap | Updates CLI help snapshot to include --strict. |
| packages/rolldown/src/utils/validator.ts | Adds strict validation (`boolean |
| packages/rolldown/src/utils/bindingify-output-options.ts | Passes outputOptions.strict into binding output options. |
| packages/rolldown/src/options/output-options.ts | Adds `strict?: boolean |
| packages/rolldown/src/binding.d.cts | Regenerates binding types to include strict. |
| crates/rolldown_testing_config/src/config_variant.rs | Adds strict to test config variants and formatting. |
| crates/rolldown_testing/_config.schema.json | Extends test config JSON schema with StrictMode and strict fields. |
| crates/rolldown_common/src/lib.rs | Re-exports StrictMode from bundler options types. |
| crates/rolldown_common/src/inner_bundler_options/types/strict_mode.rs | Introduces StrictMode enum and conversions. |
| crates/rolldown_common/src/inner_bundler_options/types/normalized_bundler_options.rs | Adds normalized strict: StrictMode field + default. |
| crates/rolldown_common/src/inner_bundler_options/types/mod.rs | Registers the new strict_mode module. |
| crates/rolldown_common/src/inner_bundler_options/mod.rs | Adds strict: Option<StrictMode> to BundlerOptions. |
| crates/rolldown_binding/src/utils/normalize_binding_options.rs | Maps NAPI strict into Rust StrictMode. |
| crates/rolldown_binding/src/options/binding_output_options/mod.rs | Exposes strict in NAPI output options (`boolean |
| crates/rolldown/tests/snapshots/integration_rolldown__filename_with_hash.snap | Snapshot updates for new strict-mode test fixtures. |
| crates/rolldown/tests/rolldown/misc/use_strict/strict_never_cjs/main.js | Adds integration test input for strict: never (CJS). |
| crates/rolldown/tests/rolldown/misc/use_strict/strict_never_cjs/artifacts.snap | Adds expected output snapshot for strict: never (CJS). |
| crates/rolldown/tests/rolldown/misc/use_strict/strict_never_cjs/_config.json | Adds test config for strict: never (CJS). |
| crates/rolldown/tests/rolldown/misc/use_strict/strict_always_esm/main.js | Adds integration test input for strict: always (ESM). |
| crates/rolldown/tests/rolldown/misc/use_strict/strict_always_esm/artifacts.snap | Adds expected output snapshot for strict: always (ESM). |
| crates/rolldown/tests/rolldown/misc/use_strict/strict_always_esm/_config.json | Adds test config for strict: always (ESM). |
| crates/rolldown/tests/rolldown/misc/use_strict/strict_always_cjs_dedup/main.js | Adds dedup integration test input (entry already has 'use strict'). |
| crates/rolldown/tests/rolldown/misc/use_strict/strict_always_cjs_dedup/artifacts.snap | Adds expected output snapshot for dedup behavior. |
| crates/rolldown/tests/rolldown/misc/use_strict/strict_always_cjs_dedup/_config.json | Adds test config for dedup case (strict: always, CJS). |
| crates/rolldown/tests/rolldown/misc/use_strict/strict_always_cjs/main.js | Adds integration test input for strict: always (CJS). |
| crates/rolldown/tests/rolldown/misc/use_strict/strict_always_cjs/artifacts.snap | Adds expected output snapshot for strict: always (CJS). |
| crates/rolldown/tests/rolldown/misc/use_strict/strict_always_cjs/_config.json | Adds test config for strict: always (CJS). |
| crates/rolldown/src/utils/prepare_build_context.rs | Threads strict into NormalizedBundlerOptions. |
| crates/rolldown/src/ecmascript/format/utils/mod.rs | Adds shared is_use_strict_directive helper. |
| crates/rolldown/src/ecmascript/format/esm.rs | Uses shared helper to filter "use strict" from ESM directives. |
| crates/rolldown/src/ecmascript/ecma_generator.rs | Applies output.strict policy to directives during chunk instantiation. |
crates/rolldown_common/src/inner_bundler_options/types/strict_mode.rs
Outdated
Show resolved
Hide resolved
Co-authored-by: shulaoda <165626830+shulaoda@users.noreply.github.com>
Benchmarks Rust |
Co-authored-by: shulaoda <165626830+shulaoda@users.noreply.github.com>
There was a problem hiding this comment.
LGTM. We should update https://rolldown.rs/in-depth/directives as well
Co-authored-by: 翠 <green@sapphi.red> Signed-off-by: dalaoshu <165626830+shulaoda@users.noreply.github.com>
Do you mean we should update it for |
## [1.0.0-rc.7] - 2026-03-05 ⚡ Smarter Code Generation Defaults - DCE-only minification and smart constant inlining are now enabled by default - Produces cleaner, smaller output bundles without requiring explicit configuration 💡 LLM-Friendly Bundle Analyzer Reports - New markdown output format for the bundle analyzer plugin with bundle summaries, module graphs, dependency chains, and optimization suggestions - Optimization suggestions now also recommend using the entriesAware option when common chunks contain modules only reachable from specific entries ### 💥 BREAKING CHANGES - enable minify: 'dce-only' by default (#8465) by @IWANABETHATGUY - settings `inlineConst: { mode: 'smart', pass: 1}` by default (#8444) by @IWANABETHATGUY ### 🚀 Features - binding: add original getter to BindingMagicString (#8533) by @IWANABETHATGUY - native-magic-string: add `offset` property support (#8531) by @IWANABETHATGUY - add `output.strict` option to control `"use strict"` directive emission (#8489) by @Copilot - watch: expose `watcher.compareContentsForPolling` (#8526) by @hyf0 - watch: use new watcher to support watch mode (#8475) by @hyf0 - rust/watch: handle bulk-change (#8466) by @hyf0 - add LLM-friendly markdown output format to bundle analyzer plugin (#8242) by @IWANABETHATGUY ### 🐛 Bug Fixes - expose `plugins` on `NormalizedInputOptions` for `buildStart` hook (#8521) by @Copilot - only uppercase facade symbols in JSX preserve mode (#8519) by @IWANABETHATGUY - binding: export BindingResult in generated dts header (#8537) by @minsoo-web - pre-resolve paths option to avoid `invoke_sync` deadlock (#8518) by @IWANABETHATGUY - remove debug-only jsx_preset and UntranspiledSyntaxError (#8511) by @IWANABETHATGUY - apply `topLevelVar` to exported `const`/`let` declarations (#8507) by @IWANABETHATGUY - rolldown_plugin_vite_web_worker_post: avoid replacing `new.target` (#8488) by @sapphi-red - update copyright year to 2026 (#8486) by @maciekzygmunt ### 🚜 Refactor - rust: use Oxc's SymbolFlags::ConstVariable instead of custom IsConst flag (#8543) by @Dunqing - rust: remove FacadeScoping, use Scoping::create_symbol for facade symbols (#8540) by @Dunqing - rust/watch: remove hacky `reset_closed_for_watch_mode` (#8530) by @hyf0 - binding: return &str instead of String in filename() getter (#8534) by @IWANABETHATGUY - rust: remove old watch mode implementation (#8525) by @hyf0 - rust/watch: simply watch logic in the binding layer (#8516) by @hyf0 - rust/watch: tweak struct/function names (#8464) by @hyf0 ### 📚 Documentation - explain how external modules work in rolldown (#8457) by @sapphi-red - add some diagrams using graphviz (#8499) by @sapphi-red - use `vitepress-plugin-graphviz` (#8498) by @sapphi-red - list s390x/ppc64le prebuilt binaries (#8495) by @crusty-voidzero - fix error type for `RolldownBuild.generate` and others (#8490) by @sapphi-red ### ⚡ Performance - string_wizard: reduce allocations and add ASCII fast paths (#8541) by @IWANABETHATGUY - use IndexBitSet to replace IndexVec<XXXIdx, bool> for module/stmt inclusion tracking (#8503) by @IWANABETHATGUY - plugin: use IndexBitSet to optimize skipped plugins checking (#8497) by @ShroXd - rust/tla: skip compute_tla if there is no module use TLA (#8487) by @ShroXd ### 🧪 Testing - node/watch: make watch tests run in concurrent and retry-able (#8512) by @hyf0 - add test case for static flag tree-shaking (#8476) by @IWANABETHATGUY - migrate post-banner sourcemap-with-shebang to Rust (#8477) by @Copilot ### ⚙️ Miscellaneous Tasks - vscode: `formatOnSave` for markdown files using oxc formatter (#8536) by @minsoo-web - deps: update test262 submodule for tests (#8528) by @sapphi-red - remove `retry` workaround from output paths test fixtures (#8520) by @Copilot - docs: add Shuyuan Wang (h-a-n-a) and remove from acknowledgements (#8509) by @Copilot - consolidate top_level_var test cases using configVariants (#8508) by @IWANABETHATGUY - add s390x and ppc64le linux gnu targets (#8493) by @Brooooooklyn ###◀️ Revert - fix(rolldown): increase tokio blocking threads size for watch mode (#8517) by @hyf0 ### ❤️ New Contributors * @minsoo-web made their first contribution in [#8536](#8536) * @crusty-voidzero made their first contribution in [#8495](#8495) * @maciekzygmunt made their first contribution in [#8486](#8486) Co-authored-by: shulaoda <165626830+shulaoda@users.noreply.github.com>
StrictModeenum in Rust (rolldown_common)strictfield toBundlerOptionsstructstrictfield toNormalizedBundlerOptionsstructstrictinprepare_build_context.rsstricttoBindingOutputOptions(NAPI bindings)strictinnormalize_binding_options.rsis_use_strict_directivehelper in format utilsecma_generator.rsto handlestrictoption using shared helperis_use_strict_directivehelperstrictto TypeScriptOutputOptionsinterface with JSDocstrictto validator schemastrictthroughbindingify-output-options.tsstricttoConfigVariantfor Rust testsstrict_always_cjs,strict_never_cjs,strict_always_esmstrict_always_cjs_dedupFrom<String>withTryFrom<&str>forStrictMode; update binding normalization to propagate a propernapi::Erroron invalid inputbinding.d.ctsOriginal prompt
"use strict"is not injected for CJS builds #5865🔒 GitHub Advanced Security automatically protects Copilot coding agent pull requests. You can protect all pull requests by enabling Advanced Security for your repositories. Learn more about Advanced Security.