Socket
Socket
Sign inDemoInstall

webpack

Package Overview
Dependencies
76
Maintainers
4
Versions
832
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 5.90.0 to 5.90.1

28

lib/APIPlugin.js

@@ -27,6 +27,8 @@ /*

/** @typedef {import("./Compiler")} Compiler */
/** @typedef {import("./Dependency").DependencyLocation} DependencyLocation */
/** @typedef {import("./javascript/JavascriptParser")} JavascriptParser */
/** @typedef {import("./javascript/JavascriptParser").Range} Range */
/**
* @param {boolean} module true if ES module
* @param {boolean | undefined} module true if ES module
* @param {string} importMetaName `import.meta` name

@@ -154,3 +156,5 @@ * @returns {Record<string, {expr: string, req: string[] | null, type?: string, assign: boolean}>} replacements

(compilation, { normalModuleFactory }) => {
const { importMetaName } = compilation.outputOptions;
const importMetaName = /** @type {string} */ (
compilation.outputOptions.importMetaName
);
const REPLACEMENTS = getReplacements(

@@ -171,3 +175,3 @@ this.options.module,

chunk,
new ChunkNameRuntimeModule(chunk.name)
new ChunkNameRuntimeModule(/** @type {string} */ (chunk.name))
);

@@ -224,3 +228,3 @@ return true;

const err = new WebpackError(`${key} must not be assigned`);
err.loc = expr.loc;
err.loc = /** @type {DependencyLocation} */ (expr.loc);
throw err;

@@ -241,5 +245,5 @@ });

JSON.stringify(parser.state.module.layer),
expr.range
/** @type {Range} */ (expr.range)
);
dep.loc = expr.loc;
dep.loc = /** @type {DependencyLocation} */ (expr.loc);
parser.state.module.addPresentationalDependency(dep);

@@ -256,3 +260,3 @@ return true;

)
).setRange(expr.range)
).setRange(/** @type {Range} */ (expr.range))
);

@@ -266,3 +270,3 @@ parser.hooks.evaluateTypeof

)
.setRange(expr.range)
.setRange(/** @type {Range} */ (expr.range))
);

@@ -277,6 +281,6 @@

parser.state.module.moduleArgument + ".id",
expr.range,
/** @type {Range} */ (expr.range),
[RuntimeGlobals.moduleId]
);
dep.loc = expr.loc;
dep.loc = /** @type {DependencyLocation} */ (expr.loc);
parser.state.module.addPresentationalDependency(dep);

@@ -293,6 +297,6 @@ return true;

parser.state.module.moduleArgument,
expr.range,
/** @type {Range} */ (expr.range),
[RuntimeGlobals.module]
);
dep.loc = expr.loc;
dep.loc = /** @type {DependencyLocation} */ (expr.loc);
parser.state.module.addPresentationalDependency(dep);

@@ -299,0 +303,0 @@ return true;

@@ -45,4 +45,4 @@ /*

/**
* @param {Context} context context
* @returns {string|Source} the source code that will be included as initialization code
* @param {GenerateContext} context context
* @returns {string | Source} the source code that will be included as initialization code
*/

@@ -49,0 +49,0 @@ getContent({ runtimeRequirements }) {

@@ -269,2 +269,5 @@ /*

/** @type {Map<ChunkGroupInfo, DependenciesBlock>} */
const blockByChunkGroups = new Map();
/** @type {Map<string, ChunkGroupInfo>} */

@@ -276,2 +279,5 @@ const namedChunkGroups = new Map();

/** @type {Set<ChunkGroupInfo>} */
const outdatedOrderIndexChunkGroups = new Set();
const ADD_AND_ENTER_ENTRY_MODULE = 0;

@@ -529,2 +535,3 @@ const ADD_AND_ENTER_MODULE = 1;

blockChunkGroups.set(b, /** @type {ChunkGroupInfo} */ (cgi));
blockByChunkGroups.set(cgi, b);
} else if (entryOptions) {

@@ -1214,2 +1221,3 @@ entrypoint = /** @type {Entrypoint} */ (cgi.chunkGroup);

}
outdatedOrderIndexChunkGroups.add(info);
}

@@ -1261,2 +1269,47 @@ outdatedChunkGroupInfo.clear();

