@@ -765,6 +765,34 @@ describe 'PHP grammar', ->
765765 expect (lines[1 ][2 ]).toEqual value : ' ?' , scopes : [" source.php" , " meta.class.php" , " meta.class.body.php" , " keyword.operator.nullable-type.php" ]
766766 expect (lines[1 ][4 ]).toEqual value : ' string' , scopes : [" source.php" , " meta.class.php" , " meta.class.body.php" , " keyword.other.type.php" ]
767767
768+ it ' tokenizes union types' , ->
769+ lines = grammar .tokenizeLines '''
770+ class A {
771+ public int|string $id;
772+ }
773+ '''
774+
775+ expect (lines[1 ][1 ]).toEqual value : ' public' , scopes : [' source.php' , ' meta.class.php' , ' meta.class.body.php' , ' storage.modifier.php' ]
776+ expect (lines[1 ][3 ]).toEqual value : ' int' , scopes : [' source.php' , ' meta.class.php' , ' meta.class.body.php' , ' keyword.other.type.php' ]
777+ expect (lines[1 ][4 ]).toEqual value : ' |' , scopes : [' source.php' , ' meta.class.php' , ' meta.class.body.php' , ' punctuation.separator.delimiter.php' ]
778+ expect (lines[1 ][5 ]).toEqual value : ' string' , scopes : [' source.php' , ' meta.class.php' , ' meta.class.body.php' , ' keyword.other.type.php' ]
779+ expect (lines[1 ][7 ]).toEqual value : ' $' , scopes : [' source.php' , ' meta.class.php' , ' meta.class.body.php' , ' variable.other.php' , ' punctuation.definition.variable.php' ]
780+ expect (lines[1 ][8 ]).toEqual value : ' id' , scopes : [' source.php' , ' meta.class.php' , ' meta.class.body.php' , ' variable.other.php' ]
781+
782+ it ' tokenizes intersection types' , ->
783+ lines = grammar .tokenizeLines '''
784+ class A {
785+ public FooInterface & BarInterface $foobar;
786+ }
787+ '''
788+
789+ expect (lines[1 ][1 ]).toEqual value : ' public' , scopes : [' source.php' , ' meta.class.php' , ' meta.class.body.php' , ' storage.modifier.php' ]
790+ expect (lines[1 ][3 ]).toEqual value : ' FooInterface' , scopes : [' source.php' , ' meta.class.php' , ' meta.class.body.php' , ' support.class.php' ]
791+ expect (lines[1 ][5 ]).toEqual value : ' &' , scopes : [' source.php' , ' meta.class.php' , ' meta.class.body.php' , ' punctuation.separator.delimiter.php' ]
792+ expect (lines[1 ][7 ]).toEqual value : ' BarInterface' , scopes : [' source.php' , ' meta.class.php' , ' meta.class.body.php' , ' support.class.php' ]
793+ expect (lines[1 ][9 ]).toEqual value : ' $' , scopes : [' source.php' , ' meta.class.php' , ' meta.class.body.php' , ' variable.other.php' , ' punctuation.definition.variable.php' ]
794+ expect (lines[1 ][10 ]).toEqual value : ' foobar' , scopes : [' source.php' , ' meta.class.php' , ' meta.class.body.php' , ' variable.other.php' ]
795+
768796 it ' tokenizes 2 modifiers correctly' , ->
769797 lines = grammar .tokenizeLines '''
770798 class Foo {
@@ -1293,6 +1321,18 @@ describe 'PHP grammar', ->
12931321 expect (tokens[14 ]).toEqual value : ' a' , scopes : [' source.php' , ' meta.function.php' , ' meta.function.parameters.php' , ' meta.function.parameter.typehinted.php' , ' variable.other.php' ]
12941322 expect (tokens[15 ]).toEqual value : ' )' , scopes : [' source.php' , ' meta.function.php' , ' punctuation.definition.parameters.end.bracket.round.php' ]
12951323
1324+ it ' tokenizes intersection types in function parameters' , ->
1325+ {tokens } = grammar .tokenizeLine ' function test(FooInterface&BarInterface $foobar){}'
1326+
1327+ expect (tokens[0 ]).toEqual value : ' function' , scopes : [' source.php' , ' meta.function.php' , ' storage.type.function.php' ]
1328+ expect (tokens[2 ]).toEqual value : ' test' , scopes : [' source.php' , ' meta.function.php' , ' entity.name.function.php' ]
1329+ expect (tokens[3 ]).toEqual value : ' (' , scopes : [' source.php' , ' meta.function.php' , ' punctuation.definition.parameters.begin.bracket.round.php' ]
1330+ expect (tokens[4 ]).toEqual value : ' FooInterface' , scopes : [' source.php' , ' meta.function.php' , ' meta.function.parameters.php' , ' meta.function.parameter.typehinted.php' , ' support.class.php' ]
1331+ expect (tokens[5 ]).toEqual value : ' &' , scopes : [' source.php' , ' meta.function.php' , ' meta.function.parameters.php' , ' meta.function.parameter.typehinted.php' , ' punctuation.separator.delimiter.php' ]
1332+ expect (tokens[6 ]).toEqual value : ' BarInterface' , scopes : [' source.php' , ' meta.function.php' , ' meta.function.parameters.php' , ' meta.function.parameter.typehinted.php' , ' support.class.php' ]
1333+ expect (tokens[8 ]).toEqual value : ' $' , scopes : [' source.php' , ' meta.function.php' , ' meta.function.parameters.php' , ' meta.function.parameter.typehinted.php' , ' variable.other.php' , ' punctuation.definition.variable.php' ]
1334+ expect (tokens[9 ]).toEqual value : ' foobar' , scopes : [' source.php' , ' meta.function.php' , ' meta.function.parameters.php' , ' meta.function.parameter.typehinted.php' , ' variable.other.php' ]
1335+
12961336 it ' tokenizes trailing comma in function parameters' , ->
12971337 {tokens } = grammar .tokenizeLine ' function abc($a, $b,){}'
12981338
@@ -1348,6 +1388,16 @@ describe 'PHP grammar', ->
13481388 expect (tokens[12 ]).toEqual value : ' ' , scopes : [' source.php' , ' meta.function.php' ]
13491389 expect (tokens[13 ]).toEqual value : ' null' , scopes : [' source.php' , ' meta.function.php' , ' keyword.other.type.php' ]
13501390
1391+ it ' tokenizes intersection return types' , ->
1392+ {tokens } = grammar .tokenizeLine ' function foobar() : FooInterface & BarInterface {}'
1393+
1394+ expect (tokens[0 ]).toEqual value : ' function' , scopes : [' source.php' , ' meta.function.php' , ' storage.type.function.php' ]
1395+ expect (tokens[2 ]).toEqual value : ' foobar' , scopes : [' source.php' , ' meta.function.php' , ' entity.name.function.php' ]
1396+ expect (tokens[6 ]).toEqual value : ' :' , scopes : [' source.php' , ' meta.function.php' , ' keyword.operator.return-value.php' ]
1397+ expect (tokens[8 ]).toEqual value : ' FooInterface' , scopes : [' source.php' , ' meta.function.php' , ' support.class.php' ]
1398+ expect (tokens[10 ]).toEqual value : ' &' , scopes : [' source.php' , ' meta.function.php' , ' punctuation.separator.delimiter.php' ]
1399+ expect (tokens[12 ]).toEqual value : ' BarInterface' , scopes : [' source.php' , ' meta.function.php' , ' support.class.php' ]
1400+
13511401 it ' tokenizes function names with characters other than letters or numbers' , ->
13521402 # Char 160 is hex 0xA0, which is between 0x7F and 0xFF, making it a valid PHP identifier
13531403 functionName = " foo#{ String .fromCharCode (160 )} bar"
@@ -2475,6 +2525,17 @@ describe 'PHP grammar', ->
24752525 expect (lines[1 ][5 ]).toEqual value : ' Class' , scopes : [' source.php' , ' comment.block.documentation.phpdoc.php' , ' meta.other.type.phpdoc.php' , ' support.class.php' ]
24762526 expect (lines[1 ][6 ]).toEqual value : ' description' , scopes : [' source.php' , ' comment.block.documentation.phpdoc.php' ]
24772527
2528+ it ' should tokenize intersection types' , ->
2529+ lines = grammar .tokenizeLines '''
2530+ /**
2531+ *@param Foo&Bar description
2532+ '''
2533+
2534+ expect (lines[1 ][1 ]).toEqual value : ' @param' , scopes : [' source.php' , ' comment.block.documentation.phpdoc.php' , ' keyword.other.phpdoc.php' ]
2535+ expect (lines[1 ][3 ]).toEqual value : ' Foo' , scopes : [' source.php' , ' comment.block.documentation.phpdoc.php' , ' meta.other.type.phpdoc.php' , ' support.class.php' ]
2536+ expect (lines[1 ][4 ]).toEqual value : ' &' , scopes : [' source.php' , ' comment.block.documentation.phpdoc.php' , ' meta.other.type.phpdoc.php' , ' punctuation.separator.delimiter.php' ]
2537+ expect (lines[1 ][5 ]).toEqual value : ' Bar' , scopes : [' source.php' , ' comment.block.documentation.phpdoc.php' , ' meta.other.type.phpdoc.php' , ' support.class.php' ]
2538+
24782539 it ' should tokenize multiple namespaced types' , ->
24792540 lines = grammar .tokenizeLines '''
24802541 /**
@@ -2545,6 +2606,19 @@ describe 'PHP grammar', ->
25452606 expect (lines[1 ][7 ]).toEqual value : ' )' , scopes : [' source.php' , ' comment.block.documentation.phpdoc.php' , ' meta.other.type.phpdoc.php' , ' punctuation.definition.type.end.bracket.round.phpdoc.php' ]
25462607 expect (lines[1 ][8 ]).toEqual value : ' []' , scopes : [' source.php' , ' comment.block.documentation.phpdoc.php' , ' meta.other.type.phpdoc.php' , ' keyword.other.array.phpdoc.php' ]
25472608
2609+ lines = grammar .tokenizeLines '''
2610+ /**
2611+ *@param (Foo&Bar)[] description
2612+ '''
2613+
2614+ expect (lines[1 ][1 ]).toEqual value : ' @param' , scopes : [' source.php' , ' comment.block.documentation.phpdoc.php' , ' keyword.other.phpdoc.php' ]
2615+ expect (lines[1 ][3 ]).toEqual value : ' (' , scopes : [' source.php' , ' comment.block.documentation.phpdoc.php' , ' meta.other.type.phpdoc.php' , ' punctuation.definition.type.begin.bracket.round.phpdoc.php' ]
2616+ expect (lines[1 ][4 ]).toEqual value : ' Foo' , scopes : [' source.php' , ' comment.block.documentation.phpdoc.php' , ' meta.other.type.phpdoc.php' , ' support.class.php' ]
2617+ expect (lines[1 ][5 ]).toEqual value : ' &' , scopes : [' source.php' , ' comment.block.documentation.phpdoc.php' , ' meta.other.type.phpdoc.php' , ' punctuation.separator.delimiter.php' ]
2618+ expect (lines[1 ][6 ]).toEqual value : ' Bar' , scopes : [' source.php' , ' comment.block.documentation.phpdoc.php' , ' meta.other.type.phpdoc.php' , ' support.class.php' ]
2619+ expect (lines[1 ][7 ]).toEqual value : ' )' , scopes : [' source.php' , ' comment.block.documentation.phpdoc.php' , ' meta.other.type.phpdoc.php' , ' punctuation.definition.type.end.bracket.round.phpdoc.php' ]
2620+ expect (lines[1 ][8 ]).toEqual value : ' []' , scopes : [' source.php' , ' comment.block.documentation.phpdoc.php' , ' meta.other.type.phpdoc.php' , ' keyword.other.array.phpdoc.php' ]
2621+
25482622 lines = grammar .tokenizeLines '''
25492623 /**
25502624 *@param ((Test|int)[]|Test\\ Type[]|string[]|resource)[] description
0 commit comments