diff --git a/compiler/forget/src/HIR/BuildHIR.ts b/compiler/forget/src/HIR/BuildHIR.ts index 6d79b759d4..7af5f6717f 100644 --- a/compiler/forget/src/HIR/BuildHIR.ts +++ b/compiler/forget/src/HIR/BuildHIR.ts @@ -723,7 +723,7 @@ function lowerExpression( switch (exprNode.type) { case "Identifier": { const expr = exprPath as NodePath; - return lowerLVal(builder, expr); + return lowerIdentifier(builder, expr); } case "NullLiteral": { return { @@ -1285,30 +1285,38 @@ function lowerExpressionToVoid( }); } +function lowerIdentifier( + builder: HIRBuilder, + exprPath: NodePath +): Place { + const exprNode = exprPath.node; + const exprLoc = exprNode.loc ?? GeneratedSource; + const binding = + exprPath.scope.getBindingIdentifier(exprNode.name) ?? + getOrAddGlobal(exprNode.name); + invariant( + binding != null, + `Expected to find a binding for variable '%s'`, + exprNode.name + ); + const identifier = builder.resolveIdentifier(binding); + const place: Place = { + kind: "Identifier", + identifier: identifier, + memberPath: null, + effect: Effect.Unknown, + loc: exprLoc, + }; + return place; +} + function lowerLVal(builder: HIRBuilder, exprPath: NodePath): Place { const exprNode = exprPath.node; const exprLoc = exprNode.loc ?? GeneratedSource; switch (exprNode.type) { case "Identifier": { - // const expr = exprPath as NodePath; - // const name: string = expr.get("name"); - const binding = - exprPath.scope.getBindingIdentifier(exprNode.name) ?? - getOrAddGlobal(exprNode.name); - invariant( - binding != null, - `Expected to find a binding for variable '%s'`, - exprNode.name - ); - const identifier = builder.resolveIdentifier(binding); - const place: Place = { - kind: "Identifier", - identifier: identifier, - memberPath: null, - effect: Effect.Unknown, - loc: exprLoc, - }; - return place; + const expr = exprPath as NodePath; + return lowerIdentifier(builder, expr); } case "MemberExpression": { const expr = exprPath as NodePath;