Skip to content

Commit fa1b0b5

Browse files
committed
feat: Enable all parser plugins
BREAKING CHANGE: this removes support for legacy decorators, because in one place we had legacy and in another we didn't.
1 parent 8fa141d commit fa1b0b5

File tree

5 files changed

+200
-19
lines changed

5 files changed

+200
-19
lines changed

.prettierignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
__tests__/fixture

__tests__/__snapshots__/test.js.snap

+151-2
Original file line numberDiff line numberDiff line change
@@ -11111,10 +11111,114 @@ It takes a ",
1111111111
"todos": Array [],
1111211112
"yields": Array [],
1111311113
},
11114+
Object {
11115+
"augments": Array [],
11116+
"context": Object {
11117+
"loc": Object {
11118+
"end": Object {
11119+
"column": 1,
11120+
"line": 189,
11121+
},
11122+
"start": Object {
11123+
"column": 0,
11124+
"line": 177,
11125+
},
11126+
},
11127+
},
11128+
"description": Object {
11129+
"children": Array [
11130+
Object {
11131+
"children": Array [
11132+
Object {
11133+
"position": Object {
11134+
"end": Object {
11135+
"column": 21,
11136+
"line": 1,
11137+
"offset": 20,
11138+
},
11139+
"indent": Array [],
11140+
"start": Object {
11141+
"column": 1,
11142+
"line": 1,
11143+
"offset": 0,
11144+
},
11145+
},
11146+
"type": "text",
11147+
"value": "babel parser plugins",
11148+
},
11149+
],
11150+
"position": Object {
11151+
"end": Object {
11152+
"column": 21,
11153+
"line": 1,
11154+
"offset": 20,
11155+
},
11156+
"indent": Array [],
11157+
"start": Object {
11158+
"column": 1,
11159+
"line": 1,
11160+
"offset": 0,
11161+
},
11162+
},
11163+
"type": "paragraph",
11164+
},
11165+
],
11166+
"position": Object {
11167+
"end": Object {
11168+
"column": 21,
11169+
"line": 1,
11170+
"offset": 20,
11171+
},
11172+
"start": Object {
11173+
"column": 1,
11174+
"line": 1,
11175+
"offset": 0,
11176+
},
11177+
},
11178+
"type": "root",
11179+
},
11180+
"errors": Array [],
11181+
"examples": Array [],
11182+
"implements": Array [],
11183+
"kind": "class",
11184+
"loc": Object {
11185+
"end": Object {
11186+
"column": 27,
11187+
"line": 176,
11188+
},
11189+
"start": Object {
11190+
"column": 0,
11191+
"line": 176,
11192+
},
11193+
},
11194+
"members": Object {
11195+
"events": Array [],
11196+
"global": Array [],
11197+
"inner": Array [],
11198+
"instance": Array [],
11199+
"static": Array [],
11200+
},
11201+
"name": "A",
11202+
"namespace": "A",
11203+
"params": Array [],
11204+
"path": Array [
11205+
Object {
11206+
"kind": "class",
11207+
"name": "A",
11208+
},
11209+
],
11210+
"properties": Array [],
11211+
"returns": Array [],
11212+
"sees": Array [],
11213+
"tags": Array [],
11214+
"throws": Array [],
11215+
"todos": Array [],
11216+
"yields": Array [],
11217+
},
1111411218
]
1111511219
`;
1111611220

11117-
exports[`outputs es6.input.js markdown 1`] = `"[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]"`;
11221+
exports[`outputs es6.input.js markdown 1`] = `"[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]"`;
1111811222

1111911223
exports[`outputs es6.input.js markdown AST 1`] = `
1112011224
Object {
@@ -13585,6 +13689,51 @@ It takes a ",
1358513689
],
1358613690
"type": "paragraph",
1358713691
},
13692+
Object {
13693+
"children": Array [
13694+
Object {
13695+
"type": "text",
13696+
"value": "A",
13697+
},
13698+
],
13699+
"depth": 2,
13700+
"type": "heading",
13701+
},
13702+
Object {
13703+
"children": Array [
13704+
Object {
13705+
"position": Position {
13706+
"end": Object {
13707+
"column": 21,
13708+
"line": 1,
13709+
"offset": 20,
13710+
},
13711+
"indent": Array [],
13712+
"start": Object {
13713+
"column": 1,
13714+
"line": 1,
13715+
"offset": 0,
13716+
},
13717+
},
13718+
"type": "text",
13719+
"value": "babel parser plugins",
13720+
},
13721+
],
13722+
"position": Position {
13723+
"end": Object {
13724+
"column": 21,
13725+
"line": 1,
13726+
"offset": 20,
13727+
},
13728+
"indent": Array [],
13729+
"start": Object {
13730+
"column": 1,
13731+
"line": 1,
13732+
"offset": 0,
13733+
},
13734+
},
13735+
"type": "paragraph",
13736+
},
1358813737
Object {
1358913738
"identifier": "1",
1359013739
"title": undefined,
@@ -13638,7 +13787,7 @@ It takes a ",
1363813787
}
1363913788
`;
1364013789

13641-
exports[`outputs es6.input.js no markdown TOC 1`] = `"[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]"`;
13790+
exports[`outputs es6.input.js no markdown TOC 1`] = `"[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]"`;
1364213791

1364313792
exports[`outputs es6-class.input.js JSON 1`] = `
1364413793
Array [

__tests__/fixture/es6.input.js

+15
Original file line numberDiff line numberDiff line change
@@ -172,3 +172,18 @@ export function isArrayEqualWith<T>(
172172
export function paramWithMemberType(a: atype.property): boolean {
173173
return true;
174174
}
175+
176+
/** babel parser plugins */
177+
class A {
178+
// classPrivateProperties
179+
#b = 1;
180+
// classPrivateMethods
181+
#c(a, b) {
182+
// numericSeparator
183+
let y = 100_000;
184+
// nullishCoalescingOperator
185+
let x = a ?? b;
186+
// logicalAssignment
187+
return x &&= b?.b |> String.fromCharCode;
188+
}
189+
}

src/input/dependency.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,15 @@ const path = require('path');
33
const babelify = require('babelify');
44
const concat = require('concat-stream');
55
const moduleFilters = require('../module_filters');
6+
const { standardBabelParserPlugins } = require('../parsers/parse_to_ast');
67
const smartGlob = require('../smart_glob.js');
78

89
const STANDARD_BABEL_CONFIG = {
910
sourceMaps: false,
1011
compact: false,
1112
cwd: path.resolve(__dirname, '../../'),
1213
presets: ['@babel/preset-react', '@babel/preset-env', '@babel/preset-flow'],
14+
parserOpts: { plugins: standardBabelParserPlugins },
1315
plugins: [
1416
// Stage 0
1517
'@babel/plugin-proposal-function-bind',
@@ -21,7 +23,7 @@ const STANDARD_BABEL_CONFIG = {
2123
['@babel/plugin-proposal-nullish-coalescing-operator', { loose: false }],
2224
'@babel/plugin-proposal-do-expressions',
2325
// Stage 2
24-
['@babel/plugin-proposal-decorators', { legacy: true }],
26+
['@babel/plugin-proposal-decorators', { decoratorsBeforeExport: true }],
2527
'@babel/plugin-proposal-function-sent',
2628
'@babel/plugin-proposal-export-namespace-from',
2729
'@babel/plugin-proposal-numeric-separator',

src/parsers/parse_to_ast.js

+30-16
Original file line numberDiff line numberDiff line change
@@ -6,28 +6,42 @@ const TYPESCRIPT_EXTS = {
66
'.tsx': true
77
};
88

9+
const standardBabelParserPlugins = [
10+
'asyncGenerators',
11+
'bigInt',
12+
'classProperties',
13+
'classConstructorCall',
14+
'classPrivateProperties',
15+
'classPrivateMethods',
16+
'doExpressions',
17+
'dynamicImport',
18+
'exportDefaultFrom',
19+
'exportNamespaceFrom',
20+
'exportExtensions',
21+
'functionBind',
22+
'functionSent',
23+
'jsx',
24+
'logicalAssignment',
25+
'nullishCoalescingOperator',
26+
'numericSeparator',
27+
'objectRestSpread',
28+
'optionalCatchBinding',
29+
'optionalChaining',
30+
'partialApplication',
31+
['pipelineOperator', { proposal: 'minimal' }],
32+
'throwExpressions'
33+
];
34+
35+
module.exports.standardBabelParserPlugins = standardBabelParserPlugins;
36+
937
function getParserOpts(file) {
1038
return {
1139
allowImportExportEverywhere: true,
1240
sourceType: 'module',
1341
plugins: [
14-
'asyncGenerators',
15-
'exportDefaultFrom',
16-
'exportNamespaceFrom',
17-
'optionalChaining',
18-
'classConstructorCall',
19-
'classPrivateProperties',
20-
'classProperties',
42+
...standardBabelParserPlugins,
2143
['decorators', { decoratorsBeforeExport: false }],
22-
'doExpressions',
23-
'exportExtensions',
24-
TYPESCRIPT_EXTS[path.extname(file || '')] ? 'typescript' : 'flow',
25-
'functionBind',
26-
'functionSent',
27-
'jsx',
28-
'objectRestSpread',
29-
'dynamicImport',
30-
'logicalAssignment'
44+
TYPESCRIPT_EXTS[path.extname(file || '')] ? 'typescript' : 'flow'
3145
]
3246
};
3347
}

0 commit comments

Comments
 (0)