From 1347621d0c948b651234c2bdab676df6e728f353 Mon Sep 17 00:00:00 2001 From: Sheetal Nandi Date: Fri, 8 Aug 2014 13:56:53 -0700 Subject: [PATCH 1/5] Report error if the entityname reference in the import declaration is using private module --- src/compiler/checker.ts | 40 +- .../diagnosticInformationMap.generated.ts | 1 + src/compiler/diagnosticMessages.json | 4 + src/compiler/emitter.ts | 47 ++- src/compiler/types.ts | 1 + .../aliasInaccessibleModule.errors.txt | 8 + .../reference/aliasInaccessibleModule.js | 18 - .../aliasInaccessibleModule2.errors.txt | 12 + .../reference/aliasInaccessibleModule2.js | 18 - .../declarationEmit_nameConflicts.js | 65 +--- .../reference/privacyGloImport.errors.txt | 157 ++++++++ tests/baselines/reference/privacyGloImport.js | 140 ------- .../reference/privacyImport.errors.txt | 361 ++++++++++++++++++ tests/baselines/reference/privacyImport.js | 112 ------ ...ternalReferenceImportWithExport.errors.txt | 167 ++++++++ ...yLocalInternalReferenceImportWithExport.js | 124 ------ ...nalReferenceImportWithoutExport.errors.txt | 163 ++++++++ ...calInternalReferenceImportWithoutExport.js | 112 ------ ...ternalReferenceImportWithExport.errors.txt | 114 ++++++ ...pLevelInternalReferenceImportWithExport.js | 120 ------ ...nalReferenceImportWithoutExport.errors.txt | 111 ++++++ ...velInternalReferenceImportWithoutExport.js | 108 ------ 22 files changed, 1165 insertions(+), 838 deletions(-) create mode 100644 tests/baselines/reference/aliasInaccessibleModule.errors.txt create mode 100644 tests/baselines/reference/aliasInaccessibleModule2.errors.txt create mode 100644 tests/baselines/reference/privacyGloImport.errors.txt create mode 100644 tests/baselines/reference/privacyImport.errors.txt create mode 100644 tests/baselines/reference/privacyLocalInternalReferenceImportWithExport.errors.txt create mode 100644 tests/baselines/reference/privacyLocalInternalReferenceImportWithoutExport.errors.txt create mode 100644 tests/baselines/reference/privacyTopLevelInternalReferenceImportWithExport.errors.txt create mode 100644 tests/baselines/reference/privacyTopLevelInternalReferenceImportWithoutExport.errors.txt diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 57147e49bc8b5..906074ccc7016 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -308,7 +308,7 @@ module ts { else { return returnResolvedSymbol(result); } - } + } break; case SyntaxKind.Method: case SyntaxKind.Constructor: @@ -448,7 +448,7 @@ module ts { return moduleSymbol; } - function getExportAssignmentSymbol(symbol: Symbol): Symbol { + function getExportAssignmentSymbol(symbol: Symbol): Symbol { checkTypeOfExportAssignmentSymbol(symbol); var symbolLinks = getSymbolLinks(symbol); return symbolLinks.exportAssignSymbol === unknownSymbol ? undefined : symbolLinks.exportAssignSymbol; @@ -662,7 +662,7 @@ module ts { } function getAccessibleSymbolChain(symbol: Symbol, enclosingDeclaration: Node, meaning: SymbolFlags): Symbol[] { - function getAccessibleSymbolChainFromSymbolTable(symbols: SymbolTable): Symbol[]{ + function getAccessibleSymbolChainFromSymbolTable(symbols: SymbolTable): Symbol[] { function canQualifySymbol(symbolFromSymbolTable: Symbol, meaning: SymbolFlags) { // If the symbol is equivalent and doesnt need futher qualification, this symbol is accessible if (!needsQualification(symbolFromSymbolTable, enclosingDeclaration, meaning)) { @@ -697,7 +697,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; + var accessibleSymbolsFromExports = resolvedImportedSymbol.exports ? getAccessibleSymbolChainFromSymbolTable(resolvedImportedSymbol.exports) : undefined; if (accessibleSymbolsFromExports && canQualifySymbol(symbolFromSymbolTable, SymbolFlags.Namespace)) { return [symbolFromSymbolTable].concat(accessibleSymbolsFromExports); } @@ -740,7 +740,6 @@ module ts { } function isSymbolAccessible(symbol: Symbol, enclosingDeclaration: Node, meaning: SymbolFlags): SymbolAccessiblityResult { - var aliasesToMakeVisible: ImportDeclaration[]; if (symbol && enclosingDeclaration && !(symbol.flags & SymbolFlags.TypeParameter)) { var initialSymbol = symbol; var meaningToLook = meaning; @@ -748,14 +747,15 @@ module ts { // Symbol is accessible if it by itself is accessible var accessibleSymbolChain = getAccessibleSymbolChain(symbol, enclosingDeclaration, meaningToLook); if (accessibleSymbolChain) { - if (forEach(accessibleSymbolChain[0].declarations, declaration => !getIsDeclarationVisible(declaration))) { + var hasAccessibleDeclarations = hasVisibleDeclarations(accessibleSymbolChain[0]); + if (!hasAccessibleDeclarations) { return { accessibility: SymbolAccessibility.NotAccessible, errorSymbolName: symbolToString(initialSymbol, enclosingDeclaration, meaning), errorModuleName: symbol !== initialSymbol ? symbolToString(symbol, enclosingDeclaration, SymbolFlags.Namespace) : undefined, }; } - return { accessibility: SymbolAccessibility.Accessible, aliasesToMakeVisible: aliasesToMakeVisible }; + return { accessibility: SymbolAccessibility.Accessible, aliasesToMakeVisible: hasAccessibleDeclarations.aliasesToMakeVisible }; } // TODO(shkamat): Handle static method of class @@ -784,6 +784,14 @@ module ts { } return { accessibility: SymbolAccessibility.Accessible }; + } + + function hasVisibleDeclarations(symbol: Symbol): { aliasesToMakeVisible?: ImportDeclaration[]; } { + var aliasesToMakeVisible: ImportDeclaration[]; + if (forEach(symbol.declarations, declaration => !getIsDeclarationVisible(declaration))) { + return undefined; + } + return { aliasesToMakeVisible: aliasesToMakeVisible }; function getIsDeclarationVisible(declaration: Declaration) { if (!isDeclarationVisible(declaration)) { @@ -812,6 +820,17 @@ module ts { } } + function isImportDeclarationEntityNameReferenceDeclarationVisibile(entityName: EntityName): SymbolAccessiblityResult { + var firstIdentifier = getFirstIdentifier(entityName); + var firstIdentifierName = identifierToString(firstIdentifier); + var symbolOfNameSpace = resolveName(entityName.parent, (firstIdentifier).text, SymbolFlags.Namespace, Diagnostics.Cannot_find_name_0, firstIdentifierName); + // Verify if the symbol is accessible + var hasNamespaceDeclarationsVisibile = hasVisibleDeclarations(symbolOfNameSpace); + return hasNamespaceDeclarationsVisibile ? + { accessibility: SymbolAccessibility.Accessible, aliasesToMakeVisible: hasNamespaceDeclarationsVisibile.aliasesToMakeVisible } : + { accessibility: SymbolAccessibility.NotAccessible, errorSymbolName: firstIdentifierName }; + } + // Enclosing declaration is optional when we dont want to get qualified name in the enclosing declaration scope // Meaning needs to be specified if the enclosing declaration is given function symbolToString(symbol: Symbol, enclosingDeclaration?: Node, meaning?: SymbolFlags) { @@ -830,7 +849,7 @@ module ts { // Properties/methods/Signatures/Constructors/TypeParameters do not need qualification !(symbol.flags & SymbolFlags.PropertyOrAccessor & SymbolFlags.Signature & SymbolFlags.Constructor & SymbolFlags.Method & SymbolFlags.TypeParameter)) { var symbolName: string; - while (symbol) { + while (symbol) { var isFirstName = !symbolName; var meaningToLook = isFirstName ? meaning : SymbolFlags.Namespace; var accessibleSymbolChain = getAccessibleSymbolChain(symbol, enclosingDeclaration, meaningToLook); @@ -864,7 +883,7 @@ module ts { }; } - function typeToString(type: Type, enclosingDeclaration?:Node, flags?: TypeFormatFlags): string { + function typeToString(type: Type, enclosingDeclaration?: Node, flags?: TypeFormatFlags): string { var stringWriter = createSingleLineTextWriter(); // TODO(shkamat): typeToString should take enclosingDeclaration as input, once we have implemented enclosingDeclaration writeTypeToTextWriter(type, enclosingDeclaration, flags, stringWriter); @@ -6787,7 +6806,8 @@ module ts { writeTypeAtLocation: writeTypeAtLocation, writeReturnTypeOfSignatureDeclaration: writeReturnTypeOfSignatureDeclaration, writeSymbol: writeSymbolToTextWriter, - isSymbolAccessible: isSymbolAccessible + isSymbolAccessible: isSymbolAccessible, + isImportDeclarationEntityNameReferenceDeclarationVisibile: isImportDeclarationEntityNameReferenceDeclarationVisibile }; checkProgram(); return emitFiles(resolver); diff --git a/src/compiler/diagnosticInformationMap.generated.ts b/src/compiler/diagnosticInformationMap.generated.ts index 0fef6cb95c024..aa89b29acade9 100644 --- a/src/compiler/diagnosticInformationMap.generated.ts +++ b/src/compiler/diagnosticInformationMap.generated.ts @@ -156,6 +156,7 @@ module ts { Return_type_of_public_method_from_exported_class_has_or_is_using_name_0_from_private_module_1: { code: 2065, category: DiagnosticCategory.Error, key: "Return type of public method from exported class has or is using name '{0}' from private module '{1}'." }, Return_type_of_method_from_exported_interface_has_or_is_using_name_0_from_private_module_1: { code: 2066, category: DiagnosticCategory.Error, key: "Return type of method from exported interface has or is using name '{0}' from private module '{1}'." }, Return_type_of_exported_function_has_or_is_using_name_0_from_private_module_1: { code: 2067, category: DiagnosticCategory.Error, key: "Return type of exported function has or is using name '{0}' from private module '{1}'." }, + Import_declaration_0_is_using_private_name_1: { code: 2181, category: DiagnosticCategory.Error, key: "Import declaration '{0}' is using private name '{1}'." }, Type_parameter_0_of_constructor_signature_from_exported_interface_has_or_is_using_private_name_1: { code: 2208, category: DiagnosticCategory.Error, key: "Type parameter '{0}' of constructor signature from exported interface has or is using private name '{1}'." }, Type_parameter_0_of_call_signature_from_exported_interface_has_or_is_using_private_name_1: { code: 2209, category: DiagnosticCategory.Error, key: "Type parameter '{0}' of call signature from exported interface has or is using private name '{1}'." }, Type_parameter_0_of_public_static_method_from_exported_class_has_or_is_using_private_name_1: { code: 2210, category: DiagnosticCategory.Error, key: "Type parameter '{0}' of public static method from exported class has or is using private name '{1}'." }, diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index c41f195bec51e..e9ce55dd3bdcc 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -616,6 +616,10 @@ "category": "Error", "code": 2067 }, + "Import declaration '{0}' is using private name '{1}'.": { + "category": "Error", + "code": 2181 + }, "Type parameter '{0}' of constructor signature from exported interface has or is using private name '{1}'.": { "category": "Error", "code": 2208 diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index 751bc480e01ae..57124e0f026cb 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -1882,6 +1882,21 @@ module ts { typeName?: Identifier } + function writeAsychronousImportDeclarations(importDeclarations: ImportDeclaration[]) { + var oldWriter = writer; + forEach(importDeclarations.sort(), aliasToWrite => { + var aliasEmitInfo = forEach(aliasDeclarationEmitInfo, declEmitInfo => declEmitInfo.declaration === aliasToWrite ? declEmitInfo : undefined); + writer = createTextWriter(writeSymbol); + for (var declarationIndent = aliasEmitInfo.indent; declarationIndent; declarationIndent--) { + writer.increaseIndent(); + } + + writeImportDeclaration(aliasToWrite); + aliasEmitInfo.asynchronousOutput = writer.getText(); + }); + writer = oldWriter; + } + function writeSymbol(symbol: Symbol, enclosingDeclaration?: Node, meaning?: SymbolFlags) { var symbolAccesibilityResult = resolver.isSymbolAccessible(symbol, enclosingDeclaration, meaning); if (symbolAccesibilityResult.accessibility === SymbolAccessibility.Accessible) { @@ -1889,18 +1904,7 @@ module ts { // write the aliases if (symbolAccesibilityResult && symbolAccesibilityResult.aliasesToMakeVisible) { - var oldWriter = writer; - forEach(symbolAccesibilityResult.aliasesToMakeVisible.sort(), aliasToWrite => { - var aliasEmitInfo = forEach(aliasDeclarationEmitInfo, declEmitInfo => declEmitInfo.declaration === aliasToWrite ? declEmitInfo : undefined); - writer = createTextWriter(writeSymbol); - for (var declarationIndent = aliasEmitInfo.indent; declarationIndent; declarationIndent--) { - writer.increaseIndent(); - } - - writeImportDeclaration(aliasToWrite); - aliasEmitInfo.asynchronousOutput = writer.getText(); - }); - writer = oldWriter; + writeAsychronousImportDeclarations(symbolAccesibilityResult.aliasesToMakeVisible); } } else { @@ -2007,6 +2011,7 @@ module ts { writer.write(getSourceTextOfLocalNode(node.name)); writer.write(" = "); if (node.entityName) { + checkEntityNameAccessible(); writer.write(getSourceTextOfLocalNode(node.entityName)); writer.write(";"); } @@ -2016,6 +2021,24 @@ module ts { writer.write(");"); } writer.writeLine(); + + function checkEntityNameAccessible() { + var symbolAccesibilityResult = resolver.isImportDeclarationEntityNameReferenceDeclarationVisibile(node.entityName); + if (symbolAccesibilityResult.accessibility === SymbolAccessibility.Accessible) { + // write the aliases + if (symbolAccesibilityResult.aliasesToMakeVisible) { + writeAsychronousImportDeclarations(symbolAccesibilityResult.aliasesToMakeVisible); + } + } + else { + // Report error + reportedDeclarationError = true; + diagnostics.push(createDiagnosticForNode(node, + Diagnostics.Import_declaration_0_is_using_private_name_1, + getSourceTextOfLocalNode(node.name), + symbolAccesibilityResult.errorSymbolName)); + } + } } function emitModuleDeclaration(node: ModuleDeclaration) { diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 911dc20b76577..5e882740f1d6c 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -658,6 +658,7 @@ module ts { writeReturnTypeOfSignatureDeclaration(signatureDeclaration: SignatureDeclaration, enclosingDeclaration: Node, flags: TypeFormatFlags, writer: TextWriter): void; writeSymbol(symbol: Symbol, enclosingDeclaration: Node, meaning: SymbolFlags, writer: TextWriter): void; isSymbolAccessible(symbol: Symbol, enclosingDeclaration: Node, meaning: SymbolFlags): SymbolAccessiblityResult; + isImportDeclarationEntityNameReferenceDeclarationVisibile(entityName: EntityName): SymbolAccessiblityResult; } export enum SymbolFlags { diff --git a/tests/baselines/reference/aliasInaccessibleModule.errors.txt b/tests/baselines/reference/aliasInaccessibleModule.errors.txt new file mode 100644 index 0000000000000..839ea965b02d3 --- /dev/null +++ b/tests/baselines/reference/aliasInaccessibleModule.errors.txt @@ -0,0 +1,8 @@ +==== tests/cases/compiler/aliasInaccessibleModule.ts (1 errors) ==== + module M { + module N { + } + export import X = N; + ~~~~~~~~~~~~~~~~~~~~ +!!! Import declaration 'X' is using private name 'N'. + } \ No newline at end of file diff --git a/tests/baselines/reference/aliasInaccessibleModule.js b/tests/baselines/reference/aliasInaccessibleModule.js index 6d22cf1a8b890..a0ecf3361fc1f 100644 --- a/tests/baselines/reference/aliasInaccessibleModule.js +++ b/tests/baselines/reference/aliasInaccessibleModule.js @@ -9,21 +9,3 @@ module M { var M; (function (M) { })(M || (M = {})); - - -//// [aliasInaccessibleModule.d.ts] -declare module M { - export import X = N; -} - - -//// [DtsFileErrors] - - -==== tests/cases/compiler/aliasInaccessibleModule.d.ts (1 errors) ==== - declare module M { - export import X = N; - ~~~~~~~~~~~~~~~~~~~~ -!!! Cannot find name 'N'. - } - \ No newline at end of file diff --git a/tests/baselines/reference/aliasInaccessibleModule2.errors.txt b/tests/baselines/reference/aliasInaccessibleModule2.errors.txt new file mode 100644 index 0000000000000..149410acb1095 --- /dev/null +++ b/tests/baselines/reference/aliasInaccessibleModule2.errors.txt @@ -0,0 +1,12 @@ +==== tests/cases/compiler/aliasInaccessibleModule2.ts (1 errors) ==== + module M { + module N { + class C { + } + + } + import R = N; + ~~~~~~~~~~~~~ +!!! Import declaration 'R' is using private name 'N'. + export import X = R; + } \ No newline at end of file diff --git a/tests/baselines/reference/aliasInaccessibleModule2.js b/tests/baselines/reference/aliasInaccessibleModule2.js index fd4fc6c737eff..b8b824d92ad9e 100644 --- a/tests/baselines/reference/aliasInaccessibleModule2.js +++ b/tests/baselines/reference/aliasInaccessibleModule2.js @@ -23,21 +23,3 @@ var M; var R = N; M.X = R; })(M || (M = {})); - - -//// [aliasInaccessibleModule2.d.ts] -declare module M { - export import X = R; -} - - -//// [DtsFileErrors] - - -==== tests/cases/compiler/aliasInaccessibleModule2.d.ts (1 errors) ==== - declare module M { - export import X = R; - ~~~~~~~~~~~~~~~~~~~~ -!!! Cannot find name 'R'. - } - \ No newline at end of file diff --git a/tests/baselines/reference/declarationEmit_nameConflicts.js b/tests/baselines/reference/declarationEmit_nameConflicts.js index 56693b03cd4c9..70b14ad66a6f8 100644 --- a/tests/baselines/reference/declarationEmit_nameConflicts.js +++ b/tests/baselines/reference/declarationEmit_nameConflicts.js @@ -145,6 +145,7 @@ declare module f { } export = f; //// [declarationEmit_nameConflicts_0.d.ts] +import im = require('declarationEmit_nameConflicts_1'); export declare module M { function f(): void; class C { @@ -193,67 +194,3 @@ export declare module M.Q { } } } - - -//// [DtsFileErrors] - - -==== tests/cases/compiler/declarationEmit_nameConflicts_0.d.ts (1 errors) ==== - export declare module M { - function f(): void; - class C { - } - module N { - function g(): void; - interface I { - } - } - export import a = M.f; - export import b = M.C; - export import c = N; - export import d = im; - ~~~~~~~~~~~~~~~~~~~~~ -!!! Cannot find name 'im'. - } - export declare module M.P { - function f(): void; - class C { - } - module N { - function g(): void; - interface I { - } - } - export import im = M.P.f; - var a: () => void; - var b: typeof M.C; - var c: typeof M.N; - var g: () => void; - var d: typeof M.d; - } - export declare module M.Q { - function f(): void; - class C { - } - module N { - function g(): void; - interface I { - } - } - interface b extends M.C { - } - interface I extends M.c.I { - } - module c { - interface I extends M.c.I { - } - } - } - -==== tests/cases/compiler/declarationEmit_nameConflicts_1.d.ts (0 errors) ==== - declare module f { - class c { - } - } - export = f; - \ No newline at end of file diff --git a/tests/baselines/reference/privacyGloImport.errors.txt b/tests/baselines/reference/privacyGloImport.errors.txt new file mode 100644 index 0000000000000..cd5c19fa9d76f --- /dev/null +++ b/tests/baselines/reference/privacyGloImport.errors.txt @@ -0,0 +1,157 @@ +==== tests/cases/compiler/privacyGloImport.ts (2 errors) ==== + module m1 { + export module m1_M1_public { + export class c1 { + } + export function f1() { + return new c1; + } + export var v1 = c1; + export var v2: c1; + } + + module m1_M2_private { + export class c1 { + } + export function f1() { + return new c1; + } + export var v1 = c1; + export var v2: c1; + } + + //export declare module "m1_M3_public" { + // export function f1(); + // export class c1 { + // } + // export var v1: { new (): c1; }; + // export var v2: c1; + //} + + //declare module "m1_M4_private" { + // export function f1(); + // export class c1 { + // } + // export var v1: { new (): c1; }; + // export var v2: c1; + //} + + import m1_im1_private = m1_M1_public; + export var m1_im1_private_v1_public = m1_im1_private.c1; + export var m1_im1_private_v2_public = new m1_im1_private.c1(); + export var m1_im1_private_v3_public = m1_im1_private.f1; + export var m1_im1_private_v4_public = m1_im1_private.f1(); + var m1_im1_private_v1_private = m1_im1_private.c1; + var m1_im1_private_v2_private = new m1_im1_private.c1(); + var m1_im1_private_v3_private = m1_im1_private.f1; + var m1_im1_private_v4_private = m1_im1_private.f1(); + + + import m1_im2_private = m1_M2_private; + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! Import declaration 'm1_im2_private' is using private name 'm1_M2_private'. + export var m1_im2_private_v1_public = m1_im2_private.c1; + export var m1_im2_private_v2_public = new m1_im2_private.c1(); + export var m1_im2_private_v3_public = m1_im2_private.f1; + export var m1_im2_private_v4_public = m1_im2_private.f1(); + var m1_im2_private_v1_private = m1_im2_private.c1; + var m1_im2_private_v2_private = new m1_im2_private.c1(); + var m1_im2_private_v3_private = m1_im2_private.f1; + var m1_im2_private_v4_private = m1_im2_private.f1(); + + //import m1_im3_private = require("m1_M3_public"); + //export var m1_im3_private_v1_public = m1_im3_private.c1; + //export var m1_im3_private_v2_public = new m1_im3_private.c1(); + //export var m1_im3_private_v3_public = m1_im3_private.f1; + //export var m1_im3_private_v4_public = m1_im3_private.f1(); + //var m1_im3_private_v1_private = m1_im3_private.c1; + //var m1_im3_private_v2_private = new m1_im3_private.c1(); + //var m1_im3_private_v3_private = m1_im3_private.f1; + //var m1_im3_private_v4_private = m1_im3_private.f1(); + + //import m1_im4_private = require("m1_M4_private"); + //export var m1_im4_private_v1_public = m1_im4_private.c1; + //export var m1_im4_private_v2_public = new m1_im4_private.c1(); + //export var m1_im4_private_v3_public = m1_im4_private.f1; + //export var m1_im4_private_v4_public = m1_im4_private.f1(); + //var m1_im4_private_v1_private = m1_im4_private.c1; + //var m1_im4_private_v2_private = new m1_im4_private.c1(); + //var m1_im4_private_v3_private = m1_im4_private.f1; + //var m1_im4_private_v4_private = m1_im4_private.f1(); + + export import m1_im1_public = m1_M1_public; + export import m1_im2_public = m1_M2_private; + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! Import declaration 'm1_im2_public' is using private name 'm1_M2_private'. + //export import m1_im3_public = require("m1_M3_public"); + //export import m1_im4_public = require("m1_M4_private"); + } + + module glo_M1_public { + export class c1 { + } + export function f1() { + return new c1; + } + export var v1 = c1; + export var v2: c1; + } + + declare module "glo_M2_public" { + export function f1(); + export class c1 { + } + export var v1: { new (): c1; }; + export var v2: c1; + } + + declare module "use_glo_M1_public" { + import use_glo_M1_public = glo_M1_public; + export var use_glo_M1_public_v1_public: { new (): use_glo_M1_public.c1; }; + export var use_glo_M1_public_v2_public: typeof use_glo_M1_public; + export var use_glo_M1_public_v3_public: ()=> use_glo_M1_public.c1; + var use_glo_M1_public_v1_private: { new (): use_glo_M1_public.c1; }; + var use_glo_M1_public_v2_private: typeof use_glo_M1_public; + var use_glo_M1_public_v3_private: () => use_glo_M1_public.c1; + + import use_glo_M2_public = require("glo_M2_public"); + export var use_glo_M2_public_v1_public: { new (): use_glo_M2_public.c1; }; + export var use_glo_M2_public_v2_public: typeof use_glo_M2_public; + export var use_glo_M2_public_v3_public: () => use_glo_M2_public.c1; + var use_glo_M2_public_v1_private: { new (): use_glo_M2_public.c1; }; + var use_glo_M2_public_v2_private: typeof use_glo_M2_public; + var use_glo_M2_public_v3_private: () => use_glo_M2_public.c1; + + module m2 { + //import errorImport = require("glo_M2_public"); + import nonerrorImport = glo_M1_public; + + module m5 { + //import m5_errorImport = require("glo_M2_public"); + import m5_nonerrorImport = glo_M1_public; + } + } + } + + declare module "anotherParseError" { + module m2 { + //declare module "abc" { + //} + } + + module m2 { + //module "abc2" { + //} + } + //module "abc3" { + //} + } + + module m2 { + //import m3 = require("use_glo_M1_public"); + module m4 { + var a = 10; + //import m2 = require("use_glo_M1_public"); + } + + } \ No newline at end of file diff --git a/tests/baselines/reference/privacyGloImport.js b/tests/baselines/reference/privacyGloImport.js index 483101dc5efe7..537e1eb43fabc 100644 --- a/tests/baselines/reference/privacyGloImport.js +++ b/tests/baselines/reference/privacyGloImport.js @@ -228,143 +228,3 @@ var m2; var a = 10; })(m4 || (m4 = {})); })(m2 || (m2 = {})); - - -//// [privacyGloImport.d.ts] -declare module m1 { - module m1_M1_public { - class c1 { - } - function f1(): c1; - var v1: typeof c1; - var v2: c1; - } - import m1_im1_private = m1_M1_public; - var m1_im1_private_v1_public: typeof m1_im1_private.c1; - var m1_im1_private_v2_public: m1_im1_private.c1; - var m1_im1_private_v3_public: () => m1_im1_private.c1; - var m1_im1_private_v4_public: m1_im1_private.c1; - import m1_im2_private = m1_M2_private; - var m1_im2_private_v1_public: typeof m1_im2_private.c1; - var m1_im2_private_v2_public: m1_im2_private.c1; - var m1_im2_private_v3_public: () => m1_im2_private.c1; - var m1_im2_private_v4_public: m1_im2_private.c1; - export import m1_im1_public = m1_M1_public; - export import m1_im2_public = m1_M2_private; -} -declare module glo_M1_public { - class c1 { - } - function f1(): c1; - var v1: typeof c1; - var v2: c1; -} -declare module "glo_M2_public" { - function f1(): any; - class c1 { - } - var v1: new () => c1; - var v2: c1; -} -declare module "use_glo_M1_public" { - import use_glo_M1_public = glo_M1_public; - var use_glo_M1_public_v1_public: new () => use_glo_M1_public.c1; - var use_glo_M1_public_v2_public: typeof use_glo_M1_public; - var use_glo_M1_public_v3_public: () => use_glo_M1_public.c1; - var use_glo_M1_public_v1_private: new () => use_glo_M1_public.c1; - var use_glo_M1_public_v2_private: typeof use_glo_M1_public; - var use_glo_M1_public_v3_private: () => use_glo_M1_public.c1; - import use_glo_M2_public = require("glo_M2_public"); - var use_glo_M2_public_v1_public: new () => use_glo_M2_public.c1; - var use_glo_M2_public_v2_public: typeof use_glo_M2_public; - var use_glo_M2_public_v3_public: () => use_glo_M2_public.c1; - var use_glo_M2_public_v1_private: new () => use_glo_M2_public.c1; - var use_glo_M2_public_v2_private: typeof use_glo_M2_public; - var use_glo_M2_public_v3_private: () => use_glo_M2_public.c1; - module m2 { - module m5 { - } - } -} -declare module "anotherParseError" { - module m2 { - } - module m2 { - } -} -declare module m2 { -} - - -//// [DtsFileErrors] - - -==== tests/cases/compiler/privacyGloImport.d.ts (2 errors) ==== - declare module m1 { - module m1_M1_public { - class c1 { - } - function f1(): c1; - var v1: typeof c1; - var v2: c1; - } - import m1_im1_private = m1_M1_public; - var m1_im1_private_v1_public: typeof m1_im1_private.c1; - var m1_im1_private_v2_public: m1_im1_private.c1; - var m1_im1_private_v3_public: () => m1_im1_private.c1; - var m1_im1_private_v4_public: m1_im1_private.c1; - import m1_im2_private = m1_M2_private; - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! Cannot find name 'm1_M2_private'. - var m1_im2_private_v1_public: typeof m1_im2_private.c1; - var m1_im2_private_v2_public: m1_im2_private.c1; - var m1_im2_private_v3_public: () => m1_im2_private.c1; - var m1_im2_private_v4_public: m1_im2_private.c1; - export import m1_im1_public = m1_M1_public; - export import m1_im2_public = m1_M2_private; - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! Cannot find name 'm1_M2_private'. - } - declare module glo_M1_public { - class c1 { - } - function f1(): c1; - var v1: typeof c1; - var v2: c1; - } - declare module "glo_M2_public" { - function f1(): any; - class c1 { - } - var v1: new () => c1; - var v2: c1; - } - declare module "use_glo_M1_public" { - import use_glo_M1_public = glo_M1_public; - var use_glo_M1_public_v1_public: new () => use_glo_M1_public.c1; - var use_glo_M1_public_v2_public: typeof use_glo_M1_public; - var use_glo_M1_public_v3_public: () => use_glo_M1_public.c1; - var use_glo_M1_public_v1_private: new () => use_glo_M1_public.c1; - var use_glo_M1_public_v2_private: typeof use_glo_M1_public; - var use_glo_M1_public_v3_private: () => use_glo_M1_public.c1; - import use_glo_M2_public = require("glo_M2_public"); - var use_glo_M2_public_v1_public: new () => use_glo_M2_public.c1; - var use_glo_M2_public_v2_public: typeof use_glo_M2_public; - var use_glo_M2_public_v3_public: () => use_glo_M2_public.c1; - var use_glo_M2_public_v1_private: new () => use_glo_M2_public.c1; - var use_glo_M2_public_v2_private: typeof use_glo_M2_public; - var use_glo_M2_public_v3_private: () => use_glo_M2_public.c1; - module m2 { - module m5 { - } - } - } - declare module "anotherParseError" { - module m2 { - } - module m2 { - } - } - declare module m2 { - } - \ No newline at end of file diff --git a/tests/baselines/reference/privacyImport.errors.txt b/tests/baselines/reference/privacyImport.errors.txt new file mode 100644 index 0000000000000..a4ea4776a121e --- /dev/null +++ b/tests/baselines/reference/privacyImport.errors.txt @@ -0,0 +1,361 @@ +==== tests/cases/compiler/privacyImport.ts (2 errors) ==== + export module m1 { + export module m1_M1_public { + export class c1 { + } + export function f1() { + return new c1; + } + export var v1 = c1; + export var v2: c1; + } + + module m1_M2_private { + export class c1 { + } + export function f1() { + return new c1; + } + export var v1 = c1; + export var v2: c1; + } + + //export declare module "m1_M3_public" { + // export function f1(); + // export class c1 { + // } + // export var v1: { new (): c1; }; + // export var v2: c1; + //} + + //declare module "m1_M4_private" { + // export function f1(); + // export class c1 { + // } + // export var v1: { new (): c1; }; + // export var v2: c1; + //} + + import m1_im1_private = m1_M1_public; + export var m1_im1_private_v1_public = m1_im1_private.c1; + export var m1_im1_private_v2_public = new m1_im1_private.c1(); + export var m1_im1_private_v3_public = m1_im1_private.f1; + export var m1_im1_private_v4_public = m1_im1_private.f1(); + var m1_im1_private_v1_private = m1_im1_private.c1; + var m1_im1_private_v2_private = new m1_im1_private.c1(); + var m1_im1_private_v3_private = m1_im1_private.f1; + var m1_im1_private_v4_private = m1_im1_private.f1(); + + + import m1_im2_private = m1_M2_private; + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! Import declaration 'm1_im2_private' is using private name 'm1_M2_private'. + export var m1_im2_private_v1_public = m1_im2_private.c1; + export var m1_im2_private_v2_public = new m1_im2_private.c1(); + export var m1_im2_private_v3_public = m1_im2_private.f1; + export var m1_im2_private_v4_public = m1_im2_private.f1(); + var m1_im2_private_v1_private = m1_im2_private.c1; + var m1_im2_private_v2_private = new m1_im2_private.c1(); + var m1_im2_private_v3_private = m1_im2_private.f1; + var m1_im2_private_v4_private = m1_im2_private.f1(); + + //import m1_im3_private = require("m1_M3_public"); + //export var m1_im3_private_v1_public = m1_im3_private.c1; + //export var m1_im3_private_v2_public = new m1_im3_private.c1(); + //export var m1_im3_private_v3_public = m1_im3_private.f1; + //export var m1_im3_private_v4_public = m1_im3_private.f1(); + //var m1_im3_private_v1_private = m1_im3_private.c1; + //var m1_im3_private_v2_private = new m1_im3_private.c1(); + //var m1_im3_private_v3_private = m1_im3_private.f1; + //var m1_im3_private_v4_private = m1_im3_private.f1(); + + //import m1_im4_private = require("m1_M4_private"); + //export var m1_im4_private_v1_public = m1_im4_private.c1; + //export var m1_im4_private_v2_public = new m1_im4_private.c1(); + //export var m1_im4_private_v3_public = m1_im4_private.f1; + //export var m1_im4_private_v4_public = m1_im4_private.f1(); + //var m1_im4_private_v1_private = m1_im4_private.c1; + //var m1_im4_private_v2_private = new m1_im4_private.c1(); + //var m1_im4_private_v3_private = m1_im4_private.f1; + //var m1_im4_private_v4_private = m1_im4_private.f1(); + + export import m1_im1_public = m1_M1_public; + export import m1_im2_public = m1_M2_private; + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! Import declaration 'm1_im2_public' is using private name 'm1_M2_private'. + //export import m1_im3_public = require("m1_M3_public"); + //export import m1_im4_public = require("m1_M4_private"); + } + + module m2 { + export module m2_M1_public { + export class c1 { + } + export function f1() { + return new c1; + } + export var v1 = c1; + export var v2: c1; + } + + module m2_M2_private { + export class c1 { + } + export function f1() { + return new c1; + } + export var v1 = c1; + export var v2: c1; + } + + //export declare module "m2_M3_public" { + // export function f1(); + // export class c1 { + // } + // export var v1: { new (): c1; }; + // export var v2: c1; + //} + + //declare module "m2_M4_private" { + // export function f1(); + // export class c1 { + // } + // export var v1: { new (): c1; }; + // export var v2: c1; + //} + + import m1_im1_private = m2_M1_public; + export var m1_im1_private_v1_public = m1_im1_private.c1; + export var m1_im1_private_v2_public = new m1_im1_private.c1(); + export var m1_im1_private_v3_public = m1_im1_private.f1; + export var m1_im1_private_v4_public = m1_im1_private.f1(); + var m1_im1_private_v1_private = m1_im1_private.c1; + var m1_im1_private_v2_private = new m1_im1_private.c1(); + var m1_im1_private_v3_private = m1_im1_private.f1; + var m1_im1_private_v4_private = m1_im1_private.f1(); + + + import m1_im2_private = m2_M2_private; + export var m1_im2_private_v1_public = m1_im2_private.c1; + export var m1_im2_private_v2_public = new m1_im2_private.c1(); + export var m1_im2_private_v3_public = m1_im2_private.f1; + export var m1_im2_private_v4_public = m1_im2_private.f1(); + var m1_im2_private_v1_private = m1_im2_private.c1; + var m1_im2_private_v2_private = new m1_im2_private.c1(); + var m1_im2_private_v3_private = m1_im2_private.f1; + var m1_im2_private_v4_private = m1_im2_private.f1(); + + //import m1_im3_private = require("m2_M3_public"); + //export var m1_im3_private_v1_public = m1_im3_private.c1; + //export var m1_im3_private_v2_public = new m1_im3_private.c1(); + //export var m1_im3_private_v3_public = m1_im3_private.f1; + //export var m1_im3_private_v4_public = m1_im3_private.f1(); + //var m1_im3_private_v1_private = m1_im3_private.c1; + //var m1_im3_private_v2_private = new m1_im3_private.c1(); + //var m1_im3_private_v3_private = m1_im3_private.f1; + //var m1_im3_private_v4_private = m1_im3_private.f1(); + + //import m1_im4_private = require("m2_M4_private"); + //export var m1_im4_private_v1_public = m1_im4_private.c1; + //export var m1_im4_private_v2_public = new m1_im4_private.c1(); + //export var m1_im4_private_v3_public = m1_im4_private.f1; + //export var m1_im4_private_v4_public = m1_im4_private.f1(); + //var m1_im4_private_v1_private = m1_im4_private.c1; + //var m1_im4_private_v2_private = new m1_im4_private.c1(); + //var m1_im4_private_v3_private = m1_im4_private.f1; + //var m1_im4_private_v4_private = m1_im4_private.f1(); + + // Parse error to export module + export import m1_im1_public = m2_M1_public; + export import m1_im2_public = m2_M2_private; + //export import m1_im3_public = require("m2_M3_public"); + //export import m1_im4_public = require("m2_M4_private"); + } + + export module glo_M1_public { + export class c1 { + } + export function f1() { + return new c1; + } + export var v1 = c1; + export var v2: c1; + } + + //export declare module "glo_M2_public" { + // export function f1(); + // export class c1 { + // } + // export var v1: { new (): c1; }; + // export var v2: c1; + //} + + export module glo_M3_private { + export class c1 { + } + export function f1() { + return new c1; + } + export var v1 = c1; + export var v2: c1; + } + + //export declare module "glo_M4_private" { + // export function f1(); + // export class c1 { + // } + // export var v1: { new (): c1; }; + // export var v2: c1; + //} + + + import glo_im1_private = glo_M1_public; + export var glo_im1_private_v1_public = glo_im1_private.c1; + export var glo_im1_private_v2_public = new glo_im1_private.c1(); + export var glo_im1_private_v3_public = glo_im1_private.f1; + export var glo_im1_private_v4_public = glo_im1_private.f1(); + var glo_im1_private_v1_private = glo_im1_private.c1; + var glo_im1_private_v2_private = new glo_im1_private.c1(); + var glo_im1_private_v3_private = glo_im1_private.f1; + var glo_im1_private_v4_private = glo_im1_private.f1(); + + + //import glo_im2_private = require("glo_M2_public"); + //export var glo_im2_private_v1_public = glo_im2_private.c1; + //export var glo_im2_private_v2_public = new glo_im2_private.c1(); + //export var glo_im2_private_v3_public = glo_im2_private.f1; + //export var glo_im2_private_v4_public = glo_im2_private.f1(); + //var glo_im2_private_v1_private = glo_im2_private.c1; + //var glo_im2_private_v2_private = new glo_im2_private.c1(); + //var glo_im2_private_v3_private = glo_im2_private.f1; + //var glo_im2_private_v4_private = glo_im2_private.f1(); + + import glo_im3_private = glo_M3_private; + export var glo_im3_private_v1_public = glo_im3_private.c1; + export var glo_im3_private_v2_public = new glo_im3_private.c1(); + export var glo_im3_private_v3_public = glo_im3_private.f1; + export var glo_im3_private_v4_public = glo_im3_private.f1(); + var glo_im3_private_v1_private = glo_im3_private.c1; + var glo_im3_private_v2_private = new glo_im3_private.c1(); + var glo_im3_private_v3_private = glo_im3_private.f1; + var glo_im3_private_v4_private = glo_im3_private.f1(); + + //import glo_im4_private = require("glo_M4_private"); + //export var glo_im4_private_v1_public = glo_im4_private.c1; + //export var glo_im4_private_v2_public = new glo_im4_private.c1(); + //export var glo_im4_private_v3_public = glo_im4_private.f1; + //export var glo_im4_private_v4_public = glo_im4_private.f1(); + //var glo_im4_private_v1_private = glo_im4_private.c1; + //var glo_im4_private_v2_private = new glo_im4_private.c1(); + //var glo_im4_private_v3_private = glo_im4_private.f1; + //var glo_im4_private_v4_private = glo_im4_private.f1(); + + // Parse error to export module + export import glo_im1_public = glo_M1_public; + export import glo_im2_public = glo_M3_private; + //export import glo_im3_public = require("glo_M2_public"); + //export import glo_im4_public = require("glo_M4_private"); + + + //export declare module "use_glo_M1_public" { + // import use_glo_M1_public = glo_M1_public; + // export var use_glo_M1_public_v1_public: { new (): use_glo_M1_public.c1; }; + // export var use_glo_M1_public_v2_public: use_glo_M1_public; + // export var use_glo_M1_public_v3_public: () => use_glo_M1_public.c1; + // var use_glo_M1_public_v1_private: { new (): use_glo_M1_public.c1; }; + // var use_glo_M1_public_v2_private: use_glo_M1_public; + // var use_glo_M1_public_v3_private: () => use_glo_M1_public.c1; + + // import use_glo_M2_public = require("glo_M2_public"); + // export var use_glo_M2_public_v1_public: { new (): use_glo_M2_public.c1; }; + // export var use_glo_M2_public_v2_public: use_glo_M2_public; + // export var use_glo_M2_public_v3_public: () => use_glo_M2_public.c1; + // var use_glo_M2_public_v1_private: { new (): use_glo_M2_public.c1; }; + // var use_glo_M2_public_v2_private: use_glo_M2_public; + // var use_glo_M2_public_v3_private: () => use_glo_M2_public.c1; + + // module m2 { + // import errorImport = require("glo_M2_public"); + // import nonerrorImport = glo_M1_public; + + // module m5 { + // import m5_errorImport = require("glo_M2_public"); + // import m5_nonerrorImport = glo_M1_public; + // } + // } + //} + + + //declare module "use_glo_M3_private" { + // import use_glo_M3_private = glo_M3_private; + // export var use_glo_M3_private_v1_public: { new (): use_glo_M3_private.c1; }; + // export var use_glo_M3_private_v2_public: use_glo_M3_private; + // export var use_glo_M3_private_v3_public: () => use_glo_M3_private.c1; + // var use_glo_M3_private_v1_private: { new (): use_glo_M3_private.c1; }; + // var use_glo_M3_private_v2_private: use_glo_M3_private; + // var use_glo_M3_private_v3_private: () => use_glo_M3_private.c1; + + // import use_glo_M4_private = require("glo_M4_private"); + // export var use_glo_M4_private_v1_public: { new (): use_glo_M4_private.c1; }; + // export var use_glo_M4_private_v2_public: use_glo_M4_private; + // export var use_glo_M4_private_v3_public: () => use_glo_M4_private.c1; + // var use_glo_M4_private_v1_private: { new (): use_glo_M4_private.c1; }; + // var use_glo_M4_private_v2_private: use_glo_M4_private; + // var use_glo_M4_private_v3_private: () => use_glo_M4_private.c1; + + // module m2 { + // import errorImport = require("glo_M4_private"); + // import nonerrorImport = glo_M3_private; + + // module m5 { + // import m5_errorImport = require("glo_M4_private"); + // import m5_nonerrorImport = glo_M3_private; + // } + // } + //} + + //declare module "anotherParseError" { + // module m2 { + // declare module "abc" { + // } + // } + + // module m2 { + // module "abc2" { + // } + // } + // module "abc3" { + // } + //} + + //declare export module "anotherParseError2" { + // module m2 { + // declare module "abc" { + // } + // } + + // module m2 { + // module "abc2" { + // } + // } + // module "abc3" { + // } + //} + + module m2 { + //import m3 = require("use_glo_M1_public"); + module m4 { + var a = 10; + //import m2 = require("use_glo_M1_public"); + } + + } + + export module m3 { + //import m3 = require("use_glo_M1_public"); + module m4 { + var a = 10; + //import m2 = require("use_glo_M1_public"); + } + + } \ No newline at end of file diff --git a/tests/baselines/reference/privacyImport.js b/tests/baselines/reference/privacyImport.js index 68f2af90c05d8..7b7e4c4977f0c 100644 --- a/tests/baselines/reference/privacyImport.js +++ b/tests/baselines/reference/privacyImport.js @@ -527,115 +527,3 @@ var m2; })(m4 || (m4 = {})); })(exports.m3 || (exports.m3 = {})); var m3 = exports.m3; - - -//// [privacyImport.d.ts] -export declare module m1 { - module m1_M1_public { - class c1 { - } - function f1(): c1; - var v1: typeof c1; - var v2: c1; - } - import m1_im1_private = m1_M1_public; - var m1_im1_private_v1_public: typeof m1_im1_private.c1; - var m1_im1_private_v2_public: m1_im1_private.c1; - var m1_im1_private_v3_public: () => m1_im1_private.c1; - var m1_im1_private_v4_public: m1_im1_private.c1; - import m1_im2_private = m1_M2_private; - var m1_im2_private_v1_public: typeof m1_im2_private.c1; - var m1_im2_private_v2_public: m1_im2_private.c1; - var m1_im2_private_v3_public: () => m1_im2_private.c1; - var m1_im2_private_v4_public: m1_im2_private.c1; - export import m1_im1_public = m1_M1_public; - export import m1_im2_public = m1_M2_private; -} -export declare module glo_M1_public { - class c1 { - } - function f1(): c1; - var v1: typeof c1; - var v2: c1; -} -export declare module glo_M3_private { - class c1 { - } - function f1(): c1; - var v1: typeof c1; - var v2: c1; -} -import glo_im1_private = glo_M1_public; -export declare var glo_im1_private_v1_public: typeof glo_im1_private.c1; -export declare var glo_im1_private_v2_public: glo_im1_private.c1; -export declare var glo_im1_private_v3_public: () => glo_im1_private.c1; -export declare var glo_im1_private_v4_public: glo_im1_private.c1; -import glo_im3_private = glo_M3_private; -export declare var glo_im3_private_v1_public: typeof glo_im3_private.c1; -export declare var glo_im3_private_v2_public: glo_im3_private.c1; -export declare var glo_im3_private_v3_public: () => glo_im3_private.c1; -export declare var glo_im3_private_v4_public: glo_im3_private.c1; -export import glo_im1_public = glo_M1_public; -export import glo_im2_public = glo_M3_private; -export declare module m3 { -} - - -//// [DtsFileErrors] - - -==== tests/cases/compiler/privacyImport.d.ts (2 errors) ==== - export declare module m1 { - module m1_M1_public { - class c1 { - } - function f1(): c1; - var v1: typeof c1; - var v2: c1; - } - import m1_im1_private = m1_M1_public; - var m1_im1_private_v1_public: typeof m1_im1_private.c1; - var m1_im1_private_v2_public: m1_im1_private.c1; - var m1_im1_private_v3_public: () => m1_im1_private.c1; - var m1_im1_private_v4_public: m1_im1_private.c1; - import m1_im2_private = m1_M2_private; - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! Cannot find name 'm1_M2_private'. - var m1_im2_private_v1_public: typeof m1_im2_private.c1; - var m1_im2_private_v2_public: m1_im2_private.c1; - var m1_im2_private_v3_public: () => m1_im2_private.c1; - var m1_im2_private_v4_public: m1_im2_private.c1; - export import m1_im1_public = m1_M1_public; - export import m1_im2_public = m1_M2_private; - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! Cannot find name 'm1_M2_private'. - } - export declare module glo_M1_public { - class c1 { - } - function f1(): c1; - var v1: typeof c1; - var v2: c1; - } - export declare module glo_M3_private { - class c1 { - } - function f1(): c1; - var v1: typeof c1; - var v2: c1; - } - import glo_im1_private = glo_M1_public; - export declare var glo_im1_private_v1_public: typeof glo_im1_private.c1; - export declare var glo_im1_private_v2_public: glo_im1_private.c1; - export declare var glo_im1_private_v3_public: () => glo_im1_private.c1; - export declare var glo_im1_private_v4_public: glo_im1_private.c1; - import glo_im3_private = glo_M3_private; - export declare var glo_im3_private_v1_public: typeof glo_im3_private.c1; - export declare var glo_im3_private_v2_public: glo_im3_private.c1; - export declare var glo_im3_private_v3_public: () => glo_im3_private.c1; - export declare var glo_im3_private_v4_public: glo_im3_private.c1; - export import glo_im1_public = glo_M1_public; - export import glo_im2_public = glo_M3_private; - export declare module m3 { - } - \ No newline at end of file diff --git a/tests/baselines/reference/privacyLocalInternalReferenceImportWithExport.errors.txt b/tests/baselines/reference/privacyLocalInternalReferenceImportWithExport.errors.txt new file mode 100644 index 0000000000000..acbe63a21d7ef --- /dev/null +++ b/tests/baselines/reference/privacyLocalInternalReferenceImportWithExport.errors.txt @@ -0,0 +1,167 @@ +==== tests/cases/compiler/privacyLocalInternalReferenceImportWithExport.ts (7 errors) ==== + // private elements + module m_private { + export class c_private { + } + export enum e_private { + Happy, + Grumpy + } + export function f_private() { + return new c_private(); + } + export var v_private = new c_private(); + export interface i_private { + } + export module mi_private { + export class c { + } + } + export module mu_private { + export interface i { + } + } + } + + // Public elements + export module m_public { + export class c_public { + } + export enum e_public { + Happy, + Grumpy + } + export function f_public() { + return new c_public(); + } + export var v_public = 10; + export interface i_public { + } + export module mi_public { + export class c { + } + } + export module mu_public { + export interface i { + } + } + } + + export module import_public { + // Privacy errors - importing private elements + export import im_public_c_private = m_private.c_private; + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! Import declaration 'im_public_c_private' is using private name 'm_private'. + export import im_public_e_private = m_private.e_private; + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! Import declaration 'im_public_e_private' is using private name 'm_private'. + export import im_public_f_private = m_private.f_private; + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! Import declaration 'im_public_f_private' is using private name 'm_private'. + export import im_public_v_private = m_private.v_private; + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! Import declaration 'im_public_v_private' is using private name 'm_private'. + export import im_public_i_private = m_private.i_private; + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! Import declaration 'im_public_i_private' is using private name 'm_private'. + export import im_public_mi_private = m_private.mi_private; + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! Import declaration 'im_public_mi_private' is using private name 'm_private'. + export import im_public_mu_private = m_private.mu_private; + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! Import declaration 'im_public_mu_private' is using private name 'm_private'. + + // Usage of privacy error imports + var privateUse_im_public_c_private = new im_public_c_private(); + export var publicUse_im_public_c_private = new im_public_c_private(); + var privateUse_im_public_e_private = im_public_e_private.Happy; + export var publicUse_im_public_e_private = im_public_e_private.Grumpy; + var privateUse_im_public_f_private = im_public_f_private(); + export var publicUse_im_public_f_private = im_public_f_private(); + var privateUse_im_public_v_private = im_public_v_private; + export var publicUse_im_public_v_private = im_public_v_private; + var privateUse_im_public_i_private: im_public_i_private; + export var publicUse_im_public_i_private: im_public_i_private; + var privateUse_im_public_mi_private = new im_public_mi_private.c(); + export var publicUse_im_public_mi_private = new im_public_mi_private.c(); + var privateUse_im_public_mu_private: im_public_mu_private.i; + export var publicUse_im_public_mu_private: im_public_mu_private.i; + + + // No Privacy errors - importing public elements + export import im_public_c_public = m_public.c_public; + export import im_public_e_public = m_public.e_public; + export import im_public_f_public = m_public.f_public; + export import im_public_v_public = m_public.v_public; + export import im_public_i_public = m_public.i_public; + export import im_public_mi_public = m_public.mi_public; + export import im_public_mu_public = m_public.mu_public; + + // Usage of above + var privateUse_im_public_c_public = new im_public_c_public(); + export var publicUse_im_public_c_public = new im_public_c_public(); + var privateUse_im_public_e_public = im_public_e_public.Happy; + export var publicUse_im_public_e_public = im_public_e_public.Grumpy; + var privateUse_im_public_f_public = im_public_f_public(); + export var publicUse_im_public_f_public = im_public_f_public(); + var privateUse_im_public_v_public = im_public_v_public; + export var publicUse_im_public_v_public = im_public_v_public; + var privateUse_im_public_i_public: im_public_i_public; + export var publicUse_im_public_i_public: im_public_i_public; + var privateUse_im_public_mi_public = new im_public_mi_public.c(); + export var publicUse_im_public_mi_public = new im_public_mi_public.c(); + var privateUse_im_public_mu_public: im_public_mu_public.i; + export var publicUse_im_public_mu_public: im_public_mu_public.i; + } + + module import_private { + // No Privacy errors - importing private elements + export import im_private_c_private = m_private.c_private; + export import im_private_e_private = m_private.e_private; + export import im_private_f_private = m_private.f_private; + export import im_private_v_private = m_private.v_private; + export import im_private_i_private = m_private.i_private; + export import im_private_mi_private = m_private.mi_private; + export import im_private_mu_private = m_private.mu_private; + + // Usage of above decls + var privateUse_im_private_c_private = new im_private_c_private(); + export var publicUse_im_private_c_private = new im_private_c_private(); + var privateUse_im_private_e_private = im_private_e_private.Happy; + export var publicUse_im_private_e_private = im_private_e_private.Grumpy; + var privateUse_im_private_f_private = im_private_f_private(); + export var publicUse_im_private_f_private = im_private_f_private(); + var privateUse_im_private_v_private = im_private_v_private; + export var publicUse_im_private_v_private = im_private_v_private; + var privateUse_im_private_i_private: im_private_i_private; + export var publicUse_im_private_i_private: im_private_i_private; + var privateUse_im_private_mi_private = new im_private_mi_private.c(); + export var publicUse_im_private_mi_private = new im_private_mi_private.c(); + var privateUse_im_private_mu_private: im_private_mu_private.i; + export var publicUse_im_private_mu_private: im_private_mu_private.i; + + // No privacy Error - importing public elements + export import im_private_c_public = m_public.c_public; + export import im_private_e_public = m_public.e_public; + export import im_private_f_public = m_public.f_public; + export import im_private_v_public = m_public.v_public; + export import im_private_i_public = m_public.i_public; + export import im_private_mi_public = m_public.mi_public; + export import im_private_mu_public = m_public.mu_public; + + // Usage of no privacy error imports + var privateUse_im_private_c_public = new im_private_c_public(); + export var publicUse_im_private_c_public = new im_private_c_public(); + var privateUse_im_private_e_public = im_private_e_public.Happy; + export var publicUse_im_private_e_public = im_private_e_public.Grumpy; + var privateUse_im_private_f_public = im_private_f_public(); + export var publicUse_im_private_f_public = im_private_f_public(); + var privateUse_im_private_v_public = im_private_v_public; + export var publicUse_im_private_v_public = im_private_v_public; + var privateUse_im_private_i_public: im_private_i_public; + export var publicUse_im_private_i_public: im_private_i_public; + var privateUse_im_private_mi_public = new im_private_mi_public.c(); + export var publicUse_im_private_mi_public = new im_private_mi_public.c(); + var privateUse_im_private_mu_public: im_private_mu_public.i; + export var publicUse_im_private_mu_public: im_private_mu_public.i; + } \ No newline at end of file diff --git a/tests/baselines/reference/privacyLocalInternalReferenceImportWithExport.js b/tests/baselines/reference/privacyLocalInternalReferenceImportWithExport.js index b27bd2b9d266a..f597ff7b1e748 100644 --- a/tests/baselines/reference/privacyLocalInternalReferenceImportWithExport.js +++ b/tests/baselines/reference/privacyLocalInternalReferenceImportWithExport.js @@ -291,127 +291,3 @@ var import_private; var privateUse_im_private_mu_public; import_private.publicUse_im_private_mu_public; })(import_private || (import_private = {})); - - -//// [privacyLocalInternalReferenceImportWithExport.d.ts] -export declare module m_public { - class c_public { - } - enum e_public { - Happy = 0, - Grumpy = 1, - } - function f_public(): c_public; - var v_public: number; - interface i_public { - } - module mi_public { - class c { - } - } - module mu_public { - interface i { - } - } -} -export declare module import_public { - export import im_public_c_private = m_private.c_private; - export import im_public_e_private = m_private.e_private; - export import im_public_f_private = m_private.f_private; - export import im_public_v_private = m_private.v_private; - export import im_public_i_private = m_private.i_private; - export import im_public_mi_private = m_private.mi_private; - export import im_public_mu_private = m_private.mu_private; - var publicUse_im_public_c_private: im_public_c_private; - var publicUse_im_public_e_private: im_public_e_private; - var publicUse_im_public_f_private: im_public_c_private; - var publicUse_im_public_v_private: im_public_c_private; - var publicUse_im_public_i_private: im_public_i_private; - var publicUse_im_public_mi_private: im_public_mi_private.c; - var publicUse_im_public_mu_private: im_public_mu_private.i; - export import im_public_c_public = m_public.c_public; - export import im_public_e_public = m_public.e_public; - export import im_public_f_public = m_public.f_public; - export import im_public_v_public = m_public.v_public; - export import im_public_i_public = m_public.i_public; - export import im_public_mi_public = m_public.mi_public; - export import im_public_mu_public = m_public.mu_public; - var publicUse_im_public_c_public: im_public_c_public; - var publicUse_im_public_e_public: im_public_e_public; - var publicUse_im_public_f_public: im_public_c_public; - var publicUse_im_public_v_public: number; - var publicUse_im_public_i_public: im_public_i_public; - var publicUse_im_public_mi_public: im_public_mi_public.c; - var publicUse_im_public_mu_public: im_public_mu_public.i; -} - - -//// [DtsFileErrors] - - -==== tests/cases/compiler/privacyLocalInternalReferenceImportWithExport.d.ts (7 errors) ==== - export declare module m_public { - class c_public { - } - enum e_public { - Happy = 0, - Grumpy = 1, - } - function f_public(): c_public; - var v_public: number; - interface i_public { - } - module mi_public { - class c { - } - } - module mu_public { - interface i { - } - } - } - export declare module import_public { - export import im_public_c_private = m_private.c_private; - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! Cannot find name 'm_private'. - export import im_public_e_private = m_private.e_private; - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! Cannot find name 'm_private'. - export import im_public_f_private = m_private.f_private; - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! Cannot find name 'm_private'. - export import im_public_v_private = m_private.v_private; - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! Cannot find name 'm_private'. - export import im_public_i_private = m_private.i_private; - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! Cannot find name 'm_private'. - export import im_public_mi_private = m_private.mi_private; - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! Cannot find name 'm_private'. - export import im_public_mu_private = m_private.mu_private; - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! Cannot find name 'm_private'. - var publicUse_im_public_c_private: im_public_c_private; - var publicUse_im_public_e_private: im_public_e_private; - var publicUse_im_public_f_private: im_public_c_private; - var publicUse_im_public_v_private: im_public_c_private; - var publicUse_im_public_i_private: im_public_i_private; - var publicUse_im_public_mi_private: im_public_mi_private.c; - var publicUse_im_public_mu_private: im_public_mu_private.i; - export import im_public_c_public = m_public.c_public; - export import im_public_e_public = m_public.e_public; - export import im_public_f_public = m_public.f_public; - export import im_public_v_public = m_public.v_public; - export import im_public_i_public = m_public.i_public; - export import im_public_mi_public = m_public.mi_public; - export import im_public_mu_public = m_public.mu_public; - var publicUse_im_public_c_public: im_public_c_public; - var publicUse_im_public_e_public: im_public_e_public; - var publicUse_im_public_f_public: im_public_c_public; - var publicUse_im_public_v_public: number; - var publicUse_im_public_i_public: im_public_i_public; - var publicUse_im_public_mi_public: im_public_mi_public.c; - var publicUse_im_public_mu_public: im_public_mu_public.i; - } - \ No newline at end of file diff --git a/tests/baselines/reference/privacyLocalInternalReferenceImportWithoutExport.errors.txt b/tests/baselines/reference/privacyLocalInternalReferenceImportWithoutExport.errors.txt new file mode 100644 index 0000000000000..7872b2b071562 --- /dev/null +++ b/tests/baselines/reference/privacyLocalInternalReferenceImportWithoutExport.errors.txt @@ -0,0 +1,163 @@ +==== tests/cases/compiler/privacyLocalInternalReferenceImportWithoutExport.ts (5 errors) ==== + // private elements + module m_private { + export class c_private { + } + export enum e_private { + Happy, + Grumpy + } + export function f_private() { + return new c_private(); + } + export var v_private = new c_private(); + export interface i_private { + } + export module mi_private { + export class c { + } + } + export module mu_private { + export interface i { + } + } + } + + // Public elements + export module m_public { + export class c_public { + } + export enum e_public { + Happy, + Grumpy + } + export function f_public() { + return new c_public(); + } + export var v_public = 10; + export interface i_public { + } + export module mi_public { + export class c { + } + } + export module mu_public { + export interface i { + } + } + } + + export module import_public { + // No Privacy errors - importing private elements + import im_private_c_private = m_private.c_private; + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! Import declaration 'im_private_c_private' is using private name 'm_private'. + import im_private_e_private = m_private.e_private; + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! Import declaration 'im_private_e_private' is using private name 'm_private'. + import im_private_f_private = m_private.f_private; + import im_private_v_private = m_private.v_private; + import im_private_i_private = m_private.i_private; + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! Import declaration 'im_private_i_private' is using private name 'm_private'. + import im_private_mi_private = m_private.mi_private; + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! Import declaration 'im_private_mi_private' is using private name 'm_private'. + import im_private_mu_private = m_private.mu_private; + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! Import declaration 'im_private_mu_private' is using private name 'm_private'. + + // Usage of above decls + var privateUse_im_private_c_private = new im_private_c_private(); + export var publicUse_im_private_c_private = new im_private_c_private(); + var privateUse_im_private_e_private = im_private_e_private.Happy; + export var publicUse_im_private_e_private = im_private_e_private.Grumpy; + var privateUse_im_private_f_private = im_private_f_private(); + export var publicUse_im_private_f_private = im_private_f_private(); + var privateUse_im_private_v_private = im_private_v_private; + export var publicUse_im_private_v_private = im_private_v_private; + var privateUse_im_private_i_private: im_private_i_private; + export var publicUse_im_private_i_private: im_private_i_private; + var privateUse_im_private_mi_private = new im_private_mi_private.c(); + export var publicUse_im_private_mi_private = new im_private_mi_private.c(); + var privateUse_im_private_mu_private: im_private_mu_private.i; + export var publicUse_im_private_mu_private: im_private_mu_private.i; + + + // No Privacy errors - importing public elements + import im_private_c_public = m_public.c_public; + import im_private_e_public = m_public.e_public; + import im_private_f_public = m_public.f_public; + import im_private_v_public = m_public.v_public; + import im_private_i_public = m_public.i_public; + import im_private_mi_public = m_public.mi_public; + import im_private_mu_public = m_public.mu_public; + + // Usage of above decls + var privateUse_im_private_c_public = new im_private_c_public(); + export var publicUse_im_private_c_public = new im_private_c_public(); + var privateUse_im_private_e_public = im_private_e_public.Happy; + export var publicUse_im_private_e_public = im_private_e_public.Grumpy; + var privateUse_im_private_f_public = im_private_f_public(); + export var publicUse_im_private_f_public = im_private_f_public(); + var privateUse_im_private_v_public = im_private_v_public; + export var publicUse_im_private_v_public = im_private_v_public; + var privateUse_im_private_i_public: im_private_i_public; + export var publicUse_im_private_i_public: im_private_i_public; + var privateUse_im_private_mi_public = new im_private_mi_public.c(); + export var publicUse_im_private_mi_public = new im_private_mi_public.c(); + var privateUse_im_private_mu_public: im_private_mu_public.i; + export var publicUse_im_private_mu_public: im_private_mu_public.i; + } + + module import_private { + // No Privacy errors - importing private elements + import im_private_c_private = m_private.c_private; + import im_private_e_private = m_private.e_private; + import im_private_f_private = m_private.f_private; + import im_private_v_private = m_private.v_private; + import im_private_i_private = m_private.i_private; + import im_private_mi_private = m_private.mi_private; + import im_private_mu_private = m_private.mu_private; + + // Usage of above decls + var privateUse_im_private_c_private = new im_private_c_private(); + export var publicUse_im_private_c_private = new im_private_c_private(); + var privateUse_im_private_e_private = im_private_e_private.Happy; + export var publicUse_im_private_e_private = im_private_e_private.Grumpy; + var privateUse_im_private_f_private = im_private_f_private(); + export var publicUse_im_private_f_private = im_private_f_private(); + var privateUse_im_private_v_private = im_private_v_private; + export var publicUse_im_private_v_private = im_private_v_private; + var privateUse_im_private_i_private: im_private_i_private; + export var publicUse_im_private_i_private: im_private_i_private; + var privateUse_im_private_mi_private = new im_private_mi_private.c(); + export var publicUse_im_private_mi_private = new im_private_mi_private.c(); + var privateUse_im_private_mu_private: im_private_mu_private.i; + export var publicUse_im_private_mu_private: im_private_mu_private.i; + + // No privacy Error - importing public elements + import im_private_c_public = m_public.c_public; + import im_private_e_public = m_public.e_public; + import im_private_f_public = m_public.f_public; + import im_private_v_public = m_public.v_public; + import im_private_i_public = m_public.i_public; + import im_private_mi_public = m_public.mi_public; + import im_private_mu_public = m_public.mu_public; + + // Usage of above decls + var privateUse_im_private_c_public = new im_private_c_public(); + export var publicUse_im_private_c_public = new im_private_c_public(); + var privateUse_im_private_e_public = im_private_e_public.Happy; + export var publicUse_im_private_e_public = im_private_e_public.Grumpy; + var privateUse_im_private_f_public = im_private_f_public(); + export var publicUse_im_private_f_public = im_private_f_public(); + var privateUse_im_private_v_public = im_private_v_public; + export var publicUse_im_private_v_public = im_private_v_public; + var privateUse_im_private_i_public: im_private_i_public; + export var publicUse_im_private_i_public: im_private_i_public; + var privateUse_im_private_mi_public = new im_private_mi_public.c(); + export var publicUse_im_private_mi_public = new im_private_mi_public.c(); + var privateUse_im_private_mu_public: im_private_mu_public.i; + export var publicUse_im_private_mu_public: im_private_mu_public.i; + } \ No newline at end of file diff --git a/tests/baselines/reference/privacyLocalInternalReferenceImportWithoutExport.js b/tests/baselines/reference/privacyLocalInternalReferenceImportWithoutExport.js index 044d318b02149..b799a464b623a 100644 --- a/tests/baselines/reference/privacyLocalInternalReferenceImportWithoutExport.js +++ b/tests/baselines/reference/privacyLocalInternalReferenceImportWithoutExport.js @@ -293,115 +293,3 @@ define(["require", "exports"], function (require, exports) { import_private.publicUse_im_private_mu_public; })(import_private || (import_private = {})); }); - - -//// [privacyLocalInternalReferenceImportWithoutExport.d.ts] -export declare module m_public { - class c_public { - } - enum e_public { - Happy = 0, - Grumpy = 1, - } - function f_public(): c_public; - var v_public: number; - interface i_public { - } - module mi_public { - class c { - } - } - module mu_public { - interface i { - } - } -} -export declare module import_public { - import im_private_c_private = m_private.c_private; - import im_private_e_private = m_private.e_private; - import im_private_i_private = m_private.i_private; - import im_private_mi_private = m_private.mi_private; - import im_private_mu_private = m_private.mu_private; - var publicUse_im_private_c_private: im_private_c_private; - var publicUse_im_private_e_private: im_private_e_private; - var publicUse_im_private_f_private: im_private_c_private; - var publicUse_im_private_v_private: im_private_c_private; - var publicUse_im_private_i_private: im_private_i_private; - var publicUse_im_private_mi_private: im_private_mi_private.c; - var publicUse_im_private_mu_private: im_private_mu_private.i; - import im_private_c_public = m_public.c_public; - import im_private_e_public = m_public.e_public; - import im_private_i_public = m_public.i_public; - import im_private_mi_public = m_public.mi_public; - import im_private_mu_public = m_public.mu_public; - var publicUse_im_private_c_public: im_private_c_public; - var publicUse_im_private_e_public: im_private_e_public; - var publicUse_im_private_f_public: im_private_c_public; - var publicUse_im_private_v_public: number; - var publicUse_im_private_i_public: im_private_i_public; - var publicUse_im_private_mi_public: im_private_mi_public.c; - var publicUse_im_private_mu_public: im_private_mu_public.i; -} - - -//// [DtsFileErrors] - - -==== tests/cases/compiler/privacyLocalInternalReferenceImportWithoutExport.d.ts (5 errors) ==== - export declare module m_public { - class c_public { - } - enum e_public { - Happy = 0, - Grumpy = 1, - } - function f_public(): c_public; - var v_public: number; - interface i_public { - } - module mi_public { - class c { - } - } - module mu_public { - interface i { - } - } - } - export declare module import_public { - import im_private_c_private = m_private.c_private; - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! Cannot find name 'm_private'. - import im_private_e_private = m_private.e_private; - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! Cannot find name 'm_private'. - import im_private_i_private = m_private.i_private; - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! Cannot find name 'm_private'. - import im_private_mi_private = m_private.mi_private; - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! Cannot find name 'm_private'. - import im_private_mu_private = m_private.mu_private; - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! Cannot find name 'm_private'. - var publicUse_im_private_c_private: im_private_c_private; - var publicUse_im_private_e_private: im_private_e_private; - var publicUse_im_private_f_private: im_private_c_private; - var publicUse_im_private_v_private: im_private_c_private; - var publicUse_im_private_i_private: im_private_i_private; - var publicUse_im_private_mi_private: im_private_mi_private.c; - var publicUse_im_private_mu_private: im_private_mu_private.i; - import im_private_c_public = m_public.c_public; - import im_private_e_public = m_public.e_public; - import im_private_i_public = m_public.i_public; - import im_private_mi_public = m_public.mi_public; - import im_private_mu_public = m_public.mu_public; - var publicUse_im_private_c_public: im_private_c_public; - var publicUse_im_private_e_public: im_private_e_public; - var publicUse_im_private_f_public: im_private_c_public; - var publicUse_im_private_v_public: number; - var publicUse_im_private_i_public: im_private_i_public; - var publicUse_im_private_mi_public: im_private_mi_public.c; - var publicUse_im_private_mu_public: im_private_mu_public.i; - } - \ No newline at end of file diff --git a/tests/baselines/reference/privacyTopLevelInternalReferenceImportWithExport.errors.txt b/tests/baselines/reference/privacyTopLevelInternalReferenceImportWithExport.errors.txt new file mode 100644 index 0000000000000..899832db21567 --- /dev/null +++ b/tests/baselines/reference/privacyTopLevelInternalReferenceImportWithExport.errors.txt @@ -0,0 +1,114 @@ +==== tests/cases/compiler/privacyTopLevelInternalReferenceImportWithExport.ts (7 errors) ==== + // private elements + module m_private { + export class c_private { + } + export enum e_private { + Happy, + Grumpy + } + export function f_private() { + return new c_private(); + } + export var v_private = new c_private(); + export interface i_private { + } + export module mi_private { + export class c { + } + } + export module mu_private { + export interface i { + } + } + } + + // Public elements + export module m_public { + export class c_public { + } + export enum e_public { + Happy, + Grumpy + } + export function f_public() { + return new c_public(); + } + export var v_public = 10; + export interface i_public { + } + export module mi_public { + export class c { + } + } + export module mu_public { + export interface i { + } + } + } + + // Privacy errors - importing private elements + export import im_public_c_private = m_private.c_private; + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! Import declaration 'im_public_c_private' is using private name 'm_private'. + export import im_public_e_private = m_private.e_private; + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! Import declaration 'im_public_e_private' is using private name 'm_private'. + export import im_public_f_private = m_private.f_private; + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! Import declaration 'im_public_f_private' is using private name 'm_private'. + export import im_public_v_private = m_private.v_private; + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! Import declaration 'im_public_v_private' is using private name 'm_private'. + export import im_public_i_private = m_private.i_private; + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! Import declaration 'im_public_i_private' is using private name 'm_private'. + export import im_public_mi_private = m_private.mi_private; + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! Import declaration 'im_public_mi_private' is using private name 'm_private'. + export import im_public_mu_private = m_private.mu_private; + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! Import declaration 'im_public_mu_private' is using private name 'm_private'. + + // Usage of privacy error imports + var privateUse_im_public_c_private = new im_public_c_private(); + export var publicUse_im_public_c_private = new im_public_c_private(); + var privateUse_im_public_e_private = im_public_e_private.Happy; + export var publicUse_im_public_e_private = im_public_e_private.Grumpy; + var privateUse_im_public_f_private = im_public_f_private(); + export var publicUse_im_public_f_private = im_public_f_private(); + var privateUse_im_public_v_private = im_public_v_private; + export var publicUse_im_public_v_private = im_public_v_private; + var privateUse_im_public_i_private: im_public_i_private; + export var publicUse_im_public_i_private: im_public_i_private; + var privateUse_im_public_mi_private = new im_public_mi_private.c(); + export var publicUse_im_public_mi_private = new im_public_mi_private.c(); + var privateUse_im_public_mu_private: im_public_mu_private.i; + export var publicUse_im_public_mu_private: im_public_mu_private.i; + + + // No Privacy errors - importing public elements + export import im_public_c_public = m_public.c_public; + export import im_public_e_public = m_public.e_public; + export import im_public_f_public = m_public.f_public; + export import im_public_v_public = m_public.v_public; + export import im_public_i_public = m_public.i_public; + export import im_public_mi_public = m_public.mi_public; + export import im_public_mu_public = m_public.mu_public; + + // Usage of above decls + var privateUse_im_public_c_public = new im_public_c_public(); + export var publicUse_im_public_c_public = new im_public_c_public(); + var privateUse_im_public_e_public = im_public_e_public.Happy; + export var publicUse_im_public_e_public = im_public_e_public.Grumpy; + var privateUse_im_public_f_public = im_public_f_public(); + export var publicUse_im_public_f_public = im_public_f_public(); + var privateUse_im_public_v_public = im_public_v_public; + export var publicUse_im_public_v_public = im_public_v_public; + var privateUse_im_public_i_public: im_public_i_public; + export var publicUse_im_public_i_public: im_public_i_public; + var privateUse_im_public_mi_public = new im_public_mi_public.c(); + export var publicUse_im_public_mi_public = new im_public_mi_public.c(); + var privateUse_im_public_mu_public: im_public_mu_public.i; + export var publicUse_im_public_mu_public: im_public_mu_public.i; + \ No newline at end of file diff --git a/tests/baselines/reference/privacyTopLevelInternalReferenceImportWithExport.js b/tests/baselines/reference/privacyTopLevelInternalReferenceImportWithExport.js index 6dcd4f49aef57..5ef31d28d6eae 100644 --- a/tests/baselines/reference/privacyTopLevelInternalReferenceImportWithExport.js +++ b/tests/baselines/reference/privacyTopLevelInternalReferenceImportWithExport.js @@ -196,123 +196,3 @@ define(["require", "exports"], function (require, exports) { var privateUse_im_public_mu_public; exports.publicUse_im_public_mu_public; }); - - -//// [privacyTopLevelInternalReferenceImportWithExport.d.ts] -export declare module m_public { - class c_public { - } - enum e_public { - Happy = 0, - Grumpy = 1, - } - function f_public(): c_public; - var v_public: number; - interface i_public { - } - module mi_public { - class c { - } - } - module mu_public { - interface i { - } - } -} -export import im_public_c_private = m_private.c_private; -export import im_public_e_private = m_private.e_private; -export import im_public_f_private = m_private.f_private; -export import im_public_v_private = m_private.v_private; -export import im_public_i_private = m_private.i_private; -export import im_public_mi_private = m_private.mi_private; -export import im_public_mu_private = m_private.mu_private; -export declare var publicUse_im_public_c_private: im_public_c_private; -export declare var publicUse_im_public_e_private: im_public_e_private; -export declare var publicUse_im_public_f_private: im_public_c_private; -export declare var publicUse_im_public_v_private: im_public_c_private; -export declare var publicUse_im_public_i_private: im_public_i_private; -export declare var publicUse_im_public_mi_private: im_public_mi_private.c; -export declare var publicUse_im_public_mu_private: im_public_mu_private.i; -export import im_public_c_public = m_public.c_public; -export import im_public_e_public = m_public.e_public; -export import im_public_f_public = m_public.f_public; -export import im_public_v_public = m_public.v_public; -export import im_public_i_public = m_public.i_public; -export import im_public_mi_public = m_public.mi_public; -export import im_public_mu_public = m_public.mu_public; -export declare var publicUse_im_public_c_public: im_public_c_public; -export declare var publicUse_im_public_e_public: im_public_e_public; -export declare var publicUse_im_public_f_public: im_public_c_public; -export declare var publicUse_im_public_v_public: number; -export declare var publicUse_im_public_i_public: im_public_i_public; -export declare var publicUse_im_public_mi_public: im_public_mi_public.c; -export declare var publicUse_im_public_mu_public: im_public_mu_public.i; - - -//// [DtsFileErrors] - - -==== tests/cases/compiler/privacyTopLevelInternalReferenceImportWithExport.d.ts (7 errors) ==== - export declare module m_public { - class c_public { - } - enum e_public { - Happy = 0, - Grumpy = 1, - } - function f_public(): c_public; - var v_public: number; - interface i_public { - } - module mi_public { - class c { - } - } - module mu_public { - interface i { - } - } - } - export import im_public_c_private = m_private.c_private; - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! Cannot find name 'm_private'. - export import im_public_e_private = m_private.e_private; - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! Cannot find name 'm_private'. - export import im_public_f_private = m_private.f_private; - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! Cannot find name 'm_private'. - export import im_public_v_private = m_private.v_private; - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! Cannot find name 'm_private'. - export import im_public_i_private = m_private.i_private; - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! Cannot find name 'm_private'. - export import im_public_mi_private = m_private.mi_private; - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! Cannot find name 'm_private'. - export import im_public_mu_private = m_private.mu_private; - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! Cannot find name 'm_private'. - export declare var publicUse_im_public_c_private: im_public_c_private; - export declare var publicUse_im_public_e_private: im_public_e_private; - export declare var publicUse_im_public_f_private: im_public_c_private; - export declare var publicUse_im_public_v_private: im_public_c_private; - export declare var publicUse_im_public_i_private: im_public_i_private; - export declare var publicUse_im_public_mi_private: im_public_mi_private.c; - export declare var publicUse_im_public_mu_private: im_public_mu_private.i; - export import im_public_c_public = m_public.c_public; - export import im_public_e_public = m_public.e_public; - export import im_public_f_public = m_public.f_public; - export import im_public_v_public = m_public.v_public; - export import im_public_i_public = m_public.i_public; - export import im_public_mi_public = m_public.mi_public; - export import im_public_mu_public = m_public.mu_public; - export declare var publicUse_im_public_c_public: im_public_c_public; - export declare var publicUse_im_public_e_public: im_public_e_public; - export declare var publicUse_im_public_f_public: im_public_c_public; - export declare var publicUse_im_public_v_public: number; - export declare var publicUse_im_public_i_public: im_public_i_public; - export declare var publicUse_im_public_mi_public: im_public_mi_public.c; - export declare var publicUse_im_public_mu_public: im_public_mu_public.i; - \ No newline at end of file diff --git a/tests/baselines/reference/privacyTopLevelInternalReferenceImportWithoutExport.errors.txt b/tests/baselines/reference/privacyTopLevelInternalReferenceImportWithoutExport.errors.txt new file mode 100644 index 0000000000000..b9791738e2401 --- /dev/null +++ b/tests/baselines/reference/privacyTopLevelInternalReferenceImportWithoutExport.errors.txt @@ -0,0 +1,111 @@ +==== tests/cases/compiler/privacyTopLevelInternalReferenceImportWithoutExport.ts (5 errors) ==== + + // private elements + module m_private { + export class c_private { + } + export enum e_private { + Happy, + Grumpy + } + export function f_private() { + return new c_private(); + } + export var v_private = new c_private(); + export interface i_private { + } + export module mi_private { + export class c { + } + } + export module mu_private { + export interface i { + } + } + } + + // Public elements + export module m_public { + export class c_public { + } + export enum e_public { + Happy, + Grumpy + } + export function f_public() { + return new c_public(); + } + export var v_public = 10; + export interface i_public { + } + export module mi_public { + export class c { + } + } + export module mu_public { + export interface i { + } + } + } + + // No Privacy errors - importing private elements + import im_private_c_private = m_private.c_private; + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! Import declaration 'im_private_c_private' is using private name 'm_private'. + import im_private_e_private = m_private.e_private; + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! Import declaration 'im_private_e_private' is using private name 'm_private'. + import im_private_f_private = m_private.f_private; + import im_private_v_private = m_private.v_private; + import im_private_i_private = m_private.i_private; + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! Import declaration 'im_private_i_private' is using private name 'm_private'. + import im_private_mi_private = m_private.mi_private; + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! Import declaration 'im_private_mi_private' is using private name 'm_private'. + import im_private_mu_private = m_private.mu_private; + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! Import declaration 'im_private_mu_private' is using private name 'm_private'. + + // Usage of above decls + var privateUse_im_private_c_private = new im_private_c_private(); + export var publicUse_im_private_c_private = new im_private_c_private(); + var privateUse_im_private_e_private = im_private_e_private.Happy; + export var publicUse_im_private_e_private = im_private_e_private.Grumpy; + var privateUse_im_private_f_private = im_private_f_private(); + export var publicUse_im_private_f_private = im_private_f_private(); + var privateUse_im_private_v_private = im_private_v_private; + export var publicUse_im_private_v_private = im_private_v_private; + var privateUse_im_private_i_private: im_private_i_private; + export var publicUse_im_private_i_private: im_private_i_private; + var privateUse_im_private_mi_private = new im_private_mi_private.c(); + export var publicUse_im_private_mi_private = new im_private_mi_private.c(); + var privateUse_im_private_mu_private: im_private_mu_private.i; + export var publicUse_im_private_mu_private: im_private_mu_private.i; + + + // No Privacy errors - importing public elements + import im_private_c_public = m_public.c_public; + import im_private_e_public = m_public.e_public; + import im_private_f_public = m_public.f_public; + import im_private_v_public = m_public.v_public; + import im_private_i_public = m_public.i_public; + import im_private_mi_public = m_public.mi_public; + import im_private_mu_public = m_public.mu_public; + + // Usage of above decls + var privateUse_im_private_c_public = new im_private_c_public(); + export var publicUse_im_private_c_public = new im_private_c_public(); + var privateUse_im_private_e_public = im_private_e_public.Happy; + export var publicUse_im_private_e_public = im_private_e_public.Grumpy; + var privateUse_im_private_f_public = im_private_f_public(); + export var publicUse_im_private_f_public = im_private_f_public(); + var privateUse_im_private_v_public = im_private_v_public; + export var publicUse_im_private_v_public = im_private_v_public; + var privateUse_im_private_i_public: im_private_i_public; + export var publicUse_im_private_i_public: im_private_i_public; + var privateUse_im_private_mi_public = new im_private_mi_public.c(); + export var publicUse_im_private_mi_public = new im_private_mi_public.c(); + var privateUse_im_private_mu_public: im_private_mu_public.i; + export var publicUse_im_private_mu_public: im_private_mu_public.i; + \ No newline at end of file diff --git a/tests/baselines/reference/privacyTopLevelInternalReferenceImportWithoutExport.js b/tests/baselines/reference/privacyTopLevelInternalReferenceImportWithoutExport.js index 0158aea6ef3f0..bce0ad5c8f6aa 100644 --- a/tests/baselines/reference/privacyTopLevelInternalReferenceImportWithoutExport.js +++ b/tests/baselines/reference/privacyTopLevelInternalReferenceImportWithoutExport.js @@ -197,111 +197,3 @@ define(["require", "exports"], function (require, exports) { var privateUse_im_private_mu_public; exports.publicUse_im_private_mu_public; }); - - -//// [privacyTopLevelInternalReferenceImportWithoutExport.d.ts] -export declare module m_public { - class c_public { - } - enum e_public { - Happy = 0, - Grumpy = 1, - } - function f_public(): c_public; - var v_public: number; - interface i_public { - } - module mi_public { - class c { - } - } - module mu_public { - interface i { - } - } -} -import im_private_c_private = m_private.c_private; -import im_private_e_private = m_private.e_private; -import im_private_i_private = m_private.i_private; -import im_private_mi_private = m_private.mi_private; -import im_private_mu_private = m_private.mu_private; -export declare var publicUse_im_private_c_private: im_private_c_private; -export declare var publicUse_im_private_e_private: im_private_e_private; -export declare var publicUse_im_private_f_private: im_private_c_private; -export declare var publicUse_im_private_v_private: im_private_c_private; -export declare var publicUse_im_private_i_private: im_private_i_private; -export declare var publicUse_im_private_mi_private: im_private_mi_private.c; -export declare var publicUse_im_private_mu_private: im_private_mu_private.i; -import im_private_c_public = m_public.c_public; -import im_private_e_public = m_public.e_public; -import im_private_i_public = m_public.i_public; -import im_private_mi_public = m_public.mi_public; -import im_private_mu_public = m_public.mu_public; -export declare var publicUse_im_private_c_public: im_private_c_public; -export declare var publicUse_im_private_e_public: im_private_e_public; -export declare var publicUse_im_private_f_public: im_private_c_public; -export declare var publicUse_im_private_v_public: number; -export declare var publicUse_im_private_i_public: im_private_i_public; -export declare var publicUse_im_private_mi_public: im_private_mi_public.c; -export declare var publicUse_im_private_mu_public: im_private_mu_public.i; - - -//// [DtsFileErrors] - - -==== tests/cases/compiler/privacyTopLevelInternalReferenceImportWithoutExport.d.ts (5 errors) ==== - export declare module m_public { - class c_public { - } - enum e_public { - Happy = 0, - Grumpy = 1, - } - function f_public(): c_public; - var v_public: number; - interface i_public { - } - module mi_public { - class c { - } - } - module mu_public { - interface i { - } - } - } - import im_private_c_private = m_private.c_private; - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! Cannot find name 'm_private'. - import im_private_e_private = m_private.e_private; - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! Cannot find name 'm_private'. - import im_private_i_private = m_private.i_private; - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! Cannot find name 'm_private'. - import im_private_mi_private = m_private.mi_private; - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! Cannot find name 'm_private'. - import im_private_mu_private = m_private.mu_private; - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! Cannot find name 'm_private'. - export declare var publicUse_im_private_c_private: im_private_c_private; - export declare var publicUse_im_private_e_private: im_private_e_private; - export declare var publicUse_im_private_f_private: im_private_c_private; - export declare var publicUse_im_private_v_private: im_private_c_private; - export declare var publicUse_im_private_i_private: im_private_i_private; - export declare var publicUse_im_private_mi_private: im_private_mi_private.c; - export declare var publicUse_im_private_mu_private: im_private_mu_private.i; - import im_private_c_public = m_public.c_public; - import im_private_e_public = m_public.e_public; - import im_private_i_public = m_public.i_public; - import im_private_mi_public = m_public.mi_public; - import im_private_mu_public = m_public.mu_public; - export declare var publicUse_im_private_c_public: im_private_c_public; - export declare var publicUse_im_private_e_public: im_private_e_public; - export declare var publicUse_im_private_f_public: im_private_c_public; - export declare var publicUse_im_private_v_public: number; - export declare var publicUse_im_private_i_public: im_private_i_public; - export declare var publicUse_im_private_mi_public: im_private_mi_public.c; - export declare var publicUse_im_private_mu_public: im_private_mu_public.i; - \ No newline at end of file From 09ea12d95cd98e0680684f7e414fae7d07213b4e Mon Sep 17 00:00:00 2001 From: Sheetal Nandi Date: Fri, 8 Aug 2014 16:15:09 -0700 Subject: [PATCH 2/5] 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 906074ccc7016..3fba12bf66c9b 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 57124e0f026cb..bb182e9a81269 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 5e882740f1d6c..e507567a577ca 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 23360404b5ed1..999ba787bd9d6 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 2be231c138156..815b8712f15f7 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 66517ca4a9462..f488d418f6dfd 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 70b14ad66a6f8..c4070db5a87eb 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 bc8ba2f63e9eb..79d73add32d65 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 cfec6264a777e..c7abf129404ad 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 40eb8dde17b77..de080873b9feb 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 2cfefecf9eb7f..0000000000000 --- 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 f80e9325871cd..8553d2da8673c 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 e50215a524b91..7d161241899fa 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 e46526f1f8bdc..3930c6cb801e9 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 a0a61453735cc..eb758b913e685 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 113396205bad7..0423a587e84e9 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 1213bbbbe2699..7fe09d1e02bde 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 af546a20b5ba2..c049bfcf8586d 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 0000000000000..50b9dc0242be6 --- /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 04063c6299196..757416c691b97 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 49218d2ef1e32..66eb732ddaebd 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 d7dd5134e9604..f0112fa9501d1 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 3/5] 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 3fba12bf66c9b..b3c61262adbb2 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 c4070db5a87eb..941029774f4ee 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 c7abf129404ad..daa5bac83d734 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 b854841b4b41a..6edc1056fa2de 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 4/5] 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 b3c61262adbb2..b32b86db63939 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 aa89b29acade9..c917a7ba12347 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 e9ce55dd3bdcc..682952ba84f4a 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 bb182e9a81269..973f7123360b9 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 0000000000000..4f7f684d073fb --- /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 0000000000000..947c3c1fc0d0c --- /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 0000000000000..92a2f34990893 --- /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 0000000000000..d113b0a809505 --- /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 0000000000000..269be5ed425fd --- /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 0000000000000..3db10b3da1adb --- /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 0000000000000..834e3d783c69f --- /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 0000000000000..603a51467e82b --- /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 0000000000000..1150cf963bf2a --- /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 0000000000000..e49d31946c678 --- /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 0000000000000..f24ed8ea32b62 --- /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 0000000000000..2eff22327b5fa --- /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(); +} From e26d9e57d402064248ca24a18c341b96549ee38f Mon Sep 17 00:00:00 2001 From: Sheetal Nandi Date: Wed, 13 Aug 2014 18:01:58 -0700 Subject: [PATCH 5/5] Remove unnecessary sort call in alias declarations that get written --- src/compiler/emitter.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index 973f7123360b9..71c44781ce47d 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -1884,7 +1884,7 @@ module ts { function writeAsychronousImportDeclarations(importDeclarations: ImportDeclaration[]) { var oldWriter = writer; - forEach(importDeclarations.sort(), aliasToWrite => { + forEach(importDeclarations, aliasToWrite => { var aliasEmitInfo = forEach(aliasDeclarationEmitInfo, declEmitInfo => declEmitInfo.declaration === aliasToWrite ? declEmitInfo : undefined); writer = createTextWriter(writeSymbol); for (var declarationIndent = aliasEmitInfo.indent; declarationIndent; declarationIndent--) {