Make goto def jump to labels across function boundries

This commit is contained in:
Mohamed Hegazy
2014-08-01 17:11:41 -07:00
parent 8606873db6
commit 41b7eb25a3
2 changed files with 8 additions and 23 deletions

View File

@@ -1865,28 +1865,12 @@ module ts {
/// Goto definition
function getDefinitionAtPosition(filename: string, position: number): DefinitionInfo[]{
function getTargetLabel(statement: BreakOrContinueStatement, labelName: string): Identifier {
var current = statement.parent;
while (current) {
switch (current.kind) {
case SyntaxKind.FunctionDeclaration:
case SyntaxKind.Method:
case SyntaxKind.Constructor:
case SyntaxKind.GetAccessor:
case SyntaxKind.SetAccessor:
case SyntaxKind.FunctionExpression:
case SyntaxKind.ArrowFunction:
case SyntaxKind.ModuleDeclaration:
case SyntaxKind.ClassDeclaration:
// Label targets cannot be across function boundaries, so do not walk any further
return undefined;
case SyntaxKind.LabelledStatement:
if ((<LabelledStatement>current).label.text === labelName) {
return (<LabelledStatement>current).label;
}
break;
function getTargetLabel(node: Node, labelName: string): Identifier {
while (node) {
if (node.kind === SyntaxKind.LabelledStatement && (<LabelledStatement>node).label.text === labelName) {
return (<LabelledStatement>node).label;
}
current = current.parent;
node = node.parent;
}
return undefined;
}

View File

@@ -17,9 +17,10 @@ goTo.marker('2');
goTo.definition();
verify.caretAtMarker('label2Definition');
// no labels accross function bounderies
// labels accross function bounderies
goTo.marker('3');
verify.not.definitionLocationExists();
goTo.definition();
verify.caretAtMarker('label1Definition');
// undefined label
goTo.marker('4');