1 1
import { parse, ParserOptions } from '@babel/parser'
2
import * as bt from '@babel/types'
3

4 1
const babelParserOptions: ParserOptions = {
5
	sourceType: 'module',
6
	strictMode: false,
7
	tokens: true,
8
	plugins: [
9
		'decorators-legacy',
10
		'doExpressions',
11
		'objectRestSpread',
12
		'classProperties',
13
		'classPrivateProperties',
14
		'classPrivateMethods',
15
		'exportDefaultFrom',
16
		'exportNamespaceFrom',
17
		'asyncGenerators',
18
		'functionBind',
19
		'functionSent',
20
		'dynamicImport',
21
		'numericSeparator',
22
		'optionalChaining',
23
		'importMeta',
24
		'bigInt',
25
		'optionalCatchBinding',
26
		'throwExpressions',
27
		'nullishCoalescingOperator'
28
	]
29
}
30

31 1
export default function buildParse(
32 1
	options: ParserOptions = {}
33
): { parse: (src: string) => bt.File } {
34 1
	options = {
35
		...babelParserOptions,
36
		...options,
37 1
		plugins: [...(babelParserOptions.plugins || []), ...(options.plugins || [])]
38
	}
39 1
	return {
40 1
		parse(src: string): bt.File {
41 1
			return parse(src, options)
42
		}
43
	}
44
}

Read our documentation on viewing source code .

Loading