mirror of
https://github.com/swc-project/swc.git
synced 2024-12-24 22:22:34 +03:00
2fedf32747
swc_bundler: - Splitted from spack swc_ecma_parser: - Fix unexpected eof problem which occurs if log level is trace swc_ecma_transforms: - Fix bugs of dce pass spack: - Support cyclic dependencies
45 lines
1.1 KiB
Rust
45 lines
1.1 KiB
Rust
use swc_common::{
|
|
self,
|
|
errors::{ColorConfig, Handler},
|
|
sync::Lrc,
|
|
FileName, SourceMap,
|
|
};
|
|
use swc_ecma_parser::{lexer::Lexer, Capturing, Parser, StringInput, Syntax};
|
|
|
|
fn main() {
|
|
let cm: Lrc<SourceMap> = Default::default();
|
|
let handler = Handler::with_tty_emitter(ColorConfig::Auto, true, false, Some(cm.clone()));
|
|
|
|
// Real usage
|
|
// let fm = cm
|
|
// .load_file(Path::new("test.js"))
|
|
// .expect("failed to load test.js");
|
|
|
|
let fm = cm.new_source_file(
|
|
FileName::Custom("test.js".into()),
|
|
"function foo() {}".into(),
|
|
);
|
|
|
|
let lexer = Lexer::new(
|
|
Syntax::Es(Default::default()),
|
|
Default::default(),
|
|
StringInput::from(&*fm),
|
|
None,
|
|
);
|
|
|
|
let capturing = Capturing::new(lexer);
|
|
|
|
let mut parser = Parser::new_from(capturing);
|
|
|
|
for e in parser.take_errors() {
|
|
e.into_diagnostic(&handler).emit();
|
|
}
|
|
|
|
let _module = parser
|
|
.parse_module()
|
|
.map_err(|e| e.into_diagnostic(&handler).emit())
|
|
.expect("Failed to parse module.");
|
|
|
|
println!("Tokens: {:?}", parser.input().take());
|
|
}
|