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): prevent variable before colons from being replaced when preventAssigment is true #1609

Merged
merged 2 commits into from
Oct 29, 2023

Conversation

hhgnsc
Copy link
Contributor

@hhgnsc hhgnsc commented Oct 12, 2023

Rollup Plugin Name: 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

Description

When preventAssignment is true, it will replace variable before colons.
For example, my options is:

{
  preventAssignment: true,
  values: {
    NAME: JSON.stringify('replace')
  }
}

The input is:

declare const NAME: string
console.log(NAME)

The output will be:

declare const 'replaced': string
console.log('replaced')

The declare is broken.
I thiink this should be fixed.

@shellscape shellscape changed the title fix: prevent variable before colons from being replaced when preventAssigment is true fix(replace): prevent variable before colons from being replaced when preventAssigment is true Oct 25, 2023
@shellscape shellscape merged commit 047d21c into rollup:master Oct 29, 2023
6 of 10 checks passed
@shellscape
Copy link
Collaborator

thanks!

@EAGzzyCSL
Copy link

@hhgnsc Hi, this may cause unexpected skip when ternary operator is used.

console.log(Math.random() > 0.5? FOO: BAR)

repl: https://stackblitz.com/edit/rollup-case-unexpected-replace

@shellscape
Copy link
Collaborator

@EAGzzyCSL could you please open that as a new issue so we can track it?

@EAGzzyCSL
Copy link

@shellscape OK~ #1619

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.

3 participants