mirror of
https://github.com/danbulant/oxc
synced 2026-05-19 04:08:41 +00:00
refactor(transformer): transformer example output semantic + transformer errors (#5852)
This commit is contained in:
parent
2e93548816
commit
b9c45646d1
1 changed files with 23 additions and 6 deletions
|
|
@ -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 {
|
||||
|
|
@ -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}");
|
||||
|
|
|
|||
Loading…
Reference in a new issue