Scope optional methods correctly

Fixes #581
This commit is contained in:
Sheetal Nandi 2018-03-14 11:16:27 -07:00
Родитель 874564b73c
Коммит b61fd56a52
5 изменённых файлов: 117 добавлений и 11 удалений

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

@ -425,11 +425,13 @@ repository:
- include: '#string'
- include: '#array-literal'
- include: '#comment'
- name: meta.definition.property.ts entity.name.function.ts
# function assignment |
# typeannotation is fn type: < | () | (... | (param: | (param, | (param? | (param= | (param) =>
match: |-
(?x)({{identifier}})(?=(\?\s*)?{{functionLikeAssignmentOrType}})
# function assignment |
# typeannotation is fn type: < | () | (... | (param: | (param, | (param? | (param= | (param) =>
- match: |-
(?x)({{identifier}})(\?)?(?=(\?\s*)?{{functionLikeAssignmentOrType}})
captures:
'1': { name: meta.definition.property.ts entity.name.function.ts }
'2': { name: keyword.operator.optional.ts }
- name: meta.definition.property.ts variable.object.property.ts
match: '{{identifier}}'
- name: keyword.operator.optional.ts

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

@ -1234,10 +1234,8 @@
<string>#comment</string>
</dict>
<dict>
<key>name</key>
<string>meta.definition.property.ts entity.name.function.ts</string>
<key>match</key>
<string>(?x)([_$[:alpha:]][_$[:alnum:]]*)(?=(\?\s*)?\s*
<string>(?x)([_$[:alpha:]][_$[:alnum:]]*)(\?)?(?=(\?\s*)?\s*
# function assignment |
(=\s*(
((async\s+)?(
@ -1305,6 +1303,19 @@
)
))
)))</string>
<key>captures</key>
<dict>
<key>1</key>
<dict>
<key>name</key>
<string>meta.definition.property.ts entity.name.function.ts</string>
</dict>
<key>2</key>
<dict>
<key>name</key>
<string>keyword.operator.optional.ts</string>
</dict>
</dict>
</dict>
<dict>
<key>name</key>

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

@ -1238,10 +1238,8 @@
<string>#comment</string>
</dict>
<dict>
<key>name</key>
<string>meta.definition.property.tsx entity.name.function.tsx</string>
<key>match</key>
<string>(?x)([_$[:alpha:]][_$[:alnum:]]*)(?=(\?\s*)?\s*
<string>(?x)([_$[:alpha:]][_$[:alnum:]]*)(\?)?(?=(\?\s*)?\s*
# function assignment |
(=\s*(
((async\s+)?(
@ -1309,6 +1307,19 @@
)
))
)))</string>
<key>captures</key>
<dict>
<key>1</key>
<dict>
<key>name</key>
<string>meta.definition.property.tsx entity.name.function.tsx</string>
</dict>
<key>2</key>
<dict>
<key>name</key>
<string>keyword.operator.optional.tsx</string>
</dict>
</dict>
</dict>
<dict>
<key>name</key>

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

@ -0,0 +1,78 @@
original file
-----------------------------------
interface Foo {
a: () => void;
b?: () => void;
}
-----------------------------------
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
> a: () => void;
^^
source.ts meta.interface.ts
^
source.ts meta.interface.ts meta.field.declaration.ts meta.definition.property.ts entity.name.function.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 meta.type.function.ts meta.parameters.ts punctuation.definition.parameters.begin.ts
^
source.ts meta.interface.ts meta.field.declaration.ts meta.type.annotation.ts meta.type.function.ts meta.parameters.ts punctuation.definition.parameters.end.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 meta.type.function.return.ts storage.type.function.arrow.ts
^
source.ts meta.interface.ts meta.field.declaration.ts meta.type.annotation.ts meta.type.function.return.ts
^^^^
source.ts meta.interface.ts meta.field.declaration.ts meta.type.annotation.ts meta.type.function.return.ts support.type.primitive.ts
^
source.ts meta.interface.ts punctuation.terminator.statement.ts
^^
source.ts meta.interface.ts
> b?: () => void;
^^
source.ts meta.interface.ts
^
source.ts meta.interface.ts meta.field.declaration.ts meta.definition.property.ts entity.name.function.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 meta.type.function.ts meta.parameters.ts punctuation.definition.parameters.begin.ts
^
source.ts meta.interface.ts meta.field.declaration.ts meta.type.annotation.ts meta.type.function.ts meta.parameters.ts punctuation.definition.parameters.end.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 meta.type.function.return.ts storage.type.function.arrow.ts
^
source.ts meta.interface.ts meta.field.declaration.ts meta.type.annotation.ts meta.type.function.return.ts
^^^^
source.ts meta.interface.ts meta.field.declaration.ts meta.type.annotation.ts meta.type.function.return.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

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

@ -0,0 +1,4 @@
interface Foo {
a: () => void;
b?: () => void;
}