Skip to content

fix: location #213

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 29, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions src/parser/class.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,15 @@ module.exports = {
* class ::= class_scope? T_CLASS T_STRING (T_EXTENDS NAMESPACE_NAME)? (T_IMPLEMENTS (NAMESPACE_NAME ',')* NAMESPACE_NAME)? '{' CLASS_BODY '}'
* ```
*/
read_class: function(flag) {
read_class: function() {
const result = this.node("class");
this.expect(this.tok.T_CLASS);
const flag = this.read_class_scope();
// graceful mode : ignore token & go next
if (this.token !== this.tok.T_CLASS) {
this.error(this.tok.T_CLASS);
this.next();
return null;
}
this.next().expect(this.tok.T_STRING);
const propName = this.text();
let propExtends = null;
Expand Down
31 changes: 6 additions & 25 deletions src/parser/statement.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,18 +42,9 @@ module.exports = {
return this.read_function(false, false);
// optional flags
case this.tok.T_ABSTRACT:
case this.tok.T_FINAL: {
const flag = this.read_class_scope();
if (this.token === this.tok.T_CLASS) {
return this.read_class(flag);
} else {
this.error(this.tok.T_CLASS);
this.next();
return null;
}
}
case this.tok.T_FINAL:
case this.tok.T_CLASS:
return this.read_class([0, 0, 0]);
return this.read_class();
case this.tok.T_INTERFACE:
return this.read_interface();
case this.tok.T_TRAIT:
Expand Down Expand Up @@ -155,19 +146,9 @@ module.exports = {
return this.read_function(false, false);
// optional flags
case this.tok.T_ABSTRACT:
case this.tok.T_FINAL: {
const flag = this.read_class_scope();
if (this.token === this.tok.T_CLASS) {
return this.read_class(flag);
} else {
this.error(this.tok.T_CLASS);
// graceful mode : ignore token & go next
this.next();
return null;
}
}
case this.tok.T_FINAL:
case this.tok.T_CLASS:
return this.read_class([0, 0, 0]);
return this.read_class();
case this.tok.T_INTERFACE:
return this.read_interface();
case this.tok.T_TRAIT:
Expand Down Expand Up @@ -355,13 +336,13 @@ module.exports = {
return null;

case this.tok.T_STRING:
let result = this.node();
current = [this.token, this.lexer.getState()];
label = this.text();
// AST : https://github.com/php/php-src/blob/master/Zend/zend_language_parser.y#L457
if (this.next().token === ":") {
result = this.node("label");
this.next();
return result(label);
return result("label", label);
}

// default fallback expr / T_STRING '::' (etc...)
Expand Down
12 changes: 6 additions & 6 deletions test/snapshot/__snapshots__/acid.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -1360,7 +1360,7 @@ Program {
"line": 47,
"offset": 938,
},
"source": "class fooBar implements namespace\\\\fooBaz {
"source": "abstract class fooBar implements namespace\\\\fooBaz {
use Line;
use foo, bar {
foo::baz insteadof bar;
Expand All @@ -1384,9 +1384,9 @@ Program {
}
}",
"start": Position {
"column": 11,
"column": 2,
"line": 25,
"offset": 399,
"offset": 390,
},
},
"name": "fooBar",
Expand Down Expand Up @@ -2776,11 +2776,11 @@ Program {
"line": 83,
"offset": 1665,
},
"source": ":",
"source": "next:",
"start": Position {
"column": 4,
"column": 0,
"line": 83,
"offset": 1664,
"offset": 1660,
},
},
"name": "next",
Expand Down
Loading