Skip to content

Commit a99a9ec

Browse files
kdy1magic-akari
andauthored
refactor(es/ast): Cherry-pick #10763 (#11060)
**Description:** Cherry pick e39a909 from #10739 because we are going to make a Wasm-breaking change anyway --------- Co-authored-by: magic-akari <[email protected]>
1 parent 6dd6f9c commit a99a9ec

File tree

16 files changed

+48
-67
lines changed

16 files changed

+48
-67
lines changed

bindings/binding_core_wasm/src/types.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1725,7 +1725,7 @@ export interface JSXAttribute extends Node, HasSpan {
17251725
export type JSXAttributeName = Identifier | JSXNamespacedName;
17261726
17271727
export type JSXAttrValue =
1728-
| Literal
1728+
| StringLiteral
17291729
| JSXExpressionContainer
17301730
| JSXElement
17311731
| JSXFragment;

bindings/binding_minifier_wasm/src/types.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1726,7 +1726,7 @@ export interface JSXAttribute extends Node, HasSpan {
17261726
export type JSXAttributeName = Identifier | JSXNamespacedName;
17271727
17281728
export type JSXAttrValue =
1729-
| Literal
1729+
| StringLiteral
17301730
| JSXExpressionContainer
17311731
| JSXElement
17321732
| JSXFragment;

crates/swc_ecma_ast/src/jsx.rs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,8 @@ use swc_common::{ast_node, util::take::Take, EqIgnoreSpan, Span, DUMMY_SP};
55
use crate::{
66
expr::{Expr, SpreadElement},
77
ident::Ident,
8-
lit::Lit,
98
typescript::TsTypeParamInstantiation,
10-
IdentName,
9+
IdentName, Str,
1110
};
1211

1312
/// Used for `obj` property of `JSXMemberExpr`.
@@ -190,12 +189,7 @@ pub enum JSXAttrName {
190189
#[cfg_attr(feature = "shrink-to-fit", derive(shrink_to_fit::ShrinkToFit))]
191190
pub enum JSXAttrValue {
192191
#[tag("StringLiteral")]
193-
#[tag("BooleanLiteral")]
194-
#[tag("NullLiteral")]
195-
#[tag("NumericLiteral")]
196-
#[tag("RegExpLiteral")]
197-
#[tag("JSXText")]
198-
Lit(Lit),
192+
Str(Str),
199193

200194
#[tag("JSXExpressionContainer")]
201195
JSXExprContainer(JSXExprContainer),

crates/swc_ecma_ast/src/lib.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -588,10 +588,13 @@ mod rkyv_layout_assert {
588588
assert_size!(ArchivedPrivateName, 16);
589589

590590
// JSX types
591-
assert_size!(ArchivedJSXAttr, 112);
591+
assert_size!(ArchivedJSXAttr, 92);
592592
assert_size!(ArchivedJSXAttrName, 44);
593-
assert_size!(ArchivedJSXAttrOrSpread, 120);
594-
assert_size!(ArchivedJSXAttrValue, 48);
593+
assert_size!(ArchivedJSXAttrOrSpread, 96);
594+
assert_size!(ArchivedJSXAttrValue, 36);
595+
assert_size!(ArchivedJSXClosingElement, 68);
596+
assert_size!(ArchivedJSXAttrOrSpread, 96);
597+
assert_size!(ArchivedJSXAttrValue, 36);
595598
assert_size!(ArchivedJSXClosingElement, 68);
596599
assert_size!(ArchivedJSXClosingFragment, 8);
597600
assert_size!(ArchivedJSXElement, 176);

crates/swc_ecma_codegen/src/jsx.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ impl MacroNode for JSXAttr {
8585
impl MacroNode for JSXAttrValue {
8686
fn emit(&mut self, emitter: &mut Macro) -> Result {
8787
match *self {
88-
JSXAttrValue::Lit(ref n) => emit!(n),
88+
JSXAttrValue::Str(ref n) => emit!(n),
8989
JSXAttrValue::JSXExprContainer(ref n) => emit!(n),
9090
JSXAttrValue::JSXElement(ref n) => emit!(n),
9191
JSXAttrValue::JSXFragment(ref n) => emit!(n),

crates/swc_ecma_lexer/src/common/parser/jsx.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ fn parse_jsx_attr_value<'a, P: Parser<'a>>(p: &mut P) -> PResult<JSXAttrValue> {
166166
let node = parse_jsx_expr_container(p)?;
167167
jsx_expr_container_to_jsx_attr_value(p, start, node)
168168
} else if cur.is_str() {
169-
Ok(JSXAttrValue::Lit(Lit::Str(parse_str_lit(p))))
169+
Ok(JSXAttrValue::Str(parse_str_lit(p)))
170170
} else if cur.is_jsx_tag_start() {
171171
let expr = parse_jsx_element(p)?;
172172
match expr {

crates/swc_ecma_parser/src/parser/jsx/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ impl<I: Tokens> Parser<I> {
252252
match cur.token {
253253
Token::Str => {
254254
let value = parse_str_lit(self);
255-
Ok(Some(JSXAttrValue::Lit(Lit::Str(value))))
255+
Ok(Some(JSXAttrValue::Str(value)))
256256
}
257257
Token::LBrace => {
258258
let start = self.cur_pos();
@@ -501,11 +501,11 @@ mod tests {
501501
attrs: vec![JSXAttrOrSpread::JSXAttr(JSXAttr {
502502
span,
503503
name: JSXAttrName::Ident(IdentName::new(atom!("id"), span)),
504-
value: Some(JSXAttrValue::Lit(Lit::Str(Str {
504+
value: Some(JSXAttrValue::Str(Str {
505505
span,
506506
value: atom!("w < w"),
507507
raw: Some(atom!("\"w &lt; w\"")),
508-
}))),
508+
})),
509509
})],
510510
name: JSXElementName::Ident(Ident::new_no_ctxt(atom!("div"), span)),
511511
self_closing: true,

crates/swc_ecma_parser/tests/typescript/issue-10993/input.ts.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
"end": 18
5151
},
5252
"ctxt": 0,
53+
"nodeId": 4294967295,
5354
"value": "Foo",
5455
"optional": false,
5556
"typeAnnotation": {
@@ -71,6 +72,7 @@
7172
"end": 21
7273
},
7374
"ctxt": 0,
75+
"nodeId": 4294967295,
7476
"value": "T",
7577
"optional": false
7678
},
@@ -108,6 +110,7 @@
108110
"end": 24
109111
},
110112
"ctxt": 0,
113+
"nodeId": 4294967295,
111114
"value": "S",
112115
"optional": false
113116
},

crates/swc_ecma_quote_macros/src/ast/expr.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ impl_struct!(JSXAttr, [span, name, value]);
145145

146146
impl_enum!(
147147
JSXAttrValue,
148-
[Lit, JSXExprContainer, JSXElement, JSXFragment]
148+
[Str, JSXExprContainer, JSXElement, JSXFragment]
149149
);
150150

151151
impl_enum!(JSXAttrName, [Ident, JSXNamespacedName]);

crates/swc_ecma_transforms_react/src/jsx/mod.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1005,14 +1005,14 @@ where
10051005
let value = a
10061006
.value
10071007
.map(|v| match v {
1008-
JSXAttrValue::Lit(Lit::Str(s)) => {
1008+
JSXAttrValue::Str(s) => {
10091009
let value = transform_jsx_attr_str(&s.value);
10101010

1011-
Lit::Str(Str {
1011+
Str {
10121012
span: s.span,
10131013
raw: None,
10141014
value: value.into(),
1015-
})
1015+
}
10161016
.into()
10171017
}
10181018
JSXAttrValue::JSXExprContainer(JSXExprContainer {
@@ -1021,7 +1021,6 @@ where
10211021
}) => e,
10221022
JSXAttrValue::JSXElement(element) => Box::new(self.jsx_elem_to_expr(*element)),
10231023
JSXAttrValue::JSXFragment(fragment) => Box::new(self.jsx_frag_to_expr(fragment)),
1024-
JSXAttrValue::Lit(lit) => Box::new(lit.into()),
10251024
JSXAttrValue::JSXExprContainer(JSXExprContainer {
10261025
span: _,
10271026
expr: JSXExpr::JSXEmptyExpr(_),
@@ -1481,7 +1480,7 @@ fn add_line_of_jsx_text<'a>(
14811480

14821481
fn jsx_attr_value_to_expr(v: JSXAttrValue) -> Option<Box<Expr>> {
14831482
Some(match v {
1484-
JSXAttrValue::Lit(Lit::Str(s)) => {
1483+
JSXAttrValue::Str(s) => {
14851484
let value = transform_jsx_attr_str(&s.value);
14861485

14871486
Lit::Str(Str {
@@ -1491,7 +1490,6 @@ fn jsx_attr_value_to_expr(v: JSXAttrValue) -> Option<Box<Expr>> {
14911490
})
14921491
.into()
14931492
}
1494-
JSXAttrValue::Lit(lit) => Box::new(lit.into()),
14951493
JSXAttrValue::JSXExprContainer(e) => match e.expr {
14961494
JSXExpr::JSXEmptyExpr(_) => None?,
14971495
JSXExpr::Expr(e) => e,

0 commit comments

Comments
 (0)