MCPcopy Index your code
hub / github.com/microsoft/typescript-go / parseModifiersEx

Method parseModifiersEx

internal/parser/parser.go:3865–3903  ·  view source on GitHub ↗
(allowDecorators bool, permitConstAsModifier bool, stopOnStartOfClassStaticBlock bool)

Source from the content-addressed store, hash-verified

3863}
3864
3865func (p *Parser) parseModifiersEx(allowDecorators bool, permitConstAsModifier bool, stopOnStartOfClassStaticBlock bool) *ast.ModifierList {
3866 var hasLeadingModifier bool
3867 var hasTrailingDecorator bool
3868 var hasTrailingModifier bool
3869 var hasStaticModifier bool
3870 // Decorators should be contiguous in a list of modifiers but can potentially appear in two places (i.e., `[...leadingDecorators, ...leadingModifiers, ...trailingDecorators, ...trailingModifiers]`).
3871 // The leading modifiers *should* only contain `export` and `default` when trailingDecorators are present, but we'll handle errors for any other leading modifiers in the checker.
3872 // It is illegal to have both leadingDecorators and trailingDecorators, but we will report that as a grammar check in the checker.
3873 // parse leading decorators
3874 pos := p.nodePos()
3875 list := make([]*ast.Node, 0, 16)
3876 for {
3877 if allowDecorators && p.token == ast.KindAtToken && !hasTrailingModifier {
3878 decorator := p.parseDecorator()
3879 list = append(list, decorator)
3880 if hasLeadingModifier {
3881 hasTrailingDecorator = true
3882 }
3883 } else {
3884 modifier := p.tryParseModifier(hasStaticModifier, permitConstAsModifier, stopOnStartOfClassStaticBlock)
3885 if modifier == nil {
3886 break
3887 }
3888 if modifier.Kind == ast.KindStaticKeyword {
3889 hasStaticModifier = true
3890 }
3891 list = append(list, modifier)
3892 if hasTrailingDecorator {
3893 hasTrailingModifier = true
3894 } else {
3895 hasLeadingModifier = true
3896 }
3897 }
3898 }
3899 if len(list) != 0 {
3900 return p.newModifierList(core.NewTextRange(pos, p.nodePos()), p.nodeSliceArena.Clone(list))
3901 }
3902 return nil
3903}
3904
3905func (p *Parser) parseDecorator() *ast.Node {
3906 pos := p.nodePos()

Callers 8

parseDeclarationMethod · 0.95
parseClassElementMethod · 0.95
parseTypeParameterMethod · 0.95
parseParameterExMethod · 0.95
parseModifiersMethod · 0.95

Calls 9

nodePosMethod · 0.95
parseDecoratorMethod · 0.95
tryParseModifierMethod · 0.95
newModifierListMethod · 0.95
NewTextRangeFunction · 0.92
lenFunction · 0.85
CloneMethod · 0.65
makeFunction · 0.50
appendFunction · 0.50

Tested by

no test coverage detected