utils/node_modules/@microsoft/tsdoc/lib-commonjs/parser/LineExtractor.js.map
2024-02-07 01:33:07 -05:00

1 line
11 KiB
Plaintext

{"version":3,"file":"LineExtractor.js","sourceRoot":"","sources":["../../src/parser/LineExtractor.ts"],"names":[],"mappings":";;;AAEA,mDAAkD;AAElD,wBAAwB;AACxB,IAAK,KAaJ;AAbD,WAAK,KAAK;IACR,kCAAkC;IAClC,mDAAa,CAAA;IACb,qCAAqC;IACrC,mDAAa,CAAA;IACb,+DAA+D;IAC/D,+DAAmB,CAAA;IACnB,iDAAiD;IACjD,qDAAc,CAAA;IACd,8FAA8F;IAC9F,mDAAa,CAAA;IACb,0BAA0B;IAC1B,iCAAI,CAAA;AACN,CAAC,EAbI,KAAK,KAAL,KAAK,QAaT;AAED;;GAEG;AACH;IAAA;IAsJA,CAAC;IAnJC;;;;OAIG;IACW,qBAAO,GAArB,UAAsB,aAA4B;QAChD,IAAM,KAAK,GAAc,aAAa,CAAC,WAAW,CAAC;QACnD,IAAM,MAAM,GAAW,KAAK,CAAC,MAAM,CAAC;QAEpC,IAAI,iBAAiB,GAAW,CAAC,CAAC;QAClC,IAAI,eAAe,GAAW,CAAC,CAAC;QAEhC,0FAA0F;QAC1F,IAAI,mBAAmB,GAAW,CAAC,CAAC;QACpC,IAAI,iBAAiB,GAAW,CAAC,CAAC;QAElC,IAAI,SAAS,GAAW,KAAK,CAAC,GAAG,CAAC;QAClC,IAAI,KAAK,GAAU,KAAK,CAAC,aAAa,CAAC;QAEvC,IAAM,KAAK,GAAgB,EAAE,CAAC;QAE9B,OAAO,KAAK,KAAK,KAAK,CAAC,IAAI,EAAE;YAC3B,IAAI,SAAS,IAAI,KAAK,CAAC,GAAG,EAAE;gBAC1B,+BAA+B;gBAC/B,QAAQ,KAAK,EAAE;oBACb,KAAK,KAAK,CAAC,aAAa,CAAC;oBACzB,KAAK,KAAK,CAAC,aAAa;wBACtB,aAAa,CAAC,GAAG,CAAC,sBAAsB,CACtC,+BAAc,CAAC,e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\nimport { TSDocMessageId } from './TSDocMessageId';\r\n\r\n// Internal parser state\r\nenum State {\r\n // Initial state, looking for \"/*\"\r\n BeginComment1,\r\n // Looking for \"*\" or \"* \" after \"/*\"\r\n BeginComment2,\r\n // Like State.CollectingLine except immediately after the \"/**\"\r\n CollectingFirstLine,\r\n // Collecting characters until we reach a newline\r\n CollectingLine,\r\n // After a newline, looking for the \"*\" that begins a new line, or the \"*/\" to end the comment\r\n AdvancingLine,\r\n // Exiting the parser loop\r\n Done\r\n}\r\n\r\n/**\r\n * The main API for parsing TSDoc comments.\r\n */\r\nexport class LineExtractor {\r\n private static readonly _whitespaceCharacterRegExp: RegExp = /^\\s$/;\r\n\r\n /**\r\n * This step parses an entire code comment from slash-star-star until star-slash,\r\n * and extracts the content lines. The lines are stored in IDocCommentParameters.lines\r\n * and the overall text range is assigned to IDocCommentParameters.range.\r\n */\r\n public static extract(parserContext: ParserContext): boolean {\r\n const range: TextRange = parserContext.sourceRange;\r\n const buffer: string = range.buffer;\r\n\r\n let commentRangeStart: number = 0;\r\n let commentRangeEnd: number = 0;\r\n\r\n // These must be set before entering CollectingFirstLine, CollectingLine, or AdvancingLine\r\n let collectingLineStart: number = 0;\r\n let collectingLineEnd: number = 0;\r\n\r\n let nextIndex: number = range.pos;\r\n let state: State = State.BeginComment1;\r\n\r\n const lines: TextRange[] = [];\r\n\r\n while (state !== State.Done) {\r\n if (nextIndex >= range.end) {\r\n // reached the end of the input\r\n switch (state) {\r\n case State.BeginComment1:\r\n case State.BeginComment2:\r\n parserContext.log.addMessageForTextRange(\r\n TSDocMessageId.CommentNotFound,\r\n 'Expecting a \"/**\" comment',\r\n range\r\n );\r\n return false;\r\n default:\r\n parserContext.log.addMessageForTextRange(\r\n TSDocMessageId.CommentMissingClosingDelimiter,\r\n 'Unexpected end of input',\r\n range\r\n );\r\n return false;\r\n }\r\n }\r\n\r\n const current: string = buffer[nextIndex];\r\n const currentIndex: number = nextIndex;\r\n ++nextIndex;\r\n const next: string = nextIndex < range.end ? buffer[nextIndex] : '';\r\n\r\n switch (state) {\r\n case State.BeginComment1:\r\n if (current === '/' && next === '*') {\r\n commentRangeStart = currentIndex;\r\n ++nextIndex; // skip the star\r\n state = State.BeginComment2;\r\n } else if (!LineExtractor._whitespaceCharacterRegExp.test(current)) {\r\n parserContext.log.addMessageForTextRange(\r\n TSDocMessageId.CommentOpeningDelimiterSyntax,\r\n 'Expecting a leading \"/**\"',\r\n range.getNewRange(currentIndex, currentIndex + 1)\r\n );\r\n return false;\r\n }\r\n break;\r\n case State.BeginComment2:\r\n if (current === '*') {\r\n if (next === ' ') {\r\n ++nextIndex; // Discard the space after the star\r\n }\r\n collectingLineStart = nextIndex;\r\n collectingLineEnd = nextIndex;\r\n state = State.CollectingFirstLine;\r\n } else {\r\n parserContext.log.addMessageForTextRange(\r\n TSDocMessageId.CommentOpeningDelimiterSyntax,\r\n 'Expecting a leading \"/**\"',\r\n range.getNewRange(currentIndex, currentIndex + 1)\r\n );\r\n return false;\r\n }\r\n break;\r\n case State.CollectingFirstLine:\r\n case State.CollectingLine:\r\n if (current === '\\n') {\r\n // Ignore an empty line if it is immediately after the \"/**\"\r\n if (state !== State.CollectingFirstLine || collectingLineEnd > collectingLineStart) {\r\n // Record the line that we collected\r\n lines.push(range.getNewRange(collectingLineStart, collectingLineEnd));\r\n }\r\n collectingLineStart = nextIndex;\r\n collectingLineEnd = nextIndex;\r\n state = State.AdvancingLine;\r\n } else if (current === '*' && next === '/') {\r\n if (collectingLineEnd > collectingLineStart) {\r\n lines.push(range.getNewRange(collectingLineStart, collectingLineEnd));\r\n }\r\n collectingLineStart = 0;\r\n collectingLineEnd = 0;\r\n ++nextIndex; // skip the slash\r\n commentRangeEnd = nextIndex;\r\n state = State.Done;\r\n } else if (!LineExtractor._whitespaceCharacterRegExp.test(current)) {\r\n collectingLineEnd = nextIndex;\r\n }\r\n break;\r\n case State.AdvancingLine:\r\n if (current === '*') {\r\n if (next === '/') {\r\n collectingLineStart = 0;\r\n collectingLineEnd = 0;\r\n\r\n ++nextIndex; // skip the slash\r\n commentRangeEnd = nextIndex;\r\n state = State.Done;\r\n } else {\r\n // Discard the \"*\" at the start of a line\r\n\r\n if (next === ' ') {\r\n ++nextIndex; // Discard the space after the star\r\n }\r\n\r\n collectingLineStart = nextIndex;\r\n collectingLineEnd = nextIndex;\r\n state = State.CollectingLine;\r\n }\r\n } else if (current === '\\n') {\r\n // Blank line\r\n lines.push(range.getNewRange(currentIndex, currentIndex));\r\n collectingLineStart = nextIndex;\r\n } else if (!LineExtractor._whitespaceCharacterRegExp.test(current)) {\r\n // If the star is missing, then start the line here\r\n // Example: \"/**\\nL1*/\"\r\n\r\n // (collectingLineStart was the start of this line)\r\n collectingLineEnd = nextIndex;\r\n state = State.CollectingLine;\r\n }\r\n break;\r\n }\r\n }\r\n\r\n /**\r\n * Only fill in these if we successfully scanned a comment\r\n */\r\n parserContext.commentRange = range.getNewRange(commentRangeStart, commentRangeEnd);\r\n parserContext.lines = lines;\r\n return true;\r\n }\r\n}\r\n"]}