Skip to content

Commit 29e5983

Browse files
Merge branch 'binaryExprAlloc'
Conflicts: src/compiler/emitter.ts
2 parents 9c867e3 + 09c0c17 commit 29e5983

File tree

62 files changed

+175
-227
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

62 files changed

+175
-227
lines changed

src/compiler/emitter.ts

Lines changed: 4 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -3088,68 +3088,17 @@ module ts {
30883088

30893089
write(tokenToString(node.operatorToken.kind));
30903090

3091-
// We'd like to preserve newlines found in the original binary expression. i.e. if a user has:
3092-
//
3093-
// Foo() ||
3094-
// Bar();
3095-
//
3096-
// Then we'd like to emit it as such. It seems like we'd only need to check for a newline and
3097-
// then just indent and emit. However, that will lead to a problem with deeply nested code.
3098-
// i.e. if you have:
3099-
//
3100-
// Foo() ||
3101-
// Bar() ||
3102-
// Baz();
3103-
//
3104-
// Then we don't want to emit it as:
3105-
//
3106-
// Foo() ||
3107-
// Bar() ||
3108-
// Baz();
3109-
//
3110-
// So we only indent if the right side of the binary expression starts further in on the line
3111-
// versus the left.
3112-
3113-
// Check if the right expression is on a different line versus the operator itself. If so,
3114-
// we'll emit newline.
31153091
if (!nodeEndIsOnSameLineAsNodeStart(node.operatorToken, node.right)) {
3116-
var rightStart = getLineAndCharacterOfPosition(currentSourceFile, skipTrivia(currentSourceFile.text, node.right.pos));
3117-
3118-
// Also, if the right expression starts further in on the line than the left, then we'll indent.
3119-
var exprStart = getLineAndCharacterOfPosition(currentSourceFile, skipTrivia(currentSourceFile.text, node.pos));
3120-
var firstCharOfExpr = getFirstNonWhitespaceCharacterIndexOnLine(exprStart.line);
3121-
var shouldIndent = rightStart.character > firstCharOfExpr;
3122-
3123-
if (shouldIndent) {
3124-
increaseIndent();
3125-
}
3126-
3092+
increaseIndent();
31273093
writeLine();
3094+
emit(node.right);
3095+
decreaseIndent();
31283096
}
31293097
else {
31303098
write(" ");
3131-
}
3132-
3133-
emit(node.right);
3134-
3135-
if (shouldIndent) {
3136-
decreaseIndent();
3137-
}
3138-
}
3139-
}
3140-
3141-
function getFirstNonWhitespaceCharacterIndexOnLine(line: number): number {
3142-
var lineStart = getLineStarts(currentSourceFile)[line];
3143-
var text = currentSourceFile.text;
3144-
3145-
for (var i = lineStart; i < text.length; i++) {
3146-
var ch = text.charCodeAt(i);
3147-
if (!isWhiteSpace(text.charCodeAt(i)) || isLineBreak(ch)) {
3148-
break;
3099+
emit(node.right);
31493100
}
31503101
}
3151-
3152-
return i - lineStart;
31533102
}
31543103

31553104
function emitConditionalExpression(node: ConditionalExpression) {

tests/baselines/reference/ES5SymbolProperty1.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ obj[Symbol.foo];
1313
//// [ES5SymbolProperty1.js]
1414
var Symbol;
1515
var obj = (_a = {}, _a[Symbol.foo] =
16-
0,
17-
_a);
16+
0,
17+
_a);
1818
obj[Symbol.foo];
1919
var _a;

tests/baselines/reference/FunctionDeclaration8_es6.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@ var v = { [yield]: foo }
33

44
//// [FunctionDeclaration8_es6.js]
55
var v = (_a = {}, _a[yield] =
6-
foo,
7-
_a);
6+
foo,
7+
_a);
88
var _a;

tests/baselines/reference/FunctionDeclaration9_es6.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ function * foo() {
66
//// [FunctionDeclaration9_es6.js]
77
function foo() {
88
var v = (_a = {}, _a[] =
9-
foo,
10-
_a);
9+
foo,
10+
_a);
1111
var _a;
1212
}

tests/baselines/reference/FunctionPropertyAssignments5_es6.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@ var v = { *[foo()]() { } }
33

44
//// [FunctionPropertyAssignments5_es6.js]
55
var v = (_a = {}, _a[foo()] = function () { },
6-
_a);
6+
_a);
77
var _a;

tests/baselines/reference/asiArith.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ y
3838
var x = 1;
3939
var y = 1;
4040
var z = x +
41-
+ +y;
41+
+ +y;
4242
var a = 1;
4343
var b = 1;
4444
var c = x -
45-
- -y;
45+
- -y;

tests/baselines/reference/computedPropertyNames10_ES5.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,5 @@ var s;
2121
var n;
2222
var a;
2323
var v = (_a = {}, _a[s] = function () { }, _a[n] = function () { }, _a[s + s] = function () { }, _a[s + n] = function () { }, _a[+s] = function () { }, _a[""] = function () { }, _a[0] = function () { }, _a[a] = function () { }, _a[true] = function () { }, _a["hello bye"] = function () { }, _a["hello " + a + " bye"] = function () { },
24-
_a);
24+
_a);
2525
var _a;

tests/baselines/reference/computedPropertyNames11_ES5.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,5 @@ var s;
2121
var n;
2222
var a;
2323
var v = (_a = {}, _a[s] = Object.defineProperty({ get: function () { return 0; }, enumerable: true, configurable: true }), _a[n] = Object.defineProperty({ set: function (v) { }, enumerable: true, configurable: true }), _a[s + s] = Object.defineProperty({ get: function () { return 0; }, enumerable: true, configurable: true }), _a[s + n] = Object.defineProperty({ set: function (v) { }, enumerable: true, configurable: true }), _a[+s] = Object.defineProperty({ get: function () { return 0; }, enumerable: true, configurable: true }), _a[""] = Object.defineProperty({ set: function (v) { }, enumerable: true, configurable: true }), _a[0] = Object.defineProperty({ get: function () { return 0; }, enumerable: true, configurable: true }), _a[a] = Object.defineProperty({ set: function (v) { }, enumerable: true, configurable: true }), _a[true] = Object.defineProperty({ get: function () { return 0; }, enumerable: true, configurable: true }), _a["hello bye"] = Object.defineProperty({ set: function (v) { }, enumerable: true, configurable: true }), _a["hello " + a + " bye"] = Object.defineProperty({ get: function () { return 0; }, enumerable: true, configurable: true }),
24-
_a);
24+
_a);
2525
var _a;

tests/baselines/reference/computedPropertyNames18_ES5.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ function foo() {
88
//// [computedPropertyNames18_ES5.js]
99
function foo() {
1010
var obj = (_a = {}, _a[this.bar] =
11-
0,
12-
_a);
11+
0,
12+
_a);
1313
var _a;
1414
}

tests/baselines/reference/computedPropertyNames19_ES5.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ module M {
99
var M;
1010
(function (M) {
1111
var obj = (_a = {}, _a[this.bar] =
12-
0,
13-
_a);
12+
0,
13+
_a);
1414
var _a;
1515
})(M || (M = {}));

0 commit comments

Comments
 (0)