refactor(oxc): remove remove_whitespace

This commit is contained in:
Boshen 2024-08-20 18:27:59 +08:00
parent 1f6b107339
commit cd9cf5efd8
No known key found for this signature in database
GPG key ID: 67715A371E534061
3 changed files with 4 additions and 11 deletions

View file

@ -65,10 +65,6 @@ pub trait CompilerInterface {
Some(CodegenOptions::default()) Some(CodegenOptions::default())
} }
fn remove_whitespace(&self) -> bool {
false
}
fn check_semantic_error(&self) -> bool { fn check_semantic_error(&self) -> bool {
true true
} }
@ -215,9 +211,8 @@ pub trait CompilerInterface {
options: CodegenOptions, options: CodegenOptions,
) -> String { ) -> String {
let comment_options = CommentOptions { preserve_annotate_comments: true }; let comment_options = CommentOptions { preserve_annotate_comments: true };
CodeGenerator::new() CodeGenerator::new()
.with_options(CodegenOptions { minify: self.remove_whitespace(), ..options }) .with_options(options)
.enable_comment(source_text, trivias.clone(), comment_options) .enable_comment(source_text, trivias.clone(), comment_options)
.build(program) .build(program)
.source_text .source_text

View file

@ -41,6 +41,7 @@ pub struct CodegenOptions {
/// Use single quotes instead of double quotes. /// Use single quotes instead of double quotes.
pub single_quote: bool, pub single_quote: bool,
/// Remove whitespace.
pub minify: bool, pub minify: bool,
} }

View file

@ -50,11 +50,8 @@ impl CompilerInterface for Driver {
} }
fn codegen_options(&self) -> Option<CodegenOptions> { fn codegen_options(&self) -> Option<CodegenOptions> {
self.codegen.then(CodegenOptions::default) self.codegen
} .then(|| CodegenOptions { minify: self.remove_whitespace, ..CodegenOptions::default() })
fn remove_whitespace(&self) -> bool {
self.remove_whitespace
} }
fn handle_errors(&mut self, errors: Vec<OxcDiagnostic>) { fn handle_errors(&mut self, errors: Vec<OxcDiagnostic>) {