Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Comment(s) in parenthesis statement being removed #426

Open
lucivpav opened this issue Oct 7, 2020 · 3 comments
Open

Comment(s) in parenthesis statement being removed #426

lucivpav opened this issue Oct 7, 2020 · 3 comments

Comments

@lucivpav
Copy link

lucivpav commented Oct 7, 2020

Problem with escodegen.attachComments (and maybe also with esprima.parse). See https://github.com/estools/escodegen/blob/master/test/comment.js or #427 PR for reproduction.

Input:

function foo(a, b, c) {
    return (
        (a >= b && a <= c)

        // lorem
        // ipsum
        || a === 42 || a === 666
    );
}

Output:

function foo(a, b, c) {
    return a >= b && a <= c || a === 42 || a === 666;
}

Suggested output:

function foo(a, b, c) {
    // lorem
    // ipsum
    return a >= b && a <= c || a === 42 || a === 666;
}
@Meir017
Copy link

Meir017 commented Oct 13, 2020

the more problematic scenario is when having an arrow function returning an object expression
in this scenario the generated code is actually invalid

() => (
// comment
{
  a: 1, b: 2
})

output:

() => // comment
{
    a: 1,
    b: 2
});

suggested output:

() => ( // comment
{
    a: 1,
    b: 2
)});

@lucivpav
Copy link
Author

@Meir017 looks like this belongs to the related issue #365. Nice catch!

@lucivpav lucivpav mentioned this issue Oct 13, 2020
@Itazulay
Copy link

@lucivpav we also need to support this syntax:
var a = b => ({}.hasOwnProperty.call(b, "c")); which actually translates to a CallExpression

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants