Merge pull request #145 from Microsoft/restConstructorParam

Issue #144: Do not emit the name of the rest paramter in constructors
This commit is contained in:
Mohamed Hegazy 2014-07-18 09:57:49 -07:00
Родитель 3665e45d19 c9c0166b04
Коммит 91b8a4531f
9 изменённых файлов: 31 добавлений и 33 удалений

Просмотреть файл

@ -1145,10 +1145,17 @@ module ts {
}
}
function emitSignatureAndBody(node: FunctionDeclaration) {
function emitSignatureParameters(node: FunctionDeclaration) {
write("(");
emitCommaList(node.parameters, node.parameters.length - (hasRestParameters(node) ? 1 : 0));
write(") {");
if (node) {
emitCommaList(node.parameters, node.parameters.length - (hasRestParameters(node) ? 1 : 0));
}
write(")");
}
function emitSignatureAndBody(node: FunctionDeclaration) {
emitSignatureParameters(node);
write(" {");
scopeEmitStart(node);
increaseIndent();
var outPos = writer.getTextPos();
@ -1354,11 +1361,8 @@ module ts {
emitStart(<Node>ctor || node);
write("function ");
emit(node.name);
write("(");
if (ctor) {
emitCommaList(ctor.parameters);
}
write(") {");
emitSignatureParameters(ctor);
write(" {");
scopeEmitStart(node, "constructor");
increaseIndent();
if (ctor) {

Просмотреть файл

@ -88,7 +88,7 @@ declare class c6NoError {
//// [collisionArgumentsClassConstructor.js]
var c1 = (function () {
function c1(i, arguments) {
function c1(i) {
var arguments = [];
for (var _i = 1; _i < arguments.length; _i++) {
arguments[_i - 1] = arguments[_i];
@ -98,7 +98,7 @@ var c1 = (function () {
return c1;
})();
var c12 = (function () {
function c12(arguments, rest) {
function c12(arguments) {
var rest = [];
for (var _i = 1; _i < arguments.length; _i++) {
rest[_i - 1] = arguments[_i];
@ -114,7 +114,7 @@ var c1NoError = (function () {
return c1NoError;
})();
var c2 = (function () {
function c2(restParameters) {
function c2() {
var restParameters = [];
for (var _i = 0; _i < arguments.length; _i++) {
restParameters[_i - 0] = arguments[_i];
@ -130,7 +130,7 @@ var c2NoError = (function () {
return c2NoError;
})();
var c3 = (function () {
function c3(arguments, restParameters) {
function c3(arguments) {
var restParameters = [];
for (var _i = 1; _i < arguments.length; _i++) {
restParameters[_i - 1] = arguments[_i];
@ -148,7 +148,7 @@ var c3NoError = (function () {
return c3NoError;
})();
var c5 = (function () {
function c5(i, arguments) {
function c5(i) {
var arguments = [];
for (var _i = 1; _i < arguments.length; _i++) {
arguments[_i - 1] = arguments[_i];
@ -158,7 +158,7 @@ var c5 = (function () {
return c5;
})();
var c52 = (function () {
function c52(arguments, rest) {
function c52(arguments) {
var rest = [];
for (var _i = 1; _i < arguments.length; _i++) {
rest[_i - 1] = arguments[_i];

Просмотреть файл

@ -68,7 +68,7 @@ declare class c6NoError {
//// [collisionRestParameterClassConstructor.js]
var c1 = (function () {
function c1(_i, restParameters) {
function c1(_i) {
var restParameters = [];
for (var _i = 1; _i < arguments.length; _i++) {
restParameters[_i - 1] = arguments[_i];
@ -84,7 +84,7 @@ var c1NoError = (function () {
return c1NoError;
})();
var c2 = (function () {
function c2(restParameters) {
function c2() {
var restParameters = [];
for (var _i = 0; _i < arguments.length; _i++) {
restParameters[_i - 0] = arguments[_i];
@ -100,7 +100,7 @@ var c2NoError = (function () {
return c2NoError;
})();
var c3 = (function () {
function c3(_i, restParameters) {
function c3(_i) {
var restParameters = [];
for (var _i = 1; _i < arguments.length; _i++) {
restParameters[_i - 1] = arguments[_i];
@ -118,7 +118,7 @@ var c3NoError = (function () {
return c3NoError;
})();
var c5 = (function () {
function c5(_i, rest) {
function c5(_i) {
var rest = [];
for (var _i = 1; _i < arguments.length; _i++) {
rest[_i - 1] = arguments[_i];

Просмотреть файл

@ -11,7 +11,7 @@ new Foo();
//// [collisionRestParameterUnderscoreIUsage.js]
var _i = "This is what I'd expect to see";
var Foo = (function () {
function Foo(args) {
function Foo() {
var args = [];
for (var _i = 0; _i < arguments.length; _i++) {
args[_i - 0] = arguments[_i];

Просмотреть файл

@ -112,7 +112,7 @@ var ConstructorWithParameters = (function () {
})();
exports.ConstructorWithParameters = ConstructorWithParameters;
var ConstructorWithRestParamters = (function () {
function ConstructorWithRestParamters(a, rests) {
function ConstructorWithRestParamters(a) {
var rests = [];
for (var _i = 1; _i < arguments.length; _i++) {
rests[_i - 1] = arguments[_i];
@ -170,7 +170,7 @@ var GlobalConstructorWithParameters = (function () {
return GlobalConstructorWithParameters;
})();
var GlobalConstructorWithRestParamters = (function () {
function GlobalConstructorWithRestParamters(a, rests) {
function GlobalConstructorWithRestParamters(a) {
var rests = [];
for (var _i = 1; _i < arguments.length; _i++) {
rests[_i - 1] = arguments[_i];

Просмотреть файл

@ -22,7 +22,7 @@ var __extends = this.__extends || function (d, b) {
d.prototype = new __();
};
var Base = (function () {
function Base(a) {
function Base() {
var a = [];
for (var _i = 0; _i < arguments.length; _i++) {
a[_i - 0] = arguments[_i];

Просмотреть файл

@ -20,7 +20,7 @@ class Greeter {
//// [sourceMapValidationClass.js]
var Greeter = (function () {
function Greeter(greeting, b) {
function Greeter(greeting) {
var b = [];
for (var _i = 1; _i < arguments.length; _i++) {
b[_i - 1] = arguments[_i];

Просмотреть файл

@ -1,2 +1,2 @@
//// [sourceMapValidationClass.js.map]
{"version":3,"file":"sourceMapValidationClass.js","sourceRoot":"","sources":["sourceMapValidationClass.ts"],"names":["Greeter","Greeter.constructor","Greeter.greet","Greeter.fn","Greeter.greetings"],"mappings":"AAAA,IAAM,OAAO;IACTA,SADEA,OAAOA,CACUA,QAAgBA,EAAKA,CAAWA;QAAdC,WAAcA;aAAdA,WAAcA,CAAdA,sBAAcA,CAAdA,IAAcA;YAAdA,0BAAcA;;QAAhCA,aAAQA,GAARA,QAAQA,CAAQA;QAM3BA,OAAEA,GAAWA,EAAEA,CAACA;IALxBA,CAACA;IACDD,uBAAKA,GAALA;QACIE,MAAMA,CAACA,MAAMA,GAAGA,IAAIA,CAACA,QAAQA,GAAGA,OAAOA,CAACA;IAC5CA,CAACA;IAGOF,oBAAEA,GAAVA;QACIG,MAAMA,CAACA,IAAIA,CAACA,QAAQA,CAACA;IACzBA,CAACA;IACDH,sBAAIA,8BAASA;aAAbA;YACII,MAAMA,CAACA,IAAIA,CAACA,QAAQA,CAACA;QACzBA,CAACA;aACDJ,UAAcA,SAAiBA;YAC3BI,IAAIA,CAACA,QAAQA,GAAGA,SAASA,CAACA;QAC9BA,CAACA;;;OAHAJ;IAILA,cAACA;AAADA,CAACA,AAjBD,IAiBC"}
{"version":3,"file":"sourceMapValidationClass.js","sourceRoot":"","sources":["sourceMapValidationClass.ts"],"names":["Greeter","Greeter.constructor","Greeter.greet","Greeter.fn","Greeter.greetings"],"mappings":"AAAA,IAAM,OAAO;IACTA,SADEA,OAAOA,CACUA,QAAgBA;QAAEC,WAAcA;aAAdA,WAAcA,CAAdA,sBAAcA,CAAdA,IAAcA;YAAdA,0BAAcA;;QAAhCA,aAAQA,GAARA,QAAQA,CAAQA;QAM3BA,OAAEA,GAAWA,EAAEA,CAACA;IALxBA,CAACA;IACDD,uBAAKA,GAALA;QACIE,MAAMA,CAACA,MAAMA,GAAGA,IAAIA,CAACA,QAAQA,GAAGA,OAAOA,CAACA;IAC5CA,CAACA;IAGOF,oBAAEA,GAAVA;QACIG,MAAMA,CAACA,IAAIA,CAACA,QAAQA,CAACA;IACzBA,CAACA;IACDH,sBAAIA,8BAASA;aAAbA;YACII,MAAMA,CAACA,IAAIA,CAACA,QAAQA,CAACA;QACzBA,CAACA;aACDJ,UAAcA,SAAiBA;YAC3BI,IAAIA,CAACA,QAAQA,GAAGA,SAASA,CAACA;QAC9BA,CAACA;;;OAHAJ;IAILA,cAACA;AAADA,CAACA,AAjBD,IAiBC"}

Просмотреть файл

@ -12,7 +12,7 @@ sourceFile:sourceMapValidationClass.ts
1 >
2 >^^^^
3 > ^^^^^^^
4 > ^^^^^^^^^^^^^^^^^^^^^^^^^->
4 > ^^^^^^^^^^^^^^^^^^^^^^->
1 >
2 >class
3 > Greeter
@ -20,14 +20,12 @@ sourceFile:sourceMapValidationClass.ts
2 >Emitted(1, 5) Source(1, 7) + SourceIndex(0)
3 >Emitted(1, 12) Source(1, 14) + SourceIndex(0)
---
>>> function Greeter(greeting, b) {
>>> function Greeter(greeting) {
1->^^^^
2 > ^^^^^^^^^
3 > ^^^^^^^
4 > ^
5 > ^^^^^^^^
6 > ^^
7 > ^
1-> {
>
2 >
@ -35,21 +33,17 @@ sourceFile:sourceMapValidationClass.ts
4 > {
> constructor(public
5 > greeting: string
6 > , ...
7 > b: string[]
1->Emitted(2, 5) Source(2, 5) + SourceIndex(0) name (Greeter)
2 >Emitted(2, 14) Source(1, 7) + SourceIndex(0) name (Greeter)
3 >Emitted(2, 21) Source(1, 14) + SourceIndex(0) name (Greeter)
4 >Emitted(2, 22) Source(2, 24) + SourceIndex(0) name (Greeter)
5 >Emitted(2, 30) Source(2, 40) + SourceIndex(0) name (Greeter)
6 >Emitted(2, 32) Source(2, 45) + SourceIndex(0) name (Greeter)
7 >Emitted(2, 33) Source(2, 56) + SourceIndex(0) name (Greeter)
---
>>> var b = [];
1 >^^^^^^^^
2 > ^^^^^^^^^^^
3 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^->
1 >
1 >,
2 > ...b: string[]
1 >Emitted(3, 9) Source(2, 42) + SourceIndex(0) name (Greeter.constructor)
2 >Emitted(3, 20) Source(2, 56) + SourceIndex(0) name (Greeter.constructor)