Skip to content

Commit ba87e14

Browse files
committed
Merge pull request microsoft#3726 from Microsoft/restParamModifier
Disallow modifiers on rest parameters
2 parents cd64f2b + 35db9f6 commit ba87e14

File tree

7 files changed

+64
-1
lines changed

7 files changed

+64
-1
lines changed

src/compiler/parser.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1979,8 +1979,8 @@ namespace ts {
19791979
function parseParameter(): ParameterDeclaration {
19801980
let node = <ParameterDeclaration>createNode(SyntaxKind.Parameter);
19811981
node.decorators = parseDecorators();
1982-
node.dotDotDotToken = parseOptionalToken(SyntaxKind.DotDotDotToken);
19831982
setModifiers(node, parseModifiers());
1983+
node.dotDotDotToken = parseOptionalToken(SyntaxKind.DotDotDotToken);
19841984

19851985
// FormalParameter [Yield,Await]:
19861986
// BindingElement[?Yield,?Await]
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
tests/cases/compiler/restParamModifier.ts(2,17): error TS2370: A rest parameter must be of an array type.
2+
tests/cases/compiler/restParamModifier.ts(2,27): error TS1005: '=' expected.
3+
tests/cases/compiler/restParamModifier.ts(2,27): error TS2304: Cannot find name 'rest'.
4+
tests/cases/compiler/restParamModifier.ts(2,31): error TS1005: ',' expected.
5+
tests/cases/compiler/restParamModifier.ts(2,39): error TS1005: '=' expected.
6+
7+
8+
==== tests/cases/compiler/restParamModifier.ts (5 errors) ====
9+
class C {
10+
constructor(...public rest: string[]) {}
11+
~~~~~~~~~~~~~~
12+
!!! error TS2370: A rest parameter must be of an array type.
13+
~~~~
14+
!!! error TS1005: '=' expected.
15+
~~~~
16+
!!! error TS2304: Cannot find name 'rest'.
17+
~
18+
!!! error TS1005: ',' expected.
19+
~
20+
!!! error TS1005: '=' expected.
21+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
//// [restParamModifier.ts]
2+
class C {
3+
constructor(...public rest: string[]) {}
4+
}
5+
6+
//// [restParamModifier.js]
7+
var C = (function () {
8+
function C(public, string) {
9+
if (string === void 0) { string = []; }
10+
}
11+
return C;
12+
})();
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
tests/cases/compiler/restParamModifier2.ts(2,24): error TS1005: ',' expected.
2+
3+
4+
==== tests/cases/compiler/restParamModifier2.ts (1 errors) ====
5+
class C {
6+
constructor(public ...rest: string[]) {}
7+
~~~
8+
!!! error TS1005: ',' expected.
9+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
//// [restParamModifier2.ts]
2+
class C {
3+
constructor(public ...rest: string[]) {}
4+
}
5+
6+
//// [restParamModifier2.js]
7+
var C = (function () {
8+
function C(public) {
9+
var rest = [];
10+
for (var _i = 1; _i < arguments.length; _i++) {
11+
rest[_i - 1] = arguments[_i];
12+
}
13+
}
14+
return C;
15+
})();
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
class C {
2+
constructor(...public rest: string[]) {}
3+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
class C {
2+
constructor(public ...rest: string[]) {}
3+
}

0 commit comments

Comments
 (0)