File tree 2 files changed +39
-4
lines changed
2 files changed +39
-4
lines changed Original file line number Diff line number Diff line change @@ -166,10 +166,18 @@ module.exports = {
166
166
case this . tok . T_TRAIT :
167
167
return this . read_trait ( ) ;
168
168
case this . tok . T_HALT_COMPILER :
169
- if ( this . next ( ) . expect ( '(' ) ) this . next ( ) ;
170
- if ( this . expect ( ')' ) ) this . next ( ) ;
171
- if ( this . expect ( ';' ) ) this . next ( ) ;
172
- this . raiseError ( '__HALT_COMPILER() can only be used from the outermost scope' ) ;
169
+ this . raiseError (
170
+ '__HALT_COMPILER() can only be used from the outermost scope'
171
+ ) ;
172
+ // fallback : returns a node but does not stop the parsing
173
+ var node = this . node ( 'halt' ) ;
174
+ this . next ( ) . expect ( '(' ) && this . next ( ) ;
175
+ this . expect ( ')' ) && this . next ( ) ;
176
+ node = node ( this . lexer . _input . substring (
177
+ this . lexer . offset
178
+ ) ) ;
179
+ this . expect ( ';' ) && this . next ( ) ;
180
+ return node ;
173
181
default :
174
182
return this . read_statement ( ) ;
175
183
}
Original file line number Diff line number Diff line change @@ -45,6 +45,33 @@ describe('Test statements', function() {
45
45
ast . children [ 0 ] . kind . should . be . exactly ( 'assign' ) ;
46
46
ast . children [ 1 ] . kind . should . be . exactly ( 'halt' ) ;
47
47
ast . children [ 1 ] . after . should . be . exactly ( '\n$b = 1;' ) ;
48
+
49
+ // test the inner error
50
+ ( function ( ) {
51
+ var ast = parser . parseEval ( [
52
+ 'if (true) {' ,
53
+ ' __halt_compiler();' ,
54
+ '}'
55
+ ] . join ( '\n' ) ) ;
56
+ } ) . should . throw ( / l i n e \s 2 / ) ;
57
+
58
+ // test the fallback
59
+ ast = parser . parseEval ( [
60
+ 'if (true) {' ,
61
+ ' __halt_compiler();' ,
62
+ '}' ,
63
+ '$b = 1;'
64
+ ] . join ( '\n' ) , {
65
+ parser : { suppressErrors : true }
66
+ } ) ;
67
+
68
+ ast . children . length . should . be . exactly ( 2 ) ;
69
+ ast . errors . length . should . be . exactly ( 1 ) ;
70
+ ast . children [ 0 ] . kind . should . be . exactly ( 'if' ) ;
71
+ ast . children [ 0 ] . body . children [ 0 ] . kind . should . be . exactly ( 'halt' ) ;
72
+ ast . children [ 0 ] . body . children [ 0 ] . after . should . be . exactly ( '\n}\n$b = 1;' ) ;
73
+ ast . children [ 1 ] . kind . should . be . exactly ( 'assign' ) ;
74
+
48
75
} ) ;
49
76
50
77
it ( 'test static' , function ( ) {
You can’t perform that action at this time.
0 commit comments