bluejava / zousan

A Lightning Fast, Yet Very Small Promise A+ Compliant Implementation
MIT License
127 stars 13 forks source link

FIX: locate global object #17

Closed yuqianma closed 5 years ago

yuqianma commented 5 years ago

Hi, I notice thers's no check for global. I add it.

Another thing is, rollup doesn't allow this inside module. And the cli option --context is not working. I replace the void 0 with this in zousan-min.js manually in the end.

Maybe we can just copy rollup's umd wrapper out, and use uglifyjs to combine them?

UPDATE: Maybe it's an uglifyjs bug. If I use global as the variable name, it converts all global to t. So I use globalThis.

bluejava commented 5 years ago

Thanks for the heads-up @yuqianma! That was an oversite.

After some thought, I decided to ditch the global reference altogether and just check for the presence of a console - and if so, use it - if not, ignore errors/warnings but allow users to override with error/warning handlers of their liking.

While I was at it, I converted vars to const/let and moved a couple other things towards modern ES styles. I tested this in the browser this time - both as a UMD and an ES module. In performance testing I think the ES Module may even have sped up a bit (which might make sense, as const variables can be optimized more than var can.)

Thanks again for bringing this to my attention and proposing a fix!