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

cannot distinguish declare global on AST. #27

Closed
mysticatea opened this issue Nov 7, 2018 · 4 comments · Fixed by #38
Closed

cannot distinguish declare global on AST. #27

mysticatea opened this issue Nov 7, 2018 · 4 comments · Fixed by #38

Comments

@mysticatea
Copy link

What version of TypeScript are you using?

  • 3.1.6

What version of typescript-estree are you using?

  • 2.1.0 (typescript-eslint-parser#master)

What code were you trying to parse?

// Augmentations for the global stuff.
declare global {
}

// A namespace declaration.
declare namespace global {
}

What did you expect to happen?

typescript-estree generates different nodes because the two have different semantics.

What actually happened?

typescript-estree generates the same node:

    {
      "type": "TSModuleDeclaration",
      "id": {
        "type": "Identifier",
        "name": "global"
      },
      "body": {
        "type": "TSModuleBlock",
        "body": []
      },
      "declare": true
    }
@mysticatea
Copy link
Author

TSGlobalAugmentationDeclaration node may be nice.

// The node that expresses `declare global {}`.
interface TSGlobalAugmentationDeclaration extends Statement {
    type: "TSGlobalAugmentationDeclaration"
    body: TSModuleBlock
}

@mysticatea
Copy link
Author

@JamesHenry what do you think about this? I think critical if we cannot distinguish semantic on AST.

@armano2
Copy link
Contributor

armano2 commented Nov 29, 2018

According to babel/typescript its: https://github.com/babel/babel/blob/master/packages/babel-types/src/definitions/typescript.js#L390

defineType("TSModuleDeclaration", {
  aliases: ["Statement", "Declaration"],
  visitor: ["id", "body"],
  fields: {
    declare: validateOptional(bool),
    global: validateOptional(bool),
    id: validateType(["Identifier", "StringLiteral"]),
    body: validateType(["TSModuleBlock", "TSModuleDeclaration"]),
  },
});

AST is not aligned it should contain global: validateOptional(bool),

https://github.com/babel/babel/blob/master/packages/babel-parser/src/plugins/typescript.js#L1046

@JamesHenry
Copy link
Owner

🎉 This issue has been resolved in version 5.3.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

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 a pull request may close this issue.

3 participants