replace: Should property accessors be replaced or not?
Nobody has claimed this yet.
Assessment
- Difficulty
- 5/5
- Estimated time
- Over a week
- Newbie friendliness
- 35/100
- Issue type
- Bug
- Clarity
- Needs clarification
- Activity status
- Quiet
- Tech stack
- javascript
- Domain
- tooling
Research direction
Compare packages/replace/test/fixtures/form/dollar-sign-boundary and replace-nothing with their _config.js files and the Vitest snapshots under packages/replace/test/snapshots/form.js.md, using the linked reproduction as context. First establish which property-access and delimiter behavior is intended; done means the conflicting fixtures and snapshots consistently reflect the agreed behavior.
Written by the indexing model from the issue text.
Description
- Rollup Plugin Name:
@rollup/plugin-replace - Rollup Plugin Version: 6.0.3
- Rollup Version: 4.62.0
- Operating System (or Browser): macOS 15.7.7 (local), unknown (stackblitz)
- Node Version: v22.22.3
- Link to reproduction (⚠️ read below): https://stackblitz.com/edit/rollup-repro-amxnsxzx?file=dist%2Fmain.js&view=editor
Expected Behavior
Given this test added in #1938 merged into 6.0.3:
https://github.com/rollup/plugins/blob/639f45638234c1c3fabfb13615c78bebaef89ef2/packages/replace/test/fixtures/form/dollar-sign-boundary/input.js#L17-L20
https://github.com/rollup/plugins/blob/639f45638234c1c3fabfb13615c78bebaef89ef2/packages/replace/test/fixtures/form/dollar-sign-boundary/_config.js#L2-L8
Comment strongly suggests it should produce the following replacement:
// Should be replaced - typeof window followed by dot
if ("undefined".document !== 'undefined') {
console.log('has document');
}
Actual Behavior
The snapshot stored by vitest does not actually replace this:
https://github.com/rollup/plugins/blob/639f45638234c1c3fabfb13615c78bebaef89ef2/packages/replace/test/snapshots/form.js.md?plain=1#L43-L46
And, there is an older fixture + snapshot which directly conflicts with this interpretation, under replace-nothing:
https://github.com/rollup/plugins/blob/639f45638234c1c3fabfb13615c78bebaef89ef2/packages/replace/test/fixtures/form/replace-nothing/input.js#L1-L2
https://github.com/rollup/plugins/blob/639f45638234c1c3fabfb13615c78bebaef89ef2/packages/replace/test/fixtures/form/replace-nothing/_config.js#L2-L5
Vitest Snapshot:
https://github.com/rollup/plugins/blob/639f45638234c1c3fabfb13615c78bebaef89ef2/packages/replace/test/snapshots/form.js.md?plain=1#L76-L81
Additional Information
The older PR which introduced the replace-nothing test was #903 which had the following comment:
Personally, I believe it's dangerous to replace
VERSIONin the case you highlighted by default:if (VERSION.startsWith('foo')) { // things }In the case above with the previous default to match VERSION when used with a
.or nested access, you would need to know all of your dependencies' code, not to mess up when replacing.
Originally posted by @o-alexandrov in https://github.com/rollup/plugins/issues/903#issuecomment-885657501
What is the current intended behavior? I don't think these two tests can co-exist unless they're testing differently configured delimiters.
- Dominant language
- JavaScript
- Stars
- 3.8k
- Forks
- 635
- PR merge metrics
- No merged PRs in 30d
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from rollup/plugins
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
-
Difficulty 4/5 3-5 days Newbie friendliness 52/100
-
Difficulty 3/5 1-2 days Newbie friendliness 48/100
-
Difficulty 4/5 3-5 days Newbie friendliness 48/100
-
Support js-yaml v5 Open
Difficulty 4/5 3-5 days Newbie friendliness 45/100
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
HarperFast/skills#96 ·
-
[Block] Latest Posts [Type] Bug
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Automattic/studio#4908 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 86/100
sugarlabs/musicblocks#8847 ·