Skip to content
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

Improve scopes of type cast declarations #798

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
7 changes: 4 additions & 3 deletions TypeScript.YAML-tmLanguage
Original file line number Diff line number Diff line change
Expand Up @@ -1375,7 +1375,7 @@ repository:
match: '{{startOfIdentifier}}(as)\s+(const)(?=\s*([,}]|$))'
captures:
'1': { name: keyword.control.as.ts }
'2': { name: storage.modifier.ts }
'2': { name: storage.modifier.const.type.ts }
Copy link
Member

Choose a reason for hiding this comment

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

please do not change scope for modifier const. Instead add name as cast.expr.ts

- name: meta.object.member.ts
begin: '{{startOfIdentifier}}(as)\s+'
beginCaptures:
Copy link
Member

Choose a reason for hiding this comment

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

Add name for this as cast.expr.ts as well

Expand Down Expand Up @@ -1561,7 +1561,7 @@ repository:
match: \s*(<)\s*(const)\s*(>)
captures:
'1': { name: meta.brace.angle.ts }
'2': { name: storage.modifier.ts }
'2': { name: storage.modifier.const.type.ts }
Copy link
Member

Choose a reason for hiding this comment

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

Same here

'3': { name: meta.brace.angle.ts }
- name: cast.expr.ts
# We need to differentiate between the relational '<' operator and the beginning of a type assertion/cast using the surrounding context.
Expand Down Expand Up @@ -1624,11 +1624,12 @@ repository:
- match: '{{startOfIdentifier}}(as)\s+(const)(?=\s*($|[;,:})\]]))'
captures:
'1': { name: keyword.control.as.ts }
'2': { name: storage.modifier.ts }
'2': { name: storage.modifier.const.type.ts }
Copy link
Member

Choose a reason for hiding this comment

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

Same here

- begin: '{{startOfIdentifier}}(as)\s+'
beginCaptures:
'1': { name: keyword.control.as.ts }
end: (?=$|^|[;,:})\]]|\|\||\&\&|({{startOfIdentifier}}(as)\s+)|(\s+\<))
contentName: meta.type.cast.ts
Copy link
Member

Choose a reason for hiding this comment

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

Name this as cast.expr.ts and use name instead of contentName since cast expression starts at as

patterns:
- include: '#type'
- name: keyword.operator.spread.ts
Expand Down
8 changes: 5 additions & 3 deletions TypeScript.tmLanguage
Original file line number Diff line number Diff line change
Expand Up @@ -4440,7 +4440,7 @@
<key>2</key>
<dict>
<key>name</key>
<string>storage.modifier.ts</string>
<string>storage.modifier.const.type.ts</string>
</dict>
</dict>
</dict>
Expand Down Expand Up @@ -5099,7 +5099,7 @@
<key>2</key>
<dict>
<key>name</key>
<string>storage.modifier.ts</string>
<string>storage.modifier.const.type.ts</string>
</dict>
<key>3</key>
<dict>
Expand Down Expand Up @@ -5281,7 +5281,7 @@
<key>2</key>
<dict>
<key>name</key>
<string>storage.modifier.ts</string>
<string>storage.modifier.const.type.ts</string>
</dict>
</dict>
</dict>
Expand All @@ -5298,6 +5298,8 @@
</dict>
<key>end</key>
<string>(?=$|^|[;,:})\]]|\|\||\&amp;\&amp;|((?&lt;![_$[:alnum:]])(?:(?&lt;=\.\.\.)|(?&lt;!\.))(as)\s+)|(\s+\&lt;))</string>
<key>contentName</key>
<string>meta.type.cast.ts</string>
<key>patterns</key>
<array>
<dict>
Expand Down
6 changes: 4 additions & 2 deletions TypeScriptReact.tmLanguage
Original file line number Diff line number Diff line change
Expand Up @@ -4464,7 +4464,7 @@
<key>2</key>
<dict>
<key>name</key>
<string>storage.modifier.tsx</string>
<string>storage.modifier.const.type.tsx</string>
</dict>
</dict>
</dict>
Expand Down Expand Up @@ -5227,7 +5227,7 @@
<key>2</key>
<dict>
<key>name</key>
<string>storage.modifier.tsx</string>
<string>storage.modifier.const.type.tsx</string>
</dict>
</dict>
</dict>
Expand All @@ -5244,6 +5244,8 @@
</dict>
<key>end</key>
<string>(?=$|^|[;,:})\]]|\|\||\&amp;\&amp;|((?&lt;![_$[:alnum:]])(?:(?&lt;=\.\.\.)|(?&lt;!\.))(as)\s+)|(\s+\&lt;))</string>
<key>contentName</key>
<string>meta.type.cast.tsx</string>
<key>patterns</key>
<array>
<dict>
Expand Down
4 changes: 2 additions & 2 deletions tests/baselines/Issue314.baseline.txt
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ Grammar: TypeScript.tmLanguage
^
source.ts meta.var.expr.ts
^
source.ts meta.var.expr.ts entity.name.type.ts
source.ts meta.var.expr.ts meta.type.cast.ts entity.name.type.ts
Copy link
Member

Choose a reason for hiding this comment

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

Please use cast.expr.ts as scope instead of meta.type.cast.ts

