microsoft / microsoft/TypeScript
grammar errors should be reported as syntactic diagnostics
Nobody has claimed this yet.
- Dominant language
- Go
- Stars
- 111k
- Forks
- 14.3k
- Avg merge
- 2d 4h
- Merged PRs (30d)
- 132
Description
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
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the examples in the TypeScript parser and compare JavaScript diagnostics with and without // @ts-check. Start by tracing grammar errors through parsing, type-checking, and the related binding phase discussed in issues #6107 and #6802. Done means the listed invalid constructs produce syntax diagnostics in JavaScript files without requiring type-checking.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, typescript
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100