🆙 Add cms i using 🆙

This commit is contained in:
Remco
2025-11-25 22:42:56 +01:00
parent 94704e0925
commit d44196149e
35591 changed files with 3601123 additions and 0 deletions
+27
View File
@@ -0,0 +1,27 @@
Copyright (c) 2014, Glayzzle
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
* 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.
* Neither the name of test-bsd 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.
+108
View File
@@ -0,0 +1,108 @@
<h1 align="center">php-parser</h1>
<p align="center">
<a title="npm version" href="https://www.npmjs.com/package/php-parser"><img src="https://badge.fury.io/js/php-parser.svg"></a>
<a title="npm downloads" href="https://www.npmjs.com/package/php-parser"><img src="https://img.shields.io/npm/dm/php-parser.svg?style=flat"></a>
<a title="Gitter" href="https://gitter.im/glayzzle/Lobby"><img src="https://img.shields.io/badge/GITTER-join%20chat-green.svg"></a>
</p>
<p align="center">This JavaScript library parses PHP code and converts it to an AST.</p>
## Installation
This library is distributed with [npm](https://www.npmjs.com/package/php-parser) :
```sh
npm install php-parser --save
```
## Usage
```js
// initialize the php parser factory class
const fs = require("fs");
const path = require("path");
const engine = require("php-parser");
// initialize a new parser instance
const parser = new engine({
// some options :
parser: {
extractDoc: true,
php7: true,
},
ast: {
withPositions: true,
},
});
// Retrieve the AST from the specified source
const eval = parser.parseEval('echo "Hello World";');
// Retrieve an array of tokens (same as php function token_get_all)
const tokens = parser.tokenGetAll('<?php echo "Hello World";');
// Load a static file (Note: this file should exist on your computer)
const phpFile = fs.readFileSync("./example.php");
// Log out results
console.log("Eval parse:", eval);
console.log("Tokens parse:", tokens);
console.log("File parse:", parser.parseCode(phpFile));
```
## Sample AST output
```js
{
'kind': 'program',
'children': [
{
'kind': 'echo',
'arguments': [
{
'kind': 'string',
'isDoubleQuote': true,
'value': 'Hello World'
}
]
}
]
}
```
- Try it online (demo) : http://glayzzle.com/php-parser/
- Or from AST Explorer : https://astexplorer.net/
## API Overview
The main API exposes a class with the following methods :
- **parseEval**(String|Buffer) : parse a PHP code in eval style mode (without php open tags)
- **parseCode**(String|Buffer, String filename) : parse a PHP code by using php open tags.
- **tokenGetAll**(String|Buffer) : retrieves a list of all tokens from the specified input.
You can also [pass options](https://github.com/glayzzle/php-parser/wiki/Options) that change the behavior of the parser/lexer.
## Documentation
- [AST nodes definition](https://php-parser.glayzzle.com/api/ast.js)
- [Sandbox](https://php-parser.glayzzle.com/demo)
- [List of options](https://php-parser.glayzzle.com/guides/options)
## Related projects
- [prettier/plugin-php](https://github.com/prettier/plugin-php) : Prettier PHP Plugin
- [babel-preset-php](https://gitlab.com/kornelski/babel-preset-php) : Babel preset for converting PHP syntax to JavaScript. It can run subset of PHP in the browser or in Node.js
- [wp-pot](https://github.com/rasmusbe/wp-pot) : Generate pot file for WordPress plugins and themes
- [crane](https://github.com/HvyIndustries/crane) : PHP Intellisense/code-completion for VS Code
- [php-unparser](https://github.com/chris-l/php-unparser) : Produce code that uses the style format recommended by PSR-1 and PSR-2.
- [php-writer](https://github.com/glayzzle/php-writer) : Update PHP scripts from their AST
- [ts-php-inspections](https://github.com/DaGhostman/ts-php-inspections) : Provide PHP code inspections written in typescript
- [php-reflection](https://github.com/glayzzle/php-reflection) : Reflection API for PHP files
- [vscode-phpunit](https://github.com/recca0120/vscode-phpunit) : vscode phpunit extension
- [lua2php](https://www.npmjs.com/package/lua2php) : a Lua to PHP transpiler
> You can add here your own project by opening an issue request.
## License
This library is released under BSD-3 license clause.
File diff suppressed because it is too large Load Diff
File diff suppressed because one or more lines are too long
@@ -0,0 +1,10 @@
/*!
*
* Package: php-parser
* Parse PHP code from JS and returns its AST
* Build: 966fc2556208046b400c - 6/7/2023
* Copyright (C) 2021 Glayzzle (BSD-3-Clause)
* @authors https://github.com/glayzzle/php-parser/graphs/contributors
* @url http://glayzzle.com
*
*/
+86
View File
@@ -0,0 +1,86 @@
{
"name": "php-parser",
"version": "3.1.5",
"description": "Parse PHP code from JS and returns its AST",
"main": "src/index.js",
"browser": "dist/php-parser.js",
"files": [
"src",
"dist",
"types.d.ts",
"LICENSE"
],
"types": "types.d.ts",
"scripts": {
"fix": "eslint . --fix",
"test": "jest",
"husky": "yarpm run test",
"prepublishOnly": "yarpm run build",
"prebuild": "yarpm run test",
"build": "webpack --config webpack.config.js",
"-postbuild": "yarpm run build-docs",
"build-docs": "jsdoc -c .jsdoc.json",
"build-types": "jsdoc -t node_modules/tsd-jsdoc/dist -r src -d . && prettier -w types.d.ts",
"publish-docs": "git subtree push --prefix docs origin gh-pages",
"benchmark": "node test/benchmark.js"
},
"husky": {
"hooks": {
"pre-commit": "yarpm run husky"
}
},
"repository": {
"type": "git",
"url": "https://github.com/glayzzle/php-parser"
},
"bugs": {
"url": "https://github.com/glayzzle/php-parser/issues"
},
"homepage": "https://glayzzle.com/",
"keywords": [
"php",
"php5",
"php7",
"php8",
"parser",
"lexer",
"tokenizer",
"ast"
],
"author": "Ioan CHIRIAC",
"contributors": [
{
"name": "Filippo Conti",
"email": "filippo@codekraft.it",
"url": "https://b4dnewz.github.io/"
},
{
"name": "Christian Zosel",
"email": "christian@zosel.ch",
"url": "https://twitter.com/chrzosel"
}
],
"license": "BSD-3-Clause",
"devDependencies": {
"@babel/core": "^7.21.3",
"@babel/preset-env": "^7.20.2",
"babel-loader": "^9.1.2",
"benchmark": "^2.1.4",
"coveralls": "^3.0.3",
"eslint": "^8.36.0",
"eslint-plugin-jest": "^27.2.1",
"eslint-plugin-prettier": "^4.2.1",
"husky": "^8.0.3",
"jest": "^29.5.0",
"jest-runner-eslint": "^2.0.0",
"jsdoc": "^3.6.11",
"jsdoc-template": "^1.2.0",
"lodash.template": ">=4.5.0",
"prettier": "^2.8.6",
"tsd-jsdoc": "^2.5.0",
"webpack": "^5.76.2",
"webpack-cli": "^5.0.1",
"yarpm": "^1.2.0"
},
"dependencies": {}
}
+591
View File
@@ -0,0 +1,591 @@
/**
* Copyright (C) 2018 Glayzzle (BSD3 License)
* @authors https://github.com/glayzzle/php-parser/graphs/contributors
* @url http://glayzzle.com
*/
"use strict";
const Location = require("./ast/location");
const Position = require("./ast/position");
/**
* ## Class hierarchy
*
* - [Location](#location)
* - [Position](#position)
* - [Node](#node)
* - [Noop](#noop)
* - [NullKeyword](#nullkeyword)
* - [StaticVariable](#staticvariable)
* - [EncapsedPart](#encapsedpart)
* - [Constant](#constant)
* - [Identifier](#identifier)
* - [Reference](#reference)
* - [TypeReference](#typereference)
* - [ParentReference](#parentreference)
* - [StaticReference](#staticreference)
* - [SelfReference](#selfreference)
* - [Name](#name)
* - [TraitUse](#traituse)
* - [TraitAlias](#traitalias)
* - [TraitPrecedence](#traitprecedence)
* - [Comment](#comment)
* - [CommentLine](#commentline)
* - [CommentBlock](#commentblock)
* - [Error](#error)
* - [Expression](#expression)
* - [Entry](#entry)
* - [ArrowFunc](#arrowfunc)
* - [Closure](#closure)
* - [ByRef](#byref)
* - [Silent](#silent)
* - [RetIf](#retif)
* - [New](#new)
* - [Include](#include)
* - [Call](#call)
* - [Eval](#eval)
* - [Exit](#exit)
* - [Clone](#clone)
* - [Assign](#assign)
* - [AssignRef](#assignref)
* - [Array](#array)
* - [List](#list)
* - [Variable](#variable)
* - [Variadic](#variadic)
* - [Yield](#yield)
* - [YieldFrom](#yieldfrom)
* - [Print](#print)
* - [Isset](#isset)
* - [Empty](#empty)
* - [Lookup](#lookup)
* - [PropertyLookup](#propertylookup)
* - [StaticLookup](#staticlookup)
* - [OffsetLookup](#offsetlookup)
* - [Operation](#operation)
* - [Pre](#pre)
* - [Post](#post)
* - [Bin](#bin)
* - [Unary](#unary)
* - [Cast](#cast)
* - [Literal](#literal)
* - [Boolean](#boolean)
* - [String](#string)
* - [Number](#number)
* - [Inline](#inline)
* - [Magic](#magic)
* - [Nowdoc](#nowdoc)
* - [Encapsed](#encapsed)
* - [Statement](#statement)
* - [ConstantStatement](#constantstatement)
* - [ClassConstant](#classconstant)
* - [Return](#return)
* - [Label](#label)
* - [Continue](#continue)
* - [Case](#case)
* - [Break](#break)
* - [Echo](#echo)
* - [Unset](#unset)
* - [Halt](#halt)
* - [Declare](#declare)
* - [Global](#global)
* - [Static](#static)
* - [If](#if)
* - [Do](#do)
* - [While](#while)
* - [For](#for)
* - [Foreach](#foreach)
* - [Switch](#switch)
* - [Goto](#goto)
* - [Try](#try)
* - [Catch](#catch)
* - [Throw](#throw)
* - [UseGroup](#usegroup)
* - [UseItem](#useitem)
* - [Block](#block)
* - [Program](#program)
* - [Namespace](#namespace)
* - [PropertyStatement](#propertystatement)
* - [Property](#property)
* - [Declaration](#declaration)
* - [Class](#class)
* - [Interface](#interface)
* - [Trait](#trait)
* - [Function](#function)
* - [Method](#method)
* - [Parameter](#parameter)
* ---
*/
/**
* The AST builder class
* @constructor AST
* @memberOf module:php-parser
* @tutorial AST
* @property {Boolean} withPositions - Should locate any node (by default false)
* @property {Boolean} withSource - Should extract the node original code (by default false)
*/
const AST = function (withPositions, withSource) {
this.withPositions = withPositions;
this.withSource = withSource;
};
// operators in ascending order of precedence
AST.precedence = {};
[
["or"],
["xor"],
["and"],
["="],
["?"],
["??"],
["||"],
["&&"],
["|"],
["^"],
["&"],
["==", "!=", "===", "!==", /* '<>', */ "<=>"],
["<", "<=", ">", ">="],
["<<", ">>"],
["+", "-", "."],
["*", "/", "%"],
["!"],
["instanceof"],
["cast", "silent"],
["**"],
// TODO: [ (array)
// TODO: clone, new
].forEach(function (list, index) {
list.forEach(function (operator) {
AST.precedence[operator] = index + 1;
});
});
/**
* @private
* @function AST#isRightAssociative
* @memberOf module:php-parser
* @param operator
* @return {boolean}
*/
AST.prototype.isRightAssociative = function (operator) {
return operator === "**" || operator === "??";
};
/**
* Change parent node informations after swapping childs
* @private
* @function AST#swapLocations
* @memberOf module:php-parser
*/
AST.prototype.swapLocations = function (target, first, last, parser) {
if (this.withPositions) {
target.loc.start = first.loc.start;
target.loc.end = last.loc.end;
if (this.withSource) {
target.loc.source = parser.lexer._input.substring(
target.loc.start.offset,
target.loc.end.offset
);
}
}
};
/**
* Includes locations from first & last into the target
* @private
* @function AST#resolveLocations
* @memberOf module:php-parser
*/
AST.prototype.resolveLocations = function (target, first, last, parser) {
if (this.withPositions) {
if (target.loc.start.offset > first.loc.start.offset) {
target.loc.start = first.loc.start;
}
/* istanbul ignore next */
if (target.loc.end.offset < last.loc.end.offset) {
target.loc.end = last.loc.end;
}
if (this.withSource) {
target.loc.source = parser.lexer._input.substring(
target.loc.start.offset,
target.loc.end.offset
);
}
}
};
/**
* Check and fix precence, by default using right
* @private
* @function AST#resolvePrecedence
* @memberOf module:php-parser
*/
AST.prototype.resolvePrecedence = function (result, parser) {
let buffer, lLevel, rLevel;
// handling precendence
if (result.kind === "call") {
// including what argument into location
this.resolveLocations(result, result.what, result, parser);
} else if (
result.kind === "propertylookup" ||
result.kind === "staticlookup" ||
(result.kind === "offsetlookup" && result.offset)
) {
// including what argument into location
this.resolveLocations(result, result.what, result.offset, parser);
} else if (result.kind === "bin") {
if (result.right && !result.right.parenthesizedExpression) {
if (result.right.kind === "bin") {
lLevel = AST.precedence[result.type];
rLevel = AST.precedence[result.right.type];
if (
lLevel &&
rLevel &&
rLevel <= lLevel &&
(result.type !== result.right.type ||
!this.isRightAssociative(result.type))
) {
// https://github.com/glayzzle/php-parser/issues/79
// shift precedence
buffer = result.right;
result.right = result.right.left;
this.swapLocations(result, result.left, result.right, parser);
buffer.left = this.resolvePrecedence(result, parser);
this.swapLocations(buffer, buffer.left, buffer.right, parser);
result = buffer;
}
} else if (result.right.kind === "retif") {
lLevel = AST.precedence[result.type];
rLevel = AST.precedence["?"];
if (lLevel && rLevel && rLevel <= lLevel) {
buffer = result.right;
result.right = result.right.test;
this.swapLocations(result, result.left, result.right, parser);
buffer.test = this.resolvePrecedence(result, parser);
this.swapLocations(buffer, buffer.test, buffer.falseExpr, parser);
result = buffer;
}
}
}
} else if (
(result.kind === "silent" || result.kind === "cast") &&
result.expr &&
!result.expr.parenthesizedExpression
) {
// https://github.com/glayzzle/php-parser/issues/172
if (result.expr.kind === "bin") {
buffer = result.expr;
result.expr = result.expr.left;
this.swapLocations(result, result, result.expr, parser);
buffer.left = this.resolvePrecedence(result, parser);
this.swapLocations(buffer, buffer.left, buffer.right, parser);
result = buffer;
} else if (result.expr.kind === "retif") {
buffer = result.expr;
result.expr = result.expr.test;
this.swapLocations(result, result, result.expr, parser);
buffer.test = this.resolvePrecedence(result, parser);
this.swapLocations(buffer, buffer.test, buffer.falseExpr, parser);
result = buffer;
}
} else if (result.kind === "unary") {
// https://github.com/glayzzle/php-parser/issues/75
if (result.what && !result.what.parenthesizedExpression) {
// unary precedence is always lower
if (result.what.kind === "bin") {
buffer = result.what;
result.what = result.what.left;
this.swapLocations(result, result, result.what, parser);
buffer.left = this.resolvePrecedence(result, parser);
this.swapLocations(buffer, buffer.left, buffer.right, parser);
result = buffer;
} else if (result.what.kind === "retif") {
buffer = result.what;
result.what = result.what.test;
this.swapLocations(result, result, result.what, parser);
buffer.test = this.resolvePrecedence(result, parser);
this.swapLocations(buffer, buffer.test, buffer.falseExpr, parser);
result = buffer;
}
}
} else if (result.kind === "retif") {
// https://github.com/glayzzle/php-parser/issues/77
if (
result.falseExpr &&
result.falseExpr.kind === "retif" &&
!result.falseExpr.parenthesizedExpression
) {
buffer = result.falseExpr;
result.falseExpr = buffer.test;
this.swapLocations(result, result.test, result.falseExpr, parser);
buffer.test = this.resolvePrecedence(result, parser);
this.swapLocations(buffer, buffer.test, buffer.falseExpr, parser);
result = buffer;
}
} else if (result.kind === "assign") {
// https://github.com/glayzzle/php-parser/issues/81
if (
result.right &&
result.right.kind === "bin" &&
!result.right.parenthesizedExpression
) {
lLevel = AST.precedence["="];
rLevel = AST.precedence[result.right.type];
// only shifts with and, xor, or
if (lLevel && rLevel && rLevel < lLevel) {
buffer = result.right;
result.right = result.right.left;
buffer.left = result;
this.swapLocations(buffer, buffer.left, result.right, parser);
result = buffer;
}
}
} else if (result.kind === "expressionstatement") {
this.swapLocations(result, result.expression, result, parser);
}
return result;
};
/**
* Prepares an AST node
* @private
* @function AST#prepare
* @memberOf module:php-parser
* @param {String|null} kind - Defines the node type
* @param {*} docs - (if null, the kind must be passed at the function call)
* @param {Parser} parser - The parser instance (use for extracting locations)
* @return {Function}
*/
AST.prototype.prepare = function (kind, docs, parser) {
let start = null;
if (this.withPositions || this.withSource) {
start = parser.position();
}
const self = this;
// returns the node
const result = function () {
let location = null;
const args = Array.prototype.slice.call(arguments);
args.push(docs);
if (self.withPositions || self.withSource) {
let src = null;
if (self.withSource) {
src = parser.lexer._input.substring(start.offset, parser.prev[2]);
}
// if with source, need location on swapLocations function
location = new Location(
src,
start,
new Position(parser.prev[0], parser.prev[1], parser.prev[2])
);
// last argument is always the location
args.push(location);
}
// handle lazy kind definitions
if (!kind) {
kind = args.shift();
}
// build the object
const node = self[kind];
if (typeof node !== "function") {
throw new Error('Undefined node "' + kind + '"');
}
const astNode = Object.create(node.prototype);
node.apply(astNode, args);
result.instance = astNode;
/* istanbul ignore next */
if (result.trailingComments) {
// buffer of trailingComments
astNode.trailingComments = result.trailingComments;
}
if (typeof result.postBuild === "function") {
result.postBuild(astNode);
}
if (parser.debug) {
delete self.stack[result.stackUid];
}
return self.resolvePrecedence(astNode, parser);
};
if (parser.debug) {
if (!this.stack) {
this.stack = {};
this.stackUid = 1;
}
this.stack[++this.stackUid] = {
position: start,
stack: new Error().stack.split("\n").slice(3, 5),
};
result.stackUid = this.stackUid;
}
/**
* Sets a list of trailing comments
* @private
* @param {*} docs
*/
result.setTrailingComments = function (docs) {
if (result.instance) {
// already created
result.instance.setTrailingComments(docs);
} else {
result.trailingComments = docs;
}
};
/**
* Release a node without using it on the AST
* @private
* @param {*} target
*/
result.destroy = function (target) {
if (docs) {
// release current docs stack
if (target) {
if (!target.leadingComments) {
target.leadingComments = docs;
} else {
target.leadingComments = docs.concat(target.leadingComments);
}
} else {
parser._docIndex = parser._docs.length - docs.length;
}
}
if (parser.debug) {
delete self.stack[result.stackUid];
}
};
return result;
};
AST.prototype.checkNodes = function () {
const errors = [];
for (const k in this.stack) {
if (Object.prototype.hasOwnProperty.call(this.stack, k)) {
this.stack[k].key = k;
errors.push(this.stack[k]);
}
}
this.stack = {};
return errors;
};
// Define all AST nodes
[
require("./ast/array"),
require("./ast/arrowfunc"),
require("./ast/assign"),
require("./ast/assignref"),
require("./ast/attribute"),
require("./ast/attrgroup"),
require("./ast/bin"),
require("./ast/block"),
require("./ast/boolean"),
require("./ast/break"),
require("./ast/byref"),
require("./ast/call"),
require("./ast/case"),
require("./ast/cast"),
require("./ast/catch"),
require("./ast/class"),
require("./ast/classconstant"),
require("./ast/clone"),
require("./ast/closure"),
require("./ast/comment"),
require("./ast/commentblock"),
require("./ast/commentline"),
require("./ast/constant"),
require("./ast/constantstatement"),
require("./ast/continue"),
require("./ast/declaration"),
require("./ast/declare"),
require("./ast/declaredirective"),
require("./ast/do"),
require("./ast/echo"),
require("./ast/empty"),
require("./ast/encapsed"),
require("./ast/encapsedpart"),
require("./ast/entry"),
require("./ast/enum"),
require("./ast/enumcase"),
require("./ast/error"),
require("./ast/eval"),
require("./ast/exit"),
require("./ast/expression"),
require("./ast/expressionstatement"),
require("./ast/for"),
require("./ast/foreach"),
require("./ast/function"),
require("./ast/global"),
require("./ast/goto"),
require("./ast/halt"),
require("./ast/identifier"),
require("./ast/if"),
require("./ast/include"),
require("./ast/inline"),
require("./ast/interface"),
require("./ast/intersectiontype"),
require("./ast/isset"),
require("./ast/label"),
require("./ast/list"),
require("./ast/literal"),
require("./ast/lookup"),
require("./ast/magic"),
require("./ast/match"),
require("./ast/matcharm"),
require("./ast/method"),
require("./ast/name"),
require("./ast/namespace"),
require("./ast/namedargument"),
require("./ast/new"),
require("./ast/node"),
require("./ast/noop"),
require("./ast/nowdoc"),
require("./ast/nullkeyword"),
require("./ast/nullsafepropertylookup"),
require("./ast/number"),
require("./ast/offsetlookup"),
require("./ast/operation"),
require("./ast/parameter"),
require("./ast/parentreference"),
require("./ast/post"),
require("./ast/pre"),
require("./ast/print"),
require("./ast/program"),
require("./ast/property"),
require("./ast/propertylookup"),
require("./ast/propertystatement"),
require("./ast/reference"),
require("./ast/retif"),
require("./ast/return"),
require("./ast/selfreference"),
require("./ast/silent"),
require("./ast/statement"),
require("./ast/static"),
require("./ast/staticvariable"),
require("./ast/staticlookup"),
require("./ast/staticreference"),
require("./ast/string"),
require("./ast/switch"),
require("./ast/throw"),
require("./ast/trait"),
require("./ast/traitalias"),
require("./ast/traitprecedence"),
require("./ast/traituse"),
require("./ast/try"),
require("./ast/typereference"),
require("./ast/unary"),
require("./ast/uniontype"),
require("./ast/unset"),
require("./ast/usegroup"),
require("./ast/useitem"),
require("./ast/variable"),
require("./ast/variadic"),
require("./ast/variadicplaceholder"),
require("./ast/while"),
require("./ast/yield"),
require("./ast/yieldfrom"),
].forEach(function (ctor) {
AST.prototype[ctor.kind] = ctor;
});
module.exports = AST;
@@ -0,0 +1,44 @@
/**
* Copyright (C) 2018 Glayzzle (BSD3 License)
* @authors https://github.com/glayzzle/php-parser/graphs/contributors
* @url http://glayzzle.com
*/
"use strict";
const Expr = require("./expression");
const KIND = "array";
/**
* Defines an array structure
* @constructor Array
* @memberOf module:php-parser
* @example
* // PHP code :
* [1, 'foo' => 'bar', 3]
*
* // AST structure :
* {
* "kind": "array",
* "shortForm": true
* "items": [
* {"kind": "number", "value": "1"},
* {
* "kind": "entry",
* "key": {"kind": "string", "value": "foo", "isDoubleQuote": false},
* "value": {"kind": "string", "value": "bar", "isDoubleQuote": false}
* },
* {"kind": "number", "value": "3"}
* ]
* }
* @extends {Expression}
* @property {Array<Entry|Expression|Variable>} items List of array items
* @property {boolean} shortForm Indicate if the short array syntax is used, ex `[]` instead `array()`
*/
module.exports = Expr.extends(
KIND,
function Array(shortForm, items, docs, location) {
Expr.apply(this, [KIND, docs, location]);
this.items = items;
this.shortForm = shortForm;
}
);
@@ -0,0 +1,43 @@
/**
* Copyright (C) 2018 Glayzzle (BSD3 License)
* @authors https://github.com/glayzzle/php-parser/graphs/contributors
* @url http://glayzzle.com
*/
"use strict";
const Expression = require("./expression");
const KIND = "arrowfunc";
/**
* Defines an arrow function (it's like a closure)
* @constructor ArrowFunc
* @memberOf module:php-parser
* @extends {Expression}
* @property {Parameter[]} arguments
* @property {Identifier} type
* @property {Expression} body
* @property {boolean} byref
* @property {boolean} nullable
* @property {boolean} isStatic
*/
module.exports = Expression.extends(
KIND,
function Closure(
args,
byref,
body,
type,
nullable,
isStatic,
docs,
location
) {
Expression.apply(this, [KIND, docs, location]);
this.arguments = args;
this.byref = byref;
this.body = body;
this.type = type;
this.nullable = nullable;
this.isStatic = isStatic || false;
}
);
@@ -0,0 +1,28 @@
/**
* Copyright (C) 2018 Glayzzle (BSD3 License)
* @authors https://github.com/glayzzle/php-parser/graphs/contributors
* @url http://glayzzle.com
*/
"use strict";
const Expression = require("./expression");
const KIND = "assign";
/**
* Assigns a value to the specified target
* @constructor Assign
* @memberOf module:php-parser
* @extends {Expression}
* @property {Expression} left
* @property {Expression} right
* @property {String} operator
*/
module.exports = Expression.extends(
KIND,
function Assign(left, right, operator, docs, location) {
Expression.apply(this, [KIND, docs, location]);
this.left = left;
this.right = right;
this.operator = operator;
}
);
@@ -0,0 +1,27 @@
/**
* Copyright (C) 2018 Glayzzle (BSD3 License)
* @authors https://github.com/glayzzle/php-parser/graphs/contributors
* @url http://glayzzle.com
*/
"use strict";
const Expression = require("./expression");
const KIND = "assignref";
/**
* Assigns a value to the specified target
* @constructor AssignRef
* @memberOf module:php-parser
* @extends {Expression}
* @property {Expression} left
* @property {Expression} right
* @property {String} operator
*/
module.exports = Expression.extends(
KIND,
function AssignRef(left, right, docs, location) {
Expression.apply(this, [KIND, docs, location]);
this.left = left;
this.right = right;
}
);
@@ -0,0 +1,21 @@
/**
* Copyright (C) 2018 Glayzzle (BSD3 License)
* @authors https://github.com/glayzzle/php-parser/graphs/contributors
* @url http://glayzzle.com
*/
"use strict";
const Node = require("./node");
const KIND = "attrgroup";
/**
* Attribute group
* @memberOf module:php-parser
* @constructor AttrGroup
* @extends {Node}
* @property {Attribute[]} attrs
*/
module.exports = Node.extends(KIND, function AttrGroup(attrs, docs, location) {
Node.apply(this, [KIND, docs, location]);
this.attrs = attrs || [];
});
@@ -0,0 +1,26 @@
/**
* Copyright (C) 2018 Glayzzle (BSD3 License)
* @authors https://github.com/glayzzle/php-parser/graphs/contributors
* @url http://glayzzle.com
*/
"use strict";
const Node = require("./node");
const KIND = "attribute";
/**
* Attribute Value
* @memberOf module:php-parser
* @constructor Attribute
* @extends {Node}
* @property {String} name
* @property {Parameter[]} args
*/
module.exports = Node.extends(
KIND,
function Attribute(name, args, docs, location) {
Node.apply(this, [KIND, docs, location]);
this.name = name;
this.args = args;
}
);
+27
View File
@@ -0,0 +1,27 @@
/**
* Copyright (C) 2018 Glayzzle (BSD3 License)
* @authors https://github.com/glayzzle/php-parser/graphs/contributors
* @url http://glayzzle.com
*/
"use strict";
const Operation = require("./operation");
const KIND = "bin";
/**
* Binary operations
* @constructor Bin
* @memberOf module:php-parser
* @extends {Operation}
* @property {String} type
* @property {Expression} left
* @property {Expression} right
*/
module.exports = Operation.extends(
KIND,
function Bin(type, left, right, docs, location) {
Operation.apply(this, [KIND, docs, location]);
this.type = type;
this.left = left;
this.right = right;
}
);
@@ -0,0 +1,24 @@
/**
* Copyright (C) 2018 Glayzzle (BSD3 License)
* @authors https://github.com/glayzzle/php-parser/graphs/contributors
* @url http://glayzzle.com
*/
"use strict";
const Statement = require("./statement");
const KIND = "block";
/**
* A block statement, i.e., a sequence of statements surrounded by braces.
* @constructor Block
* @memberOf module:php-parser
* @extends {Statement}
* @property {Node[]} children
*/
module.exports = Statement.extends(
KIND,
function Block(kind, children, docs, location) {
Statement.apply(this, [kind || KIND, docs, location]);
this.children = children.filter(Boolean);
}
);
@@ -0,0 +1,23 @@
/**
* Copyright (C) 2018 Glayzzle (BSD3 License)
* @authors https://github.com/glayzzle/php-parser/graphs/contributors
* @url http://glayzzle.com
*/
"use strict";
const Literal = require("./literal");
const KIND = "boolean";
/**
* Defines a boolean value (true/false)
* @constructor Boolean
* @memberOf module:php-parser
* @extends {Literal}
* @property {boolean} value
*/
module.exports = Literal.extends(
KIND,
function Boolean(value, raw, docs, location) {
Literal.apply(this, [KIND, value, raw, docs, location]);
}
);
@@ -0,0 +1,21 @@
/**
* Copyright (C) 2018 Glayzzle (BSD3 License)
* @authors https://github.com/glayzzle/php-parser/graphs/contributors
* @url http://glayzzle.com
*/
"use strict";
const Statement = require("./statement");
const KIND = "break";
/**
* A break statement
* @constructor Break
* @memberOf module:php-parser
* @extends {Statement}
* @property {Number|Null} level
*/
module.exports = Statement.extends(KIND, function Break(level, docs, location) {
Statement.apply(this, [KIND, docs, location]);
this.level = level;
});
@@ -0,0 +1,21 @@
/**
* Copyright (C) 2018 Glayzzle (BSD3 License)
* @authors https://github.com/glayzzle/php-parser/graphs/contributors
* @url http://glayzzle.com
*/
"use strict";
const Expression = require("./expression");
const KIND = "byref";
/**
* Passing by Reference - so the function can modify the variable
* @constructor ByRef
* @memberOf module:php-parser
* @extends {Expression}
* @property {ExpressionStatement} what
*/
module.exports = Expression.extends(KIND, function ByRef(what, docs, location) {
Expression.apply(this, [KIND, docs, location]);
this.what = what;
});
@@ -0,0 +1,26 @@
/**
* Copyright (C) 2018 Glayzzle (BSD3 License)
* @authors https://github.com/glayzzle/php-parser/graphs/contributors
* @url http://glayzzle.com
*/
"use strict";
const Expression = require("./expression");
const KIND = "call";
/**
* Executes a call statement
* @constructor Call
* @memberOf module:php-parser
* @extends {Expression}
* @property {Identifier|Variable} what
* @property {Expression[]} arguments
*/
module.exports = Expression.extends(
KIND,
function Call(what, args, docs, location) {
Expression.apply(this, [KIND, docs, location]);
this.what = what;
this.arguments = args;
}
);
@@ -0,0 +1,26 @@
/**
* Copyright (C) 2018 Glayzzle (BSD3 License)
* @authors https://github.com/glayzzle/php-parser/graphs/contributors
* @url http://glayzzle.com
*/
"use strict";
const Statement = require("./statement");
const KIND = "case";
/**
* A switch case statement
* @constructor Case
* @memberOf module:php-parser
* @extends {Statement}
* @property {Expression|null} test - if null, means that the default case
* @property {Block|null} body
*/
module.exports = Statement.extends(
KIND,
function Case(test, body, docs, location) {
Statement.apply(this, [KIND, docs, location]);
this.test = test;
this.body = body;
}
);
@@ -0,0 +1,28 @@
/**
* Copyright (C) 2018 Glayzzle (BSD3 License)
* @authors https://github.com/glayzzle/php-parser/graphs/contributors
* @url http://glayzzle.com
*/
"use strict";
const Operation = require("./operation");
const KIND = "cast";
/**
* Binary operations
* @constructor Cast
* @memberOf module:php-parser
* @extends {Operation}
* @property {String} type
* @property {String} raw
* @property {Expression} expr
*/
module.exports = Operation.extends(
KIND,
function Cast(type, raw, expr, docs, location) {
Operation.apply(this, [KIND, docs, location]);
this.type = type;
this.raw = raw;
this.expr = expr;
}
);
@@ -0,0 +1,29 @@
/**
* Copyright (C) 2018 Glayzzle (BSD3 License)
* @authors https://github.com/glayzzle/php-parser/graphs/contributors
* @url http://glayzzle.com
*/
"use strict";
const Statement = require("./statement");
const KIND = "catch";
/**
* Defines a catch statement
* @constructor Catch
* @memberOf module:php-parser
* @extends {Statement}
* @property {Name[]} what
* @property {Variable} variable
* @property {Block} body
* @see http://php.net/manual/en/language.exceptions.php
*/
module.exports = Statement.extends(
KIND,
function Catch(body, what, variable, docs, location) {
Statement.apply(this, [KIND, docs, location]);
this.body = body;
this.what = what;
this.variable = variable;
}
);
@@ -0,0 +1,36 @@
/**
* Copyright (C) 2018 Glayzzle (BSD3 License)
* @authors https://github.com/glayzzle/php-parser/graphs/contributors
* @url http://glayzzle.com
*/
"use strict";
const Declaration = require("./declaration");
const KIND = "class";
/**
* A class definition
* @constructor Class
* @memberOf module:php-parser
* @extends {Declaration}
* @property {Identifier|null} extends
* @property {Identifier[]|null} implements
* @property {Declaration[]} body
* @property {boolean} isAnonymous
* @property {boolean} isAbstract
* @property {boolean} isFinal
* @property {boolean} isReadonly
* @property {AttrGroup[]} attrGroups
*/
module.exports = Declaration.extends(
KIND,
function Class(name, ext, impl, body, flags, docs, location) {
Declaration.apply(this, [KIND, name, docs, location]);
this.isAnonymous = name ? false : true;
this.extends = ext;
this.implements = impl;
this.body = body;
this.attrGroups = [];
this.parseFlags(flags);
}
);
@@ -0,0 +1,58 @@
/**
* Copyright (C) 2018 Glayzzle (BSD3 License)
* @authors https://github.com/glayzzle/php-parser/graphs/contributors
* @url http://glayzzle.com
*/
"use strict";
const ConstantStatement = require("./constantstatement");
const KIND = "classconstant";
const IS_UNDEFINED = "";
const IS_PUBLIC = "public";
const IS_PROTECTED = "protected";
const IS_PRIVATE = "private";
/**
* Defines a class/interface/trait constant
* @constructor ClassConstant
* @memberOf module:php-parser
* @extends {ConstantStatement}
* @property {string} visibility
* @property {bool} final
* @property {AttrGroup[]} attrGroups
*/
const ClassConstant = ConstantStatement.extends(
KIND,
function ClassConstant(kind, constants, flags, attrGroups, docs, location) {
ConstantStatement.apply(this, [kind || KIND, constants, docs, location]);
this.parseFlags(flags);
this.attrGroups = attrGroups;
}
);
/**
* Generic flags parser
* @function
* @name ClassConstant#parseFlags
* @memberOf module:php-parser
* @param {Array<number|null>} flags
* @return {void}
*/
ClassConstant.prototype.parseFlags = function (flags) {
if (flags[0] === -1) {
this.visibility = IS_UNDEFINED;
} else if (flags[0] === null) {
/* istanbul ignore next */
this.visibility = null;
} else if (flags[0] === 0) {
this.visibility = IS_PUBLIC;
} else if (flags[0] === 1) {
this.visibility = IS_PROTECTED;
} else if (flags[0] === 2) {
this.visibility = IS_PRIVATE;
}
this.final = flags[2] === 2;
};
module.exports = ClassConstant;
@@ -0,0 +1,21 @@
/**
* Copyright (C) 2018 Glayzzle (BSD3 License)
* @authors https://github.com/glayzzle/php-parser/graphs/contributors
* @url http://glayzzle.com
*/
"use strict";
const Expression = require("./expression");
const KIND = "clone";
/**
* Defines a clone call
* @constructor Clone
* @memberOf module:php-parser
* @extends {Expression}
* @property {Expression} what
*/
module.exports = Expression.extends(KIND, function Clone(what, docs, location) {
Expression.apply(this, [KIND, docs, location]);
this.what = what;
});
@@ -0,0 +1,47 @@
/**
* Copyright (C) 2018 Glayzzle (BSD3 License)
* @authors https://github.com/glayzzle/php-parser/graphs/contributors
* @url http://glayzzle.com
*/
"use strict";
const Expression = require("./expression");
const KIND = "closure";
/**
* Defines a closure
* @constructor Closure
* @memberOf module:php-parser
* @extends {Expression}
* @property {Parameter[]} arguments
* @property {Variable[]} uses
* @property {Identifier} type
* @property {Boolean} byref
* @property {boolean} nullable
* @property {Block|null} body
* @property {boolean} isStatic
* @property {AttrGroup[]} attrGroups
*/
module.exports = Expression.extends(
KIND,
function Closure(
args,
byref,
uses,
type,
nullable,
isStatic,
docs,
location
) {
Expression.apply(this, [KIND, docs, location]);
this.uses = uses;
this.arguments = args;
this.byref = byref;
this.type = type;
this.nullable = nullable;
this.isStatic = isStatic || false;
this.body = null;
this.attrGroups = [];
}
);
@@ -0,0 +1,23 @@
/**
* Copyright (C) 2018 Glayzzle (BSD3 License)
* @authors https://github.com/glayzzle/php-parser/graphs/contributors
* @url http://glayzzle.com
*/
"use strict";
const Node = require("./node");
/**
* Abstract documentation node (ComentLine or CommentBlock)
* @constructor Comment
* @memberOf module:php-parser
* @extends {Node}
* @property {String} value
*/
module.exports = Node.extends(
"comment",
function Comment(kind, value, docs, location) {
Node.apply(this, [kind, docs, location]);
this.value = value;
}
);
@@ -0,0 +1,22 @@
/**
* Copyright (C) 2018 Glayzzle (BSD3 License)
* @authors https://github.com/glayzzle/php-parser/graphs/contributors
* @url http://glayzzle.com
*/
"use strict";
const Comment = require("./comment");
const KIND = "commentblock";
/**
* A comment block (multiline)
* @constructor CommentBlock
* @memberOf module:php-parser
* @extends {Comment}
*/
module.exports = Comment.extends(
KIND,
function CommentBlock(value, docs, location) {
Comment.apply(this, [KIND, value, docs, location]);
}
);
@@ -0,0 +1,22 @@
/**
* Copyright (C) 2018 Glayzzle (BSD3 License)
* @authors https://github.com/glayzzle/php-parser/graphs/contributors
* @url http://glayzzle.com
*/
"use strict";
const Comment = require("./comment");
const KIND = "commentline";
/**
* A single line comment
* @constructor CommentLine
* @memberOf module:php-parser
* @extends {Comment}
*/
module.exports = Comment.extends(
KIND,
function CommentLine(value, docs, location) {
Comment.apply(this, [KIND, value, docs, location]);
}
);
@@ -0,0 +1,26 @@
/**
* Copyright (C) 2018 Glayzzle (BSD3 License)
* @authors https://github.com/glayzzle/php-parser/graphs/contributors
* @url http://glayzzle.com
*/
"use strict";
const Node = require("./node");
const KIND = "constant";
/**
* Defines a constant
* @constructor Constant
* @memberOf module:php-parser
* @extends {Node}
* @property {string} name
* @property {Node|string|number|boolean|null} value
*/
module.exports = Node.extends(
KIND,
function Constant(name, value, docs, location) {
Node.apply(this, [KIND, docs, location]);
this.name = name;
this.value = value;
}
);
@@ -0,0 +1,24 @@
/**
* Copyright (C) 2018 Glayzzle (BSD3 License)
* @authors https://github.com/glayzzle/php-parser/graphs/contributors
* @url http://glayzzle.com
*/
"use strict";
const Statement = require("./statement");
const KIND = "constantstatement";
/**
* Declares a constants into the current scope
* @constructor ConstantStatement
* @memberOf module:php-parser
* @extends {Statement}
* @property {Constant[]} constants
*/
module.exports = Statement.extends(
KIND,
function ConstantStatement(kind, constants, docs, location) {
Statement.apply(this, [kind || KIND, docs, location]);
this.constants = constants;
}
);
@@ -0,0 +1,24 @@
/**
* Copyright (C) 2018 Glayzzle (BSD3 License)
* @authors https://github.com/glayzzle/php-parser/graphs/contributors
* @url http://glayzzle.com
*/
"use strict";
const Statement = require("./statement");
const KIND = "continue";
/**
* A continue statement
* @constructor Continue
* @memberOf module:php-parser
* @extends {Statement}
* @property {number|null} level
*/
module.exports = Statement.extends(
KIND,
function Continue(level, docs, location) {
Statement.apply(this, [KIND, docs, location]);
this.level = level;
}
);
@@ -0,0 +1,60 @@
/**
* Copyright (C) 2018 Glayzzle (BSD3 License)
* @authors https://github.com/glayzzle/php-parser/graphs/contributors
* @url http://glayzzle.com
*/
"use strict";
const Statement = require("./statement");
const KIND = "declaration";
const IS_UNDEFINED = "";
const IS_PUBLIC = "public";
const IS_PROTECTED = "protected";
const IS_PRIVATE = "private";
/**
* A declaration statement (function, class, interface...)
* @constructor Declaration
* @memberOf module:php-parser
* @extends {Statement}
* @property {Identifier|string} name
*/
const Declaration = Statement.extends(
KIND,
function Declaration(kind, name, docs, location) {
Statement.apply(this, [kind || KIND, docs, location]);
this.name = name;
}
);
/**
* Generic flags parser
* @function
* @name Declaration#parseFlags
* @memberOf module:php-parser
* @param {Array<number|null>} flags
* @return {void}
*/
Declaration.prototype.parseFlags = function (flags) {
this.isAbstract = flags[2] === 1;
this.isFinal = flags[2] === 2;
this.isReadonly = flags[3] === 1;
if (this.kind !== "class") {
if (flags[0] === -1) {
this.visibility = IS_UNDEFINED;
} else if (flags[0] === null) {
/* istanbul ignore next */
this.visibility = null;
} else if (flags[0] === 0) {
this.visibility = IS_PUBLIC;
} else if (flags[0] === 1) {
this.visibility = IS_PROTECTED;
} else if (flags[0] === 2) {
this.visibility = IS_PRIVATE;
}
this.isStatic = flags[1] === 1;
}
};
module.exports = Declaration;
@@ -0,0 +1,71 @@
/**
* Copyright (C) 2018 Glayzzle (BSD3 License)
* @authors https://github.com/glayzzle/php-parser/graphs/contributors
* @url http://glayzzle.com
*/
"use strict";
const Block = require("./block");
const KIND = "declare";
/**
* The declare construct is used to set execution directives for a block of code
* @constructor Declare
* @memberOf module:php-parser
* @extends {Block}
* @property {DeclareDirective[]} directives
* @property {string} mode
* @see http://php.net/manual/en/control-structures.declare.php
*/
const Declare = Block.extends(
KIND,
function Declare(directives, body, mode, docs, location) {
Block.apply(this, [KIND, body, docs, location]);
this.directives = directives;
this.mode = mode;
}
);
/**
* The node is declared as a short tag syntax :
* ```php
* <?php
* declare(ticks=1):
* // some statements
* enddeclare;
* ```
* @constant {String} Declare#MODE_SHORT
* @memberOf module:php-parser
*/
Declare.MODE_SHORT = "short";
/**
* The node is declared bracket enclosed code :
* ```php
* <?php
* declare(ticks=1) {
* // some statements
* }
* ```
* @constant {String} Declare#MODE_BLOCK
* @memberOf module:php-parser
*/
Declare.MODE_BLOCK = "block";
/**
* The node is declared as a simple statement. In order to make things simpler
* children of the node are automatically collected until the next
* declare statement.
* ```php
* <?php
* declare(ticks=1);
* // some statements
* declare(ticks=2);
* // some statements
* ```
* @constant {String} Declare#MODE_NONE
* @memberOf module:php-parser
*/
Declare.MODE_NONE = "none";
module.exports = Declare;
@@ -0,0 +1,26 @@
/**
* Copyright (C) 2018 Glayzzle (BSD3 License)
* @authors https://github.com/glayzzle/php-parser/graphs/contributors
* @url http://glayzzle.com
*/
"use strict";
const Node = require("./node");
const KIND = "declaredirective";
/**
* Defines a constant
* @constructor DeclareDirective
* @memberOf module:php-parser
* @extends {Node}
* @property {Identifier} key
* @property {Node|string|number|boolean|null} value
*/
module.exports = Node.extends(
KIND,
function DeclareDirective(key, value, docs, location) {
Node.apply(this, [KIND, docs, location]);
this.key = key;
this.value = value;
}
);
+26
View File
@@ -0,0 +1,26 @@
/**
* Copyright (C) 2018 Glayzzle (BSD3 License)
* @authors https://github.com/glayzzle/php-parser/graphs/contributors
* @url http://glayzzle.com
*/
"use strict";
const Statement = require("./statement");
const KIND = "do";
/**
* Defines a do/while statement
* @constructor Do
* @memberOf module:php-parser
* @extends {Statement}
* @property {Expression} test
* @property {Block | null} body
*/
module.exports = Statement.extends(
KIND,
function Do(test, body, docs, location) {
Statement.apply(this, [KIND, docs, location]);
this.test = test;
this.body = body;
}
);
@@ -0,0 +1,26 @@
/**
* Copyright (C) 2018 Glayzzle (BSD3 License)
* @authors https://github.com/glayzzle/php-parser/graphs/contributors
* @url http://glayzzle.com
*/
"use strict";
const Statement = require("./statement");
const KIND = "echo";
/**
* Defines system based call
* @constructor Echo
* @memberOf module:php-parser
* @property {boolean} shortForm
* @property {Expression[]} expressions
* @extends {Statement}
*/
module.exports = Statement.extends(
KIND,
function Echo(expressions, shortForm, docs, location) {
Statement.apply(this, [KIND, docs, location]);
this.shortForm = shortForm;
this.expressions = expressions;
}
);
@@ -0,0 +1,23 @@
/**
* Copyright (C) 2018 Glayzzle (BSD3 License)
* @authors https://github.com/glayzzle/php-parser/graphs/contributors
* @url http://glayzzle.com
*/
"use strict";
const Expression = require("./expression");
const KIND = "empty";
/**
* Defines an empty check call
* @constructor Empty
* @memberOf module:php-parser
* @extends {Expression}
*/
module.exports = Expression.extends(
KIND,
function Empty(expression, docs, location) {
Expression.apply(this, [KIND, docs, location]);
this.expression = expression;
}
);
@@ -0,0 +1,75 @@
/**
* Copyright (C) 2018 Glayzzle (BSD3 License)
* @authors https://github.com/glayzzle/php-parser/graphs/contributors
* @url http://glayzzle.com
*/
"use strict";
const Literal = require("./literal");
const KIND = "encapsed";
/**
* Defines an encapsed string (contains expressions)
* @constructor Encapsed
* @memberOf module:php-parser
* @extends {Literal}
* @property {String} type - Defines the type of encapsed string (shell, heredoc, string)
* @property {String|Null} label - The heredoc label, defined only when the type is heredoc
* @property {EncapsedPart[]} value
*/
const Encapsed = Literal.extends(
KIND,
function Encapsed(value, raw, type, docs, location) {
Literal.apply(this, [KIND, value, raw, docs, location]);
this.type = type;
}
);
/**
* The node is a double quote string :
* ```php
* <?php
* echo "hello $world";
* ```
* @constant {String} Encapsed#TYPE_STRING - `string`
* @memberOf module:php-parser
*/
Encapsed.TYPE_STRING = "string";
/**
* The node is a shell execute string :
* ```php
* <?php
* echo `ls -larth $path`;
* ```
* @constant {String} Encapsed#TYPE_SHELL - `shell`
* @memberOf module:php-parser
*/
Encapsed.TYPE_SHELL = "shell";
/**
* The node is a shell execute string :
* ```php
* <?php
* echo <<<STR
* Hello $world
* STR
* ;
* ```
* @constant {String} Encapsed#TYPE_HEREDOC - `heredoc`
* @memberOf module:php-parser
*/
Encapsed.TYPE_HEREDOC = "heredoc";
/**
* The node contains a list of constref / variables / expr :
* ```php
* <?php
* echo $foo->bar_$baz;
* ```
* @constant {String} Encapsed#TYPE_OFFSET - `offset`
* @memberOf module:php-parser
*/
Encapsed.TYPE_OFFSET = "offset";
module.exports = Encapsed;
@@ -0,0 +1,28 @@
/**
* Copyright (C) 2018 Glayzzle (BSD3 License)
* @authors https://github.com/glayzzle/php-parser/graphs/contributors
* @url http://glayzzle.com
*/
"use strict";
const Expression = require("./expression");
const KIND = "encapsedpart";
/**
* Part of `Encapsed` node
* @constructor EncapsedPart
* @memberOf module:php-parser
* @extends {Expression}
* @property {Expression} expression
* @property {String} syntax
* @property {Boolean} curly
*/
module.exports = Expression.extends(
KIND,
function EncapsedPart(expression, syntax, curly, docs, location) {
Expression.apply(this, [KIND, docs, location]);
this.expression = expression;
this.syntax = syntax;
this.curly = curly;
}
);
@@ -0,0 +1,30 @@
/**
* Copyright (C) 2018 Glayzzle (BSD3 License)
* @authors https://github.com/glayzzle/php-parser/graphs/contributors
* @url http://glayzzle.com
*/
"use strict";
const Expression = require("./expression");
const KIND = "entry";
/**
* An array entry - see [Array](#array)
* @memberOf module:php-parser
* @constructor Entry
* @extends {Expression}
* @property {Node|null} key The entry key/offset
* @property {Node} value The entry value
* @property {Boolean} byRef By reference
* @property {Boolean} unpack Argument unpacking
*/
module.exports = Expression.extends(
KIND,
function Entry(key, value, byRef, unpack, docs, location) {
Expression.apply(this, [KIND, docs, location]);
this.key = key;
this.value = value;
this.byRef = byRef;
this.unpack = unpack;
}
);
@@ -0,0 +1,30 @@
/**
* Copyright (C) 2018 Glayzzle (BSD3 License)
* @authors https://github.com/glayzzle/php-parser/graphs/contributors
* @url http://glayzzle.com
*/
"use strict";
const Declaration = require("./declaration");
const KIND = "enum";
/**
* A enum definition
* @constructor Enum
* @memberOf module:php-parser
* @extends {Declaration}
* @property {Identifier|null} valueType
* @property {Identifier[]} implements
* @property {Declaration[]} body
* @property {AttrGroup[]} attrGroups
*/
module.exports = Declaration.extends(
KIND,
function Enum(name, valueType, impl, body, docs, location) {
Declaration.apply(this, [KIND, name, docs, location]);
this.valueType = valueType;
this.implements = impl;
this.body = body;
this.attrGroups = [];
}
);
@@ -0,0 +1,26 @@
/**
* Copyright (C) 2018 Glayzzle (BSD3 License)
* @authors https://github.com/glayzzle/php-parser/graphs/contributors
* @url http://glayzzle.com
*/
"use strict";
const Node = require("./node");
const KIND = "enumcase";
/**
* Declares a cases into the current scope
* @constructor EnumCase
* @memberOf module:php-parser
* @extends {Node}
* @property {string} name
* @property {string|number|null} value
*/
module.exports = Node.extends(
KIND,
function EnumCase(name, value, docs, location) {
Node.apply(this, [KIND, docs, location]);
this.name = name;
this.value = value;
}
);
@@ -0,0 +1,30 @@
/**
* Copyright (C) 2018 Glayzzle (BSD3 License)
* @authors https://github.com/glayzzle/php-parser/graphs/contributors
* @url http://glayzzle.com
*/
"use strict";
const Node = require("./node");
const KIND = "error";
/**
* Defines an error node (used only on silentMode)
* @constructor Error
* @memberOf module:php-parser
* @extends {Node}
* @property {string} message
* @property {number} line
* @property {number|string} token
* @property {string|array} expected
*/
module.exports = Node.extends(
KIND,
function Error(message, token, line, expected, docs, location) {
Node.apply(this, [KIND, docs, location]);
this.message = message;
this.token = token;
this.line = line;
this.expected = expected;
}
);
@@ -0,0 +1,24 @@
/**
* Copyright (C) 2018 Glayzzle (BSD3 License)
* @authors https://github.com/glayzzle/php-parser/graphs/contributors
* @url http://glayzzle.com
*/
"use strict";
const Expression = require("./expression");
const KIND = "eval";
/**
* Defines an eval statement
* @constructor Eval
* @memberOf module:php-parser
* @extends {Expression}
* @property {Node} source
*/
module.exports = Expression.extends(
KIND,
function Eval(source, docs, location) {
Expression.apply(this, [KIND, docs, location]);
this.source = source;
}
);
@@ -0,0 +1,26 @@
/**
* Copyright (C) 2018 Glayzzle (BSD3 License)
* @authors https://github.com/glayzzle/php-parser/graphs/contributors
* @url http://glayzzle.com
*/
"use strict";
const Expression = require("./expression");
const KIND = "exit";
/**
* Defines an exit / die call
* @constructor Exit
* @memberOf module:php-parser
* @extends {Expression}
* @property {Node|null} expression
* @property {boolean} useDie
*/
module.exports = Expression.extends(
KIND,
function Exit(expression, useDie, docs, location) {
Expression.apply(this, [KIND, docs, location]);
this.expression = expression;
this.useDie = useDie;
}
);
@@ -0,0 +1,20 @@
/**
* Copyright (C) 2018 Glayzzle (BSD3 License)
* @authors https://github.com/glayzzle/php-parser/graphs/contributors
* @url http://glayzzle.com
*/
"use strict";
const Node = require("./node");
const KIND = "expression";
/**
* Any expression node. Since the left-hand side of an assignment may
* be any expression in general, an expression can also be a pattern.
* @constructor Expression
* @memberOf module:php-parser
* @extends {Node}
*/
module.exports = Node.extends(KIND, function Expression(kind, docs, location) {
Node.apply(this, [kind || KIND, docs, location]);
});
@@ -0,0 +1,24 @@
/**
* Copyright (C) 2018 Glayzzle (BSD3 License)
* @authors https://github.com/glayzzle/php-parser/graphs/contributors
* @url http://glayzzle.com
*/
"use strict";
const Statement = require("./statement");
const KIND = "expressionstatement";
/**
* Defines an expression based statement
* @constructor ExpressionStatement
* @memberOf module:php-parser
* @extends {Statement}
* @property {Expression} expression
*/
module.exports = Statement.extends(
KIND,
function ExpressionStatement(expr, docs, location) {
Statement.apply(this, [KIND, docs, location]);
this.expression = expr;
}
);
+33
View File
@@ -0,0 +1,33 @@
/**
* Copyright (C) 2018 Glayzzle (BSD3 License)
* @authors https://github.com/glayzzle/php-parser/graphs/contributors
* @url http://glayzzle.com
*/
"use strict";
const Statement = require("./statement");
const KIND = "for";
/**
* Defines a for iterator
* @constructor For
* @memberOf module:php-parser
* @extends {Statement}
* @property {Expression[]} init
* @property {Expression[]} test
* @property {Expression[]} increment
* @property {Block | null} body
* @property {boolean} shortForm
* @see http://php.net/manual/en/control-structures.for.php
*/
module.exports = Statement.extends(
KIND,
function For(init, test, increment, body, shortForm, docs, location) {
Statement.apply(this, [KIND, docs, location]);
this.init = init;
this.test = test;
this.increment = increment;
this.shortForm = shortForm;
this.body = body;
}
);
@@ -0,0 +1,33 @@
/**
* Copyright (C) 2018 Glayzzle (BSD3 License)
* @authors https://github.com/glayzzle/php-parser/graphs/contributors
* @url http://glayzzle.com
*/
"use strict";
const Statement = require("./statement");
const KIND = "foreach";
/**
* Defines a foreach iterator
* @constructor Foreach
* @memberOf module:php-parser
* @extends {Statement}
* @property {Expression} source
* @property {Expression|null} key
* @property {Expression} value
* @property {Block | null} body
* @property {boolean} shortForm
* @see http://php.net/manual/en/control-structures.foreach.php
*/
module.exports = Statement.extends(
KIND,
function Foreach(source, key, value, body, shortForm, docs, location) {
Statement.apply(this, [KIND, docs, location]);
this.source = source;
this.key = key;
this.value = value;
this.shortForm = shortForm;
this.body = body;
}
);
@@ -0,0 +1,34 @@
/**
* Copyright (C) 2018 Glayzzle (BSD3 License)
* @authors https://github.com/glayzzle/php-parser/graphs/contributors
* @url http://glayzzle.com
*/
"use strict";
const Declaration = require("./declaration");
const KIND = "function";
/**
* Defines a classic function
* @constructor Function
* @memberOf module:php-parser
* @extends {Declaration}
* @property {Parameter[]} arguments
* @property {Identifier} type
* @property {boolean} byref
* @property {boolean} nullable
* @property {Block|null} body
* @property {AttrGroup[]} attrGroups
*/
module.exports = Declaration.extends(
KIND,
function _Function(name, args, byref, type, nullable, docs, location) {
Declaration.apply(this, [KIND, name, docs, location]);
this.arguments = args;
this.byref = byref;
this.type = type;
this.nullable = nullable;
this.body = null;
this.attrGroups = [];
}
);
@@ -0,0 +1,24 @@
/**
* Copyright (C) 2018 Glayzzle (BSD3 License)
* @authors https://github.com/glayzzle/php-parser/graphs/contributors
* @url http://glayzzle.com
*/
"use strict";
const Statement = require("./statement");
const KIND = "global";
/**
* Imports a variable from the global scope
* @constructor Global
* @memberOf module:php-parser
* @extends {Statement}
* @property {Variable[]} items
*/
module.exports = Statement.extends(
KIND,
function Global(items, docs, location) {
Statement.apply(this, [KIND, docs, location]);
this.items = items;
}
);
@@ -0,0 +1,22 @@
/**
* Copyright (C) 2018 Glayzzle (BSD3 License)
* @authors https://github.com/glayzzle/php-parser/graphs/contributors
* @url http://glayzzle.com
*/
"use strict";
const Statement = require("./statement");
const KIND = "goto";
/**
* Defines goto statement
* @constructor Goto
* @memberOf module:php-parser
* @extends {Statement}
* @property {string} label
* @see {Label}
*/
module.exports = Statement.extends(KIND, function Goto(label, docs, location) {
Statement.apply(this, [KIND, docs, location]);
this.label = label;
});
@@ -0,0 +1,22 @@
/**
* Copyright (C) 2018 Glayzzle (BSD3 License)
* @authors https://github.com/glayzzle/php-parser/graphs/contributors
* @url http://glayzzle.com
*/
"use strict";
const Statement = require("./statement");
const KIND = "halt";
/**
* Halts the compiler execution
* @constructor Halt
* @memberOf module:php-parser
* @extends {Statement}
* @property {String} after - String after the halt statement
* @see http://php.net/manual/en/function.halt-compiler.php
*/
module.exports = Statement.extends(KIND, function Halt(after, docs, location) {
Statement.apply(this, [KIND, docs, location]);
this.after = after;
});
@@ -0,0 +1,26 @@
/**
* Copyright (C) 2018 Glayzzle (BSD3 License)
* @authors https://github.com/glayzzle/php-parser/graphs/contributors
* @url http://glayzzle.com
*/
"use strict";
const Node = require("./node");
const KIND = "identifier";
/**
* Defines an identifier node
* @constructor Identifier
* @memberOf module:php-parser
* @extends {Node}
* @property {string} name
*/
const Identifier = Node.extends(
KIND,
function Identifier(name, docs, location) {
Node.apply(this, [KIND, docs, location]);
this.name = name;
}
);
module.exports = Identifier;
+30
View File
@@ -0,0 +1,30 @@
/**
* Copyright (C) 2018 Glayzzle (BSD3 License)
* @authors https://github.com/glayzzle/php-parser/graphs/contributors
* @url http://glayzzle.com
*/
"use strict";
const Statement = require("./statement");
const KIND = "if";
/**
* Defines a if statement
* @constructor If
* @memberOf module:php-parser
* @extends {Statement}
* @property {Expression} test
* @property {Block} body
* @property {Block|If|null} alternate
* @property {boolean} shortForm
*/
module.exports = Statement.extends(
KIND,
function If(test, body, alternate, shortForm, docs, location) {
Statement.apply(this, [KIND, docs, location]);
this.test = test;
this.body = body;
this.alternate = alternate;
this.shortForm = shortForm;
}
);
@@ -0,0 +1,28 @@
/**
* Copyright (C) 2018 Glayzzle (BSD3 License)
* @authors https://github.com/glayzzle/php-parser/graphs/contributors
* @url http://glayzzle.com
*/
"use strict";
const Expression = require("./expression");
const KIND = "include";
/**
* Defines system include call
* @constructor Include
* @memberOf module:php-parser
* @extends {Expression}
* @property {Node} target
* @property {boolean} once
* @property {boolean} require
*/
module.exports = Expression.extends(
KIND,
function Include(once, require, target, docs, location) {
Expression.apply(this, [KIND, docs, location]);
this.once = once;
this.require = require;
this.target = target;
}
);
@@ -0,0 +1,23 @@
/**
* Copyright (C) 2018 Glayzzle (BSD3 License)
* @authors https://github.com/glayzzle/php-parser/graphs/contributors
* @url http://glayzzle.com
*/
"use strict";
const Literal = require("./literal");
const KIND = "inline";
/**
* Defines inline html output (treated as echo output)
* @constructor Inline
* @memberOf module:php-parser
* @extends {Literal}
* @property {string} value
*/
module.exports = Literal.extends(
KIND,
function Inline(value, raw, docs, location) {
Literal.apply(this, [KIND, value, raw, docs, location]);
}
);
@@ -0,0 +1,28 @@
/**
* Copyright (C) 2018 Glayzzle (BSD3 License)
* @authors https://github.com/glayzzle/php-parser/graphs/contributors
* @url http://glayzzle.com
*/
"use strict";
const Declaration = require("./declaration");
const KIND = "interface";
/**
* An interface definition
* @constructor Interface
* @memberOf module:php-parser
* @extends {Declaration}
* @property {Identifier[]} extends
* @property {Declaration[]} body
* @property {AttrGroup[]} attrGroups
*/
module.exports = Declaration.extends(
KIND,
function Interface(name, ext, body, attrGroups, docs, location) {
Declaration.apply(this, [KIND, name, docs, location]);
this.extends = ext;
this.body = body;
this.attrGroups = attrGroups;
}
);
@@ -0,0 +1,24 @@
/**
* Copyright (C) 2018 Glayzzle (BSD3 License)
* @authors https://github.com/glayzzle/php-parser/graphs/contributors
* @url http://glayzzle.com
*/
"use strict";
const Declaration = require("./declaration");
const KIND = "intersectiontype";
/**
* A union of types
* @memberOf module:php-parser
* @constructor IntersectionType
* @extends {Declaration}
* @property {TypeReference[]} types
*/
module.exports = Declaration.extends(
KIND,
function IntersectionType(types, docs, location) {
Declaration.apply(this, [KIND, null, docs, location]);
this.types = types;
}
);
@@ -0,0 +1,23 @@
/**
* Copyright (C) 2018 Glayzzle (BSD3 License)
* @authors https://github.com/glayzzle/php-parser/graphs/contributors
* @url http://glayzzle.com
*/
"use strict";
const Expression = require("./expression");
const KIND = "isset";
/**
* Defines an isset call
* @constructor Isset
* @memberOf module:php-parser
* @extends {Expression}
*/
module.exports = Expression.extends(
KIND,
function Isset(variables, docs, location) {
Expression.apply(this, [KIND, docs, location]);
this.variables = variables;
}
);
@@ -0,0 +1,21 @@
/**
* Copyright (C) 2018 Glayzzle (BSD3 License)
* @authors https://github.com/glayzzle/php-parser/graphs/contributors
* @url http://glayzzle.com
*/
"use strict";
const Statement = require("./statement");
const KIND = "label";
/**
* A label statement (referenced by goto)
* @constructor Label
* @memberOf module:php-parser
* @extends {Statement}
* @property {String} name
*/
module.exports = Statement.extends(KIND, function Label(name, docs, location) {
Statement.apply(this, [KIND, docs, location]);
this.name = name;
});
@@ -0,0 +1,26 @@
/**
* Copyright (C) 2018 Glayzzle (BSD3 License)
* @authors https://github.com/glayzzle/php-parser/graphs/contributors
* @url http://glayzzle.com
*/
"use strict";
const Expression = require("./expression");
const KIND = "list";
/**
* Defines list assignment
* @constructor List
* @memberOf module:php-parser
* @extends {Expression}
* @property {boolean} shortForm
* @property {Entry[]} items
*/
module.exports = Expression.extends(
KIND,
function List(items, shortForm, docs, location) {
Expression.apply(this, [KIND, docs, location]);
this.items = items;
this.shortForm = shortForm;
}
);
@@ -0,0 +1,28 @@
/**
* Copyright (C) 2018 Glayzzle (BSD3 License)
* @authors https://github.com/glayzzle/php-parser/graphs/contributors
* @url http://glayzzle.com
*/
"use strict";
const Expression = require("./expression");
const KIND = "literal";
/**
* Defines an array structure
* @constructor Literal
* @memberOf module:php-parser
* @extends {Expression}
* @property {string} raw
* @property {EncapsedPart[]|Node|string|number|boolean|null} value
*/
module.exports = Expression.extends(
KIND,
function Literal(kind, value, raw, docs, location) {
Expression.apply(this, [kind || KIND, docs, location]);
this.value = value;
if (raw) {
this.raw = raw;
}
}
);
@@ -0,0 +1,22 @@
/**
* Copyright (C) 2018 Glayzzle (BSD3 License)
* @authors https://github.com/glayzzle/php-parser/graphs/contributors
* @url http://glayzzle.com
*/
"use strict";
/**
* Defines the location of the node (with it's source contents as string)
* @constructor Location
* @memberOf module:php-parser
* @property {string|null} source
* @property {Position} start
* @property {Position} end
*/
const Location = function (source, start, end) {
this.source = source;
this.start = start;
this.end = end;
};
module.exports = Location;
@@ -0,0 +1,26 @@
/**
* Copyright (C) 2018 Glayzzle (BSD3 License)
* @authors https://github.com/glayzzle/php-parser/graphs/contributors
* @url http://glayzzle.com
*/
"use strict";
const Expr = require("./expression");
const KIND = "lookup";
/**
* Lookup on an offset in the specified object
* @constructor Lookup
* @memberOf module:php-parser
* @extends {Expression}
* @property {Expression} what
* @property {Expression} offset
*/
module.exports = Expr.extends(
KIND,
function Lookup(kind, what, offset, docs, location) {
Expr.apply(this, [kind || KIND, docs, location]);
this.what = what;
this.offset = offset;
}
);
@@ -0,0 +1,22 @@
/**
* Copyright (C) 2018 Glayzzle (BSD3 License)
* @authors https://github.com/glayzzle/php-parser/graphs/contributors
* @url http://glayzzle.com
*/
"use strict";
const Literal = require("./literal");
const KIND = "magic";
/**
* Defines magic constant
* @constructor Magic
* @memberOf module:php-parser
* @extends {Literal}
*/
module.exports = Literal.extends(
KIND,
function Magic(value, raw, docs, location) {
Literal.apply(this, [KIND, value, raw, docs, location]);
}
);
@@ -0,0 +1,26 @@
/**
* Copyright (C) 2018 Glayzzle (BSD3 License)
* @authors https://github.com/glayzzle/php-parser/graphs/contributors
* @url http://glayzzle.com
*/
"use strict";
const Expression = require("./expression");
const KIND = "match";
/**
* Defines a match expression
* @memberOf module:php-parser
* @constructor Match
* @extends {Expression}
* @property {Expression} cond Condition expression to match against
* @property {MatchArm[]} arms Arms for comparison
*/
module.exports = Expression.extends(
KIND,
function Match(cond, arms, docs, location) {
Expression.apply(this, [KIND, docs, location]);
this.cond = cond;
this.arms = arms;
}
);
@@ -0,0 +1,26 @@
/**
* Copyright (C) 2018 Glayzzle (BSD3 License)
* @authors https://github.com/glayzzle/php-parser/graphs/contributors
* @url http://glayzzle.com
*/
"use strict";
const Expression = require("./expression");
const KIND = "matcharm";
/**
* An array entry - see [Array](#array)
* @memberOf module:php-parser
* @constructor MatchArm
* @extends {Expression}
* @property {Expression[]|null} conds The match condition expression list - null indicates default arm
* @property {Expression} body The return value expression
*/
module.exports = Expression.extends(
KIND,
function MatchArm(conds, body, docs, location) {
Expression.apply(this, [KIND, docs, location]);
this.conds = conds;
this.body = body;
}
);
@@ -0,0 +1,24 @@
/**
* Copyright (C) 2018 Glayzzle (BSD3 License)
* @authors https://github.com/glayzzle/php-parser/graphs/contributors
* @url http://glayzzle.com
*/
"use strict";
const Function_ = require("./function");
const KIND = "method";
/**
* Defines a class/interface/trait method
* @constructor Method
* @memberOf module:php-parser
* @extends {Function}
* @property {boolean} isAbstract
* @property {boolean} isFinal
* @property {boolean} isStatic
* @property {string} visibility
*/
module.exports = Function_.extends(KIND, function Method() {
Function_.apply(this, arguments);
this.kind = KIND;
});
@@ -0,0 +1,55 @@
/**
* Copyright (C) 2018 Glayzzle (BSD3 License)
* @authors https://github.com/glayzzle/php-parser/graphs/contributors
* @url http://glayzzle.com
*/
"use strict";
const Reference = require("./reference");
const KIND = "name";
/**
* Defines a class reference node
* @constructor Name
* @memberOf module:php-parser
* @extends {Reference}
* @property {string} name
* @property {string} resolution
*/
const Name = Reference.extends(
KIND,
function Name(name, resolution, docs, location) {
Reference.apply(this, [KIND, docs, location]);
this.name = name.replace(/\\$/, "");
this.resolution = resolution;
}
);
/**
* This is an identifier without a namespace separator, such as Foo
* @constant {String} Name#UNQUALIFIED_NAME
* @memberOf module:php-parser
*/
Name.UNQUALIFIED_NAME = "uqn";
/**
* This is an identifier with a namespace separator, such as Foo\Bar
* @constant {String} Name#QUALIFIED_NAME
* @memberOf module:php-parser
*/
Name.QUALIFIED_NAME = "qn";
/**
* This is an identifier with a namespace separator that begins with
* a namespace separator, such as \Foo\Bar. The namespace \Foo is also
* a fully qualified name.
* @constant {String} Name#FULL_QUALIFIED_NAME
* @memberOf module:php-parser
*/
Name.FULL_QUALIFIED_NAME = "fqn";
/**
* This is an identifier starting with namespace, such as namespace\Foo\Bar.
* @constant {String} Name#RELATIVE_NAME
* @memberOf module:php-parser
*/
Name.RELATIVE_NAME = "rn";
module.exports = Name;
@@ -0,0 +1,27 @@
/**
* Copyright (C) 2018 Glayzzle (BSD3 License)
* @authors https://github.com/glayzzle/php-parser/graphs/contributors
* @url http://glayzzle.com
*/
"use strict";
const Expression = require("./expression");
const KIND = "namedargument";
/**
* Named arguments.
* @memberOf module:php-parser
* @constructor namedargument
* @extends {Expression}
* @property {String} name
* @property {Expression} value
* @see https://www.php.net/manual/en/functions.arguments.php#functions.named-arguments
*/
module.exports = Expression.extends(
KIND,
function namedargument(name, value, docs, location) {
Expression.apply(this, [KIND, docs, location]);
this.name = name;
this.value = value;
}
);
@@ -0,0 +1,26 @@
/**
* Copyright (C) 2018 Glayzzle (BSD3 License)
* @authors https://github.com/glayzzle/php-parser/graphs/contributors
* @url http://glayzzle.com
*/
"use strict";
const Block = require("./block");
const KIND = "namespace";
/**
* The main program node
* @constructor Namespace
* @memberOf module:php-parser
* @extends {Block}
* @property {string} name
* @property {boolean} withBrackets
*/
module.exports = Block.extends(
KIND,
function Namespace(name, children, withBrackets, docs, location) {
Block.apply(this, [KIND, children, docs, location]);
this.name = name;
this.withBrackets = withBrackets || false;
}
);
+26
View File
@@ -0,0 +1,26 @@
/**
* Copyright (C) 2018 Glayzzle (BSD3 License)
* @authors https://github.com/glayzzle/php-parser/graphs/contributors
* @url http://glayzzle.com
*/
"use strict";
const Expression = require("./expression");
const KIND = "new";
/**
* Creates a new instance of the specified class
* @constructor New
* @memberOf module:php-parser
* @extends {Expression}
* @property {Identifier|Variable|Class} what
* @property {Variable[]} arguments
*/
module.exports = Expression.extends(
KIND,
function New(what, args, docs, location) {
Expression.apply(this, [KIND, docs, location]);
this.what = what;
this.arguments = args;
}
);
+111
View File
@@ -0,0 +1,111 @@
/**
* Copyright (C) 2018 Glayzzle (BSD3 License)
* @authors https://github.com/glayzzle/php-parser/graphs/contributors
* @url http://glayzzle.com
*/
"use strict";
/**
* A generic AST node
* @constructor Node
* @memberOf module:php-parser
* @property {Location|null} loc
* @property {CommentBlock[]|Comment[]|null} leadingComments
* @property {CommentBlock[]|Comment[]|null} trailingComments
* @property {string} kind
*/
const Node = function Node(kind, docs, location) {
this.kind = kind;
if (docs) {
this.leadingComments = docs;
}
if (location) {
this.loc = location;
}
};
/**
* Attach comments to current node
* @function Node#setTrailingComments
* @memberOf module:php-parser
* @param {*} docs
*/
Node.prototype.setTrailingComments = function (docs) {
this.trailingComments = docs;
};
/**
* Destroying an unused node
* @function Node#destroy
* @memberOf module:php-parser
*/
Node.prototype.destroy = function (node) {
if (!node) {
/* istanbul ignore next */
throw new Error(
"Node already initialized, you must swap with another node"
);
}
if (this.leadingComments) {
if (node.leadingComments) {
node.leadingComments = Array.concat(
this.leadingComments,
node.leadingComments
);
} else {
node.leadingComments = this.leadingComments;
}
}
if (this.trailingComments) {
if (node.trailingComments) {
node.trailingComments = Array.concat(
this.trailingComments,
node.trailingComments
);
} else {
node.trailingComments = this.trailingComments;
}
}
return node;
};
/**
* Includes current token position of the parser
* @function Node#includeToken
* @memberOf module:php-parser
* @param {*} parser
*/
Node.prototype.includeToken = function (parser) {
if (this.loc) {
if (this.loc.end) {
this.loc.end.line = parser.lexer.yylloc.last_line;
this.loc.end.column = parser.lexer.yylloc.last_column;
this.loc.end.offset = parser.lexer.offset;
}
if (parser.ast.withSource) {
this.loc.source = parser.lexer._input.substring(
this.loc.start.offset,
parser.lexer.offset
);
}
}
return this;
};
/**
* Helper for extending the Node class
* @function Node.extends
* @memberOf module:php-parser
* @param {string} type
* @param {Function} constructor
* @return {Function}
*/
Node.extends = function (type, constructor) {
constructor.prototype = Object.create(this.prototype);
constructor.extends = this.extends;
constructor.prototype.constructor = constructor;
constructor.kind = type;
return constructor;
};
module.exports = Node;
@@ -0,0 +1,20 @@
/**
* Copyright (C) 2018 Glayzzle (BSD3 License)
* @authors https://github.com/glayzzle/php-parser/graphs/contributors
* @url http://glayzzle.com
*/
"use strict";
const Node = require("./node");
const KIND = "noop";
/**
* Ignore this node, it implies a no operation block, for example :
* [$foo, $bar, /* here a noop node * /]
* @constructor Noop
* @memberOf module:php-parser
* @extends {Node}
*/
module.exports = Node.extends(KIND, function Noop(docs, location) {
Node.apply(this, [KIND, docs, location]);
});
@@ -0,0 +1,26 @@
/**
* Copyright (C) 2018 Glayzzle (BSD3 License)
* @authors https://github.com/glayzzle/php-parser/graphs/contributors
* @url http://glayzzle.com
*/
"use strict";
const Literal = require("./literal");
const KIND = "nowdoc";
/**
* Defines a nowdoc string
* @constructor NowDoc
* @memberOf module:php-parser
* @extends {Literal}
* @property {string} label
* @property {string} raw
* @property {string} value
*/
module.exports = Literal.extends(
KIND,
function Nowdoc(value, raw, label, docs, location) {
Literal.apply(this, [KIND, value, raw, docs, location]);
this.label = label;
}
);
@@ -0,0 +1,20 @@
/**
* Copyright (C) 2018 Glayzzle (BSD3 License)
* @authors https://github.com/glayzzle/php-parser/graphs/contributors
* @url http://glayzzle.com
*/
"use strict";
const Node = require("./node");
const KIND = "nullkeyword";
/**
* Represents the null keyword
* @constructor NullKeyword
* @memberOf module:php-parser
* @extends {Node}
*/
module.exports = Node.extends(KIND, function NullKeyword(raw, docs, location) {
Node.apply(this, [KIND, docs, location]);
this.raw = raw;
});
@@ -0,0 +1,22 @@
/**
* Copyright (C) 2018 Glayzzle (BSD3 License)
* @authors https://github.com/glayzzle/php-parser/graphs/contributors
* @url http://glayzzle.com
*/
"use strict";
const Lookup = require("./lookup");
const KIND = "nullsafepropertylookup";
/**
* Lookup to an object property
* @memberOf module:php-parser
* @constructor NullSafePropertyLookup
* @extends {Lookup}
*/
module.exports = Lookup.extends(
KIND,
function NullSafePropertyLookup(what, offset, docs, location) {
Lookup.apply(this, [KIND, what, offset, docs, location]);
}
);
@@ -0,0 +1,23 @@
/**
* Copyright (C) 2018 Glayzzle (BSD3 License)
* @authors https://github.com/glayzzle/php-parser/graphs/contributors
* @url http://glayzzle.com
*/
"use strict";
const Literal = require("./literal");
const KIND = "number";
/**
* Defines a numeric value
* @constructor Number
* @memberOf module:php-parser
* @extends {Literal}
* @property {number} value
*/
module.exports = Literal.extends(
KIND,
function Number(value, raw, docs, location) {
Literal.apply(this, [KIND, value, raw, docs, location]);
}
);
@@ -0,0 +1,22 @@
/**
* Copyright (C) 2018 Glayzzle (BSD3 License)
* @authors https://github.com/glayzzle/php-parser/graphs/contributors
* @url http://glayzzle.com
*/
"use strict";
const Lookup = require("./lookup");
const KIND = "offsetlookup";
/**
* Lookup on an offset in an array
* @constructor OffsetLookup
* @memberOf module:php-parser
* @extends {Lookup}
*/
module.exports = Lookup.extends(
KIND,
function OffsetLookup(what, offset, docs, location) {
Lookup.apply(this, [KIND, what, offset, docs, location]);
}
);
@@ -0,0 +1,19 @@
/**
* Copyright (C) 2018 Glayzzle (BSD3 License)
* @authors https://github.com/glayzzle/php-parser/graphs/contributors
* @url http://glayzzle.com
*/
"use strict";
const Expr = require("./expression");
const KIND = "operation";
/**
* Defines binary operations
* @constructor Operation
* @memberOf module:php-parser
* @extends {Expression}
*/
module.exports = Expr.extends(KIND, function Operation(kind, docs, location) {
Expr.apply(this, [kind || KIND, docs, location]);
});
@@ -0,0 +1,61 @@
/**
* Copyright (C) 2018 Glayzzle (BSD3 License)
* @authors https://github.com/glayzzle/php-parser/graphs/contributors
* @url http://glayzzle.com
*/
"use strict";
const Declaration = require("./declaration");
const KIND = "parameter";
/**
* @memberOf module:php-parser
* @typedef {1} MODIFIER_PUBLIC
**/
/**
* @memberOf module:php-parser
* @typedef {2} MODIFIER_PROTECTED
**/
/**
* @memberOf module:php-parser
* @typedef {4} MODIFIER_PRIVATE
**/
/**
* Defines a function parameter
* @constructor Parameter
* @memberOf module:php-parser
* @extends {Declaration}
* @property {Identifier|null} type
* @property {Node|null} value
* @property {boolean} byref
* @property {boolean} variadic
* @property {boolean} readonly
* @property {boolean} nullable
* @property {AttrGroup[]} attrGroups
* @property {MODIFIER_PUBLIC|MODIFIER_PROTECTED|MODIFIER_PRIVATE} flags
*/
module.exports = Declaration.extends(
KIND,
function Parameter(
name,
type,
value,
isRef,
isVariadic,
readonly,
nullable,
flags,
docs,
location
) {
Declaration.apply(this, [KIND, name, docs, location]);
this.value = value;
this.type = type;
this.byref = isRef;
this.variadic = isVariadic;
this.readonly = readonly;
this.nullable = nullable;
this.flags = flags || 0;
this.attrGroups = [];
}
);
@@ -0,0 +1,24 @@
/**
* Copyright (C) 2018 Glayzzle (BSD3 License)
* @authors https://github.com/glayzzle/php-parser/graphs/contributors
* @url http://glayzzle.com
*/
"use strict";
const Reference = require("./reference");
const KIND = "parentreference";
/**
* Defines a class reference node
* @constructor ParentReference
* @memberOf module:php-parser
* @extends {Reference}
*/
const ParentReference = Reference.extends(
KIND,
function ParentReference(raw, docs, location) {
Reference.apply(this, [KIND, docs, location]);
this.raw = raw;
}
);
module.exports = ParentReference;
@@ -0,0 +1,22 @@
/**
* Copyright (C) 2018 Glayzzle (BSD3 License)
* @authors https://github.com/glayzzle/php-parser/graphs/contributors
* @url http://glayzzle.com
*/
"use strict";
/**
* Each Position object consists of a line number (1-indexed) and a column number (0-indexed):
* @constructor Position
* @memberOf module:php-parser
* @property {number} line
* @property {number} column
* @property {number} offset
*/
const Position = function (line, column, offset) {
this.line = line;
this.column = column;
this.offset = offset;
};
module.exports = Position;
@@ -0,0 +1,26 @@
/**
* Copyright (C) 2018 Glayzzle (BSD3 License)
* @authors https://github.com/glayzzle/php-parser/graphs/contributors
* @url http://glayzzle.com
*/
"use strict";
const Operation = require("./operation");
const KIND = "post";
/**
* Defines a post operation `$i++` or `$i--`
* @constructor Post
* @memberOf module:php-parser
* @extends {Operation}
* @property {String} type
* @property {Variable} what
*/
module.exports = Operation.extends(
KIND,
function Post(type, what, docs, location) {
Operation.apply(this, [KIND, docs, location]);
this.type = type;
this.what = what;
}
);
+26
View File
@@ -0,0 +1,26 @@
/**
* Copyright (C) 2018 Glayzzle (BSD3 License)
* @authors https://github.com/glayzzle/php-parser/graphs/contributors
* @url http://glayzzle.com
*/
"use strict";
const Operation = require("./operation");
const KIND = "pre";
/**
* Defines a pre operation `++$i` or `--$i`
* @constructor Pre
* @memberOf module:php-parser
* @extends {Operation}
* @property {String} type
* @property {Variable} what
*/
module.exports = Operation.extends(
KIND,
function Pre(type, what, docs, location) {
Operation.apply(this, [KIND, docs, location]);
this.type = type;
this.what = what;
}
);
@@ -0,0 +1,23 @@
/**
* Copyright (C) 2018 Glayzzle (BSD3 License)
* @authors https://github.com/glayzzle/php-parser/graphs/contributors
* @url http://glayzzle.com
*/
"use strict";
const Expression = require("./expression");
const KIND = "print";
/**
* Outputs
* @constructor Print
* @memberOf module:php-parser
* @extends {Expression}
*/
module.exports = Expression.extends(
KIND,
function Print(expression, docs, location) {
Expression.apply(this, [KIND, docs, location]);
this.expression = expression;
}
);
@@ -0,0 +1,32 @@
/**
* Copyright (C) 2018 Glayzzle (BSD3 License)
* @authors https://github.com/glayzzle/php-parser/graphs/contributors
* @url http://glayzzle.com
*/
"use strict";
const Block = require("./block");
const KIND = "program";
/**
* The main program node
* @constructor Program
* @memberOf module:php-parser
* @extends {Block}
* @property {Error[]} errors
* @property {Comment[]|null} comments
* @property {String[]|null} tokens
*/
module.exports = Block.extends(
KIND,
function Program(children, errors, comments, tokens, docs, location) {
Block.apply(this, [KIND, children, docs, location]);
this.errors = errors;
if (comments) {
this.comments = comments;
}
if (tokens) {
this.tokens = tokens;
}
}
);
@@ -0,0 +1,43 @@
/**
* Copyright (C) 2018 Glayzzle (BSD3 License)
* @authors https://github.com/glayzzle/php-parser/graphs/contributors
* @url http://glayzzle.com
*/
"use strict";
const Statement = require("./statement");
const KIND = "property";
/**
* Defines a class property
* @constructor Property
* @memberOf module:php-parser
* @extends {Statement}
* @property {string} name
* @property {Node|null} value
* @property {boolean} readonly
* @property {boolean} nullable
* @property {Identifier|Array<Identifier>|null} type
* @property {AttrGroup[]} attrGroups
*/
module.exports = Statement.extends(
KIND,
function Property(
name,
value,
readonly,
nullable,
type,
attrGroups,
docs,
location
) {
Statement.apply(this, [KIND, docs, location]);
this.name = name;
this.value = value;
this.readonly = readonly;
this.nullable = nullable;
this.type = type;
this.attrGroups = attrGroups;
}
);
@@ -0,0 +1,22 @@
/**
* Copyright (C) 2018 Glayzzle (BSD3 License)
* @authors https://github.com/glayzzle/php-parser/graphs/contributors
* @url http://glayzzle.com
*/
"use strict";
const Lookup = require("./lookup");
const KIND = "propertylookup";
/**
* Lookup to an object property
* @memberOf module:php-parser
* @constructor PropertyLookup
* @extends {Lookup}
*/
module.exports = Lookup.extends(
KIND,
function PropertyLookup(what, offset, docs, location) {
Lookup.apply(this, [KIND, what, offset, docs, location]);
}
);
@@ -0,0 +1,57 @@
/**
* Copyright (C) 2018 Glayzzle (BSD3 License)
* @authors https://github.com/glayzzle/php-parser/graphs/contributors
* @url http://glayzzle.com
*/
"use strict";
const Statement = require("./statement");
const KIND = "propertystatement";
const IS_UNDEFINED = "";
const IS_PUBLIC = "public";
const IS_PROTECTED = "protected";
const IS_PRIVATE = "private";
/**
* Declares a properties into the current scope
* @constructor PropertyStatement
* @memberOf module:php-parser
* @extends {Statement}
* @property {Property[]} properties
* @property {string|null} visibility
* @property {boolean} isStatic
*/
const PropertyStatement = Statement.extends(
KIND,
function PropertyStatement(kind, properties, flags, docs, location) {
Statement.apply(this, [KIND, docs, location]);
this.properties = properties;
this.parseFlags(flags);
}
);
/**
* Generic flags parser
* @function PropertyStatement#parseFlags
* @memberOf module:php-parser
* @param {Array<number|null>} flags
* @return {void}
*/
PropertyStatement.prototype.parseFlags = function (flags) {
if (flags[0] === -1) {
this.visibility = IS_UNDEFINED;
} else if (flags[0] === null) {
this.visibility = null;
} else if (flags[0] === 0) {
this.visibility = IS_PUBLIC;
} else if (flags[0] === 1) {
this.visibility = IS_PROTECTED;
} else if (flags[0] === 2) {
this.visibility = IS_PRIVATE;
}
this.isStatic = flags[1] === 1;
};
module.exports = PropertyStatement;
@@ -0,0 +1,21 @@
/**
* Copyright (C) 2018 Glayzzle (BSD3 License)
* @authors https://github.com/glayzzle/php-parser/graphs/contributors
* @url http://glayzzle.com
*/
"use strict";
const Node = require("./node");
const KIND = "reference";
/**
* Defines a reference node
* @constructor Reference
* @memberOf module:php-parser
* @extends {Node}
*/
const Reference = Node.extends(KIND, function Reference(kind, docs, location) {
Node.apply(this, [kind || KIND, docs, location]);
});
module.exports = Reference;
@@ -0,0 +1,28 @@
/**
* Copyright (C) 2018 Glayzzle (BSD3 License)
* @authors https://github.com/glayzzle/php-parser/graphs/contributors
* @url http://glayzzle.com
*/
"use strict";
const Expression = require("./expression");
const KIND = "retif";
/**
* Defines a short if statement that returns a value
* @constructor RetIf
* @memberOf module:php-parser
* @extends {Expression}
* @property {Expression} test
* @property {Expression} trueExpr
* @property {Expression} falseExpr
*/
module.exports = Expression.extends(
KIND,
function RetIf(test, trueExpr, falseExpr, docs, location) {
Expression.apply(this, [KIND, docs, location]);
this.test = test;
this.trueExpr = trueExpr;
this.falseExpr = falseExpr;
}
);
@@ -0,0 +1,21 @@
/**
* Copyright (C) 2018 Glayzzle (BSD3 License)
* @authors https://github.com/glayzzle/php-parser/graphs/contributors
* @url http://glayzzle.com
*/
"use strict";
const Statement = require("./statement");
const KIND = "return";
/**
* A continue statement
* @constructor Return
* @memberOf module:php-parser
* @extends {Statement}
* @property {Expression|null} expr
*/
module.exports = Statement.extends(KIND, function Return(expr, docs, location) {
Statement.apply(this, [KIND, docs, location]);
this.expr = expr;
});
@@ -0,0 +1,24 @@
/**
* Copyright (C) 2018 Glayzzle (BSD3 License)
* @authors https://github.com/glayzzle/php-parser/graphs/contributors
* @url http://glayzzle.com
*/
"use strict";
const Reference = require("./reference");
const KIND = "selfreference";
/**
* Defines a class reference node
* @constructor SelfReference
* @memberOf module:php-parser
* @extends {Reference}
*/
const SelfReference = Reference.extends(
KIND,
function SelfReference(raw, docs, location) {
Reference.apply(this, [KIND, docs, location]);
this.raw = raw;
}
);
module.exports = SelfReference;
@@ -0,0 +1,24 @@
/**
* Copyright (C) 2018 Glayzzle (BSD3 License)
* @authors https://github.com/glayzzle/php-parser/graphs/contributors
* @url http://glayzzle.com
*/
"use strict";
const Expression = require("./expression");
const KIND = "silent";
/**
* Avoids to show/log warnings & notices from the inner expression
* @constructor Silent
* @memberOf module:php-parser
* @extends {Expression}
* @property {Expression} expr
*/
module.exports = Expression.extends(
KIND,
function Silent(expr, docs, location) {
Expression.apply(this, [KIND, docs, location]);
this.expr = expr;
}
);
@@ -0,0 +1,19 @@
/**
* Copyright (C) 2018 Glayzzle (BSD3 License)
* @authors https://github.com/glayzzle/php-parser/graphs/contributors
* @url http://glayzzle.com
*/
"use strict";
const Node = require("./node");
const KIND = "statement";
/**
* Any statement.
* @constructor Statement
* @memberOf module:php-parser
* @extends {Node}
*/
module.exports = Node.extends(KIND, function Statement(kind, docs, location) {
Node.apply(this, [kind || KIND, docs, location]);
});
@@ -0,0 +1,24 @@
/**
* Copyright (C) 2018 Glayzzle (BSD3 License)
* @authors https://github.com/glayzzle/php-parser/graphs/contributors
* @url http://glayzzle.com
*/
"use strict";
const Statement = require("./statement");
const KIND = "static";
/**
* Declares a static variable into the current scope
* @constructor Static
* @memberOf module:php-parser
* @extends {Statement}
* @property {StaticVariable[]} variables
*/
module.exports = Statement.extends(
KIND,
function Static(variables, docs, location) {
Statement.apply(this, [KIND, docs, location]);
this.variables = variables;
}
);
@@ -0,0 +1,22 @@
/**
* Copyright (C) 2018 Glayzzle (BSD3 License)
* @authors https://github.com/glayzzle/php-parser/graphs/contributors
* @url http://glayzzle.com
*/
"use strict";
const Lookup = require("./lookup");
const KIND = "staticlookup";
/**
* Lookup to a static property
* @constructor StaticLookup
* @memberOf module:php-parser
* @extends {Lookup}
*/
module.exports = Lookup.extends(
KIND,
function StaticLookup(what, offset, docs, location) {
Lookup.apply(this, [KIND, what, offset, docs, location]);
}
);

Some files were not shown because too many files have changed in this diff Show More