Skip to content

Commit f45f757

Browse files
committed
Adds CommaList to avoid large deeply nested comma expressions
1 parent a12ec1a commit f45f757

File tree

6 files changed

+43
-1
lines changed

6 files changed

+43
-1
lines changed

src/compiler/emitter.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -733,6 +733,9 @@ namespace ts {
733733
// Transformation nodes
734734
case SyntaxKind.PartiallyEmittedExpression:
735735
return emitPartiallyEmittedExpression(<PartiallyEmittedExpression>node);
736+
737+
case SyntaxKind.CommaList:
738+
return emitCommaList(<CommaList>node);
736739
}
737740
}
738741

@@ -2101,6 +2104,10 @@ namespace ts {
21012104
emitExpression(node.expression);
21022105
}
21032106

2107+
function emitCommaList(node: CommaList) {
2108+
emitExpressionList(node, node.elements, ListFormat.CommaListElements);
2109+
}
2110+
21042111
/**
21052112
* Emits any prologue directives at the start of a Statement list, returning the
21062113
* number of prologue directives written to the output.
@@ -2951,6 +2958,7 @@ namespace ts {
29512958
ArrayBindingPatternElements = SingleLine | AllowTrailingComma | CommaDelimited | SpaceBetweenSiblings,
29522959
ObjectLiteralExpressionProperties = PreserveLines | CommaDelimited | SpaceBetweenSiblings | SpaceBetweenBraces | Indented | Braces,
29532960
ArrayLiteralExpressionElements = PreserveLines | CommaDelimited | SpaceBetweenSiblings | AllowTrailingComma | Indented | SquareBrackets,
2961+
CommaListElements = CommaDelimited | SpaceBetweenSiblings | SingleLine,
29542962
CallExpressionArguments = CommaDelimited | SpaceBetweenSiblings | SingleLine | Parenthesis,
29552963
NewExpressionArguments = CommaDelimited | SpaceBetweenSiblings | SingleLine | Parenthesis | OptionalIfUndefined,
29562964
TemplateExpressionSpans = SingleLine | NoInterveningComments,

src/compiler/factory.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2077,6 +2077,18 @@ namespace ts {
20772077
return node;
20782078
}
20792079

2080+
export function createCommaList(elements: Expression[]) {
2081+
const node = <CommaList>createSynthesizedNode(SyntaxKind.CommaList);
2082+
node.elements = createNodeArray(elements);
2083+
return node;
2084+
}
2085+
2086+
export function updateCommaList(node: CommaList, elements: Expression[]) {
2087+
return node.elements !== elements
2088+
? updateNode(createCommaList(elements), node)
2089+
: node;
2090+
}
2091+
20802092
export function createBundle(sourceFiles: SourceFile[]) {
20812093
const node = <Bundle>createNode(SyntaxKind.Bundle);
20822094
node.sourceFiles = sourceFiles;
@@ -2865,7 +2877,9 @@ namespace ts {
28652877
}
28662878

28672879
export function inlineExpressions(expressions: Expression[]) {
2868-
return reduceLeft(expressions, createComma);
2880+
return expressions.length > 10
2881+
? createCommaList(expressions)
2882+
: reduceLeft(expressions, createComma);
28692883
}
28702884

28712885
export function createExpressionFromEntityName(node: EntityName | Expression): Expression {

src/compiler/parser.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,8 @@ namespace ts {
362362
return visitNode(cbNode, (<ExternalModuleReference>node).expression);
363363
case SyntaxKind.MissingDeclaration:
364364
return visitNodes(cbNodes, node.decorators);
365+
case SyntaxKind.CommaList:
366+
return visitNodes(cbNodes, (<CommaList>node).elements);
365367

366368
case SyntaxKind.JsxElement:
367369
return visitNode(cbNode, (<JsxElement>node).openingElement) ||

src/compiler/types.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -391,6 +391,7 @@ namespace ts {
391391
PartiallyEmittedExpression,
392392
MergeDeclarationMarker,
393393
EndOfDeclarationMarker,
394+
CommaList,
394395

395396
// Enum value count
396397
Count,
@@ -1603,6 +1604,11 @@ namespace ts {
16031604
kind: SyntaxKind.EndOfDeclarationMarker;
16041605
}
16051606

1607+
export interface CommaList extends Expression {
1608+
kind: SyntaxKind.CommaList;
1609+
elements: NodeArray<Expression>;
1610+
}
1611+
16061612
/**
16071613
* Marks the beginning of a merged transformed declaration.
16081614
*/

src/compiler/utilities.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2327,6 +2327,9 @@ namespace ts {
23272327
case SyntaxKind.SpreadElement:
23282328
return 1;
23292329

2330+
case SyntaxKind.CommaList:
2331+
return 0;
2332+
23302333
default:
23312334
return -1;
23322335
}
@@ -3915,6 +3918,7 @@ namespace ts {
39153918
|| kind === SyntaxKind.SpreadElement
39163919
|| kind === SyntaxKind.AsExpression
39173920
|| kind === SyntaxKind.OmittedExpression
3921+
|| kind === SyntaxKind.CommaList
39183922
|| isUnaryExpressionKind(kind);
39193923
}
39203924

src/compiler/visitor.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -876,6 +876,10 @@ namespace ts {
876876
return updatePartiallyEmittedExpression(<PartiallyEmittedExpression>node,
877877
visitNode((<PartiallyEmittedExpression>node).expression, visitor, isExpression));
878878

879+
case SyntaxKind.CommaList:
880+
return updateCommaList(<CommaList>node,
881+
nodesVisitor((<CommaList>node).elements, visitor, isExpression));
882+
879883
default:
880884
// No need to visit nodes with no children.
881885
return node;
@@ -1389,6 +1393,10 @@ namespace ts {
13891393
result = reduceNode((<PartiallyEmittedExpression>node).expression, cbNode, result);
13901394
break;
13911395

1396+
case SyntaxKind.CommaList:
1397+
result = reduceNodes((<CommaList>node).elements, cbNodes, result);
1398+
break;
1399+
13921400
default:
13931401
break;
13941402
}

0 commit comments

Comments
 (0)