| | |
| | | "use strict"; |
| | | |
| | | const Dependency = require("../Dependency"); |
| | | const InitFragment = require("../InitFragment"); |
| | | const Template = require("../Template"); |
| | | const { |
| | | getDependencyUsedByExportsCondition |
| | | } = require("../optimize/InnerGraph"); |
| | | const { getTrimmedIdsAndRange } = require("../util/chainedImports"); |
| | | const makeSerializable = require("../util/makeSerializable"); |
| | | const propertyAccess = require("../util/propertyAccess"); |
| | | const { propertyAccess } = require("../util/property"); |
| | | const traverseDestructuringAssignmentProperties = require("../util/traverseDestructuringAssignmentProperties"); |
| | | const HarmonyImportDependency = require("./HarmonyImportDependency"); |
| | | const { ImportPhaseUtils } = require("./ImportPhase"); |
| | |
| | | /** @typedef {HarmonyImportDependency.Ids} Ids */ |
| | | /** @typedef {import("./ImportPhase").ImportPhaseType} ImportPhaseType */ |
| | | |
| | | const idsSymbol = Symbol("HarmonyImportSpecifierDependency.ids"); |
| | | const idsSymbol = /** @type {symbol} */ ( |
| | | Symbol("HarmonyImportSpecifierDependency.ids") |
| | | ); |
| | | |
| | | const { ExportPresenceModes } = HarmonyImportDependency; |
| | | |
| | | class HarmonyImportSpecifierDependency extends HarmonyImportDependency { |
| | | /** |
| | | * Creates an instance of HarmonyImportSpecifierDependency. |
| | | * @param {string} request request |
| | | * @param {number} sourceOrder source order |
| | | * @param {Ids} ids ids |
| | |
| | | this.range = range; |
| | | this.idRanges = idRanges; |
| | | this.exportPresenceMode = exportPresenceMode; |
| | | /** @type {undefined | boolean} */ |
| | | this.namespaceObjectAsContext = false; |
| | | /** @type {undefined | boolean} */ |
| | | this.call = undefined; |
| | | /** @type {undefined | boolean} */ |
| | | this.directImport = undefined; |
| | | /** @type {undefined | boolean | string} */ |
| | | this.shorthand = undefined; |
| | | /** @type {undefined | boolean} */ |
| | | this.asiSafe = undefined; |
| | | /** @type {UsedByExports | undefined} */ |
| | | this.usedByExports = undefined; |
| | |
| | | } |
| | | |
| | | // TODO webpack 6 remove |
| | | /** |
| | | * Returns id. |
| | | * @deprecated |
| | | */ |
| | | get id() { |
| | | throw new Error("id was renamed to ids and type changed to string[]"); |
| | | } |
| | | |
| | | // TODO webpack 6 remove |
| | | /** |
| | | * Returns id. |
| | | * @deprecated |
| | | */ |
| | | getId() { |
| | | throw new Error("id was renamed to ids and type changed to string[]"); |
| | | } |
| | | |
| | | // TODO webpack 6 remove |
| | | /** |
| | | * Updates id. |
| | | * @deprecated |
| | | */ |
| | | setId() { |
| | | throw new Error("id was renamed to ids and type changed to string[]"); |
| | | } |
| | |
| | | } |
| | | |
| | | /** |
| | | * Returns the imported ids. |
| | | * @param {ModuleGraph} moduleGraph the module graph |
| | | * @returns {Ids} the imported ids |
| | | */ |
| | |
| | | } |
| | | |
| | | /** |
| | | * Updates ids using the provided module graph. |
| | | * @param {ModuleGraph} moduleGraph the module graph |
| | | * @param {Ids} ids the imported ids |
| | | * @returns {void} |
| | |
| | | } |
| | | |
| | | /** |
| | | * Returns function to determine if the connection is active. |
| | | * @param {ModuleGraph} moduleGraph module graph |
| | | * @returns {null | false | GetConditionFn} function to determine if the connection is active |
| | | */ |
| | |
| | | } |
| | | |
| | | /** |
| | | * Gets module evaluation side effects state. |
| | | * @param {ModuleGraph} moduleGraph the module graph |
| | | * @returns {ConnectionState} how this dependency connects the module to referencing modules |
| | | */ |
| | |
| | | } |
| | | |
| | | /** |
| | | * Get referenced exports in destructuring. |
| | | * @param {Ids=} ids ids |
| | | * @returns {RawReferencedExports} referenced exports |
| | | */ |
| | |
| | | } |
| | | |
| | | /** |
| | | * Get effective export presence level. |
| | | * @param {ModuleGraph} moduleGraph module graph |
| | | * @returns {ExportPresenceMode} effective mode |
| | | */ |
| | |
| | | } |
| | | |
| | | /** |
| | | * Returns warnings |
| | | * Returns warnings. |
| | | * @param {ModuleGraph} moduleGraph module graph |
| | | * @returns {WebpackError[] | null | undefined} warnings |
| | | */ |
| | |
| | | } |
| | | |
| | | /** |
| | | * Returns errors |
| | | * Returns errors. |
| | | * @param {ModuleGraph} moduleGraph module graph |
| | | * @returns {WebpackError[] | null | undefined} errors |
| | | */ |
| | |
| | | } |
| | | |
| | | /** |
| | | * Returns errors. |
| | | * @param {ModuleGraph} moduleGraph module graph |
| | | * @returns {WebpackError[] | undefined} errors |
| | | */ |
| | |
| | | } |
| | | |
| | | /** |
| | | * Serializes this instance into the provided serializer context. |
| | | * @param {ObjectSerializerContext} context context |
| | | */ |
| | | serialize(context) { |
| | |
| | | } |
| | | |
| | | /** |
| | | * Restores this instance from the provided deserializer context. |
| | | * @param {ObjectDeserializerContext} context context |
| | | */ |
| | | deserialize(context) { |
| | |
| | | HarmonyImportDependency.Template |
| | | ) { |
| | | /** |
| | | * Applies the plugin by registering its hooks on the compiler. |
| | | * @param {Dependency} dependency the dependency for which the template should be applied |
| | | * @param {ReplaceSource} source the current replace source which can be modified |
| | | * @param {DependencyTemplateContext} templateContext the context object |
| | |
| | | */ |
| | | apply(dependency, source, templateContext) { |
| | | const dep = /** @type {HarmonyImportSpecifierDependency} */ (dependency); |
| | | const { moduleGraph, runtime } = templateContext; |
| | | const { moduleGraph, runtime, initFragments } = templateContext; |
| | | const connection = moduleGraph.getConnection(dep); |
| | | // Skip rendering depending when dependency is conditional |
| | | if (connection && !connection.isTargetActive(runtime)) return; |
| | | |
| | | // Only render declaration for import specifier when the dependency is conditional |
| | | if (connection && !connection.isTargetActive(runtime)) { |
| | | initFragments.push( |
| | | new InitFragment( |
| | | `/* unused harmony import specifier */ var ${dep.name};\n`, |
| | | InitFragment.STAGE_HARMONY_IMPORTS, |
| | | 0, |
| | | `unused import specifier ${dep.name}` |
| | | ) |
| | | ); |
| | | |
| | | return; |
| | | } |
| | | |
| | | const ids = dep.getIds(moduleGraph); |
| | | const { |
| | |
| | | } |
| | | |
| | | /** |
| | | * Returns generated code. |
| | | * @param {HarmonyImportSpecifierDependency} dep dependency |
| | | * @param {ReplaceSource} source source |
| | | * @param {DependencyTemplateContext} templateContext context |
| | |
| | | const { moduleGraph, module, runtime, concatenationScope } = |
| | | templateContext; |
| | | const connection = moduleGraph.getConnection(dep); |
| | | /** @type {string} */ |
| | | let exportExpr; |
| | | if ( |
| | | connection && |