Skip to content

Commit bc38ac9

Browse files
committedJan 21, 2024
fix(es/ast): Fix definition of SetterProp (#8314)
**Related issue:** - Closes #8157 - Closes #8377
1 parent 572bcae commit bc38ac9

33 files changed

+275
-89
lines changed
 

‎crates/swc_ecma_ast/src/prop.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,9 @@ use crate::{
66
function::Function,
77
ident::Ident,
88
lit::{BigInt, Number, Str},
9-
pat::Pat,
109
stmt::BlockStmt,
1110
typescript::TsTypeAnn,
12-
Id, MemberProp,
11+
Id, MemberProp, Pat,
1312
};
1413

1514
#[ast_node]
@@ -76,6 +75,7 @@ pub struct GetterProp {
7675
pub struct SetterProp {
7776
pub span: Span,
7877
pub key: PropName,
78+
pub this_param: Option<Pat>,
7979
pub param: Box<Pat>,
8080
#[cfg_attr(feature = "serde-impl", serde(default))]
8181
pub body: Option<BlockStmt>,

‎crates/swc_ecma_codegen/src/lib.rs

+8
Original file line numberDiff line numberDiff line change
@@ -2218,7 +2218,15 @@ where
22182218
formatting_space!();
22192219

22202220
punct!("(");
2221+
if let Some(this) = &node.this_param {
2222+
emit!(this);
2223+
punct!(",");
2224+
2225+
formatting_space!();
2226+
}
2227+
22212228
emit!(node.param);
2229+
22222230
punct!(")");
22232231

22242232
emit!(node.body);

‎crates/swc_ecma_compat_common/src/macros.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -77,14 +77,14 @@ macro_rules! impl_visit_mut_fn {
7777
let (mut params, body) = self.visit_mut_fn_like(
7878
&mut vec![Param {
7979
span: DUMMY_SP,
80-
decorators: Default::default(),
80+
decorators: vec![],
8181
pat: *f.param.take(),
8282
}],
8383
&mut f.body.take().unwrap(),
8484
);
8585
debug_assert!(params.len() == 1);
8686

87-
f.param = Box::new(params.pop().unwrap().pat);
87+
f.param = Box::new(params.into_iter().next().unwrap().pat);
8888
f.body = Some(body);
8989
}
9090

‎crates/swc_ecma_compat_es2015/src/computed_props.rs

+1
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,7 @@ impl VisitMut for ComputedProps {
172172
body,
173173
param,
174174
key,
175+
..
175176
}) => (
176177
key,
177178
Box::new(Function {

‎crates/swc_ecma_parser/src/parser/object.rs

+22-10
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//! Parser for object literal.
22
3-
use swc_common::Spanned;
3+
use swc_common::{Spanned, DUMMY_SP};
44

55
use super::*;
66
use crate::parser::class_and_fn::is_not_this;
@@ -355,21 +355,33 @@ impl<I: Tokens> ParseObject<Box<Expr>> for Parser<I> {
355355
|Function {
356356
mut params, body, ..
357357
}| {
358-
params.retain(|p| match &p.pat {
359-
Pat::Ident(p) => p.sym != "this",
360-
_ => true,
361-
});
358+
let mut this = None;
359+
if params.len() >= 2 {
360+
this = Some(params.remove(0).pat);
361+
}
362+
363+
let param = Box::new(
364+
params
365+
.into_iter()
366+
.next()
367+
.map(|v| v.pat)
368+
.unwrap_or_else(|| {
369+
parser.emit_err(
370+
key_span,
371+
SyntaxError::SetterParam,
372+
);
373+
374+
Pat::Invalid(Invalid { span: DUMMY_SP })
375+
}),
376+
);
362377

363378
// debug_assert_eq!(params.len(), 1);
364379
PropOrSpread::Prop(Box::new(Prop::Setter(SetterProp {
365380
span: span!(parser, start),
366381
key,
367382
body,
368-
param: Box::new(
369-
params.into_iter().map(|p| p.pat).next().unwrap_or(
370-
Pat::Invalid(Invalid { span: key_span }),
371-
),
372-
),
383+
param,
384+
this_param: this,
373385
})))
374386
},
375387
)

‎crates/swc_ecma_parser/tests/tsc/accessorWithES3.json

+1
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,7 @@
334334
"value": "b",
335335
"optional": false
336336
},
337+
"thisParam": null,
337338
"param": {
338339
"type": "Identifier",
339340
"span": {

‎crates/swc_ecma_parser/tests/tsc/accessorWithES5.json

+1
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,7 @@
334334
"value": "b",
335335
"optional": false
336336
},
337+
"thisParam": null,
337338
"param": {
338339
"type": "Identifier",
339340
"span": {

‎crates/swc_ecma_parser/tests/tsc/computedPropertyNames11_ES5.json

+5
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,7 @@
269269
"optional": false
270270
}
271271
},
272+
"thisParam": null,
272273
"param": {
273274
"type": "Identifier",
274275
"span": {
@@ -408,6 +409,7 @@
408409
}
409410
}
410411
},
412+
"thisParam": null,
411413
"param": {
412414
"type": "Identifier",
413415
"span": {
@@ -518,6 +520,7 @@
518520
"raw": "\"\""
519521
}
520522
},
523+
"thisParam": null,
521524
"param": {
522525
"type": "Identifier",
523526
"span": {
@@ -619,6 +622,7 @@
619622
"optional": false
620623
}
621624
},
625+
"thisParam": null,
622626
"param": {
623627
"type": "Identifier",
624628
"span": {
@@ -748,6 +752,7 @@
748752
]
749753
}
750754
},
755+
"thisParam": null,
751756
"param": {
752757
"type": "Identifier",
753758
"span": {

‎crates/swc_ecma_parser/tests/tsc/computedPropertyNames11_ES6.json

+5
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,7 @@
269269
"optional": false
270270
}
271271
},
272+
"thisParam": null,
272273
"param": {
273274
"type": "Identifier",
274275
"span": {
@@ -408,6 +409,7 @@
408409
}
409410
}
410411
},
412+
"thisParam": null,
411413
"param": {
412414
"type": "Identifier",
413415
"span": {
@@ -518,6 +520,7 @@
518520
"raw": "\"\""
519521
}
520522
},
523+
"thisParam": null,
521524
"param": {
522525
"type": "Identifier",
523526
"span": {
@@ -619,6 +622,7 @@
619622
"optional": false
620623
}
621624
},
625+
"thisParam": null,
622626
"param": {
623627
"type": "Identifier",
624628
"span": {
@@ -748,6 +752,7 @@
748752
]
749753
}
750754
},
755+
"thisParam": null,
751756
"param": {
752757
"type": "Identifier",
753758
"span": {

‎crates/swc_ecma_parser/tests/tsc/computedPropertyNames1_ES5.json

+1
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@
160160
}
161161
}
162162
},
163+
"thisParam": null,
163164
"param": {
164165
"type": "Identifier",
165166
"span": {

‎crates/swc_ecma_parser/tests/tsc/computedPropertyNames1_ES6.json

+1
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@
160160
}
161161
}
162162
},
163+
"thisParam": null,
163164
"param": {
164165
"type": "Identifier",
165166
"span": {

‎crates/swc_ecma_parser/tests/tsc/computedPropertyNamesDeclarationEmit5_ES5.json

+1
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,7 @@
270270
}
271271
}
272272
},
273+
"thisParam": null,
273274
"param": {
274275
"type": "Identifier",
275276
"span": {

‎crates/swc_ecma_parser/tests/tsc/computedPropertyNamesDeclarationEmit5_ES6.json

+1
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,7 @@
270270
}
271271
}
272272
},
273+
"thisParam": null,
273274
"param": {
274275
"type": "Identifier",
275276
"span": {

‎crates/swc_ecma_parser/tests/tsc/jsDeclarationsFunctionLikeClasses2.json

+2
Original file line numberDiff line numberDiff line change
@@ -1728,6 +1728,7 @@
17281728
"value": "x",
17291729
"optional": false
17301730
},
1731+
"thisParam": null,
17311732
"param": {
17321733
"type": "Identifier",
17331734
"span": {
@@ -1935,6 +1936,7 @@
19351936
"value": "y",
19361937
"optional": false
19371938
},
1939+
"thisParam": null,
19381940
"param": {
19391941
"type": "Identifier",
19401942
"span": {

‎crates/swc_ecma_parser/tests/tsc/numericIndexerConstrainsPropertyDeclarations.json

+1
Original file line numberDiff line numberDiff line change
@@ -2808,6 +2808,7 @@
28082808
"value": "X",
28092809
"optional": false
28102810
},
2811+
"thisParam": null,
28112812
"param": {
28122813
"type": "Identifier",
28132814
"span": {

‎crates/swc_ecma_parser/tests/tsc/objectLiteralErrorsES3.json

+2
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@
148148
"value": "a",
149149
"optional": false
150150
},
151+
"thisParam": null,
151152
"param": {
152153
"type": "Identifier",
153154
"span": {
@@ -275,6 +276,7 @@
275276
"value": "a",
276277
"optional": false
277278
},
279+
"thisParam": null,
278280
"param": {
279281
"type": "Identifier",
280282
"span": {

‎crates/swc_ecma_parser/tests/tsc/objectSpreadSetonlyAccessor.json

+2
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,7 @@
196196
"value": "bar",
197197
"optional": false
198198
},
199+
"thisParam": null,
199200
"param": {
200201
"type": "Identifier",
201202
"span": {
@@ -391,6 +392,7 @@
391392
"value": "foo",
392393
"optional": false
393394
},
395+
"thisParam": null,
394396
"param": {
395397
"type": "Identifier",
396398
"span": {

‎crates/swc_ecma_parser/tests/tsc/parserAccessors4.json

+1
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@
5959
"value": "Foo",
6060
"optional": false
6161
},
62+
"thisParam": null,
6263
"param": {
6364
"type": "Identifier",
6465
"span": {

‎crates/swc_ecma_parser/tests/tsc/parserComputedPropertyName17.json

+1
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@
6767
"optional": false
6868
}
6969
},
70+
"thisParam": null,
7071
"param": {
7172
"type": "Identifier",
7273
"span": {

‎crates/swc_ecma_parser/tests/tsc/parserES3Accessors4.json

+1
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@
5959
"value": "Foo",
6060
"optional": false
6161
},
62+
"thisParam": null,
6263
"param": {
6364
"type": "Identifier",
6465
"span": {

‎crates/swc_ecma_parser/tests/tsc/stringIndexerConstrainsPropertyDeclarations.json

+1
Original file line numberDiff line numberDiff line change
@@ -2808,6 +2808,7 @@
28082808
"value": "X",
28092809
"optional": false
28102810
},
2811+
"thisParam": null,
28112812
"param": {
28122813
"type": "Identifier",
28132814
"span": {

‎crates/swc_ecma_parser/tests/tsc/symbolDeclarationEmit10.json

+1
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@
158158
}
159159
}
160160
},
161+
"thisParam": null,
161162
"param": {
162163
"type": "Identifier",
163164
"span": {

‎crates/swc_ecma_parser/tests/tsc/symbolProperty18.json

+1
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,7 @@
212212
}
213213
}
214214
},
215+
"thisParam": null,
215216
"param": {
216217
"type": "Identifier",
217218
"span": {

‎crates/swc_ecma_parser/tests/tsc/thisTypeInAccessors.json

+86
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,43 @@
274274
"value": "x",
275275
"optional": false
276276
},
277+
"thisParam": {
278+
"type": "Identifier",
279+
"span": {
280+
"start": 204,
281+
"end": 213,
282+
"ctxt": 0
283+
},
284+
"value": "this",
285+
"optional": false,
286+
"typeAnnotation": {
287+
"type": "TsTypeAnnotation",
288+
"span": {
289+
"start": 208,
290+
"end": 213,
291+
"ctxt": 0
292+
},
293+
"typeAnnotation": {
294+
"type": "TsTypeReference",
295+
"span": {
296+
"start": 210,
297+
"end": 213,
298+
"ctxt": 0
299+
},
300+
"typeName": {
301+
"type": "Identifier",
302+
"span": {
303+
"start": 210,
304+
"end": 213,
305+
"ctxt": 0
306+
},
307+
"value": "Foo",
308+
"optional": false
309+
},
310+
"typeParams": null
311+
}
312+
}
313+
},
277314
"param": {
278315
"type": "Identifier",
279316
"span": {
@@ -526,6 +563,7 @@
526563
"value": "x",
527564
"optional": false
528565
},
566+
"thisParam": null,
529567
"param": {
530568
"type": "Identifier",
531569
"span": {
@@ -746,6 +784,43 @@
746784
"value": "x",
747785
"optional": false
748786
},
787+
"thisParam": {
788+
"type": "Identifier",
789+
"span": {
790+
"start": 441,
791+
"end": 450,
792+
"ctxt": 0
793+
},
794+
"value": "this",
795+
"optional": false,
796+
"typeAnnotation": {
797+
"type": "TsTypeAnnotation",
798+
"span": {
799+
"start": 445,
800+
"end": 450,
801+
"ctxt": 0
802+
},
803+
"typeAnnotation": {
804+
"type": "TsTypeReference",
805+
"span": {
806+
"start": 447,
807+
"end": 450,
808+
"ctxt": 0
809+
},
810+
"typeName": {
811+
"type": "Identifier",
812+
"span": {
813+
"start": 447,
814+
"end": 450,
815+
"ctxt": 0
816+
},
817+
"value": "Foo",
818+
"optional": false
819+
},
820+
"typeParams": null
821+
}
822+
}
823+
},
749824
"param": {
750825
"type": "Identifier",
751826
"span": {
@@ -982,6 +1057,17 @@
9821057
"value": "x",
9831058
"optional": false
9841059
},
1060+
"thisParam": {
1061+
"type": "Identifier",
1062+
"span": {
1063+
"start": 580,
1064+
"end": 584,
1065+
"ctxt": 0
1066+
},
1067+
"value": "this",
1068+
"optional": false,
1069+
"typeAnnotation": null
1070+
},
9851071
"param": {
9861072
"type": "Identifier",
9871073
"span": {

‎crates/swc_ecma_parser/tests/tsc/thisTypeInAccessorsNegative.json

+37
Original file line numberDiff line numberDiff line change
@@ -403,6 +403,43 @@
403403
"value": "x",
404404
"optional": false
405405
},
406+
"thisParam": {
407+
"type": "Identifier",
408+
"span": {
409+
"start": 267,
410+
"end": 276,
411+
"ctxt": 0
412+
},
413+
"value": "this",
414+
"optional": false,
415+
"typeAnnotation": {
416+
"type": "TsTypeAnnotation",
417+
"span": {
418+
"start": 271,
419+
"end": 276,
420+
"ctxt": 0
421+
},
422+
"typeAnnotation": {
423+
"type": "TsTypeReference",
424+
"span": {
425+
"start": 273,
426+
"end": 276,
427+
"ctxt": 0
428+
},
429+
"typeName": {
430+
"type": "Identifier",
431+
"span": {
432+
"start": 273,
433+
"end": 276,
434+
"ctxt": 0
435+
},
436+
"value": "Bar",
437+
"optional": false
438+
},
439+
"typeParams": null
440+
}
441+
}
442+
},
406443
"param": {
407444
"type": "Identifier",
408445
"span": {

‎crates/swc_ecma_parser/tests/tsc/thisTypeInObjectLiterals2.json

+1
Original file line numberDiff line numberDiff line change
@@ -400,6 +400,7 @@
400400
"value": "e",
401401
"optional": false
402402
},
403+
"thisParam": null,
403404
"param": {
404405
"type": "Identifier",
405406
"span": {

‎crates/swc_ecma_parser/tests/tsc/typeGuardsObjectMethods.json

+1
Original file line numberDiff line numberDiff line change
@@ -1050,6 +1050,7 @@
10501050
"value": "prop",
10511051
"optional": false
10521052
},
1053+
"thisParam": null,
10531054
"param": {
10541055
"type": "Identifier",
10551056
"span": {

‎crates/swc_ecma_quote_macros/src/ast/prop.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ impl_struct!(KeyValueProp, [key, value]);
2323
impl_struct!(AssignProp, [key, value]);
2424

2525
impl_struct!(GetterProp, [span, key, type_ann, body]);
26-
impl_struct!(SetterProp, [span, key, param, body]);
26+
impl_struct!(SetterProp, [span, key, param, this_param, body]);
2727

2828
impl_struct!(MethodProp, [key, function]);
2929

‎crates/swc_ecma_transforms_base/src/resolver/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1125,6 +1125,7 @@ impl<'a> VisitMut for Resolver<'a> {
11251125
{
11261126
self.with_child(ScopeKind::Fn, |child| {
11271127
child.ident_type = IdentType::Binding;
1128+
n.this_param.visit_mut_with(child);
11281129
n.param.visit_mut_with(child);
11291130
n.body.visit_mut_with(child);
11301131
});

‎crates/swc_ecma_transforms_typescript/src/strip_type.rs

+80-74
Original file line numberDiff line numberDiff line change
@@ -23,75 +23,16 @@ impl VisitMut for StripType {
2323
Box<TsTypeParamInstantiation>
2424
);
2525

26-
fn visit_mut_module_items(&mut self, n: &mut Vec<ModuleItem>) {
27-
n.retain(should_retain_module_item);
28-
n.visit_mut_children_with(self);
29-
}
30-
31-
fn visit_mut_import_specifiers(&mut self, n: &mut Vec<ImportSpecifier>) {
32-
n.retain(|s| !matches!(s, ImportSpecifier::Named(named) if named.is_type_only));
33-
}
34-
35-
fn visit_mut_export_specifiers(&mut self, n: &mut Vec<ExportSpecifier>) {
36-
n.retain(|s| match s {
37-
ExportSpecifier::Named(ExportNamedSpecifier { is_type_only, .. }) => !is_type_only,
38-
_ => true,
39-
})
40-
}
41-
42-
fn visit_mut_stmts(&mut self, n: &mut Vec<Stmt>) {
43-
n.retain(should_retain_stmt);
44-
n.visit_mut_children_with(self);
45-
}
46-
47-
// https://github.com/tc39/proposal-type-annotations#parameter-optionality
48-
fn visit_mut_ident(&mut self, n: &mut Ident) {
49-
n.optional = false;
50-
}
51-
5226
fn visit_mut_array_pat(&mut self, n: &mut ArrayPat) {
5327
n.visit_mut_children_with(self);
5428
n.optional = false;
5529
}
5630

57-
fn visit_mut_object_pat(&mut self, pat: &mut ObjectPat) {
58-
pat.visit_mut_children_with(self);
59-
pat.optional = false;
60-
}
61-
62-
fn visit_mut_expr(&mut self, n: &mut Expr) {
63-
// https://github.com/tc39/proposal-type-annotations#type-assertions
64-
// https://github.com/tc39/proposal-type-annotations#non-nullable-assertions
65-
while let Expr::TsAs(TsAsExpr { expr, .. })
66-
| Expr::TsNonNull(TsNonNullExpr { expr, .. })
67-
| Expr::TsTypeAssertion(TsTypeAssertion { expr, .. })
68-
| Expr::TsConstAssertion(TsConstAssertion { expr, .. })
69-
| Expr::TsInstantiation(TsInstantiation { expr, .. })
70-
| Expr::TsSatisfies(TsSatisfiesExpr { expr, .. }) = n
71-
{
72-
*n = *expr.take();
73-
}
74-
75-
n.visit_mut_children_with(self);
76-
}
77-
78-
// https://github.com/tc39/proposal-type-annotations#this-parameters
79-
fn visit_mut_params(&mut self, n: &mut Vec<Param>) {
80-
if n.first()
81-
.filter(|param| {
82-
matches!(
83-
&param.pat,
84-
Pat::Ident(BindingIdent {
85-
id: Ident { sym, .. },
86-
..
87-
}) if &**sym == "this"
88-
)
89-
})
90-
.is_some()
91-
{
92-
n.drain(0..1);
93-
}
94-
31+
fn visit_mut_auto_accessor(&mut self, n: &mut AutoAccessor) {
32+
n.type_ann = None;
33+
n.accessibility = None;
34+
n.definite = false;
35+
n.is_override = false;
9536
n.visit_mut_children_with(self);
9637
}
9738

@@ -130,11 +71,6 @@ impl VisitMut for StripType {
13071
n.visit_mut_children_with(self);
13172
}
13273

133-
fn visit_mut_constructor(&mut self, n: &mut Constructor) {
134-
n.accessibility = None;
135-
n.visit_mut_children_with(self);
136-
}
137-
13874
fn visit_mut_class_method(&mut self, n: &mut ClassMethod) {
13975
n.accessibility = None;
14076
n.is_override = false;
@@ -153,6 +89,73 @@ impl VisitMut for StripType {
15389
prop.visit_mut_children_with(self);
15490
}
15591

92+
fn visit_mut_constructor(&mut self, n: &mut Constructor) {
93+
n.accessibility = None;
94+
n.visit_mut_children_with(self);
95+
}
96+
97+
fn visit_mut_export_specifiers(&mut self, n: &mut Vec<ExportSpecifier>) {
98+
n.retain(|s| match s {
99+
ExportSpecifier::Named(ExportNamedSpecifier { is_type_only, .. }) => !is_type_only,
100+
_ => true,
101+
})
102+
}
103+
104+
fn visit_mut_expr(&mut self, n: &mut Expr) {
105+
// https://github.com/tc39/proposal-type-annotations#type-assertions
106+
// https://github.com/tc39/proposal-type-annotations#non-nullable-assertions
107+
while let Expr::TsAs(TsAsExpr { expr, .. })
108+
| Expr::TsNonNull(TsNonNullExpr { expr, .. })
109+
| Expr::TsTypeAssertion(TsTypeAssertion { expr, .. })
110+
| Expr::TsConstAssertion(TsConstAssertion { expr, .. })
111+
| Expr::TsInstantiation(TsInstantiation { expr, .. })
112+
| Expr::TsSatisfies(TsSatisfiesExpr { expr, .. }) = n
113+
{
114+
*n = *expr.take();
115+
}
116+
117+
n.visit_mut_children_with(self);
118+
}
119+
120+
// https://github.com/tc39/proposal-type-annotations#parameter-optionality
121+
fn visit_mut_ident(&mut self, n: &mut Ident) {
122+
n.optional = false;
123+
}
124+
125+
fn visit_mut_import_specifiers(&mut self, n: &mut Vec<ImportSpecifier>) {
126+
n.retain(|s| !matches!(s, ImportSpecifier::Named(named) if named.is_type_only));
127+
}
128+
129+
fn visit_mut_module_items(&mut self, n: &mut Vec<ModuleItem>) {
130+
n.retain(should_retain_module_item);
131+
n.visit_mut_children_with(self);
132+
}
133+
134+
fn visit_mut_object_pat(&mut self, pat: &mut ObjectPat) {
135+
pat.visit_mut_children_with(self);
136+
pat.optional = false;
137+
}
138+
139+
// https://github.com/tc39/proposal-type-annotations#this-parameters
140+
fn visit_mut_params(&mut self, n: &mut Vec<Param>) {
141+
if n.first()
142+
.filter(|param| {
143+
matches!(
144+
&param.pat,
145+
Pat::Ident(BindingIdent {
146+
id: Ident { sym, .. },
147+
..
148+
}) if &**sym == "this"
149+
)
150+
})
151+
.is_some()
152+
{
153+
n.drain(0..1);
154+
}
155+
156+
n.visit_mut_children_with(self);
157+
}
158+
156159
fn visit_mut_private_prop(&mut self, prop: &mut PrivateProp) {
157160
prop.readonly = false;
158161
prop.is_override = false;
@@ -162,11 +165,14 @@ impl VisitMut for StripType {
162165
prop.visit_mut_children_with(self);
163166
}
164167

165-
fn visit_mut_auto_accessor(&mut self, n: &mut AutoAccessor) {
166-
n.type_ann = None;
167-
n.accessibility = None;
168-
n.definite = false;
169-
n.is_override = false;
168+
fn visit_mut_setter_prop(&mut self, n: &mut SetterProp) {
169+
n.this_param = None;
170+
171+
n.visit_mut_children_with(self);
172+
}
173+
174+
fn visit_mut_stmts(&mut self, n: &mut Vec<Stmt>) {
175+
n.retain(should_retain_stmt);
170176
n.visit_mut_children_with(self);
171177
}
172178

‎crates/swc_ecma_usage_analyzer/src/analyzer/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1379,6 +1379,7 @@ fn for_each_id_ref_in_expr(e: &Expr, op: &mut impl FnMut(&Ident)) {
13791379
}
13801380
Prop::Setter(p) => {
13811381
for_each_id_ref_in_prop_name(&p.key, op);
1382+
13821383
for_each_id_ref_in_pat(&p.param, op);
13831384
}
13841385
Prop::Method(p) => {

‎crates/swc_ecma_utils/src/function/fn_env_hoister.rs

+2
Original file line numberDiff line numberDiff line change
@@ -665,6 +665,7 @@ fn extend_super(
665665
Prop::Setter(SetterProp {
666666
span: DUMMY_SP,
667667
key: PropName::Ident(quote_ident!("_")),
668+
this_param: None,
668669
param: value.clone().into(),
669670
body: Some(BlockStmt {
670671
span: DUMMY_SP,
@@ -721,6 +722,7 @@ fn extend_super(
721722
Prop::Setter(SetterProp {
722723
span: DUMMY_SP,
723724
key: PropName::Ident(quote_ident!("_")),
725+
this_param: None,
724726
param: value.clone().into(),
725727
body: Some(BlockStmt {
726728
span: DUMMY_SP,

‎crates/swc_ecma_visit/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1290,6 +1290,7 @@ define!({
12901290
pub struct SetterProp {
12911291
pub span: Span,
12921292
pub key: PropName,
1293+
pub this_param: Option<Pat>,
12931294
pub param: Box<Pat>,
12941295
pub body: Option<BlockStmt>,
12951296
}

0 commit comments

Comments
 (0)
Please sign in to comment.