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

StringLiteral value is null at v0.3.0 #82

Closed
changnet opened this issue Apr 12, 2020 · 2 comments
Closed

StringLiteral value is null at v0.3.0 #82

changnet opened this issue Apr 12, 2020 · 2 comments
Labels
compat hazard Resolving this issue may create backwards compatibility problems question General question regarding the project

Comments

@changnet
Copy link

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
Copy link
Owner

fstirlitz commented Apr 12, 2020

This is intentional, introduced in commit be3c3ee. 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.

@fstirlitz fstirlitz added compat hazard Resolving this issue may create backwards compatibility problems question General question regarding the project labels Apr 12, 2020
@changnet
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compat hazard Resolving this issue may create backwards compatibility problems question General question regarding the project
Projects
None yet
Development

No branches or pull requests

2 participants