Start and end locations when there are decorators
jseminck opened this issue · comments
I am not really sure if this is actually a bug, or if it is working as intended. It causes a bug on another project (astexplorer) but before trying to find a way to deal with it there I first want to confirm here if it's a bug or working as intended.
I have seen that when a decorator is attached to an exported class, then the start and end locations of the ExportDefaultDeclaration
are not updated correctly. There was a PR recently that fixes the locations on the node that the decorator is attached to, but it did not update any possible parent nodes.
Input Code
@connect(
state => ({
myElement: getMyElement(state)
}),
{ myAction }
)
export default class MyComponent extends React.Component {
render() {}
}
Expected Behavior
Current Behavior
So if you look at the AST below, we can see that:
Program
starts at 0
ExportDefaultDeclaration
starts at 83
ClassDeclaration
starts at 0 (actually this was done in #699 but ASTExplorer hasn't been updated yet)
Decorator
starts at 0
So the question is: should ExportDefaultDeclaration
start at 83 or at 0 ?
I have briefly looked into the code based on the existing PR. But in the code where we reset the start location for the ClassDeclaration
, there seems to be no possible way to also update all the parents of that specific node. I'm not very well versed with parsers but I suppose that makes sense... there's only the object creations going on.
Anyway, if this is a bug I would really like to help out and fix it. If it is not a bug, then I'll look for an alternative solution to fix the bug that this causes in ASTExplorer: fkling/astexplorer#269
Hey @jseminck! We really appreciate you taking the time to report an issue. The collaborators
on this project attempt to help as many people as possible, but we're a limited number of volunteers,
so it's possible this won't be addressed swiftly.
If you need any help, or just have general Babel or JavaScript questions, we have a vibrant Slack
community that typically always has someone willing to help. You can sign-up here
for an invite.
This issue has been moved to babel/babel#6676.