lectures.alex.balgavy.eu

Lecture notes from university.
git clone git://git.alex.balgavy.eu/lectures.alex.balgavy.eu.git
Log | Files | Refs | Submodules

syntax_test_js_class.js (8931B)


      1 // SYNTAX TEST "Packages/JavaScript/JavaScript.sublime-syntax"
      2 
      3 class MyClass extends TheirClass {
      4 // <- keyword.declaration.class
      5 //    ^^^^^^^ entity.name.class
      6 //            ^^^^^^^ storage.modifier.extends
      7 //                    ^^^^^^^^^^ entity.other.inherited-class
      8 //                               ^ meta.block punctuation.section.block.begin
      9 
     10     x = 42;
     11 //  ^ variable.other.readwrite
     12 //    ^ keyword.operator.assignment
     13 //      ^^ constant.numeric
     14 
     15     'y' = 42;
     16 //  ^^^ meta.string string.quoted.single
     17 //   ^ variable.other.readwrite
     18 //      ^ keyword.operator.assignment
     19 //        ^^ constant.numeric
     20 
     21     "z" = 42;
     22 //  ^^^ meta.string string.quoted.double
     23 //   ^ variable.other.readwrite
     24 //      ^ keyword.operator.assignment
     25 //        ^^ constant.numeric
     26 
     27     [w] = 42;
     28 //  ^ punctuation.section.brackets.begin
     29 //   ^ variable.other.readwrite
     30 //    ^ punctuation.section.brackets.end
     31 //      ^ keyword.operator.assignment
     32 //        ^^ constant.numeric
     33 
     34     #v = 42;
     35 //  ^ punctuation.definition.variable
     36 //   ^ variable.other.readwrite
     37 //     ^ keyword.operator.assignment
     38 //       ^^ constant.numeric
     39 
     40     f = a => b;
     41 //  ^ entity.name.function variable.other.readwrite
     42 //      ^^^^^^ meta.function
     43 //      ^ variable.parameter.function
     44 
     45     g = function() {};
     46 //  ^ entity.name.function variable.other.readwrite
     47 //      ^^^^^^^^^^^^^ meta.function
     48 
     49     #h = function() {};
     50 //  ^ punctuation.definition.variable
     51 //   ^ entity.name.function variable.other.readwrite
     52 //       ^^^^^^^^^^^^^ meta.function
     53 
     54     class = null;
     55 //  ^^^^^ variable.other.readwrite
     56 
     57     static x = 42;
     58 //  ^^^^^^ storage.modifier.js
     59 //         ^ variable.other.readwrite
     60 //           ^ keyword.operator.assignment
     61 //             ^^ constant.numeric
     62 
     63     static 'y' = 42;
     64 //  ^^^^^^ storage.modifier.js
     65 //         ^^^ meta.string string.quoted.single
     66 //          ^ variable.other.readwrite
     67 //             ^ keyword.operator.assignment
     68 //               ^^ constant.numeric
     69 
     70     static "z" = 42;
     71 //  ^^^^^^ storage.modifier.js
     72 //         ^^^ meta.string string.quoted.double
     73 //          ^ variable.other.readwrite
     74 //             ^ keyword.operator.assignment
     75 //               ^^ constant.numeric
     76 
     77     static [w] = 42;
     78 //  ^^^^^^ storage.modifier.js
     79 //         ^ punctuation.section.brackets.begin
     80 //          ^ variable.other.readwrite
     81 //           ^ punctuation.section.brackets.end
     82 //             ^ keyword.operator.assignment
     83 //               ^^ constant.numeric
     84 
     85     static #v = 42;
     86 //         ^ punctuation.definition.variable
     87 //          ^ variable.other.readwrite
     88 //            ^ keyword.operator.assignment
     89 //              ^^ constant.numeric
     90 
     91     static f = a => b;
     92 //         ^ entity.name.function variable.other.readwrite
     93 //             ^^^^^^ meta.function
     94 //             ^ variable.parameter.function
     95 
     96     static g = function() {};
     97 //         ^ entity.name.function variable.other.readwrite
     98 //             ^^^^^^^^^^^^^ meta.function
     99 
    100     static = 42;
    101 //  ^^^^^^ variable.other.readwrite
    102 
    103     static() {}
    104 //  ^^^^^^^^^^^ meta.function
    105 //  ^^^^^^ entity.name.function
    106 
    107     foo // You thought I was a field...
    108     () { return '...but was a method all along!'; }
    109 //  ^^ meta.class meta.block meta.function
    110 
    111     someMethod() {
    112         return #e * 2;
    113 //             ^ punctuation.definition.variable
    114 //              ^ variable.other.readwrite
    115 //                ^ keyword.operator.arithmetic
    116 
    117         for (const param of this.#data.get('value')) {}
    118 //                               ^ punctuation.definition.variable
    119 //                                ^^^^ meta.property.object
    120     }
    121 
    122     #privateMethod() {}
    123 //  ^^^^^^^^^^^^^^^^^^^ meta.function
    124 //  ^^^^^^^^^^^^^^ entity.name.function.js
    125 //  ^ punctuation.definition.js
    126 
    127     constructor(el)
    128 //  ^^^^^^^^^^^^^^^ meta.function
    129     // ^ entity.name.function.constructor
    130     {
    131 //  ^ meta.class meta.block meta.function meta.block punctuation.section.block
    132         $.foo = "";
    133         super(el);
    134     }
    135 //  ^ meta.class meta.block meta.function meta.block punctuation.section.block
    136 
    137     get foo()
    138 //  ^^^^^^^^^ meta.function
    139     // <- storage.type.accessor
    140     //   ^ entity.name.function
    141     {
    142         return this._foo;
    143     }
    144 
    145     get *foo()
    146 
    147     static foo(baz) {
    148 //  ^^^^^^ storage.modifier
    149 //         ^^^^^^^^^^ meta.function
    150     //     ^^^ entity.name.function
    151 
    152     }
    153 
    154     qux()
    155 //  ^^^^^ meta.function
    156     { }
    157 //  ^ meta.class meta.block meta.block punctuation.section.block.begin
    158 
    159     get bar () {
    160 //  ^^^^^^^^^^^^ meta.function
    161 //             ^ meta.class meta.block meta.block punctuation.section.block.begin
    162     // <- storage.type.accessor
    163     //   ^ entity.name.function
    164         return false;
    165     }
    166 
    167     baz() { return null }
    168 //  ^^^^^^^^^^^^^^^^^^^^^ meta.function
    169     // <- entity.name.function
    170 
    171     get() { return "foobar"; }
    172 //  ^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.function
    173 //  ^^^ entity.name.function.js - storage.type.accessor
    174 
    175     set (value) { return value; }
    176 //  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.function
    177 //       ^^^^^ variable.parameter.function.js
    178 //  ^^^ entity.name.function.js - storage.type.accessor
    179 
    180     set  abc(value1, value2) { return value1 + value2; }
    181 //  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.function
    182 //  ^^^ storage.type.accessor - entity.name.function.js
    183 //       ^^^ entity.name.function.js
    184 //           ^^^^^^ variable.parameter.function.js
    185 //                 ^ punctuation.separator.parameter.function.js
    186 //                   ^^^^^^ variable.parameter.function.js
    187 
    188     static$
    189 //  ^^^^^^^ - storage
    190     () {};
    191 
    192     constructor$() {}
    193 //  ^^^^^^^^^^^^ entity.name.function - entity.name.function.constructor
    194 
    195     @foo bar() {}
    196 //  ^^^^ meta.annotation
    197 //  ^ punctuation.definition.annotation
    198 //   ^^^ variable.annotation
    199 //       ^^^ entity.name.function
    200 
    201     @foo.bar bar() {}
    202 //  ^^^^^^^^ meta.annotation
    203 //  ^ punctuation.definition.annotation
    204 //   ^^^ variable.other.readwrite - variable.annotation
    205 //       ^^^ variable.annotation
    206 //           ^^^ entity.name.function
    207 
    208     @(whatever) bar() {}
    209 //  ^^^^^^^^^^^ meta.annotation
    210 //  ^ punctuation.definition.annotation
    211 //   ^^^^^^^^^^ meta.group
    212 //              ^^^ entity.name.function
    213 
    214     ['foo']() {}
    215 //  ^^^^^^^^^^^^ meta.function
    216 
    217     static ['foo']() {}
    218 //         ^^^^^^^^^^^^ meta.function
    219 
    220     async foo() {}
    221 //  ^^^^^ keyword.declaration.async
    222 
    223     *foo() {}
    224 //  ^ keyword.generator.asterisk
    225 
    226     async *foo() {}
    227 //  ^^^^^ keyword.declaration.async
    228 //        ^ keyword.generator.asterisk
    229 
    230     static *foo() {}
    231 //  ^^^^^^ storage.modifier
    232 //         ^ keyword.generator.asterisk
    233 //          ^^^ entity.name.function
    234 
    235     static async foo() {}
    236 //  ^^^^^^ storage.modifier
    237 //         ^^^^^ keyword.declaration.async
    238 
    239     async() {}
    240 //  ^^^^^^^^^^ meta.function
    241 //  ^^^^^ entity.name.function
    242 //       ^^ meta.function.parameters
    243 //       ^ punctuation.section.group.begin
    244 //        ^ punctuation.section.group.end
    245 //          ^^ meta.block
    246 //          ^ punctuation.section.block.begin
    247 //           ^ punctuation.section.block.end
    248 
    249     static async() {}
    250 //  ^^^^^^ storage.modifier
    251 //         ^^^^^ entity.name.function
    252 }
    253 // <- meta.block punctuation.section.block.end
    254 
    255 class Foo extends React.Component {
    256 //                ^^^^^ - entity.other.inherited-class
    257 //                      ^^^^^^^^^ entity.other.inherited-class
    258     constructor()
    259     {}
    260 
    261     [foo.bar](arg) {
    262 //   ^^^ variable.other
    263 //       ^^^ meta.property
    264 //            ^^^ variable.parameter
    265         return this.a;
    266     }
    267 }
    268 
    269 class Foo extends (Foo).Bar {}
    270 //                      ^^^ entity.other.inherited-class
    271 
    272 class Foo extends Bar
    273 //                ^^^ entity.other.inherited-class
    274     .baz {}
    275 //  ^^^^^^^ meta.class
    276 //  ^ punctuation.accessor
    277 //   ^^^ entity.other.inherited-class
    278 
    279 class Foo extends
    280 //        ^^^^^^^ storage.modifier.extends
    281 Bar {}
    282 
    283 class Foo extends getSomeClass() {}
    284 //                ^^^^^^^^^^^^ meta.function-call variable.function - entity.other.inherited-class
    285 
    286     (class extends Bar {});
    287 //         ^^^^^^^ storage.modifier.extends - entity.name.class
    288 
    289     (class extends class {} {});
    290 //   ^^^^^^^^^^^^^^^^^^^^^^^^^ meta.class
    291 //         ^^^^^^^ storage.modifier.extends
    292 //                 ^^^^^^^^ meta.class meta.class
    293 //                 ^^^^^ keyword.declaration.class
    294 
    295 // Better highlighting while typing.
    296 class
    297 class
    298 // <- keyword.declaration.class - entity.name.class
    299 
    300 class{}/**/
    301 //     ^ - meta.class
    302 
    303     @foo class Foo {}
    304 //  ^^^^ meta.annotation
    305 //  ^ punctuation.definition.annotation
    306 //   ^^^ variable.annotation
    307 //       ^^^^^ keyword.declaration.class
    308 
    309     @foo.bar class Foo {}
    310 //  ^^^^^^^^ meta.annotation
    311 //  ^ punctuation.definition.annotation
    312 //   ^^^ variable.other.readwrite - variable.annotation
    313 //       ^^^ variable.annotation
    314 //           ^^^^^ keyword.declaration.class
    315 
    316     @(whatever) class Foo {}
    317 //  ^^^^^^^^^^^ meta.annotation
    318 //  ^ punctuation.definition.annotation
    319 //   ^^^^^^^^^^ meta.group
    320 //              ^^^^^ keyword.declaration.class