From 10073d7f7d559514c9a48230ba6b9986ed4687fa Mon Sep 17 00:00:00 2001 From: wbond Date: Thu, 11 Feb 2016 22:18:18 -0500 Subject: [PATCH] [JavaScript] Various syntax improvements - Added a syntax test - Remove string.unquoted from object keys - Remove constant.other.object.key.js from object key and : - Fix : after case in switch to not have keyword.operator.ternary.js - Implement support for class method to have a { on next line - Variables starting with $ get variable.other.dollar - Object keys starting with $ get meta.object-literal.key.dollar - Object keys not start with $ get meta.object-literal.key - $ at beginning of variable or object key get puntuation.dollar - Fix various string patterns to properly handle \ escapes - Removed keyword.other.jquery.js in favor of various "dollar" scopes --- JavaScript/JavaScript.sublime-syntax | 89 ++++++++++----- JavaScript/syntax_test_js.js | 161 +++++++++++++++++++++++++++ 2 files changed, 224 insertions(+), 26 deletions(-) create mode 100644 JavaScript/syntax_test_js.js diff --git a/JavaScript/JavaScript.sublime-syntax b/JavaScript/JavaScript.sublime-syntax index d3c8f47c83..0e2b26c224 100644 --- a/JavaScript/JavaScript.sublime-syntax +++ b/JavaScript/JavaScript.sublime-syntax @@ -271,8 +271,8 @@ contexts: - match: |- (?x) (?: - ((')((?:[^']|\\')*)('))| - ((")((?:[^"]|\\")*)(")) + ((')((?:[^'\\]+|\\.)*)('))| + ((")((?:[^"\\]+|\\.)*)(")) ) \s*(:) \s*(async)? @@ -298,8 +298,8 @@ contexts: - match: |- (?x) (?: - ((')((?:[^']|\\')*)('))| - ((")((?:[^"]|\\")*)(")) + ((')((?:[^'\\]+|\\.)*)('))| + ((")((?:[^"\\]+|\\.)*)(")) ) \s*(:) \s*(async)? @@ -350,6 +350,17 @@ contexts: - include: brackets - include: comments - include: literal-method + - match: '(?:(?:(static|async)|(get|set))\s+)?(?:\s*(\*)\s*)?([$_a-zA-Z][$\w]*)(?=\()' + captures: + 1: storage.type.js + 2: storage.type.accessor + 3: keyword.generator.asterisk.js + 4: entity.name.function.method.js + push: + - meta_scope: meta.method.js + - match: (?<=\)) + pop: true + - include: function-declaration-parameters literal-constructor: - match: '(new)\s+(?=[_$a-zA-Z][$\w.]*)' captures: @@ -462,6 +473,13 @@ contexts: pop: true - include: function-declaration-parameters literal-function-call: + - match: |- + (?x) + ((? qux) { + +} + +switch ($foo) { + case foo: + // ^ keyword.control.switch + // ^ - punctuation.separator.key-value + qux = 1; + break; + // ^ keyword.control.loop + case "baz": + // ^ keyword.control.switch + // ^ - punctuation.separator.key-value string + qux = 2; + break; + // ^ keyword.control.loop + default: + // ^ keyword.control.switch + // ^ - punctuation.separator.key-value + qux = 3; +} + +class MyClass extends TheirClass { + constructor(el) + // ^ entity.name.function + { + $.foo = ""; + super(el); + } + + get foo() + // <- storage.type.accessor + // ^ entity.name.function + { + return this._foo; + } + + static foo(baz) { + // ^ storage.type + // ^ entity.name.function + + } + + qux() + { } + + get bar () { + // <- storage.type.accessor + // ^ entity.name.function + return false; + } + + baz() { return null } + // <- entity.name.function +} + +MyClass.foo = function() {} +// ^ support.class +// ^ entity.name.function + +var simpleArrow = foo => bar +// ^ entity.name.function +// ^ variable.parameter.function +// ^ storage.type.function.arrow + +var Proto = () => { +// ^ entity.name.function +// ^ storage.type.function.arrow + this._var = 1; +} + +Proto.prototype.getVar = () => this._var +// ^ entity.name.class +// ^ support.constant.prototype +// ^ entity.name.function +// ^ storage.type.function.arrow