Skip to content

feat(rolldown): add isRolldownMagicString property for reliable native detection#8614

Merged
graphite-app[bot] merged 1 commit intomainfrom
03-10-feat_magicstring_tostringtag
Mar 10, 2026
Merged

feat(rolldown): add isRolldownMagicString property for reliable native detection#8614
graphite-app[bot] merged 1 commit intomainfrom
03-10-feat_magicstring_tostringtag

Conversation

@IWANABETHATGUY
Copy link
Member

@IWANABETHATGUY IWANABETHATGUY commented Mar 10, 2026

Summary

External packages like rolldown-string need to detect native BindingMagicString instances, but the existing obj.constructor.name check breaks under minification or bundling. This PR adds a reliable isRolldownMagicString boolean property to the BindingMagicString prototype via Object.defineProperty (non-writable, non-configurable). A new binding-magic-string.ts module centralizes the patching and re-exports the class with proper TypeScript typings. All internal imports now go through this module to ensure consistency. Tests cover prototype presence, instance access, and detection without importing rolldown.

Related

#7522

🤖 Generated with Claude Code

Copy link
Member Author


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.

@netlify
Copy link

netlify bot commented Mar 10, 2026

Deploy Preview for rolldown-rs ready!

Name Link
🔨 Latest commit b08184e
🔍 Latest deploy log https://app.netlify.com/projects/rolldown-rs/deploys/69b030db5c757000085a7608
😎 Deploy Preview https://deploy-preview-8614--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.

@IWANABETHATGUY IWANABETHATGUY changed the title feat: magic string constructor toString tag feat: add Symbol.toStringTag to BindingMagicString Mar 10, 2026
@IWANABETHATGUY IWANABETHATGUY marked this pull request as ready for review March 10, 2026 04:38
Copilot AI review requested due to automatic review settings March 10, 2026 04:38
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 adds Symbol.toStringTag = 'BindingMagicString' to the BindingMagicString prototype, enabling external packages to reliably detect native instances via obj[Symbol.toStringTag] === 'BindingMagicString' instead of the fragile constructor.name check.

Changes:

  • Introduces a new binding-magic-string.ts wrapper module that imports BindingMagicString from binding.cjs, patches its prototype with Symbol.toStringTag, and re-exports it.
  • Updates all runtime (non-type-only) imports of BindingMagicString to use the new wrapper module instead of binding.cjs directly.
  • Adds comprehensive tests verifying the Symbol.toStringTag behavior on prototypes, instances, and via Object.prototype.toString.

Reviewed changes

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

Show a summary per file
File Description
packages/rolldown/src/binding-magic-string.ts New wrapper module that patches BindingMagicString.prototype[Symbol.toStringTag] and re-exports the class
packages/rolldown/src/index.ts Updates public export to use the patched wrapper module
packages/rolldown/src/plugin/bindingify-build-hooks.ts Updates runtime import to use the patched wrapper module
packages/rolldown/src/plugin/bindingify-output-hooks.ts Updates runtime import to use the patched wrapper module
packages/rolldown/tests/magic-string/magic-string-to-string-tag.test.ts New test file verifying Symbol.toStringTag behavior

@IWANABETHATGUY IWANABETHATGUY marked this pull request as draft March 10, 2026 04:46
@IWANABETHATGUY IWANABETHATGUY force-pushed the 03-10-feat_magicstring_tostringtag branch from c85fbb4 to 024f0d9 Compare March 10, 2026 04:56
@IWANABETHATGUY IWANABETHATGUY marked this pull request as ready for review March 10, 2026 05:03
Copilot AI review requested due to automatic review settings March 10, 2026 05:03
Copy link
Member Author

IWANABETHATGUY commented Mar 10, 2026

Merge activity

  • Mar 10, 5:03 AM 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 10, 2:54 PM UTC: IWANABETHATGUY added this pull request to the Graphite merge queue.
  • Mar 10, 3:00 PM UTC: Merged by the Graphite merge queue.

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 7 out of 7 changed files in this pull request and generated no new comments.

@IWANABETHATGUY IWANABETHATGUY force-pushed the 03-10-feat_magicstring_tostringtag branch from 024f0d9 to afeba2f Compare March 10, 2026 05:41
@IWANABETHATGUY IWANABETHATGUY marked this pull request as draft March 10, 2026 05:49
@IWANABETHATGUY IWANABETHATGUY force-pushed the 03-10-feat_magicstring_tostringtag branch from afeba2f to 0c5522e Compare March 10, 2026 07:46
@IWANABETHATGUY IWANABETHATGUY marked this pull request as ready for review March 10, 2026 07:55
Copilot AI review requested due to automatic review settings March 10, 2026 07:55
@IWANABETHATGUY IWANABETHATGUY force-pushed the 03-10-feat_magicstring_tostringtag branch from 0c5522e to 82ddb03 Compare March 10, 2026 07:56
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 7 out of 7 changed files in this pull request and generated 1 comment.

@IWANABETHATGUY IWANABETHATGUY force-pushed the 03-10-feat_magicstring_tostringtag branch from 82ddb03 to 6ac16a2 Compare March 10, 2026 07:59
@IWANABETHATGUY IWANABETHATGUY changed the title feat: add Symbol.toStringTag to BindingMagicString feat(rolldown): add isRolldownMagicString property for reliable native detection Mar 10, 2026
@IWANABETHATGUY IWANABETHATGUY mentioned this pull request Mar 10, 2026
10 tasks
@IWANABETHATGUY IWANABETHATGUY requested a review from hyf0 March 10, 2026 09:14
Copy link
Member

@hyf0 hyf0 left a comment

Choose a reason for hiding this comment

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

Image

FYI: Your commits are not verified.


Sorry about the question tone, I talked to CC too much and got used to ask questions.

…e detection (#8614)

## Summary

External packages like `rolldown-string` need to detect native `BindingMagicString` instances, but the existing `obj.constructor.name` check breaks under minification or bundling. This PR adds a reliable `isRolldownMagicString` boolean property to the `BindingMagicString` prototype via `Object.defineProperty` (non-writable, non-configurable). A new `binding-magic-string.ts` module centralizes the patching and re-exports the class with proper TypeScript typings. All internal imports now go through this module to ensure consistency. Tests cover prototype presence, instance access, and detection without importing rolldown.

## Related

#7522

🤖 Generated with [Claude Code](https://claude.com/claude-code)
Copilot AI review requested due to automatic review settings March 10, 2026 14:55
@graphite-app graphite-app bot force-pushed the 03-10-feat_magicstring_tostringtag branch from 6ac16a2 to b08184e Compare March 10, 2026 14:55
@IWANABETHATGUY IWANABETHATGUY review requested due to automatic review settings March 10, 2026 14:55
@IWANABETHATGUY
Copy link
Member Author

Image FYI: Your commits are not verified.

Sorry about the question tone, I talked to CC too much and got used to ask questions.

This is because I sent a PR with a laptop that is not used often; the key is stale. will fix it

@graphite-app graphite-app bot merged commit b08184e into main Mar 10, 2026
30 checks passed
@graphite-app graphite-app bot deleted the 03-10-feat_magicstring_tostringtag branch March 10, 2026 15:00
@IWANABETHATGUY
Copy link
Member Author

Image FYI: Your commits are not verified. Sorry about the question tone, I talked to CC too much and got used to ask questions.

This is because I sent a PR with a laptop that is not used often; the key is stale. will fix it

image

There is a pro of graphite, it would auto-sign the commit when it is merged into the main branch .

graphite-app bot pushed a commit that referenced this pull request Mar 10, 2026
…8626)

from #8614 (comment)
## Summary

 Rename the exported `BindingMagicString` class to `RolldownMagicString` in the public API.

 Only the exported name is changed — internal TypeScript code continues to use `BindingMagicString` to keep naming consistent with the binding layer. The public rename aligns the class name with its detection flag `isRolldownMagicString` (introduced in #8614).

 ## Changes
 - Update the re-export in `packages/rolldown/src/index.ts`
 - Update test imports to use the new name
This was referenced Mar 11, 2026
shulaoda added a commit that referenced this pull request Mar 11, 2026
## [1.0.0-rc.9] - 2026-03-11

### 💥 BREAKING CHANGES

- rename exported BindingMagicString to RolldownMagicString (#8626) by @IWANABETHATGUY

### 🚀 Features

- rolldown: add isRolldownMagicString property for reliable native detection (#8614) by @IWANABETHATGUY
- cli: align object type with rollup (#8598) by @h-a-n-a

### 🐛 Bug Fixes

- rust: circular inter-chunk imports when external dynamic imports exist (#8596) by @Dunqing
- update minify default docs from `false` to `'dce-only'` (#8620) by @shulaoda

### 💼 Other

- fix early exit in script build-node (#8617) by @h-a-n-a

### 🚜 Refactor

- binding: remove outdated TODO comment in MagicString to_string() (#8613) by @IWANABETHATGUY

### 📚 Documentation

- add viteplus alpha announcement banner (#8615) by @mdong1909
- update VitePress theme to 4.8.2 for narrow-screen layout regression (#8612) by @Copilot

### ⚡ Performance

- merge 4 integration test binaries into 1 (#8610) by @Boshen

### 🧪 Testing

- replace heavy filename_with_hash test with targeted hash fixtures (#8597) by @Boshen

### ⚙️ Miscellaneous Tasks

- ci: remove redundant `--no-run` build step from cargo-test (#8623) by @Boshen
- rust: use `cargo-shear` to toggle Cargo.toml [lib] test = bool (#8622) by @Boshen
- deps: update test262 submodule for tests (#8611) by @sapphi-red
- skip macOS CI jobs on pull requests (#8608) by @Copilot
- add rust cache to repo validation job (#8607) by @Boshen
- skip running empty bin test targets (#8605) by @Boshen
- skip building examples in cargo-test to reduce build time (#8603) by @Boshen
- switch plain workflow checkouts to taiki-e action (#8601) by @Boshen
- skip Windows CI jobs on PRs (#8600) by @Boshen
- remove unused asset module (#8594) by @shulaoda

### ◀️ Revert

- "docs: add viteplus alpha announcement banner (#8615)" (#8616) by @shulaoda

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.

4 participants