mirror of
https://github.com/microsoft/TypeScript.git
synced 2025-11-18 17:21:48 +00:00
Preserve newlines between object literal members.
This commit is contained in:
+8
-27
@@ -2546,32 +2546,6 @@ module ts {
|
||||
}
|
||||
}
|
||||
|
||||
function emitObjectLiteralBody(node: ObjectLiteralExpression, numElements: number) {
|
||||
write("{");
|
||||
|
||||
var multiLine = (node.flags & NodeFlags.MultiLine) !== 0;
|
||||
|
||||
if (numElements > 0) {
|
||||
var properties = node.properties;
|
||||
if (!multiLine) {
|
||||
write(" ");
|
||||
}
|
||||
else {
|
||||
increaseIndent();
|
||||
}
|
||||
emitList(properties, 0, numElements, /*multiLine*/ multiLine,
|
||||
/*trailingComma*/ properties.hasTrailingComma && languageVersion >= ScriptTarget.ES5);
|
||||
if (!multiLine) {
|
||||
write(" ");
|
||||
}
|
||||
else {
|
||||
decreaseIndent();
|
||||
}
|
||||
}
|
||||
|
||||
write("}");
|
||||
}
|
||||
|
||||
function createSynthesizedNode(kind: SyntaxKind): Node {
|
||||
var node = createNode(kind);
|
||||
node.pos = -1;
|
||||
@@ -2801,7 +2775,14 @@ module ts {
|
||||
|
||||
// Ordinary case: either the object has no computed properties
|
||||
// or we're compiling with an ES6+ target.
|
||||
emitObjectLiteralBody(node, properties.length);
|
||||
write("{");
|
||||
|
||||
var properties = node.properties;
|
||||
if (properties.length) {
|
||||
emitLinePreservingList(node, properties, /*allowTrailingComma:*/ languageVersion >= ScriptTarget.ES5, /*spacesBetweenBraces:*/ true)
|
||||
}
|
||||
|
||||
write("}");
|
||||
}
|
||||
|
||||
function emitComputedPropertyName(node: ComputedPropertyName) {
|
||||
|
||||
@@ -1965,8 +1965,6 @@ function compile(fileNames, options) {
|
||||
}
|
||||
exports.compile = compile;
|
||||
compile(process.argv.slice(2), {
|
||||
noEmitOnError: true,
|
||||
noImplicitAny: true,
|
||||
target: 1 /* ES5 */,
|
||||
module: 1 /* CommonJS */
|
||||
noEmitOnError: true, noImplicitAny: true,
|
||||
target: 1 /* ES5 */, module: 1 /* CommonJS */
|
||||
});
|
||||
|
||||
@@ -7,5 +7,6 @@ var v = { * foo() {
|
||||
|
||||
//// [YieldExpression10_es6.js]
|
||||
var v = { foo: function () {
|
||||
;
|
||||
} };
|
||||
;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -20,9 +20,7 @@ var C = (function () {
|
||||
return C;
|
||||
})();
|
||||
var y = {
|
||||
foo: ,
|
||||
class: C2
|
||||
}, _a = void 0;
|
||||
foo: , class: C2 }, _a = void 0;
|
||||
var M;
|
||||
(function (M) {
|
||||
var z = ;
|
||||
|
||||
@@ -30,17 +30,17 @@ var x = (_a = {
|
||||
p1: 10
|
||||
}, _a.p1 =
|
||||
10, _a[1 + 1] = Object.defineProperty({ get: function () {
|
||||
throw 10;
|
||||
}, enumerable: true, configurable: true }), _a[1 + 1] = Object.defineProperty({ get: function () {
|
||||
return 10;
|
||||
}, enumerable: true, configurable: true }), _a[1 + 1] = Object.defineProperty({ set: function () {
|
||||
// just throw
|
||||
throw 10;
|
||||
}, enumerable: true, configurable: true }), _a.foo = Object.defineProperty({ get: function () {
|
||||
if (1 == 1) {
|
||||
throw 10;
|
||||
}, enumerable: true, configurable: true }), _a[1 + 1] = Object.defineProperty({ get: function () {
|
||||
return 10;
|
||||
}
|
||||
}, enumerable: true, configurable: true }), _a.p2 =
|
||||
}, enumerable: true, configurable: true }), _a[1 + 1] = Object.defineProperty({ set: function () {
|
||||
// just throw
|
||||
throw 10;
|
||||
}, enumerable: true, configurable: true }), _a.foo = Object.defineProperty({ get: function () {
|
||||
if (1 == 1) {
|
||||
return 10;
|
||||
}
|
||||
}, enumerable: true, configurable: true }), _a.p2 =
|
||||
20,
|
||||
_a);
|
||||
var _a;
|
||||
|
||||
@@ -35,17 +35,17 @@ var x = (_a = {
|
||||
}
|
||||
}, _a.p1 =
|
||||
10, _a.foo = Object.defineProperty({ get: function () {
|
||||
if (1 == 1) {
|
||||
if (1 == 1) {
|
||||
return 10;
|
||||
}
|
||||
}, enumerable: true, configurable: true }), _a[1 + 1] = Object.defineProperty({ get: function () {
|
||||
throw 10;
|
||||
}, enumerable: true, configurable: true }), _a[1 + 1] = Object.defineProperty({ set: function () {
|
||||
// just throw
|
||||
throw 10;
|
||||
}, enumerable: true, configurable: true }), _a[1 + 1] = Object.defineProperty({ get: function () {
|
||||
return 10;
|
||||
}
|
||||
}, enumerable: true, configurable: true }), _a[1 + 1] = Object.defineProperty({ get: function () {
|
||||
throw 10;
|
||||
}, enumerable: true, configurable: true }), _a[1 + 1] = Object.defineProperty({ set: function () {
|
||||
// just throw
|
||||
throw 10;
|
||||
}, enumerable: true, configurable: true }), _a[1 + 1] = Object.defineProperty({ get: function () {
|
||||
return 10;
|
||||
}, enumerable: true, configurable: true }), _a.p2 =
|
||||
}, enumerable: true, configurable: true }), _a.p2 =
|
||||
20,
|
||||
_a);
|
||||
var _a;
|
||||
|
||||
@@ -37,5 +37,4 @@ var C3 = (function () {
|
||||
return C3;
|
||||
})();
|
||||
var x = {
|
||||
class: C4
|
||||
}, _a = void 0;
|
||||
class: C4 }, _a = void 0;
|
||||
|
||||
@@ -5,5 +5,4 @@ var v = {
|
||||
|
||||
//// [objectLiteralWithSemicolons4.js]
|
||||
var v = {
|
||||
a:
|
||||
};
|
||||
a: };
|
||||
|
||||
@@ -42,6 +42,5 @@ var C2 = (function () {
|
||||
return C2;
|
||||
})();
|
||||
var b = {
|
||||
x: function () { },
|
||||
1: // error
|
||||
x: function () { }, 1: // error
|
||||
};
|
||||
|
||||
@@ -3,4 +3,5 @@ var v = { a
|
||||
return;
|
||||
|
||||
//// [parserErrorRecovery_ObjectLiteral2.js]
|
||||
var v = { a: , return: };
|
||||
var v = { a: ,
|
||||
return: };
|
||||
|
||||
@@ -3,4 +3,5 @@ var v = { a:
|
||||
return;
|
||||
|
||||
//// [parserErrorRecovery_ObjectLiteral3.js]
|
||||
var v = { a: , return: };
|
||||
var v = { a: ,
|
||||
return: };
|
||||
|
||||
@@ -3,4 +3,5 @@ var v = { a: 1
|
||||
return;
|
||||
|
||||
//// [parserErrorRecovery_ObjectLiteral4.js]
|
||||
var v = { a: 1, return: };
|
||||
var v = { a: 1,
|
||||
return: };
|
||||
|
||||
@@ -3,4 +3,5 @@ var v = { a: 1,
|
||||
return;
|
||||
|
||||
//// [parserErrorRecovery_ObjectLiteral5.js]
|
||||
var v = { a: 1, return: };
|
||||
var v = { a: 1,
|
||||
return: };
|
||||
|
||||
@@ -5,6 +5,5 @@ var x = {
|
||||
|
||||
//// [parserSymbolIndexer5.js]
|
||||
var x = {
|
||||
[s]: symbol,
|
||||
"":
|
||||
[s]: symbol, "":
|
||||
};
|
||||
|
||||
@@ -2627,9 +2627,7 @@ var Harness;
|
||||
var description = b.description + (prop ? ": " + prop : '');
|
||||
emitLog('testStart', { desc: description });
|
||||
emitLog('pass', {
|
||||
desc: description,
|
||||
pass: true,
|
||||
perfResults: {
|
||||
desc: description, pass: true, perfResults: {
|
||||
mean: b.results[prop].mean(),
|
||||
min: b.results[prop].min(),
|
||||
max: b.results[prop].max(),
|
||||
|
||||
@@ -109,6 +109,9 @@ function C(a, b) {
|
||||
this.b = b;
|
||||
}
|
||||
C.prototype =
|
||||
{ a: 0, b: 0, C1M1: function (c, d) {
|
||||
return (this.a + c) + (this.b + d);
|
||||
} };
|
||||
{ a: 0,
|
||||
b: 0,
|
||||
C1M1: function (c, d) {
|
||||
return (this.a + c) + (this.b + d);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -6,6 +6,5 @@ var x = {
|
||||
|
||||
//// [templateStringInObjectLiteral.js]
|
||||
var x = {
|
||||
a: "abc" + 123 + "def"
|
||||
} "b";
|
||||
a: "abc" + 123 + "def" } "b";
|
||||
321;
|
||||
|
||||
@@ -6,6 +6,5 @@ var x = {
|
||||
|
||||
//// [templateStringInObjectLiteralES6.js]
|
||||
var x = {
|
||||
a: `abc${123}def`,
|
||||
} `b`;
|
||||
a: `abc${123}def`, } `b`;
|
||||
321;
|
||||
|
||||
@@ -30,6 +30,6 @@ var C = (function () {
|
||||
})();
|
||||
var c = new C({ length: 2 });
|
||||
var r = c.foo({ length: 3, charAt: function (x) {
|
||||
'';
|
||||
} });
|
||||
'';
|
||||
} });
|
||||
var r2 = r('');
|
||||
|
||||
@@ -28,5 +28,5 @@ var C = (function () {
|
||||
var c = new C({ length: 2 });
|
||||
var r = c.foo('');
|
||||
var r2 = r({ length: 3, charAt: function (x) {
|
||||
'';
|
||||
} }); // error
|
||||
'';
|
||||
} }); // error
|
||||
|
||||
Reference in New Issue
Block a user