| 6153 | // a module of a package, which the build reads only for what its |
| 6154 | // functions may write |
| 6155 | private packageModuleOf( |
| 6156 | specifier: string, |
| 6157 | importer: SourceModule |
| 6158 | ): SourceModule | undefined { |
| 6159 | const id = this.host.resolve(specifier, importer.id) |
| 6160 | if (!id || !/\.[cm]?[jt]sx?$/.test(id)) return |
| 6161 | const loaded = this.modulesById[id] |
| 6162 | if (loaded) return loaded instanceof SourceModule ? loaded : undefined |
| 6163 | let result = this.packageModulesById.get(id) |
| 6164 | if (result === undefined) { |
| 6165 | const source = this.host.readFile(id) |
| 6166 | result = |
| 6167 | source === undefined ? null : ( |
| 6168 | new SourceModule(id, source, this.pathOf(id)) |
| 6169 | ) |
| 6170 | if (result?.parseErrors.length) result = null |
| 6171 | this.packageModulesById.set(id, result) |
| 6172 | } |
| 6173 | return result ?? undefined |
| 6174 | } |
| 6175 | |
| 6176 | private isPackageModule(module: SourceModule): boolean { |
| 6177 | return this.packageModulesById.get(module.id) === module |