Description
Bug Report
I don't know if this already causes a user-facing bug, but it might in the future.
🔎 Search Terms
syntactic effective modifierflags
🕗 Version & Regression Information
The API was introduced in #38403 by @rbuckton on 12th May 2020, I don't know which TS version that is
💻 Code
class C {
/** @private */
prop = 1;
}
The code snippets below assume that node: ts.PropertyDeclaration
of property prop
🙁 Actual behavior
Note: I'm not talking about user code using compiler API as these APIs are not public. I'm talking about the compiler implementation itself.
If the above code is a TS file:
- call
ts.getSyntacticModifierFlags(node)
, returnts.ModifierFlags.None
(expected) - call
ts.getEffectiveModifierFlags(node)
, returnts.ModifierFlags.None
(expected) - call
ts.getSyntacticModifierFlags(node)
again, returnsts.ModifierFlags.None
(expected)
If the above code is a JS file:
- call
ts.getSyntacticModifierFlags(node)
, returnts.ModifierFlags.None
(expected) - call
ts.getEffectiveModifierFlags(node)
, returnts.ModifierFlags.Private
(expected) - call
ts.getSyntacticModifierFlags(node)
again, returnsts.ModifierFlags.Private
(not expected)
(see https://runkit.com/ajafff/5ff204e2ac3559001a1407f7)
This is because both use the same property to cache the result. getEffectiveModifierFlags
adds modifiers from JSDoc to the cached result. Calling getSyntacticModifierFlags
afterwards cannot remove the modifiers from JSDoc, so it simply returns them too.
🙂 Expected behavior
Looking at the description of #38403, the intended use of getSyntacticModifierFlags
is: "get me the syntactic modifiers and don't include those from JSDoc". Calling getEffectiveModifierFlags
should not have a side-effect on getSyntacticModifierFlags
.
Also there's getEffectiveModifierFlagsAlwaysIncludeJSDoc
introduced in #38523 by @Kingwl. This affects TS files, making the original change in #38403 useless depending on execution order:
- call
ts.getSyntacticModifierFlags(node)
, returnts.ModifierFlags.None
(expected) - call
ts.getEffectiveModifierFlags(node)
, returnts.ModifierFlags.None
(expected) - call
getEffectiveModifierFlagsAlwaysIncludeJSDoc
, returnts.ModifierFlags.Private
(expected) - call
ts.getSyntacticModifierFlags(node)
again, returnsts.ModifierFlags.Private
(not expected) - call
ts.getEffectiveModifierFlags(node)
again, returnsts.ModifierFlags.Private
(not expected)