I read here that I don't need to put a semicolon after default exports. So this program has an unnecessary semicolon:
export default function() {};
But if my module continues like this:
export default function() {};
(() => {
// creating a new function scope
})();
then I can't leave the semicolon.
So what is going on here? The grammar says I don't need the semicolon but if I leave it the code means something else?
UPDATE:
If I leave the semicolon:
export default function() {}
(() => {
// creating a new function scope
})();
then the exported function gets called instead of being exported. babeljs.io compiles the latter into:
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports["default"] = (function () {})(function () {
// creating a new function scope
})();
;
module.exports = exports["default"];
More precisely after it gets called an error is thrown, because the return value of the first function also gets called (but that is not a function). The error I get in chrome is this:
Uncaught TypeError: (intermediate value)(...) is not a function(…)