^
source.ts meta.var.expr.ts
source.ts meta.var.expr.ts meta.type.cast.ts
^
source.ts meta.var.expr.ts keyword.operator.ternary.ts
^
Expand Down
6 changes: 3 additions & 3 deletions tests/baselines/Issue500.baseline.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ Grammar: TypeScript.tmLanguage
^
source.ts
^^^
source.ts support.type.primitive.ts
source.ts meta.type.cast.ts support.type.primitive.ts
^
source.ts
source.ts meta.type.cast.ts
^^
source.ts keyword.control.as.ts
^
source.ts
^^^^^^
source.ts support.type.primitive.ts
source.ts meta.type.cast.ts support.type.primitive.ts
^
source.ts punctuation.terminator.statement.ts
4 changes: 2 additions & 2 deletions tests/baselines/Issue59.baseline.txt
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ Grammar: TypeScript.tmLanguage
^
source.ts meta.class.ts meta.field.declaration.ts
^
source.ts meta.class.ts meta.field.declaration.ts meta.object.type.ts punctuation.definition.block.ts
source.ts meta.class.ts meta.field.declaration.ts meta.type.cast.ts meta.object.type.ts punctuation.definition.block.ts
^
source.ts meta.class.ts meta.field.declaration.ts meta.object.type.ts punctuation.definition.block.ts
source.ts meta.class.ts meta.field.declaration.ts meta.type.cast.ts meta.object.type.ts punctuation.definition.block.ts
^
source.ts meta.class.ts punctuation.terminator.statement.ts
> public a: string;
Expand Down
2 changes: 1 addition & 1 deletion tests/baselines/Issue647.baseline.txt
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ Grammar: TypeScript.tmLanguage
^
source.ts meta.function.ts meta.block.ts
^^^^^^
source.ts meta.function.ts meta.block.ts support.type.primitive.ts
source.ts meta.function.ts meta.block.ts meta.type.cast.ts support.type.primitive.ts
^
source.ts meta.function.ts meta.block.ts
^
Expand Down
2 changes: 1 addition & 1 deletion tests/baselines/Issue695.baseline.txt
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,6 @@ Grammar: TypeScript.tmLanguage
^
source.ts meta.var.expr.ts
^^^^^^^^^^^^^^^^^^^^^^^^^^^
source.ts meta.var.expr.ts entity.name.type.ts
source.ts meta.var.expr.ts meta.type.cast.ts entity.name.type.ts
^
source.ts punctuation.terminator.statement.ts
4 changes: 2 additions & 2 deletions tests/baselines/Issue762.baseline.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ Grammar: TypeScript.tmLanguage
^
source.ts
^^^
source.ts support.type.primitive.ts
source.ts meta.type.cast.ts support.type.primitive.ts
^
source.ts
source.ts meta.type.cast.ts
^^
source.ts keyword.operator.logical.ts
^
Expand Down
10 changes: 5 additions & 5 deletions tests/baselines/constType.baseline.txt
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ Grammar: TypeScript.tmLanguage
^
source.ts meta.var.expr.ts
^^^^^
source.ts meta.var.expr.ts storage.modifier.ts
source.ts meta.var.expr.ts storage.modifier.const.type.ts
^
source.ts punctuation.terminator.statement.ts
>let r2 = {...p} as const;
Expand Down Expand Up @@ -87,7 +87,7 @@ Grammar: TypeScript.tmLanguage
^
source.ts meta.var.expr.ts
^^^^^
source.ts meta.var.expr.ts storage.modifier.ts
source.ts meta.var.expr.ts storage.modifier.const.type.ts
^
source.ts punctuation.terminator.statement.ts
>let p1 = { x: 10, y: 20 as const };
Expand Down Expand Up @@ -134,7 +134,7 @@ Grammar: TypeScript.tmLanguage
^
source.ts meta.var.expr.ts meta.objectliteral.ts meta.object.member.ts
^^^^^
source.ts meta.var.expr.ts meta.objectliteral.ts meta.object.member.ts storage.modifier.ts
source.ts meta.var.expr.ts meta.objectliteral.ts meta.object.member.ts storage.modifier.const.type.ts
^
source.ts meta.var.expr.ts meta.objectliteral.ts meta.object.member.ts
^
Expand Down Expand Up @@ -167,7 +167,7 @@ Grammar: TypeScript.tmLanguage
^
source.ts meta.var.expr.ts meta.objectliteral.ts meta.object.member.ts
^^^^^
source.ts meta.var.expr.ts meta.objectliteral.ts meta.object.member.ts storage.modifier.ts
source.ts meta.var.expr.ts meta.objectliteral.ts meta.object.member.ts storage.modifier.const.type.ts
^
source.ts meta.var.expr.ts meta.objectliteral.ts punctuation.separator.comma.ts
^
Expand All @@ -185,7 +185,7 @@ Grammar: TypeScript.tmLanguage
^
source.ts meta.var.expr.ts meta.objectliteral.ts meta.object.member.ts
^^^^^
source.ts meta.var.expr.ts meta.objectliteral.ts meta.object.member.ts storage.modifier.ts
source.ts meta.var.expr.ts meta.objectliteral.ts meta.object.member.ts storage.modifier.const.type.ts
^
source.ts meta.var.expr.ts meta.objectliteral.ts
^
Expand Down
2 changes: 1 addition & 1 deletion tests/baselines/constTypeAssert.baseline.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ Grammar: TypeScript.tmLanguage
^
source.ts meta.var.expr.ts cast.expr.ts meta.brace.angle.ts
^^^^^
source.ts meta.var.expr.ts cast.expr.ts storage.modifier.ts
source.ts meta.var.expr.ts cast.expr.ts storage.modifier.const.type.ts
^
source.ts meta.var.expr.ts cast.expr.ts meta.brace.angle.ts
^
Expand Down