rollup / plugins

🍣 The one-stop shop for official Rollup plugins
MIT License
3.64k stars 590 forks source link

replace: objectGuards not working #1178

Open privatenumber opened 2 years ago

privatenumber commented 2 years ago

Input

index.js

if (typeof process !== 'undefined' && process.env.NODE_ENV === 'production') {
    console.log('production');
}

Expected Behavior

@rollup/plugin-replace README says the output should be:

if ('object' !== 'undefined' && 'production' === 'production') {
  console.log('production');
}

Actual Behavior

typeof process is not replaced.

Output

if (typeof process !== 'undefined' && "production" === 'production') {
    console.log('production');
}

Additional Information

There is no regression. Looks like the feature was merged when it was not working: https://github.com/rollup/plugins/pull/1084#discussion_r861447543

stale[bot] commented 2 years ago

Hey folks. This issue hasn't received any traction for 60 days, so we're going to close this for housekeeping. If this is still an ongoing issue, please do consider contributing a Pull Request to resolve it. Further discussion is always welcome even with the issue closed. If anything actionable is posted in the comments, we'll consider reopening it.

niba1122 commented 2 years ago

I met same problem and maybe actual issue. Internal patterns for typeof (e.g. typeof process !==) does not work because of delimiters ['\\b', '\\b(?!\\.)'] added by https://github.com/rollup/plugins/pull/1088.

privatenumber commented 2 years ago

I don't think it was ever working:

There is no regression. Looks like the feature was merged when it was not working: https://github.com/rollup/plugins/pull/1084#discussion_r861447543