Skip to content

Commit 4a25a17

Browse files
committed
improvements from review
1 parent c41ab08 commit 4a25a17

File tree

8 files changed

+26
-11
lines changed

8 files changed

+26
-11
lines changed

lib/Compilation.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -586,7 +586,7 @@ class Compilation extends Tapable {
586586

587587
while(self.applyPluginsBailResult("optimize-chunk-modules-basic", self.chunks, self.modules) ||
588588
self.applyPluginsBailResult("optimize-chunk-modules", self.chunks, self.modules) ||
589-
self.applyPluginsBailResult("optimize-chunk-modules-advanced", self.chunks, self.modules)); // eslint-disable-line no-extra-semi
589+
self.applyPluginsBailResult("optimize-chunk-modules-advanced", self.chunks, self.modules)) { /* empty */ }
590590
self.applyPlugins2("after-optimize-chunk-modules", self.chunks, self.modules);
591591

592592
const shouldRecord = self.applyPluginsBailResult("should-record") !== false;

lib/Parser.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,20 @@ function joinRanges(startRange, endRange) {
1717
return [startRange[0], endRange[1]];
1818
}
1919

20+
const ECMA_VERSION = 2017;
21+
2022
const POSSIBLE_AST_OPTIONS = [{
2123
ranges: true,
2224
locations: true,
23-
ecmaVersion: 2017,
25+
ecmaVersion: ECMA_VERSION,
2426
sourceType: "module",
2527
plugins: {
2628
dynamicImport: true
2729
}
2830
}, {
2931
ranges: true,
3032
locations: true,
31-
ecmaVersion: 2017,
33+
ecmaVersion: ECMA_VERSION,
3234
sourceType: "script",
3335
plugins: {
3436
dynamicImport: true
@@ -1335,7 +1337,7 @@ class Parser extends Tapable {
13351337
ast = acorn.parse(source, {
13361338
ranges: true,
13371339
locations: true,
1338-
ecmaVersion: 2017,
1340+
ecmaVersion: ECMA_VERSION,
13391341
sourceType: "module",
13401342
plugins: {
13411343
dynamicImport: true
@@ -1369,7 +1371,7 @@ class Parser extends Tapable {
13691371
const ast = acorn.parse("(" + source + ")", {
13701372
ranges: true,
13711373
locations: true,
1372-
ecmaVersion: 2017,
1374+
ecmaVersion: ECMA_VERSION,
13731375
sourceType: "module",
13741376
plugins: {
13751377
dynamicImport: true
@@ -1401,4 +1403,6 @@ class Parser extends Tapable {
14011403

14021404
}
14031405

1406+
Parser.ECMA_VERSION = ECMA_VERSION;
1407+
14041408
module.exports = Parser;

lib/optimize/ConcatenatedModule.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
const Module = require("../Module");
88
const Template = require("../Template");
9+
const Parser = require("../Parser");
910
const acorn = require("acorn");
1011
const escope = require("escope");
1112
const ReplaceSource = require("webpack-sources/lib/ReplaceSource");
@@ -35,11 +36,11 @@ function getFinalName(info, exportName, moduleToInfoMap, requestShortener) {
3536
const dep = reexport.dependency;
3637
const importedModule = reexport.module;
3738
const exportName = reexport.exportName;
38-
const isNotAHarmonyModule = !(importedModule && (!importedModule.meta || importedModule.meta.harmonyModule));
39+
const isHarmonyModule = importedModule && (!importedModule.meta || importedModule.meta.harmonyModule);
3940
const importedVar = dep.importedVar;
4041
const used = importedModule.isUsed(exportName);
4142
if(!used) return "/* unused reexport */undefined";
42-
if(isNotAHarmonyModule && exportName === "default") {
43+
if(!isHarmonyModule && exportName === "default") {
4344
return `${importedVar}_default.a`;
4445
}
4546
return `${importedVar}[${JSON.stringify(used)}]`;
@@ -210,7 +211,7 @@ class ConcatenatedModule extends Module {
210211
const ast = acorn.parse(code, {
211212
ranges: true,
212213
locations: true,
213-
ecmaVersion: 2017,
214+
ecmaVersion: Parser.ECMA_VERSION,
214215
sourceType: "module"
215216
});
216217
const scopeManager = escope.analyze(ast, {
@@ -244,7 +245,7 @@ class ConcatenatedModule extends Module {
244245
info.internalNames.set(namespaceObjectName, namespaceObjectName);
245246
info.exportMap.set(true, namespaceObjectName);
246247
info.moduleScope.variables.forEach(variable => {
247-
let name = variable.name;
248+
const name = variable.name;
248249
if(allUsedNames.has(name)) {
249250
const newName = this.findNewName(name, allUsedNames, info.module.readableIdentifier(requestShortener));
250251
allUsedNames.add(newName);
@@ -290,7 +291,7 @@ class ConcatenatedModule extends Module {
290291
result.add(`Object.defineProperty(${this.rootModule.moduleArgument || "exports"}, "__esModule", { value: true });\n`);
291292
}
292293
modulesWithInfo.forEach(info => {
293-
result.add(`\n// CONCATENAMED MODULE: ${info.module.readableIdentifier(requestShortener)}\n`);
294+
result.add(`\n// CONCATENATED MODULE: ${info.module.readableIdentifier(requestShortener)}\n`);
294295
if(info.needNamespaceObject) {
295296
const name = info.exportMap.get(true);
296297
const nsObj = [`var ${name} = {};`];

lib/optimize/ModuleConcatenationPlugin.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ class ModuleConcatenationPlugin {
6666
const currentRoot = possibleRoots.pop();
6767
// console.log("#process", currentRoot.debugId, currentRoot.resource);
6868
const currentConfiguration = new ConcatConfiguration(currentRoot);
69-
for(let imp of this.getImports(currentRoot)) {
69+
for(const imp of this.getImports(currentRoot)) {
7070
this.tryToAdd(currentConfiguration, imp, possibleInners);
7171
}
7272
if(!currentConfiguration.isEmpty())
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export default "named";
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
import named from "./a";
2+
export { named }
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
import { named } from "./b";
2+
export { named }
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
var c = require("./c");
2+
3+
it("should have the correct values", function() {
4+
c.named.should.be.eql("named");
5+
});

0 commit comments

Comments
 (0)