From e22ec0b9b95ebdba0da13be9446a734e674646a0 Mon Sep 17 00:00:00 2001 From: Brian Ng Date: Mon, 16 Apr 2018 20:32:46 -0500 Subject: [PATCH 1/3] Bump flow to 0.70 --- package.json | 2 +- .../flow/traits/__snapshots__/jsfmt.spec.js.snap | 4 ++-- .../__snapshots__/jsfmt.spec.js.snap | 16 ++++++++++++++++ tests/flow_implements/implements.js | 5 +++++ tests/flow_implements/jsfmt.spec.js | 1 + tests/flow_mixins/jsfmt.spec.js | 2 +- yarn.lock | 6 +++--- 7 files changed, 29 insertions(+), 7 deletions(-) create mode 100644 tests/flow_implements/__snapshots__/jsfmt.spec.js.snap create mode 100644 tests/flow_implements/implements.js create mode 100644 tests/flow_implements/jsfmt.spec.js diff --git a/package.json b/package.json index 21bb76046..a346b6831 100644 --- a/package.json +++ b/package.json @@ -30,7 +30,7 @@ "escape-string-regexp": "1.0.5", "esutils": "2.0.2", "find-project-root": "1.1.1", - "flow-parser": "0.69", + "flow-parser": "0.70", "get-stream": "3.0.0", "globby": "6.1.0", "graphql": "0.13.2", diff --git a/tests/flow/traits/__snapshots__/jsfmt.spec.js.snap b/tests/flow/traits/__snapshots__/jsfmt.spec.js.snap index 1808e48e2..ccf8d2002 100644 --- a/tests/flow/traits/__snapshots__/jsfmt.spec.js.snap +++ b/tests/flow/traits/__snapshots__/jsfmt.spec.js.snap @@ -22,7 +22,7 @@ declare class Baz { ((new Foo).y: string); // error: Bar wins ((new Foo).z: number); // error: Qux wins ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -declare class Foo extends Qux { +declare class Foo extends Qux mixins Bar { // KeyedCollection <: Collection // ...KeyedIterable } @@ -51,6 +51,6 @@ declare interface I { } declare class C mixins I { } ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ declare interface I {} -declare class C {} +declare class C mixins I {} `; diff --git a/tests/flow_implements/__snapshots__/jsfmt.spec.js.snap b/tests/flow_implements/__snapshots__/jsfmt.spec.js.snap new file mode 100644 index 000000000..5c7ba9f8c --- /dev/null +++ b/tests/flow_implements/__snapshots__/jsfmt.spec.js.snap @@ -0,0 +1,16 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`implements.js 1`] = ` +class A implements B {} +class A implements B, C {} +declare class A implements B {} +declare class A mixins B implements C {} +declare class A implements B, C {} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +class A implements B {} +class A implements B, C {} +declare class A implements B {} +declare class A implements C mixins B {} +declare class A implements B, C {} + +`; diff --git a/tests/flow_implements/implements.js b/tests/flow_implements/implements.js new file mode 100644 index 000000000..32acd7162 --- /dev/null +++ b/tests/flow_implements/implements.js @@ -0,0 +1,5 @@ +class A implements B {} +class A implements B, C {} +declare class A implements B {} +declare class A mixins B implements C {} +declare class A implements B, C {} diff --git a/tests/flow_implements/jsfmt.spec.js b/tests/flow_implements/jsfmt.spec.js new file mode 100644 index 000000000..b9a908981 --- /dev/null +++ b/tests/flow_implements/jsfmt.spec.js @@ -0,0 +1 @@ +run_spec(__dirname, ["flow"]); diff --git a/tests/flow_mixins/jsfmt.spec.js b/tests/flow_mixins/jsfmt.spec.js index 968651cdb..bffb7a547 100644 --- a/tests/flow_mixins/jsfmt.spec.js +++ b/tests/flow_mixins/jsfmt.spec.js @@ -1 +1 @@ -run_spec(__dirname, ["babylon"]); +run_spec(__dirname, ["babylon", "flow"]); diff --git a/yarn.lock b/yarn.lock index c41b7e419..b0c3e3a69 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1971,9 +1971,9 @@ flatten@^1.0.2: version "1.0.2" resolved "https://registry.yarnpkg.com/flatten/-/flatten-1.0.2.tgz#dae46a9d78fbe25292258cc1e780a41d95c03782" -flow-parser@0.69: - version "0.69.0" - resolved "https://registry.yarnpkg.com/flow-parser/-/flow-parser-0.69.0.tgz#378b5128d6d0b554a8b2f16a4ca3e1ab9649f00e" +flow-parser@0.70: + version "0.70.0" + resolved "https://registry.yarnpkg.com/flow-parser/-/flow-parser-0.70.0.tgz#9c310187efe4380ba9a251284e9b83b95c49e857" for-in@^1.0.1: version "1.0.2" From 7ab3e94fbb70d45f872c9088432adf20658add77 Mon Sep 17 00:00:00 2001 From: Brian Ng Date: Mon, 16 Apr 2018 21:28:56 -0500 Subject: [PATCH 2/3] Ensure mixins before implements --- src/language-js/printer-estree.js | 16 ++++++++-------- .../__snapshots__/jsfmt.spec.js.snap | 2 +- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/language-js/printer-estree.js b/src/language-js/printer-estree.js index 1d4920300..d3c774db8 100644 --- a/src/language-js/printer-estree.js +++ b/src/language-js/printer-estree.js @@ -3852,6 +3852,14 @@ function printClass(path, options, print) { parts.push(" extends ", join(", ", path.map(print, "extends"))); } + if (n["mixins"] && n["mixins"].length > 0) { + partsGroup.push( + line, + "mixins ", + group(indent(join(concat([",", line]), path.map(print, "mixins")))) + ); + } + if (n["implements"] && n["implements"].length > 0) { partsGroup.push( line, @@ -3867,14 +3875,6 @@ function printClass(path, options, print) { ); } - if (n["mixins"] && n["mixins"].length > 0) { - partsGroup.push( - line, - "mixins ", - group(indent(join(concat([",", line]), path.map(print, "mixins")))) - ); - } - if (partsGroup.length > 0) { parts.push(group(indent(concat(partsGroup)))); } diff --git a/tests/flow_implements/__snapshots__/jsfmt.spec.js.snap b/tests/flow_implements/__snapshots__/jsfmt.spec.js.snap index 5c7ba9f8c..31ba4a792 100644 --- a/tests/flow_implements/__snapshots__/jsfmt.spec.js.snap +++ b/tests/flow_implements/__snapshots__/jsfmt.spec.js.snap @@ -10,7 +10,7 @@ declare class A implements B, C {} class A implements B {} class A implements B, C {} declare class A implements B {} -declare class A implements C mixins B {} +declare class A mixins B implements C {} declare class A implements B, C {} `; From 9c15f9ed9e2b90fcf5012755abf87921cb32a6a0 Mon Sep 17 00:00:00 2001 From: Brian Ng Date: Tue, 17 Apr 2018 09:50:27 -0500 Subject: [PATCH 3/3] Remove workaround in rollup config for flow parser --- scripts/build/rollup.parser.config.js | 9 --------- 1 file changed, 9 deletions(-) diff --git a/scripts/build/rollup.parser.config.js b/scripts/build/rollup.parser.config.js index f923f010a..bfb4374fc 100644 --- a/scripts/build/rollup.parser.config.js +++ b/scripts/build/rollup.parser.config.js @@ -19,15 +19,6 @@ export default Object.assign(baseConfig, { include: "node_modules/typescript-eslint-parser/parser.js" }) : {}, - // In flow-parser 0.59.0 there's a dynamic require: `require(s8)` which not - // supported by rollup-plugin-commonjs, so we have to replace the variable - // by its value before bundling. - parser.endsWith("flow") - ? replace({ - "require(tf)": 'require("fs")', - include: "node_modules/flow-parser/flow_parser.js" - }) - : {}, json(), resolve({ preferBuiltins: true }), commonjs(