| | |
| | | const FUNCTION_CONTENT_REGEX = /^function\s?\(\)\s?\{\r?\n?|\r?\n?\}$/g; |
| | | const INDENT_MULTILINE_REGEX = /^\t/gm; |
| | | const LINE_SEPARATOR_REGEX = /\r?\n/g; |
| | | const IDENTIFIER_NAME_REPLACE_REGEX = /^([^a-zA-Z$_])/; |
| | | const IDENTIFIER_ALPHA_NUMERIC_NAME_REPLACE_REGEX = /[^a-zA-Z0-9$]+/g; |
| | | const IDENTIFIER_NAME_REPLACE_REGEX = /^([^a-z$_])/i; |
| | | const IDENTIFIER_ALPHA_NUMERIC_NAME_REPLACE_REGEX = /[^a-z0-9$]+/gi; |
| | | const COMMENT_END_REGEX = /\*\//g; |
| | | const PATH_NAME_NORMALIZE_REPLACE_REGEX = /[^a-zA-Z0-9_!§$()=\-^°]+/g; |
| | | const PATH_NAME_NORMALIZE_REPLACE_REGEX = /[^a-z0-9_!§$()=\-^°]+/gi; |
| | | const MATCH_PADDED_HYPHENS_REPLACE_REGEX = /^-|-$/g; |
| | | |
| | | /** |
| | | * Defines the render manifest options type used by this module. |
| | | * @typedef {object} RenderManifestOptions |
| | | * @property {Chunk} chunk the chunk used to render |
| | | * @property {string} hash |
| | |
| | | /** @typedef {RenderManifestEntryTemplated | RenderManifestEntryStatic} RenderManifestEntry */ |
| | | |
| | | /** |
| | | * Defines the render manifest entry templated type used by this module. |
| | | * @typedef {object} RenderManifestEntryTemplated |
| | | * @property {() => Source} render |
| | | * @property {TemplatePath} filenameTemplate |
| | |
| | | */ |
| | | |
| | | /** |
| | | * Defines the render manifest entry static type used by this module. |
| | | * @typedef {object} RenderManifestEntryStatic |
| | | * @property {() => Source} render |
| | | * @property {string} filename |
| | |
| | | */ |
| | | |
| | | /** |
| | | * Defines the module filter predicate type used by this module. |
| | | * @typedef {(module: Module) => boolean} ModuleFilterPredicate |
| | | */ |
| | | |
| | | /** |
| | | * Represents the template runtime component. |
| | | * @typedef {object} Stringable |
| | | * @property {() => string} toString |
| | | */ |
| | | |
| | | class Template { |
| | | /** |
| | | * @template {EXPECTED_FUNCTION} T |
| | | * @param {T} fn a runtime function (.runtime.js) "template" |
| | | * Gets function content. |
| | | * @param {Stringable} fn a runtime function (.runtime.js) "template" |
| | | * @returns {string} the updated and normalized function string |
| | | */ |
| | | static getFunctionContent(fn) { |
| | |
| | | } |
| | | |
| | | /** |
| | | * Returns created identifier. |
| | | * @param {string} str the string converted to identifier |
| | | * @returns {string} created identifier |
| | | */ |
| | |
| | | } |
| | | |
| | | /** |
| | | * Returns a commented version of string. |
| | | * @param {string} str string to be converted to commented in bundle code |
| | | * @returns {string} returns a commented version of string |
| | | */ |
| | |
| | | } |
| | | |
| | | /** |
| | | * Returns a commented version of string. |
| | | * @param {string} str string to be converted to "normal comment" |
| | | * @returns {string} returns a commented version of string |
| | | */ |
| | |
| | | } |
| | | |
| | | /** |
| | | * Returns normalized bundle-safe path. |
| | | * @param {string} str string path to be normalized |
| | | * @returns {string} normalized bundle-safe path |
| | | */ |
| | |
| | | |
| | | // map number to a single character a-z, A-Z or multiple characters if number is too big |
| | | /** |
| | | * Number to identifier. |
| | | * @param {number} n number to convert to ident |
| | | * @returns {string} returns single character ident |
| | | */ |
| | |
| | | } |
| | | |
| | | /** |
| | | * Number to identifier continuation. |
| | | * @param {number} n number to convert to ident |
| | | * @returns {string} returns single character ident |
| | | */ |
| | |
| | | } |
| | | |
| | | /** |
| | | * Returns converted identity. |
| | | * @param {string | string[]} s string to convert to identity |
| | | * @returns {string} converted identity |
| | | */ |
| | |
| | | } |
| | | |
| | | /** |
| | | * Returns new prefix string. |
| | | * @param {string | string[]} s string to create prefix for |
| | | * @param {string} prefix prefix to compose |
| | | * @returns {string} returns new prefix string |
| | |
| | | } |
| | | |
| | | /** |
| | | * Returns a single string from array. |
| | | * @param {string | string[]} str string or string collection |
| | | * @returns {string} returns a single string from array |
| | | */ |
| | |
| | | } |
| | | |
| | | /** |
| | | * Defines the with id type used by this module. |
| | | * @typedef {object} WithId |
| | | * @property {string | number} id |
| | | */ |
| | | |
| | | /** |
| | | * Gets modules array bounds. |
| | | * @param {WithId[]} modules a collection of modules to get array bounds for |
| | | * @returns {[number, number] | false} returns the upper and lower array bounds |
| | | * or false if not every module has a number based id |
| | |
| | | } |
| | | |
| | | /** |
| | | * Renders chunk modules. |
| | | * @param {ChunkRenderContext} renderContext render context |
| | | * @param {Module[]} modules modules to render (should be ordered by identifier) |
| | | * @param {(module: Module) => Source | null} renderModule function to render a module |
| | | * @param {(module: Module, renderInArray?: boolean) => Source | null} renderModule function to render a module |
| | | * @param {string=} prefix applying prefix strings |
| | | * @returns {Source | null} rendered chunk modules in a Source object or null if no modules |
| | | */ |
| | |
| | | if (modules.length === 0) { |
| | | return null; |
| | | } |
| | | /** @type {{ id: ModuleId, source: Source | "false" }[]} */ |
| | | const allModules = modules.map((module) => ({ |
| | | id: /** @type {ModuleId} */ (chunkGraph.getModuleId(module)), |
| | | source: renderModule(module) || "false" |
| | | /** @type {{ id: ModuleId, module: Module }[]} */ |
| | | const modulesWithId = modules.map((m) => ({ |
| | | id: /** @type {ModuleId} */ (chunkGraph.getModuleId(m)), |
| | | module: m |
| | | })); |
| | | const bounds = Template.getModulesArrayBounds(allModules); |
| | | const bounds = Template.getModulesArrayBounds(modulesWithId); |
| | | const renderInObject = bounds === false; |
| | | |
| | | /** @type {{ id: ModuleId, source: Source | "false" }[]} */ |
| | | const allModules = modulesWithId.map(({ id, module }) => ({ |
| | | id, |
| | | source: renderModule(module, renderInObject) || "false" |
| | | })); |
| | | |
| | | if (bounds) { |
| | | // Render a spare array |
| | | const minId = bounds[0]; |
| | |
| | | if (i !== 0) { |
| | | source.add(",\n"); |
| | | } |
| | | source.add(`\n/***/ ${JSON.stringify(module.id)}:\n`); |
| | | source.add( |
| | | `\n/***/ ${JSON.stringify(module.id)}${renderContext.runtimeTemplate.supportsMethodShorthand() && module.source !== "false" ? "" : ":"}\n` |
| | | ); |
| | | source.add(module.source); |
| | | } |
| | | source.add(`\n\n${prefix}}`); |
| | |
| | | } |
| | | |
| | | /** |
| | | * Renders runtime modules. |
| | | * @param {RuntimeModule[]} runtimeModules array of runtime modules in order |
| | | * @param {RenderContext & { codeGenerationResults?: CodeGenerationResults }} renderContext render context |
| | | * @returns {Source} rendered runtime modules in a Source object |
| | |
| | | const source = new ConcatSource(); |
| | | for (const module of runtimeModules) { |
| | | const codeGenerationResults = renderContext.codeGenerationResults; |
| | | /** @type {undefined | Source} */ |
| | | let runtimeSource; |
| | | if (codeGenerationResults) { |
| | | runtimeSource = codeGenerationResults.getSource( |
| | |
| | | moduleGraph: renderContext.moduleGraph, |
| | | runtimeTemplate: renderContext.runtimeTemplate, |
| | | runtime: renderContext.chunk.runtime, |
| | | runtimes: [renderContext.chunk.runtime], |
| | | codeGenerationResults |
| | | }); |
| | | if (!codeGenResult) continue; |
| | |
| | | } |
| | | |
| | | /** |
| | | * Renders chunk runtime modules. |
| | | * @param {RuntimeModule[]} runtimeModules array of runtime modules in order |
| | | * @param {RenderContext} renderContext render context |
| | | * @returns {Source} rendered chunk runtime modules in a Source object |