Skip to content

Commit

Permalink
Update on "compiler: getGlobalDeclaration() takes a NonLocalBinding"
Browse files Browse the repository at this point in the history
No-op refactor to make Environment#getGlobalDeclaration() take a NonLocalBinding instead of just a name. The idea is that in subsequent PRs we can use information about the binding to resolve a type more accurately. For example, we can resolve `Array` differently if its an import or local and not the global Array. Similar for resolving local `useState` differently than the one from React.

[ghstack-poisoned]
  • Loading branch information
josephsavona committed May 21, 2024
2 parents c869c38 + 7f49517 commit 0d528a8
Showing 1 changed file with 8 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ export default class HIRBuilder {
return { kind: "Global", name: originalName };
}

// Check if the binding is from module scope, if so return null
// Check if the binding is from module scope
const outerBinding =
this.parentFunction.scope.parent.getBinding(originalName);
if (babelBinding === outerBinding) {
Expand Down Expand Up @@ -286,6 +286,13 @@ export default class HIRBuilder {
isContextIdentifier(path: NodePath<t.Identifier | t.JSXIdentifier>): boolean {
const binding = this.#resolveBabelBinding(path);
if (binding) {
// Check if the binding is from module scope, if so return null
const outerBinding = this.parentFunction.scope.parent.getBinding(
path.node.name
);
if (binding === outerBinding) {
return false;
}
return this.#env.isContextIdentifier(binding.identifier);
} else {
return false;
Expand Down

0 comments on commit 0d528a8

Please sign in to comment.