| 32 | } |
| 33 | |
| 34 | func (h *watchCompilerHost) GetSourceFile(opts ast.SourceFileParseOptions) *ast.SourceFile { |
| 35 | info := h.CompilerHost.FS().Stat(opts.FileName) |
| 36 | |
| 37 | if cached, ok := h.cache.Load(opts.Path); ok { |
| 38 | if info != nil && info.ModTime().Equal(cached.modTime) { |
| 39 | return cached.file |
| 40 | } |
| 41 | } |
| 42 | |
| 43 | file := h.CompilerHost.GetSourceFile(opts) |
| 44 | if file != nil { |
| 45 | if info != nil { |
| 46 | h.cache.Store(opts.Path, &cachedSourceFile{ |
| 47 | file: file, |
| 48 | modTime: info.ModTime(), |
| 49 | }) |
| 50 | } |
| 51 | } else { |
| 52 | h.cache.Delete(opts.Path) |
| 53 | } |
| 54 | return file |
| 55 | } |
| 56 | |
| 57 | type Watcher struct { |
| 58 | sys tsc.System |