Skip to content

Commit 64f3798

Browse files
committed
Merge pull request #2935 from Microsoft/relaxExportEqualsCheck
Fix #2929: relax the check for export= in ES6 if it is resulting from an ambient declaration
2 parents 5eefc42 + 992bbff commit 64f3798

23 files changed

+295
-1
lines changed

src/compiler/checker.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10681,7 +10681,7 @@ module ts {
1068110681
}
1068210682
checkExternalModuleExports(container);
1068310683

10684-
if (node.isExportEquals) {
10684+
if (node.isExportEquals && !isInAmbientContext(node)) {
1068510685
if (languageVersion >= ScriptTarget.ES6) {
1068610686
// export assignment is deprecated in es6 or above
1068710687
grammarErrorOnNode(node, Diagnostics.Export_assignment_cannot_be_used_when_targeting_ECMAScript_6_or_higher_Consider_using_export_default_instead);
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
tests/cases/compiler/a.ts(3,1): error TS1203: Export assignment cannot be used when targeting ECMAScript 6 or higher. Consider using 'export default' instead.
2+
3+
4+
==== tests/cases/compiler/a.ts (1 errors) ====
5+
6+
var a = 10;
7+
export = a; // Error: export = not allowed in ES6
8+
~~~~~~~~~~~
9+
!!! error TS1203: Export assignment cannot be used when targeting ECMAScript 6 or higher. Consider using 'export default' instead.
10+
11+
==== tests/cases/compiler/b.ts (0 errors) ====
12+
import * as a from "a";
13+
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
//// [tests/cases/compiler/es6ExportAssignment2.ts] ////
2+
3+
//// [a.ts]
4+
5+
var a = 10;
6+
export = a; // Error: export = not allowed in ES6
7+
8+
//// [b.ts]
9+
import * as a from "a";
10+
11+
12+
//// [a.js]
13+
var a = 10;
14+
//// [b.js]
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
//// [tests/cases/compiler/es6ExportAssignment3.ts] ////
2+
3+
//// [a.d.ts]
4+
5+
declare var a: number;
6+
export = a; // OK, in ambient context
7+
8+
//// [b.ts]
9+
import * as a from "a";
10+
11+
12+
//// [b.js]
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
=== tests/cases/compiler/a.d.ts ===
2+
3+
declare var a: number;
4+
>a : Symbol(a, Decl(a.d.ts, 1, 11))
5+
6+
export = a; // OK, in ambient context
7+
>a : Symbol(a, Decl(a.d.ts, 1, 11))
8+
9+
=== tests/cases/compiler/b.ts ===
10+
import * as a from "a";
11+
>a : Symbol(a, Decl(b.ts, 0, 6))
12+
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
=== tests/cases/compiler/a.d.ts ===
2+
3+
declare var a: number;
4+
>a : number
5+
6+
export = a; // OK, in ambient context
7+
>a : number
8+
9+
=== tests/cases/compiler/b.ts ===
10+
import * as a from "a";
11+
>a : number
12+
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
//// [tests/cases/compiler/es6ExportAssignment4.ts] ////
2+
3+
//// [modules.d.ts]
4+
5+
declare module "a" {
6+
var a: number;
7+
export = a; // OK, in ambient context
8+
}
9+
10+
//// [b.ts]
11+
import * as a from "a";
12+
13+
14+
//// [b.js]
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
=== tests/cases/compiler/modules.d.ts ===
2+
3+
declare module "a" {
4+
var a: number;
5+
>a : Symbol(a, Decl(modules.d.ts, 2, 7))
6+
7+
export = a; // OK, in ambient context
8+
>a : Symbol(a, Decl(modules.d.ts, 2, 7))
9+
}
10+
11+
=== tests/cases/compiler/b.ts ===
12+
import * as a from "a";
13+
>a : Symbol(a, Decl(b.ts, 0, 6))
14+
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
=== tests/cases/compiler/modules.d.ts ===
2+
3+
declare module "a" {
4+
var a: number;
5+
>a : number
6+
7+
export = a; // OK, in ambient context
8+
>a : number
9+
}
10+
11+
=== tests/cases/compiler/b.ts ===
12+
import * as a from "a";
13+
>a : number
14+
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
//// [tests/cases/compiler/systemExportAssignment.ts] ////
2+
3+
//// [a.d.ts]
4+
5+
declare var a: number;
6+
export = a; // OK, in ambient context
7+
8+
//// [b.ts]
9+
import * as a from "a";
10+
11+
12+
//// [b.js]
13+
System.register([], function(exports_1) {
14+
return {
15+
setters:[],
16+
execute: function() {
17+
}
18+
}
19+
});

0 commit comments

Comments
 (0)