Skip to content
This repository was archived by the owner on Mar 29, 2023. It is now read-only.

Commit d93b707

Browse files
authored
Merge pull request glayzzle#213 from glayzzle/fix-location
fix: location
2 parents c2dc021 + e87e8ca commit d93b707

File tree

5 files changed

+2011
-129
lines changed

5 files changed

+2011
-129
lines changed

src/parser/class.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,15 @@ module.exports = {
1212
* class ::= class_scope? T_CLASS T_STRING (T_EXTENDS NAMESPACE_NAME)? (T_IMPLEMENTS (NAMESPACE_NAME ',')* NAMESPACE_NAME)? '{' CLASS_BODY '}'
1313
* ```
1414
*/
15-
read_class: function(flag) {
15+
read_class: function() {
1616
const result = this.node("class");
17-
this.expect(this.tok.T_CLASS);
17+
const flag = this.read_class_scope();
18+
// graceful mode : ignore token & go next
19+
if (this.token !== this.tok.T_CLASS) {
20+
this.error(this.tok.T_CLASS);
21+
this.next();
22+
return null;
23+
}
1824
this.next().expect(this.tok.T_STRING);
1925
const propName = this.text();
2026
let propExtends = null;

src/parser/statement.js

Lines changed: 6 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -42,18 +42,9 @@ module.exports = {
4242
return this.read_function(false, false);
4343
// optional flags
4444
case this.tok.T_ABSTRACT:
45-
case this.tok.T_FINAL: {
46-
const flag = this.read_class_scope();
47-
if (this.token === this.tok.T_CLASS) {
48-
return this.read_class(flag);
49-
} else {
50-
this.error(this.tok.T_CLASS);
51-
this.next();
52-
return null;
53-
}
54-
}
45+
case this.tok.T_FINAL:
5546
case this.tok.T_CLASS:
56-
return this.read_class([0, 0, 0]);
47+
return this.read_class();
5748
case this.tok.T_INTERFACE:
5849
return this.read_interface();
5950
case this.tok.T_TRAIT:
@@ -155,19 +146,9 @@ module.exports = {
155146
return this.read_function(false, false);
156147
// optional flags
157148
case this.tok.T_ABSTRACT:
158-
case this.tok.T_FINAL: {
159-
const flag = this.read_class_scope();
160-
if (this.token === this.tok.T_CLASS) {
161-
return this.read_class(flag);
162-
} else {
163-
this.error(this.tok.T_CLASS);
164-
// graceful mode : ignore token & go next
165-
this.next();
166-
return null;
167-
}
168-
}
149+
case this.tok.T_FINAL:
169150
case this.tok.T_CLASS:
170-
return this.read_class([0, 0, 0]);
151+
return this.read_class();
171152
case this.tok.T_INTERFACE:
172153
return this.read_interface();
173154
case this.tok.T_TRAIT:
@@ -355,13 +336,13 @@ module.exports = {
355336
return null;
356337

357338
case this.tok.T_STRING:
339+
let result = this.node();
358340
current = [this.token, this.lexer.getState()];
359341
label = this.text();
360342
// AST : https://github.com/php/php-src/blob/master/Zend/zend_language_parser.y#L457
361343
if (this.next().token === ":") {
362-
result = this.node("label");
363344
this.next();
364-
return result(label);
345+
return result("label", label);
365346
}
366347

367348
// default fallback expr / T_STRING '::' (etc...)

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1360,7 +1360,7 @@ Program {
13601360
"line": 47,
13611361
"offset": 938,
13621362
},
1363-
"source": "class fooBar implements namespace\\\\fooBaz {
1363+
"source": "abstract class fooBar implements namespace\\\\fooBaz {
13641364
use Line;
13651365
use foo, bar {
13661366
foo::baz insteadof bar;
@@ -1384,9 +1384,9 @@ Program {
13841384
}
13851385
}",
13861386
"start": Position {
1387-
"column": 11,
1387+
"column": 2,
13881388
"line": 25,
1389-
"offset": 399,
1389+
"offset": 390,
13901390
},
13911391
},
13921392
"name": "fooBar",
@@ -2776,11 +2776,11 @@ Program {
27762776
"line": 83,
27772777
"offset": 1665,
27782778
},
2779-
"source": ":",
2779+
"source": "next:",
27802780
"start": Position {
2781-
"column": 4,
2781+
"column": 0,
27822782
"line": 83,
2783-
"offset": 1664,
2783+
"offset": 1660,
27842784
},
27852785
},
27862786
"name": "next",

0 commit comments

Comments
 (0)