-
-
Notifications
You must be signed in to change notification settings - Fork 466
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(mangler): add debug mode (#4314)
closes #4303
- Loading branch information
Showing
5 changed files
with
70 additions
and
3 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
#![allow(clippy::print_stdout)] | ||
use std::path::Path; | ||
|
||
use oxc_allocator::Allocator; | ||
use oxc_codegen::CodeGenerator; | ||
use oxc_mangler::ManglerBuilder; | ||
use oxc_parser::Parser; | ||
use oxc_span::SourceType; | ||
use pico_args::Arguments; | ||
|
||
// Instruction: | ||
// create a `test.js`, | ||
// run `cargo run -p oxc_mangler --example mangler` or `just example mangler` | ||
|
||
fn main() -> std::io::Result<()> { | ||
let mut args = Arguments::from_env(); | ||
|
||
let name = args.subcommand().ok().flatten().unwrap_or_else(|| String::from("test.js")); | ||
let debug = args.contains("--debug"); | ||
let twice = args.contains("--twice"); | ||
|
||
let path = Path::new(&name); | ||
let source_text = std::fs::read_to_string(path)?; | ||
let source_type = SourceType::from_path(path).unwrap(); | ||
|
||
let printed = mangler(&source_text, source_type, debug); | ||
println!("{printed}"); | ||
|
||
if twice { | ||
let printed = mangler(&printed, source_type, debug); | ||
println!("{printed}"); | ||
} | ||
|
||
Ok(()) | ||
} | ||
|
||
fn mangler(source_text: &str, source_type: SourceType, debug: bool) -> String { | ||
let allocator = Allocator::default(); | ||
let ret = Parser::new(&allocator, source_text, source_type).parse(); | ||
let program = allocator.alloc(ret.program); | ||
let mangler = ManglerBuilder::default().debug(debug).build(program); | ||
CodeGenerator::new().with_mangler(Some(mangler)).build(program).source_text | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters