Skip to content

Commit 2df6436

Browse files
authored
fix(2325): Extra parentheses added when type assertion is used in arrow function with object literal (#2345)
1 parent cac2644 commit 2df6436

File tree

41 files changed

+82
-264
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+82
-264
lines changed

internal/printer/printer.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2919,7 +2919,7 @@ func (p *Printer) emitMetaProperty(node *ast.MetaProperty) {
29192919
p.exitNode(node.AsNode(), state)
29202920
}
29212921

2922-
func (p *Printer) emitPartiallyEmittedExpression(node *ast.PartiallyEmittedExpression, precedence ast.OperatorPrecedence) {
2922+
func (p *Printer) emitPartiallyEmittedExpression(node *ast.PartiallyEmittedExpression) {
29232923
// avoid reprinting parens for nested partially emitted expressions
29242924
type entry struct {
29252925
node *ast.PartiallyEmittedExpression
@@ -2935,7 +2935,7 @@ func (p *Printer) emitPartiallyEmittedExpression(node *ast.PartiallyEmittedExpre
29352935
node = node.Expression.AsPartiallyEmittedExpression()
29362936
}
29372937

2938-
p.emitExpression(node.Expression, precedence)
2938+
p.emitExpression(node.Expression, ast.OperatorPrecedenceLowest)
29392939

29402940
// unwind stack
29412941
for stack.Len() > 0 {
@@ -3081,7 +3081,7 @@ func (p *Printer) emitExpression(node *ast.Expression, precedence ast.OperatorPr
30813081
case ast.KindNotEmittedStatement:
30823082
return
30833083
case ast.KindPartiallyEmittedExpression:
3084-
p.emitPartiallyEmittedExpression(node.AsPartiallyEmittedExpression(), precedence)
3084+
p.emitPartiallyEmittedExpression(node.AsPartiallyEmittedExpression())
30853085
case ast.KindSyntheticReferenceExpression:
30863086
panic("SyntheticReferenceExpression should not be printed")
30873087

testdata/baselines/reference/submodule/compiler/arrowFunctionWithObjectLiteralBody1.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@
44
var v = a => <any>{}
55

66
//// [arrowFunctionWithObjectLiteralBody1.js]
7-
var v = a => (({}));
7+
var v = a => ({});

testdata/baselines/reference/submodule/compiler/arrowFunctionWithObjectLiteralBody1.js.diff

Lines changed: 0 additions & 8 deletions
This file was deleted.

testdata/baselines/reference/submodule/compiler/arrowFunctionWithObjectLiteralBody2.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@
44
var v = a => <any><any>{}
55

66
//// [arrowFunctionWithObjectLiteralBody2.js]
7-
var v = a => (({}));
7+
var v = a => ({});

testdata/baselines/reference/submodule/compiler/arrowFunctionWithObjectLiteralBody2.js.diff

Lines changed: 0 additions & 8 deletions
This file was deleted.

testdata/baselines/reference/submodule/compiler/arrowFunctionWithObjectLiteralBody3.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@
44
var v = a => <any>{}
55

66
//// [arrowFunctionWithObjectLiteralBody3.js]
7-
var v = a => (({}));
7+
var v = a => ({});

testdata/baselines/reference/submodule/compiler/arrowFunctionWithObjectLiteralBody3.js.diff

Lines changed: 0 additions & 8 deletions
This file was deleted.

testdata/baselines/reference/submodule/compiler/arrowFunctionWithObjectLiteralBody4.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@
44
var v = a => <any><any>{}
55

66
//// [arrowFunctionWithObjectLiteralBody4.js]
7-
var v = a => (({}));
7+
var v = a => ({});

testdata/baselines/reference/submodule/compiler/arrowFunctionWithObjectLiteralBody4.js.diff

Lines changed: 0 additions & 8 deletions
This file was deleted.

testdata/baselines/reference/submodule/compiler/arrowFunctionWithObjectLiteralBody5.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ var c = () => ({ name: "foo", message: "bar" });
1010
var d = () => ((<Error>({ name: "foo", message: "bar" })));
1111

1212
//// [arrowFunctionWithObjectLiteralBody5.js]
13-
var a = () => (({ name: "foo", message: "bar" }));
14-
var b = () => (({ name: "foo", message: "bar" }));
13+
var a = () => ({ name: "foo", message: "bar" });
14+
var b = () => ({ name: "foo", message: "bar" });
1515
var c = () => ({ name: "foo", message: "bar" });
1616
var d = () => ({ name: "foo", message: "bar" });

0 commit comments

Comments
 (0)