diff --git a/crates/swc_ecma_parser/src/parser/class_and_fn.rs b/crates/swc_ecma_parser/src/parser/class_and_fn.rs index d915acabe811..d1fe9d395a7e 100644 --- a/crates/swc_ecma_parser/src/parser/class_and_fn.rs +++ b/crates/swc_ecma_parser/src/parser/class_and_fn.rs @@ -482,7 +482,7 @@ impl Parser { is_override: false, is_async: false, is_generator: false, - static_token: None, + static_token, key, kind: MethodKind::Method, }, @@ -497,12 +497,13 @@ impl Parser { accessor_token, ))); let is_optional = self.input.syntax().typescript() && eat!(self, '?'); + let is_static = static_token.is_some(); return self.make_property( start, decorators, accessibility, key, - false, + is_static, None, is_optional, false, diff --git a/crates/swc_ecma_parser/tests/typescript/issue-7042/case3/input.ts b/crates/swc_ecma_parser/tests/typescript/issue-7042/case3/input.ts new file mode 100644 index 000000000000..f2f185c27993 --- /dev/null +++ b/crates/swc_ecma_parser/tests/typescript/issue-7042/case3/input.ts @@ -0,0 +1,5 @@ +class SomeClass { + static accessor() { + return 'accessor'; + } +} diff --git a/crates/swc_ecma_parser/tests/typescript/issue-7042/case3/input.ts.json b/crates/swc_ecma_parser/tests/typescript/issue-7042/case3/input.ts.json new file mode 100644 index 000000000000..83a234ab6b85 --- /dev/null +++ b/crates/swc_ecma_parser/tests/typescript/issue-7042/case3/input.ts.json @@ -0,0 +1,103 @@ +{ + "type": "Script", + "span": { + "start": 1, + "end": 77, + "ctxt": 0 + }, + "body": [ + { + "type": "ClassDeclaration", + "identifier": { + "type": "Identifier", + "span": { + "start": 7, + "end": 16, + "ctxt": 0 + }, + "value": "SomeClass", + "optional": false + }, + "declare": false, + "span": { + "start": 1, + "end": 77, + "ctxt": 0 + }, + "decorators": [], + "body": [ + { + "type": "ClassMethod", + "span": { + "start": 23, + "end": 75, + "ctxt": 0 + }, + "key": { + "type": "Identifier", + "span": { + "start": 30, + "end": 38, + "ctxt": 0 + }, + "value": "accessor", + "optional": false + }, + "function": { + "params": [], + "decorators": [], + "span": { + "start": 23, + "end": 75, + "ctxt": 0 + }, + "body": { + "type": "BlockStatement", + "span": { + "start": 41, + "end": 75, + "ctxt": 0 + }, + "stmts": [ + { + "type": "ReturnStatement", + "span": { + "start": 51, + "end": 69, + "ctxt": 0 + }, + "argument": { + "type": "StringLiteral", + "span": { + "start": 58, + "end": 68, + "ctxt": 0 + }, + "value": "accessor", + "raw": "'accessor'" + } + } + ] + }, + "generator": false, + "async": false, + "typeParameters": null, + "returnType": null + }, + "kind": "method", + "isStatic": true, + "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_typescript/tests/fixture/issue-7042/case3/input.ts b/crates/swc_ecma_transforms_typescript/tests/fixture/issue-7042/case3/input.ts new file mode 100644 index 000000000000..f2f185c27993 --- /dev/null +++ b/crates/swc_ecma_transforms_typescript/tests/fixture/issue-7042/case3/input.ts @@ -0,0 +1,5 @@ +class SomeClass { + static accessor() { + return 'accessor'; + } +} diff --git a/crates/swc_ecma_transforms_typescript/tests/fixture/issue-7042/case3/output.js b/crates/swc_ecma_transforms_typescript/tests/fixture/issue-7042/case3/output.js new file mode 100644 index 000000000000..f2f185c27993 --- /dev/null +++ b/crates/swc_ecma_transforms_typescript/tests/fixture/issue-7042/case3/output.js @@ -0,0 +1,5 @@ +class SomeClass { + static accessor() { + return 'accessor'; + } +}