Skip to content

Commit

Permalink
Merge pull request #7432 from webpack/add_brackets
Browse files Browse the repository at this point in the history
Add brackets for multiline if/for statements
  • Loading branch information
sokra committed May 29, 2018
2 parents 75f12fb + 2a9452e commit 8e6a012
Show file tree
Hide file tree
Showing 84 changed files with 1,208 additions and 549 deletions.
4 changes: 3 additions & 1 deletion lib/AmdMainTemplatePlugin.js
Expand Up @@ -71,7 +71,9 @@ class AmdMainTemplatePlugin {
}

mainTemplate.hooks.globalHashPaths.tap("AmdMainTemplatePlugin", paths => {
if (this.name) paths.push(this.name);
if (this.name) {
paths.push(this.name);
}
return paths;
});

Expand Down
4 changes: 3 additions & 1 deletion lib/BannerPlugin.js
Expand Up @@ -13,7 +13,9 @@ const validateOptions = require("schema-utils");
const schema = require("../schemas/plugins/BannerPlugin.json");

const wrapComment = str => {
if (!str.includes("\n")) return Template.toComment(str);
if (!str.includes("\n")) {
return Template.toComment(str);
}
return `/*!\n * ${str
.replace(/\*\//g, "* /")
.split("\n")
Expand Down
25 changes: 14 additions & 11 deletions lib/BasicEvaluatedExpression.js
Expand Up @@ -90,20 +90,21 @@ class BasicEvaluatedExpression {

asBool() {
if (this.truthy) return true;
else if (this.falsy) return false;
else if (this.isBoolean()) return this.bool;
else if (this.isNull()) return false;
else if (this.isString()) return this.string !== "";
else if (this.isNumber()) return this.number !== 0;
else if (this.isRegExp()) return true;
else if (this.isArray()) return true;
else if (this.isConstArray()) return true;
else if (this.isWrapped())
if (this.falsy) return false;
if (this.isBoolean()) return this.bool;
if (this.isNull()) return false;
if (this.isString()) return this.string !== "";
if (this.isNumber()) return this.number !== 0;
if (this.isRegExp()) return true;
if (this.isArray()) return true;
if (this.isConstArray()) return true;
if (this.isWrapped()) {
return (this.prefix && this.prefix.asBool()) ||
(this.postfix && this.postfix.asBool())
? true
: undefined;
else if (this.isTemplateString()) {
}
if (this.isTemplateString()) {
for (const quasi of this.quasis) {
if (quasi.asBool()) return true;
}
Expand Down Expand Up @@ -165,7 +166,9 @@ class BasicEvaluatedExpression {
this.type = TypeConditional;
this.options = [];
}
for (const item of options) this.options.push(item);
for (const item of options) {
this.options.push(item);
}
return this;
}

Expand Down
17 changes: 12 additions & 5 deletions lib/CachePlugin.js
Expand Up @@ -26,12 +26,17 @@ class CachePlugin {
(childCompiler, compilerName, compilerIndex) => {
if (cache) {
let childCache;
if (!cache.children) cache.children = {};
if (!cache.children[compilerName])
if (!cache.children) {
cache.children = {};
}
if (!cache.children[compilerName]) {
cache.children[compilerName] = [];
if (cache.children[compilerName][compilerIndex])
}
if (cache.children[compilerName][compilerIndex]) {
childCache = cache.children[compilerName][compilerIndex];
else cache.children[compilerName].push((childCache = {}));
} else {
cache.children[compilerName].push((childCache = {}));
}
registerCacheToCompiler(childCompiler, childCache);
}
}
Expand All @@ -43,7 +48,9 @@ class CachePlugin {
this.watching = true;
});
compiler.hooks.run.tapAsync("CachePlugin", (compiler, callback) => {
if (!compiler._lastCompilationFileDependencies) return callback();
if (!compiler._lastCompilationFileDependencies) {
return callback();
}
const fs = compiler.inputFileSystem;
const fileTs = (compiler.fileTimestamps = new Map());
asyncLib.forEach(
Expand Down
60 changes: 44 additions & 16 deletions lib/Chunk.js
Expand Up @@ -378,13 +378,14 @@ class Chunk {
otherChunk._groups.clear();

if (this.name && otherChunk.name) {
if (this.name.length !== otherChunk.name.length)
if (this.name.length !== otherChunk.name.length) {
this.name =
this.name.length < otherChunk.name.length
? this.name
: otherChunk.name;
else
} else {
this.name = this.name < otherChunk.name ? this.name : otherChunk.name;
}
}

return true;
Expand Down Expand Up @@ -420,12 +421,16 @@ class Chunk {
for (const chunkGroup of queue) {
if (a.isInGroup(chunkGroup)) continue;
if (chunkGroup.isInitial()) return false;
for (const parent of chunkGroup.parentsIterable) queue.add(parent);
for (const parent of chunkGroup.parentsIterable) {
queue.add(parent);
}
}
return true;
};

if (this.preventIntegration || otherChunk.preventIntegration) return false;
if (this.preventIntegration || otherChunk.preventIntegration) {
return false;
}

if (this.hasRuntime() !== otherChunk.hasRuntime()) {
if (this.hasRuntime()) {
Expand All @@ -436,7 +441,11 @@ class Chunk {
return false;
}
}
if (this.hasEntryModule() || otherChunk.hasEntryModule()) return false;

if (this.hasEntryModule() || otherChunk.hasEntryModule()) {
return false;
}

return true;
}

Expand Down Expand Up @@ -509,14 +518,20 @@ class Chunk {
);

for (const chunkGroup of this.groupsIterable) {
for (const child of chunkGroup.childrenIterable) queue.add(child);
for (const child of chunkGroup.childrenIterable) {
queue.add(child);
}
}

for (const chunkGroup of queue) {
for (const chunk of chunkGroup.chunks) {
if (!initialChunks.has(chunk)) chunks.add(chunk);
if (!initialChunks.has(chunk)) {
chunks.add(chunk);
}
}
for (const child of chunkGroup.childrenIterable) {
queue.add(child);
}
for (const child of chunkGroup.childrenIterable) queue.add(child);
}

return chunks;
Expand All @@ -530,11 +545,14 @@ class Chunk {
for (const chunk of this.getAllAsyncChunks()) {
chunkHashMap[chunk.id] = realHash ? chunk.hash : chunk.renderedHash;
for (const key of Object.keys(chunk.contentHash)) {
if (!chunkContentHashMap[key])
if (!chunkContentHashMap[key]) {
chunkContentHashMap[key] = Object.create(null);
}
chunkContentHashMap[key][chunk.id] = chunk.contentHash[key];
}
if (chunk.name) chunkNameMap[chunk.id] = chunk.name;
if (chunk.name) {
chunkNameMap[chunk.id] = chunk.name;
}
}

return {
Expand Down Expand Up @@ -572,12 +590,16 @@ class Chunk {
const cmp = b.order - a.order;
if (cmp !== 0) return cmp;
// TOOD webpack 5 remove this check of compareTo
if (a.group.compareTo) return a.group.compareTo(b.group);
if (a.group.compareTo) {
return a.group.compareTo(b.group);
}
return 0;
});
result[name] = Array.from(
list.reduce((set, item) => {
for (const chunk of item.group.chunks) set.add(chunk.id);
for (const chunk of item.group.chunks) {
set.add(chunk.id);
}
return set;
}, new Set())
);
Expand All @@ -592,8 +614,9 @@ class Chunk {
const data = chunk.getChildIdsByOrders();
for (const key of Object.keys(data)) {
let chunkMap = chunkMaps[key];
if (chunkMap === undefined)
if (chunkMap === undefined) {
chunkMaps[key] = chunkMap = Object.create(null);
}
chunkMap[chunk.id] = data[key];
}
}
Expand Down Expand Up @@ -642,12 +665,17 @@ class Chunk {
if (!chunksProcessed.has(chunk)) {
chunksProcessed.add(chunk);
if (!filterChunkFn || filterChunkFn(chunk)) {
for (const module of chunk.modulesIterable)
if (filterFn(module)) return true;
for (const module of chunk.modulesIterable) {
if (filterFn(module)) {
return true;
}
}
}
}
}
for (const child of chunkGroup.childrenIterable) queue.add(child);
for (const child of chunkGroup.childrenIterable) {
queue.add(child);
}
}
return false;
}
Expand Down
18 changes: 13 additions & 5 deletions lib/ChunkGroup.js
Expand Up @@ -259,7 +259,9 @@ class ChunkGroup {

setParents(newParents) {
this._parents.clear();
for (const p of newParents) this._parents.add(p);
for (const p of newParents) {
this._parents.add(p);
}
}

getNumberOfParents() {
Expand Down Expand Up @@ -418,7 +420,9 @@ class ChunkGroup {
if (key.endsWith("Order")) {
const name = key.substr(0, key.length - "Order".length);
let list = lists.get(name);
if (list === undefined) lists.set(name, (list = []));
if (list === undefined) {
lists.set(name, (list = []));
}
list.push({
order: childGroup.options[key],
group: childGroup
Expand All @@ -433,7 +437,9 @@ class ChunkGroup {
const cmp = b.order - a.order;
if (cmp !== 0) return cmp;
// TOOD webpack 5 remove this check of compareTo
if (a.group.compareTo) return a.group.compareTo(b.group);
if (a.group.compareTo) {
return a.group.compareTo(b.group);
}
return 0;
});
result[name] = list.map(i => i.group);
Expand All @@ -444,20 +450,22 @@ class ChunkGroup {
checkConstraints() {
const chunk = this;
for (const child of chunk._children) {
if (!child._parents.has(chunk))
if (!child._parents.has(chunk)) {
throw new Error(
`checkConstraints: child missing parent ${chunk.debugId} -> ${
child.debugId
}`
);
}
}
for (const parentChunk of chunk._parents) {
if (!parentChunk._children.has(chunk))
if (!parentChunk._children.has(chunk)) {
throw new Error(
`checkConstraints: parent missing child ${parentChunk.debugId} <- ${
chunk.debugId
}`
);
}
}
}
}
Expand Down

0 comments on commit 8e6a012

Please sign in to comment.