mirror of https://github.com/webpack/webpack.git
fix: no `Function` types
This commit is contained in:
parent
cb25853b58
commit
70bdb248e4
|
@ -1,3 +1,8 @@
|
|||
type TODO = any;
|
||||
type EXPECTED_ANY = any;
|
||||
type EXPECTED_FUNCTION = Function;
|
||||
type EXPECTED_OBJECT = object;
|
||||
|
||||
declare module "*.json";
|
||||
|
||||
// Deprecated NodeJS API usages in webpack
|
||||
|
@ -124,6 +129,7 @@ declare module "neo-async" {
|
|||
|
||||
// There are no typings for @webassemblyjs/ast
|
||||
declare module "@webassemblyjs/ast" {
|
||||
export type AST = TODO;
|
||||
export interface Visitor {
|
||||
ModuleImport?: (p: NodePath<ModuleImport>) => void;
|
||||
ModuleExport?: (p: NodePath<ModuleExport>) => void;
|
||||
|
@ -131,20 +137,27 @@ declare module "@webassemblyjs/ast" {
|
|||
Global?: (p: NodePath<Global>) => void;
|
||||
}
|
||||
export function traverse(
|
||||
ast: any,
|
||||
ast: AST,
|
||||
visitor: Visitor
|
||||
): void;
|
||||
export class NodePath<T> {
|
||||
node: T;
|
||||
remove(): void;
|
||||
}
|
||||
export class Node {}
|
||||
export class Node {
|
||||
type: string;
|
||||
}
|
||||
export class Identifier extends Node {
|
||||
value: string;
|
||||
}
|
||||
export class Start extends Node {
|
||||
index: Identifier;
|
||||
}
|
||||
export class Module extends Node {
|
||||
id: TODO;
|
||||
fields: Node[];
|
||||
metadata: TODO;
|
||||
}
|
||||
export class ModuleImportDescription {
|
||||
type: string;
|
||||
valtype?: string;
|
||||
|
@ -207,7 +220,7 @@ declare module "@webassemblyjs/ast" {
|
|||
inf?: boolean,
|
||||
raw?: string
|
||||
): FloatLiteral;
|
||||
export function global(globalType: string, nodes: Node[]): Global;
|
||||
export function global(globalType: GlobalType, nodes: Node[]): Global;
|
||||
export function identifier(identifier: string): Identifier;
|
||||
export function funcParam(valType: string, id: Identifier): FuncParam;
|
||||
export function instruction(inst: string, args?: Node[]): Instruction;
|
||||
|
@ -233,12 +246,12 @@ declare module "@webassemblyjs/ast" {
|
|||
index: Index
|
||||
): ModuleExportDescr;
|
||||
|
||||
export function getSectionMetadata(ast: any, section: string): { vectorOfSize: { value: number } };
|
||||
export function getSectionMetadata(ast: AST, section: string): { vectorOfSize: { value: number } };
|
||||
export class FuncSignature {
|
||||
args: string[];
|
||||
result: string[];
|
||||
}
|
||||
export function moduleContextFromModuleAST(ast: any): any;
|
||||
export function moduleContextFromModuleAST(module: Module): TODO;
|
||||
|
||||
// Node matcher
|
||||
export function isGlobalType(n: Node): boolean;
|
||||
|
@ -248,12 +261,12 @@ declare module "@webassemblyjs/ast" {
|
|||
}
|
||||
|
||||
declare module "@webassemblyjs/wasm-parser" {
|
||||
export function decode(source: string | Buffer, options: { dump?: boolean, ignoreCodeSection?: boolean, ignoreDataSection?: boolean, ignoreCustomNameSection?: boolean }): any;
|
||||
export function decode(source: string | Buffer, options: { dump?: boolean, ignoreCodeSection?: boolean, ignoreDataSection?: boolean, ignoreCustomNameSection?: boolean }): import("@webassemblyjs/ast").AST;
|
||||
}
|
||||
|
||||
declare module "@webassemblyjs/wasm-edit" {
|
||||
export function addWithAST(ast: any, bin: any, newNodes: import("@webassemblyjs/ast").Node[]): ArrayBuffer;
|
||||
export function editWithAST(ast: any, bin: any, visitors: import("@webassemblyjs/ast").Visitor): ArrayBuffer;
|
||||
export function addWithAST(ast: import("@webassemblyjs/ast").AST, bin: any, newNodes: import("@webassemblyjs/ast").Node[]): ArrayBuffer;
|
||||
export function editWithAST(ast: import("@webassemblyjs/ast").AST, bin: any, visitors: import("@webassemblyjs/ast").Visitor): ArrayBuffer;
|
||||
}
|
||||
|
||||
declare module "webpack-sources" {
|
||||
|
@ -406,10 +419,6 @@ interface ImportAttributeNode {
|
|||
value: import("estree").Literal;
|
||||
}
|
||||
|
||||
type TODO = any;
|
||||
type EXPECTED_ANY = any;
|
||||
type EXPECTED_OBJECT = object;
|
||||
|
||||
type RecursiveArrayOrRecord<T> =
|
||||
| { [index: string]: RecursiveArrayOrRecord<T> }
|
||||
| Array<RecursiveArrayOrRecord<T>>
|
||||
|
|
|
@ -494,11 +494,15 @@ export type CssFilename = FilenameTemplate;
|
|||
/**
|
||||
* Similar to `output.devtoolModuleFilenameTemplate`, but used in the case of duplicate module identifiers.
|
||||
*/
|
||||
export type DevtoolFallbackModuleFilenameTemplate = string | Function;
|
||||
export type DevtoolFallbackModuleFilenameTemplate =
|
||||
| string
|
||||
| ((context: TODO) => string);
|
||||
/**
|
||||
* Filename template string of function for the sources array in a generated SourceMap.
|
||||
*/
|
||||
export type DevtoolModuleFilenameTemplate = string | Function;
|
||||
export type DevtoolModuleFilenameTemplate =
|
||||
| string
|
||||
| ((context: TODO) => string);
|
||||
/**
|
||||
* Module namespace to use when interpolating filename template string for the sources array in a generated SourceMap. Defaults to `output.library` if not set. It's useful for avoiding runtime collisions in sourcemaps from multiple webpack projects built as libraries.
|
||||
*/
|
||||
|
@ -1936,7 +1940,14 @@ export interface OptimizationSplitChunksOptions {
|
|||
/**
|
||||
* Give chunks created a name (chunks with equal name are merged).
|
||||
*/
|
||||
name?: false | string | Function;
|
||||
name?:
|
||||
| false
|
||||
| string
|
||||
| ((
|
||||
module: import("../lib/Module"),
|
||||
chunks: import("../lib/Chunk")[],
|
||||
key: string
|
||||
) => string | undefined);
|
||||
/**
|
||||
* Compare used exports when checking common modules. Modules will only be put in the same chunk when exports are equal.
|
||||
*/
|
||||
|
@ -1981,7 +1992,7 @@ export interface OptimizationSplitChunksCacheGroup {
|
|||
/**
|
||||
* Assign modules to a cache group by module layer.
|
||||
*/
|
||||
layer?: RegExp | string | Function;
|
||||
layer?: RegExp | string | ((layer: string | null) => boolean);
|
||||
/**
|
||||
* Maximum number of requests which are accepted for on-demand loading.
|
||||
*/
|
||||
|
@ -2021,7 +2032,14 @@ export interface OptimizationSplitChunksCacheGroup {
|
|||
/**
|
||||
* Give chunks for this cache group a name (chunks with equal name are merged).
|
||||
*/
|
||||
name?: false | string | Function;
|
||||
name?:
|
||||
| false
|
||||
| string
|
||||
| ((
|
||||
module: import("../lib/Module"),
|
||||
chunks: import("../lib/Chunk")[],
|
||||
key: string
|
||||
) => string | undefined);
|
||||
/**
|
||||
* Priority of this cache group.
|
||||
*/
|
||||
|
@ -2033,11 +2051,17 @@ export interface OptimizationSplitChunksCacheGroup {
|
|||
/**
|
||||
* Assign modules to a cache group by module name.
|
||||
*/
|
||||
test?: RegExp | string | Function;
|
||||
test?:
|
||||
| RegExp
|
||||
| string
|
||||
| ((
|
||||
module: import("../lib/Module"),
|
||||
context: import("../lib/optimize/SplitChunksPlugin").CacheGroupsContext
|
||||
) => boolean);
|
||||
/**
|
||||
* Assign modules to a cache group by module type.
|
||||
*/
|
||||
type?: RegExp | string | Function;
|
||||
type?: RegExp | string | ((type: string) => boolean);
|
||||
/**
|
||||
* Compare used exports when checking common modules. Modules will only be put in the same chunk when exports are equal.
|
||||
*/
|
||||
|
|
|
@ -39,7 +39,7 @@ export interface SourceMapDevToolPluginOptions {
|
|||
/**
|
||||
* Generator string or function to create identifiers of modules for the 'sources' array in the SourceMap used only if 'moduleFilenameTemplate' would result in a conflict.
|
||||
*/
|
||||
fallbackModuleFilenameTemplate?: string | Function;
|
||||
fallbackModuleFilenameTemplate?: string | ((context: any) => string);
|
||||
/**
|
||||
* Path prefix to which the [file] placeholder is relative to.
|
||||
*/
|
||||
|
@ -59,7 +59,7 @@ export interface SourceMapDevToolPluginOptions {
|
|||
/**
|
||||
* Generator string or function to create identifiers of modules for the 'sources' array in the SourceMap.
|
||||
*/
|
||||
moduleFilenameTemplate?: string | Function;
|
||||
moduleFilenameTemplate?: string | ((context: any) => string);
|
||||
/**
|
||||
* Namespace prefix to allow multiple webpack roots in the devtools.
|
||||
*/
|
||||
|
|
|
@ -324,22 +324,42 @@ export default [
|
|||
"error",
|
||||
{
|
||||
contexts: [
|
||||
// No `@type {*}`
|
||||
{
|
||||
comment: "JsdocBlock:has(JsdocTypeAny)",
|
||||
message: "Please use `any`."
|
||||
},
|
||||
// No `@type {?}`
|
||||
{
|
||||
comment: "JsdocBlock:has(JsdocTypeUnknown)",
|
||||
message: "Please use `unknown` or `any`"
|
||||
},
|
||||
// Prefer TypeScript syntax for functions
|
||||
{
|
||||
comment: "JsdocBlock:has(JsdocTypeFunction[arrow=false])",
|
||||
message:
|
||||
"Please use TypeScript syntax - `(a: string, b: boolean) => number`"
|
||||
},
|
||||
// No `*` type
|
||||
{
|
||||
comment: "JsdocBlock:has(JsdocTypeAny)",
|
||||
message: "Please use `any`."
|
||||
},
|
||||
// No `?` type
|
||||
{
|
||||
comment: "JsdocBlock:has(JsdocTypeUnknown)",
|
||||
message: "Please use `unknown` or `any`"
|
||||
},
|
||||
// No `Function` type
|
||||
{
|
||||
comment:
|
||||
"JsdocBlock:has(JsdocTypeName[value=/^(function|Function)$/])",
|
||||
message:
|
||||
"Please use provide types for function - `(a: number, b: number) -> number` instead `Function`"
|
||||
}
|
||||
// No `Object` type
|
||||
// {
|
||||
// comment:
|
||||
// "JsdocBlock:has(JsdocTag[tag!=typedef]:has(JsdocTypeName[value=/^(object|Object)$/]))",
|
||||
// message:
|
||||
// "Please use provide types for object - `{ property: number:, result: () => number}` instead `Object`"
|
||||
// },
|
||||
// No `any` type
|
||||
// {
|
||||
// comment: "JsdocBlock:has(JsdocTypeName[value=/^any$/])",
|
||||
// message:
|
||||
// "Please use provide types instead `any`"
|
||||
// },
|
||||
]
|
||||
}
|
||||
]
|
||||
|
|
|
@ -69,8 +69,6 @@ class ModuleHashInfo {
|
|||
}
|
||||
}
|
||||
|
||||
/** @template T @typedef {(set: SortableSet<T>) => T[]} SetToArrayFunction<T> */
|
||||
|
||||
/**
|
||||
* @template T
|
||||
* @param {SortableSet<T>} set the set
|
||||
|
@ -121,19 +119,22 @@ const modulesBySourceType = sourceTypesByModule => set => {
|
|||
};
|
||||
const defaultModulesBySourceType = modulesBySourceType(undefined);
|
||||
|
||||
/**
|
||||
* @typedef {(set: SortableSet<Module>) => Module[]} ModuleSetToArrayFunction
|
||||
*/
|
||||
|
||||
/**
|
||||
* @template T
|
||||
* @type {WeakMap<Function, any>}
|
||||
* @type {WeakMap<ModuleComparator, ModuleSetToArrayFunction>}
|
||||
*/
|
||||
const createOrderedArrayFunctionMap = new WeakMap();
|
||||
|
||||
/**
|
||||
* @template T
|
||||
* @param {(a: T, b:T) => -1 | 0 | 1 } comparator comparator function
|
||||
* @returns {SetToArrayFunction<T>} set as ordered array
|
||||
* @param {ModuleComparator} comparator comparator function
|
||||
* @returns {ModuleSetToArrayFunction} set as ordered array
|
||||
*/
|
||||
const createOrderedArrayFunction = comparator => {
|
||||
/** @type {SetToArrayFunction<T>} */
|
||||
let fn = createOrderedArrayFunctionMap.get(comparator);
|
||||
if (fn !== undefined) return fn;
|
||||
fn = set => {
|
||||
|
|
|
@ -457,9 +457,6 @@ const byLocation = compareSelect(err => err.loc, compareLocations);
|
|||
|
||||
const compareErrors = concatComparators(byModule, byLocation, byMessage);
|
||||
|
||||
/** @type {WeakMap<Dependency, Module & { restoreFromUnsafeCache: Function } | null>} */
|
||||
const unsafeCacheDependencies = new WeakMap();
|
||||
|
||||
/**
|
||||
* @typedef {object} KnownUnsafeCacheData
|
||||
* @property {FactoryMeta} [factoryMeta] factory meta
|
||||
|
@ -470,7 +467,14 @@ const unsafeCacheDependencies = new WeakMap();
|
|||
|
||||
/** @typedef {KnownUnsafeCacheData & Record<string, any>} UnsafeCacheData */
|
||||
|
||||
/** @type {WeakMap<Module & { restoreFromUnsafeCache: Function }, UnsafeCacheData>} */
|
||||
/**
|
||||
* @typedef {Module & { restoreFromUnsafeCache?: (unsafeCacheData: UnsafeCacheData, moduleFactory: ModuleFactory, compilationParams: CompilationParams) => void }} ModuleWithRestoreFromUnsafeCache
|
||||
*/
|
||||
|
||||
/** @type {WeakMap<Dependency, ModuleWithRestoreFromUnsafeCache | null>} */
|
||||
const unsafeCacheDependencies = new WeakMap();
|
||||
|
||||
/** @type {WeakMap<ModuleWithRestoreFromUnsafeCache, UnsafeCacheData>} */
|
||||
const unsafeCacheData = new WeakMap();
|
||||
|
||||
class Compilation {
|
||||
|
@ -483,7 +487,7 @@ class Compilation {
|
|||
this._backCompat = compiler._backCompat;
|
||||
|
||||
const getNormalModuleLoader = () => deprecatedNormalModuleLoaderHook(this);
|
||||
/** @typedef {{ additionalAssets?: true | Function }} ProcessAssetsAdditionalOptions */
|
||||
/** @typedef {{ additionalAssets?: true | TODO }} ProcessAssetsAdditionalOptions */
|
||||
/** @type {AsyncSeriesHook<[CompilationAssets], ProcessAssetsAdditionalOptions>} */
|
||||
const processAssetsHook = new AsyncSeriesHook(["assets"]);
|
||||
|
||||
|
@ -1143,9 +1147,9 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
|
|||
this.usedModuleIds = null;
|
||||
/** @type {boolean} */
|
||||
this.needAdditionalPass = false;
|
||||
/** @type {Set<Module & { restoreFromUnsafeCache: Function }>} */
|
||||
/** @type {Set<ModuleWithRestoreFromUnsafeCache>} */
|
||||
this._restoredUnsafeCacheModuleEntries = new Set();
|
||||
/** @type {Map<string, Module & { restoreFromUnsafeCache: Function }>} */
|
||||
/** @type {Map<string, ModuleWithRestoreFromUnsafeCache>} */
|
||||
this._restoredUnsafeCacheEntries = new Map();
|
||||
/** @type {WeakSet<Module>} */
|
||||
this.builtModules = new WeakSet();
|
||||
|
@ -1985,7 +1989,7 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
|
|||
}
|
||||
|
||||
const module =
|
||||
/** @type {Module & { restoreFromUnsafeCache?: Function }} */
|
||||
/** @type {ModuleWithRestoreFromUnsafeCache} */
|
||||
(_module);
|
||||
|
||||
if (
|
||||
|
@ -1996,7 +2000,7 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
|
|||
this._unsafeCachePredicate(module)
|
||||
) {
|
||||
const unsafeCacheableModule =
|
||||
/** @type {Module & { restoreFromUnsafeCache: Function }} */
|
||||
/** @type {ModuleWithRestoreFromUnsafeCache} */
|
||||
(module);
|
||||
for (let i = 0; i < dependencies.length; i++) {
|
||||
const dependency = dependencies[i];
|
||||
|
|
|
@ -33,8 +33,8 @@ const createHash = require("./util/createHash");
|
|||
/** @typedef {import("./logging/Logger").Logger} Logger */
|
||||
/** @typedef {import("./util/createHash").Algorithm} Algorithm */
|
||||
|
||||
/** @typedef {null | undefined | RegExp | Function | string | number | boolean | bigint | undefined} CodeValuePrimitive */
|
||||
/** @typedef {RecursiveArrayOrRecord<CodeValuePrimitive|RuntimeValue>} CodeValue */
|
||||
/** @typedef {null | undefined | RegExp | EXPECTED_FUNCTION | string | number | boolean | bigint | undefined} CodeValuePrimitive */
|
||||
/** @typedef {RecursiveArrayOrRecord<CodeValuePrimitive | RuntimeValue>} CodeValue */
|
||||
|
||||
/**
|
||||
* @typedef {object} RuntimeValueOptions
|
||||
|
@ -408,10 +408,10 @@ class DefinePlugin {
|
|||
};
|
||||
|
||||
/**
|
||||
* @template {Function} T
|
||||
* @template T
|
||||
* @param {string} key key
|
||||
* @param {T} fn fn
|
||||
* @returns {(expression: Expression) => TODO} result
|
||||
* @param {(expression: Expression) => T} fn fn
|
||||
* @returns {(expression: Expression) => T} result
|
||||
*/
|
||||
const withValueDependency =
|
||||
(key, fn) =>
|
||||
|
|
|
@ -11,14 +11,14 @@ const createHash = require("./util/createHash");
|
|||
/** @typedef {import("./DependencyTemplate")} DependencyTemplate */
|
||||
/** @typedef {typeof import("./util/Hash")} Hash */
|
||||
|
||||
/** @typedef {new (...args: any[]) => Dependency} DependencyConstructor */
|
||||
/** @typedef {new (...args: EXPECTED_ANY[]) => Dependency} DependencyConstructor */
|
||||
|
||||
class DependencyTemplates {
|
||||
/**
|
||||
* @param {string | Hash} hashFunction the hash function to use
|
||||
*/
|
||||
constructor(hashFunction = "md4") {
|
||||
/** @type {Map<Function, DependencyTemplate>} */
|
||||
/** @type {Map<DependencyConstructor, DependencyTemplate>} */
|
||||
this._map = new Map();
|
||||
/** @type {string} */
|
||||
this._hash = "31d6cfe0d16ae931b73c59d7e0c089c0";
|
||||
|
|
|
@ -29,11 +29,6 @@ class IgnorePlugin {
|
|||
constructor(options) {
|
||||
validate(options);
|
||||
this.options = options;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {Function}
|
||||
*/
|
||||
this.checkIgnore = this.checkIgnore.bind(this);
|
||||
}
|
||||
|
||||
|
|
|
@ -92,10 +92,10 @@ const getHash =
|
|||
* Returns a lazy object. The object is lazy in the sense that the properties are
|
||||
* only evaluated when they are accessed. This is only obtained by setting a function as the value for each key.
|
||||
* @param {Record<string, () => T>} obj the object to convert to a lazy access object
|
||||
* @returns {object} the lazy access object
|
||||
* @returns {T} the lazy access object
|
||||
*/
|
||||
const lazyObject = obj => {
|
||||
const newObj = {};
|
||||
const newObj = /** @type {T} */ ({});
|
||||
for (const key of Object.keys(obj)) {
|
||||
const fn = obj[key];
|
||||
Object.defineProperty(newObj, key, {
|
||||
|
@ -118,11 +118,8 @@ const SQUARE_BRACKET_TAG_REGEXP = /\[\\*([\w-]+)\\*\]/gi;
|
|||
|
||||
/**
|
||||
* @param {Module | string} module the module
|
||||
* @param {TODO} options options
|
||||
* @param {object} contextInfo context info
|
||||
* @param {RequestShortener} contextInfo.requestShortener requestShortener
|
||||
* @param {ChunkGraph} contextInfo.chunkGraph chunk graph
|
||||
* @param {string | Hash=} contextInfo.hashFunction the hash function to use
|
||||
* @param {{ namespace?: string, moduleFilenameTemplate?: string | TODO }} options options
|
||||
* @param {{ requestShortener: RequestShortener, chunkGraph: ChunkGraph, hashFunction?: string | Hash }} contextInfo context info
|
||||
* @returns {string} the filename
|
||||
*/
|
||||
ModuleFilenameHelpers.createFilename = (
|
||||
|
@ -141,6 +138,7 @@ ModuleFilenameHelpers.createFilename = (
|
|||
})
|
||||
};
|
||||
|
||||
/** @type {ReturnStringCallback} */
|
||||
let absoluteResourcePath;
|
||||
let hash;
|
||||
/** @type {ReturnStringCallback} */
|
||||
|
@ -155,7 +153,8 @@ ModuleFilenameHelpers.createFilename = (
|
|||
(memoize(() => requestShortener.shorten(module)));
|
||||
identifier = shortIdentifier;
|
||||
moduleId = () => "";
|
||||
absoluteResourcePath = () => module.split("!").pop();
|
||||
absoluteResourcePath = () =>
|
||||
/** @type {string} */ (module.split("!").pop());
|
||||
hash = getHash(identifier, hashFunction);
|
||||
} else {
|
||||
shortIdentifier = memoize(() =>
|
||||
|
@ -170,7 +169,7 @@ ModuleFilenameHelpers.createFilename = (
|
|||
absoluteResourcePath = () =>
|
||||
module instanceof NormalModule
|
||||
? module.resource
|
||||
: module.identifier().split("!").pop();
|
||||
: /** @type {string} */ (module.identifier().split("!").pop());
|
||||
hash = getHash(identifier, hashFunction);
|
||||
}
|
||||
const resource =
|
||||
|
|
|
@ -146,16 +146,12 @@ class SourceMapDevToolPlugin {
|
|||
? false
|
||||
: // eslint-disable-next-line no-useless-concat
|
||||
options.append || "\n//# source" + "MappingURL=[url]";
|
||||
/** @type {string | Function} */
|
||||
this.moduleFilenameTemplate =
|
||||
options.moduleFilenameTemplate || "webpack://[namespace]/[resourcePath]";
|
||||
/** @type {string | Function} */
|
||||
this.fallbackModuleFilenameTemplate =
|
||||
options.fallbackModuleFilenameTemplate ||
|
||||
"webpack://[namespace]/[resourcePath]?[hash]";
|
||||
/** @type {string} */
|
||||
this.namespace = options.namespace || "";
|
||||
/** @type {SourceMapDevToolPluginOptions} */
|
||||
this.options = options;
|
||||
}
|
||||
|
||||
|
@ -196,10 +192,6 @@ class SourceMapDevToolPlugin {
|
|||
const cache = compilation.getCache("SourceMapDevToolPlugin");
|
||||
/** @type {Map<string | Module, string>} */
|
||||
const moduleToSourceNameMapping = new Map();
|
||||
/**
|
||||
* @type {Function}
|
||||
* @returns {void}
|
||||
*/
|
||||
const reportProgress =
|
||||
ProgressPlugin.getReporter(compilation.compiler) || (() => {});
|
||||
|
||||
|
|
|
@ -90,7 +90,8 @@ const MATCH_PADDED_HYPHENS_REPLACE_REGEX = /^-|-$/g;
|
|||
|
||||
class Template {
|
||||
/**
|
||||
* @param {Function} fn a runtime function (.runtime.js) "template"
|
||||
* @template {EXPECTED_FUNCTION} T
|
||||
* @param {T} fn a runtime function (.runtime.js) "template"
|
||||
* @returns {string} the updated and normalized function string
|
||||
*/
|
||||
static getFunctionContent(fn) {
|
||||
|
|
|
@ -50,10 +50,10 @@ const prepareId = id => {
|
|||
* @param {((arg0: number) => string) | undefined} handler handler
|
||||
* @param {AssetInfo | undefined} assetInfo asset info
|
||||
* @param {string} hashName hash name
|
||||
* @returns {ReplacerFunction} hash replacer function
|
||||
* @returns {Replacer} hash replacer function
|
||||
*/
|
||||
const hashLength = (replacer, handler, assetInfo, hashName) => {
|
||||
/** @type {ReplacerFunction} */
|
||||
/** @type {Replacer} */
|
||||
const fn = (match, arg, input) => {
|
||||
let result;
|
||||
const length = arg && Number.parseInt(arg, 10);
|
||||
|
@ -81,7 +81,7 @@ const hashLength = (replacer, handler, assetInfo, hashName) => {
|
|||
return fn;
|
||||
};
|
||||
|
||||
/** @typedef {(match: string, arg?: string, input?: string) => string} Replacer */
|
||||
/** @typedef {(match: string, arg: string | undefined, input: string) => string} Replacer */
|
||||
|
||||
/**
|
||||
* @param {string | number | null | undefined | (() => string | number | null | undefined)} value value
|
||||
|
@ -113,10 +113,11 @@ const replacer = (value, allowEmpty) => {
|
|||
const deprecationCache = new Map();
|
||||
const deprecatedFunction = (() => () => {})();
|
||||
/**
|
||||
* @param {Function} fn function
|
||||
* @template {(...args: EXPECTED_ANY[]) => EXPECTED_ANY} T
|
||||
* @param {T} fn function
|
||||
* @param {string} message message
|
||||
* @param {string} code code
|
||||
* @returns {(...args: any[]) => void} function with deprecation output
|
||||
* @returns {T} function with deprecation output
|
||||
*/
|
||||
const deprecated = (fn, message, code) => {
|
||||
let d = deprecationCache.get(message);
|
||||
|
@ -124,10 +125,12 @@ const deprecated = (fn, message, code) => {
|
|||
d = util.deprecate(deprecatedFunction, message, code);
|
||||
deprecationCache.set(message, d);
|
||||
}
|
||||
return (...args) => {
|
||||
d();
|
||||
return fn(...args);
|
||||
};
|
||||
return /** @type {T} */ (
|
||||
(...args) => {
|
||||
d();
|
||||
return fn(...args);
|
||||
}
|
||||
);
|
||||
};
|
||||
|
||||
/** @typedef {string | ((pathData: PathData, assetInfo?: AssetInfo) => string)} TemplatePath */
|
||||
|
@ -141,7 +144,7 @@ const deprecated = (fn, message, code) => {
|
|||
const replacePathVariables = (path, data, assetInfo) => {
|
||||
const chunkGraph = data.chunkGraph;
|
||||
|
||||
/** @type {Map<string, Function>} */
|
||||
/** @type {Map<string, Replacer>} */
|
||||
const replacements = new Map();
|
||||
|
||||
// Filename context
|
||||
|
@ -366,7 +369,7 @@ const replacePathVariables = (path, data, assetInfo) => {
|
|||
const [, kind, arg] = contentMatch;
|
||||
const replacer = replacements.get(kind);
|
||||
if (replacer !== undefined) {
|
||||
return replacer(match, arg, path);
|
||||
return replacer(match, arg, /** @type {string} */ (path));
|
||||
}
|
||||
} else if (match.startsWith("[\\") && match.endsWith("\\]")) {
|
||||
return `[${match.slice(2, -2)}]`;
|
||||
|
|
|
@ -152,7 +152,7 @@ class Profiler {
|
|||
* @property {Tracer} trace instance of Tracer
|
||||
* @property {number} counter Counter
|
||||
* @property {Profiler} profiler instance of Profiler
|
||||
* @property {Function} end the end function
|
||||
* @property {(callback: (err?: null | Error) => void) => void} end the end function
|
||||
*/
|
||||
|
||||
/**
|
||||
|
@ -208,9 +208,6 @@ const createTrace = (fs, outputPath) => {
|
|||
trace,
|
||||
counter,
|
||||
profiler,
|
||||
/**
|
||||
* @param {() => void} callback callback
|
||||
*/
|
||||
end: callback => {
|
||||
trace.push("]");
|
||||
// Wait until the write stream finishes.
|
||||
|
|
|
@ -56,7 +56,7 @@ const HMR_DEPENDENCY_TYPES = new Set([
|
|||
]);
|
||||
|
||||
/**
|
||||
* @param {undefined|string|RegExp|Function} test test option
|
||||
* @param {Options["test"]} test test option
|
||||
* @param {Module} module the module
|
||||
* @returns {boolean | null | string} true, if the module should be selected
|
||||
*/
|
||||
|
@ -343,13 +343,19 @@ class LazyCompilationDependencyFactory extends ModuleFactory {
|
|||
* @returns {Promise<BackendApi>} backend
|
||||
*/
|
||||
|
||||
/** @typedef {BackendHandler | PromiseBackendHandler} BackEnd */
|
||||
|
||||
/**
|
||||
* @typedef {object} Options options
|
||||
* @property {BackEnd} backend the backend
|
||||
* @property {boolean=} entries
|
||||
* @property {boolean=} imports
|
||||
* @property {(RegExp | string | ((module: Module) => boolean))=} test additional filter for lazy compiled entrypoint modules
|
||||
*/
|
||||
|
||||
class LazyCompilationPlugin {
|
||||
/**
|
||||
* @param {object} options options
|
||||
* @param {BackendHandler | PromiseBackendHandler} options.backend the backend
|
||||
* @param {boolean} options.entries true, when entries are lazy compiled
|
||||
* @param {boolean} options.imports true, when import() modules are lazy compiled
|
||||
* @param {RegExp | string | ((module: Module) => boolean) | undefined} options.test additional filter for lazy compiled entrypoint modules
|
||||
* @param {Options} options options
|
||||
*/
|
||||
constructor({ backend, entries, imports, test }) {
|
||||
this.backend = backend;
|
||||
|
|
|
@ -64,7 +64,7 @@ const memoize = require("./util/memoize");
|
|||
/** @typedef {import("./util/fs").OutputFileSystem} OutputFileSystem */
|
||||
|
||||
/**
|
||||
* @template {Function} T
|
||||
* @template {EXPECTED_FUNCTION} T
|
||||
* @param {() => T} factory factory function
|
||||
* @returns {T} function
|
||||
*/
|
||||
|
|
|
@ -124,9 +124,9 @@ const MinMaxSizeWarning = require("./MinMaxSizeWarning");
|
|||
|
||||
/**
|
||||
* @callback GetName
|
||||
* @param {Module=} module
|
||||
* @param {Chunk[]=} chunks
|
||||
* @param {string=} key
|
||||
* @param {Module} module
|
||||
* @param {Chunk[]} chunks
|
||||
* @param {string} key
|
||||
* @returns {string=}
|
||||
*/
|
||||
|
||||
|
@ -407,7 +407,7 @@ const totalSize = sizes => {
|
|||
};
|
||||
|
||||
/**
|
||||
* @param {false | string | Function | undefined} name the chunk name
|
||||
* @param {OptimizationSplitChunksCacheGroup["name"]} name the chunk name
|
||||
* @returns {GetName | undefined} a function to get the name of the chunk
|
||||
*/
|
||||
const normalizeName = name => {
|
||||
|
@ -519,7 +519,7 @@ const normalizeCacheGroups = (cacheGroups, defaultSizeTypes) => {
|
|||
};
|
||||
|
||||
/**
|
||||
* @param {undefined|boolean|string|RegExp|Function} test test option
|
||||
* @param {OptimizationSplitChunksCacheGroup["test"]} test test option
|
||||
* @param {Module} module the module
|
||||
* @param {CacheGroupsContext} context context object
|
||||
* @returns {boolean} true, if the module should be selected
|
||||
|
@ -542,7 +542,7 @@ const checkTest = (test, module, context) => {
|
|||
};
|
||||
|
||||
/**
|
||||
* @param {undefined|string|RegExp|Function} test type option
|
||||
* @param {OptimizationSplitChunksCacheGroup["type"]} test type option
|
||||
* @param {Module} module the module
|
||||
* @returns {boolean} true, if the module should be selected
|
||||
*/
|
||||
|
@ -563,7 +563,7 @@ const checkModuleType = (test, module) => {
|
|||
};
|
||||
|
||||
/**
|
||||
* @param {undefined|string|RegExp|Function} test type option
|
||||
* @param {OptimizationSplitChunksCacheGroup["layer"]} test type option
|
||||
* @param {Module} module the module
|
||||
* @returns {boolean} true, if the module should be selected
|
||||
*/
|
||||
|
|
|
@ -157,14 +157,14 @@ jsTypes.set(ReferenceError, new ErrorObjectSerializer(ReferenceError));
|
|||
jsTypes.set(SyntaxError, new ErrorObjectSerializer(SyntaxError));
|
||||
jsTypes.set(TypeError, new ErrorObjectSerializer(TypeError));
|
||||
|
||||
// If in a sandboxed environment (e. g. jest), this escapes the sandbox and registers
|
||||
// real Object and Array types to. These types may occur in the wild too, e. g. when
|
||||
// If in a sandboxed environment (e.g. jest), this escapes the sandbox and registers
|
||||
// real Object and Array types to. These types may occur in the wild too, e.g. when
|
||||
// using Structured Clone in postMessage.
|
||||
// eslint-disable-next-line n/exports-style
|
||||
if (exports.constructor !== Object) {
|
||||
// eslint-disable-next-line jsdoc/check-types, n/exports-style
|
||||
const Obj = /** @type {typeof Object} */ (exports.constructor);
|
||||
const Fn = /** @type {typeof Function} */ (Obj.constructor);
|
||||
// eslint-disable-next-line n/exports-style
|
||||
const Obj = /** @type {ObjectConstructor} */ (exports.constructor);
|
||||
const Fn = /** @type {FunctionConstructor} */ (Obj.constructor);
|
||||
for (const [type, config] of Array.from(jsTypes)) {
|
||||
if (type) {
|
||||
const Type = new Fn(`return ${type.name};`)();
|
||||
|
|
|
@ -98,7 +98,7 @@ const { makePathsRelative, parseResource } = require("../util/identifier");
|
|||
* @property {string=} message
|
||||
* @property {string[]=} trace
|
||||
* @property {StatsLoggingEntry[]=} children
|
||||
* @property {any[]=} args
|
||||
* @property {EXPECTED_ANY[]=} args
|
||||
* @property {number=} time
|
||||
*/
|
||||
|
||||
|
@ -374,8 +374,9 @@ const mapObject = (obj, fn) => {
|
|||
};
|
||||
|
||||
/**
|
||||
* @template T
|
||||
* @param {Compilation} compilation the compilation
|
||||
* @param {(compilation: Compilation, name: string) => any[]} getItems get items
|
||||
* @param {(compilation: Compilation, name: string) => T[]} getItems get items
|
||||
* @returns {number} total number
|
||||
*/
|
||||
const countWithChildren = (compilation, getItems) => {
|
||||
|
@ -1576,7 +1577,7 @@ const SIMPLE_EXTRACTORS = {
|
|||
}
|
||||
};
|
||||
|
||||
/** @type {Record<string, Record<string, (thing: any, context: StatsFactoryContext, options: NormalizedStatsOptions) => boolean | undefined>>} */
|
||||
/** @type {Record<string, Record<string, (thing: ModuleGraphConnection, context: StatsFactoryContext, options: NormalizedStatsOptions, idx: number, i: number) => boolean | undefined>>} */
|
||||
const FILTER = {
|
||||
"module.reasons": {
|
||||
"!orphanModules": (reason, { compilation: { chunkGraph } }) => {
|
||||
|
@ -1590,7 +1591,7 @@ const FILTER = {
|
|||
}
|
||||
};
|
||||
|
||||
/** @type {Record<string, Record<string, (thing: KnownStatsError, context: StatsFactoryContext, options: NormalizedStatsOptions) => boolean | undefined>>} */
|
||||
/** @type {Record<string, Record<string, (thing: KnownStatsError, context: StatsFactoryContext, options: NormalizedStatsOptions, idx: number, i: number) => boolean | undefined>>} */
|
||||
const FILTER_RESULTS = {
|
||||
"compilation.warnings": {
|
||||
warningsFilter: util.deprecate(
|
||||
|
@ -1606,39 +1607,20 @@ const FILTER_RESULTS = {
|
|||
}
|
||||
};
|
||||
|
||||
/** @type {Record<string, (comparators: Function[], context: StatsFactoryContext) => void>} */
|
||||
/**
|
||||
* @type {Record<string, (comparators: Comparator<Module>[], context: StatsFactoryContext) => void>}
|
||||
*/
|
||||
const MODULES_SORTER = {
|
||||
_: (comparators, { compilation: { moduleGraph } }) => {
|
||||
comparators.push(
|
||||
compareSelect(
|
||||
/**
|
||||
* @param {Module} m module
|
||||
* @returns {number | null} depth
|
||||
*/
|
||||
m => moduleGraph.getDepth(m),
|
||||
compareNumbers
|
||||
),
|
||||
compareSelect(
|
||||
/**
|
||||
* @param {Module} m module
|
||||
* @returns {number | null} index
|
||||
*/
|
||||
m => moduleGraph.getPreOrderIndex(m),
|
||||
compareNumbers
|
||||
),
|
||||
compareSelect(
|
||||
/**
|
||||
* @param {Module} m module
|
||||
* @returns {string} identifier
|
||||
*/
|
||||
m => m.identifier(),
|
||||
compareIds
|
||||
)
|
||||
compareSelect(m => moduleGraph.getDepth(m), compareNumbers),
|
||||
compareSelect(m => moduleGraph.getPreOrderIndex(m), compareNumbers),
|
||||
compareSelect(m => m.identifier(), compareIds)
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
/** @type {Record<string, Record<string, (comparators: Function[], context: StatsFactoryContext) => void>>} */
|
||||
/** @type {Record<string, Record<string, (comparators: Comparator<any>[], context: StatsFactoryContext, options: NormalizedStatsOptions) => void>>} */
|
||||
const SORTERS = {
|
||||
"compilation.chunks": {
|
||||
_: comparators => {
|
||||
|
@ -2434,9 +2416,10 @@ const RESULT_SORTERS = {
|
|||
};
|
||||
|
||||
/**
|
||||
* @param {Record<string, Record<string, Function>>} config the config see above
|
||||
* @template T
|
||||
* @param {Record<string, Record<string, T>>} config the config see above
|
||||
* @param {NormalizedStatsOptions} options stats options
|
||||
* @param {(hookFor: string, fn: Function) => void} fn handler function called for every active line in config
|
||||
* @param {(hookFor: string, fn: T) => void} fn handler function called for every active line in config
|
||||
* @returns {void}
|
||||
*/
|
||||
const iterateConfig = (config, options, fn) => {
|
||||
|
@ -2525,13 +2508,18 @@ class DefaultStatsFactoryPlugin {
|
|||
* @param {NormalizedStatsOptions} options stats options
|
||||
*/
|
||||
(stats, options) => {
|
||||
iterateConfig(SIMPLE_EXTRACTORS, options, (hookFor, fn) => {
|
||||
stats.hooks.extract
|
||||
.for(hookFor)
|
||||
.tap("DefaultStatsFactoryPlugin", (obj, data, ctx) =>
|
||||
fn(obj, data, ctx, options, stats)
|
||||
);
|
||||
});
|
||||
iterateConfig(
|
||||
/** @type {TODO} */
|
||||
(SIMPLE_EXTRACTORS),
|
||||
options,
|
||||
(hookFor, fn) => {
|
||||
stats.hooks.extract
|
||||
.for(hookFor)
|
||||
.tap("DefaultStatsFactoryPlugin", (obj, data, ctx) =>
|
||||
fn(obj, data, ctx, options, stats)
|
||||
);
|
||||
}
|
||||
);
|
||||
iterateConfig(FILTER, options, (hookFor, fn) => {
|
||||
stats.hooks.filter
|
||||
.for(hookFor)
|
||||
|
@ -2560,13 +2548,18 @@ class DefaultStatsFactoryPlugin {
|
|||
fn(comparators, ctx, options)
|
||||
);
|
||||
});
|
||||
iterateConfig(RESULT_GROUPERS, options, (hookFor, fn) => {
|
||||
stats.hooks.groupResults
|
||||
.for(hookFor)
|
||||
.tap("DefaultStatsFactoryPlugin", (groupConfigs, ctx) =>
|
||||
fn(groupConfigs, ctx, options)
|
||||
);
|
||||
});
|
||||
iterateConfig(
|
||||
/** @type {TODO} */
|
||||
(RESULT_GROUPERS),
|
||||
options,
|
||||
(hookFor, fn) => {
|
||||
stats.hooks.groupResults
|
||||
.for(hookFor)
|
||||
.tap("DefaultStatsFactoryPlugin", (groupConfigs, ctx) =>
|
||||
fn(groupConfigs, ctx, options)
|
||||
);
|
||||
}
|
||||
);
|
||||
for (const key of Object.keys(ITEM_NAMES)) {
|
||||
const itemName = ITEM_NAMES[key];
|
||||
stats.hooks.getItemName
|
||||
|
|
|
@ -34,12 +34,12 @@ class SortableSet extends Set {
|
|||
this._lastActiveSortFn = NONE;
|
||||
/**
|
||||
* @private
|
||||
* @type {Map<Function, any> | undefined}
|
||||
* @type {Map<(set: SortableSet<T>) => TODO, TODO> | undefined}
|
||||
*/
|
||||
this._cache = undefined;
|
||||
/**
|
||||
* @private
|
||||
* @type {Map<Function, any> | undefined}
|
||||
* @type {Map<(set: SortableSet<T>) => TODO, TODO> | undefined}
|
||||
*/
|
||||
this._cacheOrderIndependent = undefined;
|
||||
}
|
||||
|
|
|
@ -69,11 +69,12 @@ const compileSearch = (funcName, predicate, reversed, extraArgs, earlyOut) => {
|
|||
* A(): Performs a binary search on an array using the comparison operator specified.
|
||||
* P(): Performs a binary search on an array using a _custom comparison function_
|
||||
* `c(x,y)` **and** comparison operator specified by `predicate`.
|
||||
* @template T
|
||||
* @param {BinarySearchPredicate} predicate The predicate / comparison operator to be used in the binary search.
|
||||
* @param {boolean} reversed Whether the search should be reversed.
|
||||
* @param {SearchPredicateSuffix} suffix The suffix to be used in the function name.
|
||||
* @param {boolean=} earlyOut Whether the search should return as soon as a match is found.
|
||||
* @returns {Function} The compiled binary search function.
|
||||
* @returns {(items: T[], start: number, compareFn?: number | ((item: T, needle: number) => number), l?: number, h?: number) => number} The compiled binary search function.
|
||||
*/
|
||||
const compileBoundsSearch = (predicate, reversed, suffix, earlyOut) => {
|
||||
const arg1 = compileSearch("A", `x${predicate}y`, reversed, ["y"], earlyOut);
|
||||
|
|
|
@ -199,7 +199,7 @@ const parseObject = obj => {
|
|||
/**
|
||||
* @template {object} T
|
||||
* @param {Map<string, ObjectParsedPropertyEntry>} info static properties (key is property name)
|
||||
* @param {{ byProperty: string, fn: Function } | undefined} dynamicInfo dynamic part
|
||||
* @param {{ byProperty: string, fn: (...args: EXPECTED_ANY[]) => T } | undefined} dynamicInfo dynamic part
|
||||
* @returns {T} the object
|
||||
*/
|
||||
const serializeObject = (info, dynamicInfo) => {
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
|
||||
const util = require("util");
|
||||
|
||||
/** @type {Map<string, Function>} */
|
||||
/** @type {Map<string, () => void>} */
|
||||
const deprecationCache = new Map();
|
||||
|
||||
/**
|
||||
|
@ -23,7 +23,7 @@ const deprecationCache = new Map();
|
|||
/**
|
||||
* @param {string} message deprecation message
|
||||
* @param {string} code deprecation code
|
||||
* @returns {Function} function to trigger deprecation
|
||||
* @returns {() => void} function to trigger deprecation
|
||||
*/
|
||||
const createDeprecation = (message, code) => {
|
||||
const cached = deprecationCache.get(message);
|
||||
|
|
|
@ -30,6 +30,8 @@ const WebAssemblyExportImportedDependency = require("../dependencies/WebAssembly
|
|||
/** @typedef {import("@webassemblyjs/ast").ModuleImport} ModuleImport */
|
||||
/** @typedef {import("@webassemblyjs/ast").ModuleExport} ModuleExport */
|
||||
/** @typedef {import("@webassemblyjs/ast").Global} Global */
|
||||
/** @typedef {import("@webassemblyjs/ast").AST} AST */
|
||||
/** @typedef {import("@webassemblyjs/ast").GlobalType} GlobalType */
|
||||
/**
|
||||
* @template T
|
||||
* @typedef {import("@webassemblyjs/ast").NodePath<T>} NodePath
|
||||
|
@ -42,7 +44,7 @@ const WebAssemblyExportImportedDependency = require("../dependencies/WebAssembly
|
|||
/**
|
||||
* @template T
|
||||
* @param {((prev: ArrayBuffer) => ArrayBuffer)[]} fns transforms
|
||||
* @returns {Function} composed transform
|
||||
* @returns {ArrayBufferTransform} composed transform
|
||||
*/
|
||||
const compose = (...fns) =>
|
||||
fns.reduce(
|
||||
|
@ -53,7 +55,7 @@ const compose = (...fns) =>
|
|||
/**
|
||||
* Removes the start instruction
|
||||
* @param {object} state state
|
||||
* @param {object} state.ast Module's ast
|
||||
* @param {AST} state.ast Module's ast
|
||||
* @returns {ArrayBufferTransform} transform
|
||||
*/
|
||||
const removeStartFunc = state => bin =>
|
||||
|
@ -65,7 +67,7 @@ const removeStartFunc = state => bin =>
|
|||
|
||||
/**
|
||||
* Get imported globals
|
||||
* @param {object} ast Module's AST
|
||||
* @param {AST} ast Module's AST
|
||||
* @returns {t.ModuleImport[]} - nodes
|
||||
*/
|
||||
const getImportedGlobals = ast => {
|
||||
|
@ -85,7 +87,7 @@ const getImportedGlobals = ast => {
|
|||
|
||||
/**
|
||||
* Get the count for imported func
|
||||
* @param {object} ast Module's AST
|
||||
* @param {AST} ast Module's AST
|
||||
* @returns {number} - count
|
||||
*/
|
||||
const getCountImportedFunc = ast => {
|
||||
|
@ -104,7 +106,7 @@ const getCountImportedFunc = ast => {
|
|||
|
||||
/**
|
||||
* Get next type index
|
||||
* @param {object} ast Module's AST
|
||||
* @param {AST} ast Module's AST
|
||||
* @returns {t.Index} - index
|
||||
*/
|
||||
const getNextTypeIndex = ast => {
|
||||
|
@ -122,7 +124,7 @@ const getNextTypeIndex = ast => {
|
|||
* The Func section metadata provide information for implemented funcs
|
||||
* in order to have the correct index we shift the index by number of external
|
||||
* functions.
|
||||
* @param {object} ast Module's AST
|
||||
* @param {AST} ast Module's AST
|
||||
* @param {number} countImportedFunc number of imported funcs
|
||||
* @returns {t.Index} - index
|
||||
*/
|
||||
|
@ -168,7 +170,7 @@ const createDefaultInitForGlobal = globalType => {
|
|||
*
|
||||
* Note that globals will become mutable.
|
||||
* @param {object} state transformation state
|
||||
* @param {object} state.ast Module's ast
|
||||
* @param {AST} state.ast Module's ast
|
||||
* @param {t.Instruction[]} state.additionalInitCode list of addition instructions for the init function
|
||||
* @returns {ArrayBufferTransform} transform
|
||||
*/
|
||||
|
@ -180,7 +182,9 @@ const rewriteImportedGlobals = state => bin => {
|
|||
bin = editWithAST(state.ast, bin, {
|
||||
ModuleImport(path) {
|
||||
if (t.isGlobalType(path.node.descr)) {
|
||||
const globalType = /** @type {TODO} */ (path.node.descr);
|
||||
const globalType =
|
||||
/** @type {GlobalType} */
|
||||
(path.node.descr);
|
||||
|
||||
globalType.mutability = "var";
|
||||
|
||||
|
@ -238,7 +242,7 @@ const rewriteImportedGlobals = state => bin => {
|
|||
/**
|
||||
* Rewrite the export names
|
||||
* @param {object} state state
|
||||
* @param {object} state.ast Module's ast
|
||||
* @param {AST} state.ast Module's ast
|
||||
* @param {Module} state.module Module
|
||||
* @param {ModuleGraph} state.moduleGraph module graph
|
||||
* @param {Set<string>} state.externalExports Module
|
||||
|
@ -272,7 +276,7 @@ const rewriteExportNames =
|
|||
/**
|
||||
* Mangle import names and modules
|
||||
* @param {object} state state
|
||||
* @param {object} state.ast Module's ast
|
||||
* @param {AST} state.ast Module's ast
|
||||
* @param {Map<string, UsedWasmDependency>} state.usedDependencyMap mappings to mangle names
|
||||
* @returns {ArrayBufferTransform} transform
|
||||
*/
|
||||
|
@ -300,7 +304,7 @@ const rewriteImports =
|
|||
*
|
||||
* The init function fills the globals given input arguments.
|
||||
* @param {object} state transformation state
|
||||
* @param {object} state.ast Module's ast
|
||||
* @param {AST} state.ast Module's ast
|
||||
* @param {t.Identifier} state.initFuncId identifier of the init function
|
||||
* @param {t.Index} state.startAtFuncOffset index of the start function
|
||||
* @param {t.ModuleImport[]} state.importedGlobals list of imported globals
|
||||
|
@ -442,7 +446,9 @@ class WebAssemblyGenerator extends Generator {
|
|||
* @returns {Source | null} generated code
|
||||
*/
|
||||
generate(module, { moduleGraph, runtime }) {
|
||||
const bin = /** @type {Source} */ (module.originalSource()).source();
|
||||
const bin =
|
||||
/** @type {Buffer} */
|
||||
(/** @type {Source} */ (module.originalSource()).source());
|
||||
|
||||
const initFuncId = t.identifier("");
|
||||
|
||||
|
|
|
@ -13,6 +13,8 @@ const StaticExportsDependency = require("../dependencies/StaticExportsDependency
|
|||
const WebAssemblyExportImportedDependency = require("../dependencies/WebAssemblyExportImportedDependency");
|
||||
const WebAssemblyImportDependency = require("../dependencies/WebAssemblyImportDependency");
|
||||
|
||||
/** @typedef {import("@webassemblyjs/ast").ModuleImport} ModuleImport */
|
||||
/** @typedef {import("@webassemblyjs/ast").NumberLiteral} NumberLiteral */
|
||||
/** @typedef {import("../Module")} Module */
|
||||
/** @typedef {import("../Module").BuildInfo} BuildInfo */
|
||||
/** @typedef {import("../Module").BuildMeta} BuildMeta */
|
||||
|
@ -101,8 +103,9 @@ class WebAssemblyParser extends Parser {
|
|||
/** @type {Record<string, string> | undefined} */
|
||||
let jsIncompatibleExports = (buildMeta.jsIncompatibleExports = undefined);
|
||||
|
||||
/** @type {TODO[]} */
|
||||
/** @type {(ModuleImport | null)[]} */
|
||||
const importedGlobals = [];
|
||||
|
||||
t.traverse(module, {
|
||||
ModuleExport({ node }) {
|
||||
const descriptor = node.descr;
|
||||
|
@ -130,7 +133,7 @@ class WebAssemblyParser extends Parser {
|
|||
|
||||
if (node.descr && node.descr.exportType === "Global") {
|
||||
const refNode =
|
||||
importedGlobals[/** @type {TODO} */ (node.descr.id.value)];
|
||||
importedGlobals[/** @type {NumberLiteral} */ (node.descr.id).value];
|
||||
if (refNode) {
|
||||
const dep = new WebAssemblyExportImportedDependency(
|
||||
node.name,
|
||||
|
@ -170,7 +173,8 @@ class WebAssemblyParser extends Parser {
|
|||
onlyDirectImport = "Table";
|
||||
} else if (t.isFuncImportDescr(node.descr) === true) {
|
||||
const incompatibleType = getJsIncompatibleType(
|
||||
/** @type {t.Signature} */ (node.descr.signature)
|
||||
/** @type {t.Signature} */
|
||||
(node.descr.signature)
|
||||
);
|
||||
if (incompatibleType) {
|
||||
onlyDirectImport = `Non-JS-compatible Func Signature (${incompatibleType})`;
|
||||
|
|
|
@ -604,7 +604,7 @@
|
|||
},
|
||||
{
|
||||
"instanceof": "Function",
|
||||
"tsType": "Function"
|
||||
"tsType": "((context: TODO) => string)"
|
||||
}
|
||||
]
|
||||
},
|
||||
|
@ -616,7 +616,7 @@
|
|||
},
|
||||
{
|
||||
"instanceof": "Function",
|
||||
"tsType": "Function"
|
||||
"tsType": "((context: TODO) => string)"
|
||||
}
|
||||
]
|
||||
},
|
||||
|
@ -2886,7 +2886,7 @@
|
|||
},
|
||||
{
|
||||
"instanceof": "Function",
|
||||
"tsType": "Function"
|
||||
"tsType": "((layer: string | null) => boolean)"
|
||||
}
|
||||
]
|
||||
},
|
||||
|
@ -2964,7 +2964,7 @@
|
|||
},
|
||||
{
|
||||
"instanceof": "Function",
|
||||
"tsType": "Function"
|
||||
"tsType": "((module: import('../lib/Module'), chunks: import('../lib/Chunk')[], key: string) => string | undefined)"
|
||||
}
|
||||
]
|
||||
},
|
||||
|
@ -2988,7 +2988,7 @@
|
|||
},
|
||||
{
|
||||
"instanceof": "Function",
|
||||
"tsType": "Function"
|
||||
"tsType": "((module: import('../lib/Module'), context: import('../lib/optimize/SplitChunksPlugin').CacheGroupsContext) => boolean)"
|
||||
}
|
||||
]
|
||||
},
|
||||
|
@ -3004,7 +3004,7 @@
|
|||
},
|
||||
{
|
||||
"instanceof": "Function",
|
||||
"tsType": "Function"
|
||||
"tsType": "((type: string) => boolean)"
|
||||
}
|
||||
]
|
||||
},
|
||||
|
@ -3272,7 +3272,7 @@
|
|||
},
|
||||
{
|
||||
"instanceof": "Function",
|
||||
"tsType": "Function"
|
||||
"tsType": "((module: import('../lib/Module'), chunks: import('../lib/Chunk')[], key: string) => string | undefined)"
|
||||
}
|
||||
]
|
||||
},
|
||||
|
|
|
@ -80,7 +80,7 @@
|
|||
{
|
||||
"description": "Custom function generating the identifier.",
|
||||
"instanceof": "Function",
|
||||
"tsType": "Function"
|
||||
"tsType": "((context: any) => string)"
|
||||
}
|
||||
]
|
||||
},
|
||||
|
@ -124,7 +124,7 @@
|
|||
{
|
||||
"description": "Custom function generating the identifier.",
|
||||
"instanceof": "Function",
|
||||
"tsType": "Function"
|
||||
"tsType": "((context: any) => string)"
|
||||
}
|
||||
]
|
||||
},
|
||||
|
|
|
@ -970,9 +970,9 @@ declare interface CacheGroupSource {
|
|||
key?: string;
|
||||
priority?: number;
|
||||
getName?: (
|
||||
module?: Module,
|
||||
chunks?: Chunk[],
|
||||
key?: string
|
||||
module: Module,
|
||||
chunks: Chunk[],
|
||||
key: string
|
||||
) => undefined | string;
|
||||
chunksFilter?: (chunk: Chunk) => undefined | boolean;
|
||||
enforce?: boolean;
|
||||
|
@ -3653,7 +3653,7 @@ declare interface DeterministicModuleIdsPluginOptions {
|
|||
*/
|
||||
failOnConflict?: boolean;
|
||||
}
|
||||
type DevtoolModuleFilenameTemplate = string | Function;
|
||||
type DevtoolModuleFilenameTemplate = string | ((context?: any) => string);
|
||||
declare interface Dirent {
|
||||
isFile: () => boolean;
|
||||
isDirectory: () => boolean;
|
||||
|
@ -4296,12 +4296,12 @@ declare interface EvalDevToolModulePluginOptions {
|
|||
/**
|
||||
* module filename template
|
||||
*/
|
||||
moduleFilenameTemplate?: string | Function;
|
||||
moduleFilenameTemplate?: string | ((context?: any) => string);
|
||||
}
|
||||
declare class EvalSourceMapDevToolPlugin {
|
||||
constructor(inputOptions: string | SourceMapDevToolPluginOptions);
|
||||
sourceMapComment: string;
|
||||
moduleFilenameTemplate: string | Function;
|
||||
moduleFilenameTemplate: string | ((context?: any) => string);
|
||||
namespace: string;
|
||||
options: SourceMapDevToolPluginOptions;
|
||||
|
||||
|
@ -10393,7 +10393,7 @@ declare interface OptimizationSplitChunksCacheGroup {
|
|||
/**
|
||||
* Assign modules to a cache group by module layer.
|
||||
*/
|
||||
layer?: string | Function | RegExp;
|
||||
layer?: string | RegExp | ((layer: null | string) => boolean);
|
||||
|
||||
/**
|
||||
* Maximum number of requests which are accepted for on-demand loading.
|
||||
|
@ -10443,7 +10443,10 @@ declare interface OptimizationSplitChunksCacheGroup {
|
|||
/**
|
||||
* Give chunks for this cache group a name (chunks with equal name are merged).
|
||||
*/
|
||||
name?: string | false | Function;
|
||||
name?:
|
||||
| string
|
||||
| false
|
||||
| ((module: Module, chunks: Chunk[], key: string) => undefined | string);
|
||||
|
||||
/**
|
||||
* Priority of this cache group.
|
||||
|
@ -10458,12 +10461,15 @@ declare interface OptimizationSplitChunksCacheGroup {
|
|||
/**
|
||||
* Assign modules to a cache group by module name.
|
||||
*/
|
||||
test?: string | Function | RegExp;
|
||||
test?:
|
||||
| string
|
||||
| RegExp
|
||||
| ((module: Module, context: CacheGroupsContext) => boolean);
|
||||
|
||||
/**
|
||||
* Assign modules to a cache group by module type.
|
||||
*/
|
||||
type?: string | Function | RegExp;
|
||||
type?: string | RegExp | ((type: string) => boolean);
|
||||
|
||||
/**
|
||||
* Compare used exports when checking common modules. Modules will only be put in the same chunk when exports are equal.
|
||||
|
@ -10599,7 +10605,10 @@ declare interface OptimizationSplitChunksOptions {
|
|||
/**
|
||||
* Give chunks created a name (chunks with equal name are merged).
|
||||
*/
|
||||
name?: string | false | Function;
|
||||
name?:
|
||||
| string
|
||||
| false
|
||||
| ((module: Module, chunks: Chunk[], key: string) => undefined | string);
|
||||
|
||||
/**
|
||||
* Compare used exports when checking common modules. Modules will only be put in the same chunk when exports are equal.
|
||||
|
@ -10748,12 +10757,12 @@ declare interface Output {
|
|||
/**
|
||||
* Similar to `output.devtoolModuleFilenameTemplate`, but used in the case of duplicate module identifiers.
|
||||
*/
|
||||
devtoolFallbackModuleFilenameTemplate?: string | Function;
|
||||
devtoolFallbackModuleFilenameTemplate?: string | ((context?: any) => string);
|
||||
|
||||
/**
|
||||
* Filename template string of function for the sources array in a generated SourceMap.
|
||||
*/
|
||||
devtoolModuleFilenameTemplate?: string | Function;
|
||||
devtoolModuleFilenameTemplate?: string | ((context?: any) => string);
|
||||
|
||||
/**
|
||||
* Module namespace to use when interpolating filename template string for the sources array in a generated SourceMap. Defaults to `output.library` if not set. It's useful for avoiding runtime collisions in sourcemaps from multiple webpack projects built as libraries.
|
||||
|
@ -11042,12 +11051,12 @@ declare interface OutputNormalized {
|
|||
/**
|
||||
* Similar to `output.devtoolModuleFilenameTemplate`, but used in the case of duplicate module identifiers.
|
||||
*/
|
||||
devtoolFallbackModuleFilenameTemplate?: string | Function;
|
||||
devtoolFallbackModuleFilenameTemplate?: string | ((context?: any) => string);
|
||||
|
||||
/**
|
||||
* Filename template string of function for the sources array in a generated SourceMap.
|
||||
*/
|
||||
devtoolModuleFilenameTemplate?: string | Function;
|
||||
devtoolModuleFilenameTemplate?: string | ((context?: any) => string);
|
||||
|
||||
/**
|
||||
* Module namespace to use when interpolating filename template string for the sources array in a generated SourceMap. Defaults to `output.library` if not set. It's useful for avoiding runtime collisions in sourcemaps from multiple webpack projects built as libraries.
|
||||
|
@ -11487,7 +11496,7 @@ type ProblemType =
|
|||
| "multiple-values-unexpected"
|
||||
| "invalid-value";
|
||||
declare interface ProcessAssetsAdditionalOptions {
|
||||
additionalAssets?: true | Function;
|
||||
additionalAssets?: any;
|
||||
}
|
||||
declare class Profiler {
|
||||
constructor(inspector?: any);
|
||||
|
@ -14354,8 +14363,8 @@ declare class SourceMapDevToolPlugin {
|
|||
| string
|
||||
| false
|
||||
| ((pathData: PathData, assetInfo?: AssetInfo) => string);
|
||||
moduleFilenameTemplate: string | Function;
|
||||
fallbackModuleFilenameTemplate: string | Function;
|
||||
moduleFilenameTemplate: string | ((context?: any) => string);
|
||||
fallbackModuleFilenameTemplate: string | ((context?: any) => string);
|
||||
namespace: string;
|
||||
options: SourceMapDevToolPluginOptions;
|
||||
|
||||
|
@ -14392,7 +14401,7 @@ declare interface SourceMapDevToolPluginOptions {
|
|||
/**
|
||||
* Generator string or function to create identifiers of modules for the 'sources' array in the SourceMap used only if 'moduleFilenameTemplate' would result in a conflict.
|
||||
*/
|
||||
fallbackModuleFilenameTemplate?: string | Function;
|
||||
fallbackModuleFilenameTemplate?: string | ((context?: any) => string);
|
||||
|
||||
/**
|
||||
* Path prefix to which the [file] placeholder is relative to.
|
||||
|
@ -14417,7 +14426,7 @@ declare interface SourceMapDevToolPluginOptions {
|
|||
/**
|
||||
* Generator string or function to create identifiers of modules for the 'sources' array in the SourceMap.
|
||||
*/
|
||||
moduleFilenameTemplate?: string | Function;
|
||||
moduleFilenameTemplate?: string | ((context?: any) => string);
|
||||
|
||||
/**
|
||||
* Namespace prefix to allow multiple webpack roots in the devtools.
|
||||
|
@ -14485,11 +14494,7 @@ declare interface SplitChunksOptions {
|
|||
module: Module,
|
||||
context: CacheGroupsContext
|
||||
) => null | CacheGroupSource[];
|
||||
getName: (
|
||||
module?: Module,
|
||||
chunks?: Chunk[],
|
||||
key?: string
|
||||
) => undefined | string;
|
||||
getName: (module: Module, chunks: Chunk[], key: string) => undefined | string;
|
||||
usedExports: boolean;
|
||||
fallbackCacheGroup: FallbackCacheGroup;
|
||||
}
|
||||
|
@ -15285,7 +15290,7 @@ declare interface TargetItemWithoutConnection {
|
|||
}
|
||||
declare class Template {
|
||||
constructor();
|
||||
static getFunctionContent(fn: Function): string;
|
||||
static getFunctionContent<T extends Function>(fn: T): string;
|
||||
static toIdentifier(str: string): string;
|
||||
static toComment(str: string): string;
|
||||
static toNormalComment(str: string): string;
|
||||
|
@ -16066,19 +16071,10 @@ declare namespace exports {
|
|||
export let REGEXP_NAMESPACE: RegExp;
|
||||
export let createFilename: (
|
||||
module: string | Module,
|
||||
options: any,
|
||||
options: { namespace?: string; moduleFilenameTemplate?: any },
|
||||
__2: {
|
||||
/**
|
||||
* requestShortener
|
||||
*/
|
||||
requestShortener: RequestShortener;
|
||||
/**
|
||||
* chunk graph
|
||||
*/
|
||||
chunkGraph: ChunkGraph;
|
||||
/**
|
||||
* the hash function to use
|
||||
*/
|
||||
hashFunction?: string | typeof Hash;
|
||||
}
|
||||
) => string;
|
||||
|
|
Loading…
Reference in New Issue