mirror of
https://github.com/denoland/deno.git
synced 2025-09-27 04:39:10 +00:00
Provide compiled JSON to TypeScript compiler. (#4404)
Fixes #4101 Previously, we would just provide the raw JSON to the TypeScript compiler worker, but TypeScript does not transform JSON. This caused a problem when emitting a bundle, that the JSON would just be "inlined" into the output, instead of being transformed into a module. This fixes this problem by providing the compiled JSON to the TypeScript compiler, so TypeScript just sees JSON as a "normal" TypeScript module.
This commit is contained in:
parent
83f4916195
commit
da8cb408c8
5 changed files with 60 additions and 7 deletions
|
@ -136,9 +136,9 @@ fn op_fetch_source_files(
|
|||
}
|
||||
_ => f,
|
||||
};
|
||||
// Special handling of Wasm files:
|
||||
// Special handling of WASM and JSON files:
|
||||
// compile them into JS first!
|
||||
// This allows TS to do correct export types.
|
||||
// This allows TS to do correct export types as well as bundles.
|
||||
let source_code = match file.media_type {
|
||||
msg::MediaType::Wasm => {
|
||||
global_state
|
||||
|
@ -148,6 +148,14 @@ fn op_fetch_source_files(
|
|||
.map_err(|e| OpError::other(e.to_string()))?
|
||||
.code
|
||||
}
|
||||
msg::MediaType::Json => {
|
||||
global_state
|
||||
.json_compiler
|
||||
.compile(&file)
|
||||
.await
|
||||
.map_err(|e| OpError::other(e.to_string()))?
|
||||
.code
|
||||
}
|
||||
_ => String::from_utf8(file.source_code).unwrap(),
|
||||
};
|
||||
Ok::<_, OpError>(json!({
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue