mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-06-11 20:37:46 -05:00
Make goto def jump to labels across function boundries
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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');
|
||||
|
||||
Reference in New Issue
Block a user