Repository navigation
Conversation
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
A string
replacementfor a RegExpfindnow expands$1,$&and the other special replacement patterns, as thereplacementdocs say. Before,{ find: /process\.env\.(\w+)/g, replacement: 'import.meta.env.$1' }producedimport.meta.env.$1.The expansion follows
String.prototype.replace:$$,$&,$`,$',$1to$99and$<name>;$`and$'read the original code, comments included. String keys (the object form and stringfind) and function replacements are unchanged.A RegExp replacement that relied on
$followed by one of those tokens staying literal now gets the expanded text;$$gives a literal$.Fixes #117
Tests
New tests in
tests/rollup.test.ts: find regexp with special replacement patterns, and find regexp with$'keeps comments.Fails without fix:
pnpm install --frozen-lockfile && NO_COLOR=1 pnpm vitest run tests/rollup.test.tson 5b00fec, with the fix's code reverted toorigin/main: exit 1, failing: find regexp with special replacement patterns; find regexp with $' keeps comments; rollup > find regexp with special replacement patterns.Tests (agent-run) at 5b00fec, clean setup (empty HOME, no git config):
pnpm install --frozen-lockfile && NO_COLOR=1 pnpm vitest run tests/rollup.test.ts, exit 0. Last output line:Duration 275ms (import 49%, tests 43%, worker 8%).AI disclosure: this PR was written with an AI coding agent; the test results above come from the agent's runs.