Skip to content

Commit 106945c

Browse files
andrewdelpretetmcw
authored andcommitted
fix: πŸ› Fixes an issue when using object spread and $Exact
Fixes an issue where documentationjs breaks on build when using object spread and Flow utility $Exact (i.g: ...Exact<Type>) βœ… Closes: #1324
1 parent 78db9a4 commit 106945c

File tree

1 file changed

+36
-2
lines changed

1 file changed

+36
-2
lines changed

β€Žsrc/infer/properties.js

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// properties
12
const typeAnnotation = require('../type_annotation');
23
const findTarget = require('./finders').findTarget;
34

@@ -8,8 +9,17 @@ function prefixedName(name, prefix) {
89
return name;
910
}
1011

12+
function isObjectSpreadAndExactUtilTypeProperty(property) {
13+
return (
14+
property.type === 'ObjectTypeSpreadProperty' &&
15+
property.argument.id.name === '$Exact'
16+
);
17+
}
18+
1119
function propertyToDoc(property, prefix) {
1220
let type;
21+
let name;
22+
1323
if (property.type === 'ObjectTypeProperty') {
1424
// flow
1525
type = typeAnnotation(property.value);
@@ -20,7 +30,20 @@ function propertyToDoc(property, prefix) {
2030
// typescript
2131
type = typeAnnotation(property);
2232
}
23-
const name = property.key.name || property.key.value;
33+
34+
if (property.key) {
35+
name = property.key.name || property.key.value;
36+
}
37+
38+
// Special handing for { ...$Exact<Type> }
39+
if (isObjectSpreadAndExactUtilTypeProperty(property)) {
40+
name = property.argument.id.name;
41+
type = {
42+
type: 'NameExpression',
43+
name: property.argument.typeParameters.params[0].id.name
44+
};
45+
}
46+
2447
if (property.optional) {
2548
type = {
2649
type: 'OptionalType',
@@ -54,7 +77,18 @@ function inferProperties(comment) {
5477
) {
5578
const properties = value.properties || value.members || value.body || [];
5679
properties.forEach(function(property) {
57-
if (!explicitProperties.has(prefixedName(property.key.name, prefix))) {
80+
let name;
81+
82+
if (property.key) {
83+
name = property.key.name;
84+
}
85+
86+
// Special handing for { ...$Exact<Type> }
87+
if (isObjectSpreadAndExactUtilTypeProperty(property)) {
88+
name = property.argument.id.name;
89+
}
90+
91+
if (!explicitProperties.has(prefixedName(name, prefix))) {
5892
comment.properties = comment.properties.concat(
5993
propertyToDoc(property, prefix)
6094
);

0 commit comments

Comments
Β (0)
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