diff --git a/JavaScript/JavaScript.sublime-syntax b/JavaScript/JavaScript.sublime-syntax index cb9c9bb7572..503f7ccd164 100644 --- a/JavaScript/JavaScript.sublime-syntax +++ b/JavaScript/JavaScript.sublime-syntax @@ -47,6 +47,8 @@ variables: binding_pattern_lookahead: (?:{{identifier}}|\[|\{) left_expression_end_lookahead: (?!\s*[.\[\(]) + dot_accessor: (?:\??\.) + property_name: >- (?x: {{identifier}} @@ -99,13 +101,6 @@ variables: ) )) - dot_accessor: |- - (?x: # Match . and .?, but not .?( or .?[ - \. - (?! \? [\[(] ) - \?? - ) - contexts: main: - include: comments-top-level @@ -881,7 +876,7 @@ contexts: - match: (?=`) push: literal-string-template - - match: (?=(?:\.\?)?\() + - match: (?=(?:{{dot_accessor}})?\() push: function-call-arguments - include: property-access @@ -1191,7 +1186,7 @@ contexts: push: expression-begin ternary-operator: - - match: '\?' + - match: '\?(?=[^.]|\.[0-9])' scope: keyword.operator.ternary.js set: - ternary-operator-expect-colon @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -2331,7 +2326,7 @@ contexts: - include: support-property - - match: '(?={{identifier}}\s*(?:\.\?)?\()' + - match: '(?={{identifier}}\s*(?:{{dot_accessor}})?\()' set: call-method-name - include: object-property-base @@ -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}} diff --git a/JavaScript/tests/syntax_test_js.js b/JavaScript/tests/syntax_test_js.js index b1b50630b36..110d52feb6f 100644 --- a/JavaScript/tests/syntax_test_js.js +++ b/JavaScript/tests/syntax_test_js.js @@ -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 //