Initial Drupal 11 with DDEV setup
This commit is contained in:
26
vendor/mck89/peast/LICENSE
vendored
Normal file
26
vendor/mck89/peast/LICENSE
vendored
Normal file
@ -0,0 +1,26 @@
|
||||
Copyright (c) 2024, Marco Marchiò
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
1) Redistributions of source code must retain the above copyright notice,
|
||||
this list of conditions and the following disclaimer.
|
||||
2) Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
3) Neither the name of Marco Marchiò nor the names of its contributors may be
|
||||
used to endorse or promote products derived from this software without
|
||||
specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
POSSIBILITY OF SUCH DAMAGE.
|
||||
55
vendor/mck89/peast/README.md
vendored
Normal file
55
vendor/mck89/peast/README.md
vendored
Normal file
@ -0,0 +1,55 @@
|
||||
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)
|
||||
33
vendor/mck89/peast/composer.json
vendored
Normal file
33
vendor/mck89/peast/composer.json
vendored
Normal file
@ -0,0 +1,33 @@
|
||||
{
|
||||
"name": "mck89/peast",
|
||||
"description": "Peast is PHP library that generates AST for JavaScript code",
|
||||
"license": "BSD-3-Clause",
|
||||
"authors": [
|
||||
{
|
||||
"name": "Marco Marchiò",
|
||||
"email": "marco.mm89@gmail.com"
|
||||
}
|
||||
],
|
||||
"require": {
|
||||
"php": ">=5.4.0",
|
||||
"ext-mbstring": "*"
|
||||
},
|
||||
"require-dev": {
|
||||
"phpunit/phpunit": "^4.0 || ^5.0 || ^6.0 || ^7.0 || ^8.0 || ^9.0"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Peast\\": "lib/Peast/"
|
||||
}
|
||||
},
|
||||
"autoload-dev": {
|
||||
"psr-4": {
|
||||
"Peast\\test\\": "test/Peast/"
|
||||
}
|
||||
},
|
||||
"extra": {
|
||||
"branch-alias": {
|
||||
"dev-master": "1.17.2-dev"
|
||||
}
|
||||
}
|
||||
}
|
||||
96
vendor/mck89/peast/doc/ast-and-tokenization.md
vendored
Normal file
96
vendor/mck89/peast/doc/ast-and-tokenization.md
vendored
Normal file
@ -0,0 +1,96 @@
|
||||
AST generation and tokenization
|
||||
==========
|
||||
|
||||
AST generation
|
||||
-------------
|
||||
To generate AST (abstract syntax tree) for your JavaScript code just write:
|
||||
|
||||
```php
|
||||
$source = "var a = 1"; //JavaScript code
|
||||
$ast = Peast\Peast::latest($source, $options)->parse();
|
||||
```
|
||||
|
||||
The previous code generates this structure:
|
||||
```
|
||||
Peast\Syntax\Node\Program
|
||||
getSourceType() => "script"
|
||||
getBody() => array(
|
||||
Peast\Syntax\Node\VariableDeclaration
|
||||
getKind() => "var"
|
||||
getDeclarations() => array(
|
||||
Peast\Syntax\Node\VariableDeclarator
|
||||
getId() => Peast\Syntax\Node\Identifier
|
||||
getName() => "a"
|
||||
getInit() => Peast\Syntax\Node\NumericLiteral
|
||||
getFormat() => "decimal"
|
||||
getValue() => 1
|
||||
)
|
||||
)
|
||||
```
|
||||
|
||||
Tokenization
|
||||
-------------
|
||||
To tokenize your JavaScript code just write:
|
||||
|
||||
```php
|
||||
$source = "var a = 1"; //JavaScript code
|
||||
$tokens = Peast\Peast::latest($source, $options)->tokenize();
|
||||
```
|
||||
|
||||
This function produces an array of tokens from your code:
|
||||
```
|
||||
array(
|
||||
Peast\Syntax\Token
|
||||
getType() => "Keyword"
|
||||
getValue() => "var"
|
||||
Peast\Syntax\Token
|
||||
getType() => "Identifier"
|
||||
getValue() => "a"
|
||||
Peast\Syntax\Token
|
||||
getType() => "Punctuator"
|
||||
getValue() => "="
|
||||
Peast\Syntax\Token
|
||||
getType() => "Numeric"
|
||||
getValue() => "1"
|
||||
)
|
||||
```
|
||||
|
||||
EcmaScript version
|
||||
-------------
|
||||
Peast can parse different versions of EcmaScript, you can choose the version by using the relative method on the main class.
|
||||
Available methods are:
|
||||
* ```Peast::ES2015(source, options)``` or ```Peast::ES6(source, options)```: parse using EcmaScript 2015 (ES6) syntax
|
||||
* ```Peast::ES2016(source, options)``` or ```Peast::ES7(source, options)```: parse using EcmaScript 2016 (ES7) syntax
|
||||
* ```Peast::ES2017(source, options)``` or ```Peast::ES8(source, options)```: parse using EcmaScript 2017 (ES8) syntax
|
||||
* ```Peast::ES2018(source, options)``` or ```Peast::ES9(source, options)```: parse using EcmaScript 2018 (ES9) syntax
|
||||
* ```Peast::ES2019(source, options)``` or ```Peast::ES10(source, options)```: parse using EcmaScript 2019 (ES10) syntax
|
||||
* ```Peast::ES2020(source, options)``` or ```Peast::ES11(source, options)```: parse using EcmaScript 2020 (ES11) syntax
|
||||
* ```Peast::ES2021(source, options)``` or ```Peast::ES12(source, options)```: parse using EcmaScript 2021 (ES12) syntax
|
||||
* ```Peast::ES2022(source, options)``` or ```Peast::ES13(source, options)```: parse using EcmaScript 2022 (ES13) syntax
|
||||
* ```Peast::ES2023(source, options)``` or ```Peast::ES14(source, options)```: parse using EcmaScript 2023 (ES14) syntax
|
||||
* ```Peast::ES2024(source, options)``` or ```Peast::ES15(source, options)```: parse using EcmaScript 2024 (ES15) syntax
|
||||
* ```Peast::ES2025(source, options)``` or ```Peast::ES16(source, options)```: parse using EcmaScript 2025 (ES16) syntax
|
||||
* ```Peast::latest(source, options)```: parse using the latest EcmaScript syntax version implemented
|
||||
|
||||
Options
|
||||
-------------
|
||||
|
||||
In the examples above you may have noticed the `$options` parameter. This parameter is an associative array that specifies parsing settings for the parser. Available options are:
|
||||
* "sourceType": this can be one of the source type constants defined in the Peast class:
|
||||
* `Peast\Peast::SOURCE_TYPE_SCRIPT`: this is the default source type and indicates that the code is a script, this means that `import` and `export` keywords are not parsed
|
||||
* `Peast\Peast::SOURCE_TYPE_MODULE`: this indicates that the code is a module and it activates the parsing of `import` and `export` keywords
|
||||
* "comments" (from version 1.5): enables comments parsing and attaches the comments to the nodes in the tree. You can get comments attached to nodes using `getLeadingComments` and `getTrailingComments` methods.
|
||||
* "jsx" (from version 1.8): enables parsing of JSX syntax.
|
||||
* "sourceEncoding": to specify the encoding of the code to parse, 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. (available from version 1.9.4)
|
||||
|
||||
Differences from ESTree
|
||||
-------------
|
||||
|
||||
There is only one big difference from ESTree: parenthesized expressions. This type of expressions have been introduced to let the user know if when an expression is wrapped in round brackets. For example `(a + b)` is a parenthesized expression and generates a ParenthesizedExpression node.
|
||||
|
||||
From version 1.3, literals have their own classes: `StringLiteral`, `NumericLiteral`, `BooleanLiteral` and `NullLiteral`.
|
||||
|
||||
From version 1.8, when parsing JSX, 2 new token types are emitted: `JSXIdentifier`, that represents a valid JSX identifier, and `JSXText`, that represents text inside JSX elements and fragments.
|
||||
|
||||
From version 1.13.7, the new `rawName` property has been added to `Identifiers` nodes. This property reports the raw name of the identifier with unconverted unicode escape sequences.
|
||||
181
vendor/mck89/peast/doc/changelog.md
vendored
Normal file
181
vendor/mck89/peast/doc/changelog.md
vendored
Normal file
@ -0,0 +1,181 @@
|
||||
Changelog
|
||||
==========
|
||||
|
||||
#### 1.17.2
|
||||
* Fixed bug where `const` declarations were allowed without an initializer
|
||||
|
||||
#### 1.17.1
|
||||
* Fixed bug where `continue` and `break` were allowed outside iteration and `break` statements
|
||||
|
||||
#### 1.17.0
|
||||
* Implemented ES2025 parser with import attributes
|
||||
|
||||
#### 1.16.3
|
||||
* Removed implicitly nullable parameter declarations for PHP 8.4 compatibility
|
||||
|
||||
#### 1.16.2
|
||||
* Fixed bug where a regex that started with `/=` raised a syntax error
|
||||
|
||||
#### 1.16.1
|
||||
* Fixed bug where, in some situations, scanner allowed invalid characters after a slash
|
||||
|
||||
#### 1.16.0
|
||||
* Implemented ES2024 parser, no new syntax features have been introduced
|
||||
* Fixed bug when parsing sequence expressions using older ES versions
|
||||
|
||||
#### 1.15.4
|
||||
* Fixed rendering of `let` and `const` inside `switch` cases that always require brackets
|
||||
|
||||
#### 1.15.3
|
||||
* Fixed rendering of `let` and `const` inside `if`, `for` and `while` that always require brackets
|
||||
|
||||
#### 1.15.2
|
||||
* Fixed bug where async keyword was lost when rendering an object async method
|
||||
|
||||
#### 1.15.1
|
||||
* Fixed bug on hashbang comment detection
|
||||
|
||||
#### 1.15.0
|
||||
* Implemented ES2022 parser with hashbang comments
|
||||
|
||||
#### 1.14.0
|
||||
* Implemented comments rendering
|
||||
|
||||
#### 1.13.11
|
||||
* Fixed a case of conditional expression parsed as a wrong optional chain
|
||||
|
||||
#### 1.13.10
|
||||
* Added support for php 8.1
|
||||
* Fixed parsing of multiline template literals in return statements
|
||||
|
||||
#### 1.13.9
|
||||
* Implemented parsing of arbitrary module namespace identifier names
|
||||
|
||||
#### 1.13.8
|
||||
* Fixed identifiers bug introduced in the last release
|
||||
|
||||
#### 1.13.7
|
||||
* Implemented parsing of top level await
|
||||
* Implemented parsing of `#field in obj` syntax
|
||||
* Implemented parsing of class static block
|
||||
* Aligned invalid octal numbers checks to the specification
|
||||
* __BC break__: identifier tokens' value now report their raw name, this means that unicode escape sequences are reported as they are written in the code, without converting them to their corresponding characters. Identifier nodes have a new property called `rawName` that contains their raw name, including unconverted unicode escape sequences, while the `name` property still contains the converted value as before. Renderer now prints `rawName` for identifiers to prevent automatic conversion of escaped keywords.
|
||||
|
||||
#### 1.13.6
|
||||
* Fixed parsing of adjacent JSX expressions
|
||||
* Implemented parsing of JSX fragments inside elements
|
||||
|
||||
#### 1.13.5
|
||||
* Fixed parsing of `get` and `set` as property names and class fields
|
||||
* Fixed parsing of dot after number with exponential notation
|
||||
|
||||
#### 1.13.4
|
||||
* Fixed bug when parsing surrogate pairs in php 7.4+
|
||||
|
||||
#### 1.13.3
|
||||
* Added support for surrogate pairs in strings and templates
|
||||
|
||||
#### 1.13.2
|
||||
* Fixed bug when parsing spread operator inside objects returned by arrow functions
|
||||
|
||||
#### 1.13.1
|
||||
* Major performance improvements to parsing and tokenization
|
||||
|
||||
#### 1.13.0
|
||||
* Implemented ES2022 parser with class fields and private class methods
|
||||
|
||||
#### 1.12.0
|
||||
* Added options array to Traverser constructor and shortcut method on nodes
|
||||
* Added Query class
|
||||
|
||||
#### 1.11.0
|
||||
* Implemented ES2021 parser with logical assignment operators and numeric separators
|
||||
|
||||
#### 1.10.4
|
||||
* Implemented parsing of coalescing operator
|
||||
* Implemented parsing of optional chaining
|
||||
* Fixed bug when parsing a semicolon on a new line after break and continue statements
|
||||
|
||||
#### 1.10.3
|
||||
* Implemented parsing of `import.meta` syntax
|
||||
* Implemented parsing of BigIntLiteral as objects keys
|
||||
|
||||
#### 1.10.2
|
||||
* Implemented parsing of `export * as ns from "source"` syntax
|
||||
* Fixed Renderer so that it won't trust computed flag in MemberExpression if property is not an Identifier
|
||||
|
||||
#### 1.10.1
|
||||
* Fixed parsing of semicolon after do-while statement
|
||||
|
||||
#### 1.10.0
|
||||
* Implemented ES2020 parser with dynamic import and BigInt
|
||||
* Implemented handling of UTF-8 and UTF-16 BOM when parsing the source
|
||||
* Fixed wrong rendering of unary and update expressions inside binary expressions in compact mode
|
||||
* __BC break__: major refactoring to delete all parsers except the base one and replace them with new Features classes that specify enabled parser features. This will remove duplicated code and makes the parser easier to extend with new features.
|
||||
|
||||
#### 1.9.4
|
||||
* Handled invalid UTF-8 characters in the source code by throwing an exception or replacing them with a substitution character by setting the new strictEncoding option to false
|
||||
* Fixed bug when rendering object properties with equal key and value
|
||||
|
||||
#### 1.9.3
|
||||
* Fixed another bug when rendering nested "if" statements with Compact formatter
|
||||
|
||||
#### 1.9.2
|
||||
* Fixed rendering of nested "if" statements with Compact formatter
|
||||
|
||||
#### 1.9.1
|
||||
* Fixed rendering of arrow functions that generates invalid code
|
||||
|
||||
#### 1.9
|
||||
* Added ES2019 parser
|
||||
|
||||
#### 1.8.1
|
||||
* Fixed parsing of regular expressions by disabling scan errors inside them
|
||||
* Added LSM utility class to handle correctly punctuators and strings stop characters
|
||||
|
||||
#### 1.8
|
||||
* Implemented parsing of JSX syntax
|
||||
|
||||
#### 1.7
|
||||
* Implemented missing features of es2018: object rest and spread, async generators and async iteration
|
||||
|
||||
#### 1.6
|
||||
* Fixed a lot of bugs and now Peast is compatible with all the [ECMAScript official tests](https://github.com/tc39/test262) for the implemented features. You can test Peast against ECMAScript tests using the [peast-test262](https://github.com/mck89/peast-test262) repository.
|
||||
* Added ES2018 parser
|
||||
|
||||
#### 1.5
|
||||
* Enabled JSON serialization of nodes and tokens using json_encode()
|
||||
* Added parsing and handling of comments
|
||||
|
||||
#### 1.4
|
||||
* Since EcmaScript dropped support for ES(Number) in favour of ES(Year) versions:
|
||||
* `ES6` namespace have been replaced by `ES2015`
|
||||
* `Peast::ES2015` method have been added to Peast main class, `Peast::ES6` method still exists to preserve BC and calls `Peast::ES2015` internally
|
||||
* `ES7` namespace have been replaced by `ES2016`
|
||||
* `Peast::ES2016` method have been added to Peast main class, `Peast::ES7` method still exists to preserve BC and calls `Peast::ES2016` internally
|
||||
* `Peast::latest` method have been added to Peast main class to allow parsing with the latest EcmaScript version implemented
|
||||
* Added ES2017 parser
|
||||
|
||||
#### 1.3
|
||||
* Refactored parser to make it more extensible
|
||||
* More accurate parsing of identifiers
|
||||
* Added parsing of HTML comments if source is not a module
|
||||
* Added some validations:
|
||||
* Disallowed legacy octal escape syntax (\07) in templates
|
||||
* Disallowed legacy octal escape syntax (\07) in strings if strict mode
|
||||
* Disallowed legacy octal syntax (077) for numbers if strict mode
|
||||
* Disallowed `delete` followed by single identifiers in strict mode
|
||||
* Disallowed labelled function declarations in strict mode
|
||||
* Allowed `if (...) function () {}` syntax if not in strict mode
|
||||
* __BC break__: removed Function_ and Class_ interfaces and traits and replaced them with abstract classes
|
||||
* __BC break__: if sourceEncoding is not specified, the parser won't try to autodetect it, but will assume UTF-8
|
||||
* __BC break__: Literal is now an abstract class that is extended by the new classes for literals: StringLiteral, NumericLiteral, BooleanLiteral and NullLiteral
|
||||
|
||||
#### 1.2
|
||||
* Added Renderer class
|
||||
|
||||
#### 1.1
|
||||
* Added Traverser class
|
||||
|
||||
#### 1.0
|
||||
* First release with ES6 and ES7 parsers
|
||||
146
vendor/mck89/peast/doc/querying-by-selector.md
vendored
Normal file
146
vendor/mck89/peast/doc/querying-by-selector.md
vendored
Normal file
@ -0,0 +1,146 @@
|
||||
Querying By Selector
|
||||
==========
|
||||
**_From version 1.12_**
|
||||
|
||||
Inspired by [esquery](https://github.com/estools/esquery) project, Peast allows you to query the generated AST using a syntax similar to CSS selectors.
|
||||
This can be done using the **Query** class:
|
||||
```php
|
||||
//Generate the AST
|
||||
$ast = Peast\Peast::latest($source, $options)->parse();
|
||||
//Query the AST
|
||||
$query = new Peast\Query($ast, $options);
|
||||
$query->find("Literal[value='search me']");
|
||||
```
|
||||
|
||||
Or you can use the shortcut method on the `Program` node (the one returned by Peast parser):
|
||||
```php
|
||||
//Generate the AST
|
||||
$ast = Peast\Peast::latest($source, $options)->parse();
|
||||
//Query the AST
|
||||
$query = $ast->query("Literal[value='search me']");
|
||||
```
|
||||
|
||||
The shortcut method returns a Query instance.
|
||||
|
||||
Options
|
||||
-------------
|
||||
The Query class constructor takes an optional associative array of options.
|
||||
Available options are:
|
||||
* "encoding": to specify the encoding of the selector, if not specified the parser will assume UTF-8.
|
||||
|
||||
Methods
|
||||
-------------
|
||||
### find
|
||||
The `find` method searches node that match the given selector starting from the current matching nodes.
|
||||
For example this code matches `FunctionDeclaration` nodes and then finds all the descendant `Literal` nodes:
|
||||
```php
|
||||
$ast->query("FunctionDeclaration")->find("Literal");
|
||||
```
|
||||
|
||||
### filter
|
||||
The `filter` method filters the current matching nodes and keeps only those that respect the given selector.
|
||||
For example this code matches `Literal` nodes and then keeps only the nodes whose value is 2:
|
||||
```php
|
||||
$ast->query("FunctionDeclaration")->filter("[value=2]");
|
||||
```
|
||||
|
||||
### count
|
||||
The `count` method returns the number of current matching nodes.
|
||||
You can also use the builtin `count` function:
|
||||
```php
|
||||
$ast->query("FunctionDeclaration")->count();
|
||||
//Or
|
||||
count($ast->query("FunctionDeclaration"));
|
||||
```
|
||||
|
||||
### get
|
||||
The `get` method returns the node at the given index:
|
||||
```php
|
||||
//Returns the first matching node
|
||||
$ast->query("FunctionDeclaration")->get(0);
|
||||
```
|
||||
|
||||
Iteration
|
||||
-------------
|
||||
You can use the Query object in a foreach to loop all the matching nodes:
|
||||
```php
|
||||
foreach ($ast->query("FunctionDeclaration") as $node) {
|
||||
//...
|
||||
}
|
||||
```
|
||||
|
||||
Selectors syntax
|
||||
-------------
|
||||
Note that Peast tries to preserve the order of the nodes in the AST, but that is not always possible, so you shouldn't rely on that.
|
||||
|
||||
### Filter by type
|
||||
You can filter nodes by their type simply writing it.
|
||||
For example `Literal` matches all the nodes whose type is Literal.
|
||||
|
||||
### Filter by attribute
|
||||
You can filter nodes by their attributes writing the name and optionally the value inside square brackets.
|
||||
There are several types of attribute filters:
|
||||
* `[value]` matches all the nodes that have a `value` attribute, without checking its value
|
||||
* `[value="test"]` matches all the nodes whose `value` attribute equals to the string "test"
|
||||
* `[value^="test"]` matches all the nodes whose `value` attribute starts with the string "test"
|
||||
* `[value*="test"]` matches all the nodes whose `value` attribute contains the string "test"
|
||||
* `[value$="test"]` matches all the nodes whose `value` attribute ends with the string "test"
|
||||
* `[value>2]` matches all the nodes whose `value` attribute is greater than 2
|
||||
* `[value>=2]` matches all the nodes whose `value` attribute is greater or equals to 2
|
||||
* `[value<2]` matches all the nodes whose `value` attribute is lower than 2
|
||||
* `[value<=2]` matches all the nodes whose `value` attribute is lower or equals to 2
|
||||
|
||||
In attributes filters the type is very important because a selector like `[value="2"]` will match a node whose `value` attribute is the string "2" but not 2 as number.
|
||||
Available types are:
|
||||
* Strings: `[value="a"]` or `[value='a']`
|
||||
* Integer numbers: `[value=123]` or `[value=0xFFF]` or `[value=0b11011]` or `[value=0o77]`
|
||||
* Decimal numbers: `[value=1.23]`
|
||||
* Booleans: `[value=true]` or `[value=false]`
|
||||
* Null: `[value=null]`
|
||||
|
||||
Strings can be escaped using the backslash character, for example `[value='That\'s great']` will find a value that equals to the string "That's great".
|
||||
|
||||
You can perform case-insensitive comparison using this syntax `[value='search' i]`.
|
||||
|
||||
You can also search using a regexp in this way: `[value=/test\d+/i]`.
|
||||
|
||||
Sometimes it's useful to check also inner attributes, you can do it by separating attributes name with a dot.
|
||||
For example `FunctionDeclaration[id.name='funcName']` matches all `FunctionDeclaration` whose `id` attribute has a `name` attribute with the value "funcName".
|
||||
|
||||
### Filter by pseudo selector
|
||||
Pseudo selectors begin with `:` and can optionally accept arguments wrapped in parentheses.
|
||||
There are 3 groups of pseudo selectors:
|
||||
|
||||
###### Simple pseudo selector
|
||||
These selectors don't accept any argument.
|
||||
* `:first-child` matches nodes that are the first child of their parent
|
||||
* `:last-child` matches nodes that are the first child of their parent
|
||||
* `:pattern` matches nodes that implement the `Pattern` interface
|
||||
* `:statement` matches nodes that implement the `Statement` interface
|
||||
* `:expression` matches nodes that implement the `Expression` interface
|
||||
* `:declaration` matches nodes that implement the `Declaration` interface
|
||||
|
||||
###### Positional pseudo selector
|
||||
These selectors accept a number or a An+B syntax, where A represents the step and B is the starting offset.
|
||||
Remember that the index is 1-based, so the first node is 1.
|
||||
You can read more about the arguments accepted by these select on [MDN](https://developer.mozilla.org/en-US/docs/Web/CSS/:nth-child).
|
||||
* `:nth-child` matches nodes that respects the given index in their parent children list. For example: `:nth-child(5n+3)` matches every 5th node starting from the 3rd one.
|
||||
* `:nth-last-child` matches nodes that respects the given index in their parent children list, starting from the end. For example: `:nth-last-child(1)` matches a node that is the last child of its parent.
|
||||
You can also use `even` and `odd` as arguments to match even and odds nodes.
|
||||
|
||||
###### Inner selector pseudo selector
|
||||
These selectors accept a inner selector.
|
||||
* `:is` matches a node that respect the given selector. For example `Literal:is([value=2], [value=3])` matches `Literal` nodes whose `value` is 2 or 3
|
||||
* `:not` matches a node that do not respect the given selector. For example `Literal:not([value=2], [value=3])` matches `Literal` nodes whose `value` is not 2 or 3
|
||||
* `:has` matches a node whose descendant match the given selector. For example `AssignmentExpression:has(Literal[value="string""])` matches `AssignmentExpression` nodes that contain `Literal` nodes whose `value` is "string"
|
||||
|
||||
### Combinators
|
||||
Combinators are used for match other nodes relative to the current.
|
||||
* Descendant: the space can be used to match descendant nodes. For example `AssignmentExpression Literal` matches `Literal` nodes inside `AssignmentExpression` nodes, even if they are not direct children
|
||||
* Children: the `>` character can be used to match child nodes. For example `ArrayExpression > Literal` matches a `Literal` nodes that are children of `ArrayExpression` nodes
|
||||
* Adjacent Sibling: the `+` character can be used to match nodes that follow other nodes. For example `FunctionDeclaration + VariableDeclaration` matches the first `VariableDeclaration` nodes that follow `FunctionDeclaration` nodes
|
||||
* General Sibling: the `~` character can be used to match all the nodes that follow other nodes. For example `FunctionDeclaration ~ VariableDeclaration` matches all the `VariableDeclaration` nodes that follow `FunctionDeclaration` nodes
|
||||
|
||||
### Groups
|
||||
A selector can contain multiple selector groups separated by commas.
|
||||
For example: `Literal, ArrayExpression` match all the `Literal` and `ArrayExpression` nodes.
|
||||
104
vendor/mck89/peast/doc/rendering.md
vendored
Normal file
104
vendor/mck89/peast/doc/rendering.md
vendored
Normal file
@ -0,0 +1,104 @@
|
||||
Rendering
|
||||
==========
|
||||
**_From version 1.2_**
|
||||
|
||||
To render an AST generated by Peast you need to create an instance of the **Renderer** class and associate a **Formatter** to it:
|
||||
```php
|
||||
$source = "var a;";
|
||||
//Generate the AST
|
||||
$ast = Peast\Peast::latest($source, $options)->parse();
|
||||
//Create the renderer
|
||||
$renderer = new Peast\Renderer;
|
||||
//Associate the formatter
|
||||
$renderer->setFormatter(new Peast\Formatter\PrettyPrint);
|
||||
//Render the AST
|
||||
echo $renderer->render($ast); //"var a;"
|
||||
```
|
||||
|
||||
Formatters
|
||||
-------------
|
||||
A Formatter specifies how the Renderer must format the nodes to produce the output.
|
||||
Peast implements 3 formatters: **PrettyPrint**, **Compact** and **Expanded**.
|
||||
|
||||
For example using this source code:
|
||||
```js
|
||||
if (fn(param)) alert("Ok");
|
||||
else alert("Fail");
|
||||
```
|
||||
|
||||
##### PrettyPrint
|
||||
Produces a well formatted version of the code.
|
||||
```js
|
||||
if (fn(param)) {
|
||||
alert("Ok");
|
||||
} else {
|
||||
alert("Fail");
|
||||
}
|
||||
```
|
||||
|
||||
##### Compact
|
||||
Produces a compact version of the code by removing whitespaces and optional brackets.
|
||||
```js
|
||||
if (fn(param))alert("Ok");else alert("Fail");
|
||||
```
|
||||
|
||||
##### Expanded
|
||||
An expanded version of PrettyPrint.
|
||||
```js
|
||||
if ( fn( param ) )
|
||||
{
|
||||
alert( "Ok" );
|
||||
} else
|
||||
{
|
||||
alert( "Fail" );
|
||||
}
|
||||
```
|
||||
|
||||
Custom Formatter
|
||||
-------------
|
||||
Peast allows you to create your own formatter.
|
||||
You can do it by creating a class that extends `Peast\Formatter\Base` class and overwriting its protected properties:
|
||||
|
||||
```php
|
||||
class MyFormatter extends Peast\Formatter\Base {
|
||||
//Use Windows style line endings
|
||||
protected $newLine = "\r\n";
|
||||
}
|
||||
$renderer = new Peast\Renderer;
|
||||
$renderer->setFormatter(new MyFormatter);
|
||||
echo $renderer->render($ast);
|
||||
```
|
||||
|
||||
Available properties are:
|
||||
* `$newLine`: line separator string (default: `"\n"`)
|
||||
* `$indentation`: indentation string (default: `"\t"`)
|
||||
* `$newLineBeforeCurlyBracket`: if true, open curly brackets of code blocks will be put on a new line (default: `false`)
|
||||
* `$alwaysWrapBlocks`: if true, curly brackets around code blocks will always be inserted, also when they are optional (default: `true`)
|
||||
* `$spacesAroundOperators`: if true, a space will be inserted before and after operators (default: `true`)
|
||||
* `$spacesInsideRoundBrackets`: if true, content inside round brackets will be surrounded by spaces (default: `false`)
|
||||
|
||||
Shortcut method
|
||||
-------------
|
||||
Every syntax node has its own `render` method that you can use as a shortcut.
|
||||
For example:
|
||||
|
||||
```php
|
||||
$ast = Peast\Peast::latest($source, $options)->parse();
|
||||
$ast->render(new Peast\Formatter\PrettyPrint);
|
||||
//Equivalent to
|
||||
$ast = Peast\Peast::latest($source, $options)->parse();
|
||||
$renderer = new Peast\Renderer;
|
||||
$renderer->setFormatter(new Peast\Formatter\PrettyPrint);
|
||||
$renderer->render($ast);
|
||||
```
|
||||
|
||||
Comments rendering
|
||||
-------------
|
||||
**_From version 1.14_**
|
||||
Comments can be rendered by passing `true` to the formatter constructor:
|
||||
```php
|
||||
$ast = Peast\Peast::latest($source, array("comments" => true))->parse();
|
||||
$ast->render(new Peast\Formatter\PrettyPrint(true));
|
||||
```
|
||||
Note that comments can be rendered only when parser is enabled to collect them, to do this you must set the `comments` option to `true`.
|
||||
Also note that only PrettyPrint and Expanded formatters allow comments rendering, while Compact does not allow it by default.
|
||||
120
vendor/mck89/peast/doc/tree-traversing.md
vendored
Normal file
120
vendor/mck89/peast/doc/tree-traversing.md
vendored
Normal file
@ -0,0 +1,120 @@
|
||||
Tree Traversing
|
||||
==========
|
||||
**_From version 1.1_**
|
||||
|
||||
To traverse an AST generated by Peast you can use the **Traverser** class:
|
||||
```php
|
||||
//Generate the AST
|
||||
$ast = Peast\Peast::latest($source, $options)->parse();
|
||||
//Set up the Traverser
|
||||
$traverser = new Peast\Traverser;
|
||||
$traverser->addFunction(function ($node) {
|
||||
//Do something with the current node
|
||||
});
|
||||
//Start traversing
|
||||
$traverser->traverse($ast);
|
||||
```
|
||||
|
||||
You can add one or more functions to the Traverser using the `addFunction` method. These functions receive the current traversed node while the Traverser runs on the tree.
|
||||
|
||||
The `traverse` method runs the traversing starting from the given node.
|
||||
|
||||
Options
|
||||
-------------
|
||||
|
||||
**_From version 1.12_**
|
||||
The Traverser class constructor takes an optional associative array of options.
|
||||
Available options are:
|
||||
* "skipStartingNode": by default the traversing begins with the starting node passed to the `traverse` method. If this option is set to true the starting node will be ignored.
|
||||
* "passParentNode": by default the functions added to the Traverser receive the traversed node as the only argument. if this option is set to true the node's parent node will be passed as second argument to all the functions. Note that the parent node is calculated during traversing, so for the starting node it will always be null.
|
||||
|
||||
Tree manipulation
|
||||
-------------
|
||||
Functions added to the Traverser instance can alter the tree during the traversing by modifying, replacing or removing the node they receive and they can also control the behaviour of the Traverser to make it stop or skip the node's children.
|
||||
|
||||
Traverser class provides some constants to perform these operations:
|
||||
* `Traverser::REMOVE_NODE`: removes the node
|
||||
* `Traverser::DONT_TRAVERSE_CHILD_NODES`: skips the node's children
|
||||
* `Traverser::STOP_TRAVERSING`: stops the traversing
|
||||
|
||||
The action that will be executed depends on the value returned by the functions.
|
||||
|
||||
If you want to remove a node the function must return the `Traverser::REMOVE_NODE` constant:
|
||||
```php
|
||||
$traverser->addFunction(function ($node) {
|
||||
//Remove all literal nodes
|
||||
if ($node->getType() === "Literal") {
|
||||
return Peast\Traverser::REMOVE_NODE;
|
||||
}
|
||||
});
|
||||
```
|
||||
|
||||
If you want to control the traversing you can return `Traverser::DONT_TRAVERSE_CHILD_NODES` or `Traverser::STOP_TRAVERSING` constants:
|
||||
```php
|
||||
$traverser->addFunction(function ($node) {
|
||||
//Skip nodes inside array expressions
|
||||
if ($node->getType() === "ArrayExpression") {
|
||||
return Peast\Traverser::DONT_TRAVERSE_CHILD_NODES;
|
||||
}
|
||||
//Stop the traversing when an identifier named "stop" is found
|
||||
elseif ($node->getType() === "Identifier" && $node->getName() === "stop") {
|
||||
return Peast\Traverser::STOP_TRAVERSING;
|
||||
}
|
||||
});
|
||||
```
|
||||
|
||||
You can also return a combination of these constants:
|
||||
```php
|
||||
$traverser->addFunction(function ($node) {
|
||||
//Remove the string "test" and then stop the traversing
|
||||
if ($node->getType() === "Literal" && $node->getValue() === "test") {
|
||||
return Peast\Traverser::REMOVE_NODE | Peast\Traverser::STOP_TRAVERSING;
|
||||
}
|
||||
});
|
||||
```
|
||||
|
||||
To replace a node you must return the replacement node:
|
||||
```php
|
||||
$traverser->addFunction(function ($node) {
|
||||
//Replace the number 2 with 1
|
||||
if ($node->getType() === "Literal" && $node->getValue() === 2) {
|
||||
$literal = new \Peast\Syntax\Node\NumericLiteral();
|
||||
return $literal->setValue(1);
|
||||
}
|
||||
});
|
||||
```
|
||||
|
||||
You can also control the traversing and replace a node in the same function:
|
||||
```php
|
||||
$traverser->addFunction(function ($node) {
|
||||
//Replace an array expression with an object expression without traversing its children
|
||||
if ($node->getType() === "ArrayExpression") {
|
||||
$obj = new \Peast\Syntax\Node\ObjectExpression();
|
||||
return array($obj, Peast\Traverser::DONT_TRAVERSE_CHILD_NODES);
|
||||
}
|
||||
});
|
||||
```
|
||||
|
||||
If the function returns any other value or nothing, no action will be executed and you can modify nodes without altering the tree structure:
|
||||
```php
|
||||
use Peast\Syntax\Node\StringLiteral;
|
||||
$traverser->addFunction(function ($node) {
|
||||
//Make all the strings uppercase
|
||||
if ($node->getType() === "Literal" && $node instanceof StringLiteral) {
|
||||
$node->setValue(strtoupper($node->getValue()));
|
||||
}
|
||||
});
|
||||
```
|
||||
|
||||
Shortcut method
|
||||
-------------
|
||||
|
||||
Every node implements a `traverse` method as a shortcut to initialize a traverser on itself:
|
||||
```php
|
||||
$traversingFn = function ($node) { /* ... */ };
|
||||
//Traverse $ast node
|
||||
$ast->traverse($traversingFn, $options);
|
||||
//Equivalent to
|
||||
$traverser = new Peast\Traverser;
|
||||
$traverser->addFunction($traversingFn)->traverse($ast);
|
||||
```
|
||||
182
vendor/mck89/peast/lib/Peast/Formatter/Base.php
vendored
Normal file
182
vendor/mck89/peast/lib/Peast/Formatter/Base.php
vendored
Normal file
@ -0,0 +1,182 @@
|
||||
<?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;
|
||||
}
|
||||
}
|
||||
54
vendor/mck89/peast/lib/Peast/Formatter/Compact.php
vendored
Normal file
54
vendor/mck89/peast/lib/Peast/Formatter/Compact.php
vendored
Normal file
@ -0,0 +1,54 @@
|
||||
<?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;
|
||||
}
|
||||
34
vendor/mck89/peast/lib/Peast/Formatter/Expanded.php
vendored
Normal file
34
vendor/mck89/peast/lib/Peast/Formatter/Expanded.php
vendored
Normal file
@ -0,0 +1,34 @@
|
||||
<?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;
|
||||
}
|
||||
19
vendor/mck89/peast/lib/Peast/Formatter/PrettyPrint.php
vendored
Normal file
19
vendor/mck89/peast/lib/Peast/Formatter/PrettyPrint.php
vendored
Normal file
@ -0,0 +1,19 @@
|
||||
<?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
|
||||
{
|
||||
}
|
||||
190
vendor/mck89/peast/lib/Peast/Peast.php
vendored
Normal file
190
vendor/mck89/peast/lib/Peast/Peast.php
vendored
Normal file
@ -0,0 +1,190 @@
|
||||
<?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 ES2025(string $source, array $options = array())
|
||||
* Returns a parser instance with ES2025 features for the given source. See Peast
|
||||
* class documentation to understand function arguments.
|
||||
*
|
||||
* @method static Syntax\Parser ES16(string $source, array $options = array())
|
||||
* Returns a parser instance with ES2025 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",
|
||||
"ES16" => "ES2025"
|
||||
);
|
||||
|
||||
/**
|
||||
* 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
|
||||
);
|
||||
}
|
||||
}
|
||||
123
vendor/mck89/peast/lib/Peast/Query.php
vendored
Normal file
123
vendor/mck89/peast/lib/Peast/Query.php
vendored
Normal file
@ -0,0 +1,123 @@
|
||||
<?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;
|
||||
|
||||
/**
|
||||
* Nodes query class
|
||||
*
|
||||
* @author Marco Marchiò <marco.mm89@gmail.com>
|
||||
*/
|
||||
class Query implements \IteratorAggregate, \Countable
|
||||
{
|
||||
/**
|
||||
* Current matches
|
||||
*
|
||||
* @var Selector\Matches
|
||||
*/
|
||||
protected $matches;
|
||||
|
||||
/**
|
||||
* Options array
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $options;
|
||||
|
||||
/**
|
||||
* Class constructor. Available options are:
|
||||
* - encoding: selectors encoding. If not specified the
|
||||
* parser will assume UTF-8.
|
||||
*
|
||||
* @param Syntax\Node\Program $root Root node
|
||||
* @param array $options Options array
|
||||
*/
|
||||
public function __construct(Syntax\Node\Program $root, $options = array())
|
||||
{
|
||||
$this->matches = new Selector\Matches();
|
||||
$this->matches->addMatch($root);
|
||||
$this->options = $options;
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds nodes matching the given selector starting from the
|
||||
* current matched nodes, if any, or from the root
|
||||
*
|
||||
* @param string $selector Selector
|
||||
*
|
||||
* @return $this
|
||||
*
|
||||
* @throws Selector\Exception
|
||||
*/
|
||||
public function find($selector)
|
||||
{
|
||||
$parser = new Selector\Parser($selector, $this->options);
|
||||
$selector = $parser->parse();
|
||||
$this->matches = $selector->exec($this->matches);
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Executes the given selector on the current nodes and filters
|
||||
* out the nodes which don't match
|
||||
*
|
||||
* @param string $selector Selector
|
||||
*
|
||||
* @return $this
|
||||
*
|
||||
* @throws Selector\Exception
|
||||
*/
|
||||
public function filter($selector)
|
||||
{
|
||||
$parser = new Selector\Parser($selector, $this->options);
|
||||
$selector = $parser->parse(true);
|
||||
$this->matches->filter(function ($node, $parent) use ($selector) {
|
||||
$newMatch = new Selector\Matches();
|
||||
$newMatch->addMatch($node, $parent);
|
||||
return $selector->exec($newMatch)->getMatches();
|
||||
});
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the number of matched nodes
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
#[\ReturnTypeWillChange]
|
||||
public function count()
|
||||
{
|
||||
return $this->matches->count();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the node at the given index
|
||||
*
|
||||
* @param int $index Index
|
||||
*
|
||||
* @return array
|
||||
*
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function get($index)
|
||||
{
|
||||
return $this->matches->get($index)[0];
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the nodes iterator
|
||||
*
|
||||
* @return \ArrayIterator
|
||||
*/
|
||||
#[\ReturnTypeWillChange]
|
||||
public function getIterator()
|
||||
{
|
||||
return new \ArrayIterator($this->matches->getNodes());
|
||||
}
|
||||
}
|
||||
1255
vendor/mck89/peast/lib/Peast/Renderer.php
vendored
Normal file
1255
vendor/mck89/peast/lib/Peast/Renderer.php
vendored
Normal file
File diff suppressed because it is too large
Load Diff
22
vendor/mck89/peast/lib/Peast/Selector/Exception.php
vendored
Normal file
22
vendor/mck89/peast/lib/Peast/Selector/Exception.php
vendored
Normal file
@ -0,0 +1,22 @@
|
||||
<?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
|
||||
{
|
||||
}
|
||||
185
vendor/mck89/peast/lib/Peast/Selector/Matches.php
vendored
Normal file
185
vendor/mck89/peast/lib/Peast/Selector/Matches.php
vendored
Normal file
@ -0,0 +1,185 @@
|
||||
<?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;
|
||||
|
||||
use Peast\Syntax\Node\Node;
|
||||
|
||||
/**
|
||||
* Selector matches class
|
||||
*
|
||||
* @author Marco Marchiò <marco.mm89@gmail.com>
|
||||
*/
|
||||
class Matches
|
||||
{
|
||||
/**
|
||||
* Matches array
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $matches;
|
||||
|
||||
/**
|
||||
* Class constructor
|
||||
*
|
||||
* @param array $matches Matches
|
||||
*/
|
||||
public function __construct($matches = array())
|
||||
{
|
||||
$this->matches = $matches;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a new match
|
||||
*
|
||||
* @param Node $node
|
||||
* @param Node|null $parent
|
||||
*/
|
||||
public function addMatch(Node $node, $parent = null)
|
||||
{
|
||||
$this->matches[] = array($node, $parent);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the matches
|
||||
*
|
||||
* @returns array
|
||||
*/
|
||||
public function getMatches()
|
||||
{
|
||||
return $this->matches;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the matched nodes
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getNodes() {
|
||||
return array_map(function ($m) {
|
||||
return $m[0];
|
||||
}, $this->matches);
|
||||
}
|
||||
|
||||
/**
|
||||
* Filters the matches using the given function, if it returns
|
||||
* a false value the match will be removed. The function will
|
||||
* receive the node and its parent as arguments.
|
||||
*
|
||||
* @param callable $fn Filter function
|
||||
* @return $this
|
||||
*/
|
||||
public function filter(callable $fn)
|
||||
{
|
||||
$newMatches = array();
|
||||
foreach ($this->matches as $match) {
|
||||
if ($fn($match[0], $match[1])) {
|
||||
$newMatches[] = $match;
|
||||
}
|
||||
}
|
||||
$this->matches = $newMatches;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Replaces all the matches with the result of the given function.
|
||||
* The function will receive the node and its parent as arguments
|
||||
* and must return an array of matches
|
||||
*
|
||||
* @param callable $fn Map function
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function map(callable $fn)
|
||||
{
|
||||
$newMatches = array();
|
||||
foreach ($this->matches as $match) {
|
||||
$res = $fn($match[0], $match[1]);
|
||||
if ($res) {
|
||||
$newMatches = array_merge($newMatches, $res);
|
||||
}
|
||||
}
|
||||
$this->matches = $newMatches;
|
||||
return $this->unique();
|
||||
}
|
||||
|
||||
/**
|
||||
* Merges the current object with the other given Matches objects
|
||||
*
|
||||
* @param Matches[] $matchesArr Array of Matches to merge
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function merge($matchesArr)
|
||||
{
|
||||
foreach ($matchesArr as $matches) {
|
||||
foreach ($matches->getMatches() as $match) {
|
||||
$this->addMatch($match[0], $match[1]);
|
||||
}
|
||||
}
|
||||
return $this->unique();
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove all duplicated matches
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function unique()
|
||||
{
|
||||
$newMatches = array();
|
||||
$newNodes = array();
|
||||
foreach ($this->matches as $match) {
|
||||
if (!in_array($match[0], $newNodes, true)) {
|
||||
$newMatches[] = $match;
|
||||
$newNodes[] = $match[0];
|
||||
}
|
||||
}
|
||||
$this->matches = $newMatches;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a clone of the current object
|
||||
*
|
||||
* @return Matches
|
||||
*/
|
||||
public function createClone()
|
||||
{
|
||||
return new self($this->matches);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the number of matches
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function count()
|
||||
{
|
||||
return count($this->matches);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the match at the given index
|
||||
*
|
||||
* @param int $index Index
|
||||
*
|
||||
* @return array
|
||||
*
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function get($index)
|
||||
{
|
||||
$index = (int) $index;
|
||||
if (!isset($this->matches[$index])) {
|
||||
throw new \Exception("Invalid index $index");
|
||||
}
|
||||
return $this->matches[$index];
|
||||
}
|
||||
}
|
||||
139
vendor/mck89/peast/lib/Peast/Selector/Node/Combinator.php
vendored
Normal file
139
vendor/mck89/peast/lib/Peast/Selector/Node/Combinator.php
vendored
Normal file
@ -0,0 +1,139 @@
|
||||
<?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\Node;
|
||||
|
||||
use Peast\Selector\Matches;
|
||||
use Peast\Syntax\Utils;
|
||||
use Peast\Traverser;
|
||||
|
||||
/**
|
||||
* Selector combinator class
|
||||
*
|
||||
* @author Marco Marchiò <marco.mm89@gmail.com>
|
||||
*/
|
||||
class Combinator
|
||||
{
|
||||
/**
|
||||
* Operator
|
||||
*
|
||||
* @var string|null
|
||||
*/
|
||||
protected $operator;
|
||||
|
||||
/**
|
||||
* Selector parts
|
||||
*
|
||||
* @var Part\Part[]
|
||||
*/
|
||||
protected $parts = array();
|
||||
|
||||
/**
|
||||
* Sets the operator
|
||||
*
|
||||
* @param string $operator Operator
|
||||
* @return $this
|
||||
*/
|
||||
public function setOperator($operator)
|
||||
{
|
||||
$this->operator = $operator;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a new selector part
|
||||
*
|
||||
* @param Part\Part $part Part
|
||||
* @return $this
|
||||
*/
|
||||
public function addPart(Part\Part $part)
|
||||
{
|
||||
$this->parts[] = $part;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Executes the current group on the given matches
|
||||
*
|
||||
* @param Matches $matches Matches
|
||||
*/
|
||||
public function exec(Matches $matches)
|
||||
{
|
||||
$parts = $this->parts;
|
||||
//Sort the parts by priority to execute faster checks first
|
||||
usort($parts, function ($p1, $p2) {
|
||||
$pr1 = $p1->getPriority();
|
||||
$pr2 = $p2->getPriority();
|
||||
if ($pr1 === $pr2) {
|
||||
return 0;
|
||||
} elseif ($pr1 < $pr2) {
|
||||
return -1;
|
||||
} else {
|
||||
return 1;
|
||||
}
|
||||
});
|
||||
$filter = function ($node, $parent) use ($parts) {
|
||||
foreach ($parts as $part) {
|
||||
if (!$part->check($node, $parent)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
};
|
||||
switch ($this->operator) {
|
||||
case " ":
|
||||
case ">":
|
||||
$children = $this->operator === ">";
|
||||
$matches->map(function ($curNode) use ($filter, $children) {
|
||||
$ret = array();
|
||||
$curNode->traverse(
|
||||
function ($node, $parent) use ($filter, $children, &$ret) {
|
||||
if ($filter($node, $parent)) {
|
||||
$ret[] = array($node, $parent);
|
||||
}
|
||||
if ($children) {
|
||||
return Traverser::DONT_TRAVERSE_CHILD_NODES;
|
||||
}
|
||||
},
|
||||
array(
|
||||
"skipStartingNode" => true,
|
||||
"passParentNode" => true
|
||||
)
|
||||
);
|
||||
return $ret;
|
||||
});
|
||||
break;
|
||||
case "~":
|
||||
case "+":
|
||||
$adjacent = $this->operator === "+";
|
||||
$matches->map(function ($node, $parent) use ($filter, $adjacent) {
|
||||
$ret = array();
|
||||
$evaluate = false;
|
||||
$props = $parent ? Utils::getExpandedNodeProperties($parent) : array();
|
||||
foreach ($props as $propNode) {
|
||||
if ($evaluate) {
|
||||
if ($propNode && $filter($propNode, $parent)) {
|
||||
$ret[] = array($propNode, $parent);
|
||||
}
|
||||
if ($adjacent) {
|
||||
break;
|
||||
}
|
||||
} elseif ($propNode === $node) {
|
||||
$evaluate = true;
|
||||
}
|
||||
}
|
||||
return $ret;
|
||||
});
|
||||
break;
|
||||
default:
|
||||
$matches->filter($filter);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
52
vendor/mck89/peast/lib/Peast/Selector/Node/Group.php
vendored
Normal file
52
vendor/mck89/peast/lib/Peast/Selector/Node/Group.php
vendored
Normal file
@ -0,0 +1,52 @@
|
||||
<?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\Node;
|
||||
|
||||
use Peast\Selector\Matches;
|
||||
|
||||
/**
|
||||
* Selector group class
|
||||
*
|
||||
* @author Marco Marchiò <marco.mm89@gmail.com>
|
||||
*/
|
||||
class Group
|
||||
{
|
||||
/**
|
||||
* Selector combinators
|
||||
*
|
||||
* @var Combinator[]
|
||||
*/
|
||||
protected $combinators = array();
|
||||
|
||||
/**
|
||||
* Adds a combinator
|
||||
*
|
||||
* @param Combinator $combinators Combinator
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function addCombinator(Combinator $combinators)
|
||||
{
|
||||
$this->combinators[] = $combinators;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Executes the current group on the given matches
|
||||
*
|
||||
* @param Matches $matches Matches
|
||||
*/
|
||||
public function exec(Matches $matches)
|
||||
{
|
||||
foreach ($this->combinators as $combinator) {
|
||||
$combinator->exec($matches);
|
||||
}
|
||||
}
|
||||
}
|
||||
228
vendor/mck89/peast/lib/Peast/Selector/Node/Part/Attribute.php
vendored
Normal file
228
vendor/mck89/peast/lib/Peast/Selector/Node/Part/Attribute.php
vendored
Normal file
@ -0,0 +1,228 @@
|
||||
<?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\Node\Part;
|
||||
|
||||
use Peast\Syntax\Node\Node;
|
||||
use Peast\Syntax\Utils;
|
||||
|
||||
/**
|
||||
* Selector part attribute class
|
||||
*
|
||||
* @author Marco Marchiò <marco.mm89@gmail.com>
|
||||
*/
|
||||
class Attribute extends Part
|
||||
{
|
||||
/**
|
||||
* Priority
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $priority = 4;
|
||||
|
||||
/**
|
||||
* Attribute names
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $names = array();
|
||||
|
||||
/**
|
||||
* Attribute match operator
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $operator = null;
|
||||
|
||||
/**
|
||||
* Attribute value
|
||||
*
|
||||
* @var mixed
|
||||
*/
|
||||
protected $value = null;
|
||||
|
||||
/**
|
||||
* Case insensitive flag
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $caseInsensitive = false;
|
||||
|
||||
/**
|
||||
* Regex flag
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $regex = false;
|
||||
|
||||
/**
|
||||
* Adds a name
|
||||
*
|
||||
* @param string $name Name
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function addName($name)
|
||||
{
|
||||
$this->names[] = $name;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the operator
|
||||
*
|
||||
* @param string $operator Operator
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setOperator($operator)
|
||||
{
|
||||
$this->operator = $operator;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the value
|
||||
*
|
||||
* @param mixed $value Value
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setValue($value)
|
||||
{
|
||||
$this->value = $value;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the case insensitive flag
|
||||
*
|
||||
* @param bool $caseInsensitive Case insensitive flag
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setCaseInsensitive($caseInsensitive)
|
||||
{
|
||||
$this->caseInsensitive = $caseInsensitive;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the regex flag
|
||||
*
|
||||
* @param bool $regex Regex flag
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setRegex($regex)
|
||||
{
|
||||
$this->regex = $regex;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the selector part matches the given node,
|
||||
* false otherwise
|
||||
*
|
||||
* @param Node $node Node
|
||||
* @param Node $parent Parent node
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function check(Node $node, $parent = null)
|
||||
{
|
||||
$attr = $node;
|
||||
foreach ($this->names as $name) {
|
||||
$attrFound = false;
|
||||
if ($attr instanceof Node) {
|
||||
$props = Utils::getNodeProperties($attr);
|
||||
foreach ($props as $prop) {
|
||||
if ($prop["name"] === $name) {
|
||||
$attrFound = true;
|
||||
$attr = $attr->{$prop["getter"]}();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!$attrFound) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
$bothStrings = is_string($attr) && is_string($this->value);
|
||||
switch ($this->operator) {
|
||||
case "=":
|
||||
if ($bothStrings) {
|
||||
if ($this->regex) {
|
||||
return preg_match($this->value, $attr);
|
||||
}
|
||||
return $this->compareStr(
|
||||
$this->value, $attr, $this->caseInsensitive, true, true
|
||||
);
|
||||
}
|
||||
if (is_int($attr) && is_float($this->value)) {
|
||||
return (float) $attr === $this->value;
|
||||
}
|
||||
return $attr === $this->value;
|
||||
case "<":
|
||||
if (is_float($this->value) && !is_float($attr) && !is_int($attr) && !is_string($attr)) {
|
||||
return false;
|
||||
}
|
||||
return $attr < $this->value;
|
||||
case ">":
|
||||
if (is_float($this->value) && !is_float($attr) && !is_int($attr) && !is_string($attr)) {
|
||||
return false;
|
||||
}
|
||||
return $attr > $this->value;
|
||||
case "<=":
|
||||
if (is_float($this->value) && !is_float($attr) && !is_int($attr) && !is_string($attr)) {
|
||||
return false;
|
||||
}
|
||||
return $attr <= $this->value;
|
||||
case ">=":
|
||||
if (is_float($this->value) && !is_float($attr) && !is_int($attr) && !is_string($attr)) {
|
||||
return false;
|
||||
}
|
||||
return $attr >= $this->value;
|
||||
case "^=":
|
||||
case "$=":
|
||||
case "*=":
|
||||
return $this->compareStr(
|
||||
$this->value, $attr, $this->caseInsensitive,
|
||||
$this->operator === "^=",
|
||||
$this->operator === "$="
|
||||
);
|
||||
default:
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Compares two strings
|
||||
*
|
||||
* @param string $v1 Search value
|
||||
* @param string $v2 Compare value
|
||||
* @param bool $caseInsensitive True if the search must be case insensitive
|
||||
* @param bool $matchStart True if the search must be executed from the
|
||||
* beginning of the string
|
||||
* @param bool $matchEnd True if the search must be executed from the
|
||||
* end of the string
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected function compareStr($v1, $v2, $caseInsensitive, $matchStart, $matchEnd)
|
||||
{
|
||||
$regex = "#" .
|
||||
($matchStart ? "^" : "") .
|
||||
preg_quote($v1) .
|
||||
($matchEnd ? "$" : "") .
|
||||
"#u" .
|
||||
($caseInsensitive ? "i" : "");
|
||||
return (bool) preg_match($regex, $v2);
|
||||
}
|
||||
}
|
||||
47
vendor/mck89/peast/lib/Peast/Selector/Node/Part/Part.php
vendored
Normal file
47
vendor/mck89/peast/lib/Peast/Selector/Node/Part/Part.php
vendored
Normal file
@ -0,0 +1,47 @@
|
||||
<?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\Node\Part;
|
||||
|
||||
use Peast\Syntax\Node\Node;
|
||||
|
||||
/**
|
||||
* Selector part base class
|
||||
*
|
||||
* @author Marco Marchiò <marco.mm89@gmail.com>
|
||||
*
|
||||
* @abstract
|
||||
*/
|
||||
abstract class Part
|
||||
{
|
||||
/**
|
||||
* Priority
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $priority = 5;
|
||||
|
||||
public function getPriority()
|
||||
{
|
||||
return $this->priority;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the selector part matches the given node,
|
||||
* false otherwise
|
||||
*
|
||||
* @param Node $node Node
|
||||
* @param Node $parent Parent node
|
||||
*
|
||||
* @return bool
|
||||
*
|
||||
* @abstract
|
||||
*/
|
||||
abstract public function check(Node $node, $parent = null);
|
||||
}
|
||||
40
vendor/mck89/peast/lib/Peast/Selector/Node/Part/Pseudo.php
vendored
Normal file
40
vendor/mck89/peast/lib/Peast/Selector/Node/Part/Pseudo.php
vendored
Normal file
@ -0,0 +1,40 @@
|
||||
<?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\Node\Part;
|
||||
|
||||
/**
|
||||
* Selector pseudo part base class
|
||||
*
|
||||
* @author Marco Marchiò <marco.mm89@gmail.com>
|
||||
*
|
||||
* @abstract
|
||||
*/
|
||||
abstract class Pseudo extends Part
|
||||
{
|
||||
/**
|
||||
* Selector name
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $name;
|
||||
|
||||
/**
|
||||
* Sets the name
|
||||
*
|
||||
* @param string $name Name
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setName($name)
|
||||
{
|
||||
$this->name = $name;
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
108
vendor/mck89/peast/lib/Peast/Selector/Node/Part/PseudoIndex.php
vendored
Normal file
108
vendor/mck89/peast/lib/Peast/Selector/Node/Part/PseudoIndex.php
vendored
Normal file
@ -0,0 +1,108 @@
|
||||
<?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\Node\Part;
|
||||
|
||||
use Peast\Syntax\Node\Node;
|
||||
use Peast\Syntax\Utils;
|
||||
|
||||
/**
|
||||
* Selector part index pseudo class
|
||||
*
|
||||
* @author Marco Marchiò <marco.mm89@gmail.com>
|
||||
*/
|
||||
class PseudoIndex extends Pseudo
|
||||
{
|
||||
/**
|
||||
* Priority
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $priority = 2;
|
||||
|
||||
/**
|
||||
* Step
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $step = 0;
|
||||
|
||||
/**
|
||||
* Offset
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $offset = 0;
|
||||
|
||||
/**
|
||||
* Sets the step
|
||||
*
|
||||
* @param int $step Step
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setStep($step)
|
||||
{
|
||||
$this->step = $step;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the offset
|
||||
*
|
||||
* @param int $offset Offset
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setOffset($offset)
|
||||
{
|
||||
$this->offset = $offset;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the selector part matches the given node,
|
||||
* false otherwise
|
||||
*
|
||||
* @param Node $node Node
|
||||
* @param Node $parent Parent node
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function check(Node $node, $parent = null)
|
||||
{
|
||||
$props = Utils::getExpandedNodeProperties($parent);
|
||||
$count = count($props);
|
||||
$reverse = $this->name === "nth-last-child";
|
||||
if ($reverse) {
|
||||
$start = $count - 1 - ($this->offset - 1);
|
||||
$step = $this->step * -1;
|
||||
if ($step > 0) {
|
||||
$reverse = false;
|
||||
}
|
||||
} else {
|
||||
$start = $this->offset - 1;
|
||||
$step = $this->step;
|
||||
if ($step < 0) {
|
||||
$reverse = true;
|
||||
}
|
||||
}
|
||||
//Step 0 will cause an infinite loop, so it must be set to the
|
||||
//number of props so that it will execute only one iteration
|
||||
if (!$step) {
|
||||
$step = $reverse ? -$count : $count;
|
||||
}
|
||||
for ($i = $start; ($reverse && $i >= 0) || (!$reverse && $i < $count); $i += $step) {
|
||||
if (isset($props[$i]) && $props[$i] === $node) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
66
vendor/mck89/peast/lib/Peast/Selector/Node/Part/PseudoSelector.php
vendored
Normal file
66
vendor/mck89/peast/lib/Peast/Selector/Node/Part/PseudoSelector.php
vendored
Normal file
@ -0,0 +1,66 @@
|
||||
<?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\Node\Part;
|
||||
|
||||
use Peast\Selector\Matches;
|
||||
use Peast\Selector\Node\Selector;
|
||||
use Peast\Syntax\Node\Node;
|
||||
|
||||
/**
|
||||
* Selector part selector pseudo class
|
||||
*
|
||||
* @author Marco Marchiò <marco.mm89@gmail.com>
|
||||
*/
|
||||
class PseudoSelector extends Pseudo
|
||||
{
|
||||
/**
|
||||
* Priority
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $priority = 1;
|
||||
|
||||
/**
|
||||
* Selector
|
||||
*
|
||||
* @var Selector
|
||||
*/
|
||||
protected $selector;
|
||||
|
||||
/**
|
||||
* Sets the selector
|
||||
*
|
||||
* @param Selector $selector Selector
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setSelector(Selector $selector)
|
||||
{
|
||||
$this->selector = $selector;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the selector part matches the given node,
|
||||
* false otherwise
|
||||
*
|
||||
* @param Node $node Node
|
||||
* @param Node $parent Parent node
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function check(Node $node, $parent = null)
|
||||
{
|
||||
$match = new Matches();
|
||||
$match->addMatch($node, $parent);
|
||||
$res = $this->selector->exec($match)->count();
|
||||
return $this->name === "not" ? $res === 0 : $res !== 0;
|
||||
}
|
||||
}
|
||||
62
vendor/mck89/peast/lib/Peast/Selector/Node/Part/PseudoSimple.php
vendored
Normal file
62
vendor/mck89/peast/lib/Peast/Selector/Node/Part/PseudoSimple.php
vendored
Normal file
@ -0,0 +1,62 @@
|
||||
<?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\Node\Part;
|
||||
|
||||
use Peast\Syntax\Node\Node;
|
||||
use Peast\Syntax\Node\Pattern;
|
||||
use Peast\Syntax\Node\Statement;
|
||||
use Peast\Syntax\Node\Expression;
|
||||
use Peast\Syntax\Node\Declaration;
|
||||
use Peast\Syntax\Utils;
|
||||
|
||||
/**
|
||||
* Selector part simple pseudo class
|
||||
*
|
||||
* @author Marco Marchiò <marco.mm89@gmail.com>
|
||||
*/
|
||||
class PseudoSimple extends Pseudo
|
||||
{
|
||||
/**
|
||||
* Priority
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $priority = 3;
|
||||
|
||||
/**
|
||||
* Returns true if the selector part matches the given node,
|
||||
* false otherwise
|
||||
*
|
||||
* @param Node $node Node
|
||||
* @param Node $parent Parent node
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function check(Node $node, $parent = null)
|
||||
{
|
||||
switch ($this->name) {
|
||||
case "pattern":
|
||||
return $node instanceof Pattern;
|
||||
case "statement":
|
||||
return $node instanceof Statement;
|
||||
case "expression":
|
||||
return $node instanceof Expression;
|
||||
case "declaration":
|
||||
return $node instanceof Declaration;
|
||||
case "last-child":
|
||||
case "first-child":
|
||||
$first = $this->name === "first-child";
|
||||
$props = Utils::getExpandedNodeProperties($parent);
|
||||
return count($props) > 0 && (
|
||||
$first ? $props[0] === $node : array_pop($props) === $node
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
54
vendor/mck89/peast/lib/Peast/Selector/Node/Part/Type.php
vendored
Normal file
54
vendor/mck89/peast/lib/Peast/Selector/Node/Part/Type.php
vendored
Normal file
@ -0,0 +1,54 @@
|
||||
<?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\Node\Part;
|
||||
|
||||
use Peast\Syntax\Node\Node;
|
||||
|
||||
/**
|
||||
* Selector part type class
|
||||
*
|
||||
* @author Marco Marchiò <marco.mm89@gmail.com>
|
||||
*/
|
||||
class Type extends Part
|
||||
{
|
||||
/**
|
||||
* Selector type
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $type;
|
||||
|
||||
/**
|
||||
* Sets the selector type
|
||||
*
|
||||
* @param string $type Type
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setType($type)
|
||||
{
|
||||
$this->type = $type;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the selector part matches the given node,
|
||||
* false otherwise
|
||||
*
|
||||
* @param Node $node Node
|
||||
* @param Node $parent Parent node
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function check(Node $node, $parent = null)
|
||||
{
|
||||
return $node->getType() === $this->type;
|
||||
}
|
||||
}
|
||||
61
vendor/mck89/peast/lib/Peast/Selector/Node/Selector.php
vendored
Normal file
61
vendor/mck89/peast/lib/Peast/Selector/Node/Selector.php
vendored
Normal file
@ -0,0 +1,61 @@
|
||||
<?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\Node;
|
||||
|
||||
use Peast\Selector\Matches;
|
||||
|
||||
/**
|
||||
* Selector class
|
||||
*
|
||||
* @author Marco Marchiò <marco.mm89@gmail.com>
|
||||
*/
|
||||
class Selector
|
||||
{
|
||||
/**
|
||||
* Selector groups
|
||||
*
|
||||
* @var Group[]
|
||||
*/
|
||||
protected $groups = array();
|
||||
|
||||
/**
|
||||
* Adds a new group
|
||||
*
|
||||
* @param Group $group Group
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function addGroup(Group $group)
|
||||
{
|
||||
$this->groups[] = $group;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Executes the current selector on the given matches
|
||||
*
|
||||
* @param Matches $matches Matches
|
||||
*
|
||||
* @return Matches
|
||||
*/
|
||||
public function exec(Matches $matches)
|
||||
{
|
||||
$retMatches = array();
|
||||
foreach ($this->groups as $group) {
|
||||
$clonedMatches = $matches->createClone();
|
||||
$group->exec($clonedMatches);
|
||||
$retMatches[] = $clonedMatches;
|
||||
}
|
||||
if (count($retMatches) > 1) {
|
||||
$retMatches[0]->merge(array_slice($retMatches, 1));
|
||||
}
|
||||
return $retMatches[0];
|
||||
}
|
||||
}
|
||||
615
vendor/mck89/peast/lib/Peast/Selector/Parser.php
vendored
Normal file
615
vendor/mck89/peast/lib/Peast/Selector/Parser.php
vendored
Normal file
@ -0,0 +1,615 @@
|
||||
<?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 parser class
|
||||
*
|
||||
* @author Marco Marchiò <marco.mm89@gmail.com>
|
||||
*/
|
||||
class Parser
|
||||
{
|
||||
/**
|
||||
* Selector string
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $selector;
|
||||
|
||||
/**
|
||||
* Current parser index
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $index = 0;
|
||||
|
||||
/**
|
||||
* Selector length
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $length;
|
||||
|
||||
/**
|
||||
* Whitespaces
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $whitespaces = array(" ", "\t", "\n", "\r", "\f");
|
||||
|
||||
/**
|
||||
* Combinators
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $combinators = array(">", "+", "~");
|
||||
|
||||
/**
|
||||
* Attribute selector operator characters
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $attrOperatorChars = array("=", "<", ">", "^", "$", "*");
|
||||
|
||||
/**
|
||||
* Attribute selector operators
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $attrOperators = array("=", "<", ">", "<=", ">=", "^=", "$=", "*=");
|
||||
|
||||
/**
|
||||
* Valid pseudo selectors. The value indicates the argument type:
|
||||
* - 0: no arguments
|
||||
* - 1: index formula (An+B syntax)
|
||||
* - 2: selector
|
||||
* @var array
|
||||
*/
|
||||
protected $validPseudo = array(
|
||||
"pattern" => 0, "statement" => 0, "expression" => 0, "declaration" => 0,
|
||||
"first-child" => 0, "last-child" => 0,
|
||||
"nth-child" => 1, "nth-last-child" => 1,
|
||||
"has" => 2, "is" => 2, "not" => 2
|
||||
);
|
||||
|
||||
/**
|
||||
* Class constructor
|
||||
*
|
||||
* @param string $selector Selector string
|
||||
* @param array $options Options array. See Query class
|
||||
* documentation for available options
|
||||
*/
|
||||
public function __construct($selector, $options = array())
|
||||
{
|
||||
$encoding = isset($options["encoding"]) ? $options["encoding"] : null;
|
||||
if ($encoding && !preg_match("/UTF-?8/i", $encoding)) {
|
||||
$selector = mb_convert_encoding($selector, "UTF-8", $encoding);
|
||||
}
|
||||
$this->selector = $selector;
|
||||
$this->length = strlen($selector);
|
||||
}
|
||||
|
||||
/**
|
||||
* Starts the parsing and returns the parsed selector
|
||||
*
|
||||
* @param bool $filter True if the selector must be used for a filter
|
||||
*
|
||||
* @return Node\Selector
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
public function parse($filter = false)
|
||||
{
|
||||
$selector = $this->parseSelector($filter);
|
||||
//Throw an exception if the end has not been reached
|
||||
if (($char = $this->getChar()) !== null) {
|
||||
throw new Exception("Invalid syntax '$char'");
|
||||
}
|
||||
return $selector;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses a selector
|
||||
*
|
||||
* @param bool $filter True if the selector must be used for a filter
|
||||
*
|
||||
* @return Node\Selector
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
public function parseSelector($filter = false)
|
||||
{
|
||||
$selector = new Node\Selector;
|
||||
do {
|
||||
$first = true;
|
||||
$group = new Node\Group;
|
||||
while (true) {
|
||||
$combinator = $this->consumeCombinator();
|
||||
if (!$first && !$combinator) {
|
||||
break;
|
||||
}
|
||||
$parts = $this->parseSelectorParts();
|
||||
if (!count($parts)) {
|
||||
throw new Exception("Missing selector after combinator");
|
||||
}
|
||||
$first = false;
|
||||
$selCombinator = new Node\Combinator;
|
||||
$selCombinator->setOperator(
|
||||
$combinator ?: ($filter ? null : " ")
|
||||
);
|
||||
foreach ($parts as $part) {
|
||||
$selCombinator->addPart($part);
|
||||
}
|
||||
$group->addCombinator($selCombinator);
|
||||
}
|
||||
$selector->addGroup($group);
|
||||
$this->consumeWhitespaces();
|
||||
} while ($this->consume(","));
|
||||
return $selector;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses a set of selector pats
|
||||
*
|
||||
* @return array
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
protected function parseSelectorParts()
|
||||
{
|
||||
$parts = array();
|
||||
while (true) {
|
||||
if (
|
||||
($part = $this->parseSelectorPartType()) ||
|
||||
($part = $this->parseSelectorPartAttribute()) ||
|
||||
($part = $this->parseSelectorPartPseudo())
|
||||
) {
|
||||
$parts[] = $part;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
return $parts;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses a type selector part
|
||||
*
|
||||
* @return Node\Part\Type|null
|
||||
*/
|
||||
protected function parseSelectorPartType()
|
||||
{
|
||||
$type = $this->consumeWord();
|
||||
if ($type) {
|
||||
$part = new Node\Part\Type;
|
||||
$part->setType($type);
|
||||
return $part;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses an attribute selector part
|
||||
*
|
||||
* @return Node\Part\Attribute|null
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
protected function parseSelectorPartAttribute()
|
||||
{
|
||||
if (!$this->consume("[")) {
|
||||
return null;
|
||||
}
|
||||
$this->consumeWhitespaces();
|
||||
$part = new Node\Part\Attribute;
|
||||
if (!($name = $this->consumeWord())) {
|
||||
throw new Exception("Missing attribute name");
|
||||
}
|
||||
$part->addName($name);
|
||||
while ($this->consume(".")) {
|
||||
if (!($name = $this->consumeWord())) {
|
||||
throw new Exception("Missing attribute name after dot");
|
||||
}
|
||||
$part->addName($name);
|
||||
}
|
||||
$this->consumeWhitespaces();
|
||||
$operator = $this->consumeAny($this->attrOperatorChars);
|
||||
if ($operator) {
|
||||
if (!in_array($operator, $this->attrOperators)) {
|
||||
throw new Exception("Invalid attribute operator '$operator'");
|
||||
}
|
||||
$part->setOperator($operator);
|
||||
$this->consumeWhitespaces();
|
||||
if (!($value = $this->parseLiteral())) {
|
||||
throw new Exception("Missing attribute value");
|
||||
}
|
||||
$part->setValue($value[0]);
|
||||
if ($value[1]) {
|
||||
if ($operator != "=") {
|
||||
throw new Exception(
|
||||
"Only '=' operator is valid for attribute regex match"
|
||||
);
|
||||
}
|
||||
$part->setRegex(true);
|
||||
}
|
||||
$this->consumeWhitespaces();
|
||||
if ($this->consume("i")) {
|
||||
if (!is_string($value[0]) || $value[1]) {
|
||||
throw new Exception(
|
||||
"Case insensitive flag can be used only for string values"
|
||||
);
|
||||
}
|
||||
$part->setCaseInsensitive(true);
|
||||
$this->consumeWhitespaces();
|
||||
}
|
||||
}
|
||||
if (!$this->consume("]")) {
|
||||
throw new Exception("Unterminated attribute selector");
|
||||
}
|
||||
return $part;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses a pseudo selector part
|
||||
*
|
||||
* @return Node\Part\Pseudo|null
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
protected function parseSelectorPartPseudo()
|
||||
{
|
||||
if (!$this->consume(":")) {
|
||||
return null;
|
||||
}
|
||||
$name = $this->consumeWord("-");
|
||||
if (!isset($this->validPseudo[$name])) {
|
||||
throw new Exception("Unsupported pseudo selector '$name'");
|
||||
}
|
||||
$argsType = $this->validPseudo[$name];
|
||||
$error = false;
|
||||
if ($argsType === 1) {
|
||||
$part = new Node\Part\PseudoIndex;
|
||||
if (!$this->consume("(")) {
|
||||
$error = true;
|
||||
}
|
||||
if (!$error) {
|
||||
$this->consumeWhitespaces();
|
||||
if ($indices = $this->consumeRegex("-?\d*n(?:\+\d+)?|\d+")) {
|
||||
$indices = explode("n", $indices);
|
||||
if (count($indices) === 1) {
|
||||
$part->setOffset((int) $indices[0]);
|
||||
} else {
|
||||
switch ($indices[0]) {
|
||||
case "":
|
||||
$part->setStep(1);
|
||||
break;
|
||||
case "-":
|
||||
$part->setStep(-1);
|
||||
break;
|
||||
default:
|
||||
$part->setStep((int) $indices[0]);
|
||||
break;
|
||||
}
|
||||
if ($indices[1] !== "") {
|
||||
$part->setOffset((int) $indices[1]);
|
||||
}
|
||||
}
|
||||
} elseif (
|
||||
($word = $this->consumeWord()) &&
|
||||
($word === "even" || $word === "odd")
|
||||
) {
|
||||
$part->setStep(2);
|
||||
if ($word === "odd") {
|
||||
$part->setOffset(1);
|
||||
}
|
||||
} else {
|
||||
$error = true;
|
||||
}
|
||||
$this->consumeWhitespaces();
|
||||
if (!$error && !$this->consume(")")) {
|
||||
$error = true;
|
||||
}
|
||||
}
|
||||
} elseif ($argsType === 2) {
|
||||
$part = new Node\Part\PseudoSelector;
|
||||
if (
|
||||
$this->consume("(") &&
|
||||
($selector = $this->parseSelector($name !== "has")) &&
|
||||
$this->consume(")")
|
||||
) {
|
||||
$part->setSelector($selector);
|
||||
} else {
|
||||
$error = true;
|
||||
}
|
||||
} else {
|
||||
$part = new Node\Part\PseudoSimple;
|
||||
}
|
||||
if ($error) {
|
||||
throw new Exception(
|
||||
"Invalid argument for pseudo selector '$name'"
|
||||
);
|
||||
}
|
||||
$part->setName($name);
|
||||
return $part;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses a literal value
|
||||
*
|
||||
* @return array|null
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
protected function parseLiteral()
|
||||
{
|
||||
if (
|
||||
($literal = $this->parseLiteralBoolNull()) !== 0 ||
|
||||
($literal = $this->parseLiteralString()) !== null ||
|
||||
($literal = $this->parseLiteralNumber()) !== null
|
||||
) {
|
||||
return array($literal, false);
|
||||
} elseif ($literal = $this->parseLiteralRegex()) {
|
||||
return array($literal, true);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses a literal boolean or null value
|
||||
*
|
||||
* @return int|bool|null
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
protected function parseLiteralBoolNull()
|
||||
{
|
||||
$word = $this->consumeWord();
|
||||
if (!$word) {
|
||||
return 0;
|
||||
} elseif ($word === "true") {
|
||||
return true;
|
||||
} elseif ($word === "false") {
|
||||
return false;
|
||||
} elseif ($word === "null") {
|
||||
return null;
|
||||
}
|
||||
throw new Exception("Invalid attribute value '$word'");
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses a literal string
|
||||
*
|
||||
* @return string|null
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
protected function parseLiteralString()
|
||||
{
|
||||
if (!($quote = $this->consumeAny(array("'", '"'), true))) {
|
||||
return null;
|
||||
}
|
||||
if (($str = $this->consumeUntil($quote)) === null) {
|
||||
throw new Exception("Unterminated string in attribute value");
|
||||
}
|
||||
return $str;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses a literal number
|
||||
*
|
||||
* @return int|float|null
|
||||
*/
|
||||
protected function parseLiteralNumber()
|
||||
{
|
||||
if (
|
||||
$this->getChar() === "0" &&
|
||||
($val = $this->consumeRegex("0[xX][a-fA-F]+|0[bB][01]+|0[oO][0-7]+"))
|
||||
) {
|
||||
$form = strtolower($val[1]);
|
||||
$val = substr($val, 2);
|
||||
if ($form === "x") {
|
||||
return hexdec($val);
|
||||
} elseif ($form === "o") {
|
||||
return octdec($val);
|
||||
}
|
||||
return bindec($val);
|
||||
}
|
||||
$reg = "-?\d+(?:\.\d+)?(?:[eE][+-]?\d+)?|-?\.\d+(?:[eE][+-]?\d+)?";
|
||||
if (!($val = $this->consumeRegex($reg))) {
|
||||
return null;
|
||||
}
|
||||
return (float) $val;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses a literal regex
|
||||
*
|
||||
* @return string|null
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
protected function parseLiteralRegex()
|
||||
{
|
||||
if (!($sep = $this->consume("/"))) {
|
||||
return null;
|
||||
}
|
||||
if (($reg = $this->consumeUntil($sep, false, true)) === null) {
|
||||
throw new Exception("Unterminated regex in attribute value");
|
||||
}
|
||||
$modifiers = $this->consumeWord();
|
||||
return $sep . $reg . ($modifiers ?: "");
|
||||
}
|
||||
|
||||
/**
|
||||
* Consumes the given regex
|
||||
*
|
||||
* @param string $regex Regex to consume
|
||||
*
|
||||
* @return mixed|null
|
||||
*/
|
||||
protected function consumeRegex($regex)
|
||||
{
|
||||
if ($this->getChar() === null) {
|
||||
return null;
|
||||
}
|
||||
if (!preg_match("#^($regex)#", substr($this->selector, $this->index), $matches)) {
|
||||
return null;
|
||||
}
|
||||
$this->index += strlen($matches[1]);
|
||||
return $matches[1];
|
||||
}
|
||||
|
||||
/**
|
||||
* Consumes all the characters until the given one is reached
|
||||
*
|
||||
* @param string $stop Stop character
|
||||
* @param bool $removeEscapes If false escape characters won't be removed
|
||||
* @param false $includeStop If true stop character will be returned
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
protected function consumeUntil($stop, $removeEscapes = true, $includeStop = false)
|
||||
{
|
||||
$buffer = "";
|
||||
$escaped = false;
|
||||
while (($char = $this->getChar()) !== null) {
|
||||
$this->index += 1;
|
||||
if (!$escaped) {
|
||||
if ($char === "\\") {
|
||||
$escaped = true;
|
||||
if (!$removeEscapes) {
|
||||
$buffer .= $char;
|
||||
}
|
||||
continue;
|
||||
} elseif ($char === $stop) {
|
||||
if ($includeStop) {
|
||||
$buffer .= $char;
|
||||
}
|
||||
return $buffer;
|
||||
}
|
||||
}
|
||||
$buffer .= $char;
|
||||
$escaped = false;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Consumes a word composed by characters a-z
|
||||
*
|
||||
* @param null|string $extraChar Extra character to match
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function consumeWord($extraChar = null)
|
||||
{
|
||||
$buffer = "";
|
||||
while ($char = $this->getChar()) {
|
||||
if (
|
||||
($char >= "a" && $char <= "z") ||
|
||||
($char >= "A" && $char <= "Z") ||
|
||||
($extraChar !== null && $char === $extraChar)
|
||||
) {
|
||||
$buffer .= $char;
|
||||
$this->index += 1;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
return $buffer;
|
||||
}
|
||||
|
||||
/**
|
||||
* Consumes a combinator
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
protected function consumeCombinator()
|
||||
{
|
||||
//Initial ws can be trimmed if followed by another combinator
|
||||
$ws = $this->consumeWhitespaces();
|
||||
if ($combinator = $this->consumeAny($this->combinators, true)) {
|
||||
$this->consumeWhitespaces();
|
||||
} elseif ($ws) {
|
||||
//If there's no other combinators use the space
|
||||
$combinator = " ";
|
||||
} else {
|
||||
$combinator = null;
|
||||
}
|
||||
return $combinator;
|
||||
}
|
||||
|
||||
/**
|
||||
* Consumes as much whitespaces as possible
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function consumeWhitespaces()
|
||||
{
|
||||
return $this->consumeAny($this->whitespaces);
|
||||
}
|
||||
|
||||
/**
|
||||
* Consumes the given characters
|
||||
*
|
||||
* @param array $chars Characters to consume
|
||||
* @param false $stopAtFirst If true only the first matching character
|
||||
* is consumed
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function consumeAny($chars, $stopAtFirst = false)
|
||||
{
|
||||
$buffer = "";
|
||||
while (($char = $this->getChar()) !== null) {
|
||||
if (in_array($char, $chars)) {
|
||||
$buffer .= $char;
|
||||
$this->index++;
|
||||
if ($stopAtFirst) {
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
return $buffer;
|
||||
}
|
||||
|
||||
/**
|
||||
* Consumes the current character if it is equal to the
|
||||
* given one
|
||||
*
|
||||
* @param string $char Character to compare
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
protected function consume($char)
|
||||
{
|
||||
if ($this->getChar() === $char) {
|
||||
$this->index++;
|
||||
return $char;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the current character or null if the end
|
||||
* have been reached
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
protected function getChar()
|
||||
{
|
||||
if ($this->index < $this->length) {
|
||||
return $this->selector[$this->index];
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
320
vendor/mck89/peast/lib/Peast/Syntax/CommentsRegistry.php
vendored
Normal file
320
vendor/mck89/peast/lib/Peast/Syntax/CommentsRegistry.php
vendored
Normal file
@ -0,0 +1,320 @@
|
||||
<?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\Syntax;
|
||||
|
||||
/**
|
||||
* Comments registry class. Internal class used to manage comments
|
||||
*
|
||||
* @author Marco Marchiò <marco.mm89@gmail.com>
|
||||
*/
|
||||
class CommentsRegistry
|
||||
{
|
||||
/**
|
||||
* Map of the indices where nodes start
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $nodesStartMap = array();
|
||||
|
||||
/**
|
||||
* Map of the indices where nodes end
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $nodesEndMap = array();
|
||||
|
||||
/**
|
||||
* Comments buffer
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $buffer = null;
|
||||
|
||||
/**
|
||||
* Last token index
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $lastTokenIndex = null;
|
||||
|
||||
/**
|
||||
* Comments registry
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $registry = array();
|
||||
|
||||
/**
|
||||
* Class constructor
|
||||
*
|
||||
* @param Parser $parser Parser
|
||||
*/
|
||||
public function __construct(Parser $parser)
|
||||
{
|
||||
$parser->getEventsEmitter()
|
||||
->addListener("NodeCompleted", array($this, "onNodeCompleted"))
|
||||
->addListener("EndParsing", array($this, "onEndParsing"));
|
||||
|
||||
$parser->getScanner()->getEventsEmitter()
|
||||
->addListener("TokenConsumed", array($this, "onTokenConsumed"))
|
||||
->addListener("EndReached", array($this, "onTokenConsumed"))
|
||||
->addListener("FreezeState", array($this, "onScannerFreezeState"))
|
||||
->addListener("ResetState", array($this, "onScannerResetState"));
|
||||
}
|
||||
|
||||
/**
|
||||
* Listener called every time the scanner compose the array that represents
|
||||
* its current state
|
||||
*
|
||||
* @param array $state State
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function onScannerFreezeState(&$state)
|
||||
{
|
||||
//Register the current last token index
|
||||
$state["commentsLastTokenIndex"] = $this->lastTokenIndex;
|
||||
}
|
||||
|
||||
/**
|
||||
* Listener called every time the scanner reset its state using the given
|
||||
* array
|
||||
*
|
||||
* @param array $state State
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function onScannerResetState(&$state)
|
||||
{
|
||||
//Reset the last token index and delete it from the state array
|
||||
$this->lastTokenIndex = $state["commentsLastTokenIndex"];
|
||||
unset($state["commentsLastTokenIndex"]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Listener called every time a token is consumed and when the scanner
|
||||
* reaches the end of the source
|
||||
*
|
||||
* @param Token|null $token Consumed token or null if the end has
|
||||
* been reached
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function onTokenConsumed($token = null)
|
||||
{
|
||||
//Check if it's a comment
|
||||
if ($token && $token->type === Token::TYPE_COMMENT) {
|
||||
//If there is not an open comments buffer, create it
|
||||
if (!$this->buffer) {
|
||||
$this->buffer = array(
|
||||
"prev" => $this->lastTokenIndex,
|
||||
"next" => null,
|
||||
"comments" => array()
|
||||
);
|
||||
}
|
||||
//Add the comment token to the buffer
|
||||
$this->buffer["comments"][] = $token;
|
||||
} else {
|
||||
|
||||
if ($token) {
|
||||
$loc = $token->location;
|
||||
//Store the token end position
|
||||
$this->lastTokenIndex = $loc->end->getIndex();
|
||||
if ($this->buffer) {
|
||||
//Fill the "next" key on the comments buffer with the token
|
||||
//start position
|
||||
$this->buffer["next"] = $loc->start->getIndex();
|
||||
}
|
||||
}
|
||||
|
||||
//If there is an open comment buffer, close it and move it to the
|
||||
//registry
|
||||
if ($buffer = $this->buffer) {
|
||||
//Use the location as key to add the group of comments to the
|
||||
//registry, in this way if comments are reprocessed they won't
|
||||
//be duplicated
|
||||
$key = implode("-", array(
|
||||
$buffer["prev"] !== null ? $buffer["prev"] : "",
|
||||
$buffer["next"] !== null ? $buffer["next"] : ""
|
||||
));
|
||||
$this->registry[$key] = $this->buffer;
|
||||
$this->buffer = null;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Listener called every time a node is completed by the parser
|
||||
*
|
||||
* @param Node\Node $node Completed node
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function onNodeCompleted(Node\Node $node)
|
||||
{
|
||||
//Every time a node is completed, register its start and end indices
|
||||
//in the relative properties
|
||||
$loc = $node->location;
|
||||
foreach (array("Start", "End") as $pos) {
|
||||
$val = $loc->{"get$pos"}()->getIndex();
|
||||
$map = &$this->{"nodes{$pos}Map"};
|
||||
if (!isset($map[$val])) {
|
||||
$map[$val] = array();
|
||||
}
|
||||
$map[$val][] = $node;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Listener called when parsing process ends
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function onEndParsing()
|
||||
{
|
||||
//Return if there are no comments to process
|
||||
if ($this->registry) {
|
||||
|
||||
//Make sure nodes start indices map is sorted
|
||||
ksort($this->nodesStartMap);
|
||||
|
||||
//Loop all comment groups in the registry
|
||||
foreach ($this->registry as $group) {
|
||||
$this->findNodeForCommentsGroup($group);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds the node to attach the given comments group
|
||||
*
|
||||
* @param array $group Comments group
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function findNodeForCommentsGroup($group)
|
||||
{
|
||||
$next = $group["next"];
|
||||
$prev = $group["prev"];
|
||||
$comments = $group["comments"];
|
||||
$leading = true;
|
||||
|
||||
//If the group of comments has a next token index that appears
|
||||
//in the map of start node indices, add the group to the
|
||||
//corresponding node's leading comments. This associates
|
||||
//comments that appear immediately before a node.
|
||||
//For example: /*comment*/ for (;;){}
|
||||
if (isset($this->nodesStartMap[$next])) {
|
||||
$nodes = $this->nodesStartMap[$next];
|
||||
}
|
||||
//If the group of comments has a previous token index that appears
|
||||
//in the map of end node indices, add the group to the
|
||||
//corresponding node's trailing comments. This associates
|
||||
//comments that appear immediately after a node.
|
||||
//For example: for (;;){} /*comment*/
|
||||
elseif (isset($this->nodesEndMap[$prev])) {
|
||||
$nodes = $this->nodesEndMap[$prev];
|
||||
$leading = false;
|
||||
}
|
||||
//Otherwise, find a node that wraps the comments position.
|
||||
//This associates inner comments:
|
||||
//For example: for /*comment*/ (;;){}
|
||||
else {
|
||||
//Calculate comments group boundaries
|
||||
$start = $comments[0]->location->start->getIndex();
|
||||
$end = $comments[count($comments) -1]->location->end->getIndex();
|
||||
$nodes = array();
|
||||
|
||||
//Loop all the entries in the start index map
|
||||
foreach ($this->nodesStartMap as $idx => $ns) {
|
||||
//If the index is higher than the start index of the comments
|
||||
//group, stop
|
||||
if ($idx > $start) {
|
||||
break;
|
||||
}
|
||||
foreach ($ns as $node) {
|
||||
//Check if the comments group is inside node indices range
|
||||
if ($node->location->end->getIndex() >= $end) {
|
||||
$nodes[] = $node;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//If comments can't be associated with any node, associate it as
|
||||
//leading comments of the program, this happens when the source is
|
||||
//empty
|
||||
if (!$nodes) {
|
||||
$firstNode = array_values($this->nodesStartMap);
|
||||
$nodes = array($firstNode[0][0]);
|
||||
}
|
||||
}
|
||||
|
||||
//If there are multiple possible nodes to associate the comments to,
|
||||
//find the shortest one
|
||||
if (count($nodes) > 1) {
|
||||
usort($nodes, array($this, "compareNodesLength"));
|
||||
}
|
||||
$this->associateComments($nodes[0], $comments, $leading);
|
||||
}
|
||||
|
||||
/**
|
||||
* Compares node length
|
||||
*
|
||||
* @param Node\Node $node1 First node
|
||||
* @param Node\Node $node2 Second node
|
||||
*
|
||||
* @return int
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
public function compareNodesLength($node1, $node2)
|
||||
{
|
||||
$loc1 = $node1->location;
|
||||
$length1 = $loc1->end->getIndex() - $loc1->start->getIndex();
|
||||
$loc2 = $node2->location;
|
||||
$length2 = $loc2->end->getIndex() - $loc2->start->getIndex();
|
||||
//If the nodes have the same length make sure to choose nodes
|
||||
//different from Program nodes
|
||||
if ($length1 === $length2) {
|
||||
if ($node1 instanceof Node\Program) {
|
||||
$length1 += 1000;
|
||||
} elseif ($node2 instanceof Node\Program) {
|
||||
$length2 += 1000;
|
||||
}
|
||||
}
|
||||
return $length1 < $length2 ? -1 : 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds comments to the given node
|
||||
*
|
||||
* @param Node\Node $node Node
|
||||
* @param array $comments Array of comments to add
|
||||
* @param bool $leading True to add comments as leading comments
|
||||
* or false to add them as trailing comments
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function associateComments($node, $comments, $leading)
|
||||
{
|
||||
$fn = ($leading ? "Leading" : "Trailing") . "Comments";
|
||||
$currentComments = $node->{"get$fn"}();
|
||||
foreach ($comments as $comment) {
|
||||
$loc = $comment->location;
|
||||
$commentNode = new Node\Comment;
|
||||
$commentNode->location->start = $loc->start;
|
||||
$commentNode->location->end = $loc->end;
|
||||
$commentNode->setRawText($comment->value);
|
||||
$currentComments[] = $commentNode;
|
||||
}
|
||||
$node->{"set$fn"}($currentComments);
|
||||
}
|
||||
}
|
||||
21
vendor/mck89/peast/lib/Peast/Syntax/ES2015/Features.php
vendored
Normal file
21
vendor/mck89/peast/lib/Peast/Syntax/ES2015/Features.php
vendored
Normal file
@ -0,0 +1,21 @@
|
||||
<?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\Syntax\ES2015;
|
||||
|
||||
/**
|
||||
* ES2015 features class
|
||||
*
|
||||
* @author Marco Marchiò <marco.mm89@gmail.com>
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
class Features extends \Peast\Syntax\Features
|
||||
{
|
||||
}
|
||||
27
vendor/mck89/peast/lib/Peast/Syntax/ES2016/Features.php
vendored
Normal file
27
vendor/mck89/peast/lib/Peast/Syntax/ES2016/Features.php
vendored
Normal file
@ -0,0 +1,27 @@
|
||||
<?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\Syntax\ES2016;
|
||||
|
||||
/**
|
||||
* ES2016 features class
|
||||
*
|
||||
* @author Marco Marchiò <marco.mm89@gmail.com>
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
class Features extends \Peast\Syntax\ES2015\Features
|
||||
{
|
||||
/**
|
||||
* Exponentiation operator
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
public $exponentiationOperator = true;
|
||||
}
|
||||
41
vendor/mck89/peast/lib/Peast/Syntax/ES2017/Features.php
vendored
Normal file
41
vendor/mck89/peast/lib/Peast/Syntax/ES2017/Features.php
vendored
Normal file
@ -0,0 +1,41 @@
|
||||
<?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\Syntax\ES2017;
|
||||
|
||||
/**
|
||||
* ES2017 features class
|
||||
*
|
||||
* @author Marco Marchiò <marco.mm89@gmail.com>
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
class Features extends \Peast\Syntax\ES2016\Features
|
||||
{
|
||||
/**
|
||||
* Async/await
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
public $asyncAwait = true;
|
||||
|
||||
/**
|
||||
* Trailing comma in function calls and declarations
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
public $trailingCommaFunctionCallDeclaration = true;
|
||||
|
||||
/**
|
||||
* For-in initializer
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
public $forInInitializer = true;
|
||||
}
|
||||
41
vendor/mck89/peast/lib/Peast/Syntax/ES2018/Features.php
vendored
Normal file
41
vendor/mck89/peast/lib/Peast/Syntax/ES2018/Features.php
vendored
Normal file
@ -0,0 +1,41 @@
|
||||
<?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\Syntax\ES2018;
|
||||
|
||||
/**
|
||||
* ES2018 features class
|
||||
*
|
||||
* @author Marco Marchiò <marco.mm89@gmail.com>
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
class Features extends \Peast\Syntax\ES2017\Features
|
||||
{
|
||||
/**
|
||||
* Async iteration and generators
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
public $asyncIterationGenerators = true;
|
||||
|
||||
/**
|
||||
* Rest/spread properties
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
public $restSpreadProperties = true;
|
||||
|
||||
/**
|
||||
* Skip escape sequences checks in tagged template
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
public $skipEscapeSeqCheckInTaggedTemplates = true;
|
||||
}
|
||||
34
vendor/mck89/peast/lib/Peast/Syntax/ES2019/Features.php
vendored
Normal file
34
vendor/mck89/peast/lib/Peast/Syntax/ES2019/Features.php
vendored
Normal file
@ -0,0 +1,34 @@
|
||||
<?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\Syntax\ES2019;
|
||||
|
||||
/**
|
||||
* ES2019 features class
|
||||
*
|
||||
* @author Marco Marchiò <marco.mm89@gmail.com>
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
class Features extends \Peast\Syntax\ES2018\Features
|
||||
{
|
||||
/**
|
||||
* Optional catch binding
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
public $optionalCatchBinding = true;
|
||||
|
||||
/**
|
||||
* Paragraph and line separator in strings
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
public $paragraphLineSepInStrings = true;
|
||||
}
|
||||
62
vendor/mck89/peast/lib/Peast/Syntax/ES2020/Features.php
vendored
Normal file
62
vendor/mck89/peast/lib/Peast/Syntax/ES2020/Features.php
vendored
Normal file
@ -0,0 +1,62 @@
|
||||
<?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\Syntax\ES2020;
|
||||
|
||||
/**
|
||||
* ES2020 features class
|
||||
*
|
||||
* @author Marco Marchiò <marco.mm89@gmail.com>
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
class Features extends \Peast\Syntax\ES2019\Features
|
||||
{
|
||||
/**
|
||||
* Dynamic import
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
public $dynamicImport = true;
|
||||
|
||||
/**
|
||||
* BigInt literals
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
public $bigInt = true;
|
||||
|
||||
/**
|
||||
* Exported name for export all declarations
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
public $exportedNameInExportAll = true;
|
||||
|
||||
/**
|
||||
* Import.meta
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
public $importMeta = true;
|
||||
|
||||
/**
|
||||
* Coalescing operator
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
public $coalescingOperator = true;
|
||||
|
||||
/**
|
||||
* Optional chaining
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
public $optionalChaining = true;
|
||||
}
|
||||
34
vendor/mck89/peast/lib/Peast/Syntax/ES2021/Features.php
vendored
Normal file
34
vendor/mck89/peast/lib/Peast/Syntax/ES2021/Features.php
vendored
Normal file
@ -0,0 +1,34 @@
|
||||
<?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\Syntax\ES2021;
|
||||
|
||||
/**
|
||||
* ES2021 features class
|
||||
*
|
||||
* @author Marco Marchiò <marco.mm89@gmail.com>
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
class Features extends \Peast\Syntax\ES2020\Features
|
||||
{
|
||||
/**
|
||||
* Logical assignment operators
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
public $logicalAssignmentOperators = true;
|
||||
|
||||
/**
|
||||
* Numeric literal separator
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
public $numericLiteralSeparator = true;
|
||||
}
|
||||
62
vendor/mck89/peast/lib/Peast/Syntax/ES2022/Features.php
vendored
Normal file
62
vendor/mck89/peast/lib/Peast/Syntax/ES2022/Features.php
vendored
Normal file
@ -0,0 +1,62 @@
|
||||
<?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\Syntax\ES2022;
|
||||
|
||||
/**
|
||||
* ES2022 features class
|
||||
*
|
||||
* @author Marco Marchiò <marco.mm89@gmail.com>
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
class Features extends \Peast\Syntax\ES2021\Features
|
||||
{
|
||||
/**
|
||||
* Private methods and fields
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
public $privateMethodsAndFields = true;
|
||||
|
||||
/**
|
||||
* Class fields
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
public $classFields = true;
|
||||
|
||||
/**
|
||||
* "in" operator for private fields
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
public $classFieldsPrivateIn = true;
|
||||
|
||||
/**
|
||||
* Top level await
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
public $topLevelAwait = true;
|
||||
|
||||
/**
|
||||
* Class static block
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
public $classStaticBlock = true;
|
||||
|
||||
/**
|
||||
* Arbitrary module namespace identifier names
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
public $arbitraryModuleNSNames = true;
|
||||
}
|
||||
27
vendor/mck89/peast/lib/Peast/Syntax/ES2023/Features.php
vendored
Normal file
27
vendor/mck89/peast/lib/Peast/Syntax/ES2023/Features.php
vendored
Normal file
@ -0,0 +1,27 @@
|
||||
<?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\Syntax\ES2023;
|
||||
|
||||
/**
|
||||
* ES2023 features class
|
||||
*
|
||||
* @author Marco Marchiò <marco.mm89@gmail.com>
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
class Features extends \Peast\Syntax\ES2022\Features
|
||||
{
|
||||
/**
|
||||
* Hashbang comments
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
public $hashbangComments = true;
|
||||
}
|
||||
21
vendor/mck89/peast/lib/Peast/Syntax/ES2024/Features.php
vendored
Normal file
21
vendor/mck89/peast/lib/Peast/Syntax/ES2024/Features.php
vendored
Normal file
@ -0,0 +1,21 @@
|
||||
<?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\Syntax\ES2024;
|
||||
|
||||
/**
|
||||
* ES2024 features class
|
||||
*
|
||||
* @author Marco Marchiò <marco.mm89@gmail.com>
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
class Features extends \Peast\Syntax\ES2023\Features
|
||||
{
|
||||
}
|
||||
27
vendor/mck89/peast/lib/Peast/Syntax/ES2025/Features.php
vendored
Normal file
27
vendor/mck89/peast/lib/Peast/Syntax/ES2025/Features.php
vendored
Normal file
@ -0,0 +1,27 @@
|
||||
<?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\Syntax\ES2025;
|
||||
|
||||
/**
|
||||
* ES2025 features class
|
||||
*
|
||||
* @author Marco Marchiò <marco.mm89@gmail.com>
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
class Features extends \Peast\Syntax\ES2024\Features
|
||||
{
|
||||
/**
|
||||
* Import attributes
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
public $importAttributes = true;
|
||||
}
|
||||
22
vendor/mck89/peast/lib/Peast/Syntax/EncodingException.php
vendored
Normal file
22
vendor/mck89/peast/lib/Peast/Syntax/EncodingException.php
vendored
Normal file
@ -0,0 +1,22 @@
|
||||
<?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\Syntax;
|
||||
|
||||
/**
|
||||
* Encoding exception class. Encoding errors while scanning the source are
|
||||
* thrown using this using this exception class.
|
||||
*
|
||||
* @author Marco Marchiò <marco.mm89@gmail.com>
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
class EncodingException extends \Exception
|
||||
{
|
||||
}
|
||||
62
vendor/mck89/peast/lib/Peast/Syntax/EventsEmitter.php
vendored
Normal file
62
vendor/mck89/peast/lib/Peast/Syntax/EventsEmitter.php
vendored
Normal file
@ -0,0 +1,62 @@
|
||||
<?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\Syntax;
|
||||
|
||||
/**
|
||||
* Events emitter class. An instance of this class is used by Parser and Scanner
|
||||
* to emit events and attach listeners to them
|
||||
*
|
||||
* @author Marco Marchiò <marco.mm89@gmail.com>
|
||||
*/
|
||||
class EventsEmitter
|
||||
{
|
||||
/**
|
||||
* Events registry array
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $eventsRegistry = array();
|
||||
|
||||
/**
|
||||
* Attaches a listener function to the given event
|
||||
*
|
||||
* @param string $event Event name
|
||||
* @param callable $listener Listener function
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function addListener($event, $listener)
|
||||
{
|
||||
if (!isset($this->eventsRegistry[$event])) {
|
||||
$this->eventsRegistry[$event] = array();
|
||||
}
|
||||
$this->eventsRegistry[$event][] = $listener;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Fires an event
|
||||
*
|
||||
* @param string $event Event name
|
||||
* @param array $args Arguments to pass to functions attached to the
|
||||
* event
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function fire($event, $args = array())
|
||||
{
|
||||
if (isset($this->eventsRegistry[$event])) {
|
||||
foreach ($this->eventsRegistry[$event] as $listener) {
|
||||
call_user_func_array($listener, $args);
|
||||
}
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
50
vendor/mck89/peast/lib/Peast/Syntax/Exception.php
vendored
Normal file
50
vendor/mck89/peast/lib/Peast/Syntax/Exception.php
vendored
Normal file
@ -0,0 +1,50 @@
|
||||
<?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\Syntax;
|
||||
|
||||
/**
|
||||
* Syntax exception class. Syntax errors in the source are thrown using this
|
||||
* using this exception class.
|
||||
*
|
||||
* @author Marco Marchiò <marco.mm89@gmail.com>
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
class Exception extends \Exception
|
||||
{
|
||||
/**
|
||||
* Error position
|
||||
*
|
||||
* @var Position
|
||||
*/
|
||||
protected $position;
|
||||
|
||||
/**
|
||||
* Class constructor
|
||||
*
|
||||
* @param string $message Error message
|
||||
* @param Position $position Error position
|
||||
*/
|
||||
public function __construct($message, Position $position)
|
||||
{
|
||||
parent::__construct($message);
|
||||
$this->position = $position;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the error position
|
||||
*
|
||||
* @return Position
|
||||
*/
|
||||
public function getPosition()
|
||||
{
|
||||
return $this->position;
|
||||
}
|
||||
}
|
||||
195
vendor/mck89/peast/lib/Peast/Syntax/Features.php
vendored
Normal file
195
vendor/mck89/peast/lib/Peast/Syntax/Features.php
vendored
Normal file
@ -0,0 +1,195 @@
|
||||
<?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\Syntax;
|
||||
|
||||
/**
|
||||
* Parser features class
|
||||
*
|
||||
* @author Marco Marchiò <marco.mm89@gmail.com>
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
class Features
|
||||
{
|
||||
/**
|
||||
* Exponentiation operator
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
public $exponentiationOperator = false;
|
||||
|
||||
/**
|
||||
* Async/await
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
public $asyncAwait = false;
|
||||
|
||||
/**
|
||||
* Trailing comma in function calls and declarations
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
public $trailingCommaFunctionCallDeclaration = false;
|
||||
|
||||
/**
|
||||
* For-in initializer
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
public $forInInitializer = false;
|
||||
|
||||
/**
|
||||
* Async iteration and generators
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
public $asyncIterationGenerators = false;
|
||||
|
||||
/**
|
||||
* Rest/spread properties
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
public $restSpreadProperties = false;
|
||||
|
||||
/**
|
||||
* Skip escape sequences checks in tagged template
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
public $skipEscapeSeqCheckInTaggedTemplates = false;
|
||||
|
||||
/**
|
||||
* Optional catch binding
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
public $optionalCatchBinding = false;
|
||||
|
||||
/**
|
||||
* Paragraph and line separator in strings
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
public $paragraphLineSepInStrings = false;
|
||||
|
||||
/**
|
||||
* Dynamic import
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
public $dynamicImport = false;
|
||||
|
||||
/**
|
||||
* BigInt literals
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
public $bigInt = false;
|
||||
|
||||
/**
|
||||
* Exported name for export all declarations
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
public $exportedNameInExportAll = false;
|
||||
|
||||
/**
|
||||
* Import.meta
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
public $importMeta = false;
|
||||
|
||||
/**
|
||||
* Coalescing operator
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
public $coalescingOperator = false;
|
||||
|
||||
/**
|
||||
* Optional chaining
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
public $optionalChaining = false;
|
||||
|
||||
/**
|
||||
* Logical assignment operators
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
public $logicalAssignmentOperators = false;
|
||||
|
||||
/**
|
||||
* Numeric literal separator
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
public $numericLiteralSeparator = false;
|
||||
|
||||
/**
|
||||
* Private methods and fields
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
public $privateMethodsAndFields = false;
|
||||
|
||||
/**
|
||||
* Class fields
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
public $classFields = false;
|
||||
|
||||
/**
|
||||
* "in" operator for private fields
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
public $classFieldsPrivateIn = false;
|
||||
|
||||
/**
|
||||
* Top level await
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
public $topLevelAwait = false;
|
||||
|
||||
/**
|
||||
* Class static block
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
public $classStaticBlock = false;
|
||||
|
||||
/**
|
||||
* Arbitrary module namespace identifier names
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
public $arbitraryModuleNSNames = false;
|
||||
|
||||
/**
|
||||
* Hashbang comments
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
public $hashbangComments = false;
|
||||
|
||||
/**
|
||||
* Import attributes
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
public $importAttributes = false;
|
||||
}
|
||||
438
vendor/mck89/peast/lib/Peast/Syntax/JSX/Parser.php
vendored
Normal file
438
vendor/mck89/peast/lib/Peast/Syntax/JSX/Parser.php
vendored
Normal file
@ -0,0 +1,438 @@
|
||||
<?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\Syntax\JSX;
|
||||
|
||||
use Peast\Syntax\Token;
|
||||
|
||||
/**
|
||||
* JSX parser trait
|
||||
*
|
||||
* @author Marco Marchiò <marco.mm89@gmail.com>
|
||||
*/
|
||||
trait Parser
|
||||
{
|
||||
/**
|
||||
* Creates a JSX node
|
||||
*
|
||||
* @param string $nodeType Node's type
|
||||
* @param mixed $position Node's start position
|
||||
*
|
||||
* @return \Peast\Syntax\Node\Node
|
||||
*/
|
||||
protected function createJSXNode($nodeType, $position)
|
||||
{
|
||||
return $this->createNode("JSX\\$nodeType", $position);
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses a jsx fragment
|
||||
*
|
||||
* @return \Peast\Syntax\Node\JSX\JSXFragment|null
|
||||
*/
|
||||
protected function parseJSXFragment()
|
||||
{
|
||||
$startOpeningToken = $this->scanner->getToken();
|
||||
if (!$startOpeningToken || $startOpeningToken->value !== "<") {
|
||||
return null;
|
||||
}
|
||||
|
||||
$endOpeningToken = $this->scanner->getNextToken();
|
||||
if (!$endOpeningToken || $endOpeningToken->value !== ">") {
|
||||
return null;
|
||||
}
|
||||
|
||||
$this->scanner->consumeToken();
|
||||
$this->scanner->consumeToken();
|
||||
|
||||
$children = $this->parseJSXChildren();
|
||||
|
||||
if (!($startClosingToken = $this->scanner->consume("<")) ||
|
||||
!$this->scanner->consume("/") ||
|
||||
!$this->scanner->reconsumeCurrentTokenInJSXMode() ||
|
||||
$endOpeningToken->value !== ">") {
|
||||
$this->error();
|
||||
}
|
||||
$this->scanner->consumeToken();
|
||||
|
||||
//Opening tag
|
||||
$openingNode = $this->createJSXNode(
|
||||
"JSXOpeningFragment",
|
||||
$startOpeningToken
|
||||
);
|
||||
$this->completeNode(
|
||||
$openingNode,
|
||||
$endOpeningToken->location->end
|
||||
);
|
||||
|
||||
//Closing tag
|
||||
$closingNode = $this->createJSXNode(
|
||||
"JSXClosingFragment",
|
||||
$startClosingToken
|
||||
);
|
||||
$this->completeNode($closingNode);
|
||||
|
||||
//Fragment
|
||||
$node = $this->createJSXNode("JSXFragment", $startOpeningToken);
|
||||
$node->setOpeningFragment($openingNode);
|
||||
$node->setClosingFragment($closingNode);
|
||||
if ($children) {
|
||||
$node->setChildren($children);
|
||||
}
|
||||
return $this->completeNode($node);
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses a group of jsx children
|
||||
*
|
||||
* @return \Peast\Syntax\Node\Node[]|null
|
||||
*/
|
||||
protected function parseJSXChildren()
|
||||
{
|
||||
$children = array();
|
||||
while ($child = $this->parseJSXChild()) {
|
||||
$children[] = $child;
|
||||
}
|
||||
return count($children) ? $children : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses a jsx child
|
||||
*
|
||||
* @return \Peast\Syntax\Node\Node|null
|
||||
*/
|
||||
protected function parseJSXChild()
|
||||
{
|
||||
if ($node = $this->parseJSXText()) {
|
||||
return $node;
|
||||
} elseif ($node = $this->parseJSXFragment()) {
|
||||
return $node;
|
||||
} elseif($node = $this->parseJSXElement()) {
|
||||
return $node;
|
||||
} elseif ($startToken = $this->scanner->consume("{")) {
|
||||
$spread = $this->scanner->consume("...");
|
||||
$exp = $this->parseAssignmentExpression();
|
||||
$midPos = $this->scanner->getPosition();
|
||||
if (($spread && !$exp) || !$this->scanner->consume("}")) {
|
||||
$this->error();
|
||||
}
|
||||
$node = $this->createJSXNode(
|
||||
$spread ? "JSXSpreadChild" : "JSXExpressionContainer",
|
||||
$startToken
|
||||
);
|
||||
if (!$exp) {
|
||||
$exp = $this->createJSXNode("JSXEmptyExpression", $midPos);
|
||||
$this->completeNode($exp, $midPos);
|
||||
}
|
||||
$node->setExpression($exp);
|
||||
return $this->completeNode($node);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses a jsx text
|
||||
*
|
||||
* @return \Peast\Syntax\Node\JSX\JSXText|null
|
||||
*/
|
||||
protected function parseJSXText()
|
||||
{
|
||||
if (!($token = $this->scanner->reconsumeCurrentTokenAsJSXText())) {
|
||||
return null;
|
||||
}
|
||||
$this->scanner->consumeToken();
|
||||
$node = $this->createJSXNode("JSXText", $token);
|
||||
$node->setRaw($token->value);
|
||||
return $this->completeNode($node, $token->location->end);
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses a jsx element
|
||||
*
|
||||
* @return \Peast\Syntax\Node\JSX\JSXElement|null
|
||||
*/
|
||||
protected function parseJSXElement()
|
||||
{
|
||||
$startOpeningToken = $this->scanner->getToken();
|
||||
if (!$startOpeningToken || $startOpeningToken->value !== "<") {
|
||||
return null;
|
||||
}
|
||||
|
||||
$nextToken = $this->scanner->getNextToken();
|
||||
if ($nextToken && $nextToken->value === "/") {
|
||||
return null;
|
||||
}
|
||||
|
||||
$this->scanner->consumeToken();
|
||||
|
||||
if (!($name = $this->parseJSXIdentifierOrMemberExpression())) {
|
||||
$this->error();
|
||||
}
|
||||
|
||||
$attributes = $this->parseJSXAttributes();
|
||||
|
||||
$selfClosing = $this->scanner->consume("/");
|
||||
|
||||
$endOpeningToken = $this->scanner->reconsumeCurrentTokenInJSXMode();
|
||||
if (!$endOpeningToken || $endOpeningToken->value !== ">") {
|
||||
$this->error();
|
||||
}
|
||||
$this->scanner->consumeToken();
|
||||
|
||||
if (!$selfClosing) {
|
||||
|
||||
$children = $this->parseJSXChildren();
|
||||
|
||||
if (
|
||||
($startClosingToken = $this->scanner->consume("<")) &&
|
||||
$this->scanner->consume("/") &&
|
||||
($closingName = $this->parseJSXIdentifierOrMemberExpression()) &&
|
||||
($endClosingToken = $this->scanner->reconsumeCurrentTokenInJSXMode()) &&
|
||||
($endClosingToken->value === ">")
|
||||
) {
|
||||
$this->scanner->consumeToken();
|
||||
if (!$this->isSameJSXElementName($name, $closingName)) {
|
||||
$this->error("Closing tag does not match opening tag");
|
||||
}
|
||||
} else {
|
||||
$this->error();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//Opening tag
|
||||
$openingNode = $this->createJSXNode(
|
||||
"JSXOpeningElement",
|
||||
$startOpeningToken
|
||||
);
|
||||
$openingNode->setName($name);
|
||||
$openingNode->setSelfClosing($selfClosing);
|
||||
if ($attributes) {
|
||||
$openingNode->setAttributes($attributes);
|
||||
}
|
||||
$this->completeNode(
|
||||
$openingNode,
|
||||
$endOpeningToken->location->end
|
||||
);
|
||||
|
||||
//Closing tag
|
||||
$closingNode = null;
|
||||
if (!$selfClosing) {
|
||||
$closingNode = $this->createJSXNode(
|
||||
"JSXClosingElement",
|
||||
$startClosingToken
|
||||
);
|
||||
$closingNode->setName($closingName);
|
||||
$this->completeNode($closingNode);
|
||||
}
|
||||
|
||||
//Element
|
||||
$node = $this->createJSXNode("JSXElement", $startOpeningToken);
|
||||
$node->setOpeningElement($openingNode);
|
||||
if ($closingNode) {
|
||||
$node->setClosingElement($closingNode);
|
||||
if ($children) {
|
||||
$node->setChildren($children);
|
||||
}
|
||||
}
|
||||
return $this->completeNode($node);
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses a jsx identifier, namespaced identifier or member expression
|
||||
*
|
||||
* @param bool $allowMember True to allow member expressions
|
||||
*
|
||||
* @return \Peast\Syntax\Node\Node|null
|
||||
*/
|
||||
protected function parseJSXIdentifierOrMemberExpression($allowMember = true)
|
||||
{
|
||||
$idToken = $this->scanner->reconsumeCurrentTokenInJSXMode();
|
||||
if (!$idToken || $idToken->type !== Token::TYPE_JSX_IDENTIFIER) {
|
||||
return null;
|
||||
}
|
||||
$this->scanner->consumeToken();
|
||||
|
||||
$idNode = $this->createJSXNode("JSXIdentifier", $idToken);
|
||||
$idNode->setName($idToken->value);
|
||||
$idNode = $this->completeNode($idNode);
|
||||
|
||||
//Namespaced identifier
|
||||
if ($this->scanner->consume(":")) {
|
||||
|
||||
$idToken2 = $this->scanner->reconsumeCurrentTokenInJSXMode();
|
||||
if (!$idToken2 || $idToken2->type !== Token::TYPE_JSX_IDENTIFIER) {
|
||||
$this->error();
|
||||
}
|
||||
$this->scanner->consumeToken();
|
||||
|
||||
$idNode2 = $this->createJSXNode("JSXIdentifier", $idToken2);
|
||||
$idNode2->setName($idToken2->value);
|
||||
$idNode2 = $this->completeNode($idNode2);
|
||||
|
||||
$node = $this->createJSXNode("JSXNamespacedName", $idToken);
|
||||
$node->setNamespace($idNode);
|
||||
$node->setName($idNode2);
|
||||
return $this->completeNode($node);
|
||||
|
||||
}
|
||||
|
||||
//Get following identifiers
|
||||
$nextIds = array();
|
||||
if ($allowMember) {
|
||||
while ($this->scanner->consume(".")) {
|
||||
$nextId = $this->scanner->reconsumeCurrentTokenInJSXMode();
|
||||
if (!$nextId || $nextId->type !== Token::TYPE_JSX_IDENTIFIER) {
|
||||
$this->error();
|
||||
}
|
||||
$this->scanner->consumeToken();
|
||||
$nextIds[] = $nextId;
|
||||
}
|
||||
}
|
||||
|
||||
//Create the member expression if required
|
||||
$objectNode = $idNode;
|
||||
foreach ($nextIds as $nid) {
|
||||
$propEnd = $nid->location->end;
|
||||
$propNode = $this->createJSXNode("JSXIdentifier", $nid);
|
||||
$propNode->setName($nid->value);
|
||||
$propNode = $this->completeNode($propNode, $propEnd);
|
||||
|
||||
$node = $this->createJSXNode("JSXMemberExpression", $objectNode);
|
||||
$node->setObject($objectNode);
|
||||
$node->setProperty($propNode);
|
||||
$objectNode = $this->completeNode($node, $propEnd);
|
||||
}
|
||||
|
||||
return $objectNode;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses a jsx attributes list
|
||||
*
|
||||
* @return \Peast\Syntax\Node\Node[]|null
|
||||
*/
|
||||
protected function parseJSXAttributes()
|
||||
{
|
||||
$attributes = array();
|
||||
while (
|
||||
($attr = $this->parseJSXSpreadAttribute()) ||
|
||||
($attr = $this->parseJSXAttribute())
|
||||
) {
|
||||
$attributes[] = $attr;
|
||||
}
|
||||
return count($attributes) ? $attributes : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses a jsx spread attribute
|
||||
*
|
||||
* @return \Peast\Syntax\Node\JSX\JSXSpreadAttribute|null
|
||||
*/
|
||||
protected function parseJSXSpreadAttribute()
|
||||
{
|
||||
if (!($openToken = $this->scanner->consume("{"))) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (
|
||||
$this->scanner->consume("...") &&
|
||||
($exp = $this->parseAssignmentExpression()) &&
|
||||
$this->scanner->consume("}")
|
||||
) {
|
||||
$node = $this->createJSXNode("JSXSpreadAttribute", $openToken);
|
||||
$node->setArgument($exp);
|
||||
return $this->completeNode($node);
|
||||
}
|
||||
|
||||
$this->error();
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses a jsx spread attribute
|
||||
*
|
||||
* @return \Peast\Syntax\Node\JSX\JSXSpreadAttribute|null
|
||||
*/
|
||||
protected function parseJSXAttribute()
|
||||
{
|
||||
if (!($name = $this->parseJSXIdentifierOrMemberExpression(false))) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$value = null;
|
||||
if ($this->scanner->consume("=")) {
|
||||
$strToken = $this->scanner->reconsumeCurrentTokenInJSXMode();
|
||||
if ($strToken && $strToken->type === Token::TYPE_STRING_LITERAL) {
|
||||
$this->scanner->consumeToken();
|
||||
$value = $this->createNode("StringLiteral", $strToken);
|
||||
$value->setRaw($strToken->value);
|
||||
$value = $this->completeNode($value);
|
||||
} elseif ($startExp = $this->scanner->consume("{")) {
|
||||
|
||||
if (
|
||||
($exp = $this->parseAssignmentExpression()) &&
|
||||
$this->scanner->consume("}")
|
||||
) {
|
||||
|
||||
$value = $this->createJSXNode(
|
||||
"JSXExpressionContainer",
|
||||
$startExp
|
||||
);
|
||||
$value->setExpression($exp);
|
||||
$value = $this->completeNode($value);
|
||||
|
||||
} else {
|
||||
$this->error();
|
||||
}
|
||||
|
||||
} elseif (
|
||||
!($value = $this->parseJSXFragment()) &&
|
||||
!($value = $this->parseJSXElement())
|
||||
) {
|
||||
$this->error();
|
||||
}
|
||||
}
|
||||
|
||||
$node = $this->createJSXNode("JSXAttribute", $name);
|
||||
$node->setName($name);
|
||||
if ($value) {
|
||||
$node->setValue($value);
|
||||
}
|
||||
return $this->completeNode($node);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks that 2 tag names are equal
|
||||
*
|
||||
* @param \Peast\Syntax\Node\Node $n1 First name
|
||||
* @param \Peast\Syntax\Node\Node $n2 Second name
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected function isSameJSXElementName($n1, $n2)
|
||||
{
|
||||
$type = $n1->getType();
|
||||
if ($type !== $n2->getType()) {
|
||||
return false;
|
||||
} elseif ($type === "JSXNamespacedName") {
|
||||
return $this->isSameJSXElementName(
|
||||
$n1->getNamespace(), $n2->getNamespace()
|
||||
) && $this->isSameJSXElementName(
|
||||
$n1->getName(), $n2->getName()
|
||||
);
|
||||
} elseif ($type === "JSXMemberExpression") {
|
||||
return $this->isSameJSXElementName(
|
||||
$n1->getObject(), $n2->getObject()
|
||||
) && $this->isSameJSXElementName(
|
||||
$n1->getProperty(), $n2->getProperty()
|
||||
);
|
||||
}
|
||||
return $type === "JSXIdentifier" && $n1->getName() === $n2->getName();
|
||||
}
|
||||
}
|
||||
123
vendor/mck89/peast/lib/Peast/Syntax/JSX/Scanner.php
vendored
Normal file
123
vendor/mck89/peast/lib/Peast/Syntax/JSX/Scanner.php
vendored
Normal file
@ -0,0 +1,123 @@
|
||||
<?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\Syntax\JSX;
|
||||
|
||||
use Peast\Syntax\Token;
|
||||
|
||||
/**
|
||||
* JSX scanner trait
|
||||
*
|
||||
* @author Marco Marchiò <marco.mm89@gmail.com>
|
||||
*/
|
||||
trait Scanner
|
||||
{
|
||||
/**
|
||||
* Tries to reconsume the current token as a jsx text if possible
|
||||
*
|
||||
* @return Token|null
|
||||
*/
|
||||
public function reconsumeCurrentTokenAsJSXText()
|
||||
{
|
||||
//Current and next tokens must be reset and the open brackets count must be correct
|
||||
//like they were never scanned
|
||||
foreach (array($this->currentToken, $this->nextToken) as $token) {
|
||||
if ($token && isset($this->brackets[$token->value])) {
|
||||
if ($refBracket = $this->brackets[$token->value]) {
|
||||
$this->openBrackets[$refBracket]++;
|
||||
} else {
|
||||
$this->openBrackets[$token->value]--;
|
||||
}
|
||||
}
|
||||
}
|
||||
$this->nextToken = null;
|
||||
$this->currentToken = null;
|
||||
|
||||
$startPosition = $this->getPosition();
|
||||
$this->setScanPosition($startPosition);
|
||||
$result = $this->consumeUntil(array("{", "<"), false, false);
|
||||
if ($result) {
|
||||
$this->currentToken = new Token(Token::TYPE_JSX_TEXT, $result[0]);
|
||||
$this->currentToken->location->start = $startPosition;
|
||||
$this->currentToken->location->end = $this->getPosition(true);
|
||||
}
|
||||
return $this->currentToken;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Reconsumes the current token in jsx mode
|
||||
*
|
||||
* @return Token|null
|
||||
*/
|
||||
public function reconsumeCurrentTokenInJSXMode()
|
||||
{
|
||||
$this->jsx = true;
|
||||
$this->nextToken = null;
|
||||
$this->currentToken = null;
|
||||
$startPosition = $this->getPosition();
|
||||
$this->setScanPosition($startPosition);
|
||||
$token = $this->getToken();
|
||||
$this->jsx = false;
|
||||
return $token;
|
||||
}
|
||||
|
||||
/**
|
||||
* String scanning method in jsx mode
|
||||
*
|
||||
* @return Token|null
|
||||
*/
|
||||
public function scanJSXString()
|
||||
{
|
||||
return $this->scanString(false);
|
||||
}
|
||||
|
||||
/**
|
||||
* String punctuator method in jsx mode
|
||||
*
|
||||
* @return Token|null
|
||||
*/
|
||||
public function scanJSXPunctuator()
|
||||
{
|
||||
//The ">" character in jsx mode must be emitted in its own token
|
||||
//without matching longer sequences like ">>"
|
||||
$char = $this->charAt();
|
||||
if ($char === ">") {
|
||||
$this->index++;
|
||||
$this->column++;
|
||||
return new Token(Token::TYPE_PUNCTUATOR, $char);
|
||||
}
|
||||
return $this->scanPunctuator();
|
||||
}
|
||||
|
||||
/**
|
||||
* Identifier scanning method in jsx mode
|
||||
*
|
||||
* @return Token|null
|
||||
*/
|
||||
public function scanJSXIdentifier()
|
||||
{
|
||||
$buffer = "";
|
||||
$char = $this->charAt();
|
||||
if ($char !== null && $this->isIdentifierChar($char)) {
|
||||
|
||||
do {
|
||||
$buffer .= $char;
|
||||
$this->index++;
|
||||
$this->column++;
|
||||
$char = $this->charAt();
|
||||
} while (
|
||||
$char !== null &&
|
||||
($this->isIdentifierChar($char, false) || $char === "-")
|
||||
);
|
||||
}
|
||||
|
||||
return $buffer === "" ? null : new Token(Token::TYPE_JSX_IDENTIFIER, $buffer);
|
||||
}
|
||||
}
|
||||
153
vendor/mck89/peast/lib/Peast/Syntax/LSM.php
vendored
Normal file
153
vendor/mck89/peast/lib/Peast/Syntax/LSM.php
vendored
Normal file
@ -0,0 +1,153 @@
|
||||
<?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\Syntax;
|
||||
|
||||
/**
|
||||
* Longest Sequence Matcher. Utility class used by the scanner to consume
|
||||
* the longest sequence of character given a set of allowed characters sequences.
|
||||
*
|
||||
* @author Marco Marchiò <marco.mm89@gmail.com>
|
||||
*/
|
||||
class LSM
|
||||
{
|
||||
/**
|
||||
* Internal sequences map
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $map = array();
|
||||
|
||||
/**
|
||||
* Encoding handle flag
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $handleEncoding = false;
|
||||
|
||||
/**
|
||||
* Class constructor
|
||||
*
|
||||
* @param array $sequences Allowed characters sequences
|
||||
* @param bool $handleEncoding True to handle encoding when matching
|
||||
*/
|
||||
function __construct($sequences, $handleEncoding = false)
|
||||
{
|
||||
$this->handleEncoding = $handleEncoding;
|
||||
foreach ($sequences as $s) {
|
||||
$this->add($s);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a sequence
|
||||
*
|
||||
* @param string $sequence Sequence to add
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function add($sequence)
|
||||
{
|
||||
if ($this->handleEncoding) {
|
||||
$s = Utils::stringToUTF8Array($sequence);
|
||||
$first = $s[0];
|
||||
$len = count($s);
|
||||
} else {
|
||||
$first = $sequence[0];
|
||||
$len = strlen($sequence);
|
||||
}
|
||||
if (!isset($this->map[$first])) {
|
||||
$this->map[$first] = array(
|
||||
"maxLen" => $len,
|
||||
"map" => array($sequence)
|
||||
);
|
||||
} else {
|
||||
$this->map[$first]["map"][] = $sequence;
|
||||
$this->map[$first]["maxLen"] = max($this->map[$first]["maxLen"], $len);
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes a sequence
|
||||
*
|
||||
* @param string $sequence Sequence to remove
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function remove($sequence)
|
||||
{
|
||||
if ($this->handleEncoding) {
|
||||
$s = Utils::stringToUTF8Array($sequence);
|
||||
$first = $s[0];
|
||||
} else {
|
||||
$first = $sequence[0];
|
||||
}
|
||||
if (isset($this->map[$first])) {
|
||||
$len = $this->handleEncoding ? count($s) : strlen($sequence);
|
||||
$this->map[$first]["map"] = array_diff(
|
||||
$this->map[$first]["map"], array($sequence)
|
||||
);
|
||||
if (!count($this->map[$first]["map"])) {
|
||||
unset($this->map[$first]);
|
||||
} elseif ($this->map[$first]["maxLen"] === $len) {
|
||||
// Recalculate the max length if necessary
|
||||
foreach ($this->map[$first]["map"] as $m) {
|
||||
$this->map[$first]["maxLen"] = max(
|
||||
$this->map[$first]["maxLen"],
|
||||
strlen($m)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Executes the match. It returns an array where the first element is the
|
||||
* number of consumed characters and the second element is the match. If
|
||||
* no match is found it returns null.
|
||||
*
|
||||
* @param Scanner $scanner Scanner instance
|
||||
* @param int $index Current index
|
||||
* @param string $char Current character
|
||||
*
|
||||
* @return array|null
|
||||
*/
|
||||
public function match($scanner, $index, $char)
|
||||
{
|
||||
$consumed = 1;
|
||||
$bestMatch = null;
|
||||
if (isset($this->map[$char])) {
|
||||
//If the character is present in the map and it has a max length of
|
||||
//1, match immediately
|
||||
if ($this->map[$char]["maxLen"] === 1) {
|
||||
$bestMatch = array($consumed, $char);
|
||||
} else {
|
||||
//Otherwise consume a number of characters equal to the max
|
||||
//length and find the longest match
|
||||
$buffer = $char;
|
||||
$map = $this->map[$char]["map"];
|
||||
$maxLen = $this->map[$char]["maxLen"];
|
||||
do {
|
||||
if (in_array($buffer, $map)) {
|
||||
$bestMatch = array($consumed, $buffer);
|
||||
}
|
||||
$nextChar = $scanner->charAt($index + $consumed);
|
||||
if ($nextChar === null) {
|
||||
break;
|
||||
}
|
||||
$buffer .= $nextChar;
|
||||
$consumed++;
|
||||
} while ($consumed <= $maxLen);
|
||||
}
|
||||
}
|
||||
return $bestMatch;
|
||||
}
|
||||
}
|
||||
63
vendor/mck89/peast/lib/Peast/Syntax/Node/ArrayExpression.php
vendored
Normal file
63
vendor/mck89/peast/lib/Peast/Syntax/Node/ArrayExpression.php
vendored
Normal file
@ -0,0 +1,63 @@
|
||||
<?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\Syntax\Node;
|
||||
|
||||
/**
|
||||
* A node that represents an array literal.
|
||||
* For example: [a, b, c]
|
||||
*
|
||||
* @author Marco Marchiò <marco.mm89@gmail.com>
|
||||
*/
|
||||
class ArrayExpression extends Node implements Expression
|
||||
{
|
||||
/**
|
||||
* Map of node properties
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $propertiesMap = array(
|
||||
"elements" => true
|
||||
);
|
||||
|
||||
/**
|
||||
* Array elements
|
||||
*
|
||||
* @var Expression[]|SpreadElement[]
|
||||
*/
|
||||
protected $elements = array();
|
||||
|
||||
/**
|
||||
* Returns array elements
|
||||
*
|
||||
* @return Expression[]|SpreadElement[]
|
||||
*/
|
||||
public function getElements()
|
||||
{
|
||||
return $this->elements;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets array elements
|
||||
*
|
||||
* @param Expression[]|SpreadElement[] $elements Array elements to set
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setElements($elements)
|
||||
{
|
||||
$this->assertArrayOf(
|
||||
$elements,
|
||||
array("Expression", "SpreadElement"),
|
||||
true
|
||||
);
|
||||
$this->elements = $elements;
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
59
vendor/mck89/peast/lib/Peast/Syntax/Node/ArrayPattern.php
vendored
Normal file
59
vendor/mck89/peast/lib/Peast/Syntax/Node/ArrayPattern.php
vendored
Normal file
@ -0,0 +1,59 @@
|
||||
<?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\Syntax\Node;
|
||||
|
||||
/**
|
||||
* A node that represents an array binding pattern.
|
||||
* For example: [a, b, c] = d
|
||||
*
|
||||
* @author Marco Marchiò <marco.mm89@gmail.com>
|
||||
*/
|
||||
class ArrayPattern extends Node implements Pattern
|
||||
{
|
||||
/**
|
||||
* Map of node properties
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $propertiesMap = array(
|
||||
"elements" => true
|
||||
);
|
||||
|
||||
/**
|
||||
* Array elements
|
||||
*
|
||||
* @var Pattern[]
|
||||
*/
|
||||
protected $elements = array();
|
||||
|
||||
/**
|
||||
* Returns array elements
|
||||
*
|
||||
* @return Pattern[]
|
||||
*/
|
||||
public function getElements()
|
||||
{
|
||||
return $this->elements;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets array elements
|
||||
*
|
||||
* @param Pattern[] $elements Array elements to set
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setElements($elements)
|
||||
{
|
||||
$this->assertArrayOf($elements, "Pattern", true);
|
||||
$this->elements = $elements;
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
72
vendor/mck89/peast/lib/Peast/Syntax/Node/ArrowFunctionExpression.php
vendored
Normal file
72
vendor/mck89/peast/lib/Peast/Syntax/Node/ArrowFunctionExpression.php
vendored
Normal file
@ -0,0 +1,72 @@
|
||||
<?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\Syntax\Node;
|
||||
|
||||
/**
|
||||
* A node that represents an arrow function.
|
||||
* For example: var fn = (a, b) => console.log(a, b)
|
||||
*
|
||||
* @author Marco Marchiò <marco.mm89@gmail.com>
|
||||
*/
|
||||
class ArrowFunctionExpression extends Function_ implements Expression
|
||||
{
|
||||
/**
|
||||
* Map of node properties
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $propertiesMap = array(
|
||||
"expression" => false
|
||||
);
|
||||
|
||||
/**
|
||||
* This flag is true when function body is wrapped in curly braces
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $expression = false;
|
||||
|
||||
/**
|
||||
* Sets the function body
|
||||
*
|
||||
* @param BlockStatement|Expression $body Function body
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setBody($body)
|
||||
{
|
||||
$this->assertType($body, array("BlockStatement", "Expression"));
|
||||
$this->body = $body;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the expression flag
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function getExpression()
|
||||
{
|
||||
return $this->expression;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the expression flag
|
||||
*
|
||||
* @param bool $expression Expression flag
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setExpression($expression)
|
||||
{
|
||||
$this->expression = (bool) $expression;
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
121
vendor/mck89/peast/lib/Peast/Syntax/Node/AssignmentExpression.php
vendored
Normal file
121
vendor/mck89/peast/lib/Peast/Syntax/Node/AssignmentExpression.php
vendored
Normal file
@ -0,0 +1,121 @@
|
||||
<?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\Syntax\Node;
|
||||
|
||||
/**
|
||||
* A node that represents an assignment expression.
|
||||
* For example: a = b
|
||||
*
|
||||
* @author Marco Marchiò <marco.mm89@gmail.com>
|
||||
*/
|
||||
class AssignmentExpression extends Node implements Expression
|
||||
{
|
||||
/**
|
||||
* Map of node properties
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $propertiesMap = array(
|
||||
"left" => true,
|
||||
"operator" => false,
|
||||
"right" => true
|
||||
);
|
||||
|
||||
/**
|
||||
* The assignment operator
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $operator;
|
||||
|
||||
/**
|
||||
* The left node of the assignment
|
||||
*
|
||||
* @var Pattern|Expression
|
||||
*/
|
||||
protected $left;
|
||||
|
||||
/**
|
||||
* The right node of the assignment
|
||||
*
|
||||
* @var Expression
|
||||
*/
|
||||
protected $right;
|
||||
|
||||
/**
|
||||
* Returns the assignment operator
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getOperator()
|
||||
{
|
||||
return $this->operator;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the assignment operator
|
||||
*
|
||||
* @param string $operator Assignment operator
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setOperator($operator)
|
||||
{
|
||||
$this->operator = $operator;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the left node of the assignment
|
||||
*
|
||||
* @return Pattern|Expression
|
||||
*/
|
||||
public function getLeft()
|
||||
{
|
||||
return $this->left;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the left node of the assignment
|
||||
*
|
||||
* @param Pattern|Expression $left The node to set
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setLeft($left)
|
||||
{
|
||||
$this->assertType($left, array("Pattern", "Expression"));
|
||||
$this->left = $left;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the right node of the assignment
|
||||
*
|
||||
* @return Expression
|
||||
*/
|
||||
public function getRight()
|
||||
{
|
||||
return $this->right;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the right node of the assignment
|
||||
*
|
||||
* @param Expression $right The node to set
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setRight(Expression $right)
|
||||
{
|
||||
$this->right = $right;
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
89
vendor/mck89/peast/lib/Peast/Syntax/Node/AssignmentPattern.php
vendored
Normal file
89
vendor/mck89/peast/lib/Peast/Syntax/Node/AssignmentPattern.php
vendored
Normal file
@ -0,0 +1,89 @@
|
||||
<?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\Syntax\Node;
|
||||
|
||||
/**
|
||||
* A node that represents an assignment in a binding context.
|
||||
* For example "a = b" in: var {a = b} = c
|
||||
*
|
||||
* @author Marco Marchiò <marco.mm89@gmail.com>
|
||||
*/
|
||||
class AssignmentPattern extends Node implements Pattern
|
||||
{
|
||||
/**
|
||||
* Map of node properties
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $propertiesMap = array(
|
||||
"left" => true,
|
||||
"right" => true
|
||||
);
|
||||
|
||||
/**
|
||||
* The left node of the assignment
|
||||
*
|
||||
* @var Pattern
|
||||
*/
|
||||
protected $left;
|
||||
|
||||
/**
|
||||
* The right node of the assignment
|
||||
*
|
||||
* @var Expression
|
||||
*/
|
||||
protected $right;
|
||||
|
||||
/**
|
||||
* Returns the left node of the assignment
|
||||
*
|
||||
* @return Pattern
|
||||
*/
|
||||
public function getLeft()
|
||||
{
|
||||
return $this->left;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the left node of the assignment
|
||||
*
|
||||
* @param Pattern $left Left node
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setLeft(Pattern $left)
|
||||
{
|
||||
$this->left = $left;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the right node of the assignment
|
||||
*
|
||||
* @return Expression
|
||||
*/
|
||||
public function getRight()
|
||||
{
|
||||
return $this->right;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the right node of the assignment
|
||||
*
|
||||
* @param Expression $right Right node
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setRight(Expression $right)
|
||||
{
|
||||
$this->right = $right;
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
71
vendor/mck89/peast/lib/Peast/Syntax/Node/AssignmentProperty.php
vendored
Normal file
71
vendor/mck89/peast/lib/Peast/Syntax/Node/AssignmentProperty.php
vendored
Normal file
@ -0,0 +1,71 @@
|
||||
<?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\Syntax\Node;
|
||||
|
||||
/**
|
||||
* A node that represents a property in an object binding pattern.
|
||||
* For example "a" in: var {a} = b
|
||||
*
|
||||
* @author Marco Marchiò <marco.mm89@gmail.com>
|
||||
*/
|
||||
class AssignmentProperty extends Property
|
||||
{
|
||||
/**
|
||||
* Returns node's type
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getType()
|
||||
{
|
||||
return "Property";
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the property value
|
||||
*
|
||||
* @param Pattern $value Property value
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setValue($value)
|
||||
{
|
||||
$this->assertType($value, "Pattern");
|
||||
$this->value = $value;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the property kind that is one of the kind constants
|
||||
*
|
||||
* @param string $kind Property kind
|
||||
*
|
||||
* @return $this
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
public function setKind($kind)
|
||||
{
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the property method flag that is true when the property is a method
|
||||
*
|
||||
* @param bool $method Method flag
|
||||
*
|
||||
* @return $this
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
public function setMethod($method)
|
||||
{
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
57
vendor/mck89/peast/lib/Peast/Syntax/Node/AwaitExpression.php
vendored
Normal file
57
vendor/mck89/peast/lib/Peast/Syntax/Node/AwaitExpression.php
vendored
Normal file
@ -0,0 +1,57 @@
|
||||
<?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\Syntax\Node;
|
||||
|
||||
/**
|
||||
* A node that represents an await expression.
|
||||
*
|
||||
* @author Marco Marchiò <marco.mm89@gmail.com>
|
||||
*/
|
||||
class AwaitExpression extends Node implements Expression
|
||||
{
|
||||
/**
|
||||
* Map of node properties
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $propertiesMap = array(
|
||||
"argument" => true
|
||||
);
|
||||
|
||||
/**
|
||||
* Expression's argument
|
||||
*
|
||||
* @var Expression
|
||||
*/
|
||||
protected $argument;
|
||||
|
||||
/**
|
||||
* Returns the expression's argument
|
||||
*
|
||||
* @return Expression
|
||||
*/
|
||||
public function getArgument()
|
||||
{
|
||||
return $this->argument;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the expression's argument
|
||||
*
|
||||
* @param Expression $argument Argument
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setArgument(Expression $argument)
|
||||
{
|
||||
$this->argument = $argument;
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
70
vendor/mck89/peast/lib/Peast/Syntax/Node/BigIntLiteral.php
vendored
Normal file
70
vendor/mck89/peast/lib/Peast/Syntax/Node/BigIntLiteral.php
vendored
Normal file
@ -0,0 +1,70 @@
|
||||
<?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\Syntax\Node;
|
||||
|
||||
/**
|
||||
* A node that represents a BigInt literal.
|
||||
*
|
||||
* @author Marco Marchiò <marco.mm89@gmail.com>
|
||||
*/
|
||||
class BigIntLiteral extends Literal
|
||||
{
|
||||
/**
|
||||
* Map of node properties
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $propertiesMap = array(
|
||||
"bigint" => false
|
||||
);
|
||||
|
||||
/**
|
||||
* Node's value
|
||||
*
|
||||
* @var mixed
|
||||
*/
|
||||
protected $bigint;
|
||||
|
||||
/**
|
||||
* Sets node's value
|
||||
*
|
||||
* @param float $value Value
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setValue($value)
|
||||
{
|
||||
//Value, Raw and Bigint are always the same value
|
||||
$this->value = $this->raw = $this->bigint = $value;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns node's value
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getBigint()
|
||||
{
|
||||
return $this->bigint;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets node's value
|
||||
*
|
||||
* @param string $bigint Value
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setBigint($bigint)
|
||||
{
|
||||
return $this->setValue($bigint);
|
||||
}
|
||||
}
|
||||
121
vendor/mck89/peast/lib/Peast/Syntax/Node/BinaryExpression.php
vendored
Normal file
121
vendor/mck89/peast/lib/Peast/Syntax/Node/BinaryExpression.php
vendored
Normal file
@ -0,0 +1,121 @@
|
||||
<?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\Syntax\Node;
|
||||
|
||||
/**
|
||||
* A node that represents a binary expression.
|
||||
* For example: a + b
|
||||
*
|
||||
* @author Marco Marchiò <marco.mm89@gmail.com>
|
||||
*/
|
||||
class BinaryExpression extends Node implements Expression
|
||||
{
|
||||
/**
|
||||
* Map of node properties
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $propertiesMap = array(
|
||||
"left" => true,
|
||||
"operator" => false,
|
||||
"right" => true
|
||||
);
|
||||
|
||||
/**
|
||||
* Operator
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $operator;
|
||||
|
||||
/**
|
||||
* Left expression
|
||||
*
|
||||
* @var Expression|PrivateIdentifier
|
||||
*/
|
||||
protected $left;
|
||||
|
||||
/**
|
||||
* Right expression
|
||||
*
|
||||
* @var Expression
|
||||
*/
|
||||
protected $right;
|
||||
|
||||
/**
|
||||
* Returns the operator
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getOperator()
|
||||
{
|
||||
return $this->operator;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the operator
|
||||
*
|
||||
* @param string $operator Operator
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setOperator($operator)
|
||||
{
|
||||
$this->operator = $operator;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the left expression
|
||||
*
|
||||
* @return Expression|PrivateIdentifier
|
||||
*/
|
||||
public function getLeft()
|
||||
{
|
||||
return $this->left;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the left expression
|
||||
*
|
||||
* @param Expression|PrivateIdentifier $left Left expression
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setLeft($left)
|
||||
{
|
||||
$this->assertType($left, array("Expression", "PrivateIdentifier"));
|
||||
$this->left = $left;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the right expression
|
||||
*
|
||||
* @return Expression
|
||||
*/
|
||||
public function getRight()
|
||||
{
|
||||
return $this->right;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the right expression
|
||||
*
|
||||
* @param Expression $right Right expression
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setRight(Expression $right)
|
||||
{
|
||||
$this->right = $right;
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
59
vendor/mck89/peast/lib/Peast/Syntax/Node/BlockStatement.php
vendored
Normal file
59
vendor/mck89/peast/lib/Peast/Syntax/Node/BlockStatement.php
vendored
Normal file
@ -0,0 +1,59 @@
|
||||
<?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\Syntax\Node;
|
||||
|
||||
/**
|
||||
* A node that represents a block of code wrapped in curly braces.
|
||||
*
|
||||
* @author Marco Marchiò <marco.mm89@gmail.com>
|
||||
*/
|
||||
class BlockStatement extends Node implements Statement
|
||||
{
|
||||
/**
|
||||
* Map of node properties
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $propertiesMap = array(
|
||||
"body" => true
|
||||
);
|
||||
|
||||
/**
|
||||
* Block's body
|
||||
*
|
||||
* @var Statement[]
|
||||
*/
|
||||
protected $body = array();
|
||||
|
||||
/**
|
||||
* Returns block's body
|
||||
*
|
||||
* @return Statement[]
|
||||
*/
|
||||
public function getBody()
|
||||
{
|
||||
return $this->body;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets block's body
|
||||
*
|
||||
* @param Statement[] $body Array of Statements that are the body of the
|
||||
* block
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setBody($body)
|
||||
{
|
||||
$this->assertArrayOf($body, "Statement");
|
||||
$this->body = $body;
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
38
vendor/mck89/peast/lib/Peast/Syntax/Node/BooleanLiteral.php
vendored
Normal file
38
vendor/mck89/peast/lib/Peast/Syntax/Node/BooleanLiteral.php
vendored
Normal file
@ -0,0 +1,38 @@
|
||||
<?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\Syntax\Node;
|
||||
|
||||
/**
|
||||
* A node that represents a boolean literal.
|
||||
*
|
||||
* @author Marco Marchiò <marco.mm89@gmail.com>
|
||||
*/
|
||||
class BooleanLiteral extends Literal
|
||||
{
|
||||
/**
|
||||
* Sets node's value
|
||||
*
|
||||
* @param mixed $value Value
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setValue($value)
|
||||
{
|
||||
if ($value === "true") {
|
||||
$this->value = true;
|
||||
} elseif ($value === "false") {
|
||||
$this->value = false;
|
||||
} else {
|
||||
$this->value = (bool) $value;
|
||||
}
|
||||
$this->raw = $this->value ? "true" : "false";
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
58
vendor/mck89/peast/lib/Peast/Syntax/Node/BreakStatement.php
vendored
Normal file
58
vendor/mck89/peast/lib/Peast/Syntax/Node/BreakStatement.php
vendored
Normal file
@ -0,0 +1,58 @@
|
||||
<?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\Syntax\Node;
|
||||
|
||||
/**
|
||||
* A node that represents the "break" statement inside loops.
|
||||
*
|
||||
* @author Marco Marchiò <marco.mm89@gmail.com>
|
||||
*/
|
||||
class BreakStatement extends Node implements Statement
|
||||
{
|
||||
/**
|
||||
* Map of node properties
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $propertiesMap = array(
|
||||
"label" => true
|
||||
);
|
||||
|
||||
/**
|
||||
* The optional label of the break statement
|
||||
*
|
||||
* @var Identifier
|
||||
*/
|
||||
protected $label;
|
||||
|
||||
/**
|
||||
* Returns the node's label
|
||||
*
|
||||
* @return Identifier
|
||||
*/
|
||||
public function getLabel()
|
||||
{
|
||||
return $this->label;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the node's label
|
||||
*
|
||||
* @param Identifier $label Node's label
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setLabel($label)
|
||||
{
|
||||
$this->assertType($label, "Identifier", true);
|
||||
$this->label = $label;
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
91
vendor/mck89/peast/lib/Peast/Syntax/Node/CallExpression.php
vendored
Normal file
91
vendor/mck89/peast/lib/Peast/Syntax/Node/CallExpression.php
vendored
Normal file
@ -0,0 +1,91 @@
|
||||
<?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\Syntax\Node;
|
||||
|
||||
/**
|
||||
* A node that represents a call expression.
|
||||
* For example: test()
|
||||
*
|
||||
* @author Marco Marchiò <marco.mm89@gmail.com>
|
||||
*/
|
||||
class CallExpression extends ChainElement
|
||||
{
|
||||
/**
|
||||
* Map of node properties
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $propertiesMap = array(
|
||||
"callee" => true,
|
||||
"arguments" => true
|
||||
);
|
||||
|
||||
/**
|
||||
* The callee expression
|
||||
*
|
||||
* @var Expression|Super
|
||||
*/
|
||||
protected $callee;
|
||||
|
||||
/**
|
||||
* The arguments array
|
||||
*
|
||||
* @var Expression[]|SpreadElement[]
|
||||
*/
|
||||
protected $arguments = array();
|
||||
|
||||
/**
|
||||
* Returns the callee expression
|
||||
*
|
||||
* @return Expression|Super
|
||||
*/
|
||||
public function getCallee()
|
||||
{
|
||||
return $this->callee;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the callee expression
|
||||
*
|
||||
* @param Expression|Super $callee Callee expression
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setCallee($callee)
|
||||
{
|
||||
$this->assertType($callee, array("Expression", "Super"));
|
||||
$this->callee = $callee;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the arguments array
|
||||
*
|
||||
* @return Expression[]|SpreadElement[]
|
||||
*/
|
||||
public function getArguments()
|
||||
{
|
||||
return $this->arguments;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the arguments array
|
||||
*
|
||||
* @param Expression[]|SpreadElement[] $arguments Arguments array
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setArguments($arguments)
|
||||
{
|
||||
$this->assertArrayOf($arguments, array("Expression", "SpreadElement"));
|
||||
$this->arguments = $arguments;
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
89
vendor/mck89/peast/lib/Peast/Syntax/Node/CatchClause.php
vendored
Normal file
89
vendor/mck89/peast/lib/Peast/Syntax/Node/CatchClause.php
vendored
Normal file
@ -0,0 +1,89 @@
|
||||
<?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\Syntax\Node;
|
||||
|
||||
/**
|
||||
* A node that represents the catch clause in a try-catch statement.
|
||||
*
|
||||
* @author Marco Marchiò <marco.mm89@gmail.com>
|
||||
*/
|
||||
class CatchClause extends Node
|
||||
{
|
||||
/**
|
||||
* Map of node properties
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $propertiesMap = array(
|
||||
"param" => true,
|
||||
"body" => true
|
||||
);
|
||||
|
||||
/**
|
||||
* The catch clause parameter
|
||||
*
|
||||
* @var Pattern
|
||||
*/
|
||||
protected $param;
|
||||
|
||||
/**
|
||||
* The body of the catch clause
|
||||
*
|
||||
* @var BlockStatement
|
||||
*/
|
||||
protected $body;
|
||||
|
||||
/**
|
||||
* Returns the catch clause parameter
|
||||
*
|
||||
* @return Pattern
|
||||
*/
|
||||
public function getParam()
|
||||
{
|
||||
return $this->param;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the catch clause parameter
|
||||
*
|
||||
* @param Pattern $param Catch clause parameter
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setParam($param)
|
||||
{
|
||||
$this->assertType($param, "Pattern", true);
|
||||
$this->param = $param;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the body of the catch clause
|
||||
*
|
||||
* @return BlockStatement
|
||||
*/
|
||||
public function getBody()
|
||||
{
|
||||
return $this->body;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the body of the catch clause
|
||||
*
|
||||
* @param BlockStatement $body The block of code inside the catch clause
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setBody(BlockStatement $body)
|
||||
{
|
||||
$this->body = $body;
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
55
vendor/mck89/peast/lib/Peast/Syntax/Node/ChainElement.php
vendored
Normal file
55
vendor/mck89/peast/lib/Peast/Syntax/Node/ChainElement.php
vendored
Normal file
@ -0,0 +1,55 @@
|
||||
<?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\Syntax\Node;
|
||||
|
||||
/**
|
||||
* A node that represents a chain element.
|
||||
*
|
||||
* @author Marco Marchiò <marco.mm89@gmail.com>
|
||||
*/
|
||||
abstract class ChainElement extends Node implements Expression
|
||||
{
|
||||
protected $propertiesMap = array(
|
||||
"optional" => false
|
||||
);
|
||||
|
||||
/**
|
||||
* Optional flag that is true if the node is in the optional
|
||||
* part of a chain expression
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $optional = false;
|
||||
|
||||
/**
|
||||
* Returns the optional flag that is true if the node is in
|
||||
* the optional part of a chain expression
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function getOptional()
|
||||
{
|
||||
return $this->optional;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the optional flag that is true if the node is in
|
||||
* the optional part of a chain expression
|
||||
*
|
||||
* @param bool $optional Optional flag
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setOptional($optional)
|
||||
{
|
||||
$this->optional = (bool) $optional;
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
58
vendor/mck89/peast/lib/Peast/Syntax/Node/ChainExpression.php
vendored
Normal file
58
vendor/mck89/peast/lib/Peast/Syntax/Node/ChainExpression.php
vendored
Normal file
@ -0,0 +1,58 @@
|
||||
<?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\Syntax\Node;
|
||||
|
||||
/**
|
||||
* A node that represents a chain expression.
|
||||
* For example: test?.test?.()
|
||||
*
|
||||
* @author Marco Marchiò <marco.mm89@gmail.com>
|
||||
*/
|
||||
class ChainExpression extends Node implements Expression
|
||||
{
|
||||
/**
|
||||
* Map of node properties
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $propertiesMap = array(
|
||||
"expression" => true
|
||||
);
|
||||
|
||||
/**
|
||||
* The wrapped expression
|
||||
*
|
||||
* @var Expression
|
||||
*/
|
||||
protected $expression;
|
||||
|
||||
/**
|
||||
* Returns the wrapped expression
|
||||
*
|
||||
* @return Expression
|
||||
*/
|
||||
public function getExpression()
|
||||
{
|
||||
return $this->expression;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the wrapped expression
|
||||
*
|
||||
* @param Expression $expression Wrapped expression
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setExpression(Expression $expression)
|
||||
{
|
||||
$this->expression = $expression;
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
61
vendor/mck89/peast/lib/Peast/Syntax/Node/ClassBody.php
vendored
Normal file
61
vendor/mck89/peast/lib/Peast/Syntax/Node/ClassBody.php
vendored
Normal file
@ -0,0 +1,61 @@
|
||||
<?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\Syntax\Node;
|
||||
|
||||
/**
|
||||
* A node that represents a class body.
|
||||
*
|
||||
* @author Marco Marchiò <marco.mm89@gmail.com>
|
||||
*/
|
||||
class ClassBody extends Node
|
||||
{
|
||||
/**
|
||||
* Map of node properties
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $propertiesMap = array(
|
||||
"body" => true
|
||||
);
|
||||
|
||||
/**
|
||||
* Class methods and properties
|
||||
*
|
||||
* @var MethodDefinition[]|PropertyDefinition[]|StaticBlock[]
|
||||
*/
|
||||
protected $body = array();
|
||||
|
||||
/**
|
||||
* Returns class methods and properties
|
||||
*
|
||||
* @return MethodDefinition[]|PropertyDefinition[]|StaticBlock[]
|
||||
*/
|
||||
public function getBody()
|
||||
{
|
||||
return $this->body;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets class methods and properties
|
||||
*
|
||||
* @param MethodDefinition[]|PropertyDefinition[]|StaticBlock[] $body Class methods array
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setBody($body)
|
||||
{
|
||||
$this->assertArrayOf(
|
||||
$body,
|
||||
array("MethodDefinition", "PropertyDefinition", "StaticBlock")
|
||||
);
|
||||
$this->body = $body;
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
33
vendor/mck89/peast/lib/Peast/Syntax/Node/ClassDeclaration.php
vendored
Normal file
33
vendor/mck89/peast/lib/Peast/Syntax/Node/ClassDeclaration.php
vendored
Normal file
@ -0,0 +1,33 @@
|
||||
<?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\Syntax\Node;
|
||||
|
||||
/**
|
||||
* A node that represents a class declaration.
|
||||
* For example: class test {}
|
||||
*
|
||||
* @author Marco Marchiò <marco.mm89@gmail.com>
|
||||
*/
|
||||
class ClassDeclaration extends Class_ implements Declaration
|
||||
{
|
||||
/**
|
||||
* Sets the class identifier
|
||||
*
|
||||
* @param Identifier $id Class identifier
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setId($id)
|
||||
{
|
||||
$this->assertType($id, "Identifier");
|
||||
$this->id = $id;
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
20
vendor/mck89/peast/lib/Peast/Syntax/Node/ClassExpression.php
vendored
Normal file
20
vendor/mck89/peast/lib/Peast/Syntax/Node/ClassExpression.php
vendored
Normal file
@ -0,0 +1,20 @@
|
||||
<?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\Syntax\Node;
|
||||
|
||||
/**
|
||||
* A node that represents a class expression
|
||||
* For example: test = class {}
|
||||
*
|
||||
* @author Marco Marchiò <marco.mm89@gmail.com>
|
||||
*/
|
||||
class ClassExpression extends Class_ implements Expression
|
||||
{
|
||||
}
|
||||
122
vendor/mck89/peast/lib/Peast/Syntax/Node/Class_.php
vendored
Normal file
122
vendor/mck89/peast/lib/Peast/Syntax/Node/Class_.php
vendored
Normal file
@ -0,0 +1,122 @@
|
||||
<?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\Syntax\Node;
|
||||
|
||||
/**
|
||||
* Abstract class for classes.
|
||||
*
|
||||
* @author Marco Marchiò <marco.mm89@gmail.com>
|
||||
*/
|
||||
abstract class Class_ extends Node
|
||||
{
|
||||
/**
|
||||
* Map of node properties
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $propertiesMap = array(
|
||||
"id" => true,
|
||||
"superClass" => true,
|
||||
"body" => true
|
||||
);
|
||||
|
||||
/**
|
||||
* Class name
|
||||
*
|
||||
* @var Identifier
|
||||
*/
|
||||
protected $id;
|
||||
|
||||
/**
|
||||
* Extended class
|
||||
*
|
||||
* @var Expression
|
||||
*/
|
||||
protected $superClass;
|
||||
|
||||
/**
|
||||
* Class body
|
||||
*
|
||||
* @var ClassBody
|
||||
*/
|
||||
protected $body;
|
||||
|
||||
/**
|
||||
* Returns class name
|
||||
*
|
||||
* @return Identifier
|
||||
*/
|
||||
public function getId()
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets class name
|
||||
*
|
||||
* @param Identifier $id Class name
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setId($id)
|
||||
{
|
||||
$this->assertType($id, "Identifier", true);
|
||||
$this->id = $id;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns extended class
|
||||
*
|
||||
* @return Expression
|
||||
*/
|
||||
public function getSuperClass()
|
||||
{
|
||||
return $this->superClass;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets extended class
|
||||
*
|
||||
* @param Expression $superClass Extended class
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setSuperClass($superClass)
|
||||
{
|
||||
$this->assertType($superClass, "Expression", true);
|
||||
$this->superClass = $superClass;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns class body
|
||||
*
|
||||
* @return ClassBody
|
||||
*/
|
||||
public function getBody()
|
||||
{
|
||||
return $this->body;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets class body
|
||||
*
|
||||
* @param ClassBody $body Class body
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setBody($body)
|
||||
{
|
||||
$this->assertType($body, "ClassBody");
|
||||
$this->body = $body;
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
215
vendor/mck89/peast/lib/Peast/Syntax/Node/Comment.php
vendored
Normal file
215
vendor/mck89/peast/lib/Peast/Syntax/Node/Comment.php
vendored
Normal file
@ -0,0 +1,215 @@
|
||||
<?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\Syntax\Node;
|
||||
|
||||
/**
|
||||
* A node that represents a comment.
|
||||
*
|
||||
* @author Marco Marchiò <marco.mm89@gmail.com>
|
||||
*/
|
||||
class Comment extends Node
|
||||
{
|
||||
//Comment kind constants
|
||||
/**
|
||||
* Inline comment
|
||||
*/
|
||||
const KIND_INLINE = "inline";
|
||||
|
||||
/**
|
||||
* Multiline comment
|
||||
*/
|
||||
const KIND_MULTILINE = "multiline";
|
||||
|
||||
/**
|
||||
* Html open comment
|
||||
*/
|
||||
const KIND_HTML_OPEN = "html-open";
|
||||
|
||||
/**
|
||||
* Html close comment
|
||||
*/
|
||||
const KIND_HTML_CLOSE = "html-close";
|
||||
|
||||
/**
|
||||
* Hashbang comment
|
||||
*/
|
||||
const KIND_HASHBANG = "hashbang";
|
||||
|
||||
/**
|
||||
* Map of node properties
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $propertiesMap = array(
|
||||
"kind" => false,
|
||||
"text" => false
|
||||
);
|
||||
|
||||
/**
|
||||
* The comment kind
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $kind;
|
||||
|
||||
/**
|
||||
* The comment text
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $text;
|
||||
|
||||
/**
|
||||
* Returns the comment kind
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getKind()
|
||||
{
|
||||
return $this->kind;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the comment kind
|
||||
*
|
||||
* @param string $kind Comment kind
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setKind($kind)
|
||||
{
|
||||
$this->kind = $kind;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the comment text
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getText()
|
||||
{
|
||||
return $this->text;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the comment text
|
||||
*
|
||||
* @param string $text Comment text
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setText($text)
|
||||
{
|
||||
$this->text = $text;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the comment raw text
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getRawText()
|
||||
{
|
||||
$text = $this->getText();
|
||||
$kind = $this->getKind();
|
||||
|
||||
if ($kind === self::KIND_MULTILINE) {
|
||||
$sanitize = "*/";
|
||||
} else {
|
||||
$sanitize = array("\n", "\r");
|
||||
}
|
||||
$text = str_replace($sanitize, "", $text);
|
||||
|
||||
if ($kind === self::KIND_INLINE) {
|
||||
return "//" . $text;
|
||||
} elseif ($kind === self::KIND_HASHBANG) {
|
||||
return "#!" . $text;
|
||||
} elseif ($kind === self::KIND_HTML_OPEN) {
|
||||
return "<!--" . $text;
|
||||
} elseif ($kind === self::KIND_HTML_CLOSE) {
|
||||
return "-->" . $text;
|
||||
} else {
|
||||
return "/*" . $text . "*/";
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the comment raw text
|
||||
*
|
||||
* @param string $rawText Comment raw text
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setRawText($rawText)
|
||||
{
|
||||
$start = substr($rawText, 0, 2);
|
||||
if ($start === "//") {
|
||||
$kind = self::KIND_INLINE;
|
||||
$text = substr($rawText, 2);
|
||||
} elseif ($start === "/*" && substr($rawText, -2) === "*/") {
|
||||
$kind = self::KIND_MULTILINE;
|
||||
$text = substr($rawText, 2, -2);
|
||||
} elseif ($start === "#!") {
|
||||
$kind = self::KIND_HASHBANG;
|
||||
$text = substr($rawText, 2);
|
||||
} elseif ($start === "<!" && substr($rawText, 2, 2) === "--") {
|
||||
$kind = self::KIND_HTML_OPEN;
|
||||
$text = substr($rawText, 4);
|
||||
} elseif ($start === "--" && substr($rawText, 2, 1) === ">") {
|
||||
$kind = self::KIND_HTML_CLOSE;
|
||||
$text = substr($rawText, 3);
|
||||
} else {
|
||||
throw new \Exception("Invalid comment");
|
||||
}
|
||||
return $this->setKind($kind)->setText($text);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets leading comments array
|
||||
*
|
||||
* @param Comment[] $comments Comments array
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setLeadingComments($comments)
|
||||
{
|
||||
//Comments cannot be attached to other comments
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets trailing comments array
|
||||
*
|
||||
* @param Comment[] $comments Comments array
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setTrailingComments($comments)
|
||||
{
|
||||
//Comments cannot be attached to other comments
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a serializable version of the node
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
#[\ReturnTypeWillChange]
|
||||
public function jsonSerialize()
|
||||
{
|
||||
$ret = parent::jsonSerialize();
|
||||
unset($ret["leadingComments"]);
|
||||
unset($ret["trailingComments"]);
|
||||
return $ret;
|
||||
}
|
||||
}
|
||||
120
vendor/mck89/peast/lib/Peast/Syntax/Node/ConditionalExpression.php
vendored
Normal file
120
vendor/mck89/peast/lib/Peast/Syntax/Node/ConditionalExpression.php
vendored
Normal file
@ -0,0 +1,120 @@
|
||||
<?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\Syntax\Node;
|
||||
|
||||
/**
|
||||
* A node that represents a conditional expression.
|
||||
* For example: test() ? ok() : fail()
|
||||
*
|
||||
* @author Marco Marchiò <marco.mm89@gmail.com>
|
||||
*/
|
||||
class ConditionalExpression extends Node implements Expression
|
||||
{
|
||||
/**
|
||||
* Map of node properties
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $propertiesMap = array(
|
||||
"test" => true,
|
||||
"consequent" => true,
|
||||
"alternate" => true
|
||||
);
|
||||
|
||||
/**
|
||||
* The test expression
|
||||
*
|
||||
* @var Expression
|
||||
*/
|
||||
protected $test;
|
||||
|
||||
/**
|
||||
* The consequent expression
|
||||
*
|
||||
* @var Expression
|
||||
*/
|
||||
protected $consequent;
|
||||
|
||||
/**
|
||||
* The alternate expression
|
||||
*
|
||||
* @var Expression
|
||||
*/
|
||||
protected $alternate;
|
||||
|
||||
/**
|
||||
* Returns the test expression
|
||||
*
|
||||
* @return Expression
|
||||
*/
|
||||
public function getTest()
|
||||
{
|
||||
return $this->test;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the test expression
|
||||
*
|
||||
* @param Expression $test Test expression
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setTest(Expression $test)
|
||||
{
|
||||
$this->test = $test;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the consequent expression
|
||||
*
|
||||
* @return Expression
|
||||
*/
|
||||
public function getConsequent()
|
||||
{
|
||||
return $this->consequent;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the consequent expression
|
||||
*
|
||||
* @param Expression $consequent Consequent expression
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setConsequent(Expression $consequent)
|
||||
{
|
||||
$this->consequent = $consequent;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the alternate expression
|
||||
*
|
||||
* @return Expression
|
||||
*/
|
||||
public function getAlternate()
|
||||
{
|
||||
return $this->alternate;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the alternate expression
|
||||
*
|
||||
* @param Expression $alternate Alternate expression
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setAlternate(Expression $alternate)
|
||||
{
|
||||
$this->alternate = $alternate;
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
58
vendor/mck89/peast/lib/Peast/Syntax/Node/ContinueStatement.php
vendored
Normal file
58
vendor/mck89/peast/lib/Peast/Syntax/Node/ContinueStatement.php
vendored
Normal file
@ -0,0 +1,58 @@
|
||||
<?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\Syntax\Node;
|
||||
|
||||
/**
|
||||
* A node that represents the "continue" statement inside loops.
|
||||
*
|
||||
* @author Marco Marchiò <marco.mm89@gmail.com>
|
||||
*/
|
||||
class ContinueStatement extends Node implements Statement
|
||||
{
|
||||
/**
|
||||
* Map of node properties
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $propertiesMap = array(
|
||||
"label" => true
|
||||
);
|
||||
|
||||
/**
|
||||
* The optional label of the continue statement
|
||||
*
|
||||
* @var Identifier
|
||||
*/
|
||||
protected $label;
|
||||
|
||||
/**
|
||||
* Returns the node's label
|
||||
*
|
||||
* @return Identifier
|
||||
*/
|
||||
public function getLabel()
|
||||
{
|
||||
return $this->label;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the node's label
|
||||
*
|
||||
* @param Identifier $label Node's label
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setLabel($label)
|
||||
{
|
||||
$this->assertType($label, "Identifier", true);
|
||||
$this->label = $label;
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
20
vendor/mck89/peast/lib/Peast/Syntax/Node/DebuggerStatement.php
vendored
Normal file
20
vendor/mck89/peast/lib/Peast/Syntax/Node/DebuggerStatement.php
vendored
Normal file
@ -0,0 +1,20 @@
|
||||
<?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\Syntax\Node;
|
||||
|
||||
/**
|
||||
* A node that represents a debugger statement.
|
||||
* For example: debugger;
|
||||
*
|
||||
* @author Marco Marchiò <marco.mm89@gmail.com>
|
||||
*/
|
||||
class DebuggerStatement extends Node implements Statement
|
||||
{
|
||||
}
|
||||
19
vendor/mck89/peast/lib/Peast/Syntax/Node/Declaration.php
vendored
Normal file
19
vendor/mck89/peast/lib/Peast/Syntax/Node/Declaration.php
vendored
Normal file
@ -0,0 +1,19 @@
|
||||
<?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\Syntax\Node;
|
||||
|
||||
/**
|
||||
* Interface that every declaration node must implement.
|
||||
*
|
||||
* @author Marco Marchiò <marco.mm89@gmail.com>
|
||||
*/
|
||||
interface Declaration extends Statement
|
||||
{
|
||||
}
|
||||
89
vendor/mck89/peast/lib/Peast/Syntax/Node/DoWhileStatement.php
vendored
Normal file
89
vendor/mck89/peast/lib/Peast/Syntax/Node/DoWhileStatement.php
vendored
Normal file
@ -0,0 +1,89 @@
|
||||
<?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\Syntax\Node;
|
||||
|
||||
/**
|
||||
* A node that represents a do-while loop.
|
||||
* For example: do {} while (test)
|
||||
*
|
||||
* @author Marco Marchiò <marco.mm89@gmail.com>
|
||||
*/
|
||||
class DoWhileStatement extends Node implements Statement
|
||||
{
|
||||
/**
|
||||
* Map of node properties
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $propertiesMap = array(
|
||||
"body" => true,
|
||||
"test" => true
|
||||
);
|
||||
|
||||
/**
|
||||
* The loop body
|
||||
*
|
||||
* @var Statement
|
||||
*/
|
||||
protected $body;
|
||||
|
||||
/**
|
||||
* The loop condition
|
||||
*
|
||||
* @var Expression
|
||||
*/
|
||||
protected $test;
|
||||
|
||||
/**
|
||||
* Returns the loop body
|
||||
*
|
||||
* @return Statement
|
||||
*/
|
||||
public function getBody()
|
||||
{
|
||||
return $this->body;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the loop body
|
||||
*
|
||||
* @param Statement $body Loop body
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setBody(Statement $body)
|
||||
{
|
||||
$this->body = $body;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the loop condition
|
||||
*
|
||||
* @return Expression
|
||||
*/
|
||||
public function getTest()
|
||||
{
|
||||
return $this->test;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the loop condition
|
||||
*
|
||||
* @param Expression $test Loop
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setTest(Expression $test)
|
||||
{
|
||||
$this->test = $test;
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
19
vendor/mck89/peast/lib/Peast/Syntax/Node/EmptyStatement.php
vendored
Normal file
19
vendor/mck89/peast/lib/Peast/Syntax/Node/EmptyStatement.php
vendored
Normal file
@ -0,0 +1,19 @@
|
||||
<?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\Syntax\Node;
|
||||
|
||||
/**
|
||||
* A node that represents an empty statement (;).
|
||||
*
|
||||
* @author Marco Marchiò <marco.mm89@gmail.com>
|
||||
*/
|
||||
class EmptyStatement extends Node implements Statement
|
||||
{
|
||||
}
|
||||
122
vendor/mck89/peast/lib/Peast/Syntax/Node/ExportAllDeclaration.php
vendored
Normal file
122
vendor/mck89/peast/lib/Peast/Syntax/Node/ExportAllDeclaration.php
vendored
Normal file
@ -0,0 +1,122 @@
|
||||
<?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\Syntax\Node;
|
||||
|
||||
/**
|
||||
* A node that represents an "export all" declaration.
|
||||
* For example: export * from "test"
|
||||
*
|
||||
* @author Marco Marchiò <marco.mm89@gmail.com>
|
||||
*/
|
||||
class ExportAllDeclaration extends Node implements ModuleDeclaration
|
||||
{
|
||||
/**
|
||||
* Map of node properties
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $propertiesMap = array(
|
||||
"source" => true,
|
||||
"exported" => true,
|
||||
"attributes" => true
|
||||
);
|
||||
|
||||
/**
|
||||
* The export source
|
||||
*
|
||||
* @var Literal
|
||||
*/
|
||||
protected $source;
|
||||
|
||||
/**
|
||||
* The exported name
|
||||
*
|
||||
* @var Identifier|StringLiteral
|
||||
*/
|
||||
protected $exported;
|
||||
|
||||
/**
|
||||
* Attributes array
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $attributes = array();
|
||||
|
||||
/**
|
||||
* Returns the export source
|
||||
*
|
||||
* @return Literal
|
||||
*/
|
||||
public function getSource()
|
||||
{
|
||||
return $this->source;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the export source
|
||||
*
|
||||
* @param Literal $source Export source
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setSource(Literal $source)
|
||||
{
|
||||
$this->source = $source;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the exported name
|
||||
*
|
||||
* @return Identifier|StringLiteral
|
||||
*/
|
||||
public function getExported()
|
||||
{
|
||||
return $this->exported;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the exported name
|
||||
*W
|
||||
* @param Identifier|StringLiteral $exported Exported name
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setExported($exported)
|
||||
{
|
||||
$this->assertType($exported, array("Identifier", "StringLiteral"), true);
|
||||
$this->exported = $exported;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the attributes array
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getAttributes()
|
||||
{
|
||||
return $this->attributes;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the attributes array
|
||||
*
|
||||
* @param array $attributes Attributes array
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setAttributes($attributes)
|
||||
{
|
||||
$this->assertArrayOf($attributes, "ImportAttribute");
|
||||
$this->attributes = $attributes;
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
59
vendor/mck89/peast/lib/Peast/Syntax/Node/ExportDefaultDeclaration.php
vendored
Normal file
59
vendor/mck89/peast/lib/Peast/Syntax/Node/ExportDefaultDeclaration.php
vendored
Normal file
@ -0,0 +1,59 @@
|
||||
<?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\Syntax\Node;
|
||||
|
||||
/**
|
||||
* A node that represents the export default declaration.
|
||||
* For example: export default a
|
||||
*
|
||||
* @author Marco Marchiò <marco.mm89@gmail.com>
|
||||
*/
|
||||
class ExportDefaultDeclaration extends Node implements ModuleDeclaration
|
||||
{
|
||||
/**
|
||||
* Map of node properties
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $propertiesMap = array(
|
||||
"declaration" => true
|
||||
);
|
||||
|
||||
/**
|
||||
* The exported declaration
|
||||
*
|
||||
* @var Declaration|Expression
|
||||
*/
|
||||
protected $declaration;
|
||||
|
||||
/**
|
||||
* Returns the exported declaration
|
||||
*
|
||||
* @return Declaration|Expression
|
||||
*/
|
||||
public function getDeclaration()
|
||||
{
|
||||
return $this->declaration;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the exported declaration
|
||||
*
|
||||
* @param Declaration|Expression $declaration The exported declaration
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setDeclaration($declaration)
|
||||
{
|
||||
$this->assertType($declaration, array("Declaration", "Expression"));
|
||||
$this->declaration = $declaration;
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
155
vendor/mck89/peast/lib/Peast/Syntax/Node/ExportNamedDeclaration.php
vendored
Normal file
155
vendor/mck89/peast/lib/Peast/Syntax/Node/ExportNamedDeclaration.php
vendored
Normal file
@ -0,0 +1,155 @@
|
||||
<?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\Syntax\Node;
|
||||
|
||||
/**
|
||||
* A node that represents an export named declaration.
|
||||
* For example: export {foo} from "bar"
|
||||
*
|
||||
* @author Marco Marchiò <marco.mm89@gmail.com>
|
||||
*/
|
||||
class ExportNamedDeclaration extends Node implements ModuleDeclaration
|
||||
{
|
||||
/**
|
||||
* Map of node properties
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $propertiesMap = array(
|
||||
"declaration" => true,
|
||||
"specifiers" => true,
|
||||
"source" => true,
|
||||
"attributes" => true
|
||||
);
|
||||
|
||||
/**
|
||||
* Exported declaration
|
||||
*
|
||||
* @var Declaration
|
||||
*/
|
||||
protected $declaration;
|
||||
|
||||
/**
|
||||
* Exported specifiers
|
||||
*
|
||||
* @var ExportSpecifier[]
|
||||
*/
|
||||
protected $specifiers = array();
|
||||
|
||||
/**
|
||||
* Attributes array
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $attributes = array();
|
||||
|
||||
/**
|
||||
* The export source
|
||||
*
|
||||
* @var Literal
|
||||
*/
|
||||
protected $source;
|
||||
|
||||
/**
|
||||
* Returns the exported declaration
|
||||
*
|
||||
* @return Declaration
|
||||
*/
|
||||
public function getDeclaration()
|
||||
{
|
||||
return $this->declaration;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the exported declaration
|
||||
*
|
||||
* @param Declaration $declaration Exported declaration
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setDeclaration($declaration)
|
||||
{
|
||||
$this->assertType($declaration, "Declaration", true);
|
||||
$this->declaration = $declaration;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the exported specifiers
|
||||
*
|
||||
* @return ExportSpecifier[]
|
||||
*/
|
||||
public function getSpecifiers()
|
||||
{
|
||||
return $this->specifiers;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the exported specifiers
|
||||
*
|
||||
* @param ExportSpecifier[] $specifiers Exported specifiers
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setSpecifiers($specifiers)
|
||||
{
|
||||
$this->assertArrayOf($specifiers, "ExportSpecifier");
|
||||
$this->specifiers = $specifiers;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the export source
|
||||
*
|
||||
* @return Literal
|
||||
*/
|
||||
public function getSource()
|
||||
{
|
||||
return $this->source;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the export source
|
||||
*
|
||||
* @param Literal $source Export source
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setSource($source)
|
||||
{
|
||||
$this->assertType($source, "Literal", true);
|
||||
$this->source = $source;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the attributes array
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getAttributes()
|
||||
{
|
||||
return $this->attributes;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the attributes array
|
||||
*
|
||||
* @param array $attributes Attributes array
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setAttributes($attributes)
|
||||
{
|
||||
$this->assertArrayOf($attributes, "ImportAttribute");
|
||||
$this->attributes = $attributes;
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
59
vendor/mck89/peast/lib/Peast/Syntax/Node/ExportSpecifier.php
vendored
Normal file
59
vendor/mck89/peast/lib/Peast/Syntax/Node/ExportSpecifier.php
vendored
Normal file
@ -0,0 +1,59 @@
|
||||
<?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\Syntax\Node;
|
||||
|
||||
/**
|
||||
* A node that represents a specifier in an export declaration.
|
||||
* For example "{a}" in: export {a}
|
||||
*
|
||||
* @author Marco Marchiò <marco.mm89@gmail.com>
|
||||
*/
|
||||
class ExportSpecifier extends ModuleSpecifier
|
||||
{
|
||||
/**
|
||||
* Map of node properties
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $propertiesMap = array(
|
||||
"exported" => true
|
||||
);
|
||||
|
||||
/**
|
||||
* Exported identifier
|
||||
*
|
||||
* @var Identifier|StringLiteral
|
||||
*/
|
||||
protected $exported;
|
||||
|
||||
/**
|
||||
* Returns the exported identifier
|
||||
*
|
||||
* @return Identifier|StringLiteral
|
||||
*/
|
||||
public function getExported()
|
||||
{
|
||||
return $this->exported;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the exported identifier
|
||||
*
|
||||
* @param Identifier|StringLiteral $exported Exported identifier
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setExported($exported)
|
||||
{
|
||||
$this->assertType($exported, array("Identifier", "StringLiteral"));
|
||||
$this->exported = $exported;
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
19
vendor/mck89/peast/lib/Peast/Syntax/Node/Expression.php
vendored
Normal file
19
vendor/mck89/peast/lib/Peast/Syntax/Node/Expression.php
vendored
Normal file
@ -0,0 +1,19 @@
|
||||
<?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\Syntax\Node;
|
||||
|
||||
/**
|
||||
* Interface that every expression node must implement.
|
||||
*
|
||||
* @author Marco Marchiò <marco.mm89@gmail.com>
|
||||
*/
|
||||
interface Expression
|
||||
{
|
||||
}
|
||||
57
vendor/mck89/peast/lib/Peast/Syntax/Node/ExpressionStatement.php
vendored
Normal file
57
vendor/mck89/peast/lib/Peast/Syntax/Node/ExpressionStatement.php
vendored
Normal file
@ -0,0 +1,57 @@
|
||||
<?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\Syntax\Node;
|
||||
|
||||
/**
|
||||
* A node that represents an expression statement and wraps another expression.
|
||||
*
|
||||
* @author Marco Marchiò <marco.mm89@gmail.com>
|
||||
*/
|
||||
class ExpressionStatement extends Node implements Statement
|
||||
{
|
||||
/**
|
||||
* Map of node properties
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $propertiesMap = array(
|
||||
"expression" => true
|
||||
);
|
||||
|
||||
/**
|
||||
* Wrapped expression
|
||||
*
|
||||
* @var Expression
|
||||
*/
|
||||
protected $expression;
|
||||
|
||||
/**
|
||||
* Returns the wrapped expression
|
||||
*
|
||||
* @return Expression
|
||||
*/
|
||||
public function getExpression()
|
||||
{
|
||||
return $this->expression;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the wrapped expression
|
||||
*
|
||||
* @param Expression $expression Wrapped expression
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setExpression(Expression $expression)
|
||||
{
|
||||
$this->expression = $expression;
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
123
vendor/mck89/peast/lib/Peast/Syntax/Node/ForInStatement.php
vendored
Normal file
123
vendor/mck89/peast/lib/Peast/Syntax/Node/ForInStatement.php
vendored
Normal file
@ -0,0 +1,123 @@
|
||||
<?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\Syntax\Node;
|
||||
|
||||
/**
|
||||
* A node that represents a for-in statement.
|
||||
* For example: for (var a in b) {}
|
||||
*
|
||||
* @author Marco Marchiò <marco.mm89@gmail.com>
|
||||
*/
|
||||
class ForInStatement extends Node implements Statement
|
||||
{
|
||||
/**
|
||||
* Map of node properties
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $propertiesMap = array(
|
||||
"left" => true,
|
||||
"right" => true,
|
||||
"body" => true
|
||||
);
|
||||
|
||||
/**
|
||||
* Iteration variable
|
||||
*
|
||||
* @var VariableDeclaration|Expression|Pattern
|
||||
*/
|
||||
protected $left;
|
||||
|
||||
/**
|
||||
* Iterated object
|
||||
*
|
||||
* @var Expression
|
||||
*/
|
||||
protected $right;
|
||||
|
||||
/**
|
||||
* Loop body
|
||||
*
|
||||
* @var Statement
|
||||
*/
|
||||
protected $body;
|
||||
|
||||
/**
|
||||
* Returns the iteration variable
|
||||
*
|
||||
* @return VariableDeclaration|Expression|Pattern
|
||||
*/
|
||||
public function getLeft()
|
||||
{
|
||||
return $this->left;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the iteration variable
|
||||
*
|
||||
* @param VariableDeclaration|Expression|Pattern $left Iteration variable
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setLeft($left)
|
||||
{
|
||||
$this->assertType(
|
||||
$left, array("VariableDeclaration", "Expression", "Pattern")
|
||||
);
|
||||
$this->left = $left;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the iterated object
|
||||
*
|
||||
* @return Expression
|
||||
*/
|
||||
public function getRight()
|
||||
{
|
||||
return $this->right;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the iterated object
|
||||
*
|
||||
* @param Expression $right Iterated object
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setRight(Expression $right)
|
||||
{
|
||||
$this->right = $right;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the loop body
|
||||
*
|
||||
* @return Statement
|
||||
*/
|
||||
public function getBody()
|
||||
{
|
||||
return $this->body;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the loop body
|
||||
*
|
||||
* @param Statement $body Loop body
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setBody(Statement $body)
|
||||
{
|
||||
$this->body = $body;
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
61
vendor/mck89/peast/lib/Peast/Syntax/Node/ForOfStatement.php
vendored
Normal file
61
vendor/mck89/peast/lib/Peast/Syntax/Node/ForOfStatement.php
vendored
Normal file
@ -0,0 +1,61 @@
|
||||
<?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\Syntax\Node;
|
||||
|
||||
/**
|
||||
* A node that represents the "for...of" statement.
|
||||
* For example: for (var a of b) {}
|
||||
*
|
||||
* @author Marco Marchiò <marco.mm89@gmail.com>
|
||||
*/
|
||||
class ForOfStatement extends ForInStatement
|
||||
{
|
||||
/**
|
||||
* Map of node properties
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $propertiesMap = array(
|
||||
"left" => true,
|
||||
"right" => true,
|
||||
"body" => true,
|
||||
"await" => false
|
||||
);
|
||||
|
||||
/**
|
||||
* Async iteration flag
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $await = false;
|
||||
|
||||
/**
|
||||
* Returns the async iteration flag
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function getAwait()
|
||||
{
|
||||
return $this->await;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the async iteration flag
|
||||
*
|
||||
* @param bool $await Async iteration flag
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setAwait($await)
|
||||
{
|
||||
$this->await = (bool) $await;
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
157
vendor/mck89/peast/lib/Peast/Syntax/Node/ForStatement.php
vendored
Normal file
157
vendor/mck89/peast/lib/Peast/Syntax/Node/ForStatement.php
vendored
Normal file
@ -0,0 +1,157 @@
|
||||
<?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\Syntax\Node;
|
||||
|
||||
/**
|
||||
* A node that represents a for statement.
|
||||
*
|
||||
* @author Marco Marchiò <marco.mm89@gmail.com>
|
||||
*/
|
||||
class ForStatement extends Node implements Statement
|
||||
{
|
||||
/**
|
||||
* Map of node properties
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $propertiesMap = array(
|
||||
"init" => true,
|
||||
"test" => true,
|
||||
"update" => true,
|
||||
"body" => true
|
||||
);
|
||||
|
||||
/**
|
||||
* Initializer
|
||||
*
|
||||
* @var VariableDeclaration|Expression
|
||||
*/
|
||||
protected $init;
|
||||
|
||||
/**
|
||||
* Test expression
|
||||
*
|
||||
* @var Expression
|
||||
*/
|
||||
protected $test;
|
||||
|
||||
/**
|
||||
* Update expression
|
||||
*
|
||||
* @var Expression
|
||||
*/
|
||||
protected $update;
|
||||
|
||||
/**
|
||||
* Loop body
|
||||
*
|
||||
* @var Statement
|
||||
*/
|
||||
protected $body;
|
||||
|
||||
/**
|
||||
* Returns the initializer
|
||||
*
|
||||
* @return VariableDeclaration|Expression
|
||||
*/
|
||||
public function getInit()
|
||||
{
|
||||
return $this->init;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the initializer
|
||||
*
|
||||
* @param VariableDeclaration|Expression $init Initializer
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setInit($init)
|
||||
{
|
||||
$this->assertType(
|
||||
$init,
|
||||
array("VariableDeclaration", "Expression"),
|
||||
true
|
||||
);
|
||||
$this->init = $init;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the test expression
|
||||
*
|
||||
* @return Expression
|
||||
*/
|
||||
public function getTest()
|
||||
{
|
||||
return $this->test;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the test expression
|
||||
*
|
||||
* @param Expression $test Test expression
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setTest($test)
|
||||
{
|
||||
$this->assertType($test, "Expression", true);
|
||||
$this->test = $test;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the update expression
|
||||
*
|
||||
* @return Expression
|
||||
*/
|
||||
public function getUpdate()
|
||||
{
|
||||
return $this->update;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the update expression
|
||||
*
|
||||
* @param Expression $update Update expression
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setUpdate($update)
|
||||
{
|
||||
$this->assertType($update, "Expression", true);
|
||||
$this->update = $update;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the loop body
|
||||
*
|
||||
* @return Statement
|
||||
*/
|
||||
public function getBody()
|
||||
{
|
||||
return $this->body;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the loop body
|
||||
*
|
||||
* @param Statement $body Loop body
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setBody(Statement $body)
|
||||
{
|
||||
$this->body = $body;
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
33
vendor/mck89/peast/lib/Peast/Syntax/Node/FunctionDeclaration.php
vendored
Normal file
33
vendor/mck89/peast/lib/Peast/Syntax/Node/FunctionDeclaration.php
vendored
Normal file
@ -0,0 +1,33 @@
|
||||
<?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\Syntax\Node;
|
||||
|
||||
/**
|
||||
* A node that represents a function declaration
|
||||
* For example: function test () {}
|
||||
*
|
||||
* @author Marco Marchiò <marco.mm89@gmail.com>
|
||||
*/
|
||||
class FunctionDeclaration extends Function_ implements Declaration
|
||||
{
|
||||
/**
|
||||
* Sets the function identifier
|
||||
*
|
||||
* @param Identifier $id Function identifier
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setId($id)
|
||||
{
|
||||
$this->assertType($id, "Identifier");
|
||||
$this->id = $id;
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
20
vendor/mck89/peast/lib/Peast/Syntax/Node/FunctionExpression.php
vendored
Normal file
20
vendor/mck89/peast/lib/Peast/Syntax/Node/FunctionExpression.php
vendored
Normal file
@ -0,0 +1,20 @@
|
||||
<?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\Syntax\Node;
|
||||
|
||||
/**
|
||||
* A node that represents a function expression
|
||||
* For example: var test = function () {}
|
||||
*
|
||||
* @author Marco Marchiò <marco.mm89@gmail.com>
|
||||
*/
|
||||
class FunctionExpression extends Function_ implements Expression
|
||||
{
|
||||
}
|
||||
184
vendor/mck89/peast/lib/Peast/Syntax/Node/Function_.php
vendored
Normal file
184
vendor/mck89/peast/lib/Peast/Syntax/Node/Function_.php
vendored
Normal file
@ -0,0 +1,184 @@
|
||||
<?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\Syntax\Node;
|
||||
|
||||
/**
|
||||
* Abstract class for functions.
|
||||
*
|
||||
* @author Marco Marchiò <marco.mm89@gmail.com>
|
||||
*/
|
||||
abstract class Function_ extends Node
|
||||
{
|
||||
/**
|
||||
* Map of node properties
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $propertiesMap = array(
|
||||
"id" => true,
|
||||
"params" => true,
|
||||
"body" => true,
|
||||
"generator" => false,
|
||||
"async" => false
|
||||
);
|
||||
|
||||
/**
|
||||
* Function name
|
||||
*
|
||||
* @var Identifier
|
||||
*/
|
||||
protected $id;
|
||||
|
||||
/**
|
||||
* Function parameters array
|
||||
*
|
||||
* @var Pattern[]
|
||||
*/
|
||||
protected $params = array();
|
||||
|
||||
/**
|
||||
* Function body
|
||||
*
|
||||
* @var BlockStatement
|
||||
*/
|
||||
protected $body;
|
||||
|
||||
/**
|
||||
* Generator flag that is true when the function is a generator
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $generator = false;
|
||||
|
||||
/**
|
||||
* Async flag that is true when it is an async function
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $async = false;
|
||||
|
||||
/**
|
||||
* Returns function name
|
||||
*
|
||||
* @return Identifier
|
||||
*/
|
||||
public function getId()
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets function name
|
||||
*
|
||||
* @param Identifier $id Function name
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setId($id)
|
||||
{
|
||||
$this->assertType($id, "Identifier", true);
|
||||
$this->id = $id;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns function parameters array
|
||||
*
|
||||
* @return Pattern[]
|
||||
*/
|
||||
public function getParams()
|
||||
{
|
||||
return $this->params;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets function parameters array
|
||||
*
|
||||
* @param Pattern[] $params Function parameters array
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setParams($params)
|
||||
{
|
||||
$this->assertArrayOf($params, "Pattern");
|
||||
$this->params = $params;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns function body
|
||||
*
|
||||
* @return BlockStatement
|
||||
*/
|
||||
public function getBody()
|
||||
{
|
||||
return $this->body;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets function body
|
||||
*
|
||||
* @param BlockStatement $body Function body
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setBody($body)
|
||||
{
|
||||
$this->assertType($body, "BlockStatement");
|
||||
$this->body = $body;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the generator flag that is true when the function is a generator
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function getGenerator()
|
||||
{
|
||||
return $this->generator;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the generator flag that is true when the function is a generator
|
||||
*
|
||||
* @param bool $generator Generator flag
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setGenerator($generator)
|
||||
{
|
||||
$this->generator = (bool) $generator;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the async flag that is true when it is an async function
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function getAsync()
|
||||
{
|
||||
return $this->async;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the async flag that is true when it is an async function
|
||||
*
|
||||
* @param bool $async Async flag
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setAsync($async)
|
||||
{
|
||||
$this->async = (bool) $async;
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
101
vendor/mck89/peast/lib/Peast/Syntax/Node/Identifier.php
vendored
Normal file
101
vendor/mck89/peast/lib/Peast/Syntax/Node/Identifier.php
vendored
Normal file
@ -0,0 +1,101 @@
|
||||
<?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\Syntax\Node;
|
||||
|
||||
use Peast\Syntax\Utils;
|
||||
|
||||
/**
|
||||
* A node that represents an identifier.
|
||||
*
|
||||
* @author Marco Marchiò <marco.mm89@gmail.com>
|
||||
*/
|
||||
class Identifier extends Node implements Expression, Pattern
|
||||
{
|
||||
/**
|
||||
* Map of node properties
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $propertiesMap = array(
|
||||
"name" => false,
|
||||
"rawName" => false,
|
||||
);
|
||||
|
||||
/**
|
||||
* The identifier's name
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $name;
|
||||
|
||||
/**
|
||||
* The identifier's raw name
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $rawName;
|
||||
|
||||
/**
|
||||
* Returns the identifier's name
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getName()
|
||||
{
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the identifier's name
|
||||
*
|
||||
* @param string $name The name to set
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setName($name)
|
||||
{
|
||||
$this->name = $this->rawName = $name;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the identifier's raw name
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getRawName()
|
||||
{
|
||||
return $this->rawName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the identifier's raw name
|
||||
*
|
||||
* @param string $name The raw name to set
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setRawName($name)
|
||||
{
|
||||
$this->rawName = $name;
|
||||
if (strpos($name, "\\") !== false) {
|
||||
$this->name = preg_replace_callback(
|
||||
"#\\\\u(?:\{([a-fA-F0-9]+)\}|([a-fA-F0-9]{4}))#",
|
||||
function ($match) {
|
||||
return Utils::unicodeToUtf8(hexdec($match[1] ? : $match[2]));
|
||||
},
|
||||
$name
|
||||
);
|
||||
} else {
|
||||
$this->name = $name;
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
130
vendor/mck89/peast/lib/Peast/Syntax/Node/IfStatement.php
vendored
Normal file
130
vendor/mck89/peast/lib/Peast/Syntax/Node/IfStatement.php
vendored
Normal file
@ -0,0 +1,130 @@
|
||||
<?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\Syntax\Node;
|
||||
|
||||
/**
|
||||
* A node that represents an if statement.
|
||||
* For example: if (test) {} else {}
|
||||
*
|
||||
* @author Marco Marchiò <marco.mm89@gmail.com>
|
||||
*/
|
||||
class IfStatement extends Node implements Statement
|
||||
{
|
||||
/**
|
||||
* Map of node properties
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $propertiesMap = array(
|
||||
"test" => true,
|
||||
"consequent" => true,
|
||||
"alternate" => true
|
||||
);
|
||||
|
||||
/**
|
||||
* The test expression
|
||||
*
|
||||
* @var Expression
|
||||
*/
|
||||
protected $test;
|
||||
|
||||
/**
|
||||
* The statement that is activated if the test expression is true
|
||||
*
|
||||
* @var Statement|FunctionDeclaration
|
||||
*/
|
||||
protected $consequent;
|
||||
|
||||
/**
|
||||
* The "else" statement
|
||||
*
|
||||
* @var Statement
|
||||
*/
|
||||
protected $alternate;
|
||||
|
||||
/**
|
||||
* Returns the test expression
|
||||
*
|
||||
* @return Expression
|
||||
*/
|
||||
public function getTest()
|
||||
{
|
||||
return $this->test;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the test expression
|
||||
*
|
||||
* @param Expression $test Test expression
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setTest(Expression $test)
|
||||
{
|
||||
$this->test = $test;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the statement that is activated if the test expression is true
|
||||
*
|
||||
* @return Statement|FunctionDeclaration
|
||||
*/
|
||||
public function getConsequent()
|
||||
{
|
||||
return $this->consequent;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the statement that is activated if the test expression is true
|
||||
*
|
||||
* @param Statement|FunctionDeclaration $consequent The consequent expression
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setConsequent($consequent)
|
||||
{
|
||||
$this->assertType(
|
||||
$consequent,
|
||||
array("Statement", "FunctionDeclaration"),
|
||||
true
|
||||
);
|
||||
$this->consequent = $consequent;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the "else" statement
|
||||
*
|
||||
* @return Statement
|
||||
*/
|
||||
public function getAlternate()
|
||||
{
|
||||
return $this->alternate;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the "else" statement
|
||||
*
|
||||
* @param Statement|FunctionDeclaration $alternate The "else" statement
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setAlternate($alternate)
|
||||
{
|
||||
$this->assertType(
|
||||
$alternate,
|
||||
array("Statement", "FunctionDeclaration"),
|
||||
true
|
||||
);
|
||||
$this->alternate = $alternate;
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
90
vendor/mck89/peast/lib/Peast/Syntax/Node/ImportAttribute.php
vendored
Normal file
90
vendor/mck89/peast/lib/Peast/Syntax/Node/ImportAttribute.php
vendored
Normal file
@ -0,0 +1,90 @@
|
||||
<?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\Syntax\Node;
|
||||
|
||||
/**
|
||||
* A node that represents a key value pair for an import attribute.
|
||||
* For example: return a + 1
|
||||
*
|
||||
* @author Marco Marchiò <marco.mm89@gmail.com>
|
||||
*/
|
||||
class ImportAttribute extends Node
|
||||
{
|
||||
/**
|
||||
* Map of node properties
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $propertiesMap = array(
|
||||
"key" => true,
|
||||
"value" => true
|
||||
);
|
||||
|
||||
/**
|
||||
* Import attribute key
|
||||
*
|
||||
* @var Identifier|Literal
|
||||
*/
|
||||
protected $key;
|
||||
|
||||
/**
|
||||
* Import attribute value
|
||||
*
|
||||
* @var Literal
|
||||
*/
|
||||
protected $value;
|
||||
|
||||
/**
|
||||
* Returns the import attribute key
|
||||
*
|
||||
* @return Identifier|Literal
|
||||
*/
|
||||
public function getKey()
|
||||
{
|
||||
return $this->key;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the import attribute key
|
||||
*
|
||||
* @param Identifier|Literal $key The import attribute key
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setKey($key)
|
||||
{
|
||||
$this->assertType($key, array("Identifier", "Literal"));
|
||||
$this->key = $key;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the import attribute value
|
||||
*
|
||||
* @return Literal
|
||||
*/
|
||||
public function getValue()
|
||||
{
|
||||
return $this->value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the import attribute value
|
||||
*
|
||||
* @param Literal $value The import attribute value
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setValue(Literal $value)
|
||||
{
|
||||
$this->value = $value;
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
129
vendor/mck89/peast/lib/Peast/Syntax/Node/ImportDeclaration.php
vendored
Normal file
129
vendor/mck89/peast/lib/Peast/Syntax/Node/ImportDeclaration.php
vendored
Normal file
@ -0,0 +1,129 @@
|
||||
<?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\Syntax\Node;
|
||||
|
||||
/**
|
||||
* A node that represents in import declaration.
|
||||
* For example: import a from "mod"
|
||||
*
|
||||
* @author Marco Marchiò <marco.mm89@gmail.com>
|
||||
*/
|
||||
class ImportDeclaration extends Node implements ModuleDeclaration
|
||||
{
|
||||
/**
|
||||
* Map of node properties
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $propertiesMap = array(
|
||||
"specifiers" => true,
|
||||
"source" => true,
|
||||
"attributes" => true
|
||||
);
|
||||
|
||||
/**
|
||||
* Import specifiers array
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $specifiers = array();
|
||||
|
||||
/**
|
||||
* Import source
|
||||
*
|
||||
* @var Literal
|
||||
*/
|
||||
protected $source;
|
||||
|
||||
/**
|
||||
* Attributes array
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $attributes = array();
|
||||
|
||||
/**
|
||||
* Returns the import specifiers array
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getSpecifiers()
|
||||
{
|
||||
return $this->specifiers;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the import specifiers array
|
||||
*
|
||||
* @param array $specifiers Import specifiers array
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setSpecifiers($specifiers)
|
||||
{
|
||||
$this->assertArrayOf(
|
||||
$specifiers,
|
||||
array(
|
||||
"ImportSpecifier",
|
||||
"ImportDefaultSpecifier",
|
||||
"ImportNamespaceSpecifier"
|
||||
)
|
||||
);
|
||||
$this->specifiers = $specifiers;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the import source
|
||||
*
|
||||
* @return Literal
|
||||
*/
|
||||
public function getSource()
|
||||
{
|
||||
return $this->source;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the import source
|
||||
*
|
||||
* @param Literal $source Import source
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setSource(Literal $source)
|
||||
{
|
||||
$this->source = $source;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the attributes array
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getAttributes()
|
||||
{
|
||||
return $this->attributes;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the attributes array
|
||||
*
|
||||
* @param array $attributes Attributes array
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setAttributes($attributes)
|
||||
{
|
||||
$this->assertArrayOf($attributes, "ImportAttribute");
|
||||
$this->attributes = $attributes;
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
20
vendor/mck89/peast/lib/Peast/Syntax/Node/ImportDefaultSpecifier.php
vendored
Normal file
20
vendor/mck89/peast/lib/Peast/Syntax/Node/ImportDefaultSpecifier.php
vendored
Normal file
@ -0,0 +1,20 @@
|
||||
<?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\Syntax\Node;
|
||||
|
||||
/**
|
||||
* A node that represents a namespace import specifier.
|
||||
* For example "* as test" in: import * as test from "test.js".
|
||||
*
|
||||
* @author Marco Marchiò <marco.mm89@gmail.com>
|
||||
*/
|
||||
class ImportDefaultSpecifier extends ModuleSpecifier
|
||||
{
|
||||
}
|
||||
89
vendor/mck89/peast/lib/Peast/Syntax/Node/ImportExpression.php
vendored
Normal file
89
vendor/mck89/peast/lib/Peast/Syntax/Node/ImportExpression.php
vendored
Normal file
@ -0,0 +1,89 @@
|
||||
<?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\Syntax\Node;
|
||||
|
||||
/**
|
||||
* A node that represents an import expression (dynamic import).
|
||||
*
|
||||
* @author Marco Marchiò <marco.mm89@gmail.com>
|
||||
*/
|
||||
class ImportExpression extends Node implements Expression
|
||||
{
|
||||
/**
|
||||
* Map of node properties
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $propertiesMap = array(
|
||||
"source" => true,
|
||||
"options" => true
|
||||
);
|
||||
|
||||
/**
|
||||
* The import source
|
||||
*
|
||||
* @var Expression
|
||||
*/
|
||||
protected $source;
|
||||
|
||||
/**
|
||||
* Optional import options
|
||||
*
|
||||
* @var Expression|null
|
||||
*/
|
||||
protected $options;
|
||||
|
||||
/**
|
||||
* Returns the import source
|
||||
*
|
||||
* @return Expression
|
||||
*/
|
||||
public function getSource()
|
||||
{
|
||||
return $this->source;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the import source
|
||||
*
|
||||
* @param Expression $source Import source
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setSource(Expression $source)
|
||||
{
|
||||
$this->source = $source;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the import options
|
||||
*
|
||||
* @return Expression|null
|
||||
*/
|
||||
public function getOptions()
|
||||
{
|
||||
return $this->options;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the import options
|
||||
*
|
||||
* @param Expression|null $options Import options
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setOptions($options)
|
||||
{
|
||||
$this->assertType($options, "Expression", true);
|
||||
$this->options = $options;
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
20
vendor/mck89/peast/lib/Peast/Syntax/Node/ImportNamespaceSpecifier.php
vendored
Normal file
20
vendor/mck89/peast/lib/Peast/Syntax/Node/ImportNamespaceSpecifier.php
vendored
Normal file
@ -0,0 +1,20 @@
|
||||
<?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\Syntax\Node;
|
||||
|
||||
/**
|
||||
* A node that represents a default import specifier.
|
||||
* For example "test" in: import test from "test.js".
|
||||
*
|
||||
* @author Marco Marchiò <marco.mm89@gmail.com>
|
||||
*/
|
||||
class ImportNamespaceSpecifier extends ModuleSpecifier
|
||||
{
|
||||
}
|
||||
59
vendor/mck89/peast/lib/Peast/Syntax/Node/ImportSpecifier.php
vendored
Normal file
59
vendor/mck89/peast/lib/Peast/Syntax/Node/ImportSpecifier.php
vendored
Normal file
@ -0,0 +1,59 @@
|
||||
<?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\Syntax\Node;
|
||||
|
||||
/**
|
||||
* A node that represents a specifier in an import declaration.
|
||||
* For example "{a}" in: import {a} from "test"
|
||||
*
|
||||
* @author Marco Marchiò <marco.mm89@gmail.com>
|
||||
*/
|
||||
class ImportSpecifier extends ModuleSpecifier
|
||||
{
|
||||
/**
|
||||
* Map of node properties
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $propertiesMap = array(
|
||||
"imported" => true
|
||||
);
|
||||
|
||||
/**
|
||||
* Imported identifier
|
||||
*
|
||||
* @var Identifier|StringLiteral
|
||||
*/
|
||||
protected $imported;
|
||||
|
||||
/**
|
||||
* Returns the imported identifier
|
||||
*
|
||||
* @return Identifier|StringLiteral
|
||||
*/
|
||||
public function getImported()
|
||||
{
|
||||
return $this->imported;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the imported identifier
|
||||
*
|
||||
* @param Identifier|StringLiteral $imported Imported identifier
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setImported($imported)
|
||||
{
|
||||
$this->assertType($imported, array("Identifier", "StringLiteral"));
|
||||
$this->imported = $imported;
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
99
vendor/mck89/peast/lib/Peast/Syntax/Node/JSX/JSXAttribute.php
vendored
Normal file
99
vendor/mck89/peast/lib/Peast/Syntax/Node/JSX/JSXAttribute.php
vendored
Normal file
@ -0,0 +1,99 @@
|
||||
<?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\Syntax\Node\JSX;
|
||||
|
||||
use Peast\Syntax\Node\Node;
|
||||
|
||||
/**
|
||||
* A node that represents a JSX attribute.
|
||||
*
|
||||
* @author Marco Marchiò <marco.mm89@gmail.com>
|
||||
*/
|
||||
class JSXAttribute extends Node
|
||||
{
|
||||
/**
|
||||
* Map of node properties
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $propertiesMap = array(
|
||||
"name" => true,
|
||||
"value" => true
|
||||
);
|
||||
|
||||
/**
|
||||
* Attribute name
|
||||
*
|
||||
* @var JSXIdentifier|JSXNamespacedName
|
||||
*/
|
||||
protected $name;
|
||||
|
||||
/**
|
||||
* Attribute value
|
||||
*
|
||||
* @var Node|null
|
||||
*/
|
||||
protected $value;
|
||||
|
||||
/**
|
||||
* Returns the attribute name
|
||||
*
|
||||
* @return Node
|
||||
*/
|
||||
public function getName()
|
||||
{
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the attribute name
|
||||
*
|
||||
* @param JSXIdentifier|JSXNamespacedName $name Attribute name
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setName($name)
|
||||
{
|
||||
$this->assertType($name, array("JSX\\JSXIdentifier", "JSX\\JSXNamespacedName"));
|
||||
$this->name = $name;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the attribute value
|
||||
*
|
||||
* @return Node|null
|
||||
*/
|
||||
public function getValue()
|
||||
{
|
||||
return $this->value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the attribute value
|
||||
*
|
||||
* @param Node|null $value Attribute value
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setValue($value)
|
||||
{
|
||||
$this->assertType(
|
||||
$value,
|
||||
array(
|
||||
"Literal", "JSX\\JSXExpressionContainer",
|
||||
"JSX\\JSXElement", "JSX\\JSXFragment"
|
||||
),
|
||||
true
|
||||
);
|
||||
$this->value = $value;
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
66
vendor/mck89/peast/lib/Peast/Syntax/Node/JSX/JSXBoundaryElement.php
vendored
Normal file
66
vendor/mck89/peast/lib/Peast/Syntax/Node/JSX/JSXBoundaryElement.php
vendored
Normal file
@ -0,0 +1,66 @@
|
||||
<?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\Syntax\Node\JSX;
|
||||
|
||||
use Peast\Syntax\Node\Node;
|
||||
|
||||
/**
|
||||
* A base class for boundary elements.
|
||||
*
|
||||
* @author Marco Marchiò <marco.mm89@gmail.com>
|
||||
*
|
||||
* @abstract
|
||||
*/
|
||||
abstract class JSXBoundaryElement extends Node
|
||||
{
|
||||
/**
|
||||
* Map of node properties
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $propertiesMap = array(
|
||||
"name" => true
|
||||
);
|
||||
|
||||
/**
|
||||
* Element name
|
||||
*
|
||||
* @var JSXIdentifier|JSXMemberExpression|JSXNamespacedName
|
||||
*/
|
||||
protected $name;
|
||||
|
||||
/**
|
||||
* Returns the element name
|
||||
*
|
||||
* @return JSXIdentifier|JSXMemberExpression|JSXNamespacedName
|
||||
*/
|
||||
public function getName()
|
||||
{
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the element name
|
||||
*
|
||||
* @param JSXIdentifier|JSXMemberExpression|JSXNamespacedName $name Element
|
||||
* name
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setName($name)
|
||||
{
|
||||
$this->assertType(
|
||||
$name,
|
||||
array("JSX\\JSXIdentifier", "JSX\\JSXMemberExpression", "JSX\\JSXNamespacedName")
|
||||
);
|
||||
$this->name = $name;
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
19
vendor/mck89/peast/lib/Peast/Syntax/Node/JSX/JSXClosingElement.php
vendored
Normal file
19
vendor/mck89/peast/lib/Peast/Syntax/Node/JSX/JSXClosingElement.php
vendored
Normal file
@ -0,0 +1,19 @@
|
||||
<?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\Syntax\Node\JSX;
|
||||
|
||||
/**
|
||||
* A node that represents a JSX closing element tag.
|
||||
*
|
||||
* @author Marco Marchiò <marco.mm89@gmail.com>
|
||||
*/
|
||||
class JSXClosingElement extends JSXBoundaryElement
|
||||
{
|
||||
}
|
||||
21
vendor/mck89/peast/lib/Peast/Syntax/Node/JSX/JSXClosingFragment.php
vendored
Normal file
21
vendor/mck89/peast/lib/Peast/Syntax/Node/JSX/JSXClosingFragment.php
vendored
Normal file
@ -0,0 +1,21 @@
|
||||
<?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\Syntax\Node\JSX;
|
||||
|
||||
use Peast\Syntax\Node\Node;
|
||||
|
||||
/**
|
||||
* A node that represents a JSX closing fragment tag.
|
||||
*
|
||||
* @author Marco Marchiò <marco.mm89@gmail.com>
|
||||
*/
|
||||
class JSXClosingFragment extends Node
|
||||
{
|
||||
}
|
||||
127
vendor/mck89/peast/lib/Peast/Syntax/Node/JSX/JSXElement.php
vendored
Normal file
127
vendor/mck89/peast/lib/Peast/Syntax/Node/JSX/JSXElement.php
vendored
Normal file
@ -0,0 +1,127 @@
|
||||
<?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\Syntax\Node\JSX;
|
||||
|
||||
use Peast\Syntax\Node\Node;
|
||||
use Peast\Syntax\Node\Expression;
|
||||
|
||||
/**
|
||||
* A node that represents a JSX element.
|
||||
*
|
||||
* @author Marco Marchiò <marco.mm89@gmail.com>
|
||||
*/
|
||||
class JSXElement extends Node implements Expression
|
||||
{
|
||||
/**
|
||||
* Map of node properties
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $propertiesMap = array(
|
||||
"openingElement" => true,
|
||||
"children" => true,
|
||||
"closingElement" => true
|
||||
);
|
||||
|
||||
/**
|
||||
* Opening element node
|
||||
*
|
||||
* @var JSXOpeningElement
|
||||
*/
|
||||
protected $openingElement;
|
||||
|
||||
/**
|
||||
* Children nodes array
|
||||
*
|
||||
* @var Node[]
|
||||
*/
|
||||
protected $children = array();
|
||||
|
||||
/**
|
||||
* Closing element node
|
||||
*
|
||||
* @var JSXClosingElement|null
|
||||
*/
|
||||
protected $closingElement;
|
||||
|
||||
/**
|
||||
* Returns the opening element node
|
||||
*
|
||||
* @return JSXOpeningElement
|
||||
*/
|
||||
public function getOpeningElement()
|
||||
{
|
||||
return $this->openingElement;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the opening element node
|
||||
*
|
||||
* @param JSXOpeningElement $openingElement Opening element node
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setOpeningElement(JSXOpeningElement $openingElement)
|
||||
{
|
||||
$this->openingElement = $openingElement;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the children nodes array
|
||||
*
|
||||
* @return Node[]
|
||||
*/
|
||||
public function getChildren()
|
||||
{
|
||||
return $this->children;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the children nodes array
|
||||
*
|
||||
* @param Node[] $children Children nodes array
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setChildren($children)
|
||||
{
|
||||
$this->assertArrayOf($children, array(
|
||||
"JSX\\JSXText", "JSX\\JSXExpressionContainer", "JSX\\JSXSpreadChild",
|
||||
"JSX\\JSXElement", "JSX\\JSXFragment"
|
||||
));
|
||||
$this->children = $children;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the closing element node
|
||||
*
|
||||
* @return JSXClosingElement|null
|
||||
*/
|
||||
public function getClosingElement()
|
||||
{
|
||||
return $this->closingElement;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the closing element node
|
||||
*
|
||||
* @param JSXClosingElement|null $closingElement Closing element node
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setClosingElement($closingElement)
|
||||
{
|
||||
$this->assertType($closingElement, "JSX\\JSXClosingElement", true);
|
||||
$this->closingElement = $closingElement;
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
21
vendor/mck89/peast/lib/Peast/Syntax/Node/JSX/JSXEmptyExpression.php
vendored
Normal file
21
vendor/mck89/peast/lib/Peast/Syntax/Node/JSX/JSXEmptyExpression.php
vendored
Normal file
@ -0,0 +1,21 @@
|
||||
<?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\Syntax\Node\JSX;
|
||||
|
||||
use Peast\Syntax\Node\Node;
|
||||
|
||||
/**
|
||||
* A node that represents a JSX empty expression.
|
||||
*
|
||||
* @author Marco Marchiò <marco.mm89@gmail.com>
|
||||
*/
|
||||
class JSXEmptyExpression extends Node
|
||||
{
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user