benjamn / benjamn/ast-types

Question: Why are Comment nodes treated differently than any other node

Open
#140 6 comments 1 reaction 0 assignees View on GitHub
Dominant language
TypeScript
Stars
1.2k
Forks
194
Avg merge
22h 43m
Merged PRs (30d)
10

Description

Hey there @benjamn, I have a question, I'll try to keep myself short.

Comment nodes are contained within the `comments` member of a `block` node, whereas most other nodes live inside the `body` member of a `block` node.

I'm working on [a project](https://github.com/juliankrispel/decaf) that uses the `ast-types` library and `recast` to turn a coffee-script AST into an es6 AST and although it's going well, [comments are a stumbling block](https://github.com/juliankrispel/decaf/issues/1) because they behave differently than any other node. As far as I'm aware the recast printer needs line/column coordinates to be able to print comments.

I'm sure there's a good reason for this. Would you mind explaining it to me?

Also, do you have an idea of how you'd go about solving this problem?

Contributor guide

No contributing guide indexed for this repository

Research direction

Start by tracing how block nodes expose comments through `comments` versus other nodes through `body`, then inspect how the recast printer uses line and column coordinates. Compare this behavior with the CoffeeScript-to-ES6 conversion described in decaf and its linked comments issue. Done would require an agreed explanation and a concrete direction for handling comments.

Written by the indexing model from the issue text.

Assessment

Tech stack
coffeescript, javascript, typescript
Domain
compilers, tooling
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
20/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.