From a0db3f3ac0a2cc401a61ff88b02b75e61f7dba86 Mon Sep 17 00:00:00 2001 From: David Sherret Date: Tue, 19 Dec 2023 17:17:56 -0500 Subject: [PATCH 01/14] fix(es/ast): Add definite to AutoAccessor --- crates/swc_ecma_ast/src/class.rs | 4 ++ crates/swc_ecma_codegen/src/lib.rs | 9 +++ .../fixture/typescript/class_prop/input.js | 1 + .../fixture/typescript/class_prop/output.js | 1 + .../typescript/class_prop/output.min.js | 2 +- .../src/parser/class_and_fn.rs | 1 + .../tests/tsc/autoAccessor1.json | 56 +++++++++++++++++-- .../tests/tsc/autoAccessor1.ts | 1 + .../tests/tsc/autoAccessor10.json | 15 +++-- .../tests/tsc/autoAccessor2.json | 12 ++-- .../tests/tsc/autoAccessor3.json | 12 ++-- .../tests/tsc/autoAccessor4.json | 12 ++-- .../tests/tsc/autoAccessor6.json | 3 +- .../tests/tsc/autoAccessor7.json | 6 +- .../tests/tsc/autoAccessor8.json | 18 ++++-- .../tests/tsc/autoAccessor9.json | 18 ++++-- .../tsc/autoAccessorAllowedModifiers.json | 51 +++++++++++------ ...autoAccessorNoUseDefineForClassFields.json | 24 +++++--- .../src/strip_type.rs | 7 +++ crates/swc_ecma_visit/src/lib.rs | 1 + 20 files changed, 190 insertions(+), 64 deletions(-) diff --git a/crates/swc_ecma_ast/src/class.rs b/crates/swc_ecma_ast/src/class.rs index ba3762e2fae3..17fbbd929b8c 100644 --- a/crates/swc_ecma_ast/src/class.rs +++ b/crates/swc_ecma_ast/src/class.rs @@ -331,6 +331,9 @@ pub struct AutoAccessor { /// Typescript extension. #[cfg_attr(feature = "serde-impl", serde(default))] pub accessibility: Option, + + #[cfg_attr(feature = "serde-impl", serde(default))] + pub definite: bool, } impl Take for AutoAccessor { @@ -343,6 +346,7 @@ impl Take for AutoAccessor { is_static: false, decorators: Take::dummy(), accessibility: None, + definite: false, } } } diff --git a/crates/swc_ecma_codegen/src/lib.rs b/crates/swc_ecma_codegen/src/lib.rs index 5b825db2abd2..3ce6eff76b21 100644 --- a/crates/swc_ecma_codegen/src/lib.rs +++ b/crates/swc_ecma_codegen/src/lib.rs @@ -1345,6 +1345,15 @@ where emit!(n.key); + if let Some(type_ann) = &n.type_ann { + if n.definite { + punct!("!"); + } + punct!(":"); + space!(); + emit!(type_ann); + } + if let Some(init) = &n.value { formatting_space!(); punct!("="); diff --git a/crates/swc_ecma_codegen/tests/fixture/typescript/class_prop/input.js b/crates/swc_ecma_codegen/tests/fixture/typescript/class_prop/input.js index b5325b3ca63e..c32aacf3132d 100644 --- a/crates/swc_ecma_codegen/tests/fixture/typescript/class_prop/input.js +++ b/crates/swc_ecma_codegen/tests/fixture/typescript/class_prop/input.js @@ -5,4 +5,5 @@ class MyClass { #prop4?: string = "test"; static readonly prop5!: string; readonly #prop6 = "asdf"; + accessor prop7!: string = ""; } diff --git a/crates/swc_ecma_codegen/tests/fixture/typescript/class_prop/output.js b/crates/swc_ecma_codegen/tests/fixture/typescript/class_prop/output.js index b5325b3ca63e..c32aacf3132d 100644 --- a/crates/swc_ecma_codegen/tests/fixture/typescript/class_prop/output.js +++ b/crates/swc_ecma_codegen/tests/fixture/typescript/class_prop/output.js @@ -5,4 +5,5 @@ class MyClass { #prop4?: string = "test"; static readonly prop5!: string; readonly #prop6 = "asdf"; + accessor prop7!: string = ""; } diff --git a/crates/swc_ecma_codegen/tests/fixture/typescript/class_prop/output.min.js b/crates/swc_ecma_codegen/tests/fixture/typescript/class_prop/output.min.js index 4d6c0686d641..7a1eceb165e2 100644 --- a/crates/swc_ecma_codegen/tests/fixture/typescript/class_prop/output.min.js +++ b/crates/swc_ecma_codegen/tests/fixture/typescript/class_prop/output.min.js @@ -1 +1 @@ -class MyClass{prop1?: string;prop2!: string;#prop3?: string;#prop4?: string="test";static readonly prop5!: string;readonly #prop6="asdf"} +class MyClass{prop1?: string;prop2!: string;#prop3?: string;#prop4?: string="test";static readonly prop5!: string;readonly #prop6="asdf";accessor prop7!: string=""} 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 8b3a7324b526..bbcadbc3bb40 100644 --- a/crates/swc_ecma_parser/src/parser/class_and_fn.rs +++ b/crates/swc_ecma_parser/src/parser/class_and_fn.rs @@ -1092,6 +1092,7 @@ impl Parser { is_static, decorators, accessibility, + definite, })); } diff --git a/crates/swc_ecma_parser/tests/tsc/autoAccessor1.json b/crates/swc_ecma_parser/tests/tsc/autoAccessor1.json index 49a932136390..a8bb8cfcb128 100644 --- a/crates/swc_ecma_parser/tests/tsc/autoAccessor1.json +++ b/crates/swc_ecma_parser/tests/tsc/autoAccessor1.json @@ -2,7 +2,7 @@ "type": "Script", "span": { "start": 66, - "end": 174, + "end": 199, "ctxt": 0 }, "body": [ @@ -21,7 +21,7 @@ "declare": false, "span": { "start": 66, - "end": 174, + "end": 199, "ctxt": 0 }, "decorators": [], @@ -63,7 +63,8 @@ }, "isStatic": false, "decorators": [], - "accessibility": null + "accessibility": null, + "definite": false }, { "type": "AutoAccessor", @@ -95,7 +96,8 @@ "typeAnnotation": null, "isStatic": false, "decorators": [], - "accessibility": null + "accessibility": null, + "definite": false }, { "type": "AutoAccessor", @@ -134,7 +136,8 @@ }, "isStatic": true, "decorators": [], - "accessibility": null + "accessibility": null, + "definite": false }, { "type": "AutoAccessor", @@ -166,7 +169,48 @@ "typeAnnotation": null, "isStatic": true, "decorators": [], - "accessibility": null + "accessibility": null, + "definite": false + }, + { + "type": "AutoAccessor", + "span": { + "start": 177, + "end": 197, + "ctxt": 0 + }, + "key": { + "type": "Identifier", + "span": { + "start": 186, + "end": 187, + "ctxt": 0 + }, + "value": "e", + "optional": false + }, + "value": null, + "typeAnnotation": { + "type": "TsTypeAnnotation", + "span": { + "start": 188, + "end": 196, + "ctxt": 0 + }, + "typeAnnotation": { + "type": "TsKeywordType", + "span": { + "start": 190, + "end": 196, + "ctxt": 0 + }, + "kind": "string" + } + }, + "isStatic": false, + "decorators": [], + "accessibility": null, + "definite": true } ], "superClass": null, diff --git a/crates/swc_ecma_parser/tests/tsc/autoAccessor1.ts b/crates/swc_ecma_parser/tests/tsc/autoAccessor1.ts index aab966c7f874..d886c8840f07 100644 --- a/crates/swc_ecma_parser/tests/tsc/autoAccessor1.ts +++ b/crates/swc_ecma_parser/tests/tsc/autoAccessor1.ts @@ -6,4 +6,5 @@ class C1 { accessor b = 1; static accessor c: any; static accessor d = 2; + accessor e!: string; } diff --git a/crates/swc_ecma_parser/tests/tsc/autoAccessor10.json b/crates/swc_ecma_parser/tests/tsc/autoAccessor10.json index 414775327d1a..5770c9df2508 100644 --- a/crates/swc_ecma_parser/tests/tsc/autoAccessor10.json +++ b/crates/swc_ecma_parser/tests/tsc/autoAccessor10.json @@ -56,7 +56,8 @@ "typeAnnotation": null, "isStatic": false, "decorators": [], - "accessibility": null + "accessibility": null, + "definite": false } ], "superClass": null, @@ -159,7 +160,8 @@ "typeAnnotation": null, "isStatic": false, "decorators": [], - "accessibility": null + "accessibility": null, + "definite": false } ], "superClass": null, @@ -297,7 +299,8 @@ "typeAnnotation": null, "isStatic": false, "decorators": [], - "accessibility": null + "accessibility": null, + "definite": false }, { "type": "StaticBlock", @@ -429,7 +432,8 @@ "typeAnnotation": null, "isStatic": true, "decorators": [], - "accessibility": null + "accessibility": null, + "definite": false } ], "superClass": null, @@ -488,7 +492,8 @@ "typeAnnotation": null, "isStatic": true, "decorators": [], - "accessibility": null + "accessibility": null, + "definite": false } ], "superClass": null, diff --git a/crates/swc_ecma_parser/tests/tsc/autoAccessor2.json b/crates/swc_ecma_parser/tests/tsc/autoAccessor2.json index 3a24ab3e0362..586fa1a6aa3e 100644 --- a/crates/swc_ecma_parser/tests/tsc/autoAccessor2.json +++ b/crates/swc_ecma_parser/tests/tsc/autoAccessor2.json @@ -71,7 +71,8 @@ }, "isStatic": false, "decorators": [], - "accessibility": null + "accessibility": null, + "definite": false }, { "type": "AutoAccessor", @@ -111,7 +112,8 @@ "typeAnnotation": null, "isStatic": false, "decorators": [], - "accessibility": null + "accessibility": null, + "definite": false }, { "type": "AutoAccessor", @@ -158,7 +160,8 @@ }, "isStatic": true, "decorators": [], - "accessibility": null + "accessibility": null, + "definite": false }, { "type": "AutoAccessor", @@ -198,7 +201,8 @@ "typeAnnotation": null, "isStatic": true, "decorators": [], - "accessibility": null + "accessibility": null, + "definite": false }, { "type": "Constructor", diff --git a/crates/swc_ecma_parser/tests/tsc/autoAccessor3.json b/crates/swc_ecma_parser/tests/tsc/autoAccessor3.json index 4adbffce24a6..1ff730de115f 100644 --- a/crates/swc_ecma_parser/tests/tsc/autoAccessor3.json +++ b/crates/swc_ecma_parser/tests/tsc/autoAccessor3.json @@ -63,7 +63,8 @@ }, "isStatic": false, "decorators": [], - "accessibility": null + "accessibility": null, + "definite": false }, { "type": "AutoAccessor", @@ -95,7 +96,8 @@ "typeAnnotation": null, "isStatic": false, "decorators": [], - "accessibility": null + "accessibility": null, + "definite": false }, { "type": "AutoAccessor", @@ -134,7 +136,8 @@ }, "isStatic": true, "decorators": [], - "accessibility": null + "accessibility": null, + "definite": false }, { "type": "AutoAccessor", @@ -166,7 +169,8 @@ "typeAnnotation": null, "isStatic": true, "decorators": [], - "accessibility": null + "accessibility": null, + "definite": false } ], "superClass": null, diff --git a/crates/swc_ecma_parser/tests/tsc/autoAccessor4.json b/crates/swc_ecma_parser/tests/tsc/autoAccessor4.json index abe3579415d7..5b2f53d49aaf 100644 --- a/crates/swc_ecma_parser/tests/tsc/autoAccessor4.json +++ b/crates/swc_ecma_parser/tests/tsc/autoAccessor4.json @@ -63,7 +63,8 @@ }, "isStatic": false, "decorators": [], - "accessibility": null + "accessibility": null, + "definite": false }, { "type": "AutoAccessor", @@ -95,7 +96,8 @@ "typeAnnotation": null, "isStatic": false, "decorators": [], - "accessibility": null + "accessibility": null, + "definite": false }, { "type": "AutoAccessor", @@ -134,7 +136,8 @@ }, "isStatic": true, "decorators": [], - "accessibility": null + "accessibility": null, + "definite": false }, { "type": "AutoAccessor", @@ -166,7 +169,8 @@ "typeAnnotation": null, "isStatic": true, "decorators": [], - "accessibility": null + "accessibility": null, + "definite": false } ], "superClass": null, diff --git a/crates/swc_ecma_parser/tests/tsc/autoAccessor6.json b/crates/swc_ecma_parser/tests/tsc/autoAccessor6.json index 56185dd23193..ad503e5fb875 100644 --- a/crates/swc_ecma_parser/tests/tsc/autoAccessor6.json +++ b/crates/swc_ecma_parser/tests/tsc/autoAccessor6.json @@ -63,7 +63,8 @@ }, "isStatic": false, "decorators": [], - "accessibility": null + "accessibility": null, + "definite": false } ], "superClass": null, diff --git a/crates/swc_ecma_parser/tests/tsc/autoAccessor7.json b/crates/swc_ecma_parser/tests/tsc/autoAccessor7.json index eb0663baba78..4a26b66222df 100644 --- a/crates/swc_ecma_parser/tests/tsc/autoAccessor7.json +++ b/crates/swc_ecma_parser/tests/tsc/autoAccessor7.json @@ -63,7 +63,8 @@ }, "isStatic": false, "decorators": [], - "accessibility": null + "accessibility": null, + "definite": false } ], "superClass": null, @@ -122,7 +123,8 @@ "typeAnnotation": null, "isStatic": false, "decorators": [], - "accessibility": null + "accessibility": null, + "definite": false } ], "superClass": { diff --git a/crates/swc_ecma_parser/tests/tsc/autoAccessor8.json b/crates/swc_ecma_parser/tests/tsc/autoAccessor8.json index 7485aefb562a..aaba2edacfa6 100644 --- a/crates/swc_ecma_parser/tests/tsc/autoAccessor8.json +++ b/crates/swc_ecma_parser/tests/tsc/autoAccessor8.json @@ -63,7 +63,8 @@ }, "isStatic": false, "decorators": [], - "accessibility": null + "accessibility": null, + "definite": false }, { "type": "AutoAccessor", @@ -102,7 +103,8 @@ }, "isStatic": true, "decorators": [], - "accessibility": null + "accessibility": null, + "definite": false } ], "superClass": null, @@ -168,7 +170,8 @@ }, "isStatic": false, "decorators": [], - "accessibility": null + "accessibility": null, + "definite": false }, { "type": "AutoAccessor", @@ -207,7 +210,8 @@ }, "isStatic": true, "decorators": [], - "accessibility": null + "accessibility": null, + "definite": false } ], "superClass": null, @@ -301,7 +305,8 @@ }, "isStatic": false, "decorators": [], - "accessibility": null + "accessibility": null, + "definite": false }, { "type": "AutoAccessor", @@ -340,7 +345,8 @@ }, "isStatic": true, "decorators": [], - "accessibility": null + "accessibility": null, + "definite": false } ], "superClass": null, diff --git a/crates/swc_ecma_parser/tests/tsc/autoAccessor9.json b/crates/swc_ecma_parser/tests/tsc/autoAccessor9.json index 6c6b4ce6da44..48b5455e9e30 100644 --- a/crates/swc_ecma_parser/tests/tsc/autoAccessor9.json +++ b/crates/swc_ecma_parser/tests/tsc/autoAccessor9.json @@ -56,7 +56,8 @@ "typeAnnotation": null, "isStatic": false, "decorators": [], - "accessibility": null + "accessibility": null, + "definite": false } ], "superClass": null, @@ -153,7 +154,8 @@ "typeAnnotation": null, "isStatic": false, "decorators": [], - "accessibility": null + "accessibility": null, + "definite": false }, { "type": "ClassProperty", @@ -294,7 +296,8 @@ "typeAnnotation": null, "isStatic": false, "decorators": [], - "accessibility": null + "accessibility": null, + "definite": false } ], "superClass": null, @@ -544,7 +547,8 @@ "typeAnnotation": null, "isStatic": false, "decorators": [], - "accessibility": null + "accessibility": null, + "definite": false }, { "type": "ClassProperty", @@ -641,7 +645,8 @@ "typeAnnotation": null, "isStatic": true, "decorators": [], - "accessibility": null + "accessibility": null, + "definite": false } ], "superClass": null, @@ -738,7 +743,8 @@ "typeAnnotation": null, "isStatic": true, "decorators": [], - "accessibility": null + "accessibility": null, + "definite": false }, { "type": "ClassProperty", diff --git a/crates/swc_ecma_parser/tests/tsc/autoAccessorAllowedModifiers.json b/crates/swc_ecma_parser/tests/tsc/autoAccessorAllowedModifiers.json index 63687e7c38eb..aed69a088ca2 100644 --- a/crates/swc_ecma_parser/tests/tsc/autoAccessorAllowedModifiers.json +++ b/crates/swc_ecma_parser/tests/tsc/autoAccessorAllowedModifiers.json @@ -63,7 +63,8 @@ }, "isStatic": false, "decorators": [], - "accessibility": null + "accessibility": null, + "definite": false }, { "type": "AutoAccessor", @@ -102,7 +103,8 @@ }, "isStatic": false, "decorators": [], - "accessibility": "public" + "accessibility": "public", + "definite": false }, { "type": "AutoAccessor", @@ -141,7 +143,8 @@ }, "isStatic": false, "decorators": [], - "accessibility": "private" + "accessibility": "private", + "definite": false }, { "type": "AutoAccessor", @@ -180,7 +183,8 @@ }, "isStatic": false, "decorators": [], - "accessibility": "protected" + "accessibility": "protected", + "definite": false }, { "type": "AutoAccessor", @@ -219,7 +223,8 @@ }, "isStatic": false, "decorators": [], - "accessibility": null + "accessibility": null, + "definite": false }, { "type": "AutoAccessor", @@ -258,7 +263,8 @@ }, "isStatic": true, "decorators": [], - "accessibility": null + "accessibility": null, + "definite": false }, { "type": "AutoAccessor", @@ -297,7 +303,8 @@ }, "isStatic": true, "decorators": [], - "accessibility": "public" + "accessibility": "public", + "definite": false }, { "type": "AutoAccessor", @@ -336,7 +343,8 @@ }, "isStatic": true, "decorators": [], - "accessibility": "private" + "accessibility": "private", + "definite": false }, { "type": "AutoAccessor", @@ -375,7 +383,8 @@ }, "isStatic": true, "decorators": [], - "accessibility": "protected" + "accessibility": "protected", + "definite": false }, { "type": "AutoAccessor", @@ -422,7 +431,8 @@ }, "isStatic": false, "decorators": [], - "accessibility": null + "accessibility": null, + "definite": false }, { "type": "AutoAccessor", @@ -461,7 +471,8 @@ }, "isStatic": false, "decorators": [], - "accessibility": null + "accessibility": null, + "definite": false }, { "type": "AutoAccessor", @@ -500,7 +511,8 @@ }, "isStatic": false, "decorators": [], - "accessibility": null + "accessibility": null, + "definite": false }, { "type": "AutoAccessor", @@ -547,7 +559,8 @@ }, "isStatic": false, "decorators": [], - "accessibility": null + "accessibility": null, + "definite": false }, { "type": "AutoAccessor", @@ -586,7 +599,8 @@ }, "isStatic": false, "decorators": [], - "accessibility": null + "accessibility": null, + "definite": true } ], "superClass": null, @@ -652,7 +666,8 @@ }, "isStatic": false, "decorators": [], - "accessibility": null + "accessibility": null, + "definite": false }, { "type": "AutoAccessor", @@ -691,7 +706,8 @@ }, "isStatic": true, "decorators": [], - "accessibility": null + "accessibility": null, + "definite": false } ], "superClass": { @@ -766,7 +782,8 @@ }, "isStatic": false, "decorators": [], - "accessibility": null + "accessibility": null, + "definite": false } ], "superClass": null, diff --git a/crates/swc_ecma_parser/tests/tsc/autoAccessorNoUseDefineForClassFields.json b/crates/swc_ecma_parser/tests/tsc/autoAccessorNoUseDefineForClassFields.json index 25f5f047eb51..07e80e2420a1 100644 --- a/crates/swc_ecma_parser/tests/tsc/autoAccessorNoUseDefineForClassFields.json +++ b/crates/swc_ecma_parser/tests/tsc/autoAccessorNoUseDefineForClassFields.json @@ -56,7 +56,8 @@ "typeAnnotation": null, "isStatic": true, "decorators": [], - "accessibility": null + "accessibility": null, + "definite": false } ], "superClass": null, @@ -123,7 +124,8 @@ "typeAnnotation": null, "isStatic": true, "decorators": [], - "accessibility": null + "accessibility": null, + "definite": false } ], "superClass": null, @@ -190,7 +192,8 @@ "typeAnnotation": null, "isStatic": true, "decorators": [], - "accessibility": null + "accessibility": null, + "definite": false }, { "type": "AutoAccessor", @@ -230,7 +233,8 @@ "typeAnnotation": null, "isStatic": false, "decorators": [], - "accessibility": null + "accessibility": null, + "definite": false } ], "superClass": null, @@ -289,7 +293,8 @@ "typeAnnotation": null, "isStatic": false, "decorators": [], - "accessibility": null + "accessibility": null, + "definite": false } ], "superClass": null, @@ -356,7 +361,8 @@ "typeAnnotation": null, "isStatic": false, "decorators": [], - "accessibility": null + "accessibility": null, + "definite": false } ], "superClass": null, @@ -461,7 +467,8 @@ "typeAnnotation": null, "isStatic": false, "decorators": [], - "accessibility": null + "accessibility": null, + "definite": false } ], "superClass": null, @@ -528,7 +535,8 @@ "typeAnnotation": null, "isStatic": false, "decorators": [], - "accessibility": null + "accessibility": null, + "definite": false }, { "type": "ClassProperty", diff --git a/crates/swc_ecma_transforms_typescript/src/strip_type.rs b/crates/swc_ecma_transforms_typescript/src/strip_type.rs index b62a9b145774..a44a4d1a6be8 100644 --- a/crates/swc_ecma_transforms_typescript/src/strip_type.rs +++ b/crates/swc_ecma_transforms_typescript/src/strip_type.rs @@ -158,6 +158,13 @@ impl VisitMut for StripType { prop.visit_mut_children_with(self); } + fn visit_mut_auto_accessor(&mut self,n: &mut AutoAccessor) { + n.type_ann = None; + n.accessibility = None; + n.definite = false; + n.visit_mut_children_with(self); + } + fn visit_mut_ts_import_equals_decl(&mut self, _: &mut TsImportEqualsDecl) { // n.id.visit_mut_with(self); } diff --git a/crates/swc_ecma_visit/src/lib.rs b/crates/swc_ecma_visit/src/lib.rs index 1fd732a068f0..20ea1fbc6e38 100644 --- a/crates/swc_ecma_visit/src/lib.rs +++ b/crates/swc_ecma_visit/src/lib.rs @@ -1878,6 +1878,7 @@ define!({ pub is_static: bool, pub decorators: Vec, pub accessibility: Option, + pub definite: bool, } pub enum Key { From 501a5d736e34d09ce03a30974a1dff4799e09f86 Mon Sep 17 00:00:00 2001 From: David Sherret Date: Tue, 19 Dec 2023 17:27:51 -0500 Subject: [PATCH 02/14] Format --- crates/swc_ecma_transforms_typescript/src/strip_type.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/swc_ecma_transforms_typescript/src/strip_type.rs b/crates/swc_ecma_transforms_typescript/src/strip_type.rs index a44a4d1a6be8..1bc214449eea 100644 --- a/crates/swc_ecma_transforms_typescript/src/strip_type.rs +++ b/crates/swc_ecma_transforms_typescript/src/strip_type.rs @@ -158,7 +158,7 @@ impl VisitMut for StripType { prop.visit_mut_children_with(self); } - fn visit_mut_auto_accessor(&mut self,n: &mut AutoAccessor) { + fn visit_mut_auto_accessor(&mut self, n: &mut AutoAccessor) { n.type_ann = None; n.accessibility = None; n.definite = false; From 0dd58fc7f7a52f30842ab21861ae194e36d760f2 Mon Sep 17 00:00:00 2001 From: David Sherret Date: Tue, 19 Dec 2023 17:39:14 -0500 Subject: [PATCH 03/14] Add transform test --- .../tests/fixture/auto-accessor/input.ts | 4 ++++ .../tests/fixture/auto-accessor/output.js | 4 ++++ 2 files changed, 8 insertions(+) create mode 100644 crates/swc_ecma_transforms_typescript/tests/fixture/auto-accessor/input.ts create mode 100644 crates/swc_ecma_transforms_typescript/tests/fixture/auto-accessor/output.js diff --git a/crates/swc_ecma_transforms_typescript/tests/fixture/auto-accessor/input.ts b/crates/swc_ecma_transforms_typescript/tests/fixture/auto-accessor/input.ts new file mode 100644 index 000000000000..f8ef5d5f6299 --- /dev/null +++ b/crates/swc_ecma_transforms_typescript/tests/fixture/auto-accessor/input.ts @@ -0,0 +1,4 @@ +class Test { + accessor a!: string; + accessor b: string = ""; +} diff --git a/crates/swc_ecma_transforms_typescript/tests/fixture/auto-accessor/output.js b/crates/swc_ecma_transforms_typescript/tests/fixture/auto-accessor/output.js new file mode 100644 index 000000000000..16d278ae6d4e --- /dev/null +++ b/crates/swc_ecma_transforms_typescript/tests/fixture/auto-accessor/output.js @@ -0,0 +1,4 @@ +class Test { + accessor a; + accessor b = ""; +} From 78ffec7216974b5c7453c1c132c6b265c9e6aa4b Mon Sep 17 00:00:00 2001 From: David Sherret Date: Tue, 19 Dec 2023 17:40:11 -0500 Subject: [PATCH 04/14] Forgot to add accessibility test --- .../tests/fixture/auto-accessor/input.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/swc_ecma_transforms_typescript/tests/fixture/auto-accessor/input.ts b/crates/swc_ecma_transforms_typescript/tests/fixture/auto-accessor/input.ts index f8ef5d5f6299..0ba07cdf0630 100644 --- a/crates/swc_ecma_transforms_typescript/tests/fixture/auto-accessor/input.ts +++ b/crates/swc_ecma_transforms_typescript/tests/fixture/auto-accessor/input.ts @@ -1,4 +1,4 @@ class Test { - accessor a!: string; - accessor b: string = ""; + accessor a!: string; + public accessor b: string = ""; } From c76b37260d6e7821b82b388e579d34db77484961 Mon Sep 17 00:00:00 2001 From: David Sherret Date: Tue, 19 Dec 2023 17:43:47 -0500 Subject: [PATCH 05/14] Emit accessibility for accessor --- crates/swc_ecma_codegen/src/lib.rs | 6 +++--- .../tests/fixture/typescript/class_prop/input.js | 4 ++++ .../tests/fixture/typescript/class_prop/output.js | 4 ++++ .../tests/fixture/typescript/class_prop/output.min.js | 2 +- 4 files changed, 12 insertions(+), 4 deletions(-) diff --git a/crates/swc_ecma_codegen/src/lib.rs b/crates/swc_ecma_codegen/src/lib.rs index 3ce6eff76b21..4d80ee1d67fc 100644 --- a/crates/swc_ecma_codegen/src/lib.rs +++ b/crates/swc_ecma_codegen/src/lib.rs @@ -1335,6 +1335,8 @@ where fn emit_auto_accessor(&mut self, n: &AutoAccessor) -> Result { self.emit_list(n.span, Some(&n.decorators), ListFormat::Decorators)?; + self.emit_accessibility(n.accessibility)?; + if n.is_static { keyword!("static"); space!(); @@ -1581,9 +1583,7 @@ where emit!(dec) } - if n.accessibility != Some(Accessibility::Public) { - self.emit_accessibility(n.accessibility)?; - } + self.emit_accessibility(n.accessibility)?; if n.is_static { keyword!("static"); diff --git a/crates/swc_ecma_codegen/tests/fixture/typescript/class_prop/input.js b/crates/swc_ecma_codegen/tests/fixture/typescript/class_prop/input.js index c32aacf3132d..511b7bbab6a0 100644 --- a/crates/swc_ecma_codegen/tests/fixture/typescript/class_prop/input.js +++ b/crates/swc_ecma_codegen/tests/fixture/typescript/class_prop/input.js @@ -6,4 +6,8 @@ class MyClass { static readonly prop5!: string; readonly #prop6 = "asdf"; accessor prop7!: string = ""; + public accessor prop8 = ""; + public static accessor prop8 = ""; + public prop9: string; + private static prop10: string; } diff --git a/crates/swc_ecma_codegen/tests/fixture/typescript/class_prop/output.js b/crates/swc_ecma_codegen/tests/fixture/typescript/class_prop/output.js index c32aacf3132d..511b7bbab6a0 100644 --- a/crates/swc_ecma_codegen/tests/fixture/typescript/class_prop/output.js +++ b/crates/swc_ecma_codegen/tests/fixture/typescript/class_prop/output.js @@ -6,4 +6,8 @@ class MyClass { static readonly prop5!: string; readonly #prop6 = "asdf"; accessor prop7!: string = ""; + public accessor prop8 = ""; + public static accessor prop8 = ""; + public prop9: string; + private static prop10: string; } diff --git a/crates/swc_ecma_codegen/tests/fixture/typescript/class_prop/output.min.js b/crates/swc_ecma_codegen/tests/fixture/typescript/class_prop/output.min.js index 7a1eceb165e2..44d7ce64aa7c 100644 --- a/crates/swc_ecma_codegen/tests/fixture/typescript/class_prop/output.min.js +++ b/crates/swc_ecma_codegen/tests/fixture/typescript/class_prop/output.min.js @@ -1 +1 @@ -class MyClass{prop1?: string;prop2!: string;#prop3?: string;#prop4?: string="test";static readonly prop5!: string;readonly #prop6="asdf";accessor prop7!: string=""} +class MyClass{prop1?: string;prop2!: string;#prop3?: string;#prop4?: string="test";static readonly prop5!: string;readonly #prop6="asdf";accessor prop7!: string="";public accessor prop8="";public static accessor prop8="";public prop9: string;private static prop10: string} From 8f757e6b671f2967ab6fc6e4c300ce40188b0de5 Mon Sep 17 00:00:00 2001 From: David Sherret Date: Tue, 19 Dec 2023 18:59:03 -0500 Subject: [PATCH 06/14] Run --all-features --- .../tests/fixture/legacy-only/issues/862/1/output.ts | 12 ++++++------ .../tests/fixture/legacy-only/issues/862/2/output.ts | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/crates/swc_ecma_transforms/tests/fixture/legacy-only/issues/862/1/output.ts b/crates/swc_ecma_transforms/tests/fixture/legacy-only/issues/862/1/output.ts index 224206c1f376..0f94a1b1115a 100644 --- a/crates/swc_ecma_transforms/tests/fixture/legacy-only/issues/862/1/output.ts +++ b/crates/swc_ecma_transforms/tests/fixture/legacy-only/issues/862/1/output.ts @@ -1,10 +1,10 @@ export class Product extends TimestampedEntity { - id!: string; - price!: number; - type!: ProductType; - productEntityId!: string; - /* ANCHOR: Relations ------------------------------------------------------ */ orders!: Order[]; - discounts!: Discount[]; + public id!: string; + public price!: number; + public type!: ProductType; + public productEntityId!: string; + /* ANCHOR: Relations ------------------------------------------------------ */ public orders!: Order[]; + public discounts!: Discount[]; } _ts_decorate([ PrimaryGeneratedColumn("uuid") diff --git a/crates/swc_ecma_transforms/tests/fixture/legacy-only/issues/862/2/output.ts b/crates/swc_ecma_transforms/tests/fixture/legacy-only/issues/862/2/output.ts index 1642c73ce823..0fa6a46a6066 100644 --- a/crates/swc_ecma_transforms/tests/fixture/legacy-only/issues/862/2/output.ts +++ b/crates/swc_ecma_transforms/tests/fixture/legacy-only/issues/862/2/output.ts @@ -1,5 +1,5 @@ export class Product extends TimestampedEntity { - id!: string; + public id!: string; } _ts_decorate([ PrimaryGeneratedColumn("uuid") From 9e4710d7710ec49c4da63b02e35cca01604bb637 Mon Sep 17 00:00:00 2001 From: David Sherret Date: Thu, 21 Dec 2023 09:09:34 -0500 Subject: [PATCH 07/14] Revert and add test elsewhere --- .../tests/tsc/autoAccessor1.json | 44 +-- .../tests/tsc/autoAccessor1.ts | 1 - .../typescript/class/auto-accessor/input.ts | 10 + .../class/auto-accessor/input.ts.json | 330 ++++++++++++++++++ 4 files changed, 342 insertions(+), 43 deletions(-) create mode 100644 crates/swc_ecma_parser/tests/typescript/class/auto-accessor/input.ts create mode 100644 crates/swc_ecma_parser/tests/typescript/class/auto-accessor/input.ts.json diff --git a/crates/swc_ecma_parser/tests/tsc/autoAccessor1.json b/crates/swc_ecma_parser/tests/tsc/autoAccessor1.json index a8bb8cfcb128..d76d1a38adca 100644 --- a/crates/swc_ecma_parser/tests/tsc/autoAccessor1.json +++ b/crates/swc_ecma_parser/tests/tsc/autoAccessor1.json @@ -2,7 +2,7 @@ "type": "Script", "span": { "start": 66, - "end": 199, + "end": 174, "ctxt": 0 }, "body": [ @@ -21,7 +21,7 @@ "declare": false, "span": { "start": 66, - "end": 199, + "end": 174, "ctxt": 0 }, "decorators": [], @@ -171,46 +171,6 @@ "decorators": [], "accessibility": null, "definite": false - }, - { - "type": "AutoAccessor", - "span": { - "start": 177, - "end": 197, - "ctxt": 0 - }, - "key": { - "type": "Identifier", - "span": { - "start": 186, - "end": 187, - "ctxt": 0 - }, - "value": "e", - "optional": false - }, - "value": null, - "typeAnnotation": { - "type": "TsTypeAnnotation", - "span": { - "start": 188, - "end": 196, - "ctxt": 0 - }, - "typeAnnotation": { - "type": "TsKeywordType", - "span": { - "start": 190, - "end": 196, - "ctxt": 0 - }, - "kind": "string" - } - }, - "isStatic": false, - "decorators": [], - "accessibility": null, - "definite": true } ], "superClass": null, diff --git a/crates/swc_ecma_parser/tests/tsc/autoAccessor1.ts b/crates/swc_ecma_parser/tests/tsc/autoAccessor1.ts index d886c8840f07..aab966c7f874 100644 --- a/crates/swc_ecma_parser/tests/tsc/autoAccessor1.ts +++ b/crates/swc_ecma_parser/tests/tsc/autoAccessor1.ts @@ -6,5 +6,4 @@ class C1 { accessor b = 1; static accessor c: any; static accessor d = 2; - accessor e!: string; } diff --git a/crates/swc_ecma_parser/tests/typescript/class/auto-accessor/input.ts b/crates/swc_ecma_parser/tests/typescript/class/auto-accessor/input.ts new file mode 100644 index 000000000000..2bbd0ff4fab4 --- /dev/null +++ b/crates/swc_ecma_parser/tests/typescript/class/auto-accessor/input.ts @@ -0,0 +1,10 @@ +class C1 { + accessor a: any; + accessor b = 1; + static accessor c: any; + static accessor d = 2; + public static accessor e = 4; + protected static accessor f: number; + private accessor g!: string; + public accessor h = 1; +} diff --git a/crates/swc_ecma_parser/tests/typescript/class/auto-accessor/input.ts.json b/crates/swc_ecma_parser/tests/typescript/class/auto-accessor/input.ts.json new file mode 100644 index 000000000000..866ccc65d152 --- /dev/null +++ b/crates/swc_ecma_parser/tests/typescript/class/auto-accessor/input.ts.json @@ -0,0 +1,330 @@ +{ + "type": "Script", + "span": { + "start": 1, + "end": 244, + "ctxt": 0 + }, + "body": [ + { + "type": "ClassDeclaration", + "identifier": { + "type": "Identifier", + "span": { + "start": 7, + "end": 9, + "ctxt": 0 + }, + "value": "C1", + "optional": false + }, + "declare": false, + "span": { + "start": 1, + "end": 244, + "ctxt": 0 + }, + "decorators": [], + "body": [ + { + "type": "AutoAccessor", + "span": { + "start": 16, + "end": 32, + "ctxt": 0 + }, + "key": { + "type": "Identifier", + "span": { + "start": 25, + "end": 26, + "ctxt": 0 + }, + "value": "a", + "optional": false + }, + "value": null, + "typeAnnotation": { + "type": "TsTypeAnnotation", + "span": { + "start": 26, + "end": 31, + "ctxt": 0 + }, + "typeAnnotation": { + "type": "TsKeywordType", + "span": { + "start": 28, + "end": 31, + "ctxt": 0 + }, + "kind": "any" + } + }, + "isStatic": false, + "decorators": [], + "accessibility": null, + "definite": false + }, + { + "type": "AutoAccessor", + "span": { + "start": 37, + "end": 52, + "ctxt": 0 + }, + "key": { + "type": "Identifier", + "span": { + "start": 46, + "end": 47, + "ctxt": 0 + }, + "value": "b", + "optional": false + }, + "value": { + "type": "NumericLiteral", + "span": { + "start": 50, + "end": 51, + "ctxt": 0 + }, + "value": 1.0, + "raw": "1" + }, + "typeAnnotation": null, + "isStatic": false, + "decorators": [], + "accessibility": null, + "definite": false + }, + { + "type": "AutoAccessor", + "span": { + "start": 57, + "end": 80, + "ctxt": 0 + }, + "key": { + "type": "Identifier", + "span": { + "start": 73, + "end": 74, + "ctxt": 0 + }, + "value": "c", + "optional": false + }, + "value": null, + "typeAnnotation": { + "type": "TsTypeAnnotation", + "span": { + "start": 74, + "end": 79, + "ctxt": 0 + }, + "typeAnnotation": { + "type": "TsKeywordType", + "span": { + "start": 76, + "end": 79, + "ctxt": 0 + }, + "kind": "any" + } + }, + "isStatic": true, + "decorators": [], + "accessibility": null, + "definite": false + }, + { + "type": "AutoAccessor", + "span": { + "start": 85, + "end": 107, + "ctxt": 0 + }, + "key": { + "type": "Identifier", + "span": { + "start": 101, + "end": 102, + "ctxt": 0 + }, + "value": "d", + "optional": false + }, + "value": { + "type": "NumericLiteral", + "span": { + "start": 105, + "end": 106, + "ctxt": 0 + }, + "value": 2.0, + "raw": "2" + }, + "typeAnnotation": null, + "isStatic": true, + "decorators": [], + "accessibility": null, + "definite": false + }, + { + "type": "AutoAccessor", + "span": { + "start": 112, + "end": 141, + "ctxt": 0 + }, + "key": { + "type": "Identifier", + "span": { + "start": 135, + "end": 136, + "ctxt": 0 + }, + "value": "e", + "optional": false + }, + "value": { + "type": "NumericLiteral", + "span": { + "start": 139, + "end": 140, + "ctxt": 0 + }, + "value": 4.0, + "raw": "4" + }, + "typeAnnotation": null, + "isStatic": true, + "decorators": [], + "accessibility": "public", + "definite": false + }, + { + "type": "AutoAccessor", + "span": { + "start": 146, + "end": 182, + "ctxt": 0 + }, + "key": { + "type": "Identifier", + "span": { + "start": 172, + "end": 173, + "ctxt": 0 + }, + "value": "f", + "optional": false + }, + "value": null, + "typeAnnotation": { + "type": "TsTypeAnnotation", + "span": { + "start": 173, + "end": 181, + "ctxt": 0 + }, + "typeAnnotation": { + "type": "TsKeywordType", + "span": { + "start": 175, + "end": 181, + "ctxt": 0 + }, + "kind": "number" + } + }, + "isStatic": true, + "decorators": [], + "accessibility": "protected", + "definite": false + }, + { + "type": "AutoAccessor", + "span": { + "start": 187, + "end": 215, + "ctxt": 0 + }, + "key": { + "type": "Identifier", + "span": { + "start": 204, + "end": 205, + "ctxt": 0 + }, + "value": "g", + "optional": false + }, + "value": null, + "typeAnnotation": { + "type": "TsTypeAnnotation", + "span": { + "start": 206, + "end": 214, + "ctxt": 0 + }, + "typeAnnotation": { + "type": "TsKeywordType", + "span": { + "start": 208, + "end": 214, + "ctxt": 0 + }, + "kind": "string" + } + }, + "isStatic": false, + "decorators": [], + "accessibility": "private", + "definite": true + }, + { + "type": "AutoAccessor", + "span": { + "start": 220, + "end": 242, + "ctxt": 0 + }, + "key": { + "type": "Identifier", + "span": { + "start": 236, + "end": 237, + "ctxt": 0 + }, + "value": "h", + "optional": false + }, + "value": { + "type": "NumericLiteral", + "span": { + "start": 240, + "end": 241, + "ctxt": 0 + }, + "value": 1.0, + "raw": "1" + }, + "typeAnnotation": null, + "isStatic": false, + "decorators": [], + "accessibility": "public", + "definite": false + } + ], + "superClass": null, + "isAbstract": false, + "typeParams": null, + "superTypeParams": null, + "implements": [] + } + ], + "interpreter": null +} From 5b730f0426cc273e2d6c835ed4f4e4a3a8620aad Mon Sep 17 00:00:00 2001 From: David Sherret Date: Thu, 21 Dec 2023 11:21:07 -0500 Subject: [PATCH 08/14] Parse auto accessors in test --- crates/swc_ecma_transforms_typescript/tests/strip_correctness.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/crates/swc_ecma_transforms_typescript/tests/strip_correctness.rs b/crates/swc_ecma_transforms_typescript/tests/strip_correctness.rs index 3f8d808ad4de..4fd229a1bb86 100644 --- a/crates/swc_ecma_transforms_typescript/tests/strip_correctness.rs +++ b/crates/swc_ecma_transforms_typescript/tests/strip_correctness.rs @@ -239,6 +239,7 @@ fn identity(entry: PathBuf) { export_default_from: true, import_attributes: true, allow_super_outside_method: true, + auto_accessors: true, ..Default::default() }), (&*js_fm).into(), From f476da7a759248b922d958398a463421591d1532 Mon Sep 17 00:00:00 2001 From: David Sherret Date: Fri, 22 Dec 2023 00:56:51 -0500 Subject: [PATCH 09/14] add is_override --- crates/swc_ecma_ast/src/class.rs | 4 + crates/swc_ecma_codegen/src/lib.rs | 5 + .../fixture/typescript/class_prop/input.js | 13 +- .../fixture/typescript/class_prop/output.js | 13 +- .../typescript/class_prop/output.min.js | 2 +- .../src/parser/class_and_fn.rs | 1 + .../tests/tsc/autoAccessor1.json | 4 + .../tests/tsc/autoAccessor10.json | 5 + .../tests/tsc/autoAccessor2.json | 4 + .../tests/tsc/autoAccessor3.json | 4 + .../tests/tsc/autoAccessor4.json | 4 + .../tests/tsc/autoAccessor6.json | 1 + .../tests/tsc/autoAccessor7.json | 2 + .../tests/tsc/autoAccessor8.json | 6 + .../tests/tsc/autoAccessor9.json | 6 + .../tsc/autoAccessorAllowedModifiers.json | 17 ++ ...autoAccessorNoUseDefineForClassFields.json | 8 + .../typescript/class/auto-accessor/input.ts | 3 +- .../class/auto-accessor/input.ts.json | 169 ++++++++++++------ crates/swc_ecma_visit/src/lib.rs | 1 + 20 files changed, 199 insertions(+), 73 deletions(-) diff --git a/crates/swc_ecma_ast/src/class.rs b/crates/swc_ecma_ast/src/class.rs index 17fbbd929b8c..99b47a136f53 100644 --- a/crates/swc_ecma_ast/src/class.rs +++ b/crates/swc_ecma_ast/src/class.rs @@ -332,6 +332,9 @@ pub struct AutoAccessor { #[cfg_attr(feature = "serde-impl", serde(default))] pub accessibility: Option, + #[cfg_attr(feature = "serde-impl", serde(default))] + pub is_override: bool, + #[cfg_attr(feature = "serde-impl", serde(default))] pub definite: bool, } @@ -346,6 +349,7 @@ impl Take for AutoAccessor { is_static: false, decorators: Take::dummy(), accessibility: None, + is_override: false, definite: false, } } diff --git a/crates/swc_ecma_codegen/src/lib.rs b/crates/swc_ecma_codegen/src/lib.rs index 24b2e8570c83..89a7bfcce40a 100644 --- a/crates/swc_ecma_codegen/src/lib.rs +++ b/crates/swc_ecma_codegen/src/lib.rs @@ -1360,6 +1360,11 @@ where space!(); } + if n.is_override { + keyword!("override"); + space!(); + } + keyword!("accessor"); space!(); diff --git a/crates/swc_ecma_codegen/tests/fixture/typescript/class_prop/input.js b/crates/swc_ecma_codegen/tests/fixture/typescript/class_prop/input.js index 511b7bbab6a0..4c3ee085c4ee 100644 --- a/crates/swc_ecma_codegen/tests/fixture/typescript/class_prop/input.js +++ b/crates/swc_ecma_codegen/tests/fixture/typescript/class_prop/input.js @@ -1,13 +1,14 @@ -class MyClass { +class MyClass extends Base { prop1?: string; prop2!: string; #prop3?: string; #prop4?: string = "test"; static readonly prop5!: string; readonly #prop6 = "asdf"; - accessor prop7!: string = ""; - public accessor prop8 = ""; - public static accessor prop8 = ""; - public prop9: string; - private static prop10: string; + accessor prop9!: string = ""; + public accessor prop10 = ""; + public static accessor prop11 = ""; + public prop12: string; + private static prop13: string; + protected override accessor prop14 = 5; } diff --git a/crates/swc_ecma_codegen/tests/fixture/typescript/class_prop/output.js b/crates/swc_ecma_codegen/tests/fixture/typescript/class_prop/output.js index 511b7bbab6a0..4c3ee085c4ee 100644 --- a/crates/swc_ecma_codegen/tests/fixture/typescript/class_prop/output.js +++ b/crates/swc_ecma_codegen/tests/fixture/typescript/class_prop/output.js @@ -1,13 +1,14 @@ -class MyClass { +class MyClass extends Base { prop1?: string; prop2!: string; #prop3?: string; #prop4?: string = "test"; static readonly prop5!: string; readonly #prop6 = "asdf"; - accessor prop7!: string = ""; - public accessor prop8 = ""; - public static accessor prop8 = ""; - public prop9: string; - private static prop10: string; + accessor prop9!: string = ""; + public accessor prop10 = ""; + public static accessor prop11 = ""; + public prop12: string; + private static prop13: string; + protected override accessor prop14 = 5; } diff --git a/crates/swc_ecma_codegen/tests/fixture/typescript/class_prop/output.min.js b/crates/swc_ecma_codegen/tests/fixture/typescript/class_prop/output.min.js index 44d7ce64aa7c..a50672f2ca60 100644 --- a/crates/swc_ecma_codegen/tests/fixture/typescript/class_prop/output.min.js +++ b/crates/swc_ecma_codegen/tests/fixture/typescript/class_prop/output.min.js @@ -1 +1 @@ -class MyClass{prop1?: string;prop2!: string;#prop3?: string;#prop4?: string="test";static readonly prop5!: string;readonly #prop6="asdf";accessor prop7!: string="";public accessor prop8="";public static accessor prop8="";public prop9: string;private static prop10: string} +class MyClass extends Base{prop1?: string;prop2!: string;#prop3?: string;#prop4?: string="test";static readonly prop5!: string;readonly #prop6="asdf";accessor prop9!: string="";public accessor prop10="";public static accessor prop11="";public prop12: string;private static prop13: string;protected override accessor prop14=5} 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 bbcadbc3bb40..1ae4486e3aab 100644 --- a/crates/swc_ecma_parser/src/parser/class_and_fn.rs +++ b/crates/swc_ecma_parser/src/parser/class_and_fn.rs @@ -1092,6 +1092,7 @@ impl Parser { is_static, decorators, accessibility, + is_override, definite, })); } diff --git a/crates/swc_ecma_parser/tests/tsc/autoAccessor1.json b/crates/swc_ecma_parser/tests/tsc/autoAccessor1.json index d76d1a38adca..1aae0883a373 100644 --- a/crates/swc_ecma_parser/tests/tsc/autoAccessor1.json +++ b/crates/swc_ecma_parser/tests/tsc/autoAccessor1.json @@ -64,6 +64,7 @@ "isStatic": false, "decorators": [], "accessibility": null, + "isOverride": false, "definite": false }, { @@ -97,6 +98,7 @@ "isStatic": false, "decorators": [], "accessibility": null, + "isOverride": false, "definite": false }, { @@ -137,6 +139,7 @@ "isStatic": true, "decorators": [], "accessibility": null, + "isOverride": false, "definite": false }, { @@ -170,6 +173,7 @@ "isStatic": true, "decorators": [], "accessibility": null, + "isOverride": false, "definite": false } ], diff --git a/crates/swc_ecma_parser/tests/tsc/autoAccessor10.json b/crates/swc_ecma_parser/tests/tsc/autoAccessor10.json index 5770c9df2508..ab0b274daaa4 100644 --- a/crates/swc_ecma_parser/tests/tsc/autoAccessor10.json +++ b/crates/swc_ecma_parser/tests/tsc/autoAccessor10.json @@ -57,6 +57,7 @@ "isStatic": false, "decorators": [], "accessibility": null, + "isOverride": false, "definite": false } ], @@ -161,6 +162,7 @@ "isStatic": false, "decorators": [], "accessibility": null, + "isOverride": false, "definite": false } ], @@ -300,6 +302,7 @@ "isStatic": false, "decorators": [], "accessibility": null, + "isOverride": false, "definite": false }, { @@ -433,6 +436,7 @@ "isStatic": true, "decorators": [], "accessibility": null, + "isOverride": false, "definite": false } ], @@ -493,6 +497,7 @@ "isStatic": true, "decorators": [], "accessibility": null, + "isOverride": false, "definite": false } ], diff --git a/crates/swc_ecma_parser/tests/tsc/autoAccessor2.json b/crates/swc_ecma_parser/tests/tsc/autoAccessor2.json index 586fa1a6aa3e..43f627f7b32a 100644 --- a/crates/swc_ecma_parser/tests/tsc/autoAccessor2.json +++ b/crates/swc_ecma_parser/tests/tsc/autoAccessor2.json @@ -72,6 +72,7 @@ "isStatic": false, "decorators": [], "accessibility": null, + "isOverride": false, "definite": false }, { @@ -113,6 +114,7 @@ "isStatic": false, "decorators": [], "accessibility": null, + "isOverride": false, "definite": false }, { @@ -161,6 +163,7 @@ "isStatic": true, "decorators": [], "accessibility": null, + "isOverride": false, "definite": false }, { @@ -202,6 +205,7 @@ "isStatic": true, "decorators": [], "accessibility": null, + "isOverride": false, "definite": false }, { diff --git a/crates/swc_ecma_parser/tests/tsc/autoAccessor3.json b/crates/swc_ecma_parser/tests/tsc/autoAccessor3.json index 1ff730de115f..49b35a600ab8 100644 --- a/crates/swc_ecma_parser/tests/tsc/autoAccessor3.json +++ b/crates/swc_ecma_parser/tests/tsc/autoAccessor3.json @@ -64,6 +64,7 @@ "isStatic": false, "decorators": [], "accessibility": null, + "isOverride": false, "definite": false }, { @@ -97,6 +98,7 @@ "isStatic": false, "decorators": [], "accessibility": null, + "isOverride": false, "definite": false }, { @@ -137,6 +139,7 @@ "isStatic": true, "decorators": [], "accessibility": null, + "isOverride": false, "definite": false }, { @@ -170,6 +173,7 @@ "isStatic": true, "decorators": [], "accessibility": null, + "isOverride": false, "definite": false } ], diff --git a/crates/swc_ecma_parser/tests/tsc/autoAccessor4.json b/crates/swc_ecma_parser/tests/tsc/autoAccessor4.json index 5b2f53d49aaf..8093d48f0ac2 100644 --- a/crates/swc_ecma_parser/tests/tsc/autoAccessor4.json +++ b/crates/swc_ecma_parser/tests/tsc/autoAccessor4.json @@ -64,6 +64,7 @@ "isStatic": false, "decorators": [], "accessibility": null, + "isOverride": false, "definite": false }, { @@ -97,6 +98,7 @@ "isStatic": false, "decorators": [], "accessibility": null, + "isOverride": false, "definite": false }, { @@ -137,6 +139,7 @@ "isStatic": true, "decorators": [], "accessibility": null, + "isOverride": false, "definite": false }, { @@ -170,6 +173,7 @@ "isStatic": true, "decorators": [], "accessibility": null, + "isOverride": false, "definite": false } ], diff --git a/crates/swc_ecma_parser/tests/tsc/autoAccessor6.json b/crates/swc_ecma_parser/tests/tsc/autoAccessor6.json index ad503e5fb875..ca29c7d28c64 100644 --- a/crates/swc_ecma_parser/tests/tsc/autoAccessor6.json +++ b/crates/swc_ecma_parser/tests/tsc/autoAccessor6.json @@ -64,6 +64,7 @@ "isStatic": false, "decorators": [], "accessibility": null, + "isOverride": false, "definite": false } ], diff --git a/crates/swc_ecma_parser/tests/tsc/autoAccessor7.json b/crates/swc_ecma_parser/tests/tsc/autoAccessor7.json index 4a26b66222df..778ed91d6a31 100644 --- a/crates/swc_ecma_parser/tests/tsc/autoAccessor7.json +++ b/crates/swc_ecma_parser/tests/tsc/autoAccessor7.json @@ -64,6 +64,7 @@ "isStatic": false, "decorators": [], "accessibility": null, + "isOverride": false, "definite": false } ], @@ -124,6 +125,7 @@ "isStatic": false, "decorators": [], "accessibility": null, + "isOverride": false, "definite": false } ], diff --git a/crates/swc_ecma_parser/tests/tsc/autoAccessor8.json b/crates/swc_ecma_parser/tests/tsc/autoAccessor8.json index aaba2edacfa6..1000d62a29ef 100644 --- a/crates/swc_ecma_parser/tests/tsc/autoAccessor8.json +++ b/crates/swc_ecma_parser/tests/tsc/autoAccessor8.json @@ -64,6 +64,7 @@ "isStatic": false, "decorators": [], "accessibility": null, + "isOverride": false, "definite": false }, { @@ -104,6 +105,7 @@ "isStatic": true, "decorators": [], "accessibility": null, + "isOverride": false, "definite": false } ], @@ -171,6 +173,7 @@ "isStatic": false, "decorators": [], "accessibility": null, + "isOverride": false, "definite": false }, { @@ -211,6 +214,7 @@ "isStatic": true, "decorators": [], "accessibility": null, + "isOverride": false, "definite": false } ], @@ -306,6 +310,7 @@ "isStatic": false, "decorators": [], "accessibility": null, + "isOverride": false, "definite": false }, { @@ -346,6 +351,7 @@ "isStatic": true, "decorators": [], "accessibility": null, + "isOverride": false, "definite": false } ], diff --git a/crates/swc_ecma_parser/tests/tsc/autoAccessor9.json b/crates/swc_ecma_parser/tests/tsc/autoAccessor9.json index 48b5455e9e30..75918a349602 100644 --- a/crates/swc_ecma_parser/tests/tsc/autoAccessor9.json +++ b/crates/swc_ecma_parser/tests/tsc/autoAccessor9.json @@ -57,6 +57,7 @@ "isStatic": false, "decorators": [], "accessibility": null, + "isOverride": false, "definite": false } ], @@ -155,6 +156,7 @@ "isStatic": false, "decorators": [], "accessibility": null, + "isOverride": false, "definite": false }, { @@ -297,6 +299,7 @@ "isStatic": false, "decorators": [], "accessibility": null, + "isOverride": false, "definite": false } ], @@ -548,6 +551,7 @@ "isStatic": false, "decorators": [], "accessibility": null, + "isOverride": false, "definite": false }, { @@ -646,6 +650,7 @@ "isStatic": true, "decorators": [], "accessibility": null, + "isOverride": false, "definite": false } ], @@ -744,6 +749,7 @@ "isStatic": true, "decorators": [], "accessibility": null, + "isOverride": false, "definite": false }, { diff --git a/crates/swc_ecma_parser/tests/tsc/autoAccessorAllowedModifiers.json b/crates/swc_ecma_parser/tests/tsc/autoAccessorAllowedModifiers.json index aed69a088ca2..ffcdb6125067 100644 --- a/crates/swc_ecma_parser/tests/tsc/autoAccessorAllowedModifiers.json +++ b/crates/swc_ecma_parser/tests/tsc/autoAccessorAllowedModifiers.json @@ -64,6 +64,7 @@ "isStatic": false, "decorators": [], "accessibility": null, + "isOverride": false, "definite": false }, { @@ -104,6 +105,7 @@ "isStatic": false, "decorators": [], "accessibility": "public", + "isOverride": false, "definite": false }, { @@ -144,6 +146,7 @@ "isStatic": false, "decorators": [], "accessibility": "private", + "isOverride": false, "definite": false }, { @@ -184,6 +187,7 @@ "isStatic": false, "decorators": [], "accessibility": "protected", + "isOverride": false, "definite": false }, { @@ -224,6 +228,7 @@ "isStatic": false, "decorators": [], "accessibility": null, + "isOverride": false, "definite": false }, { @@ -264,6 +269,7 @@ "isStatic": true, "decorators": [], "accessibility": null, + "isOverride": false, "definite": false }, { @@ -304,6 +310,7 @@ "isStatic": true, "decorators": [], "accessibility": "public", + "isOverride": false, "definite": false }, { @@ -344,6 +351,7 @@ "isStatic": true, "decorators": [], "accessibility": "private", + "isOverride": false, "definite": false }, { @@ -384,6 +392,7 @@ "isStatic": true, "decorators": [], "accessibility": "protected", + "isOverride": false, "definite": false }, { @@ -432,6 +441,7 @@ "isStatic": false, "decorators": [], "accessibility": null, + "isOverride": false, "definite": false }, { @@ -472,6 +482,7 @@ "isStatic": false, "decorators": [], "accessibility": null, + "isOverride": false, "definite": false }, { @@ -512,6 +523,7 @@ "isStatic": false, "decorators": [], "accessibility": null, + "isOverride": false, "definite": false }, { @@ -560,6 +572,7 @@ "isStatic": false, "decorators": [], "accessibility": null, + "isOverride": false, "definite": false }, { @@ -600,6 +613,7 @@ "isStatic": false, "decorators": [], "accessibility": null, + "isOverride": false, "definite": true } ], @@ -667,6 +681,7 @@ "isStatic": false, "decorators": [], "accessibility": null, + "isOverride": true, "definite": false }, { @@ -707,6 +722,7 @@ "isStatic": true, "decorators": [], "accessibility": null, + "isOverride": true, "definite": false } ], @@ -783,6 +799,7 @@ "isStatic": false, "decorators": [], "accessibility": null, + "isOverride": false, "definite": false } ], diff --git a/crates/swc_ecma_parser/tests/tsc/autoAccessorNoUseDefineForClassFields.json b/crates/swc_ecma_parser/tests/tsc/autoAccessorNoUseDefineForClassFields.json index 07e80e2420a1..d876c7286bc9 100644 --- a/crates/swc_ecma_parser/tests/tsc/autoAccessorNoUseDefineForClassFields.json +++ b/crates/swc_ecma_parser/tests/tsc/autoAccessorNoUseDefineForClassFields.json @@ -57,6 +57,7 @@ "isStatic": true, "decorators": [], "accessibility": null, + "isOverride": false, "definite": false } ], @@ -125,6 +126,7 @@ "isStatic": true, "decorators": [], "accessibility": null, + "isOverride": false, "definite": false } ], @@ -193,6 +195,7 @@ "isStatic": true, "decorators": [], "accessibility": null, + "isOverride": false, "definite": false }, { @@ -234,6 +237,7 @@ "isStatic": false, "decorators": [], "accessibility": null, + "isOverride": false, "definite": false } ], @@ -294,6 +298,7 @@ "isStatic": false, "decorators": [], "accessibility": null, + "isOverride": false, "definite": false } ], @@ -362,6 +367,7 @@ "isStatic": false, "decorators": [], "accessibility": null, + "isOverride": false, "definite": false } ], @@ -468,6 +474,7 @@ "isStatic": false, "decorators": [], "accessibility": null, + "isOverride": false, "definite": false } ], @@ -536,6 +543,7 @@ "isStatic": false, "decorators": [], "accessibility": null, + "isOverride": false, "definite": false }, { diff --git a/crates/swc_ecma_parser/tests/typescript/class/auto-accessor/input.ts b/crates/swc_ecma_parser/tests/typescript/class/auto-accessor/input.ts index 2bbd0ff4fab4..6bfbd0142bcd 100644 --- a/crates/swc_ecma_parser/tests/typescript/class/auto-accessor/input.ts +++ b/crates/swc_ecma_parser/tests/typescript/class/auto-accessor/input.ts @@ -1,4 +1,4 @@ -class C1 { +class C1 extends B { accessor a: any; accessor b = 1; static accessor c: any; @@ -7,4 +7,5 @@ class C1 { protected static accessor f: number; private accessor g!: string; public accessor h = 1; + public override accessor i = 10; } diff --git a/crates/swc_ecma_parser/tests/typescript/class/auto-accessor/input.ts.json b/crates/swc_ecma_parser/tests/typescript/class/auto-accessor/input.ts.json index 866ccc65d152..4bf764ad9213 100644 --- a/crates/swc_ecma_parser/tests/typescript/class/auto-accessor/input.ts.json +++ b/crates/swc_ecma_parser/tests/typescript/class/auto-accessor/input.ts.json @@ -2,7 +2,7 @@ "type": "Script", "span": { "start": 1, - "end": 244, + "end": 291, "ctxt": 0 }, "body": [ @@ -21,7 +21,7 @@ "declare": false, "span": { "start": 1, - "end": 244, + "end": 291, "ctxt": 0 }, "decorators": [], @@ -29,15 +29,15 @@ { "type": "AutoAccessor", "span": { - "start": 16, - "end": 32, + "start": 26, + "end": 42, "ctxt": 0 }, "key": { "type": "Identifier", "span": { - "start": 25, - "end": 26, + "start": 35, + "end": 36, "ctxt": 0 }, "value": "a", @@ -47,15 +47,15 @@ "typeAnnotation": { "type": "TsTypeAnnotation", "span": { - "start": 26, - "end": 31, + "start": 36, + "end": 41, "ctxt": 0 }, "typeAnnotation": { "type": "TsKeywordType", "span": { - "start": 28, - "end": 31, + "start": 38, + "end": 41, "ctxt": 0 }, "kind": "any" @@ -64,20 +64,21 @@ "isStatic": false, "decorators": [], "accessibility": null, + "isOverride": false, "definite": false }, { "type": "AutoAccessor", "span": { - "start": 37, - "end": 52, + "start": 47, + "end": 62, "ctxt": 0 }, "key": { "type": "Identifier", "span": { - "start": 46, - "end": 47, + "start": 56, + "end": 57, "ctxt": 0 }, "value": "b", @@ -86,8 +87,8 @@ "value": { "type": "NumericLiteral", "span": { - "start": 50, - "end": 51, + "start": 60, + "end": 61, "ctxt": 0 }, "value": 1.0, @@ -97,20 +98,21 @@ "isStatic": false, "decorators": [], "accessibility": null, + "isOverride": false, "definite": false }, { "type": "AutoAccessor", "span": { - "start": 57, - "end": 80, + "start": 67, + "end": 90, "ctxt": 0 }, "key": { "type": "Identifier", "span": { - "start": 73, - "end": 74, + "start": 83, + "end": 84, "ctxt": 0 }, "value": "c", @@ -120,15 +122,15 @@ "typeAnnotation": { "type": "TsTypeAnnotation", "span": { - "start": 74, - "end": 79, + "start": 84, + "end": 89, "ctxt": 0 }, "typeAnnotation": { "type": "TsKeywordType", "span": { - "start": 76, - "end": 79, + "start": 86, + "end": 89, "ctxt": 0 }, "kind": "any" @@ -137,20 +139,21 @@ "isStatic": true, "decorators": [], "accessibility": null, + "isOverride": false, "definite": false }, { "type": "AutoAccessor", "span": { - "start": 85, - "end": 107, + "start": 95, + "end": 117, "ctxt": 0 }, "key": { "type": "Identifier", "span": { - "start": 101, - "end": 102, + "start": 111, + "end": 112, "ctxt": 0 }, "value": "d", @@ -159,8 +162,8 @@ "value": { "type": "NumericLiteral", "span": { - "start": 105, - "end": 106, + "start": 115, + "end": 116, "ctxt": 0 }, "value": 2.0, @@ -170,20 +173,21 @@ "isStatic": true, "decorators": [], "accessibility": null, + "isOverride": false, "definite": false }, { "type": "AutoAccessor", "span": { - "start": 112, - "end": 141, + "start": 122, + "end": 151, "ctxt": 0 }, "key": { "type": "Identifier", "span": { - "start": 135, - "end": 136, + "start": 145, + "end": 146, "ctxt": 0 }, "value": "e", @@ -192,8 +196,8 @@ "value": { "type": "NumericLiteral", "span": { - "start": 139, - "end": 140, + "start": 149, + "end": 150, "ctxt": 0 }, "value": 4.0, @@ -203,20 +207,21 @@ "isStatic": true, "decorators": [], "accessibility": "public", + "isOverride": false, "definite": false }, { "type": "AutoAccessor", "span": { - "start": 146, - "end": 182, + "start": 156, + "end": 192, "ctxt": 0 }, "key": { "type": "Identifier", "span": { - "start": 172, - "end": 173, + "start": 182, + "end": 183, "ctxt": 0 }, "value": "f", @@ -226,15 +231,15 @@ "typeAnnotation": { "type": "TsTypeAnnotation", "span": { - "start": 173, - "end": 181, + "start": 183, + "end": 191, "ctxt": 0 }, "typeAnnotation": { "type": "TsKeywordType", "span": { - "start": 175, - "end": 181, + "start": 185, + "end": 191, "ctxt": 0 }, "kind": "number" @@ -243,20 +248,21 @@ "isStatic": true, "decorators": [], "accessibility": "protected", + "isOverride": false, "definite": false }, { "type": "AutoAccessor", "span": { - "start": 187, - "end": 215, + "start": 197, + "end": 225, "ctxt": 0 }, "key": { "type": "Identifier", "span": { - "start": 204, - "end": 205, + "start": 214, + "end": 215, "ctxt": 0 }, "value": "g", @@ -266,15 +272,15 @@ "typeAnnotation": { "type": "TsTypeAnnotation", "span": { - "start": 206, - "end": 214, + "start": 216, + "end": 224, "ctxt": 0 }, "typeAnnotation": { "type": "TsKeywordType", "span": { - "start": 208, - "end": 214, + "start": 218, + "end": 224, "ctxt": 0 }, "kind": "string" @@ -283,20 +289,21 @@ "isStatic": false, "decorators": [], "accessibility": "private", + "isOverride": false, "definite": true }, { "type": "AutoAccessor", "span": { - "start": 220, - "end": 242, + "start": 230, + "end": 252, "ctxt": 0 }, "key": { "type": "Identifier", "span": { - "start": 236, - "end": 237, + "start": 246, + "end": 247, "ctxt": 0 }, "value": "h", @@ -305,8 +312,8 @@ "value": { "type": "NumericLiteral", "span": { - "start": 240, - "end": 241, + "start": 250, + "end": 251, "ctxt": 0 }, "value": 1.0, @@ -316,10 +323,54 @@ "isStatic": false, "decorators": [], "accessibility": "public", + "isOverride": false, + "definite": false + }, + { + "type": "AutoAccessor", + "span": { + "start": 257, + "end": 289, + "ctxt": 0 + }, + "key": { + "type": "Identifier", + "span": { + "start": 282, + "end": 283, + "ctxt": 0 + }, + "value": "i", + "optional": false + }, + "value": { + "type": "NumericLiteral", + "span": { + "start": 286, + "end": 288, + "ctxt": 0 + }, + "value": 10.0, + "raw": "10" + }, + "typeAnnotation": null, + "isStatic": false, + "decorators": [], + "accessibility": "public", + "isOverride": true, "definite": false } ], - "superClass": null, + "superClass": { + "type": "Identifier", + "span": { + "start": 18, + "end": 19, + "ctxt": 0 + }, + "value": "B", + "optional": false + }, "isAbstract": false, "typeParams": null, "superTypeParams": null, diff --git a/crates/swc_ecma_visit/src/lib.rs b/crates/swc_ecma_visit/src/lib.rs index 20ea1fbc6e38..01213861e4ba 100644 --- a/crates/swc_ecma_visit/src/lib.rs +++ b/crates/swc_ecma_visit/src/lib.rs @@ -1878,6 +1878,7 @@ define!({ pub is_static: bool, pub decorators: Vec, pub accessibility: Option, + pub is_override: bool, pub definite: bool, } From 5c195c68c95f45b162715d865fed7dde0917d9d3 Mon Sep 17 00:00:00 2001 From: David Sherret Date: Fri, 22 Dec 2023 01:03:17 -0500 Subject: [PATCH 10/14] Strip override on transform --- crates/swc_ecma_transforms_typescript/src/strip_type.rs | 1 + .../tests/fixture/auto-accessor/input.ts | 4 ++-- .../tests/fixture/auto-accessor/output.js | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/crates/swc_ecma_transforms_typescript/src/strip_type.rs b/crates/swc_ecma_transforms_typescript/src/strip_type.rs index 1bc214449eea..7693e1072cad 100644 --- a/crates/swc_ecma_transforms_typescript/src/strip_type.rs +++ b/crates/swc_ecma_transforms_typescript/src/strip_type.rs @@ -162,6 +162,7 @@ impl VisitMut for StripType { n.type_ann = None; n.accessibility = None; n.definite = false; + n.is_override = false; n.visit_mut_children_with(self); } diff --git a/crates/swc_ecma_transforms_typescript/tests/fixture/auto-accessor/input.ts b/crates/swc_ecma_transforms_typescript/tests/fixture/auto-accessor/input.ts index 0ba07cdf0630..4f4cd98ead30 100644 --- a/crates/swc_ecma_transforms_typescript/tests/fixture/auto-accessor/input.ts +++ b/crates/swc_ecma_transforms_typescript/tests/fixture/auto-accessor/input.ts @@ -1,4 +1,4 @@ -class Test { +class Test extends B { accessor a!: string; - public accessor b: string = ""; + public override accessor b: string = ""; } diff --git a/crates/swc_ecma_transforms_typescript/tests/fixture/auto-accessor/output.js b/crates/swc_ecma_transforms_typescript/tests/fixture/auto-accessor/output.js index 16d278ae6d4e..e3746715bd53 100644 --- a/crates/swc_ecma_transforms_typescript/tests/fixture/auto-accessor/output.js +++ b/crates/swc_ecma_transforms_typescript/tests/fixture/auto-accessor/output.js @@ -1,4 +1,4 @@ -class Test { +class Test extends B { accessor a; accessor b = ""; } From 20ba286116214ae97106281a8b54f8f1e058a325 Mon Sep 17 00:00:00 2001 From: David Sherret Date: Sat, 23 Dec 2023 20:34:41 -0500 Subject: [PATCH 11/14] Fix test --- .../tests/fixture/typescript/class_prop/input.js | 4 ++-- .../tests/fixture/typescript/class_prop/output.js | 4 ++-- .../tests/fixture/typescript/class_prop/output.min.js | 3 +-- 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/crates/swc_ecma_codegen/tests/fixture/typescript/class_prop/input.js b/crates/swc_ecma_codegen/tests/fixture/typescript/class_prop/input.js index 99ba20947c3e..3f9140c5031f 100644 --- a/crates/swc_ecma_codegen/tests/fixture/typescript/class_prop/input.js +++ b/crates/swc_ecma_codegen/tests/fixture/typescript/class_prop/input.js @@ -5,12 +5,12 @@ class MyClass extends Base { #prop4?: string = "test"; static readonly prop5!: string; readonly #prop6 = "asdf"; + public override readonly prop7 = 5; + override readonly #prop8 = 5; accessor prop9!: string = ""; public accessor prop10 = ""; public static accessor prop11 = ""; public prop12: string; private static prop13: string; protected override accessor prop14 = 5; - public override readonly prop7 = 5; - override readonly #prop8 = 5; } diff --git a/crates/swc_ecma_codegen/tests/fixture/typescript/class_prop/output.js b/crates/swc_ecma_codegen/tests/fixture/typescript/class_prop/output.js index 99ba20947c3e..3f9140c5031f 100644 --- a/crates/swc_ecma_codegen/tests/fixture/typescript/class_prop/output.js +++ b/crates/swc_ecma_codegen/tests/fixture/typescript/class_prop/output.js @@ -5,12 +5,12 @@ class MyClass extends Base { #prop4?: string = "test"; static readonly prop5!: string; readonly #prop6 = "asdf"; + public override readonly prop7 = 5; + override readonly #prop8 = 5; accessor prop9!: string = ""; public accessor prop10 = ""; public static accessor prop11 = ""; public prop12: string; private static prop13: string; protected override accessor prop14 = 5; - public override readonly prop7 = 5; - override readonly #prop8 = 5; } diff --git a/crates/swc_ecma_codegen/tests/fixture/typescript/class_prop/output.min.js b/crates/swc_ecma_codegen/tests/fixture/typescript/class_prop/output.min.js index afba1690b17d..5474d4007e44 100644 --- a/crates/swc_ecma_codegen/tests/fixture/typescript/class_prop/output.min.js +++ b/crates/swc_ecma_codegen/tests/fixture/typescript/class_prop/output.min.js @@ -1,2 +1 @@ -class MyClass extends Base{prop1?: string;prop2!: string;#prop3?: string;#prop4?: string="test";static readonly prop5!: string;readonly #prop6="asdf";accessor prop9!: string="";public accessor prop10="";public static accessor prop11="";public prop12: string;private static prop13: string;protected override accessor prop14=5} -class MyClass extends Base{prop1?: string;prop2!: string;#prop3?: string;#prop4?: string="test";static readonly prop5!: string;readonly #prop6="asdf";public override readonly prop7=5;override readonly #prop8=5} +class MyClass extends Base{prop1?: string;prop2!: string;#prop3?: string;#prop4?: string="test";static readonly prop5!: string;readonly #prop6="asdf";public override readonly prop7=5;override readonly #prop8=5;accessor prop9!: string="";public accessor prop10="";public static accessor prop11="";public prop12: string;private static prop13: string;protected override accessor prop14=5}} From 003ace72037f8026be4bc72e8704db5b664ba6c4 Mon Sep 17 00:00:00 2001 From: David Sherret Date: Sat, 23 Dec 2023 20:46:12 -0500 Subject: [PATCH 12/14] Actually fix --- .../tests/fixture/typescript/class_prop/output.min.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/swc_ecma_codegen/tests/fixture/typescript/class_prop/output.min.js b/crates/swc_ecma_codegen/tests/fixture/typescript/class_prop/output.min.js index 5474d4007e44..22e151f87cd3 100644 --- a/crates/swc_ecma_codegen/tests/fixture/typescript/class_prop/output.min.js +++ b/crates/swc_ecma_codegen/tests/fixture/typescript/class_prop/output.min.js @@ -1 +1 @@ -class MyClass extends Base{prop1?: string;prop2!: string;#prop3?: string;#prop4?: string="test";static readonly prop5!: string;readonly #prop6="asdf";public override readonly prop7=5;override readonly #prop8=5;accessor prop9!: string="";public accessor prop10="";public static accessor prop11="";public prop12: string;private static prop13: string;protected override accessor prop14=5}} +class MyClass extends Base{prop1?: string;prop2!: string;#prop3?: string;#prop4?: string="test";static readonly prop5!: string;readonly #prop6="asdf";public override readonly prop7=5;override readonly #prop8=5;accessor prop9!: string="";public accessor prop10="";public static accessor prop11="";public prop12: string;private static prop13: string;protected override accessor prop14=5} From 27e65267571b826eefe36d0732a0d9bc8db5281e Mon Sep 17 00:00:00 2001 From: David Sherret Date: Wed, 3 Jan 2024 09:24:50 -0500 Subject: [PATCH 13/14] Fix conflicts --- .../tests/fixture/typescript/class_prop/input.js | 12 ++++++------ .../tests/fixture/typescript/class_prop/output.js | 12 ++++++------ .../fixture/typescript/class_prop/output.min.js | 3 +-- 3 files changed, 13 insertions(+), 14 deletions(-) diff --git a/crates/swc_ecma_codegen/tests/fixture/typescript/class_prop/input.js b/crates/swc_ecma_codegen/tests/fixture/typescript/class_prop/input.js index 3d8c21e62f36..507933071a45 100644 --- a/crates/swc_ecma_codegen/tests/fixture/typescript/class_prop/input.js +++ b/crates/swc_ecma_codegen/tests/fixture/typescript/class_prop/input.js @@ -7,11 +7,11 @@ class MyClass extends Base { readonly #prop6 = "asdf"; public abstract override readonly prop7 = 5; override readonly #prop8 = 5; - accessor prop9!: string = ""; - public accessor prop10 = ""; - public static accessor prop11 = ""; - public prop12: string; - private static prop13: string; - protected override accessor prop14 = 5; declare public static readonly prop9: string; + accessor prop10!: string = ""; + public accessor prop11 = ""; + public static accessor prop12 = ""; + public prop13: string; + private static prop14: string; + protected override accessor prop15 = 5; } diff --git a/crates/swc_ecma_codegen/tests/fixture/typescript/class_prop/output.js b/crates/swc_ecma_codegen/tests/fixture/typescript/class_prop/output.js index 3d8c21e62f36..507933071a45 100644 --- a/crates/swc_ecma_codegen/tests/fixture/typescript/class_prop/output.js +++ b/crates/swc_ecma_codegen/tests/fixture/typescript/class_prop/output.js @@ -7,11 +7,11 @@ class MyClass extends Base { readonly #prop6 = "asdf"; public abstract override readonly prop7 = 5; override readonly #prop8 = 5; - accessor prop9!: string = ""; - public accessor prop10 = ""; - public static accessor prop11 = ""; - public prop12: string; - private static prop13: string; - protected override accessor prop14 = 5; declare public static readonly prop9: string; + accessor prop10!: string = ""; + public accessor prop11 = ""; + public static accessor prop12 = ""; + public prop13: string; + private static prop14: string; + protected override accessor prop15 = 5; } diff --git a/crates/swc_ecma_codegen/tests/fixture/typescript/class_prop/output.min.js b/crates/swc_ecma_codegen/tests/fixture/typescript/class_prop/output.min.js index ef41fbc2689a..f66c2a794784 100644 --- a/crates/swc_ecma_codegen/tests/fixture/typescript/class_prop/output.min.js +++ b/crates/swc_ecma_codegen/tests/fixture/typescript/class_prop/output.min.js @@ -1,2 +1 @@ -class MyClass extends Base{prop1?: string;prop2!: string;#prop3?: string;#prop4?: string="test";static readonly prop5!: string;readonly #prop6="asdf";public override readonly prop7=5;override readonly #prop8=5;accessor prop9!: string="";public accessor prop10="";public static accessor prop11="";public prop12: string;private static prop13: string;protected override accessor prop14=5} -class MyClass extends Base{prop1?: string;prop2!: string;#prop3?: string;#prop4?: string="test";static readonly prop5!: string;readonly #prop6="asdf";public abstract override readonly prop7=5;override readonly #prop8=5;declare public static readonly prop9: string} +class MyClass extends Base{prop1?: string;prop2!: string;#prop3?: string;#prop4?: string="test";static readonly prop5!: string;readonly #prop6="asdf";public abstract override readonly prop7=5;override readonly #prop8=5;declare public static readonly prop9: string;accessor prop10!: string="";public accessor prop11="";public static accessor prop12="";public prop13: string;private static prop14: string;protected override accessor prop15=5} From cdb5ecbc7b27b694fdd1ed78db08b0cbd6916914 Mon Sep 17 00:00:00 2001 From: David Sherret Date: Thu, 4 Jan 2024 11:26:18 -0500 Subject: [PATCH 14/14] Update --- .../tests/fixture/typescript/class_prop/output.min.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/crates/swc_ecma_codegen/tests/fixture/typescript/class_prop/output.min.js b/crates/swc_ecma_codegen/tests/fixture/typescript/class_prop/output.min.js index dce9d3c0bb52..58f4f301b48b 100644 --- a/crates/swc_ecma_codegen/tests/fixture/typescript/class_prop/output.min.js +++ b/crates/swc_ecma_codegen/tests/fixture/typescript/class_prop/output.min.js @@ -1,2 +1 @@ -class MyClass extends Base{prop1?: string;prop2!: string;#prop3?: string;#prop4?: string="test";static readonly prop5!: string;readonly #prop6="asdf";public abstract override readonly prop7=5;override readonly #prop8=5;declare public static readonly prop9: string;accessor prop10!: string="";public accessor prop11="";public static accessor prop12="";public prop13: string;private static prop14: string;protected override accessor prop15=5} -class MyClass extends Base{prop1?: string;prop2!: string;#prop3?: string;#prop4?: string="test";#privateOptionalNoType?;static readonly prop5!: string;readonly #prop6="asdf";public abstract override readonly prop7=5;override readonly #prop8=5;declare public static readonly prop9: string;[value]?: string[]} +class MyClass extends Base{prop1?: string;prop2!: string;#prop3?: string;#prop4?: string="test";#privateOptionalNoType?;static readonly prop5!: string;readonly #prop6="asdf";public abstract override readonly prop7=5;override readonly #prop8=5;declare public static readonly prop9: string;accessor prop10!: string="";public accessor prop11="";public static accessor prop12="";public prop13: string;private static prop14: string;protected override accessor prop15=5;[value]?: string[]}