My function
export async function getAccount(provider: Provider): Promise<string | null> {
try {
const accounts: string[] = await provider.send('eth_accounts'); // 1. provider.send returns undefined
return accounts[0] || null; // 2. throw error 'Cannot read property '0' of undefined'
} catch {
warning('Some text'); // 3. log warning
}
return 'fallback account'; // 4. return 'fallback account'
}
compiled to
var getAccount = function getAccount(provider) {
try {
var _exit2 = false;
var _temp2 = _catch(function () {
return Promise.resolve(provider.send('eth_accounts')).then(function (accounts) { // 1. accounts === undefined
_exit2 = true;
return accounts[0] || null; // 2. throw error 'Cannot read property '0' of undefined'
});
}, function () {
process.env.NODE_ENV !== "production" ? warning('Some text') : void 0; // 3. log warning
});
return Promise.resolve(_temp2 && _temp2.then ? _temp2.then(function (_result) {
return _exit2 ? _result : 'fallback account'; // 4. return undefined because _exit2 === true and _result === undefined
}) : _exit2 ? _temp2 : 'fallback account');
} catch (e) {
return Promise.reject(e);
}
};
compiled to
```js.diff
var getAccount = function getAccount(provider) {
try {
var _exit2 = false;
var _temp2 = _catch(function () {
return Promise.resolve(provider.send('eth_accounts')).then(function (accounts) { // 1. accounts === undefined
- _exit2 = true;
return accounts[0] || null; // 2. throw error 'Cannot read property '0' of undefined'
+ }).then(function () {
+ _exit2 = true;
});
}, function () {
process.env.NODE_ENV !== "production" ? warning('Some text') : void 0; // 3. log warning
});
return Promise.resolve(_temp2 && _temp2.then ? _temp2.then(function (_result) {
- return _exit2 ? _result : 'fallback account'; // 4. return undefined because _exit2 === true and _result === undefined
+ return _exit2 ? _result : 'fallback account'; // 4. return 'fallback account' because _exit2 === false
}) : _exit2 ? _temp2 : 'fallback account');
} catch (e) {
return Promise.reject(e);
}
};
```
| Software | Version(s) |
| ---------------- | ---------- |
| TSDX |0.12.0
| TypeScript |3.7.2
| npm/Yarn |npm 6.12.0/yarn 1.21.1
| Node |v10.15.0
| Operating System |macOS Catalina 10.15.2
@in19farkt this is not tsdx but babel-plugin-transform-async-to-promises issue
https://www.npmjs.com/package/babel-plugin-transform-async-to-promises
tsdx uses this plugin implicitly
https://github.com/jaredpalmer/tsdx/blob/e5747fd74dae58c1f74e2d923555b37c5a6f7407/src/babelPluginTsdx.ts#L81
I鈥檓 on plane. Going to cut release on my phone and deprecate current version
when I land
I duplicated the issue in the babel-plugin-transform-async-to-promises repository
https://github.com/rpetrich/babel-plugin-transform-async-to-promises/issues/53
@allcontributors please add @in19farkt for bug
@agilgur5
I've put up a pull request to add @in19farkt! :tada:
async-to-promises has been replaced with babel-plugin-polyfill-regenerator in #795 and will be released in v0.14.0 soon. It will only pure polyfill generators for targets that need a polyfill according to your browserslistrc or preset-env targets.
Most helpful comment
async-to-promiseshas been replaced withbabel-plugin-polyfill-regeneratorin #795 and will be released in v0.14.0 soon. It will only pure polyfill generators fortargetsthat need a polyfill according to yourbrowserslistrcorpreset-envtargets.