How to use the spec.undefinedToVoid transformer.
Some JavaScript implementations allow undefined
to be overwritten, this
may lead to peculiar bugs that are extremely hard to track down.
This transformer transforms undefined
into void 0
which returns undefined
regardless of if it's been reassigned.
require("babel").transform("code", { optional: ["spec.undefinedToVoid"] });
$ babel --optional spec.undefinedToVoid script.js
In
foo === undefined;
Out
foo === void 0;