{"action":"created","issue":{"url":"https://api.github.com/repos/estree/estree/issues/40","labels_url":"https://api.github.com/repos/estree/estree/issues/40/labels{/name}","comments_url":"https://api.github.com/repos/estree/estree/issues/40/comments","events_url":"https://api.github.com/repos/estree/estree/issues/40/events","html_url":"https://github.com/estree/estree/issues/40","id":59679413,"number":40,"title":"About correctness: let+const VariableDeclaration vs Statement","user":{"login":"fkling","id":179026,"avatar_url":"https://avatars.githubusercontent.com/u/179026?v=3","gravatar_id":"","url":"https://api.github.com/users/fkling","html_url":"https://github.com/fkling","followers_url":"https://api.github.com/users/fkling/followers","following_url":"https://api.github.com/users/fkling/following{/other_user}","gists_url":"https://api.github.com/users/fkling/gists{/gist_id}","starred_url":"https://api.github.com/users/fkling/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/fkling/subscriptions","organizations_url":"https://api.github.com/users/fkling/orgs","repos_url":"https://api.github.com/users/fkling/repos","events_url":"https://api.github.com/users/fkling/events{/privacy}","received_events_url":"https://api.github.com/users/fkling/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":3,"created_at":"2015-03-03T17:56:12Z","updated_at":"2015-03-05T11:30:54Z","closed_at":"2015-03-04T16:05:07Z","body":"Sorry if this was already discussed, I couldn't find anything about it.\r\n\r\nCurrently a `Declaration` is a `Statement`, and  `VariableDeclaration` is extended to represent `let` and `const` as well:\r\n\r\n```js\r\ninterface Declaration <: Statement { }\r\n\r\ninterface VariableDeclaration <: Declaration {\r\n    type: \"VariableDeclaration\";\r\n    declarations: [ VariableDeclarator ];\r\n    kind: \"var\";\r\n}\r\n\r\nextend interface VariableDeclaration {\r\n    kind: \"var\" | \"let\" | \"const\";\r\n}\r\n```\r\n\r\nThat allows the following AST (or similar), which is not a valid JS program:\r\n\r\n```js\r\n // if (x) let y = 42;\r\n{\r\n  \"type\": \"IfStatement\",\r\n  \"test\": {...},\r\n  \"consequent\": {\r\n    \"type\": \"VariableDeclaration\",\r\n    \"declarations\": [...]\r\n    \"kind\": \"let\",\r\n  },\r\n  \"alternate\": null,\r\n}\r\n```\r\n\r\nBut of course a parser could easily detect this and throw accordingly.\r\n\r\nI am trying to get an idea about the direction/principles of estree. Is a simple API favored over correctness/spec compliancy and is correctness offloaded to parser implementations?\r\n\r\nOr is this something that should be fixed?"},"comment":{"url":"https://api.github.com/repos/estree/estree/issues/comments/77348875","html_url":"https://github.com/estree/estree/issues/40#issuecomment-77348875","issue_url":"https://api.github.com/repos/estree/estree/issues/40","id":77348875,"user":{"login":"michaelficarra","id":218840,"avatar_url":"https://avatars.githubusercontent.com/u/218840?v=3","gravatar_id":"","url":"https://api.github.com/users/michaelficarra","html_url":"https://github.com/michaelficarra","followers_url":"https://api.github.com/users/michaelficarra/followers","following_url":"https://api.github.com/users/michaelficarra/following{/other_user}","gists_url":"https://api.github.com/users/michaelficarra/gists{/gist_id}","starred_url":"https://api.github.com/users/michaelficarra/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/michaelficarra/subscriptions","organizations_url":"https://api.github.com/users/michaelficarra/orgs","repos_url":"https://api.github.com/users/michaelficarra/repos","events_url":"https://api.github.com/users/michaelficarra/events{/privacy}","received_events_url":"https://api.github.com/users/michaelficarra/received_events","type":"User","site_admin":false},"created_at":"2015-03-05T11:30:54Z","updated_at":"2015-03-05T11:30:54Z","body":"@fkling:\r\n\r\n> there's a lot of things that are not valid executable JavaScript, but can be represented by AST\r\n\r\nThis is one of the major motivations behind the design of [the Shift AST format](http://engineering.shapesecurity.com/2014/12/announcing-shift-javascript-ast.html). If that's what you're looking for, you should look into using the Shift format instead. I've compiled a [list of similar problems throughout the SpiderMonkey AST format](http://engineering.shapesecurity.com/2015/01/a-technical-comparison-of-shift-and.html)."}}