diff --git a/bindings/binding_core_node/Cargo.toml b/bindings/binding_core_node/Cargo.toml index d07a3a1d768c..20024c969808 100644 --- a/bindings/binding_core_node/Cargo.toml +++ b/bindings/binding_core_node/Cargo.toml @@ -54,6 +54,7 @@ tracing-subscriber = { version = "0.3.9", features = ["env-filter"] } swc_core = { version = "0.82.10", features = [ "allocator_node", "ecma_ast", + "ecma_codegen", "ecma_ast_serde", "common_concurrent", "bundler", diff --git a/bindings/binding_core_node/src/bundle.rs b/bindings/binding_core_node/src/bundle.rs index c2378b16987b..2fe29702c935 100644 --- a/bindings/binding_core_node/src/bundle.rs +++ b/bindings/binding_core_node/src/bundle.rs @@ -129,16 +129,16 @@ impl Task for BundleTask { None, None, true, - codegen_target, SourceMapsConfig::Bool(true), // TODO &Default::default(), None, - minify, None, true, - false, Default::default(), + swc_core::ecma::codegen::Config::default() + .with_target(codegen_target) + .with_minify(minify), )?; Ok((k, output)) diff --git a/bindings/binding_core_node/src/print.rs b/bindings/binding_core_node/src/print.rs index 983cad30e133..720c23e57fa5 100644 --- a/bindings/binding_core_node/src/print.rs +++ b/bindings/binding_core_node/src/print.rs @@ -40,18 +40,18 @@ impl Task for PrintTask { None, options.output_path.clone(), true, - options.config.jsc.target.unwrap_or(EsVersion::Es2020), options .source_maps .clone() .unwrap_or(SourceMapsConfig::Bool(false)), &Default::default(), None, - options.config.minify.into_bool(), None, options.config.emit_source_map_columns.into_bool(), - false, Default::default(), + swc_core::ecma::codegen::Config::default() + .with_target(options.config.jsc.target.unwrap_or(EsVersion::Es2020)) + .with_minify(options.config.minify.into_bool()), ) .convert_err() }) @@ -102,18 +102,18 @@ pub fn print_sync(program: String, options: Buffer) -> napi::Result, m: &Module, minify: bool) -> Result } let mut e = swc_ecma_codegen::Emitter { - cfg: swc_ecma_codegen::Config { - minify, - ..Default::default() - }, + cfg: swc_ecma_codegen::Config::default().with_minify(true), cm, comments: None, wr, diff --git a/crates/swc/benches/typescript.rs b/crates/swc/benches/typescript.rs index cde28c9da58b..b87bfc8ccb49 100644 --- a/crates/swc/benches/typescript.rs +++ b/crates/swc/benches/typescript.rs @@ -115,15 +115,13 @@ fn bench_codegen(b: &mut Bencher, _target: EsVersion) { None, None, false, - EsVersion::Es2020, SourceMapsConfig::Bool(false), &Default::default(), None, - false, None, false, - false, Default::default(), + swc_ecma_codegen::Config::default().with_target(EsVersion::Es2020), ) .unwrap() })); diff --git a/crates/swc/src/config/mod.rs b/crates/swc/src/config/mod.rs index 48086b9e0f32..f1c2bf934a56 100644 --- a/crates/swc/src/config/mod.rs +++ b/crates/swc/src/config/mod.rs @@ -667,7 +667,7 @@ impl Options { comments.map(|v| v as _), ); - let keep_import_assertions = experimental.keep_import_assertions.into_bool(); + let keep_import_attributes = experimental.keep_import_attributes.into_bool(); #[cfg(feature = "plugin")] let plugin_transforms = { @@ -801,7 +801,7 @@ impl Options { ), // The transform strips import assertions, so it's only enabled if // keep_import_assertions is false. - Optional::new(import_assertions(), !keep_import_assertions), + Optional::new(import_assertions(), !keep_import_attributes), Optional::new( typescript::strip_with_jsx::>( cm.clone(), @@ -873,6 +873,9 @@ impl Options { preserve_comments, emit_source_map_columns: cfg.emit_source_map_columns.into_bool(), output: JscOutputConfig { charset, preamble }, + emit_assert_for_import_attributes: experimental + .emit_assert_for_import_attributes + .into_bool(), }) } } @@ -1354,6 +1357,7 @@ impl Config { } /// One `BuiltConfig` per a directory with swcrc +#[non_exhaustive] pub struct BuiltInput { pub program: Program, pub pass: P, @@ -1377,6 +1381,37 @@ pub struct BuiltInput { pub emit_source_map_columns: bool, pub output: JscOutputConfig, + pub emit_assert_for_import_attributes: bool, +} + +impl

BuiltInput

+where + P: swc_ecma_visit::Fold, +{ + pub fn with_pass(self, map: impl FnOnce(P) -> N) -> BuiltInput + where + N: swc_ecma_visit::Fold, + { + BuiltInput { + program: self.program, + pass: map(self.pass), + syntax: self.syntax, + target: self.target, + minify: self.minify, + external_helpers: self.external_helpers, + source_maps: self.source_maps, + input_source_map: self.input_source_map, + is_module: self.is_module, + output_path: self.output_path, + source_file_name: self.source_file_name, + preserve_comments: self.preserve_comments, + inline_sources_content: self.inline_sources_content, + comments: self.comments, + emit_source_map_columns: self.emit_source_map_columns, + output: self.output, + emit_assert_for_import_attributes: self.emit_assert_for_import_attributes, + } + } } /// `jsc` in `.swcrc`. @@ -1460,7 +1495,10 @@ pub struct JscExperimental { pub plugins: Option>, /// If true, keeps import assertions in the output. #[serde(default)] - pub keep_import_assertions: BoolConfig, + pub keep_import_attributes: BoolConfig, + + #[serde(default)] + pub emit_assert_for_import_attributes: BoolConfig, /// Location where swc may stores its intermediate cache. /// Currently this is only being used for wasm plugin's bytecache. /// Path should be absolute directory, which will be created if not exist. diff --git a/crates/swc/src/lib.rs b/crates/swc/src/lib.rs index 6ef1ade4d104..398447dc90d2 100644 --- a/crates/swc/src/lib.rs +++ b/crates/swc/src/lib.rs @@ -501,15 +501,13 @@ impl Compiler { source_file_name: Option<&str>, output_path: Option, inline_sources_content: bool, - target: EsVersion, source_map: SourceMapsConfig, source_map_names: &AHashMap, orig: Option<&sourcemap::SourceMap>, - minify: bool, comments: Option<&dyn Comments>, emit_source_map_columns: bool, - ascii_only: bool, preamble: &str, + codegen_config: swc_ecma_codegen::Config, ) -> Result where T: Node + VisitWith, @@ -535,17 +533,12 @@ impl Compiler { w.preamble(preamble).unwrap(); let mut wr = Box::new(w) as Box; - if minify { + if codegen_config.minify { wr = Box::new(swc_ecma_codegen::text_writer::omit_trailing_semi(wr)); } let mut emitter = Emitter { - cfg: swc_ecma_codegen::Config { - minify, - target, - ascii_only, - ..Default::default() - }, + cfg: codegen_config, comments, cm: self.cm.clone(), wr, @@ -970,26 +963,9 @@ impl Compiler { } }; - let pass = chain!(config.pass, custom_after_pass(&config.program)); - - let config = BuiltInput { - program: config.program, - pass, - syntax: config.syntax, - target: config.target, - minify: config.minify, - external_helpers: config.external_helpers, - source_maps: config.source_maps, - input_source_map: config.input_source_map, - is_module: config.is_module, - output_path: config.output_path, - source_file_name: config.source_file_name, - preserve_comments: config.preserve_comments, - inline_sources_content: config.inline_sources_content, - comments: config.comments, - emit_source_map_columns: config.emit_source_map_columns, - output: config.output, - }; + let after_pass = custom_after_pass(&config.program); + + let config = config.with_pass(|pass| chain!(pass, after_pass)); let orig = if config.source_maps.enabled() { self.get_orig_src_map(&fm, &config.input_source_map, false)? @@ -1170,15 +1146,16 @@ impl Compiler { Some(&fm.name.to_string()), opts.output_path.clone().map(From::from), opts.inline_sources_content, - target, source_map, &source_map_names, orig.as_ref(), - true, Some(&comments), opts.emit_source_map_columns, - opts.format.ascii_only, &opts.format.preamble, + swc_ecma_codegen::Config::default() + .with_target(target) + .with_minify(true) + .with_ascii_only(opts.format.ascii_only), ) }) } @@ -1245,19 +1222,22 @@ impl Compiler { config.source_file_name.as_deref(), config.output_path, config.inline_sources_content, - config.target, config.source_maps, &source_map_names, orig, - config.minify, config.comments.as_ref().map(|v| v as _), config.emit_source_map_columns, - config - .output - .charset - .map(|v| matches!(v, OutputCharset::Ascii)) - .unwrap_or(false), &config.output.preamble, + swc_ecma_codegen::Config::default() + .with_target(config.target) + .with_minify(config.minify) + .with_ascii_only( + config + .output + .charset + .map(|v| matches!(v, OutputCharset::Ascii)) + .unwrap_or(false), + ), ) }) } diff --git a/crates/swc/tests/fixture/issues-7xxx/7908/input/1/.swcrc b/crates/swc/tests/fixture/issues-7xxx/7908/input/1/.swcrc new file mode 100644 index 000000000000..96207a1d39ac --- /dev/null +++ b/crates/swc/tests/fixture/issues-7xxx/7908/input/1/.swcrc @@ -0,0 +1,17 @@ +{ + "$schema": "https://json.schemastore.org/swcrc", + "jsc": { + "parser": { + "syntax": "typescript" + }, + "target": "es2022", + "experimental": { + "keepImportAttributes": true, + "emitAssertForImportAttributes": true + } + }, + "module": { + "type": "es6" + }, + "isModule": true +} \ No newline at end of file diff --git a/crates/swc/tests/fixture/issues-7xxx/7908/input/1/1.js b/crates/swc/tests/fixture/issues-7xxx/7908/input/1/1.js new file mode 100644 index 000000000000..e020128a2d7b --- /dev/null +++ b/crates/swc/tests/fixture/issues-7xxx/7908/input/1/1.js @@ -0,0 +1,3 @@ +import packageJSON from "./package.json" assert { type: "json" }; + +console.log(packageJSON) diff --git a/crates/swc/tests/fixture/issues-7xxx/7908/input/2/.swcrc b/crates/swc/tests/fixture/issues-7xxx/7908/input/2/.swcrc new file mode 100644 index 000000000000..fae29fdfd5b0 --- /dev/null +++ b/crates/swc/tests/fixture/issues-7xxx/7908/input/2/.swcrc @@ -0,0 +1,16 @@ +{ + "$schema": "https://json.schemastore.org/swcrc", + "jsc": { + "parser": { + "syntax": "typescript" + }, + "target": "es2022", + "experimental": { + "keepImportAttributes": true + } + }, + "module": { + "type": "es6" + }, + "isModule": true +} \ No newline at end of file diff --git a/crates/swc/tests/fixture/issues-7xxx/7908/input/2/1.js b/crates/swc/tests/fixture/issues-7xxx/7908/input/2/1.js new file mode 100644 index 000000000000..4606122aa677 --- /dev/null +++ b/crates/swc/tests/fixture/issues-7xxx/7908/input/2/1.js @@ -0,0 +1,4 @@ +import packageJSON from "./package.json" assert { type: "json" }; + + +console.log(packageJSON) diff --git a/crates/swc/tests/fixture/issues-7xxx/7908/output/1/1.js b/crates/swc/tests/fixture/issues-7xxx/7908/output/1/1.js new file mode 100644 index 000000000000..8398c5d0ae6f --- /dev/null +++ b/crates/swc/tests/fixture/issues-7xxx/7908/output/1/1.js @@ -0,0 +1,4 @@ +import packageJSON from "./package.json" with { + type: "json" +}; +console.log(packageJSON); diff --git a/crates/swc/tests/fixture/issues-7xxx/7908/output/2/1.js b/crates/swc/tests/fixture/issues-7xxx/7908/output/2/1.js new file mode 100644 index 000000000000..8398c5d0ae6f --- /dev/null +++ b/crates/swc/tests/fixture/issues-7xxx/7908/output/2/1.js @@ -0,0 +1,4 @@ +import packageJSON from "./package.json" with { + type: "json" +}; +console.log(packageJSON); diff --git a/crates/swc/tests/projects.rs b/crates/swc/tests/projects.rs index 2a2594d519cd..3f3c578d9f60 100644 --- a/crates/swc/tests/projects.rs +++ b/crates/swc/tests/projects.rs @@ -7,8 +7,8 @@ use anyhow::Context; use rayon::prelude::*; use swc::{ config::{ - BuiltInput, Config, FileMatcher, JsMinifyOptions, JscConfig, ModuleConfig, Options, - SourceMapsConfig, TransformConfig, + Config, FileMatcher, JsMinifyOptions, JscConfig, ModuleConfig, Options, SourceMapsConfig, + TransformConfig, }, try_with_handler, BoolOrDataConfig, Compiler, TransformOutput, }; @@ -719,24 +719,7 @@ fn should_visit() { dbg!(config.syntax); - let config = BuiltInput { - program: config.program, - pass: chain!(Panicking, config.pass), - syntax: config.syntax, - target: config.target, - minify: config.minify, - external_helpers: config.external_helpers, - source_maps: config.source_maps, - input_source_map: config.input_source_map, - is_module: config.is_module, - output_path: config.output_path, - source_file_name: config.source_file_name, - preserve_comments: config.preserve_comments, - inline_sources_content: config.inline_sources_content, - comments: config.comments, - emit_source_map_columns: config.emit_source_map_columns, - output: config.output, - }; + let config = config.with_pass(|pass| chain!(Panicking, pass)); if config.minify { let preserve_excl = |_: &BytePos, vc: &mut Vec| -> bool { @@ -760,16 +743,16 @@ fn should_visit() { None, config.output_path, config.inline_sources_content, - config.target, config.source_maps, &Default::default(), None, // TODO: figure out sourcemaps - config.minify, Some(&comments), config.emit_source_map_columns, - false, Default::default(), + swc_ecma_codegen::Config::default() + .with_target(config.target) + .with_minify(config.minify), ) .unwrap() .code) diff --git a/crates/swc_bundler/examples/bundle.rs b/crates/swc_bundler/examples/bundle.rs index 8e1b606f151f..8bbd9d6c0225 100644 --- a/crates/swc_bundler/examples/bundle.rs +++ b/crates/swc_bundler/examples/bundle.rs @@ -42,10 +42,7 @@ fn print_bundles(cm: Lrc, modules: Vec, minify: bool) { { let wr = JsWriter::new(cm.clone(), "\n", &mut buf, None); let mut emitter = Emitter { - cfg: swc_ecma_codegen::Config { - minify, - ..Default::default() - }, + cfg: swc_ecma_codegen::Config::default().with_minify(true), cm: cm.clone(), comments: None, wr: if minify { diff --git a/crates/swc_bundler/examples/path.rs b/crates/swc_bundler/examples/path.rs index 48ad850d843c..7857b6902bc3 100644 --- a/crates/swc_bundler/examples/path.rs +++ b/crates/swc_bundler/examples/path.rs @@ -46,10 +46,7 @@ fn main() { let wr = stdout(); let mut emitter = Emitter { - cfg: swc_ecma_codegen::Config { - minify: false, - ..Default::default() - }, + cfg: swc_ecma_codegen::Config::default(), cm: cm.clone(), comments: None, wr: Box::new(JsWriter::new(cm, "\n", wr.lock(), None)), diff --git a/crates/swc_bundler/src/debug/mod.rs b/crates/swc_bundler/src/debug/mod.rs index 372fbcd5a638..eca3c6ae12c7 100644 --- a/crates/swc_bundler/src/debug/mod.rs +++ b/crates/swc_bundler/src/debug/mod.rs @@ -19,10 +19,7 @@ pub(crate) fn print_hygiene(event: &str, cm: &Lrc, t: &Module) { writeln!(w, "==================== @ {} ====================", event).unwrap(); Emitter { - cfg: swc_ecma_codegen::Config { - minify: false, - ..Default::default() - }, + cfg: swc_ecma_codegen::Config::default(), cm: cm.clone(), comments: None, wr: Box::new(JsWriter::new(cm.clone(), "\n", &mut w, None)), diff --git a/crates/swc_bundler/tests/deno.rs b/crates/swc_bundler/tests/deno.rs index 4431ad4eed2d..ad593a30c783 100644 --- a/crates/swc_bundler/tests/deno.rs +++ b/crates/swc_bundler/tests/deno.rs @@ -1085,10 +1085,7 @@ fn bundle(url: &str, minify: bool) -> String { } Emitter { - cfg: swc_ecma_codegen::Config { - minify, - ..Default::default() - }, + cfg: swc_ecma_codegen::Config::default().with_minify(minify), cm: cm.clone(), comments: None, wr, diff --git a/crates/swc_ecma_codegen/src/config.rs b/crates/swc_ecma_codegen/src/config.rs index 204d77a041fd..90ff3f84d487 100644 --- a/crates/swc_ecma_codegen/src/config.rs +++ b/crates/swc_ecma_codegen/src/config.rs @@ -5,6 +5,7 @@ use swc_ecma_ast::EsVersion; #[derive(Debug, Clone, Copy)] #[cfg_attr(feature = "serde-impl", derive(Serialize, Deserialize))] #[cfg_attr(feature = "serde-impl", serde(rename_all = "camelCase"))] +#[non_exhaustive] pub struct Config { /// The target runtime environment. /// @@ -32,6 +33,9 @@ pub struct Config { /// Defaults to `false`. #[cfg_attr(feature = "serde-impl", serde(default))] pub omit_last_semi: bool, + + #[cfg_attr(feature = "serde-impl", serde(default))] + pub emit_assert_for_import_attributes: bool, } impl Default for Config { @@ -41,6 +45,37 @@ impl Default for Config { minify: false, ascii_only: false, omit_last_semi: false, + emit_assert_for_import_attributes: false, } } } + +impl Config { + pub fn with_target(mut self, target: EsVersion) -> Self { + self.target = target; + self + } + + pub fn with_minify(mut self, minify: bool) -> Self { + self.minify = minify; + self + } + + pub fn with_ascii_only(mut self, ascii_only: bool) -> Self { + self.ascii_only = ascii_only; + self + } + + pub fn with_omit_last_semi(mut self, omit_last_semi: bool) -> Self { + self.omit_last_semi = omit_last_semi; + self + } + + pub fn with_emit_assert_for_import_attributes( + mut self, + emit_assert_for_import_attributes: bool, + ) -> Self { + self.emit_assert_for_import_attributes = emit_assert_for_import_attributes; + self + } +} diff --git a/crates/swc_ecma_codegen/src/lib.rs b/crates/swc_ecma_codegen/src/lib.rs index 16dfb9bb5074..c30f9d3c8675 100644 --- a/crates/swc_ecma_codegen/src/lib.rs +++ b/crates/swc_ecma_codegen/src/lib.rs @@ -310,7 +310,11 @@ where if let Some(with) = &n.with { formatting_space!(); - keyword!("with"); + if self.cfg.emit_assert_for_import_attributes { + keyword!("asserts"); + } else { + keyword!("with") + }; formatting_space!(); emit!(with); } @@ -453,7 +457,11 @@ where if let Some(with) = &node.with { formatting_space!(); - keyword!("with"); + if self.cfg.emit_assert_for_import_attributes { + keyword!("asserts"); + } else { + keyword!("with") + }; formatting_space!(); emit!(with); } @@ -479,7 +487,11 @@ where if let Some(with) = &node.with { formatting_space!(); - keyword!("with"); + if self.cfg.emit_assert_for_import_attributes { + keyword!("asserts"); + } else { + keyword!("with") + }; formatting_space!(); emit!(with); } diff --git a/crates/swc_ecma_codegen/tests/fixture.rs b/crates/swc_ecma_codegen/tests/fixture.rs index d162af295ea5..aba025d52896 100644 --- a/crates/swc_ecma_codegen/tests/fixture.rs +++ b/crates/swc_ecma_codegen/tests/fixture.rs @@ -49,10 +49,7 @@ fn run(input: &Path, minify: bool) { } let mut emitter = Emitter { - cfg: swc_ecma_codegen::Config { - minify, - ..Default::default() - }, + cfg: swc_ecma_codegen::Config::default().with_minify(minify), cm, comments: None, wr, diff --git a/crates/swc_ecma_codegen/tests/sourcemap.rs b/crates/swc_ecma_codegen/tests/sourcemap.rs index b8d2e7af2ddd..dd8358b06dfc 100644 --- a/crates/swc_ecma_codegen/tests/sourcemap.rs +++ b/crates/swc_ecma_codegen/tests/sourcemap.rs @@ -322,12 +322,10 @@ fn identity(entry: PathBuf) { wr = Box::new(swc_ecma_codegen::text_writer::omit_trailing_semi(wr)); let mut emitter = Emitter { - cfg: swc_ecma_codegen::Config { - minify: true, - target: EsVersion::Es5, - ascii_only: true, - ..Default::default() - }, + cfg: swc_ecma_codegen::Config::default() + .with_minify(true) + .with_ascii_only(true) + .with_target(EsVersion::Es5), cm: cm.clone(), wr, comments: None, diff --git a/crates/swc_ecma_codegen/tests/test262.rs b/crates/swc_ecma_codegen/tests/test262.rs index 8e0b27028362..b8e60b4e4a4b 100644 --- a/crates/swc_ecma_codegen/tests/test262.rs +++ b/crates/swc_ecma_codegen/tests/test262.rs @@ -136,11 +136,9 @@ fn do_test(entry: &Path, minify: bool) { } let mut emitter = Emitter { - cfg: swc_ecma_codegen::Config { - minify, - target: EsVersion::Es5, - ..Default::default() - }, + cfg: swc_ecma_codegen::Config::default() + .with_minify(minify) + .with_target(EsVersion::Es5), cm, wr, comments: if minify { None } else { Some(&comments) }, diff --git a/crates/swc_ecma_minifier/benches/full.rs b/crates/swc_ecma_minifier/benches/full.rs index f0c0935256f9..17eba4f4e76a 100644 --- a/crates/swc_ecma_minifier/benches/full.rs +++ b/crates/swc_ecma_minifier/benches/full.rs @@ -112,10 +112,7 @@ fn print(cm: Lrc, nodes: &[N], minify: boo { let mut emitter = swc_ecma_codegen::Emitter { - cfg: swc_ecma_codegen::Config { - minify, - ..Default::default() - }, + cfg: swc_ecma_codegen::Config::default().with_minify(minify), cm: cm.clone(), comments: None, wr: Box::new(JsWriter::new(cm, "\n", &mut buf, None)), diff --git a/crates/swc_ecma_minifier/examples/compress.rs b/crates/swc_ecma_minifier/examples/compress.rs index f141fc234558..705ac90247a2 100644 --- a/crates/swc_ecma_minifier/examples/compress.rs +++ b/crates/swc_ecma_minifier/examples/compress.rs @@ -75,10 +75,7 @@ fn print(cm: Lrc, nodes: &[N], minify: boo { let mut emitter = swc_ecma_codegen::Emitter { - cfg: swc_ecma_codegen::Config { - minify, - ..Default::default() - }, + cfg: swc_ecma_codegen::Config::default().with_minify(minify), cm: cm.clone(), comments: None, wr: Box::new(JsWriter::new(cm, "\n", &mut buf, None)), diff --git a/crates/swc_ecma_minifier/examples/minifier.rs b/crates/swc_ecma_minifier/examples/minifier.rs index 73708705cbc1..395f6ebdd27b 100644 --- a/crates/swc_ecma_minifier/examples/minifier.rs +++ b/crates/swc_ecma_minifier/examples/minifier.rs @@ -76,10 +76,7 @@ fn print(cm: Lrc, nodes: &[N], minify: boo { let mut emitter = swc_ecma_codegen::Emitter { - cfg: swc_ecma_codegen::Config { - minify, - ..Default::default() - }, + cfg: swc_ecma_codegen::Config::default().with_minify(minify), cm: cm.clone(), comments: None, wr: omit_trailing_semi(JsWriter::new(cm, "\n", &mut buf, None)), diff --git a/crates/swc_ecma_minifier/examples/minify-all.rs b/crates/swc_ecma_minifier/examples/minify-all.rs index a770bc11b0dc..6a94bbceccdd 100644 --- a/crates/swc_ecma_minifier/examples/minify-all.rs +++ b/crates/swc_ecma_minifier/examples/minify-all.rs @@ -122,10 +122,7 @@ fn print(cm: Lrc, nodes: &[N], minify: boo { let mut emitter = swc_ecma_codegen::Emitter { - cfg: swc_ecma_codegen::Config { - minify, - ..Default::default() - }, + cfg: swc_ecma_codegen::Config::default().with_minify(minify), cm: cm.clone(), comments: None, wr: Box::new(JsWriter::new(cm, "\n", &mut buf, None)), diff --git a/crates/swc_ecma_minifier/src/util/base54.rs b/crates/swc_ecma_minifier/src/util/base54.rs index 7b0820a6f8bc..d98dfa98b9b4 100644 --- a/crates/swc_ecma_minifier/src/util/base54.rs +++ b/crates/swc_ecma_minifier/src/util/base54.rs @@ -227,12 +227,9 @@ impl CharFreq { { let mut emitter = Emitter { - cfg: swc_ecma_codegen::Config { - target: EsVersion::latest(), - ascii_only: false, - minify: true, - ..Default::default() - }, + cfg: swc_ecma_codegen::Config::default() + .with_target(EsVersion::latest()) + .with_minify(true), cm, comments: None, wr: &mut freq, diff --git a/crates/swc_ecma_minifier/tests/compress.rs b/crates/swc_ecma_minifier/tests/compress.rs index c3ba509b84e9..1ac887200a77 100644 --- a/crates/swc_ecma_minifier/tests/compress.rs +++ b/crates/swc_ecma_minifier/tests/compress.rs @@ -630,10 +630,7 @@ fn print( } let mut emitter = Emitter { - cfg: swc_ecma_codegen::Config { - minify, - ..Default::default() - }, + cfg: swc_ecma_codegen::Config::default().with_minify(minify), cm, comments: None, wr, diff --git a/crates/swc_ecma_minifier/tests/exec.rs b/crates/swc_ecma_minifier/tests/exec.rs index 98fab543f67d..a02d73b4c2b8 100644 --- a/crates/swc_ecma_minifier/tests/exec.rs +++ b/crates/swc_ecma_minifier/tests/exec.rs @@ -77,10 +77,7 @@ fn print( } let mut emitter = Emitter { - cfg: swc_ecma_codegen::Config { - minify, - ..Default::default() - }, + cfg: swc_ecma_codegen::Config::default().with_minify(minify), cm, comments: None, wr, diff --git a/crates/swc_ecma_minifier/tests/mangle.rs b/crates/swc_ecma_minifier/tests/mangle.rs index 480f48248e4f..140f3c16d369 100644 --- a/crates/swc_ecma_minifier/tests/mangle.rs +++ b/crates/swc_ecma_minifier/tests/mangle.rs @@ -33,10 +33,7 @@ fn print(cm: Lrc, m: &Module, minify: bool) -> String { } let mut emitter = Emitter { - cfg: swc_ecma_codegen::Config { - minify, - ..Default::default() - }, + cfg: swc_ecma_codegen::Config::default().with_minify(minify), cm, comments: None, wr, diff --git a/crates/swc_ecma_minifier/tests/terser_exec.rs b/crates/swc_ecma_minifier/tests/terser_exec.rs index dd8d2ed84ac1..df809bf1afee 100644 --- a/crates/swc_ecma_minifier/tests/terser_exec.rs +++ b/crates/swc_ecma_minifier/tests/terser_exec.rs @@ -304,10 +304,7 @@ fn print( } let mut emitter = Emitter { - cfg: swc_ecma_codegen::Config { - minify, - ..Default::default() - }, + cfg: swc_ecma_codegen::Config::default().with_minify(minify), cm, comments: None, wr, diff --git a/crates/swc_ecma_preset_env/tests/test.rs b/crates/swc_ecma_preset_env/tests/test.rs index f4bf64eb8cdb..1379699a01c7 100644 --- a/crates/swc_ecma_preset_env/tests/test.rs +++ b/crates/swc_ecma_preset_env/tests/test.rs @@ -159,10 +159,7 @@ fn exec(c: PresetConfig, dir: PathBuf) -> Result<(), Error> { let mut buf = vec![]; { let mut emitter = Emitter { - cfg: swc_ecma_codegen::Config { - minify: false, - ..Default::default() - }, + cfg: swc_ecma_codegen::Config::default(), comments: None, cm: cm.clone(), wr: Box::new(swc_ecma_codegen::text_writer::JsWriter::new( diff --git a/crates/swc_ecma_transforms_base/tests/fixer_test262.rs b/crates/swc_ecma_transforms_base/tests/fixer_test262.rs index 60822e4bb293..4afd9b651f2d 100644 --- a/crates/swc_ecma_transforms_base/tests/fixer_test262.rs +++ b/crates/swc_ecma_transforms_base/tests/fixer_test262.rs @@ -175,10 +175,7 @@ fn identity_tests(tests: &mut Vec) -> Result<(), io::Error> { { let mut emitter = Emitter { - cfg: swc_ecma_codegen::Config { - minify: false, - ..Default::default() - }, + cfg: swc_ecma_codegen::Config::default(), cm: cm.clone(), wr: Box::new(swc_ecma_codegen::text_writer::JsWriter::new( cm.clone(), @@ -189,10 +186,7 @@ fn identity_tests(tests: &mut Vec) -> Result<(), io::Error> { comments: None, }; let mut expected_emitter = Emitter { - cfg: swc_ecma_codegen::Config { - minify: false, - ..Default::default() - }, + cfg: swc_ecma_codegen::Config::default(), cm: cm.clone(), wr: Box::new(swc_ecma_codegen::text_writer::JsWriter::new( cm, "\n", &mut wr2, None, diff --git a/crates/swc_ecma_transforms_proposal/src/import_assertions.rs b/crates/swc_ecma_transforms_proposal/src/import_assertions.rs index ef6f5de1bc48..5612a312f169 100644 --- a/crates/swc_ecma_transforms_proposal/src/import_assertions.rs +++ b/crates/swc_ecma_transforms_proposal/src/import_assertions.rs @@ -1,9 +1,13 @@ use swc_ecma_ast::{ExportAll, ImportDecl, NamedExport}; use swc_ecma_visit::{as_folder, noop_visit_mut_type, Fold, VisitMut}; -pub fn import_assertions() -> impl VisitMut + Fold { +#[deprecated(note = "Please use `import_assertions` instead")] +pub use self::import_attributes as import_assertions; + +pub fn import_attributes() -> impl VisitMut + Fold { as_folder(ImportAssertions) } + struct ImportAssertions; impl VisitMut for ImportAssertions { diff --git a/crates/swc_ecma_transforms_react/src/jsx/tests.rs b/crates/swc_ecma_transforms_react/src/jsx/tests.rs index 7ab15dd9f0e3..acf91be34d19 100644 --- a/crates/swc_ecma_transforms_react/src/jsx/tests.rs +++ b/crates/swc_ecma_transforms_react/src/jsx/tests.rs @@ -1499,12 +1499,9 @@ fn test_script(src: &str, output: &Path, options: Options) { let mut buf = vec![]; let mut emitter = Emitter { - cfg: Config { - target: Default::default(), - ascii_only: true, - minify: false, - omit_last_semi: true, - }, + cfg: Config::default() + .with_ascii_only(true) + .with_omit_last_semi(true), cm: tester.cm.clone(), wr: Box::new(swc_ecma_codegen::text_writer::JsWriter::new( tester.cm.clone(), diff --git a/crates/swc_ecma_transforms_typescript/examples/ts_to_js.rs b/crates/swc_ecma_transforms_typescript/examples/ts_to_js.rs index 7edfc18cade2..680d3ab0e04e 100644 --- a/crates/swc_ecma_transforms_typescript/examples/ts_to_js.rs +++ b/crates/swc_ecma_transforms_typescript/examples/ts_to_js.rs @@ -80,10 +80,7 @@ fn main() { let mut buf = vec![]; { let mut emitter = Emitter { - cfg: swc_ecma_codegen::Config { - minify: false, - ..Default::default() - }, + cfg: swc_ecma_codegen::Config::default(), cm: cm.clone(), comments: Some(&comments), wr: JsWriter::new(cm.clone(), "\n", &mut buf, None), diff --git a/crates/swc_ecma_transforms_typescript/tests/strip_correctness.rs b/crates/swc_ecma_transforms_typescript/tests/strip_correctness.rs index 0497aff5bbb8..21f42d101137 100644 --- a/crates/swc_ecma_transforms_typescript/tests/strip_correctness.rs +++ b/crates/swc_ecma_transforms_typescript/tests/strip_correctness.rs @@ -188,10 +188,7 @@ fn identity(entry: PathBuf) { { let mut emitter = Emitter { - cfg: swc_ecma_codegen::Config { - minify: false, - ..Default::default() - }, + cfg: swc_ecma_codegen::Config::default(), cm: cm.clone(), wr: Box::new(swc_ecma_codegen::text_writer::JsWriter::new( cm.clone(), diff --git a/crates/swc_html_minifier/src/lib.rs b/crates/swc_html_minifier/src/lib.rs index bca0f876bf6c..4a83a7d9aa6f 100644 --- a/crates/swc_html_minifier/src/lib.rs +++ b/crates/swc_html_minifier/src/lib.rs @@ -2114,12 +2114,7 @@ impl Minifier<'_> { )) as Box; let mut emitter = swc_ecma_codegen::Emitter { - cfg: swc_ecma_codegen::Config { - target, - minify: false, - ascii_only: false, - omit_last_semi: false, - }, + cfg: swc_ecma_codegen::Config::default().with_target(target), cm, comments: Some(&comments), wr, diff --git a/crates/swc_node_bundler/tests/fixture.rs b/crates/swc_node_bundler/tests/fixture.rs index 9ecac943b378..237f37a62239 100644 --- a/crates/swc_node_bundler/tests/fixture.rs +++ b/crates/swc_node_bundler/tests/fixture.rs @@ -91,15 +91,13 @@ fn pass(input_dir: PathBuf) { None, None, false, - EsVersion::Es2020, SourceMapsConfig::Bool(false), &Default::default(), None, - false, Some(&comments), false, - false, Default::default(), + swc_ecma_codegen::Config::default().with_target(EsVersion::Es2020), ) .expect("failed to print?") .code; diff --git a/crates/swc_plugin_runner/src/wasix_runtime.rs b/crates/swc_plugin_runner/src/wasix_runtime.rs index 09e8d0b54ecd..1fa2fb936ac1 100644 --- a/crates/swc_plugin_runner/src/wasix_runtime.rs +++ b/crates/swc_plugin_runner/src/wasix_runtime.rs @@ -1,3 +1,5 @@ +#![allow(unused)] + use std::{path::PathBuf, sync::Arc}; use parking_lot::Mutex;