From f32e4bda41407855cbcb84d6a2c328f4003a0436 Mon Sep 17 00:00:00 2001 From: Thomas Smith Date: Sat, 30 Sep 2023 16:55:40 -0400 Subject: [PATCH] [JavaScript] Simplify handling of modifiers in class members --- JavaScript/JavaScript.sublime-syntax | 71 ++++++++++++------------ JavaScript/TypeScript.sublime-syntax | 8 ++- JavaScript/tests/syntax_test_js_class.js | 9 ++- 3 files changed, 48 insertions(+), 40 deletions(-) diff --git a/JavaScript/JavaScript.sublime-syntax b/JavaScript/JavaScript.sublime-syntax index ec26d8a7d1..3e43112a1c 100644 --- a/JavaScript/JavaScript.sublime-syntax +++ b/JavaScript/JavaScript.sublime-syntax @@ -231,6 +231,10 @@ contexts: - match: '' pop: 1 + immediately-pop-2: + - match: '' + pop: 2 + comma-separator: - match: ',' scope: punctuation.separator.comma.js @@ -1497,7 +1501,7 @@ contexts: pop: 1 - match: \; - scope: punctuation.terminator.statement.js + scope: punctuation.terminator.statement.empty.js - include: decorator @@ -1512,15 +1516,9 @@ contexts: branch_point: static-block branch: - static-block - - class-element-modifiers - - - match: (?={{modifier}}) - push: class-element-modifiers - - - match: (?=\*) - push: method-declaration + - class-element - - match: (?={{class_element_name}}) + - match: (?=\S) push: class-element static-block: @@ -1531,23 +1529,6 @@ contexts: - match: (?=\S) fail: static-block - class-element-modifiers: - - match: '' - pop: 1 - branch_point: class-element-modifier - branch: - - class-element-modifier - - class-element - - class-element-modifier: - - match: '{{modifier}}' - scope: storage.modifier.js - set: - - match: (?={{class_element_name}}|\*) - pop: 1 - - match: (?=\S) - fail: class-element-modifier - class-extends: - match: extends{{identifier_break}} scope: storage.modifier.extends.js @@ -1581,6 +1562,8 @@ contexts: - include: else-pop class-element: + - match: (?=\*) + set: method-declaration - match: '' pop: 1 branch_point: class-field @@ -1591,15 +1574,32 @@ contexts: class-field: - match: '' set: + - expect-semicolon - initializer - class-field-check - field-name + - class-element-modifiers class-field-check: - match: (?=\() fail: class-field - include: else-pop + class-element-modifiers: + - match: (?={{modifier}}) + branch_point: class-element-modifier + branch: + - - match: '{{modifier}}' + scope: storage.modifier.js + set: + - match: (?={{class_element_name}}|\*) + pop: 1 + - match: (?=\S) + fail: class-element-modifier + + - immediately-pop-2 + - include: else-pop + special-name: - match: true{{identifier_break}} scope: constant.language.boolean.true.js @@ -1938,6 +1938,7 @@ contexts: - method-name - method-declaration-expect-asterisk - method-declaration-prefix + - class-element-modifiers method-declaration-expect-asterisk: - match: \* @@ -1951,21 +1952,19 @@ contexts: branch: - - match: (?:get|set){{identifier_break}} scope: storage.type.accessor.js - set: - - match: (?={{class_element_name}}) - pop: 1 - - match: (?=\S) - fail: method-declaration-prefix + set: method-declaration-prefix-check - match: (?:async){{identifier_break}} scope: keyword.declaration.async.js - set: - - match: (?=\*|{{class_element_name}}) - pop: 1 - - match: (?=\S) - fail: method-declaration-prefix + set: method-declaration-prefix-check - immediately-pop - include: else-pop + method-declaration-prefix-check: + - match: (?=\*|{{class_element_name}}) + pop: 1 + - match: (?=\S) + fail: method-declaration-prefix + parenthesized-expression: - match: \( scope: punctuation.section.group.begin.js diff --git a/JavaScript/TypeScript.sublime-syntax b/JavaScript/TypeScript.sublime-syntax index faea89b42a..cba16c6fc3 100644 --- a/JavaScript/TypeScript.sublime-syntax +++ b/JavaScript/TypeScript.sublime-syntax @@ -387,11 +387,10 @@ contexts: - match: '\+|-' scope: storage.modifier.js - match: (?={{modifier}}) - pop: 1 branch_point: ts-type-member-modifier branch: - ts-type-member-modifier - - immediately-pop + - immediately-pop-2 - include: else-pop ts-type-member-modifier: @@ -399,7 +398,7 @@ contexts: scope: storage.modifier.js set: - match: (?={{identifier_start}}|[-+*''"\[\d]) - set: ts-type-element-modifiers + pop: 1 - match: (?=\S) fail: ts-type-member-modifier @@ -655,12 +654,14 @@ contexts: - meta_include_prototype: false - match: '' set: + - expect-semicolon - initializer - ts-type-annotation - ts-type-annotation-optional - ts-type-annotation-definite - class-field-check - field-name + - class-element-modifiers class-field-check: - match: (?=[(<]) @@ -679,6 +680,7 @@ contexts: - method-name - method-declaration-expect-asterisk - method-declaration-prefix + - class-element-modifiers expression-end: - meta_prepend: true diff --git a/JavaScript/tests/syntax_test_js_class.js b/JavaScript/tests/syntax_test_js_class.js index 2d13e40980..999be65c21 100644 --- a/JavaScript/tests/syntax_test_js_class.js +++ b/JavaScript/tests/syntax_test_js_class.js @@ -11,6 +11,7 @@ class MyClass extends TheirClass { // ^ variable.other.readwrite // ^ keyword.operator.assignment // ^^ constant.numeric +// ^ punctuation.terminator.statement - punctuation.terminator.statement.empty 'y' = 42; // ^^^ meta.string string.quoted.single @@ -142,7 +143,8 @@ class MyClass extends TheirClass { for (const param of this.#data.get('value')) {} // ^ punctuation.definition.variable // ^^^^ meta.property.object - } + }; +// ^ punctuation.terminator.statement.empty.js #privateMethod() {} // ^^^^^^^^^^^^^^^^^^^ meta.function @@ -168,8 +170,13 @@ class MyClass extends TheirClass { } get *foo() +// ^^^^^^^^ meta.function +// ^^^ storage.type.accessor +// ^ keyword.generator.asterisk +// ^^^ entity.name.function static foo(baz) { +// ^^^^^^^^^^^^^^^^^ meta.function // ^^^^^^ storage.modifier // ^^^^^^^^^^ meta.function // ^^^ entity.name.function