summaryrefslogtreecommitdiff
path: root/cli/tsc/99_main_compiler.js
diff options
context:
space:
mode:
authorDavid Sherret <dsherret@users.noreply.github.com>2024-04-15 17:50:52 -0400
committerGitHub <noreply@github.com>2024-04-15 17:50:52 -0400
commit6f278e5c40d101f0fb8e7b69e28d34b1c766a8fe (patch)
tree97d3edc0f0b527c3dc7f07ba71d5828cd2c77943 /cli/tsc/99_main_compiler.js
parent7e4ee02e2e37db8adfaf4a05aba3819838904650 (diff)
fix(lsp): improved cjs tracking (#23374)
Our cjs tracking was a bit broken. It was marking stuff as esm that was actually cjs leading to type checking errors.
Diffstat (limited to 'cli/tsc/99_main_compiler.js')
-rw-r--r--cli/tsc/99_main_compiler.js24
1 files changed, 18 insertions, 6 deletions
diff --git a/cli/tsc/99_main_compiler.js b/cli/tsc/99_main_compiler.js
index be9962814..b76c95aa5 100644
--- a/cli/tsc/99_main_compiler.js
+++ b/cli/tsc/99_main_compiler.js
@@ -135,12 +135,16 @@ delete Object.prototype.__proto__;
#cache = new Set();
/** @param {[string, ts.Extension]} param */
- add([specifier, ext]) {
+ maybeAdd([specifier, ext]) {
if (ext === ".cjs" || ext === ".d.cts" || ext === ".cts") {
this.#cache.add(specifier);
}
}
+ add(specifier) {
+ this.#cache.add(specifier);
+ }
+
/** @param specifier {string} */
has(specifier) {
return this.#cache.has(specifier);
@@ -603,22 +607,30 @@ delete Object.prototype.__proto__;
return sourceFile;
}
- /** @type {{ data: string; scriptKind: ts.ScriptKind; version: string; }} */
+ /** @type {{ data: string; scriptKind: ts.ScriptKind; version: string; isCjs: boolean }} */
const fileInfo = ops.op_load(specifier);
if (!fileInfo) {
return undefined;
}
- const { data, scriptKind, version } = fileInfo;
+ let { data, scriptKind, version, isCjs } = fileInfo;
assert(
data != null,
`"data" is unexpectedly null for "${specifier}".`,
);
+
+ // use the cache for non-lsp
+ if (isCjs == null) {
+ isCjs = isCjsCache.has(specifier);
+ } else if (isCjs) {
+ isCjsCache.add(specifier);
+ }
+
sourceFile = ts.createSourceFile(
specifier,
data,
{
...getCreateSourceFileOptions(languageVersion),
- impliedNodeFormat: isCjsCache.has(specifier)
+ impliedNodeFormat: isCjs
? ts.ModuleKind.CommonJS
: ts.ModuleKind.ESNext,
// no need to parse docs for `deno check`
@@ -688,7 +700,7 @@ delete Object.prototype.__proto__;
base: containingFilePath,
})?.[0];
if (resolved) {
- isCjsCache.add(resolved);
+ isCjsCache.maybeAdd(resolved);
return {
primary: true,
resolvedFileName: resolved[0],
@@ -723,7 +735,7 @@ delete Object.prototype.__proto__;
if (resolved) {
const result = resolved.map((item) => {
if (item) {
- isCjsCache.add(item);
+ isCjsCache.maybeAdd(item);
const [resolvedFileName, extension] = item;
return {
resolvedFileName,