From 8fc64ccdf4eedfd7bbefed9598c71d976463c088 Mon Sep 17 00:00:00 2001 From: Bronley Plumb Date: Fri, 14 Jun 2024 15:39:17 -0400 Subject: [PATCH] Fix crash with missing scope --- src/util.ts | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/util.ts b/src/util.ts index e88ba77cc..d5e41f4fb 100644 --- a/src/util.ts +++ b/src/util.ts @@ -1217,12 +1217,15 @@ export class Util { expressionWalker(expression); const scope = file.program.getFirstScopeForFile(file); - const filteredVarNames = [...uniqueVarNames].filter((varName: string) => { - const varNameLower = varName.toLowerCase(); - // TODO: include namespaces in this filter - return !scope.getEnumMap().has(varNameLower) && - !scope.getConstMap().has(varNameLower); - }); + let filteredVarNames = [...uniqueVarNames]; + if (scope) { + filteredVarNames = filteredVarNames.filter((varName: string) => { + const varNameLower = varName.toLowerCase(); + // TODO: include namespaces in this filter + return !scope.getEnumMap().has(varNameLower) && + !scope.getConstMap().has(varNameLower); + }); + } return { expressions: expressions, varExpressions: variableExpressions, uniqueVarNames: filteredVarNames }; }