Skip to content

Commit dad5177

Browse files
authored
Limit trailing comma preservation (microsoft#457)
1 parent c53bc89 commit dad5177

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

internal/printer/printer.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1294,7 +1294,7 @@ func (p *Printer) emitTypeParameters(parentNode *ast.Node, nodes *ast.TypeParame
12941294
return
12951295
}
12961296

1297-
p.emitList((*Printer).emitTypeParameterNode, parentNode, nodes, LFTypeParameters|core.IfElse(p.shouldAllowTrailingComma(parentNode, nodes), LFAllowTrailingComma, LFNone))
1297+
p.emitList((*Printer).emitTypeParameterNode, parentNode, nodes, LFTypeParameters|core.IfElse(ast.IsArrowFunction(parentNode) /*p.shouldAllowTrailingComma(parentNode, nodes)*/, LFAllowTrailingComma, LFNone)) // TODO: preserve trailing comma after Strada migration
12981298
}
12991299

13001300
func (p *Printer) emitTypeAnnotation(node *ast.TypeNode) {
@@ -1320,7 +1320,7 @@ func (p *Printer) emitInitializer(node *ast.Expression, equalTokenPos int, conte
13201320

13211321
func (p *Printer) emitParameters(parentNode *ast.Node, parameters *ast.ParameterList) {
13221322
p.generateAllNames(parameters)
1323-
p.emitList((*Printer).emitParameterNode, parentNode, parameters, LFParameters|core.IfElse(p.shouldAllowTrailingComma(parentNode, parameters), LFAllowTrailingComma, LFNone))
1323+
p.emitList((*Printer).emitParameterNode, parentNode, parameters, LFParameters /*|core.IfElse(p.shouldAllowTrailingComma(parentNode, parameters), LFAllowTrailingComma, LFNone)*/) // TODO: preserve trailing comma after Strada migration
13241324
}
13251325

13261326
func canEmitSimpleArrowHead(parentNode *ast.Node, parameters *ast.ParameterList) bool {
@@ -1656,7 +1656,7 @@ func (p *Printer) emitTypeArguments(parentNode *ast.Node, nodes *ast.TypeArgumen
16561656
if nodes == nil {
16571657
return
16581658
}
1659-
p.emitList((*Printer).emitTypeArgument, parentNode, nodes, LFTypeArguments|core.IfElse(p.shouldAllowTrailingComma(parentNode, nodes), LFAllowTrailingComma, LFNone) /*, typeArgumentParenthesizerRuleSelector */)
1659+
p.emitList((*Printer).emitTypeArgument, parentNode, nodes, LFTypeArguments /*|core.IfElse(p.shouldAllowTrailingComma(parentNode, nodes), LFAllowTrailingComma, LFNone)*/) // TODO: preserve trailing comma after Strada migration
16601660
}
16611661

16621662
func (p *Printer) emitTypeReference(node *ast.TypeReferenceNode) {

internal/printer/printer_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ func TestEmit(t *testing.T) {
5858
{title: "CallExpression#9", input: `a?.(b).c`, output: `a?.(b).c;`},
5959
{title: "CallExpression#10", input: `a?.<T>(b).c`, output: `a?.<T>(b).c;`},
6060
{title: "CallExpression#11", input: `a<T, U>()`, output: `a<T, U>();`},
61-
{title: "CallExpression#12", input: `a<T,>()`, output: `a<T,>();`},
61+
// {title: "CallExpression#12", input: `a<T,>()`, output: `a<T,>();`}, // TODO: preserve trailing comma after Strada migration
6262
{title: "CallExpression#13", input: `a?.b()`, output: `a?.b();`},
6363
{title: "NewExpression#1", input: `new a`, output: `new a;`},
6464
{title: "NewExpression#2", input: `new a.b`, output: `new a.b;`},
@@ -507,7 +507,7 @@ func TestEmit(t *testing.T) {
507507
{title: "ParameterDeclaration#4", input: "function f(a?)", output: "function f(a?);"},
508508
{title: "ParameterDeclaration#5", input: "function f(...a)", output: "function f(...a);"},
509509
{title: "ParameterDeclaration#6", input: "function f(this)", output: "function f(this);"},
510-
{title: "ParameterDeclaration#7", input: "function f(a,)", output: "function f(a,);"},
510+
// {title: "ParameterDeclaration#7", input: "function f(a,)", output: "function f(a,);"}, // TODO: preserve trailing comma after Strada migration
511511
{title: "ObjectBindingPattern#1", input: "function f({})", output: "function f({});"},
512512
{title: "ObjectBindingPattern#2", input: "function f({a})", output: "function f({ a });"},
513513
{title: "ObjectBindingPattern#3", input: "function f({a = b})", output: "function f({ a = b });"},
@@ -535,7 +535,7 @@ func TestEmit(t *testing.T) {
535535
{title: "TypeParameterDeclaration#4", input: "function f<T = U>();", output: "function f<T = U>();"},
536536
{title: "TypeParameterDeclaration#5", input: "function f<T extends U = V>();", output: "function f<T extends U = V>();"},
537537
{title: "TypeParameterDeclaration#6", input: "function f<T, U>();", output: "function f<T, U>();"},
538-
{title: "TypeParameterDeclaration#7", input: "function f<T,>();", output: "function f<T,>();"},
538+
// {title: "TypeParameterDeclaration#7", input: "function f<T,>();", output: "function f<T,>();"}, // TODO: preserve trailing comma after Strada migration
539539
{title: "JsxElement1", input: "<a></a>", output: "<a></a>;", jsx: true},
540540
{title: "JsxElement2", input: "<this></this>", output: "<this></this>;", jsx: true},
541541
{title: "JsxElement3", input: "<a:b></a:b>", output: "<a:b></a:b>;", jsx: true},

0 commit comments

Comments
 (0)