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

View file

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

View file

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