Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Binding identifier should care about await/yield context #44459

Closed
Kingwl opened this issue Jun 6, 2021 · 3 comments Β· Fixed by #44680
Closed

Binding identifier should care about await/yield context #44459

Kingwl opened this issue Jun 6, 2021 · 3 comments Β· Fixed by #44680
Labels
Bug A bug in TypeScript Help Wanted You can do this
Milestone

Comments

@Kingwl
Copy link
Contributor

Kingwl commented Jun 6, 2021

Bug Report

πŸ”Ž Search Terms

parsing, await, yield

πŸ•— Version & Regression Information

  • This changed between versions 3.9.7 and now

⏯ Playground Link

Playground

πŸ’» Code

async function foo () {
  var await = 1; // should be an error, but not
}

async function bar () {
  let await = 2; // error
}

function * foo1() {
  var yield = 1; // should be an error, but not
}

function * bar1() {
  let yield = 2; // error
}

πŸ™ Actual behavior

BindingIdentifier in await/yield with var keyword does not throw errors.

πŸ™‚ Expected behavior

It should.

Related:

@RyanCavanaugh RyanCavanaugh added the Bug A bug in TypeScript label Jun 8, 2021
@RyanCavanaugh RyanCavanaugh added this to the Backlog milestone Jun 8, 2021
@RyanCavanaugh RyanCavanaugh added the Help Wanted You can do this label Jun 8, 2021
@sandersn
Copy link
Member

The problem is that let await errors are issued in the parser and var await errors are issued in the binder. Syntax errors block reporting of semantic errors.

The parse errors for let await are horrible, so the right fix is to allow it in the parser and issue the same grammar error as for var await in the binder.

Note that this will make the error disappear in plain JS files for now. I hope to fix that soon.

@Kingwl
Copy link
Contributor Author

Kingwl commented Jun 22, 2021

Note that this will make the error disappear in plain JS files for now. I hope to fix that soon.

Sorry, I'm not 100% sure what your means. Does plain JS files means js files we emitted?

@sandersn
Copy link
Member

Sorry, it's a new term. 'plain JS file' means a JS file that is part of a compilation, but is not reporting semantic errors. That is, checkJS is not turned on OR explicitly off, and the file doesn't have // @ts-check or // @ts-no-check in it. Plain JS files report syntax errors but not semantic errors, so moving a parser error to a grammar error makes it disappear. However, I'm planning to turn on grammar errors for plain JS files in the next release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript Help Wanted You can do this
Projects
None yet
3 participants