mirror of
https://github.com/nikic/PHP-Parser.git
synced 2025-01-17 07:08:14 +01:00
Remove Stmt\Throw
This was a backwards-compatibility shim for Expr\Throw.
This commit is contained in:
parent
a1ccf57727
commit
b4183c2b09
@ -386,16 +386,7 @@ non_empty_statement:
|
|||||||
$$ = Stmt\InlineHTML[$1];
|
$$ = Stmt\InlineHTML[$1];
|
||||||
$$->setAttribute('hasLeadingNewline', $this->inlineHtmlHasLeadingNewline(#1));
|
$$->setAttribute('hasLeadingNewline', $this->inlineHtmlHasLeadingNewline(#1));
|
||||||
}
|
}
|
||||||
| expr semi {
|
| expr semi { $$ = Stmt\Expression[$1]; }
|
||||||
$e = $1;
|
|
||||||
if ($e instanceof Expr\Throw_) {
|
|
||||||
// For backwards-compatibility reasons, convert throw in statement position into
|
|
||||||
// Stmt\Throw_ rather than Stmt\Expression(Expr\Throw_).
|
|
||||||
$$ = Stmt\Throw_[$e->expr];
|
|
||||||
} else {
|
|
||||||
$$ = Stmt\Expression[$e];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
| T_UNSET '(' variables_list ')' semi { $$ = Stmt\Unset_[$3]; }
|
| T_UNSET '(' variables_list ')' semi { $$ = Stmt\Unset_[$3]; }
|
||||||
| T_FOREACH '(' expr T_AS foreach_variable ')' foreach_statement
|
| T_FOREACH '(' expr T_AS foreach_variable ')' foreach_statement
|
||||||
{ $$ = Stmt\Foreach_[$3, $5[0], ['keyVar' => null, 'byRef' => $5[1], 'stmts' => $7]]; }
|
{ $$ = Stmt\Foreach_[$3, $5[0], ['keyVar' => null, 'byRef' => $5[1], 'stmts' => $7]]; }
|
||||||
|
@ -1,29 +0,0 @@
|
|||||||
<?php declare(strict_types=1);
|
|
||||||
|
|
||||||
namespace PhpParser\Node\Stmt;
|
|
||||||
|
|
||||||
use PhpParser\Node;
|
|
||||||
|
|
||||||
class Throw_ extends Node\Stmt {
|
|
||||||
/** @var Node\Expr Expression */
|
|
||||||
public Node\Expr $expr;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Constructs a legacy throw statement node.
|
|
||||||
*
|
|
||||||
* @param Node\Expr $expr Expression
|
|
||||||
* @param array<string, mixed> $attributes Additional attributes
|
|
||||||
*/
|
|
||||||
public function __construct(Node\Expr $expr, array $attributes = []) {
|
|
||||||
$this->attributes = $attributes;
|
|
||||||
$this->expr = $expr;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getSubNodeNames(): array {
|
|
||||||
return ['expr'];
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getType(): string {
|
|
||||||
return 'Stmt_Throw';
|
|
||||||
}
|
|
||||||
}
|
|
@ -1473,16 +1473,7 @@ class Php7 extends \PhpParser\ParserAbstract
|
|||||||
|
|
||||||
},
|
},
|
||||||
172 => function ($stackPos) {
|
172 => function ($stackPos) {
|
||||||
|
$this->semValue = new Stmt\Expression($this->semStack[$stackPos-(2-1)], $this->getAttributes($this->tokenStartStack[$stackPos-(2-1)], $this->tokenEndStack[$stackPos]));
|
||||||
$e = $this->semStack[$stackPos-(2-1)];
|
|
||||||
if ($e instanceof Expr\Throw_) {
|
|
||||||
// For backwards-compatibility reasons, convert throw in statement position into
|
|
||||||
// Stmt\Throw_ rather than Stmt\Expression(Expr\Throw_).
|
|
||||||
$this->semValue = new Stmt\Throw_($e->expr, $this->getAttributes($this->tokenStartStack[$stackPos-(2-1)], $this->tokenEndStack[$stackPos]));
|
|
||||||
} else {
|
|
||||||
$this->semValue = new Stmt\Expression($e, $this->getAttributes($this->tokenStartStack[$stackPos-(2-1)], $this->tokenEndStack[$stackPos]));
|
|
||||||
}
|
|
||||||
|
|
||||||
},
|
},
|
||||||
173 => function ($stackPos) {
|
173 => function ($stackPos) {
|
||||||
$this->semValue = new Stmt\Unset_($this->semStack[$stackPos-(5-3)], $this->getAttributes($this->tokenStartStack[$stackPos-(5-1)], $this->tokenEndStack[$stackPos]));
|
$this->semValue = new Stmt\Unset_($this->semStack[$stackPos-(5-3)], $this->getAttributes($this->tokenStartStack[$stackPos-(5-1)], $this->tokenEndStack[$stackPos]));
|
||||||
|
@ -1491,16 +1491,7 @@ class Php8 extends \PhpParser\ParserAbstract
|
|||||||
|
|
||||||
},
|
},
|
||||||
172 => function ($stackPos) {
|
172 => function ($stackPos) {
|
||||||
|
$this->semValue = new Stmt\Expression($this->semStack[$stackPos-(2-1)], $this->getAttributes($this->tokenStartStack[$stackPos-(2-1)], $this->tokenEndStack[$stackPos]));
|
||||||
$e = $this->semStack[$stackPos-(2-1)];
|
|
||||||
if ($e instanceof Expr\Throw_) {
|
|
||||||
// For backwards-compatibility reasons, convert throw in statement position into
|
|
||||||
// Stmt\Throw_ rather than Stmt\Expression(Expr\Throw_).
|
|
||||||
$this->semValue = new Stmt\Throw_($e->expr, $this->getAttributes($this->tokenStartStack[$stackPos-(2-1)], $this->tokenEndStack[$stackPos]));
|
|
||||||
} else {
|
|
||||||
$this->semValue = new Stmt\Expression($e, $this->getAttributes($this->tokenStartStack[$stackPos-(2-1)], $this->tokenEndStack[$stackPos]));
|
|
||||||
}
|
|
||||||
|
|
||||||
},
|
},
|
||||||
173 => function ($stackPos) {
|
173 => function ($stackPos) {
|
||||||
$this->semValue = new Stmt\Unset_($this->semStack[$stackPos-(5-3)], $this->getAttributes($this->tokenStartStack[$stackPos-(5-1)], $this->tokenEndStack[$stackPos]));
|
$this->semValue = new Stmt\Unset_($this->semStack[$stackPos-(5-3)], $this->getAttributes($this->tokenStartStack[$stackPos-(5-1)], $this->tokenEndStack[$stackPos]));
|
||||||
|
@ -960,10 +960,6 @@ class Standard extends PrettyPrinterAbstract {
|
|||||||
return 'return' . (null !== $node->expr ? ' ' . $this->p($node->expr) : '') . ';';
|
return 'return' . (null !== $node->expr ? ' ' . $this->p($node->expr) : '') . ';';
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function pStmt_Throw(Stmt\Throw_ $node): string {
|
|
||||||
return 'throw ' . $this->p($node->expr) . ';';
|
|
||||||
}
|
|
||||||
|
|
||||||
protected function pStmt_Label(Stmt\Label $node): string {
|
protected function pStmt_Label(Stmt\Label $node): string {
|
||||||
return $node->name . ':';
|
return $node->name . ':';
|
||||||
}
|
}
|
||||||
|
@ -525,9 +525,11 @@ array(
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
12: Stmt_Throw(
|
12: Stmt_Expression(
|
||||||
expr: Expr_Variable(
|
expr: Expr_Throw(
|
||||||
name: x
|
expr: Expr_Variable(
|
||||||
|
name: x
|
||||||
|
)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
13: Stmt_Goto(
|
13: Stmt_Goto(
|
||||||
|
@ -41,9 +41,11 @@ array(
|
|||||||
name: a
|
name: a
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
6: Stmt_Throw(
|
6: Stmt_Expression(
|
||||||
expr: Expr_Variable(
|
expr: Expr_Throw(
|
||||||
name: e
|
expr: Expr_Variable(
|
||||||
|
name: e
|
||||||
|
)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
7: Stmt_Label(
|
7: Stmt_Label(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user