lua-in-js icon indicating copy to clipboard operation
lua-in-js copied to clipboard

Expose luaparse encoding mode option to lua-in-js

Open DanWaLes opened this issue 1 year ago • 5 comments

When trying to execute the strings '▲' or '▼' (html entities &#9650 and &#9660), luaparse gives an encoding error. lua-in-js should provide the option to change from the default encoding mode.

DanWaLes avatar Jan 05 '25 17:01 DanWaLes

My scripts have chinese characters in it. It also throw the same error to me as well. I think the problem is here...

src/parser.ts

encodingMode: 'x-user-defined'

Elly2018 avatar Feb 09 '25 12:02 Elly2018

Downgrading to 2.2.0 fixed it for me.
encodingMode: 'x-user-defined' was introduced in 2.2.1.

Gurimarukin avatar Feb 19 '25 19:02 Gurimarukin

I should have probably used encodingMode: 'none', could you give it a try? If it works, a PR would be welcome.

teoxoy avatar Mar 24 '25 10:03 teoxoy

https://github.com/teoxoy/lua-in-js/pull/24

Elly2018 avatar Apr 19 '25 01:04 Elly2018

Actually, encodingMode: 'none' is not correct since it always sets value to null, we could use the raw property but we'd have to reparse the string literal ourselves.

'pseudo-latin1' seems like the best choice, but characters outside of ISO/IEC 8859-1 need to be escaped (via \u{XXX}) either by lua-in-js or by user code.

This should also now be removed:

https://github.com/teoxoy/lua-in-js/blob/1165827c2e0dc95b3962a70e8a8c97a758fc5944/src/parser.ts#L224

Relevant: https://github.com/fstirlitz/luaparse/issues/68. Ideally luaparse would allow for a utf16 encoding, but I don't know what that would entail.

teoxoy avatar Aug 26 '25 13:08 teoxoy