ConsenSysMesh / solidity-parser

Solidity Parser in Javascript
137 stars 53 forks source link

Missing "type" field in "PropertyAssignment" Node definition #10

Closed duaraghav8 closed 8 years ago

duaraghav8 commented 8 years ago

take below code:

sendObject ({
    name: "foo bar",
    age: 20
});

The AST for this is (you don't need to see the JSON, its just for reference):

{
  "type": "Program",
  "body": [
    {
      "type": "ExpressionStatement",
      "expression": {
        "type": "CallExpression",
        "callee": {
          "type": "Identifier",
          "name": "sendObject",
          "start": 0,
          "end": 10
        },
        "arguments": [
          {
            "type": "ObjectExpression",
            "properties": [
              {
                "key": {
                  "type": "Identifier",
                  "name": "name",
                  "start": 13,
                  "end": 17
                },
                "value": {
                  "type": "Literal",
                  "value": "foo bar",
                  "start": 19,
                  "end": 28
                },
                "kind": "init",
                "start": 13,
                "end": 28
              },
              {
                "key": {
                  "type": "Identifier",
                  "name": "age",
                  "start": 29,
                  "end": 32
                },
                "value": {
                  "type": "Literal",
                  "value": 20,
                  "start": 34,
                  "end": 36
                },
                "kind": "init",
                "start": 29,
                "end": 36
              }
            ],
            "start": 12,
            "end": 37
          }
        ],
        "start": 0,
        "end": 38
      },
      "start": 0,
      "end": 38
    }
  ],
  "start": 0,
  "end": 38
}

Specifically, I'd like to point out the elements of properties array of ObjectExpression node. The node corresponding to name: "foo bar" is:

{
                "key": {
                  "type": "Identifier",
                  "name": "name",
                  "start": 13,
                  "end": 17
                },
                "value": {
                  "type": "Literal",
                  "value": "foo bar",
                  "start": 19,
                  "end": 28
                },
                "kind": "init",
                "start": 13,
                "end": 28
              }

This node has fields key, value, kind, start, end, but doesn't have any type field (which is necessary for Spider Monkey complaint AST Nodes.

I've already fixed this on my local module with type: "Property".

When its decided what type's value to give to PropertyAssignment nodes, let me know and I'll make a PR.

raineorshine commented 8 years ago

I will second the use of type: "Property" since that is what is used in esprima.

tcoulter commented 8 years ago

Looks good to me. I defer to you guys on what the best value for type is here. :+1: Thanks @duaraghav8