getSyntacticModifierFlags return value affected by getEffectiveModifierFlags #42189
Labels
Fix Available
A PR has been opened for this issue
Needs Investigation
This issue needs a team member to investigate its status.
Rescheduled
This issue was previously scheduled to an earlier milestone
Milestone
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
The code snippets below assume that
node: ts.PropertyDeclaration
of propertyprop
🙁 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:
ts.getSyntacticModifierFlags(node)
, returnts.ModifierFlags.None
(expected)ts.getEffectiveModifierFlags(node)
, returnts.ModifierFlags.None
(expected)ts.getSyntacticModifierFlags(node)
again, returnsts.ModifierFlags.None
(expected)If the above code is a JS file:
ts.getSyntacticModifierFlags(node)
, returnts.ModifierFlags.None
(expected)ts.getEffectiveModifierFlags(node)
, returnts.ModifierFlags.Private
(expected)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. CallinggetSyntacticModifierFlags
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". CallinggetEffectiveModifierFlags
should not have a side-effect ongetSyntacticModifierFlags
.Also there's
getEffectiveModifierFlagsAlwaysIncludeJSDoc
introduced in #38523 by @Kingwl. This affects TS files, making the original change in #38403 useless depending on execution order:ts.getSyntacticModifierFlags(node)
, returnts.ModifierFlags.None
(expected)ts.getEffectiveModifierFlags(node)
, returnts.ModifierFlags.None
(expected)getEffectiveModifierFlagsAlwaysIncludeJSDoc
, returnts.ModifierFlags.Private
(expected)ts.getSyntacticModifierFlags(node)
again, returnsts.ModifierFlags.Private
(not expected)ts.getEffectiveModifierFlags(node)
again, returnsts.ModifierFlags.Private
(not expected)The text was updated successfully, but these errors were encountered: