1 | "use strict";
|
2 |
|
3 | exports.__esModule = true;
|
4 | exports.getBabelParserOptions = getBabelParserOptions;
|
5 | exports.babelParseToAst = babelParseToAst;
|
6 |
|
7 | const parser = require(`@babel/parser`);
|
8 |
|
9 | const PARSER_OPTIONS = {
|
10 | allowImportExportEverywhere: true,
|
11 | allowReturnOutsideFunction: true,
|
12 | allowSuperOutsideMethod: true,
|
13 | sourceType: `unambigious`,
|
14 | sourceFilename: true,
|
15 | plugins: [`jsx`, `flow`, `doExpressions`, `objectRestSpread`, [`decorators`, {
|
16 | decoratorsBeforeExport: true
|
17 | }], `classProperties`, `classPrivateProperties`, `classPrivateMethods`, `exportDefaultFrom`, `exportNamespaceFrom`, `asyncGenerators`, `functionBind`, `functionSent`, `dynamicImport`, `numericSeparator`, `optionalChaining`, `importMeta`, `bigInt`, `optionalCatchBinding`, `throwExpressions`, [`pipelineOperator`, {
|
18 | proposal: `minimal`
|
19 | }], `nullishCoalescingOperator`]
|
20 | };
|
21 |
|
22 | function getBabelParserOptions(filePath) {
|
23 |
|
24 | if (/\.tsx?/.test(filePath)) {
|
25 | const {
|
26 | plugins
|
27 | } = PARSER_OPTIONS;
|
28 | return Object.assign({}, PARSER_OPTIONS, {
|
29 | plugins: plugins.map(plugin => plugin === `flow` ? `typescript` : plugin)
|
30 | });
|
31 | }
|
32 |
|
33 | return PARSER_OPTIONS;
|
34 | }
|
35 |
|
36 | function babelParseToAst(contents, filePath) {
|
37 | return parser.parse(contents, getBabelParserOptions(filePath));
|
38 | }
|
39 |
|
\ | No newline at end of file |