-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix dynamic rebinding for hoisted JSX
- Loading branch information
Showing
4 changed files
with
38 additions
and
15 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import type * as babel from '@babel/core'; | ||
import type * as t from '@babel/types'; | ||
|
||
export function isStatementTopLevel( | ||
path: babel.NodePath<t.Statement>, | ||
): boolean { | ||
let blockParent = path.scope.getBlockParent(); | ||
const programParent = path.scope.getProgramParent(); | ||
// a FunctionDeclaration binding refers to itself as the block parent | ||
if (blockParent.path === path) { | ||
blockParent = blockParent.parent; | ||
} | ||
|
||
return programParent === blockParent; | ||
} |
This file contains 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
This file contains 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