Skip to content

Commit 7d8a2b9

Browse files
committed
produce an error if private field helpers are not up to date
1 parent 3b62d3c commit 7d8a2b9

File tree

2 files changed

+23
-3
lines changed

2 files changed

+23
-3
lines changed

Diff for: src/compiler/checker.ts

+19-3
Original file line numberDiff line numberDiff line change
@@ -26791,12 +26791,18 @@ namespace ts {
2679126791
const parentSymbol = getNodeLinks(left).resolvedSymbol;
2679226792
const assignmentKind = getAssignmentTargetKind(node);
2679326793
const apparentType = getApparentType(assignmentKind !== AssignmentKind.None || isMethodAccessForCall(node) ? getWidenedType(leftType) : leftType);
26794-
if (isPrivateIdentifier(right)) {
26795-
checkExternalEmitHelpers(node, ExternalEmitHelpers.ClassPrivateFieldGet);
26796-
}
2679726794
const isAnyLike = isTypeAny(apparentType) || apparentType === silentNeverType;
2679826795
let prop: Symbol | undefined;
2679926796
if (isPrivateIdentifier(right)) {
26797+
if (languageVersion < ScriptTarget.ESNext) {
26798+
if (assignmentKind !== AssignmentKind.None) {
26799+
checkExternalEmitHelpers(node, ExternalEmitHelpers.ClassPrivateFieldSet);
26800+
}
26801+
if (assignmentKind !== AssignmentKind.Definite) {
26802+
checkExternalEmitHelpers(node, ExternalEmitHelpers.ClassPrivateFieldGet);
26803+
}
26804+
}
26805+
2680026806
const lexicallyScopedSymbol = lookupSymbolForPrivateIdentifierDeclaration(right.escapedText, right);
2680126807
if (assignmentKind && lexicallyScopedSymbol && lexicallyScopedSymbol.valueDeclaration && isMethodDeclaration(lexicallyScopedSymbol.valueDeclaration)) {
2680226808
grammarErrorOnNode(right, Diagnostics.Cannot_assign_to_private_method_0_Private_methods_are_not_writable, idText(right));
@@ -39906,6 +39912,16 @@ namespace ts {
3990639912
if (!symbol) {
3990739913
error(location, Diagnostics.This_syntax_requires_an_imported_helper_named_1_which_does_not_exist_in_0_Consider_upgrading_your_version_of_0, externalHelpersModuleNameText, name);
3990839914
}
39915+
else if (helper & ExternalEmitHelpers.ClassPrivateFieldGet) {
39916+
if (!some(getSignaturesOfSymbol(symbol), signature => getParameterCount(signature) > 3)) {
39917+
error(location, Diagnostics.This_syntax_requires_an_imported_helper_named_1_with_2_parameters_which_is_not_compatible_with_the_one_in_0_Consider_upgrading_your_version_of_0, externalHelpersModuleNameText, name, 4);
39918+
}
39919+
}
39920+
else if (helper & ExternalEmitHelpers.ClassPrivateFieldSet) {
39921+
if (!some(getSignaturesOfSymbol(symbol), signature => getParameterCount(signature) > 4)) {
39922+
error(location, Diagnostics.This_syntax_requires_an_imported_helper_named_1_with_2_parameters_which_is_not_compatible_with_the_one_in_0_Consider_upgrading_your_version_of_0, externalHelpersModuleNameText, name, 5);
39923+
}
39924+
}
3990939925
}
3991039926
}
3991139927
}

Diff for: src/compiler/diagnosticMessages.json

+4
Original file line numberDiff line numberDiff line change
@@ -3300,6 +3300,10 @@
33003300
"category": "Error",
33013301
"code": 2806
33023302
},
3303+
"This syntax requires an imported helper named '{1}' with {2} parameters, which is not compatible with the one in '{0}'. Consider upgrading your version of '{0}'.": {
3304+
"category": "Error",
3305+
"code": 2807
3306+
},
33033307

33043308
"Import declaration '{0}' is using private name '{1}'.": {
33053309
"category": "Error",

0 commit comments

Comments
 (0)