Skip to content

Commit

Permalink
[TypeScript] Non-null assertion is not an accessor (#3893)
Browse files Browse the repository at this point in the history
Fixes 3890

This commit changes scope of exclamation mark in `foo!.` from accessor to operator.
  • Loading branch information
Thom1729 authored Dec 16, 2023
1 parent 36d3f0e commit ba620ca
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 8 deletions.
6 changes: 3 additions & 3 deletions JavaScript/JavaScript.sublime-syntax
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ variables:
=>
)
function_call_after_lookahead: (?=\s*(?:{{dot_accessor}}\s*)?\()
function_call_after_lookahead: (?=\s*(?:\?\.\s*)?\()

function_assignment_lookahead: |-
(?x:(?=
Expand Down Expand Up @@ -1970,7 +1970,7 @@ contexts:

function-call-arguments:
- meta_content_scope: meta.function-call.js
- match: '{{dot_accessor}}'
- match: '\?\.'
scope: punctuation.accessor.js
- match: \(
scope: punctuation.section.group.begin.js
Expand All @@ -1992,7 +1992,7 @@ contexts:
- include: expression-list

property-access:
- match: ({{dot_accessor}})?(\[)
- match: (\?\.)?(\[)
captures:
1: punctuation.accessor.js
2: punctuation.section.brackets.begin.js
Expand Down
20 changes: 16 additions & 4 deletions JavaScript/TypeScript.sublime-syntax
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ first_line_match: |-
variables:
shebang_lang: \bts-node(?:-script)?\b

dot_accessor: (?:[?!]?\.)
possible_arrow_function_begin: (?:\(|{{identifier_start}}|<)

function_call_after_lookahead: >-
Expand All @@ -30,7 +29,8 @@ variables:
>
\s*
)?
(?:{{dot_accessor}}\s*)?
(?: \! \s* )*
(?: \?\. \s*)?
\(
))
Expand Down Expand Up @@ -692,6 +692,12 @@ contexts:
- method-declaration-prefix
- class-element-modifiers

left-expression-end:
- meta_prepend: true
- match: '{{function_call_after_lookahead}}'
push: function-call-arguments
- include: ts-non-null-assertion

expression-end:
- meta_prepend: true
- include: ts-type-assertion
Expand All @@ -700,6 +706,7 @@ contexts:
decorator-expression-end:
- meta_prepend: true
- include: ts-function-type-arguments-or-less-than
- include: ts-non-null-assertion

ts-function-type-arguments-or-less-than:
- match: (?=<(?![<=]))
Expand Down Expand Up @@ -756,10 +763,11 @@ contexts:
- parenthesized-expression
- include: else-pop

ts-type-assertion:
- match: '!(?![.=])'
ts-non-null-assertion:
- match: '!(?!=)'
scope: keyword.operator.type.js

ts-type-assertion:
- match: as{{identifier_break}}
scope: keyword.operator.type.js
push:
Expand Down Expand Up @@ -1192,3 +1200,7 @@ contexts:
pop: 1
- match: (?=\S)
fail: ts-object-literal-element-modifier

function-call-arguments:
- meta_prepend: true
- include: ts-non-null-assertion
8 changes: 7 additions & 1 deletion JavaScript/tests/syntax_test_typescript.ts
Original file line number Diff line number Diff line change
Expand Up @@ -783,7 +783,8 @@ x as const;
// ^^^^^ storage.modifier.const

foo!.bar;
// ^^ punctuation.accessor
// ^ keyword.operator.type - punctuation.accessor
// ^ punctuation.accessor

x ! ;
// ^ variable.other.readwrite
Expand Down Expand Up @@ -1553,3 +1554,8 @@ type T = Foo | ... 100 more ... | Bar;
// ^ keyword.operator.comparison
// ^ meta.number.integer.decimal constant.numeric.value
// ^ punctuation.terminator.statement

foo!!()
// ^^^^^^^ meta.function-call
// ^^ keyword.operator.type
// ^^ meta.function-call.arguments

0 comments on commit ba620ca

Please sign in to comment.