/
parser-override.js
52 lines (46 loc) 路 1.32 KB
/
parser-override.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import path from "path";
import { fileURLToPath } from "url";
import * as babelESLint from "@babel/eslint-parser";
import * as babelESLintWorker from "@babel/eslint-parser/experimental-worker";
describe("parserOverride", () => {
const expectedAST = {
type: "Program",
body: [
{
type: "ExpressionStatement",
expression: {
type: "Identifier",
name: "foo",
},
},
],
};
const babel7node12 =
process.env.BABEL_8_BREAKING || parseInt(process.versions.node) < 12
? it.skip
: it;
it("works when parsing in the main thread", () => {
const { ast } = babelESLint.parseForESLint(`27`, {
filename: "input.js",
babelOptions: {
configFile: path.resolve(
path.dirname(fileURLToPath(import.meta.url)),
"../fixtures/parser-override/babel.config.json",
),
},
});
expect(ast).toMatchObject(expectedAST);
});
babel7node12("works when parsing in a worker", () => {
const { ast } = babelESLintWorker.parseForESLint(`27`, {
filename: "input.js",
babelOptions: {
configFile: path.resolve(
path.dirname(fileURLToPath(import.meta.url)),
"../fixtures/parser-override/babel.config.json",
),
},
});
expect(ast).toMatchObject(expectedAST);
});
});