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

Apply defines before injected global variables #1261

Merged
merged 1 commit into from
May 18, 2021

Conversation

rtsao
Copy link
Contributor

@rtsao rtsao commented May 7, 2021

Resolves #660

This seemed like the most straightforward way of addressing this, would love feedback

@@ -9508,8 +9508,10 @@ func (p *parser) isDotDefineMatch(expr js_ast.Expr, parts []string) bool {
return false
}

// The last symbol must be unbound
return p.symbols[result.ref.InnerIndex].Kind == js_ast.SymbolUnbound
p.ignoreUsage(result.ref)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

If we replace an injected symbol with a define, we need to explicitly mark it as unused (as p.findSymbol has the effect of marking usage). Otherwise, the injected import won't be eliminated.

Calling p.ignoreUsage feels a bit hacky. I also suppose that ignoreUsage should be invoked closer to the actual replacement callsite rather than in isDotDefineMatch, which doesn't necessitate that a replacement actually occurs...

@rtsao rtsao force-pushed the define-before-inject branch from e5d626c to dfb36d4 Compare May 10, 2021 20:01
@evanw evanw added the breaking label May 14, 2021
@evanw
Copy link
Owner

evanw commented May 14, 2021

I agree that #660 would be good to solve. However, it seems like a breaking change to me in that this may cause subtle and unintentional behavior changes. So I'd like to wait on this until the next round of breaking changes (i.e. the next minor version bump, since esbuild is <1.0.0).

@evanw evanw merged commit f158b78 into evanw:master May 18, 2021
@evanw
Copy link
Owner

evanw commented May 18, 2021

Thanks! I appreciate you taking the time to fix this.

evanw added a commit that referenced this pull request May 18, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

inject has higher priority than define
2 participants