mirror of
https://github.com/nikic/PHP-Parser.git
synced 2025-06-18 05:45:46 +02:00
Compare commits
8 Commits
Author | SHA1 | Date | |
---|---|---|---|
f59bbe44bf | |||
2e11deec46 | |||
a4fe65bf60 | |||
e072fd2c30 | |||
7027899d7f | |||
2f1fd784fe | |||
0ef6c55a3f | |||
8216e878be |
18
CHANGELOG.md
18
CHANGELOG.md
@ -1,3 +1,21 @@
|
||||
Version 4.15.2 (2022-11-12)
|
||||
---------------------------
|
||||
|
||||
### Fixed
|
||||
|
||||
* Fixed parsing of large hex float literals that contain an "e" character.
|
||||
* Fixed tests to pass on 32-bit.
|
||||
* Fixed generation of invalid code when using formatting-preserving pretty printer with code that
|
||||
uses inline HTML.
|
||||
|
||||
Version 4.15.1 (2022-09-04)
|
||||
---------------------------
|
||||
|
||||
### Fixed
|
||||
|
||||
* Fixed formatting preservation when adding *multiple* attributes to a class/method/etc that
|
||||
previously had none. This fixes a regression in the 4.15.0 release.
|
||||
|
||||
Version 4.15.0 (2022-09-03)
|
||||
---------------------------
|
||||
|
||||
|
@ -206,6 +206,11 @@ class TokenStream
|
||||
|| $this->haveTokenInRange($startPos, $endPos, '}');
|
||||
}
|
||||
|
||||
public function haveTagInRange(int $startPos, int $endPos): bool {
|
||||
return $this->haveTokenInRange($startPos, $endPos, \T_OPEN_TAG)
|
||||
|| $this->haveTokenInRange($startPos, $endPos, \T_CLOSE_TAG);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get indentation before token position.
|
||||
*
|
||||
|
@ -47,13 +47,7 @@ class DNumber extends Scalar
|
||||
public static function parse(string $str) : float {
|
||||
$str = str_replace('_', '', $str);
|
||||
|
||||
// if string contains any of .eE just cast it to float
|
||||
if (false !== strpbrk($str, '.eE')) {
|
||||
return (float) $str;
|
||||
}
|
||||
|
||||
// otherwise it's an integer notation that overflowed into a float
|
||||
// if it starts with 0 it's one of the special integer notations
|
||||
// Check whether this is one of the special integer notations.
|
||||
if ('0' === $str[0]) {
|
||||
// hex
|
||||
if ('x' === $str[1] || 'X' === $str[1]) {
|
||||
@ -65,10 +59,12 @@ class DNumber extends Scalar
|
||||
return bindec($str);
|
||||
}
|
||||
|
||||
// oct
|
||||
// substr($str, 0, strcspn($str, '89')) cuts the string at the first invalid digit (8 or 9)
|
||||
// so that only the digits before that are used
|
||||
return octdec(substr($str, 0, strcspn($str, '89')));
|
||||
// oct, but only if the string does not contain any of '.eE'.
|
||||
if (false === strpbrk($str, '.eE')) {
|
||||
// substr($str, 0, strcspn($str, '89')) cuts the string at the first invalid digit
|
||||
// (8 or 9) so that only the digits before that are used.
|
||||
return octdec(substr($str, 0, strcspn($str, '89')));
|
||||
}
|
||||
}
|
||||
|
||||
// dec
|
||||
|
@ -4,7 +4,7 @@ namespace PhpParser\Node;
|
||||
|
||||
class UnionType extends ComplexType
|
||||
{
|
||||
/** @var (Identifier|Name)[] Types */
|
||||
/** @var (Identifier|Name|IntersectionType)[] Types */
|
||||
public $types;
|
||||
|
||||
/**
|
||||
|
@ -774,7 +774,8 @@ abstract class PrettyPrinterAbstract
|
||||
}
|
||||
|
||||
if ($skipRemovedNode) {
|
||||
if ($isStmtList && $this->origTokens->haveBracesInRange($pos, $itemStartPos)) {
|
||||
if ($isStmtList && ($this->origTokens->haveBracesInRange($pos, $itemStartPos) ||
|
||||
$this->origTokens->haveTagInRange($pos, $itemStartPos))) {
|
||||
// We'd remove the brace of a code block.
|
||||
// TODO: Preserve formatting.
|
||||
$this->setIndentLevel($origIndentLevel);
|
||||
@ -877,7 +878,8 @@ abstract class PrettyPrinterAbstract
|
||||
$pos, $itemStartPos, $indentAdjustment);
|
||||
$skipRemovedNode = true;
|
||||
} else {
|
||||
if ($isStmtList && $this->origTokens->haveBracesInRange($pos, $itemStartPos)) {
|
||||
if ($isStmtList && ($this->origTokens->haveBracesInRange($pos, $itemStartPos) ||
|
||||
$this->origTokens->haveTagInRange($pos, $itemStartPos))) {
|
||||
// We'd remove the brace of a code block.
|
||||
// TODO: Preserve formatting.
|
||||
return null;
|
||||
@ -923,6 +925,9 @@ abstract class PrettyPrinterAbstract
|
||||
foreach ($delayedAdd as $delayedAddNode) {
|
||||
if (!$first) {
|
||||
$result .= $insertStr;
|
||||
if ($insertNewline) {
|
||||
$result .= $this->nl;
|
||||
}
|
||||
}
|
||||
$result .= $this->p($delayedAddNode, true);
|
||||
$first = false;
|
||||
|
@ -241,8 +241,8 @@ class EmulativeTest extends LexerTest
|
||||
['1_000', [
|
||||
[Tokens::T_LNUMBER, '1_000'],
|
||||
]],
|
||||
['0xCAFE_F00D', [
|
||||
[Tokens::T_LNUMBER, '0xCAFE_F00D'],
|
||||
['0x7AFE_F00D', [
|
||||
[Tokens::T_LNUMBER, '0x7AFE_F00D'],
|
||||
]],
|
||||
['0b0101_1111', [
|
||||
[Tokens::T_LNUMBER, '0b0101_1111'],
|
||||
|
@ -105,8 +105,13 @@ fn()
|
||||
$attrGroup = new Node\AttributeGroup([
|
||||
new Node\Attribute(new Node\Name('A'), []),
|
||||
]);
|
||||
$attrGroup2 = new Node\AttributeGroup([
|
||||
new Node\Attribute(new Node\Name('B'), []),
|
||||
]);
|
||||
$stmts[0]->attrGroups[] = $attrGroup;
|
||||
$stmts[0]->attrGroups[] = $attrGroup2;
|
||||
$stmts[0]->stmts[0]->attrGroups[] = $attrGroup;
|
||||
$stmts[0]->stmts[0]->attrGroups[] = $attrGroup2;
|
||||
$stmts[0]->stmts[1]->attrGroups[] = $attrGroup;
|
||||
$stmts[0]->stmts[2]->attrGroups[] = $attrGroup;
|
||||
$stmts[1]->attrGroups[] = $attrGroup;
|
||||
@ -118,8 +123,10 @@ $stmts[6]->expr->attrGroups[] = $attrGroup;
|
||||
-----
|
||||
<?php
|
||||
#[A]
|
||||
#[B]
|
||||
class X {
|
||||
#[A]
|
||||
#[B]
|
||||
public function m() {}
|
||||
|
||||
#[A]
|
||||
|
@ -42,13 +42,71 @@ function test() {
|
||||
baz();
|
||||
}
|
||||
-----
|
||||
// TODO Fix broken result
|
||||
// TODO Preserve formatting
|
||||
$stmts[0]->stmts[1] = $stmts[0]->stmts[2];
|
||||
-----
|
||||
<?php
|
||||
|
||||
function test()
|
||||
{
|
||||
foo();
|
||||
baz();
|
||||
baz();
|
||||
}
|
||||
-----
|
||||
<?php
|
||||
|
||||
function test() {
|
||||
foo();<?php
|
||||
foo();
|
||||
?>Bar<?php
|
||||
baz();
|
||||
}
|
||||
-----
|
||||
// TODO Preserve formatting
|
||||
unset($stmts[0]->stmts[2]);
|
||||
-----
|
||||
<?php
|
||||
|
||||
function test()
|
||||
{
|
||||
foo();
|
||||
?>Bar<?php
|
||||
}
|
||||
-----
|
||||
<?php
|
||||
|
||||
function test() {
|
||||
foo();
|
||||
?>Bar<?php
|
||||
baz();
|
||||
}
|
||||
}
|
||||
-----
|
||||
// TODO Preserve formatting
|
||||
array_splice($stmts[0]->stmts, 0, 1, []);
|
||||
-----
|
||||
<?php
|
||||
|
||||
function test()
|
||||
{
|
||||
?>Bar<?php
|
||||
baz();
|
||||
}
|
||||
-----
|
||||
<?php
|
||||
|
||||
function test() {
|
||||
foo();
|
||||
?>Bar<?php
|
||||
baz();
|
||||
}
|
||||
-----
|
||||
// TODO Preserve formatting
|
||||
array_splice($stmts[0]->stmts, 1, 1, []);
|
||||
-----
|
||||
<?php
|
||||
|
||||
function test()
|
||||
{
|
||||
foo();
|
||||
baz();
|
||||
}
|
||||
|
@ -17,6 +17,7 @@ Different float syntaxes
|
||||
// (all are actually the same number, just in different representations)
|
||||
18446744073709551615;
|
||||
0xFFFFFFFFFFFFFFFF;
|
||||
0xEEEEEEEEEEEEEEEE;
|
||||
01777777777777777777777;
|
||||
0177777777777777777777787;
|
||||
0b1111111111111111111111111111111111111111111111111111111111111111;
|
||||
@ -92,7 +93,7 @@ array(
|
||||
)
|
||||
12: Stmt_Expression(
|
||||
expr: Scalar_DNumber(
|
||||
value: 1.844674407371E+19
|
||||
value: 1.7216961135462E+19
|
||||
)
|
||||
)
|
||||
13: Stmt_Expression(
|
||||
@ -105,4 +106,9 @@ array(
|
||||
value: 1.844674407371E+19
|
||||
)
|
||||
)
|
||||
)
|
||||
15: Stmt_Expression(
|
||||
expr: Scalar_DNumber(
|
||||
value: 1.844674407371E+19
|
||||
)
|
||||
)
|
||||
)
|
||||
|
@ -4,7 +4,7 @@ Different integer syntaxes
|
||||
|
||||
6.674_083e-11;
|
||||
299_792_458;
|
||||
0xCAFE_F00D;
|
||||
0x7AFE_F00D;
|
||||
0b0101_1111;
|
||||
0137_041;
|
||||
|
||||
@ -42,7 +42,7 @@ array(
|
||||
)
|
||||
2: Stmt_Expression(
|
||||
expr: Scalar_LNumber(
|
||||
value: 3405705229
|
||||
value: 2063527949
|
||||
)
|
||||
)
|
||||
3: Stmt_Expression(
|
||||
@ -196,4 +196,4 @@ array(
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
|
Reference in New Issue
Block a user