Skip to content

grammar errors should be reported as syntactic diagnostics #29213

@ajafff

Description

@ajafff

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    In DiscussionNot yet reached consensusSuggestionAn idea for TypeScript

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions