Skip to content

fix: apply the trim quantifier to the whole charType - #396

Open
derdossi wants to merge 1 commit into
Rich-Harris:masterfrom
derdossi:fix/trim-chartype
Open

derdossi wants to merge 1 commit into
Rich-Harris:masterfrom
derdossi:fix/trim-chartype

Conversation

@derdossi

@derdossi derdossi commented Dec 3, 2026

Copy link
Copy Markdown

trim, trimStart and trimEnd build their RegExp as ^${charType}+ / ${charType}+$, so an alternation like x|y becomes ^x|y+, i.e. (^x)|(y+). new MagicString('xyaxy').trimStart('x|y') gives yaxy instead of axy.

This wraps charType in a non-capturing group in MagicString and Bundle. Single characters and classes such as the default \s match as before; a multi-character charType is now repeated as a whole.

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.

1 participant