@@ -7619,8 +7619,8 @@ namespace ts {
7619
7619
return anyType;
7620
7620
}
7621
7621
else if (declaration.kind === SyntaxKind.BinaryExpression ||
7622
- (declaration.kind === SyntaxKind.PropertyAccessExpression || declaration.kind === SyntaxKind.ElementAccessExpression ) &&
7623
- declaration.parent.kind === SyntaxKind.BinaryExpression) {
7622
+ isAccessExpression (declaration) &&
7623
+ declaration.parent.kind === SyntaxKind.BinaryExpression) {
7624
7624
return getWidenedTypeForAssignmentDeclaration(symbol);
7625
7625
}
7626
7626
else if (symbol.flags & SymbolFlags.ValueModule && declaration && isSourceFile(declaration) && declaration.commonJsModuleIndicator) {
@@ -21015,8 +21015,8 @@ namespace ts {
21015
21015
const parent = func.parent;
21016
21016
if (parent.kind === SyntaxKind.BinaryExpression && (<BinaryExpression>parent).operatorToken.kind === SyntaxKind.EqualsToken) {
21017
21017
const target = (<BinaryExpression>parent).left;
21018
- if (target.kind === SyntaxKind.PropertyAccessExpression || target.kind === SyntaxKind.ElementAccessExpression ) {
21019
- const { expression } = target as AccessExpression ;
21018
+ if (isAccessExpression( target) ) {
21019
+ const { expression } = target;
21020
21020
// Don't contextually type `this` as `exports` in `exports.Point = function(x, y) { this.x = x; this.y = y; }`
21021
21021
if (inJs && isIdentifier(expression)) {
21022
21022
const sourceFile = getSourceFileOfNode(parent);
@@ -23208,7 +23208,7 @@ namespace ts {
23208
23208
// assignment target, and the referenced property was declared as a variable, property,
23209
23209
// accessor, or optional method.
23210
23210
const assignmentKind = getAssignmentTargetKind(node);
23211
- if (node.kind !== SyntaxKind.ElementAccessExpression && node.kind !== SyntaxKind.PropertyAccessExpression ||
23211
+ if (!isAccessExpression( node) ||
23212
23212
assignmentKind === AssignmentKind.Definite ||
23213
23213
prop && !(prop.flags & (SymbolFlags.Variable | SymbolFlags.Property | SymbolFlags.Accessor)) && !(prop.flags & SymbolFlags.Method && propType.flags & TypeFlags.Union)) {
23214
23214
return propType;
@@ -23250,8 +23250,9 @@ namespace ts {
23250
23250
23251
23251
let diagnosticMessage;
23252
23252
const declarationName = idText(right);
23253
- if (isInPropertyInitializer(node) &&
23254
- !isBlockScopedNameDeclaredBeforeUse(valueDeclaration, right)
23253
+ if (isInPropertyInitializer(node)
23254
+ && !(isAccessExpression(node) && isAccessExpression(node.expression))
23255
+ && !isBlockScopedNameDeclaredBeforeUse(valueDeclaration, right)
23255
23256
&& !isPropertyDeclaredInAncestorClass(prop)) {
23256
23257
diagnosticMessage = error(right, Diagnostics.Property_0_is_used_before_its_initialization, declarationName);
23257
23258
}
@@ -24144,8 +24145,8 @@ namespace ts {
24144
24145
function getThisArgumentOfCall(node: CallLikeExpression): LeftHandSideExpression | undefined {
24145
24146
if (node.kind === SyntaxKind.CallExpression) {
24146
24147
const callee = skipOuterExpressions(node.expression);
24147
- if (callee.kind === SyntaxKind.PropertyAccessExpression || callee.kind === SyntaxKind.ElementAccessExpression ) {
24148
- return ( callee as AccessExpression) .expression;
24148
+ if (isAccessExpression( callee) ) {
24149
+ return callee.expression;
24149
24150
}
24150
24151
}
24151
24152
}
@@ -26499,8 +26500,8 @@ namespace ts {
26499
26500
if (isReadonlySymbol(symbol)) {
26500
26501
// Allow assignments to readonly properties within constructors of the same class declaration.
26501
26502
if (symbol.flags & SymbolFlags.Property &&
26502
- (expr.kind === SyntaxKind.PropertyAccessExpression || expr.kind === SyntaxKind.ElementAccessExpression ) &&
26503
- ( expr as AccessExpression) .expression.kind === SyntaxKind.ThisKeyword) {
26503
+ isAccessExpression (expr) &&
26504
+ expr.expression.kind === SyntaxKind.ThisKeyword) {
26504
26505
// Look for if this is the constructor for the class that `symbol` is a property of.
26505
26506
const ctor = getContainingFunction(expr);
26506
26507
if (!(ctor && ctor.kind === SyntaxKind.Constructor)) {
@@ -26522,9 +26523,9 @@ namespace ts {
26522
26523
}
26523
26524
return true;
26524
26525
}
26525
- if (expr.kind === SyntaxKind.PropertyAccessExpression || expr.kind === SyntaxKind.ElementAccessExpression ) {
26526
+ if (isAccessExpression( expr) ) {
26526
26527
// references through namespace import should be readonly
26527
- const node = skipParentheses(( expr as AccessExpression) .expression);
26528
+ const node = skipParentheses(expr.expression);
26528
26529
if (node.kind === SyntaxKind.Identifier) {
26529
26530
const symbol = getNodeLinks(node).resolvedSymbol!;
26530
26531
if (symbol.flags & SymbolFlags.Alias) {
@@ -26539,7 +26540,7 @@ namespace ts {
26539
26540
function checkReferenceExpression(expr: Expression, invalidReferenceMessage: DiagnosticMessage, invalidOptionalChainMessage: DiagnosticMessage): boolean {
26540
26541
// References are combinations of identifiers, parentheses, and property accesses.
26541
26542
const node = skipOuterExpressions(expr, OuterExpressionKinds.Assertions | OuterExpressionKinds.Parentheses);
26542
- if (node.kind !== SyntaxKind.Identifier && node.kind !== SyntaxKind.PropertyAccessExpression && node.kind !== SyntaxKind.ElementAccessExpression ) {
26543
+ if (node.kind !== SyntaxKind.Identifier && !isAccessExpression( node) ) {
26543
26544
error(expr, invalidReferenceMessage);
26544
26545
return false;
26545
26546
}
@@ -26553,7 +26554,7 @@ namespace ts {
26553
26554
function checkDeleteExpression(node: DeleteExpression): Type {
26554
26555
checkExpression(node.expression);
26555
26556
const expr = skipParentheses(node.expression);
26556
- if (expr.kind !== SyntaxKind.PropertyAccessExpression && expr.kind !== SyntaxKind.ElementAccessExpression ) {
26557
+ if (!isAccessExpression( expr) ) {
26557
26558
error(expr, Diagnostics.The_operand_of_a_delete_operator_must_be_a_property_reference);
26558
26559
return booleanType;
26559
26560
}
@@ -36174,10 +36175,10 @@ namespace ts {
36174
36175
}
36175
36176
36176
36177
function isSimpleLiteralEnumReference(expr: Expression) {
36177
- if (
36178
- (isPropertyAccessExpression( expr) || (isElementAccessExpression(expr) && isStringOrNumberLiteralExpression(expr.argumentExpression))) &&
36179
- isEntityNameExpression( expr.expression)
36180
- ) return !!(checkExpressionCached(expr).flags & TypeFlags.EnumLiteral);
36178
+ if ((isPropertyAccessExpression(expr) || (isElementAccessExpression(expr) && isStringOrNumberLiteralExpression(expr.argumentExpression))) &&
36179
+ isEntityNameExpression( expr.expression)) {
36180
+ return !!(checkExpressionCached( expr).flags & TypeFlags.EnumLiteral);
36181
+ }
36181
36182
}
36182
36183
36183
36184
function checkAmbientInitializer(node: VariableDeclaration | PropertyDeclaration | PropertySignature) {
0 commit comments