Skip to content

Commit 7b636ef

Browse files
committed
fix: babelify & swcify
1 parent 0ac4afc commit 7b636ef

File tree

4 files changed

+57
-20
lines changed

4 files changed

+57
-20
lines changed

crates/swc_estree_ast/src/typescript.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ use crate::{
1010
object::ObjectKey,
1111
pat::AssignmentPattern,
1212
stmt::Statement,
13+
PrivateName,
1314
};
1415

1516
#[derive(Debug, Clone, PartialEq)]
@@ -248,7 +249,8 @@ pub struct TSQualifiedName {
248249
#[serde(flatten)]
249250
pub base: BaseNode,
250251
pub left: Box<TSEntityName>,
251-
pub right: Identifier,
252+
#[serde(flatten)]
253+
pub right: TSMemberName,
252254
}
253255

254256
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
@@ -467,6 +469,15 @@ pub enum TSEntityName {
467469
Qualified(TSQualifiedName),
468470
}
469471

472+
#[derive(Debug, Clone, PartialEq)]
473+
#[ast_serde]
474+
pub enum TSMemberName {
475+
#[tag("Identifier")]
476+
Id(Identifier),
477+
#[tag("PrivateName")]
478+
PrivateName(PrivateName),
479+
}
480+
470481
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
471482
#[serde(rename_all = "camelCase")]
472483
#[serde(tag = "type")]

