Skip to content

Commit

Permalink
fix: set types specifier for jsxImportSourceTypes (#462)
Browse files Browse the repository at this point in the history
  • Loading branch information
dsherret authored Apr 30, 2024
1 parent 16937a4 commit 5e2f69e
Showing 1 changed file with 52 additions and 0 deletions.
52 changes: 52 additions & 0 deletions src/graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2388,6 +2388,7 @@ pub(crate) fn parse_js_module_from_module_info(
maybe_resolver,
maybe_npm_resolver,
);
dep.maybe_deno_types_specifier = Some(specifier_text);
}
}
dep.imports.push(Import {
Expand Down Expand Up @@ -5677,6 +5678,57 @@ mod tests {
);
}

#[tokio::test]
async fn dependency_jsx_import_source_types() {
let mut mem_loader = MemoryLoader::default();
mem_loader.add_source_with_text(
"file:///foo.tsx",
"
/* @jsxImportSource http://localhost */
/* @jsxImportSourceTypes http://localhost/types */
",
);
mem_loader.add_source(
"http://localhost/jsx-runtime",
Source::Module {
specifier: "http://localhost/jsx-runtime",
maybe_headers: Some(vec![("content-type", "application/javascript")]),
content: "",
},
);
mem_loader.add_source(
"http://localhost/types/jsx-runtime",
Source::Module {
specifier: "http://localhost/types/jsx-runtime",
maybe_headers: Some(vec![("content-type", "application/typescript")]),
content: "",
},
);
let mut graph = ModuleGraph::new(GraphKind::All);
graph
.build(
vec![Url::parse("file:///foo.tsx").unwrap()],
&mem_loader,
Default::default(),
)
.await;
graph.valid().unwrap();
let module = graph.get(&Url::parse("file:///foo.tsx").unwrap()).unwrap();
let module = module.js().unwrap();
let dependency_a = module
.dependencies
.get("http://localhost/jsx-runtime")
.unwrap();
assert_eq!(
dependency_a.maybe_type.maybe_specifier().unwrap().as_str(),
"http://localhost/types/jsx-runtime"
);
assert_eq!(
dependency_a.maybe_deno_types_specifier.as_ref().unwrap(),
"http://localhost/types/jsx-runtime"
);
}

#[cfg(feature = "fast_check")]
#[tokio::test]
async fn fast_check_dts() {
Expand Down

0 comments on commit 5e2f69e

Please sign in to comment.