1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 | 'use strict';
|
10 |
|
11 | const babylon = require('@babel/parser');
|
12 |
|
13 | const defaultOptions = {
|
14 | sourceType: 'module',
|
15 | allowImportExportEverywhere: true,
|
16 | allowReturnOutsideFunction: true,
|
17 | startLine: 1,
|
18 | tokens: true,
|
19 | plugins: [
|
20 | ['flow', {all: true}],
|
21 | 'flowComments',
|
22 | 'jsx',
|
23 |
|
24 | 'asyncGenerators',
|
25 | 'bigInt',
|
26 | 'classProperties',
|
27 | 'classPrivateProperties',
|
28 | 'classPrivateMethods',
|
29 | ['decorators', {decoratorsBeforeExport: false}],
|
30 | 'doExpressions',
|
31 | 'dynamicImport',
|
32 | 'exportDefaultFrom',
|
33 | 'exportNamespaceFrom',
|
34 | 'functionBind',
|
35 | 'functionSent',
|
36 | 'importMeta',
|
37 | 'logicalAssignment',
|
38 | 'nullishCoalescingOperator',
|
39 | 'numericSeparator',
|
40 | 'objectRestSpread',
|
41 | 'optionalCatchBinding',
|
42 | 'optionalChaining',
|
43 | ['pipelineOperator', {proposal: 'minimal'}],
|
44 | 'throwExpressions',
|
45 | ],
|
46 | };
|
47 |
|
48 |
|
49 |
|
50 |
|
51 | module.exports = function(options=defaultOptions) {
|
52 | return {
|
53 | parse(code) {
|
54 | return babylon.parse(code, options);
|
55 | },
|
56 | };
|
57 | };
|