mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-14 10:55:15 -06:00
Enable new behavior only in --noImplicitThis mode
This commit is contained in:
parent
ee7b93c1a0
commit
21c43009a6
@ -11570,36 +11570,38 @@ namespace ts {
|
||||
}
|
||||
}
|
||||
}
|
||||
const containingLiteral = getContainingObjectLiteral(func);
|
||||
if (containingLiteral) {
|
||||
// We have an object literal method. Check if the containing object literal has a contextual type
|
||||
// that includes a ThisType<T>. If so, T is the contextual type for 'this'. We continue looking in
|
||||
// any directly enclosing object literals.
|
||||
const contextualType = getApparentTypeOfContextualType(containingLiteral);
|
||||
let literal = containingLiteral;
|
||||
let type = contextualType;
|
||||
while (type) {
|
||||
const thisType = getThisTypeFromContextualType(type);
|
||||
if (thisType) {
|
||||
return instantiateType(thisType, getContextualMapper(containingLiteral));
|
||||
if (compilerOptions.noImplicitThis) {
|
||||
const containingLiteral = getContainingObjectLiteral(func);
|
||||
if (containingLiteral) {
|
||||
// We have an object literal method. Check if the containing object literal has a contextual type
|
||||
// that includes a ThisType<T>. If so, T is the contextual type for 'this'. We continue looking in
|
||||
// any directly enclosing object literals.
|
||||
const contextualType = getApparentTypeOfContextualType(containingLiteral);
|
||||
let literal = containingLiteral;
|
||||
let type = contextualType;
|
||||
while (type) {
|
||||
const thisType = getThisTypeFromContextualType(type);
|
||||
if (thisType) {
|
||||
return instantiateType(thisType, getContextualMapper(containingLiteral));
|
||||
}
|
||||
if (literal.parent.kind !== SyntaxKind.PropertyAssignment) {
|
||||
break;
|
||||
}
|
||||
literal = <ObjectLiteralExpression>literal.parent.parent;
|
||||
type = getApparentTypeOfContextualType(literal);
|
||||
}
|
||||
if (literal.parent.kind !== SyntaxKind.PropertyAssignment) {
|
||||
break;
|
||||
}
|
||||
literal = <ObjectLiteralExpression>literal.parent.parent;
|
||||
type = getApparentTypeOfContextualType(literal);
|
||||
// There was no contextual ThisType<T> for the containing object literal, so the contextual type
|
||||
// for 'this' is the contextual type for the containing object literal or the type of the object
|
||||
// literal itself.
|
||||
return contextualType || checkExpressionCached(containingLiteral);
|
||||
}
|
||||
// There was no contextual ThisType<T> for the containing object literal, so the contextual type
|
||||
// for 'this' is the contextual type for the containing object literal or the type of the object
|
||||
// literal itself.
|
||||
return contextualType || checkExpressionCached(containingLiteral);
|
||||
}
|
||||
// In an assignment of the form 'obj.xxx = function(...)' or 'obj[xxx] = function(...)', the
|
||||
// contextual type for 'this' is 'obj'.
|
||||
if (func.parent.kind === SyntaxKind.BinaryExpression && (<BinaryExpression>func.parent).operatorToken.kind === SyntaxKind.EqualsToken) {
|
||||
const target = (<BinaryExpression>func.parent).left;
|
||||
if (target.kind === SyntaxKind.PropertyAccessExpression || target.kind === SyntaxKind.ElementAccessExpression) {
|
||||
return checkExpressionCached((<PropertyAccessExpression | ElementAccessExpression>target).expression);
|
||||
// In an assignment of the form 'obj.xxx = function(...)' or 'obj[xxx] = function(...)', the
|
||||
// contextual type for 'this' is 'obj'.
|
||||
if (func.parent.kind === SyntaxKind.BinaryExpression && (<BinaryExpression>func.parent).operatorToken.kind === SyntaxKind.EqualsToken) {
|
||||
const target = (<BinaryExpression>func.parent).left;
|
||||
if (target.kind === SyntaxKind.PropertyAccessExpression || target.kind === SyntaxKind.ElementAccessExpression) {
|
||||
return checkExpressionCached((<PropertyAccessExpression | ElementAccessExpression>target).expression);
|
||||
}
|
||||
}
|
||||
}
|
||||
return undefined;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user