Documentation ¶
Index ¶
- Constants
- func IsIdentifier(s string) bool
- func ParseFile(fileSet *file.FileSet, filename string, src any, mode Mode, options ...Option) (*ast.Program, error)
- func ParseFunction(parameterList, body string, options ...Option) (*ast.FunctionLiteral, error)
- func ReadSource(filename string, src any) ([]byte, error)
- func TransformRegExp(pattern string) (transformed string, err error)
- func WithDisableSourceMaps(opts *options)
- type Error
- type ErrorList
- type Mode
- type Option
- type RegexpErrorIncompatible
- type RegexpSyntaxError
Constants ¶
View Source
const ( WhitespaceChars = " \f\n\r\t\v\u00a0\u1680\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u2028\u2029\u202f\u205f\u3000\ufeff" Re2Dot = "[^\r\n\u2028\u2029]" )
Variables ¶
This section is empty.
Functions ¶
func IsIdentifier ¶
func ParseFile ¶
func ParseFile(fileSet *file.FileSet, filename string, src any, mode Mode, options ...Option) (*ast.Program, error)
ParseFile 解析单个 JavaScript 源文件的代码并返回相应的 ast.Program 节点 若文件集合为空,则解析时不包含文件集合(没有上下文),若文件集合非空,则先将要解析的文件加入其中 文件名参数可选,用于在出现错误时,标记错误发生的文件名 src 可以是 string/[]byte/bytes.Buffer/io.Reader, 但是不论如何,它的内容编码必须是UTF8 解析 JavaScript 将最终产生一个 *ast.Program 和一个 ErrorList
func ParseFunction ¶
func ParseFunction(parameterList, body string, options ...Option) (*ast.FunctionLiteral, error)
ParseFunction 将一个给定的参数列表和主体解析为一个函数,并返回相应的 ast.FunctionLiteral 节点 若有参数,则参数列表必须是一个用逗号分隔的标识符列表
func TransformRegExp ¶
TransformRegExp 将一个 JavaScript 的正则表达式转换为 Go 的正则 re2 (Go) 不能进行回溯,因此遇到回看,如 (?=) (?!) 或 (\1, \2, ...) 将报错 re2 (Go) 对 \s 有不同的定义: [\t\n\f\r ] 另外,JavaScript 还包含了额外的 \v, Unicode 的分割符和空格等
func WithDisableSourceMaps ¶
func WithDisableSourceMaps(opts *options)
WithDisableSourceMaps 禁用源码 map 的选项,在不使用源码 map 时,将会节省解析 map 的时间
Types ¶
type Option ¶
type Option func(*options)
Option 表示在 parser 内使用的选项之一,目前支持的是 WithDisableSourceMaps 和 WithSourceMapLoader
type RegexpErrorIncompatible ¶
type RegexpErrorIncompatible struct {
// contains filtered or unexported fields
}
type RegexpSyntaxError ¶
type RegexpSyntaxError struct {
// contains filtered or unexported fields
}
Click to show internal directories.
Click to hide internal directories.