From 98404ec7bfb5f6f4569cdfe7ba81a6435521ad99 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Fri, 12 Mar 2021 23:47:28 +0000 Subject: [PATCH] Try a naive file load during parse, to see if that helps with pre-caching. --- src/compiler/parser.ts | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index 3c1c118b5b3..57cb951247b 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -1,4 +1,12 @@ namespace ts { + let fs: typeof import("fs") | undefined; + let path: typeof import("path") | undefined; + try { + fs = require("fs"); + path = require("path"); + } + catch {} + const enum SignatureFlags { None = 0, Yield = 1 << 0, @@ -7010,7 +7018,19 @@ namespace ts { function parseModuleSpecifier(): Expression { if (token() === SyntaxKind.StringLiteral) { const result = parseLiteralNode(); - result.text = internIdentifier(result.text); + const text = result.text; + if (fs && path && result.text.charCodeAt(0) === CharacterCodes.dot) { + const initPath = path.resolve(fileName, result.text); + const ext = path.extname(initPath); + fs.readFile(text, noop); + if (!ext) { + fs.readFile(text + ".ts", noop); + fs.readFile(text + ".tsx", noop); + fs.readFile(text + ".d.ts", noop); + fs.readFile(text + ".js", noop); + } + } + result.text = internIdentifier(text); return result; } else {