Made the initial object literal properties indented.

This commit is contained in:
Daniel Rosenwasser
2015-02-19 13:11:59 -08:00
parent a6c5505881
commit ce85b14589
15 changed files with 569 additions and 22 deletions
+27 -16
View File
@@ -2065,9 +2065,6 @@ module ts {
}
function emitList(nodes: Node[], start: number, count: number, multiLine: boolean, trailingComma: boolean) {
if (multiLine) {
increaseIndent();
}
for (var i = 0; i < count; i++) {
if (multiLine) {
if (i) {
@@ -2086,7 +2083,6 @@ module ts {
write(",");
}
if (multiLine) {
decreaseIndent();
writeLine();
}
}
@@ -2097,12 +2093,6 @@ module ts {
}
}
function emitMultiLineList(nodes: Node[]) {
if (nodes) {
emitList(nodes, 0, nodes.length, /*multiline*/ true, /*trailingComma*/ false);
}
}
function emitLines(nodes: Node[]) {
emitLinesStartingAt(nodes, /*startIndex*/ 0);
}
@@ -2457,7 +2447,13 @@ module ts {
i++;
}
write("[");
if (multiLine) {
increaseIndent();
}
emitList(elements, pos, i - pos, multiLine, trailingComma && i === length);
if (multiLine) {
decreaseIndent();
}
write("]");
pos = i;
}
@@ -2475,8 +2471,15 @@ module ts {
}
else if (languageVersion >= ScriptTarget.ES6) {
write("[");
emitList(elements, 0, elements.length, /*multiLine*/ (node.flags & NodeFlags.MultiLine) !== 0,
var multiLine = (node.flags & NodeFlags.MultiLine) !== 0;
if (multiLine) {
increaseIndent();
}
emitList(elements, 0, elements.length, /*multiLine*/ multiLine,
/*trailingComma*/ elements.hasTrailingComma);
if (multiLine) {
decreaseIndent();
}
write("]");
}
else {
@@ -2488,17 +2491,24 @@ module ts {
function emitObjectLiteralBody(node: ObjectLiteralExpression, numElements: number) {
write("{");
var multiLine = (node.flags & NodeFlags.MultiLine) !== 0;
if (numElements > 0) {
var properties = node.properties;
var multiLine = (node.flags & NodeFlags.MultiLine) !== 0;
if (!multiLine) {
write(" ");
}
else {
increaseIndent();
}
emitList(properties, 0, numElements, /*multiLine*/ multiLine,
/*trailingComma*/ properties.hasTrailingComma && languageVersion >= ScriptTarget.ES5);
if (!multiLine) {
write(" ");
}
else {
decreaseIndent();
}
}
write("}");
@@ -2510,6 +2520,10 @@ module ts {
write("(");
if (multiLine) {
increaseIndent();
}
// For computed properties, we need to create a unique handle to the object
// literal so we can modify it without risking internal assignments tainting the object.
var tempVar = createAndRecordTempVariable(node);
@@ -2521,9 +2535,6 @@ module ts {
write(" = ");
emitObjectLiteralBody(node, firstComputedPropertyIndex);
if (multiLine) {
increaseIndent();
}
for (var i = firstComputedPropertyIndex, n = properties.length; i < n; i++) {
writeComma();
@@ -2624,10 +2635,10 @@ module ts {
var properties = node.properties;
if (languageVersion < ScriptTarget.ES6) {
var numProperties = properties.length;
// Find the first computed property.
// Everything until that point can be emitted as part of the initial object literal.
var numProperties = properties.length;
var numInitialNonComputedProperties = numProperties;
for (var i = 0, n = properties.length; i < n; i++) {
if (properties[i].name.kind === SyntaxKind.ComputedPropertyName) {
@@ -0,0 +1,52 @@
tests/cases/conformance/es6/computedProperties/computedPropertyNames49_ES5.ts(4,9): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher.
tests/cases/conformance/es6/computedProperties/computedPropertyNames49_ES5.ts(7,9): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher.
tests/cases/conformance/es6/computedProperties/computedPropertyNames49_ES5.ts(10,9): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher.
tests/cases/conformance/es6/computedProperties/computedPropertyNames49_ES5.ts(14,9): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher.
tests/cases/conformance/es6/computedProperties/computedPropertyNames49_ES5.ts(14,9): error TS2300: Duplicate identifier 'foo'.
tests/cases/conformance/es6/computedProperties/computedPropertyNames49_ES5.ts(19,9): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher.
tests/cases/conformance/es6/computedProperties/computedPropertyNames49_ES5.ts(19,9): error TS1118: An object literal cannot have multiple get/set accessors with the same name.
tests/cases/conformance/es6/computedProperties/computedPropertyNames49_ES5.ts(19,9): error TS2300: Duplicate identifier 'foo'.
==== tests/cases/conformance/es6/computedProperties/computedPropertyNames49_ES5.ts (8 errors) ====
var x = {
p1: 10,
get [1 + 1]() {
~~~~~~~
!!! error TS1056: Accessors are only available when targeting ECMAScript 5 and higher.
throw 10;
},
get [1 + 1]() {
~~~~~~~
!!! error TS1056: Accessors are only available when targeting ECMAScript 5 and higher.
return 10;
},
set [1 + 1]() {
~~~~~~~
!!! error TS1056: Accessors are only available when targeting ECMAScript 5 and higher.
// just throw
throw 10;
},
get foo() {
~~~
!!! error TS1056: Accessors are only available when targeting ECMAScript 5 and higher.
~~~
!!! error TS2300: Duplicate identifier 'foo'.
if (1 == 1) {
return 10;
}
},
get foo() {
~~~
!!! error TS1056: Accessors are only available when targeting ECMAScript 5 and higher.
~~~
!!! error TS1118: An object literal cannot have multiple get/set accessors with the same name.
~~~
!!! error TS2300: Duplicate identifier 'foo'.
if (2 == 2) {
return 20;
}
},
p2: 20
}
@@ -0,0 +1,75 @@
//// [computedPropertyNames49_ES5.ts]
var x = {
p1: 10,
get [1 + 1]() {
throw 10;
},
get [1 + 1]() {
return 10;
},
set [1 + 1]() {
// just throw
throw 10;
},
get foo() {
if (1 == 1) {
return 10;
}
},
get foo() {
if (2 == 2) {
return 20;
}
},
p2: 20
}
//// [computedPropertyNames49_ES5.js]
var x = (_a = {
p1: 10
},
Object.defineProperty(_a, 1 + 1, {
get: function () {
throw 10;
},
enumerable: true,
configurable: true
}),
Object.defineProperty(_a, 1 + 1, {
get: function () {
return 10;
},
enumerable: true,
configurable: true
}),
Object.defineProperty(_a, 1 + 1, {
set: function () {
// just throw
throw 10;
},
enumerable: true,
configurable: true
}),
Object.defineProperty(_a, "foo", {
get: function () {
if (1 == 1) {
return 10;
}
},
enumerable: true,
configurable: true
}),
Object.defineProperty(_a, "foo", {
get: function () {
if (1 == 1) {
return 10;
}
},
enumerable: true,
configurable: true
}),
_a.p2 = 20,
_a
);
var _a;
@@ -0,0 +1,40 @@
tests/cases/conformance/es6/computedProperties/computedPropertyNames49_ES6.ts(10,9): error TS1049: A 'set' accessor must have exactly one parameter.
tests/cases/conformance/es6/computedProperties/computedPropertyNames49_ES6.ts(14,9): error TS2300: Duplicate identifier 'foo'.
tests/cases/conformance/es6/computedProperties/computedPropertyNames49_ES6.ts(19,9): error TS1118: An object literal cannot have multiple get/set accessors with the same name.
tests/cases/conformance/es6/computedProperties/computedPropertyNames49_ES6.ts(19,9): error TS2300: Duplicate identifier 'foo'.
==== tests/cases/conformance/es6/computedProperties/computedPropertyNames49_ES6.ts (4 errors) ====
var x = {
p1: 10,
get [1 + 1]() {
throw 10;
},
get [1 + 1]() {
return 10;
},
set [1 + 1]() {
~~~~~~~
!!! error TS1049: A 'set' accessor must have exactly one parameter.
// just throw
throw 10;
},
get foo() {
~~~
!!! error TS2300: Duplicate identifier 'foo'.
if (1 == 1) {
return 10;
}
},
get foo() {
~~~
!!! error TS1118: An object literal cannot have multiple get/set accessors with the same name.
~~~
!!! error TS2300: Duplicate identifier 'foo'.
if (2 == 2) {
return 20;
}
},
p2: 20
}
@@ -0,0 +1,52 @@
//// [computedPropertyNames49_ES6.ts]
var x = {
p1: 10,
get [1 + 1]() {
throw 10;
},
get [1 + 1]() {
return 10;
},
set [1 + 1]() {
// just throw
throw 10;
},
get foo() {
if (1 == 1) {
return 10;
}
},
get foo() {
if (2 == 2) {
return 20;
}
},
p2: 20
}
//// [computedPropertyNames49_ES6.js]
var x = {
p1: 10,
get [1 + 1]() {
throw 10;
},
get [1 + 1]() {
return 10;
},
set [1 + 1]() {
// just throw
throw 10;
},
get foo() {
if (1 == 1) {
return 10;
}
},
get foo() {
if (2 == 2) {
return 20;
}
},
p2: 20
};
@@ -0,0 +1,52 @@
tests/cases/conformance/es6/computedProperties/computedPropertyNames50_ES5.ts(4,9): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher.
tests/cases/conformance/es6/computedProperties/computedPropertyNames50_ES5.ts(4,9): error TS2300: Duplicate identifier 'foo'.
tests/cases/conformance/es6/computedProperties/computedPropertyNames50_ES5.ts(9,9): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher.
tests/cases/conformance/es6/computedProperties/computedPropertyNames50_ES5.ts(12,9): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher.
tests/cases/conformance/es6/computedProperties/computedPropertyNames50_ES5.ts(16,9): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher.
tests/cases/conformance/es6/computedProperties/computedPropertyNames50_ES5.ts(19,9): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher.
tests/cases/conformance/es6/computedProperties/computedPropertyNames50_ES5.ts(19,9): error TS1118: An object literal cannot have multiple get/set accessors with the same name.
tests/cases/conformance/es6/computedProperties/computedPropertyNames50_ES5.ts(19,9): error TS2300: Duplicate identifier 'foo'.
==== tests/cases/conformance/es6/computedProperties/computedPropertyNames50_ES5.ts (8 errors) ====
var x = {
p1: 10,
get foo() {
~~~
!!! error TS1056: Accessors are only available when targeting ECMAScript 5 and higher.
~~~
!!! error TS2300: Duplicate identifier 'foo'.
if (1 == 1) {
return 10;
}
},
get [1 + 1]() {
~~~~~~~
!!! error TS1056: Accessors are only available when targeting ECMAScript 5 and higher.
throw 10;
},
set [1 + 1]() {
~~~~~~~
!!! error TS1056: Accessors are only available when targeting ECMAScript 5 and higher.
// just throw
throw 10;
},
get [1 + 1]() {
~~~~~~~
!!! error TS1056: Accessors are only available when targeting ECMAScript 5 and higher.
return 10;
},
get foo() {
~~~
!!! error TS1056: Accessors are only available when targeting ECMAScript 5 and higher.
~~~
!!! error TS1118: An object literal cannot have multiple get/set accessors with the same name.
~~~
!!! error TS2300: Duplicate identifier 'foo'.
if (2 == 2) {
return 20;
}
},
p2: 20
}
@@ -0,0 +1,71 @@
//// [computedPropertyNames50_ES5.ts]
var x = {
p1: 10,
get foo() {
if (1 == 1) {
return 10;
}
},
get [1 + 1]() {
throw 10;
},
set [1 + 1]() {
// just throw
throw 10;
},
get [1 + 1]() {
return 10;
},
get foo() {
if (2 == 2) {
return 20;
}
},
p2: 20
}
//// [computedPropertyNames50_ES5.js]
var x = (_a = {
p1: 10,
get foo() {
if (1 == 1) {
return 10;
}
}
},
Object.defineProperty(_a, 1 + 1, {
get: function () {
throw 10;
},
enumerable: true,
configurable: true
}),
Object.defineProperty(_a, 1 + 1, {
set: function () {
// just throw
throw 10;
},
enumerable: true,
configurable: true
}),
Object.defineProperty(_a, 1 + 1, {
get: function () {
return 10;
},
enumerable: true,
configurable: true
}),
Object.defineProperty(_a, "foo", {
get: function () {
if (1 == 1) {
return 10;
}
},
enumerable: true,
configurable: true
}),
_a.p2 = 20,
_a
);
var _a;
@@ -0,0 +1,40 @@
tests/cases/conformance/es6/computedProperties/computedPropertyNames50_ES6.ts(4,9): error TS2300: Duplicate identifier 'foo'.
tests/cases/conformance/es6/computedProperties/computedPropertyNames50_ES6.ts(12,9): error TS1049: A 'set' accessor must have exactly one parameter.
tests/cases/conformance/es6/computedProperties/computedPropertyNames50_ES6.ts(19,9): error TS1118: An object literal cannot have multiple get/set accessors with the same name.
tests/cases/conformance/es6/computedProperties/computedPropertyNames50_ES6.ts(19,9): error TS2300: Duplicate identifier 'foo'.
==== tests/cases/conformance/es6/computedProperties/computedPropertyNames50_ES6.ts (4 errors) ====
var x = {
p1: 10,
get foo() {
~~~
!!! error TS2300: Duplicate identifier 'foo'.
if (1 == 1) {
return 10;
}
},
get [1 + 1]() {
throw 10;
},
set [1 + 1]() {
~~~~~~~
!!! error TS1049: A 'set' accessor must have exactly one parameter.
// just throw
throw 10;
},
get [1 + 1]() {
return 10;
},
get foo() {
~~~
!!! error TS1118: An object literal cannot have multiple get/set accessors with the same name.
~~~
!!! error TS2300: Duplicate identifier 'foo'.
if (2 == 2) {
return 20;
}
},
p2: 20
}
@@ -0,0 +1,52 @@
//// [computedPropertyNames50_ES6.ts]
var x = {
p1: 10,
get foo() {
if (1 == 1) {
return 10;
}
},
get [1 + 1]() {
throw 10;
},
set [1 + 1]() {
// just throw
throw 10;
},
get [1 + 1]() {
return 10;
},
get foo() {
if (2 == 2) {
return 20;
}
},
p2: 20
}
//// [computedPropertyNames50_ES6.js]
var x = {
p1: 10,
get foo() {
if (1 == 1) {
return 10;
}
},
get [1 + 1]() {
throw 10;
},
set [1 + 1]() {
// just throw
throw 10;
},
get [1 + 1]() {
return 10;
},
get foo() {
if (2 == 2) {
return 20;
}
},
p2: 20
};
@@ -15,9 +15,9 @@ foo({
//// [computedPropertyNamesContextualType6_ES5.js]
foo((_a = {
p: "",
0: function () { }
},
p: "",
0: function () { }
},
_a["hi" + "bye"] = true,
_a[0 + 1] = 0,
_a[+"hi"] = [0],
@@ -15,9 +15,9 @@ foo({
//// [computedPropertyNamesContextualType7_ES5.js]
foo((_a = {
p: "",
0: function () { }
},
p: "",
0: function () { }
},
_a["hi" + "bye"] = true,
_a[0 + 1] = 0,
_a[+"hi"] = [0],
@@ -0,0 +1,25 @@
var x = {
p1: 10,
get [1 + 1]() {
throw 10;
},
get [1 + 1]() {
return 10;
},
set [1 + 1]() {
// just throw
throw 10;
},
get foo() {
if (1 == 1) {
return 10;
}
},
get foo() {
if (2 == 2) {
return 20;
}
},
p2: 20
}
@@ -0,0 +1,26 @@
// @target: es6
var x = {
p1: 10,
get [1 + 1]() {
throw 10;
},
get [1 + 1]() {
return 10;
},
set [1 + 1]() {
// just throw
throw 10;
},
get foo() {
if (1 == 1) {
return 10;
}
},
get foo() {
if (2 == 2) {
return 20;
}
},
p2: 20
}
@@ -0,0 +1,25 @@
var x = {
p1: 10,
get foo() {
if (1 == 1) {
return 10;
}
},
get [1 + 1]() {
throw 10;
},
set [1 + 1]() {
// just throw
throw 10;
},
get [1 + 1]() {
return 10;
},
get foo() {
if (2 == 2) {
return 20;
}
},
p2: 20
}
@@ -0,0 +1,26 @@
// @target: es6
var x = {
p1: 10,
get foo() {
if (1 == 1) {
return 10;
}
},
get [1 + 1]() {
throw 10;
},
set [1 + 1]() {
// just throw
throw 10;
},
get [1 + 1]() {
return 10;
},
get foo() {
if (2 == 2) {
return 20;
}
},
p2: 20
}