-
Notifications
You must be signed in to change notification settings - Fork 588
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[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
- Loading branch information
Showing
2 changed files
with
224 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,161 @@ | ||
// SYNTAX TEST "Packages/JavaScript/JavaScript.sublime-syntax" | ||
|
||
import TheirClass from "./mypath"; | ||
|
||
function foo() { | ||
// ^ storage.type.function | ||
// ^ entity.name.function | ||
} | ||
|
||
var bar = function() { | ||
// <- storage.type | ||
// ^ entity.name.function | ||
// ^ storage.type.function | ||
} | ||
|
||
baz = function*() | ||
// <- entity.name.function | ||
// ^ storage.type.function | ||
// ^ keyword.generator.asterisk | ||
{ | ||
|
||
} | ||
|
||
if (true) | ||
// <- keyword.control.conditional | ||
{ | ||
bar() | ||
} | ||
|
||
var str = '\':'; | ||
var str2 = 0; | ||
// <- storage.type | ||
// ^ variable.other.readwrite | ||
// ^ keyword.operator.assignment | ||
|
||
var obj = { | ||
key: bar, | ||
// <- meta.object-literal.key | ||
$key2: "string value", | ||
// ^ meta.object-literal.key | ||
// ^ - constant.other | ||
// ^ string.quoted.double | ||
$key3: 0 | ||
// <- meta.object-literal.key.dollar punctuation.dollar | ||
// <- meta.object-literal.key.dollar - punctuation.dollar | ||
"key4": true | ||
// <- string.quoted.double | ||
// ^ punctuation.separator.key-value - string | ||
'key5': true | ||
// <- string.quoted.single | ||
// ^ punctuation.separator.key-value - string | ||
|
||
static foo(bar) { | ||
// ^ storage.type | ||
// ^entity.name.function | ||
} | ||
|
||
*baz(){ | ||
// <- keyword.generator.asterisk | ||
// ^ entity.name.function | ||
} | ||
} | ||
|
||
var $ = function(baz) { | ||
// ^ variable.other.dollar.only punctuation.dollar | ||
} | ||
|
||
$() | ||
// <- variable.other.dollar.only punctuation.dollar | ||
|
||
$foo = null; | ||
// <- variable.other.dollar punctuation.dollar | ||
// ^ variable.other.dollar - punctuation.dollar | ||
|
||
|
||
baz = ""; | ||
// <- variable.other.readwrite | ||
// ^ string.quoted.double | ||
|
||
var qux = 100; | ||
// <- storage.type | ||
// ^ variable.other.readwrite | ||
// ^ constant.numeric | ||
|
||
if (100.0 > 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 |
10073d7
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suggest matching the escape sequences (at least the ones that you modified) as
constant.character.escape
.10073d7
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There will need to be more refactoring to support that, I imagine. You can open an issue if you'd like to see that happen. I won't remember every issue mentioned In a comment.
10073d7
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I might as well.