diff --git a/.changes/61-bug.md b/.changes/61-bug.md new file mode 100644 index 0000000..531cb96 --- /dev/null +++ b/.changes/61-bug.md @@ -0,0 +1 @@ +align w/ breaking changes to AST function nodes diff --git a/foreman.toml b/foreman.toml index a72721d..83b09cb 100644 --- a/foreman.toml +++ b/foreman.toml @@ -1,3 +1,3 @@ [tools] -lute = { source = "luau-lang/lute", version = "=0.1.0-nightly.20260124" } +lute = { source = "luau-lang/lute", version = "=0.1.0-nightly.20260130" } stylua = { source = "JohnnyMorganz/StyLua", version = "2.0.2" } \ No newline at end of file diff --git a/frontend/src/tests/TreeNode.test.tsx b/frontend/src/tests/TreeNode.test.tsx index 63f835c..4f94bfd 100644 --- a/frontend/src/tests/TreeNode.test.tsx +++ b/frontend/src/tests/TreeNode.test.tsx @@ -401,7 +401,7 @@ describe("TreeNode", () => { describe("array type inference edge cases", () => { test("handles punctuated arrays", () => { const punctuatedNode = { - _astType: "AstFunctionBody", + _astType: "AstExprFunction", parameters: [ // Use proper Punctuated structures { diff --git a/frontend/src/utils/astTypeDefinitions.ts b/frontend/src/utils/astTypeDefinitions.ts index 48d8ad7..9c5bc4a 100644 --- a/frontend/src/utils/astTypeDefinitions.ts +++ b/frontend/src/utils/astTypeDefinitions.ts @@ -240,8 +240,13 @@ export const astTypeDefinitions: Record = { ], }, - AstFunctionBody: { + AstExprFunction: { properties: [ + { name: "location", type: "span" }, + { name: "kind", type: '"expr"' }, + { name: "tag", type: '"function"' }, + { name: "attributes", type: "{ AstAttribute }" }, + { name: "functionkeyword", type: "Token", generic: 'Token<"function">' }, { name: "opengenerics", type: "Token", @@ -266,8 +271,8 @@ export const astTypeDefinitions: Record = { generic: 'Token<">">', optional: true, }, - { name: "self", type: "AstLocal", optional: true }, { name: "openparens", type: "Token", generic: 'Token<"(">' }, + { name: "self", type: "AstLocal", optional: true }, { name: "parameters", type: "Punctuated", @@ -299,17 +304,6 @@ export const astTypeDefinitions: Record = { ], }, - AstExprAnonymousFunction: { - properties: [ - { name: "location", type: "span" }, - { name: "kind", type: '"expr"' }, - { name: "tag", type: '"function"' }, - { name: "attributes", type: "{ AstAttribute }" }, - { name: "functionkeyword", type: "Token", generic: 'Token<"function">' }, - { name: "body", type: "AstFunctionBody" }, - ], - }, - AstExprTableItemList: { properties: [ { name: "location", type: "span" }, @@ -459,7 +453,7 @@ export const astTypeDefinitions: Record = { "AstExprCall", "AstExprIndexName", "AstExprIndexExpr", - "AstExprAnonymousFunction", + "AstExprFunction", "AstExprTable", "AstExprUnary", "AstExprBinary", @@ -683,10 +677,8 @@ export const astTypeDefinitions: Record = { { name: "location", type: "span" }, { name: "kind", type: '"stat"' }, { name: "tag", type: '"function"' }, - { name: "attributes", type: "{ AstAttribute }" }, - { name: "functionkeyword", type: "Token", generic: 'Token<"function">' }, { name: "name", type: "AstExpr" }, - { name: "body", type: "AstFunctionBody" }, + { name: "func", type: "AstExprFunction" }, ], }, @@ -695,11 +687,9 @@ export const astTypeDefinitions: Record = { { name: "location", type: "span" }, { name: "kind", type: '"stat"' }, { name: "tag", type: '"localfunction"' }, - { name: "attributes", type: "{ AstAttribute }" }, { name: "localkeyword", type: "Token", generic: 'Token<"local">' }, - { name: "functionkeyword", type: "Token", generic: 'Token<"function">' }, { name: "name", type: "AstLocal" }, - { name: "body", type: "AstFunctionBody" }, + { name: "func", type: "AstExprFunction" }, ], }, @@ -757,9 +747,8 @@ export const astTypeDefinitions: Record = { optional: true, }, { name: "type", type: "Token", generic: 'Token<"type">' }, - { name: "functionkeyword", type: "Token", generic: 'Token<"function">' }, { name: "name", type: "Token" }, - { name: "body", type: "AstFunctionBody" }, + { name: "body", type: "AstExprFunction" }, ], }, diff --git a/lua_helpers/typeAnnotations.lua b/lua_helpers/typeAnnotations.lua index 281e5eb..2749a21 100644 --- a/lua_helpers/typeAnnotations.lua +++ b/lua_helpers/typeAnnotations.lua @@ -129,7 +129,7 @@ local typeDefinitions = { -- Expression/Statement specific ["expression"] = "AstExpr", - ["func"] = "AstExpr", + ["func"] = "AstExprFunction", ["condition"] = "AstExpr", ["from"] = "AstExpr", ["to"] = "AstExpr", @@ -210,11 +210,12 @@ local function resolveAmbiguousTags(node) -- AstTypeFunction has returnarrow and kind="type" if kind == "type" or node.returnarrow then return "AstTypeFunction" - -- AstStatFunction has name and kind="stat" - elseif kind == "stat" or node.name then + -- AstStatFunction has name field and kind="stat" (but not func field directly on it) + elseif kind == "stat" then return "AstStatFunction" else - return "AstExprAnonymousFunction" + -- AstExprFunction (consolidated from old AstExprAnonymousFunction + AstFunctionBody) + return "AstExprFunction" end elseif tag == "group" then -- AstExprGroup has expression and kind="expr", AstTypeGroup has type and kind="type" @@ -286,9 +287,10 @@ local function resolveAmbiguousKeys(nodeKey, node, parentNode, parentKey) -- Ambiguous keys that need context-aware resolution: if nodeKey == "body" then - -- AstStatBlock vs AstFunctionBody vs { AstStat } for AstStatDo - if node.openparens then - return "AstFunctionBody" + -- AstStatBlock vs AstExprFunction (for AstStatTypeFunction) vs { AstStat } for AstStatDo + if node.functionkeyword and node.openparens then + -- This is AstExprFunction (used in AstStatTypeFunction.body) + return "AstExprFunction" elseif node.statements then return "AstStatBlock" else diff --git a/lua_tests/helpers/typeAnnotationTestHelpers.lua b/lua_tests/helpers/typeAnnotationTestHelpers.lua index 69cd46a..d14d751 100644 --- a/lua_tests/helpers/typeAnnotationTestHelpers.lua +++ b/lua_tests/helpers/typeAnnotationTestHelpers.lua @@ -108,8 +108,8 @@ typeAnnotationVisitor.visitStatFunction = function(node: luau.AstStatFunction) return true end -typeAnnotationVisitor.visitExprAnonymousFunction = function(node: luau.AstExprAnonymousFunction) - verifyOutput(node, "visitAnonymousFunction", node._astType == "AstExprAnonymousFunction") +typeAnnotationVisitor.visitExprFunction = function(node: luau.AstExprFunction) + verifyOutput(node, "visitExprFunction", node._astType == "AstExprFunction") return true end @@ -305,7 +305,7 @@ local ambiguousTagTestCases = { { { tag = "conditional", kind = "expr" }, "AstExprIfElse", "if expression" }, { { tag = "function", kind = "type", returnarrow = {} }, "AstTypeFunction", "type function" }, { { tag = "function", kind = "stat", name = {} }, "AstStatFunction", "function statement" }, - { { tag = "function", kind = "expr" }, "AstExprAnonymousFunction", "anonymous function" }, + { { tag = "function", kind = "expr" }, "AstExprFunction", "expression function" }, { { tag = "group", kind = "expr", expression = {} }, "AstExprGroup", "expression group" }, { { tag = "group", kind = "type", type = {} }, "AstTypeGroup", "type group" }, { { tag = "local", kind = "expr", token = {}, upvalue = false }, "AstExprLocal", "local expression" }, @@ -316,14 +316,14 @@ local ambiguousTagTestCases = { local ambiguousKeyTestCases = { -- {key, node, parent, expectedType, description} - { "body", { openparens = {} }, {}, "AstFunctionBody", "function body" }, + { "body", { functionkeyword = {}, openparens = {} }, {}, "AstExprFunction", "function body (AstStatTypeFunction)" }, { "body", { statements = {} }, { tag = "if" }, "AstStatBlock", "if body" }, { "operand", { tag = "call" }, { operator = {}, tag = "unary" }, "AstExpr", "unary operand" }, { "self", {}, {}, "AstLocal", "self parameter" }, { "self", {}, { tag = "call" }, "boolean", "no self parameter" }, { "condition", { tag = "binary" }, {}, "AstExpr", "condition expression" }, { "expression", { tag = "call" }, {}, "AstExpr", "expression" }, - { "func", { tag = "function" }, {}, "AstExpr", "function expression" }, + { "func", { tag = "function" }, {}, "AstExprFunction", "function expression" }, { "key", {}, { kind = "record", istableitem = true }, "Token", "record key" }, { "key", {}, { kind = "indexer" }, "AstType", "indexer key" }, { "key", {}, { kind = "general", istableitem = true }, "AstExpr", "general key" }, diff --git a/rokit.toml b/rokit.toml index 04e7172..ab91290 100644 --- a/rokit.toml +++ b/rokit.toml @@ -1,3 +1,3 @@ [tools] -lute = "luau-lang/lute@0.1.0-nightly.20251213" +lute = "luau-lang/lute@0.1.0-nightly.20260130" stylua = "JohnnyMorganz/StyLua@2.0.2"