Comments are attached to wrong nodes as inner position

未关闭
#2,004 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
4/5
预计耗时
3-5 天
新手友好度
35/100
Issue 类型
缺陷
描述清晰度
基本清楚
活跃度
停滞
领域
compilers

调研方向

使用提供的 JavaScript 和“Attach comments”选项,在 Esprima 演示解析页面中重现该问题。从该入口点跟踪注释附加过程,并验证注释没有重复,也没有附加到错误的节点,同时保留 Comment 3 作为其块的内部注释。

由索引模型根据 Issue 内容生成。

描述

Steps to reproduce:

  1. Use Esprima demo page: https://esprima.org/demo/parse.html
  2. Copy paste this code inside the editor
function a() {
   var b = 5;
   /* Comment1 */
}
/* Comment2 */
{
   /* Comment 3 */
}
  1. Check option (checkbox) "Attach comments"

Expected output:
All comments are trailing or leading with exception of the inner comment for "Comment 3"

Actual output:

{
    "type": "Program",
    "body": [
        {
            "type": "FunctionDeclaration",
            "id": {
                "type": "Identifier",
                "name": "a"
            },
            "params": [],
            "body": {
                "type": "BlockStatement",
                "body": [
                    {
                        "type": "VariableDeclaration",
                        "declarations": [
                            {
                                "type": "VariableDeclarator",
                                "id": {
                                    "type": "Identifier",
                                    "name": "b"
                                },
                                "init": {
                                    "type": "Literal",
                                    "value": 5,
                                    "raw": "5"
                                }
                            }
                        ],
                        "kind": "var",
                        "trailingComments": [
                            {
                                "type": "Block",
                                "value": " Comment1 ",
                                "range": [
                                    32,
                                    46
                                ]
                            }
                        ]
                    }
                ]
            },
            "generator": false,
            "expression": false,
            "async": false,
            "trailingComments": [
                {
                    "type": "Block",
                    "value": " Comment2 ",
                    "range": [
                        49,
                        63
                    ]
                }
            ]
        },
        {
            "type": "BlockStatement",
            "body": [],
            "innerComments": [
                {
                    "type": "Block",
                    "value": " Comment1 ",
                    "range": [
                        32,
                        46
                    ]
                },
                {
                    "type": "Block",
                    "value": " Comment2 ",
                    "range": [
                        49,
                        63
                    ]
                },
                {
                    "type": "Block",
                    "value": " Comment 3 ",
                    "range": [
                        69,
                        84
                    ]
                }
            ]
        }
    ],
    "sourceType": "script"
}
主要语言
TypeScript
星标
7.1k
派生
772
PR 合并指标
30 天内没有已合并 PR

环境准备

  • 没有 Dockerfile 或 Docker Compose 文件
  • 没有 Pull Request 模板
  • 阅读贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

jquery/esprima 的其他 Issue

查看 jquery/esprima 的全部 Issue

相似的 Issue

更多 TypeScript Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。