Skip to content

Commit

Permalink
Remove flow plugin from babel parser
Browse files Browse the repository at this point in the history
  • Loading branch information
fisker committed Feb 1, 2023
1 parent 97c8e3c commit 12176c2
Show file tree
Hide file tree
Showing 33 changed files with 753 additions and 573 deletions.
8 changes: 5 additions & 3 deletions src/language-js/parse/babel.js
Original file line number Diff line number Diff line change
Expand Up @@ -220,8 +220,9 @@ const allowedMessageCodes = new Set([
"DuplicateExport",
]);

const babelParserOptionsCombinations = [appendPlugins(["jsx"])];
const babel = createBabelParser({
optionsCombinations: [appendPlugins(["jsx", "flow"])],
optionsCombinations: babelParserOptionsCombinations,
});
const babelTs = createBabelParser({
optionsCombinations: [
Expand All @@ -237,7 +238,6 @@ const babelTSExpression = createBabelParser({
isExpression: true,
optionsCombinations: [appendPlugins(["typescript"])],
});

const babelFlow = createBabelParser({
optionsCombinations: [
appendPlugins([
Expand All @@ -248,7 +248,9 @@ const babelFlow = createBabelParser({
],
});
const babelEstree = createBabelParser({
optionsCombinations: [appendPlugins(["jsx", "flow", "estree"])],
optionsCombinations: babelParserOptionsCombinations.map((options) =>
appendPlugins(["estree"], options)
),
});

// Export as a plugin so we can reuse the same bundle for UMD loading
Expand Down
26 changes: 13 additions & 13 deletions tests/config/format-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -218,19 +218,6 @@ function runSpec(fixtures, parsers, options) {
const allParsers = [...parsers];

if (!IS_ERROR_TESTS) {
if (
parsers.includes("typescript") &&
!parsers.includes("babel-ts") &&
!IS_TYPESCRIPT_ONLY_TEST &&
!babelTsDisabledTest.has(dirname)
) {
allParsers.push("babel-ts");
}

if (parsers.includes("flow") && !parsers.includes("babel-flow")) {
allParsers.push("babel-flow");
}

if (
parsers.includes("babel") &&
(isTestDirectory(dirname, "js") || isTestDirectory(dirname, "jsx"))
Expand All @@ -246,6 +233,19 @@ function runSpec(fixtures, parsers, options) {
}
}

if (
parsers.includes("typescript") &&
!parsers.includes("babel-ts") &&
!IS_TYPESCRIPT_ONLY_TEST &&
!babelTsDisabledTest.has(dirname)
) {
allParsers.push("babel-ts");
}

if (parsers.includes("flow") && !parsers.includes("babel-flow")) {
allParsers.push("babel-flow");
}

if (parsers.includes("babel") && !parsers.includes("__babel_estree")) {
allParsers.push("__babel_estree");
}
Expand Down
115 changes: 115 additions & 0 deletions tests/format/flow/decorator/__snapshots__/jsfmt.spec.js.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`comments.js format 1`] = `
====================================options=====================================
parsers: ["flow"]
printWidth: 80
| printWidth
=====================================input======================================
class Something {
@Annotateme()
// comment
static property: Array<string>;
}
=====================================output=====================================
class Something {
static // comment
property: Array<string>;
}
================================================================================
`;
exports[`mobx.js format 1`] = `
====================================options=====================================
parsers: ["flow"]
printWidth: 80
| printWidth
=====================================input======================================
import {observable} from "mobx";
@observer class OrderLine {
@observable price:number = 0;
@observable amount:number = 1;
constructor(price) {
this.price = price;
}
@computed get total() {
return this.price * this.amount;
}
@action.bound setPrice(price) {
this.price = price;
}
@computed
get total() {
return this.price * this.amount;
}
@action.bound
setPrice(price) {
this.price = price;
}
@computed @computed @computed @computed @computed @computed @computed get total() {
return this.price * this.amount;
}
@action handleDecrease = (event: React.ChangeEvent<HTMLInputElement>) => this.count--;
@action handleSomething = (event: React.ChangeEvent<HTMLInputElement>) => doSomething();
}
=====================================output=====================================
import { observable } from "mobx";
@observer
class OrderLine {
price: number = 0;
amount: number = 1;
constructor(price) {
this.price = price;
}
@computed get total() {
return this.price * this.amount;
}
@action.bound setPrice(price) {
this.price = price;
}
@computed
get total() {
return this.price * this.amount;
}
@action.bound
setPrice(price) {
this.price = price;
}
@computed
@computed
@computed
@computed
@computed
@computed
@computed
get total() {
return this.price * this.amount;
}
handleDecrease = (event: React.ChangeEvent<HTMLInputElement>) => this.count--;
handleSomething = (event: React.ChangeEvent<HTMLInputElement>) =>
doSomething();
}
================================================================================
`;
File renamed without changes.
1 change: 1 addition & 0 deletions tests/format/flow/decorator/jsfmt.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
run_spec(import.meta, ["flow",]);
36 changes: 36 additions & 0 deletions tests/format/flow/decorator/mobx.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import {observable} from "mobx";

@observer class OrderLine {
@observable price:number = 0;
@observable amount:number = 1;

constructor(price) {
this.price = price;
}

@computed get total() {
return this.price * this.amount;
}

@action.bound setPrice(price) {
this.price = price;
}

@computed
get total() {
return this.price * this.amount;
}

@action.bound
setPrice(price) {
this.price = price;
}

@computed @computed @computed @computed @computed @computed @computed get total() {
return this.price * this.amount;
}

@action handleDecrease = (event: React.ChangeEvent<HTMLInputElement>) => this.count--;

@action handleSomething = (event: React.ChangeEvent<HTMLInputElement>) => doSomething();
}
98 changes: 85 additions & 13 deletions tests/format/js/babel-plugins/__snapshots__/jsfmt.spec.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -937,34 +937,34 @@ export * as ns from "mod";
================================================================================
`;
exports[`flow.js [acorn] format 1`] = `
"Unexpected token (3:17)
exports[`flow.js [__babel_estree] format 1`] = `
"Unexpected token, expected "," (3:17)
1 | // https://babeljs.io/docs/en/babel-preset-flow
2 |
> 3 | function foo(one: any, two: number, three?): string {}
| ^
4 |"
`;
exports[`flow.js [espree] format 1`] = `
"Unexpected token : (3:17)
exports[`flow.js [acorn] format 1`] = `
"Unexpected token (3:17)
1 | // https://babeljs.io/docs/en/babel-preset-flow
2 |
> 3 | function foo(one: any, two: number, three?): string {}
| ^
4 |"
`;
exports[`flow.js [meriyah] format 1`] = `
"Expected ')' (3:17)
exports[`flow.js [babel] format 1`] = `
"Unexpected token, expected "," (3:17)
1 | // https://babeljs.io/docs/en/babel-preset-flow
2 |
> 3 | function foo(one: any, two: number, three?): string {}
| ^
4 |"
`;
exports[`flow.js format 1`] = `
exports[`flow.js [babel-flow] format 1`] = `
====================================options=====================================
parsers: ["babel", "babel-ts", "babel-flow"]
printWidth: 80
Expand All @@ -982,6 +982,42 @@ function foo(one: any, two: number, three?): string {}
================================================================================
`;
exports[`flow.js [babel-ts] format 1`] = `
====================================options=====================================
parsers: ["babel", "babel-ts", "babel-flow"]
printWidth: 80
| printWidth
=====================================input======================================
// https://babeljs.io/docs/en/babel-preset-flow
function foo(one: any, two: number, three?): string {}
=====================================output=====================================
// https://babeljs.io/docs/en/babel-preset-flow
function foo(one: any, two: number, three?): string {}
================================================================================
`;
exports[`flow.js [espree] format 1`] = `
"Unexpected token : (3:17)
1 | // https://babeljs.io/docs/en/babel-preset-flow
2 |
> 3 | function foo(one: any, two: number, three?): string {}
| ^
4 |"
`;
exports[`flow.js [meriyah] format 1`] = `
"Expected ')' (3:17)
1 | // https://babeljs.io/docs/en/babel-preset-flow
2 |
> 3 | function foo(one: any, two: number, three?): string {}
| ^
4 |"
`;
exports[`function-bind.js [acorn] format 1`] = `
"Unexpected token (3:5)
1 | // https://babeljs.io/docs/en/babel-plugin-proposal-function-bind
Expand Down Expand Up @@ -2381,7 +2417,7 @@ function test(param = throw new Error("required!")) {
================================================================================
`;
exports[`typescript.js [acorn] format 1`] = `
exports[`typescript.js [__babel_estree] format 1`] = `
"Unexpected token (3:8)
1 | // https://babeljs.io/docs/en/babel-preset-typescript
2 |
Expand All @@ -2390,25 +2426,25 @@ exports[`typescript.js [acorn] format 1`] = `
4 |"
`;
exports[`typescript.js [espree] format 1`] = `
"Unexpected token : (3:8)
exports[`typescript.js [acorn] format 1`] = `
"Unexpected token (3:8)
1 | // https://babeljs.io/docs/en/babel-preset-typescript
2 |
> 3 | const x: number = 0;
| ^
4 |"
`;
exports[`typescript.js [meriyah] format 1`] = `
"Missing initializer in const declaration (3:8)
exports[`typescript.js [babel] format 1`] = `
"Unexpected token (3:8)
1 | // https://babeljs.io/docs/en/babel-preset-typescript
2 |
> 3 | const x: number = 0;
| ^
4 |"
`;
exports[`typescript.js format 1`] = `
exports[`typescript.js [babel-flow] format 1`] = `
====================================options=====================================
parsers: ["babel", "babel-ts", "babel-flow"]
printWidth: 80
Expand All @@ -2426,6 +2462,42 @@ const x: number = 0;
================================================================================
`;
exports[`typescript.js [babel-ts] format 1`] = `
====================================options=====================================
parsers: ["babel", "babel-ts", "babel-flow"]
printWidth: 80
| printWidth
=====================================input======================================
// https://babeljs.io/docs/en/babel-preset-typescript
const x: number = 0;
=====================================output=====================================
// https://babeljs.io/docs/en/babel-preset-typescript
const x: number = 0;
================================================================================
`;
exports[`typescript.js [espree] format 1`] = `
"Unexpected token : (3:8)
1 | // https://babeljs.io/docs/en/babel-preset-typescript
2 |
> 3 | const x: number = 0;
| ^
4 |"
`;
exports[`typescript.js [meriyah] format 1`] = `
"Missing initializer in const declaration (3:8)
1 | // https://babeljs.io/docs/en/babel-preset-typescript
2 |
> 3 | const x: number = 0;
| ^
4 |"
`;
exports[`v8intrinsic.js [acorn] format 1`] = `
"Unexpected token (3:1)
1 | // https://github.com/babel/babel/pull/10148
Expand Down

0 comments on commit 12176c2

Please sign in to comment.