Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
4 changes: 2 additions & 2 deletions crates/oxc/src/compiler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::{mem, ops::ControlFlow, path::Path};

use oxc_allocator::Allocator;
use oxc_ast::ast::Program;
use oxc_codegen::{CodeGenerator, CodegenOptions, CodegenReturn};
use oxc_codegen::{Codegen, CodegenOptions, CodegenReturn};
use oxc_diagnostics::OxcDiagnostic;
use oxc_isolated_declarations::{IsolatedDeclarations, IsolatedDeclarationsOptions};
use oxc_mangler::{MangleOptions, Mangler};
Expand Down Expand Up @@ -294,6 +294,6 @@ pub trait CompilerInterface {
if self.enable_sourcemap() {
options.source_map_path = Some(source_path.to_path_buf());
}
CodeGenerator::new().with_options(options).with_scoping(scoping).build(program)
Codegen::new().with_options(options).with_scoping(scoping).build(program)
}
}
4 changes: 2 additions & 2 deletions crates/oxc_codegen/examples/codegen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
use std::path::Path;

use oxc_allocator::Allocator;
use oxc_codegen::{CodeGenerator, CodegenOptions};
use oxc_codegen::{Codegen, CodegenOptions};
use oxc_parser::{ParseOptions, Parser, ParserReturn};
use oxc_span::SourceType;
use pico_args::Arguments;
Expand Down Expand Up @@ -68,7 +68,7 @@ fn parse<'a>(
}

