@wordpress/babel-plugin-import-jsx-pragma
Advanced tools
Comparing version 1.0.0-alpha.2 to 1.0.0-alpha.3
@@ -1,2 +0,4 @@ | ||
import _extends from 'babel-runtime/helpers/extends'; | ||
import "core-js/modules/es6.function.name"; | ||
import _objectSpread from "@babel/runtime/helpers/objectSpread"; | ||
/** | ||
@@ -15,7 +17,6 @@ * Default options for the plugin. | ||
var DEFAULT_OPTIONS = { | ||
scopeVariable: 'React', | ||
source: 'react', | ||
isDefault: true | ||
scopeVariable: 'React', | ||
source: 'react', | ||
isDefault: true | ||
}; | ||
/** | ||
@@ -31,70 +32,67 @@ * Babel transform plugin for automatically injecting an import to be used as | ||
*/ | ||
export default function (babel) { | ||
var t = babel.types; | ||
var t = babel.types; | ||
function getOptions(state) { | ||
if (!state._options) { | ||
state._options = _objectSpread({}, DEFAULT_OPTIONS, state.opts); | ||
} | ||
function getOptions(state) { | ||
if (!state._options) { | ||
state._options = _extends({}, DEFAULT_OPTIONS, state.opts); | ||
} | ||
return state._options; | ||
} | ||
return state._options; | ||
} | ||
return { | ||
visitor: { | ||
JSXElement: function JSXElement(path, state) { | ||
state.hasJSX = true; | ||
}, | ||
ImportDeclaration: function ImportDeclaration(path, state) { | ||
if (state.hasImportedScopeVariable) { | ||
return; | ||
} | ||
return { | ||
visitor: { | ||
JSXElement: function JSXElement(path, state) { | ||
state.hasJSX = true; | ||
}, | ||
ImportDeclaration: function ImportDeclaration(path, state) { | ||
if (state.hasImportedScopeVariable) { | ||
return; | ||
} | ||
var _getOptions = getOptions(state), | ||
scopeVariable = _getOptions.scopeVariable, | ||
isDefault = _getOptions.isDefault; // 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. | ||
var _getOptions = getOptions(state), | ||
scopeVariable = _getOptions.scopeVariable, | ||
isDefault = _getOptions.isDefault; | ||
// Test that at least one import specifier exists matching the | ||
// scope variable name. The module source is not verfied 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(function (specifier) { | ||
switch (specifier.type) { | ||
case 'ImportSpecifier': | ||
return !isDefault && specifier.imported.name === scopeVariable; | ||
case 'ImportDefaultSpecifier': | ||
return isDefault; | ||
} | ||
}); | ||
}, | ||
Program: { | ||
exit: function exit(path, state) { | ||
if (!state.hasJSX || state.hasImportedScopeVariable) { | ||
return; | ||
} | ||
state.hasImportedScopeVariable = path.node.specifiers.some(function (specifier) { | ||
switch (specifier.type) { | ||
case 'ImportSpecifier': | ||
return !isDefault && specifier.imported.name === scopeVariable; | ||
var _getOptions2 = getOptions(state), | ||
scopeVariable = _getOptions2.scopeVariable, | ||
source = _getOptions2.source, | ||
isDefault = _getOptions2.isDefault; | ||
case 'ImportDefaultSpecifier': | ||
return isDefault; | ||
} | ||
}); | ||
}, | ||
var specifier; | ||
Program: { | ||
exit: function exit(path, state) { | ||
if (!state.hasJSX || state.hasImportedScopeVariable) { | ||
return; | ||
} | ||
if (isDefault) { | ||
specifier = t.importDefaultSpecifier(t.identifier(scopeVariable)); | ||
} else { | ||
specifier = t.importSpecifier(t.identifier(scopeVariable), t.identifier(scopeVariable)); | ||
} | ||
var _getOptions2 = getOptions(state), | ||
scopeVariable = _getOptions2.scopeVariable, | ||
source = _getOptions2.source, | ||
isDefault = _getOptions2.isDefault; | ||
var specifier = void 0; | ||
if (isDefault) { | ||
specifier = t.importDefaultSpecifier(t.identifier(scopeVariable)); | ||
} else { | ||
specifier = t.importSpecifier(t.identifier(scopeVariable), t.identifier(scopeVariable)); | ||
} | ||
var importDeclaration = t.importDeclaration([specifier], t.stringLiteral(source)); | ||
path.unshiftContainer('body', importDeclaration); | ||
} | ||
} | ||
} | ||
}; | ||
var importDeclaration = t.importDeclaration([specifier], t.stringLiteral(source)); | ||
path.unshiftContainer('body', importDeclaration); | ||
} | ||
} | ||
} | ||
}; | ||
} |
@@ -1,83 +0,14 @@ | ||
'use strict'; | ||
"use strict"; | ||
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
value: true | ||
}); | ||
exports.default = _default; | ||
var _extends2 = require('babel-runtime/helpers/extends'); | ||
require("core-js/modules/es6.function.name"); | ||
var _extends3 = _interopRequireDefault(_extends2); | ||
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread")); | ||
exports.default = function (babel) { | ||
var t = babel.types; | ||
function getOptions(state) { | ||
if (!state._options) { | ||
state._options = (0, _extends3.default)({}, DEFAULT_OPTIONS, state.opts); | ||
} | ||
return state._options; | ||
} | ||
return { | ||
visitor: { | ||
JSXElement: function JSXElement(path, state) { | ||
state.hasJSX = true; | ||
}, | ||
ImportDeclaration: function ImportDeclaration(path, state) { | ||
if (state.hasImportedScopeVariable) { | ||
return; | ||
} | ||
var _getOptions = getOptions(state), | ||
scopeVariable = _getOptions.scopeVariable, | ||
isDefault = _getOptions.isDefault; | ||
// Test that at least one import specifier exists matching the | ||
// scope variable name. The module source is not verfied 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(function (specifier) { | ||
switch (specifier.type) { | ||
case 'ImportSpecifier': | ||
return !isDefault && specifier.imported.name === scopeVariable; | ||
case 'ImportDefaultSpecifier': | ||
return isDefault; | ||
} | ||
}); | ||
}, | ||
Program: { | ||
exit: function exit(path, state) { | ||
if (!state.hasJSX || state.hasImportedScopeVariable) { | ||
return; | ||
} | ||
var _getOptions2 = getOptions(state), | ||
scopeVariable = _getOptions2.scopeVariable, | ||
source = _getOptions2.source, | ||
isDefault = _getOptions2.isDefault; | ||
var specifier = void 0; | ||
if (isDefault) { | ||
specifier = t.importDefaultSpecifier(t.identifier(scopeVariable)); | ||
} else { | ||
specifier = t.importSpecifier(t.identifier(scopeVariable), t.identifier(scopeVariable)); | ||
} | ||
var importDeclaration = t.importDeclaration([specifier], t.stringLiteral(source)); | ||
path.unshiftContainer('body', importDeclaration); | ||
} | ||
} | ||
} | ||
}; | ||
}; | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
/** | ||
@@ -96,7 +27,6 @@ * Default options for the plugin. | ||
var DEFAULT_OPTIONS = { | ||
scopeVariable: 'React', | ||
source: 'react', | ||
isDefault: true | ||
scopeVariable: 'React', | ||
source: 'react', | ||
isDefault: true | ||
}; | ||
/** | ||
@@ -111,2 +41,68 @@ * Babel transform plugin for automatically injecting an import to be used as | ||
* @return {Object} Babel transform plugin. | ||
*/ | ||
*/ | ||
function _default(babel) { | ||
var t = babel.types; | ||
function getOptions(state) { | ||
if (!state._options) { | ||
state._options = (0, _objectSpread2.default)({}, DEFAULT_OPTIONS, state.opts); | ||
} | ||
return state._options; | ||
} | ||
return { | ||
visitor: { | ||
JSXElement: function JSXElement(path, state) { | ||
state.hasJSX = true; | ||
}, | ||
ImportDeclaration: function ImportDeclaration(path, state) { | ||
if (state.hasImportedScopeVariable) { | ||
return; | ||
} | ||
var _getOptions = getOptions(state), | ||
scopeVariable = _getOptions.scopeVariable, | ||
isDefault = _getOptions.isDefault; // 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(function (specifier) { | ||
switch (specifier.type) { | ||
case 'ImportSpecifier': | ||
return !isDefault && specifier.imported.name === scopeVariable; | ||
case 'ImportDefaultSpecifier': | ||
return isDefault; | ||
} | ||
}); | ||
}, | ||
Program: { | ||
exit: function exit(path, state) { | ||
if (!state.hasJSX || state.hasImportedScopeVariable) { | ||
return; | ||
} | ||
var _getOptions2 = getOptions(state), | ||
scopeVariable = _getOptions2.scopeVariable, | ||
source = _getOptions2.source, | ||
isDefault = _getOptions2.isDefault; | ||
var specifier; | ||
if (isDefault) { | ||
specifier = t.importDefaultSpecifier(t.identifier(scopeVariable)); | ||
} else { | ||
specifier = t.importSpecifier(t.identifier(scopeVariable), t.identifier(scopeVariable)); | ||
} | ||
var importDeclaration = t.importDeclaration([specifier], t.stringLiteral(source)); | ||
path.unshiftContainer('body', importDeclaration); | ||
} | ||
} | ||
} | ||
}; | ||
} |
{ | ||
"name": "@wordpress/babel-plugin-import-jsx-pragma", | ||
"version": "1.0.0-alpha.2", | ||
"version": "1.0.0-alpha.3", | ||
"description": "Babel transform plugin for automatically injecting an import to be used as the pragma for the React JSX Transform plugin.", | ||
@@ -22,11 +22,19 @@ "author": "The WordPress Contributors", | ||
}, | ||
"files": [ | ||
"build", | ||
"build-module" | ||
], | ||
"main": "build/index.js", | ||
"module": "build-module/index.js", | ||
"devDependencies": { | ||
"babel-core": "^6.26.3", | ||
"babel-plugin-syntax-jsx": "^6.18.0" | ||
"@babel/core": "^7.0.0-beta.52", | ||
"@babel/plugin-syntax-jsx": "^7.0.0-beta.52" | ||
}, | ||
"peerDependencies": { | ||
"@babel/core": "^7.0.0-beta.52" | ||
}, | ||
"publishConfig": { | ||
"access": "public" | ||
} | ||
}, | ||
"gitHead": "8827c049ec802471f51a5cb906d9096ffc1b4e48" | ||
} |
@@ -68,3 +68,3 @@ Babel Plugin Import JSX Pragma | ||
### `isDefautl` | ||
### `isDefault` | ||
@@ -71,0 +71,0 @@ _Type:_ Boolean |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
10385
1
4
170
1