From fda7bf59f482c83a9db94bdc1111689a3e4ff474 Mon Sep 17 00:00:00 2001 From: Brian Ng Date: Fri, 25 May 2018 17:23:17 -0500 Subject: [PATCH] Add support for Flow's proto modifier syntax (#4551) Flow commit: https://github.com/facebook/flow/commit/eb815be907eeae9f4851ff154087ebf079510d18 Babel PR: https://github.com/babel/babel/pull/7978 --- src/language-js/printer-estree.js | 10 +++++++++- .../__snapshots__/jsfmt.spec.js.snap | 12 ++++++++++++ tests/flow_proto_props/jsfmt.spec.js | 1 + tests/flow_proto_props/proto_props.js | 3 +++ 4 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 tests/flow_proto_props/__snapshots__/jsfmt.spec.js.snap create mode 100644 tests/flow_proto_props/jsfmt.spec.js create mode 100644 tests/flow_proto_props/proto_props.js diff --git a/src/language-js/printer-estree.js b/src/language-js/printer-estree.js index e03565597..663126784 100644 --- a/src/language-js/printer-estree.js +++ b/src/language-js/printer-estree.js @@ -2675,8 +2675,16 @@ function printPathNoParens(path, options, print, args) { case "ObjectTypeProperty": { const variance = getFlowVariance(n); + let modifier = ""; + + if (n.proto) { + modifier = "proto "; + } else if (n.static) { + modifier = "static "; + } + return concat([ - n.static ? "static " : "", + modifier, isGetterOrSetter(n) ? n.kind + " " : "", variance || "", printPropertyKey(path, options, print), diff --git a/tests/flow_proto_props/__snapshots__/jsfmt.spec.js.snap b/tests/flow_proto_props/__snapshots__/jsfmt.spec.js.snap new file mode 100644 index 000000000..52e130ec1 --- /dev/null +++ b/tests/flow_proto_props/__snapshots__/jsfmt.spec.js.snap @@ -0,0 +1,12 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`proto_props.js 1`] = ` +declare class A { proto: T; } +declare class B { proto x: T; } +declare class C { proto +x: T; } +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +declare class A { proto: T } +declare class B { proto x: T } +declare class C { proto +x: T } + +`; diff --git a/tests/flow_proto_props/jsfmt.spec.js b/tests/flow_proto_props/jsfmt.spec.js new file mode 100644 index 000000000..b9a908981 --- /dev/null +++ b/tests/flow_proto_props/jsfmt.spec.js @@ -0,0 +1 @@ +run_spec(__dirname, ["flow"]); diff --git a/tests/flow_proto_props/proto_props.js b/tests/flow_proto_props/proto_props.js new file mode 100644 index 000000000..94e6ab9f7 --- /dev/null +++ b/tests/flow_proto_props/proto_props.js @@ -0,0 +1,3 @@ +declare class A { proto: T; } +declare class B { proto x: T; } +declare class C { proto +x: T; }