Skip to content

Commit 1472263

Browse files
authored
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
1 parent 30fe85c commit 1472263

File tree

7 files changed

+29
-12
lines changed

7 files changed

+29
-12
lines changed

src/compiler/binder.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -537,6 +537,10 @@ namespace ts {
537537
symbol.parent = parent;
538538
}
539539

540+
if (node.flags & NodeFlags.Deprecated) {
541+
symbol.isDeprecated = true;
542+
}
543+
540544
return symbol;
541545
}
542546

src/compiler/checker.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13146,7 +13146,7 @@ namespace ts {
1314613146
if (propName !== undefined) {
1314713147
const prop = getPropertyOfType(objectType, propName);
1314813148
if (prop) {
13149-
if (accessNode && hasEffectiveModifierFlagsFromSymbol(prop, ModifierFlags.Deprecated)) {
13149+
if (accessNode && prop.isDeprecated) {
1315013150
const deprecatedNode = accessExpression?.argumentExpression ?? (isIndexedAccessTypeNode(accessNode) ? accessNode.indexType : accessNode);
1315113151
errorOrSuggestion(/* isError */ false, deprecatedNode, Diagnostics._0_is_deprecated, propName as string);
1315213152
}
@@ -21681,7 +21681,7 @@ namespace ts {
2168121681
let declaration: Declaration | undefined = localOrExportSymbol.valueDeclaration;
2168221682

2168321683
const target = (symbol.flags & SymbolFlags.Alias ? resolveAlias(symbol) : symbol);
21684-
if (hasEffectiveModifierFlagsFromSymbol(target, ModifierFlags.Deprecated)) {
21684+
if (target.isDeprecated) {
2168521685
errorOrSuggestion(/* isError */ false, node, Diagnostics._0_is_deprecated, node.escapedText as string);
2168621686
}
2168721687
if (localOrExportSymbol.flags & SymbolFlags.Class) {
@@ -24654,7 +24654,7 @@ namespace ts {
2465424654
propType = indexInfo.type;
2465524655
}
2465624656
else {
24657-
if (hasEffectiveModifierFlagsFromSymbol(prop, ModifierFlags.Deprecated)) {
24657+
if (prop.isDeprecated) {
2465824658
errorOrSuggestion(/* isError */ false, right, Diagnostics._0_is_deprecated, right.escapedText as string);
2465924659
}
2466024660

@@ -30480,7 +30480,7 @@ namespace ts {
3048030480
}
3048130481
const symbol = getNodeLinks(node).resolvedSymbol;
3048230482
if (symbol) {
30483-
if (hasEffectiveModifierFlagsFromSymbol(symbol, ModifierFlags.Deprecated)) {
30483+
if (symbol.isDeprecated) {
3048430484
const diagLocation = isTypeReferenceNode(node) && isQualifiedName(node.typeName) ? node.typeName.right : node;
3048530485
errorOrSuggestion(/* isError */ false, diagLocation, Diagnostics._0_is_deprecated, symbol.escapedName as string);
3048630486
}
@@ -34821,7 +34821,7 @@ namespace ts {
3482134821
}
3482234822
}
3482334823

34824-
if (isImportSpecifier(node) && hasEffectiveModifierFlagsFromSymbol(target, ModifierFlags.Deprecated)) {
34824+
if (isImportSpecifier(node) && target.isDeprecated) {
3482534825
errorOrSuggestion(/* isError */ false, node.name, Diagnostics._0_is_deprecated, symbol.escapedName as string);
3482634826
}
3482734827
}

src/compiler/parser.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1014,10 +1014,15 @@ namespace ts {
10141014
return hasJSDoc ? addJSDocComment(node) : node;
10151015
}
10161016

1017+
let hasDeprecatedTag = false;
10171018
function addJSDocComment<T extends HasJSDoc>(node: T): T {
10181019
Debug.assert(!node.jsDoc); // Should only be called once per node
10191020
const jsDoc = mapDefined(getJSDocCommentRanges(node, sourceText), comment => JSDocParser.parseJSDocComment(node, comment.pos, comment.end - comment.pos));
10201021
if (jsDoc.length) node.jsDoc = jsDoc;
1022+
if (hasDeprecatedTag) {
1023+
hasDeprecatedTag = false;
1024+
(node as Mutable<T>).flags |= NodeFlags.Deprecated;
1025+
}
10211026
return node;
10221027
}
10231028

@@ -7179,6 +7184,7 @@ namespace ts {
71797184
tag = parseSimpleTag(start, factory.createJSDocReadonlyTag, tagName, margin, indentText);
71807185
break;
71817186
case "deprecated":
7187+
hasDeprecatedTag = true;
71827188
tag = parseSimpleTag(start, factory.createJSDocDeprecatedTag, tagName, margin, indentText);
71837189
break;
71847190
case "this":

src/compiler/types.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -754,6 +754,7 @@ namespace ts {
754754
/* @internal */ InWithStatement = 1 << 24, // If any ancestor of node was the `statement` of a WithStatement (not the `expression`)
755755
JsonFile = 1 << 25, // If node was parsed in a Json
756756
/* @internal */ TypeCached = 1 << 26, // If a type was cached for node at any point
757+
/* @internal */ Deprecated = 1 << 27, // If has '@deprecated' JSDoc tag
757758

758759
BlockScoped = Let | Const,
759760

@@ -4587,6 +4588,7 @@ namespace ts {
45874588
/* @internal */ isReplaceableByMethod?: boolean; // Can this Javascript class property be replaced by a method symbol?
45884589
/* @internal */ isAssigned?: boolean; // True if the symbol is a parameter with assignments
45894590
/* @internal */ assignmentDeclarationMembers?: Map<Declaration>; // detected late-bound assignment declarations associated with the symbol
4591+
/* @internal */ isDeprecated?: boolean
45904592
}
45914593

45924594
/* @internal */

src/compiler/utilities.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4555,11 +4555,7 @@ namespace ts {
45554555
return getSyntacticModifierFlags(node) & flags;
45564556
}
45574557

4558-
export function hasEffectiveModifierFlagsFromSymbol(symbol: Symbol, flags: ModifierFlags): boolean {
4559-
return some(symbol.declarations, decl => !!getSelectedEffectiveModifierFlags(decl, flags));
4560-
}
4561-
4562-
function getModifierFlagsWorker(node: Node, includeJSDoc: boolean): ModifierFlags {
4558+
function getModifierFlagsWorker(node: Node, includeJSDoc: boolean, alwaysIncludeJSDoc?: boolean): ModifierFlags {
45634559
if (node.kind >= SyntaxKind.FirstToken && node.kind <= SyntaxKind.LastToken) {
45644560
return ModifierFlags.None;
45654561
}
@@ -4568,7 +4564,7 @@ namespace ts {
45684564
node.modifierFlagsCache = getSyntacticModifierFlagsNoCache(node) | ModifierFlags.HasComputedFlags;
45694565
}
45704566

4571-
if (includeJSDoc && !(node.modifierFlagsCache & ModifierFlags.HasComputedJSDocModifiers) && node.parent) {
4567+
if (includeJSDoc && !(node.modifierFlagsCache & ModifierFlags.HasComputedJSDocModifiers) && (alwaysIncludeJSDoc || isInJSFile(node)) && node.parent) {
45724568
node.modifierFlagsCache |= getJSDocModifierFlagsNoCache(node) | ModifierFlags.HasComputedJSDocModifiers;
45734569
}
45744570

@@ -4584,6 +4580,10 @@ namespace ts {
45844580
return getModifierFlagsWorker(node, /*includeJSDoc*/ true);
45854581
}
45864582

4583+
export function getEffectiveModifierFlagsAlwaysIncludeJSDoc(node: Node): ModifierFlags {
4584+
return getModifierFlagsWorker(node, /*includeJSDOc*/ true, /*alwaysIncludeJSDOc*/ true);
4585+
}
4586+
45874587
/**
45884588
* Gets the ModifierFlags for syntactic modifiers on the provided node. The modifiers will be cached on the node to improve performance.
45894589
*

src/compiler/utilitiesPublic.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,11 @@ namespace ts {
302302
return getCombinedFlags(node, getEffectiveModifierFlags);
303303
}
304304

305+
/* @internal */
306+
export function getCombinedNodeFlagsAlwaysIncludeJSDoc(node: Declaration): ModifierFlags {
307+
return getCombinedFlags(node, getEffectiveModifierFlagsAlwaysIncludeJSDoc);
308+
}
309+
305310
// Returns the node flags for this node and all relevant parent nodes. This is done so that
306311
// nodes like variable declarations and binding elements can returned a view of their flags
307312
// that includes the modifiers from their container. i.e. flags like export/declare aren't

src/services/utilities.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1495,7 +1495,7 @@ namespace ts {
14951495
}
14961496

14971497
export function getNodeModifiers(node: Node): string {
1498-
const flags = isDeclaration(node) ? getCombinedModifierFlags(node) : ModifierFlags.None;
1498+
const flags = isDeclaration(node) ? getCombinedNodeFlagsAlwaysIncludeJSDoc(node) : ModifierFlags.None;
14991499
const result: string[] = [];
15001500

15011501
if (flags & ModifierFlags.Private) result.push(ScriptElementKindModifier.privateMemberModifier);

0 commit comments

Comments
 (0)