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

Function ParseFile

parser/parser.go:165–182  ·  view source on GitHub ↗

ParseFile parses the source code of a single JavaScript/ECMAScript source file and returns the corresponding ast.Program node. If fileSet == nil, ParseFile parses source without a FileSet. If fileSet != nil, ParseFile first adds filename and src to fileSet. The filename argument is optional and is

(fileSet *file.FileSet, filename string, src interface{}, mode Mode, options ...Option)

Source from the content-addressed store, hash-verified

163// // Parse some JavaScript, yielding a *ast.Program and/or an ErrorList
164// program, err := parser.ParseFile(nil, "", `if (abc > 1) {}`, 0)
165func ParseFile(fileSet *file.FileSet, filename string, src interface{}, mode Mode, options ...Option) (*ast.Program, error) {
166 str, err := ReadSource(filename, src)
167 if err != nil {
168 return nil, err
169 }
170 {
171 str := string(str)
172
173 base := 1
174 if fileSet != nil {
175 base = fileSet.AddFile(filename, str)
176 }
177
178 parser := _newParser(filename, str, base, options...)
179 parser.mode = mode
180 return parser.parse()
181 }
182}
183
184// ParseFunction parses a given parameter list and body as a function and returns the
185// corresponding ast.FunctionLiteral node.

Callers 4

BenchmarkFibFunction · 0.92
ParseFunction · 0.92
TestParseFileFunction · 0.85
TestSourceMapOptionsFunction · 0.85

Calls 4

ReadSourceFunction · 0.85
_newParserFunction · 0.85
AddFileMethod · 0.80
parseMethod · 0.45

Tested by 3

BenchmarkFibFunction · 0.74
TestParseFileFunction · 0.68
TestSourceMapOptionsFunction · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…