Skip to content

Commit d9b459b

Browse files
authored
Merge pull request #15490 from SaschaNaz/allowArguments
Allow use of "arguments" on ambient context
2 parents e642691 + 78ece7b commit d9b459b

File tree

3 files changed

+12
-66
lines changed

3 files changed

+12
-66
lines changed

src/compiler/binder.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ namespace ts {
221221
// other kinds of value declarations take precedence over modules
222222
symbol.valueDeclaration = node;
223223
}
224-
}
224+
}
225225
}
226226

227227
// Should not be called on a declaration with a computed property name,
@@ -389,9 +389,9 @@ namespace ts {
389389
// 1. multiple export default of class declaration or function declaration by checking NodeFlags.Default
390390
// 2. multiple export default of export assignment. This one doesn't have NodeFlags.Default on (as export default doesn't considered as modifiers)
391391
if (symbol.declarations && symbol.declarations.length &&
392-
(isDefaultExport || (node.kind === SyntaxKind.ExportAssignment && !(<ExportAssignment>node).isExportEquals))) {
393-
message = Diagnostics.A_module_cannot_have_multiple_default_exports;
394-
}
392+
(isDefaultExport || (node.kind === SyntaxKind.ExportAssignment && !(<ExportAssignment>node).isExportEquals))) {
393+
message = Diagnostics.A_module_cannot_have_multiple_default_exports;
394+
}
395395
}
396396
}
397397

