fix(50303): Using @linkcode in combination with private methods causes TS1003 in JavaScript files. (#56338)

This commit is contained in:
Oleksandr T 2023-11-29 01:07:31 +02:00 committed by GitHub
parent c250aed310
commit 4eae150282
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 91 additions and 12 deletions

View File

@ -9210,18 +9210,7 @@ namespace Parser {
}
nextTokenJSDoc(); // start at token after link, then skip any whitespace
skipWhitespace();
// parseEntityName logs an error for non-identifier, so create a MissingNode ourselves to avoid the error
const p2 = getNodePos();
let name: EntityName | JSDocMemberName | undefined = tokenIsIdentifierOrKeyword(token())
? parseEntityName(/*allowReservedWords*/ true)
: undefined;
if (name) {
while (token() === SyntaxKind.PrivateIdentifier) {
reScanHashToken(); // rescan #id as # id
nextTokenJSDoc(); // then skip the #
name = finishNode(factory.createJSDocMemberName(name, parseIdentifier()), p2);
}
}
const name = parseJSDocLinkName();
const text = [];
while (token() !== SyntaxKind.CloseBraceToken && token() !== SyntaxKind.NewLineTrivia && token() !== SyntaxKind.EndOfFileToken) {
text.push(scanner.getTokenText());
@ -9233,6 +9222,24 @@ namespace Parser {
return finishNode(create(name, text.join("")), start, scanner.getTokenEnd());
}
function parseJSDocLinkName() {
if (tokenIsIdentifierOrKeyword(token())) {
const pos = getNodePos();
let name: EntityName | JSDocMemberName = parseIdentifierName();
while (parseOptional(SyntaxKind.DotToken)) {
name = finishNode(factory.createQualifiedName(name, token() === SyntaxKind.PrivateIdentifier ? createMissingNode<Identifier>(SyntaxKind.Identifier, /*reportAtCurrentPosition*/ false) : parseIdentifier()), pos);
}
while (token() === SyntaxKind.PrivateIdentifier) {
reScanHashToken();
nextTokenJSDoc();
name = finishNode(factory.createJSDocMemberName(name, parseIdentifier()), pos);
}
return name;
}
return undefined;
}
function parseJSDocLinkPrefix() {
skipWhitespaceOrAsterisk();
if (

View File

@ -0,0 +1,26 @@
//// [tests/cases/conformance/jsdoc/jsdocLinkTag7.ts] ////
=== /a.js ===
class Foo {
>Foo : Symbol(Foo, Decl(a.js, 0, 0))
/**
* {@linkcode this.a}
* {@linkcode this.#c}
*
* {@link this.a}
* {@link this.#c}
*
* {@linkplain this.a}
* {@linkplain this.#c}
*/
a() { }
>a : Symbol(Foo.a, Decl(a.js, 0, 11))
b() { }
>b : Symbol(Foo.b, Decl(a.js, 11, 11))
#c() { }
>#c : Symbol(Foo.#c, Decl(a.js, 12, 11))
}

View File

@ -0,0 +1,26 @@
//// [tests/cases/conformance/jsdoc/jsdocLinkTag7.ts] ////
=== /a.js ===
class Foo {
>Foo : Foo
/**
* {@linkcode this.a}
* {@linkcode this.#c}
*
* {@link this.a}
* {@link this.#c}
*
* {@linkplain this.a}
* {@linkplain this.#c}
*/
a() { }
>a : () => void
b() { }
>b : () => void
#c() { }
>#c : () => void
}

View File

@ -0,0 +1,20 @@
// @checkJs: true
// @allowJs: true
// @target: esnext
// @noEmit: true
// @filename: /a.js
class Foo {
/**
* {@linkcode this.a}
* {@linkcode this.#c}
*
* {@link this.a}
* {@link this.#c}
*
* {@linkplain this.a}
* {@linkplain this.#c}
*/
a() { }
b() { }
#c() { }
}