| | |
| | | const HarmonyImportSideEffectDependency = require("./HarmonyImportSideEffectDependency"); |
| | | const { ImportPhaseUtils, createGetImportPhase } = require("./ImportPhase"); |
| | | |
| | | /** @typedef {import("../../declarations/WebpackOptions").JavascriptParserOptions} JavascriptParserOptions */ |
| | | /** @typedef {import("../Dependency").DependencyLocation} DependencyLocation */ |
| | | /** @typedef {import("../javascript/JavascriptParser")} JavascriptParser */ |
| | | /** @typedef {import("../javascript/JavascriptParser").ClassDeclaration} ClassDeclaration */ |
| | |
| | | |
| | | module.exports = class HarmonyExportDependencyParserPlugin { |
| | | /** |
| | | * @param {import("../../declarations/WebpackOptions").JavascriptParserOptions} options options |
| | | * Creates an instance of HarmonyExportDependencyParserPlugin. |
| | | * @param {JavascriptParserOptions} options options |
| | | */ |
| | | constructor(options) { |
| | | this.options = options; |
| | | this.exportPresenceMode = |
| | | options.reexportExportsPresence !== undefined |
| | | ? ExportPresenceModes.fromUserOption(options.reexportExportsPresence) |
| | | : options.exportsPresence !== undefined |
| | | ? ExportPresenceModes.fromUserOption(options.exportsPresence) |
| | | : options.strictExportPresence |
| | | ? ExportPresenceModes.ERROR |
| | | : ExportPresenceModes.AUTO; |
| | | this.exportPresenceMode = ExportPresenceModes.resolveFromOptions( |
| | | options.reexportExportsPresence, |
| | | options |
| | | ); |
| | | } |
| | | |
| | | /** |
| | | * Applies the plugin by registering its hooks on the compiler. |
| | | * @param {JavascriptParser} parser the parser |
| | | * @returns {void} |
| | | */ |
| | | apply(parser) { |
| | | const { exportPresenceMode } = this; |
| | | const getImportPhase = createGetImportPhase(this.options.deferImport); |
| | | const getImportPhase = createGetImportPhase( |
| | | this.options.deferImport, |
| | | false |
| | | ); |
| | | |
| | | parser.hooks.export.tap(PLUGIN_NAME, (statement) => { |
| | | const dep = new HarmonyExportHeaderDependency( |
| | |
| | | }) |
| | | .join(""), |
| | | node.type.endsWith("Declaration") && |
| | | /** @type {FunctionDeclaration | ClassDeclaration} */ (node).id |
| | | /** @type {FunctionDeclaration | ClassDeclaration} */ (node).id |
| | | ? /** @type {FunctionDeclaration | ClassDeclaration} */ |
| | | (node).id.name |
| | | : isFunctionDeclaration |
| | |
| | | } |
| | | : undefined |
| | | ); |
| | | dep.isAnonymousDefault = |
| | | node.type === "ArrowFunctionExpression" || |
| | | ((node.type === "FunctionDeclaration" || |
| | | node.type === "FunctionExpression" || |
| | | node.type === "ClassDeclaration" || |
| | | node.type === "ClassExpression") && |
| | | !node.id); |
| | | dep.loc = Object.create( |
| | | /** @type {DependencyLocation} */ (statement.loc) |
| | | ); |
| | |
| | | const dep = new HarmonyExportImportedSpecifierDependency( |
| | | /** @type {string} */ |
| | | (source), |
| | | parser.state.lastHarmonyImportOrder, |
| | | /** @type {number} */ |
| | | (parser.state.lastHarmonyImportOrder), |
| | | id ? [id] : [], |
| | | name, |
| | | harmonyNamedExports, |