Skip to content

Commit b586fef

Browse files
committed
fix
1 parent 08df352 commit b586fef

4 files changed

Lines changed: 51 additions & 31 deletions

File tree

src/parser/class.js

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -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]);

test/snapshot/__snapshots__/acid.test.js.snap

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -841,14 +841,14 @@ Program {
841841
"line": 35,
842842
"offset": 648,
843843
},
844-
"source": "$dwarf = [
844+
"source": "protected $dwarf = [
845845
'sneezy' => 'achoum',
846846
'bashful' => 'tadah'
847847
]",
848848
"start": Position {
849-
"column": 14,
849+
"column": 4,
850850
"line": 32,
851-
"offset": 577,
851+
"offset": 567,
852852
},
853853
},
854854
"properties": [

test/snapshot/__snapshots__/location.test.js.snap

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3838,11 +3838,11 @@ Program {
38383838
"line": 1,
38393839
"offset": 32,
38403840
},
3841-
"source": "const BAR = 1",
3841+
"source": "public const BAR = 1",
38423842
"start": Position {
3843-
"column": 19,
3843+
"column": 12,
38443844
"line": 1,
3845-
"offset": 19,
3845+
"offset": 12,
38463846
},
38473847
},
38483848
"nullable": false,
@@ -4149,11 +4149,11 @@ Program {
41494149
"line": 1,
41504150
"offset": 44,
41514151
},
4152-
"source": "const FOO = 1",
4152+
"source": "#[Deprecated] public const FOO = 1",
41534153
"start": Position {
4154-
"column": 31,
4154+
"column": 10,
41554155
"line": 1,
4156-
"offset": 31,
4156+
"offset": 10,
41574157
},
41584158
},
41594159
"nullable": false,
@@ -4171,11 +4171,11 @@ Program {
41714171
"line": 1,
41724172
"offset": 61,
41734173
},
4174-
"source": "$bar = 2",
4174+
"source": "public $bar = 2",
41754175
"start": Position {
4176-
"column": 53,
4176+
"column": 46,
41774177
"line": 1,
4178-
"offset": 53,
4178+
"offset": 46,
41794179
},
41804180
},
41814181
"properties": [
@@ -12017,11 +12017,11 @@ Program {
1201712017
"line": 1,
1201812018
"offset": 36,
1201912019
},
12020-
"source": "$foo = 1",
12020+
"source": "#[Pure] protected $foo = 1",
1202112021
"start": Position {
12022-
"column": 28,
12022+
"column": 10,
1202312023
"line": 1,
12024-
"offset": 28,
12024+
"offset": 10,
1202512025
},
1202612026
},
1202712027
"properties": [
@@ -12131,11 +12131,11 @@ Program {
1213112131
"line": 1,
1213212132
"offset": 53,
1213312133
},
12134-
"source": "$bar = 2",
12134+
"source": "public $bar = 2",
1213512135
"start": Position {
12136-
"column": 45,
12136+
"column": 38,
1213712137
"line": 1,
12138-
"offset": 45,
12138+
"offset": 38,
1213912139
},
1214012140
},
1214112141
"properties": [

test/snapshot/__snapshots__/namespace.test.js.snap

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -271,9 +271,9 @@ Program {
271271
},
272272
"source": null,
273273
"start": Position {
274-
"column": 15,
274+
"column": 8,
275275
"line": 10,
276-
"offset": 184,
276+
"offset": 177,
277277
},
278278
},
279279
"properties": [
@@ -811,9 +811,9 @@ Program {
811811
},
812812
"source": null,
813813
"start": Position {
814-
"column": 15,
814+
"column": 8,
815815
"line": 10,
816-
"offset": 184,
816+
"offset": 177,
817817
},
818818
},
819819
"properties": [

0 commit comments

Comments
 (0)