Skip to content

Commit 9baca8c

Browse files
authored
Enable V8 supported stage-3 syntax, as well as stage-4 syntax
* Enable Babel parser options directly, rather than through Babel syntax plugins * Enable stage-3 syntax supported in V8 * Enable stage-4 dynamic import syntax
1 parent 7fb0546 commit 9baca8c

File tree

10 files changed

+27
-74
lines changed

10 files changed

+27
-74
lines changed

lib/babel-pipeline.js

Lines changed: 27 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,26 @@ function validate(conf) {
5858
};
5959
}
6060

61+
function enableParserPlugins(api) {
62+
api.assertVersion(7);
63+
64+
return {
65+
name: 'ava-babel-pipeline-enable-parser-plugins',
66+
manipulateOptions(_, parserOpts) {
67+
parserOpts.plugins.push(
68+
'asyncGenerators',
69+
'bigInt',
70+
'classPrivateProperties',
71+
'classProperties',
72+
'dynamicImport',
73+
'numericSeparator',
74+
'objectRestSpread',
75+
'optionalCatchBinding'
76+
);
77+
}
78+
};
79+
}
80+
6181
// Compare actual values rather than file paths, which should be
6282
// more reliable.
6383
function makeValueChecker(ref) {
@@ -118,7 +138,12 @@ function hashPartialTestConfig({babelrc, config, options: {plugins, presets}}, p
118138
inputs.push(config, stripBomBuf(fs.readFileSync(config)));
119139
}
120140

121-
for (const {file: {resolved: filename}} of [...plugins, ...presets]) {
141+
for (const item of [...plugins, ...presets]) {
142+
if (!item.file) {
143+
continue;
144+
}
145+
146+
const {file: {resolved: filename}} = item;
122147
if (pluginAndPresetHashes.has(filename)) {
123148
inputs.push(pluginAndPresetHashes.get(filename));
124149
continue;
@@ -168,9 +193,6 @@ function build(projectDir, cacheDir, userOptions, compileEnhancements) {
168193
const pluginAndPresetHashes = new Map();
169194

170195
const ensureStage4 = wantsStage4(userOptions, projectDir);
171-
const containsAsyncGenerators = makeValueChecker('@babel/plugin-syntax-async-generators');
172-
const containsObjectRestSpread = makeValueChecker('@babel/plugin-syntax-object-rest-spread');
173-
const containsOptionalCatchBinding = makeValueChecker('@babel/plugin-syntax-optional-catch-binding');
174196
const containsStage4 = makeValueChecker('../stage-4');
175197
const containsTransformTestFiles = makeValueChecker('@ava/babel-preset-transform-test-files');
176198

@@ -193,17 +215,7 @@ function build(projectDir, cacheDir, userOptions, compileEnhancements) {
193215
}
194216

195217
const {options: testOptions} = partialTestConfig;
196-
if (!testOptions.plugins.some(containsAsyncGenerators)) { // TODO: Remove once Babel can parse this syntax unaided.
197-
testOptions.plugins.unshift(createConfigItem('@babel/plugin-syntax-async-generators', 'plugin'));
198-
}
199-
200-
if (!testOptions.plugins.some(containsObjectRestSpread)) { // TODO: Remove once Babel can parse this syntax unaided.
201-
testOptions.plugins.unshift(createConfigItem('@babel/plugin-syntax-object-rest-spread', 'plugin'));
202-
}
203-
204-
if (!testOptions.plugins.some(containsOptionalCatchBinding)) { // TODO: Remove once Babel can parse this syntax unaided.
205-
testOptions.plugins.unshift(createConfigItem('@babel/plugin-syntax-optional-catch-binding', 'plugin'));
206-
}
218+
testOptions.plugins.push(enableParserPlugins);
207219

208220
if (ensureStage4 && !testOptions.presets.some(containsStage4)) {
209221
// Apply last.

package-lock.json

Lines changed: 0 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,6 @@
6161
"@ava/babel-preset-transform-test-files": "^6.0.0",
6262
"@babel/core": "^7.5.5",
6363
"@babel/generator": "^7.5.5",
64-
"@babel/plugin-syntax-async-generators": "^7.2.0",
65-
"@babel/plugin-syntax-object-rest-spread": "^7.2.0",
66-
"@babel/plugin-syntax-optional-catch-binding": "^7.2.0",
6764
"@concordance/react": "^2.0.0",
6865
"ansi-escapes": "^4.2.1",
6966
"ansi-styles": "^4.0.0",

test/fixture/babel/with-explicit-syntax-plugins/async-generators/package.json

Lines changed: 0 additions & 10 deletions
This file was deleted.

test/fixture/babel/with-explicit-syntax-plugins/async-generators/test.js

Lines changed: 0 additions & 3 deletions
This file was deleted.

test/fixture/babel/with-explicit-syntax-plugins/object-rest-spread/package.json

Lines changed: 0 additions & 10 deletions
This file was deleted.

test/fixture/babel/with-explicit-syntax-plugins/object-rest-spread/test.js

Lines changed: 0 additions & 3 deletions
This file was deleted.

test/fixture/babel/with-explicit-syntax-plugins/optional-catch-binding/package.json

Lines changed: 0 additions & 10 deletions
This file was deleted.

test/fixture/babel/with-explicit-syntax-plugins/optional-catch-binding/test.js

Lines changed: 0 additions & 3 deletions
This file was deleted.

test/integration/babel.js

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,3 @@ test('includes relative paths in source map', t => {
4646
t.end();
4747
});
4848
});
49-
50-
for (const plugin of ['async-generators', 'object-rest-spread', 'optional-catch-binding']) {
51-
test(`avoids applying '@babel/plugin-syntax-${plugin}' if already in config`, t => {
52-
execCli([], {dirname: `fixture/babel/with-explicit-syntax-plugins/${plugin}`}, err => {
53-
t.ifError(err);
54-
t.end();
55-
});
56-
});
57-
}

0 commit comments

Comments
 (0)