Skip to content

Incorrectly attributed trailingComments for CallExpression #8483

@jiaxuan

Description

@jiaxuan

Bug Report

Current Behavior

Given the current code block:

test(function() {
                var a = 1;
                // one
        }
        // two
);

The first line of comment is incorrectly attributed to the trailingComments of the anonymous function:

{
    "type": "File",
    "program": {
        "body": [
            {
               "type": "ExpressionStatement",
                "expression": {
                    "type": "CallExpression",
                    "arguments": [
                        {
                            "type": "FunctionExpression",
                            "body": {
                                "type": "BlockStatement",
                            },
                            "trailingComments": [
                                {
                                    "type": "CommentLine",
                                    "value": " two",
                                    "start": 34,
                                    "end": 40,
                                    "loc": {
                                        "start": {
                                            "line": 4,
                                            "column": 2
                                        },
                                        "end": {
                                            "line": 4,
                                            "column": 8
                                        }
                                    }
                                },
                                {
                                    "type": "CommentLine",
                                    "value": " three",
                                    "start": 46,
                                    "end": 54,
                                    "loc": {
                                        "start": {
                                            "line": 6,
                                            "column": 1
                                        },
                                        "end": {
                                            "line": 6,
                                            "column": 9
                                        }
                                    }
                                }
                            ]

Expected behavior/code
trailingComments for the anonymous function should only contain the second comment line.

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: commentsoutdatedA closed issue/PR that is archived due to age. Recommended to make a new issuepkg: parser

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions