jquery / jquery/esprima

Include Comment Style in LineComment and BlockComment Nodes

Open
#2,003 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
TypeScript
Stars
7.1k
Forks
772
PR merge metrics
No merged PRs in 30d

Description

Multiple different Javascript snippets can result in a LineComment node:

// type1
<!-- type2
--> type3

From current Esprima's output there's no way to know which one of these 'styles' was used as a comment.

Since this is specific to LineComment nodes, it's possible to split the type of node from 'LineComment' into 3 node types (one for each style). But I assume that would completely break the API. I offer the solution of adding 'style' attribute to Comment nodes (both Block and Line). The values can be: ['//', '', '/*'].

I believe this API change is relatively minor since we're only adding an attribute without replacing any existing ones. We will have to change the Comment section in the Esprima API documentation. There shouldn't be any performance degradation since the comment style is known while parsing, it just wasn't exposed to the AST.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the linked Comment section in the Esprima API documentation and trace how LineComment and BlockComment nodes are represented by the parser. Confirm the proposed style values and update the documentation and relevant AST behavior so comment nodes expose the style without removing existing attributes.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, typescript
Domain
compilers, documentation
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.