@babel/plugin-transform-new-target

    1. class Foo {
    2. constructor() {
    3. console.log(new.target);
    4. }
    5. }
    6. new Foo(); // => Foo
    7. new Bar(); // => Bar
    1. function Foo() {
    2. console.log(new.target);
    3. }
    4. // Bar extends Foo in ES5
    5. function Bar() {
    6. Foo.call(this);
    7. }
    8. Bar.prototype = Object.create(Foo.prototype);
    9. Bar.prototype.constructor = Bar;
    10. function Baz() {}
    11. Reflect.construct(Foo, []); // => Foo (correct)
    12. Reflect.construct(Foo, [], Bar); // => Bar (correct)
    13. Reflect.construct(Bar, []); // => Bar (incorrect, though this is how ES5
    14. // inheritance is commonly implemented.)
    15. Reflect.construct(Foo, [], Baz); // => undefined (incorrect)
    1. {
    2. "plugins": ["@babel/plugin-transform-new-target"]
    3. }
    1. require("@babel/core").transformSync("code", {
    2. });