Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(transformer): transformer example output semantic + transformer errors #5852

Merged
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
29 changes: 23 additions & 6 deletions crates/oxc_transformer/examples/transformer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,22 @@ fn main() {
println!("{source_text}\n");

let mut program = ret.program;
let trivias = ret.trivias;

let (symbols, scopes) = SemanticBuilder::new(&source_text)
let ret = SemanticBuilder::new(&source_text)
// Estimate transformer will triple scopes, symbols, references
.with_excess_capacity(2.0)
.build(&program)
.semantic
.into_symbol_table_and_scope_tree();
.build(&program);

if !ret.errors.is_empty() {
println!("Semantic Errors:");
for error in ret.errors {
let error = error.with_source_code(source_text.clone());
println!("{error:?}");
}
}

let (symbols, scopes) = ret.semantic.into_symbol_table_and_scope_tree();

let transform_options = if let Some(targets) = &targets {
TransformOptions::from_preset_env(&EnvOptions {
Expand All @@ -56,16 +65,24 @@ fn main() {
TransformOptions::enable_all()
};

let _ = Transformer::new(
let ret = Transformer::new(
&allocator,
path,
source_type,
&source_text,
ret.trivias.clone(),
trivias.clone(),
transform_options,
)
.build_with_symbols_and_scopes(symbols, scopes, &mut program);

if !ret.errors.is_empty() {
println!("Transformer Errors:");
for error in ret.errors {
let error = error.with_source_code(source_text.clone());
println!("{error:?}");
}
}

let printed = CodeGenerator::new().build(&program).source_text;
println!("Transformed:\n");
println!("{printed}");
Expand Down