javascript

package
v1.3.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 12, 2024 License: AGPL-3.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetStatementType added in v1.2.4

func GetStatementType(st interface{}) string

func NewJavaScriptWalker

func NewJavaScriptWalker(handlers ...func(ast.Node)) *walker

func Walk added in v1.3.2

func Walk(v Visitor, n ast.Node)

Walk traverses an AST in depth-first order: It starts by calling v.Enter(node); node must not be nil. If the visitor v returned by v.Enter(node) is not nil, Walk is invoked recursively with visitor v for each of the non-nil children of node, followed by a call of v.Exit(node).

Types

type ASTWalkerResult

type ASTWalkerResult struct {
	StringLiteral  []string
	Int64Literal   []int64
	Float64Literal []float64
	Identifies     []string
	BadSyntax      []string
}

func BasicJavaScriptASTWalker

func BasicJavaScriptASTWalker(code string) (*ASTWalkerResult, error)

ASTWalk 对传入的JS代码进行AST遍历,返回遍历后的结果(包含字面量,标识符,语法错误)和错误 Example: ``` code = `function add(a, b) { return a + b; }` res = javascript.ASTWalk(code)~ dump(res) ```

type Visitor added in v1.3.2

type Visitor interface {
	Enter(n ast.Node) (v Visitor)
	Exit(n ast.Node)
}

Visitor Enter method is invoked for each node encountered by Walk. If the result visitor w is not nil, Walk visits each of the children of node with the visitor v, followed by a call of the Exit method.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL