diff --git a/.prettierignore b/.prettierignore new file mode 100644 index 000000000..d826961de --- /dev/null +++ b/.prettierignore @@ -0,0 +1 @@ +__tests__/fixture diff --git a/__tests__/__snapshots__/test.js.snap b/__tests__/__snapshots__/test.js.snap index e67531100..4472a6bb5 100644 --- a/__tests__/__snapshots__/test.js.snap +++ b/__tests__/__snapshots__/test.js.snap @@ -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 { @@ -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, @@ -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 [ diff --git a/__tests__/fixture/es6.input.js b/__tests__/fixture/es6.input.js index dde95b11e..a300409a2 100644 --- a/__tests__/fixture/es6.input.js +++ b/__tests__/fixture/es6.input.js @@ -172,3 +172,18 @@ export function isArrayEqualWith( 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; + } +} diff --git a/src/input/dependency.js b/src/input/dependency.js index e8f4f99b1..b1348c405 100644 --- a/src/input/dependency.js +++ b/src/input/dependency.js @@ -3,6 +3,7 @@ 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 = { @@ -10,6 +11,7 @@ const STANDARD_BABEL_CONFIG = { 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', @@ -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', diff --git a/src/parsers/parse_to_ast.js b/src/parsers/parse_to_ast.js index 6b8065be7..74b61d355 100644 --- a/src/parsers/parse_to_ast.js +++ b/src/parsers/parse_to_ast.js @@ -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' ] }; }