Skip to content

Commit b227cf0

Browse files
authored
Merge pull request #11119 from YuichiNukiyama/defult_export_error_message
Change error message for default export in namespace
2 parents 4e4892a + ec72ad6 commit b227cf0

File tree

5 files changed

+52
-1
lines changed

5 files changed

+52
-1
lines changed

src/compiler/checker.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19107,7 +19107,13 @@ namespace ts {
1910719107

1910819108
const container = node.parent.kind === SyntaxKind.SourceFile ? <SourceFile>node.parent : <ModuleDeclaration>node.parent.parent;
1910919109
if (container.kind === SyntaxKind.ModuleDeclaration && !isAmbientModule(container)) {
19110-
error(node, Diagnostics.An_export_assignment_cannot_be_used_in_a_namespace);
19110+
if (node.isExportEquals) {
19111+
error(node, Diagnostics.An_export_assignment_cannot_be_used_in_a_namespace);
19112+
}
19113+
else {
19114+
error(node, Diagnostics.A_default_export_can_only_be_used_in_an_ECMAScript_style_module);
19115+
}
19116+
1911119117
return;
1911219118
}
1911319119
// Grammar checking

src/compiler/diagnosticMessages.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -855,6 +855,10 @@
855855
"category": "Error",
856856
"code": 1318
857857
},
858+
"A default export can only be used in an ECMAScript-style module.": {
859+
"category": "Error",
860+
"code": 1319
861+
},
858862
"Duplicate identifier '{0}'.": {
859863
"category": "Error",
860864
"code": 2300
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
tests/cases/conformance/parser/ecmascript5/ExportAssignments/parserExportAssignment9.ts(2,3): error TS1319: A default export can only be used in an ECMAScript-style module.
2+
tests/cases/conformance/parser/ecmascript5/ExportAssignments/parserExportAssignment9.ts(6,3): error TS1319: A default export can only be used in an ECMAScript-style module.
3+
4+
5+
==== tests/cases/conformance/parser/ecmascript5/ExportAssignments/parserExportAssignment9.ts (2 errors) ====
6+
namespace Foo {
7+
export default foo;
8+
~~~~~~~~~~~~~~~~~~~
9+
!!! error TS1319: A default export can only be used in an ECMAScript-style module.
10+
}
11+
12+
module Bar {
13+
export default bar;
14+
~~~~~~~~~~~~~~~~~~~
15+
!!! error TS1319: A default export can only be used in an ECMAScript-style module.
16+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
//// [parserExportAssignment9.ts]
2+
namespace Foo {
3+
export default foo;
4+
}
5+
6+
module Bar {
7+
export default bar;
8+
}
9+
10+
//// [parserExportAssignment9.js]
11+
var Foo;
12+
(function (Foo) {
13+
export default foo;
14+
})(Foo || (Foo = {}));
15+
var Bar;
16+
(function (Bar) {
17+
export default bar;
18+
})(Bar || (Bar = {}));
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
namespace Foo {
2+
export default foo;
3+
}
4+
5+
module Bar {
6+
export default bar;
7+
}

0 commit comments

Comments
 (0)