-
-
Notifications
You must be signed in to change notification settings - Fork 75
Fix: Label variable declartions as Ambient (fixes #185) #198
Conversation
LGTM |
lib/ast-converter.js
Outdated
variableIsAmbient = ts.isInAmbientContext(node); | ||
|
||
if (variableIsAmbient) { | ||
variableDeclarationType = "TSAmbientVariableDefinition"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this should be TSAmbientVariableDeclaration since it fits better with estree. What was the reason behind VariableDefinition?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You used definition for the the methods in #163 and I just followed that because that what I based this PR on. But I agree with you Declaration would probably be better in this case, will update.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks I just feel like we should be as close to estree as possible.
LGTM |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
I think the downside of this is that the standard ESLint rules which apply to That tradeoff is probably worth it for now... |
I could add a property to the node instead, maybe I have no idea what approach is the best in this case though. |
@JamesHenry @Pajn The reason I recommended using a new node type was because I found that empty body Function Expressions/Declarations, those used in declared functions or ambient class declarations, caused rules to break in eslint. I know we have renamed node types before, such as Abstract Classes or Functions in Namespaces, to overcome rule failures and thought that solution might work here as well. If we didn't use new node types we can always fix the rules in eslint, and other plugins. So I would not be opposed to using a property. Another thing I just though of is that using the method declare namespace Foo {
const bar = 0; //I think isInAmbientContext is true
} Will that be a problem? Should we use two different properties for declared or isAmbient? |
I think that when changing the structure of the nodes (like not having a body in a function), the type should change as those probably will be handled differently both by eslint rules and by pretter.
Uh, yes. At least for pretter it's important to differentiate them as it needs to know if it should print "declare " or not. It might be less important for lint rules as those probably will apply the same rules in either case, but I think they should have the ability to differentiate them because you never know what rules that may come up in the future. |
I am leaning towards a So many standard constructs in TypeScript can also be "declared" to turn them into ambient type information, rather than true implementation details. declare var foo
declare function bar() {}
declare class Qux {}
etc By simply marking the nodes as @Pajn please could you add @soda0289's example case above as a test either way? We will still need to separately address the point around empty bodies on ESTree nodes (which other tools are expecting to be there), but can you guys think of any other downsides of going with the |
@JamesHenry We could even change abstract methods and classes to just use a property as well. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you change this to use a property declared
?
Thanks a lot for your contributions to the project, @Pajn! I am going to close this now, as significant changes have been made to the codebase since this was first opened. We are tracking similar changes to this one here: https://github.com/JamesHenry/tsep-babylon-test/issues/6 |
I'm sorry for having letting it drag out. Your collaboration with the TS team is super exciting, great work! |
Sets a new type on ambient variables as discussed in #185. I tried to follow the implementation in #163