Skip to content

Commit b7d0bcd

Browse files
authored
refactor(es/ast): Replace Literal with StringLiteral in JSXAttrValue type (#10763)
**Related issue:** - Closes #10584
1 parent f36341a commit b7d0bcd

File tree

14 files changed

+36
-62
lines changed

14 files changed

+36
-62
lines changed

bindings/binding_core_wasm/src/types.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1727,7 +1727,7 @@ export interface JSXAttribute extends Node, HasSpan {
17271727
export type JSXAttributeName = Identifier | JSXNamespacedName;
17281728
17291729
export type JSXAttrValue =
1730-
| Literal
1730+
| StringLiteral
17311731
| JSXExpressionContainer
17321732
| JSXElement
17331733
| 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_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
@@ -169,7 +169,7 @@ fn parse_jsx_attr_value<'a, P: Parser<'a>>(p: &mut P) -> PResult<JSXAttrValue> {
169169
let node = parse_jsx_expr_container(p)?;
170170
jsx_expr_container_to_jsx_attr_value(p, start, node)
171171
} else if cur.is_str() {
172-
Ok(JSXAttrValue::Lit(Lit::Str(parse_str_lit(p))))
172+
Ok(JSXAttrValue::Str(parse_str_lit(p)))
173173
} else if cur.is_jsx_tag_start() {
174174
let expr = parse_jsx_element(p)?;
175175
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
@@ -241,7 +241,7 @@ impl<I: Tokens> Parser<I> {
241241
match cur.token {
242242
Token::Str => {
243243
let value = parse_str_lit(self);
244-
Ok(Some(JSXAttrValue::Lit(Lit::Str(value))))
244+
Ok(Some(JSXAttrValue::Str(value)))
245245
}
246246
Token::LBrace => {
247247
let start = self.cur_pos();
@@ -498,11 +498,11 @@ mod tests {
498498
attrs: vec![JSXAttrOrSpread::JSXAttr(JSXAttr {
499499
span,
500500
name: JSXAttrName::Ident(IdentName::new(atom!("id"), span)),
501-
value: Some(JSXAttrValue::Lit(Lit::Str(Str {
501+
value: Some(JSXAttrValue::Str(Str {
502502
span,
503503
value: atom!("w < w"),
504504
raw: Some(atom!("\"w &lt; w\"")),
505-
}))),
505+
})),
506506
})],
507507
name: JSXElementName::Ident(Ident::new_no_ctxt(atom!("div"), span)),
508508
self_closing: true,

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/automatic.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -639,7 +639,7 @@ fn add_require(imports: Vec<(Ident, IdentName)>, src: &str, unresolved_mark: Mar
639639

640640
fn jsx_attr_value_to_expr(v: JSXAttrValue) -> Option<Box<Expr>> {
641641
Some(match v {
642-
JSXAttrValue::Lit(Lit::Str(s)) => {
642+
JSXAttrValue::Str(s) => {
643643
let value = transform_jsx_attr_str(&s.value);
644644

645645
Lit::Str(Str {
@@ -649,7 +649,6 @@ fn jsx_attr_value_to_expr(v: JSXAttrValue) -> Option<Box<Expr>> {
649649
})
650650
.into()
651651
}
652-
JSXAttrValue::Lit(lit) => Box::new(lit.into()),
653652
JSXAttrValue::JSXExprContainer(e) => match e.expr {
654653
JSXExpr::JSXEmptyExpr(_) => None?,
655654
JSXExpr::Expr(e) => e,

crates/swc_ecma_transforms_react/src/jsx/classic.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ impl Classic {
274274
let value = a
275275
.value
276276
.map(|v| match v {
277-
JSXAttrValue::Lit(Lit::Str(s)) => {
277+
JSXAttrValue::Str(s) => {
278278
let value = transform_jsx_attr_str(&s.value);
279279

280280
Lit::Str(Str {
@@ -290,7 +290,6 @@ impl Classic {
290290
}) => e,
291291
JSXAttrValue::JSXElement(element) => Box::new(self.jsx_elem_to_expr(*element)),
292292
JSXAttrValue::JSXFragment(fragment) => Box::new(self.jsx_frag_to_expr(fragment)),
293-
JSXAttrValue::Lit(lit) => Box::new(lit.into()),
294293
JSXAttrValue::JSXExprContainer(JSXExprContainer {
295294
span: _,
296295
expr: JSXExpr::JSXEmptyExpr(_),

crates/swc_ecma_visit/src/generated.rs

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -11669,8 +11669,8 @@ impl<V: ?Sized + Visit> VisitWith<V> for JSXAttrValue {
1166911669

1167011670
fn visit_children_with(&self, visitor: &mut V) {
1167111671
match self {
11672-
JSXAttrValue::Lit { 0: _field_0 } => {
11673-
<Lit as VisitWith<V>>::visit_with(_field_0, visitor);
11672+
JSXAttrValue::Str { 0: _field_0 } => {
11673+
<Str as VisitWith<V>>::visit_with(_field_0, visitor);
1167411674
}
1167511675
JSXAttrValue::JSXExprContainer { 0: _field_0 } => {
1167611676
<JSXExprContainer as VisitWith<V>>::visit_with(_field_0, visitor);
@@ -37656,12 +37656,12 @@ impl<V: ?Sized + VisitAstPath> VisitWithAstPath<V> for JSXAttrValue {
3765637656
__ast_path: &mut AstNodePath<'r>,
3765737657
) {
3765837658
match self {
37659-
JSXAttrValue::Lit { 0: _field_0 } => {
37659+
JSXAttrValue::Str { 0: _field_0 } => {
3766037660
let mut __ast_path = __ast_path.with_guard(AstParentNodeRef::JSXAttrValue(
3766137661
self,
37662-
self::fields::JSXAttrValueField::Lit,
37662+
self::fields::JSXAttrValueField::Str,
3766337663
));
37664-
<Lit as VisitWithAstPath<V>>::visit_with_ast_path(
37664+
<Str as VisitWithAstPath<V>>::visit_with_ast_path(
3766537665
_field_0,
3766637666
visitor,
3766737667
&mut *__ast_path,
@@ -60607,8 +60607,8 @@ impl<V: ?Sized + VisitMut> VisitMutWith<V> for JSXAttrValue {
6060760607

6060860608
fn visit_mut_children_with(&mut self, visitor: &mut V) {
6060960609
match self {
60610-
JSXAttrValue::Lit { 0: _field_0 } => {
60611-
<Lit as VisitMutWith<V>>::visit_mut_with(_field_0, visitor);
60610+
JSXAttrValue::Str { 0: _field_0 } => {
60611+
<Str as VisitMutWith<V>>::visit_mut_with(_field_0, visitor);
6061260612
}
6061360613
JSXAttrValue::JSXExprContainer { 0: _field_0 } => {
6061460614
<JSXExprContainer as VisitMutWith<V>>::visit_mut_with(_field_0, visitor);
@@ -83159,11 +83159,11 @@ impl<V: ?Sized + VisitMutAstPath> VisitMutWithAstPath<V> for JSXAttrValue {
8315983159

8316083160
fn visit_mut_children_with_ast_path(&mut self, visitor: &mut V, __ast_path: &mut AstKindPath) {
8316183161
match self {
83162-
JSXAttrValue::Lit { 0: _field_0 } => {
83162+
JSXAttrValue::Str { 0: _field_0 } => {
8316383163
let mut __ast_path = __ast_path.with_guard(AstParentKind::JSXAttrValue(
83164-
self::fields::JSXAttrValueField::Lit,
83164+
self::fields::JSXAttrValueField::Str,
8316583165
));
83166-
<Lit as VisitMutWithAstPath<V>>::visit_mut_with_ast_path(
83166+
<Str as VisitMutWithAstPath<V>>::visit_mut_with_ast_path(
8316783167
_field_0,
8316883168
visitor,
8316983169
&mut *__ast_path,
@@ -103887,9 +103887,9 @@ impl<V: ?Sized + Fold> FoldWith<V> for JSXAttrValue {
103887103887

103888103888
fn fold_children_with(self, visitor: &mut V) -> Self {
103889103889
match self {
103890-
JSXAttrValue::Lit { 0: _field_0 } => {
103891-
let _field_0 = <Lit as FoldWith<V>>::fold_with(_field_0, visitor);
103892-
JSXAttrValue::Lit { 0: _field_0 }
103890+
JSXAttrValue::Str { 0: _field_0 } => {
103891+
let _field_0 = <Str as FoldWith<V>>::fold_with(_field_0, visitor);
103892+
JSXAttrValue::Str { 0: _field_0 }
103893103893
}
103894103894
JSXAttrValue::JSXExprContainer { 0: _field_0 } => {
103895103895
let _field_0 = <JSXExprContainer as FoldWith<V>>::fold_with(_field_0, visitor);
@@ -127464,16 +127464,16 @@ impl<V: ?Sized + FoldAstPath> FoldWithAstPath<V> for JSXAttrValue {
127464127464

127465127465
fn fold_children_with_ast_path(self, visitor: &mut V, __ast_path: &mut AstKindPath) -> Self {
127466127466
match self {
127467-
JSXAttrValue::Lit { 0: _field_0 } => {
127467+
JSXAttrValue::Str { 0: _field_0 } => {
127468127468
let mut __ast_path = __ast_path.with_guard(AstParentKind::JSXAttrValue(
127469-
self::fields::JSXAttrValueField::Lit,
127469+
self::fields::JSXAttrValueField::Str,
127470127470
));
127471-
let _field_0 = <Lit as FoldWithAstPath<V>>::fold_with_ast_path(
127471+
let _field_0 = <Str as FoldWithAstPath<V>>::fold_with_ast_path(
127472127472
_field_0,
127473127473
visitor,
127474127474
&mut *__ast_path,
127475127475
);
127476-
JSXAttrValue::Lit { 0: _field_0 }
127476+
JSXAttrValue::Str { 0: _field_0 }
127477127477
}
127478127478
JSXAttrValue::JSXExprContainer { 0: _field_0 } => {
127479127479
let mut __ast_path = __ast_path.with_guard(AstParentKind::JSXAttrValue(
@@ -138138,8 +138138,8 @@ pub mod fields {
138138138138
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
138139138139
#[cfg_attr(feature = "serde-impl", derive(serde::Serialize, serde::Deserialize))]
138140138140
pub enum JSXAttrValueField {
138141-
#[doc = "Represents [`JSXAttrValue::Lit`]"]
138142-
Lit,
138141+
#[doc = "Represents [`JSXAttrValue::Str`]"]
138142+
Str,
138143138143
#[doc = "Represents [`JSXAttrValue::JSXExprContainer`]"]
138144138144
JsxexprContainer,
138145138145
#[doc = "Represents [`JSXAttrValue::JSXElement`]"]
@@ -144744,7 +144744,7 @@ impl<'ast> NodeRef<'ast> {
144744144744
_ => Box::new(::std::iter::empty::<NodeRef<'ast>>()),
144745144745
},
144746144746
NodeRef::JSXAttrValue(node) => match node {
144747-
JSXAttrValue::Lit(v0) => Box::new(::std::iter::once(NodeRef::Lit(v0))),
144747+
JSXAttrValue::Str(v0) => Box::new(::std::iter::once(NodeRef::Str(v0))),
144748144748
JSXAttrValue::JSXExprContainer(v0) => {
144749144749
Box::new(::std::iter::once(NodeRef::JSXExprContainer(v0)))
144750144750
}

0 commit comments

Comments
 (0)