mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-27 13:42:16 -05:00
Addressed CR feedback.
This commit is contained in:
@@ -3461,11 +3461,14 @@ module ts {
|
||||
}
|
||||
|
||||
function checkThisExpression(node: Node): Type {
|
||||
var container = getThisContainerOrArrowFunction(node);
|
||||
// Stop at the first arrow function so that we can
|
||||
// tell whether 'this' needs to be captured.
|
||||
var container = getThisContainer(node, /* includeArrowFunctions */ true);
|
||||
var needToCaptureLexicalThis = false;
|
||||
// skip arrow functions
|
||||
while (container.kind === SyntaxKind.ArrowFunction) {
|
||||
container = getThisContainerOrArrowFunction(container);
|
||||
|
||||
// Now skip arrow functions to get the "real" owner of 'this'.
|
||||
if (container.kind === SyntaxKind.ArrowFunction) {
|
||||
container = getThisContainer(container, /* includeArrowFunctions */ false);
|
||||
needToCaptureLexicalThis = true;
|
||||
}
|
||||
|
||||
|
||||
@@ -407,13 +407,18 @@ module ts {
|
||||
}
|
||||
}
|
||||
|
||||
export function getThisContainerOrArrowFunction(node: Node): Node {
|
||||
export function getThisContainer(node: Node, includeArrowFunctions: boolean): Node {
|
||||
while (true) {
|
||||
node = node.parent;
|
||||
if (!node) {
|
||||
return node;
|
||||
}
|
||||
switch (node.kind) {
|
||||
case SyntaxKind.ArrowFunction:
|
||||
if (!includeArrowFunctions) {
|
||||
continue;
|
||||
}
|
||||
// Fall through
|
||||
case SyntaxKind.FunctionDeclaration:
|
||||
case SyntaxKind.FunctionExpression:
|
||||
case SyntaxKind.ModuleDeclaration:
|
||||
@@ -424,20 +429,11 @@ module ts {
|
||||
case SyntaxKind.SetAccessor:
|
||||
case SyntaxKind.EnumDeclaration:
|
||||
case SyntaxKind.SourceFile:
|
||||
case SyntaxKind.ArrowFunction:
|
||||
return node;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export function getThisContainer(node: Node): Node {
|
||||
do {
|
||||
node = getThisContainerOrArrowFunction(node);
|
||||
} while (node.kind === SyntaxKind.ArrowFunction);
|
||||
|
||||
return node;
|
||||
}
|
||||
|
||||
export function hasRestParameters(s: SignatureDeclaration): boolean {
|
||||
return s.parameters.length > 0 && (s.parameters[s.parameters.length - 1].flags & NodeFlags.Rest) !== 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user