escodegen icon indicating copy to clipboard operation
escodegen copied to clipboard

Duplicated comments in output from Esprima

Open mduvall opened this issue 12 years ago • 11 comments

When given the Esprima output from program:

var obj =
{
    // Pre-a comment
    a: function()
    {
        var foo = 1; // hello
    }
    ,b: function()
    {

    }
};

// comment above
function bar()
{
    // comment below
    var i = 1;

}

/**
 * This is some documentation for this function
 */
function foo()
{

}

(available here)

escodegen.generate will produce the program:

var obj = {
        a: function () {
            var foo = 1;    // hello
        },
        b: function () {
        }
    };    // comment above
// comment above
function bar() {
    // comment below
    var i = 1;
}    /**
 * This is some documentation for this function
 */
/**
 * This is some documentation for this function
 */
function foo() {
}

The comments seem duplicated - is this the expected behavior for the output from Esprima? I saw that @Constellation did the work in Esprima for attachComments so wondering if this was an intentional duplication in the Esprima AST output.

mduvall avatar Dec 18 '13 08:12 mduvall

+1

https://github.com/ecomfe/edp/issues/273

leeight avatar Jun 27 '14 02:06 leeight

Right. I'll investigate it.

Constellation avatar Jun 30 '14 06:06 Constellation

Could you show me how to create this AST? It seems that AST already has duplicated comments. https://gist.github.com/mduvall/8018844 In this case, this output is expected.

Constellation avatar Jun 30 '14 06:06 Constellation

Me too

finscn avatar Sep 23 '14 19:09 finscn

Having this issue as well.

RReverser avatar Nov 22 '14 09:11 RReverser

I'm also being affected by this. Is this a bug on escodegen or esprima? Is a PR welcome?

magalhas avatar May 06 '15 14:05 magalhas

I have the same issue.

donaldpipowitch avatar Jun 22 '15 10:06 donaldpipowitch

Any word on this @Constellation ? I still see this issue today. The AST is created from a file that has single copies of each comment, but some of these comments are attached to both the trailing comments of a node and the leading comments of the following node, causing escodegen to output duplicates.

casey-speer avatar Nov 10 '15 22:11 casey-speer

I think this is an issue to Esprima because the parsed AST contains duplicate comments.

/cc @ariya @michaelficarra What do you think of?

Constellation avatar Nov 11 '15 11:11 Constellation

Ah, @Constellation sorry that's likely the case. Esprima should consider a comment as leading or trailing, but not both. It looks like a bug there because this doesn't happen for all comments that could be interpreted as leading or trailing.

casey-speer avatar Nov 11 '15 17:11 casey-speer

+1 Any news about this issue?

ogorbacheva avatar Feb 12 '18 17:02 ogorbacheva