Fixes #605
This commit is contained in:
Sheetal Nandi 2018-04-24 13:41:17 -07:00
Родитель 9cb5c7c858
Коммит ee1eb6f2d9
5 изменённых файлов: 295 добавлений и 139 удалений

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

@ -527,9 +527,34 @@ repository:
method-declaration:
patterns:
# constructor signature
- name: meta.method.declaration.ts
begin: '(?x){{startOfIdentifier}}(?:\b(public|private|protected)\s+)?(?:\b(abstract)\s+)?(?:\b(async)\s+)?\b(constructor)\b(?!:){{endOfIdentifier}}'
beginCaptures:
'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.ts } # captures keyword (constructor)
end: (?=\}|;|,|$)|(?<=\})
patterns:
- include: '#method-declaration-name'
- include: '#function-body'
# new or call signature
- name: meta.method.declaration.ts
begin: '(?x){{startOfIdentifier}}(?:\b(public|private|protected)\s+)?(?:\b(abstract)\s+)?(?:\b(async)\s+)?(?:(?:\b(new)\b(?!:){{endOfIdentifier}})|(?:(\*)\s*)?)(?=\s*[\(\<])'
beginCaptures:
'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: keyword.operator.new.ts } # captures keyword (new)
'5': { name: keyword.generator.asterisk.ts } # captures keyword (*)
end: (?=\}|;|,|$)|(?<=\})
patterns:
- include: '#method-declaration-name'
- include: '#function-body'
# method, accessor
- name: meta.method.declaration.ts
begin: '(?x){{startOfIdentifier}}(?:\b(public|private|protected)\s+)?(?:\b(abstract)\s+)?(?:\b(async)\s+)?(?:\b(get|set)\s+)(?:(\*)\s*)?(?=({{propertyName}}\s*(\??))\s*[\(\<])'
begin: '(?x){{startOfIdentifier}}(?:\b(public|private|protected)\s+)?(?:\b(abstract)\s+)?(?:\b(async)\s+)?(?:\b(get|set)\s+)?(?:(\*)\s*)?(?=({{propertyName}}\s*(\??))\s*[\(\<])'
beginCaptures:
'1': { name: storage.modifier.ts } # captures keyword (public or private or protected)
'2': { name: storage.modifier.ts } # captures keyword (abstract)
@ -540,20 +565,6 @@ repository:
patterns:
- include: '#method-declaration-name'
- include: '#function-body'
# new, constructor or call signature
- name: meta.method.declaration.ts
begin: '(?x){{startOfIdentifier}}(?:\b(public|private|protected)\s+)?(?:\b(abstract)\s+)?(?:\b(async)\s+)?(?:(?:\b(?:(new)|(constructor))\b(?!:){{endOfIdentifier}})|(?:(\*)\s*)?(?=({{propertyName}}\s*(\??))?\s*[\(\<]))'
beginCaptures:
'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: keyword.operator.new.ts } # captures keyword (new)
'5': { name: storage.type.ts } # captures keyword (constructor)
'6': { name: keyword.generator.asterisk.ts } # captures keyword (*)
end: (?=\}|;|,|$)|(?<=\})
patterns:
- include: '#method-declaration-name'
- include: '#function-body'
object-literal-method-declaration:
name: meta.method.declaration.ts

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

