Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conflict with using "await" keyword in function argument position inside condition #190

Closed
Syynth opened this issue Aug 30, 2019 · 4 comments
Labels
kind: bug Something isn't working solution: can't repro An attempt to reproduce has been tried and failed topic: async-to-promises Related to bugs with babel-plugin-async-to-promises

Comments

@Syynth
Copy link

Syynth commented Aug 30, 2019

Current Behavior

Certain usages of await keyword break babel plugin. Here is the minimum repro I could come up with:

async function test(callback) {
  if (true) {
    return callback(await 0);
  }
  return callback();
}

which results in the following error:

✖ Failed to compile
(babel plugin) TypeError: Cannot read property 'await' of null
TypeError: Cannot read property 'await' of null

It happens in https://github.com/babel/babel/blob/master/packages/babel-traverse/src/path/lib/virtual-types.js#L153
after being called from https://github.com/rpetrich/babel-plugin-transform-async-to-promises/blob/master/async-to-promises.ts#L3217
This may be a bug in the babel plugin but it seems to be only caused when used in conjunction with some other plugin in the tsdx babel configuration.

Expected behavior

It should compile the code correctly, as shown in this Babel Repl

Suggestions

I don't know if this is an issue with the plugin itself, in which case it would be ideal to get it fixed there, but in the mean time either the combinations of plugins which causes this would hopefully be identified or a different plugin for transforming async calls could be used.

Your environment

Software Version(s)
TSDX 0.9.0
TypeScript 3.5.3
Browser N/A
npm/Yarn 6.9.0
Operating System Ubuntu 19.04
@agilgur5 agilgur5 added the kind: bug Something isn't working label Mar 10, 2020
@agilgur5 agilgur5 added the topic: async-to-promises Related to bugs with babel-plugin-async-to-promises label Mar 20, 2020
@jaredpalmer

This comment has been minimized.

@agilgur5
Copy link
Collaborator

agilgur5 commented Sep 18, 2020

Per #795 (comment), have added a regression test for this in #795 so can confirm that that PR will fix this issue too.

[This issue] was different from the other async-to-promises issues in that it wasn't a correctness issue but an actual Babel plugin error, and per OP [h]ere, potentially due to interaction with other plugins in TSDX

@agilgur5
Copy link
Collaborator

agilgur5 commented Sep 20, 2020

So a similar "error, not correctness" bug was found in #869 just now, so I actually reproduced that and confirmed it as an upstream issue.

So I thought this is also an upstream issue, however, I was unable to reproduce this given the code from OP with TSDX v0.13.3. So perhaps changes in other Babel plugins or the ordering or ones included have already resolved this. This report is from TSDX v0.9.0, so it's quite outdated now.
The repro also doesn't pass strict type-checking (the code can be plain JS) and without an export or some usage it gets tree-shaked out. I added export to it and turned off strict and didn't get an error. Also tried adding some usage to it instead and similarly didn't get an error.

@jaredpalmer since you said you "might have" you hit this, could you please provide a reproduction? Your previous comment did not give any sort of example or error code. Otherwise I think this is already resolved without #795
Or @Syynth if you have a current repro of this, that would be helpful for regression testing.

@agilgur5 agilgur5 added solution: outdated This is not up-to-date with the current version solution: can't repro An attempt to reproduce has been tried and failed and removed solution: outdated This is not up-to-date with the current version labels Sep 20, 2020
@agilgur5
Copy link
Collaborator

Just tried this on TSDX v0.9.0 and TS 3.5.3 as per OP's environment and similarly was not able to reproduce... So even on the same version this repro doesn't seem to work 😕

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind: bug Something isn't working solution: can't repro An attempt to reproduce has been tried and failed topic: async-to-promises Related to bugs with babel-plugin-async-to-promises
Projects
None yet
Development

No branches or pull requests

3 participants