jsparse

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Aug 22, 2026 License: Apache-2.0 Imports: 6 Imported by: 0

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

Constants

This section is empty.

Variables

This section is empty.

Functions

func Field

func Field(n any, field string) any

Field returns the value of the named node field, or nil.

func FieldBool

func FieldBool(n any, field string) bool

FieldBool returns the bool value of the named node field.

func FieldSlice

func FieldSlice(n any, field string) []any

FieldSlice returns the []any value of the named node field.

func IdentName

func IdentName(n any) string

IdentName returns the "name" field of an Identifier node.

func IsIdentifierPart

func IsIdentifierPart(cp int) bool

IsIdentifierPart reports whether a code point may appear after the first character of a JavaScript identifier.

func IsWhiteSpace

func IsWhiteSpace(cp int) bool

IsWhiteSpace reports whether a code point is whitespace to JavaScript, which counts more characters than Go does.

func NodeType

func NodeType(n any) string

NodeType returns the "type" field of an AST node.

func Parse

func Parse(code string) (ast jsonval.Object, err error)

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.

Jump to

Keyboard shortcuts

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