Skip to content

Commit 9c7cdf9

Browse files
committed
feat(42684): allow deprecated JSDoc tag to be used on aliased nodes
1 parent ef9fd97 commit 9c7cdf9

File tree

7 files changed

+115
-11
lines changed

7 files changed

+115
-11
lines changed

src/compiler/checker.ts

Lines changed: 36 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25066,9 +25066,13 @@ namespace ts {
2506625066
}
2506725067

2506825068
const localOrExportSymbol = getExportSymbolOfValueSymbolIfExported(symbol);
25069-
const sourceSymbol = localOrExportSymbol.flags & SymbolFlags.Alias ? resolveAlias(localOrExportSymbol) : localOrExportSymbol;
25070-
if (sourceSymbol.declarations && getDeclarationNodeFlagsFromSymbol(sourceSymbol) & NodeFlags.Deprecated && isUncalledFunctionReference(node, sourceSymbol)) {
25071-
addDeprecatedSuggestion(node, sourceSymbol.declarations, node.escapedText as string);
25069+
if (localOrExportSymbol.flags & SymbolFlags.Alias) {
25070+
checkDeprecatedAliasedSymbol(localOrExportSymbol, node);
25071+
}
25072+
else {
25073+
if (localOrExportSymbol.declarations && getDeclarationNodeFlagsFromSymbol(localOrExportSymbol) & NodeFlags.Deprecated && isUncalledFunctionReference(node, localOrExportSymbol)) {
25074+
addDeprecatedSuggestion(node, localOrExportSymbol.declarations, node.escapedText as string);
25075+
}
2507225076
}
2507325077

2507425078
let declaration = localOrExportSymbol.valueDeclaration;
@@ -39802,8 +39806,35 @@ namespace ts {
3980239806
}
3980339807
}
3980439808

39805-
if (isImportSpecifier(node) && target.declarations?.every(d => !!(getCombinedNodeFlags(d) & NodeFlags.Deprecated))) {
39806-
addDeprecatedSuggestion(node.name, target.declarations, symbol.escapedName as string);
39809+
if (isImportSpecifier(node)) {
39810+
checkDeprecatedAliasedSymbol(symbol, node);
39811+
}
39812+
}
39813+
}
39814+
39815+
function checkDeprecatedAliasedSymbol(symbol: Symbol, location: Node) {
39816+
if (!(symbol.flags & SymbolFlags.Alias)) return;
39817+
39818+
const targetSymbol = resolveAlias(symbol);
39819+
if (targetSymbol === unknownSymbol) return;
39820+
39821+
while (symbol.flags & SymbolFlags.Alias) {
39822+
const target = getImmediateAliasedSymbol(symbol);
39823+
if (target && target.declarations && length(target.declarations)) {
39824+
const deprecated = target.declarations.every(d => !!(getCombinedNodeFlags(d) & NodeFlags.Deprecated));
39825+
if (deprecated && isUncalledFunctionReference(location, target)) {
39826+
addDeprecatedSuggestion(location, target.declarations, target.escapedName as string);
39827+
break;
39828+
}
39829+
else {
39830+
if (symbol === targetSymbol) {
39831+
break;
39832+
}
39833+
symbol = target;
39834+
}
39835+
}
39836+
else {
39837+
break;
3980739838
}
3980839839
}
3980939840
}

src/compiler/parser.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7406,7 +7406,8 @@ namespace ts {
74067406
}
74077407

74087408
function parseExportSpecifier() {
7409-
return parseImportOrExportSpecifier(SyntaxKind.ExportSpecifier) as ExportSpecifier;
7409+
const hasJSDoc = hasPrecedingJSDocComment();
7410+
return withJSDoc(parseImportOrExportSpecifier(SyntaxKind.ExportSpecifier) as ExportSpecifier, hasJSDoc);
74107411
}
74117412

