Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions crates/swc/src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -802,7 +802,11 @@ impl Options {
comments: comments.cloned(),
preserve_comments,
emit_source_map_columns: cfg.emit_source_map_columns.into_bool(),
output: JscOutputConfig { charset, preamble },
output: JscOutputConfig {
charset,
preamble,
preserve_annotations: cfg.jsc.output.preserve_annotations,
},
emit_assert_for_import_attributes: experimental
.emit_assert_for_import_attributes
.into_bool(),
Expand Down Expand Up @@ -1144,9 +1148,9 @@ where
output_path: self.output_path,
source_root: self.source_root,
source_file_name: self.source_file_name,
comments: self.comments,
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,
Expand Down Expand Up @@ -1212,6 +1216,9 @@ pub struct JscOutputConfig {

#[serde(default)]
pub preamble: String,

#[serde(default)]
pub preserve_annotations: BoolConfig<false>,
}

#[derive(Debug, Clone, Serialize, Deserialize, Default)]
Expand Down
12 changes: 10 additions & 2 deletions crates/swc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -888,7 +888,11 @@ impl Compiler {
.clone()
.into_inner()
.unwrap_or(BoolOr::Data(JsMinifyCommentOption::PreserveSomeComments));
swc_compiler_base::minify_file_comments(&comments, preserve_comments);
swc_compiler_base::minify_file_comments(
&comments,
preserve_comments,
opts.format.preserve_annotations,
);

self.print(
&program,
Expand Down Expand Up @@ -1018,7 +1022,11 @@ impl Compiler {
});

if let Some(comments) = &config.comments {
swc_compiler_base::minify_file_comments(comments, config.preserve_comments);
swc_compiler_base::minify_file_comments(
comments,
config.preserve_comments,
config.output.preserve_annotations.into_bool(),
);
}

self.print(
Expand Down
10 changes: 6 additions & 4 deletions crates/swc_compiler_base/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,7 @@ impl SourceMapGenConfig for SwcSourceMapConfig<'_> {
pub fn minify_file_comments(
comments: &SingleThreadedComments,
preserve_comments: BoolOr<JsMinifyCommentOption>,
preserve_annotations: bool,
) {
match preserve_comments {
BoolOr::Bool(true) | BoolOr::Data(JsMinifyCommentOption::PreserveAllComments) => {}
Expand All @@ -356,10 +357,11 @@ pub fn minify_file_comments(
|| c.text.contains("@preserve")
|| c.text.contains("@copyright")
|| c.text.contains("@cc_on")
|| c.text.contains("__PURE__")
|| c.text.contains("__INLINE__")
|| c.text.contains("__NOINLINE__")
|| c.text.contains("@vite-ignore")
|| (preserve_annotations
&& (c.text.contains("__PURE__")
|| c.text.contains("__INLINE__")
|| c.text.contains("__NOINLINE__")
|| c.text.contains("@vite-ignore")))
|| (c.kind == CommentKind::Block && c.text.starts_with('!'))
});
!vc.is_empty()
Expand Down
Loading