mirror of
https://github.com/denoland/deno.git
synced 2025-08-02 01:52:56 +00:00
workers: proper TS libs, more spec-compliant APIs (#3812)
* split lib.deno_main.d.ts into: - lib.deno.shared_globals.d.ts - lib.deno.window.d.ts - lib.deno.worker.d.ts * remove no longer used libs: - lib.deno_main.d.ts - lib.deno_worker.d.ts * change module loading to use proper TS library for compilation * align to Worker API spec: - Worker.terminate() - self.close() - self.name
This commit is contained in:
parent
d14864c57c
commit
161adfc51b
24 changed files with 449 additions and 287 deletions
|
@ -13,6 +13,7 @@ pub use js::JsCompiler;
|
|||
pub use json::JsonCompiler;
|
||||
pub use ts::runtime_compile_async;
|
||||
pub use ts::runtime_transpile_async;
|
||||
pub use ts::TargetLib;
|
||||
pub use ts::TsCompiler;
|
||||
pub use wasm::WasmCompiler;
|
||||
|
||||
|
|
|
@ -37,6 +37,12 @@ lazy_static! {
|
|||
Regex::new(r#""checkJs"\s*?:\s*?true"#).unwrap();
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy)]
|
||||
pub enum TargetLib {
|
||||
Main,
|
||||
Worker,
|
||||
}
|
||||
|
||||
/// Struct which represents the state of the compiler
|
||||
/// configuration where the first is canonical name for the configuration file,
|
||||
/// second is a vector of the bytes of the contents of the configuration file,
|
||||
|
@ -318,6 +324,7 @@ impl TsCompiler {
|
|||
&self,
|
||||
global_state: ThreadSafeGlobalState,
|
||||
source_file: &SourceFile,
|
||||
target: TargetLib,
|
||||
) -> Pin<Box<CompiledModuleFuture>> {
|
||||
if self.has_compiled(&source_file.url) {
|
||||
return match self.get_compiled_module(&source_file.url) {
|
||||
|
@ -360,7 +367,10 @@ impl TsCompiler {
|
|||
&source_file.url
|
||||
);
|
||||
|
||||
let target = "main";
|
||||
let target = match target {
|
||||
TargetLib::Main => "main",
|
||||
TargetLib::Worker => "worker",
|
||||
};
|
||||
|
||||
let root_names = vec![module_url.to_string()];
|
||||
let req_msg = req(
|
||||
|
@ -710,7 +720,7 @@ mod tests {
|
|||
let fut = async move {
|
||||
let result = mock_state
|
||||
.ts_compiler
|
||||
.compile_async(mock_state.clone(), &out)
|
||||
.compile_async(mock_state.clone(), &out, TargetLib::Main)
|
||||
.await;
|
||||
|
||||
assert!(result.is_ok());
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue