diff --git a/crates/swc_ecma_ast/src/lib.rs b/crates/swc_ecma_ast/src/lib.rs index c3c9cfb8eb9b..ba952a2844db 100644 --- a/crates/swc_ecma_ast/src/lib.rs +++ b/crates/swc_ecma_ast/src/lib.rs @@ -62,15 +62,14 @@ pub use self::{ TsExprWithTypeArgs, TsExternalModuleRef, TsFnOrConstructorType, TsFnParam, TsFnType, TsGetterSignature, TsImportEqualsDecl, TsImportType, TsIndexSignature, TsIndexedAccessType, TsInferType, TsInstantiation, TsInterfaceBody, TsInterfaceDecl, TsIntersectionType, - TsKeywordType, TsKeywordTypeKind, TsLit, TsLitType, TsMappedType, TsMemberName, - TsMethodSignature, TsModuleBlock, TsModuleDecl, TsModuleName, TsModuleRef, TsNamespaceBody, - TsNamespaceDecl, TsNamespaceExportDecl, TsNonNullExpr, TsOptionalType, TsParamProp, - TsParamPropParam, TsParenthesizedType, TsPropertySignature, TsQualifiedName, TsRestType, - TsSetterSignature, TsThisType, TsThisTypeOrIdent, TsTplLitType, TsTupleElement, - TsTupleType, TsType, TsTypeAliasDecl, TsTypeAnn, TsTypeAssertion, TsTypeElement, TsTypeLit, - TsTypeOperator, TsTypeOperatorOp, TsTypeParam, TsTypeParamDecl, TsTypeParamInstantiation, - TsTypePredicate, TsTypeQuery, TsTypeQueryExpr, TsTypeRef, TsUnionOrIntersectionType, - TsUnionType, + TsKeywordType, TsKeywordTypeKind, TsLit, TsLitType, TsMappedType, TsMethodSignature, + TsModuleBlock, TsModuleDecl, TsModuleName, TsModuleRef, TsNamespaceBody, TsNamespaceDecl, + TsNamespaceExportDecl, TsNonNullExpr, TsOptionalType, TsParamProp, TsParamPropParam, + TsParenthesizedType, TsPropertySignature, TsQualifiedName, TsRestType, TsSetterSignature, + TsThisType, TsThisTypeOrIdent, TsTplLitType, TsTupleElement, TsTupleType, TsType, + TsTypeAliasDecl, TsTypeAnn, TsTypeAssertion, TsTypeElement, TsTypeLit, TsTypeOperator, + TsTypeOperatorOp, TsTypeParam, TsTypeParamDecl, TsTypeParamInstantiation, TsTypePredicate, + TsTypeQuery, TsTypeQueryExpr, TsTypeRef, TsUnionOrIntersectionType, TsUnionType, }, }; diff --git a/crates/swc_ecma_ast/src/typescript.rs b/crates/swc_ecma_ast/src/typescript.rs index a9b41346b1a8..a5693f95b6f6 100644 --- a/crates/swc_ecma_ast/src/typescript.rs +++ b/crates/swc_ecma_ast/src/typescript.rs @@ -18,7 +18,7 @@ use crate::{ lit::{Bool, Number, Str}, module::ModuleItem, pat::{ArrayPat, AssignPat, ObjectPat, Pat, RestPat}, - BigInt, BindingIdent, PrivateName, TplElement, + BigInt, BindingIdent, TplElement, }; #[ast_node("TsTypeAnnotation")] @@ -101,7 +101,7 @@ pub struct TsQualifiedName { #[span(lo)] pub left: TsEntityName, #[span(hi)] - pub right: TsMemberName, + pub right: Ident, } #[ast_node] @@ -116,18 +116,6 @@ pub enum TsEntityName { Ident(Ident), } -#[ast_node] -#[derive(Eq, Hash, Is, EqIgnoreSpan)] -#[allow(variant_size_differences)] -#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))] -pub enum TsMemberName { - #[tag("Identifier")] - Ident(Ident), - - #[tag("PrivateName")] - PrivateName(PrivateName), -} - // ================ // TypeScript type members (for type literal / interface / class) // ================ diff --git a/crates/swc_ecma_codegen/src/typescript.rs b/crates/swc_ecma_codegen/src/typescript.rs index 36443553a930..51cc20af3931 100644 --- a/crates/swc_ecma_codegen/src/typescript.rs +++ b/crates/swc_ecma_codegen/src/typescript.rs @@ -137,16 +137,6 @@ where } } - #[emitter] - fn emit_ts_member_name(&mut self, n: &TsMemberName) -> Result { - self.emit_leading_comments_of_span(n.span(), false)?; - - match n { - TsMemberName::Ident(n) => emit!(n), - TsMemberName::PrivateName(n) => emit!(n), - } - } - #[emitter] fn emit_ts_enum_decl(&mut self, n: &TsEnumDecl) -> Result { self.emit_leading_comments_of_span(n.span(), false)?; diff --git a/crates/swc_ecma_parser/src/parser/typescript.rs b/crates/swc_ecma_parser/src/parser/typescript.rs index ec26a6a54535..590a53bf2d5c 100644 --- a/crates/swc_ecma_parser/src/parser/typescript.rs +++ b/crates/swc_ecma_parser/src/parser/typescript.rs @@ -180,11 +180,7 @@ impl Parser { } /// `tsParseEntityName` - fn parse_ts_entity_name( - &mut self, - allow_reserved_words: bool, - allow_private_identifiers: bool, - ) -> PResult { + fn parse_ts_entity_name(&mut self, allow_reserved_words: bool) -> PResult { debug_assert!(self.input.syntax().typescript()); let init = self.parse_ident_name()?; @@ -200,7 +196,7 @@ impl Parser { let mut entity = TsEntityName::Ident(init); while eat!(self, '.') { let dot_start = cur_pos!(self); - if !allow_private_identifiers && !is!(self, '#') && !is!(self, IdentName) { + if !is!(self, '#') && !is!(self, IdentName) { self.emit_err( Span::new(dot_start, dot_start, Default::default()), SyntaxError::TS1003, @@ -209,13 +205,10 @@ impl Parser { } let left = entity; - let right = if allow_private_identifiers { - self.parse_maybe_private_name()? - .either(Into::into, Into::into) - } else if allow_reserved_words { - self.parse_ident_name()?.into() + let right = if allow_reserved_words { + self.parse_ident_name()? } else { - self.parse_ident(false, false)?.into() + self.parse_ident(false, false)? }; entity = TsEntityName::TsQualifiedName(Box::new(TsQualifiedName { left, right })); } @@ -232,9 +225,7 @@ impl Parser { let has_modifier = self.eat_any_ts_modifier()?; - let type_name = self.parse_ts_entity_name( - /* allow_reserved_words */ true, /* allow_private_identifiers */ false, - )?; + let type_name = self.parse_ts_entity_name(/* allow_reserved_words */ true)?; trace_cur!(self, parse_ts_type_ref__type_args); let type_params = if !self.input.had_line_break_before_cur() && is!(self, '<') { Some(self.parse_ts_type_args()?) @@ -326,7 +317,7 @@ impl Parser { expect!(self, ')'); let qualifier = if eat!(self, '.') { - self.parse_ts_entity_name(false, false).map(Some)? + self.parse_ts_entity_name(false).map(Some)? } else { None }; @@ -356,7 +347,7 @@ impl Parser { } else { self.parse_ts_entity_name( // allow_reserved_word - true, true, + true, ) .map(From::from)? }; @@ -1142,10 +1133,8 @@ impl Parser { if self.is_ts_external_module_ref()? { self.parse_ts_external_module_ref().map(From::from) } else { - self.parse_ts_entity_name( - /* allow_reserved_words */ false, /* allow_private_identifiers */ false, - ) - .map(From::from) + self.parse_ts_entity_name(/* allow_reserved_words */ false) + .map(From::from) } } diff --git a/crates/swc_ecma_parser/tests/typescript/private-name-in-type-query/1/input.ts b/crates/swc_ecma_parser/tests/typescript/private-name-in-type-query/1/input.ts deleted file mode 100644 index 95d8b82a0a99..000000000000 --- a/crates/swc_ecma_parser/tests/typescript/private-name-in-type-query/1/input.ts +++ /dev/null @@ -1,8 +0,0 @@ -class C { - #a = 'a'; - - constructor() { - const a: typeof this.#a = ''; // Ok - const b: typeof this.#a = 1; // Error - } -} \ No newline at end of file diff --git a/crates/swc_ecma_parser/tests/typescript/private-name-in-type-query/1/input.ts.json b/crates/swc_ecma_parser/tests/typescript/private-name-in-type-query/1/input.ts.json deleted file mode 100644 index 8ea98bf289b3..000000000000 --- a/crates/swc_ecma_parser/tests/typescript/private-name-in-type-query/1/input.ts.json +++ /dev/null @@ -1,291 +0,0 @@ -{ - "type": "Script", - "span": { - "start": 0, - "end": 143, - "ctxt": 0 - }, - "body": [ - { - "type": "ClassDeclaration", - "identifier": { - "type": "Identifier", - "span": { - "start": 6, - "end": 7, - "ctxt": 0 - }, - "value": "C", - "optional": false - }, - "declare": false, - "span": { - "start": 0, - "end": 143, - "ctxt": 0 - }, - "decorators": [], - "body": [ - { - "type": "PrivateProperty", - "span": { - "start": 14, - "end": 23, - "ctxt": 0 - }, - "key": { - "type": "PrivateName", - "span": { - "start": 14, - "end": 16, - "ctxt": 0 - }, - "id": { - "type": "Identifier", - "span": { - "start": 15, - "end": 16, - "ctxt": 0 - }, - "value": "a", - "optional": false - } - }, - "value": { - "type": "StringLiteral", - "span": { - "start": 19, - "end": 22, - "ctxt": 0 - }, - "value": "a", - "raw": "'a'" - }, - "typeAnnotation": null, - "isStatic": false, - "decorators": [], - "accessibility": null, - "isOptional": false, - "isOverride": false, - "readonly": false, - "definite": false - }, - { - "type": "Constructor", - "span": { - "start": 29, - "end": 141, - "ctxt": 0 - }, - "key": { - "type": "Identifier", - "span": { - "start": 29, - "end": 40, - "ctxt": 0 - }, - "value": "constructor", - "optional": false - }, - "params": [], - "body": { - "type": "BlockStatement", - "span": { - "start": 43, - "end": 141, - "ctxt": 0 - }, - "stmts": [ - { - "type": "VariableDeclaration", - "span": { - "start": 53, - "end": 82, - "ctxt": 0 - }, - "kind": "const", - "declare": false, - "declarations": [ - { - "type": "VariableDeclarator", - "span": { - "start": 59, - "end": 81, - "ctxt": 0 - }, - "id": { - "type": "Identifier", - "span": { - "start": 59, - "end": 60, - "ctxt": 0 - }, - "value": "a", - "optional": false, - "typeAnnotation": { - "type": "TsTypeAnnotation", - "span": { - "start": 60, - "end": 76, - "ctxt": 0 - }, - "typeAnnotation": { - "type": "TsTypeQuery", - "span": { - "start": 62, - "end": 76, - "ctxt": 0 - }, - "exprName": { - "type": "TsQualifiedName", - "left": { - "type": "Identifier", - "span": { - "start": 69, - "end": 73, - "ctxt": 0 - }, - "value": "this", - "optional": false - }, - "right": { - "type": "PrivateName", - "span": { - "start": 74, - "end": 76, - "ctxt": 0 - }, - "id": { - "type": "Identifier", - "span": { - "start": 75, - "end": 76, - "ctxt": 0 - }, - "value": "a", - "optional": false - } - } - }, - "typeArguments": null - } - } - }, - "init": { - "type": "StringLiteral", - "span": { - "start": 79, - "end": 81, - "ctxt": 0 - }, - "value": "", - "raw": "''" - }, - "definite": false - } - ] - }, - { - "type": "VariableDeclaration", - "span": { - "start": 97, - "end": 125, - "ctxt": 0 - }, - "kind": "const", - "declare": false, - "declarations": [ - { - "type": "VariableDeclarator", - "span": { - "start": 103, - "end": 124, - "ctxt": 0 - }, - "id": { - "type": "Identifier", - "span": { - "start": 103, - "end": 104, - "ctxt": 0 - }, - "value": "b", - "optional": false, - "typeAnnotation": { - "type": "TsTypeAnnotation", - "span": { - "start": 104, - "end": 120, - "ctxt": 0 - }, - "typeAnnotation": { - "type": "TsTypeQuery", - "span": { - "start": 106, - "end": 120, - "ctxt": 0 - }, - "exprName": { - "type": "TsQualifiedName", - "left": { - "type": "Identifier", - "span": { - "start": 113, - "end": 117, - "ctxt": 0 - }, - "value": "this", - "optional": false - }, - "right": { - "type": "PrivateName", - "span": { - "start": 118, - "end": 120, - "ctxt": 0 - }, - "id": { - "type": "Identifier", - "span": { - "start": 119, - "end": 120, - "ctxt": 0 - }, - "value": "a", - "optional": false - } - } - }, - "typeArguments": null - } - } - }, - "init": { - "type": "NumericLiteral", - "span": { - "start": 123, - "end": 124, - "ctxt": 0 - }, - "value": 1.0, - "raw": "1" - }, - "definite": false - } - ] - } - ] - }, - "accessibility": null, - "isOptional": false - } - ], - "superClass": null, - "isAbstract": false, - "typeParams": null, - "superTypeParams": null, - "implements": [] - } - ], - "interpreter": null -} diff --git a/crates/swc_ecma_parser/tests/typescript/private-name-in-type-query/2/input.ts b/crates/swc_ecma_parser/tests/typescript/private-name-in-type-query/2/input.ts deleted file mode 100644 index 028caeaf4b0d..000000000000 --- a/crates/swc_ecma_parser/tests/typescript/private-name-in-type-query/2/input.ts +++ /dev/null @@ -1,11 +0,0 @@ -class Container { - #data = "hello!"; - - get data(): typeof this.#data { - return this.#data; - } - - set data(value: typeof this.#data) { - this.#data = value; - } -} \ No newline at end of file diff --git a/crates/swc_ecma_parser/tests/typescript/private-name-in-type-query/2/input.ts.json b/crates/swc_ecma_parser/tests/typescript/private-name-in-type-query/2/input.ts.json deleted file mode 100644 index 3b496282d01b..000000000000 --- a/crates/swc_ecma_parser/tests/typescript/private-name-in-type-query/2/input.ts.json +++ /dev/null @@ -1,394 +0,0 @@ -{ - "type": "Script", - "span": { - "start": 0, - "end": 187, - "ctxt": 0 - }, - "body": [ - { - "type": "ClassDeclaration", - "identifier": { - "type": "Identifier", - "span": { - "start": 6, - "end": 15, - "ctxt": 0 - }, - "value": "Container", - "optional": false - }, - "declare": false, - "span": { - "start": 0, - "end": 187, - "ctxt": 0 - }, - "decorators": [], - "body": [ - { - "type": "PrivateProperty", - "span": { - "start": 22, - "end": 39, - "ctxt": 0 - }, - "key": { - "type": "PrivateName", - "span": { - "start": 22, - "end": 27, - "ctxt": 0 - }, - "id": { - "type": "Identifier", - "span": { - "start": 23, - "end": 27, - "ctxt": 0 - }, - "value": "data", - "optional": false - } - }, - "value": { - "type": "StringLiteral", - "span": { - "start": 30, - "end": 38, - "ctxt": 0 - }, - "value": "hello!", - "raw": "\"hello!\"" - }, - "typeAnnotation": null, - "isStatic": false, - "decorators": [], - "accessibility": null, - "isOptional": false, - "isOverride": false, - "readonly": false, - "definite": false - }, - { - "type": "ClassMethod", - "span": { - "start": 45, - "end": 109, - "ctxt": 0 - }, - "key": { - "type": "Identifier", - "span": { - "start": 49, - "end": 53, - "ctxt": 0 - }, - "value": "data", - "optional": false - }, - "function": { - "params": [], - "decorators": [], - "span": { - "start": 45, - "end": 109, - "ctxt": 0 - }, - "body": { - "type": "BlockStatement", - "span": { - "start": 75, - "end": 109, - "ctxt": 0 - }, - "stmts": [ - { - "type": "ReturnStatement", - "span": { - "start": 85, - "end": 103, - "ctxt": 0 - }, - "argument": { - "type": "MemberExpression", - "span": { - "start": 92, - "end": 102, - "ctxt": 0 - }, - "object": { - "type": "ThisExpression", - "span": { - "start": 92, - "end": 96, - "ctxt": 0 - } - }, - "property": { - "type": "PrivateName", - "span": { - "start": 97, - "end": 102, - "ctxt": 0 - }, - "id": { - "type": "Identifier", - "span": { - "start": 98, - "end": 102, - "ctxt": 0 - }, - "value": "data", - "optional": false - } - } - } - } - ] - }, - "generator": false, - "async": false, - "typeParameters": null, - "returnType": { - "type": "TsTypeAnnotation", - "span": { - "start": 55, - "end": 74, - "ctxt": 0 - }, - "typeAnnotation": { - "type": "TsTypeQuery", - "span": { - "start": 57, - "end": 74, - "ctxt": 0 - }, - "exprName": { - "type": "TsQualifiedName", - "left": { - "type": "Identifier", - "span": { - "start": 64, - "end": 68, - "ctxt": 0 - }, - "value": "this", - "optional": false - }, - "right": { - "type": "PrivateName", - "span": { - "start": 69, - "end": 74, - "ctxt": 0 - }, - "id": { - "type": "Identifier", - "span": { - "start": 70, - "end": 74, - "ctxt": 0 - }, - "value": "data", - "optional": false - } - } - }, - "typeArguments": null - } - } - }, - "kind": "getter", - "isStatic": false, - "accessibility": null, - "isAbstract": false, - "isOptional": false, - "isOverride": false - }, - { - "type": "ClassMethod", - "span": { - "start": 115, - "end": 185, - "ctxt": 0 - }, - "key": { - "type": "Identifier", - "span": { - "start": 119, - "end": 123, - "ctxt": 0 - }, - "value": "data", - "optional": false - }, - "function": { - "params": [ - { - "type": "Parameter", - "span": { - "start": 124, - "end": 148, - "ctxt": 0 - }, - "decorators": [], - "pat": { - "type": "Identifier", - "span": { - "start": 124, - "end": 148, - "ctxt": 0 - }, - "value": "value", - "optional": false, - "typeAnnotation": { - "type": "TsTypeAnnotation", - "span": { - "start": 129, - "end": 148, - "ctxt": 0 - }, - "typeAnnotation": { - "type": "TsTypeQuery", - "span": { - "start": 131, - "end": 148, - "ctxt": 0 - }, - "exprName": { - "type": "TsQualifiedName", - "left": { - "type": "Identifier", - "span": { - "start": 138, - "end": 142, - "ctxt": 0 - }, - "value": "this", - "optional": false - }, - "right": { - "type": "PrivateName", - "span": { - "start": 143, - "end": 148, - "ctxt": 0 - }, - "id": { - "type": "Identifier", - "span": { - "start": 144, - "end": 148, - "ctxt": 0 - }, - "value": "data", - "optional": false - } - } - }, - "typeArguments": null - } - } - } - } - ], - "decorators": [], - "span": { - "start": 115, - "end": 185, - "ctxt": 0 - }, - "body": { - "type": "BlockStatement", - "span": { - "start": 150, - "end": 185, - "ctxt": 0 - }, - "stmts": [ - { - "type": "ExpressionStatement", - "span": { - "start": 160, - "end": 179, - "ctxt": 0 - }, - "expression": { - "type": "AssignmentExpression", - "span": { - "start": 160, - "end": 178, - "ctxt": 0 - }, - "operator": "=", - "left": { - "type": "MemberExpression", - "span": { - "start": 160, - "end": 170, - "ctxt": 0 - }, - "object": { - "type": "ThisExpression", - "span": { - "start": 160, - "end": 164, - "ctxt": 0 - } - }, - "property": { - "type": "PrivateName", - "span": { - "start": 165, - "end": 170, - "ctxt": 0 - }, - "id": { - "type": "Identifier", - "span": { - "start": 166, - "end": 170, - "ctxt": 0 - }, - "value": "data", - "optional": false - } - } - }, - "right": { - "type": "Identifier", - "span": { - "start": 173, - "end": 178, - "ctxt": 0 - }, - "value": "value", - "optional": false - } - } - } - ] - }, - "generator": false, - "async": false, - "typeParameters": null, - "returnType": null - }, - "kind": "setter", - "isStatic": false, - "accessibility": null, - "isAbstract": false, - "isOptional": false, - "isOverride": false - } - ], - "superClass": null, - "isAbstract": false, - "typeParams": null, - "superTypeParams": null, - "implements": [] - } - ], - "interpreter": null -} diff --git a/crates/swc_ecma_transforms_proposal/src/decorators/legacy/metadata.rs b/crates/swc_ecma_transforms_proposal/src/decorators/legacy/metadata.rs index da9d1e13b321..ca72f771399f 100644 --- a/crates/swc_ecma_transforms_proposal/src/decorators/legacy/metadata.rs +++ b/crates/swc_ecma_transforms_proposal/src/decorators/legacy/metadata.rs @@ -478,10 +478,7 @@ fn ts_entity_to_member_expr(type_name: &TsEntityName) -> Expr { Expr::Member(MemberExpr { span: DUMMY_SP, obj: obj.into(), - prop: match q.right.clone() { - TsMemberName::Ident(i) => MemberProp::Ident(i), - TsMemberName::PrivateName(p) => MemberProp::PrivateName(p), - }, + prop: MemberProp::Ident(q.right.clone()), }) } TsEntityName::Ident(i) => Expr::Ident(i.clone()), diff --git a/crates/swc_ecma_transforms_typescript/src/strip.rs b/crates/swc_ecma_transforms_typescript/src/strip.rs index ab98db7b74b2..21c5372184e6 100644 --- a/crates/swc_ecma_transforms_typescript/src/strip.rs +++ b/crates/swc_ecma_transforms_typescript/src/strip.rs @@ -2549,10 +2549,7 @@ fn ts_entity_name_to_expr(n: TsEntityName) -> Expr { MemberExpr { span: DUMMY_SP, obj: Box::new(ts_entity_name_to_expr(left)), - prop: match right { - TsMemberName::Ident(i) => MemberProp::Ident(i), - TsMemberName::PrivateName(p) => MemberProp::PrivateName(p), - }, + prop: MemberProp::Ident(right), } .into() } diff --git a/crates/swc_ecma_transforms_typescript/tests/fixture/issue-4287/1/input.ts b/crates/swc_ecma_transforms_typescript/tests/fixture/issue-4287/1/input.ts deleted file mode 100644 index 95d8b82a0a99..000000000000 --- a/crates/swc_ecma_transforms_typescript/tests/fixture/issue-4287/1/input.ts +++ /dev/null @@ -1,8 +0,0 @@ -class C { - #a = 'a'; - - constructor() { - const a: typeof this.#a = ''; // Ok - const b: typeof this.#a = 1; // Error - } -} \ No newline at end of file diff --git a/crates/swc_ecma_transforms_typescript/tests/fixture/issue-4287/1/output.js b/crates/swc_ecma_transforms_typescript/tests/fixture/issue-4287/1/output.js deleted file mode 100644 index c4a80136696d..000000000000 --- a/crates/swc_ecma_transforms_typescript/tests/fixture/issue-4287/1/output.js +++ /dev/null @@ -1,11 +0,0 @@ -var _a = /*#__PURE__*/ new WeakMap(); -class C { - constructor(){ - _classPrivateFieldInit(this, _a, { - writable: true, - value: 'a' - }); - const a = ''; // Ok - const b = 1; // Error - } -} diff --git a/crates/swc_ecma_transforms_typescript/tests/fixture/issue-4287/2/input.ts b/crates/swc_ecma_transforms_typescript/tests/fixture/issue-4287/2/input.ts deleted file mode 100644 index 028caeaf4b0d..000000000000 --- a/crates/swc_ecma_transforms_typescript/tests/fixture/issue-4287/2/input.ts +++ /dev/null @@ -1,11 +0,0 @@ -class Container { - #data = "hello!"; - - get data(): typeof this.#data { - return this.#data; - } - - set data(value: typeof this.#data) { - this.#data = value; - } -} \ No newline at end of file diff --git a/crates/swc_ecma_transforms_typescript/tests/fixture/issue-4287/2/output.js b/crates/swc_ecma_transforms_typescript/tests/fixture/issue-4287/2/output.js deleted file mode 100644 index 1919de0084dc..000000000000 --- a/crates/swc_ecma_transforms_typescript/tests/fixture/issue-4287/2/output.js +++ /dev/null @@ -1,15 +0,0 @@ -var _data = /*#__PURE__*/ new WeakMap(); -class Container { - get data() { - return _classPrivateFieldGet(this, _data); - } - set data(value) { - _classPrivateFieldSet(this, _data, value); - } - constructor(){ - _classPrivateFieldInit(this, _data, { - writable: true, - value: "hello!" - }); - } -} diff --git a/crates/swc_ecma_visit/src/lib.rs b/crates/swc_ecma_visit/src/lib.rs index 5bed611a92e4..dd675f597732 100644 --- a/crates/swc_ecma_visit/src/lib.rs +++ b/crates/swc_ecma_visit/src/lib.rs @@ -309,7 +309,6 @@ macro_rules! noop_fold_type { noop_fold_type!(fold_ts_construct_signature_decl, TsConstructSignatureDecl); noop_fold_type!(fold_ts_constructor_type, TsConstructorType); noop_fold_type!(fold_ts_entity_name, TsEntityName); - noop_fold_type!(fold_ts_member_name, TsMemberName); noop_fold_type!(fold_ts_enum_decl, TsEnumDecl); noop_fold_type!(fold_ts_enum_member, TsEnumMember); noop_fold_type!(fold_ts_enum_member_id, TsEnumMemberId); @@ -385,7 +384,6 @@ macro_rules! noop_visit_type { noop_visit_type!(visit_ts_construct_signature_decl, TsConstructSignatureDecl); noop_visit_type!(visit_ts_constructor_type, TsConstructorType); noop_visit_type!(visit_ts_entity_name, TsEntityName); - noop_visit_type!(visit_ts_member_name, TsMemberName); noop_visit_type!(visit_ts_external_module_ref, TsExternalModuleRef); noop_visit_type!(visit_ts_fn_or_constructor_type, TsFnOrConstructorType); noop_visit_type!(visit_ts_fn_param, TsFnParam); @@ -451,7 +449,6 @@ macro_rules! noop_visit_mut_type { ); noop_visit_mut_type!(visit_mut_ts_constructor_type, TsConstructorType); noop_visit_mut_type!(visit_mut_ts_entity_name, TsEntityName); - noop_visit_mut_type!(visit_mut_ts_member_name, TsMemberName); noop_visit_mut_type!(visit_mut_ts_external_module_ref, TsExternalModuleRef); noop_visit_mut_type!(visit_mut_ts_fn_or_constructor_type, TsFnOrConstructorType); noop_visit_mut_type!(visit_mut_ts_fn_param, TsFnParam); @@ -1428,16 +1425,12 @@ define!({ } pub struct TsQualifiedName { pub left: TsEntityName, - pub right: TsMemberName, + pub right: Ident, } pub enum TsEntityName { TsQualifiedName(Box), Ident(Ident), } - pub enum TsMemberName { - Ident(Ident), - PrivateName(PrivateName), - } pub enum TsTypeElement { TsCallSignatureDecl(TsCallSignatureDecl), TsConstructSignatureDecl(TsConstructSignatureDecl), diff --git a/crates/swc_estree_ast/src/typescript.rs b/crates/swc_estree_ast/src/typescript.rs index 8f4030b0c87f..128238cc968b 100644 --- a/crates/swc_estree_ast/src/typescript.rs +++ b/crates/swc_estree_ast/src/typescript.rs @@ -10,7 +10,6 @@ use crate::{ object::ObjectKey, pat::AssignmentPattern, stmt::Statement, - PrivateName, }; #[derive(Debug, Clone, PartialEq)] @@ -249,8 +248,7 @@ pub struct TSQualifiedName { #[serde(flatten)] pub base: BaseNode, pub left: Box, - #[serde(flatten)] - pub right: TSMemberName, + pub right: Identifier, } #[derive(Debug, Clone, Serialize, Deserialize, PartialEq)] @@ -469,15 +467,6 @@ pub enum TSEntityName { Qualified(TSQualifiedName), } -#[derive(Debug, Clone, PartialEq)] -#[ast_serde] -pub enum TSMemberName { - #[tag("Identifier")] - Id(Identifier), - #[tag("PrivateName")] - PrivateName(PrivateName), -} - #[derive(Debug, Clone, Serialize, Deserialize, PartialEq)] #[serde(rename_all = "camelCase")] #[serde(tag = "type")] diff --git a/crates/swc_estree_compat/src/babelify/typescript.rs b/crates/swc_estree_compat/src/babelify/typescript.rs index 0d628a244a3b..d70c037d32a5 100644 --- a/crates/swc_estree_compat/src/babelify/typescript.rs +++ b/crates/swc_estree_compat/src/babelify/typescript.rs @@ -9,14 +9,14 @@ use swc_ecma_ast::{ TsExprWithTypeArgs, TsExternalModuleRef, TsFnOrConstructorType, TsFnParam, TsFnType, TsImportEqualsDecl, TsImportType, TsIndexSignature, TsIndexedAccessType, TsInferType, TsInterfaceBody, TsInterfaceDecl, TsIntersectionType, TsKeywordType, TsKeywordTypeKind, TsLit, - TsLitType, TsMappedType, TsMemberName, TsMethodSignature, TsModuleBlock, TsModuleDecl, - TsModuleName, TsModuleRef, TsNamespaceBody, TsNamespaceDecl, TsNamespaceExportDecl, - TsNonNullExpr, TsOptionalType, TsParamProp, TsParamPropParam, TsParenthesizedType, - TsPropertySignature, TsQualifiedName, TsRestType, TsThisType, TsThisTypeOrIdent, TsTplLitType, - TsTupleElement, TsTupleType, TsType, TsTypeAliasDecl, TsTypeAnn, TsTypeAssertion, - TsTypeElement, TsTypeLit, TsTypeOperator, TsTypeOperatorOp, TsTypeParam, TsTypeParamDecl, - TsTypeParamInstantiation, TsTypePredicate, TsTypeQuery, TsTypeQueryExpr, TsTypeRef, - TsUnionOrIntersectionType, TsUnionType, + TsLitType, TsMappedType, TsMethodSignature, TsModuleBlock, TsModuleDecl, TsModuleName, + TsModuleRef, TsNamespaceBody, TsNamespaceDecl, TsNamespaceExportDecl, TsNonNullExpr, + TsOptionalType, TsParamProp, TsParamPropParam, TsParenthesizedType, TsPropertySignature, + TsQualifiedName, TsRestType, TsThisType, TsThisTypeOrIdent, TsTplLitType, TsTupleElement, + TsTupleType, TsType, TsTypeAliasDecl, TsTypeAnn, TsTypeAssertion, TsTypeElement, TsTypeLit, + TsTypeOperator, TsTypeOperatorOp, TsTypeParam, TsTypeParamDecl, TsTypeParamInstantiation, + TsTypePredicate, TsTypeQuery, TsTypeQueryExpr, TsTypeRef, TsUnionOrIntersectionType, + TsUnionType, }; use swc_estree_ast::{ Access, ArrayPattern, IdOrRest, IdOrString, Identifier, ObjectPattern, RestElement, @@ -26,8 +26,8 @@ use swc_estree_ast::{ TSExpressionWithTypeArguments, TSExternalModuleReference, TSFunctionType, TSImportEqualsDeclModuleRef, TSImportEqualsDeclaration, TSImportType, TSIndexSignature, TSIndexedAccessType, TSInferType, TSInterfaceBody, TSInterfaceDeclaration, TSIntersectionType, - TSIntrinsicKeyword, TSLiteralType, TSLiteralTypeLiteral, TSMappedType, TSMemberName, - TSMethodSignature, TSModuleBlock, TSModuleDeclBody, TSModuleDeclaration, TSNamedTupleMember, + TSIntrinsicKeyword, TSLiteralType, TSLiteralTypeLiteral, TSMappedType, TSMethodSignature, + TSModuleBlock, TSModuleDeclBody, TSModuleDeclaration, TSNamedTupleMember, TSNamespaceExportDeclaration, TSNeverKeyword, TSNonNullExpression, TSNullKeyword, TSNumberKeyword, TSObjectKeyword, TSOptionalType, TSParamPropParam, TSParameterProperty, TSParenthesizedType, TSPropertySignature, TSQualifiedName, TSRestType, TSStringKeyword, @@ -192,17 +192,6 @@ impl Babelify for TsEntityName { } } -impl Babelify for TsMemberName { - type Output = TSMemberName; - - fn babelify(self, ctx: &Context) -> Self::Output { - match self { - Self::Ident(i) => Self::Output::Id(i.babelify(ctx)), - Self::PrivateName(p) => Self::Output::PrivateName(p.babelify(ctx)), - } - } -} - impl Babelify for TsTypeElement { type Output = TSTypeElement; @@ -853,8 +842,7 @@ impl Babelify for TsExprWithTypeArgs { base: ctx.base(e.span), left: Box::new(babelify_expr(*e.obj, ctx)), right: match e.prop { - MemberProp::Ident(id) => TSMemberName::Id(id.babelify(ctx)), - MemberProp::PrivateName(p) => TSMemberName::PrivateName(p.babelify(ctx)), + MemberProp::Ident(id) => id.babelify(ctx), _ => unreachable!(), }, }), diff --git a/crates/swc_estree_compat/src/swcify/class.rs b/crates/swc_estree_compat/src/swcify/class.rs index 63bd72e64437..eda0f94b53fb 100644 --- a/crates/swc_estree_compat/src/swcify/class.rs +++ b/crates/swc_estree_compat/src/swcify/class.rs @@ -1,6 +1,6 @@ use swc_ecma_ast::{ ClassMember, Expr, Function, MemberExpr, MemberProp, MethodKind, ParamOrTsParamProp, - TsExprWithTypeArgs, TsMemberName, + TsExprWithTypeArgs, }; use swc_estree_ast::{ ClassBody, ClassBodyEl, ClassImpl, ClassMethodKind, TSEntityName, @@ -198,10 +198,7 @@ impl Swcify for TSExpressionWithTypeArguments { fn swcify_qualified_name(qualified_name: TSQualifiedName, ctx: &Context) -> Box { Box::new(Expr::Member(MemberExpr { obj: swcify_expr(*qualified_name.left, ctx), - prop: match qualified_name.right.swcify(ctx) { - TsMemberName::Ident(id) => MemberProp::Ident(id), - TsMemberName::PrivateName(p) => MemberProp::PrivateName(p), - }, + prop: MemberProp::Ident(qualified_name.right.swcify(ctx).id), span: ctx.span(&qualified_name.base), })) } diff --git a/crates/swc_estree_compat/src/swcify/typescript.rs b/crates/swc_estree_compat/src/swcify/typescript.rs index 2da16fe346d7..9be83ae05816 100644 --- a/crates/swc_estree_compat/src/swcify/typescript.rs +++ b/crates/swc_estree_compat/src/swcify/typescript.rs @@ -1,11 +1,11 @@ use swc_ecma_ast::{ - Accessibility, Ident, TsEntityName, TsMemberName, TsQualifiedName, TsType, TsTypeAnn, - TsTypeParam, TsTypeParamDecl, TsTypeParamInstantiation, + Accessibility, Ident, TsEntityName, TsQualifiedName, TsType, TsTypeAnn, TsTypeParam, + TsTypeParamDecl, TsTypeParamInstantiation, }; use swc_estree_ast::{ - Access, FlowType, SuperTypeParams, TSEntityName, TSMemberName, TSQualifiedName, TSType, - TSTypeAnnotation, TSTypeParameter, TSTypeParameterDeclaration, TSTypeParameterInstantiation, - TypeAnnotOrNoop, TypeParamDeclOrNoop, + Access, FlowType, SuperTypeParams, TSEntityName, TSQualifiedName, TSType, TSTypeAnnotation, + TSTypeParameter, TSTypeParameterDeclaration, TSTypeParameterInstantiation, TypeAnnotOrNoop, + TypeParamDeclOrNoop, }; use super::Context; @@ -140,18 +140,7 @@ impl Swcify for TSQualifiedName { fn swcify(self, ctx: &Context) -> Self::Output { TsQualifiedName { left: self.left.swcify(ctx), - right: self.right.swcify(ctx), - } - } -} - -impl Swcify for TSMemberName { - type Output = TsMemberName; - - fn swcify(self, ctx: &Context) -> Self::Output { - match self { - Self::Id(id) => Self::Output::Ident(id.swcify(ctx).id), - Self::PrivateName(p) => Self::Output::Ident(p.swcify(ctx).id), + right: self.right.swcify(ctx).id, } } }