for (const info of outdatedOrderIndexChunkGroups) {
const { chunkGroup, runtime } = info;
const block = blockByChunkGroups.get(info);
if (!block) {
continue;
}
let preOrderIndex = 0;
let postOrderIndex = 0;
const process = (current, visited = new Set()) => {
if (visited.has(current)) {
return;
}
visited.add(current);
const blockModules = getBlockModules(current, runtime);
if (blockModules === undefined) {
return;
}
for (let i = 0; i < blockModules.length; i += 2) {
const refModule = /** @type {Module} */ (blockModules[i]);
const activeState = /** @type {ConnectionState} */ (
blockModules[i + 1]
);
if (activeState === false) {
continue;
}
if (refModule) {
chunkGroup.setModulePreOrderIndex(refModule, preOrderIndex++);
process(refModule, visited);
chunkGroup.setModulePostOrderIndex(refModule, postOrderIndex++);
}
}
};
process(block);
}
outdatedOrderIndexChunkGroups.clear();
logger.log(

@@ -1263,0 +1316,0 @@ `${statProcessedQueueItems} queue items processed (${statProcessedBlocks} blocks)`

@@ -65,4 +65,4 @@ /*

/**
* @param {Context} context context
* @returns {string|Source} the source code that will be included as initialization code
* @param {GenerateContext} context context
* @returns {string | Source} the source code that will be included as initialization code
*/

@@ -83,3 +83,3 @@ getContent(context) {

/**
* @param {Context} context context
* @param {GenerateContext} context context
* @returns {string|Source=} the source code that will be included at the end of the module

@@ -86,0 +86,0 @@ */

@@ -93,3 +93,5 @@ /*

? [Infinity, Infinity]
: parsedVersion.split(".");
: parsedVersion.includes("-")
? parsedVersion.split("-")[0].split(".")
: parsedVersion.split(".");
if (typeof requiredVersion === "number") {

@@ -122,4 +124,4 @@ return +parsedMajor >= requiredVersion;

and_qq: [10, 4],
// baidu: Not supported
// and_uc: Not supported
baidu: [13, 18],
and_uc: [15, 5],
kaios: [3, 0],

@@ -149,3 +151,3 @@ node: [12, 17]

// Supported correctly in strict mode, otherwise supported without block scope
// baidu: Not supported
baidu: [13, 18],
and_uc: [12, 12],

@@ -228,5 +230,5 @@ kaios: [2, 5],

android: 67,
// and_qq: Not supported
// baidu: Not supported
// and_uc: Not supported
and_qq: [13, 1],
baidu: [13, 18],
and_uc: [15, 5],
kaios: [3, 0],

@@ -251,4 +253,4 @@ node: [10, 4]

and_qq: [10, 4],
// baidu: Not supported
// and_uc: Not supported
baidu: [13, 18],
and_uc: [15, 5],
kaios: [3, 0],

@@ -327,10 +329,10 @@ node: [12, 17]

op_mob: 42,
safari: [10, 1],
ios_saf: [10, 3],
samsung: 6,
safari: 11,
ios_saf: 11,
samsung: [6, 2],
android: 55,
// and_qq: Unknown support
// baidu: Unknown support
// and_uc: Unknown support
// kaios: Unknown support
and_qq: [13, 1],
baidu: [13, 18],
and_uc: [15, 5],
kaios: 3,
node: [7, 6]

@@ -337,0 +339,0 @@ }),

@@ -475,2 +475,3 @@ /*

});
F(snapshot, "unmanagedPaths", () => []);
A(snapshot, "immutablePaths", () => {

@@ -477,0 +478,0 @@ if (process.versions.pnp === "1") {

@@ -26,5 +26,7 @@ /*

/** @typedef {import("./Compiler")} Compiler */
/** @typedef {import("./Module").BuildInfo} BuildInfo */
/** @typedef {import("./NormalModule")} NormalModule */
/** @typedef {import("./RuntimeTemplate")} RuntimeTemplate */
/** @typedef {import("./javascript/JavascriptParser")} JavascriptParser */
/** @typedef {import("./javascript/JavascriptParser").Range} Range */
/** @typedef {import("./logging/Logger").Logger} Logger */

@@ -70,3 +72,3 @@

exec(parser, valueCacheVersions, key) {
const buildInfo = parser.state.module.buildInfo;
const buildInfo = /** @type {BuildInfo} */ (parser.state.module.buildInfo);
if (this.options === true) {

@@ -141,15 +143,17 @@ buildInfo.cacheable = false;

if (arr) {
code = `[${obj
.map(code =>
toCode(
code,
parser,
valueCacheVersions,
key,
runtimeTemplate,
logger,
null
code = `[${
/** @type {any[]} */ (obj)
.map(code =>
toCode(
code,
parser,
valueCacheVersions,
key,
runtimeTemplate,
logger,
null
)
)
)
.join(",")}]`;
.join(",")
}]`;
} else {

@@ -163,3 +167,3 @@ let keys = Object.keys(obj);

.map(key => {
const code = obj[key];
const code = /** @type {{[k: string]: any}} */ (obj)[key];
return (

@@ -270,2 +274,6 @@ JSON.stringify(key) +

/**
* @param {CodeValue} code code
* @returns {string | undefined} result
*/
const toCacheVersion = code => {

@@ -293,3 +301,3 @@ if (code === null) {

key,
value: toCacheVersion(code[key])
value: toCacheVersion(/** @type {Record<string, any>} */ (code)[key])
}));

@@ -362,3 +370,5 @@ if (items.some(({ value }) => value === undefined)) return undefined;

parser.hooks.program.tap(PLUGIN_NAME, () => {
const { buildInfo } = parser.state.module;
const buildInfo = /** @type {BuildInfo} */ (
parser.state.module.buildInfo
);
if (!buildInfo.valueDependencies)

@@ -369,4 +379,9 @@ buildInfo.valueDependencies = new Map();

/**
* @param {string} key key
*/
const addValueDependency = key => {
const { buildInfo } = parser.state.module;
const buildInfo = /** @type {BuildInfo} */ (
parser.state.module.buildInfo
);
buildInfo.valueDependencies.set(

@@ -387,3 +402,3 @@ VALUE_DEP_PREFIX + key,

* Walk definitions
* @param {Object} definitions Definitions map
* @param {Record<string, CodeValue>} definitions Definitions map
* @param {string} prefix Prefix string

@@ -401,3 +416,6 @@ * @returns {void}

) {
walkDefinitions(code, prefix + key + ".");
walkDefinitions(
/** @type {Record<string, CodeValue>} */ (code),
prefix + key + "."
);
applyObjectDefine(prefix + key, code);

@@ -471,3 +489,3 @@ return;

recurse = false;
res.setRange(expr.range);
res.setRange(/** @type {Range} */ (expr.range));
return res;

@@ -484,3 +502,3 @@ });

logger,
!parser.isAsiPosition(expr.range[0]),
!parser.isAsiPosition(/** @type {Range} */ (expr.range)[0]),
parser.destructuringAssignmentPropertiesFor(expr)

@@ -532,3 +550,3 @@ );

recurseTypeof = false;
res.setRange(expr.range);
res.setRange(/** @type {Range} */ (expr.range));
return res;

@@ -575,3 +593,3 @@ });

.setSideEffects(false)
.setRange(expr.range);
.setRange(/** @type {Range} */ (expr.range));
});

@@ -593,3 +611,3 @@ parser.hooks.evaluateTypeof

logger,
!parser.isAsiPosition(expr.range[0]),
!parser.isAsiPosition(/** @type {Range} */ (expr.range)[0]),
parser.destructuringAssignmentPropertiesFor(expr)

@@ -640,3 +658,3 @@ );

* Walk definitions
* @param {Object} definitions Definitions map
* @param {Record<string, CodeValue>} definitions Definitions map
* @param {string} prefix Prefix string

@@ -668,3 +686,6 @@ * @returns {void}

) {
walkDefinitionsForValues(code, prefix + key + ".");
walkDefinitionsForValues(
/** @type {Record<string, CodeValue>} */ (code),
prefix + key + "."
);
}

@@ -671,0 +692,0 @@ });

@@ -111,6 +111,6 @@ /*

* @param {Range} range range
* @param {Range} arrayRange array range
* @param {Range} functionRange function range
* @param {Range} objectRange object range
* @param {boolean} namedModule true, when define is called with a name
* @param {Range | null} arrayRange array range
* @param {Range | null} functionRange function range
* @param {Range | null} objectRange object range
* @param {boolean | null} namedModule true, when define is called with a name
*/

