diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index cae9f2dac25..b01c145c24b 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -3352,8 +3352,6 @@ namespace ts { getObjectFlags(type) & ObjectFlags.Anonymous && type.symbol && type.symbol.flags & SymbolFlags.Class; if (isConstructorObject) { - // TODO: something needs to issue accessibility errors (here, I think) - // before writing a literal type that flattens base types, check that the base types are accessible writeLiteralType(type, flags); } else { @@ -3479,10 +3477,13 @@ namespace ts { buildIndexSignatureDisplay(resolved.stringIndexInfo, writer, IndexKind.String, enclosingDeclaration, globalFlags, symbolStack); buildIndexSignatureDisplay(resolved.numberIndexInfo, writer, IndexKind.Number, enclosingDeclaration, globalFlags, symbolStack); for (const p of resolved.properties) { - if (globalFlags & TypeFormatFlags.WriteClassExpressionAsTypeLiteral && - (p.name === "prototype" || - getDeclarationModifierFlagsFromSymbol(p) & (ModifierFlags.Private | ModifierFlags.Protected))) { - continue; + if (globalFlags & TypeFormatFlags.WriteClassExpressionAsTypeLiteral) { + if (p.flags & SymbolFlags.Prototype) { + continue; + } + if (getDeclarationModifierFlagsFromSymbol(p) & (ModifierFlags.Private | ModifierFlags.Protected)) { + writer.reportPrivateInBaseOfClassExpression(p.name); + } } const t = getTypeOfSymbol(p); if (p.flags & (SymbolFlags.Function | SymbolFlags.Method) && !getPropertiesOfObjectType(t).length) { diff --git a/src/compiler/declarationEmitter.ts b/src/compiler/declarationEmitter.ts index 89358872a0f..3cc85aaa24b 100644 --- a/src/compiler/declarationEmitter.ts +++ b/src/compiler/declarationEmitter.ts @@ -190,7 +190,7 @@ namespace ts { const writer = createTextWriter(newLine); writer.trackSymbol = trackSymbol; writer.reportInaccessibleThisError = reportInaccessibleThisError; - writer.reportIllegalExtends = reportIllegalExtends; + writer.reportPrivateInBaseOfClassExpression = reportPrivateInBaseOfClassExpression; writer.writeKeyword = writer.write; writer.writeOperator = writer.write; writer.writePunctuation = writer.write; @@ -314,11 +314,11 @@ namespace ts { recordTypeReferenceDirectivesIfNecessary(resolver.getTypeReferenceDirectivesForSymbol(symbol, meaning)); } - function reportIllegalExtends() { + function reportPrivateInBaseOfClassExpression(propertyName: string) { if (errorNameNode) { reportedDeclarationError = true; - emitterDiagnostics.add(createDiagnosticForNode(errorNameNode, Diagnostics.extends_clause_of_exported_class_0_refers_to_a_type_whose_name_cannot_be_referenced, - declarationNameToString(errorNameNode))); + emitterDiagnostics.add( + createDiagnosticForNode(errorNameNode, Diagnostics.Property_0_of_exported_class_expression_may_not_be_private_or_protected, propertyName)); } } diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index 4aee7a37a88..c5b74943dcd 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -2432,9 +2432,9 @@ "category": "Error", "code": 4092 }, - "'extends' clause of exported class '{0}' refers to a type whose name cannot be referenced.": { + "Property '{0}' of exported class expression may not be private or protected.": { "category": "Error", - "code": 4093 + "code": 4094 }, "The current host does not support the '{0}' option.": { diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 069f8b967cf..0cade7f2cbc 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -2648,7 +2648,7 @@ namespace ts { // with import statements it previously saw (but chose not to emit). trackSymbol(symbol: Symbol, enclosingDeclaration?: Node, meaning?: SymbolFlags): void; reportInaccessibleThisError(): void; - reportIllegalExtends(): void; + reportPrivateInBaseOfClassExpression(propertyName: string): void; } export const enum TypeFormatFlags { diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index befb1c4ba77..3c3710c1cc5 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -68,7 +68,7 @@ namespace ts { clear: () => str = "", trackSymbol: noop, reportInaccessibleThisError: noop, - reportIllegalExtends: noop + reportPrivateInBaseOfClassExpression: noop, }; } diff --git a/src/services/utilities.ts b/src/services/utilities.ts index c8b710789ad..0965eb4dad7 100644 --- a/src/services/utilities.ts +++ b/src/services/utilities.ts @@ -1128,7 +1128,7 @@ namespace ts { clear: resetWriter, trackSymbol: noop, reportInaccessibleThisError: noop, - reportIllegalExtends: noop + reportPrivateInBaseOfClassExpression: noop, }; function writeIndent() {