Make resolveParser work like v2 (#13732)
This commit is contained in:
1 parent
930cf29d15
commit
b7223354a1
2 files changed
+24
-1
No files matched your search
+7
-1
@@ -1,7 +1,13 @@
|
||||
import { ConfigError } from "../common/errors.js";
|
||||
|
||||
function resolveParser({ plugins, parser }) {
|
||||
for (const { parsers } of plugins) {
|
||||
/*
|
||||
Loop from end to allow plugins override builtin plugins,
|
||||
this is how `resolveParser` works in v2.
|
||||
This is a temporarily solution, see #13729
|
||||
*/
|
||||
for (let index = plugins.length - 1; index >= 0; index--) {
|
||||
const { parsers } = plugins[index];
|
||||
if (parsers && Object.hasOwn(parsers, parser)) {
|
||||
const parserOrParserInitFunction = parsers[parser];
|
||||
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
import prettier from "../../config/prettier-entry.js";
|
||||
import createPlugin from "../../config/utils/create-plugin.cjs";
|
||||
|
||||
test("plugins can override builtin plugins", async () => {
|
||||
const outputWithoutPlugin = await prettier.format("foo()", {
|
||||
parser: "babel",
|
||||
});
|
||||
const outputWithPlugin = await prettier.format("foo()", {
|
||||
parser: "babel",
|
||||
plugins: [
|
||||
createPlugin({ name: "babel", print: () => "fake-babel-output" }),
|
||||
],
|
||||
});
|
||||
|
||||
expect(outputWithoutPlugin).not.toBe(outputWithPlugin);
|
||||
expect(outputWithPlugin).toBe("fake-babel-output\n");
|
||||
});
|
||||
Reference in new issue
Block a user