fstirlitz / luaparse

A Lua parser written in JavaScript
https://fstirlitz.github.io/luaparse/
MIT License
459 stars 91 forks source link

Fixes locations for long string literals. #37

Closed paulcuth closed 7 years ago

paulcuth commented 8 years ago

I don't fully understand the code around locations, but this does fix the issue in my use case.

Fixes oxyc/luaparse#36

oxyc commented 8 years ago

Thanks for your research and PR! Unfortunately I dont have access to a dev environment where I can test this at the moment. Unless @fstirlitz gets to it first, I'll be back to my laptop in a week or so

fstirlitz commented 8 years ago

The start position is good, but the end position is now wrong. Your own example from #36:

/* ... */
        {
          "type": "StringLiteral",
          "value": "hello\nworld",
          "raw": "[[hello\nworld]]",
          "loc": {
            "start": {
              "line": 1,
              "column": 10
            },
            "end": {
              "line": 1,
              "column": 25
            }
          }
        }
/* ... */

Also, please add some testcases. Something like

x = [[hello@n@world]]
x = { 1, 2, [[hello@n@@n@world]], @n@ 3 }

into test/scaffolding/literals and then run make scaffold-tests. To run tests, make test.

fstirlitz commented 7 years ago

Cherry-picked in 4b56017a702789db0ea71011758667a511bc0d34.