From 608a029e366b1377b4d548ca1f7633e7db19b167 Mon Sep 17 00:00:00 2001 From: Andrew Del Prete Date: Tue, 2 Jun 2020 15:25:30 -0500 Subject: [PATCH 1/2] =?UTF-8?q?fix:=20=F0=9F=90=9B=20Fixes=20an=20issue=20?= =?UTF-8?q?when=20using=20object=20spread=20and=20$Exact?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixes an issue where documentationjs breaks on build when using object spread and Flow utility $Exact (i.g: ...Exact) ✅ Closes: #1324 --- src/infer/properties.js | 38 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 36 insertions(+), 2 deletions(-) diff --git a/src/infer/properties.js b/src/infer/properties.js index 5af742042..a9d331247 100644 --- a/src/infer/properties.js +++ b/src/infer/properties.js @@ -1,3 +1,4 @@ +// properties const typeAnnotation = require('../type_annotation'); const findTarget = require('./finders').findTarget; @@ -8,8 +9,17 @@ function prefixedName(name, prefix) { return name; } +function isObjectSpreadAndExactUtilTypeProperty(property) { + return ( + property.type === 'ObjectTypeSpreadProperty' && + property.argument.id.name === '$Exact' + ); +} + function propertyToDoc(property, prefix) { let type; + let name; + if (property.type === 'ObjectTypeProperty') { // flow type = typeAnnotation(property.value); @@ -20,7 +30,20 @@ function propertyToDoc(property, prefix) { // typescript type = typeAnnotation(property); } - const name = property.key.name || property.key.value; + + if (property.key) { + name = property.key.name || property.key.value; + } + + // Special handing for { ...$Exact } + if (isObjectSpreadAndExactUtilTypeProperty(property)) { + name = property.argument.id.name; + type = { + type: 'NameExpression', + name: property.argument.typeParameters.params[0].id.name + }; + } + if (property.optional) { type = { type: 'OptionalType', @@ -54,7 +77,18 @@ function inferProperties(comment) { ) { const properties = value.properties || value.members || value.body || []; properties.forEach(function(property) { - if (!explicitProperties.has(prefixedName(property.key.name, prefix))) { + let name; + + if (property.key) { + name = property.key.name; + } + + // Special handing for { ...$Exact } + if (isObjectSpreadAndExactUtilTypeProperty(property)) { + name = property.argument.id.name; + } + + if (!explicitProperties.has(prefixedName(name, prefix))) { comment.properties = comment.properties.concat( propertyToDoc(property, prefix) ); From 51e07ba9d8a5399310b91d977c0c33de8b255d31 Mon Sep 17 00:00:00 2001 From: Andrew Del Prete Date: Tue, 2 Jun 2020 15:29:06 -0500 Subject: [PATCH 2/2] fix comment typo --- src/infer/properties.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/infer/properties.js b/src/infer/properties.js index a9d331247..35399866c 100644 --- a/src/infer/properties.js +++ b/src/infer/properties.js @@ -1,4 +1,3 @@ -// properties const typeAnnotation = require('../type_annotation'); const findTarget = require('./finders').findTarget; @@ -35,7 +34,7 @@ function propertyToDoc(property, prefix) { name = property.key.name || property.key.value; } - // Special handing for { ...$Exact } + // Special handling for { ...$Exact } if (isObjectSpreadAndExactUtilTypeProperty(property)) { name = property.argument.id.name; type = { @@ -83,7 +82,7 @@ function inferProperties(comment) { name = property.key.name; } - // Special handing for { ...$Exact } + // Special handling for { ...$Exact } if (isObjectSpreadAndExactUtilTypeProperty(property)) { name = property.argument.id.name; }