Skip to content

fix: Use globalThis to prevent environment check code from being re…#44

Merged
slevithan merged 1 commit into
slevithan:mainfrom
xiaweiss:fix-rolldown-v-tag-error
Mar 13, 2026
Merged

fix: Use globalThis to prevent environment check code from being re…#44
slevithan merged 1 commit into
slevithan:mainfrom
xiaweiss:fix-rolldown-v-tag-error

Conversation

@xiaweiss

Copy link
Copy Markdown
Contributor

fix #42

When bundling with Rolldown or tsdown, enabling code minification (compression) or tree-shaking (pruning) will cause the environment check code to be removed.

Works fine with esbuild and Rollup, they won’t remove it.

Before bundling

var envFlags = {
  flagGroups: (() => {
    try {
      new RegExp("(?i:)");
    } catch {
      return false;
    }
    return true;
  })(),
  unicodeSets: (() => {
    try {
      new RegExp("[[]]", "v");
    } catch {
      return false;
    }
    return true;
  })()
};

After bundling

var envFlags = {
  flagGroups: true,
  unicodeSets: true
};

Replacing RegExp with globalThis.RegExp can prevent this behavior.

Copilot AI review requested due to automatic review settings March 11, 2026 10:35

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Fixes incorrect tree-shaking/minification by some bundlers (Rolldown/tsdown) that were removing runtime RegExp feature-detection logic, which could cause envFlags to be incorrectly constant-folded.

Changes:

  • Switched RegExp feature checks to use globalThis.RegExp to avoid bundler removal/constant-folding.
  • Added an inline note explaining the bundler-related rationale.

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

Comment thread src/utils.js
@slevithan slevithan merged commit bd9a2dd into slevithan:main Mar 13, 2026
6 of 7 checks passed
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.

Error does not support the v tag

3 participants