So according to this issue, I guess flash must have an amount of the abandoned data before running compact, if not, the compact function will cause data loss.
Espruino is a JavaScript interpreter for low-power Microcontrollers. This site is both a support community for Espruino and a place to share what you are working on.
Please share snippet to reproduce it.