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

grammar errors should be reported as syntactic diagnostics #29213

Open
ajafff opened this issue Dec 31, 2018 · 0 comments
Open

grammar errors should be reported as syntactic diagnostics #29213

ajafff opened this issue Dec 31, 2018 · 0 comments
Labels
In Discussion Not yet reached consensus Suggestion An idea for TypeScript

Comments

@ajafff
Copy link
Contributor

ajafff commented Dec 31, 2018

TypeScript Version: 3.3.0-dev.20181222

Search Terms:

Code

// @filename: test.js
function test(...args,) {} // trailing comma not allowed

class C {
  async static foo() {} // modifiers are in the wrong order
}

@decorator // invalid decorator location
async var v = 1; // invalid modifier location

let {...rest: rest} = {}; // rest property cannot have a property name

Expected behavior:

All errors above are reported in JS files as they result in parse errors when executed.

Actual behavior:

The above file has no errors. They are not reported as syntax errors because TypeScript's parser is more permissive than the spec in many cases. Since grammar errors are only reported during type-checking they are ignored in JS files without // @ts-check.

Other JS parsers, e.g. javascript VMs, emit a parse error for the code above.

Related Issues:
#6107 suggests moving grammar errors to the binding phase
#6802

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
In Discussion Not yet reached consensus Suggestion An idea for TypeScript
Projects
None yet
Development

No branches or pull requests

2 participants