Skip to content

Commit b744633

Browse files
committed
Issue# 144: Do not emit the name of the rest paramter in constructors
1 parent 4223466 commit b744633

9 files changed

+31
-33
lines changed

src/compiler/emitter.ts

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1145,10 +1145,17 @@ module ts {
11451145
}
11461146
}
11471147

1148-
function emitSignatureAndBody(node: FunctionDeclaration) {
1148+
function emitSigatureParamters(node: FunctionDeclaration) {
11491149
write("(");
1150-
emitCommaList(node.parameters, node.parameters.length - (hasRestParameters(node) ? 1 : 0));
1151-
write(") {");
1150+
if (node) {
1151+
emitCommaList(node.parameters, node.parameters.length - (hasRestParameters(node) ? 1 : 0));
1152+
}
1153+
write(")");
1154+
}
1155+
1156+
function emitSignatureAndBody(node: FunctionDeclaration) {
1157+
emitSigatureParamters(node);
1158+
write(" {");
11521159
scopeEmitStart(node);
11531160
increaseIndent();
11541161
var outPos = writer.getTextPos();
@@ -1354,11 +1361,8 @@ module ts {
13541361
emitStart(<Node>ctor || node);
13551362
write("function ");
13561363
emit(node.name);
1357-
write("(");
1358-
if (ctor) {
1359-
emitCommaList(ctor.parameters);
1360-
}
1361-
write(") {");
1364+
emitSigatureParamters(ctor);
1365+
write(" {");
13621366
scopeEmitStart(node, "constructor");
13631367
increaseIndent();
13641368
if (ctor) {

tests/baselines/reference/collisionArgumentsClassConstructor.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ declare class c6NoError {
8888

8989
//// [collisionArgumentsClassConstructor.js]
9090
var c1 = (function () {
91-
function c1(i, arguments) {
91+
function c1(i) {
9292
var arguments = [];
9393
for (var _i = 1; _i < arguments.length; _i++) {
9494
arguments[_i - 1] = arguments[_i];
@@ -98,7 +98,7 @@ var c1 = (function () {
9898
return c1;
9999
})();
100100
var c12 = (function () {
101-
function c12(arguments, rest) {
101+
function c12(arguments) {
102102
var rest = [];
103103
for (var _i = 1; _i < arguments.length; _i++) {
104104
rest[_i - 1] = arguments[_i];
@@ -114,7 +114,7 @@ var c1NoError = (function () {
114114
return c1NoError;
115115
})();
116116
var c2 = (function () {
117-
function c2(restParameters) {
117+
function c2() {
118118
var restParameters = [];
119119
for (var _i = 0; _i < arguments.length; _i++) {
120120
restParameters[_i - 0] = arguments[_i];
@@ -130,7 +130,7 @@ var c2NoError = (function () {
130130
return c2NoError;
131131
})();
132132
var c3 = (function () {
133-
function c3(arguments, restParameters) {
133+
function c3(arguments) {
134134
var restParameters = [];
135135
for (var _i = 1; _i < arguments.length; _i++) {
136136
restParameters[_i - 1] = arguments[_i];
@@ -148,7 +148,7 @@ var c3NoError = (function () {
148148
return c3NoError;
149149
})();
150150
var c5 = (function () {
151-
function c5(i, arguments) {
151+
function c5(i) {
152152
var arguments = [];
153153
for (var _i = 1; _i < arguments.length; _i++) {
154154
arguments[_i - 1] = arguments[_i];
@@ -158,7 +158,7 @@ var c5 = (function () {
158158
return c5;
159159
})();
160160
var c52 = (function () {
161-
function c52(arguments, rest) {
161+
function c52(arguments) {
162162
var rest = [];
163163
for (var _i = 1; _i < arguments.length; _i++) {
164164
rest[_i - 1] = arguments[_i];

tests/baselines/reference/collisionRestParameterClassConstructor.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ declare class c6NoError {
6868

6969
//// [collisionRestParameterClassConstructor.js]
7070
var c1 = (function () {
71-
function c1(_i, restParameters) {
71+
function c1(_i) {
7272
var restParameters = [];
7373
for (var _i = 1; _i < arguments.length; _i++) {
7474
restParameters[_i - 1] = arguments[_i];
@@ -84,7 +84,7 @@ var c1NoError = (function () {
8484
return c1NoError;
8585
})();
8686
var c2 = (function () {
87-
function c2(restParameters) {
87+
function c2() {
8888
var restParameters = [];
8989
for (var _i = 0; _i < arguments.length; _i++) {
9090
restParameters[_i - 0] = arguments[_i];
@@ -100,7 +100,7 @@ var c2NoError = (function () {
100100
return c2NoError;
101101
})();
102102
var c3 = (function () {
103-
function c3(_i, restParameters) {
103+
function c3(_i) {
104104
var restParameters = [];
105105
for (var _i = 1; _i < arguments.length; _i++) {
106106
restParameters[_i - 1] = arguments[_i];
@@ -118,7 +118,7 @@ var c3NoError = (function () {
118118
return c3NoError;
119119
})();
120120
var c5 = (function () {
121-
function c5(_i, rest) {
121+
function c5(_i) {
122122
var rest = [];
123123
for (var _i = 1; _i < arguments.length; _i++) {
124124
rest[_i - 1] = arguments[_i];

tests/baselines/reference/collisionRestParameterUnderscoreIUsage.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ new Foo();
1111
//// [collisionRestParameterUnderscoreIUsage.js]
1212
var _i = "This is what I'd expect to see";
1313
var Foo = (function () {
14-
function Foo(args) {
14+
function Foo() {
1515
var args = [];
1616
for (var _i = 0; _i < arguments.length; _i++) {
1717
args[_i - 0] = arguments[_i];

tests/baselines/reference/declFileConstructors.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ var ConstructorWithParameters = (function () {
112112
})();
113113
exports.ConstructorWithParameters = ConstructorWithParameters;
114114
var ConstructorWithRestParamters = (function () {
115-
function ConstructorWithRestParamters(a, rests) {
115+
function ConstructorWithRestParamters(a) {
116116
var rests = [];
117117
for (var _i = 1; _i < arguments.length; _i++) {
118118
rests[_i - 1] = arguments[_i];
@@ -170,7 +170,7 @@ var GlobalConstructorWithParameters = (function () {
170170
return GlobalConstructorWithParameters;
171171
})();
172172
var GlobalConstructorWithRestParamters = (function () {
173-
function GlobalConstructorWithRestParamters(a, rests) {
173+
function GlobalConstructorWithRestParamters(a) {
174174
var rests = [];
175175
for (var _i = 1; _i < arguments.length; _i++) {
176176
rests[_i - 1] = arguments[_i];

tests/baselines/reference/inheritedConstructorWithRestParams.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ var __extends = this.__extends || function (d, b) {
2222
d.prototype = new __();
2323
};
2424
var Base = (function () {
25-
function Base(a) {
25+
function Base() {
2626
var a = [];
2727
for (var _i = 0; _i < arguments.length; _i++) {
2828
a[_i - 0] = arguments[_i];

tests/baselines/reference/sourceMapValidationClass.js

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/sourceMapValidationClass.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/sourceMapValidationClass.sourcemap.txt

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,44 +12,38 @@ sourceFile:sourceMapValidationClass.ts
1212
1 >
1313
2 >^^^^
1414
3 > ^^^^^^^
15-
4 > ^^^^^^^^^^^^^^^^^^^^^^^^^->
15+
4 > ^^^^^^^^^^^^^^^^^^^^^^->
1616
1 >
1717
2 >class
1818
3 > Greeter
1919
1 >Emitted(1, 1) Source(1, 1) + SourceIndex(0)
2020
2 >Emitted(1, 5) Source(1, 7) + SourceIndex(0)
2121
3 >Emitted(1, 12) Source(1, 14) + SourceIndex(0)
2222
---
23-
>>> function Greeter(greeting, b) {
23+
>>> function Greeter(greeting) {
2424
1->^^^^
2525
2 > ^^^^^^^^^
2626
3 > ^^^^^^^
2727
4 > ^
2828
5 > ^^^^^^^^
29-
6 > ^^
30-
7 > ^
3129
1-> {
3230
>
3331
2 >
3432
3 > Greeter
3533
4 > {
3634
> constructor(public
3735
5 > greeting: string
38-
6 > , ...
39-
7 > b: string[]
4036
1->Emitted(2, 5) Source(2, 5) + SourceIndex(0) name (Greeter)
4137
2 >Emitted(2, 14) Source(1, 7) + SourceIndex(0) name (Greeter)
4238
3 >Emitted(2, 21) Source(1, 14) + SourceIndex(0) name (Greeter)
4339
4 >Emitted(2, 22) Source(2, 24) + SourceIndex(0) name (Greeter)
4440
5 >Emitted(2, 30) Source(2, 40) + SourceIndex(0) name (Greeter)
45-
6 >Emitted(2, 32) Source(2, 45) + SourceIndex(0) name (Greeter)
46-
7 >Emitted(2, 33) Source(2, 56) + SourceIndex(0) name (Greeter)
4741
---
4842
>>> var b = [];
4943
1 >^^^^^^^^
5044
2 > ^^^^^^^^^^^
5145
3 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^->
52-
1 >
46+
1 >,
5347
2 > ...b: string[]
5448
1 >Emitted(3, 9) Source(2, 42) + SourceIndex(0) name (Greeter.constructor)
5549
2 >Emitted(3, 20) Source(2, 56) + SourceIndex(0) name (Greeter.constructor)

0 commit comments

Comments
 (0)