Socket
Socket
Sign inDemoInstall

@wordpress/babel-plugin-import-jsx-pragma

Package Overview
Dependencies
Maintainers
6
Versions
122
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@wordpress/babel-plugin-import-jsx-pragma - npm Package Compare versions

Comparing version 1.0.0-alpha.2 to 1.0.0-alpha.3

120

build-module/index.js

@@ -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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc