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)
| 163 | // // Parse some JavaScript, yielding a *ast.Program and/or an ErrorList |
| 164 | // program, err := parser.ParseFile(nil, "", `if (abc > 1) {}`, 0) |
| 165 | func 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. |
searching dependent graphs…