From 13dcb77923c28a92d66f53ebde1c1ca598518f5c Mon Sep 17 00:00:00 2001 From: Andrew Gallant Date: Wed, 15 Feb 2017 07:46:49 -0500 Subject: [PATCH] Fix bug parsing anonymous closure types from Flow. If no parameter name exists in a function type, then set it to empty. Also, fix the formatter so that `{param}: {ty}` is formatted as `{ty}` when `{param}` is empty. Fixes #671 --- lib/flow_doctrine.js | 6 +++++- lib/output/util/format_type.js | 5 ++++- test/lib/flow_doctrine.js | 13 +++++++++++++ 3 files changed, 22 insertions(+), 2 deletions(-) diff --git a/lib/flow_doctrine.js b/lib/flow_doctrine.js index a7e46c07b..49a28d83e 100644 --- a/lib/flow_doctrine.js +++ b/lib/flow_doctrine.js @@ -98,9 +98,13 @@ function flowDoctrine(type/*: Object */)/*: DoctrineType*/ { return { type: 'FunctionType', params: type.params.map(param => { + let name = ''; + if (param.name && param.name.name) { + name = param.name.name; + } return { type: 'ParameterType', - name: param.name.name, + name: name, expression: flowDoctrine(param.typeAnnotation) }; }), diff --git a/lib/output/util/format_type.js b/lib/output/util/format_type.js index 19ed6913d..242954623 100644 --- a/lib/output/util/format_type.js +++ b/lib/output/util/format_type.js @@ -118,7 +118,10 @@ function formatType(getHref/*: Function*/, node/*: ?Object */) { case Syntax.NameExpression: return [link(node.name, getHref)]; case Syntax.ParameterType: - return [t(node.name + ': ')].concat(formatType(getHref, node.expression)); + if (node.name) { + result.push(t(node.name + ': ')); + } + return result.concat(formatType(getHref, node.expression)); case Syntax.TypeApplication: return formatType(getHref, node.expression) diff --git a/test/lib/flow_doctrine.js b/test/lib/flow_doctrine.js index 1ba50537e..df0505fd2 100644 --- a/test/lib/flow_doctrine.js +++ b/test/lib/flow_doctrine.js @@ -181,6 +181,19 @@ test('flowDoctrine', function (t) { name: 'boolean' }, 'boolean'); + t.deepEqual(toDoctrineType('any => any'), + { + type: 'FunctionType', + params: [ + { + expression: {type: 'AllLiteral'}, + name: '', + type: 'ParameterType' + } + ], + result: {type: 'AllLiteral'}, + }, ''); + t.deepEqual(toDoctrineType('undefined'), { type: 'NameExpression', pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy