diff options
Diffstat (limited to 'node_modules/@babel/helper-define-polyfill-provider/lib')
5 files changed, 82 insertions, 126 deletions
diff --git a/node_modules/@babel/helper-define-polyfill-provider/lib/imports-cache.js b/node_modules/@babel/helper-define-polyfill-provider/lib/imports-cache.js deleted file mode 100644 index 553c8930..00000000 --- a/node_modules/@babel/helper-define-polyfill-provider/lib/imports-cache.js +++ /dev/null @@ -1,96 +0,0 @@ -"use strict"; - -exports.__esModule = true; -exports.default = void 0; -var _babel = _interopRequireWildcard(require("@babel/core")); -function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); } -function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; } -const { - types: t -} = _babel.default || _babel; -class ImportsCache { - constructor(resolver) { - this._imports = new WeakMap(); - this._anonymousImports = new WeakMap(); - this._lastImports = new WeakMap(); - this._resolver = resolver; - } - storeAnonymous(programPath, url, - // eslint-disable-next-line no-undef - getVal) { - const key = this._normalizeKey(programPath, url); - const imports = this._ensure(this._anonymousImports, programPath, Set); - if (imports.has(key)) return; - const node = getVal(programPath.node.sourceType === "script", t.stringLiteral(this._resolver(url))); - imports.add(key); - this._injectImport(programPath, node); - } - storeNamed(programPath, url, name, getVal) { - const key = this._normalizeKey(programPath, url, name); - const imports = this._ensure(this._imports, programPath, Map); - if (!imports.has(key)) { - const { - node, - name: id - } = getVal(programPath.node.sourceType === "script", t.stringLiteral(this._resolver(url)), t.identifier(name)); - imports.set(key, id); - this._injectImport(programPath, node); - } - return t.identifier(imports.get(key)); - } - _injectImport(programPath, node) { - const lastImport = this._lastImports.get(programPath); - let newNodes; - if (lastImport && lastImport.node && - // Sometimes the AST is modified and the "last import" - // we have has been replaced - lastImport.parent === programPath.node && lastImport.container === programPath.node.body) { - newNodes = lastImport.insertAfter(node); - } else { - newNodes = programPath.unshiftContainer("body", node); - } - const newNode = newNodes[newNodes.length - 1]; - this._lastImports.set(programPath, newNode); - - /* - let lastImport; - programPath.get("body").forEach(path => { - if (path.isImportDeclaration()) lastImport = path; - if ( - path.isExpressionStatement() && - isRequireCall(path.get("expression")) - ) { - lastImport = path; - } - if ( - path.isVariableDeclaration() && - path.get("declarations").length === 1 && - (isRequireCall(path.get("declarations.0.init")) || - (path.get("declarations.0.init").isMemberExpression() && - isRequireCall(path.get("declarations.0.init.object")))) - ) { - lastImport = path; - } - });*/ - } - - _ensure(map, programPath, Collection) { - let collection = map.get(programPath); - if (!collection) { - collection = new Collection(); - map.set(programPath, collection); - } - return collection; - } - _normalizeKey(programPath, url, name = "") { - const { - sourceType - } = programPath.node; - - // If we rely on the imported binding (the "name" parameter), we also need to cache - // based on the sourceType. This is because the module transforms change the names - // of the import variables. - return `${name && sourceType}::${url}::${name}`; - } -} -exports.default = ImportsCache;
\ No newline at end of file diff --git a/node_modules/@babel/helper-define-polyfill-provider/lib/index.js b/node_modules/@babel/helper-define-polyfill-provider/lib/index.js index 4ea2980f..b0dc90b7 100644 --- a/node_modules/@babel/helper-define-polyfill-provider/lib/index.js +++ b/node_modules/@babel/helper-define-polyfill-provider/lib/index.js @@ -5,7 +5,7 @@ exports.default = definePolyfillProvider; var _helperPluginUtils = require("@babel/helper-plugin-utils"); var _helperCompilationTargets = _interopRequireWildcard(require("@babel/helper-compilation-targets")); var _utils = require("./utils"); -var _importsCache = _interopRequireDefault(require("./imports-cache")); +var _importsInjector = _interopRequireDefault(require("./imports-injector")); var _debugUtils = require("./debug-utils"); var _normalizeOptions = require("./normalize-options"); var v = _interopRequireWildcard(require("./visitors")); @@ -90,13 +90,16 @@ function instantiateProvider(factory, options, missingDependencies, dirname, deb providerOptions, absoluteImports } = resolveOptions(options, babelApi); - const getUtils = (0, _utils.createUtilsGetter)(new _importsCache.default(moduleName => deps.resolve(dirname, moduleName, absoluteImports))); // eslint-disable-next-line prefer-const let include, exclude; let polyfillsSupport; let polyfillsNames; let filterPolyfills; + const getUtils = (0, _utils.createUtilsGetter)(new _importsInjector.default(moduleName => deps.resolve(dirname, moduleName, absoluteImports), name => { + var _polyfillsNames$get, _polyfillsNames; + return (_polyfillsNames$get = (_polyfillsNames = polyfillsNames) == null ? void 0 : _polyfillsNames.get(name)) != null ? _polyfillsNames$get : Infinity; + })); const depsCache = new Map(); const api = { babel: babelApi, @@ -154,29 +157,40 @@ function instantiateProvider(factory, options, missingDependencies, dirname, deb throw new Error(`The "${providerName}" provider doesn't support the "${method}" polyfilling method.`); } if (Array.isArray(provider.polyfills)) { - polyfillsNames = new Set(provider.polyfills); + polyfillsNames = new Map(provider.polyfills.map((name, index) => [name, index])); filterPolyfills = provider.filterPolyfills; } else if (provider.polyfills) { - polyfillsNames = new Set(Object.keys(provider.polyfills)); + polyfillsNames = new Map(Object.keys(provider.polyfills).map((name, index) => [name, index])); polyfillsSupport = provider.polyfills; filterPolyfills = provider.filterPolyfills; } else { - polyfillsNames = new Set(); + polyfillsNames = new Map(); } ({ include, exclude } = (0, _normalizeOptions.validateIncludeExclude)(providerName, polyfillsNames, providerOptions.include || [], providerOptions.exclude || [])); + let callProvider; + if (methodName === "usageGlobal") { + callProvider = (payload, path) => { + var _ref; + const utils = getUtils(path); + return (_ref = provider[methodName](payload, utils, path)) != null ? _ref : false; + }; + } else { + callProvider = (payload, path) => { + const utils = getUtils(path); + provider[methodName](payload, utils, path); + return false; + }; + } return { debug, method, targets, provider, providerName, - callProvider(payload, path) { - const utils = getUtils(path); - provider[methodName](payload, utils, path); - } + callProvider }; } function definePolyfillProvider(factory) { diff --git a/node_modules/@babel/helper-define-polyfill-provider/lib/normalize-options.js b/node_modules/@babel/helper-define-polyfill-provider/lib/normalize-options.js index 62937764..16b196a9 100644 --- a/node_modules/@babel/helper-define-polyfill-provider/lib/normalize-options.js +++ b/node_modules/@babel/helper-define-polyfill-provider/lib/normalize-options.js @@ -26,7 +26,7 @@ function validateIncludeExclude(provider, polyfills, includePatterns, excludePat const regexp = patternToRegExp(pattern); if (!regexp) return false; let matched = false; - for (const polyfill of polyfills) { + for (const polyfill of polyfills.keys()) { if (regexp.test(polyfill)) { matched = true; current.add(polyfill); diff --git a/node_modules/@babel/helper-define-polyfill-provider/lib/utils.js b/node_modules/@babel/helper-define-polyfill-provider/lib/utils.js index 0aff88b1..0f13a007 100644 --- a/node_modules/@babel/helper-define-polyfill-provider/lib/utils.js +++ b/node_modules/@babel/helper-define-polyfill-provider/lib/utils.js @@ -135,13 +135,13 @@ function createUtilsGetter(cache) { return path => { const prog = path.findParent(p => p.isProgram()); return { - injectGlobalImport(url) { - cache.storeAnonymous(prog, url, (isScript, source) => { + injectGlobalImport(url, moduleName) { + cache.storeAnonymous(prog, url, moduleName, (isScript, source) => { return isScript ? template.statement.ast`require(${source})` : t.importDeclaration([], source); }); }, - injectNamedImport(url, name, hint = name) { - return cache.storeNamed(prog, url, name, (isScript, source, name) => { + injectNamedImport(url, name, hint = name, moduleName) { + return cache.storeNamed(prog, url, name, moduleName, (isScript, source, name) => { const id = prog.scope.generateUidIdentifier(hint); return { node: isScript ? hoist(template.statement.ast` @@ -151,8 +151,8 @@ function createUtilsGetter(cache) { }; }); }, - injectDefaultImport(url, hint = url) { - return cache.storeNamed(prog, url, "default", (isScript, source) => { + injectDefaultImport(url, hint = url, moduleName) { + return cache.storeNamed(prog, url, "default", moduleName, (isScript, source) => { const id = prog.scope.generateUidIdentifier(hint); return { node: isScript ? hoist(template.statement.ast`var ${id} = require(${source})`) : t.importDeclaration([t.importDefaultSpecifier(id)], source), diff --git a/node_modules/@babel/helper-define-polyfill-provider/lib/visitors/usage.js b/node_modules/@babel/helper-define-polyfill-provider/lib/visitors/usage.js index 4a4c5472..77def9f8 100644 --- a/node_modules/@babel/helper-define-polyfill-provider/lib/visitors/usage.js +++ b/node_modules/@babel/helper-define-polyfill-provider/lib/visitors/usage.js @@ -3,6 +3,17 @@ exports.__esModule = true; exports.default = void 0; var _utils = require("../utils"); +function isRemoved(path) { + if (path.removed) return true; + if (!path.parentPath) return false; + if (path.listKey) { + var _path$parentPath$node; + if (!((_path$parentPath$node = path.parentPath.node) != null && (_path$parentPath$node = _path$parentPath$node[path.listKey]) != null && _path$parentPath$node.includes(path.node))) return true; + } else { + if (path.parentPath.node[path.key] !== path.node) return true; + } + return isRemoved(path.parentPath); +} var _default = callProvider => { function property(object, key, placement, path) { return callProvider({ @@ -12,31 +23,58 @@ var _default = callProvider => { placement }, path); } + function handleReferencedIdentifier(path) { + const { + node: { + name + }, + scope + } = path; + if (scope.getBindingIdentifier(name)) return; + callProvider({ + kind: "global", + name + }, path); + } + function analyzeMemberExpression(path) { + const key = (0, _utils.resolveKey)(path.get("property"), path.node.computed); + return { + key, + handleAsMemberExpression: !!key && key !== "prototype" + }; + } return { // Symbol(), new Promise ReferencedIdentifier(path) { const { - node: { - name - }, - scope + parentPath } = path; - if (scope.getBindingIdentifier(name)) return; - callProvider({ - kind: "global", - name - }, path); + if (parentPath.isMemberExpression({ + object: path.node + }) && analyzeMemberExpression(parentPath).handleAsMemberExpression) { + return; + } + handleReferencedIdentifier(path); }, MemberExpression(path) { - const key = (0, _utils.resolveKey)(path.get("property"), path.node.computed); - if (!key || key === "prototype") return; + const { + key, + handleAsMemberExpression + } = analyzeMemberExpression(path); + if (!handleAsMemberExpression) return; const object = path.get("object"); - if (object.isIdentifier()) { + let objectIsGlobalIdentifier = object.isIdentifier(); + if (objectIsGlobalIdentifier) { const binding = object.scope.getBinding(object.node.name); - if (binding && binding.path.isImportNamespaceSpecifier()) return; + if (binding) { + if (binding.path.isImportNamespaceSpecifier()) return; + objectIsGlobalIdentifier = false; + } } const source = (0, _utils.resolveSource)(object); - return property(source.id, key, source.placement, path); + let skipObject = property(source.id, key, source.placement, path); + skipObject || (skipObject = !objectIsGlobalIdentifier || path.shouldSkip || object.shouldSkip || isRemoved(object)); + if (!skipObject) handleReferencedIdentifier(object); }, ObjectPattern(path) { const { |
