standard-things / esm

Tomorrow's ECMAScript modules today!
Other
5.27k stars 147 forks source link

Exporting a hoisted var-declared variable causes syntax error #846

Open mkubilayk opened 5 years ago

mkubilayk commented 5 years ago
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.