Skip to content

Commit

Permalink
Fixup getSupportInfo for babylon parser prior to 1.16.0 (#5826)
Browse files Browse the repository at this point in the history
This undoes an accidental breaking change where `prettier.getSupportInfo('1.0.0')` would report supporting the `babel` parser instead of `babylon`.

Fixes #5822
  • Loading branch information
azz authored and ikatyang committed Feb 3, 2019
1 parent 94e2617 commit 29799e5
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 14 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.unreleased.md
Expand Up @@ -41,3 +41,7 @@ Examples:
```
-->

- API: Fix `prettier.getSupportInfo()` reporting babel parser for older versions of Prettier. ([#5826] by [@azz])

In version `1.16.0` of Prettier, the `babylon` parser was renamed to `babel`. Unfortunately this lead to a minor breaking change: `prettier.getSupportInfo('1.15.0')` would report that it supported `babel`, not `babylon`, which breaks text-editor integrations. This has now been fixed.
10 changes: 10 additions & 0 deletions src/main/support.js
Expand Up @@ -75,6 +75,7 @@ function getSupportInfo(version, opts) {
});

const usePostCssParser = semver.lt(version, "1.7.1");
const useBabylonParser = semver.lt(version, "1.16.0");

const languages = plugins
.reduce((all, plugin) => all.concat(plugin.languages || []), [])
Expand All @@ -92,6 +93,15 @@ function getSupportInfo(version, opts) {
});
}

// "babylon" was renamed to "babel" in 1.16.0
if (useBabylonParser && language.parsers.indexOf("babel") !== -1) {
return Object.assign({}, language, {
parsers: language.parsers.map(parser =>
parser === "babel" ? "babylon" : parser
)
});
}

if (
usePostCssParser &&
(language.name === "CSS" || language.group === "CSS")
Expand Down
36 changes: 22 additions & 14 deletions tests_integration/__tests__/__snapshots__/support-info.js.snap
Expand Up @@ -67,15 +67,15 @@ exports[`API getSupportInfo() with version 0.0.0 1`] = `
Object {
"languages": Object {
"Flow": Array [
"babel",
"babylon",
"flow",
],
"JSX": Array [
"babel",
"babylon",
"flow",
],
"JavaScript": Array [
"babel",
"babylon",
"flow",
],
},
Expand Down Expand Up @@ -137,14 +137,14 @@ exports[`API getSupportInfo() with version 1.0.0 -> 1.4.0 1`] = `
+ \\"postcss\\",
+ ],
\\"Flow\\": Array [
\\"babel\\",
\\"babylon\\",
\\"flow\\",
],
\\"JSX\\": Array [
@@ -10,24 +13,51 @@
],
\\"JavaScript\\": Array [
\\"babel\\",
\\"babylon\\",
\\"flow\\",
],
+ \\"Less\\": Array [
Expand Down Expand Up @@ -232,7 +232,7 @@ exports[`API getSupportInfo() with version 1.4.0 -> 1.5.0 1`] = `
@@ -5,10 +5,19 @@
],
\\"Flow\\": Array [
\\"babel\\",
\\"babylon\\",
\\"flow\\",
],
+ \\"GraphQL\\": Array [
Expand All @@ -245,7 +245,7 @@ exports[`API getSupportInfo() with version 1.4.0 -> 1.5.0 1`] = `
+ \\"json\\",
+ ],
\\"JSX\\": Array [
\\"babel\\",
\\"babylon\\",
\\"flow\\",
],
\\"JavaScript\\": Array [
Expand Down Expand Up @@ -277,12 +277,12 @@ exports[`API getSupportInfo() with version 1.5.0 -> 1.7.1 1`] = `
+ \\"css\\",
],
\\"Flow\\": Array [
\\"babel\\",
\\"babylon\\",
\\"flow\\",
],
@@ -23,17 +23,17 @@
\\"JavaScript\\": Array [
\\"babel\\",
\\"babylon\\",
\\"flow\\",
],
\\"Less\\": Array [
Expand Down Expand Up @@ -407,12 +407,12 @@ exports[`API getSupportInfo() with version 1.8.0 -> 1.8.2 1`] = `
\\"start\\": 0,"
`;
exports[`API getSupportInfo() with version 1.8.2 -> undefined 1`] = `
exports[`API getSupportInfo() with version 1.8.2 -> 1.16.0 1`] = `
"Snapshot Diff:
- First value
+ Second value
@@ -1,23 +1,35 @@
@@ -1,34 +1,49 @@
Object {
\\"languages\\": Object {
+ \\"Angular\\": Array [
Expand All @@ -422,7 +422,8 @@ exports[`API getSupportInfo() with version 1.8.2 -> undefined 1`] = `
\\"css\\",
],
\\"Flow\\": Array [
\\"babel\\",
- \\"babylon\\",
+ \\"babel\\",
\\"flow\\",
],
\\"GraphQL\\": Array [
Expand All @@ -444,11 +445,13 @@ exports[`API getSupportInfo() with version 1.8.2 -> undefined 1`] = `
+ \\"json5\\",
+ ],
\\"JSX\\": Array [
\\"babel\\",
- \\"babylon\\",
+ \\"babel\\",
\\"flow\\",
],
\\"JavaScript\\": Array [
@@ -25,10 +37,13 @@
- \\"babylon\\",
+ \\"babel\\",
\\"flow\\",
],
\\"Less\\": Array [
Expand Down Expand Up @@ -589,6 +592,11 @@ exports[`API getSupportInfo() with version 1.8.2 -> undefined 1`] = `
\\"range\\": Object {"
`;
exports[`API getSupportInfo() with version 1.16.0 -> undefined 1`] = `
"Snapshot Diff:
Compared values have no visual difference."
`;
exports[`CLI --support-info (stderr) 1`] = `""`;
exports[`CLI --support-info (stdout) 1`] = `
Expand Down
1 change: 1 addition & 0 deletions tests_integration/__tests__/support-info.js
Expand Up @@ -13,6 +13,7 @@ describe("API getSupportInfo()", () => {
"1.7.1",
"1.8.0",
"1.8.2",
"1.16.0",
undefined
];

Expand Down

0 comments on commit 29799e5

Please sign in to comment.