Skip to content

Commit 6c90e3f

Browse files
authored
Merge pull request #13616 from tinganho/staticPropertyConflictsInAmbientContext
Static property conflicts in ambient context
2 parents 4ee8213 + 36f6e19 commit 6c90e3f

File tree

4 files changed

+279
-5
lines changed

4 files changed

+279
-5
lines changed

src/compiler/checker.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15722,12 +15722,12 @@ namespace ts {
1572215722
}
1572315723
}
1572415724

15725-
/**
15725+
/**
1572615726
* Static members being set on a constructor function may conflict with built-in properties
15727-
* of Function. Esp. in ECMAScript 5 there are non-configurable and non-writable
15728-
* built-in properties. This check issues a transpile error when a class has a static
15727+
* of Function. Esp. in ECMAScript 5 there are non-configurable and non-writable
15728+
* built-in properties. This check issues a transpile error when a class has a static
1572915729
* member with the same name as a non-writable built-in property.
15730-
*
15730+
*
1573115731
* @see http://www.ecma-international.org/ecma-262/5.1/#sec-15.3.3
1573215732
* @see http://www.ecma-international.org/ecma-262/5.1/#sec-15.3.5
1573315733
* @see http://www.ecma-international.org/ecma-262/6.0/#sec-properties-of-the-function-constructor
@@ -18337,7 +18337,11 @@ namespace ts {
1833718337
const staticType = <ObjectType>getTypeOfSymbol(symbol);
1833818338
checkTypeParameterListsIdentical(node, symbol);
1833918339
checkClassForDuplicateDeclarations(node);
18340-
checkClassForStaticPropertyNameConflicts(node);
18340+
18341+
// Only check for reserved static identifiers on non-ambient context.
18342+
if (!isInAmbientContext(node)) {
18343+
checkClassForStaticPropertyNameConflicts(node);
18344+
}
1834118345

1834218346
const baseTypeNode = getClassExtendsHeritageClauseElement(node);
1834318347
if (baseTypeNode) {
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
=== tests/cases/conformance/classes/propertyMemberDeclarations/decl.d.ts ===
2+
3+
// name
4+
declare class StaticName {
5+
>StaticName : Symbol(StaticName, Decl(decl.d.ts, 0, 0))
6+
7+
static name: number; // ok
8+
>name : Symbol(StaticName.name, Decl(decl.d.ts, 2, 26))
9+
10+
name: string; // ok
11+
>name : Symbol(StaticName.name, Decl(decl.d.ts, 3, 24))
12+
}
13+
14+
declare class StaticNameFn {
15+
>StaticNameFn : Symbol(StaticNameFn, Decl(decl.d.ts, 5, 1))
16+
17+
static name(): string; // ok
18+
>name : Symbol(StaticNameFn.name, Decl(decl.d.ts, 7, 28))
19+
20+
name(): string; // ok
21+
>name : Symbol(StaticNameFn.name, Decl(decl.d.ts, 8, 26))
22+
}
23+
24+
// length
25+
declare class StaticLength {
26+
>StaticLength : Symbol(StaticLength, Decl(decl.d.ts, 10, 1))
27+
28+
static length: number; // ok
29+
>length : Symbol(StaticLength.length, Decl(decl.d.ts, 13, 28))
30+
31+
length: string; // ok
32+
>length : Symbol(StaticLength.length, Decl(decl.d.ts, 14, 26))
33+
}
34+
35+
declare class StaticLengthFn {
36+
>StaticLengthFn : Symbol(StaticLengthFn, Decl(decl.d.ts, 16, 1))
37+
38+
static length(): number; // ok
39+
>length : Symbol(StaticLengthFn.length, Decl(decl.d.ts, 18, 30))
40+
41+
length(): number; // ok
42+
>length : Symbol(StaticLengthFn.length, Decl(decl.d.ts, 19, 28))
43+
}
44+
45+
// prototype
46+
declare class StaticPrototype {
47+
>StaticPrototype : Symbol(StaticPrototype, Decl(decl.d.ts, 21, 1))
48+
49+
static prototype: number; // ok
50+
>prototype : Symbol(StaticPrototype.prototype, Decl(decl.d.ts, 24, 31))
51+
52+
prototype: string; // ok
53+
>prototype : Symbol(StaticPrototype.prototype, Decl(decl.d.ts, 25, 29))
54+
}
55+
56+
declare class StaticPrototypeFn {
57+
>StaticPrototypeFn : Symbol(StaticPrototypeFn, Decl(decl.d.ts, 27, 1))
58+
59+
static prototype: any; // ok
60+
>prototype : Symbol(StaticPrototypeFn.prototype, Decl(decl.d.ts, 29, 33))
61+
62+
prototype(): any; // ok
63+
>prototype : Symbol(StaticPrototypeFn.prototype, Decl(decl.d.ts, 30, 26))
64+
}
65+
66+
// caller
67+
declare class StaticCaller {
68+
>StaticCaller : Symbol(StaticCaller, Decl(decl.d.ts, 32, 1))
69+
70+
static caller: number; // ok
71+
>caller : Symbol(StaticCaller.caller, Decl(decl.d.ts, 35, 28))
72+
73+
caller: string; // ok
74+
>caller : Symbol(StaticCaller.caller, Decl(decl.d.ts, 36, 26))
75+
}
76+
77+
declare class StaticCallerFn {
78+
>StaticCallerFn : Symbol(StaticCallerFn, Decl(decl.d.ts, 38, 1))
79+
80+
static caller(): any; // ok
81+
>caller : Symbol(StaticCallerFn.caller, Decl(decl.d.ts, 40, 30))
82+
83+
caller(): any; // ok
84+
>caller : Symbol(StaticCallerFn.caller, Decl(decl.d.ts, 41, 25))
85+
}
86+
87+
// arguments
88+
declare class StaticArguments {
89+
>StaticArguments : Symbol(StaticArguments, Decl(decl.d.ts, 43, 1))
90+
91+
static arguments: number; // ok
92+
>arguments : Symbol(StaticArguments.arguments, Decl(decl.d.ts, 46, 31))
93+
94+
arguments: string; // ok
95+
>arguments : Symbol(StaticArguments.arguments, Decl(decl.d.ts, 47, 29))
96+
}
97+
98+
declare class StaticArgumentsFn {
99+
>StaticArgumentsFn : Symbol(StaticArgumentsFn, Decl(decl.d.ts, 49, 1))
100+
101+
static arguments(): any; // ok
102+
>arguments : Symbol(StaticArgumentsFn.arguments, Decl(decl.d.ts, 51, 33))
103+
104+
arguments(): any; // ok
105+
>arguments : Symbol(StaticArgumentsFn.arguments, Decl(decl.d.ts, 52, 28))
106+
}
107+
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
=== tests/cases/conformance/classes/propertyMemberDeclarations/decl.d.ts ===
2+
3+
// name
4+
declare class StaticName {
5+
>StaticName : StaticName
6+
7+
static name: number; // ok
8+
>name : number
9+
10+
name: string; // ok
11+
>name : string
12+
}
13+
14+
declare class StaticNameFn {
15+
>StaticNameFn : StaticNameFn
16+
17+
static name(): string; // ok
18+
>name : () => string
19+
20+
name(): string; // ok
21+
>name : () => string
22+
}
23+
24+
// length
25+
declare class StaticLength {
26+
>StaticLength : StaticLength
27+
28+
static length: number; // ok
29+
>length : number
30+
31+
length: string; // ok
32+
>length : string
33+
}
34+
35+
declare class StaticLengthFn {
36+
>StaticLengthFn : StaticLengthFn
37+
38+
static length(): number; // ok
39+
>length : () => number
40+
41+
length(): number; // ok
42+
>length : () => number
43+
}
44+
45+
// prototype
46+
declare class StaticPrototype {
47+
>StaticPrototype : StaticPrototype
48+
49+
static prototype: number; // ok
50+
>prototype : StaticPrototype
51+
52+
prototype: string; // ok
53+
>prototype : string
54+
}
55+
56+
declare class StaticPrototypeFn {
57+
>StaticPrototypeFn : StaticPrototypeFn
58+
59+
static prototype: any; // ok
60+
>prototype : StaticPrototypeFn
61+
62+
prototype(): any; // ok
63+
>prototype : () => any
64+
}
65+
66+
// caller
67+
declare class StaticCaller {
68+
>StaticCaller : StaticCaller
69+
70+
static caller: number; // ok
71+
>caller : number
72+
73+
caller: string; // ok
74+
>caller : string
75+
}
76+
77+
declare class StaticCallerFn {
78+
>StaticCallerFn : StaticCallerFn
79+
80+
static caller(): any; // ok
81+
>caller : () => any
82+
83+
caller(): any; // ok
84+
>caller : () => any
85+
}
86+
87+
// arguments
88+
declare class StaticArguments {
89+
>StaticArguments : StaticArguments
90+
91+
static arguments: number; // ok
92+
>arguments : number
93+
94+
arguments: string; // ok
95+
>arguments : string
96+
}
97+
98+
declare class StaticArgumentsFn {
99+
>StaticArgumentsFn : StaticArgumentsFn
100+
101+
static arguments(): any; // ok
102+
>arguments : () => any
103+
104+
arguments(): any; // ok
105+
>arguments : () => any
106+
}
107+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
2+
//@Filename: decl.d.ts
3+
// name
4+
declare class StaticName {
5+
static name: number; // ok
6+
name: string; // ok
7+
}
8+
9+
declare class StaticNameFn {
10+
static name(): string; // ok
11+
name(): string; // ok
12+
}
13+
14+
// length
15+
declare class StaticLength {
16+
static length: number; // ok
17+
length: string; // ok
18+
}
19+
20+
declare class StaticLengthFn {
21+
static length(): number; // ok
22+
length(): number; // ok
23+
}
24+
25+
// prototype
26+
declare class StaticPrototype {
27+
static prototype: number; // ok
28+
prototype: string; // ok
29+
}
30+
31+
declare class StaticPrototypeFn {
32+
static prototype: any; // ok
33+
prototype(): any; // ok
34+
}
35+
36+
// caller
37+
declare class StaticCaller {
38+
static caller: number; // ok
39+
caller: string; // ok
40+
}
41+
42+
declare class StaticCallerFn {
43+
static caller(): any; // ok
44+
caller(): any; // ok
45+
}
46+
47+
// arguments
48+
declare class StaticArguments {
49+
static arguments: number; // ok
50+
arguments: string; // ok
51+
}
52+
53+
declare class StaticArgumentsFn {
54+
static arguments(): any; // ok
55+
arguments(): any; // ok
56+
}

0 commit comments

Comments
 (0)