Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(babel): support code transpiled with esbuild (#1143)
* fix(babel): support code transpiled with esbuild
- Loading branch information
Showing
8 changed files
with
366 additions
and
38 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
--- | ||
'@linaria/testkit': patch | ||
'@linaria/utils': patch | ||
'@linaria/babel-preset': patch | ||
--- | ||
|
||
Support for code transpiled with esbuild. |
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
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 |
---|---|---|
@@ -1,19 +1,23 @@ | ||
import type { NodePath } from '@babel/traverse'; | ||
|
||
import { getScope } from './getScope'; | ||
import { isGlobal } from './isGlobal'; | ||
|
||
/** | ||
* Checks that specified Identifier is a global `exports` | ||
* @param id | ||
* Checks that specified Identifier is a global `exports` or `module.exports` | ||
* @param node | ||
*/ | ||
export default function isExports(id: NodePath | null | undefined) { | ||
if (!id?.isIdentifier() || id.node.name !== 'exports') { | ||
return false; | ||
export default function isExports(node: NodePath | null | undefined) { | ||
if (node?.isIdentifier({ name: 'exports' })) { | ||
return isGlobal(node, 'exports'); | ||
} | ||
|
||
const scope = getScope(id); | ||
if ( | ||
node?.isMemberExpression() && | ||
node.get('object').isIdentifier({ name: 'module' }) && | ||
node.get('property').isIdentifier({ name: 'exports' }) | ||
) { | ||
return isGlobal(node, 'module'); | ||
} | ||
|
||
return ( | ||
scope.getBinding('exports') === undefined && scope.hasGlobal('exports') | ||
); | ||
return false; | ||
} |
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,9 @@ | ||
import type { NodePath } from '@babel/traverse'; | ||
|
||
import { getScope } from './getScope'; | ||
|
||
export const isGlobal = (node: NodePath, name: string) => { | ||
const scope = getScope(node); | ||
|
||
return scope.getBinding(name) === undefined && scope.hasGlobal(name); | ||
}; |
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
Oops, something went wrong.