-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
/
parser-override.js
52 lines (46 loc) 路 1.42 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 { createRequire } from "module";
import * as babelESLint from "@babel/eslint-parser";
describe("parserOverride", () => {
const expectedAST = {
type: "Program",
body: [
{
type: "ExpressionStatement",
expression: {
type: "Identifier",
name: "foo",
},
},
],
};
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);
});
const babel7node12 = parseInt(process.versions.node) < 12 ? it.skip : it;
babel7node12("works when parsing in a worker", async () => {
const require = createRequire(import.meta.url);
// eslint-disable-next-line import/extensions
const babelESLintWorker = require("@babel/eslint-parser/experimental-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);
});
});