esnext / es6-module-transpiler

Tomorrow’s JavaScript module syntax today
http://esnext.github.io/es6-module-transpiler/
Other
1.21k stars 85 forks source link

Issue with: expected exactly one declaration for export #147

Closed matthewrobb closed 10 years ago

matthewrobb commented 10 years ago

Currently there are some common es6 modules (handlebars in my case) that use the following pattern:

export var foo = function (){};
if (some_environment_check)
  var foo = function(){}

This leads to the above error.

I am not entirely sure what the spec says about this case but it DOES seem like an easy mistake. I guess as I type this I realize that in strict bodies this is an error anyway but I am curious if the reported error should be changed because while yes the foo identifier is declared twice in the body of the module, only ONE of those declarations is technically an export declaration.

matthewrobb commented 10 years ago

In fact, the transpiler is catching and asserting on ALL redeclarations, not just imports/exports. I know that these will be static errors in a strict body but it doesn't seem like it's appropriate for the module transpiler to keep people from shooting themselves in the foot in this way.

I'd propose that the asserting be changed to only those of imports/exports.

meandmycode commented 10 years ago

Currently seeing this issue with non imports too, importing d3 for example, would cause the assertImportIsNotReassigned to trigger for all the for(var i = ... loops.

Current work around is to disable the assertion by doing:

require('es6-module-transpiler/lib/rewriter').prototype.assertImportIsNotReassigned = function() { }

matthewrobb commented 10 years ago

@meandmycode That is resolved by #148

meandmycode commented 10 years ago

Fantastic, thank you for contributing and fixing this.

eventualbuddha commented 10 years ago

This is fixed as of v0.6.2 thanks to @matthewrobb's work.