Adds CommaList to avoid large deeply nested comma expressions

This commit is contained in:
Ron Buckton
2017-05-11 23:51:20 -07:00
parent a12ec1af43
commit f45f7579fc
6 changed files with 43 additions and 1 deletions

View File

@@ -733,6 +733,9 @@ namespace ts {
// Transformation nodes
case SyntaxKind.PartiallyEmittedExpression:
return emitPartiallyEmittedExpression(<PartiallyEmittedExpression>node);
case SyntaxKind.CommaList:
return emitCommaList(<CommaList>node);
}
}
@@ -2101,6 +2104,10 @@ namespace ts {
emitExpression(node.expression);
}
function emitCommaList(node: CommaList) {
emitExpressionList(node, node.elements, ListFormat.CommaListElements);
}
/**
* Emits any prologue directives at the start of a Statement list, returning the
* number of prologue directives written to the output.
@@ -2951,6 +2958,7 @@ namespace ts {
ArrayBindingPatternElements = SingleLine | AllowTrailingComma | CommaDelimited | SpaceBetweenSiblings,
ObjectLiteralExpressionProperties = PreserveLines | CommaDelimited | SpaceBetweenSiblings | SpaceBetweenBraces | Indented | Braces,
ArrayLiteralExpressionElements = PreserveLines | CommaDelimited | SpaceBetweenSiblings | AllowTrailingComma | Indented | SquareBrackets,
CommaListElements = CommaDelimited | SpaceBetweenSiblings | SingleLine,
CallExpressionArguments = CommaDelimited | SpaceBetweenSiblings | SingleLine | Parenthesis,
NewExpressionArguments = CommaDelimited | SpaceBetweenSiblings | SingleLine | Parenthesis | OptionalIfUndefined,
TemplateExpressionSpans = SingleLine | NoInterveningComments,

View File

@@ -2077,6 +2077,18 @@ namespace ts {
return node;
}
export function createCommaList(elements: Expression[]) {
const node = <CommaList>createSynthesizedNode(SyntaxKind.CommaList);
node.elements = createNodeArray(elements);
return node;
}
export function updateCommaList(node: CommaList, elements: Expression[]) {
return node.elements !== elements
? updateNode(createCommaList(elements), node)
: node;
}
export function createBundle(sourceFiles: SourceFile[]) {
const node = <Bundle>createNode(SyntaxKind.Bundle);
node.sourceFiles = sourceFiles;
@@ -2865,7 +2877,9 @@ namespace ts {
}
export function inlineExpressions(expressions: Expression[]) {
return reduceLeft(expressions, createComma);
return expressions.length > 10
? createCommaList(expressions)
: reduceLeft(expressions, createComma);
}
export function createExpressionFromEntityName(node: EntityName | Expression): Expression {

View File

@@ -362,6 +362,8 @@ namespace ts {
return visitNode(cbNode, (<ExternalModuleReference>node).expression);
case SyntaxKind.MissingDeclaration:
return visitNodes(cbNodes, node.decorators);
case SyntaxKind.CommaList:
return visitNodes(cbNodes, (<CommaList>node).elements);
case SyntaxKind.JsxElement:
return visitNode(cbNode, (<JsxElement>node).openingElement) ||

View File

@@ -391,6 +391,7 @@ namespace ts {
PartiallyEmittedExpression,
MergeDeclarationMarker,
EndOfDeclarationMarker,
CommaList,
// Enum value count
Count,
@@ -1603,6 +1604,11 @@ namespace ts {
kind: SyntaxKind.EndOfDeclarationMarker;
}
export interface CommaList extends Expression {
kind: SyntaxKind.CommaList;
elements: NodeArray<Expression>;
}
/**
* Marks the beginning of a merged transformed declaration.
*/

View File

@@ -2327,6 +2327,9 @@ namespace ts {
case SyntaxKind.SpreadElement:
return 1;
case SyntaxKind.CommaList:
return 0;
default:
return -1;
}
@@ -3915,6 +3918,7 @@ namespace ts {
|| kind === SyntaxKind.SpreadElement
|| kind === SyntaxKind.AsExpression
|| kind === SyntaxKind.OmittedExpression
|| kind === SyntaxKind.CommaList
|| isUnaryExpressionKind(kind);
}

View File

@@ -876,6 +876,10 @@ namespace ts {
return updatePartiallyEmittedExpression(<PartiallyEmittedExpression>node,
visitNode((<PartiallyEmittedExpression>node).expression, visitor, isExpression));
case SyntaxKind.CommaList:
return updateCommaList(<CommaList>node,
nodesVisitor((<CommaList>node).elements, visitor, isExpression));
default:
// No need to visit nodes with no children.
return node;
@@ -1389,6 +1393,10 @@ namespace ts {
result = reduceNode((<PartiallyEmittedExpression>node).expression, cbNode, result);
break;
case SyntaxKind.CommaList:
result = reduceNodes((<CommaList>node).elements, cbNodes, result);
break;
default:
break;
}