From 37c4f24ef3e1af56d45f1fffe46acc054d65f787 Mon Sep 17 00:00:00 2001 From: Ron Buckton Date: Wed, 7 Aug 2019 11:22:32 -0700 Subject: [PATCH 1/4] Allow accessors in ambient classes --- src/compiler/checker.ts | 9 ++-- src/compiler/diagnosticMessages.json | 4 -- .../accessorsInAmbientContext.errors.txt | 44 ------------------- .../reference/ambientGetters.errors.txt | 16 ------- .../reference/parserAccessors5.errors.txt | 9 ---- .../reference/parserAccessors6.errors.txt | 9 ---- .../parserComputedPropertyName23.errors.txt | 5 +-- 7 files changed, 5 insertions(+), 91 deletions(-) delete mode 100644 tests/baselines/reference/accessorsInAmbientContext.errors.txt delete mode 100644 tests/baselines/reference/ambientGetters.errors.txt delete mode 100644 tests/baselines/reference/parserAccessors5.errors.txt delete mode 100644 tests/baselines/reference/parserAccessors6.errors.txt diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 30637c3cebcae..eff67197bbc1a 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -5935,7 +5935,9 @@ namespace ts { // Otherwise, fall back to 'any'. else { if (setter) { - errorOrSuggestion(noImplicitAny, setter, Diagnostics.Property_0_implicitly_has_type_any_because_its_set_accessor_lacks_a_parameter_type_annotation, symbolToString(symbol)); + if (!isPrivateWithinAmbient(setter)) { + errorOrSuggestion(noImplicitAny, setter, Diagnostics.Property_0_implicitly_has_type_any_because_its_set_accessor_lacks_a_parameter_type_annotation, symbolToString(symbol)); + } } else { Debug.assert(!!getter, "there must existed getter as we are current checking either setter or getter in this function"); @@ -33039,10 +33041,7 @@ namespace ts { if (languageVersion < ScriptTarget.ES5) { return grammarErrorOnNode(accessor.name, Diagnostics.Accessors_are_only_available_when_targeting_ECMAScript_5_and_higher); } - else if (accessor.flags & NodeFlags.Ambient) { - return grammarErrorOnNode(accessor.name, Diagnostics.An_accessor_cannot_be_declared_in_an_ambient_context); - } - else if (accessor.body === undefined && !hasModifier(accessor, ModifierFlags.Abstract)) { + else if (accessor.body === undefined && !hasModifier(accessor, ModifierFlags.Abstract) && !(accessor.flags & NodeFlags.Ambient)) { return grammarErrorAtPos(accessor, accessor.end - 1, ";".length, Diagnostics._0_expected, "{"); } else if (accessor.body && hasModifier(accessor, ModifierFlags.Abstract)) { diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index 4528d504d0d12..5cca456dd4905 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -243,10 +243,6 @@ "category": "Error", "code": 1085 }, - "An accessor cannot be declared in an ambient context.": { - "category": "Error", - "code": 1086 - }, "'{0}' modifier cannot appear on a constructor declaration.": { "category": "Error", "code": 1089 diff --git a/tests/baselines/reference/accessorsInAmbientContext.errors.txt b/tests/baselines/reference/accessorsInAmbientContext.errors.txt deleted file mode 100644 index 44b100bd58ddb..0000000000000 --- a/tests/baselines/reference/accessorsInAmbientContext.errors.txt +++ /dev/null @@ -1,44 +0,0 @@ -tests/cases/compiler/accessorsInAmbientContext.ts(3,13): error TS1086: An accessor cannot be declared in an ambient context. -tests/cases/compiler/accessorsInAmbientContext.ts(4,13): error TS1086: An accessor cannot be declared in an ambient context. -tests/cases/compiler/accessorsInAmbientContext.ts(6,20): error TS1086: An accessor cannot be declared in an ambient context. -tests/cases/compiler/accessorsInAmbientContext.ts(7,20): error TS1086: An accessor cannot be declared in an ambient context. -tests/cases/compiler/accessorsInAmbientContext.ts(12,9): error TS1086: An accessor cannot be declared in an ambient context. -tests/cases/compiler/accessorsInAmbientContext.ts(13,9): error TS1086: An accessor cannot be declared in an ambient context. -tests/cases/compiler/accessorsInAmbientContext.ts(15,16): error TS1086: An accessor cannot be declared in an ambient context. -tests/cases/compiler/accessorsInAmbientContext.ts(16,16): error TS1086: An accessor cannot be declared in an ambient context. - - -==== tests/cases/compiler/accessorsInAmbientContext.ts (8 errors) ==== - declare module M { - class C { - get X() { return 1; } - ~ -!!! error TS1086: An accessor cannot be declared in an ambient context. - set X(v) { } - ~ -!!! error TS1086: An accessor cannot be declared in an ambient context. - - static get Y() { return 1; } - ~ -!!! error TS1086: An accessor cannot be declared in an ambient context. - static set Y(v) { } - ~ -!!! error TS1086: An accessor cannot be declared in an ambient context. - } - } - - declare class C { - get X() { return 1; } - ~ -!!! error TS1086: An accessor cannot be declared in an ambient context. - set X(v) { } - ~ -!!! error TS1086: An accessor cannot be declared in an ambient context. - - static get Y() { return 1; } - ~ -!!! error TS1086: An accessor cannot be declared in an ambient context. - static set Y(v) { } - ~ -!!! error TS1086: An accessor cannot be declared in an ambient context. - } \ No newline at end of file diff --git a/tests/baselines/reference/ambientGetters.errors.txt b/tests/baselines/reference/ambientGetters.errors.txt deleted file mode 100644 index b245f56181354..0000000000000 --- a/tests/baselines/reference/ambientGetters.errors.txt +++ /dev/null @@ -1,16 +0,0 @@ -tests/cases/compiler/ambientGetters.ts(2,9): error TS1086: An accessor cannot be declared in an ambient context. -tests/cases/compiler/ambientGetters.ts(6,9): error TS1086: An accessor cannot be declared in an ambient context. - - -==== tests/cases/compiler/ambientGetters.ts (2 errors) ==== - declare class A { - get length() : number; - ~~~~~~ -!!! error TS1086: An accessor cannot be declared in an ambient context. - } - - declare class B { - get length() { return 0; } - ~~~~~~ -!!! error TS1086: An accessor cannot be declared in an ambient context. - } \ No newline at end of file diff --git a/tests/baselines/reference/parserAccessors5.errors.txt b/tests/baselines/reference/parserAccessors5.errors.txt deleted file mode 100644 index b7dcd8ef923b3..0000000000000 --- a/tests/baselines/reference/parserAccessors5.errors.txt +++ /dev/null @@ -1,9 +0,0 @@ -tests/cases/conformance/parser/ecmascript5/Accessors/parserAccessors5.ts(2,7): error TS1086: An accessor cannot be declared in an ambient context. - - -==== tests/cases/conformance/parser/ecmascript5/Accessors/parserAccessors5.ts (1 errors) ==== - declare class C { - get foo() { return 0; } - ~~~ -!!! error TS1086: An accessor cannot be declared in an ambient context. - } \ No newline at end of file diff --git a/tests/baselines/reference/parserAccessors6.errors.txt b/tests/baselines/reference/parserAccessors6.errors.txt deleted file mode 100644 index 023ec6d79c345..0000000000000 --- a/tests/baselines/reference/parserAccessors6.errors.txt +++ /dev/null @@ -1,9 +0,0 @@ -tests/cases/conformance/parser/ecmascript5/Accessors/parserAccessors6.ts(2,7): error TS1086: An accessor cannot be declared in an ambient context. - - -==== tests/cases/conformance/parser/ecmascript5/Accessors/parserAccessors6.ts (1 errors) ==== - declare class C { - set foo(v) { } - ~~~ -!!! error TS1086: An accessor cannot be declared in an ambient context. - } \ No newline at end of file diff --git a/tests/baselines/reference/parserComputedPropertyName23.errors.txt b/tests/baselines/reference/parserComputedPropertyName23.errors.txt index 8c95992253c54..2ecf45eb69733 100644 --- a/tests/baselines/reference/parserComputedPropertyName23.errors.txt +++ b/tests/baselines/reference/parserComputedPropertyName23.errors.txt @@ -1,12 +1,9 @@ -tests/cases/conformance/parser/ecmascript6/ComputedPropertyNames/parserComputedPropertyName23.ts(2,9): error TS1086: An accessor cannot be declared in an ambient context. tests/cases/conformance/parser/ecmascript6/ComputedPropertyNames/parserComputedPropertyName23.ts(2,10): error TS2304: Cannot find name 'e'. -==== tests/cases/conformance/parser/ecmascript6/ComputedPropertyNames/parserComputedPropertyName23.ts (2 errors) ==== +==== tests/cases/conformance/parser/ecmascript6/ComputedPropertyNames/parserComputedPropertyName23.ts (1 errors) ==== declare class C { get [e](): number - ~~~ -!!! error TS1086: An accessor cannot be declared in an ambient context. ~ !!! error TS2304: Cannot find name 'e'. } \ No newline at end of file From 77fc6f3b2ecea0ef176bded5e5882e9f18dc4f0a Mon Sep 17 00:00:00 2001 From: Ron Buckton Date: Wed, 7 Aug 2019 11:38:45 -0700 Subject: [PATCH 2/4] Allow and emit accessors on interfaces --- src/compiler/binder.ts | 10 ++ src/compiler/checker.ts | 137 ++++++++++++------ src/compiler/diagnosticMessages.json | 21 +++ src/compiler/emitter.ts | 17 +++ src/compiler/factory.ts | 60 ++++++++ src/compiler/parser.ts | 35 ++++- src/compiler/transformers/declarations.ts | 79 ++++++++-- .../transformers/declarations/diagnostics.ts | 34 ++++- src/compiler/types.ts | 30 ++++ src/compiler/utilities.ts | 91 +++++++++++- src/compiler/visitor.ts | 49 ++++++- 11 files changed, 489 insertions(+), 74 deletions(-) diff --git a/src/compiler/binder.ts b/src/compiler/binder.ts index 25c275fe9696a..baa7b7c1e61a0 100644 --- a/src/compiler/binder.ts +++ b/src/compiler/binder.ts @@ -1502,6 +1502,8 @@ namespace ts { case SyntaxKind.MethodSignature: case SyntaxKind.GetAccessor: case SyntaxKind.SetAccessor: + case SyntaxKind.GetAccessorSignature: + case SyntaxKind.SetAccessorSignature: case SyntaxKind.CallSignature: case SyntaxKind.JSDocSignature: case SyntaxKind.JSDocFunctionType: @@ -1600,6 +1602,8 @@ namespace ts { case SyntaxKind.Constructor: case SyntaxKind.GetAccessor: case SyntaxKind.SetAccessor: + case SyntaxKind.GetAccessorSignature: + case SyntaxKind.SetAccessorSignature: case SyntaxKind.FunctionDeclaration: case SyntaxKind.FunctionExpression: case SyntaxKind.ArrowFunction: @@ -2236,8 +2240,10 @@ namespace ts { case SyntaxKind.Constructor: return declareSymbolAndAddToSymbolTable(node, SymbolFlags.Constructor, /*symbolExcludes:*/ SymbolFlags.None); case SyntaxKind.GetAccessor: + case SyntaxKind.GetAccessorSignature: return bindPropertyOrMethodOrAccessor(node, SymbolFlags.GetAccessor, SymbolFlags.GetAccessorExcludes); case SyntaxKind.SetAccessor: + case SyntaxKind.SetAccessorSignature: return bindPropertyOrMethodOrAccessor(node, SymbolFlags.SetAccessor, SymbolFlags.SetAccessorExcludes); case SyntaxKind.FunctionType: case SyntaxKind.JSDocFunctionType: @@ -3750,6 +3756,8 @@ namespace ts { case SyntaxKind.TypeParameter: case SyntaxKind.PropertySignature: case SyntaxKind.MethodSignature: + case SyntaxKind.GetAccessorSignature: + case SyntaxKind.SetAccessorSignature: case SyntaxKind.CallSignature: case SyntaxKind.ConstructSignature: case SyntaxKind.IndexSignature: @@ -3934,6 +3942,8 @@ namespace ts { case SyntaxKind.TypeParameter: case SyntaxKind.PropertySignature: case SyntaxKind.MethodSignature: + case SyntaxKind.GetAccessorSignature: + case SyntaxKind.SetAccessorSignature: case SyntaxKind.CallSignature: case SyntaxKind.ConstructSignature: case SyntaxKind.IndexSignature: diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index eff67197bbc1a..60ecfdb2cf141 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -4902,6 +4902,8 @@ namespace ts { case SyntaxKind.PropertySignature: case SyntaxKind.GetAccessor: case SyntaxKind.SetAccessor: + case SyntaxKind.GetAccessorSignature: + case SyntaxKind.SetAccessorSignature: case SyntaxKind.MethodDeclaration: case SyntaxKind.MethodSignature: if (hasModifier(node, ModifierFlags.Private | ModifierFlags.Protected)) { @@ -5356,13 +5358,14 @@ namespace ts { } if (declaration.kind === SyntaxKind.Parameter) { - const func = declaration.parent; + const func = declaration.parent; // For a parameter of a set accessor, use the type of the get accessor if one is present - if (func.kind === SyntaxKind.SetAccessor && !hasNonBindableDynamicName(func)) { - const getter = getDeclarationOfKind(getSymbolOfNode(declaration.parent), SyntaxKind.GetAccessor); + if (isSetAccessorLike(func) && !hasNonBindableDynamicName(func)) { + const getAccessorKind = func.kind === SyntaxKind.SetAccessorSignature ? SyntaxKind.GetAccessorSignature : SyntaxKind.GetAccessor; + const getter = getDeclarationOfKind(getSymbolOfNode(declaration.parent), getAccessorKind); if (getter) { const getterSignature = getSignatureFromDeclaration(getter); - const thisParameter = getAccessorThisParameter(func as AccessorDeclaration); + const thisParameter = getAccessorThisParameter(func); if (thisParameter && declaration === thisParameter) { // Use the type from the *getter* Debug.assert(!thisParameter.type); @@ -5866,9 +5869,9 @@ namespace ts { return type; } - function getAnnotatedAccessorTypeNode(accessor: AccessorDeclaration | undefined): TypeNode | undefined { + function getAnnotatedAccessorTypeNode(accessor: AccessorLike | undefined): TypeNode | undefined { if (accessor) { - if (accessor.kind === SyntaxKind.GetAccessor) { + if (isGetAccessorLike(accessor)) { const getterTypeAnnotation = getEffectiveReturnTypeNode(accessor); return getterTypeAnnotation; } @@ -5880,12 +5883,12 @@ namespace ts { return undefined; } - function getAnnotatedAccessorType(accessor: AccessorDeclaration | undefined): Type | undefined { + function getAnnotatedAccessorType(accessor: AccessorLike | undefined): Type | undefined { const node = getAnnotatedAccessorTypeNode(accessor); return node && getTypeFromTypeNode(node); } - function getAnnotatedAccessorThisParameter(accessor: AccessorDeclaration): Symbol | undefined { + function getAnnotatedAccessorThisParameter(accessor: AccessorLike): Symbol | undefined { const parameter = getAccessorThisParameter(accessor); return parameter && parameter.symbol; } @@ -5900,8 +5903,10 @@ namespace ts { } function getTypeOfAccessorsWorker(symbol: Symbol): Type { - const getter = getDeclarationOfKind(symbol, SyntaxKind.GetAccessor); - const setter = getDeclarationOfKind(symbol, SyntaxKind.SetAccessor); + const getter = getDeclarationOfKind(symbol, SyntaxKind.GetAccessor) || + getDeclarationOfKind(symbol, SyntaxKind.GetAccessorSignature); + const setter = getDeclarationOfKind(symbol, SyntaxKind.SetAccessor) || + getDeclarationOfKind(symbol, SyntaxKind.SetAccessorSignature); if (getter && isInJSFile(getter)) { const jsDocType = getTypeForDeclarationFromJSDocComment(getter); @@ -5929,7 +5934,7 @@ namespace ts { } else { // If there are no specified types, try to infer it from the body of the get accessor if it exists. - if (getter && getter.body) { + if (getter && isGetAccessorDeclaration(getter) && getter.body) { type = getReturnTypeFromBody(getter); } // Otherwise, fall back to 'any'. @@ -5950,7 +5955,8 @@ namespace ts { if (!popTypeResolution()) { type = anyType; if (noImplicitAny) { - const getter = getDeclarationOfKind(symbol, SyntaxKind.GetAccessor); + const getter = getDeclarationOfKind(symbol, SyntaxKind.GetAccessor) || + getDeclarationOfKind(symbol, SyntaxKind.GetAccessorSignature); error(getter, Diagnostics._0_implicitly_has_return_type_any_because_it_does_not_have_a_return_type_annotation_and_is_referenced_directly_or_indirectly_in_one_of_its_return_expressions, symbolToString(symbol)); } } @@ -6748,7 +6754,9 @@ namespace ts { case SyntaxKind.Constructor: case SyntaxKind.GetAccessor: case SyntaxKind.SetAccessor: - return isThislessFunctionLikeDeclaration(declaration); + case SyntaxKind.GetAccessorSignature: + case SyntaxKind.SetAccessorSignature: + return isThislessFunctionLikeDeclaration(declaration); } } } @@ -8562,11 +8570,12 @@ namespace ts { } // If only one accessor includes a this-type annotation, the other behaves as if it had the same type annotation - if ((declaration.kind === SyntaxKind.GetAccessor || declaration.kind === SyntaxKind.SetAccessor) && + if (isAccessorDeclaration(declaration) && !hasNonBindableDynamicName(declaration) && (!hasThisParameter || !thisParameter)) { - const otherKind = declaration.kind === SyntaxKind.GetAccessor ? SyntaxKind.SetAccessor : SyntaxKind.GetAccessor; - const other = getDeclarationOfKind(getSymbolOfNode(declaration), otherKind); + const symbol = getSymbolOfNode(declaration); + const other = getDeclarationOfKind(symbol, getOtherAccessorDeclarationKind(declaration)) || + getDeclarationOfKind(symbol, getOtherAccessorSignatureKind(declaration)); if (other) { thisParameter = getAnnotatedAccessorThisParameter(other); } @@ -8779,12 +8788,13 @@ namespace ts { if (typeNode) { return getTypeFromTypeNode(typeNode); } - if (declaration.kind === SyntaxKind.GetAccessor && !hasNonBindableDynamicName(declaration)) { + if (isGetAccessorLike(declaration) && !hasNonBindableDynamicName(declaration)) { const jsDocType = isInJSFile(declaration) && getTypeForDeclarationFromJSDocComment(declaration); if (jsDocType) { return jsDocType; } - const setter = getDeclarationOfKind(getSymbolOfNode(declaration), SyntaxKind.SetAccessor); + const setter = getDeclarationOfKind(getSymbolOfNode(declaration), SyntaxKind.SetAccessor) || + getDeclarationOfKind(getSymbolOfNode(declaration), SyntaxKind.SetAccessorSignature); const setterType = getAnnotatedAccessorType(setter); if (setterType) { return setterType; @@ -15177,6 +15187,8 @@ namespace ts { case SyntaxKind.MethodSignature: case SyntaxKind.GetAccessor: case SyntaxKind.SetAccessor: + case SyntaxKind.GetAccessorSignature: + case SyntaxKind.SetAccessorSignature: case SyntaxKind.FunctionExpression: case SyntaxKind.ArrowFunction: if (noImplicitAny && !(declaration as NamedDeclaration).name) { @@ -18566,13 +18578,17 @@ namespace ts { return container.kind === SyntaxKind.MethodDeclaration || container.kind === SyntaxKind.MethodSignature || container.kind === SyntaxKind.GetAccessor || - container.kind === SyntaxKind.SetAccessor; + container.kind === SyntaxKind.SetAccessor || + container.kind === SyntaxKind.GetAccessorSignature || + container.kind === SyntaxKind.SetAccessorSignature; } else { return container.kind === SyntaxKind.MethodDeclaration || container.kind === SyntaxKind.MethodSignature || container.kind === SyntaxKind.GetAccessor || container.kind === SyntaxKind.SetAccessor || + container.kind === SyntaxKind.GetAccessorSignature || + container.kind === SyntaxKind.SetAccessorSignature || container.kind === SyntaxKind.PropertyDeclaration || container.kind === SyntaxKind.PropertySignature || container.kind === SyntaxKind.Constructor; @@ -25861,7 +25877,7 @@ namespace ts { } } - function checkAccessorDeclaration(node: AccessorDeclaration) { + function checkAccessorDeclaration(node: AccessorLike) { if (produceDiagnostics) { // Grammar checking accessors if (!checkGrammarFunctionLikeDeclaration(node) && !checkGrammarAccessor(node)) checkGrammarComputedPropertyName(node.name); @@ -25884,8 +25900,9 @@ namespace ts { if (!hasNonBindableDynamicName(node)) { // TypeScript 1.0 spec (April 2014): 8.4.3 // Accessors for the same member name must specify the same accessibility. - const otherKind = node.kind === SyntaxKind.GetAccessor ? SyntaxKind.SetAccessor : SyntaxKind.GetAccessor; - const otherAccessor = getDeclarationOfKind(getSymbolOfNode(node), otherKind); + const symbol = getSymbolOfNode(node); + const otherAccessor = getDeclarationOfKind(symbol, getOtherAccessorDeclarationKind(node)) || + getDeclarationOfKind(symbol, getOtherAccessorSignatureKind(node)); if (otherAccessor) { const nodeFlags = getModifierFlags(node); const otherFlags = getModifierFlags(otherAccessor); @@ -25907,10 +25924,12 @@ namespace ts { checkAllCodePathsInNonVoidFunctionReturnOrThrow(node, returnType); } } - checkSourceElement(node.body); + if (isAccessorDeclaration(node)) { + checkSourceElement(node.body); + } } - function checkAccessorDeclarationTypesIdentical(first: AccessorDeclaration, second: AccessorDeclaration, getAnnotatedType: (a: AccessorDeclaration) => Type | undefined, message: DiagnosticMessage) { + function checkAccessorDeclarationTypesIdentical(first: AccessorLike, second: AccessorLike, getAnnotatedType: (a: AccessorLike) => Type | undefined, message: DiagnosticMessage) { const firstType = getAnnotatedType(first); const secondType = getAnnotatedType(second); if (firstType && secondType && !isTypeIdenticalTo(firstType, secondType)) { @@ -27199,6 +27218,8 @@ namespace ts { checkUnusedTypeParameters(node, addDiagnostic); break; case SyntaxKind.MethodSignature: + case SyntaxKind.GetAccessorSignature: + case SyntaxKind.SetAccessorSignature: case SyntaxKind.CallSignature: case SyntaxKind.ConstructSignature: case SyntaxKind.FunctionType: @@ -27471,7 +27492,9 @@ namespace ts { node.kind === SyntaxKind.MethodDeclaration || node.kind === SyntaxKind.MethodSignature || node.kind === SyntaxKind.GetAccessor || - node.kind === SyntaxKind.SetAccessor) { + node.kind === SyntaxKind.SetAccessor || + node.kind === SyntaxKind.GetAccessorSignature || + node.kind === SyntaxKind.SetAccessorSignature) { // it is ok to have member named '_super' or '_this' - member access is always qualified return false; } @@ -30326,6 +30349,8 @@ namespace ts { return checkConstructorDeclaration(node); case SyntaxKind.GetAccessor: case SyntaxKind.SetAccessor: + case SyntaxKind.GetAccessorSignature: + case SyntaxKind.SetAccessorSignature: return checkAccessorDeclaration(node); case SyntaxKind.TypeReference: return checkTypeReferenceNode(node); @@ -30564,7 +30589,9 @@ namespace ts { break; case SyntaxKind.GetAccessor: case SyntaxKind.SetAccessor: - checkAccessorDeclaration(node); + case SyntaxKind.GetAccessorSignature: + case SyntaxKind.SetAccessorSignature: + checkAccessorDeclaration(node); break; case SyntaxKind.ClassExpression: checkClassExpressionDeferred(node); @@ -31931,8 +31958,8 @@ namespace ts { }, getJsxFactoryEntity: location => location ? (getJsxNamespace(location), (getSourceFileOfNode(location).localJsxFactory || _jsxFactoryEntity)) : _jsxFactoryEntity, getAllAccessorDeclarations(accessor: AccessorDeclaration): AllAccessorDeclarations { - accessor = getParseTreeNode(accessor, isGetOrSetAccessorDeclaration)!; // TODO: GH#18217 - const otherKind = accessor.kind === SyntaxKind.SetAccessor ? SyntaxKind.GetAccessor : SyntaxKind.SetAccessor; + accessor = getParseTreeNode(accessor, isAccessorDeclaration)!; // TODO: GH#18217 + const otherKind = getOtherAccessorDeclarationKind(accessor); const otherAccessor = getDeclarationOfKind(getSymbolOfNode(accessor), otherKind); const firstAccessor = otherAccessor && (otherAccessor.pos < accessor.pos) ? otherAccessor : accessor; const secondAccessor = otherAccessor && (otherAccessor.pos < accessor.pos) ? accessor : otherAccessor; @@ -31945,6 +31972,21 @@ namespace ts { getAccessor }; }, + getAllAccessorSignatures(accessor: AccessorSignature): AllAccessorSignatures { + accessor = getParseTreeNode(accessor, isAccessorSignature)!; // TODO: GH#18217 + const otherKind = getOtherAccessorSignatureKind(accessor); + const otherAccessor = getDeclarationOfKind(getSymbolOfNode(accessor), otherKind); + const firstAccessor = otherAccessor && (otherAccessor.pos < accessor.pos) ? otherAccessor : accessor; + const secondAccessor = otherAccessor && (otherAccessor.pos < accessor.pos) ? accessor : otherAccessor; + const setAccessor = accessor.kind === SyntaxKind.SetAccessorSignature ? accessor : otherAccessor as SetAccessorSignature; + const getAccessor = accessor.kind === SyntaxKind.GetAccessorSignature ? accessor : otherAccessor as GetAccessorSignature; + return { + firstAccessor, + secondAccessor, + setAccessor, + getAccessor + }; + }, getSymbolOfExternalModuleSpecifier: moduleName => resolveExternalModuleNameWorker(moduleName, moduleName, /*moduleNotFoundError*/ undefined), isBindingCapturedByNode: (node, decl) => { const parseNode = getParseTreeNode(node); @@ -32493,6 +32535,8 @@ namespace ts { switch (node.kind) { case SyntaxKind.GetAccessor: case SyntaxKind.SetAccessor: + case SyntaxKind.GetAccessorSignature: + case SyntaxKind.SetAccessorSignature: case SyntaxKind.Constructor: case SyntaxKind.PropertyDeclaration: case SyntaxKind.PropertySignature: @@ -32624,7 +32668,7 @@ namespace ts { return false; } - function checkGrammarFunctionLikeDeclaration(node: FunctionLikeDeclaration | MethodSignature): boolean { + function checkGrammarFunctionLikeDeclaration(node: FunctionLikeDeclaration | MethodSignature | AccessorSignature): boolean { // Prevent cascading error by short-circuit const file = getSourceFileOfNode(node); return checkGrammarDecoratorsAndModifiers(node) || checkGrammarTypeParameterList(node.typeParameters, file) || @@ -33036,27 +33080,28 @@ namespace ts { return false; } - function checkGrammarAccessor(accessor: AccessorDeclaration): boolean { - const kind = accessor.kind; - if (languageVersion < ScriptTarget.ES5) { - return grammarErrorOnNode(accessor.name, Diagnostics.Accessors_are_only_available_when_targeting_ECMAScript_5_and_higher); - } - else if (accessor.body === undefined && !hasModifier(accessor, ModifierFlags.Abstract) && !(accessor.flags & NodeFlags.Ambient)) { - return grammarErrorAtPos(accessor, accessor.end - 1, ";".length, Diagnostics._0_expected, "{"); - } - else if (accessor.body && hasModifier(accessor, ModifierFlags.Abstract)) { - return grammarErrorOnNode(accessor, Diagnostics.An_abstract_accessor_cannot_have_an_implementation); + function checkGrammarAccessor(accessor: AccessorLike): boolean { + if (isAccessorDeclaration(accessor)) { + if (languageVersion < ScriptTarget.ES5) { + return grammarErrorOnNode(accessor.name, Diagnostics.Accessors_are_only_available_when_targeting_ECMAScript_5_and_higher); + } + else if (accessor.body === undefined && !hasModifier(accessor, ModifierFlags.Abstract) && !(accessor.flags & NodeFlags.Ambient)) { + return grammarErrorAtPos(accessor, accessor.end - 1, ";".length, Diagnostics._0_expected, "{"); + } + else if (accessor.body && hasModifier(accessor, ModifierFlags.Abstract)) { + return grammarErrorOnNode(accessor, Diagnostics.An_abstract_accessor_cannot_have_an_implementation); + } } - else if (accessor.typeParameters) { + if (accessor.typeParameters) { return grammarErrorOnNode(accessor.name, Diagnostics.An_accessor_cannot_have_type_parameters); } else if (!doesAccessorHaveCorrectParameterCount(accessor)) { return grammarErrorOnNode(accessor.name, - kind === SyntaxKind.GetAccessor ? + isGetAccessorLike(accessor) ? Diagnostics.A_get_accessor_cannot_have_parameters : Diagnostics.A_set_accessor_must_have_exactly_one_parameter); } - else if (kind === SyntaxKind.SetAccessor) { + else if (isSetAccessorLike(accessor)) { if (accessor.type) { return grammarErrorOnNode(accessor.name, Diagnostics.A_set_accessor_cannot_have_a_return_type_annotation); } @@ -33080,12 +33125,12 @@ namespace ts { * A get accessor has no parameters or a single `this` parameter. * A set accessor has one parameter or a `this` parameter and one more parameter. */ - function doesAccessorHaveCorrectParameterCount(accessor: AccessorDeclaration) { - return getAccessorThisParameter(accessor) || accessor.parameters.length === (accessor.kind === SyntaxKind.GetAccessor ? 0 : 1); + function doesAccessorHaveCorrectParameterCount(accessor: AccessorLike) { + return getAccessorThisParameter(accessor) || accessor.parameters.length === (isGetAccessorLike(accessor) ? 0 : 1); } - function getAccessorThisParameter(accessor: AccessorDeclaration): ParameterDeclaration | undefined { - if (accessor.parameters.length === (accessor.kind === SyntaxKind.GetAccessor ? 1 : 2)) { + function getAccessorThisParameter(accessor: AccessorLike): ParameterDeclaration | undefined { + if (accessor.parameters.length === (isGetAccessorLike(accessor) ? 1 : 2)) { return getThisParameter(accessor); } } diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index 5cca456dd4905..5abc9ee1e8a30 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -3036,6 +3036,27 @@ "code": 4105 }, + "Parameter type of setter '{0}' from exported interface has or is using name '{1}' from private module '{2}'.": { + "category": "Error", + "code": 4106 + }, + "Parameter type of setter '{0}' from exported interface has or is using private name '{1}'.": { + "category": "Error", + "code": 4107 + }, + "Return type of getter '{0}' from exported interface has or is using name '{1}' from external module {2} but cannot be named.": { + "category": "Error", + "code": 4108 + }, + "Return type of getter '{0}' from exported interface has or is using name '{1}' from private module '{2}'.": { + "category": "Error", + "code": 4109 + }, + "Return type of getter '{0}' from exported interface has or is using private name '{1}'.": { + "category": "Error", + "code": 4110 + }, + "The current host does not support the '{0}' option.": { "category": "Error", "code": 5001 diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index 8681a452e2a56..a1f3534b60d70 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -617,6 +617,7 @@ namespace ts { isLiteralConstDeclaration: notImplemented, getJsxFactoryEntity: notImplemented, getAllAccessorDeclarations: notImplemented, + getAllAccessorSignatures: notImplemented, getSymbolOfExternalModuleSpecifier: notImplemented, isBindingCapturedByNode: notImplemented, }; @@ -1211,6 +1212,9 @@ namespace ts { case SyntaxKind.GetAccessor: case SyntaxKind.SetAccessor: return emitAccessorDeclaration(node); + case SyntaxKind.GetAccessorSignature: + case SyntaxKind.SetAccessorSignature: + return emitAccessorSignature(node); case SyntaxKind.CallSignature: return emitCallSignature(node); case SyntaxKind.ConstructSignature: @@ -1865,6 +1869,19 @@ namespace ts { emitSignatureAndBody(node, emitSignatureHead); } + function emitAccessorSignature(node: AccessorSignature) { + pushNameGenerationScope(node); + emitDecorators(node, node.decorators); + emitModifiers(node, node.modifiers); + writeKeyword(node.kind === SyntaxKind.GetAccessorSignature ? "get" : "set"); + writeSpace(); + emit(node.name); + emitParameters(node, node.parameters); + emitTypeAnnotation(node.type); + writeTrailingSemicolon(); + popNameGenerationScope(node); + } + function emitCallSignature(node: CallSignatureDeclaration) { pushNameGenerationScope(node); emitDecorators(node, node.decorators); diff --git a/src/compiler/factory.ts b/src/compiler/factory.ts index 3a8ecb2099903..7ba691a3126f3 100644 --- a/src/compiler/factory.ts +++ b/src/compiler/factory.ts @@ -600,6 +600,66 @@ namespace ts { : node; } + export function createGetAccessorSignature( + decorators: ReadonlyArray | undefined, + modifiers: ReadonlyArray | undefined, + name: string | PropertyName, + parameters: ReadonlyArray, + type: TypeNode | undefined) { + const node = createSynthesizedNode(SyntaxKind.GetAccessorSignature); + node.decorators = asNodeArray(decorators); + node.modifiers = asNodeArray(modifiers); + node.name = asName(name); + node.typeParameters = undefined; + node.parameters = createNodeArray(parameters); + node.type = type; + return node; + } + + export function updateGetAccessorSignature( + node: GetAccessorSignature, + decorators: ReadonlyArray | undefined, + modifiers: ReadonlyArray | undefined, + name: PropertyName, + parameters: ReadonlyArray, + type: TypeNode | undefined) { + return node.decorators !== decorators + || node.modifiers !== modifiers + || node.name !== name + || node.parameters !== parameters + || node.type !== type + ? updateNode(createGetAccessorSignature(decorators, modifiers, name, parameters, type), node) + : node; + } + + export function createSetAccessorSignature( + decorators: ReadonlyArray | undefined, + modifiers: ReadonlyArray | undefined, + name: string | PropertyName, + parameters: ReadonlyArray) { + const node = createSynthesizedNode(SyntaxKind.SetAccessorSignature); + node.decorators = asNodeArray(decorators); + node.modifiers = asNodeArray(modifiers); + node.name = asName(name); + node.typeParameters = undefined; + node.parameters = createNodeArray(parameters); + return node; + } + + export function updateSetAccessorSignature( + node: SetAccessorSignature, + decorators: ReadonlyArray | undefined, + modifiers: ReadonlyArray | undefined, + name: PropertyName, + parameters: ReadonlyArray) { + return node.decorators !== decorators + || node.modifiers !== modifiers + || node.name !== name + || node.parameters !== parameters + ? updateNode(createSetAccessorSignature(decorators, modifiers, name, parameters), node) + : node; + } + export function createCallSignature(typeParameters: ReadonlyArray | undefined, parameters: ReadonlyArray, type: TypeNode | undefined) { return createSignatureDeclaration(SyntaxKind.CallSignature, typeParameters, parameters, type) as CallSignatureDeclaration; } diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index 704260e727961..9041ef5f85fbc 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -149,6 +149,8 @@ namespace ts { case SyntaxKind.Constructor: case SyntaxKind.GetAccessor: case SyntaxKind.SetAccessor: + case SyntaxKind.GetAccessorSignature: + case SyntaxKind.SetAccessorSignature: case SyntaxKind.FunctionExpression: case SyntaxKind.FunctionDeclaration: case SyntaxKind.ArrowFunction: @@ -2006,6 +2008,8 @@ namespace ts { switch (node.kind) { case SyntaxKind.ConstructSignature: case SyntaxKind.MethodSignature: + case SyntaxKind.GetAccessorSignature: + case SyntaxKind.SetAccessorSignature: case SyntaxKind.IndexSignature: case SyntaxKind.PropertySignature: case SyntaxKind.CallSignature: @@ -2702,6 +2706,14 @@ namespace ts { return finishNode(node); } + function parseAccessorSignature(node: AccessorSignature, kind: AccessorSignature["kind"]): AccessorSignature { + node.kind = kind; + node.name = parsePropertyName(); + fillSignature(SyntaxKind.ColonToken, SignatureFlags.Type, node); + parseTypeMemberSemicolon(); + return finishNode(node); + } + function parsePropertyOrMethodSignature(node: PropertySignature | MethodSignature): PropertySignature | MethodSignature { node.name = parsePropertyName(); node.questionToken = parseOptionalToken(SyntaxKind.QuestionToken); @@ -2730,10 +2742,10 @@ namespace ts { if (token() === SyntaxKind.OpenParenToken || token() === SyntaxKind.LessThanToken) { return true; } - let idToken = false; + let idToken: SyntaxKind | undefined; // Eat up all modifiers, but hold on to the last one in case it is actually an identifier while (isModifierKind(token())) { - idToken = true; + idToken = token(); nextToken(); } // Index signatures and computed property names are type members @@ -2742,12 +2754,17 @@ namespace ts { } // Try to get the first property-like token following all modifiers if (isLiteralPropertyName()) { - idToken = true; + idToken = token(); nextToken(); } // If we were able to get any potential identifier, check that it is // the start of a member declaration - if (idToken) { + if (idToken !== undefined) { + // If we have a non-keyword identifier, or if we have an accessor, then it's safe to parse. + if (!isKeyword(idToken) || idToken === SyntaxKind.SetKeyword || idToken === SyntaxKind.GetKeyword) { + return true; + } + return token() === SyntaxKind.OpenParenToken || token() === SyntaxKind.LessThanToken || token() === SyntaxKind.QuestionToken || @@ -2765,8 +2782,18 @@ namespace ts { if (token() === SyntaxKind.NewKeyword && lookAhead(nextTokenIsOpenParenOrLessThan)) { return parseSignatureMember(SyntaxKind.ConstructSignature); } + const node = createNodeWithJSDoc(SyntaxKind.Unknown); node.modifiers = parseModifiers(); + + if (parseContextualModifier(SyntaxKind.GetKeyword)) { + return parseAccessorSignature(node, SyntaxKind.GetAccessorSignature); + } + + if (parseContextualModifier(SyntaxKind.SetKeyword)) { + return parseAccessorSignature(node, SyntaxKind.SetAccessorSignature); + } + if (isIndexSignature()) { return parseIndexSignatureDeclaration(node); } diff --git a/src/compiler/transformers/declarations.ts b/src/compiler/transformers/declarations.ts index 6dfc909b93abd..d834e29f2f308 100644 --- a/src/compiler/transformers/declarations.ts +++ b/src/compiler/transformers/declarations.ts @@ -393,7 +393,24 @@ namespace ts { } } - function ensureParameter(p: ParameterDeclaration, modifierMask?: ModifierFlags): ParameterDeclaration { + function ensureParameter(node: Node, p: ParameterDeclaration, modifierMask?: ModifierFlags): ParameterDeclaration { + let type: TypeNode | undefined; + let name: BindingName | undefined; + let noType = false; + if (isAccessorLike(node) && !isThisIdentifier(p.name)) { + if (!hasModifier(node, ModifierFlags.Private)) { + type = p.type || (isAccessorDeclaration(node) + ? getTypeAnnotationFromAllAccessorDeclarations(node) + : getTypeAnnotationFromAllAccessorSignatures(node)); + } + else { + name = createIdentifier("value"); + noType = true; + } + } + else { + type = p.type; + } let oldDiag: typeof getSymbolAccessibilityDiagnostic | undefined; if (!suppressNewDiagnosticContexts) { oldDiag = getSymbolAccessibilityDiagnostic; @@ -404,9 +421,9 @@ namespace ts { /*decorators*/ undefined, maskModifiers(p, modifierMask), p.dotDotDotToken, - filterBindingPatternInitializers(p.name), + name || filterBindingPatternInitializers(p.name), resolver.isOptionalParameter(p) ? (p.questionToken || createToken(SyntaxKind.QuestionToken)) : undefined, - ensureType(p, p.type, /*ignorePrivate*/ true), // Ignore private param props, since this type is going straight back into a param + noType ? undefined : ensureType(p, type, /*ignorePrivate*/ true), // Ignore private param props, since this type is going straight back into a param ensureNoInitializer(p) ); if (!suppressNewDiagnosticContexts) { @@ -435,6 +452,8 @@ namespace ts { | ConstructSignatureDeclaration | VariableDeclaration | MethodSignature + | GetAccessorSignature + | SetAccessorSignature | CallSignatureDeclaration | ParameterDeclaration | PropertyDeclaration @@ -525,10 +544,10 @@ namespace ts { } function updateParamsList(node: Node, params: NodeArray, modifierMask?: ModifierFlags) { - if (hasModifier(node, ModifierFlags.Private)) { + if (hasModifier(node, ModifierFlags.Private) && !isSetAccessorLike(node)) { return undefined!; // TODO: GH#18217 } - const newParams = map(params, p => ensureParameter(p, modifierMask)); + const newParams = map(params, p => ensureParameter(node, p, modifierMask)); if (!newParams) { return undefined!; // TODO: GH#18217 } @@ -847,6 +866,24 @@ namespace ts { input.questionToken )); } + case SyntaxKind.GetAccessorSignature: { + const accessorType = getTypeAnnotationFromAllAccessorSignatures(input); + return cleanup(updateGetAccessorSignature( + input, + /*decorators*/ undefined, + ensureModifiers(input), + input.name, + updateParamsList(input, input.parameters), + !hasModifier(input, ModifierFlags.Private) ? ensureType(input, accessorType) : undefined)); + } + case SyntaxKind.SetAccessorSignature: { + return cleanup(updateSetAccessorSignature( + input, + /*decorators*/ undefined, + ensureModifiers(input), + input.name, + updateParamsList(input, input.parameters))); + } case SyntaxKind.CallSignature: { return cleanup(updateCallSignature( input, @@ -1374,17 +1411,35 @@ namespace ts { return maskModifierFlags(node, mask, additions); } - function ensureAccessor(node: AccessorDeclaration): PropertyDeclaration | undefined { + function getTypeAnnotationFromAllAccessorDeclarations(node: AccessorDeclaration) { const accessors = resolver.getAllAccessorDeclarations(node); - if (node.kind !== accessors.firstAccessor.kind) { - return; + let accessorType = getTypeAnnotationFromAccessor(node); + if (!accessorType && accessors.secondAccessor) { + accessorType = getTypeAnnotationFromAccessor(accessors.secondAccessor); + // If we end up pulling the type from the second accessor, we also need to change the diagnostic context to get the expected error message + getSymbolAccessibilityDiagnostic = createGetSymbolAccessibilityDiagnosticForNode(accessors.secondAccessor); } + return accessorType; + } + + function getTypeAnnotationFromAllAccessorSignatures(node: AccessorSignature) { + const accessors = resolver.getAllAccessorSignatures(node); let accessorType = getTypeAnnotationFromAccessor(node); if (!accessorType && accessors.secondAccessor) { accessorType = getTypeAnnotationFromAccessor(accessors.secondAccessor); // If we end up pulling the type from the second accessor, we also need to change the diagnostic context to get the expected error message getSymbolAccessibilityDiagnostic = createGetSymbolAccessibilityDiagnosticForNode(accessors.secondAccessor); } + return accessorType; + } + + function ensureAccessor(node: AccessorDeclaration): PropertyDeclaration | undefined { + const accessors = resolver.getAllAccessorDeclarations(node); + if (node.kind !== accessors.firstAccessor.kind) { + return; + } + + const accessorType = getTypeAnnotationFromAllAccessorDeclarations(node); const prop = createProperty(/*decorators*/ undefined, maskModifiers(node, /*mask*/ undefined, (!accessors.setAccessor) ? ModifierFlags.Readonly : ModifierFlags.None), node.name, node.questionToken, ensureType(node, accessorType), /*initializer*/ undefined); const leadingsSyntheticCommentRanges = accessors.secondAccessor && getLeadingCommentRangesOfNode(accessors.secondAccessor, currentSourceFile); if (leadingsSyntheticCommentRanges) { @@ -1441,9 +1496,9 @@ namespace ts { return flags; } - function getTypeAnnotationFromAccessor(accessor: AccessorDeclaration): TypeNode | undefined { + function getTypeAnnotationFromAccessor(accessor: AccessorLike): TypeNode | undefined { if (accessor) { - return accessor.kind === SyntaxKind.GetAccessor + return isGetAccessorLike(accessor) ? accessor.type // Getter - return type : accessor.parameters.length > 0 ? accessor.parameters[0].type // Setter parameter type @@ -1501,6 +1556,8 @@ namespace ts { | MethodDeclaration | GetAccessorDeclaration | SetAccessorDeclaration + | GetAccessorSignature + | SetAccessorSignature | PropertyDeclaration | PropertySignature | MethodSignature @@ -1522,6 +1579,8 @@ namespace ts { case SyntaxKind.MethodDeclaration: case SyntaxKind.GetAccessor: case SyntaxKind.SetAccessor: + case SyntaxKind.GetAccessorSignature: + case SyntaxKind.SetAccessorSignature: case SyntaxKind.PropertyDeclaration: case SyntaxKind.PropertySignature: case SyntaxKind.MethodSignature: diff --git a/src/compiler/transformers/declarations/diagnostics.ts b/src/compiler/transformers/declarations/diagnostics.ts index 33465799c29e8..ca679864b6746 100644 --- a/src/compiler/transformers/declarations/diagnostics.ts +++ b/src/compiler/transformers/declarations/diagnostics.ts @@ -15,6 +15,8 @@ namespace ts { | BindingElement | SetAccessorDeclaration | GetAccessorDeclaration + | SetAccessorSignature + | GetAccessorSignature | ConstructSignatureDeclaration | CallSignatureDeclaration | MethodDeclaration @@ -34,8 +36,10 @@ namespace ts { isPropertyDeclaration(node) || isPropertySignature(node) || isBindingElement(node) || - isSetAccessor(node) || - isGetAccessor(node) || + isSetAccessorDeclaration(node) || + isGetAccessorDeclaration(node) || + isSetAccessorSignature(node) || + isGetAccessorSignature(node) || isConstructSignatureDeclaration(node) || isCallSignatureDeclaration(node) || isMethodDeclaration(node) || @@ -131,6 +135,9 @@ namespace ts { else if (isSetAccessor(node) || isGetAccessor(node)) { return getAccessorDeclarationTypeVisibilityError; } + else if (isAccessorSignature(node)) { + return getAccessorSignatureTypeVisibilityError; + } else if (isConstructSignatureDeclaration(node) || isCallSignatureDeclaration(node) || isMethodDeclaration(node) || isMethodSignature(node) || isFunctionDeclaration(node) || isIndexSignatureDeclaration(node)) { return getReturnTypeVisibilityError; } @@ -240,6 +247,29 @@ namespace ts { }; } + function getAccessorSignatureTypeVisibilityError(symbolAccessibilityResult: SymbolAccessibilityResult): SymbolAccessibilityDiagnostic { + let diagnosticMessage: DiagnosticMessage; + if (node.kind === SyntaxKind.SetAccessorSignature) { + // Getters can infer the return type from the returned expression, but setters cannot, so the + // "_from_external_module_1_but_cannot_be_named" case cannot occur. + diagnosticMessage = symbolAccessibilityResult.errorModuleName ? + Diagnostics.Parameter_type_of_setter_0_from_exported_interface_has_or_is_using_name_1_from_private_module_2 : + Diagnostics.Parameter_type_of_setter_0_from_exported_interface_has_or_is_using_private_name_1; + } + else { + diagnosticMessage = symbolAccessibilityResult.errorModuleName ? + symbolAccessibilityResult.accessibility === SymbolAccessibility.CannotBeNamed ? + Diagnostics.Return_type_of_getter_0_from_exported_interface_has_or_is_using_name_1_from_external_module_2_but_cannot_be_named : + Diagnostics.Return_type_of_getter_0_from_exported_interface_has_or_is_using_name_1_from_private_module_2 : + Diagnostics.Return_type_of_getter_0_from_exported_interface_has_or_is_using_private_name_1; + } + return { + diagnosticMessage, + errorNode: (node as NamedDeclaration).name!, + typeName: (node as NamedDeclaration).name + }; + } + function getReturnTypeVisibilityError(symbolAccessibilityResult: SymbolAccessibilityResult): SymbolAccessibilityDiagnostic { let diagnosticMessage: DiagnosticMessage; switch (node.kind) { diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 3f1b30feb4526..a57e5d7766ae5 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -295,7 +295,9 @@ namespace ts { MethodDeclaration, Constructor, GetAccessor, + GetAccessorSignature, SetAccessor, + SetAccessorSignature, CallSignature, ConstructSignature, IndexSignature, @@ -648,6 +650,7 @@ namespace ts { | ConstructSignatureDeclaration | MethodSignature | PropertySignature + | AccessorSignature | ArrowFunction | ParenthesizedExpression | SpreadAssignment @@ -871,6 +874,7 @@ namespace ts { | CallSignatureDeclaration | ConstructSignatureDeclaration | MethodSignature + | AccessorSignature | IndexSignatureDeclaration | FunctionTypeNode | ConstructorTypeNode @@ -1109,6 +1113,23 @@ namespace ts { export type AccessorDeclaration = GetAccessorDeclaration | SetAccessorDeclaration; + export interface GetAccessorSignature extends SignatureDeclarationBase, TypeElement { + kind: SyntaxKind.GetAccessorSignature; + parent: ObjectTypeDeclaration; + name: PropertyName; + } + + export interface SetAccessorSignature extends SignatureDeclarationBase, TypeElement { + kind: SyntaxKind.SetAccessorSignature; + parent: ObjectTypeDeclaration; + name: PropertyName; + } + + export type AccessorSignature = GetAccessorSignature | SetAccessorSignature; + export type GetAccessorLike = GetAccessorDeclaration | GetAccessorSignature; + export type SetAccessorLike = SetAccessorDeclaration | SetAccessorSignature; + export type AccessorLike = AccessorDeclaration | AccessorSignature; + export interface IndexSignatureDeclaration extends SignatureDeclarationBase, ClassElement, TypeElement { kind: SyntaxKind.IndexSignature; parent: ObjectTypeDeclaration; @@ -3560,6 +3581,14 @@ namespace ts { setAccessor: SetAccessorDeclaration | undefined; } + /* @internal */ + export interface AllAccessorSignatures { + firstAccessor: AccessorSignature; + secondAccessor: AccessorSignature | undefined; + getAccessor: GetAccessorSignature | undefined; + setAccessor: SetAccessorSignature | undefined; + } + /** Indicates how to serialize the name for a TypeReferenceNode when emitting decorator metadata */ /* @internal */ export enum TypeReferenceSerializationKind { @@ -3620,6 +3649,7 @@ namespace ts { isLiteralConstDeclaration(node: VariableDeclaration | PropertyDeclaration | PropertySignature | ParameterDeclaration): boolean; getJsxFactoryEntity(location?: Node): EntityName | undefined; getAllAccessorDeclarations(declaration: AccessorDeclaration): AllAccessorDeclarations; + getAllAccessorSignatures(declaration: AccessorSignature): AllAccessorSignatures; getSymbolOfExternalModuleSpecifier(node: StringLiteralLike): Symbol | undefined; isBindingCapturedByNode(node: Node, decl: VariableDeclaration | BindingElement): boolean; } diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index 4ca13e663ab18..07947b5371240 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -746,6 +746,8 @@ namespace ts { case SyntaxKind.CallSignature: case SyntaxKind.ConstructSignature: case SyntaxKind.MethodSignature: + case SyntaxKind.GetAccessorSignature: + case SyntaxKind.SetAccessorSignature: case SyntaxKind.IndexSignature: case SyntaxKind.FunctionType: case SyntaxKind.ConstructorType: @@ -921,6 +923,8 @@ namespace ts { case SyntaxKind.MethodDeclaration: case SyntaxKind.GetAccessor: case SyntaxKind.SetAccessor: + case SyntaxKind.GetAccessorSignature: + case SyntaxKind.SetAccessorSignature: case SyntaxKind.TypeAliasDeclaration: case SyntaxKind.PropertyDeclaration: case SyntaxKind.PropertySignature: @@ -1097,6 +1101,8 @@ namespace ts { case SyntaxKind.MethodSignature: case SyntaxKind.GetAccessor: case SyntaxKind.SetAccessor: + case SyntaxKind.GetAccessorSignature: + case SyntaxKind.SetAccessorSignature: return node === (parent).type; case SyntaxKind.CallSignature: case SyntaxKind.ConstructSignature: @@ -1400,6 +1406,8 @@ namespace ts { case SyntaxKind.Constructor: case SyntaxKind.GetAccessor: case SyntaxKind.SetAccessor: + case SyntaxKind.GetAccessorSignature: + case SyntaxKind.SetAccessorSignature: case SyntaxKind.CallSignature: case SyntaxKind.ConstructSignature: case SyntaxKind.IndexSignature: @@ -1456,6 +1464,8 @@ namespace ts { case SyntaxKind.Constructor: case SyntaxKind.GetAccessor: case SyntaxKind.SetAccessor: + case SyntaxKind.GetAccessorSignature: + case SyntaxKind.SetAccessorSignature: return node; case SyntaxKind.Decorator: // Decorators are always applied outside of the body of a class or method. @@ -2520,6 +2530,8 @@ namespace ts { case SyntaxKind.MethodSignature: case SyntaxKind.GetAccessor: case SyntaxKind.SetAccessor: + case SyntaxKind.GetAccessorSignature: + case SyntaxKind.SetAccessorSignature: case SyntaxKind.EnumMember: case SyntaxKind.PropertyAssignment: case SyntaxKind.PropertyAccessExpression: @@ -3518,7 +3530,7 @@ namespace ts { return find(node.members, (member): member is ConstructorDeclaration & { body: FunctionBody } => isConstructorDeclaration(member) && nodeIsPresent(member.body)); } - function getSetAccessorValueParameter(accessor: SetAccessorDeclaration): ParameterDeclaration | undefined { + function getSetAccessorValueParameter(accessor: SetAccessorLike): ParameterDeclaration | undefined { if (accessor && accessor.parameters.length > 0) { const hasThis = accessor.parameters.length === 2 && parameterIsThisKeyword(accessor.parameters[0]); return accessor.parameters[hasThis ? 1 : 0]; @@ -3526,7 +3538,7 @@ namespace ts { } /** Get the type annotation for the value parameter. */ - export function getSetAccessorTypeAnnotationNode(accessor: SetAccessorDeclaration): TypeNode | undefined { + export function getSetAccessorTypeAnnotationNode(accessor: SetAccessorLike): TypeNode | undefined { const parameter = getSetAccessorValueParameter(accessor); return parameter && parameter.type; } @@ -3553,6 +3565,23 @@ namespace ts { return id.originalKeywordKind === SyntaxKind.ThisKeyword; } + export function getOtherAccessorLikeKind(node: AccessorLike) { + return isGetAccessorDeclaration(node) ? SyntaxKind.SetAccessor : + isGetAccessorSignature(node) ? SyntaxKind.SetAccessorSignature : + isSetAccessorDeclaration(node) ? SyntaxKind.GetAccessor : + SyntaxKind.GetAccessorSignature; + } + + export function getOtherAccessorDeclarationKind(node: AccessorLike) { + return isGetAccessorLike(node) ? SyntaxKind.SetAccessor : + SyntaxKind.GetAccessor; + } + + export function getOtherAccessorSignatureKind(node: AccessorLike) { + return isGetAccessorLike(node) ? SyntaxKind.SetAccessorSignature : + SyntaxKind.GetAccessorSignature; + } + export function getAllAccessorDeclarations(declarations: NodeArray, accessor: AccessorDeclaration): AllAccessorDeclarations { // TODO: GH#18217 let firstAccessor!: AccessorDeclaration; @@ -3641,7 +3670,7 @@ namespace ts { * Gets the effective type annotation of the value parameter of a set accessor. If the node * was parsed in a JavaScript file, gets the type annotation from JSDoc. */ - export function getEffectiveSetAccessorTypeAnnotationNode(node: SetAccessorDeclaration): TypeNode | undefined { + export function getEffectiveSetAccessorTypeAnnotationNode(node: SetAccessorLike): TypeNode | undefined { const parameter = getSetAccessorValueParameter(node); return parameter && getEffectiveTypeAnnotationNode(parameter); } @@ -5541,6 +5570,46 @@ namespace ts { return node.kind === SyntaxKind.SetAccessor; } + export function isGetAccessorSignature(node: Node): node is GetAccessorSignature { + return node.kind === SyntaxKind.GetAccessorSignature; + } + + export function isSetAccessorSignature(node: Node): node is SetAccessorSignature { + return node.kind === SyntaxKind.SetAccessorSignature; + } + + export function isGetAccessorLike(node: Node): node is GetAccessorLike { + const kind = node.kind; + return kind === SyntaxKind.GetAccessor + || kind === SyntaxKind.GetAccessorSignature; + } + + export function isSetAccessorLike(node: Node): node is SetAccessorLike { + const kind = node.kind; + return kind === SyntaxKind.SetAccessor + || kind === SyntaxKind.SetAccessorSignature; + } + + export function isAccessorDeclaration(node: Node): node is AccessorDeclaration { + const kind = node.kind; + return kind === SyntaxKind.GetAccessor + || kind === SyntaxKind.SetAccessor; + } + + export function isAccessorSignature(node: Node): node is AccessorSignature { + const kind = node.kind; + return kind === SyntaxKind.GetAccessorSignature + || kind === SyntaxKind.SetAccessorSignature; + } + + export function isAccessorLike(node: Node): node is AccessorLike { + const kind = node.kind; + return kind === SyntaxKind.GetAccessor + || kind === SyntaxKind.GetAccessorSignature + || kind === SyntaxKind.SetAccessor + || kind === SyntaxKind.SetAccessorSignature; + } + export function isCallSignatureDeclaration(node: Node): node is CallSignatureDeclaration { return node.kind === SyntaxKind.CallSignature; } @@ -5553,9 +5622,10 @@ namespace ts { return node.kind === SyntaxKind.IndexSignature; } + /** @deprecated Use `isAccessorDeclaration` instead. */ /* @internal */ export function isGetOrSetAccessorDeclaration(node: Node): node is AccessorDeclaration { - return node.kind === SyntaxKind.SetAccessor || node.kind === SyntaxKind.GetAccessor; + return isAccessorDeclaration(node); } // Type @@ -6347,6 +6417,8 @@ namespace ts { export function isFunctionLikeKind(kind: SyntaxKind): boolean { switch (kind) { case SyntaxKind.MethodSignature: + case SyntaxKind.GetAccessorSignature: + case SyntaxKind.SetAccessorSignature: case SyntaxKind.CallSignature: case SyntaxKind.JSDocSignature: case SyntaxKind.ConstructSignature: @@ -6381,8 +6453,9 @@ namespace ts { return node && (node.kind === SyntaxKind.ClassDeclaration || node.kind === SyntaxKind.ClassExpression); } + /** @deprecated Use `isAccessorDeclaration` instead. */ export function isAccessor(node: Node): node is AccessorDeclaration { - return node && (node.kind === SyntaxKind.GetAccessor || node.kind === SyntaxKind.SetAccessor); + return isAccessorDeclaration(node); } /* @internal */ @@ -6405,6 +6478,8 @@ namespace ts { || kind === SyntaxKind.CallSignature || kind === SyntaxKind.PropertySignature || kind === SyntaxKind.MethodSignature + || kind === SyntaxKind.GetAccessorSignature + || kind === SyntaxKind.SetAccessorSignature || kind === SyntaxKind.IndexSignature; } @@ -6955,12 +7030,14 @@ namespace ts { return node.kind >= SyntaxKind.FirstJSDocTagNode && node.kind <= SyntaxKind.LastJSDocTagNode; } + /** @deprecated Use `isSetAccessorDeclaration` instead. */ export function isSetAccessor(node: Node): node is SetAccessorDeclaration { - return node.kind === SyntaxKind.SetAccessor; + return isSetAccessorDeclaration(node); } + /** @deprecated Use `isGetAccessorDeclaration` instead. */ export function isGetAccessor(node: Node): node is GetAccessorDeclaration { - return node.kind === SyntaxKind.GetAccessor; + return isGetAccessorDeclaration(node); } /** True if has jsdoc nodes attached to it. */ diff --git a/src/compiler/visitor.ts b/src/compiler/visitor.ts index 53ccd81f7a6a3..eb25da4a96f56 100644 --- a/src/compiler/visitor.ts +++ b/src/compiler/visitor.ts @@ -317,6 +317,21 @@ namespace ts { visitParameterList((node).parameters, visitor, context, nodesVisitor), visitFunctionBody((node).body!, visitor, context)); + case SyntaxKind.GetAccessorSignature: + return updateGetAccessorSignature(node, + nodesVisitor((node).decorators, visitor, isDecorator), + nodesVisitor((node).modifiers, visitor, isModifier), + visitNode((node).name, visitor, isPropertyName), + nodesVisitor((node).parameters, visitor, isParameter), + visitNode((node).type, visitor, isTypeNode)); + + case SyntaxKind.SetAccessorSignature: + return updateSetAccessorSignature(node, + nodesVisitor((node).decorators, visitor, isDecorator), + nodesVisitor((node).modifiers, visitor, isModifier), + visitNode((node).name, visitor, isPropertyName), + visitNodes((node).parameters, visitor, isParameter)); + case SyntaxKind.CallSignature: return updateCallSignature(node, nodesVisitor((node).typeParameters, visitor, isTypeParameterDeclaration), @@ -1034,6 +1049,15 @@ namespace ts { result = reduceNode((node).initializer, cbNode, result); break; + case SyntaxKind.MethodSignature: + result = reduceNodes((node).decorators, cbNodes, result); + result = reduceNodes((node).modifiers, cbNodes, result); + result = reduceNode((node).name, cbNode, result); + result = reduceNodes((node).typeParameters, cbNodes, result); + result = reduceNodes((node).parameters, cbNodes, result); + result = reduceNode((node).type, cbNode, result); + break; + case SyntaxKind.MethodDeclaration: result = reduceNodes((node).decorators, cbNodes, result); result = reduceNodes((node).modifiers, cbNodes, result); @@ -1060,11 +1084,26 @@ namespace ts { break; case SyntaxKind.SetAccessor: - result = reduceNodes((node).decorators, cbNodes, result); - result = reduceNodes((node).modifiers, cbNodes, result); - result = reduceNode((node).name, cbNode, result); - result = reduceNodes((node).parameters, cbNodes, result); - result = reduceNode((node).body, cbNode, result); + result = reduceNodes((node).decorators, cbNodes, result); + result = reduceNodes((node).modifiers, cbNodes, result); + result = reduceNode((node).name, cbNode, result); + result = reduceNodes((node).parameters, cbNodes, result); + result = reduceNode((node).body, cbNode, result); + break; + + case SyntaxKind.GetAccessorSignature: + result = reduceNodes((node).decorators, cbNodes, result); + result = reduceNodes((node).modifiers, cbNodes, result); + result = reduceNode((node).name, cbNode, result); + result = reduceNodes((node).parameters, cbNodes, result); + result = reduceNode((node).type, cbNode, result); + break; + + case SyntaxKind.SetAccessorSignature: + result = reduceNodes((node).decorators, cbNodes, result); + result = reduceNodes((node).modifiers, cbNodes, result); + result = reduceNode((node).name, cbNode, result); + result = reduceNodes((node).parameters, cbNodes, result); break; // Binding patterns From 4e8ffd8e4fafcad7af9d7b0784cfe0e5b7a8b1e1 Mon Sep 17 00:00:00 2001 From: Ron Buckton Date: Wed, 7 Aug 2019 16:26:08 -0700 Subject: [PATCH 3/4] Add basic test cases for accessors in interfaces and ambient classes --- src/compiler/checker.ts | 14 +++++++----- src/compiler/transformers/declarations.ts | 22 +++++++++++++++++++ .../reference/ambientAccessors(target=es3).js | 19 ++++++++++++++++ .../ambientAccessors(target=es3).symbols | 19 ++++++++++++++++ .../ambientAccessors(target=es3).types | 19 ++++++++++++++++ .../reference/ambientAccessors(target=es5).js | 19 ++++++++++++++++ .../ambientAccessors(target=es5).symbols | 19 ++++++++++++++++ .../ambientAccessors(target=es5).types | 19 ++++++++++++++++ .../ambientAccessors.ts | 9 ++++++++ .../interfaceWithAccessors.ts | 15 +++++++++++++ 10 files changed, 168 insertions(+), 6 deletions(-) create mode 100644 tests/baselines/reference/ambientAccessors(target=es3).js create mode 100644 tests/baselines/reference/ambientAccessors(target=es3).symbols create mode 100644 tests/baselines/reference/ambientAccessors(target=es3).types create mode 100644 tests/baselines/reference/ambientAccessors(target=es5).js create mode 100644 tests/baselines/reference/ambientAccessors(target=es5).symbols create mode 100644 tests/baselines/reference/ambientAccessors(target=es5).types create mode 100644 tests/cases/conformance/classes/propertyMemberDeclarations/memberAccessorDeclarations/ambientAccessors.ts create mode 100644 tests/cases/conformance/interfaces/interfaceDeclarations/interfaceWithAccessors.ts diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 60ecfdb2cf141..ed68db53803e0 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -33082,13 +33082,15 @@ namespace ts { function checkGrammarAccessor(accessor: AccessorLike): boolean { if (isAccessorDeclaration(accessor)) { - if (languageVersion < ScriptTarget.ES5) { - return grammarErrorOnNode(accessor.name, Diagnostics.Accessors_are_only_available_when_targeting_ECMAScript_5_and_higher); - } - else if (accessor.body === undefined && !hasModifier(accessor, ModifierFlags.Abstract) && !(accessor.flags & NodeFlags.Ambient)) { - return grammarErrorAtPos(accessor, accessor.end - 1, ";".length, Diagnostics._0_expected, "{"); + if (!(accessor.flags & NodeFlags.Ambient)) { + if (languageVersion < ScriptTarget.ES5) { + return grammarErrorOnNode(accessor.name, Diagnostics.Accessors_are_only_available_when_targeting_ECMAScript_5_and_higher); + } + else if (accessor.body === undefined && !hasModifier(accessor, ModifierFlags.Abstract) && !(accessor.flags & NodeFlags.Ambient)) { + return grammarErrorAtPos(accessor, accessor.end - 1, ";".length, Diagnostics._0_expected, "{"); + } } - else if (accessor.body && hasModifier(accessor, ModifierFlags.Abstract)) { + if (accessor.body && hasModifier(accessor, ModifierFlags.Abstract)) { return grammarErrorOnNode(accessor, Diagnostics.An_abstract_accessor_cannot_have_an_implementation); } } diff --git a/src/compiler/transformers/declarations.ts b/src/compiler/transformers/declarations.ts index d834e29f2f308..ea0b5488cec24 100644 --- a/src/compiler/transformers/declarations.ts +++ b/src/compiler/transformers/declarations.ts @@ -830,10 +830,32 @@ namespace ts { return cleanup(sig); } case SyntaxKind.GetAccessor: { + // For now, only emit class accessors as accessors if they were already declared in an ambient context. + if (input.flags & NodeFlags.Ambient) { + const accessorType = getTypeAnnotationFromAllAccessorDeclarations(input); + return cleanup(updateGetAccessor( + input, + /*decorators*/ undefined, + ensureModifiers(input), + input.name, + updateParamsList(input, input.parameters), + !hasModifier(input, ModifierFlags.Private) ? ensureType(input, accessorType) : undefined, + /*body*/ undefined)); + } const newNode = ensureAccessor(input); return cleanup(newNode); } case SyntaxKind.SetAccessor: { + // For now, only emit class accessors as accessors if they were already declared in an ambient context. + if (input.flags & NodeFlags.Ambient) { + return cleanup(updateSetAccessor( + input, + /*decorators*/ undefined, + ensureModifiers(input), + input.name, + updateParamsList(input, input.parameters), + /*body*/ undefined)); + } const newNode = ensureAccessor(input); return cleanup(newNode); } diff --git a/tests/baselines/reference/ambientAccessors(target=es3).js b/tests/baselines/reference/ambientAccessors(target=es3).js new file mode 100644 index 0000000000000..120e871927072 --- /dev/null +++ b/tests/baselines/reference/ambientAccessors(target=es3).js @@ -0,0 +1,19 @@ +//// [ambientAccessors.ts] +// ok to use accessors in ambient class in ES3 +declare class C { + get x(): string; + set x(value: string); + static get y(): string; + static set y(value: string); +} + +//// [ambientAccessors.js] + + +//// [ambientAccessors.d.ts] +declare class C { + get x(): string; + set x(value: string); + static get y(): string; + static set y(value: string); +} diff --git a/tests/baselines/reference/ambientAccessors(target=es3).symbols b/tests/baselines/reference/ambientAccessors(target=es3).symbols new file mode 100644 index 0000000000000..6076622b82569 --- /dev/null +++ b/tests/baselines/reference/ambientAccessors(target=es3).symbols @@ -0,0 +1,19 @@ +=== tests/cases/conformance/classes/propertyMemberDeclarations/memberAccessorDeclarations/ambientAccessors.ts === +// ok to use accessors in ambient class in ES3 +declare class C { +>C : Symbol(C, Decl(ambientAccessors.ts, 0, 0)) + + get x(): string; +>x : Symbol(C.x, Decl(ambientAccessors.ts, 1, 17), Decl(ambientAccessors.ts, 2, 20)) + + set x(value: string); +>x : Symbol(C.x, Decl(ambientAccessors.ts, 1, 17), Decl(ambientAccessors.ts, 2, 20)) +>value : Symbol(value, Decl(ambientAccessors.ts, 3, 10)) + + static get y(): string; +>y : Symbol(C.y, Decl(ambientAccessors.ts, 3, 25), Decl(ambientAccessors.ts, 4, 27)) + + static set y(value: string); +>y : Symbol(C.y, Decl(ambientAccessors.ts, 3, 25), Decl(ambientAccessors.ts, 4, 27)) +>value : Symbol(value, Decl(ambientAccessors.ts, 5, 17)) +} diff --git a/tests/baselines/reference/ambientAccessors(target=es3).types b/tests/baselines/reference/ambientAccessors(target=es3).types new file mode 100644 index 0000000000000..dc5fb2c7d6c06 --- /dev/null +++ b/tests/baselines/reference/ambientAccessors(target=es3).types @@ -0,0 +1,19 @@ +=== tests/cases/conformance/classes/propertyMemberDeclarations/memberAccessorDeclarations/ambientAccessors.ts === +// ok to use accessors in ambient class in ES3 +declare class C { +>C : C + + get x(): string; +>x : string + + set x(value: string); +>x : string +>value : string + + static get y(): string; +>y : string + + static set y(value: string); +>y : string +>value : string +} diff --git a/tests/baselines/reference/ambientAccessors(target=es5).js b/tests/baselines/reference/ambientAccessors(target=es5).js new file mode 100644 index 0000000000000..120e871927072 --- /dev/null +++ b/tests/baselines/reference/ambientAccessors(target=es5).js @@ -0,0 +1,19 @@ +//// [ambientAccessors.ts] +// ok to use accessors in ambient class in ES3 +declare class C { + get x(): string; + set x(value: string); + static get y(): string; + static set y(value: string); +} + +//// [ambientAccessors.js] + + +//// [ambientAccessors.d.ts] +declare class C { + get x(): string; + set x(value: string); + static get y(): string; + static set y(value: string); +} diff --git a/tests/baselines/reference/ambientAccessors(target=es5).symbols b/tests/baselines/reference/ambientAccessors(target=es5).symbols new file mode 100644 index 0000000000000..6076622b82569 --- /dev/null +++ b/tests/baselines/reference/ambientAccessors(target=es5).symbols @@ -0,0 +1,19 @@ +=== tests/cases/conformance/classes/propertyMemberDeclarations/memberAccessorDeclarations/ambientAccessors.ts === +// ok to use accessors in ambient class in ES3 +declare class C { +>C : Symbol(C, Decl(ambientAccessors.ts, 0, 0)) + + get x(): string; +>x : Symbol(C.x, Decl(ambientAccessors.ts, 1, 17), Decl(ambientAccessors.ts, 2, 20)) + + set x(value: string); +>x : Symbol(C.x, Decl(ambientAccessors.ts, 1, 17), Decl(ambientAccessors.ts, 2, 20)) +>value : Symbol(value, Decl(ambientAccessors.ts, 3, 10)) + + static get y(): string; +>y : Symbol(C.y, Decl(ambientAccessors.ts, 3, 25), Decl(ambientAccessors.ts, 4, 27)) + + static set y(value: string); +>y : Symbol(C.y, Decl(ambientAccessors.ts, 3, 25), Decl(ambientAccessors.ts, 4, 27)) +>value : Symbol(value, Decl(ambientAccessors.ts, 5, 17)) +} diff --git a/tests/baselines/reference/ambientAccessors(target=es5).types b/tests/baselines/reference/ambientAccessors(target=es5).types new file mode 100644 index 0000000000000..dc5fb2c7d6c06 --- /dev/null +++ b/tests/baselines/reference/ambientAccessors(target=es5).types @@ -0,0 +1,19 @@ +=== tests/cases/conformance/classes/propertyMemberDeclarations/memberAccessorDeclarations/ambientAccessors.ts === +// ok to use accessors in ambient class in ES3 +declare class C { +>C : C + + get x(): string; +>x : string + + set x(value: string); +>x : string +>value : string + + static get y(): string; +>y : string + + static set y(value: string); +>y : string +>value : string +} diff --git a/tests/cases/conformance/classes/propertyMemberDeclarations/memberAccessorDeclarations/ambientAccessors.ts b/tests/cases/conformance/classes/propertyMemberDeclarations/memberAccessorDeclarations/ambientAccessors.ts new file mode 100644 index 0000000000000..a13ea412df651 --- /dev/null +++ b/tests/cases/conformance/classes/propertyMemberDeclarations/memberAccessorDeclarations/ambientAccessors.ts @@ -0,0 +1,9 @@ +// @target: es3, es5 +// @declaration: true +// ok to use accessors in ambient class in ES3 +declare class C { + get x(): string; + set x(value: string); + static get y(): string; + static set y(value: string); +} \ No newline at end of file diff --git a/tests/cases/conformance/interfaces/interfaceDeclarations/interfaceWithAccessors.ts b/tests/cases/conformance/interfaces/interfaceDeclarations/interfaceWithAccessors.ts new file mode 100644 index 0000000000000..087c7fca01f96 --- /dev/null +++ b/tests/cases/conformance/interfaces/interfaceDeclarations/interfaceWithAccessors.ts @@ -0,0 +1,15 @@ +// @target: esnext +// @declaration: true +interface I0 { + get x(): number; + set x(value); +} + +interface I1 { + get x(): number; +} + +interface I1 { + set x(value); +} + From 62264392d2163150d823c1741bee3a24c8502d1c Mon Sep 17 00:00:00 2001 From: Ron Buckton Date: Thu, 8 Aug 2019 17:58:05 -0700 Subject: [PATCH 4/4] Support accessors in interfaces in the language service --- src/compiler/checker.ts | 206 ++++++++++-------- src/compiler/program.ts | 2 + src/compiler/types.ts | 13 +- src/compiler/utilities.ts | 68 +++++- src/harness/fourslash.ts | 3 + src/services/breakpoints.ts | 4 + src/services/codefixes/fixJSDocTypes.ts | 26 ++- src/services/codefixes/helpers.ts | 49 ++++- src/services/completions.ts | 9 +- src/services/findAllReferences.ts | 6 + src/services/formatting/rules.ts | 4 +- src/services/formatting/smartIndenter.ts | 2 + src/services/navigationBar.ts | 2 + src/services/services.ts | 2 + src/services/utilities.ts | 16 +- ...turesWithParameterInitializers2.errors.txt | 8 +- ...gnaturesWithParameterInitializers2.symbols | 12 +- ...SignaturesWithParameterInitializers2.types | 24 +- .../classWithDuplicateIdentifier.errors.txt | 12 +- .../classWithDuplicateIdentifier.symbols | 4 +- .../classWithDuplicateIdentifier.types | 2 +- .../computedPropertyNames49_ES5.symbols | 4 +- .../computedPropertyNames49_ES6.symbols | 4 +- .../computedPropertyNames50_ES5.symbols | 4 +- .../computedPropertyNames50_ES6.symbols | 4 +- ...ssibilityModifiersOnParameters2.errors.txt | 11 +- .../duplicateClassElements.errors.txt | 15 +- .../reference/duplicateClassElements.symbols | 6 +- .../reference/duplicateClassElements.types | 2 +- ...duplicateIdentifierComputedName.errors.txt | 5 +- ...cateIdentifierDifferentSpelling.errors.txt | 8 +- .../duplicateObjectLiteralProperty.errors.txt | 16 +- .../duplicateObjectLiteralProperty.symbols | 6 +- .../duplicateObjectLiteralProperty.types | 4 +- ...duplicatePropertiesInStrictMode.errors.txt | 5 +- .../duplicatePropertyNames.errors.txt | 14 +- ...xportEqualsClassRedeclarationError.symbols | 6 +- .../gettersAndSettersErrors.errors.txt | 12 +- .../reference/gettersAndSettersErrors.symbols | 6 +- .../reference/gettersAndSettersErrors.types | 2 +- .../reference/interfaceWithAccessors.js | 30 +++ .../reference/interfaceWithAccessors.symbols | 28 +++ .../reference/interfaceWithAccessors.types | 22 ++ ...CompilationBindStrictModeErrors.errors.txt | 5 +- .../lastPropertyInLiteralWins.errors.txt | 8 +- .../reference/memberOverride.errors.txt | 5 +- ...terfaceWithConflictingAccessors.errors.txt | 87 ++++++++ ...dInterfaceWithConflictingAccessors.symbols | 123 +++++++++++ ...AndInterfaceWithConflictingAccessors.types | 107 +++++++++ ...erfacesWithConflictingAccessors.errors.txt | 40 ++++ ...InterfacesWithConflictingAccessors.symbols | 45 ++++ ...edInterfacesWithConflictingAccessors.types | 33 +++ ...HandledDeclarationKindForSymbol.errors.txt | 10 +- ...ureHandledDeclarationKindForSymbol.symbols | 4 +- ...atureHandledDeclarationKindForSymbol.types | 2 +- .../reference/multipleDeclarations.symbols | 30 +-- .../reference/numericClassMembers1.errors.txt | 16 +- .../numericNamedPropertyDuplicates.errors.txt | 12 +- ...cStringNamedPropertyEquivalence.errors.txt | 12 +- .../reference/objectLiteralErrors.errors.txt | 119 ++++++++-- .../reference/objectSpreadNegative.errors.txt | 5 +- ...ypeWithDuplicateNumericProperty.errors.txt | 32 +-- ...parameterPropertyInConstructor2.errors.txt | 5 +- .../reference/parser0_004152.errors.txt | 8 +- .../reference/reassignStaticProp.errors.txt | 5 +- ...ypesInImplementationSignatures2.errors.txt | 5 +- ...alTypesInImplementationSignatures2.symbols | 4 +- ...eralTypesInImplementationSignatures2.types | 8 +- .../stringNamedPropertyDuplicates.errors.txt | 16 +- .../reference/symbolProperty36.errors.txt | 5 +- .../reference/symbolProperty37.errors.txt | 13 ++ .../reference/symbolProperty44.symbols | 4 +- .../twoAccessorsWithSameName.symbols | 12 +- .../twoAccessorsWithSameName2.symbols | 8 +- ...assAndInterfaceWithConflictingAccessors.ts | 62 ++++++ ...ergedInterfacesWithConflictingAccessors.ts | 24 ++ .../codeFixClassExtendAbstractGetterSetter.ts | 31 ++- ...ImplementClassAbstractGettersAndSetters.ts | 15 +- ...codeFixClassImplementInterfaceAccessors.ts | 43 ++++ ...tInClosedObjectTypeLiteralInSignature04.ts | 2 +- ...nUnclosedObjectTypeLiteralInSignature04.ts | 2 +- ...pletionListWithModulesInsideModuleScope.ts | 7 +- ...letionListWithModulesOutsideModuleScope.ts | 2 +- .../fourslash/completionsInterfaceElement.ts | 16 +- tests/cases/fourslash/fourslash.ts | 1 + .../fourslash/navigationBarItemsItems.ts | 18 ++ 86 files changed, 1393 insertions(+), 306 deletions(-) create mode 100644 tests/baselines/reference/interfaceWithAccessors.js create mode 100644 tests/baselines/reference/interfaceWithAccessors.symbols create mode 100644 tests/baselines/reference/interfaceWithAccessors.types create mode 100644 tests/baselines/reference/mergeClassAndInterfaceWithConflictingAccessors.errors.txt create mode 100644 tests/baselines/reference/mergeClassAndInterfaceWithConflictingAccessors.symbols create mode 100644 tests/baselines/reference/mergeClassAndInterfaceWithConflictingAccessors.types create mode 100644 tests/baselines/reference/mergedInterfacesWithConflictingAccessors.errors.txt create mode 100644 tests/baselines/reference/mergedInterfacesWithConflictingAccessors.symbols create mode 100644 tests/baselines/reference/mergedInterfacesWithConflictingAccessors.types create mode 100644 tests/baselines/reference/symbolProperty37.errors.txt create mode 100644 tests/cases/conformance/interfaces/declarationMerging/mergeClassAndInterfaceWithConflictingAccessors.ts create mode 100644 tests/cases/conformance/interfaces/declarationMerging/mergedInterfacesWithConflictingAccessors.ts create mode 100644 tests/cases/fourslash/codeFixClassImplementInterfaceAccessors.ts diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index ed68db53803e0..66a7d32a972fa 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -223,12 +223,14 @@ namespace ts { const isNotOverloadAndNotAccessor = and(isNotOverload, isNotAccessor); const enum DeclarationMeaning { - GetAccessor = 1, - SetAccessor = 2, - PropertyAssignment = 4, - Method = 8, - GetOrSetAccessor = GetAccessor | SetAccessor, - PropertyAssignmentOrMethod = PropertyAssignment | Method, + GetAccessor = 1 << 0, + SetAccessor = 1 << 1, + Property = 1 << 2, + Method = 1 << 3, + Accessor = GetAccessor | SetAccessor, + All = GetAccessor | SetAccessor | Property | Method, + + DuplicateIdErrorReported = 1 << 4, } const enum DeclarationSpaces { @@ -25614,6 +25616,82 @@ namespace ts { } } + /** + * Checks whether a member has a conflicting or duplicate declaration. If a conflict is found, we report an error both against `location` as well as + * the value declaration of the symbol. + * @param errorReporter The error reporting function to use. + * @param initial Indicates whether to also report an error at the initial declaration of the name (defaults to `true`). + * @param names A map of names to their recorded meanings. + * @param name The node on which to report diagnostics. + * @param memberName The underscore-escaped name for the member. + * @param symbol The symbol for the member. + * @param meaning The meaning represented by the member. + * @param exclude Meanings that conflict with the member. + * @param message The diagnostic message to use when the name already has the meaning defined in `exclude` (defaults to `Duplicate identifier '{0}'`). + * @param altExclude An alternative meaning to exclude. + * @param altMessage The diagnostic message to use when the name already has the meaning defined in `altExclude` (defaults to `Duplicate identifier '{0}'`). + */ + function checkMemberForDuplicateDeclaration( + errorReporter: (node: Node | undefined, message: DiagnosticMessage, arg0: string | number) => void, + initial: boolean, + names: UnderscoreEscapedMap, + name: PropertyName, + symbol: Symbol, + meaning: DeclarationMeaning, + exclude: DeclarationMeaning, + message?: DiagnosticMessage, + altExclude: DeclarationMeaning = 0, + altMessage?: DiagnosticMessage + ) { + const memberName = getPropertyNameForPropertyNameNode(name); + if (memberName) { + const prev = names.get(memberName); + if (prev) { + if (prev & (exclude | altExclude)) { + let nameText: string; + switch (name.kind) { + case SyntaxKind.StringLiteral: + case SyntaxKind.NumericLiteral: + case SyntaxKind.Identifier: + nameText = unescapeLeadingUnderscores(memberName); + break; + default: + nameText = getTextOfNode(name); + break; + } + + if (!(prev & DeclarationMeaning.DuplicateIdErrorReported)) { + for (const decl of symbol.declarations) { + const declarationName = getNameOfDeclaration(decl); + if (declarationName) { + errorReporter(declarationName, Diagnostics.Duplicate_identifier_0, nameText); + } + } + names.set(memberName, prev | DeclarationMeaning.DuplicateIdErrorReported); + } + + const customMessage = + prev & exclude ? message : + altExclude && prev & altExclude ? altMessage : + undefined; + if (customMessage && customMessage !== Diagnostics.Duplicate_identifier_0) { + const declarationName = getNameOfDeclaration(symbol.valueDeclaration); + if (declarationName && initial) { + errorReporter(declarationName, customMessage, nameText); + } + errorReporter(name, customMessage, nameText); + } + } + else { + names.set(memberName, prev | meaning); + } + } + else { + names.set(memberName, meaning); + } + } + } + function checkClassForDuplicateDeclarations(node: ClassLikeDeclaration) { const instanceNames = createUnderscoreEscapedMap(); const staticNames = createUnderscoreEscapedMap(); @@ -25621,57 +25699,32 @@ namespace ts { if (member.kind === SyntaxKind.Constructor) { for (const param of (member as ConstructorDeclaration).parameters) { if (isParameterPropertyDeclaration(param) && !isBindingPattern(param.name)) { - addName(instanceNames, param.name, param.name.escapedText, DeclarationMeaning.GetOrSetAccessor); + const propertySymbol = Debug.assertDefined(getSymbol(getMembersOfSymbol(node.symbol), param.name.escapedText, SymbolFlags.Value)); + checkMemberForDuplicateDeclaration(error, /*initial*/ false, instanceNames, param.name, propertySymbol, DeclarationMeaning.Property, DeclarationMeaning.All); } } } else { const isStatic = hasModifier(member, ModifierFlags.Static); const names = isStatic ? staticNames : instanceNames; - - const name = member.name; - const memberName = name && getPropertyNameForPropertyNameNode(name); - if (name && memberName) { + if (member.name) { switch (member.kind) { case SyntaxKind.GetAccessor: - addName(names, name, memberName, DeclarationMeaning.GetAccessor); + checkMemberForDuplicateDeclaration(error, /*initial*/ false, names, member.name, member.symbol, DeclarationMeaning.GetAccessor, ~DeclarationMeaning.SetAccessor); break; - case SyntaxKind.SetAccessor: - addName(names, name, memberName, DeclarationMeaning.SetAccessor); + checkMemberForDuplicateDeclaration(error, /*initial*/ false, names, member.name, member.symbol, DeclarationMeaning.SetAccessor, ~DeclarationMeaning.GetAccessor); break; - case SyntaxKind.PropertyDeclaration: - addName(names, name, memberName, DeclarationMeaning.GetOrSetAccessor); + checkMemberForDuplicateDeclaration(error, /*initial*/ false, names, member.name, member.symbol, DeclarationMeaning.Property, DeclarationMeaning.All); break; - case SyntaxKind.MethodDeclaration: - addName(names, name, memberName, DeclarationMeaning.Method); + checkMemberForDuplicateDeclaration(error, /*initial*/ false, names, member.name, member.symbol, DeclarationMeaning.Method, ~DeclarationMeaning.Method); break; } } } } - - function addName(names: UnderscoreEscapedMap, location: Node, name: __String, meaning: DeclarationMeaning) { - const prev = names.get(name); - if (prev) { - if (prev & DeclarationMeaning.Method) { - if (meaning !== DeclarationMeaning.Method) { - error(location, Diagnostics.Duplicate_identifier_0, getTextOfNode(location)); - } - } - else if (prev & meaning) { - error(location, Diagnostics.Duplicate_identifier_0, getTextOfNode(location)); - } - else { - names.set(name, prev | meaning); - } - } - else { - names.set(name, meaning); - } - } } /** @@ -25707,29 +25760,22 @@ namespace ts { } function checkObjectTypeForDuplicateDeclarations(node: TypeLiteralNode | InterfaceDeclaration) { - const names = createMap(); + const names = createUnderscoreEscapedMap(); for (const member of node.members) { - if (member.kind === SyntaxKind.PropertySignature) { - let memberName: string; - const name = member.name!; - switch (name.kind) { - case SyntaxKind.StringLiteral: - case SyntaxKind.NumericLiteral: - memberName = name.text; + if (member.name) { + switch (member.kind) { + case SyntaxKind.GetAccessorSignature: + checkMemberForDuplicateDeclaration(error, /*initial*/ true, names, member.name, member.symbol, DeclarationMeaning.GetAccessor, ~DeclarationMeaning.SetAccessor); break; - case SyntaxKind.Identifier: - memberName = idText(name); + case SyntaxKind.SetAccessorSignature: + checkMemberForDuplicateDeclaration(error, /*initial*/ true, names, member.name, member.symbol, DeclarationMeaning.SetAccessor, ~DeclarationMeaning.GetAccessor); + break; + case SyntaxKind.PropertySignature: + checkMemberForDuplicateDeclaration(error, /*initial*/ true, names, member.name, member.symbol, DeclarationMeaning.Property, DeclarationMeaning.All); + break; + case SyntaxKind.MethodSignature: + checkMemberForDuplicateDeclaration(error, /*initial*/ true, names, member.name, member.symbol, DeclarationMeaning.Method, ~DeclarationMeaning.Method); break; - default: - continue; - } - - if (names.get(memberName)) { - error(getNameOfDeclaration(member.symbol.valueDeclaration), Diagnostics.Duplicate_identifier_0, memberName); - error(member.name, Diagnostics.Duplicate_identifier_0, memberName); - } - else { - names.set(memberName, true); } } } @@ -32931,7 +32977,6 @@ namespace ts { // c.IsAccessorDescriptor(previous) is true and IsDataDescriptor(propId.descriptor) is true. // d.IsAccessorDescriptor(previous) is true and IsAccessorDescriptor(propId.descriptor) is true // and either both previous and propId.descriptor have[[Get]] fields or both previous and propId.descriptor have[[Set]] fields - let currentKind: DeclarationMeaning; switch (prop.kind) { case SyntaxKind.ShorthandPropertyAssignment: checkGrammarForInvalidExclamationToken(prop.exclamationToken, Diagnostics.A_definite_assignment_assertion_is_not_permitted_in_this_context); @@ -32942,45 +32987,24 @@ namespace ts { if (name.kind === SyntaxKind.NumericLiteral) { checkGrammarNumericLiteral(name); } - currentKind = DeclarationMeaning.PropertyAssignment; - break; + // falls through case SyntaxKind.MethodDeclaration: - currentKind = DeclarationMeaning.Method; + checkMemberForDuplicateDeclaration(grammarErrorOnNode, /*initial*/ false, seen, name, prop.symbol, DeclarationMeaning.Property, + DeclarationMeaning.Accessor, Diagnostics.An_object_literal_cannot_have_property_and_accessor_with_the_same_name, + DeclarationMeaning.All); break; case SyntaxKind.GetAccessor: - currentKind = DeclarationMeaning.GetAccessor; + checkMemberForDuplicateDeclaration(grammarErrorOnNode, /*initial*/ false, seen, name, prop.symbol, DeclarationMeaning.GetAccessor, + DeclarationMeaning.Property, Diagnostics.An_object_literal_cannot_have_property_and_accessor_with_the_same_name, + ~DeclarationMeaning.SetAccessor, Diagnostics.An_object_literal_cannot_have_multiple_get_Slashset_accessors_with_the_same_name); break; case SyntaxKind.SetAccessor: - currentKind = DeclarationMeaning.SetAccessor; + checkMemberForDuplicateDeclaration(grammarErrorOnNode, /*initial*/ false, seen, name, prop.symbol, DeclarationMeaning.SetAccessor, + DeclarationMeaning.Property, Diagnostics.An_object_literal_cannot_have_property_and_accessor_with_the_same_name, + ~DeclarationMeaning.GetAccessor, Diagnostics.An_object_literal_cannot_have_multiple_get_Slashset_accessors_with_the_same_name); break; default: - throw Debug.assertNever(prop, "Unexpected syntax kind:" + (prop).kind); - } - - const effectiveName = getPropertyNameForPropertyNameNode(name); - if (effectiveName === undefined) { - continue; - } - - const existingKind = seen.get(effectiveName); - if (!existingKind) { - seen.set(effectiveName, currentKind); - } - else { - if ((currentKind & DeclarationMeaning.PropertyAssignmentOrMethod) && (existingKind & DeclarationMeaning.PropertyAssignmentOrMethod)) { - grammarErrorOnNode(name, Diagnostics.Duplicate_identifier_0, getTextOfNode(name)); - } - else if ((currentKind & DeclarationMeaning.GetOrSetAccessor) && (existingKind & DeclarationMeaning.GetOrSetAccessor)) { - if (existingKind !== DeclarationMeaning.GetOrSetAccessor && currentKind !== existingKind) { - seen.set(effectiveName, currentKind | existingKind); - } - else { - return grammarErrorOnNode(name, Diagnostics.An_object_literal_cannot_have_multiple_get_Slashset_accessors_with_the_same_name); - } - } - else { - return grammarErrorOnNode(name, Diagnostics.An_object_literal_cannot_have_property_and_accessor_with_the_same_name); - } + return Debug.assertNever(prop); } } } diff --git a/src/compiler/program.ts b/src/compiler/program.ts index a7cb013c8eebc..cf0280e997c5b 100644 --- a/src/compiler/program.ts +++ b/src/compiler/program.ts @@ -1827,6 +1827,8 @@ namespace ts { case SyntaxKind.Constructor: case SyntaxKind.GetAccessor: case SyntaxKind.SetAccessor: + case SyntaxKind.GetAccessorSignature: + case SyntaxKind.SetAccessorSignature: case SyntaxKind.FunctionExpression: case SyntaxKind.FunctionDeclaration: case SyntaxKind.ArrowFunction: diff --git a/src/compiler/types.ts b/src/compiler/types.ts index a57e5d7766ae5..0337d0dba64d6 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -3589,6 +3589,13 @@ namespace ts { setAccessor: SetAccessorSignature | undefined; } + /* @internal */ + export interface AllAccessors { + orderedAccessors: [AccessorLike] | [AccessorLike, AccessorLike]; + getAccessor: GetAccessorLike | undefined; + setAccessor: SetAccessorLike | undefined; + } + /** Indicates how to serialize the name for a TypeReferenceNode when emitting decorator metadata */ /* @internal */ export enum TypeReferenceSerializationKind { @@ -3706,7 +3713,7 @@ namespace ts { BlockScopedVariableExcludes = Value, ParameterExcludes = Value, - PropertyExcludes = None, + PropertyExcludes = Value & ~(Property | Variable), // Merge with variables to allow expandos to merge EnumMemberExcludes = Value | Type, FunctionExcludes = Value & ~(Function | ValueModule), ClassExcludes = (Value | Type) & ~(ValueModule | Interface), // class-interface mergability done in checker.ts @@ -3716,8 +3723,8 @@ namespace ts { ValueModuleExcludes = Value & ~(Function | Class | RegularEnum | ValueModule), NamespaceModuleExcludes = 0, MethodExcludes = Value & ~Method, - GetAccessorExcludes = Value & ~SetAccessor, - SetAccessorExcludes = Value & ~GetAccessor, + GetAccessorExcludes = Value & ~Accessor, + SetAccessorExcludes = Value & ~Accessor, TypeParameterExcludes = Type & ~TypeParameter, TypeAliasExcludes = Type, AliasExcludes = Alias, diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index 07947b5371240..f1cf428ae8978 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -1273,6 +1273,8 @@ namespace ts { case SyntaxKind.Constructor: case SyntaxKind.GetAccessor: case SyntaxKind.SetAccessor: + case SyntaxKind.GetAccessorSignature: + case SyntaxKind.SetAccessorSignature: case SyntaxKind.FunctionDeclaration: case SyntaxKind.FunctionExpression: return true; @@ -3530,7 +3532,7 @@ namespace ts { return find(node.members, (member): member is ConstructorDeclaration & { body: FunctionBody } => isConstructorDeclaration(member) && nodeIsPresent(member.body)); } - function getSetAccessorValueParameter(accessor: SetAccessorLike): ParameterDeclaration | undefined { + export function getSetAccessorValueParameter(accessor: SetAccessorLike): ParameterDeclaration | undefined { if (accessor && accessor.parameters.length > 0) { const hasThis = accessor.parameters.length === 2 && parameterIsThisKeyword(accessor.parameters[0]); return accessor.parameters[hasThis ? 1 : 0]; @@ -3582,7 +3584,7 @@ namespace ts { SyntaxKind.GetAccessorSignature; } - export function getAllAccessorDeclarations(declarations: NodeArray, accessor: AccessorDeclaration): AllAccessorDeclarations { + export function getAllAccessorDeclarations(declarations: readonly Declaration[], accessor: AccessorDeclaration): AllAccessorDeclarations { // TODO: GH#18217 let firstAccessor!: AccessorDeclaration; let secondAccessor!: AccessorDeclaration; @@ -3633,6 +3635,66 @@ namespace ts { }; } + export function getAllAccessors(declarations: readonly Declaration[], accessor: AccessorLike): AllAccessors { + // TODO: GH#18217 + let firstAccessorIsGetter = false; + let firstAccessor: AccessorLike | undefined; + let secondAccessor: AccessorLike | undefined; + let getAccessor: GetAccessorLike | undefined; + let setAccessor: SetAccessorLike | undefined; + if (hasDynamicName(accessor)) { + firstAccessor = accessor; + if (isGetAccessorLike(accessor)) { + getAccessor = accessor; + } + else if (isSetAccessorLike(accessor)) { + setAccessor = accessor; + } + else { + return Debug.assertNever(accessor); + } + } + else { + const isStatic = isStaticAccessor(accessor); + const accessorName = getPropertyNameForPropertyNameNode(accessor.name); + for (const member of declarations) { + if (isAccessorLike(member) && isStaticAccessor(member) === isStatic) { + const memberName = getPropertyNameForPropertyNameNode(member.name); + if (memberName === accessorName) { + if (isGetAccessorLike(member) && !getAccessor) { + getAccessor = member; + } + + if (isSetAccessorLike(member) && !setAccessor) { + setAccessor = member; + } + + if (!firstAccessor) { + firstAccessor = member; + firstAccessorIsGetter = isGetAccessorLike(member); + } + else if (!secondAccessor && firstAccessorIsGetter !== isGetAccessorLike(member)) { + secondAccessor = member; + break; + } + } + } + } + if (!firstAccessor) { + return Debug.fail("Accessors not found."); + } + } + return { + orderedAccessors: secondAccessor ? [firstAccessor, secondAccessor] : [firstAccessor], + getAccessor, + setAccessor, + }; + } + + function isStaticAccessor(node: Declaration) { + return isAccessorDeclaration(node) && hasModifier(node, ModifierFlags.Static); + } + /** * Gets the effective type annotation of a variable, parameter, or property. If the node was * parsed in a JavaScript file, gets the type annotation from JSDoc. @@ -6850,6 +6912,7 @@ namespace ts { || kind === SyntaxKind.FunctionDeclaration || kind === SyntaxKind.FunctionExpression || kind === SyntaxKind.GetAccessor + || kind === SyntaxKind.GetAccessorSignature || kind === SyntaxKind.ImportClause || kind === SyntaxKind.ImportEqualsDeclaration || kind === SyntaxKind.ImportSpecifier @@ -6865,6 +6928,7 @@ namespace ts { || kind === SyntaxKind.PropertyDeclaration || kind === SyntaxKind.PropertySignature || kind === SyntaxKind.SetAccessor + || kind === SyntaxKind.SetAccessorSignature || kind === SyntaxKind.ShorthandPropertyAssignment || kind === SyntaxKind.TypeAliasDeclaration || kind === SyntaxKind.TypeParameter diff --git a/src/harness/fourslash.ts b/src/harness/fourslash.ts index 3b09fc01fc071..433f0f7c466e9 100644 --- a/src/harness/fourslash.ts +++ b/src/harness/fourslash.ts @@ -4737,6 +4737,9 @@ namespace FourSlashInterface { }); } + export const interfaceElementKeywords: ReadonlyArray = + ["get", "readonly", "set"].map(keywordEntry); + export const classElementKeywords: ReadonlyArray = ["private", "protected", "public", "static", "abstract", "async", "constructor", "get", "readonly", "set"].map(keywordEntry); diff --git a/src/services/breakpoints.ts b/src/services/breakpoints.ts index 404e75db14728..725c6c4ee302c 100644 --- a/src/services/breakpoints.ts +++ b/src/services/breakpoints.ts @@ -85,6 +85,8 @@ namespace ts.BreakpointResolver { case SyntaxKind.MethodSignature: case SyntaxKind.GetAccessor: case SyntaxKind.SetAccessor: + case SyntaxKind.GetAccessorSignature: + case SyntaxKind.SetAccessorSignature: case SyntaxKind.Constructor: case SyntaxKind.FunctionExpression: case SyntaxKind.ArrowFunction: @@ -664,6 +666,8 @@ namespace ts.BreakpointResolver { case SyntaxKind.MethodSignature: case SyntaxKind.GetAccessor: case SyntaxKind.SetAccessor: + case SyntaxKind.GetAccessorSignature: + case SyntaxKind.SetAccessorSignature: case SyntaxKind.Constructor: case SyntaxKind.WhileStatement: case SyntaxKind.DoStatement: diff --git a/src/services/codefixes/fixJSDocTypes.ts b/src/services/codefixes/fixJSDocTypes.ts index 8769b0339e03c..f1ff4510e95f1 100644 --- a/src/services/codefixes/fixJSDocTypes.ts +++ b/src/services/codefixes/fixJSDocTypes.ts @@ -51,10 +51,24 @@ namespace ts.codefix { // TODO: GH#19856 Node & { type: TypeNode } type TypeContainer = - | AsExpression | CallSignatureDeclaration | ConstructSignatureDeclaration | FunctionDeclaration - | GetAccessorDeclaration | IndexSignatureDeclaration | MappedTypeNode | MethodDeclaration - | MethodSignature | ParameterDeclaration | PropertyDeclaration | PropertySignature | SetAccessorDeclaration - | TypeAliasDeclaration | TypeAssertion | VariableDeclaration; + | AsExpression + | CallSignatureDeclaration + | ConstructSignatureDeclaration + | FunctionDeclaration + | GetAccessorDeclaration + | SetAccessorDeclaration + | GetAccessorSignature + | SetAccessorSignature + | IndexSignatureDeclaration + | MappedTypeNode + | MethodDeclaration + | MethodSignature + | ParameterDeclaration + | PropertyDeclaration + | PropertySignature + | TypeAliasDeclaration + | TypeAssertion + | VariableDeclaration; function isTypeContainer(node: Node): node is TypeContainer { // NOTE: Some locations are not handled yet: // MappedTypeNode.typeParameters and SignatureDeclaration.typeParameters, as well as CallExpression.typeArguments @@ -64,6 +78,9 @@ namespace ts.codefix { case SyntaxKind.ConstructSignature: case SyntaxKind.FunctionDeclaration: case SyntaxKind.GetAccessor: + case SyntaxKind.SetAccessor: + case SyntaxKind.GetAccessorSignature: + case SyntaxKind.SetAccessorSignature: case SyntaxKind.IndexSignature: case SyntaxKind.MappedType: case SyntaxKind.MethodDeclaration: @@ -71,7 +88,6 @@ namespace ts.codefix { case SyntaxKind.Parameter: case SyntaxKind.PropertyDeclaration: case SyntaxKind.PropertySignature: - case SyntaxKind.SetAccessor: case SyntaxKind.TypeAliasDeclaration: case SyntaxKind.TypeAssertionExpression: case SyntaxKind.VariableDeclaration: diff --git a/src/services/codefixes/helpers.ts b/src/services/codefixes/helpers.ts index 45a79613db5fd..1d811749ccbdd 100644 --- a/src/services/codefixes/helpers.ts +++ b/src/services/codefixes/helpers.ts @@ -55,12 +55,11 @@ namespace ts.codefix { const modifiers = visibilityModifier ? createNodeArray([visibilityModifier]) : undefined; const type = checker.getWidenedType(checker.getTypeOfSymbolAtLocation(symbol, enclosingDeclaration)); const optional = !!(symbol.flags & SymbolFlags.Optional); + const ambient = !!(enclosingDeclaration.flags & NodeFlags.Ambient); switch (declaration.kind) { - case SyntaxKind.GetAccessor: - case SyntaxKind.SetAccessor: case SyntaxKind.PropertySignature: - case SyntaxKind.PropertyDeclaration: + case SyntaxKind.PropertyDeclaration: { const typeNode = checker.typeToTypeNode(type, enclosingDeclaration, /*flags*/ undefined, getNoopSymbolTrackerWithResolver(context)); out(createProperty( /*decorators*/undefined, @@ -70,6 +69,37 @@ namespace ts.codefix { typeNode, /*initializer*/ undefined)); break; + } + case SyntaxKind.GetAccessor: + case SyntaxKind.SetAccessor: + case SyntaxKind.GetAccessorSignature: + case SyntaxKind.SetAccessorSignature: { + const allAccessors = getAllAccessors(declarations, declaration as AccessorLike); + const typeNode = checker.typeToTypeNode(type, enclosingDeclaration, /*flags*/ undefined, getNoopSymbolTrackerWithResolver(context)); + for (const accessor of allAccessors.orderedAccessors) { + if (isGetAccessorLike(accessor)) { + out(createGetAccessor( + /*decorators*/ undefined, + modifiers, + name, + emptyArray, + typeNode, + ambient ? undefined : createStubbedMethodBody(preferences))); + } + else { + Debug.assertNode(accessor, isSetAccessorLike); + const parameter = getSetAccessorValueParameter(accessor); + const parameterName = parameter && isIdentifier(parameter.name) ? idText(parameter.name) : undefined; + out(createSetAccessor( + /*decorators*/ undefined, + modifiers, + name, + createDummyParameters(1, [parameterName], [typeNode], 1, /*inJs*/ false), + ambient ? undefined : createStubbedMethodBody(preferences))); + } + } + break; + } case SyntaxKind.MethodSignature: case SyntaxKind.MethodDeclaration: // The signature for the implementation appears as an entry in `signatures` iff @@ -87,7 +117,7 @@ namespace ts.codefix { if (declarations.length === 1) { Debug.assert(signatures.length === 1); const signature = signatures[0]; - outputMethod(signature, modifiers, name, createStubbedMethodBody(preferences)); + outputMethod(signature, modifiers, name, ambient ? undefined : createStubbedMethodBody(preferences)); break; } @@ -98,11 +128,11 @@ namespace ts.codefix { if (declarations.length > signatures.length) { const signature = checker.getSignatureFromDeclaration(declarations[declarations.length - 1] as SignatureDeclaration)!; - outputMethod(signature, modifiers, name, createStubbedMethodBody(preferences)); + outputMethod(signature, modifiers, name, ambient ? undefined : createStubbedMethodBody(preferences)); } else { Debug.assert(declarations.length === signatures.length); - out(createMethodImplementingSignatures(signatures, name, optional, modifiers, preferences)); + out(createMethodImplementingSignatures(signatures, name, optional, ambient, modifiers, preferences)); } break; } @@ -190,6 +220,7 @@ namespace ts.codefix { signatures: ReadonlyArray, name: PropertyName, optional: boolean, + ambient: boolean, modifiers: ReadonlyArray | undefined, preferences: UserPreferences, ): MethodDeclaration { @@ -231,6 +262,7 @@ namespace ts.codefix { modifiers, name, optional, + ambient, /*typeParameters*/ undefined, parameters, /*returnType*/ undefined, @@ -241,10 +273,11 @@ namespace ts.codefix { modifiers: ReadonlyArray | undefined, name: PropertyName, optional: boolean, + ambient: boolean, typeParameters: ReadonlyArray | undefined, parameters: ReadonlyArray, returnType: TypeNode | undefined, - preferences: UserPreferences + preferences: UserPreferences, ): MethodDeclaration { return createMethod( /*decorators*/ undefined, @@ -255,7 +288,7 @@ namespace ts.codefix { typeParameters, parameters, returnType, - createStubbedMethodBody(preferences)); + ambient ? undefined : createStubbedMethodBody(preferences)); } function createStubbedMethodBody(preferences: UserPreferences): Block { diff --git a/src/services/completions.ts b/src/services/completions.ts index e9a38fb1516db..9bba4ecb78ea2 100644 --- a/src/services/completions.ts +++ b/src/services/completions.ts @@ -2119,7 +2119,14 @@ namespace ts.Completions { } function isInterfaceOrTypeLiteralCompletionKeyword(kind: SyntaxKind): boolean { - return kind === SyntaxKind.ReadonlyKeyword; + switch (kind) { + case SyntaxKind.ReadonlyKeyword: + case SyntaxKind.GetKeyword: + case SyntaxKind.SetKeyword: + return true; + default: + return false; + } } function isClassMemberCompletionKeyword(kind: SyntaxKind) { diff --git a/src/services/findAllReferences.ts b/src/services/findAllReferences.ts index 1296b3cfa883b..1cbcacb69c531 100644 --- a/src/services/findAllReferences.ts +++ b/src/services/findAllReferences.ts @@ -517,6 +517,8 @@ namespace ts.FindAllReferences { return !!(decl as VariableDeclaration | PropertyDeclaration).initializer || isCatchClause(decl.parent); case SyntaxKind.MethodSignature: + case SyntaxKind.GetAccessorSignature: + case SyntaxKind.SetAccessorSignature: case SyntaxKind.PropertySignature: case SyntaxKind.JSDocPropertyTag: case SyntaxKind.JSDocParameterTag: @@ -1716,6 +1718,8 @@ namespace ts.FindAllReferences.Core { case SyntaxKind.Constructor: case SyntaxKind.GetAccessor: case SyntaxKind.SetAccessor: + case SyntaxKind.GetAccessorSignature: + case SyntaxKind.SetAccessorSignature: staticFlag &= getModifierFlags(searchSpaceNode); searchSpaceNode = searchSpaceNode.parent; // re-assign to be the owning class break; @@ -1762,6 +1766,8 @@ namespace ts.FindAllReferences.Core { case SyntaxKind.Constructor: case SyntaxKind.GetAccessor: case SyntaxKind.SetAccessor: + case SyntaxKind.GetAccessorSignature: + case SyntaxKind.SetAccessorSignature: staticFlag &= getModifierFlags(searchSpaceNode); searchSpaceNode = searchSpaceNode.parent; // re-assign to be the owning class break; diff --git a/src/services/formatting/rules.ts b/src/services/formatting/rules.ts index 84ee38f0f306d..855e70d5876e9 100644 --- a/src/services/formatting/rules.ts +++ b/src/services/formatting/rules.ts @@ -539,10 +539,10 @@ namespace ts.formatting { case SyntaxKind.FunctionDeclaration: case SyntaxKind.MethodDeclaration: case SyntaxKind.MethodSignature: - // case SyntaxKind.MemberFunctionDeclaration: case SyntaxKind.GetAccessor: case SyntaxKind.SetAccessor: - // case SyntaxKind.MethodSignature: + case SyntaxKind.GetAccessorSignature: + case SyntaxKind.SetAccessorSignature: case SyntaxKind.CallSignature: case SyntaxKind.FunctionExpression: case SyntaxKind.Constructor: diff --git a/src/services/formatting/smartIndenter.ts b/src/services/formatting/smartIndenter.ts index 7a8bfb5f5d509..85d51c156c2ec 100644 --- a/src/services/formatting/smartIndenter.ts +++ b/src/services/formatting/smartIndenter.ts @@ -523,6 +523,8 @@ namespace ts.formatting { case SyntaxKind.JsxSelfClosingElement: case SyntaxKind.JsxExpression: case SyntaxKind.MethodSignature: + case SyntaxKind.GetAccessorSignature: + case SyntaxKind.SetAccessorSignature: case SyntaxKind.CallSignature: case SyntaxKind.ConstructSignature: case SyntaxKind.Parameter: diff --git a/src/services/navigationBar.ts b/src/services/navigationBar.ts index 60f1283f7e6ea..e4ca1b7af2ab0 100644 --- a/src/services/navigationBar.ts +++ b/src/services/navigationBar.ts @@ -171,6 +171,8 @@ namespace ts.NavigationBar { case SyntaxKind.GetAccessor: case SyntaxKind.SetAccessor: case SyntaxKind.MethodSignature: + case SyntaxKind.GetAccessorSignature: + case SyntaxKind.SetAccessorSignature: if (!hasDynamicName((node))) { addNodeWithRecursiveChild(node, (node).body); } diff --git a/src/services/services.ts b/src/services/services.ts index 42b3ac3b31dd5..e47e02a1e93c5 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -705,6 +705,8 @@ namespace ts { case SyntaxKind.NamespaceImport: case SyntaxKind.GetAccessor: case SyntaxKind.SetAccessor: + case SyntaxKind.GetAccessorSignature: + case SyntaxKind.SetAccessorSignature: case SyntaxKind.TypeLiteral: addDeclaration(node); forEachChild(node, visit); diff --git a/src/services/utilities.ts b/src/services/utilities.ts index 852d22106a28f..a8bbccfa51c9c 100644 --- a/src/services/utilities.ts +++ b/src/services/utilities.ts @@ -37,6 +37,8 @@ namespace ts { case SyntaxKind.Constructor: case SyntaxKind.GetAccessor: case SyntaxKind.SetAccessor: + case SyntaxKind.GetAccessorSignature: + case SyntaxKind.SetAccessorSignature: case SyntaxKind.FunctionDeclaration: case SyntaxKind.FunctionExpression: case SyntaxKind.ArrowFunction: @@ -277,6 +279,8 @@ namespace ts { case SyntaxKind.MethodSignature: case SyntaxKind.GetAccessor: case SyntaxKind.SetAccessor: + case SyntaxKind.GetAccessorSignature: + case SyntaxKind.SetAccessorSignature: case SyntaxKind.ModuleDeclaration: return getNameOfDeclaration(node.parent) === node; case SyntaxKind.ElementAccessExpression: @@ -316,6 +320,8 @@ namespace ts { case SyntaxKind.FunctionExpression: case SyntaxKind.GetAccessor: case SyntaxKind.SetAccessor: + case SyntaxKind.GetAccessorSignature: + case SyntaxKind.SetAccessorSignature: case SyntaxKind.ClassDeclaration: case SyntaxKind.InterfaceDeclaration: case SyntaxKind.EnumDeclaration: @@ -348,8 +354,12 @@ namespace ts { case SyntaxKind.FunctionDeclaration: case SyntaxKind.FunctionExpression: return ScriptElementKind.functionElement; - case SyntaxKind.GetAccessor: return ScriptElementKind.memberGetAccessorElement; - case SyntaxKind.SetAccessor: return ScriptElementKind.memberSetAccessorElement; + case SyntaxKind.GetAccessor: + case SyntaxKind.GetAccessorSignature: + return ScriptElementKind.memberGetAccessorElement; + case SyntaxKind.SetAccessor: + case SyntaxKind.SetAccessorSignature: + return ScriptElementKind.memberSetAccessorElement; case SyntaxKind.MethodDeclaration: case SyntaxKind.MethodSignature: return ScriptElementKind.memberFunctionElement; @@ -520,6 +530,8 @@ namespace ts { case SyntaxKind.Constructor: case SyntaxKind.GetAccessor: case SyntaxKind.SetAccessor: + case SyntaxKind.GetAccessorSignature: + case SyntaxKind.SetAccessorSignature: case SyntaxKind.FunctionDeclaration: case SyntaxKind.FunctionExpression: case SyntaxKind.MethodDeclaration: diff --git a/tests/baselines/reference/callSignaturesWithParameterInitializers2.errors.txt b/tests/baselines/reference/callSignaturesWithParameterInitializers2.errors.txt index 6329b0c5403c8..22f8a563e710f 100644 --- a/tests/baselines/reference/callSignaturesWithParameterInitializers2.errors.txt +++ b/tests/baselines/reference/callSignaturesWithParameterInitializers2.errors.txt @@ -1,10 +1,12 @@ tests/cases/conformance/types/objectTypeLiteral/callSignatures/callSignaturesWithParameterInitializers2.ts(4,14): error TS2371: A parameter initializer is only allowed in a function or constructor implementation. tests/cases/conformance/types/objectTypeLiteral/callSignatures/callSignaturesWithParameterInitializers2.ts(11,9): error TS2371: A parameter initializer is only allowed in a function or constructor implementation. +tests/cases/conformance/types/objectTypeLiteral/callSignatures/callSignaturesWithParameterInitializers2.ts(20,5): error TS2300: Duplicate identifier 'foo'. tests/cases/conformance/types/objectTypeLiteral/callSignatures/callSignaturesWithParameterInitializers2.ts(20,9): error TS2371: A parameter initializer is only allowed in a function or constructor implementation. tests/cases/conformance/types/objectTypeLiteral/callSignatures/callSignaturesWithParameterInitializers2.ts(20,15): error TS1005: '{' expected. +tests/cases/conformance/types/objectTypeLiteral/callSignatures/callSignaturesWithParameterInitializers2.ts(21,5): error TS2300: Duplicate identifier 'foo'. -==== tests/cases/conformance/types/objectTypeLiteral/callSignatures/callSignaturesWithParameterInitializers2.ts (4 errors) ==== +==== tests/cases/conformance/types/objectTypeLiteral/callSignatures/callSignaturesWithParameterInitializers2.ts (6 errors) ==== // Optional parameters allow initializers only in implementation signatures // All the below declarations are errors @@ -29,11 +31,15 @@ tests/cases/conformance/types/objectTypeLiteral/callSignatures/callSignaturesWit var b = { foo(x = 1), // error + ~~~ +!!! error TS2300: Duplicate identifier 'foo'. ~~~~~ !!! error TS2371: A parameter initializer is only allowed in a function or constructor implementation. ~ !!! error TS1005: '{' expected. foo(x = 1) { }, // error + ~~~ +!!! error TS2300: Duplicate identifier 'foo'. } b.foo(); diff --git a/tests/baselines/reference/callSignaturesWithParameterInitializers2.symbols b/tests/baselines/reference/callSignaturesWithParameterInitializers2.symbols index 12f4aeb5ed310..d475fcca64821 100644 --- a/tests/baselines/reference/callSignaturesWithParameterInitializers2.symbols +++ b/tests/baselines/reference/callSignaturesWithParameterInitializers2.symbols @@ -46,21 +46,21 @@ var b = { >b : Symbol(b, Decl(callSignaturesWithParameterInitializers2.ts, 18, 3)) foo(x = 1), // error ->foo : Symbol(foo, Decl(callSignaturesWithParameterInitializers2.ts, 18, 9), Decl(callSignaturesWithParameterInitializers2.ts, 19, 15)) +>foo : Symbol(foo, Decl(callSignaturesWithParameterInitializers2.ts, 18, 9)) >x : Symbol(x, Decl(callSignaturesWithParameterInitializers2.ts, 19, 8)) foo(x = 1) { }, // error ->foo : Symbol(foo, Decl(callSignaturesWithParameterInitializers2.ts, 18, 9), Decl(callSignaturesWithParameterInitializers2.ts, 19, 15)) +>foo : Symbol(foo, Decl(callSignaturesWithParameterInitializers2.ts, 19, 15)) >x : Symbol(x, Decl(callSignaturesWithParameterInitializers2.ts, 20, 8)) } b.foo(); ->b.foo : Symbol(foo, Decl(callSignaturesWithParameterInitializers2.ts, 18, 9), Decl(callSignaturesWithParameterInitializers2.ts, 19, 15)) +>b.foo : Symbol(foo, Decl(callSignaturesWithParameterInitializers2.ts, 19, 15)) >b : Symbol(b, Decl(callSignaturesWithParameterInitializers2.ts, 18, 3)) ->foo : Symbol(foo, Decl(callSignaturesWithParameterInitializers2.ts, 18, 9), Decl(callSignaturesWithParameterInitializers2.ts, 19, 15)) +>foo : Symbol(foo, Decl(callSignaturesWithParameterInitializers2.ts, 19, 15)) b.foo(1); ->b.foo : Symbol(foo, Decl(callSignaturesWithParameterInitializers2.ts, 18, 9), Decl(callSignaturesWithParameterInitializers2.ts, 19, 15)) +>b.foo : Symbol(foo, Decl(callSignaturesWithParameterInitializers2.ts, 19, 15)) >b : Symbol(b, Decl(callSignaturesWithParameterInitializers2.ts, 18, 3)) ->foo : Symbol(foo, Decl(callSignaturesWithParameterInitializers2.ts, 18, 9), Decl(callSignaturesWithParameterInitializers2.ts, 19, 15)) +>foo : Symbol(foo, Decl(callSignaturesWithParameterInitializers2.ts, 19, 15)) diff --git a/tests/baselines/reference/callSignaturesWithParameterInitializers2.types b/tests/baselines/reference/callSignaturesWithParameterInitializers2.types index f339e01c00334..a1ab3b843c6ed 100644 --- a/tests/baselines/reference/callSignaturesWithParameterInitializers2.types +++ b/tests/baselines/reference/callSignaturesWithParameterInitializers2.types @@ -52,30 +52,30 @@ c.foo(1); >1 : 1 var b = { ->b : { foo(x?: number): any; foo(x?: number): void; } ->{ foo(x = 1), // error foo(x = 1) { }, // error} : { foo(x?: number): any; foo(x?: number): void; } +>b : { foo(x?: number): void; } +>{ foo(x = 1), // error foo(x = 1) { }, // error} : { foo(x?: number): void; } foo(x = 1), // error ->foo : { (x?: number): any; (x?: number): void; } +>foo : (x?: number) => any >x : number >1 : 1 foo(x = 1) { }, // error ->foo : { (x?: number): any; (x?: number): void; } +>foo : (x?: number) => void >x : number >1 : 1 } b.foo(); ->b.foo() : any ->b.foo : { (x?: number): any; (x?: number): void; } ->b : { foo(x?: number): any; foo(x?: number): void; } ->foo : { (x?: number): any; (x?: number): void; } +>b.foo() : void +>b.foo : (x?: number) => void +>b : { foo(x?: number): void; } +>foo : (x?: number) => void b.foo(1); ->b.foo(1) : any ->b.foo : { (x?: number): any; (x?: number): void; } ->b : { foo(x?: number): any; foo(x?: number): void; } ->foo : { (x?: number): any; (x?: number): void; } +>b.foo(1) : void +>b.foo : (x?: number) => void +>b : { foo(x?: number): void; } +>foo : (x?: number) => void >1 : 1 diff --git a/tests/baselines/reference/classWithDuplicateIdentifier.errors.txt b/tests/baselines/reference/classWithDuplicateIdentifier.errors.txt index 60390e8a84354..e209143269047 100644 --- a/tests/baselines/reference/classWithDuplicateIdentifier.errors.txt +++ b/tests/baselines/reference/classWithDuplicateIdentifier.errors.txt @@ -1,20 +1,20 @@ +tests/cases/compiler/classWithDuplicateIdentifier.ts(2,5): error TS2300: Duplicate identifier 'a'. tests/cases/compiler/classWithDuplicateIdentifier.ts(3,5): error TS2300: Duplicate identifier 'a'. -tests/cases/compiler/classWithDuplicateIdentifier.ts(3,5): error TS2717: Subsequent property declarations must have the same type. Property 'a' must be of type '() => number', but here has type 'number'. tests/cases/compiler/classWithDuplicateIdentifier.ts(6,5): error TS2300: Duplicate identifier 'b'. tests/cases/compiler/classWithDuplicateIdentifier.ts(7,5): error TS2300: Duplicate identifier 'b'. +tests/cases/compiler/classWithDuplicateIdentifier.ts(10,5): error TS2300: Duplicate identifier 'c'. tests/cases/compiler/classWithDuplicateIdentifier.ts(11,5): error TS2300: Duplicate identifier 'c'. tests/cases/compiler/classWithDuplicateIdentifier.ts(11,5): error TS2717: Subsequent property declarations must have the same type. Property 'c' must be of type 'number', but here has type 'string'. -==== tests/cases/compiler/classWithDuplicateIdentifier.ts (6 errors) ==== +==== tests/cases/compiler/classWithDuplicateIdentifier.ts (7 errors) ==== class C { a(): number { return 0; } // error: duplicate identifier - a: number; ~ !!! error TS2300: Duplicate identifier 'a'. + a: number; ~ -!!! error TS2717: Subsequent property declarations must have the same type. Property 'a' must be of type '() => number', but here has type 'number'. -!!! related TS6203 tests/cases/compiler/classWithDuplicateIdentifier.ts:2:5: 'a' was also declared here. +!!! error TS2300: Duplicate identifier 'a'. } class K { b: number; // error: duplicate identifier @@ -26,6 +26,8 @@ tests/cases/compiler/classWithDuplicateIdentifier.ts(11,5): error TS2717: Subseq } class D { c: number; + ~ +!!! error TS2300: Duplicate identifier 'c'. c: string; ~ !!! error TS2300: Duplicate identifier 'c'. diff --git a/tests/baselines/reference/classWithDuplicateIdentifier.symbols b/tests/baselines/reference/classWithDuplicateIdentifier.symbols index e1f6ab51f6665..d97e75ef40e82 100644 --- a/tests/baselines/reference/classWithDuplicateIdentifier.symbols +++ b/tests/baselines/reference/classWithDuplicateIdentifier.symbols @@ -3,10 +3,10 @@ class C { >C : Symbol(C, Decl(classWithDuplicateIdentifier.ts, 0, 0)) a(): number { return 0; } // error: duplicate identifier ->a : Symbol(C.a, Decl(classWithDuplicateIdentifier.ts, 0, 9), Decl(classWithDuplicateIdentifier.ts, 1, 29)) +>a : Symbol(C.a, Decl(classWithDuplicateIdentifier.ts, 0, 9)) a: number; ->a : Symbol(C.a, Decl(classWithDuplicateIdentifier.ts, 0, 9), Decl(classWithDuplicateIdentifier.ts, 1, 29)) +>a : Symbol(C.a, Decl(classWithDuplicateIdentifier.ts, 1, 29)) } class K { >K : Symbol(K, Decl(classWithDuplicateIdentifier.ts, 3, 1)) diff --git a/tests/baselines/reference/classWithDuplicateIdentifier.types b/tests/baselines/reference/classWithDuplicateIdentifier.types index f9dac77710846..d3fadd87cd256 100644 --- a/tests/baselines/reference/classWithDuplicateIdentifier.types +++ b/tests/baselines/reference/classWithDuplicateIdentifier.types @@ -7,7 +7,7 @@ class C { >0 : 0 a: number; ->a : () => number +>a : number } class K { >K : K diff --git a/tests/baselines/reference/computedPropertyNames49_ES5.symbols b/tests/baselines/reference/computedPropertyNames49_ES5.symbols index d2da5b9df1a90..4ce4bf7ec0ba0 100644 --- a/tests/baselines/reference/computedPropertyNames49_ES5.symbols +++ b/tests/baselines/reference/computedPropertyNames49_ES5.symbols @@ -22,14 +22,14 @@ var x = { throw 10; }, get foo() { ->foo : Symbol(foo, Decl(computedPropertyNames49_ES5.ts, 11, 6)) +>foo : Symbol(foo, Decl(computedPropertyNames49_ES5.ts, 11, 6), Decl(computedPropertyNames49_ES5.ts, 16, 6)) if (1 == 1) { return 10; } }, get foo() { ->foo : Symbol(foo, Decl(computedPropertyNames49_ES5.ts, 16, 6)) +>foo : Symbol(foo, Decl(computedPropertyNames49_ES5.ts, 11, 6), Decl(computedPropertyNames49_ES5.ts, 16, 6)) if (2 == 2) { return 20; diff --git a/tests/baselines/reference/computedPropertyNames49_ES6.symbols b/tests/baselines/reference/computedPropertyNames49_ES6.symbols index 9c320ae4f4b45..a2864b819ba13 100644 --- a/tests/baselines/reference/computedPropertyNames49_ES6.symbols +++ b/tests/baselines/reference/computedPropertyNames49_ES6.symbols @@ -22,14 +22,14 @@ var x = { throw 10; }, get foo() { ->foo : Symbol(foo, Decl(computedPropertyNames49_ES6.ts, 11, 6)) +>foo : Symbol(foo, Decl(computedPropertyNames49_ES6.ts, 11, 6), Decl(computedPropertyNames49_ES6.ts, 16, 6)) if (1 == 1) { return 10; } }, get foo() { ->foo : Symbol(foo, Decl(computedPropertyNames49_ES6.ts, 16, 6)) +>foo : Symbol(foo, Decl(computedPropertyNames49_ES6.ts, 11, 6), Decl(computedPropertyNames49_ES6.ts, 16, 6)) if (2 == 2) { return 20; diff --git a/tests/baselines/reference/computedPropertyNames50_ES5.symbols b/tests/baselines/reference/computedPropertyNames50_ES5.symbols index 71996786af543..437fced239613 100644 --- a/tests/baselines/reference/computedPropertyNames50_ES5.symbols +++ b/tests/baselines/reference/computedPropertyNames50_ES5.symbols @@ -6,7 +6,7 @@ var x = { >p1 : Symbol(p1, Decl(computedPropertyNames50_ES5.ts, 0, 9)) get foo() { ->foo : Symbol(foo, Decl(computedPropertyNames50_ES5.ts, 1, 11)) +>foo : Symbol(foo, Decl(computedPropertyNames50_ES5.ts, 1, 11), Decl(computedPropertyNames50_ES5.ts, 16, 6)) if (1 == 1) { return 10; @@ -29,7 +29,7 @@ var x = { return 10; }, get foo() { ->foo : Symbol(foo, Decl(computedPropertyNames50_ES5.ts, 16, 6)) +>foo : Symbol(foo, Decl(computedPropertyNames50_ES5.ts, 1, 11), Decl(computedPropertyNames50_ES5.ts, 16, 6)) if (2 == 2) { return 20; diff --git a/tests/baselines/reference/computedPropertyNames50_ES6.symbols b/tests/baselines/reference/computedPropertyNames50_ES6.symbols index d47f6ee9f58b2..3045f1686dea2 100644 --- a/tests/baselines/reference/computedPropertyNames50_ES6.symbols +++ b/tests/baselines/reference/computedPropertyNames50_ES6.symbols @@ -6,7 +6,7 @@ var x = { >p1 : Symbol(p1, Decl(computedPropertyNames50_ES6.ts, 0, 9)) get foo() { ->foo : Symbol(foo, Decl(computedPropertyNames50_ES6.ts, 1, 11)) +>foo : Symbol(foo, Decl(computedPropertyNames50_ES6.ts, 1, 11), Decl(computedPropertyNames50_ES6.ts, 16, 6)) if (1 == 1) { return 10; @@ -29,7 +29,7 @@ var x = { return 10; }, get foo() { ->foo : Symbol(foo, Decl(computedPropertyNames50_ES6.ts, 16, 6)) +>foo : Symbol(foo, Decl(computedPropertyNames50_ES6.ts, 1, 11), Decl(computedPropertyNames50_ES6.ts, 16, 6)) if (2 == 2) { return 20; diff --git a/tests/baselines/reference/constructSignatureWithAccessibilityModifiersOnParameters2.errors.txt b/tests/baselines/reference/constructSignatureWithAccessibilityModifiersOnParameters2.errors.txt index 78ef601af2359..9cc5895e4bf73 100644 --- a/tests/baselines/reference/constructSignatureWithAccessibilityModifiersOnParameters2.errors.txt +++ b/tests/baselines/reference/constructSignatureWithAccessibilityModifiersOnParameters2.errors.txt @@ -1,8 +1,11 @@ tests/cases/conformance/types/objectTypeLiteral/callSignatures/constructSignatureWithAccessibilityModifiersOnParameters2.ts(4,17): error TS2369: A parameter property is only allowed in a constructor implementation. +tests/cases/conformance/types/objectTypeLiteral/callSignatures/constructSignatureWithAccessibilityModifiersOnParameters2.ts(4,24): error TS2300: Duplicate identifier 'x'. tests/cases/conformance/types/objectTypeLiteral/callSignatures/constructSignatureWithAccessibilityModifiersOnParameters2.ts(4,27): error TS2369: A parameter property is only allowed in a constructor implementation. +tests/cases/conformance/types/objectTypeLiteral/callSignatures/constructSignatureWithAccessibilityModifiersOnParameters2.ts(4,35): error TS2300: Duplicate identifier 'y'. tests/cases/conformance/types/objectTypeLiteral/callSignatures/constructSignatureWithAccessibilityModifiersOnParameters2.ts(5,24): error TS2300: Duplicate identifier 'x'. tests/cases/conformance/types/objectTypeLiteral/callSignatures/constructSignatureWithAccessibilityModifiersOnParameters2.ts(5,35): error TS2300: Duplicate identifier 'y'. tests/cases/conformance/types/objectTypeLiteral/callSignatures/constructSignatureWithAccessibilityModifiersOnParameters2.ts(9,17): error TS2369: A parameter property is only allowed in a constructor implementation. +tests/cases/conformance/types/objectTypeLiteral/callSignatures/constructSignatureWithAccessibilityModifiersOnParameters2.ts(9,25): error TS2300: Duplicate identifier 'x'. tests/cases/conformance/types/objectTypeLiteral/callSignatures/constructSignatureWithAccessibilityModifiersOnParameters2.ts(9,25): error TS2687: All declarations of 'x' must have identical modifiers. tests/cases/conformance/types/objectTypeLiteral/callSignatures/constructSignatureWithAccessibilityModifiersOnParameters2.ts(10,24): error TS2300: Duplicate identifier 'x'. tests/cases/conformance/types/objectTypeLiteral/callSignatures/constructSignatureWithAccessibilityModifiersOnParameters2.ts(10,24): error TS2687: All declarations of 'x' must have identical modifiers. @@ -17,15 +20,19 @@ tests/cases/conformance/types/objectTypeLiteral/callSignatures/constructSignatur tests/cases/conformance/types/objectTypeLiteral/callSignatures/constructSignatureWithAccessibilityModifiersOnParameters2.ts(35,10): error TS2369: A parameter property is only allowed in a constructor implementation. -==== tests/cases/conformance/types/objectTypeLiteral/callSignatures/constructSignatureWithAccessibilityModifiersOnParameters2.ts (17 errors) ==== +==== tests/cases/conformance/types/objectTypeLiteral/callSignatures/constructSignatureWithAccessibilityModifiersOnParameters2.ts (20 errors) ==== // Parameter properties are not valid in overloads of constructors class C { constructor(public x, private y); ~~~~~~~~ !!! error TS2369: A parameter property is only allowed in a constructor implementation. + ~ +!!! error TS2300: Duplicate identifier 'x'. ~~~~~~~~~ !!! error TS2369: A parameter property is only allowed in a constructor implementation. + ~ +!!! error TS2300: Duplicate identifier 'y'. constructor(public x, private y) { } ~ !!! error TS2300: Duplicate identifier 'x'. @@ -38,6 +45,8 @@ tests/cases/conformance/types/objectTypeLiteral/callSignatures/constructSignatur ~~~~~~~~~ !!! error TS2369: A parameter property is only allowed in a constructor implementation. ~ +!!! error TS2300: Duplicate identifier 'x'. + ~ !!! error TS2687: All declarations of 'x' must have identical modifiers. constructor(public x) { } ~ diff --git a/tests/baselines/reference/duplicateClassElements.errors.txt b/tests/baselines/reference/duplicateClassElements.errors.txt index 397ee4454590c..9dfec7a2908ea 100644 --- a/tests/baselines/reference/duplicateClassElements.errors.txt +++ b/tests/baselines/reference/duplicateClassElements.errors.txt @@ -1,3 +1,4 @@ +tests/cases/compiler/duplicateClassElements.ts(2,12): error TS2300: Duplicate identifier 'a'. tests/cases/compiler/duplicateClassElements.ts(3,12): error TS2300: Duplicate identifier 'a'. tests/cases/compiler/duplicateClassElements.ts(4,12): error TS2393: Duplicate function implementation. tests/cases/compiler/duplicateClassElements.ts(6,12): error TS2393: Duplicate function implementation. @@ -14,9 +15,10 @@ tests/cases/compiler/duplicateClassElements.ts(23,9): error TS2300: Duplicate id tests/cases/compiler/duplicateClassElements.ts(26,9): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. tests/cases/compiler/duplicateClassElements.ts(26,9): error TS2300: Duplicate identifier 'z'. tests/cases/compiler/duplicateClassElements.ts(29,9): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. +tests/cases/compiler/duplicateClassElements.ts(29,9): error TS2300: Duplicate identifier 'x2'. tests/cases/compiler/duplicateClassElements.ts(32,9): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. +tests/cases/compiler/duplicateClassElements.ts(32,9): error TS2300: Duplicate identifier 'x2'. tests/cases/compiler/duplicateClassElements.ts(34,12): error TS2300: Duplicate identifier 'x2'. -tests/cases/compiler/duplicateClassElements.ts(34,12): error TS2717: Subsequent property declarations must have the same type. Property 'x2' must be of type 'number', but here has type 'any'. tests/cases/compiler/duplicateClassElements.ts(36,9): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. tests/cases/compiler/duplicateClassElements.ts(36,9): error TS2300: Duplicate identifier 'z2'. tests/cases/compiler/duplicateClassElements.ts(39,9): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. @@ -24,9 +26,11 @@ tests/cases/compiler/duplicateClassElements.ts(39,9): error TS2300: Duplicate id tests/cases/compiler/duplicateClassElements.ts(41,12): error TS2300: Duplicate identifier 'z2'. -==== tests/cases/compiler/duplicateClassElements.ts (24 errors) ==== +==== tests/cases/compiler/duplicateClassElements.ts (26 errors) ==== class a { public a; + ~ +!!! error TS2300: Duplicate identifier 'a'. public a; ~ !!! error TS2300: Duplicate identifier 'a'. @@ -86,18 +90,19 @@ tests/cases/compiler/duplicateClassElements.ts(41,12): error TS2300: Duplicate i get x2() { ~~ !!! error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. + ~~ +!!! error TS2300: Duplicate identifier 'x2'. return 10; } set x2(_x: number) { ~~ !!! error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. + ~~ +!!! error TS2300: Duplicate identifier 'x2'. } public x2; ~~ !!! error TS2300: Duplicate identifier 'x2'. - ~~ -!!! error TS2717: Subsequent property declarations must have the same type. Property 'x2' must be of type 'number', but here has type 'any'. -!!! related TS6203 tests/cases/compiler/duplicateClassElements.ts:29:9: 'x2' was also declared here. get z2() { ~~ diff --git a/tests/baselines/reference/duplicateClassElements.symbols b/tests/baselines/reference/duplicateClassElements.symbols index de3ed4b309137..b987d592a8969 100644 --- a/tests/baselines/reference/duplicateClassElements.symbols +++ b/tests/baselines/reference/duplicateClassElements.symbols @@ -51,16 +51,16 @@ class a { } get x2() { ->x2 : Symbol(a.x2, Decl(duplicateClassElements.ts, 26, 5), Decl(duplicateClassElements.ts, 30, 5), Decl(duplicateClassElements.ts, 32, 5)) +>x2 : Symbol(a.x2, Decl(duplicateClassElements.ts, 26, 5), Decl(duplicateClassElements.ts, 30, 5)) return 10; } set x2(_x: number) { ->x2 : Symbol(a.x2, Decl(duplicateClassElements.ts, 26, 5), Decl(duplicateClassElements.ts, 30, 5), Decl(duplicateClassElements.ts, 32, 5)) +>x2 : Symbol(a.x2, Decl(duplicateClassElements.ts, 26, 5), Decl(duplicateClassElements.ts, 30, 5)) >_x : Symbol(_x, Decl(duplicateClassElements.ts, 31, 11)) } public x2; ->x2 : Symbol(a.x2, Decl(duplicateClassElements.ts, 26, 5), Decl(duplicateClassElements.ts, 30, 5), Decl(duplicateClassElements.ts, 32, 5)) +>x2 : Symbol(a.x2, Decl(duplicateClassElements.ts, 32, 5)) get z2() { >z2 : Symbol(a.z2, Decl(duplicateClassElements.ts, 33, 14), Decl(duplicateClassElements.ts, 37, 5)) diff --git a/tests/baselines/reference/duplicateClassElements.types b/tests/baselines/reference/duplicateClassElements.types index 1338a19598ba4..666436729e63f 100644 --- a/tests/baselines/reference/duplicateClassElements.types +++ b/tests/baselines/reference/duplicateClassElements.types @@ -64,7 +64,7 @@ class a { >_x : number } public x2; ->x2 : number +>x2 : any get z2() { >z2 : string diff --git a/tests/baselines/reference/duplicateIdentifierComputedName.errors.txt b/tests/baselines/reference/duplicateIdentifierComputedName.errors.txt index 12d70ca545806..0a5cb3eb2afd4 100644 --- a/tests/baselines/reference/duplicateIdentifierComputedName.errors.txt +++ b/tests/baselines/reference/duplicateIdentifierComputedName.errors.txt @@ -1,9 +1,12 @@ +tests/cases/compiler/duplicateIdentifierComputedName.ts(2,5): error TS2300: Duplicate identifier '["a"]'. tests/cases/compiler/duplicateIdentifierComputedName.ts(3,5): error TS2300: Duplicate identifier '["a"]'. -==== tests/cases/compiler/duplicateIdentifierComputedName.ts (1 errors) ==== +==== tests/cases/compiler/duplicateIdentifierComputedName.ts (2 errors) ==== class C { ["a"]: string; + ~~~~~ +!!! error TS2300: Duplicate identifier '["a"]'. ["a"]: string; ~~~~~ !!! error TS2300: Duplicate identifier '["a"]'. diff --git a/tests/baselines/reference/duplicateIdentifierDifferentSpelling.errors.txt b/tests/baselines/reference/duplicateIdentifierDifferentSpelling.errors.txt index fda0f4a66d98a..c9726372691da 100644 --- a/tests/baselines/reference/duplicateIdentifierDifferentSpelling.errors.txt +++ b/tests/baselines/reference/duplicateIdentifierDifferentSpelling.errors.txt @@ -1,16 +1,22 @@ +tests/cases/compiler/duplicateIdentifierDifferentSpelling.ts(2,3): error TS2300: Duplicate identifier '3'. tests/cases/compiler/duplicateIdentifierDifferentSpelling.ts(3,3): error TS2300: Duplicate identifier '3'. +tests/cases/compiler/duplicateIdentifierDifferentSpelling.ts(6,11): error TS2300: Duplicate identifier '3'. tests/cases/compiler/duplicateIdentifierDifferentSpelling.ts(6,21): error TS2300: Duplicate identifier '3'. -==== tests/cases/compiler/duplicateIdentifierDifferentSpelling.ts (2 errors) ==== +==== tests/cases/compiler/duplicateIdentifierDifferentSpelling.ts (4 errors) ==== class A { 0b11 = ''; + ~~~~ +!!! error TS2300: Duplicate identifier '3'. 3 = ''; ~ !!! error TS2300: Duplicate identifier '3'. } var X = { 0b11: '', 3: '' }; + ~~~~ +!!! error TS2300: Duplicate identifier '3'. ~ !!! error TS2300: Duplicate identifier '3'. \ No newline at end of file diff --git a/tests/baselines/reference/duplicateObjectLiteralProperty.errors.txt b/tests/baselines/reference/duplicateObjectLiteralProperty.errors.txt index abc56a6f8fce7..52207ae304d14 100644 --- a/tests/baselines/reference/duplicateObjectLiteralProperty.errors.txt +++ b/tests/baselines/reference/duplicateObjectLiteralProperty.errors.txt @@ -1,30 +1,36 @@ +tests/cases/compiler/duplicateObjectLiteralProperty.ts(2,5): error TS2300: Duplicate identifier 'a'. tests/cases/compiler/duplicateObjectLiteralProperty.ts(4,5): error TS2300: Duplicate identifier 'a'. -tests/cases/compiler/duplicateObjectLiteralProperty.ts(5,5): error TS2300: Duplicate identifier '\u0061'. +tests/cases/compiler/duplicateObjectLiteralProperty.ts(5,5): error TS2300: Duplicate identifier 'a'. tests/cases/compiler/duplicateObjectLiteralProperty.ts(6,5): error TS2300: Duplicate identifier 'a'. -tests/cases/compiler/duplicateObjectLiteralProperty.ts(8,9): error TS2300: Duplicate identifier '"c"'. +tests/cases/compiler/duplicateObjectLiteralProperty.ts(7,9): error TS2300: Duplicate identifier 'c'. +tests/cases/compiler/duplicateObjectLiteralProperty.ts(8,9): error TS2300: Duplicate identifier 'c'. tests/cases/compiler/duplicateObjectLiteralProperty.ts(14,9): error TS2300: Duplicate identifier 'a'. tests/cases/compiler/duplicateObjectLiteralProperty.ts(15,9): error TS2300: Duplicate identifier 'a'. tests/cases/compiler/duplicateObjectLiteralProperty.ts(16,9): error TS1118: An object literal cannot have multiple get/set accessors with the same name. tests/cases/compiler/duplicateObjectLiteralProperty.ts(16,9): error TS2300: Duplicate identifier 'a'. -==== tests/cases/compiler/duplicateObjectLiteralProperty.ts (8 errors) ==== +==== tests/cases/compiler/duplicateObjectLiteralProperty.ts (10 errors) ==== var x = { a: 1, + ~ +!!! error TS2300: Duplicate identifier 'a'. b: true, // OK a: 56, // Duplicate ~ !!! error TS2300: Duplicate identifier 'a'. \u0061: "ss", // Duplicate ~~~~~~ -!!! error TS2300: Duplicate identifier '\u0061'. +!!! error TS2300: Duplicate identifier 'a'. a: { ~ !!! error TS2300: Duplicate identifier 'a'. c: 1, + ~ +!!! error TS2300: Duplicate identifier 'c'. "c": 56, // Duplicate ~~~ -!!! error TS2300: Duplicate identifier '"c"'. +!!! error TS2300: Duplicate identifier 'c'. } }; diff --git a/tests/baselines/reference/duplicateObjectLiteralProperty.symbols b/tests/baselines/reference/duplicateObjectLiteralProperty.symbols index 37e68e0af049c..9b7c2f86514b5 100644 --- a/tests/baselines/reference/duplicateObjectLiteralProperty.symbols +++ b/tests/baselines/reference/duplicateObjectLiteralProperty.symbols @@ -30,14 +30,14 @@ var y = { >y : Symbol(y, Decl(duplicateObjectLiteralProperty.ts, 12, 3)) get a() { return 0; }, ->a : Symbol(a, Decl(duplicateObjectLiteralProperty.ts, 12, 9), Decl(duplicateObjectLiteralProperty.ts, 13, 26)) +>a : Symbol(a, Decl(duplicateObjectLiteralProperty.ts, 12, 9), Decl(duplicateObjectLiteralProperty.ts, 13, 26), Decl(duplicateObjectLiteralProperty.ts, 14, 25)) set a(v: number) { }, ->a : Symbol(a, Decl(duplicateObjectLiteralProperty.ts, 12, 9), Decl(duplicateObjectLiteralProperty.ts, 13, 26)) +>a : Symbol(a, Decl(duplicateObjectLiteralProperty.ts, 12, 9), Decl(duplicateObjectLiteralProperty.ts, 13, 26), Decl(duplicateObjectLiteralProperty.ts, 14, 25)) >v : Symbol(v, Decl(duplicateObjectLiteralProperty.ts, 14, 10)) get a() { return 0; } ->a : Symbol(a, Decl(duplicateObjectLiteralProperty.ts, 14, 25)) +>a : Symbol(a, Decl(duplicateObjectLiteralProperty.ts, 12, 9), Decl(duplicateObjectLiteralProperty.ts, 13, 26), Decl(duplicateObjectLiteralProperty.ts, 14, 25)) }; diff --git a/tests/baselines/reference/duplicateObjectLiteralProperty.types b/tests/baselines/reference/duplicateObjectLiteralProperty.types index 4431a52c19612..06beb2fc51622 100644 --- a/tests/baselines/reference/duplicateObjectLiteralProperty.types +++ b/tests/baselines/reference/duplicateObjectLiteralProperty.types @@ -35,8 +35,8 @@ var x = { var y = { ->y : { readonly a: number; } ->{ get a() { return 0; }, set a(v: number) { }, get a() { return 0; }} : { readonly a: number; } +>y : { a: number; } +>{ get a() { return 0; }, set a(v: number) { }, get a() { return 0; }} : { a: number; } get a() { return 0; }, >a : number diff --git a/tests/baselines/reference/duplicatePropertiesInStrictMode.errors.txt b/tests/baselines/reference/duplicatePropertiesInStrictMode.errors.txt index 17a55a7876b00..b3d868dbe7ed5 100644 --- a/tests/baselines/reference/duplicatePropertiesInStrictMode.errors.txt +++ b/tests/baselines/reference/duplicatePropertiesInStrictMode.errors.txt @@ -1,11 +1,14 @@ +tests/cases/compiler/duplicatePropertiesInStrictMode.ts(3,3): error TS2300: Duplicate identifier 'x'. tests/cases/compiler/duplicatePropertiesInStrictMode.ts(4,3): error TS1117: An object literal cannot have multiple properties with the same name in strict mode. tests/cases/compiler/duplicatePropertiesInStrictMode.ts(4,3): error TS2300: Duplicate identifier 'x'. -==== tests/cases/compiler/duplicatePropertiesInStrictMode.ts (2 errors) ==== +==== tests/cases/compiler/duplicatePropertiesInStrictMode.ts (3 errors) ==== "use strict"; var x = { x: 1, + ~ +!!! error TS2300: Duplicate identifier 'x'. x: 2 ~ !!! error TS1117: An object literal cannot have multiple properties with the same name in strict mode. diff --git a/tests/baselines/reference/duplicatePropertyNames.errors.txt b/tests/baselines/reference/duplicatePropertyNames.errors.txt index f8ed73c570740..108a88d145110 100644 --- a/tests/baselines/reference/duplicatePropertyNames.errors.txt +++ b/tests/baselines/reference/duplicatePropertyNames.errors.txt @@ -2,9 +2,11 @@ tests/cases/conformance/types/members/duplicatePropertyNames.ts(4,5): error TS23 tests/cases/conformance/types/members/duplicatePropertyNames.ts(5,5): error TS2300: Duplicate identifier 'foo'. tests/cases/conformance/types/members/duplicatePropertyNames.ts(14,5): error TS2300: Duplicate identifier 'foo'. tests/cases/conformance/types/members/duplicatePropertyNames.ts(15,5): error TS2300: Duplicate identifier 'foo'. +tests/cases/conformance/types/members/duplicatePropertyNames.ts(19,5): error TS2300: Duplicate identifier 'foo'. tests/cases/conformance/types/members/duplicatePropertyNames.ts(20,5): error TS2300: Duplicate identifier 'foo'. tests/cases/conformance/types/members/duplicatePropertyNames.ts(22,5): error TS2393: Duplicate function implementation. tests/cases/conformance/types/members/duplicatePropertyNames.ts(23,5): error TS2393: Duplicate function implementation. +tests/cases/conformance/types/members/duplicatePropertyNames.ts(25,5): error TS2300: Duplicate identifier 'baz'. tests/cases/conformance/types/members/duplicatePropertyNames.ts(26,5): error TS2300: Duplicate identifier 'baz'. tests/cases/conformance/types/members/duplicatePropertyNames.ts(30,5): error TS2300: Duplicate identifier 'foo'. tests/cases/conformance/types/members/duplicatePropertyNames.ts(31,5): error TS2300: Duplicate identifier 'foo'. @@ -12,11 +14,13 @@ tests/cases/conformance/types/members/duplicatePropertyNames.ts(35,5): error TS2 tests/cases/conformance/types/members/duplicatePropertyNames.ts(36,5): error TS2300: Duplicate identifier 'foo'. tests/cases/conformance/types/members/duplicatePropertyNames.ts(38,5): error TS2300: Duplicate identifier 'bar'. tests/cases/conformance/types/members/duplicatePropertyNames.ts(39,5): error TS2300: Duplicate identifier 'bar'. +tests/cases/conformance/types/members/duplicatePropertyNames.ts(43,5): error TS2300: Duplicate identifier 'foo'. tests/cases/conformance/types/members/duplicatePropertyNames.ts(44,5): error TS2300: Duplicate identifier 'foo'. +tests/cases/conformance/types/members/duplicatePropertyNames.ts(45,5): error TS2300: Duplicate identifier 'bar'. tests/cases/conformance/types/members/duplicatePropertyNames.ts(46,5): error TS2300: Duplicate identifier 'bar'. -==== tests/cases/conformance/types/members/duplicatePropertyNames.ts (16 errors) ==== +==== tests/cases/conformance/types/members/duplicatePropertyNames.ts (20 errors) ==== // duplicate property names are an error in all types interface Number { @@ -44,6 +48,8 @@ tests/cases/conformance/types/members/duplicatePropertyNames.ts(46,5): error TS2 class C { foo: string; + ~~~ +!!! error TS2300: Duplicate identifier 'foo'. foo: string; ~~~ !!! error TS2300: Duplicate identifier 'foo'. @@ -56,6 +62,8 @@ tests/cases/conformance/types/members/duplicatePropertyNames.ts(46,5): error TS2 !!! error TS2393: Duplicate function implementation. baz = () => { } + ~~~ +!!! error TS2300: Duplicate identifier 'baz'. baz = () => { } ~~~ !!! error TS2300: Duplicate identifier 'baz'. @@ -88,10 +96,14 @@ tests/cases/conformance/types/members/duplicatePropertyNames.ts(46,5): error TS2 var b = { foo: '', + ~~~ +!!! error TS2300: Duplicate identifier 'foo'. foo: '', ~~~ !!! error TS2300: Duplicate identifier 'foo'. bar: () => { }, + ~~~ +!!! error TS2300: Duplicate identifier 'bar'. bar: () => { } ~~~ !!! error TS2300: Duplicate identifier 'bar'. diff --git a/tests/baselines/reference/exportEqualsClassRedeclarationError.symbols b/tests/baselines/reference/exportEqualsClassRedeclarationError.symbols index 93fa2524827cb..bc28cf2667c02 100644 --- a/tests/baselines/reference/exportEqualsClassRedeclarationError.symbols +++ b/tests/baselines/reference/exportEqualsClassRedeclarationError.symbols @@ -3,17 +3,17 @@ class SomeClass { >SomeClass : Symbol(SomeClass, Decl(exportEqualsClassRedeclarationError.ts, 0, 0)) static get someProp(): number { ->someProp : Symbol(SomeClass.someProp, Decl(exportEqualsClassRedeclarationError.ts, 0, 17), Decl(exportEqualsClassRedeclarationError.ts, 3, 5)) +>someProp : Symbol(SomeClass.someProp, Decl(exportEqualsClassRedeclarationError.ts, 0, 17), Decl(exportEqualsClassRedeclarationError.ts, 3, 5), Decl(exportEqualsClassRedeclarationError.ts, 5, 41)) return 0; } static set someProp(value: number) {} ->someProp : Symbol(SomeClass.someProp, Decl(exportEqualsClassRedeclarationError.ts, 0, 17), Decl(exportEqualsClassRedeclarationError.ts, 3, 5)) +>someProp : Symbol(SomeClass.someProp, Decl(exportEqualsClassRedeclarationError.ts, 0, 17), Decl(exportEqualsClassRedeclarationError.ts, 3, 5), Decl(exportEqualsClassRedeclarationError.ts, 5, 41)) >value : Symbol(value, Decl(exportEqualsClassRedeclarationError.ts, 5, 24)) static set someProp(value: number) {} ->someProp : Symbol(SomeClass.someProp, Decl(exportEqualsClassRedeclarationError.ts, 5, 41)) +>someProp : Symbol(SomeClass.someProp, Decl(exportEqualsClassRedeclarationError.ts, 0, 17), Decl(exportEqualsClassRedeclarationError.ts, 3, 5), Decl(exportEqualsClassRedeclarationError.ts, 5, 41)) >value : Symbol(value, Decl(exportEqualsClassRedeclarationError.ts, 6, 24)) } export = SomeClass; diff --git a/tests/baselines/reference/gettersAndSettersErrors.errors.txt b/tests/baselines/reference/gettersAndSettersErrors.errors.txt index 013e195876e86..db2d4c5bc87de 100644 --- a/tests/baselines/reference/gettersAndSettersErrors.errors.txt +++ b/tests/baselines/reference/gettersAndSettersErrors.errors.txt @@ -1,7 +1,8 @@ tests/cases/compiler/gettersAndSettersErrors.ts(2,16): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. +tests/cases/compiler/gettersAndSettersErrors.ts(2,16): error TS2300: Duplicate identifier 'Foo'. tests/cases/compiler/gettersAndSettersErrors.ts(3,16): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. +tests/cases/compiler/gettersAndSettersErrors.ts(3,16): error TS2300: Duplicate identifier 'Foo'. tests/cases/compiler/gettersAndSettersErrors.ts(5,12): error TS2300: Duplicate identifier 'Foo'. -tests/cases/compiler/gettersAndSettersErrors.ts(5,12): error TS2717: Subsequent property declarations must have the same type. Property 'Foo' must be of type 'string', but here has type 'number'. tests/cases/compiler/gettersAndSettersErrors.ts(6,16): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. tests/cases/compiler/gettersAndSettersErrors.ts(7,16): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. tests/cases/compiler/gettersAndSettersErrors.ts(11,17): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. @@ -10,21 +11,22 @@ tests/cases/compiler/gettersAndSettersErrors.ts(12,16): error TS1056: Accessors tests/cases/compiler/gettersAndSettersErrors.ts(12,16): error TS2379: Getter and setter accessors do not agree in visibility. -==== tests/cases/compiler/gettersAndSettersErrors.ts (10 errors) ==== +==== tests/cases/compiler/gettersAndSettersErrors.ts (11 errors) ==== class C { public get Foo() { return "foo";} // ok ~~~ !!! error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. + ~~~ +!!! error TS2300: Duplicate identifier 'Foo'. public set Foo(foo:string) {} // ok ~~~ !!! error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. + ~~~ +!!! error TS2300: Duplicate identifier 'Foo'. public Foo = 0; // error - duplicate identifier Foo - confirmed ~~~ !!! error TS2300: Duplicate identifier 'Foo'. - ~~~ -!!! error TS2717: Subsequent property declarations must have the same type. Property 'Foo' must be of type 'string', but here has type 'number'. -!!! related TS6203 tests/cases/compiler/gettersAndSettersErrors.ts:2:16: 'Foo' was also declared here. public get Goo(v:string):string {return null;} // error - getters must not have a parameter ~~~ !!! error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. diff --git a/tests/baselines/reference/gettersAndSettersErrors.symbols b/tests/baselines/reference/gettersAndSettersErrors.symbols index 1cc97e63394a1..c3c651b28f138 100644 --- a/tests/baselines/reference/gettersAndSettersErrors.symbols +++ b/tests/baselines/reference/gettersAndSettersErrors.symbols @@ -3,14 +3,14 @@ class C { >C : Symbol(C, Decl(gettersAndSettersErrors.ts, 0, 0)) public get Foo() { return "foo";} // ok ->Foo : Symbol(C.Foo, Decl(gettersAndSettersErrors.ts, 0, 9), Decl(gettersAndSettersErrors.ts, 1, 37), Decl(gettersAndSettersErrors.ts, 2, 33)) +>Foo : Symbol(C.Foo, Decl(gettersAndSettersErrors.ts, 0, 9), Decl(gettersAndSettersErrors.ts, 1, 37)) public set Foo(foo:string) {} // ok ->Foo : Symbol(C.Foo, Decl(gettersAndSettersErrors.ts, 0, 9), Decl(gettersAndSettersErrors.ts, 1, 37), Decl(gettersAndSettersErrors.ts, 2, 33)) +>Foo : Symbol(C.Foo, Decl(gettersAndSettersErrors.ts, 0, 9), Decl(gettersAndSettersErrors.ts, 1, 37)) >foo : Symbol(foo, Decl(gettersAndSettersErrors.ts, 2, 19)) public Foo = 0; // error - duplicate identifier Foo - confirmed ->Foo : Symbol(C.Foo, Decl(gettersAndSettersErrors.ts, 0, 9), Decl(gettersAndSettersErrors.ts, 1, 37), Decl(gettersAndSettersErrors.ts, 2, 33)) +>Foo : Symbol(C.Foo, Decl(gettersAndSettersErrors.ts, 2, 33)) public get Goo(v:string):string {return null;} // error - getters must not have a parameter >Goo : Symbol(C.Goo, Decl(gettersAndSettersErrors.ts, 4, 19), Decl(gettersAndSettersErrors.ts, 5, 50)) diff --git a/tests/baselines/reference/gettersAndSettersErrors.types b/tests/baselines/reference/gettersAndSettersErrors.types index fc0863fc11e44..6a2eb67575358 100644 --- a/tests/baselines/reference/gettersAndSettersErrors.types +++ b/tests/baselines/reference/gettersAndSettersErrors.types @@ -11,7 +11,7 @@ class C { >foo : string public Foo = 0; // error - duplicate identifier Foo - confirmed ->Foo : string +>Foo : number >0 : 0 public get Goo(v:string):string {return null;} // error - getters must not have a parameter diff --git a/tests/baselines/reference/interfaceWithAccessors.js b/tests/baselines/reference/interfaceWithAccessors.js new file mode 100644 index 0000000000000..cfe67ef0c109c --- /dev/null +++ b/tests/baselines/reference/interfaceWithAccessors.js @@ -0,0 +1,30 @@ +//// [interfaceWithAccessors.ts] +interface I0 { + get x(): number; + set x(value); +} + +interface I1 { + get x(): number; +} + +interface I1 { + set x(value); +} + + + +//// [interfaceWithAccessors.js] + + +//// [interfaceWithAccessors.d.ts] +interface I0 { + get x(): number; + set x(value: number); +} +interface I1 { + get x(): number; +} +interface I1 { + set x(value: number); +} diff --git a/tests/baselines/reference/interfaceWithAccessors.symbols b/tests/baselines/reference/interfaceWithAccessors.symbols new file mode 100644 index 0000000000000..f4042ff409f71 --- /dev/null +++ b/tests/baselines/reference/interfaceWithAccessors.symbols @@ -0,0 +1,28 @@ +=== tests/cases/conformance/interfaces/interfaceDeclarations/interfaceWithAccessors.ts === +interface I0 { +>I0 : Symbol(I0, Decl(interfaceWithAccessors.ts, 0, 0)) + + get x(): number; +>x : Symbol(I0.x, Decl(interfaceWithAccessors.ts, 0, 14), Decl(interfaceWithAccessors.ts, 1, 20)) + + set x(value); +>x : Symbol(I0.x, Decl(interfaceWithAccessors.ts, 0, 14), Decl(interfaceWithAccessors.ts, 1, 20)) +>value : Symbol(value, Decl(interfaceWithAccessors.ts, 2, 10)) +} + +interface I1 { +>I1 : Symbol(I1, Decl(interfaceWithAccessors.ts, 3, 1), Decl(interfaceWithAccessors.ts, 7, 1)) + + get x(): number; +>x : Symbol(I1.x, Decl(interfaceWithAccessors.ts, 5, 14), Decl(interfaceWithAccessors.ts, 9, 14)) +} + +interface I1 { +>I1 : Symbol(I1, Decl(interfaceWithAccessors.ts, 3, 1), Decl(interfaceWithAccessors.ts, 7, 1)) + + set x(value); +>x : Symbol(I1.x, Decl(interfaceWithAccessors.ts, 5, 14), Decl(interfaceWithAccessors.ts, 9, 14)) +>value : Symbol(value, Decl(interfaceWithAccessors.ts, 10, 10)) +} + + diff --git a/tests/baselines/reference/interfaceWithAccessors.types b/tests/baselines/reference/interfaceWithAccessors.types new file mode 100644 index 0000000000000..d4a4a0eec5b7e --- /dev/null +++ b/tests/baselines/reference/interfaceWithAccessors.types @@ -0,0 +1,22 @@ +=== tests/cases/conformance/interfaces/interfaceDeclarations/interfaceWithAccessors.ts === +interface I0 { + get x(): number; +>x : number + + set x(value); +>x : number +>value : number +} + +interface I1 { + get x(): number; +>x : number +} + +interface I1 { + set x(value); +>x : number +>value : number +} + + diff --git a/tests/baselines/reference/jsFileCompilationBindStrictModeErrors.errors.txt b/tests/baselines/reference/jsFileCompilationBindStrictModeErrors.errors.txt index ed19b5c4a9b89..592034a6dcc1e 100644 --- a/tests/baselines/reference/jsFileCompilationBindStrictModeErrors.errors.txt +++ b/tests/baselines/reference/jsFileCompilationBindStrictModeErrors.errors.txt @@ -1,3 +1,4 @@ +tests/cases/compiler/a.js(3,5): error TS2300: Duplicate identifier 'a'. tests/cases/compiler/a.js(5,5): error TS1117: An object literal cannot have multiple properties with the same name in strict mode. tests/cases/compiler/a.js(5,5): error TS2300: Duplicate identifier 'a'. tests/cases/compiler/a.js(7,5): error TS1212: Identifier expected. 'let' is a reserved word in strict mode. @@ -15,10 +16,12 @@ tests/cases/compiler/d.js(2,9): error TS1121: Octal literals are not allowed in tests/cases/compiler/d.js(2,11): error TS1005: ',' expected. -==== tests/cases/compiler/a.js (9 errors) ==== +==== tests/cases/compiler/a.js (10 errors) ==== "use strict"; var a = { a: "hello", // error + ~ +!!! error TS2300: Duplicate identifier 'a'. b: 10, a: 10 // error ~ diff --git a/tests/baselines/reference/lastPropertyInLiteralWins.errors.txt b/tests/baselines/reference/lastPropertyInLiteralWins.errors.txt index 5e12521ad6064..fecbfef77d035 100644 --- a/tests/baselines/reference/lastPropertyInLiteralWins.errors.txt +++ b/tests/baselines/reference/lastPropertyInLiteralWins.errors.txt @@ -1,12 +1,14 @@ +tests/cases/compiler/lastPropertyInLiteralWins.ts(8,5): error TS2300: Duplicate identifier 'thunk'. tests/cases/compiler/lastPropertyInLiteralWins.ts(8,5): error TS2322: Type '(num: number) => void' is not assignable to type '(str: string) => void'. Types of parameters 'num' and 'str' are incompatible. Type 'string' is not assignable to type 'number'. tests/cases/compiler/lastPropertyInLiteralWins.ts(9,5): error TS2300: Duplicate identifier 'thunk'. tests/cases/compiler/lastPropertyInLiteralWins.ts(9,5): error TS2322: Type '(num: number) => void' is not assignable to type '(str: string) => void'. +tests/cases/compiler/lastPropertyInLiteralWins.ts(13,5): error TS2300: Duplicate identifier 'thunk'. tests/cases/compiler/lastPropertyInLiteralWins.ts(14,5): error TS2300: Duplicate identifier 'thunk'. -==== tests/cases/compiler/lastPropertyInLiteralWins.ts (4 errors) ==== +==== tests/cases/compiler/lastPropertyInLiteralWins.ts (6 errors) ==== interface Thing { thunk: (str: string) => void; } @@ -16,6 +18,8 @@ tests/cases/compiler/lastPropertyInLiteralWins.ts(14,5): error TS2300: Duplicate test({ // Should error, as last one wins, and is wrong type thunk: (str: string) => {}, ~~~~~ +!!! error TS2300: Duplicate identifier 'thunk'. + ~~~~~ !!! error TS2322: Type '(num: number) => void' is not assignable to type '(str: string) => void'. !!! error TS2322: Types of parameters 'num' and 'str' are incompatible. !!! error TS2322: Type 'string' is not assignable to type 'number'. @@ -30,6 +34,8 @@ tests/cases/compiler/lastPropertyInLiteralWins.ts(14,5): error TS2300: Duplicate test({ // Should be OK. Last 'thunk' is of correct type thunk: (num: number) => {}, + ~~~~~ +!!! error TS2300: Duplicate identifier 'thunk'. thunk: (str: string) => {} ~~~~~ !!! error TS2300: Duplicate identifier 'thunk'. diff --git a/tests/baselines/reference/memberOverride.errors.txt b/tests/baselines/reference/memberOverride.errors.txt index 15c4b2ad37bb8..b4974e69e5363 100644 --- a/tests/baselines/reference/memberOverride.errors.txt +++ b/tests/baselines/reference/memberOverride.errors.txt @@ -1,11 +1,14 @@ +tests/cases/compiler/memberOverride.ts(4,5): error TS2300: Duplicate identifier 'a'. tests/cases/compiler/memberOverride.ts(5,5): error TS2300: Duplicate identifier 'a'. -==== tests/cases/compiler/memberOverride.ts (1 errors) ==== +==== tests/cases/compiler/memberOverride.ts (2 errors) ==== // An object initialiser accepts the first definition for the same property with a different type signature // Should compile, since the second declaration of a overrides the first var x = { a: "", + ~ +!!! error TS2300: Duplicate identifier 'a'. a: 5 ~ !!! error TS2300: Duplicate identifier 'a'. diff --git a/tests/baselines/reference/mergeClassAndInterfaceWithConflictingAccessors.errors.txt b/tests/baselines/reference/mergeClassAndInterfaceWithConflictingAccessors.errors.txt new file mode 100644 index 0000000000000..e40a0796307c1 --- /dev/null +++ b/tests/baselines/reference/mergeClassAndInterfaceWithConflictingAccessors.errors.txt @@ -0,0 +1,87 @@ +tests/cases/conformance/interfaces/declarationMerging/mergeClassAndInterfaceWithConflictingAccessors.ts(9,9): error TS2380: 'get' and 'set' accessor must have the same type. +tests/cases/conformance/interfaces/declarationMerging/mergeClassAndInterfaceWithConflictingAccessors.ts(12,9): error TS2380: 'get' and 'set' accessor must have the same type. +tests/cases/conformance/interfaces/declarationMerging/mergeClassAndInterfaceWithConflictingAccessors.ts(16,9): error TS2300: Duplicate identifier 'x'. +tests/cases/conformance/interfaces/declarationMerging/mergeClassAndInterfaceWithConflictingAccessors.ts(17,9): error TS2300: Duplicate identifier 'x'. +tests/cases/conformance/interfaces/declarationMerging/mergeClassAndInterfaceWithConflictingAccessors.ts(20,5): error TS2300: Duplicate identifier 'x'. +tests/cases/conformance/interfaces/declarationMerging/mergeClassAndInterfaceWithConflictingAccessors.ts(24,5): error TS2300: Duplicate identifier 'x'. +tests/cases/conformance/interfaces/declarationMerging/mergeClassAndInterfaceWithConflictingAccessors.ts(27,9): error TS2300: Duplicate identifier 'x'. +tests/cases/conformance/interfaces/declarationMerging/mergeClassAndInterfaceWithConflictingAccessors.ts(28,9): error TS2300: Duplicate identifier 'x'. + + +==== tests/cases/conformance/interfaces/declarationMerging/mergeClassAndInterfaceWithConflictingAccessors.ts (8 errors) ==== + declare class A { + get x(): number; + } + interface A { + get x(): string; + } + + declare class B { + get x(): number; + ~ +!!! error TS2380: 'get' and 'set' accessor must have the same type. + } + interface B { + set x(value: string); + ~ +!!! error TS2380: 'get' and 'set' accessor must have the same type. + } + + declare class C { + get x(): number; + ~ +!!! error TS2300: Duplicate identifier 'x'. + set x(value: number); + ~ +!!! error TS2300: Duplicate identifier 'x'. + } + interface C { + x: number; + ~ +!!! error TS2300: Duplicate identifier 'x'. + } + + declare class D { + x: number; + ~ +!!! error TS2300: Duplicate identifier 'x'. + } + interface D { + get x(): number; + ~ +!!! error TS2300: Duplicate identifier 'x'. + set x(value: number); + ~ +!!! error TS2300: Duplicate identifier 'x'. + } + + declare class E { + get x(): number; + } + interface E { + get x(): number; // ok + } + + declare class F { + set x(value: string); + } + interface F { + get x(): string; // ok + } + + declare class G { + get x(): number; + set x(value: number); + } + interface G { + get x(): number; + set x(value: number); + } + + declare class H { + x: number; + } + interface H { + x: number; + } + \ No newline at end of file diff --git a/tests/baselines/reference/mergeClassAndInterfaceWithConflictingAccessors.symbols b/tests/baselines/reference/mergeClassAndInterfaceWithConflictingAccessors.symbols new file mode 100644 index 0000000000000..0e824630d45d8 --- /dev/null +++ b/tests/baselines/reference/mergeClassAndInterfaceWithConflictingAccessors.symbols @@ -0,0 +1,123 @@ +=== tests/cases/conformance/interfaces/declarationMerging/mergeClassAndInterfaceWithConflictingAccessors.ts === +declare class A { +>A : Symbol(A, Decl(mergeClassAndInterfaceWithConflictingAccessors.ts, 0, 0), Decl(mergeClassAndInterfaceWithConflictingAccessors.ts, 2, 1)) + + get x(): number; +>x : Symbol(A.x, Decl(mergeClassAndInterfaceWithConflictingAccessors.ts, 0, 17), Decl(mergeClassAndInterfaceWithConflictingAccessors.ts, 3, 13)) +} +interface A { +>A : Symbol(A, Decl(mergeClassAndInterfaceWithConflictingAccessors.ts, 0, 0), Decl(mergeClassAndInterfaceWithConflictingAccessors.ts, 2, 1)) + + get x(): string; +>x : Symbol(A.x, Decl(mergeClassAndInterfaceWithConflictingAccessors.ts, 0, 17), Decl(mergeClassAndInterfaceWithConflictingAccessors.ts, 3, 13)) +} + +declare class B { +>B : Symbol(B, Decl(mergeClassAndInterfaceWithConflictingAccessors.ts, 5, 1), Decl(mergeClassAndInterfaceWithConflictingAccessors.ts, 9, 1)) + + get x(): number; +>x : Symbol(B.x, Decl(mergeClassAndInterfaceWithConflictingAccessors.ts, 7, 17), Decl(mergeClassAndInterfaceWithConflictingAccessors.ts, 10, 13)) +} +interface B { +>B : Symbol(B, Decl(mergeClassAndInterfaceWithConflictingAccessors.ts, 5, 1), Decl(mergeClassAndInterfaceWithConflictingAccessors.ts, 9, 1)) + + set x(value: string); +>x : Symbol(B.x, Decl(mergeClassAndInterfaceWithConflictingAccessors.ts, 7, 17), Decl(mergeClassAndInterfaceWithConflictingAccessors.ts, 10, 13)) +>value : Symbol(value, Decl(mergeClassAndInterfaceWithConflictingAccessors.ts, 11, 10)) +} + +declare class C { +>C : Symbol(C, Decl(mergeClassAndInterfaceWithConflictingAccessors.ts, 12, 1), Decl(mergeClassAndInterfaceWithConflictingAccessors.ts, 17, 1)) + + get x(): number; +>x : Symbol(C.x, Decl(mergeClassAndInterfaceWithConflictingAccessors.ts, 14, 17), Decl(mergeClassAndInterfaceWithConflictingAccessors.ts, 15, 20)) + + set x(value: number); +>x : Symbol(C.x, Decl(mergeClassAndInterfaceWithConflictingAccessors.ts, 14, 17), Decl(mergeClassAndInterfaceWithConflictingAccessors.ts, 15, 20)) +>value : Symbol(value, Decl(mergeClassAndInterfaceWithConflictingAccessors.ts, 16, 10)) +} +interface C { +>C : Symbol(C, Decl(mergeClassAndInterfaceWithConflictingAccessors.ts, 12, 1), Decl(mergeClassAndInterfaceWithConflictingAccessors.ts, 17, 1)) + + x: number; +>x : Symbol(C.x, Decl(mergeClassAndInterfaceWithConflictingAccessors.ts, 18, 13)) +} + +declare class D { +>D : Symbol(D, Decl(mergeClassAndInterfaceWithConflictingAccessors.ts, 20, 1), Decl(mergeClassAndInterfaceWithConflictingAccessors.ts, 24, 1)) + + x: number; +>x : Symbol(D.x, Decl(mergeClassAndInterfaceWithConflictingAccessors.ts, 22, 17)) +} +interface D { +>D : Symbol(D, Decl(mergeClassAndInterfaceWithConflictingAccessors.ts, 20, 1), Decl(mergeClassAndInterfaceWithConflictingAccessors.ts, 24, 1)) + + get x(): number; +>x : Symbol(D.x, Decl(mergeClassAndInterfaceWithConflictingAccessors.ts, 25, 13)) + + set x(value: number); +>x : Symbol(D.x, Decl(mergeClassAndInterfaceWithConflictingAccessors.ts, 26, 20)) +>value : Symbol(value, Decl(mergeClassAndInterfaceWithConflictingAccessors.ts, 27, 10)) +} + +declare class E { +>E : Symbol(E, Decl(mergeClassAndInterfaceWithConflictingAccessors.ts, 28, 1), Decl(mergeClassAndInterfaceWithConflictingAccessors.ts, 32, 1)) + + get x(): number; +>x : Symbol(E.x, Decl(mergeClassAndInterfaceWithConflictingAccessors.ts, 30, 17), Decl(mergeClassAndInterfaceWithConflictingAccessors.ts, 33, 13)) +} +interface E { +>E : Symbol(E, Decl(mergeClassAndInterfaceWithConflictingAccessors.ts, 28, 1), Decl(mergeClassAndInterfaceWithConflictingAccessors.ts, 32, 1)) + + get x(): number; // ok +>x : Symbol(E.x, Decl(mergeClassAndInterfaceWithConflictingAccessors.ts, 30, 17), Decl(mergeClassAndInterfaceWithConflictingAccessors.ts, 33, 13)) +} + +declare class F { +>F : Symbol(F, Decl(mergeClassAndInterfaceWithConflictingAccessors.ts, 35, 1), Decl(mergeClassAndInterfaceWithConflictingAccessors.ts, 39, 1)) + + set x(value: string); +>x : Symbol(F.x, Decl(mergeClassAndInterfaceWithConflictingAccessors.ts, 37, 17), Decl(mergeClassAndInterfaceWithConflictingAccessors.ts, 40, 13)) +>value : Symbol(value, Decl(mergeClassAndInterfaceWithConflictingAccessors.ts, 38, 10)) +} +interface F { +>F : Symbol(F, Decl(mergeClassAndInterfaceWithConflictingAccessors.ts, 35, 1), Decl(mergeClassAndInterfaceWithConflictingAccessors.ts, 39, 1)) + + get x(): string; // ok +>x : Symbol(F.x, Decl(mergeClassAndInterfaceWithConflictingAccessors.ts, 37, 17), Decl(mergeClassAndInterfaceWithConflictingAccessors.ts, 40, 13)) +} + +declare class G { +>G : Symbol(G, Decl(mergeClassAndInterfaceWithConflictingAccessors.ts, 42, 1), Decl(mergeClassAndInterfaceWithConflictingAccessors.ts, 47, 1)) + + get x(): number; +>x : Symbol(G.x, Decl(mergeClassAndInterfaceWithConflictingAccessors.ts, 44, 17), Decl(mergeClassAndInterfaceWithConflictingAccessors.ts, 45, 20), Decl(mergeClassAndInterfaceWithConflictingAccessors.ts, 48, 13), Decl(mergeClassAndInterfaceWithConflictingAccessors.ts, 49, 20)) + + set x(value: number); +>x : Symbol(G.x, Decl(mergeClassAndInterfaceWithConflictingAccessors.ts, 44, 17), Decl(mergeClassAndInterfaceWithConflictingAccessors.ts, 45, 20), Decl(mergeClassAndInterfaceWithConflictingAccessors.ts, 48, 13), Decl(mergeClassAndInterfaceWithConflictingAccessors.ts, 49, 20)) +>value : Symbol(value, Decl(mergeClassAndInterfaceWithConflictingAccessors.ts, 46, 10)) +} +interface G { +>G : Symbol(G, Decl(mergeClassAndInterfaceWithConflictingAccessors.ts, 42, 1), Decl(mergeClassAndInterfaceWithConflictingAccessors.ts, 47, 1)) + + get x(): number; +>x : Symbol(G.x, Decl(mergeClassAndInterfaceWithConflictingAccessors.ts, 44, 17), Decl(mergeClassAndInterfaceWithConflictingAccessors.ts, 45, 20), Decl(mergeClassAndInterfaceWithConflictingAccessors.ts, 48, 13), Decl(mergeClassAndInterfaceWithConflictingAccessors.ts, 49, 20)) + + set x(value: number); +>x : Symbol(G.x, Decl(mergeClassAndInterfaceWithConflictingAccessors.ts, 44, 17), Decl(mergeClassAndInterfaceWithConflictingAccessors.ts, 45, 20), Decl(mergeClassAndInterfaceWithConflictingAccessors.ts, 48, 13), Decl(mergeClassAndInterfaceWithConflictingAccessors.ts, 49, 20)) +>value : Symbol(value, Decl(mergeClassAndInterfaceWithConflictingAccessors.ts, 50, 10)) +} + +declare class H { +>H : Symbol(H, Decl(mergeClassAndInterfaceWithConflictingAccessors.ts, 51, 1), Decl(mergeClassAndInterfaceWithConflictingAccessors.ts, 55, 1)) + + x: number; +>x : Symbol(H.x, Decl(mergeClassAndInterfaceWithConflictingAccessors.ts, 53, 17), Decl(mergeClassAndInterfaceWithConflictingAccessors.ts, 56, 13)) +} +interface H { +>H : Symbol(H, Decl(mergeClassAndInterfaceWithConflictingAccessors.ts, 51, 1), Decl(mergeClassAndInterfaceWithConflictingAccessors.ts, 55, 1)) + + x: number; +>x : Symbol(H.x, Decl(mergeClassAndInterfaceWithConflictingAccessors.ts, 53, 17), Decl(mergeClassAndInterfaceWithConflictingAccessors.ts, 56, 13)) +} + diff --git a/tests/baselines/reference/mergeClassAndInterfaceWithConflictingAccessors.types b/tests/baselines/reference/mergeClassAndInterfaceWithConflictingAccessors.types new file mode 100644 index 0000000000000..93f8b466f163d --- /dev/null +++ b/tests/baselines/reference/mergeClassAndInterfaceWithConflictingAccessors.types @@ -0,0 +1,107 @@ +=== tests/cases/conformance/interfaces/declarationMerging/mergeClassAndInterfaceWithConflictingAccessors.ts === +declare class A { +>A : A + + get x(): number; +>x : number +} +interface A { + get x(): string; +>x : number +} + +declare class B { +>B : B + + get x(): number; +>x : number +} +interface B { + set x(value: string); +>x : number +>value : string +} + +declare class C { +>C : C + + get x(): number; +>x : number + + set x(value: number); +>x : number +>value : number +} +interface C { + x: number; +>x : number +} + +declare class D { +>D : D + + x: number; +>x : number +} +interface D { + get x(): number; +>x : number + + set x(value: number); +>x : number +>value : number +} + +declare class E { +>E : E + + get x(): number; +>x : number +} +interface E { + get x(): number; // ok +>x : number +} + +declare class F { +>F : F + + set x(value: string); +>x : string +>value : string +} +interface F { + get x(): string; // ok +>x : string +} + +declare class G { +>G : G + + get x(): number; +>x : number + + set x(value: number); +>x : number +>value : number +} +interface G { + get x(): number; +>x : number + + set x(value: number); +>x : number +>value : number +} + +declare class H { +>H : H + + x: number; +>x : number +} +interface H { + x: number; +>x : number +} + diff --git a/tests/baselines/reference/mergedInterfacesWithConflictingAccessors.errors.txt b/tests/baselines/reference/mergedInterfacesWithConflictingAccessors.errors.txt new file mode 100644 index 0000000000000..0802455302014 --- /dev/null +++ b/tests/baselines/reference/mergedInterfacesWithConflictingAccessors.errors.txt @@ -0,0 +1,40 @@ +tests/cases/conformance/interfaces/declarationMerging/mergedInterfacesWithConflictingAccessors.ts(9,9): error TS2380: 'get' and 'set' accessor must have the same type. +tests/cases/conformance/interfaces/declarationMerging/mergedInterfacesWithConflictingAccessors.ts(12,9): error TS2380: 'get' and 'set' accessor must have the same type. +tests/cases/conformance/interfaces/declarationMerging/mergedInterfacesWithConflictingAccessors.ts(16,5): error TS2300: Duplicate identifier 'x'. +tests/cases/conformance/interfaces/declarationMerging/mergedInterfacesWithConflictingAccessors.ts(19,9): error TS2300: Duplicate identifier 'x'. +tests/cases/conformance/interfaces/declarationMerging/mergedInterfacesWithConflictingAccessors.ts(20,9): error TS2300: Duplicate identifier 'x'. + + +==== tests/cases/conformance/interfaces/declarationMerging/mergedInterfacesWithConflictingAccessors.ts (5 errors) ==== + interface A { + get x(): number; + } + interface A { + get x(): string; + } + + interface B { + get x(): number; + ~ +!!! error TS2380: 'get' and 'set' accessor must have the same type. + } + interface B { + set x(value: string); + ~ +!!! error TS2380: 'get' and 'set' accessor must have the same type. + } + + interface C { + x: number; + ~ +!!! error TS2300: Duplicate identifier 'x'. + } + interface C { + get x(): number; + ~ +!!! error TS2300: Duplicate identifier 'x'. + set x(value: number); + ~ +!!! error TS2300: Duplicate identifier 'x'. + } + \ No newline at end of file diff --git a/tests/baselines/reference/mergedInterfacesWithConflictingAccessors.symbols b/tests/baselines/reference/mergedInterfacesWithConflictingAccessors.symbols new file mode 100644 index 0000000000000..a89df033355ef --- /dev/null +++ b/tests/baselines/reference/mergedInterfacesWithConflictingAccessors.symbols @@ -0,0 +1,45 @@ +=== tests/cases/conformance/interfaces/declarationMerging/mergedInterfacesWithConflictingAccessors.ts === +interface A { +>A : Symbol(A, Decl(mergedInterfacesWithConflictingAccessors.ts, 0, 0), Decl(mergedInterfacesWithConflictingAccessors.ts, 2, 1)) + + get x(): number; +>x : Symbol(A.x, Decl(mergedInterfacesWithConflictingAccessors.ts, 0, 13), Decl(mergedInterfacesWithConflictingAccessors.ts, 3, 13)) +} +interface A { +>A : Symbol(A, Decl(mergedInterfacesWithConflictingAccessors.ts, 0, 0), Decl(mergedInterfacesWithConflictingAccessors.ts, 2, 1)) + + get x(): string; +>x : Symbol(A.x, Decl(mergedInterfacesWithConflictingAccessors.ts, 0, 13), Decl(mergedInterfacesWithConflictingAccessors.ts, 3, 13)) +} + +interface B { +>B : Symbol(B, Decl(mergedInterfacesWithConflictingAccessors.ts, 5, 1), Decl(mergedInterfacesWithConflictingAccessors.ts, 9, 1)) + + get x(): number; +>x : Symbol(B.x, Decl(mergedInterfacesWithConflictingAccessors.ts, 7, 13), Decl(mergedInterfacesWithConflictingAccessors.ts, 10, 13)) +} +interface B { +>B : Symbol(B, Decl(mergedInterfacesWithConflictingAccessors.ts, 5, 1), Decl(mergedInterfacesWithConflictingAccessors.ts, 9, 1)) + + set x(value: string); +>x : Symbol(B.x, Decl(mergedInterfacesWithConflictingAccessors.ts, 7, 13), Decl(mergedInterfacesWithConflictingAccessors.ts, 10, 13)) +>value : Symbol(value, Decl(mergedInterfacesWithConflictingAccessors.ts, 11, 10)) +} + +interface C { +>C : Symbol(C, Decl(mergedInterfacesWithConflictingAccessors.ts, 12, 1), Decl(mergedInterfacesWithConflictingAccessors.ts, 16, 1)) + + x: number; +>x : Symbol(C.x, Decl(mergedInterfacesWithConflictingAccessors.ts, 14, 13)) +} +interface C { +>C : Symbol(C, Decl(mergedInterfacesWithConflictingAccessors.ts, 12, 1), Decl(mergedInterfacesWithConflictingAccessors.ts, 16, 1)) + + get x(): number; +>x : Symbol(C.x, Decl(mergedInterfacesWithConflictingAccessors.ts, 17, 13)) + + set x(value: number); +>x : Symbol(C.x, Decl(mergedInterfacesWithConflictingAccessors.ts, 18, 20)) +>value : Symbol(value, Decl(mergedInterfacesWithConflictingAccessors.ts, 19, 10)) +} + diff --git a/tests/baselines/reference/mergedInterfacesWithConflictingAccessors.types b/tests/baselines/reference/mergedInterfacesWithConflictingAccessors.types new file mode 100644 index 0000000000000..ee356dc043313 --- /dev/null +++ b/tests/baselines/reference/mergedInterfacesWithConflictingAccessors.types @@ -0,0 +1,33 @@ +=== tests/cases/conformance/interfaces/declarationMerging/mergedInterfacesWithConflictingAccessors.ts === +interface A { + get x(): number; +>x : number +} +interface A { + get x(): string; +>x : number +} + +interface B { + get x(): number; +>x : number +} +interface B { + set x(value: string); +>x : number +>value : string +} + +interface C { + x: number; +>x : number +} +interface C { + get x(): number; +>x : number + + set x(value: number); +>x : number +>value : number +} + diff --git a/tests/baselines/reference/methodSignatureHandledDeclarationKindForSymbol.errors.txt b/tests/baselines/reference/methodSignatureHandledDeclarationKindForSymbol.errors.txt index edb66f56dd347..27df3e8e0d2b7 100644 --- a/tests/baselines/reference/methodSignatureHandledDeclarationKindForSymbol.errors.txt +++ b/tests/baselines/reference/methodSignatureHandledDeclarationKindForSymbol.errors.txt @@ -1,16 +1,18 @@ -tests/cases/compiler/methodSignatureHandledDeclarationKindForSymbol.ts(6,5): error TS2717: Subsequent property declarations must have the same type. Property 'bold' must be of type '() => string', but here has type 'string'. +tests/cases/compiler/methodSignatureHandledDeclarationKindForSymbol.ts(2,5): error TS2300: Duplicate identifier 'bold'. +tests/cases/compiler/methodSignatureHandledDeclarationKindForSymbol.ts(6,5): error TS2300: Duplicate identifier 'bold'. -==== tests/cases/compiler/methodSignatureHandledDeclarationKindForSymbol.ts (1 errors) ==== +==== tests/cases/compiler/methodSignatureHandledDeclarationKindForSymbol.ts (2 errors) ==== interface Foo { bold(): string; + ~~~~ +!!! error TS2300: Duplicate identifier 'bold'. } interface Foo { bold: string; ~~~~ -!!! error TS2717: Subsequent property declarations must have the same type. Property 'bold' must be of type '() => string', but here has type 'string'. -!!! related TS6203 tests/cases/compiler/methodSignatureHandledDeclarationKindForSymbol.ts:2:5: 'bold' was also declared here. +!!! error TS2300: Duplicate identifier 'bold'. } \ No newline at end of file diff --git a/tests/baselines/reference/methodSignatureHandledDeclarationKindForSymbol.symbols b/tests/baselines/reference/methodSignatureHandledDeclarationKindForSymbol.symbols index 27bc633ce5751..98816ea7a2407 100644 --- a/tests/baselines/reference/methodSignatureHandledDeclarationKindForSymbol.symbols +++ b/tests/baselines/reference/methodSignatureHandledDeclarationKindForSymbol.symbols @@ -3,14 +3,14 @@ interface Foo { >Foo : Symbol(Foo, Decl(methodSignatureHandledDeclarationKindForSymbol.ts, 0, 0), Decl(methodSignatureHandledDeclarationKindForSymbol.ts, 2, 1)) bold(): string; ->bold : Symbol(Foo.bold, Decl(methodSignatureHandledDeclarationKindForSymbol.ts, 0, 15), Decl(methodSignatureHandledDeclarationKindForSymbol.ts, 4, 15)) +>bold : Symbol(Foo.bold, Decl(methodSignatureHandledDeclarationKindForSymbol.ts, 0, 15)) } interface Foo { >Foo : Symbol(Foo, Decl(methodSignatureHandledDeclarationKindForSymbol.ts, 0, 0), Decl(methodSignatureHandledDeclarationKindForSymbol.ts, 2, 1)) bold: string; ->bold : Symbol(Foo.bold, Decl(methodSignatureHandledDeclarationKindForSymbol.ts, 0, 15), Decl(methodSignatureHandledDeclarationKindForSymbol.ts, 4, 15)) +>bold : Symbol(Foo.bold, Decl(methodSignatureHandledDeclarationKindForSymbol.ts, 4, 15)) } diff --git a/tests/baselines/reference/methodSignatureHandledDeclarationKindForSymbol.types b/tests/baselines/reference/methodSignatureHandledDeclarationKindForSymbol.types index d565bebc1b6fc..7c14015b1d746 100644 --- a/tests/baselines/reference/methodSignatureHandledDeclarationKindForSymbol.types +++ b/tests/baselines/reference/methodSignatureHandledDeclarationKindForSymbol.types @@ -6,7 +6,7 @@ interface Foo { interface Foo { bold: string; ->bold : () => string +>bold : string } diff --git a/tests/baselines/reference/multipleDeclarations.symbols b/tests/baselines/reference/multipleDeclarations.symbols index b33ebc0222fb3..8b7bae125bf84 100644 --- a/tests/baselines/reference/multipleDeclarations.symbols +++ b/tests/baselines/reference/multipleDeclarations.symbols @@ -30,7 +30,7 @@ class X { >this : Symbol(X, Decl(input.js, 5, 1)) this.mistake = 'frankly, complete nonsense'; ->this.mistake : Symbol(X.mistake, Decl(input.js, 12, 5), Decl(input.js, 16, 16)) +>this.mistake : Symbol(X.mistake, Decl(input.js, 12, 5)) >this : Symbol(X, Decl(input.js, 5, 1)) >mistake : Symbol(X.mistake, Decl(input.js, 8, 35)) } @@ -38,7 +38,7 @@ class X { >m : Symbol(X.m, Decl(input.js, 10, 5)) } mistake() { ->mistake : Symbol(X.mistake, Decl(input.js, 12, 5), Decl(input.js, 16, 16)) +>mistake : Symbol(X.mistake, Decl(input.js, 12, 5)) } } let x = new X(); @@ -46,11 +46,11 @@ let x = new X(); >X : Symbol(X, Decl(input.js, 5, 1)) X.prototype.mistake = false; ->X.prototype.mistake : Symbol(X.mistake, Decl(input.js, 12, 5), Decl(input.js, 16, 16)) ->X.prototype : Symbol(X.mistake, Decl(input.js, 12, 5), Decl(input.js, 16, 16)) +>X.prototype.mistake : Symbol(X.mistake, Decl(input.js, 12, 5)) +>X.prototype : Symbol(X.mistake, Decl(input.js, 16, 16)) >X : Symbol(X, Decl(input.js, 5, 1)) >prototype : Symbol(X.prototype) ->mistake : Symbol(X.mistake, Decl(input.js, 12, 5), Decl(input.js, 16, 16)) +>mistake : Symbol(X.mistake, Decl(input.js, 16, 16)) x.m(); >x.m : Symbol(X.m, Decl(input.js, 10, 5)) @@ -58,15 +58,15 @@ x.m(); >m : Symbol(X.m, Decl(input.js, 10, 5)) x.mistake; ->x.mistake : Symbol(X.mistake, Decl(input.js, 12, 5), Decl(input.js, 16, 16)) +>x.mistake : Symbol(X.mistake, Decl(input.js, 12, 5)) >x : Symbol(x, Decl(input.js, 16, 3)) ->mistake : Symbol(X.mistake, Decl(input.js, 12, 5), Decl(input.js, 16, 16)) +>mistake : Symbol(X.mistake, Decl(input.js, 12, 5)) class Y { >Y : Symbol(Y, Decl(input.js, 19, 10)) mistake() { ->mistake : Symbol(Y.mistake, Decl(input.js, 20, 9), Decl(input.js, 29, 1)) +>mistake : Symbol(Y.mistake, Decl(input.js, 20, 9)) } m() { >m : Symbol(Y.m, Decl(input.js, 22, 5)) @@ -84,17 +84,17 @@ class Y { >this : Symbol(Y, Decl(input.js, 19, 10)) this.mistake = 'even more nonsense'; ->this.mistake : Symbol(Y.mistake, Decl(input.js, 20, 9), Decl(input.js, 29, 1)) +>this.mistake : Symbol(Y.mistake, Decl(input.js, 20, 9)) >this : Symbol(Y, Decl(input.js, 19, 10)) ->mistake : Symbol(Y.mistake, Decl(input.js, 20, 9), Decl(input.js, 29, 1)) +>mistake : Symbol(Y.mistake, Decl(input.js, 20, 9)) } } Y.prototype.mistake = true; ->Y.prototype.mistake : Symbol(Y.mistake, Decl(input.js, 20, 9), Decl(input.js, 29, 1)) ->Y.prototype : Symbol(Y.mistake, Decl(input.js, 20, 9), Decl(input.js, 29, 1)) +>Y.prototype.mistake : Symbol(Y.mistake, Decl(input.js, 20, 9)) +>Y.prototype : Symbol(Y.mistake, Decl(input.js, 29, 1)) >Y : Symbol(Y, Decl(input.js, 19, 10)) >prototype : Symbol(Y.prototype) ->mistake : Symbol(Y.mistake, Decl(input.js, 20, 9), Decl(input.js, 29, 1)) +>mistake : Symbol(Y.mistake, Decl(input.js, 29, 1)) let y = new Y(); >y : Symbol(y, Decl(input.js, 31, 3)) @@ -106,7 +106,7 @@ y.m(); >m : Symbol(Y.m, Decl(input.js, 22, 5)) y.mistake(); ->y.mistake : Symbol(Y.mistake, Decl(input.js, 20, 9), Decl(input.js, 29, 1)) +>y.mistake : Symbol(Y.mistake, Decl(input.js, 20, 9)) >y : Symbol(y, Decl(input.js, 31, 3)) ->mistake : Symbol(Y.mistake, Decl(input.js, 20, 9), Decl(input.js, 29, 1)) +>mistake : Symbol(Y.mistake, Decl(input.js, 20, 9)) diff --git a/tests/baselines/reference/numericClassMembers1.errors.txt b/tests/baselines/reference/numericClassMembers1.errors.txt index 28c06a6fcf514..dd88beb5029ae 100644 --- a/tests/baselines/reference/numericClassMembers1.errors.txt +++ b/tests/baselines/reference/numericClassMembers1.errors.txt @@ -1,20 +1,26 @@ -tests/cases/compiler/numericClassMembers1.ts(3,3): error TS2300: Duplicate identifier '0.0'. -tests/cases/compiler/numericClassMembers1.ts(8,2): error TS2300: Duplicate identifier ''0''. +tests/cases/compiler/numericClassMembers1.ts(2,3): error TS2300: Duplicate identifier '0'. +tests/cases/compiler/numericClassMembers1.ts(3,3): error TS2300: Duplicate identifier '0'. +tests/cases/compiler/numericClassMembers1.ts(7,3): error TS2300: Duplicate identifier '0'. +tests/cases/compiler/numericClassMembers1.ts(8,2): error TS2300: Duplicate identifier '0'. -==== tests/cases/compiler/numericClassMembers1.ts (2 errors) ==== +==== tests/cases/compiler/numericClassMembers1.ts (4 errors) ==== class C234 { 0 = 1; + ~ +!!! error TS2300: Duplicate identifier '0'. 0.0 = 2; ~~~ -!!! error TS2300: Duplicate identifier '0.0'. +!!! error TS2300: Duplicate identifier '0'. } class C235 { 0.0 = 1; + ~~~ +!!! error TS2300: Duplicate identifier '0'. '0' = 2; ~~~ -!!! error TS2300: Duplicate identifier ''0''. +!!! error TS2300: Duplicate identifier '0'. } class C236 { diff --git a/tests/baselines/reference/numericNamedPropertyDuplicates.errors.txt b/tests/baselines/reference/numericNamedPropertyDuplicates.errors.txt index 5fb05297f119a..a298ce6878245 100644 --- a/tests/baselines/reference/numericNamedPropertyDuplicates.errors.txt +++ b/tests/baselines/reference/numericNamedPropertyDuplicates.errors.txt @@ -1,4 +1,6 @@ -tests/cases/conformance/types/objectTypeLiteral/propertySignatures/numericNamedPropertyDuplicates.ts(3,5): error TS2300: Duplicate identifier '1.0'. +tests/cases/conformance/types/objectTypeLiteral/propertySignatures/numericNamedPropertyDuplicates.ts(2,5): error TS2300: Duplicate identifier '1'. +tests/cases/conformance/types/objectTypeLiteral/propertySignatures/numericNamedPropertyDuplicates.ts(3,5): error TS2300: Duplicate identifier '1'. +tests/cases/conformance/types/objectTypeLiteral/propertySignatures/numericNamedPropertyDuplicates.ts(4,12): error TS2300: Duplicate identifier '2'. tests/cases/conformance/types/objectTypeLiteral/propertySignatures/numericNamedPropertyDuplicates.ts(5,12): error TS2300: Duplicate identifier '2'. tests/cases/conformance/types/objectTypeLiteral/propertySignatures/numericNamedPropertyDuplicates.ts(9,5): error TS2300: Duplicate identifier '2'. tests/cases/conformance/types/objectTypeLiteral/propertySignatures/numericNamedPropertyDuplicates.ts(10,5): error TS2300: Duplicate identifier '2'. @@ -7,13 +9,17 @@ tests/cases/conformance/types/objectTypeLiteral/propertySignatures/numericNamedP tests/cases/conformance/types/objectTypeLiteral/propertySignatures/numericNamedPropertyDuplicates.ts(20,5): error TS1005: ',' expected. -==== tests/cases/conformance/types/objectTypeLiteral/propertySignatures/numericNamedPropertyDuplicates.ts (7 errors) ==== +==== tests/cases/conformance/types/objectTypeLiteral/propertySignatures/numericNamedPropertyDuplicates.ts (9 errors) ==== class C { 1: number; + ~ +!!! error TS2300: Duplicate identifier '1'. 1.0: number; ~~~ -!!! error TS2300: Duplicate identifier '1.0'. +!!! error TS2300: Duplicate identifier '1'. static 2: number; + ~ +!!! error TS2300: Duplicate identifier '2'. static 2: number; ~ !!! error TS2300: Duplicate identifier '2'. diff --git a/tests/baselines/reference/numericStringNamedPropertyEquivalence.errors.txt b/tests/baselines/reference/numericStringNamedPropertyEquivalence.errors.txt index 7d3ff163300d5..a04801868ddf9 100644 --- a/tests/baselines/reference/numericStringNamedPropertyEquivalence.errors.txt +++ b/tests/baselines/reference/numericStringNamedPropertyEquivalence.errors.txt @@ -1,21 +1,25 @@ -tests/cases/conformance/types/objectTypeLiteral/propertySignatures/numericStringNamedPropertyEquivalence.ts(6,5): error TS2300: Duplicate identifier '1.0'. +tests/cases/conformance/types/objectTypeLiteral/propertySignatures/numericStringNamedPropertyEquivalence.ts(4,5): error TS2300: Duplicate identifier '1'. +tests/cases/conformance/types/objectTypeLiteral/propertySignatures/numericStringNamedPropertyEquivalence.ts(6,5): error TS2300: Duplicate identifier '1'. tests/cases/conformance/types/objectTypeLiteral/propertySignatures/numericStringNamedPropertyEquivalence.ts(10,5): error TS2300: Duplicate identifier '1'. tests/cases/conformance/types/objectTypeLiteral/propertySignatures/numericStringNamedPropertyEquivalence.ts(12,5): error TS2300: Duplicate identifier '1'. tests/cases/conformance/types/objectTypeLiteral/propertySignatures/numericStringNamedPropertyEquivalence.ts(16,5): error TS2300: Duplicate identifier '1'. tests/cases/conformance/types/objectTypeLiteral/propertySignatures/numericStringNamedPropertyEquivalence.ts(17,5): error TS2300: Duplicate identifier '1'. tests/cases/conformance/types/objectTypeLiteral/propertySignatures/numericStringNamedPropertyEquivalence.ts(17,5): error TS2717: Subsequent property declarations must have the same type. Property '1.0' must be of type 'number', but here has type 'string'. +tests/cases/conformance/types/objectTypeLiteral/propertySignatures/numericStringNamedPropertyEquivalence.ts(21,5): error TS2300: Duplicate identifier '0'. tests/cases/conformance/types/objectTypeLiteral/propertySignatures/numericStringNamedPropertyEquivalence.ts(22,5): error TS2300: Duplicate identifier '0'. -==== tests/cases/conformance/types/objectTypeLiteral/propertySignatures/numericStringNamedPropertyEquivalence.ts (7 errors) ==== +==== tests/cases/conformance/types/objectTypeLiteral/propertySignatures/numericStringNamedPropertyEquivalence.ts (9 errors) ==== // Each of these types has an error in it. // String named and numeric named properties conflict if they would be equivalent after ToNumber on the property name. class C { "1": number; + ~~~ +!!! error TS2300: Duplicate identifier '1'. "1.0": number; // not a duplicate 1.0: number; ~~~ -!!! error TS2300: Duplicate identifier '1.0'. +!!! error TS2300: Duplicate identifier '1'. } interface I { @@ -42,6 +46,8 @@ tests/cases/conformance/types/objectTypeLiteral/propertySignatures/numericString var b = { "0": '', + ~~~ +!!! error TS2300: Duplicate identifier '0'. 0: '' ~ !!! error TS2300: Duplicate identifier '0'. diff --git a/tests/baselines/reference/objectLiteralErrors.errors.txt b/tests/baselines/reference/objectLiteralErrors.errors.txt index 2a2dc7dd5753c..e352a9f42e718 100644 --- a/tests/baselines/reference/objectLiteralErrors.errors.txt +++ b/tests/baselines/reference/objectLiteralErrors.errors.txt @@ -1,21 +1,39 @@ +tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts(2,12): error TS2300: Duplicate identifier 'a'. tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts(2,18): error TS2300: Duplicate identifier 'a'. +tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts(3,12): error TS2300: Duplicate identifier 'a'. tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts(3,19): error TS2300: Duplicate identifier 'a'. +tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts(4,12): error TS2300: Duplicate identifier 'a'. tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts(4,18): error TS2300: Duplicate identifier 'a'. +tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts(5,12): error TS2300: Duplicate identifier 'a'. tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts(5,21): error TS2300: Duplicate identifier 'a'. +tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts(6,12): error TS2300: Duplicate identifier 'a'. tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts(6,19): error TS2300: Duplicate identifier 'a'. -tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts(7,18): error TS2300: Duplicate identifier ''a''. +tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts(7,12): error TS2300: Duplicate identifier 'a'. +tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts(7,18): error TS2300: Duplicate identifier 'a'. +tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts(8,12): error TS2300: Duplicate identifier 'a'. tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts(8,20): error TS2300: Duplicate identifier 'a'. -tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts(9,20): error TS2300: Duplicate identifier '"a"'. -tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts(10,20): error TS2300: Duplicate identifier ''a''. -tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts(11,21): error TS2300: Duplicate identifier ''a''. -tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts(12,21): error TS2300: Duplicate identifier ''1''. +tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts(9,12): error TS2300: Duplicate identifier 'a'. +tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts(9,20): error TS2300: Duplicate identifier 'a'. +tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts(10,12): error TS2300: Duplicate identifier 'a'. +tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts(10,20): error TS2300: Duplicate identifier 'a'. +tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts(11,13): error TS2300: Duplicate identifier 'a'. +tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts(11,21): error TS2300: Duplicate identifier 'a'. +tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts(12,13): error TS2300: Duplicate identifier '1'. +tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts(12,21): error TS2300: Duplicate identifier '1'. +tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts(13,13): error TS2300: Duplicate identifier '0'. tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts(13,19): error TS2300: Duplicate identifier '0'. +tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts(14,13): error TS2300: Duplicate identifier '0'. tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts(14,19): error TS2300: Duplicate identifier '0'. -tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts(15,19): error TS2300: Duplicate identifier '0x0'. +tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts(15,13): error TS2300: Duplicate identifier '0'. +tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts(15,19): error TS2300: Duplicate identifier '0'. +tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts(16,13): error TS2300: Duplicate identifier '0'. tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts(16,19): error TS1085: Octal literals are not available when targeting ECMAScript 5 and higher. Use the syntax '0o0'. -tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts(16,19): error TS2300: Duplicate identifier '000'. -tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts(17,23): error TS2300: Duplicate identifier '1e2'. -tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts(18,22): error TS2300: Duplicate identifier '3.2e1'. +tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts(16,19): error TS2300: Duplicate identifier '0'. +tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts(17,13): error TS2300: Duplicate identifier '100'. +tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts(17,23): error TS2300: Duplicate identifier '100'. +tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts(18,13): error TS2300: Duplicate identifier '32'. +tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts(18,22): error TS2300: Duplicate identifier '32'. +tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts(19,13): error TS2300: Duplicate identifier 'a'. tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts(19,25): error TS2300: Duplicate identifier 'a'. tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts(22,12): error TS2300: Duplicate identifier 'a'. tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts(22,22): error TS1119: An object literal cannot have property and accessor with the same name. @@ -35,21 +53,26 @@ tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts(26,23) tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts(27,12): error TS2300: Duplicate identifier 'a'. tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts(27,22): error TS1119: An object literal cannot have property and accessor with the same name. tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts(27,22): error TS2300: Duplicate identifier ''a''. +tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts(27,22): error TS2300: Duplicate identifier 'a'. tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts(28,12): error TS2300: Duplicate identifier ''a''. tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts(28,24): error TS1119: An object literal cannot have property and accessor with the same name. tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts(28,24): error TS2300: Duplicate identifier 'a'. tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts(29,12): error TS2300: Duplicate identifier ''a''. tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts(29,24): error TS1119: An object literal cannot have property and accessor with the same name. tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts(29,24): error TS2300: Duplicate identifier '"a"'. +tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts(29,24): error TS2300: Duplicate identifier 'a'. tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts(30,12): error TS2300: Duplicate identifier ''a''. tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts(30,24): error TS1119: An object literal cannot have property and accessor with the same name. tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts(30,24): error TS2300: Duplicate identifier ''a''. +tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts(30,24): error TS2300: Duplicate identifier 'a'. tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts(31,13): error TS2300: Duplicate identifier '"a"'. tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts(31,25): error TS1119: An object literal cannot have property and accessor with the same name. tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts(31,25): error TS2300: Duplicate identifier ''a''. +tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts(31,25): error TS2300: Duplicate identifier 'a'. tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts(32,13): error TS2300: Duplicate identifier '1.0'. tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts(32,25): error TS1119: An object literal cannot have property and accessor with the same name. tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts(32,25): error TS2300: Duplicate identifier ''1''. +tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts(32,25): error TS2300: Duplicate identifier '1'. tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts(33,13): error TS2300: Duplicate identifier '0'. tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts(33,23): error TS1119: An object literal cannot have property and accessor with the same name. tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts(33,23): error TS2300: Duplicate identifier '0'. @@ -58,16 +81,20 @@ tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts(34,23) tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts(34,23): error TS2300: Duplicate identifier '0'. tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts(35,13): error TS2300: Duplicate identifier '0'. tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts(35,23): error TS1119: An object literal cannot have property and accessor with the same name. +tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts(35,23): error TS2300: Duplicate identifier '0'. tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts(35,23): error TS2300: Duplicate identifier '0x0'. tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts(36,13): error TS2300: Duplicate identifier '0'. tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts(36,23): error TS1119: An object literal cannot have property and accessor with the same name. +tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts(36,23): error TS2300: Duplicate identifier '0'. tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts(36,23): error TS2300: Duplicate identifier '000'. tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts(37,13): error TS2300: Duplicate identifier '"100"'. tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts(37,27): error TS1119: An object literal cannot have property and accessor with the same name. +tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts(37,27): error TS2300: Duplicate identifier '100'. tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts(37,27): error TS2300: Duplicate identifier '1e2'. tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts(38,13): error TS2300: Duplicate identifier '0x20'. tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts(38,26): error TS1119: An object literal cannot have property and accessor with the same name. tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts(38,26): error TS2300: Duplicate identifier '3.2e1'. +tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts(38,26): error TS2300: Duplicate identifier '32'. tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts(39,13): error TS2300: Duplicate identifier 'a'. tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts(39,46): error TS1119: An object literal cannot have property and accessor with the same name. tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts(39,46): error TS2300: Duplicate identifier 'a'. @@ -78,62 +105,98 @@ tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts(44,16) tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts(44,55): error TS2380: 'get' and 'set' accessor must have the same type. -==== tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts (78 errors) ==== +==== tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts (105 errors) ==== // Multiple properties with the same name var e1 = { a: 0, a: 0 }; + ~ +!!! error TS2300: Duplicate identifier 'a'. ~ !!! error TS2300: Duplicate identifier 'a'. var e2 = { a: '', a: '' }; + ~ +!!! error TS2300: Duplicate identifier 'a'. ~ !!! error TS2300: Duplicate identifier 'a'. var e3 = { a: 0, a: '' }; + ~ +!!! error TS2300: Duplicate identifier 'a'. ~ !!! error TS2300: Duplicate identifier 'a'. var e4 = { a: true, a: false }; + ~ +!!! error TS2300: Duplicate identifier 'a'. ~ !!! error TS2300: Duplicate identifier 'a'. var e5 = { a: {}, a: {} }; + ~ +!!! error TS2300: Duplicate identifier 'a'. ~ !!! error TS2300: Duplicate identifier 'a'. var e6 = { a: 0, 'a': 0 }; + ~ +!!! error TS2300: Duplicate identifier 'a'. ~~~ -!!! error TS2300: Duplicate identifier ''a''. +!!! error TS2300: Duplicate identifier 'a'. var e7 = { 'a': 0, a: 0 }; + ~~~ +!!! error TS2300: Duplicate identifier 'a'. ~ !!! error TS2300: Duplicate identifier 'a'. var e8 = { 'a': 0, "a": 0 }; + ~~~ +!!! error TS2300: Duplicate identifier 'a'. ~~~ -!!! error TS2300: Duplicate identifier '"a"'. +!!! error TS2300: Duplicate identifier 'a'. var e9 = { 'a': 0, 'a': 0 }; + ~~~ +!!! error TS2300: Duplicate identifier 'a'. ~~~ -!!! error TS2300: Duplicate identifier ''a''. +!!! error TS2300: Duplicate identifier 'a'. var e10 = { "a": 0, 'a': 0 }; + ~~~ +!!! error TS2300: Duplicate identifier 'a'. ~~~ -!!! error TS2300: Duplicate identifier ''a''. +!!! error TS2300: Duplicate identifier 'a'. var e11 = { 1.0: 0, '1': 0 }; + ~~~ +!!! error TS2300: Duplicate identifier '1'. ~~~ -!!! error TS2300: Duplicate identifier ''1''. +!!! error TS2300: Duplicate identifier '1'. var e12 = { 0: 0, 0: 0 }; + ~ +!!! error TS2300: Duplicate identifier '0'. ~ !!! error TS2300: Duplicate identifier '0'. var e13 = { 0: 0, 0: 0 }; + ~ +!!! error TS2300: Duplicate identifier '0'. ~ !!! error TS2300: Duplicate identifier '0'. var e14 = { 0: 0, 0x0: 0 }; + ~ +!!! error TS2300: Duplicate identifier '0'. ~~~ -!!! error TS2300: Duplicate identifier '0x0'. +!!! error TS2300: Duplicate identifier '0'. var e14 = { 0: 0, 000: 0 }; + ~ +!!! error TS2300: Duplicate identifier '0'. ~~~ !!! error TS1085: Octal literals are not available when targeting ECMAScript 5 and higher. Use the syntax '0o0'. ~~~ -!!! error TS2300: Duplicate identifier '000'. +!!! error TS2300: Duplicate identifier '0'. var e15 = { "100": 0, 1e2: 0 }; + ~~~~~ +!!! error TS2300: Duplicate identifier '100'. ~~~ -!!! error TS2300: Duplicate identifier '1e2'. +!!! error TS2300: Duplicate identifier '100'. var e16 = { 0x20: 0, 3.2e1: 0 }; + ~~~~ +!!! error TS2300: Duplicate identifier '32'. ~~~~~ -!!! error TS2300: Duplicate identifier '3.2e1'. +!!! error TS2300: Duplicate identifier '32'. var e17 = { a: 0, b: 1, a: 0 }; + ~ +!!! error TS2300: Duplicate identifier 'a'. ~ !!! error TS2300: Duplicate identifier 'a'. @@ -180,6 +243,8 @@ tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts(44,55) !!! error TS1119: An object literal cannot have property and accessor with the same name. ~~~ !!! error TS2300: Duplicate identifier ''a''. + ~~~ +!!! error TS2300: Duplicate identifier 'a'. var f7 = { 'a': 0, get a() { return 0; } }; ~~~ !!! error TS2300: Duplicate identifier ''a''. @@ -194,6 +259,8 @@ tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts(44,55) !!! error TS1119: An object literal cannot have property and accessor with the same name. ~~~ !!! error TS2300: Duplicate identifier '"a"'. + ~~~ +!!! error TS2300: Duplicate identifier 'a'. var f9 = { 'a': 0, get 'a'() { return 0; } }; ~~~ !!! error TS2300: Duplicate identifier ''a''. @@ -201,6 +268,8 @@ tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts(44,55) !!! error TS1119: An object literal cannot have property and accessor with the same name. ~~~ !!! error TS2300: Duplicate identifier ''a''. + ~~~ +!!! error TS2300: Duplicate identifier 'a'. var f10 = { "a": 0, get 'a'() { return 0; } }; ~~~ !!! error TS2300: Duplicate identifier '"a"'. @@ -208,6 +277,8 @@ tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts(44,55) !!! error TS1119: An object literal cannot have property and accessor with the same name. ~~~ !!! error TS2300: Duplicate identifier ''a''. + ~~~ +!!! error TS2300: Duplicate identifier 'a'. var f11 = { 1.0: 0, get '1'() { return 0; } }; ~~~ !!! error TS2300: Duplicate identifier '1.0'. @@ -215,6 +286,8 @@ tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts(44,55) !!! error TS1119: An object literal cannot have property and accessor with the same name. ~~~ !!! error TS2300: Duplicate identifier ''1''. + ~~~ +!!! error TS2300: Duplicate identifier '1'. var f12 = { 0: 0, get 0() { return 0; } }; ~ !!! error TS2300: Duplicate identifier '0'. @@ -235,6 +308,8 @@ tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts(44,55) ~~~ !!! error TS1119: An object literal cannot have property and accessor with the same name. ~~~ +!!! error TS2300: Duplicate identifier '0'. + ~~~ !!! error TS2300: Duplicate identifier '0x0'. var f14 = { 0: 0, get 000() { return 0; } }; ~ @@ -242,6 +317,8 @@ tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts(44,55) ~~~ !!! error TS1119: An object literal cannot have property and accessor with the same name. ~~~ +!!! error TS2300: Duplicate identifier '0'. + ~~~ !!! error TS2300: Duplicate identifier '000'. var f15 = { "100": 0, get 1e2() { return 0; } }; ~~~~~ @@ -249,6 +326,8 @@ tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts(44,55) ~~~ !!! error TS1119: An object literal cannot have property and accessor with the same name. ~~~ +!!! error TS2300: Duplicate identifier '100'. + ~~~ !!! error TS2300: Duplicate identifier '1e2'. var f16 = { 0x20: 0, get 3.2e1() { return 0; } }; ~~~~ @@ -257,6 +336,8 @@ tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts(44,55) !!! error TS1119: An object literal cannot have property and accessor with the same name. ~~~~~ !!! error TS2300: Duplicate identifier '3.2e1'. + ~~~~~ +!!! error TS2300: Duplicate identifier '32'. var f17 = { a: 0, get b() { return 1; }, get a() { return 0; } }; ~ !!! error TS2300: Duplicate identifier 'a'. diff --git a/tests/baselines/reference/objectSpreadNegative.errors.txt b/tests/baselines/reference/objectSpreadNegative.errors.txt index 914df6d78d883..0b44101334424 100644 --- a/tests/baselines/reference/objectSpreadNegative.errors.txt +++ b/tests/baselines/reference/objectSpreadNegative.errors.txt @@ -3,6 +3,7 @@ tests/cases/conformance/types/spread/objectSpreadNegative.ts(16,5): error TS2322 Property 'sn' is optional in type '{ sn?: string | number; }' but required in type '{ sn: string | number; }'. tests/cases/conformance/types/spread/objectSpreadNegative.ts(23,1): error TS2741: Property 'b' is missing in type '{ s: string; }' but required in type '{ s: string; b: boolean; }'. tests/cases/conformance/types/spread/objectSpreadNegative.ts(25,1): error TS2741: Property 's' is missing in type '{ b: boolean; }' but required in type '{ s: string; b: boolean; }'. +tests/cases/conformance/types/spread/objectSpreadNegative.ts(28,20): error TS2300: Duplicate identifier 'b'. tests/cases/conformance/types/spread/objectSpreadNegative.ts(28,36): error TS2300: Duplicate identifier 'b'. tests/cases/conformance/types/spread/objectSpreadNegative.ts(28,53): error TS2300: Duplicate identifier 'b'. tests/cases/conformance/types/spread/objectSpreadNegative.ts(32,19): error TS2698: Spread types may only be created from object types. @@ -17,7 +18,7 @@ tests/cases/conformance/types/spread/objectSpreadNegative.ts(53,9): error TS2339 tests/cases/conformance/types/spread/objectSpreadNegative.ts(58,11): error TS2339: Property 'a' does not exist on type '{}'. -==== tests/cases/conformance/types/spread/objectSpreadNegative.ts (15 errors) ==== +==== tests/cases/conformance/types/spread/objectSpreadNegative.ts (16 errors) ==== let o = { a: 1, b: 'no' } /// private propagates @@ -57,6 +58,8 @@ tests/cases/conformance/types/spread/objectSpreadNegative.ts(58,11): error TS233 // literal repeats are not allowed, but spread repeats are fine let duplicated = { b: 'bad', ...o, b: 'bad', ...o2, b: 'bad' } + ~ +!!! error TS2300: Duplicate identifier 'b'. ~ !!! error TS2300: Duplicate identifier 'b'. ~ diff --git a/tests/baselines/reference/objectTypeWithDuplicateNumericProperty.errors.txt b/tests/baselines/reference/objectTypeWithDuplicateNumericProperty.errors.txt index 80931650d0a87..9db06b25e74f3 100644 --- a/tests/baselines/reference/objectTypeWithDuplicateNumericProperty.errors.txt +++ b/tests/baselines/reference/objectTypeWithDuplicateNumericProperty.errors.txt @@ -1,6 +1,7 @@ -tests/cases/conformance/types/members/objectTypeWithDuplicateNumericProperty.ts(6,5): error TS2300: Duplicate identifier '1.0'. -tests/cases/conformance/types/members/objectTypeWithDuplicateNumericProperty.ts(7,5): error TS2300: Duplicate identifier '1.'. -tests/cases/conformance/types/members/objectTypeWithDuplicateNumericProperty.ts(8,5): error TS2300: Duplicate identifier '1.00'. +tests/cases/conformance/types/members/objectTypeWithDuplicateNumericProperty.ts(5,5): error TS2300: Duplicate identifier '1'. +tests/cases/conformance/types/members/objectTypeWithDuplicateNumericProperty.ts(6,5): error TS2300: Duplicate identifier '1'. +tests/cases/conformance/types/members/objectTypeWithDuplicateNumericProperty.ts(7,5): error TS2300: Duplicate identifier '1'. +tests/cases/conformance/types/members/objectTypeWithDuplicateNumericProperty.ts(8,5): error TS2300: Duplicate identifier '1'. tests/cases/conformance/types/members/objectTypeWithDuplicateNumericProperty.ts(12,5): error TS2300: Duplicate identifier '1'. tests/cases/conformance/types/members/objectTypeWithDuplicateNumericProperty.ts(13,5): error TS2300: Duplicate identifier '1'. tests/cases/conformance/types/members/objectTypeWithDuplicateNumericProperty.ts(14,5): error TS2300: Duplicate identifier '1'. @@ -9,26 +10,29 @@ tests/cases/conformance/types/members/objectTypeWithDuplicateNumericProperty.ts( tests/cases/conformance/types/members/objectTypeWithDuplicateNumericProperty.ts(20,5): error TS2300: Duplicate identifier '1'. tests/cases/conformance/types/members/objectTypeWithDuplicateNumericProperty.ts(21,5): error TS2300: Duplicate identifier '1'. tests/cases/conformance/types/members/objectTypeWithDuplicateNumericProperty.ts(22,5): error TS2300: Duplicate identifier '1'. -tests/cases/conformance/types/members/objectTypeWithDuplicateNumericProperty.ts(27,5): error TS2300: Duplicate identifier '1.0'. -tests/cases/conformance/types/members/objectTypeWithDuplicateNumericProperty.ts(28,5): error TS2300: Duplicate identifier '1.'. -tests/cases/conformance/types/members/objectTypeWithDuplicateNumericProperty.ts(29,5): error TS2300: Duplicate identifier '1.00'. +tests/cases/conformance/types/members/objectTypeWithDuplicateNumericProperty.ts(26,5): error TS2300: Duplicate identifier '1'. +tests/cases/conformance/types/members/objectTypeWithDuplicateNumericProperty.ts(27,5): error TS2300: Duplicate identifier '1'. +tests/cases/conformance/types/members/objectTypeWithDuplicateNumericProperty.ts(28,5): error TS2300: Duplicate identifier '1'. +tests/cases/conformance/types/members/objectTypeWithDuplicateNumericProperty.ts(29,5): error TS2300: Duplicate identifier '1'. -==== tests/cases/conformance/types/members/objectTypeWithDuplicateNumericProperty.ts (14 errors) ==== +==== tests/cases/conformance/types/members/objectTypeWithDuplicateNumericProperty.ts (16 errors) ==== // numeric properties must be distinct after a ToNumber operation // so the below are all errors class C { 1; + ~ +!!! error TS2300: Duplicate identifier '1'. 1.0; ~~~ -!!! error TS2300: Duplicate identifier '1.0'. +!!! error TS2300: Duplicate identifier '1'. 1.; ~~ -!!! error TS2300: Duplicate identifier '1.'. +!!! error TS2300: Duplicate identifier '1'. 1.00; ~~~~ -!!! error TS2300: Duplicate identifier '1.00'. +!!! error TS2300: Duplicate identifier '1'. } interface I { @@ -63,15 +67,17 @@ tests/cases/conformance/types/members/objectTypeWithDuplicateNumericProperty.ts( var b = { 1: 1, + ~ +!!! error TS2300: Duplicate identifier '1'. 1.0: 1, ~~~ -!!! error TS2300: Duplicate identifier '1.0'. +!!! error TS2300: Duplicate identifier '1'. 1.: 1, ~~ -!!! error TS2300: Duplicate identifier '1.'. +!!! error TS2300: Duplicate identifier '1'. 1.00: 1 ~~~~ -!!! error TS2300: Duplicate identifier '1.00'. +!!! error TS2300: Duplicate identifier '1'. } \ No newline at end of file diff --git a/tests/baselines/reference/parameterPropertyInConstructor2.errors.txt b/tests/baselines/reference/parameterPropertyInConstructor2.errors.txt index 6f64fdc86697f..69faad5446fda 100644 --- a/tests/baselines/reference/parameterPropertyInConstructor2.errors.txt +++ b/tests/baselines/reference/parameterPropertyInConstructor2.errors.txt @@ -1,9 +1,10 @@ tests/cases/compiler/parameterPropertyInConstructor2.ts(3,5): error TS2394: This overload signature is not compatible with its implementation signature. tests/cases/compiler/parameterPropertyInConstructor2.ts(3,17): error TS2369: A parameter property is only allowed in a constructor implementation. +tests/cases/compiler/parameterPropertyInConstructor2.ts(3,24): error TS2300: Duplicate identifier 'names'. tests/cases/compiler/parameterPropertyInConstructor2.ts(4,24): error TS2300: Duplicate identifier 'names'. -==== tests/cases/compiler/parameterPropertyInConstructor2.ts (3 errors) ==== +==== tests/cases/compiler/parameterPropertyInConstructor2.ts (4 errors) ==== module mod { class Customers { constructor(public names: string); @@ -12,6 +13,8 @@ tests/cases/compiler/parameterPropertyInConstructor2.ts(4,24): error TS2300: Dup !!! related TS2750 tests/cases/compiler/parameterPropertyInConstructor2.ts:4:5: The implementation signature is declared here. ~~~~~~~~~~~~~~~~~~~~ !!! error TS2369: A parameter property is only allowed in a constructor implementation. + ~~~~~ +!!! error TS2300: Duplicate identifier 'names'. constructor(public names: string, public ages: number) { ~~~~~ !!! error TS2300: Duplicate identifier 'names'. diff --git a/tests/baselines/reference/parser0_004152.errors.txt b/tests/baselines/reference/parser0_004152.errors.txt index 93ac55f4c409f..dfff2ea1a0968 100644 --- a/tests/baselines/reference/parser0_004152.errors.txt +++ b/tests/baselines/reference/parser0_004152.errors.txt @@ -1,6 +1,7 @@ tests/cases/conformance/parser/ecmascript5/Fuzz/parser0_004152.ts(2,28): error TS2304: Cannot find name 'DisplayPosition'. tests/cases/conformance/parser/ecmascript5/Fuzz/parser0_004152.ts(2,45): error TS1137: Expression or comma expected. tests/cases/conformance/parser/ecmascript5/Fuzz/parser0_004152.ts(2,46): error TS1005: ';' expected. +tests/cases/conformance/parser/ecmascript5/Fuzz/parser0_004152.ts(2,48): error TS2300: Duplicate identifier '3'. tests/cases/conformance/parser/ecmascript5/Fuzz/parser0_004152.ts(2,49): error TS1005: ';' expected. tests/cases/conformance/parser/ecmascript5/Fuzz/parser0_004152.ts(2,51): error TS2300: Duplicate identifier '3'. tests/cases/conformance/parser/ecmascript5/Fuzz/parser0_004152.ts(2,52): error TS1005: ';' expected. @@ -10,6 +11,7 @@ tests/cases/conformance/parser/ecmascript5/Fuzz/parser0_004152.ts(2,57): error T tests/cases/conformance/parser/ecmascript5/Fuzz/parser0_004152.ts(2,58): error TS1005: ';' expected. tests/cases/conformance/parser/ecmascript5/Fuzz/parser0_004152.ts(2,60): error TS2300: Duplicate identifier '3'. tests/cases/conformance/parser/ecmascript5/Fuzz/parser0_004152.ts(2,61): error TS1005: ';' expected. +tests/cases/conformance/parser/ecmascript5/Fuzz/parser0_004152.ts(2,63): error TS2300: Duplicate identifier '0'. tests/cases/conformance/parser/ecmascript5/Fuzz/parser0_004152.ts(2,64): error TS1005: ';' expected. tests/cases/conformance/parser/ecmascript5/Fuzz/parser0_004152.ts(2,66): error TS2300: Duplicate identifier '3'. tests/cases/conformance/parser/ecmascript5/Fuzz/parser0_004152.ts(2,67): error TS1005: ';' expected. @@ -32,7 +34,7 @@ tests/cases/conformance/parser/ecmascript5/Fuzz/parser0_004152.ts(2,97): error T tests/cases/conformance/parser/ecmascript5/Fuzz/parser0_004152.ts(3,25): error TS2304: Cannot find name 'SeedCoords'. -==== tests/cases/conformance/parser/ecmascript5/Fuzz/parser0_004152.ts (32 errors) ==== +==== tests/cases/conformance/parser/ecmascript5/Fuzz/parser0_004152.ts (34 errors) ==== export class Game { private position = new DisplayPosition([), 3, 3, 3, 3, 3, 0, 3, 3, 3, 3, 3, 3, 0], NoMove, 0); ~~~~~~~~~~~~~~~ @@ -41,6 +43,8 @@ tests/cases/conformance/parser/ecmascript5/Fuzz/parser0_004152.ts(3,25): error T !!! error TS1137: Expression or comma expected. ~ !!! error TS1005: ';' expected. + ~ +!!! error TS2300: Duplicate identifier '3'. ~ !!! error TS1005: ';' expected. ~ @@ -59,6 +63,8 @@ tests/cases/conformance/parser/ecmascript5/Fuzz/parser0_004152.ts(3,25): error T !!! error TS2300: Duplicate identifier '3'. ~ !!! error TS1005: ';' expected. + ~ +!!! error TS2300: Duplicate identifier '0'. ~ !!! error TS1005: ';' expected. ~ diff --git a/tests/baselines/reference/reassignStaticProp.errors.txt b/tests/baselines/reference/reassignStaticProp.errors.txt index bd62f1aa80dfb..48ef4a1cc3ca9 100644 --- a/tests/baselines/reference/reassignStaticProp.errors.txt +++ b/tests/baselines/reference/reassignStaticProp.errors.txt @@ -1,11 +1,14 @@ +tests/cases/compiler/reassignStaticProp.ts(3,12): error TS2300: Duplicate identifier 'bar'. tests/cases/compiler/reassignStaticProp.ts(5,12): error TS2300: Duplicate identifier 'bar'. tests/cases/compiler/reassignStaticProp.ts(5,12): error TS2717: Subsequent property declarations must have the same type. Property 'bar' must be of type 'number', but here has type 'string'. -==== tests/cases/compiler/reassignStaticProp.ts (2 errors) ==== +==== tests/cases/compiler/reassignStaticProp.ts (3 errors) ==== class foo { static bar = 1; + ~~~ +!!! error TS2300: Duplicate identifier 'bar'. static bar:string; // errror - duplicate id ~~~ diff --git a/tests/baselines/reference/stringLiteralTypesInImplementationSignatures2.errors.txt b/tests/baselines/reference/stringLiteralTypesInImplementationSignatures2.errors.txt index d7f6c1825035c..b0ab5010ea5e8 100644 --- a/tests/baselines/reference/stringLiteralTypesInImplementationSignatures2.errors.txt +++ b/tests/baselines/reference/stringLiteralTypesInImplementationSignatures2.errors.txt @@ -1,7 +1,8 @@ +tests/cases/conformance/types/objectTypeLiteral/callSignatures/stringLiteralTypesInImplementationSignatures2.ts(26,5): error TS2300: Duplicate identifier 'foo'. tests/cases/conformance/types/objectTypeLiteral/callSignatures/stringLiteralTypesInImplementationSignatures2.ts(27,5): error TS2300: Duplicate identifier 'foo'. -==== tests/cases/conformance/types/objectTypeLiteral/callSignatures/stringLiteralTypesInImplementationSignatures2.ts (1 errors) ==== +==== tests/cases/conformance/types/objectTypeLiteral/callSignatures/stringLiteralTypesInImplementationSignatures2.ts (2 errors) ==== // String literal types are only valid in overload signatures function foo(x: any); @@ -28,6 +29,8 @@ tests/cases/conformance/types/objectTypeLiteral/callSignatures/stringLiteralType var b = { foo(x: 'hi') { }, + ~~~ +!!! error TS2300: Duplicate identifier 'foo'. foo(x: 'a') { }, ~~~ !!! error TS2300: Duplicate identifier 'foo'. diff --git a/tests/baselines/reference/stringLiteralTypesInImplementationSignatures2.symbols b/tests/baselines/reference/stringLiteralTypesInImplementationSignatures2.symbols index 1d0b323224fab..bf2f178d795d7 100644 --- a/tests/baselines/reference/stringLiteralTypesInImplementationSignatures2.symbols +++ b/tests/baselines/reference/stringLiteralTypesInImplementationSignatures2.symbols @@ -63,11 +63,11 @@ var b = { >b : Symbol(b, Decl(stringLiteralTypesInImplementationSignatures2.ts, 24, 3)) foo(x: 'hi') { }, ->foo : Symbol(foo, Decl(stringLiteralTypesInImplementationSignatures2.ts, 24, 9), Decl(stringLiteralTypesInImplementationSignatures2.ts, 25, 21)) +>foo : Symbol(foo, Decl(stringLiteralTypesInImplementationSignatures2.ts, 24, 9)) >x : Symbol(x, Decl(stringLiteralTypesInImplementationSignatures2.ts, 25, 8)) foo(x: 'a') { }, ->foo : Symbol(foo, Decl(stringLiteralTypesInImplementationSignatures2.ts, 24, 9), Decl(stringLiteralTypesInImplementationSignatures2.ts, 25, 21)) +>foo : Symbol(foo, Decl(stringLiteralTypesInImplementationSignatures2.ts, 25, 21)) >x : Symbol(x, Decl(stringLiteralTypesInImplementationSignatures2.ts, 26, 8)) } diff --git a/tests/baselines/reference/stringLiteralTypesInImplementationSignatures2.types b/tests/baselines/reference/stringLiteralTypesInImplementationSignatures2.types index ed461631d0947..a70fa43c82fbf 100644 --- a/tests/baselines/reference/stringLiteralTypesInImplementationSignatures2.types +++ b/tests/baselines/reference/stringLiteralTypesInImplementationSignatures2.types @@ -58,15 +58,15 @@ var a: { } var b = { ->b : { foo(x: "hi"): void; foo(x: "a"): void; } ->{ foo(x: 'hi') { }, foo(x: 'a') { },} : { foo(x: "hi"): void; foo(x: "a"): void; } +>b : { foo(x: "a"): void; } +>{ foo(x: 'hi') { }, foo(x: 'a') { },} : { foo(x: "a"): void; } foo(x: 'hi') { }, ->foo : { (x: "hi"): void; (x: "a"): void; } +>foo : (x: "hi") => void >x : "hi" foo(x: 'a') { }, ->foo : { (x: "hi"): void; (x: "a"): void; } +>foo : (x: "a") => void >x : "a" } diff --git a/tests/baselines/reference/stringNamedPropertyDuplicates.errors.txt b/tests/baselines/reference/stringNamedPropertyDuplicates.errors.txt index 5bd8a2771ba6c..72af75e2aa2dd 100644 --- a/tests/baselines/reference/stringNamedPropertyDuplicates.errors.txt +++ b/tests/baselines/reference/stringNamedPropertyDuplicates.errors.txt @@ -1,5 +1,7 @@ -tests/cases/conformance/types/objectTypeLiteral/propertySignatures/stringNamedPropertyDuplicates.ts(3,5): error TS2300: Duplicate identifier '"a b"'. -tests/cases/conformance/types/objectTypeLiteral/propertySignatures/stringNamedPropertyDuplicates.ts(5,12): error TS2300: Duplicate identifier '"c d"'. +tests/cases/conformance/types/objectTypeLiteral/propertySignatures/stringNamedPropertyDuplicates.ts(2,5): error TS2300: Duplicate identifier 'a b'. +tests/cases/conformance/types/objectTypeLiteral/propertySignatures/stringNamedPropertyDuplicates.ts(3,5): error TS2300: Duplicate identifier 'a b'. +tests/cases/conformance/types/objectTypeLiteral/propertySignatures/stringNamedPropertyDuplicates.ts(4,12): error TS2300: Duplicate identifier 'c d'. +tests/cases/conformance/types/objectTypeLiteral/propertySignatures/stringNamedPropertyDuplicates.ts(5,12): error TS2300: Duplicate identifier 'c d'. tests/cases/conformance/types/objectTypeLiteral/propertySignatures/stringNamedPropertyDuplicates.ts(9,5): error TS2300: Duplicate identifier 'a b'. tests/cases/conformance/types/objectTypeLiteral/propertySignatures/stringNamedPropertyDuplicates.ts(10,5): error TS2300: Duplicate identifier 'a b'. tests/cases/conformance/types/objectTypeLiteral/propertySignatures/stringNamedPropertyDuplicates.ts(14,5): error TS2300: Duplicate identifier 'a b'. @@ -7,16 +9,20 @@ tests/cases/conformance/types/objectTypeLiteral/propertySignatures/stringNamedPr tests/cases/conformance/types/objectTypeLiteral/propertySignatures/stringNamedPropertyDuplicates.ts(20,5): error TS1005: ',' expected. -==== tests/cases/conformance/types/objectTypeLiteral/propertySignatures/stringNamedPropertyDuplicates.ts (7 errors) ==== +==== tests/cases/conformance/types/objectTypeLiteral/propertySignatures/stringNamedPropertyDuplicates.ts (9 errors) ==== class C { "a b": number; + ~~~~~ +!!! error TS2300: Duplicate identifier 'a b'. "a b": number; ~~~~~ -!!! error TS2300: Duplicate identifier '"a b"'. +!!! error TS2300: Duplicate identifier 'a b'. static "c d": number; + ~~~~~ +!!! error TS2300: Duplicate identifier 'c d'. static "c d": number; ~~~~~ -!!! error TS2300: Duplicate identifier '"c d"'. +!!! error TS2300: Duplicate identifier 'c d'. } interface I { diff --git a/tests/baselines/reference/symbolProperty36.errors.txt b/tests/baselines/reference/symbolProperty36.errors.txt index 69102da1db387..6fe3299ab905e 100644 --- a/tests/baselines/reference/symbolProperty36.errors.txt +++ b/tests/baselines/reference/symbolProperty36.errors.txt @@ -1,9 +1,12 @@ +tests/cases/conformance/es6/Symbols/symbolProperty36.ts(2,5): error TS2300: Duplicate identifier '[Symbol.isConcatSpreadable]'. tests/cases/conformance/es6/Symbols/symbolProperty36.ts(3,5): error TS2300: Duplicate identifier '[Symbol.isConcatSpreadable]'. -==== tests/cases/conformance/es6/Symbols/symbolProperty36.ts (1 errors) ==== +==== tests/cases/conformance/es6/Symbols/symbolProperty36.ts (2 errors) ==== var x = { [Symbol.isConcatSpreadable]: 0, + ~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2300: Duplicate identifier '[Symbol.isConcatSpreadable]'. [Symbol.isConcatSpreadable]: 1 ~~~~~~~~~~~~~~~~~~~~~~~~~~~ !!! error TS2300: Duplicate identifier '[Symbol.isConcatSpreadable]'. diff --git a/tests/baselines/reference/symbolProperty37.errors.txt b/tests/baselines/reference/symbolProperty37.errors.txt new file mode 100644 index 0000000000000..96e10e7f2a4e2 --- /dev/null +++ b/tests/baselines/reference/symbolProperty37.errors.txt @@ -0,0 +1,13 @@ +tests/cases/conformance/es6/Symbols/symbolProperty37.ts(2,5): error TS2300: Duplicate identifier '[Symbol.isConcatSpreadable]'. +tests/cases/conformance/es6/Symbols/symbolProperty37.ts(3,5): error TS2300: Duplicate identifier '[Symbol.isConcatSpreadable]'. + + +==== tests/cases/conformance/es6/Symbols/symbolProperty37.ts (2 errors) ==== + interface I { + [Symbol.isConcatSpreadable]: string; + ~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2300: Duplicate identifier '[Symbol.isConcatSpreadable]'. + [Symbol.isConcatSpreadable]: string; + ~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2300: Duplicate identifier '[Symbol.isConcatSpreadable]'. + } \ No newline at end of file diff --git a/tests/baselines/reference/symbolProperty44.symbols b/tests/baselines/reference/symbolProperty44.symbols index ff625bd527855..f5f3cce7c9bab 100644 --- a/tests/baselines/reference/symbolProperty44.symbols +++ b/tests/baselines/reference/symbolProperty44.symbols @@ -3,7 +3,7 @@ class C { >C : Symbol(C, Decl(symbolProperty44.ts, 0, 0)) get [Symbol.hasInstance]() { ->[Symbol.hasInstance] : Symbol(C[Symbol.hasInstance], Decl(symbolProperty44.ts, 0, 9)) +>[Symbol.hasInstance] : Symbol(C[Symbol.hasInstance], Decl(symbolProperty44.ts, 0, 9), Decl(symbolProperty44.ts, 3, 5)) >Symbol.hasInstance : Symbol(SymbolConstructor.hasInstance, Decl(lib.es2015.symbol.wellknown.d.ts, --, --)) >Symbol : Symbol(Symbol, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.symbol.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --)) >hasInstance : Symbol(SymbolConstructor.hasInstance, Decl(lib.es2015.symbol.wellknown.d.ts, --, --)) @@ -11,7 +11,7 @@ class C { return ""; } get [Symbol.hasInstance]() { ->[Symbol.hasInstance] : Symbol(C[Symbol.hasInstance], Decl(symbolProperty44.ts, 3, 5)) +>[Symbol.hasInstance] : Symbol(C[Symbol.hasInstance], Decl(symbolProperty44.ts, 0, 9), Decl(symbolProperty44.ts, 3, 5)) >Symbol.hasInstance : Symbol(SymbolConstructor.hasInstance, Decl(lib.es2015.symbol.wellknown.d.ts, --, --)) >Symbol : Symbol(Symbol, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.symbol.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --)) >hasInstance : Symbol(SymbolConstructor.hasInstance, Decl(lib.es2015.symbol.wellknown.d.ts, --, --)) diff --git a/tests/baselines/reference/twoAccessorsWithSameName.symbols b/tests/baselines/reference/twoAccessorsWithSameName.symbols index 4e4b795b89078..96fc2468d4dd0 100644 --- a/tests/baselines/reference/twoAccessorsWithSameName.symbols +++ b/tests/baselines/reference/twoAccessorsWithSameName.symbols @@ -3,21 +3,21 @@ class C { >C : Symbol(C, Decl(twoAccessorsWithSameName.ts, 0, 0)) get x() { return 1; } ->x : Symbol(C.x, Decl(twoAccessorsWithSameName.ts, 0, 9)) +>x : Symbol(C.x, Decl(twoAccessorsWithSameName.ts, 0, 9), Decl(twoAccessorsWithSameName.ts, 1, 25)) get x() { return 1; } // error ->x : Symbol(C.x, Decl(twoAccessorsWithSameName.ts, 1, 25)) +>x : Symbol(C.x, Decl(twoAccessorsWithSameName.ts, 0, 9), Decl(twoAccessorsWithSameName.ts, 1, 25)) } class D { >D : Symbol(D, Decl(twoAccessorsWithSameName.ts, 3, 1)) set x(v) { } ->x : Symbol(D.x, Decl(twoAccessorsWithSameName.ts, 5, 9)) +>x : Symbol(D.x, Decl(twoAccessorsWithSameName.ts, 5, 9), Decl(twoAccessorsWithSameName.ts, 6, 17)) >v : Symbol(v, Decl(twoAccessorsWithSameName.ts, 6, 10)) set x(v) { } // error ->x : Symbol(D.x, Decl(twoAccessorsWithSameName.ts, 6, 17)) +>x : Symbol(D.x, Decl(twoAccessorsWithSameName.ts, 5, 9), Decl(twoAccessorsWithSameName.ts, 6, 17)) >v : Symbol(v, Decl(twoAccessorsWithSameName.ts, 7, 10)) } @@ -38,14 +38,14 @@ var x = { >x : Symbol(x, Decl(twoAccessorsWithSameName.ts, 17, 3)) get x() { ->x : Symbol(x, Decl(twoAccessorsWithSameName.ts, 17, 9)) +>x : Symbol(x, Decl(twoAccessorsWithSameName.ts, 17, 9), Decl(twoAccessorsWithSameName.ts, 20, 6)) return 1; }, // error get x() { ->x : Symbol(x, Decl(twoAccessorsWithSameName.ts, 20, 6)) +>x : Symbol(x, Decl(twoAccessorsWithSameName.ts, 17, 9), Decl(twoAccessorsWithSameName.ts, 20, 6)) return 1; } diff --git a/tests/baselines/reference/twoAccessorsWithSameName2.symbols b/tests/baselines/reference/twoAccessorsWithSameName2.symbols index ebed0f5f930f2..d4d42f489d1c6 100644 --- a/tests/baselines/reference/twoAccessorsWithSameName2.symbols +++ b/tests/baselines/reference/twoAccessorsWithSameName2.symbols @@ -3,21 +3,21 @@ class C { >C : Symbol(C, Decl(twoAccessorsWithSameName2.ts, 0, 0)) static get x() { return 1; } ->x : Symbol(C.x, Decl(twoAccessorsWithSameName2.ts, 0, 9)) +>x : Symbol(C.x, Decl(twoAccessorsWithSameName2.ts, 0, 9), Decl(twoAccessorsWithSameName2.ts, 1, 32)) static get x() { return 1; } // error ->x : Symbol(C.x, Decl(twoAccessorsWithSameName2.ts, 1, 32)) +>x : Symbol(C.x, Decl(twoAccessorsWithSameName2.ts, 0, 9), Decl(twoAccessorsWithSameName2.ts, 1, 32)) } class D { >D : Symbol(D, Decl(twoAccessorsWithSameName2.ts, 3, 1)) static set x(v) { } ->x : Symbol(D.x, Decl(twoAccessorsWithSameName2.ts, 5, 9)) +>x : Symbol(D.x, Decl(twoAccessorsWithSameName2.ts, 5, 9), Decl(twoAccessorsWithSameName2.ts, 6, 24)) >v : Symbol(v, Decl(twoAccessorsWithSameName2.ts, 6, 17)) static set x(v) { } // error ->x : Symbol(D.x, Decl(twoAccessorsWithSameName2.ts, 6, 24)) +>x : Symbol(D.x, Decl(twoAccessorsWithSameName2.ts, 5, 9), Decl(twoAccessorsWithSameName2.ts, 6, 24)) >v : Symbol(v, Decl(twoAccessorsWithSameName2.ts, 7, 17)) } diff --git a/tests/cases/conformance/interfaces/declarationMerging/mergeClassAndInterfaceWithConflictingAccessors.ts b/tests/cases/conformance/interfaces/declarationMerging/mergeClassAndInterfaceWithConflictingAccessors.ts new file mode 100644 index 0000000000000..f8a2bac71ea82 --- /dev/null +++ b/tests/cases/conformance/interfaces/declarationMerging/mergeClassAndInterfaceWithConflictingAccessors.ts @@ -0,0 +1,62 @@ +// @target: esnext +// @noemit: true + +declare class A { + get x(): number; +} +interface A { + get x(): string; +} + +declare class B { + get x(): number; +} +interface B { + set x(value: string); +} + +declare class C { + get x(): number; + set x(value: number); +} +interface C { + x: number; +} + +declare class D { + x: number; +} +interface D { + get x(): number; + set x(value: number); +} + +declare class E { + get x(): number; +} +interface E { + get x(): number; // ok +} + +declare class F { + set x(value: string); +} +interface F { + get x(): string; // ok +} + +declare class G { + get x(): number; + set x(value: number); +} +interface G { + get x(): number; + set x(value: number); +} + +declare class H { + x: number; +} +interface H { + x: number; +} diff --git a/tests/cases/conformance/interfaces/declarationMerging/mergedInterfacesWithConflictingAccessors.ts b/tests/cases/conformance/interfaces/declarationMerging/mergedInterfacesWithConflictingAccessors.ts new file mode 100644 index 0000000000000..ee68375a58fa4 --- /dev/null +++ b/tests/cases/conformance/interfaces/declarationMerging/mergedInterfacesWithConflictingAccessors.ts @@ -0,0 +1,24 @@ +// @target: esnext +// @noemit: true + +interface A { + get x(): number; +} +interface A { + get x(): string; +} + +interface B { + get x(): number; +} +interface B { + set x(value: string); +} + +interface C { + x: number; +} +interface C { + get x(): number; + set x(value: number); +} diff --git a/tests/cases/fourslash/codeFixClassExtendAbstractGetterSetter.ts b/tests/cases/fourslash/codeFixClassExtendAbstractGetterSetter.ts index 0a66f445cc7b1..00c140dfcccb3 100644 --- a/tests/cases/fourslash/codeFixClassExtendAbstractGetterSetter.ts +++ b/tests/cases/fourslash/codeFixClassExtendAbstractGetterSetter.ts @@ -38,12 +38,29 @@ verify.codeFix({ abstract class B extends A {} class C extends A { - a: string | number; - b: this; - c: A; - d: string | number; - e: this; - f: A; - g: string; + get a(): string | number { + throw new Error("Method not implemented."); + } + get b(): this { + throw new Error("Method not implemented."); + } + get c(): A { + throw new Error("Method not implemented."); + } + set d(arg: string | number) { + throw new Error("Method not implemented."); + } + set e(arg: this) { + throw new Error("Method not implemented."); + } + set f(arg: A) { + throw new Error("Method not implemented."); + } + get g(): string { + throw new Error("Method not implemented."); + } + set g(newName: string) { + throw new Error("Method not implemented."); + } }` }); diff --git a/tests/cases/fourslash/codeFixClassImplementClassAbstractGettersAndSetters.ts b/tests/cases/fourslash/codeFixClassImplementClassAbstractGettersAndSetters.ts index 71e0aba73b334..dad3c42964d40 100644 --- a/tests/cases/fourslash/codeFixClassImplementClassAbstractGettersAndSetters.ts +++ b/tests/cases/fourslash/codeFixClassImplementClassAbstractGettersAndSetters.ts @@ -24,8 +24,17 @@ verify.codeFix({ } class C implements A { - a: string; - b: number; - c: string | number; + get a(): string { + throw new Error("Method not implemented."); + } + set a(newName: string) { + throw new Error("Method not implemented."); + } + get b(): number { + throw new Error("Method not implemented."); + } + set c(arg: string | number) { + throw new Error("Method not implemented."); + } }`, }); diff --git a/tests/cases/fourslash/codeFixClassImplementInterfaceAccessors.ts b/tests/cases/fourslash/codeFixClassImplementInterfaceAccessors.ts new file mode 100644 index 0000000000000..904f897b99451 --- /dev/null +++ b/tests/cases/fourslash/codeFixClassImplementInterfaceAccessors.ts @@ -0,0 +1,43 @@ +/// + +// @lib: es2017 + +////enum E { a,b,c } +////interface I { +//// get x(): E; +//// get y(): E.a +//// get z(): symbol; +//// set z(arg: symbol); +//// set w(arg: object); +////} +////class C implements I {} + +verify.codeFix({ + description: "Implement interface 'I'", + newFileContent: +`enum E { a,b,c } +interface I { + get x(): E; + get y(): E.a + get z(): symbol; + set z(arg: symbol); + set w(arg: object); +} +class C implements I { + get x(): E { + throw new Error("Method not implemented."); + } + get y(): E.a { + throw new Error("Method not implemented."); + } + get z(): symbol { + throw new Error("Method not implemented."); + } + set z(arg: symbol) { + throw new Error("Method not implemented."); + } + set w(arg: object) { + throw new Error("Method not implemented."); + } +}`, +}); diff --git a/tests/cases/fourslash/completionListInClosedObjectTypeLiteralInSignature04.ts b/tests/cases/fourslash/completionListInClosedObjectTypeLiteralInSignature04.ts index 94f109d787a7a..3360cc2679986 100644 --- a/tests/cases/fourslash/completionListInClosedObjectTypeLiteralInSignature04.ts +++ b/tests/cases/fourslash/completionListInClosedObjectTypeLiteralInSignature04.ts @@ -9,6 +9,6 @@ verify.completions({ marker: "1", - exact: { name: "readonly", sortText: completion.SortText.GlobalsOrKeywords }, + exact: completion.interfaceElementKeywords, isNewIdentifierLocation: true }); diff --git a/tests/cases/fourslash/completionListInUnclosedObjectTypeLiteralInSignature04.ts b/tests/cases/fourslash/completionListInUnclosedObjectTypeLiteralInSignature04.ts index 52b73aa1f1ed7..969df8cf2ea0d 100644 --- a/tests/cases/fourslash/completionListInUnclosedObjectTypeLiteralInSignature04.ts +++ b/tests/cases/fourslash/completionListInUnclosedObjectTypeLiteralInSignature04.ts @@ -9,6 +9,6 @@ verify.completions({ marker: "1", - exact: { name: "readonly", sortText: completion.SortText.GlobalsOrKeywords } , + exact: completion.interfaceElementKeywords, isNewIdentifierLocation: true }); diff --git a/tests/cases/fourslash/completionListWithModulesInsideModuleScope.ts b/tests/cases/fourslash/completionListWithModulesInsideModuleScope.ts index ad0f2531f86e0..7085b9e2e639a 100644 --- a/tests/cases/fourslash/completionListWithModulesInsideModuleScope.ts +++ b/tests/cases/fourslash/completionListWithModulesInsideModuleScope.ts @@ -328,7 +328,7 @@ verifyGeneral('class', { // from interface in mod1 verify.completions({ marker: "interface", - exact: { name: "readonly", sortText: completion.SortText.GlobalsOrKeywords }, + exact: completion.interfaceElementKeywords, isNewIdentifierLocation: true, }); @@ -378,10 +378,7 @@ verifyGeneral('exportedClass', { // from exported interface in mod1 verify.completions({ marker: "exportedInterface", - exact: [{ - name: "readonly", - sortText: completion.SortText.GlobalsOrKeywords - }], + exact: completion.interfaceElementKeywords, isNewIdentifierLocation: true }); diff --git a/tests/cases/fourslash/completionListWithModulesOutsideModuleScope.ts b/tests/cases/fourslash/completionListWithModulesOutsideModuleScope.ts index c811316ee82ce..b6eb81762edc9 100644 --- a/tests/cases/fourslash/completionListWithModulesOutsideModuleScope.ts +++ b/tests/cases/fourslash/completionListWithModulesOutsideModuleScope.ts @@ -256,7 +256,7 @@ verify.completions( // from interface scope { marker: "interface", - exact: [{ name: "readonly", sortText: completion.SortText.GlobalsOrKeywords }], + exact: completion.interfaceElementKeywords, isNewIdentifierLocation: true, } ); diff --git a/tests/cases/fourslash/completionsInterfaceElement.ts b/tests/cases/fourslash/completionsInterfaceElement.ts index 5a00473ce562a..0326643ed3450 100644 --- a/tests/cases/fourslash/completionsInterfaceElement.ts +++ b/tests/cases/fourslash/completionsInterfaceElement.ts @@ -11,13 +11,17 @@ ////type T = { fo/*t*/ }; ////type U = { /*u*/ }; +////interface L { +//// get /*l*/ +////} +////interface M { +//// set /*m*/ +////} + ////interface EndOfFile { f; /*e*/ -verify.completions({ +verify.completions({ marker: test.markers(), - exact: { - name: "readonly", - sortText: completion.SortText.GlobalsOrKeywords - }, - isNewIdentifierLocation: true + exact: completion.interfaceElementKeywords, + isNewIdentifierLocation: true }); diff --git a/tests/cases/fourslash/fourslash.ts b/tests/cases/fourslash/fourslash.ts index cbb6df28585d3..deb68438d80e2 100644 --- a/tests/cases/fourslash/fourslash.ts +++ b/tests/cases/fourslash/fourslash.ts @@ -696,6 +696,7 @@ declare namespace completion { export const globalTypes: ReadonlyArray; export function globalTypesPlus(plus: ReadonlyArray): ReadonlyArray; export const typeAssertionKeywords: ReadonlyArray; + export const interfaceElementKeywords: ReadonlyArray; export const classElementKeywords: ReadonlyArray; export const classElementInJsKeywords: ReadonlyArray; export const constructorParameterKeywords: ReadonlyArray; diff --git a/tests/cases/fourslash/navigationBarItemsItems.ts b/tests/cases/fourslash/navigationBarItemsItems.ts index 4597ac6474b50..05bf2555e0994 100644 --- a/tests/cases/fourslash/navigationBarItemsItems.ts +++ b/tests/cases/fourslash/navigationBarItemsItems.ts @@ -2,6 +2,8 @@ ////// Interface ////interface IPoint { +//// get a(): number; +//// set b(value: string); //// getDist(): number; //// new(): IPoint; //// (): any; @@ -63,6 +65,14 @@ verify.navigationTree({ "text": "[]", "kind": "index" }, + { + "text": "a", + "kind": "getter" + }, + { + "text": "b", + "kind": "setter" + }, { "text": "getDist", "kind": "method" @@ -186,6 +196,14 @@ verify.navigationBar([ "text": "[]", "kind": "index" }, + { + "text": "a", + "kind": "getter" + }, + { + "text": "b", + "kind": "setter" + }, { "text": "getDist", "kind": "method"