Skip to content

Commit 0ed9d4e

Browse files
committed
Treat the { in the class body as decl block.
Fixes #379 and #382 But this results in incorrect picking up of object literal in field initializer where object literal starts on new line
1 parent 98ab3ba commit 0ed9d4e

14 files changed

+540
-223
lines changed

TypeScript.YAML-tmLanguage

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -484,6 +484,7 @@ repository:
484484
- include: '#variable-initializer'
485485
- include: '#access-modifier'
486486
- include: '#property-accessor'
487+
- include: '#decl-block'
487488
- include: '#expression'
488489
- include: '#punctuation-comma'
489490
- include: '#punctuation-semicolon'
@@ -572,30 +573,15 @@ repository:
572573
'5': { name: keyword.operator.new.ts } # captures keyword (new)
573574
'6': { name: storage.type.ts } # captures keyword (constructor)
574575
'7': { name: keyword.generator.asterisk.ts } # captures keyword (*)
575-
end: '(?=\}|;|,)|(?<=\})'
576+
end: (?=\}|;|,|$)|(?<=\})
576577
patterns:
577578
- include: '#method-declaration-name'
578579
- include: '#comment'
579580
- include: '#type-parameters'
580581
- include: '#function-parameters'
581582
- include: '#return-type'
582-
- include: '#method-overload-declaration'
583583
- include: '#decl-block'
584584

