From bb09d386450d645bf32a60a53fa07f279e484e59 Mon Sep 17 00:00:00 2001 From: kingwl Date: Wed, 13 May 2020 12:53:37 +0800 Subject: [PATCH 01/38] Add deprecated related feature --- src/compiler/factoryPublic.ts | 4 + src/compiler/parser.ts | 3 + src/compiler/types.ts | 5 + src/compiler/utilitiesPublic.ts | 9 + src/harness/client.ts | 1 + src/harness/fourslashImpl.ts | 1 + src/harness/fourslashInterfaceImpl.ts | 1 + src/server/protocol.ts | 9 + src/server/session.ts | 3 +- src/services/navigateTo.ts | 1 + src/services/types.ts | 1 + .../unittests/tsserver/declarationFileMaps.ts | 7 + src/testRunner/unittests/tsserver/navTo.ts | 27 +- .../reference/api/tsserverlibrary.d.ts | 265 +++++++++--------- tests/baselines/reference/api/typescript.d.ts | 258 ++++++++--------- 15 files changed, 343 insertions(+), 252 deletions(-) diff --git a/src/compiler/factoryPublic.ts b/src/compiler/factoryPublic.ts index 030b527b30bd1..2eaf6f139b950 100644 --- a/src/compiler/factoryPublic.ts +++ b/src/compiler/factoryPublic.ts @@ -2613,6 +2613,10 @@ namespace ts { return createJSDocTag(SyntaxKind.JSDocAuthorTag, "author", comment); } + export function createJSDocDeprecatedTag(comment?: string) { + return createJSDocTag(SyntaxKind.JSDocDeprecatedTag, "deprecated", comment); + } + export function createJSDocPublicTag() { return createJSDocTag(SyntaxKind.JSDocPublicTag, "public"); } diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index 9754cdf64d362..9505c6a59e5f8 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -7094,6 +7094,9 @@ namespace ts { case "readonly": tag = parseSimpleTag(start, SyntaxKind.JSDocReadonlyTag, tagName); break; + case "deprecated": + tag = parseSimpleTag(start, SyntaxKind.JSDocDeprecatedTag, tagName); + break; case "this": tag = parseThisTag(start, tagName); break; diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 0c45dca9529fc..70ab5e74696e3 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -474,6 +474,7 @@ namespace ts { JSDocAugmentsTag, JSDocImplementsTag, JSDocAuthorTag, + JSDocDeprecatedTag, JSDocClassTag, JSDocPublicTag, JSDocPrivateTag, @@ -2688,6 +2689,10 @@ namespace ts { kind: SyntaxKind.JSDocAuthorTag; } + export interface JSDocDeprecatedTag extends JSDocTag { + kind: SyntaxKind.JSDocDeprecatedTag; + } + export interface JSDocClassTag extends JSDocTag { kind: SyntaxKind.JSDocClassTag; } diff --git a/src/compiler/utilitiesPublic.ts b/src/compiler/utilitiesPublic.ts index 0da9f34ecec82..934cee5f51c2f 100644 --- a/src/compiler/utilitiesPublic.ts +++ b/src/compiler/utilitiesPublic.ts @@ -759,6 +759,11 @@ namespace ts { return getFirstJSDocTag(node, isJSDocTemplateTag); } + /** Gets the JSDoc deprecated tag for the node if present */ + export function getJSDocDeprecatedTag(node: Node): JSDocDeprecatedTag | undefined { + return getFirstJSDocTag(node, isJSDocDeprecatedTag); + } + /** Gets the JSDoc type tag for the node if present and valid */ export function getJSDocTypeTag(node: Node): JSDocTypeTag | undefined { // We should have already issued an error if there were multiple type jsdocs, so just use the first one. @@ -1692,6 +1697,10 @@ namespace ts { return node.kind === SyntaxKind.JSDocTemplateTag; } + export function isJSDocDeprecatedTag(node: Node): node is JSDocDeprecatedTag { + return node.kind === SyntaxKind.JSDocDeprecatedTag; + } + export function isJSDocTypedefTag(node: Node): node is JSDocTypedefTag { return node.kind === SyntaxKind.JSDocTypedefTag; } diff --git a/src/harness/client.ts b/src/harness/client.ts index 83e85cbc9a328..63b613b0cf7c3 100644 --- a/src/harness/client.ts +++ b/src/harness/client.ts @@ -242,6 +242,7 @@ namespace ts.server { isCaseSensitive: entry.isCaseSensitive, fileName: entry.file, textSpan: this.decodeSpan(entry), + isDeprecated: !!entry.tags?.includes(protocol.SymbolTag.Deprecated) })); } diff --git a/src/harness/fourslashImpl.ts b/src/harness/fourslashImpl.ts index dd4135ca40c15..e6c9849bdb537 100644 --- a/src/harness/fourslashImpl.ts +++ b/src/harness/fourslashImpl.ts @@ -2988,6 +2988,7 @@ namespace FourSlash { textSpan: ts.createTextSpanFromRange(e.range), containerName: e.containerName || "", containerKind: e.containerKind || ts.ScriptElementKind.unknown, + isDeprecated: !!e.isDeprecated }))); } } diff --git a/src/harness/fourslashInterfaceImpl.ts b/src/harness/fourslashInterfaceImpl.ts index f4905c00b84b5..c24c565a81bcf 100644 --- a/src/harness/fourslashInterfaceImpl.ts +++ b/src/harness/fourslashInterfaceImpl.ts @@ -1545,6 +1545,7 @@ namespace FourSlashInterface { readonly range: FourSlash.Range; readonly containerName?: string; readonly containerKind?: ts.ScriptElementKind; + readonly isDeprecated?: boolean } export type ArrayOrSingle = T | readonly T[]; diff --git a/src/server/protocol.ts b/src/server/protocol.ts index b6cc2e4d8fdab..182b0255804e4 100644 --- a/src/server/protocol.ts +++ b/src/server/protocol.ts @@ -2818,6 +2818,10 @@ namespace ts.server.protocol { arguments: NavtoRequestArgs; } + export enum SymbolTag { + Deprecated = 1 + } + /** * An item found in a navto response. */ @@ -2857,6 +2861,11 @@ namespace ts.server.protocol { * Kind of symbol's container symbol (if any). */ containerKind?: ScriptElementKind; + + /** + * The symbol's tag. + */ + tags?: SymbolTag[] } /** diff --git a/src/server/session.ts b/src/server/session.ts index 3f0321074a994..c39bd21d23a3d 100644 --- a/src/server/session.ts +++ b/src/server/session.ts @@ -1886,7 +1886,8 @@ namespace ts.server { matchKind: navItem.matchKind, file: navItem.fileName, start: scriptInfo.positionToLineOffset(navItem.textSpan.start), - end: scriptInfo.positionToLineOffset(textSpanEnd(navItem.textSpan)) + end: scriptInfo.positionToLineOffset(textSpanEnd(navItem.textSpan)), + tags: navItem.isDeprecated ? [protocol.SymbolTag.Deprecated] : undefined }; if (navItem.kindModifiers && (navItem.kindModifiers !== "")) { bakedItem.kindModifiers = navItem.kindModifiers; diff --git a/src/services/navigateTo.ts b/src/services/navigateTo.ts index bcd0fbe273682..caf913a5444cb 100644 --- a/src/services/navigateTo.ts +++ b/src/services/navigateTo.ts @@ -131,6 +131,7 @@ namespace ts.NavigateTo { // TODO(jfreeman): What should be the containerName when the container has a computed name? containerName: containerName ? (containerName).text : "", containerKind: containerName ? getNodeKind(container!) : ScriptElementKind.unknown, // TODO: GH#18217 Just use `container ? ...` + isDeprecated: !!getJSDocDeprecatedTag(rawItem.declaration) }; } } diff --git a/src/services/types.ts b/src/services/types.ts index fd8ade8f8e6e1..6aa60b85fff0d 100644 --- a/src/services/types.ts +++ b/src/services/types.ts @@ -807,6 +807,7 @@ namespace ts { textSpan: TextSpan; containerName: string; containerKind: ScriptElementKind; + isDeprecated: boolean } export enum IndentStyle { diff --git a/src/testRunner/unittests/tsserver/declarationFileMaps.ts b/src/testRunner/unittests/tsserver/declarationFileMaps.ts index c52e2ad807a74..ee9e68b5f5b50 100644 --- a/src/testRunner/unittests/tsserver/declarationFileMaps.ts +++ b/src/testRunner/unittests/tsserver/declarationFileMaps.ts @@ -296,6 +296,7 @@ namespace ts.projectSystem { isCaseSensitive: true, kind: ScriptElementKind.functionElement, kindModifiers: "export,declare", + tags: undefined }, { ...protocolFileSpanFromSubstring({ @@ -307,6 +308,7 @@ namespace ts.projectSystem { isCaseSensitive: true, kind: ScriptElementKind.functionElement, kindModifiers: "export", + tags: undefined }, { ...protocolFileSpanFromSubstring({ @@ -318,6 +320,7 @@ namespace ts.projectSystem { isCaseSensitive: true, kind: ScriptElementKind.functionElement, kindModifiers: "export", + tags: undefined }, ]); @@ -338,6 +341,7 @@ namespace ts.projectSystem { isCaseSensitive: true, kind: ScriptElementKind.functionElement, kindModifiers: "export", + tags: undefined }, { ...protocolFileSpanFromSubstring({ @@ -349,6 +353,7 @@ namespace ts.projectSystem { isCaseSensitive: true, kind: ScriptElementKind.functionElement, kindModifiers: "export", + tags: undefined }, { ...protocolFileSpanFromSubstring({ @@ -360,6 +365,7 @@ namespace ts.projectSystem { isCaseSensitive: true, kind: ScriptElementKind.functionElement, kindModifiers: "export", + tags: undefined } ]); }); @@ -378,6 +384,7 @@ namespace ts.projectSystem { isCaseSensitive: true, kind: ScriptElementKind.functionElement, kindModifiers: "export", + tags: undefined } ]); }); diff --git a/src/testRunner/unittests/tsserver/navTo.ts b/src/testRunner/unittests/tsserver/navTo.ts index 0ce98a076de3f..6b6e06d99f587 100644 --- a/src/testRunner/unittests/tsserver/navTo.ts +++ b/src/testRunner/unittests/tsserver/navTo.ts @@ -1,7 +1,11 @@ namespace ts.projectSystem { describe("unittests:: tsserver:: navigate-to for javascript project", () => { + function findNavToItem(items: protocol.NavtoItem[], itemName: string, itemKind: string) { + return find(items, item => item.name === itemName && item.kind === itemKind); + } + function containsNavToItem(items: protocol.NavtoItem[], itemName: string, itemKind: string) { - return find(items, item => item.name === itemName && item.kind === itemKind) !== undefined; + return findNavToItem(items, itemName, itemKind) !== undefined; } it("should not include type symbols", () => { @@ -67,5 +71,26 @@ export const ghijkl = a.abcdef;` assert.strictEqual(item.name, "abcdef"); assert.strictEqual(item.file, file1.path); }); + + it("should work with Deprecated", () => { + const file1: File = { + path: "/a/b/file1.js", + content: "/** @deprecated */\nfunction foo () {}" + }; + const configFile: File = { + path: "/a/b/jsconfig.json", + content: "{}" + }; + const host = createServerHost([file1, configFile, libFile]); + const session = createSession(host); + openFilesForSession([file1], session); + + // Try to find some interface type defined in lib.d.ts + const libTypeNavToRequest = makeSessionRequest(CommandNames.Navto, { searchValue: "foo", file: file1.path, projectFileName: configFile.path }); + const items = session.executeCommand(libTypeNavToRequest).response as protocol.NavtoItem[]; + const fooItem = findNavToItem(items, "foo", "function"); + assert.isNotNull(fooItem, `Cannot find function symbol "foo".`); + assert.isTrue(fooItem!.tags?.some(x => x === protocol.SymbolTag.Deprecated), "Cannot find deprecated tag"); + }); }); } diff --git a/tests/baselines/reference/api/tsserverlibrary.d.ts b/tests/baselines/reference/api/tsserverlibrary.d.ts index e89d9461ff314..e41ab4ea20a60 100644 --- a/tests/baselines/reference/api/tsserverlibrary.d.ts +++ b/tests/baselines/reference/api/tsserverlibrary.d.ts @@ -263,129 +263,129 @@ declare namespace ts { IndexedAccessType = 185, MappedType = 186, LiteralType = 187, - NamedTupleMember = 188, - ImportType = 189, - ObjectBindingPattern = 190, - ArrayBindingPattern = 191, - BindingElement = 192, - ArrayLiteralExpression = 193, - ObjectLiteralExpression = 194, - PropertyAccessExpression = 195, - ElementAccessExpression = 196, - CallExpression = 197, - NewExpression = 198, - TaggedTemplateExpression = 199, - TypeAssertionExpression = 200, - ParenthesizedExpression = 201, - FunctionExpression = 202, - ArrowFunction = 203, - DeleteExpression = 204, - TypeOfExpression = 205, - VoidExpression = 206, - AwaitExpression = 207, - PrefixUnaryExpression = 208, - PostfixUnaryExpression = 209, - BinaryExpression = 210, - ConditionalExpression = 211, - TemplateExpression = 212, - YieldExpression = 213, - SpreadElement = 214, - ClassExpression = 215, - OmittedExpression = 216, - ExpressionWithTypeArguments = 217, - AsExpression = 218, - NonNullExpression = 219, - MetaProperty = 220, - SyntheticExpression = 221, - TemplateSpan = 222, - SemicolonClassElement = 223, - Block = 224, - EmptyStatement = 225, - VariableStatement = 226, - ExpressionStatement = 227, - IfStatement = 228, - DoStatement = 229, - WhileStatement = 230, - ForStatement = 231, - ForInStatement = 232, - ForOfStatement = 233, - ContinueStatement = 234, - BreakStatement = 235, - ReturnStatement = 236, - WithStatement = 237, - SwitchStatement = 238, - LabeledStatement = 239, - ThrowStatement = 240, - TryStatement = 241, - DebuggerStatement = 242, - VariableDeclaration = 243, - VariableDeclarationList = 244, - FunctionDeclaration = 245, - ClassDeclaration = 246, - InterfaceDeclaration = 247, - TypeAliasDeclaration = 248, - EnumDeclaration = 249, - ModuleDeclaration = 250, - ModuleBlock = 251, - CaseBlock = 252, - NamespaceExportDeclaration = 253, - ImportEqualsDeclaration = 254, - ImportDeclaration = 255, - ImportClause = 256, - NamespaceImport = 257, - NamedImports = 258, - ImportSpecifier = 259, - ExportAssignment = 260, - ExportDeclaration = 261, - NamedExports = 262, - NamespaceExport = 263, - ExportSpecifier = 264, - MissingDeclaration = 265, - ExternalModuleReference = 266, - JsxElement = 267, - JsxSelfClosingElement = 268, - JsxOpeningElement = 269, - JsxClosingElement = 270, - JsxFragment = 271, - JsxOpeningFragment = 272, - JsxClosingFragment = 273, - JsxAttribute = 274, - JsxAttributes = 275, - JsxSpreadAttribute = 276, - JsxExpression = 277, - CaseClause = 278, - DefaultClause = 279, - HeritageClause = 280, - CatchClause = 281, - PropertyAssignment = 282, - ShorthandPropertyAssignment = 283, - SpreadAssignment = 284, - EnumMember = 285, - UnparsedPrologue = 286, - UnparsedPrepend = 287, - UnparsedText = 288, - UnparsedInternalText = 289, - UnparsedSyntheticReference = 290, - SourceFile = 291, - Bundle = 292, - UnparsedSource = 293, - InputFiles = 294, - JSDocTypeExpression = 295, - JSDocAllType = 296, - JSDocUnknownType = 297, - JSDocNullableType = 298, - JSDocNonNullableType = 299, - JSDocOptionalType = 300, - JSDocFunctionType = 301, - JSDocVariadicType = 302, - JSDocNamepathType = 303, - JSDocComment = 304, - JSDocTypeLiteral = 305, - JSDocSignature = 306, - JSDocTag = 307, - JSDocAugmentsTag = 308, - JSDocImplementsTag = 309, - JSDocAuthorTag = 310, + ImportType = 188, + ObjectBindingPattern = 189, + ArrayBindingPattern = 190, + BindingElement = 191, + ArrayLiteralExpression = 192, + ObjectLiteralExpression = 193, + PropertyAccessExpression = 194, + ElementAccessExpression = 195, + CallExpression = 196, + NewExpression = 197, + TaggedTemplateExpression = 198, + TypeAssertionExpression = 199, + ParenthesizedExpression = 200, + FunctionExpression = 201, + ArrowFunction = 202, + DeleteExpression = 203, + TypeOfExpression = 204, + VoidExpression = 205, + AwaitExpression = 206, + PrefixUnaryExpression = 207, + PostfixUnaryExpression = 208, + BinaryExpression = 209, + ConditionalExpression = 210, + TemplateExpression = 211, + YieldExpression = 212, + SpreadElement = 213, + ClassExpression = 214, + OmittedExpression = 215, + ExpressionWithTypeArguments = 216, + AsExpression = 217, + NonNullExpression = 218, + MetaProperty = 219, + SyntheticExpression = 220, + TemplateSpan = 221, + SemicolonClassElement = 222, + Block = 223, + EmptyStatement = 224, + VariableStatement = 225, + ExpressionStatement = 226, + IfStatement = 227, + DoStatement = 228, + WhileStatement = 229, + ForStatement = 230, + ForInStatement = 231, + ForOfStatement = 232, + ContinueStatement = 233, + BreakStatement = 234, + ReturnStatement = 235, + WithStatement = 236, + SwitchStatement = 237, + LabeledStatement = 238, + ThrowStatement = 239, + TryStatement = 240, + DebuggerStatement = 241, + VariableDeclaration = 242, + VariableDeclarationList = 243, + FunctionDeclaration = 244, + ClassDeclaration = 245, + InterfaceDeclaration = 246, + TypeAliasDeclaration = 247, + EnumDeclaration = 248, + ModuleDeclaration = 249, + ModuleBlock = 250, + CaseBlock = 251, + NamespaceExportDeclaration = 252, + ImportEqualsDeclaration = 253, + ImportDeclaration = 254, + ImportClause = 255, + NamespaceImport = 256, + NamedImports = 257, + ImportSpecifier = 258, + ExportAssignment = 259, + ExportDeclaration = 260, + NamedExports = 261, + NamespaceExport = 262, + ExportSpecifier = 263, + MissingDeclaration = 264, + ExternalModuleReference = 265, + JsxElement = 266, + JsxSelfClosingElement = 267, + JsxOpeningElement = 268, + JsxClosingElement = 269, + JsxFragment = 270, + JsxOpeningFragment = 271, + JsxClosingFragment = 272, + JsxAttribute = 273, + JsxAttributes = 274, + JsxSpreadAttribute = 275, + JsxExpression = 276, + CaseClause = 277, + DefaultClause = 278, + HeritageClause = 279, + CatchClause = 280, + PropertyAssignment = 281, + ShorthandPropertyAssignment = 282, + SpreadAssignment = 283, + EnumMember = 284, + UnparsedPrologue = 285, + UnparsedPrepend = 286, + UnparsedText = 287, + UnparsedInternalText = 288, + UnparsedSyntheticReference = 289, + SourceFile = 290, + Bundle = 291, + UnparsedSource = 292, + InputFiles = 293, + JSDocTypeExpression = 294, + JSDocAllType = 295, + JSDocUnknownType = 296, + JSDocNullableType = 297, + JSDocNonNullableType = 298, + JSDocOptionalType = 299, + JSDocFunctionType = 300, + JSDocVariadicType = 301, + JSDocNamepathType = 302, + JSDocComment = 303, + JSDocTypeLiteral = 304, + JSDocSignature = 305, + JSDocTag = 306, + JSDocAugmentsTag = 307, + JSDocImplementsTag = 308, + JSDocAuthorTag = 309, + JSDocDeprecatedTag = 310, JSDocClassTag = 311, JSDocPublicTag = 312, JSDocPrivateTag = 313, @@ -435,9 +435,9 @@ declare namespace ts { FirstStatement = 226, LastStatement = 242, FirstNode = 153, - FirstJSDocNode = 295, + FirstJSDocNode = 294, LastJSDocNode = 324, - FirstJSDocTagNode = 307, + FirstJSDocTagNode = 306, LastJSDocTagNode = 324, } export enum NodeFlags { @@ -1659,6 +1659,9 @@ declare namespace ts { export interface JSDocAuthorTag extends JSDocTag { kind: SyntaxKind.JSDocAuthorTag; } + export interface JSDocDeprecatedTag extends JSDocTag { + kind: SyntaxKind.JSDocDeprecatedTag; + } export interface JSDocClassTag extends JSDocTag { kind: SyntaxKind.JSDocClassTag; } @@ -3547,6 +3550,8 @@ declare namespace ts { function getJSDocReturnTag(node: Node): JSDocReturnTag | undefined; /** Gets the JSDoc template tag for the node if present */ function getJSDocTemplateTag(node: Node): JSDocTemplateTag | undefined; + /** Gets the JSDoc deprecated tag for the node if present */ + function getJSDocDeprecatedTag(node: Node): JSDocDeprecatedTag | undefined; /** Gets the JSDoc type tag for the node if present and valid */ function getJSDocTypeTag(node: Node): JSDocTypeTag | undefined; /** @@ -3761,6 +3766,7 @@ declare namespace ts { function isJSDocReturnTag(node: Node): node is JSDocReturnTag; function isJSDocTypeTag(node: Node): node is JSDocTypeTag; function isJSDocTemplateTag(node: Node): node is JSDocTemplateTag; + function isJSDocDeprecatedTag(node: Node): node is JSDocDeprecatedTag; function isJSDocTypedefTag(node: Node): node is JSDocTypedefTag; function isJSDocPropertyTag(node: Node): node is JSDocPropertyTag; function isJSDocPropertyLikeTag(node: Node): node is JSDocPropertyLikeTag; @@ -4273,6 +4279,7 @@ declare namespace ts { function createJSDocTypeLiteral(jsDocPropertyTags?: readonly JSDocPropertyLikeTag[], isArrayType?: boolean): JSDocTypeLiteral; function createJSDocImplementsTag(classExpression: JSDocImplementsTag["class"], comment?: string): JSDocImplementsTag; function createJSDocAuthorTag(comment?: string): JSDocTag; + function createJSDocDeprecatedTag(comment?: string): JSDocTag; function createJSDocPublicTag(): JSDocTag; function createJSDocPrivateTag(): JSDocTag; function createJSDocProtectedTag(): JSDocTag; @@ -5588,6 +5595,7 @@ declare namespace ts { textSpan: TextSpan; containerName: string; containerKind: ScriptElementKind; + isDeprecated: boolean; } enum IndentStyle { None = 0, @@ -8383,6 +8391,9 @@ declare namespace ts.server.protocol { command: CommandTypes.Navto; arguments: NavtoRequestArgs; } + enum SymbolTag { + Deprecated = 1 + } /** * An item found in a navto response. */ @@ -8416,6 +8427,10 @@ declare namespace ts.server.protocol { * Kind of symbol's container symbol (if any). */ containerKind?: ScriptElementKind; + /** + * The symbol's tag. + */ + tags?: SymbolTag[]; } /** * Navto response message. Body is an array of navto items. Each diff --git a/tests/baselines/reference/api/typescript.d.ts b/tests/baselines/reference/api/typescript.d.ts index 2213fd4be6a66..1ced43859c2c6 100644 --- a/tests/baselines/reference/api/typescript.d.ts +++ b/tests/baselines/reference/api/typescript.d.ts @@ -263,129 +263,129 @@ declare namespace ts { IndexedAccessType = 185, MappedType = 186, LiteralType = 187, - NamedTupleMember = 188, - ImportType = 189, - ObjectBindingPattern = 190, - ArrayBindingPattern = 191, - BindingElement = 192, - ArrayLiteralExpression = 193, - ObjectLiteralExpression = 194, - PropertyAccessExpression = 195, - ElementAccessExpression = 196, - CallExpression = 197, - NewExpression = 198, - TaggedTemplateExpression = 199, - TypeAssertionExpression = 200, - ParenthesizedExpression = 201, - FunctionExpression = 202, - ArrowFunction = 203, - DeleteExpression = 204, - TypeOfExpression = 205, - VoidExpression = 206, - AwaitExpression = 207, - PrefixUnaryExpression = 208, - PostfixUnaryExpression = 209, - BinaryExpression = 210, - ConditionalExpression = 211, - TemplateExpression = 212, - YieldExpression = 213, - SpreadElement = 214, - ClassExpression = 215, - OmittedExpression = 216, - ExpressionWithTypeArguments = 217, - AsExpression = 218, - NonNullExpression = 219, - MetaProperty = 220, - SyntheticExpression = 221, - TemplateSpan = 222, - SemicolonClassElement = 223, - Block = 224, - EmptyStatement = 225, - VariableStatement = 226, - ExpressionStatement = 227, - IfStatement = 228, - DoStatement = 229, - WhileStatement = 230, - ForStatement = 231, - ForInStatement = 232, - ForOfStatement = 233, - ContinueStatement = 234, - BreakStatement = 235, - ReturnStatement = 236, - WithStatement = 237, - SwitchStatement = 238, - LabeledStatement = 239, - ThrowStatement = 240, - TryStatement = 241, - DebuggerStatement = 242, - VariableDeclaration = 243, - VariableDeclarationList = 244, - FunctionDeclaration = 245, - ClassDeclaration = 246, - InterfaceDeclaration = 247, - TypeAliasDeclaration = 248, - EnumDeclaration = 249, - ModuleDeclaration = 250, - ModuleBlock = 251, - CaseBlock = 252, - NamespaceExportDeclaration = 253, - ImportEqualsDeclaration = 254, - ImportDeclaration = 255, - ImportClause = 256, - NamespaceImport = 257, - NamedImports = 258, - ImportSpecifier = 259, - ExportAssignment = 260, - ExportDeclaration = 261, - NamedExports = 262, - NamespaceExport = 263, - ExportSpecifier = 264, - MissingDeclaration = 265, - ExternalModuleReference = 266, - JsxElement = 267, - JsxSelfClosingElement = 268, - JsxOpeningElement = 269, - JsxClosingElement = 270, - JsxFragment = 271, - JsxOpeningFragment = 272, - JsxClosingFragment = 273, - JsxAttribute = 274, - JsxAttributes = 275, - JsxSpreadAttribute = 276, - JsxExpression = 277, - CaseClause = 278, - DefaultClause = 279, - HeritageClause = 280, - CatchClause = 281, - PropertyAssignment = 282, - ShorthandPropertyAssignment = 283, - SpreadAssignment = 284, - EnumMember = 285, - UnparsedPrologue = 286, - UnparsedPrepend = 287, - UnparsedText = 288, - UnparsedInternalText = 289, - UnparsedSyntheticReference = 290, - SourceFile = 291, - Bundle = 292, - UnparsedSource = 293, - InputFiles = 294, - JSDocTypeExpression = 295, - JSDocAllType = 296, - JSDocUnknownType = 297, - JSDocNullableType = 298, - JSDocNonNullableType = 299, - JSDocOptionalType = 300, - JSDocFunctionType = 301, - JSDocVariadicType = 302, - JSDocNamepathType = 303, - JSDocComment = 304, - JSDocTypeLiteral = 305, - JSDocSignature = 306, - JSDocTag = 307, - JSDocAugmentsTag = 308, - JSDocImplementsTag = 309, - JSDocAuthorTag = 310, + ImportType = 188, + ObjectBindingPattern = 189, + ArrayBindingPattern = 190, + BindingElement = 191, + ArrayLiteralExpression = 192, + ObjectLiteralExpression = 193, + PropertyAccessExpression = 194, + ElementAccessExpression = 195, + CallExpression = 196, + NewExpression = 197, + TaggedTemplateExpression = 198, + TypeAssertionExpression = 199, + ParenthesizedExpression = 200, + FunctionExpression = 201, + ArrowFunction = 202, + DeleteExpression = 203, + TypeOfExpression = 204, + VoidExpression = 205, + AwaitExpression = 206, + PrefixUnaryExpression = 207, + PostfixUnaryExpression = 208, + BinaryExpression = 209, + ConditionalExpression = 210, + TemplateExpression = 211, + YieldExpression = 212, + SpreadElement = 213, + ClassExpression = 214, + OmittedExpression = 215, + ExpressionWithTypeArguments = 216, + AsExpression = 217, + NonNullExpression = 218, + MetaProperty = 219, + SyntheticExpression = 220, + TemplateSpan = 221, + SemicolonClassElement = 222, + Block = 223, + EmptyStatement = 224, + VariableStatement = 225, + ExpressionStatement = 226, + IfStatement = 227, + DoStatement = 228, + WhileStatement = 229, + ForStatement = 230, + ForInStatement = 231, + ForOfStatement = 232, + ContinueStatement = 233, + BreakStatement = 234, + ReturnStatement = 235, + WithStatement = 236, + SwitchStatement = 237, + LabeledStatement = 238, + ThrowStatement = 239, + TryStatement = 240, + DebuggerStatement = 241, + VariableDeclaration = 242, + VariableDeclarationList = 243, + FunctionDeclaration = 244, + ClassDeclaration = 245, + InterfaceDeclaration = 246, + TypeAliasDeclaration = 247, + EnumDeclaration = 248, + ModuleDeclaration = 249, + ModuleBlock = 250, + CaseBlock = 251, + NamespaceExportDeclaration = 252, + ImportEqualsDeclaration = 253, + ImportDeclaration = 254, + ImportClause = 255, + NamespaceImport = 256, + NamedImports = 257, + ImportSpecifier = 258, + ExportAssignment = 259, + ExportDeclaration = 260, + NamedExports = 261, + NamespaceExport = 262, + ExportSpecifier = 263, + MissingDeclaration = 264, + ExternalModuleReference = 265, + JsxElement = 266, + JsxSelfClosingElement = 267, + JsxOpeningElement = 268, + JsxClosingElement = 269, + JsxFragment = 270, + JsxOpeningFragment = 271, + JsxClosingFragment = 272, + JsxAttribute = 273, + JsxAttributes = 274, + JsxSpreadAttribute = 275, + JsxExpression = 276, + CaseClause = 277, + DefaultClause = 278, + HeritageClause = 279, + CatchClause = 280, + PropertyAssignment = 281, + ShorthandPropertyAssignment = 282, + SpreadAssignment = 283, + EnumMember = 284, + UnparsedPrologue = 285, + UnparsedPrepend = 286, + UnparsedText = 287, + UnparsedInternalText = 288, + UnparsedSyntheticReference = 289, + SourceFile = 290, + Bundle = 291, + UnparsedSource = 292, + InputFiles = 293, + JSDocTypeExpression = 294, + JSDocAllType = 295, + JSDocUnknownType = 296, + JSDocNullableType = 297, + JSDocNonNullableType = 298, + JSDocOptionalType = 299, + JSDocFunctionType = 300, + JSDocVariadicType = 301, + JSDocNamepathType = 302, + JSDocComment = 303, + JSDocTypeLiteral = 304, + JSDocSignature = 305, + JSDocTag = 306, + JSDocAugmentsTag = 307, + JSDocImplementsTag = 308, + JSDocAuthorTag = 309, + JSDocDeprecatedTag = 310, JSDocClassTag = 311, JSDocPublicTag = 312, JSDocPrivateTag = 313, @@ -435,9 +435,9 @@ declare namespace ts { FirstStatement = 226, LastStatement = 242, FirstNode = 153, - FirstJSDocNode = 295, + FirstJSDocNode = 294, LastJSDocNode = 324, - FirstJSDocTagNode = 307, + FirstJSDocTagNode = 306, LastJSDocTagNode = 324, } export enum NodeFlags { @@ -1659,6 +1659,9 @@ declare namespace ts { export interface JSDocAuthorTag extends JSDocTag { kind: SyntaxKind.JSDocAuthorTag; } + export interface JSDocDeprecatedTag extends JSDocTag { + kind: SyntaxKind.JSDocDeprecatedTag; + } export interface JSDocClassTag extends JSDocTag { kind: SyntaxKind.JSDocClassTag; } @@ -3547,6 +3550,8 @@ declare namespace ts { function getJSDocReturnTag(node: Node): JSDocReturnTag | undefined; /** Gets the JSDoc template tag for the node if present */ function getJSDocTemplateTag(node: Node): JSDocTemplateTag | undefined; + /** Gets the JSDoc deprecated tag for the node if present */ + function getJSDocDeprecatedTag(node: Node): JSDocDeprecatedTag | undefined; /** Gets the JSDoc type tag for the node if present and valid */ function getJSDocTypeTag(node: Node): JSDocTypeTag | undefined; /** @@ -3761,6 +3766,7 @@ declare namespace ts { function isJSDocReturnTag(node: Node): node is JSDocReturnTag; function isJSDocTypeTag(node: Node): node is JSDocTypeTag; function isJSDocTemplateTag(node: Node): node is JSDocTemplateTag; + function isJSDocDeprecatedTag(node: Node): node is JSDocDeprecatedTag; function isJSDocTypedefTag(node: Node): node is JSDocTypedefTag; function isJSDocPropertyTag(node: Node): node is JSDocPropertyTag; function isJSDocPropertyLikeTag(node: Node): node is JSDocPropertyLikeTag; @@ -4273,6 +4279,7 @@ declare namespace ts { function createJSDocTypeLiteral(jsDocPropertyTags?: readonly JSDocPropertyLikeTag[], isArrayType?: boolean): JSDocTypeLiteral; function createJSDocImplementsTag(classExpression: JSDocImplementsTag["class"], comment?: string): JSDocImplementsTag; function createJSDocAuthorTag(comment?: string): JSDocTag; + function createJSDocDeprecatedTag(comment?: string): JSDocTag; function createJSDocPublicTag(): JSDocTag; function createJSDocPrivateTag(): JSDocTag; function createJSDocProtectedTag(): JSDocTag; @@ -5588,6 +5595,7 @@ declare namespace ts { textSpan: TextSpan; containerName: string; containerKind: ScriptElementKind; + isDeprecated: boolean; } enum IndentStyle { None = 0, From 5a8da1694f7d30a0a78185d79eb9e6370bf329c0 Mon Sep 17 00:00:00 2001 From: kingwl Date: Thu, 14 May 2020 00:57:28 +0800 Subject: [PATCH 02/38] Add more support --- src/compiler/builder.ts | 1 + src/compiler/checker.ts | 9 +++++++++ src/compiler/diagnosticMessages.json | 4 ++++ src/compiler/types.ts | 3 +++ src/harness/client.ts | 11 ++++++----- src/server/protocol.ts | 6 ++++++ src/server/session.ts | 7 ++++--- src/services/callHierarchy.ts | 2 +- src/services/completions.ts | 13 +++++++++---- src/services/jsDoc.ts | 3 ++- src/services/types.ts | 2 ++ 11 files changed, 47 insertions(+), 14 deletions(-) diff --git a/src/compiler/builder.ts b/src/compiler/builder.ts index d5a1e16f2f1d1..8afb1a1b4c248 100644 --- a/src/compiler/builder.ts +++ b/src/compiler/builder.ts @@ -3,6 +3,7 @@ namespace ts { export interface ReusableDiagnostic extends ReusableDiagnosticRelatedInformation { /** May store more in future. For now, this will simply be `true` to indicate when a diagnostic is an unused-identifier diagnostic. */ reportsUnnecessary?: {}; + reportDeprecated?: {} source?: string; relatedInformation?: ReusableDiagnosticRelatedInformation[]; } diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 7bd58c379eac9..c669d3af65894 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -31336,6 +31336,13 @@ namespace ts { error(classLike, Diagnostics.JSDoc_0_is_not_attached_to_a_class, idText(node.tagName)); } } + + function checkJSDocDeprecatedTag(node: JSDocDeprecatedTag): void { + const diag = Diagnostics._0_is_deprecated; + diag.reportsDeprecated = true; + errorOrSuggestion(/* isError */ false, node.parent, diag, "test") + } + function checkJSDocAugmentsTag(node: JSDocAugmentsTag): void { const classLike = getEffectiveJSDocHost(node); if (!classLike || !isClassDeclaration(classLike) && !isClassExpression(classLike)) { @@ -34904,6 +34911,8 @@ namespace ts { return checkJSDocAugmentsTag(node as JSDocAugmentsTag); case SyntaxKind.JSDocImplementsTag: return checkJSDocImplementsTag(node as JSDocImplementsTag); + case SyntaxKind.JSDocDeprecatedTag: + return checkJSDocDeprecatedTag(node as JSDocDeprecatedTag); case SyntaxKind.JSDocTypedefTag: case SyntaxKind.JSDocCallbackTag: case SyntaxKind.JSDocEnumTag: diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index df3192652aca9..091f16c11927e 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -4590,6 +4590,10 @@ "category": "Message", "code": 6384 }, + "'{0}' is deprecated": { + "category": "Suggestion", + "code": 6385 + }, "The expected type comes from property '{0}' which is declared here on type '{1}'": { "category": "Message", diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 70ab5e74696e3..52b2d599428a8 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -5044,6 +5044,7 @@ namespace ts { code: number; message: string; reportsUnnecessary?: {}; + reportsDeprecated?: {}; /* @internal */ elidedInCompatabilityPyramid?: boolean; } @@ -5064,6 +5065,8 @@ namespace ts { export interface Diagnostic extends DiagnosticRelatedInformation { /** May store more in future. For now, this will simply be `true` to indicate when a diagnostic is an unused-identifier diagnostic. */ reportsUnnecessary?: {}; + + reportsDeprecated?: {} source?: string; relatedInformation?: DiagnosticRelatedInformation[]; } diff --git a/src/harness/client.ts b/src/harness/client.ts index 63b613b0cf7c3..8977a68c79085 100644 --- a/src/harness/client.ts +++ b/src/harness/client.ts @@ -198,14 +198,14 @@ namespace ts.server { isNewIdentifierLocation: false, entries: response.body!.map(entry => { // TODO: GH#18217 if (entry.replacementSpan !== undefined) { - const { name, kind, kindModifiers, sortText, replacementSpan, hasAction, source, isRecommended } = entry; + const { name, kind, kindModifiers, sortText, replacementSpan, hasAction, source, isRecommended, tags } = entry; // TODO: GH#241 - const res: CompletionEntry = { name, kind, kindModifiers, sortText, replacementSpan: this.decodeSpan(replacementSpan, fileName), hasAction, source, isRecommended }; + const res: CompletionEntry = { name, kind, kindModifiers, sortText, replacementSpan: this.decodeSpan(replacementSpan, fileName), hasAction, source, isRecommended, isDeprecated: tags?.includes(protocol.SymbolTag.Deprecated) }; return res; } - return entry as { name: string, kind: ScriptElementKind, kindModifiers: string, sortText: string }; // TODO: GH#18217 - }) + const { name, kind, kindModifiers, sortText, tags } = entry; + return { name, kind, kindModifiers, sortText, isDeprecated: tags?.includes(protocol.SymbolTag.Deprecated) } }) }; } @@ -750,7 +750,8 @@ namespace ts.server { name: item.name, kind: item.kind, span: this.decodeSpan(item.span, item.file), - selectionSpan: this.decodeSpan(item.selectionSpan, item.file) + selectionSpan: this.decodeSpan(item.selectionSpan, item.file), + isDeprecated: item.tags?.includes(protocol.SymbolTag.Deprecated) }; } diff --git a/src/server/protocol.ts b/src/server/protocol.ts index 182b0255804e4..c88be018f71ec 100644 --- a/src/server/protocol.ts +++ b/src/server/protocol.ts @@ -2154,6 +2154,11 @@ namespace ts.server.protocol { * and therefore may not be accurate. */ isFromUncheckedFile?: true; + + /** + * Exist if the item has some symbol Tag. + */ + tags?: SymbolTag[] } /** @@ -3074,6 +3079,7 @@ namespace ts.server.protocol { file: string; span: TextSpan; selectionSpan: TextSpan; + tags?: SymbolTag[] } export interface CallHierarchyIncomingCall { diff --git a/src/server/session.ts b/src/server/session.ts index c39bd21d23a3d..99988b8635efe 100644 --- a/src/server/session.ts +++ b/src/server/session.ts @@ -1661,10 +1661,10 @@ namespace ts.server { const prefix = args.prefix || ""; const entries = mapDefined(completions.entries, entry => { if (completions.isMemberCompletion || startsWith(entry.name.toLowerCase(), prefix.toLowerCase())) { - const { name, kind, kindModifiers, sortText, insertText, replacementSpan, hasAction, source, isRecommended } = entry; + const { name, kind, kindModifiers, sortText, insertText, replacementSpan, hasAction, source, isRecommended, isDeprecated } = entry; const convertedSpan = replacementSpan ? toProtocolTextSpan(replacementSpan, scriptInfo) : undefined; // Use `hasAction || undefined` to avoid serializing `false`. - return { name, kind, kindModifiers, sortText, insertText, replacementSpan: convertedSpan, hasAction: hasAction || undefined, source, isRecommended }; + return { name, kind, kindModifiers, sortText, insertText, replacementSpan: convertedSpan, hasAction: hasAction || undefined, source, isRecommended, tags: isDeprecated ? [protocol.SymbolTag.Deprecated] : undefined }; } }).sort((a, b) => compareStringsCaseSensitiveUI(a.name, b.name)); @@ -2224,7 +2224,8 @@ namespace ts.server { kind: item.kind, file: item.file, span: toProtocolTextSpan(item.span, scriptInfo), - selectionSpan: toProtocolTextSpan(item.selectionSpan, scriptInfo) + selectionSpan: toProtocolTextSpan(item.selectionSpan, scriptInfo), + tags: item.isDeprecated ? [protocol.SymbolTag.Deprecated] : undefined }; } diff --git a/src/services/callHierarchy.ts b/src/services/callHierarchy.ts index bbf28ac8f1101..c853195b5c3ff 100644 --- a/src/services/callHierarchy.ts +++ b/src/services/callHierarchy.ts @@ -248,7 +248,7 @@ namespace ts.CallHierarchy { const kind = getNodeKind(node); const span = createTextSpanFromBounds(skipTrivia(sourceFile.text, node.getFullStart(), /*stopAfterLineBreak*/ false, /*stopAtComments*/ true), node.getEnd()); const selectionSpan = createTextSpanFromBounds(name.pos, name.end); - return { file: sourceFile.fileName, kind, name: name.text, span, selectionSpan }; + return { file: sourceFile.fileName, kind, name: name.text, span, selectionSpan, isDeprecated: !!getJSDocDeprecatedTag(node) }; } function isDefined(x: T): x is NonNullable { diff --git a/src/services/completions.ts b/src/services/completions.ts index 8b9228d3441ad..f130101f4d907 100644 --- a/src/services/completions.ts +++ b/src/services/completions.ts @@ -235,6 +235,7 @@ namespace ts.Completions { kind: ScriptElementKind.classElement, kindModifiers: undefined, sortText: SortText.LocationPriority, + isDeprecated: undefined }; return { isGlobalCompletion: false, isMemberCompletion: true, isNewIdentifierLocation: false, entries: [entry] }; } @@ -337,7 +338,8 @@ namespace ts.Completions { kind: ScriptElementKind.warning, kindModifiers: "", sortText: SortText.JavascriptIdentifiers, - isFromUncheckedFile: true + isFromUncheckedFile: true, + isDeprecated: undefined }); } }); @@ -349,7 +351,7 @@ namespace ts.Completions { } function createCompletionEntryForLiteral(literal: string | number | PseudoBigInt, preferences: UserPreferences): CompletionEntry { - return { name: completionNameForLiteral(literal, preferences), kind: ScriptElementKind.string, kindModifiers: ScriptElementKindModifier.none, sortText: SortText.LocationPriority }; + return { name: completionNameForLiteral(literal, preferences), kind: ScriptElementKind.string, kindModifiers: ScriptElementKindModifier.none, sortText: SortText.LocationPriority, isDeprecated: undefined }; } function createCompletionEntry( @@ -437,6 +439,7 @@ namespace ts.Completions { isRecommended: isRecommendedCompletionMatch(symbol, recommendedCompletion, typeChecker) || undefined, insertText, replacementSpan, + isDeprecated: symbol.declarations.some(decl => getJSDocDeprecatedTag(decl)) }; } @@ -558,7 +561,8 @@ namespace ts.Completions { name, kindModifiers: ScriptElementKindModifier.none, kind: ScriptElementKind.label, - sortText: SortText.LocationPriority + sortText: SortText.LocationPriority, + isDeprecated: undefined }); } } @@ -2517,7 +2521,8 @@ namespace ts.Completions { name: tokenToString(i)!, kind: ScriptElementKind.keyword, kindModifiers: ScriptElementKindModifier.none, - sortText: SortText.GlobalsOrKeywords + sortText: SortText.GlobalsOrKeywords, + isDeprecated: undefined }); } return res; diff --git a/src/services/jsDoc.ts b/src/services/jsDoc.ts index 3115109572a0d..de766acf64d27 100644 --- a/src/services/jsDoc.ts +++ b/src/services/jsDoc.ts @@ -164,6 +164,7 @@ namespace ts.JsDoc { kind: ScriptElementKind.keyword, kindModifiers: "", sortText: "0", + isDeprecated: undefined }; })); } @@ -211,7 +212,7 @@ namespace ts.JsDoc { return undefined; } - return { name, kind: ScriptElementKind.parameterElement, kindModifiers: "", sortText: "0" }; + return { name, kind: ScriptElementKind.parameterElement, kindModifiers: "", sortText: "0", isDeprecated: undefined }; }); } diff --git a/src/services/types.ts b/src/services/types.ts index 6aa60b85fff0d..05d2c8d7f82e3 100644 --- a/src/services/types.ts +++ b/src/services/types.ts @@ -615,6 +615,7 @@ namespace ts { file: string; span: TextSpan; selectionSpan: TextSpan; + isDeprecated?: boolean } export interface CallHierarchyIncomingCall { @@ -1072,6 +1073,7 @@ namespace ts { source?: string; isRecommended?: true; isFromUncheckedFile?: true; + isDeprecated?: boolean } export interface CompletionEntryDetails { From 2deadaa1d37ee2245c86070907557004c26e9049 Mon Sep 17 00:00:00 2001 From: kingwl Date: Thu, 14 May 2020 01:55:35 +0800 Subject: [PATCH 03/38] fix navtree --- src/harness/client.ts | 3 ++- src/server/protocol.ts | 1 + src/server/session.ts | 3 ++- src/services/navigationBar.ts | 3 ++- src/services/types.ts | 1 + 5 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/harness/client.ts b/src/harness/client.ts index 8977a68c79085..8167fb87247e3 100644 --- a/src/harness/client.ts +++ b/src/harness/client.ts @@ -491,7 +491,8 @@ namespace ts.server { kindModifiers: tree.kindModifiers, spans: tree.spans.map(span => this.decodeSpan(span, fileName, lineMap)), nameSpan: tree.nameSpan && this.decodeSpan(tree.nameSpan, fileName, lineMap), - childItems: map(tree.childItems, item => this.decodeNavigationTree(item, fileName, lineMap)) + childItems: map(tree.childItems, item => this.decodeNavigationTree(item, fileName, lineMap)), + isDeprecated: !!tree.tags?.includes(protocol.SymbolTag.Deprecated) }; } diff --git a/src/server/protocol.ts b/src/server/protocol.ts index c88be018f71ec..e10dadc0d65cb 100644 --- a/src/server/protocol.ts +++ b/src/server/protocol.ts @@ -2974,6 +2974,7 @@ namespace ts.server.protocol { spans: TextSpan[]; nameSpan: TextSpan | undefined; childItems?: NavigationTree[]; + tags?: SymbolTag[] } export type TelemetryEventName = "telemetry"; diff --git a/src/server/session.ts b/src/server/session.ts index 99988b8635efe..dbe46b66c5feb 100644 --- a/src/server/session.ts +++ b/src/server/session.ts @@ -1860,7 +1860,8 @@ namespace ts.server { kindModifiers: tree.kindModifiers, spans: tree.spans.map(span => toProtocolTextSpan(span, scriptInfo)), nameSpan: tree.nameSpan && toProtocolTextSpan(tree.nameSpan, scriptInfo), - childItems: map(tree.childItems, item => this.toLocationNavigationTree(item, scriptInfo)) + childItems: map(tree.childItems, item => this.toLocationNavigationTree(item, scriptInfo)), + tags: tree.isDeprecated ? [protocol.SymbolTag.Deprecated] : undefined }; } diff --git a/src/services/navigationBar.ts b/src/services/navigationBar.ts index 91bf61270dea4..289b40679f4bf 100644 --- a/src/services/navigationBar.ts +++ b/src/services/navigationBar.ts @@ -793,7 +793,8 @@ namespace ts.NavigationBar { kindModifiers: getModifiers(n.node), spans: getSpans(n), nameSpan: n.name && getNodeSpan(n.name), - childItems: map(n.children, convertToTree) + childItems: map(n.children, convertToTree), + isDeprecated: !!getJSDocDeprecatedTag(n.node) }; } diff --git a/src/services/types.ts b/src/services/types.ts index 05d2c8d7f82e3..b5013d86d873b 100644 --- a/src/services/types.ts +++ b/src/services/types.ts @@ -607,6 +607,7 @@ namespace ts { nameSpan: TextSpan | undefined; /** Present if non-empty */ childItems?: NavigationTree[]; + isDeprecated: boolean } export interface CallHierarchyItem { From 9847ffb8cb7a52bedab5225a14dba18b82dc7e1e Mon Sep 17 00:00:00 2001 From: kingwl Date: Thu, 14 May 2020 14:35:46 +0800 Subject: [PATCH 04/38] Add identifier check --- src/compiler/builder.ts | 2 ++ src/compiler/checker.ts | 13 +++++-------- src/compiler/utilities.ts | 2 ++ src/harness/client.ts | 1 + src/harness/fourslashImpl.ts | 1 + src/harness/fourslashInterfaceImpl.ts | 2 ++ src/server/protocol.ts | 4 ++++ src/server/session.ts | 4 ++++ src/services/shims.ts | 3 +++ 9 files changed, 24 insertions(+), 8 deletions(-) diff --git a/src/compiler/builder.ts b/src/compiler/builder.ts index 8afb1a1b4c248..0ae2e7ca0c291 100644 --- a/src/compiler/builder.ts +++ b/src/compiler/builder.ts @@ -268,6 +268,7 @@ namespace ts { return diagnostics.map(diagnostic => { const result: Diagnostic = convertToDiagnosticRelatedInformation(diagnostic, newProgram, toPath); result.reportsUnnecessary = diagnostic.reportsUnnecessary; + result.reportsDeprecated = diagnostic.reportDeprecated; result.source = diagnostic.source; const { relatedInformation } = diagnostic; result.relatedInformation = relatedInformation ? @@ -802,6 +803,7 @@ namespace ts { return diagnostics.map(diagnostic => { const result: ReusableDiagnostic = convertToReusableDiagnosticRelatedInformation(diagnostic, relativeToBuildInfo); result.reportsUnnecessary = diagnostic.reportsUnnecessary; + result.reportDeprecated = diagnostic.reportsDeprecated; result.source = diagnostic.source; const { relatedInformation } = diagnostic; result.relatedInformation = relatedInformation ? diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index c669d3af65894..bc239cf63c82f 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -21453,6 +21453,11 @@ namespace ts { const localOrExportSymbol = getExportSymbolOfValueSymbolIfExported(symbol); let declaration: Declaration | undefined = localOrExportSymbol.valueDeclaration; + if (getJSDocDeprecatedTag(declaration)) { + const diag = Diagnostics._0_is_deprecated + diag.reportsDeprecated = true + errorOrSuggestion(false, node, diag, node.escapedText as string) + } if (localOrExportSymbol.flags & SymbolFlags.Class) { // Due to the emit for class decorators, any reference to the class from inside of the class body @@ -31337,12 +31342,6 @@ namespace ts { } } - function checkJSDocDeprecatedTag(node: JSDocDeprecatedTag): void { - const diag = Diagnostics._0_is_deprecated; - diag.reportsDeprecated = true; - errorOrSuggestion(/* isError */ false, node.parent, diag, "test") - } - function checkJSDocAugmentsTag(node: JSDocAugmentsTag): void { const classLike = getEffectiveJSDocHost(node); if (!classLike || !isClassDeclaration(classLike) && !isClassExpression(classLike)) { @@ -34911,8 +34910,6 @@ namespace ts { return checkJSDocAugmentsTag(node as JSDocAugmentsTag); case SyntaxKind.JSDocImplementsTag: return checkJSDocImplementsTag(node as JSDocImplementsTag); - case SyntaxKind.JSDocDeprecatedTag: - return checkJSDocDeprecatedTag(node as JSDocDeprecatedTag); case SyntaxKind.JSDocTypedefTag: case SyntaxKind.JSDocCallbackTag: case SyntaxKind.JSDocEnumTag: diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index 17ce0562122e0..fd9a5adfe1458 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -5353,6 +5353,7 @@ namespace ts { category: message.category, code: message.code, reportsUnnecessary: message.reportsUnnecessary, + reportsDeprecated: message.reportsDeprecated }; } @@ -5384,6 +5385,7 @@ namespace ts { category: message.category, code: message.code, reportsUnnecessary: message.reportsUnnecessary, + reportsDeprecated: message.reportsDeprecated }; } diff --git a/src/harness/client.ts b/src/harness/client.ts index 8167fb87247e3..20fe29f146c01 100644 --- a/src/harness/client.ts +++ b/src/harness/client.ts @@ -389,6 +389,7 @@ namespace ts.server { category: Debug.checkDefined(category, "convertDiagnostic: category should not be undefined"), code: entry.code, reportsUnnecessary: entry.reportsUnnecessary, + reportsDeprecated: entry.reportsDeprecated }; }); } diff --git a/src/harness/fourslashImpl.ts b/src/harness/fourslashImpl.ts index e6c9849bdb537..d7a9a448982ee 100644 --- a/src/harness/fourslashImpl.ts +++ b/src/harness/fourslashImpl.ts @@ -1218,6 +1218,7 @@ namespace FourSlash { code: e.code, ...ts.createTextSpanFromRange(range), reportsUnnecessary: e.reportsUnnecessary, + reportsDeprecated: e.reportsDeprecated }; })); } diff --git a/src/harness/fourslashInterfaceImpl.ts b/src/harness/fourslashInterfaceImpl.ts index c24c565a81bcf..17d7d7fa8120a 100644 --- a/src/harness/fourslashInterfaceImpl.ts +++ b/src/harness/fourslashInterfaceImpl.ts @@ -1609,6 +1609,8 @@ namespace FourSlashInterface { range?: FourSlash.Range; code: number; reportsUnnecessary?: true; + + reportsDeprecated?: true; } export interface GetEditsForFileRenameOptions { diff --git a/src/server/protocol.ts b/src/server/protocol.ts index e10dadc0d65cb..99c55999c2c22 100644 --- a/src/server/protocol.ts +++ b/src/server/protocol.ts @@ -498,6 +498,8 @@ namespace ts.server.protocol { code: number; /** May store more in future. For now, this will simply be `true` to indicate when a diagnostic is an unused-identifier diagnostic. */ reportsUnnecessary?: {}; + + reportsDeprecated?: {}; relatedInformation?: DiagnosticRelatedInformation[]; } @@ -2536,6 +2538,8 @@ namespace ts.server.protocol { reportsUnnecessary?: {}; + reportsDeprecated?: {}; + /** * Any related spans the diagnostic may have, such as other locations relevant to an error, such as declarartion sites */ diff --git a/src/server/session.ts b/src/server/session.ts index dbe46b66c5feb..2e9b96d85168d 100644 --- a/src/server/session.ts +++ b/src/server/session.ts @@ -56,6 +56,7 @@ namespace ts.server { code: diag.code, category: diagnosticCategoryName(diag), reportsUnnecessary: diag.reportsUnnecessary, + reportsDeprecated: diag.reportsDeprecated, source: diag.source, relatedInformation: map(diag.relatedInformation, formatRelatedInformation), }; @@ -100,6 +101,7 @@ namespace ts.server { code, category, reportsUnnecessary: diag.reportsUnnecessary, + reportsDeprecated: diag.reportsDeprecated, source, relatedInformation: map(diag.relatedInformation, formatRelatedInformation), }; @@ -1018,6 +1020,7 @@ namespace ts.server { startLocation: (d.file && convertToLocation(getLineAndCharacterOfPosition(d.file, d.start!)))!, // TODO: GH#18217 endLocation: (d.file && convertToLocation(getLineAndCharacterOfPosition(d.file, d.start! + d.length!)))!, // TODO: GH#18217 reportsUnnecessary: d.reportsUnnecessary, + reportsDeprecated: d.reportsDeprecated, relatedInformation: map(d.relatedInformation, formatRelatedInformation) })); } @@ -1047,6 +1050,7 @@ namespace ts.server { startLocation: scriptInfo && scriptInfo.positionToLineOffset(d.start!), // TODO: GH#18217 endLocation: scriptInfo && scriptInfo.positionToLineOffset(d.start! + d.length!), reportsUnnecessary: d.reportsUnnecessary, + reportsDeprecated: d.reportsDeprecated, relatedInformation: map(d.relatedInformation, formatRelatedInformation), }); } diff --git a/src/services/shims.ts b/src/services/shims.ts index 6cecfeaa674fc..4ba69f8f971ec 100644 --- a/src/services/shims.ts +++ b/src/services/shims.ts @@ -601,6 +601,8 @@ namespace ts { category: string; code: number; reportsUnnecessary?: {}; + + reportsDeprecated?: {} } export function realizeDiagnostics(diagnostics: readonly Diagnostic[], newLine: string): RealizedDiagnostic[] { return diagnostics.map(d => realizeDiagnostic(d, newLine)); @@ -614,6 +616,7 @@ namespace ts { category: diagnosticCategoryName(diagnostic), code: diagnostic.code, reportsUnnecessary: diagnostic.reportsUnnecessary, + reportsDeprecated: diagnostic.reportsDeprecated }; } From 06c8d22b783b5912ffb49f0e473c544d36ab97ef Mon Sep 17 00:00:00 2001 From: kingwl Date: Thu, 14 May 2020 18:30:07 +0800 Subject: [PATCH 05/38] Add more deprecated --- src/compiler/checker.ts | 30 ++++++++++++++++++++++++------ 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index bc239cf63c82f..64dfac9e61842 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -12962,6 +12962,11 @@ namespace ts { if (propName !== undefined) { const prop = getPropertyOfType(objectType, propName); if (prop) { + if (accessNode && prop.declarations.some(getJSDocDeprecatedTag)) { + const diag = Diagnostics._0_is_deprecated + diag.reportsDeprecated = true + errorOrSuggestion(false, accessNode, diag, "fff") + } if (accessExpression) { markPropertyAsReferenced(prop, accessExpression, /*isThisAccess*/ accessExpression.expression.kind === SyntaxKind.ThisKeyword); if (isAssignmentToReadonlyEntity(accessExpression, prop, getAssignmentTargetKind(accessExpression))) { @@ -21424,6 +21429,12 @@ namespace ts { return errorType; } + if (symbol.declarations.some(getJSDocDeprecatedTag)) { + const diag = Diagnostics._0_is_deprecated + diag.reportsDeprecated = true + errorOrSuggestion(false, node, diag, node.escapedText as string) + } + // As noted in ECMAScript 6 language spec, arrow functions never have an arguments objects. // Although in down-level emit of arrow function, we emit it using function expression which means that // arguments objects will be bound to the inner object; emitting arrow function natively in ES6, arguments objects @@ -21453,11 +21464,6 @@ namespace ts { const localOrExportSymbol = getExportSymbolOfValueSymbolIfExported(symbol); let declaration: Declaration | undefined = localOrExportSymbol.valueDeclaration; - if (getJSDocDeprecatedTag(declaration)) { - const diag = Diagnostics._0_is_deprecated - diag.reportsDeprecated = true - errorOrSuggestion(false, node, diag, node.escapedText as string) - } if (localOrExportSymbol.flags & SymbolFlags.Class) { // Due to the emit for class decorators, any reference to the class from inside of the class body @@ -24426,6 +24432,12 @@ namespace ts { propType = indexInfo.type; } else { + if (prop.declarations.some(getJSDocDeprecatedTag)) { + const diag = Diagnostics._0_is_deprecated + diag.reportsDeprecated = true + errorOrSuggestion(false, node, diag, "foo") + } + checkPropertyNotUsedBeforeDeclaration(prop, node, right); markPropertyAsReferenced(prop, node, left.kind === SyntaxKind.ThisKeyword); getNodeLinks(node).resolvedSymbol = prop; @@ -30196,7 +30208,13 @@ namespace ts { checkTypeArgumentConstraints(node, typeParameters); } } - if (type.flags & TypeFlags.Enum && getNodeLinks(node).resolvedSymbol!.flags & SymbolFlags.EnumMember) { + const symbol = getNodeLinks(node).resolvedSymbol! + if (symbol.declarations.some(getJSDocDeprecatedTag)) { + const diag = Diagnostics._0_is_deprecated + diag.reportsDeprecated = true + errorOrSuggestion(false, node, diag, "foo") + } + if (type.flags & TypeFlags.Enum && symbol.flags & SymbolFlags.EnumMember) { error(node, Diagnostics.Enum_type_0_has_members_with_initializers_that_are_not_literals, typeToString(type)); } } From 03d1ffe479b3fd57ea30415a9d933a79fc2dad9e Mon Sep 17 00:00:00 2001 From: kingwl Date: Thu, 14 May 2020 19:14:09 +0800 Subject: [PATCH 06/38] fix crash --- src/compiler/checker.ts | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 64dfac9e61842..aa137e68f9a99 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -12962,7 +12962,7 @@ namespace ts { if (propName !== undefined) { const prop = getPropertyOfType(objectType, propName); if (prop) { - if (accessNode && prop.declarations.some(getJSDocDeprecatedTag)) { + if (accessNode && some(prop.declarations, decl => !!getJSDocDeprecatedTag(decl))) { const diag = Diagnostics._0_is_deprecated diag.reportsDeprecated = true errorOrSuggestion(false, accessNode, diag, "fff") @@ -21429,12 +21429,6 @@ namespace ts { return errorType; } - if (symbol.declarations.some(getJSDocDeprecatedTag)) { - const diag = Diagnostics._0_is_deprecated - diag.reportsDeprecated = true - errorOrSuggestion(false, node, diag, node.escapedText as string) - } - // As noted in ECMAScript 6 language spec, arrow functions never have an arguments objects. // Although in down-level emit of arrow function, we emit it using function expression which means that // arguments objects will be bound to the inner object; emitting arrow function natively in ES6, arguments objects @@ -21465,6 +21459,12 @@ namespace ts { const localOrExportSymbol = getExportSymbolOfValueSymbolIfExported(symbol); let declaration: Declaration | undefined = localOrExportSymbol.valueDeclaration; + if (some(symbol.declarations, decl => !!getJSDocDeprecatedTag(decl))) { + const diag = Diagnostics._0_is_deprecated + diag.reportsDeprecated = true + errorOrSuggestion(false, node, diag, node.escapedText as string) + } + if (localOrExportSymbol.flags & SymbolFlags.Class) { // Due to the emit for class decorators, any reference to the class from inside of the class body // must instead be rewritten to point to a temporary variable to avoid issues with the double-bind @@ -24432,7 +24432,7 @@ namespace ts { propType = indexInfo.type; } else { - if (prop.declarations.some(getJSDocDeprecatedTag)) { + if (some(prop.declarations, decl => !!getJSDocDeprecatedTag(decl))) { const diag = Diagnostics._0_is_deprecated diag.reportsDeprecated = true errorOrSuggestion(false, node, diag, "foo") @@ -30209,7 +30209,7 @@ namespace ts { } } const symbol = getNodeLinks(node).resolvedSymbol! - if (symbol.declarations.some(getJSDocDeprecatedTag)) { + if (some(symbol.declarations, decl => !!getJSDocDeprecatedTag(decl))) { const diag = Diagnostics._0_is_deprecated diag.reportsDeprecated = true errorOrSuggestion(false, node, diag, "foo") From 30cea12902a1c74ca8af7bd0c11eaced6d510be2 Mon Sep 17 00:00:00 2001 From: kingwl Date: Thu, 14 May 2020 19:28:27 +0800 Subject: [PATCH 07/38] fix more crash --- src/services/completions.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/services/completions.ts b/src/services/completions.ts index f130101f4d907..ae0122eff259f 100644 --- a/src/services/completions.ts +++ b/src/services/completions.ts @@ -439,7 +439,7 @@ namespace ts.Completions { isRecommended: isRecommendedCompletionMatch(symbol, recommendedCompletion, typeChecker) || undefined, insertText, replacementSpan, - isDeprecated: symbol.declarations.some(decl => getJSDocDeprecatedTag(decl)) + isDeprecated: some(symbol.declarations, decl => !!getJSDocDeprecatedTag(decl)) }; } From 13bdb758636385c9f2edfc7d5e9210231bf9f39d Mon Sep 17 00:00:00 2001 From: kingwl Date: Thu, 14 May 2020 20:33:45 +0800 Subject: [PATCH 08/38] fix crash --- src/compiler/checker.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index aa137e68f9a99..e1f6daf555246 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -21459,7 +21459,7 @@ namespace ts { const localOrExportSymbol = getExportSymbolOfValueSymbolIfExported(symbol); let declaration: Declaration | undefined = localOrExportSymbol.valueDeclaration; - if (some(symbol.declarations, decl => !!getJSDocDeprecatedTag(decl))) { + if (symbol && some(symbol.declarations, decl => !!getJSDocDeprecatedTag(decl))) { const diag = Diagnostics._0_is_deprecated diag.reportsDeprecated = true errorOrSuggestion(false, node, diag, node.escapedText as string) @@ -30209,7 +30209,7 @@ namespace ts { } } const symbol = getNodeLinks(node).resolvedSymbol! - if (some(symbol.declarations, decl => !!getJSDocDeprecatedTag(decl))) { + if (symbol && some(symbol.declarations, decl => !!getJSDocDeprecatedTag(decl))) { const diag = Diagnostics._0_is_deprecated diag.reportsDeprecated = true errorOrSuggestion(false, node, diag, "foo") From 1b3e477d0857e9ee81db488517490013610c2794 Mon Sep 17 00:00:00 2001 From: kingwl Date: Sat, 16 May 2020 08:44:54 +0800 Subject: [PATCH 09/38] improve diagnostic --- scripts/processDiagnosticMessages.ts | 11 +++++++---- src/compiler/checker.ts | 16 ++++------------ src/compiler/diagnosticMessages.json | 3 ++- 3 files changed, 13 insertions(+), 17 deletions(-) diff --git a/scripts/processDiagnosticMessages.ts b/scripts/processDiagnosticMessages.ts index 7577707340aa0..eeb6debfa56b9 100644 --- a/scripts/processDiagnosticMessages.ts +++ b/scripts/processDiagnosticMessages.ts @@ -5,6 +5,7 @@ interface DiagnosticDetails { category: string; code: number; reportsUnnecessary?: {}; + reportsDeprecated?: {}; isEarly?: boolean; elidedInCompatabilityPyramid?: boolean; } @@ -64,15 +65,17 @@ function buildInfoFileOutput(messageTable: InputDiagnosticMessageTable, inputFil "// generated from '" + inputFilePathRel + "' by '" + thisFilePathRel.replace(/\\/g, "/") + "'\r\n" + "/* @internal */\r\n" + "namespace ts {\r\n" + - " function diag(code: number, category: DiagnosticCategory, key: string, message: string, reportsUnnecessary?: {}, elidedInCompatabilityPyramid?: boolean): DiagnosticMessage {\r\n" + - " return { code, category, key, message, reportsUnnecessary, elidedInCompatabilityPyramid };\r\n" + + " function diag(code: number, category: DiagnosticCategory, key: string, message: string, reportsUnnecessary?: {}, elidedInCompatabilityPyramid?: boolean, reportsDeprecated?: {}): DiagnosticMessage {\r\n" + + " return { code, category, key, message, reportsUnnecessary, elidedInCompatabilityPyramid, reportsDeprecated };\r\n" + " }\r\n" + " export const Diagnostics = {\r\n"; - messageTable.forEach(({ code, category, reportsUnnecessary, elidedInCompatabilityPyramid }, name) => { + messageTable.forEach(({ code, category, reportsUnnecessary, elidedInCompatabilityPyramid, reportsDeprecated }, name) => { const propName = convertPropertyName(name); const argReportsUnnecessary = reportsUnnecessary ? `, /*reportsUnnecessary*/ ${reportsUnnecessary}` : ""; const argElidedInCompatabilityPyramid = elidedInCompatabilityPyramid ? `${!reportsUnnecessary ? ", /*reportsUnnecessary*/ undefined" : ""}, /*elidedInCompatabilityPyramid*/ ${elidedInCompatabilityPyramid}` : ""; - result += ` ${propName}: diag(${code}, DiagnosticCategory.${category}, "${createKey(propName, code)}", ${JSON.stringify(name)}${argReportsUnnecessary}${argElidedInCompatabilityPyramid}),\r\n`; + const argReportsDeprecated = reportsDeprecated ? `${!argElidedInCompatabilityPyramid ? ", /*reportsUnnecessary*/ undefined, /*elidedInCompatabilityPyramid*/ undefined" : ""}, /*reportsDeprecated*/ ${reportsDeprecated}` : ""; + + result += ` ${propName}: diag(${code}, DiagnosticCategory.${category}, "${createKey(propName, code)}", ${JSON.stringify(name)}${argReportsUnnecessary}${argElidedInCompatabilityPyramid}${argReportsDeprecated}),\r\n`; }); result += " };\r\n}"; diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index e1f6daf555246..5cf0d756ce4b3 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -12963,9 +12963,7 @@ namespace ts { const prop = getPropertyOfType(objectType, propName); if (prop) { if (accessNode && some(prop.declarations, decl => !!getJSDocDeprecatedTag(decl))) { - const diag = Diagnostics._0_is_deprecated - diag.reportsDeprecated = true - errorOrSuggestion(false, accessNode, diag, "fff") + errorOrSuggestion(false, accessNode, Diagnostics._0_is_deprecated, propName as string) } if (accessExpression) { markPropertyAsReferenced(prop, accessExpression, /*isThisAccess*/ accessExpression.expression.kind === SyntaxKind.ThisKeyword); @@ -21460,9 +21458,7 @@ namespace ts { let declaration: Declaration | undefined = localOrExportSymbol.valueDeclaration; if (symbol && some(symbol.declarations, decl => !!getJSDocDeprecatedTag(decl))) { - const diag = Diagnostics._0_is_deprecated - diag.reportsDeprecated = true - errorOrSuggestion(false, node, diag, node.escapedText as string) + errorOrSuggestion(false, node, Diagnostics._0_is_deprecated, node.escapedText as string) } if (localOrExportSymbol.flags & SymbolFlags.Class) { @@ -24433,9 +24429,7 @@ namespace ts { } else { if (some(prop.declarations, decl => !!getJSDocDeprecatedTag(decl))) { - const diag = Diagnostics._0_is_deprecated - diag.reportsDeprecated = true - errorOrSuggestion(false, node, diag, "foo") + errorOrSuggestion(false, node, Diagnostics._0_is_deprecated, right.escapedText as string) } checkPropertyNotUsedBeforeDeclaration(prop, node, right); @@ -30210,9 +30204,7 @@ namespace ts { } const symbol = getNodeLinks(node).resolvedSymbol! if (symbol && some(symbol.declarations, decl => !!getJSDocDeprecatedTag(decl))) { - const diag = Diagnostics._0_is_deprecated - diag.reportsDeprecated = true - errorOrSuggestion(false, node, diag, "foo") + errorOrSuggestion(false, node, Diagnostics._0_is_deprecated, symbol.escapedName as string) } if (type.flags & TypeFlags.Enum && symbol.flags & SymbolFlags.EnumMember) { error(node, Diagnostics.Enum_type_0_has_members_with_initializers_that_are_not_literals, typeToString(type)); diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index 091f16c11927e..1da11f99af58c 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -4592,7 +4592,8 @@ }, "'{0}' is deprecated": { "category": "Suggestion", - "code": 6385 + "code": 6385, + "reportsDeprecated": true }, "The expected type comes from property '{0}' which is declared here on type '{1}'": { From f794e118619d41cdd03566d805944ca1eba8fc7f Mon Sep 17 00:00:00 2001 From: kingwl Date: Sun, 17 May 2020 10:03:08 +0800 Subject: [PATCH 10/38] avoid new tag --- src/harness/client.ts | 19 +++++++++---------- src/harness/fourslashImpl.ts | 3 +-- src/harness/fourslashInterfaceImpl.ts | 1 - src/server/protocol.ts | 17 +---------------- src/services/callHierarchy.ts | 3 ++- src/services/completions.ts | 17 ++++++----------- src/services/jsDoc.ts | 5 ++--- src/services/navigateTo.ts | 1 - src/services/navigationBar.ts | 3 +-- src/services/types.ts | 7 +++---- src/services/utilities.ts | 1 + 11 files changed, 26 insertions(+), 51 deletions(-) diff --git a/src/harness/client.ts b/src/harness/client.ts index 20fe29f146c01..de3fa8f5352a1 100644 --- a/src/harness/client.ts +++ b/src/harness/client.ts @@ -198,14 +198,15 @@ namespace ts.server { isNewIdentifierLocation: false, entries: response.body!.map(entry => { // TODO: GH#18217 if (entry.replacementSpan !== undefined) { - const { name, kind, kindModifiers, sortText, replacementSpan, hasAction, source, isRecommended, tags } = entry; + const { name, kind, kindModifiers, sortText, replacementSpan, hasAction, source, isRecommended } = entry; // TODO: GH#241 - const res: CompletionEntry = { name, kind, kindModifiers, sortText, replacementSpan: this.decodeSpan(replacementSpan, fileName), hasAction, source, isRecommended, isDeprecated: tags?.includes(protocol.SymbolTag.Deprecated) }; + const res: CompletionEntry = { name, kind, kindModifiers, sortText, replacementSpan: this.decodeSpan(replacementSpan, fileName), hasAction, source, isRecommended }; return res; } - const { name, kind, kindModifiers, sortText, tags } = entry; - return { name, kind, kindModifiers, sortText, isDeprecated: tags?.includes(protocol.SymbolTag.Deprecated) } }) + const { name, kind, kindModifiers, sortText } = entry; + return { name, kind, kindModifiers, sortText } + }) }; } @@ -241,8 +242,7 @@ namespace ts.server { matchKind: entry.matchKind as keyof typeof PatternMatchKind, isCaseSensitive: entry.isCaseSensitive, fileName: entry.file, - textSpan: this.decodeSpan(entry), - isDeprecated: !!entry.tags?.includes(protocol.SymbolTag.Deprecated) + textSpan: this.decodeSpan(entry) })); } @@ -492,8 +492,7 @@ namespace ts.server { kindModifiers: tree.kindModifiers, spans: tree.spans.map(span => this.decodeSpan(span, fileName, lineMap)), nameSpan: tree.nameSpan && this.decodeSpan(tree.nameSpan, fileName, lineMap), - childItems: map(tree.childItems, item => this.decodeNavigationTree(item, fileName, lineMap)), - isDeprecated: !!tree.tags?.includes(protocol.SymbolTag.Deprecated) + childItems: map(tree.childItems, item => this.decodeNavigationTree(item, fileName, lineMap)) }; } @@ -751,9 +750,9 @@ namespace ts.server { file: item.file, name: item.name, kind: item.kind, + kindModifiers: item.kindModifiers, span: this.decodeSpan(item.span, item.file), - selectionSpan: this.decodeSpan(item.selectionSpan, item.file), - isDeprecated: item.tags?.includes(protocol.SymbolTag.Deprecated) + selectionSpan: this.decodeSpan(item.selectionSpan, item.file) }; } diff --git a/src/harness/fourslashImpl.ts b/src/harness/fourslashImpl.ts index d7a9a448982ee..d69edb48e32a2 100644 --- a/src/harness/fourslashImpl.ts +++ b/src/harness/fourslashImpl.ts @@ -2988,8 +2988,7 @@ namespace FourSlash { fileName: e.range.fileName, textSpan: ts.createTextSpanFromRange(e.range), containerName: e.containerName || "", - containerKind: e.containerKind || ts.ScriptElementKind.unknown, - isDeprecated: !!e.isDeprecated + containerKind: e.containerKind || ts.ScriptElementKind.unknown }))); } } diff --git a/src/harness/fourslashInterfaceImpl.ts b/src/harness/fourslashInterfaceImpl.ts index 17d7d7fa8120a..1283589acd1ae 100644 --- a/src/harness/fourslashInterfaceImpl.ts +++ b/src/harness/fourslashInterfaceImpl.ts @@ -1545,7 +1545,6 @@ namespace FourSlashInterface { readonly range: FourSlash.Range; readonly containerName?: string; readonly containerKind?: ts.ScriptElementKind; - readonly isDeprecated?: boolean } export type ArrayOrSingle = T | readonly T[]; diff --git a/src/server/protocol.ts b/src/server/protocol.ts index 99c55999c2c22..4086e10d8b981 100644 --- a/src/server/protocol.ts +++ b/src/server/protocol.ts @@ -2156,11 +2156,6 @@ namespace ts.server.protocol { * and therefore may not be accurate. */ isFromUncheckedFile?: true; - - /** - * Exist if the item has some symbol Tag. - */ - tags?: SymbolTag[] } /** @@ -2827,10 +2822,6 @@ namespace ts.server.protocol { arguments: NavtoRequestArgs; } - export enum SymbolTag { - Deprecated = 1 - } - /** * An item found in a navto response. */ @@ -2870,11 +2861,6 @@ namespace ts.server.protocol { * Kind of symbol's container symbol (if any). */ containerKind?: ScriptElementKind; - - /** - * The symbol's tag. - */ - tags?: SymbolTag[] } /** @@ -2978,7 +2964,6 @@ namespace ts.server.protocol { spans: TextSpan[]; nameSpan: TextSpan | undefined; childItems?: NavigationTree[]; - tags?: SymbolTag[] } export type TelemetryEventName = "telemetry"; @@ -3081,10 +3066,10 @@ namespace ts.server.protocol { export interface CallHierarchyItem { name: string; kind: ScriptElementKind; + kindModifiers?: string file: string; span: TextSpan; selectionSpan: TextSpan; - tags?: SymbolTag[] } export interface CallHierarchyIncomingCall { diff --git a/src/services/callHierarchy.ts b/src/services/callHierarchy.ts index c853195b5c3ff..1bfac203affbd 100644 --- a/src/services/callHierarchy.ts +++ b/src/services/callHierarchy.ts @@ -246,9 +246,10 @@ namespace ts.CallHierarchy { const sourceFile = node.getSourceFile(); const name = getCallHierarchyItemName(program, node); const kind = getNodeKind(node); + const kindModifiers = getNodeModifiers(node); const span = createTextSpanFromBounds(skipTrivia(sourceFile.text, node.getFullStart(), /*stopAfterLineBreak*/ false, /*stopAtComments*/ true), node.getEnd()); const selectionSpan = createTextSpanFromBounds(name.pos, name.end); - return { file: sourceFile.fileName, kind, name: name.text, span, selectionSpan, isDeprecated: !!getJSDocDeprecatedTag(node) }; + return { file: sourceFile.fileName, kind, kindModifiers, name: name.text, span, selectionSpan }; } function isDefined(x: T): x is NonNullable { diff --git a/src/services/completions.ts b/src/services/completions.ts index ae0122eff259f..3eab998ec499b 100644 --- a/src/services/completions.ts +++ b/src/services/completions.ts @@ -234,8 +234,7 @@ namespace ts.Completions { name: tagName.getFullText(sourceFile) + (hasClosingAngleBracket ? "" : ">"), kind: ScriptElementKind.classElement, kindModifiers: undefined, - sortText: SortText.LocationPriority, - isDeprecated: undefined + sortText: SortText.LocationPriority }; return { isGlobalCompletion: false, isMemberCompletion: true, isNewIdentifierLocation: false, entries: [entry] }; } @@ -338,8 +337,7 @@ namespace ts.Completions { kind: ScriptElementKind.warning, kindModifiers: "", sortText: SortText.JavascriptIdentifiers, - isFromUncheckedFile: true, - isDeprecated: undefined + isFromUncheckedFile: true }); } }); @@ -351,7 +349,7 @@ namespace ts.Completions { } function createCompletionEntryForLiteral(literal: string | number | PseudoBigInt, preferences: UserPreferences): CompletionEntry { - return { name: completionNameForLiteral(literal, preferences), kind: ScriptElementKind.string, kindModifiers: ScriptElementKindModifier.none, sortText: SortText.LocationPriority, isDeprecated: undefined }; + return { name: completionNameForLiteral(literal, preferences), kind: ScriptElementKind.string, kindModifiers: ScriptElementKindModifier.none, sortText: SortText.LocationPriority }; } function createCompletionEntry( @@ -438,8 +436,7 @@ namespace ts.Completions { hasAction: origin && originIsExport(origin) || undefined, isRecommended: isRecommendedCompletionMatch(symbol, recommendedCompletion, typeChecker) || undefined, insertText, - replacementSpan, - isDeprecated: some(symbol.declarations, decl => !!getJSDocDeprecatedTag(decl)) + replacementSpan }; } @@ -561,8 +558,7 @@ namespace ts.Completions { name, kindModifiers: ScriptElementKindModifier.none, kind: ScriptElementKind.label, - sortText: SortText.LocationPriority, - isDeprecated: undefined + sortText: SortText.LocationPriority }); } } @@ -2521,8 +2517,7 @@ namespace ts.Completions { name: tokenToString(i)!, kind: ScriptElementKind.keyword, kindModifiers: ScriptElementKindModifier.none, - sortText: SortText.GlobalsOrKeywords, - isDeprecated: undefined + sortText: SortText.GlobalsOrKeywords }); } return res; diff --git a/src/services/jsDoc.ts b/src/services/jsDoc.ts index de766acf64d27..6e7963073bd12 100644 --- a/src/services/jsDoc.ts +++ b/src/services/jsDoc.ts @@ -163,8 +163,7 @@ namespace ts.JsDoc { name: tagName, kind: ScriptElementKind.keyword, kindModifiers: "", - sortText: "0", - isDeprecated: undefined + sortText: "0" }; })); } @@ -212,7 +211,7 @@ namespace ts.JsDoc { return undefined; } - return { name, kind: ScriptElementKind.parameterElement, kindModifiers: "", sortText: "0", isDeprecated: undefined }; + return { name, kind: ScriptElementKind.parameterElement, kindModifiers: "", sortText: "0" }; }); } diff --git a/src/services/navigateTo.ts b/src/services/navigateTo.ts index caf913a5444cb..bcd0fbe273682 100644 --- a/src/services/navigateTo.ts +++ b/src/services/navigateTo.ts @@ -131,7 +131,6 @@ namespace ts.NavigateTo { // TODO(jfreeman): What should be the containerName when the container has a computed name? containerName: containerName ? (containerName).text : "", containerKind: containerName ? getNodeKind(container!) : ScriptElementKind.unknown, // TODO: GH#18217 Just use `container ? ...` - isDeprecated: !!getJSDocDeprecatedTag(rawItem.declaration) }; } } diff --git a/src/services/navigationBar.ts b/src/services/navigationBar.ts index 289b40679f4bf..91bf61270dea4 100644 --- a/src/services/navigationBar.ts +++ b/src/services/navigationBar.ts @@ -793,8 +793,7 @@ namespace ts.NavigationBar { kindModifiers: getModifiers(n.node), spans: getSpans(n), nameSpan: n.name && getNodeSpan(n.name), - childItems: map(n.children, convertToTree), - isDeprecated: !!getJSDocDeprecatedTag(n.node) + childItems: map(n.children, convertToTree) }; } diff --git a/src/services/types.ts b/src/services/types.ts index b5013d86d873b..b9da022baa16c 100644 --- a/src/services/types.ts +++ b/src/services/types.ts @@ -607,16 +607,15 @@ namespace ts { nameSpan: TextSpan | undefined; /** Present if non-empty */ childItems?: NavigationTree[]; - isDeprecated: boolean } export interface CallHierarchyItem { name: string; kind: ScriptElementKind; + kindModifiers?: string; file: string; span: TextSpan; selectionSpan: TextSpan; - isDeprecated?: boolean } export interface CallHierarchyIncomingCall { @@ -809,7 +808,6 @@ namespace ts { textSpan: TextSpan; containerName: string; containerKind: ScriptElementKind; - isDeprecated: boolean } export enum IndentStyle { @@ -1074,7 +1072,6 @@ namespace ts { source?: string; isRecommended?: true; isFromUncheckedFile?: true; - isDeprecated?: boolean } export interface CompletionEntryDetails { @@ -1299,6 +1296,8 @@ namespace ts { abstractModifier = "abstract", optionalModifier = "optional", + deprecatedModifier = "deprecated", + dtsModifier = ".d.ts", tsModifier = ".ts", tsxModifier = ".tsx", diff --git a/src/services/utilities.ts b/src/services/utilities.ts index b1799167c437b..2fbf0d2cc955b 100644 --- a/src/services/utilities.ts +++ b/src/services/utilities.ts @@ -1506,6 +1506,7 @@ namespace ts { if (flags & ModifierFlags.Export) result.push(ScriptElementKindModifier.exportedModifier); if (node.flags & NodeFlags.Ambient) result.push(ScriptElementKindModifier.ambientModifier); if (node.kind === SyntaxKind.ExportAssignment) result.push(ScriptElementKindModifier.exportedModifier); + if (getJSDocDeprecatedTag(node)) result.push(ScriptElementKindModifier.deprecatedModifier); return result.length > 0 ? result.join(",") : ScriptElementKindModifier.none; } From 9d27ab3f669224d4187a9f6fe60bafb23e1a58ad Mon Sep 17 00:00:00 2001 From: kingwl Date: Sun, 17 May 2020 15:33:57 +0800 Subject: [PATCH 11/38] avoid tags --- src/server/session.ts | 9 ++++----- src/testRunner/unittests/tsserver/declarationFileMaps.ts | 9 +-------- src/testRunner/unittests/tsserver/navTo.ts | 2 +- 3 files changed, 6 insertions(+), 14 deletions(-) diff --git a/src/server/session.ts b/src/server/session.ts index 2e9b96d85168d..149da1ac29c3f 100644 --- a/src/server/session.ts +++ b/src/server/session.ts @@ -1665,10 +1665,10 @@ namespace ts.server { const prefix = args.prefix || ""; const entries = mapDefined(completions.entries, entry => { if (completions.isMemberCompletion || startsWith(entry.name.toLowerCase(), prefix.toLowerCase())) { - const { name, kind, kindModifiers, sortText, insertText, replacementSpan, hasAction, source, isRecommended, isDeprecated } = entry; + const { name, kind, kindModifiers, sortText, insertText, replacementSpan, hasAction, source, isRecommended } = entry; const convertedSpan = replacementSpan ? toProtocolTextSpan(replacementSpan, scriptInfo) : undefined; // Use `hasAction || undefined` to avoid serializing `false`. - return { name, kind, kindModifiers, sortText, insertText, replacementSpan: convertedSpan, hasAction: hasAction || undefined, source, isRecommended, tags: isDeprecated ? [protocol.SymbolTag.Deprecated] : undefined }; + return { name, kind, kindModifiers, sortText, insertText, replacementSpan: convertedSpan, hasAction: hasAction || undefined, source, isRecommended }; } }).sort((a, b) => compareStringsCaseSensitiveUI(a.name, b.name)); @@ -1865,7 +1865,6 @@ namespace ts.server { spans: tree.spans.map(span => toProtocolTextSpan(span, scriptInfo)), nameSpan: tree.nameSpan && toProtocolTextSpan(tree.nameSpan, scriptInfo), childItems: map(tree.childItems, item => this.toLocationNavigationTree(item, scriptInfo)), - tags: tree.isDeprecated ? [protocol.SymbolTag.Deprecated] : undefined }; } @@ -1887,12 +1886,12 @@ namespace ts.server { const bakedItem: protocol.NavtoItem = { name: navItem.name, kind: navItem.kind, + kindModifiers: navItem.kindModifiers, isCaseSensitive: navItem.isCaseSensitive, matchKind: navItem.matchKind, file: navItem.fileName, start: scriptInfo.positionToLineOffset(navItem.textSpan.start), end: scriptInfo.positionToLineOffset(textSpanEnd(navItem.textSpan)), - tags: navItem.isDeprecated ? [protocol.SymbolTag.Deprecated] : undefined }; if (navItem.kindModifiers && (navItem.kindModifiers !== "")) { bakedItem.kindModifiers = navItem.kindModifiers; @@ -2227,10 +2226,10 @@ namespace ts.server { return { name: item.name, kind: item.kind, + kindModifiers: item.kindModifiers, file: item.file, span: toProtocolTextSpan(item.span, scriptInfo), selectionSpan: toProtocolTextSpan(item.selectionSpan, scriptInfo), - tags: item.isDeprecated ? [protocol.SymbolTag.Deprecated] : undefined }; } diff --git a/src/testRunner/unittests/tsserver/declarationFileMaps.ts b/src/testRunner/unittests/tsserver/declarationFileMaps.ts index ee9e68b5f5b50..0a3aef4de9067 100644 --- a/src/testRunner/unittests/tsserver/declarationFileMaps.ts +++ b/src/testRunner/unittests/tsserver/declarationFileMaps.ts @@ -295,8 +295,7 @@ namespace ts.projectSystem { matchKind: "prefix", isCaseSensitive: true, kind: ScriptElementKind.functionElement, - kindModifiers: "export,declare", - tags: undefined + kindModifiers: "export,declare" }, { ...protocolFileSpanFromSubstring({ @@ -308,7 +307,6 @@ namespace ts.projectSystem { isCaseSensitive: true, kind: ScriptElementKind.functionElement, kindModifiers: "export", - tags: undefined }, { ...protocolFileSpanFromSubstring({ @@ -320,7 +318,6 @@ namespace ts.projectSystem { isCaseSensitive: true, kind: ScriptElementKind.functionElement, kindModifiers: "export", - tags: undefined }, ]); @@ -341,7 +338,6 @@ namespace ts.projectSystem { isCaseSensitive: true, kind: ScriptElementKind.functionElement, kindModifiers: "export", - tags: undefined }, { ...protocolFileSpanFromSubstring({ @@ -353,7 +349,6 @@ namespace ts.projectSystem { isCaseSensitive: true, kind: ScriptElementKind.functionElement, kindModifiers: "export", - tags: undefined }, { ...protocolFileSpanFromSubstring({ @@ -365,7 +360,6 @@ namespace ts.projectSystem { isCaseSensitive: true, kind: ScriptElementKind.functionElement, kindModifiers: "export", - tags: undefined } ]); }); @@ -384,7 +378,6 @@ namespace ts.projectSystem { isCaseSensitive: true, kind: ScriptElementKind.functionElement, kindModifiers: "export", - tags: undefined } ]); }); diff --git a/src/testRunner/unittests/tsserver/navTo.ts b/src/testRunner/unittests/tsserver/navTo.ts index 6b6e06d99f587..113db9855999f 100644 --- a/src/testRunner/unittests/tsserver/navTo.ts +++ b/src/testRunner/unittests/tsserver/navTo.ts @@ -90,7 +90,7 @@ export const ghijkl = a.abcdef;` const items = session.executeCommand(libTypeNavToRequest).response as protocol.NavtoItem[]; const fooItem = findNavToItem(items, "foo", "function"); assert.isNotNull(fooItem, `Cannot find function symbol "foo".`); - assert.isTrue(fooItem!.tags?.some(x => x === protocol.SymbolTag.Deprecated), "Cannot find deprecated tag"); + assert.isTrue(fooItem?.kindModifiers?.includes("deprecated")) }); }); } From 36f4226d8578be8910420a73698d6d4ef2da231f Mon Sep 17 00:00:00 2001 From: kingwl Date: Sun, 17 May 2020 15:40:33 +0800 Subject: [PATCH 12/38] accept baseline --- .../baselines/reference/api/tsserverlibrary.d.ts | 15 +++++++-------- tests/baselines/reference/api/typescript.d.ts | 5 ++++- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/tests/baselines/reference/api/tsserverlibrary.d.ts b/tests/baselines/reference/api/tsserverlibrary.d.ts index e41ab4ea20a60..290b3e9346251 100644 --- a/tests/baselines/reference/api/tsserverlibrary.d.ts +++ b/tests/baselines/reference/api/tsserverlibrary.d.ts @@ -2580,6 +2580,7 @@ declare namespace ts { code: number; message: string; reportsUnnecessary?: {}; + reportsDeprecated?: {}; } /** * A linked list of formatted diagnostic messages to be used as part of a multiline message. @@ -2596,6 +2597,7 @@ declare namespace ts { export interface Diagnostic extends DiagnosticRelatedInformation { /** May store more in future. For now, this will simply be `true` to indicate when a diagnostic is an unused-identifier diagnostic. */ reportsUnnecessary?: {}; + reportsDeprecated?: {}; source?: string; relatedInformation?: DiagnosticRelatedInformation[]; } @@ -5431,6 +5433,7 @@ declare namespace ts { interface CallHierarchyItem { name: string; kind: ScriptElementKind; + kindModifiers?: string; file: string; span: TextSpan; selectionSpan: TextSpan; @@ -5595,7 +5598,6 @@ declare namespace ts { textSpan: TextSpan; containerName: string; containerKind: ScriptElementKind; - isDeprecated: boolean; } enum IndentStyle { None = 0, @@ -5979,6 +5981,7 @@ declare namespace ts { staticModifier = "static", abstractModifier = "abstract", optionalModifier = "optional", + deprecatedModifier = "deprecated", dtsModifier = ".d.ts", tsModifier = ".ts", tsxModifier = ".tsx", @@ -6601,6 +6604,7 @@ declare namespace ts.server.protocol { code: number; /** May store more in future. For now, this will simply be `true` to indicate when a diagnostic is an unused-identifier diagnostic. */ reportsUnnecessary?: {}; + reportsDeprecated?: {}; relatedInformation?: DiagnosticRelatedInformation[]; } /** @@ -8151,6 +8155,7 @@ declare namespace ts.server.protocol { */ category: string; reportsUnnecessary?: {}; + reportsDeprecated?: {}; /** * Any related spans the diagnostic may have, such as other locations relevant to an error, such as declarartion sites */ @@ -8391,9 +8396,6 @@ declare namespace ts.server.protocol { command: CommandTypes.Navto; arguments: NavtoRequestArgs; } - enum SymbolTag { - Deprecated = 1 - } /** * An item found in a navto response. */ @@ -8427,10 +8429,6 @@ declare namespace ts.server.protocol { * Kind of symbol's container symbol (if any). */ containerKind?: ScriptElementKind; - /** - * The symbol's tag. - */ - tags?: SymbolTag[]; } /** * Navto response message. Body is an array of navto items. Each @@ -8594,6 +8592,7 @@ declare namespace ts.server.protocol { interface CallHierarchyItem { name: string; kind: ScriptElementKind; + kindModifiers?: string; file: string; span: TextSpan; selectionSpan: TextSpan; diff --git a/tests/baselines/reference/api/typescript.d.ts b/tests/baselines/reference/api/typescript.d.ts index 1ced43859c2c6..7dc484c6da5f9 100644 --- a/tests/baselines/reference/api/typescript.d.ts +++ b/tests/baselines/reference/api/typescript.d.ts @@ -2580,6 +2580,7 @@ declare namespace ts { code: number; message: string; reportsUnnecessary?: {}; + reportsDeprecated?: {}; } /** * A linked list of formatted diagnostic messages to be used as part of a multiline message. @@ -2596,6 +2597,7 @@ declare namespace ts { export interface Diagnostic extends DiagnosticRelatedInformation { /** May store more in future. For now, this will simply be `true` to indicate when a diagnostic is an unused-identifier diagnostic. */ reportsUnnecessary?: {}; + reportsDeprecated?: {}; source?: string; relatedInformation?: DiagnosticRelatedInformation[]; } @@ -5431,6 +5433,7 @@ declare namespace ts { interface CallHierarchyItem { name: string; kind: ScriptElementKind; + kindModifiers?: string; file: string; span: TextSpan; selectionSpan: TextSpan; @@ -5595,7 +5598,6 @@ declare namespace ts { textSpan: TextSpan; containerName: string; containerKind: ScriptElementKind; - isDeprecated: boolean; } enum IndentStyle { None = 0, @@ -5979,6 +5981,7 @@ declare namespace ts { staticModifier = "static", abstractModifier = "abstract", optionalModifier = "optional", + deprecatedModifier = "deprecated", dtsModifier = ".d.ts", tsModifier = ".ts", tsxModifier = ".tsx", From 6df251f405680f31b218af2cfe9945a8c7046ad4 Mon Sep 17 00:00:00 2001 From: kingwl Date: Mon, 18 May 2020 15:03:27 +0800 Subject: [PATCH 13/38] Check deprecated in binder --- src/compiler/binder.ts | 2 ++ src/compiler/checker.ts | 13 +++++++------ src/compiler/types.ts | 2 ++ 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/src/compiler/binder.ts b/src/compiler/binder.ts index 8809c34d06053..ffe733594e385 100644 --- a/src/compiler/binder.ts +++ b/src/compiler/binder.ts @@ -414,6 +414,7 @@ namespace ts { Debug.assert(!hasDynamicName(node)); const isDefaultExport = hasSyntacticModifier(node, ModifierFlags.Default) || isExportSpecifier(node) && node.name.escapedText === "default"; + const isDeprecated = !!getJSDocDeprecatedTag(node); // The exported symbol for an export default function/class node is always named "default" const name = isDefaultExport && parent ? InternalSymbolName.Default : getDeclarationName(node); @@ -533,6 +534,7 @@ namespace ts { } } + symbol.isDeprecated = symbol.isDeprecated || isDeprecated; addDeclarationToSymbol(symbol, node, includes); if (symbol.parent) { Debug.assert(symbol.parent === parent, "Existing symbol parent should match new one"); diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 5cf0d756ce4b3..95e8facae9654 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -12962,8 +12962,9 @@ namespace ts { if (propName !== undefined) { const prop = getPropertyOfType(objectType, propName); if (prop) { - if (accessNode && some(prop.declarations, decl => !!getJSDocDeprecatedTag(decl))) { - errorOrSuggestion(false, accessNode, Diagnostics._0_is_deprecated, propName as string) + if (accessNode && prop?.isDeprecated) { + const deprecatedNode = accessExpression?.argumentExpression ?? (isIndexedAccessTypeNode(accessNode) ? accessNode.indexType : accessNode); + errorOrSuggestion(false, deprecatedNode, Diagnostics._0_is_deprecated, propName as string) } if (accessExpression) { markPropertyAsReferenced(prop, accessExpression, /*isThisAccess*/ accessExpression.expression.kind === SyntaxKind.ThisKeyword); @@ -21457,7 +21458,7 @@ namespace ts { const localOrExportSymbol = getExportSymbolOfValueSymbolIfExported(symbol); let declaration: Declaration | undefined = localOrExportSymbol.valueDeclaration; - if (symbol && some(symbol.declarations, decl => !!getJSDocDeprecatedTag(decl))) { + if (symbol?.isDeprecated) { errorOrSuggestion(false, node, Diagnostics._0_is_deprecated, node.escapedText as string) } @@ -24428,8 +24429,8 @@ namespace ts { propType = indexInfo.type; } else { - if (some(prop.declarations, decl => !!getJSDocDeprecatedTag(decl))) { - errorOrSuggestion(false, node, Diagnostics._0_is_deprecated, right.escapedText as string) + if (prop?.isDeprecated) { + errorOrSuggestion(false, right, Diagnostics._0_is_deprecated, right.escapedText as string) } checkPropertyNotUsedBeforeDeclaration(prop, node, right); @@ -30203,7 +30204,7 @@ namespace ts { } } const symbol = getNodeLinks(node).resolvedSymbol! - if (symbol && some(symbol.declarations, decl => !!getJSDocDeprecatedTag(decl))) { + if (symbol?.isDeprecated) { errorOrSuggestion(false, node, Diagnostics._0_is_deprecated, symbol.escapedName as string) } if (type.flags & TypeFlags.Enum && symbol.flags & SymbolFlags.EnumMember) { diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 52b2d599428a8..6b20f83e79a32 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -4124,6 +4124,8 @@ namespace ts { /* @internal */ isReplaceableByMethod?: boolean; // Can this Javascript class property be replaced by a method symbol? /* @internal */ isAssigned?: boolean; // True if the symbol is a parameter with assignments /* @internal */ assignmentDeclarationMembers?: Map; // detected late-bound assignment declarations associated with the symbol + + /* @internal */ isDeprecated?: boolean; } /* @internal */ From 1f151361aafb198804657e046d1f8176214ac71a Mon Sep 17 00:00:00 2001 From: kingwl Date: Mon, 18 May 2020 19:45:03 +0800 Subject: [PATCH 14/38] fix baseline --- src/compiler/checker.ts | 13 ++++++------ src/compiler/types.ts | 3 +-- src/harness/client.ts | 2 +- src/testRunner/unittests/config/matchFiles.ts | 1 + src/testRunner/unittests/moduleResolution.ts | 21 ++++++++++++------- .../unittests/tscWatch/incremental.ts | 1 + .../unittests/tsserver/compileOnSave.ts | 1 + src/testRunner/unittests/tsserver/helpers.ts | 6 ++++-- src/testRunner/unittests/tsserver/navTo.ts | 2 +- .../unittests/tsserver/projectErrors.ts | 7 +++++-- 10 files changed, 35 insertions(+), 22 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 95e8facae9654..98c7bb870b9cd 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -12964,7 +12964,7 @@ namespace ts { if (prop) { if (accessNode && prop?.isDeprecated) { const deprecatedNode = accessExpression?.argumentExpression ?? (isIndexedAccessTypeNode(accessNode) ? accessNode.indexType : accessNode); - errorOrSuggestion(false, deprecatedNode, Diagnostics._0_is_deprecated, propName as string) + errorOrSuggestion(/* isError */false, deprecatedNode, Diagnostics._0_is_deprecated, propName as string); } if (accessExpression) { markPropertyAsReferenced(prop, accessExpression, /*isThisAccess*/ accessExpression.expression.kind === SyntaxKind.ThisKeyword); @@ -21459,9 +21459,8 @@ namespace ts { let declaration: Declaration | undefined = localOrExportSymbol.valueDeclaration; if (symbol?.isDeprecated) { - errorOrSuggestion(false, node, Diagnostics._0_is_deprecated, node.escapedText as string) - } - + errorOrSuggestion(/* isError */false, node, Diagnostics._0_is_deprecated, node.escapedText as string); + } if (localOrExportSymbol.flags & SymbolFlags.Class) { // Due to the emit for class decorators, any reference to the class from inside of the class body // must instead be rewritten to point to a temporary variable to avoid issues with the double-bind @@ -24430,7 +24429,7 @@ namespace ts { } else { if (prop?.isDeprecated) { - errorOrSuggestion(false, right, Diagnostics._0_is_deprecated, right.escapedText as string) + errorOrSuggestion(/* isError */false, right, Diagnostics._0_is_deprecated, right.escapedText as string); } checkPropertyNotUsedBeforeDeclaration(prop, node, right); @@ -30203,9 +30202,9 @@ namespace ts { checkTypeArgumentConstraints(node, typeParameters); } } - const symbol = getNodeLinks(node).resolvedSymbol! + const symbol = getNodeLinks(node).resolvedSymbol!; if (symbol?.isDeprecated) { - errorOrSuggestion(false, node, Diagnostics._0_is_deprecated, symbol.escapedName as string) + errorOrSuggestion(/* isError */false, node, Diagnostics._0_is_deprecated, symbol.escapedName as string); } if (type.flags & TypeFlags.Enum && symbol.flags & SymbolFlags.EnumMember) { error(node, Diagnostics.Enum_type_0_has_members_with_initializers_that_are_not_literals, typeToString(type)); diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 6b20f83e79a32..fa7eeeb0a9716 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -4123,8 +4123,7 @@ namespace ts { /* @internal */ isReferenced?: SymbolFlags; // True if the symbol is referenced elsewhere. Keeps track of the meaning of a reference in case a symbol is both a type parameter and parameter. /* @internal */ isReplaceableByMethod?: boolean; // Can this Javascript class property be replaced by a method symbol? /* @internal */ isAssigned?: boolean; // True if the symbol is a parameter with assignments - /* @internal */ assignmentDeclarationMembers?: Map; // detected late-bound assignment declarations associated with the symbol - + /* @internal */ assignmentDeclarationMembers?: Map; // detected late-bound assignment declarations associated with the symbol /* @internal */ isDeprecated?: boolean; } diff --git a/src/harness/client.ts b/src/harness/client.ts index de3fa8f5352a1..6b64ee7e44485 100644 --- a/src/harness/client.ts +++ b/src/harness/client.ts @@ -205,7 +205,7 @@ namespace ts.server { } const { name, kind, kindModifiers, sortText } = entry; - return { name, kind, kindModifiers, sortText } + return { name, kind, kindModifiers, sortText }; }) }; } diff --git a/src/testRunner/unittests/config/matchFiles.ts b/src/testRunner/unittests/config/matchFiles.ts index 272137af69607..915f73e036f33 100644 --- a/src/testRunner/unittests/config/matchFiles.ts +++ b/src/testRunner/unittests/config/matchFiles.ts @@ -128,6 +128,7 @@ namespace ts { messageText: error.messageText, start: undefined, reportsUnnecessary: undefined, + reportsDeprecated: undefined })); assertParsed(actual, expected); } diff --git a/src/testRunner/unittests/moduleResolution.ts b/src/testRunner/unittests/moduleResolution.ts index be70424248cc9..7bf5e811bd304 100644 --- a/src/testRunner/unittests/moduleResolution.ts +++ b/src/testRunner/unittests/moduleResolution.ts @@ -615,7 +615,8 @@ export = C; "D.ts", "d.ts", ), - reportsUnnecessary: undefined + reportsUnnecessary: undefined, + reportsDeprecated: undefined }] ); }); @@ -641,7 +642,8 @@ export = C; "/a/b/D.ts", "d.ts", ), - reportsUnnecessary: undefined + reportsUnnecessary: undefined, + reportsDeprecated: undefined }] ); }); @@ -667,7 +669,8 @@ export = C; "ModuleB.ts", "moduleB.ts", ), - reportsUnnecessary: undefined + reportsUnnecessary: undefined, + reportsDeprecated: undefined }] ); }); @@ -694,7 +697,8 @@ export = C; "/a/b/D.ts", "d.ts", ), - reportsUnnecessary: undefined + reportsUnnecessary: undefined, + reportsDeprecated: undefined }] ); }); @@ -722,7 +726,8 @@ export = C; "ModuleC.ts", "moduleC.ts", ), - reportsUnnecessary: undefined + reportsUnnecessary: undefined, + reportsDeprecated: undefined }, { ...tscWatch.getDiagnosticOfFileFromProgram( @@ -734,7 +739,8 @@ export = C; "moduleC.ts", "ModuleC.ts" ), - reportsUnnecessary: undefined + reportsUnnecessary: undefined, + reportsDeprecated: undefined } ] ); @@ -766,7 +772,8 @@ import b = require("./moduleB"); "/a/B/c/moduleC.ts", "/a/B/c/ModuleC.ts" ), - reportsUnnecessary: undefined + reportsUnnecessary: undefined, + reportsDeprecated: undefined }] ); }); diff --git a/src/testRunner/unittests/tscWatch/incremental.ts b/src/testRunner/unittests/tscWatch/incremental.ts index 2d05482c2b1e8..7743fa8cd3564 100644 --- a/src/testRunner/unittests/tscWatch/incremental.ts +++ b/src/testRunner/unittests/tscWatch/incremental.ts @@ -199,6 +199,7 @@ namespace ts.tscWatch { messageText: "Type '20' is not assignable to type 'string'.", relatedInformation: undefined, reportsUnnecessary: undefined, + reportsDeprecated: undefined, source: undefined }]); }); diff --git a/src/testRunner/unittests/tsserver/compileOnSave.ts b/src/testRunner/unittests/tsserver/compileOnSave.ts index 29bb0a9525937..084317afe894f 100644 --- a/src/testRunner/unittests/tsserver/compileOnSave.ts +++ b/src/testRunner/unittests/tsserver/compileOnSave.ts @@ -869,6 +869,7 @@ namespace ts.projectSystem { code: Diagnostics.Cannot_write_file_0_because_it_would_overwrite_input_file.code, category: diagnosticCategoryName(Diagnostics.Cannot_write_file_0_because_it_would_overwrite_input_file), reportsUnnecessary: undefined, + reportsDeprecated: undefined, relatedInformation: undefined, source: undefined }] diff --git a/src/testRunner/unittests/tsserver/helpers.ts b/src/testRunner/unittests/tsserver/helpers.ts index 9d464ee7fccd9..000d6933a7d0b 100644 --- a/src/testRunner/unittests/tsserver/helpers.ts +++ b/src/testRunner/unittests/tsserver/helpers.ts @@ -204,6 +204,8 @@ namespace ts.projectSystem { category: DiagnosticCategory; code: number; reportsUnnecessary?: {}; + + reportsDeprecated?: {}; source?: string; relatedInformation?: DiagnosticRelatedInformation[]; } @@ -699,8 +701,8 @@ namespace ts.projectSystem { checkNthEvent(session, server.toEvent(eventName, diagnostics), 0, isMostRecent); } - export function createDiagnostic(start: protocol.Location, end: protocol.Location, message: DiagnosticMessage, args: readonly string[] = [], category = diagnosticCategoryName(message), reportsUnnecessary?: {}, relatedInformation?: protocol.DiagnosticRelatedInformation[]): protocol.Diagnostic { - return { start, end, text: formatStringFromArgs(message.message, args), code: message.code, category, reportsUnnecessary, relatedInformation, source: undefined }; + export function createDiagnostic(start: protocol.Location, end: protocol.Location, message: DiagnosticMessage, args: readonly string[] = [], category = diagnosticCategoryName(message), reportsUnnecessary?: {}, relatedInformation?: protocol.DiagnosticRelatedInformation[], reportsDeprecated?: {}): protocol.Diagnostic { + return { start, end, text: formatStringFromArgs(message.message, args), code: message.code, category, reportsUnnecessary, reportsDeprecated, relatedInformation, source: undefined }; } export function checkCompleteEvent(session: TestSession, numberOfCurrentEvents: number, expectedSequenceId: number, isMostRecent = true): void { diff --git a/src/testRunner/unittests/tsserver/navTo.ts b/src/testRunner/unittests/tsserver/navTo.ts index 113db9855999f..e447a312e2fd8 100644 --- a/src/testRunner/unittests/tsserver/navTo.ts +++ b/src/testRunner/unittests/tsserver/navTo.ts @@ -90,7 +90,7 @@ export const ghijkl = a.abcdef;` const items = session.executeCommand(libTypeNavToRequest).response as protocol.NavtoItem[]; const fooItem = findNavToItem(items, "foo", "function"); assert.isNotNull(fooItem, `Cannot find function symbol "foo".`); - assert.isTrue(fooItem?.kindModifiers?.includes("deprecated")) + assert.isTrue(fooItem?.kindModifiers?.includes("deprecated")); }); }); } diff --git a/src/testRunner/unittests/tsserver/projectErrors.ts b/src/testRunner/unittests/tsserver/projectErrors.ts index 9019644537561..af1d2240d5f90 100644 --- a/src/testRunner/unittests/tsserver/projectErrors.ts +++ b/src/testRunner/unittests/tsserver/projectErrors.ts @@ -534,7 +534,8 @@ declare module '@custom/plugin' { messageText: formatStringFromArgs(d.message, didYouMean ? [prop, didYouMean] : [prop]), category: d.category, code: d.code, - reportsUnnecessary: undefined + reportsUnnecessary: undefined, + reportsDeprecated: undefined }; } @@ -549,7 +550,8 @@ declare module '@custom/plugin' { messageText: formatStringFromArgs(d.message, [`${getDirectoryPath(configFile.path)}/${relativeFileName}`]), category: d.category, code: d.code, - reportsUnnecessary: undefined + reportsUnnecessary: undefined, + reportsDeprecated: undefined }; } @@ -908,6 +910,7 @@ declare module '@custom/plugin' { code: Diagnostics.Unused_label.code, relatedInformation: undefined, reportsUnnecessary: true, + reportsDeprecated: undefined, source: undefined, }, ]); From d856ad50e42c74a94e6ead1cbd0d4406d37041a8 Mon Sep 17 00:00:00 2001 From: kingwl Date: Mon, 18 May 2020 20:18:29 +0800 Subject: [PATCH 15/38] fix jsdoc cache --- src/compiler/binder.ts | 2 +- src/compiler/checker.ts | 10 +++++----- src/compiler/types.ts | 2 +- src/compiler/utilitiesPublic.ts | 4 ++-- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/compiler/binder.ts b/src/compiler/binder.ts index ffe733594e385..932e7c13c4cff 100644 --- a/src/compiler/binder.ts +++ b/src/compiler/binder.ts @@ -414,7 +414,7 @@ namespace ts { Debug.assert(!hasDynamicName(node)); const isDefaultExport = hasSyntacticModifier(node, ModifierFlags.Default) || isExportSpecifier(node) && node.name.escapedText === "default"; - const isDeprecated = !!getJSDocDeprecatedTag(node); + const isDeprecated = !!getJSDocDeprecatedTag(node, /* noCache */ true); // The exported symbol for an export default function/class node is always named "default" const name = isDefaultExport && parent ? InternalSymbolName.Default : getDeclarationName(node); diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 98c7bb870b9cd..c661dcda03ea9 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -12964,7 +12964,7 @@ namespace ts { if (prop) { if (accessNode && prop?.isDeprecated) { const deprecatedNode = accessExpression?.argumentExpression ?? (isIndexedAccessTypeNode(accessNode) ? accessNode.indexType : accessNode); - errorOrSuggestion(/* isError */false, deprecatedNode, Diagnostics._0_is_deprecated, propName as string); + errorOrSuggestion(/* isError */ false, deprecatedNode, Diagnostics._0_is_deprecated, propName as string); } if (accessExpression) { markPropertyAsReferenced(prop, accessExpression, /*isThisAccess*/ accessExpression.expression.kind === SyntaxKind.ThisKeyword); @@ -21459,8 +21459,8 @@ namespace ts { let declaration: Declaration | undefined = localOrExportSymbol.valueDeclaration; if (symbol?.isDeprecated) { - errorOrSuggestion(/* isError */false, node, Diagnostics._0_is_deprecated, node.escapedText as string); - } + errorOrSuggestion(/* isError */ false, node, Diagnostics._0_is_deprecated, node.escapedText as string); + } if (localOrExportSymbol.flags & SymbolFlags.Class) { // Due to the emit for class decorators, any reference to the class from inside of the class body // must instead be rewritten to point to a temporary variable to avoid issues with the double-bind @@ -24429,7 +24429,7 @@ namespace ts { } else { if (prop?.isDeprecated) { - errorOrSuggestion(/* isError */false, right, Diagnostics._0_is_deprecated, right.escapedText as string); + errorOrSuggestion(/* isError */ false, right, Diagnostics._0_is_deprecated, right.escapedText as string); } checkPropertyNotUsedBeforeDeclaration(prop, node, right); @@ -30204,7 +30204,7 @@ namespace ts { } const symbol = getNodeLinks(node).resolvedSymbol!; if (symbol?.isDeprecated) { - errorOrSuggestion(/* isError */false, node, Diagnostics._0_is_deprecated, symbol.escapedName as string); + errorOrSuggestion(/* isError */ false, node, Diagnostics._0_is_deprecated, symbol.escapedName as string); } if (type.flags & TypeFlags.Enum && symbol.flags & SymbolFlags.EnumMember) { error(node, Diagnostics.Enum_type_0_has_members_with_initializers_that_are_not_literals, typeToString(type)); diff --git a/src/compiler/types.ts b/src/compiler/types.ts index fa7eeeb0a9716..752c8bf3a346d 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -4123,7 +4123,7 @@ namespace ts { /* @internal */ isReferenced?: SymbolFlags; // True if the symbol is referenced elsewhere. Keeps track of the meaning of a reference in case a symbol is both a type parameter and parameter. /* @internal */ isReplaceableByMethod?: boolean; // Can this Javascript class property be replaced by a method symbol? /* @internal */ isAssigned?: boolean; // True if the symbol is a parameter with assignments - /* @internal */ assignmentDeclarationMembers?: Map; // detected late-bound assignment declarations associated with the symbol + /* @internal */ assignmentDeclarationMembers?: Map; // detected late-bound assignment declarations associated with the symbol /* @internal */ isDeprecated?: boolean; } diff --git a/src/compiler/utilitiesPublic.ts b/src/compiler/utilitiesPublic.ts index 934cee5f51c2f..2dda552d4d3dc 100644 --- a/src/compiler/utilitiesPublic.ts +++ b/src/compiler/utilitiesPublic.ts @@ -760,8 +760,8 @@ namespace ts { } /** Gets the JSDoc deprecated tag for the node if present */ - export function getJSDocDeprecatedTag(node: Node): JSDocDeprecatedTag | undefined { - return getFirstJSDocTag(node, isJSDocDeprecatedTag); + export function getJSDocDeprecatedTag(node: Node, noCache?: boolean): JSDocDeprecatedTag | undefined { + return getFirstJSDocTag(node, isJSDocDeprecatedTag, noCache); } /** Gets the JSDoc type tag for the node if present and valid */ From 9c577e2aad3c9769d0b8d72d2037e661402c2275 Mon Sep 17 00:00:00 2001 From: kingwl Date: Mon, 18 May 2020 21:03:37 +0800 Subject: [PATCH 16/38] fix incorrect fix --- src/harness/client.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/harness/client.ts b/src/harness/client.ts index 6b64ee7e44485..21488b6aa074a 100644 --- a/src/harness/client.ts +++ b/src/harness/client.ts @@ -204,8 +204,7 @@ namespace ts.server { return res; } - const { name, kind, kindModifiers, sortText } = entry; - return { name, kind, kindModifiers, sortText }; + return entry as { name: string, kind: ScriptElementKind, kindModifiers: string, sortText: string }; // TODO: GH#18217 }) }; } From 8abcf7e9381b030d162e328526ffa714d4e84e20 Mon Sep 17 00:00:00 2001 From: kingwl Date: Mon, 18 May 2020 21:45:20 +0800 Subject: [PATCH 17/38] Avoid useless changes --- src/harness/client.ts | 4 ++-- src/harness/fourslashImpl.ts | 2 +- src/harness/fourslashInterfaceImpl.ts | 1 - src/server/protocol.ts | 1 - src/server/session.ts | 6 +++--- src/services/completions.ts | 4 ++-- src/services/jsDoc.ts | 2 +- src/services/shims.ts | 3 +-- src/testRunner/unittests/tsserver/declarationFileMaps.ts | 2 +- src/testRunner/unittests/tsserver/helpers.ts | 1 - tests/baselines/reference/api/tsserverlibrary.d.ts | 2 +- tests/baselines/reference/api/typescript.d.ts | 2 +- 12 files changed, 13 insertions(+), 17 deletions(-) diff --git a/src/harness/client.ts b/src/harness/client.ts index 21488b6aa074a..381177bdf23e4 100644 --- a/src/harness/client.ts +++ b/src/harness/client.ts @@ -241,7 +241,7 @@ namespace ts.server { matchKind: entry.matchKind as keyof typeof PatternMatchKind, isCaseSensitive: entry.isCaseSensitive, fileName: entry.file, - textSpan: this.decodeSpan(entry) + textSpan: this.decodeSpan(entry), })); } @@ -388,7 +388,7 @@ namespace ts.server { category: Debug.checkDefined(category, "convertDiagnostic: category should not be undefined"), code: entry.code, reportsUnnecessary: entry.reportsUnnecessary, - reportsDeprecated: entry.reportsDeprecated + reportsDeprecated: entry.reportsDeprecated, }; }); } diff --git a/src/harness/fourslashImpl.ts b/src/harness/fourslashImpl.ts index d69edb48e32a2..046b4bc5d2e9c 100644 --- a/src/harness/fourslashImpl.ts +++ b/src/harness/fourslashImpl.ts @@ -2988,7 +2988,7 @@ namespace FourSlash { fileName: e.range.fileName, textSpan: ts.createTextSpanFromRange(e.range), containerName: e.containerName || "", - containerKind: e.containerKind || ts.ScriptElementKind.unknown + containerKind: e.containerKind || ts.ScriptElementKind.unknown, }))); } } diff --git a/src/harness/fourslashInterfaceImpl.ts b/src/harness/fourslashInterfaceImpl.ts index 1283589acd1ae..d5063761f5ed1 100644 --- a/src/harness/fourslashInterfaceImpl.ts +++ b/src/harness/fourslashInterfaceImpl.ts @@ -1608,7 +1608,6 @@ namespace FourSlashInterface { range?: FourSlash.Range; code: number; reportsUnnecessary?: true; - reportsDeprecated?: true; } diff --git a/src/server/protocol.ts b/src/server/protocol.ts index 4086e10d8b981..923ff41661f90 100644 --- a/src/server/protocol.ts +++ b/src/server/protocol.ts @@ -498,7 +498,6 @@ namespace ts.server.protocol { code: number; /** May store more in future. For now, this will simply be `true` to indicate when a diagnostic is an unused-identifier diagnostic. */ reportsUnnecessary?: {}; - reportsDeprecated?: {}; relatedInformation?: DiagnosticRelatedInformation[]; } diff --git a/src/server/session.ts b/src/server/session.ts index 149da1ac29c3f..85f8b0694ece2 100644 --- a/src/server/session.ts +++ b/src/server/session.ts @@ -1864,7 +1864,7 @@ namespace ts.server { kindModifiers: tree.kindModifiers, spans: tree.spans.map(span => toProtocolTextSpan(span, scriptInfo)), nameSpan: tree.nameSpan && toProtocolTextSpan(tree.nameSpan, scriptInfo), - childItems: map(tree.childItems, item => this.toLocationNavigationTree(item, scriptInfo)), + childItems: map(tree.childItems, item => this.toLocationNavigationTree(item, scriptInfo)) }; } @@ -1891,7 +1891,7 @@ namespace ts.server { matchKind: navItem.matchKind, file: navItem.fileName, start: scriptInfo.positionToLineOffset(navItem.textSpan.start), - end: scriptInfo.positionToLineOffset(textSpanEnd(navItem.textSpan)), + end: scriptInfo.positionToLineOffset(textSpanEnd(navItem.textSpan)) }; if (navItem.kindModifiers && (navItem.kindModifiers !== "")) { bakedItem.kindModifiers = navItem.kindModifiers; @@ -2229,7 +2229,7 @@ namespace ts.server { kindModifiers: item.kindModifiers, file: item.file, span: toProtocolTextSpan(item.span, scriptInfo), - selectionSpan: toProtocolTextSpan(item.selectionSpan, scriptInfo), + selectionSpan: toProtocolTextSpan(item.selectionSpan, scriptInfo) }; } diff --git a/src/services/completions.ts b/src/services/completions.ts index 3eab998ec499b..8b9228d3441ad 100644 --- a/src/services/completions.ts +++ b/src/services/completions.ts @@ -234,7 +234,7 @@ namespace ts.Completions { name: tagName.getFullText(sourceFile) + (hasClosingAngleBracket ? "" : ">"), kind: ScriptElementKind.classElement, kindModifiers: undefined, - sortText: SortText.LocationPriority + sortText: SortText.LocationPriority, }; return { isGlobalCompletion: false, isMemberCompletion: true, isNewIdentifierLocation: false, entries: [entry] }; } @@ -436,7 +436,7 @@ namespace ts.Completions { hasAction: origin && originIsExport(origin) || undefined, isRecommended: isRecommendedCompletionMatch(symbol, recommendedCompletion, typeChecker) || undefined, insertText, - replacementSpan + replacementSpan, }; } diff --git a/src/services/jsDoc.ts b/src/services/jsDoc.ts index 6e7963073bd12..3115109572a0d 100644 --- a/src/services/jsDoc.ts +++ b/src/services/jsDoc.ts @@ -163,7 +163,7 @@ namespace ts.JsDoc { name: tagName, kind: ScriptElementKind.keyword, kindModifiers: "", - sortText: "0" + sortText: "0", }; })); } diff --git a/src/services/shims.ts b/src/services/shims.ts index 4ba69f8f971ec..5bca205d825b0 100644 --- a/src/services/shims.ts +++ b/src/services/shims.ts @@ -601,8 +601,7 @@ namespace ts { category: string; code: number; reportsUnnecessary?: {}; - - reportsDeprecated?: {} + reportsDeprecated?: {}; } export function realizeDiagnostics(diagnostics: readonly Diagnostic[], newLine: string): RealizedDiagnostic[] { return diagnostics.map(d => realizeDiagnostic(d, newLine)); diff --git a/src/testRunner/unittests/tsserver/declarationFileMaps.ts b/src/testRunner/unittests/tsserver/declarationFileMaps.ts index 0a3aef4de9067..c52e2ad807a74 100644 --- a/src/testRunner/unittests/tsserver/declarationFileMaps.ts +++ b/src/testRunner/unittests/tsserver/declarationFileMaps.ts @@ -295,7 +295,7 @@ namespace ts.projectSystem { matchKind: "prefix", isCaseSensitive: true, kind: ScriptElementKind.functionElement, - kindModifiers: "export,declare" + kindModifiers: "export,declare", }, { ...protocolFileSpanFromSubstring({ diff --git a/src/testRunner/unittests/tsserver/helpers.ts b/src/testRunner/unittests/tsserver/helpers.ts index 000d6933a7d0b..992ca05c5ec0f 100644 --- a/src/testRunner/unittests/tsserver/helpers.ts +++ b/src/testRunner/unittests/tsserver/helpers.ts @@ -204,7 +204,6 @@ namespace ts.projectSystem { category: DiagnosticCategory; code: number; reportsUnnecessary?: {}; - reportsDeprecated?: {}; source?: string; relatedInformation?: DiagnosticRelatedInformation[]; diff --git a/tests/baselines/reference/api/tsserverlibrary.d.ts b/tests/baselines/reference/api/tsserverlibrary.d.ts index 290b3e9346251..0ade0a3418fa4 100644 --- a/tests/baselines/reference/api/tsserverlibrary.d.ts +++ b/tests/baselines/reference/api/tsserverlibrary.d.ts @@ -3553,7 +3553,7 @@ declare namespace ts { /** Gets the JSDoc template tag for the node if present */ function getJSDocTemplateTag(node: Node): JSDocTemplateTag | undefined; /** Gets the JSDoc deprecated tag for the node if present */ - function getJSDocDeprecatedTag(node: Node): JSDocDeprecatedTag | undefined; + function getJSDocDeprecatedTag(node: Node, noCache?: boolean): JSDocDeprecatedTag | undefined; /** Gets the JSDoc type tag for the node if present and valid */ function getJSDocTypeTag(node: Node): JSDocTypeTag | undefined; /** diff --git a/tests/baselines/reference/api/typescript.d.ts b/tests/baselines/reference/api/typescript.d.ts index 7dc484c6da5f9..94985e32b5ed2 100644 --- a/tests/baselines/reference/api/typescript.d.ts +++ b/tests/baselines/reference/api/typescript.d.ts @@ -3553,7 +3553,7 @@ declare namespace ts { /** Gets the JSDoc template tag for the node if present */ function getJSDocTemplateTag(node: Node): JSDocTemplateTag | undefined; /** Gets the JSDoc deprecated tag for the node if present */ - function getJSDocDeprecatedTag(node: Node): JSDocDeprecatedTag | undefined; + function getJSDocDeprecatedTag(node: Node, noCache?: boolean): JSDocDeprecatedTag | undefined; /** Gets the JSDoc type tag for the node if present and valid */ function getJSDocTypeTag(node: Node): JSDocTypeTag | undefined; /** From e7be90959fdbddd009ef4eddaa0d9d8187235e67 Mon Sep 17 00:00:00 2001 From: kingwl Date: Wed, 20 May 2020 10:09:00 +0800 Subject: [PATCH 18/38] Accept baseline --- .../reference/api/tsserverlibrary.d.ts | 299 +++++++++--------- tests/baselines/reference/api/typescript.d.ts | 299 +++++++++--------- 2 files changed, 300 insertions(+), 298 deletions(-) diff --git a/tests/baselines/reference/api/tsserverlibrary.d.ts b/tests/baselines/reference/api/tsserverlibrary.d.ts index 0ade0a3418fa4..92b8f7201ce37 100644 --- a/tests/baselines/reference/api/tsserverlibrary.d.ts +++ b/tests/baselines/reference/api/tsserverlibrary.d.ts @@ -263,151 +263,152 @@ declare namespace ts { IndexedAccessType = 185, MappedType = 186, LiteralType = 187, - ImportType = 188, - ObjectBindingPattern = 189, - ArrayBindingPattern = 190, - BindingElement = 191, - ArrayLiteralExpression = 192, - ObjectLiteralExpression = 193, - PropertyAccessExpression = 194, - ElementAccessExpression = 195, - CallExpression = 196, - NewExpression = 197, - TaggedTemplateExpression = 198, - TypeAssertionExpression = 199, - ParenthesizedExpression = 200, - FunctionExpression = 201, - ArrowFunction = 202, - DeleteExpression = 203, - TypeOfExpression = 204, - VoidExpression = 205, - AwaitExpression = 206, - PrefixUnaryExpression = 207, - PostfixUnaryExpression = 208, - BinaryExpression = 209, - ConditionalExpression = 210, - TemplateExpression = 211, - YieldExpression = 212, - SpreadElement = 213, - ClassExpression = 214, - OmittedExpression = 215, - ExpressionWithTypeArguments = 216, - AsExpression = 217, - NonNullExpression = 218, - MetaProperty = 219, - SyntheticExpression = 220, - TemplateSpan = 221, - SemicolonClassElement = 222, - Block = 223, - EmptyStatement = 224, - VariableStatement = 225, - ExpressionStatement = 226, - IfStatement = 227, - DoStatement = 228, - WhileStatement = 229, - ForStatement = 230, - ForInStatement = 231, - ForOfStatement = 232, - ContinueStatement = 233, - BreakStatement = 234, - ReturnStatement = 235, - WithStatement = 236, - SwitchStatement = 237, - LabeledStatement = 238, - ThrowStatement = 239, - TryStatement = 240, - DebuggerStatement = 241, - VariableDeclaration = 242, - VariableDeclarationList = 243, - FunctionDeclaration = 244, - ClassDeclaration = 245, - InterfaceDeclaration = 246, - TypeAliasDeclaration = 247, - EnumDeclaration = 248, - ModuleDeclaration = 249, - ModuleBlock = 250, - CaseBlock = 251, - NamespaceExportDeclaration = 252, - ImportEqualsDeclaration = 253, - ImportDeclaration = 254, - ImportClause = 255, - NamespaceImport = 256, - NamedImports = 257, - ImportSpecifier = 258, - ExportAssignment = 259, - ExportDeclaration = 260, - NamedExports = 261, - NamespaceExport = 262, - ExportSpecifier = 263, - MissingDeclaration = 264, - ExternalModuleReference = 265, - JsxElement = 266, - JsxSelfClosingElement = 267, - JsxOpeningElement = 268, - JsxClosingElement = 269, - JsxFragment = 270, - JsxOpeningFragment = 271, - JsxClosingFragment = 272, - JsxAttribute = 273, - JsxAttributes = 274, - JsxSpreadAttribute = 275, - JsxExpression = 276, - CaseClause = 277, - DefaultClause = 278, - HeritageClause = 279, - CatchClause = 280, - PropertyAssignment = 281, - ShorthandPropertyAssignment = 282, - SpreadAssignment = 283, - EnumMember = 284, - UnparsedPrologue = 285, - UnparsedPrepend = 286, - UnparsedText = 287, - UnparsedInternalText = 288, - UnparsedSyntheticReference = 289, - SourceFile = 290, - Bundle = 291, - UnparsedSource = 292, - InputFiles = 293, - JSDocTypeExpression = 294, - JSDocAllType = 295, - JSDocUnknownType = 296, - JSDocNullableType = 297, - JSDocNonNullableType = 298, - JSDocOptionalType = 299, - JSDocFunctionType = 300, - JSDocVariadicType = 301, - JSDocNamepathType = 302, - JSDocComment = 303, - JSDocTypeLiteral = 304, - JSDocSignature = 305, - JSDocTag = 306, - JSDocAugmentsTag = 307, - JSDocImplementsTag = 308, - JSDocAuthorTag = 309, - JSDocDeprecatedTag = 310, - JSDocClassTag = 311, - JSDocPublicTag = 312, - JSDocPrivateTag = 313, - JSDocProtectedTag = 314, - JSDocReadonlyTag = 315, - JSDocCallbackTag = 316, - JSDocEnumTag = 317, - JSDocParameterTag = 318, - JSDocReturnTag = 319, - JSDocThisTag = 320, - JSDocTypeTag = 321, - JSDocTemplateTag = 322, - JSDocTypedefTag = 323, - JSDocPropertyTag = 324, - SyntaxList = 325, - NotEmittedStatement = 326, - PartiallyEmittedExpression = 327, - CommaListExpression = 328, - MergeDeclarationMarker = 329, - EndOfDeclarationMarker = 330, - SyntheticReferenceExpression = 331, - Count = 332, + NamedTupleMember = 188, + ImportType = 189, + ObjectBindingPattern = 190, + ArrayBindingPattern = 191, + BindingElement = 192, + ArrayLiteralExpression = 193, + ObjectLiteralExpression = 194, + PropertyAccessExpression = 195, + ElementAccessExpression = 196, + CallExpression = 197, + NewExpression = 198, + TaggedTemplateExpression = 199, + TypeAssertionExpression = 200, + ParenthesizedExpression = 201, + FunctionExpression = 202, + ArrowFunction = 203, + DeleteExpression = 204, + TypeOfExpression = 205, + VoidExpression = 206, + AwaitExpression = 207, + PrefixUnaryExpression = 208, + PostfixUnaryExpression = 209, + BinaryExpression = 210, + ConditionalExpression = 211, + TemplateExpression = 212, + YieldExpression = 213, + SpreadElement = 214, + ClassExpression = 215, + OmittedExpression = 216, + ExpressionWithTypeArguments = 217, + AsExpression = 218, + NonNullExpression = 219, + MetaProperty = 220, + SyntheticExpression = 221, + TemplateSpan = 222, + SemicolonClassElement = 223, + Block = 224, + EmptyStatement = 225, + VariableStatement = 226, + ExpressionStatement = 227, + IfStatement = 228, + DoStatement = 229, + WhileStatement = 230, + ForStatement = 231, + ForInStatement = 232, + ForOfStatement = 233, + ContinueStatement = 234, + BreakStatement = 235, + ReturnStatement = 236, + WithStatement = 237, + SwitchStatement = 238, + LabeledStatement = 239, + ThrowStatement = 240, + TryStatement = 241, + DebuggerStatement = 242, + VariableDeclaration = 243, + VariableDeclarationList = 244, + FunctionDeclaration = 245, + ClassDeclaration = 246, + InterfaceDeclaration = 247, + TypeAliasDeclaration = 248, + EnumDeclaration = 249, + ModuleDeclaration = 250, + ModuleBlock = 251, + CaseBlock = 252, + NamespaceExportDeclaration = 253, + ImportEqualsDeclaration = 254, + ImportDeclaration = 255, + ImportClause = 256, + NamespaceImport = 257, + NamedImports = 258, + ImportSpecifier = 259, + ExportAssignment = 260, + ExportDeclaration = 261, + NamedExports = 262, + NamespaceExport = 263, + ExportSpecifier = 264, + MissingDeclaration = 265, + ExternalModuleReference = 266, + JsxElement = 267, + JsxSelfClosingElement = 268, + JsxOpeningElement = 269, + JsxClosingElement = 270, + JsxFragment = 271, + JsxOpeningFragment = 272, + JsxClosingFragment = 273, + JsxAttribute = 274, + JsxAttributes = 275, + JsxSpreadAttribute = 276, + JsxExpression = 277, + CaseClause = 278, + DefaultClause = 279, + HeritageClause = 280, + CatchClause = 281, + PropertyAssignment = 282, + ShorthandPropertyAssignment = 283, + SpreadAssignment = 284, + EnumMember = 285, + UnparsedPrologue = 286, + UnparsedPrepend = 287, + UnparsedText = 288, + UnparsedInternalText = 289, + UnparsedSyntheticReference = 290, + SourceFile = 291, + Bundle = 292, + UnparsedSource = 293, + InputFiles = 294, + JSDocTypeExpression = 295, + JSDocAllType = 296, + JSDocUnknownType = 297, + JSDocNullableType = 298, + JSDocNonNullableType = 299, + JSDocOptionalType = 300, + JSDocFunctionType = 301, + JSDocVariadicType = 302, + JSDocNamepathType = 303, + JSDocComment = 304, + JSDocTypeLiteral = 305, + JSDocSignature = 306, + JSDocTag = 307, + JSDocAugmentsTag = 308, + JSDocImplementsTag = 309, + JSDocAuthorTag = 310, + JSDocDeprecatedTag = 311, + JSDocClassTag = 312, + JSDocPublicTag = 313, + JSDocPrivateTag = 314, + JSDocProtectedTag = 315, + JSDocReadonlyTag = 316, + JSDocCallbackTag = 317, + JSDocEnumTag = 318, + JSDocParameterTag = 319, + JSDocReturnTag = 320, + JSDocThisTag = 321, + JSDocTypeTag = 322, + JSDocTemplateTag = 323, + JSDocTypedefTag = 324, + JSDocPropertyTag = 325, + SyntaxList = 326, + NotEmittedStatement = 327, + PartiallyEmittedExpression = 328, + CommaListExpression = 329, + MergeDeclarationMarker = 330, + EndOfDeclarationMarker = 331, + SyntheticReferenceExpression = 332, + Count = 333, FirstAssignment = 62, LastAssignment = 74, FirstCompoundAssignment = 63, @@ -435,10 +436,10 @@ declare namespace ts { FirstStatement = 226, LastStatement = 242, FirstNode = 153, - FirstJSDocNode = 294, - LastJSDocNode = 324, - FirstJSDocTagNode = 306, - LastJSDocTagNode = 324, + FirstJSDocNode = 295, + LastJSDocNode = 325, + FirstJSDocTagNode = 307, + LastJSDocTagNode = 325, } export enum NodeFlags { None = 0, diff --git a/tests/baselines/reference/api/typescript.d.ts b/tests/baselines/reference/api/typescript.d.ts index 94985e32b5ed2..04cee78015689 100644 --- a/tests/baselines/reference/api/typescript.d.ts +++ b/tests/baselines/reference/api/typescript.d.ts @@ -263,151 +263,152 @@ declare namespace ts { IndexedAccessType = 185, MappedType = 186, LiteralType = 187, - ImportType = 188, - ObjectBindingPattern = 189, - ArrayBindingPattern = 190, - BindingElement = 191, - ArrayLiteralExpression = 192, - ObjectLiteralExpression = 193, - PropertyAccessExpression = 194, - ElementAccessExpression = 195, - CallExpression = 196, - NewExpression = 197, - TaggedTemplateExpression = 198, - TypeAssertionExpression = 199, - ParenthesizedExpression = 200, - FunctionExpression = 201, - ArrowFunction = 202, - DeleteExpression = 203, - TypeOfExpression = 204, - VoidExpression = 205, - AwaitExpression = 206, - PrefixUnaryExpression = 207, - PostfixUnaryExpression = 208, - BinaryExpression = 209, - ConditionalExpression = 210, - TemplateExpression = 211, - YieldExpression = 212, - SpreadElement = 213, - ClassExpression = 214, - OmittedExpression = 215, - ExpressionWithTypeArguments = 216, - AsExpression = 217, - NonNullExpression = 218, - MetaProperty = 219, - SyntheticExpression = 220, - TemplateSpan = 221, - SemicolonClassElement = 222, - Block = 223, - EmptyStatement = 224, - VariableStatement = 225, - ExpressionStatement = 226, - IfStatement = 227, - DoStatement = 228, - WhileStatement = 229, - ForStatement = 230, - ForInStatement = 231, - ForOfStatement = 232, - ContinueStatement = 233, - BreakStatement = 234, - ReturnStatement = 235, - WithStatement = 236, - SwitchStatement = 237, - LabeledStatement = 238, - ThrowStatement = 239, - TryStatement = 240, - DebuggerStatement = 241, - VariableDeclaration = 242, - VariableDeclarationList = 243, - FunctionDeclaration = 244, - ClassDeclaration = 245, - InterfaceDeclaration = 246, - TypeAliasDeclaration = 247, - EnumDeclaration = 248, - ModuleDeclaration = 249, - ModuleBlock = 250, - CaseBlock = 251, - NamespaceExportDeclaration = 252, - ImportEqualsDeclaration = 253, - ImportDeclaration = 254, - ImportClause = 255, - NamespaceImport = 256, - NamedImports = 257, - ImportSpecifier = 258, - ExportAssignment = 259, - ExportDeclaration = 260, - NamedExports = 261, - NamespaceExport = 262, - ExportSpecifier = 263, - MissingDeclaration = 264, - ExternalModuleReference = 265, - JsxElement = 266, - JsxSelfClosingElement = 267, - JsxOpeningElement = 268, - JsxClosingElement = 269, - JsxFragment = 270, - JsxOpeningFragment = 271, - JsxClosingFragment = 272, - JsxAttribute = 273, - JsxAttributes = 274, - JsxSpreadAttribute = 275, - JsxExpression = 276, - CaseClause = 277, - DefaultClause = 278, - HeritageClause = 279, - CatchClause = 280, - PropertyAssignment = 281, - ShorthandPropertyAssignment = 282, - SpreadAssignment = 283, - EnumMember = 284, - UnparsedPrologue = 285, - UnparsedPrepend = 286, - UnparsedText = 287, - UnparsedInternalText = 288, - UnparsedSyntheticReference = 289, - SourceFile = 290, - Bundle = 291, - UnparsedSource = 292, - InputFiles = 293, - JSDocTypeExpression = 294, - JSDocAllType = 295, - JSDocUnknownType = 296, - JSDocNullableType = 297, - JSDocNonNullableType = 298, - JSDocOptionalType = 299, - JSDocFunctionType = 300, - JSDocVariadicType = 301, - JSDocNamepathType = 302, - JSDocComment = 303, - JSDocTypeLiteral = 304, - JSDocSignature = 305, - JSDocTag = 306, - JSDocAugmentsTag = 307, - JSDocImplementsTag = 308, - JSDocAuthorTag = 309, - JSDocDeprecatedTag = 310, - JSDocClassTag = 311, - JSDocPublicTag = 312, - JSDocPrivateTag = 313, - JSDocProtectedTag = 314, - JSDocReadonlyTag = 315, - JSDocCallbackTag = 316, - JSDocEnumTag = 317, - JSDocParameterTag = 318, - JSDocReturnTag = 319, - JSDocThisTag = 320, - JSDocTypeTag = 321, - JSDocTemplateTag = 322, - JSDocTypedefTag = 323, - JSDocPropertyTag = 324, - SyntaxList = 325, - NotEmittedStatement = 326, - PartiallyEmittedExpression = 327, - CommaListExpression = 328, - MergeDeclarationMarker = 329, - EndOfDeclarationMarker = 330, - SyntheticReferenceExpression = 331, - Count = 332, + NamedTupleMember = 188, + ImportType = 189, + ObjectBindingPattern = 190, + ArrayBindingPattern = 191, + BindingElement = 192, + ArrayLiteralExpression = 193, + ObjectLiteralExpression = 194, + PropertyAccessExpression = 195, + ElementAccessExpression = 196, + CallExpression = 197, + NewExpression = 198, + TaggedTemplateExpression = 199, + TypeAssertionExpression = 200, + ParenthesizedExpression = 201, + FunctionExpression = 202, + ArrowFunction = 203, + DeleteExpression = 204, + TypeOfExpression = 205, + VoidExpression = 206, + AwaitExpression = 207, + PrefixUnaryExpression = 208, + PostfixUnaryExpression = 209, + BinaryExpression = 210, + ConditionalExpression = 211, + TemplateExpression = 212, + YieldExpression = 213, + SpreadElement = 214, + ClassExpression = 215, + OmittedExpression = 216, + ExpressionWithTypeArguments = 217, + AsExpression = 218, + NonNullExpression = 219, + MetaProperty = 220, + SyntheticExpression = 221, + TemplateSpan = 222, + SemicolonClassElement = 223, + Block = 224, + EmptyStatement = 225, + VariableStatement = 226, + ExpressionStatement = 227, + IfStatement = 228, + DoStatement = 229, + WhileStatement = 230, + ForStatement = 231, + ForInStatement = 232, + ForOfStatement = 233, + ContinueStatement = 234, + BreakStatement = 235, + ReturnStatement = 236, + WithStatement = 237, + SwitchStatement = 238, + LabeledStatement = 239, + ThrowStatement = 240, + TryStatement = 241, + DebuggerStatement = 242, + VariableDeclaration = 243, + VariableDeclarationList = 244, + FunctionDeclaration = 245, + ClassDeclaration = 246, + InterfaceDeclaration = 247, + TypeAliasDeclaration = 248, + EnumDeclaration = 249, + ModuleDeclaration = 250, + ModuleBlock = 251, + CaseBlock = 252, + NamespaceExportDeclaration = 253, + ImportEqualsDeclaration = 254, + ImportDeclaration = 255, + ImportClause = 256, + NamespaceImport = 257, + NamedImports = 258, + ImportSpecifier = 259, + ExportAssignment = 260, + ExportDeclaration = 261, + NamedExports = 262, + NamespaceExport = 263, + ExportSpecifier = 264, + MissingDeclaration = 265, + ExternalModuleReference = 266, + JsxElement = 267, + JsxSelfClosingElement = 268, + JsxOpeningElement = 269, + JsxClosingElement = 270, + JsxFragment = 271, + JsxOpeningFragment = 272, + JsxClosingFragment = 273, + JsxAttribute = 274, + JsxAttributes = 275, + JsxSpreadAttribute = 276, + JsxExpression = 277, + CaseClause = 278, + DefaultClause = 279, + HeritageClause = 280, + CatchClause = 281, + PropertyAssignment = 282, + ShorthandPropertyAssignment = 283, + SpreadAssignment = 284, + EnumMember = 285, + UnparsedPrologue = 286, + UnparsedPrepend = 287, + UnparsedText = 288, + UnparsedInternalText = 289, + UnparsedSyntheticReference = 290, + SourceFile = 291, + Bundle = 292, + UnparsedSource = 293, + InputFiles = 294, + JSDocTypeExpression = 295, + JSDocAllType = 296, + JSDocUnknownType = 297, + JSDocNullableType = 298, + JSDocNonNullableType = 299, + JSDocOptionalType = 300, + JSDocFunctionType = 301, + JSDocVariadicType = 302, + JSDocNamepathType = 303, + JSDocComment = 304, + JSDocTypeLiteral = 305, + JSDocSignature = 306, + JSDocTag = 307, + JSDocAugmentsTag = 308, + JSDocImplementsTag = 309, + JSDocAuthorTag = 310, + JSDocDeprecatedTag = 311, + JSDocClassTag = 312, + JSDocPublicTag = 313, + JSDocPrivateTag = 314, + JSDocProtectedTag = 315, + JSDocReadonlyTag = 316, + JSDocCallbackTag = 317, + JSDocEnumTag = 318, + JSDocParameterTag = 319, + JSDocReturnTag = 320, + JSDocThisTag = 321, + JSDocTypeTag = 322, + JSDocTemplateTag = 323, + JSDocTypedefTag = 324, + JSDocPropertyTag = 325, + SyntaxList = 326, + NotEmittedStatement = 327, + PartiallyEmittedExpression = 328, + CommaListExpression = 329, + MergeDeclarationMarker = 330, + EndOfDeclarationMarker = 331, + SyntheticReferenceExpression = 332, + Count = 333, FirstAssignment = 62, LastAssignment = 74, FirstCompoundAssignment = 63, @@ -435,10 +436,10 @@ declare namespace ts { FirstStatement = 226, LastStatement = 242, FirstNode = 153, - FirstJSDocNode = 294, - LastJSDocNode = 324, - FirstJSDocTagNode = 306, - LastJSDocTagNode = 324, + FirstJSDocNode = 295, + LastJSDocNode = 325, + FirstJSDocTagNode = 307, + LastJSDocTagNode = 325, } export enum NodeFlags { None = 0, From e796f20cf20702f6843ee22964ab26f943284fb8 Mon Sep 17 00:00:00 2001 From: kingwl Date: Tue, 26 May 2020 11:02:20 +0800 Subject: [PATCH 19/38] Add tests --- .../fourslash/completionsWithDeprecatedTag.ts | 32 ++++ tests/cases/fourslash/fourslash.ts | 1 + .../fourslash/jsdocDeprecated_suggestion1.ts | 148 ++++++++++++++++++ 3 files changed, 181 insertions(+) create mode 100644 tests/cases/fourslash/completionsWithDeprecatedTag.ts create mode 100644 tests/cases/fourslash/jsdocDeprecated_suggestion1.ts diff --git a/tests/cases/fourslash/completionsWithDeprecatedTag.ts b/tests/cases/fourslash/completionsWithDeprecatedTag.ts new file mode 100644 index 0000000000000..4de10cc12f21c --- /dev/null +++ b/tests/cases/fourslash/completionsWithDeprecatedTag.ts @@ -0,0 +1,32 @@ +/// +// @strict: true + +//// /** @deprecated */ +//// interface Foo { +//// /** @deprecated */ +//// bar(): void +//// /** @deprecated */ +//// prop: number +//// } +//// declare const foo: Foo; +//// declare const foooo: Fo/*1*/; +//// foo.ba/*2*/; +//// foo.pro/*3*/; + +verify.completions({ + marker: "1", + includes: [ + { name: "Foo", kind: "interface", kindModifiers: "deprecated" } + ] +}, { + marker: "2", + includes: [ + { name: "bar", kind: "method", kindModifiers: "deprecated" } + ] +}, { + marker: "3", + includes: [ + { name: "prop", kind: "property", kindModifiers: "deprecated" } + ] +}); + diff --git a/tests/cases/fourslash/fourslash.ts b/tests/cases/fourslash/fourslash.ts index d7d4935118d0f..bdd7a6f38afb7 100644 --- a/tests/cases/fourslash/fourslash.ts +++ b/tests/cases/fourslash/fourslash.ts @@ -585,6 +585,7 @@ declare namespace FourSlashInterface { range?: Range; code: number; reportsUnnecessary?: true; + reportsDeprecated?: true; } interface VerifyDocumentHighlightsOptions { filesToSearch?: ReadonlyArray; diff --git a/tests/cases/fourslash/jsdocDeprecated_suggestion1.ts b/tests/cases/fourslash/jsdocDeprecated_suggestion1.ts new file mode 100644 index 0000000000000..48cf0dd41c090 --- /dev/null +++ b/tests/cases/fourslash/jsdocDeprecated_suggestion1.ts @@ -0,0 +1,148 @@ +// @Filename: a.ts +//// export namespace foo { +//// /** @deprecated */ +//// export function faff () { } +//// [|faff|]() +//// } +//// const [|a|] = foo.[|faff|]() +//// foo[[|"faff"|]] +//// const { [|faff|] } = foo +//// faff() +//// /** @deprecated */ +//// export function bar () { +//// foo?.[|faff|]() +//// } +//// foo?.[[|"faff"|]]?.() +//// [|bar|](); +//// /** @deprecated */ +//// export interface Foo { +//// /** @deprecated */ +//// zzz: number +//// } +//// /** @deprecated */ +//// export type QW = [|Foo|][[|"zzz"|]] +//// export type WQ = [|QW|] + +// @Filename: b.ts +//// import * as f from './a'; +//// import { bar, QW } from './a'; +//// f.[|bar|](); +//// f.foo.[|faff|](); +//// bar(); +//// type Z = [|QW|]; +//// type A = [|f.Foo|]; +//// type B = [|f.QW|]; +//// type C = [|f.WQ|]; +//// type [|O|] = Z | A | B | C; + +goTo.file('a.ts') +const ranges = test.ranges(); + +verify.getSuggestionDiagnostics([ + { + message: "'faff' is deprecated", + code: 6385, + range: ranges[0], + reportsDeprecated: true, + }, + { + message: "'a' is declared but its value is never read.", + code: 6133, + range: ranges[1], + reportsUnnecessary: true + }, + { + message: "'faff' is deprecated", + code: 6385, + range: ranges[2], + reportsDeprecated: true, + }, + { + message: "'faff' is deprecated", + code: 6385, + range: ranges[3], + reportsDeprecated: true, + }, + { + message: "'faff' is deprecated", + code: 6385, + range: ranges[4], + reportsDeprecated: true, + }, + { + message: "'faff' is deprecated", + code: 6385, + range: ranges[5], + reportsDeprecated: true, + }, + { + message: "'faff' is deprecated", + code: 6385, + range: ranges[6], + reportsDeprecated: true, + }, + { + message: "'bar' is deprecated", + code: 6385, + range: ranges[7], + reportsDeprecated: true, + }, + { + message: "'Foo' is deprecated", + code: 6385, + range: ranges[8], + reportsDeprecated: true, + }, + { + message: "'zzz' is deprecated", + code: 6385, + range: ranges[9], + reportsDeprecated: true, + }, + { + message: "'QW' is deprecated", + code: 6385, + range: ranges[10], + reportsDeprecated: true, + } +]) + +goTo.file('b.ts') +verify.getSuggestionDiagnostics([ + { + message: "'bar' is deprecated", + code: 6385, + range: ranges[11], + reportsDeprecated: true, + }, + { + message: "'faff' is deprecated", + code: 6385, + range: ranges[12], + reportsDeprecated: true, + }, + { + message: "'QW' is deprecated", + code: 6385, + range: ranges[13], + reportsDeprecated: true, + }, + { + message: "'Foo' is deprecated", + code: 6385, + range: ranges[14], + reportsDeprecated: true, + }, + { + message: "'QW' is deprecated", + code: 6385, + range: ranges[15], + reportsDeprecated: true, + }, + { + message: "'O' is declared but never used.", + code: 6196, + range: ranges[17], + reportsUnnecessary: true + } +]) \ No newline at end of file From 70b0445af0009f390110dd6c3887425d158907cc Mon Sep 17 00:00:00 2001 From: kingwl Date: Thu, 28 May 2020 21:06:13 +0800 Subject: [PATCH 20/38] fix perf --- src/compiler/binder.ts | 2 +- src/compiler/utilitiesPublic.ts | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/compiler/binder.ts b/src/compiler/binder.ts index 932e7c13c4cff..5182bcae2ca98 100644 --- a/src/compiler/binder.ts +++ b/src/compiler/binder.ts @@ -414,7 +414,7 @@ namespace ts { Debug.assert(!hasDynamicName(node)); const isDefaultExport = hasSyntacticModifier(node, ModifierFlags.Default) || isExportSpecifier(node) && node.name.escapedText === "default"; - const isDeprecated = !!getJSDocDeprecatedTag(node, /* noCache */ true); + const isDeprecated = hasJSDocNodes(node) && !!getJSDocDeprecatedTag(node); // The exported symbol for an export default function/class node is always named "default" const name = isDefaultExport && parent ? InternalSymbolName.Default : getDeclarationName(node); diff --git a/src/compiler/utilitiesPublic.ts b/src/compiler/utilitiesPublic.ts index 2dda552d4d3dc..934cee5f51c2f 100644 --- a/src/compiler/utilitiesPublic.ts +++ b/src/compiler/utilitiesPublic.ts @@ -760,8 +760,8 @@ namespace ts { } /** Gets the JSDoc deprecated tag for the node if present */ - export function getJSDocDeprecatedTag(node: Node, noCache?: boolean): JSDocDeprecatedTag | undefined { - return getFirstJSDocTag(node, isJSDocDeprecatedTag, noCache); + export function getJSDocDeprecatedTag(node: Node): JSDocDeprecatedTag | undefined { + return getFirstJSDocTag(node, isJSDocDeprecatedTag); } /** Gets the JSDoc type tag for the node if present and valid */ From 8d5bcc00a79de41ea4576e810c277278844cb43e Mon Sep 17 00:00:00 2001 From: kingwl Date: Thu, 28 May 2020 22:33:27 +0800 Subject: [PATCH 21/38] fix public api --- tests/baselines/reference/api/tsserverlibrary.d.ts | 2 +- tests/baselines/reference/api/typescript.d.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/baselines/reference/api/tsserverlibrary.d.ts b/tests/baselines/reference/api/tsserverlibrary.d.ts index 9e4e6ef3eac1f..1ad71ea7899cb 100644 --- a/tests/baselines/reference/api/tsserverlibrary.d.ts +++ b/tests/baselines/reference/api/tsserverlibrary.d.ts @@ -3554,7 +3554,7 @@ declare namespace ts { /** Gets the JSDoc template tag for the node if present */ function getJSDocTemplateTag(node: Node): JSDocTemplateTag | undefined; /** Gets the JSDoc deprecated tag for the node if present */ - function getJSDocDeprecatedTag(node: Node, noCache?: boolean): JSDocDeprecatedTag | undefined; + function getJSDocDeprecatedTag(node: Node): JSDocDeprecatedTag | undefined; /** Gets the JSDoc type tag for the node if present and valid */ function getJSDocTypeTag(node: Node): JSDocTypeTag | undefined; /** diff --git a/tests/baselines/reference/api/typescript.d.ts b/tests/baselines/reference/api/typescript.d.ts index 1c84abe678311..848e286f41d9b 100644 --- a/tests/baselines/reference/api/typescript.d.ts +++ b/tests/baselines/reference/api/typescript.d.ts @@ -3554,7 +3554,7 @@ declare namespace ts { /** Gets the JSDoc template tag for the node if present */ function getJSDocTemplateTag(node: Node): JSDocTemplateTag | undefined; /** Gets the JSDoc deprecated tag for the node if present */ - function getJSDocDeprecatedTag(node: Node, noCache?: boolean): JSDocDeprecatedTag | undefined; + function getJSDocDeprecatedTag(node: Node): JSDocDeprecatedTag | undefined; /** Gets the JSDoc type tag for the node if present and valid */ function getJSDocTypeTag(node: Node): JSDocTypeTag | undefined; /** From b0311e304ff8d4e1a629f934c8b8f50a813432b2 Mon Sep 17 00:00:00 2001 From: kingwl Date: Fri, 12 Jun 2020 17:00:46 +0800 Subject: [PATCH 22/38] Adjust deprecated mark on qualifed name --- src/compiler/checker.ts | 3 ++- tests/cases/fourslash/jsdocDeprecated_suggestion1.ts | 6 +++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 871a4a64d41da..d8da107f2c1cd 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -30354,7 +30354,8 @@ namespace ts { } const symbol = getNodeLinks(node).resolvedSymbol!; if (symbol?.isDeprecated) { - errorOrSuggestion(/* isError */ false, node, Diagnostics._0_is_deprecated, symbol.escapedName as string); + const diagLocation = isTypeReferenceNode(node) && isQualifiedName(node.typeName) ? node.typeName.right : node; + errorOrSuggestion(/* isError */ false, diagLocation, Diagnostics._0_is_deprecated, symbol.escapedName as string); } if (type.flags & TypeFlags.Enum && symbol.flags & SymbolFlags.EnumMember) { error(node, Diagnostics.Enum_type_0_has_members_with_initializers_that_are_not_literals, typeToString(type)); diff --git a/tests/cases/fourslash/jsdocDeprecated_suggestion1.ts b/tests/cases/fourslash/jsdocDeprecated_suggestion1.ts index 48cf0dd41c090..2a506c128c8f4 100644 --- a/tests/cases/fourslash/jsdocDeprecated_suggestion1.ts +++ b/tests/cases/fourslash/jsdocDeprecated_suggestion1.ts @@ -30,9 +30,9 @@ //// f.foo.[|faff|](); //// bar(); //// type Z = [|QW|]; -//// type A = [|f.Foo|]; -//// type B = [|f.QW|]; -//// type C = [|f.WQ|]; +//// type A = f.[|Foo|]; +//// type B = f.[|QW|]; +//// type C = f.[|WQ|]; //// type [|O|] = Z | A | B | C; goTo.file('a.ts') From 182ed1c7850adcc68f18397494f1e4aa39d9eaeb Mon Sep 17 00:00:00 2001 From: kingwl Date: Fri, 12 Jun 2020 20:05:24 +0800 Subject: [PATCH 23/38] Revolve alias symbol --- src/compiler/checker.ts | 63 ++++++++++--------- .../fourslash/jsdocDeprecated_suggestion1.ts | 35 ++++++++--- 2 files changed, 62 insertions(+), 36 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index d8da107f2c1cd..43ff7a230f395 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -21554,7 +21554,8 @@ namespace ts { const localOrExportSymbol = getExportSymbolOfValueSymbolIfExported(symbol); let declaration: Declaration | undefined = localOrExportSymbol.valueDeclaration; - if (symbol?.isDeprecated) { + const target = (symbol.flags & SymbolFlags.Alias ? resolveAlias(symbol) : symbol); + if (target.isDeprecated) { errorOrSuggestion(/* isError */ false, node, Diagnostics._0_is_deprecated, node.escapedText as string); } if (localOrExportSymbol.flags & SymbolFlags.Class) { @@ -34662,33 +34663,39 @@ namespace ts { let symbol = getSymbolOfNode(node); const target = resolveAlias(symbol); - const shouldSkipWithJSExpandoTargets = symbol.flags & SymbolFlags.Assignment; - if (!shouldSkipWithJSExpandoTargets && target !== unknownSymbol) { - // For external modules symbol represents local symbol for an alias. - // This local symbol will merge any other local declarations (excluding other aliases) - // and symbol.flags will contains combined representation for all merged declaration. - // Based on symbol.flags we can compute a set of excluded meanings (meaning that resolved alias should not have, - // otherwise it will conflict with some local declaration). Note that in addition to normal flags we include matching SymbolFlags.Export* - // in order to prevent collisions with declarations that were exported from the current module (they still contribute to local names). - symbol = getMergedSymbol(symbol.exportSymbol || symbol); - const excludedMeanings = - (symbol.flags & (SymbolFlags.Value | SymbolFlags.ExportValue) ? SymbolFlags.Value : 0) | - (symbol.flags & SymbolFlags.Type ? SymbolFlags.Type : 0) | - (symbol.flags & SymbolFlags.Namespace ? SymbolFlags.Namespace : 0); - if (target.flags & excludedMeanings) { - const message = node.kind === SyntaxKind.ExportSpecifier ? - Diagnostics.Export_declaration_conflicts_with_exported_declaration_of_0 : - Diagnostics.Import_declaration_conflicts_with_local_declaration_of_0; - error(node, message, symbolToString(symbol)); - } - - // Don't allow to re-export something with no value side when `--isolatedModules` is set. - if (compilerOptions.isolatedModules - && node.kind === SyntaxKind.ExportSpecifier - && !node.parent.parent.isTypeOnly - && !(target.flags & SymbolFlags.Value) - && !(node.flags & NodeFlags.Ambient)) { - error(node, Diagnostics.Re_exporting_a_type_when_the_isolatedModules_flag_is_provided_requires_using_export_type); + if (target !== unknownSymbol) { + const shouldSkipWithJSExpandoTargets = symbol.flags & SymbolFlags.Assignment; + if (!shouldSkipWithJSExpandoTargets) { + // For external modules symbol represents local symbol for an alias. + // This local symbol will merge any other local declarations (excluding other aliases) + // and symbol.flags will contains combined representation for all merged declaration. + // Based on symbol.flags we can compute a set of excluded meanings (meaning that resolved alias should not have, + // otherwise it will conflict with some local declaration). Note that in addition to normal flags we include matching SymbolFlags.Export* + // in order to prevent collisions with declarations that were exported from the current module (they still contribute to local names). + symbol = getMergedSymbol(symbol.exportSymbol || symbol); + const excludedMeanings = + (symbol.flags & (SymbolFlags.Value | SymbolFlags.ExportValue) ? SymbolFlags.Value : 0) | + (symbol.flags & SymbolFlags.Type ? SymbolFlags.Type : 0) | + (symbol.flags & SymbolFlags.Namespace ? SymbolFlags.Namespace : 0); + if (target.flags & excludedMeanings) { + const message = node.kind === SyntaxKind.ExportSpecifier ? + Diagnostics.Export_declaration_conflicts_with_exported_declaration_of_0 : + Diagnostics.Import_declaration_conflicts_with_local_declaration_of_0; + error(node, message, symbolToString(symbol)); + } + + // Don't allow to re-export something with no value side when `--isolatedModules` is set. + if (compilerOptions.isolatedModules + && node.kind === SyntaxKind.ExportSpecifier + && !node.parent.parent.isTypeOnly + && !(target.flags & SymbolFlags.Value) + && !(node.flags & NodeFlags.Ambient)) { + error(node, Diagnostics.Re_exporting_a_type_when_the_isolatedModules_flag_is_provided_requires_using_export_type); + } + } + + if (isImportSpecifier(node) && target.isDeprecated) { + errorOrSuggestion(/* isError */ false, node.name, Diagnostics._0_is_deprecated, symbol.escapedName as string); } } } diff --git a/tests/cases/fourslash/jsdocDeprecated_suggestion1.ts b/tests/cases/fourslash/jsdocDeprecated_suggestion1.ts index 2a506c128c8f4..92efe352bd68f 100644 --- a/tests/cases/fourslash/jsdocDeprecated_suggestion1.ts +++ b/tests/cases/fourslash/jsdocDeprecated_suggestion1.ts @@ -1,3 +1,4 @@ +// @noUnusedLocals: false // @Filename: a.ts //// export namespace foo { //// /** @deprecated */ @@ -25,14 +26,14 @@ // @Filename: b.ts //// import * as f from './a'; -//// import { bar, QW } from './a'; +//// import { [|bar|], [|QW|] } from './a'; //// f.[|bar|](); //// f.foo.[|faff|](); -//// bar(); +//// [|bar|](); //// type Z = [|QW|]; //// type A = f.[|Foo|]; //// type B = f.[|QW|]; -//// type C = f.[|WQ|]; +//// type C = f.WQ; //// type [|O|] = Z | A | B | C; goTo.file('a.ts') @@ -116,33 +117,51 @@ verify.getSuggestionDiagnostics([ reportsDeprecated: true, }, { - message: "'faff' is deprecated", + message: "'QW' is deprecated", code: 6385, range: ranges[12], reportsDeprecated: true, }, { - message: "'QW' is deprecated", + message: "'bar' is deprecated", code: 6385, range: ranges[13], reportsDeprecated: true, }, { - message: "'Foo' is deprecated", + message: "'faff' is deprecated", code: 6385, range: ranges[14], reportsDeprecated: true, }, { - message: "'QW' is deprecated", + message: "'bar' is deprecated", code: 6385, range: ranges[15], reportsDeprecated: true, }, + { + message: "'QW' is deprecated", + code: 6385, + range: ranges[16], + reportsDeprecated: true, + }, + { + message: "'Foo' is deprecated", + code: 6385, + range: ranges[17], + reportsDeprecated: true, + }, + { + message: "'QW' is deprecated", + code: 6385, + range: ranges[18], + reportsDeprecated: true, + }, { message: "'O' is declared but never used.", code: 6196, - range: ranges[17], + range: ranges[19], reportsUnnecessary: true } ]) \ No newline at end of file From 8b2f1f84a4236444a8c1cea8250b31bc2cc3fe1d Mon Sep 17 00:00:00 2001 From: kingwl Date: Sat, 13 Jun 2020 20:44:31 +0800 Subject: [PATCH 24/38] Use modifier flags insted of symbol props --- src/compiler/binder.ts | 2 -- src/compiler/checker.ts | 24 ++++++++++--------- src/compiler/types.ts | 5 ++-- src/compiler/utilities.ts | 4 ++++ src/services/utilities.ts | 2 +- .../reference/api/tsserverlibrary.d.ts | 3 ++- tests/baselines/reference/api/typescript.d.ts | 3 ++- 7 files changed, 25 insertions(+), 18 deletions(-) diff --git a/src/compiler/binder.ts b/src/compiler/binder.ts index 164d8b7da5e74..0d42737bf4dca 100644 --- a/src/compiler/binder.ts +++ b/src/compiler/binder.ts @@ -414,7 +414,6 @@ namespace ts { Debug.assert(!hasDynamicName(node)); const isDefaultExport = hasSyntacticModifier(node, ModifierFlags.Default) || isExportSpecifier(node) && node.name.escapedText === "default"; - const isDeprecated = hasJSDocNodes(node) && !!getJSDocDeprecatedTag(node); // The exported symbol for an export default function/class node is always named "default" const name = isDefaultExport && parent ? InternalSymbolName.Default : getDeclarationName(node); @@ -534,7 +533,6 @@ namespace ts { } } - symbol.isDeprecated = symbol.isDeprecated || isDeprecated; addDeclarationToSymbol(symbol, node, includes); if (symbol.parent) { Debug.assert(symbol.parent === parent, "Existing symbol parent should match new one"); diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 43ff7a230f395..57f77723dbe2f 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -13027,7 +13027,7 @@ namespace ts { if (propName !== undefined) { const prop = getPropertyOfType(objectType, propName); if (prop) { - if (accessNode && prop?.isDeprecated) { + if (accessNode && hasEffectiveModifierFlagsFromSymbol(prop, ModifierFlags.Deprecated)) { const deprecatedNode = accessExpression?.argumentExpression ?? (isIndexedAccessTypeNode(accessNode) ? accessNode.indexType : accessNode); errorOrSuggestion(/* isError */ false, deprecatedNode, Diagnostics._0_is_deprecated, propName as string); } @@ -21555,7 +21555,7 @@ namespace ts { let declaration: Declaration | undefined = localOrExportSymbol.valueDeclaration; const target = (symbol.flags & SymbolFlags.Alias ? resolveAlias(symbol) : symbol); - if (target.isDeprecated) { + if (hasEffectiveModifierFlagsFromSymbol(target, ModifierFlags.Deprecated)) { errorOrSuggestion(/* isError */ false, node, Diagnostics._0_is_deprecated, node.escapedText as string); } if (localOrExportSymbol.flags & SymbolFlags.Class) { @@ -24528,7 +24528,7 @@ namespace ts { propType = indexInfo.type; } else { - if (prop?.isDeprecated) { + if (hasEffectiveModifierFlagsFromSymbol(prop, ModifierFlags.Deprecated)) { errorOrSuggestion(/* isError */ false, right, Diagnostics._0_is_deprecated, right.escapedText as string); } @@ -30353,13 +30353,15 @@ namespace ts { checkTypeArgumentConstraints(node, typeParameters); } } - const symbol = getNodeLinks(node).resolvedSymbol!; - if (symbol?.isDeprecated) { - const diagLocation = isTypeReferenceNode(node) && isQualifiedName(node.typeName) ? node.typeName.right : node; - errorOrSuggestion(/* isError */ false, diagLocation, Diagnostics._0_is_deprecated, symbol.escapedName as string); - } - if (type.flags & TypeFlags.Enum && symbol.flags & SymbolFlags.EnumMember) { - error(node, Diagnostics.Enum_type_0_has_members_with_initializers_that_are_not_literals, typeToString(type)); + const symbol = getNodeLinks(node).resolvedSymbol; + if (symbol) { + if (hasEffectiveModifierFlagsFromSymbol(symbol, ModifierFlags.Deprecated)) { + const diagLocation = isTypeReferenceNode(node) && isQualifiedName(node.typeName) ? node.typeName.right : node; + errorOrSuggestion(/* isError */ false, diagLocation, Diagnostics._0_is_deprecated, symbol.escapedName as string); + } + if (type.flags & TypeFlags.Enum && symbol.flags & SymbolFlags.EnumMember) { + error(node, Diagnostics.Enum_type_0_has_members_with_initializers_that_are_not_literals, typeToString(type)); + } } } } @@ -34694,7 +34696,7 @@ namespace ts { } } - if (isImportSpecifier(node) && target.isDeprecated) { + if (isImportSpecifier(node) && hasEffectiveModifierFlagsFromSymbol(target, ModifierFlags.Deprecated)) { errorOrSuggestion(/* isError */ false, node.name, Diagnostics._0_is_deprecated, symbol.escapedName as string); } } diff --git a/src/compiler/types.ts b/src/compiler/types.ts index de66024b85578..1c74cae5c7844 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -615,6 +615,8 @@ namespace ts { Default = 1 << 9, // Function/Class (export default declaration) Const = 1 << 11, // Const enum HasComputedJSDocModifiers = 1 << 12, // Indicates the computed modifier flags include modifiers from JSDoc. + + Deprecated = 1 << 13, // Deprecated tag. HasComputedFlags = 1 << 29, // Modifier flags have been computed AccessibilityModifier = Public | Private | Protected, @@ -624,7 +626,7 @@ namespace ts { TypeScriptModifier = Ambient | Public | Private | Protected | Readonly | Abstract | Const, ExportDefault = Export | Default, - All = Export | Ambient | Public | Private | Protected | Static | Readonly | Abstract | Async | Default | Const + All = Export | Ambient | Public | Private | Protected | Static | Readonly | Abstract | Async | Default | Const | Deprecated } export const enum JsxFlags { @@ -4136,7 +4138,6 @@ namespace ts { /* @internal */ isReplaceableByMethod?: boolean; // Can this Javascript class property be replaced by a method symbol? /* @internal */ isAssigned?: boolean; // True if the symbol is a parameter with assignments /* @internal */ assignmentDeclarationMembers?: Map; // detected late-bound assignment declarations associated with the symbol - /* @internal */ isDeprecated?: boolean; } /* @internal */ diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index 3a860e69b1fc0..2ec670c0cb39c 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -4360,6 +4360,10 @@ namespace ts { return getSyntacticModifierFlags(node) & flags; } + export function hasEffectiveModifierFlagsFromSymbol(symbol: Symbol, flags: ModifierFlags): boolean { + return symbol.declarations.some(decl => !!getSelectedEffectiveModifierFlags(decl, flags)); + } + function getModifierFlagsWorker(node: Node, includeJSDoc: boolean): ModifierFlags { if (node.kind >= SyntaxKind.FirstToken && node.kind <= SyntaxKind.LastToken) { return ModifierFlags.None; diff --git a/src/services/utilities.ts b/src/services/utilities.ts index 2fbf0d2cc955b..45e0530d99561 100644 --- a/src/services/utilities.ts +++ b/src/services/utilities.ts @@ -1504,9 +1504,9 @@ namespace ts { if (flags & ModifierFlags.Static) result.push(ScriptElementKindModifier.staticModifier); if (flags & ModifierFlags.Abstract) result.push(ScriptElementKindModifier.abstractModifier); if (flags & ModifierFlags.Export) result.push(ScriptElementKindModifier.exportedModifier); + if (flags & ModifierFlags.Deprecated) result.push(ScriptElementKindModifier.deprecatedModifier); if (node.flags & NodeFlags.Ambient) result.push(ScriptElementKindModifier.ambientModifier); if (node.kind === SyntaxKind.ExportAssignment) result.push(ScriptElementKindModifier.exportedModifier); - if (getJSDocDeprecatedTag(node)) result.push(ScriptElementKindModifier.deprecatedModifier); return result.length > 0 ? result.join(",") : ScriptElementKindModifier.none; } diff --git a/tests/baselines/reference/api/tsserverlibrary.d.ts b/tests/baselines/reference/api/tsserverlibrary.d.ts index 1801434e7417f..653faf3237601 100644 --- a/tests/baselines/reference/api/tsserverlibrary.d.ts +++ b/tests/baselines/reference/api/tsserverlibrary.d.ts @@ -488,13 +488,14 @@ declare namespace ts { Default = 512, Const = 2048, HasComputedJSDocModifiers = 4096, + Deprecated = 8192, HasComputedFlags = 536870912, AccessibilityModifier = 28, ParameterPropertyModifier = 92, NonPublicAccessibilityModifier = 24, TypeScriptModifier = 2270, ExportDefault = 513, - All = 3071 + All = 11263 } export enum JsxFlags { None = 0, diff --git a/tests/baselines/reference/api/typescript.d.ts b/tests/baselines/reference/api/typescript.d.ts index ef7570dd93837..870736e345db2 100644 --- a/tests/baselines/reference/api/typescript.d.ts +++ b/tests/baselines/reference/api/typescript.d.ts @@ -488,13 +488,14 @@ declare namespace ts { Default = 512, Const = 2048, HasComputedJSDocModifiers = 4096, + Deprecated = 8192, HasComputedFlags = 536870912, AccessibilityModifier = 28, ParameterPropertyModifier = 92, NonPublicAccessibilityModifier = 24, TypeScriptModifier = 2270, ExportDefault = 513, - All = 3071 + All = 11263 } export enum JsxFlags { None = 0, From ed18e4a8616f622a0e33194cae533053b28b01a0 Mon Sep 17 00:00:00 2001 From: kingwl Date: Sat, 13 Jun 2020 20:56:59 +0800 Subject: [PATCH 25/38] Fix modifier flag resolve --- src/compiler/utilities.ts | 20 +++++++++++++------ src/compiler/utilitiesPublic.ts | 10 +++++----- .../reference/api/tsserverlibrary.d.ts | 4 ++-- tests/baselines/reference/api/typescript.d.ts | 4 ++-- 4 files changed, 23 insertions(+), 15 deletions(-) diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index 2ec670c0cb39c..aa5c30dd69914 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -4373,10 +4373,13 @@ namespace ts { node.modifierFlagsCache = getSyntacticModifierFlagsNoCache(node) | ModifierFlags.HasComputedFlags; } - if (includeJSDoc && !(node.modifierFlagsCache & ModifierFlags.HasComputedJSDocModifiers) && isInJSFile(node) && node.parent) { + if (includeJSDoc && !(node.modifierFlagsCache & ModifierFlags.HasComputedJSDocModifiers) && node.parent) { node.modifierFlagsCache |= getJSDocModifierFlagsNoCache(node) | ModifierFlags.HasComputedJSDocModifiers; } + if (includeJSDoc && !(node.modifierFlagsCache & ModifierFlags.HasComputedJSDocModifiers) && isInJSFile(node) && node.parent) { + } + return node.modifierFlagsCache & ~(ModifierFlags.HasComputedFlags | ModifierFlags.HasComputedJSDocModifiers); } @@ -4400,12 +4403,17 @@ namespace ts { function getJSDocModifierFlagsNoCache(node: Node): ModifierFlags { let flags = ModifierFlags.None; - if (isInJSFile(node) && !!node.parent && !isParameter(node)) { - if (getJSDocPublicTagNoCache(node)) flags |= ModifierFlags.Public; - if (getJSDocPrivateTagNoCache(node)) flags |= ModifierFlags.Private; - if (getJSDocProtectedTagNoCache(node)) flags |= ModifierFlags.Protected; - if (getJSDocReadonlyTagNoCache(node)) flags |= ModifierFlags.Readonly; + if (!!node.parent && !isParameter(node)) { + if (isInJSFile(node)) { + if (getJSDocPublicTagNoCache(node)) flags |= ModifierFlags.Public; + if (getJSDocPrivateTagNoCache(node)) flags |= ModifierFlags.Private; + if (getJSDocProtectedTagNoCache(node)) flags |= ModifierFlags.Protected; + if (getJSDocReadonlyTagNoCache(node)) flags |= ModifierFlags.Readonly; + + } + if (getJSDocDeprecatedTagNoCache(node)) flags |= ModifierFlags.Deprecated; } + return flags; } diff --git a/src/compiler/utilitiesPublic.ts b/src/compiler/utilitiesPublic.ts index 54abdb26293d3..c0c72d353512e 100644 --- a/src/compiler/utilitiesPublic.ts +++ b/src/compiler/utilitiesPublic.ts @@ -740,6 +740,11 @@ namespace ts { return getFirstJSDocTag(node, isJSDocReadonlyTag, /*noCache*/ true); } + /** Gets the JSDoc deprecated tag for the node if present */ + export function getJSDocDeprecatedTagNoCache(node: Node): JSDocDeprecatedTag | undefined { + return getFirstJSDocTag(node, isJSDocDeprecatedTag, /*noCache*/ true); + } + /** Gets the JSDoc enum tag for the node if present */ export function getJSDocEnumTag(node: Node): JSDocEnumTag | undefined { return getFirstJSDocTag(node, isJSDocEnumTag); @@ -760,11 +765,6 @@ namespace ts { return getFirstJSDocTag(node, isJSDocTemplateTag); } - /** Gets the JSDoc deprecated tag for the node if present */ - export function getJSDocDeprecatedTag(node: Node): JSDocDeprecatedTag | undefined { - return getFirstJSDocTag(node, isJSDocDeprecatedTag); - } - /** Gets the JSDoc type tag for the node if present and valid */ export function getJSDocTypeTag(node: Node): JSDocTypeTag | undefined { // We should have already issued an error if there were multiple type jsdocs, so just use the first one. diff --git a/tests/baselines/reference/api/tsserverlibrary.d.ts b/tests/baselines/reference/api/tsserverlibrary.d.ts index 653faf3237601..c83926df87a4b 100644 --- a/tests/baselines/reference/api/tsserverlibrary.d.ts +++ b/tests/baselines/reference/api/tsserverlibrary.d.ts @@ -3550,6 +3550,8 @@ declare namespace ts { function getJSDocProtectedTag(node: Node): JSDocProtectedTag | undefined; /** Gets the JSDoc protected tag for the node if present */ function getJSDocReadonlyTag(node: Node): JSDocReadonlyTag | undefined; + /** Gets the JSDoc deprecated tag for the node if present */ + function getJSDocDeprecatedTagNoCache(node: Node): JSDocDeprecatedTag | undefined; /** Gets the JSDoc enum tag for the node if present */ function getJSDocEnumTag(node: Node): JSDocEnumTag | undefined; /** Gets the JSDoc this tag for the node if present */ @@ -3558,8 +3560,6 @@ declare namespace ts { function getJSDocReturnTag(node: Node): JSDocReturnTag | undefined; /** Gets the JSDoc template tag for the node if present */ function getJSDocTemplateTag(node: Node): JSDocTemplateTag | undefined; - /** Gets the JSDoc deprecated tag for the node if present */ - function getJSDocDeprecatedTag(node: Node): JSDocDeprecatedTag | undefined; /** Gets the JSDoc type tag for the node if present and valid */ function getJSDocTypeTag(node: Node): JSDocTypeTag | undefined; /** diff --git a/tests/baselines/reference/api/typescript.d.ts b/tests/baselines/reference/api/typescript.d.ts index 870736e345db2..233d5320c3b4b 100644 --- a/tests/baselines/reference/api/typescript.d.ts +++ b/tests/baselines/reference/api/typescript.d.ts @@ -3550,6 +3550,8 @@ declare namespace ts { function getJSDocProtectedTag(node: Node): JSDocProtectedTag | undefined; /** Gets the JSDoc protected tag for the node if present */ function getJSDocReadonlyTag(node: Node): JSDocReadonlyTag | undefined; + /** Gets the JSDoc deprecated tag for the node if present */ + function getJSDocDeprecatedTagNoCache(node: Node): JSDocDeprecatedTag | undefined; /** Gets the JSDoc enum tag for the node if present */ function getJSDocEnumTag(node: Node): JSDocEnumTag | undefined; /** Gets the JSDoc this tag for the node if present */ @@ -3558,8 +3560,6 @@ declare namespace ts { function getJSDocReturnTag(node: Node): JSDocReturnTag | undefined; /** Gets the JSDoc template tag for the node if present */ function getJSDocTemplateTag(node: Node): JSDocTemplateTag | undefined; - /** Gets the JSDoc deprecated tag for the node if present */ - function getJSDocDeprecatedTag(node: Node): JSDocDeprecatedTag | undefined; /** Gets the JSDoc type tag for the node if present and valid */ function getJSDocTypeTag(node: Node): JSDocTypeTag | undefined; /** From 69ddd5f41fcbbb215a40fea880525aa4cccd2e79 Mon Sep 17 00:00:00 2001 From: kingwl Date: Sat, 13 Jun 2020 20:59:12 +0800 Subject: [PATCH 26/38] Make lint happy --- src/compiler/utilities.ts | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index aa5c30dd69914..ad32248d67eb5 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -4377,9 +4377,6 @@ namespace ts { node.modifierFlagsCache |= getJSDocModifierFlagsNoCache(node) | ModifierFlags.HasComputedJSDocModifiers; } - if (includeJSDoc && !(node.modifierFlagsCache & ModifierFlags.HasComputedJSDocModifiers) && isInJSFile(node) && node.parent) { - } - return node.modifierFlagsCache & ~(ModifierFlags.HasComputedFlags | ModifierFlags.HasComputedJSDocModifiers); } @@ -4409,7 +4406,6 @@ namespace ts { if (getJSDocPrivateTagNoCache(node)) flags |= ModifierFlags.Private; if (getJSDocProtectedTagNoCache(node)) flags |= ModifierFlags.Protected; if (getJSDocReadonlyTagNoCache(node)) flags |= ModifierFlags.Readonly; - } if (getJSDocDeprecatedTagNoCache(node)) flags |= ModifierFlags.Deprecated; } From 8fdceabae16ff0ddd1534ea8eb91019cb9c0dee2 Mon Sep 17 00:00:00 2001 From: kingwl Date: Sat, 13 Jun 2020 21:37:42 +0800 Subject: [PATCH 27/38] Fix crash --- src/compiler/utilities.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index ad32248d67eb5..1530d1182f082 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -4361,7 +4361,7 @@ namespace ts { } export function hasEffectiveModifierFlagsFromSymbol(symbol: Symbol, flags: ModifierFlags): boolean { - return symbol.declarations.some(decl => !!getSelectedEffectiveModifierFlags(decl, flags)); + return symbol.declarations?.some(decl => !!getSelectedEffectiveModifierFlags(decl, flags)); } function getModifierFlagsWorker(node: Node, includeJSDoc: boolean): ModifierFlags { From a30a4300257160335b3b1a339fb9eee5dcb42248 Mon Sep 17 00:00:00 2001 From: kingwl Date: Sat, 13 Jun 2020 21:38:16 +0800 Subject: [PATCH 28/38] fix crash --- src/compiler/utilities.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index 1530d1182f082..4ee2a97ba643f 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -4361,7 +4361,7 @@ namespace ts { } export function hasEffectiveModifierFlagsFromSymbol(symbol: Symbol, flags: ModifierFlags): boolean { - return symbol.declarations?.some(decl => !!getSelectedEffectiveModifierFlags(decl, flags)); + return !!symbol.declarations?.some(decl => !!getSelectedEffectiveModifierFlags(decl, flags)); } function getModifierFlagsWorker(node: Node, includeJSDoc: boolean): ModifierFlags { From 7e18beb6749f5d7dd02a4a3a5d73053afe4f5f4d Mon Sep 17 00:00:00 2001 From: kingwl Date: Mon, 15 Jun 2020 10:13:17 +0800 Subject: [PATCH 29/38] Add cached utils function --- src/compiler/utilitiesPublic.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/compiler/utilitiesPublic.ts b/src/compiler/utilitiesPublic.ts index c0c72d353512e..8125d087016c3 100644 --- a/src/compiler/utilitiesPublic.ts +++ b/src/compiler/utilitiesPublic.ts @@ -741,6 +741,11 @@ namespace ts { } /** Gets the JSDoc deprecated tag for the node if present */ + export function getJSDocDeprecatedTag(node: Node): JSDocDeprecatedTag | undefined { + return getFirstJSDocTag(node, isJSDocDeprecatedTag); + } + + /*@internal */ export function getJSDocDeprecatedTagNoCache(node: Node): JSDocDeprecatedTag | undefined { return getFirstJSDocTag(node, isJSDocDeprecatedTag, /*noCache*/ true); } From 22410c18a080a5401282cb7ed1b6868c1cc25b38 Mon Sep 17 00:00:00 2001 From: kingwl Date: Mon, 15 Jun 2020 10:14:52 +0800 Subject: [PATCH 30/38] Accept baseline --- tests/baselines/reference/api/tsserverlibrary.d.ts | 2 +- tests/baselines/reference/api/typescript.d.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/baselines/reference/api/tsserverlibrary.d.ts b/tests/baselines/reference/api/tsserverlibrary.d.ts index c83926df87a4b..6807d050161eb 100644 --- a/tests/baselines/reference/api/tsserverlibrary.d.ts +++ b/tests/baselines/reference/api/tsserverlibrary.d.ts @@ -3551,7 +3551,7 @@ declare namespace ts { /** Gets the JSDoc protected tag for the node if present */ function getJSDocReadonlyTag(node: Node): JSDocReadonlyTag | undefined; /** Gets the JSDoc deprecated tag for the node if present */ - function getJSDocDeprecatedTagNoCache(node: Node): JSDocDeprecatedTag | undefined; + function getJSDocDeprecatedTag(node: Node): JSDocDeprecatedTag | undefined; /** Gets the JSDoc enum tag for the node if present */ function getJSDocEnumTag(node: Node): JSDocEnumTag | undefined; /** Gets the JSDoc this tag for the node if present */ diff --git a/tests/baselines/reference/api/typescript.d.ts b/tests/baselines/reference/api/typescript.d.ts index 233d5320c3b4b..7e3b2cd43e751 100644 --- a/tests/baselines/reference/api/typescript.d.ts +++ b/tests/baselines/reference/api/typescript.d.ts @@ -3551,7 +3551,7 @@ declare namespace ts { /** Gets the JSDoc protected tag for the node if present */ function getJSDocReadonlyTag(node: Node): JSDocReadonlyTag | undefined; /** Gets the JSDoc deprecated tag for the node if present */ - function getJSDocDeprecatedTagNoCache(node: Node): JSDocDeprecatedTag | undefined; + function getJSDocDeprecatedTag(node: Node): JSDocDeprecatedTag | undefined; /** Gets the JSDoc enum tag for the node if present */ function getJSDocEnumTag(node: Node): JSDocEnumTag | undefined; /** Gets the JSDoc this tag for the node if present */ From b1eb8e0eaf87e27279bcbf82a87dfd3546f0a6ad Mon Sep 17 00:00:00 2001 From: kingwl Date: Mon, 15 Jun 2020 10:20:48 +0800 Subject: [PATCH 31/38] Add more tests --- .../reference/jsdocDeprecatedTag1.js | 89 ++++++++++++++ .../reference/jsdocDeprecatedTag1.symbols | 110 ++++++++++++++++++ .../reference/jsdocDeprecatedTag1.types | 109 +++++++++++++++++ .../conformance/jsdoc/jsdocDeprecatedTag1.ts | 37 ++++++ .../fourslash/jsdocDeprecated_suggestion1.ts | 1 - 5 files changed, 345 insertions(+), 1 deletion(-) create mode 100644 tests/baselines/reference/jsdocDeprecatedTag1.js create mode 100644 tests/baselines/reference/jsdocDeprecatedTag1.symbols create mode 100644 tests/baselines/reference/jsdocDeprecatedTag1.types create mode 100644 tests/cases/conformance/jsdoc/jsdocDeprecatedTag1.ts diff --git a/tests/baselines/reference/jsdocDeprecatedTag1.js b/tests/baselines/reference/jsdocDeprecatedTag1.js new file mode 100644 index 0000000000000..d3e40164e22cd --- /dev/null +++ b/tests/baselines/reference/jsdocDeprecatedTag1.js @@ -0,0 +1,89 @@ +//// [tests/cases/conformance/jsdoc/jsdocDeprecatedTag1.ts] //// + +//// [a.ts] +export namespace foo { + /** @deprecated */ + export function faff () { } + faff() +} +const a = foo.faff() +foo["faff"] +const { faff } = foo +faff() +/** @deprecated */ +export function bar () { + foo?.faff() +} +foo?.["faff"]?.() +bar(); +/** @deprecated */ +export interface Foo { + /** @deprecated */ + zzz: number +} +/** @deprecated */ +export type QW = Foo["zzz"] +export type WQ = QW + +//// [b.ts] +import * as f from './a'; +import { bar, QW } from './a'; +f.bar(); +f.foo.faff(); +bar(); +type Z = QW; +type A = f.Foo; +type B = f.QW; +type C = f.WQ; +type O = Z | A | B | C; + +//// [a.js] +"use strict"; +var _a; +exports.__esModule = true; +exports.bar = exports.foo = void 0; +var foo; +(function (foo) { + /** @deprecated */ + function faff() { } + foo.faff = faff; + faff(); +})(foo = exports.foo || (exports.foo = {})); +var a = foo.faff(); +foo["faff"]; +var faff = foo.faff; +faff(); +/** @deprecated */ +function bar() { + foo === null || foo === void 0 ? void 0 : foo.faff(); +} +exports.bar = bar; +(_a = foo === null || foo === void 0 ? void 0 : foo["faff"]) === null || _a === void 0 ? void 0 : _a.call(foo); +bar(); +//// [b.js] +"use strict"; +exports.__esModule = true; +var f = require("./a"); +var a_1 = require("./a"); +f.bar(); +f.foo.faff(); +a_1.bar(); + + +//// [a.d.ts] +export declare namespace foo { + /** @deprecated */ + function faff(): void; +} +/** @deprecated */ +export declare function bar(): void; +/** @deprecated */ +export interface Foo { + /** @deprecated */ + zzz: number; +} +/** @deprecated */ +export declare type QW = Foo["zzz"]; +export declare type WQ = QW; +//// [b.d.ts] +export {}; diff --git a/tests/baselines/reference/jsdocDeprecatedTag1.symbols b/tests/baselines/reference/jsdocDeprecatedTag1.symbols new file mode 100644 index 0000000000000..b17e63f470286 --- /dev/null +++ b/tests/baselines/reference/jsdocDeprecatedTag1.symbols @@ -0,0 +1,110 @@ +=== tests/cases/conformance/jsdoc/a.ts === +export namespace foo { +>foo : Symbol(foo, Decl(a.ts, 0, 0)) + + /** @deprecated */ + export function faff () { } +>faff : Symbol(faff, Decl(a.ts, 0, 22)) + + faff() +>faff : Symbol(faff, Decl(a.ts, 0, 22)) +} +const a = foo.faff() +>a : Symbol(a, Decl(a.ts, 5, 5)) +>foo.faff : Symbol(foo.faff, Decl(a.ts, 0, 22)) +>foo : Symbol(foo, Decl(a.ts, 0, 0)) +>faff : Symbol(foo.faff, Decl(a.ts, 0, 22)) + +foo["faff"] +>foo : Symbol(foo, Decl(a.ts, 0, 0)) +>"faff" : Symbol(foo.faff, Decl(a.ts, 0, 22)) + +const { faff } = foo +>faff : Symbol(faff, Decl(a.ts, 7, 7)) +>foo : Symbol(foo, Decl(a.ts, 0, 0)) + +faff() +>faff : Symbol(faff, Decl(a.ts, 7, 7)) + +/** @deprecated */ +export function bar () { +>bar : Symbol(bar, Decl(a.ts, 8, 6)) + + foo?.faff() +>foo?.faff : Symbol(foo.faff, Decl(a.ts, 0, 22)) +>foo : Symbol(foo, Decl(a.ts, 0, 0)) +>faff : Symbol(foo.faff, Decl(a.ts, 0, 22)) +} +foo?.["faff"]?.() +>foo : Symbol(foo, Decl(a.ts, 0, 0)) +>"faff" : Symbol(foo.faff, Decl(a.ts, 0, 22)) + +bar(); +>bar : Symbol(bar, Decl(a.ts, 8, 6)) + +/** @deprecated */ +export interface Foo { +>Foo : Symbol(Foo, Decl(a.ts, 14, 6)) + + /** @deprecated */ + zzz: number +>zzz : Symbol(Foo.zzz, Decl(a.ts, 16, 22)) +} +/** @deprecated */ +export type QW = Foo["zzz"] +>QW : Symbol(QW, Decl(a.ts, 19, 1)) +>Foo : Symbol(Foo, Decl(a.ts, 14, 6)) + +export type WQ = QW +>WQ : Symbol(WQ, Decl(a.ts, 21, 27)) +>QW : Symbol(QW, Decl(a.ts, 19, 1)) + +=== tests/cases/conformance/jsdoc/b.ts === +import * as f from './a'; +>f : Symbol(f, Decl(b.ts, 0, 6)) + +import { bar, QW } from './a'; +>bar : Symbol(bar, Decl(b.ts, 1, 8)) +>QW : Symbol(QW, Decl(b.ts, 1, 13)) + +f.bar(); +>f.bar : Symbol(f.bar, Decl(a.ts, 8, 6)) +>f : Symbol(f, Decl(b.ts, 0, 6)) +>bar : Symbol(f.bar, Decl(a.ts, 8, 6)) + +f.foo.faff(); +>f.foo.faff : Symbol(f.foo.faff, Decl(a.ts, 0, 22)) +>f.foo : Symbol(f.foo, Decl(a.ts, 0, 0)) +>f : Symbol(f, Decl(b.ts, 0, 6)) +>foo : Symbol(f.foo, Decl(a.ts, 0, 0)) +>faff : Symbol(f.foo.faff, Decl(a.ts, 0, 22)) + +bar(); +>bar : Symbol(bar, Decl(b.ts, 1, 8)) + +type Z = QW; +>Z : Symbol(Z, Decl(b.ts, 4, 6)) +>QW : Symbol(QW, Decl(b.ts, 1, 13)) + +type A = f.Foo; +>A : Symbol(A, Decl(b.ts, 5, 12)) +>f : Symbol(f, Decl(b.ts, 0, 6)) +>Foo : Symbol(f.Foo, Decl(a.ts, 14, 6)) + +type B = f.QW; +>B : Symbol(B, Decl(b.ts, 6, 15)) +>f : Symbol(f, Decl(b.ts, 0, 6)) +>QW : Symbol(f.QW, Decl(a.ts, 19, 1)) + +type C = f.WQ; +>C : Symbol(C, Decl(b.ts, 7, 14)) +>f : Symbol(f, Decl(b.ts, 0, 6)) +>WQ : Symbol(f.WQ, Decl(a.ts, 21, 27)) + +type O = Z | A | B | C; +>O : Symbol(O, Decl(b.ts, 8, 14)) +>Z : Symbol(Z, Decl(b.ts, 4, 6)) +>A : Symbol(A, Decl(b.ts, 5, 12)) +>B : Symbol(B, Decl(b.ts, 6, 15)) +>C : Symbol(C, Decl(b.ts, 7, 14)) + diff --git a/tests/baselines/reference/jsdocDeprecatedTag1.types b/tests/baselines/reference/jsdocDeprecatedTag1.types new file mode 100644 index 0000000000000..1f4eb87db08b3 --- /dev/null +++ b/tests/baselines/reference/jsdocDeprecatedTag1.types @@ -0,0 +1,109 @@ +=== tests/cases/conformance/jsdoc/a.ts === +export namespace foo { +>foo : typeof foo + + /** @deprecated */ + export function faff () { } +>faff : () => void + + faff() +>faff() : void +>faff : () => void +} +const a = foo.faff() +>a : void +>foo.faff() : void +>foo.faff : () => void +>foo : typeof foo +>faff : () => void + +foo["faff"] +>foo["faff"] : () => void +>foo : typeof foo +>"faff" : "faff" + +const { faff } = foo +>faff : () => void +>foo : typeof foo + +faff() +>faff() : void +>faff : () => void + +/** @deprecated */ +export function bar () { +>bar : () => void + + foo?.faff() +>foo?.faff() : void +>foo?.faff : () => void +>foo : typeof foo +>faff : () => void +} +foo?.["faff"]?.() +>foo?.["faff"]?.() : void +>foo?.["faff"] : () => void +>foo : typeof foo +>"faff" : "faff" + +bar(); +>bar() : void +>bar : () => void + +/** @deprecated */ +export interface Foo { + /** @deprecated */ + zzz: number +>zzz : number +} +/** @deprecated */ +export type QW = Foo["zzz"] +>QW : number + +export type WQ = QW +>WQ : number + +=== tests/cases/conformance/jsdoc/b.ts === +import * as f from './a'; +>f : typeof f + +import { bar, QW } from './a'; +>bar : () => void +>QW : any + +f.bar(); +>f.bar() : void +>f.bar : () => void +>f : typeof f +>bar : () => void + +f.foo.faff(); +>f.foo.faff() : void +>f.foo.faff : () => void +>f.foo : typeof f.foo +>f : typeof f +>foo : typeof f.foo +>faff : () => void + +bar(); +>bar() : void +>bar : () => void + +type Z = QW; +>Z : number + +type A = f.Foo; +>A : f.Foo +>f : any + +type B = f.QW; +>B : number +>f : any + +type C = f.WQ; +>C : number +>f : any + +type O = Z | A | B | C; +>O : O + diff --git a/tests/cases/conformance/jsdoc/jsdocDeprecatedTag1.ts b/tests/cases/conformance/jsdoc/jsdocDeprecatedTag1.ts new file mode 100644 index 0000000000000..588381b4792db --- /dev/null +++ b/tests/cases/conformance/jsdoc/jsdocDeprecatedTag1.ts @@ -0,0 +1,37 @@ +// @declaration: true +// @Filename: a.ts +export namespace foo { + /** @deprecated */ + export function faff () { } + faff() +} +const a = foo.faff() +foo["faff"] +const { faff } = foo +faff() +/** @deprecated */ +export function bar () { + foo?.faff() +} +foo?.["faff"]?.() +bar(); +/** @deprecated */ +export interface Foo { + /** @deprecated */ + zzz: number +} +/** @deprecated */ +export type QW = Foo["zzz"] +export type WQ = QW + +// @Filename: b.ts +import * as f from './a'; +import { bar, QW } from './a'; +f.bar(); +f.foo.faff(); +bar(); +type Z = QW; +type A = f.Foo; +type B = f.QW; +type C = f.WQ; +type O = Z | A | B | C; \ No newline at end of file diff --git a/tests/cases/fourslash/jsdocDeprecated_suggestion1.ts b/tests/cases/fourslash/jsdocDeprecated_suggestion1.ts index 92efe352bd68f..a8e13edbe04de 100644 --- a/tests/cases/fourslash/jsdocDeprecated_suggestion1.ts +++ b/tests/cases/fourslash/jsdocDeprecated_suggestion1.ts @@ -1,4 +1,3 @@ -// @noUnusedLocals: false // @Filename: a.ts //// export namespace foo { //// /** @deprecated */ From c89ee760e44f3c7504b4392a5573846d4449c5e2 Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders <293473+sandersn@users.noreply.github.com> Date: Mon, 15 Jun 2020 09:38:15 -0700 Subject: [PATCH 32/38] try pinning octokit again --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index ea458d053aa8d..56e5706038415 100644 --- a/package.json +++ b/package.json @@ -29,7 +29,7 @@ "node": ">=4.2.0" }, "devDependencies": { - "@octokit/rest": "latest", + "@octokit/rest": "17.11.2", "@types/browserify": "latest", "@types/chai": "latest", "@types/convert-source-map": "latest", From 1e00d36032d9e998da5c7e4acf936b654bd32ea3 Mon Sep 17 00:00:00 2001 From: kingwl Date: Tue, 16 Jun 2020 01:18:30 +0800 Subject: [PATCH 33/38] Avoid tests --- .../reference/jsdocDeprecatedTag1.js | 89 -------------- .../reference/jsdocDeprecatedTag1.symbols | 110 ------------------ .../reference/jsdocDeprecatedTag1.types | 109 ----------------- .../conformance/jsdoc/jsdocDeprecatedTag1.ts | 37 ------ 4 files changed, 345 deletions(-) delete mode 100644 tests/baselines/reference/jsdocDeprecatedTag1.js delete mode 100644 tests/baselines/reference/jsdocDeprecatedTag1.symbols delete mode 100644 tests/baselines/reference/jsdocDeprecatedTag1.types delete mode 100644 tests/cases/conformance/jsdoc/jsdocDeprecatedTag1.ts diff --git a/tests/baselines/reference/jsdocDeprecatedTag1.js b/tests/baselines/reference/jsdocDeprecatedTag1.js deleted file mode 100644 index d3e40164e22cd..0000000000000 --- a/tests/baselines/reference/jsdocDeprecatedTag1.js +++ /dev/null @@ -1,89 +0,0 @@ -//// [tests/cases/conformance/jsdoc/jsdocDeprecatedTag1.ts] //// - -//// [a.ts] -export namespace foo { - /** @deprecated */ - export function faff () { } - faff() -} -const a = foo.faff() -foo["faff"] -const { faff } = foo -faff() -/** @deprecated */ -export function bar () { - foo?.faff() -} -foo?.["faff"]?.() -bar(); -/** @deprecated */ -export interface Foo { - /** @deprecated */ - zzz: number -} -/** @deprecated */ -export type QW = Foo["zzz"] -export type WQ = QW - -//// [b.ts] -import * as f from './a'; -import { bar, QW } from './a'; -f.bar(); -f.foo.faff(); -bar(); -type Z = QW; -type A = f.Foo; -type B = f.QW; -type C = f.WQ; -type O = Z | A | B | C; - -//// [a.js] -"use strict"; -var _a; -exports.__esModule = true; -exports.bar = exports.foo = void 0; -var foo; -(function (foo) { - /** @deprecated */ - function faff() { } - foo.faff = faff; - faff(); -})(foo = exports.foo || (exports.foo = {})); -var a = foo.faff(); -foo["faff"]; -var faff = foo.faff; -faff(); -/** @deprecated */ -function bar() { - foo === null || foo === void 0 ? void 0 : foo.faff(); -} -exports.bar = bar; -(_a = foo === null || foo === void 0 ? void 0 : foo["faff"]) === null || _a === void 0 ? void 0 : _a.call(foo); -bar(); -//// [b.js] -"use strict"; -exports.__esModule = true; -var f = require("./a"); -var a_1 = require("./a"); -f.bar(); -f.foo.faff(); -a_1.bar(); - - -//// [a.d.ts] -export declare namespace foo { - /** @deprecated */ - function faff(): void; -} -/** @deprecated */ -export declare function bar(): void; -/** @deprecated */ -export interface Foo { - /** @deprecated */ - zzz: number; -} -/** @deprecated */ -export declare type QW = Foo["zzz"]; -export declare type WQ = QW; -//// [b.d.ts] -export {}; diff --git a/tests/baselines/reference/jsdocDeprecatedTag1.symbols b/tests/baselines/reference/jsdocDeprecatedTag1.symbols deleted file mode 100644 index b17e63f470286..0000000000000 --- a/tests/baselines/reference/jsdocDeprecatedTag1.symbols +++ /dev/null @@ -1,110 +0,0 @@ -=== tests/cases/conformance/jsdoc/a.ts === -export namespace foo { ->foo : Symbol(foo, Decl(a.ts, 0, 0)) - - /** @deprecated */ - export function faff () { } ->faff : Symbol(faff, Decl(a.ts, 0, 22)) - - faff() ->faff : Symbol(faff, Decl(a.ts, 0, 22)) -} -const a = foo.faff() ->a : Symbol(a, Decl(a.ts, 5, 5)) ->foo.faff : Symbol(foo.faff, Decl(a.ts, 0, 22)) ->foo : Symbol(foo, Decl(a.ts, 0, 0)) ->faff : Symbol(foo.faff, Decl(a.ts, 0, 22)) - -foo["faff"] ->foo : Symbol(foo, Decl(a.ts, 0, 0)) ->"faff" : Symbol(foo.faff, Decl(a.ts, 0, 22)) - -const { faff } = foo ->faff : Symbol(faff, Decl(a.ts, 7, 7)) ->foo : Symbol(foo, Decl(a.ts, 0, 0)) - -faff() ->faff : Symbol(faff, Decl(a.ts, 7, 7)) - -/** @deprecated */ -export function bar () { ->bar : Symbol(bar, Decl(a.ts, 8, 6)) - - foo?.faff() ->foo?.faff : Symbol(foo.faff, Decl(a.ts, 0, 22)) ->foo : Symbol(foo, Decl(a.ts, 0, 0)) ->faff : Symbol(foo.faff, Decl(a.ts, 0, 22)) -} -foo?.["faff"]?.() ->foo : Symbol(foo, Decl(a.ts, 0, 0)) ->"faff" : Symbol(foo.faff, Decl(a.ts, 0, 22)) - -bar(); ->bar : Symbol(bar, Decl(a.ts, 8, 6)) - -/** @deprecated */ -export interface Foo { ->Foo : Symbol(Foo, Decl(a.ts, 14, 6)) - - /** @deprecated */ - zzz: number ->zzz : Symbol(Foo.zzz, Decl(a.ts, 16, 22)) -} -/** @deprecated */ -export type QW = Foo["zzz"] ->QW : Symbol(QW, Decl(a.ts, 19, 1)) ->Foo : Symbol(Foo, Decl(a.ts, 14, 6)) - -export type WQ = QW ->WQ : Symbol(WQ, Decl(a.ts, 21, 27)) ->QW : Symbol(QW, Decl(a.ts, 19, 1)) - -=== tests/cases/conformance/jsdoc/b.ts === -import * as f from './a'; ->f : Symbol(f, Decl(b.ts, 0, 6)) - -import { bar, QW } from './a'; ->bar : Symbol(bar, Decl(b.ts, 1, 8)) ->QW : Symbol(QW, Decl(b.ts, 1, 13)) - -f.bar(); ->f.bar : Symbol(f.bar, Decl(a.ts, 8, 6)) ->f : Symbol(f, Decl(b.ts, 0, 6)) ->bar : Symbol(f.bar, Decl(a.ts, 8, 6)) - -f.foo.faff(); ->f.foo.faff : Symbol(f.foo.faff, Decl(a.ts, 0, 22)) ->f.foo : Symbol(f.foo, Decl(a.ts, 0, 0)) ->f : Symbol(f, Decl(b.ts, 0, 6)) ->foo : Symbol(f.foo, Decl(a.ts, 0, 0)) ->faff : Symbol(f.foo.faff, Decl(a.ts, 0, 22)) - -bar(); ->bar : Symbol(bar, Decl(b.ts, 1, 8)) - -type Z = QW; ->Z : Symbol(Z, Decl(b.ts, 4, 6)) ->QW : Symbol(QW, Decl(b.ts, 1, 13)) - -type A = f.Foo; ->A : Symbol(A, Decl(b.ts, 5, 12)) ->f : Symbol(f, Decl(b.ts, 0, 6)) ->Foo : Symbol(f.Foo, Decl(a.ts, 14, 6)) - -type B = f.QW; ->B : Symbol(B, Decl(b.ts, 6, 15)) ->f : Symbol(f, Decl(b.ts, 0, 6)) ->QW : Symbol(f.QW, Decl(a.ts, 19, 1)) - -type C = f.WQ; ->C : Symbol(C, Decl(b.ts, 7, 14)) ->f : Symbol(f, Decl(b.ts, 0, 6)) ->WQ : Symbol(f.WQ, Decl(a.ts, 21, 27)) - -type O = Z | A | B | C; ->O : Symbol(O, Decl(b.ts, 8, 14)) ->Z : Symbol(Z, Decl(b.ts, 4, 6)) ->A : Symbol(A, Decl(b.ts, 5, 12)) ->B : Symbol(B, Decl(b.ts, 6, 15)) ->C : Symbol(C, Decl(b.ts, 7, 14)) - diff --git a/tests/baselines/reference/jsdocDeprecatedTag1.types b/tests/baselines/reference/jsdocDeprecatedTag1.types deleted file mode 100644 index 1f4eb87db08b3..0000000000000 --- a/tests/baselines/reference/jsdocDeprecatedTag1.types +++ /dev/null @@ -1,109 +0,0 @@ -=== tests/cases/conformance/jsdoc/a.ts === -export namespace foo { ->foo : typeof foo - - /** @deprecated */ - export function faff () { } ->faff : () => void - - faff() ->faff() : void ->faff : () => void -} -const a = foo.faff() ->a : void ->foo.faff() : void ->foo.faff : () => void ->foo : typeof foo ->faff : () => void - -foo["faff"] ->foo["faff"] : () => void ->foo : typeof foo ->"faff" : "faff" - -const { faff } = foo ->faff : () => void ->foo : typeof foo - -faff() ->faff() : void ->faff : () => void - -/** @deprecated */ -export function bar () { ->bar : () => void - - foo?.faff() ->foo?.faff() : void ->foo?.faff : () => void ->foo : typeof foo ->faff : () => void -} -foo?.["faff"]?.() ->foo?.["faff"]?.() : void ->foo?.["faff"] : () => void ->foo : typeof foo ->"faff" : "faff" - -bar(); ->bar() : void ->bar : () => void - -/** @deprecated */ -export interface Foo { - /** @deprecated */ - zzz: number ->zzz : number -} -/** @deprecated */ -export type QW = Foo["zzz"] ->QW : number - -export type WQ = QW ->WQ : number - -=== tests/cases/conformance/jsdoc/b.ts === -import * as f from './a'; ->f : typeof f - -import { bar, QW } from './a'; ->bar : () => void ->QW : any - -f.bar(); ->f.bar() : void ->f.bar : () => void ->f : typeof f ->bar : () => void - -f.foo.faff(); ->f.foo.faff() : void ->f.foo.faff : () => void ->f.foo : typeof f.foo ->f : typeof f ->foo : typeof f.foo ->faff : () => void - -bar(); ->bar() : void ->bar : () => void - -type Z = QW; ->Z : number - -type A = f.Foo; ->A : f.Foo ->f : any - -type B = f.QW; ->B : number ->f : any - -type C = f.WQ; ->C : number ->f : any - -type O = Z | A | B | C; ->O : O - diff --git a/tests/cases/conformance/jsdoc/jsdocDeprecatedTag1.ts b/tests/cases/conformance/jsdoc/jsdocDeprecatedTag1.ts deleted file mode 100644 index 588381b4792db..0000000000000 --- a/tests/cases/conformance/jsdoc/jsdocDeprecatedTag1.ts +++ /dev/null @@ -1,37 +0,0 @@ -// @declaration: true -// @Filename: a.ts -export namespace foo { - /** @deprecated */ - export function faff () { } - faff() -} -const a = foo.faff() -foo["faff"] -const { faff } = foo -faff() -/** @deprecated */ -export function bar () { - foo?.faff() -} -foo?.["faff"]?.() -bar(); -/** @deprecated */ -export interface Foo { - /** @deprecated */ - zzz: number -} -/** @deprecated */ -export type QW = Foo["zzz"] -export type WQ = QW - -// @Filename: b.ts -import * as f from './a'; -import { bar, QW } from './a'; -f.bar(); -f.foo.faff(); -bar(); -type Z = QW; -type A = f.Foo; -type B = f.QW; -type C = f.WQ; -type O = Z | A | B | C; \ No newline at end of file From f3e425c105e4b7f6748ae33b37b0299e45e72c64 Mon Sep 17 00:00:00 2001 From: kingwl Date: Tue, 16 Jun 2020 02:23:34 +0800 Subject: [PATCH 34/38] Use utils some --- src/compiler/utilities.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index 4ee2a97ba643f..6e32fe2d8ecb3 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -4361,7 +4361,7 @@ namespace ts { } export function hasEffectiveModifierFlagsFromSymbol(symbol: Symbol, flags: ModifierFlags): boolean { - return !!symbol.declarations?.some(decl => !!getSelectedEffectiveModifierFlags(decl, flags)); + return some(symbol.declarations, decl => !!getSelectedEffectiveModifierFlags(decl, flags)); } function getModifierFlagsWorker(node: Node, includeJSDoc: boolean): ModifierFlags { From 1472263c8563559759b85e20289ae38414fc4294 Mon Sep 17 00:00:00 2001 From: Wenlu Wang Date: Fri, 19 Jun 2020 00:10:43 +0800 Subject: [PATCH 35/38] Deprecated perf test (#3) * check valueDeclaration only * check without modifierFlags * donot check alias * use cached tag * remove call to jsdoc * use deprecated tag * revert changes * Revert mission changes * use node flags * cache result * cache * avoid modifier flags * Opts * fix jsdoc include modifier * fix tests * fix again --- src/compiler/binder.ts | 4 ++++ src/compiler/checker.ts | 10 +++++----- src/compiler/parser.ts | 6 ++++++ src/compiler/types.ts | 2 ++ src/compiler/utilities.ts | 12 ++++++------ src/compiler/utilitiesPublic.ts | 5 +++++ src/services/utilities.ts | 2 +- 7 files changed, 29 insertions(+), 12 deletions(-) diff --git a/src/compiler/binder.ts b/src/compiler/binder.ts index c65b720f8f5f3..ed8ab3dd66bc0 100644 --- a/src/compiler/binder.ts +++ b/src/compiler/binder.ts @@ -537,6 +537,10 @@ namespace ts { symbol.parent = parent; } + if (node.flags & NodeFlags.Deprecated) { + symbol.isDeprecated = true; + } + return symbol; } diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 947b842abd6eb..b23f3be8f301e 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -13146,7 +13146,7 @@ namespace ts { if (propName !== undefined) { const prop = getPropertyOfType(objectType, propName); if (prop) { - if (accessNode && hasEffectiveModifierFlagsFromSymbol(prop, ModifierFlags.Deprecated)) { + if (accessNode && prop.isDeprecated) { const deprecatedNode = accessExpression?.argumentExpression ?? (isIndexedAccessTypeNode(accessNode) ? accessNode.indexType : accessNode); errorOrSuggestion(/* isError */ false, deprecatedNode, Diagnostics._0_is_deprecated, propName as string); } @@ -21681,7 +21681,7 @@ namespace ts { let declaration: Declaration | undefined = localOrExportSymbol.valueDeclaration; const target = (symbol.flags & SymbolFlags.Alias ? resolveAlias(symbol) : symbol); - if (hasEffectiveModifierFlagsFromSymbol(target, ModifierFlags.Deprecated)) { + if (target.isDeprecated) { errorOrSuggestion(/* isError */ false, node, Diagnostics._0_is_deprecated, node.escapedText as string); } if (localOrExportSymbol.flags & SymbolFlags.Class) { @@ -24654,7 +24654,7 @@ namespace ts { propType = indexInfo.type; } else { - if (hasEffectiveModifierFlagsFromSymbol(prop, ModifierFlags.Deprecated)) { + if (prop.isDeprecated) { errorOrSuggestion(/* isError */ false, right, Diagnostics._0_is_deprecated, right.escapedText as string); } @@ -30480,7 +30480,7 @@ namespace ts { } const symbol = getNodeLinks(node).resolvedSymbol; if (symbol) { - if (hasEffectiveModifierFlagsFromSymbol(symbol, ModifierFlags.Deprecated)) { + if (symbol.isDeprecated) { const diagLocation = isTypeReferenceNode(node) && isQualifiedName(node.typeName) ? node.typeName.right : node; errorOrSuggestion(/* isError */ false, diagLocation, Diagnostics._0_is_deprecated, symbol.escapedName as string); } @@ -34821,7 +34821,7 @@ namespace ts { } } - if (isImportSpecifier(node) && hasEffectiveModifierFlagsFromSymbol(target, ModifierFlags.Deprecated)) { + if (isImportSpecifier(node) && target.isDeprecated) { errorOrSuggestion(/* isError */ false, node.name, Diagnostics._0_is_deprecated, symbol.escapedName as string); } } diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index e09443cfed305..f137b4b6032a7 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -1014,10 +1014,15 @@ namespace ts { return hasJSDoc ? addJSDocComment(node) : node; } + let hasDeprecatedTag = false; function addJSDocComment(node: T): T { Debug.assert(!node.jsDoc); // Should only be called once per node const jsDoc = mapDefined(getJSDocCommentRanges(node, sourceText), comment => JSDocParser.parseJSDocComment(node, comment.pos, comment.end - comment.pos)); if (jsDoc.length) node.jsDoc = jsDoc; + if (hasDeprecatedTag) { + hasDeprecatedTag = false; + (node as Mutable).flags |= NodeFlags.Deprecated; + } return node; } @@ -7179,6 +7184,7 @@ namespace ts { tag = parseSimpleTag(start, factory.createJSDocReadonlyTag, tagName, margin, indentText); break; case "deprecated": + hasDeprecatedTag = true; tag = parseSimpleTag(start, factory.createJSDocDeprecatedTag, tagName, margin, indentText); break; case "this": diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 6ae6d7ddc6891..87fb01dd578d1 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -754,6 +754,7 @@ namespace ts { /* @internal */ InWithStatement = 1 << 24, // If any ancestor of node was the `statement` of a WithStatement (not the `expression`) JsonFile = 1 << 25, // If node was parsed in a Json /* @internal */ TypeCached = 1 << 26, // If a type was cached for node at any point + /* @internal */ Deprecated = 1 << 27, // If has '@deprecated' JSDoc tag BlockScoped = Let | Const, @@ -4587,6 +4588,7 @@ namespace ts { /* @internal */ isReplaceableByMethod?: boolean; // Can this Javascript class property be replaced by a method symbol? /* @internal */ isAssigned?: boolean; // True if the symbol is a parameter with assignments /* @internal */ assignmentDeclarationMembers?: Map; // detected late-bound assignment declarations associated with the symbol + /* @internal */ isDeprecated?: boolean } /* @internal */ diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index a7f241712047d..b147e79348733 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -4555,11 +4555,7 @@ namespace ts { return getSyntacticModifierFlags(node) & flags; } - export function hasEffectiveModifierFlagsFromSymbol(symbol: Symbol, flags: ModifierFlags): boolean { - return some(symbol.declarations, decl => !!getSelectedEffectiveModifierFlags(decl, flags)); - } - - function getModifierFlagsWorker(node: Node, includeJSDoc: boolean): ModifierFlags { + function getModifierFlagsWorker(node: Node, includeJSDoc: boolean, alwaysIncludeJSDoc?: boolean): ModifierFlags { if (node.kind >= SyntaxKind.FirstToken && node.kind <= SyntaxKind.LastToken) { return ModifierFlags.None; } @@ -4568,7 +4564,7 @@ namespace ts { node.modifierFlagsCache = getSyntacticModifierFlagsNoCache(node) | ModifierFlags.HasComputedFlags; } - if (includeJSDoc && !(node.modifierFlagsCache & ModifierFlags.HasComputedJSDocModifiers) && node.parent) { + if (includeJSDoc && !(node.modifierFlagsCache & ModifierFlags.HasComputedJSDocModifiers) && (alwaysIncludeJSDoc || isInJSFile(node)) && node.parent) { node.modifierFlagsCache |= getJSDocModifierFlagsNoCache(node) | ModifierFlags.HasComputedJSDocModifiers; } @@ -4584,6 +4580,10 @@ namespace ts { return getModifierFlagsWorker(node, /*includeJSDoc*/ true); } + export function getEffectiveModifierFlagsAlwaysIncludeJSDoc(node: Node): ModifierFlags { + return getModifierFlagsWorker(node, /*includeJSDOc*/ true, /*alwaysIncludeJSDOc*/ true); + } + /** * Gets the ModifierFlags for syntactic modifiers on the provided node. The modifiers will be cached on the node to improve performance. * diff --git a/src/compiler/utilitiesPublic.ts b/src/compiler/utilitiesPublic.ts index 3b29fd65a17d8..e9d28e8fab5c1 100644 --- a/src/compiler/utilitiesPublic.ts +++ b/src/compiler/utilitiesPublic.ts @@ -302,6 +302,11 @@ namespace ts { return getCombinedFlags(node, getEffectiveModifierFlags); } + /* @internal */ + export function getCombinedNodeFlagsAlwaysIncludeJSDoc(node: Declaration): ModifierFlags { + return getCombinedFlags(node, getEffectiveModifierFlagsAlwaysIncludeJSDoc); + } + // Returns the node flags for this node and all relevant parent nodes. This is done so that // nodes like variable declarations and binding elements can returned a view of their flags // that includes the modifiers from their container. i.e. flags like export/declare aren't diff --git a/src/services/utilities.ts b/src/services/utilities.ts index a0ca1790fdf97..5b9c2b1738016 100644 --- a/src/services/utilities.ts +++ b/src/services/utilities.ts @@ -1495,7 +1495,7 @@ namespace ts { } export function getNodeModifiers(node: Node): string { - const flags = isDeclaration(node) ? getCombinedModifierFlags(node) : ModifierFlags.None; + const flags = isDeclaration(node) ? getCombinedNodeFlagsAlwaysIncludeJSDoc(node) : ModifierFlags.None; const result: string[] = []; if (flags & ModifierFlags.Private) result.push(ScriptElementKindModifier.privateMemberModifier); From 2d189dc69fe984d8143c96a0942c37d3037c556b Mon Sep 17 00:00:00 2001 From: kingwl Date: Fri, 19 Jun 2020 02:08:35 +0800 Subject: [PATCH 36/38] use symbol flag --- src/compiler/binder.ts | 2 +- src/compiler/checker.ts | 10 +++++----- src/compiler/types.ts | 5 ++--- tests/baselines/reference/api/tsserverlibrary.d.ts | 1 + tests/baselines/reference/api/typescript.d.ts | 1 + 5 files changed, 10 insertions(+), 9 deletions(-) diff --git a/src/compiler/binder.ts b/src/compiler/binder.ts index ed8ab3dd66bc0..7549759138967 100644 --- a/src/compiler/binder.ts +++ b/src/compiler/binder.ts @@ -538,7 +538,7 @@ namespace ts { } if (node.flags & NodeFlags.Deprecated) { - symbol.isDeprecated = true; + symbol.flags |= SymbolFlags.Deprecated; } return symbol; diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index b23f3be8f301e..4a47ca884a6e3 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -13146,7 +13146,7 @@ namespace ts { if (propName !== undefined) { const prop = getPropertyOfType(objectType, propName); if (prop) { - if (accessNode && prop.isDeprecated) { + if (accessNode && prop.flags & SymbolFlags.Deprecated) { const deprecatedNode = accessExpression?.argumentExpression ?? (isIndexedAccessTypeNode(accessNode) ? accessNode.indexType : accessNode); errorOrSuggestion(/* isError */ false, deprecatedNode, Diagnostics._0_is_deprecated, propName as string); } @@ -21681,7 +21681,7 @@ namespace ts { let declaration: Declaration | undefined = localOrExportSymbol.valueDeclaration; const target = (symbol.flags & SymbolFlags.Alias ? resolveAlias(symbol) : symbol); - if (target.isDeprecated) { + if (target.flags & SymbolFlags.Deprecated) { errorOrSuggestion(/* isError */ false, node, Diagnostics._0_is_deprecated, node.escapedText as string); } if (localOrExportSymbol.flags & SymbolFlags.Class) { @@ -24654,7 +24654,7 @@ namespace ts { propType = indexInfo.type; } else { - if (prop.isDeprecated) { + if (prop.flags & SymbolFlags.Deprecated) { errorOrSuggestion(/* isError */ false, right, Diagnostics._0_is_deprecated, right.escapedText as string); } @@ -30480,7 +30480,7 @@ namespace ts { } const symbol = getNodeLinks(node).resolvedSymbol; if (symbol) { - if (symbol.isDeprecated) { + if (symbol.flags & SymbolFlags.Deprecated) { const diagLocation = isTypeReferenceNode(node) && isQualifiedName(node.typeName) ? node.typeName.right : node; errorOrSuggestion(/* isError */ false, diagLocation, Diagnostics._0_is_deprecated, symbol.escapedName as string); } @@ -34821,7 +34821,7 @@ namespace ts { } } - if (isImportSpecifier(node) && target.isDeprecated) { + if (isImportSpecifier(node) && target.flags & SymbolFlags.Deprecated) { errorOrSuggestion(/* isError */ false, node.name, Diagnostics._0_is_deprecated, symbol.escapedName as string); } } diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 87fb01dd578d1..f8e6cdf345ea4 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -4508,10 +4508,10 @@ namespace ts { Transient = 1 << 25, // Transient symbol (created during type check) Assignment = 1 << 26, // Assignment treated as declaration (eg `this.prop = 1`) ModuleExports = 1 << 27, // Symbol for CommonJS `module` of `module.exports` - + Deprecated = 1 << 28, // Symbol has Deprecated declaration tag (eg `@deprecated`) /* @internal */ All = FunctionScopedVariable | BlockScopedVariable | Property | EnumMember | Function | Class | Interface | ConstEnum | RegularEnum | ValueModule | NamespaceModule | TypeLiteral - | ObjectLiteral | Method | Constructor | GetAccessor | SetAccessor | Signature | TypeParameter | TypeAlias | ExportValue | Alias | Prototype | ExportStar | Optional | Transient, + | ObjectLiteral | Method | Constructor | GetAccessor | SetAccessor | Signature | TypeParameter | TypeAlias | ExportValue | Alias | Prototype | ExportStar | Optional | Transient | Deprecated, Enum = RegularEnum | ConstEnum, Variable = FunctionScopedVariable | BlockScopedVariable, @@ -4588,7 +4588,6 @@ namespace ts { /* @internal */ isReplaceableByMethod?: boolean; // Can this Javascript class property be replaced by a method symbol? /* @internal */ isAssigned?: boolean; // True if the symbol is a parameter with assignments /* @internal */ assignmentDeclarationMembers?: Map; // detected late-bound assignment declarations associated with the symbol - /* @internal */ isDeprecated?: boolean } /* @internal */ diff --git a/tests/baselines/reference/api/tsserverlibrary.d.ts b/tests/baselines/reference/api/tsserverlibrary.d.ts index eb38687b7c340..21b0fcd3276f2 100644 --- a/tests/baselines/reference/api/tsserverlibrary.d.ts +++ b/tests/baselines/reference/api/tsserverlibrary.d.ts @@ -2313,6 +2313,7 @@ declare namespace ts { Transient = 33554432, Assignment = 67108864, ModuleExports = 134217728, + Deprecated = 268435456, Enum = 384, Variable = 3, Value = 111551, diff --git a/tests/baselines/reference/api/typescript.d.ts b/tests/baselines/reference/api/typescript.d.ts index 256ed45940118..23b40aabb02c9 100644 --- a/tests/baselines/reference/api/typescript.d.ts +++ b/tests/baselines/reference/api/typescript.d.ts @@ -2313,6 +2313,7 @@ declare namespace ts { Transient = 33554432, Assignment = 67108864, ModuleExports = 134217728, + Deprecated = 268435456, Enum = 384, Variable = 3, Value = 111551, From 6b30216ad43d317c5652025824ea26f1269d42b0 Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders <293473+sandersn@users.noreply.github.com> Date: Thu, 18 Jun 2020 16:49:14 -0700 Subject: [PATCH 37/38] set @octokit/rest back to latest --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 2ca5f1a19a977..b8700085ad8a1 100644 --- a/package.json +++ b/package.json @@ -29,7 +29,7 @@ "node": ">=4.2.0" }, "devDependencies": { - "@octokit/rest": "17.11.2", + "@octokit/rest": "latest", "@types/browserify": "latest", "@types/chai": "latest", "@types/convert-source-map": "latest", From 6434447c678c8779badc6157b5d8ab0c217e0c75 Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders <293473+sandersn@users.noreply.github.com> Date: Thu, 18 Jun 2020 17:15:07 -0700 Subject: [PATCH 38/38] fix trailing spacel int --- src/compiler/types.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 13bb9b17c7d23..c9facd108a4c5 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -4511,7 +4511,7 @@ namespace ts { Transient = 1 << 25, // Transient symbol (created during type check) Assignment = 1 << 26, // Assignment treated as declaration (eg `this.prop = 1`) ModuleExports = 1 << 27, // Symbol for CommonJS `module` of `module.exports` - Deprecated = 1 << 28, // Symbol has Deprecated declaration tag (eg `@deprecated`) + Deprecated = 1 << 28, // Symbol has Deprecated declaration tag (eg `@deprecated`) /* @internal */ All = FunctionScopedVariable | BlockScopedVariable | Property | EnumMember | Function | Class | Interface | ConstEnum | RegularEnum | ValueModule | NamespaceModule | TypeLiteral | ObjectLiteral | Method | Constructor | GetAccessor | SetAccessor | Signature | TypeParameter | TypeAlias | ExportValue | Alias | Prototype | ExportStar | Optional | Transient | Deprecated, pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy