function spanInSourceFileAtLocation(sourceFile, position) {
            // Cannot set breakpoint in dts file
            if (sourceFile.flags & 4096 /* DeclarationFile */) {
                return undefined;
            }
            var tokenAtLocation = ts.getTokenAtPosition(sourceFile, position);
            var lineOfPosition = sourceFile.getLineAndCharacterOfPosition(position).line;
            if (sourceFile.getLineAndCharacterOfPosition(tokenAtLocation.getStart()).line > lineOfPosition) {
                // Get previous token if the token is returned starts on new line
                // eg: let x =10; |--- cursor is here
                //     let y = 10; 
                // token at position will return let keyword on second line as the token but we would like to use 
                // token on same line if trailing trivia (comments or white spaces on same line) part of the last token on that line
                tokenAtLocation = ts.findPrecedingToken(tokenAtLocation.pos, sourceFile);
                // Its a blank line
                if (!tokenAtLocation || sourceFile.getLineAndCharacterOfPosition(tokenAtLocation.getEnd()).line !== lineOfPosition) {
                    return undefined;
                }
            }
            // Cannot set breakpoint in ambient declarations
            if (ts.isInAmbientContext(tokenAtLocation)) {
                return undefined;
            }
            // Get the span in the node based on its syntax
            return spanInNode(tokenAtLocation);
            function textSpan(startNode, endNode) {
                return ts.createTextSpanFromBounds(startNode.getStart(), (endNode || startNode).getEnd());
            }
            function spanInNodeIfStartsOnSameLine(node, otherwiseOnNode) {
                if (node && lineOfPosition === sourceFile.getLineAndCharacterOfPosition(node.getStart()).line) {
                    return spanInNode(node);
                }
                return spanInNode(otherwiseOnNode);
            }
            function spanInPreviousNode(node) {
                return spanInNode(ts.findPrecedingToken(node.pos, sourceFile));
            }
            function spanInNextNode(node) {
                return spanInNode(ts.findNextToken(node, node.parent));
            }
            function spanInNode(node) {
                if (node) {
                    if (ts.isExpression(node)) {
                        if (node.parent.kind === 197 /* DoStatement */) {
                            // Set span as if on while keyword
                            return spanInPreviousNode(node);
                        }
                        if (node.parent.kind === 199 /* ForStatement */) {
                            // For now lets set the span on this expression, fix it later
                            return textSpan(node);
                        }
                        if (node.parent.kind === 181 /* BinaryExpression */ && node.parent.operatorToken.kind === 24 /* CommaToken */) {
                            // if this is comma expression, the breakpoint is possible in this expression
                            return textSpan(node);
                        }
                        if (node.parent.kind === 174 /* ArrowFunction */ && node.parent.body === node) {
                            // If this is body of arrow function, it is allowed to have the breakpoint
                            return textSpan(node);
                        }
                    }
                    switch (node.kind) {
                        case 193 /* VariableStatement */:
                            // Span on first variable declaration
                            return spanInVariableDeclaration(node.declarationList.declarations[0]);
                        case 211 /* VariableDeclaration */:
                        case 141 /* PropertyDeclaration */:
                        case 140 /* PropertySignature */:
                            return spanInVariableDeclaration(node);
                        case 138 /* Parameter */:
                            return spanInParameterDeclaration(node);
                        case 213 /* FunctionDeclaration */:
                        case 143 /* MethodDeclaration */:
                        case 142 /* MethodSignature */:
                        case 145 /* GetAccessor */:
                        case 146 /* SetAccessor */:
                        case 144 /* Constructor */:
                        case 173 /* FunctionExpression */:
                        case 174 /* ArrowFunction */:
                            return spanInFunctionDeclaration(node);
                        case 192 /* Block */:
                            if (ts.isFunctionBlock(node)) {
                                return spanInFunctionBlock(node);
                            }
                        // Fall through
                        case 219 /* ModuleBlock */:
                            return spanInBlock(node);
                        case 244 /* CatchClause */:
                            return spanInBlock(node.block);
                        case 195 /* ExpressionStatement */:
                            // span on the expression
                            return textSpan(node.expression);
                        case 204 /* ReturnStatement */:
                            // span on return keyword and expression if present
                            return textSpan(node.getChildAt(0), node.expression);
                        case 198 /* WhileStatement */:
                            // Span on while(...)
                            return textSpan(node, ts.findNextToken(node.expression, node));
                        case 197 /* DoStatement */:
                            // span in statement of the do statement
                            return spanInNode(node.statement);
                        case 210 /* DebuggerStatement */:
                            // span on debugger keyword
                            return textSpan(node.getChildAt(0));
                        case 196 /* IfStatement */:
                            // set on if(..) span
                            return textSpan(node, ts.findNextToken(node.expression, node));
                        case 207 /* LabeledStatement */:
                            // span in statement
                            return spanInNode(node.statement);
                        case 203 /* BreakStatement */:
                        case 202 /* ContinueStatement */:
                            // On break or continue keyword and label if present
                            return textSpan(node.getChildAt(0), node.label);
                        case 199 /* ForStatement */:
                            return spanInForStatement(node);
                        case 200 /* ForInStatement */:
                        case 201 /* ForOfStatement */:
                            // span on for (a in ...)
                            return textSpan(node, ts.findNextToken(node.expression, node));
                        case 206 /* SwitchStatement */:
                            // span on switch(...)
                            return textSpan(node, ts.findNextToken(node.expression, node));
                        case 241 /* CaseClause */:
                        case 242 /* DefaultClause */:
                            // span in first statement of the clause
                            return spanInNode(node.statements[0]);
                        case 209 /* TryStatement */:
                            // span in try block
                            return spanInBlock(node.tryBlock);
                        case 208 /* ThrowStatement */:
                            // span in throw ...
                            return textSpan(node, node.expression);
                        case 227 /* ExportAssignment */:
                            // span on export = id
                            return textSpan(node, node.expression);
                        case 221 /* ImportEqualsDeclaration */:
                            // import statement without including semicolon
                            return textSpan(node, node.moduleReference);
                        case 222 /* ImportDeclaration */:
                            // import statement without including semicolon
                            return textSpan(node, node.moduleSpecifier);
                        case 228 /* ExportDeclaration */:
                            // import statement without including semicolon
                            return textSpan(node, node.moduleSpecifier);
                        case 218 /* ModuleDeclaration */:
                            // span on complete module if it is instantiated
                            if (ts.getModuleInstanceState(node) !== 1 /* Instantiated */) {
                                return undefined;
                            }
                        case 214 /* ClassDeclaration */:
                        case 217 /* EnumDeclaration */:
                        case 247 /* EnumMember */:
                        case 168 /* CallExpression */:
                        case 169 /* NewExpression */:
                            // span on complete node
                            return textSpan(node);
                        case 205 /* WithStatement */:
                            // span in statement
                            return spanInNode(node.statement);
                        // No breakpoint in interface, type alias
                        case 215 /* InterfaceDeclaration */:
                        case 216 /* TypeAliasDeclaration */:
                            return undefined;
                        // Tokens:
                        case 23 /* SemicolonToken */:
                        case 1 /* EndOfFileToken */:
                            return spanInNodeIfStartsOnSameLine(ts.findPrecedingToken(node.pos, sourceFile));
                        case 24 /* CommaToken */:
                            return spanInPreviousNode(node);
                        case 15 /* OpenBraceToken */:
                            return spanInOpenBraceToken(node);
                        case 16 /* CloseBraceToken */:
                            return spanInCloseBraceToken(node);
                        case 17 /* OpenParenToken */:
                            return spanInOpenParenToken(node);
                        case 18 /* CloseParenToken */:
                            return spanInCloseParenToken(node);
                        case 54 /* ColonToken */:
                            return spanInColonToken(node);
                        case 27 /* GreaterThanToken */:
                        case 25 /* LessThanToken */:
                            return spanInGreaterThanOrLessThanToken(node);
                        // Keywords:
                        case 104 /* WhileKeyword */:
                            return spanInWhileKeyword(node);
                        case 80 /* ElseKeyword */:
                        case 72 /* CatchKeyword */:
                        case 85 /* FinallyKeyword */:
                            return spanInNextNode(node);
                        default:
                            // If this is name of property assignment, set breakpoint in the initializer
                            if (node.parent.kind === 245 /* PropertyAssignment */ && node.parent.name === node) {
                                return spanInNode(node.parent.initializer);
                            }
                            // Breakpoint in type assertion goes to its operand
                            if (node.parent.kind === 171 /* TypeAssertionExpression */ && node.parent.type === node) {
                                return spanInNode(node.parent.expression);
                            }
                            // return type of function go to previous token
                            if (ts.isFunctionLike(node.parent) && node.parent.type === node) {
                                return spanInPreviousNode(node);
                            }
                            // Default go to parent to set the breakpoint
                            return spanInNode(node.parent);
                    }
                }
                function spanInVariableDeclaration(variableDeclaration) {
                    // If declaration of for in statement, just set the span in parent
                    if (variableDeclaration.parent.parent.kind === 200 /* ForInStatement */ ||
                        variableDeclaration.parent.parent.kind === 201 /* ForOfStatement */) {
                        return spanInNode(variableDeclaration.parent.parent);
                    }
                    var isParentVariableStatement = variableDeclaration.parent.parent.kind === 193 /* VariableStatement */;
                    var isDeclarationOfForStatement = variableDeclaration.parent.parent.kind === 199 /* ForStatement */ && ts.contains(variableDeclaration.parent.parent.initializer.declarations, variableDeclaration);
                    var declarations = isParentVariableStatement
                        ? variableDeclaration.parent.parent.declarationList.declarations
                        : isDeclarationOfForStatement
                            ? variableDeclaration.parent.parent.initializer.declarations
                            : undefined;
                    // Breakpoint is possible in variableDeclaration only if there is initialization
                    if (variableDeclaration.initializer || (variableDeclaration.flags & 2 /* Export */)) {
                        if (declarations && declarations[0] === variableDeclaration) {
                            if (isParentVariableStatement) {
                                // First declaration - include let keyword
                                return textSpan(variableDeclaration.parent, variableDeclaration);
                            }
                            else {
                                ts.Debug.assert(isDeclarationOfForStatement);
                                // Include let keyword from for statement declarations in the span
                                return textSpan(ts.findPrecedingToken(variableDeclaration.pos, sourceFile, variableDeclaration.parent), variableDeclaration);
                            }
                        }
                        else {
                            // Span only on this declaration
                            return textSpan(variableDeclaration);
                        }
                    }
                    else if (declarations && declarations[0] !== variableDeclaration) {
                        // If we cant set breakpoint on this declaration, set it on previous one
                        var indexOfCurrentDeclaration = ts.indexOf(declarations, variableDeclaration);
                        return spanInVariableDeclaration(declarations[indexOfCurrentDeclaration - 1]);
                    }
                }
                function canHaveSpanInParameterDeclaration(parameter) {
                    // Breakpoint is possible on parameter only if it has initializer, is a rest parameter, or has public or private modifier
                    return !!parameter.initializer || parameter.dotDotDotToken !== undefined ||
                        !!(parameter.flags & 8 /* Public */) || !!(parameter.flags & 16 /* Private */);
                }
                function spanInParameterDeclaration(parameter) {
                    if (canHaveSpanInParameterDeclaration(parameter)) {
                        return textSpan(parameter);
                    }
                    else {
                        var functionDeclaration = parameter.parent;
                        var indexOfParameter = ts.indexOf(functionDeclaration.parameters, parameter);
                        if (indexOfParameter) {
                            // Not a first parameter, go to previous parameter
                            return spanInParameterDeclaration(functionDeclaration.parameters[indexOfParameter - 1]);
                        }
                        else {
                            // Set breakpoint in the function declaration body
                            return spanInNode(functionDeclaration.body);
                        }
                    }
                }
                function canFunctionHaveSpanInWholeDeclaration(functionDeclaration) {
                    return !!(functionDeclaration.flags & 2 /* Export */) ||
                        (functionDeclaration.parent.kind === 214 /* ClassDeclaration */ && functionDeclaration.kind !== 144 /* Constructor */);
                }
                function spanInFunctionDeclaration(functionDeclaration) {
                    // No breakpoints in the function signature
                    if (!functionDeclaration.body) {
                        return undefined;
                    }
                    if (canFunctionHaveSpanInWholeDeclaration(functionDeclaration)) {
                        // Set the span on whole function declaration
                        return textSpan(functionDeclaration);
                    }
                    // Set span in function body
                    return spanInNode(functionDeclaration.body);
                }
                function spanInFunctionBlock(block) {
                    var nodeForSpanInBlock = block.statements.length ? block.statements[0] : block.getLastToken();
                    if (canFunctionHaveSpanInWholeDeclaration(block.parent)) {
                        return spanInNodeIfStartsOnSameLine(block.parent, nodeForSpanInBlock);
                    }
                    return spanInNode(nodeForSpanInBlock);
                }
                function spanInBlock(block) {
                    switch (block.parent.kind) {
                        case 218 /* ModuleDeclaration */:
                            if (ts.getModuleInstanceState(block.parent) !== 1 /* Instantiated */) {
                                return undefined;
                            }
                        // Set on parent if on same line otherwise on first statement
                        case 198 /* WhileStatement */:
                        case 196 /* IfStatement */:
                        case 200 /* ForInStatement */:
                        case 201 /* ForOfStatement */:
                            return spanInNodeIfStartsOnSameLine(block.parent, block.statements[0]);
                        // Set span on previous token if it starts on same line otherwise on the first statement of the block
                        case 199 /* ForStatement */:
                            return spanInNodeIfStartsOnSameLine(ts.findPrecedingToken(block.pos, sourceFile, block.parent), block.statements[0]);
                    }
                    // Default action is to set on first statement
                    return spanInNode(block.statements[0]);
                }
                function spanInForStatement(forStatement) {
                    if (forStatement.initializer) {
                        if (forStatement.initializer.kind === 212 /* VariableDeclarationList */) {
                            var variableDeclarationList = forStatement.initializer;
                            if (variableDeclarationList.declarations.length > 0) {
                                return spanInNode(variableDeclarationList.declarations[0]);
                            }
                        }
                        else {
                            return spanInNode(forStatement.initializer);
                        }
                    }
                    if (forStatement.condition) {
                        return textSpan(forStatement.condition);
                    }
                    if (forStatement.incrementor) {
                        return textSpan(forStatement.incrementor);
                    }
                }
                // Tokens:
                function spanInOpenBraceToken(node) {
                    switch (node.parent.kind) {
                        case 217 /* EnumDeclaration */:
                            var enumDeclaration = node.parent;
                            return spanInNodeIfStartsOnSameLine(ts.findPrecedingToken(node.pos, sourceFile, node.parent), enumDeclaration.members.length ? enumDeclaration.members[0] : enumDeclaration.getLastToken(sourceFile));
                        case 214 /* ClassDeclaration */:
                            var classDeclaration = node.parent;
                            return spanInNodeIfStartsOnSameLine(ts.findPrecedingToken(node.pos, sourceFile, node.parent), classDeclaration.members.length ? classDeclaration.members[0] : classDeclaration.getLastToken(sourceFile));
                        case 220 /* CaseBlock */:
                            return spanInNodeIfStartsOnSameLine(node.parent.parent, node.parent.clauses[0]);
                    }
                    // Default to parent node
                    return spanInNode(node.parent);
                }
                function spanInCloseBraceToken(node) {
                    switch (node.parent.kind) {
                        case 219 /* ModuleBlock */:
                            // If this is not instantiated module block no bp span
                            if (ts.getModuleInstanceState(node.parent.parent) !== 1 /* Instantiated */) {
                                return undefined;
                            }
                        case 217 /* EnumDeclaration */:
                        case 214 /* ClassDeclaration */:
                            // Span on close brace token
                            return textSpan(node);
                        case 192 /* Block */:
                            if (ts.isFunctionBlock(node.parent)) {
                                // Span on close brace token
                                return textSpan(node);
                            }
                        // fall through.
                        case 244 /* CatchClause */:
                            return spanInNode(ts.lastOrUndefined(node.parent.statements));
                        case 220 /* CaseBlock */:
                            // breakpoint in last statement of the last clause
                            var caseBlock = node.parent;
                            var lastClause = ts.lastOrUndefined(caseBlock.clauses);
                            if (lastClause) {
                                return spanInNode(ts.lastOrUndefined(lastClause.statements));
                            }
                            return undefined;
                        // Default to parent node
                        default:
                            return spanInNode(node.parent);
                    }
                }
                function spanInOpenParenToken(node) {
                    if (node.parent.kind === 197 /* DoStatement */) {
                        // Go to while keyword and do action instead
                        return spanInPreviousNode(node);
                    }
                    // Default to parent node
                    return spanInNode(node.parent);
                }
                function spanInCloseParenToken(node) {
                    // Is this close paren token of parameter list, set span in previous token
                    switch (node.parent.kind) {
                        case 173 /* FunctionExpression */:
                        case 213 /* FunctionDeclaration */:
                        case 174 /* ArrowFunction */:
                        case 143 /* MethodDeclaration */:
                        case 142 /* MethodSignature */:
                        case 145 /* GetAccessor */:
                        case 146 /* SetAccessor */:
                        case 144 /* Constructor */:
                        case 198 /* WhileStatement */:
                        case 197 /* DoStatement */:
                        case 199 /* ForStatement */:
                            return spanInPreviousNode(node);
                        // Default to parent node
                        default:
                            return spanInNode(node.parent);
                    }
                }
                function spanInColonToken(node) {
                    // Is this : specifying return annotation of the function declaration
                    if (ts.isFunctionLike(node.parent) || node.parent.kind === 245 /* PropertyAssignment */) {
                        return spanInPreviousNode(node);
                    }
                    return spanInNode(node.parent);
                }
                function spanInGreaterThanOrLessThanToken(node) {
                    if (node.parent.kind === 171 /* TypeAssertionExpression */) {
                        return spanInNode(node.parent.expression);
                    }
                    return spanInNode(node.parent);
                }
                function spanInWhileKeyword(node) {
                    if (node.parent.kind === 197 /* DoStatement */) {
                        // Set span on while expression
                        return textSpan(node, ts.findNextToken(node.parent.expression, node.parent));
                    }
                    // Default to parent node
                    return spanInNode(node.parent);
                }
            }
        }
Get the breakpoint span in given sourceFile