replace Object.assign with object spread

This commit is contained in:
Tobias Koppers 2019-06-19 13:16:05 +02:00
parent d675f4e3ee
commit b2e7837288
41 changed files with 281 additions and 343 deletions

View File

@ -567,7 +567,7 @@ class Compilation {
optionsOrPreset = { preset: optionsOrPreset };
}
if (typeof optionsOrPreset === "object" && optionsOrPreset !== null) {
const options = Object.assign({}, optionsOrPreset);
const options = { ...optionsOrPreset };
if (options.preset !== undefined) {
this.hooks.statsPreset.for(options.preset).call(options, context);
}
@ -2528,12 +2528,10 @@ class Compilation {
*/
getPath(filename, data) {
if (!data.hash) {
data = Object.assign(
{
hash: this.hash
},
data
);
data = {
hash: this.hash,
...data
};
}
return this.mainTemplate.getAssetPath(filename, data);
}

View File

@ -93,7 +93,8 @@ class ContextModule extends Module {
// Info from Factory
this.resolveDependencies = resolveDependencies;
/** @type {ContextModuleOptions} */
this.options = Object.assign({}, options, {
this.options = ({
...options,
resource: resource,
resourceQuery: resourceQuery
});
@ -324,11 +325,10 @@ class ContextModule extends Module {
// for the lazy-once mode create a new async dependency block
// and add that block to this context
if (dependencies.length > 0) {
const block = new AsyncDependenciesBlock(
Object.assign({}, this.options.groupOptions, {
name: this.options.chunkName
})
);
const block = new AsyncDependenciesBlock({
...this.options.groupOptions,
name: this.options.chunkName
});
for (const dep of dependencies) {
block.addDependency(dep);
}
@ -360,9 +360,10 @@ class ContextModule extends Module {
);
}
const block = new AsyncDependenciesBlock(
Object.assign({}, this.options.groupOptions, {
{
...this.options.groupOptions,
name: chunkName
}),
},
dep.loc,
dep.userRequest
);

View File

@ -49,17 +49,15 @@ module.exports = class ContextModuleFactory extends ModuleFactory {
const missingDependencies = new Set();
const contextDependencies = new Set();
this.hooks.beforeResolve.callAsync(
Object.assign(
{
context: context,
dependencies: dependencies,
resolveOptions,
fileDependencies,
missingDependencies,
contextDependencies
},
dependency.options
),
{
context: context,
dependencies: dependencies,
resolveOptions,
fileDependencies,
missingDependencies,
contextDependencies,
...dependency.options
},
(err, beforeResolveResult) => {
if (err) return callback(err);
@ -145,17 +143,15 @@ module.exports = class ContextModuleFactory extends ModuleFactory {
if (err) return callback(err);
this.hooks.afterResolve.callAsync(
Object.assign(
{
addon:
loadersPrefix +
result[1].join("!") +
(result[1].length > 0 ? "!" : ""),
resource: result[0],
resolveDependencies: this.resolveDependencies.bind(this)
},
beforeResolveResult
),
{
addon:
loadersPrefix +
result[1].join("!") +
(result[1].length > 0 ? "!" : ""),
resource: result[0],
resolveDependencies: this.resolveDependencies.bind(this),
...beforeResolveResult
},
(err, result) => {
if (err) return callback(err);

View File

@ -87,7 +87,7 @@ class DelegatedModule extends Module {
* @returns {void}
*/
build(options, compilation, resolver, fs, callback) {
this.buildMeta = Object.assign({}, this.delegateData.buildMeta);
this.buildMeta = { ...this.delegateData.buildMeta };
this.buildInfo = {};
this.dependencies.length = 0;
this.delegatedSourceDependency = new DelegatedSourceDependency(

View File

@ -38,14 +38,10 @@ class DelegatedPlugin {
);
compiler.hooks.compile.tap("DelegatedPlugin", ({ normalModuleFactory }) => {
new DelegatedModuleFactoryPlugin(
Object.assign(
{
associatedObjectForCache: compiler.root
},
this.options
)
).apply(normalModuleFactory);
new DelegatedModuleFactoryPlugin({
associatedObjectForCache: compiler.root,
...this.options
}).apply(normalModuleFactory);
});
}
}

View File

@ -2409,11 +2409,10 @@ class JavascriptParser {
static parse(code, options) {
const type = options ? options.sourceType : "module";
const parserOptions = Object.assign(
Object.create(null),
defaultParserOptions,
options
);
const parserOptions = {
...defaultParserOptions,
...options
};
if (type === "auto") {
parserOptions.sourceType = "module";

View File

@ -60,17 +60,15 @@ ModuleFilenameHelpers.createFilename = (
options,
{ requestShortener, chunkGraph }
) => {
const opts = Object.assign(
{
namespace: "",
moduleFilenameTemplate: ""
},
typeof options === "object"
const opts = {
namespace: "",
moduleFilenameTemplate: "",
...(typeof options === "object"
? options
: {
moduleFilenameTemplate: options
}
);
})
};
let absoluteResourcePath;
let hash;

View File

@ -47,13 +47,12 @@ class MultiStats {
? options.children[idx]
: options.children;
return stat.compilation.createStatsOptions(
Object.assign(
{},
baseOptions,
childOptions && typeof childOptions === "object"
{
...baseOptions,
...(childOptions && typeof childOptions === "object"
? childOptions
: { preset: childOptions }
),
: { preset: childOptions })
},
context
);
});
@ -101,11 +100,12 @@ class MultiStats {
if (!j.errors) return arr;
return arr.concat(
j.errors.map(obj => {
return Object.assign({}, obj, {
return {
...obj,
compilerPath: obj.compilerPath
? `${j.name}.${obj.compilerPath}`
: j.name
});
};
})
);
}, []);
@ -113,11 +113,12 @@ class MultiStats {
if (!j.warnings) return arr;
return arr.concat(
j.warnings.map(obj => {
return Object.assign({}, obj, {
return {
...obj,
compilerPath: obj.compilerPath
? `${j.name}.${obj.compilerPath}`
: j.name
});
};
})
);
}, []);

View File

@ -38,7 +38,7 @@ class NodeStuffPlugin {
let localOptions = options;
if (parserOptions.node) {
localOptions = Object.assign({}, localOptions, parserOptions.node);
localOptions = { ...localOptions, ...parserOptions.node };
}
const setModuleConstant = (expressionName, fn) => {

View File

@ -468,7 +468,7 @@ class NormalModule extends Module {
*/
markModuleAsErrored(error) {
// Restore build meta from successful build to keep importing state
this.buildMeta = Object.assign({}, this._lastSuccessfulBuildMeta);
this.buildMeta = { ...this._lastSuccessfulBuildMeta };
this.error = error;
this.errors.push(error);
}

View File

@ -32,7 +32,7 @@ class OptionsDefaulter {
}
process(options) {
options = Object.assign({}, options);
options = { ...options };
for (let name in this.defaults) {
switch (this.config[name]) {
case undefined:

View File

@ -110,7 +110,7 @@ class ProgressPlugin {
options = options || {};
validateOptions(schema, options, "Progress Plugin");
options = Object.assign({}, ProgressPlugin.defaultOptions, options);
options = { ...ProgressPlugin.defaultOptions, ...options };
this.profile = options.profile;
this.handler = options.handler;

View File

@ -67,7 +67,7 @@ module.exports = class ResolverFactory {
* @returns {Resolver} the resolver
*/
_create(type, resolveOptions) {
const originalResolveOptions = Object.assign({}, resolveOptions);
const originalResolveOptions = { ...resolveOptions };
resolveOptions = this.hooks.resolveOptions.for(type).call(resolveOptions);
const resolver = Factory.createResolver(resolveOptions);
if (!resolver) {

View File

@ -37,7 +37,7 @@ class Watching {
aggregateTimeout: watchOptions
};
} else if (watchOptions && typeof watchOptions === "object") {
this.watchOptions = Object.assign({}, watchOptions);
this.watchOptions = { ...watchOptions };
} else {
this.watchOptions = {};
}

View File

@ -617,33 +617,27 @@ class WebpackOptionsApply extends OptionsApply {
compiler.resolverFactory.hooks.resolveOptions
.for("normal")
.tap("WebpackOptionsApply", resolveOptions => {
return Object.assign(
{
fileSystem: compiler.inputFileSystem
},
cachedCleverMerge(options.resolve, resolveOptions)
);
return {
fileSystem: compiler.inputFileSystem,
...cachedCleverMerge(options.resolve, resolveOptions)
};
});
compiler.resolverFactory.hooks.resolveOptions
.for("context")
.tap("WebpackOptionsApply", resolveOptions => {
return Object.assign(
{
fileSystem: compiler.inputFileSystem,
resolveToContext: true
},
cachedCleverMerge(options.resolve, resolveOptions)
);
return {
fileSystem: compiler.inputFileSystem,
resolveToContext: true,
...cachedCleverMerge(options.resolve, resolveOptions)
};
});
compiler.resolverFactory.hooks.resolveOptions
.for("loader")
.tap("WebpackOptionsApply", resolveOptions => {
return Object.assign(
{
fileSystem: compiler.inputFileSystem
},
cachedCleverMerge(options.resolveLoader, resolveOptions)
);
return {
fileSystem: compiler.inputFileSystem,
...cachedCleverMerge(options.resolveLoader, resolveOptions)
};
});
compiler.hooks.afterResolvers.call(compiler);
return options;

View File

@ -35,7 +35,7 @@ class WebpackOptionsDefaulter extends OptionsDefaulter {
constructor() {
super();
this.set("experiments", "call", value => Object.assign({}, value));
this.set("experiments", "call", value => ({ ...value }));
this.set("experiments.mjs", false);
this.set("experiments.importAwait", false);
this.set("experiments.importAsync", false);
@ -60,7 +60,7 @@ class WebpackOptionsDefaulter extends OptionsDefaulter {
if (!value) {
return false;
}
value = Object.assign({}, value);
value = { ...value };
if (value.type === "filesystem") {
if (value.name === undefined) {
value.name =
@ -95,7 +95,7 @@ class WebpackOptionsDefaulter extends OptionsDefaulter {
this.set("context", process.cwd());
this.set("target", "web");
this.set("module", "call", value => Object.assign({}, value));
this.set("module", "call", value => ({ ...value }));
this.set("module.unknownContextRequest", ".");
this.set("module.unknownContextRegExp", false);
this.set("module.unknownContextRecursive", true);
@ -159,7 +159,7 @@ class WebpackOptionsDefaulter extends OptionsDefaulter {
} else if (typeof value !== "object") {
return {};
} else {
return Object.assign({}, value);
return { ...value };
}
});
@ -236,7 +236,7 @@ class WebpackOptionsDefaulter extends OptionsDefaulter {
if (typeof value === "boolean") {
return value;
} else {
return Object.assign({}, value);
return { ...value };
}
});
this.set("node.global", "make", options => {
@ -277,7 +277,7 @@ class WebpackOptionsDefaulter extends OptionsDefaulter {
(!isProductionLikeMode(options) || !isWebLikeTarget(options))
)
return false;
return Object.assign({}, value);
return { ...value };
});
this.set("performance.maxAssetSize", 250000);
this.set("performance.maxEntrypointSize", 250000);
@ -285,7 +285,7 @@ class WebpackOptionsDefaulter extends OptionsDefaulter {
isProductionLikeMode(options) ? "warning" : false
);
this.set("optimization", "call", value => Object.assign({}, value));
this.set("optimization", "call", value => ({ ...value }));
this.set("optimization.removeAvailableModules", true);
this.set("optimization.removeEmptyChunks", true);
this.set("optimization.mergeDuplicateChunks", true);
@ -404,7 +404,7 @@ class WebpackOptionsDefaulter extends OptionsDefaulter {
}
});
this.set("resolve", "call", value => Object.assign({}, value));
this.set("resolve", "call", value => ({ ...value }));
this.set("resolve.cache", "make", options => !!options.cache);
this.set("resolve.modules", ["node_modules"]);
this.set("resolve.extensions", "make", options =>
@ -436,7 +436,7 @@ class WebpackOptionsDefaulter extends OptionsDefaulter {
}
});
this.set("resolveLoader", "call", value => Object.assign({}, value));
this.set("resolveLoader", "call", value => ({ ...value }));
this.set("resolveLoader.cache", "make", options => !!options.cache);
this.set("resolveLoader.mainFields", ["loader", "main"]);
this.set("resolveLoader.extensions", [".js"]);

View File

@ -240,16 +240,11 @@ class WebpackOptionsValidationError extends WebpackError {
0,
err.children.length - 1
);
return WebpackOptionsValidationError.formatValidationError(
Object.assign({}, lastChild, {
children: remainingChildren,
parentSchema: Object.assign(
{},
err.parentSchema,
lastChild.parentSchema
)
})
);
return WebpackOptionsValidationError.formatValidationError({
...lastChild,
children: remainingChildren,
parentSchema: { ...err.parentSchema, ...lastChild.parentSchema }
});
}
const children = filterChildren(err.children);
if (children.length === 1) {

View File

@ -42,18 +42,17 @@ class ResolverCachePlugin {
request,
callback
) => {
const newRequest = Object.assign(
{
_ResolverCachePluginCacheMiss: true
},
request
);
const newResolveContext = Object.assign({}, resolveContext, {
const newRequest = {
_ResolverCachePluginCacheMiss: true,
...request
};
const newResolveContext = {
...resolveContext,
stack: new Set(),
missing: new Set(),
fileDependencies: new Set(),
contextDependencies: new Set()
});
};
const propagate = key => {
if (resolveContext[key]) {
for (const dep of newResolveContext[key]) {

View File

@ -35,7 +35,7 @@ class ContextDependency extends Dependency {
this.options &&
(this.options.regExp.global || this.options.regExp.sticky)
) {
this.options = Object.assign({}, this.options, { regExp: null });
this.options = { ...this.options, regExp: null };
this.hadGlobalOrStickyRegExp = true;
}

View File

@ -93,15 +93,13 @@ exports.create = (Dep, range, param, expr, options, contextOptions, parser) => {
`^${quotemeta(prefix)}${innerRegExp}${quotemeta(postfix)}$`
);
const dep = new Dep(
Object.assign(
{
request: context + query,
recursive: options.wrappedContextRecursive,
regExp,
mode: "sync"
},
contextOptions
),
{
request: context + query,
recursive: options.wrappedContextRecursive,
regExp,
mode: "sync",
...contextOptions
},
range,
valueRange
);
@ -174,15 +172,13 @@ exports.create = (Dep, range, param, expr, options, contextOptions, parser) => {
)}$`
);
const dep = new Dep(
Object.assign(
{
request: context + query,
recursive: options.wrappedContextRecursive,
regExp,
mode: "sync"
},
contextOptions
),
{
request: context + query,
recursive: options.wrappedContextRecursive,
regExp,
mode: "sync",
...contextOptions
},
range,
valueRange
);
@ -214,15 +210,13 @@ exports.create = (Dep, range, param, expr, options, contextOptions, parser) => {
return dep;
} else {
const dep = new Dep(
Object.assign(
{
request: options.exprContextRequest,
recursive: options.exprContextRecursive,
regExp: options.exprContextRegExp,
mode: "sync"
},
contextOptions
),
{
request: options.exprContextRequest,
recursive: options.exprContextRecursive,
regExp: options.exprContextRegExp,
mode: "sync",
...contextOptions
},
range,
param.range
);

View File

@ -175,9 +175,10 @@ class ImportParserPlugin {
parser.state.current.addDependency(dep);
} else {
const depBlock = new ImportDependenciesBlock(
Object.assign(groupOptions, {
{
...groupOptions,
name: chunkName
}),
},
expr.loc,
param.string,
expr.range

View File

@ -23,15 +23,13 @@ class HashedModuleIdsPlugin {
validateOptions(schema, options || {}, "Hashed Module Ids Plugin");
/** @type {HashedModuleIdsPluginOptions} */
this.options = Object.assign(
{
context: null,
hashFunction: "md4",
hashDigest: "base64",
hashDigestLength: 4
},
options
);
this.options = {
context: null,
hashFunction: "md4",
hashDigest: "base64",
hashDigestLength: 4,
...options
};
}
apply(compiler) {

View File

@ -38,7 +38,7 @@ module.exports = class NodeSourcePlugin {
let localOptions = options;
if (parserOptions.node) {
localOptions = Object.assign({}, localOptions, parserOptions.node);
localOptions = { ...localOptions, ...parserOptions.node };
}
if (localOptions.global) {

View File

@ -1231,9 +1231,10 @@ class ConcatenatedModule extends Module {
moduleToInfoMap
);
const innerContext = Object.assign({}, context, {
const innerContext = {
...context,
dependencyTemplates: innerDependencyTemplates
});
};
const set = new Set([
RuntimeGlobals.exports, // TODO check if really used

View File

@ -11,12 +11,10 @@ const { STAGE_ADVANCED } = require("../OptimizationStages");
class RuntimeChunkPlugin {
constructor(options) {
this.options = Object.assign(
{
name: entrypoint => `runtime~${entrypoint.name}`
},
options
);
this.options = {
name: entrypoint => `runtime~${entrypoint.name}`,
...options
};
}
/**

View File

@ -239,7 +239,7 @@ const normalizeSizes = value => {
javascript: value
};
} else if (typeof value === "object" && value !== null) {
return Object.assign({}, value);
return { ...value };
} else {
return {};
}
@ -383,9 +383,7 @@ const normalizeCacheGroups = cacheGroups => {
if (result) {
const groups = Array.isArray(result) ? result : [result];
for (const group of groups) {
results.push(
createCacheGroupSource(Object.assign({ key }, group))
);
results.push(createCacheGroupSource({ key, ...group }));
}
}
} else {
@ -393,9 +391,7 @@ const normalizeCacheGroups = cacheGroups => {
checkTest(option.test, module, context) &&
checkModuleType(option.type, module)
) {
results.push(
createCacheGroupSource(Object.assign({ key }, option))
);
results.push(createCacheGroupSource({ key, ...option }));
}
}
}
@ -1006,10 +1002,7 @@ module.exports = class SplitChunksPlugin {
hasNonZeroSizes(item.cacheGroup.minRemainingSize)
) {
const chunk = validChunks[0];
const chunkSizes = Object.assign(
{},
chunkGraph.getChunkModulesSizes(chunk)
);
const chunkSizes = { ...chunkGraph.getChunkModulesSizes(chunk) };
for (const key of Object.keys(item.sizes)) {
chunkSizes[key] -= item.sizes[key];
}

View File

@ -261,32 +261,30 @@ class ObjectMiddleware extends SerializerMiddleware {
let currentPosTypeLookup = 0;
const objectTypeLookup = new Map();
const cycleStack = new Set();
const ctx = Object.assign(
{
write(value) {
process(value);
},
snapshot() {
return {
length: result.length,
cycleStackSize: cycleStack.size,
referenceableSize: referenceable.size,
currentPos,
objectTypeLookupSize: objectTypeLookup.size,
currentPosTypeLookup
};
},
rollback(snapshot) {
result.length = snapshot.length;
setSetSize(cycleStack, snapshot.cycleStackSize);
setMapSize(referenceable, snapshot.referenceableSize);
currentPos = snapshot.currentPos;
setMapSize(objectTypeLookup, snapshot.objectTypeLookupSize);
currentPosTypeLookup = snapshot.currentPosTypeLookup;
}
const ctx = {
write(value) {
process(value);
},
context
);
snapshot() {
return {
length: result.length,
cycleStackSize: cycleStack.size,
referenceableSize: referenceable.size,
currentPos,
objectTypeLookupSize: objectTypeLookup.size,
currentPosTypeLookup
};
},
rollback(snapshot) {
result.length = snapshot.length;
setSetSize(cycleStack, snapshot.cycleStackSize);
setMapSize(referenceable, snapshot.referenceableSize);
currentPos = snapshot.currentPos;
setMapSize(objectTypeLookup, snapshot.objectTypeLookupSize);
currentPosTypeLookup = snapshot.currentPosTypeLookup;
},
...context
};
const process = item => {
// check if we can emit a reference
const ref = referenceable.get(item);
@ -394,14 +392,12 @@ class ObjectMiddleware extends SerializerMiddleware {
let currentPosTypeLookup = 0;
const objectTypeLookup = new Map();
const result = [];
const ctx = Object.assign(
{
read() {
return decodeValue();
}
const ctx = {
read() {
return decodeValue();
},
context
);
...context
};
const decodeValue = () => {
const item = read();

View File

@ -11,7 +11,7 @@ class Serializer {
}
serialize(obj, context) {
const ctx = Object.assign({}, context, this.context);
const ctx = { ...context, ...this.context };
return new Promise((resolve, reject) =>
resolve(
this.middlewares.reduce((last, middleware) => {
@ -32,7 +32,7 @@ class Serializer {
}
deserialize(context) {
const ctx = Object.assign({}, context, this.context);
const ctx = { ...context, ...this.context };
return Promise.resolve().then(() =>
this.middlewares.reduceRight((last, middleware) => {
if (last instanceof Promise)

View File

@ -50,6 +50,7 @@ const {
* @property {string} modulesSort
* @property {string} assetsSort
* @property {Function[]} excludeAssets
* @property {Function[]} excludeModules
* @property {Function[]} warningsFilter
* @property {number} maxModules
* @property {any} _env
@ -708,33 +709,25 @@ const FILTER = {
if (excluded) return false;
}
},
"compilation.modules": Object.assign(
{
excludeModules: EXCLUDE_MODULES_FILTER("module"),
"!orphanModules": (module, { compilation: { chunkGraph } }) => {
if (chunkGraph.getNumberOfModuleChunks(module) === 0) return false;
}
"compilation.modules": ({
excludeModules: EXCLUDE_MODULES_FILTER("module"),
"!orphanModules": (module, { compilation: { chunkGraph } }) => {
if (chunkGraph.getNumberOfModuleChunks(module) === 0) return false;
},
BASE_MODULES_FILTER
),
"module.modules": Object.assign(
{
excludeModules: EXCLUDE_MODULES_FILTER("nested")
},
BASE_MODULES_FILTER
),
"chunk.modules": Object.assign(
{
excludeModules: EXCLUDE_MODULES_FILTER("chunk")
},
BASE_MODULES_FILTER
),
"chunk.rootModules": Object.assign(
{
excludeModules: EXCLUDE_MODULES_FILTER("root-of-chunk")
},
BASE_MODULES_FILTER
)
...BASE_MODULES_FILTER
}),
"module.modules": ({
excludeModules: EXCLUDE_MODULES_FILTER("nested"),
...BASE_MODULES_FILTER
}),
"chunk.modules": ({
excludeModules: EXCLUDE_MODULES_FILTER("chunk"),
...BASE_MODULES_FILTER
}),
"chunk.rootModules": ({
excludeModules: EXCLUDE_MODULES_FILTER("root-of-chunk"),
...BASE_MODULES_FILTER
})
};
/** @type {Record<string, (module: Module, context: UsualContext, options: UsualOptions, idx: number, i: number) => boolean | undefined>} */

View File

@ -73,11 +73,10 @@ const SIMPLE_PRINTERS = {
"compilation.entrypoints": (entrypoints, context, printer) =>
Array.isArray(entrypoints)
? undefined
: printer.print(
context.type,
Object.values(entrypoints),
Object.assign({}, context, { chunkGroupKind: "Entrypoint" })
),
: printer.print(context.type, Object.values(entrypoints), ({
...context,
chunkGroupKind: "Entrypoint"
})),
"compilation.namedChunkGroups": (namedChunkGroups, context, printer) => {
if (!Array.isArray(namedChunkGroups)) {
const {
@ -90,11 +89,10 @@ const SIMPLE_PRINTERS = {
!Object.prototype.hasOwnProperty.call(entrypoints, group.name)
);
}
return printer.print(
context.type,
chunkGroups,
Object.assign({}, context, { chunkGroupKind: "Chunk Group" })
);
return printer.print(context.type, chunkGroups, ({
...context,
chunkGroupKind: "Chunk Group"
}));
}
},
"compilation.assetsByChunkName": () => "",

View File

@ -90,10 +90,11 @@ class StatsFactory {
}
create(type, data, baseContext) {
const context = Object.assign({}, baseContext, {
const context = {
...baseContext,
type,
[type]: data
});
};
if (Array.isArray(data)) {
// run filter on unsorted items
const items = forEachLevelFilter(
@ -125,9 +126,10 @@ class StatsFactory {
// for each item
const resultItems = items2.map((item, i) => {
const itemContext = Object.assign({}, context, {
const itemContext = {
...context,
_index: i
});
};
// run getItemName
const itemName = forEachLevel(this.hooks.getItemName, `${type}[]`, h =>

View File

@ -62,10 +62,11 @@ class StatsPrinter {
}
print(type, object, baseContext) {
const context = Object.assign({}, baseContext, {
const context = {
...baseContext,
type,
[type]: object
});
};
let printResult = forEachLevel(this.hooks.print, type, hook =>
hook.call(object, context)
@ -77,9 +78,10 @@ class StatsPrinter {
h.call(sortedItems, context)
);
const printedItems = sortedItems.map((item, i) => {
const itemContext = Object.assign({}, context, {
const itemContext = {
...context,
_index: i
});
};
const itemName = forEachLevel(
this.hooks.getItemName,
`${type}[]`,
@ -105,15 +107,12 @@ class StatsPrinter {
h.call(elements, context)
);
const printedElements = elements.map(element => {
const content = this.print(
`${type}.${element}`,
object[element],
Object.assign({}, context, {
_parent: object,
_element: element,
[element]: object[element]
})
);
const content = this.print(`${type}.${element}`, object[element], {
...context,
_parent: object,
_element: element,
[element]: object[element]
});
return { element, content };
});
printResult = forEachLevel(this.hooks.printElements, type, h =>

View File

@ -41,7 +41,7 @@ const cachedCleverMerge = (first, second) => {
* @returns {object} merged object of first and second object
*/
const cleverMerge = (first, second) => {
const newObject = Object.assign({}, first);
const newObject = { ...first };
for (const key of Object.keys(second)) {
if (!(key in newObject)) {
newObject[key] = second[key];

View File

@ -92,7 +92,7 @@ const defaults = {
async function compile(options) {
const stats = await new Promise((resolve, reject) => {
const compiler = webpack(Object.assign({}, defaults.options, options));
const compiler = webpack({ ...defaults.options, ...options });
if (options.mode === "production") {
if (options.optimization) options.optimization.minimize = true;
else options.optimization = { minimize: true };

View File

@ -97,11 +97,10 @@ const describeCases = config => {
mode: config.mode || "none",
optimization: config.mode
? NO_EMIT_ON_ERRORS_OPTIMIZATIONS
: Object.assign(
{},
config.optimization,
DEFAULT_OPTIMIZATIONS
),
: {
...config.optimization,
...DEFAULT_OPTIMIZATIONS
},
performance: {
hints: false
},
@ -109,15 +108,11 @@ const describeCases = config => {
__dirname: "mock",
__filename: "mock"
},
cache:
config.cache &&
Object.assign(
{
loglevel: "warning",
cacheDirectory
},
config.cache
),
cache: config.cache && {
loglevel: "warning",
cacheDirectory,
...config.cache
},
output: {
pathinfo: true,
path: outputDirectory,

View File

@ -6,20 +6,26 @@ module.exports = function(content) {
json.imports,
function(url, callback) {
this.loadModule(url, function(err, source, map, module) {
if(err) {
if (err) {
return callback(err);
}
callback(null, JSON.parse(source));
});
}.bind(this),
function(err, results) {
if(err) {
if (err) {
return cb(err);
}
// Combine all the results into one object and return it
cb(null, "module.exports = " + JSON.stringify(results.reduce(function(prev, result) {
return Object.assign({}, prev, result);
}, json)));
cb(
null,
"module.exports = " +
JSON.stringify(
results.reduce(function(prev, result) {
return { ...prev, ...result };
}, json)
)
);
}
);
};

View File

@ -2,13 +2,11 @@
const { compareLocations } = require("../lib/util/comparators");
const createPosition = overrides => {
return Object.assign(
{
line: 10,
column: 5
},
overrides
);
return {
line: 10,
column: 5,
...overrides
};
};
const createLocation = (start, end, index) => {

View File

@ -46,11 +46,8 @@ module.exports = [
["should not filter"],
[/should not filter/],
[warnings => false]
].map(filter =>
Object.assign({}, baseConfig, {
name: Array.isArray(filter) ? `[${filter}]` : `${filter}`,
stats: Object.assign({}, baseConfig.stats, {
warningsFilter: filter
})
})
);
].map(filter => ({
...baseConfig,
name: Array.isArray(filter) ? `[${filter}]` : `${filter}`,
stats: { ...baseConfig.stats, warningsFilter: filter }
}));

View File

@ -16,31 +16,25 @@ const base = {
}
};
module.exports = [
Object.assign(
{
entry: "./a.js",
output: {
filename: "a-[name]-[chunkhash].js"
}
{
entry: "./a.js",
output: {
filename: "a-[name]-[chunkhash].js"
},
base
),
Object.assign(
{
entry: "./b.js",
output: {
filename: "b-[name]-[chunkhash].js"
}
...base
},
{
entry: "./b.js",
output: {
filename: "b-[name]-[chunkhash].js"
},
base
),
Object.assign(
{
entry: "./c.js",
output: {
filename: "c-[name]-[chunkhash].js"
}
...base
},
{
entry: "./c.js",
output: {
filename: "c-[name]-[chunkhash].js"
},
base
)
...base
}
];

View File

@ -32,16 +32,12 @@ const config = {
};
module.exports = [
Object.assign(
{
stats: Object.assign({ entrypoints: false, chunkGroups: true }, stats)
},
config
),
Object.assign(
{
stats: Object.assign({ entrypoints: true, chunkGroups: true }, stats)
},
config
)
{
stats: { entrypoints: false, chunkGroups: true, ...stats },
...config
},
{
stats: { entrypoints: true, chunkGroups: true, ...stats },
...config
}
];

View File

@ -18,7 +18,8 @@ const baseConfig = {
]
};
const withoutNamedEntry = Object.assign({}, baseConfig, {
const withoutNamedEntry = {
...baseConfig,
name: "base",
entry: {
main1: "./main1"
@ -26,9 +27,10 @@ const withoutNamedEntry = Object.assign({}, baseConfig, {
optimization: {
runtimeChunk: "single"
}
});
};
const withNamedEntry = Object.assign({}, baseConfig, {
const withNamedEntry = {
...baseConfig,
name: "manifest is named entry",
entry: {
main1: "./main1",
@ -39,6 +41,6 @@ const withNamedEntry = Object.assign({}, baseConfig, {
name: "manifest"
}
}
});
};
module.exports = [withoutNamedEntry, withNamedEntry];