Skip to content
This repository has been archived by the owner on Mar 29, 2018. It is now read-only.

Default exports #143

Closed
matthewrobb opened this issue Jul 30, 2014 · 8 comments
Closed

Default exports #143

matthewrobb opened this issue Jul 30, 2014 · 8 comments

Comments

@matthewrobb
Copy link
Contributor

I may be missing something but I cannot get default exports to work with the current or previous few versions of es6-module-transpiler.

Error:

...\node_modules\es6-module-transpiler\lib\exports.js:54
  } else if (n.ExportBatchSpecifier.check(node.specifiers[0])) {
                                                         ^
TypeError: Cannot read property '0' of null
    at ExportDeclarationList.declarationForNode (...\node_modules\es6-module-transpiler\lib\exports.js:54:58)
    at ...\node_modules\es6-module-transpiler\lib\module_binding_list.js:213:17
    at Array.map (native)
    at ExportDeclarationList.module.exports (...\node_modules\es6-module-transpiler\lib\module_binding_list.js:212:22)
    at ExportDeclarationList.Object.defineProperty.get (...\node_modules\es6-module-transpiler\lib\utils.js:11:31)
    at ...\node_modules\es6-module-transpiler\lib\rewriter.js:60:19
    at Array.forEach (native)
    at ...\node_modules\es6-module-transpiler\lib\rewriter.js:59:32
    at Array.forEach (native)
    at Rewriter.rewrite (...\node_modules\es6-module-transpiler\lib\rewriter.js:58:11)

When looking a little deeper it appears that the ast node used in exports.js has the default property undefined no matter what:

/**
 * Gets an export declaration for the given `node`.
 *
 * @private
 * @param {ast-types.ExportDeclaration} node
 * @return {Import}
 */
ExportDeclarationList.prototype.declarationForNode = function(node) {
  if (node.default) {
    return new DefaultExportDeclaration(this.module, node);
  } else if (n.VariableDeclaration.check(node.declaration)) {
    return new VariableExportDeclaration(this.module, node);
  } else if (n.FunctionDeclaration.check(node.declaration)) {
    return new FunctionExportDeclaration(this.module, node);
  } else if (n.ExportBatchSpecifier.check(node.specifiers[0])) {
    throw new Error(
      '`export *` found at ' + sourcePosition(this.module, node) +
      ' is not supported, please use `export { … }` instead'
    );
  } else {
    return new NamedExportDeclaration(this.module, node);
  }
};
@caridy
Copy link
Contributor

caridy commented Jul 30, 2014

this normally happen when you have a linked pkg that contains recast as a dep, while you have another recast dep that does the parsing. Even if the version of the recast pkgs are the same, it seems to be a problem with the way recast compare references. Nothing to do with the transpiler IMO.

@matthewrobb
Copy link
Contributor Author

@caridy I did a bit more digging based on what you said and I found that the problem stems from the fact that recast depends on a different esprima than the version es6-module-transpiler depends on. If I adjust recast to have the same dependency then it works, otherwise not.

@matthewrobb
Copy link
Contributor Author

It might be valuable to put some documentation up somewhere that in order to use es6-module-transpiler with other recast transformers you need to pass esprima into recast.parse() and it has to be git://github.com/thomasboyt/esprima#4be906f1abcbb

Alternatively, perhaps exporting esprima from es6-module-transpiler would be a good choice. Allowing people to do recast.parse(..., { esprima: require("es6-module-transpiler").esprima })

@gigr
Copy link

gigr commented Aug 14, 2014

@matthewrobb Care to share some more details as to how you resolved this issue?

@eventualbuddha
Copy link
Contributor

I believe the current plan is to standardize on using esprima-fb instead of esprima#harmony. That way npm can properly dedupe and everyone will be happy 😉

@caridy
Copy link
Contributor

caridy commented Oct 13, 2014

I think we can close this one now.

@ericf
Copy link
Contributor

ericf commented Oct 23, 2014

Maybe this should be reopened. With v0.9.0 when using:

export * from './foo';

I'm seeing this error:

Error writing bundle in "bundle.js": Error: `export *` found at foo.js:1:1 is not supported, please use `export { … }` instead

This export-from syntax is suppose to be supported, correct?

@caridy
Copy link
Contributor

caridy commented Oct 23, 2014

@ericf this is tracked here: #29

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants