From 09ea12d95cd98e0680684f7e414fae7d07213b4e Mon Sep 17 00:00:00 2001 From: Sheetal Nandi Date: Fri, 8 Aug 2014 16:15:09 -0700 Subject: [PATCH 1/3] Use typeof function in the declaration emitter instead of unwinding first level --- src/compiler/checker.ts | 24 ++++++++++- src/compiler/emitter.ts | 12 +++--- src/compiler/types.ts | 2 + .../reference/commentsClassMembers.js | 4 +- .../reference/declFileGenericType.js | 10 ++--- .../reference/declFileTypeofFunction.js | 40 ++++--------------- .../declarationEmit_nameConflicts.js | 5 +-- .../declarationEmit_nameConflicts2.js | 3 +- .../declarationEmit_nameConflicts3.js | 6 +-- tests/baselines/reference/funcdecl.js | 23 +++++------ ...nctionExpressionReturningItself.errors.txt | 4 -- .../functionExpressionReturningItself.js | 4 ++ .../reference/functionReturningItself.js | 2 +- .../reference/internalAliasFunction.js | 3 +- ...liasFunctionInsideLocalModuleWithExport.js | 2 +- ...sFunctionInsideLocalModuleWithoutExport.js | 3 +- ...sFunctionInsideTopLevelModuleWithExport.js | 2 +- ...nctionInsideTopLevelModuleWithoutExport.js | 3 +- .../privacyCheckTypeOfFunction.errors.txt | 10 +++++ .../reference/privacyCheckTypeOfFunction.js | 5 --- .../compiler/declarationEmit_nameConflicts.ts | 1 - .../declarationEmit_nameConflicts2.ts | 1 - 22 files changed, 84 insertions(+), 85 deletions(-) delete mode 100644 tests/baselines/reference/functionExpressionReturningItself.errors.txt create mode 100644 tests/baselines/reference/privacyCheckTypeOfFunction.errors.txt diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 906074ccc70..3fba12bf66c 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -942,10 +942,13 @@ module ts { writeTypeofSymbol(type); } // Use 'typeof T' for types of functions and methods that circularly reference themselves - // TODO(shkamat): correct the usuage of typeof function - always on functions that are visible - else if (type.symbol && type.symbol.flags & (SymbolFlags.Function | SymbolFlags.Method) && typeStack && contains(typeStack, type)) { + else if (shouldWriteTypeOfFunctionSymbol()) { writeTypeofSymbol(type); } + else if (typeStack && contains(typeStack, type)) { + // Recursive usage, use any + writer.write("any"); + } else { if (!typeStack) { typeStack = []; @@ -954,6 +957,23 @@ module ts { writeLiteralType(type, allowFunctionOrConstructorTypeLiteral); typeStack.pop(); } + + function shouldWriteTypeOfFunctionSymbol() { + if (type.symbol) { + var isStaticMethodSymbol = !!(type.symbol.flags & SymbolFlags.Method && // typeof static method + ts.forEach(type.symbol.declarations, declaration => declaration.flags & NodeFlags.Static)); + var isNonLocalFunctionSymbol = !!(type.symbol.flags & SymbolFlags.Function) && + (type.symbol.parent || // is exported function symbol + ts.forEach(type.symbol.declarations, declaration => + declaration.parent.kind === SyntaxKind.SourceFile || declaration.parent.kind === SyntaxKind.ModuleBlock)); + + if (isStaticMethodSymbol || isNonLocalFunctionSymbol) { + // typeof is allowed only for static/non local functions + return !!(flags & TypeFormatFlags.UseTypeOfFunction) || // use typeof if format flags specify it + (typeStack && contains(typeStack, type)); // it is type of the symbol uses itself recursively + } + } + } } function writeTypeofSymbol(type: ObjectType) { diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index 57124e0f026..bb182e9a812 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -2160,7 +2160,7 @@ module ts { if (node.constraint && (node.parent.kind !== SyntaxKind.Method || !(node.parent.flags & NodeFlags.Private))) { write(" extends "); getSymbolVisibilityDiagnosticMessage = getTypeParameterConstraintVisibilityError; - resolver.writeTypeAtLocation(node.constraint, enclosingDeclaration, TypeFormatFlags.None, writer); + resolver.writeTypeAtLocation(node.constraint, enclosingDeclaration, TypeFormatFlags.UseTypeOfFunction, writer); } } @@ -2179,7 +2179,7 @@ module ts { function emitTypeOfTypeReference(node: Node) { getSymbolVisibilityDiagnosticMessage = getHeritageClauseVisibilityError; - resolver.writeTypeAtLocation(node, enclosingDeclaration, TypeFormatFlags.WriteArrayAsGenericType, writer); + resolver.writeTypeAtLocation(node, enclosingDeclaration, TypeFormatFlags.WriteArrayAsGenericType | TypeFormatFlags.UseTypeOfFunction, writer); function getHeritageClauseVisibilityError(symbolAccesibilityResult: SymbolAccessiblityResult) { var diagnosticMessage: DiagnosticMessage; @@ -2304,7 +2304,7 @@ module ts { if (!(node.flags & NodeFlags.Private)) { write(": "); getSymbolVisibilityDiagnosticMessage = getVariableDeclarationTypeVisibilityError; - resolver.writeTypeAtLocation(node, enclosingDeclaration, TypeFormatFlags.None, writer); + resolver.writeTypeAtLocation(node, enclosingDeclaration, TypeFormatFlags.UseTypeOfFunction, writer); } } @@ -2362,7 +2362,7 @@ module ts { if (!(node.flags & NodeFlags.Private)) { write(": "); getSymbolVisibilityDiagnosticMessage = getAccessorDeclarationTypeVisibilityError; - resolver.writeTypeAtLocation(node, enclosingDeclaration, TypeFormatFlags.None, writer); + resolver.writeTypeAtLocation(node, enclosingDeclaration, TypeFormatFlags.UseTypeOfFunction, writer); } write(";"); writeLine(); @@ -2459,7 +2459,7 @@ module ts { if (node.kind !== SyntaxKind.Constructor && !(node.flags & NodeFlags.Private)) { write(": "); getSymbolVisibilityDiagnosticMessage = getReturnTypeVisibilityError; - resolver.writeReturnTypeOfSignatureDeclaration(node, enclosingDeclaration, TypeFormatFlags.None, writer); + resolver.writeReturnTypeOfSignatureDeclaration(node, enclosingDeclaration, TypeFormatFlags.UseTypeOfFunction, writer); } write(";"); writeLine(); @@ -2534,7 +2534,7 @@ module ts { if (!(node.parent.flags & NodeFlags.Private)) { write(": "); getSymbolVisibilityDiagnosticMessage = getParameterDeclarationTypeVisibilityError; - resolver.writeTypeAtLocation(node, enclosingDeclaration, TypeFormatFlags.None, writer); + resolver.writeTypeAtLocation(node, enclosingDeclaration, TypeFormatFlags.UseTypeOfFunction, writer); } function getParameterDeclarationTypeVisibilityError(symbolAccesibilityResult: SymbolAccessiblityResult) { diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 5e882740f1d..e507567a577 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -626,6 +626,8 @@ module ts { /** writes Array instead T[] */ WriteArrayAsGenericType = 0x00000001, // Declarations + + UseTypeOfFunction = 0x00000002, // instead of writing signature type of function use typeof } export enum SymbolAccessibility { diff --git a/tests/baselines/reference/commentsClassMembers.js b/tests/baselines/reference/commentsClassMembers.js index 23360404b5e..999ba787bd9 100644 --- a/tests/baselines/reference/commentsClassMembers.js +++ b/tests/baselines/reference/commentsClassMembers.js @@ -487,11 +487,11 @@ declare var i1_ncf: (b: number) => number; declare var i1_ncr: number; declare var i1_ncprop: number; declare var i1_s_p: number; -declare var i1_s_f: (b: number) => number; +declare var i1_s_f: typeof c1.s2; declare var i1_s_r: number; declare var i1_s_prop: number; declare var i1_s_nc_p: number; -declare var i1_s_ncf: (b: number) => number; +declare var i1_s_ncf: typeof c1.nc_s2; declare var i1_s_ncr: number; declare var i1_s_ncprop: number; declare var i1_c: typeof c1; diff --git a/tests/baselines/reference/declFileGenericType.js b/tests/baselines/reference/declFileGenericType.js index 2be231c1381..815b8712f15 100644 --- a/tests/baselines/reference/declFileGenericType.js +++ b/tests/baselines/reference/declFileGenericType.js @@ -131,10 +131,10 @@ export declare module C { } } export declare var a: C.A; -export declare var b: (x: T) => C.A; -export declare var c: (x: T) => C.A; -export declare var d: (x: T) => C.A[]; -export declare var e: >(x: T) => C.A[]; +export declare var b: typeof C.F; +export declare var c: typeof C.F2; +export declare var d: typeof C.F3; +export declare var e: typeof C.F4; export declare var x: C.A; export declare function f>(): void; export declare var g: C.A; @@ -142,4 +142,4 @@ export declare class h extends C.A { } export interface i extends C.A { } -export declare var j: >(x: T) => T; +export declare var j: typeof C.F6; diff --git a/tests/baselines/reference/declFileTypeofFunction.js b/tests/baselines/reference/declFileTypeofFunction.js index 66517ca4a94..f488d418f6d 100644 --- a/tests/baselines/reference/declFileTypeofFunction.js +++ b/tests/baselines/reference/declFileTypeofFunction.js @@ -64,39 +64,15 @@ function foo5(x) { //// [declFileTypeofFunction.d.ts] -declare function f(n: { - (n: typeof f): string; - (n: { - (n: typeof g): number; - (n: typeof f): number; - }): string; -}): string; -declare function f(n: { - (n: typeof g): number; - (n: { - (n: typeof f): string; - (n: typeof g): string; - }): number; -}): string; -declare function g(n: { - (n: typeof g): number; - (n: { - (n: typeof f): string; - (n: typeof g): string; - }): number; -}): number; -declare function g(n: { - (n: typeof f): string; - (n: { - (n: typeof g): number; - (n: typeof f): number; - }): string; -}): number; +declare function f(n: typeof f): string; +declare function f(n: typeof g): string; +declare function g(n: typeof g): number; +declare function g(n: typeof f): number; declare var b: any; -declare function b1(): () => typeof b1; -declare function foo(): () => typeof foo; -declare var foo1: () => typeof foo; -declare var foo2: () => typeof foo; +declare function b1(): typeof b1; +declare function foo(): typeof foo; +declare var foo1: typeof foo; +declare var foo2: typeof foo; declare var foo3: any; declare var x: any; declare function foo5(x: number): (x: number) => number; diff --git a/tests/baselines/reference/declarationEmit_nameConflicts.js b/tests/baselines/reference/declarationEmit_nameConflicts.js index 70b14ad66a6..c4070db5a87 100644 --- a/tests/baselines/reference/declarationEmit_nameConflicts.js +++ b/tests/baselines/reference/declarationEmit_nameConflicts.js @@ -28,7 +28,6 @@ export module M.P { export interface I { } } export import im = M.P.f; - // Bug 887180: Invalid .d.ts when an aliased entity is referenced, and a different entity is closer in scope export var a = M.a; // emitted incorrectly as typeof f export var b = M.b; // ok export var c = M.c; // ok @@ -170,10 +169,10 @@ export declare module M.P { } } export import im = M.P.f; - var a: () => void; + var a: typeof M.f; var b: typeof M.C; var c: typeof M.N; - var g: () => void; + var g: typeof c.g; var d: typeof M.d; } export declare module M.Q { diff --git a/tests/baselines/reference/declarationEmit_nameConflicts2.js b/tests/baselines/reference/declarationEmit_nameConflicts2.js index bc8ba2f63e9..79d73add32d 100644 --- a/tests/baselines/reference/declarationEmit_nameConflicts2.js +++ b/tests/baselines/reference/declarationEmit_nameConflicts2.js @@ -9,7 +9,6 @@ module X.Y.base { } module X.Y.base.Z { - // Bug 887180 export var f = X.Y.base.f; // Should be base.f export var C = X.Y.base.C; // Should be base.C export var M = X.Y.base.M; // Should be base.M @@ -72,7 +71,7 @@ declare module X.Y.base { } } declare module X.Y.base.Z { - var f: () => void; + var f: typeof base.f; var C: typeof base.C; var M: typeof base.M; var E: typeof base.E; diff --git a/tests/baselines/reference/declarationEmit_nameConflicts3.js b/tests/baselines/reference/declarationEmit_nameConflicts3.js index cfec6264a77..c7abf129404 100644 --- a/tests/baselines/reference/declarationEmit_nameConflicts3.js +++ b/tests/baselines/reference/declarationEmit_nameConflicts3.js @@ -111,7 +111,7 @@ declare module M.P { f = 0, } var v: M.D; - var w: () => void; - var x: () => void; - var x: () => void; + var w: typeof D.f; + var x: typeof C.f; + var x: typeof C.f; } diff --git a/tests/baselines/reference/funcdecl.js b/tests/baselines/reference/funcdecl.js index 40eb8dde17b..de080873b9f 100644 --- a/tests/baselines/reference/funcdecl.js +++ b/tests/baselines/reference/funcdecl.js @@ -134,29 +134,26 @@ var f2 = function () { //// [funcdecl.d.ts] declare function simpleFunc(): string; -declare var simpleFuncVar: () => string; +declare var simpleFuncVar: typeof simpleFunc; declare function anotherFuncNoReturn(): void; -declare var anotherFuncNoReturnVar: () => void; +declare var anotherFuncNoReturnVar: typeof anotherFuncNoReturn; declare function withReturn(): string; -declare var withReturnVar: () => string; +declare var withReturnVar: typeof withReturn; declare function withParams(a: string): string; -declare var withparamsVar: (a: string) => string; +declare var withparamsVar: typeof withParams; declare function withMultiParams(a: number, b: any, c: Object): number; -declare var withMultiParamsVar: (a: number, b: any, c: Object) => number; +declare var withMultiParamsVar: typeof withMultiParams; declare function withOptionalParams(a?: string): void; -declare var withOptionalParamsVar: (a?: string) => void; +declare var withOptionalParamsVar: typeof withOptionalParams; declare function withInitializedParams(a: string, b0: any, b?: number, c?: string): void; -declare var withInitializedParamsVar: (a: string, b0: any, b?: number, c?: string) => void; +declare var withInitializedParamsVar: typeof withInitializedParams; declare function withOptionalInitializedParams(a: string, c?: string): void; -declare var withOptionalInitializedParamsVar: (a: string, c?: string) => void; +declare var withOptionalInitializedParamsVar: typeof withOptionalInitializedParams; declare function withRestParams(a: string, ...myRestParameter: number[]): number[]; -declare var withRestParamsVar: (a: string, ...myRestParameter: number[]) => number[]; +declare var withRestParamsVar: typeof withRestParams; declare function overload1(n: number): string; declare function overload1(s: string): string; -declare var withOverloadSignature: { - (n: number): string; - (s: string): string; -}; +declare var withOverloadSignature: typeof overload1; declare function f(n: () => void): void; declare module m2 { function foo(n: () => void): void; diff --git a/tests/baselines/reference/functionExpressionReturningItself.errors.txt b/tests/baselines/reference/functionExpressionReturningItself.errors.txt deleted file mode 100644 index 2cfefecf9eb..00000000000 --- a/tests/baselines/reference/functionExpressionReturningItself.errors.txt +++ /dev/null @@ -1,4 +0,0 @@ -==== tests/cases/compiler/functionExpressionReturningItself.ts (1 errors) ==== - var x = function somefn() { return somefn; }; - ~ -!!! Exported variable 'x' has or is using private name 'somefn'. \ No newline at end of file diff --git a/tests/baselines/reference/functionExpressionReturningItself.js b/tests/baselines/reference/functionExpressionReturningItself.js index f80e9325871..8553d2da867 100644 --- a/tests/baselines/reference/functionExpressionReturningItself.js +++ b/tests/baselines/reference/functionExpressionReturningItself.js @@ -5,3 +5,7 @@ var x = function somefn() { return somefn; }; var x = function somefn() { return somefn; }; + + +//// [functionExpressionReturningItself.d.ts] +declare var x: () => any; diff --git a/tests/baselines/reference/functionReturningItself.js b/tests/baselines/reference/functionReturningItself.js index e50215a524b..7d161241899 100644 --- a/tests/baselines/reference/functionReturningItself.js +++ b/tests/baselines/reference/functionReturningItself.js @@ -10,4 +10,4 @@ function somefn() { //// [functionReturningItself.d.ts] -declare function somefn(): () => typeof somefn; +declare function somefn(): typeof somefn; diff --git a/tests/baselines/reference/internalAliasFunction.js b/tests/baselines/reference/internalAliasFunction.js index e46526f1f8b..3930c6cb801 100644 --- a/tests/baselines/reference/internalAliasFunction.js +++ b/tests/baselines/reference/internalAliasFunction.js @@ -33,6 +33,7 @@ declare module a { function foo(x: number): number; } declare module c { + import b = a.foo; var bVal: number; - var bVal2: (x: number) => number; + var bVal2: typeof b; } diff --git a/tests/baselines/reference/internalAliasFunctionInsideLocalModuleWithExport.js b/tests/baselines/reference/internalAliasFunctionInsideLocalModuleWithExport.js index a0a61453735..eb758b913e6 100644 --- a/tests/baselines/reference/internalAliasFunctionInsideLocalModuleWithExport.js +++ b/tests/baselines/reference/internalAliasFunctionInsideLocalModuleWithExport.js @@ -35,5 +35,5 @@ export declare module a { export declare module c { export import b = a.foo; var bVal: number; - var bVal2: (x: number) => number; + var bVal2: typeof b; } diff --git a/tests/baselines/reference/internalAliasFunctionInsideLocalModuleWithoutExport.js b/tests/baselines/reference/internalAliasFunctionInsideLocalModuleWithoutExport.js index 113396205ba..0423a587e84 100644 --- a/tests/baselines/reference/internalAliasFunctionInsideLocalModuleWithoutExport.js +++ b/tests/baselines/reference/internalAliasFunctionInsideLocalModuleWithoutExport.js @@ -33,5 +33,6 @@ export declare module a { function foo(x: number): number; } export declare module c { - var bVal2: (x: number) => number; + import b = a.foo; + var bVal2: typeof b; } diff --git a/tests/baselines/reference/internalAliasFunctionInsideTopLevelModuleWithExport.js b/tests/baselines/reference/internalAliasFunctionInsideTopLevelModuleWithExport.js index 1213bbbbe26..7fe09d1e02b 100644 --- a/tests/baselines/reference/internalAliasFunctionInsideTopLevelModuleWithExport.js +++ b/tests/baselines/reference/internalAliasFunctionInsideTopLevelModuleWithExport.js @@ -31,4 +31,4 @@ export declare module a { } export import b = a.foo; export declare var bVal: number; -export declare var bVal2: (x: number) => number; +export declare var bVal2: typeof b; diff --git a/tests/baselines/reference/internalAliasFunctionInsideTopLevelModuleWithoutExport.js b/tests/baselines/reference/internalAliasFunctionInsideTopLevelModuleWithoutExport.js index af546a20b5b..c049bfcf858 100644 --- a/tests/baselines/reference/internalAliasFunctionInsideTopLevelModuleWithoutExport.js +++ b/tests/baselines/reference/internalAliasFunctionInsideTopLevelModuleWithoutExport.js @@ -27,5 +27,6 @@ exports.bVal2 = b; export declare module a { function foo(x: number): number; } +import b = a.foo; export declare var bVal: number; -export declare var bVal2: (x: number) => number; +export declare var bVal2: typeof b; diff --git a/tests/baselines/reference/privacyCheckTypeOfFunction.errors.txt b/tests/baselines/reference/privacyCheckTypeOfFunction.errors.txt new file mode 100644 index 00000000000..50b9dc0242b --- /dev/null +++ b/tests/baselines/reference/privacyCheckTypeOfFunction.errors.txt @@ -0,0 +1,10 @@ +==== tests/cases/compiler/privacyCheckTypeOfFunction.ts (2 errors) ==== + function foo() { + } + export var x: typeof foo; + ~ +!!! Exported variable 'x' has or is using private name 'foo'. + export var b = foo; + ~ +!!! Exported variable 'b' has or is using private name 'foo'. + \ No newline at end of file diff --git a/tests/baselines/reference/privacyCheckTypeOfFunction.js b/tests/baselines/reference/privacyCheckTypeOfFunction.js index 04063c62991..757416c691b 100644 --- a/tests/baselines/reference/privacyCheckTypeOfFunction.js +++ b/tests/baselines/reference/privacyCheckTypeOfFunction.js @@ -10,8 +10,3 @@ function foo() { } exports.x; exports.b = foo; - - -//// [privacyCheckTypeOfFunction.d.ts] -export declare var x: () => void; -export declare var b: () => void; diff --git a/tests/cases/compiler/declarationEmit_nameConflicts.ts b/tests/cases/compiler/declarationEmit_nameConflicts.ts index 49218d2ef1e..66eb732ddae 100644 --- a/tests/cases/compiler/declarationEmit_nameConflicts.ts +++ b/tests/cases/compiler/declarationEmit_nameConflicts.ts @@ -28,7 +28,6 @@ export module M.P { export interface I { } } export import im = M.P.f; - // Bug 887180: Invalid .d.ts when an aliased entity is referenced, and a different entity is closer in scope export var a = M.a; // emitted incorrectly as typeof f export var b = M.b; // ok export var c = M.c; // ok diff --git a/tests/cases/compiler/declarationEmit_nameConflicts2.ts b/tests/cases/compiler/declarationEmit_nameConflicts2.ts index d7dd5134e96..f0112fa9501 100644 --- a/tests/cases/compiler/declarationEmit_nameConflicts2.ts +++ b/tests/cases/compiler/declarationEmit_nameConflicts2.ts @@ -9,7 +9,6 @@ module X.Y.base { } module X.Y.base.Z { - // Bug 887180 export var f = X.Y.base.f; // Should be base.f export var C = X.Y.base.C; // Should be base.C export var M = X.Y.base.M; // Should be base.M From e27e6b2bbbda680e624351231823b0978a6a75be Mon Sep 17 00:00:00 2001 From: Sheetal Nandi Date: Fri, 8 Aug 2014 17:07:00 -0700 Subject: [PATCH 2/3] During qualification if we are looking in value space, the left qualifier meaning is also value --- src/compiler/checker.ts | 19 +++++++++++-------- .../declarationEmit_nameConflicts.js | 2 +- .../declarationEmit_nameConflicts3.js | 7 +++---- .../declarationEmit_nameConflicts3.ts | 1 - 4 files changed, 15 insertions(+), 14 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 3fba12bf66c..b3c61262adb 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -661,6 +661,11 @@ module ts { return callback(globals); } + function getQualifiedLeftMeaning(rightMeaning: SymbolFlags) { + // If we are looking in value space, the parent meaning is value, other wise it is namespace + return rightMeaning === SymbolFlags.Value ? SymbolFlags.Value : SymbolFlags.Namespace; + } + function getAccessibleSymbolChain(symbol: Symbol, enclosingDeclaration: Node, meaning: SymbolFlags): Symbol[] { function getAccessibleSymbolChainFromSymbolTable(symbols: SymbolTable): Symbol[] { function canQualifySymbol(symbolFromSymbolTable: Symbol, meaning: SymbolFlags) { @@ -670,7 +675,7 @@ module ts { } // If symbol needs qualification, make sure that parent is accessible, if it is then this symbol is accessible too - var accessibleParent = getAccessibleSymbolChain(symbolFromSymbolTable.parent, enclosingDeclaration, SymbolFlags.Namespace); + var accessibleParent = getAccessibleSymbolChain(symbolFromSymbolTable.parent, enclosingDeclaration, getQualifiedLeftMeaning(meaning)); return !!accessibleParent; } @@ -698,7 +703,7 @@ module ts { // Look in the exported members, if we can find accessibleSymbolChain, symbol is accessible using this chain // but only if the symbolFromSymbolTable can be qualified var accessibleSymbolsFromExports = resolvedImportedSymbol.exports ? getAccessibleSymbolChainFromSymbolTable(resolvedImportedSymbol.exports) : undefined; - if (accessibleSymbolsFromExports && canQualifySymbol(symbolFromSymbolTable, SymbolFlags.Namespace)) { + if (accessibleSymbolsFromExports && canQualifySymbol(symbolFromSymbolTable, getQualifiedLeftMeaning(meaning))) { return [symbolFromSymbolTable].concat(accessibleSymbolsFromExports); } } @@ -758,8 +763,6 @@ module ts { return { accessibility: SymbolAccessibility.Accessible, aliasesToMakeVisible: hasAccessibleDeclarations.aliasesToMakeVisible }; } - // TODO(shkamat): Handle static method of class - // If we havent got the accessible symbol doesnt mean the symbol is actually inaccessible. // It could be qualified symbol and hence verify the path // eg: @@ -772,7 +775,7 @@ module ts { // we are going to see if c can be accessed in scope directly. // But it cant, hence the accessible is going to be undefined, but that doesnt mean m.c is accessible // It is accessible if the parent m is accessible because then m.c can be accessed through qualification - meaningToLook = SymbolFlags.Namespace; + meaningToLook = getQualifiedLeftMeaning(meaning); symbol = symbol.parent; } @@ -851,14 +854,14 @@ module ts { var symbolName: string; while (symbol) { var isFirstName = !symbolName; - var meaningToLook = isFirstName ? meaning : SymbolFlags.Namespace; - var accessibleSymbolChain = getAccessibleSymbolChain(symbol, enclosingDeclaration, meaningToLook); + var accessibleSymbolChain = getAccessibleSymbolChain(symbol, enclosingDeclaration, meaning); var currentSymbolName = accessibleSymbolChain ? ts.map(accessibleSymbolChain, accessibleSymbol => getSymbolName(accessibleSymbol)).join(".") : getSymbolName(symbol); symbolName = currentSymbolName + (isFirstName ? "" : ("." + symbolName)); - if (accessibleSymbolChain && !needsQualification(accessibleSymbolChain[0], enclosingDeclaration, accessibleSymbolChain.length === 1 ? meaningToLook : SymbolFlags.Namespace)) { + if (accessibleSymbolChain && !needsQualification(accessibleSymbolChain[0], enclosingDeclaration, accessibleSymbolChain.length === 1 ? meaning : getQualifiedLeftMeaning(meaning))) { break; } symbol = accessibleSymbolChain ? accessibleSymbolChain[0].parent : symbol.parent; + meaning = getQualifiedLeftMeaning(meaning); } return symbolName; diff --git a/tests/baselines/reference/declarationEmit_nameConflicts.js b/tests/baselines/reference/declarationEmit_nameConflicts.js index c4070db5a87..941029774f4 100644 --- a/tests/baselines/reference/declarationEmit_nameConflicts.js +++ b/tests/baselines/reference/declarationEmit_nameConflicts.js @@ -172,7 +172,7 @@ export declare module M.P { var a: typeof M.f; var b: typeof M.C; var c: typeof M.N; - var g: typeof c.g; + var g: typeof M.c.g; var d: typeof M.d; } export declare module M.Q { diff --git a/tests/baselines/reference/declarationEmit_nameConflicts3.js b/tests/baselines/reference/declarationEmit_nameConflicts3.js index c7abf129404..daa5bac83d7 100644 --- a/tests/baselines/reference/declarationEmit_nameConflicts3.js +++ b/tests/baselines/reference/declarationEmit_nameConflicts3.js @@ -20,7 +20,6 @@ module M.P { export enum D { f } - // Bug 887180 export var v: M.D; // ok export var w = M.D.f; // error, should be typeof M.D.f export var x = M.C.f; // error, should be typeof M.C.f @@ -111,7 +110,7 @@ declare module M.P { f = 0, } var v: M.D; - var w: typeof D.f; - var x: typeof C.f; - var x: typeof C.f; + var w: typeof M.D.f; + var x: typeof M.C.f; + var x: typeof M.C.f; } diff --git a/tests/cases/compiler/declarationEmit_nameConflicts3.ts b/tests/cases/compiler/declarationEmit_nameConflicts3.ts index b854841b4b4..6edc1056fa2 100644 --- a/tests/cases/compiler/declarationEmit_nameConflicts3.ts +++ b/tests/cases/compiler/declarationEmit_nameConflicts3.ts @@ -21,7 +21,6 @@ module M.P { export enum D { f } - // Bug 887180 export var v: M.D; // ok export var w = M.D.f; // error, should be typeof M.D.f export var x = M.C.f; // error, should be typeof M.C.f From 98f631e23fa49dd22b7ffb3dd6e99fc12433a4f2 Mon Sep 17 00:00:00 2001 From: Sheetal Nandi Date: Mon, 11 Aug 2014 14:15:57 -0700 Subject: [PATCH 3/3] Make changes to report error if the type used from external module cannot be named Adds test cases too --- src/compiler/checker.ts | 51 ++- .../diagnosticInformationMap.generated.ts | 12 + src/compiler/diagnosticMessages.json | 48 ++ src/compiler/emitter.ts | 84 ++-- ...ivacyCannotNameAccessorDeclFile.errors.txt | 151 +++++++ .../privacyCannotNameAccessorDeclFile.js | 410 +++++++++++++++++ ...rivacyCannotNameVarTypeDeclFile.errors.txt | 123 +++++ .../privacyCannotNameVarTypeDeclFile.js | 238 ++++++++++ ...CannotNameParameterTypeDeclFile.errors.txt | 203 +++++++++ ...FunctionCannotNameParameterTypeDeclFile.js | 424 ++++++++++++++++++ ...ionCannotNameReturnTypeDeclFile.errors.txt | 186 ++++++++ ...acyFunctionCannotNameReturnTypeDeclFile.js | 381 ++++++++++++++++ .../privacyCannotNameAccessorDeclFile.ts | 138 ++++++ .../privacyCannotNameVarTypeDeclFile.ts | 101 +++++ ...FunctionCannotNameParameterTypeDeclFile.ts | 157 +++++++ ...acyFunctionCannotNameReturnTypeDeclFile.ts | 163 +++++++ 16 files changed, 2831 insertions(+), 39 deletions(-) create mode 100644 tests/baselines/reference/privacyCannotNameAccessorDeclFile.errors.txt create mode 100644 tests/baselines/reference/privacyCannotNameAccessorDeclFile.js create mode 100644 tests/baselines/reference/privacyCannotNameVarTypeDeclFile.errors.txt create mode 100644 tests/baselines/reference/privacyCannotNameVarTypeDeclFile.js create mode 100644 tests/baselines/reference/privacyFunctionCannotNameParameterTypeDeclFile.errors.txt create mode 100644 tests/baselines/reference/privacyFunctionCannotNameParameterTypeDeclFile.js create mode 100644 tests/baselines/reference/privacyFunctionCannotNameReturnTypeDeclFile.errors.txt create mode 100644 tests/baselines/reference/privacyFunctionCannotNameReturnTypeDeclFile.js create mode 100644 tests/cases/compiler/privacyCannotNameAccessorDeclFile.ts create mode 100644 tests/cases/compiler/privacyCannotNameVarTypeDeclFile.ts create mode 100644 tests/cases/compiler/privacyFunctionCannotNameParameterTypeDeclFile.ts create mode 100644 tests/cases/compiler/privacyFunctionCannotNameReturnTypeDeclFile.ts diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index b3c61262adb..b32b86db639 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -681,9 +681,11 @@ module ts { function isAccessible(symbolFromSymbolTable: Symbol, resolvedAliasSymbol?: Symbol) { if (symbol === (resolvedAliasSymbol || symbolFromSymbolTable)) { - // if symbolfrom symbolTable or alias resolution matches the symbol, + // if the symbolFromSymbolTable is not external module (it could be if it was determined as ambient external module and would be in globals table) + // and if symbolfrom symbolTable or alias resolution matches the symbol, // check the symbol can be qualified, it is only then this symbol is accessible - return canQualifySymbol(symbolFromSymbolTable, meaning); + return !forEach(symbolFromSymbolTable.declarations, declaration => hasExternalModuleSymbol(declaration)) && + canQualifySymbol(symbolFromSymbolTable, meaning); } } @@ -779,14 +781,42 @@ module ts { symbol = symbol.parent; } - // This is a local symbol that cannot be named + // This could be a symbol that is not exported in the external module + // or it could be a symbol from different external module that is not aliased and hence cannot be named + var symbolExternalModule = forEach(initialSymbol.declarations, declaration => getExternalModuleContainer(declaration)); + if (symbolExternalModule) { + var enclosingExternalModule = getExternalModuleContainer(enclosingDeclaration); + if (symbolExternalModule !== enclosingExternalModule) { + // name from different external module that is not visibile + return { + accessibility: SymbolAccessibility.CannotBeNamed, + errorSymbolName: symbolToString(initialSymbol, enclosingDeclaration, meaning), + errorModuleName: symbolToString(symbolExternalModule) + }; + } + } + + // Just a local name that is not accessible return { - accessibility: SymbolAccessibility.CannotBeNamed, + accessibility: SymbolAccessibility.NotAccessible, errorSymbolName: symbolToString(initialSymbol, enclosingDeclaration, meaning), }; } return { accessibility: SymbolAccessibility.Accessible }; + + function getExternalModuleContainer(declaration: Declaration) { + for (; declaration; declaration = declaration.parent) { + if (hasExternalModuleSymbol(declaration)) { + return getSymbolOfNode(declaration); + } + } + } + } + + function hasExternalModuleSymbol(declaration: Declaration) { + return (declaration.kind === SyntaxKind.ModuleDeclaration && declaration.name.kind === SyntaxKind.StringLiteral) || + (declaration.kind === SyntaxKind.SourceFile && isExternalModule(declaration)); } function hasVisibleDeclarations(symbol: Symbol): { aliasesToMakeVisible?: ImportDeclaration[]; } { @@ -855,7 +885,18 @@ module ts { while (symbol) { var isFirstName = !symbolName; var accessibleSymbolChain = getAccessibleSymbolChain(symbol, enclosingDeclaration, meaning); - var currentSymbolName = accessibleSymbolChain ? ts.map(accessibleSymbolChain, accessibleSymbol => getSymbolName(accessibleSymbol)).join(".") : getSymbolName(symbol); + + var currentSymbolName: string; + if (accessibleSymbolChain) { + currentSymbolName = ts.map(accessibleSymbolChain, accessibleSymbol => getSymbolName(accessibleSymbol)).join("."); + } + else { + // If we didnt find accessible symbol chain for this symbol, break if this is external module + if (!isFirstName && ts.forEach(symbol.declarations, declaration => hasExternalModuleSymbol(declaration))) { + break; + } + currentSymbolName = getSymbolName(symbol); + } symbolName = currentSymbolName + (isFirstName ? "" : ("." + symbolName)); if (accessibleSymbolChain && !needsQualification(accessibleSymbolChain[0], enclosingDeclaration, accessibleSymbolChain.length === 1 ? meaning : getQualifiedLeftMeaning(meaning))) { break; diff --git a/src/compiler/diagnosticInformationMap.generated.ts b/src/compiler/diagnosticInformationMap.generated.ts index aa89b29acad..c917a7ba123 100644 --- a/src/compiler/diagnosticInformationMap.generated.ts +++ b/src/compiler/diagnosticInformationMap.generated.ts @@ -231,6 +231,18 @@ module ts { A_parameter_property_is_only_allowed_in_a_constructor_implementation: { code: 2246, category: DiagnosticCategory.Error, key: "A parameter property is only allowed in a constructor implementation." }, Function_overload_must_be_static: { code: 2247, category: DiagnosticCategory.Error, key: "Function overload must be static." }, Function_overload_must_not_be_static: { code: 2248, category: DiagnosticCategory.Error, key: "Function overload must not be static." }, + Public_static_property_0_of_exported_class_has_or_is_using_name_1_from_external_module_2_but_cannot_be_named: { code: 2249, category: DiagnosticCategory.Error, key: "Public static property '{0}' of exported class has or is using name '{1}' from external module {2} but cannot be named." }, + Public_property_0_of_exported_class_has_or_is_using_name_1_from_external_module_2_but_cannot_be_named: { code: 2250, category: DiagnosticCategory.Error, key: "Public property '{0}' of exported class has or is using name '{1}' from external module {2} but cannot be named." }, + Exported_variable_0_has_or_is_using_name_1_from_external_module_2_but_cannot_be_named: { code: 2251, category: DiagnosticCategory.Error, key: "Exported variable '{0}' has or is using name '{1}' from external module {2} but cannot be named." }, + Parameter_0_of_constructor_from_exported_class_has_or_is_using_name_1_from_external_module_2_but_cannot_be_named: { code: 2252, category: DiagnosticCategory.Error, key: "Parameter '{0}' of constructor from exported class has or is using name '{1}' from external module {2} but cannot be named." }, + Parameter_0_of_public_static_method_from_exported_class_has_or_is_using_name_1_from_external_module_2_but_cannot_be_named: { code: 2253, category: DiagnosticCategory.Error, key: "Parameter '{0}' of public static method from exported class has or is using name '{1}' from external module {2} but cannot be named." }, + Parameter_0_of_public_method_from_exported_class_has_or_is_using_name_1_from_external_module_2_but_cannot_be_named: { code: 2254, category: DiagnosticCategory.Error, key: "Parameter '{0}' of public method from exported class 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_external_module_2_but_cannot_be_named: { code: 2255, category: DiagnosticCategory.Error, key: "Parameter '{0}' of exported function has or is using name '{1}' from external module {2} but cannot be named." }, + Return_type_of_public_static_property_getter_from_exported_class_has_or_is_using_name_0_from_external_module_1_but_cannot_be_named: { code: 2256, category: DiagnosticCategory.Error, key: "Return type of public static property getter from exported class has or is using name '{0}' from external module {1} but cannot be named." }, + Return_type_of_public_property_getter_from_exported_class_has_or_is_using_name_0_from_external_module_1_but_cannot_be_named: { code: 2257, category: DiagnosticCategory.Error, key: "Return type of public property getter from exported class has or is using name '{0}' from external module {1} but cannot be named." }, + Return_type_of_public_static_method_from_exported_class_has_or_is_using_name_0_from_external_module_1_but_cannot_be_named: { code: 2258, category: DiagnosticCategory.Error, key: "Return type of public static method from exported class has or is using name '{0}' from external module {1} but cannot be named." }, + Return_type_of_public_method_from_exported_class_has_or_is_using_name_0_from_external_module_1_but_cannot_be_named: { code: 2259, category: DiagnosticCategory.Error, key: "Return type of public method from exported class has or is using name '{0}' from external module {1} but cannot be named." }, + Return_type_of_exported_function_has_or_is_using_name_0_from_external_module_1_but_cannot_be_named: { code: 2260, category: DiagnosticCategory.Error, key: "Return type of exported function has or is using name '{0}' from external module {1} but cannot be named." }, Circular_definition_of_import_alias_0: { code: 3000, category: DiagnosticCategory.Error, key: "Circular definition of import alias '{0}'." }, Cannot_find_name_0: { code: 3001, category: DiagnosticCategory.Error, key: "Cannot find name '{0}'." }, Module_0_has_no_exported_member_1: { code: 3002, category: DiagnosticCategory.Error, key: "Module '{0}' has no exported member '{1}'." }, diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index e9ce55dd3bd..682952ba84f 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -916,6 +916,54 @@ "category": "Error", "code": 2248 }, + "Public static property '{0}' of exported class has or is using name '{1}' from external module {2} but cannot be named.": { + "category": "Error", + "code": 2249 + }, + "Public property '{0}' of exported class has or is using name '{1}' from external module {2} but cannot be named.": { + "category": "Error", + "code": 2250 + }, + "Exported variable '{0}' has or is using name '{1}' from external module {2} but cannot be named.": { + "category": "Error", + "code": 2251 + }, + "Parameter '{0}' of constructor from exported class has or is using name '{1}' from external module {2} but cannot be named.": { + "category": "Error", + "code": 2252 + }, + "Parameter '{0}' of public static method from exported class has or is using name '{1}' from external module {2} but cannot be named.": { + "category": "Error", + "code": 2253 + }, + "Parameter '{0}' of public method from exported class has or is using name '{1}' from external module {2} but cannot be named.": { + "category": "Error", + "code": 2254 + }, + "Parameter '{0}' of exported function has or is using name '{1}' from external module {2} but cannot be named.": { + "category": "Error", + "code": 2255 + }, + "Return type of public static property getter from exported class has or is using name '{0}' from external module {1} but cannot be named.": { + "category": "Error", + "code": 2256 + }, + "Return type of public property getter from exported class has or is using name '{0}' from external module {1} but cannot be named.": { + "category": "Error", + "code": 2257 + }, + "Return type of public static method from exported class has or is using name '{0}' from external module {1} but cannot be named.": { + "category": "Error", + "code": 2258 + }, + "Return type of public method from exported class has or is using name '{0}' from external module {1} but cannot be named.": { + "category": "Error", + "code": 2259 + }, + "Return type of exported function has or is using name '{0}' from external module {1} but cannot be named.": { + "category": "Error", + "code": 2260 + }, "Circular definition of import alias '{0}'.": { "category": "Error", "code": 3000 diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index bb182e9a812..973f7123360 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -2093,7 +2093,7 @@ module ts { function emitTypeParameters(typeParameters: TypeParameterDeclaration[]) { function emitTypeParameter(node: TypeParameterDeclaration) { function getTypeParameterConstraintVisibilityError(symbolAccesibilityResult: SymbolAccessiblityResult) { - // TODO(shkamat) Cannot access name errors + // Type parameter constraints are named by user so we should always be able to name it var diagnosticMessage: DiagnosticMessage; switch (node.parent.kind) { case SyntaxKind.ClassDeclaration: @@ -2183,42 +2183,30 @@ module ts { function getHeritageClauseVisibilityError(symbolAccesibilityResult: SymbolAccessiblityResult) { var diagnosticMessage: DiagnosticMessage; + // Heritage clause is written by user so it can always be named if (node.parent.kind === SyntaxKind.ClassDeclaration) { // Class - if (symbolAccesibilityResult.accessibility == SymbolAccessibility.NotAccessible) { - if (symbolAccesibilityResult.errorModuleName) { - // Module is inaccessible - diagnosticMessage = isImplementsList ? - Diagnostics.Implements_clause_of_exported_class_0_has_or_is_using_name_1_from_private_module_2 : - Diagnostics.Extends_clause_of_exported_class_0_has_or_is_using_name_1_from_private_module_2; - } - else { - // Class or Interface implemented/extended is inaccessible - diagnosticMessage = isImplementsList ? - Diagnostics.Implements_clause_of_exported_class_0_has_or_is_using_private_name_1 : - Diagnostics.Extends_clause_of_exported_class_0_has_or_is_using_private_name_1; - } + if (symbolAccesibilityResult.errorModuleName) { + // Module is inaccessible + diagnosticMessage = isImplementsList ? + Diagnostics.Implements_clause_of_exported_class_0_has_or_is_using_name_1_from_private_module_2 : + Diagnostics.Extends_clause_of_exported_class_0_has_or_is_using_name_1_from_private_module_2; } else { - // CannotBeNamed - // TODO(shkamat): CannotBeNamed error needs to be handled + // Class or Interface implemented/extended is inaccessible + diagnosticMessage = isImplementsList ? + Diagnostics.Implements_clause_of_exported_class_0_has_or_is_using_private_name_1 : + Diagnostics.Extends_clause_of_exported_class_0_has_or_is_using_private_name_1; } } else { - // Interface - if (symbolAccesibilityResult.accessibility == SymbolAccessibility.NotAccessible) { - if (symbolAccesibilityResult.errorModuleName) { - // Module is inaccessible - diagnosticMessage = Diagnostics.Extends_clause_of_exported_interface_0_has_or_is_using_name_1_from_private_module_2; - } - else { - // interface is inaccessible - diagnosticMessage = Diagnostics.Extends_clause_of_exported_interface_0_has_or_is_using_private_name_1; - } + if (symbolAccesibilityResult.errorModuleName) { + // Module is inaccessible + diagnosticMessage = Diagnostics.Extends_clause_of_exported_interface_0_has_or_is_using_name_1_from_private_module_2; } else { - // CannotBeNamed - // TODO(shkamat): CannotBeNamed error needs to be handled + // interface is inaccessible + diagnosticMessage = Diagnostics.Extends_clause_of_exported_interface_0_has_or_is_using_private_name_1; } } @@ -2309,10 +2297,11 @@ module ts { } function getVariableDeclarationTypeVisibilityError(symbolAccesibilityResult: SymbolAccessiblityResult) { - // TODO(shkamat) Cannot access name errors var diagnosticMessage: DiagnosticMessage; if (node.kind === SyntaxKind.VariableDeclaration) { diagnosticMessage = symbolAccesibilityResult.errorModuleName ? + symbolAccesibilityResult.accessibility === SymbolAccessibility.CannotBeNamed ? + Diagnostics.Exported_variable_0_has_or_is_using_name_1_from_external_module_2_but_cannot_be_named : Diagnostics.Exported_variable_0_has_or_is_using_name_1_from_private_module_2 : Diagnostics.Exported_variable_0_has_or_is_using_private_name_1; } @@ -2320,15 +2309,20 @@ module ts { else if (node.kind === SyntaxKind.Property) { if (node.flags & NodeFlags.Static) { diagnosticMessage = symbolAccesibilityResult.errorModuleName ? + symbolAccesibilityResult.accessibility === SymbolAccessibility.CannotBeNamed ? + Diagnostics.Public_static_property_0_of_exported_class_has_or_is_using_name_1_from_external_module_2_but_cannot_be_named : Diagnostics.Public_static_property_0_of_exported_class_has_or_is_using_name_1_from_private_module_2 : Diagnostics.Public_static_property_0_of_exported_class_has_or_is_using_private_name_1; } else if (node.parent.kind === SyntaxKind.ClassDeclaration) { diagnosticMessage = symbolAccesibilityResult.errorModuleName ? + symbolAccesibilityResult.accessibility === SymbolAccessibility.CannotBeNamed ? + Diagnostics.Public_property_0_of_exported_class_has_or_is_using_name_1_from_external_module_2_but_cannot_be_named : Diagnostics.Public_property_0_of_exported_class_has_or_is_using_name_1_from_private_module_2 : Diagnostics.Public_property_0_of_exported_class_has_or_is_using_private_name_1; } else { + // Interfaces cannot have types that cannot be named diagnosticMessage = symbolAccesibilityResult.errorModuleName ? Diagnostics.Property_0_of_exported_interface_has_or_is_using_name_1_from_private_module_2 : Diagnostics.Property_0_of_exported_interface_has_or_is_using_private_name_1; @@ -2369,9 +2363,9 @@ module ts { } function getAccessorDeclarationTypeVisibilityError(symbolAccesibilityResult: SymbolAccessiblityResult) { - // TODO(shkamat) Cannot access name errors var diagnosticMessage: DiagnosticMessage; if (node.kind === SyntaxKind.SetAccessor) { + // Setters have to have type named and cannot infer it so, the type should always be named if (node.parent.flags & NodeFlags.Static) { diagnosticMessage = symbolAccesibilityResult.errorModuleName ? Diagnostics.Parameter_0_of_public_static_property_setter_from_exported_class_has_or_is_using_name_1_from_private_module_2 : @@ -2391,11 +2385,15 @@ module ts { else { if (node.flags & NodeFlags.Static) { diagnosticMessage = symbolAccesibilityResult.errorModuleName ? + symbolAccesibilityResult.accessibility === SymbolAccessibility.CannotBeNamed ? + Diagnostics.Return_type_of_public_static_property_getter_from_exported_class_has_or_is_using_name_0_from_external_module_1_but_cannot_be_named : Diagnostics.Return_type_of_public_static_property_getter_from_exported_class_has_or_is_using_name_0_from_private_module_1 : Diagnostics.Return_type_of_public_static_property_getter_from_exported_class_has_or_is_using_private_name_0; } else { diagnosticMessage = symbolAccesibilityResult.errorModuleName ? + symbolAccesibilityResult.accessibility === SymbolAccessibility.CannotBeNamed ? + Diagnostics.Return_type_of_public_property_getter_from_exported_class_has_or_is_using_name_0_from_external_module_1_but_cannot_be_named : Diagnostics.Return_type_of_public_property_getter_from_exported_class_has_or_is_using_name_0_from_private_module_1 : Diagnostics.Return_type_of_public_property_getter_from_exported_class_has_or_is_using_private_name_0; } @@ -2465,22 +2463,24 @@ module ts { writeLine(); function getReturnTypeVisibilityError(symbolAccesibilityResult: SymbolAccessiblityResult) { - // TODO(shkamat) Cannot access name errors var diagnosticMessage: DiagnosticMessage; switch (node.kind) { case SyntaxKind.ConstructSignature: - diagnosticMessage = symbolAccesibilityResult.errorModuleName ? + // Interfaces cannot have return types that cannot be named + diagnosticMessage = symbolAccesibilityResult.errorModuleName ? Diagnostics.Return_type_of_constructor_signature_from_exported_interface_has_or_is_using_name_0_from_private_module_1 : Diagnostics.Return_type_of_constructor_signature_from_exported_interface_has_or_is_using_private_name_0; break; case SyntaxKind.CallSignature: + // Interfaces cannot have return types that cannot be named diagnosticMessage = symbolAccesibilityResult.errorModuleName ? Diagnostics.Return_type_of_call_signature_from_exported_interface_has_or_is_using_name_0_from_private_module_1 : Diagnostics.Return_type_of_call_signature_from_exported_interface_has_or_is_using_private_name_0; break; case SyntaxKind.IndexSignature: + // Interfaces cannot have return types that cannot be named diagnosticMessage = symbolAccesibilityResult.errorModuleName ? Diagnostics.Return_type_of_index_signature_from_exported_interface_has_or_is_using_name_0_from_private_module_1 : Diagnostics.Return_type_of_index_signature_from_exported_interface_has_or_is_using_private_name_0; @@ -2489,15 +2489,20 @@ module ts { case SyntaxKind.Method: if (node.flags & NodeFlags.Static) { diagnosticMessage = symbolAccesibilityResult.errorModuleName ? + symbolAccesibilityResult.accessibility === SymbolAccessibility.CannotBeNamed ? + Diagnostics.Return_type_of_public_static_method_from_exported_class_has_or_is_using_name_0_from_external_module_1_but_cannot_be_named : Diagnostics.Return_type_of_public_static_method_from_exported_class_has_or_is_using_name_0_from_private_module_1 : Diagnostics.Return_type_of_public_static_method_from_exported_class_has_or_is_using_private_name_0; } else if (node.parent.kind === SyntaxKind.ClassDeclaration) { diagnosticMessage = symbolAccesibilityResult.errorModuleName ? + symbolAccesibilityResult.accessibility === SymbolAccessibility.CannotBeNamed ? + Diagnostics.Return_type_of_public_method_from_exported_class_has_or_is_using_name_0_from_external_module_1_but_cannot_be_named : Diagnostics.Return_type_of_public_method_from_exported_class_has_or_is_using_name_0_from_private_module_1 : Diagnostics.Return_type_of_public_method_from_exported_class_has_or_is_using_private_name_0; } else { + // Interfaces cannot have return types that cannot be named diagnosticMessage = symbolAccesibilityResult.errorModuleName ? Diagnostics.Return_type_of_method_from_exported_interface_has_or_is_using_name_0_from_private_module_1 : Diagnostics.Return_type_of_method_from_exported_interface_has_or_is_using_private_name_0; @@ -2506,6 +2511,8 @@ module ts { case SyntaxKind.FunctionDeclaration: diagnosticMessage = symbolAccesibilityResult.errorModuleName ? + symbolAccesibilityResult.accessibility === SymbolAccessibility.CannotBeNamed ? + Diagnostics.Return_type_of_exported_function_has_or_is_using_name_0_from_external_module_1_but_cannot_be_named : Diagnostics.Return_type_of_exported_function_has_or_is_using_name_0_from_private_module_1 : Diagnostics.Return_type_of_exported_function_has_or_is_using_private_name_0; break; @@ -2519,7 +2526,6 @@ module ts { errorNode: node.name || node, }; } - } function emitParameterDeclaration(node: ParameterDeclaration) { @@ -2538,22 +2544,25 @@ module ts { } function getParameterDeclarationTypeVisibilityError(symbolAccesibilityResult: SymbolAccessiblityResult) { - // TODO(shkamat) Cannot access name errors var diagnosticMessage: DiagnosticMessage; switch (node.parent.kind) { case SyntaxKind.Constructor: diagnosticMessage = symbolAccesibilityResult.errorModuleName ? + symbolAccesibilityResult.accessibility === SymbolAccessibility.CannotBeNamed ? + Diagnostics.Parameter_0_of_constructor_from_exported_class_has_or_is_using_name_1_from_external_module_2_but_cannot_be_named : Diagnostics.Parameter_0_of_constructor_from_exported_class_has_or_is_using_name_1_from_private_module_2 : Diagnostics.Parameter_0_of_constructor_from_exported_class_has_or_is_using_private_name_1; break; case SyntaxKind.ConstructSignature: + // Interfaces cannot have parameter types that cannot be named diagnosticMessage = symbolAccesibilityResult.errorModuleName ? Diagnostics.Parameter_0_of_constructor_signature_from_exported_interface_has_or_is_using_name_1_from_private_module_2 : Diagnostics.Parameter_0_of_constructor_signature_from_exported_interface_has_or_is_using_private_name_1; break; case SyntaxKind.CallSignature: + // Interfaces cannot have parameter types that cannot be named diagnosticMessage = symbolAccesibilityResult.errorModuleName ? Diagnostics.Parameter_0_of_call_signature_from_exported_interface_has_or_is_using_name_1_from_private_module_2 : Diagnostics.Parameter_0_of_call_signature_from_exported_interface_has_or_is_using_private_name_1; @@ -2562,15 +2571,20 @@ module ts { case SyntaxKind.Method: if (node.parent.flags & NodeFlags.Static) { diagnosticMessage = symbolAccesibilityResult.errorModuleName ? + symbolAccesibilityResult.accessibility === SymbolAccessibility.CannotBeNamed ? + Diagnostics.Parameter_0_of_public_static_method_from_exported_class_has_or_is_using_name_1_from_external_module_2_but_cannot_be_named : Diagnostics.Parameter_0_of_public_static_method_from_exported_class_has_or_is_using_name_1_from_private_module_2 : Diagnostics.Parameter_0_of_public_static_method_from_exported_class_has_or_is_using_private_name_1; } else if (node.parent.parent.kind === SyntaxKind.ClassDeclaration) { diagnosticMessage = symbolAccesibilityResult.errorModuleName ? + symbolAccesibilityResult.accessibility === SymbolAccessibility.CannotBeNamed ? + Diagnostics.Parameter_0_of_public_method_from_exported_class_has_or_is_using_name_1_from_external_module_2_but_cannot_be_named : Diagnostics.Parameter_0_of_public_method_from_exported_class_has_or_is_using_name_1_from_private_module_2 : Diagnostics.Parameter_0_of_public_method_from_exported_class_has_or_is_using_private_name_1; } else { + // Interfaces cannot have parameter types that cannot be named diagnosticMessage = symbolAccesibilityResult.errorModuleName ? Diagnostics.Parameter_0_of_method_from_exported_interface_has_or_is_using_name_1_from_private_module_2 : Diagnostics.Parameter_0_of_method_from_exported_interface_has_or_is_using_private_name_1; @@ -2579,6 +2593,8 @@ module ts { case SyntaxKind.FunctionDeclaration: diagnosticMessage = symbolAccesibilityResult.errorModuleName ? + symbolAccesibilityResult.accessibility === SymbolAccessibility.CannotBeNamed ? + Diagnostics.Parameter_0_of_exported_function_has_or_is_using_name_1_from_external_module_2_but_cannot_be_named : Diagnostics.Parameter_0_of_exported_function_has_or_is_using_name_1_from_private_module_2 : Diagnostics.Parameter_0_of_exported_function_has_or_is_using_private_name_1; break; diff --git a/tests/baselines/reference/privacyCannotNameAccessorDeclFile.errors.txt b/tests/baselines/reference/privacyCannotNameAccessorDeclFile.errors.txt new file mode 100644 index 00000000000..4f7f684d073 --- /dev/null +++ b/tests/baselines/reference/privacyCannotNameAccessorDeclFile.errors.txt @@ -0,0 +1,151 @@ +==== tests/cases/compiler/privacyCannotNameAccessorDeclFile_consumer.ts (8 errors) ==== + import exporter = require("privacyCannotNameAccessorDeclFile_exporter"); + export class publicClassWithWithPrivateGetAccessorTypes { + static get myPublicStaticMethod() { // Error + ~~~~~~~~~~~~~~~~~~~~ +!!! Return type of public static property getter from exported class has or is using name 'Widget1' from external module "tests/cases/compiler/privacyCannotNameAccessorDeclFile_Widgets" but cannot be named. + return exporter.createExportedWidget1(); + } + private static get myPrivateStaticMethod() { + return exporter.createExportedWidget1(); + } + get myPublicMethod() { // Error + ~~~~~~~~~~~~~~ +!!! Return type of public property getter from exported class has or is using name 'Widget1' from external module "tests/cases/compiler/privacyCannotNameAccessorDeclFile_Widgets" but cannot be named. + return exporter.createExportedWidget1(); + } + private get myPrivateMethod() { + return exporter.createExportedWidget1(); + } + static get myPublicStaticMethod1() { // Error + ~~~~~~~~~~~~~~~~~~~~~ +!!! Return type of public static property getter from exported class has or is using name 'Widget3' from external module "GlobalWidgets" but cannot be named. + return exporter.createExportedWidget3(); + } + private static get myPrivateStaticMethod1() { + return exporter.createExportedWidget3(); + } + get myPublicMethod1() { // Error + ~~~~~~~~~~~~~~~ +!!! Return type of public property getter from exported class has or is using name 'Widget3' from external module "GlobalWidgets" but cannot be named. + return exporter.createExportedWidget3(); + } + private get myPrivateMethod1() { + return exporter.createExportedWidget3(); + } + } + + class privateClassWithWithPrivateGetAccessorTypes { + static get myPublicStaticMethod() { + return exporter.createExportedWidget1(); + } + private static get myPrivateStaticMethod() { + return exporter.createExportedWidget1(); + } + get myPublicMethod() { + return exporter.createExportedWidget1(); + } + private get myPrivateMethod() { + return exporter.createExportedWidget1(); + } + static get myPublicStaticMethod1() { + return exporter.createExportedWidget3(); + } + private static get myPrivateStaticMethod1() { + return exporter.createExportedWidget3(); + } + get myPublicMethod1() { + return exporter.createExportedWidget3(); + } + private get myPrivateMethod1() { + return exporter.createExportedWidget3(); + } + } + + export class publicClassWithPrivateModuleGetAccessorTypes { + static get myPublicStaticMethod() { // Error + ~~~~~~~~~~~~~~~~~~~~ +!!! Return type of public static property getter from exported class has or is using name 'SpecializedWidget.Widget2' from external module "tests/cases/compiler/privacyCannotNameAccessorDeclFile_Widgets" but cannot be named. + return exporter.createExportedWidget2(); + } + get myPublicMethod() { // Error + ~~~~~~~~~~~~~~ +!!! Return type of public property getter from exported class has or is using name 'SpecializedWidget.Widget2' from external module "tests/cases/compiler/privacyCannotNameAccessorDeclFile_Widgets" but cannot be named. + return exporter.createExportedWidget2(); + } + static get myPublicStaticMethod1() { // Error + ~~~~~~~~~~~~~~~~~~~~~ +!!! Return type of public static property getter from exported class has or is using name 'SpecializedGlobalWidget.Widget4' from external module "GlobalWidgets" but cannot be named. + return exporter.createExportedWidget4(); + } + get myPublicMethod1() { // Error + ~~~~~~~~~~~~~~~ +!!! Return type of public property getter from exported class has or is using name 'SpecializedGlobalWidget.Widget4' from external module "GlobalWidgets" but cannot be named. + return exporter.createExportedWidget4(); + } + } + + class privateClassWithPrivateModuleGetAccessorTypes { + static get myPublicStaticMethod() { + return exporter.createExportedWidget2(); + } + get myPublicMethod() { + return exporter.createExportedWidget2(); + } + static get myPublicStaticMethod1() { + return exporter.createExportedWidget4(); + } + get myPublicMethod1() { + return exporter.createExportedWidget4(); + } + } +==== tests/cases/compiler/privacyCannotNameAccessorDeclFile_GlobalWidgets.ts (0 errors) ==== + + declare module "GlobalWidgets" { + export class Widget3 { + name: string; + } + export function createWidget3(): Widget3; + + export module SpecializedGlobalWidget { + export class Widget4 { + name: string; + } + function createWidget4(): Widget4; + } + } + +==== tests/cases/compiler/privacyCannotNameAccessorDeclFile_Widgets.ts (0 errors) ==== + export class Widget1 { + name = 'one'; + } + export function createWidget1() { + return new Widget1(); + } + + export module SpecializedWidget { + export class Widget2 { + name = 'one'; + } + export function createWidget2() { + return new Widget2(); + } + } + +==== tests/cases/compiler/privacyCannotNameAccessorDeclFile_exporter.ts (0 errors) ==== + /// + import Widgets = require("privacyCannotNameAccessorDeclFile_Widgets"); + import Widgets1 = require("GlobalWidgets"); + export function createExportedWidget1() { + return Widgets.createWidget1(); + } + export function createExportedWidget2() { + return Widgets.SpecializedWidget.createWidget2(); + } + export function createExportedWidget3() { + return Widgets1.createWidget3(); + } + export function createExportedWidget4() { + return Widgets1.SpecializedGlobalWidget.createWidget4(); + } + \ No newline at end of file diff --git a/tests/baselines/reference/privacyCannotNameAccessorDeclFile.js b/tests/baselines/reference/privacyCannotNameAccessorDeclFile.js new file mode 100644 index 00000000000..947c3c1fc0d --- /dev/null +++ b/tests/baselines/reference/privacyCannotNameAccessorDeclFile.js @@ -0,0 +1,410 @@ +//// [tests/cases/compiler/privacyCannotNameAccessorDeclFile.ts] //// + +//// [privacyCannotNameAccessorDeclFile_GlobalWidgets.ts] + +declare module "GlobalWidgets" { + export class Widget3 { + name: string; + } + export function createWidget3(): Widget3; + + export module SpecializedGlobalWidget { + export class Widget4 { + name: string; + } + function createWidget4(): Widget4; + } +} + +//// [privacyCannotNameAccessorDeclFile_Widgets.ts] +export class Widget1 { + name = 'one'; +} +export function createWidget1() { + return new Widget1(); +} + +export module SpecializedWidget { + export class Widget2 { + name = 'one'; + } + export function createWidget2() { + return new Widget2(); + } +} + +//// [privacyCannotNameAccessorDeclFile_exporter.ts] +/// +import Widgets = require("privacyCannotNameAccessorDeclFile_Widgets"); +import Widgets1 = require("GlobalWidgets"); +export function createExportedWidget1() { + return Widgets.createWidget1(); +} +export function createExportedWidget2() { + return Widgets.SpecializedWidget.createWidget2(); +} +export function createExportedWidget3() { + return Widgets1.createWidget3(); +} +export function createExportedWidget4() { + return Widgets1.SpecializedGlobalWidget.createWidget4(); +} + +//// [privacyCannotNameAccessorDeclFile_consumer.ts] +import exporter = require("privacyCannotNameAccessorDeclFile_exporter"); +export class publicClassWithWithPrivateGetAccessorTypes { + static get myPublicStaticMethod() { // Error + return exporter.createExportedWidget1(); + } + private static get myPrivateStaticMethod() { + return exporter.createExportedWidget1(); + } + get myPublicMethod() { // Error + return exporter.createExportedWidget1(); + } + private get myPrivateMethod() { + return exporter.createExportedWidget1(); + } + static get myPublicStaticMethod1() { // Error + return exporter.createExportedWidget3(); + } + private static get myPrivateStaticMethod1() { + return exporter.createExportedWidget3(); + } + get myPublicMethod1() { // Error + return exporter.createExportedWidget3(); + } + private get myPrivateMethod1() { + return exporter.createExportedWidget3(); + } +} + +class privateClassWithWithPrivateGetAccessorTypes { + static get myPublicStaticMethod() { + return exporter.createExportedWidget1(); + } + private static get myPrivateStaticMethod() { + return exporter.createExportedWidget1(); + } + get myPublicMethod() { + return exporter.createExportedWidget1(); + } + private get myPrivateMethod() { + return exporter.createExportedWidget1(); + } + static get myPublicStaticMethod1() { + return exporter.createExportedWidget3(); + } + private static get myPrivateStaticMethod1() { + return exporter.createExportedWidget3(); + } + get myPublicMethod1() { + return exporter.createExportedWidget3(); + } + private get myPrivateMethod1() { + return exporter.createExportedWidget3(); + } +} + +export class publicClassWithPrivateModuleGetAccessorTypes { + static get myPublicStaticMethod() { // Error + return exporter.createExportedWidget2(); + } + get myPublicMethod() { // Error + return exporter.createExportedWidget2(); + } + static get myPublicStaticMethod1() { // Error + return exporter.createExportedWidget4(); + } + get myPublicMethod1() { // Error + return exporter.createExportedWidget4(); + } +} + +class privateClassWithPrivateModuleGetAccessorTypes { + static get myPublicStaticMethod() { + return exporter.createExportedWidget2(); + } + get myPublicMethod() { + return exporter.createExportedWidget2(); + } + static get myPublicStaticMethod1() { + return exporter.createExportedWidget4(); + } + get myPublicMethod1() { + return exporter.createExportedWidget4(); + } +} + +//// [privacyCannotNameAccessorDeclFile_GlobalWidgets.js] +//// [privacyCannotNameAccessorDeclFile_Widgets.js] +var Widget1 = (function () { + function Widget1() { + this.name = 'one'; + } + return Widget1; +})(); +exports.Widget1 = Widget1; +function createWidget1() { + return new Widget1(); +} +exports.createWidget1 = createWidget1; +(function (SpecializedWidget) { + var Widget2 = (function () { + function Widget2() { + this.name = 'one'; + } + return Widget2; + })(); + SpecializedWidget.Widget2 = Widget2; + function createWidget2() { + return new Widget2(); + } + SpecializedWidget.createWidget2 = createWidget2; +})(exports.SpecializedWidget || (exports.SpecializedWidget = {})); +var SpecializedWidget = exports.SpecializedWidget; +//// [privacyCannotNameAccessorDeclFile_exporter.js] +var Widgets = require("privacyCannotNameAccessorDeclFile_Widgets"); +var Widgets1 = require("GlobalWidgets"); +function createExportedWidget1() { + return Widgets.createWidget1(); +} +exports.createExportedWidget1 = createExportedWidget1; +function createExportedWidget2() { + return Widgets.SpecializedWidget.createWidget2(); +} +exports.createExportedWidget2 = createExportedWidget2; +function createExportedWidget3() { + return Widgets1.createWidget3(); +} +exports.createExportedWidget3 = createExportedWidget3; +function createExportedWidget4() { + return Widgets1.SpecializedGlobalWidget.createWidget4(); +} +exports.createExportedWidget4 = createExportedWidget4; +//// [privacyCannotNameAccessorDeclFile_consumer.js] +var exporter = require("privacyCannotNameAccessorDeclFile_exporter"); +var publicClassWithWithPrivateGetAccessorTypes = (function () { + function publicClassWithWithPrivateGetAccessorTypes() { + } + Object.defineProperty(publicClassWithWithPrivateGetAccessorTypes, "myPublicStaticMethod", { + get: function () { + return exporter.createExportedWidget1(); + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(publicClassWithWithPrivateGetAccessorTypes, "myPrivateStaticMethod", { + get: function () { + return exporter.createExportedWidget1(); + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(publicClassWithWithPrivateGetAccessorTypes.prototype, "myPublicMethod", { + get: function () { + return exporter.createExportedWidget1(); + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(publicClassWithWithPrivateGetAccessorTypes.prototype, "myPrivateMethod", { + get: function () { + return exporter.createExportedWidget1(); + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(publicClassWithWithPrivateGetAccessorTypes, "myPublicStaticMethod1", { + get: function () { + return exporter.createExportedWidget3(); + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(publicClassWithWithPrivateGetAccessorTypes, "myPrivateStaticMethod1", { + get: function () { + return exporter.createExportedWidget3(); + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(publicClassWithWithPrivateGetAccessorTypes.prototype, "myPublicMethod1", { + get: function () { + return exporter.createExportedWidget3(); + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(publicClassWithWithPrivateGetAccessorTypes.prototype, "myPrivateMethod1", { + get: function () { + return exporter.createExportedWidget3(); + }, + enumerable: true, + configurable: true + }); + return publicClassWithWithPrivateGetAccessorTypes; +})(); +exports.publicClassWithWithPrivateGetAccessorTypes = publicClassWithWithPrivateGetAccessorTypes; +var privateClassWithWithPrivateGetAccessorTypes = (function () { + function privateClassWithWithPrivateGetAccessorTypes() { + } + Object.defineProperty(privateClassWithWithPrivateGetAccessorTypes, "myPublicStaticMethod", { + get: function () { + return exporter.createExportedWidget1(); + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(privateClassWithWithPrivateGetAccessorTypes, "myPrivateStaticMethod", { + get: function () { + return exporter.createExportedWidget1(); + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(privateClassWithWithPrivateGetAccessorTypes.prototype, "myPublicMethod", { + get: function () { + return exporter.createExportedWidget1(); + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(privateClassWithWithPrivateGetAccessorTypes.prototype, "myPrivateMethod", { + get: function () { + return exporter.createExportedWidget1(); + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(privateClassWithWithPrivateGetAccessorTypes, "myPublicStaticMethod1", { + get: function () { + return exporter.createExportedWidget3(); + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(privateClassWithWithPrivateGetAccessorTypes, "myPrivateStaticMethod1", { + get: function () { + return exporter.createExportedWidget3(); + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(privateClassWithWithPrivateGetAccessorTypes.prototype, "myPublicMethod1", { + get: function () { + return exporter.createExportedWidget3(); + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(privateClassWithWithPrivateGetAccessorTypes.prototype, "myPrivateMethod1", { + get: function () { + return exporter.createExportedWidget3(); + }, + enumerable: true, + configurable: true + }); + return privateClassWithWithPrivateGetAccessorTypes; +})(); +var publicClassWithPrivateModuleGetAccessorTypes = (function () { + function publicClassWithPrivateModuleGetAccessorTypes() { + } + Object.defineProperty(publicClassWithPrivateModuleGetAccessorTypes, "myPublicStaticMethod", { + get: function () { + return exporter.createExportedWidget2(); + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(publicClassWithPrivateModuleGetAccessorTypes.prototype, "myPublicMethod", { + get: function () { + return exporter.createExportedWidget2(); + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(publicClassWithPrivateModuleGetAccessorTypes, "myPublicStaticMethod1", { + get: function () { + return exporter.createExportedWidget4(); + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(publicClassWithPrivateModuleGetAccessorTypes.prototype, "myPublicMethod1", { + get: function () { + return exporter.createExportedWidget4(); + }, + enumerable: true, + configurable: true + }); + return publicClassWithPrivateModuleGetAccessorTypes; +})(); +exports.publicClassWithPrivateModuleGetAccessorTypes = publicClassWithPrivateModuleGetAccessorTypes; +var privateClassWithPrivateModuleGetAccessorTypes = (function () { + function privateClassWithPrivateModuleGetAccessorTypes() { + } + Object.defineProperty(privateClassWithPrivateModuleGetAccessorTypes, "myPublicStaticMethod", { + get: function () { + return exporter.createExportedWidget2(); + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(privateClassWithPrivateModuleGetAccessorTypes.prototype, "myPublicMethod", { + get: function () { + return exporter.createExportedWidget2(); + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(privateClassWithPrivateModuleGetAccessorTypes, "myPublicStaticMethod1", { + get: function () { + return exporter.createExportedWidget4(); + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(privateClassWithPrivateModuleGetAccessorTypes.prototype, "myPublicMethod1", { + get: function () { + return exporter.createExportedWidget4(); + }, + enumerable: true, + configurable: true + }); + return privateClassWithPrivateModuleGetAccessorTypes; +})(); + + +//// [privacyCannotNameAccessorDeclFile_GlobalWidgets.d.ts] +declare module "GlobalWidgets" { + class Widget3 { + name: string; + } + function createWidget3(): Widget3; + module SpecializedGlobalWidget { + class Widget4 { + name: string; + } + function createWidget4(): Widget4; + } +} +//// [privacyCannotNameAccessorDeclFile_Widgets.d.ts] +export declare class Widget1 { + name: string; +} +export declare function createWidget1(): Widget1; +export declare module SpecializedWidget { + class Widget2 { + name: string; + } + function createWidget2(): Widget2; +} +//// [privacyCannotNameAccessorDeclFile_exporter.d.ts] +/// +import Widgets = require("privacyCannotNameAccessorDeclFile_Widgets"); +import Widgets1 = require("GlobalWidgets"); +export declare function createExportedWidget1(): Widgets.Widget1; +export declare function createExportedWidget2(): Widgets.SpecializedWidget.Widget2; +export declare function createExportedWidget3(): Widgets1.Widget3; +export declare function createExportedWidget4(): Widgets1.SpecializedGlobalWidget.Widget4; diff --git a/tests/baselines/reference/privacyCannotNameVarTypeDeclFile.errors.txt b/tests/baselines/reference/privacyCannotNameVarTypeDeclFile.errors.txt new file mode 100644 index 00000000000..92a2f349908 --- /dev/null +++ b/tests/baselines/reference/privacyCannotNameVarTypeDeclFile.errors.txt @@ -0,0 +1,123 @@ +==== tests/cases/compiler/privacyCannotNameVarTypeDeclFile_consumer.ts (12 errors) ==== + import exporter = require("privacyCannotNameVarTypeDeclFile_exporter"); + export class publicClassWithWithPrivatePropertyTypes { + static myPublicStaticProperty = exporter.createExportedWidget1(); // Error + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! Public static property 'myPublicStaticProperty' of exported class has or is using name 'Widget1' from external module "tests/cases/compiler/privacyCannotNameVarTypeDeclFile_Widgets" but cannot be named. + private static myPrivateStaticProperty = exporter.createExportedWidget1(); + myPublicProperty = exporter.createExportedWidget1(); // Error + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! Public property 'myPublicProperty' of exported class has or is using name 'Widget1' from external module "tests/cases/compiler/privacyCannotNameVarTypeDeclFile_Widgets" but cannot be named. + private myPrivateProperty = exporter.createExportedWidget1(); + + static myPublicStaticProperty1 = exporter.createExportedWidget3(); // Error + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! Public static property 'myPublicStaticProperty1' of exported class has or is using name 'Widget3' from external module "GlobalWidgets" but cannot be named. + private static myPrivateStaticProperty1 = exporter.createExportedWidget3(); + myPublicProperty1 = exporter.createExportedWidget3(); // Error + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! Public property 'myPublicProperty1' of exported class has or is using name 'Widget3' from external module "GlobalWidgets" but cannot be named. + private myPrivateProperty1 = exporter.createExportedWidget3(); + } + + class privateClassWithWithPrivatePropertyTypes { + static myPublicStaticProperty = exporter.createExportedWidget1(); + private static myPrivateStaticProperty = exporter.createExportedWidget1(); + myPublicProperty = exporter.createExportedWidget1(); + private myPrivateProperty = exporter.createExportedWidget1(); + + static myPublicStaticProperty1 = exporter.createExportedWidget3(); + private static myPrivateStaticProperty1 = exporter.createExportedWidget3(); + myPublicProperty1 = exporter.createExportedWidget3(); + private myPrivateProperty1 = exporter.createExportedWidget3(); + } + + export var publicVarWithPrivatePropertyTypes= exporter.createExportedWidget1(); // Error + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! Exported variable 'publicVarWithPrivatePropertyTypes' has or is using name 'Widget1' from external module "tests/cases/compiler/privacyCannotNameVarTypeDeclFile_Widgets" but cannot be named. + var privateVarWithPrivatePropertyTypes= exporter.createExportedWidget1(); + export var publicVarWithPrivatePropertyTypes1 = exporter.createExportedWidget3(); // Error + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! Exported variable 'publicVarWithPrivatePropertyTypes1' has or is using name 'Widget3' from external module "GlobalWidgets" but cannot be named. + var privateVarWithPrivatePropertyTypes1 = exporter.createExportedWidget3(); + + export class publicClassWithPrivateModulePropertyTypes { + static myPublicStaticProperty= exporter.createExportedWidget2(); // Error + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! Public static property 'myPublicStaticProperty' of exported class has or is using name 'SpecializedWidget.Widget2' from external module "tests/cases/compiler/privacyCannotNameVarTypeDeclFile_Widgets" but cannot be named. + myPublicProperty = exporter.createExportedWidget2(); // Error + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! Public property 'myPublicProperty' of exported class has or is using name 'SpecializedWidget.Widget2' from external module "tests/cases/compiler/privacyCannotNameVarTypeDeclFile_Widgets" but cannot be named. + static myPublicStaticProperty1 = exporter.createExportedWidget4(); // Error + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! Public static property 'myPublicStaticProperty1' of exported class has or is using name 'SpecializedGlobalWidget.Widget4' from external module "GlobalWidgets" but cannot be named. + myPublicProperty1 = exporter.createExportedWidget4(); // Error + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! Public property 'myPublicProperty1' of exported class has or is using name 'SpecializedGlobalWidget.Widget4' from external module "GlobalWidgets" but cannot be named. + } + export var publicVarWithPrivateModulePropertyTypes= exporter.createExportedWidget2(); // Error + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! Exported variable 'publicVarWithPrivateModulePropertyTypes' has or is using name 'SpecializedWidget.Widget2' from external module "tests/cases/compiler/privacyCannotNameVarTypeDeclFile_Widgets" but cannot be named. + export var publicVarWithPrivateModulePropertyTypes1 = exporter.createExportedWidget4(); // Error + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! Exported variable 'publicVarWithPrivateModulePropertyTypes1' has or is using name 'SpecializedGlobalWidget.Widget4' from external module "GlobalWidgets" but cannot be named. + + class privateClassWithPrivateModulePropertyTypes { + static myPublicStaticProperty= exporter.createExportedWidget2(); + myPublicProperty= exporter.createExportedWidget2(); + static myPublicStaticProperty1 = exporter.createExportedWidget4(); + myPublicProperty1 = exporter.createExportedWidget4(); + } + var privateVarWithPrivateModulePropertyTypes= exporter.createExportedWidget2(); + var privateVarWithPrivateModulePropertyTypes1 = exporter.createExportedWidget4(); +==== tests/cases/compiler/privacyCannotNameVarTypeDeclFile_GlobalWidgets.ts (0 errors) ==== + + + declare module "GlobalWidgets" { + export class Widget3 { + name: string; + } + export function createWidget3(): Widget3; + + export module SpecializedGlobalWidget { + export class Widget4 { + name: string; + } + function createWidget4(): Widget4; + } + } + +==== tests/cases/compiler/privacyCannotNameVarTypeDeclFile_Widgets.ts (0 errors) ==== + export class Widget1 { + name = 'one'; + } + export function createWidget1() { + return new Widget1(); + } + + export module SpecializedWidget { + export class Widget2 { + name = 'one'; + } + export function createWidget2() { + return new Widget2(); + } + } + +==== tests/cases/compiler/privacyCannotNameVarTypeDeclFile_exporter.ts (0 errors) ==== + /// + import Widgets = require("privacyCannotNameVarTypeDeclFile_Widgets"); + import Widgets1 = require("GlobalWidgets"); + export function createExportedWidget1() { + return Widgets.createWidget1(); + } + export function createExportedWidget2() { + return Widgets.SpecializedWidget.createWidget2(); + } + export function createExportedWidget3() { + return Widgets1.createWidget3(); + } + export function createExportedWidget4() { + return Widgets1.SpecializedGlobalWidget.createWidget4(); + } + \ No newline at end of file diff --git a/tests/baselines/reference/privacyCannotNameVarTypeDeclFile.js b/tests/baselines/reference/privacyCannotNameVarTypeDeclFile.js new file mode 100644 index 00000000000..d113b0a8095 --- /dev/null +++ b/tests/baselines/reference/privacyCannotNameVarTypeDeclFile.js @@ -0,0 +1,238 @@ +//// [tests/cases/compiler/privacyCannotNameVarTypeDeclFile.ts] //// + +//// [privacyCannotNameVarTypeDeclFile_GlobalWidgets.ts] + + +declare module "GlobalWidgets" { + export class Widget3 { + name: string; + } + export function createWidget3(): Widget3; + + export module SpecializedGlobalWidget { + export class Widget4 { + name: string; + } + function createWidget4(): Widget4; + } +} + +//// [privacyCannotNameVarTypeDeclFile_Widgets.ts] +export class Widget1 { + name = 'one'; +} +export function createWidget1() { + return new Widget1(); +} + +export module SpecializedWidget { + export class Widget2 { + name = 'one'; + } + export function createWidget2() { + return new Widget2(); + } +} + +//// [privacyCannotNameVarTypeDeclFile_exporter.ts] +/// +import Widgets = require("privacyCannotNameVarTypeDeclFile_Widgets"); +import Widgets1 = require("GlobalWidgets"); +export function createExportedWidget1() { + return Widgets.createWidget1(); +} +export function createExportedWidget2() { + return Widgets.SpecializedWidget.createWidget2(); +} +export function createExportedWidget3() { + return Widgets1.createWidget3(); +} +export function createExportedWidget4() { + return Widgets1.SpecializedGlobalWidget.createWidget4(); +} + +//// [privacyCannotNameVarTypeDeclFile_consumer.ts] +import exporter = require("privacyCannotNameVarTypeDeclFile_exporter"); +export class publicClassWithWithPrivatePropertyTypes { + static myPublicStaticProperty = exporter.createExportedWidget1(); // Error + private static myPrivateStaticProperty = exporter.createExportedWidget1(); + myPublicProperty = exporter.createExportedWidget1(); // Error + private myPrivateProperty = exporter.createExportedWidget1(); + + static myPublicStaticProperty1 = exporter.createExportedWidget3(); // Error + private static myPrivateStaticProperty1 = exporter.createExportedWidget3(); + myPublicProperty1 = exporter.createExportedWidget3(); // Error + private myPrivateProperty1 = exporter.createExportedWidget3(); +} + +class privateClassWithWithPrivatePropertyTypes { + static myPublicStaticProperty = exporter.createExportedWidget1(); + private static myPrivateStaticProperty = exporter.createExportedWidget1(); + myPublicProperty = exporter.createExportedWidget1(); + private myPrivateProperty = exporter.createExportedWidget1(); + + static myPublicStaticProperty1 = exporter.createExportedWidget3(); + private static myPrivateStaticProperty1 = exporter.createExportedWidget3(); + myPublicProperty1 = exporter.createExportedWidget3(); + private myPrivateProperty1 = exporter.createExportedWidget3(); +} + +export var publicVarWithPrivatePropertyTypes= exporter.createExportedWidget1(); // Error +var privateVarWithPrivatePropertyTypes= exporter.createExportedWidget1(); +export var publicVarWithPrivatePropertyTypes1 = exporter.createExportedWidget3(); // Error +var privateVarWithPrivatePropertyTypes1 = exporter.createExportedWidget3(); + +export class publicClassWithPrivateModulePropertyTypes { + static myPublicStaticProperty= exporter.createExportedWidget2(); // Error + myPublicProperty = exporter.createExportedWidget2(); // Error + static myPublicStaticProperty1 = exporter.createExportedWidget4(); // Error + myPublicProperty1 = exporter.createExportedWidget4(); // Error +} +export var publicVarWithPrivateModulePropertyTypes= exporter.createExportedWidget2(); // Error +export var publicVarWithPrivateModulePropertyTypes1 = exporter.createExportedWidget4(); // Error + +class privateClassWithPrivateModulePropertyTypes { + static myPublicStaticProperty= exporter.createExportedWidget2(); + myPublicProperty= exporter.createExportedWidget2(); + static myPublicStaticProperty1 = exporter.createExportedWidget4(); + myPublicProperty1 = exporter.createExportedWidget4(); +} +var privateVarWithPrivateModulePropertyTypes= exporter.createExportedWidget2(); +var privateVarWithPrivateModulePropertyTypes1 = exporter.createExportedWidget4(); + +//// [privacyCannotNameVarTypeDeclFile_GlobalWidgets.js] +//// [privacyCannotNameVarTypeDeclFile_Widgets.js] +var Widget1 = (function () { + function Widget1() { + this.name = 'one'; + } + return Widget1; +})(); +exports.Widget1 = Widget1; +function createWidget1() { + return new Widget1(); +} +exports.createWidget1 = createWidget1; +(function (SpecializedWidget) { + var Widget2 = (function () { + function Widget2() { + this.name = 'one'; + } + return Widget2; + })(); + SpecializedWidget.Widget2 = Widget2; + function createWidget2() { + return new Widget2(); + } + SpecializedWidget.createWidget2 = createWidget2; +})(exports.SpecializedWidget || (exports.SpecializedWidget = {})); +var SpecializedWidget = exports.SpecializedWidget; +//// [privacyCannotNameVarTypeDeclFile_exporter.js] +var Widgets = require("privacyCannotNameVarTypeDeclFile_Widgets"); +var Widgets1 = require("GlobalWidgets"); +function createExportedWidget1() { + return Widgets.createWidget1(); +} +exports.createExportedWidget1 = createExportedWidget1; +function createExportedWidget2() { + return Widgets.SpecializedWidget.createWidget2(); +} +exports.createExportedWidget2 = createExportedWidget2; +function createExportedWidget3() { + return Widgets1.createWidget3(); +} +exports.createExportedWidget3 = createExportedWidget3; +function createExportedWidget4() { + return Widgets1.SpecializedGlobalWidget.createWidget4(); +} +exports.createExportedWidget4 = createExportedWidget4; +//// [privacyCannotNameVarTypeDeclFile_consumer.js] +var exporter = require("privacyCannotNameVarTypeDeclFile_exporter"); +var publicClassWithWithPrivatePropertyTypes = (function () { + function publicClassWithWithPrivatePropertyTypes() { + this.myPublicProperty = exporter.createExportedWidget1(); + this.myPrivateProperty = exporter.createExportedWidget1(); + this.myPublicProperty1 = exporter.createExportedWidget3(); + this.myPrivateProperty1 = exporter.createExportedWidget3(); + } + publicClassWithWithPrivatePropertyTypes.myPublicStaticProperty = exporter.createExportedWidget1(); + publicClassWithWithPrivatePropertyTypes.myPrivateStaticProperty = exporter.createExportedWidget1(); + publicClassWithWithPrivatePropertyTypes.myPublicStaticProperty1 = exporter.createExportedWidget3(); + publicClassWithWithPrivatePropertyTypes.myPrivateStaticProperty1 = exporter.createExportedWidget3(); + return publicClassWithWithPrivatePropertyTypes; +})(); +exports.publicClassWithWithPrivatePropertyTypes = publicClassWithWithPrivatePropertyTypes; +var privateClassWithWithPrivatePropertyTypes = (function () { + function privateClassWithWithPrivatePropertyTypes() { + this.myPublicProperty = exporter.createExportedWidget1(); + this.myPrivateProperty = exporter.createExportedWidget1(); + this.myPublicProperty1 = exporter.createExportedWidget3(); + this.myPrivateProperty1 = exporter.createExportedWidget3(); + } + privateClassWithWithPrivatePropertyTypes.myPublicStaticProperty = exporter.createExportedWidget1(); + privateClassWithWithPrivatePropertyTypes.myPrivateStaticProperty = exporter.createExportedWidget1(); + privateClassWithWithPrivatePropertyTypes.myPublicStaticProperty1 = exporter.createExportedWidget3(); + privateClassWithWithPrivatePropertyTypes.myPrivateStaticProperty1 = exporter.createExportedWidget3(); + return privateClassWithWithPrivatePropertyTypes; +})(); +exports.publicVarWithPrivatePropertyTypes = exporter.createExportedWidget1(); +var privateVarWithPrivatePropertyTypes = exporter.createExportedWidget1(); +exports.publicVarWithPrivatePropertyTypes1 = exporter.createExportedWidget3(); +var privateVarWithPrivatePropertyTypes1 = exporter.createExportedWidget3(); +var publicClassWithPrivateModulePropertyTypes = (function () { + function publicClassWithPrivateModulePropertyTypes() { + this.myPublicProperty = exporter.createExportedWidget2(); + this.myPublicProperty1 = exporter.createExportedWidget4(); + } + publicClassWithPrivateModulePropertyTypes.myPublicStaticProperty = exporter.createExportedWidget2(); + publicClassWithPrivateModulePropertyTypes.myPublicStaticProperty1 = exporter.createExportedWidget4(); + return publicClassWithPrivateModulePropertyTypes; +})(); +exports.publicClassWithPrivateModulePropertyTypes = publicClassWithPrivateModulePropertyTypes; +exports.publicVarWithPrivateModulePropertyTypes = exporter.createExportedWidget2(); +exports.publicVarWithPrivateModulePropertyTypes1 = exporter.createExportedWidget4(); +var privateClassWithPrivateModulePropertyTypes = (function () { + function privateClassWithPrivateModulePropertyTypes() { + this.myPublicProperty = exporter.createExportedWidget2(); + this.myPublicProperty1 = exporter.createExportedWidget4(); + } + privateClassWithPrivateModulePropertyTypes.myPublicStaticProperty = exporter.createExportedWidget2(); + privateClassWithPrivateModulePropertyTypes.myPublicStaticProperty1 = exporter.createExportedWidget4(); + return privateClassWithPrivateModulePropertyTypes; +})(); +var privateVarWithPrivateModulePropertyTypes = exporter.createExportedWidget2(); +var privateVarWithPrivateModulePropertyTypes1 = exporter.createExportedWidget4(); + + +//// [privacyCannotNameVarTypeDeclFile_GlobalWidgets.d.ts] +declare module "GlobalWidgets" { + class Widget3 { + name: string; + } + function createWidget3(): Widget3; + module SpecializedGlobalWidget { + class Widget4 { + name: string; + } + function createWidget4(): Widget4; + } +} +//// [privacyCannotNameVarTypeDeclFile_Widgets.d.ts] +export declare class Widget1 { + name: string; +} +export declare function createWidget1(): Widget1; +export declare module SpecializedWidget { + class Widget2 { + name: string; + } + function createWidget2(): Widget2; +} +//// [privacyCannotNameVarTypeDeclFile_exporter.d.ts] +/// +import Widgets = require("privacyCannotNameVarTypeDeclFile_Widgets"); +import Widgets1 = require("GlobalWidgets"); +export declare function createExportedWidget1(): Widgets.Widget1; +export declare function createExportedWidget2(): Widgets.SpecializedWidget.Widget2; +export declare function createExportedWidget3(): Widgets1.Widget3; +export declare function createExportedWidget4(): Widgets1.SpecializedGlobalWidget.Widget4; diff --git a/tests/baselines/reference/privacyFunctionCannotNameParameterTypeDeclFile.errors.txt b/tests/baselines/reference/privacyFunctionCannotNameParameterTypeDeclFile.errors.txt new file mode 100644 index 00000000000..269be5ed425 --- /dev/null +++ b/tests/baselines/reference/privacyFunctionCannotNameParameterTypeDeclFile.errors.txt @@ -0,0 +1,203 @@ +==== tests/cases/compiler/privacyFunctionCannotNameParameterTypeDeclFile_consumer.ts (24 errors) ==== + import exporter = require("privacyFunctionCannotNameParameterTypeDeclFile_exporter"); + export class publicClassWithWithPrivateParmeterTypes { + static myPublicStaticMethod(param = exporter.createExportedWidget1()) { // Error + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! Parameter 'param' of public static method from exported class has or is using name 'Widget1' from external module "tests/cases/compiler/privacyFunctionCannotNameParameterTypeDeclFile_Widgets" but cannot be named. + } + private static myPrivateStaticMethod(param = exporter.createExportedWidget1()) { + } + myPublicMethod(param = exporter.createExportedWidget1()) { // Error + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! Parameter 'param' of public method from exported class has or is using name 'Widget1' from external module "tests/cases/compiler/privacyFunctionCannotNameParameterTypeDeclFile_Widgets" but cannot be named. + } + private myPrivateMethod(param = exporter.createExportedWidget1()) { + } + constructor(param = exporter.createExportedWidget1(), private param1 = exporter.createExportedWidget1(), public param2 = exporter.createExportedWidget1()) { // Error + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! Parameter 'param' of constructor from exported class has or is using name 'Widget1' from external module "tests/cases/compiler/privacyFunctionCannotNameParameterTypeDeclFile_Widgets" but cannot be named. + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! Parameter 'param1' of constructor from exported class has or is using name 'Widget1' from external module "tests/cases/compiler/privacyFunctionCannotNameParameterTypeDeclFile_Widgets" but cannot be named. + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! Parameter 'param2' of constructor from exported class has or is using name 'Widget1' from external module "tests/cases/compiler/privacyFunctionCannotNameParameterTypeDeclFile_Widgets" but cannot be named. + } + } + export class publicClassWithWithPrivateParmeterTypes1 { + static myPublicStaticMethod(param = exporter.createExportedWidget3()) { // Error + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! Parameter 'param' of public static method from exported class has or is using name 'Widget3' from external module "GlobalWidgets" but cannot be named. + } + private static myPrivateStaticMethod(param = exporter.createExportedWidget3()) { + } + myPublicMethod(param = exporter.createExportedWidget3()) { // Error + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! Parameter 'param' of public method from exported class has or is using name 'Widget3' from external module "GlobalWidgets" but cannot be named. + } + private myPrivateMethod(param = exporter.createExportedWidget3()) { + } + constructor(param = exporter.createExportedWidget3(), private param1 = exporter.createExportedWidget3(), public param2 = exporter.createExportedWidget3()) { // Error + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! Parameter 'param' of constructor from exported class has or is using name 'Widget3' from external module "GlobalWidgets" but cannot be named. + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! Parameter 'param1' of constructor from exported class has or is using name 'Widget3' from external module "GlobalWidgets" but cannot be named. + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! Parameter 'param2' of constructor from exported class has or is using name 'Widget3' from external module "GlobalWidgets" but cannot be named. + } + } + + class privateClassWithWithPrivateParmeterTypes { + static myPublicStaticMethod(param = exporter.createExportedWidget1()) { + } + private static myPrivateStaticMethod(param = exporter.createExportedWidget1()) { + } + myPublicMethod(param = exporter.createExportedWidget1()) { + } + private myPrivateMethod(param = exporter.createExportedWidget1()) { + } + constructor(param = exporter.createExportedWidget1(), private param1 = exporter.createExportedWidget1(), public param2 = exporter.createExportedWidget1()) { + } + } + class privateClassWithWithPrivateParmeterTypes2 { + static myPublicStaticMethod(param = exporter.createExportedWidget3()) { + } + private static myPrivateStaticMethod(param = exporter.createExportedWidget3()) { + } + myPublicMethod(param = exporter.createExportedWidget3()) { + } + private myPrivateMethod(param = exporter.createExportedWidget3()) { + } + constructor(param = exporter.createExportedWidget3(), private param1 = exporter.createExportedWidget3(), public param2 = exporter.createExportedWidget3()) { + } + } + + export function publicFunctionWithPrivateParmeterTypes(param = exporter.createExportedWidget1()) { // Error + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! Parameter 'param' of exported function has or is using name 'Widget1' from external module "tests/cases/compiler/privacyFunctionCannotNameParameterTypeDeclFile_Widgets" but cannot be named. + } + function privateFunctionWithPrivateParmeterTypes(param = exporter.createExportedWidget1()) { + } + export function publicFunctionWithPrivateParmeterTypes1(param = exporter.createExportedWidget3()) { // Error + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! Parameter 'param' of exported function has or is using name 'Widget3' from external module "GlobalWidgets" but cannot be named. + } + function privateFunctionWithPrivateParmeterTypes1(param = exporter.createExportedWidget3()) { + } + + + export class publicClassWithPrivateModuleParameterTypes { + static myPublicStaticMethod(param= exporter.createExportedWidget2()) { // Error + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! Parameter 'param' of public static method from exported class has or is using name 'SpecializedWidget.Widget2' from external module "tests/cases/compiler/privacyFunctionCannotNameParameterTypeDeclFile_Widgets" but cannot be named. + } + myPublicMethod(param= exporter.createExportedWidget2()) { // Error + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! Parameter 'param' of public method from exported class has or is using name 'SpecializedWidget.Widget2' from external module "tests/cases/compiler/privacyFunctionCannotNameParameterTypeDeclFile_Widgets" but cannot be named. + } + constructor(param= exporter.createExportedWidget2(), private param1= exporter.createExportedWidget2(), public param2= exporter.createExportedWidget2()) { // Error + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! Parameter 'param' of constructor from exported class has or is using name 'SpecializedWidget.Widget2' from external module "tests/cases/compiler/privacyFunctionCannotNameParameterTypeDeclFile_Widgets" but cannot be named. + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! Parameter 'param1' of constructor from exported class has or is using name 'SpecializedWidget.Widget2' from external module "tests/cases/compiler/privacyFunctionCannotNameParameterTypeDeclFile_Widgets" but cannot be named. + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! Parameter 'param2' of constructor from exported class has or is using name 'SpecializedWidget.Widget2' from external module "tests/cases/compiler/privacyFunctionCannotNameParameterTypeDeclFile_Widgets" but cannot be named. + } + } + export class publicClassWithPrivateModuleParameterTypes2 { + static myPublicStaticMethod(param= exporter.createExportedWidget4()) { // Error + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! Parameter 'param' of public static method from exported class has or is using name 'SpecializedGlobalWidget.Widget4' from external module "GlobalWidgets" but cannot be named. + } + myPublicMethod(param= exporter.createExportedWidget4()) { // Error + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! Parameter 'param' of public method from exported class has or is using name 'SpecializedGlobalWidget.Widget4' from external module "GlobalWidgets" but cannot be named. + } + constructor(param= exporter.createExportedWidget4(), private param1= exporter.createExportedWidget4(), public param2= exporter.createExportedWidget4()) { // Error + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! Parameter 'param' of constructor from exported class has or is using name 'SpecializedGlobalWidget.Widget4' from external module "GlobalWidgets" but cannot be named. + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! Parameter 'param1' of constructor from exported class has or is using name 'SpecializedGlobalWidget.Widget4' from external module "GlobalWidgets" but cannot be named. + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! Parameter 'param2' of constructor from exported class has or is using name 'SpecializedGlobalWidget.Widget4' from external module "GlobalWidgets" but cannot be named. + } + } + export function publicFunctionWithPrivateModuleParameterTypes(param= exporter.createExportedWidget2()) { // Error + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! Parameter 'param' of exported function has or is using name 'SpecializedWidget.Widget2' from external module "tests/cases/compiler/privacyFunctionCannotNameParameterTypeDeclFile_Widgets" but cannot be named. + } + export function publicFunctionWithPrivateModuleParameterTypes1(param= exporter.createExportedWidget4()) { // Error + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! Parameter 'param' of exported function has or is using name 'SpecializedGlobalWidget.Widget4' from external module "GlobalWidgets" but cannot be named. + } + + + class privateClassWithPrivateModuleParameterTypes { + static myPublicStaticMethod(param= exporter.createExportedWidget2()) { + } + myPublicMethod(param= exporter.createExportedWidget2()) { + } + constructor(param= exporter.createExportedWidget2(), private param1= exporter.createExportedWidget2(), public param2= exporter.createExportedWidget2()) { + } + } + class privateClassWithPrivateModuleParameterTypes1 { + static myPublicStaticMethod(param= exporter.createExportedWidget4()) { + } + myPublicMethod(param= exporter.createExportedWidget4()) { + } + constructor(param= exporter.createExportedWidget4(), private param1= exporter.createExportedWidget4(), public param2= exporter.createExportedWidget4()) { + } + } + function privateFunctionWithPrivateModuleParameterTypes(param= exporter.createExportedWidget2()) { + } + function privateFunctionWithPrivateModuleParameterTypes1(param= exporter.createExportedWidget4()) { + } +==== tests/cases/compiler/privacyFunctionCannotNameParameterTypeDeclFile_GlobalWidgets.ts (0 errors) ==== + + + declare module "GlobalWidgets" { + export class Widget3 { + name: string; + } + export function createWidget3(): Widget3; + + export module SpecializedGlobalWidget { + export class Widget4 { + name: string; + } + function createWidget4(): Widget4; + } + } + +==== tests/cases/compiler/privacyFunctionCannotNameParameterTypeDeclFile_Widgets.ts (0 errors) ==== + export class Widget1 { + name = 'one'; + } + export function createWidget1() { + return new Widget1(); + } + + export module SpecializedWidget { + export class Widget2 { + name = 'one'; + } + export function createWidget2() { + return new Widget2(); + } + } + +==== tests/cases/compiler/privacyFunctionCannotNameParameterTypeDeclFile_exporter.ts (0 errors) ==== + /// + import Widgets = require("privacyFunctionCannotNameParameterTypeDeclFile_Widgets"); + import Widgets1 = require("GlobalWidgets"); + export function createExportedWidget1() { + return Widgets.createWidget1(); + } + export function createExportedWidget2() { + return Widgets.SpecializedWidget.createWidget2(); + } + export function createExportedWidget3() { + return Widgets1.createWidget3(); + } + export function createExportedWidget4() { + return Widgets1.SpecializedGlobalWidget.createWidget4(); + } + \ No newline at end of file diff --git a/tests/baselines/reference/privacyFunctionCannotNameParameterTypeDeclFile.js b/tests/baselines/reference/privacyFunctionCannotNameParameterTypeDeclFile.js new file mode 100644 index 00000000000..3db10b3da1a --- /dev/null +++ b/tests/baselines/reference/privacyFunctionCannotNameParameterTypeDeclFile.js @@ -0,0 +1,424 @@ +//// [tests/cases/compiler/privacyFunctionCannotNameParameterTypeDeclFile.ts] //// + +//// [privacyFunctionCannotNameParameterTypeDeclFile_GlobalWidgets.ts] + + +declare module "GlobalWidgets" { + export class Widget3 { + name: string; + } + export function createWidget3(): Widget3; + + export module SpecializedGlobalWidget { + export class Widget4 { + name: string; + } + function createWidget4(): Widget4; + } +} + +//// [privacyFunctionCannotNameParameterTypeDeclFile_Widgets.ts] +export class Widget1 { + name = 'one'; +} +export function createWidget1() { + return new Widget1(); +} + +export module SpecializedWidget { + export class Widget2 { + name = 'one'; + } + export function createWidget2() { + return new Widget2(); + } +} + +//// [privacyFunctionCannotNameParameterTypeDeclFile_exporter.ts] +/// +import Widgets = require("privacyFunctionCannotNameParameterTypeDeclFile_Widgets"); +import Widgets1 = require("GlobalWidgets"); +export function createExportedWidget1() { + return Widgets.createWidget1(); +} +export function createExportedWidget2() { + return Widgets.SpecializedWidget.createWidget2(); +} +export function createExportedWidget3() { + return Widgets1.createWidget3(); +} +export function createExportedWidget4() { + return Widgets1.SpecializedGlobalWidget.createWidget4(); +} + +//// [privacyFunctionCannotNameParameterTypeDeclFile_consumer.ts] +import exporter = require("privacyFunctionCannotNameParameterTypeDeclFile_exporter"); +export class publicClassWithWithPrivateParmeterTypes { + static myPublicStaticMethod(param = exporter.createExportedWidget1()) { // Error + } + private static myPrivateStaticMethod(param = exporter.createExportedWidget1()) { + } + myPublicMethod(param = exporter.createExportedWidget1()) { // Error + } + private myPrivateMethod(param = exporter.createExportedWidget1()) { + } + constructor(param = exporter.createExportedWidget1(), private param1 = exporter.createExportedWidget1(), public param2 = exporter.createExportedWidget1()) { // Error + } +} +export class publicClassWithWithPrivateParmeterTypes1 { + static myPublicStaticMethod(param = exporter.createExportedWidget3()) { // Error + } + private static myPrivateStaticMethod(param = exporter.createExportedWidget3()) { + } + myPublicMethod(param = exporter.createExportedWidget3()) { // Error + } + private myPrivateMethod(param = exporter.createExportedWidget3()) { + } + constructor(param = exporter.createExportedWidget3(), private param1 = exporter.createExportedWidget3(), public param2 = exporter.createExportedWidget3()) { // Error + } +} + +class privateClassWithWithPrivateParmeterTypes { + static myPublicStaticMethod(param = exporter.createExportedWidget1()) { + } + private static myPrivateStaticMethod(param = exporter.createExportedWidget1()) { + } + myPublicMethod(param = exporter.createExportedWidget1()) { + } + private myPrivateMethod(param = exporter.createExportedWidget1()) { + } + constructor(param = exporter.createExportedWidget1(), private param1 = exporter.createExportedWidget1(), public param2 = exporter.createExportedWidget1()) { + } +} +class privateClassWithWithPrivateParmeterTypes2 { + static myPublicStaticMethod(param = exporter.createExportedWidget3()) { + } + private static myPrivateStaticMethod(param = exporter.createExportedWidget3()) { + } + myPublicMethod(param = exporter.createExportedWidget3()) { + } + private myPrivateMethod(param = exporter.createExportedWidget3()) { + } + constructor(param = exporter.createExportedWidget3(), private param1 = exporter.createExportedWidget3(), public param2 = exporter.createExportedWidget3()) { + } +} + +export function publicFunctionWithPrivateParmeterTypes(param = exporter.createExportedWidget1()) { // Error +} +function privateFunctionWithPrivateParmeterTypes(param = exporter.createExportedWidget1()) { +} +export function publicFunctionWithPrivateParmeterTypes1(param = exporter.createExportedWidget3()) { // Error +} +function privateFunctionWithPrivateParmeterTypes1(param = exporter.createExportedWidget3()) { +} + + +export class publicClassWithPrivateModuleParameterTypes { + static myPublicStaticMethod(param= exporter.createExportedWidget2()) { // Error + } + myPublicMethod(param= exporter.createExportedWidget2()) { // Error + } + constructor(param= exporter.createExportedWidget2(), private param1= exporter.createExportedWidget2(), public param2= exporter.createExportedWidget2()) { // Error + } +} +export class publicClassWithPrivateModuleParameterTypes2 { + static myPublicStaticMethod(param= exporter.createExportedWidget4()) { // Error + } + myPublicMethod(param= exporter.createExportedWidget4()) { // Error + } + constructor(param= exporter.createExportedWidget4(), private param1= exporter.createExportedWidget4(), public param2= exporter.createExportedWidget4()) { // Error + } +} +export function publicFunctionWithPrivateModuleParameterTypes(param= exporter.createExportedWidget2()) { // Error +} +export function publicFunctionWithPrivateModuleParameterTypes1(param= exporter.createExportedWidget4()) { // Error +} + + +class privateClassWithPrivateModuleParameterTypes { + static myPublicStaticMethod(param= exporter.createExportedWidget2()) { + } + myPublicMethod(param= exporter.createExportedWidget2()) { + } + constructor(param= exporter.createExportedWidget2(), private param1= exporter.createExportedWidget2(), public param2= exporter.createExportedWidget2()) { + } +} +class privateClassWithPrivateModuleParameterTypes1 { + static myPublicStaticMethod(param= exporter.createExportedWidget4()) { + } + myPublicMethod(param= exporter.createExportedWidget4()) { + } + constructor(param= exporter.createExportedWidget4(), private param1= exporter.createExportedWidget4(), public param2= exporter.createExportedWidget4()) { + } +} +function privateFunctionWithPrivateModuleParameterTypes(param= exporter.createExportedWidget2()) { +} +function privateFunctionWithPrivateModuleParameterTypes1(param= exporter.createExportedWidget4()) { +} + +//// [privacyFunctionCannotNameParameterTypeDeclFile_GlobalWidgets.js] +//// [privacyFunctionCannotNameParameterTypeDeclFile_Widgets.js] +var Widget1 = (function () { + function Widget1() { + this.name = 'one'; + } + return Widget1; +})(); +exports.Widget1 = Widget1; +function createWidget1() { + return new Widget1(); +} +exports.createWidget1 = createWidget1; +(function (SpecializedWidget) { + var Widget2 = (function () { + function Widget2() { + this.name = 'one'; + } + return Widget2; + })(); + SpecializedWidget.Widget2 = Widget2; + function createWidget2() { + return new Widget2(); + } + SpecializedWidget.createWidget2 = createWidget2; +})(exports.SpecializedWidget || (exports.SpecializedWidget = {})); +var SpecializedWidget = exports.SpecializedWidget; +//// [privacyFunctionCannotNameParameterTypeDeclFile_exporter.js] +var Widgets = require("privacyFunctionCannotNameParameterTypeDeclFile_Widgets"); +var Widgets1 = require("GlobalWidgets"); +function createExportedWidget1() { + return Widgets.createWidget1(); +} +exports.createExportedWidget1 = createExportedWidget1; +function createExportedWidget2() { + return Widgets.SpecializedWidget.createWidget2(); +} +exports.createExportedWidget2 = createExportedWidget2; +function createExportedWidget3() { + return Widgets1.createWidget3(); +} +exports.createExportedWidget3 = createExportedWidget3; +function createExportedWidget4() { + return Widgets1.SpecializedGlobalWidget.createWidget4(); +} +exports.createExportedWidget4 = createExportedWidget4; +//// [privacyFunctionCannotNameParameterTypeDeclFile_consumer.js] +var exporter = require("privacyFunctionCannotNameParameterTypeDeclFile_exporter"); +var publicClassWithWithPrivateParmeterTypes = (function () { + function publicClassWithWithPrivateParmeterTypes(param, param1, param2) { + if (param === void 0) { param = exporter.createExportedWidget1(); } + if (param1 === void 0) { param1 = exporter.createExportedWidget1(); } + if (param2 === void 0) { param2 = exporter.createExportedWidget1(); } + this.param1 = param1; + this.param2 = param2; + } + publicClassWithWithPrivateParmeterTypes.myPublicStaticMethod = function (param) { + if (param === void 0) { param = exporter.createExportedWidget1(); } + }; + publicClassWithWithPrivateParmeterTypes.myPrivateStaticMethod = function (param) { + if (param === void 0) { param = exporter.createExportedWidget1(); } + }; + publicClassWithWithPrivateParmeterTypes.prototype.myPublicMethod = function (param) { + if (param === void 0) { param = exporter.createExportedWidget1(); } + }; + publicClassWithWithPrivateParmeterTypes.prototype.myPrivateMethod = function (param) { + if (param === void 0) { param = exporter.createExportedWidget1(); } + }; + return publicClassWithWithPrivateParmeterTypes; +})(); +exports.publicClassWithWithPrivateParmeterTypes = publicClassWithWithPrivateParmeterTypes; +var publicClassWithWithPrivateParmeterTypes1 = (function () { + function publicClassWithWithPrivateParmeterTypes1(param, param1, param2) { + if (param === void 0) { param = exporter.createExportedWidget3(); } + if (param1 === void 0) { param1 = exporter.createExportedWidget3(); } + if (param2 === void 0) { param2 = exporter.createExportedWidget3(); } + this.param1 = param1; + this.param2 = param2; + } + publicClassWithWithPrivateParmeterTypes1.myPublicStaticMethod = function (param) { + if (param === void 0) { param = exporter.createExportedWidget3(); } + }; + publicClassWithWithPrivateParmeterTypes1.myPrivateStaticMethod = function (param) { + if (param === void 0) { param = exporter.createExportedWidget3(); } + }; + publicClassWithWithPrivateParmeterTypes1.prototype.myPublicMethod = function (param) { + if (param === void 0) { param = exporter.createExportedWidget3(); } + }; + publicClassWithWithPrivateParmeterTypes1.prototype.myPrivateMethod = function (param) { + if (param === void 0) { param = exporter.createExportedWidget3(); } + }; + return publicClassWithWithPrivateParmeterTypes1; +})(); +exports.publicClassWithWithPrivateParmeterTypes1 = publicClassWithWithPrivateParmeterTypes1; +var privateClassWithWithPrivateParmeterTypes = (function () { + function privateClassWithWithPrivateParmeterTypes(param, param1, param2) { + if (param === void 0) { param = exporter.createExportedWidget1(); } + if (param1 === void 0) { param1 = exporter.createExportedWidget1(); } + if (param2 === void 0) { param2 = exporter.createExportedWidget1(); } + this.param1 = param1; + this.param2 = param2; + } + privateClassWithWithPrivateParmeterTypes.myPublicStaticMethod = function (param) { + if (param === void 0) { param = exporter.createExportedWidget1(); } + }; + privateClassWithWithPrivateParmeterTypes.myPrivateStaticMethod = function (param) { + if (param === void 0) { param = exporter.createExportedWidget1(); } + }; + privateClassWithWithPrivateParmeterTypes.prototype.myPublicMethod = function (param) { + if (param === void 0) { param = exporter.createExportedWidget1(); } + }; + privateClassWithWithPrivateParmeterTypes.prototype.myPrivateMethod = function (param) { + if (param === void 0) { param = exporter.createExportedWidget1(); } + }; + return privateClassWithWithPrivateParmeterTypes; +})(); +var privateClassWithWithPrivateParmeterTypes2 = (function () { + function privateClassWithWithPrivateParmeterTypes2(param, param1, param2) { + if (param === void 0) { param = exporter.createExportedWidget3(); } + if (param1 === void 0) { param1 = exporter.createExportedWidget3(); } + if (param2 === void 0) { param2 = exporter.createExportedWidget3(); } + this.param1 = param1; + this.param2 = param2; + } + privateClassWithWithPrivateParmeterTypes2.myPublicStaticMethod = function (param) { + if (param === void 0) { param = exporter.createExportedWidget3(); } + }; + privateClassWithWithPrivateParmeterTypes2.myPrivateStaticMethod = function (param) { + if (param === void 0) { param = exporter.createExportedWidget3(); } + }; + privateClassWithWithPrivateParmeterTypes2.prototype.myPublicMethod = function (param) { + if (param === void 0) { param = exporter.createExportedWidget3(); } + }; + privateClassWithWithPrivateParmeterTypes2.prototype.myPrivateMethod = function (param) { + if (param === void 0) { param = exporter.createExportedWidget3(); } + }; + return privateClassWithWithPrivateParmeterTypes2; +})(); +function publicFunctionWithPrivateParmeterTypes(param) { + if (param === void 0) { param = exporter.createExportedWidget1(); } +} +exports.publicFunctionWithPrivateParmeterTypes = publicFunctionWithPrivateParmeterTypes; +function privateFunctionWithPrivateParmeterTypes(param) { + if (param === void 0) { param = exporter.createExportedWidget1(); } +} +function publicFunctionWithPrivateParmeterTypes1(param) { + if (param === void 0) { param = exporter.createExportedWidget3(); } +} +exports.publicFunctionWithPrivateParmeterTypes1 = publicFunctionWithPrivateParmeterTypes1; +function privateFunctionWithPrivateParmeterTypes1(param) { + if (param === void 0) { param = exporter.createExportedWidget3(); } +} +var publicClassWithPrivateModuleParameterTypes = (function () { + function publicClassWithPrivateModuleParameterTypes(param, param1, param2) { + if (param === void 0) { param = exporter.createExportedWidget2(); } + if (param1 === void 0) { param1 = exporter.createExportedWidget2(); } + if (param2 === void 0) { param2 = exporter.createExportedWidget2(); } + this.param1 = param1; + this.param2 = param2; + } + publicClassWithPrivateModuleParameterTypes.myPublicStaticMethod = function (param) { + if (param === void 0) { param = exporter.createExportedWidget2(); } + }; + publicClassWithPrivateModuleParameterTypes.prototype.myPublicMethod = function (param) { + if (param === void 0) { param = exporter.createExportedWidget2(); } + }; + return publicClassWithPrivateModuleParameterTypes; +})(); +exports.publicClassWithPrivateModuleParameterTypes = publicClassWithPrivateModuleParameterTypes; +var publicClassWithPrivateModuleParameterTypes2 = (function () { + function publicClassWithPrivateModuleParameterTypes2(param, param1, param2) { + if (param === void 0) { param = exporter.createExportedWidget4(); } + if (param1 === void 0) { param1 = exporter.createExportedWidget4(); } + if (param2 === void 0) { param2 = exporter.createExportedWidget4(); } + this.param1 = param1; + this.param2 = param2; + } + publicClassWithPrivateModuleParameterTypes2.myPublicStaticMethod = function (param) { + if (param === void 0) { param = exporter.createExportedWidget4(); } + }; + publicClassWithPrivateModuleParameterTypes2.prototype.myPublicMethod = function (param) { + if (param === void 0) { param = exporter.createExportedWidget4(); } + }; + return publicClassWithPrivateModuleParameterTypes2; +})(); +exports.publicClassWithPrivateModuleParameterTypes2 = publicClassWithPrivateModuleParameterTypes2; +function publicFunctionWithPrivateModuleParameterTypes(param) { + if (param === void 0) { param = exporter.createExportedWidget2(); } +} +exports.publicFunctionWithPrivateModuleParameterTypes = publicFunctionWithPrivateModuleParameterTypes; +function publicFunctionWithPrivateModuleParameterTypes1(param) { + if (param === void 0) { param = exporter.createExportedWidget4(); } +} +exports.publicFunctionWithPrivateModuleParameterTypes1 = publicFunctionWithPrivateModuleParameterTypes1; +var privateClassWithPrivateModuleParameterTypes = (function () { + function privateClassWithPrivateModuleParameterTypes(param, param1, param2) { + if (param === void 0) { param = exporter.createExportedWidget2(); } + if (param1 === void 0) { param1 = exporter.createExportedWidget2(); } + if (param2 === void 0) { param2 = exporter.createExportedWidget2(); } + this.param1 = param1; + this.param2 = param2; + } + privateClassWithPrivateModuleParameterTypes.myPublicStaticMethod = function (param) { + if (param === void 0) { param = exporter.createExportedWidget2(); } + }; + privateClassWithPrivateModuleParameterTypes.prototype.myPublicMethod = function (param) { + if (param === void 0) { param = exporter.createExportedWidget2(); } + }; + return privateClassWithPrivateModuleParameterTypes; +})(); +var privateClassWithPrivateModuleParameterTypes1 = (function () { + function privateClassWithPrivateModuleParameterTypes1(param, param1, param2) { + if (param === void 0) { param = exporter.createExportedWidget4(); } + if (param1 === void 0) { param1 = exporter.createExportedWidget4(); } + if (param2 === void 0) { param2 = exporter.createExportedWidget4(); } + this.param1 = param1; + this.param2 = param2; + } + privateClassWithPrivateModuleParameterTypes1.myPublicStaticMethod = function (param) { + if (param === void 0) { param = exporter.createExportedWidget4(); } + }; + privateClassWithPrivateModuleParameterTypes1.prototype.myPublicMethod = function (param) { + if (param === void 0) { param = exporter.createExportedWidget4(); } + }; + return privateClassWithPrivateModuleParameterTypes1; +})(); +function privateFunctionWithPrivateModuleParameterTypes(param) { + if (param === void 0) { param = exporter.createExportedWidget2(); } +} +function privateFunctionWithPrivateModuleParameterTypes1(param) { + if (param === void 0) { param = exporter.createExportedWidget4(); } +} + + +//// [privacyFunctionCannotNameParameterTypeDeclFile_GlobalWidgets.d.ts] +declare module "GlobalWidgets" { + class Widget3 { + name: string; + } + function createWidget3(): Widget3; + module SpecializedGlobalWidget { + class Widget4 { + name: string; + } + function createWidget4(): Widget4; + } +} +//// [privacyFunctionCannotNameParameterTypeDeclFile_Widgets.d.ts] +export declare class Widget1 { + name: string; +} +export declare function createWidget1(): Widget1; +export declare module SpecializedWidget { + class Widget2 { + name: string; + } + function createWidget2(): Widget2; +} +//// [privacyFunctionCannotNameParameterTypeDeclFile_exporter.d.ts] +/// +import Widgets = require("privacyFunctionCannotNameParameterTypeDeclFile_Widgets"); +import Widgets1 = require("GlobalWidgets"); +export declare function createExportedWidget1(): Widgets.Widget1; +export declare function createExportedWidget2(): Widgets.SpecializedWidget.Widget2; +export declare function createExportedWidget3(): Widgets1.Widget3; +export declare function createExportedWidget4(): Widgets1.SpecializedGlobalWidget.Widget4; diff --git a/tests/baselines/reference/privacyFunctionCannotNameReturnTypeDeclFile.errors.txt b/tests/baselines/reference/privacyFunctionCannotNameReturnTypeDeclFile.errors.txt new file mode 100644 index 00000000000..834e3d783c6 --- /dev/null +++ b/tests/baselines/reference/privacyFunctionCannotNameReturnTypeDeclFile.errors.txt @@ -0,0 +1,186 @@ +==== tests/cases/compiler/privacyFunctionReturnTypeDeclFile_consumer.ts (12 errors) ==== + import exporter = require("privacyFunctionReturnTypeDeclFile_exporter"); + export class publicClassWithWithPrivateParmeterTypes { + static myPublicStaticMethod() { // Error + ~~~~~~~~~~~~~~~~~~~~ +!!! Return type of public static method from exported class has or is using name 'Widget1' from external module "tests/cases/compiler/privacyFunctionReturnTypeDeclFile_Widgets" but cannot be named. + return exporter.createExportedWidget1(); + } + private static myPrivateStaticMethod() { + return exporter.createExportedWidget1();; + } + myPublicMethod() { // Error + ~~~~~~~~~~~~~~ +!!! Return type of public method from exported class has or is using name 'Widget1' from external module "tests/cases/compiler/privacyFunctionReturnTypeDeclFile_Widgets" but cannot be named. + return exporter.createExportedWidget1();; + } + private myPrivateMethod() { + return exporter.createExportedWidget1();; + } + static myPublicStaticMethod1() { // Error + ~~~~~~~~~~~~~~~~~~~~~ +!!! Return type of public static method from exported class has or is using name 'Widget3' from external module "GlobalWidgets" but cannot be named. + return exporter.createExportedWidget3(); + } + private static myPrivateStaticMethod1() { + return exporter.createExportedWidget3();; + } + myPublicMethod1() { // Error + ~~~~~~~~~~~~~~~ +!!! Return type of public method from exported class has or is using name 'Widget3' from external module "GlobalWidgets" but cannot be named. + return exporter.createExportedWidget3();; + } + private myPrivateMethod1() { + return exporter.createExportedWidget3();; + } + } + + class privateClassWithWithPrivateParmeterTypes { + static myPublicStaticMethod() { + return exporter.createExportedWidget1(); + } + private static myPrivateStaticMethod() { + return exporter.createExportedWidget1();; + } + myPublicMethod() { + return exporter.createExportedWidget1();; + } + private myPrivateMethod() { + return exporter.createExportedWidget1();; + } + static myPublicStaticMethod1() { + return exporter.createExportedWidget3(); + } + private static myPrivateStaticMethod1() { + return exporter.createExportedWidget3();; + } + myPublicMethod1() { + return exporter.createExportedWidget3();; + } + private myPrivateMethod1() { + return exporter.createExportedWidget3();; + } + } + + export function publicFunctionWithPrivateParmeterTypes() { // Error + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! Return type of exported function has or is using name 'Widget1' from external module "tests/cases/compiler/privacyFunctionReturnTypeDeclFile_Widgets" but cannot be named. + return exporter.createExportedWidget1(); + } + function privateFunctionWithPrivateParmeterTypes() { + return exporter.createExportedWidget1(); + } + export function publicFunctionWithPrivateParmeterTypes1() { // Error + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! Return type of exported function has or is using name 'Widget3' from external module "GlobalWidgets" but cannot be named. + return exporter.createExportedWidget3(); + } + function privateFunctionWithPrivateParmeterTypes1() { + return exporter.createExportedWidget3(); + } + + export class publicClassWithPrivateModuleReturnTypes { + static myPublicStaticMethod() { // Error + ~~~~~~~~~~~~~~~~~~~~ +!!! Return type of public static method from exported class has or is using name 'SpecializedWidget.Widget2' from external module "tests/cases/compiler/privacyFunctionReturnTypeDeclFile_Widgets" but cannot be named. + return exporter.createExportedWidget2(); + } + myPublicMethod() { // Error + ~~~~~~~~~~~~~~ +!!! Return type of public method from exported class has or is using name 'SpecializedWidget.Widget2' from external module "tests/cases/compiler/privacyFunctionReturnTypeDeclFile_Widgets" but cannot be named. + return exporter.createExportedWidget2(); + } + static myPublicStaticMethod1() { // Error + ~~~~~~~~~~~~~~~~~~~~~ +!!! Return type of public static method from exported class has or is using name 'SpecializedGlobalWidget.Widget4' from external module "GlobalWidgets" but cannot be named. + return exporter.createExportedWidget4(); + } + myPublicMethod1() { // Error + ~~~~~~~~~~~~~~~ +!!! Return type of public method from exported class has or is using name 'SpecializedGlobalWidget.Widget4' from external module "GlobalWidgets" but cannot be named. + return exporter.createExportedWidget4(); + } + } + export function publicFunctionWithPrivateModuleReturnTypes() { // Error + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! Return type of exported function has or is using name 'SpecializedWidget.Widget2' from external module "tests/cases/compiler/privacyFunctionReturnTypeDeclFile_Widgets" but cannot be named. + return exporter.createExportedWidget2(); + } + export function publicFunctionWithPrivateModuleReturnTypes1() { // Error + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! Return type of exported function has or is using name 'SpecializedGlobalWidget.Widget4' from external module "GlobalWidgets" but cannot be named. + return exporter.createExportedWidget4(); + } + + class privateClassWithPrivateModuleReturnTypes { + static myPublicStaticMethod() { + return exporter.createExportedWidget2(); + } + myPublicMethod() { + return exporter.createExportedWidget2(); + } + static myPublicStaticMethod1() { // Error + return exporter.createExportedWidget4(); + } + myPublicMethod1() { // Error + return exporter.createExportedWidget4(); + } + } + function privateFunctionWithPrivateModuleReturnTypes() { + return exporter.createExportedWidget2(); + } + function privateFunctionWithPrivateModuleReturnTypes1() { + return exporter.createExportedWidget4(); + } + +==== tests/cases/compiler/privacyFunctionReturnTypeDeclFile_GlobalWidgets.ts (0 errors) ==== + + + declare module "GlobalWidgets" { + export class Widget3 { + name: string; + } + export function createWidget3(): Widget3; + + export module SpecializedGlobalWidget { + export class Widget4 { + name: string; + } + function createWidget4(): Widget4; + } + } + +==== tests/cases/compiler/privacyFunctionReturnTypeDeclFile_Widgets.ts (0 errors) ==== + export class Widget1 { + name = 'one'; + } + export function createWidget1() { + return new Widget1(); + } + + export module SpecializedWidget { + export class Widget2 { + name = 'one'; + } + export function createWidget2() { + return new Widget2(); + } + } + +==== tests/cases/compiler/privacyFunctionReturnTypeDeclFile_exporter.ts (0 errors) ==== + /// + import Widgets = require("privacyFunctionReturnTypeDeclFile_Widgets"); + import Widgets1 = require("GlobalWidgets"); + export function createExportedWidget1() { + return Widgets.createWidget1(); + } + export function createExportedWidget2() { + return Widgets.SpecializedWidget.createWidget2(); + } + export function createExportedWidget3() { + return Widgets1.createWidget3(); + } + export function createExportedWidget4() { + return Widgets1.SpecializedGlobalWidget.createWidget4(); + } + \ No newline at end of file diff --git a/tests/baselines/reference/privacyFunctionCannotNameReturnTypeDeclFile.js b/tests/baselines/reference/privacyFunctionCannotNameReturnTypeDeclFile.js new file mode 100644 index 00000000000..603a51467e8 --- /dev/null +++ b/tests/baselines/reference/privacyFunctionCannotNameReturnTypeDeclFile.js @@ -0,0 +1,381 @@ +//// [tests/cases/compiler/privacyFunctionCannotNameReturnTypeDeclFile.ts] //// + +//// [privacyFunctionReturnTypeDeclFile_GlobalWidgets.ts] + + +declare module "GlobalWidgets" { + export class Widget3 { + name: string; + } + export function createWidget3(): Widget3; + + export module SpecializedGlobalWidget { + export class Widget4 { + name: string; + } + function createWidget4(): Widget4; + } +} + +//// [privacyFunctionReturnTypeDeclFile_Widgets.ts] +export class Widget1 { + name = 'one'; +} +export function createWidget1() { + return new Widget1(); +} + +export module SpecializedWidget { + export class Widget2 { + name = 'one'; + } + export function createWidget2() { + return new Widget2(); + } +} + +//// [privacyFunctionReturnTypeDeclFile_exporter.ts] +/// +import Widgets = require("privacyFunctionReturnTypeDeclFile_Widgets"); +import Widgets1 = require("GlobalWidgets"); +export function createExportedWidget1() { + return Widgets.createWidget1(); +} +export function createExportedWidget2() { + return Widgets.SpecializedWidget.createWidget2(); +} +export function createExportedWidget3() { + return Widgets1.createWidget3(); +} +export function createExportedWidget4() { + return Widgets1.SpecializedGlobalWidget.createWidget4(); +} + +//// [privacyFunctionReturnTypeDeclFile_consumer.ts] +import exporter = require("privacyFunctionReturnTypeDeclFile_exporter"); +export class publicClassWithWithPrivateParmeterTypes { + static myPublicStaticMethod() { // Error + return exporter.createExportedWidget1(); + } + private static myPrivateStaticMethod() { + return exporter.createExportedWidget1();; + } + myPublicMethod() { // Error + return exporter.createExportedWidget1();; + } + private myPrivateMethod() { + return exporter.createExportedWidget1();; + } + static myPublicStaticMethod1() { // Error + return exporter.createExportedWidget3(); + } + private static myPrivateStaticMethod1() { + return exporter.createExportedWidget3();; + } + myPublicMethod1() { // Error + return exporter.createExportedWidget3();; + } + private myPrivateMethod1() { + return exporter.createExportedWidget3();; + } +} + +class privateClassWithWithPrivateParmeterTypes { + static myPublicStaticMethod() { + return exporter.createExportedWidget1(); + } + private static myPrivateStaticMethod() { + return exporter.createExportedWidget1();; + } + myPublicMethod() { + return exporter.createExportedWidget1();; + } + private myPrivateMethod() { + return exporter.createExportedWidget1();; + } + static myPublicStaticMethod1() { + return exporter.createExportedWidget3(); + } + private static myPrivateStaticMethod1() { + return exporter.createExportedWidget3();; + } + myPublicMethod1() { + return exporter.createExportedWidget3();; + } + private myPrivateMethod1() { + return exporter.createExportedWidget3();; + } +} + +export function publicFunctionWithPrivateParmeterTypes() { // Error + return exporter.createExportedWidget1(); +} +function privateFunctionWithPrivateParmeterTypes() { + return exporter.createExportedWidget1(); +} +export function publicFunctionWithPrivateParmeterTypes1() { // Error + return exporter.createExportedWidget3(); +} +function privateFunctionWithPrivateParmeterTypes1() { + return exporter.createExportedWidget3(); +} + +export class publicClassWithPrivateModuleReturnTypes { + static myPublicStaticMethod() { // Error + return exporter.createExportedWidget2(); + } + myPublicMethod() { // Error + return exporter.createExportedWidget2(); + } + static myPublicStaticMethod1() { // Error + return exporter.createExportedWidget4(); + } + myPublicMethod1() { // Error + return exporter.createExportedWidget4(); + } +} +export function publicFunctionWithPrivateModuleReturnTypes() { // Error + return exporter.createExportedWidget2(); +} +export function publicFunctionWithPrivateModuleReturnTypes1() { // Error + return exporter.createExportedWidget4(); +} + +class privateClassWithPrivateModuleReturnTypes { + static myPublicStaticMethod() { + return exporter.createExportedWidget2(); + } + myPublicMethod() { + return exporter.createExportedWidget2(); + } + static myPublicStaticMethod1() { // Error + return exporter.createExportedWidget4(); + } + myPublicMethod1() { // Error + return exporter.createExportedWidget4(); + } +} +function privateFunctionWithPrivateModuleReturnTypes() { + return exporter.createExportedWidget2(); +} +function privateFunctionWithPrivateModuleReturnTypes1() { + return exporter.createExportedWidget4(); +} + + +//// [privacyFunctionReturnTypeDeclFile_GlobalWidgets.js] +//// [privacyFunctionReturnTypeDeclFile_Widgets.js] +var Widget1 = (function () { + function Widget1() { + this.name = 'one'; + } + return Widget1; +})(); +exports.Widget1 = Widget1; +function createWidget1() { + return new Widget1(); +} +exports.createWidget1 = createWidget1; +(function (SpecializedWidget) { + var Widget2 = (function () { + function Widget2() { + this.name = 'one'; + } + return Widget2; + })(); + SpecializedWidget.Widget2 = Widget2; + function createWidget2() { + return new Widget2(); + } + SpecializedWidget.createWidget2 = createWidget2; +})(exports.SpecializedWidget || (exports.SpecializedWidget = {})); +var SpecializedWidget = exports.SpecializedWidget; +//// [privacyFunctionReturnTypeDeclFile_exporter.js] +var Widgets = require("privacyFunctionReturnTypeDeclFile_Widgets"); +var Widgets1 = require("GlobalWidgets"); +function createExportedWidget1() { + return Widgets.createWidget1(); +} +exports.createExportedWidget1 = createExportedWidget1; +function createExportedWidget2() { + return Widgets.SpecializedWidget.createWidget2(); +} +exports.createExportedWidget2 = createExportedWidget2; +function createExportedWidget3() { + return Widgets1.createWidget3(); +} +exports.createExportedWidget3 = createExportedWidget3; +function createExportedWidget4() { + return Widgets1.SpecializedGlobalWidget.createWidget4(); +} +exports.createExportedWidget4 = createExportedWidget4; +//// [privacyFunctionReturnTypeDeclFile_consumer.js] +var exporter = require("privacyFunctionReturnTypeDeclFile_exporter"); +var publicClassWithWithPrivateParmeterTypes = (function () { + function publicClassWithWithPrivateParmeterTypes() { + } + publicClassWithWithPrivateParmeterTypes.myPublicStaticMethod = function () { + return exporter.createExportedWidget1(); + }; + publicClassWithWithPrivateParmeterTypes.myPrivateStaticMethod = function () { + return exporter.createExportedWidget1(); + ; + }; + publicClassWithWithPrivateParmeterTypes.prototype.myPublicMethod = function () { + return exporter.createExportedWidget1(); + ; + }; + publicClassWithWithPrivateParmeterTypes.prototype.myPrivateMethod = function () { + return exporter.createExportedWidget1(); + ; + }; + publicClassWithWithPrivateParmeterTypes.myPublicStaticMethod1 = function () { + return exporter.createExportedWidget3(); + }; + publicClassWithWithPrivateParmeterTypes.myPrivateStaticMethod1 = function () { + return exporter.createExportedWidget3(); + ; + }; + publicClassWithWithPrivateParmeterTypes.prototype.myPublicMethod1 = function () { + return exporter.createExportedWidget3(); + ; + }; + publicClassWithWithPrivateParmeterTypes.prototype.myPrivateMethod1 = function () { + return exporter.createExportedWidget3(); + ; + }; + return publicClassWithWithPrivateParmeterTypes; +})(); +exports.publicClassWithWithPrivateParmeterTypes = publicClassWithWithPrivateParmeterTypes; +var privateClassWithWithPrivateParmeterTypes = (function () { + function privateClassWithWithPrivateParmeterTypes() { + } + privateClassWithWithPrivateParmeterTypes.myPublicStaticMethod = function () { + return exporter.createExportedWidget1(); + }; + privateClassWithWithPrivateParmeterTypes.myPrivateStaticMethod = function () { + return exporter.createExportedWidget1(); + ; + }; + privateClassWithWithPrivateParmeterTypes.prototype.myPublicMethod = function () { + return exporter.createExportedWidget1(); + ; + }; + privateClassWithWithPrivateParmeterTypes.prototype.myPrivateMethod = function () { + return exporter.createExportedWidget1(); + ; + }; + privateClassWithWithPrivateParmeterTypes.myPublicStaticMethod1 = function () { + return exporter.createExportedWidget3(); + }; + privateClassWithWithPrivateParmeterTypes.myPrivateStaticMethod1 = function () { + return exporter.createExportedWidget3(); + ; + }; + privateClassWithWithPrivateParmeterTypes.prototype.myPublicMethod1 = function () { + return exporter.createExportedWidget3(); + ; + }; + privateClassWithWithPrivateParmeterTypes.prototype.myPrivateMethod1 = function () { + return exporter.createExportedWidget3(); + ; + }; + return privateClassWithWithPrivateParmeterTypes; +})(); +function publicFunctionWithPrivateParmeterTypes() { + return exporter.createExportedWidget1(); +} +exports.publicFunctionWithPrivateParmeterTypes = publicFunctionWithPrivateParmeterTypes; +function privateFunctionWithPrivateParmeterTypes() { + return exporter.createExportedWidget1(); +} +function publicFunctionWithPrivateParmeterTypes1() { + return exporter.createExportedWidget3(); +} +exports.publicFunctionWithPrivateParmeterTypes1 = publicFunctionWithPrivateParmeterTypes1; +function privateFunctionWithPrivateParmeterTypes1() { + return exporter.createExportedWidget3(); +} +var publicClassWithPrivateModuleReturnTypes = (function () { + function publicClassWithPrivateModuleReturnTypes() { + } + publicClassWithPrivateModuleReturnTypes.myPublicStaticMethod = function () { + return exporter.createExportedWidget2(); + }; + publicClassWithPrivateModuleReturnTypes.prototype.myPublicMethod = function () { + return exporter.createExportedWidget2(); + }; + publicClassWithPrivateModuleReturnTypes.myPublicStaticMethod1 = function () { + return exporter.createExportedWidget4(); + }; + publicClassWithPrivateModuleReturnTypes.prototype.myPublicMethod1 = function () { + return exporter.createExportedWidget4(); + }; + return publicClassWithPrivateModuleReturnTypes; +})(); +exports.publicClassWithPrivateModuleReturnTypes = publicClassWithPrivateModuleReturnTypes; +function publicFunctionWithPrivateModuleReturnTypes() { + return exporter.createExportedWidget2(); +} +exports.publicFunctionWithPrivateModuleReturnTypes = publicFunctionWithPrivateModuleReturnTypes; +function publicFunctionWithPrivateModuleReturnTypes1() { + return exporter.createExportedWidget4(); +} +exports.publicFunctionWithPrivateModuleReturnTypes1 = publicFunctionWithPrivateModuleReturnTypes1; +var privateClassWithPrivateModuleReturnTypes = (function () { + function privateClassWithPrivateModuleReturnTypes() { + } + privateClassWithPrivateModuleReturnTypes.myPublicStaticMethod = function () { + return exporter.createExportedWidget2(); + }; + privateClassWithPrivateModuleReturnTypes.prototype.myPublicMethod = function () { + return exporter.createExportedWidget2(); + }; + privateClassWithPrivateModuleReturnTypes.myPublicStaticMethod1 = function () { + return exporter.createExportedWidget4(); + }; + privateClassWithPrivateModuleReturnTypes.prototype.myPublicMethod1 = function () { + return exporter.createExportedWidget4(); + }; + return privateClassWithPrivateModuleReturnTypes; +})(); +function privateFunctionWithPrivateModuleReturnTypes() { + return exporter.createExportedWidget2(); +} +function privateFunctionWithPrivateModuleReturnTypes1() { + return exporter.createExportedWidget4(); +} + + +//// [privacyFunctionReturnTypeDeclFile_GlobalWidgets.d.ts] +declare module "GlobalWidgets" { + class Widget3 { + name: string; + } + function createWidget3(): Widget3; + module SpecializedGlobalWidget { + class Widget4 { + name: string; + } + function createWidget4(): Widget4; + } +} +//// [privacyFunctionReturnTypeDeclFile_Widgets.d.ts] +export declare class Widget1 { + name: string; +} +export declare function createWidget1(): Widget1; +export declare module SpecializedWidget { + class Widget2 { + name: string; + } + function createWidget2(): Widget2; +} +//// [privacyFunctionReturnTypeDeclFile_exporter.d.ts] +/// +import Widgets = require("privacyFunctionReturnTypeDeclFile_Widgets"); +import Widgets1 = require("GlobalWidgets"); +export declare function createExportedWidget1(): Widgets.Widget1; +export declare function createExportedWidget2(): Widgets.SpecializedWidget.Widget2; +export declare function createExportedWidget3(): Widgets1.Widget3; +export declare function createExportedWidget4(): Widgets1.SpecializedGlobalWidget.Widget4; diff --git a/tests/cases/compiler/privacyCannotNameAccessorDeclFile.ts b/tests/cases/compiler/privacyCannotNameAccessorDeclFile.ts new file mode 100644 index 00000000000..1150cf963bf --- /dev/null +++ b/tests/cases/compiler/privacyCannotNameAccessorDeclFile.ts @@ -0,0 +1,138 @@ +// @target: ES5 +// @module: commonjs +// @declaration: true + +// @Filename: privacyCannotNameAccessorDeclFile_GlobalWidgets.ts +declare module "GlobalWidgets" { + export class Widget3 { + name: string; + } + export function createWidget3(): Widget3; + + export module SpecializedGlobalWidget { + export class Widget4 { + name: string; + } + function createWidget4(): Widget4; + } +} + +// @Filename: privacyCannotNameAccessorDeclFile_Widgets.ts +export class Widget1 { + name = 'one'; +} +export function createWidget1() { + return new Widget1(); +} + +export module SpecializedWidget { + export class Widget2 { + name = 'one'; + } + export function createWidget2() { + return new Widget2(); + } +} + +// @Filename:privacyCannotNameAccessorDeclFile_exporter.ts +/// +import Widgets = require("privacyCannotNameAccessorDeclFile_Widgets"); +import Widgets1 = require("GlobalWidgets"); +export function createExportedWidget1() { + return Widgets.createWidget1(); +} +export function createExportedWidget2() { + return Widgets.SpecializedWidget.createWidget2(); +} +export function createExportedWidget3() { + return Widgets1.createWidget3(); +} +export function createExportedWidget4() { + return Widgets1.SpecializedGlobalWidget.createWidget4(); +} + +// @Filename:privacyCannotNameAccessorDeclFile_consumer.ts +import exporter = require("privacyCannotNameAccessorDeclFile_exporter"); +export class publicClassWithWithPrivateGetAccessorTypes { + static get myPublicStaticMethod() { // Error + return exporter.createExportedWidget1(); + } + private static get myPrivateStaticMethod() { + return exporter.createExportedWidget1(); + } + get myPublicMethod() { // Error + return exporter.createExportedWidget1(); + } + private get myPrivateMethod() { + return exporter.createExportedWidget1(); + } + static get myPublicStaticMethod1() { // Error + return exporter.createExportedWidget3(); + } + private static get myPrivateStaticMethod1() { + return exporter.createExportedWidget3(); + } + get myPublicMethod1() { // Error + return exporter.createExportedWidget3(); + } + private get myPrivateMethod1() { + return exporter.createExportedWidget3(); + } +} + +class privateClassWithWithPrivateGetAccessorTypes { + static get myPublicStaticMethod() { + return exporter.createExportedWidget1(); + } + private static get myPrivateStaticMethod() { + return exporter.createExportedWidget1(); + } + get myPublicMethod() { + return exporter.createExportedWidget1(); + } + private get myPrivateMethod() { + return exporter.createExportedWidget1(); + } + static get myPublicStaticMethod1() { + return exporter.createExportedWidget3(); + } + private static get myPrivateStaticMethod1() { + return exporter.createExportedWidget3(); + } + get myPublicMethod1() { + return exporter.createExportedWidget3(); + } + private get myPrivateMethod1() { + return exporter.createExportedWidget3(); + } +} + +export class publicClassWithPrivateModuleGetAccessorTypes { + static get myPublicStaticMethod() { // Error + return exporter.createExportedWidget2(); + } + get myPublicMethod() { // Error + return exporter.createExportedWidget2(); + } + static get myPublicStaticMethod1() { // Error + return exporter.createExportedWidget4(); + } + get myPublicMethod1() { // Error + return exporter.createExportedWidget4(); + } +} + +class privateClassWithPrivateModuleGetAccessorTypes { + static get myPublicStaticMethod() { + return exporter.createExportedWidget2(); + } + get myPublicMethod() { + return exporter.createExportedWidget2(); + } + static get myPublicStaticMethod1() { + return exporter.createExportedWidget4(); + } + get myPublicMethod1() { + return exporter.createExportedWidget4(); + } +} \ No newline at end of file diff --git a/tests/cases/compiler/privacyCannotNameVarTypeDeclFile.ts b/tests/cases/compiler/privacyCannotNameVarTypeDeclFile.ts new file mode 100644 index 00000000000..e49d31946c6 --- /dev/null +++ b/tests/cases/compiler/privacyCannotNameVarTypeDeclFile.ts @@ -0,0 +1,101 @@ +// @module: commonjs +// @declaration: true + + +// @Filename: privacyCannotNameVarTypeDeclFile_GlobalWidgets.ts +declare module "GlobalWidgets" { + export class Widget3 { + name: string; + } + export function createWidget3(): Widget3; + + export module SpecializedGlobalWidget { + export class Widget4 { + name: string; + } + function createWidget4(): Widget4; + } +} + +// @Filename: privacyCannotNameVarTypeDeclFile_Widgets.ts +export class Widget1 { + name = 'one'; +} +export function createWidget1() { + return new Widget1(); +} + +export module SpecializedWidget { + export class Widget2 { + name = 'one'; + } + export function createWidget2() { + return new Widget2(); + } +} + +// @Filename:privacyCannotNameVarTypeDeclFile_exporter.ts +/// +import Widgets = require("privacyCannotNameVarTypeDeclFile_Widgets"); +import Widgets1 = require("GlobalWidgets"); +export function createExportedWidget1() { + return Widgets.createWidget1(); +} +export function createExportedWidget2() { + return Widgets.SpecializedWidget.createWidget2(); +} +export function createExportedWidget3() { + return Widgets1.createWidget3(); +} +export function createExportedWidget4() { + return Widgets1.SpecializedGlobalWidget.createWidget4(); +} + +// @Filename:privacyCannotNameVarTypeDeclFile_consumer.ts +import exporter = require("privacyCannotNameVarTypeDeclFile_exporter"); +export class publicClassWithWithPrivatePropertyTypes { + static myPublicStaticProperty = exporter.createExportedWidget1(); // Error + private static myPrivateStaticProperty = exporter.createExportedWidget1(); + myPublicProperty = exporter.createExportedWidget1(); // Error + private myPrivateProperty = exporter.createExportedWidget1(); + + static myPublicStaticProperty1 = exporter.createExportedWidget3(); // Error + private static myPrivateStaticProperty1 = exporter.createExportedWidget3(); + myPublicProperty1 = exporter.createExportedWidget3(); // Error + private myPrivateProperty1 = exporter.createExportedWidget3(); +} + +class privateClassWithWithPrivatePropertyTypes { + static myPublicStaticProperty = exporter.createExportedWidget1(); + private static myPrivateStaticProperty = exporter.createExportedWidget1(); + myPublicProperty = exporter.createExportedWidget1(); + private myPrivateProperty = exporter.createExportedWidget1(); + + static myPublicStaticProperty1 = exporter.createExportedWidget3(); + private static myPrivateStaticProperty1 = exporter.createExportedWidget3(); + myPublicProperty1 = exporter.createExportedWidget3(); + private myPrivateProperty1 = exporter.createExportedWidget3(); +} + +export var publicVarWithPrivatePropertyTypes= exporter.createExportedWidget1(); // Error +var privateVarWithPrivatePropertyTypes= exporter.createExportedWidget1(); +export var publicVarWithPrivatePropertyTypes1 = exporter.createExportedWidget3(); // Error +var privateVarWithPrivatePropertyTypes1 = exporter.createExportedWidget3(); + +export class publicClassWithPrivateModulePropertyTypes { + static myPublicStaticProperty= exporter.createExportedWidget2(); // Error + myPublicProperty = exporter.createExportedWidget2(); // Error + static myPublicStaticProperty1 = exporter.createExportedWidget4(); // Error + myPublicProperty1 = exporter.createExportedWidget4(); // Error +} +export var publicVarWithPrivateModulePropertyTypes= exporter.createExportedWidget2(); // Error +export var publicVarWithPrivateModulePropertyTypes1 = exporter.createExportedWidget4(); // Error + +class privateClassWithPrivateModulePropertyTypes { + static myPublicStaticProperty= exporter.createExportedWidget2(); + myPublicProperty= exporter.createExportedWidget2(); + static myPublicStaticProperty1 = exporter.createExportedWidget4(); + myPublicProperty1 = exporter.createExportedWidget4(); +} +var privateVarWithPrivateModulePropertyTypes= exporter.createExportedWidget2(); +var privateVarWithPrivateModulePropertyTypes1 = exporter.createExportedWidget4(); \ No newline at end of file diff --git a/tests/cases/compiler/privacyFunctionCannotNameParameterTypeDeclFile.ts b/tests/cases/compiler/privacyFunctionCannotNameParameterTypeDeclFile.ts new file mode 100644 index 00000000000..f24ed8ea32b --- /dev/null +++ b/tests/cases/compiler/privacyFunctionCannotNameParameterTypeDeclFile.ts @@ -0,0 +1,157 @@ +// @module: commonjs +// @declaration: true + + +// @Filename: privacyFunctionCannotNameParameterTypeDeclFile_GlobalWidgets.ts +declare module "GlobalWidgets" { + export class Widget3 { + name: string; + } + export function createWidget3(): Widget3; + + export module SpecializedGlobalWidget { + export class Widget4 { + name: string; + } + function createWidget4(): Widget4; + } +} + +// @Filename: privacyFunctionCannotNameParameterTypeDeclFile_Widgets.ts +export class Widget1 { + name = 'one'; +} +export function createWidget1() { + return new Widget1(); +} + +export module SpecializedWidget { + export class Widget2 { + name = 'one'; + } + export function createWidget2() { + return new Widget2(); + } +} + +// @Filename:privacyFunctionCannotNameParameterTypeDeclFile_exporter.ts +/// +import Widgets = require("privacyFunctionCannotNameParameterTypeDeclFile_Widgets"); +import Widgets1 = require("GlobalWidgets"); +export function createExportedWidget1() { + return Widgets.createWidget1(); +} +export function createExportedWidget2() { + return Widgets.SpecializedWidget.createWidget2(); +} +export function createExportedWidget3() { + return Widgets1.createWidget3(); +} +export function createExportedWidget4() { + return Widgets1.SpecializedGlobalWidget.createWidget4(); +} + +// @Filename:privacyFunctionCannotNameParameterTypeDeclFile_consumer.ts +import exporter = require("privacyFunctionCannotNameParameterTypeDeclFile_exporter"); +export class publicClassWithWithPrivateParmeterTypes { + static myPublicStaticMethod(param = exporter.createExportedWidget1()) { // Error + } + private static myPrivateStaticMethod(param = exporter.createExportedWidget1()) { + } + myPublicMethod(param = exporter.createExportedWidget1()) { // Error + } + private myPrivateMethod(param = exporter.createExportedWidget1()) { + } + constructor(param = exporter.createExportedWidget1(), private param1 = exporter.createExportedWidget1(), public param2 = exporter.createExportedWidget1()) { // Error + } +} +export class publicClassWithWithPrivateParmeterTypes1 { + static myPublicStaticMethod(param = exporter.createExportedWidget3()) { // Error + } + private static myPrivateStaticMethod(param = exporter.createExportedWidget3()) { + } + myPublicMethod(param = exporter.createExportedWidget3()) { // Error + } + private myPrivateMethod(param = exporter.createExportedWidget3()) { + } + constructor(param = exporter.createExportedWidget3(), private param1 = exporter.createExportedWidget3(), public param2 = exporter.createExportedWidget3()) { // Error + } +} + +class privateClassWithWithPrivateParmeterTypes { + static myPublicStaticMethod(param = exporter.createExportedWidget1()) { + } + private static myPrivateStaticMethod(param = exporter.createExportedWidget1()) { + } + myPublicMethod(param = exporter.createExportedWidget1()) { + } + private myPrivateMethod(param = exporter.createExportedWidget1()) { + } + constructor(param = exporter.createExportedWidget1(), private param1 = exporter.createExportedWidget1(), public param2 = exporter.createExportedWidget1()) { + } +} +class privateClassWithWithPrivateParmeterTypes2 { + static myPublicStaticMethod(param = exporter.createExportedWidget3()) { + } + private static myPrivateStaticMethod(param = exporter.createExportedWidget3()) { + } + myPublicMethod(param = exporter.createExportedWidget3()) { + } + private myPrivateMethod(param = exporter.createExportedWidget3()) { + } + constructor(param = exporter.createExportedWidget3(), private param1 = exporter.createExportedWidget3(), public param2 = exporter.createExportedWidget3()) { + } +} + +export function publicFunctionWithPrivateParmeterTypes(param = exporter.createExportedWidget1()) { // Error +} +function privateFunctionWithPrivateParmeterTypes(param = exporter.createExportedWidget1()) { +} +export function publicFunctionWithPrivateParmeterTypes1(param = exporter.createExportedWidget3()) { // Error +} +function privateFunctionWithPrivateParmeterTypes1(param = exporter.createExportedWidget3()) { +} + + +export class publicClassWithPrivateModuleParameterTypes { + static myPublicStaticMethod(param= exporter.createExportedWidget2()) { // Error + } + myPublicMethod(param= exporter.createExportedWidget2()) { // Error + } + constructor(param= exporter.createExportedWidget2(), private param1= exporter.createExportedWidget2(), public param2= exporter.createExportedWidget2()) { // Error + } +} +export class publicClassWithPrivateModuleParameterTypes2 { + static myPublicStaticMethod(param= exporter.createExportedWidget4()) { // Error + } + myPublicMethod(param= exporter.createExportedWidget4()) { // Error + } + constructor(param= exporter.createExportedWidget4(), private param1= exporter.createExportedWidget4(), public param2= exporter.createExportedWidget4()) { // Error + } +} +export function publicFunctionWithPrivateModuleParameterTypes(param= exporter.createExportedWidget2()) { // Error +} +export function publicFunctionWithPrivateModuleParameterTypes1(param= exporter.createExportedWidget4()) { // Error +} + + +class privateClassWithPrivateModuleParameterTypes { + static myPublicStaticMethod(param= exporter.createExportedWidget2()) { + } + myPublicMethod(param= exporter.createExportedWidget2()) { + } + constructor(param= exporter.createExportedWidget2(), private param1= exporter.createExportedWidget2(), public param2= exporter.createExportedWidget2()) { + } +} +class privateClassWithPrivateModuleParameterTypes1 { + static myPublicStaticMethod(param= exporter.createExportedWidget4()) { + } + myPublicMethod(param= exporter.createExportedWidget4()) { + } + constructor(param= exporter.createExportedWidget4(), private param1= exporter.createExportedWidget4(), public param2= exporter.createExportedWidget4()) { + } +} +function privateFunctionWithPrivateModuleParameterTypes(param= exporter.createExportedWidget2()) { +} +function privateFunctionWithPrivateModuleParameterTypes1(param= exporter.createExportedWidget4()) { +} \ No newline at end of file diff --git a/tests/cases/compiler/privacyFunctionCannotNameReturnTypeDeclFile.ts b/tests/cases/compiler/privacyFunctionCannotNameReturnTypeDeclFile.ts new file mode 100644 index 00000000000..2eff22327b5 --- /dev/null +++ b/tests/cases/compiler/privacyFunctionCannotNameReturnTypeDeclFile.ts @@ -0,0 +1,163 @@ +// @module: commonjs +// @declaration: true + + +// @Filename: privacyFunctionReturnTypeDeclFile_GlobalWidgets.ts +declare module "GlobalWidgets" { + export class Widget3 { + name: string; + } + export function createWidget3(): Widget3; + + export module SpecializedGlobalWidget { + export class Widget4 { + name: string; + } + function createWidget4(): Widget4; + } +} + +// @Filename: privacyFunctionReturnTypeDeclFile_Widgets.ts +export class Widget1 { + name = 'one'; +} +export function createWidget1() { + return new Widget1(); +} + +export module SpecializedWidget { + export class Widget2 { + name = 'one'; + } + export function createWidget2() { + return new Widget2(); + } +} + +// @Filename:privacyFunctionReturnTypeDeclFile_exporter.ts +/// +import Widgets = require("privacyFunctionReturnTypeDeclFile_Widgets"); +import Widgets1 = require("GlobalWidgets"); +export function createExportedWidget1() { + return Widgets.createWidget1(); +} +export function createExportedWidget2() { + return Widgets.SpecializedWidget.createWidget2(); +} +export function createExportedWidget3() { + return Widgets1.createWidget3(); +} +export function createExportedWidget4() { + return Widgets1.SpecializedGlobalWidget.createWidget4(); +} + +// @Filename:privacyFunctionReturnTypeDeclFile_consumer.ts +import exporter = require("privacyFunctionReturnTypeDeclFile_exporter"); +export class publicClassWithWithPrivateParmeterTypes { + static myPublicStaticMethod() { // Error + return exporter.createExportedWidget1(); + } + private static myPrivateStaticMethod() { + return exporter.createExportedWidget1();; + } + myPublicMethod() { // Error + return exporter.createExportedWidget1();; + } + private myPrivateMethod() { + return exporter.createExportedWidget1();; + } + static myPublicStaticMethod1() { // Error + return exporter.createExportedWidget3(); + } + private static myPrivateStaticMethod1() { + return exporter.createExportedWidget3();; + } + myPublicMethod1() { // Error + return exporter.createExportedWidget3();; + } + private myPrivateMethod1() { + return exporter.createExportedWidget3();; + } +} + +class privateClassWithWithPrivateParmeterTypes { + static myPublicStaticMethod() { + return exporter.createExportedWidget1(); + } + private static myPrivateStaticMethod() { + return exporter.createExportedWidget1();; + } + myPublicMethod() { + return exporter.createExportedWidget1();; + } + private myPrivateMethod() { + return exporter.createExportedWidget1();; + } + static myPublicStaticMethod1() { + return exporter.createExportedWidget3(); + } + private static myPrivateStaticMethod1() { + return exporter.createExportedWidget3();; + } + myPublicMethod1() { + return exporter.createExportedWidget3();; + } + private myPrivateMethod1() { + return exporter.createExportedWidget3();; + } +} + +export function publicFunctionWithPrivateParmeterTypes() { // Error + return exporter.createExportedWidget1(); +} +function privateFunctionWithPrivateParmeterTypes() { + return exporter.createExportedWidget1(); +} +export function publicFunctionWithPrivateParmeterTypes1() { // Error + return exporter.createExportedWidget3(); +} +function privateFunctionWithPrivateParmeterTypes1() { + return exporter.createExportedWidget3(); +} + +export class publicClassWithPrivateModuleReturnTypes { + static myPublicStaticMethod() { // Error + return exporter.createExportedWidget2(); + } + myPublicMethod() { // Error + return exporter.createExportedWidget2(); + } + static myPublicStaticMethod1() { // Error + return exporter.createExportedWidget4(); + } + myPublicMethod1() { // Error + return exporter.createExportedWidget4(); + } +} +export function publicFunctionWithPrivateModuleReturnTypes() { // Error + return exporter.createExportedWidget2(); +} +export function publicFunctionWithPrivateModuleReturnTypes1() { // Error + return exporter.createExportedWidget4(); +} + +class privateClassWithPrivateModuleReturnTypes { + static myPublicStaticMethod() { + return exporter.createExportedWidget2(); + } + myPublicMethod() { + return exporter.createExportedWidget2(); + } + static myPublicStaticMethod1() { // Error + return exporter.createExportedWidget4(); + } + myPublicMethod1() { // Error + return exporter.createExportedWidget4(); + } +} +function privateFunctionWithPrivateModuleReturnTypes() { + return exporter.createExportedWidget2(); +} +function privateFunctionWithPrivateModuleReturnTypes1() { + return exporter.createExportedWidget4(); +}