@@ -103,18 +103,18 @@ module.exports = {
103103 continue ;
104104 }
105105
106+ const locStart = this . position ( ) ;
107+
106108 if ( this . token === this . tok . T_ATTRIBUTE ) {
107109 attrs = this . read_attr_list ( ) ;
108110 }
109111
110- const locStart = this . position ( ) ;
111-
112112 // read member flags
113113 const flags = this . read_member_flags ( false ) ;
114114
115115 // check constant
116116 if ( this . token === this . tok . T_CONST ) {
117- const constants = this . read_constant_list ( flags , attrs ) ;
117+ const constants = this . read_constant_list ( flags , attrs , locStart ) ;
118118 if ( this . expect ( ";" ) ) {
119119 this . next ( ) ;
120120 }
@@ -150,7 +150,7 @@ module.exports = {
150150 this . token === this . tok . T_STRING ) ) )
151151 ) {
152152 // reads a variable
153- const variables = this . read_variable_list ( flags , attrs ) ;
153+ const variables = this . read_variable_list ( flags , attrs , locStart ) ;
154154 attrs = [ ] ;
155155 result = result . concat ( variables ) ;
156156 } else {
@@ -175,7 +175,7 @@ module.exports = {
175175 * variable_list ::= (variable_declaration ',')* variable_declaration
176176 * ```
177177 */
178- read_variable_list ( flags , attrs ) {
178+ read_variable_list ( flags , attrs , locStart ) {
179179 let property_statement = this . node ( "propertystatement" ) ;
180180
181181 const properties = this . read_list (
@@ -232,6 +232,16 @@ module.exports = {
232232 ) ;
233233
234234 property_statement = property_statement ( null , properties , flags ) ;
235+ if ( locStart && property_statement . loc ) {
236+ property_statement . loc . start = locStart ;
237+ if ( property_statement . loc . source ) {
238+ property_statement . loc . source = this . lexer . _input . substr (
239+ property_statement . loc . start . offset ,
240+ property_statement . loc . end . offset -
241+ property_statement . loc . start . offset ,
242+ ) ;
243+ }
244+ }
235245
236246 // semicolons are found only for regular properties definitions.
237247 // Property hooks are terminated by a closing curly brace, }.
@@ -334,7 +344,7 @@ module.exports = {
334344 * constant_list ::= T_CONST [type] (constant_declaration ',')* constant_declaration
335345 * ```
336346 */
337- read_constant_list ( flags , attrs ) {
347+ read_constant_list ( flags , attrs , locStart ) {
338348 const result = this . node ( "classconstant" ) ;
339349 if ( this . expect ( this . tok . T_CONST ) ) {
340350 this . next ( ) ;
@@ -378,7 +388,17 @@ module.exports = {
378388 "," ,
379389 ) ;
380390
381- return result ( null , items , flags , nullable , type , attrs || [ ] ) ;
391+ const node = result ( null , items , flags , nullable , type , attrs || [ ] ) ;
392+ if ( locStart && node . loc ) {
393+ node . loc . start = locStart ;
394+ if ( node . loc . source ) {
395+ node . loc . source = this . lexer . _input . substr (
396+ node . loc . start . offset ,
397+ node . loc . end . offset - node . loc . start . offset ,
398+ ) ;
399+ }
400+ }
401+ return node ;
382402 } ,
383403 /*
384404 * Read member flags
@@ -573,7 +593,7 @@ module.exports = {
573593
574594 // check constant
575595 if ( this . token === this . tok . T_CONST ) {
576- const constants = this . read_constant_list ( flags , attrs ) ;
596+ const constants = this . read_constant_list ( flags , attrs , locStart ) ;
577597 if ( this . expect ( ";" ) ) {
578598 this . next ( ) ;
579599 }
@@ -592,7 +612,7 @@ module.exports = {
592612 this . next ( ) ;
593613 }
594614 } else if ( this . token === this . tok . T_STRING ) {
595- result . push ( this . read_variable_list ( flags , attrs ) ) ;
615+ result . push ( this . read_variable_list ( flags , attrs , locStart ) ) ;
596616 } else {
597617 // raise an error
598618 this . error ( [ this . tok . T_CONST , this . tok . T_FUNCTION , this . tok . T_STRING ] ) ;
0 commit comments