fn codegen(ret: &ParserReturn<'_>, minify: bool) -> String {
CodeGenerator::new()
Codegen::new()
.with_options(CodegenOptions { minify, ..CodegenOptions::default() })
.build(&ret.program)
.code
Expand Down
4 changes: 2 additions & 2 deletions crates/oxc_codegen/examples/sourcemap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::{env, path::Path};

use base64::{Engine, prelude::BASE64_STANDARD};
use oxc_allocator::Allocator;
use oxc_codegen::{CodeGenerator, CodegenOptions, CodegenReturn};
use oxc_codegen::{Codegen, CodegenOptions, CodegenReturn};
use oxc_parser::Parser;
use oxc_span::SourceType;

Expand All @@ -27,7 +27,7 @@ fn main() -> std::io::Result<()> {
return Ok(());
}

let CodegenReturn { code, map, .. } = CodeGenerator::new()
let CodegenReturn { code, map, .. } = Codegen::new()
.with_options(CodegenOptions {
source_map_path: Some(path.to_path_buf()),
..CodegenOptions::default()
Expand Down
3 changes: 0 additions & 3 deletions crates/oxc_codegen/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,6 @@ pub use crate::{
options::{CodegenOptions, LegalComment},
};

/// Code generator without whitespace removal.
pub type CodeGenerator<'a> = Codegen<'a>;

/// Output from [`Codegen::build`]
#[non_exhaustive]
pub struct CodegenReturn {
Expand Down
4 changes: 2 additions & 2 deletions crates/oxc_codegen/tests/integration/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ pub mod ts;
pub mod unit;

use oxc_allocator::Allocator;
use oxc_codegen::{CodeGenerator, CodegenOptions, CodegenReturn};
use oxc_codegen::{Codegen, CodegenOptions, CodegenReturn};
use oxc_parser::Parser;
use oxc_span::SourceType;

Expand All @@ -20,7 +20,7 @@ pub fn codegen_options(source_text: &str, options: &CodegenOptions) -> CodegenRe
let ret = Parser::new(&allocator, source_text, source_type).parse();
let mut options = options.clone();
options.single_quote = true;
CodeGenerator::new().with_options(options).build(&ret.program)
Codegen::new().with_options(options).build(&ret.program)
}

pub fn snapshot(name: &str, cases: &[&str]) {
Expand Down
8 changes: 4 additions & 4 deletions crates/oxc_codegen/tests/integration/tester.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use oxc_allocator::Allocator;
use oxc_codegen::{CodeGenerator, CodegenOptions};
use oxc_codegen::{Codegen, CodegenOptions};
use oxc_parser::{ParseOptions, Parser};
use oxc_span::SourceType;

Expand All @@ -8,7 +8,7 @@ pub fn test_with_parse_options(source_text: &str, expected: &str, parse_options:
let allocator = Allocator::default();
let ret =
Parser::new(&allocator, source_text, SourceType::tsx()).with_options(parse_options).parse();
let result = CodeGenerator::new().build(&ret.program).code;
let result = Codegen::new().build(&ret.program).code;
assert_eq!(result, expected, "\nfor source: {source_text}");
}

Expand Down Expand Up @@ -46,7 +46,7 @@ pub fn test_options_with_source_type(
) {
let allocator = Allocator::default();
let ret = Parser::new(&allocator, source_text, source_type).parse();
let result = CodeGenerator::new().with_options(options).build(&ret.program).code;
let result = Codegen::new().with_options(options).build(&ret.program).code;
assert_eq!(result, expected, "\nfor source: {source_text:?}");
}

Expand All @@ -55,7 +55,7 @@ pub fn test_minify(source_text: &str, expected: &str) {
let source_type = SourceType::jsx();
let allocator = Allocator::default();
let ret = Parser::new(&allocator, source_text, source_type).parse();
let result = CodeGenerator::new()
let result = Codegen::new()
.with_options(CodegenOptions { minify: true, ..CodegenOptions::default() })
.build(&ret.program)
.code;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
use std::{env, path::Path};

use oxc_allocator::Allocator;
use oxc_codegen::CodeGenerator;
use oxc_codegen::Codegen;
use oxc_isolated_declarations::{IsolatedDeclarations, IsolatedDeclarationsOptions};
use oxc_parser::Parser;
use oxc_span::SourceType;
Expand Down Expand Up @@ -35,7 +35,7 @@ fn main() -> std::io::Result<()> {
let id_ret =
IsolatedDeclarations::new(&allocator, IsolatedDeclarationsOptions { strip_internal: true })
.build(&ret.program);
let printed = CodeGenerator::new().build(&id_ret.program).code;
let printed = Codegen::new().build(&id_ret.program).code;

println!("Dts Emit:\n");
println!("{printed}\n");
Expand Down
6 changes: 3 additions & 3 deletions crates/oxc_isolated_declarations/tests/deno/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#[cfg(test)]
mod tests {
use oxc_allocator::Allocator;
use oxc_codegen::CodeGenerator;
use oxc_codegen::Codegen;
use oxc_isolated_declarations::{IsolatedDeclarations, IsolatedDeclarationsOptions};
use oxc_parser::Parser;
use oxc_span::SourceType;
Expand All @@ -18,9 +18,9 @@ mod tests {
IsolatedDeclarationsOptions { strip_internal: true },
)
.build(&ret.program);
let actual = CodeGenerator::new().build(&ret.program).code;
let actual = Codegen::new().build(&ret.program).code;
let expected_program = Parser::new(&allocator, expected, source_type).parse().program;
let expected = CodeGenerator::new().build(&expected_program).code;
let expected = Codegen::new().build(&expected_program).code;
assert_eq!(actual.trim(), expected.trim());
}

Expand Down
6 changes: 3 additions & 3 deletions crates/oxc_linter/src/fixer/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::borrow::Cow;

use oxc_codegen::{CodeGenerator, CodegenOptions};
use oxc_codegen::{Codegen, CodegenOptions};
use oxc_diagnostics::OxcDiagnostic;
use oxc_span::{GetSpan, Span};

Expand Down Expand Up @@ -186,8 +186,8 @@ impl<'c, 'a: 'c> RuleFixer<'c, 'a> {

#[expect(clippy::unused_self)]
#[must_use]
pub fn codegen(self) -> CodeGenerator<'a> {
CodeGenerator::new()
pub fn codegen(self) -> Codegen<'a> {
Codegen::new()
.with_options(CodegenOptions { single_quote: true, ..CodegenOptions::default() })
}

Expand Down
4 changes: 2 additions & 2 deletions crates/oxc_minifier/examples/dce.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
use std::path::Path;

use oxc_allocator::Allocator;
use oxc_codegen::{CodeGenerator, CodegenOptions};
use oxc_codegen::{Codegen, CodegenOptions};
use oxc_minifier::{CompressOptions, Compressor};
use oxc_parser::Parser;
use oxc_span::SourceType;
Expand Down Expand Up @@ -41,7 +41,7 @@ fn dce(allocator: &Allocator, source_text: &str, source_type: SourceType, nospac
let ret = Parser::new(allocator, source_text, source_type).parse();
let mut program = ret.program;
Compressor::new(allocator, CompressOptions::default()).dead_code_elimination(&mut program);
CodeGenerator::new()
Codegen::new()
.with_options(CodegenOptions { minify: nospace, ..CodegenOptions::default() })
.build(&program)
.code
Expand Down
4 changes: 2 additions & 2 deletions crates/oxc_minifier/examples/mangler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
use std::path::Path;

use oxc_allocator::Allocator;
use oxc_codegen::CodeGenerator;
use oxc_codegen::Codegen;
use oxc_mangler::{MangleOptions, MangleOptionsKeepNames, Mangler};
use oxc_parser::Parser;
use oxc_span::SourceType;
Expand Down Expand Up @@ -45,5 +45,5 @@ fn mangler(source_text: &str, source_type: SourceType, options: MangleOptions) -
let allocator = Allocator::default();
let ret = Parser::new(&allocator, source_text, source_type).parse();
let symbol_table = Mangler::new().with_options(options).build(&ret.program);
CodeGenerator::new().with_scoping(Some(symbol_table)).build(&ret.program).code
Codegen::new().with_scoping(Some(symbol_table)).build(&ret.program).code
}
4 changes: 2 additions & 2 deletions crates/oxc_minifier/examples/minifier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
use std::path::Path;

use oxc_allocator::Allocator;
use oxc_codegen::{CodeGenerator, CodegenOptions};
use oxc_codegen::{Codegen, CodegenOptions};
use oxc_mangler::MangleOptions;
use oxc_minifier::{CompressOptions, Minifier, MinifierOptions};
use oxc_parser::Parser;
Expand Down Expand Up @@ -53,7 +53,7 @@ fn minify(
compress: Some(CompressOptions::default()),
};
let ret = Minifier::new(options).build(allocator, &mut program);
CodeGenerator::new()
Codegen::new()
.with_options(CodegenOptions { minify: nospace, ..CodegenOptions::default() })
.with_scoping(ret.scoping)
.build(&program)
Expand Down
4 changes: 2 additions & 2 deletions crates/oxc_minifier/src/tester.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use oxc_allocator::Allocator;
use oxc_codegen::{CodeGenerator, CodegenOptions};
use oxc_codegen::{Codegen, CodegenOptions};
use oxc_parser::{ParseOptions, Parser};
use oxc_span::SourceType;

Expand Down Expand Up @@ -33,7 +33,7 @@ pub fn run(source_text: &str, options: Option<CompressOptions>) -> String {
if let Some(options) = options {
Compressor::new(&allocator, options).build(&mut program);
}
CodeGenerator::new()
Codegen::new()
.with_options(CodegenOptions {
single_quote: true,
minify: false,
Expand Down
4 changes: 2 additions & 2 deletions crates/oxc_minifier/tests/mangler/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::fmt::Write;

use oxc_allocator::Allocator;
use oxc_codegen::CodeGenerator;
use oxc_codegen::Codegen;
use oxc_mangler::{MangleOptions, MangleOptionsKeepNames, Mangler};
use oxc_parser::Parser;
use oxc_span::SourceType;
Expand All @@ -12,7 +12,7 @@ fn mangle(source_text: &str, options: MangleOptions) -> String {
let ret = Parser::new(&allocator, source_text, source_type).parse();
let program = ret.program;
let symbol_table = Mangler::new().with_options(options).build(&program);
CodeGenerator::new().with_scoping(Some(symbol_table)).build(&program).code
Codegen::new().with_scoping(Some(symbol_table)).build(&program).code
}

#[test]
Expand Down
4 changes: 2 additions & 2 deletions crates/oxc_minifier/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ mod mangler;
mod peephole;

use oxc_allocator::Allocator;
use oxc_codegen::{CodeGenerator, CodegenOptions};
use oxc_codegen::{Codegen, CodegenOptions};
use oxc_minifier::{CompressOptions, Compressor};
use oxc_parser::{ParseOptions, Parser};
use oxc_span::SourceType;
Expand Down Expand Up @@ -43,7 +43,7 @@ pub(crate) fn run(
if let Some(options) = options {
Compressor::new(&allocator, options).build(&mut program);
}
CodeGenerator::new()
Codegen::new()
.with_options(CodegenOptions { single_quote: true, ..CodegenOptions::default() })
.build(&program)
.code
Expand Down
4 changes: 2 additions & 2 deletions crates/oxc_transformer/examples/transformer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
use std::path::Path;

use oxc_allocator::Allocator;
use oxc_codegen::CodeGenerator;
use oxc_codegen::Codegen;
use oxc_parser::Parser;
use oxc_semantic::SemanticBuilder;
use oxc_span::SourceType;
Expand Down Expand Up @@ -85,7 +85,7 @@ fn main() {
}
}

let printed = CodeGenerator::new().build(&program).code;
let printed = Codegen::new().build(&program).code;
println!("Transformed:\n");
println!("{printed}");
}
6 changes: 3 additions & 3 deletions crates/oxc_transformer/tests/integrations/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ mod targets;
use std::path::Path;

use oxc_allocator::Allocator;
use oxc_codegen::{CodeGenerator, CodegenOptions};
use oxc_codegen::{Codegen, CodegenOptions};
use oxc_diagnostics::OxcDiagnostic;
use oxc_parser::Parser;
use oxc_semantic::SemanticBuilder;
Expand All @@ -14,7 +14,7 @@ use oxc_transformer::{TransformOptions, Transformer};
pub fn codegen(source_text: &str, source_type: SourceType) -> String {
let allocator = Allocator::default();
let ret = Parser::new(&allocator, source_text, source_type).parse();
CodeGenerator::new()
Codegen::new()
.with_options(CodegenOptions { single_quote: true, ..CodegenOptions::default() })
.build(&ret.program)
.code
Expand All @@ -34,7 +34,7 @@ pub(crate) fn test(
if !ret.errors.is_empty() {
return Err(ret.errors);
}
let code = CodeGenerator::new()
let code = Codegen::new()
.with_options(CodegenOptions { single_quote: true, ..CodegenOptions::default() })
.build(&program)
.code;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -850,7 +850,7 @@ mod test {
use similar::TextDiff;

use oxc_allocator::Allocator;
use oxc_codegen::{CodeGenerator, CodegenOptions};
use oxc_codegen::{Codegen, CodegenOptions};
use oxc_diagnostics::OxcDiagnostic;
use oxc_parser::Parser;
use oxc_semantic::SemanticBuilder;
Expand Down Expand Up @@ -885,7 +885,7 @@ mod test {
if !ret.errors.is_empty() {
return Err(ret.errors);
}
let code = CodeGenerator::new()
let code = Codegen::new()
.with_options(CodegenOptions {
comments: false,
single_quote: true,
Expand All @@ -902,7 +902,7 @@ mod test {
let allocator = Allocator::default();
let ret = Parser::new(&allocator, source_text, source_type).parse();

CodeGenerator::new()
Codegen::new()
.with_options(CodegenOptions {
comments: false,
single_quote: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
//! * <https://github.com/rollup/plugins/tree/pluginutils-v5.1.3/packages/inject/test>

use oxc_allocator::Allocator;
use oxc_codegen::{CodeGenerator, CodegenOptions};
use oxc_codegen::{Codegen, CodegenOptions};
use oxc_parser::Parser;
use oxc_semantic::SemanticBuilder;
use oxc_span::SourceType;
Expand All @@ -19,7 +19,7 @@ fn test(source_text: &str, expected: &str, config: InjectGlobalVariablesConfig)
let mut program = ret.program;
let scoping = SemanticBuilder::new().build(&program).semantic.into_scoping();
let _ = InjectGlobalVariables::new(&allocator, config).build(scoping, &mut program);
let result = CodeGenerator::new()
let result = Codegen::new()
.with_options(CodegenOptions { single_quote: true, ..CodegenOptions::default() })
.build(&program)
.code;
Expand Down
4 changes: 2 additions & 2 deletions crates/oxc_transformer_plugins/tests/integrations/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ mod inject_global_variables;
mod replace_global_defines;

use oxc_allocator::Allocator;
use oxc_codegen::{CodeGenerator, CodegenOptions};
use oxc_codegen::{Codegen, CodegenOptions};
use oxc_parser::Parser;
use oxc_span::SourceType;

pub fn codegen(source_text: &str, source_type: SourceType) -> String {
let allocator = Allocator::default();
let ret = Parser::new(&allocator, source_text, source_type).parse();
CodeGenerator::new()
Codegen::new()
.with_options(CodegenOptions { single_quote: true, ..CodegenOptions::default() })
.build(&ret.program)
.code
Expand Down
Loading
Loading