Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(replace)!: issues with nested objects replacements #903

Merged
merged 2 commits into from
Jul 16, 2021

Conversation

o-alexandrov
Copy link
Contributor

@o-alexandrov o-alexandrov commented Jun 15, 2021

Rollup Plugin Name: @rollup/plugin-replace

This PR contains:

  • bugfix
  • feature
  • refactor
  • documentation
  • other

Are tests included?

  • yes (bugfixes and features will not be merged without tests)
  • no

Breaking Changes?

  • yes (breaking changes will not be merged unless absolutely necessary)
  • no

If yes, then include "BREAKING CHANGES:" in the first commit message body, followed by a description of what is breaking.

List any relevant issue numbers:

Description

Currently, developers have issues with replacements w/ nested access.
If you attempt to replace typeof window with "object", you would see the following scenarios:

  • typeof window will be replaced
  • typeof window.document will be replaced, resulting in "object".document (which is an error)
  • typeof windowSmth will not be replaced due to a \b boundary

Therefore, it's important to change the default delimiters from:
['\b', '\b']
to:
['\b', '\b(?!\.)']

Sorry, something went wrong.

@shellscape
Copy link
Collaborator

Thanks for the PR. Since this does contain a breaking change (any change in default behavior is breaking, even a bug fix), I would encourage you to bring this up as an issue for discussion first. I'm sure this is perceived as a bug, but there's technically nothing incorrect about the current behavior, because the option exists to customize it. Since we already have a delimiters option, it's my position that we need but a documentation improvement, rather than a breaking change which requires the same documentation improvement for users to understand what the new behavior is.

Other maintainers may weigh in on this, but it's my take that we should not merge this change as-is.

@o-alexandrov
Copy link
Contributor Author

@shellscape I was going to actually report an issue with delimiters also.

@o-alexandrov
Copy link
Contributor Author

@shellscape as you requested, created an Issue to discuss this breaking fix 😄

@shellscape
Copy link
Collaborator

Ah thanks, I meant more so for the future. Since this is already open and discussion has commenced, the merits of the change can be discussed here.

@o-alexandrov
Copy link
Contributor Author

apologies for pinging, could you please let me know whether anyone is expected to be looking at this PR and when?

@o-alexandrov o-alexandrov requested a review from shellscape as a code owner July 15, 2021 19:24
@shellscape shellscape force-pushed the master branch 11 times, most recently from c33e948 to 1ae22f4 Compare July 15, 2021 21:28
@shellscape
Copy link
Collaborator

Please update from upstream/master. We've made some improvements to repo workflows and we'll need them to run against your PR.

Unverified

This user has not yet uploaded their public signing key.

Unverified

This user has not yet uploaded their public signing key.
@o-alexandrov
Copy link
Contributor Author

@shellscape rebased and force pushed, please let me know, if I should do anything else to speed up the review

@shellscape
Copy link
Collaborator

thanks!

@shellscape shellscape changed the title fix(replace): issues with nested objects replacements fix(replace)!: issues with nested objects replacements Jul 16, 2021
@shellscape shellscape merged commit 7fbc22b into rollup:master Jul 16, 2021
shellscape pushed a commit that referenced this pull request Jul 16, 2021

Unverified

This commit is not signed, but one or more authors requires that any commit attributed to them is signed.
* fix(replace): issues with nested objects replacements

* fix(replace): update tests & snapshots
shellscape pushed a commit that referenced this pull request Jul 16, 2021

Unverified

This commit is not signed, but one or more authors requires that any commit attributed to them is signed.
* fix(replace): issues with nested objects replacements

* fix(replace): update tests & snapshots
@jbt
Copy link

jbt commented Jul 23, 2021

I just stumbled on this PR after noticing the breaking changes myself in the replace plugin - I'd like to highlight that this change in defaults breaks things where you might want to preserve property / method calls on the thing being replaced.

For me, for example, I have a lot of things that look like:

if (VERSION.startsWith('foo')) {
  // things
}

... where I'm replacing VERSION with a string literal. This change in defaults breaks that behaviour.

I'm aware that all I need to do is change the delimiters I'm using and I'm cool with doing that - but since (as highlighted earlier in this thread) there doesn't seem to have been discussion of the relative merits of different default options, which cases they support and which cases they break - would it be worth opening a discussion to decide the best options here?

If so, I'm happy to create a new issue for discussion. But if not, and if my example is much more edge-case than the typeof window-style replacement, I'm fine to continue manually specifying my own delimiters with the old values

@o-alexandrov
Copy link
Contributor Author

Personally, I believe it's dangerous to replace VERSION in 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.

thebengeu added a commit to supabase/supabase that referenced this pull request Sep 3, 2021

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
Due to this breaking change in the replace plugin: rollup/plugins#903.
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.

None yet

3 participants