Skip to content

Commit

Permalink
Merge fabdd6f into 2c2e63d
Browse files Browse the repository at this point in the history
  • Loading branch information
evilebottnawi committed Jan 7, 2019
2 parents 2c2e63d + fabdd6f commit e5a36fe
Show file tree
Hide file tree
Showing 10 changed files with 413 additions and 65 deletions.
3 changes: 2 additions & 1 deletion src/ast.js
Expand Up @@ -14,7 +14,7 @@ const Position = require("./ast/position");
* - [Location](#location)
* - [Position](#position)
* - [Node](#node)
* - [DeclareDirective](#declaredirective)
* - [StaticVariable](#staticvariable)
* - [EncapsedPart](#encapsedpart)
* - [Constant](#constant)
* - [Identifier](#identifier)
Expand Down Expand Up @@ -472,6 +472,7 @@ AST.prototype.prepare = function(kind, docs, parser) {
require("./ast/silent"),
require("./ast/statement"),
require("./ast/static"),
require("./ast/staticvariable"),
require("./ast/staticlookup"),
require("./ast/staticreference"),
require("./ast/string"),
Expand Down
6 changes: 3 additions & 3 deletions src/ast/static.js
Expand Up @@ -12,13 +12,13 @@ const KIND = "static";
* Declares a static variable into the current scope
* @constructor Static
* @extends {Statement}
* @property {Variable[]|Assign[]} items
* @property {StaticVariable[]} variables
*/
module.exports = Statement.extends(KIND, function Static(
items,
variables,
docs,
location
) {
Statement.apply(this, [KIND, docs, location]);
this.items = items;
this.variables = variables;
});
27 changes: 27 additions & 0 deletions src/ast/staticvariable.js
@@ -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 Node = require("./node");
const KIND = "staticvariable";

/**
* Defines a constant
* @constructor StaticVariable
* @extends {Node}
* @property {Variable} variable
* @property {Node|string|number|boolean|null} defaultValue
*/
module.exports = Node.extends(KIND, function StaticVariable(
variable,
defaultValue,
docs,
location
) {
Node.apply(this, [KIND, docs, location]);
this.variable = variable;
this.defaultValue = defaultValue;
});
6 changes: 3 additions & 3 deletions src/parser/utils.js
Expand Up @@ -89,14 +89,14 @@ module.exports = {
*
* Sample code :
* ```php
* <?php class foo extends bar, baz { }
* <?php static $a = 'hello', $b = 'world';
* ```
* @return {Variable[]|Assign[]} Returns an array composed by a list of variables, or
* @return {StaticVariable[]} Returns an array composed by a list of variables, or
* assign values
*/
read_variable_declarations: function() {
return this.read_list(function() {
const node = this.node("assign");
const node = this.node("staticvariable");
let variable = this.node("variable");
// plain variable name
if (this.expect(this.tok.T_VARIABLE)) {
Expand Down
30 changes: 15 additions & 15 deletions test/snapshot/__snapshots__/acid.test.js.snap
Expand Up @@ -3975,7 +3975,21 @@ next:
"body": Block {
"children": Array [
Static {
"items": Array [
"kind": "static",
"loc": Location {
"end": Position {
"column": 19,
"line": 96,
"offset": 1953,
},
"source": "static $banana;",
"start": Position {
"column": 4,
"line": 96,
"offset": 1938,
},
},
"variables": Array [
Variable {
"byref": false,
"curly": false,
Expand All @@ -3996,20 +4010,6 @@ next:
"name": "banana",
},
],
"kind": "static",
"loc": Location {
"end": Position {
"column": 19,
"line": 96,
"offset": 1953,
},
"source": "static $banana;",
"start": Position {
"column": 4,
"line": 96,
"offset": 1938,
},
},
},
If {
"alternate": If {
Expand Down

0 comments on commit e5a36fe

Please sign in to comment.