Test cases for type alias declaration emit and privacy check.
Also removed the unnecessary error messages for type alias privacy check
This commit is contained in:
parent
5664b6fcf9
commit
d6fb678222
9 changed files with 385 additions and 19 deletions
|
@ -349,8 +349,6 @@ module ts {
|
|||
Parameter_0_of_exported_function_has_or_is_using_name_1_from_external_module_2_but_cannot_be_named: { code: 4076, category: DiagnosticCategory.Error, key: "Parameter '{0}' of exported function has or is using name '{1}' from external module {2} but cannot be named." },
|
||||
Parameter_0_of_exported_function_has_or_is_using_name_1_from_private_module_2: { code: 4077, category: DiagnosticCategory.Error, key: "Parameter '{0}' of exported function has or is using name '{1}' from private module '{2}'." },
|
||||
Parameter_0_of_exported_function_has_or_is_using_private_name_1: { code: 4078, category: DiagnosticCategory.Error, key: "Parameter '{0}' of exported function has or is using private name '{1}'." },
|
||||
Exported_type_alias_0_has_or_is_using_name_1_from_external_module_2_but_cannot_be_named: { code: 4079, category: DiagnosticCategory.Error, key: "Exported type alias '{0}' has or is using name '{1}' from external module {2} but cannot be named." },
|
||||
Exported_type_alias_0_has_or_is_using_name_1_from_private_module_2: { code: 4080, category: DiagnosticCategory.Error, key: "Exported type alias '{0}' has or is using name '{1}' from private module '{2}'." },
|
||||
Exported_type_alias_0_has_or_is_using_private_name_1: { code: 4081, category: DiagnosticCategory.Error, key: "Exported type alias '{0}' has or is using private name '{1}'." },
|
||||
Enum_declarations_must_all_be_const_or_non_const: { code: 4082, category: DiagnosticCategory.Error, key: "Enum declarations must all be const or non-const." },
|
||||
In_const_enum_declarations_member_initializer_must_be_constant_expression: { code: 4083, category: DiagnosticCategory.Error, key: "In 'const' enum declarations member initializer must be constant expression.", isEarly: true },
|
||||
|
|
|
@ -1393,14 +1393,6 @@
|
|||
"category": "Error",
|
||||
"code": 4078
|
||||
},
|
||||
"Exported type alias '{0}' has or is using name '{1}' from external module {2} but cannot be named.": {
|
||||
"category": "Error",
|
||||
"code": 4079
|
||||
},
|
||||
"Exported type alias '{0}' has or is using name '{1}' from private module '{2}'.": {
|
||||
"category": "Error",
|
||||
"code": 4080
|
||||
},
|
||||
"Exported type alias '{0}' has or is using private name '{1}'.": {
|
||||
"category": "Error",
|
||||
"code": 4081
|
||||
|
|
|
@ -2840,7 +2840,7 @@ module ts {
|
|||
}
|
||||
writer.writeLine();
|
||||
|
||||
function getImportEntityNameVisibilityError(symbolAccesibilityResult: SymbolAccessiblityResult) {
|
||||
function getImportEntityNameVisibilityError(symbolAccesibilityResult: SymbolAccessiblityResult): SymbolAccessibilityDiagnostic {
|
||||
return {
|
||||
diagnosticMessage: Diagnostics.Import_declaration_0_is_using_private_name_1,
|
||||
errorNode: node,
|
||||
|
@ -2884,15 +2884,10 @@ module ts {
|
|||
write(";");
|
||||
writeLine();
|
||||
}
|
||||
function getTypeAliasDeclarationVisibilityError(symbolAccesibilityResult: SymbolAccessiblityResult) {
|
||||
var diagnosticMessage = symbolAccesibilityResult.errorModuleName ?
|
||||
symbolAccesibilityResult.accessibility === SymbolAccessibility.CannotBeNamed ?
|
||||
Diagnostics.Exported_type_alias_0_has_or_is_using_name_1_from_external_module_2_but_cannot_be_named :
|
||||
Diagnostics.Exported_type_alias_0_has_or_is_using_name_1_from_private_module_2 :
|
||||
Diagnostics.Exported_type_alias_0_has_or_is_using_private_name_1;
|
||||
function getTypeAliasDeclarationVisibilityError(symbolAccesibilityResult: SymbolAccessiblityResult): SymbolAccessibilityDiagnostic {
|
||||
return {
|
||||
diagnosticMessage: diagnosticMessage,
|
||||
errorNode: node,
|
||||
diagnosticMessage: Diagnostics.Exported_type_alias_0_has_or_is_using_private_name_1,
|
||||
errorNode: node.type,
|
||||
typeName: node.name
|
||||
};
|
||||
}
|
||||
|
|
93
tests/baselines/reference/declFileTypeAnnotationTypeAlias.js
Normal file
93
tests/baselines/reference/declFileTypeAnnotationTypeAlias.js
Normal file
|
@ -0,0 +1,93 @@
|
|||
//// [declFileTypeAnnotationTypeAlias.ts]
|
||||
|
||||
module M {
|
||||
export type Value = string | number | boolean;
|
||||
export var x: Value;
|
||||
|
||||
export class c {
|
||||
}
|
||||
|
||||
export type C = c;
|
||||
|
||||
export module m {
|
||||
export class c {
|
||||
}
|
||||
}
|
||||
|
||||
export type MC = m.c;
|
||||
|
||||
export type fc = () => c;
|
||||
}
|
||||
|
||||
interface Window {
|
||||
someMethod();
|
||||
}
|
||||
|
||||
module M {
|
||||
export type W = Window | string;
|
||||
export module N {
|
||||
export class Window { }
|
||||
export var p: W;
|
||||
}
|
||||
}
|
||||
|
||||
//// [declFileTypeAnnotationTypeAlias.js]
|
||||
var M;
|
||||
(function (M) {
|
||||
M.x;
|
||||
var c = (function () {
|
||||
function c() {
|
||||
}
|
||||
return c;
|
||||
})();
|
||||
M.c = c;
|
||||
var m;
|
||||
(function (m) {
|
||||
var c = (function () {
|
||||
function c() {
|
||||
}
|
||||
return c;
|
||||
})();
|
||||
m.c = c;
|
||||
})(m = M.m || (M.m = {}));
|
||||
})(M || (M = {}));
|
||||
var M;
|
||||
(function (M) {
|
||||
var N;
|
||||
(function (N) {
|
||||
var Window = (function () {
|
||||
function Window() {
|
||||
}
|
||||
return Window;
|
||||
})();
|
||||
N.Window = Window;
|
||||
N.p;
|
||||
})(N = M.N || (M.N = {}));
|
||||
})(M || (M = {}));
|
||||
|
||||
|
||||
//// [declFileTypeAnnotationTypeAlias.d.ts]
|
||||
declare module M {
|
||||
type Value = string | number | boolean;
|
||||
var x: Value;
|
||||
class c {
|
||||
}
|
||||
type C = c;
|
||||
module m {
|
||||
class c {
|
||||
}
|
||||
}
|
||||
type MC = m.c;
|
||||
type fc = () => c;
|
||||
}
|
||||
interface Window {
|
||||
someMethod(): any;
|
||||
}
|
||||
declare module M {
|
||||
type W = Window | string;
|
||||
module N {
|
||||
class Window {
|
||||
}
|
||||
var p: W;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,63 @@
|
|||
=== tests/cases/compiler/declFileTypeAnnotationTypeAlias.ts ===
|
||||
|
||||
module M {
|
||||
>M : typeof M
|
||||
|
||||
export type Value = string | number | boolean;
|
||||
>Value : string | number | boolean
|
||||
|
||||
export var x: Value;
|
||||
>x : string | number | boolean
|
||||
>Value : string | number | boolean
|
||||
|
||||
export class c {
|
||||
>c : c
|
||||
}
|
||||
|
||||
export type C = c;
|
||||
>C : c
|
||||
>c : c
|
||||
|
||||
export module m {
|
||||
>m : typeof m
|
||||
|
||||
export class c {
|
||||
>c : c
|
||||
}
|
||||
}
|
||||
|
||||
export type MC = m.c;
|
||||
>MC : m.c
|
||||
>m : unknown
|
||||
>c : m.c
|
||||
|
||||
export type fc = () => c;
|
||||
>fc : () => c
|
||||
>c : c
|
||||
}
|
||||
|
||||
interface Window {
|
||||
>Window : Window
|
||||
|
||||
someMethod();
|
||||
>someMethod : () => any
|
||||
}
|
||||
|
||||
module M {
|
||||
>M : typeof M
|
||||
|
||||
export type W = Window | string;
|
||||
>W : string | Window
|
||||
>Window : Window
|
||||
|
||||
export module N {
|
||||
>N : typeof N
|
||||
|
||||
export class Window { }
|
||||
>Window : Window
|
||||
|
||||
export var p: W;
|
||||
>p : string | Window
|
||||
>W : string | Window
|
||||
}
|
||||
}
|
|
@ -0,0 +1,56 @@
|
|||
tests/cases/compiler/declFileTypeAnnotationVisibilityErrorTypeAlias.ts(10,23): error TS4025: Exported variable 'p' has or is using private name 'W'.
|
||||
tests/cases/compiler/declFileTypeAnnotationVisibilityErrorTypeAlias.ts(33,22): error TS4081: Exported type alias 't2' has or is using private name 'private1'.
|
||||
tests/cases/compiler/declFileTypeAnnotationVisibilityErrorTypeAlias.ts(36,23): error TS4081: Exported type alias 't12' has or is using private name 'public1'.
|
||||
tests/cases/compiler/declFileTypeAnnotationVisibilityErrorTypeAlias.ts(39,24): error TS4081: Exported type alias 't112' has or is using private name 'm3'.
|
||||
|
||||
|
||||
==== tests/cases/compiler/declFileTypeAnnotationVisibilityErrorTypeAlias.ts (4 errors) ====
|
||||
|
||||
interface Window {
|
||||
someMethod();
|
||||
}
|
||||
|
||||
module M {
|
||||
type W = Window | string;
|
||||
export module N {
|
||||
export class Window { }
|
||||
export var p: W; // Should report error that W is private
|
||||
~
|
||||
!!! error TS4025: Exported variable 'p' has or is using private name 'W'.
|
||||
}
|
||||
}
|
||||
|
||||
module M1 {
|
||||
export type W = Window | string;
|
||||
export module N {
|
||||
export class Window { }
|
||||
export var p: W; // No error
|
||||
}
|
||||
}
|
||||
|
||||
module M2 {
|
||||
class private1 {
|
||||
}
|
||||
class public1 {
|
||||
}
|
||||
module m3 {
|
||||
export class public1 {
|
||||
}
|
||||
}
|
||||
|
||||
type t1 = private1;
|
||||
export type t2 = private1; // error
|
||||
~~~~~~~~
|
||||
!!! error TS4081: Exported type alias 't2' has or is using private name 'private1'.
|
||||
|
||||
type t11 = public1;
|
||||
export type t12 = public1;
|
||||
~~~~~~~
|
||||
!!! error TS4081: Exported type alias 't12' has or is using private name 'public1'.
|
||||
|
||||
type t111 = m3.public1;
|
||||
export type t112 = m3.public1; // error
|
||||
~~~~~~~~~~
|
||||
!!! error TS4081: Exported type alias 't112' has or is using private name 'm3'.
|
||||
}
|
||||
|
|
@ -0,0 +1,92 @@
|
|||
//// [declFileTypeAnnotationVisibilityErrorTypeAlias.ts]
|
||||
|
||||
interface Window {
|
||||
someMethod();
|
||||
}
|
||||
|
||||
module M {
|
||||
type W = Window | string;
|
||||
export module N {
|
||||
export class Window { }
|
||||
export var p: W; // Should report error that W is private
|
||||
}
|
||||
}
|
||||
|
||||
module M1 {
|
||||
export type W = Window | string;
|
||||
export module N {
|
||||
export class Window { }
|
||||
export var p: W; // No error
|
||||
}
|
||||
}
|
||||
|
||||
module M2 {
|
||||
class private1 {
|
||||
}
|
||||
class public1 {
|
||||
}
|
||||
module m3 {
|
||||
export class public1 {
|
||||
}
|
||||
}
|
||||
|
||||
type t1 = private1;
|
||||
export type t2 = private1; // error
|
||||
|
||||
type t11 = public1;
|
||||
export type t12 = public1;
|
||||
|
||||
type t111 = m3.public1;
|
||||
export type t112 = m3.public1; // error
|
||||
}
|
||||
|
||||
|
||||
//// [declFileTypeAnnotationVisibilityErrorTypeAlias.js]
|
||||
var M;
|
||||
(function (M) {
|
||||
var N;
|
||||
(function (N) {
|
||||
var Window = (function () {
|
||||
function Window() {
|
||||
}
|
||||
return Window;
|
||||
})();
|
||||
N.Window = Window;
|
||||
N.p; // Should report error that W is private
|
||||
})(N = M.N || (M.N = {}));
|
||||
})(M || (M = {}));
|
||||
var M1;
|
||||
(function (M1) {
|
||||
var N;
|
||||
(function (N) {
|
||||
var Window = (function () {
|
||||
function Window() {
|
||||
}
|
||||
return Window;
|
||||
})();
|
||||
N.Window = Window;
|
||||
N.p; // No error
|
||||
})(N = M1.N || (M1.N = {}));
|
||||
})(M1 || (M1 = {}));
|
||||
var M2;
|
||||
(function (M2) {
|
||||
var private1 = (function () {
|
||||
function private1() {
|
||||
}
|
||||
return private1;
|
||||
})();
|
||||
var public1 = (function () {
|
||||
function public1() {
|
||||
}
|
||||
return public1;
|
||||
})();
|
||||
var m3;
|
||||
(function (m3) {
|
||||
var public1 = (function () {
|
||||
function public1() {
|
||||
}
|
||||
return public1;
|
||||
})();
|
||||
m3.public1 = public1;
|
||||
})(m3 || (m3 = {}));
|
||||
})(M2 || (M2 = {}));
|
34
tests/cases/compiler/declFileTypeAnnotationTypeAlias.ts
Normal file
34
tests/cases/compiler/declFileTypeAnnotationTypeAlias.ts
Normal file
|
@ -0,0 +1,34 @@
|
|||
// @target: ES5
|
||||
// @module: commonjs
|
||||
// @declaration: true
|
||||
|
||||
module M {
|
||||
export type Value = string | number | boolean;
|
||||
export var x: Value;
|
||||
|
||||
export class c {
|
||||
}
|
||||
|
||||
export type C = c;
|
||||
|
||||
export module m {
|
||||
export class c {
|
||||
}
|
||||
}
|
||||
|
||||
export type MC = m.c;
|
||||
|
||||
export type fc = () => c;
|
||||
}
|
||||
|
||||
interface Window {
|
||||
someMethod();
|
||||
}
|
||||
|
||||
module M {
|
||||
export type W = Window | string;
|
||||
export module N {
|
||||
export class Window { }
|
||||
export var p: W;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,43 @@
|
|||
// @target: ES5
|
||||
// @module: commonjs
|
||||
// @declaration: true
|
||||
|
||||
interface Window {
|
||||
someMethod();
|
||||
}
|
||||
|
||||
module M {
|
||||
type W = Window | string;
|
||||
export module N {
|
||||
export class Window { }
|
||||
export var p: W; // Should report error that W is private
|
||||
}
|
||||
}
|
||||
|
||||
module M1 {
|
||||
export type W = Window | string;
|
||||
export module N {
|
||||
export class Window { }
|
||||
export var p: W; // No error
|
||||
}
|
||||
}
|
||||
|
||||
module M2 {
|
||||
class private1 {
|
||||
}
|
||||
class public1 {
|
||||
}
|
||||
module m3 {
|
||||
export class public1 {
|
||||
}
|
||||
}
|
||||
|
||||
type t1 = private1;
|
||||
export type t2 = private1; // error
|
||||
|
||||
type t11 = public1;
|
||||
export type t12 = public1;
|
||||
|
||||
type t111 = m3.public1;
|
||||
export type t112 = m3.public1; // error
|
||||
}
|
Loading…
Reference in a new issue