MCPcopy
hub / github.com/microsoft/tsdoc / _parseDeclarationReference

Method _parseDeclarationReference

tsdoc/src/parser/NodeParser.ts:1250–1495  ·  view source on GitHub ↗
(
    tokenReader: TokenReader,
    tokenSequenceForErrorContext: TokenSequence,
    nodeForErrorContext: DocNode
  )

Source from the content-addressed store, hash-verified

1248 }
1249
1250 private _parseDeclarationReference(
1251 tokenReader: TokenReader,
1252 tokenSequenceForErrorContext: TokenSequence,
1253 nodeForErrorContext: DocNode
1254 ): DocDeclarationReference | undefined {
1255 tokenReader.assertAccumulatedSequenceIsEmpty();
1256
1257 // The package name can contain characters that look like a member reference. This means we need to scan forwards
1258 // to see if there is a "#". However, we need to be careful not to match a "#" that is part of a quoted expression.
1259
1260 const marker: number = tokenReader.createMarker();
1261 let hasHash: boolean = false;
1262
1263 // A common mistake is to forget the "#" for package name or import path. The telltale sign
1264 // of this is mistake is that we see path-only characters such as "@" or "/" in the beginning
1265 // where this would be a syntax error for a member reference.
1266 let lookingForImportCharacters: boolean = true;
1267 let sawImportCharacters: boolean = false;
1268
1269 let done: boolean = false;
1270 while (!done) {
1271 switch (tokenReader.peekTokenKind()) {
1272 case TokenKind.DoubleQuote:
1273 case TokenKind.EndOfInput:
1274 case TokenKind.LeftCurlyBracket:
1275 case TokenKind.LeftParenthesis:
1276 case TokenKind.LeftSquareBracket:
1277 case TokenKind.Newline:
1278 case TokenKind.Pipe:
1279 case TokenKind.RightCurlyBracket:
1280 case TokenKind.RightParenthesis:
1281 case TokenKind.RightSquareBracket:
1282 case TokenKind.SingleQuote:
1283 case TokenKind.Spacing:
1284 done = true;
1285 break;
1286 case TokenKind.PoundSymbol:
1287 hasHash = true;
1288 done = true;
1289 break;
1290 case TokenKind.Slash:
1291 case TokenKind.AtSign:
1292 if (lookingForImportCharacters) {
1293 sawImportCharacters = true;
1294 }
1295 tokenReader.readToken();
1296 break;
1297 case TokenKind.AsciiWord:
1298 case TokenKind.Period:
1299 case TokenKind.Hyphen:
1300 // It's a character that looks like part of a package name or import path,
1301 // so don't set lookingForImportCharacters = false
1302 tokenReader.readToken();
1303 break;
1304 default:
1305 // Once we reach something other than AsciiWord and Period, then the meaning of
1306 // slashes and at-signs is no longer obvious.
1307 lookingForImportCharacters = false;

Callers 3

_parseInheritDocTagMethod · 0.95
_parseMemberSymbolMethod · 0.95

Calls 13

_parseMemberReferenceMethod · 0.95
createMarkerMethod · 0.80
peekTokenKindMethod · 0.80
readTokenMethod · 0.80
backtrackToMarkerMethod · 0.80

Tested by

no test coverage detected