amd-to-as6 icon indicating copy to clipboard operation
amd-to-as6 copied to clipboard

Uglified AMD modules aren't always properly converted

Open jslegers opened this issue 6 years ago • 2 comments
trafficstars

Take the following AMD module :

define([
  "./Promise",
  "./request"
], function(Promise,
            request) {

  return {
    func1: function(v1) {
    },
    func2: function(v1) {
    }
  };
});

This module is succesfully converted to the following format :

import Promise from "./Promise";
import request from "./request";

  export default {
    func1: function(v1) {
    },
    func2: function(v1) {
    }
  };

However, consider the same code, but uglified :

define(["./Promise","./request"],function(n,u){return{func1:function(n){},func2:function(n){}}});

If I now try to convert to ES6 modules, it produces the following incorrect output :

import n from "./Promise";
import u from "./request";return{func1:function(n){},func2:function(n){}}

jslegers avatar Mar 19 '19 17:03 jslegers

Hey, I'm not sure why this is happening but my first question would be why are you running this against uglified code? The intention of this package to convert source code written in AMD format to ES6 style imports as a one-time operation to help with migration from the former to the latter.

Does this make sense?

jonbretman avatar Mar 28 '19 15:03 jonbretman

Here at Luciad, we are currently in the process of moving our LuciadRIA library away from AMD to ES6. And the code that we ship to our customers is minified.

My first attempts to use this project were done on one of our official releases. And, because this code was minified, it produced incorrect output.

Also, to make our code fully ES6-compatible, I will need to strip out all AMD-specific code, such as require.toUrl or the "exports" module identifier (as they don't have ES6 equivalent) before I convert all of our dev code to ES6. And not being able to use our release for testing makes this quite a painful process.

jslegers avatar Mar 28 '19 15:03 jslegers