Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion bindings/binding_core_wasm/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1727,7 +1727,7 @@ export interface JSXAttribute extends Node, HasSpan {
export type JSXAttributeName = Identifier | JSXNamespacedName;

export type JSXAttrValue =
| Literal
| StringLiteral
| JSXExpressionContainer
| JSXElement
| JSXFragment;
Expand Down
2 changes: 1 addition & 1 deletion bindings/binding_minifier_wasm/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1726,7 +1726,7 @@ export interface JSXAttribute extends Node, HasSpan {
export type JSXAttributeName = Identifier | JSXNamespacedName;

export type JSXAttrValue =
| Literal
| StringLiteral
| JSXExpressionContainer
| JSXElement
| JSXFragment;
Expand Down
10 changes: 2 additions & 8 deletions crates/swc_ecma_ast/src/jsx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@ use swc_common::{ast_node, util::take::Take, EqIgnoreSpan, Span, DUMMY_SP};
use crate::{
expr::{Expr, SpreadElement},
ident::Ident,
lit::Lit,
typescript::TsTypeParamInstantiation,
IdentName,
IdentName, Str,
};

/// Used for `obj` property of `JSXMemberExpr`.
Expand Down Expand Up @@ -190,12 +189,7 @@ pub enum JSXAttrName {
#[cfg_attr(feature = "shrink-to-fit", derive(shrink_to_fit::ShrinkToFit))]
pub enum JSXAttrValue {
#[tag("StringLiteral")]
#[tag("BooleanLiteral")]
#[tag("NullLiteral")]
#[tag("NumericLiteral")]
#[tag("RegExpLiteral")]
#[tag("JSXText")]
Lit(Lit),
Str(Str),

#[tag("JSXExpressionContainer")]
JSXExprContainer(JSXExprContainer),
Expand Down
2 changes: 1 addition & 1 deletion crates/swc_ecma_codegen/src/jsx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ impl MacroNode for JSXAttr {
impl MacroNode for JSXAttrValue {
fn emit(&mut self, emitter: &mut Macro) -> Result {
match *self {
JSXAttrValue::Lit(ref n) => emit!(n),
JSXAttrValue::Str(ref n) => emit!(n),
JSXAttrValue::JSXExprContainer(ref n) => emit!(n),
JSXAttrValue::JSXElement(ref n) => emit!(n),
JSXAttrValue::JSXFragment(ref n) => emit!(n),
Expand Down
2 changes: 1 addition & 1 deletion crates/swc_ecma_lexer/src/common/parser/jsx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ fn parse_jsx_attr_value<'a, P: Parser<'a>>(p: &mut P) -> PResult<JSXAttrValue> {
let node = parse_jsx_expr_container(p)?;
jsx_expr_container_to_jsx_attr_value(p, start, node)
} else if cur.is_str() {
Ok(JSXAttrValue::Lit(Lit::Str(parse_str_lit(p))))
Ok(JSXAttrValue::Str(parse_str_lit(p)))
} else if cur.is_jsx_tag_start() {
let expr = parse_jsx_element(p)?;
match expr {
Expand Down
6 changes: 3 additions & 3 deletions crates/swc_ecma_parser/src/parser/jsx/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ impl<I: Tokens> Parser<I> {
match cur.token {
Token::Str => {
let value = parse_str_lit(self);
Ok(Some(JSXAttrValue::Lit(Lit::Str(value))))
Ok(Some(JSXAttrValue::Str(value)))
}
Token::LBrace => {
let start = self.cur_pos();
Expand Down Expand Up @@ -498,11 +498,11 @@ mod tests {
attrs: vec![JSXAttrOrSpread::JSXAttr(JSXAttr {
span,
name: JSXAttrName::Ident(IdentName::new(atom!("id"), span)),
value: Some(JSXAttrValue::Lit(Lit::Str(Str {
value: Some(JSXAttrValue::Str(Str {
span,
value: atom!("w < w"),
raw: Some(atom!("\"w &lt; w\"")),
}))),
})),
})],
name: JSXElementName::Ident(Ident::new_no_ctxt(atom!("div"), span)),
self_closing: true,
Expand Down
2 changes: 1 addition & 1 deletion crates/swc_ecma_quote_macros/src/ast/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ impl_struct!(JSXAttr, [span, name, value]);

impl_enum!(
JSXAttrValue,
[Lit, JSXExprContainer, JSXElement, JSXFragment]
[Str, JSXExprContainer, JSXElement, JSXFragment]
);

impl_enum!(JSXAttrName, [Ident, JSXNamespacedName]);
Expand Down
3 changes: 1 addition & 2 deletions crates/swc_ecma_transforms_react/src/jsx/automatic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -639,7 +639,7 @@ fn add_require(imports: Vec<(Ident, IdentName)>, src: &str, unresolved_mark: Mar

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

Lit::Str(Str {
Expand All @@ -649,7 +649,6 @@ fn jsx_attr_value_to_expr(v: JSXAttrValue) -> Option<Box<Expr>> {
})
.into()
}
JSXAttrValue::Lit(lit) => Box::new(lit.into()),
JSXAttrValue::JSXExprContainer(e) => match e.expr {
JSXExpr::JSXEmptyExpr(_) => None?,
JSXExpr::Expr(e) => e,
Expand Down
3 changes: 1 addition & 2 deletions crates/swc_ecma_transforms_react/src/jsx/classic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ impl Classic {
let value = a
.value
.map(|v| match v {
JSXAttrValue::Lit(Lit::Str(s)) => {
JSXAttrValue::Str(s) => {
let value = transform_jsx_attr_str(&s.value);

Lit::Str(Str {
Expand All @@ -290,7 +290,6 @@ impl Classic {
}) => e,
JSXAttrValue::JSXElement(element) => Box::new(self.jsx_elem_to_expr(*element)),
JSXAttrValue::JSXFragment(fragment) => Box::new(self.jsx_frag_to_expr(fragment)),
JSXAttrValue::Lit(lit) => Box::new(lit.into()),
JSXAttrValue::JSXExprContainer(JSXExprContainer {
span: _,
expr: JSXExpr::JSXEmptyExpr(_),
Expand Down
40 changes: 20 additions & 20 deletions crates/swc_ecma_visit/src/generated.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11669,8 +11669,8 @@ impl<V: ?Sized + Visit> VisitWith<V> for JSXAttrValue {

fn visit_children_with(&self, visitor: &mut V) {
match self {
JSXAttrValue::Lit { 0: _field_0 } => {
<Lit as VisitWith<V>>::visit_with(_field_0, visitor);
JSXAttrValue::Str { 0: _field_0 } => {
<Str as VisitWith<V>>::visit_with(_field_0, visitor);
}
JSXAttrValue::JSXExprContainer { 0: _field_0 } => {
<JSXExprContainer as VisitWith<V>>::visit_with(_field_0, visitor);
Expand Down Expand Up @@ -37656,12 +37656,12 @@ impl<V: ?Sized + VisitAstPath> VisitWithAstPath<V> for JSXAttrValue {
__ast_path: &mut AstNodePath<'r>,
) {
match self {
JSXAttrValue::Lit { 0: _field_0 } => {
JSXAttrValue::Str { 0: _field_0 } => {
let mut __ast_path = __ast_path.with_guard(AstParentNodeRef::JSXAttrValue(
self,
self::fields::JSXAttrValueField::Lit,
self::fields::JSXAttrValueField::Str,
));
<Lit as VisitWithAstPath<V>>::visit_with_ast_path(
<Str as VisitWithAstPath<V>>::visit_with_ast_path(
_field_0,
visitor,
&mut *__ast_path,
Expand Down Expand Up @@ -60607,8 +60607,8 @@ impl<V: ?Sized + VisitMut> VisitMutWith<V> for JSXAttrValue {

fn visit_mut_children_with(&mut self, visitor: &mut V) {
match self {
JSXAttrValue::Lit { 0: _field_0 } => {
<Lit as VisitMutWith<V>>::visit_mut_with(_field_0, visitor);
JSXAttrValue::Str { 0: _field_0 } => {
<Str as VisitMutWith<V>>::visit_mut_with(_field_0, visitor);
}
JSXAttrValue::JSXExprContainer { 0: _field_0 } => {
<JSXExprContainer as VisitMutWith<V>>::visit_mut_with(_field_0, visitor);
Expand Down Expand Up @@ -83159,11 +83159,11 @@ impl<V: ?Sized + VisitMutAstPath> VisitMutWithAstPath<V> for JSXAttrValue {

fn visit_mut_children_with_ast_path(&mut self, visitor: &mut V, __ast_path: &mut AstKindPath) {
match self {
JSXAttrValue::Lit { 0: _field_0 } => {
JSXAttrValue::Str { 0: _field_0 } => {
let mut __ast_path = __ast_path.with_guard(AstParentKind::JSXAttrValue(
self::fields::JSXAttrValueField::Lit,
self::fields::JSXAttrValueField::Str,
));
<Lit as VisitMutWithAstPath<V>>::visit_mut_with_ast_path(
<Str as VisitMutWithAstPath<V>>::visit_mut_with_ast_path(
_field_0,
visitor,
&mut *__ast_path,
Expand Down Expand Up @@ -103887,9 +103887,9 @@ impl<V: ?Sized + Fold> FoldWith<V> for JSXAttrValue {

fn fold_children_with(self, visitor: &mut V) -> Self {
match self {
JSXAttrValue::Lit { 0: _field_0 } => {
let _field_0 = <Lit as FoldWith<V>>::fold_with(_field_0, visitor);
JSXAttrValue::Lit { 0: _field_0 }
JSXAttrValue::Str { 0: _field_0 } => {
let _field_0 = <Str as FoldWith<V>>::fold_with(_field_0, visitor);
JSXAttrValue::Str { 0: _field_0 }
}
JSXAttrValue::JSXExprContainer { 0: _field_0 } => {
let _field_0 = <JSXExprContainer as FoldWith<V>>::fold_with(_field_0, visitor);
Expand Down Expand Up @@ -127464,16 +127464,16 @@ impl<V: ?Sized + FoldAstPath> FoldWithAstPath<V> for JSXAttrValue {

fn fold_children_with_ast_path(self, visitor: &mut V, __ast_path: &mut AstKindPath) -> Self {
match self {
JSXAttrValue::Lit { 0: _field_0 } => {
JSXAttrValue::Str { 0: _field_0 } => {
let mut __ast_path = __ast_path.with_guard(AstParentKind::JSXAttrValue(
self::fields::JSXAttrValueField::Lit,
self::fields::JSXAttrValueField::Str,
));
let _field_0 = <Lit as FoldWithAstPath<V>>::fold_with_ast_path(
let _field_0 = <Str as FoldWithAstPath<V>>::fold_with_ast_path(
_field_0,
visitor,
&mut *__ast_path,
);
JSXAttrValue::Lit { 0: _field_0 }
JSXAttrValue::Str { 0: _field_0 }
}
JSXAttrValue::JSXExprContainer { 0: _field_0 } => {
let mut __ast_path = __ast_path.with_guard(AstParentKind::JSXAttrValue(
Expand Down Expand Up @@ -138138,8 +138138,8 @@ pub mod fields {
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[cfg_attr(feature = "serde-impl", derive(serde::Serialize, serde::Deserialize))]
pub enum JSXAttrValueField {
#[doc = "Represents [`JSXAttrValue::Lit`]"]
Lit,
#[doc = "Represents [`JSXAttrValue::Str`]"]
Str,
#[doc = "Represents [`JSXAttrValue::JSXExprContainer`]"]
JsxexprContainer,
#[doc = "Represents [`JSXAttrValue::JSXElement`]"]
Expand Down Expand Up @@ -144744,7 +144744,7 @@ impl<'ast> NodeRef<'ast> {
_ => Box::new(::std::iter::empty::<NodeRef<'ast>>()),
},
NodeRef::JSXAttrValue(node) => match node {
JSXAttrValue::Lit(v0) => Box::new(::std::iter::once(NodeRef::Lit(v0))),
JSXAttrValue::Str(v0) => Box::new(::std::iter::once(NodeRef::Str(v0))),
JSXAttrValue::JSXExprContainer(v0) => {
Box::new(::std::iter::once(NodeRef::JSXExprContainer(v0)))
}
Expand Down
14 changes: 2 additions & 12 deletions crates/swc_estree_compat/src/babelify/jsx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use swc_ecma_ast::{
JSXAttr, JSXAttrName, JSXAttrOrSpread, JSXAttrValue, JSXClosingElement, JSXClosingFragment,
JSXElement, JSXElementChild, JSXElementName, JSXEmptyExpr, JSXExpr, JSXExprContainer,
JSXFragment, JSXMemberExpr, JSXNamespacedName, JSXObject, JSXOpeningElement,
JSXOpeningFragment, JSXSpreadChild, JSXText, Lit,
JSXOpeningFragment, JSXSpreadChild, JSXText,
};
use swc_estree_ast::{
flavor::Flavor, JSXAttrName as BabelJSXAttrName, JSXAttrVal, JSXAttribute,
Expand Down Expand Up @@ -212,17 +212,7 @@ impl Babelify for JSXAttrValue {

fn babelify(self, ctx: &Context) -> Self::Output {
match self {
JSXAttrValue::Lit(lit) => {
// TODO(dwoznicki): Babel only seems to accept string literals here. Is that
// right?
match lit {
Lit::Str(s) => JSXAttrVal::String(s.babelify(ctx)),
_ => panic!(
"illegal conversion: Cannot convert {:?} to JsxAttrVal::Lit",
&lit
),
}
}
JSXAttrValue::Str(s) => JSXAttrVal::String(s.babelify(ctx)),
JSXAttrValue::JSXExprContainer(e) => JSXAttrVal::Expr(e.babelify(ctx)),
JSXAttrValue::JSXElement(e) => JSXAttrVal::Element(e.babelify(ctx)),
JSXAttrValue::JSXFragment(f) => JSXAttrVal::Fragment(f.babelify(ctx)),
Expand Down
2 changes: 1 addition & 1 deletion crates/swc_estree_compat/src/swcify/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -941,7 +941,7 @@ impl Swcify for JSXAttrVal {
match self {
JSXAttrVal::Element(v) => JSXAttrValue::JSXElement(Box::new(v.swcify(ctx))),
JSXAttrVal::Fragment(v) => JSXAttrValue::JSXFragment(v.swcify(ctx)),
JSXAttrVal::String(v) => JSXAttrValue::Lit(Lit::Str(v.swcify(ctx))),
JSXAttrVal::String(v) => JSXAttrValue::Str(v.swcify(ctx)),
JSXAttrVal::Expr(v) => JSXAttrValue::JSXExprContainer(v.swcify(ctx)),
}
}
Expand Down
8 changes: 0 additions & 8 deletions packages/core/src/Visitor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1628,14 +1628,6 @@ export class Visitor {
if (!n) return n;

switch (n.type) {
case "BooleanLiteral":
return this.visitBooleanLiteral(n);
case "NullLiteral":
return this.visitNullLiteral(n);
case "NumericLiteral":
return this.visitNumericLiteral(n);
case "JSXText":
return this.visitJSXText(n);
case "StringLiteral":
return this.visitStringLiteral(n);

Expand Down
2 changes: 1 addition & 1 deletion packages/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1799,7 +1799,7 @@ export interface JSXAttribute extends Node, HasSpan {
export type JSXAttributeName = Identifier | JSXNamespacedName;

export type JSXAttrValue =
| Literal
| StringLiteral
| JSXExpressionContainer
| JSXElement
| JSXFragment;
Expand Down
Loading