Add error for class exprs w/private properties
This commit is contained in:
parent
a0fa8ae6c4
commit
860e8e88c8
|
@ -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) {
|
||||
|
|
|
@ -190,7 +190,7 @@ namespace ts {
|
|||
const writer = <EmitTextWriterWithSymbolWriter>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));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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.": {
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -68,7 +68,7 @@ namespace ts {
|
|||
clear: () => str = "",
|
||||
trackSymbol: noop,
|
||||
reportInaccessibleThisError: noop,
|
||||
reportIllegalExtends: noop
|
||||
reportPrivateInBaseOfClassExpression: noop,
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -1128,7 +1128,7 @@ namespace ts {
|
|||
clear: resetWriter,
|
||||
trackSymbol: noop,
|
||||
reportInaccessibleThisError: noop,
|
||||
reportIllegalExtends: noop
|
||||
reportPrivateInBaseOfClassExpression: noop,
|
||||
};
|
||||
|
||||
function writeIndent() {
|
||||
|
|
Loading…
Reference in a new issue