From 8c88a7aa2e61f21c0c4ea67676a7ad3ec0571e4e Mon Sep 17 00:00:00 2001 From: Jon Surrell Date: Tue, 23 Apr 2019 14:44:02 +0200 Subject: [PATCH] Drop handling of named --- packages/babel-plugin-import-jsx-pragma/README.md | 3 ++- packages/babel-plugin-import-jsx-pragma/index.js | 7 ++----- packages/babel-plugin-import-jsx-pragma/test/index.js | 4 ++-- 3 files changed, 6 insertions(+), 8 deletions(-) diff --git a/packages/babel-plugin-import-jsx-pragma/README.md b/packages/babel-plugin-import-jsx-pragma/README.md index ca6d7dc2c2763..2459cea08be45 100644 --- a/packages/babel-plugin-import-jsx-pragma/README.md +++ b/packages/babel-plugin-import-jsx-pragma/README.md @@ -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 ``) JSX. +Name of variable required to be in scope for `<>` `Fragment` JSX. Named `` elements +expect Fragment to be in scope and will not add the import. ### `source` diff --git a/packages/babel-plugin-import-jsx-pragma/index.js b/packages/babel-plugin-import-jsx-pragma/index.js index ad774b218087e..a39d4320ebbc4 100644 --- a/packages/babel-plugin-import-jsx-pragma/index.js +++ b/packages/babel-plugin-import-jsx-pragma/index.js @@ -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; } @@ -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 ); } }, diff --git a/packages/babel-plugin-import-jsx-pragma/test/index.js b/packages/babel-plugin-import-jsx-pragma/test/index.js index fbd21615abc30..c3e098476db3d 100644 --- a/packages/babel-plugin-import-jsx-pragma/test/index.js +++ b/packages/babel-plugin-import-jsx-pragma/test/index.js @@ -135,7 +135,7 @@ describe( 'babel-plugin-import-jsx-pragma', () => { ); } ); - it( 'adds Fragment import for Fragment', () => { + it( 'does not add Fragment import for ', () => { const original = 'let foo = ;'; const string = getTransformedCode( original, { scopeVariable: 'createElement', @@ -145,7 +145,7 @@ describe( 'babel-plugin-import-jsx-pragma', () => { } ); expect( string ).toBe( - 'import { createElement, Fragment } from "@wordpress/element";\nlet foo = ;' + 'import { createElement } from "@wordpress/element";\nlet foo = ;' ); } ); } );