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): Fix
generator
(#5796)
**Description:** - Merge `temp_vars` into `hoisted_vars`. - Fix the context of the function call and new call. **Related issue (if exists):** - vercel/next.js#40399
- Loading branch information
1 parent
c8bb70f
commit aa8672e
Showing
13 changed files
with
268 additions
and
29 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
(async () => { | ||
// Blob is not defined | ||
// const blob = new Blob(); | ||
|
||
new Uint8Array(await Promise.resolve(10)); | ||
console.log("Success"); | ||
})(); |
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,6 @@ | ||
(async () => { | ||
const a = await 1; | ||
expect(a).toBe(1); | ||
const b = ((x) => x + x)(await 2); | ||
expect(b).toBe(4); | ||
})(); |
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,25 @@ | ||
class Foo { | ||
constructor(v) { | ||
this.value = v; | ||
} | ||
|
||
static klass = class { | ||
constructor(v) { | ||
this.value = v; | ||
} | ||
}; | ||
} | ||
|
||
(async () => { | ||
class Bar extends Foo { | ||
async bar() { | ||
const foo = new Foo(await Promise.resolve(1)); | ||
const foo2 = new Foo.klass(await Promise.resolve(2)); | ||
|
||
console.log(foo.value); | ||
console.log(foo2.value); | ||
} | ||
} | ||
|
||
await new Bar().bar(); | ||
})(); |
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 @@ | ||
(async () => { | ||
const blob = new Blob(); | ||
new Uint8Array(await blob.arrayBuffer()); | ||
console.log("Success"); | ||
})(); |
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,25 @@ | ||
import _async_to_generator from "@swc/helpers/src/_async_to_generator.mjs"; | ||
import _ts_generator from "@swc/helpers/src/_ts_generator.mjs"; | ||
_async_to_generator(function() { | ||
var blob, _; | ||
return _ts_generator(this, function(_state) { | ||
switch(_state.label){ | ||
case 0: | ||
blob = new Blob(); | ||
_ = Uint8Array.bind; | ||
return [ | ||
4, | ||
blob.arrayBuffer() | ||
]; | ||
case 1: | ||
new (_.apply(Uint8Array, [ | ||
void 0, | ||
_state.sent() | ||
])); | ||
console.log("Success"); | ||
return [ | ||
2 | ||
]; | ||
} | ||
}); | ||
})(); |
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,6 @@ | ||
(async () => { | ||
const a = await 1; | ||
expect(a).toBe(1); | ||
const b = ((x) => x + x)(await 2); | ||
expect(b).toBe(4); | ||
})(); |
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,32 @@ | ||
import _async_to_generator from "@swc/helpers/src/_async_to_generator.mjs"; | ||
import _ts_generator from "@swc/helpers/src/_ts_generator.mjs"; | ||
_async_to_generator(function() { | ||
var a, b, _; | ||
return _ts_generator(this, function(_state) { | ||
switch(_state.label){ | ||
case 0: | ||
return [ | ||
4, | ||
1 | ||
]; | ||
case 1: | ||
a = _state.sent(); | ||
expect(a).toBe(1); | ||
_ = function(x) { | ||
return x + x; | ||
}; | ||
return [ | ||
4, | ||
2 | ||
]; | ||
case 2: | ||
b = _.apply(void 0, [ | ||
_state.sent() | ||
]); | ||
expect(b).toBe(4); | ||
return [ | ||
2 | ||
]; | ||
} | ||
}); | ||
})(); |
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,25 @@ | ||
class Foo { | ||
constructor(v) { | ||
this.value = v; | ||
} | ||
|
||
static klass = class { | ||
constructor(v) { | ||
this.value = v; | ||
} | ||
}; | ||
} | ||
|
||
(async () => { | ||
class Bar extends Foo { | ||
async bar() { | ||
const foo = new Foo(await Promise.resolve(1)); | ||
const foo2 = new Foo.klass(await Promise.resolve(2)); | ||
|
||
expect(foo.value).toBe(1); | ||
expect(foo2.value).toBe(2); | ||
} | ||
} | ||
|
||
await new Bar().bar(); | ||
})(); |
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,84 @@ | ||
import _async_to_generator from "@swc/helpers/src/_async_to_generator.mjs"; | ||
import _class_call_check from "@swc/helpers/src/_class_call_check.mjs"; | ||
import _create_class from "@swc/helpers/src/_create_class.mjs"; | ||
import _define_property from "@swc/helpers/src/_define_property.mjs"; | ||
import _inherits from "@swc/helpers/src/_inherits.mjs"; | ||
import _create_super from "@swc/helpers/src/_create_super.mjs"; | ||
import _ts_generator from "@swc/helpers/src/_ts_generator.mjs"; | ||
var Foo = function Foo(v) { | ||
"use strict"; | ||
_class_call_check(this, Foo); | ||
this.value = v; | ||
}; | ||
_define_property(Foo, "klass", function _class(v) { | ||
"use strict"; | ||
_class_call_check(this, _class); | ||
this.value = v; | ||
}); | ||
_async_to_generator(function() { | ||
var Bar; | ||
return _ts_generator(this, function(_state) { | ||
switch(_state.label){ | ||
case 0: | ||
Bar = /*#__PURE__*/ function(Foo1) { | ||
"use strict"; | ||
_inherits(Bar, Foo1); | ||
var _super = _create_super(Bar); | ||
function Bar() { | ||
_class_call_check(this, Bar); | ||
return _super.apply(this, arguments); | ||
} | ||
_create_class(Bar, [ | ||
{ | ||
key: "bar", | ||
value: function bar() { | ||
return _async_to_generator(function() { | ||
var foo, _, foo2, _1, _2; | ||
return _ts_generator(this, function(_state) { | ||
switch(_state.label){ | ||
case 0: | ||
_ = Foo.bind; | ||
return [ | ||
4, | ||
Promise.resolve(1) | ||
]; | ||
case 1: | ||
foo = new (_.apply(Foo, [ | ||
void 0, | ||
_state.sent() | ||
])); | ||
_2 = (_1 = Foo.klass).bind; | ||
return [ | ||
4, | ||
Promise.resolve(2) | ||
]; | ||
case 2: | ||
foo2 = new (_2.apply(_1, [ | ||
void 0, | ||
_state.sent() | ||
])); | ||
expect(foo.value).toBe(1); | ||
expect(foo2.value).toBe(2); | ||
return [ | ||
2 | ||
]; | ||
} | ||
}); | ||
})(); | ||
} | ||
} | ||
]); | ||
return Bar; | ||
}(Foo); | ||
return [ | ||
4, | ||
new Bar().bar() | ||
]; | ||
case 1: | ||
_state.sent(); | ||
return [ | ||
2 | ||
]; | ||
} | ||
}); | ||
})(); |
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
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
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
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
aa8672e
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
2483931405
ns/iter (± 157654513
)2451081491
ns/iter (± 66638631
)1.01
es/full/minify/libraries/d3
487250631
ns/iter (± 27364123
)463061858
ns/iter (± 23657832
)1.05
es/full/minify/libraries/echarts
1883726164
ns/iter (± 53251890
)1831571956
ns/iter (± 43276570
)1.03
es/full/minify/libraries/jquery
118029072
ns/iter (± 2969446
)103139586
ns/iter (± 5137713
)1.14
es/full/minify/libraries/lodash
154897953
ns/iter (± 11763110
)136018657
ns/iter (± 6582291
)1.14
es/full/minify/libraries/moment
75523714
ns/iter (± 8230160
)62368120
ns/iter (± 3117080
)1.21
es/full/minify/libraries/react
27255331
ns/iter (± 792407
)24750153
ns/iter (± 1093337
)1.10
es/full/minify/libraries/terser
392120388
ns/iter (± 15654044
)367368892
ns/iter (± 12571036
)1.07
es/full/minify/libraries/three
656575004
ns/iter (± 63485380
)626658818
ns/iter (± 63256020
)1.05
es/full/minify/libraries/typescript
5372070303
ns/iter (± 599608851
)5003824947
ns/iter (± 144677011
)1.07
es/full/minify/libraries/victory
1033323963
ns/iter (± 81262484
)966298737
ns/iter (± 44314749
)1.07
es/full/minify/libraries/vue
199605573
ns/iter (± 25980939
)171574133
ns/iter (± 13849459
)1.16
es/full/codegen/es3
34582
ns/iter (± 2214
)32870
ns/iter (± 1053
)1.05
es/full/codegen/es5
34354
ns/iter (± 2815
)32739
ns/iter (± 372
)1.05
es/full/codegen/es2015
34130
ns/iter (± 3320
)33456
ns/iter (± 1106
)1.02
es/full/codegen/es2016
34374
ns/iter (± 2106
)33483
ns/iter (± 1256
)1.03
es/full/codegen/es2017
34404
ns/iter (± 3091
)33739
ns/iter (± 2221
)1.02
es/full/codegen/es2018
35077
ns/iter (± 5465
)33706
ns/iter (± 932
)1.04
es/full/codegen/es2019
34325
ns/iter (± 5554
)33601
ns/iter (± 750
)1.02
es/full/codegen/es2020
34247
ns/iter (± 1448
)33408
ns/iter (± 615
)1.03
es/full/all/es3
253959950
ns/iter (± 20309131
)216477751
ns/iter (± 20790712
)1.17
es/full/all/es5
238679872
ns/iter (± 17778750
)202383072
ns/iter (± 17491871
)1.18
es/full/all/es2015
192713613
ns/iter (± 12401036
)162308693
ns/iter (± 13528183
)1.19
es/full/all/es2016
188759830
ns/iter (± 15150143
)161907729
ns/iter (± 11981314
)1.17
es/full/all/es2017
189358897
ns/iter (± 18192947
)160210722
ns/iter (± 11956221
)1.18
es/full/all/es2018
187239811
ns/iter (± 14442055
)156997709
ns/iter (± 12021424
)1.19
es/full/all/es2019
184566302
ns/iter (± 13214796
)158452089
ns/iter (± 13566768
)1.16
es/full/all/es2020
178238302
ns/iter (± 15891160
)151838842
ns/iter (± 12578687
)1.17
es/full/parser
837340
ns/iter (± 83085
)843524
ns/iter (± 51749
)0.99
es/full/base/fixer
32413
ns/iter (± 3317
)31601
ns/iter (± 2474
)1.03
es/full/base/resolver_and_hygiene
105683
ns/iter (± 25986
)103869
ns/iter (± 9525
)1.02
serialization of ast node
226
ns/iter (± 7
)227
ns/iter (± 13
)1.00
serialization of serde
233
ns/iter (± 9
)236
ns/iter (± 23
)0.99
This comment was automatically generated by workflow using github-action-benchmark.