mljs / regression-multivariate-linear

Multivariate linear regression
MIT License
33 stars 13 forks source link

Transpiled with Webpack to work with IE11 #7

Closed Paul-Kijtapart closed 5 years ago

Paul-Kijtapart commented 6 years ago

Hi there,

First of all, thank you for creating this library.

Goal I am hoping to enable using this library in both Chrome and IE11.

Without any additional webpack config, MLR is already working with Chrome. So, only IE11 is the issue for me.

What I tried I have been trying to configure my webpack to transpile the module 'ml-regression-multivariate-linear' in node_modules to enable using it in Internet Explorer 11.

Note I did upgrade babel to 7 ("@babel/core": "^7.0.0-beta.49",)

Please see below my Webpack config for javascript file

{
 test: /\.js$/,
                use: [
                    {
                        loader: 'babel-loader',
                        options: {
                            "presets": [
                                "@babel/preset-env"
                            ],
                            "plugins": [
                                "@babel/plugin-transform-arrow-functions",
                                "@babel/plugin-transform-new-target",
                                "@babel/plugin-transform-runtime",
                                "@babel/plugin-transform-destructuring"
                            ]
                        }
                    }
                ],
                include: [
                    path.resolve('src'),
                    path.resolve('test'),

                    // mljs
                    path.join(__dirname, 'node_modules', 'ml-regression-multivariate-linear'),
                    path.join(__dirname, 'node_modules', 'ml-regression-simple-linear'),

                    // dependencies
                    path.join(__dirname, 'node_modules', 'ml-regression-base'),
                    path.join(__dirname, 'node_modules', 'ml-array-max'),
                    path.join(__dirname, 'node_modules', 'ml-array-min'),
                    path.join(__dirname, 'node_modules', 'ml-array-rescale'),
                    path.join(__dirname, 'node_modules', 'ml-matrix'),
                ]
}

From above, you can see that I makes Webpack transpile both Multivariable module and all its dependencies.

This kind of works, since it stops the syntax error in IE11.

However Since I have to transpile the dependencies of MLR, I ended up transpiling 'm-matrix' as well. This ends up making Matrix not working properly.

x = new Matrix(x) // on line number 15 in src

What happened Instead of creating a Matrix instance with x vals, the above code will return x as an array. As a result, x will error out on line 17 (x.addColumn(...))

What if I don't transpile the Matrix 'm-matrix' Then, i will end up with syntax error in IE11 due to having 'class BaseView' as can be seen below

class BaseView extends __webpack_require__.i(__WEBPACK_IMPORTED_MODULE_0__abstractMatrix__["a" /* default */])() {
  constructor(matrix, rows, columns) {
    super();
    this.matrix = matrix;
    this.rows = rows;
    this.columns = columns;
  }

  static get [Symbol.species]() {
    return __WEBPACK_IMPORTED_MODULE_1__matrix__["a" /* default */];
  }
}
/* harmony export (immutable) */ __webpack_exports__["a"] = BaseView;

I feel like I am missing some Webpack configuration required to work with MLR. Could you point me in some direction?

Any help is appreciated.

clararichter commented 5 years ago

@Paul-Kijtapart , were you able to fix this problem? I'm currently getting a syntax error in IE 11, even though the browser is included in my .browserslistrc file of my Vue.js project (https://cli.vuejs.org/guide/browser-compatibility.html).

Paul-Kijtapart commented 5 years ago

@clararichter

I believe the issue is b/c of the wrong prototype chain. You can find more info here

Even with the latest Babel 7 with babel/plugin-transform-classes, it seems the prototype chain of the Matrix class is still not set up properly.

Solution I ended up fixing it by updating the prototype field of the Matrix class. From the post above, the issue is that 'addColumn' cannot be called on the 'x' instance. By updating the prototype chain, 'x' will have the correct '__proto__' field that can be used to access 'addColumn'.