Skip to content

Commit

Permalink
feat: Enable all parser plugins
Browse files Browse the repository at this point in the history
BREAKING CHANGE: this removes support for legacy decorators, because
in one place we had legacy and in another we didn't.
  • Loading branch information
tmcw committed May 7, 2019
1 parent 8fa141d commit fa1b0b5
Show file tree
Hide file tree
Showing 5 changed files with 200 additions and 19 deletions.
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
__tests__/fixture
153 changes: 151 additions & 2 deletions __tests__/__snapshots__/test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -11111,10 +11111,114 @@ It takes a ",
"todos": Array [],
"yields": Array [],
},
Object {
"augments": Array [],
"context": Object {
"loc": Object {
"end": Object {
"column": 1,
"line": 189,
},
"start": Object {
"column": 0,
"line": 177,
},
},
},
"description": Object {
"children": Array [
Object {
"children": Array [
Object {
"position": Object {
"end": Object {
"column": 21,
"line": 1,
"offset": 20,
},
"indent": Array [],
"start": Object {
"column": 1,
"line": 1,
"offset": 0,
},
},
"type": "text",
"value": "babel parser plugins",
},
],
"position": Object {
"end": Object {
"column": 21,
"line": 1,
"offset": 20,
},
"indent": Array [],
"start": Object {
"column": 1,
"line": 1,
"offset": 0,
},
},
"type": "paragraph",
},
],
"position": Object {
"end": Object {
"column": 21,
"line": 1,
"offset": 20,
},
"start": Object {
"column": 1,
"line": 1,
"offset": 0,
},
},
"type": "root",
},
"errors": Array [],
"examples": Array [],
"implements": Array [],
"kind": "class",
"loc": Object {
"end": Object {
"column": 27,
"line": 176,
},
"start": Object {
"column": 0,
"line": 176,
},
},
"members": Object {
"events": Array [],
"global": Array [],
"inner": Array [],
"instance": Array [],
"static": Array [],
},
"name": "A",
"namespace": "A",
"params": Array [],
"path": Array [
Object {
"kind": "class",
"name": "A",
},
],
"properties": Array [],
"returns": Array [],
"sees": Array [],
"tags": Array [],
"throws": Array [],
"todos": Array [],
"yields": Array [],
},
]
`;

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]"`;
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]"`;

exports[`outputs es6.input.js markdown AST 1`] = `
Object {
Expand Down Expand Up @@ -13585,6 +13689,51 @@ It takes a ",
],
"type": "paragraph",
},
Object {
"children": Array [
Object {
"type": "text",
"value": "A",
},
],
"depth": 2,
"type": "heading",
},
Object {
"children": Array [
Object {
"position": Position {
"end": Object {
"column": 21,
"line": 1,
"offset": 20,
},
"indent": Array [],
"start": Object {
"column": 1,
"line": 1,
"offset": 0,
},
},
"type": "text",
"value": "babel parser plugins",
},
],
"position": Position {
"end": Object {
"column": 21,
"line": 1,
"offset": 20,
},
"indent": Array [],
"start": Object {
"column": 1,
"line": 1,
"offset": 0,
},
},
"type": "paragraph",
},
Object {
"identifier": "1",
"title": undefined,
Expand Down Expand Up @@ -13638,7 +13787,7 @@ It takes a ",
}
`;

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]"`;
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]"`;

exports[`outputs es6-class.input.js JSON 1`] = `
Array [
Expand Down
15 changes: 15 additions & 0 deletions __tests__/fixture/es6.input.js
Original file line number Diff line number Diff line change
Expand Up @@ -172,3 +172,18 @@ export function isArrayEqualWith<T>(
export function paramWithMemberType(a: atype.property): boolean {
return true;
}

/** babel parser plugins */
class A {
// classPrivateProperties
#b = 1;
// classPrivateMethods
#c(a, b) {
// numericSeparator
let y = 100_000;
// nullishCoalescingOperator
let x = a ?? b;
// logicalAssignment
return x &&= b?.b |> String.fromCharCode;
}
}
4 changes: 3 additions & 1 deletion src/input/dependency.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@ const path = require('path');
const babelify = require('babelify');
const concat = require('concat-stream');
const moduleFilters = require('../module_filters');
const { standardBabelParserPlugins } = require('../parsers/parse_to_ast');
const smartGlob = require('../smart_glob.js');

const STANDARD_BABEL_CONFIG = {
sourceMaps: false,
compact: false,
cwd: path.resolve(__dirname, '../../'),
presets: ['@babel/preset-react', '@babel/preset-env', '@babel/preset-flow'],
parserOpts: { plugins: standardBabelParserPlugins },
plugins: [
// Stage 0
'@babel/plugin-proposal-function-bind',
Expand All @@ -21,7 +23,7 @@ const STANDARD_BABEL_CONFIG = {
['@babel/plugin-proposal-nullish-coalescing-operator', { loose: false }],
'@babel/plugin-proposal-do-expressions',
// Stage 2
['@babel/plugin-proposal-decorators', { legacy: true }],
['@babel/plugin-proposal-decorators', { decoratorsBeforeExport: true }],
'@babel/plugin-proposal-function-sent',
'@babel/plugin-proposal-export-namespace-from',
'@babel/plugin-proposal-numeric-separator',
Expand Down
46 changes: 30 additions & 16 deletions src/parsers/parse_to_ast.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,28 +6,42 @@ const TYPESCRIPT_EXTS = {
'.tsx': true
};

const standardBabelParserPlugins = [
'asyncGenerators',
'bigInt',
'classProperties',
'classConstructorCall',
'classPrivateProperties',
'classPrivateMethods',
'doExpressions',
'dynamicImport',
'exportDefaultFrom',
'exportNamespaceFrom',
'exportExtensions',
'functionBind',
'functionSent',
'jsx',
'logicalAssignment',
'nullishCoalescingOperator',
'numericSeparator',
'objectRestSpread',
'optionalCatchBinding',
'optionalChaining',
'partialApplication',
['pipelineOperator', { proposal: 'minimal' }],
'throwExpressions'
];

module.exports.standardBabelParserPlugins = standardBabelParserPlugins;

function getParserOpts(file) {
return {
allowImportExportEverywhere: true,
sourceType: 'module',
plugins: [
'asyncGenerators',
'exportDefaultFrom',
'exportNamespaceFrom',
'optionalChaining',
'classConstructorCall',
'classPrivateProperties',
'classProperties',
...standardBabelParserPlugins,
['decorators', { decoratorsBeforeExport: false }],
'doExpressions',
'exportExtensions',
TYPESCRIPT_EXTS[path.extname(file || '')] ? 'typescript' : 'flow',
'functionBind',
'functionSent',
'jsx',
'objectRestSpread',
'dynamicImport',
'logicalAssignment'
TYPESCRIPT_EXTS[path.extname(file || '')] ? 'typescript' : 'flow'
]
};
}
Expand Down

0 comments on commit fa1b0b5

Please sign in to comment.