| 1406 | } |
| 1407 | |
| 1408 | private load(id: string, specifier: string): SourceModule | ImportTarget { |
| 1409 | const source = this.host.readFile(id) |
| 1410 | if (source === undefined) { |
| 1411 | return { |
| 1412 | kind: "unresolved", |
| 1413 | message: `${this.pathOf(id)} cannot be read` |
| 1414 | } |
| 1415 | } |
| 1416 | if (id.endsWith(".json")) { |
| 1417 | try { |
| 1418 | return { |
| 1419 | kind: "json", |
| 1420 | id, |
| 1421 | value: parseJsonText(source, this.pathOf(id)) |
| 1422 | } |
| 1423 | } catch { |
| 1424 | return { |
| 1425 | kind: "unresolved", |
| 1426 | message: `${this.pathOf(id)} is not valid JSON` |
| 1427 | } |
| 1428 | } |
| 1429 | } |
| 1430 | if (!/\.[cm]?[jt]sx?$/.test(id)) { |
| 1431 | return { |
| 1432 | kind: "unresolved", |
| 1433 | message: `\`${specifier}\` is not a JavaScript or TypeScript module` |
| 1434 | } |
| 1435 | } |
| 1436 | return new SourceModule(id, source, this.pathOf(id)) |
| 1437 | } |
| 1438 | |
| 1439 | dependenciesOf(id: string): string[] { |
| 1440 | // a Set iterates in insertion order, entries added as it goes included, |