Skip to content

Commit a0782d9

Browse files
committed
fix error message with public class inside namespace
1 parent cd2638e commit a0782d9

9 files changed

+71
-71
lines changed

src/compiler/checker.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -16214,7 +16214,7 @@ namespace ts {
1621416214
return grammarErrorOnNode(modifier, Diagnostics._0_modifier_must_precede_1_modifier, text, "async");
1621516215
}
1621616216
else if (node.parent.kind === SyntaxKind.ModuleBlock || node.parent.kind === SyntaxKind.SourceFile) {
16217-
return grammarErrorOnNode(modifier, Diagnostics._0_modifier_cannot_appear_on_a_module_element, text);
16217+
return grammarErrorOnNode(modifier, Diagnostics._0_modifier_cannot_appear_on_a_module_or_namespace_element, text);
1621816218
}
1621916219
else if (flags & NodeFlags.Abstract) {
1622016220
if (modifier.kind === SyntaxKind.PrivateKeyword) {
@@ -16238,7 +16238,7 @@ namespace ts {
1623816238
return grammarErrorOnNode(modifier, Diagnostics._0_modifier_must_precede_1_modifier, "static", "async");
1623916239
}
1624016240
else if (node.parent.kind === SyntaxKind.ModuleBlock || node.parent.kind === SyntaxKind.SourceFile) {
16241-
return grammarErrorOnNode(modifier, Diagnostics._0_modifier_cannot_appear_on_a_module_element, "static");
16241+
return grammarErrorOnNode(modifier, Diagnostics._0_modifier_cannot_appear_on_a_module_or_namespace_element, "static");
1624216242
}
1624316243
else if (node.kind === SyntaxKind.Parameter) {
1624416244
return grammarErrorOnNode(modifier, Diagnostics._0_modifier_cannot_appear_on_a_parameter, "static");

src/compiler/diagnosticMessages.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@
123123
"category": "Error",
124124
"code": 1043
125125
},
126-
"'{0}' modifier cannot appear on a module element.": {
126+
"'{0}' modifier cannot appear on a module or namespace element.": {
127127
"category": "Error",
128128
"code": 1044
129129
},
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
tests/cases/conformance/parser/ecmascript5/Protected/Protected1.ts(1,1): error TS1044: 'protected' modifier cannot appear on a module element.
1+
tests/cases/conformance/parser/ecmascript5/Protected/Protected1.ts(1,1): error TS1044: 'protected' modifier cannot appear on a module or namespace element.
22

33

44
==== tests/cases/conformance/parser/ecmascript5/Protected/Protected1.ts (1 errors) ====
55
protected class C {
66
~~~~~~~~~
7-
!!! error TS1044: 'protected' modifier cannot appear on a module element.
7+
!!! error TS1044: 'protected' modifier cannot appear on a module or namespace element.
88
}
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
tests/cases/conformance/parser/ecmascript5/Protected/Protected2.ts(1,1): error TS1044: 'protected' modifier cannot appear on a module element.
1+
tests/cases/conformance/parser/ecmascript5/Protected/Protected2.ts(1,1): error TS1044: 'protected' modifier cannot appear on a module or namespace element.
22

33

44
==== tests/cases/conformance/parser/ecmascript5/Protected/Protected2.ts (1 errors) ====
55
protected module M {
66
~~~~~~~~~
7-
!!! error TS1044: 'protected' modifier cannot appear on a module element.
7+
!!! error TS1044: 'protected' modifier cannot appear on a module or namespace element.
88
}

tests/baselines/reference/importDeclWithClassModifiers.errors.txt

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
tests/cases/compiler/importDeclWithClassModifiers.ts(5,8): error TS1044: 'public' modifier cannot appear on a module element.
1+
tests/cases/compiler/importDeclWithClassModifiers.ts(5,8): error TS1044: 'public' modifier cannot appear on a module or namespace element.
22
tests/cases/compiler/importDeclWithClassModifiers.ts(5,28): error TS2305: Module 'x' has no exported member 'c'.
3-
tests/cases/compiler/importDeclWithClassModifiers.ts(6,8): error TS1044: 'private' modifier cannot appear on a module element.
3+
tests/cases/compiler/importDeclWithClassModifiers.ts(6,8): error TS1044: 'private' modifier cannot appear on a module or namespace element.
44
tests/cases/compiler/importDeclWithClassModifiers.ts(6,29): error TS2305: Module 'x' has no exported member 'c'.
5-
tests/cases/compiler/importDeclWithClassModifiers.ts(7,8): error TS1044: 'static' modifier cannot appear on a module element.
5+
tests/cases/compiler/importDeclWithClassModifiers.ts(7,8): error TS1044: 'static' modifier cannot appear on a module or namespace element.
66
tests/cases/compiler/importDeclWithClassModifiers.ts(7,28): error TS2305: Module 'x' has no exported member 'c'.
77

88

@@ -13,17 +13,17 @@ tests/cases/compiler/importDeclWithClassModifiers.ts(7,28): error TS2305: Module
1313
}
1414
export public import a = x.c;
1515
~~~~~~
16-
!!! error TS1044: 'public' modifier cannot appear on a module element.
16+
!!! error TS1044: 'public' modifier cannot appear on a module or namespace element.
1717
~
1818
!!! error TS2305: Module 'x' has no exported member 'c'.
1919
export private import b = x.c;
2020
~~~~~~~
21-
!!! error TS1044: 'private' modifier cannot appear on a module element.
21+
!!! error TS1044: 'private' modifier cannot appear on a module or namespace element.
2222
~
2323
!!! error TS2305: Module 'x' has no exported member 'c'.
2424
export static import c = x.c;
2525
~~~~~~
26-
!!! error TS1044: 'static' modifier cannot appear on a module element.
26+
!!! error TS1044: 'static' modifier cannot appear on a module or namespace element.
2727
~
2828
!!! error TS2305: Module 'x' has no exported member 'c'.
2929
var b: a;
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
1-
tests/cases/conformance/internalModules/moduleBody/invalidModuleWithStatementsOfEveryKind.ts(4,5): error TS1044: 'public' modifier cannot appear on a module element.
2-
tests/cases/conformance/internalModules/moduleBody/invalidModuleWithStatementsOfEveryKind.ts(6,5): error TS1044: 'public' modifier cannot appear on a module element.
3-
tests/cases/conformance/internalModules/moduleBody/invalidModuleWithStatementsOfEveryKind.ts(12,5): error TS1044: 'public' modifier cannot appear on a module element.
4-
tests/cases/conformance/internalModules/moduleBody/invalidModuleWithStatementsOfEveryKind.ts(13,5): error TS1044: 'public' modifier cannot appear on a module element.
5-
tests/cases/conformance/internalModules/moduleBody/invalidModuleWithStatementsOfEveryKind.ts(15,5): error TS1044: 'public' modifier cannot appear on a module element.
6-
tests/cases/conformance/internalModules/moduleBody/invalidModuleWithStatementsOfEveryKind.ts(19,5): error TS1044: 'public' modifier cannot appear on a module element.
7-
tests/cases/conformance/internalModules/moduleBody/invalidModuleWithStatementsOfEveryKind.ts(25,5): error TS1044: 'public' modifier cannot appear on a module element.
8-
tests/cases/conformance/internalModules/moduleBody/invalidModuleWithStatementsOfEveryKind.ts(29,5): error TS1044: 'private' modifier cannot appear on a module element.
9-
tests/cases/conformance/internalModules/moduleBody/invalidModuleWithStatementsOfEveryKind.ts(31,5): error TS1044: 'private' modifier cannot appear on a module element.
10-
tests/cases/conformance/internalModules/moduleBody/invalidModuleWithStatementsOfEveryKind.ts(37,5): error TS1044: 'private' modifier cannot appear on a module element.
11-
tests/cases/conformance/internalModules/moduleBody/invalidModuleWithStatementsOfEveryKind.ts(38,5): error TS1044: 'private' modifier cannot appear on a module element.
12-
tests/cases/conformance/internalModules/moduleBody/invalidModuleWithStatementsOfEveryKind.ts(40,5): error TS1044: 'private' modifier cannot appear on a module element.
13-
tests/cases/conformance/internalModules/moduleBody/invalidModuleWithStatementsOfEveryKind.ts(44,5): error TS1044: 'private' modifier cannot appear on a module element.
14-
tests/cases/conformance/internalModules/moduleBody/invalidModuleWithStatementsOfEveryKind.ts(50,5): error TS1044: 'private' modifier cannot appear on a module element.
15-
tests/cases/conformance/internalModules/moduleBody/invalidModuleWithStatementsOfEveryKind.ts(55,5): error TS1044: 'static' modifier cannot appear on a module element.
16-
tests/cases/conformance/internalModules/moduleBody/invalidModuleWithStatementsOfEveryKind.ts(57,5): error TS1044: 'static' modifier cannot appear on a module element.
17-
tests/cases/conformance/internalModules/moduleBody/invalidModuleWithStatementsOfEveryKind.ts(63,5): error TS1044: 'static' modifier cannot appear on a module element.
18-
tests/cases/conformance/internalModules/moduleBody/invalidModuleWithStatementsOfEveryKind.ts(64,5): error TS1044: 'static' modifier cannot appear on a module element.
19-
tests/cases/conformance/internalModules/moduleBody/invalidModuleWithStatementsOfEveryKind.ts(66,5): error TS1044: 'static' modifier cannot appear on a module element.
20-
tests/cases/conformance/internalModules/moduleBody/invalidModuleWithStatementsOfEveryKind.ts(70,5): error TS1044: 'static' modifier cannot appear on a module element.
21-
tests/cases/conformance/internalModules/moduleBody/invalidModuleWithStatementsOfEveryKind.ts(76,5): error TS1044: 'static' modifier cannot appear on a module element.
1+
tests/cases/conformance/internalModules/moduleBody/invalidModuleWithStatementsOfEveryKind.ts(4,5): error TS1044: 'public' modifier cannot appear on a module or namespace element.
2+
tests/cases/conformance/internalModules/moduleBody/invalidModuleWithStatementsOfEveryKind.ts(6,5): error TS1044: 'public' modifier cannot appear on a module or namespace element.
3+
tests/cases/conformance/internalModules/moduleBody/invalidModuleWithStatementsOfEveryKind.ts(12,5): error TS1044: 'public' modifier cannot appear on a module or namespace element.
4+
tests/cases/conformance/internalModules/moduleBody/invalidModuleWithStatementsOfEveryKind.ts(13,5): error TS1044: 'public' modifier cannot appear on a module or namespace element.
5+
tests/cases/conformance/internalModules/moduleBody/invalidModuleWithStatementsOfEveryKind.ts(15,5): error TS1044: 'public' modifier cannot appear on a module or namespace element.
6+
tests/cases/conformance/internalModules/moduleBody/invalidModuleWithStatementsOfEveryKind.ts(19,5): error TS1044: 'public' modifier cannot appear on a module or namespace element.
7+
tests/cases/conformance/internalModules/moduleBody/invalidModuleWithStatementsOfEveryKind.ts(25,5): error TS1044: 'public' modifier cannot appear on a module or namespace element.
8+
tests/cases/conformance/internalModules/moduleBody/invalidModuleWithStatementsOfEveryKind.ts(29,5): error TS1044: 'private' modifier cannot appear on a module or namespace element.
9+
tests/cases/conformance/internalModules/moduleBody/invalidModuleWithStatementsOfEveryKind.ts(31,5): error TS1044: 'private' modifier cannot appear on a module or namespace element.
10+
tests/cases/conformance/internalModules/moduleBody/invalidModuleWithStatementsOfEveryKind.ts(37,5): error TS1044: 'private' modifier cannot appear on a module or namespace element.
11+
tests/cases/conformance/internalModules/moduleBody/invalidModuleWithStatementsOfEveryKind.ts(38,5): error TS1044: 'private' modifier cannot appear on a module or namespace element.
12+
tests/cases/conformance/internalModules/moduleBody/invalidModuleWithStatementsOfEveryKind.ts(40,5): error TS1044: 'private' modifier cannot appear on a module or namespace element.
13+
tests/cases/conformance/internalModules/moduleBody/invalidModuleWithStatementsOfEveryKind.ts(44,5): error TS1044: 'private' modifier cannot appear on a module or namespace element.
14+
tests/cases/conformance/internalModules/moduleBody/invalidModuleWithStatementsOfEveryKind.ts(50,5): error TS1044: 'private' modifier cannot appear on a module or namespace element.
15+
tests/cases/conformance/internalModules/moduleBody/invalidModuleWithStatementsOfEveryKind.ts(55,5): error TS1044: 'static' modifier cannot appear on a module or namespace element.
16+
tests/cases/conformance/internalModules/moduleBody/invalidModuleWithStatementsOfEveryKind.ts(57,5): error TS1044: 'static' modifier cannot appear on a module or namespace element.
17+
tests/cases/conformance/internalModules/moduleBody/invalidModuleWithStatementsOfEveryKind.ts(63,5): error TS1044: 'static' modifier cannot appear on a module or namespace element.
18+
tests/cases/conformance/internalModules/moduleBody/invalidModuleWithStatementsOfEveryKind.ts(64,5): error TS1044: 'static' modifier cannot appear on a module or namespace element.
19+
tests/cases/conformance/internalModules/moduleBody/invalidModuleWithStatementsOfEveryKind.ts(66,5): error TS1044: 'static' modifier cannot appear on a module or namespace element.
20+
tests/cases/conformance/internalModules/moduleBody/invalidModuleWithStatementsOfEveryKind.ts(70,5): error TS1044: 'static' modifier cannot appear on a module or namespace element.
21+
tests/cases/conformance/internalModules/moduleBody/invalidModuleWithStatementsOfEveryKind.ts(76,5): error TS1044: 'static' modifier cannot appear on a module or namespace element.
2222

2323

2424
==== tests/cases/conformance/internalModules/moduleBody/invalidModuleWithStatementsOfEveryKind.ts (21 errors) ====
@@ -27,118 +27,118 @@ tests/cases/conformance/internalModules/moduleBody/invalidModuleWithStatementsOf
2727
module Y {
2828
public class A { s: string }
2929
~~~~~~
30-
!!! error TS1044: 'public' modifier cannot appear on a module element.
30+
!!! error TS1044: 'public' modifier cannot appear on a module or namespace element.
3131

3232
public class BB<T> extends A {
3333
~~~~~~
34-
!!! error TS1044: 'public' modifier cannot appear on a module element.
34+
!!! error TS1044: 'public' modifier cannot appear on a module or namespace element.
3535
id: number;
3636
}
3737
}
3838

3939
module Y2 {
4040
public class AA<T> { s: T }
4141
~~~~~~
42-
!!! error TS1044: 'public' modifier cannot appear on a module element.
42+
!!! error TS1044: 'public' modifier cannot appear on a module or namespace element.
4343
public interface I { id: number }
4444
~~~~~~
45-
!!! error TS1044: 'public' modifier cannot appear on a module element.
45+
!!! error TS1044: 'public' modifier cannot appear on a module or namespace element.
4646

4747
public class B extends AA<string> implements I { id: number }
4848
~~~~~~
49-
!!! error TS1044: 'public' modifier cannot appear on a module element.
49+
!!! error TS1044: 'public' modifier cannot appear on a module or namespace element.
5050
}
5151

5252
module Y3 {
5353
public module Module {
5454
~~~~~~
55-
!!! error TS1044: 'public' modifier cannot appear on a module element.
55+
!!! error TS1044: 'public' modifier cannot appear on a module or namespace element.
5656
class A { s: string }
5757
}
5858
}
5959

6060
module Y4 {
6161
public enum Color { Blue, Red }
6262
~~~~~~
63-
!!! error TS1044: 'public' modifier cannot appear on a module element.
63+
!!! error TS1044: 'public' modifier cannot appear on a module or namespace element.
6464
}
6565

6666
module YY {
6767
private class A { s: string }
6868
~~~~~~~
69-
!!! error TS1044: 'private' modifier cannot appear on a module element.
69+
!!! error TS1044: 'private' modifier cannot appear on a module or namespace element.
7070

7171
private class BB<T> extends A {
7272
~~~~~~~
73-
!!! error TS1044: 'private' modifier cannot appear on a module element.
73+
!!! error TS1044: 'private' modifier cannot appear on a module or namespace element.
7474
id: number;
7575
}
7676
}
7777

7878
module YY2 {
7979
private class AA<T> { s: T }
8080
~~~~~~~
81-
!!! error TS1044: 'private' modifier cannot appear on a module element.
81+
!!! error TS1044: 'private' modifier cannot appear on a module or namespace element.
8282
private interface I { id: number }
8383
~~~~~~~
84-
!!! error TS1044: 'private' modifier cannot appear on a module element.
84+
!!! error TS1044: 'private' modifier cannot appear on a module or namespace element.
8585

8686
private class B extends AA<string> implements I { id: number }
8787
~~~~~~~
88-
!!! error TS1044: 'private' modifier cannot appear on a module element.
88+
!!! error TS1044: 'private' modifier cannot appear on a module or namespace element.
8989
}
9090

9191
module YY3 {
9292
private module Module {
9393
~~~~~~~
94-
!!! error TS1044: 'private' modifier cannot appear on a module element.
94+
!!! error TS1044: 'private' modifier cannot appear on a module or namespace element.
9595
class A { s: string }
9696
}
9797
}
9898

9999
module YY4 {
100100
private enum Color { Blue, Red }
101101
~~~~~~~
102-
!!! error TS1044: 'private' modifier cannot appear on a module element.
102+
!!! error TS1044: 'private' modifier cannot appear on a module or namespace element.
103103
}
104104

105105

106106
module YYY {
107107
static class A { s: string }
108108
~~~~~~
109-
!!! error TS1044: 'static' modifier cannot appear on a module element.
109+
!!! error TS1044: 'static' modifier cannot appear on a module or namespace element.
110110

111111
static class BB<T> extends A {
112112
~~~~~~
113-
!!! error TS1044: 'static' modifier cannot appear on a module element.
113+
!!! error TS1044: 'static' modifier cannot appear on a module or namespace element.
114114
id: number;
115115
}
116116
}
117117

118118
module YYY2 {
119119
static class AA<T> { s: T }
120120
~~~~~~
121-
!!! error TS1044: 'static' modifier cannot appear on a module element.
121+
!!! error TS1044: 'static' modifier cannot appear on a module or namespace element.
122122
static interface I { id: number }
123123
~~~~~~
124-
!!! error TS1044: 'static' modifier cannot appear on a module element.
124+
!!! error TS1044: 'static' modifier cannot appear on a module or namespace element.
125125

126126
static class B extends AA<string> implements I { id: number }
127127
~~~~~~
128-
!!! error TS1044: 'static' modifier cannot appear on a module element.
128+
!!! error TS1044: 'static' modifier cannot appear on a module or namespace element.
129129
}
130130

131131
module YYY3 {
132132
static module Module {
133133
~~~~~~
134-
!!! error TS1044: 'static' modifier cannot appear on a module element.
134+
!!! error TS1044: 'static' modifier cannot appear on a module or namespace element.
135135
class A { s: string }
136136
}
137137
}
138138

139139
module YYY4 {
140140
static enum Color { Blue, Red }
141141
~~~~~~
142-
!!! error TS1044: 'static' modifier cannot appear on a module element.
142+
!!! error TS1044: 'static' modifier cannot appear on a module or namespace element.
143143
}
144144

0 commit comments

Comments
 (0)