esm icon indicating copy to clipboard operation
esm copied to clipboard

Exporting a hoisted var-declared variable causes syntax error

Open mkubilayk opened this issue 6 years ago • 0 comments

if (true) {
    var x = 1;
}
export { x };

This piece of code works with node --experimental-modules on v12.8.0. On esm v3.2.25, it fails with the following error:

export { x };
         ^

SyntaxError: Export 'x' is not defined in module

Expected behaviour is that this should be considered valid syntax and exported value should have value of 1.

It looks like the assumption here that the exported names should have a top level declaration is wrong.

mkubilayk avatar Oct 25 '19 10:10 mkubilayk