Fixes indentation of object literals with computed properties

This commit is contained in:
Ron Buckton
2016-04-05 18:24:02 -07:00
parent e3e45c5354
commit 8988ea849b
9 changed files with 41 additions and 6 deletions

View File

@@ -964,9 +964,18 @@ const _super = (function (geti, seti) {
write("{}");
}
else {
const indentedFlag = getNodeEmitFlags(node) & NodeEmitFlags.Indented;
if (indentedFlag) {
increaseIndent();
}
const preferNewLine = node.multiLine ? ListFormat.PreferNewLine : ListFormat.None;
const allowTrailingComma = languageVersion >= ScriptTarget.ES5 ? ListFormat.AllowTrailingComma : ListFormat.None;
emitList(node, properties, ListFormat.ObjectLiteralExpressionProperties | allowTrailingComma | preferNewLine);
if (indentedFlag) {
decreaseIndent();
}
}
}

View File

@@ -1688,10 +1688,13 @@ namespace ts {
addNode(expressions,
createAssignment(
temp,
createObjectLiteral(
visitNodes(properties, visitor, isObjectLiteralElement, 0, numInitialNonComputedProperties),
/*location*/ undefined,
node.multiLine
setNodeEmitFlags(
createObjectLiteral(
visitNodes(properties, visitor, isObjectLiteralElement, 0, numInitialNonComputedProperties),
/*location*/ undefined,
node.multiLine
),
NodeEmitFlags.Indented
)
),
node.multiLine

View File

@@ -1637,6 +1637,9 @@ namespace ts {
const rightHandSideName = (<PropertyAccessExpression>nameExpression).name.text;
return getPropertyNameForKnownSymbolName(rightHandSideName);
}
if (isStringOrNumericLiteral(nameExpression.kind)) {
return (<LiteralExpression>nameExpression).text;
}
}
return undefined;