A position in source code (1-based line and column).
@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
Location
A span in source code with 1-based line and column coordinates.
ParseErrorInfo
A parse error with its location in the source.
CommentInfo
A comment descriptor. Only present when captureComments is enabled
in the ParseOptions.
type: "Comment" | "BlockComment" | "BrokenComment"
SurroundingText
TableAccess
AttrType
AstAttr
AstGenericType
AstGenericTypePack
AstTypeOrPack
kind: "Type" | "TypePack" | "Unknown"
AstTypeList
TypeReference
type TypeReference = {
type: "TypeReference",
location: Location,
hasParameterList: boolean,
name: string,
nameLocation: Location,
prefix: string?,
prefixLocation: Location?,
parameters: { AstTypeOrPack }?
}
type: "TypeReference"
TypeTableProp
type TypeTableProp = {
name: string,
type: AstType,
location: Location,
access: TableAccess,
accessLocation: Location?
}
TypeTableIndexer
type TypeTableIndexer = {
indexType: AstType,
resultType: AstType,
location: Location,
access: TableAccess,
accessLocation: Location?
}
TypeTable
type TypeTable = {
type: "TypeTable",
location: Location,
props: { TypeTableProp },
indexer: TypeTableIndexer?
}
type: "TypeTable"
TypeFunction
type TypeFunction = {
type: "TypeFunction",
location: Location,
attributes: { AstAttr }?,
generics: { AstGenericType }?,
genericPacks: { AstGenericTypePack }?,
argTypes: AstTypeList,
argNames: { AstTypeName? },
returnTypes: AstTypePack?
}
type: "TypeFunction"
TypeTypeof
type: "TypeTypeof"
TypeOptional
type: "TypeOptional"
TypeUnion
type: "TypeUnion"
TypeIntersection
type: "TypeIntersection"
TypeSingletonBool
type: "TypeSingletonBool"
TypeSingletonString
type: "TypeSingletonString"
TypeGroup
type: "TypeGroup"
TypeError
type: "TypeError"
TypeUnknown
type: "TypeUnknown"
AstType
Union of all type annotation nodes.
type AstType = TypeReference
| TypeTable
| TypeFunction
| TypeTypeof
| TypeOptional
| TypeUnion
| TypeIntersection
| TypeSingletonBool
| TypeSingletonString
| TypeGroup
| TypeError
| TypeUnknown
TypePackExplicit
type TypePackExplicit = {
type: "TypePackExplicit",
location: Location,
types: { AstType },
tail: AstTypePack?
}
type: "TypePackExplicit"
TypePackVariadic
type: "TypePackVariadic"
TypePackGeneric
type: "TypePackGeneric"
TypePackUnknown
type: "TypePackUnknown"
AstTypePack
Union of all type-pack nodes (used for return types and variadic packs).
AstLocal
ExprGroup
type: "ExprGroup"
ExprConstantNil
type: "ExprConstantNil"
ExprConstantBool
type: "ExprConstantBool"
ExprConstantNumber
type ExprConstantNumber = {
type: "ExprConstantNumber",
location: Location,
value: number,
parseResult: "Ok"
| "Imprecise"
| "Malformed"
| "BinOverflow"
| "HexOverflow"
| "Unknown"
}
type: "ExprConstantNumber"
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"
quoteStyle: "QuotedSimple" | "QuotedSingle" | "QuotedRaw" | "Unquoted" | "Unknown"
ExprLocal
type: "ExprLocal"
ExprGlobal
type: "ExprGlobal"
ExprVarargs
type: "ExprVarargs"
ExprCall
type: "ExprCall"
ExprIndexName
type: "ExprIndexName"
ExprIndexExpr
type: "ExprIndexExpr"
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"
ExprTableItem
kind: "List" | "Record" | "General"
ExprTable
type: "ExprTable"
ExprUnary
type: "ExprUnary"
ExprBinary
type ExprBinary = {
type: "ExprBinary",
location: Location,
op: string,
left: AstExpr,
right: AstExpr
}
type: "ExprBinary"
ExprTypeAssertion
type ExprTypeAssertion = {
type: "ExprTypeAssertion",
location: Location,
expr: AstExpr,
annotation: AstType
}
type: "ExprTypeAssertion"
ExprIfElse
type: "ExprIfElse"
ExprInterpString
type ExprInterpString = {
type: "ExprInterpString",
location: Location,
strings: { string },
expressions: { AstExpr }
}
type: "ExprInterpString"
ExprInstantiate
type ExprInstantiate = {
type: "ExprInstantiate",
location: Location,
expr: AstExpr,
typeArguments: { AstTypeOrPack }
}
type: "ExprInstantiate"
ExprError
type: "ExprError"
ExprUnknown
type: "ExprUnknown"
AstExpr
Union of all expression nodes.
type AstExpr = ExprGroup
| ExprConstantNil
| ExprConstantBool
| ExprConstantNumber
| ExprConstantString
| ExprLocal
| ExprGlobal
| ExprVarargs
| ExprCall
| ExprIndexName
| ExprIndexExpr
| ExprFunction
| ExprTable
| ExprUnary
| ExprBinary
| ExprTypeAssertion
| ExprIfElse
| ExprInterpString
| ExprInstantiate
| ExprError
| ExprUnknown
Block
type: "Block"
StatIf
type: "StatIf"
StatWhile
type: "StatWhile"
StatRepeat
type: "StatRepeat"
StatBreak
type: "StatBreak"
StatContinue
type: "StatContinue"
StatReturn
type StatReturn = {
type: "StatReturn",
location: Location,
hasSemicolon: boolean,
list: { AstExpr }
}
type: "StatReturn"
StatExpr
type: "StatExpr"
StatLocal
type: "StatLocal"
StatFor
type: "StatFor"
StatForIn
type: "StatForIn"
StatAssign
type StatAssign = {
type: "StatAssign",
location: Location,
hasSemicolon: boolean,
vars: { AstExpr },
values: { AstExpr }
}
type: "StatAssign"
StatCompoundAssign
type: "StatCompoundAssign"
StatFunction
type StatFunction = {
type: "StatFunction",
location: Location,
hasSemicolon: boolean,
name: AstExpr,
func: ExprFunction
}
type: "StatFunction"
StatLocalFunction
type StatLocalFunction = {
type: "StatLocalFunction",
location: Location,
hasSemicolon: boolean,
name: AstLocal,
func: ExprFunction
}
type: "StatLocalFunction"
StatTypeAlias
type StatTypeAlias = {
type: "StatTypeAlias",
location: Location,
hasSemicolon: boolean,
name: string,
nameLocation: Location,
exported: boolean,
aliasedType: AstType,
generics: { AstGenericType }?,
genericPacks: { AstGenericTypePack }?
}
type: "StatTypeAlias"
StatTypeFunction
type StatTypeFunction = {
type: "StatTypeFunction",
location: Location,
hasSemicolon: boolean,
name: string,
nameLocation: Location,
body: ExprFunction,
exported: boolean,
hasErrors: boolean
}
type: "StatTypeFunction"
StatDeclareGlobal
type: "StatDeclareGlobal"
AstParamName
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"
AstDeclaredExternTypeProperty
StatDeclareExternType
type StatDeclareExternType = {
type: "StatDeclareExternType",
location: Location,
hasSemicolon: boolean,
name: string,
superName: string?,
props: { AstDeclaredExternTypeProperty },
indexer: TypeTableIndexer?
}
type: "StatDeclareExternType"
StatError
type: "StatError"
StatUnknown
type: "StatUnknown"
AstStat
Union of all statement nodes.
type AstStat = Block
| StatIf
| StatWhile
| StatRepeat
| StatBreak
| StatContinue
| StatReturn
| StatExpr
| StatLocal
| StatFor
| StatForIn
| StatAssign
| StatCompoundAssign
| StatFunction
| StatLocalFunction
| StatTypeAlias
| StatTypeFunction
| StatDeclareGlobal
| StatDeclareFunction
| StatDeclareExternType
| StatError
| StatUnknown
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
}