summaryrefslogtreecommitdiff
path: root/src/compiler/parse/acorn.ts
blob: f017b6dece0c907abe96f088eaf602585bbea7f8 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
import { Node } from 'acorn';
import acorn from 'acorn';
// @ts-ignore
import jsx from 'acorn-jsx';

const acornJsx = acorn.Parser.extend(jsx());

export const parse = (source: string): Node => acorn.parse(source, {
	sourceType: 'module',
	ecmaVersion: 2020,
	locations: true
});

export const parse_expression_at = (source: string, index: number): Node => acornJsx.parseExpressionAt(source, index, {
	sourceType: 'module',
	ecmaVersion: 2020,
	locations: true
});