Skip to content

Commit 99d4532

Browse files
authored
Merge pull request #515 from cgatian/fix/missing-declaration
fix: declaration array can be undefined
2 parents ffaca22 + d7a5b9d commit 99d4532

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

src/parser.ts

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -266,10 +266,9 @@ export class Parser {
266266
if (exp.flags & ts.SymbolFlags.Alias) {
267267
targetSymbol = this.checker.getAliasedSymbol(exp);
268268
}
269-
const declaration =
270-
targetSymbol.valueDeclaration || targetSymbol.declarations![0];
269+
const declaration = targetSymbol.valueDeclaration;
271270

272-
if (ts.isClassDeclaration(declaration)) {
271+
if (!declaration || ts.isClassDeclaration(declaration)) {
273272
return false;
274273
}
275274

@@ -1203,18 +1202,22 @@ export class Parser {
12031202
properties: ts.NodeArray<ts.PropertyAssignment | ts.BindingElement>
12041203
): StringIndexedObject<string | boolean | number | null> {
12051204
return properties.reduce((acc, property) => {
1206-
const propertyName = getPropertyName(ts.isBindingElement(property) ? (property.propertyName || property.name) : property.name);
1205+
const propertyName = getPropertyName(
1206+
ts.isBindingElement(property)
1207+
? property.propertyName || property.name
1208+
: property.name
1209+
);
12071210
if (ts.isSpreadAssignment(property) || !propertyName) {
12081211
return acc;
12091212
}
12101213

12111214
const literalValue = this.getLiteralValueFromPropertyAssignment(property);
12121215

12131216
if (
1214-
(typeof literalValue === 'string' ||
1215-
typeof literalValue === 'number' ||
1216-
typeof literalValue === 'boolean' ||
1217-
literalValue === null)
1217+
typeof literalValue === 'string' ||
1218+
typeof literalValue === 'number' ||
1219+
typeof literalValue === 'boolean' ||
1220+
literalValue === null
12181221
) {
12191222
acc[propertyName] = literalValue;
12201223
}

0 commit comments

Comments
 (0)