Skip to content

Commit 5100827

Browse files
committed
Handle AstExprVarargs
1 parent dc985a5 commit 5100827

File tree

3 files changed

+14
-3
lines changed

3 files changed

+14
-3
lines changed

batteries/codemod/ast_types.luau

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@ export type AstExprGlobal = {
7474
name: Token,
7575
}
7676

77+
export type AstExprVarargs = Token<"..."> & { tag: "vararg" }
78+
7779
export type AstExprCall = {
7880
tag: "call",
7981
func: AstExpr, -- TODO: stricter?
@@ -158,6 +160,7 @@ export type AstExpr =
158160
| AstExprConstantString
159161
| AstExprLocal
160162
| AstExprGlobal
163+
| AstExprVarargs
161164
| AstExprCall
162165
| AstExprIndexName
163166
| AstExprIndexExpr

batteries/codemod/visitor.luau

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ type Visitor = {
2626
visitBoolean: (T.AstExprConstantBool) -> boolean,
2727
visitNumber: (T.AstExprConstantNumber) -> boolean,
2828
visitLocal: (T.AstLocal) -> boolean,
29+
visitVarargs: (T.AstExprVarargs) -> boolean,
2930
}
3031

3132
local function alwaysVisit(...: any)
@@ -56,6 +57,7 @@ local defaultVisitor: Visitor = {
5657
visitBoolean = alwaysVisit :: any,
5758
visitNumber = alwaysVisit :: any,
5859
visitLocal = alwaysVisit :: any,
60+
visitVarargs = alwaysVisit :: any,
5961
}
6062

6163
local function exhaustiveMatch(value: never): never
@@ -160,6 +162,12 @@ local function visitGlobal(node: T.AstExprGlobal, visitor: Visitor)
160162
end
161163
end
162164

165+
local function visitVarargs(node: T.AstExprVarargs, visitor: Visitor)
166+
if visitor.visitVarargs(node) then
167+
visitToken(node)
168+
end
169+
end
170+
163171
local function visitCall(node: T.AstExprCall, visitor: Visitor)
164172
if visitor.visitCall(node) then
165173
visitExpression(node.func, visitor)
@@ -278,6 +286,8 @@ function visitExpression(expression: T.AstExpr, visitor: Visitor)
278286
visitLocalReference(expression, visitor)
279287
elseif expression.tag == "global" then
280288
visitGlobal(expression, visitor)
289+
elseif expression.tag == "vararg" then
290+
visitVarargs(expression, visitor)
281291
elseif expression.tag == "call" then
282292
visitCall(expression, visitor)
283293
elseif expression.tag == "unary" then

luau/src/luau.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -571,9 +571,7 @@ struct AstSerialize : public Luau::AstVisitor
571571

572572
void serialize(Luau::AstExprVarargs* node)
573573
{
574-
lua_rawcheckstack(L, 2);
575-
lua_createtable(L, 0, preambleSize);
576-
574+
serializeToken(node->location.begin, "...", preambleSize);
577575
serializeNodePreamble(node, "vararg");
578576
}
579577

0 commit comments

Comments
 (0)