585-
method-overload-declaration:
586-
begin: (?<!\.|\$)(?:\b(public|private|protected)\s+)?(?:\b(abstract)\s+)?(?:\b(async)\s+)?(?:\b(get|set)\s+)?(?:(?:\b(?:(new)|(constructor))\b(?!\$|:))|(?:(\*)\s*)?(?=((([_$[:alpha:]][_$[:alnum:]]*)|(\'[^']*\')|(\"[^"]*\")|(\[([^\[\]]|\[[^\[\]]*\])+\]))\s*(\??))?\s*[\(\<]))
587-
beginCaptures:
588-
'1': { name: storage.modifier.ts } # captures keyword (public or private or protected)
589-
'2': { name: storage.modifier.ts } # captures keyword (abstract)
590-
'3': { name: storage.modifier.async.ts } # captures keyword (async)
591-
'4': { name: storage.type.property.ts } # captures keyword (get|set)
592-
'5': { name: keyword.operator.new.ts } # captures keyword (new)
593-
'6': { name: storage.type.ts } # captures keyword (constructor)
594-
'7': { name: keyword.generator.asterisk.ts } # captures keyword (*)
595-
end: (?=\(|\<)
596-
patterns:
597-
- include: '#method-declaration-name'
598-
599585
method-declaration-name:
600586
begin: (?=(([_$[:alpha:]][_$[:alnum:]]*)|(\'[^']*\')|(\"[^"]*\")|(\[([^\[\]]|\[[^\[\]]*\])+\]))\s*(\??)\s*[\(\<])
601587
end: (?=\(|\<)
@@ -621,7 +607,7 @@ repository:
621607
- include: '#type-parameters'
622608
- include: '#function-parameters'
623609
- include: '#return-type'
624-
- include: '#method-overload-declaration'
610+
- include: '#object-literal-method-overload-declaration'
625611
- include: '#decl-block'
626612

627613
object-literal-method-overload-declaration:

TypeScript.tmLanguage

Lines changed: 6 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1545,6 +1545,10 @@
15451545
<key>include</key>
15461546
<string>#property-accessor</string>
15471547
</dict>
1548+
<dict>
1549+
<key>include</key>
1550+
<string>#decl-block</string>
1551+
</dict>
15481552
<dict>
15491553
<key>include</key>
15501554
<string>#expression</string>
@@ -1785,7 +1789,7 @@
17851789
</dict>
17861790
</dict>
17871791
<key>end</key>
1788-
<string>(?=\}|;|,)|(?&lt;=\})</string>
1792+
<string>(?=\}|;|,|$)|(?&lt;=\})</string>
17891793
<key>patterns</key>
17901794
<array>
17911795
<dict>
@@ -1808,68 +1812,12 @@
18081812
<key>include</key>
18091813
<string>#return-type</string>
18101814
</dict>
1811-
<dict>
1812-
<key>include</key>
1813-
<string>#method-overload-declaration</string>
1814-
</dict>
18151815
<dict>
18161816
<key>include</key>
18171817
<string>#decl-block</string>
18181818
</dict>
18191819
</array>
18201820
</dict>
1821-
<key>method-overload-declaration</key>
1822-
<dict>
1823-
<key>begin</key>
1824-
<string>(?&lt;!\.|\$)(?:\b(public|private|protected)\s+)?(?:\b(abstract)\s+)?(?:\b(async)\s+)?(?:\b(get|set)\s+)?(?:(?:\b(?:(new)|(constructor))\b(?!\$|:))|(?:(\*)\s*)?(?=((([_$[:alpha:]][_$[:alnum:]]*)|(\'[^']*\')|(\"[^"]*\")|(\[([^\[\]]|\[[^\[\]]*\])+\]))\s*(\??))?\s*[\(\&lt;]))</string>
1825-
<key>beginCaptures</key>
1826-
<dict>
1827-
<key>1</key>
1828-
<dict>
1829-
<key>name</key>
1830-
<string>storage.modifier.ts</string>
1831-
</dict>
1832-
<key>2</key>
1833-
<dict>
1834-
<key>name</key>
1835-
<string>storage.modifier.ts</string>
1836-
</dict>
1837-
<key>3</key>
1838-
<dict>
1839-
<key>name</key>
1840-
<string>storage.modifier.async.ts</string>
1841-
</dict>
1842-
<key>4</key>
1843-
<dict>
1844-
<key>name</key>
1845-
<string>storage.type.property.ts</string>
1846-
</dict>
1847-
<key>5</key>
1848-
<dict>
1849-
<key>name</key>
1850-
<string>keyword.operator.new.ts</string>
1851-
</dict>
1852-
<key>6</key>
1853-
<dict>
1854-
<key>name</key>
1855-
<string>storage.type.ts</string>
1856-
</dict>
1857-
<key>7</key>
1858-
<dict>
1859-
<key>name</key>
1860-
<string>keyword.generator.asterisk.ts</string>
1861-
</dict>
1862-
</dict>
1863-
<key>end</key>
1864-
<string>(?=\(|\&lt;)</string>
1865-
<key>patterns</key>
1866-
<array>
1867-
<dict>
1868-
<key>include</key>
1869-
<string>#method-declaration-name</string>
1870-
</dict>
1871-
</array>
1872-
</dict>
18731821
<key>method-declaration-name</key>
18741822
<dict>
18751823
<key>begin</key>
@@ -1950,7 +1898,7 @@
19501898
</dict>
19511899
<dict>
19521900
<key>include</key>
1953-
<string>#method-overload-declaration</string>
1901+
<string>#object-literal-method-overload-declaration</string>
19541902
</dict>
19551903
<dict>
19561904
<key>include</key>

TypeScriptReact.tmLanguage

Lines changed: 6 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1549,6 +1549,10 @@
15491549
<key>include</key>
15501550
<string>#property-accessor</string>
15511551
</dict>
1552+
<dict>
1553+
<key>include</key>
1554+
<string>#decl-block</string>
1555+
</dict>
15521556
<dict>
15531557
<key>include</key>
15541558
<string>#expression</string>
@@ -1789,7 +1793,7 @@
17891793
</dict>
17901794
</dict>
17911795
<key>end</key>
1792-
<string>(?=\}|;|,)|(?&lt;=\})</string>
1796+
<string>(?=\}|;|,|$)|(?&lt;=\})</string>
17931797
<key>patterns</key>
17941798
<array>
17951799
<dict>
@@ -1812,68 +1816,12 @@
18121816
<key>include</key>
18131817
<string>#return-type</string>
18141818
</dict>
1815-
<dict>
1816-
<key>include</key>
1817-
<string>#method-overload-declaration</string>
1818-
</dict>
18191819
<dict>
18201820
<key>include</key>
18211821
<string>#decl-block</string>
18221822
</dict>
18231823
</array>
18241824
</dict>
1825-
<key>method-overload-declaration</key>
1826-
<dict>
1827-
<key>begin</key>
1828-
<string>(?&lt;!\.|\$)(?:\b(public|private|protected)\s+)?(?:\b(abstract)\s+)?(?:\b(async)\s+)?(?:\b(get|set)\s+)?(?:(?:\b(?:(new)|(constructor))\b(?!\$|:))|(?:(\*)\s*)?(?=((([_$[:alpha:]][_$[:alnum:]]*)|(\'[^']*\')|(\"[^"]*\")|(\[([^\[\]]|\[[^\[\]]*\])+\]))\s*(\??))?\s*[\(\&lt;]))</string>
1829-
<key>beginCaptures</key>
1830-
<dict>
1831-
<key>1</key>
1832-
<dict>
1833-
<key>name</key>
1834-
<string>storage.modifier.tsx</string>
1835-
</dict>
1836-
<key>2</key>
1837-
<dict>
1838-
<key>name</key>
1839-
<string>storage.modifier.tsx</string>
1840-
</dict>
1841-
<key>3</key>
1842-
<dict>
1843-
<key>name</key>
1844-
<string>storage.modifier.async.tsx</string>
1845-
</dict>
1846-
<key>4</key>
1847-
<dict>
1848-
<key>name</key>
1849-
<string>storage.type.property.tsx</string>
1850-
</dict>
1851-
<key>5</key>
1852-
<dict>
1853-
<key>name</key>
1854-
<string>keyword.operator.new.tsx</string>
1855-
</dict>
1856-
<key>6</key>
1857-
<dict>
1858-
<key>name</key>
1859-
<string>storage.type.tsx</string>
1860-
</dict>
1861-
<key>7</key>
1862-
<dict>
1863-
<key>name</key>
1864-
<string>keyword.generator.asterisk.tsx</string>
1865-
</dict>
1866-
</dict>
1867-
<key>end</key>
1868-
<string>(?=\(|\&lt;)</string>
1869-
<key>patterns</key>
1870-
<array>
1871-
<dict>
1872-
<key>include</key>
1873-
<string>#method-declaration-name</string>
1874-
</dict>
1875-
</array>
1876-
</dict>
18771825
<key>method-declaration-name</key>
18781826
<dict>
18791827
<key>begin</key>
@@ -1954,7 +1902,7 @@
19541902
</dict>
19551903
<dict>
19561904
<key>include</key>
1957-
<string>#method-overload-declaration</string>
1905+
<string>#object-literal-method-overload-declaration</string>
19581906
</dict>
19591907
<dict>
19601908
<key>include</key>

tests/baselines/FunctionMethodOverloads.baseline.txt

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -635,7 +635,7 @@ Grammar: TypeScript.tmLanguage
635635
source.ts meta.class.ts meta.method.declaration.ts meta.return.type.ts meta.type.function.return.ts support.type.primitive.ts
636636
> public testMethodOverload(p: string)
637637
^^^^
638-
source.ts meta.class.ts meta.method.declaration.ts
638+
source.ts meta.class.ts
639639
^^^^^^
640640
source.ts meta.class.ts meta.method.declaration.ts storage.modifier.ts
641641
^
@@ -656,7 +656,7 @@ Grammar: TypeScript.tmLanguage
656656
source.ts meta.class.ts meta.method.declaration.ts meta.parameters.ts punctuation.definition.parameters.end.ts
657657
> public testMethodOverload(p: string [])
658658
^^^^
659-
source.ts meta.class.ts meta.method.declaration.ts
659+
source.ts meta.class.ts
660660
^^^^^^
661661
source.ts meta.class.ts meta.method.declaration.ts storage.modifier.ts
662662
^
@@ -683,7 +683,7 @@ Grammar: TypeScript.tmLanguage
683683
source.ts meta.class.ts meta.method.declaration.ts meta.parameters.ts punctuation.definition.parameters.end.ts
684684
> public testMethodOverload(p: {})
685685
^^^^
686-
source.ts meta.class.ts meta.method.declaration.ts
686+
source.ts meta.class.ts
687687
^^^^^^
688688
source.ts meta.class.ts meta.method.declaration.ts storage.modifier.ts
689689
^
@@ -706,7 +706,7 @@ Grammar: TypeScript.tmLanguage
706706
source.ts meta.class.ts meta.method.declaration.ts meta.parameters.ts punctuation.definition.parameters.end.ts
707707
> public testMethodOverload(p: {a: A, b:B} | string [])
708708
^^^^
709-
source.ts meta.class.ts meta.method.declaration.ts
709+
source.ts meta.class.ts
710710
^^^^^^
711711
source.ts meta.class.ts meta.method.declaration.ts storage.modifier.ts
712712
^
@@ -761,7 +761,7 @@ Grammar: TypeScript.tmLanguage
761761
source.ts meta.class.ts meta.method.declaration.ts meta.parameters.ts punctuation.definition.parameters.end.ts
762762
> public testMethodOverload(p: any): new() => any {
763763
^^^^
764-
source.ts meta.class.ts meta.method.declaration.ts
764+
source.ts meta.class.ts
765765
^^^^^^
766766
source.ts meta.class.ts meta.method.declaration.ts storage.modifier.ts
767767
^
@@ -1115,7 +1115,7 @@ Grammar: TypeScript.tmLanguage
11151115
source.ts meta.class.ts meta.method.declaration.ts meta.return.type.ts support.type.primitive.ts
11161116
> bar(): string;
11171117
^^^^
1118-
source.ts meta.class.ts meta.method.declaration.ts
1118+
source.ts meta.class.ts
11191119
^^^
11201120
source.ts meta.class.ts meta.method.declaration.ts meta.definition.method.ts entity.name.function.ts
11211121
^
@@ -1166,7 +1166,7 @@ Grammar: TypeScript.tmLanguage
11661166
source.ts meta.class.ts meta.method.declaration.ts meta.parameters.ts punctuation.definition.parameters.end.ts
11671167
> abstract bar()
11681168
^^^^
1169-
source.ts meta.class.ts meta.method.declaration.ts
1169+
source.ts meta.class.ts
11701170
^^^^^^^^
11711171
source.ts meta.class.ts meta.method.declaration.ts storage.modifier.ts
11721172
^

tests/baselines/Issue156.baseline.txt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,21 +60,21 @@ Grammar: TypeScript.tmLanguage
6060
source.ts meta.class.ts meta.method.declaration.ts meta.parameters.ts meta.type.annotation.ts support.type.primitive.ts
6161
^
6262
source.ts meta.class.ts meta.method.declaration.ts meta.parameters.ts punctuation.definition.parameters.end.ts
63-
^^
63+
^
6464
source.ts meta.class.ts meta.method.declaration.ts
6565
> {
6666
^
67-
source.ts meta.class.ts meta.method.declaration.ts
67+
source.ts meta.class.ts
6868
^
69-
source.ts meta.class.ts meta.method.declaration.ts meta.block.ts punctuation.definition.block.ts
69+
source.ts meta.class.ts meta.block.ts punctuation.definition.block.ts
7070
>
7171
^^^^^^^^^
72-
source.ts meta.class.ts meta.method.declaration.ts meta.block.ts
72+
source.ts meta.class.ts meta.block.ts
7373
> }
7474
^
75-
source.ts meta.class.ts meta.method.declaration.ts meta.block.ts
75+
source.ts meta.class.ts meta.block.ts
7676
^
77-
source.ts meta.class.ts meta.method.declaration.ts meta.block.ts punctuation.definition.block.ts
77+
source.ts meta.class.ts meta.block.ts punctuation.definition.block.ts
7878
>}
7979
^
8080
source.ts meta.class.ts punctuation.definition.block.ts

tests/baselines/Issue156.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,6 @@ Grammar: TypeScript.tmLanguage
2727
> {
2828
>
2929
^^^^^^^^^
30-
[4, 9]: source.ts meta.class.ts meta.method.declaration.ts meta.block.ts
30+
[4, 9]: source.ts meta.class.ts meta.block.ts
3131
> }
3232
>}

0 commit comments

Comments
 (0)