Documentation
¶
Overview ¶
Package jsparse parses JavaScript into an ESTree-shaped syntax tree.
It is a port of esprima, the parser CyberChef uses, so the tree it returns matches esprima's node for node — the JavaScript Parser operation prints it directly, and JavaScript Beautify walks it. The tree is built out of github.com/roberson-io/cchef/internal/jsonval.Object values rather than Go structs, because a node's shape varies by type and the output has to serialise in esprima's key order.
Parse returns the tree alone; ParseFull also returns the comments and tokens a beautifier needs to put things back where they were. The Field accessors read a node's properties, which are typed as any.
Index ¶
- func Field(n any, field string) any
- func FieldBool(n any, field string) bool
- func FieldSlice(n any, field string) []any
- func IdentName(n any) string
- func IsIdentifierPart(cp int) bool
- func IsWhiteSpace(cp int) bool
- func NodeType(n any) string
- func Parse(code string) (ast jsonval.Object, err error)
- func ParseFull(code string) (ast jsonval.Object, comments []jsonval.Object, tokens []jsonval.Object, ...)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func FieldSlice ¶
FieldSlice returns the []any value of the named node field.
func IsIdentifierPart ¶
IsIdentifierPart reports whether a code point may appear after the first character of a JavaScript identifier.
func IsWhiteSpace ¶
IsWhiteSpace reports whether a code point is whitespace to JavaScript, which counts more characters than Go does.
func Parse ¶
Parse parses the source and returns the ESTree AST as a jsonval.Object, or a *jsSyntaxError (recovered from the panic-based control flow).
func ParseFull ¶
func ParseFull(code string) (ast jsonval.Object, comments []jsonval.Object, tokens []jsonval.Object, err error)
ParseFull parses the source with esprima's range/tokens/comment options enabled: every AST node carries a range, and flat comments/tokens arrays are returned in source order. On a syntax error it returns the error like Parse.
Types ¶
This section is empty.