Fix incorrect constructor type's type parameter detection

Fixes #687
This commit is contained in:
Sheetal Nandi 2018-11-29 10:10:12 -08:00
Родитель 72cb5cd533
Коммит 7db029d755
5 изменённых файлов: 160 добавлений и 14 удалений

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

@ -2220,10 +2220,13 @@ repository:
type-fn-type-parameters:
patterns:
# constructor type
- name: meta.type.constructor.ts
match: '{{startOfIdentifier}}(new)\b(?=\s*\<)'
captures:
'1': { name: keyword.control.new.ts }
- begin: '{{startOfIdentifier}}(new)\b(?=\s*\<)'
beginCaptures:
'1': { name: meta.type.constructor.ts keyword.control.new.ts }
end: (?<=>)
patterns:
- include: '#comment'
- include: '#type-parameters'
- name: meta.type.constructor.ts
begin: '{{startOfIdentifier}}(new)\b\s*(?=\()'
beginCaptures:

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

@ -6628,18 +6628,29 @@
<key>patterns</key>
<array>
<dict>
<key>name</key>
<string>meta.type.constructor.ts</string>
<key>match</key>
<key>begin</key>
<string>(?&lt;![_$[:alnum:]])(?:(?&lt;=\.\.\.)|(?&lt;!\.))(new)\b(?=\s*\&lt;)</string>
<key>captures</key>
<key>beginCaptures</key>
<dict>
<key>1</key>
<dict>
<key>name</key>
<string>keyword.control.new.ts</string>
<string>meta.type.constructor.ts keyword.control.new.ts</string>
</dict>
</dict>
<key>end</key>
<string>(?&lt;=&gt;)</string>
<key>patterns</key>
<array>
<dict>
<key>include</key>
<string>#comment</string>
</dict>
<dict>
<key>include</key>
<string>#type-parameters</string>
</dict>
</array>
</dict>
<dict>
<key>name</key>

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

@ -6574,18 +6574,29 @@
<key>patterns</key>
<array>
<dict>
<key>name</key>
<string>meta.type.constructor.tsx</string>
<key>match</key>
<key>begin</key>
<string>(?&lt;![_$[:alnum:]])(?:(?&lt;=\.\.\.)|(?&lt;!\.))(new)\b(?=\s*\&lt;)</string>
<key>captures</key>
<key>beginCaptures</key>
<dict>
<key>1</key>
<dict>
<key>name</key>
<string>keyword.control.new.tsx</string>
<string>meta.type.constructor.tsx keyword.control.new.tsx</string>
</dict>
</dict>
<key>end</key>
<string>(?&lt;=&gt;)</string>
<key>patterns</key>
<array>
<dict>
<key>include</key>
<string>#comment</string>
</dict>
<dict>
<key>include</key>
<string>#type-parameters</string>
</dict>
</array>
</dict>
<dict>
<key>name</key>

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

