fstirlitz / luaparse

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

StringLiteral value is null at v0.3.0 #82

Closed changnet closed 4 years ago

changnet commented 4 years ago
luaparse "local m = require \"a.b.c\""
{"type":"Chunk","body":[{"type":"LocalStatement","variables":[{"type":"Identifie
r","name":"m"}],"init":[{"type":"StringCallExpression","base":{"type":"Identifie
r","name":"require"},"argument":{"type":"StringLiteral","value":null,"raw":"\"a.
b.c\""}}]}],"comments":[]}

luaparse "local m = require [[a.b.c]]"
{"type":"Chunk","body":[{"type":"LocalStatement","variables":[{"type":"Identifie
r","name":"m"}],"init":[{"type":"StringCallExpression","base":{"type":"Identifie
r","name":"require"},"argument":{"type":"StringLiteral","value":null,"raw":"[[a.
b.c]]"}}]}],"comments":[]}

The value is "a.b.c" at version 0.2.1, without this value, I have to parse the value from raw, because lua string can be wrap within [[]] or "" or ''

Is this a change in 0.3.0, if so i need to change my code.

fstirlitz commented 4 years ago

This is intentional, introduced in commit be3c3ee863bec09ba6ae5c4e4fcfa09f7172814c. The reason is the semantic mismatch between bytestrings (used by Lua) and Unicode strings (used by JavaScript); #68 and the README file elaborate on this further. Pre-release versions handled this by mangling Unicode input into UTF-8, but I got a number of reports that this behaviour is confusing; and since most users were more interested in identifiers than values of string literals, I decided to change the default mode to one with no mangling of identifiers and no interpretation of string literals. If you want string literals parsed into their contents, you need to decide how bytestrings should map into Unicode strings by specifying the encodingMode option.

Yes, this is a breaking change. Perhaps I should have put a release note somewhere, but I'm not sure where; this project doesn't have a changelog other than commit history. But this change is why I bumped the minor release number, and not just the patch.

changnet commented 4 years ago

thank you for reply

It would be better if there is release note or a change log

I did a little search at npm page, README and release page before open this issuse, but did't find anything