Skip to content

Commit

Permalink
fix: Relax simple expression requirements for default values
Browse files Browse the repository at this point in the history
Resolves #1552
  • Loading branch information
Gerrit0 committed Apr 3, 2021
1 parent d1a9bca commit bff5816
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 8 deletions.
22 changes: 18 additions & 4 deletions src/lib/converter/convert-expression.ts
Expand Up @@ -26,9 +26,23 @@ export function convertExpression(expression: ts.Expression) {
case ts.SyntaxKind.NumericLiteral:
case ts.SyntaxKind.PrefixUnaryExpression:
return expression.getText();
default:
// More complex expressions are generally not useful in the documentation.
// Show that there was a value, but not specifics.
return "...";
}

if (
ts.isArrayLiteralExpression(expression) &&
expression.elements.length === 0
) {
return "[]";
}

if (
ts.isObjectLiteralExpression(expression) &&
expression.properties.length === 0
) {
return "{}";
}

// More complex expressions are generally not useful in the documentation.
// Show that there was a value, but not specifics.
return "...";
}
4 changes: 2 additions & 2 deletions src/test/converter/variables/specs.json
Expand Up @@ -247,7 +247,7 @@
}
}
},
"defaultValue": "..."
"defaultValue": "[]"
},
{
"id": 8,
Expand All @@ -271,7 +271,7 @@
],
"name": "Array"
},
"defaultValue": "..."
"defaultValue": "{}"
}
],
"groups": [
Expand Down
4 changes: 2 additions & 2 deletions src/test/converter/variables/specs.nodoc.json
Expand Up @@ -247,7 +247,7 @@
}
}
},
"defaultValue": "..."
"defaultValue": "[]"
},
{
"id": 8,
Expand All @@ -271,7 +271,7 @@
],
"name": "Array"
},
"defaultValue": "..."
"defaultValue": "{}"
}
],
"groups": [
Expand Down
7 changes: 7 additions & 0 deletions src/test/converter2.test.ts
Expand Up @@ -179,6 +179,13 @@ const issueTests: Record<string, (project: ProjectReflection) => void> = {
["Test", "ThingA", "ThingB"]
);
},

gh1552(project) {
equal(query(project, "emptyArr").defaultValue, "[]");
equal(query(project, "nonEmptyArr").defaultValue, "...");
equal(query(project, "emptyObj").defaultValue, "{}");
equal(query(project, "nonEmptyObj").defaultValue, "...");
},
};

describe("Converter2", () => {
Expand Down
4 changes: 4 additions & 0 deletions src/test/converter2/issues/gh1552.ts
@@ -0,0 +1,4 @@
export const emptyArr = [];
export const nonEmptyArr = [1];
export const emptyObj = {};
export const nonEmptyObj = { x: 1 };

0 comments on commit bff5816

Please sign in to comment.