Skip to content

Commit ebd63c0

Browse files
Remove optimization of eliding the preamble code for functions without statements.
1 parent e9874a2 commit ebd63c0

60 files changed

Lines changed: 638 additions & 168 deletions

File tree

Some content is hidden

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

src/compiler/emitter.ts

Lines changed: 1 addition & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -3992,46 +3992,6 @@ module ts {
39923992
}
39933993

39943994
function emitBlockFunctionBody(node: FunctionLikeDeclaration, body: Block) {
3995-
// If the body has no statements, and we know there's no code that would cause any
3996-
// prologue to be emitted, then just do a simple emit if the empty block.
3997-
if (body.statements.length === 0 && !anyParameterHasBindingPatternOrInitializer(node)) {
3998-
emitFunctionBodyWithNoStatements(node, body);
3999-
}
4000-
else {
4001-
emitFunctionBodyWithStatements(node, body);
4002-
}
4003-
}
4004-
4005-
function anyParameterHasBindingPatternOrInitializer(func: FunctionLikeDeclaration) {
4006-
return forEach(func.parameters, hasBindingPatternOrInitializer);
4007-
}
4008-
4009-
function hasBindingPatternOrInitializer(parameter: ParameterDeclaration) {
4010-
return parameter.initializer || isBindingPattern(parameter.name);
4011-
}
4012-
4013-
function emitFunctionBodyWithNoStatements(node: FunctionLikeDeclaration, body: Block) {
4014-
var singleLine = isSingleLineEmptyBlock(node.body);
4015-
4016-
write(" {");
4017-
if (singleLine) {
4018-
write(" ");
4019-
}
4020-
else {
4021-
increaseIndent();
4022-
writeLine();
4023-
}
4024-
4025-
emitLeadingCommentsOfPosition(body.statements.end);
4026-
4027-
if (!singleLine) {
4028-
decreaseIndent();
4029-
}
4030-
4031-
emitToken(SyntaxKind.CloseBraceToken, body.statements.end);
4032-
}
4033-
4034-
function emitFunctionBodyWithStatements(node: FunctionLikeDeclaration, body: Block) {
40353995
write(" {");
40363996
scopeEmitStart(node);
40373997

@@ -4046,7 +4006,7 @@ module ts {
40464006
var preambleEmitted = writer.getTextPos() !== outPos;
40474007

40484008
if (!preambleEmitted && nodeEndIsOnSameLineAsNodeStart(body, body)) {
4049-
for (var i = 0, n = body.statements.length; i < n; i++) {
4009+
for (var i = startIndex, n = body.statements.length; i < n; i++) {
40504010
write(" ");
40514011
emit(body.statements[i]);
40524012
}

tests/baselines/reference/accessorWithRestParam.js

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,22 @@ var C = (function () {
1010
function C() {
1111
}
1212
Object.defineProperty(C.prototype, "X", {
13-
set: function () { },
13+
set: function () {
14+
var v = [];
15+
for (var _i = 0; _i < arguments.length; _i++) {
16+
v[_i - 0] = arguments[_i];
17+
}
18+
},
1419
enumerable: true,
1520
configurable: true
1621
});
1722
Object.defineProperty(C, "X", {
18-
set: function () { },
23+
set: function () {
24+
var v2 = [];
25+
for (var _i = 0; _i < arguments.length; _i++) {
26+
v2[_i - 0] = arguments[_i];
27+
}
28+
},
1929
enumerable: true,
2030
configurable: true
2131
});

tests/baselines/reference/arrayLiteralInNonVarArgParameter.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,10 @@ panic([], 'one', 'two');
55

66

77
//// [arrayLiteralInNonVarArgParameter.js]
8-
function panic(val) { }
8+
function panic(val) {
9+
var opt = [];
10+
for (var _i = 1; _i < arguments.length; _i++) {
11+
opt[_i - 1] = arguments[_i];
12+
}
13+
}
914
panic([], 'one', 'two');

tests/baselines/reference/baseTypeAfterDerivedType.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@ interface Base2 {
2020
var Derived2 = (function () {
2121
function Derived2() {
2222
}
23-
Derived2.prototype.method = function () { };
23+
Derived2.prototype.method = function () {
24+
var args = [];
25+
for (var _i = 0; _i < arguments.length; _i++) {
26+
args[_i - 0] = arguments[_i];
27+
}
28+
};
2429
return Derived2;
2530
})();

tests/baselines/reference/callWithSpread.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,10 @@ var __extends = this.__extends || function (d, b) {
6161
d.prototype = new __();
6262
};
6363
function foo(x, y) {
64+
var z = [];
65+
for (var _i = 2; _i < arguments.length; _i++) {
66+
z[_i - 2] = arguments[_i];
67+
}
6468
}
6569
var a;
6670
var z;
@@ -89,6 +93,10 @@ var C = (function () {
8993
this.foo.apply(this, [x, y].concat(z));
9094
}
9195
C.prototype.foo = function (x, y) {
96+
var z = [];
97+
for (var _i = 2; _i < arguments.length; _i++) {
98+
z[_i - 2] = arguments[_i];
99+
}
92100
};
93101
return C;
94102
})();

tests/baselines/reference/collisionRestParameterFunction.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,10 @@ function f3NoError() {
5656
var _i = 10; // no error
5757
}
5858
function f4(_i) {
59+
var rest = [];
60+
for (var _a = 1; _a < arguments.length; _a++) {
61+
rest[_a - 1] = arguments[_a];
62+
}
5963
}
6064
function f4NoError(_i) {
6165
}

tests/baselines/reference/collisionRestParameterFunctionExpressions.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,10 @@ function foo() {
4747
var _i = 10; // no error
4848
}
4949
function f4(_i) {
50+
var rest = [];
51+
for (var _a = 1; _a < arguments.length; _a++) {
52+
rest[_a - 1] = arguments[_a];
53+
}
5054
}
5155
function f4NoError(_i) {
5256
}

tests/baselines/reference/contextualTyping.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/baselines/reference/contextualTyping.sourcemap.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2210,8 +2210,8 @@ sourceFile:contextualTyping.ts
22102210
2 >Emitted(87, 14) Source(146, 14) + SourceIndex(0)
22112211
3 >Emitted(87, 15) Source(146, 15) + SourceIndex(0)
22122212
4 >Emitted(87, 16) Source(146, 37) + SourceIndex(0)
2213-
5 >Emitted(87, 20) Source(146, 40) + SourceIndex(0)
2214-
6 >Emitted(87, 21) Source(146, 41) + SourceIndex(0)
2213+
5 >Emitted(87, 20) Source(146, 40) + SourceIndex(0) name (c9t5)
2214+
6 >Emitted(87, 21) Source(146, 41) + SourceIndex(0) name (c9t5)
22152215
---
22162216
>>>;
22172217
1 >

tests/baselines/reference/declFileRestParametersOfFunctionAndFunctionType.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,12 @@ var f6 = () => { return [<any>10]; }
1111

1212

1313
//// [declFileRestParametersOfFunctionAndFunctionType.js]
14-
function f1() { }
14+
function f1() {
15+
var args = [];
16+
for (var _i = 0; _i < arguments.length; _i++) {
17+
args[_i - 0] = arguments[_i];
18+
}
19+
}
1520
function f2(x) { }
1621
function f3(x) { }
1722
function f4() { }

0 commit comments

Comments
 (0)