Skip to content

Commit bf86c04

Browse files
committed
update: sync with merge changes from last commit
but ignore some pointless refactoring as 34c02a PS: duo to microsoft/TypeScript#12123, 9 testcases don't pass test. But it will pass with future typescript
1 parent bd397af commit bf86c04

8 files changed

+70
-33
lines changed

lib/Compilation.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1037,11 +1037,12 @@ class Compilation extends Tapable {
10371037
for (let i = 0; i < this.modules.length; i++) {
10381038
const module = this.modules[i];
10391039
if (module.assets) {
1040-
Object.keys(module.assets).forEach(function (name) {
1041-
const file = this.getPath(name);
1042-
this.assets[file] = module.assets[name];
1043-
this.applyPlugins('module-asset', module, file);
1044-
}, this);
1040+
Object.keys(module.assets)
1041+
.forEach(name => {
1042+
const file = this.getPath(name);
1043+
this.assets[file] = module.assets[name];
1044+
this.applyPlugins('module-asset', module, file);
1045+
});
10451046
}
10461047
}
10471048
}

lib/Parser.ts

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,12 @@ const POSSIBLE_AST_OPTIONS = [
2020
{
2121
ranges: true,
2222
locations: true,
23-
ecmaVersion: 6,
23+
ecmaVersion: 2017,
2424
sourceType: 'module'
2525
}, {
2626
ranges: true,
2727
locations: true,
28-
ecmaVersion: 6,
28+
ecmaVersion: 2017,
2929
sourceType: 'script'
3030
}
3131
] as ASTOPTION[];
@@ -829,6 +829,13 @@ class Parser extends Tapable {
829829
}
830830
}
831831

