{"action":"created","issue":{"url":"https://api.github.com/repos/JamesHenry/typescript-estree/issues/28","repository_url":"https://api.github.com/repos/JamesHenry/typescript-estree","labels_url":"https://api.github.com/repos/JamesHenry/typescript-estree/issues/28/labels{/name}","comments_url":"https://api.github.com/repos/JamesHenry/typescript-estree/issues/28/comments","events_url":"https://api.github.com/repos/JamesHenry/typescript-estree/issues/28/events","html_url":"https://github.com/JamesHenry/typescript-estree/issues/28","id":378166471,"node_id":"MDU6SXNzdWUzNzgxNjY0NzE=","number":28,"title":"Inconsistent AST about `declare` keyword","user":{"login":"mysticatea","id":1937871,"node_id":"MDQ6VXNlcjE5Mzc4NzE=","avatar_url":"https://avatars2.githubusercontent.com/u/1937871?v=4","gravatar_id":"","url":"https://api.github.com/users/mysticatea","html_url":"https://github.com/mysticatea","followers_url":"https://api.github.com/users/mysticatea/followers","following_url":"https://api.github.com/users/mysticatea/following{/other_user}","gists_url":"https://api.github.com/users/mysticatea/gists{/gist_id}","starred_url":"https://api.github.com/users/mysticatea/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mysticatea/subscriptions","organizations_url":"https://api.github.com/users/mysticatea/orgs","repos_url":"https://api.github.com/users/mysticatea/repos","events_url":"https://api.github.com/users/mysticatea/events{/privacy}","received_events_url":"https://api.github.com/users/mysticatea/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":9,"created_at":"2018-11-07T07:07:38Z","updated_at":"2018-12-01T05:17:33Z","closed_at":null,"author_association":"NONE","body":"**What version of TypeScript are you using?**\r\n\r\n- 3.1.6\r\n\r\n**What version of `typescript-estree` are you using?**\r\n\r\n- 2.1.0 (typescript-eslint-parser#master)\r\n\r\n**What code were you trying to parse?**\r\n\r\n```ts\r\ndeclare function f1(a: number): number\r\nfunction f2(a: number): number\r\ndeclare namespace n1 {}\r\nnamespace n2 {}\r\ndeclare class C1 {}\r\nclass C2 {}\r\n\r\ndeclare namespace N3 {\r\n    declare function f1(a: number): number\r\n    function f2(a: number): number\r\n}\r\n```\r\n\r\n**What did you expect to happen?**\r\n\r\nI can get consistent AST for semantics about whether the `declare` keyword exists or not.\r\nFor example, consistently `declare:boolean` property or consistently different AST type.\r\n\r\n**What actually happened?**\r\n\r\n<details>\r\n<summary>I got:</summary>\r\n\r\n```json\r\n{\r\n  \"type\": \"Program\",\r\n  \"body\": [\r\n    {\r\n      \"type\": \"TSEmptyBodyDeclareFunction\",\r\n      \"id\": {\r\n        \"type\": \"Identifier\",\r\n        \"name\": \"f1\"\r\n      },\r\n      \"generator\": false,\r\n      \"expression\": false,\r\n      \"async\": false,\r\n      \"params\": [\r\n        {\r\n          \"type\": \"Identifier\",\r\n          \"name\": \"a\",\r\n          \"typeAnnotation\": {\r\n            \"type\": \"TSTypeAnnotation\",\r\n            \"typeAnnotation\": {\r\n              \"type\": \"TSNumberKeyword\"\r\n            }\r\n          }\r\n        }\r\n      ],\r\n      \"body\": null,\r\n      \"returnType\": {\r\n        \"type\": \"TSTypeAnnotation\",\r\n        \"typeAnnotation\": {\r\n          \"type\": \"TSNumberKeyword\"\r\n        }\r\n      }\r\n    },\r\n    {\r\n      \"type\": \"TSEmptyBodyFunctionDeclaration\",\r\n      \"id\": {\r\n        \"type\": \"Identifier\",\r\n        \"name\": \"f2\"\r\n      },\r\n      \"generator\": false,\r\n      \"expression\": false,\r\n      \"async\": false,\r\n      \"params\": [\r\n        {\r\n          \"type\": \"Identifier\",\r\n          \"name\": \"a\",\r\n          \"typeAnnotation\": {\r\n            \"type\": \"TSTypeAnnotation\",\r\n            \"typeAnnotation\": {\r\n              \"type\": \"TSNumberKeyword\"\r\n            }\r\n          }\r\n        }\r\n      ],\r\n      \"body\": null,\r\n      \"returnType\": {\r\n        \"type\": \"TSTypeAnnotation\",\r\n        \"typeAnnotation\": {\r\n          \"type\": \"TSNumberKeyword\"\r\n        }\r\n      }\r\n    },\r\n    {\r\n      \"type\": \"TSModuleDeclaration\",\r\n      \"id\": {\r\n        \"type\": \"Identifier\",\r\n        \"name\": \"n1\"\r\n      },\r\n      \"body\": {\r\n        \"type\": \"TSModuleBlock\",\r\n        \"body\": []\r\n      },\r\n      \"declare\": true\r\n    },\r\n    {\r\n      \"type\": \"TSModuleDeclaration\",\r\n      \"id\": {\r\n        \"type\": \"Identifier\",\r\n        \"name\": \"n2\"\r\n      },\r\n      \"body\": {\r\n        \"type\": \"TSModuleBlock\",\r\n        \"body\": []\r\n      }\r\n    },\r\n    {\r\n      \"type\": \"ClassDeclaration\",\r\n      \"id\": {\r\n        \"type\": \"Identifier\",\r\n        \"name\": \"C1\"\r\n      },\r\n      \"body\": {\r\n        \"type\": \"ClassBody\",\r\n        \"body\": []\r\n      },\r\n      \"superClass\": null\r\n    },\r\n    {\r\n      \"type\": \"ClassDeclaration\",\r\n      \"id\": {\r\n        \"type\": \"Identifier\",\r\n        \"name\": \"C2\"\r\n      },\r\n      \"body\": {\r\n        \"type\": \"ClassBody\",\r\n        \"body\": []\r\n      },\r\n      \"superClass\": null\r\n    },\r\n    {\r\n      \"type\": \"TSInterfaceDeclaration\",\r\n      \"abstract\": false,\r\n      \"body\": {\r\n        \"type\": \"TSInterfaceBody\",\r\n        \"body\": []\r\n      },\r\n      \"id\": {\r\n        \"type\": \"Identifier\",\r\n        \"name\": \"I1\"\r\n      },\r\n      \"heritage\": []\r\n    },\r\n    {\r\n      \"type\": \"TSInterfaceDeclaration\",\r\n      \"abstract\": false,\r\n      \"body\": {\r\n        \"type\": \"TSInterfaceBody\",\r\n        \"body\": []\r\n      },\r\n      \"id\": {\r\n        \"type\": \"Identifier\",\r\n        \"name\": \"I2\"\r\n      },\r\n      \"heritage\": []\r\n    },\r\n    {\r\n      \"type\": \"TSEnumDeclaration\",\r\n      \"id\": {\r\n        \"type\": \"Identifier\",\r\n        \"name\": \"E1\"\r\n      },\r\n      \"members\": [],\r\n      \"declare\": true\r\n    },\r\n    {\r\n      \"type\": \"TSEnumDeclaration\",\r\n      \"id\": {\r\n        \"type\": \"Identifier\",\r\n        \"name\": \"E2\"\r\n      },\r\n      \"members\": []\r\n    },\r\n    {\r\n      \"type\": \"TSModuleDeclaration\",\r\n      \"id\": {\r\n        \"type\": \"Identifier\",\r\n        \"name\": \"N3\"\r\n      },\r\n      \"body\": {\r\n        \"type\": \"TSModuleBlock\",\r\n        \"body\": [\r\n          {\r\n            \"type\": \"TSEmptyBodyDeclareFunction\",\r\n            \"id\": {\r\n              \"type\": \"Identifier\",\r\n              \"name\": \"f1\"\r\n            },\r\n            \"generator\": false,\r\n            \"expression\": false,\r\n            \"async\": false,\r\n            \"params\": [\r\n              {\r\n                \"type\": \"Identifier\",\r\n                \"name\": \"a\",\r\n                \"typeAnnotation\": {\r\n                  \"type\": \"TSTypeAnnotation\",\r\n                  \"typeAnnotation\": {\r\n                    \"type\": \"TSNumberKeyword\"\r\n                  }\r\n                }\r\n              }\r\n            ],\r\n            \"body\": null,\r\n            \"returnType\": {\r\n              \"type\": \"TSTypeAnnotation\",\r\n              \"typeAnnotation\": {\r\n                \"type\": \"TSNumberKeyword\"\r\n              }\r\n            }\r\n          },\r\n          {\r\n            \"type\": \"TSEmptyBodyFunctionDeclaration\",\r\n            \"id\": {\r\n              \"type\": \"Identifier\",\r\n              \"name\": \"f2\"\r\n            },\r\n            \"generator\": false,\r\n            \"expression\": false,\r\n            \"async\": false,\r\n            \"params\": [\r\n              {\r\n                \"type\": \"Identifier\",\r\n                \"name\": \"a\",\r\n                \"typeAnnotation\": {\r\n                  \"type\": \"TSTypeAnnotation\",\r\n                  \"typeAnnotation\": {\r\n                    \"type\": \"TSNumberKeyword\"\r\n                  }\r\n                }\r\n              }\r\n            ],\r\n            \"body\": null,\r\n            \"returnType\": {\r\n              \"type\": \"TSTypeAnnotation\",\r\n              \"typeAnnotation\": {\r\n                \"type\": \"TSNumberKeyword\"\r\n              }\r\n            }\r\n          }\r\n        ]\r\n      },\r\n      \"declare\": true\r\n    }\r\n  ],\r\n  \"sourceType\": \"script\"\r\n}\r\n```\r\n\r\n</details><br>\r\n\r\nIn short:\r\n\r\n- On functions, the `declare` keyword changes AST node types: `DeclareFunction` or `FunctionDeclaration`\r\n- On classes, the `declare` keyword does not change AST. I cannot distinguish it.\r\n- On interfaces, the `declare` keyword does not change AST. I cannot distinguish it.\r\n- On enums, the `declare` keyword changes `node.declare` property.\r\n- On namespaces, the `declare` keyword changes `node.declare` property.\r\n  - In namespaces which have the `declare` keyword, in semantics, I think that the declarations in the namespaces are same as having the `declare` keyword, but...\r\n\r\nAnyway, I want a consistent behavior around this."},"comment":{"url":"https://api.github.com/repos/JamesHenry/typescript-estree/issues/comments/443400835","html_url":"https://github.com/JamesHenry/typescript-estree/issues/28#issuecomment-443400835","issue_url":"https://api.github.com/repos/JamesHenry/typescript-estree/issues/28","id":443400835,"node_id":"MDEyOklzc3VlQ29tbWVudDQ0MzQwMDgzNQ==","user":{"login":"mysticatea","id":1937871,"node_id":"MDQ6VXNlcjE5Mzc4NzE=","avatar_url":"https://avatars2.githubusercontent.com/u/1937871?v=4","gravatar_id":"","url":"https://api.github.com/users/mysticatea","html_url":"https://github.com/mysticatea","followers_url":"https://api.github.com/users/mysticatea/followers","following_url":"https://api.github.com/users/mysticatea/following{/other_user}","gists_url":"https://api.github.com/users/mysticatea/gists{/gist_id}","starred_url":"https://api.github.com/users/mysticatea/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mysticatea/subscriptions","organizations_url":"https://api.github.com/users/mysticatea/orgs","repos_url":"https://api.github.com/users/mysticatea/repos","events_url":"https://api.github.com/users/mysticatea/events{/privacy}","received_events_url":"https://api.github.com/users/mysticatea/received_events","type":"User","site_admin":false},"created_at":"2018-12-01T05:17:33Z","updated_at":"2018-12-01T05:17:33Z","author_association":"NONE","body":"I follow the @JamesHenry decision because this is your product :smile: .\r\n\r\nFor what it's worth, as I said on https://github.com/JamesHenry/typescript-estree/pull/38#issuecomment-443058786, JS and TS have very different mental model about AST. I'm warried that the mix of the two in `typescript-estree` causes confusion."}}
{"actor":{"display_login":"mysticatea"}}