report errors when re-exporting globals
This commit is contained in:
parent
d267d645d2
commit
b811b9f94b
|
@ -14364,7 +14364,16 @@ namespace ts {
|
|||
function checkExportSpecifier(node: ExportSpecifier) {
|
||||
checkAliasSymbol(node);
|
||||
if (!(<ExportDeclaration>node.parent.parent).moduleSpecifier) {
|
||||
markExportAsReferenced(node);
|
||||
const exportedName = node.propertyName || node.name;
|
||||
// find immediate value referenced by exported name (SymbolFlags.Alias is set so we don't chase down aliases)
|
||||
const symbol = resolveName(exportedName, exportedName.text, SymbolFlags.Value | SymbolFlags.Type | SymbolFlags.Namespace | SymbolFlags.Alias,
|
||||
/*nameNotFoundMessage*/ undefined, /*nameArg*/ undefined);
|
||||
if (symbol && isGlobalSourceFile(getDeclarationContainer(symbol.declarations[0]))) {
|
||||
error(exportedName, Diagnostics.Cannot_re_export_name_that_is_not_defined_in_the_module);
|
||||
}
|
||||
else {
|
||||
markExportAsReferenced(node);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1771,6 +1771,10 @@
|
|||
"category": "Error",
|
||||
"code": 2660
|
||||
},
|
||||
"Cannot re-export name that is not defined in the module.": {
|
||||
"category": "Error",
|
||||
"code": 2661
|
||||
},
|
||||
"Import declaration '{0}' is using private name '{1}'.": {
|
||||
"category": "Error",
|
||||
"code": 4000
|
||||
|
|
|
@ -0,0 +1,16 @@
|
|||
tests/cases/compiler/b.ts(1,9): error TS2661: Cannot re-export name that is not defined in the module.
|
||||
|
||||
|
||||
==== tests/cases/compiler/a.d.ts (0 errors) ====
|
||||
|
||||
declare class X { }
|
||||
|
||||
==== tests/cases/compiler/b.ts (1 errors) ====
|
||||
export {X};
|
||||
~
|
||||
!!! error TS2661: Cannot re-export name that is not defined in the module.
|
||||
export function f() {
|
||||
var x: X;
|
||||
return x;
|
||||
}
|
||||
|
|
@ -1,20 +0,0 @@
|
|||
=== tests/cases/compiler/a.d.ts ===
|
||||
|
||||
declare class X { }
|
||||
>X : Symbol(X, Decl(a.d.ts, 0, 0))
|
||||
|
||||
=== tests/cases/compiler/b.ts ===
|
||||
export {X};
|
||||
>X : Symbol(X, Decl(b.ts, 0, 8))
|
||||
|
||||
export function f() {
|
||||
>f : Symbol(f, Decl(b.ts, 0, 11))
|
||||
|
||||
var x: X;
|
||||
>x : Symbol(x, Decl(b.ts, 2, 7))
|
||||
>X : Symbol(X, Decl(a.d.ts, 0, 0))
|
||||
|
||||
return x;
|
||||
>x : Symbol(x, Decl(b.ts, 2, 7))
|
||||
}
|
||||
|
|
@ -1,20 +0,0 @@
|
|||
=== tests/cases/compiler/a.d.ts ===
|
||||
|
||||
declare class X { }
|
||||
>X : X
|
||||
|
||||
=== tests/cases/compiler/b.ts ===
|
||||
export {X};
|
||||
>X : typeof X
|
||||
|
||||
export function f() {
|
||||
>f : () => X
|
||||
|
||||
var x: X;
|
||||
>x : X
|
||||
>X : X
|
||||
|
||||
return x;
|
||||
>x : X
|
||||
}
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
tests/cases/compiler/exportSpecifierReferencingOuterDeclaration1.ts(3,14): error TS2661: Cannot re-export name that is not defined in the module.
|
||||
|
||||
|
||||
==== tests/cases/compiler/exportSpecifierReferencingOuterDeclaration1.ts (1 errors) ====
|
||||
declare module X { export interface bar { } }
|
||||
declare module "m" {
|
||||
export { X };
|
||||
~
|
||||
!!! error TS2661: Cannot re-export name that is not defined in the module.
|
||||
export function foo(): X.bar;
|
||||
}
|
|
@ -1,14 +0,0 @@
|
|||
=== tests/cases/compiler/exportSpecifierReferencingOuterDeclaration1.ts ===
|
||||
declare module X { export interface bar { } }
|
||||
>X : Symbol(X, Decl(exportSpecifierReferencingOuterDeclaration1.ts, 0, 0))
|
||||
>bar : Symbol(bar, Decl(exportSpecifierReferencingOuterDeclaration1.ts, 0, 18))
|
||||
|
||||
declare module "m" {
|
||||
export { X };
|
||||
>X : Symbol(X, Decl(exportSpecifierReferencingOuterDeclaration1.ts, 2, 12))
|
||||
|
||||
export function foo(): X.bar;
|
||||
>foo : Symbol(foo, Decl(exportSpecifierReferencingOuterDeclaration1.ts, 2, 17))
|
||||
>X : Symbol(X, Decl(exportSpecifierReferencingOuterDeclaration1.ts, 0, 0))
|
||||
>bar : Symbol(X.bar, Decl(exportSpecifierReferencingOuterDeclaration1.ts, 0, 18))
|
||||
}
|
|
@ -1,14 +0,0 @@
|
|||
=== tests/cases/compiler/exportSpecifierReferencingOuterDeclaration1.ts ===
|
||||
declare module X { export interface bar { } }
|
||||
>X : any
|
||||
>bar : bar
|
||||
|
||||
declare module "m" {
|
||||
export { X };
|
||||
>X : any
|
||||
|
||||
export function foo(): X.bar;
|
||||
>foo : () => X.bar
|
||||
>X : any
|
||||
>bar : X.bar
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
tests/cases/compiler/exportSpecifierReferencingOuterDeclaration2_B.ts(1,10): error TS2661: Cannot re-export name that is not defined in the module.
|
||||
|
||||
|
||||
==== tests/cases/compiler/exportSpecifierReferencingOuterDeclaration2_A.ts (0 errors) ====
|
||||
declare module X { export interface bar { } }
|
||||
|
||||
==== tests/cases/compiler/exportSpecifierReferencingOuterDeclaration2_B.ts (1 errors) ====
|
||||
export { X };
|
||||
~
|
||||
!!! error TS2661: Cannot re-export name that is not defined in the module.
|
||||
export declare function foo(): X.bar;
|
|
@ -1,14 +0,0 @@
|
|||
=== tests/cases/compiler/exportSpecifierReferencingOuterDeclaration2_A.ts ===
|
||||
declare module X { export interface bar { } }
|
||||
>X : Symbol(X, Decl(exportSpecifierReferencingOuterDeclaration2_A.ts, 0, 0))
|
||||
>bar : Symbol(bar, Decl(exportSpecifierReferencingOuterDeclaration2_A.ts, 0, 18))
|
||||
|
||||
=== tests/cases/compiler/exportSpecifierReferencingOuterDeclaration2_B.ts ===
|
||||
export { X };
|
||||
>X : Symbol(X, Decl(exportSpecifierReferencingOuterDeclaration2_B.ts, 0, 8))
|
||||
|
||||
export declare function foo(): X.bar;
|
||||
>foo : Symbol(foo, Decl(exportSpecifierReferencingOuterDeclaration2_B.ts, 0, 13))
|
||||
>X : Symbol(X, Decl(exportSpecifierReferencingOuterDeclaration2_A.ts, 0, 0))
|
||||
>bar : Symbol(X.bar, Decl(exportSpecifierReferencingOuterDeclaration2_A.ts, 0, 18))
|
||||
|
|
@ -1,14 +0,0 @@
|
|||
=== tests/cases/compiler/exportSpecifierReferencingOuterDeclaration2_A.ts ===
|
||||
declare module X { export interface bar { } }
|
||||
>X : any
|
||||
>bar : bar
|
||||
|
||||
=== tests/cases/compiler/exportSpecifierReferencingOuterDeclaration2_B.ts ===
|
||||
export { X };
|
||||
>X : any
|
||||
|
||||
export declare function foo(): X.bar;
|
||||
>foo : () => X.bar
|
||||
>X : any
|
||||
>bar : X.bar
|
||||
|
|
@ -0,0 +1,57 @@
|
|||
tests/cases/compiler/file2.ts(1,9): error TS2661: Cannot re-export name that is not defined in the module.
|
||||
tests/cases/compiler/file2.ts(1,12): error TS2661: Cannot re-export name that is not defined in the module.
|
||||
tests/cases/compiler/file2.ts(2,9): error TS2661: Cannot re-export name that is not defined in the module.
|
||||
tests/cases/compiler/file2.ts(2,13): error TS2661: Cannot re-export name that is not defined in the module.
|
||||
tests/cases/compiler/file2.ts(4,9): error TS2661: Cannot re-export name that is not defined in the module.
|
||||
tests/cases/compiler/file2.ts(4,12): error TS2661: Cannot re-export name that is not defined in the module.
|
||||
tests/cases/compiler/file2.ts(5,9): error TS2661: Cannot re-export name that is not defined in the module.
|
||||
tests/cases/compiler/file2.ts(5,12): error TS2661: Cannot re-export name that is not defined in the module.
|
||||
tests/cases/compiler/file2.ts(8,9): error TS2661: Cannot re-export name that is not defined in the module.
|
||||
tests/cases/compiler/file2.ts(9,9): error TS2661: Cannot re-export name that is not defined in the module.
|
||||
tests/cases/compiler/file2.ts(10,9): error TS2661: Cannot re-export name that is not defined in the module.
|
||||
tests/cases/compiler/file2.ts(11,9): error TS2661: Cannot re-export name that is not defined in the module.
|
||||
|
||||
|
||||
==== tests/cases/compiler/file1.d.ts (0 errors) ====
|
||||
|
||||
declare var x: number;
|
||||
declare var x1: number;
|
||||
declare let {a, b}: {a: number, b: number};
|
||||
|
||||
==== tests/cases/compiler/file2.ts (12 errors) ====
|
||||
export {x, x as y};
|
||||
~
|
||||
!!! error TS2661: Cannot re-export name that is not defined in the module.
|
||||
~
|
||||
!!! error TS2661: Cannot re-export name that is not defined in the module.
|
||||
export {x1, x1 as y1};
|
||||
~~
|
||||
!!! error TS2661: Cannot re-export name that is not defined in the module.
|
||||
~~
|
||||
!!! error TS2661: Cannot re-export name that is not defined in the module.
|
||||
|
||||
export {a, a as a1};
|
||||
~
|
||||
!!! error TS2661: Cannot re-export name that is not defined in the module.
|
||||
~
|
||||
!!! error TS2661: Cannot re-export name that is not defined in the module.
|
||||
export {b, b as b1};
|
||||
~
|
||||
!!! error TS2661: Cannot re-export name that is not defined in the module.
|
||||
~
|
||||
!!! error TS2661: Cannot re-export name that is not defined in the module.
|
||||
|
||||
|
||||
export {x as z};
|
||||
~
|
||||
!!! error TS2661: Cannot re-export name that is not defined in the module.
|
||||
export {x1 as z1};
|
||||
~~
|
||||
!!! error TS2661: Cannot re-export name that is not defined in the module.
|
||||
export {a as a2};
|
||||
~
|
||||
!!! error TS2661: Cannot re-export name that is not defined in the module.
|
||||
export {b as b2};
|
||||
~
|
||||
!!! error TS2661: Cannot re-export name that is not defined in the module.
|
||||
|
24
tests/baselines/reference/reExportGlobalDeclaration1.js
Normal file
24
tests/baselines/reference/reExportGlobalDeclaration1.js
Normal file
|
@ -0,0 +1,24 @@
|
|||
//// [tests/cases/compiler/reExportGlobalDeclaration1.ts] ////
|
||||
|
||||
//// [file1.d.ts]
|
||||
|
||||
declare var x: number;
|
||||
declare var x1: number;
|
||||
declare let {a, b}: {a: number, b: number};
|
||||
|
||||
//// [file2.ts]
|
||||
export {x, x as y};
|
||||
export {x1, x1 as y1};
|
||||
|
||||
export {a, a as a1};
|
||||
export {b, b as b1};
|
||||
|
||||
|
||||
export {x as z};
|
||||
export {x1 as z1};
|
||||
export {a as a2};
|
||||
export {b as b2};
|
||||
|
||||
|
||||
//// [file2.js]
|
||||
"use strict";
|
|
@ -0,0 +1,35 @@
|
|||
tests/cases/compiler/file2.ts(1,9): error TS2661: Cannot re-export name that is not defined in the module.
|
||||
tests/cases/compiler/file2.ts(1,13): error TS2661: Cannot re-export name that is not defined in the module.
|
||||
tests/cases/compiler/file2.ts(2,9): error TS2661: Cannot re-export name that is not defined in the module.
|
||||
tests/cases/compiler/file2.ts(2,13): error TS2661: Cannot re-export name that is not defined in the module.
|
||||
tests/cases/compiler/file2.ts(3,9): error TS2661: Cannot re-export name that is not defined in the module.
|
||||
tests/cases/compiler/file2.ts(4,9): error TS2661: Cannot re-export name that is not defined in the module.
|
||||
|
||||
|
||||
==== tests/cases/compiler/file1.d.ts (0 errors) ====
|
||||
|
||||
declare interface I1 {
|
||||
x: number
|
||||
}
|
||||
|
||||
declare interface I2 {
|
||||
x: number
|
||||
}
|
||||
|
||||
==== tests/cases/compiler/file2.ts (6 errors) ====
|
||||
export {I1, I1 as II1};
|
||||
~~
|
||||
!!! error TS2661: Cannot re-export name that is not defined in the module.
|
||||
~~
|
||||
!!! error TS2661: Cannot re-export name that is not defined in the module.
|
||||
export {I2, I2 as II2};
|
||||
~~
|
||||
!!! error TS2661: Cannot re-export name that is not defined in the module.
|
||||
~~
|
||||
!!! error TS2661: Cannot re-export name that is not defined in the module.
|
||||
export {I1 as III1};
|
||||
~~
|
||||
!!! error TS2661: Cannot re-export name that is not defined in the module.
|
||||
export {I2 as III2};
|
||||
~~
|
||||
!!! error TS2661: Cannot re-export name that is not defined in the module.
|
20
tests/baselines/reference/reExportGlobalDeclaration2.js
Normal file
20
tests/baselines/reference/reExportGlobalDeclaration2.js
Normal file
|
@ -0,0 +1,20 @@
|
|||
//// [tests/cases/compiler/reExportGlobalDeclaration2.ts] ////
|
||||
|
||||
//// [file1.d.ts]
|
||||
|
||||
declare interface I1 {
|
||||
x: number
|
||||
}
|
||||
|
||||
declare interface I2 {
|
||||
x: number
|
||||
}
|
||||
|
||||
//// [file2.ts]
|
||||
export {I1, I1 as II1};
|
||||
export {I2, I2 as II2};
|
||||
export {I1 as III1};
|
||||
export {I2 as III2};
|
||||
|
||||
//// [file2.js]
|
||||
"use strict";
|
|
@ -0,0 +1,35 @@
|
|||
tests/cases/compiler/file2.ts(1,9): error TS2661: Cannot re-export name that is not defined in the module.
|
||||
tests/cases/compiler/file2.ts(1,14): error TS2661: Cannot re-export name that is not defined in the module.
|
||||
tests/cases/compiler/file2.ts(2,9): error TS2661: Cannot re-export name that is not defined in the module.
|
||||
tests/cases/compiler/file2.ts(2,14): error TS2661: Cannot re-export name that is not defined in the module.
|
||||
tests/cases/compiler/file2.ts(3,9): error TS2661: Cannot re-export name that is not defined in the module.
|
||||
tests/cases/compiler/file2.ts(4,9): error TS2661: Cannot re-export name that is not defined in the module.
|
||||
|
||||
|
||||
==== tests/cases/compiler/file1.d.ts (0 errors) ====
|
||||
|
||||
declare namespace NS1 {
|
||||
export var foo: number;
|
||||
}
|
||||
|
||||
declare namespace NS2 {
|
||||
export var foo: number;
|
||||
}
|
||||
|
||||
==== tests/cases/compiler/file2.ts (6 errors) ====
|
||||
export {NS1, NS1 as NNS1};
|
||||
~~~
|
||||
!!! error TS2661: Cannot re-export name that is not defined in the module.
|
||||
~~~
|
||||
!!! error TS2661: Cannot re-export name that is not defined in the module.
|
||||
export {NS2, NS2 as NNS2};
|
||||
~~~
|
||||
!!! error TS2661: Cannot re-export name that is not defined in the module.
|
||||
~~~
|
||||
!!! error TS2661: Cannot re-export name that is not defined in the module.
|
||||
export {NS1 as NNNS1};
|
||||
~~~
|
||||
!!! error TS2661: Cannot re-export name that is not defined in the module.
|
||||
export {NS2 as NNNS2};
|
||||
~~~
|
||||
!!! error TS2661: Cannot re-export name that is not defined in the module.
|
20
tests/baselines/reference/reExportGlobalDeclaration3.js
Normal file
20
tests/baselines/reference/reExportGlobalDeclaration3.js
Normal file
|
@ -0,0 +1,20 @@
|
|||
//// [tests/cases/compiler/reExportGlobalDeclaration3.ts] ////
|
||||
|
||||
//// [file1.d.ts]
|
||||
|
||||
declare namespace NS1 {
|
||||
export var foo: number;
|
||||
}
|
||||
|
||||
declare namespace NS2 {
|
||||
export var foo: number;
|
||||
}
|
||||
|
||||
//// [file2.ts]
|
||||
export {NS1, NS1 as NNS1};
|
||||
export {NS2, NS2 as NNS2};
|
||||
export {NS1 as NNNS1};
|
||||
export {NS2 as NNNS2};
|
||||
|
||||
//// [file2.js]
|
||||
"use strict";
|
|
@ -0,0 +1,35 @@
|
|||
tests/cases/compiler/file2.ts(1,9): error TS2661: Cannot re-export name that is not defined in the module.
|
||||
tests/cases/compiler/file2.ts(1,15): error TS2661: Cannot re-export name that is not defined in the module.
|
||||
tests/cases/compiler/file2.ts(2,9): error TS2661: Cannot re-export name that is not defined in the module.
|
||||
tests/cases/compiler/file2.ts(2,15): error TS2661: Cannot re-export name that is not defined in the module.
|
||||
tests/cases/compiler/file2.ts(3,9): error TS2661: Cannot re-export name that is not defined in the module.
|
||||
tests/cases/compiler/file2.ts(4,9): error TS2661: Cannot re-export name that is not defined in the module.
|
||||
|
||||
|
||||
==== tests/cases/compiler/file1.d.ts (0 errors) ====
|
||||
|
||||
declare class Cls1 {
|
||||
x: number
|
||||
}
|
||||
declare class Cls2 {
|
||||
x: number
|
||||
}
|
||||
|
||||
|
||||
==== tests/cases/compiler/file2.ts (6 errors) ====
|
||||
export {Cls1, Cls1 as CCls1};
|
||||
~~~~
|
||||
!!! error TS2661: Cannot re-export name that is not defined in the module.
|
||||
~~~~
|
||||
!!! error TS2661: Cannot re-export name that is not defined in the module.
|
||||
export {Cls2, Cls2 as CCls2};
|
||||
~~~~
|
||||
!!! error TS2661: Cannot re-export name that is not defined in the module.
|
||||
~~~~
|
||||
!!! error TS2661: Cannot re-export name that is not defined in the module.
|
||||
export {Cls1 as CCCls1};
|
||||
~~~~
|
||||
!!! error TS2661: Cannot re-export name that is not defined in the module.
|
||||
export {Cls2 as CCCls2};
|
||||
~~~~
|
||||
!!! error TS2661: Cannot re-export name that is not defined in the module.
|
20
tests/baselines/reference/reExportGlobalDeclaration4.js
Normal file
20
tests/baselines/reference/reExportGlobalDeclaration4.js
Normal file
|
@ -0,0 +1,20 @@
|
|||
//// [tests/cases/compiler/reExportGlobalDeclaration4.ts] ////
|
||||
|
||||
//// [file1.d.ts]
|
||||
|
||||
declare class Cls1 {
|
||||
x: number
|
||||
}
|
||||
declare class Cls2 {
|
||||
x: number
|
||||
}
|
||||
|
||||
|
||||
//// [file2.ts]
|
||||
export {Cls1, Cls1 as CCls1};
|
||||
export {Cls2, Cls2 as CCls2};
|
||||
export {Cls1 as CCCls1};
|
||||
export {Cls2 as CCCls2};
|
||||
|
||||
//// [file2.js]
|
||||
"use strict";
|
19
tests/cases/compiler/reExportGlobalDeclaration1.ts
Normal file
19
tests/cases/compiler/reExportGlobalDeclaration1.ts
Normal file
|
@ -0,0 +1,19 @@
|
|||
// @module: commonjs
|
||||
|
||||
// @filename: file1.d.ts
|
||||
declare var x: number;
|
||||
declare var x1: number;
|
||||
declare let {a, b}: {a: number, b: number};
|
||||
|
||||
// @filename: file2.ts
|
||||
export {x, x as y};
|
||||
export {x1, x1 as y1};
|
||||
|
||||
export {a, a as a1};
|
||||
export {b, b as b1};
|
||||
|
||||
|
||||
export {x as z};
|
||||
export {x1 as z1};
|
||||
export {a as a2};
|
||||
export {b as b2};
|
16
tests/cases/compiler/reExportGlobalDeclaration2.ts
Normal file
16
tests/cases/compiler/reExportGlobalDeclaration2.ts
Normal file
|
@ -0,0 +1,16 @@
|
|||
// @module: commonjs
|
||||
|
||||
// @filename: file1.d.ts
|
||||
declare interface I1 {
|
||||
x: number
|
||||
}
|
||||
|
||||
declare interface I2 {
|
||||
x: number
|
||||
}
|
||||
|
||||
// @filename: file2.ts
|
||||
export {I1, I1 as II1};
|
||||
export {I2, I2 as II2};
|
||||
export {I1 as III1};
|
||||
export {I2 as III2};
|
16
tests/cases/compiler/reExportGlobalDeclaration3.ts
Normal file
16
tests/cases/compiler/reExportGlobalDeclaration3.ts
Normal file
|
@ -0,0 +1,16 @@
|
|||
// @module: commonjs
|
||||
|
||||
// @filename: file1.d.ts
|
||||
declare namespace NS1 {
|
||||
export var foo: number;
|
||||
}
|
||||
|
||||
declare namespace NS2 {
|
||||
export var foo: number;
|
||||
}
|
||||
|
||||
// @filename: file2.ts
|
||||
export {NS1, NS1 as NNS1};
|
||||
export {NS2, NS2 as NNS2};
|
||||
export {NS1 as NNNS1};
|
||||
export {NS2 as NNNS2};
|
16
tests/cases/compiler/reExportGlobalDeclaration4.ts
Normal file
16
tests/cases/compiler/reExportGlobalDeclaration4.ts
Normal file
|
@ -0,0 +1,16 @@
|
|||
// @module: commonjs
|
||||
|
||||
// @filename: file1.d.ts
|
||||
declare class Cls1 {
|
||||
x: number
|
||||
}
|
||||
declare class Cls2 {
|
||||
x: number
|
||||
}
|
||||
|
||||
|
||||
// @filename: file2.ts
|
||||
export {Cls1, Cls1 as CCls1};
|
||||
export {Cls2, Cls2 as CCls2};
|
||||
export {Cls1 as CCCls1};
|
||||
export {Cls2 as CCCls2};
|
Loading…
Reference in a new issue