Skip to content

Commit 16f6718

Browse files
committed
Merge pull request webpack#1230 from thaiat/feat-beautifier
Feat beautifier
2 parents fddb66e + 0a340f2 commit 16f6718

File tree

159 files changed

+2241
-2101
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

159 files changed

+2241
-2101
lines changed

.eslintrc

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,27 @@
22
"env": {
33
"node": true
44
},
5+
"plugins": [
6+
"nodeca"
7+
],
58
"rules": {
69
"strict": 0,
10+
"camelcase": 0,
711
"curly": 0,
12+
"indent": [0, "tab"],
13+
"nodeca/indent": [2, "tabs", 1 ],
814
"eol-last": 1,
915
"no-shadow": 0,
1016
"no-redeclare": 1,
1117
"no-extra-bind": 1,
18+
"no-empty": 0,
19+
"no-process-exit": 1,
1220
"no-underscore-dangle": 0,
1321
"no-use-before-define": 0,
22+
"no-unused-vars": 0,
1423
"consistent-return": 0,
1524
"no-inner-declarations": 1,
16-
"no-loop-func": 1
25+
"no-loop-func": 1,
26+
"space-before-function-paren": [2, "never"]
1727
}
1828
}

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@
66
/examples/*/js
77
/coverage
88
.DS_Store
9-
*.log
9+
*.log

.jsbeautifyrc

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
{
2+
"js": {
3+
"allowed_file_extensions": ["js", "json", "jshintrc", "jsbeautifyrc"],
4+
"brace_style": "collapse",
5+
"break_chained_methods": false,
6+
"e4x": true,
7+
"eval_code": false,
8+
"end_with_newline": true,
9+
"indent_char": "\t",
10+
"indent_level": 0,
11+
"indent_size": 1,
12+
"indent_with_tabs": false,
13+
"jslint_happy": false,
14+
"jslint_happy_align_switch_case": true,
15+
"space_after_anon_function": false,
16+
"keep_array_indentation": false,
17+
"keep_function_indentation": false,
18+
"max_preserve_newlines": 2,
19+
"preserve_newlines": true,
20+
"space_before_conditional": false,
21+
"space_in_paren": false,
22+
"unescape_strings": false,
23+
"wrap_line_length": 0
24+
}
25+
}

lib/APIPlugin.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@ var BasicEvaluatedExpression = require("./BasicEvaluatedExpression");
77

88
var NullFactory = require("./NullFactory");
99

10-
function APIPlugin() {
11-
}
10+
function APIPlugin() {}
1211
module.exports = APIPlugin;
1312

1413
var REPLACEMENTS = {
@@ -25,8 +24,7 @@ var REPLACEMENT_TYPES = {
2524
__webpack_modules__: "object", // eslint-disable-line camelcase
2625
__webpack_chunk_load__: "function" // eslint-disable-line camelcase
2726
};
28-
var IGNORES = [
29-
];
27+
var IGNORES = [];
3028
APIPlugin.prototype.apply = function(compiler) {
3129
compiler.plugin("compilation", function(compilation) {
3230
compilation.dependencyFactories.set(ConstDependency, new NullFactory());
@@ -48,4 +46,4 @@ APIPlugin.prototype.apply = function(compiler) {
4846
return true;
4947
});
5048
});
51-
};
49+
};

lib/AbstractPlugin.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ AbstractPlugin.create = function(plugins) {
1616
};
1717

1818
AbstractPlugin.prototype.apply = function(object) {
19-
for(var name in this._plugins) {
19+
for (var name in this._plugins) {
2020
object.plugin(name, this._plugins[name]);
2121
}
2222
};

lib/AmdMainTemplatePlugin.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,13 @@ AmdMainTemplatePlugin.prototype.apply = function(compilation) {
2020
var externalsArguments = externals.map(function(m) {
2121
return "__WEBPACK_EXTERNAL_MODULE_" + m.id + "__";
2222
}).join(", ");
23-
if(this.name) {
23+
if (this.name) {
2424
var name = mainTemplate.applyPluginsWaterfall("asset-path", this.name, {
2525
hash: hash,
2626
chunk: chunk
2727
});
2828
return new ConcatSource("define(" + JSON.stringify(name) + ", " + externalsDepsArray + ", function(" + externalsArguments + ") { return ", source, "});");
29-
} else if(externalsArguments) {
29+
} else if (externalsArguments) {
3030
return new ConcatSource("define(" + externalsDepsArray + ", function(" + externalsArguments + ") { return ", source, "});");
3131
} else {
3232
return new ConcatSource("define(function() { return ", source, "});");

lib/ArrayMap.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,17 @@ function ArrayMap() {
99
module.exports = ArrayMap;
1010

1111
ArrayMap.prototype.get = function(key) {
12-
for(var i = 0; i < this.keys.length; i++) {
13-
if(this.keys[i] === key) {
12+
for (var i = 0; i < this.keys.length; i++) {
13+
if (this.keys[i] === key) {
1414
return this.values[i];
1515
}
1616
}
1717
return;
1818
};
1919

2020
ArrayMap.prototype.set = function(key, value) {
21-
for(var i = 0; i < this.keys.length; i++) {
22-
if(this.keys[i] === key) {
21+
for (var i = 0; i < this.keys.length; i++) {
22+
if (this.keys[i] === key) {
2323
this.values[i] = value;
2424
return this;
2525
}
@@ -30,8 +30,8 @@ ArrayMap.prototype.set = function(key, value) {
3030
};
3131

3232
ArrayMap.prototype.remove = function(key) {
33-
for(var i = 0; i < this.keys.length; i++) {
34-
if(this.keys[i] === key) {
33+
for (var i = 0; i < this.keys.length; i++) {
34+
if (this.keys[i] === key) {
3535
this.keys.splice(i, 1);
3636
this.values.splice(i, 1);
3737
return true;
@@ -42,7 +42,7 @@ ArrayMap.prototype.remove = function(key) {
4242

4343
ArrayMap.prototype.clone = function() {
4444
var newMap = new ArrayMap();
45-
for(var i = 0; i < this.keys.length; i++) {
45+
for (var i = 0; i < this.keys.length; i++) {
4646
newMap.keys.push(this.keys[i]);
4747
newMap.values.push(this.values[i]);
4848
}

lib/AutomaticPrefetchPlugin.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@ var async = require("async");
66
var PrefetchDependency = require("./dependencies/PrefetchDependency");
77
var NormalModule = require("./NormalModule");
88

9-
function AutomaticPrefetchPlugin() {
10-
}
9+
function AutomaticPrefetchPlugin() {}
1110
module.exports = AutomaticPrefetchPlugin;
1211
AutomaticPrefetchPlugin.prototype.apply = function(compiler) {
1312
compiler.plugin("compilation", function(compilation, params) {
@@ -28,7 +27,7 @@ AutomaticPrefetchPlugin.prototype.apply = function(compiler) {
2827
callback();
2928
});
3029
compiler.plugin("make", function(compilation, callback) {
31-
if(!lastModules) return callback();
30+
if (!lastModules) return callback();
3231
async.forEach(lastModules, function(m, callback) {
3332
compilation.prefetch(m.context || compiler.context, new PrefetchDependency(m.request), callback);
3433
}, callback);

lib/BannerPlugin.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ var ConcatSource = require("webpack-core/lib/ConcatSource");
66
var ModuleFilenameHelpers = require("./ModuleFilenameHelpers");
77

88
function wrapComment(str) {
9-
if(str.indexOf("\n") < 0) return "/*! " + str + " */";
9+
if (str.indexOf("\n") < 0) return "/*! " + str + " */";
1010
return "/*!\n * " + str.split("\n").join("\n * ") + "\n */";
1111
}
1212

