-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(es/compat): Handle classes with accessors and a method with the s…
…ame name (#5039)
- Loading branch information
Showing
9 changed files
with
77 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 7 additions & 11 deletions
18
crates/swc_ecma_transforms_compat/src/es2015/classes/prop_name.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,23 @@ | ||
use num_bigint::BigInt as BigIntValue; | ||
use ordered_float::OrderedFloat; | ||
use swc_atoms::JsWord; | ||
use swc_common::{Span, Spanned}; | ||
use swc_ecma_ast::*; | ||
|
||
#[derive(Debug, PartialEq, Eq, Hash)] | ||
pub enum HashKey { | ||
Ident(JsWord), | ||
Str(JsWord), | ||
Num(OrderedFloat<f64>), | ||
BigInt(BigIntValue), | ||
/// Not for key merging | ||
Computed(Span), | ||
} | ||
|
||
impl From<&PropName> for HashKey { | ||
fn from(p: &PropName) -> Self { | ||
match *p { | ||
PropName::Ident(Ident { ref sym, .. }) => HashKey::Ident(sym.clone()), | ||
PropName::Str(Str { ref value, .. }) => HashKey::Str(value.clone()), | ||
PropName::Num(Number { value, .. }) => HashKey::Num(value.into()), | ||
PropName::BigInt(BigInt { ref value, .. }) => HashKey::BigInt(value.clone()), | ||
PropName::Computed(ref expr) => HashKey::Computed(expr.span()), | ||
match p { | ||
PropName::Ident(Ident { sym: value, .. }) | PropName::Str(Str { value, .. }) => { | ||
HashKey::Str(value.clone()) | ||
} | ||
PropName::Num(Number { value, .. }) => HashKey::Str(value.to_string().into()), | ||
PropName::BigInt(BigInt { value, .. }) => HashKey::Str(value.to_string().into()), | ||
PropName::Computed(expr) => HashKey::Computed(expr.span()), | ||
} | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
crates/swc_ecma_transforms_compat/tests/classes/issue-5029/1/input.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
class A { | ||
static b() {} | ||
static get b() {} | ||
static set b(b) {} | ||
} |
14 changes: 14 additions & 0 deletions
14
crates/swc_ecma_transforms_compat/tests/classes/issue-5029/1/output.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
let A = /*#__PURE__*/ function() { | ||
"use strict"; | ||
function A() { | ||
_classCallCheck(this, A); | ||
} | ||
_createClass(A, null, [ | ||
{ | ||
key: "b", | ||
get: function() {}, | ||
set: function(b) {} | ||
} | ||
]); | ||
return A; | ||
}(); |
5 changes: 5 additions & 0 deletions
5
crates/swc_ecma_transforms_compat/tests/classes/issue-5029/2/input.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
class A { | ||
"b"() {} | ||
get b() {} | ||
set b(b) {} | ||
} |
14 changes: 14 additions & 0 deletions
14
crates/swc_ecma_transforms_compat/tests/classes/issue-5029/2/output.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
let A = /*#__PURE__*/ function() { | ||
"use strict"; | ||
function A() { | ||
_classCallCheck(this, A); | ||
} | ||
_createClass(A, [ | ||
{ | ||
key: "b", | ||
get: function() {}, | ||
set: function(b) {} | ||
} | ||
]); | ||
return A; | ||
}(); |
5 changes: 5 additions & 0 deletions
5
crates/swc_ecma_transforms_compat/tests/classes/issue-5029/3/input.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
class A { | ||
get b() {} | ||
set b(b) {} | ||
b() {} | ||
} |
13 changes: 13 additions & 0 deletions
13
crates/swc_ecma_transforms_compat/tests/classes/issue-5029/3/output.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
let A = /*#__PURE__*/ function() { | ||
"use strict"; | ||
function A() { | ||
_classCallCheck(this, A); | ||
} | ||
_createClass(A, [ | ||
{ | ||
key: "b", | ||
value: function b() {} | ||
} | ||
]); | ||
return A; | ||
}(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25bd520
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Benchmark
es/full/minify/libraries/antd
1660157241
ns/iter (± 29445587
)1650352318
ns/iter (± 22405676
)1.01
es/full/minify/libraries/d3
432446991
ns/iter (± 9623092
)410692002
ns/iter (± 5985850
)1.05
es/full/minify/libraries/echarts
1640863988
ns/iter (± 59944311
)1620558786
ns/iter (± 16520914
)1.01
es/full/minify/libraries/jquery
97162700
ns/iter (± 9486253
)91234715
ns/iter (± 1710878
)1.06
es/full/minify/libraries/lodash
129508882
ns/iter (± 7671518
)120218577
ns/iter (± 2246002
)1.08
es/full/minify/libraries/moment
50736458
ns/iter (± 2014851
)50225925
ns/iter (± 599070
)1.01
es/full/minify/libraries/react
17556311
ns/iter (± 422645
)16913175
ns/iter (± 232698
)1.04
es/full/minify/libraries/terser
605230980
ns/iter (± 12204837
)600727821
ns/iter (± 14201905
)1.01
es/full/minify/libraries/three
546272389
ns/iter (± 7194303
)544133444
ns/iter (± 8020000
)1.00
es/full/minify/libraries/typescript
3546859049
ns/iter (± 112292243
)3494031014
ns/iter (± 78102606
)1.02
es/full/minify/libraries/victory
744850007
ns/iter (± 27294268
)704360073
ns/iter (± 12178621
)1.06
es/full/minify/libraries/vue
141427411
ns/iter (± 10246009
)131353871
ns/iter (± 4147410
)1.08
es/full/codegen/es3
32307
ns/iter (± 959
)32769
ns/iter (± 974
)0.99
es/full/codegen/es5
32290
ns/iter (± 399
)32718
ns/iter (± 1531
)0.99
es/full/codegen/es2015
32177
ns/iter (± 288
)32563
ns/iter (± 288
)0.99
es/full/codegen/es2016
32262
ns/iter (± 642
)32805
ns/iter (± 288
)0.98
es/full/codegen/es2017
32113
ns/iter (± 753
)32872
ns/iter (± 423
)0.98
es/full/codegen/es2018
32104
ns/iter (± 981
)32883
ns/iter (± 843
)0.98
es/full/codegen/es2019
32358
ns/iter (± 257
)32911
ns/iter (± 1230
)0.98
es/full/codegen/es2020
32363
ns/iter (± 1284
)32866
ns/iter (± 1283
)0.98
es/full/all/es3
185492468
ns/iter (± 9634017
)182622275
ns/iter (± 6364872
)1.02
es/full/all/es5
175228710
ns/iter (± 15617929
)171188778
ns/iter (± 6014477
)1.02
es/full/all/es2015
140694418
ns/iter (± 9049913
)143054436
ns/iter (± 4896559
)0.98
es/full/all/es2016
139315801
ns/iter (± 7565191
)142916735
ns/iter (± 3006689
)0.97
es/full/all/es2017
138056332
ns/iter (± 5650379
)140541203
ns/iter (± 3354802
)0.98
es/full/all/es2018
135434615
ns/iter (± 6908263
)139622879
ns/iter (± 6782736
)0.97
es/full/all/es2019
147058509
ns/iter (± 9486317
)138937121
ns/iter (± 4600810
)1.06
es/full/all/es2020
138386534
ns/iter (± 6084780
)133158568
ns/iter (± 3926862
)1.04
es/full/parser
695481
ns/iter (± 21226
)705087
ns/iter (± 18735
)0.99
es/full/base/fixer
29172
ns/iter (± 383
)29199
ns/iter (± 1323
)1.00
es/full/base/resolver_and_hygiene
85995
ns/iter (± 1688
)87409
ns/iter (± 3800
)0.98
serialization of ast node
207
ns/iter (± 2
)206
ns/iter (± 9
)1.00
serialization of serde
217
ns/iter (± 4
)225
ns/iter (± 3
)0.96
This comment was automatically generated by workflow using github-action-benchmark.