mirror of https://github.com/webpack/webpack.git
style: improve style of code
This commit is contained in:
parent
b9d9a5d9ff
commit
0b745968a2
|
@ -238,10 +238,17 @@ module.exports = [
|
||||||
"no-var": "error",
|
"no-var": "error",
|
||||||
"one-var": ["error", "never"],
|
"one-var": ["error", "never"],
|
||||||
"prefer-template": "error",
|
"prefer-template": "error",
|
||||||
|
"no-implicit-coercion": [
|
||||||
|
"error",
|
||||||
|
{
|
||||||
|
boolean: true,
|
||||||
|
number: true,
|
||||||
|
string: true
|
||||||
|
}
|
||||||
|
],
|
||||||
|
|
||||||
// TODO Enable
|
// TODO Enable
|
||||||
"arrow-body-style": "off",
|
"arrow-body-style": "off",
|
||||||
"no-implicit-coercion": "off",
|
|
||||||
"no-sequences": "off",
|
"no-sequences": "off",
|
||||||
"prefer-spread": "off",
|
"prefer-spread": "off",
|
||||||
"default-case": "off",
|
"default-case": "off",
|
||||||
|
@ -300,7 +307,8 @@ module.exports = [
|
||||||
"no-undef-init": "off",
|
"no-undef-init": "off",
|
||||||
"no-var": "off",
|
"no-var": "off",
|
||||||
"n/exports-style": "off",
|
"n/exports-style": "off",
|
||||||
"prefer-template": "off"
|
"prefer-template": "off",
|
||||||
|
"no-implicit-coercion": "off"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|
|
@ -1099,7 +1099,7 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
|
||||||
this._codeGenerationCache = this.getCache("Compilation/codeGeneration");
|
this._codeGenerationCache = this.getCache("Compilation/codeGeneration");
|
||||||
|
|
||||||
const unsafeCache = options.module.unsafeCache;
|
const unsafeCache = options.module.unsafeCache;
|
||||||
this._unsafeCache = !!unsafeCache;
|
this._unsafeCache = Boolean(unsafeCache);
|
||||||
this._unsafeCachePredicate =
|
this._unsafeCachePredicate =
|
||||||
typeof unsafeCache === "function" ? unsafeCache : () => true;
|
typeof unsafeCache === "function" ? unsafeCache : () => true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1238,7 +1238,7 @@ ${other}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
isChild() {
|
isChild() {
|
||||||
return !!this.parentCompilation;
|
return Boolean(this.parentCompilation);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -135,7 +135,7 @@ class ConcatenationScope {
|
||||||
static matchModuleReference(name) {
|
static matchModuleReference(name) {
|
||||||
const match = MODULE_REFERENCE_REGEXP.exec(name);
|
const match = MODULE_REFERENCE_REGEXP.exec(name);
|
||||||
if (!match) return null;
|
if (!match) return null;
|
||||||
const index = +match[1];
|
const index = Number(match[1]);
|
||||||
const asiSafe = match[5];
|
const asiSafe = match[5];
|
||||||
return {
|
return {
|
||||||
index,
|
index,
|
||||||
|
@ -143,8 +143,8 @@ class ConcatenationScope {
|
||||||
match[2] === "ns"
|
match[2] === "ns"
|
||||||
? []
|
? []
|
||||||
: JSON.parse(Buffer.from(match[2], "hex").toString("utf-8")),
|
: JSON.parse(Buffer.from(match[2], "hex").toString("utf-8")),
|
||||||
call: !!match[3],
|
call: Boolean(match[3]),
|
||||||
directImport: !!match[4],
|
directImport: Boolean(match[4]),
|
||||||
asiSafe: asiSafe ? asiSafe === "1" : undefined
|
asiSafe: asiSafe ? asiSafe === "1" : undefined
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,7 +24,7 @@ const processAsyncTree = require("./util/processAsyncTree");
|
||||||
/** @typedef {import("./util/fs").IStats} IStats */
|
/** @typedef {import("./util/fs").IStats} IStats */
|
||||||
/** @typedef {import("./util/fs").InputFileSystem} InputFileSystem */
|
/** @typedef {import("./util/fs").InputFileSystem} InputFileSystem */
|
||||||
|
|
||||||
const supportsEsm = +process.versions.modules >= 83;
|
const supportsEsm = Number(process.versions.modules) >= 83;
|
||||||
|
|
||||||
const builtinModules = new Set(nodeModule.builtinModules);
|
const builtinModules = new Set(nodeModule.builtinModules);
|
||||||
|
|
||||||
|
@ -2945,7 +2945,7 @@ class FileSystemInfo {
|
||||||
timestamp: undefined
|
timestamp: undefined
|
||||||
};
|
};
|
||||||
} else {
|
} else {
|
||||||
const mtime = +stat.mtime;
|
const mtime = Number(stat.mtime);
|
||||||
|
|
||||||
if (mtime) applyMtime(mtime);
|
if (mtime) applyMtime(mtime);
|
||||||
|
|
||||||
|
@ -3158,7 +3158,7 @@ class FileSystemInfo {
|
||||||
if (cache !== undefined)
|
if (cache !== undefined)
|
||||||
return callback(null, cache === "ignore" ? null : cache);
|
return callback(null, cache === "ignore" ? null : cache);
|
||||||
|
|
||||||
const mtime = +stat.mtime;
|
const mtime = Number(stat.mtime);
|
||||||
|
|
||||||
if (mtime) applyMtime(mtime);
|
if (mtime) applyMtime(mtime);
|
||||||
|
|
||||||
|
|
|
@ -600,7 +600,7 @@ class HotModuleReplacementPlugin {
|
||||||
removedFromRuntime = subtractRuntime(oldRuntime, newRuntime);
|
removedFromRuntime = subtractRuntime(oldRuntime, newRuntime);
|
||||||
} else {
|
} else {
|
||||||
// chunk has completely removed
|
// chunk has completely removed
|
||||||
chunkId = `${+key}` === key ? +key : key;
|
chunkId = `${Number(key)}` === key ? Number(key) : key;
|
||||||
removedFromRuntime = oldRuntime;
|
removedFromRuntime = oldRuntime;
|
||||||
newRuntime = oldRuntime;
|
newRuntime = oldRuntime;
|
||||||
}
|
}
|
||||||
|
|
|
@ -73,7 +73,7 @@ class ModuleGraphConnection {
|
||||||
this.resolvedModule = module;
|
this.resolvedModule = module;
|
||||||
this.module = module;
|
this.module = module;
|
||||||
this.weak = weak;
|
this.weak = weak;
|
||||||
this.conditional = !!condition;
|
this.conditional = Boolean(condition);
|
||||||
this._active = condition !== false;
|
this._active = condition !== false;
|
||||||
/** @type {(function(ModuleGraphConnection, RuntimeSpec): ConnectionState) | undefined} */
|
/** @type {(function(ModuleGraphConnection, RuntimeSpec): ConnectionState) | undefined} */
|
||||||
this.condition = condition || undefined;
|
this.condition = condition || undefined;
|
||||||
|
|
|
@ -736,7 +736,7 @@ class NormalModule extends Module {
|
||||||
utils,
|
utils,
|
||||||
rootContext: /** @type {string} */ (options.context),
|
rootContext: /** @type {string} */ (options.context),
|
||||||
webpack: true,
|
webpack: true,
|
||||||
sourceMap: !!this.useSourceMap,
|
sourceMap: Boolean(this.useSourceMap),
|
||||||
mode: options.mode || "production",
|
mode: options.mode || "production",
|
||||||
_module: this,
|
_module: this,
|
||||||
_compilation: compilation,
|
_compilation: compilation,
|
||||||
|
@ -1450,7 +1450,7 @@ class NormalModule extends Module {
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
callback(null, !!needBuild);
|
callback(null, Boolean(needBuild));
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -376,7 +376,9 @@ class RuntimePlugin {
|
||||||
compilation.hooks.runtimeRequirementInTree
|
compilation.hooks.runtimeRequirementInTree
|
||||||
.for(RuntimeGlobals.loadScript)
|
.for(RuntimeGlobals.loadScript)
|
||||||
.tap("RuntimePlugin", (chunk, set) => {
|
.tap("RuntimePlugin", (chunk, set) => {
|
||||||
const withCreateScriptUrl = !!compilation.outputOptions.trustedTypes;
|
const withCreateScriptUrl = Boolean(
|
||||||
|
compilation.outputOptions.trustedTypes
|
||||||
|
);
|
||||||
if (withCreateScriptUrl) {
|
if (withCreateScriptUrl) {
|
||||||
set.add(RuntimeGlobals.createScriptUrl);
|
set.add(RuntimeGlobals.createScriptUrl);
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,5 +21,5 @@ module.exports.formatSize = size => {
|
||||||
const abbreviations = ["bytes", "KiB", "MiB", "GiB"];
|
const abbreviations = ["bytes", "KiB", "MiB", "GiB"];
|
||||||
const index = Math.floor(Math.log(size) / Math.log(1024));
|
const index = Math.floor(Math.log(size) / Math.log(1024));
|
||||||
|
|
||||||
return `${+(size / 1024 ** index).toPrecision(3)} ${abbreviations[index]}`;
|
return `${Number(size / 1024 ** index).toPrecision(3)} ${abbreviations[index]}`;
|
||||||
};
|
};
|
||||||
|
|
|
@ -276,7 +276,7 @@ const getArguments = (schema = webpackSchema) => {
|
||||||
|
|
||||||
let addedArguments = 0;
|
let addedArguments = 0;
|
||||||
|
|
||||||
addedArguments += addFlag(fullPath, !!inArray);
|
addedArguments += addFlag(fullPath, Boolean(inArray));
|
||||||
|
|
||||||
if (schemaPart.type === "object") {
|
if (schemaPart.type === "object") {
|
||||||
if (schemaPart.properties) {
|
if (schemaPart.properties) {
|
||||||
|
@ -565,7 +565,7 @@ const parseValueForArgumentConfig = (argConfig, value) => {
|
||||||
case "number":
|
case "number":
|
||||||
if (typeof value === "number") return value;
|
if (typeof value === "number") return value;
|
||||||
if (typeof value === "string" && /^[+-]?\d*(\.\d*)[eE]\d+$/) {
|
if (typeof value === "string" && /^[+-]?\d*(\.\d*)[eE]\d+$/) {
|
||||||
const n = +value;
|
const n = Number(value);
|
||||||
if (!isNaN(n)) return n;
|
if (!isNaN(n)) return n;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -94,11 +94,11 @@ const resolve = browsers => {
|
||||||
? parsedVersion.split("-")[0].split(".")
|
? parsedVersion.split("-")[0].split(".")
|
||||||
: parsedVersion.split(".");
|
: parsedVersion.split(".");
|
||||||
if (typeof requiredVersion === "number") {
|
if (typeof requiredVersion === "number") {
|
||||||
return +parsedMajor >= requiredVersion;
|
return Number(parsedMajor) >= requiredVersion;
|
||||||
}
|
}
|
||||||
return requiredVersion[0] === +parsedMajor
|
return requiredVersion[0] === Number(parsedMajor)
|
||||||
? +parserMinor >= requiredVersion[1]
|
? Number(parserMinor) >= requiredVersion[1]
|
||||||
: +parsedMajor > requiredVersion[0];
|
: Number(parsedMajor) > requiredVersion[0];
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
const anyNode = browsers.some(b => /^node /.test(b));
|
const anyNode = browsers.some(b => /^node /.test(b));
|
||||||
|
|
|
@ -217,7 +217,7 @@ const applyWebpackOptionsDefaults = (options, compilerIndex) => {
|
||||||
cacheUnaffected: options.experiments.cacheUnaffected,
|
cacheUnaffected: options.experiments.cacheUnaffected,
|
||||||
compilerIndex
|
compilerIndex
|
||||||
});
|
});
|
||||||
const cache = !!options.cache;
|
const cache = Boolean(options.cache);
|
||||||
|
|
||||||
applySnapshotDefaults(options.snapshot, {
|
applySnapshotDefaults(options.snapshot, {
|
||||||
production,
|
production,
|
||||||
|
@ -258,7 +258,7 @@ const applyWebpackOptionsDefaults = (options, compilerIndex) => {
|
||||||
|
|
||||||
applyExternalsPresetsDefaults(options.externalsPresets, {
|
applyExternalsPresetsDefaults(options.externalsPresets, {
|
||||||
targetProperties,
|
targetProperties,
|
||||||
buildHttp: !!options.experiments.buildHttp
|
buildHttp: Boolean(options.experiments.buildHttp)
|
||||||
});
|
});
|
||||||
|
|
||||||
applyLoaderDefaults(
|
applyLoaderDefaults(
|
||||||
|
@ -308,7 +308,7 @@ const applyWebpackOptionsDefaults = (options, compilerIndex) => {
|
||||||
css:
|
css:
|
||||||
/** @type {NonNullable<ExperimentsNormalized["css"]>} */
|
/** @type {NonNullable<ExperimentsNormalized["css"]>} */
|
||||||
(options.experiments.css),
|
(options.experiments.css),
|
||||||
records: !!(options.recordsInputPath || options.recordsOutputPath)
|
records: Boolean(options.recordsInputPath || options.recordsOutputPath)
|
||||||
});
|
});
|
||||||
|
|
||||||
options.resolve = cleverMerge(
|
options.resolve = cleverMerge(
|
||||||
|
@ -919,7 +919,7 @@ const applyOutputDefaults = (
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
F(output, "module", () => !!outputModule);
|
F(output, "module", () => Boolean(outputModule));
|
||||||
D(output, "filename", output.module ? "[name].mjs" : "[name].js");
|
D(output, "filename", output.module ? "[name].mjs" : "[name].js");
|
||||||
F(output, "iife", () => !output.module);
|
F(output, "iife", () => !output.module);
|
||||||
D(output, "importFunctionName", "import");
|
D(output, "importFunctionName", "import");
|
||||||
|
|
|
@ -90,9 +90,9 @@ const versionDependent = (major, minor) => {
|
||||||
return () => /** @type {undefined} */ (undefined);
|
return () => /** @type {undefined} */ (undefined);
|
||||||
}
|
}
|
||||||
/** @type {number} */
|
/** @type {number} */
|
||||||
const nMajor = +major;
|
const nMajor = Number(major);
|
||||||
/** @type {number} */
|
/** @type {number} */
|
||||||
const nMinor = minor ? +minor : 0;
|
const nMinor = minor ? Number(minor) : 0;
|
||||||
return (vMajor, vMinor = 0) => {
|
return (vMajor, vMinor = 0) => {
|
||||||
return nMajor > vMajor || (nMajor === vMajor && nMinor >= vMinor);
|
return nMajor > vMajor || (nMajor === vMajor && nMinor >= vMinor);
|
||||||
};
|
};
|
||||||
|
@ -184,7 +184,7 @@ You can also more options via the 'target' option: 'browserslist' / 'browserslis
|
||||||
require: !asyncFlag,
|
require: !asyncFlag,
|
||||||
nodeBuiltins: true,
|
nodeBuiltins: true,
|
||||||
// v16.0.0, v14.18.0
|
// v16.0.0, v14.18.0
|
||||||
nodePrefixForCoreModules: +major < 15 ? v(14, 18) : v(16),
|
nodePrefixForCoreModules: Number(major) < 15 ? v(14, 18) : v(16),
|
||||||
global: true,
|
global: true,
|
||||||
document: false,
|
document: false,
|
||||||
fetchWasm: false,
|
fetchWasm: false,
|
||||||
|
@ -295,7 +295,7 @@ You can also more options via the 'target' option: 'browserslist' / 'browserslis
|
||||||
"EcmaScript in this version. Examples: es2020, es5.",
|
"EcmaScript in this version. Examples: es2020, es5.",
|
||||||
/^es(\d+)$/,
|
/^es(\d+)$/,
|
||||||
version => {
|
version => {
|
||||||
let v = +version;
|
let v = Number(version);
|
||||||
if (v < 1000) v = v + 2009;
|
if (v < 1000) v = v + 2009;
|
||||||
return {
|
return {
|
||||||
const: v >= 2015,
|
const: v >= 2015,
|
||||||
|
@ -366,7 +366,7 @@ const mergeTargetProperties = targetProperties => {
|
||||||
}
|
}
|
||||||
if (hasTrue || hasFalse)
|
if (hasTrue || hasFalse)
|
||||||
/** @type {TargetProperties} */
|
/** @type {TargetProperties} */
|
||||||
(result)[key] = hasFalse && hasTrue ? null : !!hasTrue;
|
(result)[key] = hasFalse && hasTrue ? null : Boolean(hasTrue);
|
||||||
}
|
}
|
||||||
return /** @type {TargetProperties} */ (result);
|
return /** @type {TargetProperties} */ (result);
|
||||||
};
|
};
|
||||||
|
|
|
@ -86,7 +86,7 @@ class CssLoadingRuntimeModule extends RuntimeModule {
|
||||||
* @returns {boolean} true, if the chunk has css
|
* @returns {boolean} true, if the chunk has css
|
||||||
*/
|
*/
|
||||||
(chunk, chunkGraph) =>
|
(chunk, chunkGraph) =>
|
||||||
!!chunkGraph.getChunkModulesIterableBySourceType(chunk, "css")
|
Boolean(chunkGraph.getChunkModulesIterableBySourceType(chunk, "css"))
|
||||||
);
|
);
|
||||||
const hasCssMatcher = compileBooleanMatcher(conditionMap);
|
const hasCssMatcher = compileBooleanMatcher(conditionMap);
|
||||||
|
|
||||||
|
|
|
@ -797,8 +797,10 @@ class CssModulesPlugin {
|
||||||
*/
|
*/
|
||||||
static chunkHasCss(chunk, chunkGraph) {
|
static chunkHasCss(chunk, chunkGraph) {
|
||||||
return (
|
return (
|
||||||
!!chunkGraph.getChunkModulesIterableBySourceType(chunk, "css") ||
|
Boolean(chunkGraph.getChunkModulesIterableBySourceType(chunk, "css")) ||
|
||||||
!!chunkGraph.getChunkModulesIterableBySourceType(chunk, "css-import")
|
Boolean(
|
||||||
|
chunkGraph.getChunkModulesIterableBySourceType(chunk, "css-import")
|
||||||
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -131,7 +131,7 @@ class AMDDefineDependencyParserPlugin {
|
||||||
} else {
|
} else {
|
||||||
dep = this.newRequireItemDependency(request);
|
dep = this.newRequireItemDependency(request);
|
||||||
dep.loc = /** @type {DependencyLocation} */ (expr.loc);
|
dep.loc = /** @type {DependencyLocation} */ (expr.loc);
|
||||||
dep.optional = !!parser.scope.inTry;
|
dep.optional = Boolean(parser.scope.inTry);
|
||||||
parser.state.current.addDependency(dep);
|
parser.state.current.addDependency(dep);
|
||||||
}
|
}
|
||||||
deps.push(dep);
|
deps.push(dep);
|
||||||
|
@ -141,7 +141,7 @@ class AMDDefineDependencyParserPlugin {
|
||||||
/** @type {Range} */ (param.range)
|
/** @type {Range} */ (param.range)
|
||||||
);
|
);
|
||||||
dep.loc = /** @type {DependencyLocation} */ (expr.loc);
|
dep.loc = /** @type {DependencyLocation} */ (expr.loc);
|
||||||
dep.optional = !!parser.scope.inTry;
|
dep.optional = Boolean(parser.scope.inTry);
|
||||||
parser.state.module.addPresentationalDependency(dep);
|
parser.state.module.addPresentationalDependency(dep);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -200,7 +200,7 @@ class AMDDefineDependencyParserPlugin {
|
||||||
/** @type {string} */ (param.string),
|
/** @type {string} */ (param.string),
|
||||||
param.range
|
param.range
|
||||||
);
|
);
|
||||||
dep.optional = !!parser.scope.inTry;
|
dep.optional = Boolean(parser.scope.inTry);
|
||||||
parser.state.current.addDependency(dep);
|
parser.state.current.addDependency(dep);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -230,7 +230,7 @@ class AMDDefineDependencyParserPlugin {
|
||||||
);
|
);
|
||||||
if (!dep) return;
|
if (!dep) return;
|
||||||
dep.loc = /** @type {DependencyLocation} */ (expr.loc);
|
dep.loc = /** @type {DependencyLocation} */ (expr.loc);
|
||||||
dep.optional = !!parser.scope.inTry;
|
dep.optional = Boolean(parser.scope.inTry);
|
||||||
parser.state.current.addDependency(dep);
|
parser.state.current.addDependency(dep);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -118,7 +118,7 @@ class AMDRequireDependenciesBlockParserPlugin {
|
||||||
} else {
|
} else {
|
||||||
dep = this.newRequireItemDependency(request);
|
dep = this.newRequireItemDependency(request);
|
||||||
dep.loc = /** @type {DependencyLocation} */ (expr.loc);
|
dep.loc = /** @type {DependencyLocation} */ (expr.loc);
|
||||||
dep.optional = !!parser.scope.inTry;
|
dep.optional = Boolean(parser.scope.inTry);
|
||||||
parser.state.current.addDependency(dep);
|
parser.state.current.addDependency(dep);
|
||||||
}
|
}
|
||||||
deps.push(dep);
|
deps.push(dep);
|
||||||
|
@ -128,7 +128,7 @@ class AMDRequireDependenciesBlockParserPlugin {
|
||||||
/** @type {Range} */ (param.range)
|
/** @type {Range} */ (param.range)
|
||||||
);
|
);
|
||||||
dep.loc = /** @type {DependencyLocation} */ (expr.loc);
|
dep.loc = /** @type {DependencyLocation} */ (expr.loc);
|
||||||
dep.optional = !!parser.scope.inTry;
|
dep.optional = Boolean(parser.scope.inTry);
|
||||||
parser.state.module.addPresentationalDependency(dep);
|
parser.state.module.addPresentationalDependency(dep);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -188,7 +188,7 @@ class AMDRequireDependenciesBlockParserPlugin {
|
||||||
param.range
|
param.range
|
||||||
);
|
);
|
||||||
dep.loc = /** @type {DependencyLocation} */ (expr.loc);
|
dep.loc = /** @type {DependencyLocation} */ (expr.loc);
|
||||||
dep.optional = !!parser.scope.inTry;
|
dep.optional = Boolean(parser.scope.inTry);
|
||||||
parser.state.current.addDependency(dep);
|
parser.state.current.addDependency(dep);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -218,7 +218,7 @@ class AMDRequireDependenciesBlockParserPlugin {
|
||||||
);
|
);
|
||||||
if (!dep) return;
|
if (!dep) return;
|
||||||
dep.loc = /** @type {DependencyLocation} */ (expr.loc);
|
dep.loc = /** @type {DependencyLocation} */ (expr.loc);
|
||||||
dep.optional = !!parser.scope.inTry;
|
dep.optional = Boolean(parser.scope.inTry);
|
||||||
parser.state.current.addDependency(dep);
|
parser.state.current.addDependency(dep);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -66,7 +66,7 @@ const getValueOfPropertyDescription = expr => {
|
||||||
const isTruthyLiteral = expr => {
|
const isTruthyLiteral = expr => {
|
||||||
switch (expr.type) {
|
switch (expr.type) {
|
||||||
case "Literal":
|
case "Literal":
|
||||||
return !!expr.value;
|
return Boolean(expr.value);
|
||||||
case "UnaryExpression":
|
case "UnaryExpression":
|
||||||
if (expr.operator === "!") return isFalsyLiteral(expr.argument);
|
if (expr.operator === "!") return isFalsyLiteral(expr.argument);
|
||||||
}
|
}
|
||||||
|
@ -211,7 +211,7 @@ class CommonJsExportsParserPlugin {
|
||||||
!parser.isStatementLevelExpression(expr)
|
!parser.isStatementLevelExpression(expr)
|
||||||
);
|
);
|
||||||
dep.loc = /** @type {DependencyLocation} */ (expr.loc);
|
dep.loc = /** @type {DependencyLocation} */ (expr.loc);
|
||||||
dep.optional = !!parser.scope.inTry;
|
dep.optional = Boolean(parser.scope.inTry);
|
||||||
parser.state.module.addDependency(dep);
|
parser.state.module.addDependency(dep);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -324,7 +324,7 @@ class CommonJsExportsParserPlugin {
|
||||||
/** @type {Range} */ (expr.range),
|
/** @type {Range} */ (expr.range),
|
||||||
base,
|
base,
|
||||||
members,
|
members,
|
||||||
!!call
|
Boolean(call)
|
||||||
);
|
);
|
||||||
dep.loc = /** @type {DependencyLocation} */ (expr.loc);
|
dep.loc = /** @type {DependencyLocation} */ (expr.loc);
|
||||||
parser.state.module.addDependency(dep);
|
parser.state.module.addDependency(dep);
|
||||||
|
|
|
@ -215,7 +215,7 @@ class CommonJsImportsParserPlugin {
|
||||||
options.unknownContextCritical &&
|
options.unknownContextCritical &&
|
||||||
"require function is used in a way in which dependencies cannot be statically extracted";
|
"require function is used in a way in which dependencies cannot be statically extracted";
|
||||||
dep.loc = /** @type {DependencyLocation} */ (expr.loc);
|
dep.loc = /** @type {DependencyLocation} */ (expr.loc);
|
||||||
dep.optional = !!parser.scope.inTry;
|
dep.optional = Boolean(parser.scope.inTry);
|
||||||
parser.state.current.addDependency(dep);
|
parser.state.current.addDependency(dep);
|
||||||
return true;
|
return true;
|
||||||
};
|
};
|
||||||
|
@ -238,7 +238,7 @@ class CommonJsImportsParserPlugin {
|
||||||
getContext()
|
getContext()
|
||||||
);
|
);
|
||||||
dep.loc = /** @type {DependencyLocation} */ (expr.loc);
|
dep.loc = /** @type {DependencyLocation} */ (expr.loc);
|
||||||
dep.optional = !!parser.scope.inTry;
|
dep.optional = Boolean(parser.scope.inTry);
|
||||||
parser.state.current.addDependency(dep);
|
parser.state.current.addDependency(dep);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -264,7 +264,7 @@ class CommonJsImportsParserPlugin {
|
||||||
);
|
);
|
||||||
if (!dep) return;
|
if (!dep) return;
|
||||||
dep.loc = /** @type {DependencyLocation} */ (expr.loc);
|
dep.loc = /** @type {DependencyLocation} */ (expr.loc);
|
||||||
dep.optional = !!parser.scope.inTry;
|
dep.optional = Boolean(parser.scope.inTry);
|
||||||
parser.state.current.addDependency(dep);
|
parser.state.current.addDependency(dep);
|
||||||
return true;
|
return true;
|
||||||
};
|
};
|
||||||
|
@ -401,7 +401,7 @@ class CommonJsImportsParserPlugin {
|
||||||
dep.asiSafe = !parser.isAsiPosition(
|
dep.asiSafe = !parser.isAsiPosition(
|
||||||
/** @type {Range} */ (expr.range)[0]
|
/** @type {Range} */ (expr.range)[0]
|
||||||
);
|
);
|
||||||
dep.optional = !!parser.scope.inTry;
|
dep.optional = Boolean(parser.scope.inTry);
|
||||||
dep.loc = /** @type {DependencyLocation} */ (expr.loc);
|
dep.loc = /** @type {DependencyLocation} */ (expr.loc);
|
||||||
parser.state.current.addDependency(dep);
|
parser.state.current.addDependency(dep);
|
||||||
return true;
|
return true;
|
||||||
|
@ -438,7 +438,7 @@ class CommonJsImportsParserPlugin {
|
||||||
dep.asiSafe = !parser.isAsiPosition(
|
dep.asiSafe = !parser.isAsiPosition(
|
||||||
/** @type {Range} */ (expr.range)[0]
|
/** @type {Range} */ (expr.range)[0]
|
||||||
);
|
);
|
||||||
dep.optional = !!parser.scope.inTry;
|
dep.optional = Boolean(parser.scope.inTry);
|
||||||
dep.loc = /** @type {DependencyLocation} */ (expr.callee.loc);
|
dep.loc = /** @type {DependencyLocation} */ (expr.callee.loc);
|
||||||
parser.state.current.addDependency(dep);
|
parser.state.current.addDependency(dep);
|
||||||
parser.walkExpressions(expr.arguments);
|
parser.walkExpressions(expr.arguments);
|
||||||
|
@ -509,7 +509,7 @@ class CommonJsImportsParserPlugin {
|
||||||
getContext()
|
getContext()
|
||||||
);
|
);
|
||||||
dep.loc = /** @type {DependencyLocation} */ (expr.loc);
|
dep.loc = /** @type {DependencyLocation} */ (expr.loc);
|
||||||
dep.optional = !!parser.scope.inTry;
|
dep.optional = Boolean(parser.scope.inTry);
|
||||||
dep.weak = weak;
|
dep.weak = weak;
|
||||||
parser.state.current.addDependency(dep);
|
parser.state.current.addDependency(dep);
|
||||||
return true;
|
return true;
|
||||||
|
@ -537,7 +537,7 @@ class CommonJsImportsParserPlugin {
|
||||||
);
|
);
|
||||||
if (!dep) return;
|
if (!dep) return;
|
||||||
dep.loc = /** @type {DependencyLocation} */ (expr.loc);
|
dep.loc = /** @type {DependencyLocation} */ (expr.loc);
|
||||||
dep.optional = !!parser.scope.inTry;
|
dep.optional = Boolean(parser.scope.inTry);
|
||||||
parser.state.current.addDependency(dep);
|
parser.state.current.addDependency(dep);
|
||||||
return true;
|
return true;
|
||||||
};
|
};
|
||||||
|
|
|
@ -293,7 +293,7 @@ module.exports = class ImportMetaContextDependencyParserPlugin {
|
||||||
/** @type {Range} */ (expr.range)
|
/** @type {Range} */ (expr.range)
|
||||||
);
|
);
|
||||||
dep.loc = /** @type {DependencyLocation} */ (expr.loc);
|
dep.loc = /** @type {DependencyLocation} */ (expr.loc);
|
||||||
dep.optional = !!parser.scope.inTry;
|
dep.optional = Boolean(parser.scope.inTry);
|
||||||
parser.state.current.addDependency(dep);
|
parser.state.current.addDependency(dep);
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
|
|
|
@ -292,7 +292,7 @@ class ImportParserPlugin {
|
||||||
attributes
|
attributes
|
||||||
);
|
);
|
||||||
dep.loc = /** @type {DependencyLocation} */ (expr.loc);
|
dep.loc = /** @type {DependencyLocation} */ (expr.loc);
|
||||||
dep.optional = !!parser.scope.inTry;
|
dep.optional = Boolean(parser.scope.inTry);
|
||||||
depBlock.addDependency(dep);
|
depBlock.addDependency(dep);
|
||||||
parser.state.current.addBlock(depBlock);
|
parser.state.current.addBlock(depBlock);
|
||||||
}
|
}
|
||||||
|
@ -327,7 +327,7 @@ class ImportParserPlugin {
|
||||||
);
|
);
|
||||||
if (!dep) return;
|
if (!dep) return;
|
||||||
dep.loc = /** @type {DependencyLocation} */ (expr.loc);
|
dep.loc = /** @type {DependencyLocation} */ (expr.loc);
|
||||||
dep.optional = !!parser.scope.inTry;
|
dep.optional = Boolean(parser.scope.inTry);
|
||||||
parser.state.current.addDependency(dep);
|
parser.state.current.addDependency(dep);
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
|
|
|
@ -56,7 +56,7 @@ module.exports = class RequireContextDependencyParserPlugin {
|
||||||
/** @type {Range} */ (expr.range)
|
/** @type {Range} */ (expr.range)
|
||||||
);
|
);
|
||||||
dep.loc = /** @type {DependencyLocation} */ (expr.loc);
|
dep.loc = /** @type {DependencyLocation} */ (expr.loc);
|
||||||
dep.optional = !!parser.scope.inTry;
|
dep.optional = Boolean(parser.scope.inTry);
|
||||||
parser.state.current.addDependency(dep);
|
parser.state.current.addDependency(dep);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -229,7 +229,7 @@ class LazyCompilationProxyModule extends Module {
|
||||||
]);
|
]);
|
||||||
const keepActive = Template.asString([
|
const keepActive = Template.asString([
|
||||||
`var dispose = client.keepAlive({ data: data, active: ${JSON.stringify(
|
`var dispose = client.keepAlive({ data: data, active: ${JSON.stringify(
|
||||||
!!block
|
Boolean(block)
|
||||||
)}, module: module, onError: onError });`
|
)}, module: module, onError: onError });`
|
||||||
]);
|
]);
|
||||||
let source;
|
let source;
|
||||||
|
|
|
@ -43,7 +43,7 @@ const avoidNumber = str => {
|
||||||
} else if (firstChar > 57) {
|
} else if (firstChar > 57) {
|
||||||
return str;
|
return str;
|
||||||
}
|
}
|
||||||
if (str === String(+str)) {
|
if (str === String(Number(str))) {
|
||||||
return `_${str}`;
|
return `_${str}`;
|
||||||
}
|
}
|
||||||
return str;
|
return str;
|
||||||
|
|
|
@ -59,7 +59,9 @@ const JavascriptParser = require("./JavascriptParser");
|
||||||
const chunkHasJs = (chunk, chunkGraph) => {
|
const chunkHasJs = (chunk, chunkGraph) => {
|
||||||
if (chunkGraph.getNumberOfEntryModules(chunk) > 0) return true;
|
if (chunkGraph.getNumberOfEntryModules(chunk) > 0) return true;
|
||||||
|
|
||||||
return !!chunkGraph.getChunkModulesIterableBySourceType(chunk, "javascript");
|
return Boolean(
|
||||||
|
chunkGraph.getChunkModulesIterableBySourceType(chunk, "javascript")
|
||||||
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -1190,6 +1190,7 @@ class JavascriptParser extends Parser {
|
||||||
} else if (expr.operator === "~") {
|
} else if (expr.operator === "~") {
|
||||||
return handleConstOperation(v => ~v);
|
return handleConstOperation(v => ~v);
|
||||||
} else if (expr.operator === "+") {
|
} else if (expr.operator === "+") {
|
||||||
|
// eslint-disable-next-line no-implicit-coercion
|
||||||
return handleConstOperation(v => +v);
|
return handleConstOperation(v => +v);
|
||||||
} else if (expr.operator === "-") {
|
} else if (expr.operator === "-") {
|
||||||
return handleConstOperation(v => -v);
|
return handleConstOperation(v => -v);
|
||||||
|
|
|
@ -71,7 +71,7 @@ module.exports.enable = parserState => {
|
||||||
*/
|
*/
|
||||||
module.exports.isEnabled = parserState => {
|
module.exports.isEnabled = parserState => {
|
||||||
const state = parserStateMap.get(parserState);
|
const state = parserStateMap.get(parserState);
|
||||||
return !!state;
|
return Boolean(state);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -138,8 +138,8 @@ const parseCacheControl = (cacheControl, requestTime) => {
|
||||||
if (cacheControl) {
|
if (cacheControl) {
|
||||||
const parsed = parseKeyValuePairs(cacheControl);
|
const parsed = parseKeyValuePairs(cacheControl);
|
||||||
if (parsed["no-cache"]) storeCache = storeLock = false;
|
if (parsed["no-cache"]) storeCache = storeLock = false;
|
||||||
if (parsed["max-age"] && !isNaN(+parsed["max-age"])) {
|
if (parsed["max-age"] && !isNaN(Number(parsed["max-age"]))) {
|
||||||
validUntil = requestTime + +parsed["max-age"] * 1000;
|
validUntil = requestTime + Number(parsed["max-age"]) * 1000;
|
||||||
}
|
}
|
||||||
if (parsed["must-revalidate"]) validUntil = 0;
|
if (parsed["must-revalidate"]) validUntil = 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -62,7 +62,7 @@ class SerializerMiddleware {
|
||||||
static isLazy(fn, target) {
|
static isLazy(fn, target) {
|
||||||
if (typeof fn !== "function") return false;
|
if (typeof fn !== "function") return false;
|
||||||
const t = fn[LAZY_TARGET];
|
const t = fn[LAZY_TARGET];
|
||||||
return target ? t === target : !!t;
|
return target ? t === target : Boolean(t);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -97,8 +97,8 @@ class ConsumeSharedPlugin {
|
||||||
? item.strictVersion
|
? item.strictVersion
|
||||||
: item.import !== false && !item.singleton,
|
: item.import !== false && !item.singleton,
|
||||||
packageName: item.packageName,
|
packageName: item.packageName,
|
||||||
singleton: !!item.singleton,
|
singleton: Boolean(item.singleton),
|
||||||
eager: !!item.eager
|
eager: Boolean(item.eager)
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -62,7 +62,7 @@ class ProvideSharedPlugin {
|
||||||
shareKey: item.shareKey,
|
shareKey: item.shareKey,
|
||||||
version: item.version,
|
version: item.version,
|
||||||
shareScope: item.shareScope || options.shareScope || "default",
|
shareScope: item.shareScope || options.shareScope || "default",
|
||||||
eager: !!item.eager
|
eager: Boolean(item.eager)
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
|
@ -1909,13 +1909,13 @@ const ASSETS_GROUPERS = {
|
||||||
return exclude
|
return exclude
|
||||||
? {
|
? {
|
||||||
type: "assets by status",
|
type: "assets by status",
|
||||||
[name]: !!key,
|
[name]: Boolean(key),
|
||||||
filteredChildren: assets.length,
|
filteredChildren: assets.length,
|
||||||
...assetGroup(children, assets)
|
...assetGroup(children, assets)
|
||||||
}
|
}
|
||||||
: {
|
: {
|
||||||
type: "assets by status",
|
type: "assets by status",
|
||||||
[name]: !!key,
|
[name]: Boolean(key),
|
||||||
children,
|
children,
|
||||||
...assetGroup(children, assets)
|
...assetGroup(children, assets)
|
||||||
};
|
};
|
||||||
|
@ -1983,7 +1983,7 @@ const ASSETS_GROUPERS = {
|
||||||
return {
|
return {
|
||||||
type: "assets by info",
|
type: "assets by info",
|
||||||
info: {
|
info: {
|
||||||
[name]: !!key
|
[name]: Boolean(key)
|
||||||
},
|
},
|
||||||
children,
|
children,
|
||||||
...assetGroup(children, assets)
|
...assetGroup(children, assets)
|
||||||
|
@ -2053,7 +2053,7 @@ const MODULES_GROUPERS = type => ({
|
||||||
createGroup: (key, children, modules) => {
|
createGroup: (key, children, modules) => {
|
||||||
return {
|
return {
|
||||||
type,
|
type,
|
||||||
[name]: !!key,
|
[name]: Boolean(key),
|
||||||
...(exclude ? { filteredChildren: modules.length } : { children }),
|
...(exclude ? { filteredChildren: modules.length } : { children }),
|
||||||
...moduleGroup(children, modules)
|
...moduleGroup(children, modules)
|
||||||
};
|
};
|
||||||
|
|
|
@ -18,7 +18,7 @@ const quoteMeta = str => {
|
||||||
* @returns {string} string
|
* @returns {string} string
|
||||||
*/
|
*/
|
||||||
const toSimpleString = str => {
|
const toSimpleString = str => {
|
||||||
if (`${+str}` === str) {
|
if (`${Number(str)}` === str) {
|
||||||
return str;
|
return str;
|
||||||
}
|
}
|
||||||
return JSON.stringify(str);
|
return JSON.stringify(str);
|
||||||
|
|
|
@ -16,7 +16,7 @@ const propertyAccess = (properties, start = 0) => {
|
||||||
let str = "";
|
let str = "";
|
||||||
for (let i = start; i < properties.length; i++) {
|
for (let i = start; i < properties.length; i++) {
|
||||||
const p = properties[i];
|
const p = properties[i];
|
||||||
if (`${+p}` === p) {
|
if (`${Number(p)}` === p) {
|
||||||
str += `[${p}]`;
|
str += `[${p}]`;
|
||||||
} else if (SAFE_IDENTIFIER.test(p) && !RESERVED_IDENTIFIER.has(p)) {
|
} else if (SAFE_IDENTIFIER.test(p) && !RESERVED_IDENTIFIER.has(p)) {
|
||||||
str += `.${p}`;
|
str += `.${p}`;
|
||||||
|
|
|
@ -48,7 +48,9 @@ class ImportScriptsChunkLoadingPlugin {
|
||||||
if (onceForChunkSet.has(chunk)) return;
|
if (onceForChunkSet.has(chunk)) return;
|
||||||
onceForChunkSet.add(chunk);
|
onceForChunkSet.add(chunk);
|
||||||
if (!isEnabledForChunk(chunk)) return;
|
if (!isEnabledForChunk(chunk)) return;
|
||||||
const withCreateScriptUrl = !!compilation.outputOptions.trustedTypes;
|
const withCreateScriptUrl = Boolean(
|
||||||
|
compilation.outputOptions.trustedTypes
|
||||||
|
);
|
||||||
set.add(RuntimeGlobals.moduleFactoriesAddOnly);
|
set.add(RuntimeGlobals.moduleFactoriesAddOnly);
|
||||||
set.add(RuntimeGlobals.hasOwnProperty);
|
set.add(RuntimeGlobals.hasOwnProperty);
|
||||||
if (withCreateScriptUrl) {
|
if (withCreateScriptUrl) {
|
||||||
|
|
|
@ -95,7 +95,7 @@ const exec = (n, options = {}) => {
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
const supportsEsm = +process.versions.modules >= 83;
|
const supportsEsm = Number(process.versions.modules) >= 83;
|
||||||
|
|
||||||
describe("BuildDependencies", () => {
|
describe("BuildDependencies", () => {
|
||||||
beforeEach(done => {
|
beforeEach(done => {
|
||||||
|
|
|
@ -315,8 +315,10 @@ describe("HotModuleReplacementPlugin", () => {
|
||||||
Object.keys(stats.compilation.assets).forEach(key => {
|
Object.keys(stats.compilation.assets).forEach(key => {
|
||||||
foundUpdates =
|
foundUpdates =
|
||||||
foundUpdates ||
|
foundUpdates ||
|
||||||
!!key.match(
|
Boolean(
|
||||||
/static\/webpack\/\[name\]\/entry\.js\..*?\.hot-update\.js/
|
key.match(
|
||||||
|
/static\/webpack\/\[name\]\/entry\.js\..*?\.hot-update\.js/
|
||||||
|
)
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -69,6 +69,7 @@ describe("JavascriptParser", () => {
|
||||||
"member expression": [
|
"member expression": [
|
||||||
function () {
|
function () {
|
||||||
test[memberExpr];
|
test[memberExpr];
|
||||||
|
// eslint-disable-next-line no-implicit-coercion
|
||||||
test[+memberExpr];
|
test[+memberExpr];
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|
|
@ -23,8 +23,8 @@ const referenceComparer = (a, b) => {
|
||||||
if (pA < pB) return -1;
|
if (pA < pB) return -1;
|
||||||
if (pA > pB) return 1;
|
if (pA > pB) return 1;
|
||||||
} else {
|
} else {
|
||||||
const nA = +pA;
|
const nA = Number(pA);
|
||||||
const nB = +pB;
|
const nB = Number(pB);
|
||||||
if (nA < nB) return -1;
|
if (nA < nB) return -1;
|
||||||
if (nA > nB) return 1;
|
if (nA > nB) return 1;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
module.exports = function supportsRequireInModule() {
|
module.exports = function supportsRequireInModule() {
|
||||||
// eslint-disable-next-line n/no-unsupported-features/node-builtins
|
// eslint-disable-next-line n/no-unsupported-features/node-builtins
|
||||||
return !!require("module").createRequire;
|
return Boolean(require("module").createRequire);
|
||||||
};
|
};
|
||||||
|
|
|
@ -11,7 +11,10 @@ module.exports = {
|
||||||
compiler => {
|
compiler => {
|
||||||
const base = {
|
const base = {
|
||||||
DEFINE: "{}",
|
DEFINE: "{}",
|
||||||
RUN: DefinePlugin.runtimeValue(() => +(currentWatchStep.step || 0), [])
|
RUN: DefinePlugin.runtimeValue(
|
||||||
|
() => Number(currentWatchStep.step || 0),
|
||||||
|
[]
|
||||||
|
)
|
||||||
};
|
};
|
||||||
const defines = [
|
const defines = [
|
||||||
{
|
{
|
||||||
|
@ -40,7 +43,9 @@ module.exports = {
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
compiler.hooks.compilation.tap("webpack.config", (...args) => {
|
compiler.hooks.compilation.tap("webpack.config", (...args) => {
|
||||||
const plugin = new DefinePlugin(defines[+(currentWatchStep.step || 0)]);
|
const plugin = new DefinePlugin(
|
||||||
|
defines[Number(currentWatchStep.step || 0)]
|
||||||
|
);
|
||||||
plugin.apply(
|
plugin.apply(
|
||||||
/** @type {any} */ ({
|
/** @type {any} */ ({
|
||||||
hooks: {
|
hooks: {
|
||||||
|
|
|
@ -148,7 +148,7 @@ const printData = async (data, indent) => {
|
||||||
await printData(innerData, `${indent} `);
|
await printData(innerData, `${indent} `);
|
||||||
printLine(`}`);
|
printLine(`}`);
|
||||||
} else {
|
} else {
|
||||||
printLine(`${item}`);
|
printLine(String(item));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
const refCounters = Array.from(referencedValuesCounters);
|
const refCounters = Array.from(referencedValuesCounters);
|
||||||
|
|
Loading…
Reference in New Issue