-
Notifications
You must be signed in to change notification settings - Fork 10
Multi and single line comments #1
Comments
why? am i missing something? |
@flying-sheep feel free to give it a try it'd be pretty awesome to get some help on it. Comment nodes differ from any other nodes (this is not obvious from reading the source) in that comments need to have a location object to be usable by the recast printer and they need to be attached to a block (this can be the block of a program or a function body). The problem with having to have a location object is that the transpiler needs to know where in relation to other nodes the comment should be positioned, currently the transpiler doesn't know or care about location. |
ok, so what i understood (or thought to understand) from your comment:
is that all right? |
Simplified but yes. In answer to 2,3,4 Generally yes, here's some more explaining: Blocks are generally nodes themselves. If you parse a bunch of javascript code with recast, recast attaches a However, we're not parsing javascript code here. We're building an AST manually (with the information we get from the coffeescript compiler). All block expressions live in |
and how do the location objects look? line/column coordinates? or node indices? or what? because if it’s the former, the AST also has to know about how exactly the code will be rendered (e.g. regarding whitespace), which really makes it all awkward. suddenly it’s all no longer semantics with attached presentation, but instead semantics tied to presentational information. (once you change semantic information, you also have to change presentational information) is this the case? |
line/column coordinates, which makes the whole thing rather difficult. |
I wonder what the reason is to treat comment nodes differently than any other nodes |
hmm, looking at recast’s printComments function, it works if we’re OK with simply adding a comment node without loc. then this will be skipped but this will be executed else we need those parts to work (flow-like type annotations) Node {
comment: Comment {
loc: Location {
lines: Lines {
skipSpaces: (start: number, backward: boolean) => number,
firstPos: () => number,
slice: (start: number, end: number) => Lines,
...
},
start: number,
end: number,
...
},
leading: boolean,
trailing: boolean,
type: "Block" | "Line",
...
},
...
} |
Hi @flying-sheep. I really appreciate the company ❤️ I don't get what you're saying here:
It works if what?
It's entirely possible that I'm missing something glaringly obvious, but how are type annotations related to this issue? |
eh, sorry, edited the second part, forgot to finish the first.
|
@flying-sheep how would that work? Where would the comment be positioned? I thought we just established that it wouldn't work and benjamin sorta confirmed it right? |
based on your explanation. but look at the code: isn’t it so that if you simply don’t have /e: yes it will, but it’s attached to the function body block, as you said (so it can be inserted before/after it) as said in benjamn/recast#159 (comment), there are methods that reattach comments. maybe we can use one to reattach comments from the body itself to the body nodes (e.g. statements in a function body)? |
hmm, maybe like that: for each comment:
|
Hmm |
@flying-sheep that sounds like a reasonable way of doing it 👍 |
The coffeescript compiler unfortunately completely ditches single line comments and currently there's no easy way to insert multiline comments into the ast (ast-types doesn't make that easy).
The text was updated successfully, but these errors were encountered: