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

feature: support typescript #2

Closed
UltiRequiem opened this issue Jan 24, 2022 · 2 comments
Closed

feature: support typescript #2

UltiRequiem opened this issue Jan 24, 2022 · 2 comments
Assignees
Labels
enhancement New feature or request good first issue Good for newcomers help wanted Extra attention is needed

Comments

@UltiRequiem
Copy link
Owner

Options

  1. Still using the browser to manage al js related, using something like https://github.com/harrysolovay/ts-browser

  2. Integrate swc/similar to parse jsx+ts

@UltiRequiem UltiRequiem added enhancement New feature or request good first issue Good for newcomers help wanted Extra attention is needed labels Jan 24, 2022
@UltiRequiem
Copy link
Owner Author

UltiRequiem commented Jan 24, 2022

(not yet) working exampleusing jsx + typescript

use std::{path::Path, sync::Arc};
use swc::{self, config::Options};
use swc_common::{
    errors::{ColorConfig, Handler},
    SourceMap,
};

fn main() {
    let cm = Arc::<SourceMap>::default();

    let fm = cm
        .load_file(Path::new("foo.ts")) // works if only ts
        .expect("failed to load file");

    let handler = Arc::new(Handler::with_tty_emitter(
        ColorConfig::Auto,
        true,
        false,
        Some(cm.clone()),
    ));

    let c = swc::Compiler::new(cm.clone());

    let output = c
        .process_js_file(
            fm,
            &handler,
            &Options {
                ..Default::default()
            },
        )
        .expect("failed to process file");

    println!("{:#?}", output.code);
}

Cargo.toml

[package]
name = "swc_test"
version = "0.1.0"
edition = "2021"

[dependencies]
swc_common = { version = "0.17.2", features = ["tty-emitter"] }
swc = "0.116.23"

@UltiRequiem UltiRequiem self-assigned this Jan 24, 2022
@UltiRequiem
Copy link
Owner Author

TypeScript supported with babel, anyways maybe in the future swc will be integrated into this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

1 participant