王清雨 aa18da08cd
fix(class-properties): replace new.target in static properties with undefined (#13560)
* fix(class-properties): replace `new.target` in static properties with `undefined`

non-static prop is not affected

fix #12737

* Update packages/babel-helper-create-class-features-plugin/src/fields.ts

fix typo

Co-authored-by: Brian Ng <bng412@gmail.com>

* fix: add loose test case and fix replace condition

* test: add new.target tests for static block

* feat: move new-target replace into thisContextVisitor

defaults to replace new.target, do not replace within function

* feat: simplify thisContextVisitor

remove function visitor since environmentVisitor is skipping arrow function

* test: remove unused fixme comments

Co-authored-by: Brian Ng <bng412@gmail.com>
2021-07-16 15:58:55 -04:00

34 lines
1.0 KiB
JavaScript

class Foo {
constructor() {
var _newtarget = this.constructor,
_class,
_temp;
babelHelpers.defineProperty(this, "test", function _target() {
this instanceof _target ? this.constructor : void 0;
});
babelHelpers.defineProperty(this, "test2", function () {
_newtarget;
});
this.Bar = (_temp = _class = class _target2 {
constructor() {
babelHelpers.defineProperty(this, "q", this.constructor);
} // should not replace
}, babelHelpers.defineProperty(_class, "p", void 0), babelHelpers.defineProperty(_class, "p1", class _target3 {
constructor() {
this.constructor;
}
}), babelHelpers.defineProperty(_class, "p2", new function _target4() {
this instanceof _target4 ? this.constructor : void 0;
}()), babelHelpers.defineProperty(_class, "p3", function () {
void 0;
}), babelHelpers.defineProperty(_class, "p4", function _target5() {
this instanceof _target5 ? this.constructor : void 0;
}), _temp);
}
}