Skip to content

Commit

Permalink
Check combined node flags for deprecated flags
Browse files Browse the repository at this point in the history
  • Loading branch information
Kingwl committed Jul 2, 2020
1 parent 6253e87 commit 57b28d2
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 8 deletions.
16 changes: 8 additions & 8 deletions src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13287,7 +13287,7 @@ namespace ts {
function isUncalledFunctionReference(node: Node, symbol: Symbol) {
return !(symbol.flags & SymbolFlags.Function)
|| !isCallExpression(findAncestor(node, n => !isAccessExpression(n)) ?? node.parent)
&& every(symbol.declarations, d => !isFunctionLike(d) || !!(d.flags & NodeFlags.Deprecated));
&& every(symbol.declarations, d => !isFunctionLike(d) || !!(getCombinedNodeFlags(d) & NodeFlags.Deprecated));
}

function getPropertyTypeForIndexType(originalObjectType: Type, objectType: Type, indexType: Type, fullIndexType: Type, suppressNoImplicitAnyError: boolean, accessNode: ElementAccessExpression | IndexedAccessTypeNode | PropertyName | BindingName | SyntheticExpression | undefined, accessFlags: AccessFlags) {
Expand All @@ -13296,7 +13296,7 @@ namespace ts {
if (propName !== undefined) {
const prop = getPropertyOfType(objectType, propName);
if (prop) {
if (accessNode && prop.valueDeclaration?.flags & NodeFlags.Deprecated && isUncalledFunctionReference(accessNode, prop)) {
if (accessNode && prop.valueDeclaration && getCombinedNodeFlags(prop.valueDeclaration) & NodeFlags.Deprecated && isUncalledFunctionReference(accessNode, prop)) {
const deprecatedNode = accessExpression?.argumentExpression ?? (isIndexedAccessTypeNode(accessNode) ? accessNode.indexType : accessNode);
errorOrSuggestion(/* isError */ false, deprecatedNode, Diagnostics._0_is_deprecated, propName as string);
}
Expand Down Expand Up @@ -22061,7 +22061,7 @@ namespace ts {
const localOrExportSymbol = getExportSymbolOfValueSymbolIfExported(symbol);
let declaration: Declaration | undefined = localOrExportSymbol.valueDeclaration;

if (declaration?.flags & NodeFlags.Deprecated && isUncalledFunctionReference(node.parent, localOrExportSymbol)) {
if (declaration && getCombinedNodeFlags(declaration) & NodeFlags.Deprecated && isUncalledFunctionReference(node.parent, localOrExportSymbol)) {
errorOrSuggestion(/* isError */ false, node, Diagnostics._0_is_deprecated, node.escapedText as string);;
}
if (localOrExportSymbol.flags & SymbolFlags.Class) {
Expand Down Expand Up @@ -25037,7 +25037,7 @@ namespace ts {
propType = indexInfo.type;
}
else {
if (prop.valueDeclaration?.flags & NodeFlags.Deprecated && isUncalledFunctionReference(node, prop)) {
if (prop.valueDeclaration && getCombinedNodeFlags(prop.valueDeclaration) & NodeFlags.Deprecated && isUncalledFunctionReference(node, prop)) {
errorOrSuggestion(/* isError */ false, right, Diagnostics._0_is_deprecated, right.escapedText as string);
}

Expand Down Expand Up @@ -27429,7 +27429,7 @@ namespace ts {
return nonInferrableType;
}

if (signature.declaration && signature.declaration.flags & NodeFlags.Deprecated) {
if (signature.declaration && getCombinedNodeFlags(signature.declaration) & NodeFlags.Deprecated) {
errorOrSuggestion(/*isError*/ false, node, Diagnostics._0_is_deprecated, signatureToString(signature));
}

Expand Down Expand Up @@ -30876,7 +30876,7 @@ namespace ts {
}
const symbol = getNodeLinks(node).resolvedSymbol;
if (symbol) {
if (every(symbol.declarations, d => !isTypeDeclaration(d) || !!(d.flags & NodeFlags.Deprecated))) {
if (every(symbol.declarations, d => !isTypeDeclaration(d) || !!(getCombinedNodeFlags(d) & NodeFlags.Deprecated))) {
const diagLocation = isTypeReferenceNode(node) && isQualifiedName(node.typeName) ? node.typeName.right : node;
errorOrSuggestion(/* isError */ false, diagLocation, Diagnostics._0_is_deprecated, symbol.escapedName as string);
}
Expand Down Expand Up @@ -35222,8 +35222,8 @@ namespace ts {
}

if (isImportSpecifier(node) &&
(target.valueDeclaration && target.valueDeclaration.flags & NodeFlags.Deprecated
|| every(target.declarations, d => !!(d.flags & NodeFlags.Deprecated)))) {
(target.valueDeclaration && getCombinedNodeFlags(target.valueDeclaration) & NodeFlags.Deprecated
|| every(target.declarations, d => !!(getCombinedNodeFlags(d) & NodeFlags.Deprecated)))) {
errorOrSuggestion(/* isError */ false, node.name, Diagnostics._0_is_deprecated, symbol.escapedName as string);
}
}
Expand Down
46 changes: 46 additions & 0 deletions tests/cases/fourslash/jsdocDeprecated_suggestion5.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// @Filename: a.tsx
//// /** @deprecated */
//// type Props = {}

//// /** @deprecated */
//// const Component = (props: [|Props|]) => props && <div />;

//// <[|Component|] old="old" new="new" />

//// /** @deprecated */
//// type Options = {}

//// /** @deprecated */
//// const deprecatedFunction = (options: [|Options|]) => { options }

//// [|deprecatedFunction|]({});

goTo.file('a.tsx')
const ranges = test.ranges();

verify.getSuggestionDiagnostics([
{
message: "'Props' is deprecated",
code: 6385,
range: ranges[0],
reportsDeprecated: true,
},
{
message: "'Component' is deprecated",
code: 6385,
range: ranges[1],
reportsDeprecated: true
},
{
message: "'Options' is deprecated",
code: 6385,
range: ranges[2],
reportsDeprecated: true,
},
{
message: "'deprecatedFunction' is deprecated",
code: 6385,
range: ranges[3],
reportsDeprecated: true,
}
])

0 comments on commit 57b28d2

Please sign in to comment.