babel-plugin-import
Advanced tools
Comparing version 1.13.6 to 1.13.7
179
lib/index.js
@@ -1,20 +0,39 @@ | ||
"use strict"; | ||
var __create = Object.create; | ||
var __defProp = Object.defineProperty; | ||
var __getOwnPropDesc = Object.getOwnPropertyDescriptor; | ||
var __getOwnPropNames = Object.getOwnPropertyNames; | ||
var __getProtoOf = Object.getPrototypeOf; | ||
var __hasOwnProp = Object.prototype.hasOwnProperty; | ||
var __export = (target, all) => { | ||
for (var name in all) | ||
__defProp(target, name, { get: all[name], enumerable: true }); | ||
}; | ||
var __copyProps = (to, from, except, desc) => { | ||
if (from && typeof from === "object" || typeof from === "function") { | ||
for (let key of __getOwnPropNames(from)) | ||
if (!__hasOwnProp.call(to, key) && key !== except) | ||
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); | ||
} | ||
return to; | ||
}; | ||
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps( | ||
// If the importer is in node compatibility mode or this is not an ESM | ||
// file that has been converted to a CommonJS file using a Babel- | ||
// compatible transform (i.e. "__esModule" has not been set), then set | ||
// "default" to the CommonJS "module.exports" for node compatibility. | ||
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, | ||
mod | ||
)); | ||
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
// src/index.js | ||
var src_exports = {}; | ||
__export(src_exports, { | ||
default: () => src_default | ||
}); | ||
exports.default = _default; | ||
var _assert = _interopRequireDefault(require("assert")); | ||
var _Plugin = _interopRequireDefault(require("./Plugin")); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; } | ||
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); } | ||
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; } | ||
function _default({ | ||
types | ||
}) { | ||
module.exports = __toCommonJS(src_exports); | ||
var import_assert = __toESM(require("assert")); | ||
var import_Plugin = __toESM(require("./Plugin")); | ||
function src_default({ types }) { | ||
let plugins = null; | ||
// Only for test | ||
// eslint-disable-next-line no-underscore-dangle | ||
global.__clearBabelAntdPlugin = () => { | ||
@@ -24,70 +43,96 @@ plugins = null; | ||
function applyInstance(method, args, context) { | ||
// eslint-disable-next-line no-restricted-syntax | ||
var _iterator = _createForOfIteratorHelper(plugins), | ||
_step; | ||
try { | ||
for (_iterator.s(); !(_step = _iterator.n()).done;) { | ||
const plugin = _step.value; | ||
if (plugin[method]) { | ||
plugin[method].apply(plugin, [...args, context]); | ||
} | ||
for (const plugin of plugins) { | ||
if (plugin[method]) { | ||
plugin[method].apply(plugin, [...args, context]); | ||
} | ||
} catch (err) { | ||
_iterator.e(err); | ||
} finally { | ||
_iterator.f(); | ||
} | ||
} | ||
const Program = { | ||
enter(path, { | ||
opts = {} | ||
}) { | ||
// Init plugin instances once. | ||
enter(path, { opts = {} }) { | ||
if (!plugins) { | ||
if (Array.isArray(opts)) { | ||
plugins = opts.map(({ | ||
libraryName, | ||
libraryDirectory, | ||
style, | ||
styleLibraryDirectory, | ||
customStyleName, | ||
camel2DashComponentName, | ||
camel2UnderlineComponentName, | ||
fileName, | ||
customName, | ||
transformToDefaultImport | ||
}, index) => { | ||
(0, _assert.default)(libraryName, 'libraryName should be provided'); | ||
return new _Plugin.default(libraryName, libraryDirectory, style, styleLibraryDirectory, customStyleName, camel2DashComponentName, camel2UnderlineComponentName, fileName, customName, transformToDefaultImport, types, index); | ||
}); | ||
plugins = opts.map( | ||
({ | ||
libraryName, | ||
libraryDirectory, | ||
style, | ||
styleLibraryDirectory, | ||
customStyleName, | ||
camel2DashComponentName, | ||
camel2UnderlineComponentName, | ||
fileName, | ||
customName, | ||
transformToDefaultImport | ||
}, index) => { | ||
(0, import_assert.default)(libraryName, "libraryName should be provided"); | ||
return new import_Plugin.default( | ||
libraryName, | ||
libraryDirectory, | ||
style, | ||
styleLibraryDirectory, | ||
customStyleName, | ||
camel2DashComponentName, | ||
camel2UnderlineComponentName, | ||
fileName, | ||
customName, | ||
transformToDefaultImport, | ||
types, | ||
index | ||
); | ||
} | ||
); | ||
} else { | ||
(0, _assert.default)(opts.libraryName, 'libraryName should be provided'); | ||
plugins = [new _Plugin.default(opts.libraryName, opts.libraryDirectory, opts.style, opts.styleLibraryDirectory, opts.customStyleName, opts.camel2DashComponentName, opts.camel2UnderlineComponentName, opts.fileName, opts.customName, opts.transformToDefaultImport, types)]; | ||
(0, import_assert.default)(opts.libraryName, "libraryName should be provided"); | ||
plugins = [ | ||
new import_Plugin.default( | ||
opts.libraryName, | ||
opts.libraryDirectory, | ||
opts.style, | ||
opts.styleLibraryDirectory, | ||
opts.customStyleName, | ||
opts.camel2DashComponentName, | ||
opts.camel2UnderlineComponentName, | ||
opts.fileName, | ||
opts.customName, | ||
opts.transformToDefaultImport, | ||
types | ||
) | ||
]; | ||
} | ||
} | ||
applyInstance('ProgramEnter', arguments, this); // eslint-disable-line | ||
applyInstance("ProgramEnter", arguments, this); | ||
}, | ||
exit() { | ||
applyInstance('ProgramExit', arguments, this); // eslint-disable-line | ||
applyInstance("ProgramExit", arguments, this); | ||
} | ||
}; | ||
const methods = ['ImportDeclaration', 'CallExpression', 'MemberExpression', 'Property', 'VariableDeclarator', 'ArrayExpression', 'LogicalExpression', 'ConditionalExpression', 'IfStatement', 'ExpressionStatement', 'ReturnStatement', 'ExportDefaultDeclaration', 'BinaryExpression', 'NewExpression', 'ClassDeclaration', 'SwitchStatement', 'SwitchCase', 'SequenceExpression']; | ||
const methods = [ | ||
"ImportDeclaration", | ||
"CallExpression", | ||
"MemberExpression", | ||
"Property", | ||
"VariableDeclarator", | ||
"ArrayExpression", | ||
"LogicalExpression", | ||
"ConditionalExpression", | ||
"IfStatement", | ||
"ExpressionStatement", | ||
"ReturnStatement", | ||
"ExportDefaultDeclaration", | ||
"BinaryExpression", | ||
"NewExpression", | ||
"ClassDeclaration", | ||
"SwitchStatement", | ||
"SwitchCase", | ||
"SequenceExpression" | ||
]; | ||
const ret = { | ||
visitor: { | ||
Program | ||
} | ||
visitor: { Program } | ||
}; | ||
// eslint-disable-next-line no-restricted-syntax | ||
for (var _i = 0, _methods = methods; _i < _methods.length; _i++) { | ||
const method = _methods[_i]; | ||
ret.visitor[method] = function () { | ||
// eslint-disable-line | ||
applyInstance(method, arguments, ret.visitor); // eslint-disable-line | ||
for (const method of methods) { | ||
ret.visitor[method] = function() { | ||
applyInstance(method, arguments, ret.visitor); | ||
}; | ||
} | ||
return ret; | ||
} | ||
} |
@@ -1,35 +0,46 @@ | ||
"use strict"; | ||
var __defProp = Object.defineProperty; | ||
var __getOwnPropDesc = Object.getOwnPropertyDescriptor; | ||
var __getOwnPropNames = Object.getOwnPropertyNames; | ||
var __hasOwnProp = Object.prototype.hasOwnProperty; | ||
var __export = (target, all) => { | ||
for (var name in all) | ||
__defProp(target, name, { get: all[name], enumerable: true }); | ||
}; | ||
var __copyProps = (to, from, except, desc) => { | ||
if (from && typeof from === "object" || typeof from === "function") { | ||
for (let key of __getOwnPropNames(from)) | ||
if (!__hasOwnProp.call(to, key) && key !== except) | ||
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); | ||
} | ||
return to; | ||
}; | ||
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
// src/Plugin.js | ||
var Plugin_exports = {}; | ||
__export(Plugin_exports, { | ||
default: () => Plugin | ||
}); | ||
exports.default = void 0; | ||
var _path = require("path"); | ||
var _helperModuleImports = require("@babel/helper-module-imports"); | ||
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; } | ||
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; } | ||
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } | ||
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); } | ||
function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); } | ||
module.exports = __toCommonJS(Plugin_exports); | ||
var import_path = require("path"); | ||
var import_helper_module_imports = require("@babel/helper-module-imports"); | ||
function transCamel(_str, symbol) { | ||
const str = _str[0].toLowerCase() + _str.substr(1); | ||
return str.replace(/([A-Z])/g, $1 => `${symbol}${$1.toLowerCase()}`); | ||
const cells = _str.match(/([A-Z]+(?=[A-Z]))|([A-Z]?[^A-Z]+)/g) || []; | ||
return cells.map((c) => c.toLowerCase()).join(symbol); | ||
} | ||
function winPath(path) { | ||
return path.replace(/\\/g, '/'); | ||
return path.replace(/\\/g, "/"); | ||
} | ||
function normalizeCustomName(originCustomName) { | ||
// If set to a string, treat it as a JavaScript source file path. | ||
if (typeof originCustomName === 'string') { | ||
// eslint-disable-next-line import/no-dynamic-require | ||
if (typeof originCustomName === "string") { | ||
const customNameExports = require(originCustomName); | ||
return typeof customNameExports === 'function' ? customNameExports : customNameExports.default; | ||
return typeof customNameExports === "function" ? customNameExports : customNameExports.default; | ||
} | ||
return originCustomName; | ||
} | ||
class Plugin { | ||
var Plugin = class { | ||
constructor(libraryName, libraryDirectory, style, styleLibraryDirectory, customStyleName, camel2DashComponentName, camel2UnderlineComponentName, fileName, customName, transformToDefaultImport, types, index = 0) { | ||
this.libraryName = libraryName; | ||
this.libraryDirectory = typeof libraryDirectory === 'undefined' ? 'lib' : libraryDirectory; | ||
this.camel2DashComponentName = typeof camel2DashComponentName === 'undefined' ? true : camel2DashComponentName; | ||
this.libraryDirectory = typeof libraryDirectory === "undefined" ? "lib" : libraryDirectory; | ||
this.camel2DashComponentName = typeof camel2DashComponentName === "undefined" ? true : camel2DashComponentName; | ||
this.camel2UnderlineComponentName = camel2UnderlineComponentName; | ||
@@ -39,5 +50,5 @@ this.style = style || false; | ||
this.customStyleName = normalizeCustomName(customStyleName); | ||
this.fileName = fileName || ''; | ||
this.fileName = fileName || ""; | ||
this.customName = normalizeCustomName(customName); | ||
this.transformToDefaultImport = typeof transformToDefaultImport === 'undefined' ? true : transformToDefaultImport; | ||
this.transformToDefaultImport = typeof transformToDefaultImport === "undefined" ? true : transformToDefaultImport; | ||
this.types = types; | ||
@@ -48,5 +59,4 @@ this.pluginStateKey = `importPluginState${index}`; | ||
if (!state[this.pluginStateKey]) { | ||
state[this.pluginStateKey] = {}; // eslint-disable-line | ||
state[this.pluginStateKey] = {}; | ||
} | ||
return state[this.pluginStateKey]; | ||
@@ -56,60 +66,59 @@ } | ||
if (!pluginState.selectedMethods[methodName]) { | ||
const style = this.style, | ||
libraryDirectory = this.libraryDirectory; | ||
const transformedMethodName = this.camel2UnderlineComponentName // eslint-disable-line | ||
? transCamel(methodName, '_') : this.camel2DashComponentName ? transCamel(methodName, '-') : methodName; | ||
const path = winPath(this.customName ? this.customName(transformedMethodName, file) : (0, _path.join)(this.libraryName, libraryDirectory, transformedMethodName, this.fileName) // eslint-disable-line | ||
const { style, libraryDirectory } = this; | ||
const transformedMethodName = this.camel2UnderlineComponentName ? transCamel(methodName, "_") : this.camel2DashComponentName ? transCamel(methodName, "-") : methodName; | ||
const path = winPath( | ||
this.customName ? this.customName(transformedMethodName, file) : (0, import_path.join)(this.libraryName, libraryDirectory, transformedMethodName, this.fileName) | ||
// eslint-disable-line | ||
); | ||
pluginState.selectedMethods[methodName] = this.transformToDefaultImport // eslint-disable-line | ||
? (0, _helperModuleImports.addDefault)(file.path, path, { | ||
nameHint: methodName | ||
}) : (0, _helperModuleImports.addNamed)(file.path, methodName, path); | ||
pluginState.selectedMethods[methodName] = this.transformToDefaultImport ? (0, import_helper_module_imports.addDefault)(file.path, path, { nameHint: methodName }) : (0, import_helper_module_imports.addNamed)(file.path, methodName, path); | ||
if (this.customStyleName) { | ||
const stylePath = winPath(this.customStyleName(transformedMethodName, file)); | ||
(0, _helperModuleImports.addSideEffect)(file.path, `${stylePath}`); | ||
(0, import_helper_module_imports.addSideEffect)(file.path, `${stylePath}`); | ||
} else if (this.styleLibraryDirectory) { | ||
const stylePath = winPath((0, _path.join)(this.libraryName, this.styleLibraryDirectory, transformedMethodName, this.fileName)); | ||
(0, _helperModuleImports.addSideEffect)(file.path, `${stylePath}`); | ||
const stylePath = winPath( | ||
(0, import_path.join)(this.libraryName, this.styleLibraryDirectory, transformedMethodName, this.fileName) | ||
); | ||
(0, import_helper_module_imports.addSideEffect)(file.path, `${stylePath}`); | ||
} else if (style === true) { | ||
(0, _helperModuleImports.addSideEffect)(file.path, `${path}/style`); | ||
} else if (style === 'css') { | ||
(0, _helperModuleImports.addSideEffect)(file.path, `${path}/style/css`); | ||
} else if (typeof style === 'function') { | ||
(0, import_helper_module_imports.addSideEffect)(file.path, `${path}/style`); | ||
} else if (style === "css") { | ||
(0, import_helper_module_imports.addSideEffect)(file.path, `${path}/style/css`); | ||
} else if (typeof style === "function") { | ||
const stylePath = style(path, file); | ||
if (stylePath) { | ||
(0, _helperModuleImports.addSideEffect)(file.path, stylePath); | ||
(0, import_helper_module_imports.addSideEffect)(file.path, stylePath); | ||
} | ||
} | ||
} | ||
return _objectSpread({}, pluginState.selectedMethods[methodName]); | ||
return { ...pluginState.selectedMethods[methodName] }; | ||
} | ||
buildExpressionHandler(node, props, path, state) { | ||
const file = path && path.hub && path.hub.file || state && state.file; | ||
const types = this.types; | ||
const { types } = this; | ||
const pluginState = this.getPluginState(state); | ||
props.forEach(prop => { | ||
if (!types.isIdentifier(node[prop])) return; | ||
props.forEach((prop) => { | ||
if (!types.isIdentifier(node[prop])) | ||
return; | ||
if (pluginState.specified[node[prop].name] && types.isImportSpecifier(path.scope.getBinding(node[prop].name).path)) { | ||
node[prop] = this.importMethod(pluginState.specified[node[prop].name], file, pluginState); // eslint-disable-line | ||
node[prop] = this.importMethod(pluginState.specified[node[prop].name], file, pluginState); | ||
} | ||
}); | ||
} | ||
buildDeclaratorHandler(node, prop, path, state) { | ||
const file = path && path.hub && path.hub.file || state && state.file; | ||
const types = this.types; | ||
const { types } = this; | ||
const pluginState = this.getPluginState(state); | ||
const checkScope = targetNode => pluginState.specified[targetNode.name] && | ||
// eslint-disable-line | ||
path.scope.hasBinding(targetNode.name) && | ||
// eslint-disable-line | ||
path.scope.getBinding(targetNode.name).path.type === 'ImportSpecifier'; // eslint-disable-line | ||
const checkScope = (targetNode) => pluginState.specified[targetNode.name] && // eslint-disable-line | ||
path.scope.hasBinding(targetNode.name) && // eslint-disable-line | ||
path.scope.getBinding(targetNode.name).path.type === "ImportSpecifier"; | ||
if (types.isIdentifier(node[prop]) && checkScope(node[prop])) { | ||
node[prop] = this.importMethod(pluginState.specified[node[prop].name], file, pluginState); // eslint-disable-line | ||
node[prop] = this.importMethod(pluginState.specified[node[prop].name], file, pluginState); | ||
} else if (types.isSequenceExpression(node[prop])) { | ||
node[prop].expressions.forEach((expressionNode, index) => { | ||
if (types.isIdentifier(expressionNode) && checkScope(expressionNode)) { | ||
node[prop].expressions[index] = this.importMethod(pluginState.specified[expressionNode.name], file, pluginState); // eslint-disable-line | ||
node[prop].expressions[index] = this.importMethod( | ||
pluginState.specified[expressionNode.name], | ||
file, | ||
pluginState | ||
); | ||
} | ||
@@ -119,24 +128,22 @@ }); | ||
} | ||
ProgramEnter(path, state) { | ||
const pluginState = this.getPluginState(state); | ||
pluginState.specified = Object.create(null); | ||
pluginState.libraryObjs = Object.create(null); | ||
pluginState.selectedMethods = Object.create(null); | ||
pluginState.specified = /* @__PURE__ */ Object.create(null); | ||
pluginState.libraryObjs = /* @__PURE__ */ Object.create(null); | ||
pluginState.selectedMethods = /* @__PURE__ */ Object.create(null); | ||
pluginState.pathsToRemove = []; | ||
} | ||
ProgramExit(path, state) { | ||
this.getPluginState(state).pathsToRemove.forEach(p => !p.removed && p.remove()); | ||
this.getPluginState(state).pathsToRemove.forEach((p) => !p.removed && p.remove()); | ||
} | ||
ImportDeclaration(path, state) { | ||
const node = path.node; | ||
// path maybe removed by prev instances. | ||
if (!node) return; | ||
const value = node.source.value; | ||
const libraryName = this.libraryName; | ||
const types = this.types; | ||
const { node } = path; | ||
if (!node) | ||
return; | ||
const { value } = node.source; | ||
const { libraryName } = this; | ||
const { types } = this; | ||
const pluginState = this.getPluginState(state); | ||
if (value === libraryName) { | ||
node.specifiers.forEach(spec => { | ||
node.specifiers.forEach((spec) => { | ||
if (types.isImportSpecifier(spec)) { | ||
@@ -152,6 +159,6 @@ pluginState.specified[spec.local.name] = spec.imported.name; | ||
CallExpression(path, state) { | ||
const node = path.node; | ||
const { node } = path; | ||
const file = path && path.hub && path.hub.file || state && state.file; | ||
const name = node.callee.name; | ||
const types = this.types; | ||
const { name } = node.callee; | ||
const { types } = this; | ||
const pluginState = this.getPluginState(state); | ||
@@ -163,5 +170,5 @@ if (types.isIdentifier(node.callee)) { | ||
} | ||
node.arguments = node.arguments.map(arg => { | ||
const argName = arg.name; | ||
if (pluginState.specified[argName] && path.scope.hasBinding(argName) && path.scope.getBinding(argName).path.type === 'ImportSpecifier') { | ||
node.arguments = node.arguments.map((arg) => { | ||
const { name: argName } = arg; | ||
if (pluginState.specified[argName] && path.scope.hasBinding(argName) && path.scope.getBinding(argName).path.type === "ImportSpecifier") { | ||
return this.importMethod(pluginState.specified[argName], file, pluginState); | ||
@@ -173,16 +180,12 @@ } | ||
MemberExpression(path, state) { | ||
const node = path.node; | ||
const { node } = path; | ||
const file = path && path.hub && path.hub.file || state && state.file; | ||
const pluginState = this.getPluginState(state); | ||
// multiple instance check. | ||
if (!node.object || !node.object.name) return; | ||
if (!node.object || !node.object.name) | ||
return; | ||
if (pluginState.libraryObjs[node.object.name]) { | ||
// antd.Button -> _Button | ||
path.replaceWith(this.importMethod(node.property.name, file, pluginState)); | ||
} else if (pluginState.specified[node.object.name] && path.scope.hasBinding(node.object.name)) { | ||
const _path$scope$getBindin = path.scope.getBinding(node.object.name), | ||
scope = _path$scope$getBindin.scope; | ||
// global variable in file scope | ||
if (scope.path.parent.type === 'File') { | ||
const { scope } = path.scope.getBinding(node.object.name); | ||
if (scope.path.parent.type === "File") { | ||
node.object = this.importMethod(pluginState.specified[node.object.name], file, pluginState); | ||
@@ -193,11 +196,11 @@ } | ||
Property(path, state) { | ||
const node = path.node; | ||
this.buildDeclaratorHandler(node, 'value', path, state); | ||
const { node } = path; | ||
this.buildDeclaratorHandler(node, "value", path, state); | ||
} | ||
VariableDeclarator(path, state) { | ||
const node = path.node; | ||
this.buildDeclaratorHandler(node, 'init', path, state); | ||
const { node } = path; | ||
this.buildDeclaratorHandler(node, "init", path, state); | ||
} | ||
ArrayExpression(path, state) { | ||
const node = path.node; | ||
const { node } = path; | ||
const props = node.elements.map((_, index) => index); | ||
@@ -207,36 +210,36 @@ this.buildExpressionHandler(node.elements, props, path, state); | ||
LogicalExpression(path, state) { | ||
const node = path.node; | ||
this.buildExpressionHandler(node, ['left', 'right'], path, state); | ||
const { node } = path; | ||
this.buildExpressionHandler(node, ["left", "right"], path, state); | ||
} | ||
ConditionalExpression(path, state) { | ||
const node = path.node; | ||
this.buildExpressionHandler(node, ['test', 'consequent', 'alternate'], path, state); | ||
const { node } = path; | ||
this.buildExpressionHandler(node, ["test", "consequent", "alternate"], path, state); | ||
} | ||
IfStatement(path, state) { | ||
const node = path.node; | ||
this.buildExpressionHandler(node, ['test'], path, state); | ||
this.buildExpressionHandler(node.test, ['left', 'right'], path, state); | ||
const { node } = path; | ||
this.buildExpressionHandler(node, ["test"], path, state); | ||
this.buildExpressionHandler(node.test, ["left", "right"], path, state); | ||
} | ||
ExpressionStatement(path, state) { | ||
const node = path.node; | ||
const types = this.types; | ||
const { node } = path; | ||
const { types } = this; | ||
if (types.isAssignmentExpression(node.expression)) { | ||
this.buildExpressionHandler(node.expression, ['right'], path, state); | ||
this.buildExpressionHandler(node.expression, ["right"], path, state); | ||
} | ||
} | ||
ReturnStatement(path, state) { | ||
const node = path.node; | ||
this.buildExpressionHandler(node, ['argument'], path, state); | ||
const { node } = path; | ||
this.buildExpressionHandler(node, ["argument"], path, state); | ||
} | ||
ExportDefaultDeclaration(path, state) { | ||
const node = path.node; | ||
this.buildExpressionHandler(node, ['declaration'], path, state); | ||
const { node } = path; | ||
this.buildExpressionHandler(node, ["declaration"], path, state); | ||
} | ||
BinaryExpression(path, state) { | ||
const node = path.node; | ||
this.buildExpressionHandler(node, ['left', 'right'], path, state); | ||
const { node } = path; | ||
this.buildExpressionHandler(node, ["left", "right"], path, state); | ||
} | ||
NewExpression(path, state) { | ||
const node = path.node; | ||
this.buildExpressionHandler(node, ['callee'], path, state); | ||
const { node } = path; | ||
this.buildExpressionHandler(node, ["callee"], path, state); | ||
const argumentsProps = node.arguments.map((_, index) => index); | ||
@@ -246,19 +249,18 @@ this.buildExpressionHandler(node.arguments, argumentsProps, path, state); | ||
SwitchStatement(path, state) { | ||
const node = path.node; | ||
this.buildExpressionHandler(node, ['discriminant'], path, state); | ||
const { node } = path; | ||
this.buildExpressionHandler(node, ["discriminant"], path, state); | ||
} | ||
SwitchCase(path, state) { | ||
const node = path.node; | ||
this.buildExpressionHandler(node, ['test'], path, state); | ||
const { node } = path; | ||
this.buildExpressionHandler(node, ["test"], path, state); | ||
} | ||
ClassDeclaration(path, state) { | ||
const node = path.node; | ||
this.buildExpressionHandler(node, ['superClass'], path, state); | ||
const { node } = path; | ||
this.buildExpressionHandler(node, ["superClass"], path, state); | ||
} | ||
SequenceExpression(path, state) { | ||
const node = path.node; | ||
const { node } = path; | ||
const expressionsProps = node.expressions.map((_, index) => index); | ||
this.buildExpressionHandler(node.expressions, expressionsProps, path, state); | ||
} | ||
} | ||
exports.default = Plugin; | ||
}; |
{ | ||
"name": "babel-plugin-import", | ||
"version": "1.13.6", | ||
"version": "1.13.7", | ||
"description": "Component modular import plugin for babel.", | ||
@@ -11,3 +11,3 @@ "repository": { | ||
"scripts": { | ||
"build": "father-build", | ||
"build": "father build", | ||
"test": "umi-test --coverage", | ||
@@ -18,3 +18,3 @@ "debug": "umi-test", | ||
"prepack": "npm run build", | ||
"prepublishOnly": "npm run build && np --no-cleanup --yolo --no-publish --any-branch" | ||
"prepublishOnly": "npm run build && father doctor && np --no-cleanup --yolo --no-publish --any-branch" | ||
}, | ||
@@ -50,3 +50,3 @@ "husky": { | ||
"eslint-plugin-prettier": "^3.1.3", | ||
"father-build": "^1.22.1", | ||
"father": "^4.0.0", | ||
"husky": "^4.2.5", | ||
@@ -53,0 +53,0 @@ "lint-staged": "^10.2.8", |
@@ -5,4 +5,7 @@ import { join } from 'path'; | ||
function transCamel(_str, symbol) { | ||
const str = _str[0].toLowerCase() + _str.substr(1); | ||
return str.replace(/([A-Z])/g, $1 => `${symbol}${$1.toLowerCase()}`); | ||
// e.g. QRCode | ||
// First match: QR | ||
// Second match: Code | ||
const cells = _str.match(/([A-Z]+(?=[A-Z]))|([A-Z]?[^A-Z]+)/g) || []; | ||
return cells.map(c => c.toLowerCase()).join(symbol); | ||
} | ||
@@ -9,0 +12,0 @@ |
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
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
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
771
37497
1