Skip to content

Commit d85d165

Browse files
authored
Merge branch 'master' into fix/eslint-no-loop-func-warnings
2 parents 34c02a9 + 481752a commit d85d165

9 files changed

Lines changed: 74 additions & 35 deletions

File tree

‎bin/config-yargs.js‎

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ module.exports = function(yargs) {
1010
yargs
1111
.help("help")
1212
.alias("help", "h", "?")
13+
.version()
14+
.alias("version", "v")
1315
.options({
1416
"config": {
1517
type: "string",
@@ -22,12 +24,6 @@ module.exports = function(yargs) {
2224
describe: "Enviroment passed to the config, when it is a function",
2325
group: CONFIG_GROUP
2426
},
25-
"version": {
26-
type: "string",
27-
describe: "Webpack version",
28-
alias: "v",
29-
group: BASIC_GROUP,
30-
},
3127
"context": {
3228
type: "string",
3329
describe: "The root directory for resolving entry point and stats",

‎bin/convert-argv.js‎

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,10 @@ var interpret = require("interpret");
66
var WebpackOptionsDefaulter = require("../lib/WebpackOptionsDefaulter");
77
var validateWebpackOptions = require("../lib/validateWebpackOptions");
88

9-
module.exports = function(optimist, argv, convertOptions) {
9+
module.exports = function(yargs, argv, convertOptions) {
1010

1111
var options = [];
1212

13-
// Help
14-
if(argv.help) {
15-
optimist.showHelp();
16-
process.exit(0); // eslint-disable-line
17-
}
18-
19-
// Version
20-
if(argv.v || argv.version) {
21-
console.log(require("../package.json").version);
22-
process.exit(0); // eslint-disable-line
23-
}
24-
2513
// Shortcuts
2614
if(argv.d) {
2715
argv.debug = true;
@@ -53,7 +41,7 @@ module.exports = function(optimist, argv, convertOptions) {
5341

5442
var i;
5543
if(argv.config) {
56-
function getConfigExtension(configPath) {
44+
var getConfigExtension = function getConfigExtension(configPath) {
5745
for(i = extensions.length - 1; i >= 0; i--) {
5846
var tmpExt = extensions[i];
5947
if(configPath.indexOf(tmpExt, configPath.length - tmpExt.length) > -1) {
@@ -63,7 +51,7 @@ module.exports = function(optimist, argv, convertOptions) {
6351
return path.extname(configPath);
6452
}
6553

66-
function mapConfigArg(configArg) {
54+
var mapConfigArg = function mapConfigArg(configArg) {
6755
var resolvedPath = path.resolve(configArg);
6856
var extension = getConfigExtension(resolvedPath);
6957
return {
@@ -88,7 +76,7 @@ module.exports = function(optimist, argv, convertOptions) {
8876
}
8977

9078
if(configFiles.length > 0) {
91-
function registerCompiler(moduleDescriptor) {
79+
var registerCompiler = function registerCompiler(moduleDescriptor) {
9280
if(moduleDescriptor) {
9381
if(typeof moduleDescriptor === "string") {
9482
require(moduleDescriptor);
@@ -107,7 +95,7 @@ module.exports = function(optimist, argv, convertOptions) {
10795
}
10896
}
10997

110-
function requireConfig(configPath) {
98+
var requireConfig = function requireConfig(configPath) {
11199
var options = require(configPath);
112100
var isES6DefaultExportedFunc = (
113101
typeof options === "object" && options !== null && typeof options.default === "function"
@@ -538,7 +526,7 @@ module.exports = function(optimist, argv, convertOptions) {
538526
}
539527
ensureObject(options, "entry");
540528

541-
function addTo(name, entry) {
529+
var addTo = function addTo(name, entry) {
542530
if(options.entry[name]) {
543531
if(!Array.isArray(options.entry[name])) {
544532
options.entry[name] = [options.entry[name]];

‎hot/poll.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
if(module.hot) {
77
var hotPollInterval = +(__resourceQuery.substr(1)) || (10 * 60 * 1000);
88

9-
function checkForUpdate(fromUpdate) {
9+
var checkForUpdate = function checkForUpdate(fromUpdate) {
1010
if(module.hot.status() === "idle") {
1111
module.hot.check(true).then(function(updatedModules) {
1212
if(!updatedModules) {

‎hot/signal.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
*/
55
/*globals __resourceQuery */
66
if(module.hot) {
7-
function checkForUpdate(fromUpdate) {
7+
var checkForUpdate = function checkForUpdate(fromUpdate) {
88
module.hot.check().then(function(updatedModules) {
99
if(!updatedModules) {
1010
if(fromUpdate)

‎lib/NormalModule.js‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ NormalModule.prototype.build = function build(options, compilation, resolver, fs
183183
_this._cachedSource = null;
184184
if(err) return setError(err);
185185
if(options.module && options.module.noParse) {
186-
function testRegExp(regExp) {
186+
var testRegExp = function testRegExp(regExp) {
187187
return typeof regExp === "string" ?
188188
_this.request.indexOf(regExp) === 0 :
189189
regExp.test(_this.request);
@@ -267,7 +267,7 @@ NormalModule.prototype.source = function(dependencyTemplates, outputOptions, req
267267
var varStartCode = "";
268268
var varEndCode = "";
269269

270-
function emitFunction() {
270+
var emitFunction = function emitFunction() {
271271
if(varNames.length === 0) return;
272272

273273
varStartCode += "/* WEBPACK VAR INJECTION */(function(" + varNames.join(", ") + ") {";

‎lib/Parser.js‎

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -650,6 +650,12 @@ Parser.prototype.walkExpression = function walkExpression(expression) {
650650
return this["walk" + expression.type](expression);
651651
};
652652

653+
Parser.prototype.walkAwaitExpression = function walkAwaitExpression(expression) {
654+
var argument = expression.argument
655+
if(this["walk" + argument.type])
656+
return this["walk" + argument.type](argument);
657+
}
658+
653659
Parser.prototype.walkArrayExpression = function walkArrayExpression(expression) {
654660
if(expression.elements)
655661
this.walkExpressions(expression.elements);
@@ -1035,12 +1041,12 @@ Parser.prototype.parseCalculatedString = function parseCalculatedString(expressi
10351041
var POSSIBLE_AST_OPTIONS = [{
10361042
ranges: true,
10371043
locations: true,
1038-
ecmaVersion: 6,
1044+
ecmaVersion: 2017,
10391045
sourceType: "module"
10401046
}, {
10411047
ranges: true,
10421048
locations: true,
1043-
ecmaVersion: 6,
1049+
ecmaVersion: 2017,
10441050
sourceType: "script"
10451051
}]
10461052

@@ -1062,7 +1068,7 @@ Parser.prototype.parse = function parse(source, initialState) {
10621068
ast = acorn.parse(source, {
10631069
ranges: true,
10641070
locations: true,
1065-
ecmaVersion: 6,
1071+
ecmaVersion: 2017,
10661072
sourceType: "module",
10671073
onComment: comments
10681074
});
@@ -1088,7 +1094,7 @@ Parser.prototype.evaluate = function evaluate(source) {
10881094
var ast = acorn.parse("(" + source + ")", {
10891095
ranges: true,
10901096
locations: true,
1091-
ecmaVersion: 6,
1097+
ecmaVersion: 2017,
10921098
sourceType: "module"
10931099
});
10941100
if(!ast || typeof ast !== "object" || ast.type !== "Program")

‎lib/ProgressPlugin.js‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ ProgressPlugin.prototype.apply = function(compiler) {
3838
var doneModules = 0;
3939
var activeModules = [];
4040

41-
function update(module) {
41+
var update = function update(module) {
4242
handler(
4343
0.1 + (doneModules / Math.max(lastModulesCount, moduleCount)) * 0.6,
4444
"building modules",
@@ -48,7 +48,7 @@ ProgressPlugin.prototype.apply = function(compiler) {
4848
);
4949
}
5050

51-
function moduleDone(module) {
51+
var moduleDone = function moduleDone(module) {
5252
doneModules++;
5353
var ident = module.identifier();
5454
if(ident) {

‎lib/UmdMainTemplatePlugin.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ UmdMainTemplatePlugin.prototype.apply = function(compilation) {
164164
" for(var i in a) (typeof exports === 'object' ? exports : root)[i] = a[i];\n" +
165165
" }\n"
166166
) +
167-
"})(this, function(" + externalsArguments(externals) + ") {\nreturn ", "webpack/universalModuleDefinition"), source, "\n});\n");
167+
"})(this, function(" + externalsArguments(externals) + ") {\nreturn ", "webpack/universalModuleDefinition"), source, ";\n})");
168168
}.bind(this));
169169
mainTemplate.plugin("global-hash-paths", function(paths) {
170170
if(this.name) paths = paths.concat(this.name);

‎test/Parser.test.js‎

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,4 +307,53 @@ describe("Parser", function() {
307307
});
308308
});
309309
});
310+
311+
describe("async/await support", function() {
312+
describe("should accept", function() {
313+
var cases = {
314+
"async function": "async function x() {}",
315+
"async arrow function": "async () => {}",
316+
"await expression": "async function x(y) { await y }"
317+
};
318+
var parser = new Parser();
319+
Object.keys(cases).forEach(function(name) {
320+
var expr = cases[name];
321+
it(name, function() {
322+
var actual = parser.parse(expr);
323+
should.strictEqual(typeof actual, "object");
324+
});
325+
});
326+
});
327+
describe("should parse await", function() {
328+
var cases = {
329+
"require": [
330+
"async function x() { await require('y'); }", {
331+
param: "y"
332+
}
333+
],
334+
"System.import": [
335+
"async function x() { var y = await System.import('z'); }", {
336+
param: "z"
337+
}
338+
]
339+
};
340+
341+
var parser = new Parser();
342+
parser.plugin("call require", function(expr) {
343+
var param = this.evaluateExpression(expr.arguments[0]);
344+
this.state.param = param.string;
345+
});
346+
parser.plugin("call System.import", function(expr) {
347+
var param = this.evaluateExpression(expr.arguments[0]);
348+
this.state.param = param.string;
349+
});
350+
351+
Object.keys(cases).forEach(function(name) {
352+
it(name, function() {
353+
var actual = parser.parse(cases[name][0]);
354+
actual.should.be.eql(cases[name][1]);
355+
});
356+
});
357+
});
358+
})
310359
});

0 commit comments

Comments
 (0)