astexplorer icon indicating copy to clipboard operation
astexplorer copied to clipboard

Typescript `declare` syntax not supported in typescript eslint

Open NullVoxPopuli opened this issue 5 years ago • 3 comments

Describe the bug The URL I'm working with might not live forever, but this is the error at the time of writing. This is an issue with the transformer's parser. Parsing into the AST seems to work fine.

// Parsing error: Unexpected token

  4 | 
  5 | export class Foo {
> 6 |   declare regularProperty: number;

To Reproduce Steps to reproduce the behavior: as demonstrated in https://astexplorer.net/#/gist/109e7e211c47172833af69eff15cc565/149750098824767f23980eb51790bed2ba67cf7a

  1. select @typescript-eslint/parser
  2. use declare in a class. e.g.:
class Foo {
  declare foo: number;
}
  1. Notice error

Expected behavior There should not be a parsing error

Screenshots image

If applicable, add screenshots to help explain your problem.

Browser (please complete the following information):

  • any browser
  • any OS

Additional Context

Transforms that don't error on the declare keyword:

  • prettier
  • babel-plugin-macros
  • babelv7

Transforms that do error on the declare keyword:

  • tslint (which isn't used anymore anyway, so this is fine)
  • jscodeshift (probably needs a specific parser set)
  • ESLint v4 (I wouldn't expect this to work by default, but I don't know how I'd set the parser to parser: '@typescript-eslint/parser',, per: https://github.com/typescript-eslint/typescript-eslint/blob/master/docs/getting-started/linting/README.md
    • this is the parser I have selected in the ASTExplorer UI, but I don't quite know if that feeds or is configured directly with the transformer.

Of note, declare is new as of TypeScript 3.8 -- I couldn't find anything in the ASTExplorer UI to hint at which TypeScript version was being used. I only see what versions of the parser and transform plugins are used: image

NullVoxPopuli avatar Oct 18 '20 00:10 NullVoxPopuli

New as of 3.7 - https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-7.html#the-usedefineforclassfields-flag-and-the-declare-property-modifier

Gerrit0 avatar Oct 18 '20 01:10 Gerrit0

Related: https://github.com/NullVoxPopuli/eslint-plugin-decorator-position/pull/170

NullVoxPopuli avatar Oct 19 '20 20:10 NullVoxPopuli

this is the parser I have selected in the ASTExplorer UI, but I don't quite know if that feeds or is configured directly with the transformer.

That's exactly the issue: It doesn't. The parser is completely independent of the transformer. I know it's confusing and surprising, and I don't like it. I think the next version of astexplorer will not distinguish between parsers and transformers. You will be able to select a transformer and if it supports multiple parsers you will be able to configure it accordingly.

I'm really sorry for the confusion.

fkling avatar Oct 22 '20 18:10 fkling