Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 13.7k
Make JSDoc skipping public, plus more configurable#55739
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
442b4679119d2fba9dcab8a4837c66a0b0946bbf0e88bfd9e2abd21bb6918309e2f8c13d60c92fb22a3e626ae3eb6379cba273a91a430b303ebdfb63673f9ef39363140b0cc412f5903735c17cb3e23a9db14c33517f2899392280File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -12,6 +12,7 @@ import { | ||
| DiagnosticMessage, | ||
| Diagnostics, | ||
| identity, | ||
| JSDocParsingMode, | ||
| JSDocSyntaxKind, | ||
| JsxTokenSyntaxKind, | ||
| KeywordSyntaxKind, | ||
| @@ -21,6 +22,7 @@ import { | ||
| parsePseudoBigInt, | ||
| positionIsSynthesized, | ||
| PunctuationOrKeywordSyntaxKind, | ||
| ScriptKind, | ||
| ScriptTarget, | ||
| SourceFileLike, | ||
| SyntaxKind, | ||
| @@ -95,6 +97,8 @@ export interface Scanner { | ||
| setOnError(onError: ErrorCallback | undefined): void; | ||
| setScriptTarget(scriptTarget: ScriptTarget): void; | ||
| setLanguageVariant(variant: LanguageVariant): void; | ||
| setScriptKind(scriptKind: ScriptKind): void; | ||
| setJSDocParsingMode(kind: JSDocParsingMode): void; | ||
| /** @deprecated use {@link resetTokenState} */ | ||
| setTextPos(textPos: number): void; | ||
| resetTokenState(pos: number): void; | ||
| @@ -114,8 +118,6 @@ export interface Scanner { | ||
| // callback returns something truthy, then the scanner state is not rolled back. The result | ||
| // of invoking the callback is returned from this function. | ||
| tryScan<T>(callback: () => T): T; | ||
| /** @internal */ | ||
| setSkipNonSemanticJSDoc(skip: boolean): void; | ||
| } | ||
| /** @internal */ | ||
| @@ -345,10 +347,7 @@ const commentDirectiveRegExSingleLine = /^\/\/\/?\s*@(ts-expect-error|ts-ignore) | ||
| */ | ||
| const commentDirectiveRegExMultiLine = /^(?:\/|\*)*\s*@(ts-expect-error|ts-ignore)/; | ||
| /** | ||
| * Test for whether a comment contains a JSDoc tag needed by the checker when run in tsc. | ||
| */ | ||
| const semanticJSDocTagRegEx = /@(?:see|link)/i; | ||
| const jsDocSeeOrLink = /@(?:see|link)/i; | ||
| function lookupInUnicodeMap(code: number, map: readonly number[]): boolean { | ||
| // Bail out quickly if it couldn't possibly be in the map. | ||
| @@ -1008,7 +1007,8 @@ export function createScanner(languageVersion: ScriptTarget, skipTrivia: boolean | ||
| var commentDirectives: CommentDirective[] | undefined; | ||
| var inJSDocType = 0; | ||
| var skipNonSemanticJSDoc = false; | ||
| var scriptKind = ScriptKind.Unknown; | ||
| var jsDocParsingMode = JSDocParsingMode.ParseAll; | ||
| setText(text, start, length); | ||
| @@ -1054,14 +1054,15 @@ export function createScanner(languageVersion: ScriptTarget, skipTrivia: boolean | ||
| setText, | ||
| setScriptTarget, | ||
| setLanguageVariant, | ||
| setScriptKind, | ||
| setJSDocParsingMode, | ||
| setOnError, | ||
| resetTokenState, | ||
| setTextPos: resetTokenState, | ||
| setInJSDocType, | ||
| tryScan, | ||
| lookAhead, | ||
| scanRange, | ||
| setSkipNonSemanticJSDoc, | ||
| }; | ||
| /* eslint-enable no-var */ | ||
| @@ -2003,7 +2004,7 @@ export function createScanner(languageVersion: ScriptTarget, skipTrivia: boolean | ||
| } | ||
| } | ||
| if (isJSDoc && (!skipNonSemanticJSDoc || semanticJSDocTagRegEx.test(text.slice(fullStartPos, pos)))) { | ||
| if (isJSDoc && shouldParseJSDoc()) { | ||
Member There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍🏼 | ||
| tokenFlags |= TokenFlags.PrecedingJSDocComment; | ||
| } | ||
| @@ -2288,6 +2289,28 @@ export function createScanner(languageVersion: ScriptTarget, skipTrivia: boolean | ||
| } | ||
| } | ||
| function shouldParseJSDoc() { | ||
| switch (jsDocParsingMode) { | ||
| case JSDocParsingMode.ParseAll: | ||
| return true; | ||
| case JSDocParsingMode.ParseNone: | ||
| return false; | ||
| } | ||
| if (scriptKind !== ScriptKind.TS && scriptKind !== ScriptKind.TSX) { | ||
| // If outside of TS, we need JSDoc to get any type info. | ||
| ||
| return true; | ||
| } | ||
| if (jsDocParsingMode === JSDocParsingMode.ParseForTypeInfo) { | ||
| // If we're in TS, but we don't need to produce reliable errors, | ||
| // we don't need to parse to find @see or @link. | ||
| return false; | ||
| } | ||
| return jsDocSeeOrLink.test(text.slice(fullStartPos, pos)); | ||
| } | ||
| function reScanInvalidIdentifier(): SyntaxKind { | ||
| Debug.assert(token === SyntaxKind.Unknown, "'reScanInvalidIdentifier' should only be called when the current token is 'SyntaxKind.Unknown'."); | ||
| pos = tokenStart = fullStartPos; | ||
| @@ -2788,8 +2811,12 @@ export function createScanner(languageVersion: ScriptTarget, skipTrivia: boolean | ||
| languageVariant = variant; | ||
| } | ||
| function setSkipNonSemanticJSDoc(skip: boolean) { | ||
| skipNonSemanticJSDoc = skip; | ||
| function setScriptKind(kind: ScriptKind) { | ||
| scriptKind = kind; | ||
| } | ||
| function setJSDocParsingMode(kind: JSDocParsingMode) { | ||
| jsDocParsingMode = kind; | ||
| } | ||
| function resetTokenState(position: number) { | ||
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.