@ -1606,7 +1606,96 @@
<key>name</key>
<string>meta.method.declaration.ts</string>
<key>begin</key>
<string>(?x)(?&lt;![_$[:alnum:]])(?:(?&lt;=\.\.\.)|(?&lt;!\.))(?:\b(public|private|protected)\s+)?(?:\b(abstract)\s+)?(?:\b(async)\s+)?(?:\b(get|set)\s+)(?:(\*)\s*)?(?=(((\b(?&lt;!\$)0(x|X)[0-9a-fA-F][0-9a-fA-F_]*\b(?!\$))|(\b(?&lt;!\$)0(b|B)[01][01_]*\b(?!\$))|(\b(?&lt;!\$)0(o|O)?[0-7][0-7_]*\b(?!\$))|((?&lt;!\$)(?:
<string>(?x)(?&lt;![_$[:alnum:]])(?:(?&lt;=\.\.\.)|(?&lt;!\.))(?:\b(public|private|protected)\s+)?(?:\b(abstract)\s+)?(?:\b(async)\s+)?\b(constructor)\b(?!:)(?![_$[:alnum:]])(?:(?=\.\.\.)|(?!\.))</string>
<key>beginCaptures</key>
<dict>
<key>1</key>
<dict>
<key>name</key>
<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>storage.modifier.async.ts</string>
</dict>
<key>4</key>
<dict>
<key>name</key>
<string>storage.type.ts</string>
</dict>
</dict>
<key>end</key>
<string>(?=\}|;|,|$)|(?&lt;=\})</string>
<key>patterns</key>
<array>
<dict>
<key>include</key>
<string>#method-declaration-name</string>
</dict>
<dict>
<key>include</key>
<string>#function-body</string>
</dict>
</array>
</dict>
<dict>
<key>name</key>
<string>meta.method.declaration.ts</string>
<key>begin</key>
<string>(?x)(?&lt;![_$[:alnum:]])(?:(?&lt;=\.\.\.)|(?&lt;!\.))(?:\b(public|private|protected)\s+)?(?:\b(abstract)\s+)?(?:\b(async)\s+)?(?:(?:\b(new)\b(?!:)(?![_$[:alnum:]])(?:(?=\.\.\.)|(?!\.)))|(?:(\*)\s*)?)(?=\s*[\(\&lt;])</string>
<key>beginCaptures</key>
<dict>
<key>1</key>
<dict>
<key>name</key>
<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>storage.modifier.async.ts</string>
</dict>
<key>4</key>
<dict>
<key>name</key>
<string>keyword.operator.new.ts</string>
</dict>
<key>5</key>
<dict>
<key>name</key>
<string>keyword.generator.asterisk.ts</string>
</dict>
</dict>
<key>end</key>
<string>(?=\}|;|,|$)|(?&lt;=\})</string>
<key>patterns</key>
<array>
<dict>
<key>include</key>
<string>#method-declaration-name</string>
</dict>
<dict>
<key>include</key>
<string>#function-body</string>
</dict>
</array>
</dict>
<dict>
<key>name</key>
<string>meta.method.declaration.ts</string>
<key>begin</key>
<string>(?x)(?&lt;![_$[:alnum:]])(?:(?&lt;=\.\.\.)|(?&lt;!\.))(?:\b(public|private|protected)\s+)?(?:\b(abstract)\s+)?(?:\b(async)\s+)?(?:\b(get|set)\s+)?(?:(\*)\s*)?(?=(((\b(?&lt;!\$)0(x|X)[0-9a-fA-F][0-9a-fA-F_]*\b(?!\$))|(\b(?&lt;!\$)0(b|B)[01][01_]*\b(?!\$))|(\b(?&lt;!\$)0(o|O)?[0-7][0-7_]*\b(?!\$))|((?&lt;!\$)(?:
(?:\b[0-9][0-9_]*(\.)[0-9][0-9_]*[eE][+-]?[0-9][0-9_]*\b)| # 1.1E+3
(?:\b[0-9][0-9_]*(\.)[eE][+-]?[0-9][0-9_]*\b)| # 1.E+3
(?:\B(\.)[0-9][0-9_]*[eE][+-]?[0-9][0-9_]*\b)| # .1E+3
@ -1658,67 +1747,6 @@
</dict>
</array>
</dict>
<dict>
<key>name</key>
<string>meta.method.declaration.ts</string>
<key>begin</key>
<string>(?x)(?&lt;![_$[:alnum:]])(?:(?&lt;=\.\.\.)|(?&lt;!\.))(?:\b(public|private|protected)\s+)?(?:\b(abstract)\s+)?(?:\b(async)\s+)?(?:(?:\b(?:(new)|(constructor))\b(?!:)(?![_$[:alnum:]])(?:(?=\.\.\.)|(?!\.)))|(?:(\*)\s*)?(?=(((\b(?&lt;!\$)0(x|X)[0-9a-fA-F][0-9a-fA-F_]*\b(?!\$))|(\b(?&lt;!\$)0(b|B)[01][01_]*\b(?!\$))|(\b(?&lt;!\$)0(o|O)?[0-7][0-7_]*\b(?!\$))|((?&lt;!\$)(?:
(?:\b[0-9][0-9_]*(\.)[0-9][0-9_]*[eE][+-]?[0-9][0-9_]*\b)| # 1.1E+3
(?:\b[0-9][0-9_]*(\.)[eE][+-]?[0-9][0-9_]*\b)| # 1.E+3
(?:\B(\.)[0-9][0-9_]*[eE][+-]?[0-9][0-9_]*\b)| # .1E+3
(?:\b[0-9][0-9_]*[eE][+-]?[0-9][0-9_]*\b)| # 1E+3
(?:\b[0-9][0-9_]*(\.)[0-9][0-9_]*\b)| # 1.1
(?:\b[0-9][0-9_]*(\.)\B)| # 1.
(?:\B(\.)[0-9][0-9_]*\b)| # .1
(?:\b[0-9][0-9_]*\b(?!\.)) # 1
)(?!\$))|([_$[:alpha:]][_$[:alnum:]]*)|(\'([^\'\\]|\\\'|\\)*\')|(\"([^\"\\]|\\\"|\\)*\")|(\[([^\[\]]|\[[^\[\]]*\])+\]))\s*(\??))?\s*[\(\&lt;]))</string>
<key>beginCaptures</key>
<dict>
<key>1</key>
<dict>
<key>name</key>
<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>storage.modifier.async.ts</string>
</dict>
<key>4</key>
<dict>
<key>name</key>
<string>keyword.operator.new.ts</string>
</dict>
<key>5</key>
<dict>
<key>name</key>
<string>storage.type.ts</string>
</dict>
<key>6</key>
<dict>
<key>name</key>
<string>keyword.generator.asterisk.ts</string>
</dict>
</dict>
<key>end</key>
<string>(?=\}|;|,|$)|(?&lt;=\})</string>
<key>patterns</key>
<array>
<dict>
<key>include</key>
<string>#method-declaration-name</string>
</dict>
<dict>
<key>include</key>
<string>#function-body</string>
</dict>
</array>
</dict>
</array>
</dict>
<key>object-literal-method-declaration</key>

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

@ -1610,7 +1610,96 @@
<key>name</key>
<string>meta.method.declaration.tsx</string>
<key>begin</key>
<string>(?x)(?&lt;![_$[:alnum:]])(?:(?&lt;=\.\.\.)|(?&lt;!\.))(?:\b(public|private|protected)\s+)?(?:\b(abstract)\s+)?(?:\b(async)\s+)?(?:\b(get|set)\s+)(?:(\*)\s*)?(?=(((\b(?&lt;!\$)0(x|X)[0-9a-fA-F][0-9a-fA-F_]*\b(?!\$))|(\b(?&lt;!\$)0(b|B)[01][01_]*\b(?!\$))|(\b(?&lt;!\$)0(o|O)?[0-7][0-7_]*\b(?!\$))|((?&lt;!\$)(?:
<string>(?x)(?&lt;![_$[:alnum:]])(?:(?&lt;=\.\.\.)|(?&lt;!\.))(?:\b(public|private|protected)\s+)?(?:\b(abstract)\s+)?(?:\b(async)\s+)?\b(constructor)\b(?!:)(?![_$[:alnum:]])(?:(?=\.\.\.)|(?!\.))</string>
<key>beginCaptures</key>
<dict>
<key>1</key>
<dict>
<key>name</key>
<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>storage.modifier.async.tsx</string>
</dict>
<key>4</key>
<dict>
<key>name</key>
<string>storage.type.tsx</string>
</dict>
</dict>
<key>end</key>
<string>(?=\}|;|,|$)|(?&lt;=\})</string>
<key>patterns</key>
<array>
<dict>
<key>include</key>
<string>#method-declaration-name</string>
</dict>
<dict>
<key>include</key>
<string>#function-body</string>
</dict>
</array>
</dict>
<dict>
<key>name</key>
<string>meta.method.declaration.tsx</string>
<key>begin</key>
<string>(?x)(?&lt;![_$[:alnum:]])(?:(?&lt;=\.\.\.)|(?&lt;!\.))(?:\b(public|private|protected)\s+)?(?:\b(abstract)\s+)?(?:\b(async)\s+)?(?:(?:\b(new)\b(?!:)(?![_$[:alnum:]])(?:(?=\.\.\.)|(?!\.)))|(?:(\*)\s*)?)(?=\s*[\(\&lt;])</string>
<key>beginCaptures</key>
<dict>
<key>1</key>
<dict>
<key>name</key>
<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>storage.modifier.async.tsx</string>
</dict>
<key>4</key>
<dict>
<key>name</key>
<string>keyword.operator.new.tsx</string>
</dict>
<key>5</key>
<dict>
<key>name</key>
<string>keyword.generator.asterisk.tsx</string>
</dict>
</dict>
<key>end</key>
<string>(?=\}|;|,|$)|(?&lt;=\})</string>
<key>patterns</key>
<array>
<dict>
<key>include</key>
<string>#method-declaration-name</string>
</dict>
<dict>
<key>include</key>
<string>#function-body</string>
</dict>
</array>
</dict>
<dict>
<key>name</key>
<string>meta.method.declaration.tsx</string>
<key>begin</key>
<string>(?x)(?&lt;![_$[:alnum:]])(?:(?&lt;=\.\.\.)|(?&lt;!\.))(?:\b(public|private|protected)\s+)?(?:\b(abstract)\s+)?(?:\b(async)\s+)?(?:\b(get|set)\s+)?(?:(\*)\s*)?(?=(((\b(?&lt;!\$)0(x|X)[0-9a-fA-F][0-9a-fA-F_]*\b(?!\$))|(\b(?&lt;!\$)0(b|B)[01][01_]*\b(?!\$))|(\b(?&lt;!\$)0(o|O)?[0-7][0-7_]*\b(?!\$))|((?&lt;!\$)(?:
(?:\b[0-9][0-9_]*(\.)[0-9][0-9_]*[eE][+-]?[0-9][0-9_]*\b)| # 1.1E+3
(?:\b[0-9][0-9_]*(\.)[eE][+-]?[0-9][0-9_]*\b)| # 1.E+3
(?:\B(\.)[0-9][0-9_]*[eE][+-]?[0-9][0-9_]*\b)| # .1E+3
@ -1662,67 +1751,6 @@
</dict>
</array>
</dict>
<dict>
<key>name</key>
<string>meta.method.declaration.tsx</string>
<key>begin</key>
<string>(?x)(?&lt;![_$[:alnum:]])(?:(?&lt;=\.\.\.)|(?&lt;!\.))(?:\b(public|private|protected)\s+)?(?:\b(abstract)\s+)?(?:\b(async)\s+)?(?:(?:\b(?:(new)|(constructor))\b(?!:)(?![_$[:alnum:]])(?:(?=\.\.\.)|(?!\.)))|(?:(\*)\s*)?(?=(((\b(?&lt;!\$)0(x|X)[0-9a-fA-F][0-9a-fA-F_]*\b(?!\$))|(\b(?&lt;!\$)0(b|B)[01][01_]*\b(?!\$))|(\b(?&lt;!\$)0(o|O)?[0-7][0-7_]*\b(?!\$))|((?&lt;!\$)(?:
(?:\b[0-9][0-9_]*(\.)[0-9][0-9_]*[eE][+-]?[0-9][0-9_]*\b)| # 1.1E+3
(?:\b[0-9][0-9_]*(\.)[eE][+-]?[0-9][0-9_]*\b)| # 1.E+3
(?:\B(\.)[0-9][0-9_]*[eE][+-]?[0-9][0-9_]*\b)| # .1E+3
(?:\b[0-9][0-9_]*[eE][+-]?[0-9][0-9_]*\b)| # 1E+3
(?:\b[0-9][0-9_]*(\.)[0-9][0-9_]*\b)| # 1.1
(?:\b[0-9][0-9_]*(\.)\B)| # 1.
(?:\B(\.)[0-9][0-9_]*\b)| # .1
(?:\b[0-9][0-9_]*\b(?!\.)) # 1
)(?!\$))|([_$[:alpha:]][_$[:alnum:]]*)|(\'([^\'\\]|\\\'|\\)*\')|(\"([^\"\\]|\\\"|\\)*\")|(\[([^\[\]]|\[[^\[\]]*\])+\]))\s*(\??))?\s*[\(\&lt;]))</string>
<key>beginCaptures</key>
<dict>
<key>1</key>
<dict>
<key>name</key>
<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>storage.modifier.async.tsx</string>
</dict>
<key>4</key>
<dict>
<key>name</key>
<string>keyword.operator.new.tsx</string>
</dict>
<key>5</key>
<dict>
<key>name</key>
<string>storage.type.tsx</string>
</dict>
<key>6</key>
<dict>
<key>name</key>
<string>keyword.generator.asterisk.tsx</string>
</dict>
</dict>
<key>end</key>
<string>(?=\}|;|,|$)|(?&lt;=\})</string>
<key>patterns</key>
<array>
<dict>
<key>include</key>
<string>#method-declaration-name</string>
</dict>
<dict>
<key>include</key>
<string>#function-body</string>
</dict>
</array>
</dict>
</array>
</dict>
<key>object-literal-method-declaration</key>

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

@ -0,0 +1,82 @@
original file
-----------------------------------
interface Foo {
new: number;
}
interface Foo2 {
new?: number;
}
-----------------------------------
Grammar: TypeScript.tmLanguage
-----------------------------------
>interface Foo {
^^^^^^^^^
source.ts meta.interface.ts storage.type.interface.ts
^
source.ts meta.interface.ts
^^^
source.ts meta.interface.ts entity.name.type.interface.ts
^
source.ts meta.interface.ts
^
source.ts meta.interface.ts punctuation.definition.block.ts
^^
source.ts meta.interface.ts
> new: number;
^^^^
source.ts meta.interface.ts
^^^
source.ts meta.interface.ts meta.field.declaration.ts meta.definition.property.ts variable.object.property.ts
^
source.ts meta.interface.ts meta.field.declaration.ts meta.type.annotation.ts keyword.operator.type.annotation.ts
^
source.ts meta.interface.ts meta.field.declaration.ts meta.type.annotation.ts
^^^^^^
source.ts meta.interface.ts meta.field.declaration.ts meta.type.annotation.ts support.type.primitive.ts
^
source.ts meta.interface.ts punctuation.terminator.statement.ts
^^
source.ts meta.interface.ts
>}
^
source.ts meta.interface.ts punctuation.definition.block.ts
^^
source.ts
>
^^
source.ts
>interface Foo2 {
^^^^^^^^^
source.ts meta.interface.ts storage.type.interface.ts
^
source.ts meta.interface.ts
^^^^
source.ts meta.interface.ts entity.name.type.interface.ts
^
source.ts meta.interface.ts
^
source.ts meta.interface.ts punctuation.definition.block.ts
^^
source.ts meta.interface.ts
> new?: number;
^^^^
source.ts meta.interface.ts
^^^
source.ts meta.interface.ts meta.field.declaration.ts meta.definition.property.ts variable.object.property.ts
^
source.ts meta.interface.ts meta.field.declaration.ts keyword.operator.optional.ts
^
source.ts meta.interface.ts meta.field.declaration.ts meta.type.annotation.ts keyword.operator.type.annotation.ts
^
source.ts meta.interface.ts meta.field.declaration.ts meta.type.annotation.ts
^^^^^^
source.ts meta.interface.ts meta.field.declaration.ts meta.type.annotation.ts support.type.primitive.ts
^
source.ts meta.interface.ts punctuation.terminator.statement.ts
^^
source.ts meta.interface.ts
>}
^
source.ts meta.interface.ts punctuation.definition.block.ts

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

@ -0,0 +1,7 @@
interface Foo {
new: number;
}
interface Foo2 {
new?: number;
}