@@ -5940,7 +5940,9 @@ namespace ts {
59405940 // Otherwise, fall back to 'any'.
59415941 else {
59425942 if (setter) {
5943- errorOrSuggestion(noImplicitAny, setter, Diagnostics.Property_0_implicitly_has_type_any_because_its_set_accessor_lacks_a_parameter_type_annotation, symbolToString(symbol));
5943+ if (!isPrivateWithinAmbient(setter)) {
5944+ errorOrSuggestion(noImplicitAny, setter, Diagnostics.Property_0_implicitly_has_type_any_because_its_set_accessor_lacks_a_parameter_type_annotation, symbolToString(symbol));
5945+ }
59445946 }
59455947 else {
59465948 Debug.assert(!!getter, "there must existed getter as we are current checking either setter or getter in this function");
@@ -26330,8 +26332,9 @@ namespace ts {
2633026332
2633126333 let duplicateFunctionDeclaration = false;
2633226334 let multipleConstructorImplementation = false;
26335+ let hasNonAmbientClass = false;
2633326336 for (const current of declarations) {
26334- const node = <SignatureDeclaration>current;
26337+ const node = <SignatureDeclaration | ClassDeclaration | ClassExpression >current;
2633526338 const inAmbientContext = node.flags & NodeFlags.Ambient;
2633626339 const inAmbientContextOrInterface = node.parent.kind === SyntaxKind.InterfaceDeclaration || node.parent.kind === SyntaxKind.TypeLiteral || inAmbientContext;
2633726340 if (inAmbientContextOrInterface) {
@@ -26345,6 +26348,10 @@ namespace ts {
2634526348 previousDeclaration = undefined;
2634626349 }
2634726350
26351+ if ((node.kind === SyntaxKind.ClassDeclaration || node.kind === SyntaxKind.ClassExpression) && !inAmbientContext) {
26352+ hasNonAmbientClass = true;
26353+ }
26354+
2634826355 if (node.kind === SyntaxKind.FunctionDeclaration || node.kind === SyntaxKind.MethodDeclaration || node.kind === SyntaxKind.MethodSignature || node.kind === SyntaxKind.Constructor) {
2634926356 const currentNodeFlags = getEffectiveDeclarationFlags(node, flagsToCheck);
2635026357 someNodeFlags |= currentNodeFlags;
@@ -26393,6 +26400,16 @@ namespace ts {
2639326400 });
2639426401 }
2639526402
26403+ if (hasNonAmbientClass && !isConstructor && symbol.flags & SymbolFlags.Function) {
26404+ // A non-ambient class cannot be an implementation for a non-constructor function/class merge
26405+ // TODO: The below just replicates our older error from when classes and functions were
26406+ // entirely unable to merge - a more helpful message like "Class declaration cannot implement overload list"
26407+ // might be warranted. :shrug:
26408+ forEach(declarations, declaration => {
26409+ addDuplicateDeclarationError(getNameOfDeclaration(declaration) || declaration, Diagnostics.Duplicate_identifier_0, symbolName(symbol), filter(declarations, d => d !== declaration));
26410+ });
26411+ }
26412+
2639626413 // Abstract methods can't have an implementation -- in particular, they don't need one.
2639726414 if (lastSeenNonAmbientDeclaration && !lastSeenNonAmbientDeclaration.body &&
2639826415 !hasModifier(lastSeenNonAmbientDeclaration, ModifierFlags.Abstract) && !lastSeenNonAmbientDeclaration.questionToken) {
@@ -31704,7 +31721,7 @@ namespace ts {
3170431721 if (!symbol || !(symbol.flags & SymbolFlags.Function)) {
3170531722 return false;
3170631723 }
31707- return !!forEachEntry(getExportsOfSymbol(symbol), p => p.flags & SymbolFlags.Value && isPropertyAccessExpression(p.valueDeclaration));
31724+ return !!forEachEntry(getExportsOfSymbol(symbol), p => p.flags & SymbolFlags.Value && p.valueDeclaration && isPropertyAccessExpression(p.valueDeclaration));
3170831725 }
3170931726
3171031727 function getPropertiesOfContainerFunction(node: Declaration): Symbol[] {
@@ -33098,43 +33115,39 @@ namespace ts {
3309833115 }
3309933116
3310033117 function checkGrammarAccessor(accessor: AccessorDeclaration): boolean {
33101- const kind = accessor.kind;
33102- if (languageVersion < ScriptTarget.ES5) {
33103- return grammarErrorOnNode(accessor.name, Diagnostics.Accessors_are_only_available_when_targeting_ECMAScript_5_and_higher);
33104- }
33105- else if (accessor.flags & NodeFlags.Ambient) {
33106- return grammarErrorOnNode(accessor.name, Diagnostics.An_accessor_cannot_be_declared_in_an_ambient_context);
33107- }
33108- else if (accessor.body === undefined && !hasModifier(accessor, ModifierFlags.Abstract)) {
33109- return grammarErrorAtPos(accessor, accessor.end - 1, ";".length, Diagnostics._0_expected, "{");
33118+ if (!(accessor.flags & NodeFlags.Ambient)) {
33119+ if (languageVersion < ScriptTarget.ES5) {
33120+ return grammarErrorOnNode(accessor.name, Diagnostics.Accessors_are_only_available_when_targeting_ECMAScript_5_and_higher);
33121+ }
33122+ if (accessor.body === undefined && !hasModifier(accessor, ModifierFlags.Abstract)) {
33123+ return grammarErrorAtPos(accessor, accessor.end - 1, ";".length, Diagnostics._0_expected, "{");
33124+ }
3311033125 }
33111- else if (accessor.body && hasModifier(accessor, ModifierFlags.Abstract)) {
33126+ if (accessor.body && hasModifier(accessor, ModifierFlags.Abstract)) {
3311233127 return grammarErrorOnNode(accessor, Diagnostics.An_abstract_accessor_cannot_have_an_implementation);
3311333128 }
33114- else if (accessor.typeParameters) {
33129+ if (accessor.typeParameters) {
3311533130 return grammarErrorOnNode(accessor.name, Diagnostics.An_accessor_cannot_have_type_parameters);
3311633131 }
33117- else if (!doesAccessorHaveCorrectParameterCount(accessor)) {
33132+ if (!doesAccessorHaveCorrectParameterCount(accessor)) {
3311833133 return grammarErrorOnNode(accessor.name,
33119- kind === SyntaxKind.GetAccessor ?
33134+ accessor. kind === SyntaxKind.GetAccessor ?
3312033135 Diagnostics.A_get_accessor_cannot_have_parameters :
3312133136 Diagnostics.A_set_accessor_must_have_exactly_one_parameter);
3312233137 }
33123- else if (kind === SyntaxKind.SetAccessor) {
33138+ if (accessor. kind === SyntaxKind.SetAccessor) {
3312433139 if (accessor.type) {
3312533140 return grammarErrorOnNode(accessor.name, Diagnostics.A_set_accessor_cannot_have_a_return_type_annotation);
3312633141 }
33127- else {
33128- const parameter = accessor.parameters[0];
33129- if (parameter.dotDotDotToken) {
33130- return grammarErrorOnNode(parameter.dotDotDotToken, Diagnostics.A_set_accessor_cannot_have_rest_parameter);
33131- }
33132- else if (parameter.questionToken) {
33133- return grammarErrorOnNode(parameter.questionToken, Diagnostics.A_set_accessor_cannot_have_an_optional_parameter);
33134- }
33135- else if (parameter.initializer) {
33136- return grammarErrorOnNode(accessor.name, Diagnostics.A_set_accessor_parameter_cannot_have_an_initializer);
33137- }
33142+ const parameter = Debug.assertDefined(getSetAccessorValueParameter(accessor), "Return value does not match parameter count assertion.");
33143+ if (parameter.dotDotDotToken) {
33144+ return grammarErrorOnNode(parameter.dotDotDotToken, Diagnostics.A_set_accessor_cannot_have_rest_parameter);
33145+ }
33146+ if (parameter.questionToken) {
33147+ return grammarErrorOnNode(parameter.questionToken, Diagnostics.A_set_accessor_cannot_have_an_optional_parameter);
33148+ }
33149+ if (parameter.initializer) {
33150+ return grammarErrorOnNode(accessor.name, Diagnostics.A_set_accessor_parameter_cannot_have_an_initializer);
3313833151 }
3313933152 }
3314033153 return false;
@@ -33622,14 +33635,9 @@ namespace ts {
3362233635
3362333636 function checkGrammarStatementInAmbientContext(node: Node): boolean {
3362433637 if (node.flags & NodeFlags.Ambient) {
33625- // An accessors is already reported about the ambient context
33626- if (isAccessor(node.parent)) {
33627- return getNodeLinks(node).hasReportedStatementInAmbientContext = true;
33628- }
33629-
3363033638 // Find containing block which is either Block, ModuleBlock, SourceFile
3363133639 const links = getNodeLinks(node);
33632- if (!links.hasReportedStatementInAmbientContext && isFunctionLike(node.parent)) {
33640+ if (!links.hasReportedStatementInAmbientContext && ( isFunctionLike(node.parent) || isAccessor(node.parent) )) {
3363333641 return getNodeLinks(node).hasReportedStatementInAmbientContext = grammarErrorOnFirstToken(node, Diagnostics.An_implementation_cannot_be_declared_in_ambient_contexts);
3363433642 }
3363533643
0 commit comments