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

Babel Plugin Import JSX Pragma: Remove import visitor #14106

Merged
merged 1 commit into from
Feb 27, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion packages/babel-plugin-import-jsx-pragma/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@

### Breaking Change

- Plugin skips now adding import JSX pragma when the scope variable is defined for all JSX elements ([#13809](https://github.com/WordPress/gutenberg/pull/13809)).
- Stop using Babel transpilation internally and set node 8 as a minimal version required ([#13540](https://github.com/WordPress/gutenberg/pull/13540)).

### Enhancement

- Plugin skips now adding import JSX pragma when the scope variable is defined for all JSX elements ([#13809](https://github.com/WordPress/gutenberg/pull/13809)).

## 1.1.0 (2018-09-05)

### New Feature
Expand Down
28 changes: 1 addition & 27 deletions packages/babel-plugin-import-jsx-pragma/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,42 +40,16 @@ module.exports = function( babel ) {
return {
visitor: {
JSXElement( path, state ) {
state.hasJSX = true;
if ( state.hasUndeclaredScopeVariable ) {
return;
}

const { scopeVariable } = getOptions( state );

state.hasUndeclaredScopeVariable = ! path.scope.hasBinding( scopeVariable );
},
ImportDeclaration( path, state ) {
if ( state.hasImportedScopeVariable ) {
return;
}

const { scopeVariable, isDefault } = getOptions( state );

// Test that at least one import specifier exists matching the
// scope variable name. The module source is not verified since
// we must avoid introducing a conflicting import name, even if
// the scope variable is referenced from a different source.
state.hasImportedScopeVariable = path.node.specifiers.some( ( specifier ) => {
switch ( specifier.type ) {
case 'ImportSpecifier':
return (
! isDefault &&
specifier.imported.name === scopeVariable
);

case 'ImportDefaultSpecifier':
return isDefault;
}
} );
},
Program: {
exit( path, state ) {
if ( ! state.hasJSX || state.hasImportedScopeVariable || ! state.hasUndeclaredScopeVariable ) {
if ( ! state.hasUndeclaredScopeVariable ) {
return;
}

Expand Down