New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Object comments #176
Object comments #176
Conversation
@@ -1526,6 +1526,9 @@ | |||
throw new Error('Unknown expression type: ' + expr.type); | |||
} | |||
|
|||
if (expr.leadingComments || expr.trailingComments) { |
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.
extra.comment
check is necessary. Replacing expr.leadingComments || expr.trailingComments
with extra.comment
I've reviewed. |
I think 2 options are needed, |
Thanks |
or should i fix these things and make another PR? |
Does it make sense to fix such things now, or to defer until the concrete syntax tree stuff works out? |
Could you fix the reviewed point and rebase this PR? As discussed at #133 (comment), I think escodegen need to provide good default code generation for AST (not for CST). So this PR makes sense. It provides good default comment code generation. After CST works out, escodegen will also provide AST to CST functionality with these good default format. ;) |
And |
To be honest, that approach doesn't make much sense to me, in several respects. I plan to create my own CST and shove it into It's an expressed goal of CST that it holds all the standardized way of representing all whitespace and comments (and any other "extras"). This means parsers need to see that standard CST format, and it also means that code generators need so use that same standard CST format. The ad hoc tracking of whitespace and comments in both parsers and code generators as it stands today should, IMO, be replaced by a CST, not sitting along side it. So, if we're heading soon towards a CST (which I really hope we are), I'm not sure why work should continue on things that are clearly not informed by, nor likely compatible with, where CST is heading in the short-term. Again, just my 2 cents. |
Ah, maybe there's misleading points in my comments.
Yes, not ssitting along side it. Will be reconstructed on the top of CST. To show my design of js tools with CST clearly, I'll create and attach figures about tool stacks later.(after I have dinner) Sorry for your inconvenience. |
I've created figures. Currently JS modules infrastructure is shown as the above. However, AST has a problem, it doesn't have any textual information such as whitespaces. Now I have the new JS modules design, the following figure describe it. In this newly reconstructed modules, I'm planning to implement This PR adds good default comment handling part to OK, so I'll answer your questions.
If you would like to pass your own CST to escodegen, you can use
These options work in
Actual code generation part will be implemented as Since I think the JS tools design with CST will become as the above, so I think this PR makes sense (this PR is part of @getify, maybe you have the different design. could you show me it? @michaelficarra: |
Yes, that is exactly what I had understood from #133. Thanks for making the awesome diagram. An additional note: depending on the structure we choose for CSTs, the CST->AST transformation may be the identity function. |
I think all this discussion is great, but we now have a dedicated place for it: https://github.com/getify/concrete-syntax-tree I would strongly suggest/request that you move these posts from here to an issue thread there. I just started one there with my diagram of how I see the flow working (I think somewhat more simply). Feel free to hijack that thread, or create a new one, for what's being discussed here. |
Hi @getify and @michaelficarra, I've posted getify/concrete-syntax-tree#3 ! |
@Constellation I changed the condition from |
Hi @getify Seeing your proposal, you also suggested that
In your proposal this code will become a part of
So I think this PR makes sense in both proposals, mine and yours. So I would like to merge it. Do you agree with this? |
Ah, I'll add them later. |
Code itself looks nice. |
This is your project, I didn't mean to butt in and try to control it. If you think it makes sense, sure. I just wasn't clear that this work wasn't duplcative of work that will eventually need to be done once we decide what the CST looks like. If it's compatible, great. If there's any chance that this work "forks" in a different and non-compatible direction from the CST, and particularly if it could possibly set a precedent (legacy code) that makes it any harder for the eventual CST adoption, I would suggest you consider waiting. Sounds like you've already analyzed that, so I have no objections. :) |
If so, maybe I don't still understand your proposal completely. I think it's important that this work makes sence in the future CST architecture, and so I'd like to get your agreement since I believe this PR works in the both your and my proposals. So let's describe my understanding, if it isn't true, I'd appreciate if you would point it. This PR in your CST = AST + extras architecture
Since you noted as the above, I imagine that the
And then,
Is it correct? And in your CST architecture, this PR will be the part of the So I think this makes sence. Do you agree with this? If you don't think so, please point which is incorrect. This PR in my CST != AST architectureIn my proposal, this PR will become a part of |
Hey guys, |
The theory sounds just fine here, IMO. My soft objection earlier was I didn't think it was a good idea if it end up being that a tree "standard" assumed as a result of this PR was something like: {
"type": "BinaryExpression",
"operator": "+",
"left": {
"type": "Identifier",
"name": "a",
"comments": " ... "
},
"right": {
"type": "Identifier",
"name": "b"
}
} That tree structure could end up being incompatible with the eventual CST tree structure, so setting such a precedent now would make it harder to switch later. That's all I meant. If that kind of precedent isn't being set, then it doesn't seem like a concern to hold up this PR. |
Ah, I see! Thank you for your clarification. To clarify my understanding, I'll describe my thought. Yes, current However, in my understanding, I think it doesn't become an issue. So let's describing why I think so. if it is not correct or there's missed points, please feel free to point it :) This PR in your CST = AST + extras architectureI think this I imagine that
So once This is important: OK, so let's answer your questions. If my thought is incorrect, I'd appreciate if you would point it!
Fortunately, No :)
Is it a good answer for your concerns? If it isn't, please point it :) Let's continue to consider / reconstruct the design! This PR in my CST != AST architectureAbout this, my proposal works as the same. |
If I understand correctly, you will be adding some "non standard properties" (only so far as there is not a CST standard yet) to the AST, but since that's only internal use in your tool, it won't represent a de facto "standard tree format" that could hamper us from a future CST format. Am I correct on that? |
Oh, sorry, I failed to send my comment on GitHub...
Yes! And the important thing is that, |
ping? @getify |
No further objections from me. :) |
Thank you @getify! So I'll merge it. |
This fix prevents comments inside objects from being dropped