MCPcopy Create free account
hub / github.com/dop251/goja / ParseFunction

Function ParseFunction

parser/parser.go:188–199  ·  view source on GitHub ↗

ParseFunction parses a given parameter list and body as a function and returns the corresponding ast.FunctionLiteral node. The parameter list, if any, should be a comma-separated list of identifiers.

(parameterList, body string, options ...Option)

Source from the content-addressed store, hash-verified

186//
187// The parameter list, if any, should be a comma-separated list of identifiers.
188func ParseFunction(parameterList, body string, options ...Option) (*ast.FunctionLiteral, error) {
189
190 src := "(function(" + parameterList + ") {\n" + body + "\n})"
191
192 parser := _newParser("", src, 1, options...)
193 program, err := parser.parse()
194 if err != nil {
195 return nil, err
196 }
197
198 return program.Body[0].(*ast.ExpressionStatement).Expression.(*ast.FunctionLiteral), nil
199}
200
201func (self *_parser) slice(idx0, idx1 file.Idx) string {
202 from := int(idx0) - self.base

Callers 1

TestParseFunctionFunction · 0.85

Calls 2

_newParserFunction · 0.85
parseMethod · 0.45

Tested by 1

TestParseFunctionFunction · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…