Файловый менеджер - Редактировать - /var/www/html/peast.zip
Ðазад
PK ! �fw�� � README.mdnu �Iw�� Peast ========== [](https://packagist.org/packages/mck89/peast) [](https://packagist.org/packages/mck89/peast) [](https://packagist.org/packages/mck89/peast) [](https://github.com/mck89/peast/actions/workflows/test.yml) **Peast** _(PHP ECMAScript Abstract Syntax Tree)_ is a PHP 5.4+ library that parses JavaScript code, according to [ECMAScript specification](http://www.ecma-international.org/publications/standards/Ecma-262.htm), and generates an abstract syntax tree following the [ESTree standard](https://github.com/estree/estree). Installation ------------- Include the following requirement to your composer.json: ```json { "require": { "mck89/peast": "dev-master" } } ``` Run `composer install` to install the package. Then in your script include the autoloader and you can start using Peast: ```php require_once "vendor/autoload.php"; $source = "var a = 1"; // Your JavaScript code $ast = Peast\Peast::latest($source, $options)->parse(); // Parse it! ``` Known issues ------------- When Xdebug is enabled and Peast is used to scan code that contains deeply nested functions, this fatal error can appear: ``` PHP Fatal error: Maximum function nesting level of '512' reached, aborting! ``` or ``` PHP Warning: Uncaught Error: Xdebug has detected a possible infinite loop, and aborted your script with a stack depth of '256' frames ``` To prevent this you can set `xdebug.max_nesting_level` to a higher value, such as 512. Documentation ------------- Read the documentation for more examples and explanations: 1. [AST generation and tokenization](doc/ast-and-tokenization.md) 2. [Tree Traversing](doc/tree-traversing.md) 3. [Querying By Selector](doc/querying-by-selector.md) 4. [Rendering](doc/rendering.md) [Changelog](doc/changelog.md) PK ! tEZA A lib/Peast/Peast.phpnu �Iw�� <?php /** * This file is part of the Peast package * * (c) Marco Marchiò <marco.mm89@gmail.com> * * For the full copyright and license information refer to the LICENSE file * distributed with this source code */ namespace Peast; /** * Main class of Peast library. * Every function of this class takes two arguments: * - The source code to parse * - The options array that is an associative array of parser settings. * Available options are: * - "sourceType": one of the source type constants declared in this class. * This option tells the parser to parse the source in script or module * mode. If this option is not provided the parser will work in script * mode. * - "sourceEncoding": the encoding of the source. If not specified the * parser will assume UTF-8. * - "strictEncoding": if false the parser will handle invalid UTF8 * characters in the source code by replacing them with the character * defined in the "mbstring.substitute_character" ini setting, otherwise * it will throw an exception. * - "comments": if true it enables comments parsing. * - "jsx": if true it enables parsing of JSX syntax. * * @method static Syntax\Parser ES2015(string $source, array $options = array()) * Returns a parser instance with ES2015 features for the given source. See Peast * class documentation to understand the function arguments. * * @method static Syntax\Parser ES6(string $source, array $options = array()) * Returns a parser instance with ES2015 features for the given source. See Peast * class documentation to understand function arguments. * * @method static Syntax\Parser ES2016(string $source, array $options = array()) * Returns a parser instance with ES2016 features for the given source. See Peast * class documentation to understand function arguments. * * @method static Syntax\Parser ES7(string $source, array $options = array()) * Returns a parser instance with ES2016 features for the given source. See Peast * class documentation to understand function arguments. * * @method static Syntax\Parser ES2017(string $source, array $options = array()) * Returns a parser instance with ES2017 features for the given source. See Peast * class documentation to understand function arguments. * * @method static Syntax\Parser ES8(string $source, array $options = array()) * Returns a parser instance with ES2017 features for the given source. See Peast * class documentation to understand function arguments. * * @method static Syntax\Parser ES2018(string $source, array $options = array()) * Returns a parser instance with ES2018 features for the given source. See Peast * class documentation to understand function arguments. * * @method static Syntax\Parser ES9(string $source, array $options = array()) * Returns a parser instance with ES2018 features for the given source. See Peast * class documentation to understand function arguments. * * @method static Syntax\Parser ES2019(string $source, array $options = array()) * Returns a parser instance with ES2019 features for the given source. See Peast * class documentation to understand function arguments. * * @method static Syntax\Parser ES10(string $source, array $options = array()) * Returns a parser instance with ES2019 features for the given source. See Peast * class documentation to understand function arguments. * * @method static Syntax\Parser ES2020(string $source, array $options = array()) * Returns a parser instance with ES2020 features for the given source. See Peast * class documentation to understand function arguments. * * @method static Syntax\Parser ES11(string $source, array $options = array()) * Returns a parser instance with ES2020 features for the given source. See Peast * class documentation to understand function arguments. * * @method static Syntax\Parser ES2021(string $source, array $options = array()) * Returns a parser instance with ES2021 features for the given source. See Peast * class documentation to understand function arguments. * * @method static Syntax\Parser ES12(string $source, array $options = array()) * Returns a parser instance with ES2021 features for the given source. See Peast * class documentation to understand function arguments. * * @method static Syntax\Parser ES2022(string $source, array $options = array()) * Returns a parser instance with ES2022 features for the given source. See Peast * class documentation to understand function arguments. * * @method static Syntax\Parser ES13(string $source, array $options = array()) * Returns a parser instance with ES2022 features for the given source. See Peast * class documentation to understand function arguments. * * @method static Syntax\Parser ES2023(string $source, array $options = array()) * Returns a parser instance with ES2023 features for the given source. See Peast * class documentation to understand function arguments. * * @method static Syntax\Parser ES14(string $source, array $options = array()) * Returns a parser instance with ES2023 features for the given source. See Peast * class documentation to understand function arguments. * * @method static Syntax\Parser ES2024(string $source, array $options = array()) * Returns a parser instance with ES2024 features for the given source. See Peast * class documentation to understand function arguments. * * @method static Syntax\Parser ES15(string $source, array $options = array()) * Returns a parser instance with ES2024 features for the given source. See Peast * class documentation to understand function arguments. * * @method static Syntax\Parser latest(string $source, array $options = array()) * Returns an instance of the latest parser version for the given source. See * Peast class documentation to understand function arguments. * * @author Marco Marchiò <marco.mm89@gmail.com> */ class Peast { //Source type constants /** * This source type indicates that the source is a script and import * and export keywords are not parsed. */ const SOURCE_TYPE_SCRIPT = "script"; /** * This source type indicates that the source is a module, this enables * the parsing of import and export keywords. */ const SOURCE_TYPE_MODULE = "module"; /** * Valid versions and aliases * * @var array */ static protected $versions = array( "ES6" => "ES2015", "ES7" => "ES2016", "ES8" => "ES2017", "ES9" => "ES2018", "ES10" => "ES2019", "ES11" => "ES2020", "ES12" => "ES2021", "ES13" => "ES2022", "ES14" => "ES2023", "ES15" => "ES2024" ); /** * Magic method that exposes all the functions to access parser with * specific features * * @param string $version Parser version * @param array $args Parser arguments * * @return Syntax\Parser * * @throws \Exception */ public static function __callStatic($version, $args) { $source = $args[0]; $options = isset($args[1]) ? $args[1] : array(); if (!in_array($version, self::$versions)) { if ($version === "latest") { $version = end(self::$versions); } elseif (isset(self::$versions[$version])) { $version = self::$versions[$version]; } else { throw new \Exception("Invalid version $version"); } } $featuresClass = "\\Peast\\Syntax\\$version\\Features"; return new Syntax\Parser( $source, new $featuresClass, $options ); } }PK ! �=�l l lib/Peast/Formatter/Base.phpnu �Iw�� <?php /** * This file is part of the Peast package * * (c) Marco Marchiò <marco.mm89@gmail.com> * * For the full copyright and license information refer to the LICENSE file * distributed with this source code */ namespace Peast\Formatter; /** * Base class for formatters, all the formatters must extend this class. * * @author Marco Marchiò <marco.mm89@gmail.com> * * @abstract */ abstract class Base { /** * New line character * * @var string */ protected $newLine = "\n"; /** * Indentation character * * @var string */ protected $indentation = "\t"; /** * Boolean that indicates if open curly brackets in code blocks must be * on a new line * * @var bool */ protected $newLineBeforeCurlyBracket = false; /** * Boolean that indicates if blocks of code must be wrapped in curly * brackets also if they contain only one instruction * * @var bool */ protected $alwaysWrapBlocks = true; /** * Boolean that indicates if operators must be surrounded by spaces * * @var bool */ protected $spacesAroundOperators = true; /** * Boolean that indicates if content inside round brackets must be * surrounded by spaces * * @var bool */ protected $spacesInsideRoundBrackets = false; /** * Boolean that indicates if comments must be rendered * * @var bool */ protected $renderComments = true; /** * Boolean that indicates if multiline documentation comments * (for example JSDoc syntax) must be manipulated to match the * right indentation * * @var bool */ protected $recalcCommentsIndent = true; /** * Class constructor * * @param bool $renderComments True to render the comments if * the parser has collected them * and the formatter allows their * rendering */ public function __construct($renderComments = false) { if ($this->renderComments) { $this->renderComments = $renderComments; } } /** * Returns the new line character * * @return string */ public function getNewLine() { return $this->newLine; } /** * Returns the indentation character * * @return string */ public function getIndentation() { return $this->indentation; } /** * Returns a boolean that indicates if open curly brackets in code blocks * must be on a new line * * @return bool */ public function getNewLineBeforeCurlyBracket() { return $this->newLineBeforeCurlyBracket; } /** * Returns a boolean that indicates if blocks of code must be wrapped in * curly brackets also if they contain only one instruction * * @return bool */ public function getAlwaysWrapBlocks() { return $this->alwaysWrapBlocks; } /** * Returns a boolean that indicates if operators must be surrounded by * spaces * * @return bool */ public function getSpacesAroundOperator() { return $this->spacesAroundOperators; } /** * Returns a boolean that indicates if content inside round brackets must be * surrounded by spaces * * @return bool */ public function getSpacesInsideRoundBrackets() { return $this->spacesInsideRoundBrackets; } /** * Returns a boolean that indicates if comments must be rendered * * @return bool */ public function getRenderComments() { return $this->renderComments; } /** * Returns a boolean that indicates if multiline documentation comments * (for example JSDoc syntax) must be manipulated to match the * right indentation * * @return bool */ public function getRecalcCommentsIndent() { return $this->recalcCommentsIndent; } }PK ! �j��r r # lib/Peast/Formatter/PrettyPrint.phpnu �Iw�� <?php /** * This file is part of the Peast package * * (c) Marco Marchiò <marco.mm89@gmail.com> * * For the full copyright and license information refer to the LICENSE file * distributed with this source code */ namespace Peast\Formatter; /** * Pretty print formatter. * * @author Marco Marchiò <marco.mm89@gmail.com> */ class PrettyPrint extends Base { }PK ! ��x� � lib/Peast/Formatter/Expanded.phpnu �Iw�� <?php /** * This file is part of the Peast package * * (c) Marco Marchiò <marco.mm89@gmail.com> * * For the full copyright and license information refer to the LICENSE file * distributed with this source code */ namespace Peast\Formatter; /** * Compact formatter. * * @author Marco Marchiò <marco.mm89@gmail.com> */ class Expanded extends Base { /** * Boolean that indicates if open curly brackets in code blocks must be * on a new line * * @var bool */ protected $newLineBeforeCurlyBracket = true; /** * Boolean that indicates if content inside round brackets must be * surrounded by spaces * * @var bool */ protected $spacesInsideRoundBrackets = true; }PK ! �o�G G lib/Peast/Formatter/Compact.phpnu �Iw�� <?php /** * This file is part of the Peast package * * (c) Marco Marchiò <marco.mm89@gmail.com> * * For the full copyright and license information refer to the LICENSE file * distributed with this source code */ namespace Peast\Formatter; /** * Compact formatter. * * @author Marco Marchiò <marco.mm89@gmail.com> */ class Compact extends Base { /** * New line character * * @var string */ protected $newLine = ""; /** * Indentation character * * @var string */ protected $indentation = ""; /** * Boolean that indicates if operators must be surrounded by spaces * * @var bool */ protected $spacesAroundOperators = false; /** * Boolean that indicates if blocks of code must be wrapped in curly * brackets also if they contain only one instruction * * @var bool */ protected $alwaysWrapBlocks = false; /** * Boolean that indicates if comments must be rendered * * @var bool */ protected $renderComments = false; }PK ! BQ:�� � lib/Peast/Selector/Exception.phpnu �Iw�� <?php /** * This file is part of the Peast package * * (c) Marco Marchiò <marco.mm89@gmail.com> * * For the full copyright and license information refer to the LICENSE file * distributed with this source code */ namespace Peast\Selector; /** * Selector exception class. Syntax errors in selectors are thrown * using this exception class. * * @author Marco Marchiò <marco.mm89@gmail.com> * * @codeCoverageIgnore */ class Exception extends \Exception { }PK ! ���S S &