@@ -5937,7 +5937,9 @@ namespace ts {
59375937 // Otherwise, fall back to 'any'.
59385938 else {
59395939 if (setter) {
5940- errorOrSuggestion(noImplicitAny, setter, Diagnostics.Property_0_implicitly_has_type_any_because_its_set_accessor_lacks_a_parameter_type_annotation, symbolToString(symbol));
5940+ if (!isPrivateWithinAmbient(setter)) {
5941+ errorOrSuggestion(noImplicitAny, setter, Diagnostics.Property_0_implicitly_has_type_any_because_its_set_accessor_lacks_a_parameter_type_annotation, symbolToString(symbol));
5942+ }
59415943 }
59425944 else {
59435945 Debug.assert(!!getter, "there must existed getter as we are current checking either setter or getter in this function");
@@ -26273,8 +26275,9 @@ namespace ts {
2627326275
2627426276 let duplicateFunctionDeclaration = false;
2627526277 let multipleConstructorImplementation = false;
26278+ let hasNonAmbientClass = false;
2627626279 for (const current of declarations) {
26277- const node = <SignatureDeclaration>current;
26280+ const node = <SignatureDeclaration | ClassDeclaration | ClassExpression >current;
2627826281 const inAmbientContext = node.flags & NodeFlags.Ambient;
2627926282 const inAmbientContextOrInterface = node.parent.kind === SyntaxKind.InterfaceDeclaration || node.parent.kind === SyntaxKind.TypeLiteral || inAmbientContext;
2628026283 if (inAmbientContextOrInterface) {
@@ -26288,6 +26291,10 @@ namespace ts {
2628826291 previousDeclaration = undefined;
2628926292 }
2629026293
26294+ if ((node.kind === SyntaxKind.ClassDeclaration || node.kind === SyntaxKind.ClassExpression) && !inAmbientContext) {
26295+ hasNonAmbientClass = true;
26296+ }
26297+
2629126298 if (node.kind === SyntaxKind.FunctionDeclaration || node.kind === SyntaxKind.MethodDeclaration || node.kind === SyntaxKind.MethodSignature || node.kind === SyntaxKind.Constructor) {
2629226299 const currentNodeFlags = getEffectiveDeclarationFlags(node, flagsToCheck);
2629326300 someNodeFlags |= currentNodeFlags;
@@ -26336,6 +26343,16 @@ namespace ts {
2633626343 });
2633726344 }
2633826345
26346+ if (hasNonAmbientClass && !isConstructor && symbol.flags & SymbolFlags.Function) {
26347+ // A non-ambient class cannot be an implementation for a non-constructor function/class merge
26348+ // TODO: The below just replicates our older error from when classes and functions were
26349+ // entirely unable to merge - a more helpful message like "Class declaration cannot implement overload list"
26350+ // might be warranted. :shrug:
26351+ forEach(declarations, declaration => {
26352+ addDuplicateDeclarationError(getNameOfDeclaration(declaration) || declaration, Diagnostics.Duplicate_identifier_0, symbolName(symbol), filter(declarations, d => d !== declaration));
26353+ });
26354+ }
26355+
2633926356 // Abstract methods can't have an implementation -- in particular, they don't need one.
2634026357 if (lastSeenNonAmbientDeclaration && !lastSeenNonAmbientDeclaration.body &&
2634126358 !hasModifier(lastSeenNonAmbientDeclaration, ModifierFlags.Abstract) && !lastSeenNonAmbientDeclaration.questionToken) {
@@ -31649,7 +31666,7 @@ namespace ts {
3164931666 if (!symbol || !(symbol.flags & SymbolFlags.Function)) {
3165031667 return false;
3165131668 }
31652- return !!forEachEntry(getExportsOfSymbol(symbol), p => p.flags & SymbolFlags.Value && isPropertyAccessExpression(p.valueDeclaration));
31669+ return !!forEachEntry(getExportsOfSymbol(symbol), p => p.flags & SymbolFlags.Value && p.valueDeclaration && isPropertyAccessExpression(p.valueDeclaration));
3165331670 }
3165431671
3165531672 function getPropertiesOfContainerFunction(node: Declaration): Symbol[] {
@@ -33043,43 +33060,39 @@ namespace ts {
3304333060 }
3304433061
3304533062 function checkGrammarAccessor(accessor: AccessorDeclaration): boolean {
33046- const kind = accessor.kind;
33047- if (languageVersion < ScriptTarget.ES5) {
33048- return grammarErrorOnNode(accessor.name, Diagnostics.Accessors_are_only_available_when_targeting_ECMAScript_5_and_higher);
33049- }
33050- else if (accessor.flags & NodeFlags.Ambient) {
33051- return grammarErrorOnNode(accessor.name, Diagnostics.An_accessor_cannot_be_declared_in_an_ambient_context);
33052- }
33053- else if (accessor.body === undefined && !hasModifier(accessor, ModifierFlags.Abstract)) {
33054- return grammarErrorAtPos(accessor, accessor.end - 1, ";".length, Diagnostics._0_expected, "{");
33063+ if (!(accessor.flags & NodeFlags.Ambient)) {
33064+ if (languageVersion < ScriptTarget.ES5) {
33065+ return grammarErrorOnNode(accessor.name, Diagnostics.Accessors_are_only_available_when_targeting_ECMAScript_5_and_higher);
33066+ }
33067+ if (accessor.body === undefined && !hasModifier(accessor, ModifierFlags.Abstract)) {
33068+ return grammarErrorAtPos(accessor, accessor.end - 1, ";".length, Diagnostics._0_expected, "{");
33069+ }
3305533070 }
33056- else if (accessor.body && hasModifier(accessor, ModifierFlags.Abstract)) {
33071+ if (accessor.body && hasModifier(accessor, ModifierFlags.Abstract)) {
3305733072 return grammarErrorOnNode(accessor, Diagnostics.An_abstract_accessor_cannot_have_an_implementation);
3305833073 }
33059- else if (accessor.typeParameters) {
33074+ if (accessor.typeParameters) {
3306033075 return grammarErrorOnNode(accessor.name, Diagnostics.An_accessor_cannot_have_type_parameters);
3306133076 }
33062- else if (!doesAccessorHaveCorrectParameterCount(accessor)) {
33077+ if (!doesAccessorHaveCorrectParameterCount(accessor)) {
3306333078 return grammarErrorOnNode(accessor.name,
33064- kind === SyntaxKind.GetAccessor ?
33079+ accessor. kind === SyntaxKind.GetAccessor ?
3306533080 Diagnostics.A_get_accessor_cannot_have_parameters :
3306633081 Diagnostics.A_set_accessor_must_have_exactly_one_parameter);
3306733082 }
33068- else if (kind === SyntaxKind.SetAccessor) {
33083+ if (accessor. kind === SyntaxKind.SetAccessor) {
3306933084 if (accessor.type) {
3307033085 return grammarErrorOnNode(accessor.name, Diagnostics.A_set_accessor_cannot_have_a_return_type_annotation);
3307133086 }
33072- else {
33073- const parameter = accessor.parameters[0];
33074- if (parameter.dotDotDotToken) {
33075- return grammarErrorOnNode(parameter.dotDotDotToken, Diagnostics.A_set_accessor_cannot_have_rest_parameter);
33076- }
33077- else if (parameter.questionToken) {
33078- return grammarErrorOnNode(parameter.questionToken, Diagnostics.A_set_accessor_cannot_have_an_optional_parameter);
33079- }
33080- else if (parameter.initializer) {
33081- return grammarErrorOnNode(accessor.name, Diagnostics.A_set_accessor_parameter_cannot_have_an_initializer);
33082- }
33087+ const parameter = Debug.assertDefined(getSetAccessorValueParameter(accessor), "Return value does not match parameter count assertion.");
33088+ if (parameter.dotDotDotToken) {
33089+ return grammarErrorOnNode(parameter.dotDotDotToken, Diagnostics.A_set_accessor_cannot_have_rest_parameter);
33090+ }
33091+ if (parameter.questionToken) {
33092+ return grammarErrorOnNode(parameter.questionToken, Diagnostics.A_set_accessor_cannot_have_an_optional_parameter);
33093+ }
33094+ if (parameter.initializer) {
33095+ return grammarErrorOnNode(accessor.name, Diagnostics.A_set_accessor_parameter_cannot_have_an_initializer);
3308333096 }
3308433097 }
3308533098 return false;
@@ -33567,14 +33580,9 @@ namespace ts {
3356733580
3356833581 function checkGrammarStatementInAmbientContext(node: Node): boolean {
3356933582 if (node.flags & NodeFlags.Ambient) {
33570- // An accessors is already reported about the ambient context
33571- if (isAccessor(node.parent)) {
33572- return getNodeLinks(node).hasReportedStatementInAmbientContext = true;
33573- }
33574-
3357533583 // Find containing block which is either Block, ModuleBlock, SourceFile
3357633584 const links = getNodeLinks(node);
33577- if (!links.hasReportedStatementInAmbientContext && isFunctionLike(node.parent)) {
33585+ if (!links.hasReportedStatementInAmbientContext && ( isFunctionLike(node.parent) || isAccessor(node.parent) )) {
3357833586 return getNodeLinks(node).hasReportedStatementInAmbientContext = grammarErrorOnFirstToken(node, Diagnostics.An_implementation_cannot_be_declared_in_ambient_contexts);
3357933587 }
3358033588
0 commit comments