File tree 4 files changed +51
-0
lines changed
4 files changed +51
-0
lines changed Original file line number Diff line number Diff line change 43
43
- [ Statement] ( #statement )
44
44
- [ Eval] ( #eval )
45
45
- [ Exit] ( #exit )
46
+ - [ Halt] ( #halt )
46
47
- [ Clone] ( #clone )
47
48
- [ Declare] ( #declare )
48
49
- [ Global] ( #global )
@@ -597,6 +598,16 @@ Defines goto statement
597
598
598
599
- ` label ` ** [ String] ( #string ) **
599
600
601
+ # Halt
602
+
603
+ ** Extends Statement**
604
+
605
+ Halts the compiler execution
606
+
607
+ ** Properties**
608
+
609
+ - ` after ` ** [ String] ( #string ) ** String after the halt statement
610
+
600
611
# Identifier
601
612
602
613
** Extends Node**
Original file line number Diff line number Diff line change @@ -49,6 +49,7 @@ var Position = require('./ast/position');
49
49
* - [Statement](#statement)
50
50
* - [Eval](#eval)
51
51
* - [Exit](#exit)
52
+ * - [Halt](#halt)
52
53
* - [Clone](#clone)
53
54
* - [Declare](#declare)
54
55
* - [Global](#global)
@@ -207,6 +208,7 @@ AST.prototype.prepare = function(kind, parser) {
207
208
require ( './ast/function' ) ,
208
209
require ( './ast/global' ) ,
209
210
require ( './ast/goto' ) ,
211
+ require ( './ast/halt' ) ,
210
212
require ( './ast/identifier' ) ,
211
213
require ( './ast/if' ) ,
212
214
require ( './ast/include' ) ,
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
+
8
+ var Statement = require ( './statement' ) ;
9
+ var KIND = 'halt' ;
10
+
11
+ /**
12
+ * Halts the compiler execution
13
+ * @constructor Halt
14
+ * @extends {Statement }
15
+ * @property {String } after - String after the halt statement
16
+ * @see http://php.net/manual/en/function.halt-compiler.php
17
+ */
18
+ var Halt = Statement . extends ( function Halt ( after , location ) {
19
+ Statement . apply ( this , [ KIND , location ] ) ;
20
+ this . after = after ;
21
+ } ) ;
22
+
23
+ module . exports = Halt ;
Original file line number Diff line number Diff line change @@ -16,6 +16,7 @@ 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
+
19
20
it ( 'test global' , function ( ) {
20
21
var ast = parser . parseEval ( [
21
22
'function foo() {' ,
@@ -32,6 +33,20 @@ describe('Test statements', function() {
32
33
expr . items [ 1 ] . name . should . be . exactly ( 'b' ) ;
33
34
} ) ;
34
35
36
+ it ( 'test halt statement' , function ( ) {
37
+ var ast = parser . parseEval ( [
38
+ '$a = 1;' ,
39
+ '__halt_compiler();' ,
40
+ '$b = 1;'
41
+ ] . join ( '\n' ) , {
42
+ parser : { debug : false }
43
+ } ) ;
44
+ ast . children . length . should . be . exactly ( 2 ) ;
45
+ ast . children [ 0 ] . kind . should . be . exactly ( 'assign' ) ;
46
+ ast . children [ 1 ] . kind . should . be . exactly ( 'halt' ) ;
47
+ ast . children [ 1 ] . after . should . be . exactly ( '\n$b = 1;' ) ;
48
+ } ) ;
49
+
35
50
it ( 'test static' , function ( ) {
36
51
var ast = parser . parseEval ( [
37
52
'function foo() {' ,
You can’t perform that action at this time.
0 commit comments