[babel-plugin] use globalThis in the compile-time evaluator - #1844
Closed
henryqdineen wants to merge 2 commits into
Closed
[babel-plugin] use globalThis in the compile-time evaluator#1844henryqdineen wants to merge 2 commits into
henryqdineen wants to merge 2 commits into
Conversation
`global` only exists in Node, so reading globals off it throws a ReferenceError when the plugin runs in a browser (the docs playground). `globalThis` is equivalent in Node and works everywhere. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
|
@henryqdineen is attempting to deploy a commit to the Meta Open Source Team on Vercel. A member of the Team first needs to authorize it. |
Closed
Member
|
can we fix the flow types? |
Flow types `global` as `any`, so these three lines were never actually typechecked. `globalThis` is a real namespace type, which surfaced two things it can't express: indexing with an arbitrary string, and `eval`, which is absent from the namespace even though the bare binding is fine. Cast at each read to keep the escape hatch local to the three sites. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
henryqdineen
force-pushed
the
hqd-fix-playground-global-not-defined
branch
from
September 4, 2026 03:58
1016a30 to
cc26f99
Compare
Collaborator
Author
Thanks. I always forget about Flow. Should be fixed in cc26f99. I considered just having a transform from |
Collaborator
Author
|
This was fixed by #1847 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What changed / motivation ?
This only affects the playground. It's a bug in the browser build of the plugin (
lib/index.browser.js), which the playground is the only known consumer of. Node builds were never affected, sinceglobalexists there.The compile-time evaluator read globals off Node's
globalobject in three places insrc/utils/evaluate-path.js.globaldoesn't exist in browsers, so those reads throwReferenceError: global is not definedwhen the plugin runs client-side, as it does in the docs playground. Babel prefixes the filename, giving the reported/App.tsx: global is not defined.Swapped all three to
globalThis, which is equivalent in Node and available in browsers.It broke now because of the read added in #1818:
isBlockedFunctioncompares againstglobal.evaland runs for every call expression, which is why removing thestylex.when(...)call from the example works around it. The other two reads are older and equally broken in a browser, but sit behind theisValidCalleeallowlist (String,Number,Math,Object,Array) that no playground example hits.Linked PR/Issues
Fixes #1838
Additional Context
globalThisbehaves identically toglobalin Node, so this is strictly a widening. No behavior change for any Node consumer of the plugin.Pre-flight checklist
Contribution Guidelines
🤖 Generated with Claude Code