Skip to content

getSyntacticModifierFlags return value affected by getEffectiveModifierFlags#42189

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 Ron Buckton (@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), return ts.ModifierFlags.None (expected)
  • call ts.getEffectiveModifierFlags(node), return ts.ModifierFlags.None (expected)
  • call ts.getSyntacticModifierFlags(node) again, returns ts.ModifierFlags.None (expected)

If the above code is a JS file:

  • call ts.getSyntacticModifierFlags(node), return ts.ModifierFlags.None (expected)
  • call ts.getEffectiveModifierFlags(node), return ts.ModifierFlags.Private (expected)
  • call ts.getSyntacticModifierFlags(node) again, returns ts.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 Wenlu Wang (@Kingwl). This affects TS files, making the original change in #38403 useless depending on execution order:

  • call ts.getSyntacticModifierFlags(node), return ts.ModifierFlags.None (expected)
  • call ts.getEffectiveModifierFlags(node), return ts.ModifierFlags.None (expected)
  • call getEffectiveModifierFlagsAlwaysIncludeJSDoc, return ts.ModifierFlags.Private (expected)
  • call ts.getSyntacticModifierFlags(node) again, returns ts.ModifierFlags.Private (not expected)
  • call ts.getEffectiveModifierFlags(node) again, returns ts.ModifierFlags.Private (not expected)

Metadata

Metadata

Labels

Fix AvailableA PR has been opened for this issueNeeds InvestigationThis issue needs a team member to investigate its status.RescheduledThis issue was previously scheduled to an earlier milestone

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions