887 Commits

Author SHA1 Message Date
Markus Staab
45f70ed80a Simplify NodeTraverser->traverseNode() 2024-12-30 11:10:07 +01:00
Markus Staab
74a361814d Simplify NodeTraverser->traverseArray() 2024-12-30 11:10:07 +01:00
Nikita Popov
6478c5ac53 Fix PropertyHook::getStmts() for set hook
Produce the correct desugaring if the propertyName attribute is
set, and set it in the parser. Otherwise throw an exception.

Fixes #1053.
2024-12-27 16:56:00 +01:00
Nikita Popov
48fd76e542 Make PropertyHook::getStmts() less incorrect
Still missing the assignment to the correct property, but at
least we're not returning from a non-void function now...
2024-12-27 16:30:03 +01:00
Ondrej Mirtes
d20a197ca7 Emit error - Multiple properties cannot share the same hooks
Closes GH-1052.
2024-12-27 16:19:46 +01:00
Ondrej Mirtes
62dee28027 Rename ParserAbstract method checkPropertyHookList to checkEmptyPropertyHookList 2024-12-27 16:13:47 +01:00
Ondrej Mirtes
f212bb7afb Add PropertyHook::isFinal() helper method with tests 2024-12-13 23:15:12 +01:00
Ondrej Mirtes
f43324a074 Missing flags subNode description in PropertyHook constructor PHPDoc 2024-12-13 23:15:12 +01:00
Ondrej Mirtes
73b160f8c4 Add flags helper methods Property::isAbstract() and Property::isFinal() 2024-12-13 23:15:12 +01:00
Ondrej Mirtes
4f9dc8b0f5 Promoted properties with hooks do not need visibility modifier 2024-12-11 10:17:55 +01:00
Nathanael Esayeas
469377f4a8
Fix classmap authoritative autoloading (#1046)
This patch resolves #1045 by adding dummy class definitions
behind if (false) checks that are picked up the authoritative
autoloader.
2024-12-06 22:00:17 +01:00
Jorg Sowa
05ed79595b Removed unrecheable statement 2024-11-19 21:17:27 +01:00
Markus Staab
954f7a411f More precise toLowerString() return type 2024-11-05 21:19:09 +01:00
Nikita Popov
9c7a3f8d8f Support declaring functions with name exit/die
For use in stubs.

Fixes #1030.
2024-10-08 20:46:50 +02:00
Nikita Popov
961f158f6d Avoid negative indendation in formatting-preserving printer
Fixes #1015.
2024-09-29 15:34:59 +02:00
Nikita Popov
e50c67b7a9 Add basic support for tab indentation
Add a new "indent" option for the pretty printer, which can be
use to control the indentation width, or switch it to use tabs.

Tab width is currenlty hardcoded to 4, but also shouldn't matter
much.

Possibly the formatting-preserving printer should auto-detect
the indentation in the future.
2024-09-21 20:58:10 +02:00
Nikita Popov
aedfcc23cd Include trailing semicolon in GroupUse
Fixes https://github.com/nikic/PHP-Parser/issues/1026.
2024-09-21 15:55:21 +02:00
Nikita Popov
8d09ba87f4 Support PropertyHooks in NameResolver 2024-09-17 21:33:51 +02:00
Nikita Popov
b493c51cce [8.4] Add support for asymmetric visibility modifiers
Represented using new PRIVATE_SET, PROTECTED_SET and PUBLIC_SET
bits in Modifiers.

RFC: https://wiki.php.net/rfc/asymmetric-visibility-v2
2024-09-05 21:38:16 +02:00
Nikita Popov
cde9bab3bb Add support for PHP 8.4 exit function
For backwards-compatibility, parse the simple single argument
case into an Exit_ node as previously. For more complex
expressions generate a function call.
2024-09-01 12:41:27 +02:00
Nikita Popov
018da15f3a Add token emulation support for asymmetric visibility modifiers 2024-08-31 20:41:07 +02:00
evenevent
ba14437165 chore: fix comment
Signed-off-by: evenevent <digping@icloud.com>
2024-08-15 09:22:56 +02:00
Nikita Popov
514f71024e Fix for new php-cs-fixer version 2024-08-11 17:03:56 +02:00
Ruud Kamphuis
6a97061265 Normalize enum value to ClassConstFetch
Fixes #930

(cherry picked from commit 8a21ec3182533ee6448a4efb8d238a4163b89297)
2024-08-11 16:58:28 +02:00
Nikita Popov
03caf4cc99 [8.4] Add support for property hooks
Add hooks subnode to Stmt\Property and Param, which contains an
array of PropertyHook.

The property hook support is considered experimental and subject
to change.

RFC: https://wiki.php.net/rfc/property-hooks
2024-07-28 19:02:18 +02:00
Nikita Popov
3beee6ec77 Add Modifiers::toString() helper
Convert an integer modifier into a string.
2024-07-28 17:09:14 +02:00
Nikita Popov
58de479119 Remove error for abstract/final properties
These are allowed since PHP 8.4, with the introduction of property
hooks. (Abstract properties require hooks, which is not validated
here.)
2024-07-21 18:59:18 +02:00
Nikita Popov
beba9c528f Remove support for alternative array syntax in PHP 8 parser
We cannot support both this syntax and property hooks. Drop
support for the alternative syntax in the PHP 8 parser. The
PHP 7 parser still supports it.
2024-07-19 22:29:35 +02:00
Nikita Popov
fadccead52 Avoid compatibilty token list in parser
Create the mapping using the entries in symbolToName, so we don't
need to repeat the compatibility tokens in another place.
2024-07-14 20:53:13 +02:00
Nikita Popov
d8235a2701 [8.4] Add support for __PROPERTY__ magic constant
Part of property hooks RFC.
2024-07-14 18:52:47 +02:00
Nikita Popov
caf540443a Declare PHP 8.4 as the newest supported version
As the comment indicates, this includes partially supported
versions. PHP-Parser includes support for all parts of PHP 8.4
that have landed in php-src.
2024-07-13 11:10:30 +02:00
Nikita Popov
a894652a3d Fix ternary precedence printing
The precedence table set the LHS and RHS precedence for the
ternary to -1, which is the dummy value used for unary operators.
Instead, it should be the same as the operator precedence, as
the ternary is non-associative since PHP 8.

Fixes #1009.
2024-07-01 21:51:42 +02:00
Nikita Popov
7b0384cdbe [8.4] Add support for new deref without parens
RFC: https://wiki.php.net/rfc/new_without_parentheses
2024-05-31 23:07:44 +02:00
Markus Staab
c5ee33df86
Declare more precise phpdoc types (#993) 2024-04-19 21:04:10 +09:00
Markus Staab
09691fc86e Prevent off-by-one errors in line-number related methods 2024-03-13 20:24:50 +01:00
Nikita Popov
70c96493b4 Fix indentation detection after opening tag
Fixes #982.
2024-03-02 18:59:44 +01:00
Maarten Buis
ec02613432 Update PhpVersion::getNewestSupported() to PHP 8.3 2024-03-02 08:27:21 +01:00
Nikita Popov
af14fdb282 Avoid cyclic reference in parser
Pass $this as an explicit $self argument to the reduce callbacks,
so we can make them static. This avoids a circular reference in
the parser, so that it can be immediately destroyed when it goes
out of scope.

Fixes #980.
2024-02-21 21:13:45 +01:00
Nikita Popov
ff095c3c65 Check for tokens with non-integer ID
Fixes #974.
2024-01-10 20:34:09 +01:00
Ondrej Mirtes
1eeeb2d525 Fix parent class of PropertyItem and UseItem 2023-12-22 19:57:32 +01:00
Nikita Popov
f7d484aa0e Fix handling of empty input
Fixes #967.
2023-12-20 21:51:46 +01:00
Ondrej Mirtes
f66650073c Fix NameResolver for class constant native type 2023-11-28 20:10:53 +01:00
Nikita Popov
3640d18b87 Remove ParserFactory::create()
Don't try to keep backwards-compatibility with the old factory
style, which doesn't map cleanly onto supported options (we only
have ONLY_PHP7/PREFER_PHP7, which should probably create a Php8
parser in terms of how they are used, but this would no longer
match their names).

Instead, I have backported the new createForNewestSupportedVersion()
and createForHostVersion() methods to PHP-Parser 4.
2023-11-12 16:52:30 +01:00
Nikita Popov
acfccd9d74 Run with updated php-cs-fixer 2023-11-01 18:50:25 +01:00
xjaja
8d50e9d066 Don't drop class statements before error (#952)
When encountering a null statement (indicating that an error occurred),
retain the preceding statements. These were accidentally dropped
previously.

(cherry picked from commit 54103d838734be0499172026525e38cbf6af2711)
2023-10-07 12:22:01 +02:00
Abdul Malik Ikhsan
481fec47f4 Improve performance of find() and findFirst() when passed $nodes is empty array 2023-10-07 12:11:47 +02:00
Nikita Popov
4e27a17cd8 Use visitor to assign comments
This fixes the long-standing issue where a comment would get assigned
to all nodes with the same starting position, instead of only the
outer-most one.

Fixes #253.
2023-09-28 21:45:08 +02:00
Nikita Popov
de84f76766 Avoid by-reference iteration in NodeTraverser
No need to create reference wrappers around every element in the
array.
2023-09-26 20:25:37 +02:00
Nikita Popov
b4183c2b09 Remove Stmt\Throw
This was a backwards-compatibility shim for Expr\Throw.
2023-09-25 18:37:07 +02:00
Nikita Popov
a1ccf57727 Introduce Stmt\Block
Stmt\Block will be created for { $a; } style blocks, unless these
occur directly inside some structure that is usually combined
with a block.

For example if ($a) { $b; } will continue to use the old
representation (plain array in in If_::$stmts), but a free-standing
{ $b; } will become a Stmt\Block.

Fixes #590.
2023-09-24 21:13:01 +02:00