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