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

[TypeScript] Non-null assertion is not an accessor #3893

Merged
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
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