Skip to content

Commit 0c1765f

Browse files
committed
Merge remote-tracking branch 'upstream/master'
2 parents 12e05b6 + 10e901a commit 0c1765f

22 files changed

+506
-16
lines changed

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ language: php
33
php:
44
- 7.0
55
- 7.1
6+
- 7.2
67

78
env:
89
- TYPE=UNIT_TEST

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"php": ">=7.0"
77
},
88
"require-dev": {
9-
"phpunit/phpunit": "^5.5"
9+
"phpunit/phpunit": "^6.4"
1010
},
1111
"license": "MIT",
1212
"authors": [

src/Parser.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -961,8 +961,10 @@ private function parsePrimaryExpression($parentNode) {
961961

962962
// anonymous-function-creation-expression
963963
case TokenKind::StaticKeyword:
964-
// handle `static::`, `static(`
965-
if ($this->lookahead([TokenKind::ColonColonToken, TokenKind::OpenParenToken])) {
964+
// handle `static::`, `static(`, `new static;`, `instanceof static`
965+
if (($this->lookahead([TokenKind::ColonColonToken, TokenKind::OpenParenToken])) ||
966+
(!$this->lookahead(TokenKind::FunctionKeyword))
967+
) {
966968
return $this->parseQualifiedName($parentNode);
967969
}
968970
// Could be `static function` anonymous function creation expression, so flow through
@@ -2490,7 +2492,6 @@ private function parseObjectCreationExpression($parentNode) {
24902492
$this->isParsingObjectCreationExpression = true;
24912493
$objectCreationExpression->classTypeDesignator =
24922494
$this->eatOptional1(TokenKind::ClassKeyword) ??
2493-
$this->eatOptional1(TokenKind::StaticKeyword) ??
24942495
$this->parseExpression($objectCreationExpression);
24952496

24962497
$this->isParsingObjectCreationExpression = false;

tests/LexicalGrammarTest.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,22 @@
55
*--------------------------------------------------------------------------------------------*/
66

77
use Microsoft\PhpParser\Token;
8+
use PHPUnit\Framework\Test;
89
use PHPUnit\Framework\TestCase;
10+
use PHPUnit\Framework\TestResult;
11+
use PHPUnit\Framework\BaseTestListener;
12+
use PHPUnit\Framework\AssertionFailedError;
913

1014
class LexicalGrammarTest extends TestCase {
1115
const FILE_PATTERN = __DIR__ . "/cases/lexical/*";
12-
public function run(PHPUnit_Framework_TestResult $result = null) : PHPUnit_Framework_TestResult {
16+
public function run(TestResult $result = null) : TestResult {
1317
if (!isset($GLOBALS["GIT_CHECKOUT_LEXER"])) {
1418
$GLOBALS["GIT_CHECKOUT_LEXER"] = true;
1519
exec("git -C " . dirname(self::FILE_PATTERN) . " checkout *.php.tokens");
1620
}
1721

18-
$result->addListener(new class() extends PHPUnit_Framework_BaseTestListener {
19-
function addFailure(PHPUnit_Framework_Test $test, PHPUnit_Framework_AssertionFailedError $e, $time) {
22+
$result->addListener(new class() extends BaseTestListener {
23+
function addFailure(Test $test, AssertionFailedError $e, $time) {
2024
if (isset($test->expectedTokensFile) && isset($test->tokens)) {
2125
file_put_contents($test->expectedTokensFile, str_replace("\r\n", "\n", $test->tokens));
2226
}

tests/ParserGrammarTest.php

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,21 @@
66

77
use Microsoft\PhpParser\Token;
88
use Microsoft\PhpParser\DiagnosticsProvider;
9+
use PHPUnit\Framework\Test;
910
use PHPUnit\Framework\TestCase;
11+
use PHPUnit\Framework\TestResult;
12+
use PHPUnit\Framework\BaseTestListener;
13+
use PHPUnit\Framework\AssertionFailedError;
1014

1115
class ParserGrammarTest extends TestCase {
12-
public function run(PHPUnit_Framework_TestResult $result = null) : PHPUnit_Framework_TestResult {
16+
public function run(TestResult $result = null) : TestResult {
1317
if (!isset($GLOBALS["GIT_CHECKOUT_PARSER"])) {
1418
$GLOBALS["GIT_CHECKOUT_PARSER"] = true;
1519
exec("git -C " . dirname(self::FILE_PATTERN) . " checkout *.php.tree *.php.diag");
1620
}
1721

18-
$result->addListener(new class() extends PHPUnit_Framework_BaseTestListener {
19-
function addFailure(PHPUnit_Framework_Test $test, PHPUnit_Framework_AssertionFailedError $e, $time) {
22+
$result->addListener(new class() extends BaseTestListener {
23+
function addFailure(Test $test, AssertionFailedError $e, $time) {
2024
if (isset($test->expectedTokensFile) && isset($test->tokens)) {
2125
file_put_contents($test->expectedTokensFile, str_replace("\r\n", "\n", $test->tokens));
2226
}
@@ -59,13 +63,13 @@ public function testOutputTreeClassificationAndLength($testCaseFile, $expectedTo
5963
$tokens = str_replace("\r\n", "\n", json_encode($sourceFileNode, JSON_PRETTY_PRINT));
6064
$diagnostics = str_replace("\r\n", "\n", json_encode(\Microsoft\PhpParser\DiagnosticsProvider::getDiagnostics($sourceFileNode), JSON_PRETTY_PRINT));
6165
$GLOBALS["SHORT_TOKEN_SERIALIZE"] = false;
62-
66+
6367
$this->tokens = $tokens;
6468
$this->diagnostics = $diagnostics;
6569

6670
$tokensOutputStr = "input doc:\r\n$fileContents\r\n\r\ninput: $testCaseFile\r\nexpected: $expectedTokensFile";
6771
$diagnosticsOutputStr = "input doc:\r\n$fileContents\r\n\r\ninput: $testCaseFile\r\nexpected: $expectedDiagnosticsFile";
68-
72+
6973
$this->assertEquals($expectedTokens, $tokens, $tokensOutputStr);
7074
$this->assertEquals($expectedDiagnostics, $diagnostics, $diagnosticsOutputStr);
7175
}

tests/cases/parser/ifStatement1_6.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<?php
2+
3+
if (static::$a instanceof static) {
4+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
[]
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
{
2+
"SourceFileNode": {
3+
"statementList": [
4+
{
5+
"InlineHtml": {
6+
"scriptSectionEndTag": null,
7+
"text": null,
8+
"scriptSectionStartTag": {
9+
"kind": "ScriptSectionStartTag",
10+
"textLength": 6
11+
}
12+
}
13+
},
14+
{
15+
"IfStatementNode": {
16+
"ifKeyword": {
17+
"kind": "IfKeyword",
18+
"textLength": 2
19+
},
20+
"openParen": {
21+
"kind": "OpenParenToken",
22+
"textLength": 1
23+
},
24+
"expression": {
25+
"BinaryExpression": {
26+
"leftOperand": {
27+
"ScopedPropertyAccessExpression": {
28+
"scopeResolutionQualifier": {
29+
"QualifiedName": {
30+
"globalSpecifier": null,
31+
"relativeSpecifier": null,
32+
"nameParts": [
33+
{
34+
"kind": "Name",
35+
"textLength": 6
36+
}
37+
]
38+
}
39+
},
40+
"doubleColon": {
41+
"kind": "ColonColonToken",
42+
"textLength": 2
43+
},
44+
"memberName": {
45+
"Variable": {
46+
"dollar": null,
47+
"name": {
48+
"kind": "VariableName",
49+
"textLength": 2
50+
}
51+
}
52+
}
53+
}
54+
},
55+
"operator": {
56+
"kind": "InstanceOfKeyword",
57+
"textLength": 10
58+
},
59+
"rightOperand": {
60+
"QualifiedName": {
61+
"globalSpecifier": null,
62+
"relativeSpecifier": null,
63+
"nameParts": [
64+
{
65+
"kind": "Name",
66+
"textLength": 6
67+
}
68+
]
69+
}
70+
}
71+
}
72+
},
73+
"closeParen": {
74+
"kind": "CloseParenToken",
75+
"textLength": 1
76+
},
77+
"colon": null,
78+
"statements": {
79+
"CompoundStatementNode": {
80+
"openBrace": {
81+
"kind": "OpenBraceToken",
82+
"textLength": 1
83+
},
84+
"statements": [],
85+
"closeBrace": {
86+
"kind": "CloseBraceToken",
87+
"textLength": 1
88+
}
89+
}
90+
},
91+
"elseIfClauses": [],
92+
"elseClause": null,
93+
"endifKeyword": null,
94+
"semicolon": null
95+
}
96+
}
97+
],
98+
"endOfFileToken": {
99+
"kind": "EndOfFileToken",
100+
"textLength": 0
101+
}
102+
}
103+
}

tests/cases/parser/objectCreationExpression13.php.tree

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,16 @@
3636
"textLength": 3
3737
},
3838
"classTypeDesignator": {
39-
"kind": "StaticKeyword",
40-
"textLength": 6
39+
"QualifiedName": {
40+
"globalSpecifier": null,
41+
"relativeSpecifier": null,
42+
"nameParts": [
43+
{
44+
"kind": "Name",
45+
"textLength": 6
46+
}
47+
]
48+
}
4149
},
4250
"openParen": null,
4351
"argumentExpressionList": null,

tests/cases/parser/objectCreationExpression14.php.tree

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,16 @@
3636
"textLength": 3
3737
},
3838
"classTypeDesignator": {
39-
"kind": "StaticKeyword",
40-
"textLength": 6
39+
"QualifiedName": {
40+
"globalSpecifier": null,
41+
"relativeSpecifier": null,
42+
"nameParts": [
43+
{
44+
"kind": "Name",
45+
"textLength": 6
46+
}
47+
]
48+
}
4149
},
4250
"openParen": {
4351
"kind": "OpenParenToken",

0 commit comments

Comments
 (0)