| | |
| | | } = require("../javascript/JavascriptParser"); |
| | | const traverseDestructuringAssignmentProperties = require("../util/traverseDestructuringAssignmentProperties"); |
| | | const ContextDependencyHelpers = require("./ContextDependencyHelpers"); |
| | | const { getNonOptionalPart } = require("./HarmonyImportDependency"); |
| | | const ImportContextDependency = require("./ImportContextDependency"); |
| | | const ImportDependency = require("./ImportDependency"); |
| | | const ImportEagerDependency = require("./ImportEagerDependency"); |
| | | const { ImportPhaseUtils, createGetImportPhase } = require("./ImportPhase"); |
| | | const { createGetImportPhase } = require("./ImportPhase"); |
| | | const ImportWeakDependency = require("./ImportWeakDependency"); |
| | | |
| | | /** @typedef {import("../../declarations/WebpackOptions").JavascriptParserOptions} JavascriptParserOptions */ |
| | |
| | | /** @typedef {import("../javascript/JavascriptParser")} JavascriptParser */ |
| | | /** @typedef {import("../javascript/JavascriptParser").ImportExpression} ImportExpression */ |
| | | /** @typedef {import("../javascript/JavascriptParser").Range} Range */ |
| | | /** @typedef {import("../javascript/JavascriptParser").ParserState} ParserState */ |
| | | /** @typedef {import("../javascript/JavascriptParser").JavascriptParserState} JavascriptParserState */ |
| | | /** @typedef {import("../javascript/JavascriptParser").Members} Members */ |
| | | /** @typedef {import("../javascript/JavascriptParser").MembersOptionals} MembersOptionals */ |
| | | /** @typedef {import("../javascript/JavascriptParser").ArrowFunctionExpression} ArrowFunctionExpression */ |
| | |
| | | /** @typedef {{ references: RawReferencedExports, expression: ImportExpression }} ImportSettings */ |
| | | /** @typedef {WeakMap<ImportExpression, RawReferencedExports>} State */ |
| | | |
| | | /** @type {WeakMap<ParserState, State>} */ |
| | | /** @type {WeakMap<JavascriptParserState, State>} */ |
| | | const parserStateMap = new WeakMap(); |
| | | const dynamicImportTag = Symbol("import()"); |
| | | |
| | | /** |
| | | * Returns import parser plugin state. |
| | | * @param {JavascriptParser} parser javascript parser |
| | | * @returns {State} import parser plugin state |
| | | */ |
| | |
| | | } |
| | | |
| | | /** |
| | | * Tag dynamic import referenced. |
| | | * @param {JavascriptParser} parser javascript parser |
| | | * @param {ImportExpression} importCall import expression |
| | | * @param {string} variableName variable name |
| | |
| | | } |
| | | |
| | | /** |
| | | * Gets fulfilled callback namespace obj. |
| | | * @param {CallExpression} importThen import().then() call |
| | | * @returns {Identifier | ObjectPattern | undefined} the dynamic imported namespace obj |
| | | */ |
| | |
| | | } |
| | | |
| | | /** |
| | | * Walk import then fulfilled callback. |
| | | * @param {JavascriptParser} parser javascript parser |
| | | * @param {ImportExpression} importCall import expression |
| | | * @param {ArrowFunctionExpression | FunctionExpression} fulfilledCallback the fulfilled callback |
| | |
| | | } |
| | | |
| | | /** |
| | | * Exports from enumerable. |
| | | * @template T |
| | | * @param {Iterable<T>} enumerable enumerable |
| | | * @returns {T[][]} array of array |
| | |
| | | |
| | | class ImportParserPlugin { |
| | | /** |
| | | * Creates an instance of ImportParserPlugin. |
| | | * @param {JavascriptParserOptions} options options |
| | | */ |
| | | constructor(options) { |
| | |
| | | } |
| | | |
| | | /** |
| | | * Applies the plugin by registering its hooks on the compiler. |
| | | * @param {JavascriptParser} parser the parser |
| | | * @returns {void} |
| | | */ |
| | | apply(parser) { |
| | | /** |
| | | * @param {Members} members members |
| | | * @param {MembersOptionals} membersOptionals members Optionals |
| | | * @returns {string[]} a non optional part |
| | | */ |
| | | function getNonOptionalPart(members, membersOptionals) { |
| | | let i = 0; |
| | | while (i < members.length && membersOptionals[i] === false) i++; |
| | | return i !== members.length ? members.slice(0, i) : members; |
| | | } |
| | | |
| | | parser.hooks.collectDestructuringAssignmentProperties.tap( |
| | | PLUGIN_NAME, |
| | | (expr) => { |
| | |
| | | parser.hooks.importCall.tap(PLUGIN_NAME, (expr, importThen) => { |
| | | const param = parser.evaluateExpression(expr.source); |
| | | |
| | | /** @type {null | string} */ |
| | | let chunkName = null; |
| | | let mode = /** @type {ContextMode} */ (this.options.dynamicImportMode); |
| | | /** @type {null | RegExp} */ |
| | | let include = null; |
| | | /** @type {null | RegExp} */ |
| | | let exclude = null; |
| | | /** @type {RawReferencedExports | null} */ |
| | | /** @type {null | RawReferencedExports} */ |
| | | let exports = null; |
| | | /** @type {RawChunkGroupOptions} */ |
| | | const groupOptions = {}; |
| | |
| | | } |
| | | } |
| | | |
| | | const phase = createGetImportPhase(this.options.deferImport)( |
| | | parser, |
| | | expr, |
| | | () => importOptions |
| | | ); |
| | | const phase = createGetImportPhase( |
| | | this.options.deferImport, |
| | | this.options.sourceImport |
| | | )(parser, expr, () => importOptions); |
| | | |
| | | if (importOptions) { |
| | | if (importOptions.webpackIgnore !== undefined) { |
| | |
| | | mode = "async-weak"; |
| | | } |
| | | |
| | | if (ImportPhaseUtils.isDefer(phase)) { |
| | | parser.state.module.addWarning( |
| | | new UnsupportedFeatureWarning( |
| | | "import.defer() is not yet supported for ContextModule (the import path is a dynamic expression).", |
| | | /** @type {DependencyLocation} */ (expr.loc) |
| | | ) |
| | | ); |
| | | } |
| | | |
| | | const dep = ContextDependencyHelpers.create( |
| | | ImportContextDependency, |
| | | /** @type {Range} */ (expr.range), |
| | |
| | | typePrefix: "import()", |
| | | category: "esm", |
| | | referencedExports: exports, |
| | | attributes: getImportAttributes(expr) |
| | | attributes: getImportAttributes(expr), |
| | | phase |
| | | }, |
| | | parser |
| | | ); |