Open Gozala opened 8 years ago
I guess easier way to see this issue is by looking at https://astexplorer.net/#/8hK2Y2BwqI
the "fun" thing here is that the startToken of the body is really the {
because the body
is marked as an ObjectExpression
... - AST ignores parenthesis in most cases...
this is one of the main reasons why I really wanted to have a REAL concrete syntax tree, where the parenthesis would create groups and have an easy way to capture the start/end of the group... but it would be too much work and I went with the easy way...
see getParentheses
method inside https://github.com/millermedeiros/esformatter/blob/master/lib/hooks/expressionParentheses.js#L19 - maybe we should export this function on the esformatter
object to make it easier for plugins to reuse it (esformatter
is passed as second argument on plugin.setOptions
)
Here is an example code:
I'm trying to write plugin that would reformat such function as follows:
But when attempting to do something along these lines:
I get following result:
And more importantly following thing is being logged:
It seems that
startToken
of the function body is{
instead of expected(
.