Skip to content

Commit fc5336d

Browse files
Thomas Smithwbond
Thomas Smith
authored andcommitted
[JavaScript] Implemented decorators proposal. (#1483)
1 parent 326c509 commit fc5336d

File tree

2 files changed

+71
-0
lines changed

2 files changed

+71
-0
lines changed

JavaScript/JavaScript.sublime-syntax

+34
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,8 @@ contexts:
284284

285285
- include: function-or-class-declaration
286286

287+
- include: decorator
288+
287289
- match: (?=\S)
288290
set: expression-statement
289291

@@ -699,6 +701,36 @@ contexts:
699701
set: parenthesized-expression
700702
- include: else-pop
701703

704+
decorator:
705+
- match: '@'
706+
scope: punctuation.definition.annotation.js
707+
push:
708+
- decorator-meta
709+
- decorator-expression-end
710+
- decorator-expression-begin
711+
712+
decorator-meta:
713+
- meta_scope: meta.annotation.js
714+
- include: immediately-pop
715+
716+
decorator-name:
717+
- match: '{{identifier}}{{left_expression_end_lookahead}}'
718+
scope: variable.annotation.js
719+
pop: true
720+
721+
decorator-expression-end:
722+
- match: \.
723+
scope: punctuation.accessor.js
724+
push:
725+
- include: decorator-name
726+
- include: object-property
727+
728+
- include: left-expression-end
729+
730+
decorator-expression-begin:
731+
- include: decorator-name
732+
- include: expression-begin
733+
702734
expression-break:
703735
- match: (?=[;})\]])
704736
pop: true
@@ -1074,6 +1106,8 @@ contexts:
10741106
- match: \;
10751107
scope: punctuation.terminator.statement.js
10761108

1109+
- include: decorator
1110+
10771111
- match: constructor{{identifier_break}}
10781112
scope: entity.name.function.constructor.js
10791113
push:

JavaScript/tests/syntax_test_js.js

+37
Original file line numberDiff line numberDiff line change
@@ -890,6 +890,24 @@ class MyClass extends TheirClass {
890890
constructor$() {}
891891
// ^^^^^^^^^^^^ entity.name.function - entity.name.function.constructor
892892

893+
@foo bar() {}
894+
// ^^^^ meta.annotation
895+
// ^ punctuation.definition.annotation
896+
// ^^^ variable.annotation
897+
// ^^^ entity.name.function
898+
899+
@foo.bar bar() {}
900+
// ^^^^^^^^ meta.annotation
901+
// ^ punctuation.definition.annotation
902+
// ^^^ variable.other.object - variable.annotation
903+
// ^^^ variable.annotation
904+
// ^^^ entity.name.function
905+
906+
@(whatever) bar() {}
907+
// ^^^^^^^^^^^ meta.annotation
908+
// ^ punctuation.definition.annotation
909+
// ^^^^^^^^^^ meta.group
910+
// ^^^ entity.name.function
893911

894912
['foo']() {}
895913
// ^^^^^^^^^ meta.function.declaration
@@ -936,6 +954,25 @@ Bar {}
936954
class Foo extends getSomeClass() {}
937955
// ^^^^^^^^^^^^ meta.function-call variable.function - entity.other.inherited-class
938956

957+
@foo class Foo {}
958+
// ^^^^ meta.annotation
959+
// ^ punctuation.definition.annotation
960+
// ^^^ variable.annotation
961+
// ^^^^^ storage.type.class
962+
963+
@foo.bar class Foo {}
964+
// ^^^^^^^^ meta.annotation
965+
// ^ punctuation.definition.annotation
966+
// ^^^ variable.other.object - variable.annotation
967+
// ^^^ variable.annotation
968+
// ^^^^^ storage.type.class
969+
970+
@(whatever) class Foo {}
971+
// ^^^^^^^^^^^ meta.annotation
972+
// ^ punctuation.definition.annotation
973+
// ^^^^^^^^^^ meta.group
974+
// ^^^^^ storage.type.class
975+
939976
() => {}
940977
// <- meta.function.declaration punctuation.section.group.begin
941978
// <- meta.function.declaration punctuation.section.group.end

0 commit comments

Comments
 (0)