@ -0,0 +1,118 @@
original file
-----------------------------------
export interface ObjectAllocator {
getTokenConstructor(): new <TKind extends SyntaxKind>(kind: TKind, pos?: number, end?: number) => Token<TKind>;
}
-----------------------------------
Grammar: TypeScript.tmLanguage
-----------------------------------
>export interface ObjectAllocator {
^^^^^^
source.ts meta.interface.ts keyword.control.export.ts
^
source.ts meta.interface.ts
^^^^^^^^^
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
> getTokenConstructor(): new <TKind extends SyntaxKind>(kind: TKind, pos?: number, end?: number) => Token<TKind>;
^^^^^^^^
source.ts meta.interface.ts meta.method.declaration.ts
^^^^^^^^^^^^^^^^^^^
source.ts meta.interface.ts meta.method.declaration.ts meta.definition.method.ts entity.name.function.ts
^
source.ts meta.interface.ts meta.method.declaration.ts meta.parameters.ts punctuation.definition.parameters.begin.ts
^
source.ts meta.interface.ts meta.method.declaration.ts meta.parameters.ts punctuation.definition.parameters.end.ts
^
source.ts meta.interface.ts meta.method.declaration.ts meta.return.type.ts keyword.operator.type.annotation.ts
^
source.ts meta.interface.ts meta.method.declaration.ts meta.return.type.ts
^^^
source.ts meta.interface.ts meta.method.declaration.ts meta.return.type.ts meta.type.constructor.ts keyword.control.new.ts
^
source.ts meta.interface.ts meta.method.declaration.ts meta.return.type.ts
^
source.ts meta.interface.ts meta.method.declaration.ts meta.return.type.ts meta.type.parameters.ts punctuation.definition.typeparameters.begin.ts
^^^^^
source.ts meta.interface.ts meta.method.declaration.ts meta.return.type.ts meta.type.parameters.ts entity.name.type.ts
^
source.ts meta.interface.ts meta.method.declaration.ts meta.return.type.ts meta.type.parameters.ts
^^^^^^^
source.ts meta.interface.ts meta.method.declaration.ts meta.return.type.ts meta.type.parameters.ts storage.modifier.ts
^
source.ts meta.interface.ts meta.method.declaration.ts meta.return.type.ts meta.type.parameters.ts
^^^^^^^^^^
source.ts meta.interface.ts meta.method.declaration.ts meta.return.type.ts meta.type.parameters.ts entity.name.type.ts
^
source.ts meta.interface.ts meta.method.declaration.ts meta.return.type.ts meta.type.parameters.ts punctuation.definition.typeparameters.end.ts
^
source.ts meta.interface.ts meta.method.declaration.ts meta.return.type.ts meta.type.function.ts meta.parameters.ts punctuation.definition.parameters.begin.ts
^^^^
source.ts meta.interface.ts meta.method.declaration.ts meta.return.type.ts meta.type.function.ts meta.parameters.ts variable.parameter.ts
^
source.ts meta.interface.ts meta.method.declaration.ts meta.return.type.ts meta.type.function.ts meta.parameters.ts meta.type.annotation.ts keyword.operator.type.annotation.ts
^
source.ts meta.interface.ts meta.method.declaration.ts meta.return.type.ts meta.type.function.ts meta.parameters.ts meta.type.annotation.ts
^^^^^
source.ts meta.interface.ts meta.method.declaration.ts meta.return.type.ts meta.type.function.ts meta.parameters.ts meta.type.annotation.ts entity.name.type.ts
^
source.ts meta.interface.ts meta.method.declaration.ts meta.return.type.ts meta.type.function.ts meta.parameters.ts punctuation.separator.parameter.ts
^
source.ts meta.interface.ts meta.method.declaration.ts meta.return.type.ts meta.type.function.ts meta.parameters.ts
^^^
source.ts meta.interface.ts meta.method.declaration.ts meta.return.type.ts meta.type.function.ts meta.parameters.ts variable.parameter.ts
^
source.ts meta.interface.ts meta.method.declaration.ts meta.return.type.ts meta.type.function.ts meta.parameters.ts keyword.operator.optional.ts
^
source.ts meta.interface.ts meta.method.declaration.ts meta.return.type.ts meta.type.function.ts meta.parameters.ts meta.type.annotation.ts keyword.operator.type.annotation.ts
^
source.ts meta.interface.ts meta.method.declaration.ts meta.return.type.ts meta.type.function.ts meta.parameters.ts meta.type.annotation.ts
^^^^^^
source.ts meta.interface.ts meta.method.declaration.ts meta.return.type.ts meta.type.function.ts meta.parameters.ts meta.type.annotation.ts support.type.primitive.ts
^
source.ts meta.interface.ts meta.method.declaration.ts meta.return.type.ts meta.type.function.ts meta.parameters.ts punctuation.separator.parameter.ts
^
source.ts meta.interface.ts meta.method.declaration.ts meta.return.type.ts meta.type.function.ts meta.parameters.ts
^^^
source.ts meta.interface.ts meta.method.declaration.ts meta.return.type.ts meta.type.function.ts meta.parameters.ts variable.parameter.ts
^
source.ts meta.interface.ts meta.method.declaration.ts meta.return.type.ts meta.type.function.ts meta.parameters.ts keyword.operator.optional.ts
^
source.ts meta.interface.ts meta.method.declaration.ts meta.return.type.ts meta.type.function.ts meta.parameters.ts meta.type.annotation.ts keyword.operator.type.annotation.ts
^
source.ts meta.interface.ts meta.method.declaration.ts meta.return.type.ts meta.type.function.ts meta.parameters.ts meta.type.annotation.ts
^^^^^^
source.ts meta.interface.ts meta.method.declaration.ts meta.return.type.ts meta.type.function.ts meta.parameters.ts meta.type.annotation.ts support.type.primitive.ts
^
source.ts meta.interface.ts meta.method.declaration.ts meta.return.type.ts meta.type.function.ts meta.parameters.ts punctuation.definition.parameters.end.ts
^
source.ts meta.interface.ts meta.method.declaration.ts meta.return.type.ts
^^
source.ts meta.interface.ts meta.method.declaration.ts meta.return.type.ts meta.type.function.return.ts storage.type.function.arrow.ts
^
source.ts meta.interface.ts meta.method.declaration.ts meta.return.type.ts meta.type.function.return.ts
^^^^^
source.ts meta.interface.ts meta.method.declaration.ts meta.return.type.ts meta.type.function.return.ts entity.name.type.ts
^
source.ts meta.interface.ts meta.method.declaration.ts meta.return.type.ts meta.type.function.return.ts meta.type.parameters.ts punctuation.definition.typeparameters.begin.ts
^^^^^
source.ts meta.interface.ts meta.method.declaration.ts meta.return.type.ts meta.type.function.return.ts meta.type.parameters.ts entity.name.type.ts
^
source.ts meta.interface.ts meta.method.declaration.ts meta.return.type.ts meta.type.function.return.ts meta.type.parameters.ts punctuation.definition.typeparameters.end.ts
^
source.ts meta.interface.ts punctuation.terminator.statement.ts
^^
source.ts meta.interface.ts
>}
^
source.ts meta.interface.ts punctuation.definition.block.ts

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

@ -0,0 +1,3 @@
export interface ObjectAllocator {
getTokenConstructor(): new <TKind extends SyntaxKind>(kind: TKind, pos?: number, end?: number) => Token<TKind>;
}