Skip to content

Commit

Permalink
fix: Resolved issue with the RHS of dot-accessor assignments not prop…
Browse files Browse the repository at this point in the history
…erly resetting to the outer scope.
  • Loading branch information
adam-coster committed Aug 17, 2023
1 parent a729171 commit c09d25b
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions packages/parser/src/visitor.identifierAccessor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -419,15 +419,21 @@ function processDotAccessor(
visitor.PROCESSOR.pushSelfScope(dot, dottableType, true, {
accessorScope: true,
});
let scopeIsPopped = false;
const popSelfScope = (on = propertyNameLocation) => {
if (scopeIsPopped) return;
visitor.PROCESSOR.scope.setEnd(on, true);
visitor.PROCESSOR.popSelfScope(on, true);
scopeIsPopped = true;
};

// While editing a user will dot into something
// prior to actually adding the new identifier.
// To provide autocomplete options, we need to
// still add a scopeRange for the dot.
const hasIdentifier = !isEmpty(dotAccessor.identifier[0].children);
if (!hasIdentifier) {
visitor.PROCESSOR.scope.setEnd(dot, true);
visitor.PROCESSOR.popSelfScope(dot, true);
popSelfScope(dot);
nextAccessed.types = [visitor.ANY];
return nextAccessed;
}
Expand All @@ -452,6 +458,8 @@ function processDotAccessor(
!isTypeOfKind(dottableType, 'Enum') &&
!property.def
) {
// Pop the self-scope so the RHS is in the right place!
popSelfScope();
property =
assignVariable(
visitor,
Expand Down Expand Up @@ -481,6 +489,9 @@ function processDotAccessor(
} else if (lastAccessed.rhs) {
// Then this variable is not yet defined on this struct,
// but we have an assignment operation to use to define it.
// We need to pop the scope first so that the RHS is evaluated
// in the correct scope!
popSelfScope();
property = assignVariable(
visitor,
{
Expand Down Expand Up @@ -512,8 +523,7 @@ function processDotAccessor(
);
}
}
visitor.PROCESSOR.scope.setEnd(propertyNameLocation, true);
visitor.PROCESSOR.popSelfScope(propertyNameLocation, true);
popSelfScope();
nextAccessed.signifier = property;
nextAccessed.types = arrayWrapped(property?.type || visitor.ANY);
return nextAccessed;
Expand Down

0 comments on commit c09d25b

Please sign in to comment.