74127413
function parseImportSpecifier() {

src/compiler/types.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -929,6 +929,7 @@ namespace ts {
929929
| JSDocFunctionType
930930
| ExportDeclaration
931931
| NamedTupleMember
932+
| ExportSpecifier
932933
| EndOfFileToken
933934
;
934935

@@ -3117,7 +3118,7 @@ namespace ts {
31173118
readonly isTypeOnly: boolean;
31183119
}
31193120

3120-
export interface ExportSpecifier extends NamedDeclaration {
3121+
export interface ExportSpecifier extends NamedDeclaration, JSDocContainer {
31213122
readonly kind: SyntaxKind.ExportSpecifier;
31223123
readonly parent: NamedExports;
31233124
readonly isTypeOnly: boolean;

tests/baselines/reference/api/tsserverlibrary.d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -572,7 +572,7 @@ declare namespace ts {
572572
}
573573
export interface JSDocContainer {
574574
}
575-
export type HasJSDoc = ParameterDeclaration | CallSignatureDeclaration | ClassStaticBlockDeclaration | ConstructSignatureDeclaration | MethodSignature | PropertySignature | ArrowFunction | ParenthesizedExpression | SpreadAssignment | ShorthandPropertyAssignment | PropertyAssignment | FunctionExpression | EmptyStatement | DebuggerStatement | Block | VariableStatement | ExpressionStatement | IfStatement | DoStatement | WhileStatement | ForStatement | ForInStatement | ForOfStatement | BreakStatement | ContinueStatement | ReturnStatement | WithStatement | SwitchStatement | LabeledStatement | ThrowStatement | TryStatement | FunctionDeclaration | ConstructorDeclaration | MethodDeclaration | VariableDeclaration | PropertyDeclaration | AccessorDeclaration | ClassLikeDeclaration | InterfaceDeclaration | TypeAliasDeclaration | EnumMember | EnumDeclaration | ModuleDeclaration | ImportEqualsDeclaration | ImportDeclaration | NamespaceExportDeclaration | ExportAssignment | IndexSignatureDeclaration | FunctionTypeNode | ConstructorTypeNode | JSDocFunctionType | ExportDeclaration | NamedTupleMember | EndOfFileToken;
575+
export type HasJSDoc = ParameterDeclaration | CallSignatureDeclaration | ClassStaticBlockDeclaration | ConstructSignatureDeclaration | MethodSignature | PropertySignature | ArrowFunction | ParenthesizedExpression | SpreadAssignment | ShorthandPropertyAssignment | PropertyAssignment | FunctionExpression | EmptyStatement | DebuggerStatement | Block | VariableStatement | ExpressionStatement | IfStatement | DoStatement | WhileStatement | ForStatement | ForInStatement | ForOfStatement | BreakStatement | ContinueStatement | ReturnStatement | WithStatement | SwitchStatement | LabeledStatement | ThrowStatement | TryStatement | FunctionDeclaration | ConstructorDeclaration | MethodDeclaration | VariableDeclaration | PropertyDeclaration | AccessorDeclaration | ClassLikeDeclaration | InterfaceDeclaration | TypeAliasDeclaration | EnumMember | EnumDeclaration | ModuleDeclaration | ImportEqualsDeclaration | ImportDeclaration | NamespaceExportDeclaration | ExportAssignment | IndexSignatureDeclaration | FunctionTypeNode | ConstructorTypeNode | JSDocFunctionType | ExportDeclaration | NamedTupleMember | ExportSpecifier | EndOfFileToken;
576576
export type HasType = SignatureDeclaration | VariableDeclaration | ParameterDeclaration | PropertySignature | PropertyDeclaration | TypePredicateNode | ParenthesizedTypeNode | TypeOperatorNode | MappedTypeNode | AssertionExpression | TypeAliasDeclaration | JSDocTypeExpression | JSDocNonNullableType | JSDocNullableType | JSDocOptionalType | JSDocVariadicType;
577577
export type HasTypeArguments = CallExpression | NewExpression | TaggedTemplateExpression | JsxOpeningElement | JsxSelfClosingElement;
578578
export type HasInitializer = HasExpressionInitializer | ForStatement | ForInStatement | ForOfStatement | JsxAttribute;
@@ -1702,7 +1702,7 @@ declare namespace ts {
17021702
readonly name: Identifier;
17031703
readonly isTypeOnly: boolean;
17041704
}
1705-
export interface ExportSpecifier extends NamedDeclaration {
1705+
export interface ExportSpecifier extends NamedDeclaration, JSDocContainer {
17061706
readonly kind: SyntaxKind.ExportSpecifier;
17071707
readonly parent: NamedExports;
17081708
readonly isTypeOnly: boolean;

tests/baselines/reference/api/typescript.d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -572,7 +572,7 @@ declare namespace ts {
572572
}
573573
export interface JSDocContainer {
574574
}
575-
export type HasJSDoc = ParameterDeclaration | CallSignatureDeclaration | ClassStaticBlockDeclaration | ConstructSignatureDeclaration | MethodSignature | PropertySignature | ArrowFunction | ParenthesizedExpression | SpreadAssignment | ShorthandPropertyAssignment | PropertyAssignment | FunctionExpression | EmptyStatement | DebuggerStatement | Block | VariableStatement | ExpressionStatement | IfStatement | DoStatement | WhileStatement | ForStatement | ForInStatement | ForOfStatement | BreakStatement | ContinueStatement | ReturnStatement | WithStatement | SwitchStatement | LabeledStatement | ThrowStatement | TryStatement | FunctionDeclaration | ConstructorDeclaration | MethodDeclaration | VariableDeclaration | PropertyDeclaration | AccessorDeclaration | ClassLikeDeclaration | InterfaceDeclaration | TypeAliasDeclaration | EnumMember | EnumDeclaration | ModuleDeclaration | ImportEqualsDeclaration | ImportDeclaration | NamespaceExportDeclaration | ExportAssignment | IndexSignatureDeclaration | FunctionTypeNode | ConstructorTypeNode | JSDocFunctionType | ExportDeclaration | NamedTupleMember | EndOfFileToken;
575+
export type HasJSDoc = ParameterDeclaration | CallSignatureDeclaration | ClassStaticBlockDeclaration | ConstructSignatureDeclaration | MethodSignature | PropertySignature | ArrowFunction | ParenthesizedExpression | SpreadAssignment | ShorthandPropertyAssignment | PropertyAssignment | FunctionExpression | EmptyStatement | DebuggerStatement | Block | VariableStatement | ExpressionStatement | IfStatement | DoStatement | WhileStatement | ForStatement | ForInStatement | ForOfStatement | BreakStatement | ContinueStatement | ReturnStatement | WithStatement | SwitchStatement | LabeledStatement | ThrowStatement | TryStatement | FunctionDeclaration | ConstructorDeclaration | MethodDeclaration | VariableDeclaration | PropertyDeclaration | AccessorDeclaration | ClassLikeDeclaration | InterfaceDeclaration | TypeAliasDeclaration | EnumMember | EnumDeclaration | ModuleDeclaration | ImportEqualsDeclaration | ImportDeclaration | NamespaceExportDeclaration | ExportAssignment | IndexSignatureDeclaration | FunctionTypeNode | ConstructorTypeNode | JSDocFunctionType | ExportDeclaration | NamedTupleMember | ExportSpecifier | EndOfFileToken;
576576
export type HasType = SignatureDeclaration | VariableDeclaration | ParameterDeclaration | PropertySignature | PropertyDeclaration | TypePredicateNode | ParenthesizedTypeNode | TypeOperatorNode | MappedTypeNode | AssertionExpression | TypeAliasDeclaration | JSDocTypeExpression | JSDocNonNullableType | JSDocNullableType | JSDocOptionalType | JSDocVariadicType;
577577
export type HasTypeArguments = CallExpression | NewExpression | TaggedTemplateExpression | JsxOpeningElement | JsxSelfClosingElement;
578578
export type HasInitializer = HasExpressionInitializer | ForStatement | ForInStatement | ForOfStatement | JsxAttribute;
@@ -1702,7 +1702,7 @@ declare namespace ts {
17021702
readonly name: Identifier;
17031703
readonly isTypeOnly: boolean;
17041704
}
1705-
export interface ExportSpecifier extends NamedDeclaration {
1705+
export interface ExportSpecifier extends NamedDeclaration, JSDocContainer {
17061706
readonly kind: SyntaxKind.ExportSpecifier;
17071707
readonly parent: NamedExports;
17081708
readonly isTypeOnly: boolean;
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/// <reference path="fourslash.ts" />
2+
3+
// @module: esnext
4+
// @filename: /a.ts
5+
////export const a = 1;
6+
////export const b = 1;
7+
8+
// @filename: /b.ts
9+
////export {
10+
//// /** @deprecated a is deprecated */
11+
//// a
12+
////} from "./a";
13+
14+
// @filename: /c.ts
15+
////import { [|a|] } from "./b";
16+
////[|a|]
17+
18+
goTo.file("/c.ts")
19+
20+
verify.getSuggestionDiagnostics([
21+
{
22+
"code": 6385,
23+
"message": "'a' is deprecated.",
24+
"reportsDeprecated": true,
25+
"range": test.ranges()[0]
26+
},
27+
{
28+
"code": 6385,
29+
"message": "'a' is deprecated.",
30+
"reportsDeprecated": true,
31+
"range": test.ranges()[1]
32+
},
33+
]);
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/// <reference path="fourslash.ts" />
2+
3+
// @module: esnext
4+
// @filename: /a.ts
5+
////export const a = 1;
6+
////export const b = 1;
7+
8+
// @filename: /b.ts
9+
////export {
10+
//// /** @deprecated a is deprecated */
11+
//// a
12+
////} from "./a";
13+
14+
// @filename: /c.ts
15+
////export {
16+
//// a
17+
////} from "./b";
18+
19+
// @filename: /d.ts
20+
////import { [|a|] } from "./c";
21+
////[|a|]
22+
23+
goTo.file("/d.ts")
24+
25+
verify.getSuggestionDiagnostics([
26+
{
27+
"code": 6385,
28+
"message": "'a' is deprecated.",
29+
"reportsDeprecated": true,
30+
"range": test.ranges()[0]
31+
},
32+
{
33+
"code": 6385,
34+
"message": "'a' is deprecated.",
35+
"reportsDeprecated": true,
36+
"range": test.ranges()[1]
37+
},
38+
]);

0 commit comments

Comments
 (0)