fstirlitz / luaparse

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

The string literal's value is not passed properly. #129

Open HeeMyung opened 1 year ago

HeeMyung commented 1 year ago

See example below.

local foo = 'ABCD'

At a very simple level of code like this, "ABCD" is parsed well as a Literal node, but if you look into that node, raw is properly entered, but the value is null.

the result of printing ast is as follows.

{
  type: 'Chunk',
  body: [ { type: 'LocalStatement', variables: [Array], init: [Array] } ],
  comments: []
}
{ type: 'StringLiteral', value: null, raw: "'ABCD'" }
semiyan commented 2 months ago

This is an effect of encodingMode 'none', you can either use x-user-defined or pseudo-latin1 and strings should get parsed

parser.parse("a = 1",{
  encodingMode: "x-user-defined"
});