@@ -117,0 +117,0 @@ constructor(range, arrayRange, functionRange, objectRange, namedModule) {

@@ -19,7 +19,16 @@ /*

/** @typedef {import("estree").ArrowFunctionExpression} ArrowFunctionExpression */
/** @typedef {import("estree").CallExpression} CallExpression */
/** @typedef {import("estree").Expression} Expression */
/** @typedef {import("estree").FunctionExpression} FunctionExpression */
/** @typedef {import("estree").Literal} Literal */
/** @typedef {import("estree").SpreadElement} SpreadElement */
/** @typedef {import("../../declarations/WebpackOptions").JavascriptParserOptions} JavascriptParserOptions */
/** @typedef {import("../Dependency").DependencyLocation} DependencyLocation */
/** @typedef {import("../javascript/BasicEvaluatedExpression")} BasicEvaluatedExpression */
/** @typedef {import("../javascript/JavascriptParser")} JavascriptParser */
/** @typedef {import("../javascript/JavascriptParser").Range} Range */
/**
* @param {CallExpression} expr expression
* @param {Expression | SpreadElement} expr expression
* @returns {boolean} true if it's a bound function expression

@@ -37,2 +46,8 @@ */

/** @typedef {FunctionExpression | ArrowFunctionExpression} UnboundFunctionExpression */
/**
* @param {Expression | SpreadElement} expr expression
* @returns {boolean} true when unbound function expression
*/
const isUnboundFunctionExpression = expr => {

@@ -44,2 +59,6 @@ if (expr.type === "FunctionExpression") return true;

/**
* @param {Expression | SpreadElement} expr expression
* @returns {boolean} true when callable
*/
const isCallable = expr => {

@@ -52,2 +71,5 @@ if (isUnboundFunctionExpression(expr)) return true;

class AMDDefineDependencyParserPlugin {
/**
* @param {JavascriptParserOptions} options parserOptions
*/
constructor(options) {

@@ -70,8 +92,19 @@ this.options = options;

/**
* @param {JavascriptParser} parser the parser
* @param {CallExpression} expr call expression
* @param {BasicEvaluatedExpression} param param
* @param {Record<number, string>} identifiers identifiers
* @param {string=} namedModule named module
* @returns {boolean | undefined} result
*/
processArray(parser, expr, param, identifiers, namedModule) {
if (param.isArray()) {
param.items.forEach((param, idx) => {
/** @type {BasicEvaluatedExpression[]} */
(param.items).forEach((param, idx) => {
if (
param.isString() &&
["require", "module", "exports"].includes(param.string)
["require", "module", "exports"].includes(
/** @type {string} */ (param.string)
)
)

@@ -86,2 +119,3 @@ identifiers[idx] = param.string;

} else if (param.isConstArray()) {
/** @type {(string | LocalModuleDependency | AMDRequireItemDependency)[]} */
const deps = [];

@@ -100,7 +134,7 @@ param.array.forEach((request, idx) => {

dep = new LocalModuleDependency(localModule, undefined, false);
dep.loc = expr.loc;
dep.loc = /** @type {DependencyLocation} */ (expr.loc);
parser.state.module.addPresentationalDependency(dep);
} else {
dep = this.newRequireItemDependency(request);
dep.loc = expr.loc;
dep.loc = /** @type {DependencyLocation} */ (expr.loc);
dep.optional = !!parser.scope.inTry;

@@ -111,4 +145,7 @@ parser.state.current.addDependency(dep);

});
const dep = this.newRequireArrayDependency(deps, param.range);
dep.loc = expr.loc;
const dep = this.newRequireArrayDependency(
deps,
/** @type {Range} */ (param.range)
);
dep.loc = /** @type {DependencyLocation} */ (expr.loc);
dep.optional = !!parser.scope.inTry;

@@ -119,5 +156,14 @@ parser.state.module.addPresentationalDependency(dep);

}
/**
* @param {JavascriptParser} parser the parser
* @param {CallExpression} expr call expression
* @param {BasicEvaluatedExpression} param param
* @param {string=} namedModule named module
* @returns {boolean} result
*/
processItem(parser, expr, param, namedModule) {
if (param.isConditional()) {
param.options.forEach(param => {
/** @type {BasicEvaluatedExpression[]} */
(param.options).forEach(param => {
const result = this.processItem(parser, expr, param);

@@ -132,15 +178,25 @@ if (result === undefined) {

if (param.string === "require") {
dep = new ConstDependency(RuntimeGlobals.require, param.range, [
RuntimeGlobals.require
]);
dep = new ConstDependency(
RuntimeGlobals.require,
/** @type {Range} */ (param.range),
[RuntimeGlobals.require]
);
} else if (param.string === "exports") {
dep = new ConstDependency("exports", param.range, [
RuntimeGlobals.exports
]);
dep = new ConstDependency(
"exports",
/** @type {Range} */ (param.range),
[RuntimeGlobals.exports]
);
} else if (param.string === "module") {
dep = new ConstDependency("module", param.range, [
RuntimeGlobals.module
]);
dep = new ConstDependency(
"module",
/** @type {Range} */ (param.range),
[RuntimeGlobals.module]
);
} else if (
(localModule = getLocalModule(parser.state, param.string, namedModule))
(localModule = getLocalModule(
parser.state,
/** @type {string} */ (param.string),
namedModule
))
) {

@@ -155,3 +211,3 @@ localModule.flagUsed();

}
dep.loc = expr.loc;
dep.loc = /** @type {DependencyLocation} */ (expr.loc);
parser.state.module.addPresentationalDependency(dep);

@@ -161,6 +217,13 @@ return true;

}
/**
* @param {JavascriptParser} parser the parser
* @param {CallExpression} expr call expression
* @param {BasicEvaluatedExpression} param param
* @returns {boolean | undefined} result
*/
processContext(parser, expr, param) {
const dep = ContextDependencyHelpers.create(
AMDRequireContextDependency,
param.range,
/** @type {Range} */ (param.range),
param,

@@ -175,3 +238,3 @@ expr,

if (!dep) return;
dep.loc = expr.loc;
dep.loc = /** @type {DependencyLocation} */ (expr.loc);
dep.optional = !!parser.scope.inTry;

@@ -182,2 +245,7 @@ parser.state.current.addDependency(dep);

/**
* @param {JavascriptParser} parser the parser
* @param {CallExpression} expr call expression
* @returns {boolean | undefined} result
*/
processCallDefine(parser, expr) {

@@ -231,3 +299,3 @@ let array, fn, obj, namedModule;

// define("…", […], f() {…})
namedModule = expr.arguments[0].value;
namedModule = /** @type {TODO} */ (expr).arguments[0].value;
array = expr.arguments[1];

@@ -254,6 +322,6 @@ if (isCallable(expr.arguments[2])) {

if (isUnboundFunctionExpression(fn)) {
fnParams = fn.params;
fnParams = /** @type {UnboundFunctionExpression} */ (fn).params;
} else if (isBoundFunctionExpression(fn)) {
fnParams = fn.callee.object.params;
fnParamsOffset = fn.arguments.length - 1;
fnParams = /** @type {TODO} */ (fn).callee.object.params;
fnParamsOffset = /** @type {TODO} */ (fn).arguments.length - 1;
if (fnParamsOffset < 0) {

@@ -266,2 +334,3 @@ fnParamsOffset = 0;

if (array) {
/** @type {Record<number, string>} */
const identifiers = {};

@@ -298,2 +367,3 @@ const param = parser.evaluateExpression(array);

}
/** @type {boolean | undefined} */
let inTry;

@@ -306,3 +376,3 @@ if (fn && isUnboundFunctionExpression(fn)) {

}
parser.scope.inTry = inTry;
parser.scope.inTry = /** @type {boolean} */ (inTry);
if (fn.body.type === "BlockStatement") {

@@ -321,3 +391,4 @@ parser.detectMode(fn.body.body);

parser.inScope(
fn.callee.object.params.filter(
/** @type {TODO} */
(fn).callee.object.params.filter(
i => !["require", "module", "exports"].includes(i.name)

@@ -341,4 +412,4 @@ ),

);
if (fn.arguments) {
parser.walkExpressions(fn.arguments);
if (/** @type {TODO} */ (fn).arguments) {
parser.walkExpressions(/** @type {TODO} */ (fn).arguments);
}

@@ -350,9 +421,9 @@ } else if (fn || obj) {

const dep = this.newDefineDependency(
expr.range,
array ? array.range : null,
fn ? fn.range : null,
obj ? obj.range : null,
/** @type {Range} */ (expr.range),
array ? /** @type {Range} */ (array.range) : null,
fn ? /** @type {Range} */ (fn.range) : null,
obj ? /** @type {Range} */ (obj.range) : null,
namedModule ? namedModule : null
);
dep.loc = expr.loc;
dep.loc = /** @type {DependencyLocation} */ (expr.loc);
if (namedModule) {

@@ -365,2 +436,10 @@ dep.localModule = addLocalModule(parser.state, namedModule);

/**
* @param {Range} range range
* @param {Range | null} arrayRange array range
* @param {Range | null} functionRange function range
* @param {Range | null} objectRange object range
* @param {boolean | null} namedModule true, when define is called with a name
* @returns {AMDDefineDependency} AMDDefineDependency
*/
newDefineDependency(

@@ -381,5 +460,17 @@ range,

}
/**
* @param {TODO[]} depsArray deps array
* @param {Range} range range
* @returns {AMDRequireArrayDependency} AMDRequireArrayDependency
*/
newRequireArrayDependency(depsArray, range) {
return new AMDRequireArrayDependency(depsArray, range);
}
/**
* @param {string} request request
* @param {Range=} range range
* @returns {AMDRequireItemDependency} AMDRequireItemDependency
*/
newRequireItemDependency(request, range) {

@@ -389,2 +480,3 @@ return new AMDRequireItemDependency(request, range);

}
module.exports = AMDDefineDependencyParserPlugin;

@@ -38,3 +38,5 @@ /*

/** @typedef {import("../Compiler")} Compiler */
/** @typedef {import("../Dependency").DependencyLocation} DependencyLocation */
/** @typedef {import("../javascript/JavascriptParser")} Parser */
/** @typedef {import("../javascript/JavascriptParser").Range} Range */

@@ -139,2 +141,7 @@ const PLUGIN_NAME = "AMDPlugin";

/**
* @param {string} optionExpr option expression
* @param {string} rootName root name
* @param {function(): TODO} getMembers callback
*/
const tapOptionsHooks = (optionExpr, rootName, getMembers) => {

@@ -182,6 +189,6 @@ parser.hooks.expression

RuntimeGlobals.amdDefine,
expr.range,
/** @type {Range} */ (expr.range),
[RuntimeGlobals.amdDefine]
);
dep.loc = expr.loc;
dep.loc = /** @type {DependencyLocation} */ (expr.loc);
parser.state.module.addPresentationalDependency(dep);

@@ -203,6 +210,6 @@ return true;

RuntimeGlobals.amdDefine,
expr.range,
/** @type {Range} */ (expr.range),
[RuntimeGlobals.amdDefine]
);
dep.loc = expr.loc;
dep.loc = /** @type {DependencyLocation} */ (expr.loc);
parser.state.module.addPresentationalDependency(dep);

@@ -209,0 +216,0 @@ return false;

@@ -18,6 +18,8 @@ /*

/** @typedef {import("../serialization/ObjectMiddleware").ObjectSerializerContext} ObjectSerializerContext */
/** @typedef {import("./AMDRequireItemDependency")} AMDRequireItemDependency */
/** @typedef {import("./LocalModuleDependency")} LocalModuleDependency */
class AMDRequireArrayDependency extends NullDependency {
/**
* @param {TODO} depsArray deps array
* @param {(string | LocalModuleDependency | AMDRequireItemDependency)[]} depsArray deps array
* @param {Range} range range

@@ -85,2 +87,7 @@ */

/**
* @param {AMDRequireArrayDependency} dep the dependency for which the template should be applied
* @param {DependencyTemplateContext} templateContext the context object
* @returns {string} content
*/
getContent(dep, templateContext) {

@@ -93,2 +100,7 @@ const requires = dep.depsArray.map(dependency => {

/**
* @param {TODO} dep the dependency for which the template should be applied
* @param {DependencyTemplateContext} templateContext the context object
* @returns {string} content
*/
contentForDependency(

@@ -95,0 +107,0 @@ dep,

@@ -22,5 +22,17 @@ /*

/** @typedef {import("estree").CallExpression} CallExpression */
/** @typedef {import("estree").Expression} Expression */
/** @typedef {import("estree").SourceLocation} SourceLocation */
/** @typedef {import("estree").SpreadElement} SpreadElement */
/** @typedef {import("../../declarations/WebpackOptions").JavascriptParserOptions} JavascriptParserOptions */
/** @typedef {import("../Dependency").DependencyLocation} DependencyLocation */
/** @typedef {import("../Module").BuildInfo} BuildInfo */
/** @typedef {import("../javascript/BasicEvaluatedExpression")} BasicEvaluatedExpression */
/** @typedef {import("../javascript/JavascriptParser")} JavascriptParser */
/** @typedef {import("../javascript/JavascriptParser").Range} Range */
class AMDRequireDependenciesBlockParserPlugin {
/**
* @param {JavascriptParserOptions} options parserOptions
*/
constructor(options) {

@@ -30,2 +42,7 @@ this.options = options;

/**
* @param {JavascriptParser} parser the parser
* @param {Expression | SpreadElement} expression expression
* @returns {boolean} need bind this
*/
processFunctionArgument(parser, expression) {

@@ -70,5 +87,11 @@ let bindThis = true;

/**
* @param {JavascriptParser} parser the parser
* @param {CallExpression} expr call expression
* @param {BasicEvaluatedExpression} param param
* @returns {boolean | undefined} result
*/
processArray(parser, expr, param) {
if (param.isArray()) {
for (const p of param.items) {
for (const p of /** @type {BasicEvaluatedExpression[]} */ (param.items)) {
const result = this.processItem(parser, expr, p);

@@ -81,4 +104,5 @@ if (result === undefined) {

} else if (param.isConstArray()) {
/** @type {(string | LocalModuleDependency | AMDRequireItemDependency)[]} */
const deps = [];
for (const request of param.array) {
for (const request of /** @type {any[]} */ (param.array)) {
let dep, localModule;

@@ -92,7 +116,7 @@ if (request === "require") {

dep = new LocalModuleDependency(localModule, undefined, false);
dep.loc = expr.loc;
dep.loc = /** @type {DependencyLocation} */ (expr.loc);
parser.state.module.addPresentationalDependency(dep);
} else {
dep = this.newRequireItemDependency(request);
dep.loc = expr.loc;
dep.loc = /** @type {DependencyLocation} */ (expr.loc);
dep.optional = !!parser.scope.inTry;

@@ -103,4 +127,7 @@ parser.state.current.addDependency(dep);

}
const dep = this.newRequireArrayDependency(deps, param.range);
dep.loc = expr.loc;
const dep = this.newRequireArrayDependency(
deps,
/** @type {Range} */ (param.range)
);
dep.loc = /** @type {DependencyLocation} */ (expr.loc);
dep.optional = !!parser.scope.inTry;

@@ -111,5 +138,14 @@ parser.state.module.addPresentationalDependency(dep);

}
/**
* @param {JavascriptParser} parser the parser
* @param {CallExpression} expr call expression
* @param {BasicEvaluatedExpression} param param
* @returns {boolean | undefined} result
*/
processItem(parser, expr, param) {
if (param.isConditional()) {
for (const p of param.options) {
for (const p of /** @type {BasicEvaluatedExpression[]} */ (
param.options
)) {
const result = this.processItem(parser, expr, p);

@@ -124,9 +160,12 @@ if (result === undefined) {

if (param.string === "require") {
dep = new ConstDependency(RuntimeGlobals.require, param.string, [
RuntimeGlobals.require
]);
dep = new ConstDependency(
RuntimeGlobals.require,
/** @type {TODO} */ (param.string),
[RuntimeGlobals.require]
);
} else if (param.string === "module") {
dep = new ConstDependency(
parser.state.module.buildInfo.moduleArgument,
param.range,
/** @type {BuildInfo} */
(parser.state.module.buildInfo).moduleArgument,
/** @type {Range} */ (param.range),
[RuntimeGlobals.module]

@@ -136,12 +175,21 @@ );

dep = new ConstDependency(
parser.state.module.buildInfo.exportsArgument,
param.range,
/** @type {BuildInfo} */
(parser.state.module.buildInfo).exportsArgument,
/** @type {Range} */ (param.range),
[RuntimeGlobals.exports]
);
} else if ((localModule = getLocalModule(parser.state, param.string))) {
} else if (
(localModule = getLocalModule(
parser.state,
/** @type {string} */ (param.string)
))
) {
localModule.flagUsed();
dep = new LocalModuleDependency(localModule, param.range, false);
} else {
dep = this.newRequireItemDependency(param.string, param.range);
dep.loc = expr.loc;
dep = this.newRequireItemDependency(
/** @type {string} */ (param.string),
param.range
);
dep.loc = /** @type {DependencyLocation} */ (expr.loc);
dep.optional = !!parser.scope.inTry;

@@ -151,3 +199,3 @@ parser.state.current.addDependency(dep);

}
dep.loc = expr.loc;
dep.loc = /** @type {DependencyLocation} */ (expr.loc);
parser.state.module.addPresentationalDependency(dep);

@@ -157,6 +205,13 @@ return true;

}
/**
* @param {JavascriptParser} parser the parser
* @param {CallExpression} expr call expression
* @param {BasicEvaluatedExpression} param param
* @returns {boolean | undefined} result
*/
processContext(parser, expr, param) {
const dep = ContextDependencyHelpers.create(
AMDRequireContextDependency,
param.range,
/** @type {Range} */ (param.range),
param,

@@ -171,3 +226,3 @@ expr,

if (!dep) return;
dep.loc = expr.loc;
dep.loc = /** @type {DependencyLocation} */ (expr.loc);
dep.optional = !!parser.scope.inTry;

@@ -178,18 +233,26 @@ parser.state.current.addDependency(dep);

/**
* @param {BasicEvaluatedExpression} param param
* @returns {string | undefined} result
*/
processArrayForRequestString(param) {
if (param.isArray()) {
const result = param.items.map(item =>
this.processItemForRequestString(item)
);
const result =
/** @type {BasicEvaluatedExpression[]} */
(param.items).map(item => this.processItemForRequestString(item));
if (result.every(Boolean)) return result.join(" ");
} else if (param.isConstArray()) {
return param.array.join(" ");
return /** @type {string[]} */ (param.array).join(" ");
}
}
/**
* @param {BasicEvaluatedExpression} param param
* @returns {string | undefined} result
*/
processItemForRequestString(param) {
if (param.isConditional()) {
const result = param.options.map(item =>
this.processItemForRequestString(item)
);
const result =
/** @type {BasicEvaluatedExpression[]} */
(param.options).map(item => this.processItemForRequestString(item));
if (result.every(Boolean)) return result.join("|");

@@ -201,6 +264,15 @@ } else if (param.isString()) {

/**
* @param {JavascriptParser} parser the parser
* @param {CallExpression} expr call expression
* @returns {boolean | undefined} result
*/
processCallRequire(parser, expr) {
/** @type {BasicEvaluatedExpression | undefined} */
let param;
/** @type {AMDRequireDependenciesBlock | undefined | null} */
let depBlock;
/** @type {AMDRequireDependency | undefined} */
let dep;
/** @type {boolean | undefined} */
let result;

@@ -213,15 +285,19 @@

depBlock = this.newRequireDependenciesBlock(
expr.loc,
this.processArrayForRequestString(param)
/** @type {DependencyLocation} */ (expr.loc),
/** @type {string} */ (this.processArrayForRequestString(param))
);
dep = this.newRequireDependency(
expr.range,
param.range,
expr.arguments.length > 1 ? expr.arguments[1].range : null,
expr.arguments.length > 2 ? expr.arguments[2].range : null
/** @type {Range} */ (expr.range),
/** @type {Range} */ (param.range),
expr.arguments.length > 1
? /** @type {Range} */ (expr.arguments[1].range)
: null,
expr.arguments.length > 2
? /** @type {Range} */ (expr.arguments[2].range)
: null
);
dep.loc = expr.loc;
dep.loc = /** @type {DependencyLocation} */ (expr.loc);
depBlock.addDependency(dep);
parser.state.current = depBlock;
parser.state.current = /** @type {TODO} */ (depBlock);
}

@@ -231,7 +307,13 @@

parser.inScope([], () => {
result = this.processArray(parser, expr, param);
result = this.processArray(
parser,
expr,
/** @type {BasicEvaluatedExpression} */ (param)
);
});
parser.state.current = old;
if (!result) return;
parser.state.current.addBlock(depBlock);
parser.state.current.addBlock(
/** @type {AMDRequireDependenciesBlock} */ (depBlock)
);
return true;

@@ -243,6 +325,13 @@ }

parser.inScope([], () => {
result = this.processArray(parser, expr, param);
result = this.processArray(
parser,
expr,
/** @type {BasicEvaluatedExpression} */ (param)
);
});
if (!result) {
const dep = new UnsupportedDependency("unsupported", expr.range);
const dep = new UnsupportedDependency(
"unsupported",
/** @type {Range} */ (expr.range)
);
old.addPresentationalDependency(dep);

@@ -253,4 +342,4 @@ if (parser.state.module) {

"Cannot statically analyse 'require(…, …)' in line " +
expr.loc.start.line,
expr.loc
/** @type {SourceLocation} */ (expr.loc).start.line,
/** @type {DependencyLocation} */ (expr.loc)
)

@@ -262,3 +351,4 @@ );

}
dep.functionBindThis = this.processFunctionArgument(
/** @type {AMDRequireDependency} */
(dep).functionBindThis = this.processFunctionArgument(
parser,

@@ -268,3 +358,4 @@ expr.arguments[1]

if (expr.arguments.length === 3) {
dep.errorCallbackBindThis = this.processFunctionArgument(
/** @type {AMDRequireDependency} */
(dep).errorCallbackBindThis = this.processFunctionArgument(
parser,

@@ -282,5 +373,18 @@ expr.arguments[2]

/**
* @param {DependencyLocation} loc location
* @param {string} request request
* @returns {AMDRequireDependenciesBlock} AMDRequireDependenciesBlock
*/
newRequireDependenciesBlock(loc, request) {
return new AMDRequireDependenciesBlock(loc, request);
}
/**
* @param {Range} outerRange outer range
* @param {Range} arrayRange array range
* @param {Range | null} functionRange function range
* @param {Range | null} errorCallbackRange error callback range
* @returns {AMDRequireDependency} dependency
*/
newRequireDependency(

@@ -299,5 +403,17 @@ outerRange,

}
/**
* @param {string} request request
* @param {Range=} range range
* @returns {AMDRequireItemDependency} AMDRequireItemDependency
*/
newRequireItemDependency(request, range) {
return new AMDRequireItemDependency(request, range);
}
/**
* @param {(string | LocalModuleDependency | AMDRequireItemDependency)[]} depsArray deps array
* @param {Range} range range
* @returns {AMDRequireArrayDependency} AMDRequireArrayDependency
*/
newRequireArrayDependency(depsArray, range) {

@@ -304,0 +420,0 @@ return new AMDRequireArrayDependency(depsArray, range);

@@ -24,4 +24,4 @@ /*

* @param {Range} arrayRange array range
* @param {Range} functionRange function range
* @param {Range} errorCallbackRange error callback range
* @param {Range | null} functionRange function range
* @param {Range | null} errorCallbackRange error callback range
*/

@@ -28,0 +28,0 @@ constructor(outerRange, arrayRange, functionRange, errorCallbackRange) {

@@ -17,3 +17,3 @@ /*

* @param {string} request the request string
* @param {Range} range location in source code
* @param {Range=} range location in source code
*/

@@ -20,0 +20,0 @@ constructor(request, range) {

@@ -17,2 +17,3 @@ /*

/** @typedef {import("../javascript/JavascriptModulesPlugin").ChunkRenderContext} ChunkRenderContext */
/** @typedef {import("../javascript/JavascriptParser").Range} Range */
/** @typedef {import("../serialization/ObjectMiddleware").ObjectDeserializerContext} ObjectDeserializerContext */

@@ -23,2 +24,10 @@ /** @typedef {import("../serialization/ObjectMiddleware").ObjectSerializerContext} ObjectSerializerContext */

class ExternalModuleDependency extends CachedConstDependency {
/**
* @param {string} module module
* @param {{ name: string, value: string }[]} importSpecifiers import specifiers
* @param {string | undefined} defaultImport default import
* @param {string} expression expression
* @param {Range} range range
* @param {string} identifier identifier
*/
constructor(

@@ -25,0 +34,0 @@ module,

@@ -12,3 +12,3 @@ /*

/** @typedef {import("webpack-sources").Source} Source */
/** @typedef {import("../Generator").GenerateContext} Context */
/** @typedef {import("../Generator").GenerateContext} GenerateContext */
/** @typedef {import("../serialization/ObjectMiddleware").ObjectDeserializerContext} ObjectDeserializerContext */

@@ -18,2 +18,5 @@ /** @typedef {import("../serialization/ObjectMiddleware").ObjectSerializerContext} ObjectSerializerContext */

/**
* @extends {InitFragment<GenerateContext>}
*/
class ExternalModuleInitFragment extends InitFragment {

@@ -50,2 +53,6 @@ /**

/**
* @param {ExternalModuleInitFragment} other other
* @returns {ExternalModuleInitFragment} ExternalModuleInitFragment
*/
merge(other) {

@@ -69,4 +76,4 @@ const newSpecifiersMap = new Map(this.specifiers);

/**
* @param {Context} context context
* @returns {string|Source} the source code that will be included as initialization code
* @param {GenerateContext} context context
* @returns {string | Source} the source code that will be included as initialization code
*/

@@ -73,0 +80,0 @@ getContent({ runtimeRequirements }) {

@@ -12,4 +12,4 @@ /*

/**
* @param {Expression} expr expressions
* @returns {{fn: TODO, expressions: (Expression | SpreadElement)[], needThis: boolean | undefined }} function expression with additional information
* @param {Expression | SpreadElement} expr expressions
* @returns {{fn: TODO, expressions: (Expression | SpreadElement)[], needThis: boolean | undefined } | undefined} function expression with additional information
*/

@@ -16,0 +16,0 @@ module.exports = expr => {

@@ -133,4 +133,4 @@ /*

/**
* @param {Context} context context
* @returns {string|Source} the source code that will be included as initialization code
* @param {GenerateContext} context context
* @returns {string | Source} the source code that will be included as initialization code
*/

@@ -137,0 +137,0 @@ getContent({ runtimeTemplate, runtimeRequirements }) {

@@ -22,3 +22,3 @@ /*

* @param {LocalModule} localModule local module
* @param {Range} range range
* @param {Range | undefined} range range
* @param {boolean} callNew true, when the local module should be called with new

@@ -25,0 +25,0 @@ */

@@ -187,4 +187,5 @@ /*

const insertType = expr.properties.length > 0 ? "comma" : "single";
const insertLocation =
expr.properties[expr.properties.length - 1].range[1];
const insertLocation = /** @type {Range} */ (
expr.properties[expr.properties.length - 1].range
)[1];
return {

@@ -191,0 +192,0 @@ expressions,

@@ -132,3 +132,3 @@ /*

sourceMap = { ...sourceMap };
const context = compiler.options.context;
const context = /** @type {string} */ (compiler.options.context);
const root = compiler.root;

@@ -135,0 +135,0 @@ const modules = sourceMap.sources.map(source => {

@@ -39,11 +39,11 @@ /*

/**
* @template Context
* @template GenerateContext
*/
class InitFragment {
/**
* @param {string|Source} content the source code that will be included as initialization code
* @param {string | Source} content the source code that will be included as initialization code
* @param {number} stage category of initialization code (contribute to order)
* @param {number} position position in the category (contribute to order)
* @param {string=} key unique key to avoid emitting the same initialization code twice
* @param {string|Source=} endContent the source code that will be included at the end of the module
* @param {string | Source=} endContent the source code that will be included at the end of the module
*/

@@ -59,4 +59,4 @@ constructor(content, stage, position, key, endContent) {

/**
* @param {Context} context context
* @returns {string|Source} the source code that will be included as initialization code
* @param {GenerateContext} context context
* @returns {string | Source} the source code that will be included as initialization code
*/

@@ -68,3 +68,3 @@ getContent(context) {

/**
* @param {Context} context context
* @param {GenerateContext} context context
* @returns {string|Source=} the source code that will be included at the end of the module

@@ -97,3 +97,3 @@ */

typeof (
/** @type {InitFragment<T> & { mergeAll?: (fragments: InitFragment[]) => InitFragment[] }} */
/** @type {InitFragment<T> & { mergeAll?: (fragments: InitFragment<Context>[]) => InitFragment<Context>[] }} */
(fragment).mergeAll

@@ -100,0 +100,0 @@ ) === "function"

@@ -139,3 +139,3 @@ /*

* @param {string} expressionName expression name
* @param {(value: string) => void} fn function
* @param {(value: string) => string} fn function
* @returns {void}

@@ -157,6 +157,6 @@ */

fn("__webpack_fileURLToPath__"),
expr.range,
/** @type {Range} */ (expr.range),
expressionName
);
dep.loc = expr.loc;
dep.loc = /** @type {DependencyLocation} */ (expr.loc);
parser.state.module.addPresentationalDependency(dep);

@@ -163,0 +163,0 @@

@@ -91,3 +91,7 @@ /*

) {
mangleExportsInfo(deterministic, exportInfo.exportsInfo, false);
mangleExportsInfo(
deterministic,
/** @type {ExportsInfo} */ (exportInfo.exportsInfo),
false
);
}

@@ -94,0 +98,0 @@ }

@@ -68,2 +68,6 @@ /*

/**
* @param {(string|StatsOptions)=} options stats options
* @returns {string} string output
*/
toString(options) {

@@ -70,0 +74,0 @@ options = this.compilation.createStatsOptions(options, {

@@ -9,2 +9,3 @@ /*

/** @typedef {import("../Dependency")} Dependency */
/** @typedef {import("../Module")} Module */
/** @typedef {import("../ModuleGraph")} ModuleGraph */

@@ -21,3 +22,3 @@ /** @typedef {import("../javascript/JavascriptParser").Range} Range */

* @param {Range} untrimmedRange range encompassing allIds
* @param {Range[]} ranges cumulative range of ids for each of allIds
* @param {Range[] | undefined} ranges cumulative range of ids for each of allIds
* @param {ModuleGraph} moduleGraph moduleGraph

@@ -49,3 +50,3 @@ * @param {Dependency} dependency dependency

: ranges.length + (trimmedIds.length - untrimmedIds.length);
if (idx < 0 || idx >= ranges.length) {
if (idx < 0 || idx >= /** @type {Range[]} */ (ranges).length) {
// cspell:ignore minifiers

@@ -58,3 +59,3 @@ // Should not happen but we can't throw an error here because of backward compatibility with

} else {
trimmedRange = ranges[idx];
trimmedRange = /** @type {Range[]} */ (ranges)[idx];
}

@@ -75,7 +76,7 @@ }

function trimIdsToThoseImported(ids, moduleGraph, dependency) {
/** @type {string[]} */
let trimmedIds = [];
const exportsInfo = moduleGraph.getExportsInfo(
moduleGraph.getModule(dependency)
let currentExportsInfo = moduleGraph.getExportsInfo(
/** @type {Module} */ (moduleGraph.getModule(dependency))
);
let currentExportsInfo = /** @type {ExportsInfo=} */ exportsInfo;
for (let i = 0; i < ids.length; i++) {

@@ -82,0 +83,0 @@ if (i === 0 && ids[i] === "default") {

@@ -95,28 +95,64 @@ /*

const compareStringsNumeric = (a, b) => {
const partsA = a.split(/(\d+)/);
const partsB = b.split(/(\d+)/);
const len = Math.min(partsA.length, partsB.length);
for (let i = 0; i < len; i++) {
const pA = partsA[i];
const pB = partsB[i];
if (i % 2 === 0) {
if (pA.length > pB.length) {
if (pA.slice(0, pB.length) > pB) return 1;
return -1;
} else if (pB.length > pA.length) {
if (pB.slice(0, pA.length) > pA) return -1;
return 1;
} else {
if (pA < pB) return -1;
if (pA > pB) return 1;
const aLength = a.length;
const bLength = b.length;
let aChar = 0;
let bChar = 0;
let aIsDigit = false;
let bIsDigit = false;
let i = 0;
let j = 0;
while (i < aLength && j < bLength) {
aChar = a.charCodeAt(i);
bChar = b.charCodeAt(j);
aIsDigit = aChar >= 48 && aChar <= 57;
bIsDigit = bChar >= 48 && bChar <= 57;
if (!aIsDigit && !bIsDigit) {
if (aChar < bChar) return -1;
if (aChar > bChar) return 1;
i++;
j++;
} else if (aIsDigit && !bIsDigit) {
// This segment of a is shorter than in b
return 1;
} else if (!aIsDigit && bIsDigit) {
// This segment of b is shorter than in a
return -1;
} else {
let aNumber = aChar - 48;
let bNumber = bChar - 48;
while (++i < aLength) {
aChar = a.charCodeAt(i);
if (aChar < 48 || aChar > 57) break;
aNumber = aNumber * 10 + aChar - 48;
}
} else {
const nA = +pA;
const nB = +pB;
if (nA < nB) return -1;
if (nA > nB) return 1;
while (++j < bLength) {
bChar = b.charCodeAt(j);
if (bChar < 48 || bChar > 57) break;
bNumber = bNumber * 10 + bChar - 48;
}
if (aNumber < bNumber) return -1;
if (aNumber > bNumber) return 1;
}
}
if (partsB.length < partsA.length) return 1;
if (partsB.length > partsA.length) return -1;
if (j < bLength) {
// a is shorter than b
bChar = b.charCodeAt(j);
bIsDigit = bChar >= 48 && bChar <= 57;
return bIsDigit ? -1 : 1;
}
if (i < aLength) {
// b is shorter than a
aChar = a.charCodeAt(i);
aIsDigit = aChar >= 48 && aChar <= 57;
return aIsDigit ? 1 : -1;
}
return 0;

@@ -123,0 +159,0 @@ };

@@ -9,34 +9,78 @@ /*

/**
* The maximum safe integer value for 32-bit integers.
* Threshold for switching from 32-bit to 64-bit hashing. This is selected to ensure that the bias towards lower modulo results when using 32-bit hashing is <0.5%.
* @type {number}
*/
const SAFE_LIMIT = 0x80000000;
const FNV_64_THRESHOLD = 1 << 24;
/**
* The maximum safe integer value for 32-bit integers minus one. This is used
* in the algorithm to ensure that intermediate hash values do not exceed the
* 32-bit integer limit.
* The FNV-1a offset basis for 32-bit hash values.
* @type {number}
*/
const SAFE_PART = SAFE_LIMIT - 1;
const FNV_OFFSET_32 = 2166136261;
/**
* The number of 32-bit integers used to store intermediate hash values.
* The FNV-1a prime for 32-bit hash values.
* @type {number}
*/
const COUNT = 4;
const FNV_PRIME_32 = 16777619;
/**
* The mask for a positive 32-bit signed integer.
* @type {number}
*/
const MASK_31 = 0x7fffffff;
/**
* An array used to store intermediate hash values during the calculation.
* @type {number[]}
* The FNV-1a offset basis for 64-bit hash values.
* @type {bigint}
*/
const arr = [0, 0, 0, 0, 0];
const FNV_OFFSET_64 = BigInt("0xCBF29CE484222325");
/**
* The FNV-1a prime for 64-bit hash values.
* @type {bigint}
*/
const FNV_PRIME_64 = BigInt("0x100000001B3");
/**
* An array of prime numbers used in the hash calculation.
* @type {number[]}
* Computes a 32-bit FNV-1a hash value for the given string.
* See https://en.wikipedia.org/wiki/Fowler%E2%80%93Noll%E2%80%93Vo_hash_function
* @param {string} str The input string to hash
* @returns {number} - The computed hash value.
*/
const primes = [3, 7, 17, 19];
function fnv1a32(str) {
let hash = FNV_OFFSET_32;
for (let i = 0, len = str.length; i < len; i++) {
let code = str.charCodeAt(i);
if (code > 0xff) {
hash ^= code & 0xff;
hash = (hash * FNV_PRIME_32) | 0;
code >>= 8;
}
hash ^= code;
hash = (hash * FNV_PRIME_32) | 0;
}
// Force the result to be positive
return hash & MASK_31;
}
/**
* Computes a 64-bit FNV-1a hash value for the given string.
* See https://en.wikipedia.org/wiki/Fowler%E2%80%93Noll%E2%80%93Vo_hash_function
* @param {string} str The input string to hash
* @returns {bigint} - The computed hash value.
*/
function fnv1a64(str) {
let hash = FNV_OFFSET_64;
for (let i = 0, len = str.length; i < len; i++) {
let code = str.charCodeAt(i);
if (code > 0xff) {
hash ^= BigInt(code & 0xff);
hash = BigInt.asUintN(64, hash * FNV_PRIME_64);
code >>= 8;
}
hash ^= BigInt(code);
hash = BigInt.asUintN(64, hash * FNV_PRIME_64);
}
return hash;
}
/**
* Computes a hash value for the given string and range. This hashing algorithm is a modified

@@ -57,4 +101,4 @@ * version of the [FNV-1a algorithm](https://en.wikipedia.org/wiki/Fowler%E2%80%93Noll%E2%80%93Vo_hash_function).

* const numberHash = require("webpack/lib/util/numberHash");
* numberHash("hello", 1000); // 57
* numberHash("hello world"); // 990
* numberHash("hello", 1000); // 73
* numberHash("hello world"); // 72
* ```

@@ -64,39 +108,7 @@ *

module.exports = (str, range) => {
/**
* Initialize the array with zeros before it is used
* to store intermediate hash values.
*/
arr.fill(0);
// For each character in the string
for (let i = 0; i < str.length; i++) {
// Get the character code.
const c = str.charCodeAt(i);
// For each 32-bit integer used to store the hash value
// add the character code to the current hash value and multiply by the prime number and
// add the previous 32-bit integer.
arr[0] = (arr[0] + c * primes[0] + arr[3]) & SAFE_PART;
arr[1] = (arr[1] + c * primes[1] + arr[0]) & SAFE_PART;
arr[2] = (arr[2] + c * primes[2] + arr[1]) & SAFE_PART;
arr[3] = (arr[3] + c * primes[3] + arr[2]) & SAFE_PART;
// For each 32-bit integer used to store the hash value
// XOR the current hash value with the value of the next 32-bit integer.
arr[0] = arr[0] ^ (arr[arr[0] % COUNT] >> 1);
arr[1] = arr[1] ^ (arr[arr[1] % COUNT] >> 1);
arr[2] = arr[2] ^ (arr[arr[2] % COUNT] >> 1);
arr[3] = arr[3] ^ (arr[arr[3] % COUNT] >> 1);
}
if (range <= SAFE_PART) {
return (arr[0] + arr[1] + arr[2] + arr[3]) % range;
if (range < FNV_64_THRESHOLD) {
return fnv1a32(str) % range;
} else {
// Calculate the range extension.
const rangeExt = Math.floor(range / SAFE_LIMIT);
const sum1 = (arr[0] + arr[2]) & SAFE_PART;
const sum2 = (arr[0] + arr[2]) % rangeExt;
return (sum2 * SAFE_LIMIT + sum1) % range;
return Number(fnv1a64(str) % BigInt(range));
}
};

@@ -55,34 +55,59 @@ /*

);
return `${fn} = ${runtimeTemplate.basicFunction(
"exports, wasmModuleId, wasmModuleHash, importsObj",
[
`var req = ${this.generateLoadBinaryCode(wasmModuleSrcPath)};`,
this.supportsStreaming
? Template.asString([
"if (typeof WebAssembly.instantiateStreaming === 'function') {",
const loader = this.generateLoadBinaryCode(wasmModuleSrcPath);
const fallback = [
`.then(${runtimeTemplate.returningFunction("x.arrayBuffer()", "x")})`,
`.then(${runtimeTemplate.returningFunction(
"WebAssembly.instantiate(bytes, importsObj)",
"bytes"
)})`,
`.then(${runtimeTemplate.returningFunction(
"Object.assign(exports, res.instance.exports)",
"res"
)})`
];
const getStreaming = () => {
const concat = (/** @type {string[]} */ ...text) => text.join("");
return [
`var req = ${loader};`,
`var fallback = ${runtimeTemplate.returningFunction(Template.asString(["req", Template.indent(fallback)]))};`,
concat(
"return req.then(",
runtimeTemplate.basicFunction("res", [
`if (typeof WebAssembly.instantiateStreaming === "function") {`,
Template.indent([
"return WebAssembly.instantiateStreaming(res, importsObj)",
Template.indent([
"return WebAssembly.instantiateStreaming(req, importsObj)",
".then(",
Template.indent([
`.then(${runtimeTemplate.returningFunction(
runtimeTemplate.returningFunction(
"Object.assign(exports, res.instance.exports)",
"res"
)});`
])
]),
"}"
])
: "// no support for streaming compilation",
"return req",
Template.indent([
`.then(${runtimeTemplate.returningFunction("x.arrayBuffer()", "x")})`,
`.then(${runtimeTemplate.returningFunction(
"WebAssembly.instantiate(bytes, importsObj)",
"bytes"
)})`,
`.then(${runtimeTemplate.returningFunction(
"Object.assign(exports, res.instance.exports)",
"res"
)});`
])
]
) + ",",
runtimeTemplate.basicFunction("e", [
`if(res.headers.get("Content-Type") !== "application/wasm") {`,
Template.indent([
'console.warn("`WebAssembly.instantiateStreaming` failed because your server does not serve wasm with `application/wasm` MIME type. Falling back to `WebAssembly.instantiate` which is slower. Original error:\\n", e);',
"return fallback();"
]),
"}",
"throw e;"
])
]),
");"
])
]),
"}",
"return fallback();"
]),
");"
)
];
};
return `${fn} = ${runtimeTemplate.basicFunction(
"exports, wasmModuleId, wasmModuleHash, importsObj",
this.supportsStreaming
? getStreaming()
: [`return ${loader}`, Template.indent(fallback) + ";"]
)};`;

@@ -89,0 +114,0 @@ }

{
"name": "webpack",
"version": "5.90.0",
"version": "5.90.1",
"author": "Tobias Koppers @sokra",

@@ -87,2 +87,3 @@ "description": "Packs ECMAScript/CommonJs/AMD modules for the browser. Allows you to split your codebase into multiple bundles, which can be loaded on demand. Supports loaders to preprocess files, i.e. json, jsx, es7, css, less, ... and your custom stuff.",

"open-cli": "^7.2.0",
"prettier-2": "npm:prettier@^2",
"prettier": "^3.2.1",

@@ -162,3 +163,3 @@ "pretty-format": "^29.5.0",

"prepare": "husky install",
"pretty-lint-base": "prettier --cache .",
"pretty-lint-base": "node node_modules/prettier/bin/prettier.cjs --cache .",
"pretty-lint-fix": "yarn pretty-lint-base --loglevel warn --write",

@@ -191,59 +192,3 @@ "pretty-lint": "yarn pretty-lint-base --check",

]
},
"jest": {
"forceExit": true,
"setupFilesAfterEnv": [
"<rootDir>/test/setupTestFramework.js"
],
"testMatch": [
"<rootDir>/test/*.test.js",
"<rootDir>/test/*.basictest.js",
"<rootDir>/test/*.longtest.js",
"<rootDir>/test/*.unittest.js"
],
"watchPathIgnorePatterns": [
"<rootDir>/.git",
"<rootDir>/node_modules",
"<rootDir>/test/js",
"<rootDir>/test/browsertest/js",
"<rootDir>/test/fixtures/temp-cache-fixture",
"<rootDir>/test/fixtures/temp-",
"<rootDir>/benchmark",
"<rootDir>/assembly",
"<rootDir>/tooling",
"<rootDir>/examples/*/dist",
"<rootDir>/coverage",
"<rootDir>/.eslintcache"
],
"modulePathIgnorePatterns": [
"<rootDir>/.git",
"<rootDir>/node_modules/webpack/node_modules",
"<rootDir>/test/js",
"<rootDir>/test/browsertest/js",
"<rootDir>/test/fixtures/temp-cache-fixture",
"<rootDir>/test/fixtures/temp-",
"<rootDir>/benchmark",
"<rootDir>/examples/*/dist",
"<rootDir>/coverage",
"<rootDir>/.eslintcache"
],
"transformIgnorePatterns": [
"<rootDir>"
],
"coverageDirectory": "<rootDir>/coverage",
"coveragePathIgnorePatterns": [
"\\.runtime\\.js$",
"<rootDir>/test",
"<rootDir>/schemas",
"<rootDir>/node_modules"
],
"testEnvironment": "./test/patch-node-env.js",
"coverageReporters": [
"json"
],
"snapshotFormat": {
"escapeString": true,
"printBasicPrototype": true
}
}
}

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc