Skip to content

Commit aeb9683

Browse files
committed
Merge branch 'master' into next
2 parents 325a5c4 + 74afac5 commit aeb9683

File tree

14 files changed

+611
-437
lines changed

14 files changed

+611
-437
lines changed

examples/chunkhash/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
A common challenge with combining `[chunkhash]` and Code Splitting is that the entry chunk includes the webpack runtime and with it the chunkhash mappings. This means it's always updated and the `[chunkhash]` is pretty useless, because this chunk won't be cached.
22

3-
A very simple solution to this problem is to create another chunk which contains only the webpack runtime (including chunkhash map). This can be archieved by the CommonsChunkPlugin (or if the CommonsChunkPlugin is already used by passing multiple names to the CommonChunkPlugin). To avoid the additional request for another chunk, this pretty small chunk can be inlined into the HTML page.
3+
A very simple solution to this problem is to create another chunk which contains only the webpack runtime (including chunkhash map). This can be achieved by the CommonsChunkPlugin (or if the CommonsChunkPlugin is already used by passing multiple names to the CommonChunkPlugin). To avoid the additional request for another chunk, this pretty small chunk can be inlined into the HTML page.
44

55
The configuration required for this is:
66

examples/chunkhash/template.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
A common challenge with combining `[chunkhash]` and Code Splitting is that the entry chunk includes the webpack runtime and with it the chunkhash mappings. This means it's always updated and the `[chunkhash]` is pretty useless, because this chunk won't be cached.
22

3-
A very simple solution to this problem is to create another chunk which contains only the webpack runtime (including chunkhash map). This can be archieved by the CommonsChunkPlugin (or if the CommonsChunkPlugin is already used by passing multiple names to the CommonChunkPlugin). To avoid the additional request for another chunk, this pretty small chunk can be inlined into the HTML page.
3+
A very simple solution to this problem is to create another chunk which contains only the webpack runtime (including chunkhash map). This can be achieved by the CommonsChunkPlugin (or if the CommonsChunkPlugin is already used by passing multiple names to the CommonChunkPlugin). To avoid the additional request for another chunk, this pretty small chunk can be inlined into the HTML page.
44

55
The configuration required for this is:
66

examples/common-chunk-and-vendor-chunk/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
This example shows how to create an explicit vendor chunk as well as a common chunk for code shared among entry points. In this example, we have 3 entry points: `pageA`, `pageB`, and `pageC`. Those entry points share some of the same utility modules, but not others. This configuration will pull out any modules common to at least 2 bundles and place it it the `common` bundle instead, all while keeping the specified vendor libraries in their own bundle by themselves.
1+
This example shows how to create an explicit vendor chunk as well as a common chunk for code shared among entry points. In this example, we have 3 entry points: `pageA`, `pageB`, and `pageC`. Those entry points share some of the same utility modules, but not others. This configuration will pull out any modules common to at least 2 bundles and place it in the `common` bundle instead, all while keeping the specified vendor libraries in their own bundle by themselves.
22

33
To better understand, here are the entry points and which utility modules they depend on:
44

examples/common-chunk-and-vendor-chunk/template.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
This example shows how to create an explicit vendor chunk as well as a common chunk for code shared among entry points. In this example, we have 3 entry points: `pageA`, `pageB`, and `pageC`. Those entry points share some of the same utility modules, but not others. This configuration will pull out any modules common to at least 2 bundles and place it it the `common` bundle instead, all while keeping the specified vendor libraries in their own bundle by themselves.
1+
This example shows how to create an explicit vendor chunk as well as a common chunk for code shared among entry points. In this example, we have 3 entry points: `pageA`, `pageB`, and `pageC`. Those entry points share some of the same utility modules, but not others. This configuration will pull out any modules common to at least 2 bundles and place it in the `common` bundle instead, all while keeping the specified vendor libraries in their own bundle by themselves.
22

33
To better understand, here are the entry points and which utility modules they depend on:
44

lib/Parser.js

Lines changed: 33 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -636,6 +636,9 @@ class Parser extends Tapable {
636636
}
637637

638638
walkFunctionDeclaration(statement) {
639+
statement.params.forEach(param => {
640+
this.walkPattern(param);
641+
});
639642
this.inScope(statement.params, function() {
640643
if(statement.body.type === "BlockStatement") {
641644
this.prewalkStatement(statement.body);
@@ -797,24 +800,15 @@ class Parser extends Tapable {
797800
switch(declarator.type) {
798801
case "VariableDeclarator":
799802
{
800-
const renameIdentifier = declarator.init && this.getRenameIdentifier(declarator.init);
801-
if(renameIdentifier && declarator.id.type === "Identifier" && this.applyPluginsBailResult1("can-rename " + renameIdentifier, declarator.init)) {
802-
// renaming with "var a = b;"
803-
if(!this.applyPluginsBailResult1("rename " + renameIdentifier, declarator.init)) {
804-
this.scope.renames["$" + declarator.id.name] = this.scope.renames["$" + renameIdentifier] || renameIdentifier;
805-
const idx = this.scope.definitions.indexOf(declarator.id.name);
806-
if(idx >= 0) this.scope.definitions.splice(idx, 1);
807-
}
808-
} else {
809-
this.enterPattern(declarator.id, (name, decl) => {
810-
if(!this.applyPluginsBailResult1("var-" + declarator.kind + " " + name, decl)) {
811-
if(!this.applyPluginsBailResult1("var " + name, decl)) {
812-
this.scope.renames["$" + name] = undefined;
803+
this.enterPattern(declarator.id, (name, decl) => {
804+
if(!this.applyPluginsBailResult1("var-" + declarator.kind + " " + name, decl)) {
805+
if(!this.applyPluginsBailResult1("var " + name, decl)) {
806+
this.scope.renames["$" + name] = undefined;
807+
if(this.scope.definitions.indexOf(name) < 0)
813808
this.scope.definitions.push(name);
814-
}
815809
}
816-
});
817-
}
810+
}
811+
});
818812
break;
819813
}
820814
}
@@ -827,7 +821,14 @@ class Parser extends Tapable {
827821
case "VariableDeclarator":
828822
{
829823
const renameIdentifier = declarator.init && this.getRenameIdentifier(declarator.init);
830-
if(!renameIdentifier || declarator.id.type !== "Identifier" || !this.applyPluginsBailResult1("can-rename " + renameIdentifier, declarator.init)) {
824+
if(renameIdentifier && declarator.id.type === "Identifier" && this.applyPluginsBailResult1("can-rename " + renameIdentifier, declarator.init)) {
825+
// renaming with "var a = b;"
826+
if(!this.applyPluginsBailResult1("rename " + renameIdentifier, declarator.init)) {
827+
this.scope.renames["$" + declarator.id.name] = this.scope.renames["$" + renameIdentifier] || renameIdentifier;
828+
const idx = this.scope.definitions.indexOf(declarator.id.name);
829+
if(idx >= 0) this.scope.definitions.splice(idx, 1);
830+
}
831+
} else {
831832
this.walkPattern(declarator.id);
832833
if(declarator.init)
833834
this.walkExpression(declarator.init);
@@ -845,6 +846,11 @@ class Parser extends Tapable {
845846
this["walk" + pattern.type](pattern);
846847
}
847848

849+
walkAssignmentPattern(pattern) {
850+
this.walkExpression(pattern.right);
851+
this.walkPattern(pattern.left);
852+
}
853+
848854
walkObjectPattern(pattern) {
849855
for(let i = 0, len = pattern.properties.length; i < len; i++) {
850856
const prop = pattern.properties[i];
@@ -912,6 +918,9 @@ class Parser extends Tapable {
912918
}
913919

914920
walkFunctionExpression(expression) {
921+
expression.params.forEach(param => {
922+
this.walkPattern(param);
923+
});
915924
this.inScope(expression.params, function() {
916925
if(expression.body.type === "BlockStatement") {
917926
this.prewalkStatement(expression.body);
@@ -923,6 +932,9 @@ class Parser extends Tapable {
923932
}
924933

925934
walkArrowFunctionExpression(expression) {
935+
expression.params.forEach(param => {
936+
this.walkPattern(param);
937+
});
926938
this.inScope(expression.params, function() {
927939
if(expression.body.type === "BlockStatement") {
928940
this.prewalkStatement(expression.body);
@@ -993,8 +1005,10 @@ class Parser extends Tapable {
9931005
}
9941006
} else {
9951007
this.walkExpression(expression.right);
996-
this.scope.renames["$" + expression.left.name] = undefined;
997-
this.walkExpression(expression.left);
1008+
this.walkPattern(expression.left);
1009+
this.enterPattern(expression.left, (name, decl) => {
1010+
this.scope.renames["$" + name] = undefined;
1011+
});
9981012
}
9991013
}
10001014

@@ -1191,7 +1205,6 @@ class Parser extends Tapable {
11911205

11921206
enterAssignmentPattern(pattern, onIdent) {
11931207
this.enterPattern(pattern.left, onIdent);
1194-
this.walkExpression(pattern.right);
11951208
}
11961209

11971210
evaluateExpression(expression) {

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
"source-map": "^0.5.3",
2222
"supports-color": "^3.1.0",
2323
"tapable": "~0.2.5",
24-
"uglify-js": "^2.8.5",
24+
"uglify-js": "^2.8.27",
2525
"watchpack": "^1.3.1",
2626
"webpack-sources": "^0.2.3",
2727
"yargs": "^6.0.0"

test/cases/parsing/issue-3273/index.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,13 @@ it("should hide import by pattern in function", function() {
2626
}({ test: "ok" }));
2727
});
2828

29-
it("should allow import in default", function() {
29+
it("should allow import in default (incorrect)", function() {
3030
var { other = test, test } = { test: "ok" };
3131
test.should.be.eql("ok");
32+
(typeof other).should.be.eql("undefined");
33+
});
34+
35+
it("should allow import in default", function() {
36+
var { other = test } = { test: "ok" };
3237
other.should.be.eql("test");
3338
});
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export var test = "test";
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { test } from "./file";
2+
3+
it("should allow import in array destructing", function() {
4+
var other;
5+
[other = test] = [];
6+
other.should.be.eql("test");
7+
});
8+
9+
it("should allow import in object destructing", function() {
10+
var other;
11+
({other = test} = {});
12+
other.should.be.eql("test");
13+
});
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
var supportsIteratorDestructuring = require("../../../helpers/supportsIteratorDestructuring");
2+
var supportsObjectDestructuring = require("../../../helpers/supportsObjectDestructuring");
3+
4+
module.exports = function(config) {
5+
return !config.minimize && supportsObjectDestructuring() && supportsIteratorDestructuring();
6+
};

0 commit comments

Comments
 (0)