summaryrefslogtreecommitdiff
path: root/cli/lsp/tsc.rs
diff options
context:
space:
mode:
authorDavid Sherret <dsherret@users.noreply.github.com>2024-11-01 12:27:00 -0400
committerGitHub <noreply@github.com>2024-11-01 12:27:00 -0400
commit826e42a5b5880c974ae019a7a21aade6a718062c (patch)
treea46502ecc3c73e4f7fc3a4517d83c7b2f3d0c0d3 /cli/lsp/tsc.rs
parent4774eab64d5176e997b6431f03f075782321b3d9 (diff)
fix: improved support for cjs and cts modules (#26558)
* cts support * better cjs/cts type checking * deno compile cjs/cts support * More efficient detect cjs (going towards stabilization) * Determination of whether .js, .ts, .jsx, or .tsx is cjs or esm is only done after loading * Support `import x = require(...);` Co-authored-by: Bartek IwaƄczuk <biwanczuk@gmail.com>
Diffstat (limited to 'cli/lsp/tsc.rs')
-rw-r--r--cli/lsp/tsc.rs27
1 files changed, 19 insertions, 8 deletions
diff --git a/cli/lsp/tsc.rs b/cli/lsp/tsc.rs
index 0f31d7dd3..5fcdb3575 100644
--- a/cli/lsp/tsc.rs
+++ b/cli/lsp/tsc.rs
@@ -4362,14 +4362,25 @@ fn op_load<'s>(
None
} else {
let asset_or_document = state.get_asset_or_document(&specifier);
- asset_or_document.map(|doc| LoadResponse {
- data: doc.text(),
- script_kind: crate::tsc::as_ts_script_kind(doc.media_type()),
- version: state.script_version(&specifier),
- is_cjs: matches!(
- doc.media_type(),
- MediaType::Cjs | MediaType::Cts | MediaType::Dcts
- ),
+ asset_or_document.map(|doc| {
+ let maybe_cjs_tracker = state
+ .state_snapshot
+ .resolver
+ .maybe_cjs_tracker(Some(&specifier));
+ LoadResponse {
+ data: doc.text(),
+ script_kind: crate::tsc::as_ts_script_kind(doc.media_type()),
+ version: state.script_version(&specifier),
+ is_cjs: maybe_cjs_tracker
+ .map(|t| {
+ t.is_cjs(
+ &specifier,
+ doc.media_type(),
+ doc.maybe_parsed_source().and_then(|p| p.as_ref().ok()),
+ )
+ })
+ .unwrap_or(false),
+ }
})
};