Skip to content

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

Closed

Description

@Syynth

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

Activity

  1. jaredpalmer commented on Sep 11, 2020

    @jaredpalmer
  2. agilgur5 commented on Sep 18, 2020

    @agilgur5
    Collaborator

    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

  3. agilgur5 commented on Sep 20, 2020

    @agilgur5
    Collaborator

    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.

  4. added
    solution: outdatedThis is not up-to-date with the current version
    solution: can't reproAn attempt to reproduce has been tried and failed
    and removed
    solution: outdatedThis is not up-to-date with the current version
    on Sep 20, 2020
  5. agilgur5 commented on Sep 20, 2020

    @agilgur5
    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    kind: bugSomething isn't workingsolution: can't reproAn attempt to reproduce has been tried and failedtopic: async-to-promisesRelated to bugs with babel-plugin-async-to-promises

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions