@eryx/luau/ast Module

Shared Luau AST and parse-result type definitions.

This module is intended for type imports by the split @eryx/luau/* libraries. At runtime it returns an empty frozen table.

API Reference

Types

Position

A position in source code (1-based line and column).

type Position = { line: number, column: number }
line: number
column: number

Location

A span in source code with 1-based line and column coordinates.

type Location = { beginline: number, begincolumn: number, endline: number, endcolumn: number }
beginline: number
begincolumn: number
endline: number
endcolumn: number

ParseErrorInfo

A parse error with its location in the source.

type ParseErrorInfo = { message: string, location: Location }
message: string
location: Location

CommentInfo

A comment descriptor. Only present when captureComments is enabled in the ParseOptions.

type CommentInfo = { type: "Comment" | "BlockComment" | "BrokenComment", location: Location }
type: "Comment" | "BlockComment" | "BrokenComment"
location: Location

SurroundingText

type SurroundingText = { leading: string?, trailing: string? }
leading: string?
trailing: string?

ParseOptions

Options for parse.

type ParseOptions = { captureComments: boolean?, collectSurroundingText: boolean? }
captureComments: boolean?
collectSurroundingText: boolean?

TableAccess

type TableAccess = "Read" | "Write" | "ReadWrite"

AttrType

type AttrType = "Checked" | "Native" | "Deprecated" | "Unknown"

AstAttr

type AstAttr = { type: AttrType, location: Location, name: string?, args: { AstExpr }, deprecatedInfo: { deprecated: boolean, use: string?, reason: string? }? }
type: AttrType
location: Location
name: string?
args: { AstExpr }
deprecatedInfo: { deprecated: boolean, use: string?, reason: string? }?

AstGenericType

type AstGenericType = { name: string, location: Location, default: AstType? }
name: string
location: Location
default: AstType?

AstGenericTypePack

type AstGenericTypePack = { name: string, location: Location, default: AstTypePack? }
name: string
location: Location
default: AstTypePack?

AstTypeOrPack

type AstTypeOrPack = { kind: "Type" | "TypePack" | "Unknown", value: AstType | AstTypePack? }
kind: "Type" | "TypePack" | "Unknown"

AstTypeName

type AstTypeName = { name: string, location: Location }
name: string
location: Location

AstTypeList

type AstTypeList = { types: { AstType }, tail: AstTypePack? }
types: { AstType }

TypeReference

type TypeReference = { type: "TypeReference", location: Location, hasParameterList: boolean, name: string, nameLocation: Location, prefix: string?, prefixLocation: Location?, parameters: { AstTypeOrPack }? }
type: "TypeReference"
location: Location
hasParameterList: boolean
name: string
nameLocation: Location
prefix: string?
prefixLocation: Location?
parameters: { AstTypeOrPack }?

TypeTableProp

type TypeTableProp = { name: string, type: AstType, location: Location, access: TableAccess, accessLocation: Location? }
name: string
type: AstType
location: Location
access: TableAccess
accessLocation: Location?

TypeTableIndexer

type TypeTableIndexer = { indexType: AstType, resultType: AstType, location: Location, access: TableAccess, accessLocation: Location? }
indexType: AstType
resultType: AstType
location: Location
access: TableAccess
accessLocation: Location?

TypeTable

type TypeTable = { type: "TypeTable", location: Location, props: { TypeTableProp }, indexer: TypeTableIndexer? }
type: "TypeTable"
location: Location
props: { TypeTableProp }

TypeFunction

type TypeFunction = { type: "TypeFunction", location: Location, attributes: { AstAttr }?, generics: { AstGenericType }?, genericPacks: { AstGenericTypePack }?, argTypes: AstTypeList, argNames: { AstTypeName? }, returnTypes: AstTypePack? }
type: "TypeFunction"
location: Location
attributes: { AstAttr }?
generics: { AstGenericType }?
genericPacks: { AstGenericTypePack }?
argTypes: AstTypeList
argNames: { AstTypeName? }
returnTypes: AstTypePack?

TypeTypeof

type TypeTypeof = { type: "TypeTypeof", location: Location, expr: AstExpr }
type: "TypeTypeof"
location: Location
expr: AstExpr

TypeOptional

type TypeOptional = { type: "TypeOptional", location: Location }
type: "TypeOptional"
location: Location

TypeUnion

type TypeUnion = { type: "TypeUnion", location: Location, types: { AstType } }
type: "TypeUnion"
location: Location
types: { AstType }

TypeIntersection

type TypeIntersection = { type: "TypeIntersection", location: Location, types: { AstType } }
type: "TypeIntersection"
location: Location
types: { AstType }

TypeSingletonBool

type TypeSingletonBool = { type: "TypeSingletonBool", location: Location, value: boolean }
type: "TypeSingletonBool"
location: Location
value: boolean

TypeSingletonString

type TypeSingletonString = { type: "TypeSingletonString", location: Location, value: string }
type: "TypeSingletonString"
location: Location
value: string

TypeGroup

type TypeGroup = { type: "TypeGroup", location: Location, inner: AstType }
type: "TypeGroup"
location: Location
inner: AstType

TypeError

type TypeError = { type: "TypeError", location: Location, types: { AstType }, isMissing: boolean, messageIndex: number }
type: "TypeError"
location: Location
types: { AstType }
isMissing: boolean
messageIndex: number

TypeUnknown

type TypeUnknown = { type: "TypeUnknown", location: Location }
type: "TypeUnknown"
location: Location

AstType

Union of all type annotation nodes.

TypePackExplicit

type TypePackExplicit = { type: "TypePackExplicit", location: Location, types: { AstType }, tail: AstTypePack? }
type: "TypePackExplicit"
location: Location
types: { AstType }

TypePackVariadic

type TypePackVariadic = { type: "TypePackVariadic", location: Location, variadicType: AstType }
type: "TypePackVariadic"
location: Location
variadicType: AstType

TypePackGeneric

type TypePackGeneric = { type: "TypePackGeneric", location: Location, name: string }
type: "TypePackGeneric"
location: Location
name: string

TypePackUnknown

type TypePackUnknown = { type: "TypePackUnknown", location: Location }
type: "TypePackUnknown"
location: Location

AstTypePack

Union of all type-pack nodes (used for return types and variadic packs).

AstLocal

type AstLocal = { name: string, location: Location, annotation: AstType?, functionDepth: number, loopDepth: number, isConst: boolean, shadow: { name: string, location: Location }? }
name: string
location: Location
annotation: AstType?
functionDepth: number
loopDepth: number
isConst: boolean
shadow: { name: string, location: Location }?

ExprGroup

type ExprGroup = { type: "ExprGroup", location: Location, expr: AstExpr }
type: "ExprGroup"
location: Location
expr: AstExpr

ExprConstantNil

type ExprConstantNil = { type: "ExprConstantNil", location: Location }
type: "ExprConstantNil"
location: Location

ExprConstantBool

type ExprConstantBool = { type: "ExprConstantBool", location: Location, value: boolean }
type: "ExprConstantBool"
location: Location
value: boolean

ExprConstantNumber

type ExprConstantNumber = { type: "ExprConstantNumber", location: Location, value: number, parseResult: "Ok" | "Imprecise" | "Malformed" | "BinOverflow" | "HexOverflow" | "Unknown" }
type: "ExprConstantNumber"
location: Location
value: number
parseResult: "Ok" | "Imprecise" | "Malformed" | "BinOverflow" | "HexOverflow" | "Unknown"

ExprConstantString

type ExprConstantString = { type: "ExprConstantString", location: Location, value: string, quoteStyle: "QuotedSimple" | "QuotedSingle" | "QuotedRaw" | "Unquoted" | "Unknown", isQuoted: boolean }
type: "ExprConstantString"
location: Location
value: string
quoteStyle: "QuotedSimple" | "QuotedSingle" | "QuotedRaw" | "Unquoted" | "Unknown"
isQuoted: boolean

ExprLocal

type ExprLocal = { type: "ExprLocal", location: Location, local: AstLocal, upvalue: boolean }
type: "ExprLocal"
location: Location
local: AstLocal
upvalue: boolean

ExprGlobal

type ExprGlobal = { type: "ExprGlobal", location: Location, name: string }
type: "ExprGlobal"
location: Location
name: string

ExprVarargs

type ExprVarargs = { type: "ExprVarargs", location: Location }
type: "ExprVarargs"
location: Location

ExprCall

type ExprCall = { type: "ExprCall", location: Location, func: AstExpr, typeArguments: { AstTypeOrPack }?, args: { AstExpr }, self: boolean, argLocation: Location }
type: "ExprCall"
location: Location
func: AstExpr
typeArguments: { AstTypeOrPack }?
args: { AstExpr }
self: boolean
argLocation: Location

ExprIndexName

type ExprIndexName = { type: "ExprIndexName", location: Location, expr: AstExpr, index: string, indexLocation: Location, opPosition: Position, op: string }
type: "ExprIndexName"
location: Location
expr: AstExpr
index: string
indexLocation: Location
opPosition: Position
op: string

ExprIndexExpr

type ExprIndexExpr = { type: "ExprIndexExpr", location: Location, expr: AstExpr, index: AstExpr }
type: "ExprIndexExpr"
location: Location
expr: AstExpr
index: AstExpr

ExprFunction

type ExprFunction = { type: "ExprFunction", location: Location, attributes: { AstAttr }?, debugname: string?, generics: { AstGenericType }?, genericPacks: { AstGenericTypePack }?, args: { AstLocal }, vararg: boolean, varargLocation: Location?, varargAnnotation: AstTypePack?, returnAnnotation: AstTypePack?, self: AstLocal?, argLocation: Location?, functionDepth: number, body: Block }
type: "ExprFunction"
location: Location
attributes: { AstAttr }?
debugname: string?
generics: { AstGenericType }?
genericPacks: { AstGenericTypePack }?
args: { AstLocal }
vararg: boolean
varargLocation: Location?
varargAnnotation: AstTypePack?
returnAnnotation: AstTypePack?
self: AstLocal?
argLocation: Location?
functionDepth: number
body: Block

ExprTableItem

type ExprTableItem = { kind: "List" | "Record" | "General", key: AstExpr?, value: AstExpr }
kind: "List" | "Record" | "General"
key: AstExpr?
value: AstExpr

ExprTable

type ExprTable = { type: "ExprTable", location: Location, items: { ExprTableItem } }
type: "ExprTable"
location: Location
items: { ExprTableItem }

ExprUnary

type ExprUnary = { type: "ExprUnary", location: Location, op: string, expr: AstExpr }
type: "ExprUnary"
location: Location
op: string
expr: AstExpr

ExprBinary

type ExprBinary = { type: "ExprBinary", location: Location, op: string, left: AstExpr, right: AstExpr }
type: "ExprBinary"
location: Location
op: string
left: AstExpr
right: AstExpr

ExprTypeAssertion

type ExprTypeAssertion = { type: "ExprTypeAssertion", location: Location, expr: AstExpr, annotation: AstType }
type: "ExprTypeAssertion"
location: Location
expr: AstExpr
annotation: AstType

ExprIfElse

type ExprIfElse = { type: "ExprIfElse", location: Location, condition: AstExpr, hasThen: boolean, trueExpr: AstExpr, hasElse: boolean, falseExpr: AstExpr }
type: "ExprIfElse"
location: Location
condition: AstExpr
hasThen: boolean
trueExpr: AstExpr
hasElse: boolean
falseExpr: AstExpr

ExprInterpString

type ExprInterpString = { type: "ExprInterpString", location: Location, strings: { string }, expressions: { AstExpr } }
type: "ExprInterpString"
location: Location
strings: { string }
expressions: { AstExpr }

ExprInstantiate

type ExprInstantiate = { type: "ExprInstantiate", location: Location, expr: AstExpr, typeArguments: { AstTypeOrPack } }
type: "ExprInstantiate"
location: Location
expr: AstExpr
typeArguments: { AstTypeOrPack }

ExprError

type ExprError = { type: "ExprError", location: Location, expressions: { AstExpr }, messageIndex: number }
type: "ExprError"
location: Location
expressions: { AstExpr }
messageIndex: number

ExprUnknown

type ExprUnknown = { type: "ExprUnknown", location: Location }
type: "ExprUnknown"
location: Location

AstExpr

Union of all expression nodes.

Block

type Block = { type: "Block", location: Location, hasSemicolon: boolean, body: { AstStat }, hasEnd: boolean }
type: "Block"
location: Location
hasSemicolon: boolean
body: { AstStat }
hasEnd: boolean

StatIf

type StatIf = { type: "StatIf", location: Location, hasSemicolon: boolean, condition: AstExpr, thenBody: Block, elseBody: (Block | StatIf)?, thenLocation: Location?, elseLocation: Location? }
type: "StatIf"
location: Location
hasSemicolon: boolean
condition: AstExpr
thenBody: Block
elseBody: (Block | StatIf)?
thenLocation: Location?
elseLocation: Location?

StatWhile

type StatWhile = { type: "StatWhile", location: Location, hasSemicolon: boolean, condition: AstExpr, body: Block, hasDo: boolean, doLocation: Location }
type: "StatWhile"
location: Location
hasSemicolon: boolean
condition: AstExpr
body: Block
hasDo: boolean
doLocation: Location

StatRepeat

type StatRepeat = { type: "StatRepeat", location: Location, hasSemicolon: boolean, condition: AstExpr, body: Block, hasUntil: boolean }
type: "StatRepeat"
location: Location
hasSemicolon: boolean
condition: AstExpr
body: Block
hasUntil: boolean

StatBreak

type StatBreak = { type: "StatBreak", location: Location, hasSemicolon: boolean }
type: "StatBreak"
location: Location
hasSemicolon: boolean

StatContinue

type StatContinue = { type: "StatContinue", location: Location, hasSemicolon: boolean }
type: "StatContinue"
location: Location
hasSemicolon: boolean

StatReturn

type StatReturn = { type: "StatReturn", location: Location, hasSemicolon: boolean, list: { AstExpr } }
type: "StatReturn"
location: Location
hasSemicolon: boolean
list: { AstExpr }

StatExpr

type StatExpr = { type: "StatExpr", location: Location, hasSemicolon: boolean, expr: AstExpr }
type: "StatExpr"
location: Location
hasSemicolon: boolean
expr: AstExpr

StatLocal

type StatLocal = { type: "StatLocal", location: Location, hasSemicolon: boolean, vars: { AstLocal }, values: { AstExpr }, equalsSignLocation: Location? }
type: "StatLocal"
location: Location
hasSemicolon: boolean
vars: { AstLocal }
values: { AstExpr }
equalsSignLocation: Location?

StatFor

type StatFor = { type: "StatFor", location: Location, hasSemicolon: boolean, var: AstLocal, from: AstExpr, to: AstExpr, step: AstExpr?, body: Block, hasDo: boolean, doLocation: Location }
type: "StatFor"
location: Location
hasSemicolon: boolean
from: AstExpr
step: AstExpr?
body: Block
hasDo: boolean
doLocation: Location

StatForIn

type StatForIn = { type: "StatForIn", location: Location, hasSemicolon: boolean, vars: { AstLocal }, values: { AstExpr }, body: Block, hasIn: boolean, inLocation: Location, hasDo: boolean, doLocation: Location }
type: "StatForIn"
location: Location
hasSemicolon: boolean
vars: { AstLocal }
values: { AstExpr }
body: Block
hasIn: boolean
inLocation: Location
hasDo: boolean
doLocation: Location

StatAssign

type StatAssign = { type: "StatAssign", location: Location, hasSemicolon: boolean, vars: { AstExpr }, values: { AstExpr } }
type: "StatAssign"
location: Location
hasSemicolon: boolean
vars: { AstExpr }
values: { AstExpr }

StatCompoundAssign

type StatCompoundAssign = { type: "StatCompoundAssign", location: Location, hasSemicolon: boolean, op: string, var: AstExpr, value: AstExpr }
type: "StatCompoundAssign"
location: Location
hasSemicolon: boolean
op: string
var: AstExpr
value: AstExpr

StatFunction

type StatFunction = { type: "StatFunction", location: Location, hasSemicolon: boolean, name: AstExpr, func: ExprFunction }
type: "StatFunction"
location: Location
hasSemicolon: boolean
name: AstExpr

StatLocalFunction

type StatLocalFunction = { type: "StatLocalFunction", location: Location, hasSemicolon: boolean, name: AstLocal, func: ExprFunction }
type: "StatLocalFunction"
location: Location
hasSemicolon: boolean
name: AstLocal

StatTypeAlias

type StatTypeAlias = { type: "StatTypeAlias", location: Location, hasSemicolon: boolean, name: string, nameLocation: Location, exported: boolean, aliasedType: AstType, generics: { AstGenericType }?, genericPacks: { AstGenericTypePack }? }
type: "StatTypeAlias"
location: Location
hasSemicolon: boolean
name: string
nameLocation: Location
exported: boolean
aliasedType: AstType
generics: { AstGenericType }?
genericPacks: { AstGenericTypePack }?

StatTypeFunction

type StatTypeFunction = { type: "StatTypeFunction", location: Location, hasSemicolon: boolean, name: string, nameLocation: Location, body: ExprFunction, exported: boolean, hasErrors: boolean }
type: "StatTypeFunction"
location: Location
hasSemicolon: boolean
name: string
nameLocation: Location
exported: boolean
hasErrors: boolean

StatDeclareGlobal

type StatDeclareGlobal = { type: "StatDeclareGlobal", location: Location, hasSemicolon: boolean, name: string, nameLocation: Location, declaredType: AstType }
type: "StatDeclareGlobal"
location: Location
hasSemicolon: boolean
name: string
nameLocation: Location
declaredType: AstType

AstParamName

type AstParamName = { name: string, location: Location }
name: string
location: Location

StatDeclareFunction

type StatDeclareFunction = { type: "StatDeclareFunction", location: Location, hasSemicolon: boolean, attributes: { AstAttr }?, name: string, nameLocation: Location, generics: { AstGenericType }?, genericPacks: { AstGenericTypePack }?, params: AstTypeList, paramNames: { AstParamName }, vararg: boolean, varargLocation: Location, returnTypes: AstTypePack }
type: "StatDeclareFunction"
location: Location
hasSemicolon: boolean
attributes: { AstAttr }?
name: string
nameLocation: Location
generics: { AstGenericType }?
genericPacks: { AstGenericTypePack }?
params: AstTypeList
paramNames: { AstParamName }
vararg: boolean
varargLocation: Location
returnTypes: AstTypePack

AstDeclaredExternTypeProperty

type AstDeclaredExternTypeProperty = { name: string, nameLocation: Location, type: AstType, isMethod: boolean, location: Location }
name: string
nameLocation: Location
type: AstType
isMethod: boolean
location: Location

StatDeclareExternType

type StatDeclareExternType = { type: "StatDeclareExternType", location: Location, hasSemicolon: boolean, name: string, superName: string?, props: { AstDeclaredExternTypeProperty }, indexer: TypeTableIndexer? }
type: "StatDeclareExternType"
location: Location
hasSemicolon: boolean
name: string
superName: string?

StatError

type StatError = { type: "StatError", location: Location, hasSemicolon: boolean, expressions: { AstExpr }, statements: { AstStat }, messageIndex: number }
type: "StatError"
location: Location
hasSemicolon: boolean
expressions: { AstExpr }
statements: { AstStat }
messageIndex: number

StatUnknown

type StatUnknown = { type: "StatUnknown", location: Location }
type: "StatUnknown"
location: Location

AstStat

Union of all statement nodes.

AstNode

Any AST node (statement, expression, or type annotation).

ParseResult

The result returned by parse.

type ParseResult = { root: Block, errors: { ParseErrorInfo }, comments: { CommentInfo }?, surroundingText: { [AstNode]: SurroundingText }?, lines: number }
root: Block
errors: { ParseErrorInfo }
comments: { CommentInfo }?
surroundingText: { [AstNode]: SurroundingText }?
lines: number