Fix the modifier detection for fields and parameters

Fixes #305 and #306
This commit is contained in:
Sheetal Nandi 2016-10-11 12:30:14 -07:00
Родитель ca8743609f
Коммит 072bd267fe
5 изменённых файлов: 151 добавлений и 45 удалений

Просмотреть файл

@ -442,7 +442,6 @@ repository:
- include: '#type-annotation'
- include: '#variable-initializer'
- include: '#access-modifier'
- include: '#static-modifier'
- include: '#property-accessor'
- include: '#expression'
- include: '#punctuation-comma'
@ -515,10 +514,10 @@ repository:
method-overload-declaration:
name: meta.method.overload.declaration.ts
begin: (?<!\.|\$)(?:\b(abstract)\s+)?(?:\b(public|private|protected)\s+)?(?:\b(async)\s+)?(?:\b(get|set)\s+)?(?:(?:\b(?:(new)|(constructor))\b(?!\$|:))|(?:(\*)\s*)?(?=((([_$[:alpha:]][_$[:alnum:]]*)|(\'[^']*\')|(\"[^"]*\")|(\[[^\]]*\]))\s*(\??))?\s*[\(\<]))
begin: (?<!\.|\$)(?:\b(public|private|protected)\s+)?(?:\b(abstract)\s+)?(?:\b(async)\s+)?(?:\b(get|set)\s+)?(?:(?:\b(?:(new)|(constructor))\b(?!\$|:))|(?:(\*)\s*)?(?=((([_$[:alpha:]][_$[:alnum:]]*)|(\'[^']*\')|(\"[^"]*\")|(\[[^\]]*\]))\s*(\??))?\s*[\(\<]))
beginCaptures:
'1': { name: storage.modifier.ts } # captures keyword (abstract)
'2': { name: storage.modifier.ts } # captures keyword (public or private or protected)
'1': { name: storage.modifier.ts } # captures keyword (public or private or protected)
'2': { name: storage.modifier.ts } # captures keyword (abstract)
'3': { name: storage.modifier.async.ts } # captures keyword (async)
'4': { name: storage.type.property.ts } # captures keyword (get|set)
'5': { name: keyword.operator.new.ts } # captures keyword (new)
@ -621,12 +620,13 @@ repository:
- include: '#object-member'
parameter-name:
match: '(?:\s*\b(public|private|protected)\b\s+)?(\.\.\.)?\s*(?<!=|:)([_$[:alpha:]][_$[:alnum:]]*)\s*(\??)'
match: '(?:\s*\b(readonly)\s+)?(?:\s*\b(public|private|protected)\s+)?(\.\.\.)?\s*(?<!=|:)([_$[:alpha:]][_$[:alnum:]]*)\s*(\??)'
captures:
'1': { name: storage.modifier.ts }
'2': { name: keyword.operator.rest.ts }
'3': { name: variable.parameter.ts }
'4': { name: keyword.operator.optional.ts }
'2': { name: storage.modifier.ts }
'3': { name: keyword.operator.rest.ts }
'4': { name: variable.parameter.ts }
'5': { name: keyword.operator.optional.ts }
destructuring-parameter:
patterns:
@ -1713,11 +1713,7 @@ repository:
access-modifier:
name: storage.modifier.ts
match: (?<!\.|\$)\b(public|protected|private|readonly)\b(?!\$)
static-modifier:
name: storage.modifier.ts
match: (?<!\.|\$)\b(static)\b(?!\$)
match: (?<!\.|\$)\b(abstract|public|protected|private|readonly|static)\b(?!\$)
property-accessor:
name: storage.type.property.ts

Просмотреть файл

@ -1455,10 +1455,6 @@
<key>include</key>
<string>#access-modifier</string>
</dict>
<dict>
<key>include</key>
<string>#static-modifier</string>
</dict>
<dict>
<key>include</key>
<string>#property-accessor</string>
@ -1702,7 +1698,7 @@
<key>name</key>
<string>meta.method.overload.declaration.ts</string>
<key>begin</key>
<string>(?&lt;!\.|\$)(?:\b(abstract)\s+)?(?:\b(public|private|protected)\s+)?(?:\b(async)\s+)?(?:\b(get|set)\s+)?(?:(?:\b(?:(new)|(constructor))\b(?!\$|:))|(?:(\*)\s*)?(?=((([_$[:alpha:]][_$[:alnum:]]*)|(\'[^']*\')|(\"[^"]*\")|(\[[^\]]*\]))\s*(\??))?\s*[\(\&lt;]))</string>
<string>(?&lt;!\.|\$)(?:\b(public|private|protected)\s+)?(?:\b(abstract)\s+)?(?:\b(async)\s+)?(?:\b(get|set)\s+)?(?:(?:\b(?:(new)|(constructor))\b(?!\$|:))|(?:(\*)\s*)?(?=((([_$[:alpha:]][_$[:alnum:]]*)|(\'[^']*\')|(\"[^"]*\")|(\[[^\]]*\]))\s*(\??))?\s*[\(\&lt;]))</string>
<key>beginCaptures</key>
<dict>
<key>1</key>
@ -2040,7 +2036,7 @@
<key>parameter-name</key>
<dict>
<key>match</key>
<string>(?:\s*\b(public|private|protected)\b\s+)?(\.\.\.)?\s*(?&lt;!=|:)([_$[:alpha:]][_$[:alnum:]]*)\s*(\??)</string>
<string>(?:\s*\b(readonly)\s+)?(?:\s*\b(public|private|protected)\s+)?(\.\.\.)?\s*(?&lt;!=|:)([_$[:alpha:]][_$[:alnum:]]*)\s*(\??)</string>
<key>captures</key>
<dict>
<key>1</key>
@ -2051,14 +2047,19 @@
<key>2</key>
<dict>
<key>name</key>
<string>keyword.operator.rest.ts</string>
<string>storage.modifier.ts</string>
</dict>
<key>3</key>
<dict>
<key>name</key>
<string>variable.parameter.ts</string>
<string>keyword.operator.rest.ts</string>
</dict>
<key>4</key>
<dict>
<key>name</key>
<string>variable.parameter.ts</string>
</dict>
<key>5</key>
<dict>
<key>name</key>
<string>keyword.operator.optional.ts</string>
@ -4852,14 +4853,7 @@
<key>name</key>
<string>storage.modifier.ts</string>
<key>match</key>
<string>(?&lt;!\.|\$)\b(public|protected|private|readonly)\b(?!\$)</string>
</dict>
<key>static-modifier</key>
<dict>
<key>name</key>
<string>storage.modifier.ts</string>
<key>match</key>
<string>(?&lt;!\.|\$)\b(static)\b(?!\$)</string>
<string>(?&lt;!\.|\$)\b(abstract|public|protected|private|readonly|static)\b(?!\$)</string>
</dict>
<key>property-accessor</key>
<dict>

Просмотреть файл

@ -1459,10 +1459,6 @@
<key>include</key>
<string>#access-modifier</string>
</dict>
<dict>
<key>include</key>
<string>#static-modifier</string>
</dict>
<dict>
<key>include</key>
<string>#property-accessor</string>
@ -1706,7 +1702,7 @@
<key>name</key>
<string>meta.method.overload.declaration.tsx</string>
<key>begin</key>
<string>(?&lt;!\.|\$)(?:\b(abstract)\s+)?(?:\b(public|private|protected)\s+)?(?:\b(async)\s+)?(?:\b(get|set)\s+)?(?:(?:\b(?:(new)|(constructor))\b(?!\$|:))|(?:(\*)\s*)?(?=((([_$[:alpha:]][_$[:alnum:]]*)|(\'[^']*\')|(\"[^"]*\")|(\[[^\]]*\]))\s*(\??))?\s*[\(\&lt;]))</string>
<string>(?&lt;!\.|\$)(?:\b(public|private|protected)\s+)?(?:\b(abstract)\s+)?(?:\b(async)\s+)?(?:\b(get|set)\s+)?(?:(?:\b(?:(new)|(constructor))\b(?!\$|:))|(?:(\*)\s*)?(?=((([_$[:alpha:]][_$[:alnum:]]*)|(\'[^']*\')|(\"[^"]*\")|(\[[^\]]*\]))\s*(\??))?\s*[\(\&lt;]))</string>
<key>beginCaptures</key>
<dict>
<key>1</key>
@ -2044,7 +2040,7 @@
<key>parameter-name</key>
<dict>
<key>match</key>
<string>(?:\s*\b(public|private|protected)\b\s+)?(\.\.\.)?\s*(?&lt;!=|:)([_$[:alpha:]][_$[:alnum:]]*)\s*(\??)</string>
<string>(?:\s*\b(readonly)\s+)?(?:\s*\b(public|private|protected)\s+)?(\.\.\.)?\s*(?&lt;!=|:)([_$[:alpha:]][_$[:alnum:]]*)\s*(\??)</string>
<key>captures</key>
<dict>
<key>1</key>
@ -2055,14 +2051,19 @@
<key>2</key>
<dict>
<key>name</key>
<string>keyword.operator.rest.tsx</string>
<string>storage.modifier.tsx</string>
</dict>
<key>3</key>
<dict>
<key>name</key>
<string>variable.parameter.tsx</string>
<string>keyword.operator.rest.tsx</string>
</dict>
<key>4</key>
<dict>
<key>name</key>
<string>variable.parameter.tsx</string>
</dict>
<key>5</key>
<dict>
<key>name</key>
<string>keyword.operator.optional.tsx</string>
@ -4834,14 +4835,7 @@
<key>name</key>
<string>storage.modifier.tsx</string>
<key>match</key>
<string>(?&lt;!\.|\$)\b(public|protected|private|readonly)\b(?!\$)</string>
</dict>
<key>static-modifier</key>
<dict>
<key>name</key>
<string>storage.modifier.tsx</string>
<key>match</key>
<string>(?&lt;!\.|\$)\b(static)\b(?!\$)</string>
<string>(?&lt;!\.|\$)\b(abstract|public|protected|private|readonly|static)\b(?!\$)</string>
</dict>
<key>property-accessor</key>
<dict>

Просмотреть файл

@ -0,0 +1,118 @@
original file
-----------------------------------
abstract class Base {
protected abstract topic: string
constructor(protected wire: Transport, protected token?: string, readonly bar?: boolean) { }
}
-----------------------------------
Grammar: TypeScript.tmLanguage
-----------------------------------
>abstract class Base {
^^^^^^^^
source.ts meta.class.ts storage.modifier.ts
^
source.ts meta.class.ts
^^^^^
source.ts meta.class.ts storage.type.class.ts
^
source.ts meta.class.ts
^^^^
source.ts meta.class.ts entity.name.class.ts
^
source.ts meta.class.ts
^
source.ts meta.class.ts punctuation.definition.block.ts
^^
source.ts meta.class.ts
> protected abstract topic: string
^^^^
source.ts meta.class.ts
^^^^^^^^^
source.ts meta.class.ts storage.modifier.ts
^
source.ts meta.class.ts
^^^^^^^^
source.ts meta.class.ts storage.modifier.ts
^
source.ts meta.class.ts meta.field.declaration.ts
^^^^^
source.ts meta.class.ts meta.field.declaration.ts variable.object.property.ts
^
source.ts meta.class.ts meta.field.declaration.ts meta.type.annotation.ts keyword.operator.type.annotation.ts
^
source.ts meta.class.ts meta.field.declaration.ts meta.type.annotation.ts
^^^^^^
source.ts meta.class.ts meta.field.declaration.ts meta.type.annotation.ts support.type.primitive.ts
^
source.ts meta.class.ts meta.field.declaration.ts meta.type.annotation.ts
> constructor(protected wire: Transport, protected token?: string, readonly bar?: boolean) { }
^^^^
source.ts meta.class.ts
^^^^^^^^^^^
source.ts meta.class.ts meta.method.declaration.ts storage.type.ts
^
source.ts meta.class.ts meta.method.declaration.ts meta.parameters.ts punctuation.definition.parameters.begin.ts
^^^^^^^^^
source.ts meta.class.ts meta.method.declaration.ts meta.parameters.ts storage.modifier.ts
^
source.ts meta.class.ts meta.method.declaration.ts meta.parameters.ts
^^^^
source.ts meta.class.ts meta.method.declaration.ts meta.parameters.ts variable.parameter.ts
^
source.ts meta.class.ts meta.method.declaration.ts meta.parameters.ts meta.type.annotation.ts keyword.operator.type.annotation.ts
^
source.ts meta.class.ts meta.method.declaration.ts meta.parameters.ts meta.type.annotation.ts
^^^^^^^^^
source.ts meta.class.ts meta.method.declaration.ts meta.parameters.ts meta.type.annotation.ts entity.name.type.ts
^
source.ts meta.class.ts meta.method.declaration.ts meta.parameters.ts punctuation.separator.parameter.ts
^
source.ts meta.class.ts meta.method.declaration.ts meta.parameters.ts
^^^^^^^^^
source.ts meta.class.ts meta.method.declaration.ts meta.parameters.ts storage.modifier.ts
^
source.ts meta.class.ts meta.method.declaration.ts meta.parameters.ts
^^^^^
source.ts meta.class.ts meta.method.declaration.ts meta.parameters.ts variable.parameter.ts
^
source.ts meta.class.ts meta.method.declaration.ts meta.parameters.ts keyword.operator.optional.ts
^
source.ts meta.class.ts meta.method.declaration.ts meta.parameters.ts meta.type.annotation.ts keyword.operator.type.annotation.ts
^
source.ts meta.class.ts meta.method.declaration.ts meta.parameters.ts meta.type.annotation.ts
^^^^^^
source.ts meta.class.ts meta.method.declaration.ts meta.parameters.ts meta.type.annotation.ts support.type.primitive.ts
^
source.ts meta.class.ts meta.method.declaration.ts meta.parameters.ts punctuation.separator.parameter.ts
^
source.ts meta.class.ts meta.method.declaration.ts meta.parameters.ts
^^^^^^^^
source.ts meta.class.ts meta.method.declaration.ts meta.parameters.ts storage.modifier.ts
^
source.ts meta.class.ts meta.method.declaration.ts meta.parameters.ts
^^^
source.ts meta.class.ts meta.method.declaration.ts meta.parameters.ts variable.parameter.ts
^
source.ts meta.class.ts meta.method.declaration.ts meta.parameters.ts keyword.operator.optional.ts
^
source.ts meta.class.ts meta.method.declaration.ts meta.parameters.ts meta.type.annotation.ts keyword.operator.type.annotation.ts
^
source.ts meta.class.ts meta.method.declaration.ts meta.parameters.ts meta.type.annotation.ts
^^^^^^^
source.ts meta.class.ts meta.method.declaration.ts meta.parameters.ts meta.type.annotation.ts support.type.primitive.ts
^
source.ts meta.class.ts meta.method.declaration.ts meta.parameters.ts punctuation.definition.parameters.end.ts
^
source.ts meta.class.ts meta.method.declaration.ts
^
source.ts meta.class.ts meta.method.declaration.ts meta.block.ts punctuation.definition.block.ts
^
source.ts meta.class.ts meta.method.declaration.ts meta.block.ts
^
source.ts meta.class.ts meta.method.declaration.ts meta.block.ts punctuation.definition.block.ts
^^
source.ts meta.class.ts
>}
^
source.ts meta.class.ts punctuation.definition.block.ts

4
tests/cases/Issue305.ts Normal file
Просмотреть файл

@ -0,0 +1,4 @@
abstract class Base {
protected abstract topic: string
constructor(protected wire: Transport, protected token?: string, readonly bar?: boolean) { }
}