mirror of
https://github.com/microsoft/TypeScript.git
synced 2025-11-18 17:21:48 +00:00
ES private field check (#44648)
* es private fields in in (#52) add support for the 'private-fields-in-in' TC39 proposal Signed-off-by: Ashley Claymore <acutmore@users.noreply.github.com> * [fixup] include inToken when walking forEachChild(node, cb) * [squash] re-accept lib definition baseline changes * [squash] reduce if/else to ternary Signed-off-by: Ashley Claymore <acutmore@users.noreply.github.com> * [squash] drop 'originalName' and rename parameter instead Signed-off-by: Ashley Claymore <acutmore@users.noreply.github.com> * [squash] extend spelling suggestion to all privateIdentifiers Signed-off-by: Ashley Claymore <acutmore@users.noreply.github.com> * [squash] revert the added lexical spelling suggestions logic Signed-off-by: Ashley Claymore <acutmore@users.noreply.github.com> * [squash] update baseline Signed-off-by: Ashley Claymore <acutmore@users.noreply.github.com> * [squash] inline variable as per PR suggestion Signed-off-by: Ashley Claymore <acutmore@users.noreply.github.com> * [squash] test targets both esnext and es2020 as per PR comment Signed-off-by: Ashley Claymore <acutmore@users.noreply.github.com> * switch to using a binary expression Signed-off-by: Ashley Claymore <acutmore@users.noreply.github.com> * [squash] PrivateIdentifier now extends PrimaryExpression Signed-off-by: Ashley Claymore <acutmore@users.noreply.github.com> * [squash] accept public api baseline changes Signed-off-by: Ashley Claymore <acutmore@users.noreply.github.com> * [squash] classPrivateFieldInHelper now has documentation Signed-off-by: Ashley Claymore <acutmore@users.noreply.github.com> * [squash] type-check now follows existing in-expression path Signed-off-by: Ashley Claymore <acutmore@users.noreply.github.com> * [squash] parser now follows existing binaryExpression path Signed-off-by: Ashley Claymore <acutmore@users.noreply.github.com> * [squash] correct typo in comment Signed-off-by: Ashley Claymore <acutmore@users.noreply.github.com> * [squash] no longer use esNext flag Signed-off-by: Ashley Claymore <acutmore@users.noreply.github.com> * [squash] swap 'reciever, state' helper params Signed-off-by: Ashley Claymore <acutmore@users.noreply.github.com> * [squash] remove change to parenthesizerRules Signed-off-by: Ashley Claymore <acutmore@users.noreply.github.com> * [squash] apply suggested changes to checker Signed-off-by: Ashley Claymore <acutmore@users.noreply.github.com> * [squash] remove need for assertion in fixSpelling Signed-off-by: Ashley Claymore <acutmore@users.noreply.github.com> * [squash] improve comment hint in test Signed-off-by: Ashley Claymore <acutmore@users.noreply.github.com> * [squash] fix comment typos Signed-off-by: Ashley Claymore <acutmore@users.noreply.github.com> * [squash] add flow-test for Foo | FooSub | Bar Signed-off-by: Ashley Claymore <acutmore@users.noreply.github.com> * [squash] add checkExternalEmitHelpers call and new test case Signed-off-by: Ashley Claymore <acutmore@users.noreply.github.com> * [squash] simplify and correct parser Signed-off-by: Ashley Claymore <acutmore@users.noreply.github.com> * [squash] move most of the added checker logic to expression level Signed-off-by: Ashley Claymore <acutmore@users.noreply.github.com> * [squash] always error when privateId could not be resolved Signed-off-by: Ashley Claymore <acutmore@users.noreply.github.com> * [squash] reword comment Signed-off-by: Ashley Claymore <acutmore@users.noreply.github.com> * [squash] fix codeFixSpelling test Signed-off-by: Ashley Claymore <acutmore@users.noreply.github.com> * [squash] do less work Signed-off-by: Ashley Claymore <acutmore@users.noreply.github.com> * store symbol by priateId not binaryExpression Signed-off-by: Ashley Claymore <acutmore@users.noreply.github.com> * moved parsePrivateIdentifier into parsePrimaryExpression Signed-off-by: Ashley Claymore <acutmore@users.noreply.github.com> * [squash] checkInExpressionn bails out early on silentNeverType Signed-off-by: Ashley Claymore <acutmore@users.noreply.github.com> * [squash] more detailed error messages Signed-off-by: Ashley Claymore <acutmore@users.noreply.github.com> * [squash] resolves conflict in diagnosticMessages.json Signed-off-by: Ashley Claymore <acutmore@users.noreply.github.com> * [squash] update baseline for importHelpersES6 Signed-off-by: Ashley Claymore <acutmore@users.noreply.github.com> * [squash] remove redundent if and comment from parser Signed-off-by: Ashley Claymore <acutmore@users.noreply.github.com> * [squash] split up grammar/check/symbolLookup Signed-off-by: Ashley Claymore <acutmore@users.noreply.github.com> * [squash] reword message for existing left side of in-expression error Signed-off-by: Ashley Claymore <acutmore@users.noreply.github.com>
This commit is contained in:
@@ -4,7 +4,7 @@ namespace ts.codefix {
|
||||
const didYouMeanStaticMemberCode = Diagnostics.Cannot_find_name_0_Did_you_mean_the_static_member_1_0.code;
|
||||
const errorCodes = [
|
||||
Diagnostics.Cannot_find_name_0_Did_you_mean_the_instance_member_this_0.code,
|
||||
Diagnostics.Private_identifiers_are_not_allowed_outside_class_bodies.code,
|
||||
Diagnostics.Private_identifiers_are_only_allowed_in_class_bodies_and_may_only_be_used_as_part_of_a_class_member_declaration_property_access_or_on_the_left_hand_side_of_an_in_expression.code,
|
||||
didYouMeanStaticMemberCode,
|
||||
];
|
||||
registerCodeFix({
|
||||
@@ -32,7 +32,7 @@ namespace ts.codefix {
|
||||
|
||||
function getInfo(sourceFile: SourceFile, pos: number, diagCode: number): Info | undefined {
|
||||
const node = getTokenAtPosition(sourceFile, pos);
|
||||
if (isIdentifier(node)) {
|
||||
if (isIdentifier(node) || isPrivateIdentifier(node)) {
|
||||
return { node, className: diagCode === didYouMeanStaticMemberCode ? getContainingClass(node)!.name!.text : undefined };
|
||||
}
|
||||
}
|
||||
|
||||
@@ -57,6 +57,10 @@ namespace ts.codefix {
|
||||
}
|
||||
suggestedSymbol = checker.getSuggestedSymbolForNonexistentProperty(node, containingType);
|
||||
}
|
||||
else if (isBinaryExpression(parent) && parent.operatorToken.kind === SyntaxKind.InKeyword && parent.left === node && isPrivateIdentifier(node)) {
|
||||
const receiverType = checker.getTypeAtLocation(parent.right);
|
||||
suggestedSymbol = checker.getSuggestedSymbolForNonexistentProperty(node, receiverType);
|
||||
}
|
||||
else if (isQualifiedName(parent) && parent.right === node) {
|
||||
const symbol = checker.getSymbolAtLocation(parent.left);
|
||||
if (symbol && symbol.flags & SymbolFlags.Module) {
|
||||
|
||||
@@ -401,6 +401,12 @@ namespace ts {
|
||||
public kind!: SyntaxKind.PrivateIdentifier;
|
||||
public escapedText!: __String;
|
||||
public symbol!: Symbol;
|
||||
_primaryExpressionBrand: any;
|
||||
_memberExpressionBrand: any;
|
||||
_leftHandSideExpressionBrand: any;
|
||||
_updateExpressionBrand: any;
|
||||
_unaryExpressionBrand: any;
|
||||
_expressionBrand: any;
|
||||
constructor(_kind: SyntaxKind.PrivateIdentifier, pos: number, end: number) {
|
||||
super(pos, end);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user