Get set helpers (#7687)
* Improve get/set helper
* fixtures
* Edge cases
* Add loose edge cases
* Spec compliant
* Add issue case
* Even more edge cases!
* Final updates
* Fix name
* Use Reflect.{get, set} when available
* Avoid block scoping in loose
* Remove semicolon
* Do not redefine a non-enumerable
* Get strictness from call site, not helpers
* Add called assertions
* Classes are always strict
* Update test fixture
This commit is contained in:
@@ -2,7 +2,7 @@ function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.crea
|
||||
|
||||
function _wrapNativeSuper(Class) { var _cache = typeof Map === "function" ? new Map() : undefined; _wrapNativeSuper = function _wrapNativeSuper(Class) { if (typeof Class !== "function") { throw new TypeError("Super expression must either be null or a function"); } if (typeof _cache !== "undefined") { if (_cache.has(Class)) return _cache.get(Class); _cache.set(Class, Wrapper); } function Wrapper() {} Wrapper.prototype = Object.create(Class.prototype, { constructor: { value: Wrapper, enumerable: false, writable: true, configurable: true } }); return _setPrototypeOf(Wrapper, _setPrototypeOf(function Super() { return _construct(Class, arguments, _getPrototypeOf(this).constructor); }, Class)); }; return _wrapNativeSuper(Class); }
|
||||
|
||||
function _construct(Parent, args, Class) { if (typeof Reflect === "object" && Reflect.construct) { _construct = Reflect.construct; } else { _construct = function _construct(Parent, args, Class) { var a = [null]; a.push.apply(a, args); var Constructor = Parent.bind.apply(Parent, a); var instance = new Constructor(); if (Class) _setPrototypeOf(instance, Class.prototype); return instance; }; } return _construct.apply(null, arguments); }
|
||||
function _construct(Parent, args, Class) { if (typeof Reflect !== "undefined" && Reflect.construct) { _construct = Reflect.construct; } else { _construct = function _construct(Parent, args, Class) { var a = [null]; a.push.apply(a, args); var Constructor = Parent.bind.apply(Parent, a); var instance = new Constructor(); if (Class) _setPrototypeOf(instance, Class.prototype); return instance; }; } return _construct.apply(null, arguments); }
|
||||
|
||||
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@ function _inherits(subClass, superClass) { if (typeof superClass !== "function"
|
||||
|
||||
function _wrapNativeSuper(Class) { var _cache = typeof Map === "function" ? new Map() : undefined; _wrapNativeSuper = function _wrapNativeSuper(Class) { if (typeof Class !== "function") { throw new TypeError("Super expression must either be null or a function"); } if (typeof _cache !== "undefined") { if (_cache.has(Class)) return _cache.get(Class); _cache.set(Class, Wrapper); } function Wrapper() {} Wrapper.prototype = Object.create(Class.prototype, { constructor: { value: Wrapper, enumerable: false, writable: true, configurable: true } }); return _setPrototypeOf(Wrapper, _setPrototypeOf(function Super() { return _construct(Class, arguments, _getPrototypeOf(this).constructor); }, Class)); }; return _wrapNativeSuper(Class); }
|
||||
|
||||
function _construct(Parent, args, Class) { if (typeof Reflect === "object" && Reflect.construct) { _construct = Reflect.construct; } else { _construct = function _construct(Parent, args, Class) { var a = [null]; a.push.apply(a, args); var Constructor = Parent.bind.apply(Parent, a); var instance = new Constructor(); if (Class) _setPrototypeOf(instance, Class.prototype); return instance; }; } return _construct.apply(null, arguments); }
|
||||
function _construct(Parent, args, Class) { if (typeof Reflect !== "undefined" && Reflect.construct) { _construct = Reflect.construct; } else { _construct = function _construct(Parent, args, Class) { var a = [null]; a.push.apply(a, args); var Constructor = Parent.bind.apply(Parent, a); var instance = new Constructor(); if (Class) _setPrototypeOf(instance, Class.prototype); return instance; }; } return _construct.apply(null, arguments); }
|
||||
|
||||
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
||||
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
"use strict";
|
||||
class Base {
|
||||
}
|
||||
Object.defineProperty(Base.prototype, 'test', {
|
||||
value: 1,
|
||||
writable: true,
|
||||
configurable: true,
|
||||
});
|
||||
|
||||
class Obj extends Base {
|
||||
get() {
|
||||
return super.test;
|
||||
}
|
||||
}
|
||||
Object.defineProperty(Obj.prototype, 'test', {
|
||||
value: 2,
|
||||
writable: true,
|
||||
configurable: true,
|
||||
});
|
||||
|
||||
const obj = new Obj();
|
||||
assert.equal(obj.test, 2);
|
||||
assert.equal(obj.get(), 1);
|
||||
@@ -0,0 +1,15 @@
|
||||
"use strict";
|
||||
class Base {
|
||||
}
|
||||
Base.prototype.test = 1;
|
||||
|
||||
class Obj extends Base {
|
||||
get() {
|
||||
return super.test;
|
||||
}
|
||||
}
|
||||
Obj.prototype.test = 2;
|
||||
|
||||
const obj = new Obj();
|
||||
assert.equal(obj.test, 2);
|
||||
assert.equal(obj.get(), 1);
|
||||
@@ -0,0 +1,53 @@
|
||||
"use strict";
|
||||
|
||||
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
|
||||
|
||||
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
|
||||
|
||||
function _possibleConstructorReturn(self, call) { if (call && (typeof call === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
|
||||
|
||||
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
||||
|
||||
function _get(target, property, receiver) { if (typeof Reflect !== "undefined" && Reflect.get) { _get = Reflect.get; } else { _get = function _get(target, property, receiver) { var base = _superPropBase(target, property); if (!base) return; var desc = Object.getOwnPropertyDescriptor(base, property); if (desc.get) { return desc.get.call(receiver); } return desc.value; }; } return _get(target, property, receiver || target); }
|
||||
|
||||
function _superPropBase(object, property) { while (!Object.prototype.hasOwnProperty.call(object, property)) { object = _getPrototypeOf(object); if (object === null) break; } return object; }
|
||||
|
||||
function _getPrototypeOf(o) { _getPrototypeOf = Object.getPrototypeOf || function _getPrototypeOf(o) { return o.__proto__; }; return _getPrototypeOf(o); }
|
||||
|
||||
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
|
||||
|
||||
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
||||
|
||||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
||||
|
||||
let Base = function Base() {
|
||||
_classCallCheck(this, Base);
|
||||
};
|
||||
|
||||
Base.prototype.test = 1;
|
||||
|
||||
let Obj =
|
||||
/*#__PURE__*/
|
||||
function (_Base) {
|
||||
_inherits(Obj, _Base);
|
||||
|
||||
function Obj() {
|
||||
_classCallCheck(this, Obj);
|
||||
|
||||
return _possibleConstructorReturn(this, _getPrototypeOf(Obj).apply(this, arguments));
|
||||
}
|
||||
|
||||
_createClass(Obj, [{
|
||||
key: "get",
|
||||
value: function get() {
|
||||
return _get(_getPrototypeOf(Obj.prototype), "test", this);
|
||||
}
|
||||
}]);
|
||||
|
||||
return Obj;
|
||||
}(Base);
|
||||
|
||||
Obj.prototype.test = 2;
|
||||
const obj = new Obj();
|
||||
assert.equal(obj.test, 2);
|
||||
assert.equal(obj.get(), 1);
|
||||
@@ -0,0 +1,22 @@
|
||||
"use strict";
|
||||
class Base {
|
||||
get test() {
|
||||
assert.equal(this, obj);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
class Obj extends Base {
|
||||
get() {
|
||||
return super.test;
|
||||
}
|
||||
}
|
||||
Object.defineProperty(Obj.prototype, 'test', {
|
||||
value: 2,
|
||||
writable: true,
|
||||
configurable: true,
|
||||
});
|
||||
|
||||
const obj = new Obj();
|
||||
assert.equal(obj.test, 2);
|
||||
assert.equal(obj.get(), 1);
|
||||
@@ -0,0 +1,22 @@
|
||||
"use strict";
|
||||
class Base {
|
||||
get test() {
|
||||
assert.equal(this, obj);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
class Obj extends Base {
|
||||
get() {
|
||||
return super.test;
|
||||
}
|
||||
}
|
||||
Object.defineProperty(Obj.prototype, 'test', {
|
||||
value: 2,
|
||||
writable: true,
|
||||
configurable: true,
|
||||
});
|
||||
|
||||
const obj = new Obj();
|
||||
assert.equal(obj.test, 2);
|
||||
assert.equal(obj.get(), 1);
|
||||
@@ -0,0 +1,69 @@
|
||||
"use strict";
|
||||
|
||||
function _possibleConstructorReturn(self, call) { if (call && (typeof call === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
|
||||
|
||||
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
||||
|
||||
function _get(target, property, receiver) { if (typeof Reflect !== "undefined" && Reflect.get) { _get = Reflect.get; } else { _get = function _get(target, property, receiver) { var base = _superPropBase(target, property); if (!base) return; var desc = Object.getOwnPropertyDescriptor(base, property); if (desc.get) { return desc.get.call(receiver); } return desc.value; }; } return _get(target, property, receiver || target); }
|
||||
|
||||
function _superPropBase(object, property) { while (!Object.prototype.hasOwnProperty.call(object, property)) { object = _getPrototypeOf(object); if (object === null) break; } return object; }
|
||||
|
||||
function _getPrototypeOf(o) { _getPrototypeOf = Object.getPrototypeOf || function _getPrototypeOf(o) { return o.__proto__; }; return _getPrototypeOf(o); }
|
||||
|
||||
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
|
||||
|
||||
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
||||
|
||||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
||||
|
||||
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
|
||||
|
||||
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
|
||||
|
||||
let Base =
|
||||
/*#__PURE__*/
|
||||
function () {
|
||||
function Base() {
|
||||
_classCallCheck(this, Base);
|
||||
}
|
||||
|
||||
_createClass(Base, [{
|
||||
key: "test",
|
||||
get: function () {
|
||||
assert.equal(this, obj);
|
||||
return 1;
|
||||
}
|
||||
}]);
|
||||
|
||||
return Base;
|
||||
}();
|
||||
|
||||
let Obj =
|
||||
/*#__PURE__*/
|
||||
function (_Base) {
|
||||
_inherits(Obj, _Base);
|
||||
|
||||
function Obj() {
|
||||
_classCallCheck(this, Obj);
|
||||
|
||||
return _possibleConstructorReturn(this, _getPrototypeOf(Obj).apply(this, arguments));
|
||||
}
|
||||
|
||||
_createClass(Obj, [{
|
||||
key: "get",
|
||||
value: function get() {
|
||||
return _get(_getPrototypeOf(Obj.prototype), "test", this);
|
||||
}
|
||||
}]);
|
||||
|
||||
return Obj;
|
||||
}(Base);
|
||||
|
||||
Object.defineProperty(Obj.prototype, 'test', {
|
||||
value: 2,
|
||||
writable: true,
|
||||
configurable: true
|
||||
});
|
||||
const obj = new Obj();
|
||||
assert.equal(obj.test, 2);
|
||||
assert.equal(obj.get(), 1);
|
||||
@@ -0,0 +1,18 @@
|
||||
"use strict";
|
||||
class Base {
|
||||
}
|
||||
|
||||
class Obj extends Base {
|
||||
get() {
|
||||
return super.test;
|
||||
}
|
||||
}
|
||||
Object.defineProperty(Obj.prototype, 'test', {
|
||||
value: 2,
|
||||
writable: true,
|
||||
configurable: true,
|
||||
});
|
||||
|
||||
const obj = new Obj();
|
||||
assert.equal(obj.test, 2);
|
||||
assert.equal(obj.get(), undefined);
|
||||
@@ -0,0 +1,18 @@
|
||||
"use strict";
|
||||
class Base {
|
||||
}
|
||||
|
||||
class Obj extends Base {
|
||||
get() {
|
||||
return super.test;
|
||||
}
|
||||
}
|
||||
Object.defineProperty(Obj.prototype, 'test', {
|
||||
value: 2,
|
||||
writable: true,
|
||||
configurable: true,
|
||||
});
|
||||
|
||||
const obj = new Obj();
|
||||
assert.equal(obj.test, 2);
|
||||
assert.equal(obj.get(), undefined);
|
||||
@@ -0,0 +1,55 @@
|
||||
"use strict";
|
||||
|
||||
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
|
||||
|
||||
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
|
||||
|
||||
function _possibleConstructorReturn(self, call) { if (call && (typeof call === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
|
||||
|
||||
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
||||
|
||||
function _get(target, property, receiver) { if (typeof Reflect !== "undefined" && Reflect.get) { _get = Reflect.get; } else { _get = function _get(target, property, receiver) { var base = _superPropBase(target, property); if (!base) return; var desc = Object.getOwnPropertyDescriptor(base, property); if (desc.get) { return desc.get.call(receiver); } return desc.value; }; } return _get(target, property, receiver || target); }
|
||||
|
||||
function _superPropBase(object, property) { while (!Object.prototype.hasOwnProperty.call(object, property)) { object = _getPrototypeOf(object); if (object === null) break; } return object; }
|
||||
|
||||
function _getPrototypeOf(o) { _getPrototypeOf = Object.getPrototypeOf || function _getPrototypeOf(o) { return o.__proto__; }; return _getPrototypeOf(o); }
|
||||
|
||||
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
|
||||
|
||||
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
||||
|
||||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
||||
|
||||
let Base = function Base() {
|
||||
_classCallCheck(this, Base);
|
||||
};
|
||||
|
||||
let Obj =
|
||||
/*#__PURE__*/
|
||||
function (_Base) {
|
||||
_inherits(Obj, _Base);
|
||||
|
||||
function Obj() {
|
||||
_classCallCheck(this, Obj);
|
||||
|
||||
return _possibleConstructorReturn(this, _getPrototypeOf(Obj).apply(this, arguments));
|
||||
}
|
||||
|
||||
_createClass(Obj, [{
|
||||
key: "get",
|
||||
value: function get() {
|
||||
return _get(_getPrototypeOf(Obj.prototype), "test", this);
|
||||
}
|
||||
}]);
|
||||
|
||||
return Obj;
|
||||
}(Base);
|
||||
|
||||
Object.defineProperty(Obj.prototype, 'test', {
|
||||
value: 2,
|
||||
writable: true,
|
||||
configurable: true
|
||||
});
|
||||
const obj = new Obj();
|
||||
assert.equal(obj.test, 2);
|
||||
assert.equal(obj.get(), undefined);
|
||||
@@ -0,0 +1,21 @@
|
||||
"use strict";
|
||||
class Base {
|
||||
set test(v) {
|
||||
throw new Error("not called");
|
||||
}
|
||||
}
|
||||
|
||||
class Obj extends Base {
|
||||
get() {
|
||||
return super.test;
|
||||
}
|
||||
}
|
||||
Object.defineProperty(Obj.prototype, 'test', {
|
||||
value: 2,
|
||||
writable: true,
|
||||
configurable: true,
|
||||
});
|
||||
|
||||
const obj = new Obj();
|
||||
assert.equal(obj.test, 2);
|
||||
assert.equal(obj.get(), undefined);
|
||||
@@ -0,0 +1,21 @@
|
||||
"use strict";
|
||||
class Base {
|
||||
set test(v) {
|
||||
throw new Error("not called");
|
||||
}
|
||||
}
|
||||
|
||||
class Obj extends Base {
|
||||
get() {
|
||||
return super.test;
|
||||
}
|
||||
}
|
||||
Object.defineProperty(Obj.prototype, 'test', {
|
||||
value: 2,
|
||||
writable: true,
|
||||
configurable: true,
|
||||
});
|
||||
|
||||
const obj = new Obj();
|
||||
assert.equal(obj.test, 2);
|
||||
assert.equal(obj.get(), undefined);
|
||||
@@ -0,0 +1,68 @@
|
||||
"use strict";
|
||||
|
||||
function _possibleConstructorReturn(self, call) { if (call && (typeof call === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
|
||||
|
||||
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
||||
|
||||
function _get(target, property, receiver) { if (typeof Reflect !== "undefined" && Reflect.get) { _get = Reflect.get; } else { _get = function _get(target, property, receiver) { var base = _superPropBase(target, property); if (!base) return; var desc = Object.getOwnPropertyDescriptor(base, property); if (desc.get) { return desc.get.call(receiver); } return desc.value; }; } return _get(target, property, receiver || target); }
|
||||
|
||||
function _superPropBase(object, property) { while (!Object.prototype.hasOwnProperty.call(object, property)) { object = _getPrototypeOf(object); if (object === null) break; } return object; }
|
||||
|
||||
function _getPrototypeOf(o) { _getPrototypeOf = Object.getPrototypeOf || function _getPrototypeOf(o) { return o.__proto__; }; return _getPrototypeOf(o); }
|
||||
|
||||
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
|
||||
|
||||
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
||||
|
||||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
||||
|
||||
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
|
||||
|
||||
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
|
||||
|
||||
let Base =
|
||||
/*#__PURE__*/
|
||||
function () {
|
||||
function Base() {
|
||||
_classCallCheck(this, Base);
|
||||
}
|
||||
|
||||
_createClass(Base, [{
|
||||
key: "test",
|
||||
set: function (v) {
|
||||
throw new Error("not called");
|
||||
}
|
||||
}]);
|
||||
|
||||
return Base;
|
||||
}();
|
||||
|
||||
let Obj =
|
||||
/*#__PURE__*/
|
||||
function (_Base) {
|
||||
_inherits(Obj, _Base);
|
||||
|
||||
function Obj() {
|
||||
_classCallCheck(this, Obj);
|
||||
|
||||
return _possibleConstructorReturn(this, _getPrototypeOf(Obj).apply(this, arguments));
|
||||
}
|
||||
|
||||
_createClass(Obj, [{
|
||||
key: "get",
|
||||
value: function get() {
|
||||
return _get(_getPrototypeOf(Obj.prototype), "test", this);
|
||||
}
|
||||
}]);
|
||||
|
||||
return Obj;
|
||||
}(Base);
|
||||
|
||||
Object.defineProperty(Obj.prototype, 'test', {
|
||||
value: 2,
|
||||
writable: true,
|
||||
configurable: true
|
||||
});
|
||||
const obj = new Obj();
|
||||
assert.equal(obj.test, 2);
|
||||
assert.equal(obj.get(), undefined);
|
||||
3
packages/babel-plugin-transform-classes/test/fixtures/get-set/options.json
vendored
Normal file
3
packages/babel-plugin-transform-classes/test/fixtures/get-set/options.json
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"plugins": ["transform-classes"]
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
"use strict";
|
||||
class Base {
|
||||
}
|
||||
Object.defineProperty(Base.prototype, 'test', {
|
||||
value: 1,
|
||||
writable: true,
|
||||
configurable: true,
|
||||
});
|
||||
|
||||
class Obj extends Base {
|
||||
set() {
|
||||
return super.test = 3;
|
||||
}
|
||||
}
|
||||
Object.defineProperty(Obj.prototype, 'test', {
|
||||
value: 2,
|
||||
writable: true,
|
||||
configurable: true,
|
||||
});
|
||||
|
||||
const obj = new Obj();
|
||||
assert.equal(obj.set(), 3);
|
||||
assert.equal(Base.prototype.test, 1);
|
||||
assert.equal(Obj.prototype.test, 2);
|
||||
assert.equal(obj.test, 3);
|
||||
@@ -0,0 +1,25 @@
|
||||
"use strict";
|
||||
class Base {
|
||||
}
|
||||
Object.defineProperty(Base.prototype, 'test', {
|
||||
value: 1,
|
||||
writable: true,
|
||||
configurable: true,
|
||||
});
|
||||
|
||||
class Obj extends Base {
|
||||
set() {
|
||||
return super.test = 3;
|
||||
}
|
||||
}
|
||||
Object.defineProperty(Obj.prototype, 'test', {
|
||||
value: 2,
|
||||
writable: true,
|
||||
configurable: true,
|
||||
});
|
||||
|
||||
const obj = new Obj();
|
||||
assert.equal(obj.set(), 3);
|
||||
assert.equal(Base.prototype.test, 1);
|
||||
assert.equal(Obj.prototype.test, 2);
|
||||
assert.equal(obj.test, 3);
|
||||
@@ -0,0 +1,67 @@
|
||||
"use strict";
|
||||
|
||||
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
|
||||
|
||||
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
|
||||
|
||||
function _possibleConstructorReturn(self, call) { if (call && (typeof call === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
|
||||
|
||||
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
||||
|
||||
function set(target, property, value, receiver) { if (typeof Reflect !== "undefined" && Reflect.set) { set = Reflect.set; } else { set = function set(target, property, value, receiver) { var base = _superPropBase(target, property); var desc; if (base) { desc = Object.getOwnPropertyDescriptor(base, property); if (desc.set) { desc.set.call(receiver, value); return true; } else if (!desc.writable) { return false; } } desc = Object.getOwnPropertyDescriptor(receiver, property); if (desc) { if (!desc.writable) { return false; } desc.value = value; Object.defineProperty(receiver, property, desc); } else { _defineProperty(receiver, property, value); } return true; }; } return set(target, property, value, receiver); }
|
||||
|
||||
function _set(target, property, value, receiver, isStrict) { const s = set(target, property, value, receiver || target); if (!s && isStrict) { throw new Error('failed to set property'); } return value; }
|
||||
|
||||
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
||||
|
||||
function _superPropBase(object, property) { while (!Object.prototype.hasOwnProperty.call(object, property)) { object = _getPrototypeOf(object); if (object === null) break; } return object; }
|
||||
|
||||
function _getPrototypeOf(o) { _getPrototypeOf = Object.getPrototypeOf || function _getPrototypeOf(o) { return o.__proto__; }; return _getPrototypeOf(o); }
|
||||
|
||||
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
|
||||
|
||||
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
||||
|
||||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
||||
|
||||
let Base = function Base() {
|
||||
_classCallCheck(this, Base);
|
||||
};
|
||||
|
||||
Object.defineProperty(Base.prototype, 'test', {
|
||||
value: 1,
|
||||
writable: true,
|
||||
configurable: true
|
||||
});
|
||||
|
||||
let Obj =
|
||||
/*#__PURE__*/
|
||||
function (_Base) {
|
||||
_inherits(Obj, _Base);
|
||||
|
||||
function Obj() {
|
||||
_classCallCheck(this, Obj);
|
||||
|
||||
return _possibleConstructorReturn(this, _getPrototypeOf(Obj).apply(this, arguments));
|
||||
}
|
||||
|
||||
_createClass(Obj, [{
|
||||
key: "set",
|
||||
value: function set() {
|
||||
return _set(_getPrototypeOf(Obj.prototype), "test", 3, this, true);
|
||||
}
|
||||
}]);
|
||||
|
||||
return Obj;
|
||||
}(Base);
|
||||
|
||||
Object.defineProperty(Obj.prototype, 'test', {
|
||||
value: 2,
|
||||
writable: true,
|
||||
configurable: true
|
||||
});
|
||||
const obj = new Obj();
|
||||
assert.equal(obj.set(), 3);
|
||||
assert.equal(Base.prototype.test, 1);
|
||||
assert.equal(Obj.prototype.test, 2);
|
||||
assert.equal(obj.test, 3);
|
||||
@@ -0,0 +1,28 @@
|
||||
"use strict";
|
||||
let called = false;
|
||||
class Base {
|
||||
get test() {
|
||||
called = true;
|
||||
return 1;
|
||||
}
|
||||
};
|
||||
|
||||
class Obj extends Base {
|
||||
set() {
|
||||
return super.test = 3;
|
||||
}
|
||||
}
|
||||
Object.defineProperty(Obj.prototype, 'test', {
|
||||
value: 2,
|
||||
writable: true,
|
||||
configurable: true,
|
||||
});
|
||||
|
||||
const obj = new Obj();
|
||||
assert.throws(() => {
|
||||
obj.set();
|
||||
});
|
||||
assert.equal(called, false);
|
||||
assert.equal(Base.prototype.test, 1);
|
||||
assert.equal(Obj.prototype.test, 2);
|
||||
assert.equal(obj.test, 2);
|
||||
@@ -0,0 +1,27 @@
|
||||
"use strict";
|
||||
class Base {
|
||||
get test() {
|
||||
return 1;
|
||||
}
|
||||
};
|
||||
|
||||
class Obj extends Base {
|
||||
set() {
|
||||
return super.test = 3;
|
||||
}
|
||||
}
|
||||
Object.defineProperty(Obj.prototype, 'test', {
|
||||
value: 2,
|
||||
writable: true,
|
||||
configurable: true,
|
||||
});
|
||||
|
||||
const obj = new Obj();
|
||||
assert.throws(() => {
|
||||
// this requires helpers to be in file (not external), so they
|
||||
// are in "strict" mode code.
|
||||
obj.set();
|
||||
});
|
||||
assert.equal(Base.prototype.test, 1);
|
||||
assert.equal(Obj.prototype.test, 2);
|
||||
assert.equal(obj.test, 2);
|
||||
@@ -0,0 +1,80 @@
|
||||
"use strict";
|
||||
|
||||
function _possibleConstructorReturn(self, call) { if (call && (typeof call === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
|
||||
|
||||
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
||||
|
||||
function set(target, property, value, receiver) { if (typeof Reflect !== "undefined" && Reflect.set) { set = Reflect.set; } else { set = function set(target, property, value, receiver) { var base = _superPropBase(target, property); var desc; if (base) { desc = Object.getOwnPropertyDescriptor(base, property); if (desc.set) { desc.set.call(receiver, value); return true; } else if (!desc.writable) { return false; } } desc = Object.getOwnPropertyDescriptor(receiver, property); if (desc) { if (!desc.writable) { return false; } desc.value = value; Object.defineProperty(receiver, property, desc); } else { _defineProperty(receiver, property, value); } return true; }; } return set(target, property, value, receiver); }
|
||||
|
||||
function _set(target, property, value, receiver, isStrict) { const s = set(target, property, value, receiver || target); if (!s && isStrict) { throw new Error('failed to set property'); } return value; }
|
||||
|
||||
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
||||
|
||||
function _superPropBase(object, property) { while (!Object.prototype.hasOwnProperty.call(object, property)) { object = _getPrototypeOf(object); if (object === null) break; } return object; }
|
||||
|
||||
function _getPrototypeOf(o) { _getPrototypeOf = Object.getPrototypeOf || function _getPrototypeOf(o) { return o.__proto__; }; return _getPrototypeOf(o); }
|
||||
|
||||
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
|
||||
|
||||
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
||||
|
||||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
||||
|
||||
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
|
||||
|
||||
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
|
||||
|
||||
let Base =
|
||||
/*#__PURE__*/
|
||||
function () {
|
||||
function Base() {
|
||||
_classCallCheck(this, Base);
|
||||
}
|
||||
|
||||
_createClass(Base, [{
|
||||
key: "test",
|
||||
get: function () {
|
||||
return 1;
|
||||
}
|
||||
}]);
|
||||
|
||||
return Base;
|
||||
}();
|
||||
|
||||
;
|
||||
|
||||
let Obj =
|
||||
/*#__PURE__*/
|
||||
function (_Base) {
|
||||
_inherits(Obj, _Base);
|
||||
|
||||
function Obj() {
|
||||
_classCallCheck(this, Obj);
|
||||
|
||||
return _possibleConstructorReturn(this, _getPrototypeOf(Obj).apply(this, arguments));
|
||||
}
|
||||
|
||||
_createClass(Obj, [{
|
||||
key: "set",
|
||||
value: function set() {
|
||||
return _set(_getPrototypeOf(Obj.prototype), "test", 3, this, true);
|
||||
}
|
||||
}]);
|
||||
|
||||
return Obj;
|
||||
}(Base);
|
||||
|
||||
Object.defineProperty(Obj.prototype, 'test', {
|
||||
value: 2,
|
||||
writable: true,
|
||||
configurable: true
|
||||
});
|
||||
const obj = new Obj();
|
||||
assert.throws(() => {
|
||||
// this requires helpers to be in file (not external), so they
|
||||
// are in "strict" mode code.
|
||||
obj.set();
|
||||
});
|
||||
assert.equal(Base.prototype.test, 1);
|
||||
assert.equal(Obj.prototype.test, 2);
|
||||
assert.equal(obj.test, 2);
|
||||
@@ -0,0 +1,20 @@
|
||||
"use strict";
|
||||
class Base {
|
||||
}
|
||||
|
||||
class Obj extends Base {
|
||||
set() {
|
||||
return super.test = 3;
|
||||
}
|
||||
}
|
||||
Object.defineProperty(Obj.prototype, 'test', {
|
||||
value: 2,
|
||||
writable: true,
|
||||
configurable: true,
|
||||
});
|
||||
|
||||
const obj = new Obj();
|
||||
assert.equal(obj.set(), 3);
|
||||
assert.equal(Base.prototype.test, undefined);
|
||||
assert.equal(Obj.prototype.test, 2);
|
||||
assert.equal(obj.test, 3);
|
||||
@@ -0,0 +1,20 @@
|
||||
"use strict";
|
||||
class Base {
|
||||
}
|
||||
|
||||
class Obj extends Base {
|
||||
set() {
|
||||
return super.test = 3;
|
||||
}
|
||||
}
|
||||
Object.defineProperty(Obj.prototype, 'test', {
|
||||
value: 2,
|
||||
writable: true,
|
||||
configurable: true,
|
||||
});
|
||||
|
||||
const obj = new Obj();
|
||||
assert.equal(obj.set(), 3);
|
||||
assert.equal(Base.prototype.test, undefined);
|
||||
assert.equal(Obj.prototype.test, 2);
|
||||
assert.equal(obj.test, 3);
|
||||
@@ -0,0 +1,61 @@
|
||||
"use strict";
|
||||
|
||||
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
|
||||
|
||||
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
|
||||
|
||||
function _possibleConstructorReturn(self, call) { if (call && (typeof call === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
|
||||
|
||||
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
||||
|
||||
function set(target, property, value, receiver) { if (typeof Reflect !== "undefined" && Reflect.set) { set = Reflect.set; } else { set = function set(target, property, value, receiver) { var base = _superPropBase(target, property); var desc; if (base) { desc = Object.getOwnPropertyDescriptor(base, property); if (desc.set) { desc.set.call(receiver, value); return true; } else if (!desc.writable) { return false; } } desc = Object.getOwnPropertyDescriptor(receiver, property); if (desc) { if (!desc.writable) { return false; } desc.value = value; Object.defineProperty(receiver, property, desc); } else { _defineProperty(receiver, property, value); } return true; }; } return set(target, property, value, receiver); }
|
||||
|
||||
function _set(target, property, value, receiver, isStrict) { const s = set(target, property, value, receiver || target); if (!s && isStrict) { throw new Error('failed to set property'); } return value; }
|
||||
|
||||
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
||||
|
||||
function _superPropBase(object, property) { while (!Object.prototype.hasOwnProperty.call(object, property)) { object = _getPrototypeOf(object); if (object === null) break; } return object; }
|
||||
|
||||
function _getPrototypeOf(o) { _getPrototypeOf = Object.getPrototypeOf || function _getPrototypeOf(o) { return o.__proto__; }; return _getPrototypeOf(o); }
|
||||
|
||||
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
|
||||
|
||||
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
||||
|
||||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
||||
|
||||
let Base = function Base() {
|
||||
_classCallCheck(this, Base);
|
||||
};
|
||||
|
||||
let Obj =
|
||||
/*#__PURE__*/
|
||||
function (_Base) {
|
||||
_inherits(Obj, _Base);
|
||||
|
||||
function Obj() {
|
||||
_classCallCheck(this, Obj);
|
||||
|
||||
return _possibleConstructorReturn(this, _getPrototypeOf(Obj).apply(this, arguments));
|
||||
}
|
||||
|
||||
_createClass(Obj, [{
|
||||
key: "set",
|
||||
value: function set() {
|
||||
return _set(_getPrototypeOf(Obj.prototype), "test", 3, this, true);
|
||||
}
|
||||
}]);
|
||||
|
||||
return Obj;
|
||||
}(Base);
|
||||
|
||||
Object.defineProperty(Obj.prototype, 'test', {
|
||||
value: 2,
|
||||
writable: true,
|
||||
configurable: true
|
||||
});
|
||||
const obj = new Obj();
|
||||
assert.equal(obj.set(), 3);
|
||||
assert.equal(Base.prototype.test, undefined);
|
||||
assert.equal(Obj.prototype.test, 2);
|
||||
assert.equal(obj.test, 3);
|
||||
@@ -0,0 +1,21 @@
|
||||
"use strict";
|
||||
class Base {
|
||||
}
|
||||
|
||||
let called = false;
|
||||
class Obj extends Base {
|
||||
get test() {
|
||||
called = true;
|
||||
}
|
||||
|
||||
set() {
|
||||
return super.test = 3;
|
||||
}
|
||||
}
|
||||
|
||||
const obj = new Obj();
|
||||
assert.equal(obj.set(), 3);
|
||||
assert.equal(called, false);
|
||||
assert.equal(Base.prototype.test, undefined);
|
||||
assert.equal(Obj.prototype.test, undefined);
|
||||
assert.equal(obj.test, 3);
|
||||
@@ -0,0 +1,17 @@
|
||||
"use strict";
|
||||
class Base {
|
||||
}
|
||||
|
||||
class Obj extends Base {
|
||||
get test() { }
|
||||
|
||||
set() {
|
||||
return super.test = 3;
|
||||
}
|
||||
}
|
||||
|
||||
const obj = new Obj();
|
||||
assert.equal(obj.set(), 3);
|
||||
assert.equal(Base.prototype.test, undefined);
|
||||
assert.equal(Obj.prototype.test, undefined);
|
||||
assert.equal(obj.test, 3);
|
||||
@@ -0,0 +1,59 @@
|
||||
"use strict";
|
||||
|
||||
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
|
||||
|
||||
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
|
||||
|
||||
function _possibleConstructorReturn(self, call) { if (call && (typeof call === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
|
||||
|
||||
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
||||
|
||||
function set(target, property, value, receiver) { if (typeof Reflect !== "undefined" && Reflect.set) { set = Reflect.set; } else { set = function set(target, property, value, receiver) { var base = _superPropBase(target, property); var desc; if (base) { desc = Object.getOwnPropertyDescriptor(base, property); if (desc.set) { desc.set.call(receiver, value); return true; } else if (!desc.writable) { return false; } } desc = Object.getOwnPropertyDescriptor(receiver, property); if (desc) { if (!desc.writable) { return false; } desc.value = value; Object.defineProperty(receiver, property, desc); } else { _defineProperty(receiver, property, value); } return true; }; } return set(target, property, value, receiver); }
|
||||
|
||||
function _set(target, property, value, receiver, isStrict) { const s = set(target, property, value, receiver || target); if (!s && isStrict) { throw new Error('failed to set property'); } return value; }
|
||||
|
||||
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
||||
|
||||
function _superPropBase(object, property) { while (!Object.prototype.hasOwnProperty.call(object, property)) { object = _getPrototypeOf(object); if (object === null) break; } return object; }
|
||||
|
||||
function _getPrototypeOf(o) { _getPrototypeOf = Object.getPrototypeOf || function _getPrototypeOf(o) { return o.__proto__; }; return _getPrototypeOf(o); }
|
||||
|
||||
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
|
||||
|
||||
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
||||
|
||||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
||||
|
||||
let Base = function Base() {
|
||||
_classCallCheck(this, Base);
|
||||
};
|
||||
|
||||
let Obj =
|
||||
/*#__PURE__*/
|
||||
function (_Base) {
|
||||
_inherits(Obj, _Base);
|
||||
|
||||
function Obj() {
|
||||
_classCallCheck(this, Obj);
|
||||
|
||||
return _possibleConstructorReturn(this, _getPrototypeOf(Obj).apply(this, arguments));
|
||||
}
|
||||
|
||||
_createClass(Obj, [{
|
||||
key: "set",
|
||||
value: function set() {
|
||||
return _set(_getPrototypeOf(Obj.prototype), "test", 3, this, true);
|
||||
}
|
||||
}, {
|
||||
key: "test",
|
||||
get: function () {}
|
||||
}]);
|
||||
|
||||
return Obj;
|
||||
}(Base);
|
||||
|
||||
const obj = new Obj();
|
||||
assert.equal(obj.set(), 3);
|
||||
assert.equal(Base.prototype.test, undefined);
|
||||
assert.equal(Obj.prototype.test, undefined);
|
||||
assert.equal(obj.test, 3);
|
||||
@@ -0,0 +1,15 @@
|
||||
"use strict";
|
||||
class Base {
|
||||
}
|
||||
|
||||
class Obj extends Base {
|
||||
set() {
|
||||
return super.test = 3;
|
||||
}
|
||||
}
|
||||
|
||||
const obj = new Obj();
|
||||
assert.equal(obj.set(), 3);
|
||||
assert.equal(Base.prototype.test, undefined);
|
||||
assert.equal(Obj.prototype.test, undefined);
|
||||
assert.equal(obj.test, 3);
|
||||
@@ -0,0 +1,15 @@
|
||||
"use strict";
|
||||
class Base {
|
||||
}
|
||||
|
||||
class Obj extends Base {
|
||||
set() {
|
||||
return super.test = 3;
|
||||
}
|
||||
}
|
||||
|
||||
const obj = new Obj();
|
||||
assert.equal(obj.set(), 3);
|
||||
assert.equal(Base.prototype.test, undefined);
|
||||
assert.equal(Obj.prototype.test, undefined);
|
||||
assert.equal(obj.test, 3);
|
||||
@@ -0,0 +1,56 @@
|
||||
"use strict";
|
||||
|
||||
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
|
||||
|
||||
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
|
||||
|
||||
function _possibleConstructorReturn(self, call) { if (call && (typeof call === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
|
||||
|
||||
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
||||
|
||||
function set(target, property, value, receiver) { if (typeof Reflect !== "undefined" && Reflect.set) { set = Reflect.set; } else { set = function set(target, property, value, receiver) { var base = _superPropBase(target, property); var desc; if (base) { desc = Object.getOwnPropertyDescriptor(base, property); if (desc.set) { desc.set.call(receiver, value); return true; } else if (!desc.writable) { return false; } } desc = Object.getOwnPropertyDescriptor(receiver, property); if (desc) { if (!desc.writable) { return false; } desc.value = value; Object.defineProperty(receiver, property, desc); } else { _defineProperty(receiver, property, value); } return true; }; } return set(target, property, value, receiver); }
|
||||
|
||||
function _set(target, property, value, receiver, isStrict) { const s = set(target, property, value, receiver || target); if (!s && isStrict) { throw new Error('failed to set property'); } return value; }
|
||||
|
||||
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
||||
|
||||
function _superPropBase(object, property) { while (!Object.prototype.hasOwnProperty.call(object, property)) { object = _getPrototypeOf(object); if (object === null) break; } return object; }
|
||||
|
||||
function _getPrototypeOf(o) { _getPrototypeOf = Object.getPrototypeOf || function _getPrototypeOf(o) { return o.__proto__; }; return _getPrototypeOf(o); }
|
||||
|
||||
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
|
||||
|
||||
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
||||
|
||||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
||||
|
||||
let Base = function Base() {
|
||||
_classCallCheck(this, Base);
|
||||
};
|
||||
|
||||
let Obj =
|
||||
/*#__PURE__*/
|
||||
function (_Base) {
|
||||
_inherits(Obj, _Base);
|
||||
|
||||
function Obj() {
|
||||
_classCallCheck(this, Obj);
|
||||
|
||||
return _possibleConstructorReturn(this, _getPrototypeOf(Obj).apply(this, arguments));
|
||||
}
|
||||
|
||||
_createClass(Obj, [{
|
||||
key: "set",
|
||||
value: function set() {
|
||||
return _set(_getPrototypeOf(Obj.prototype), "test", 3, this, true);
|
||||
}
|
||||
}]);
|
||||
|
||||
return Obj;
|
||||
}(Base);
|
||||
|
||||
const obj = new Obj();
|
||||
assert.equal(obj.set(), 3);
|
||||
assert.equal(Base.prototype.test, undefined);
|
||||
assert.equal(Obj.prototype.test, undefined);
|
||||
assert.equal(obj.test, 3);
|
||||
@@ -0,0 +1,21 @@
|
||||
"use strict";
|
||||
class Base {
|
||||
}
|
||||
|
||||
let value = 2;
|
||||
class Obj extends Base {
|
||||
set test(v) {
|
||||
value = v;
|
||||
}
|
||||
|
||||
set() {
|
||||
return super.test = 3;
|
||||
}
|
||||
}
|
||||
|
||||
const obj = new Obj();
|
||||
assert.equal(obj.set(), 3);
|
||||
assert.equal(Base.prototype.test, undefined);
|
||||
assert.equal(Obj.prototype.test, undefined);
|
||||
assert.equal(value, 2);
|
||||
assert.equal(obj.test, 3);
|
||||
@@ -0,0 +1,22 @@
|
||||
"use strict";
|
||||
class Base {
|
||||
}
|
||||
|
||||
let value = 2;
|
||||
class Obj extends Base {
|
||||
set test(v) {
|
||||
assert.equal(this, obj);
|
||||
value = v;
|
||||
}
|
||||
|
||||
set() {
|
||||
return super.test = 3;
|
||||
}
|
||||
}
|
||||
|
||||
const obj = new Obj();
|
||||
assert.equal(obj.set(), 3);
|
||||
assert.equal(Base.prototype.test, undefined);
|
||||
assert.equal(Obj.prototype.test, undefined);
|
||||
assert.equal(value, 2);
|
||||
assert.equal(obj.test, 3);
|
||||
@@ -0,0 +1,65 @@
|
||||
"use strict";
|
||||
|
||||
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
|
||||
|
||||
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
|
||||
|
||||
function _possibleConstructorReturn(self, call) { if (call && (typeof call === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
|
||||
|
||||
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
||||
|
||||
function set(target, property, value, receiver) { if (typeof Reflect !== "undefined" && Reflect.set) { set = Reflect.set; } else { set = function set(target, property, value, receiver) { var base = _superPropBase(target, property); var desc; if (base) { desc = Object.getOwnPropertyDescriptor(base, property); if (desc.set) { desc.set.call(receiver, value); return true; } else if (!desc.writable) { return false; } } desc = Object.getOwnPropertyDescriptor(receiver, property); if (desc) { if (!desc.writable) { return false; } desc.value = value; Object.defineProperty(receiver, property, desc); } else { _defineProperty(receiver, property, value); } return true; }; } return set(target, property, value, receiver); }
|
||||
|
||||
function _set(target, property, value, receiver, isStrict) { const s = set(target, property, value, receiver || target); if (!s && isStrict) { throw new Error('failed to set property'); } return value; }
|
||||
|
||||
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
||||
|
||||
function _superPropBase(object, property) { while (!Object.prototype.hasOwnProperty.call(object, property)) { object = _getPrototypeOf(object); if (object === null) break; } return object; }
|
||||
|
||||
function _getPrototypeOf(o) { _getPrototypeOf = Object.getPrototypeOf || function _getPrototypeOf(o) { return o.__proto__; }; return _getPrototypeOf(o); }
|
||||
|
||||
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
|
||||
|
||||
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
||||
|
||||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
||||
|
||||
let Base = function Base() {
|
||||
_classCallCheck(this, Base);
|
||||
};
|
||||
|
||||
let value = 2;
|
||||
|
||||
let Obj =
|
||||
/*#__PURE__*/
|
||||
function (_Base) {
|
||||
_inherits(Obj, _Base);
|
||||
|
||||
function Obj() {
|
||||
_classCallCheck(this, Obj);
|
||||
|
||||
return _possibleConstructorReturn(this, _getPrototypeOf(Obj).apply(this, arguments));
|
||||
}
|
||||
|
||||
_createClass(Obj, [{
|
||||
key: "set",
|
||||
value: function set() {
|
||||
return _set(_getPrototypeOf(Obj.prototype), "test", 3, this, true);
|
||||
}
|
||||
}, {
|
||||
key: "test",
|
||||
set: function (v) {
|
||||
assert.equal(this, obj);
|
||||
value = v;
|
||||
}
|
||||
}]);
|
||||
|
||||
return Obj;
|
||||
}(Base);
|
||||
|
||||
const obj = new Obj();
|
||||
assert.equal(obj.set(), 3);
|
||||
assert.equal(Base.prototype.test, undefined);
|
||||
assert.equal(Obj.prototype.test, undefined);
|
||||
assert.equal(value, 2);
|
||||
assert.equal(obj.test, 3);
|
||||
@@ -0,0 +1,25 @@
|
||||
"use strict";
|
||||
let value = 1;
|
||||
class Base {
|
||||
set test(v) {
|
||||
value = v;
|
||||
}
|
||||
}
|
||||
|
||||
class Obj extends Base {
|
||||
set() {
|
||||
return super.test = 3;
|
||||
}
|
||||
}
|
||||
Object.defineProperty(Obj.prototype, 'test', {
|
||||
value: 2,
|
||||
writable: true,
|
||||
configurable: true,
|
||||
});
|
||||
|
||||
const obj = new Obj();
|
||||
assert.equal(obj.set(), 3);
|
||||
assert.equal(value, 3);
|
||||
assert.equal(Base.prototype.test, undefined);
|
||||
assert.equal(Obj.prototype.test, 2);
|
||||
assert.equal(obj.test, 2);
|
||||
@@ -0,0 +1,25 @@
|
||||
"use strict";
|
||||
let value = 1;
|
||||
class Base {
|
||||
set test(v) {
|
||||
value = v;
|
||||
}
|
||||
}
|
||||
|
||||
class Obj extends Base {
|
||||
set() {
|
||||
return super.test = 3;
|
||||
}
|
||||
}
|
||||
Object.defineProperty(Obj.prototype, 'test', {
|
||||
value: 2,
|
||||
writable: true,
|
||||
configurable: true,
|
||||
});
|
||||
|
||||
const obj = new Obj();
|
||||
assert.equal(obj.set(), 3);
|
||||
assert.equal(value, 3);
|
||||
assert.equal(Base.prototype.test, undefined);
|
||||
assert.equal(Obj.prototype.test, 2);
|
||||
assert.equal(obj.test, 2);
|
||||
@@ -0,0 +1,77 @@
|
||||
"use strict";
|
||||
|
||||
function _possibleConstructorReturn(self, call) { if (call && (typeof call === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
|
||||
|
||||
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
||||
|
||||
function set(target, property, value, receiver) { if (typeof Reflect !== "undefined" && Reflect.set) { set = Reflect.set; } else { set = function set(target, property, value, receiver) { var base = _superPropBase(target, property); var desc; if (base) { desc = Object.getOwnPropertyDescriptor(base, property); if (desc.set) { desc.set.call(receiver, value); return true; } else if (!desc.writable) { return false; } } desc = Object.getOwnPropertyDescriptor(receiver, property); if (desc) { if (!desc.writable) { return false; } desc.value = value; Object.defineProperty(receiver, property, desc); } else { _defineProperty(receiver, property, value); } return true; }; } return set(target, property, value, receiver); }
|
||||
|
||||
function _set(target, property, value, receiver, isStrict) { const s = set(target, property, value, receiver || target); if (!s && isStrict) { throw new Error('failed to set property'); } return value; }
|
||||
|
||||
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
||||
|
||||
function _superPropBase(object, property) { while (!Object.prototype.hasOwnProperty.call(object, property)) { object = _getPrototypeOf(object); if (object === null) break; } return object; }
|
||||
|
||||
function _getPrototypeOf(o) { _getPrototypeOf = Object.getPrototypeOf || function _getPrototypeOf(o) { return o.__proto__; }; return _getPrototypeOf(o); }
|
||||
|
||||
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
|
||||
|
||||
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
||||
|
||||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
||||
|
||||
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
|
||||
|
||||
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
|
||||
|
||||
let value = 1;
|
||||
|
||||
let Base =
|
||||
/*#__PURE__*/
|
||||
function () {
|
||||
function Base() {
|
||||
_classCallCheck(this, Base);
|
||||
}
|
||||
|
||||
_createClass(Base, [{
|
||||
key: "test",
|
||||
set: function (v) {
|
||||
value = v;
|
||||
}
|
||||
}]);
|
||||
|
||||
return Base;
|
||||
}();
|
||||
|
||||
let Obj =
|
||||
/*#__PURE__*/
|
||||
function (_Base) {
|
||||
_inherits(Obj, _Base);
|
||||
|
||||
function Obj() {
|
||||
_classCallCheck(this, Obj);
|
||||
|
||||
return _possibleConstructorReturn(this, _getPrototypeOf(Obj).apply(this, arguments));
|
||||
}
|
||||
|
||||
_createClass(Obj, [{
|
||||
key: "set",
|
||||
value: function set() {
|
||||
return _set(_getPrototypeOf(Obj.prototype), "test", 3, this, true);
|
||||
}
|
||||
}]);
|
||||
|
||||
return Obj;
|
||||
}(Base);
|
||||
|
||||
Object.defineProperty(Obj.prototype, 'test', {
|
||||
value: 2,
|
||||
writable: true,
|
||||
configurable: true
|
||||
});
|
||||
const obj = new Obj();
|
||||
assert.equal(obj.set(), 3);
|
||||
assert.equal(value, 3);
|
||||
assert.equal(Base.prototype.test, undefined);
|
||||
assert.equal(Obj.prototype.test, 2);
|
||||
assert.equal(obj.test, 2);
|
||||
22
packages/babel-plugin-transform-classes/test/fixtures/regression/5769/exec.js
vendored
Normal file
22
packages/babel-plugin-transform-classes/test/fixtures/regression/5769/exec.js
vendored
Normal file
@@ -0,0 +1,22 @@
|
||||
class Point {
|
||||
getX() {
|
||||
assert.equal(this.x, 3); // C
|
||||
}
|
||||
}
|
||||
|
||||
class ColorPoint extends Point {
|
||||
constructor() {
|
||||
super();
|
||||
this.x = 2;
|
||||
super.x = 3;
|
||||
assert.equal(this.x, 3) // A
|
||||
assert.equal(super.x, undefined) // B
|
||||
}
|
||||
|
||||
m() {
|
||||
this.getX()
|
||||
}
|
||||
}
|
||||
|
||||
const cp = new ColorPoint();
|
||||
cp.m();
|
||||
22
packages/babel-plugin-transform-classes/test/fixtures/regression/5769/input.js
vendored
Normal file
22
packages/babel-plugin-transform-classes/test/fixtures/regression/5769/input.js
vendored
Normal file
@@ -0,0 +1,22 @@
|
||||
class Point {
|
||||
getX() {
|
||||
assert.equal(this.x, 3); // C
|
||||
}
|
||||
}
|
||||
|
||||
class ColorPoint extends Point {
|
||||
constructor() {
|
||||
super();
|
||||
this.x = 2;
|
||||
super.x = 3;
|
||||
assert.equal(this.x, 3) // A
|
||||
assert.equal(super.x, undefined) // B
|
||||
}
|
||||
|
||||
m() {
|
||||
this.getX()
|
||||
}
|
||||
}
|
||||
|
||||
const cp = new ColorPoint();
|
||||
cp.m();
|
||||
46
packages/babel-plugin-transform-classes/test/fixtures/regression/5769/output.js
vendored
Normal file
46
packages/babel-plugin-transform-classes/test/fixtures/regression/5769/output.js
vendored
Normal file
@@ -0,0 +1,46 @@
|
||||
var Point =
|
||||
/*#__PURE__*/
|
||||
function () {
|
||||
function Point() {
|
||||
babelHelpers.classCallCheck(this, Point);
|
||||
}
|
||||
|
||||
babelHelpers.createClass(Point, [{
|
||||
key: "getX",
|
||||
value: function getX() {
|
||||
assert.equal(this.x, 3); // C
|
||||
}
|
||||
}]);
|
||||
return Point;
|
||||
}();
|
||||
|
||||
var ColorPoint =
|
||||
/*#__PURE__*/
|
||||
function (_Point) {
|
||||
babelHelpers.inherits(ColorPoint, _Point);
|
||||
|
||||
function ColorPoint() {
|
||||
var _this;
|
||||
|
||||
babelHelpers.classCallCheck(this, ColorPoint);
|
||||
_this = babelHelpers.possibleConstructorReturn(this, babelHelpers.getPrototypeOf(ColorPoint).call(this));
|
||||
_this.x = 2;
|
||||
babelHelpers.set(babelHelpers.getPrototypeOf(ColorPoint.prototype), "x", 3, _this, true);
|
||||
assert.equal(_this.x, 3); // A
|
||||
|
||||
assert.equal(babelHelpers.get(babelHelpers.getPrototypeOf(ColorPoint.prototype), "x", babelHelpers.assertThisInitialized(_this)), undefined); // B
|
||||
|
||||
return _this;
|
||||
}
|
||||
|
||||
babelHelpers.createClass(ColorPoint, [{
|
||||
key: "m",
|
||||
value: function m() {
|
||||
this.getX();
|
||||
}
|
||||
}]);
|
||||
return ColorPoint;
|
||||
}(Point);
|
||||
|
||||
var cp = new ColorPoint();
|
||||
cp.m();
|
||||
@@ -6,7 +6,9 @@ function _inherits(subClass, superClass) { if (typeof superClass !== "function"
|
||||
|
||||
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
||||
|
||||
function _get(object, property, receiver) { if (object === null) object = Function.prototype; var desc = Object.getOwnPropertyDescriptor(object, property); if (desc === undefined) { var parent = _getPrototypeOf(object); if (parent === null) { return undefined; } else { return _get(parent, property, receiver); } } else if ("value" in desc) { return desc.value; } else { var getter = desc.get; if (getter === undefined) { return undefined; } return getter.call(receiver); } }
|
||||
function _get(target, property, receiver) { if (typeof Reflect !== "undefined" && Reflect.get) { _get = Reflect.get; } else { _get = function _get(target, property, receiver) { var base = _superPropBase(target, property); if (!base) return; var desc = Object.getOwnPropertyDescriptor(base, property); if (desc.get) { return desc.get.call(receiver); } return desc.value; }; } return _get(target, property, receiver || target); }
|
||||
|
||||
function _superPropBase(object, property) { while (!Object.prototype.hasOwnProperty.call(object, property)) { object = _getPrototypeOf(object); if (object === null) break; } return object; }
|
||||
|
||||
function _getPrototypeOf(o) { _getPrototypeOf = Object.getPrototypeOf || function _getPrototypeOf(o) { return o.__proto__; }; return _getPrototypeOf(o); }
|
||||
|
||||
|
||||
@@ -6,7 +6,9 @@ function _inherits(subClass, superClass) { if (typeof superClass !== "function"
|
||||
|
||||
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
||||
|
||||
function _get(object, property, receiver) { if (object === null) object = Function.prototype; var desc = Object.getOwnPropertyDescriptor(object, property); if (desc === undefined) { var parent = _getPrototypeOf(object); if (parent === null) { return undefined; } else { return _get(parent, property, receiver); } } else if ("value" in desc) { return desc.value; } else { var getter = desc.get; if (getter === undefined) { return undefined; } return getter.call(receiver); } }
|
||||
function _get(target, property, receiver) { if (typeof Reflect !== "undefined" && Reflect.get) { _get = Reflect.get; } else { _get = function _get(target, property, receiver) { var base = _superPropBase(target, property); if (!base) return; var desc = Object.getOwnPropertyDescriptor(base, property); if (desc.get) { return desc.get.call(receiver); } return desc.value; }; } return _get(target, property, receiver || target); }
|
||||
|
||||
function _superPropBase(object, property) { while (!Object.prototype.hasOwnProperty.call(object, property)) { object = _getPrototypeOf(object); if (object === null) break; } return object; }
|
||||
|
||||
function _getPrototypeOf(o) { _getPrototypeOf = Object.getPrototypeOf || function _getPrototypeOf(o) { return o.__proto__; }; return _getPrototypeOf(o); }
|
||||
|
||||
|
||||
Reference in New Issue
Block a user