| | |
| | | const { equals } = require("./util/ArrayHelpers"); |
| | | const compileBooleanMatcher = require("./util/compileBooleanMatcher"); |
| | | const memoize = require("./util/memoize"); |
| | | const propertyAccess = require("./util/propertyAccess"); |
| | | const { propertyAccess } = require("./util/property"); |
| | | const { forEachRuntime, subtractRuntime } = require("./util/runtime"); |
| | | |
| | | const getHarmonyImportDependency = memoize(() => |
| | |
| | | /** @typedef {import("./NormalModuleFactory").ModuleDependency} ModuleDependency */ |
| | | |
| | | /** |
| | | * No module id error message. |
| | | * @param {Module} module the module |
| | | * @param {ChunkGraph} chunkGraph the chunk graph |
| | | * @returns {string} error message |
| | |
| | | ).join("")}`; |
| | | |
| | | /** |
| | | * Gets global object. |
| | | * @param {string | undefined} definition global object definition |
| | | * @returns {string | undefined} save to use global object |
| | | */ |
| | |
| | | // iife |
| | | // call expression |
| | | // expression in parentheses |
| | | /^([_\p{L}][_0-9\p{L}]*)?\(.*\)$/iu.test(trimmed) |
| | | /^(?:[_\p{L}][_0-9\p{L}]*)?\(.*\)$/iu.test(trimmed) |
| | | ) { |
| | | return trimmed; |
| | | } |
| | |
| | | |
| | | class RuntimeTemplate { |
| | | /** |
| | | * Creates an instance of RuntimeTemplate. |
| | | * @param {Compilation} compilation the compilation |
| | | * @param {OutputOptions} outputOptions the compilation output options |
| | | * @param {RequestShortener} requestShortener the request shortener |
| | |
| | | |
| | | supportsConst() { |
| | | return this.outputOptions.environment.const; |
| | | } |
| | | |
| | | supportsMethodShorthand() { |
| | | return this.outputOptions.environment.methodShorthand; |
| | | } |
| | | |
| | | supportsArrowFunction() { |
| | |
| | | } |
| | | |
| | | /** |
| | | * Renders node prefix for core module. |
| | | * @param {string} mod a module |
| | | * @returns {string} a module with `node:` prefix when supported, otherwise an original name |
| | | */ |
| | |
| | | } |
| | | |
| | | /** |
| | | * Renders return const when it is supported, otherwise var. |
| | | * @returns {"const" | "var"} return `const` when it is supported, otherwise `var` |
| | | */ |
| | | renderConst() { |
| | |
| | | } |
| | | |
| | | /** |
| | | * Returning function. |
| | | * @param {string} returnValue return value |
| | | * @param {string} args arguments |
| | | * @returns {string} returning function |
| | |
| | | } |
| | | |
| | | /** |
| | | * Returns basic function. |
| | | * @param {string} args arguments |
| | | * @param {string | string[]} body body |
| | | * @returns {string} basic function |
| | |
| | | } |
| | | |
| | | /** |
| | | * Returns result expression. |
| | | * @param {(string | { expr: string })[]} args args |
| | | * @returns {string} result expression |
| | | */ |
| | |
| | | } |
| | | |
| | | /** |
| | | * Returns result expression. |
| | | * @param {(string | { expr: string })[]} args args (len >= 2) |
| | | * @returns {string} result expression |
| | | * @private |
| | |
| | | } |
| | | |
| | | /** |
| | | * Expression function. |
| | | * @param {string} expression expression |
| | | * @param {string} args arguments |
| | | * @returns {string} expression function code |
| | |
| | | } |
| | | |
| | | /** |
| | | * Returns empty function code. |
| | | * @returns {string} empty function code |
| | | */ |
| | | emptyFunction() { |
| | |
| | | } |
| | | |
| | | /** |
| | | * Returns destructure array code. |
| | | * @param {string[]} items items |
| | | * @param {string} value value |
| | | * @returns {string} destructure array code |
| | |
| | | } |
| | | |
| | | /** |
| | | * Destructure object. |
| | | * @param {string[]} items items |
| | | * @param {string} value value |
| | | * @returns {string} destructure object code |
| | |
| | | } |
| | | |
| | | /** |
| | | * Returns iIFE code. |
| | | * @param {string} args arguments |
| | | * @param {string} body body |
| | | * @returns {string} IIFE code |
| | |
| | | } |
| | | |
| | | /** |
| | | * Returns for each code. |
| | | * @param {string} variable variable |
| | | * @param {string} array array |
| | | * @param {string | string[]} body body |
| | |
| | | } |
| | | |
| | | /** |
| | | * Add a comment |
| | | * Returns comment. |
| | | * @param {object} options Information content of the comment |
| | | * @param {string=} options.request request string used originally |
| | | * @param {(string | null)=} options.chunkName name of the chunk referenced |
| | |
| | | * @returns {string} comment |
| | | */ |
| | | comment({ request, chunkName, chunkReason, message, exportName }) { |
| | | /** @type {string} */ |
| | | let content; |
| | | if (this.outputOptions.pathinfo) { |
| | | content = [message, request, chunkName, chunkReason] |
| | |
| | | } |
| | | |
| | | /** |
| | | * Throw missing module error block. |
| | | * @param {object} options generation options |
| | | * @param {string=} options.request request string used originally |
| | | * @returns {string} generated error block |
| | |
| | | } |
| | | |
| | | /** |
| | | * Throw missing module error function. |
| | | * @param {object} options generation options |
| | | * @param {string=} options.request request string used originally |
| | | * @returns {string} generated error function |
| | |
| | | } |
| | | |
| | | /** |
| | | * Returns generated error IIFE. |
| | | * @param {object} options generation options |
| | | * @param {string=} options.request request string used originally |
| | | * @returns {string} generated error IIFE |
| | |
| | | } |
| | | |
| | | /** |
| | | * Missing module statement. |
| | | * @param {object} options generation options |
| | | * @param {string=} options.request request string used originally |
| | | * @returns {string} generated error statement |
| | |
| | | } |
| | | |
| | | /** |
| | | * Missing module promise. |
| | | * @param {object} options generation options |
| | | * @param {string=} options.request request string used originally |
| | | * @returns {string} generated error code |
| | |
| | | } |
| | | |
| | | /** |
| | | * Returns the code. |
| | | * @param {object} options options object |
| | | * @param {ChunkGraph} options.chunkGraph the chunk graph |
| | | * @param {Module} options.module the module |
| | |
| | | } |
| | | |
| | | /** |
| | | * Returns the expression. |
| | | * @param {object} options options object |
| | | * @param {Module} options.module the module |
| | | * @param {ChunkGraph} options.chunkGraph the chunk graph |
| | |
| | | } |
| | | |
| | | /** |
| | | * Returns the expression. |
| | | * @param {object} options options object |
| | | * @param {Module | null} options.module the module |
| | | * @param {ChunkGraph} options.chunkGraph the chunk graph |
| | |
| | | } |
| | | |
| | | /** |
| | | * Returns the expression. |
| | | * @param {object} options options object |
| | | * @param {Module | null} options.module the module |
| | | * @param {ChunkGraph} options.chunkGraph the chunk graph |
| | |
| | | } |
| | | |
| | | /** |
| | | * Returns the expression. |
| | | * @param {object} options options object |
| | | * @param {Module} options.module the module |
| | | * @param {ChunkGraph} options.chunkGraph the chunk graph |
| | |
| | | } |
| | | |
| | | /** |
| | | * Module namespace promise. |
| | | * @param {object} options options object |
| | | * @param {ChunkGraph} options.chunkGraph the chunk graph |
| | | * @param {AsyncDependenciesBlock=} options.block the current dependencies block |
| | |
| | | runtimeRequirements |
| | | }); |
| | | |
| | | /** @type {string} */ |
| | | let appending; |
| | | let idExpr = JSON.stringify(chunkGraph.getModuleId(module)); |
| | | const comment = this.comment({ |
| | |
| | | |
| | | if (isModuleDeferred) { |
| | | runtimeRequirements.add(RuntimeGlobals.makeDeferredNamespaceObject); |
| | | const mode = getMakeDeferredNamespaceModeFromExportsType(exportsType); |
| | | |
| | | let mode = getMakeDeferredNamespaceModeFromExportsType(exportsType); |
| | | if (mode) mode = `${mode} | 16`; |
| | | |
| | | const asyncDeps = Array.from( |
| | | getOutgoingAsyncModules(chunkGraph.moduleGraph, module), |
| | | (m) => chunkGraph.getModuleId(m) |
| | |
| | | } |
| | | |
| | | /** |
| | | * Runtime condition expression. |
| | | * @param {object} options options object |
| | | * @param {ChunkGraph} options.chunkGraph the chunk graph |
| | | * @param {RuntimeSpec=} options.runtime runtime for which this code will be generated |
| | |
| | | } |
| | | |
| | | /** |
| | | * Returns the import statement and the compat statement. |
| | | * @param {object} options options object |
| | | * @param {boolean=} options.update whether a new variable should be created or the existing one updated |
| | | * @param {Module} options.module the module |
| | | * @param {Module} options.originModule module in which the statement is emitted |
| | | * @param {ModuleGraph} options.moduleGraph the module graph |
| | | * @param {ChunkGraph} options.chunkGraph the chunk graph |
| | | * @param {string} options.request the request that should be printed as comment |
| | | * @param {string} options.importVar name of the import variable |
| | | * @param {Module} options.originModule module in which the statement is emitted |
| | | * @param {boolean=} options.weak true, if this is a weak dependency |
| | | * @param {RuntimeRequirements} options.runtimeRequirements if set, will be filled with runtime requirements |
| | | * @param {ModuleDependency} options.dependency module dependency |
| | | * @param {string} options.importVar name of the import variable |
| | | * @param {string=} options.request the request that should be printed as comment |
| | | * @param {boolean=} options.weak true, if this is a weak dependency |
| | | * @param {ModuleDependency=} options.dependency module dependency |
| | | * @returns {[string, string]} the import statement and the compat statement |
| | | */ |
| | | importStatement({ |
| | |
| | | (originModule.buildMeta).strictHarmonyModule |
| | | ); |
| | | runtimeRequirements.add(RuntimeGlobals.require); |
| | | |
| | | /** @type {string} */ |
| | | let importContent; |
| | | |
| | | const isModuleDeferred = |
| | |
| | | } |
| | | |
| | | /** |
| | | * Export from import. |
| | | * @template GenerateContext |
| | | * @param {object} options options |
| | | * @param {ModuleGraph} options.moduleGraph the module graph |
| | |
| | | * @param {string | string[]} options.exportName the export name |
| | | * @param {Module} options.originModule the origin module |
| | | * @param {boolean|undefined} options.asiSafe true, if location is safe for ASI, a bracket can be emitted |
| | | * @param {boolean} options.isCall true, if expression will be called |
| | | * @param {boolean | undefined} options.isCall true, if expression will be called |
| | | * @param {boolean | null} options.callContext when false, call context will not be preserved |
| | | * @param {boolean} options.defaultInterop when true and accessing the default exports, interop code will be generated |
| | | * @param {string} options.importVar the identifier name of the import variable |
| | |
| | | } |
| | | |
| | | /** |
| | | * Returns expression. |
| | | * @param {object} options options |
| | | * @param {AsyncDependenciesBlock | undefined} options.block the async block |
| | | * @param {string} options.message the message |
| | |
| | | } |
| | | |
| | | /** |
| | | * Returns require chunk id code. |
| | | * @param {Chunk} chunk chunk |
| | | * @returns {string} require chunk id code |
| | | */ |
| | |
| | | } |
| | | |
| | | /** |
| | | * Async module factory. |
| | | * @param {object} options options |
| | | * @param {AsyncDependenciesBlock} options.block the async block |
| | | * @param {ChunkGraph} options.chunkGraph the chunk graph |
| | |
| | | } |
| | | |
| | | /** |
| | | * Sync module factory. |
| | | * @param {object} options options |
| | | * @param {Dependency} options.dependency the dependency |
| | | * @param {ChunkGraph} options.chunkGraph the chunk graph |
| | |
| | | } |
| | | |
| | | /** |
| | | * Define es module flag statement. |
| | | * @param {object} options options |
| | | * @param {string} options.exportsArgument the name of the exports object |
| | | * @param {RuntimeRequirements} options.runtimeRequirements if set, will be filled with runtime requirements |