diff options
Diffstat (limited to 'cli')
-rw-r--r-- | cli/dts/lib.deno.unstable.d.ts | 8 | ||||
-rw-r--r-- | cli/module_graph.rs | 23 | ||||
-rw-r--r-- | cli/ops/runtime_compiler.rs | 12 | ||||
-rw-r--r-- | cli/tests/compiler_api_test.ts | 16 |
4 files changed, 31 insertions, 28 deletions
diff --git a/cli/dts/lib.deno.unstable.d.ts b/cli/dts/lib.deno.unstable.d.ts index 908c433bf..d955a825f 100644 --- a/cli/dts/lib.deno.unstable.d.ts +++ b/cli/dts/lib.deno.unstable.d.ts @@ -441,10 +441,10 @@ declare namespace Deno { */ export interface EmitOptions { /** Indicate that the source code should be emitted to a single file - * JavaScript bundle that is a single ES module (`"esm"`) or a single file - * self contained script we executes in an immediately invoked function - * when loaded (`"iife"`). */ - bundle?: "esm" | "iife"; + * JavaScript bundle that is a single ES module (`"module"`) or a single + * file self contained script we executes in an immediately invoked function + * when loaded (`"classic"`). */ + bundle?: "module" | "classic"; /** If `true` then the sources will be typed checked, returning any * diagnostic errors in the result. If `false` type checking will be * skipped. Defaults to `true`. diff --git a/cli/module_graph.rs b/cli/module_graph.rs index 51e257339..93930c8a5 100644 --- a/cli/module_graph.rs +++ b/cli/module_graph.rs @@ -606,11 +606,11 @@ pub struct CheckOptions { pub enum BundleType { /// Return the emitted contents of the program as a single "flattened" ES /// module. - Esm, + Module, /// Return the emitted contents of the program as a single script that /// executes the program using an immediately invoked function execution /// (IIFE). - Iife, + Classic, /// Do not bundle the emit, instead returning each of the modules that are /// part of the program as individual files. None, @@ -776,8 +776,11 @@ impl Graph { let maybe_ignored_options = ts_config.merge_tsconfig(options.maybe_config_path)?; - let s = - self.emit_bundle(&root_specifier, &ts_config.into(), &BundleType::Esm)?; + let s = self.emit_bundle( + &root_specifier, + &ts_config.into(), + &BundleType::Module, + )?; let stats = Stats(vec![ ("Files".to_string(), self.modules.len() as u32), ("Total time".to_string(), start.elapsed().as_millis() as u32), @@ -952,7 +955,7 @@ impl Graph { "useDefineForClassFields": true, })); let opts = match options.bundle_type { - BundleType::Esm | BundleType::Iife => json!({ + BundleType::Module | BundleType::Classic => json!({ "noEmit": true, }), BundleType::None => json!({ @@ -993,7 +996,7 @@ impl Graph { let graph = graph.lock().unwrap(); match options.bundle_type { - BundleType::Esm | BundleType::Iife => { + BundleType::Module | BundleType::Classic => { assert!( response.emitted_files.is_empty(), "No files should have been emitted from tsc." @@ -1049,7 +1052,7 @@ impl Graph { let start = Instant::now(); let mut emit_count = 0_u32; match options.bundle_type { - BundleType::Esm | BundleType::Iife => { + BundleType::Module | BundleType::Classic => { assert_eq!( self.roots.len(), 1, @@ -1122,8 +1125,8 @@ impl Graph { let loader = BundleLoader::new(self, emit_options, &globals, cm.clone()); let hook = Box::new(BundleHook); let module = match bundle_type { - BundleType::Esm => swc_bundler::ModuleType::Es, - BundleType::Iife => swc_bundler::ModuleType::Iife, + BundleType::Module => swc_bundler::ModuleType::Es, + BundleType::Classic => swc_bundler::ModuleType::Iife, _ => unreachable!("invalid bundle type"), }; let bundler = swc_bundler::Bundler::new( @@ -2381,7 +2384,7 @@ pub mod tests { let (emitted_files, result_info) = graph .emit(EmitOptions { check: true, - bundle_type: BundleType::Esm, + bundle_type: BundleType::Module, debug: false, maybe_user_config: None, }) diff --git a/cli/ops/runtime_compiler.rs b/cli/ops/runtime_compiler.rs index dc9cd2163..4865c1045 100644 --- a/cli/ops/runtime_compiler.rs +++ b/cli/ops/runtime_compiler.rs @@ -33,10 +33,10 @@ pub fn init(rt: &mut deno_core::JsRuntime) { #[derive(Debug, Deserialize)] enum RuntimeBundleType { - #[serde(rename = "esm")] - Esm, - #[serde(rename = "iife")] - Iife, + #[serde(rename = "module")] + Module, + #[serde(rename = "classic")] + Classic, } #[derive(Debug, Deserialize)] @@ -108,8 +108,8 @@ async fn op_emit( )) })?; let bundle_type = match args.bundle { - Some(RuntimeBundleType::Esm) => BundleType::Esm, - Some(RuntimeBundleType::Iife) => BundleType::Iife, + Some(RuntimeBundleType::Module) => BundleType::Module, + Some(RuntimeBundleType::Classic) => BundleType::Classic, None => BundleType::None, }; let graph = builder.get_graph(); diff --git a/cli/tests/compiler_api_test.ts b/cli/tests/compiler_api_test.ts index 427d3af54..04a4675b8 100644 --- a/cli/tests/compiler_api_test.ts +++ b/cli/tests/compiler_api_test.ts @@ -173,12 +173,12 @@ Deno.test({ }); Deno.test({ - name: "Deno.emit() - bundle esm - with sources", + name: "Deno.emit() - bundle as module script - with sources", async fn() { const { diagnostics, files, ignoredOptions, stats } = await Deno.emit( "/foo.ts", { - bundle: "esm", + bundle: "module", sources: { "/foo.ts": `export * from "./bar.ts";\n`, "/bar.ts": `export const bar = "bar";\n`, @@ -194,12 +194,12 @@ Deno.test({ }); Deno.test({ - name: "Deno.emit() - bundle esm - no sources", + name: "Deno.emit() - bundle as module script - no sources", async fn() { const { diagnostics, files, ignoredOptions, stats } = await Deno.emit( "./subdir/mod1.ts", { - bundle: "esm", + bundle: "module", }, ); assertEquals(diagnostics.length, 0); @@ -211,12 +211,12 @@ Deno.test({ }); Deno.test({ - name: "Deno.emit() - bundle esm - include js modules", + name: "Deno.emit() - bundle as module script - include js modules", async fn() { const { diagnostics, files, ignoredOptions, stats } = await Deno.emit( "/foo.js", { - bundle: "esm", + bundle: "module", sources: { "/foo.js": `export * from "./bar.js";\n`, "/bar.js": `export const bar = "bar";\n`, @@ -321,10 +321,10 @@ Deno.test({ }); Deno.test({ - name: `Deno.emit() - bundle supports iife`, + name: `Deno.emit() - bundle as classic script iife`, async fn() { const { diagnostics, files } = await Deno.emit("/a.ts", { - bundle: "iife", + bundle: "classic", sources: { "/a.ts": `import { b } from "./b.ts"; console.log(b);`, |