From bbb36dc933c7462095f4398715c35e94d8861496 Mon Sep 17 00:00:00 2001 From: Sheetal Nandi Date: Fri, 18 Jul 2014 14:40:47 -0700 Subject: [PATCH 01/15] Make the symbol writing api on the text writer --- src/compiler/checker.ts | 27 +++++++++++++++++++-------- src/compiler/emitter.ts | 14 +++++++++++--- src/compiler/types.ts | 3 +++ 3 files changed, 33 insertions(+), 11 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 7e935b03c19..4e689944394 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -693,6 +693,10 @@ module ts { return qualify } + function isSymbolAccessible(symbol: Symbol, enclosingDeclaration: Node, meaning: SymbolFlags): boolean { + // TODO(shkamat): Actual implementation + } + // 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) { @@ -728,10 +732,15 @@ module ts { return getSymbolName(symbol); } + function writeSymbolToTextWriter(symbol: Symbol, enclosingDeclaration: Node, meaning: SymbolFlags, writer: TextWriter) { + writer.write(symbolToString(symbol, enclosingDeclaration, meaning)); + } + function createSingleLineTextWriter() { var result = ""; return { write(s: string) { result += s; }, + writeSymbol(symbol: Symbol, enclosingDeclaration?: Node, meaning?: SymbolFlags) { writeSymbolToTextWriter(symbol, enclosingDeclaration, meaning, this); }, writeLine() { result += " "; }, increaseIndent() { }, decreaseIndent() { }, @@ -758,7 +767,7 @@ module ts { writeTypeReference(type); } else if (type.flags & (TypeFlags.Class | TypeFlags.Interface | TypeFlags.Enum | TypeFlags.TypeParameter)) { - writer.write(symbolToString(type.symbol, enclosingDeclaration, SymbolFlags.Type)); + writer.writeSymbol(type.symbol, enclosingDeclaration, SymbolFlags.Type); } else if (type.flags & TypeFlags.Anonymous) { writeAnonymousType(type, allowFunctionOrConstructorTypeLiteral); @@ -780,7 +789,7 @@ module ts { writer.write("[]"); } else { - writer.write(symbolToString(type.target.symbol, enclosingDeclaration, SymbolFlags.Type)); + writer.writeSymbol(type.target.symbol, enclosingDeclaration, SymbolFlags.Type); writer.write("<"); for (var i = 0; i < type.typeArguments.length; i++) { if (i > 0) { @@ -814,7 +823,7 @@ module ts { function writeTypeofSymbol(type: ObjectType) { writer.write("typeof "); - writer.write(symbolToString(type.symbol, enclosingDeclaration, SymbolFlags.Value)); + writer.writeSymbol(type.symbol, enclosingDeclaration, SymbolFlags.Value); } function writeLiteralType(type: ObjectType, allowFunctionOrConstructorTypeLiteral: boolean) { @@ -870,7 +879,7 @@ module ts { if (p.flags & (SymbolFlags.Function | SymbolFlags.Method) && !getPropertiesOfType(t).length) { var signatures = getSignaturesOfType(t, SignatureKind.Call); for (var j = 0; j < signatures.length; j++) { - writer.write(symbolToString(p)); + writer.writeSymbol(p); if (isOptionalProperty(p)) { writer.write("?"); } @@ -880,7 +889,7 @@ module ts { } } else { - writer.write(symbolToString(p)); + writer.writeSymbol(p); if (isOptionalProperty(p)) { writer.write("?"); } @@ -902,7 +911,7 @@ module ts { writer.write(", "); } var tp = signature.typeParameters[i]; - writer.write(symbolToString(tp.symbol)); + writer.writeSymbol(tp.symbol); var constraint = getConstraintOfTypeParameter(tp); if (constraint) { writer.write(" extends "); @@ -920,7 +929,7 @@ module ts { if (getDeclarationFlagsFromSymbol(p) & NodeFlags.Rest) { writer.write("..."); } - writer.write(symbolToString(p)); + writer.writeSymbol(p); if (p.valueDeclaration.flags & NodeFlags.QuestionMark || (p.valueDeclaration).initializer) { writer.write("?"); } @@ -6105,7 +6114,9 @@ module ts { isDeclarationVisible: isDeclarationVisible, isImplementationOfOverload: isImplementationOfOverload, writeTypeAtLocation: writeTypeAtLocation, - writeReturnTypeOfSignatureDeclaration: writeReturnTypeOfSignatureDeclaration + writeReturnTypeOfSignatureDeclaration: writeReturnTypeOfSignatureDeclaration, + writeSymbol: writeSymbolToTextWriter, + isSymbolAccessible: isSymbolAccessible }; checkProgram(); return emitFiles(resolver); diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index eec80b72729..0f5e3477778 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -88,7 +88,7 @@ module ts { }; } - function createTextWriter(): EmitTextWriter { + function createTextWriter(writeSymbol: (symbol: Symbol, enclosingDeclaration?: Node, meaning?: SymbolFlags)=> void): EmitTextWriter { var output = ""; var indent = 0; var lineStart = true; @@ -135,6 +135,7 @@ module ts { return { write: write, + writeSymbol: writeSymbol, writeLiteral: writeLiteral, writeLine: writeLine, increaseIndent: () => indent++, @@ -162,7 +163,7 @@ module ts { } function emitJavaScript(jsFilePath: string, root?: SourceFile) { - var writer = createTextWriter(); + var writer = createTextWriter(writeSymbol); var write = writer.write; var writeLine = writer.writeLine; var increaseIndent = writer.increaseIndent; @@ -204,6 +205,8 @@ module ts { /** Sourcemap data that will get encoded */ var sourceMapData: SourceMapData; + function writeSymbol(symbol: Symbol, enclosingDeclaration: Node, meaning: SymbolFlags) { } + function initializeEmitterWithSourceMaps() { var sourceMapDir: string; // The directory in which sourcemap will be @@ -1844,7 +1847,7 @@ module ts { } function emitDeclarations(jsFilePath: string, root?: SourceFile) { - var writer = createTextWriter(); + var writer = createTextWriter(writeSymbol); var write = writer.write; var writeLine = writer.writeLine; var increaseIndent = writer.increaseIndent; @@ -1852,6 +1855,11 @@ module ts { var enclosingDeclaration: Node; + function writeSymbol(symbol: Symbol, enclosingDeclaration?: Node, meaning?: SymbolFlags) { + // TODO(shkamat): Report error if the symbol is not accessible + resolver.writeSymbol(symbol, enclosingDeclaration, meaning, writer); + } + function emitLines(nodes: Node[]) { for (var i = 0, n = nodes.length; i < n; i++) { emitNode(nodes[i]); diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 65ca7d01fbd..9b446ff0153 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -597,6 +597,7 @@ module ts { export interface TextWriter { write(s: string): void; + writeSymbol(symbol: Symbol, enclosingDeclaration?: Node, meaning?: SymbolFlags): void; writeLine(): void; increaseIndent(): void; decreaseIndent(): void; @@ -625,6 +626,8 @@ module ts { isImplementationOfOverload(node: FunctionDeclaration): boolean; writeTypeAtLocation(location: Node, enclosingDeclaration: Node, flags: TypeFormatFlags, writer: TextWriter): void; 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): boolean; } export enum SymbolFlags { From 999b7fed928cb803b83cbb4555560f623060f10d Mon Sep 17 00:00:00 2001 From: Sheetal Nandi Date: Fri, 18 Jul 2014 18:06:37 -0700 Subject: [PATCH 02/15] Checker and emitter changes to report errors on inaccessibility of symbols when writing types in declaration file --- src/compiler/checker.ts | 36 ++++++++++++++++++++++++++++++++---- src/compiler/emitter.ts | 30 +++++++++++++++++++++++++++--- src/compiler/types.ts | 14 +++++++++++++- 3 files changed, 72 insertions(+), 8 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 4e689944394..378e23bf83d 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -645,7 +645,7 @@ module ts { } // If symbol is directly available by its name in the symbol table - if (isAccessible(symbols[symbol.name])) { + if (hasProperty(symbols, symbol.name) && isAccessible(symbols[symbol.name])) { return symbol; } @@ -668,7 +668,7 @@ module ts { var qualify = false; forEachSymbolTableInScope(enclosingDeclaration, symbolTable => { // If symbol of this name is not available in the symbol table we are ok - if (!symbolTable[symbol.name]) { + if (!hasProperty(symbolTable, symbol.name)) { // Continue to the next symbol table return false; } @@ -693,8 +693,36 @@ module ts { return qualify } - function isSymbolAccessible(symbol: Symbol, enclosingDeclaration: Node, meaning: SymbolFlags): boolean { - // TODO(shkamat): Actual implementation + function isSymbolAccessible(symbol: Symbol, enclosingDeclaration: Node, meaning: SymbolFlags): SymbolAccessiblityResult { + if (symbol && enclosingDeclaration && !(symbol.flags & SymbolFlags.TypeParameter)) { + var initialSymbol = symbol; + var meaningToLook = meaning; + while (symbol) { + // Symbol is accessible if it by itself is accessible + var accessibleSymbol = getAccessibleSymbol(symbol, enclosingDeclaration, meaningToLook); + if (accessibleSymbol) { + if (forEach(accessibleSymbol.declarations, declaration => !isDeclarationVisible(declaration))) { + return { + accessibility: SymbolAccessibility.NotAccessible, + errorSymbolName: symbolToString(initialSymbol, enclosingDeclaration, meaning), + errorModuleName: symbol !== initialSymbol ? symbolToString(symbol, enclosingDeclaration, SymbolFlags.Namespace) : undefined + }; + } + return { accessibility: SymbolAccessibility.Accessible }; + } + + meaningToLook = SymbolFlags.Namespace; + symbol = symbol.parent; + } + + // This is a local symbol that cannot be named + return { + accessibility: SymbolAccessibility.CannotBeNamed, + errorSymbolName: symbolToString(initialSymbol, enclosingDeclaration, meaning), + }; + } + + return { accessibility: SymbolAccessibility.Accessible }; } // Enclosing declaration is optional when we dont want to get qualified name in the enclosing declaration scope diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index 0f5e3477778..bf6f8c7fff9 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -1854,10 +1854,30 @@ module ts { var decreaseIndent = writer.decreaseIndent; var enclosingDeclaration: Node; + var reportedDeclarationError = false; + + var getSymbolVisibilityDiagnosticMessage: (symbolAccesibilityResult: SymbolAccessiblityResult) => { + errorNode: Node; + diagnosticMessage: DiagnosticMessage; + typeName: Identifier + } function writeSymbol(symbol: Symbol, enclosingDeclaration?: Node, meaning?: SymbolFlags) { - // TODO(shkamat): Report error if the symbol is not accessible - resolver.writeSymbol(symbol, enclosingDeclaration, meaning, writer); + var symbolAccesibilityResult = resolver.isSymbolAccessible(symbol, enclosingDeclaration, meaning); + // TODO(shkamat): Since we dont have error reporting for all the cases as yet we have this check on handler being present + if (!getSymbolVisibilityDiagnosticMessage || symbolAccesibilityResult.accessibility === SymbolAccessibility.Accessible) { + resolver.writeSymbol(symbol, enclosingDeclaration, meaning, writer); + } + else { + // Report error + reportedDeclarationError = true; + var errorInfo = getSymbolVisibilityDiagnosticMessage(symbolAccesibilityResult); + diagnostics.push(createDiagnosticForNode(errorInfo.errorNode, + errorInfo.diagnosticMessage, + getSourceTextOfLocalNode(errorInfo.typeName), + symbolAccesibilityResult.errorSymbolName, + symbolAccesibilityResult.errorModuleName)); + } } function emitLines(nodes: Node[]) { @@ -2296,7 +2316,11 @@ module ts { }); } - writeFile(getModuleNameFromFilename(jsFilePath) + ".d.ts", referencePathsOutput + writer.getText()); + // TODO(shkamat): Should we not write any declaration file if any of them can produce error, + // or should we just not write this file like we are doing now + if (!reportedDeclarationError) { + writeFile(getModuleNameFromFilename(jsFilePath) + ".d.ts", referencePathsOutput + writer.getText()); + } } var shouldEmitDeclarations = resolver.shouldEmitDeclarations(); diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 9b446ff0153..6bf3f971a95 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -611,6 +611,18 @@ module ts { WriteArrayAsGenericType = 0x00000001, // Declarations } + export enum SymbolAccessibility { + Accessible, + NotAccessible, + CannotBeNamed + } + + export interface SymbolAccessiblityResult { + accessibility: SymbolAccessibility; + errorSymbolName?: string // Optional symbol name that results in error + errorModuleName?: string // If the symbol is not visibile from module, module's name + } + export interface EmitResolver { getProgram(): Program; getModuleObjectName(node: ModuleDeclaration): string; @@ -627,7 +639,7 @@ module ts { writeTypeAtLocation(location: Node, enclosingDeclaration: Node, flags: TypeFormatFlags, writer: TextWriter): void; 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): boolean; + isSymbolAccessible(symbol: Symbol, enclosingDeclaration: Node, meaning: SymbolFlags): SymbolAccessiblityResult; } export enum SymbolFlags { From 09ec1bb9ae92557f50becbb31c003643a1bb8862 Mon Sep 17 00:00:00 2001 From: Sheetal Nandi Date: Fri, 18 Jul 2014 18:07:38 -0700 Subject: [PATCH 03/15] Report error on Class/Interface heritage clause if it cant be accessed Fixes #78 and #83 --- .../diagnosticInformationMap.generated.ts | 6 + src/compiler/diagnosticMessages.json | 24 ++ src/compiler/emitter.ts | 48 +++ src/harness/harness.ts | 8 +- ...ivacyClassExtendsClauseDeclFile.errors.txt | 106 ++++++ .../privacyClassExtendsClauseDeclFile.js | 351 ++++++++++++++++++ ...cyClassImplementsClauseDeclFile.errors.txt | 105 ++++++ .../privacyClassImplementsClauseDeclFile.js | 239 ++++++++++++ ...yInterfaceExtendsClauseDeclFile.errors.txt | 105 ++++++ .../privacyInterfaceExtendsClauseDeclFile.js | 98 +++++ .../privacyClassExtendsClauseDeclFile.ts | 97 +++++ .../privacyClassImplementsClauseDeclFile.ts | 94 +++++ .../privacyInterfaceExtendsClauseDeclFile.ts | 94 +++++ 13 files changed, 1371 insertions(+), 4 deletions(-) create mode 100644 tests/baselines/reference/privacyClassExtendsClauseDeclFile.errors.txt create mode 100644 tests/baselines/reference/privacyClassExtendsClauseDeclFile.js create mode 100644 tests/baselines/reference/privacyClassImplementsClauseDeclFile.errors.txt create mode 100644 tests/baselines/reference/privacyClassImplementsClauseDeclFile.js create mode 100644 tests/baselines/reference/privacyInterfaceExtendsClauseDeclFile.errors.txt create mode 100644 tests/baselines/reference/privacyInterfaceExtendsClauseDeclFile.js create mode 100644 tests/cases/compiler/privacyClassExtendsClauseDeclFile.ts create mode 100644 tests/cases/compiler/privacyClassImplementsClauseDeclFile.ts create mode 100644 tests/cases/compiler/privacyInterfaceExtendsClauseDeclFile.ts diff --git a/src/compiler/diagnosticInformationMap.generated.ts b/src/compiler/diagnosticInformationMap.generated.ts index d9e35f29086..80bf686c8ae 100644 --- a/src/compiler/diagnosticInformationMap.generated.ts +++ b/src/compiler/diagnosticInformationMap.generated.ts @@ -99,6 +99,12 @@ module ts { A_constructor_implementation_cannot_be_declared_in_an_ambient_context: { code: 1111, category: DiagnosticCategory.Error, key: "A constructor implementation cannot be declared in an ambient context." }, A_class_member_cannot_be_declared_optional: { code: 1112, category: DiagnosticCategory.Error, key: "A class member cannot be declared optional." }, Duplicate_identifier_0: { code: 2000, category: DiagnosticCategory.Error, key: "Duplicate identifier '{0}'." }, + Extends_clause_of_exported_class_0_has_or_is_using_private_name_1: { code: 2018, category: DiagnosticCategory.Error, key: "Extends clause of exported class '{0}' has or is using private name '{1}'." }, + Implements_clause_of_exported_class_0_has_or_is_using_private_name_1: { code: 2019, category: DiagnosticCategory.Error, key: "Implements clause of exported class '{0}' has or is using private name '{1}'." }, + Extends_clause_of_exported_interface_0_has_or_is_using_private_name_1: { code: 2020, category: DiagnosticCategory.Error, key: "Extends clause of exported interface '{0}' has or is using private name '{1}'." }, + Extends_clause_of_exported_class_0_has_or_is_using_name_1_from_private_module_2: { code: 2021, category: DiagnosticCategory.Error, key: "Extends clause of exported class '{0}' has or is using name '{1}' from private module '{2}'." }, + Implements_clause_of_exported_class_0_has_or_is_using_name_1_from_private_module_2: { code: 2022, category: DiagnosticCategory.Error, key: "Implements clause of exported class '{0}' has or is using name '{1}' from private module '{2}'." }, + Extends_clause_of_exported_interface_0_has_or_is_using_name_1_from_private_module_2: { code: 2023, category: DiagnosticCategory.Error, key: "Extends clause of exported interface '{0}' has or is using name '{1}' from private module '{2}'." }, new_T_cannot_be_used_to_create_an_array_Use_new_Array_T_instead: { code: 2068, category: DiagnosticCategory.Error, key: "'new T[]' cannot be used to create an array. Use 'new Array()' instead." }, Multiple_constructor_implementations_are_not_allowed: { code: 2070, category: DiagnosticCategory.Error, key: "Multiple constructor implementations are not allowed." }, A_class_may_only_implement_another_class_or_interface: { code: 2074, category: DiagnosticCategory.Error, key: "A class may only implement another class or interface." }, diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index 92b8d1a3e0e..362f4cd6129 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -390,6 +390,30 @@ "category": "Error", "code": 2000 }, + "Extends clause of exported class '{0}' has or is using private name '{1}'.": { + "category": "Error", + "code": 2018 + }, + "Implements clause of exported class '{0}' has or is using private name '{1}'.": { + "category": "Error", + "code": 2019 + }, + "Extends clause of exported interface '{0}' has or is using private name '{1}'.": { + "category": "Error", + "code": 2020 + }, + "Extends clause of exported class '{0}' has or is using name '{1}' from private module '{2}'.": { + "category": "Error", + "code": 2021 + }, + "Implements clause of exported class '{0}' has or is using name '{1}' from private module '{2}'.": { + "category": "Error", + "code": 2022 + }, + "Extends clause of exported interface '{0}' has or is using name '{1}' from private module '{2}'.": { + "category": "Error", + "code": 2023 + }, "'new T[]' cannot be used to create an array. Use 'new Array()' instead.": { "category": "Error", "code": 2068 diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index bf6f8c7fff9..5de70cbc318 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -2027,6 +2027,54 @@ module ts { function emitHeritageClause(typeReferences: TypeReferenceNode[], isImplementsList: boolean) { function emitTypeOfTypeReference(node: Node) { + function getHeritageClauseVisibilityError(symbolAccesibilityResult: SymbolAccessiblityResult) { + var diagnosticMessage: DiagnosticMessage; + 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; + } + } + else { + // CannotBeNamed + // TODO(shkamat): CannotBeNamed error needs to be handled + } + } + 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; + } + } + else { + // CannotBeNamed + // TODO(shkamat): CannotBeNamed error needs to be handled + } + } + + return { + diagnosticMessage: diagnosticMessage, + errorNode: node, + typeName: (node.parent).name + } + } + getSymbolVisibilityDiagnosticMessage = getHeritageClauseVisibilityError; resolver.writeTypeAtLocation(node, enclosingDeclaration, TypeFormatFlags.WriteArrayAsGenericType, writer); } diff --git a/src/harness/harness.ts b/src/harness/harness.ts index c35ba97df3a..b68c27712fc 100644 --- a/src/harness/harness.ts +++ b/src/harness/harness.ts @@ -736,13 +736,13 @@ module Harness { checker.checkProgram(); // only emit if there weren't parse errors - var sourceMapData: ts.SourceMapData[]; + var emitResult: ts.EmitResult; if (!hadParseErrors) { - sourceMapData = checker.emitFiles().sourceMaps; + emitResult = checker.emitFiles(); } var errors: MinimalDiagnostic[] = []; - program.getDiagnostics().concat(checker.getDiagnostics()).forEach(err => { + program.getDiagnostics().concat(checker.getDiagnostics()).concat(emitResult ? emitResult.errors : []).forEach(err => { // TODO: new compiler formats errors after this point to add . and newlines so we'll just do it manually for now errors.push({ filename: err.file && err.file.filename, start: err.start, end: err.start + err.length, line: 0, character: 0, message: err.messageText }); }); @@ -750,7 +750,7 @@ module Harness { var result = new CompilerResult(fileOutputs, errors, []); // Covert the source Map data into the baseline - result.updateSourceMapRecord(program, sourceMapData); + result.updateSourceMapRecord(program, emitResult ? emitResult.sourceMaps : undefined); onComplete(result); return options; } diff --git a/tests/baselines/reference/privacyClassExtendsClauseDeclFile.errors.txt b/tests/baselines/reference/privacyClassExtendsClauseDeclFile.errors.txt new file mode 100644 index 00000000000..598dead5154 --- /dev/null +++ b/tests/baselines/reference/privacyClassExtendsClauseDeclFile.errors.txt @@ -0,0 +1,106 @@ +==== tests/cases/compiler/privacyClassExtendsClauseDeclFile_externalModule.ts (4 errors) ==== + + export module publicModule { + export class publicClassInPublicModule { + private f1() { + } + } + + class privateClassInPublicModule { + } + + class privateClassExtendingPublicClassInModule extends publicClassInPublicModule { + } + class privateClassExtendingPrivateClassInModule extends privateClassInPublicModule { + } + export class publicClassExtendingPublicClassInModule extends publicClassInPublicModule { + } + export class publicClassExtendingPrivateClassInModule extends privateClassInPublicModule { // Should error + ~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! Extends clause of exported class 'publicClassExtendingPrivateClassInModule' has or is using private name 'privateClassInPublicModule'. + } + + class privateClassExtendingFromPrivateModuleClass extends privateModule.publicClassInPrivateModule { + } + export class publicClassExtendingFromPrivateModuleClass extends privateModule.publicClassInPrivateModule { // Should error + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! Extends clause of exported class 'publicClassExtendingFromPrivateModuleClass' has or is using name 'privateModule.publicClassInPrivateModule' from private module 'privateModule'. + } + } + + module privateModule { + export class publicClassInPrivateModule { + private f1() { + } + } + + class privateClassInPrivateModule { + } + + class privateClassExtendingPublicClassInModule extends publicClassInPrivateModule { + } + class privateClassExtendingPrivateClassInModule extends privateClassInPrivateModule { + } + export class publicClassExtendingPublicClassInModule extends publicClassInPrivateModule { + } + export class publicClassExtendingPrivateClassInModule extends privateClassInPrivateModule { + } + + class privateClassExtendingFromPrivateModuleClass extends privateModule.publicClassInPrivateModule { + } + export class publicClassExtendingFromPrivateModuleClass extends privateModule.publicClassInPrivateModule { + } + } + + export class publicClass { + private f1() { + } + } + + class privateClass { + } + + class privateClassExtendingPublicClass extends publicClass { + } + class privateClassExtendingPrivateClassInModule extends privateClass { + } + export class publicClassExtendingPublicClass extends publicClass { + } + export class publicClassExtendingPrivateClass extends privateClass { // Should error + ~~~~~~~~~~~~ +!!! Extends clause of exported class 'publicClassExtendingPrivateClass' has or is using private name 'privateClass'. + } + + class privateClassExtendingFromPrivateModuleClass extends privateModule.publicClassInPrivateModule { + } + export class publicClassExtendingFromPrivateModuleClass extends privateModule.publicClassInPrivateModule { // Should error + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! Extends clause of exported class 'publicClassExtendingFromPrivateModuleClass' has or is using name 'privateModule.publicClassInPrivateModule' from private module 'privateModule'. + } + +==== tests/cases/compiler/privacyClassExtendsClauseDeclFile_GlobalFile.ts (1 errors) ==== + module publicModuleInGlobal { + export class publicClassInPublicModule { + private f1() { + } + } + + class privateClassInPublicModule { + } + + class privateClassExtendingPublicClassInModule extends publicClassInPublicModule { + } + class privateClassExtendingPrivateClassInModule extends privateClassInPublicModule { + } + export class publicClassExtendingPublicClassInModule extends publicClassInPublicModule { + } + export class publicClassExtendingPrivateClassInModule extends privateClassInPublicModule { // Should error + ~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! Extends clause of exported class 'publicClassExtendingPrivateClassInModule' has or is using private name 'privateClassInPublicModule'. + } + } + class publicClassInGlobal { + } + class publicClassExtendingPublicClassInGlobal extends publicClassInGlobal { + } + \ No newline at end of file diff --git a/tests/baselines/reference/privacyClassExtendsClauseDeclFile.js b/tests/baselines/reference/privacyClassExtendsClauseDeclFile.js new file mode 100644 index 00000000000..77adca24aa6 --- /dev/null +++ b/tests/baselines/reference/privacyClassExtendsClauseDeclFile.js @@ -0,0 +1,351 @@ +//// [tests/cases/compiler/privacyClassExtendsClauseDeclFile.ts] //// + +//// [privacyClassExtendsClauseDeclFile_externalModule.ts] + +export module publicModule { + export class publicClassInPublicModule { + private f1() { + } + } + + class privateClassInPublicModule { + } + + class privateClassExtendingPublicClassInModule extends publicClassInPublicModule { + } + class privateClassExtendingPrivateClassInModule extends privateClassInPublicModule { + } + export class publicClassExtendingPublicClassInModule extends publicClassInPublicModule { + } + export class publicClassExtendingPrivateClassInModule extends privateClassInPublicModule { // Should error + } + + class privateClassExtendingFromPrivateModuleClass extends privateModule.publicClassInPrivateModule { + } + export class publicClassExtendingFromPrivateModuleClass extends privateModule.publicClassInPrivateModule { // Should error + } +} + +module privateModule { + export class publicClassInPrivateModule { + private f1() { + } + } + + class privateClassInPrivateModule { + } + + class privateClassExtendingPublicClassInModule extends publicClassInPrivateModule { + } + class privateClassExtendingPrivateClassInModule extends privateClassInPrivateModule { + } + export class publicClassExtendingPublicClassInModule extends publicClassInPrivateModule { + } + export class publicClassExtendingPrivateClassInModule extends privateClassInPrivateModule { + } + + class privateClassExtendingFromPrivateModuleClass extends privateModule.publicClassInPrivateModule { + } + export class publicClassExtendingFromPrivateModuleClass extends privateModule.publicClassInPrivateModule { + } +} + +export class publicClass { + private f1() { + } +} + +class privateClass { +} + +class privateClassExtendingPublicClass extends publicClass { +} +class privateClassExtendingPrivateClassInModule extends privateClass { +} +export class publicClassExtendingPublicClass extends publicClass { +} +export class publicClassExtendingPrivateClass extends privateClass { // Should error +} + +class privateClassExtendingFromPrivateModuleClass extends privateModule.publicClassInPrivateModule { +} +export class publicClassExtendingFromPrivateModuleClass extends privateModule.publicClassInPrivateModule { // Should error +} + +//// [privacyClassExtendsClauseDeclFile_GlobalFile.ts] +module publicModuleInGlobal { + export class publicClassInPublicModule { + private f1() { + } + } + + class privateClassInPublicModule { + } + + class privateClassExtendingPublicClassInModule extends publicClassInPublicModule { + } + class privateClassExtendingPrivateClassInModule extends privateClassInPublicModule { + } + export class publicClassExtendingPublicClassInModule extends publicClassInPublicModule { + } + export class publicClassExtendingPrivateClassInModule extends privateClassInPublicModule { // Should error + } +} +class publicClassInGlobal { +} +class publicClassExtendingPublicClassInGlobal extends publicClassInGlobal { +} + + +//// [privacyClassExtendsClauseDeclFile_externalModule.js] +var __extends = this.__extends || function (d, b) { + for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; + function __() { this.constructor = d; } + __.prototype = b.prototype; + d.prototype = new __(); +}; +(function (publicModule) { + var publicClassInPublicModule = (function () { + function publicClassInPublicModule() { + } + publicClassInPublicModule.prototype.f1 = function () { + }; + return publicClassInPublicModule; + })(); + publicModule.publicClassInPublicModule = publicClassInPublicModule; + var privateClassInPublicModule = (function () { + function privateClassInPublicModule() { + } + return privateClassInPublicModule; + })(); + var privateClassExtendingPublicClassInModule = (function (_super) { + __extends(privateClassExtendingPublicClassInModule, _super); + function privateClassExtendingPublicClassInModule() { + _super.apply(this, arguments); + } + return privateClassExtendingPublicClassInModule; + })(publicClassInPublicModule); + var privateClassExtendingPrivateClassInModule = (function (_super) { + __extends(privateClassExtendingPrivateClassInModule, _super); + function privateClassExtendingPrivateClassInModule() { + _super.apply(this, arguments); + } + return privateClassExtendingPrivateClassInModule; + })(privateClassInPublicModule); + var publicClassExtendingPublicClassInModule = (function (_super) { + __extends(publicClassExtendingPublicClassInModule, _super); + function publicClassExtendingPublicClassInModule() { + _super.apply(this, arguments); + } + return publicClassExtendingPublicClassInModule; + })(publicClassInPublicModule); + publicModule.publicClassExtendingPublicClassInModule = publicClassExtendingPublicClassInModule; + var publicClassExtendingPrivateClassInModule = (function (_super) { + __extends(publicClassExtendingPrivateClassInModule, _super); + function publicClassExtendingPrivateClassInModule() { + _super.apply(this, arguments); + } + return publicClassExtendingPrivateClassInModule; + })(privateClassInPublicModule); + publicModule.publicClassExtendingPrivateClassInModule = publicClassExtendingPrivateClassInModule; + var privateClassExtendingFromPrivateModuleClass = (function (_super) { + __extends(privateClassExtendingFromPrivateModuleClass, _super); + function privateClassExtendingFromPrivateModuleClass() { + _super.apply(this, arguments); + } + return privateClassExtendingFromPrivateModuleClass; + })(privateModule.publicClassInPrivateModule); + var publicClassExtendingFromPrivateModuleClass = (function (_super) { + __extends(publicClassExtendingFromPrivateModuleClass, _super); + function publicClassExtendingFromPrivateModuleClass() { + _super.apply(this, arguments); + } + return publicClassExtendingFromPrivateModuleClass; + })(privateModule.publicClassInPrivateModule); + publicModule.publicClassExtendingFromPrivateModuleClass = publicClassExtendingFromPrivateModuleClass; +})(exports.publicModule || (exports.publicModule = {})); +var publicModule = exports.publicModule; +var privateModule; +(function (privateModule) { + var publicClassInPrivateModule = (function () { + function publicClassInPrivateModule() { + } + publicClassInPrivateModule.prototype.f1 = function () { + }; + return publicClassInPrivateModule; + })(); + privateModule.publicClassInPrivateModule = publicClassInPrivateModule; + var privateClassInPrivateModule = (function () { + function privateClassInPrivateModule() { + } + return privateClassInPrivateModule; + })(); + var privateClassExtendingPublicClassInModule = (function (_super) { + __extends(privateClassExtendingPublicClassInModule, _super); + function privateClassExtendingPublicClassInModule() { + _super.apply(this, arguments); + } + return privateClassExtendingPublicClassInModule; + })(publicClassInPrivateModule); + var privateClassExtendingPrivateClassInModule = (function (_super) { + __extends(privateClassExtendingPrivateClassInModule, _super); + function privateClassExtendingPrivateClassInModule() { + _super.apply(this, arguments); + } + return privateClassExtendingPrivateClassInModule; + })(privateClassInPrivateModule); + var publicClassExtendingPublicClassInModule = (function (_super) { + __extends(publicClassExtendingPublicClassInModule, _super); + function publicClassExtendingPublicClassInModule() { + _super.apply(this, arguments); + } + return publicClassExtendingPublicClassInModule; + })(publicClassInPrivateModule); + privateModule.publicClassExtendingPublicClassInModule = publicClassExtendingPublicClassInModule; + var publicClassExtendingPrivateClassInModule = (function (_super) { + __extends(publicClassExtendingPrivateClassInModule, _super); + function publicClassExtendingPrivateClassInModule() { + _super.apply(this, arguments); + } + return publicClassExtendingPrivateClassInModule; + })(privateClassInPrivateModule); + privateModule.publicClassExtendingPrivateClassInModule = publicClassExtendingPrivateClassInModule; + var privateClassExtendingFromPrivateModuleClass = (function (_super) { + __extends(privateClassExtendingFromPrivateModuleClass, _super); + function privateClassExtendingFromPrivateModuleClass() { + _super.apply(this, arguments); + } + return privateClassExtendingFromPrivateModuleClass; + })(privateModule.publicClassInPrivateModule); + var publicClassExtendingFromPrivateModuleClass = (function (_super) { + __extends(publicClassExtendingFromPrivateModuleClass, _super); + function publicClassExtendingFromPrivateModuleClass() { + _super.apply(this, arguments); + } + return publicClassExtendingFromPrivateModuleClass; + })(privateModule.publicClassInPrivateModule); + privateModule.publicClassExtendingFromPrivateModuleClass = publicClassExtendingFromPrivateModuleClass; +})(privateModule || (privateModule = {})); +var publicClass = (function () { + function publicClass() { + } + publicClass.prototype.f1 = function () { + }; + return publicClass; +})(); +exports.publicClass = publicClass; +var privateClass = (function () { + function privateClass() { + } + return privateClass; +})(); +var privateClassExtendingPublicClass = (function (_super) { + __extends(privateClassExtendingPublicClass, _super); + function privateClassExtendingPublicClass() { + _super.apply(this, arguments); + } + return privateClassExtendingPublicClass; +})(publicClass); +var privateClassExtendingPrivateClassInModule = (function (_super) { + __extends(privateClassExtendingPrivateClassInModule, _super); + function privateClassExtendingPrivateClassInModule() { + _super.apply(this, arguments); + } + return privateClassExtendingPrivateClassInModule; +})(privateClass); +var publicClassExtendingPublicClass = (function (_super) { + __extends(publicClassExtendingPublicClass, _super); + function publicClassExtendingPublicClass() { + _super.apply(this, arguments); + } + return publicClassExtendingPublicClass; +})(publicClass); +exports.publicClassExtendingPublicClass = publicClassExtendingPublicClass; +var publicClassExtendingPrivateClass = (function (_super) { + __extends(publicClassExtendingPrivateClass, _super); + function publicClassExtendingPrivateClass() { + _super.apply(this, arguments); + } + return publicClassExtendingPrivateClass; +})(privateClass); +exports.publicClassExtendingPrivateClass = publicClassExtendingPrivateClass; +var privateClassExtendingFromPrivateModuleClass = (function (_super) { + __extends(privateClassExtendingFromPrivateModuleClass, _super); + function privateClassExtendingFromPrivateModuleClass() { + _super.apply(this, arguments); + } + return privateClassExtendingFromPrivateModuleClass; +})(privateModule.publicClassInPrivateModule); +var publicClassExtendingFromPrivateModuleClass = (function (_super) { + __extends(publicClassExtendingFromPrivateModuleClass, _super); + function publicClassExtendingFromPrivateModuleClass() { + _super.apply(this, arguments); + } + return publicClassExtendingFromPrivateModuleClass; +})(privateModule.publicClassInPrivateModule); +exports.publicClassExtendingFromPrivateModuleClass = publicClassExtendingFromPrivateModuleClass; +//// [privacyClassExtendsClauseDeclFile_GlobalFile.js] +var __extends = this.__extends || function (d, b) { + for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; + function __() { this.constructor = d; } + __.prototype = b.prototype; + d.prototype = new __(); +}; +var publicModuleInGlobal; +(function (publicModuleInGlobal) { + var publicClassInPublicModule = (function () { + function publicClassInPublicModule() { + } + publicClassInPublicModule.prototype.f1 = function () { + }; + return publicClassInPublicModule; + })(); + publicModuleInGlobal.publicClassInPublicModule = publicClassInPublicModule; + var privateClassInPublicModule = (function () { + function privateClassInPublicModule() { + } + return privateClassInPublicModule; + })(); + var privateClassExtendingPublicClassInModule = (function (_super) { + __extends(privateClassExtendingPublicClassInModule, _super); + function privateClassExtendingPublicClassInModule() { + _super.apply(this, arguments); + } + return privateClassExtendingPublicClassInModule; + })(publicClassInPublicModule); + var privateClassExtendingPrivateClassInModule = (function (_super) { + __extends(privateClassExtendingPrivateClassInModule, _super); + function privateClassExtendingPrivateClassInModule() { + _super.apply(this, arguments); + } + return privateClassExtendingPrivateClassInModule; + })(privateClassInPublicModule); + var publicClassExtendingPublicClassInModule = (function (_super) { + __extends(publicClassExtendingPublicClassInModule, _super); + function publicClassExtendingPublicClassInModule() { + _super.apply(this, arguments); + } + return publicClassExtendingPublicClassInModule; + })(publicClassInPublicModule); + publicModuleInGlobal.publicClassExtendingPublicClassInModule = publicClassExtendingPublicClassInModule; + var publicClassExtendingPrivateClassInModule = (function (_super) { + __extends(publicClassExtendingPrivateClassInModule, _super); + function publicClassExtendingPrivateClassInModule() { + _super.apply(this, arguments); + } + return publicClassExtendingPrivateClassInModule; + })(privateClassInPublicModule); + publicModuleInGlobal.publicClassExtendingPrivateClassInModule = publicClassExtendingPrivateClassInModule; +})(publicModuleInGlobal || (publicModuleInGlobal = {})); +var publicClassInGlobal = (function () { + function publicClassInGlobal() { + } + return publicClassInGlobal; +})(); +var publicClassExtendingPublicClassInGlobal = (function (_super) { + __extends(publicClassExtendingPublicClassInGlobal, _super); + function publicClassExtendingPublicClassInGlobal() { + _super.apply(this, arguments); + } + return publicClassExtendingPublicClassInGlobal; +})(publicClassInGlobal); diff --git a/tests/baselines/reference/privacyClassImplementsClauseDeclFile.errors.txt b/tests/baselines/reference/privacyClassImplementsClauseDeclFile.errors.txt new file mode 100644 index 00000000000..61b5e199b07 --- /dev/null +++ b/tests/baselines/reference/privacyClassImplementsClauseDeclFile.errors.txt @@ -0,0 +1,105 @@ +==== tests/cases/compiler/privacyClassImplementsClauseDeclFile_externalModule.ts (5 errors) ==== + + export module publicModule { + export interface publicInterfaceInPublicModule { + } + + interface privateInterfaceInPublicModule { + } + + class privateClassImplementingPublicInterfaceInModule implements publicInterfaceInPublicModule { + } + class privateClassImplementingPrivateInterfaceInModule implements privateInterfaceInPublicModule { + } + export class publicClassImplementingPublicInterfaceInModule implements publicInterfaceInPublicModule { + } + export class publicClassImplementingPrivateInterfaceInModule implements privateInterfaceInPublicModule { // Should error + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! Implements clause of exported class 'publicClassImplementingPrivateInterfaceInModule' has or is using private name 'privateInterfaceInPublicModule'. + } + + class privateClassImplementingFromPrivateModuleInterface implements privateModule.publicInterfaceInPrivateModule { + } + export class publicClassImplementingFromPrivateModuleInterface implements privateModule.publicInterfaceInPrivateModule { // Should error + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! Implements clause of exported class 'publicClassImplementingFromPrivateModuleInterface' has or is using name 'privateModule.publicInterfaceInPrivateModule' from private module 'privateModule'. + } + + export class publicClassImplementingPrivateAndPublicInterface implements privateInterfaceInPublicModule, publicInterfaceInPublicModule { // Should error + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! Implements clause of exported class 'publicClassImplementingPrivateAndPublicInterface' has or is using private name 'privateInterfaceInPublicModule'. + } + } + + module privateModule { + export interface publicInterfaceInPrivateModule { + + } + + interface privateInterfaceInPrivateModule { + } + + class privateClassImplementingPublicInterfaceInModule implements publicInterfaceInPrivateModule { + } + class privateClassImplementingPrivateInterfaceInModule implements privateInterfaceInPrivateModule { + } + export class publicClassImplementingPublicInterfaceInModule implements publicInterfaceInPrivateModule { + } + export class publicClassImplementingPrivateInterfaceInModule implements privateInterfaceInPrivateModule { + } + + class privateClassImplementingFromPrivateModuleInterface implements privateModule.publicInterfaceInPrivateModule { + } + export class publicClassImplementingFromPrivateModuleInterface implements privateModule.publicInterfaceInPrivateModule { + } + } + + export interface publicInterface { + + } + + interface privateInterface { + } + + class privateClassImplementingPublicInterface implements publicInterface { + } + class privateClassImplementingPrivateInterfaceInModule implements privateInterface { + } + export class publicClassImplementingPublicInterface implements publicInterface { + } + export class publicClassImplementingPrivateInterface implements privateInterface { // Should error + ~~~~~~~~~~~~~~~~ +!!! Implements clause of exported class 'publicClassImplementingPrivateInterface' has or is using private name 'privateInterface'. + } + + class privateClassImplementingFromPrivateModuleInterface implements privateModule.publicInterfaceInPrivateModule { + } + export class publicClassImplementingFromPrivateModuleInterface implements privateModule.publicInterfaceInPrivateModule { // Should error + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! Implements clause of exported class 'publicClassImplementingFromPrivateModuleInterface' has or is using name 'privateModule.publicInterfaceInPrivateModule' from private module 'privateModule'. + } + +==== tests/cases/compiler/privacyClassImplementsClauseDeclFile_GlobalFile.ts (1 errors) ==== + module publicModuleInGlobal { + export interface publicInterfaceInPublicModule { + } + + interface privateInterfaceInPublicModule { + } + + class privateClassImplementingPublicInterfaceInModule implements publicInterfaceInPublicModule { + } + class privateClassImplementingPrivateInterfaceInModule implements privateInterfaceInPublicModule { + } + export class publicClassImplementingPublicInterfaceInModule implements publicInterfaceInPublicModule { + } + export class publicClassImplementingPrivateInterfaceInModule implements privateInterfaceInPublicModule { // Should error + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! Implements clause of exported class 'publicClassImplementingPrivateInterfaceInModule' has or is using private name 'privateInterfaceInPublicModule'. + } + } + interface publicInterfaceInGlobal { + } + class publicClassImplementingPublicInterfaceInGlobal implements publicInterfaceInGlobal { + } + \ No newline at end of file diff --git a/tests/baselines/reference/privacyClassImplementsClauseDeclFile.js b/tests/baselines/reference/privacyClassImplementsClauseDeclFile.js new file mode 100644 index 00000000000..d4a1ffafd53 --- /dev/null +++ b/tests/baselines/reference/privacyClassImplementsClauseDeclFile.js @@ -0,0 +1,239 @@ +//// [tests/cases/compiler/privacyClassImplementsClauseDeclFile.ts] //// + +//// [privacyClassImplementsClauseDeclFile_externalModule.ts] + +export module publicModule { + export interface publicInterfaceInPublicModule { + } + + interface privateInterfaceInPublicModule { + } + + class privateClassImplementingPublicInterfaceInModule implements publicInterfaceInPublicModule { + } + class privateClassImplementingPrivateInterfaceInModule implements privateInterfaceInPublicModule { + } + export class publicClassImplementingPublicInterfaceInModule implements publicInterfaceInPublicModule { + } + export class publicClassImplementingPrivateInterfaceInModule implements privateInterfaceInPublicModule { // Should error + } + + class privateClassImplementingFromPrivateModuleInterface implements privateModule.publicInterfaceInPrivateModule { + } + export class publicClassImplementingFromPrivateModuleInterface implements privateModule.publicInterfaceInPrivateModule { // Should error + } + + export class publicClassImplementingPrivateAndPublicInterface implements privateInterfaceInPublicModule, publicInterfaceInPublicModule { // Should error + } +} + +module privateModule { + export interface publicInterfaceInPrivateModule { + + } + + interface privateInterfaceInPrivateModule { + } + + class privateClassImplementingPublicInterfaceInModule implements publicInterfaceInPrivateModule { + } + class privateClassImplementingPrivateInterfaceInModule implements privateInterfaceInPrivateModule { + } + export class publicClassImplementingPublicInterfaceInModule implements publicInterfaceInPrivateModule { + } + export class publicClassImplementingPrivateInterfaceInModule implements privateInterfaceInPrivateModule { + } + + class privateClassImplementingFromPrivateModuleInterface implements privateModule.publicInterfaceInPrivateModule { + } + export class publicClassImplementingFromPrivateModuleInterface implements privateModule.publicInterfaceInPrivateModule { + } +} + +export interface publicInterface { + +} + +interface privateInterface { +} + +class privateClassImplementingPublicInterface implements publicInterface { +} +class privateClassImplementingPrivateInterfaceInModule implements privateInterface { +} +export class publicClassImplementingPublicInterface implements publicInterface { +} +export class publicClassImplementingPrivateInterface implements privateInterface { // Should error +} + +class privateClassImplementingFromPrivateModuleInterface implements privateModule.publicInterfaceInPrivateModule { +} +export class publicClassImplementingFromPrivateModuleInterface implements privateModule.publicInterfaceInPrivateModule { // Should error +} + +//// [privacyClassImplementsClauseDeclFile_GlobalFile.ts] +module publicModuleInGlobal { + export interface publicInterfaceInPublicModule { + } + + interface privateInterfaceInPublicModule { + } + + class privateClassImplementingPublicInterfaceInModule implements publicInterfaceInPublicModule { + } + class privateClassImplementingPrivateInterfaceInModule implements privateInterfaceInPublicModule { + } + export class publicClassImplementingPublicInterfaceInModule implements publicInterfaceInPublicModule { + } + export class publicClassImplementingPrivateInterfaceInModule implements privateInterfaceInPublicModule { // Should error + } +} +interface publicInterfaceInGlobal { +} +class publicClassImplementingPublicInterfaceInGlobal implements publicInterfaceInGlobal { +} + + +//// [privacyClassImplementsClauseDeclFile_externalModule.js] +(function (publicModule) { + var privateClassImplementingPublicInterfaceInModule = (function () { + function privateClassImplementingPublicInterfaceInModule() { + } + return privateClassImplementingPublicInterfaceInModule; + })(); + var privateClassImplementingPrivateInterfaceInModule = (function () { + function privateClassImplementingPrivateInterfaceInModule() { + } + return privateClassImplementingPrivateInterfaceInModule; + })(); + var publicClassImplementingPublicInterfaceInModule = (function () { + function publicClassImplementingPublicInterfaceInModule() { + } + return publicClassImplementingPublicInterfaceInModule; + })(); + publicModule.publicClassImplementingPublicInterfaceInModule = publicClassImplementingPublicInterfaceInModule; + var publicClassImplementingPrivateInterfaceInModule = (function () { + function publicClassImplementingPrivateInterfaceInModule() { + } + return publicClassImplementingPrivateInterfaceInModule; + })(); + publicModule.publicClassImplementingPrivateInterfaceInModule = publicClassImplementingPrivateInterfaceInModule; + var privateClassImplementingFromPrivateModuleInterface = (function () { + function privateClassImplementingFromPrivateModuleInterface() { + } + return privateClassImplementingFromPrivateModuleInterface; + })(); + var publicClassImplementingFromPrivateModuleInterface = (function () { + function publicClassImplementingFromPrivateModuleInterface() { + } + return publicClassImplementingFromPrivateModuleInterface; + })(); + publicModule.publicClassImplementingFromPrivateModuleInterface = publicClassImplementingFromPrivateModuleInterface; + var publicClassImplementingPrivateAndPublicInterface = (function () { + function publicClassImplementingPrivateAndPublicInterface() { + } + return publicClassImplementingPrivateAndPublicInterface; + })(); + publicModule.publicClassImplementingPrivateAndPublicInterface = publicClassImplementingPrivateAndPublicInterface; +})(exports.publicModule || (exports.publicModule = {})); +var publicModule = exports.publicModule; +var privateModule; +(function (privateModule) { + var privateClassImplementingPublicInterfaceInModule = (function () { + function privateClassImplementingPublicInterfaceInModule() { + } + return privateClassImplementingPublicInterfaceInModule; + })(); + var privateClassImplementingPrivateInterfaceInModule = (function () { + function privateClassImplementingPrivateInterfaceInModule() { + } + return privateClassImplementingPrivateInterfaceInModule; + })(); + var publicClassImplementingPublicInterfaceInModule = (function () { + function publicClassImplementingPublicInterfaceInModule() { + } + return publicClassImplementingPublicInterfaceInModule; + })(); + privateModule.publicClassImplementingPublicInterfaceInModule = publicClassImplementingPublicInterfaceInModule; + var publicClassImplementingPrivateInterfaceInModule = (function () { + function publicClassImplementingPrivateInterfaceInModule() { + } + return publicClassImplementingPrivateInterfaceInModule; + })(); + privateModule.publicClassImplementingPrivateInterfaceInModule = publicClassImplementingPrivateInterfaceInModule; + var privateClassImplementingFromPrivateModuleInterface = (function () { + function privateClassImplementingFromPrivateModuleInterface() { + } + return privateClassImplementingFromPrivateModuleInterface; + })(); + var publicClassImplementingFromPrivateModuleInterface = (function () { + function publicClassImplementingFromPrivateModuleInterface() { + } + return publicClassImplementingFromPrivateModuleInterface; + })(); + privateModule.publicClassImplementingFromPrivateModuleInterface = publicClassImplementingFromPrivateModuleInterface; +})(privateModule || (privateModule = {})); +var privateClassImplementingPublicInterface = (function () { + function privateClassImplementingPublicInterface() { + } + return privateClassImplementingPublicInterface; +})(); +var privateClassImplementingPrivateInterfaceInModule = (function () { + function privateClassImplementingPrivateInterfaceInModule() { + } + return privateClassImplementingPrivateInterfaceInModule; +})(); +var publicClassImplementingPublicInterface = (function () { + function publicClassImplementingPublicInterface() { + } + return publicClassImplementingPublicInterface; +})(); +exports.publicClassImplementingPublicInterface = publicClassImplementingPublicInterface; +var publicClassImplementingPrivateInterface = (function () { + function publicClassImplementingPrivateInterface() { + } + return publicClassImplementingPrivateInterface; +})(); +exports.publicClassImplementingPrivateInterface = publicClassImplementingPrivateInterface; +var privateClassImplementingFromPrivateModuleInterface = (function () { + function privateClassImplementingFromPrivateModuleInterface() { + } + return privateClassImplementingFromPrivateModuleInterface; +})(); +var publicClassImplementingFromPrivateModuleInterface = (function () { + function publicClassImplementingFromPrivateModuleInterface() { + } + return publicClassImplementingFromPrivateModuleInterface; +})(); +exports.publicClassImplementingFromPrivateModuleInterface = publicClassImplementingFromPrivateModuleInterface; +//// [privacyClassImplementsClauseDeclFile_GlobalFile.js] +var publicModuleInGlobal; +(function (publicModuleInGlobal) { + var privateClassImplementingPublicInterfaceInModule = (function () { + function privateClassImplementingPublicInterfaceInModule() { + } + return privateClassImplementingPublicInterfaceInModule; + })(); + var privateClassImplementingPrivateInterfaceInModule = (function () { + function privateClassImplementingPrivateInterfaceInModule() { + } + return privateClassImplementingPrivateInterfaceInModule; + })(); + var publicClassImplementingPublicInterfaceInModule = (function () { + function publicClassImplementingPublicInterfaceInModule() { + } + return publicClassImplementingPublicInterfaceInModule; + })(); + publicModuleInGlobal.publicClassImplementingPublicInterfaceInModule = publicClassImplementingPublicInterfaceInModule; + var publicClassImplementingPrivateInterfaceInModule = (function () { + function publicClassImplementingPrivateInterfaceInModule() { + } + return publicClassImplementingPrivateInterfaceInModule; + })(); + publicModuleInGlobal.publicClassImplementingPrivateInterfaceInModule = publicClassImplementingPrivateInterfaceInModule; +})(publicModuleInGlobal || (publicModuleInGlobal = {})); +var publicClassImplementingPublicInterfaceInGlobal = (function () { + function publicClassImplementingPublicInterfaceInGlobal() { + } + return publicClassImplementingPublicInterfaceInGlobal; +})(); diff --git a/tests/baselines/reference/privacyInterfaceExtendsClauseDeclFile.errors.txt b/tests/baselines/reference/privacyInterfaceExtendsClauseDeclFile.errors.txt new file mode 100644 index 00000000000..24fccd203bc --- /dev/null +++ b/tests/baselines/reference/privacyInterfaceExtendsClauseDeclFile.errors.txt @@ -0,0 +1,105 @@ +==== tests/cases/compiler/privacyInterfaceExtendsClauseDeclFile_externalModule.ts (5 errors) ==== + + export module publicModule { + export interface publicInterfaceInPublicModule { + } + + interface privateInterfaceInPublicModule { + } + + interface privateInterfaceImplementingPublicInterfaceInModule extends publicInterfaceInPublicModule { + } + interface privateInterfaceImplementingPrivateInterfaceInModule extends privateInterfaceInPublicModule { + } + export interface publicInterfaceImplementingPublicInterfaceInModule extends publicInterfaceInPublicModule { + } + export interface publicInterfaceImplementingPrivateInterfaceInModule extends privateInterfaceInPublicModule { // Should error + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! Extends clause of exported interface 'publicInterfaceImplementingPrivateInterfaceInModule' has or is using private name 'privateInterfaceInPublicModule'. + } + + interface privateInterfaceImplementingFromPrivateModuleInterface extends privateModule.publicInterfaceInPrivateModule { + } + export interface publicInterfaceImplementingFromPrivateModuleInterface extends privateModule.publicInterfaceInPrivateModule { // Should error + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! Extends clause of exported interface 'publicInterfaceImplementingFromPrivateModuleInterface' has or is using name 'privateModule.publicInterfaceInPrivateModule' from private module 'privateModule'. + } + + export interface publicInterfaceImplementingPrivateAndPublicInterface extends privateInterfaceInPublicModule, publicInterfaceInPublicModule { // Should error + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! Extends clause of exported interface 'publicInterfaceImplementingPrivateAndPublicInterface' has or is using private name 'privateInterfaceInPublicModule'. + } + } + + module privateModule { + export interface publicInterfaceInPrivateModule { + + } + + interface privateInterfaceInPrivateModule { + } + + interface privateInterfaceImplementingPublicInterfaceInModule extends publicInterfaceInPrivateModule { + } + interface privateInterfaceImplementingPrivateInterfaceInModule extends privateInterfaceInPrivateModule { + } + export interface publicInterfaceImplementingPublicInterfaceInModule extends publicInterfaceInPrivateModule { + } + export interface publicInterfaceImplementingPrivateInterfaceInModule extends privateInterfaceInPrivateModule { + } + + interface privateInterfaceImplementingFromPrivateModuleInterface extends privateModule.publicInterfaceInPrivateModule { + } + export interface publicInterfaceImplementingFromPrivateModuleInterface extends privateModule.publicInterfaceInPrivateModule { + } + } + + export interface publicInterface { + + } + + interface privateInterface { + } + + interface privateInterfaceImplementingPublicInterface extends publicInterface { + } + interface privateInterfaceImplementingPrivateInterfaceInModule extends privateInterface { + } + export interface publicInterfaceImplementingPublicInterface extends publicInterface { + } + export interface publicInterfaceImplementingPrivateInterface extends privateInterface { // Should error + ~~~~~~~~~~~~~~~~ +!!! Extends clause of exported interface 'publicInterfaceImplementingPrivateInterface' has or is using private name 'privateInterface'. + } + + interface privateInterfaceImplementingFromPrivateModuleInterface extends privateModule.publicInterfaceInPrivateModule { + } + export interface publicInterfaceImplementingFromPrivateModuleInterface extends privateModule.publicInterfaceInPrivateModule { // Should error + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! Extends clause of exported interface 'publicInterfaceImplementingFromPrivateModuleInterface' has or is using name 'privateModule.publicInterfaceInPrivateModule' from private module 'privateModule'. + } + +==== tests/cases/compiler/privacyInterfaceExtendsClauseDeclFile_GlobalFile.ts (1 errors) ==== + module publicModuleInGlobal { + export interface publicInterfaceInPublicModule { + } + + interface privateInterfaceInPublicModule { + } + + interface privateInterfaceImplementingPublicInterfaceInModule extends publicInterfaceInPublicModule { + } + interface privateInterfaceImplementingPrivateInterfaceInModule extends privateInterfaceInPublicModule { + } + export interface publicInterfaceImplementingPublicInterfaceInModule extends publicInterfaceInPublicModule { + } + export interface publicInterfaceImplementingPrivateInterfaceInModule extends privateInterfaceInPublicModule { // Should error + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! Extends clause of exported interface 'publicInterfaceImplementingPrivateInterfaceInModule' has or is using private name 'privateInterfaceInPublicModule'. + } + } + interface publicInterfaceInGlobal { + } + interface publicInterfaceImplementingPublicInterfaceInGlobal extends publicInterfaceInGlobal { + } + \ No newline at end of file diff --git a/tests/baselines/reference/privacyInterfaceExtendsClauseDeclFile.js b/tests/baselines/reference/privacyInterfaceExtendsClauseDeclFile.js new file mode 100644 index 00000000000..65f0a2af420 --- /dev/null +++ b/tests/baselines/reference/privacyInterfaceExtendsClauseDeclFile.js @@ -0,0 +1,98 @@ +//// [tests/cases/compiler/privacyInterfaceExtendsClauseDeclFile.ts] //// + +//// [privacyInterfaceExtendsClauseDeclFile_externalModule.ts] + +export module publicModule { + export interface publicInterfaceInPublicModule { + } + + interface privateInterfaceInPublicModule { + } + + interface privateInterfaceImplementingPublicInterfaceInModule extends publicInterfaceInPublicModule { + } + interface privateInterfaceImplementingPrivateInterfaceInModule extends privateInterfaceInPublicModule { + } + export interface publicInterfaceImplementingPublicInterfaceInModule extends publicInterfaceInPublicModule { + } + export interface publicInterfaceImplementingPrivateInterfaceInModule extends privateInterfaceInPublicModule { // Should error + } + + interface privateInterfaceImplementingFromPrivateModuleInterface extends privateModule.publicInterfaceInPrivateModule { + } + export interface publicInterfaceImplementingFromPrivateModuleInterface extends privateModule.publicInterfaceInPrivateModule { // Should error + } + + export interface publicInterfaceImplementingPrivateAndPublicInterface extends privateInterfaceInPublicModule, publicInterfaceInPublicModule { // Should error + } +} + +module privateModule { + export interface publicInterfaceInPrivateModule { + + } + + interface privateInterfaceInPrivateModule { + } + + interface privateInterfaceImplementingPublicInterfaceInModule extends publicInterfaceInPrivateModule { + } + interface privateInterfaceImplementingPrivateInterfaceInModule extends privateInterfaceInPrivateModule { + } + export interface publicInterfaceImplementingPublicInterfaceInModule extends publicInterfaceInPrivateModule { + } + export interface publicInterfaceImplementingPrivateInterfaceInModule extends privateInterfaceInPrivateModule { + } + + interface privateInterfaceImplementingFromPrivateModuleInterface extends privateModule.publicInterfaceInPrivateModule { + } + export interface publicInterfaceImplementingFromPrivateModuleInterface extends privateModule.publicInterfaceInPrivateModule { + } +} + +export interface publicInterface { + +} + +interface privateInterface { +} + +interface privateInterfaceImplementingPublicInterface extends publicInterface { +} +interface privateInterfaceImplementingPrivateInterfaceInModule extends privateInterface { +} +export interface publicInterfaceImplementingPublicInterface extends publicInterface { +} +export interface publicInterfaceImplementingPrivateInterface extends privateInterface { // Should error +} + +interface privateInterfaceImplementingFromPrivateModuleInterface extends privateModule.publicInterfaceInPrivateModule { +} +export interface publicInterfaceImplementingFromPrivateModuleInterface extends privateModule.publicInterfaceInPrivateModule { // Should error +} + +//// [privacyInterfaceExtendsClauseDeclFile_GlobalFile.ts] +module publicModuleInGlobal { + export interface publicInterfaceInPublicModule { + } + + interface privateInterfaceInPublicModule { + } + + interface privateInterfaceImplementingPublicInterfaceInModule extends publicInterfaceInPublicModule { + } + interface privateInterfaceImplementingPrivateInterfaceInModule extends privateInterfaceInPublicModule { + } + export interface publicInterfaceImplementingPublicInterfaceInModule extends publicInterfaceInPublicModule { + } + export interface publicInterfaceImplementingPrivateInterfaceInModule extends privateInterfaceInPublicModule { // Should error + } +} +interface publicInterfaceInGlobal { +} +interface publicInterfaceImplementingPublicInterfaceInGlobal extends publicInterfaceInGlobal { +} + + +//// [privacyInterfaceExtendsClauseDeclFile_externalModule.js] +//// [privacyInterfaceExtendsClauseDeclFile_GlobalFile.js] diff --git a/tests/cases/compiler/privacyClassExtendsClauseDeclFile.ts b/tests/cases/compiler/privacyClassExtendsClauseDeclFile.ts new file mode 100644 index 00000000000..4feb4a691b7 --- /dev/null +++ b/tests/cases/compiler/privacyClassExtendsClauseDeclFile.ts @@ -0,0 +1,97 @@ +// @module: commonjs +// @declaration: true + +// @Filename: privacyClassExtendsClauseDeclFile_externalModule.ts +export module publicModule { + export class publicClassInPublicModule { + private f1() { + } + } + + class privateClassInPublicModule { + } + + class privateClassExtendingPublicClassInModule extends publicClassInPublicModule { + } + class privateClassExtendingPrivateClassInModule extends privateClassInPublicModule { + } + export class publicClassExtendingPublicClassInModule extends publicClassInPublicModule { + } + export class publicClassExtendingPrivateClassInModule extends privateClassInPublicModule { // Should error + } + + class privateClassExtendingFromPrivateModuleClass extends privateModule.publicClassInPrivateModule { + } + export class publicClassExtendingFromPrivateModuleClass extends privateModule.publicClassInPrivateModule { // Should error + } +} + +module privateModule { + export class publicClassInPrivateModule { + private f1() { + } + } + + class privateClassInPrivateModule { + } + + class privateClassExtendingPublicClassInModule extends publicClassInPrivateModule { + } + class privateClassExtendingPrivateClassInModule extends privateClassInPrivateModule { + } + export class publicClassExtendingPublicClassInModule extends publicClassInPrivateModule { + } + export class publicClassExtendingPrivateClassInModule extends privateClassInPrivateModule { + } + + class privateClassExtendingFromPrivateModuleClass extends privateModule.publicClassInPrivateModule { + } + export class publicClassExtendingFromPrivateModuleClass extends privateModule.publicClassInPrivateModule { + } +} + +export class publicClass { + private f1() { + } +} + +class privateClass { +} + +class privateClassExtendingPublicClass extends publicClass { +} +class privateClassExtendingPrivateClassInModule extends privateClass { +} +export class publicClassExtendingPublicClass extends publicClass { +} +export class publicClassExtendingPrivateClass extends privateClass { // Should error +} + +class privateClassExtendingFromPrivateModuleClass extends privateModule.publicClassInPrivateModule { +} +export class publicClassExtendingFromPrivateModuleClass extends privateModule.publicClassInPrivateModule { // Should error +} + +// @Filename: privacyClassExtendsClauseDeclFile_GlobalFile.ts +module publicModuleInGlobal { + export class publicClassInPublicModule { + private f1() { + } + } + + class privateClassInPublicModule { + } + + class privateClassExtendingPublicClassInModule extends publicClassInPublicModule { + } + class privateClassExtendingPrivateClassInModule extends privateClassInPublicModule { + } + export class publicClassExtendingPublicClassInModule extends publicClassInPublicModule { + } + export class publicClassExtendingPrivateClassInModule extends privateClassInPublicModule { // Should error + } +} +class publicClassInGlobal { +} +class publicClassExtendingPublicClassInGlobal extends publicClassInGlobal { +} diff --git a/tests/cases/compiler/privacyClassImplementsClauseDeclFile.ts b/tests/cases/compiler/privacyClassImplementsClauseDeclFile.ts new file mode 100644 index 00000000000..17791e49f86 --- /dev/null +++ b/tests/cases/compiler/privacyClassImplementsClauseDeclFile.ts @@ -0,0 +1,94 @@ +// @module: commonjs +// @declaration: true + +// @Filename: privacyClassImplementsClauseDeclFile_externalModule.ts +export module publicModule { + export interface publicInterfaceInPublicModule { + } + + interface privateInterfaceInPublicModule { + } + + class privateClassImplementingPublicInterfaceInModule implements publicInterfaceInPublicModule { + } + class privateClassImplementingPrivateInterfaceInModule implements privateInterfaceInPublicModule { + } + export class publicClassImplementingPublicInterfaceInModule implements publicInterfaceInPublicModule { + } + export class publicClassImplementingPrivateInterfaceInModule implements privateInterfaceInPublicModule { // Should error + } + + class privateClassImplementingFromPrivateModuleInterface implements privateModule.publicInterfaceInPrivateModule { + } + export class publicClassImplementingFromPrivateModuleInterface implements privateModule.publicInterfaceInPrivateModule { // Should error + } + + export class publicClassImplementingPrivateAndPublicInterface implements privateInterfaceInPublicModule, publicInterfaceInPublicModule { // Should error + } +} + +module privateModule { + export interface publicInterfaceInPrivateModule { + + } + + interface privateInterfaceInPrivateModule { + } + + class privateClassImplementingPublicInterfaceInModule implements publicInterfaceInPrivateModule { + } + class privateClassImplementingPrivateInterfaceInModule implements privateInterfaceInPrivateModule { + } + export class publicClassImplementingPublicInterfaceInModule implements publicInterfaceInPrivateModule { + } + export class publicClassImplementingPrivateInterfaceInModule implements privateInterfaceInPrivateModule { + } + + class privateClassImplementingFromPrivateModuleInterface implements privateModule.publicInterfaceInPrivateModule { + } + export class publicClassImplementingFromPrivateModuleInterface implements privateModule.publicInterfaceInPrivateModule { + } +} + +export interface publicInterface { + +} + +interface privateInterface { +} + +class privateClassImplementingPublicInterface implements publicInterface { +} +class privateClassImplementingPrivateInterfaceInModule implements privateInterface { +} +export class publicClassImplementingPublicInterface implements publicInterface { +} +export class publicClassImplementingPrivateInterface implements privateInterface { // Should error +} + +class privateClassImplementingFromPrivateModuleInterface implements privateModule.publicInterfaceInPrivateModule { +} +export class publicClassImplementingFromPrivateModuleInterface implements privateModule.publicInterfaceInPrivateModule { // Should error +} + +// @Filename: privacyClassImplementsClauseDeclFile_GlobalFile.ts +module publicModuleInGlobal { + export interface publicInterfaceInPublicModule { + } + + interface privateInterfaceInPublicModule { + } + + class privateClassImplementingPublicInterfaceInModule implements publicInterfaceInPublicModule { + } + class privateClassImplementingPrivateInterfaceInModule implements privateInterfaceInPublicModule { + } + export class publicClassImplementingPublicInterfaceInModule implements publicInterfaceInPublicModule { + } + export class publicClassImplementingPrivateInterfaceInModule implements privateInterfaceInPublicModule { // Should error + } +} +interface publicInterfaceInGlobal { +} +class publicClassImplementingPublicInterfaceInGlobal implements publicInterfaceInGlobal { +} diff --git a/tests/cases/compiler/privacyInterfaceExtendsClauseDeclFile.ts b/tests/cases/compiler/privacyInterfaceExtendsClauseDeclFile.ts new file mode 100644 index 00000000000..d1c73724bb9 --- /dev/null +++ b/tests/cases/compiler/privacyInterfaceExtendsClauseDeclFile.ts @@ -0,0 +1,94 @@ +// @module: commonjs +// @declaration: true + +// @Filename: privacyInterfaceExtendsClauseDeclFile_externalModule.ts +export module publicModule { + export interface publicInterfaceInPublicModule { + } + + interface privateInterfaceInPublicModule { + } + + interface privateInterfaceImplementingPublicInterfaceInModule extends publicInterfaceInPublicModule { + } + interface privateInterfaceImplementingPrivateInterfaceInModule extends privateInterfaceInPublicModule { + } + export interface publicInterfaceImplementingPublicInterfaceInModule extends publicInterfaceInPublicModule { + } + export interface publicInterfaceImplementingPrivateInterfaceInModule extends privateInterfaceInPublicModule { // Should error + } + + interface privateInterfaceImplementingFromPrivateModuleInterface extends privateModule.publicInterfaceInPrivateModule { + } + export interface publicInterfaceImplementingFromPrivateModuleInterface extends privateModule.publicInterfaceInPrivateModule { // Should error + } + + export interface publicInterfaceImplementingPrivateAndPublicInterface extends privateInterfaceInPublicModule, publicInterfaceInPublicModule { // Should error + } +} + +module privateModule { + export interface publicInterfaceInPrivateModule { + + } + + interface privateInterfaceInPrivateModule { + } + + interface privateInterfaceImplementingPublicInterfaceInModule extends publicInterfaceInPrivateModule { + } + interface privateInterfaceImplementingPrivateInterfaceInModule extends privateInterfaceInPrivateModule { + } + export interface publicInterfaceImplementingPublicInterfaceInModule extends publicInterfaceInPrivateModule { + } + export interface publicInterfaceImplementingPrivateInterfaceInModule extends privateInterfaceInPrivateModule { + } + + interface privateInterfaceImplementingFromPrivateModuleInterface extends privateModule.publicInterfaceInPrivateModule { + } + export interface publicInterfaceImplementingFromPrivateModuleInterface extends privateModule.publicInterfaceInPrivateModule { + } +} + +export interface publicInterface { + +} + +interface privateInterface { +} + +interface privateInterfaceImplementingPublicInterface extends publicInterface { +} +interface privateInterfaceImplementingPrivateInterfaceInModule extends privateInterface { +} +export interface publicInterfaceImplementingPublicInterface extends publicInterface { +} +export interface publicInterfaceImplementingPrivateInterface extends privateInterface { // Should error +} + +interface privateInterfaceImplementingFromPrivateModuleInterface extends privateModule.publicInterfaceInPrivateModule { +} +export interface publicInterfaceImplementingFromPrivateModuleInterface extends privateModule.publicInterfaceInPrivateModule { // Should error +} + +// @Filename: privacyInterfaceExtendsClauseDeclFile_GlobalFile.ts +module publicModuleInGlobal { + export interface publicInterfaceInPublicModule { + } + + interface privateInterfaceInPublicModule { + } + + interface privateInterfaceImplementingPublicInterfaceInModule extends publicInterfaceInPublicModule { + } + interface privateInterfaceImplementingPrivateInterfaceInModule extends privateInterfaceInPublicModule { + } + export interface publicInterfaceImplementingPublicInterfaceInModule extends publicInterfaceInPublicModule { + } + export interface publicInterfaceImplementingPrivateInterfaceInModule extends privateInterfaceInPublicModule { // Should error + } +} +interface publicInterfaceInGlobal { +} +interface publicInterfaceImplementingPublicInterfaceInGlobal extends publicInterfaceInGlobal { +} From 9fd95fcb95fa13265ad27090a8b1be74ac1e8a3e Mon Sep 17 00:00:00 2001 From: Sheetal Nandi Date: Fri, 18 Jul 2014 18:11:04 -0700 Subject: [PATCH 04/15] Report errors if the type parameter uses constraint that is using private type/module Fixes #86 --- .../diagnosticInformationMap.generated.ts | 16 + src/compiler/diagnosticMessages.json | 64 ++ src/compiler/emitter.ts | 68 ++ .../privacyTypeParameterOfFunction.errors.txt | 136 --- ...TypeParameterOfFunctionDeclFile.errors.txt | 495 +++++++++++ .../privacyTypeParameterOfFunctionDeclFile.js | 816 ++++++++++++++++++ .../privacyTypeParametersOfClass.errors.txt | 47 - ...cyTypeParametersOfClassDeclFile.errors.txt | 163 ++++ .../privacyTypeParametersOfClassDeclFile.js | 383 ++++++++ ...rivacyTypeParametersOfInterface.errors.txt | 62 -- ...peParametersOfInterfaceDeclFile.errors.txt | 199 +++++ ...rivacyTypeParametersOfInterfaceDeclFile.js | 265 ++++++ .../privacyTypeParameterOfFunction.ts | 1 + .../privacyTypeParameterOfFunctionDeclFile.ts | 440 ++++++++++ .../compiler/privacyTypeParametersOfClass.ts | 1 + .../privacyTypeParametersOfClassDeclFile.ts | 155 ++++ .../privacyTypeParametersOfInterface.ts | 1 + ...rivacyTypeParametersOfInterfaceDeclFile.ts | 192 +++++ 18 files changed, 3259 insertions(+), 245 deletions(-) delete mode 100644 tests/baselines/reference/privacyTypeParameterOfFunction.errors.txt create mode 100644 tests/baselines/reference/privacyTypeParameterOfFunctionDeclFile.errors.txt create mode 100644 tests/baselines/reference/privacyTypeParameterOfFunctionDeclFile.js delete mode 100644 tests/baselines/reference/privacyTypeParametersOfClass.errors.txt create mode 100644 tests/baselines/reference/privacyTypeParametersOfClassDeclFile.errors.txt create mode 100644 tests/baselines/reference/privacyTypeParametersOfClassDeclFile.js delete mode 100644 tests/baselines/reference/privacyTypeParametersOfInterface.errors.txt create mode 100644 tests/baselines/reference/privacyTypeParametersOfInterfaceDeclFile.errors.txt create mode 100644 tests/baselines/reference/privacyTypeParametersOfInterfaceDeclFile.js create mode 100644 tests/cases/compiler/privacyTypeParameterOfFunctionDeclFile.ts create mode 100644 tests/cases/compiler/privacyTypeParametersOfClassDeclFile.ts create mode 100644 tests/cases/compiler/privacyTypeParametersOfInterfaceDeclFile.ts diff --git a/src/compiler/diagnosticInformationMap.generated.ts b/src/compiler/diagnosticInformationMap.generated.ts index 80bf686c8ae..2f5daae7ed4 100644 --- a/src/compiler/diagnosticInformationMap.generated.ts +++ b/src/compiler/diagnosticInformationMap.generated.ts @@ -105,6 +105,22 @@ module ts { Extends_clause_of_exported_class_0_has_or_is_using_name_1_from_private_module_2: { code: 2021, category: DiagnosticCategory.Error, key: "Extends clause of exported class '{0}' has or is using name '{1}' from private module '{2}'." }, Implements_clause_of_exported_class_0_has_or_is_using_name_1_from_private_module_2: { code: 2022, category: DiagnosticCategory.Error, key: "Implements clause of exported class '{0}' has or is using name '{1}' from private module '{2}'." }, Extends_clause_of_exported_interface_0_has_or_is_using_name_1_from_private_module_2: { code: 2023, category: DiagnosticCategory.Error, key: "Extends clause of exported interface '{0}' has or is using name '{1}' from private module '{2}'." }, + TypeParameter_0_of_constructor_signature_from_exported_interface_has_or_is_using_private_name_1: { code: 2208, category: DiagnosticCategory.Error, key: "TypeParameter '{0}' of constructor signature from exported interface has or is using private name '{1}'." }, + TypeParameter_0_of_call_signature_from_exported_interface_has_or_is_using_private_name_1: { code: 2209, category: DiagnosticCategory.Error, key: "TypeParameter '{0}' of call signature from exported interface has or is using private name '{1}'." }, + TypeParameter_0_of_public_static_method_from_exported_class_has_or_is_using_private_name_1: { code: 2210, category: DiagnosticCategory.Error, key: "TypeParameter '{0}' of public static method from exported class has or is using private name '{1}'." }, + TypeParameter_0_of_public_method_from_exported_class_has_or_is_using_private_name_1: { code: 2211, category: DiagnosticCategory.Error, key: "TypeParameter '{0}' of public method from exported class has or is using private name '{1}'." }, + TypeParameter_0_of_method_from_exported_interface_has_or_is_using_private_name_1: { code: 2212, category: DiagnosticCategory.Error, key: "TypeParameter '{0}' of method from exported interface has or is using private name '{1}'." }, + TypeParameter_0_of_exported_function_has_or_is_using_private_name_1: { code: 2213, category: DiagnosticCategory.Error, key: "TypeParameter '{0}' of exported function has or is using private name '{1}'." }, + TypeParameter_0_of_constructor_signature_from_exported_interface_has_or_is_using_name_1_from_private_module_2: { code: 2214, category: DiagnosticCategory.Error, key: "TypeParameter '{0}' of constructor signature from exported interface has or is using name '{1}' from private module '{2}'." }, + TypeParameter_0_of_call_signature_from_exported_interface_has_or_is_using_name_1_from_private_module_2: { code: 2215, category: DiagnosticCategory.Error, key: "TypeParameter '{0}' of call signature from exported interface has or is using name '{1}' from private module '{2}'." }, + TypeParameter_0_of_public_static_method_from_exported_class_has_or_is_using_name_1_from_private_module_2: { code: 2216, category: DiagnosticCategory.Error, key: "TypeParameter '{0}' of public static method from exported class has or is using name '{1}' from private module '{2}'." }, + TypeParameter_0_of_public_method_from_exported_class_has_or_is_using_name_1_from_private_module_2: { code: 2217, category: DiagnosticCategory.Error, key: "TypeParameter '{0}' of public method from exported class has or is using name '{1}' from private module '{2}'." }, + TypeParameter_0_of_method_from_exported_interface_has_or_is_using_name_1_from_private_module_2: { code: 2218, category: DiagnosticCategory.Error, key: "TypeParameter '{0}' of method from exported interface has or is using name '{1}' from private module '{2}'." }, + TypeParameter_0_of_exported_function_has_or_is_using_name_1_from_private_module_2: { code: 2219, category: DiagnosticCategory.Error, key: "TypeParameter '{0}' of exported function has or is using name '{1}' from private module '{2}'." }, + TypeParameter_0_of_exported_class_has_or_is_using_private_name_1: { code: 2220, category: DiagnosticCategory.Error, key: "TypeParameter '{0}' of exported class has or is using private name '{1}'." }, + TypeParameter_0_of_exported_interface_has_or_is_using_private_name_1: { code: 2221, category: DiagnosticCategory.Error, key: "TypeParameter '{0}' of exported interface has or is using private name '{1}'." }, + TypeParameter_0_of_exported_class_has_or_is_using_name_1_from_private_module_2: { code: 2222, category: DiagnosticCategory.Error, key: "TypeParameter '{0}' of exported class has or is using name '{1}' from private module '{2}'." }, + TypeParameter_0_of_exported_interface_has_or_is_using_name_1_from_private_module_2: { code: 2223, category: DiagnosticCategory.Error, key: "TypeParameter '{0}' of exported interface has or is using name '{1}' from private module '{2}'." }, new_T_cannot_be_used_to_create_an_array_Use_new_Array_T_instead: { code: 2068, category: DiagnosticCategory.Error, key: "'new T[]' cannot be used to create an array. Use 'new Array()' instead." }, Multiple_constructor_implementations_are_not_allowed: { code: 2070, category: DiagnosticCategory.Error, key: "Multiple constructor implementations are not allowed." }, A_class_may_only_implement_another_class_or_interface: { code: 2074, category: DiagnosticCategory.Error, key: "A class may only implement another class or interface." }, diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index 362f4cd6129..1b1ccff36fd 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -414,6 +414,70 @@ "category": "Error", "code": 2023 }, + "TypeParameter '{0}' of constructor signature from exported interface has or is using private name '{1}'.": { + "category": "Error", + "code": 2208 + }, + "TypeParameter '{0}' of call signature from exported interface has or is using private name '{1}'.": { + "category": "Error", + "code": 2209 + }, + "TypeParameter '{0}' of public static method from exported class has or is using private name '{1}'.": { + "category": "Error", + "code": 2210 + }, + "TypeParameter '{0}' of public method from exported class has or is using private name '{1}'.": { + "category": "Error", + "code": 2211 + }, + "TypeParameter '{0}' of method from exported interface has or is using private name '{1}'.": { + "category": "Error", + "code": 2212 + }, + "TypeParameter '{0}' of exported function has or is using private name '{1}'.": { + "category": "Error", + "code": 2213 + }, + "TypeParameter '{0}' of constructor signature from exported interface has or is using name '{1}' from private module '{2}'.": { + "category": "Error", + "code": 2214 + }, + "TypeParameter '{0}' of call signature from exported interface has or is using name '{1}' from private module '{2}'.": { + "category": "Error", + "code": 2215 + }, + "TypeParameter '{0}' of public static method from exported class has or is using name '{1}' from private module '{2}'.": { + "category": "Error", + "code": 2216 + }, + "TypeParameter '{0}' of public method from exported class has or is using name '{1}' from private module '{2}'.": { + "category": "Error", + "code": 2217 + }, + "TypeParameter '{0}' of method from exported interface has or is using name '{1}' from private module '{2}'.": { + "category": "Error", + "code": 2218 + }, + "TypeParameter '{0}' of exported function has or is using name '{1}' from private module '{2}'.": { + "category": "Error", + "code": 2219 + }, + "TypeParameter '{0}' of exported class has or is using private name '{1}'.": { + "category": "Error", + "code": 2220 + }, + "TypeParameter '{0}' of exported interface has or is using private name '{1}'.": { + "category": "Error", + "code": 2221 + }, + "TypeParameter '{0}' of exported class has or is using name '{1}' from private module '{2}'.": { + "category": "Error", + "code": 2222 + }, + "TypeParameter '{0}' of exported interface has or is using name '{1}' from private module '{2}'.": { + "category": "Error", + "code": 2223 + }, "'new T[]' cannot be used to create an array. Use 'new Array()' instead.": { "category": "Error", "code": 2068 diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index 5de70cbc318..4169d48e0b1 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -2011,10 +2011,76 @@ module ts { function emitTypeParameters(typeParameters: TypeParameterDeclaration[]) { function emitTypeParameter(node: TypeParameterDeclaration) { + function getTypeParameterConstraintVisibilityError(symbolAccesibilityResult: SymbolAccessiblityResult) { + // TODO(shkamat) Cannot access name errors + var diagnosticMessage: DiagnosticMessage; + switch (node.parent.kind) { + case SyntaxKind.ClassDeclaration: + diagnosticMessage = symbolAccesibilityResult.errorModuleName ? + Diagnostics.TypeParameter_0_of_exported_class_has_or_is_using_name_1_from_private_module_2 : + Diagnostics.TypeParameter_0_of_exported_class_has_or_is_using_private_name_1; + break; + + case SyntaxKind.InterfaceDeclaration: + diagnosticMessage = symbolAccesibilityResult.errorModuleName ? + Diagnostics.TypeParameter_0_of_exported_interface_has_or_is_using_name_1_from_private_module_2 : + Diagnostics.TypeParameter_0_of_exported_interface_has_or_is_using_private_name_1; + break; + + case SyntaxKind.ConstructSignature: + diagnosticMessage = symbolAccesibilityResult.errorModuleName ? + Diagnostics.TypeParameter_0_of_constructor_signature_from_exported_interface_has_or_is_using_name_1_from_private_module_2 : + Diagnostics.TypeParameter_0_of_constructor_signature_from_exported_interface_has_or_is_using_private_name_1; + break; + + case SyntaxKind.CallSignature: + diagnosticMessage = symbolAccesibilityResult.errorModuleName ? + Diagnostics.TypeParameter_0_of_call_signature_from_exported_interface_has_or_is_using_name_1_from_private_module_2 : + Diagnostics.TypeParameter_0_of_call_signature_from_exported_interface_has_or_is_using_private_name_1; + break; + + case SyntaxKind.Method: + if (node.parent.flags & NodeFlags.Static) { + diagnosticMessage = symbolAccesibilityResult.errorModuleName ? + Diagnostics.TypeParameter_0_of_public_static_method_from_exported_class_has_or_is_using_name_1_from_private_module_2 : + Diagnostics.TypeParameter_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 ? + Diagnostics.TypeParameter_0_of_public_method_from_exported_class_has_or_is_using_name_1_from_private_module_2 : + Diagnostics.TypeParameter_0_of_public_method_from_exported_class_has_or_is_using_private_name_1; + } + else { + diagnosticMessage = symbolAccesibilityResult.errorModuleName ? + Diagnostics.TypeParameter_0_of_method_from_exported_interface_has_or_is_using_name_1_from_private_module_2 : + Diagnostics.TypeParameter_0_of_method_from_exported_interface_has_or_is_using_private_name_1; + } + break; + + case SyntaxKind.FunctionDeclaration: + diagnosticMessage = symbolAccesibilityResult.errorModuleName ? + Diagnostics.TypeParameter_0_of_exported_function_has_or_is_using_name_1_from_private_module_2 : + Diagnostics.TypeParameter_0_of_exported_function_has_or_is_using_private_name_1; + break; + + default: + Debug.fail("This is unknown parent for type parameter: " + SyntaxKind[node.parent.kind]); + } + + return { + diagnosticMessage: diagnosticMessage, + errorNode: node, + typeName: node.name + } + } + emitSourceTextOfNode(node.name); if (node.constraint) { write(" extends "); + getSymbolVisibilityDiagnosticMessage = getTypeParameterConstraintVisibilityError; resolver.writeTypeAtLocation(node.constraint, enclosingDeclaration, TypeFormatFlags.None, writer); + // TODO(shkamat) This is just till we get rest of the error reporting up + getSymbolVisibilityDiagnosticMessage = undefined; } } @@ -2076,6 +2142,8 @@ module ts { } getSymbolVisibilityDiagnosticMessage = getHeritageClauseVisibilityError; resolver.writeTypeAtLocation(node, enclosingDeclaration, TypeFormatFlags.WriteArrayAsGenericType, writer); + // TODO(shkamat) This is just till we get rest of the error reporting up + getSymbolVisibilityDiagnosticMessage = undefined; } if (typeReferences) { diff --git a/tests/baselines/reference/privacyTypeParameterOfFunction.errors.txt b/tests/baselines/reference/privacyTypeParameterOfFunction.errors.txt deleted file mode 100644 index a48f291d507..00000000000 --- a/tests/baselines/reference/privacyTypeParameterOfFunction.errors.txt +++ /dev/null @@ -1,136 +0,0 @@ -==== tests/cases/compiler/privacyTypeParameterOfFunction.ts (1 errors) ==== - class privateClass { - } - - export class publicClass { - ~~~~~~~~~~~~~~~~~~~~~~~~~~ - } - ~ -!!! Cannot compile external modules unless the '--module' flag is provided. - - export interface publicInterfaceWithPrivateTypeParameters { - // TypeParameter_0_of_constructor_signature_from_exported_interface_has_or_is_using_private_type_1 - new (): privateClass; - - // TypeParameter_0_of_constructor_signature_from_exported_interface_has_or_is_using_private_type_1 - (): privateClass; - - // TypeParameter_0_of_method_from_exported_interface_has_or_is_using_private_type_1 - myMethod(): privateClass; - } - - export interface publicInterfaceWithPublicTypeParameters { - new (): publicClass; - (): publicClass; - myMethod(): publicClass; - } - - interface privateInterfaceWithPrivateTypeParameters { - new (): privateClass; - (): privateClass; - myMethod(): privateClass; - } - - interface privateInterfaceWithPublicTypeParameters { - new (): publicClass; - (): publicClass; - myMethod(): publicClass; - } - - export class publicClassWithWithPrivateTypeParameters { - // TypeParameter_0_of_public_static_method_from_exported_class_has_or_is_using_private_type_1 - static myPublicStaticMethod() { - } - private static myPrivateStaticMethod() { // No error - } - // TypeParameter_0_of_public_method_from_exported_class_has_or_is_using_private_type_1 - myPublicMethod() { - } - private myPrivateMethod() { // No error - } - } - - export class publicClassWithWithPublicTypeParameters { - static myPublicStaticMethod() { - } - private static myPrivateStaticMethod() { - } - myPublicMethod() { - } - private myPrivateMethod() { - } - } - - class privateClassWithWithPrivateTypeParameters { - static myPublicStaticMethod() { - } - private static myPrivateStaticMethod() { // No error - } - myPublicMethod() { - } - private myPrivateMethod() { // No error - } - } - - class privateClassWithWithPublicTypeParameters { - static myPublicStaticMethod() { - } - private static myPrivateStaticMethod() { - } - myPublicMethod() { - } - private myPrivateMethod() { - } - } - - // TypeParameter_0_of_exported_function_has_or_is_using_private_type_1 - export function publicFunctionWithPrivateTypeParameters() { - } - - export function publicFunctionWithPublicTypeParameters() { - } - - function privateFunctionWithPrivateTypeParameters() { - } - - function privateFunctionWithPublicTypeParameters() { - } - - export interface publicInterfaceWithPublicTypeParametersWithoutExtends { - new (): publicClass; - (): publicClass; - myMethod(): publicClass; - } - - interface privateInterfaceWithPublicTypeParametersWithoutExtends { - new (): publicClass; - (): publicClass; - myMethod(): publicClass; - } - - export class publicClassWithWithPublicTypeParametersWithoutExtends { - static myPublicStaticMethod() { - } - private static myPrivateStaticMethod() { - } - myPublicMethod() { - } - private myPrivateMethod() { - } - } - class privateClassWithWithPublicTypeParametersWithoutExtends { - static myPublicStaticMethod() { - } - private static myPrivateStaticMethod() { - } - myPublicMethod() { - } - private myPrivateMethod() { - } - } - - export function publicFunctionWithPublicTypeParametersWithoutExtends() { - } - - function privateFunctionWithPublicTypeParametersWithoutExtends() { - } \ No newline at end of file diff --git a/tests/baselines/reference/privacyTypeParameterOfFunctionDeclFile.errors.txt b/tests/baselines/reference/privacyTypeParameterOfFunctionDeclFile.errors.txt new file mode 100644 index 00000000000..ccb7be1e181 --- /dev/null +++ b/tests/baselines/reference/privacyTypeParameterOfFunctionDeclFile.errors.txt @@ -0,0 +1,495 @@ +==== tests/cases/compiler/privacyTypeParameterOfFunctionDeclFile.ts (28 errors) ==== + class privateClass { + } + + export class publicClass { + } + + export interface publicInterfaceWithPrivateTypeParameters { + new (): privateClass; // Error + ~~~~~~~~~~~~~~~~~~~~~~ +!!! TypeParameter 'T' of constructor signature from exported interface has or is using private name 'privateClass'. + (): privateClass; // Error + ~~~~~~~~~~~~~~~~~~~~~~ +!!! TypeParameter 'T' of call signature from exported interface has or is using private name 'privateClass'. + myMethod(): privateClass; // Error + ~~~~~~~~~~~~~~~~~~~~~~ +!!! TypeParameter 'T' of method from exported interface has or is using private name 'privateClass'. + } + + export interface publicInterfaceWithPublicTypeParameters { + new (): publicClass; + (): publicClass; + myMethod(): publicClass; + } + + interface privateInterfaceWithPrivateTypeParameters { + new (): privateClass; + (): privateClass; + myMethod(): privateClass; + } + + interface privateInterfaceWithPublicTypeParameters { + new (): publicClass; + (): publicClass; + myMethod(): publicClass; + } + + export class publicClassWithWithPrivateTypeParameters { + static myPublicStaticMethod() { // Error + ~~~~~~~~~~~~~~~~~~~~~~ +!!! TypeParameter 'T' of public static method from exported class has or is using private name 'privateClass'. + } + private static myPrivateStaticMethod() { + ~~~~~~~~~~~~~~~~~~~~~~ +!!! TypeParameter 'T' of public static method from exported class has or is using private name 'privateClass'. + } + myPublicMethod() { // Error + ~~~~~~~~~~~~~~~~~~~~~~ +!!! TypeParameter 'T' of public method from exported class has or is using private name 'privateClass'. + } + private myPrivateMethod() { + ~~~~~~~~~~~~~~~~~~~~~~ +!!! TypeParameter 'T' of public method from exported class has or is using private name 'privateClass'. + } + } + + export class publicClassWithWithPublicTypeParameters { + static myPublicStaticMethod() { + } + private static myPrivateStaticMethod() { + } + myPublicMethod() { + } + private myPrivateMethod() { + } + } + + class privateClassWithWithPrivateTypeParameters { + static myPublicStaticMethod() { + } + private static myPrivateStaticMethod() { + } + myPublicMethod() { + } + private myPrivateMethod() { + } + } + + class privateClassWithWithPublicTypeParameters { + static myPublicStaticMethod() { + } + private static myPrivateStaticMethod() { + } + myPublicMethod() { + } + private myPrivateMethod() { + } + } + + export function publicFunctionWithPrivateTypeParameters() { // Error + ~~~~~~~~~~~~~~~~~~~~~~ +!!! TypeParameter 'T' of exported function has or is using private name 'privateClass'. + } + + export function publicFunctionWithPublicTypeParameters() { + } + + function privateFunctionWithPrivateTypeParameters() { + } + + function privateFunctionWithPublicTypeParameters() { + } + + export interface publicInterfaceWithPublicTypeParametersWithoutExtends { + new (): publicClass; + (): publicClass; + myMethod(): publicClass; + } + + interface privateInterfaceWithPublicTypeParametersWithoutExtends { + new (): publicClass; + (): publicClass; + myMethod(): publicClass; + } + + export class publicClassWithWithPublicTypeParametersWithoutExtends { + static myPublicStaticMethod() { + } + private static myPrivateStaticMethod() { + } + myPublicMethod() { + } + private myPrivateMethod() { + } + } + class privateClassWithWithPublicTypeParametersWithoutExtends { + static myPublicStaticMethod() { + } + private static myPrivateStaticMethod() { + } + myPublicMethod() { + } + private myPrivateMethod() { + } + } + + export function publicFunctionWithPublicTypeParametersWithoutExtends() { + } + + function privateFunctionWithPublicTypeParametersWithoutExtends() { + } + + export interface publicInterfaceWithPrivatModuleTypeParameters { + new (): privateModule.publicClass; // Error + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! TypeParameter 'T' of constructor signature from exported interface has or is using name 'privateModule.publicClass' from private module 'privateModule'. + (): privateModule.publicClass; // Error + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! TypeParameter 'T' of call signature from exported interface has or is using name 'privateModule.publicClass' from private module 'privateModule'. + myMethod(): privateModule.publicClass; // Error + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! TypeParameter 'T' of method from exported interface has or is using name 'privateModule.publicClass' from private module 'privateModule'. + } + export class publicClassWithWithPrivateModuleTypeParameters { + static myPublicStaticMethod() { // Error + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! TypeParameter 'T' of public static method from exported class has or is using name 'privateModule.publicClass' from private module 'privateModule'. + } + myPublicMethod() { // Error + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! TypeParameter 'T' of public method from exported class has or is using name 'privateModule.publicClass' from private module 'privateModule'. + } + } + export function publicFunctionWithPrivateMopduleTypeParameters() { // Error + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! TypeParameter 'T' of exported function has or is using name 'privateModule.publicClass' from private module 'privateModule'. + } + + + interface privateInterfaceWithPrivatModuleTypeParameters { + new (): privateModule.publicClass; + (): privateModule.publicClass; + myMethod(): privateModule.publicClass; + } + class privateClassWithWithPrivateModuleTypeParameters { + static myPublicStaticMethod() { + } + myPublicMethod() { + } + } + function privateFunctionWithPrivateMopduleTypeParameters() { + } + + + export module publicModule { + class privateClass { + } + + export class publicClass { + } + + export interface publicInterfaceWithPrivateTypeParameters { + new (): privateClass; // Error + ~~~~~~~~~~~~~~~~~~~~~~ +!!! TypeParameter 'T' of constructor signature from exported interface has or is using private name 'privateClass'. + (): privateClass; // Error + ~~~~~~~~~~~~~~~~~~~~~~ +!!! TypeParameter 'T' of call signature from exported interface has or is using private name 'privateClass'. + myMethod(): privateClass; // Error + ~~~~~~~~~~~~~~~~~~~~~~ +!!! TypeParameter 'T' of method from exported interface has or is using private name 'privateClass'. + } + + export interface publicInterfaceWithPublicTypeParameters { + new (): publicClass; + (): publicClass; + myMethod(): publicClass; + } + + interface privateInterfaceWithPrivateTypeParameters { + new (): privateClass; + (): privateClass; + myMethod(): privateClass; + } + + interface privateInterfaceWithPublicTypeParameters { + new (): publicClass; + (): publicClass; + myMethod(): publicClass; + } + + export class publicClassWithWithPrivateTypeParameters { + static myPublicStaticMethod() { // Error + ~~~~~~~~~~~~~~~~~~~~~~ +!!! TypeParameter 'T' of public static method from exported class has or is using private name 'privateClass'. + } + private static myPrivateStaticMethod() { + ~~~~~~~~~~~~~~~~~~~~~~ +!!! TypeParameter 'T' of public static method from exported class has or is using private name 'privateClass'. + } + myPublicMethod() { // Error + ~~~~~~~~~~~~~~~~~~~~~~ +!!! TypeParameter 'T' of public method from exported class has or is using private name 'privateClass'. + } + private myPrivateMethod() { + ~~~~~~~~~~~~~~~~~~~~~~ +!!! TypeParameter 'T' of public method from exported class has or is using private name 'privateClass'. + } + } + + export class publicClassWithWithPublicTypeParameters { + static myPublicStaticMethod() { + } + private static myPrivateStaticMethod() { + } + myPublicMethod() { + } + private myPrivateMethod() { + } + } + + class privateClassWithWithPrivateTypeParameters { + static myPublicStaticMethod() { + } + private static myPrivateStaticMethod() { + } + myPublicMethod() { + } + private myPrivateMethod() { + } + } + + class privateClassWithWithPublicTypeParameters { + static myPublicStaticMethod() { + } + private static myPrivateStaticMethod() { + } + myPublicMethod() { + } + private myPrivateMethod() { + } + } + + export function publicFunctionWithPrivateTypeParameters() { // Error + ~~~~~~~~~~~~~~~~~~~~~~ +!!! TypeParameter 'T' of exported function has or is using private name 'privateClass'. + } + + export function publicFunctionWithPublicTypeParameters() { + } + + function privateFunctionWithPrivateTypeParameters() { + } + + function privateFunctionWithPublicTypeParameters() { + } + + export interface publicInterfaceWithPublicTypeParametersWithoutExtends { + new (): publicClass; + (): publicClass; + myMethod(): publicClass; + } + + interface privateInterfaceWithPublicTypeParametersWithoutExtends { + new (): publicClass; + (): publicClass; + myMethod(): publicClass; + } + + export class publicClassWithWithPublicTypeParametersWithoutExtends { + static myPublicStaticMethod() { + } + private static myPrivateStaticMethod() { + } + myPublicMethod() { + } + private myPrivateMethod() { + } + } + class privateClassWithWithPublicTypeParametersWithoutExtends { + static myPublicStaticMethod() { + } + private static myPrivateStaticMethod() { + } + myPublicMethod() { + } + private myPrivateMethod() { + } + } + + export function publicFunctionWithPublicTypeParametersWithoutExtends() { + } + + function privateFunctionWithPublicTypeParametersWithoutExtends() { + } + + export interface publicInterfaceWithPrivatModuleTypeParameters { + new (): privateModule.publicClass; // Error + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! TypeParameter 'T' of constructor signature from exported interface has or is using name 'privateModule.publicClass' from private module 'privateModule'. + (): privateModule.publicClass; // Error + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! TypeParameter 'T' of call signature from exported interface has or is using name 'privateModule.publicClass' from private module 'privateModule'. + myMethod(): privateModule.publicClass; // Error + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! TypeParameter 'T' of method from exported interface has or is using name 'privateModule.publicClass' from private module 'privateModule'. + } + export class publicClassWithWithPrivateModuleTypeParameters { + static myPublicStaticMethod() { // Error + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! TypeParameter 'T' of public static method from exported class has or is using name 'privateModule.publicClass' from private module 'privateModule'. + } + myPublicMethod() { // Error + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! TypeParameter 'T' of public method from exported class has or is using name 'privateModule.publicClass' from private module 'privateModule'. + } + } + export function publicFunctionWithPrivateMopduleTypeParameters() { // Error + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! TypeParameter 'T' of exported function has or is using name 'privateModule.publicClass' from private module 'privateModule'. + } + + + interface privateInterfaceWithPrivatModuleTypeParameters { + new (): privateModule.publicClass; + (): privateModule.publicClass; + myMethod(): privateModule.publicClass; + } + class privateClassWithWithPrivateModuleTypeParameters { + static myPublicStaticMethod() { + } + myPublicMethod() { + } + } + function privateFunctionWithPrivateMopduleTypeParameters() { + } + + } + + module privateModule { + class privateClass { + } + + export class publicClass { + } + + export interface publicInterfaceWithPrivateTypeParameters { + new (): privateClass; + (): privateClass; + myMethod(): privateClass; + } + + export interface publicInterfaceWithPublicTypeParameters { + new (): publicClass; + (): publicClass; + myMethod(): publicClass; + } + + interface privateInterfaceWithPrivateTypeParameters { + new (): privateClass; + (): privateClass; + myMethod(): privateClass; + } + + interface privateInterfaceWithPublicTypeParameters { + new (): publicClass; + (): publicClass; + myMethod(): publicClass; + } + + export class publicClassWithWithPrivateTypeParameters { + static myPublicStaticMethod() { + } + private static myPrivateStaticMethod() { + } + myPublicMethod() { + } + private myPrivateMethod() { + } + } + + export class publicClassWithWithPublicTypeParameters { + static myPublicStaticMethod() { + } + private static myPrivateStaticMethod() { + } + myPublicMethod() { + } + private myPrivateMethod() { + } + } + + class privateClassWithWithPrivateTypeParameters { + static myPublicStaticMethod() { + } + private static myPrivateStaticMethod() { + } + myPublicMethod() { + } + private myPrivateMethod() { + } + } + + class privateClassWithWithPublicTypeParameters { + static myPublicStaticMethod() { + } + private static myPrivateStaticMethod() { + } + myPublicMethod() { + } + private myPrivateMethod() { + } + } + + export function publicFunctionWithPrivateTypeParameters() { + } + + export function publicFunctionWithPublicTypeParameters() { + } + + function privateFunctionWithPrivateTypeParameters() { + } + + function privateFunctionWithPublicTypeParameters() { + } + + export interface publicInterfaceWithPublicTypeParametersWithoutExtends { + new (): publicClass; + (): publicClass; + myMethod(): publicClass; + } + + interface privateInterfaceWithPublicTypeParametersWithoutExtends { + new (): publicClass; + (): publicClass; + myMethod(): publicClass; + } + + export class publicClassWithWithPublicTypeParametersWithoutExtends { + static myPublicStaticMethod() { + } + private static myPrivateStaticMethod() { + } + myPublicMethod() { + } + private myPrivateMethod() { + } + } + class privateClassWithWithPublicTypeParametersWithoutExtends { + static myPublicStaticMethod() { + } + private static myPrivateStaticMethod() { + } + myPublicMethod() { + } + private myPrivateMethod() { + } + } + + export function publicFunctionWithPublicTypeParametersWithoutExtends() { + } + + function privateFunctionWithPublicTypeParametersWithoutExtends() { + } + } \ No newline at end of file diff --git a/tests/baselines/reference/privacyTypeParameterOfFunctionDeclFile.js b/tests/baselines/reference/privacyTypeParameterOfFunctionDeclFile.js new file mode 100644 index 00000000000..173b48b8049 --- /dev/null +++ b/tests/baselines/reference/privacyTypeParameterOfFunctionDeclFile.js @@ -0,0 +1,816 @@ +//// [privacyTypeParameterOfFunctionDeclFile.ts] +class privateClass { +} + +export class publicClass { +} + +export interface publicInterfaceWithPrivateTypeParameters { + new (): privateClass; // Error + (): privateClass; // Error + myMethod(): privateClass; // Error +} + +export interface publicInterfaceWithPublicTypeParameters { + new (): publicClass; + (): publicClass; + myMethod(): publicClass; +} + +interface privateInterfaceWithPrivateTypeParameters { + new (): privateClass; + (): privateClass; + myMethod(): privateClass; +} + +interface privateInterfaceWithPublicTypeParameters { + new (): publicClass; + (): publicClass; + myMethod(): publicClass; +} + +export class publicClassWithWithPrivateTypeParameters { + static myPublicStaticMethod() { // Error + } + private static myPrivateStaticMethod() { + } + myPublicMethod() { // Error + } + private myPrivateMethod() { + } +} + +export class publicClassWithWithPublicTypeParameters { + static myPublicStaticMethod() { + } + private static myPrivateStaticMethod() { + } + myPublicMethod() { + } + private myPrivateMethod() { + } +} + +class privateClassWithWithPrivateTypeParameters { + static myPublicStaticMethod() { + } + private static myPrivateStaticMethod() { + } + myPublicMethod() { + } + private myPrivateMethod() { + } +} + +class privateClassWithWithPublicTypeParameters { + static myPublicStaticMethod() { + } + private static myPrivateStaticMethod() { + } + myPublicMethod() { + } + private myPrivateMethod() { + } +} + +export function publicFunctionWithPrivateTypeParameters() { // Error +} + +export function publicFunctionWithPublicTypeParameters() { +} + +function privateFunctionWithPrivateTypeParameters() { +} + +function privateFunctionWithPublicTypeParameters() { +} + +export interface publicInterfaceWithPublicTypeParametersWithoutExtends { + new (): publicClass; + (): publicClass; + myMethod(): publicClass; +} + +interface privateInterfaceWithPublicTypeParametersWithoutExtends { + new (): publicClass; + (): publicClass; + myMethod(): publicClass; +} + +export class publicClassWithWithPublicTypeParametersWithoutExtends { + static myPublicStaticMethod() { + } + private static myPrivateStaticMethod() { + } + myPublicMethod() { + } + private myPrivateMethod() { + } +} +class privateClassWithWithPublicTypeParametersWithoutExtends { + static myPublicStaticMethod() { + } + private static myPrivateStaticMethod() { + } + myPublicMethod() { + } + private myPrivateMethod() { + } +} + +export function publicFunctionWithPublicTypeParametersWithoutExtends() { +} + +function privateFunctionWithPublicTypeParametersWithoutExtends() { +} + +export interface publicInterfaceWithPrivatModuleTypeParameters { + new (): privateModule.publicClass; // Error + (): privateModule.publicClass; // Error + myMethod(): privateModule.publicClass; // Error +} +export class publicClassWithWithPrivateModuleTypeParameters { + static myPublicStaticMethod() { // Error + } + myPublicMethod() { // Error + } +} +export function publicFunctionWithPrivateMopduleTypeParameters() { // Error +} + + +interface privateInterfaceWithPrivatModuleTypeParameters { + new (): privateModule.publicClass; + (): privateModule.publicClass; + myMethod(): privateModule.publicClass; +} +class privateClassWithWithPrivateModuleTypeParameters { + static myPublicStaticMethod() { + } + myPublicMethod() { + } +} +function privateFunctionWithPrivateMopduleTypeParameters() { +} + + +export module publicModule { + class privateClass { + } + + export class publicClass { + } + + export interface publicInterfaceWithPrivateTypeParameters { + new (): privateClass; // Error + (): privateClass; // Error + myMethod(): privateClass; // Error + } + + export interface publicInterfaceWithPublicTypeParameters { + new (): publicClass; + (): publicClass; + myMethod(): publicClass; + } + + interface privateInterfaceWithPrivateTypeParameters { + new (): privateClass; + (): privateClass; + myMethod(): privateClass; + } + + interface privateInterfaceWithPublicTypeParameters { + new (): publicClass; + (): publicClass; + myMethod(): publicClass; + } + + export class publicClassWithWithPrivateTypeParameters { + static myPublicStaticMethod() { // Error + } + private static myPrivateStaticMethod() { + } + myPublicMethod() { // Error + } + private myPrivateMethod() { + } + } + + export class publicClassWithWithPublicTypeParameters { + static myPublicStaticMethod() { + } + private static myPrivateStaticMethod() { + } + myPublicMethod() { + } + private myPrivateMethod() { + } + } + + class privateClassWithWithPrivateTypeParameters { + static myPublicStaticMethod() { + } + private static myPrivateStaticMethod() { + } + myPublicMethod() { + } + private myPrivateMethod() { + } + } + + class privateClassWithWithPublicTypeParameters { + static myPublicStaticMethod() { + } + private static myPrivateStaticMethod() { + } + myPublicMethod() { + } + private myPrivateMethod() { + } + } + + export function publicFunctionWithPrivateTypeParameters() { // Error + } + + export function publicFunctionWithPublicTypeParameters() { + } + + function privateFunctionWithPrivateTypeParameters() { + } + + function privateFunctionWithPublicTypeParameters() { + } + + export interface publicInterfaceWithPublicTypeParametersWithoutExtends { + new (): publicClass; + (): publicClass; + myMethod(): publicClass; + } + + interface privateInterfaceWithPublicTypeParametersWithoutExtends { + new (): publicClass; + (): publicClass; + myMethod(): publicClass; + } + + export class publicClassWithWithPublicTypeParametersWithoutExtends { + static myPublicStaticMethod() { + } + private static myPrivateStaticMethod() { + } + myPublicMethod() { + } + private myPrivateMethod() { + } + } + class privateClassWithWithPublicTypeParametersWithoutExtends { + static myPublicStaticMethod() { + } + private static myPrivateStaticMethod() { + } + myPublicMethod() { + } + private myPrivateMethod() { + } + } + + export function publicFunctionWithPublicTypeParametersWithoutExtends() { + } + + function privateFunctionWithPublicTypeParametersWithoutExtends() { + } + + export interface publicInterfaceWithPrivatModuleTypeParameters { + new (): privateModule.publicClass; // Error + (): privateModule.publicClass; // Error + myMethod(): privateModule.publicClass; // Error + } + export class publicClassWithWithPrivateModuleTypeParameters { + static myPublicStaticMethod() { // Error + } + myPublicMethod() { // Error + } + } + export function publicFunctionWithPrivateMopduleTypeParameters() { // Error + } + + + interface privateInterfaceWithPrivatModuleTypeParameters { + new (): privateModule.publicClass; + (): privateModule.publicClass; + myMethod(): privateModule.publicClass; + } + class privateClassWithWithPrivateModuleTypeParameters { + static myPublicStaticMethod() { + } + myPublicMethod() { + } + } + function privateFunctionWithPrivateMopduleTypeParameters() { + } + +} + +module privateModule { + class privateClass { + } + + export class publicClass { + } + + export interface publicInterfaceWithPrivateTypeParameters { + new (): privateClass; + (): privateClass; + myMethod(): privateClass; + } + + export interface publicInterfaceWithPublicTypeParameters { + new (): publicClass; + (): publicClass; + myMethod(): publicClass; + } + + interface privateInterfaceWithPrivateTypeParameters { + new (): privateClass; + (): privateClass; + myMethod(): privateClass; + } + + interface privateInterfaceWithPublicTypeParameters { + new (): publicClass; + (): publicClass; + myMethod(): publicClass; + } + + export class publicClassWithWithPrivateTypeParameters { + static myPublicStaticMethod() { + } + private static myPrivateStaticMethod() { + } + myPublicMethod() { + } + private myPrivateMethod() { + } + } + + export class publicClassWithWithPublicTypeParameters { + static myPublicStaticMethod() { + } + private static myPrivateStaticMethod() { + } + myPublicMethod() { + } + private myPrivateMethod() { + } + } + + class privateClassWithWithPrivateTypeParameters { + static myPublicStaticMethod() { + } + private static myPrivateStaticMethod() { + } + myPublicMethod() { + } + private myPrivateMethod() { + } + } + + class privateClassWithWithPublicTypeParameters { + static myPublicStaticMethod() { + } + private static myPrivateStaticMethod() { + } + myPublicMethod() { + } + private myPrivateMethod() { + } + } + + export function publicFunctionWithPrivateTypeParameters() { + } + + export function publicFunctionWithPublicTypeParameters() { + } + + function privateFunctionWithPrivateTypeParameters() { + } + + function privateFunctionWithPublicTypeParameters() { + } + + export interface publicInterfaceWithPublicTypeParametersWithoutExtends { + new (): publicClass; + (): publicClass; + myMethod(): publicClass; + } + + interface privateInterfaceWithPublicTypeParametersWithoutExtends { + new (): publicClass; + (): publicClass; + myMethod(): publicClass; + } + + export class publicClassWithWithPublicTypeParametersWithoutExtends { + static myPublicStaticMethod() { + } + private static myPrivateStaticMethod() { + } + myPublicMethod() { + } + private myPrivateMethod() { + } + } + class privateClassWithWithPublicTypeParametersWithoutExtends { + static myPublicStaticMethod() { + } + private static myPrivateStaticMethod() { + } + myPublicMethod() { + } + private myPrivateMethod() { + } + } + + export function publicFunctionWithPublicTypeParametersWithoutExtends() { + } + + function privateFunctionWithPublicTypeParametersWithoutExtends() { + } +} + +//// [privacyTypeParameterOfFunctionDeclFile.js] +var privateClass = (function () { + function privateClass() { + } + return privateClass; +})(); +var publicClass = (function () { + function publicClass() { + } + return publicClass; +})(); +exports.publicClass = publicClass; +var publicClassWithWithPrivateTypeParameters = (function () { + function publicClassWithWithPrivateTypeParameters() { + } + publicClassWithWithPrivateTypeParameters.myPublicStaticMethod = function () { + }; + publicClassWithWithPrivateTypeParameters.myPrivateStaticMethod = function () { + }; + publicClassWithWithPrivateTypeParameters.prototype.myPublicMethod = function () { + }; + publicClassWithWithPrivateTypeParameters.prototype.myPrivateMethod = function () { + }; + return publicClassWithWithPrivateTypeParameters; +})(); +exports.publicClassWithWithPrivateTypeParameters = publicClassWithWithPrivateTypeParameters; +var publicClassWithWithPublicTypeParameters = (function () { + function publicClassWithWithPublicTypeParameters() { + } + publicClassWithWithPublicTypeParameters.myPublicStaticMethod = function () { + }; + publicClassWithWithPublicTypeParameters.myPrivateStaticMethod = function () { + }; + publicClassWithWithPublicTypeParameters.prototype.myPublicMethod = function () { + }; + publicClassWithWithPublicTypeParameters.prototype.myPrivateMethod = function () { + }; + return publicClassWithWithPublicTypeParameters; +})(); +exports.publicClassWithWithPublicTypeParameters = publicClassWithWithPublicTypeParameters; +var privateClassWithWithPrivateTypeParameters = (function () { + function privateClassWithWithPrivateTypeParameters() { + } + privateClassWithWithPrivateTypeParameters.myPublicStaticMethod = function () { + }; + privateClassWithWithPrivateTypeParameters.myPrivateStaticMethod = function () { + }; + privateClassWithWithPrivateTypeParameters.prototype.myPublicMethod = function () { + }; + privateClassWithWithPrivateTypeParameters.prototype.myPrivateMethod = function () { + }; + return privateClassWithWithPrivateTypeParameters; +})(); +var privateClassWithWithPublicTypeParameters = (function () { + function privateClassWithWithPublicTypeParameters() { + } + privateClassWithWithPublicTypeParameters.myPublicStaticMethod = function () { + }; + privateClassWithWithPublicTypeParameters.myPrivateStaticMethod = function () { + }; + privateClassWithWithPublicTypeParameters.prototype.myPublicMethod = function () { + }; + privateClassWithWithPublicTypeParameters.prototype.myPrivateMethod = function () { + }; + return privateClassWithWithPublicTypeParameters; +})(); +function publicFunctionWithPrivateTypeParameters() { +} +exports.publicFunctionWithPrivateTypeParameters = publicFunctionWithPrivateTypeParameters; +function publicFunctionWithPublicTypeParameters() { +} +exports.publicFunctionWithPublicTypeParameters = publicFunctionWithPublicTypeParameters; +function privateFunctionWithPrivateTypeParameters() { +} +function privateFunctionWithPublicTypeParameters() { +} +var publicClassWithWithPublicTypeParametersWithoutExtends = (function () { + function publicClassWithWithPublicTypeParametersWithoutExtends() { + } + publicClassWithWithPublicTypeParametersWithoutExtends.myPublicStaticMethod = function () { + }; + publicClassWithWithPublicTypeParametersWithoutExtends.myPrivateStaticMethod = function () { + }; + publicClassWithWithPublicTypeParametersWithoutExtends.prototype.myPublicMethod = function () { + }; + publicClassWithWithPublicTypeParametersWithoutExtends.prototype.myPrivateMethod = function () { + }; + return publicClassWithWithPublicTypeParametersWithoutExtends; +})(); +exports.publicClassWithWithPublicTypeParametersWithoutExtends = publicClassWithWithPublicTypeParametersWithoutExtends; +var privateClassWithWithPublicTypeParametersWithoutExtends = (function () { + function privateClassWithWithPublicTypeParametersWithoutExtends() { + } + privateClassWithWithPublicTypeParametersWithoutExtends.myPublicStaticMethod = function () { + }; + privateClassWithWithPublicTypeParametersWithoutExtends.myPrivateStaticMethod = function () { + }; + privateClassWithWithPublicTypeParametersWithoutExtends.prototype.myPublicMethod = function () { + }; + privateClassWithWithPublicTypeParametersWithoutExtends.prototype.myPrivateMethod = function () { + }; + return privateClassWithWithPublicTypeParametersWithoutExtends; +})(); +function publicFunctionWithPublicTypeParametersWithoutExtends() { +} +exports.publicFunctionWithPublicTypeParametersWithoutExtends = publicFunctionWithPublicTypeParametersWithoutExtends; +function privateFunctionWithPublicTypeParametersWithoutExtends() { +} +var publicClassWithWithPrivateModuleTypeParameters = (function () { + function publicClassWithWithPrivateModuleTypeParameters() { + } + publicClassWithWithPrivateModuleTypeParameters.myPublicStaticMethod = function () { + }; + publicClassWithWithPrivateModuleTypeParameters.prototype.myPublicMethod = function () { + }; + return publicClassWithWithPrivateModuleTypeParameters; +})(); +exports.publicClassWithWithPrivateModuleTypeParameters = publicClassWithWithPrivateModuleTypeParameters; +function publicFunctionWithPrivateMopduleTypeParameters() { +} +exports.publicFunctionWithPrivateMopduleTypeParameters = publicFunctionWithPrivateMopduleTypeParameters; +var privateClassWithWithPrivateModuleTypeParameters = (function () { + function privateClassWithWithPrivateModuleTypeParameters() { + } + privateClassWithWithPrivateModuleTypeParameters.myPublicStaticMethod = function () { + }; + privateClassWithWithPrivateModuleTypeParameters.prototype.myPublicMethod = function () { + }; + return privateClassWithWithPrivateModuleTypeParameters; +})(); +function privateFunctionWithPrivateMopduleTypeParameters() { +} +(function (publicModule) { + var privateClass = (function () { + function privateClass() { + } + return privateClass; + })(); + var publicClass = (function () { + function publicClass() { + } + return publicClass; + })(); + publicModule.publicClass = publicClass; + var publicClassWithWithPrivateTypeParameters = (function () { + function publicClassWithWithPrivateTypeParameters() { + } + publicClassWithWithPrivateTypeParameters.myPublicStaticMethod = function () { + }; + publicClassWithWithPrivateTypeParameters.myPrivateStaticMethod = function () { + }; + publicClassWithWithPrivateTypeParameters.prototype.myPublicMethod = function () { + }; + publicClassWithWithPrivateTypeParameters.prototype.myPrivateMethod = function () { + }; + return publicClassWithWithPrivateTypeParameters; + })(); + publicModule.publicClassWithWithPrivateTypeParameters = publicClassWithWithPrivateTypeParameters; + var publicClassWithWithPublicTypeParameters = (function () { + function publicClassWithWithPublicTypeParameters() { + } + publicClassWithWithPublicTypeParameters.myPublicStaticMethod = function () { + }; + publicClassWithWithPublicTypeParameters.myPrivateStaticMethod = function () { + }; + publicClassWithWithPublicTypeParameters.prototype.myPublicMethod = function () { + }; + publicClassWithWithPublicTypeParameters.prototype.myPrivateMethod = function () { + }; + return publicClassWithWithPublicTypeParameters; + })(); + publicModule.publicClassWithWithPublicTypeParameters = publicClassWithWithPublicTypeParameters; + var privateClassWithWithPrivateTypeParameters = (function () { + function privateClassWithWithPrivateTypeParameters() { + } + privateClassWithWithPrivateTypeParameters.myPublicStaticMethod = function () { + }; + privateClassWithWithPrivateTypeParameters.myPrivateStaticMethod = function () { + }; + privateClassWithWithPrivateTypeParameters.prototype.myPublicMethod = function () { + }; + privateClassWithWithPrivateTypeParameters.prototype.myPrivateMethod = function () { + }; + return privateClassWithWithPrivateTypeParameters; + })(); + var privateClassWithWithPublicTypeParameters = (function () { + function privateClassWithWithPublicTypeParameters() { + } + privateClassWithWithPublicTypeParameters.myPublicStaticMethod = function () { + }; + privateClassWithWithPublicTypeParameters.myPrivateStaticMethod = function () { + }; + privateClassWithWithPublicTypeParameters.prototype.myPublicMethod = function () { + }; + privateClassWithWithPublicTypeParameters.prototype.myPrivateMethod = function () { + }; + return privateClassWithWithPublicTypeParameters; + })(); + function publicFunctionWithPrivateTypeParameters() { + } + publicModule.publicFunctionWithPrivateTypeParameters = publicFunctionWithPrivateTypeParameters; + function publicFunctionWithPublicTypeParameters() { + } + publicModule.publicFunctionWithPublicTypeParameters = publicFunctionWithPublicTypeParameters; + function privateFunctionWithPrivateTypeParameters() { + } + function privateFunctionWithPublicTypeParameters() { + } + var publicClassWithWithPublicTypeParametersWithoutExtends = (function () { + function publicClassWithWithPublicTypeParametersWithoutExtends() { + } + publicClassWithWithPublicTypeParametersWithoutExtends.myPublicStaticMethod = function () { + }; + publicClassWithWithPublicTypeParametersWithoutExtends.myPrivateStaticMethod = function () { + }; + publicClassWithWithPublicTypeParametersWithoutExtends.prototype.myPublicMethod = function () { + }; + publicClassWithWithPublicTypeParametersWithoutExtends.prototype.myPrivateMethod = function () { + }; + return publicClassWithWithPublicTypeParametersWithoutExtends; + })(); + publicModule.publicClassWithWithPublicTypeParametersWithoutExtends = publicClassWithWithPublicTypeParametersWithoutExtends; + var privateClassWithWithPublicTypeParametersWithoutExtends = (function () { + function privateClassWithWithPublicTypeParametersWithoutExtends() { + } + privateClassWithWithPublicTypeParametersWithoutExtends.myPublicStaticMethod = function () { + }; + privateClassWithWithPublicTypeParametersWithoutExtends.myPrivateStaticMethod = function () { + }; + privateClassWithWithPublicTypeParametersWithoutExtends.prototype.myPublicMethod = function () { + }; + privateClassWithWithPublicTypeParametersWithoutExtends.prototype.myPrivateMethod = function () { + }; + return privateClassWithWithPublicTypeParametersWithoutExtends; + })(); + function publicFunctionWithPublicTypeParametersWithoutExtends() { + } + publicModule.publicFunctionWithPublicTypeParametersWithoutExtends = publicFunctionWithPublicTypeParametersWithoutExtends; + function privateFunctionWithPublicTypeParametersWithoutExtends() { + } + var publicClassWithWithPrivateModuleTypeParameters = (function () { + function publicClassWithWithPrivateModuleTypeParameters() { + } + publicClassWithWithPrivateModuleTypeParameters.myPublicStaticMethod = function () { + }; + publicClassWithWithPrivateModuleTypeParameters.prototype.myPublicMethod = function () { + }; + return publicClassWithWithPrivateModuleTypeParameters; + })(); + publicModule.publicClassWithWithPrivateModuleTypeParameters = publicClassWithWithPrivateModuleTypeParameters; + function publicFunctionWithPrivateMopduleTypeParameters() { + } + publicModule.publicFunctionWithPrivateMopduleTypeParameters = publicFunctionWithPrivateMopduleTypeParameters; + var privateClassWithWithPrivateModuleTypeParameters = (function () { + function privateClassWithWithPrivateModuleTypeParameters() { + } + privateClassWithWithPrivateModuleTypeParameters.myPublicStaticMethod = function () { + }; + privateClassWithWithPrivateModuleTypeParameters.prototype.myPublicMethod = function () { + }; + return privateClassWithWithPrivateModuleTypeParameters; + })(); + function privateFunctionWithPrivateMopduleTypeParameters() { + } +})(exports.publicModule || (exports.publicModule = {})); +var publicModule = exports.publicModule; +var privateModule; +(function (privateModule) { + var privateClass = (function () { + function privateClass() { + } + return privateClass; + })(); + var publicClass = (function () { + function publicClass() { + } + return publicClass; + })(); + privateModule.publicClass = publicClass; + var publicClassWithWithPrivateTypeParameters = (function () { + function publicClassWithWithPrivateTypeParameters() { + } + publicClassWithWithPrivateTypeParameters.myPublicStaticMethod = function () { + }; + publicClassWithWithPrivateTypeParameters.myPrivateStaticMethod = function () { + }; + publicClassWithWithPrivateTypeParameters.prototype.myPublicMethod = function () { + }; + publicClassWithWithPrivateTypeParameters.prototype.myPrivateMethod = function () { + }; + return publicClassWithWithPrivateTypeParameters; + })(); + privateModule.publicClassWithWithPrivateTypeParameters = publicClassWithWithPrivateTypeParameters; + var publicClassWithWithPublicTypeParameters = (function () { + function publicClassWithWithPublicTypeParameters() { + } + publicClassWithWithPublicTypeParameters.myPublicStaticMethod = function () { + }; + publicClassWithWithPublicTypeParameters.myPrivateStaticMethod = function () { + }; + publicClassWithWithPublicTypeParameters.prototype.myPublicMethod = function () { + }; + publicClassWithWithPublicTypeParameters.prototype.myPrivateMethod = function () { + }; + return publicClassWithWithPublicTypeParameters; + })(); + privateModule.publicClassWithWithPublicTypeParameters = publicClassWithWithPublicTypeParameters; + var privateClassWithWithPrivateTypeParameters = (function () { + function privateClassWithWithPrivateTypeParameters() { + } + privateClassWithWithPrivateTypeParameters.myPublicStaticMethod = function () { + }; + privateClassWithWithPrivateTypeParameters.myPrivateStaticMethod = function () { + }; + privateClassWithWithPrivateTypeParameters.prototype.myPublicMethod = function () { + }; + privateClassWithWithPrivateTypeParameters.prototype.myPrivateMethod = function () { + }; + return privateClassWithWithPrivateTypeParameters; + })(); + var privateClassWithWithPublicTypeParameters = (function () { + function privateClassWithWithPublicTypeParameters() { + } + privateClassWithWithPublicTypeParameters.myPublicStaticMethod = function () { + }; + privateClassWithWithPublicTypeParameters.myPrivateStaticMethod = function () { + }; + privateClassWithWithPublicTypeParameters.prototype.myPublicMethod = function () { + }; + privateClassWithWithPublicTypeParameters.prototype.myPrivateMethod = function () { + }; + return privateClassWithWithPublicTypeParameters; + })(); + function publicFunctionWithPrivateTypeParameters() { + } + privateModule.publicFunctionWithPrivateTypeParameters = publicFunctionWithPrivateTypeParameters; + function publicFunctionWithPublicTypeParameters() { + } + privateModule.publicFunctionWithPublicTypeParameters = publicFunctionWithPublicTypeParameters; + function privateFunctionWithPrivateTypeParameters() { + } + function privateFunctionWithPublicTypeParameters() { + } + var publicClassWithWithPublicTypeParametersWithoutExtends = (function () { + function publicClassWithWithPublicTypeParametersWithoutExtends() { + } + publicClassWithWithPublicTypeParametersWithoutExtends.myPublicStaticMethod = function () { + }; + publicClassWithWithPublicTypeParametersWithoutExtends.myPrivateStaticMethod = function () { + }; + publicClassWithWithPublicTypeParametersWithoutExtends.prototype.myPublicMethod = function () { + }; + publicClassWithWithPublicTypeParametersWithoutExtends.prototype.myPrivateMethod = function () { + }; + return publicClassWithWithPublicTypeParametersWithoutExtends; + })(); + privateModule.publicClassWithWithPublicTypeParametersWithoutExtends = publicClassWithWithPublicTypeParametersWithoutExtends; + var privateClassWithWithPublicTypeParametersWithoutExtends = (function () { + function privateClassWithWithPublicTypeParametersWithoutExtends() { + } + privateClassWithWithPublicTypeParametersWithoutExtends.myPublicStaticMethod = function () { + }; + privateClassWithWithPublicTypeParametersWithoutExtends.myPrivateStaticMethod = function () { + }; + privateClassWithWithPublicTypeParametersWithoutExtends.prototype.myPublicMethod = function () { + }; + privateClassWithWithPublicTypeParametersWithoutExtends.prototype.myPrivateMethod = function () { + }; + return privateClassWithWithPublicTypeParametersWithoutExtends; + })(); + function publicFunctionWithPublicTypeParametersWithoutExtends() { + } + privateModule.publicFunctionWithPublicTypeParametersWithoutExtends = publicFunctionWithPublicTypeParametersWithoutExtends; + function privateFunctionWithPublicTypeParametersWithoutExtends() { + } +})(privateModule || (privateModule = {})); diff --git a/tests/baselines/reference/privacyTypeParametersOfClass.errors.txt b/tests/baselines/reference/privacyTypeParametersOfClass.errors.txt deleted file mode 100644 index ad9ed70998f..00000000000 --- a/tests/baselines/reference/privacyTypeParametersOfClass.errors.txt +++ /dev/null @@ -1,47 +0,0 @@ -==== tests/cases/compiler/privacyTypeParametersOfClass.ts (1 errors) ==== - class privateClass { - } - - export class publicClass { - ~~~~~~~~~~~~~~~~~~~~~~~~~~ - } - ~ -!!! Cannot compile external modules unless the '--module' flag is provided. - - // TypeParameter_0_of_exported_class_1_has_or_is_using_private_type_2 - export class publicClassWithPrivateTypeParameters { - myMethod(val: T): T { // Error - return val; - } - } - - export class publicClassWithPublicTypeParameters { - myMethod(val: T): T { // No Error - return val; - } - } - - class privateClassWithPrivateTypeParameters { - myMethod(val: T): T { // No Error - return val; - } - } - - class privateClassWithPublicTypeParameters { - myMethod(val: T): T { // No Error - return val; - } - } - - export class publicClassWithPublicTypeParametersWithoutExtends { - myMethod(val: T): T { // No Error - return val; - } - } - - class privateClassWithPublicTypeParametersWithoutExtends { - myMethod(val: T): T { // No Error - return val; - } - } - \ No newline at end of file diff --git a/tests/baselines/reference/privacyTypeParametersOfClassDeclFile.errors.txt b/tests/baselines/reference/privacyTypeParametersOfClassDeclFile.errors.txt new file mode 100644 index 00000000000..fd9386f9b13 --- /dev/null +++ b/tests/baselines/reference/privacyTypeParametersOfClassDeclFile.errors.txt @@ -0,0 +1,163 @@ +==== tests/cases/compiler/privacyTypeParametersOfClassDeclFile.ts (4 errors) ==== + class privateClass { + } + + export class publicClass { + } + + export class publicClassWithPrivateTypeParameters { // Error + ~~~~~~~~~~~~~~~~~~~~~~ +!!! TypeParameter 'T' of exported class has or is using private name 'privateClass'. + myMethod(val: T): T { + return val; + } + } + + export class publicClassWithPublicTypeParameters { + myMethod(val: T): T { + return val; + } + } + + class privateClassWithPrivateTypeParameters { + myMethod(val: T): T { + return val; + } + } + + class privateClassWithPublicTypeParameters { + myMethod(val: T): T { + return val; + } + } + + export class publicClassWithPublicTypeParametersWithoutExtends { + myMethod(val: T): T { + return val; + } + } + + class privateClassWithPublicTypeParametersWithoutExtends { + myMethod(val: T): T { + return val; + } + } + + export class publicClassWithTypeParametersFromPrivateModule { // Error + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! TypeParameter 'T' of exported class has or is using name 'privateModule.publicClassInPrivateModule' from private module 'privateModule'. + myMethod(val: T): T { + return val; + } + } + + class privateClassWithTypeParametersFromPrivateModule { + myMethod(val: T): T { + return val; + } + } + + export module publicModule { + class privateClassInPublicModule { + } + + export class publicClassInPublicModule { + } + + export class publicClassWithPrivateTypeParameters { // Error + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! TypeParameter 'T' of exported class has or is using private name 'privateClassInPublicModule'. + myMethod(val: T): T { + return val; + } + } + + export class publicClassWithPublicTypeParameters { + myMethod(val: T): T { + return val; + } + } + + class privateClassWithPrivateTypeParameters { + myMethod(val: T): T { + return val; + } + } + + class privateClassWithPublicTypeParameters { + myMethod(val: T): T { + return val; + } + } + + export class publicClassWithPublicTypeParametersWithoutExtends { + myMethod(val: T): T { + return val; + } + } + + class privateClassWithPublicTypeParametersWithoutExtends { + myMethod(val: T): T { + return val; + } + } + + export class publicClassWithTypeParametersFromPrivateModule { // Error + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! TypeParameter 'T' of exported class has or is using name 'privateModule.publicClassInPrivateModule' from private module 'privateModule'. + myMethod(val: T): T { + return val; + } + } + + class privateClassWithTypeParametersFromPrivateModule { + myMethod(val: T): T { + return val; + } + } + } + + module privateModule { + class privateClassInPrivateModule { + } + + export class publicClassInPrivateModule { + } + + export class publicClassWithPrivateTypeParameters { + myMethod(val: T): T { + return val; + } + } + + export class publicClassWithPublicTypeParameters { + myMethod(val: T): T { + return val; + } + } + + class privateClassWithPrivateTypeParameters { + myMethod(val: T): T { + return val; + } + } + + class privateClassWithPublicTypeParameters { + myMethod(val: T): T { + return val; + } + } + + export class publicClassWithPublicTypeParametersWithoutExtends { + myMethod(val: T): T { + return val; + } + } + + class privateClassWithPublicTypeParametersWithoutExtends { + myMethod(val: T): T { + return val; + } + } + } + \ No newline at end of file diff --git a/tests/baselines/reference/privacyTypeParametersOfClassDeclFile.js b/tests/baselines/reference/privacyTypeParametersOfClassDeclFile.js new file mode 100644 index 00000000000..ae829f5ab8a --- /dev/null +++ b/tests/baselines/reference/privacyTypeParametersOfClassDeclFile.js @@ -0,0 +1,383 @@ +//// [privacyTypeParametersOfClassDeclFile.ts] +class privateClass { +} + +export class publicClass { +} + +export class publicClassWithPrivateTypeParameters { // Error + myMethod(val: T): T { + return val; + } +} + +export class publicClassWithPublicTypeParameters { + myMethod(val: T): T { + return val; + } +} + +class privateClassWithPrivateTypeParameters { + myMethod(val: T): T { + return val; + } +} + +class privateClassWithPublicTypeParameters { + myMethod(val: T): T { + return val; + } +} + +export class publicClassWithPublicTypeParametersWithoutExtends { + myMethod(val: T): T { + return val; + } +} + +class privateClassWithPublicTypeParametersWithoutExtends { + myMethod(val: T): T { + return val; + } +} + +export class publicClassWithTypeParametersFromPrivateModule { // Error + myMethod(val: T): T { + return val; + } +} + +class privateClassWithTypeParametersFromPrivateModule { + myMethod(val: T): T { + return val; + } +} + +export module publicModule { + class privateClassInPublicModule { + } + + export class publicClassInPublicModule { + } + + export class publicClassWithPrivateTypeParameters { // Error + myMethod(val: T): T { + return val; + } + } + + export class publicClassWithPublicTypeParameters { + myMethod(val: T): T { + return val; + } + } + + class privateClassWithPrivateTypeParameters { + myMethod(val: T): T { + return val; + } + } + + class privateClassWithPublicTypeParameters { + myMethod(val: T): T { + return val; + } + } + + export class publicClassWithPublicTypeParametersWithoutExtends { + myMethod(val: T): T { + return val; + } + } + + class privateClassWithPublicTypeParametersWithoutExtends { + myMethod(val: T): T { + return val; + } + } + + export class publicClassWithTypeParametersFromPrivateModule { // Error + myMethod(val: T): T { + return val; + } + } + + class privateClassWithTypeParametersFromPrivateModule { + myMethod(val: T): T { + return val; + } + } +} + +module privateModule { + class privateClassInPrivateModule { + } + + export class publicClassInPrivateModule { + } + + export class publicClassWithPrivateTypeParameters { + myMethod(val: T): T { + return val; + } + } + + export class publicClassWithPublicTypeParameters { + myMethod(val: T): T { + return val; + } + } + + class privateClassWithPrivateTypeParameters { + myMethod(val: T): T { + return val; + } + } + + class privateClassWithPublicTypeParameters { + myMethod(val: T): T { + return val; + } + } + + export class publicClassWithPublicTypeParametersWithoutExtends { + myMethod(val: T): T { + return val; + } + } + + class privateClassWithPublicTypeParametersWithoutExtends { + myMethod(val: T): T { + return val; + } + } +} + + +//// [privacyTypeParametersOfClassDeclFile.js] +var privateClass = (function () { + function privateClass() { + } + return privateClass; +})(); +var publicClass = (function () { + function publicClass() { + } + return publicClass; +})(); +exports.publicClass = publicClass; +var publicClassWithPrivateTypeParameters = (function () { + function publicClassWithPrivateTypeParameters() { + } + publicClassWithPrivateTypeParameters.prototype.myMethod = function (val) { + return val; + }; + return publicClassWithPrivateTypeParameters; +})(); +exports.publicClassWithPrivateTypeParameters = publicClassWithPrivateTypeParameters; +var publicClassWithPublicTypeParameters = (function () { + function publicClassWithPublicTypeParameters() { + } + publicClassWithPublicTypeParameters.prototype.myMethod = function (val) { + return val; + }; + return publicClassWithPublicTypeParameters; +})(); +exports.publicClassWithPublicTypeParameters = publicClassWithPublicTypeParameters; +var privateClassWithPrivateTypeParameters = (function () { + function privateClassWithPrivateTypeParameters() { + } + privateClassWithPrivateTypeParameters.prototype.myMethod = function (val) { + return val; + }; + return privateClassWithPrivateTypeParameters; +})(); +var privateClassWithPublicTypeParameters = (function () { + function privateClassWithPublicTypeParameters() { + } + privateClassWithPublicTypeParameters.prototype.myMethod = function (val) { + return val; + }; + return privateClassWithPublicTypeParameters; +})(); +var publicClassWithPublicTypeParametersWithoutExtends = (function () { + function publicClassWithPublicTypeParametersWithoutExtends() { + } + publicClassWithPublicTypeParametersWithoutExtends.prototype.myMethod = function (val) { + return val; + }; + return publicClassWithPublicTypeParametersWithoutExtends; +})(); +exports.publicClassWithPublicTypeParametersWithoutExtends = publicClassWithPublicTypeParametersWithoutExtends; +var privateClassWithPublicTypeParametersWithoutExtends = (function () { + function privateClassWithPublicTypeParametersWithoutExtends() { + } + privateClassWithPublicTypeParametersWithoutExtends.prototype.myMethod = function (val) { + return val; + }; + return privateClassWithPublicTypeParametersWithoutExtends; +})(); +var publicClassWithTypeParametersFromPrivateModule = (function () { + function publicClassWithTypeParametersFromPrivateModule() { + } + publicClassWithTypeParametersFromPrivateModule.prototype.myMethod = function (val) { + return val; + }; + return publicClassWithTypeParametersFromPrivateModule; +})(); +exports.publicClassWithTypeParametersFromPrivateModule = publicClassWithTypeParametersFromPrivateModule; +var privateClassWithTypeParametersFromPrivateModule = (function () { + function privateClassWithTypeParametersFromPrivateModule() { + } + privateClassWithTypeParametersFromPrivateModule.prototype.myMethod = function (val) { + return val; + }; + return privateClassWithTypeParametersFromPrivateModule; +})(); +(function (publicModule) { + var privateClassInPublicModule = (function () { + function privateClassInPublicModule() { + } + return privateClassInPublicModule; + })(); + var publicClassInPublicModule = (function () { + function publicClassInPublicModule() { + } + return publicClassInPublicModule; + })(); + publicModule.publicClassInPublicModule = publicClassInPublicModule; + var publicClassWithPrivateTypeParameters = (function () { + function publicClassWithPrivateTypeParameters() { + } + publicClassWithPrivateTypeParameters.prototype.myMethod = function (val) { + return val; + }; + return publicClassWithPrivateTypeParameters; + })(); + publicModule.publicClassWithPrivateTypeParameters = publicClassWithPrivateTypeParameters; + var publicClassWithPublicTypeParameters = (function () { + function publicClassWithPublicTypeParameters() { + } + publicClassWithPublicTypeParameters.prototype.myMethod = function (val) { + return val; + }; + return publicClassWithPublicTypeParameters; + })(); + publicModule.publicClassWithPublicTypeParameters = publicClassWithPublicTypeParameters; + var privateClassWithPrivateTypeParameters = (function () { + function privateClassWithPrivateTypeParameters() { + } + privateClassWithPrivateTypeParameters.prototype.myMethod = function (val) { + return val; + }; + return privateClassWithPrivateTypeParameters; + })(); + var privateClassWithPublicTypeParameters = (function () { + function privateClassWithPublicTypeParameters() { + } + privateClassWithPublicTypeParameters.prototype.myMethod = function (val) { + return val; + }; + return privateClassWithPublicTypeParameters; + })(); + var publicClassWithPublicTypeParametersWithoutExtends = (function () { + function publicClassWithPublicTypeParametersWithoutExtends() { + } + publicClassWithPublicTypeParametersWithoutExtends.prototype.myMethod = function (val) { + return val; + }; + return publicClassWithPublicTypeParametersWithoutExtends; + })(); + publicModule.publicClassWithPublicTypeParametersWithoutExtends = publicClassWithPublicTypeParametersWithoutExtends; + var privateClassWithPublicTypeParametersWithoutExtends = (function () { + function privateClassWithPublicTypeParametersWithoutExtends() { + } + privateClassWithPublicTypeParametersWithoutExtends.prototype.myMethod = function (val) { + return val; + }; + return privateClassWithPublicTypeParametersWithoutExtends; + })(); + var publicClassWithTypeParametersFromPrivateModule = (function () { + function publicClassWithTypeParametersFromPrivateModule() { + } + publicClassWithTypeParametersFromPrivateModule.prototype.myMethod = function (val) { + return val; + }; + return publicClassWithTypeParametersFromPrivateModule; + })(); + publicModule.publicClassWithTypeParametersFromPrivateModule = publicClassWithTypeParametersFromPrivateModule; + var privateClassWithTypeParametersFromPrivateModule = (function () { + function privateClassWithTypeParametersFromPrivateModule() { + } + privateClassWithTypeParametersFromPrivateModule.prototype.myMethod = function (val) { + return val; + }; + return privateClassWithTypeParametersFromPrivateModule; + })(); +})(exports.publicModule || (exports.publicModule = {})); +var publicModule = exports.publicModule; +var privateModule; +(function (privateModule) { + var privateClassInPrivateModule = (function () { + function privateClassInPrivateModule() { + } + return privateClassInPrivateModule; + })(); + var publicClassInPrivateModule = (function () { + function publicClassInPrivateModule() { + } + return publicClassInPrivateModule; + })(); + privateModule.publicClassInPrivateModule = publicClassInPrivateModule; + var publicClassWithPrivateTypeParameters = (function () { + function publicClassWithPrivateTypeParameters() { + } + publicClassWithPrivateTypeParameters.prototype.myMethod = function (val) { + return val; + }; + return publicClassWithPrivateTypeParameters; + })(); + privateModule.publicClassWithPrivateTypeParameters = publicClassWithPrivateTypeParameters; + var publicClassWithPublicTypeParameters = (function () { + function publicClassWithPublicTypeParameters() { + } + publicClassWithPublicTypeParameters.prototype.myMethod = function (val) { + return val; + }; + return publicClassWithPublicTypeParameters; + })(); + privateModule.publicClassWithPublicTypeParameters = publicClassWithPublicTypeParameters; + var privateClassWithPrivateTypeParameters = (function () { + function privateClassWithPrivateTypeParameters() { + } + privateClassWithPrivateTypeParameters.prototype.myMethod = function (val) { + return val; + }; + return privateClassWithPrivateTypeParameters; + })(); + var privateClassWithPublicTypeParameters = (function () { + function privateClassWithPublicTypeParameters() { + } + privateClassWithPublicTypeParameters.prototype.myMethod = function (val) { + return val; + }; + return privateClassWithPublicTypeParameters; + })(); + var publicClassWithPublicTypeParametersWithoutExtends = (function () { + function publicClassWithPublicTypeParametersWithoutExtends() { + } + publicClassWithPublicTypeParametersWithoutExtends.prototype.myMethod = function (val) { + return val; + }; + return publicClassWithPublicTypeParametersWithoutExtends; + })(); + privateModule.publicClassWithPublicTypeParametersWithoutExtends = publicClassWithPublicTypeParametersWithoutExtends; + var privateClassWithPublicTypeParametersWithoutExtends = (function () { + function privateClassWithPublicTypeParametersWithoutExtends() { + } + privateClassWithPublicTypeParametersWithoutExtends.prototype.myMethod = function (val) { + return val; + }; + return privateClassWithPublicTypeParametersWithoutExtends; + })(); +})(privateModule || (privateModule = {})); diff --git a/tests/baselines/reference/privacyTypeParametersOfInterface.errors.txt b/tests/baselines/reference/privacyTypeParametersOfInterface.errors.txt deleted file mode 100644 index 42eb13995c8..00000000000 --- a/tests/baselines/reference/privacyTypeParametersOfInterface.errors.txt +++ /dev/null @@ -1,62 +0,0 @@ -==== tests/cases/compiler/privacyTypeParametersOfInterface.ts (1 errors) ==== - class privateClass { - } - - export class publicClass { - ~~~~~~~~~~~~~~~~~~~~~~~~~~ - } - ~ -!!! Cannot compile external modules unless the '--module' flag is provided. - - class privateClassT { - } - - export class publicClassT { - } - - // TypeParameter_0_of_exported_interface_1_has_or_is_using_private_type_2 - export interface publicInterfaceWithPrivateTypeParameters { - myMethod(val: T): T; // Error - myMethod0(): publicClassT; // error - myMethod1(): privateClassT; // error - myMethod2(): privateClassT; // error - myMethod3(): publicClassT; //error - myMethod4(): publicClassT; // no error - } - - export interface publicInterfaceWithPublicTypeParameters { - myMethod(val: T): T; // No Error - myMethod0(): publicClassT; // No error - myMethod1(): privateClassT; // error - myMethod2(): privateClassT; // error - myMethod3(): publicClassT; //error - myMethod4(): publicClassT; // no error - } - - interface privateInterfaceWithPrivateTypeParameters { - myMethod(val: T): T; // No Error - myMethod0(): publicClassT; // No error - myMethod1(): privateClassT; // No error - myMethod2(): privateClassT; // No error - myMethod3(): publicClassT; //No error - myMethod4(): publicClassT; // no error - } - - interface privateInterfaceWithPublicTypeParameters { - myMethod(val: T): T; // No Error - myMethod0(): publicClassT; // No error - myMethod1(): privateClassT; // No error - myMethod2(): privateClassT; // No error - myMethod3(): publicClassT; //No error - myMethod4(): publicClassT; // no error - } - - export interface publicInterfaceWithPublicTypeParametersWithoutExtends { - myMethod(val: T): T; // No Error - myMethod0(): publicClassT; // No error - } - - interface privateInterfaceWithPublicTypeParametersWithoutExtends { - myMethod(val: T): T; // No Error - myMethod0(): publicClassT; // No error - } \ No newline at end of file diff --git a/tests/baselines/reference/privacyTypeParametersOfInterfaceDeclFile.errors.txt b/tests/baselines/reference/privacyTypeParametersOfInterfaceDeclFile.errors.txt new file mode 100644 index 00000000000..090ca91836d --- /dev/null +++ b/tests/baselines/reference/privacyTypeParametersOfInterfaceDeclFile.errors.txt @@ -0,0 +1,199 @@ +==== tests/cases/compiler/privacyTypeParametersOfInterfaceDeclFile.ts (4 errors) ==== + class privateClass { + } + + export class publicClass { + } + + class privateClassT { + } + + export class publicClassT { + } + + export interface publicInterfaceWithPrivateTypeParameters { // Error + ~~~~~~~~~~~~~~~~~~~~~~ +!!! TypeParameter 'T' of exported interface has or is using private name 'privateClass'. + myMethod(val: T): T; + myMethod0(): publicClassT; + myMethod1(): privateClassT; + myMethod2(): privateClassT; + myMethod3(): publicClassT; + myMethod4(): publicClassT; + } + + export interface publicInterfaceWithPublicTypeParameters { + myMethod(val: T): T; + myMethod0(): publicClassT + myMethod1(): privateClassT; + myMethod2(): privateClassT; + myMethod3(): publicClassT; + myMethod4(): publicClassT; + } + + interface privateInterfaceWithPrivateTypeParameters { + myMethod(val: T): T; + myMethod0(): publicClassT; + myMethod1(): privateClassT; + myMethod2(): privateClassT; + myMethod3(): publicClassT; + myMethod4(): publicClassT; + } + + interface privateInterfaceWithPublicTypeParameters { + myMethod(val: T): T; + myMethod0(): publicClassT; + myMethod1(): privateClassT; + myMethod2(): privateClassT; + myMethod3(): publicClassT; + myMethod4(): publicClassT; + } + + export interface publicInterfaceWithPublicTypeParametersWithoutExtends { + myMethod(val: T): T; + myMethod0(): publicClassT; + } + + interface privateInterfaceWithPublicTypeParametersWithoutExtends { + myMethod(val: T): T; + myMethod0(): publicClassT; + } + + + export interface publicInterfaceWithPrivateModuleTypeParameterConstraints { // Error + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! TypeParameter 'T' of exported interface has or is using name 'privateModule.publicClassInPrivateModule' from private module 'privateModule'. + } + + interface privateInterfaceWithPrivateModuleTypeParameterConstraints { // Error + } + + export module publicModule { + class privateClassInPublicModule { + } + + export class publicClassInPublicModule { + } + + class privateClassInPublicModuleT { + } + + export class publicClassInPublicModuleT { + } + + export interface publicInterfaceWithPrivateTypeParameters { // Error + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! TypeParameter 'T' of exported interface has or is using private name 'privateClassInPublicModule'. + myMethod(val: T): T; + myMethod0(): publicClassInPublicModuleT; + myMethod1(): privateClassInPublicModuleT; + myMethod2(): privateClassInPublicModuleT; + myMethod3(): publicClassInPublicModuleT; + myMethod4(): publicClassInPublicModuleT; + } + + export interface publicInterfaceWithPublicTypeParameters { + myMethod(val: T): T; + myMethod0(): publicClassInPublicModuleT + myMethod1(): privateClassInPublicModuleT; + myMethod2(): privateClassInPublicModuleT; + myMethod3(): publicClassInPublicModuleT; + myMethod4(): publicClassInPublicModuleT; + } + + interface privateInterfaceWithPrivateTypeParameters { + myMethod(val: T): T; + myMethod0(): publicClassInPublicModuleT; + myMethod1(): privateClassInPublicModuleT; + myMethod2(): privateClassInPublicModuleT; + myMethod3(): publicClassInPublicModuleT; + myMethod4(): publicClassInPublicModuleT; + } + + interface privateInterfaceWithPublicTypeParameters { + myMethod(val: T): T; + myMethod0(): publicClassInPublicModuleT; + myMethod1(): privateClassInPublicModuleT; + myMethod2(): privateClassInPublicModuleT; + myMethod3(): publicClassInPublicModuleT; + myMethod4(): publicClassInPublicModuleT; + } + + export interface publicInterfaceWithPublicTypeParametersWithoutExtends { + myMethod(val: T): T; + myMethod0(): publicClassInPublicModuleT; + } + + interface privateInterfaceWithPublicTypeParametersWithoutExtends { + myMethod(val: T): T; + myMethod0(): publicClassInPublicModuleT; + } + + export interface publicInterfaceWithPrivateModuleTypeParameterConstraints { // Error + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! TypeParameter 'T' of exported interface has or is using name 'privateModule.publicClassInPrivateModule' from private module 'privateModule'. + } + + interface privateInterfaceWithPrivateModuleTypeParameterConstraints { // Error + } + } + + module privateModule { + class privateClassInPrivateModule { + } + + export class publicClassInPrivateModule { + } + + class privateClassInPrivateModuleT { + } + + export class publicClassInPrivateModuleT { + } + + export interface publicInterfaceWithPrivateTypeParameters { + myMethod(val: T): T; + myMethod0(): publicClassInPrivateModuleT; + myMethod1(): privateClassInPrivateModuleT; + myMethod2(): privateClassInPrivateModuleT; + myMethod3(): publicClassInPrivateModuleT; + myMethod4(): publicClassInPrivateModuleT; + } + + export interface publicInterfaceWithPublicTypeParameters { + myMethod(val: T): T; + myMethod0(): publicClassInPrivateModuleT + myMethod1(): privateClassInPrivateModuleT; + myMethod2(): privateClassInPrivateModuleT; + myMethod3(): publicClassInPrivateModuleT; + myMethod4(): publicClassInPrivateModuleT; + } + + interface privateInterfaceWithPrivateTypeParameters { + myMethod(val: T): T; + myMethod0(): publicClassInPrivateModuleT; + myMethod1(): privateClassInPrivateModuleT; + myMethod2(): privateClassInPrivateModuleT; + myMethod3(): publicClassInPrivateModuleT; + myMethod4(): publicClassInPrivateModuleT; + } + + interface privateInterfaceWithPublicTypeParameters { + myMethod(val: T): T; + myMethod0(): publicClassInPrivateModuleT; + myMethod1(): privateClassInPrivateModuleT; + myMethod2(): privateClassInPrivateModuleT; + myMethod3(): publicClassInPrivateModuleT; + myMethod4(): publicClassInPrivateModuleT; + } + + export interface publicInterfaceWithPublicTypeParametersWithoutExtends { + myMethod(val: T): T; + myMethod0(): publicClassInPrivateModuleT; + } + + interface privateInterfaceWithPublicTypeParametersWithoutExtends { + myMethod(val: T): T; + myMethod0(): publicClassInPrivateModuleT; + } + } \ No newline at end of file diff --git a/tests/baselines/reference/privacyTypeParametersOfInterfaceDeclFile.js b/tests/baselines/reference/privacyTypeParametersOfInterfaceDeclFile.js new file mode 100644 index 00000000000..2ae5488dd3c --- /dev/null +++ b/tests/baselines/reference/privacyTypeParametersOfInterfaceDeclFile.js @@ -0,0 +1,265 @@ +//// [privacyTypeParametersOfInterfaceDeclFile.ts] +class privateClass { +} + +export class publicClass { +} + +class privateClassT { +} + +export class publicClassT { +} + +export interface publicInterfaceWithPrivateTypeParameters { // Error + myMethod(val: T): T; + myMethod0(): publicClassT; + myMethod1(): privateClassT; + myMethod2(): privateClassT; + myMethod3(): publicClassT; + myMethod4(): publicClassT; +} + +export interface publicInterfaceWithPublicTypeParameters { + myMethod(val: T): T; + myMethod0(): publicClassT + myMethod1(): privateClassT; + myMethod2(): privateClassT; + myMethod3(): publicClassT; + myMethod4(): publicClassT; +} + +interface privateInterfaceWithPrivateTypeParameters { + myMethod(val: T): T; + myMethod0(): publicClassT; + myMethod1(): privateClassT; + myMethod2(): privateClassT; + myMethod3(): publicClassT; + myMethod4(): publicClassT; +} + +interface privateInterfaceWithPublicTypeParameters { + myMethod(val: T): T; + myMethod0(): publicClassT; + myMethod1(): privateClassT; + myMethod2(): privateClassT; + myMethod3(): publicClassT; + myMethod4(): publicClassT; +} + +export interface publicInterfaceWithPublicTypeParametersWithoutExtends { + myMethod(val: T): T; + myMethod0(): publicClassT; +} + +interface privateInterfaceWithPublicTypeParametersWithoutExtends { + myMethod(val: T): T; + myMethod0(): publicClassT; +} + + +export interface publicInterfaceWithPrivateModuleTypeParameterConstraints { // Error +} + +interface privateInterfaceWithPrivateModuleTypeParameterConstraints { // Error +} + +export module publicModule { + class privateClassInPublicModule { + } + + export class publicClassInPublicModule { + } + + class privateClassInPublicModuleT { + } + + export class publicClassInPublicModuleT { + } + + export interface publicInterfaceWithPrivateTypeParameters { // Error + myMethod(val: T): T; + myMethod0(): publicClassInPublicModuleT; + myMethod1(): privateClassInPublicModuleT; + myMethod2(): privateClassInPublicModuleT; + myMethod3(): publicClassInPublicModuleT; + myMethod4(): publicClassInPublicModuleT; + } + + export interface publicInterfaceWithPublicTypeParameters { + myMethod(val: T): T; + myMethod0(): publicClassInPublicModuleT + myMethod1(): privateClassInPublicModuleT; + myMethod2(): privateClassInPublicModuleT; + myMethod3(): publicClassInPublicModuleT; + myMethod4(): publicClassInPublicModuleT; + } + + interface privateInterfaceWithPrivateTypeParameters { + myMethod(val: T): T; + myMethod0(): publicClassInPublicModuleT; + myMethod1(): privateClassInPublicModuleT; + myMethod2(): privateClassInPublicModuleT; + myMethod3(): publicClassInPublicModuleT; + myMethod4(): publicClassInPublicModuleT; + } + + interface privateInterfaceWithPublicTypeParameters { + myMethod(val: T): T; + myMethod0(): publicClassInPublicModuleT; + myMethod1(): privateClassInPublicModuleT; + myMethod2(): privateClassInPublicModuleT; + myMethod3(): publicClassInPublicModuleT; + myMethod4(): publicClassInPublicModuleT; + } + + export interface publicInterfaceWithPublicTypeParametersWithoutExtends { + myMethod(val: T): T; + myMethod0(): publicClassInPublicModuleT; + } + + interface privateInterfaceWithPublicTypeParametersWithoutExtends { + myMethod(val: T): T; + myMethod0(): publicClassInPublicModuleT; + } + + export interface publicInterfaceWithPrivateModuleTypeParameterConstraints { // Error + } + + interface privateInterfaceWithPrivateModuleTypeParameterConstraints { // Error + } +} + +module privateModule { + class privateClassInPrivateModule { + } + + export class publicClassInPrivateModule { + } + + class privateClassInPrivateModuleT { + } + + export class publicClassInPrivateModuleT { + } + + export interface publicInterfaceWithPrivateTypeParameters { + myMethod(val: T): T; + myMethod0(): publicClassInPrivateModuleT; + myMethod1(): privateClassInPrivateModuleT; + myMethod2(): privateClassInPrivateModuleT; + myMethod3(): publicClassInPrivateModuleT; + myMethod4(): publicClassInPrivateModuleT; + } + + export interface publicInterfaceWithPublicTypeParameters { + myMethod(val: T): T; + myMethod0(): publicClassInPrivateModuleT + myMethod1(): privateClassInPrivateModuleT; + myMethod2(): privateClassInPrivateModuleT; + myMethod3(): publicClassInPrivateModuleT; + myMethod4(): publicClassInPrivateModuleT; + } + + interface privateInterfaceWithPrivateTypeParameters { + myMethod(val: T): T; + myMethod0(): publicClassInPrivateModuleT; + myMethod1(): privateClassInPrivateModuleT; + myMethod2(): privateClassInPrivateModuleT; + myMethod3(): publicClassInPrivateModuleT; + myMethod4(): publicClassInPrivateModuleT; + } + + interface privateInterfaceWithPublicTypeParameters { + myMethod(val: T): T; + myMethod0(): publicClassInPrivateModuleT; + myMethod1(): privateClassInPrivateModuleT; + myMethod2(): privateClassInPrivateModuleT; + myMethod3(): publicClassInPrivateModuleT; + myMethod4(): publicClassInPrivateModuleT; + } + + export interface publicInterfaceWithPublicTypeParametersWithoutExtends { + myMethod(val: T): T; + myMethod0(): publicClassInPrivateModuleT; + } + + interface privateInterfaceWithPublicTypeParametersWithoutExtends { + myMethod(val: T): T; + myMethod0(): publicClassInPrivateModuleT; + } +} + +//// [privacyTypeParametersOfInterfaceDeclFile.js] +var privateClass = (function () { + function privateClass() { + } + return privateClass; +})(); +var publicClass = (function () { + function publicClass() { + } + return publicClass; +})(); +exports.publicClass = publicClass; +var privateClassT = (function () { + function privateClassT() { + } + return privateClassT; +})(); +var publicClassT = (function () { + function publicClassT() { + } + return publicClassT; +})(); +exports.publicClassT = publicClassT; +(function (publicModule) { + var privateClassInPublicModule = (function () { + function privateClassInPublicModule() { + } + return privateClassInPublicModule; + })(); + var publicClassInPublicModule = (function () { + function publicClassInPublicModule() { + } + return publicClassInPublicModule; + })(); + publicModule.publicClassInPublicModule = publicClassInPublicModule; + var privateClassInPublicModuleT = (function () { + function privateClassInPublicModuleT() { + } + return privateClassInPublicModuleT; + })(); + var publicClassInPublicModuleT = (function () { + function publicClassInPublicModuleT() { + } + return publicClassInPublicModuleT; + })(); + publicModule.publicClassInPublicModuleT = publicClassInPublicModuleT; +})(exports.publicModule || (exports.publicModule = {})); +var publicModule = exports.publicModule; +var privateModule; +(function (privateModule) { + var privateClassInPrivateModule = (function () { + function privateClassInPrivateModule() { + } + return privateClassInPrivateModule; + })(); + var publicClassInPrivateModule = (function () { + function publicClassInPrivateModule() { + } + return publicClassInPrivateModule; + })(); + privateModule.publicClassInPrivateModule = publicClassInPrivateModule; + var privateClassInPrivateModuleT = (function () { + function privateClassInPrivateModuleT() { + } + return privateClassInPrivateModuleT; + })(); + var publicClassInPrivateModuleT = (function () { + function publicClassInPrivateModuleT() { + } + return publicClassInPrivateModuleT; + })(); + privateModule.publicClassInPrivateModuleT = publicClassInPrivateModuleT; +})(privateModule || (privateModule = {})); diff --git a/tests/cases/compiler/privacyTypeParameterOfFunction.ts b/tests/cases/compiler/privacyTypeParameterOfFunction.ts index 2b22b5321bb..dfbecc24bf3 100644 --- a/tests/cases/compiler/privacyTypeParameterOfFunction.ts +++ b/tests/cases/compiler/privacyTypeParameterOfFunction.ts @@ -1,3 +1,4 @@ +// @module: commonjs class privateClass { } diff --git a/tests/cases/compiler/privacyTypeParameterOfFunctionDeclFile.ts b/tests/cases/compiler/privacyTypeParameterOfFunctionDeclFile.ts new file mode 100644 index 00000000000..7ea908e9cfb --- /dev/null +++ b/tests/cases/compiler/privacyTypeParameterOfFunctionDeclFile.ts @@ -0,0 +1,440 @@ +// @module: commonjs +// @declaration: true +class privateClass { +} + +export class publicClass { +} + +export interface publicInterfaceWithPrivateTypeParameters { + new (): privateClass; // Error + (): privateClass; // Error + myMethod(): privateClass; // Error +} + +export interface publicInterfaceWithPublicTypeParameters { + new (): publicClass; + (): publicClass; + myMethod(): publicClass; +} + +interface privateInterfaceWithPrivateTypeParameters { + new (): privateClass; + (): privateClass; + myMethod(): privateClass; +} + +interface privateInterfaceWithPublicTypeParameters { + new (): publicClass; + (): publicClass; + myMethod(): publicClass; +} + +export class publicClassWithWithPrivateTypeParameters { + static myPublicStaticMethod() { // Error + } + private static myPrivateStaticMethod() { + } + myPublicMethod() { // Error + } + private myPrivateMethod() { + } +} + +export class publicClassWithWithPublicTypeParameters { + static myPublicStaticMethod() { + } + private static myPrivateStaticMethod() { + } + myPublicMethod() { + } + private myPrivateMethod() { + } +} + +class privateClassWithWithPrivateTypeParameters { + static myPublicStaticMethod() { + } + private static myPrivateStaticMethod() { + } + myPublicMethod() { + } + private myPrivateMethod() { + } +} + +class privateClassWithWithPublicTypeParameters { + static myPublicStaticMethod() { + } + private static myPrivateStaticMethod() { + } + myPublicMethod() { + } + private myPrivateMethod() { + } +} + +export function publicFunctionWithPrivateTypeParameters() { // Error +} + +export function publicFunctionWithPublicTypeParameters() { +} + +function privateFunctionWithPrivateTypeParameters() { +} + +function privateFunctionWithPublicTypeParameters() { +} + +export interface publicInterfaceWithPublicTypeParametersWithoutExtends { + new (): publicClass; + (): publicClass; + myMethod(): publicClass; +} + +interface privateInterfaceWithPublicTypeParametersWithoutExtends { + new (): publicClass; + (): publicClass; + myMethod(): publicClass; +} + +export class publicClassWithWithPublicTypeParametersWithoutExtends { + static myPublicStaticMethod() { + } + private static myPrivateStaticMethod() { + } + myPublicMethod() { + } + private myPrivateMethod() { + } +} +class privateClassWithWithPublicTypeParametersWithoutExtends { + static myPublicStaticMethod() { + } + private static myPrivateStaticMethod() { + } + myPublicMethod() { + } + private myPrivateMethod() { + } +} + +export function publicFunctionWithPublicTypeParametersWithoutExtends() { +} + +function privateFunctionWithPublicTypeParametersWithoutExtends() { +} + +export interface publicInterfaceWithPrivatModuleTypeParameters { + new (): privateModule.publicClass; // Error + (): privateModule.publicClass; // Error + myMethod(): privateModule.publicClass; // Error +} +export class publicClassWithWithPrivateModuleTypeParameters { + static myPublicStaticMethod() { // Error + } + myPublicMethod() { // Error + } +} +export function publicFunctionWithPrivateMopduleTypeParameters() { // Error +} + + +interface privateInterfaceWithPrivatModuleTypeParameters { + new (): privateModule.publicClass; + (): privateModule.publicClass; + myMethod(): privateModule.publicClass; +} +class privateClassWithWithPrivateModuleTypeParameters { + static myPublicStaticMethod() { + } + myPublicMethod() { + } +} +function privateFunctionWithPrivateMopduleTypeParameters() { +} + + +export module publicModule { + class privateClass { + } + + export class publicClass { + } + + export interface publicInterfaceWithPrivateTypeParameters { + new (): privateClass; // Error + (): privateClass; // Error + myMethod(): privateClass; // Error + } + + export interface publicInterfaceWithPublicTypeParameters { + new (): publicClass; + (): publicClass; + myMethod(): publicClass; + } + + interface privateInterfaceWithPrivateTypeParameters { + new (): privateClass; + (): privateClass; + myMethod(): privateClass; + } + + interface privateInterfaceWithPublicTypeParameters { + new (): publicClass; + (): publicClass; + myMethod(): publicClass; + } + + export class publicClassWithWithPrivateTypeParameters { + static myPublicStaticMethod() { // Error + } + private static myPrivateStaticMethod() { + } + myPublicMethod() { // Error + } + private myPrivateMethod() { + } + } + + export class publicClassWithWithPublicTypeParameters { + static myPublicStaticMethod() { + } + private static myPrivateStaticMethod() { + } + myPublicMethod() { + } + private myPrivateMethod() { + } + } + + class privateClassWithWithPrivateTypeParameters { + static myPublicStaticMethod() { + } + private static myPrivateStaticMethod() { + } + myPublicMethod() { + } + private myPrivateMethod() { + } + } + + class privateClassWithWithPublicTypeParameters { + static myPublicStaticMethod() { + } + private static myPrivateStaticMethod() { + } + myPublicMethod() { + } + private myPrivateMethod() { + } + } + + export function publicFunctionWithPrivateTypeParameters() { // Error + } + + export function publicFunctionWithPublicTypeParameters() { + } + + function privateFunctionWithPrivateTypeParameters() { + } + + function privateFunctionWithPublicTypeParameters() { + } + + export interface publicInterfaceWithPublicTypeParametersWithoutExtends { + new (): publicClass; + (): publicClass; + myMethod(): publicClass; + } + + interface privateInterfaceWithPublicTypeParametersWithoutExtends { + new (): publicClass; + (): publicClass; + myMethod(): publicClass; + } + + export class publicClassWithWithPublicTypeParametersWithoutExtends { + static myPublicStaticMethod() { + } + private static myPrivateStaticMethod() { + } + myPublicMethod() { + } + private myPrivateMethod() { + } + } + class privateClassWithWithPublicTypeParametersWithoutExtends { + static myPublicStaticMethod() { + } + private static myPrivateStaticMethod() { + } + myPublicMethod() { + } + private myPrivateMethod() { + } + } + + export function publicFunctionWithPublicTypeParametersWithoutExtends() { + } + + function privateFunctionWithPublicTypeParametersWithoutExtends() { + } + + export interface publicInterfaceWithPrivatModuleTypeParameters { + new (): privateModule.publicClass; // Error + (): privateModule.publicClass; // Error + myMethod(): privateModule.publicClass; // Error + } + export class publicClassWithWithPrivateModuleTypeParameters { + static myPublicStaticMethod() { // Error + } + myPublicMethod() { // Error + } + } + export function publicFunctionWithPrivateMopduleTypeParameters() { // Error + } + + + interface privateInterfaceWithPrivatModuleTypeParameters { + new (): privateModule.publicClass; + (): privateModule.publicClass; + myMethod(): privateModule.publicClass; + } + class privateClassWithWithPrivateModuleTypeParameters { + static myPublicStaticMethod() { + } + myPublicMethod() { + } + } + function privateFunctionWithPrivateMopduleTypeParameters() { + } + +} + +module privateModule { + class privateClass { + } + + export class publicClass { + } + + export interface publicInterfaceWithPrivateTypeParameters { + new (): privateClass; + (): privateClass; + myMethod(): privateClass; + } + + export interface publicInterfaceWithPublicTypeParameters { + new (): publicClass; + (): publicClass; + myMethod(): publicClass; + } + + interface privateInterfaceWithPrivateTypeParameters { + new (): privateClass; + (): privateClass; + myMethod(): privateClass; + } + + interface privateInterfaceWithPublicTypeParameters { + new (): publicClass; + (): publicClass; + myMethod(): publicClass; + } + + export class publicClassWithWithPrivateTypeParameters { + static myPublicStaticMethod() { + } + private static myPrivateStaticMethod() { + } + myPublicMethod() { + } + private myPrivateMethod() { + } + } + + export class publicClassWithWithPublicTypeParameters { + static myPublicStaticMethod() { + } + private static myPrivateStaticMethod() { + } + myPublicMethod() { + } + private myPrivateMethod() { + } + } + + class privateClassWithWithPrivateTypeParameters { + static myPublicStaticMethod() { + } + private static myPrivateStaticMethod() { + } + myPublicMethod() { + } + private myPrivateMethod() { + } + } + + class privateClassWithWithPublicTypeParameters { + static myPublicStaticMethod() { + } + private static myPrivateStaticMethod() { + } + myPublicMethod() { + } + private myPrivateMethod() { + } + } + + export function publicFunctionWithPrivateTypeParameters() { + } + + export function publicFunctionWithPublicTypeParameters() { + } + + function privateFunctionWithPrivateTypeParameters() { + } + + function privateFunctionWithPublicTypeParameters() { + } + + export interface publicInterfaceWithPublicTypeParametersWithoutExtends { + new (): publicClass; + (): publicClass; + myMethod(): publicClass; + } + + interface privateInterfaceWithPublicTypeParametersWithoutExtends { + new (): publicClass; + (): publicClass; + myMethod(): publicClass; + } + + export class publicClassWithWithPublicTypeParametersWithoutExtends { + static myPublicStaticMethod() { + } + private static myPrivateStaticMethod() { + } + myPublicMethod() { + } + private myPrivateMethod() { + } + } + class privateClassWithWithPublicTypeParametersWithoutExtends { + static myPublicStaticMethod() { + } + private static myPrivateStaticMethod() { + } + myPublicMethod() { + } + private myPrivateMethod() { + } + } + + export function publicFunctionWithPublicTypeParametersWithoutExtends() { + } + + function privateFunctionWithPublicTypeParametersWithoutExtends() { + } +} \ No newline at end of file diff --git a/tests/cases/compiler/privacyTypeParametersOfClass.ts b/tests/cases/compiler/privacyTypeParametersOfClass.ts index 59f771ef718..e7b520e58ca 100644 --- a/tests/cases/compiler/privacyTypeParametersOfClass.ts +++ b/tests/cases/compiler/privacyTypeParametersOfClass.ts @@ -1,3 +1,4 @@ +// @module: commonjs class privateClass { } diff --git a/tests/cases/compiler/privacyTypeParametersOfClassDeclFile.ts b/tests/cases/compiler/privacyTypeParametersOfClassDeclFile.ts new file mode 100644 index 00000000000..dcc21ca362a --- /dev/null +++ b/tests/cases/compiler/privacyTypeParametersOfClassDeclFile.ts @@ -0,0 +1,155 @@ +// @module: commonjs +// @declaration: true +class privateClass { +} + +export class publicClass { +} + +export class publicClassWithPrivateTypeParameters { // Error + myMethod(val: T): T { + return val; + } +} + +export class publicClassWithPublicTypeParameters { + myMethod(val: T): T { + return val; + } +} + +class privateClassWithPrivateTypeParameters { + myMethod(val: T): T { + return val; + } +} + +class privateClassWithPublicTypeParameters { + myMethod(val: T): T { + return val; + } +} + +export class publicClassWithPublicTypeParametersWithoutExtends { + myMethod(val: T): T { + return val; + } +} + +class privateClassWithPublicTypeParametersWithoutExtends { + myMethod(val: T): T { + return val; + } +} + +export class publicClassWithTypeParametersFromPrivateModule { // Error + myMethod(val: T): T { + return val; + } +} + +class privateClassWithTypeParametersFromPrivateModule { + myMethod(val: T): T { + return val; + } +} + +export module publicModule { + class privateClassInPublicModule { + } + + export class publicClassInPublicModule { + } + + export class publicClassWithPrivateTypeParameters { // Error + myMethod(val: T): T { + return val; + } + } + + export class publicClassWithPublicTypeParameters { + myMethod(val: T): T { + return val; + } + } + + class privateClassWithPrivateTypeParameters { + myMethod(val: T): T { + return val; + } + } + + class privateClassWithPublicTypeParameters { + myMethod(val: T): T { + return val; + } + } + + export class publicClassWithPublicTypeParametersWithoutExtends { + myMethod(val: T): T { + return val; + } + } + + class privateClassWithPublicTypeParametersWithoutExtends { + myMethod(val: T): T { + return val; + } + } + + export class publicClassWithTypeParametersFromPrivateModule { // Error + myMethod(val: T): T { + return val; + } + } + + class privateClassWithTypeParametersFromPrivateModule { + myMethod(val: T): T { + return val; + } + } +} + +module privateModule { + class privateClassInPrivateModule { + } + + export class publicClassInPrivateModule { + } + + export class publicClassWithPrivateTypeParameters { + myMethod(val: T): T { + return val; + } + } + + export class publicClassWithPublicTypeParameters { + myMethod(val: T): T { + return val; + } + } + + class privateClassWithPrivateTypeParameters { + myMethod(val: T): T { + return val; + } + } + + class privateClassWithPublicTypeParameters { + myMethod(val: T): T { + return val; + } + } + + export class publicClassWithPublicTypeParametersWithoutExtends { + myMethod(val: T): T { + return val; + } + } + + class privateClassWithPublicTypeParametersWithoutExtends { + myMethod(val: T): T { + return val; + } + } +} diff --git a/tests/cases/compiler/privacyTypeParametersOfInterface.ts b/tests/cases/compiler/privacyTypeParametersOfInterface.ts index fedb16be766..c61174a37c0 100644 --- a/tests/cases/compiler/privacyTypeParametersOfInterface.ts +++ b/tests/cases/compiler/privacyTypeParametersOfInterface.ts @@ -1,3 +1,4 @@ +// @module: commonjs class privateClass { } diff --git a/tests/cases/compiler/privacyTypeParametersOfInterfaceDeclFile.ts b/tests/cases/compiler/privacyTypeParametersOfInterfaceDeclFile.ts new file mode 100644 index 00000000000..55984b46ccb --- /dev/null +++ b/tests/cases/compiler/privacyTypeParametersOfInterfaceDeclFile.ts @@ -0,0 +1,192 @@ +// @module: commonjs +// @declaration: true +class privateClass { +} + +export class publicClass { +} + +class privateClassT { +} + +export class publicClassT { +} + +export interface publicInterfaceWithPrivateTypeParameters { // Error + myMethod(val: T): T; + myMethod0(): publicClassT; + myMethod1(): privateClassT; + myMethod2(): privateClassT; + myMethod3(): publicClassT; + myMethod4(): publicClassT; +} + +export interface publicInterfaceWithPublicTypeParameters { + myMethod(val: T): T; + myMethod0(): publicClassT + myMethod1(): privateClassT; + myMethod2(): privateClassT; + myMethod3(): publicClassT; + myMethod4(): publicClassT; +} + +interface privateInterfaceWithPrivateTypeParameters { + myMethod(val: T): T; + myMethod0(): publicClassT; + myMethod1(): privateClassT; + myMethod2(): privateClassT; + myMethod3(): publicClassT; + myMethod4(): publicClassT; +} + +interface privateInterfaceWithPublicTypeParameters { + myMethod(val: T): T; + myMethod0(): publicClassT; + myMethod1(): privateClassT; + myMethod2(): privateClassT; + myMethod3(): publicClassT; + myMethod4(): publicClassT; +} + +export interface publicInterfaceWithPublicTypeParametersWithoutExtends { + myMethod(val: T): T; + myMethod0(): publicClassT; +} + +interface privateInterfaceWithPublicTypeParametersWithoutExtends { + myMethod(val: T): T; + myMethod0(): publicClassT; +} + + +export interface publicInterfaceWithPrivateModuleTypeParameterConstraints { // Error +} + +interface privateInterfaceWithPrivateModuleTypeParameterConstraints { // Error +} + +export module publicModule { + class privateClassInPublicModule { + } + + export class publicClassInPublicModule { + } + + class privateClassInPublicModuleT { + } + + export class publicClassInPublicModuleT { + } + + export interface publicInterfaceWithPrivateTypeParameters { // Error + myMethod(val: T): T; + myMethod0(): publicClassInPublicModuleT; + myMethod1(): privateClassInPublicModuleT; + myMethod2(): privateClassInPublicModuleT; + myMethod3(): publicClassInPublicModuleT; + myMethod4(): publicClassInPublicModuleT; + } + + export interface publicInterfaceWithPublicTypeParameters { + myMethod(val: T): T; + myMethod0(): publicClassInPublicModuleT + myMethod1(): privateClassInPublicModuleT; + myMethod2(): privateClassInPublicModuleT; + myMethod3(): publicClassInPublicModuleT; + myMethod4(): publicClassInPublicModuleT; + } + + interface privateInterfaceWithPrivateTypeParameters { + myMethod(val: T): T; + myMethod0(): publicClassInPublicModuleT; + myMethod1(): privateClassInPublicModuleT; + myMethod2(): privateClassInPublicModuleT; + myMethod3(): publicClassInPublicModuleT; + myMethod4(): publicClassInPublicModuleT; + } + + interface privateInterfaceWithPublicTypeParameters { + myMethod(val: T): T; + myMethod0(): publicClassInPublicModuleT; + myMethod1(): privateClassInPublicModuleT; + myMethod2(): privateClassInPublicModuleT; + myMethod3(): publicClassInPublicModuleT; + myMethod4(): publicClassInPublicModuleT; + } + + export interface publicInterfaceWithPublicTypeParametersWithoutExtends { + myMethod(val: T): T; + myMethod0(): publicClassInPublicModuleT; + } + + interface privateInterfaceWithPublicTypeParametersWithoutExtends { + myMethod(val: T): T; + myMethod0(): publicClassInPublicModuleT; + } + + export interface publicInterfaceWithPrivateModuleTypeParameterConstraints { // Error + } + + interface privateInterfaceWithPrivateModuleTypeParameterConstraints { // Error + } +} + +module privateModule { + class privateClassInPrivateModule { + } + + export class publicClassInPrivateModule { + } + + class privateClassInPrivateModuleT { + } + + export class publicClassInPrivateModuleT { + } + + export interface publicInterfaceWithPrivateTypeParameters { + myMethod(val: T): T; + myMethod0(): publicClassInPrivateModuleT; + myMethod1(): privateClassInPrivateModuleT; + myMethod2(): privateClassInPrivateModuleT; + myMethod3(): publicClassInPrivateModuleT; + myMethod4(): publicClassInPrivateModuleT; + } + + export interface publicInterfaceWithPublicTypeParameters { + myMethod(val: T): T; + myMethod0(): publicClassInPrivateModuleT + myMethod1(): privateClassInPrivateModuleT; + myMethod2(): privateClassInPrivateModuleT; + myMethod3(): publicClassInPrivateModuleT; + myMethod4(): publicClassInPrivateModuleT; + } + + interface privateInterfaceWithPrivateTypeParameters { + myMethod(val: T): T; + myMethod0(): publicClassInPrivateModuleT; + myMethod1(): privateClassInPrivateModuleT; + myMethod2(): privateClassInPrivateModuleT; + myMethod3(): publicClassInPrivateModuleT; + myMethod4(): publicClassInPrivateModuleT; + } + + interface privateInterfaceWithPublicTypeParameters { + myMethod(val: T): T; + myMethod0(): publicClassInPrivateModuleT; + myMethod1(): privateClassInPrivateModuleT; + myMethod2(): privateClassInPrivateModuleT; + myMethod3(): publicClassInPrivateModuleT; + myMethod4(): publicClassInPrivateModuleT; + } + + export interface publicInterfaceWithPublicTypeParametersWithoutExtends { + myMethod(val: T): T; + myMethod0(): publicClassInPrivateModuleT; + } + + interface privateInterfaceWithPublicTypeParametersWithoutExtends { + myMethod(val: T): T; + myMethod0(): publicClassInPrivateModuleT; + } +} \ No newline at end of file From 616dae20f0894eb47cd957130e0eb47daa796374 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Thu, 31 Jul 2014 17:20:57 -0700 Subject: [PATCH 05/15] Fixed diagnostic generator; added messages. --- Jakefile | 2 + scripts/processDiagnosticMessages.ts | 13 +- .../diagnosticInformationMap.generated.ts | 30 ++++ src/compiler/diagnosticMessages.json | 128 +++++++++++++++++- 4 files changed, 163 insertions(+), 10 deletions(-) diff --git a/Jakefile b/Jakefile index 7a8ee59d532..bf5201b696b 100644 --- a/Jakefile +++ b/Jakefile @@ -199,6 +199,8 @@ var processDiagnosticMessagesTs = path.join(scriptsDirectory, "processDiagnostic var diagnosticMessagesJson = path.join(compilerDirectory, "diagnosticMessages.json"); var diagnosticInfoMapTs = path.join(compilerDirectory, "diagnosticInformationMap.generated.ts"); +file(processDiagnosticMessagesTs) + // processDiagnosticMessages script compileFile(processDiagnosticMessagesJs, [processDiagnosticMessagesTs], diff --git a/scripts/processDiagnosticMessages.ts b/scripts/processDiagnosticMessages.ts index e1a198a2124..31449c88e3a 100644 --- a/scripts/processDiagnosticMessages.ts +++ b/scripts/processDiagnosticMessages.ts @@ -94,10 +94,7 @@ function convertPropertyName(origName: string): string { } module NameGenerator { - export function ensureUniqueness( - names: string[], - isFixed: boolean[]= names.map(() => false), - isCaseSensitive: boolean = true): string[] { + export function ensureUniqueness(names: string[], isFixed: boolean[] = names.map(() => false), isCaseSensitive: boolean = false): string[] { var names = names.map(x => x); ensureUniquenessInPlace(names, isFixed, isCaseSensitive); @@ -133,7 +130,7 @@ module NameGenerator { while (true) { var newName = name + suffix++; - if (proposedNames.some((name) => Utilities.stringEquals(name, newName, isCaseSensitive))) { + if (!proposedNames.some((name) => Utilities.stringEquals(name, newName, isCaseSensitive))) { proposedNames[collisionIndex] = newName; break; } @@ -144,7 +141,7 @@ module NameGenerator { module Utilities { /// Return a list of all indices where a string occurs. - export function collectMatchingIndices(name: string, proposedNames: string[], isCaseSensitive: boolean = true): number[] { + export function collectMatchingIndices(name: string, proposedNames: string[], isCaseSensitive: boolean = false): number[] { var matchingIndices: number[] = []; for (var i = 0; i < proposedNames.length; i++) { @@ -156,8 +153,8 @@ module Utilities { return matchingIndices; } - export function stringEquals(s1: string, s2: string, caseSensitive: boolean = true): boolean { - if (!caseSensitive) { + export function stringEquals(s1: string, s2: string, caseSensitive: boolean = false): boolean { + if (caseSensitive) { s1 = s1.toLowerCase(); s2 = s2.toLowerCase(); } diff --git a/src/compiler/diagnosticInformationMap.generated.ts b/src/compiler/diagnosticInformationMap.generated.ts index a3b85cfb013..b97e3974f7b 100644 --- a/src/compiler/diagnosticInformationMap.generated.ts +++ b/src/compiler/diagnosticInformationMap.generated.ts @@ -216,8 +216,38 @@ module ts { Could_not_write_file_0_Colon_1: { code: 5033, category: DiagnosticCategory.Error, key: "Could not write file '{0}': {1}" }, Option_mapRoot_cannot_be_specified_without_specifying_sourcemap_option: { code: 5038, category: DiagnosticCategory.Error, key: "Option mapRoot cannot be specified without specifying sourcemap option." }, Option_sourceRoot_cannot_be_specified_without_specifying_sourcemap_option: { code: 5039, category: DiagnosticCategory.Error, key: "Option sourceRoot cannot be specified without specifying sourcemap option." }, + Concatenate_and_emit_output_to_single_file: { code: 6001, category: DiagnosticCategory.Message, key: "Concatenate and emit output to single file." }, + Generates_corresponding_0_file: { code: 6002, category: DiagnosticCategory.Message, key: "Generates corresponding {0} file." }, + Specifies_the_location_where_debugger_should_locate_map_files_instead_of_generated_locations: { code: 6003, category: DiagnosticCategory.Message, key: "Specifies the location where debugger should locate map files instead of generated locations." }, + Specifies_the_location_where_debugger_should_locate_TypeScript_files_instead_of_source_locations: { code: 6004, category: DiagnosticCategory.Message, key: "Specifies the location where debugger should locate TypeScript files instead of source locations." }, + Watch_input_files: { code: 6005, category: DiagnosticCategory.Message, key: "Watch input files." }, + Redirect_output_structure_to_the_directory: { code: 6006, category: DiagnosticCategory.Message, key: "Redirect output structure to the directory." }, + Do_not_emit_comments_to_output: { code: 6009, category: DiagnosticCategory.Message, key: "Do not emit comments to output." }, + Skip_resolution_and_preprocessing: { code: 6010, category: DiagnosticCategory.Message, key: "Skip resolution and preprocessing." }, + Specify_ECMAScript_target_version_Colon_0_default_or_1: { code: 6015, category: DiagnosticCategory.Message, key: "Specify ECMAScript target version: '{0}' (default), or '{1}'" }, + Specify_module_code_generation_Colon_0_or_1: { code: 6016, category: DiagnosticCategory.Message, key: "Specify module code generation: '{0}' or '{1}'" }, + Print_this_message: { code: 6017, category: DiagnosticCategory.Message, key: "Print this message." }, + Print_the_compiler_s_version_Colon_0: { code: 6019, category: DiagnosticCategory.Message, key: "Print the compiler's version: {0}" }, + Allow_use_of_deprecated_0_keyword_when_referencing_an_external_module: { code: 6021, category: DiagnosticCategory.Message, key: "Allow use of deprecated '{0}' keyword when referencing an external module." }, + Specify_locale_for_errors_and_messages_For_example_0_or_1: { code: 6022, category: DiagnosticCategory.Message, key: "Specify locale for errors and messages. For example '{0}' or '{1}'" }, + Syntax_Colon_0: { code: 6023, category: DiagnosticCategory.Message, key: "Syntax: {0}" }, + options: { code: 6024, category: DiagnosticCategory.Message, key: "options" }, + file: { code: 6025, category: DiagnosticCategory.Message, key: "file" }, + Examples_Colon: { code: 6026, category: DiagnosticCategory.Message, key: "Examples:" }, + Options_Colon: { code: 6027, category: DiagnosticCategory.Message, key: "Options:" }, + Insert_command_line_options_and_files_from_a_file: { code: 6030, category: DiagnosticCategory.Message, key: "Insert command line options and files from a file." }, Version_0: { code: 6029, category: DiagnosticCategory.Message, key: "Version {0}" }, + Use_the_0_flag_to_see_options: { code: 6031, category: DiagnosticCategory.Message, key: "Use the '{0}' flag to see options." }, File_Changed_Compiling: { code: 6032, category: DiagnosticCategory.Message, key: "File Changed. Compiling." }, + STRING: { code: 6033, category: DiagnosticCategory.Message, key: "STRING" }, + KIND: { code: 6034, category: DiagnosticCategory.Message, key: "KIND" }, + FILE: { code: 6035, category: DiagnosticCategory.Message, key: "FILE" }, + VERSION: { code: 6036, category: DiagnosticCategory.Message, key: "VERSION" }, + LOCATION: { code: 6037, category: DiagnosticCategory.Message, key: "LOCATION" }, + DIRECTORY: { code: 6038, category: DiagnosticCategory.Message, key: "DIRECTORY" }, + NUMBER: { code: 6039, category: DiagnosticCategory.Message, key: "NUMBER" }, + Specify_the_codepage_to_use_when_opening_source_files: { code: 6040, category: DiagnosticCategory.Message, key: "Specify the codepage to use when opening source files." }, + Additional_locations_Colon: { code: 6041, category: DiagnosticCategory.Message, key: "Additional locations:" }, Compile_complete_Listening_for_changed_files: { code: 6042, category: DiagnosticCategory.Message, key: "Compile complete. Listening for changed files." }, Variable_0_implicitly_has_an_1_type: { code: 7005, category: DiagnosticCategory.Error, key: "Variable '{0}' implicitly has an '{1}' type." }, Parameter_0_implicitly_has_an_1_type: { code: 7006, category: DiagnosticCategory.Error, key: "Parameter '{0}' implicitly has an '{1}' type." }, diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index 9ace46f4202..d4ae58e8705 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -858,14 +858,138 @@ "category": "Error", "code": 5039 }, + "Concatenate and emit output to single file.": { + "category": "Message", + "code": 6001 + }, + "Generates corresponding {0} file.": { + "category": "Message", + "code": 6002 + }, + "Specifies the location where debugger should locate map files instead of generated locations.": { + "category": "Message", + "code": 6003 + }, + "Specifies the location where debugger should locate TypeScript files instead of source locations.": { + "category": "Message", + "code": 6004 + }, + "Watch input files.": { + "category": "Message", + "code": 6005 + }, + "Redirect output structure to the directory.": { + "category": "Message", + "code": 6006 + }, + "Do not emit comments to output.": { + "category": "Message", + "code": 6009 + }, + "Skip resolution and preprocessing.": { + "category": "Message", + "code": 6010 + }, + "Specify ECMAScript target version: '{0}' (default), or '{1}'": { + "category": "Message", + "code": 6015 + }, + "Specify module code generation: '{0}' or '{1}'": { + "category": "Message", + "code": 6016 + }, + "Print this message.": { + "category": "Message", + "code": 6017 + }, + "Print the compiler's version: {0}": { + "category": "Message", + "code": 6019 + }, + "Allow use of deprecated '{0}' keyword when referencing an external module.": { + "category": "Message", + "code": 6021 + }, + "Specify locale for errors and messages. For example '{0}' or '{1}'": { + "category": "Message", + "code": 6022 + }, + "Syntax: {0}": { + "category": "Message", + "code": 6023 + }, + "options": { + "category": "Message", + "code": 6024 + }, + "file": { + "category": "Message", + "code": 6025 + }, + "Examples:": { + "category": "Message", + "code": 6026 + }, + "Options:": { + "category": "Message", + "code": 6027 + }, + "Insert command line options and files from a file.": { + "category": "Message", + "code": 6028 + }, "Version {0}": { - "category": "Message", - "code": 6029 + "category": "Message", + "code": 6029 + }, + "Insert command line options and files from a file.": { + "category": "Message", + "code": 6030 + }, + "Use the '{0}' flag to see options.": { + "category": "Message", + "code": 6031 }, "File Changed. Compiling.": { "category": "Message", "code": 6032 }, + "STRING": { + "category": "Message", + "code": 6033 + }, + "KIND": { + "category": "Message", + "code": 6034 + }, + "FILE": { + "category": "Message", + "code": 6035 + }, + "VERSION": { + "category": "Message", + "code": 6036 + }, + "LOCATION": { + "category": "Message", + "code": 6037 + }, + "DIRECTORY": { + "category": "Message", + "code": 6038 + }, + "NUMBER": { + "category": "Message", + "code": 6039 + }, + "Specify the codepage to use when opening source files.": { + "category": "Message", + "code": 6040 + }, + "Additional locations:": { + "category": "Message", + "code": 6041 + }, "Compile complete. Listening for changed files.": { "category": "Message", "code": 6042 From 2dd9763badc9075eb3f27a6041338f63cbaa1776 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Fri, 1 Aug 2014 17:12:29 -0700 Subject: [PATCH 06/15] Implemented --help. --- src/compiler/commandLineParser.ts | 158 ++++++++++++++---- src/compiler/core.ts | 2 +- .../diagnosticInformationMap.generated.ts | 32 ++-- src/compiler/diagnosticMessages.json | 93 ++++++----- src/compiler/tc.ts | 146 +++++++++++++--- src/compiler/types.ts | 5 +- 6 files changed, 320 insertions(+), 116 deletions(-) diff --git a/src/compiler/commandLineParser.ts b/src/compiler/commandLineParser.ts index 7a3e27b8a02..8d0f977dddb 100644 --- a/src/compiler/commandLineParser.ts +++ b/src/compiler/commandLineParser.ts @@ -4,44 +4,128 @@ /// module ts { - var shortOptionNames: Map = { - "d": "declaration", - "h": "help", - "m": "module", - "o": "out", - "t": "target", - "v": "version", - "w": "watch", - }; - - var optionDeclarations: CommandLineOption[] = [ - { name: "charset", type: "string" }, - { name: "codepage", type: "number" }, - { name: "declaration", type: "boolean" }, - { name: "diagnostics", type: "boolean" }, - { name: "help", type: "boolean" }, - { name: "locale", type: "string" }, - { name: "mapRoot", type: "string" }, - { name: "module", type: { "commonjs": ModuleKind.CommonJS, "amd": ModuleKind.AMD }, error: Diagnostics.Argument_for_module_option_must_be_commonjs_or_amd }, - { name: "noImplicitAny", type: "boolean" }, - { name: "noLib", type: "boolean" }, - { name: "noLibCheck", type: "boolean" }, - { name: "noResolve", type: "boolean" }, - { name: "out", type: "string" }, - { name: "outDir", type: "string" }, - { name: "removeComments", type: "boolean" }, - { name: "sourceMap", type: "boolean" }, - { name: "sourceRoot", type: "string" }, - { name: "target", type: { "es3": ScriptTarget.ES3, "es5": ScriptTarget.ES5 }, error: Diagnostics.Argument_for_target_option_must_be_es3_or_es5 }, - { name: "version", type: "boolean" }, - { name: "watch", type: "boolean" }, + export var optionDeclarations: CommandLineOption[] = [ + { + name: "charset", + type: "string", + }, + { + name: "codepage", + type: "number", + }, + { + name: "declaration", + shortName: "d", + type: "boolean", + description: Diagnostics.Generates_corresponding_d_ts_file, + }, + { + name: "diagnostics", + type: "boolean", + }, + { + name: "help", + shortName: "h", + type: "boolean", + description: Diagnostics.Print_this_message, + }, + { + name: "locale", + type: "string", + }, + { + name: "mapRoot", + type: "string", + description: Diagnostics.Specifies_the_location_where_debugger_should_locate_map_files_instead_of_generated_locations, + paramType: Diagnostics.LOCATION, + }, + { + name: "module", + shortName: "m", + type: { + "commonjs": ModuleKind.CommonJS, + "amd": ModuleKind.AMD + }, + description: Diagnostics.Specify_module_code_generation_Colon_commonjs_or_amd, + paramType: Diagnostics.KIND, + error: Diagnostics.Argument_for_module_option_must_be_commonjs_or_amd + }, + { + name: "noImplicitAny", + type: "boolean", + description: Diagnostics.Warn_on_expressions_and_declarations_with_an_implied_any_type, + }, + { + name: "noLib", + type: "boolean", + }, + { + name: "noLibCheck", + type: "boolean", + }, + { + name: "noResolve", + type: "boolean", + }, + { + name: "out", + type: "string", + description: Diagnostics.Concatenate_and_emit_output_to_single_file, + paramType: Diagnostics.FILE, + }, + { + name: "outDir", + type: "string", + description: Diagnostics.Redirect_output_structure_to_the_directory, + paramType: Diagnostics.DIRECTORY, + }, + { + name: "removeComments", + type: "boolean", + description: Diagnostics.Do_not_emit_comments_to_output, + }, + { + name: "sourcemap", + type: "boolean", + description: Diagnostics.Generates_corresponding_map_file, + }, + { + name: "sourceRoot", + type: "string", + description: Diagnostics.Specifies_the_location_where_debugger_should_locate_TypeScript_files_instead_of_source_locations, + paramType: Diagnostics.LOCATION, + }, + { + name: "target", + shortName: "t", + type: { "es3": ScriptTarget.ES3, "es5": ScriptTarget.ES5 }, + description: Diagnostics.Specify_ECMAScript_target_version_Colon_ES3_default_or_ES5, + paramType: Diagnostics.VERSION, + error: Diagnostics.Argument_for_target_option_must_be_es3_or_es5 + }, + { + name: "version", + shortName: "v", + type: "boolean", + description: Diagnostics.Print_the_compiler_s_version, + }, + { + name: "watch", + shortName: "w", + type: "boolean", + description: Diagnostics.Watch_input_files, + }, ]; - // Map command line switches to compiler options' property descriptors. Keys must be lower case spellings of command line switches. - // The 'name' property specifies the property name in the CompilerOptions type. The 'type' property specifies the type of the option. - var optionMap: Map = {}; + var shortOptionNames: Map = {}; + var optionNameMap: Map = {}; + forEach(optionDeclarations, option => { - optionMap[option.name.toLowerCase()] = option; + optionNameMap[option.name.toLowerCase()] = option; + + if (option.shortName) { + shortOptionNames[option.shortName] = option.name; + } }); export function parseCommandLine(commandLine: string[]): ParsedCommandLine { @@ -75,8 +159,8 @@ module ts { s = shortOptionNames[s]; } - if (hasProperty(optionMap, s)) { - var opt = optionMap[s]; + if (hasProperty(optionNameMap, s)) { + var opt = optionNameMap[s]; // Check to see if no argument was provided (e.g. "--locale" is the last command-line argument). if (!args[i] && opt.type !== "boolean") { diff --git a/src/compiler/core.ts b/src/compiler/core.ts index 1171191f8dc..537b60cd4ea 100644 --- a/src/compiler/core.ts +++ b/src/compiler/core.ts @@ -247,7 +247,7 @@ module ts { }; } - function compareValues(a: any, b: any): number { + export function compareValues(a: T, b: T): number { if (a === b) return 0; if (a === undefined) return -1; if (b === undefined) return 1; diff --git a/src/compiler/diagnosticInformationMap.generated.ts b/src/compiler/diagnosticInformationMap.generated.ts index b97e3974f7b..0299cbe846d 100644 --- a/src/compiler/diagnosticInformationMap.generated.ts +++ b/src/compiler/diagnosticInformationMap.generated.ts @@ -217,23 +217,23 @@ module ts { Option_mapRoot_cannot_be_specified_without_specifying_sourcemap_option: { code: 5038, category: DiagnosticCategory.Error, key: "Option mapRoot cannot be specified without specifying sourcemap option." }, Option_sourceRoot_cannot_be_specified_without_specifying_sourcemap_option: { code: 5039, category: DiagnosticCategory.Error, key: "Option sourceRoot cannot be specified without specifying sourcemap option." }, Concatenate_and_emit_output_to_single_file: { code: 6001, category: DiagnosticCategory.Message, key: "Concatenate and emit output to single file." }, - Generates_corresponding_0_file: { code: 6002, category: DiagnosticCategory.Message, key: "Generates corresponding {0} file." }, + Generates_corresponding_d_ts_file: { code: 6002, category: DiagnosticCategory.Message, key: "Generates corresponding '.d.ts' file." }, Specifies_the_location_where_debugger_should_locate_map_files_instead_of_generated_locations: { code: 6003, category: DiagnosticCategory.Message, key: "Specifies the location where debugger should locate map files instead of generated locations." }, Specifies_the_location_where_debugger_should_locate_TypeScript_files_instead_of_source_locations: { code: 6004, category: DiagnosticCategory.Message, key: "Specifies the location where debugger should locate TypeScript files instead of source locations." }, Watch_input_files: { code: 6005, category: DiagnosticCategory.Message, key: "Watch input files." }, Redirect_output_structure_to_the_directory: { code: 6006, category: DiagnosticCategory.Message, key: "Redirect output structure to the directory." }, Do_not_emit_comments_to_output: { code: 6009, category: DiagnosticCategory.Message, key: "Do not emit comments to output." }, Skip_resolution_and_preprocessing: { code: 6010, category: DiagnosticCategory.Message, key: "Skip resolution and preprocessing." }, - Specify_ECMAScript_target_version_Colon_0_default_or_1: { code: 6015, category: DiagnosticCategory.Message, key: "Specify ECMAScript target version: '{0}' (default), or '{1}'" }, - Specify_module_code_generation_Colon_0_or_1: { code: 6016, category: DiagnosticCategory.Message, key: "Specify module code generation: '{0}' or '{1}'" }, + Specify_ECMAScript_target_version_Colon_ES3_default_or_ES5: { code: 6015, category: DiagnosticCategory.Message, key: "Specify ECMAScript target version: 'ES3' (default), or 'ES5'" }, + Specify_module_code_generation_Colon_commonjs_or_amd: { code: 6016, category: DiagnosticCategory.Message, key: "Specify module code generation: 'commonjs' or 'amd'" }, Print_this_message: { code: 6017, category: DiagnosticCategory.Message, key: "Print this message." }, - Print_the_compiler_s_version_Colon_0: { code: 6019, category: DiagnosticCategory.Message, key: "Print the compiler's version: {0}" }, + Print_the_compiler_s_version: { code: 6019, category: DiagnosticCategory.Message, key: "Print the compiler's version." }, Allow_use_of_deprecated_0_keyword_when_referencing_an_external_module: { code: 6021, category: DiagnosticCategory.Message, key: "Allow use of deprecated '{0}' keyword when referencing an external module." }, Specify_locale_for_errors_and_messages_For_example_0_or_1: { code: 6022, category: DiagnosticCategory.Message, key: "Specify locale for errors and messages. For example '{0}' or '{1}'" }, - Syntax_Colon_0: { code: 6023, category: DiagnosticCategory.Message, key: "Syntax: {0}" }, + Syntax_Colon_0: { code: 6023, category: DiagnosticCategory.Message, key: "Syntax: {0}" }, options: { code: 6024, category: DiagnosticCategory.Message, key: "options" }, file: { code: 6025, category: DiagnosticCategory.Message, key: "file" }, - Examples_Colon: { code: 6026, category: DiagnosticCategory.Message, key: "Examples:" }, + Examples_Colon_0: { code: 6026, category: DiagnosticCategory.Message, key: "Examples: {0}" }, Options_Colon: { code: 6027, category: DiagnosticCategory.Message, key: "Options:" }, Insert_command_line_options_and_files_from_a_file: { code: 6030, category: DiagnosticCategory.Message, key: "Insert command line options and files from a file." }, Version_0: { code: 6029, category: DiagnosticCategory.Message, key: "Version {0}" }, @@ -249,6 +249,17 @@ module ts { Specify_the_codepage_to_use_when_opening_source_files: { code: 6040, category: DiagnosticCategory.Message, key: "Specify the codepage to use when opening source files." }, Additional_locations_Colon: { code: 6041, category: DiagnosticCategory.Message, key: "Additional locations:" }, Compile_complete_Listening_for_changed_files: { code: 6042, category: DiagnosticCategory.Message, key: "Compile complete. Listening for changed files." }, + Generates_corresponding_map_file: { code: 6043, category: DiagnosticCategory.Message, key: "Generates corresponding '.map' file." }, + Compiler_option_0_expects_an_argument: { code: 6044, category: DiagnosticCategory.Error, key: "Compiler option '{0}' expects an argument." }, + Unterminated_quoted_string_in_response_file_0: { code: 6045, category: DiagnosticCategory.Error, key: "Unterminated quoted string in response file '{0}'." }, + Argument_for_module_option_must_be_commonjs_or_amd: { code: 6045, category: DiagnosticCategory.Error, key: "Argument for '--module' option must be 'commonjs' or 'amd'." }, + Argument_for_target_option_must_be_es3_or_es5: { code: 6046, category: DiagnosticCategory.Error, key: "Argument for '--target' option must be 'es3' or 'es5'." }, + Locale_must_be_of_the_form_language_or_language_territory_For_example_0_or_1: { code: 6047, category: DiagnosticCategory.Error, key: "Locale must be of the form or -. For example '{0}' or '{1}'." }, + Unsupported_locale_0: { code: 6048, category: DiagnosticCategory.Error, key: "Unsupported locale '{0}'." }, + Unable_to_open_file_0: { code: 6049, category: DiagnosticCategory.Error, key: "Unable to open file '{0}'." }, + Corrupted_locale_file_0: { code: 6050, category: DiagnosticCategory.Error, key: "Corrupted locale file {0}." }, + No_input_files_specified: { code: 6051, category: DiagnosticCategory.Error, key: "No input files specified." }, + Warn_on_expressions_and_declarations_with_an_implied_any_type: { code: 7004, category: DiagnosticCategory.Message, key: "Warn on expressions and declarations with an implied 'any' type." }, Variable_0_implicitly_has_an_1_type: { code: 7005, category: DiagnosticCategory.Error, key: "Variable '{0}' implicitly has an '{1}' type." }, Parameter_0_implicitly_has_an_1_type: { code: 7006, category: DiagnosticCategory.Error, key: "Parameter '{0}' implicitly has an '{1}' type." }, Member_0_implicitly_has_an_1_type: { code: 7008, category: DiagnosticCategory.Error, key: "Member '{0}' implicitly has an '{1}' type." }, @@ -334,14 +345,5 @@ module ts { Import_declaration_conflicts_with_local_declaration_of_0: { code: -9999999, category: DiagnosticCategory.Error, key: "Import declaration conflicts with local declaration of '{0}'" }, Module_0_is_hidden_by_a_local_declaration_with_the_same_name: { code: -9999999, category: DiagnosticCategory.Error, key: "Module '{0}' is hidden by a local declaration with the same name" }, Filename_0_differs_from_already_included_filename_1_only_in_casing: { code: -9999999, category: DiagnosticCategory.Error, key: "Filename '{0}' differs from already included filename '{1}' only in casing" }, - Argument_for_module_option_must_be_commonjs_or_amd: { code: -9999999, category: DiagnosticCategory.Error, key: "Argument for '--module' option must be 'commonjs' or 'amd'." }, - Argument_for_target_option_must_be_es3_or_es5: { code: -9999999, category: DiagnosticCategory.Error, key: "Argument for '--target' option must be 'es3' or 'es5'." }, - Compiler_option_0_expects_an_argument: { code: -9999999, category: DiagnosticCategory.Error, key: "Compiler option '{0}' expects an argument." }, - Unterminated_quoted_string_in_response_file_0: { code: -9999999, category: DiagnosticCategory.Error, key: "Unterminated quoted string in response file '{0}'." }, - Locale_must_be_of_the_form_language_or_language_territory_For_example_0_or_1: { code: -9999999, category: DiagnosticCategory.Error, key: "Locale must be of the form or -. For example '{0}' or '{1}'." }, - Unsupported_locale_0: { code: -9999999, category: DiagnosticCategory.Error, key: "Unsupported locale {0}." }, - Unable_to_open_file_0: { code: -9999999, category: DiagnosticCategory.Error, key: "Unable to open file {0}." }, - Corrupted_locale_file_0: { code: -9999999, category: DiagnosticCategory.Error, key: "Corrupted locale file {0}." }, - No_input_files_specified: { code: -9999999, category: DiagnosticCategory.Error, key: "No input files specified." }, }; } \ No newline at end of file diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index d4ae58e8705..30bd7d0a1ed 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -862,7 +862,7 @@ "category": "Message", "code": 6001 }, - "Generates corresponding {0} file.": { + "Generates corresponding '.d.ts' file.": { "category": "Message", "code": 6002 }, @@ -890,11 +890,11 @@ "category": "Message", "code": 6010 }, - "Specify ECMAScript target version: '{0}' (default), or '{1}'": { + "Specify ECMAScript target version: 'ES3' (default), or 'ES5'": { "category": "Message", "code": 6015 }, - "Specify module code generation: '{0}' or '{1}'": { + "Specify module code generation: 'commonjs' or 'amd'": { "category": "Message", "code": 6016 }, @@ -902,7 +902,7 @@ "category": "Message", "code": 6017 }, - "Print the compiler's version: {0}": { + "Print the compiler's version.": { "category": "Message", "code": 6019 }, @@ -914,7 +914,7 @@ "category": "Message", "code": 6022 }, - "Syntax: {0}": { + "Syntax: {0}": { "category": "Message", "code": 6023 }, @@ -926,7 +926,7 @@ "category": "Message", "code": 6025 }, - "Examples:": { + "Examples: {0}": { "category": "Message", "code": 6026 }, @@ -994,11 +994,54 @@ "category": "Message", "code": 6042 }, + "Generates corresponding '.map' file.": { + "category": "Message", + "code": 6043 + }, + "Compiler option '{0}' expects an argument.": { + "category": "Error", + "code": 6044 + }, + "Unterminated quoted string in response file '{0}'.": { + "category": "Error", + "code": 6045 + }, + "Argument for '--module' option must be 'commonjs' or 'amd'.": { + "category": "Error", + "code": 6045 + }, + "Argument for '--target' option must be 'es3' or 'es5'.": { + "category": "Error", + "code": 6046 + }, + "Locale must be of the form or -. For example '{0}' or '{1}'.": { + "category": "Error", + "code": 6047 + }, + "Unsupported locale '{0}'.": { + "category": "Error", + "code": 6048 + }, + "Unable to open file '{0}'.": { + "category": "Error", + "code": 6049 + }, + "Corrupted locale file {0}.": { + "category": "Error", + "code": 6050 + }, + "No input files specified.": { + "category": "Error", + "code": 6051 + }, + "Warn on expressions and declarations with an implied 'any' type.": { + "category": "Message", + "code": 7004 + }, "Variable '{0}' implicitly has an '{1}' type.": { "category": "Error", "code": 7005 }, - "Parameter '{0}' implicitly has an '{1}' type.": { "category": "Error", "code": 7006 @@ -1358,41 +1401,5 @@ "Filename '{0}' differs from already included filename '{1}' only in casing": { "category": "Error", "code": -9999999 - }, - "Argument for '--module' option must be 'commonjs' or 'amd'.": { - "category": "Error", - "code": -9999999 - }, - "Argument for '--target' option must be 'es3' or 'es5'.": { - "category": "Error", - "code": -9999999 - }, - "Compiler option '{0}' expects an argument.": { - "category": "Error", - "code": -9999999 - }, - "Unterminated quoted string in response file '{0}'.": { - "category": "Error", - "code": -9999999 - }, - "Locale must be of the form or -. For example '{0}' or '{1}'.": { - "category": "Error", - "code": -9999999 - }, - "Unsupported locale {0}.": { - "category": "Error", - "code": -9999999 - }, - "Unable to open file {0}.": { - "category": "Error", - "code": -9999999 - }, - "Corrupted locale file {0}.": { - "category": "Error", - "code": -9999999 - }, - "No input files specified.": { - "category": "Error", - "code": -9999999 } } \ No newline at end of file diff --git a/src/compiler/tc.ts b/src/compiler/tc.ts index fc508ed459c..3baefd00ad0 100644 --- a/src/compiler/tc.ts +++ b/src/compiler/tc.ts @@ -78,19 +78,24 @@ module ts { return count; } - function reportDiagnostic(error: Diagnostic) { - if (error.file) { - var loc = error.file.getLineAndCharacterFromPosition(error.start); - sys.write(error.file.filename + "(" + loc.line + "," + loc.character + "): " + error.messageText + sys.newLine); + function getDiagnosticText(message: DiagnosticMessage, ...args: any[]): string { + var diagnostic: Diagnostic = createCompilerDiagnostic.apply(undefined, arguments); + return diagnostic.messageText; + } + + function reportDiagnostic(diagnostic: Diagnostic) { + if (diagnostic.file) { + var loc = diagnostic.file.getLineAndCharacterFromPosition(diagnostic.start); + sys.write(diagnostic.file.filename + "(" + loc.line + "," + loc.character + "): " + diagnostic.messageText + sys.newLine); } else { - sys.write(error.messageText + sys.newLine); + sys.write(diagnostic.messageText + sys.newLine); } } - function reportDiagnostics(errors: Diagnostic[]) { - for (var i = 0; i < errors.length; i++) { - reportDiagnostic(errors[i]); + function reportDiagnostics(diagnostics: Diagnostic[]) { + for (var i = 0; i < diagnostics.length; i++) { + reportDiagnostic(diagnostics[i]); } } @@ -179,29 +184,33 @@ module ts { } export function executeCommandLine(args: string[]): void { + var exitCode = 0; var commandLine = parseCommandLine(args); if (commandLine.options.locale) { validateLocaleAndSetLanguage(commandLine.options.locale, commandLine.errors); } + // Report all errors at this point, even if there are none. + if (commandLine.errors.length > 0) { + reportDiagnostics(commandLine.errors); + exitCode = 1; + } + if (commandLine.options.version) { reportDiagnostic(createCompilerDiagnostic(Diagnostics.Version_0, version)); - sys.exit(0); + sys.exit(exitCode); } - if (commandLine.options.help) { - // TODO (drosen): Usage. - sys.exit(0); + if (commandLine.options.help || commandLine.filenames.length === 0) { + printVersion(); + printHelp(); + sys.exit(exitCode); } - if (commandLine.filenames.length === 0) { - commandLine.errors.push(createCompilerDiagnostic(Diagnostics.No_input_files_specified)); - } - - if (commandLine.errors.length) { - reportDiagnostics(commandLine.errors); - sys.exit(1); + // If we encountered an error before we even started compiling, just bail out. + if (exitCode !== 0) { + sys.exit(exitCode); } var defaultCompilerHost = createCompilerHost(commandLine.options); @@ -338,6 +347,105 @@ module ts { return { program: program, errors: errors }; } + + function printVersion() { + sys.write(getDiagnosticText(Diagnostics.Version_0, version) + sys.newLine); + } + + function printHelp() { + var output = ""; + + // We want to align our "syntax" and "examples" commands to a certain margin. + var syntaxLength = getDiagnosticText(Diagnostics.Syntax_Colon_0, "").length + var examplesLength = getDiagnosticText(Diagnostics.Examples_Colon_0, "").length + var marginLength = Math.max(syntaxLength, examplesLength); + + // Build up the syntactic skeleton. + var syntax = makePadding(marginLength - syntaxLength); + syntax += "tsc [" + getDiagnosticText(Diagnostics.options) + "] [" + getDiagnosticText(Diagnostics.file) + " ...]"; + + output += getDiagnosticText(Diagnostics.Syntax_Colon_0, syntax); + output += sys.newLine + sys.newLine; + + // Build up the examples. + var padding = makePadding(marginLength); + output += getDiagnosticText(Diagnostics.Examples_Colon_0, makePadding(marginLength - examplesLength) + "tsc hello.ts") + sys.newLine; + output += padding + "tsc --out foo.js foo.ts" + sys.newLine; + output += padding + "tsc @args.txt" + sys.newLine; + output += sys.newLine; + + // Sort our options by their command names, (e.g. "--noImplicitAny" comes before "--watch") + output += getDiagnosticText(Diagnostics.Options_Colon) + sys.newLine; + + var optsList = optionDeclarations.slice().sort((a, b) => { + var aName = a.name.toLowerCase(); + var bName = b.name.toLowerCase(); + return compareValues(aName, bName); + }); + + // We want our descriptions to align at the same column in our output, + // so we keep track of the longest option usage string. + var marginLength = 0; + var usageColumn: string[] = []; // Things like "-d, --declaration" go in here. + var descriptionColumn: string[] = []; + + for (var i = 0; i < optsList.length; i++) { + var option = optsList[i]; + + // If an option lacks a description, + // it is not officially supported. + if (!option.description) { + continue; + } + + var usageText = " "; + if (option.shortName) { + usageText += "-" + option.shortName; + usageText += getParamName(option); + usageText += ", "; + } + + usageText += "--" + option.name; + usageText += getParamName(option); + + usageColumn.push(usageText); + descriptionColumn.push(getDiagnosticText(option.description)); + + // Set the new margin for the description column if necessary. + if (usageText.length > marginLength) { + marginLength = usageText.length; + } + } + + // Special case that can't fit in the loop. + var usageText = " @<" + getDiagnosticText(Diagnostics.file) + ">"; + usageColumn.push(usageText); + descriptionColumn.push(getDiagnosticText(Diagnostics.Insert_command_line_options_and_files_from_a_file)); + if (usageText.length > marginLength) { + marginLength = usageText.length; + } + + // Print out each row, aligning all the descriptions on the same column. + for (var i = 0; i < usageColumn.length; i++) { + var usage = usageColumn[i]; + var description = descriptionColumn[i]; + output += usage + makePadding(marginLength - usage.length + 2) + description + sys.newLine; + } + + sys.write(output); + return; + + function getParamName(option: CommandLineOption) { + if (option.paramName !== undefined) { + return " " + getDiagnosticText(option.paramName); + } + return ""; + } + + function makePadding(paddingLength: number): string { + return Array(paddingLength + 1).join(" "); + } + } } ts.executeCommandLine(sys.args); diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 316ae5410c0..3d5c176d272 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -953,7 +953,10 @@ module ts { export interface CommandLineOption { name: string; type: any; - error?: DiagnosticMessage; + shortName?: string; + description?: DiagnosticMessage; + paramName?: DiagnosticMessage; // The name to be used for a non-boolean option's parameter. + error?: DiagnosticMessage; // The error given when the argument does not fit a customized 'type'. } export enum CharacterCodes { From 0e76a820724cc2677d5f87a84ea5af711c77c597 Mon Sep 17 00:00:00 2001 From: Sheetal Nandi Date: Mon, 4 Aug 2014 12:06:07 -0700 Subject: [PATCH 07/15] Fix the incorrect error reporting and declaration file emit for the type parameter constraint of private methods Also incorporates code review feedback --- .../diagnosticInformationMap.generated.ts | 32 ++++----- src/compiler/diagnosticMessages.json | 32 ++++----- src/compiler/emitter.ts | 54 +++++++-------- ...TypeParameterOfFunctionDeclFile.errors.txt | 58 +++++++--------- ...cyTypeParametersOfClassDeclFile.errors.txt | 8 +-- ...peParametersOfInterfaceDeclFile.errors.txt | 8 +-- ...dWithTypeParameterExtendsClauseDeclFile.js | 66 +++++++++++++++++++ ...dWithTypeParameterExtendsClauseDeclFile.ts | 22 +++++++ 8 files changed, 181 insertions(+), 99 deletions(-) create mode 100644 tests/baselines/reference/staticMethodWithTypeParameterExtendsClauseDeclFile.js create mode 100644 tests/cases/compiler/staticMethodWithTypeParameterExtendsClauseDeclFile.ts diff --git a/src/compiler/diagnosticInformationMap.generated.ts b/src/compiler/diagnosticInformationMap.generated.ts index 2f5daae7ed4..c7c28f9e226 100644 --- a/src/compiler/diagnosticInformationMap.generated.ts +++ b/src/compiler/diagnosticInformationMap.generated.ts @@ -105,22 +105,22 @@ module ts { Extends_clause_of_exported_class_0_has_or_is_using_name_1_from_private_module_2: { code: 2021, category: DiagnosticCategory.Error, key: "Extends clause of exported class '{0}' has or is using name '{1}' from private module '{2}'." }, Implements_clause_of_exported_class_0_has_or_is_using_name_1_from_private_module_2: { code: 2022, category: DiagnosticCategory.Error, key: "Implements clause of exported class '{0}' has or is using name '{1}' from private module '{2}'." }, Extends_clause_of_exported_interface_0_has_or_is_using_name_1_from_private_module_2: { code: 2023, category: DiagnosticCategory.Error, key: "Extends clause of exported interface '{0}' has or is using name '{1}' from private module '{2}'." }, - TypeParameter_0_of_constructor_signature_from_exported_interface_has_or_is_using_private_name_1: { code: 2208, category: DiagnosticCategory.Error, key: "TypeParameter '{0}' of constructor signature from exported interface has or is using private name '{1}'." }, - TypeParameter_0_of_call_signature_from_exported_interface_has_or_is_using_private_name_1: { code: 2209, category: DiagnosticCategory.Error, key: "TypeParameter '{0}' of call signature from exported interface has or is using private name '{1}'." }, - TypeParameter_0_of_public_static_method_from_exported_class_has_or_is_using_private_name_1: { code: 2210, category: DiagnosticCategory.Error, key: "TypeParameter '{0}' of public static method from exported class has or is using private name '{1}'." }, - TypeParameter_0_of_public_method_from_exported_class_has_or_is_using_private_name_1: { code: 2211, category: DiagnosticCategory.Error, key: "TypeParameter '{0}' of public method from exported class has or is using private name '{1}'." }, - TypeParameter_0_of_method_from_exported_interface_has_or_is_using_private_name_1: { code: 2212, category: DiagnosticCategory.Error, key: "TypeParameter '{0}' of method from exported interface has or is using private name '{1}'." }, - TypeParameter_0_of_exported_function_has_or_is_using_private_name_1: { code: 2213, category: DiagnosticCategory.Error, key: "TypeParameter '{0}' of exported function has or is using private name '{1}'." }, - TypeParameter_0_of_constructor_signature_from_exported_interface_has_or_is_using_name_1_from_private_module_2: { code: 2214, category: DiagnosticCategory.Error, key: "TypeParameter '{0}' of constructor signature from exported interface has or is using name '{1}' from private module '{2}'." }, - TypeParameter_0_of_call_signature_from_exported_interface_has_or_is_using_name_1_from_private_module_2: { code: 2215, category: DiagnosticCategory.Error, key: "TypeParameter '{0}' of call signature from exported interface has or is using name '{1}' from private module '{2}'." }, - TypeParameter_0_of_public_static_method_from_exported_class_has_or_is_using_name_1_from_private_module_2: { code: 2216, category: DiagnosticCategory.Error, key: "TypeParameter '{0}' of public static method from exported class has or is using name '{1}' from private module '{2}'." }, - TypeParameter_0_of_public_method_from_exported_class_has_or_is_using_name_1_from_private_module_2: { code: 2217, category: DiagnosticCategory.Error, key: "TypeParameter '{0}' of public method from exported class has or is using name '{1}' from private module '{2}'." }, - TypeParameter_0_of_method_from_exported_interface_has_or_is_using_name_1_from_private_module_2: { code: 2218, category: DiagnosticCategory.Error, key: "TypeParameter '{0}' of method from exported interface has or is using name '{1}' from private module '{2}'." }, - TypeParameter_0_of_exported_function_has_or_is_using_name_1_from_private_module_2: { code: 2219, category: DiagnosticCategory.Error, key: "TypeParameter '{0}' of exported function has or is using name '{1}' from private module '{2}'." }, - TypeParameter_0_of_exported_class_has_or_is_using_private_name_1: { code: 2220, category: DiagnosticCategory.Error, key: "TypeParameter '{0}' of exported class has or is using private name '{1}'." }, - TypeParameter_0_of_exported_interface_has_or_is_using_private_name_1: { code: 2221, category: DiagnosticCategory.Error, key: "TypeParameter '{0}' of exported interface has or is using private name '{1}'." }, - TypeParameter_0_of_exported_class_has_or_is_using_name_1_from_private_module_2: { code: 2222, category: DiagnosticCategory.Error, key: "TypeParameter '{0}' of exported class has or is using name '{1}' from private module '{2}'." }, - TypeParameter_0_of_exported_interface_has_or_is_using_name_1_from_private_module_2: { code: 2223, category: DiagnosticCategory.Error, key: "TypeParameter '{0}' of exported interface has or is using name '{1}' from private module '{2}'." }, + 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}'." }, + Type_parameter_0_of_public_method_from_exported_class_has_or_is_using_private_name_1: { code: 2211, category: DiagnosticCategory.Error, key: "Type parameter '{0}' of public method from exported class has or is using private name '{1}'." }, + Type_parameter_0_of_method_from_exported_interface_has_or_is_using_private_name_1: { code: 2212, category: DiagnosticCategory.Error, key: "Type parameter '{0}' of method from exported interface has or is using private name '{1}'." }, + Type_parameter_0_of_exported_function_has_or_is_using_private_name_1: { code: 2213, category: DiagnosticCategory.Error, key: "Type parameter '{0}' of exported function has or is using private name '{1}'." }, + Type_parameter_0_of_constructor_signature_from_exported_interface_has_or_is_using_name_1_from_private_module_2: { code: 2214, category: DiagnosticCategory.Error, key: "Type parameter '{0}' of constructor signature from exported interface has or is using name '{1}' from private module '{2}'." }, + Type_parameter_0_of_call_signature_from_exported_interface_has_or_is_using_name_1_from_private_module_2: { code: 2215, category: DiagnosticCategory.Error, key: "Type parameter '{0}' of call signature from exported interface has or is using name '{1}' from private module '{2}'." }, + Type_parameter_0_of_public_static_method_from_exported_class_has_or_is_using_name_1_from_private_module_2: { code: 2216, category: DiagnosticCategory.Error, key: "Type parameter '{0}' of public static method from exported class has or is using name '{1}' from private module '{2}'." }, + Type_parameter_0_of_public_method_from_exported_class_has_or_is_using_name_1_from_private_module_2: { code: 2217, category: DiagnosticCategory.Error, key: "Type parameter '{0}' of public method from exported class has or is using name '{1}' from private module '{2}'." }, + Type_parameter_0_of_method_from_exported_interface_has_or_is_using_name_1_from_private_module_2: { code: 2218, category: DiagnosticCategory.Error, key: "Type parameter '{0}' of method from exported interface has or is using name '{1}' from private module '{2}'." }, + Type_parameter_0_of_exported_function_has_or_is_using_name_1_from_private_module_2: { code: 2219, category: DiagnosticCategory.Error, key: "Type parameter '{0}' of exported function has or is using name '{1}' from private module '{2}'." }, + Type_parameter_0_of_exported_class_has_or_is_using_private_name_1: { code: 2220, category: DiagnosticCategory.Error, key: "Type parameter '{0}' of exported class has or is using private name '{1}'." }, + Type_parameter_0_of_exported_interface_has_or_is_using_private_name_1: { code: 2221, category: DiagnosticCategory.Error, key: "Type parameter '{0}' of exported interface has or is using private name '{1}'." }, + Type_parameter_0_of_exported_class_has_or_is_using_name_1_from_private_module_2: { code: 2222, category: DiagnosticCategory.Error, key: "Type parameter '{0}' of exported class has or is using name '{1}' from private module '{2}'." }, + Type_parameter_0_of_exported_interface_has_or_is_using_name_1_from_private_module_2: { code: 2223, category: DiagnosticCategory.Error, key: "Type parameter '{0}' of exported interface has or is using name '{1}' from private module '{2}'." }, new_T_cannot_be_used_to_create_an_array_Use_new_Array_T_instead: { code: 2068, category: DiagnosticCategory.Error, key: "'new T[]' cannot be used to create an array. Use 'new Array()' instead." }, Multiple_constructor_implementations_are_not_allowed: { code: 2070, category: DiagnosticCategory.Error, key: "Multiple constructor implementations are not allowed." }, A_class_may_only_implement_another_class_or_interface: { code: 2074, category: DiagnosticCategory.Error, key: "A class may only implement another class or interface." }, diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index 1b1ccff36fd..e9637570794 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -414,67 +414,67 @@ "category": "Error", "code": 2023 }, - "TypeParameter '{0}' of constructor signature from exported interface has or is using private name '{1}'.": { + "Type parameter '{0}' of constructor signature from exported interface has or is using private name '{1}'.": { "category": "Error", "code": 2208 }, - "TypeParameter '{0}' of call 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}'.": { "category": "Error", "code": 2209 }, - "TypeParameter '{0}' of public static method from exported class has or is using private name '{1}'.": { + "Type parameter '{0}' of public static method from exported class has or is using private name '{1}'.": { "category": "Error", "code": 2210 }, - "TypeParameter '{0}' of public method from exported class has or is using private name '{1}'.": { + "Type parameter '{0}' of public method from exported class has or is using private name '{1}'.": { "category": "Error", "code": 2211 }, - "TypeParameter '{0}' of method from exported interface has or is using private name '{1}'.": { + "Type parameter '{0}' of method from exported interface has or is using private name '{1}'.": { "category": "Error", "code": 2212 }, - "TypeParameter '{0}' of exported function has or is using private name '{1}'.": { + "Type parameter '{0}' of exported function has or is using private name '{1}'.": { "category": "Error", "code": 2213 }, - "TypeParameter '{0}' of constructor signature from exported interface has or is using name '{1}' from private module '{2}'.": { + "Type parameter '{0}' of constructor signature from exported interface has or is using name '{1}' from private module '{2}'.": { "category": "Error", "code": 2214 }, - "TypeParameter '{0}' of call signature from exported interface has or is using name '{1}' from private module '{2}'.": { + "Type parameter '{0}' of call signature from exported interface has or is using name '{1}' from private module '{2}'.": { "category": "Error", "code": 2215 }, - "TypeParameter '{0}' of public static method from exported class has or is using name '{1}' from private module '{2}'.": { + "Type parameter '{0}' of public static method from exported class has or is using name '{1}' from private module '{2}'.": { "category": "Error", "code": 2216 }, - "TypeParameter '{0}' of public method from exported class has or is using name '{1}' from private module '{2}'.": { + "Type parameter '{0}' of public method from exported class has or is using name '{1}' from private module '{2}'.": { "category": "Error", "code": 2217 }, - "TypeParameter '{0}' of method from exported interface has or is using name '{1}' from private module '{2}'.": { + "Type parameter '{0}' of method from exported interface has or is using name '{1}' from private module '{2}'.": { "category": "Error", "code": 2218 }, - "TypeParameter '{0}' of exported function has or is using name '{1}' from private module '{2}'.": { + "Type parameter '{0}' of exported function has or is using name '{1}' from private module '{2}'.": { "category": "Error", "code": 2219 }, - "TypeParameter '{0}' of exported class has or is using private name '{1}'.": { + "Type parameter '{0}' of exported class has or is using private name '{1}'.": { "category": "Error", "code": 2220 }, - "TypeParameter '{0}' of exported interface has or is using private name '{1}'.": { + "Type parameter '{0}' of exported interface has or is using private name '{1}'.": { "category": "Error", "code": 2221 }, - "TypeParameter '{0}' of exported class has or is using name '{1}' from private module '{2}'.": { + "Type parameter '{0}' of exported class has or is using name '{1}' from private module '{2}'.": { "category": "Error", "code": 2222 }, - "TypeParameter '{0}' of exported interface has or is using name '{1}' from private module '{2}'.": { + "Type parameter '{0}' of exported interface has or is using name '{1}' from private module '{2}'.": { "category": "Error", "code": 2223 }, diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index 4169d48e0b1..6052e5c3ba0 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -2017,50 +2017,50 @@ module ts { switch (node.parent.kind) { case SyntaxKind.ClassDeclaration: diagnosticMessage = symbolAccesibilityResult.errorModuleName ? - Diagnostics.TypeParameter_0_of_exported_class_has_or_is_using_name_1_from_private_module_2 : - Diagnostics.TypeParameter_0_of_exported_class_has_or_is_using_private_name_1; + Diagnostics.Type_parameter_0_of_exported_class_has_or_is_using_name_1_from_private_module_2 : + Diagnostics.Type_parameter_0_of_exported_class_has_or_is_using_private_name_1; break; case SyntaxKind.InterfaceDeclaration: diagnosticMessage = symbolAccesibilityResult.errorModuleName ? - Diagnostics.TypeParameter_0_of_exported_interface_has_or_is_using_name_1_from_private_module_2 : - Diagnostics.TypeParameter_0_of_exported_interface_has_or_is_using_private_name_1; + Diagnostics.Type_parameter_0_of_exported_interface_has_or_is_using_name_1_from_private_module_2 : + Diagnostics.Type_parameter_0_of_exported_interface_has_or_is_using_private_name_1; break; case SyntaxKind.ConstructSignature: diagnosticMessage = symbolAccesibilityResult.errorModuleName ? - Diagnostics.TypeParameter_0_of_constructor_signature_from_exported_interface_has_or_is_using_name_1_from_private_module_2 : - Diagnostics.TypeParameter_0_of_constructor_signature_from_exported_interface_has_or_is_using_private_name_1; + Diagnostics.Type_parameter_0_of_constructor_signature_from_exported_interface_has_or_is_using_name_1_from_private_module_2 : + Diagnostics.Type_parameter_0_of_constructor_signature_from_exported_interface_has_or_is_using_private_name_1; break; case SyntaxKind.CallSignature: diagnosticMessage = symbolAccesibilityResult.errorModuleName ? - Diagnostics.TypeParameter_0_of_call_signature_from_exported_interface_has_or_is_using_name_1_from_private_module_2 : - Diagnostics.TypeParameter_0_of_call_signature_from_exported_interface_has_or_is_using_private_name_1; + Diagnostics.Type_parameter_0_of_call_signature_from_exported_interface_has_or_is_using_name_1_from_private_module_2 : + Diagnostics.Type_parameter_0_of_call_signature_from_exported_interface_has_or_is_using_private_name_1; break; case SyntaxKind.Method: if (node.parent.flags & NodeFlags.Static) { diagnosticMessage = symbolAccesibilityResult.errorModuleName ? - Diagnostics.TypeParameter_0_of_public_static_method_from_exported_class_has_or_is_using_name_1_from_private_module_2 : - Diagnostics.TypeParameter_0_of_public_static_method_from_exported_class_has_or_is_using_private_name_1; + Diagnostics.Type_parameter_0_of_public_static_method_from_exported_class_has_or_is_using_name_1_from_private_module_2 : + Diagnostics.Type_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 ? - Diagnostics.TypeParameter_0_of_public_method_from_exported_class_has_or_is_using_name_1_from_private_module_2 : - Diagnostics.TypeParameter_0_of_public_method_from_exported_class_has_or_is_using_private_name_1; + Diagnostics.Type_parameter_0_of_public_method_from_exported_class_has_or_is_using_name_1_from_private_module_2 : + Diagnostics.Type_parameter_0_of_public_method_from_exported_class_has_or_is_using_private_name_1; } else { diagnosticMessage = symbolAccesibilityResult.errorModuleName ? - Diagnostics.TypeParameter_0_of_method_from_exported_interface_has_or_is_using_name_1_from_private_module_2 : - Diagnostics.TypeParameter_0_of_method_from_exported_interface_has_or_is_using_private_name_1; + Diagnostics.Type_parameter_0_of_method_from_exported_interface_has_or_is_using_name_1_from_private_module_2 : + Diagnostics.Type_parameter_0_of_method_from_exported_interface_has_or_is_using_private_name_1; } break; case SyntaxKind.FunctionDeclaration: diagnosticMessage = symbolAccesibilityResult.errorModuleName ? - Diagnostics.TypeParameter_0_of_exported_function_has_or_is_using_name_1_from_private_module_2 : - Diagnostics.TypeParameter_0_of_exported_function_has_or_is_using_private_name_1; + Diagnostics.Type_parameter_0_of_exported_function_has_or_is_using_name_1_from_private_module_2 : + Diagnostics.Type_parameter_0_of_exported_function_has_or_is_using_private_name_1; break; default: @@ -2075,7 +2075,8 @@ module ts { } emitSourceTextOfNode(node.name); - if (node.constraint) { + // If there is constraint present and this is not a type parameter of the private method emit the constraint + 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); @@ -2092,7 +2093,17 @@ module ts { } function emitHeritageClause(typeReferences: TypeReferenceNode[], isImplementsList: boolean) { + if (typeReferences) { + write(isImplementsList ? " implements " : " extends "); + emitCommaList(typeReferences, emitTypeOfTypeReference); + } + function emitTypeOfTypeReference(node: Node) { + getSymbolVisibilityDiagnosticMessage = getHeritageClauseVisibilityError; + resolver.writeTypeAtLocation(node, enclosingDeclaration, TypeFormatFlags.WriteArrayAsGenericType, writer); + // TODO(shkamat) This is just till we get rest of the error reporting up + getSymbolVisibilityDiagnosticMessage = undefined; + function getHeritageClauseVisibilityError(symbolAccesibilityResult: SymbolAccessiblityResult) { var diagnosticMessage: DiagnosticMessage; if (node.parent.kind === SyntaxKind.ClassDeclaration) { @@ -2140,15 +2151,6 @@ module ts { typeName: (node.parent).name } } - getSymbolVisibilityDiagnosticMessage = getHeritageClauseVisibilityError; - resolver.writeTypeAtLocation(node, enclosingDeclaration, TypeFormatFlags.WriteArrayAsGenericType, writer); - // TODO(shkamat) This is just till we get rest of the error reporting up - getSymbolVisibilityDiagnosticMessage = undefined; - } - - if (typeReferences) { - write(isImplementsList ? " implements " : " extends "); - emitCommaList(typeReferences, emitTypeOfTypeReference); } } diff --git a/tests/baselines/reference/privacyTypeParameterOfFunctionDeclFile.errors.txt b/tests/baselines/reference/privacyTypeParameterOfFunctionDeclFile.errors.txt index ccb7be1e181..8e892e57dee 100644 --- a/tests/baselines/reference/privacyTypeParameterOfFunctionDeclFile.errors.txt +++ b/tests/baselines/reference/privacyTypeParameterOfFunctionDeclFile.errors.txt @@ -1,4 +1,4 @@ -==== tests/cases/compiler/privacyTypeParameterOfFunctionDeclFile.ts (28 errors) ==== +==== tests/cases/compiler/privacyTypeParameterOfFunctionDeclFile.ts (24 errors) ==== class privateClass { } @@ -8,13 +8,13 @@ export interface publicInterfaceWithPrivateTypeParameters { new (): privateClass; // Error ~~~~~~~~~~~~~~~~~~~~~~ -!!! TypeParameter 'T' of constructor signature from exported interface has or is using private name 'privateClass'. +!!! Type parameter 'T' of constructor signature from exported interface has or is using private name 'privateClass'. (): privateClass; // Error ~~~~~~~~~~~~~~~~~~~~~~ -!!! TypeParameter 'T' of call signature from exported interface has or is using private name 'privateClass'. +!!! Type parameter 'T' of call signature from exported interface has or is using private name 'privateClass'. myMethod(): privateClass; // Error ~~~~~~~~~~~~~~~~~~~~~~ -!!! TypeParameter 'T' of method from exported interface has or is using private name 'privateClass'. +!!! Type parameter 'T' of method from exported interface has or is using private name 'privateClass'. } export interface publicInterfaceWithPublicTypeParameters { @@ -38,19 +38,15 @@ export class publicClassWithWithPrivateTypeParameters { static myPublicStaticMethod() { // Error ~~~~~~~~~~~~~~~~~~~~~~ -!!! TypeParameter 'T' of public static method from exported class has or is using private name 'privateClass'. +!!! Type parameter 'T' of public static method from exported class has or is using private name 'privateClass'. } private static myPrivateStaticMethod() { - ~~~~~~~~~~~~~~~~~~~~~~ -!!! TypeParameter 'T' of public static method from exported class has or is using private name 'privateClass'. } myPublicMethod() { // Error ~~~~~~~~~~~~~~~~~~~~~~ -!!! TypeParameter 'T' of public method from exported class has or is using private name 'privateClass'. +!!! Type parameter 'T' of public method from exported class has or is using private name 'privateClass'. } private myPrivateMethod() { - ~~~~~~~~~~~~~~~~~~~~~~ -!!! TypeParameter 'T' of public method from exported class has or is using private name 'privateClass'. } } @@ -89,7 +85,7 @@ export function publicFunctionWithPrivateTypeParameters() { // Error ~~~~~~~~~~~~~~~~~~~~~~ -!!! TypeParameter 'T' of exported function has or is using private name 'privateClass'. +!!! Type parameter 'T' of exported function has or is using private name 'privateClass'. } export function publicFunctionWithPublicTypeParameters() { @@ -143,27 +139,27 @@ export interface publicInterfaceWithPrivatModuleTypeParameters { new (): privateModule.publicClass; // Error ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! TypeParameter 'T' of constructor signature from exported interface has or is using name 'privateModule.publicClass' from private module 'privateModule'. +!!! Type parameter 'T' of constructor signature from exported interface has or is using name 'privateModule.publicClass' from private module 'privateModule'. (): privateModule.publicClass; // Error ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! TypeParameter 'T' of call signature from exported interface has or is using name 'privateModule.publicClass' from private module 'privateModule'. +!!! Type parameter 'T' of call signature from exported interface has or is using name 'privateModule.publicClass' from private module 'privateModule'. myMethod(): privateModule.publicClass; // Error ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! TypeParameter 'T' of method from exported interface has or is using name 'privateModule.publicClass' from private module 'privateModule'. +!!! Type parameter 'T' of method from exported interface has or is using name 'privateModule.publicClass' from private module 'privateModule'. } export class publicClassWithWithPrivateModuleTypeParameters { static myPublicStaticMethod() { // Error ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! TypeParameter 'T' of public static method from exported class has or is using name 'privateModule.publicClass' from private module 'privateModule'. +!!! Type parameter 'T' of public static method from exported class has or is using name 'privateModule.publicClass' from private module 'privateModule'. } myPublicMethod() { // Error ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! TypeParameter 'T' of public method from exported class has or is using name 'privateModule.publicClass' from private module 'privateModule'. +!!! Type parameter 'T' of public method from exported class has or is using name 'privateModule.publicClass' from private module 'privateModule'. } } export function publicFunctionWithPrivateMopduleTypeParameters() { // Error ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! TypeParameter 'T' of exported function has or is using name 'privateModule.publicClass' from private module 'privateModule'. +!!! Type parameter 'T' of exported function has or is using name 'privateModule.publicClass' from private module 'privateModule'. } @@ -192,13 +188,13 @@ export interface publicInterfaceWithPrivateTypeParameters { new (): privateClass; // Error ~~~~~~~~~~~~~~~~~~~~~~ -!!! TypeParameter 'T' of constructor signature from exported interface has or is using private name 'privateClass'. +!!! Type parameter 'T' of constructor signature from exported interface has or is using private name 'privateClass'. (): privateClass; // Error ~~~~~~~~~~~~~~~~~~~~~~ -!!! TypeParameter 'T' of call signature from exported interface has or is using private name 'privateClass'. +!!! Type parameter 'T' of call signature from exported interface has or is using private name 'privateClass'. myMethod(): privateClass; // Error ~~~~~~~~~~~~~~~~~~~~~~ -!!! TypeParameter 'T' of method from exported interface has or is using private name 'privateClass'. +!!! Type parameter 'T' of method from exported interface has or is using private name 'privateClass'. } export interface publicInterfaceWithPublicTypeParameters { @@ -222,19 +218,15 @@ export class publicClassWithWithPrivateTypeParameters { static myPublicStaticMethod() { // Error ~~~~~~~~~~~~~~~~~~~~~~ -!!! TypeParameter 'T' of public static method from exported class has or is using private name 'privateClass'. +!!! Type parameter 'T' of public static method from exported class has or is using private name 'privateClass'. } private static myPrivateStaticMethod() { - ~~~~~~~~~~~~~~~~~~~~~~ -!!! TypeParameter 'T' of public static method from exported class has or is using private name 'privateClass'. } myPublicMethod() { // Error ~~~~~~~~~~~~~~~~~~~~~~ -!!! TypeParameter 'T' of public method from exported class has or is using private name 'privateClass'. +!!! Type parameter 'T' of public method from exported class has or is using private name 'privateClass'. } private myPrivateMethod() { - ~~~~~~~~~~~~~~~~~~~~~~ -!!! TypeParameter 'T' of public method from exported class has or is using private name 'privateClass'. } } @@ -273,7 +265,7 @@ export function publicFunctionWithPrivateTypeParameters() { // Error ~~~~~~~~~~~~~~~~~~~~~~ -!!! TypeParameter 'T' of exported function has or is using private name 'privateClass'. +!!! Type parameter 'T' of exported function has or is using private name 'privateClass'. } export function publicFunctionWithPublicTypeParameters() { @@ -327,27 +319,27 @@ export interface publicInterfaceWithPrivatModuleTypeParameters { new (): privateModule.publicClass; // Error ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! TypeParameter 'T' of constructor signature from exported interface has or is using name 'privateModule.publicClass' from private module 'privateModule'. +!!! Type parameter 'T' of constructor signature from exported interface has or is using name 'privateModule.publicClass' from private module 'privateModule'. (): privateModule.publicClass; // Error ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! TypeParameter 'T' of call signature from exported interface has or is using name 'privateModule.publicClass' from private module 'privateModule'. +!!! Type parameter 'T' of call signature from exported interface has or is using name 'privateModule.publicClass' from private module 'privateModule'. myMethod(): privateModule.publicClass; // Error ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! TypeParameter 'T' of method from exported interface has or is using name 'privateModule.publicClass' from private module 'privateModule'. +!!! Type parameter 'T' of method from exported interface has or is using name 'privateModule.publicClass' from private module 'privateModule'. } export class publicClassWithWithPrivateModuleTypeParameters { static myPublicStaticMethod() { // Error ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! TypeParameter 'T' of public static method from exported class has or is using name 'privateModule.publicClass' from private module 'privateModule'. +!!! Type parameter 'T' of public static method from exported class has or is using name 'privateModule.publicClass' from private module 'privateModule'. } myPublicMethod() { // Error ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! TypeParameter 'T' of public method from exported class has or is using name 'privateModule.publicClass' from private module 'privateModule'. +!!! Type parameter 'T' of public method from exported class has or is using name 'privateModule.publicClass' from private module 'privateModule'. } } export function publicFunctionWithPrivateMopduleTypeParameters() { // Error ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! TypeParameter 'T' of exported function has or is using name 'privateModule.publicClass' from private module 'privateModule'. +!!! Type parameter 'T' of exported function has or is using name 'privateModule.publicClass' from private module 'privateModule'. } diff --git a/tests/baselines/reference/privacyTypeParametersOfClassDeclFile.errors.txt b/tests/baselines/reference/privacyTypeParametersOfClassDeclFile.errors.txt index fd9386f9b13..b413b671f40 100644 --- a/tests/baselines/reference/privacyTypeParametersOfClassDeclFile.errors.txt +++ b/tests/baselines/reference/privacyTypeParametersOfClassDeclFile.errors.txt @@ -7,7 +7,7 @@ export class publicClassWithPrivateTypeParameters { // Error ~~~~~~~~~~~~~~~~~~~~~~ -!!! TypeParameter 'T' of exported class has or is using private name 'privateClass'. +!!! Type parameter 'T' of exported class has or is using private name 'privateClass'. myMethod(val: T): T { return val; } @@ -45,7 +45,7 @@ export class publicClassWithTypeParametersFromPrivateModule { // Error ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! TypeParameter 'T' of exported class has or is using name 'privateModule.publicClassInPrivateModule' from private module 'privateModule'. +!!! Type parameter 'T' of exported class has or is using name 'privateModule.publicClassInPrivateModule' from private module 'privateModule'. myMethod(val: T): T { return val; } @@ -66,7 +66,7 @@ export class publicClassWithPrivateTypeParameters { // Error ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! TypeParameter 'T' of exported class has or is using private name 'privateClassInPublicModule'. +!!! Type parameter 'T' of exported class has or is using private name 'privateClassInPublicModule'. myMethod(val: T): T { return val; } @@ -104,7 +104,7 @@ export class publicClassWithTypeParametersFromPrivateModule { // Error ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! TypeParameter 'T' of exported class has or is using name 'privateModule.publicClassInPrivateModule' from private module 'privateModule'. +!!! Type parameter 'T' of exported class has or is using name 'privateModule.publicClassInPrivateModule' from private module 'privateModule'. myMethod(val: T): T { return val; } diff --git a/tests/baselines/reference/privacyTypeParametersOfInterfaceDeclFile.errors.txt b/tests/baselines/reference/privacyTypeParametersOfInterfaceDeclFile.errors.txt index 090ca91836d..92aa57bcef1 100644 --- a/tests/baselines/reference/privacyTypeParametersOfInterfaceDeclFile.errors.txt +++ b/tests/baselines/reference/privacyTypeParametersOfInterfaceDeclFile.errors.txt @@ -13,7 +13,7 @@ export interface publicInterfaceWithPrivateTypeParameters { // Error ~~~~~~~~~~~~~~~~~~~~~~ -!!! TypeParameter 'T' of exported interface has or is using private name 'privateClass'. +!!! Type parameter 'T' of exported interface has or is using private name 'privateClass'. myMethod(val: T): T; myMethod0(): publicClassT; myMethod1(): privateClassT; @@ -62,7 +62,7 @@ export interface publicInterfaceWithPrivateModuleTypeParameterConstraints { // Error ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! TypeParameter 'T' of exported interface has or is using name 'privateModule.publicClassInPrivateModule' from private module 'privateModule'. +!!! Type parameter 'T' of exported interface has or is using name 'privateModule.publicClassInPrivateModule' from private module 'privateModule'. } interface privateInterfaceWithPrivateModuleTypeParameterConstraints { // Error @@ -83,7 +83,7 @@ export interface publicInterfaceWithPrivateTypeParameters { // Error ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! TypeParameter 'T' of exported interface has or is using private name 'privateClassInPublicModule'. +!!! Type parameter 'T' of exported interface has or is using private name 'privateClassInPublicModule'. myMethod(val: T): T; myMethod0(): publicClassInPublicModuleT; myMethod1(): privateClassInPublicModuleT; @@ -131,7 +131,7 @@ export interface publicInterfaceWithPrivateModuleTypeParameterConstraints { // Error ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! TypeParameter 'T' of exported interface has or is using name 'privateModule.publicClassInPrivateModule' from private module 'privateModule'. +!!! Type parameter 'T' of exported interface has or is using name 'privateModule.publicClassInPrivateModule' from private module 'privateModule'. } interface privateInterfaceWithPrivateModuleTypeParameterConstraints { // Error diff --git a/tests/baselines/reference/staticMethodWithTypeParameterExtendsClauseDeclFile.js b/tests/baselines/reference/staticMethodWithTypeParameterExtendsClauseDeclFile.js new file mode 100644 index 00000000000..ba2ca1ae758 --- /dev/null +++ b/tests/baselines/reference/staticMethodWithTypeParameterExtendsClauseDeclFile.js @@ -0,0 +1,66 @@ +//// [staticMethodWithTypeParameterExtendsClauseDeclFile.ts] +class privateClass { +} + +export class publicClass { +} + +export class publicClassWithWithPrivateTypeParameters { + private static myPrivateStaticMethod1() { // do not emit extends clause + } + private myPrivateMethod1() { // do not emit extends clause + } + private static myPrivateStaticMethod2() { // do not emit extends clause + } + private myPrivateMethod2() { // do not emit extends clause + } + public static myPublicStaticMethod() { + } + public myPublicMethod() { + } +} + + +//// [staticMethodWithTypeParameterExtendsClauseDeclFile.js] +var privateClass = (function () { + function privateClass() { + } + return privateClass; +})(); +var publicClass = (function () { + function publicClass() { + } + return publicClass; +})(); +exports.publicClass = publicClass; +var publicClassWithWithPrivateTypeParameters = (function () { + function publicClassWithWithPrivateTypeParameters() { + } + publicClassWithWithPrivateTypeParameters.myPrivateStaticMethod1 = function () { + }; + publicClassWithWithPrivateTypeParameters.prototype.myPrivateMethod1 = function () { + }; + publicClassWithWithPrivateTypeParameters.myPrivateStaticMethod2 = function () { + }; + publicClassWithWithPrivateTypeParameters.prototype.myPrivateMethod2 = function () { + }; + publicClassWithWithPrivateTypeParameters.myPublicStaticMethod = function () { + }; + publicClassWithWithPrivateTypeParameters.prototype.myPublicMethod = function () { + }; + return publicClassWithWithPrivateTypeParameters; +})(); +exports.publicClassWithWithPrivateTypeParameters = publicClassWithWithPrivateTypeParameters; + + +//// [staticMethodWithTypeParameterExtendsClauseDeclFile.d.ts] +export declare class publicClass { +} +export declare class publicClassWithWithPrivateTypeParameters { + private static myPrivateStaticMethod1(); + private myPrivateMethod1(); + private static myPrivateStaticMethod2(); + private myPrivateMethod2(); + static myPublicStaticMethod(): void; + myPublicMethod(): void; +} diff --git a/tests/cases/compiler/staticMethodWithTypeParameterExtendsClauseDeclFile.ts b/tests/cases/compiler/staticMethodWithTypeParameterExtendsClauseDeclFile.ts new file mode 100644 index 00000000000..48d31d92870 --- /dev/null +++ b/tests/cases/compiler/staticMethodWithTypeParameterExtendsClauseDeclFile.ts @@ -0,0 +1,22 @@ +// @module: commonjs +// @declaration: true +class privateClass { +} + +export class publicClass { +} + +export class publicClassWithWithPrivateTypeParameters { + private static myPrivateStaticMethod1() { // do not emit extends clause + } + private myPrivateMethod1() { // do not emit extends clause + } + private static myPrivateStaticMethod2() { // do not emit extends clause + } + private myPrivateMethod2() { // do not emit extends clause + } + public static myPublicStaticMethod() { + } + public myPublicMethod() { + } +} From e05e7836e3fd97398c4ad66514d3494506e048cd Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Mon, 4 Aug 2014 12:01:27 -0700 Subject: [PATCH 08/15] Style and comments. --- src/compiler/tc.ts | 19 +++++++++---------- src/compiler/types.ts | 10 +++++----- 2 files changed, 14 insertions(+), 15 deletions(-) diff --git a/src/compiler/tc.ts b/src/compiler/tc.ts index 3baefd00ad0..d38aca5a055 100644 --- a/src/compiler/tc.ts +++ b/src/compiler/tc.ts @@ -9,10 +9,12 @@ /// module ts { - export var version = "1.1.0.0"; + var version = "1.1.0.0"; - /// Checks to see if the locale is in the appropriate format, - /// and if it is, attempt to set the appropriate language. + /** + * Checks to see if the locale is in the appropriate format, + * and if it is, attempts to set the appropriate language. + */ function validateLocaleAndSetLanguage(locale: string, errors: Diagnostic[]): boolean { var matchResult = /^([a-z]+)([_\-]([a-z]+))?$/.exec(locale.toLowerCase()); @@ -367,21 +369,18 @@ module ts { output += getDiagnosticText(Diagnostics.Syntax_Colon_0, syntax); output += sys.newLine + sys.newLine; - // Build up the examples. + // Build up the list of examples. var padding = makePadding(marginLength); output += getDiagnosticText(Diagnostics.Examples_Colon_0, makePadding(marginLength - examplesLength) + "tsc hello.ts") + sys.newLine; output += padding + "tsc --out foo.js foo.ts" + sys.newLine; output += padding + "tsc @args.txt" + sys.newLine; output += sys.newLine; - // Sort our options by their command names, (e.g. "--noImplicitAny" comes before "--watch") output += getDiagnosticText(Diagnostics.Options_Colon) + sys.newLine; - var optsList = optionDeclarations.slice().sort((a, b) => { - var aName = a.name.toLowerCase(); - var bName = b.name.toLowerCase(); - return compareValues(aName, bName); - }); + // Sort our options by their names, (e.g. "--noImplicitAny" comes before "--watch") + var optsList = optionDeclarations.slice(); + optsList.sort((a, b) => compareValues(a.name.toLowerCase(), b.name.toLowerCase())); // We want our descriptions to align at the same column in our output, // so we keep track of the longest option usage string. diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 3d5c176d272..6ff7bfc3586 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -952,11 +952,11 @@ module ts { export interface CommandLineOption { name: string; - type: any; - shortName?: string; - description?: DiagnosticMessage; - paramName?: DiagnosticMessage; // The name to be used for a non-boolean option's parameter. - error?: DiagnosticMessage; // The error given when the argument does not fit a customized 'type'. + type: any; // "string", "number", "boolean", or an object literal mapping named values to actual values + shortName?: string; // A short pneumonic for convenience - for instance, 'h' can be used in place of 'help'. + description?: DiagnosticMessage; // The message describing what the command line switch does + paramName?: DiagnosticMessage; // The name to be used for a non-boolean option's parameter. + error?: DiagnosticMessage; // The error given when the argument does not fit a customized 'type'. } export enum CharacterCodes { From a64db42337afc44f9893ef22ff326cee19a905bf Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Mon, 4 Aug 2014 12:28:46 -0700 Subject: [PATCH 09/15] Got rid of that cscript-breaking comma. --- src/compiler/commandLineParser.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/compiler/commandLineParser.ts b/src/compiler/commandLineParser.ts index 8d0f977dddb..25d304bda7f 100644 --- a/src/compiler/commandLineParser.ts +++ b/src/compiler/commandLineParser.ts @@ -114,7 +114,7 @@ module ts { shortName: "w", type: "boolean", description: Diagnostics.Watch_input_files, - }, + } ]; var shortOptionNames: Map = {}; From 348d0fca21cb8832ebdcb3f45cd4f3a596777f94 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Mon, 4 Aug 2014 17:52:58 -0700 Subject: [PATCH 10/15] Addressed code review feedback. --- scripts/processDiagnosticMessages.ts | 24 +++++++++++++++--------- src/compiler/tc.ts | 23 +++++++---------------- 2 files changed, 22 insertions(+), 25 deletions(-) diff --git a/scripts/processDiagnosticMessages.ts b/scripts/processDiagnosticMessages.ts index 31449c88e3a..6a4aaad9f93 100644 --- a/scripts/processDiagnosticMessages.ts +++ b/scripts/processDiagnosticMessages.ts @@ -39,7 +39,7 @@ function main(): void { function buildUniqueNameMap(names: string[]): IIndexable { var nameMap: IIndexable = {}; - var uniqueNames = NameGenerator.ensureUniqueness(names, /*isFixed */ undefined, /* isCaseSensitive */ false); + var uniqueNames = NameGenerator.ensureUniqueness(names, /* isCaseSensitive */ false, /* isFixed */ undefined); for (var i = 0; i < names.length; i++) { nameMap[names[i]] = uniqueNames[i]; @@ -94,14 +94,17 @@ function convertPropertyName(origName: string): string { } module NameGenerator { - export function ensureUniqueness(names: string[], isFixed: boolean[] = names.map(() => false), isCaseSensitive: boolean = false): string[] { + export function ensureUniqueness(names: string[], isCaseSensitive: boolean, isFixed?: boolean[]): string[]{ + if (!isFixed) { + isFixed = names.map(() => false) + } - var names = names.map(x => x); - ensureUniquenessInPlace(names, isFixed, isCaseSensitive); + var names = names.slice(); + ensureUniquenessInPlace(names, isCaseSensitive, isFixed); return names; } - function ensureUniquenessInPlace(names: string[], isFixed: boolean[], isCaseSensitive: boolean): void { + function ensureUniquenessInPlace(names: string[], isCaseSensitive: boolean, isFixed: boolean[]): void { for (var i = 0; i < names.length; i++) { var name = names[i]; var collisionIndices = Utilities.collectMatchingIndices(name, names, isCaseSensitive); @@ -128,9 +131,12 @@ module NameGenerator { } while (true) { - var newName = name + suffix++; + var newName = name + suffix; + suffix++; - if (!proposedNames.some((name) => Utilities.stringEquals(name, newName, isCaseSensitive))) { + // Check if we've synthesized a unique name, and if so + // replace the conflicting name with the new one. + if (!proposedNames.some(name => Utilities.stringEquals(name, newName, isCaseSensitive))) { proposedNames[collisionIndex] = newName; break; } @@ -141,7 +147,7 @@ module NameGenerator { module Utilities { /// Return a list of all indices where a string occurs. - export function collectMatchingIndices(name: string, proposedNames: string[], isCaseSensitive: boolean = false): number[] { + export function collectMatchingIndices(name: string, proposedNames: string[], isCaseSensitive: boolean): number[] { var matchingIndices: number[] = []; for (var i = 0; i < proposedNames.length; i++) { @@ -153,7 +159,7 @@ module Utilities { return matchingIndices; } - export function stringEquals(s1: string, s2: string, caseSensitive: boolean = false): boolean { + export function stringEquals(s1: string, s2: string, caseSensitive: boolean): boolean { if (caseSensitive) { s1 = s1.toLowerCase(); s2 = s2.toLowerCase(); diff --git a/src/compiler/tc.ts b/src/compiler/tc.ts index d38aca5a055..614a20aa21a 100644 --- a/src/compiler/tc.ts +++ b/src/compiler/tc.ts @@ -186,33 +186,28 @@ module ts { } export function executeCommandLine(args: string[]): void { - var exitCode = 0; var commandLine = parseCommandLine(args); if (commandLine.options.locale) { validateLocaleAndSetLanguage(commandLine.options.locale, commandLine.errors); } - // Report all errors at this point, even if there are none. + // If there are any errors due to command line parsing and/or + // setting up localization, report them and quit. if (commandLine.errors.length > 0) { reportDiagnostics(commandLine.errors); - exitCode = 1; + sys.exit(1); } if (commandLine.options.version) { reportDiagnostic(createCompilerDiagnostic(Diagnostics.Version_0, version)); - sys.exit(exitCode); + sys.exit(0); } if (commandLine.options.help || commandLine.filenames.length === 0) { printVersion(); printHelp(); - sys.exit(exitCode); - } - - // If we encountered an error before we even started compiling, just bail out. - if (exitCode !== 0) { - sys.exit(exitCode); + sys.exit(0); } var defaultCompilerHost = createCompilerHost(commandLine.options); @@ -411,18 +406,14 @@ module ts { descriptionColumn.push(getDiagnosticText(option.description)); // Set the new margin for the description column if necessary. - if (usageText.length > marginLength) { - marginLength = usageText.length; - } + marginLength = Math.max(usageText.length, marginLength); } // Special case that can't fit in the loop. var usageText = " @<" + getDiagnosticText(Diagnostics.file) + ">"; usageColumn.push(usageText); descriptionColumn.push(getDiagnosticText(Diagnostics.Insert_command_line_options_and_files_from_a_file)); - if (usageText.length > marginLength) { - marginLength = usageText.length; - } + marginLength = Math.max(usageText.length, marginLength); // Print out each row, aligning all the descriptions on the same column. for (var i = 0; i < usageColumn.length; i++) { From a1a1ea3f96188eb4ad63a1a0cffb626af1720ee6 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Mon, 4 Aug 2014 18:00:33 -0700 Subject: [PATCH 11/15] Fixed up duplicate diagnostic. --- src/compiler/diagnosticInformationMap.generated.ts | 2 +- src/compiler/diagnosticMessages.json | 5 +---- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/src/compiler/diagnosticInformationMap.generated.ts b/src/compiler/diagnosticInformationMap.generated.ts index 0299cbe846d..b29bbf7f3b2 100644 --- a/src/compiler/diagnosticInformationMap.generated.ts +++ b/src/compiler/diagnosticInformationMap.generated.ts @@ -235,8 +235,8 @@ module ts { file: { code: 6025, category: DiagnosticCategory.Message, key: "file" }, Examples_Colon_0: { code: 6026, category: DiagnosticCategory.Message, key: "Examples: {0}" }, Options_Colon: { code: 6027, category: DiagnosticCategory.Message, key: "Options:" }, - Insert_command_line_options_and_files_from_a_file: { code: 6030, category: DiagnosticCategory.Message, key: "Insert command line options and files from a file." }, Version_0: { code: 6029, category: DiagnosticCategory.Message, key: "Version {0}" }, + Insert_command_line_options_and_files_from_a_file: { code: 6030, category: DiagnosticCategory.Message, key: "Insert command line options and files from a file." }, Use_the_0_flag_to_see_options: { code: 6031, category: DiagnosticCategory.Message, key: "Use the '{0}' flag to see options." }, File_Changed_Compiling: { code: 6032, category: DiagnosticCategory.Message, key: "File Changed. Compiling." }, STRING: { code: 6033, category: DiagnosticCategory.Message, key: "STRING" }, diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index 30bd7d0a1ed..6ce94b14404 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -934,10 +934,7 @@ "category": "Message", "code": 6027 }, - "Insert command line options and files from a file.": { - "category": "Message", - "code": 6028 - }, + "Version {0}": { "category": "Message", "code": 6029 From 078e49dd8bed70b2d02cd0f96b6f56f0d8503987 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Mon, 4 Aug 2014 18:29:58 -0700 Subject: [PATCH 12/15] Explicitly supply generic argument for 'compareValues'. --- src/compiler/tc.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/compiler/tc.ts b/src/compiler/tc.ts index 614a20aa21a..ee1089f7c6c 100644 --- a/src/compiler/tc.ts +++ b/src/compiler/tc.ts @@ -375,7 +375,7 @@ module ts { // Sort our options by their names, (e.g. "--noImplicitAny" comes before "--watch") var optsList = optionDeclarations.slice(); - optsList.sort((a, b) => compareValues(a.name.toLowerCase(), b.name.toLowerCase())); + optsList.sort((a, b) => compareValues(a.name.toLowerCase(), b.name.toLowerCase())); // We want our descriptions to align at the same column in our output, // so we keep track of the longest option usage string. From a24b175586c841b25a8ea195c572ad347f8f027d Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Tue, 5 Aug 2014 12:51:17 -0700 Subject: [PATCH 13/15] Perform an explicit return just in case sys.exit fails. --- src/compiler/tc.ts | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/compiler/tc.ts b/src/compiler/tc.ts index 77caacbe149..5009e4c7a97 100644 --- a/src/compiler/tc.ts +++ b/src/compiler/tc.ts @@ -197,32 +197,33 @@ module ts { // setting up localization, report them and quit. if (commandLine.errors.length > 0) { reportDiagnostics(commandLine.errors); - sys.exit(1); + return sys.exit(1); } if (commandLine.options.version) { reportDiagnostic(createCompilerDiagnostic(Diagnostics.Version_0, version)); - sys.exit(0); + return sys.exit(0); } if (commandLine.options.help || commandLine.filenames.length === 0) { printVersion(); printHelp(); - sys.exit(0); + return sys.exit(0); } var defaultCompilerHost = createCompilerHost(commandLine.options); - + if (commandLine.options.watch) { if (!sys.watchFile) { reportDiagnostic(createCompilerDiagnostic(Diagnostics.The_current_host_does_not_support_the_0_option, "--watch")); - sys.exit(1); + return sys.exit(1); } watchProgram(commandLine, defaultCompilerHost); } else { - sys.exit(compile(commandLine, defaultCompilerHost).errors.length > 0 ? 1 : 0); + var result = compile(commandLine, defaultCompilerHost).errors.length > 0 ? 1 : 0; + return sys.exit(result); } } From 7bf5a95105e9708a02654328307faa86c4063555 Mon Sep 17 00:00:00 2001 From: Dick van den Brink Date: Wed, 6 Aug 2014 19:08:55 +0200 Subject: [PATCH 14/15] Rename lib.scripthost.d.ts to lib.scriptHost.d.ts --- bin/{lib.scripthost.d.ts => lib.scriptHost.d.ts} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename bin/{lib.scripthost.d.ts => lib.scriptHost.d.ts} (100%) diff --git a/bin/lib.scripthost.d.ts b/bin/lib.scriptHost.d.ts similarity index 100% rename from bin/lib.scripthost.d.ts rename to bin/lib.scriptHost.d.ts From e31aa9e12ae98fe5cbfffdd4aaee85bf0b67197b Mon Sep 17 00:00:00 2001 From: Sheetal Nandi Date: Wed, 6 Aug 2014 11:26:34 -0700 Subject: [PATCH 15/15] Added more comments and todos as per code review feedback --- src/compiler/checker.ts | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 378e23bf83d..076478ae989 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -711,6 +711,20 @@ module ts { return { accessibility: SymbolAccessibility.Accessible }; } + // 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: + // module m { + // export class c { + // } + // } + // var x: typeof m.c + // In the above example when we start with checking if typeof m.c symbol is accessible, + // 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; symbol = symbol.parent; }