diff --git a/JavaScript/JavaScript.sublime-syntax b/JavaScript/JavaScript.sublime-syntax index 0da5bfceae..b75884d896 100644 --- a/JavaScript/JavaScript.sublime-syntax +++ b/JavaScript/JavaScript.sublime-syntax @@ -16,6 +16,19 @@ variables: constant_identifier: (?:[[:upper:]]{{identifier_part}}*{{identifier_break}}) dollar_only_identifier: (?:\${{identifier_break}}) dollar_identifier: '(?:(\$){{identifier_part}}*{{identifier_break}})' + + # https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Lexical_grammar + reserved_word: |- + (?x)(?: + break|case|catch|class|const|continue|debugger|default|delete|do|else| + export|extends|finally|for|function|if|import|in|instanceof|new|return| + super|switch|this|throw|try|typeof|var|void|while|with|yield| + enum| + null|true|false + ){{identifier_break}} + + non_reserved_identifier: (?:(?!{{reserved_word}}){{identifier}}) + either_func_lookahead: (?:{{func_lookahead}}|{{arrow_func_lookahead}}) binding_pattern_lookahead: (?:{{identifier}}|\[|\{) left_expression_end_lookahead: (?!\s*[.\[\(]) @@ -1155,7 +1168,7 @@ contexts: - include: else-pop inherited-class-name: - - match: '{{identifier}}{{left_expression_end_lookahead}}' + - match: '{{non_reserved_identifier}}{{left_expression_end_lookahead}}' scope: entity.other.inherited-class.js pop: true @@ -1173,7 +1186,7 @@ contexts: - include: expression-begin class-name: - - match: '{{identifier}}' + - match: '{{non_reserved_identifier}}' scope: entity.name.class.js pop: true - include: else-pop diff --git a/JavaScript/tests/syntax_test_js.js b/JavaScript/tests/syntax_test_js.js index 51f060a04a..fdc7612cfe 100644 --- a/JavaScript/tests/syntax_test_js.js +++ b/JavaScript/tests/syntax_test_js.js @@ -982,6 +982,15 @@ Bar {} class Foo extends getSomeClass() {} // ^^^^^^^^^^^^ meta.function-call variable.function - entity.other.inherited-class + (class extends Bar {}); +// ^^^^^^^ storage.modifier.extends - entity.name.class + + (class extends class {} {}); +// ^^^^^^^^^^^^^^^^^^^^^^^^^ meta.class +// ^^^^^^^ storage.modifier.extends +// ^^^^^^^^ meta.class meta.class +// ^^^^^ storage.type.class + () => {} // ^^^^^^^^ meta.function - meta.function meta.function // ^^^^^ meta.function.declaration