Skip to content

How to walk SWC-generated AST in Rust #3044

Answered by RiESAEX
PuruVJ asked this question in Q&A
Discussion options

You must be logged in to vote
use std::{fs, sync::Arc};
use swc::{config::Options, ecmascript::ast::ModuleItem};
use swc_common::{
    errors::{ColorConfig, Handler},
    FileName, SourceMap, DUMMY_SP,
};
use swc_ecma_parser::{Syntax, TsConfig};
use swc_ecmascript::{
    ast::Lit,
    transforms::pass::noop,
    visit::{as_folder, Fold},
};
use swc_ecmascript::{
    ast::{Expr, Number},
    visit::{VisitMut, VisitMutWith},
};
fn main() {
    let cm = Arc::<SourceMap>::default();
    let handler = Handler::with_tty_emitter(ColorConfig::Auto, true, false, Some(cm.clone()));
    let c = swc::Compiler::new(cm.clone());

    let fm = cm.new_source_file(
        FileName::Custom("test.js".into()),
        include_str!("./ma…

Replies: 2 comments 6 replies

Comment options

You must be logged in to vote
1 reply
@PuruVJ
Comment options

Comment options

You must be logged in to vote
5 replies
@PuruVJ
Comment options

@kdy1
Comment options

@PuruVJ
Comment options

@PuruVJ
Comment options

@kdy1
Comment options

Answer selected by PuruVJ
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
4 participants