Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ASTBuilder ¶
type ASTBuilder struct {
// contains filtered or unexported fields
}
ASTBuilder builds our internal AST from tree-sitter CST
func NewASTBuilder ¶
func NewASTBuilder(filename string, source []byte) *ASTBuilder
NewASTBuilder creates a new AST builder
type Node ¶
type Node struct {
Type NodeType
Value interface{} // Can hold various values depending on node type
Children []*Node
Location Location
Parent *Node
// Common fields for various node types
Name string // For function/class/variable names
// Function-related fields
Params []*Node // Function parameters
Body []*Node // Function/block body
Async bool // Async function
Generator bool // Generator function
// Control flow fields
Test *Node // Condition for if/while/for
Consequent *Node // Then branch for if
Alternate *Node // Else branch for if
Init *Node // For loop initializer
Update *Node // For loop update
Cases []*Node // Switch cases
// Try-catch fields
Handler *Node // Catch clause
Finalizer *Node // Finally block
Handlers []*Node // Multiple catch handlers
// Expression fields
Left *Node // Left operand
Right *Node // Right operand
Operator string // Operator (+, -, *, etc.)
Argument *Node // Unary expression argument
Arguments []*Node // Function call arguments
Callee *Node // Function being called
Object *Node // Object in member expression
Property *Node // Property in member expression
// Variable declaration fields
Kind string // var, let, const
Declarations []*Node // Variable declarators
// Import/Export fields
Source *Node // Import source
Specifiers []*Node // Import/export specifiers
Declaration *Node // Export declaration
Imported *Node // Imported name
Local *Node // Local binding
// TypeScript fields
TypeAnnotation *Node // Type annotation
TypeParameters []*Node // Generic type parameters
// Utility fields
Computed bool // Computed property
Optional bool // Optional chaining
Raw string // Raw literal value
}
Node represents an AST node
func ParseForLanguage ¶
ParseForLanguage automatically selects JavaScript or TypeScript parser based on file extension
func (*Node) IsExpression ¶
IsExpression returns true if the node is an expression
func (*Node) IsFunction ¶
IsFunction returns true if the node is a function
func (*Node) IsStatement ¶
IsStatement returns true if the node is a statement
type NodeType ¶
type NodeType string
NodeType represents the type of AST node
const ( // Program and structure NodeProgram NodeType = "Program" NodeScript NodeType = "Script" // Function declarations NodeFunction NodeType = "FunctionDeclaration" NodeFunctionExpression NodeType = "FunctionExpression" NodeArrowFunction NodeType = "ArrowFunctionExpression" NodeAsyncFunction NodeType = "AsyncFunctionDeclaration" NodeGeneratorFunction NodeType = "GeneratorFunctionDeclaration" NodeMethodDefinition NodeType = "MethodDefinition" // Class declarations NodeClass NodeType = "ClassDeclaration" NodeClassExpression NodeType = "ClassExpression" // Variable declarations NodeVariableDeclaration NodeType = "VariableDeclaration" NodeVariableDeclarator NodeType = "VariableDeclarator" NodeIdentifier NodeType = "Identifier" // Control flow statements NodeIfStatement NodeType = "IfStatement" NodeSwitchStatement NodeType = "SwitchStatement" NodeCaseClause NodeType = "SwitchCase" NodeDefaultClause NodeType = "SwitchDefault" NodeForStatement NodeType = "ForStatement" NodeForInStatement NodeType = "ForInStatement" NodeForOfStatement NodeType = "ForOfStatement" NodeWhileStatement NodeType = "WhileStatement" NodeDoWhileStatement NodeType = "DoWhileStatement" NodeBreakStatement NodeType = "BreakStatement" NodeContinueStatement NodeType = "ContinueStatement" NodeReturnStatement NodeType = "ReturnStatement" NodeThrowStatement NodeType = "ThrowStatement" // Exception handling NodeTryStatement NodeType = "TryStatement" NodeCatchClause NodeType = "CatchClause" NodeFinallyClause NodeType = "FinallyClause" // Expressions NodeCallExpression NodeType = "CallExpression" NodeMemberExpression NodeType = "MemberExpression" NodeBinaryExpression NodeType = "BinaryExpression" NodeUnaryExpression NodeType = "UnaryExpression" NodeLogicalExpression NodeType = "LogicalExpression" NodeConditionalExpression NodeType = "ConditionalExpression" NodeAssignmentExpression NodeType = "AssignmentExpression" NodeUpdateExpression NodeType = "UpdateExpression" NodeNewExpression NodeType = "NewExpression" NodeThisExpression NodeType = "ThisExpression" NodeSequenceExpression NodeType = "SequenceExpression" NodeAwaitExpression NodeType = "AwaitExpression" NodeYieldExpression NodeType = "YieldExpression" NodeSpreadElement NodeType = "SpreadElement" NodeTemplateLiteral NodeType = "TemplateLiteral" // Literals NodeLiteral NodeType = "Literal" NodeStringLiteral NodeType = "StringLiteral" NodeNumberLiteral NodeType = "NumberLiteral" NodeBooleanLiteral NodeType = "BooleanLiteral" NodeNullLiteral NodeType = "NullLiteral" NodeRegExpLiteral NodeType = "RegExpLiteral" NodeArrayExpression NodeType = "ArrayExpression" NodeObjectExpression NodeType = "ObjectExpression" NodeProperty NodeType = "Property" // Module system (ESM) NodeImportDeclaration NodeType = "ImportDeclaration" NodeImportSpecifier NodeType = "ImportSpecifier" NodeImportDefaultSpecifier NodeType = "ImportDefaultSpecifier" NodeImportNamespaceSpecifier NodeType = "ImportNamespaceSpecifier" NodeExportNamedDeclaration NodeType = "ExportNamedDeclaration" NodeExportDefaultDeclaration NodeType = "ExportDefaultDeclaration" NodeExportAllDeclaration NodeType = "ExportAllDeclaration" NodeExportSpecifier NodeType = "ExportSpecifier" // Module system (CommonJS) NodeRequireCall NodeType = "RequireCall" NodeModuleExports NodeType = "ModuleExports" // Other statements NodeExpressionStatement NodeType = "ExpressionStatement" NodeBlockStatement NodeType = "BlockStatement" NodeEmptyStatement NodeType = "EmptyStatement" NodeLabeledStatement NodeType = "LabeledStatement" NodeWithStatement NodeType = "WithStatement" NodeDebuggerStatement NodeType = "DebuggerStatement" // TypeScript-specific nodes NodeInterfaceDeclaration NodeType = "InterfaceDeclaration" NodeTypeAlias NodeType = "TypeAliasDeclaration" NodeEnumDeclaration NodeType = "EnumDeclaration" NodeTypeAnnotation NodeType = "TypeAnnotation" NodeTypeParameter NodeType = "TypeParameter" NodeImportType NodeType = "ImportType" NodeAsExpression NodeType = "AsExpression" NodeNonNullExpression NodeType = "NonNullExpression" // JSX (if needed) NodeJSXElement NodeType = "JSXElement" NodeJSXFragment NodeType = "JSXFragment" NodeJSXAttribute NodeType = "JSXAttribute" // Tree-sitter specific structural nodes NodeStatementBlock NodeType = "StatementBlock" NodeElseClause NodeType = "ElseClause" )
JavaScript/TypeScript AST node types
type Parser ¶
type Parser struct {
// contains filtered or unexported fields
}
Parser wraps tree-sitter parser for JavaScript/TypeScript
func NewTypeScriptParser ¶
func NewTypeScriptParser() *Parser
NewTypeScriptParser creates a new TypeScript parser
func (*Parser) IsTypeScript ¶
IsTypeScript returns true if this parser is configured for TypeScript