summaryrefslogtreecommitdiff
path: root/src/compiler/parse/acorn.ts
blob: 966a137926099dcc0bdbdf8cb6d6d5a4330f2b11 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
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,
  });