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

Commit 99b7b2f

Browse files
committed
Revert "Bring jsx magic back"
This reverts commit 27167e1.
1 parent 8b125a1 commit 99b7b2f

File tree

7 files changed

+72
-321
lines changed

7 files changed

+72
-321
lines changed

compiler/src/jsx_magic.rs

Lines changed: 0 additions & 166 deletions
This file was deleted.

compiler/src/lib.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ mod css;
55
mod error;
66
mod export_names;
77
mod hmr;
8-
mod jsx_magic;
98
mod resolve_fold;
109
mod resolver;
1110
mod swc;
@@ -59,9 +58,6 @@ pub struct Options {
5958
#[serde(default)]
6059
pub jsx_import_source: Option<String>,
6160

62-
#[serde(default)]
63-
pub jsx_magic: bool,
64-
6561
#[serde(default)]
6662
pub strip_data_export: bool,
6763
}
@@ -167,7 +163,6 @@ pub fn transform(specifier: &str, code: &str, options: JsValue) -> Result<JsValu
167163
resolver.clone(),
168164
&EmitOptions {
169165
strip_data_export: options.strip_data_export,
170-
jsx_magic: options.jsx_magic,
171166
jsx_import_source: options.jsx_import_source,
172167
minify: !options.is_dev,
173168
source_map: options.is_dev,

compiler/src/resolve_fold.rs

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ use crate::swc_helpers::{is_call_expr_by_name, new_str};
33
use std::{cell::RefCell, rc::Rc};
44
use swc_common::{Span, DUMMY_SP};
55
use swc_ecmascript::ast::*;
6-
use swc_ecmascript::utils::quote_ident;
76
use swc_ecmascript::visit::{noop_fold_type, Fold, FoldWith};
87

98
pub fn resolve_fold(
@@ -30,34 +29,6 @@ impl Fold for ResolveFold {
3029
// fold&resolve import/export url
3130
fn fold_module_items(&mut self, module_items: Vec<ModuleItem>) -> Vec<ModuleItem> {
3231
let mut items = Vec::<ModuleItem>::new();
33-
let jsx_magic_tags = self.resolver.borrow().jsx_magic_tags.to_owned();
34-
let jsx_runtime = self.resolver.borrow().jsx_runtime.to_owned();
35-
36-
if jsx_magic_tags.len() > 0 {
37-
if let Some(jsx_runtime) = jsx_runtime {
38-
let mut resolver = self.resolver.borrow_mut();
39-
let url = format!("{}/framework/{}/mod.ts", resolver.aleph_pkg_uri, jsx_runtime);
40-
let src = resolver.resolve(&url, false, None);
41-
// import { $TAG as __ALEPH_$TAG } from "$aleph_pkg_uri/framework/$framework/mod.ts"
42-
items.push(ModuleItem::ModuleDecl(ModuleDecl::Import(ImportDecl {
43-
span: DUMMY_SP,
44-
specifiers: jsx_magic_tags
45-
.into_iter()
46-
.map(|tag| {
47-
ImportSpecifier::Named(ImportNamedSpecifier {
48-
span: DUMMY_SP,
49-
local: quote_ident!(format!("__ALEPH__{}", tag)),
50-
imported: Some(ModuleExportName::Ident(quote_ident!(tag.as_str()))),
51-
is_type_only: false,
52-
})
53-
})
54-
.collect(),
55-
src: new_str(&src),
56-
type_only: false,
57-
asserts: None,
58-
})));
59-
}
60-
}
6132

6233
for item in module_items {
6334
match item {

compiler/src/resolver.rs

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
use import_map::ImportMap;
2-
use indexmap::IndexSet;
32
use path_slash::PathBufExt;
43
use pathdiff::diff_paths;
54
use regex::Regex;
@@ -13,7 +12,7 @@ use url::Url;
1312
lazy_static! {
1413
pub static ref RE_REACT_URL: Regex =
1514
Regex::new(r"^https?://(esm\.sh|cdn\.esm\.sh)(/v\d+)?/react(\-dom)?(@[^/]+)?(/.*)?$").unwrap();
16-
pub static ref RE_PROTOCOL_URL: Regex = Regex::new(r"^(data:|mailto:|[a-z]+://)").unwrap();
15+
pub static ref RE_PROTOCOL_URL: Regex = Regex::new(r"^(mailto:|[a-z]+://)").unwrap();
1716
}
1817

1918
#[derive(Clone, Debug, Eq, PartialEq, Serialize)]
@@ -39,17 +38,23 @@ pub struct Resolver {
3938
pub deps: Vec<DependencyDescriptor>,
4039
/// jsx runtime: react | preact
4140
pub jsx_runtime: Option<String>,
42-
/// resolved jsx magic tags: `Head`, 'Anchor'
43-
pub jsx_magic_tags: IndexSet<String>,
4441
/// development mode
4542
pub is_dev: bool,
4643
// internal
4744
import_map: ImportMap,
45+
resolve_remote_deps: bool,
46+
jsx_runtime_version: Option<String>,
47+
jsx_runtime_cdn_version: Option<String>,
4848
graph_versions: HashMap<String, String>,
4949
initial_graph_version: Option<String>,
50-
jsx_runtime_cdn_version: Option<String>,
51-
jsx_runtime_version: Option<String>,
52-
resolve_remote_deps: bool,
50+
}
51+
52+
#[derive(Clone, Debug, Eq, PartialEq, Serialize)]
53+
#[serde(rename_all = "camelCase")]
54+
pub struct InlineStyle {
55+
pub r#type: String,
56+
pub quasis: Vec<String>,
57+
pub exprs: Vec<String>,
5358
}
5459

5560
impl Resolver {
@@ -70,7 +75,6 @@ impl Resolver {
7075
specifier: specifier.into(),
7176
specifier_is_remote: is_http_url(specifier),
7277
deps: Vec::new(),
73-
jsx_magic_tags: IndexSet::new(),
7478
jsx_runtime,
7579
jsx_runtime_version,
7680
jsx_runtime_cdn_version,

compiler/src/swc.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
use crate::error::{DiagnosticBuffer, ErrorBuffer};
22
use crate::export_names::ExportParser;
33
use crate::hmr::hmr;
4-
use crate::jsx_magic::jsx_magic_fold;
54
use crate::resolve_fold::resolve_fold;
65
use crate::resolver::{DependencyDescriptor, Resolver};
76

@@ -24,7 +23,6 @@ use swc_ecmascript::visit::{Fold, FoldWith};
2423
#[derive(Debug, Clone)]
2524
pub struct EmitOptions {
2625
pub jsx_import_source: Option<String>,
27-
pub jsx_magic: bool,
2826
pub strip_data_export: bool,
2927
pub minify: bool,
3028
pub source_map: bool,
@@ -34,7 +32,6 @@ impl Default for EmitOptions {
3432
fn default() -> Self {
3533
EmitOptions {
3634
jsx_import_source: None,
37-
jsx_magic: false,
3835
strip_data_export: false,
3936
minify: false,
4037
source_map: false,
@@ -155,7 +152,6 @@ impl SWC {
155152
};
156153
let passes = chain!(
157154
swc_ecma_transforms::resolver(unresolved_mark, top_level_mark, is_ts),
158-
Optional::new(jsx_magic_fold(resolver.clone()), options.jsx_magic),
159155
Optional::new(react::jsx_src(is_dev, self.source_map.clone()), is_jsx),
160156
resolve_fold(resolver.clone(), options.strip_data_export, false),
161157
decorators::decorators(decorators::Config {
@@ -205,7 +201,7 @@ impl SWC {
205201
Optional::new(hmr(resolver.clone()), is_dev && !specifier_is_remote),
206202
fixer(Some(&self.comments)),
207203
hygiene()
208-
);
204+
);
209205

210206
let (code, map) = self.emit(passes, options.source_map, options.minify).unwrap();
211207

0 commit comments

Comments
 (0)