utils
local utils = require("@std/syntax/utils")WARNING
These APIs are still open to future evolution. In new major versions, they may change in backwards incompatible ways.
Summary
| Entry | Description |
|---|---|
| isAttribute | Returns n narrowed to CstAttribute if it is an attribute node, or nil otherwise. |
| isExpr | Returns n narrowed to CstExpr if it is any expression node, or nil otherwise. |
| isExprBinary | Returns n narrowed to CstExprBinary if it is a binary expression, or nil otherwise. |
| isExprCall | Returns n narrowed to CstExprCall if it is a call expression, or nil otherwise. |
| isExprConstantBool | Returns n narrowed to CstExprConstantBool if it is a boolean literal expression, or nil otherwise. |
| isExprConstantNil | Returns n narrowed to CstExprConstantNil if it is a nil literal expression, or nil otherwise. |
| isExprConstantNumber | Returns n narrowed to CstExprConstantNumber if it is a number literal expression, or nil otherwise. |
| isExprConstantString | Returns n narrowed to CstExprConstantString if it is a string literal expression, or nil otherwise. |
| isExprFunction | Returns n narrowed to CstExprFunction if it is a function expression, or nil otherwise. |
| isExprGlobal | Returns n narrowed to CstExprGlobal if it is a global variable reference expression, or nil otherwise. |
| isExprGroup | Returns n narrowed to CstExprGroup if it is a parenthesized expression, or nil otherwise. |
| isExprIfElse | Returns n narrowed to CstExprIfElse if it is an if-then-else expression, or nil otherwise. |
| isExprIndexExpr | Returns n narrowed to CstExprIndexExpr if it is an index expression (e.g. a[b]), or nil otherwise. |
| isExprIndexName | Returns n narrowed to CstExprIndexName if it is a field access expression (e.g. a.b), or nil otherwise. |
| isExprInterpString | Returns n narrowed to CstExprInterpString if it is an interpolated string expression, or nil otherwise. |
| isExprLocal | Returns n narrowed to CstExprLocal if it is a local variable reference expression, or nil otherwise. |
| isExprTable | Returns n narrowed to CstExprTable if it is a table constructor expression, or nil otherwise. |
| isExprTypeAssertion | Returns n narrowed to CstExprTypeAssertion if it is a type assertion expression (expr :: Type), or nil otherwise. |
| isExprUnary | Returns n narrowed to CstExprUnary if it is a unary expression, or nil otherwise. |
| isExprVarargs | Returns n narrowed to CstExprVarargs if it is a varargs expression (...), or nil otherwise. |
| isGenericType | Returns n narrowed to CstGenericType if it is a generic type parameter, or nil otherwise. |
| isGenericTypePack | Returns n narrowed to CstGenericTypePack if it is a generic type pack parameter, or nil otherwise. |
| isLocal | Returns n narrowed to CstLocal if it is a local variable node, or nil otherwise. |
| isRequireCall | Returns n as an CstExprCall if it is a require(...) call expression, or nil otherwise. |
| isStat | Returns n narrowed to CstStat if it is any statement node, or nil otherwise. |
| isStatAssign | Returns n narrowed to CstStatAssign if it is an assignment statement, or nil otherwise. |
| isStatBlock | Returns n narrowed to CstStatBlock if it is a block statement (do...end), or nil otherwise. |
| isStatBreak | Returns n narrowed to CstStatBreak if it is a break statement, or nil otherwise. |
| isStatCompoundAssign | Returns n narrowed to CstStatCompoundAssign if it is a compound assignment statement (e.g. +=), or nil otherwise. |
| isStatConst | Returns n narrowed to CstStatConst if it is a const variable declaration, or nil otherwise. |
| isStatContinue | Returns n narrowed to CstStatContinue if it is a continue statement, or nil otherwise. |
| isStatExpr | Returns n narrowed to CstStatExpr if it is an expression statement, or nil otherwise. |
| isStatFor | Returns n narrowed to CstStatFor if it is a numeric for statement, or nil otherwise. |
| isStatForIn | Returns n narrowed to CstStatForIn if it is a generic for-in statement, or nil otherwise. |
| isStatFunction | Returns n narrowed to CstStatFunction if it is a function declaration statement, or nil otherwise. |
| isStatIf | Returns n narrowed to CstStatIf if it is an if statement, or nil otherwise. |
| isStatLocal | Returns n narrowed to CstStatLocal if it is a local variable declaration, or nil otherwise. |
| isStatLocalFunction | Returns n narrowed to CstStatLocalFunction if it is a local function declaration, or nil otherwise. |
| isStatRepeat | Returns n narrowed to CstStatRepeat if it is a repeat-until statement, or nil otherwise. |
| isStatReturn | Returns n narrowed to CstStatReturn if it is a return statement, or nil otherwise. |
| isStatTypeAlias | Returns n narrowed to CstStatTypeAlias if it is a type alias declaration, or nil otherwise. |
| isStatTypeFunction | Returns n narrowed to CstStatTypeFunction if it is a type function declaration, or nil otherwise. |
| isStatWhile | Returns n narrowed to CstStatWhile if it is a while statement, or nil otherwise. |
| isTableExprItem | Returns n narrowed to CstTableExprItem if it is a table constructor item, or nil otherwise. |
| isToken | Returns n narrowed to CstToken if it is a token, or nil otherwise. |
| isType | Returns n narrowed to CstType if it is any type annotation node, or nil otherwise. |
| isTypeArray | Returns n narrowed to CstTypeArray if it is an array type ({T}), or nil otherwise. |
| isTypeFunction | Returns n narrowed to CstTypeFunction if it is a function type, or nil otherwise. |
| isTypeGroup | Returns n narrowed to CstTypeGroup if it is a parenthesized type, or nil otherwise. |
| isTypeIntersection | Returns n narrowed to CstTypeIntersection if it is a type intersection, or nil otherwise. |
| isTypeOptional | Returns n narrowed to CstTypeOptional if it is an optional type (T?), or nil otherwise. |
| isTypePack | Returns n narrowed to CstTypePack if it is any type pack node, or nil otherwise. |
| isTypePackExplicit | Returns n narrowed to CstTypePackExplicit if it is an explicit type pack, or nil otherwise. |
| isTypePackGeneric | Returns n narrowed to CstTypePackGeneric if it is a generic type pack, or nil otherwise. |
| isTypePackVariadic | Returns n narrowed to CstTypePackVariadic if it is a variadic type pack, or nil otherwise. |
| isTypeReference | Returns n narrowed to CstTypeReference if it is a type reference, or nil otherwise. |
| isTypeSingletonBool | Returns n narrowed to CstTypeSingletonBool if it is a boolean singleton type, or nil otherwise. |
| isTypeSingletonString | Returns n narrowed to CstTypeSingletonString if it is a string singleton type, or nil otherwise. |
| isTypeTable | Returns n narrowed to CstTypeTable if it is a table type, or nil otherwise. |
| isTypeTypeof | Returns n narrowed to CstTypeTypeof if it is a typeof(...) type, or nil otherwise. |
| isTypeUnion | Returns n narrowed to CstTypeUnion if it is a type union, or nil otherwise. |
| replacementWithTrivia | Returns a Replacement that replaces the original node with the given content, preserving trivia. |
| replacementWithoutTrivia | Returns a Replacement that replaces the original node with the given content, discarding trivia. |
Functions and Properties
utils.isAttribute
Returns n narrowed to CstAttribute if it is an attribute node, or nil otherwise.
(n: types.CstNode) -> types.CstAttribute?utils.isExpr
Returns n narrowed to CstExpr if it is any expression node, or nil otherwise.
(n: types.CstNode) -> types.CstExpr?utils.isExprBinary
Returns n narrowed to CstExprBinary if it is a binary expression, or nil otherwise.
(n: types.CstNode) -> types.CstExprBinary?utils.isExprCall
Returns n narrowed to CstExprCall if it is a call expression, or nil otherwise.
(n: types.CstNode) -> types.CstExprCall?utils.isExprConstantBool
Returns n narrowed to CstExprConstantBool if it is a boolean literal expression, or nil otherwise.
(n: types.CstNode) -> types.CstExprConstantBool?utils.isExprConstantNil
Returns n narrowed to CstExprConstantNil if it is a nil literal expression, or nil otherwise.
(n: types.CstNode) -> types.CstExprConstantNil?utils.isExprConstantNumber
Returns n narrowed to CstExprConstantNumber if it is a number literal expression, or nil otherwise.
(n: types.CstNode) -> types.CstExprConstantNumber?utils.isExprConstantString
Returns n narrowed to CstExprConstantString if it is a string literal expression, or nil otherwise.
(n: types.CstNode) -> types.CstExprConstantString?utils.isExprFunction
Returns n narrowed to CstExprFunction if it is a function expression, or nil otherwise.
(n: types.CstNode) -> types.CstExprFunction?utils.isExprGlobal
Returns n narrowed to CstExprGlobal if it is a global variable reference expression, or nil otherwise.
(n: types.CstNode) -> types.CstExprGlobal?utils.isExprGroup
Returns n narrowed to CstExprGroup if it is a parenthesized expression, or nil otherwise.
(n: types.CstNode) -> types.CstExprGroup?utils.isExprIfElse
Returns n narrowed to CstExprIfElse if it is an if-then-else expression, or nil otherwise.
(n: types.CstNode) -> types.CstExprIfElse?utils.isExprIndexExpr
Returns n narrowed to CstExprIndexExpr if it is an index expression (e.g. a[b]), or nil otherwise.
(n: types.CstNode) -> types.CstExprIndexExpr?utils.isExprIndexName
Returns n narrowed to CstExprIndexName if it is a field access expression (e.g. a.b), or nil otherwise.
(n: types.CstNode) -> types.CstExprIndexName?utils.isExprInterpString
Returns n narrowed to CstExprInterpString if it is an interpolated string expression, or nil otherwise.
(n: types.CstNode) -> types.CstExprInterpString?utils.isExprLocal
Returns n narrowed to CstExprLocal if it is a local variable reference expression, or nil otherwise.
(n: types.CstNode) -> types.CstExprLocal?utils.isExprTable
Returns n narrowed to CstExprTable if it is a table constructor expression, or nil otherwise.
(n: types.CstNode) -> types.CstExprTable?utils.isExprTypeAssertion
Returns n narrowed to CstExprTypeAssertion if it is a type assertion expression (expr :: Type), or nil otherwise.
(n: types.CstNode) -> types.CstExprTypeAssertion?utils.isExprUnary
Returns n narrowed to CstExprUnary if it is a unary expression, or nil otherwise.
(n: types.CstNode) -> types.CstExprUnary?utils.isExprVarargs
Returns n narrowed to CstExprVarargs if it is a varargs expression (...), or nil otherwise.
(n: types.CstNode) -> types.CstExprVarargs?utils.isGenericType
Returns n narrowed to CstGenericType if it is a generic type parameter, or nil otherwise.
(n: types.CstNode) -> types.CstGenericType?utils.isGenericTypePack
Returns n narrowed to CstGenericTypePack if it is a generic type pack parameter, or nil otherwise.
(n: types.CstNode) -> types.CstGenericTypePack?utils.isLocal
Returns n narrowed to CstLocal if it is a local variable node, or nil otherwise.
(n: types.CstNode) -> types.CstLocal?utils.isRequireCall
Returns n as an CstExprCall if it is a require(...) call expression, or nil otherwise.
(n: types.CstNode) -> types.CstExprCall?utils.isStat
Returns n narrowed to CstStat if it is any statement node, or nil otherwise.
(n: types.CstNode) -> types.CstStat?utils.isStatAssign
Returns n narrowed to CstStatAssign if it is an assignment statement, or nil otherwise.
(n: types.CstNode) -> types.CstStatAssign?utils.isStatBlock
Returns n narrowed to CstStatBlock if it is a block statement (do...end), or nil otherwise.
(n: types.CstNode) -> types.CstStatBlock?utils.isStatBreak
Returns n narrowed to CstStatBreak if it is a break statement, or nil otherwise.
(n: types.CstNode) -> types.CstStatBreak?utils.isStatCompoundAssign
Returns n narrowed to CstStatCompoundAssign if it is a compound assignment statement (e.g. +=), or nil otherwise.
(n: types.CstNode) -> types.CstStatCompoundAssign?utils.isStatConst
Returns n narrowed to CstStatConst if it is a const variable declaration, or nil otherwise.
(n: types.CstNode) -> types.CstStatConst?utils.isStatContinue
Returns n narrowed to CstStatContinue if it is a continue statement, or nil otherwise.
(n: types.CstNode) -> types.CstStatContinue?utils.isStatExpr
Returns n narrowed to CstStatExpr if it is an expression statement, or nil otherwise.
(n: types.CstNode) -> types.CstStatExpr?utils.isStatFor
Returns n narrowed to CstStatFor if it is a numeric for statement, or nil otherwise.
(n: types.CstNode) -> types.CstStatFor?utils.isStatForIn
Returns n narrowed to CstStatForIn if it is a generic for-in statement, or nil otherwise.
(n: types.CstNode) -> types.CstStatForIn?utils.isStatFunction
Returns n narrowed to CstStatFunction if it is a function declaration statement, or nil otherwise.
(n: types.CstNode) -> types.CstStatFunction?utils.isStatIf
Returns n narrowed to CstStatIf if it is an if statement, or nil otherwise.
(n: types.CstNode) -> types.CstStatIf?utils.isStatLocal
Returns n narrowed to CstStatLocal if it is a local variable declaration, or nil otherwise.
(n: types.CstNode) -> types.CstStatLocal?utils.isStatLocalFunction
Returns n narrowed to CstStatLocalFunction if it is a local function declaration, or nil otherwise.
(n: types.CstNode) -> types.CstStatLocalFunction?utils.isStatRepeat
Returns n narrowed to CstStatRepeat if it is a repeat-until statement, or nil otherwise.
(n: types.CstNode) -> types.CstStatRepeat?utils.isStatReturn
Returns n narrowed to CstStatReturn if it is a return statement, or nil otherwise.
(n: types.CstNode) -> types.CstStatReturn?utils.isStatTypeAlias
Returns n narrowed to CstStatTypeAlias if it is a type alias declaration, or nil otherwise.
(n: types.CstNode) -> types.CstStatTypeAlias?utils.isStatTypeFunction
Returns n narrowed to CstStatTypeFunction if it is a type function declaration, or nil otherwise.
(n: types.CstNode) -> types.CstStatTypeFunction?utils.isStatWhile
Returns n narrowed to CstStatWhile if it is a while statement, or nil otherwise.
(n: types.CstNode) -> types.CstStatWhile?utils.isTableExprItem
Returns n narrowed to CstTableExprItem if it is a table constructor item, or nil otherwise.
(n: types.CstNode | types.CstTableExprItem) -> types.CstTableExprItem?utils.isToken
Returns n narrowed to CstToken if it is a token, or nil otherwise.
(n: types.CstNode) -> types.CstToken?utils.isType
Returns n narrowed to CstType if it is any type annotation node, or nil otherwise.
(n: types.CstNode) -> types.CstType?utils.isTypeArray
Returns n narrowed to CstTypeArray if it is an array type ({T}), or nil otherwise.
(n: types.CstNode) -> types.CstTypeArray?utils.isTypeFunction
Returns n narrowed to CstTypeFunction if it is a function type, or nil otherwise.
(n: types.CstNode) -> types.CstTypeFunction?utils.isTypeGroup
Returns n narrowed to CstTypeGroup if it is a parenthesized type, or nil otherwise.
(n: types.CstNode) -> types.CstTypeGroup?utils.isTypeIntersection
Returns n narrowed to CstTypeIntersection if it is a type intersection, or nil otherwise.
(n: types.CstNode) -> types.CstTypeIntersection?utils.isTypeOptional
Returns n narrowed to CstTypeOptional if it is an optional type (T?), or nil otherwise.
(n: types.CstNode) -> types.CstTypeOptional?utils.isTypePack
Returns n narrowed to CstTypePack if it is any type pack node, or nil otherwise.
(n: types.CstNode) -> types.CstTypePack?utils.isTypePackExplicit
Returns n narrowed to CstTypePackExplicit if it is an explicit type pack, or nil otherwise.
(n: types.CstNode) -> types.CstTypePackExplicit?utils.isTypePackGeneric
Returns n narrowed to CstTypePackGeneric if it is a generic type pack, or nil otherwise.
(n: types.CstNode) -> types.CstTypePackGeneric?utils.isTypePackVariadic
Returns n narrowed to CstTypePackVariadic if it is a variadic type pack, or nil otherwise.
(n: types.CstNode) -> types.CstTypePackVariadic?utils.isTypeReference
Returns n narrowed to CstTypeReference if it is a type reference, or nil otherwise.
(n: types.CstNode) -> types.CstTypeReference?utils.isTypeSingletonBool
Returns n narrowed to CstTypeSingletonBool if it is a boolean singleton type, or nil otherwise.
(n: types.CstNode) -> types.CstTypeSingletonBool?utils.isTypeSingletonString
Returns n narrowed to CstTypeSingletonString if it is a string singleton type, or nil otherwise.
(n: types.CstNode) -> types.CstTypeSingletonString?utils.isTypeTable
Returns n narrowed to CstTypeTable if it is a table type, or nil otherwise.
(n: types.CstNode) -> types.CstTypeTable?utils.isTypeTypeof
Returns n narrowed to CstTypeTypeof if it is a typeof(...) type, or nil otherwise.
(n: types.CstNode) -> types.CstTypeTypeof?utils.isTypeUnion
Returns n narrowed to CstTypeUnion if it is a type union, or nil otherwise.
(n: types.CstNode) -> types.CstTypeUnion?utils.replacementWithTrivia
Returns a Replacement that replaces the original node with the given content, preserving trivia.
(content: string) -> types.Replacementutils.replacementWithoutTrivia
Returns a Replacement that replaces the original node with the given content, discarding trivia.
(content: string) -> types.Replacement