@@ -1414,7 +1414,7 @@ namespace ts {
14141414
if (isObjectLiteralOrClassExpressionMethod(node)) {
14151415
return ContainerFlags.IsContainer | ContainerFlags.IsControlFlowContainer | ContainerFlags.HasLocals | ContainerFlags.IsFunctionLike | ContainerFlags.IsObjectLiteralOrClassExpressionMethod;
14161416
}
1417-
// falls through
1417+
// falls through
14181418
case SyntaxKind.Constructor:
14191419
case SyntaxKind.FunctionDeclaration:
14201420
case SyntaxKind.MethodSignature:
@@ -1716,7 +1716,7 @@ namespace ts {
17161716
declareModuleMember(node, symbolFlags, symbolExcludes);
17171717
break;
17181718
}
1719-
// falls through
1719+
// falls through
17201720
default:
17211721
if (!blockScopeContainer.locals) {
17221722
blockScopeContainer.locals = createMap<Symbol>();
@@ -2010,7 +2010,7 @@ namespace ts {
20102010
bindBlockScopedDeclaration(<Declaration>parentNode, SymbolFlags.TypeAlias, SymbolFlags.TypeAliasExcludes);
20112011
break;
20122012
}
2013-
// falls through
2013+
// falls through
20142014
case SyntaxKind.ThisKeyword:
20152015
if (currentFlow && (isExpression(node) || parent.kind === SyntaxKind.ShorthandPropertyAssignment)) {
20162016
node.flowNode = currentFlow;
@@ -2186,7 +2186,7 @@ namespace ts {
21862186
if (!isFunctionLike(node.parent)) {
21872187
return;
21882188
}
2189-
// falls through
2189+
// falls through
21902190
case SyntaxKind.ModuleBlock:
21912191
return updateStrictModeStatementList((<Block | ModuleBlock>node).statements);
21922192
}
@@ -2211,7 +2211,7 @@ namespace ts {
22112211
}
22122212

22132213
function bindSourceFileAsExternalModule() {
2214-
bindAnonymousDeclaration(file, SymbolFlags.ValueModule, `"${removeFileExtension(file.fileName) }"`);
2214+
bindAnonymousDeclaration(file, SymbolFlags.ValueModule, `"${removeFileExtension(file.fileName)}"`);
22152215
}
22162216

22172217
function bindExportAssignment(node: ExportAssignment | BinaryExpression) {
@@ -2504,7 +2504,7 @@ namespace ts {
25042504
}
25052505

25062506
function bindParameter(node: ParameterDeclaration) {
2507-
if (inStrictMode) {
2507+
if (inStrictMode && !isInAmbientContext(node)) {
25082508
// It is a SyntaxError if the identifier eval or arguments appears within a FormalParameterList of a
25092509
// strict mode FunctionLikeDeclaration or FunctionExpression(13.1)
25102510
checkStrictModeEvalOrArguments(node, node.name);

tests/baselines/reference/collisionArgumentsClassConstructor.errors.txt

Lines changed: 1 addition & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,6 @@ tests/cases/compiler/collisionArgumentsClassConstructor.ts(30,24): error TS1210:
1313
tests/cases/compiler/collisionArgumentsClassConstructor.ts(31,13): error TS1210: Invalid use of 'arguments'. Class definitions are automatically in strict mode.
1414
tests/cases/compiler/collisionArgumentsClassConstructor.ts(35,24): error TS1210: Invalid use of 'arguments'. Class definitions are automatically in strict mode.
1515
tests/cases/compiler/collisionArgumentsClassConstructor.ts(36,13): error TS1210: Invalid use of 'arguments'. Class definitions are automatically in strict mode.
16-
tests/cases/compiler/collisionArgumentsClassConstructor.ts(41,31): error TS1210: Invalid use of 'arguments'. Class definitions are automatically in strict mode.
17-
tests/cases/compiler/collisionArgumentsClassConstructor.ts(44,17): error TS1210: Invalid use of 'arguments'. Class definitions are automatically in strict mode.
18-
tests/cases/compiler/collisionArgumentsClassConstructor.ts(47,17): error TS1210: Invalid use of 'arguments'. Class definitions are automatically in strict mode.
1916
tests/cases/compiler/collisionArgumentsClassConstructor.ts(51,31): error TS1210: Invalid use of 'arguments'. Class definitions are automatically in strict mode.
2017
tests/cases/compiler/collisionArgumentsClassConstructor.ts(52,31): error TS1210: Invalid use of 'arguments'. Class definitions are automatically in strict mode.
2118
tests/cases/compiler/collisionArgumentsClassConstructor.ts(53,25): error TS2396: Duplicate identifier 'arguments'. Compiler uses 'arguments' to initialize rest parameters.
@@ -30,15 +27,9 @@ tests/cases/compiler/collisionArgumentsClassConstructor.ts(67,17): error TS1210:
3027
tests/cases/compiler/collisionArgumentsClassConstructor.ts(68,17): error TS1210: Invalid use of 'arguments'. Class definitions are automatically in strict mode.
3128
tests/cases/compiler/collisionArgumentsClassConstructor.ts(69,17): error TS1210: Invalid use of 'arguments'. Class definitions are automatically in strict mode.
3229
tests/cases/compiler/collisionArgumentsClassConstructor.ts(70,13): error TS1210: Invalid use of 'arguments'. Class definitions are automatically in strict mode.
33-
tests/cases/compiler/collisionArgumentsClassConstructor.ts(75,31): error TS1210: Invalid use of 'arguments'. Class definitions are automatically in strict mode.
34-
tests/cases/compiler/collisionArgumentsClassConstructor.ts(76,31): error TS1210: Invalid use of 'arguments'. Class definitions are automatically in strict mode.
35-
tests/cases/compiler/collisionArgumentsClassConstructor.ts(79,17): error TS1210: Invalid use of 'arguments'. Class definitions are automatically in strict mode.
36-
tests/cases/compiler/collisionArgumentsClassConstructor.ts(80,17): error TS1210: Invalid use of 'arguments'. Class definitions are automatically in strict mode.
37-
tests/cases/compiler/collisionArgumentsClassConstructor.ts(84,17): error TS1210: Invalid use of 'arguments'. Class definitions are automatically in strict mode.
38-
tests/cases/compiler/collisionArgumentsClassConstructor.ts(85,17): error TS1210: Invalid use of 'arguments'. Class definitions are automatically in strict mode.
3930

4031

41-
==== tests/cases/compiler/collisionArgumentsClassConstructor.ts (38 errors) ====
32+
==== tests/cases/compiler/collisionArgumentsClassConstructor.ts (29 errors) ====
4233
// Constructors
4334
class c1 {
4435
constructor(i: number, ...arguments) { // error
@@ -110,18 +101,12 @@ tests/cases/compiler/collisionArgumentsClassConstructor.ts(85,17): error TS1210:
110101

111102
declare class c4 {
112103
constructor(i: number, ...arguments); // No error - no code gen
113-
~~~~~~~~~
114-
!!! error TS1210: Invalid use of 'arguments'. Class definitions are automatically in strict mode.
115104
}
116105
declare class c42 {
117106
constructor(arguments: number, ...rest); // No error - no code gen
118-
~~~~~~~~~
119-
!!! error TS1210: Invalid use of 'arguments'. Class definitions are automatically in strict mode.
120107
}
121108
declare class c4NoError {
122109
constructor(arguments: number); // no error
123-
~~~~~~~~~
124-
!!! error TS1210: Invalid use of 'arguments'. Class definitions are automatically in strict mode.
125110
}
126111

127112
class c5 {
@@ -178,26 +163,14 @@ tests/cases/compiler/collisionArgumentsClassConstructor.ts(85,17): error TS1210:
178163

179164
declare class c6 {
180165
constructor(i: number, ...arguments); // no codegen no error
181-
~~~~~~~~~
182-
!!! error TS1210: Invalid use of 'arguments'. Class definitions are automatically in strict mode.
183166
constructor(i: string, ...arguments); // no codegen no error
184-
~~~~~~~~~
185-
!!! error TS1210: Invalid use of 'arguments'. Class definitions are automatically in strict mode.
186167
}
187168
declare class c62 {
188169
constructor(arguments: number, ...rest); // no codegen no error
189-
~~~~~~~~~
190-
!!! error TS1210: Invalid use of 'arguments'. Class definitions are automatically in strict mode.
191170
constructor(arguments: string, ...rest); // no codegen no error
192-
~~~~~~~~~
193-
!!! error TS1210: Invalid use of 'arguments'. Class definitions are automatically in strict mode.
194171
}
195172

196173
declare class c6NoError {
197174
constructor(arguments: number); // no error
198-
~~~~~~~~~
199-
!!! error TS1210: Invalid use of 'arguments'. Class definitions are automatically in strict mode.
200175
constructor(arguments: string); // no error
201-
~~~~~~~~~
202-
!!! error TS1210: Invalid use of 'arguments'. Class definitions are automatically in strict mode.
203176
}

tests/baselines/reference/collisionArgumentsClassMethod.errors.txt

Lines changed: 1 addition & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -20,20 +20,11 @@ tests/cases/compiler/collisionArgumentsClassMethod.ts(21,22): error TS1210: Inva
2020
tests/cases/compiler/collisionArgumentsClassMethod.ts(22,22): error TS1210: Invalid use of 'arguments'. Class definitions are automatically in strict mode.
2121
tests/cases/compiler/collisionArgumentsClassMethod.ts(23,22): error TS1210: Invalid use of 'arguments'. Class definitions are automatically in strict mode.
2222
tests/cases/compiler/collisionArgumentsClassMethod.ts(24,13): error TS1210: Invalid use of 'arguments'. Class definitions are automatically in strict mode.
23-
tests/cases/compiler/collisionArgumentsClassMethod.ts(29,30): error TS1210: Invalid use of 'arguments'. Class definitions are automatically in strict mode.
24-
tests/cases/compiler/collisionArgumentsClassMethod.ts(30,17): error TS1210: Invalid use of 'arguments'. Class definitions are automatically in strict mode.
25-
tests/cases/compiler/collisionArgumentsClassMethod.ts(31,23): error TS1210: Invalid use of 'arguments'. Class definitions are automatically in strict mode.
26-
tests/cases/compiler/collisionArgumentsClassMethod.ts(33,29): error TS1210: Invalid use of 'arguments'. Class definitions are automatically in strict mode.
27-
tests/cases/compiler/collisionArgumentsClassMethod.ts(34,29): error TS1210: Invalid use of 'arguments'. Class definitions are automatically in strict mode.
28-
tests/cases/compiler/collisionArgumentsClassMethod.ts(35,16): error TS1210: Invalid use of 'arguments'. Class definitions are automatically in strict mode.
29-
tests/cases/compiler/collisionArgumentsClassMethod.ts(36,16): error TS1210: Invalid use of 'arguments'. Class definitions are automatically in strict mode.
30-
tests/cases/compiler/collisionArgumentsClassMethod.ts(37,22): error TS1210: Invalid use of 'arguments'. Class definitions are automatically in strict mode.
31-
tests/cases/compiler/collisionArgumentsClassMethod.ts(38,22): error TS1210: Invalid use of 'arguments'. Class definitions are automatically in strict mode.
3223
tests/cases/compiler/collisionArgumentsClassMethod.ts(43,13): error TS1210: Invalid use of 'arguments'. Class definitions are automatically in strict mode.
3324
tests/cases/compiler/collisionArgumentsClassMethod.ts(46,13): error TS1210: Invalid use of 'arguments'. Class definitions are automatically in strict mode.
3425

3526

36-
==== tests/cases/compiler/collisionArgumentsClassMethod.ts (33 errors) ====
27+
==== tests/cases/compiler/collisionArgumentsClassMethod.ts (24 errors) ====
3728
class c1 {
3829
public foo(i: number, ...arguments) { //arguments is error
3930
~~~~~~~~~~~~
@@ -107,33 +98,15 @@ tests/cases/compiler/collisionArgumentsClassMethod.ts(46,13): error TS1210: Inva
10798

10899
declare class c2 {
109100
public foo(i: number, ...arguments); // No error - no code gen
110-
~~~~~~~~~
111-
!!! error TS1210: Invalid use of 'arguments'. Class definitions are automatically in strict mode.
112101
public foo1(arguments: number, ...rest); // No error - no code gen
113-
~~~~~~~~~
114-
!!! error TS1210: Invalid use of 'arguments'. Class definitions are automatically in strict mode.
115102
public fooNoError(arguments: number); // No error - no code gen
116-
~~~~~~~~~
117-
!!! error TS1210: Invalid use of 'arguments'. Class definitions are automatically in strict mode.
118103

119104
public f4(i: number, ...arguments); // no codegen no error
120-
~~~~~~~~~
121-
!!! error TS1210: Invalid use of 'arguments'. Class definitions are automatically in strict mode.
122105
public f4(i: string, ...arguments); // no codegen no error
123-
~~~~~~~~~
124-
!!! error TS1210: Invalid use of 'arguments'. Class definitions are automatically in strict mode.
125106
public f41(arguments: number, ...rest); // no codegen no error
126-
~~~~~~~~~
127-
!!! error TS1210: Invalid use of 'arguments'. Class definitions are automatically in strict mode.
128107
public f41(arguments: string, ...rest); // no codegen no error
129-
~~~~~~~~~
130-
!!! error TS1210: Invalid use of 'arguments'. Class definitions are automatically in strict mode.
131108
public f4NoError(arguments: number); // no error
132-
~~~~~~~~~
133-
!!! error TS1210: Invalid use of 'arguments'. Class definitions are automatically in strict mode.
134109
public f4NoError(arguments: string); // no error
135-
~~~~~~~~~
136-
!!! error TS1210: Invalid use of 'arguments'. Class definitions are automatically in strict mode.
137110
}
138111

139112
class c3 {

0 commit comments

Comments
 (0)