mirror of
https://github.com/swc-project/swc.git
synced 2024-11-29 11:47:21 +03:00
fix(es/typescript): Fix typings (#9301)
Some checks are pending
CI / Cargo fmt (push) Waiting to run
CI / Cargo clippy (push) Waiting to run
CI / Check license of dependencies (push) Waiting to run
CI / Check (macos-latest) (push) Waiting to run
CI / Check (ubuntu-latest) (push) Waiting to run
CI / Check (windows-latest) (push) Waiting to run
CI / Test wasm (binding_core_wasm) (push) Waiting to run
CI / Test wasm (binding_minifier_wasm) (push) Waiting to run
CI / Test wasm (binding_typescript_wasm) (push) Waiting to run
CI / List crates (push) Waiting to run
CI / Test - ${{ matrix.settings.crate }} - ${{ matrix.settings.os }} (push) Blocked by required conditions
CI / Test node bindings - ${{ matrix.os }} (macos-latest) (push) Waiting to run
CI / Test node bindings - ${{ matrix.os }} (windows-latest) (push) Waiting to run
CI / Test with @swc/cli (push) Waiting to run
CI / Miri (better_scoped_tls) (push) Waiting to run
CI / Miri (string_enum) (push) Waiting to run
CI / Miri (swc) (push) Waiting to run
CI / Miri (swc_bundler) (push) Waiting to run
CI / Miri (swc_ecma_codegen) (push) Waiting to run
CI / Miri (swc_ecma_minifier) (push) Waiting to run
CI / Done (push) Blocked by required conditions
Benchmark / Bench everything (push) Waiting to run
Some checks are pending
CI / Cargo fmt (push) Waiting to run
CI / Cargo clippy (push) Waiting to run
CI / Check license of dependencies (push) Waiting to run
CI / Check (macos-latest) (push) Waiting to run
CI / Check (ubuntu-latest) (push) Waiting to run
CI / Check (windows-latest) (push) Waiting to run
CI / Test wasm (binding_core_wasm) (push) Waiting to run
CI / Test wasm (binding_minifier_wasm) (push) Waiting to run
CI / Test wasm (binding_typescript_wasm) (push) Waiting to run
CI / List crates (push) Waiting to run
CI / Test - ${{ matrix.settings.crate }} - ${{ matrix.settings.os }} (push) Blocked by required conditions
CI / Test node bindings - ${{ matrix.os }} (macos-latest) (push) Waiting to run
CI / Test node bindings - ${{ matrix.os }} (windows-latest) (push) Waiting to run
CI / Test with @swc/cli (push) Waiting to run
CI / Miri (better_scoped_tls) (push) Waiting to run
CI / Miri (string_enum) (push) Waiting to run
CI / Miri (swc) (push) Waiting to run
CI / Miri (swc_bundler) (push) Waiting to run
CI / Miri (swc_ecma_codegen) (push) Waiting to run
CI / Miri (swc_ecma_minifier) (push) Waiting to run
CI / Done (push) Blocked by required conditions
Benchmark / Bench everything (push) Waiting to run
This commit is contained in:
parent
51d3f8dbb2
commit
27ca712812
6
.github/workflows/CI.yml
vendored
6
.github/workflows/CI.yml
vendored
@ -148,7 +148,7 @@ jobs:
|
||||
run: |
|
||||
echo '[patch.crates-io]' >> bindings/Cargo.toml
|
||||
./scripts/cargo/patch-section.sh >> bindings/Cargo.toml
|
||||
cd bindings && cargo update -p swc_core
|
||||
cd bindings && cargo update -p swc_core -p swc_fast_ts_strip
|
||||
|
||||
- name: Install wasm-pack
|
||||
run: curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh
|
||||
@ -367,7 +367,7 @@ jobs:
|
||||
echo '[patch.crates-io]' >> bindings/Cargo.toml
|
||||
./scripts/cargo/patch-section.sh
|
||||
./scripts/cargo/patch-section.sh >> bindings/Cargo.toml
|
||||
cd bindings && cargo update -p swc_core
|
||||
cd bindings && cargo update -p swc_core -p swc_fast_ts_strip
|
||||
|
||||
- name: Set platform name
|
||||
run: |
|
||||
@ -424,7 +424,7 @@ jobs:
|
||||
run: |
|
||||
echo '[patch.crates-io]' >> bindings/Cargo.toml
|
||||
./scripts/cargo/patch-section.sh >> bindings/Cargo.toml
|
||||
cd bindings && cargo update -p swc_core
|
||||
cd bindings && cargo update -p swc_core -p swc_fast_ts_strip
|
||||
|
||||
- name: Prepare
|
||||
run: |
|
||||
|
1
Cargo.lock
generated
1
Cargo.lock
generated
@ -5019,6 +5019,7 @@ dependencies = [
|
||||
"swc_ecma_transforms_typescript",
|
||||
"swc_ecma_visit",
|
||||
"testing",
|
||||
"wasm-bindgen",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -35,7 +35,7 @@ resolver = "2"
|
||||
tracing-chrome = "0.5.0"
|
||||
tracing-futures = "0.2.5"
|
||||
tracing-subscriber = "0.3.9"
|
||||
wasm-bindgen = "0.2.82"
|
||||
wasm-bindgen = "0.2.91"
|
||||
wasm-bindgen-futures = "0.4.41"
|
||||
|
||||
[profile.release]
|
||||
|
@ -22,7 +22,7 @@ serde-wasm-bindgen = { workspace = true }
|
||||
serde_json = { workspace = true }
|
||||
swc_common = { workspace = true }
|
||||
swc_error_reporters = { workspace = true }
|
||||
swc_fast_ts_strip = { workspace = true }
|
||||
swc_fast_ts_strip = { workspace = true, features = ["wasm-bindgen"] }
|
||||
tracing = { workspace = true, features = ["max_level_off"] }
|
||||
wasm-bindgen = { workspace = true, features = ["enable-interning"] }
|
||||
wasm-bindgen-futures = { workspace = true }
|
||||
|
@ -16,14 +16,18 @@ export function transform(src: string, opts?: Options): Promise<TransformOutput>
|
||||
export function transformSync(src: string, opts?: Options): TransformOutput;
|
||||
"#;
|
||||
|
||||
#[wasm_bindgen]
|
||||
#[wasm_bindgen(skip_typescript)]
|
||||
pub fn transform(input: JsString, options: JsValue) -> Promise {
|
||||
future_to_promise(async move { transform_sync(input, options) })
|
||||
}
|
||||
|
||||
#[wasm_bindgen(js_name = "transformSync")]
|
||||
#[wasm_bindgen(js_name = "transformSync", skip_typescript)]
|
||||
pub fn transform_sync(input: JsString, options: JsValue) -> Result<JsValue, JsValue> {
|
||||
let options: Options = serde_wasm_bindgen::from_value(options)?;
|
||||
let options: Options = if options.is_falsy() {
|
||||
Default::default()
|
||||
} else {
|
||||
serde_wasm_bindgen::from_value(options)?
|
||||
};
|
||||
|
||||
let input = input.as_string().unwrap();
|
||||
|
||||
|
@ -13,6 +13,8 @@ version = "0.4.1"
|
||||
[dependencies]
|
||||
anyhow = { workspace = true }
|
||||
serde = { workspace = true, features = ["derive"] }
|
||||
wasm-bindgen = { workspace = true, optional = true }
|
||||
|
||||
swc_allocator = { version = "0.1.7", path = "../swc_allocator", default-features = false }
|
||||
|
||||
swc_common = { version = "0.36.0", path = "../swc_common", features = [
|
||||
|
@ -31,6 +31,8 @@ use swc_ecma_transforms_base::{
|
||||
};
|
||||
use swc_ecma_transforms_typescript::typescript;
|
||||
use swc_ecma_visit::{Visit, VisitMutWith, VisitWith};
|
||||
#[cfg(feature = "wasm-bindgen")]
|
||||
use wasm_bindgen::prelude::*;
|
||||
|
||||
#[derive(Default, Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
@ -53,6 +55,17 @@ pub struct Options {
|
||||
pub source_map: bool,
|
||||
}
|
||||
|
||||
#[cfg(feature = "wasm-bindgen")]
|
||||
#[wasm_bindgen(typescript_custom_section)]
|
||||
const Type_Options: &'static str = r#"
|
||||
interface Options {
|
||||
module?: boolean;
|
||||
filename?: string;
|
||||
mode?: Mode;
|
||||
sourceMap?: boolean;
|
||||
}
|
||||
"#;
|
||||
|
||||
#[derive(Debug, Default, Deserialize)]
|
||||
#[serde(rename_all = "kebab-case")]
|
||||
pub enum Mode {
|
||||
@ -61,6 +74,12 @@ pub enum Mode {
|
||||
Transform,
|
||||
}
|
||||
|
||||
#[cfg(feature = "wasm-bindgen")]
|
||||
#[wasm_bindgen(typescript_custom_section)]
|
||||
const Type_Mode: &'static str = r#"
|
||||
type Mode = "strip-only" | "transform";
|
||||
"#;
|
||||
|
||||
fn default_ts_syntax() -> TsSyntax {
|
||||
TsSyntax {
|
||||
decorators: true,
|
||||
@ -74,6 +93,15 @@ pub struct TransformOutput {
|
||||
pub map: Option<String>,
|
||||
}
|
||||
|
||||
#[cfg(feature = "wasm-bindgen")]
|
||||
#[wasm_bindgen(typescript_custom_section)]
|
||||
const Type_TransformOutput: &'static str = r#"
|
||||
interface TransformOutput {
|
||||
code: string;
|
||||
map?: string;
|
||||
}
|
||||
"#;
|
||||
|
||||
pub fn operate(
|
||||
cm: &Lrc<SourceMap>,
|
||||
handler: &Handler,
|
||||
|
Loading…
Reference in New Issue
Block a user