@@ -23,7 +23,7 @@ BannerPlugin.prototype.apply = function(compiler) {
2323
compiler.plugin("compilation", function(compilation) {
2424
compilation.plugin("optimize-chunk-assets", function(chunks, callback) {
2525
chunks.forEach(function(chunk) {
26-
if(options.entryOnly && !chunk.initial) return;
26+
if (options.entryOnly && !chunk.initial) return;
2727
chunk.files.filter(ModuleFilenameHelpers.matchObject.bind(undefined, options)).forEach(function(file) {
2828
compilation.assets[file] = new ConcatSource(banner, "\n", compilation.assets[file]);
2929
});

lib/BasicEvaluatedExpression.js

Lines changed: 23 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -38,27 +38,27 @@ BasicEvaluatedExpression.prototype.isWrapped = function() {
3838
return Object.prototype.hasOwnProperty.call(this, "prefix") || Object.prototype.hasOwnProperty.call(this, "postfix");
3939
};
4040
BasicEvaluatedExpression.prototype.asBool = function() {
41-
if(this.isBoolean()) return this.bool;
42-
else if(this.isNull()) return false;
43-
else if(this.isString()) return !!this.string;
44-
else if(this.isNumber()) return !!this.number;
45-
else if(this.isRegExp()) return true;
46-
else if(this.isArray()) return true;
47-
else if(this.isConstArray()) return true;
48-
else if(this.isWrapped()) return this.prefix && this.prefix.asBool() || this.postfix && this.postfix.asBool() ? true : undefined;
41+
if (this.isBoolean()) return this.bool;
42+
else if (this.isNull()) return false;
43+
else if (this.isString()) return !!this.string;
44+
else if (this.isNumber()) return !!this.number;
45+
else if (this.isRegExp()) return true;
46+
else if (this.isArray()) return true;
47+
else if (this.isConstArray()) return true;
48+
else if (this.isWrapped()) return this.prefix && this.prefix.asBool() || this.postfix && this.postfix.asBool() ? true : undefined;
4949
return undefined;
5050
};
5151
BasicEvaluatedExpression.prototype.set = function(value) {
52-
if(typeof value === "string") return this.setString(value);
53-
if(typeof value === "number") return this.setNumber(value);
54-
if(typeof value === "boolean") return this.setBoolean(value);
55-
if(value === null) return this.setNull();
56-
if(value instanceof RegExp) return this.setRegExp(value);
57-
if(Array.isArray(value)) return this.setArray(value);
52+
if (typeof value === "string") return this.setString(value);
53+
if (typeof value === "number") return this.setNumber(value);
54+
if (typeof value === "boolean") return this.setBoolean(value);
55+
if (value === null) return this.setNull();
56+
if (value instanceof RegExp) return this.setRegExp(value);
57+
if (Array.isArray(value)) return this.setArray(value);
5858
return this;
5959
};
6060
BasicEvaluatedExpression.prototype.setString = function(str) {
61-
if(str === null)
61+
if (str === null)
6262
delete this.string;
6363
else
6464
this.string = str;
@@ -69,28 +69,28 @@ BasicEvaluatedExpression.prototype.setNull = function() {
6969
return this;
7070
};
7171
BasicEvaluatedExpression.prototype.setNumber = function(num) {
72-
if(num === null)
72+
if (num === null)
7373
delete this.number;
7474
else
7575
this.number = num;
7676
return this;
7777
};
7878
BasicEvaluatedExpression.prototype.setBoolean = function(bool) {
79-
if(bool === null)
79+
if (bool === null)
8080
delete this.bool;
8181
else
8282
this.bool = bool;
8383
return this;
8484
};
8585
BasicEvaluatedExpression.prototype.setRegExp = function(regExp) {
86-
if(regExp === null)
86+
if (regExp === null)
8787
delete this.regExp;
8888
else
8989
this.regExp = regExp;
9090
return this;
9191
};
9292
BasicEvaluatedExpression.prototype.setIdentifier = function(identifier) {
93-
if(identifier === null)
93+
if (identifier === null)
9494
delete this.identifier;
9595
else
9696
this.identifier = identifier;
@@ -107,28 +107,28 @@ BasicEvaluatedExpression.prototype.unsetWrapped = function() {
107107
return this;
108108
};
109109
BasicEvaluatedExpression.prototype.setOptions = function(options) {
110-
if(options === null)
110+
if (options === null)
111111
delete this.options;
112112
else
113113
this.options = options;
114114
return this;
115115
};
116116
BasicEvaluatedExpression.prototype.setItems = function(items) {
117-
if(items === null)
117+
if (items === null)
118118
delete this.items;
119119
else
120120
this.items = items;
121121
return this;
122122
};
123123
BasicEvaluatedExpression.prototype.setArray = function(array) {
124-
if(array === null)
124+
if (array === null)
125125
delete this.array;
126126
else
127127
this.array = array;
128128
return this;
129129
};
130130
BasicEvaluatedExpression.prototype.addOptions = function(options) {
131-
if(!this.options) this.options = [];
131+
if (!this.options) this.options = [];
132132
options.forEach(function(item) {
133133
this.options.push(item);
134134
}, this);
@@ -138,6 +138,3 @@ BasicEvaluatedExpression.prototype.setRange = function(range) {
138138
this.range = range;
139139
return this;
140140
};
141-
142-
143-

lib/CachePlugin.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ function CachePlugin(cache) {
1010
module.exports = CachePlugin;
1111

1212
CachePlugin.prototype.apply = function(compiler) {
13-
if(Array.isArray(compiler.compilers)) {
13+
if (Array.isArray(compiler.compilers)) {
1414
compiler.compilers.forEach(function(c, idx) {
1515
c.apply(new CachePlugin(this.cache[idx] = this.cache[idx] || {}));
1616
}, this);
@@ -19,13 +19,13 @@ CachePlugin.prototype.apply = function(compiler) {
1919
compilation.cache = this.cache;
2020
}.bind(this));
2121
compiler.plugin("run", function(compiler, callback) {
22-
if(!compiler._lastCompilationFileDependencies) return callback();
22+
if (!compiler._lastCompilationFileDependencies) return callback();
2323
var fs = compiler.inputFileSystem;
2424
var fileTs = compiler.fileTimestamps = {};
2525
async.forEach(compiler._lastCompilationFileDependencies, function(file, callback) {
2626
fs.stat(file, function(err, stat) {
27-
if(err) {
28-
if(err.code === "ENOENT") return callback();
27+
if (err) {
28+
if (err.code === "ENOENT") return callback();
2929
return callback(err);
3030
}
3131

@@ -40,4 +40,4 @@ CachePlugin.prototype.apply = function(compiler) {
4040
callback();
4141
});
4242
}
43-
};
43+
};

0 commit comments

Comments
 (0)