-
Notifications
You must be signed in to change notification settings - Fork 13
Inconsistent AST about declare
keyword
#28
Comments
See also eslint/typescript-eslint-parser#384 |
interface TSAmbientDeclaration extends Statement {
declaration:
| VariableDeclaration
| FunctionDeclaration
| TSInterfaceDeclaration
| TSEnumDeclaration
| TSModuleDeclaration
} All declaration in this node, contains declarations in module blocks recursively, are handled as ambient declarations. This is similar to (EDIT: I have less understanding about the ambient declaration of TypeScript, I may say strange things...) |
I like this idea. In babel-typescript types: We have few types like this is a mess, we should decide how we are going to do it, we can follow babel or @mysticatea proposal but it has to be consistent |
@JamesHenry can you take a look on this? |
I won’t have time over the next week as I’m travelling a lot. Definitely open to PRs if anyone else gets chance, otherwise I may have some time the week after. My gut reaction is: I prefer @MysticTea’s approach but that initially alignment with Babel might be preferable. We can then consider if it’s worth updating both tools. WDYT? |
i can make those changes, but i don't know which one to go for... :> |
Let’s go for matching Babel unless there is a strong reason not to as a general rule. It’s why I spent the time setting up the testing for it. The Babel support was built by the TS Team themselves and they have always been open to changes where they make sense, so if we feel strongly the AST design is not optimal we can propose a change to them and carry it out in both tools later |
@mysticatea any objections? |
I follow the @JamesHenry decision because this is your product 😄 . For what it's worth, as I said on #38 (comment), JS and TS have very different mental model about AST. I was warried that the mix of the two in |
@mysticatea i did most of changes for delcare, but i'm unsure what i should do with type Foo = string right now it's {
"body": [
{
"declarations": [
{
"id": {
"loc": {
"end": {
"column": 16,
"line": 1
},
"start": {
"column": 13,
"line": 1
}
},
"name": "Foo",
"range": [
13,
16
],
"type": "Identifier"
},
"init": {
"loc": {
"end": {
"column": 25,
"line": 1
},
"start": {
"column": 19,
"line": 1
}
},
"range": [
19,
25
],
"type": "TSStringKeyword"
},
"loc": {
"end": {
"column": 25,
"line": 1
},
"start": {
"column": 13,
"line": 1
}
},
"range": [
13,
25
],
"type": "VariableDeclarator"
}
],
"kind": "type",
"loc": {
"end": {
"column": 25,
"line": 1
},
"start": {
"column": 0,
"line": 1
}
},
"range": [
0,
25
],
"type": "VariableDeclaration"
}
],
"sourceType": "script",
"type": "Program"
}
but babel defines is at new node |
There is also this |
I remember eslint/typescript-eslint-parser#414 |
ok, i will take a look on this to than :> |
@JamesHenry this issue got solved in #42 |
What version of TypeScript are you using?
What version of
typescript-estree
are you using?What code were you trying to parse?
What did you expect to happen?
I can get consistent AST for semantics about whether the
declare
keyword exists or not.For example, consistently
declare:boolean
property or consistently different AST type.What actually happened?
I got:
In short:
declare
keyword changes AST node types:DeclareFunction
orFunctionDeclaration
declare
keyword does not change AST. I cannot distinguish it.declare
keyword does not change AST. I cannot distinguish it.declare
keyword changesnode.declare
property.declare
keyword changesnode.declare
property.declare
keyword, in semantics, I think that the declarations in the namespaces are same as having thedeclare
keyword, but...Anyway, I want a consistent behavior around this.
The text was updated successfully, but these errors were encountered: