1
- /*! php-parser - BSD3 License - 2018-03-26 */
1
+ /*! php-parser - BSD3 License - 2018-03-27 */
2
2
3
3
require = ( function e ( t , n , r ) { function s ( o , u ) { if ( ! n [ o ] ) { if ( ! t [ o ] ) { var a = typeof require == "function" && require ; if ( ! u && a ) return a ( o , ! 0 ) ; if ( i ) return i ( o , ! 0 ) ; var f = new Error ( "Cannot find module '" + o + "'" ) ; throw f . code = "MODULE_NOT_FOUND" , f } var l = n [ o ] = { exports :{ } } ; t [ o ] [ 0 ] . call ( l . exports , function ( e ) { var n = t [ o ] [ 1 ] [ e ] ; return s ( n ?n :e ) } , l , l . exports , e , t , n , r ) } return n [ o ] . exports } var i = typeof require == "function" && require ; for ( var o = 0 ; o < r . length ; o ++ ) s ( r [ o ] ) ; return s } ) ( { 1 :[ function ( require , module , exports ) {
4
4
/*!
@@ -438,10 +438,10 @@ AST.prototype.prepare = function (kind, docs, parser) {
438
438
if ( self . withPositions || self . withSource ) {
439
439
var src = null ;
440
440
if ( self . withSource ) {
441
- src = parser . lexer . _input . substring ( start . offset , parser . lexer . yylloc . prev_offset ) ;
441
+ src = parser . lexer . _input . substring ( start . offset , parser . prev [ 2 ] ) ;
442
442
}
443
443
if ( self . withPositions ) {
444
- location = new Location ( src , start , new Position ( parser . lexer . yylloc . prev_line , parser . lexer . yylloc . prev_column , parser . lexer . yylloc . prev_offset ) ) ;
444
+ location = new Location ( src , start , new Position ( parser . prev [ 0 ] , parser . prev [ 1 ] , parser . prev [ 2 ] ) ) ;
445
445
} else {
446
446
location = new Location ( src , null , null ) ;
447
447
}
@@ -2321,7 +2321,7 @@ var KIND = "program";
2321
2321
* @property {Doc[]? } comments
2322
2322
* @property {String[]? } tokens
2323
2323
*/
2324
- var Program = Block . extends ( function Program ( children , errors , comments , docs , tokens , location ) {
2324
+ var Program = Block . extends ( function Program ( children , errors , comments , tokens , docs , location ) {
2325
2325
Block . apply ( this , [ KIND , children , docs , location ] ) ;
2326
2326
this . errors = errors ;
2327
2327
if ( comments ) {
@@ -4767,7 +4767,7 @@ parser.prototype.parse = function (code, filename) {
4767
4767
}
4768
4768
}
4769
4769
}
4770
- return program ( childs , this . _errors , this . _docs , null , this . _tokens ) ;
4770
+ return program ( childs , this . _errors , this . _docs , this . _tokens ) ;
4771
4771
} ;
4772
4772
4773
4773
/**
@@ -4902,6 +4902,9 @@ parser.prototype.text = function () {
4902
4902
4903
4903
/** consume the next token **/
4904
4904
parser . prototype . next = function ( ) {
4905
+ // prepare the back command
4906
+ this . prev = [ this . lexer . yylloc . last_line , this . lexer . yylloc . last_column , this . lexer . offset ] ;
4907
+
4905
4908
// eating the token
4906
4909
this . lex ( ) ;
4907
4910
@@ -4929,9 +4932,6 @@ parser.prototype.next = function () {
4929
4932
* Eating a token
4930
4933
*/
4931
4934
parser . prototype . lex = function ( ) {
4932
- // prepare the back command
4933
- this . prev = [ this . lexer . yylloc . first_line , this . lexer . yylloc . first_column , this . lexer . offset ] ;
4934
-
4935
4935
// append on token stack
4936
4936
if ( this . extractTokens ) {
4937
4937
do {
@@ -4947,16 +4947,15 @@ parser.prototype.lex = function () {
4947
4947
this . _tokens . push ( entry ) ;
4948
4948
if ( this . token === this . tok . T_CLOSE_TAG ) {
4949
4949
// https://github.com/php/php-src/blob/7ff186434e82ee7be7c59d0db9a976641cf7b09c/Zend/zend_compile.c#L1680
4950
- this . token = ';' ;
4950
+ this . token = ";" ;
4951
4951
return this ;
4952
4952
} else if ( this . token === this . tok . T_OPEN_TAG_WITH_ECHO ) {
4953
4953
this . token = this . tok . T_ECHO ;
4954
4954
return this ;
4955
4955
}
4956
4956
} while ( this . token === this . tok . T_WHITESPACE || // ignore white space
4957
4957
! this . extractDoc && ( this . token === this . tok . T_COMMENT || // ignore single lines comments
4958
- this . token === this . tok . T_DOC_COMMENT // ignore doc comments
4959
- ) ||
4958
+ this . token === this . tok . T_DOC_COMMENT ) || // ignore doc comments
4960
4959
// ignore open tags
4961
4960
this . token === this . tok . T_OPEN_TAG ) ;
4962
4961
} else {
@@ -5535,17 +5534,26 @@ module.exports = {
5535
5534
read_comment : function read_comment ( ) {
5536
5535
var text = this . text ( ) ;
5537
5536
var result = this . ast . prepare ( text . substring ( 0 , 2 ) === "/*" ? "commentblock" : "commentline" , null , this ) ;
5537
+ // handle location on comment
5538
+ var prev = this . prev ;
5539
+ this . prev = [ this . lexer . yylloc . last_line , this . lexer . yylloc . last_column , this . lexer . offset ] ;
5538
5540
this . lex ( ) ;
5539
- return result ( text ) ;
5541
+ result = result ( text ) ;
5542
+ this . prev = prev ;
5543
+ return result ;
5540
5544
} ,
5541
5545
/**
5542
5546
* Comments with / ** ... * /
5543
5547
*/
5544
5548
read_doc_comment : function read_doc_comment ( ) {
5545
5549
var result = this . ast . prepare ( "commentblock" , null , this ) ;
5546
5550
var text = this . text ( ) ;
5551
+ var prev = this . prev ;
5552
+ this . prev = [ this . lexer . yylloc . last_line , this . lexer . yylloc . last_column , this . lexer . offset ] ;
5547
5553
this . lex ( ) ;
5548
- return result ( text ) ;
5554
+ result = result ( text ) ;
5555
+ this . prev = prev ;
5556
+ return result ;
5549
5557
}
5550
5558
} ;
5551
5559
@@ -6307,7 +6315,7 @@ module.exports = {
6307
6315
var alternate = null ;
6308
6316
var shortForm = false ;
6309
6317
var test = null ;
6310
- test = this . read_if_expr ( ) ;
6318
+ test = this . next ( ) . read_if_expr ( ) ;
6311
6319
6312
6320
if ( this . token === ":" ) {
6313
6321
shortForm = true ;
@@ -6316,10 +6324,10 @@ module.exports = {
6316
6324
var items = [ ] ;
6317
6325
while ( this . token !== this . EOF && this . token !== this . tok . T_ENDIF ) {
6318
6326
if ( this . token === this . tok . T_ELSEIF ) {
6319
- alternate = this . next ( ) . read_elseif_short ( ) ;
6327
+ alternate = this . read_elseif_short ( ) ;
6320
6328
break ;
6321
6329
} else if ( this . token === this . tok . T_ELSE ) {
6322
- alternate = this . next ( ) . read_else_short ( ) ;
6330
+ alternate = this . read_else_short ( ) ;
6323
6331
break ;
6324
6332
}
6325
6333
items . push ( this . read_inner_statement ( ) ) ;
@@ -6330,7 +6338,7 @@ module.exports = {
6330
6338
} else {
6331
6339
body = this . read_statement ( ) ;
6332
6340
if ( this . token === this . tok . T_ELSEIF ) {
6333
- alternate = this . next ( ) . read_if ( ) ;
6341
+ alternate = this . read_if ( ) ;
6334
6342
} else if ( this . token === this . tok . T_ELSE ) {
6335
6343
alternate = this . next ( ) . read_statement ( ) ;
6336
6344
}
@@ -6355,15 +6363,15 @@ module.exports = {
6355
6363
var test = null ;
6356
6364
var body = null ;
6357
6365
var items = [ ] ;
6358
- test = this . read_if_expr ( ) ;
6366
+ test = this . next ( ) . read_if_expr ( ) ;
6359
6367
if ( this . expect ( ":" ) ) this . next ( ) ;
6360
6368
body = this . node ( "block" ) ;
6361
6369
while ( this . token != this . EOF && this . token !== this . tok . T_ENDIF ) {
6362
6370
if ( this . token === this . tok . T_ELSEIF ) {
6363
- alternate = this . next ( ) . read_elseif_short ( ) ;
6371
+ alternate = this . read_elseif_short ( ) ;
6364
6372
break ;
6365
6373
} else if ( this . token === this . tok . T_ELSE ) {
6366
- alternate = this . next ( ) . read_else_short ( ) ;
6374
+ alternate = this . read_else_short ( ) ;
6367
6375
break ;
6368
6376
}
6369
6377
items . push ( this . read_inner_statement ( ) ) ;
@@ -6375,8 +6383,8 @@ module.exports = {
6375
6383
*
6376
6384
*/
6377
6385
read_else_short : function read_else_short ( ) {
6378
- if ( this . expect ( ":" ) ) this . next ( ) ;
6379
6386
var body = this . node ( "block" ) ;
6387
+ if ( this . next ( ) . expect ( ":" ) ) this . next ( ) ;
6380
6388
var items = [ ] ;
6381
6389
while ( this . token != this . EOF && this . token !== this . tok . T_ENDIF ) {
6382
6390
items . push ( this . read_inner_statement ( ) ) ;
@@ -7224,7 +7232,7 @@ module.exports = {
7224
7232
return this . read_code_block ( false ) ;
7225
7233
7226
7234
case this . tok . T_IF :
7227
- return this . next ( ) . read_if ( ) ;
7235
+ return this . read_if ( ) ;
7228
7236
7229
7237
case this . tok . T_SWITCH :
7230
7238
return this . read_switch ( ) ;
0 commit comments