| | |
| | | const { UsageState } = require("../ExportsInfo"); |
| | | const RuntimeGlobals = require("../RuntimeGlobals"); |
| | | const Template = require("../Template"); |
| | | const propertyAccess = require("../util/propertyAccess"); |
| | | const { propertyAccess } = require("../util/property"); |
| | | const { getEntryRuntime } = require("../util/runtime"); |
| | | const AbstractLibraryPlugin = require("./AbstractLibraryPlugin"); |
| | | |
| | |
| | | /** @typedef {import("../util/Hash")} Hash */ |
| | | |
| | | /** |
| | | * Defines the shared type used by this module. |
| | | * @template T |
| | | * @typedef {import("./AbstractLibraryPlugin").LibraryContext<T>} LibraryContext<T> |
| | | */ |
| | | |
| | | const KEYWORD_REGEX = |
| | | /^(await|break|case|catch|class|const|continue|debugger|default|delete|do|else|enum|export|extends|false|finally|for|function|if|implements|import|in|instanceof|interface|let|new|null|package|private|protected|public|return|super|switch|static|this|throw|try|true|typeof|var|void|while|with|yield)$/; |
| | | /^(?:await|break|case|catch|class|const|continue|debugger|default|delete|do|else|enum|export|extends|false|finally|for|function|if|implements|import|in|instanceof|interface|let|new|null|package|private|protected|public|return|super|switch|static|this|throw|try|true|typeof|var|void|while|with|yield)$/; |
| | | const IDENTIFIER_REGEX = |
| | | /^[\p{L}\p{Nl}$_][\p{L}\p{Nl}$\p{Mn}\p{Mc}\p{Nd}\p{Pc}]*$/iu; |
| | | |
| | |
| | | !KEYWORD_REGEX.test(name) && IDENTIFIER_REGEX.test(name); |
| | | |
| | | /** |
| | | * Returns code to access the accessor while initializing. |
| | | * @param {string[]} accessor variable plus properties |
| | | * @param {number} existingLength items of accessor that are existing already |
| | | * @param {boolean=} initLast if the last property should also be initialized to an object |
| | |
| | | /** @typedef {string[] | "global"} LibraryPrefix */ |
| | | |
| | | /** |
| | | * Defines the assign library plugin options type used by this module. |
| | | * @typedef {object} AssignLibraryPluginOptions |
| | | * @property {LibraryType} type |
| | | * @property {LibraryPrefix} prefix name prefix |
| | |
| | | /** @typedef {string | string[]} LibraryName */ |
| | | |
| | | /** |
| | | * Defines the assign library plugin parsed type used by this module. |
| | | * @typedef {object} AssignLibraryPluginParsed |
| | | * @property {LibraryName} name |
| | | * @property {LibraryExport=} export |
| | | */ |
| | | |
| | | /** |
| | | * Represents the assign library plugin runtime component. |
| | | * @typedef {AssignLibraryPluginParsed} T |
| | | * @extends {AbstractLibraryPlugin<AssignLibraryPluginParsed>} |
| | | */ |
| | | class AssignLibraryPlugin extends AbstractLibraryPlugin { |
| | | /** |
| | | * Creates an instance of AssignLibraryPlugin. |
| | | * @param {AssignLibraryPluginOptions} options the plugin options |
| | | */ |
| | | constructor(options) { |
| | |
| | | pluginName: "AssignLibraryPlugin", |
| | | type: options.type |
| | | }); |
| | | /** @type {AssignLibraryPluginOptions["prefix"]} */ |
| | | this.prefix = options.prefix; |
| | | /** @type {AssignLibraryPluginOptions["declare"]} */ |
| | | this.declare = options.declare; |
| | | /** @type {AssignLibraryPluginOptions["unnamed"]} */ |
| | | this.unnamed = options.unnamed; |
| | | /** @type {AssignLibraryPluginOptions["named"]} */ |
| | | this.named = options.named || "assign"; |
| | | } |
| | | |
| | | /** |
| | | * Returns preprocess as needed by overriding. |
| | | * @param {LibraryOptions} library normalized library option |
| | | * @returns {T | false} preprocess as needed by overriding |
| | | * @returns {T} preprocess as needed by overriding |
| | | */ |
| | | parseOptions(library) { |
| | | const { name } = library; |
| | |
| | | } |
| | | |
| | | /** |
| | | * Finish entry module. |
| | | * @param {Module} module the exporting entry module |
| | | * @param {string} entryName the name of the entrypoint |
| | | * @param {LibraryContext<T>} libraryContext context |
| | |
| | | } |
| | | |
| | | /** |
| | | * Returns the prefix. |
| | | * @param {Compilation} compilation the compilation |
| | | * @returns {LibraryPrefix} the prefix |
| | | */ |
| | |
| | | } |
| | | |
| | | /** |
| | | * Get resolved full name. |
| | | * @param {AssignLibraryPluginParsed} options the library options |
| | | * @param {Chunk} chunk the chunk |
| | | * @param {Compilation} compilation the compilation |
| | |
| | | } |
| | | |
| | | /** |
| | | * Returns source with library export. |
| | | * @param {Source} source source |
| | | * @param {RenderContext} renderContext render context |
| | | * @param {LibraryContext<T>} libraryContext context |
| | |
| | | } |
| | | |
| | | /** |
| | | * Embed in runtime bailout. |
| | | * @param {Module} module the exporting entry module |
| | | * @param {RenderContext} renderContext render context |
| | | * @param {LibraryContext<T>} libraryContext context |
| | |
| | | } |
| | | |
| | | /** |
| | | * Strict runtime bailout. |
| | | * @param {RenderContext} renderContext render context |
| | | * @param {LibraryContext<T>} libraryContext context |
| | | * @returns {string | undefined} bailout reason |
| | |
| | | } |
| | | |
| | | /** |
| | | * Renders source with library export. |
| | | * @param {Source} source source |
| | | * @param {Module} module module |
| | | * @param {StartupRenderContext} renderContext render context |
| | |
| | | } |
| | | |
| | | /** |
| | | * Processes the provided chunk. |
| | | * @param {Chunk} chunk the chunk |
| | | * @param {RuntimeRequirements} set runtime requirements |
| | | * @param {LibraryContext<T>} libraryContext context |
| | |
| | | } |
| | | |
| | | /** |
| | | * Processes the provided chunk. |
| | | * @param {Chunk} chunk the chunk |
| | | * @param {Hash} hash hash |
| | | * @param {ChunkHashContext} chunkHashContext chunk hash context |