Skip to content

Commit 1561701

Browse files
authored
Allow to define valid static fields with names conflicting with builtin properties (#54198)
1 parent 0d26261 commit 1561701

10 files changed

+1845
-183
lines changed

src/compiler/checker.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38334,6 +38334,10 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
3833438334
case "length":
3833538335
case "caller":
3833638336
case "arguments":
38337+
if (compilerOptions.useDefineForClassFields) {
38338+
break;
38339+
}
38340+
// fall through
3833738341
case "prototype":
3833838342
const message = Diagnostics.Static_property_0_conflicts_with_built_in_property_Function_0_of_constructor_function_1;
3833938343
const className = getNameOfSymbolAsWritten(getSymbolOfDeclaration(node));

tests/baselines/reference/staticPropertyNameConflicts.errors.txt renamed to tests/baselines/reference/staticPropertyNameConflicts(usedefineforclassfields=false).errors.txt

Lines changed: 33 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -44,44 +44,44 @@ tests/cases/conformance/classes/propertyMemberDeclarations/staticPropertyNameCon
4444
==== tests/cases/conformance/classes/propertyMemberDeclarations/staticPropertyNameConflicts.ts (41 errors) ====
4545
// name
4646
class StaticName {
47-
static name: number; // error
47+
static name: number; // error without useDefineForClassFields
4848
~~~~
4949
!!! error TS2699: Static property 'name' conflicts with built-in property 'Function.name' of constructor function 'StaticName'.
5050
name: string; // ok
5151
}
5252

5353
class StaticNameFn {
54-
static name() {} // error
54+
static name() {} // error without useDefineForClassFields
5555
~~~~
5656
!!! error TS2699: Static property 'name' conflicts with built-in property 'Function.name' of constructor function 'StaticNameFn'.
5757
name() {} // ok
5858
}
5959

6060
// length
6161
class StaticLength {
62-
static length: number; // error
62+
static length: number; // error without useDefineForClassFields
6363
~~~~~~
6464
!!! error TS2699: Static property 'length' conflicts with built-in property 'Function.length' of constructor function 'StaticLength'.
6565
length: string; // ok
6666
}
6767

6868
class StaticLengthFn {
69-
static length() {} // error
69+
static length() {} // error without useDefineForClassFields
7070
~~~~~~
7171
!!! error TS2699: Static property 'length' conflicts with built-in property 'Function.length' of constructor function 'StaticLengthFn'.
7272
length() {} // ok
7373
}
7474

7575
// prototype
7676
class StaticPrototype {
77-
static prototype: number; // error
77+
static prototype: number; // always an error
7878
~~~~~~~~~
7979
!!! error TS2699: Static property 'prototype' conflicts with built-in property 'Function.prototype' of constructor function 'StaticPrototype'.
8080
prototype: string; // ok
8181
}
8282

8383
class StaticPrototypeFn {
84-
static prototype() {} // error
84+
static prototype() {} // always an error
8585
~~~~~~~~~
8686
!!! error TS2300: Duplicate identifier 'prototype'.
8787
~~~~~~~~~
@@ -91,29 +91,29 @@ tests/cases/conformance/classes/propertyMemberDeclarations/staticPropertyNameCon
9191

9292
// caller
9393
class StaticCaller {
94-
static caller: number; // error
94+
static caller: number; // error without useDefineForClassFields
9595
~~~~~~
9696
!!! error TS2699: Static property 'caller' conflicts with built-in property 'Function.caller' of constructor function 'StaticCaller'.
9797
caller: string; // ok
9898
}
9999

100100
class StaticCallerFn {
101-
static caller() {} // error
101+
static caller() {} // error without useDefineForClassFields
102102
~~~~~~
103103
!!! error TS2699: Static property 'caller' conflicts with built-in property 'Function.caller' of constructor function 'StaticCallerFn'.
104104
caller() {} // ok
105105
}
106106

107107
// arguments
108108
class StaticArguments {
109-
static arguments: number; // error
109+
static arguments: number; // error without useDefineForClassFields
110110
~~~~~~~~~
111111
!!! error TS2699: Static property 'arguments' conflicts with built-in property 'Function.arguments' of constructor function 'StaticArguments'.
112112
arguments: string; // ok
113113
}
114114

115115
class StaticArgumentsFn {
116-
static arguments() {} // error
116+
static arguments() {} // error without useDefineForClassFields
117117
~~~~~~~~~
118118
!!! error TS2699: Static property 'arguments' conflicts with built-in property 'Function.arguments' of constructor function 'StaticArgumentsFn'.
119119
arguments() {} // ok
@@ -125,44 +125,44 @@ tests/cases/conformance/classes/propertyMemberDeclarations/staticPropertyNameCon
125125

126126
// name
127127
var StaticName_Anonymous = class {
128-
static name: number; // error
128+
static name: number; // error without useDefineForClassFields
129129
~~~~
130130
!!! error TS2699: Static property 'name' conflicts with built-in property 'Function.name' of constructor function 'StaticName_Anonymous'.
131131
name: string; // ok
132132
}
133133

134134
var StaticNameFn_Anonymous = class {
135-
static name() {} // error
135+
static name() {} // error without useDefineForClassFields
136136
~~~~
137137
!!! error TS2699: Static property 'name' conflicts with built-in property 'Function.name' of constructor function 'StaticNameFn_Anonymous'.
138138
name() {} // ok
139139
}
140140

141141
// length
142142
var StaticLength_Anonymous = class {
143-
static length: number; // error
143+
static length: number; // error without useDefineForClassFields
144144
~~~~~~
145145
!!! error TS2699: Static property 'length' conflicts with built-in property 'Function.length' of constructor function 'StaticLength_Anonymous'.
146146
length: string; // ok
147147
}
148148

149149
var StaticLengthFn_Anonymous = class {
150-
static length() {} // error
150+
static length() {} // error without useDefineForClassFields
151151
~~~~~~
152152
!!! error TS2699: Static property 'length' conflicts with built-in property 'Function.length' of constructor function 'StaticLengthFn_Anonymous'.
153153
length() {} // ok
154154
}
155155

156156
// prototype
157157
var StaticPrototype_Anonymous = class {
158-
static prototype: number; // error
158+
static prototype: number; // always an error
159159
~~~~~~~~~
160160
!!! error TS2699: Static property 'prototype' conflicts with built-in property 'Function.prototype' of constructor function 'StaticPrototype_Anonymous'.
161161
prototype: string; // ok
162162
}
163163

164164
var StaticPrototypeFn_Anonymous = class {
165-
static prototype() {} // error
165+
static prototype() {} // always an error
166166
~~~~~~~~~
167167
!!! error TS2300: Duplicate identifier 'prototype'.
168168
~~~~~~~~~
@@ -172,29 +172,29 @@ tests/cases/conformance/classes/propertyMemberDeclarations/staticPropertyNameCon
172172

173173
// caller
174174
var StaticCaller_Anonymous = class {
175-
static caller: number; // error
175+
static caller: number; // error without useDefineForClassFields
176176
~~~~~~
177177
!!! error TS2699: Static property 'caller' conflicts with built-in property 'Function.caller' of constructor function 'StaticCaller_Anonymous'.
178178
caller: string; // ok
179179
}
180180

181181
var StaticCallerFn_Anonymous = class {
182-
static caller() {} // error
182+
static caller() {} // error without useDefineForClassFields
183183
~~~~~~
184184
!!! error TS2699: Static property 'caller' conflicts with built-in property 'Function.caller' of constructor function 'StaticCallerFn_Anonymous'.
185185
caller() {} // ok
186186
}
187187

188188
// arguments
189189
var StaticArguments_Anonymous = class {
190-
static arguments: number; // error
190+
static arguments: number; // error without useDefineForClassFields
191191
~~~~~~~~~
192192
!!! error TS2699: Static property 'arguments' conflicts with built-in property 'Function.arguments' of constructor function 'StaticArguments_Anonymous'.
193193
arguments: string; // ok
194194
}
195195

196196
var StaticArgumentsFn_Anonymous = class {
197-
static arguments() {} // error
197+
static arguments() {} // error without useDefineForClassFields
198198
~~~~~~~~~
199199
!!! error TS2699: Static property 'arguments' conflicts with built-in property 'Function.arguments' of constructor function 'StaticArgumentsFn_Anonymous'.
200200
arguments() {} // ok
@@ -206,7 +206,7 @@ tests/cases/conformance/classes/propertyMemberDeclarations/staticPropertyNameCon
206206
// name
207207
module TestOnDefaultExportedClass_1 {
208208
class StaticName {
209-
static name: number; // error
209+
static name: number; // error without useDefineForClassFields
210210
~~~~
211211
!!! error TS2699: Static property 'name' conflicts with built-in property 'Function.name' of constructor function 'StaticName'.
212212
name: string; // ok
@@ -215,7 +215,7 @@ tests/cases/conformance/classes/propertyMemberDeclarations/staticPropertyNameCon
215215

216216
module TestOnDefaultExportedClass_2 {
217217
class StaticNameFn {
218-
static name() {} // error
218+
static name() {} // error without useDefineForClassFields
219219
~~~~
220220
!!! error TS2699: Static property 'name' conflicts with built-in property 'Function.name' of constructor function 'StaticNameFn'.
221221
name() {} // ok
@@ -227,7 +227,7 @@ tests/cases/conformance/classes/propertyMemberDeclarations/staticPropertyNameCon
227227
export default class StaticLength {
228228
~~~~~~~
229229
!!! error TS1319: A default export can only be used in an ECMAScript-style module.
230-
static length: number; // error
230+
static length: number; // error without useDefineForClassFields
231231
~~~~~~
232232
!!! error TS2699: Static property 'length' conflicts with built-in property 'Function.length' of constructor function 'StaticLength'.
233233
length: string; // ok
@@ -238,19 +238,19 @@ tests/cases/conformance/classes/propertyMemberDeclarations/staticPropertyNameCon
238238
export default class StaticLengthFn {
239239
~~~~~~~
240240
!!! error TS1319: A default export can only be used in an ECMAScript-style module.
241-
static length() {} // error
241+
static length() {} // error without useDefineForClassFields
242242
~~~~~~
243243
!!! error TS2699: Static property 'length' conflicts with built-in property 'Function.length' of constructor function 'StaticLengthFn'.
244244
length() {} // ok
245245
}
246246
}
247247

248248
// prototype
249-
module TestOnDefaultExportedClass_5 {
249+
module TestOnDefaultExportedClass_5 {
250250
export default class StaticPrototype {
251251
~~~~~~~
252252
!!! error TS1319: A default export can only be used in an ECMAScript-style module.
253-
static prototype: number; // error
253+
static prototype: number; // always an error
254254
~~~~~~~~~
255255
!!! error TS2699: Static property 'prototype' conflicts with built-in property 'Function.prototype' of constructor function 'StaticPrototype'.
256256
prototype: string; // ok
@@ -261,7 +261,7 @@ tests/cases/conformance/classes/propertyMemberDeclarations/staticPropertyNameCon
261261
export default class StaticPrototypeFn {
262262
~~~~~~~
263263
!!! error TS1319: A default export can only be used in an ECMAScript-style module.
264-
static prototype() {} // error
264+
static prototype() {} // always an error
265265
~~~~~~~~~
266266
!!! error TS2300: Duplicate identifier 'prototype'.
267267
~~~~~~~~~
@@ -275,7 +275,7 @@ tests/cases/conformance/classes/propertyMemberDeclarations/staticPropertyNameCon
275275
export default class StaticCaller {
276276
~~~~~~~
277277
!!! error TS1319: A default export can only be used in an ECMAScript-style module.
278-
static caller: number; // error
278+
static caller: number; // error without useDefineForClassFields
279279
~~~~~~
280280
!!! error TS2699: Static property 'caller' conflicts with built-in property 'Function.caller' of constructor function 'StaticCaller'.
281281
caller: string; // ok
@@ -286,7 +286,7 @@ tests/cases/conformance/classes/propertyMemberDeclarations/staticPropertyNameCon
286286
export default class StaticCallerFn {
287287
~~~~~~~
288288
!!! error TS1319: A default export can only be used in an ECMAScript-style module.
289-
static caller() {} // error
289+
static caller() {} // error without useDefineForClassFields
290290
~~~~~~
291291
!!! error TS2699: Static property 'caller' conflicts with built-in property 'Function.caller' of constructor function 'StaticCallerFn'.
292292
caller() {} // ok
@@ -298,7 +298,7 @@ tests/cases/conformance/classes/propertyMemberDeclarations/staticPropertyNameCon
298298
export default class StaticArguments {
299299
~~~~~~~
300300
!!! error TS1319: A default export can only be used in an ECMAScript-style module.
301-
static arguments: number; // error
301+
static arguments: number; // error without useDefineForClassFields
302302
~~~~~~~~~
303303
!!! error TS2699: Static property 'arguments' conflicts with built-in property 'Function.arguments' of constructor function 'StaticArguments'.
304304
arguments: string; // ok
@@ -309,9 +309,10 @@ tests/cases/conformance/classes/propertyMemberDeclarations/staticPropertyNameCon
309309
export default class StaticArgumentsFn {
310310
~~~~~~~
311311
!!! error TS1319: A default export can only be used in an ECMAScript-style module.
312-
static arguments() {} // error
312+
static arguments() {} // error without useDefineForClassFields
313313
~~~~~~~~~
314314
!!! error TS2699: Static property 'arguments' conflicts with built-in property 'Function.arguments' of constructor function 'StaticArgumentsFn'.
315315
arguments() {} // ok
316316
}
317-
}
317+
}
318+

0 commit comments

Comments
 (0)