mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-10 21:07:52 -05:00
Add error for using generalized expressions with export assignments in ambient contexts (#18444)
This commit is contained in:
@@ -22345,6 +22345,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
|
||||
|
||||
@@ -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",
|
||||
|
||||
@@ -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
tests/baselines/reference/ambientExportDefaultErrors.js
Normal file
39
tests/baselines/reference/ambientExportDefaultErrors.js
Normal file
@@ -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");
|
||||
@@ -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))
|
||||
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
=== tests/cases/compiler/test.d.ts ===
|
||||
export default "test";
|
||||
export default undefined;
|
||||
>undefined : undefined
|
||||
|
||||
export var __esModule;
|
||||
>__esModule : any
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
//// [typeAliasExport.ts]
|
||||
declare module "a" {
|
||||
export default 0
|
||||
export default undefined
|
||||
export var a;
|
||||
export type a = typeof a;
|
||||
}
|
||||
|
||||
@@ -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))
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
27
tests/cases/compiler/ambientExportDefaultErrors.ts
Normal file
27
tests/cases/compiler/ambientExportDefaultErrors.ts
Normal file
@@ -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";
|
||||
@@ -4,5 +4,5 @@
|
||||
// @module: commonjs
|
||||
|
||||
// @filename: test.d.ts
|
||||
export default "test";
|
||||
export default undefined;
|
||||
export var __esModule;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
declare module "a" {
|
||||
export default 0
|
||||
export default undefined
|
||||
export var a;
|
||||
export type a = typeof a;
|
||||
}
|
||||
Reference in New Issue
Block a user