Skip to content

Commit

Permalink
fix(BREAKING): flip keep_comments to remove_comments (#246)
Browse files Browse the repository at this point in the history
  • Loading branch information
dsherret authored May 30, 2024
1 parent b09282d commit 7b6757d
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 13 deletions.
12 changes: 6 additions & 6 deletions src/emit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ pub struct EmitOptions {
pub source_map_file: Option<String>,
/// Whether to inline the source contents in the source map. Defaults to `true`.
pub inline_sources: bool,
/// Whether to keep comments in the output. Defaults to `false`.
pub keep_comments: bool,
/// Whether to remove comments in the output. Defaults to `false`.
pub remove_comments: bool,
}

impl Default for EmitOptions {
Expand All @@ -41,7 +41,7 @@ impl Default for EmitOptions {
source_map: SourceMapOption::default(),
source_map_file: None,
inline_sources: true,
keep_comments: false,
remove_comments: false,
}
}
}
Expand Down Expand Up @@ -103,10 +103,10 @@ pub fn emit(

let mut emitter = crate::swc::codegen::Emitter {
cfg: swc_codegen_config(),
comments: if emit_options.keep_comments {
Some(&comments)
} else {
comments: if emit_options.remove_comments {
None
} else {
Some(&comments)
},
cm: source_map.clone(),
wr: writer,
Expand Down
32 changes: 25 additions & 7 deletions src/transpiling/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -884,7 +884,13 @@ function App() {
})
.unwrap();
let code = module
.transpile(&TranspileOptions::default(), &EmitOptions::default())
.transpile(
&TranspileOptions::default(),
&EmitOptions {
remove_comments: true,
..Default::default()
},
)
.unwrap()
.into_source()
.into_string()
Expand Down Expand Up @@ -922,7 +928,7 @@ function App() {
.transpile(
&TranspileOptions::default(),
&EmitOptions {
keep_comments: true,
remove_comments: false,
..Default::default()
},
)
Expand Down Expand Up @@ -965,7 +971,13 @@ function App() {
..Default::default()
};
let code = module
.transpile(&transpile_options, &EmitOptions::default())
.transpile(
&transpile_options,
&EmitOptions {
remove_comments: true,
..Default::default()
},
)
.unwrap()
.into_source()
.into_string()
Expand Down Expand Up @@ -1006,7 +1018,13 @@ function App() {
..Default::default()
};
let code = module
.transpile(&transpile_options, &EmitOptions::default())
.transpile(
&transpile_options,
&EmitOptions {
remove_comments: true,
..Default::default()
},
)
.unwrap()
.into_source()
.into_string()
Expand Down Expand Up @@ -1059,11 +1077,11 @@ function App() {
.into_string()
.unwrap()
.text;
let expected = r#"const { "jsx": _jsx, "Fragment": _Fragment } = await import("jsx_lib/jsx-runtime");
let expected = r#"/** @jsxImportSource jsx_lib */ const { "jsx": _jsx, "Fragment": _Fragment } = await import("jsx_lib/jsx-runtime");
const example = await import("example");
function App() {
return _jsx("div", {
children: _jsx(_Fragment, {})
return /*#__PURE__*/ _jsx("div", {
children: /*#__PURE__*/ _jsx(_Fragment, {})
});
"#;
assert_eq!(&code[..expected.len()], expected);
Expand Down

0 comments on commit 7b6757d

Please sign in to comment.