File tree 5 files changed +52
-1
lines changed
5 files changed +52
-1
lines changed Original file line number Diff line number Diff line change 43
43
- [ Eval] ( #eval )
44
44
- [ Exit] ( #exit )
45
45
- [ Clone] ( #clone )
46
+ - [ Global] ( #global )
46
47
- [ Include] ( #include )
47
48
- [ Assign] ( #assign )
48
49
- [ RetIf] ( #retif )
@@ -511,6 +512,16 @@ Defines a classic function
511
512
- ` nullable ` ** [ boolean] ( https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean ) **
512
513
- ` body ` ** ([ Block] ( #block ) | null)**
513
514
515
+ # Global
516
+
517
+ ** Extends Statement**
518
+
519
+ Imports a variable from the global scope
520
+
521
+ ** Properties**
522
+
523
+ - ` items ` ** [ Array] ( #array ) < ; [ Variable] ( #variable ) >**
524
+
514
525
# Goto
515
526
516
527
** Extends Statement**
Original file line number Diff line number Diff line change @@ -49,6 +49,7 @@ var Position = require('./ast/position');
49
49
* - [Eval](#eval)
50
50
* - [Exit](#exit)
51
51
* - [Clone](#clone)
52
+ * - [Global](#global)
52
53
* - [Include](#include)
53
54
* - [Assign](#assign)
54
55
* - [RetIf](#retif)
@@ -199,6 +200,7 @@ AST.prototype.prepare = function(kind, parser) {
199
200
require ( './ast/for' ) ,
200
201
require ( './ast/foreach' ) ,
201
202
require ( './ast/function' ) ,
203
+ require ( './ast/global' ) ,
202
204
require ( './ast/goto' ) ,
203
205
require ( './ast/identifier' ) ,
204
206
require ( './ast/if' ) ,
Original file line number Diff line number Diff line change
1
+ /*!
2
+ * Copyright (C) 2017 Glayzzle (BSD3 License)
3
+ * @authors https://github.com/glayzzle/php-parser/graphs/contributors
4
+ * @url http://glayzzle.com
5
+ */
6
+ "use strict" ;
7
+ var Statement = require ( './statement' ) ;
8
+ var KIND = 'global' ;
9
+
10
+ /**
11
+ * Imports a variable from the global scope
12
+ * @constructor Global
13
+ * @extends {Statement }
14
+ * @property {Variable[] } items
15
+ */
16
+ var Global = Statement . extends ( function Global ( items , location ) {
17
+ Statement . apply ( this , [ KIND , location ] ) ;
18
+ this . items = items ;
19
+ } ) ;
20
+
21
+ module . exports = Global ;
Original file line number Diff line number Diff line change @@ -213,9 +213,10 @@ module.exports = {
213
213
return result ( ) ;
214
214
215
215
case this . tok . T_GLOBAL :
216
+ var result = this . node ( 'global' ) ;
216
217
var items = this . next ( ) . read_list ( this . read_simple_variable , ',' ) ;
217
218
this . expectEndOfStatement ( ) ;
218
- return [ 'global' , items ] ;
219
+ return result ( items ) ;
219
220
220
221
case this . tok . T_STATIC :
221
222
var current = [ this . token , this . lexer . getState ( ) ] ;
Original file line number Diff line number Diff line change @@ -16,6 +16,22 @@ describe('Test statements', function() {
16
16
ast . children [ 2 ] . kind . should . be . exactly ( 'goto' ) ;
17
17
ast . children [ 2 ] . label . should . be . exactly ( 'start' ) ;
18
18
} ) ;
19
+ it ( 'test global' , function ( ) {
20
+ var ast = parser . parseEval ( [
21
+ 'function foo() {' ,
22
+ ' global $a, $b;' ,
23
+ '}'
24
+ ] . join ( '\n' ) , {
25
+ parser : { debug : false }
26
+ } ) ;
27
+ var expr = ast . children [ 0 ] . body . children [ 0 ] ;
28
+ expr . kind . should . be . exactly ( 'global' ) ;
29
+ expr . items [ 0 ] . kind . should . be . exactly ( 'variable' ) ;
30
+ expr . items [ 0 ] . name . should . be . exactly ( 'a' ) ;
31
+ expr . items [ 1 ] . kind . should . be . exactly ( 'variable' ) ;
32
+ expr . items [ 1 ] . name . should . be . exactly ( 'b' ) ;
33
+ } ) ;
34
+
19
35
it ( 'test try' , function ( ) {
20
36
var ast = parser . parseEval ( [
21
37
'try {' ,
You can’t perform that action at this time.
0 commit comments