Skip to content
This repository was archived by the owner on Jul 6, 2025. It is now read-only.

Commit 8699ed8

Browse files
committed
Remove swc compat transforms
1 parent 607575f commit 8699ed8

File tree

4 files changed

+17
-49
lines changed

4 files changed

+17
-49
lines changed

compiler/mod.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ export type ReactResolve = {
2727

2828
export type SWCOptions = {
2929
sourceType?: SourceType
30-
target?: 'es2015' | 'es2016' | 'es2017' | 'es2018' | 'es2019' | 'es2020'
3130
jsxFactory?: string
3231
jsxFragmentFactory?: string
3332
}
@@ -39,7 +38,6 @@ export type TransformOptions = {
3938
swcOptions?: SWCOptions
4039
sourceMap?: boolean
4140
isDev?: boolean
42-
transpileOnly?: boolean
4341
bundleMode?: boolean
4442
bundleExternal?: string[]
4543
inlineStylePreprocess?(key: string, type: string, tpl: string): Promise<string>

compiler/src/lib.rs

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ use source_type::SourceType;
1717
use std::collections::HashMap;
1818
use std::{cell::RefCell, rc::Rc};
1919
use swc::{EmitOptions, SWC};
20-
use swc_ecmascript::parser::JscTarget;
2120
use wasm_bindgen::prelude::{wasm_bindgen, JsValue};
2221

2322
#[derive(Deserialize)]
@@ -41,9 +40,6 @@ pub struct Options {
4140
#[serde(default)]
4241
pub is_dev: bool,
4342

44-
#[serde(default)]
45-
pub transpile_only: bool,
46-
4743
#[serde(default)]
4844
pub bundle_mode: bool,
4945

@@ -57,9 +53,6 @@ pub struct SWCOptions {
5753
#[serde(default)]
5854
pub source_type: SourceType,
5955

60-
#[serde(default = "default_target")]
61-
pub target: JscTarget,
62-
6356
#[serde(default = "default_pragma")]
6457
pub jsx_factory: String,
6558

@@ -71,17 +64,12 @@ impl Default for SWCOptions {
7164
fn default() -> Self {
7265
SWCOptions {
7366
source_type: SourceType::default(),
74-
target: default_target(),
7567
jsx_factory: default_pragma(),
7668
jsx_fragment_factory: default_pragma_frag(),
7769
}
7870
}
7971
}
8072

81-
fn default_target() -> JscTarget {
82-
JscTarget::Es2020
83-
}
84-
8573
fn default_pragma() -> String {
8674
"React.createElement".into()
8775
}
@@ -143,12 +131,10 @@ pub fn transform_sync(url: &str, code: &str, options: JsValue) -> Result<JsValue
143131
.transform(
144132
resolver.clone(),
145133
&EmitOptions {
146-
target: options.swc_options.target,
147134
jsx_factory: options.swc_options.jsx_factory.clone(),
148135
jsx_fragment_factory: options.swc_options.jsx_fragment_factory.clone(),
149136
source_map: options.source_map,
150137
is_dev: options.is_dev,
151-
transpile_only: options.transpile_only,
152138
},
153139
)
154140
.expect("could not transform module");

compiler/src/resolve_fold.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,10 @@ impl Fold for ResolveFold {
229229
}))
230230
} else {
231231
if self.resolve_star_exports {
232-
let mut src = fixed_url.to_owned();
232+
let mut src = "".to_owned();
233+
src.push('[');
234+
src.push_str(fixed_url.as_str());
235+
src.push(']');
233236
src.push(':');
234237
src.push_str(resolved_path.as_str());
235238
resolver.star_exports.push(fixed_url.clone());
@@ -624,7 +627,7 @@ mod tests {
624627
assert!(code.contains("import Logo3 from \"../component/logo.js#/component/logo.tsx@000000\""));
625628
assert!(code.contains("const AsyncLogo = React.lazy(()=>import(\"../components/async-logo.js#/components/async-logo.tsx@000000\")"));
626629
assert!(code.contains("export { useState } from \"../-/esm.sh/[email protected]\""));
627-
assert!(code.contains("export * from \"../-/esm.sh/swr.js\""));
630+
assert!(code.contains("export * from \"[https://esm.sh/swr]:../-/esm.sh/swr.js\""));
628631
}
629632

630633
#[test]

compiler/src/swc.rs

Lines changed: 12 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ use swc_common::{
1313
errors::{Handler, HandlerFlags},
1414
FileName, Globals, SourceMap,
1515
};
16-
use swc_ecma_transforms_compat::{es2016, es2017, es2018, es2020};
1716
use swc_ecma_transforms_proposal::decorators;
1817
use swc_ecma_transforms_typescript::strip;
1918
use swc_ecmascript::{
@@ -27,22 +26,18 @@ use swc_ecmascript::{
2726
/// Options for transpiling a module.
2827
#[derive(Debug, Clone)]
2928
pub struct EmitOptions {
30-
pub target: JscTarget,
3129
pub jsx_factory: String,
3230
pub jsx_fragment_factory: String,
33-
pub is_dev: bool,
34-
pub transpile_only: bool,
3531
pub source_map: bool,
32+
pub is_dev: bool,
3633
}
3734

3835
impl Default for EmitOptions {
3936
fn default() -> Self {
4037
EmitOptions {
41-
target: JscTarget::Es2020,
4238
jsx_factory: "React.createElement".into(),
4339
jsx_fragment_factory: "React.Fragment".into(),
4440
is_dev: false,
45-
transpile_only: false,
4641
source_map: false,
4742
}
4843
}
@@ -130,7 +125,6 @@ impl SWC {
130125
) -> Result<(String, Option<String>), anyhow::Error> {
131126
swc_common::GLOBALS.set(&Globals::new(), || {
132127
let specifier_is_remote = resolver.borrow().specifier_is_remote;
133-
let transpile_only = options.transpile_only;
134128
let is_ts = match self.source_type {
135129
SourceType::TS => true,
136130
SourceType::TSX => true,
@@ -144,20 +138,17 @@ impl SWC {
144138
let (aleph_jsx_fold, aleph_jsx_builtin_resolve_fold) =
145139
aleph_jsx_fold(resolver.clone(), self.source_map.clone(), options.is_dev);
146140
let mut passes = chain!(
147-
Optional::new(
148-
resolve_fold(resolver.clone(), self.source_map.clone(), !options.is_dev,),
149-
!transpile_only
150-
),
151-
Optional::new(aleph_jsx_fold, is_jsx && !transpile_only),
152-
Optional::new(aleph_jsx_builtin_resolve_fold, is_jsx && !transpile_only),
141+
resolve_fold(resolver.clone(), self.source_map.clone(), !options.is_dev),
142+
Optional::new(aleph_jsx_fold, is_jsx),
143+
Optional::new(aleph_jsx_builtin_resolve_fold, is_jsx),
153144
Optional::new(
154145
react_refresh_fold(
155146
"$RefreshReg$",
156147
"$RefreshSig$",
157148
false,
158149
self.source_map.clone()
159150
),
160-
options.is_dev && !specifier_is_remote && !transpile_only
151+
options.is_dev && !specifier_is_remote
161152
),
162153
Optional::new(
163154
react::jsx(
@@ -171,26 +162,16 @@ impl SWC {
171162
..Default::default()
172163
},
173164
),
174-
is_jsx && !transpile_only
175-
),
176-
Optional::new(
177-
decorators::decorators(decorators::Config {
178-
legacy: true,
179-
emit_metadata: false
180-
}),
181-
!transpile_only
165+
is_jsx
182166
),
167+
decorators::decorators(decorators::Config {
168+
legacy: true,
169+
emit_metadata: false
170+
}),
171+
helpers::inject_helpers(),
183172
Optional::new(strip(), is_ts),
184-
Optional::new(es2020(), options.target < JscTarget::Es2020),
185-
Optional::new(es2018(), options.target < JscTarget::Es2018),
186-
Optional::new(es2017(), options.target < JscTarget::Es2017),
187-
Optional::new(es2016(), options.target < JscTarget::Es2016),
188-
Optional::new(
189-
helpers::inject_helpers(),
190-
options.target < JscTarget::Es2020
191-
),
192-
Optional::new(hygiene(), options.target < JscTarget::Es2020),
193173
fixer(Some(&self.comments)),
174+
hygiene()
194175
);
195176

196177
self.apply_transform(&mut passes, options.source_map)

0 commit comments

Comments
 (0)