crates/swc_estree_compat/src/babelify/typescript.rs

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@ use swc_ecma_ast::{
99
TsExprWithTypeArgs, TsExternalModuleRef, TsFnOrConstructorType, TsFnParam, TsFnType,
1010
TsImportEqualsDecl, TsImportType, TsIndexSignature, TsIndexedAccessType, TsInferType,
1111
TsInterfaceBody, TsInterfaceDecl, TsIntersectionType, TsKeywordType, TsKeywordTypeKind, TsLit,
12-
TsLitType, TsMappedType, TsMethodSignature, TsModuleBlock, TsModuleDecl, TsModuleName,
13-
TsModuleRef, TsNamespaceBody, TsNamespaceDecl, TsNamespaceExportDecl, TsNonNullExpr,
14-
TsOptionalType, TsParamProp, TsParamPropParam, TsParenthesizedType, TsPropertySignature,
15-
TsQualifiedName, TsRestType, TsThisType, TsThisTypeOrIdent, TsTplLitType, TsTupleElement,
16-
TsTupleType, TsType, TsTypeAliasDecl, TsTypeAnn, TsTypeAssertion, TsTypeElement, TsTypeLit,
17-
TsTypeOperator, TsTypeOperatorOp, TsTypeParam, TsTypeParamDecl, TsTypeParamInstantiation,
18-
TsTypePredicate, TsTypeQuery, TsTypeQueryExpr, TsTypeRef, TsUnionOrIntersectionType,
19-
TsUnionType,
12+
TsLitType, TsMappedType, TsMemberName, TsMethodSignature, TsModuleBlock, TsModuleDecl,
13+
TsModuleName, TsModuleRef, TsNamespaceBody, TsNamespaceDecl, TsNamespaceExportDecl,
14+
TsNonNullExpr, TsOptionalType, TsParamProp, TsParamPropParam, TsParenthesizedType,
15+
TsPropertySignature, TsQualifiedName, TsRestType, TsThisType, TsThisTypeOrIdent, TsTplLitType,
16+
TsTupleElement, TsTupleType, TsType, TsTypeAliasDecl, TsTypeAnn, TsTypeAssertion,
17+
TsTypeElement, TsTypeLit, TsTypeOperator, TsTypeOperatorOp, TsTypeParam, TsTypeParamDecl,
18+
TsTypeParamInstantiation, TsTypePredicate, TsTypeQuery, TsTypeQueryExpr, TsTypeRef,
19+
TsUnionOrIntersectionType, TsUnionType,
2020
};
2121
use swc_estree_ast::{
2222
Access, ArrayPattern, IdOrRest, IdOrString, Identifier, ObjectPattern, RestElement,
@@ -26,8 +26,8 @@ use swc_estree_ast::{
2626
TSExpressionWithTypeArguments, TSExternalModuleReference, TSFunctionType,
2727
TSImportEqualsDeclModuleRef, TSImportEqualsDeclaration, TSImportType, TSIndexSignature,
2828
TSIndexedAccessType, TSInferType, TSInterfaceBody, TSInterfaceDeclaration, TSIntersectionType,
29-
TSIntrinsicKeyword, TSLiteralType, TSLiteralTypeLiteral, TSMappedType, TSMethodSignature,
30-
TSModuleBlock, TSModuleDeclBody, TSModuleDeclaration, TSNamedTupleMember,
29+
TSIntrinsicKeyword, TSLiteralType, TSLiteralTypeLiteral, TSMappedType, TSMemberName,
30+
TSMethodSignature, TSModuleBlock, TSModuleDeclBody, TSModuleDeclaration, TSNamedTupleMember,
3131
TSNamespaceExportDeclaration, TSNeverKeyword, TSNonNullExpression, TSNullKeyword,
3232
TSNumberKeyword, TSObjectKeyword, TSOptionalType, TSParamPropParam, TSParameterProperty,
3333
TSParenthesizedType, TSPropertySignature, TSQualifiedName, TSRestType, TSStringKeyword,
@@ -192,6 +192,17 @@ impl Babelify for TsEntityName {
192192
}
193193
}
194194

195+
impl Babelify for TsMemberName {
196+
type Output = TSMemberName;
197+
198+
fn babelify(self, ctx: &Context) -> Self::Output {
199+
match self {
200+
Self::Ident(i) => Self::Output::Id(i.babelify(ctx)),
201+
Self::PrivateName(p) => Self::Output::PrivateName(p.babelify(ctx)),
202+
}
203+
}
204+
}
205+
195206
impl Babelify for TsTypeElement {
196207
type Output = TSTypeElement;
197208

@@ -842,7 +853,8 @@ impl Babelify for TsExprWithTypeArgs {
842853
base: ctx.base(e.span),
843854
left: Box::new(babelify_expr(*e.obj, ctx)),
844855
right: match e.prop {
845-
MemberProp::Ident(id) => id.babelify(ctx),
856+
MemberProp::Ident(id) => TSMemberName::Id(id.babelify(ctx)),
857+
MemberProp::PrivateName(p) => TSMemberName::PrivateName(p.babelify(ctx)),
846858
_ => unreachable!(),
847859
},
848860
}),

crates/swc_estree_compat/src/swcify/class.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use swc_ecma_ast::{
22
ClassMember, Expr, Function, MemberExpr, MemberProp, MethodKind, ParamOrTsParamProp,
3-
TsExprWithTypeArgs,
3+
TsExprWithTypeArgs, TsMemberName,
44
};
55
use swc_estree_ast::{
66
ClassBody, ClassBodyEl, ClassImpl, ClassMethodKind, TSEntityName,
@@ -198,7 +198,10 @@ impl Swcify for TSExpressionWithTypeArguments {
198198
fn swcify_qualified_name(qualified_name: TSQualifiedName, ctx: &Context) -> Box<Expr> {
199199
Box::new(Expr::Member(MemberExpr {
200200
obj: swcify_expr(*qualified_name.left, ctx),
201-
prop: MemberProp::Ident(qualified_name.right.swcify(ctx).id),
201+
prop: match qualified_name.right.swcify(ctx) {
202+
TsMemberName::Ident(id) => MemberProp::Ident(id),
203+
TsMemberName::PrivateName(p) => MemberProp::PrivateName(p),
204+
},
202205
span: ctx.span(&qualified_name.base),
203206
}))
204207
}

crates/swc_estree_compat/src/swcify/typescript.rs

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
use swc_ecma_ast::{
2-
Accessibility, Ident, TsEntityName, TsQualifiedName, TsType, TsTypeAnn, TsTypeParam,
3-
TsTypeParamDecl, TsTypeParamInstantiation,
2+
Accessibility, Ident, TsEntityName, TsMemberName, TsQualifiedName, TsType, TsTypeAnn,
3+
TsTypeParam, TsTypeParamDecl, TsTypeParamInstantiation,
44
};
55
use swc_estree_ast::{
6-
Access, FlowType, SuperTypeParams, TSEntityName, TSQualifiedName, TSType, TSTypeAnnotation,
7-
TSTypeParameter, TSTypeParameterDeclaration, TSTypeParameterInstantiation, TypeAnnotOrNoop,
8-
TypeParamDeclOrNoop,
6+
Access, FlowType, SuperTypeParams, TSEntityName, TSMemberName, TSQualifiedName, TSType,
7+
TSTypeAnnotation, TSTypeParameter, TSTypeParameterDeclaration, TSTypeParameterInstantiation,
8+
TypeAnnotOrNoop, TypeParamDeclOrNoop,
99
};
1010

1111
use super::Context;
@@ -140,7 +140,18 @@ impl Swcify for TSQualifiedName {
140140
fn swcify(self, ctx: &Context) -> Self::Output {
141141
TsQualifiedName {
142142
left: self.left.swcify(ctx),
143-
right: self.right.swcify(ctx).id,
143+
right: self.right.swcify(ctx),
144+
}
145+
}
146+
}
147+
148+
impl Swcify for TSMemberName {
149+
type Output = TsMemberName;
150+
151+
fn swcify(self, ctx: &Context) -> Self::Output {
152+
match self {
153+
Self::Id(id) => Self::Output::Ident(id.swcify(ctx).id),
154+
Self::PrivateName(p) => Self::Output::Ident(p.swcify(ctx).id),
144155
}
145156
}
146157
}

0 commit comments

Comments
 (0)