Skip to content
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

feat: better ast for parameter node #262

Merged
merged 1 commit into from Feb 16, 2019
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 6 additions & 2 deletions src/ast.js
Expand Up @@ -296,8 +296,12 @@ AST.prototype.resolvePrecedence = function(result, parser) {
result = buffer;
}
}
} else if (result.kind === "silent" && result.expr.right && !result.expr.parenthesizedExpression) {
// overall least precedence
} else if (
result.kind === "silent" &&
result.expr.right &&
!result.expr.parenthesizedExpression
) {
// overall least precedence
buffer = result.expr;
result.expr = buffer.left;
buffer.left = result;
Expand Down
8 changes: 5 additions & 3 deletions src/parser/function.js
Expand Up @@ -168,7 +168,7 @@ module.exports = {
*/
read_parameter: function() {
const node = this.node("parameter");
let name = null;
let parameterName = null;
let value = null;
let type = null;
let nullable = false;
Expand All @@ -185,13 +185,15 @@ module.exports = {
const isRef = this.is_reference();
const isVariadic = this.is_variadic();
if (this.expect(this.tok.T_VARIABLE)) {
name = this.text().substring(1);
parameterName = this.node("identifier");
const name = this.text().substring(1);
this.next();
parameterName = parameterName(name);
}
if (this.token == "=") {
value = this.next().read_expr();
}
return node(name, type, value, isRef, isVariadic, nullable);
return node(parameterName, type, value, isRef, isVariadic, nullable);
},
/**
* Reads a list of arguments
Expand Down
36 changes: 34 additions & 2 deletions test/snapshot/__snapshots__/acid.test.js.snap
Expand Up @@ -2016,7 +2016,23 @@ Program {
"offset": 1234,
},
},
"name": "arrow",
"name": Identifier {
"kind": "identifier",
"loc": Location {
"end": Position {
"column": 36,
"line": 61,
"offset": 1245,
},
"source": "$arrow",
"start": Position {
"column": 30,
"line": 61,
"offset": 1239,
},
},
"name": "arrow",
},
"nullable": false,
"type": TypeReference {
"kind": "typereference",
Expand Down Expand Up @@ -3921,7 +3937,23 @@ next:
"offset": 1893,
},
},
"name": "bar",
"name": Identifier {
"kind": "identifier",
"loc": Location {
"end": Position {
"column": 27,
"line": 95,
"offset": 1902,
},
"source": "$bar",
"start": Position {
"column": 23,
"line": 95,
"offset": 1898,
},
},
"name": "bar",
},
"nullable": true,
"type": TypeReference {
"kind": "typereference",
Expand Down
10 changes: 8 additions & 2 deletions test/snapshot/__snapshots__/class.test.js.snap
Expand Up @@ -685,7 +685,10 @@ Program {
Parameter {
"byref": false,
"kind": "parameter",
"name": "data",
"name": Identifier {
"kind": "identifier",
"name": "data",
},
"nullable": false,
"type": TypeReference {
"kind": "typereference",
Expand Down Expand Up @@ -769,7 +772,10 @@ Program {
Parameter {
"byref": false,
"kind": "parameter",
"name": "foo",
"name": Identifier {
"kind": "identifier",
"name": "foo",
},
"nullable": false,
"type": null,
"value": StaticLookup {
Expand Down
10 changes: 8 additions & 2 deletions test/snapshot/__snapshots__/classreference.test.js.snap
Expand Up @@ -8,7 +8,10 @@ Program {
Parameter {
"byref": false,
"kind": "parameter",
"name": "arg",
"name": Identifier {
"kind": "identifier",
"name": "arg",
},
"nullable": false,
"type": ClassReference {
"kind": "classreference",
Expand Down Expand Up @@ -46,7 +49,10 @@ Program {
Parameter {
"byref": false,
"kind": "parameter",
"name": "arg",
"name": Identifier {
"kind": "identifier",
"name": "arg",
},
"nullable": false,
"type": ClassReference {
"kind": "classreference",
Expand Down
45 changes: 36 additions & 9 deletions test/snapshot/__snapshots__/closure.test.js.snap
Expand Up @@ -18,7 +18,10 @@ Program {
Parameter {
"byref": false,
"kind": "parameter",
"name": "arg",
"name": Identifier {
"kind": "identifier",
"name": "arg",
},
"nullable": false,
"type": null,
"value": null,
Expand Down Expand Up @@ -77,7 +80,10 @@ Program {
Parameter {
"byref": false,
"kind": "parameter",
"name": "arg",
"name": Identifier {
"kind": "identifier",
"name": "arg",
},
"nullable": false,
"type": null,
"value": null,
Expand Down Expand Up @@ -143,7 +149,10 @@ Program {
Parameter {
"byref": true,
"kind": "parameter",
"name": "arg",
"name": Identifier {
"kind": "identifier",
"name": "arg",
},
"nullable": false,
"type": null,
"value": null,
Expand Down Expand Up @@ -202,7 +211,10 @@ Program {
Parameter {
"byref": false,
"kind": "parameter",
"name": "arg",
"name": Identifier {
"kind": "identifier",
"name": "arg",
},
"nullable": false,
"type": null,
"value": null,
Expand All @@ -211,7 +223,10 @@ Program {
Parameter {
"byref": false,
"kind": "parameter",
"name": "arg",
"name": Identifier {
"kind": "identifier",
"name": "arg",
},
"nullable": false,
"type": null,
"value": null,
Expand All @@ -220,7 +235,10 @@ Program {
Parameter {
"byref": false,
"kind": "parameter",
"name": "arg",
"name": Identifier {
"kind": "identifier",
"name": "arg",
},
"nullable": false,
"type": null,
"value": null,
Expand Down Expand Up @@ -279,7 +297,10 @@ Program {
Parameter {
"byref": false,
"kind": "parameter",
"name": "arg",
"name": Identifier {
"kind": "identifier",
"name": "arg",
},
"nullable": false,
"type": null,
"value": null,
Expand All @@ -288,7 +309,10 @@ Program {
Parameter {
"byref": false,
"kind": "parameter",
"name": "arg",
"name": Identifier {
"kind": "identifier",
"name": "arg",
},
"nullable": false,
"type": null,
"value": null,
Expand All @@ -297,7 +321,10 @@ Program {
Parameter {
"byref": false,
"kind": "parameter",
"name": "arg",
"name": Identifier {
"kind": "identifier",
"name": "arg",
},
"nullable": false,
"type": null,
"value": null,
Expand Down
5 changes: 4 additions & 1 deletion test/snapshot/__snapshots__/comment.test.js.snap
Expand Up @@ -841,7 +841,10 @@ Program {
"value": "/* @var something */",
},
],
"name": "arg",
"name": Identifier {
"kind": "identifier",
"name": "arg",
},
"nullable": false,
"type": null,
"value": null,
Expand Down