Skip to content
This repository was archived by the owner on Jan 19, 2019. It is now read-only.
This repository was 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

Description

@j-f1

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' })

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions