Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6393e60
commit 531db5d
Showing
4 changed files
with
68 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 3 additions & 0 deletions
3
eslint/babel-eslint-tests/test/fixtures/parser-override/babel.config.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"plugins": ["./plugin.js"] | ||
} |
9 changes: 9 additions & 0 deletions
9
eslint/babel-eslint-tests/test/fixtures/parser-override/plugin.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
const parser = require("@babel/parser"); | ||
|
||
module.exports = function () { | ||
return { | ||
parserOverride(code, opts) { | ||
return parser.parse(`foo;`, opts); | ||
}, | ||
}; | ||
}; |
51 changes: 51 additions & 0 deletions
51
eslint/babel-eslint-tests/test/integration/parser-override.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
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); | ||
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); | ||
}); | ||
}); |