Skip to content

Commit

Permalink
[JavaScript] Fix optional chaining typos (#2350)
Browse files Browse the repository at this point in the history
  • Loading branch information
jfcherng authored Jul 20, 2020
1 parent e19987b commit cbfcbcd
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 24 deletions.
35 changes: 15 additions & 20 deletions JavaScript/JavaScript.sublime-syntax
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ variables:
binding_pattern_lookahead: (?:{{identifier}}|\[|\{)
left_expression_end_lookahead: (?!\s*[.\[\(])

dot_accessor: (?:\??\.)

property_name: >-
(?x:
{{identifier}}
Expand Down Expand Up @@ -99,13 +101,6 @@ variables:
)
))
dot_accessor: |-
(?x: # Match . and .?, but not .?( or .?[
\.
(?! \? [\[(] )
\??
)
contexts:
main:
- include: comments-top-level
Expand Down Expand Up @@ -881,7 +876,7 @@ contexts:
- match: (?=`)
push: literal-string-template

- match: (?=(?:\.\?)?\()
- match: (?=(?:{{dot_accessor}})?\()
push: function-call-arguments

- include: property-access
Expand Down Expand Up @@ -1191,7 +1186,7 @@ contexts:
push: expression-begin

ternary-operator:
- match: '\?'
- match: '\?(?=[^.]|\.[0-9])'
scope: keyword.operator.ternary.js
set:
- ternary-operator-expect-colon
Expand Down Expand Up @@ -1371,7 +1366,7 @@ contexts:
- function-declaration-identifiers
function-declaration-identifiers:
- match: '(?={{identifier}}\s*\.)'
- match: '(?={{identifier}}\s*{{dot_accessor}})'
push:
- expect-dot-accessor
- function-declaration-identifiers-expect-class
Expand Down Expand Up @@ -1741,7 +1736,7 @@ contexts:
push: expression

function-call-arguments:
- match: (\.\?)?(\()
- match: ({{dot_accessor}})?(\()
captures:
1: punctuation.accessor.js
2: punctuation.section.group.begin.js
Expand All @@ -1763,7 +1758,7 @@ contexts:
- include: expression-list

property-access:
- match: (\.\?)?(\[)
- match: ({{dot_accessor}})?(\[)
captures:
1: punctuation.accessor.js
2: punctuation.section.brackets.begin.js
Expand All @@ -1775,10 +1770,10 @@ contexts:
- match: (?=\S)
push: expression

- match: \.(?:\?)?
- match: '{{dot_accessor}}'
scope: punctuation.accessor.js
push:
- match: '(?={{identifier}}\s*(?:\.\?)?\()'
- match: '(?={{identifier}}\s*(?:{{dot_accessor}})?\()'
set:
- call-method-meta
- function-call-arguments
Expand Down Expand Up @@ -1851,13 +1846,13 @@ contexts:
pop: true

literal-call:
- match: (?={{identifier}}\s*(?:\.\?)?\()
- match: (?={{identifier}}\s*(?:{{dot_accessor}})?\()
set:
- call-function-meta
- function-call-arguments
- literal-variable

- match: (?={{identifier}}\s*(?:\.\s*{{identifier}}\s*)+(?:\.\?)?\()
- match: (?={{identifier}}\s*(?:{{dot_accessor}}\s*{{identifier}}\s*)+(?:{{dot_accessor}})?\()
set:
- call-method-meta
- function-call-arguments
Expand Down Expand Up @@ -1900,11 +1895,11 @@ contexts:
- include: language-identifiers
- include: support

- match: '{{constant_identifier}}(?=\s*[\[.])'
- match: '{{constant_identifier}}(?=\s*(?:{{dot_accessor}}|\[))'
scope: support.class.js
pop: true

- match: (?={{identifier}}\s*(?:\.\?)?\()
- match: (?={{identifier}}\s*(?:{{dot_accessor}})?\()
set: call-function-name

- include: literal-variable-base
Expand Down Expand Up @@ -2331,7 +2326,7 @@ contexts:
- include: support-property

- match: '(?={{identifier}}\s*(?:\.\?)?\()'
- match: '(?={{identifier}}\s*(?:{{dot_accessor}})?\()'
set: call-method-name

- include: object-property-base
Expand Down Expand Up @@ -2389,7 +2384,7 @@ contexts:
import-expression-end:
- match: (?=\()
set: function-call-arguments
- match: \.
- match: '{{dot_accessor}}'
scope: punctuation.accessor.js
set:
- match: meta{{identifier_break}}
Expand Down
13 changes: 9 additions & 4 deletions JavaScript/tests/syntax_test_js.js
Original file line number Diff line number Diff line change
Expand Up @@ -1989,25 +1989,30 @@ debugger
a ?? b;
// ^^ keyword.operator.logical

a.?b.?c;
a ?.5 : .7;
// ^ keyword.operator.ternary
// ^^ constant.numeric
// ^ keyword.operator.ternary

a?.b?.c;
// ^^ punctuation.accessor
// ^ meta.property.object
// ^^ punctuation.accessor
// ^ meta.property.object

a.?[propName];
a?.[propName];
// ^^^^^^^^^^^^ meta.brackets
// ^^ punctuation.accessor
// ^ punctuation.section.brackets.begin

a.?();
a?.();
// ^^^^^ meta.function-call
// ^ variable.function
// ^^^^ meta.group
// ^^ punctuation.accessor
// ^ punctuation.section.group.begin

a.b.?();
a.b?.();
// ^^^^^^^ meta.function-call.method
// ^ variable.function
//

0 comments on commit cbfcbcd

Please sign in to comment.