MatAtBread / fast-async

603 stars 21 forks source link

Clobbers single line function definition export #7

Closed naturalethic closed 8 years ago

naturalethic commented 8 years ago

Will rewrite an exported function into a non-exported given for example:

export async function foo() {}

This then requires a manual export later in the file.

simonbuchan commented 8 years ago

I get this even for non-async functions:

% cat export.js
export function test() {
  return 1;
}
% babel --presets es2015 --plugins fast-async export.js
"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});

Function.prototype.$asyncbind = <snip>;

function test() {
  return 1;
}

And export default function will error with "ReferenceError: $1 is not defined":

% babel --presets es2015 --plugins fast-async export_default.js
"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});

Function.prototype.$asyncbind = <snip>

exports.default = $1;
function test() {
  return 1;
}
MatAtBread commented 8 years ago

Thanks for pointing this one out. Can you tell me the exact versions of fast-async, nodent and acorn-es7-plugin that was installed in your test environment, as I fixed some export-async issues recently. I'm unable to when through issues for a week as I'm away, but will get these patches when I'm back

naturalethic commented 8 years ago

For myself:

fast-async@6.0.31
nodent@2.6.2
acorn-es7-plugin@1.0.17
MatAtBread commented 8 years ago

They're all latest, so it might be something I've missed. However, this might be a Babel issue, as the online compiler (same versions as you - no Babel, just nodent and acorn doing the transpiling) seems to generate good code:

http://nodent.mailed.me.uk/#export%20async%20function%20foo()%20%7B%7D

MatAtBread commented 8 years ago

@simonbuchan's comment would seem to support the theory it's a Babel issue, but I'll take a look anyway, unless you determine this one way or the other in advance

simonbuchan commented 8 years ago

Well they export fine without --plugins fast-async, or with the regenerator based transform plugins, but it does look like an interaction with Babel's module transform

nightwolfz commented 8 years ago

Having the same issues

MatAtBread commented 8 years ago

Out of interest, what happens if you reverse the order of the plugins (ie fast-async before the presets). I'm still away so I can't test this myself for a few days!

MatAtBread commented 8 years ago

Fixed in fast-async@6.0.32

naturalethic commented 8 years ago

Confirmed. Thanks!

MatAtBread commented 8 years ago

NP :)