@@ -5940,7 +5940,9 @@ namespace ts {
5940
5940
// Otherwise, fall back to 'any'.
5941
5941
else {
5942
5942
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
+ }
5944
5946
}
5945
5947
else {
5946
5948
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 {
26330
26332
26331
26333
let duplicateFunctionDeclaration = false;
26332
26334
let multipleConstructorImplementation = false;
26335
+ let hasNonAmbientClass = false;
26333
26336
for (const current of declarations) {
26334
- const node = <SignatureDeclaration>current;
26337
+ const node = <SignatureDeclaration | ClassDeclaration | ClassExpression >current;
26335
26338
const inAmbientContext = node.flags & NodeFlags.Ambient;
26336
26339
const inAmbientContextOrInterface = node.parent.kind === SyntaxKind.InterfaceDeclaration || node.parent.kind === SyntaxKind.TypeLiteral || inAmbientContext;
26337
26340
if (inAmbientContextOrInterface) {
@@ -26345,6 +26348,10 @@ namespace ts {
26345
26348
previousDeclaration = undefined;
26346
26349
}
26347
26350
26351
+ if ((node.kind === SyntaxKind.ClassDeclaration || node.kind === SyntaxKind.ClassExpression) && !inAmbientContext) {
26352
+ hasNonAmbientClass = true;
26353
+ }
26354
+
26348
26355
if (node.kind === SyntaxKind.FunctionDeclaration || node.kind === SyntaxKind.MethodDeclaration || node.kind === SyntaxKind.MethodSignature || node.kind === SyntaxKind.Constructor) {
26349
26356
const currentNodeFlags = getEffectiveDeclarationFlags(node, flagsToCheck);
26350
26357
someNodeFlags |= currentNodeFlags;
@@ -26393,6 +26400,16 @@ namespace ts {
26393
26400
});
26394
26401
}
26395
26402
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
+
26396
26413
// Abstract methods can't have an implementation -- in particular, they don't need one.
26397
26414
if (lastSeenNonAmbientDeclaration && !lastSeenNonAmbientDeclaration.body &&
26398
26415
!hasModifier(lastSeenNonAmbientDeclaration, ModifierFlags.Abstract) && !lastSeenNonAmbientDeclaration.questionToken) {
@@ -31704,7 +31721,7 @@ namespace ts {
31704
31721
if (!symbol || !(symbol.flags & SymbolFlags.Function)) {
31705
31722
return false;
31706
31723
}
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));
31708
31725
}
31709
31726
31710
31727
function getPropertiesOfContainerFunction(node: Declaration): Symbol[] {
@@ -33098,43 +33115,39 @@ namespace ts {
33098
33115
}
33099
33116
33100
33117
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
+ }
33110
33125
}
33111
- else if (accessor.body && hasModifier(accessor, ModifierFlags.Abstract)) {
33126
+ if (accessor.body && hasModifier(accessor, ModifierFlags.Abstract)) {
33112
33127
return grammarErrorOnNode(accessor, Diagnostics.An_abstract_accessor_cannot_have_an_implementation);
33113
33128
}
33114
- else if (accessor.typeParameters) {
33129
+ if (accessor.typeParameters) {
33115
33130
return grammarErrorOnNode(accessor.name, Diagnostics.An_accessor_cannot_have_type_parameters);
33116
33131
}
33117
- else if (!doesAccessorHaveCorrectParameterCount(accessor)) {
33132
+ if (!doesAccessorHaveCorrectParameterCount(accessor)) {
33118
33133
return grammarErrorOnNode(accessor.name,
33119
- kind === SyntaxKind.GetAccessor ?
33134
+ accessor. kind === SyntaxKind.GetAccessor ?
33120
33135
Diagnostics.A_get_accessor_cannot_have_parameters :
33121
33136
Diagnostics.A_set_accessor_must_have_exactly_one_parameter);
33122
33137
}
33123
- else if (kind === SyntaxKind.SetAccessor) {
33138
+ if (accessor. kind === SyntaxKind.SetAccessor) {
33124
33139
if (accessor.type) {
33125
33140
return grammarErrorOnNode(accessor.name, Diagnostics.A_set_accessor_cannot_have_a_return_type_annotation);
33126
33141
}
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);
33138
33151
}
33139
33152
}
33140
33153
return false;
@@ -33622,14 +33635,9 @@ namespace ts {
33622
33635
33623
33636
function checkGrammarStatementInAmbientContext(node: Node): boolean {
33624
33637
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
-
33630
33638
// Find containing block which is either Block, ModuleBlock, SourceFile
33631
33639
const links = getNodeLinks(node);
33632
- if (!links.hasReportedStatementInAmbientContext && isFunctionLike(node.parent)) {
33640
+ if (!links.hasReportedStatementInAmbientContext && ( isFunctionLike(node.parent) || isAccessor(node.parent) )) {
33633
33641
return getNodeLinks(node).hasReportedStatementInAmbientContext = grammarErrorOnFirstToken(node, Diagnostics.An_implementation_cannot_be_declared_in_ambient_contexts);
33634
33642
}
33635
33643
0 commit comments