832+
walkAwaitExpression(expression) {
833+
const argument = expression.argument
834+
if (this["walk" + argument.type]) {
835+
return this["walk" + argument.type](argument);
836+
}
837+
}
838+
832839
walkSpreadElement(expression) {
833840
if (expression.argument) {
834841
this.walkExpression(expression.argument);
@@ -1105,7 +1112,7 @@ class Parser extends Tapable {
11051112
}
11061113

11071114
enterPattern(pattern, onIdent) {
1108-
if (this[`enter${pattern.type}`]) {
1115+
if (pattern != null && this[`enter${pattern.type}`]) {
11091116
return this[`enter${pattern.type}`](pattern, onIdent);
11101117
}
11111118
}
@@ -1251,7 +1258,7 @@ class Parser extends Tapable {
12511258
ast = acorn.parse(source, {
12521259
ranges: true,
12531260
locations: true,
1254-
ecmaVersion: 6,
1261+
ecmaVersion: 2017,
12551262
sourceType: 'module',
12561263
onComment: comments
12571264
});
@@ -1279,7 +1286,7 @@ class Parser extends Tapable {
12791286
const ast = acorn.parse(`(${source})`, {
12801287
ranges: true,
12811288
locations: true,
1282-
ecmaVersion: 6,
1289+
ecmaVersion: 2017,
12831290
sourceType: 'module'
12841291
});
12851292
if (!ast || typeof ast !== 'object' || ast.type !== 'Program') {

lib/RuleSet.ts

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
<condition>: { and: [<condition>] }
5252
<condition>: { or: [<condition>] }
5353
<condition>: { not: [<condition>] }
54-
<condition>: { test: <condition>, include: <condition>, exclude: <codition> }
54+
<condition>: { test: <condition>, include: <condition>, exclude: <condition> }
5555
5656
5757
normalized:
@@ -163,20 +163,33 @@ class RuleSet {
163163

164164
if (rule.test || rule.include || rule.exclude) {
165165
checkResourceSource('test + include + exclude');
166-
newRule.resource = RuleSet.normalizeCondition({
166+
let condition = {
167167
test: rule.test,
168168
include: rule.include,
169169
exclude: rule.exclude
170-
});
170+
};
171+
try {
172+
newRule.resource = RuleSet.normalizeCondition(condition);
173+
} catch(error) {
174+
throw new Error(RuleSet.buildErrorMessage(condition, error));
175+
}
171176
}
172177

173178
if (rule.resource) {
174179
checkResourceSource('resource');
175-
newRule.resource = RuleSet.normalizeCondition(rule.resource);
180+
try {
181+
newRule.resource = RuleSet.normalizeCondition(rule.resource);
182+
} catch(error) {
183+
throw new Error(RuleSet.buildErrorMessage(rule.resource, error));
184+
}
176185
}
177186

178187
if (rule.issuer) {
179-
newRule.issuer = RuleSet.normalizeCondition(rule.issuer);
188+
try {
189+
newRule.issuer = RuleSet.normalizeCondition(rule.issuer);
190+
} catch(error) {
191+
throw new Error(RuleSet.buildErrorMessage(rule.issuer, error));
192+
}
180193
}
181194

182195
if (rule.loader && rule.loaders) {
@@ -350,6 +363,15 @@ class RuleSet {
350363
return andMatcher(matchers);
351364
}
352365

366+
static buildErrorMessage(condition, error) {
367+
const conditionAsText = JSON.stringify(
368+
condition,
369+
(key, value) => value === undefined ? "undefined" : value,
370+
2
371+
)
372+
return error.message + " in " + conditionAsText;
373+
}
374+
353375
exec(data) {
354376
const result = [];
355377
this._run(data, {

lib/UmdMainTemplatePlugin.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ ${(externals.length > 0
153153
+
154154
`})(this, function(${externalsArguments(externals)}) {\nreturn `, 'webpack/universalModuleDefinition'),
155155
source,
156-
'\n});\n'
156+
';\n})'
157157
);
158158
});
159159
mainTemplate.plugin('global-hash-paths', paths => {

lib/WebpackOptionsDefaulter.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,6 @@ class WebpackOptionsDefaulter extends OptionsDefaulter {
9494
this.set('resolveLoader.unsafeCache', true);
9595
this.set('resolveLoader.mainFields', ['loader', 'main']);
9696
this.set('resolveLoader.extensions', ['.js', '.json']);
97-
this.set('resolveLoader.moduleExtensions', ['-loader']);
9897
}
9998
}
10099

lib/WebpackOptionsValidationError.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@ For loader options: webpack 2 no longer allows custom properties in configuratio
6565
return `${dataPath} should be a number.`;
6666
}
6767
return `${dataPath} should be ${err.params.type}:\n${getSchemaPartText(err.parentSchema)}`;
68+
case "instanceof":
69+
return `${dataPath} should be an instance of ${getSchemaPartText(err.parentSchema)}.`;
6870
case 'required':
6971
const missingProperty = err.params.missingProperty.replace(/^\./, '');
7072
return `${dataPath} misses the property '${missingProperty}'.\n${getSchemaPartText(err.parentSchema, [

lib/validateWebpackOptions.ts renamed to lib/validateSchema.ts

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,26 @@
11
/*
2-
MIT License http://www.opensource.org/licenses/mit-license.php
3-
Author Gajus Kuizinas @gajus
4-
*/
2+
MIT License http://www.opensource.org/licenses/mit-license.php
3+
Author Gajus Kuizinas @gajus
4+
*/
55
import Ajv = require('ajv');
6-
const webpackOptionsSchema = require('../schemas/webpackOptionsSchema.json');
6+
import defineKeywords = require('ajv-keywords')
77

88
const ajv = new Ajv({
99
errorDataPath: 'configuration',
1010
allErrors: true,
1111
verbose: true
1212
});
1313

14-
const validate = ajv.compile(webpackOptionsSchema);
14+
defineKeywords(ajv);
1515

16-
function validateWebpackOptions(options) {
16+
function validateSchema(schema, options) {
17+
const validate = ajv.compile(schema);
1718
if (Array.isArray(options)) {
1819
const errors = options.map(validateObject);
19-
errors.forEach((list, idx) => {
20+
21+
errors.forEach(function (list, idx) {
2022
list.forEach(function applyPrefix(err) {
21-
err.dataPath = `[${idx}]${err.dataPath}`;
23+
err.dataPath = "[" + idx + "]" + err.dataPath;
2224
if (err.children) {
2325
err.children.forEach(applyPrefix);
2426
}
@@ -29,11 +31,11 @@ function validateWebpackOptions(options) {
2931
else {
3032
return validateObject(options);
3133
}
32-
}
3334

34-
function validateObject(options) {
35-
const valid = validate(options);
36-
return valid ? [] : filterErrors(validate.errors);
35+
function validateObject(options) {
36+
const valid = validate(options);
37+
return valid ? [] : filterErrors(validate.errors);
38+
}
3739
}
3840

3941
function filterErrors(errors) {
@@ -62,4 +64,4 @@ function filterErrors(errors) {
6264
return newErrors;
6365
}
6466

65-
export = validateWebpackOptions;
67+
export = validateSchema;

lib/webpack.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,16 @@ import MultiCompiler = require('./MultiCompiler');
77
import NodeEnvironmentPlugin = require('./node/NodeEnvironmentPlugin');
88
import WebpackOptionsApply = require('./WebpackOptionsApply');
99
import WebpackOptionsDefaulter = require('./WebpackOptionsDefaulter');
10-
import validateWebpackOptions = require('./validateWebpackOptions');
10+
import validateSchema = require("./validateSchema");
1111
import WebpackOptionsValidationError = require('./WebpackOptionsValidationError');
1212

13+
const webpackOptionsSchema = require("../schemas/webpackOptionsSchema.json");
14+
1315
function webpack(options, callback): Watching
1416
function webpack(options): MultiCompiler | Compiler
1517

1618
function webpack(options, callback?) {
17-
const webpackOptionsValidationErrors = validateWebpackOptions(options);
19+
const webpackOptionsValidationErrors = validateSchema(webpackOptionsSchema, options);
1820
if (webpackOptionsValidationErrors.length) {
1921
throw new WebpackOptionsValidationError(webpackOptionsValidationErrors);
2022
}
@@ -57,7 +59,9 @@ webpack.WebpackOptionsApply = WebpackOptionsApply;
5759
webpack.Compiler = Compiler;
5860
webpack.MultiCompiler = MultiCompiler;
5961
webpack.NodeEnvironmentPlugin = NodeEnvironmentPlugin;
60-
webpack.validate = validateWebpackOptions;
62+
webpack.validate = validateSchema.bind(this, webpackOptionsSchema);
63+
webpack.validateSchema = validateSchema;
64+
webpack.WebpackOptionsValidationError = WebpackOptionsValidationError;
6165

6266
function exportPlugins(exports, path, plugins) {
6367
plugins.forEach(name => {

0 commit comments

Comments
 (0)