fix(api): no regression for deprecated parser (#4072)
This commit is contained in:
3 files changed
+45
-2
No files matched your search
+13
-2
@@ -26,7 +26,8 @@ function normalize(options, opts) {
|
||||
const supportOptions = getSupportInfo(null, {
|
||||
plugins,
|
||||
pluginsLoaded: true,
|
||||
showUnreleased: true
|
||||
showUnreleased: true,
|
||||
showDeprecated: true
|
||||
}).options;
|
||||
const defaults = supportOptions.reduce(
|
||||
(reduced, optionInfo) =>
|
||||
@@ -49,10 +50,20 @@ function normalize(options, opts) {
|
||||
}
|
||||
}
|
||||
|
||||
const parser = resolveParser(rawOptions);
|
||||
const parser = resolveParser(
|
||||
!rawOptions.parser
|
||||
? rawOptions
|
||||
: // handle deprecated parsers
|
||||
normalizer.normalizeApiOptions(
|
||||
rawOptions,
|
||||
[supportOptions.find(x => x.name === "parser")],
|
||||
{ passThrough: true, logger: false }
|
||||
)
|
||||
);
|
||||
rawOptions.astFormat = parser.astFormat;
|
||||
rawOptions.locEnd = parser.locEnd;
|
||||
rawOptions.locStart = parser.locStart;
|
||||
|
||||
const plugin = getPlugin(rawOptions);
|
||||
rawOptions.printer = plugin.printers[rawOptions.astFormat];
|
||||
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||
|
||||
exports[`API format with deprecated parser should work 1`] = `
|
||||
"\`{ \\"parser\\": \\"postcss\\" }\` is deprecated. Prettier now treats it as \`{ \\"parser\\": \\"css\\" }\`.
|
||||
"
|
||||
`;
|
||||
@@ -0,0 +1,26 @@
|
||||
"use strict";
|
||||
|
||||
const prettier = require("../../tests_config/require_prettier");
|
||||
|
||||
let warnings = "";
|
||||
|
||||
beforeAll(() => {
|
||||
jest
|
||||
.spyOn(console, "warn")
|
||||
.mockImplementation(text => (warnings += text + "\n"));
|
||||
});
|
||||
|
||||
beforeEach(() => {
|
||||
warnings = "";
|
||||
});
|
||||
|
||||
afterAll(() => {
|
||||
jest.restoreAllMocks();
|
||||
});
|
||||
|
||||
test("API format with deprecated parser should work", () => {
|
||||
expect(() =>
|
||||
prettier.format("body { color: #131313; }", { parser: "postcss" })
|
||||
).not.toThrowError();
|
||||
expect(warnings).toMatchSnapshot();
|
||||
});
|
||||
Reference in new issue
Block a user