Skip to content

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

Closed
@Seikho

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

yortus

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

yortus

yortus commented on Jul 6, 2016

@yortus
Contributor

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

DanielRosenwasser

DanielRosenwasser commented on Jul 6, 2016

@DanielRosenwasser
Member

Thanks for tracking the regression down @yortus!

self-assigned this
on Jul 6, 2016
added a commit that references this issue on Jul 6, 2016

Fix #9531: account for async as an contextual keyword when parsing ex…

bf240d2
added a commit that references this issue on Jul 6, 2016

Merge pull request #9541 from Microsoft/Fix9531

4768286
added
FixedA PR has been merged for this issue
on Jul 6, 2016
added a commit that references this issue on Jul 18, 2016
1c9df84
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

Assignees

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

      Participants

      @DanielRosenwasser@yortus@Seikho@mhegazy

      Issue actions

        [Bug] Cannot default export an expression that begins with async · Issue #9531 · microsoft/TypeScript