Skip to content

Commit dfb4799

Browse files
committed
Make constant finding better
1 parent ff0642d commit dfb4799

1 file changed

Lines changed: 5 additions & 1 deletion

File tree

src/analyzers/resistor-color/ResistorColorSolution.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,11 @@ export class ResistorColorSolution {
369369
this.fileConstants = findTopLevelConstants(program, ['let', 'const', 'var'])
370370
.filter((declaration): boolean => declaration && isIdentifier(declaration.id) && declaration.id.name !== EXPECTED_METHOD)
371371

372-
const expectedConstant = this.fileConstants.find((constant) => isIdentifier(constant.id, EXPECTED_CONSTANT))
372+
// Find expected name
373+
const expectedConstant = this.fileConstants.find((constant) => isIdentifier(constant.id, EXPECTED_CONSTANT)) ||
374+
// Or find the first array or object assignment
375+
this.fileConstants.find((constant) => constant.init && [AST_NODE_TYPES.ArrayExpression, AST_NODE_TYPES.ObjectExpression].indexOf(constant.init.type))
376+
373377
this.mainConstant = expectedConstant && new Constant(expectedConstant, this.source) || undefined
374378
}
375379

0 commit comments

Comments
 (0)