mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-15 04:43:37 -05:00
Address PR feedback for trailing commas
This commit is contained in:
2
Jakefile
2
Jakefile
@@ -55,7 +55,7 @@ var servicesSources = [
|
||||
"services.ts",
|
||||
"shims.ts",
|
||||
"signatureHelp.ts",
|
||||
"utilities.ts"
|
||||
"utilities.ts"
|
||||
].map(function (f) {
|
||||
return path.join(servicesDirectory, f);
|
||||
}));
|
||||
|
||||
@@ -700,23 +700,46 @@ module ts {
|
||||
}
|
||||
}
|
||||
|
||||
function emitCommaList(nodes: Node[], count?: number) {
|
||||
if (!(count >= 0)) count = nodes.length;
|
||||
if (nodes) {
|
||||
for (var i = 0; i < count; i++) {
|
||||
if (i) write(", ");
|
||||
emit(nodes[i]);
|
||||
function emitTrailingCommaIfPresent(nodeList: NodeArray<Node>, isMultiline: boolean): void {
|
||||
if (nodeList.hasTrailingComma) {
|
||||
write(",");
|
||||
if (isMultiline) {
|
||||
writeLine();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function emitMultiLineList(nodes: Node[]) {
|
||||
function emitCommaList(nodes: NodeArray<Node>, includeTrailingComma: boolean, count?: number) {
|
||||
if (!(count >= 0)) {
|
||||
count = nodes.length;
|
||||
}
|
||||
if (nodes) {
|
||||
for (var i = 0; i < count; i++) {
|
||||
if (i) {
|
||||
write(", ");
|
||||
}
|
||||
emit(nodes[i]);
|
||||
}
|
||||
|
||||
if (includeTrailingComma) {
|
||||
emitTrailingCommaIfPresent(nodes, /*isMultiline*/ false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function emitMultiLineList(nodes: NodeArray<Node>, includeTrailingComma: boolean) {
|
||||
if (nodes) {
|
||||
for (var i = 0; i < nodes.length; i++) {
|
||||
if (i) write(",");
|
||||
if (i) {
|
||||
write(",");
|
||||
}
|
||||
writeLine();
|
||||
emit(nodes[i]);
|
||||
}
|
||||
|
||||
if (includeTrailingComma) {
|
||||
emitTrailingCommaIfPresent(nodes, /*isMultiline*/ true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -824,29 +847,18 @@ module ts {
|
||||
}
|
||||
}
|
||||
|
||||
function emitTrailingCommaIfPresent(nodeList: NodeArray<Node>, isMultiline: boolean): void {
|
||||
if (nodeList.hasTrailingComma) {
|
||||
write(",");
|
||||
if (isMultiline) {
|
||||
writeLine();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function emitArrayLiteral(node: ArrayLiteral) {
|
||||
if (node.flags & NodeFlags.MultiLine) {
|
||||
write("[");
|
||||
increaseIndent();
|
||||
emitMultiLineList(node.elements);
|
||||
emitTrailingCommaIfPresent(node.elements, /*isMultiline*/ true);
|
||||
emitMultiLineList(node.elements, /*includeTrailingComma*/ true);
|
||||
decreaseIndent();
|
||||
writeLine();
|
||||
write("]");
|
||||
}
|
||||
else {
|
||||
write("[");
|
||||
emitCommaList(node.elements);
|
||||
emitTrailingCommaIfPresent(node.elements, /*isMultiline*/ false);
|
||||
emitCommaList(node.elements, /*includeTrailingComma*/ true);
|
||||
write("]");
|
||||
}
|
||||
}
|
||||
@@ -858,24 +870,14 @@ module ts {
|
||||
else if (node.flags & NodeFlags.MultiLine) {
|
||||
write("{");
|
||||
increaseIndent();
|
||||
emitMultiLineList(node.properties);
|
||||
|
||||
if (compilerOptions.target === ScriptTarget.ES5) {
|
||||
emitTrailingCommaIfPresent(node.properties, /*isMultiline*/ true);
|
||||
}
|
||||
|
||||
emitMultiLineList(node.properties, /*includeTrailingComma*/ compilerOptions.target >= ScriptTarget.ES5);
|
||||
decreaseIndent();
|
||||
writeLine();
|
||||
write("}");
|
||||
}
|
||||
else {
|
||||
write("{ ");
|
||||
emitCommaList(node.properties);
|
||||
|
||||
if (compilerOptions.target === ScriptTarget.ES5) {
|
||||
emitTrailingCommaIfPresent(node.properties, /*isMultiline*/ false);
|
||||
}
|
||||
|
||||
emitCommaList(node.properties, /*includeTrailingComma*/ compilerOptions.target >= ScriptTarget.ES5);
|
||||
write(" }");
|
||||
}
|
||||
}
|
||||
@@ -921,13 +923,13 @@ module ts {
|
||||
emitThis(node.func);
|
||||
if (node.arguments.length) {
|
||||
write(", ");
|
||||
emitCommaList(node.arguments);
|
||||
emitCommaList(node.arguments, /*includeTrailingComma*/ false);
|
||||
}
|
||||
write(")");
|
||||
}
|
||||
else {
|
||||
write("(");
|
||||
emitCommaList(node.arguments);
|
||||
emitCommaList(node.arguments, /*includeTrailingComma*/ false);
|
||||
write(")");
|
||||
}
|
||||
}
|
||||
@@ -937,7 +939,7 @@ module ts {
|
||||
emit(node.func);
|
||||
if (node.arguments) {
|
||||
write("(");
|
||||
emitCommaList(node.arguments);
|
||||
emitCommaList(node.arguments, /*includeTrailingComma*/ false);
|
||||
write(")");
|
||||
}
|
||||
}
|
||||
@@ -1110,7 +1112,7 @@ module ts {
|
||||
if (node.declarations) {
|
||||
emitToken(SyntaxKind.VarKeyword, endPos);
|
||||
write(" ");
|
||||
emitCommaList(node.declarations);
|
||||
emitCommaList(node.declarations, /*includeTrailingComma*/ false);
|
||||
}
|
||||
if (node.initializer) {
|
||||
emit(node.initializer);
|
||||
@@ -1258,7 +1260,7 @@ module ts {
|
||||
function emitVariableStatement(node: VariableStatement) {
|
||||
emitLeadingComments(node);
|
||||
if (!(node.flags & NodeFlags.Export)) write("var ");
|
||||
emitCommaList(node.declarations);
|
||||
emitCommaList(node.declarations, /*includeTrailingComma*/ false);
|
||||
write(";");
|
||||
emitTrailingComments(node);
|
||||
}
|
||||
@@ -1367,7 +1369,7 @@ module ts {
|
||||
increaseIndent();
|
||||
write("(");
|
||||
if (node) {
|
||||
emitCommaList(node.parameters, node.parameters.length - (hasRestParameters(node) ? 1 : 0));
|
||||
emitCommaList(node.parameters, /*includeTrailingComma*/ false, node.parameters.length - (hasRestParameters(node) ? 1 : 0));
|
||||
}
|
||||
write(")");
|
||||
decreaseIndent();
|
||||
|
||||
Reference in New Issue
Block a user