2

Here is the snapshot of a part of my script after compiling:

1

I don't understand that why doesn't it convert new.target to this.constructor?

Example:

class IList {
  constructor() {
    console.log('compare using new.target:', new.target === IList);
    console.log('compare using this.constructor:', this.constructor === IList);
  }
}

new IList();

I want it does that because I can use this.constructor in the browsers which don't support for es6 while new.target requires.

Should I report it to webpack team?

UPDATE:

webpack.config.js:

let webpack = require('webpack'),
    path = require('path'),
    BabiliPlugin = require("babili-webpack-plugin");

module.exports = {
    entry: {
        'site': './assets/js/site',
        'site.min': './assets/js/site'
    },
    output: {
        publicPath: '/js/',
        path: path.join(__dirname, '/wwwroot/js/'),
        filename: '[name].js'
    },
    module: {
        loaders: [
            {
                exclude: /node_modules/,
                loader: 'babel-loader',
                query: {
                    presets: ['es2015', 'stage-1']
                }
            }
        ]
    },
    plugins: [
        new BabiliPlugin({}, {
            test: /\.min\.js$/
        }),
        new webpack.ProvidePlugin({
            $: 'jquery',
            jQuery: 'jquery'
        })
    ]
};
  • Webpack can use the Babel-package to convert ES6 to ES5 code. Could you provide some more informations about your setup (~packages)? – Spears Aug 08 '17 at 05:55
  • Possible duplicate of [Webpack not converting ES6 to ES5](https://stackoverflow.com/questions/34404496/webpack-not-converting-es6-to-es5) – Jorg Aug 08 '17 at 05:56
  • @Jorg It's not. Almost es6 syntaxes in my script had been converted successful. Except `new.target` –  Aug 08 '17 at 05:58
  • 1
    @Alan That's because your Babel version [doesn't yet support transpiling `new.target`](https://github.com/babel/babel/issues/1088). The rest is working as expected. – Bergi Aug 08 '17 at 06:03
  • @Bergi omg, there was a report in 2015 and I'm still getting it in 2017 (~2018) ^^! –  Aug 08 '17 at 06:07
  • 4
    @Alan Which means you had 2 years of time to submit a pull request :-) The maintainers are busy and always welcome help - it's a community project. `new.target` just wasn't a priority. – Bergi Aug 08 '17 at 06:13

1 Answers1

0

It looks like this issue is solved in Babel 7. See https://github.com/babel/babel/pull/5906

Seems like it's included in the builds of the pre-release: https://github.com/babel/babel/releases

BoxerBucks
  • 3,124
  • 2
  • 21
  • 26
  • Thanks! But after installing plugin [babel-plugin-transform-new-target](https://github.com/babel/babel/blob/7.0/packages/babel-plugin-transform-new-target/README.md). The `new.target` part was not changed. –  Aug 09 '17 at 02:11
  • I don't think Babel 7 is officially out yet. I think you'd have to install a pre alpha version or compile it from source. – BoxerBucks Aug 09 '17 at 13:39