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

PrefixExpression incorrect range/location #47

Closed
trixnz opened this issue Mar 18, 2017 · 2 comments
Closed

PrefixExpression incorrect range/location #47

trixnz opened this issue Mar 18, 2017 · 2 comments
Labels
incorrect parsing Valid Lua code fails to parse, is parsed incorrectly, or invalid Lua code is accepted

Comments

@trixnz
Copy link

trixnz commented Mar 18, 2017

parsePrefixExpression seems to be incorrectly handling the propagation of child ranges and locations, as demonstrated with the following Lua snippet:

base['outer']['inner']()

Expected behaviour

The outer IndexExpression's range should contain the inner expression without the CallExpression's parenthesis and the inner expression should only contain its own range.

Output

{
  "type": "Chunk",
  "body": [
    {
      "type": "CallStatement",
      "expression": {
        "type": "CallExpression",
        "base": {
          "type": "IndexExpression",
          "base": {
            "type": "IndexExpression",
            "base": {
              "type": "Identifier",
              "name": "base",
              "range": [
                0,
                4
              ]
            },
            "index": {
              "type": "StringLiteral",
              "value": "outer",
              "raw": "'outer'",
              "range": [
                5,
                12
              ]
            },
            "range": [
              13,
              22
            ]
          },
          "index": {
            "type": "StringLiteral",
            "value": "inner",
            "raw": "'inner'",
            "range": [
              14,
              21
            ]
          },
          "range": [
            0,
            22
          ]
        },
        "arguments": [],
        "range": [
          0,
          24
        ]
      },
      "range": [
        0,
        24
      ]
    }
  ],
  "range": [
    0,
    24
  ],
  "comments": []
}

Actual behaviour

Both IndexExpressions refer to the same range as the entire CallExpression (including its (), which is incorrect)

Output

{
  "type": "Chunk",
  "body": [
    {
      "type": "CallStatement",
      "expression": {
        "type": "CallExpression",
        "base": {
          "type": "IndexExpression",
          "base": {
            "type": "IndexExpression",
            "base": {
              "type": "Identifier",
              "name": "base",
              "range": [
                0,
                4
              ]
            },
            "index": {
              "type": "StringLiteral",
              "value": "outer",
              "raw": "'outer'",
              "range": [
                5,
                12
              ]
            },
            "range": [
              0,
              24
            ]
          },
          "index": {
            "type": "StringLiteral",
            "value": "inner",
            "raw": "'inner'",
            "range": [
              14,
              21
            ]
          },
          "range": [
            0,
            24
          ]
        },
        "arguments": [],
        "range": [
          0,
          24
        ]
      },
      "range": [
        0,
        24
      ]
    }
  ],
  "range": [
    0,
    24
  ],
  "comments": []
}
@fstirlitz
Copy link
Owner

Fixed by fc6fdf4, thank you.

@trixnz
Copy link
Author

trixnz commented Mar 20, 2017

Thanks for the quick turn around! This cascaded down and fixed a whole slew of hacks I had to implement in my formatter. Appreciate it! 😄

@fstirlitz fstirlitz added the incorrect parsing Valid Lua code fails to parse, is parsed incorrectly, or invalid Lua code is accepted label Aug 2, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
incorrect parsing Valid Lua code fails to parse, is parsed incorrectly, or invalid Lua code is accepted
Projects
None yet
Development

No branches or pull requests

2 participants