I was playing around on the Babel repl, when I noticed, for:
import {foo} from 'bar';
foo();
Babel generates:
'use strict';
var _bar = require('bar');
(0, _bar.foo)();
whereas for:
function foo() {}
foo();
Babel generates the expected:
"use strict";
function foo() {}
foo();
My question is with regards to the last line of the first Babel output, is there a reason for doing (0, _bar.foo)();
instead of _bar.foo()
? Does it handle some sort of corner case if _bar.foo
is undefined
?
I found these resources. From MDN comma operator docs:
The comma operator evaluates each of its operands (from left to right) and returns the value of the last operand.
and from MDN grouping operator docs:
The grouping operator ( ) controls the precedence of evaluation in expressions.
From my understanding, from those two statements, (0, _bar.foo)
should evaluate to _bar.foo
?