Skip to content

Commit

Permalink
fix(es/parser): Skip this parameters in setter (#8158)
Browse files Browse the repository at this point in the history
**Description:**

This is not a proper fix, but let's wait for the conf.

**Related issue:**

 - Closes #8156
  • Loading branch information
kdy1 committed Oct 20, 2023
1 parent 10e523d commit 826386f
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 16 deletions.
19 changes: 19 additions & 0 deletions crates/swc/tests/fixture/issues-8xxx/8156/input/.swcrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"jsc": {
"parser": {
"syntax": "typescript",
"tsx": false
},
"target": "es2015",
"loose": false,
"minify": {
"compress": false,
"mangle": false
}
},
"module": {
"type": "commonjs"
},
"minify": false,
"isModule": true
}
5 changes: 5 additions & 0 deletions crates/swc/tests/fixture/issues-8xxx/8156/input/1.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
const s = {
set m(this: {}, value1: {}) {
console.log(value1)
}
};
6 changes: 6 additions & 0 deletions crates/swc/tests/fixture/issues-8xxx/8156/output/1.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
"use strict";
const s = {
set m (value1){
console.log(value1);
}
};
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ var explicit = {
get x () {
return this.n;
},
set x (_this){
set x (n){
this.n = n;
}
};
Expand All @@ -24,7 +24,7 @@ var copiedFromSetter = {
get x () {
return this.n;
},
set x (_this){
set x (n){
this.n = n;
}
};
Expand All @@ -33,7 +33,7 @@ var copiedFromGetterUnannotated = {
get x () {
return this.n;
},
set x (_this){
set x (n){
this.n = n;
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ var mismatch = {
get x () {
return this.n;
},
set x (_this){
set x (n){
this.wrong = "method";
}
};
Expand Down
33 changes: 21 additions & 12 deletions crates/swc_ecma_parser/src/parser/object.rs
Original file line number Diff line number Diff line change
Expand Up @@ -351,19 +351,28 @@ impl<I: Tokens> ParseObject<Box<Expr>> for Parser<I> {
false,
)
.map(|v| *v)
.map(|Function { params, body, .. }| {
// debug_assert_eq!(params.len(), 1);
PropOrSpread::Prop(Box::new(Prop::Setter(SetterProp {
span: span!(parser, start),
key,
body,
param: Box::new(
params.into_iter().map(|p| p.pat).next().unwrap_or(
Pat::Invalid(Invalid { span: key_span }),
.map(
|Function {
mut params, body, ..
}| {
params.retain(|p| match &p.pat {
Pat::Ident(p) => p.sym != "this",
_ => true,
});

// debug_assert_eq!(params.len(), 1);
PropOrSpread::Prop(Box::new(Prop::Setter(SetterProp {
span: span!(parser, start),
key,
body,
param: Box::new(
params.into_iter().map(|p| p.pat).next().unwrap_or(
Pat::Invalid(Invalid { span: key_span }),
),
),
),
})))
})
})))
},
)
}
"async" => parser
.parse_fn_args_body(
Expand Down

1 comment on commit 826386f

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Benchmark

Benchmark suite Current: 826386f Previous: 08cf1f7 Ratio
es/full/bugs-1 304830 ns/iter (± 9876) 290510 ns/iter (± 8504) 1.05
es/full/minify/libraries/antd 1422749110 ns/iter (± 13502159) 1388758180 ns/iter (± 15869273) 1.02
es/full/minify/libraries/d3 295447889 ns/iter (± 2794977) 295109041 ns/iter (± 5100917) 1.00
es/full/minify/libraries/echarts 1134399671 ns/iter (± 15541838) 1109498555 ns/iter (± 5882328) 1.02
es/full/minify/libraries/jquery 89299486 ns/iter (± 686945) 88509528 ns/iter (± 263506) 1.01
es/full/minify/libraries/lodash 104599023 ns/iter (± 499309) 102957094 ns/iter (± 211363) 1.02
es/full/minify/libraries/moment 52616711 ns/iter (± 96213) 52147649 ns/iter (± 90546) 1.01
es/full/minify/libraries/react 18804483 ns/iter (± 200302) 18807623 ns/iter (± 70750) 1.00
es/full/minify/libraries/terser 232064702 ns/iter (± 1627447) 230264991 ns/iter (± 2849716) 1.01
es/full/minify/libraries/three 414733523 ns/iter (± 3843485) 405427452 ns/iter (± 1585627) 1.02
es/full/minify/libraries/typescript 2819538857 ns/iter (± 20644391) 2740039955 ns/iter (± 23334438) 1.03
es/full/minify/libraries/victory 604692365 ns/iter (± 5542451) 583282768 ns/iter (± 3987120) 1.04
es/full/minify/libraries/vue 127430047 ns/iter (± 1164986) 125534328 ns/iter (± 466149) 1.02
es/full/codegen/es3 35289 ns/iter (± 86) 34394 ns/iter (± 49) 1.03
es/full/codegen/es5 35449 ns/iter (± 88) 34382 ns/iter (± 91) 1.03
es/full/codegen/es2015 35439 ns/iter (± 102) 34351 ns/iter (± 70) 1.03
es/full/codegen/es2016 35363 ns/iter (± 103) 34310 ns/iter (± 83) 1.03
es/full/codegen/es2017 35524 ns/iter (± 110) 34254 ns/iter (± 83) 1.04
es/full/codegen/es2018 35612 ns/iter (± 62) 34360 ns/iter (± 63) 1.04
es/full/codegen/es2019 35551 ns/iter (± 126) 34323 ns/iter (± 68) 1.04
es/full/codegen/es2020 35492 ns/iter (± 160) 34420 ns/iter (± 123) 1.03
es/full/all/es3 180314286 ns/iter (± 1143878) 176614225 ns/iter (± 1601883) 1.02
es/full/all/es5 173373204 ns/iter (± 499839) 169687476 ns/iter (± 1431069) 1.02
es/full/all/es2015 131181547 ns/iter (± 1381884) 128463268 ns/iter (± 946398) 1.02
es/full/all/es2016 130819586 ns/iter (± 658128) 128220429 ns/iter (± 783862) 1.02
es/full/all/es2017 130236190 ns/iter (± 1053828) 125868154 ns/iter (± 879867) 1.03
es/full/all/es2018 127736698 ns/iter (± 1048424) 124686921 ns/iter (± 772923) 1.02
es/full/all/es2019 126901081 ns/iter (± 998552) 124518578 ns/iter (± 1442617) 1.02
es/full/all/es2020 122753530 ns/iter (± 797503) 119951567 ns/iter (± 1185544) 1.02
es/full/parser 572072 ns/iter (± 3154) 564945 ns/iter (± 3225) 1.01
es/full/base/fixer 17924 ns/iter (± 31) 19756 ns/iter (± 115) 0.91
es/full/base/resolver_and_hygiene 83810 ns/iter (± 148) 84203 ns/iter (± 361) 1.00

This comment was automatically generated by workflow using github-action-benchmark.

Please sign in to comment.