mathiasbynens / luamin

A Lua minifier written in JavaScript
https://mths.be/luamin
MIT License
217 stars 54 forks source link

Working with BOMs #54

Closed martin-braun closed 6 years ago

martin-braun commented 6 years ago

Right out of my node console:

> let luamin = require("luamin")
undefined
> var x = fs.readFileSync("test.lua", "utf8")
undefined
> x
'local a = 123'
> luamin.minify(x)
TypeError: Cannot read property 'value' of undefined
    at unexpected (.\node_modules\luaparse\luaparse.js:499:55)
    at lex (.\node_modules\luaparse\luaparse.js:627:12)
    at end (.\node_modules\luaparse\luaparse.js:2092:17)
    at parse (.\node_modules\luaparse\luaparse.js:2065:31)
    at Object.minify (.\node_modules\luamin\luamin.js:621:6)
    at repl:1:8
    at ContextifyScript.Script.runInThisContext (vm.js:50:33)
    at REPLServer.defaultEval (repl.js:240:29)
    at bound (domain.js:301:14)
    at REPLServer.runBound [as eval] (domain.js:314:12)
>

The file is encoded UTF8 with BOM. Changing it to UTF8 without BOM works. Maybe luamin could deal with it? BOMs are useful if all the environment deals with their existence.

Thanks.

mathiasbynens commented 6 years ago

BOMs are never useful.

Supporting them is out of the scope of the luamin project.

If you need to support them, consider using https://github.com/sindresorhus/strip-bom before passing the content to luamin.