Thanks to visit codestin.com
Credit goes to github.com

Skip to content

fix(plugin): fix expand_typeof_replacements#2196

Merged
IWANABETHATGUY merged 2 commits into
rolldown:mainfrom
AliceLanniste:fix/objectGuards
Sep 11, 2024
Merged

fix(plugin): fix expand_typeof_replacements#2196
IWANABETHATGUY merged 2 commits into
rolldown:mainfrom
AliceLanniste:fix/objectGuards

Conversation

@AliceLanniste
Copy link
Copy Markdown
Contributor

Description

Related issue:#2057 . fix the function of expand_typeof_replacements

@netlify
Copy link
Copy Markdown

netlify Bot commented Sep 9, 2024

Deploy Preview for rolldown-rs canceled.

Name Link
🔨 Latest commit efc989d
🔍 Latest deploy log https://app.netlify.com/sites/rolldown-rs/deploys/66e0f080903be200093fe935

Copy link
Copy Markdown
Member

@hyf0 hyf0 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool. Thank you!

@hyf0
Copy link
Copy Markdown
Member

hyf0 commented Sep 9, 2024

CI failed.

@IWANABETHATGUY IWANABETHATGUY added this pull request to the merge queue Sep 11, 2024
Merged via the queue into rolldown:main with commit d6233d8 Sep 11, 2024
@ikkz
Copy link
Copy Markdown
Contributor

ikkz commented Sep 11, 2024

@AliceLanniste Hi, I would like to further discuss this function.
In your version, process.env.NODE_ENV will be expanded to typeof process, typeof env, but I think in actual use, the more common usage is as follows:

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

This will cause typeof process.env === "object" not to be replaced and console.log('production'); won't be executed, which can also be seen in the snapshot of this pr.

Secondly, taking your replacement result typeof process!== as an example, after constructing the replacement regular expression, the default delimiter will be added on both sides of this replacement: \btypeof process!==\b(?!\.). In the above usage, this will not match because the equal sign is not followed by a word boundary.

Before:
image

Delimiters added:
image

@AliceLanniste AliceLanniste deleted the fix/objectGuards branch November 2, 2024 07:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants