-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Closed
Description
Describe the bug
This might be pretty niche, but I need to always have access to this
inside my custom _async_to_generator
. In the project I'm working on, methods of different objects use different promise implementations, so I'm doing something like const Promise = this.Promise || globalThis.Promise
in _async_to_generator
. However, this doesn't work because this
isn’t passed into async methods.
I wanted to find another reason to question the current behavior, so I came up with this example using eval
.
Input code
class Foo {
async bar() {
eval('console.log(this)');
}
}
Config
{
"jsc": {
"parser": {
"syntax": "ecmascript",
"jsx": false
},
"target": "es2015",
"loose": false,
"minify": {
"compress": false,
"mangle": false
}
},
"module": {
"type": "es6"
},
"minify": false,
"isModule": true
}
Link to the code that reproduces this issue
SWC Info output
No response
Expected behavior
this
should be correctly set in async methods.
Actual behavior
this
isn't passed.
Version
1.11.21
Additional context
Noticed also another bug with eval
.