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 committed Feb 3, 2019
1 parent a093bb3 commit 2982dcd
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 21 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.unreleased.md
Expand Up @@ -84,3 +84,7 @@ Examples:
// Output (Prettier master)
<my-element data-for={value}></my-element>
```

- 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
74 changes: 53 additions & 21 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,19 +445,18 @@ exports[`API getSupportInfo() with version 1.8.2 -> undefined 1`] = `
+ \\"json5\\",
+ ],
\\"JSX\\": Array [
\\"babel\\",
- \\"babylon\\",
+ \\"babel\\",
\\"flow\\",
],
\\"JavaScript\\": Array [
@@ -25,10 +37,16 @@
- \\"babylon\\",
+ \\"babel\\",
\\"flow\\",
],
\\"Less\\": Array [
\\"less\\",
],
+ \\"Lightning Web Components\\": Array [
+ \\"lwc\\",
+ ],
+ \\"MDX\\": Array [
+ \\"mdx\\",
+ ],
Expand All @@ -465,7 +465,7 @@ exports[`API getSupportInfo() with version 1.8.2 -> undefined 1`] = `
],
\\"PostCSS\\": Array [
\\"css\\",
@@ -37,12 +55,26 @@
@@ -37,12 +52,26 @@
\\"scss\\",
],
\\"TypeScript\\": Array [
Expand All @@ -492,7 +492,7 @@ exports[`API getSupportInfo() with version 1.8.2 -> undefined 1`] = `
\\"type\\": \\"boolean\\",
},
\\"cursorOffset\\": Object {
@@ -52,37 +84,77 @@
@@ -52,37 +81,76 @@
\\"start\\": -1,
\\"step\\": 1,
},
Expand Down Expand Up @@ -553,7 +553,6 @@ exports[`API getSupportInfo() with version 1.8.2 -> undefined 1`] = `
+ \\"yaml\\",
+ \\"html\\",
+ \\"angular\\",
+ \\"lwc\\",
],
- \\"default\\": \\"babylon\\",
+ \\"default\\": undefined,
Expand All @@ -572,7 +571,7 @@ exports[`API getSupportInfo() with version 1.8.2 -> undefined 1`] = `
\\"range\\": Object {
\\"end\\": Infinity,
\\"start\\": 0,
@@ -90,14 +162,15 @@
@@ -90,14 +158,15 @@
},
\\"type\\": \\"int\\",
},
Expand All @@ -593,6 +592,39 @@ exports[`API getSupportInfo() with version 1.8.2 -> undefined 1`] = `
\\"range\\": Object {"
`;
exports[`API getSupportInfo() with version 1.16.0 -> undefined 1`] = `
"Snapshot Diff:
- First value
+ Second value
@@ -37,10 +37,13 @@
\\"flow\\",
],
\\"Less\\": Array [
\\"less\\",
],
+ \\"Lightning Web Components\\": Array [
+ \\"lwc\\",
+ ],
\\"MDX\\": Array [
\\"mdx\\",
],
\\"Markdown\\": Array [
\\"markdown\\",
@@ -135,10 +138,11 @@
\\"mdx\\",
\\"vue\\",
\\"yaml\\",
\\"html\\",
\\"angular\\",
+ \\"lwc\\",
],
\\"default\\": undefined,
\\"type\\": \\"choice\\",
},
\\"pluginSearchDirs\\": Object {"
`;
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 2982dcd

Please sign in to comment.