From ac9a0843d29f9074d7e3300fc6ae04d3321bdd0a Mon Sep 17 00:00:00 2001 From: Martin Broder Date: Thu, 14 Sep 2017 17:27:24 +0200 Subject: [PATCH 1/2] fix: special property names in flowtypes --- src/flow_doctrine.js | 2 +- src/infer/params.js | 4 ++-- src/infer/properties.js | 3 ++- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/flow_doctrine.js b/src/flow_doctrine.js index 25f18f756..208df57d8 100644 --- a/src/flow_doctrine.js +++ b/src/flow_doctrine.js @@ -27,7 +27,7 @@ function propertyToField(property) { } return { type: 'FieldType', - key: property.key.name, + key: property.key.name || property.key.value, value: type }; } diff --git a/src/infer/params.js b/src/infer/params.js index 17f8ad543..ba99d707f 100644 --- a/src/infer/params.js +++ b/src/infer/params.js @@ -197,8 +197,8 @@ function paramToDoc( }); } case 'ObjectProperty': { - return _.assign(paramToDoc(param.value, prefix + '.' + param.key.name), { - name: prefix + '.' + param.key.name + return _.assign(paramToDoc(param.value, prefix + '.' + param.key.name || param.key.value), { + name: prefix + '.' + param.key.name || param.key.value }); } case 'RestProperty': // (a, ...b) diff --git a/src/infer/properties.js b/src/infer/properties.js index 19b63dd95..12d9639ee 100644 --- a/src/infer/properties.js +++ b/src/infer/properties.js @@ -12,6 +12,7 @@ function prefixedName(name, prefix) { function propertyToDoc(property, prefix): CommentTag { var type = flowDoctrine(property.value); + var name = property.key.name || property.key.value if (property.optional) { type = { type: 'OptionalType', @@ -20,7 +21,7 @@ function propertyToDoc(property, prefix): CommentTag { } return { title: 'property', - name: prefixedName(property.key.name, prefix), + name: prefixedName(name, prefix), lineNumber: property.loc.start.line, type }; From 586116b4bfa4b28f9c57a600da7a9fc40fd11230 Mon Sep 17 00:00:00 2001 From: Tom MacWright Date: Thu, 14 Sep 2017 15:37:00 -0700 Subject: [PATCH 2/2] test: Add specific test for quoted properties in type definitions --- __tests__/lib/infer/type.js | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/__tests__/lib/infer/type.js b/__tests__/lib/infer/type.js index 4832d9d1c..c7da9b312 100644 --- a/__tests__/lib/infer/type.js +++ b/__tests__/lib/infer/type.js @@ -40,6 +40,28 @@ test('inferType', function() { type: 'TypeApplication' }); + expect(evaluate('/** */' + "type V = {a:number,'b':string}").type).toEqual({ + fields: [ + { + key: 'a', + type: 'FieldType', + value: { + name: 'number', + type: 'NameExpression' + } + }, + { + key: 'b', + type: 'FieldType', + value: { + name: 'string', + type: 'NameExpression' + } + } + ], + type: 'RecordType' + }); + expect(evaluate('/** */' + 'type V = Array').type).toEqual({ applications: [ {