Skip to content
This repository has been archived by the owner on Jan 19, 2019. It is now read-only.

declare class is represented the same as a regular class #384

Closed
j-f1 opened this issue Sep 10, 2017 · 3 comments
Closed

declare class is represented the same as a regular class #384

j-f1 opened this issue Sep 10, 2017 · 3 comments
Labels

Comments

@j-f1
Copy link
Contributor

j-f1 commented Sep 10, 2017

What version of TypeScript are you using? 2.4.2

What version of typescript-eslint-parser are you using? 6.0.1

What code were you trying to parse?

declare class Foo {}
declare var Foo
declare function Foo() {}

What did you expect to happen?

The AST should specify that the Foo class and the Foo variable aren’t actual declarations.

Maybe

// declare var Foo
({
  type: 'VariableDeclaration',
  declarations: 
   [ { type: 'VariableDeclarator',
       id: 
        { type: 'Identifier',
         name: 'Foo' },
      init: null } ],
  kind: 'declare var'
})

// declare class Foo {}
({
  type: 'TSAmbientClass',
  id: 
   { type: 'Identifier',
     name: 'Foo' },
  body: 
   { type: 'ClassBody',
     body: [],
  superClass: null
})

What happened?

The AST is the same as the one generated for this code:

class Foo {}
var Foo
declare function Foo() {}

Generated AST:

({ type: 'Program',
  body: 
   [ { type: 'ClassDeclaration',
       id: 
        { type: 'Identifier',
          name: 'Foo' },
       body: 
        { type: 'ClassBody',
          body: [] },
       superClass: null },
     { type: 'VariableDeclaration',
       declarations: 
        [ { type: 'VariableDeclarator',
            id: 
             { type: 'Identifier',
               name: 'Foo' },
            init: null } ],
       kind: 'var' },
     { type: 'DeclareFunction',
       id: 
        { type: 'Identifier',
          name: 'Foo' },
       generator: false,
       expression: false,
       async: false,
       params: [],
       body: 
        { type: 'BlockStatement',
          body: [] } } ],
  sourceType: 'script' })
@j-f1
Copy link
Contributor Author

j-f1 commented Sep 10, 2017

This breaks no-useless-constructor and indent and probably other rules too.

@mysticatea
Copy link
Member

mysticatea commented Nov 8, 2018

I removed ESLint rule/integration issue label because this is an AST issue that the AST cannot distinguish semantics. So let's solve it on the underlying package.

See also JamesHenry/typescript-estree#28.

/cc @JamesHenry

@JamesHenry
Copy link
Member

Fxed by #596

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

4 participants