From 61b39749a1d9208b41953a0ff6f14e58dbc780fb Mon Sep 17 00:00:00 2001 From: Brian Ng Date: Fri, 25 May 2018 08:55:39 -0500 Subject: [PATCH] Add support for flow explicit type arguments (#4540) Fixes #4489. Babylon support landed in `beta.48` just now but requires a few other fixture changes, so I'm going to follow this up with another PR. --- src/language-js/printer-estree.js | 5 ++- .../__snapshots__/jsfmt.spec.js.snap | 42 +++++++++++++++++++ tests/flow_typeapp_call/jsfmt.spec.js | 1 + tests/flow_typeapp_call/typeapp_call.js | 18 ++++++++ 4 files changed, 65 insertions(+), 1 deletion(-) create mode 100644 tests/flow_typeapp_call/__snapshots__/jsfmt.spec.js.snap create mode 100644 tests/flow_typeapp_call/jsfmt.spec.js create mode 100644 tests/flow_typeapp_call/typeapp_call.js diff --git a/src/language-js/printer-estree.js b/src/language-js/printer-estree.js index a85e7327..0d805b32 100644 --- a/src/language-js/printer-estree.js +++ b/src/language-js/printer-estree.js @@ -1030,7 +1030,7 @@ function printPathNoParens(path, options, print, args) { isNew ? "new " : "", path.call(print, "callee"), optional, - path.call(print, "typeParameters"), + printFunctionTypeParameters(path, options, print), concat(["(", join(", ", path.map(print, "arguments")), ")"]) ]); } @@ -3583,6 +3583,9 @@ function printTypeAnnotation(path, options, print) { function printFunctionTypeParameters(path, options, print) { const fun = path.getValue(); + if (fun.typeArguments) { + return path.call(print, "typeArguments"); + } if (fun.typeParameters) { return path.call(print, "typeParameters"); } diff --git a/tests/flow_typeapp_call/__snapshots__/jsfmt.spec.js.snap b/tests/flow_typeapp_call/__snapshots__/jsfmt.spec.js.snap new file mode 100644 index 00000000..48d6a530 --- /dev/null +++ b/tests/flow_typeapp_call/__snapshots__/jsfmt.spec.js.snap @@ -0,0 +1,42 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`typeapp_call.js 1`] = ` +//@flow +f(); +f; +new C; +f(e); +o[e](); +f(x)(y); +async () => {}; +async (): T => {} +new C(e); +f[e]; +new C(); +o.m(); +f.0; +o?.m(e); +o.m?.(e); +async(); +f?.(e); +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +//@flow +f(); +f < T > ; +new C(); +f(e); +o[e](); +f(x)(y); +async () => {}; +async (): T => {}; +new C(e); +f < T > [e]; +new C(); +o.m(); +f < T > 0.0; +o?.m(e); +o.m?.(e); +async(); +f?.(e); + +`; diff --git a/tests/flow_typeapp_call/jsfmt.spec.js b/tests/flow_typeapp_call/jsfmt.spec.js new file mode 100644 index 00000000..b9a90898 --- /dev/null +++ b/tests/flow_typeapp_call/jsfmt.spec.js @@ -0,0 +1 @@ +run_spec(__dirname, ["flow"]); diff --git a/tests/flow_typeapp_call/typeapp_call.js b/tests/flow_typeapp_call/typeapp_call.js new file mode 100644 index 00000000..f0b0f9ac --- /dev/null +++ b/tests/flow_typeapp_call/typeapp_call.js @@ -0,0 +1,18 @@ +//@flow +f(); +f; +new C; +f(e); +o[e](); +f(x)(y); +async () => {}; +async (): T => {} +new C(e); +f[e]; +new C(); +o.m(); +f.0; +o?.m(e); +o.m?.(e); +async(); +f?.(e);