Skip to content

Commit dfee5f8

Browse files
authored
refactor(es/typescript): Extract type annotation proposal out (#9127)
**Description:** The Node.js team wants a Wasm package that only implements type annotation proposals. So, we need to refactor our TypeScript transform to allow it. **Related issue:** - nodejs/loaders#208 (comment)
1 parent eda493c commit dfee5f8

File tree

3 files changed

+16
-13
lines changed

3 files changed

+16
-13
lines changed

bindings/binding_typescript_wasm/src/lib.rs

+11-12
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,14 @@ use swc_core::{
1111
parser::{
1212
parse_file_as_module, parse_file_as_program, parse_file_as_script, Syntax, TsSyntax,
1313
},
14-
transforms::base::{
15-
fixer::fixer,
16-
helpers::{inject_helpers, Helpers, HELPERS},
17-
hygiene::hygiene,
18-
resolver,
14+
transforms::{
15+
base::{
16+
fixer::fixer,
17+
helpers::{inject_helpers, Helpers, HELPERS},
18+
hygiene::hygiene,
19+
resolver,
20+
},
21+
typescript::strip_type,
1922
},
2023
visit::VisitMutWith,
2124
},
@@ -52,9 +55,8 @@ pub struct Options {
5255
#[serde(default)]
5356
pub source_maps: bool,
5457

55-
#[serde(default)]
56-
pub transform: swc_core::ecma::transforms::typescript::Config,
57-
58+
// #[serde(default)]
59+
// pub transform: swc_core::ecma::transforms::typescript::Config,
5860
#[serde(default)]
5961
pub codegen: swc_core::ecma::codegen::Config,
6062
}
@@ -148,10 +150,7 @@ fn operate(input: String, options: Options) -> Result<TransformOutput, Error> {
148150

149151
// Strip typescript types
150152

151-
program.visit_mut_with(&mut swc_core::ecma::transforms::typescript::typescript(
152-
options.transform,
153-
top_level_mark,
154-
));
153+
program.visit_mut_with(&mut strip_type());
155154

156155
// Apply external helpers
157156

crates/swc_ecma_transforms_typescript/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#![allow(clippy::vec_box)]
33
#![allow(clippy::mutable_key_type)]
44

5-
pub use self::typescript::*;
5+
pub use self::{strip_type::*, typescript::*};
66
mod config;
77
mod macros;
88
mod strip_import_export;

crates/swc_ecma_transforms_typescript/src/strip_type.rs

+4
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ use swc_ecma_visit::{VisitMut, VisitMutWith};
55

66
use crate::{type_to_none, unreachable_visit_mut_type};
77

8+
pub fn strip_type() -> impl VisitMut {
9+
StripType::default()
10+
}
11+
812
/// This Module will strip all types/generics/interface/declares
913
/// and type import/export
1014
#[derive(Default)]

0 commit comments

Comments
 (0)