Skip to content

Commit

Permalink
Merge a88fcad into 6e63a00
Browse files Browse the repository at this point in the history
  • Loading branch information
evilebottnawi committed Aug 27, 2019
2 parents 6e63a00 + a88fcad commit f5f2f92
Show file tree
Hide file tree
Showing 10 changed files with 328 additions and 21 deletions.
9 changes: 3 additions & 6 deletions src/ast.js
Expand Up @@ -323,18 +323,15 @@ AST.prototype.resolvePrecedence = function(result, parser) {
result = buffer;
}
}
} else if (
result.kind === "silent" &&
!result.expr.parenthesizedExpression
) {
if (result.expr.kind === 'assign') return result;
} else if (result.kind === "silent" && !result.expr.parenthesizedExpression) {
if (result.expr.kind === "assign") return result;
// overall least precedence
if (result.expr.right) {
buffer = result.expr;
result.expr = buffer.left;
buffer.left = result;
this.swapLocations(buffer, buffer.left, buffer.right, parser);
result = buffer;
result = buffer;
}
}
return result;
Expand Down
17 changes: 11 additions & 6 deletions src/parser/statement.js
Expand Up @@ -353,11 +353,13 @@ module.exports = {
case this.tok.T_STRING: {
const result = this.node();
const current = [this.token, this.lexer.getState()];
const label = this.text();
const labelNameText = this.text();
// AST : https://github.com/php/php-src/blob/master/Zend/zend_language_parser.y#L457
if (this.next().token === ":") {
let labelName = this.node("identifier");
this.next();
return result("label", label);
labelName = labelName(labelNameText);
return result("label", labelName);
}

// default fallback expr / T_STRING '::' (etc...)
Expand All @@ -371,12 +373,15 @@ module.exports = {

case this.tok.T_GOTO: {
const result = this.node("goto");
let label = null;
let labelName = null;
if (this.next().expect(this.tok.T_STRING)) {
label = this.text();
this.next().expectEndOfStatement();
labelName = this.node("identifier");
const name = this.text();
this.next();
labelName = labelName(name);
this.expectEndOfStatement();
}
return result(label);
return result(labelName);
}

default: {
Expand Down
36 changes: 34 additions & 2 deletions test/snapshot/__snapshots__/acid.test.js.snap
Expand Up @@ -3118,7 +3118,23 @@ Program {
"offset": 1660,
},
},
"name": "next",
"name": Identifier {
"kind": "identifier",
"loc": Location {
"end": Position {
"column": 5,
"line": 83,
"offset": 1665,
},
"source": ":",
"start": Position {
"column": 4,
"line": 83,
"offset": 1664,
},
},
"name": "next",
},
},
ExpressionStatement {
"expression": Assign {
Expand Down Expand Up @@ -3663,7 +3679,23 @@ Program {
"alternate": null,
"body": Goto {
"kind": "goto",
"label": "next",
"label": Identifier {
"kind": "identifier",
"loc": Location {
"end": Position {
"column": 49,
"line": 90,
"offset": 1847,
},
"source": "next",
"start": Position {
"column": 45,
"line": 90,
"offset": 1843,
},
},
"name": "next",
},
"loc": Location {
"end": Position {
"column": 50,
Expand Down
34 changes: 33 additions & 1 deletion test/snapshot/__snapshots__/goto.test.js.snap
Expand Up @@ -5,7 +5,39 @@ Program {
"children": Array [
Goto {
"kind": "goto",
"label": "a",
"label": Identifier {
"kind": "identifier",
"name": "a",
},
},
Echo {
"expressions": Array [
String {
"isDoubleQuote": true,
"kind": "string",
"raw": "\\"Foo\\"",
"unicode": false,
"value": "Foo",
},
],
"kind": "echo",
"shortForm": false,
},
],
"errors": Array [],
"kind": "program",
}
`;

exports[`goto simple 2`] = `
Program {
"children": Array [
Goto {
"kind": "goto",
"label": Identifier {
"kind": "identifier",
"name": "longName",
},
},
Echo {
"expressions": Array [
Expand Down
34 changes: 33 additions & 1 deletion test/snapshot/__snapshots__/label.test.js.snap
Expand Up @@ -5,7 +5,39 @@ Program {
"children": Array [
Label {
"kind": "label",
"name": "a",
"name": Identifier {
"kind": "identifier",
"name": "a",
},
},
Echo {
"expressions": Array [
String {
"isDoubleQuote": true,
"kind": "string",
"raw": "\\"Foo\\"",
"unicode": false,
"value": "Foo",
},
],
"kind": "echo",
"shortForm": false,
},
],
"errors": Array [],
"kind": "program",
}
`;

exports[`label simple 2`] = `
Program {
"children": Array [
Label {
"kind": "label",
"name": Identifier {
"kind": "identifier",
"name": "longName",
},
},
Echo {
"expressions": Array [
Expand Down

0 comments on commit f5f2f92

Please sign in to comment.