Skip to content

Commit

Permalink
Merge pull request #262 from glayzzle/feat-better-ast-for-parameter-node
Browse files Browse the repository at this point in the history
feat: better ast for parameter node
  • Loading branch information
ichiriac committed Feb 16, 2019
2 parents 78c8204 + 09710fc commit bf62e78
Show file tree
Hide file tree
Showing 12 changed files with 356 additions and 81 deletions.
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 @@ -2163,7 +2163,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 @@ -4068,7 +4084,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 @@ -715,7 +715,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 @@ -802,7 +805,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
60 changes: 48 additions & 12 deletions test/snapshot/__snapshots__/function.test.js.snap
Expand Up @@ -8,7 +8,10 @@ Program {
Parameter {
"byref": false,
"kind": "parameter",
"name": "a",
"name": Identifier {
"kind": "identifier",
"name": "a",
},
"nullable": false,
"type": TypeReference {
"kind": "typereference",
Expand All @@ -24,7 +27,10 @@ Program {
Parameter {
"byref": false,
"kind": "parameter",
"name": "b",
"name": Identifier {
"kind": "identifier",
"name": "b",
},
"nullable": false,
"type": TypeReference {
"kind": "typereference",
Expand All @@ -40,7 +46,10 @@ Program {
Parameter {
"byref": false,
"kind": "parameter",
"name": "c",
"name": Identifier {
"kind": "identifier",
"name": "c",
},
"nullable": false,
"type": TypeReference {
"kind": "typereference",
Expand All @@ -56,7 +65,10 @@ Program {
Parameter {
"byref": false,
"kind": "parameter",
"name": "d",
"name": Identifier {
"kind": "identifier",
"name": "d",
},
"nullable": false,
"type": TypeReference {
"kind": "typereference",
Expand All @@ -69,7 +81,10 @@ Program {
Parameter {
"byref": false,
"kind": "parameter",
"name": "e",
"name": Identifier {
"kind": "identifier",
"name": "e",
},
"nullable": false,
"type": TypeReference {
"kind": "typereference",
Expand All @@ -82,7 +97,10 @@ Program {
Parameter {
"byref": false,
"kind": "parameter",
"name": "f",
"name": Identifier {
"kind": "identifier",
"name": "f",
},
"nullable": false,
"type": ClassReference {
"kind": "classreference",
Expand All @@ -95,7 +113,10 @@ Program {
Parameter {
"byref": true,
"kind": "parameter",
"name": "params",
"name": Identifier {
"kind": "identifier",
"name": "params",
},
"nullable": true,
"type": TypeReference {
"kind": "typereference",
Expand Down Expand Up @@ -144,7 +165,10 @@ Program {
"value": "/* f */",
},
],
"name": "a",
"name": Identifier {
"kind": "identifier",
"name": "a",
},
"nullable": false,
"type": null,
"value": null,
Expand Down Expand Up @@ -185,7 +209,10 @@ Program {
Parameter {
"byref": false,
"kind": "parameter",
"name": "a",
"name": Identifier {
"kind": "identifier",
"name": "a",
},
"nullable": false,
"type": null,
"value": Number {
Expand All @@ -197,7 +224,10 @@ Program {
Parameter {
"byref": false,
"kind": "parameter",
"name": "b",
"name": Identifier {
"kind": "identifier",
"name": "b",
},
"nullable": false,
"type": TypeReference {
"kind": "typereference",
Expand All @@ -210,7 +240,10 @@ Program {
Parameter {
"byref": true,
"kind": "parameter",
"name": "params",
"name": Identifier {
"kind": "identifier",
"name": "params",
},
"nullable": true,
"type": TypeReference {
"kind": "typereference",
Expand Down Expand Up @@ -253,7 +286,10 @@ Program {
Parameter {
"byref": false,
"kind": "parameter",
"name": "b",
"name": Identifier {
"kind": "identifier",
"name": "b",
},
"nullable": false,
"type": null,
"value": null,
Expand Down

0 comments on commit bf62e78

Please sign in to comment.