This repository has been archived by the owner. It is now read-only.

[WIP] Improve error message for await-outside-async #125

Closed
wants to merge 1 commit into
base: master
from

Conversation

Projects
None yet
4 participants
@motiz88
Contributor

motiz88 commented Sep 13, 2016

This is an attempt to implement #113. I would love some early feedback/pointers, as well as help completing the following list which reflects the current state of this branch. I only added tests for true positives and true negatives, so they should all pass despite the work being incomplete.

Examples

馃槑 True positives 馃憤

The following all raise await can only be used in async functions correctly (to my understanding).

  • await promise
  • return await promise
  • var x = await promise
  • x[await promise]
  • x(await promise)
  • x(await promise, 0)
  • await await
  • await yield
  • await this
  • await super
  • await {}
  • function* a() {yield await 0}
  • await new Promise
  • await.0

Non-examples

馃槑 True negatives 馃憥

The following all raise Unexpected token etc, correctly (to my understanding).

  • await}
  • await( - parseExprSubscripts
  • await.
  • await[
  • await+
  • `await``
  • await/
  • await*
  • await[0;
  • await(0
  • await instanceof

馃槥 False positives 馃憤

The following all raise await can only be used in async functions incorrectly (only in actual non-async contexts, though).

parseExpressionStatement
  • await var
  • await)
  • await~
  • await{
  • await x(
  • await x((
parseSubscripts
  • x[await
parseParenAndDistinguishExpression
  • (await

馃槥 False negatives 馃憥

Cases which should raise await can only be used in async functions but raise some other error: None that I know of.

馃槑 No error at all 馃憣

  • `await ```
@codecov-io

This comment has been minimized.

Show comment
Hide comment
@codecov-io

codecov-io Sep 13, 2016

Current coverage is 94.18% (diff: 97.14%)

No coverage report found for master at 44d44a2.

Powered by Codecov. Last update 44d44a2...11513b7

codecov-io commented Sep 13, 2016

Current coverage is 94.18% (diff: 97.14%)

No coverage report found for master at 44d44a2.

Powered by Codecov. Last update 44d44a2...11513b7

@hzoo

This comment has been minimized.

Show comment
Hide comment
@hzoo

hzoo Sep 22, 2016

Member

Should we change the wording to say something like: can only be used in an immediate async function (or just to say the parent function should be async) - we could give an example too

Member

hzoo commented Sep 22, 2016

Should we change the wording to say something like: can only be used in an immediate async function (or just to say the parent function should be async) - we could give an example too

Detect+rewrite errors stemming from await-outside-async
Introduces two new parser state fields: `awaitContext` and `potentialIllegalAwaitAt`.
Not complete yet - generates several false positives.
Only passing tests have been added.
@danez

This comment has been minimized.

Show comment
Hide comment
@danez

danez Nov 1, 2017

Member

We moved babylon back into the monorepo at https://github.com/babel/babel/tree/master/packages/babylon.

Unfortunately pull requests cannot be migrated between repositories automatically. If this PR is still valid please reopen it there.
Thanks for your effort.

Member

danez commented Nov 1, 2017

We moved babylon back into the monorepo at https://github.com/babel/babel/tree/master/packages/babylon.

Unfortunately pull requests cannot be migrated between repositories automatically. If this PR is still valid please reopen it there.
Thanks for your effort.

@danez danez closed this Nov 1, 2017

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.