Skip to content

Add 'abstract' keyword to constructor type syntax. #861

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 9, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions TypeScript.YAML-tmLanguage
Original file line number Diff line number Diff line change
Expand Up @@ -2443,17 +2443,19 @@ repository:
type-fn-type-parameters:
patterns:
# constructor type
- begin: '{{startOfIdentifier}}(new)\b(?=\s*\<)'
- begin: '{{startOfIdentifier}}(?:(abstract)\s+)?(new)\b(?=\s*\<)'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

beginCaptures:
'1': { name: meta.type.constructor.ts keyword.control.new.ts }
'1': { name: meta.type.constructor.ts storage.modifier.ts } # captures keyword (abstract)
'2': { name: meta.type.constructor.ts keyword.control.new.ts } # captures keyword (new)
end: (?<=>)
patterns:
- include: '#comment'
- include: '#type-parameters'
- name: meta.type.constructor.ts
begin: '{{startOfIdentifier}}(new)\b\s*(?=\()'
begin: '{{startOfIdentifier}}(?:(abstract)\s+)?(new)\b\s*(?=\()'
beginCaptures:
'1': { name: keyword.control.new.ts }
'1': { name: storage.modifier.ts } # captures keyword (abstract)
'2': { name: keyword.control.new.ts } # captures keyword (new)
end: (?<=\))
patterns:
- include: '#function-parameters'
Expand Down
14 changes: 12 additions & 2 deletions TypeScript.tmLanguage
Original file line number Diff line number Diff line change
Expand Up @@ -7424,10 +7424,15 @@
<array>
<dict>
<key>begin</key>
<string>(?&lt;![_$[:alnum:]])(?:(?&lt;=\.\.\.)|(?&lt;!\.))(new)\b(?=\s*\&lt;)</string>
<string>(?&lt;![_$[:alnum:]])(?:(?&lt;=\.\.\.)|(?&lt;!\.))(?:(abstract)\s+)?(new)\b(?=\s*\&lt;)</string>
<key>beginCaptures</key>
<dict>
<key>1</key>
<dict>
<key>name</key>
<string>meta.type.constructor.ts storage.modifier.ts</string>
</dict>
<key>2</key>
<dict>
<key>name</key>
<string>meta.type.constructor.ts keyword.control.new.ts</string>
Expand All @@ -7451,10 +7456,15 @@
<key>name</key>
<string>meta.type.constructor.ts</string>
<key>begin</key>
<string>(?&lt;![_$[:alnum:]])(?:(?&lt;=\.\.\.)|(?&lt;!\.))(new)\b\s*(?=\()</string>
<string>(?&lt;![_$[:alnum:]])(?:(?&lt;=\.\.\.)|(?&lt;!\.))(?:(abstract)\s+)?(new)\b\s*(?=\()</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>keyword.control.new.ts</string>
Expand Down
14 changes: 12 additions & 2 deletions TypeScriptReact.tmLanguage
Original file line number Diff line number Diff line change
Expand Up @@ -7372,10 +7372,15 @@
<array>
<dict>
<key>begin</key>
<string>(?&lt;![_$[:alnum:]])(?:(?&lt;=\.\.\.)|(?&lt;!\.))(new)\b(?=\s*\&lt;)</string>
<string>(?&lt;![_$[:alnum:]])(?:(?&lt;=\.\.\.)|(?&lt;!\.))(?:(abstract)\s+)?(new)\b(?=\s*\&lt;)</string>
<key>beginCaptures</key>
<dict>
<key>1</key>
<dict>
<key>name</key>
<string>meta.type.constructor.tsx storage.modifier.tsx</string>
</dict>
<key>2</key>
<dict>
<key>name</key>
<string>meta.type.constructor.tsx keyword.control.new.tsx</string>
Expand All @@ -7399,10 +7404,15 @@
<key>name</key>
<string>meta.type.constructor.tsx</string>
<key>begin</key>
<string>(?&lt;![_$[:alnum:]])(?:(?&lt;=\.\.\.)|(?&lt;!\.))(new)\b\s*(?=\()</string>
<string>(?&lt;![_$[:alnum:]])(?:(?&lt;=\.\.\.)|(?&lt;!\.))(?:(abstract)\s+)?(new)\b\s*(?=\()</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>keyword.control.new.tsx</string>
Expand Down
58 changes: 57 additions & 1 deletion tests/baselines/constructorType.baseline.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
original file
-----------------------------------
type constructorType<T> = new <T>(a: T) => T;
type abstractConstructorType<T> = abstract new <T>(a: T) => T;
-----------------------------------

Grammar: TypeScript.tmLanguage
Expand Down Expand Up @@ -55,4 +56,59 @@ Grammar: TypeScript.tmLanguage
^
source.ts meta.type.declaration.ts meta.type.function.return.ts entity.name.type.ts
^
source.ts punctuation.terminator.statement.ts
source.ts punctuation.terminator.statement.ts
>type abstractConstructorType<T> = abstract new <T>(a: T) => T;
^^^^
source.ts meta.type.declaration.ts storage.type.type.ts
^
source.ts meta.type.declaration.ts
^^^^^^^^^^^^^^^^^^^^^^^
source.ts meta.type.declaration.ts entity.name.type.alias.ts
^
source.ts meta.type.declaration.ts meta.type.parameters.ts punctuation.definition.typeparameters.begin.ts
^
source.ts meta.type.declaration.ts meta.type.parameters.ts entity.name.type.ts
^
source.ts meta.type.declaration.ts meta.type.parameters.ts punctuation.definition.typeparameters.end.ts
^
source.ts meta.type.declaration.ts
^
source.ts meta.type.declaration.ts keyword.operator.assignment.ts
^
source.ts meta.type.declaration.ts
^^^^^^^^
source.ts meta.type.declaration.ts meta.type.constructor.ts storage.modifier.ts
^
source.ts meta.type.declaration.ts
^^^
source.ts meta.type.declaration.ts meta.type.constructor.ts keyword.control.new.ts
^
source.ts meta.type.declaration.ts
^
source.ts meta.type.declaration.ts meta.type.parameters.ts punctuation.definition.typeparameters.begin.ts
^
source.ts meta.type.declaration.ts meta.type.parameters.ts entity.name.type.ts
^
source.ts meta.type.declaration.ts meta.type.parameters.ts punctuation.definition.typeparameters.end.ts
^
source.ts meta.type.declaration.ts meta.type.function.ts meta.parameters.ts punctuation.definition.parameters.begin.ts
^
source.ts meta.type.declaration.ts meta.type.function.ts meta.parameters.ts variable.parameter.ts
^
source.ts meta.type.declaration.ts meta.type.function.ts meta.parameters.ts meta.type.annotation.ts keyword.operator.type.annotation.ts
^
source.ts meta.type.declaration.ts meta.type.function.ts meta.parameters.ts meta.type.annotation.ts
^
source.ts meta.type.declaration.ts meta.type.function.ts meta.parameters.ts meta.type.annotation.ts entity.name.type.ts
^
source.ts meta.type.declaration.ts meta.type.function.ts meta.parameters.ts punctuation.definition.parameters.end.ts
^
source.ts meta.type.declaration.ts
^^
source.ts meta.type.declaration.ts meta.type.function.return.ts storage.type.function.arrow.ts
^
source.ts meta.type.declaration.ts meta.type.function.return.ts
^
source.ts meta.type.declaration.ts meta.type.function.return.ts entity.name.type.ts
^
source.ts punctuation.terminator.statement.ts
3 changes: 2 additions & 1 deletion tests/cases/constructorType.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
type constructorType<T> = new <T>(a: T) => T;
type constructorType<T> = new <T>(a: T) => T;
type abstractConstructorType<T> = abstract new <T>(a: T) => T;