Skip to content

Commit 52a5578

Browse files
committed
Add declaration file version of this test
1 parent 6aee14c commit 52a5578

3 files changed

Lines changed: 271 additions & 0 deletions

File tree

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
decl.d.ts(1,1): error TS1046: Top-level declarations in .d.ts files must start with either a 'declare' or 'export' modifier.
2+
decl.d.ts(3,17): error TS1294: This syntax is not allowed when 'erasableSyntaxOnly' is enabled.
3+
decl.d.ts(3,17): error TS2369: A parameter property is only allowed in a constructor implementation.
4+
5+
6+
==== decl.d.ts (3 errors) ====
7+
class MyClassErr {
8+
~~~~~
9+
!!! error TS1046: Top-level declarations in .d.ts files must start with either a 'declare' or 'export' modifier.
10+
// No parameter properties
11+
constructor(public foo: string);
12+
~~~~~~~~~~~~~~~~~~
13+
!!! error TS1294: This syntax is not allowed when 'erasableSyntaxOnly' is enabled.
14+
~~~~~~~~~~~~~~~~~~
15+
!!! error TS2369: A parameter property is only allowed in a constructor implementation.
16+
}
17+
18+
namespace IllegalBecauseInstantiated {
19+
export const m = 1;
20+
}
21+
22+
namespace AlsoIllegalBecauseInstantiated {
23+
class PrivateClass {
24+
25+
}
26+
}
27+
28+
enum NotLegalEnum {
29+
B = 1
30+
}
31+
32+
const enum NotLegalConstEnum {
33+
C = 2
34+
}
35+
36+
// No errors after this point
37+
class MyClassOk {
38+
// Not a parameter property, ok
39+
constructor(foo: string);
40+
}
41+
namespace NotInstantiated {
42+
export interface JustAType { }
43+
export type ATypeInANamespace = {};
44+
}
45+
declare namespace AmbientIsNotInstantiated {
46+
export const stillOk = 12;
47+
}
48+
49+
declare enum LegalEnum {
50+
A = 1
51+
}
52+
53+
declare namespace AmbientStuff {
54+
namespace Nested {
55+
export const stillOk = 12;
56+
}
57+
enum EnumInAmbientContext {
58+
B = 1
59+
}
60+
}
61+
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
//// [tests/cases/compiler/erasableSyntaxOnlyDeclaration.ts] ////
2+
3+
=== decl.d.ts ===
4+
class MyClassErr {
5+
>MyClassErr : Symbol(MyClassErr, Decl(decl.d.ts, 0, 0))
6+
7+
// No parameter properties
8+
constructor(public foo: string);
9+
>foo : Symbol(MyClassErr.foo, Decl(decl.d.ts, 2, 16))
10+
}
11+
12+
namespace IllegalBecauseInstantiated {
13+
>IllegalBecauseInstantiated : Symbol(IllegalBecauseInstantiated, Decl(decl.d.ts, 3, 1))
14+
15+
export const m = 1;
16+
>m : Symbol(m, Decl(decl.d.ts, 6, 16))
17+
}
18+
19+
namespace AlsoIllegalBecauseInstantiated {
20+
>AlsoIllegalBecauseInstantiated : Symbol(AlsoIllegalBecauseInstantiated, Decl(decl.d.ts, 7, 1))
21+
22+
class PrivateClass {
23+
>PrivateClass : Symbol(PrivateClass, Decl(decl.d.ts, 9, 42))
24+
25+
}
26+
}
27+
28+
enum NotLegalEnum {
29+
>NotLegalEnum : Symbol(NotLegalEnum, Decl(decl.d.ts, 13, 1))
30+
31+
B = 1
32+
>B : Symbol(NotLegalEnum.B, Decl(decl.d.ts, 15, 19))
33+
}
34+
35+
const enum NotLegalConstEnum {
36+
>NotLegalConstEnum : Symbol(NotLegalConstEnum, Decl(decl.d.ts, 17, 1))
37+
38+
C = 2
39+
>C : Symbol(NotLegalConstEnum.C, Decl(decl.d.ts, 19, 30))
40+
}
41+
42+
// No errors after this point
43+
class MyClassOk {
44+
>MyClassOk : Symbol(MyClassOk, Decl(decl.d.ts, 21, 1))
45+
46+
// Not a parameter property, ok
47+
constructor(foo: string);
48+
>foo : Symbol(foo, Decl(decl.d.ts, 26, 16))
49+
}
50+
namespace NotInstantiated {
51+
>NotInstantiated : Symbol(NotInstantiated, Decl(decl.d.ts, 27, 1))
52+
53+
export interface JustAType { }
54+
>JustAType : Symbol(JustAType, Decl(decl.d.ts, 28, 27))
55+
56+
export type ATypeInANamespace = {};
57+
>ATypeInANamespace : Symbol(ATypeInANamespace, Decl(decl.d.ts, 29, 34))
58+
}
59+
declare namespace AmbientIsNotInstantiated {
60+
>AmbientIsNotInstantiated : Symbol(AmbientIsNotInstantiated, Decl(decl.d.ts, 31, 1))
61+
62+
export const stillOk = 12;
63+
>stillOk : Symbol(stillOk, Decl(decl.d.ts, 33, 16))
64+
}
65+
66+
declare enum LegalEnum {
67+
>LegalEnum : Symbol(LegalEnum, Decl(decl.d.ts, 34, 1))
68+
69+
A = 1
70+
>A : Symbol(LegalEnum.A, Decl(decl.d.ts, 36, 24))
71+
}
72+
73+
declare namespace AmbientStuff {
74+
>AmbientStuff : Symbol(AmbientStuff, Decl(decl.d.ts, 38, 1))
75+
76+
namespace Nested {
77+
>Nested : Symbol(Nested, Decl(decl.d.ts, 40, 32))
78+
79+
export const stillOk = 12;
80+
>stillOk : Symbol(stillOk, Decl(decl.d.ts, 42, 20))
81+
}
82+
enum EnumInAmbientContext {
83+
>EnumInAmbientContext : Symbol(EnumInAmbientContext, Decl(decl.d.ts, 43, 5))
84+
85+
B = 1
86+
>B : Symbol(EnumInAmbientContext.B, Decl(decl.d.ts, 44, 31))
87+
}
88+
}
89+
Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
//// [tests/cases/compiler/erasableSyntaxOnlyDeclaration.ts] ////
2+
3+
=== decl.d.ts ===
4+
class MyClassErr {
5+
>MyClassErr : MyClassErr
6+
> : ^^^^^^^^^^
7+
8+
// No parameter properties
9+
constructor(public foo: string);
10+
>foo : string
11+
> : ^^^^^^
12+
}
13+
14+
namespace IllegalBecauseInstantiated {
15+
>IllegalBecauseInstantiated : typeof IllegalBecauseInstantiated
16+
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
17+
18+
export const m = 1;
19+
>m : 1
20+
> : ^
21+
>1 : 1
22+
> : ^
23+
}
24+
25+
namespace AlsoIllegalBecauseInstantiated {
26+
>AlsoIllegalBecauseInstantiated : typeof AlsoIllegalBecauseInstantiated
27+
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
28+
29+
class PrivateClass {
30+
>PrivateClass : PrivateClass
31+
> : ^^^^^^^^^^^^
32+
33+
}
34+
}
35+
36+
enum NotLegalEnum {
37+
>NotLegalEnum : NotLegalEnum
38+
> : ^^^^^^^^^^^^
39+
40+
B = 1
41+
>B : NotLegalEnum.B
42+
> : ^^^^^^^^^^^^^^
43+
>1 : 1
44+
> : ^
45+
}
46+
47+
const enum NotLegalConstEnum {
48+
>NotLegalConstEnum : NotLegalConstEnum
49+
> : ^^^^^^^^^^^^^^^^^
50+
51+
C = 2
52+
>C : NotLegalConstEnum.C
53+
> : ^^^^^^^^^^^^^^^^^^^
54+
>2 : 2
55+
> : ^
56+
}
57+
58+
// No errors after this point
59+
class MyClassOk {
60+
>MyClassOk : MyClassOk
61+
> : ^^^^^^^^^
62+
63+
// Not a parameter property, ok
64+
constructor(foo: string);
65+
>foo : string
66+
> : ^^^^^^
67+
}
68+
namespace NotInstantiated {
69+
export interface JustAType { }
70+
export type ATypeInANamespace = {};
71+
>ATypeInANamespace : ATypeInANamespace
72+
> : ^^^^^^^^^^^^^^^^^
73+
}
74+
declare namespace AmbientIsNotInstantiated {
75+
>AmbientIsNotInstantiated : typeof AmbientIsNotInstantiated
76+
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
77+
78+
export const stillOk = 12;
79+
>stillOk : 12
80+
> : ^^
81+
>12 : 12
82+
> : ^^
83+
}
84+
85+
declare enum LegalEnum {
86+
>LegalEnum : LegalEnum
87+
> : ^^^^^^^^^
88+
89+
A = 1
90+
>A : LegalEnum.A
91+
> : ^^^^^^^^^^^
92+
>1 : 1
93+
> : ^
94+
}
95+
96+
declare namespace AmbientStuff {
97+
>AmbientStuff : typeof AmbientStuff
98+
> : ^^^^^^^^^^^^^^^^^^^
99+
100+
namespace Nested {
101+
>Nested : typeof Nested
102+
> : ^^^^^^^^^^^^^
103+
104+
export const stillOk = 12;
105+
>stillOk : 12
106+
> : ^^
107+
>12 : 12
108+
> : ^^
109+
}
110+
enum EnumInAmbientContext {
111+
>EnumInAmbientContext : EnumInAmbientContext
112+
> : ^^^^^^^^^^^^^^^^^^^^
113+
114+
B = 1
115+
>B : EnumInAmbientContext.B
116+
> : ^^^^^^^^^^^^^^^^^^^^^^
117+
>1 : 1
118+
> : ^
119+
}
120+
}
121+

0 commit comments

Comments
 (0)