Skip to content

Commit e4c54be

Browse files
committed
update TypeScript grammar
1 parent c640a0e commit e4c54be

7 files changed

Lines changed: 1079 additions & 127 deletions

File tree

‎extensions/javascript/syntaxes/JavaScript.tmLanguage.json‎

Lines changed: 269 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"If you want to provide a fix or improvement, please create a pull request against the original repository.",
55
"Once accepted there, we are happy to receive an update request."
66
],
7-
"version": "https://github.com/Microsoft/TypeScript-TmLanguage/commit/32208c2b11569d08a925f56fd69d28b18a5cc308",
7+
"version": "https://github.com/Microsoft/TypeScript-TmLanguage/commit/858d33f03943e4ec040e81cbabbc3f7892157c18",
88
"name": "JavaScript (with React support)",
99
"scopeName": "source.js",
1010
"patterns": [
@@ -285,55 +285,112 @@
285285
]
286286
},
287287
"var-expr": {
288-
"name": "meta.var.expr.js",
289-
"begin": "(?<![_$[:alnum:]])(?:(?<=\\.\\.\\.)|(?<!\\.))(?:(\\bexport)\\s+)?\\b(var|let|const(?!\\s+enum\\b))(?![_$[:alnum:]])(?:(?=\\.\\.\\.)|(?!\\.))",
290-
"beginCaptures": {
291-
"1": {
292-
"name": "keyword.control.export.js"
293-
},
294-
"2": {
295-
"name": "storage.type.js"
296-
}
297-
},
298-
"end": "((?=;|}|(\\s+(of|in)\\s+)|^\\s*$|;|^\\s*abstract\\b|^\\s*async\\b|^\\s*class\\b|^\\s*const\\b|^\\s*declare\\b|^\\s*enum\\b|^\\s*export\\b|^\\s*function\\b|^\\s*import\\b|^\\s*interface\\b|^\\s*let\\b|^\\s*module\\b|^\\s*namespace\\b|^\\s*return\\b|^\\s*type\\b|^\\s*var\\b)|((?<=\\S)(?<!^const|[^\\._$[:alnum:]]const|^let|[^\\._$[:alnum:]]let|^var|[^\\._$[:alnum:]]var)(?=\\s*$)))",
299288
"patterns": [
300289
{
301-
"include": "#destructuring-variable"
302-
},
303-
{
304-
"include": "#var-single-variable"
305-
},
306-
{
307-
"include": "#variable-initializer"
308-
},
309-
{
310-
"include": "#comment"
311-
},
312-
{
313-
"begin": "(,)\\s*(?!\\S)",
290+
"name": "meta.var.expr.js",
291+
"begin": "(?<![_$[:alnum:]])(?:(?<=\\.\\.\\.)|(?<!\\.))(?:(\\bexport)\\s+)?\\b(var|let)(?![_$[:alnum:]])(?:(?=\\.\\.\\.)|(?!\\.))",
314292
"beginCaptures": {
315293
"1": {
316-
"name": "punctuation.separator.comma.js"
294+
"name": "keyword.control.export.js"
295+
},
296+
"2": {
297+
"name": "storage.type.js"
317298
}
318299
},
319-
"end": "(?<!,)(((?==|;|}|(\\s+(of|in)\\s+)|^\\s*$))|((?<=\\S)(?=\\s*$)))",
300+
"end": "((?=;|}|(\\s+(of|in)\\s+)|^\\s*$|;|^\\s*abstract\\b|^\\s*async\\b|^\\s*class\\b|^\\s*const\\b|^\\s*declare\\b|^\\s*enum\\b|^\\s*export\\b|^\\s*function\\b|^\\s*import\\b|^\\s*interface\\b|^\\s*let\\b|^\\s*module\\b|^\\s*namespace\\b|^\\s*return\\b|^\\s*type\\b|^\\s*var\\b)|((?<=\\S)(?<!^let|[^\\._$[:alnum:]]let|^var|[^\\._$[:alnum:]]var)(?=\\s*$)))",
320301
"patterns": [
321-
{
322-
"include": "#comment"
323-
},
324302
{
325303
"include": "#destructuring-variable"
326304
},
327305
{
328306
"include": "#var-single-variable"
329307
},
308+
{
309+
"include": "#variable-initializer"
310+
},
311+
{
312+
"include": "#comment"
313+
},
314+
{
315+
"begin": "(,)\\s*(?!\\S)",
316+
"beginCaptures": {
317+
"1": {
318+
"name": "punctuation.separator.comma.js"
319+
}
320+
},
321+
"end": "(?<!,)(((?==|;|}|(\\s+(of|in)\\s+)|^\\s*$))|((?<=\\S)(?=\\s*$)))",
322+
"patterns": [
323+
{
324+
"include": "#comment"
325+
},
326+
{
327+
"include": "#destructuring-variable"
328+
},
329+
{
330+
"include": "#var-single-variable"
331+
},
332+
{
333+
"include": "#punctuation-comma"
334+
}
335+
]
336+
},
330337
{
331338
"include": "#punctuation-comma"
332339
}
333340
]
334341
},
335342
{
336-
"include": "#punctuation-comma"
343+
"name": "meta.var.expr.js",
344+
"begin": "(?<![_$[:alnum:]])(?:(?<=\\.\\.\\.)|(?<!\\.))(?:(\\bexport)\\s+)?\\b(const(?!\\s+enum\\b))(?![_$[:alnum:]])(?:(?=\\.\\.\\.)|(?!\\.))",
345+
"beginCaptures": {
346+
"1": {
347+
"name": "keyword.control.export.js"
348+
},
349+
"2": {
350+
"name": "storage.type.js"
351+
}
352+
},
353+
"end": "((?=;|}|(\\s+(of|in)\\s+)|^\\s*$|;|^\\s*abstract\\b|^\\s*async\\b|^\\s*class\\b|^\\s*const\\b|^\\s*declare\\b|^\\s*enum\\b|^\\s*export\\b|^\\s*function\\b|^\\s*import\\b|^\\s*interface\\b|^\\s*let\\b|^\\s*module\\b|^\\s*namespace\\b|^\\s*return\\b|^\\s*type\\b|^\\s*var\\b)|((?<=\\S)(?<!^const|[^\\._$[:alnum:]]const)(?=\\s*$)))",
354+
"patterns": [
355+
{
356+
"include": "#destructuring-const"
357+
},
358+
{
359+
"include": "#var-single-const"
360+
},
361+
{
362+
"include": "#variable-initializer"
363+
},
364+
{
365+
"include": "#comment"
366+
},
367+
{
368+
"begin": "(,)\\s*(?!\\S)",
369+
"beginCaptures": {
370+
"1": {
371+
"name": "punctuation.separator.comma.js"
372+
}
373+
},
374+
"end": "(?<!,)(((?==|;|}|(\\s+(of|in)\\s+)|^\\s*$))|((?<=\\S)(?=\\s*$)))",
375+
"patterns": [
376+
{
377+
"include": "#comment"
378+
},
379+
{
380+
"include": "#destructuring-const"
381+
},
382+
{
383+
"include": "#var-single-const"
384+
},
385+
{
386+
"include": "#punctuation-comma"
387+
}
388+
]
389+
},
390+
{
391+
"include": "#punctuation-comma"
392+
}
393+
]
337394
}
338395
]
339396
},
@@ -386,6 +443,40 @@
386443
}
387444
]
388445
},
446+
"var-single-const": {
447+
"patterns": [
448+
{
449+
"name": "meta.var-single-variable.expr.js",
450+
"begin": "(?x)([_$[:alpha:]][_$[:alnum:]]*)(?=\\s*\n# function assignment |\n(=\\s*(\n ((async\\s+)?(\n (function\\s*[(<*]) |\n (function\\s+) |\n ([_$[:alpha:]][_$[:alnum:]]*\\s*=>)\n )) |\n ((async\\s*)?(\n ((<\\s*$)|([\\(]\\s*([\\{\\[]\\s*)?$)) |\n # sure shot arrow functions even if => is on new line\n(\n (<\\s*([_$[:alpha:]]|(\\{([^\\{\\}]|(\\{[^\\{\\}]*\\}))*\\})|(\\(([^\\(\\)]|(\\([^\\(\\)]*\\)))*\\))|(\\[([^\\[\\]]|(\\[[^\\[\\]]*\\]))*\\]))([^=<>]|=[^<]|\\<\\s*([_$[:alpha:]]|(\\{([^\\{\\}]|(\\{[^\\{\\}]*\\}))*\\})|(\\(([^\\(\\)]|(\\([^\\(\\)]*\\)))*\\))|(\\[([^\\[\\]]|(\\[[^\\[\\]]*\\]))*\\]))([^=<>]|=[^<])*\\>)*>\\s*)?\n [(]\\s*\n (\n ([)]\\s*:) | # ():\n ((\\.\\.\\.\\s*)?[_$[:alpha:]][_$[:alnum:]]*\\s*:) # [(]param: | [(]...param:\n )\n) |\n(\n [<]\\s*[_$[:alpha:]][_$[:alnum:]]*\\s+extends\\s*[^=>] # < typeparam extends\n) |\n# arrow function possible to detect only with => on same line\n(\n (<\\s*([_$[:alpha:]]|(\\{([^\\{\\}]|(\\{[^\\{\\}]*\\}))*\\})|(\\(([^\\(\\)]|(\\([^\\(\\)]*\\)))*\\))|(\\[([^\\[\\]]|(\\[[^\\[\\]]*\\]))*\\]))([^=<>]|=[^<]|\\<\\s*([_$[:alpha:]]|(\\{([^\\{\\}]|(\\{[^\\{\\}]*\\}))*\\})|(\\(([^\\(\\)]|(\\([^\\(\\)]*\\)))*\\))|(\\[([^\\[\\]]|(\\[[^\\[\\]]*\\]))*\\]))([^=<>]|=[^<])*\\>)*>\\s*)? # typeparameters\n \\(\\s*(([_$[:alpha:]]|(\\{([^\\{\\}]|(\\{[^\\{\\}]*\\}))*\\})|(\\[([^\\[\\]]|(\\[[^\\[\\]]*\\]))*\\])|(\\.\\.\\.\\s*[_$[:alpha:]]))([^()]|(\\(([^\\(\\)]|(\\([^\\(\\)]*\\)))*\\)))*)?\\) # parameters\n (\\s*:\\s*([^<>\\(\\)]|\\<[^<>]+\\>|\\([^\\(\\)]+\\))+)? # return type\n \\s*=> # arrow operator\n)\n ))\n)) |\n# typeannotation is fn type: < | () | (... | (param: | (param, | (param? | (param= | (param) =>\n(:\\s*(\n (<) |\n ([(]\\s*(\n ([)]) |\n (\\.\\.\\.) |\n ([_$[:alnum:]]+\\s*(\n ([:,?=])|\n ([)]\\s*=>)\n ))\n ))\n)) |\n(:\\s*((<\\s*$)|([\\(]\\s*([\\{\\[]\\s*)?$))) |\n(:\\s*(=>|(\\(([^\\(\\)]|(\\([^\\(\\)]*\\)))*\\))|(<[^<>]*>)|[^<>(),=])+=\\s*(\n ((async\\s+)?(\n (function\\s*[(<*]) |\n (function\\s+) |\n ([_$[:alpha:]][_$[:alnum:]]*\\s*=>)\n )) |\n ((async\\s*)?(\n ((<\\s*$)|([\\(]\\s*([\\{\\[]\\s*)?$)) |\n # sure shot arrow functions even if => is on new line\n(\n (<\\s*([_$[:alpha:]]|(\\{([^\\{\\}]|(\\{[^\\{\\}]*\\}))*\\})|(\\(([^\\(\\)]|(\\([^\\(\\)]*\\)))*\\))|(\\[([^\\[\\]]|(\\[[^\\[\\]]*\\]))*\\]))([^=<>]|=[^<]|\\<\\s*([_$[:alpha:]]|(\\{([^\\{\\}]|(\\{[^\\{\\}]*\\}))*\\})|(\\(([^\\(\\)]|(\\([^\\(\\)]*\\)))*\\))|(\\[([^\\[\\]]|(\\[[^\\[\\]]*\\]))*\\]))([^=<>]|=[^<])*\\>)*>\\s*)?\n [(]\\s*\n (\n ([)]\\s*:) | # ():\n ((\\.\\.\\.\\s*)?[_$[:alpha:]][_$[:alnum:]]*\\s*:) # [(]param: | [(]...param:\n )\n) |\n(\n [<]\\s*[_$[:alpha:]][_$[:alnum:]]*\\s+extends\\s*[^=>] # < typeparam extends\n) |\n# arrow function possible to detect only with => on same line\n(\n (<\\s*([_$[:alpha:]]|(\\{([^\\{\\}]|(\\{[^\\{\\}]*\\}))*\\})|(\\(([^\\(\\)]|(\\([^\\(\\)]*\\)))*\\))|(\\[([^\\[\\]]|(\\[[^\\[\\]]*\\]))*\\]))([^=<>]|=[^<]|\\<\\s*([_$[:alpha:]]|(\\{([^\\{\\}]|(\\{[^\\{\\}]*\\}))*\\})|(\\(([^\\(\\)]|(\\([^\\(\\)]*\\)))*\\))|(\\[([^\\[\\]]|(\\[[^\\[\\]]*\\]))*\\]))([^=<>]|=[^<])*\\>)*>\\s*)? # typeparameters\n \\(\\s*(([_$[:alpha:]]|(\\{([^\\{\\}]|(\\{[^\\{\\}]*\\}))*\\})|(\\[([^\\[\\]]|(\\[[^\\[\\]]*\\]))*\\])|(\\.\\.\\.\\s*[_$[:alpha:]]))([^()]|(\\(([^\\(\\)]|(\\([^\\(\\)]*\\)))*\\)))*)?\\) # parameters\n (\\s*:\\s*([^<>\\(\\)]|\\<[^<>]+\\>|\\([^\\(\\)]+\\))+)? # return type\n \\s*=> # arrow operator\n)\n ))\n)))",
451+
"beginCaptures": {
452+
"1": {
453+
"name": "meta.definition.variable.js variable.other.constant.js entity.name.function.js"
454+
}
455+
},
456+
"end": "(?=$|^|[;,=}]|(\\s+(of|in)\\s+))",
457+
"patterns": [
458+
{
459+
"include": "#var-single-variable-type-annotation"
460+
}
461+
]
462+
},
463+
{
464+
"name": "meta.var-single-variable.expr.js",
465+
"begin": "([_$[:alpha:]][_$[:alnum:]]*)",
466+
"beginCaptures": {
467+
"1": {
468+
"name": "meta.definition.variable.js variable.other.constant.js"
469+
}
470+
},
471+
"end": "(?=$|^|[;,=}]|(\\s+(of|in)\\s+))",
472+
"patterns": [
473+
{
474+
"include": "#var-single-variable-type-annotation"
475+
}
476+
]
477+
}
478+
]
479+
},
389480
"var-single-variable-type-annotation": {
390481
"patterns": [
391482
{
@@ -435,6 +526,42 @@
435526
}
436527
]
437528
},
529+
"destructuring-const": {
530+
"patterns": [
531+
{
532+
"name": "meta.object-binding-pattern-variable.js",
533+
"begin": "(?<!=|:|^of|[^\\._$[:alnum:]]of|^in|[^\\._$[:alnum:]]in)\\s*(?=\\{)",
534+
"end": "(?=$|^|[;,=}]|(\\s+(of|in)\\s+))",
535+
"patterns": [
536+
{
537+
"include": "#object-binding-pattern-const"
538+
},
539+
{
540+
"include": "#type-annotation"
541+
},
542+
{
543+
"include": "#comment"
544+
}
545+
]
546+
},
547+
{
548+
"name": "meta.array-binding-pattern-variable.js",
549+
"begin": "(?<!=|:|^of|[^\\._$[:alnum:]]of|^in|[^\\._$[:alnum:]]in)\\s*(?=\\[)",
550+
"end": "(?=$|^|[;,=}]|(\\s+(of|in)\\s+))",
551+
"patterns": [
552+
{
553+
"include": "#array-binding-pattern-const"
554+
},
555+
{
556+
"include": "#type-annotation"
557+
},
558+
{
559+
"include": "#comment"
560+
}
561+
]
562+
}
563+
]
564+
},
438565
"object-binding-element": {
439566
"patterns": [
440567
{
@@ -466,6 +593,37 @@
466593
}
467594
]
468595
},
596+
"object-binding-element-const": {
597+
"patterns": [
598+
{
599+
"include": "#comment"
600+
},
601+
{
602+
"begin": "(?x)(?=((\\b(?<!\\$)0(x|X)[0-9a-fA-F][0-9a-fA-F_]*\\b(?!\\$))|(\\b(?<!\\$)0(b|B)[01][01_]*\\b(?!\\$))|(\\b(?<!\\$)0(o|O)?[0-7][0-7_]*\\b(?!\\$))|((?<!\\$)(?:\n (?:\\b[0-9][0-9_]*(\\.)[0-9][0-9_]*[eE][+-]?[0-9][0-9_]*\\b)| # 1.1E+3\n (?:\\b[0-9][0-9_]*(\\.)[eE][+-]?[0-9][0-9_]*\\b)| # 1.E+3\n (?:\\B(\\.)[0-9][0-9_]*[eE][+-]?[0-9][0-9_]*\\b)| # .1E+3\n (?:\\b[0-9][0-9_]*[eE][+-]?[0-9][0-9_]*\\b)| # 1E+3\n (?:\\b[0-9][0-9_]*(\\.)[0-9][0-9_]*\\b)| # 1.1\n (?:\\b[0-9][0-9_]*(\\.)\\B)| # 1.\n (?:\\B(\\.)[0-9][0-9_]*\\b)| # .1\n (?:\\b[0-9][0-9_]*\\b(?!\\.)) # 1\n)(?!\\$))|([_$[:alpha:]][_$[:alnum:]]*)|(\\'([^\\'\\\\]|\\\\\\'|\\\\)*\\')|(\\\"([^\\\"\\\\]|\\\\\\\"|\\\\)*\\\")|(\\[([^\\[\\]]|\\[[^\\[\\]]*\\])+\\]))\\s*(:))",
603+
"end": "(?=,|\\})",
604+
"patterns": [
605+
{
606+
"include": "#object-binding-element-propertyName"
607+
},
608+
{
609+
"include": "#binding-element-const"
610+
}
611+
]
612+
},
613+
{
614+
"include": "#object-binding-pattern-const"
615+
},
616+
{
617+
"include": "#destructuring-variable-rest-const"
618+
},
619+
{
620+
"include": "#variable-initializer"
621+
},
622+
{
623+
"include": "#punctuation-comma"
624+
}
625+
]
626+
},
469627
"object-binding-element-propertyName": {
470628
"begin": "(?x)(?=((\\b(?<!\\$)0(x|X)[0-9a-fA-F][0-9a-fA-F_]*\\b(?!\\$))|(\\b(?<!\\$)0(b|B)[01][01_]*\\b(?!\\$))|(\\b(?<!\\$)0(o|O)?[0-7][0-7_]*\\b(?!\\$))|((?<!\\$)(?:\n (?:\\b[0-9][0-9_]*(\\.)[0-9][0-9_]*[eE][+-]?[0-9][0-9_]*\\b)| # 1.1E+3\n (?:\\b[0-9][0-9_]*(\\.)[eE][+-]?[0-9][0-9_]*\\b)| # 1.E+3\n (?:\\B(\\.)[0-9][0-9_]*[eE][+-]?[0-9][0-9_]*\\b)| # .1E+3\n (?:\\b[0-9][0-9_]*[eE][+-]?[0-9][0-9_]*\\b)| # 1E+3\n (?:\\b[0-9][0-9_]*(\\.)[0-9][0-9_]*\\b)| # 1.1\n (?:\\b[0-9][0-9_]*(\\.)\\B)| # 1.\n (?:\\B(\\.)[0-9][0-9_]*\\b)| # .1\n (?:\\b[0-9][0-9_]*\\b(?!\\.)) # 1\n)(?!\\$))|([_$[:alpha:]][_$[:alnum:]]*)|(\\'([^\\'\\\\]|\\\\\\'|\\\\)*\\')|(\\\"([^\\\"\\\\]|\\\\\\\"|\\\\)*\\\")|(\\[([^\\[\\]]|\\[[^\\[\\]]*\\])+\\]))\\s*(:))",
471629
"end": "(:)",
@@ -512,6 +670,28 @@
512670
}
513671
]
514672
},
673+
"binding-element-const": {
674+
"patterns": [
675+
{
676+
"include": "#comment"
677+
},
678+
{
679+
"include": "#string"
680+
},
681+
{
682+
"include": "#object-binding-pattern-const"
683+
},
684+
{
685+
"include": "#array-binding-pattern-const"
686+
},
687+
{
688+
"include": "#destructuring-variable-rest-const"
689+
},
690+
{
691+
"include": "#variable-initializer"
692+
}
693+
]
694+
},
515695
"destructuring-variable-rest": {
516696
"match": "(?:(\\.\\.\\.)\\s*)?([_$[:alpha:]][_$[:alnum:]]*)",
517697
"captures": {
@@ -523,6 +703,17 @@
523703
}
524704
}
525705
},
706+
"destructuring-variable-rest-const": {
707+
"match": "(?:(\\.\\.\\.)\\s*)?([_$[:alpha:]][_$[:alnum:]]*)",
708+
"captures": {
709+
"1": {
710+
"name": "keyword.operator.rest.js"
711+
},
712+
"2": {
713+
"name": "meta.definition.variable.js variable.other.constant.js"
714+
}
715+
}
716+
},
526717
"object-binding-pattern": {
527718
"begin": "(?:(\\.\\.\\.)\\s*)?(\\{)",
528719
"beginCaptures": {
@@ -545,6 +736,28 @@
545736
}
546737
]
547738
},
739+
"object-binding-pattern-const": {
740+
"begin": "(?:(\\.\\.\\.)\\s*)?(\\{)",
741+
"beginCaptures": {
742+
"1": {
743+
"name": "keyword.operator.rest.js"
744+
},
745+
"2": {
746+
"name": "punctuation.definition.binding-pattern.object.js"
747+
}
748+
},
749+
"end": "\\}",
750+
"endCaptures": {
751+
"0": {
752+
"name": "punctuation.definition.binding-pattern.object.js"
753+
}
754+
},
755+
"patterns": [
756+
{
757+
"include": "#object-binding-element-const"
758+
}
759+
]
760+
},
548761
"array-binding-pattern": {
549762
"begin": "(?:(\\.\\.\\.)\\s*)?(\\[)",
550763
"beginCaptures": {
@@ -570,6 +783,31 @@
570783
}
571784
]
572785
},
786+
"array-binding-pattern-const": {
787+
"begin": "(?:(\\.\\.\\.)\\s*)?(\\[)",
788+
"beginCaptures": {
789+
"1": {
790+
"name": "keyword.operator.rest.js"
791+
},
792+
"2": {
793+
"name": "punctuation.definition.binding-pattern.array.js"
794+
}
795+
},
796+
"end": "\\]",
797+
"endCaptures": {
798+
"0": {
799+
"name": "punctuation.definition.binding-pattern.array.js"
800+
}
801+
},
802+
"patterns": [
803+
{
804+
"include": "#binding-element-const"
805+
},
806+
{
807+
"include": "#punctuation-comma"
808+
}
809+
]
810+
},
573811
"parameter-name": {
574812
"patterns": [
575813
{

0 commit comments

Comments
 (0)