Skip to content

Commit

Permalink
Drop handling of named <Fragment />
Browse files Browse the repository at this point in the history
  • Loading branch information
sirreal committed Apr 23, 2019
1 parent 85d1460 commit 8c88a7a
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 8 deletions.
3 changes: 2 additions & 1 deletion packages/babel-plugin-import-jsx-pragma/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ Name of variable required to be in scope for use by the JSX pragma. For the defa

_Type:_ String

Name of variable required to be in scope for `Fragment` (`<></>` or `<Fragment />`) JSX.
Name of variable required to be in scope for `<></>` `Fragment` JSX. Named `<Fragment />` elements
expect Fragment to be in scope and will not add the import.

### `source`

Expand Down
7 changes: 2 additions & 5 deletions packages/babel-plugin-import-jsx-pragma/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ module.exports = function( babel ) {
const { scopeVariable } = getOptions( state );
state.hasUndeclaredScopeVariable = ! path.scope.hasBinding( scopeVariable );
},
'JSXElement|JSXFragment'( path, state ) {
JSXFragment( path, state ) {
if ( state.hasUndeclaredScopeVariableFrag ) {
return;
}
Expand All @@ -65,10 +65,7 @@ module.exports = function( babel ) {
return;
}

if (
path.type === 'JSXFragment' ||
( path.type === 'JSXElement' && path.node.openingElement.name.name === 'Fragment' )
) {
if ( path.type === 'JSXFragment' ) {
state.hasUndeclaredScopeVariableFrag = ! path.scope.hasBinding( scopeVariableFrag );
}
},
Expand Down
4 changes: 2 additions & 2 deletions packages/babel-plugin-import-jsx-pragma/test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ describe( 'babel-plugin-import-jsx-pragma', () => {
);
} );

it( 'adds Fragment import for Fragment', () => {
it( 'does not add Fragment import for <Fragment />', () => {
const original = 'let foo = <Fragment><bar /><baz /></Fragment>;';
const string = getTransformedCode( original, {
scopeVariable: 'createElement',
Expand All @@ -145,7 +145,7 @@ describe( 'babel-plugin-import-jsx-pragma', () => {
} );

expect( string ).toBe(
'import { createElement, Fragment } from "@wordpress/element";\nlet foo = <Fragment><bar /><baz /></Fragment>;'
'import { createElement } from "@wordpress/element";\nlet foo = <Fragment><bar /><baz /></Fragment>;'
);
} );
} );
Expand Down

0 comments on commit 8c88a7a

Please sign in to comment.