Skip to content

Commit

Permalink
fix: VisitConditionalAccessExpression being defined twice
Browse files Browse the repository at this point in the history
  • Loading branch information
denispionicul committed Jan 10, 2025
1 parent 4284556 commit 311036c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
14 changes: 14 additions & 0 deletions RobloxCS.Luau/Macros.cs
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,20 @@ private static bool DictionaryMethod(Func<SyntaxNode, Node?> visit, MemberAccess
expanded = new Assignment(new ElementAccess(self, key), value);
break;
}
case "ContainsKey": {
var arguments = (ArgumentList)visit(invocation.ArgumentList)!;
var self = (Expression)visit(memberAccess.Expression)!;
var key = arguments.Arguments.First().Expression;

expanded = new BinaryOperator(new ElementAccess(self, key), "~=", AstUtility.Nil());
break;
}
case "Clear": {
var self = (Expression)visit(memberAccess.Expression)!;

expanded = new Call(new QualifiedName(new IdentifierName("table"), new IdentifierName("clear")), new ArgumentList([new Argument(self)]));
break;
}
}

expanded?.MarkExpanded(MacroKind.DictionaryMethod);
Expand Down
4 changes: 0 additions & 4 deletions RobloxCS/LuauGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -725,10 +725,6 @@ public override Luau.Node VisitPostfixUnaryExpression(PostfixUnaryExpressionSynt
return new Luau.UnaryOperator(mappedOperator, operand);
}

public override Luau.BinaryOperator VisitConditionalAccessExpression(ConditionalAccessExpressionSyntax node) {
return new Luau.BinaryOperator(new Luau.BinaryOperator(Visit<Luau.Expression>(node.Expression), "~=", Luau.AstUtility.Nil()), "and", Visit<Luau.Expression>(node.WhenNotNull));
}

public override Luau.Call VisitSwitchExpression(SwitchExpressionSyntax node) {
var statements = new List<Luau.Statement>();
var createTempVariable = node.GoverningExpression is not IdentifierNameSyntax && node.GoverningExpression is not LiteralExpressionSyntax;
Expand Down

0 comments on commit 311036c

Please sign in to comment.