Skip to content

Commit

Permalink
chore: add null-check
Browse files Browse the repository at this point in the history
  • Loading branch information
wessberg committed Jul 29, 2022
1 parent deb1e34 commit 3b365dd
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
Expand Up @@ -11,7 +11,7 @@ export function evaluatePropertyAccessExpression(options: EvaluatorOptions<TS.Pr
const {evaluate, node, statementTraversalStack, environment, typescript, getCurrentError} = options;
const expressionResult = evaluate.expression(node.expression, options) as IndexLiteral;

if (getCurrentError() != null) {
if (expressionResult == null || getCurrentError() != null) {
return;
}

Expand Down
27 changes: 27 additions & 0 deletions test/assignments/assignments.test.ts
Expand Up @@ -21,3 +21,30 @@ test("Can evaluate a CallExpression for a function with variable assignments. #1
if (!result.success) t.fail(result.reason.stack);
else t.deepEqual(result.value, 4);
});

test("Can evaluate a CallExpression for a function with variable assignments. #2", withTypeScript, (t, {typescript, useTypeChecker}) => {
const {result} = executeProgram(
`
const mapOfMaps: Map<string, Map<string, string>> = new Map();
function getMapForKey(key: string): string {
let innerMap = mapOfMaps.get(key);
if (innerMap == null) {
innerMap = new Map();
mapOfMaps.set(key, innerMap);
}
return innerMap;
}
mapOfMaps.set("foo", new Map());
getMapForKey("foo");
`,
"getMapForKey(",
{typescript, useTypeChecker}
);

if (!result.success) t.fail(result.reason.stack);
else t.deepEqual(result.value, new Map());
});

0 comments on commit 3b365dd

Please sign in to comment.