Skip to content

Commit

Permalink
3.2.1
Browse files Browse the repository at this point in the history
  • Loading branch information
cherifGsoul committed May 24, 2019
1 parent e569775 commit 7f0a292
Show file tree
Hide file tree
Showing 3 changed files with 406 additions and 0 deletions.
82 changes: 82 additions & 0 deletions dist/amd/can-construct-super.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
/*can-construct-super@3.2.0#can-construct-super*/
define([
'require',
'exports',
'module',
'can-reflect',
'can-construct'
], function (require, exports, module) {
(function (global, require, exports, module) {
'use strict';
var canReflect = require('can-reflect');
var Construct = require('can-construct');
var hasOwnProperty = Object.prototype.hasOwnProperty;
var isFunction = function (val) {
return typeof val === 'function';
}, fnTest = /xyz/.test(function () {
return this.xyz;
}) ? /\b_super\b/ : /.*/, getset = [
'get',
'set'
], getSuper = function (base, name, fn) {
return function () {
var hasExistingValue = false;
var existingValue;
var prototype = getPrototypeOf(this);
var existingPrototypeValue = prototype._super;
if (hasOwnProperty.call(this, '_super')) {
hasExistingValue = true;
existingValue = this._super;
delete this._super;
}
prototype._super = base[name];
var ret = fn.apply(this, arguments);
prototype._super = existingPrototypeValue;
if (hasExistingValue) {
this._super = existingValue;
}
return ret;
};
};
Construct._defineProperty = function (addTo, base, name, descriptor) {
var _super = Object.getOwnPropertyDescriptor(base, name);
if (_super) {
canReflect.each(getset, function (method) {
if (isFunction(_super[method]) && isFunction(descriptor[method])) {
descriptor[method] = getSuper(_super, method, descriptor[method]);
} else if (!isFunction(descriptor[method])) {
descriptor[method] = _super[method];
}
});
}
Object.defineProperty(addTo, name, descriptor);
};
var getPrototypeOf = Object.getPrototypeOf || function (obj) {
return obj.__proto__;
};
var getPropertyDescriptor = Object.getPropertyDescriptor || function (subject, name) {
if (name in subject) {
var pd = Object.getOwnPropertyDescriptor(subject, name);
var proto = getPrototypeOf(subject);
while (pd === undefined && proto !== null) {
pd = Object.getOwnPropertyDescriptor(proto, name);
proto = getPrototypeOf(proto);
}
return pd;
}
};
Construct._overwrite = function (addTo, base, name, val) {
var baseDescriptor = getPropertyDescriptor(base, name);
var baseValue = baseDescriptor && baseDescriptor.value;
Object.defineProperty(addTo, name, {
value: isFunction(val) && isFunction(baseValue) && fnTest.test(val) ? getSuper(base, name, val) : val,
configurable: true,
enumerable: true,
writable: true
});
};
module.exports = Construct;
}(function () {
return this;
}(), require, exports, module));
});
70 changes: 70 additions & 0 deletions dist/cjs/can-construct-super.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/*can-construct-super@3.2.0#can-construct-super*/
'use strict';
var canReflect = require('can-reflect');
var Construct = require('can-construct');
var hasOwnProperty = Object.prototype.hasOwnProperty;
var isFunction = function (val) {
return typeof val === 'function';
}, fnTest = /xyz/.test(function () {
return this.xyz;
}) ? /\b_super\b/ : /.*/, getset = [
'get',
'set'
], getSuper = function (base, name, fn) {
return function () {
var hasExistingValue = false;
var existingValue;
var prototype = getPrototypeOf(this);
var existingPrototypeValue = prototype._super;
if (hasOwnProperty.call(this, '_super')) {
hasExistingValue = true;
existingValue = this._super;
delete this._super;
}
prototype._super = base[name];
var ret = fn.apply(this, arguments);
prototype._super = existingPrototypeValue;
if (hasExistingValue) {
this._super = existingValue;
}
return ret;
};
};
Construct._defineProperty = function (addTo, base, name, descriptor) {
var _super = Object.getOwnPropertyDescriptor(base, name);
if (_super) {
canReflect.each(getset, function (method) {
if (isFunction(_super[method]) && isFunction(descriptor[method])) {
descriptor[method] = getSuper(_super, method, descriptor[method]);
} else if (!isFunction(descriptor[method])) {
descriptor[method] = _super[method];
}
});
}
Object.defineProperty(addTo, name, descriptor);
};
var getPrototypeOf = Object.getPrototypeOf || function (obj) {
return obj.__proto__;
};
var getPropertyDescriptor = Object.getPropertyDescriptor || function (subject, name) {
if (name in subject) {
var pd = Object.getOwnPropertyDescriptor(subject, name);
var proto = getPrototypeOf(subject);
while (pd === undefined && proto !== null) {
pd = Object.getOwnPropertyDescriptor(proto, name);
proto = getPrototypeOf(proto);
}
return pd;
}
};
Construct._overwrite = function (addTo, base, name, val) {
var baseDescriptor = getPropertyDescriptor(base, name);
var baseValue = baseDescriptor && baseDescriptor.value;
Object.defineProperty(addTo, name, {
value: isFunction(val) && isFunction(baseValue) && fnTest.test(val) ? getSuper(base, name, val) : val,
configurable: true,
enumerable: true,
writable: true
});
};
module.exports = Construct;
Loading

0 comments on commit 7f0a292

Please sign in to comment.