From a410133039d5c5f91bcc8ee659b29def63223ae8 Mon Sep 17 00:00:00 2001 From: Sheetal Nandi Date: Tue, 21 Oct 2014 12:12:43 -0700 Subject: [PATCH] Some reorganizing --- src/services/breakpoints.ts | 141 ++++++++++-------------------------- 1 file changed, 40 insertions(+), 101 deletions(-) diff --git a/src/services/breakpoints.ts b/src/services/breakpoints.ts index 15140f6c64a..95d87171c79 100644 --- a/src/services/breakpoints.ts +++ b/src/services/breakpoints.ts @@ -82,7 +82,8 @@ module ts.BreakpointResolver { switch (node.kind) { case SyntaxKind.VariableStatement: - return spanInVariableStatement(node); + // Span on first variable declaration + return spanInVariableDeclaration((node).declarations[0]); case SyntaxKind.VariableDeclaration: case SyntaxKind.Property: @@ -111,71 +112,87 @@ module ts.BreakpointResolver { return spanInBlock(node); case SyntaxKind.ExpressionStatement: - return spanInExpressionStatement(node); + // span on the expression + return textSpan((node).expression); case SyntaxKind.ReturnStatement: - return spanInReturnStatement(node); + // span on return keyword and expression if present + return textSpan(node.getChildAt(0), (node).expression); case SyntaxKind.WhileStatement: - return spanInWhileStatement(node); + // Span on while(...) + return textSpan(node, findNextToken((node).expression, node)); case SyntaxKind.DoStatement: - return spanInDoStatement(node); + // span in statement of the do statement + return spanInNode((node).statement); case SyntaxKind.DebuggerStatement: - return spanInDebuggerStatement(node); + // span on debugger keyword + return textSpan(node.getChildAt(0)); case SyntaxKind.IfStatement: - return spanInIfStatement(node); + // set on if(..) span + return textSpan(node, findNextToken((node).expression, node)); case SyntaxKind.LabeledStatement: - return spanInLabeledStatement(node); + // span in statement + return spanInNode((node).statement); case SyntaxKind.BreakStatement: case SyntaxKind.ContinueStatement: - return spanInBreakOrContinueStatement(node); + // On break or continue keyword and label if present + return textSpan(node.getChildAt(0), (node).label); case SyntaxKind.ForStatement: return spanInForStatement(node); case SyntaxKind.ForInStatement: - return spanInForInStatement(node); + // span on for (a in ...) + return textSpan(node, findNextToken((node).expression, node)); case SyntaxKind.SwitchStatement: - return spanInSwitchStatement(node); + // span on switch(...) + return textSpan(node, findNextToken((node).expression, node)); case SyntaxKind.CaseClause: case SyntaxKind.DefaultClause: - return spanInCaseOrDefaultClause(node); + // span in first statement of the clause + return spanInNode((node).statements[0]); case SyntaxKind.TryStatement: - return spanInTryStatement(node); + // span in try block + return spanInBlock((node).tryBlock); case SyntaxKind.ThrowStatement: - return spanInThrowStatement(node); + // span in throw ... + return textSpan(node, (node).expression); case SyntaxKind.ExportAssignment: - return spanInExportAssignment(node); + // span on export = id + return textSpan(node, (node).exportName); case SyntaxKind.ImportDeclaration: - return spanInImportDeclaration(node); + // import statement without including semicolon + return textSpan(node, (node).entityName || (node).externalModuleName); case SyntaxKind.EnumDeclaration: case SyntaxKind.EnumMember: + case SyntaxKind.CallExpression: + case SyntaxKind.NewExpression: + // span on complete node return textSpan(node); case SyntaxKind.ModuleDeclaration: - return spanInModuleDeclaration(node); + // span in module body + return spanInNode((node).body); case SyntaxKind.ClassDeclaration: return spanInClassDeclaration(node); - case SyntaxKind.CallExpression: - case SyntaxKind.NewExpression: - return spanInCallOrNewExpression(node); - case SyntaxKind.WithStatement: - return spanInWithStatement(node); + // span in statement + return spanInNode((node).statement); // No breakpoint in interface case SyntaxKind.InterfaceDeclaration: @@ -241,7 +258,7 @@ module ts.BreakpointResolver { function spanInVariableDeclaration(variableDeclaration: VariableDeclaration): TypeScript.TextSpan { // If declaration of for in statement, just set the span in parent if (variableDeclaration.parent.kind === SyntaxKind.ForInStatement) { - return spanInForInStatement(variableDeclaration.parent); + return spanInNode(variableDeclaration.parent); } var isParentVariableStatement = variableDeclaration.parent.kind === SyntaxKind.VariableStatement; @@ -277,10 +294,6 @@ module ts.BreakpointResolver { } } - function spanInVariableStatement(variableStatement: VariableStatement): TypeScript.TextSpan { - return spanInVariableDeclaration(variableStatement.declarations[0]); - } - function canHaveSpanInParameterDeclaration(parameter: ParameterDeclaration): boolean { // Breakpoint is possible on parameter only if it has initializer, is a rest parameter, or has public or private modifier return !!parameter.initializer || !!(parameter.flags & NodeFlags.Rest) || @@ -351,40 +364,6 @@ module ts.BreakpointResolver { return spanInFirstStatementOfBlock(block); } - function spanInExpressionStatement(expressionStatement: ExpressionStatement): TypeScript.TextSpan { - return textSpan(expressionStatement.expression); - } - - function spanInReturnStatement(returnStatement: ReturnStatement): TypeScript.TextSpan { - return textSpan(returnStatement.getChildAt(0, sourceFile), returnStatement.expression); - } - - function spanInWhileStatement(whileStatement: WhileStatement): TypeScript.TextSpan { - return textSpan(whileStatement, findNextToken(whileStatement.expression, whileStatement)); - } - - function spanInDoStatement(doStatement: DoStatement): TypeScript.TextSpan { - return spanInNode(doStatement.statement); - } - - function spanInDebuggerStatement(node: Node): TypeScript.TextSpan { - // Set breakpoint on debugger keyword - return textSpan(node.getChildAt(0, sourceFile)); - } - - function spanInIfStatement(ifStatement: IfStatement): TypeScript.TextSpan { - // set on if(..) span - return textSpan(ifStatement, findNextToken(ifStatement.expression, ifStatement)); - } - - function spanInLabeledStatement(labeledStatement: LabeledStatement): TypeScript.TextSpan { - return spanInNode(labeledStatement.statement); - } - - function spanInBreakOrContinueStatement(breakOrContinueStatement: BreakOrContinueStatement): TypeScript.TextSpan { - return textSpan(breakOrContinueStatement, breakOrContinueStatement.label || breakOrContinueStatement.getChildAt(0)); - } - function spanInForStatement(forStatement: ForStatement): TypeScript.TextSpan { if (forStatement.declarations) { return spanInNode(forStatement.declarations[0]); @@ -401,38 +380,6 @@ module ts.BreakpointResolver { } } - function spanInForInStatement(forInStatement: ForInStatement): TypeScript.TextSpan { - return textSpan(forInStatement, findNextToken(forInStatement.expression, forInStatement)); - } - - function spanInSwitchStatement(switchStatement: SwitchStatement): TypeScript.TextSpan { - return textSpan(switchStatement, findNextToken(switchStatement.expression, switchStatement)); - } - - function spanInCaseOrDefaultClause(caseOrDefaultClause: CaseOrDefaultClause): TypeScript.TextSpan { - return spanInNode(caseOrDefaultClause.statements[0]); - } - - function spanInTryStatement(tryStatement: TryStatement): TypeScript.TextSpan { - return spanInBlock(tryStatement.tryBlock); - } - - function spanInThrowStatement(throwStatement: ThrowStatement): TypeScript.TextSpan { - return textSpan(throwStatement, throwStatement.expression); - } - - function spanInExportAssignment(exportAssignment: ExportAssignment): TypeScript.TextSpan { - return textSpan(exportAssignment, exportAssignment.exportName); - } - - function spanInImportDeclaration(importDeclaration: ImportDeclaration): TypeScript.TextSpan { - return textSpan(importDeclaration, importDeclaration.entityName || importDeclaration.externalModuleName); - } - - function spanInModuleDeclaration(moduleDeclaration: ModuleDeclaration): TypeScript.TextSpan { - return spanInNode(moduleDeclaration.body); - } - function spanInClassDeclaration(classDeclaration: ClassDeclaration): TypeScript.TextSpan { if (classDeclaration.members.length) { return spanInNode(classDeclaration.members[0]); @@ -441,14 +388,6 @@ module ts.BreakpointResolver { return spanInNode(classDeclaration.getLastToken()); } - function spanInCallOrNewExpression(callOrNewExpression: CallExpression): TypeScript.TextSpan { - return textSpan(callOrNewExpression); - } - - function spanInWithStatement(withStatement: WithStatement): TypeScript.TextSpan { - return spanInNode(withStatement.statement); - } - // Tokens: function spanInOpenBraceToken(node: Node): TypeScript.TextSpan { switch (node.parent.kind) {