Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix
parserOverride
support in @babel/eslint-parser
- Loading branch information
1 parent
5b29557
commit 7692378
Showing
4 changed files
with
64 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); | ||
}, | ||
}; | ||
}; |
47 changes: 47 additions & 0 deletions
47
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,47 @@ | ||
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", | ||
}, | ||
}, | ||
], | ||
}; | ||
|
||
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); | ||
}); | ||
|
||
it("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); | ||
}); | ||
}); |