Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19062,7 +19062,13 @@ namespace ts {

const container = node.parent.kind === SyntaxKind.SourceFile ? <SourceFile>node.parent : <ModuleDeclaration>node.parent.parent;
if (container.kind === SyntaxKind.ModuleDeclaration && !isAmbientModule(container)) {
error(node, Diagnostics.An_export_assignment_cannot_be_used_in_a_namespace);
if (node.isExportEquals) {
error(node, Diagnostics.An_export_assignment_cannot_be_used_in_a_namespace);
}
else {
error(node, Diagnostics.A_default_export_can_only_be_used_in_an_ECMAScript_style_module);
}

return;
}
// Grammar checking
Expand Down
4 changes: 4 additions & 0 deletions src/compiler/diagnosticMessages.json
Original file line number Diff line number Diff line change
Expand Up @@ -855,6 +855,10 @@
"category": "Error",
"code": 1318
},
"A default export can only be used in an ECMAScript-style module.": {
"category": "Error",
"code": 1319
},
"Duplicate identifier '{0}'.": {
"category": "Error",
"code": 2300
Expand Down
16 changes: 16 additions & 0 deletions tests/baselines/reference/parserExportAssignment9.errors.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
tests/cases/conformance/parser/ecmascript5/ExportAssignments/parserExportAssignment9.ts(2,3): error TS1319: A default export can only be used in an ECMAScript-style module.
tests/cases/conformance/parser/ecmascript5/ExportAssignments/parserExportAssignment9.ts(6,3): error TS1319: A default export can only be used in an ECMAScript-style module.


==== tests/cases/conformance/parser/ecmascript5/ExportAssignments/parserExportAssignment9.ts (2 errors) ====
namespace Foo {
export default foo;
~~~~~~~~~~~~~~~~~~~
!!! error TS1319: A default export can only be used in an ECMAScript-style module.
}

module Bar {
export default bar;
~~~~~~~~~~~~~~~~~~~
!!! error TS1319: A default export can only be used in an ECMAScript-style module.
}
18 changes: 18 additions & 0 deletions tests/baselines/reference/parserExportAssignment9.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
//// [parserExportAssignment9.ts]
namespace Foo {
export default foo;
}

module Bar {
export default bar;
}

//// [parserExportAssignment9.js]
var Foo;
(function (Foo) {
export default foo;
})(Foo || (Foo = {}));
var Bar;
(function (Bar) {
export default bar;
})(Bar || (Bar = {}));
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace Foo {
export default foo;
}

module Bar {
export default bar;
}