MCPcopy Create free account
hub / github.com/nodejs/node / getPossibleSymbolReferencePositions

Function getPossibleSymbolReferencePositions

test/fixtures/snapshot/typescript.js:138055–138083  ·  view source on GitHub ↗
(sourceFile, symbolName, container)

Source from the content-addressed store, hash-verified

138053 return getPossibleSymbolReferencePositions(sourceFile, symbolName, container).map(function (pos) { return ts.getTouchingPropertyName(sourceFile, pos); });
138054 }
138055 function getPossibleSymbolReferencePositions(sourceFile, symbolName, container) {
138056 if (container === void 0) { container = sourceFile; }
138057 var positions = [];
138058 /// TODO: Cache symbol existence for files to save text search
138059 // Also, need to make this work for unicode escapes.
138060 // Be resilient in the face of a symbol with no name or zero length name
138061 if (!symbolName || !symbolName.length) {
138062 return positions;
138063 }
138064 var text = sourceFile.text;
138065 var sourceLength = text.length;
138066 var symbolNameLength = symbolName.length;
138067 var position = text.indexOf(symbolName, container.pos);
138068 while (position >= 0) {
138069 // If we are past the end, stop looking
138070 if (position > container.end)
138071 break;
138072 // We found a match. Make sure it's not part of a larger word (i.e. the char
138073 // before and after it have to be a non-identifier char).
138074 var endPosition = position + symbolNameLength;
138075 if ((position === 0 || !ts.isIdentifierPart(text.charCodeAt(position - 1), 99 /* ScriptTarget.Latest */)) &&
138076 (endPosition === sourceLength || !ts.isIdentifierPart(text.charCodeAt(endPosition), 99 /* ScriptTarget.Latest */))) {
138077 // Found a real match. Keep searching.
138078 positions.push(position);
138079 }
138080 position = text.indexOf(symbolName, position + symbolNameLength + 1);
138081 }
138082 return positions;
138083 }
138084 function getLabelReferencesInNode(container, targetLabel) {
138085 var sourceFile = container.getSourceFile();
138086 var labelName = targetLabel.text;

Callers 2

getReferencesInContainerFunction · 0.85

Calls 2

indexOfMethod · 0.45
pushMethod · 0.45

Tested by

no test coverage detected