Skip to content

Commit

Permalink
Match multiple modifiers in the parameter name
Browse files Browse the repository at this point in the history
Fixes #365
  • Loading branch information
sheetalkamat committed Nov 21, 2016
1 parent 6fe1b65 commit e6ba96f
Show file tree
Hide file tree
Showing 5 changed files with 154 additions and 42 deletions.
21 changes: 11 additions & 10 deletions TypeScript.YAML-tmLanguage
Original file line number Diff line number Diff line change
Expand Up @@ -728,10 +728,13 @@ repository:

parameter-name:
patterns:
- match: \s*\b(public|protected|private|readonly)(?=\s+(public|protected|private|readonly)\s+)
captures:
'1': { name: storage.modifier.ts }
# function assignment |
# typeannotation is fn type: < | () | (... | (param: | (param, | (param? | (param= | (param) =>
- match: |-
(?x)(?:\s*\b(readonly)\s+)?(?:\s*\b(public|private|protected)\s+)?(\.\.\.)?\s*(?<!=|:)([_$[:alpha:]][_$[:alnum:]]*)\s*(\??)(?=\s*
(?x)(?:\s*\b(public|private|protected|readonly)\s+)?(\.\.\.)?\s*(?<!=|:)([_$[:alpha:]][_$[:alnum:]]*)\s*(\??)(?=\s*
(=\s*(
(async\s+) |
(function\s*[(<]) |
Expand All @@ -753,17 +756,15 @@ repository:
)
captures:
'1': { name: storage.modifier.ts }
'2': { name: storage.modifier.ts }
'3': { name: keyword.operator.rest.ts }
'4': { name: entity.name.function.ts }
'5': { name: keyword.operator.optional.ts }
- match: (?:\s*\b(readonly)\s+)?(?:\s*\b(public|private|protected)\s+)?(\.\.\.)?\s*(?<!=|:)([_$[:alpha:]][_$[:alnum:]]*)\s*(\??)
'2': { name: keyword.operator.rest.ts }
'3': { name: entity.name.function.ts }
'4': { name: keyword.operator.optional.ts }
- match: (?:\s*\b(public|private|protected|readonly)\s+)?(\.\.\.)?\s*(?<!=|:)([_$[:alpha:]][_$[:alnum:]]*)\s*(\??)
captures:
'1': { name: storage.modifier.ts }
'2': { name: storage.modifier.ts }
'3': { name: keyword.operator.rest.ts }
'4': { name: variable.parameter.ts }
'5': { name: keyword.operator.optional.ts }
'2': { name: keyword.operator.rest.ts }
'3': { name: variable.parameter.ts }
'4': { name: keyword.operator.optional.ts }

destructuring-parameter:
patterns:
Expand Down
34 changes: 18 additions & 16 deletions TypeScript.tmLanguage
Original file line number Diff line number Diff line change
Expand Up @@ -2290,7 +2290,19 @@
<array>
<dict>
<key>match</key>
<string>(?x)(?:\s*\b(readonly)\s+)?(?:\s*\b(public|private|protected)\s+)?(\.\.\.)?\s*(?&lt;!=|:)([_$[:alpha:]][_$[:alnum:]]*)\s*(\??)(?=\s*
<string>\s*\b(public|protected|private|readonly)(?=\s+(public|protected|private|readonly)\s+)</string>
<key>captures</key>
<dict>
<key>1</key>
<dict>
<key>name</key>
<string>storage.modifier.ts</string>
</dict>
</dict>
</dict>
<dict>
<key>match</key>
<string>(?x)(?:\s*\b(public|private|protected|readonly)\s+)?(\.\.\.)?\s*(?&lt;!=|:)([_$[:alpha:]][_$[:alnum:]]*)\s*(\??)(?=\s*
(=\s*(
(async\s+) |
(function\s*[(&lt;]) |
Expand Down Expand Up @@ -2318,21 +2330,16 @@
<string>storage.modifier.ts</string>
</dict>
<key>2</key>
<dict>
<key>name</key>
<string>storage.modifier.ts</string>
</dict>
<key>3</key>
<dict>
<key>name</key>
<string>keyword.operator.rest.ts</string>
</dict>
<key>4</key>
<key>3</key>
<dict>
<key>name</key>
<string>entity.name.function.ts</string>
</dict>
<key>5</key>
<key>4</key>
<dict>
<key>name</key>
<string>keyword.operator.optional.ts</string>
Expand All @@ -2341,7 +2348,7 @@
</dict>
<dict>
<key>match</key>
<string>(?:\s*\b(readonly)\s+)?(?:\s*\b(public|private|protected)\s+)?(\.\.\.)?\s*(?&lt;!=|:)([_$[:alpha:]][_$[:alnum:]]*)\s*(\??)</string>
<string>(?:\s*\b(public|private|protected|readonly)\s+)?(\.\.\.)?\s*(?&lt;!=|:)([_$[:alpha:]][_$[:alnum:]]*)\s*(\??)</string>
<key>captures</key>
<dict>
<key>1</key>
Expand All @@ -2350,21 +2357,16 @@
<string>storage.modifier.ts</string>
</dict>
<key>2</key>
<dict>
<key>name</key>
<string>storage.modifier.ts</string>
</dict>
<key>3</key>
<dict>
<key>name</key>
<string>keyword.operator.rest.ts</string>
</dict>
<key>4</key>
<key>3</key>
<dict>
<key>name</key>
<string>variable.parameter.ts</string>
</dict>
<key>5</key>
<key>4</key>
<dict>
<key>name</key>
<string>keyword.operator.optional.ts</string>
Expand Down
34 changes: 18 additions & 16 deletions TypeScriptReact.tmLanguage
Original file line number Diff line number Diff line change
Expand Up @@ -2294,7 +2294,19 @@
<array>
<dict>
<key>match</key>
<string>(?x)(?:\s*\b(readonly)\s+)?(?:\s*\b(public|private|protected)\s+)?(\.\.\.)?\s*(?&lt;!=|:)([_$[:alpha:]][_$[:alnum:]]*)\s*(\??)(?=\s*
<string>\s*\b(public|protected|private|readonly)(?=\s+(public|protected|private|readonly)\s+)</string>
<key>captures</key>
<dict>
<key>1</key>
<dict>
<key>name</key>
<string>storage.modifier.tsx</string>
</dict>
</dict>
</dict>
<dict>
<key>match</key>
<string>(?x)(?:\s*\b(public|private|protected|readonly)\s+)?(\.\.\.)?\s*(?&lt;!=|:)([_$[:alpha:]][_$[:alnum:]]*)\s*(\??)(?=\s*
(=\s*(
(async\s+) |
(function\s*[(&lt;]) |
Expand Down Expand Up @@ -2322,21 +2334,16 @@
<string>storage.modifier.tsx</string>
</dict>
<key>2</key>
<dict>
<key>name</key>
<string>storage.modifier.tsx</string>
</dict>
<key>3</key>
<dict>
<key>name</key>
<string>keyword.operator.rest.tsx</string>
</dict>
<key>4</key>
<key>3</key>
<dict>
<key>name</key>
<string>entity.name.function.tsx</string>
</dict>
<key>5</key>
<key>4</key>
<dict>
<key>name</key>
<string>keyword.operator.optional.tsx</string>
Expand All @@ -2345,7 +2352,7 @@
</dict>
<dict>
<key>match</key>
<string>(?:\s*\b(readonly)\s+)?(?:\s*\b(public|private|protected)\s+)?(\.\.\.)?\s*(?&lt;!=|:)([_$[:alpha:]][_$[:alnum:]]*)\s*(\??)</string>
<string>(?:\s*\b(public|private|protected|readonly)\s+)?(\.\.\.)?\s*(?&lt;!=|:)([_$[:alpha:]][_$[:alnum:]]*)\s*(\??)</string>
<key>captures</key>
<dict>
<key>1</key>
Expand All @@ -2354,21 +2361,16 @@
<string>storage.modifier.tsx</string>
</dict>
<key>2</key>
<dict>
<key>name</key>
<string>storage.modifier.tsx</string>
</dict>
<key>3</key>
<dict>
<key>name</key>
<string>keyword.operator.rest.tsx</string>
</dict>
<key>4</key>
<key>3</key>
<dict>
<key>name</key>
<string>variable.parameter.tsx</string>
</dict>
<key>5</key>
<key>4</key>
<dict>
<key>name</key>
<string>keyword.operator.optional.tsx</string>
Expand Down
104 changes: 104 additions & 0 deletions tests/baselines/Issue365.baseline.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
original file
-----------------------------------
class Renamer {
constructor (private readonly srcName: string, private readonly target: string, readonly copy: boolean = false) {}
}
-----------------------------------

Grammar: TypeScript.tmLanguage
-----------------------------------
>class Renamer {
^^^^^
source.ts meta.class.ts storage.type.class.ts
^
source.ts meta.class.ts
^^^^^^^
source.ts meta.class.ts entity.name.type.class.ts
^
source.ts meta.class.ts
^
source.ts meta.class.ts punctuation.definition.block.ts
^^
source.ts meta.class.ts
> constructor (private readonly srcName: string, private readonly target: string, readonly copy: boolean = false) {}
^^
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
^
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 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 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 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 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 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 meta.type.annotation.ts
^
source.ts meta.class.ts meta.method.declaration.ts meta.parameters.ts keyword.operator.assignment.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 constant.language.boolean.false.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 punctuation.definition.block.ts
^^
source.ts meta.class.ts
>}
^
source.ts meta.class.ts punctuation.definition.block.ts
3 changes: 3 additions & 0 deletions tests/cases/Issue365.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
class Renamer {
constructor (private readonly srcName: string, private readonly target: string, readonly copy: boolean = false) {}
}

0 comments on commit e6ba96f

Please sign in to comment.