(filePath string, node *ast.Node, dependencies map[string]struct{}, stackTrace *[]TraceFrame, canonicalPaths bool)
| 285 | } |
| 286 | |
| 287 | func (vm *VM) findDependencies(filePath string, node *ast.Node, dependencies map[string]struct{}, stackTrace *[]TraceFrame, canonicalPaths bool) (err error) { |
| 288 | var cleanedAbsPath string |
| 289 | switch i := (*node).(type) { |
| 290 | case *ast.Import: |
| 291 | node, foundAt, err := vm.ImportAST(filePath, i.File.Value) |
| 292 | if err != nil { |
| 293 | *stackTrace = append([]TraceFrame{{Loc: *i.Loc()}}, *stackTrace...) |
| 294 | return err |
| 295 | } |
| 296 | cleanedAbsPath = foundAt |
| 297 | if _, isFileImporter := vm.importer.(*FileImporter); isFileImporter { |
| 298 | cleanedAbsPath, err = getAbsPath(foundAt, canonicalPaths) |
| 299 | if err != nil { |
| 300 | *stackTrace = append([]TraceFrame{{Loc: *i.Loc()}}, *stackTrace...) |
| 301 | return err |
| 302 | } |
| 303 | } |
| 304 | // Check that we haven't already parsed the imported file. |
| 305 | if _, alreadyParsed := dependencies[cleanedAbsPath]; alreadyParsed { |
| 306 | return nil |
| 307 | } |
| 308 | dependencies[cleanedAbsPath] = struct{}{} |
| 309 | err = vm.findDependencies(foundAt, &node, dependencies, stackTrace, canonicalPaths) |
| 310 | if err != nil { |
| 311 | *stackTrace = append([]TraceFrame{{Loc: *i.Loc()}}, *stackTrace...) |
| 312 | return err |
| 313 | } |
| 314 | case *ast.ImportStr: |
| 315 | foundAt, err := vm.ResolveImport(filePath, i.File.Value) |
| 316 | if err != nil { |
| 317 | *stackTrace = append([]TraceFrame{{Loc: *i.Loc()}}, *stackTrace...) |
| 318 | return err |
| 319 | } |
| 320 | cleanedAbsPath = foundAt |
| 321 | if _, isFileImporter := vm.importer.(*FileImporter); isFileImporter { |
| 322 | cleanedAbsPath, err = getAbsPath(foundAt, canonicalPaths) |
| 323 | if err != nil { |
| 324 | *stackTrace = append([]TraceFrame{{Loc: *i.Loc()}}, *stackTrace...) |
| 325 | return err |
| 326 | } |
| 327 | } |
| 328 | dependencies[cleanedAbsPath] = struct{}{} |
| 329 | case *ast.ImportBin: |
| 330 | foundAt, err := vm.ResolveImport(filePath, i.File.Value) |
| 331 | if err != nil { |
| 332 | *stackTrace = append([]TraceFrame{{Loc: *i.Loc()}}, *stackTrace...) |
| 333 | return err |
| 334 | } |
| 335 | cleanedAbsPath = foundAt |
| 336 | if _, isFileImporter := vm.importer.(*FileImporter); isFileImporter { |
| 337 | cleanedAbsPath, err = getAbsPath(foundAt, canonicalPaths) |
| 338 | if err != nil { |
| 339 | *stackTrace = append([]TraceFrame{{Loc: *i.Loc()}}, *stackTrace...) |
| 340 | return err |
| 341 | } |
| 342 | } |
| 343 | dependencies[cleanedAbsPath] = struct{}{} |
| 344 | default: |
no test coverage detected