From 170e6ec1305fae1e3b5115a9581b9c51cf98e020 Mon Sep 17 00:00:00 2001 From: Ron Buckton Date: Thu, 26 Oct 2017 15:50:07 -0700 Subject: [PATCH] Ensure correct errors when emitting declarations --- src/compiler/checker.ts | 14 +- src/compiler/declarationEmitter.ts | 128 ++++++++++++++---- src/compiler/diagnosticMessages.json | 33 +++++ src/compiler/types.ts | 9 +- src/compiler/utilities.ts | 2 +- .../reference/dynamicNamesErrors.errors.txt | 89 +++++++++++- .../baselines/reference/dynamicNamesErrors.js | 55 +++++++- .../reference/dynamicNamesErrors.symbols | 86 +++++++++++- .../reference/dynamicNamesErrors.types | 98 +++++++++++++- tests/cases/compiler/dynamicNamesErrors.ts | 36 ++++- 10 files changed, 488 insertions(+), 62 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 47ebf0bd5b0..1a8c2a09f04 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -24569,14 +24569,6 @@ namespace ts { return undefined; } - function isLiteralDynamicName(name: ComputedPropertyName) { - name = getParseTreeNode(name, isComputedPropertyName); - if (name) { - return isLateBindableName(name); - } - return false; - } - function isLiteralConstDeclaration(node: VariableDeclaration | PropertyDeclaration | PropertySignature | ParameterDeclaration): boolean { if (isConst(node)) { const type = getTypeOfSymbol(getSymbolOfNode(node)); @@ -24650,7 +24642,11 @@ namespace ts { getTypeReferenceDirectivesForEntityName, getTypeReferenceDirectivesForSymbol, isLiteralConstDeclaration, - isLiteralDynamicName, + isLateBound: (node: Declaration): node is LateBoundDeclaration => { + node = getParseTreeNode(node, isDeclaration); + const symbol = node && getSymbolOfNode(node); + return !!(symbol && symbol.flags & SymbolFlags.Late); + }, writeLiteralConstValue, getJsxFactoryEntity: () => _jsxFactoryEntity }; diff --git a/src/compiler/declarationEmitter.ts b/src/compiler/declarationEmitter.ts index cf702d24077..2efea500a9b 100644 --- a/src/compiler/declarationEmitter.ts +++ b/src/compiler/declarationEmitter.ts @@ -1227,7 +1227,7 @@ namespace ts { } function emitPropertyDeclaration(node: Declaration) { - if (hasDynamicName(node) && !resolver.isLiteralDynamicName(getNameOfDeclaration(node))) { + if (hasDynamicName(node) && !resolver.isLateBound(node)) { return; } @@ -1246,17 +1246,8 @@ namespace ts { emitBindingPattern(node.name); } else { - if (isDynamicName(node.name)) { - // If this node has a dynamic name, it can only be an identifier or property access because - // we've already skipped it otherwise. - emitDynamicName((node.name).expression); - } - else { - // If this node is a computed name, it can only be a symbol, because we've already skipped - // it if it's not a well known symbol. In that case, the text of the name will be exactly - // what we want, namely the name expression enclosed in brackets. - writeTextOfNode(currentText, node.name); - } + writeNameOfDeclaration(node, getVariableDeclarationTypeOrNameVisibilityError); + // If optional property emit ? but in the case of parameterProperty declaration with "?" indicating optional parameter for the constructor // we don't want to emit property declaration with "?" if ((node.kind === SyntaxKind.PropertyDeclaration || node.kind === SyntaxKind.PropertySignature || @@ -1271,12 +1262,12 @@ namespace ts { resolver.writeLiteralConstValue(node, writer); } else if (!hasModifier(node, ModifierFlags.Private)) { - writeTypeOfDeclaration(node, node.type, getVariableDeclarationTypeVisibilityError); + writeTypeOfDeclaration(node, node.type, getVariableDeclarationTypeOrNameVisibilityError); } } } - function getVariableDeclarationTypeVisibilityDiagnosticMessage(symbolAccessibilityResult: SymbolAccessibilityResult) { + function getVariableDeclarationTypeOrNameVisibilityDiagnosticMessage(symbolAccessibilityResult: SymbolAccessibilityResult) { if (node.kind === SyntaxKind.VariableDeclaration) { return symbolAccessibilityResult.errorModuleName ? symbolAccessibilityResult.accessibility === SymbolAccessibility.CannotBeNamed ? @@ -1312,8 +1303,8 @@ namespace ts { } } - function getVariableDeclarationTypeVisibilityError(symbolAccessibilityResult: SymbolAccessibilityResult): SymbolAccessibilityDiagnostic { - const diagnosticMessage = getVariableDeclarationTypeVisibilityDiagnosticMessage(symbolAccessibilityResult); + function getVariableDeclarationTypeOrNameVisibilityError(symbolAccessibilityResult: SymbolAccessibilityResult): SymbolAccessibilityDiagnostic { + const diagnosticMessage = getVariableDeclarationTypeOrNameVisibilityDiagnosticMessage(symbolAccessibilityResult); return diagnosticMessage !== undefined ? { diagnosticMessage, errorNode: node, @@ -1321,14 +1312,6 @@ namespace ts { } : undefined; } - function emitDynamicName(entityName: EntityNameExpression) { - writer.getSymbolAccessibilityDiagnostic = getVariableDeclarationTypeVisibilityError; - const visibilityResult = resolver.isEntityNameVisible(entityName, enclosingDeclaration); - handleSymbolAccessibilityError(visibilityResult); - recordTypeReferenceDirectivesIfNecessary(resolver.getTypeReferenceDirectivesForEntityName(entityName)); - writeTextOfNode(currentText, node.name); - } - function emitBindingPattern(bindingPattern: BindingPattern) { // Only select non-omitted expression from the bindingPattern's elements. // We have to do this to avoid emitting trailing commas. @@ -1346,7 +1329,7 @@ namespace ts { function emitBindingElement(bindingElement: BindingElement) { function getBindingElementTypeVisibilityError(symbolAccessibilityResult: SymbolAccessibilityResult): SymbolAccessibilityDiagnostic { - const diagnosticMessage = getVariableDeclarationTypeVisibilityDiagnosticMessage(symbolAccessibilityResult); + const diagnosticMessage = getVariableDeclarationTypeOrNameVisibilityDiagnosticMessage(symbolAccessibilityResult); return diagnosticMessage !== undefined ? { diagnosticMessage, errorNode: bindingElement, @@ -1402,7 +1385,7 @@ namespace ts { } function emitAccessorDeclaration(node: AccessorDeclaration) { - if (hasDynamicName(node)) { + if (hasDynamicName(node) && !resolver.isLateBound(node)) { return; } @@ -1413,7 +1396,7 @@ namespace ts { emitJsDocComments(accessors.getAccessor); emitJsDocComments(accessors.setAccessor); emitClassMemberDeclarationFlags(getModifierFlags(node) | (accessors.setAccessor ? 0 : ModifierFlags.Readonly)); - writeTextOfNode(currentText, node.name); + writeNameOfDeclaration(node, getAccessorNameVisibilityError); if (!hasModifier(node, ModifierFlags.Private)) { accessorWithTypeAnnotation = node; let type = getTypeAnnotationFromAccessor(node); @@ -1441,6 +1424,37 @@ namespace ts { } } + function getAccessorNameVisibilityError(symbolAccessibilityResult: SymbolAccessibilityResult) { + const diagnosticMessage = getAccessorNameVisibilityDiagnosticMessage(symbolAccessibilityResult); + return diagnosticMessage !== undefined ? { + diagnosticMessage, + errorNode: node, + typeName: node.name + } : undefined; + } + + function getAccessorNameVisibilityDiagnosticMessage(symbolAccessibilityResult: SymbolAccessibilityResult) { + if (hasModifier(node, ModifierFlags.Static)) { + return symbolAccessibilityResult.errorModuleName ? + symbolAccessibilityResult.accessibility === SymbolAccessibility.CannotBeNamed ? + Diagnostics.Public_static_property_0_of_exported_class_has_or_is_using_name_1_from_external_module_2_but_cannot_be_named : + Diagnostics.Public_static_property_0_of_exported_class_has_or_is_using_name_1_from_private_module_2 : + Diagnostics.Public_static_property_0_of_exported_class_has_or_is_using_private_name_1; + } + else if (node.parent.kind === SyntaxKind.ClassDeclaration) { + return symbolAccessibilityResult.errorModuleName ? + symbolAccessibilityResult.accessibility === SymbolAccessibility.CannotBeNamed ? + Diagnostics.Public_property_0_of_exported_class_has_or_is_using_name_1_from_external_module_2_but_cannot_be_named : + Diagnostics.Public_property_0_of_exported_class_has_or_is_using_name_1_from_private_module_2 : + Diagnostics.Public_property_0_of_exported_class_has_or_is_using_private_name_1; + } + else { + return symbolAccessibilityResult.errorModuleName ? + Diagnostics.Property_0_of_exported_interface_has_or_is_using_name_1_from_private_module_2 : + Diagnostics.Property_0_of_exported_interface_has_or_is_using_private_name_1; + } + } + function getAccessorDeclarationTypeVisibilityError(symbolAccessibilityResult: SymbolAccessibilityResult): SymbolAccessibilityDiagnostic { let diagnosticMessage: DiagnosticMessage; if (accessorWithTypeAnnotation.kind === SyntaxKind.SetAccessor) { @@ -1487,7 +1501,7 @@ namespace ts { } function writeFunctionDeclaration(node: FunctionLikeDeclaration) { - if (hasDynamicName(node)) { + if (hasDynamicName(node) && !resolver.isLateBound(node)) { return; } @@ -1509,13 +1523,69 @@ namespace ts { write("constructor"); } else { - writeTextOfNode(currentText, node.name); + writeNameOfDeclaration(node, getMethodNameVisibilityError); if (hasQuestionToken(node)) { write("?"); } } emitSignatureDeclaration(node); } + + function getMethodNameVisibilityError(symbolAccessibilityResult: SymbolAccessibilityResult): SymbolAccessibilityDiagnostic { + const diagnosticMessage = getMethodNameVisibilityDiagnosticMessage(symbolAccessibilityResult); + return diagnosticMessage !== undefined ? { + diagnosticMessage, + errorNode: node, + typeName: node.name + } : undefined; + } + + function getMethodNameVisibilityDiagnosticMessage(symbolAccessibilityResult: SymbolAccessibilityResult) { + if (hasModifier(node, ModifierFlags.Static)) { + return symbolAccessibilityResult.errorModuleName ? + symbolAccessibilityResult.accessibility === SymbolAccessibility.CannotBeNamed ? + Diagnostics.Public_static_method_0_of_exported_class_has_or_is_using_name_1_from_external_module_2_but_cannot_be_named : + Diagnostics.Public_static_method_0_of_exported_class_has_or_is_using_name_1_from_private_module_2 : + Diagnostics.Public_static_method_0_of_exported_class_has_or_is_using_private_name_1; + } + else if (node.parent.kind === SyntaxKind.ClassDeclaration) { + return symbolAccessibilityResult.errorModuleName ? + symbolAccessibilityResult.accessibility === SymbolAccessibility.CannotBeNamed ? + Diagnostics.Public_method_0_of_exported_class_has_or_is_using_name_1_from_external_module_2_but_cannot_be_named : + Diagnostics.Public_method_0_of_exported_class_has_or_is_using_name_1_from_private_module_2 : + Diagnostics.Public_method_0_of_exported_class_has_or_is_using_private_name_1; + } + else { + return symbolAccessibilityResult.errorModuleName ? + Diagnostics.Method_0_of_exported_interface_has_or_is_using_name_1_from_private_module_2 : + Diagnostics.Method_0_of_exported_interface_has_or_is_using_private_name_1; + } + } + } + + function writeNameOfDeclaration(node: NamedDeclaration, getSymbolAccessibilityDiagnostic: GetSymbolAccessibilityDiagnostic) { + if (hasDynamicName(node)) { + // If this node has a dynamic name, it can only be an identifier or property access because + // we've already skipped it otherwise. + Debug.assert(resolver.isLateBound(node)); + + writeLateBoundNameOfDeclaration(node as LateBoundDeclaration, getSymbolAccessibilityDiagnostic); + } + else { + // If this node is a computed name, it can only be a symbol, because we've already skipped + // it if it's not a well known symbol. In that case, the text of the name will be exactly + // what we want, namely the name expression enclosed in brackets. + writeTextOfNode(currentText, node.name); + } + } + + function writeLateBoundNameOfDeclaration(node: LateBoundDeclaration, getSymbolAccessibilityDiagnostic: GetSymbolAccessibilityDiagnostic) { + writer.getSymbolAccessibilityDiagnostic = getSymbolAccessibilityDiagnostic; + const entityName = node.name.expression; + const visibilityResult = resolver.isEntityNameVisible(entityName, enclosingDeclaration); + handleSymbolAccessibilityError(visibilityResult); + recordTypeReferenceDirectivesIfNecessary(resolver.getTypeReferenceDirectivesForEntityName(entityName)); + writeTextOfNode(currentText, node.name); } function emitSignatureDeclarationWithJsDocComments(node: SignatureDeclaration) { diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index dc8ef6cdac5..7734012c97d 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -2562,6 +2562,39 @@ "code": 4094 }, + "Public static method '{0}' of exported class has or is using name '{1}' from external module {2} but cannot be named.": { + "category": "Error", + "code": 4095 + }, + "Public static method '{0}' of exported class has or is using name '{1}' from private module '{2}'.": { + "category": "Error", + "code": 4096 + }, + "Public static method '{0}' of exported class has or is using private name '{1}'.": { + "category": "Error", + "code": 4097 + }, + "Public method '{0}' of exported class has or is using name '{1}' from external module {2} but cannot be named.": { + "category": "Error", + "code": 4098 + }, + "Public method '{0}' of exported class has or is using name '{1}' from private module '{2}'.": { + "category": "Error", + "code": 4099 + }, + "Public method '{0}' of exported class has or is using private name '{1}'.": { + "category": "Error", + "code": 4100 + }, + "Method '{0}' of exported interface has or is using name '{1}' from private module '{2}'.": { + "category": "Error", + "code": 4101 + }, + "Method '{0}' of exported interface has or is using private name '{1}'.": { + "category": "Error", + "code": 4102 + }, + "The current host does not support the '{0}' option.": { "category": "Error", "code": 5001 diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 21ee4af65ec..f4cc88e9a31 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -662,9 +662,14 @@ namespace ts { name?: DeclarationName; } + /* @internal */ + export interface DynamicNamedDeclaration extends NamedDeclaration { + name: ComputedPropertyName; + } + /* @internal */ // A declaration that supports late-binding (used in checker) - export interface LateBoundDeclaration extends NamedDeclaration { + export interface LateBoundDeclaration extends DynamicNamedDeclaration { name: LateBoundName; } @@ -2945,7 +2950,7 @@ namespace ts { isTopLevelValueImportEqualsWithEntityName(node: ImportEqualsDeclaration): boolean; getNodeCheckFlags(node: Node): NodeCheckFlags; isDeclarationVisible(node: Declaration): boolean; - isLiteralDynamicName(node: ComputedPropertyName): boolean; + isLateBound(node: Declaration): node is LateBoundDeclaration; collectLinkedAliases(node: Identifier): Node[]; isImplementationOfOverload(node: FunctionLikeDeclaration): boolean | undefined; isRequiredInitializedParameter(node: ParameterDeclaration): boolean; diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index 82cad54bf6d..b2ece2421ab 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -2001,7 +2001,7 @@ namespace ts { * is a property of the Symbol constructor that denotes a built in * Symbol. */ - export function hasDynamicName(declaration: Declaration): boolean { + export function hasDynamicName(declaration: Declaration): declaration is DynamicNamedDeclaration { const name = getNameOfDeclaration(declaration); return name && isDynamicName(name); } diff --git a/tests/baselines/reference/dynamicNamesErrors.errors.txt b/tests/baselines/reference/dynamicNamesErrors.errors.txt index 2e7525e2508..15722ed1a49 100644 --- a/tests/baselines/reference/dynamicNamesErrors.errors.txt +++ b/tests/baselines/reference/dynamicNamesErrors.errors.txt @@ -7,10 +7,25 @@ tests/cases/compiler/dynamicNamesErrors.ts(24,1): error TS2322: Type 'T2' is not tests/cases/compiler/dynamicNamesErrors.ts(25,1): error TS2322: Type 'T1' is not assignable to type 'T2'. Types of property '[c0]' are incompatible. Type 'number' is not assignable to type 'string'. -tests/cases/compiler/dynamicNamesErrors.ts(28,6): error TS4033: Property '[c0]' of exported interface has or is using private name 'c0'. +tests/cases/compiler/dynamicNamesErrors.ts(33,6): error TS4033: Property '[x]' of exported interface has or is using private name 'x'. +tests/cases/compiler/dynamicNamesErrors.ts(34,6): error TS4102: Method '[y]' of exported interface has or is using private name 'y'. +tests/cases/compiler/dynamicNamesErrors.ts(38,13): error TS4028: Public static property '[x]' of exported class has or is using private name 'x'. +tests/cases/compiler/dynamicNamesErrors.ts(39,13): error TS4097: Public static method '[y]' of exported class has or is using private name 'y'. +tests/cases/compiler/dynamicNamesErrors.ts(40,17): error TS4028: Public static property '[z]' of exported class has or is using private name 'z'. +tests/cases/compiler/dynamicNamesErrors.ts(41,17): error TS4028: Public static property '[w]' of exported class has or is using private name 'w'. +tests/cases/compiler/dynamicNamesErrors.ts(43,6): error TS4031: Public property '[x]' of exported class has or is using private name 'x'. +tests/cases/compiler/dynamicNamesErrors.ts(44,6): error TS4100: Public method '[y]' of exported class has or is using private name 'y'. +tests/cases/compiler/dynamicNamesErrors.ts(45,10): error TS4031: Public property '[z]' of exported class has or is using private name 'z'. +tests/cases/compiler/dynamicNamesErrors.ts(46,10): error TS4031: Public property '[w]' of exported class has or is using private name 'w'. +tests/cases/compiler/dynamicNamesErrors.ts(50,6): error TS4033: Property '[x]' of exported interface has or is using private name 'x'. +tests/cases/compiler/dynamicNamesErrors.ts(51,6): error TS4102: Method '[y]' of exported interface has or is using private name 'y'. +tests/cases/compiler/dynamicNamesErrors.ts(54,14): error TS4025: Exported variable 'ObjectLiteralVisibility' has or is using private name 'w'. +tests/cases/compiler/dynamicNamesErrors.ts(54,14): error TS4025: Exported variable 'ObjectLiteralVisibility' has or is using private name 'x'. +tests/cases/compiler/dynamicNamesErrors.ts(54,14): error TS4025: Exported variable 'ObjectLiteralVisibility' has or is using private name 'y'. +tests/cases/compiler/dynamicNamesErrors.ts(54,14): error TS4025: Exported variable 'ObjectLiteralVisibility' has or is using private name 'z'. -==== tests/cases/compiler/dynamicNamesErrors.ts (6 errors) ==== +==== tests/cases/compiler/dynamicNamesErrors.ts (21 errors) ==== const c0 = "1"; const c1 = 1; @@ -51,8 +66,68 @@ tests/cases/compiler/dynamicNamesErrors.ts(28,6): error TS4033: Property '[c0]' !!! error TS2322: Types of property '[c0]' are incompatible. !!! error TS2322: Type 'number' is not assignable to type 'string'. - export interface T4 { - [c0]: number; - ~~ -!!! error TS4033: Property '[c0]' of exported interface has or is using private name 'c0'. - } \ No newline at end of file + const x = Symbol(); + const y = Symbol(); + const z = Symbol(); + const w = Symbol(); + + export interface InterfaceMemberVisibility { + [x]: number; + ~ +!!! error TS4033: Property '[x]' of exported interface has or is using private name 'x'. + [y](): number; + ~ +!!! error TS4102: Method '[y]' of exported interface has or is using private name 'y'. + } + + export class ClassMemberVisibility { + static [x]: number; + ~ +!!! error TS4028: Public static property '[x]' of exported class has or is using private name 'x'. + static [y](): number { return 0; } + ~ +!!! error TS4097: Public static method '[y]' of exported class has or is using private name 'y'. + static get [z](): number { return 0; } + ~ +!!! error TS4028: Public static property '[z]' of exported class has or is using private name 'z'. + static set [w](value: number) { } + ~ +!!! error TS4028: Public static property '[w]' of exported class has or is using private name 'w'. + + [x]: number; + ~ +!!! error TS4031: Public property '[x]' of exported class has or is using private name 'x'. + [y](): number { return 0; } + ~ +!!! error TS4100: Public method '[y]' of exported class has or is using private name 'y'. + get [z](): number { return 0; } + ~ +!!! error TS4031: Public property '[z]' of exported class has or is using private name 'z'. + set [w](value: number) { } + ~ +!!! error TS4031: Public property '[w]' of exported class has or is using private name 'w'. + } + + export type ObjectTypeVisibility = { + [x]: number; + ~ +!!! error TS4033: Property '[x]' of exported interface has or is using private name 'x'. + [y](): number; + ~ +!!! error TS4102: Method '[y]' of exported interface has or is using private name 'y'. + }; + + export const ObjectLiteralVisibility = { + ~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS4025: Exported variable 'ObjectLiteralVisibility' has or is using private name 'w'. + ~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS4025: Exported variable 'ObjectLiteralVisibility' has or is using private name 'x'. + ~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS4025: Exported variable 'ObjectLiteralVisibility' has or is using private name 'y'. + ~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS4025: Exported variable 'ObjectLiteralVisibility' has or is using private name 'z'. + [x]: 0, + [y](): number { return 0; }, + get [z](): number { return 0; }, + set [w](value: number) { }, + }; \ No newline at end of file diff --git a/tests/baselines/reference/dynamicNamesErrors.js b/tests/baselines/reference/dynamicNamesErrors.js index ec4fb8114cb..dbea91fcb01 100644 --- a/tests/baselines/reference/dynamicNamesErrors.js +++ b/tests/baselines/reference/dynamicNamesErrors.js @@ -25,9 +25,39 @@ let t2: T2; t1 = t2; t2 = t1; -export interface T4 { - [c0]: number; -} +const x = Symbol(); +const y = Symbol(); +const z = Symbol(); +const w = Symbol(); + +export interface InterfaceMemberVisibility { + [x]: number; + [y](): number; +} + +export class ClassMemberVisibility { + static [x]: number; + static [y](): number { return 0; } + static get [z](): number { return 0; } + static set [w](value: number) { } + + [x]: number; + [y](): number { return 0; } + get [z](): number { return 0; } + set [w](value: number) { } +} + +export type ObjectTypeVisibility = { + [x]: number; + [y](): number; +}; + +export const ObjectLiteralVisibility = { + [x]: 0, + [y](): number { return 0; }, + get [z](): number { return 0; }, + set [w](value: number) { }, +}; //// [dynamicNamesErrors.js] "use strict"; @@ -38,3 +68,22 @@ let t1; let t2; t1 = t2; t2 = t1; +const x = Symbol(); +const y = Symbol(); +const z = Symbol(); +const w = Symbol(); +class ClassMemberVisibility { + static [y]() { return 0; } + static get [z]() { return 0; } + static set [w](value) { } + [y]() { return 0; } + get [z]() { return 0; } + set [w](value) { } +} +exports.ClassMemberVisibility = ClassMemberVisibility; +exports.ObjectLiteralVisibility = { + [x]: 0, + [y]() { return 0; }, + get [z]() { return 0; }, + set [w](value) { }, +}; diff --git a/tests/baselines/reference/dynamicNamesErrors.symbols b/tests/baselines/reference/dynamicNamesErrors.symbols index cc8c3a2e6cf..30ba78a99a3 100644 --- a/tests/baselines/reference/dynamicNamesErrors.symbols +++ b/tests/baselines/reference/dynamicNamesErrors.symbols @@ -54,9 +54,87 @@ t2 = t1; >t2 : Symbol(t2, Decl(dynamicNamesErrors.ts, 22, 3)) >t1 : Symbol(t1, Decl(dynamicNamesErrors.ts, 21, 3)) -export interface T4 { ->T4 : Symbol(T4, Decl(dynamicNamesErrors.ts, 24, 8)) +const x = Symbol(); +>x : Symbol(x, Decl(dynamicNamesErrors.ts, 26, 5)) +>Symbol : Symbol(Symbol, Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2015.symbol.d.ts, --, --), Decl(lib.es2015.symbol.d.ts, --, --)) - [c0]: number; ->c0 : Symbol(c0, Decl(dynamicNamesErrors.ts, 0, 5)) +const y = Symbol(); +>y : Symbol(y, Decl(dynamicNamesErrors.ts, 27, 5)) +>Symbol : Symbol(Symbol, Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2015.symbol.d.ts, --, --), Decl(lib.es2015.symbol.d.ts, --, --)) + +const z = Symbol(); +>z : Symbol(z, Decl(dynamicNamesErrors.ts, 28, 5)) +>Symbol : Symbol(Symbol, Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2015.symbol.d.ts, --, --), Decl(lib.es2015.symbol.d.ts, --, --)) + +const w = Symbol(); +>w : Symbol(w, Decl(dynamicNamesErrors.ts, 29, 5)) +>Symbol : Symbol(Symbol, Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2015.symbol.d.ts, --, --), Decl(lib.es2015.symbol.d.ts, --, --)) + +export interface InterfaceMemberVisibility { +>InterfaceMemberVisibility : Symbol(InterfaceMemberVisibility, Decl(dynamicNamesErrors.ts, 29, 19)) + + [x]: number; +>x : Symbol(x, Decl(dynamicNamesErrors.ts, 26, 5)) + + [y](): number; +>y : Symbol(y, Decl(dynamicNamesErrors.ts, 27, 5)) } + +export class ClassMemberVisibility { +>ClassMemberVisibility : Symbol(ClassMemberVisibility, Decl(dynamicNamesErrors.ts, 34, 1)) + + static [x]: number; +>x : Symbol(x, Decl(dynamicNamesErrors.ts, 26, 5)) + + static [y](): number { return 0; } +>y : Symbol(y, Decl(dynamicNamesErrors.ts, 27, 5)) + + static get [z](): number { return 0; } +>z : Symbol(z, Decl(dynamicNamesErrors.ts, 28, 5)) + + static set [w](value: number) { } +>w : Symbol(w, Decl(dynamicNamesErrors.ts, 29, 5)) +>value : Symbol(value, Decl(dynamicNamesErrors.ts, 40, 19)) + + [x]: number; +>x : Symbol(x, Decl(dynamicNamesErrors.ts, 26, 5)) + + [y](): number { return 0; } +>y : Symbol(y, Decl(dynamicNamesErrors.ts, 27, 5)) + + get [z](): number { return 0; } +>z : Symbol(z, Decl(dynamicNamesErrors.ts, 28, 5)) + + set [w](value: number) { } +>w : Symbol(w, Decl(dynamicNamesErrors.ts, 29, 5)) +>value : Symbol(value, Decl(dynamicNamesErrors.ts, 45, 12)) +} + +export type ObjectTypeVisibility = { +>ObjectTypeVisibility : Symbol(ObjectTypeVisibility, Decl(dynamicNamesErrors.ts, 46, 1)) + + [x]: number; +>x : Symbol(x, Decl(dynamicNamesErrors.ts, 26, 5)) + + [y](): number; +>y : Symbol(y, Decl(dynamicNamesErrors.ts, 27, 5)) + +}; + +export const ObjectLiteralVisibility = { +>ObjectLiteralVisibility : Symbol(ObjectLiteralVisibility, Decl(dynamicNamesErrors.ts, 53, 12)) + + [x]: 0, +>x : Symbol(x, Decl(dynamicNamesErrors.ts, 26, 5)) + + [y](): number { return 0; }, +>y : Symbol(y, Decl(dynamicNamesErrors.ts, 27, 5)) + + get [z](): number { return 0; }, +>z : Symbol(z, Decl(dynamicNamesErrors.ts, 28, 5)) + + set [w](value: number) { }, +>w : Symbol(w, Decl(dynamicNamesErrors.ts, 29, 5)) +>value : Symbol(value, Decl(dynamicNamesErrors.ts, 57, 12)) + +}; diff --git a/tests/baselines/reference/dynamicNamesErrors.types b/tests/baselines/reference/dynamicNamesErrors.types index afee89cf397..3e3f71ec141 100644 --- a/tests/baselines/reference/dynamicNamesErrors.types +++ b/tests/baselines/reference/dynamicNamesErrors.types @@ -58,9 +58,99 @@ t2 = t1; >t2 : T2 >t1 : T1 -export interface T4 { ->T4 : T4 +const x = Symbol(); +>x : unique symbol +>Symbol() : unique symbol +>Symbol : SymbolConstructor - [c0]: number; ->c0 : "1" +const y = Symbol(); +>y : unique symbol +>Symbol() : unique symbol +>Symbol : SymbolConstructor + +const z = Symbol(); +>z : unique symbol +>Symbol() : unique symbol +>Symbol : SymbolConstructor + +const w = Symbol(); +>w : unique symbol +>Symbol() : unique symbol +>Symbol : SymbolConstructor + +export interface InterfaceMemberVisibility { +>InterfaceMemberVisibility : InterfaceMemberVisibility + + [x]: number; +>x : unique symbol + + [y](): number; +>y : unique symbol } + +export class ClassMemberVisibility { +>ClassMemberVisibility : ClassMemberVisibility + + static [x]: number; +>x : unique symbol + + static [y](): number { return 0; } +>y : unique symbol +>0 : 0 + + static get [z](): number { return 0; } +>z : unique symbol +>0 : 0 + + static set [w](value: number) { } +>w : unique symbol +>value : number + + [x]: number; +>x : unique symbol + + [y](): number { return 0; } +>y : unique symbol +>0 : 0 + + get [z](): number { return 0; } +>z : unique symbol +>0 : 0 + + set [w](value: number) { } +>w : unique symbol +>value : number +} + +export type ObjectTypeVisibility = { +>ObjectTypeVisibility : ObjectTypeVisibility + + [x]: number; +>x : unique symbol + + [y](): number; +>y : unique symbol + +}; + +export const ObjectLiteralVisibility = { +>ObjectLiteralVisibility : { [x]: number; [y](): number; readonly [z]: number; [w]: number; } +>{ [x]: 0, [y](): number { return 0; }, get [z](): number { return 0; }, set [w](value: number) { },} : { [x]: number; [y](): number; readonly [z]: number; [w]: number; } + + [x]: 0, +>x : unique symbol +>0 : 0 + + [y](): number { return 0; }, +>y : unique symbol +>0 : 0 + + get [z](): number { return 0; }, +>z : unique symbol +>0 : 0 + + set [w](value: number) { }, +>w : unique symbol +>value : number + +}; diff --git a/tests/cases/compiler/dynamicNamesErrors.ts b/tests/cases/compiler/dynamicNamesErrors.ts index cb837767732..daeb5cb600b 100644 --- a/tests/cases/compiler/dynamicNamesErrors.ts +++ b/tests/cases/compiler/dynamicNamesErrors.ts @@ -27,6 +27,36 @@ let t2: T2; t1 = t2; t2 = t1; -export interface T4 { - [c0]: number; -} \ No newline at end of file +const x = Symbol(); +const y = Symbol(); +const z = Symbol(); +const w = Symbol(); + +export interface InterfaceMemberVisibility { + [x]: number; + [y](): number; +} + +export class ClassMemberVisibility { + static [x]: number; + static [y](): number { return 0; } + static get [z](): number { return 0; } + static set [w](value: number) { } + + [x]: number; + [y](): number { return 0; } + get [z](): number { return 0; } + set [w](value: number) { } +} + +export type ObjectTypeVisibility = { + [x]: number; + [y](): number; +}; + +export const ObjectLiteralVisibility = { + [x]: 0, + [y](): number { return 0; }, + get [z](): number { return 0; }, + set [w](value: number) { }, +}; \ No newline at end of file