Documentation
¶
Overview ¶
Package parser parses ECMAScript source text into the syntax tree of package ast.
Index ¶
- func IsIdentifierName(s string) bool
- func ParseFunction(params, body wtf8.String, kind FunctionKind, opts Options) (*ast.Program, error)
- func ParseModule(src wtf8.String, opts Options) (*ast.Program, error)
- func ParseScript(src wtf8.String, opts Options) (*ast.Program, error)
- type Error
- type FunctionKind
- type Options
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func IsIdentifierName ¶
IsIdentifierName reports whether s is an IdentifierName without escapes.
func ParseFunction ¶
ParseFunction parses a function given as separate parameter text and body text, as the Function constructor and its generator and async variants require.
The source of the returned program is the synthesized function text. Its body is one expression statement holding the function. The returned error is an *Error.
func ParseModule ¶
ParseModule parses src as a Module. The returned error is an *Error.
Types ¶
type Error ¶
type Error struct {
// Offset is the byte offset of the error in the source text.
Offset int
// Line is the 1-based line of the error.
Line int
// Column is the 1-based column of the error, counted in code points.
Column int
Message string
}
Error is a syntax error.
type FunctionKind ¶
type FunctionKind uint8
FunctionKind is the kind of function that ParseFunction creates.
const ( NormalFunction FunctionKind = iota GeneratorFunction AsyncFunction AsyncGeneratorFunction )
type Options ¶
type Options struct {
// Strict makes the code strict mode code from its start.
Strict bool
// AllowSuperProperty permits super property accesses at the top level, as in a direct eval inside a method.
AllowSuperProperty bool
// AllowSuperCall permits super calls at the top level, as in a direct eval inside a derived constructor.
AllowSuperCall bool
// AllowNewTarget permits new.target at the top level, as in a direct eval inside a function.
AllowNewTarget bool
// InClassFieldInit makes references to arguments an error, as in a direct eval inside a class field initializer.
InClassFieldInit bool
// PrivateNames lists the private names, without '#', declared by the classes enclosing a direct eval.
PrivateNames []string
// Poll, when not nil, is called now and then during a long parse, and may stop it by
// panicking.
Poll func()
}
Options describes the context that source text is parsed in.