Skip to content

feat(binding): add original getter to BindingMagicString#8533

Merged
graphite-app[bot] merged 1 commit intomainfrom
03-03-feat_magicstring_original
Mar 3, 2026
Merged

feat(binding): add original getter to BindingMagicString#8533
graphite-app[bot] merged 1 commit intomainfrom
03-03-feat_magicstring_original

Conversation

@IWANABETHATGUY
Copy link
Member

@IWANABETHATGUY IWANABETHATGUY commented Mar 3, 2026

Summary\n\n- Ports the original property from the JavaScript magic-string library to BindingMagicString\n- Exposes the unmodified source string passed to the constructor as a read-only getter\n- Updates the generated TypeScript type definition (binding.d.cts)\n\nNote: The offset getter/setter and constructor option visible in this diff are from the parent PR #8531 (stacked beneath this one).\n\nPart of #7522.

Copilot AI review requested due to automatic review settings March 3, 2026 08:19
@netlify
Copy link

netlify bot commented Mar 3, 2026

Deploy Preview for rolldown-rs ready!

Name Link
🔨 Latest commit 1d8c626
🔍 Latest deploy log https://app.netlify.com/projects/rolldown-rs/deploys/69a69991bf5f3c000848dd7b
😎 Deploy Preview https://deploy-preview-8533--rolldown-rs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@netlify
Copy link

netlify bot commented Mar 3, 2026

Deploy Preview for rolldown-rs canceled.

Name Link
🔨 Latest commit 8552549
🔍 Latest deploy log https://app.netlify.com/projects/rolldown-rs/deploys/69a6d0dd97c9e70008bc2038

@IWANABETHATGUY IWANABETHATGUY force-pushed the 03-03-feat_magicstring_original branch from 12a0cb1 to 7768963 Compare March 3, 2026 08:22
Copy link
Member Author

IWANABETHATGUY commented Mar 3, 2026


How to use the Graphite Merge Queue

Add the label graphite: merge-when-ready 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.

This stack of pull requests is managed by Graphite. Learn more about stacking.

@IWANABETHATGUY IWANABETHATGUY changed the base branch from main to graphite-base/8533 March 3, 2026 08:23
@IWANABETHATGUY IWANABETHATGUY force-pushed the 03-03-feat_magicstring_original branch from 7768963 to e0653c5 Compare March 3, 2026 08:23
@IWANABETHATGUY IWANABETHATGUY changed the base branch from graphite-base/8533 to worktree-validated-gliding-crescent March 3, 2026 08:23
@IWANABETHATGUY IWANABETHATGUY marked this pull request as draft March 3, 2026 08:23
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

Adds parity features to BindingMagicString to better match the JavaScript magic-string API by exposing access to the original source string and expanding offset support across position-based operations.

Changes:

  • Expose original as a read-only getter on BindingMagicString (and update TS typings).
  • Implement and surface offset (constructor option + getter/setter) and apply it across index-based operations in the Rust binding.
  • Add/enable tests covering original and offset behavior.

Reviewed changes

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

Show a summary per file
File Description
packages/rolldown/tests/magic-string/magic-string-original.test.ts Adds dedicated tests for the new original getter (including behavior with offset/clone).
packages/rolldown/tests/magic-string/download-tests.mjs Updates documentation/skip rules around supported BindingMagicString API and offset-related test skipping.
packages/rolldown/tests/magic-string/MagicString.test.ts Enables the upstream-derived “with offset” test case.
packages/rolldown/src/binding.d.cts Updates generated TS declarations to include original and offset (incl. constructor option).
crates/rolldown_binding/src/types/binding_magic_string.rs Implements original getter and offset plumbing in the N-API Rust binding.
Comments suppressed due to low confidence (1)

crates/rolldown_binding/src/types/binding_magic_string.rs:276

  • apply_offset_u32 performs (i64::from(index) + self.offset) as u32 with suppressed clippy lints. If offset is negative (or large enough to overflow), this can wrap to a huge u32 and then the subsequent char_to_byte(...).expect(...) calls will panic, potentially crashing the process. Consider validating/clamping offset in the setter/constructor and using checked arithmetic + returning a napi::Result error (instead of panicking) for all offset-adjusted index conversions.
  pub fn set_offset(&mut self, offset: i64) {
    self.offset = offset;
  }

  /// Applies `self.offset` to a u32 character index.
  #[inline]
  fn apply_offset_u32(&self, index: u32) -> u32 {
    #[expect(clippy::cast_sign_loss, clippy::cast_possible_truncation)]

@IWANABETHATGUY IWANABETHATGUY changed the base branch from worktree-validated-gliding-crescent to graphite-base/8533 March 3, 2026 08:52
@IWANABETHATGUY IWANABETHATGUY force-pushed the 03-03-feat_magicstring_original branch from e0653c5 to a2a8164 Compare March 3, 2026 09:43
@IWANABETHATGUY IWANABETHATGUY changed the base branch from graphite-base/8533 to worktree-validated-gliding-crescent March 3, 2026 09:43
@IWANABETHATGUY IWANABETHATGUY force-pushed the 03-03-feat_magicstring_original branch from a2a8164 to 6dfa9f9 Compare March 3, 2026 10:06
@IWANABETHATGUY IWANABETHATGUY force-pushed the worktree-validated-gliding-crescent branch from 039395c to 242491e Compare March 3, 2026 10:06
@graphite-app graphite-app bot changed the base branch from worktree-validated-gliding-crescent to graphite-base/8533 March 3, 2026 10:16
@graphite-app graphite-app bot force-pushed the 03-03-feat_magicstring_original branch from 6dfa9f9 to 71835a1 Compare March 3, 2026 10:28
@graphite-app graphite-app bot force-pushed the graphite-base/8533 branch from 242491e to 5f5768f Compare March 3, 2026 10:28
@graphite-app graphite-app bot changed the base branch from graphite-base/8533 to main March 3, 2026 10:28
@graphite-app graphite-app bot force-pushed the 03-03-feat_magicstring_original branch from 71835a1 to 90328d5 Compare March 3, 2026 10:28
@IWANABETHATGUY IWANABETHATGUY marked this pull request as ready for review March 3, 2026 11:52
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

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

Copy link
Member Author

IWANABETHATGUY commented Mar 3, 2026

Merge activity

  • Mar 3, 12:07 PM UTC: The merge label 'graphite: merge-when-ready' was detected. This PR will be added to the Graphite merge queue once it meets the requirements.
  • Mar 3, 12:14 PM UTC: IWANABETHATGUY added this pull request to the Graphite merge queue.
  • Mar 3, 12:27 PM UTC: Merged by the Graphite merge queue.

Summary\n\n- Ports the original property from the JavaScript magic-string library to BindingMagicString\n- Exposes the unmodified source string passed to the constructor as a read-only getter\n- Updates the generated TypeScript type definition (binding.d.cts)\n\nNote: The offset getter/setter and constructor option visible in this diff are from the parent PR #8531 (stacked beneath this one).\n\nPart of #7522.
@graphite-app graphite-app bot force-pushed the 03-03-feat_magicstring_original branch from 6175a19 to 8552549 Compare March 3, 2026 12:15
@graphite-app graphite-app bot merged commit 8552549 into main Mar 3, 2026
34 checks passed
@graphite-app graphite-app bot deleted the 03-03-feat_magicstring_original branch March 3, 2026 12:27
This was referenced Mar 4, 2026
shulaoda added a commit that referenced this pull request Mar 5, 2026
## [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>
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.

3 participants