Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 860e8e8

Browse filesBrowse files
committed
Add error for class exprs w/private properties
1 parent a0fa8ae commit 860e8e8
Copy full SHA for 860e8e8

6 files changed

+16-15Lines changed: 16 additions & 15 deletions

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎src/compiler/checker.ts‎

Copy file name to clipboardExpand all lines: src/compiler/checker.ts
+7-6Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3352,8 +3352,6 @@ namespace ts {
33523352
getObjectFlags(type) & ObjectFlags.Anonymous &&
33533353
type.symbol && type.symbol.flags & SymbolFlags.Class;
33543354
if (isConstructorObject) {
3355-
// TODO: something needs to issue accessibility errors (here, I think)
3356-
// before writing a literal type that flattens base types, check that the base types are accessible
33573355
writeLiteralType(type, flags);
33583356
}
33593357
else {
@@ -3479,10 +3477,13 @@ namespace ts {
34793477
buildIndexSignatureDisplay(resolved.stringIndexInfo, writer, IndexKind.String, enclosingDeclaration, globalFlags, symbolStack);
34803478
buildIndexSignatureDisplay(resolved.numberIndexInfo, writer, IndexKind.Number, enclosingDeclaration, globalFlags, symbolStack);
34813479
for (const p of resolved.properties) {
3482-
if (globalFlags & TypeFormatFlags.WriteClassExpressionAsTypeLiteral &&
3483-
(p.name === "prototype" ||
3484-
getDeclarationModifierFlagsFromSymbol(p) & (ModifierFlags.Private | ModifierFlags.Protected))) {
3485-
continue;
3480+
if (globalFlags & TypeFormatFlags.WriteClassExpressionAsTypeLiteral) {
3481+
if (p.flags & SymbolFlags.Prototype) {
3482+
continue;
3483+
}
3484+
if (getDeclarationModifierFlagsFromSymbol(p) & (ModifierFlags.Private | ModifierFlags.Protected)) {
3485+
writer.reportPrivateInBaseOfClassExpression(p.name);
3486+
}
34863487
}
34873488
const t = getTypeOfSymbol(p);
34883489
if (p.flags & (SymbolFlags.Function | SymbolFlags.Method) && !getPropertiesOfObjectType(t).length) {
Collapse file

‎src/compiler/declarationEmitter.ts‎

Copy file name to clipboardExpand all lines: src/compiler/declarationEmitter.ts
+4-4Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ namespace ts {
190190
const writer = <EmitTextWriterWithSymbolWriter>createTextWriter(newLine);
191191
writer.trackSymbol = trackSymbol;
192192
writer.reportInaccessibleThisError = reportInaccessibleThisError;
193-
writer.reportIllegalExtends = reportIllegalExtends;
193+
writer.reportPrivateInBaseOfClassExpression = reportPrivateInBaseOfClassExpression;
194194
writer.writeKeyword = writer.write;
195195
writer.writeOperator = writer.write;
196196
writer.writePunctuation = writer.write;
@@ -314,11 +314,11 @@ namespace ts {
314314
recordTypeReferenceDirectivesIfNecessary(resolver.getTypeReferenceDirectivesForSymbol(symbol, meaning));
315315
}
316316

317-
function reportIllegalExtends() {
317+
function reportPrivateInBaseOfClassExpression(propertyName: string) {
318318
if (errorNameNode) {
319319
reportedDeclarationError = true;
320-
emitterDiagnostics.add(createDiagnosticForNode(errorNameNode, Diagnostics.extends_clause_of_exported_class_0_refers_to_a_type_whose_name_cannot_be_referenced,
321-
declarationNameToString(errorNameNode)));
320+
emitterDiagnostics.add(
321+
createDiagnosticForNode(errorNameNode, Diagnostics.Property_0_of_exported_class_expression_may_not_be_private_or_protected, propertyName));
322322
}
323323
}
324324

Collapse file

‎src/compiler/diagnosticMessages.json‎

Copy file name to clipboardExpand all lines: src/compiler/diagnosticMessages.json
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2432,9 +2432,9 @@
24322432
"category": "Error",
24332433
"code": 4092
24342434
},
2435-
"'extends' clause of exported class '{0}' refers to a type whose name cannot be referenced.": {
2435+
"Property '{0}' of exported class expression may not be private or protected.": {
24362436
"category": "Error",
2437-
"code": 4093
2437+
"code": 4094
24382438
},
24392439

24402440
"The current host does not support the '{0}' option.": {
Collapse file

‎src/compiler/types.ts‎

Copy file name to clipboardExpand all lines: src/compiler/types.ts
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2648,7 +2648,7 @@ namespace ts {
26482648
// with import statements it previously saw (but chose not to emit).
26492649
trackSymbol(symbol: Symbol, enclosingDeclaration?: Node, meaning?: SymbolFlags): void;
26502650
reportInaccessibleThisError(): void;
2651-
reportIllegalExtends(): void;
2651+
reportPrivateInBaseOfClassExpression(propertyName: string): void;
26522652
}
26532653

26542654
export const enum TypeFormatFlags {
Collapse file

‎src/compiler/utilities.ts‎

Copy file name to clipboardExpand all lines: src/compiler/utilities.ts
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ namespace ts {
6868
clear: () => str = "",
6969
trackSymbol: noop,
7070
reportInaccessibleThisError: noop,
71-
reportIllegalExtends: noop
71+
reportPrivateInBaseOfClassExpression: noop,
7272
};
7373
}
7474

Collapse file

‎src/services/utilities.ts‎

Copy file name to clipboardExpand all lines: src/services/utilities.ts
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1128,7 +1128,7 @@ namespace ts {
11281128
clear: resetWriter,
11291129
trackSymbol: noop,
11301130
reportInaccessibleThisError: noop,
1131-
reportIllegalExtends: noop
1131+
reportPrivateInBaseOfClassExpression: noop,
11321132
};
11331133

11341134
function writeIndent() {

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.