demo/typescript.js
function getReferencesInNode(container, searchSymbol, searchText, searchLocation, searchMeaning, findInStrings, findInComments, result, symbolToIndex) {
                var sourceFile = container.getSourceFile();
                var tripleSlashDirectivePrefixRegex = /^\/\/\/\s*</;
                var possiblePositions = getPossibleSymbolReferencePositions(sourceFile, searchText, container.getStart(), container.getEnd());
                if (possiblePositions.length) {
                    // Build the set of symbols to search for, initially it has only the current symbol
                    var searchSymbols = populateSearchSymbolSet(searchSymbol, searchLocation);
                    ts.forEach(possiblePositions, function (position) {
                        cancellationToken.throwIfCancellationRequested();
                        var referenceLocation = ts.getTouchingPropertyName(sourceFile, position);
                        if (!isValidReferencePosition(referenceLocation, searchText)) {
                            // This wasn't the start of a token.  Check to see if it might be a
                            // match in a comment or string if that's what the caller is asking
                            // for.
                            if ((findInStrings && ts.isInString(sourceFile, position)) ||
                                (findInComments && isInNonReferenceComment(sourceFile, position))) {
                                // In the case where we're looking inside comments/strings, we don't have
                                // an actual definition.  So just use 'undefined' here.  Features like
                                // 'Rename' won't care (as they ignore the definitions), and features like
                                // 'FindReferences' will just filter out these results.
                                result.push({
                                    definition: undefined,
                                    references: [{
                                        fileName: sourceFile.fileName,
                                        textSpan: ts.createTextSpan(position, searchText.length),
                                        isWriteAccess: false
                                    }]
                                });
                            }
                            return;
                        }
                        if (!(getMeaningFromLocation(referenceLocation) & searchMeaning)) {
                            return;
                        }
                        var referenceSymbol = typeChecker.getSymbolAtLocation(referenceLocation);
                        if (referenceSymbol) {
                            var referenceSymbolDeclaration = referenceSymbol.valueDeclaration;
                            var shorthandValueSymbol = typeChecker.getShorthandAssignmentValueSymbol(referenceSymbolDeclaration);
                            var relatedSymbol = getRelatedSymbol(searchSymbols, referenceSymbol, referenceLocation);
                            if (relatedSymbol) {
                                var referencedSymbol = getReferencedSymbol(relatedSymbol);
                                referencedSymbol.references.push(getReferenceEntryFromNode(referenceLocation));
                            }
                            else if (!(referenceSymbol.flags & 67108864 /* Transient */) && searchSymbols.indexOf(shorthandValueSymbol) >= 0) {
                                var referencedSymbol = getReferencedSymbol(shorthandValueSymbol);
                                referencedSymbol.references.push(getReferenceEntryFromNode(referenceSymbolDeclaration.name));
                            }
                        }
                    });
                }
                return;
                function getReferencedSymbol(symbol) {
                    var symbolId = ts.getSymbolId(symbol);
                    var index = symbolToIndex[symbolId];
                    if (index === undefined) {
                        index = result.length;
                        symbolToIndex[symbolId] = index;
                        result.push({
                            definition: getDefinition(symbol),
                            references: []
                        });
                    }
                    return result[index];
                }
                function isInNonReferenceComment(sourceFile, position) {
                    return ts.isInCommentHelper(sourceFile, position, isNonReferenceComment);
                    function isNonReferenceComment(c) {
                        var commentText = sourceFile.text.substring(c.pos, c.end);
                        return !tripleSlashDirectivePrefixRegex.test(commentText);
                    }
                }
            }
function getReferencesInNode(container, searchSymbol, searchText, searchLocation, searchMeaning, findInStrings, findInComments, result, symbolToIndex) {
                var sourceFile = container.getSourceFile();
                var tripleSlashDirectivePrefixRegex = /^\/\/\/\s*</;
                var possiblePositions = getPossibleSymbolReferencePositions(sourceFile, searchText, container.getStart(), container.getEnd());
                if (possiblePositions.length) {
                    // Build the set of symbols to search for, initially it has only the current symbol
                    var searchSymbols = populateSearchSymbolSet(searchSymbol, searchLocation);
                    ts.forEach(possiblePositions, function (position) {
                        cancellationToken.throwIfCancellationRequested();
                        var referenceLocation = ts.getTouchingPropertyName(sourceFile, position);
                        if (!isValidReferencePosition(referenceLocation, searchText)) {
                            // This wasn't the start of a token.  Check to see if it might be a
                            // match in a comment or string if that's what the caller is asking
                            // for.
                            if ((findInStrings && ts.isInString(sourceFile, position)) ||
                                (findInComments && isInNonReferenceComment(sourceFile, position))) {
                                // In the case where we're looking inside comments/strings, we don't have
                                // an actual definition.  So just use 'undefined' here.  Features like
                                // 'Rename' won't care (as they ignore the definitions), and features like
                                // 'FindReferences' will just filter out these results.
                                result.push({
                                    definition: undefined,
                                    references: [{
                                        fileName: sourceFile.fileName,
                                        textSpan: ts.createTextSpan(position, searchText.length),
                                        isWriteAccess: false
                                    }]
                                });
                            }
                            return;
                        }
                        if (!(getMeaningFromLocation(referenceLocation) & searchMeaning)) {
                            return;
                        }
                        var referenceSymbol = typeChecker.getSymbolAtLocation(referenceLocation);
                        if (referenceSymbol) {
                            var referenceSymbolDeclaration = referenceSymbol.valueDeclaration;
                            var shorthandValueSymbol = typeChecker.getShorthandAssignmentValueSymbol(referenceSymbolDeclaration);
                            var relatedSymbol = getRelatedSymbol(searchSymbols, referenceSymbol, referenceLocation);
                            if (relatedSymbol) {
                                var referencedSymbol = getReferencedSymbol(relatedSymbol);
                                referencedSymbol.references.push(getReferenceEntryFromNode(referenceLocation));
                            }
                            else if (!(referenceSymbol.flags & 67108864 /* Transient */) && searchSymbols.indexOf(shorthandValueSymbol) >= 0) {
                                var referencedSymbol = getReferencedSymbol(shorthandValueSymbol);
                                referencedSymbol.references.push(getReferenceEntryFromNode(referenceSymbolDeclaration.name));
                            }
                        }
                    });
                }
                return;
                function getReferencedSymbol(symbol) {
                    var symbolId = ts.getSymbolId(symbol);
                    var index = symbolToIndex[symbolId];
                    if (index === undefined) {
                        index = result.length;
                        symbolToIndex[symbolId] = index;
                        result.push({
                            definition: getDefinition(symbol),
                            references: []
                        });
                    }
                    return result[index];
                }
                function isInNonReferenceComment(sourceFile, position) {
                    return ts.isInCommentHelper(sourceFile, position, isNonReferenceComment);
                    function isNonReferenceComment(c) {
                        var commentText = sourceFile.text.substring(c.pos, c.end);
                        return !tripleSlashDirectivePrefixRegex.test(commentText);
                    }
                }
            }
function getReferencesInNode ( container , searchSymbol , searchText , searchLocation , searchMeaning , findInStrings , findInComments , result , symbolToIndex ) { var sourceFile = container . getSourceFile ( ) ; var tripleSlashDirectivePrefixRegex = / ^\/\/\/\s*< / ; var possiblePositions = getPossibleSymbolReferencePositions ( sourceFile , searchText , container . getStart ( ) , container . getEnd ( ) ) ; if ( possiblePositions . length ) { // Build the set of symbols to search for, initially it has only the current symbol var searchSymbols = populateSearchSymbolSet ( searchSymbol , searchLocation ) ; ts . forEach ( possiblePositions , function ( position ) { cancellationToken . throwIfCancellationRequested ( ) ; var referenceLocation = ts . getTouchingPropertyName ( sourceFile , position ) ; if ( ! isValidReferencePosition ( referenceLocation , searchText ) ) { // This wasn't the start of a token.  Check to see if it might be a // match in a comment or string if that's what the caller is asking // for. if ( ( findInStrings && ts . isInString ( sourceFile , position ) ) || ( findInComments && isInNonReferenceComment ( sourceFile , position ) ) ) { // In the case where we're looking inside comments/strings, we don't have // an actual definition.  So just use 'undefined' here.  Features like // 'Rename' won't care (as they ignore the definitions), and features like // 'FindReferences' will just filter out these results. result . push ( { definition : undefined , references : [ { fileName : sourceFile . fileName , textSpan : ts . createTextSpan ( position , searchText . length ) , isWriteAccess : false } ] } ) ; } return ; } if ( ! ( getMeaningFromLocation ( referenceLocation ) & searchMeaning ) ) { return ; } var referenceSymbol = typeChecker . getSymbolAtLocation ( referenceLocation ) ; if ( referenceSymbol ) { var referenceSymbolDeclaration = referenceSymbol . valueDeclaration ; var shorthandValueSymbol = typeChecker . getShorthandAssignmentValueSymbol ( referenceSymbolDeclaration ) ; var relatedSymbol = getRelatedSymbol ( searchSymbols , referenceSymbol , referenceLocation ) ; if ( relatedSymbol ) { var referencedSymbol = getReferencedSymbol ( relatedSymbol ) ; referencedSymbol . references . push ( getReferenceEntryFromNode ( referenceLocation ) ) ; } else if ( ! ( referenceSymbol . flags & 67108864 /* Transient */ ) && searchSymbols . indexOf ( shorthandValueSymbol ) >= 0 ) { var referencedSymbol = getReferencedSymbol ( shorthandValueSymbol ) ; referencedSymbol . references . push ( getReferenceEntryFromNode ( referenceSymbolDeclaration . name ) ) ; } } } ) ; } return ; function getReferencedSymbol ( symbol ) { var symbolId = ts . getSymbolId ( symbol ) ; var index = symbolToIndex [ symbolId ] ; if ( index === undefined ) { index = result . length ; symbolToIndex [ symbolId ] = index ; result . push ( { definition : getDefinition ( symbol ) , references : [ ] } ) ; } return result [ index ] ; } function isInNonReferenceComment ( sourceFile , position ) { return ts . isInCommentHelper ( sourceFile , position , isNonReferenceComment ) ; function isNonReferenceComment ( c ) { var commentText = sourceFile . text . substring ( c . pos , c . end ) ; return ! tripleSlashDirectivePrefixRegex . test ( commentText ) ; } } }
Search within node "container" for references for a search value, where the search value is defined as a
tuple of(searchSymbol, searchText, searchLocation, and searchMeaning).
searchLocation: a node where the search value
Search within node container for references for a search value where the search value is defined as a tuple of ( searchSymbol searchText searchLocation and searchMeaning ) . searchLocation : a node where the search value