Skip to content
This repository was archived by the owner on Jun 10, 2019. It is now read-only.

Variables goes out of scope prematurely #123

@TheGrandmother

Description

@TheGrandmother

I had this code:

1 const cid = await getCid(slackUsername)
2 await replyFn(`Creating time report for ${year} ${month} and ${cid}`)
3 const resp = await request.post(config.apiUrl + `/create-time-report/${cid}/${year}/${month}`)

And I got this strange error that cid was undefined on line 3, but it was defined properly on line 2.
After a lot of crying i looked into the generated code and i found that it had been transpiled to:

1  return Promise.resolve().then(function () {
2     return getCid(slackUsername);
3   }).then(function (_resp) {
4    const cid = _resp;
5    return replyFn(`Creating time report for ${year} ${month} and ${cid}`);
6  }).then(function () {
7    return request.post(config.apiUrl + `/create-time-report/${cid}/${year}/${month}`)
8  })

As is clear from the transpiled code cid goes out of scope prematurely.

I am running version 1.0.5 of async-to-promises.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions