buxlabs / amd-to-es6

convert amd to es
MIT License
35 stars 17 forks source link

If an AMD Module nests a return statement below the conditionals, then the return doesn't become an export. #103

Closed stevethedev closed 6 years ago

stevethedev commented 6 years ago

Target Code

define([],function(){
    function a(){}
    if ("function"===typeof Object.create)
        return Object.create;
    else
        return function(b){a.prototype=b;var c=new a;a.prototype=null;return c};
});

Expected Result

function a() {}
export default ("function" === typeof Object.create)
    ? Object.create
    : function(b){a.prototype=b;var c=new a;a.prototype=null;return c};

Actual Result

function a() {
}
if ('function' === typeof Object.create)
    return Object.create;
else
    return function (b) {
        a.prototype = b;
        var c = new a();
        a.prototype = null;
        return c;
    };
emilos commented 6 years ago

@stevethedev thx, I'll investigate. In the meantime, as a workaround, you could assign the result of the if statement to a variable so that there is one return.

pkonieczniak commented 6 years ago

It has been fixed in https://github.com/buxlabs/amd-to-es6/commit/6f3ab08c7e1d424d14fe157e1c87327d9bb0025e and released as 0.12.5. Thanks !