Skip to content

Add error for using generalized expressions with export assignments in ambient contexts #18444

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 14, 2017
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
4 changes: 4 additions & 0 deletions src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22311,6 +22311,10 @@ namespace ts {

checkExternalModuleExports(container);

if (isInAmbientContext(node) && !isEntityNameExpression(node.expression)) {
grammarErrorOnNode(node.expression, Diagnostics.The_expression_of_an_export_assignment_must_be_an_identifier_or_qualified_name_in_an_ambient_context);
}

if (node.isExportEquals && !isInAmbientContext(node)) {
if (modulekind >= ModuleKind.ES2015) {
// export assignment is not supported in es6 modules
Expand Down
4 changes: 4 additions & 0 deletions src/compiler/diagnosticMessages.json
Original file line number Diff line number Diff line change
Expand Up @@ -2212,6 +2212,10 @@
"category": "Error",
"code": 2713
},
"The expression of an export assignment must be an identifier or qualified name in an ambient context.": {
"category": "Error",
"code": 2714
},

"Import declaration '{0}' is using private name '{1}'.": {
"category": "Error",
Expand Down
41 changes: 41 additions & 0 deletions tests/baselines/reference/ambientExportDefaultErrors.errors.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
tests/cases/compiler/foo.d.ts(1,16): error TS2714: The expression of an export assignment must be an identifier or qualified name in an ambient context.
tests/cases/compiler/foo2.d.ts(1,10): error TS2714: The expression of an export assignment must be an identifier or qualified name in an ambient context.
tests/cases/compiler/indirection.d.ts(3,20): error TS2714: The expression of an export assignment must be an identifier or qualified name in an ambient context.
tests/cases/compiler/indirection2.d.ts(3,14): error TS2714: The expression of an export assignment must be an identifier or qualified name in an ambient context.


==== tests/cases/compiler/consumer.ts (0 errors) ====
/// <reference path="./indirection.d.ts" />
/// <reference path="./indirection2.d.ts" />
import "indirect";
import "foo";
import "indirect2";
import "foo2";
==== tests/cases/compiler/foo.d.ts (1 errors) ====
export default 2 + 2;
~~~~~
!!! error TS2714: The expression of an export assignment must be an identifier or qualified name in an ambient context.
export as namespace Foo;

==== tests/cases/compiler/foo2.d.ts (1 errors) ====
export = 2 + 2;
~~~~~
!!! error TS2714: The expression of an export assignment must be an identifier or qualified name in an ambient context.
export as namespace Foo2;

==== tests/cases/compiler/indirection.d.ts (1 errors) ====
/// <reference path="./foo.d.ts" />
declare module "indirect" {
export default typeof Foo.default;
~~~~~~~~~~~~~~~~~~
!!! error TS2714: The expression of an export assignment must be an identifier or qualified name in an ambient context.
}

==== tests/cases/compiler/indirection2.d.ts (1 errors) ====
/// <reference path="./foo2.d.ts" />
declare module "indirect2" {
export = typeof Foo2;
~~~~~~~~~~~
!!! error TS2714: The expression of an export assignment must be an identifier or qualified name in an ambient context.
}

39 changes: 39 additions & 0 deletions tests/baselines/reference/ambientExportDefaultErrors.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
//// [tests/cases/compiler/ambientExportDefaultErrors.ts] ////

//// [foo.d.ts]
export default 2 + 2;
export as namespace Foo;

//// [foo2.d.ts]
export = 2 + 2;
export as namespace Foo2;

//// [indirection.d.ts]
/// <reference path="./foo.d.ts" />
declare module "indirect" {
export default typeof Foo.default;
}

//// [indirection2.d.ts]
/// <reference path="./foo2.d.ts" />
declare module "indirect2" {
export = typeof Foo2;
}

//// [consumer.ts]
/// <reference path="./indirection.d.ts" />
/// <reference path="./indirection2.d.ts" />
import "indirect";
import "foo";
import "indirect2";
import "foo2";

//// [consumer.js]
"use strict";
exports.__esModule = true;
/// <reference path="./indirection.d.ts" />
/// <reference path="./indirection2.d.ts" />
require("indirect");
require("foo");
require("indirect2");
require("foo2");
4 changes: 3 additions & 1 deletion tests/baselines/reference/es5-commonjs7.symbols
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
=== tests/cases/compiler/test.d.ts ===
export default "test";
export default undefined;
>undefined : Symbol(default)

export var __esModule;
>__esModule : Symbol(__esModule, Decl(test.d.ts, 1, 10))

4 changes: 3 additions & 1 deletion tests/baselines/reference/es5-commonjs7.types
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
=== tests/cases/compiler/test.d.ts ===
export default "test";
export default undefined;
>undefined : undefined

export var __esModule;
>__esModule : any

2 changes: 1 addition & 1 deletion tests/baselines/reference/typeAliasExport.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//// [typeAliasExport.ts]
declare module "a" {
export default 0
export default undefined
export var a;
export type a = typeof a;
}
Expand Down
4 changes: 3 additions & 1 deletion tests/baselines/reference/typeAliasExport.symbols
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
=== tests/cases/compiler/typeAliasExport.ts ===
declare module "a" {
export default 0
export default undefined
>undefined : Symbol(default)

export var a;
>a : Symbol(a, Decl(typeAliasExport.ts, 2, 12), Decl(typeAliasExport.ts, 2, 15))

Expand Down
4 changes: 3 additions & 1 deletion tests/baselines/reference/typeAliasExport.types
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
=== tests/cases/compiler/typeAliasExport.ts ===
declare module "a" {
export default 0
export default undefined
>undefined : undefined

export var a;
>a : any

Expand Down
27 changes: 27 additions & 0 deletions tests/cases/compiler/ambientExportDefaultErrors.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// @filename: foo.d.ts
export default 2 + 2;
export as namespace Foo;

// @filename: foo2.d.ts
export = 2 + 2;
export as namespace Foo2;

// @filename: indirection.d.ts
/// <reference path="./foo.d.ts" />
declare module "indirect" {
export default typeof Foo.default;
}

// @filename: indirection2.d.ts
/// <reference path="./foo2.d.ts" />
declare module "indirect2" {
export = typeof Foo2;
}

// @filename: consumer.ts
/// <reference path="./indirection.d.ts" />
/// <reference path="./indirection2.d.ts" />
import "indirect";
import "foo";
import "indirect2";
import "foo2";
2 changes: 1 addition & 1 deletion tests/cases/compiler/es5-commonjs7.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@
// @module: commonjs

// @filename: test.d.ts
export default "test";
export default undefined;
export var __esModule;
2 changes: 1 addition & 1 deletion tests/cases/compiler/typeAliasExport.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
declare module "a" {
export default 0
export default undefined
export var a;
export type a = typeof a;
}