镜像站点 · 本页由第三方 GitHub 只读镜像提供,非 GitHub 官方站点,不接受任何登录或凭据输入。前往 github.com
Skip to content

[Bug] Cannot default export an expression that begins with async #9531

Description

@Seikho

TypeScript Version: nightly (2.0.0-dev.20160705)

The changes in #9445 have caused a breaking change in my code base. This is a pattern that we use very frequently our projects.
The compiled output has also changed and no longer functions as expected. The same error also occurs when using the async library in the same way (e.g. export default async.map(...))

Code

import {async,await} from 'asyncawait';
export default async(() => await(Promise.resolve(1)));

should compile without error and emit:

const asyncawait_1 = require('asyncawait');
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = asyncawait_1.async(() => asyncawait_1.await(Promise.resolve(1)));

but incorrectly emits:

const asyncawait_1 = require('asyncawait');
asyncawait_1.async(() => asyncawait_1.await(Promise.resolve(1)));

Expected behavior:
Compiles without error
Actual behavior:
[ts] Declaration expected
Incorrect compiled output

Activity

  1. yortus commented on Jul 6, 2016

    @yortus
    Contributor

    Looking at the changes in #9445, it seems that if the next token after export default is async, then it's treated like a declaration rather than an expression. But async is not a keyword (spec), and a valid expression may begin with an async token, as in Carl (@Seikho)'s two examples above.

    I think export default <expression> should be allowed even if the expression is something like async.map(...) or async(() => {...}), since these are valid expressions.

  2. yortus commented on Jul 6, 2016

    @yortus
    Contributor

    If this makes it into the 2.0 release, it will be a breaking change.

  3. DanielRosenwasser commented on Jul 6, 2016

    @DanielRosenwasser
    Member

    Thanks for tracking the regression down Troy Gerwien (@yortus)!

  4. added 2 commits that reference this issue on Jul 6, 2016
    bf240d2
    4768286
  5. added a commit that references this issue on Jul 18, 2016
    1c9df84
  6. locked and limited conversation to collaborators on Jun 19, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

BugA bug in TypeScriptFixedA PR has been merged for this issue

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions