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

Reproduce issue #426 #427

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft

Reproduce issue #426 #427

wants to merge 1 commit into from

Conversation

lucivpav
Copy link

@lucivpav lucivpav commented Oct 7, 2020

Reproduces #426

@Meir017
Copy link

Meir017 commented Oct 12, 2020

@lucivpav I just ran into this issue too.
I found a solution for this -

escodegen/escodegen.js

Lines 946 to 949 in ab53cd5

expr = this.generateExpression(node.body, Precedence.Assignment, E_TTT);
if (expr.toString().charAt(0) === '{') {
expr = ['(', expr, ')'];
}

this should be

var strExpr = expr.toString();
if (strExpr[0] === '{' || strExpr[strExpr.length - 1] === '}') {
  expr = ['(', expr, ')'];
}

I'm pretty sure the last character cannot be part of the comment, in that case the comment would not be part of the node

@lucivpav
Copy link
Author

I wonder if this fix works for the affected parenthesized expressions in general, or just in function bodies 🤔

@Meir017
Copy link

Meir017 commented Oct 14, 2020

@lucivpav a better solution is to check the node types:

if (node.type === Syntax.ArrowFunctionExpression && node.body.type === Syntax.ObjectExpression) {
  expr = ['(', expr, ')'];
}

@Itazulay
Copy link

@lucivpav This PR does not cover this scenario:
var a = b => ({}.hasOwnProperty.call(b, "c"));
This is a CallExpression and not an ObjectExpression.
Maybe it should be simply:
if (node.type === Syntax.ArrowFunctionExpression) { expr = ['(', expr, ')']; }

@lucivpav
Copy link
Author

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

Successfully merging this pull request may close these issues.

3 participants