webpack 1.12.13 → 1.13.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/EvalSourceMapDevToolModuleTemplatePlugin.js +2 -2
- package/lib/HotModuleReplacement.runtime.js +57 -36
- package/lib/LibManifestPlugin.js +3 -1
- package/lib/Parser.js +152 -49
- package/lib/SourceMapDevToolPlugin.js +2 -2
- package/lib/WebpackOptionsApply.js +33 -4
- package/lib/dependencies/AMDDefineDependency.js +1 -1
- package/lib/dependencies/AMDRequireDependenciesBlock.js +1 -0
- package/lib/dependencies/AMDRequireDependenciesBlockParserPlugin.js +14 -5
- package/lib/dependencies/AMDRequireDependency.js +2 -2
- package/lib/dependencies/LoaderPlugin.js +2 -3
- package/lib/dependencies/getFunctionExpression.js +4 -2
- package/lib/optimize/UglifyJsPlugin.js +3 -0
- package/lib/webpack.js +4 -1
- package/package.json +2 -2
@@ -7,7 +7,7 @@ var ModuleFilenameHelpers = require("./ModuleFilenameHelpers");
|
|
7
7
|
|
8
8
|
function EvalSourceMapDevToolModuleTemplatePlugin(compilation, options, sourceMapComment, moduleFilenameTemplate) {
|
9
9
|
this.compilation = compilation;
|
10
|
-
this.sourceMapComment = sourceMapComment || "
|
10
|
+
this.sourceMapComment = sourceMapComment || "//# sourceMappingURL=[url]";
|
11
11
|
this.moduleFilenameTemplate = moduleFilenameTemplate || "webpack:///[resource-path]?[hash]";
|
12
12
|
this.options = options;
|
13
13
|
}
|
@@ -57,7 +57,7 @@ EvalSourceMapDevToolModuleTemplatePlugin.prototype.apply = function(moduleTempla
|
|
57
57
|
}
|
58
58
|
sourceMap.sourceRoot = "";
|
59
59
|
sourceMap.file = module.id + ".js";
|
60
|
-
var footer = self.sourceMapComment.replace(/\[url\]/g, "data:application/json;base64," + new Buffer(JSON.stringify(sourceMap)).toString("base64"));
|
60
|
+
var footer = self.sourceMapComment.replace(/\[url\]/g, "data:application/json;charset=utf-8;base64," + new Buffer(JSON.stringify(sourceMap)).toString("base64"));
|
61
61
|
source.__EvalSourceMapDevToolData = new RawSource("eval(" + JSON.stringify(content + footer) + ");");
|
62
62
|
return source.__EvalSourceMapDevToolData;
|
63
63
|
});
|
@@ -5,6 +5,17 @@
|
|
5
5
|
/*global $hash$ installedModules $require$ hotDownloadManifest hotDownloadUpdateChunk modules */
|
6
6
|
module.exports = function() {
|
7
7
|
|
8
|
+
// Copied from https://github.com/facebook/react/blob/bef45b0/src/shared/utils/canDefineProperty.js
|
9
|
+
var canDefineProperty = false;
|
10
|
+
try {
|
11
|
+
Object.defineProperty({}, "x", {
|
12
|
+
get: function() {}
|
13
|
+
});
|
14
|
+
canDefineProperty = true;
|
15
|
+
} catch(x) {
|
16
|
+
// IE will fail on defineProperty
|
17
|
+
}
|
18
|
+
|
8
19
|
var hotApplyOnUpdate = true;
|
9
20
|
var hotCurrentHash = $hash$; // eslint-disable-line no-unused-vars
|
10
21
|
var hotCurrentModuleData = {};
|
@@ -29,47 +40,57 @@ module.exports = function() {
|
|
29
40
|
};
|
30
41
|
for(var name in $require$) {
|
31
42
|
if(Object.prototype.hasOwnProperty.call($require$, name)) {
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
43
|
+
if(canDefineProperty) {
|
44
|
+
Object.defineProperty(fn, name, (function(name) {
|
45
|
+
return {
|
46
|
+
configurable: true,
|
47
|
+
enumerable: true,
|
48
|
+
get: function() {
|
49
|
+
return $require$[name];
|
50
|
+
},
|
51
|
+
set: function(value) {
|
52
|
+
$require$[name] = value;
|
53
|
+
}
|
54
|
+
};
|
55
|
+
}(name)));
|
56
|
+
} else {
|
57
|
+
fn[name] = $require$[name];
|
58
|
+
}
|
44
59
|
}
|
45
60
|
}
|
46
|
-
Object.defineProperty(fn, "e", {
|
47
|
-
enumerable: true,
|
48
|
-
value: function(chunkId, callback) {
|
49
|
-
if(hotStatus === "ready")
|
50
|
-
hotSetStatus("prepare");
|
51
|
-
hotChunksLoading++;
|
52
|
-
$require$.e(chunkId, function() {
|
53
|
-
try {
|
54
|
-
callback.call(null, fn);
|
55
|
-
} finally {
|
56
|
-
finishChunkLoading();
|
57
|
-
}
|
58
61
|
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
62
|
+
function ensure(chunkId, callback) {
|
63
|
+
if(hotStatus === "ready")
|
64
|
+
hotSetStatus("prepare");
|
65
|
+
hotChunksLoading++;
|
66
|
+
$require$.e(chunkId, function() {
|
67
|
+
try {
|
68
|
+
callback.call(null, fn);
|
69
|
+
} finally {
|
70
|
+
finishChunkLoading();
|
71
|
+
}
|
72
|
+
|
73
|
+
function finishChunkLoading() {
|
74
|
+
hotChunksLoading--;
|
75
|
+
if(hotStatus === "prepare") {
|
76
|
+
if(!hotWaitingFilesMap[chunkId]) {
|
77
|
+
hotEnsureUpdateChunk(chunkId);
|
78
|
+
}
|
79
|
+
if(hotChunksLoading === 0 && hotWaitingFiles === 0) {
|
80
|
+
hotUpdateDownloaded();
|
68
81
|
}
|
69
82
|
}
|
70
|
-
}
|
71
|
-
}
|
72
|
-
}
|
83
|
+
}
|
84
|
+
});
|
85
|
+
}
|
86
|
+
if(canDefineProperty) {
|
87
|
+
Object.defineProperty(fn, "e", {
|
88
|
+
enumerable: true,
|
89
|
+
value: ensure
|
90
|
+
});
|
91
|
+
} else {
|
92
|
+
fn.e = ensure;
|
93
|
+
}
|
73
94
|
return fn;
|
74
95
|
}
|
75
96
|
|
package/lib/LibManifestPlugin.js
CHANGED
@@ -12,8 +12,10 @@ module.exports = LibManifestPlugin;
|
|
12
12
|
LibManifestPlugin.prototype.apply = function(compiler) {
|
13
13
|
compiler.plugin("emit", function(compilation, callback) {
|
14
14
|
async.forEach(compilation.chunks, function(chunk, callback) {
|
15
|
-
if(!chunk.initial)
|
15
|
+
if(!chunk.initial) {
|
16
|
+
callback();
|
16
17
|
return;
|
18
|
+
}
|
17
19
|
var targetPath = compilation.getPath(this.options.path, {
|
18
20
|
hash: compilation.hash,
|
19
21
|
chunk: chunk
|
package/lib/Parser.js
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
MIT License http://www.opensource.org/licenses/mit-license.php
|
3
3
|
Author Tobias Koppers @sokra
|
4
4
|
*/
|
5
|
-
var
|
5
|
+
var acorn = require("acorn");
|
6
6
|
var Tapable = require("tapable");
|
7
7
|
var BasicEvaluatedExpression = require("./BasicEvaluatedExpression");
|
8
8
|
|
@@ -39,28 +39,34 @@ Parser.prototype.initializeEvaluating = function() {
|
|
39
39
|
return new BasicEvaluatedExpression().setRegExp(expr.value).setRange(expr.range);
|
40
40
|
});
|
41
41
|
this.plugin("evaluate LogicalExpression", function(expr) {
|
42
|
+
var left;
|
43
|
+
var leftAsBool;
|
44
|
+
var right;
|
42
45
|
if(expr.operator === "&&") {
|
43
|
-
|
44
|
-
|
46
|
+
left = this.evaluateExpression(expr.left);
|
47
|
+
leftAsBool = left && left.asBool();
|
45
48
|
if(leftAsBool === false) return left.setRange(expr.range);
|
46
49
|
if(leftAsBool !== true) return;
|
47
|
-
|
50
|
+
right = this.evaluateExpression(expr.right);
|
48
51
|
return right.setRange(expr.range);
|
49
52
|
} else if(expr.operator === "||") {
|
50
|
-
|
51
|
-
|
53
|
+
left = this.evaluateExpression(expr.left);
|
54
|
+
leftAsBool = left && left.asBool();
|
52
55
|
if(leftAsBool === true) return left.setRange(expr.range);
|
53
56
|
if(leftAsBool !== false) return;
|
54
|
-
|
57
|
+
right = this.evaluateExpression(expr.right);
|
55
58
|
return right.setRange(expr.range);
|
56
59
|
}
|
57
60
|
});
|
58
61
|
this.plugin("evaluate BinaryExpression", function(expr) {
|
62
|
+
var left;
|
63
|
+
var right;
|
64
|
+
var res;
|
59
65
|
if(expr.operator === "+") {
|
60
|
-
|
61
|
-
|
66
|
+
left = this.evaluateExpression(expr.left);
|
67
|
+
right = this.evaluateExpression(expr.right);
|
62
68
|
if(!left || !right) return;
|
63
|
-
|
69
|
+
res = new BasicEvaluatedExpression();
|
64
70
|
if(left.isString()) {
|
65
71
|
if(right.isString()) {
|
66
72
|
res.setString(left.string + right.string);
|
@@ -112,37 +118,37 @@ Parser.prototype.initializeEvaluating = function() {
|
|
112
118
|
res.setRange(expr.range);
|
113
119
|
return res;
|
114
120
|
} else if(expr.operator === "-") {
|
115
|
-
|
116
|
-
|
121
|
+
left = this.evaluateExpression(expr.left);
|
122
|
+
right = this.evaluateExpression(expr.right);
|
117
123
|
if(!left || !right) return;
|
118
124
|
if(!left.isNumber() || !right.isNumber()) return;
|
119
|
-
|
125
|
+
res = new BasicEvaluatedExpression();
|
120
126
|
res.setNumber(left.number - right.number);
|
121
127
|
res.setRange(expr.range);
|
122
128
|
return res;
|
123
129
|
} else if(expr.operator === "*") {
|
124
|
-
|
125
|
-
|
130
|
+
left = this.evaluateExpression(expr.left);
|
131
|
+
right = this.evaluateExpression(expr.right);
|
126
132
|
if(!left || !right) return;
|
127
133
|
if(!left.isNumber() || !right.isNumber()) return;
|
128
|
-
|
134
|
+
res = new BasicEvaluatedExpression();
|
129
135
|
res.setNumber(left.number * right.number);
|
130
136
|
res.setRange(expr.range);
|
131
137
|
return res;
|
132
138
|
} else if(expr.operator === "/") {
|
133
|
-
|
134
|
-
|
139
|
+
left = this.evaluateExpression(expr.left);
|
140
|
+
right = this.evaluateExpression(expr.right);
|
135
141
|
if(!left || !right) return;
|
136
142
|
if(!left.isNumber() || !right.isNumber()) return;
|
137
|
-
|
143
|
+
res = new BasicEvaluatedExpression();
|
138
144
|
res.setNumber(left.number / right.number);
|
139
145
|
res.setRange(expr.range);
|
140
146
|
return res;
|
141
147
|
} else if(expr.operator === "==" || expr.operator === "===") {
|
142
|
-
|
143
|
-
|
148
|
+
left = this.evaluateExpression(expr.left);
|
149
|
+
right = this.evaluateExpression(expr.right);
|
144
150
|
if(!left || !right) return;
|
145
|
-
|
151
|
+
res = new BasicEvaluatedExpression();
|
146
152
|
res.setRange(expr.range);
|
147
153
|
if(left.isString() && right.isString()) {
|
148
154
|
return res.setBoolean(left.string === right.string);
|
@@ -152,10 +158,10 @@ Parser.prototype.initializeEvaluating = function() {
|
|
152
158
|
return res.setBoolean(left.bool === right.bool);
|
153
159
|
}
|
154
160
|
} else if(expr.operator === "!=" || expr.operator === "!==") {
|
155
|
-
|
156
|
-
|
161
|
+
left = this.evaluateExpression(expr.left);
|
162
|
+
right = this.evaluateExpression(expr.right);
|
157
163
|
if(!left || !right) return;
|
158
|
-
|
164
|
+
res = new BasicEvaluatedExpression();
|
159
165
|
res.setRange(expr.range);
|
160
166
|
if(left.isString() && right.isString()) {
|
161
167
|
return res.setBoolean(left.string !== right.string);
|
@@ -168,10 +174,11 @@ Parser.prototype.initializeEvaluating = function() {
|
|
168
174
|
});
|
169
175
|
this.plugin("evaluate UnaryExpression", function(expr) {
|
170
176
|
if(expr.operator === "typeof") {
|
177
|
+
var res;
|
171
178
|
if(expr.argument.type === "Identifier") {
|
172
179
|
var name = this.scope.renames["$" + expr.argument.name] || expr.argument.name;
|
173
180
|
if(this.scope.definitions.indexOf(name) === -1) {
|
174
|
-
|
181
|
+
res = this.applyPluginsBailResult("evaluate typeof " + name, expr);
|
175
182
|
if(res !== undefined) return res;
|
176
183
|
}
|
177
184
|
}
|
@@ -186,7 +193,7 @@ Parser.prototype.initializeEvaluating = function() {
|
|
186
193
|
exprName.unshift(this.scope.renames["$" + expression.name] || expression.name);
|
187
194
|
if(this.scope.definitions.indexOf(name) === -1) {
|
188
195
|
exprName = exprName.join(".");
|
189
|
-
|
196
|
+
res = this.applyPluginsBailResult("evaluate typeof " + exprName, expr);
|
190
197
|
if(res !== undefined) return res;
|
191
198
|
}
|
192
199
|
}
|
@@ -267,15 +274,16 @@ Parser.prototype.initializeEvaluating = function() {
|
|
267
274
|
["substr", "substring"].forEach(function(fn) {
|
268
275
|
this.plugin("evaluate CallExpression ." + fn, function(expr, param) {
|
269
276
|
if(!param.isString()) return;
|
277
|
+
var arg1;
|
270
278
|
var result, str = param.string;
|
271
279
|
switch(expr.arguments.length) {
|
272
280
|
case 1:
|
273
|
-
|
281
|
+
arg1 = this.evaluateExpression(expr.arguments[0]);
|
274
282
|
if(!arg1.isNumber()) return;
|
275
283
|
result = str[fn](arg1.number);
|
276
284
|
break;
|
277
285
|
case 2:
|
278
|
-
|
286
|
+
arg1 = this.evaluateExpression(expr.arguments[0]);
|
279
287
|
var arg2 = this.evaluateExpression(expr.arguments[1]);
|
280
288
|
if(!arg1.isNumber()) return;
|
281
289
|
if(!arg2.isNumber()) return;
|
@@ -302,11 +310,12 @@ Parser.prototype.initializeEvaluating = function() {
|
|
302
310
|
this.plugin("evaluate ConditionalExpression", function(expr) {
|
303
311
|
var condition = this.evaluateExpression(expr.test);
|
304
312
|
var conditionValue = condition.asBool();
|
313
|
+
var res;
|
305
314
|
if(conditionValue === undefined) {
|
306
315
|
var consequent = this.evaluateExpression(expr.consequent);
|
307
316
|
var alternate = this.evaluateExpression(expr.alternate);
|
308
317
|
if(!consequent || !alternate) return;
|
309
|
-
|
318
|
+
res = new BasicEvaluatedExpression();
|
310
319
|
if(consequent.isConditional())
|
311
320
|
res.setOptions(consequent.options);
|
312
321
|
else
|
@@ -316,7 +325,7 @@ Parser.prototype.initializeEvaluating = function() {
|
|
316
325
|
else
|
317
326
|
res.addOptions([alternate]);
|
318
327
|
} else {
|
319
|
-
|
328
|
+
res = this.evaluateExpression(conditionValue ? expr.consequent : expr.alternate);
|
320
329
|
}
|
321
330
|
res.setRange(expr.range);
|
322
331
|
return res;
|
@@ -339,6 +348,24 @@ Parser.prototype.getRenameIdentifier = function getRenameIdentifier(expr) {
|
|
339
348
|
return;
|
340
349
|
};
|
341
350
|
|
351
|
+
Parser.prototype.walkClass = function walkClass(classy) {
|
352
|
+
if(classy.superClass)
|
353
|
+
this.walkExpression(classy.superClass);
|
354
|
+
if(classy.body && classy.body.type === "ClassBody") {
|
355
|
+
classy.body.body.forEach(function(methodDefinition) {
|
356
|
+
if(methodDefinition.type === "MethodDefinition")
|
357
|
+
this.walkMethodDefinition(methodDefinition);
|
358
|
+
}, this);
|
359
|
+
}
|
360
|
+
};
|
361
|
+
|
362
|
+
Parser.prototype.walkMethodDefinition = function walkMethodDefinition(methodDefinition) {
|
363
|
+
if(methodDefinition.computed && methodDefinition.key)
|
364
|
+
this.walkExpression(methodDefinition.key);
|
365
|
+
if(methodDefinition.value)
|
366
|
+
this.walkExpression(methodDefinition.value);
|
367
|
+
};
|
368
|
+
|
342
369
|
Parser.prototype.walkStatements = function walkStatements(statements) {
|
343
370
|
statements.forEach(function(statement) {
|
344
371
|
this.walkStatement(statement);
|
@@ -405,7 +432,8 @@ Parser.prototype.walkTryStatement = function walkTryStatement(statement) {
|
|
405
432
|
this.walkStatement(statement.block);
|
406
433
|
this.scope.inTry = false;
|
407
434
|
}
|
408
|
-
|
435
|
+
if(statement.handler)
|
436
|
+
this.walkCatchClause(statement.handler);
|
409
437
|
if(statement.finalizer)
|
410
438
|
this.walkStatement(statement.finalizer);
|
411
439
|
};
|
@@ -439,6 +467,15 @@ Parser.prototype.walkForInStatement = function walkForInStatement(statement) {
|
|
439
467
|
this.walkStatement(statement.body);
|
440
468
|
};
|
441
469
|
|
470
|
+
Parser.prototype.walkForOfStatement = function walkForOfStatement(statement) {
|
471
|
+
if(statement.left.type === "VariableDeclaration")
|
472
|
+
this.walkStatement(statement.left);
|
473
|
+
else
|
474
|
+
this.walkExpression(statement.left);
|
475
|
+
this.walkExpression(statement.right);
|
476
|
+
this.walkStatement(statement.body);
|
477
|
+
};
|
478
|
+
|
442
479
|
// Declarations
|
443
480
|
Parser.prototype.walkFunctionDeclaration = function walkFunctionDeclaration(statement) {
|
444
481
|
this.scope.renames["$" + statement.id.name] = undefined;
|
@@ -456,6 +493,10 @@ Parser.prototype.walkVariableDeclaration = function walkVariableDeclaration(stat
|
|
456
493
|
this.walkVariableDeclarators(statement.declarations);
|
457
494
|
};
|
458
495
|
|
496
|
+
Parser.prototype.walkClassDeclaration = function walkClassDeclaration(statement) {
|
497
|
+
this.walkClass(statement);
|
498
|
+
};
|
499
|
+
|
459
500
|
Parser.prototype.walkSwitchCases = function walkSwitchCases(switchCases) {
|
460
501
|
switchCases.forEach(function(switchCase) {
|
461
502
|
if(switchCase.test)
|
@@ -464,14 +505,12 @@ Parser.prototype.walkSwitchCases = function walkSwitchCases(switchCases) {
|
|
464
505
|
}, this);
|
465
506
|
};
|
466
507
|
|
467
|
-
Parser.prototype.
|
468
|
-
|
469
|
-
|
470
|
-
|
471
|
-
this.
|
472
|
-
|
473
|
-
}.bind(this));
|
474
|
-
}, this);
|
508
|
+
Parser.prototype.walkCatchClause = function walkCatchClause(catchClause) {
|
509
|
+
if(catchClause.guard)
|
510
|
+
this.walkExpression(catchClause.guard);
|
511
|
+
this.inScope([catchClause.param], function() {
|
512
|
+
this.walkStatement(catchClause.body);
|
513
|
+
}.bind(this));
|
475
514
|
};
|
476
515
|
|
477
516
|
Parser.prototype.walkVariableDeclarators = function walkVariableDeclarators(declarators) {
|
@@ -518,8 +557,15 @@ Parser.prototype.walkArrayExpression = function walkArrayExpression(expression)
|
|
518
557
|
this.walkExpressions(expression.elements);
|
519
558
|
};
|
520
559
|
|
560
|
+
Parser.prototype.walkSpreadElement = function walkSpreadElement(expression) {
|
561
|
+
if(expression.argument)
|
562
|
+
this.walkExpression(expression.argument);
|
563
|
+
};
|
564
|
+
|
521
565
|
Parser.prototype.walkObjectExpression = function walkObjectExpression(expression) {
|
522
566
|
expression.properties.forEach(function(prop) {
|
567
|
+
if(prop.computed)
|
568
|
+
this.walkExpression(prop.key)
|
523
569
|
this.walkExpression(prop.value);
|
524
570
|
}, this);
|
525
571
|
};
|
@@ -533,6 +579,15 @@ Parser.prototype.walkFunctionExpression = function walkFunctionExpression(expres
|
|
533
579
|
}.bind(this));
|
534
580
|
};
|
535
581
|
|
582
|
+
Parser.prototype.walkArrowFunctionExpression = function walkArrowFunctionExpression(expression) {
|
583
|
+
this.inScope(expression.params, function() {
|
584
|
+
if(expression.body.type === "BlockStatement")
|
585
|
+
this.walkStatement(expression.body);
|
586
|
+
else
|
587
|
+
this.walkExpression(expression.body);
|
588
|
+
}.bind(this));
|
589
|
+
};
|
590
|
+
|
536
591
|
Parser.prototype.walkSequenceExpression = function walkSequenceExpression(expression) {
|
537
592
|
if(expression.expressions)
|
538
593
|
this.walkExpressions(expression.expressions);
|
@@ -612,6 +667,27 @@ Parser.prototype.walkNewExpression = function walkNewExpression(expression) {
|
|
612
667
|
this.walkExpressions(expression.arguments);
|
613
668
|
};
|
614
669
|
|
670
|
+
Parser.prototype.walkYieldExpression = function walkYieldExpression(expression) {
|
671
|
+
if(expression.argument)
|
672
|
+
this.walkExpression(expression.argument);
|
673
|
+
};
|
674
|
+
|
675
|
+
Parser.prototype.walkTemplateLiteral = function walkTemplateLiteral(expression) {
|
676
|
+
if(expression.expressions)
|
677
|
+
this.walkExpressions(expression.expressions);
|
678
|
+
};
|
679
|
+
|
680
|
+
Parser.prototype.walkTaggedTemplateExpression = function walkTaggedTemplateExpression(expression) {
|
681
|
+
if(expression.tag)
|
682
|
+
this.walkExpression(expression.tag);
|
683
|
+
if(expression.quasi && expression.quasi.expressions)
|
684
|
+
this.walkExpressions(expression.quasi.expressions);
|
685
|
+
};
|
686
|
+
|
687
|
+
Parser.prototype.walkClassExpression = function walkClassExpression(expression) {
|
688
|
+
this.walkClass(expression);
|
689
|
+
};
|
690
|
+
|
615
691
|
Parser.prototype.walkCallExpression = function walkCallExpression(expression) {
|
616
692
|
function walkIIFE(functionExpression, args) {
|
617
693
|
var params = functionExpression.params;
|
@@ -798,12 +874,38 @@ Parser.prototype.parseCalculatedString = function parseCalculatedString(expressi
|
|
798
874
|
};
|
799
875
|
});
|
800
876
|
|
877
|
+
var POSSIBLE_AST_OPTIONS = [{
|
878
|
+
ranges: true,
|
879
|
+
locations: true,
|
880
|
+
ecmaVersion: 6,
|
881
|
+
sourceType: "module"
|
882
|
+
}, {
|
883
|
+
ranges: true,
|
884
|
+
locations: true,
|
885
|
+
ecmaVersion: 6,
|
886
|
+
sourceType: "script"
|
887
|
+
}]
|
888
|
+
|
801
889
|
Parser.prototype.parse = function parse(source, initialState) {
|
802
|
-
var ast
|
803
|
-
|
804
|
-
|
805
|
-
|
806
|
-
|
890
|
+
var ast;
|
891
|
+
for(var i = 0; i < POSSIBLE_AST_OPTIONS.length; i++) {
|
892
|
+
if(!ast) {
|
893
|
+
try {
|
894
|
+
ast = acorn.parse(source, POSSIBLE_AST_OPTIONS[i]);
|
895
|
+
} catch(e) {
|
896
|
+
// ignore the error
|
897
|
+
}
|
898
|
+
}
|
899
|
+
}
|
900
|
+
if(!ast) {
|
901
|
+
// for the error
|
902
|
+
ast = acorn.parse(source, {
|
903
|
+
ranges: true,
|
904
|
+
locations: true,
|
905
|
+
ecmaVersion: 6,
|
906
|
+
sourceType: "module"
|
907
|
+
});
|
908
|
+
}
|
807
909
|
if(!ast || typeof ast !== "object")
|
808
910
|
throw new Error("Source couldn't be parsed");
|
809
911
|
var oldScope = this.scope;
|
@@ -822,10 +924,11 @@ Parser.prototype.parse = function parse(source, initialState) {
|
|
822
924
|
};
|
823
925
|
|
824
926
|
Parser.prototype.evaluate = function evaluate(source) {
|
825
|
-
var ast =
|
826
|
-
|
827
|
-
|
828
|
-
|
927
|
+
var ast = acorn.parse("(" + source + ")", {
|
928
|
+
ranges: true,
|
929
|
+
locations: true,
|
930
|
+
ecmaVersion: 6,
|
931
|
+
sourceType: "module"
|
829
932
|
});
|
830
933
|
if(!ast || typeof ast !== "object" || ast.type !== "Program")
|
831
934
|
throw new Error("evaluate: Source couldn't be parsed");
|
@@ -112,7 +112,7 @@ SourceMapDevToolPlugin.prototype.apply = function(compiler) {
|
|
112
112
|
var moduleFilenames = task.moduleFilenames;
|
113
113
|
var modules = task.modules;
|
114
114
|
sourceMap.sources = moduleFilenames;
|
115
|
-
if(sourceMap.sourcesContent) {
|
115
|
+
if(sourceMap.sourcesContent && !options.noSources) {
|
116
116
|
sourceMap.sourcesContent = sourceMap.sourcesContent.map(function(content, i) {
|
117
117
|
return content + "\n\n\n" + ModuleFilenameHelpers.createFooter(modules[i], requestShortener);
|
118
118
|
});
|
@@ -152,7 +152,7 @@ SourceMapDevToolPlugin.prototype.apply = function(compiler) {
|
|
152
152
|
return JSON.stringify(sourceMap);
|
153
153
|
})
|
154
154
|
.replace(/\[url\]/g, function() {
|
155
|
-
return "data:application/json;base64," +
|
155
|
+
return "data:application/json;charset=utf-8;base64," +
|
156
156
|
new Buffer(JSON.stringify(sourceMap)).toString("base64");
|
157
157
|
})
|
158
158
|
);
|
@@ -112,6 +112,7 @@ WebpackOptionsApply.prototype.process = function(options, compiler) {
|
|
112
112
|
break;
|
113
113
|
case "atom":
|
114
114
|
case "electron":
|
115
|
+
case "electron-main":
|
115
116
|
var NodeTemplatePlugin = require("./node/NodeTemplatePlugin");
|
116
117
|
var NodeTargetPlugin = require("./node/NodeTargetPlugin");
|
117
118
|
var ExternalsPlugin = require("./ExternalsPlugin");
|
@@ -128,18 +129,44 @@ WebpackOptionsApply.prototype.process = function(options, compiler) {
|
|
128
129
|
"electron",
|
129
130
|
"global-shortcut",
|
130
131
|
"ipc",
|
132
|
+
"ipc-main",
|
131
133
|
"menu",
|
132
134
|
"menu-item",
|
133
135
|
"power-monitor",
|
136
|
+
"power-save-blocker",
|
134
137
|
"protocol",
|
138
|
+
"session",
|
139
|
+
"web-contents",
|
135
140
|
"tray",
|
141
|
+
"clipboard",
|
142
|
+
"crash-reporter",
|
143
|
+
"native-image",
|
144
|
+
"screen",
|
145
|
+
"shell"
|
146
|
+
]),
|
147
|
+
new LoaderTargetPlugin(options.target)
|
148
|
+
);
|
149
|
+
break;
|
150
|
+
case "electron-renderer":
|
151
|
+
var JsonpTemplatePlugin = require("./JsonpTemplatePlugin");
|
152
|
+
var NodeTargetPlugin = require("./node/NodeTargetPlugin");
|
153
|
+
var ExternalsPlugin = require("./ExternalsPlugin");
|
154
|
+
compiler.apply(
|
155
|
+
new JsonpTemplatePlugin(options.output),
|
156
|
+
new FunctionModulePlugin(options.output),
|
157
|
+
new NodeTargetPlugin(),
|
158
|
+
new ExternalsPlugin("commonjs", [
|
159
|
+
"desktop-capturer",
|
160
|
+
"electron",
|
161
|
+
"ipc",
|
162
|
+
"ipc-renderer",
|
136
163
|
"remote",
|
137
|
-
"web-
|
164
|
+
"web-frame",
|
138
165
|
"clipboard",
|
139
166
|
"crash-reporter",
|
167
|
+
"native-image",
|
140
168
|
"screen",
|
141
|
-
"shell"
|
142
|
-
"native-image"
|
169
|
+
"shell"
|
143
170
|
]),
|
144
171
|
new LoaderTargetPlugin(options.target)
|
145
172
|
);
|
@@ -173,6 +200,7 @@ WebpackOptionsApply.prototype.process = function(options, compiler) {
|
|
173
200
|
var evalWrapped = options.devtool.indexOf("eval") >= 0;
|
174
201
|
var cheap = options.devtool.indexOf("cheap") >= 0;
|
175
202
|
var moduleMaps = options.devtool.indexOf("module") >= 0;
|
203
|
+
var noSources = options.devtool.indexOf("nosources") >= 0;
|
176
204
|
var legacy = options.devtool.indexOf("@") >= 0;
|
177
205
|
var modern = options.devtool.indexOf("#") >= 0;
|
178
206
|
var comment = legacy && modern ? "\n/*\n//@ sourceMappingURL=[url]\n//# sourceMappingURL=[url]\n*/" :
|
@@ -187,7 +215,8 @@ WebpackOptionsApply.prototype.process = function(options, compiler) {
|
|
187
215
|
append: hidden ? false : comment,
|
188
216
|
module: moduleMaps ? true : cheap ? false : true,
|
189
217
|
columns: cheap ? false : true,
|
190
|
-
lineToLine: options.output.devtoolLineToLine
|
218
|
+
lineToLine: options.output.devtoolLineToLine,
|
219
|
+
noSources: noSources,
|
191
220
|
}));
|
192
221
|
} else if(options.devtool && options.devtool.indexOf("eval") >= 0) {
|
193
222
|
var legacy = options.devtool.indexOf("@") >= 0;
|
@@ -17,7 +17,7 @@ AMDDefineDependency.prototype = Object.create(NullDependency.prototype);
|
|
17
17
|
AMDDefineDependency.prototype.constructor = AMDDefineDependency;
|
18
18
|
AMDDefineDependency.prototype.type = "amd define";
|
19
19
|
|
20
|
-
AMDDefineDependency.Template = function
|
20
|
+
AMDDefineDependency.Template = function AMDDefineDependencyTemplate() {};
|
21
21
|
|
22
22
|
AMDDefineDependency.Template.prototype.apply = function(dep, source) {
|
23
23
|
var localModuleVar = dep.localModule && dep.localModule.used && dep.localModule.variableName();
|
@@ -11,6 +11,7 @@ function AMDRequireDependenciesBlock(expr, arrayRange, functionRange, module, lo
|
|
11
11
|
this.outerRange = expr.range;
|
12
12
|
this.arrayRange = arrayRange;
|
13
13
|
this.functionRange = functionRange;
|
14
|
+
this.bindThis = true;
|
14
15
|
this.range = arrayRange && functionRange ? [arrayRange[0], functionRange[1]] :
|
15
16
|
arrayRange ? arrayRange :
|
16
17
|
functionRange ? functionRange :
|
@@ -10,6 +10,7 @@ var LocalModuleDependency = require("./LocalModuleDependency");
|
|
10
10
|
var ContextDependencyHelpers = require("./ContextDependencyHelpers");
|
11
11
|
var LocalModulesHelpers = require("./LocalModulesHelpers");
|
12
12
|
var ConstDependency = require("./ConstDependency");
|
13
|
+
var getFunctionExpression = require("./getFunctionExpression");
|
13
14
|
|
14
15
|
function AMDRequireDependenciesBlockParserPlugin(options) {
|
15
16
|
this.options = options;
|
@@ -46,15 +47,23 @@ AMDRequireDependenciesBlockParserPlugin.prototype.apply = function(parser) {
|
|
46
47
|
result = this.applyPluginsBailResult("call require:amd:array", expr, param);
|
47
48
|
}.bind(this));
|
48
49
|
if(!result) return;
|
49
|
-
|
50
|
-
|
50
|
+
var fnData = getFunctionExpression(expr.arguments[1]);
|
51
|
+
if(fnData) {
|
52
|
+
this.inScope(fnData.fn.params.filter(function(i) {
|
51
53
|
return ["require", "module", "exports"].indexOf(i.name) < 0;
|
52
54
|
}), function() {
|
53
|
-
if(
|
54
|
-
this.walkStatement(
|
55
|
+
if(fnData.fn.body.type === "BlockStatement")
|
56
|
+
this.walkStatement(fnData.fn.body);
|
55
57
|
else
|
56
|
-
this.walkExpression(
|
58
|
+
this.walkExpression(fnData.fn.body);
|
57
59
|
}.bind(this));
|
60
|
+
this.walkExpressions(fnData.expressions);
|
61
|
+
if(fnData.needThis === false) {
|
62
|
+
// smaller bundles for simple function expression
|
63
|
+
dep.bindThis = false;
|
64
|
+
}
|
65
|
+
} else {
|
66
|
+
this.walkExpression(expr.arguments[1]);
|
58
67
|
}
|
59
68
|
} finally {
|
60
69
|
this.state.current = old;
|
@@ -46,14 +46,14 @@ AMDRequireDependency.Template.prototype.apply = function(dep, source, outputOpti
|
|
46
46
|
source.insert(depBlock.arrayRange[0] + 0.9, "var __WEBPACK_AMD_REQUIRE_ARRAY__ = ");
|
47
47
|
source.replace(depBlock.arrayRange[1], depBlock.functionRange[0] - 1, "; (");
|
48
48
|
source.insert(depBlock.functionRange[1], ".apply(null, __WEBPACK_AMD_REQUIRE_ARRAY__));");
|
49
|
-
source.replace(depBlock.functionRange[1], depBlock.outerRange[1] - 1, "}" + wrapper[1]);
|
49
|
+
source.replace(depBlock.functionRange[1], depBlock.outerRange[1] - 1, "}" + (depBlock.bindThis ? ".bind(this)" : "") + wrapper[1]);
|
50
50
|
} else {
|
51
51
|
source.replace(depBlock.outerRange[0], depBlock.arrayRange[0] - 1,
|
52
52
|
"!/* require */(" + asComment(depBlock.chunkReason) + "function() { ");
|
53
53
|
source.insert(depBlock.arrayRange[0] + 0.9, "var __WEBPACK_AMD_REQUIRE_ARRAY__ = ");
|
54
54
|
source.replace(depBlock.arrayRange[1], depBlock.functionRange[0] - 1, "; (");
|
55
55
|
source.insert(depBlock.functionRange[1], ".apply(null, __WEBPACK_AMD_REQUIRE_ARRAY__));");
|
56
|
-
source.replace(depBlock.functionRange[1], depBlock.outerRange[1] - 1, "}())");
|
56
|
+
source.replace(depBlock.functionRange[1], depBlock.outerRange[1] - 1, "}" + (depBlock.bindThis ? ".call(this)" : "()") + ")");
|
57
57
|
}
|
58
58
|
}
|
59
59
|
};
|
@@ -23,9 +23,8 @@ LoaderPlugin.prototype.apply = function(compiler) {
|
|
23
23
|
], true, "lm", false, function(err) {
|
24
24
|
if(err) return callback(err);
|
25
25
|
|
26
|
-
module
|
27
|
-
if(
|
28
|
-
if(module.building) module.building.push(next);
|
26
|
+
if(!dep.module) return callback(new Error("Cannot load the module"));
|
27
|
+
if(dep.module.building) dep.module.building.push(next);
|
29
28
|
else next();
|
30
29
|
|
31
30
|
function next(err) {
|
@@ -7,7 +7,8 @@ module.exports = function(expr) {
|
|
7
7
|
if(expr.type === "FunctionExpression") {
|
8
8
|
return {
|
9
9
|
fn: expr,
|
10
|
-
expressions: []
|
10
|
+
expressions: [],
|
11
|
+
needThis: false
|
11
12
|
};
|
12
13
|
}
|
13
14
|
// <FunctionExpression>.bind(<Expression>)
|
@@ -35,7 +36,8 @@ module.exports = function(expr) {
|
|
35
36
|
expr.callee.body.body[0].argument.type === "FunctionExpression") {
|
36
37
|
return {
|
37
38
|
fn: expr.callee.body.body[0].argument,
|
38
|
-
expressions: []
|
39
|
+
expressions: [],
|
40
|
+
needThis: true
|
39
41
|
};
|
40
42
|
}
|
41
43
|
};
|
@@ -91,6 +91,9 @@ UglifyJsPlugin.prototype.apply = function(compiler) {
|
|
91
91
|
ast.figure_out_scope();
|
92
92
|
ast.compute_char_frequency(options.mangle || {});
|
93
93
|
ast.mangle_names(options.mangle || {});
|
94
|
+
if(options.mangle && options.mangle.props) {
|
95
|
+
uglify.mangle_properties(ast, options.mangle.props);
|
96
|
+
}
|
94
97
|
}
|
95
98
|
var output = {};
|
96
99
|
output.comments = Object.prototype.hasOwnProperty.call(options, "comments") ? options.comments : /^\**!|@preserve|@license/;
|
package/lib/webpack.js
CHANGED
@@ -28,7 +28,10 @@ function webpack(options, callback) {
|
|
28
28
|
}
|
29
29
|
if(callback) {
|
30
30
|
if(typeof callback !== "function") throw new Error("Invalid argument: callback");
|
31
|
-
if(options.watch === true)
|
31
|
+
if(options.watch === true || (Array.isArray(options) &&
|
32
|
+
options.some(function(o) {
|
33
|
+
return o.watch;
|
34
|
+
}))) {
|
32
35
|
var watchOptions = (!Array.isArray(options) ? options : options[0]).watchOptions || {};
|
33
36
|
// TODO remove this in next major version
|
34
37
|
var watchDelay = (!Array.isArray(options) ? options : options[0]).watchDelay;
|
package/package.json
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
{
|
2
2
|
"name": "webpack",
|
3
|
-
"version": "1.
|
3
|
+
"version": "1.13.1",
|
4
4
|
"author": "Tobias Koppers @sokra",
|
5
5
|
"description": "Packs CommonJs/AMD modules for the browser. Allows to split your codebase into multiple bundles, which can be loaded on demand. Support loaders to preprocess files, i.e. json, jade, coffee, css, less, ... and your custom stuff.",
|
6
6
|
"dependencies": {
|
7
7
|
"async": "^1.3.0",
|
8
8
|
"clone": "^1.0.2",
|
9
9
|
"enhanced-resolve": "~0.9.0",
|
10
|
-
"
|
10
|
+
"acorn": "^3.0.0",
|
11
11
|
"interpret": "^0.6.4",
|
12
12
|
"loader-utils": "^0.2.11",
|
13
13
|
"memory-fs": "~0.3.0",
|