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

Diff for: src/compiler/checker.ts

+1-1
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);
+13
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+

Diff for: tests/baselines/reference/es6ExportAssignment2.js

+14
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]

Diff for: tests/baselines/reference/es6ExportAssignment3.js

+12
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]
+12
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+

Diff for: tests/baselines/reference/es6ExportAssignment3.types

+12
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+

Diff for: tests/baselines/reference/es6ExportAssignment4.js

+14
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]
+14
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+

Diff for: tests/baselines/reference/es6ExportAssignment4.types

+14
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+

Diff for: tests/baselines/reference/systemExportAssignment.js

+19
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+
});
+12
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+
+12
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+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
tests/cases/compiler/a.ts(3,1): error TS1218: Export assignment is not supported when '--module' flag is 'system'.
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 TS1218: Export assignment is not supported when '--module' flag is 'system'.
10+
11+
==== tests/cases/compiler/b.ts (0 errors) ====
12+
import * as a from "a";
13+

Diff for: tests/baselines/reference/systemExportAssignment2.js

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
//// [tests/cases/compiler/systemExportAssignment2.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+
System.register([], function(exports_1) {
14+
var a;
15+
return {
16+
setters:[],
17+
execute: function() {
18+
a = 10;
19+
}
20+
}
21+
});
22+
//// [b.js]
23+
System.register([], function(exports_1) {
24+
return {
25+
setters:[],
26+
execute: function() {
27+
}
28+
}
29+
});

Diff for: tests/baselines/reference/systemExportAssignment3.js

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
//// [tests/cases/compiler/systemExportAssignment3.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]
15+
System.register([], function(exports_1) {
16+
return {
17+
setters:[],
18+
execute: function() {
19+
}
20+
}
21+
});
+14
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+
+14
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+

Diff for: tests/cases/compiler/es6ExportAssignment2.ts

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// @target: es6
2+
3+
// @filename: a.ts
4+
var a = 10;
5+
export = a; // Error: export = not allowed in ES6
6+
7+
// @filename: b.ts
8+
import * as a from "a";

Diff for: tests/cases/compiler/es6ExportAssignment3.ts

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// @target: es6
2+
3+
// @filename: a.d.ts
4+
declare var a: number;
5+
export = a; // OK, in ambient context
6+
7+
// @filename: b.ts
8+
import * as a from "a";

Diff for: tests/cases/compiler/es6ExportAssignment4.ts

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// @target: es6
2+
3+
// @filename: modules.d.ts
4+
declare module "a" {
5+
var a: number;
6+
export = a; // OK, in ambient context
7+
}
8+
9+
// @filename: b.ts
10+
import * as a from "a";

Diff for: tests/cases/compiler/systemExportAssignment.ts

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// @target: es5
2+
// @module: system
3+
4+
// @filename: a.d.ts
5+
declare var a: number;
6+
export = a; // OK, in ambient context
7+
8+
// @filename: b.ts
9+
import * as a from "a";

Diff for: tests/cases/compiler/systemExportAssignment2.ts

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// @target: es5
2+
// @module: system
3+
4+
// @filename: a.ts
5+
var a = 10;
6+
export = a; // Error: export = not allowed in ES6
7+
8+
// @filename: b.ts
9+
import * as a from "a";

Diff for: tests/cases/compiler/systemExportAssignment3.ts

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// @target: es5
2+
// @module: system
3+
4+
// @filename: modules.d.ts
5+
declare module "a" {
6+
var a: number;
7+
export = a; // OK, in ambient context
8+
}
9+
10+
// @filename: b.ts
11+
import * as a from "a";

0 commit comments

Comments
 (0)