Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(typescript-estree): add ExportDefaultDeclaration to union DeclarationStatement #378

Merged
merged 1 commit into from Mar 27, 2019

Conversation

ndelangen
Copy link
Contributor

I have this example:

https://astexplorer.net/#/gist/2c50aae34bea149fc9863a2dd0e7a6f5/69d563ee31f1bc01d3cf71c005bb92dd24c3910e

Notice how

export default class Foo {}

Is transformed to:

{
      "type": "ExportDefaultDeclaration",
      "declaration": {
        "type": "ClassDeclaration",
        "id": {
          "type": "Identifier",
          "name": "Foo",
          "range": [
            580,
            583
          ],
          "loc": {
            "start": {
              "line": 30,
              "column": 21
            },
            "end": {
              "line": 30,
              "column": 24
            }
          }
        },
        "body": {
          "type": "ClassBody",
          "body": [],
          "range": [
            584,
            586
          ],
          "loc": {
            "start": {
              "line": 30,
              "column": 25
            },
            "end": {
              "line": 30,
              "column": 27
            }
          }
        },
        "superClass": null,
        "range": [
          574,
          586
        ],
        "loc": {
          "start": {
            "line": 30,
            "column": 15
          },
          "end": {
            "line": 30,
            "column": 27
          }
        }
      },
      "range": [
        559,
        586
      ],
      "loc": {
        "start": {
          "line": 30,
          "column": 0
        },
        "end": {
          "line": 30,
          "column": 27
        }
      }
    }

according to Program.body which is a Statement[]

and Statement containing DeclarationStatement

I conclude that DeclarationStatement is missing ExportDefaultDeclaration

I have this example:

https://astexplorer.net/#/gist/2c50aae34bea149fc9863a2dd0e7a6f5/69d563ee31f1bc01d3cf71c005bb92dd24c3910e

Notice how
```
export default class Foo {}
```

Is transformed to:

```
{
      "type": "ExportDefaultDeclaration",
      "declaration": {
        "type": "ClassDeclaration",
        "id": {
          "type": "Identifier",
          "name": "Foo",
          "range": [
            580,
            583
          ],
          "loc": {
            "start": {
              "line": 30,
              "column": 21
            },
            "end": {
              "line": 30,
              "column": 24
            }
          }
        },
        "body": {
          "type": "ClassBody",
          "body": [],
          "range": [
            584,
            586
          ],
          "loc": {
            "start": {
              "line": 30,
              "column": 25
            },
            "end": {
              "line": 30,
              "column": 27
            }
          }
        },
        "superClass": null,
        "range": [
          574,
          586
        ],
        "loc": {
          "start": {
            "line": 30,
            "column": 15
          },
          "end": {
            "line": 30,
            "column": 27
          }
        }
      },
      "range": [
        559,
        586
      ],
      "loc": {
        "start": {
          "line": 30,
          "column": 0
        },
        "end": {
          "line": 30,
          "column": 27
        }
      }
    }
```

according to Program.body which is a Statement[]

and `Statement` containing `DeclarationStatement`

I conclude that `DeclarationStatement` is missing `ExportDefaultDeclaration`
@ndelangen
Copy link
Contributor Author

I'm contributing 'in the 'dark', if this is wrong, no hard feelings, if this commit needs to be changed to conform to something 👍

@ndelangen
Copy link
Contributor Author

ndelangen commented Mar 27, 2019

I found this by trying this:

if (i.type === AST_NODE_TYPES.ExportDefaultDeclaration) {
}

where i is a Program["body"]

which resulted in a typescript error:

This condition will always return 'false' since the types 'AST_NODE_TYPES.BlockStatement | AST_NODE_TYPES.BreakStatement | AST_NODE_TYPES.ClassDeclaration | AST_NODE_TYPES.ClassExpression | AST_NODE_TYPES.ContinueStatement | AST_NODE_TYPES.DebuggerStatement | AST_NODE_TYPES.DoWhileStatement | AST_NODE_TYPES.EmptyStatement | AST_NODE_TYPES.ExportAllDeclaration | AST_NODE_TYP...' and 'AST_NODE_TYPES.ExportDefaultDeclaration' have no overlap.ts(2367)

@ndelangen ndelangen changed the title ADD ExportDefaultDeclaration to union DeclarationStatement bug(typescript-estree) add ExportDefaultDeclaration to union DeclarationStatement Mar 27, 2019
@ndelangen ndelangen changed the title bug(typescript-estree) add ExportDefaultDeclaration to union DeclarationStatement fix(typescript-estree) add ExportDefaultDeclaration to union DeclarationStatement Mar 27, 2019
@bradzacher bradzacher changed the title fix(typescript-estree) add ExportDefaultDeclaration to union DeclarationStatement fix(typescript-estree): add ExportDefaultDeclaration to union DeclarationStatement Mar 27, 2019
@bradzacher bradzacher merged commit bf04398 into typescript-eslint:master Mar 27, 2019
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 21, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants