replace: Should property accessors be replaced or not?
还没有人认领这个 Issue。
评估
- 难度
- 5/5
- 预计耗时
- 一周以上
- 新手友好度
- 35/100
- Issue 类型
- 缺陷
- 描述清晰度
- 需要澄清
- 活跃度
- 冷清
- 技术栈
- javascript
- 领域
- tooling
调研方向
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.
由索引模型根据 Issue 内容生成。
描述
- 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.
- 主要语言
- JavaScript
- 星标
- 3.8k
- 派生
- 635
- PR 合并指标
- 30 天内没有已合并 PR
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
rollup/plugins 的其他 Issue
-
难度 2/5 1-3 小时 新手友好度 82/100
-
难度 4/5 3-5 天 新手友好度 52/100
-
难度 3/5 1-2 天 新手友好度 48/100
-
难度 4/5 3-5 天 新手友好度 48/100
-
难度 4/5 3-5 天 新手友好度 45/100
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 88/100
HarperFast/skills#96 ·
-
[Block] Latest Posts [Type] Bug
难度 2/5 1-3 小时 新手友好度 76/100
-
难度 2/5 1-3 小时 新手友好度 78/100
Automattic/studio#4908 ·
-
难度 2/5 1-3 小时 新手友好度 74/100
-
难度 2/5 1-3 小时 新手友好度 86/100
sugarlabs/musicblocks#8847 ·