@dmail/uneval
Advanced tools
Comparing version 5.1.0 to 5.2.0
@@ -1,2 +0,779 @@ | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),Object.defineProperty(Object.prototype,"__global__",{get:function(){return this},configurable:!0});var t=__global__;function e(t){return(e="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}function r(t){return function(t){if(Array.isArray(t)){for(var e=0,r=new Array(t.length);e<t.length;e++)r[e]=t[e];return r}}(t)||function(t){if(Symbol.iterator in Object(t)||"[object Arguments]"===Object.prototype.toString.call(t))return Array.from(t)}(t)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance")}()}delete Object.prototype.__global__,t.globalThis=t;var n=function(t){if(null===t)return!1;var r=e(t);return"object"===r||"function"===r},o=new WeakMap,i=new Map,c=function(t){return o.get(t)},a=function(t){!function t(e,c){if(n(e)){if(o.has(e))return;o.set(e,c);var a=function(n){var o;try{o=Object.getOwnPropertyDescriptor(e,n)}catch(t){if("SecurityError"===t.name)return;throw t}if("value"in o){var i=o.value;t(i,r(c).concat([n]))}};Object.getOwnPropertyNames(e).forEach(function(t){return a(t)}),Object.getOwnPropertySymbols(e).forEach(function(t){return a(t)})}i.set(e,c)}(t,[])};"object"===("undefined"==typeof window?"undefined":e(window))&&a(window),"object"===("undefined"==typeof global?"undefined":e(global))&&a(global);var f=function(t,e){var o=e.functionAllowed,i={},a=[],f=function t(e){var i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:[];if(!n(e)){var f=s(e);if(void 0!==f)return f;var g=j(e);return a[g]=u(e),g}if("function"==typeof Promise&&e instanceof Promise)throw new Error(d({path:i}));if("function"==typeof WeakSet&&e instanceof WeakSet)throw new Error(b({path:i}));if("function"==typeof WeakMap&&e instanceof WeakMap)throw new Error(h({path:i}));if("function"==typeof e&&!o)throw new Error(m({path:i}));var E=y(e);if(void 0!==E)return E;var k=j(e),D=c(e);if(D)return a[k]=l(D),k;var S={};Object.getOwnPropertyNames(e).forEach(function(n){var c=Object.getOwnPropertyDescriptor(e,n),a={};Object.keys(c).forEach(function(e){var f=c[e];if("set"===e&&f&&!o)throw new Error(w({path:i,propertyName:n}));if("get"===e&&f&&!o)throw new Error(O({path:i,propertyName:n}));var u=t(e,r(i).concat(['["'.concat(n,'"]'),"[[propertyDescriptor:".concat(e,"]]")])),p=t(f,r(i).concat(['["'.concat(n,'"]'),"[[propertyDescriptor:".concat(e,"]]")]));a[u]=p});var f=t(n,r(i).concat([n]));S[f]=a});var I={};Object.getOwnPropertySymbols(e).forEach(function(n){var o=Object.getOwnPropertyDescriptor(e,n),c={};Object.keys(o).forEach(function(e){var a=t(e,r(i).concat(["[".concat(n.toString(),"]"),"[[propertyDescriptor:".concat(e,"]]")])),f=t(o[e],r(i).concat(["[".concat(n.toString(),"]"),"[[propertyDescriptor:".concat(e,"]]")]));c[a]=f});var a=t(n,r(i).concat([n]));I[a]=c});var x=p(e,i),A=Object.isExtensible(e);return a[k]=v({propertiesDescription:S,symbolsDescription:I,methodsDescription:x,extensible:A}),k},p=function(t,e){var n={};if("function"==typeof Set&&t instanceof Set){var o=[];t.forEach(function(t,n){var i=f(t,r(e).concat(["[[SetEntryValue]]",n]));o.push([i])}),n[f("add")]=o}if("function"==typeof Map&&t instanceof Map){var i=[];t.forEach(function(t,n){var o=f(n,r(e).concat(["[[MapEntryKey]]",n])),c=f(t,r(e).concat(["[[MapEntryValue]]",t]));i.push([o,c])}),n[f("set")]=i}return n},s=function(t){return Object.keys(i).find(function(e){var r=i[e];return!!Object.is(t,r)||t===r})},y=function(t){return Object.keys(i).find(function(e){var r=i[e];return t===r})},j=function(t){var e=D();return i[e]=t,e},k=-1,D=function(){var t=String(parseInt(k)+1);return k=t,t},S=f(t);return a.slice().forEach(function(t,e){if("composite"===t.type){var o=i[e];if("function"==typeof o){var u=D();return a[u]={type:"primitive",value:o},void(t.valueOfIdentifier=u)}if(o instanceof RegExp){var p=D();return a[p]={type:"primitive",value:o},void(t.valueOfIdentifier=p)}t.valueOfIdentifier=function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:[];if(t instanceof Array)return f(t.length,r(e).concat(["length"]));if("valueOf"in t!=0&&"function"==typeof t.valueOf){var o=t.valueOf();if(!n(o))return f(o,r(e).concat(["valueOf()"]));if(o!==t)throw new Error(g())}}(o);var s=Object.getPrototypeOf(o);t.prototypeIdentifier=function(t){if(null===t)return f(t);var e=y(t);if(void 0!==e)return e;var r=j(t),n=c(t);if(n)return a[r]=l(n),r;throw new Error(E({prototypeValue:t}))}(s)}}),{recipeArray:a,mainIdentifier:S}},u=function(t){return"symbol"===e(t)?p(t):s(t)},p=function(t){var e=Symbol.keyFor(t);if(void 0!==e)return y(e);var r,n=(r=t,i.get(r));if(!n)throw new Error(j({symbol:t}));return l(n)},s=function(t){return{type:"primitive",value:t}},l=function(t){return{type:"global-reference",path:t}},y=function(t){return{type:"global-symbol",key:t}},v=function(t){return{type:"composite",prototypeIdentifier:t.prototypeIdentifier,valueOfIdentifier:t.valueOfIdentifier,propertiesDescription:t.propertiesDescription,symbolsDescription:t.symbolsDescription,methodsDescription:t.methodsDescription,extensible:t.extensible}},d=function(t){var e=t.path;return 0===e.length?"promise are not supported.":"promise are not supported.\npromise found at: ".concat(e.join(""))},b=function(t){var e=t.path;return 0===e.length?"weakSet are not supported.":"weakSet are not supported.\nweakSet found at: ".concat(e.join(""))},h=function(t){var e=t.path;return 0===e.length?"weakMap are not supported.":"weakMap are not supported.\nweakMap found at: ".concat(e.join(""))},m=function(t){var e=t.path;return 0===e.length?"function are not allowed.":"function are not allowed.\nfunction found at: ".concat(e.join(""))},O=function(t){var e=t.path,r=t.propertyName;return"property getter are not allowed.\ngetter found on property: ".concat(r,"\nat: ").concat(e.join(""))},w=function(t){var e=t.path,r=t.propertyName;return"property setter are not allowed.\nsetter found on property: ".concat(r,"\nat: ").concat(e.join(""))},g=function(){return"valueOf() must return a primitive of the object itself."},j=function(t){var e=t.symbol;return"symbol must be global, like Symbol.iterator, or created using Symbol.for().\nsymbol: ".concat(e.toString())},E=function(){return"prototype must be global, like Object.prototype, or somewhere in the value."},k=function(t){var n=t.recipeArray,o=t.mainIdentifier,i="object"===("undefined"==typeof window?"undefined":e(window))?window:global,c={},a=function(t){return t.value},f=function(t){var e=t.key;return Symbol.for(e)},u=function(t){for(var e=t.path,r=i,n=0;n<e.length;){var o=e[n];if(n++,o in r==!1)throw new Error(y({path:e,index:n}));r=r[o]}return r},p=function(t){var e=t.prototypeIdentifier,r=t.valueOfIdentifier;if(void 0===e)return c[r];var n=c[e];if(null===n)return Object.create(null);var o=n.constructor;return o===Object?Object.create(n):void 0===r?new o:new o(c[r])};n.forEach(function(t,e){var r=function(t){return"primitive"===t.type?a(t):"global-symbol"===t.type?f(t):"global-reference"===t.type?u(t):p(t)}(t);c[e]=r});var s=function(t,e){var n=t.propertiesDescription,o=t.symbolsDescription,i=t.methodsDescription,a=t.extensible,f=void 0===a||a,u=c[e];n&&Object.keys(n).forEach(function(t){var e=c[t],r=n[t];l(u,e,r)}),o&&Object.keys(o).forEach(function(t){var e=c[t],r=o[t];l(u,e,r)}),i&&Object.keys(i).forEach(function(t){var e=c[t];i[t].forEach(function(t){var n=t.map(function(t){return c[t]});u[e].apply(u,r(n))})}),f||Object.preventExtensions(u)},l=function(t,e,r){var n=Object.getOwnPropertyDescriptor(t,e);if(!n||!1!==n.configurable){var o={};Object.keys(r).forEach(function(t){var e=r[t],n=c[t],i=c[e];o[n]=i}),Object.defineProperty(t,e,o)}};n.forEach(function(t,e){!function(t,e){"composite"===t.type&&s(t,e)}(t,e)});var y=function(t){var e=t.path,r=t.index;return"value not found for path.\npart not found: ".concat(e[r],"\npath: ").concat(e.join(","))};return c[o]},D=function(t){for(var e=String(t),r=0,n=e.length,o="";r<n;){var i=e[r];o+='"'===i||"'"===i||"\\"===i?"\\".concat(i):"\n"===i?"\\n":"\r"===i?"\\r":"\u2028"===i?"\\u2028":"\u2029"===i?"\\u2029":i,r++}return o},S=function(t){var r=function(t){return t instanceof Array?n(t):t instanceof RegExp?t.toString():null===t?"null":"object"===e(t)?o(t):"string"==typeof t?'"'.concat(D(t),'"'):Object.is(t,-0)?"-0":String(t)},n=function(t){var e=t.map(function(t){return r(t)});return"[".concat(e.join(","),"]")},o=function(t){var e=Object.keys(t).map(function(e){return'"'.concat(D(e),'":').concat(r(t[e]))});return"{".concat(e.join(","),"}")};return r(t)};exports.uneval=function(t){var e=(arguments.length>1&&void 0!==arguments[1]?arguments[1]:{}).functionAllowed,r=function(t){var e=t.recipeArray,r=t.mainIdentifier;return e.forEach(function(t){"composite"===t.type&&(void 0===t.prototypeIdentifier&&delete t.prototypeIdentifier,void 0===t.valueOfIdentifier&&delete t.valueOfIdentifier,!0===t.extensible&&delete t.extensible,0===Object.keys(t.propertiesDescription).length&&delete t.propertiesDescription,0===Object.keys(t.symbolsDescription).length&&delete t.symbolsDescription,0===Object.keys(t.methodsDescription).length&&delete t.methodsDescription)}),{recipeArray:e,mainIdentifier:r}}(function(t){var e=t.recipeArray,r=t.mainIdentifier,n=function(t,r){for(var n=t;"composite"===n.type;){var o=n.prototypeIdentifier;if(void 0===o)break;if(r(n=e[o],o))return o}},o=e.slice();o.sort(function(t,r){var o=t.type,i=r.type;if("composite"===o&&"composite"===i){if(n(t,function(t){return t===r}))return 1;if(n(r,function(e){return e===t}))return-1}if(o!==i){if("composite"===o)return 1;if("composite"===i)return-1}return e.indexOf(t)<e.indexOf(r)?-1:1});var i={};e.forEach(function(t,e){var r=o.indexOf(t);e!==r&&(i[e]=r)});var c=function(t){return t in i?i[t]:t},a=function(t){var e={};return Object.keys(t).forEach(function(r){e[c(r)]=c(t[r])}),e};return o.forEach(function(t){if("composite"===t.type){t.valueOfIdentifier=c(t.valueOfIdentifier),t.prototypeIdentifier=c(t.prototypeIdentifier);var e=t.propertiesDescription,r={};Object.keys(e).forEach(function(t){r[c(t)]=a(e[t])}),t.propertiesDescription=r;var n=t.symbolsDescription,o={};Object.keys(n).forEach(function(t){o[c(t)]=a(n[t])}),t.symbolsDescription=o;var i=t.methodsDescription,f={};Object.keys(i).forEach(function(t){var e=i[t].map(function(t){return t.map(function(t){return c(t)})});f[c(t)]=e}),t.methodsDescription=f}}),{recipeArray:o,mainIdentifier:c(r)}}(f(t,{functionAllowed:void 0!==e&&e}))),n=k.toString(),o=S(r);return"(".concat(n,")(").concat(o,")")}; | ||
'use strict'; | ||
Object.defineProperty(exports, '__esModule', { value: true }); | ||
// https://mathiasbynens.be/notes/globalthis | ||
// eslint-disable-next-line no-extend-native | ||
Object.defineProperty(Object.prototype, "__global__", { | ||
get: function get() { | ||
return this; | ||
}, | ||
configurable: true | ||
}); // eslint-disable-next-line no-undef | ||
var globalThis = __global__; | ||
delete Object.prototype.__global__; | ||
globalThis.globalThis = globalThis; | ||
function _typeof(obj) { | ||
if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { | ||
_typeof = function (obj) { | ||
return typeof obj; | ||
}; | ||
} else { | ||
_typeof = function (obj) { | ||
return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; | ||
}; | ||
} | ||
return _typeof(obj); | ||
} | ||
function _toConsumableArray(arr) { | ||
return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _nonIterableSpread(); | ||
} | ||
function _arrayWithoutHoles(arr) { | ||
if (Array.isArray(arr)) { | ||
for (var i = 0, arr2 = new Array(arr.length); i < arr.length; i++) arr2[i] = arr[i]; | ||
return arr2; | ||
} | ||
} | ||
function _iterableToArray(iter) { | ||
if (Symbol.iterator in Object(iter) || Object.prototype.toString.call(iter) === "[object Arguments]") return Array.from(iter); | ||
} | ||
function _nonIterableSpread() { | ||
throw new TypeError("Invalid attempt to spread non-iterable instance"); | ||
} | ||
// https://developer.mozilla.org/en-US/docs/Glossary/Primitive | ||
var isComposite = function isComposite(value) { | ||
if (value === null) return false; | ||
var type = _typeof(value); | ||
if (type === "object") return true; | ||
if (type === "function") return true; | ||
return false; | ||
}; | ||
var compositeWellKnownMap = new WeakMap(); | ||
var primitiveWellKnownMap = new Map(); | ||
var getCompositeGlobalPath = function getCompositeGlobalPath(value) { | ||
return compositeWellKnownMap.get(value); | ||
}; | ||
var getPrimitiveGlobalPath = function getPrimitiveGlobalPath(value) { | ||
return primitiveWellKnownMap.get(value); | ||
}; | ||
var visitGlobalObject = function visitGlobalObject(value) { | ||
var visitValue = function visitValue(value, path) { | ||
if (isComposite(value)) { | ||
if (compositeWellKnownMap.has(value)) return; // prevent infinite recursion | ||
compositeWellKnownMap.set(value, path); | ||
var visitProperty = function visitProperty(property) { | ||
var descriptor; | ||
try { | ||
descriptor = Object.getOwnPropertyDescriptor(value, property); | ||
} catch (e) { | ||
if (e.name === "SecurityError") { | ||
return; | ||
} | ||
throw e; | ||
} // do not trigger getter/setter | ||
if ("value" in descriptor) { | ||
var propertyValue = descriptor.value; | ||
visitValue(propertyValue, _toConsumableArray(path).concat([property])); | ||
} | ||
}; | ||
Object.getOwnPropertyNames(value).forEach(function (name) { | ||
return visitProperty(name); | ||
}); | ||
Object.getOwnPropertySymbols(value).forEach(function (symbol) { | ||
return visitProperty(symbol); | ||
}); | ||
} | ||
primitiveWellKnownMap.set(value, path); | ||
return; | ||
}; | ||
visitValue(value, []); | ||
}; | ||
if ((typeof window === "undefined" ? "undefined" : _typeof(window)) === "object") visitGlobalObject(window); | ||
if ((typeof global === "undefined" ? "undefined" : _typeof(global)) === "object") visitGlobalObject(global); | ||
var decompose = function decompose(mainValue, _ref) { | ||
var functionAllowed = _ref.functionAllowed; | ||
var valueMap = {}; | ||
var recipeArray = []; | ||
var valueToIdentifier = function valueToIdentifier(value) { | ||
var path = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : []; | ||
if (!isComposite(value)) { | ||
var _existingIdentifier = identifierForPrimitive(value); | ||
if (_existingIdentifier !== undefined) return _existingIdentifier; | ||
var _identifier = identifierForNewValue(value); | ||
recipeArray[_identifier] = primitiveToRecipe(value); | ||
return _identifier; | ||
} | ||
if (typeof Promise === "function" && value instanceof Promise) throw new Error(createPromiseAreNotSupportedMessage({ | ||
path: path | ||
})); | ||
if (typeof WeakSet === "function" && value instanceof WeakSet) throw new Error(createWeakSetAreNotSupportedMessage({ | ||
path: path | ||
})); | ||
if (typeof WeakMap === "function" && value instanceof WeakMap) throw new Error(createWeakMapAreNotSupportedMessage({ | ||
path: path | ||
})); | ||
if (typeof value === "function" && !functionAllowed) throw new Error(createForbiddenFunctionMessage({ | ||
path: path | ||
})); | ||
var existingIdentifier = identifierForComposite(value); | ||
if (existingIdentifier !== undefined) return existingIdentifier; | ||
var identifier = identifierForNewValue(value); | ||
var compositeGlobalPath = getCompositeGlobalPath(value); | ||
if (compositeGlobalPath) { | ||
recipeArray[identifier] = createGlobalReferenceRecipe(compositeGlobalPath); | ||
return identifier; | ||
} | ||
var propertiesDescription = {}; | ||
Object.getOwnPropertyNames(value).forEach(function (propertyName) { | ||
var propertyDescriptor = Object.getOwnPropertyDescriptor(value, propertyName); | ||
var propertyDescription = {}; | ||
Object.keys(propertyDescriptor).forEach(function (descriptorName) { | ||
var descriptorValue = propertyDescriptor[descriptorName]; | ||
if (descriptorName === "set" && descriptorValue && !functionAllowed) throw new Error(createForbiddenPropertySetterMessage({ | ||
path: path, | ||
propertyName: propertyName | ||
})); | ||
if (descriptorName === "get" && descriptorValue && !functionAllowed) throw new Error(createForbiddenPropertyGetterMessage({ | ||
path: path, | ||
propertyName: propertyName | ||
})); | ||
var descriptorNameIdentifier = valueToIdentifier(descriptorName, _toConsumableArray(path).concat(["[\"".concat(propertyName, "\"]"), "[[propertyDescriptor:".concat(descriptorName, "]]")])); | ||
var descriptorValueIdentifier = valueToIdentifier(descriptorValue, _toConsumableArray(path).concat(["[\"".concat(propertyName, "\"]"), "[[propertyDescriptor:".concat(descriptorName, "]]")])); | ||
propertyDescription[descriptorNameIdentifier] = descriptorValueIdentifier; | ||
}); | ||
var propertyNameIdentifier = valueToIdentifier(propertyName, _toConsumableArray(path).concat([propertyName])); | ||
propertiesDescription[propertyNameIdentifier] = propertyDescription; | ||
}); | ||
var symbolsDescription = {}; | ||
Object.getOwnPropertySymbols(value).forEach(function (symbol) { | ||
var propertyDescriptor = Object.getOwnPropertyDescriptor(value, symbol); | ||
var propertyDescription = {}; | ||
Object.keys(propertyDescriptor).forEach(function (descriptorName) { | ||
var descriptorNameIdentifier = valueToIdentifier(descriptorName, _toConsumableArray(path).concat(["[".concat(symbol.toString(), "]"), "[[propertyDescriptor:".concat(descriptorName, "]]")])); | ||
var descriptorValueIdentifier = valueToIdentifier(propertyDescriptor[descriptorName], _toConsumableArray(path).concat(["[".concat(symbol.toString(), "]"), "[[propertyDescriptor:".concat(descriptorName, "]]")])); | ||
propertyDescription[descriptorNameIdentifier] = descriptorValueIdentifier; | ||
}); | ||
var symbolIdentifier = valueToIdentifier(symbol, _toConsumableArray(path).concat([symbol])); | ||
symbolsDescription[symbolIdentifier] = propertyDescription; | ||
}); | ||
var methodsDescription = computeMethodsDescription(value, path); | ||
var extensible = Object.isExtensible(value); | ||
recipeArray[identifier] = createCompositeRecipe({ | ||
propertiesDescription: propertiesDescription, | ||
symbolsDescription: symbolsDescription, | ||
methodsDescription: methodsDescription, | ||
extensible: extensible | ||
}); | ||
return identifier; | ||
}; | ||
var computeMethodsDescription = function computeMethodsDescription(value, path) { | ||
var methodsDescription = {}; | ||
if (typeof Set === "function" && value instanceof Set) { | ||
var addCallArray = []; | ||
value.forEach(function (entryValue, index) { | ||
var entryValueIdentifier = valueToIdentifier(entryValue, _toConsumableArray(path).concat(["[[SetEntryValue]]", index])); | ||
addCallArray.push([entryValueIdentifier]); | ||
}); | ||
methodsDescription[valueToIdentifier("add")] = addCallArray; | ||
} | ||
if (typeof Map === "function" && value instanceof Map) { | ||
var setCallArray = []; | ||
value.forEach(function (entryValue, entryKey) { | ||
var entryKeyIdentifier = valueToIdentifier(entryKey, _toConsumableArray(path).concat(["[[MapEntryKey]]", entryKey])); | ||
var entryValueIdentifier = valueToIdentifier(entryValue, _toConsumableArray(path).concat(["[[MapEntryValue]]", entryValue])); | ||
setCallArray.push([entryKeyIdentifier, entryValueIdentifier]); | ||
}); | ||
methodsDescription[valueToIdentifier("set")] = setCallArray; | ||
} | ||
return methodsDescription; | ||
}; | ||
var identifierForPrimitive = function identifierForPrimitive(value) { | ||
return Object.keys(valueMap).find(function (existingIdentifier) { | ||
var existingValue = valueMap[existingIdentifier]; | ||
if (Object.is(value, existingValue)) return true; | ||
return value === existingValue; | ||
}); | ||
}; | ||
var identifierForComposite = function identifierForComposite(value) { | ||
return Object.keys(valueMap).find(function (existingIdentifier) { | ||
var existingValue = valueMap[existingIdentifier]; | ||
return value === existingValue; | ||
}); | ||
}; | ||
var identifierForNewValue = function identifierForNewValue(value) { | ||
var identifier = nextIdentifier(); | ||
valueMap[identifier] = value; | ||
return identifier; | ||
}; | ||
var currentIdentifier = -1; | ||
var nextIdentifier = function nextIdentifier() { | ||
var identifier = String(parseInt(currentIdentifier) + 1); | ||
currentIdentifier = identifier; | ||
return identifier; | ||
}; | ||
var mainIdentifier = valueToIdentifier(mainValue); // prototype, important to keep after the whole structure was visited | ||
// so that we discover if any prototype is part of the value | ||
var prototypeValueToIdentifier = function prototypeValueToIdentifier(prototypeValue) { | ||
// prototype is null | ||
if (prototypeValue === null) return valueToIdentifier(prototypeValue); // prototype found somewhere already | ||
var prototypeExistingIdentifier = identifierForComposite(prototypeValue); | ||
if (prototypeExistingIdentifier !== undefined) return prototypeExistingIdentifier; // mark prototype as visited | ||
var prototypeIdentifier = identifierForNewValue(prototypeValue); // prototype is a global reference ? | ||
var prototypeGlobalPath = getCompositeGlobalPath(prototypeValue); | ||
if (prototypeGlobalPath) { | ||
recipeArray[prototypeIdentifier] = createGlobalReferenceRecipe(prototypeGlobalPath); | ||
return prototypeIdentifier; | ||
} // otherwise prototype is unknown | ||
throw new Error(createUnknownPrototypeMessage({ | ||
prototypeValue: prototypeValue | ||
})); | ||
}; | ||
var identifierForValueOf = function identifierForValueOf(value) { | ||
var path = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : []; | ||
if (value instanceof Array) return valueToIdentifier(value.length, _toConsumableArray(path).concat(["length"])); | ||
if ("valueOf" in value === false) return undefined; | ||
if (typeof value.valueOf !== "function") return undefined; | ||
var valueOfReturnValue = value.valueOf(); | ||
if (!isComposite(valueOfReturnValue)) return valueToIdentifier(valueOfReturnValue, _toConsumableArray(path).concat(["valueOf()"])); | ||
if (valueOfReturnValue === value) return undefined; | ||
throw new Error(createUnexpectedValueOfReturnValueMessage()); | ||
}; | ||
recipeArray.slice().forEach(function (recipe, index) { | ||
if (recipe.type === "composite") { | ||
var value = valueMap[index]; | ||
if (typeof value === "function") { | ||
var valueOfIdentifier = nextIdentifier(); | ||
recipeArray[valueOfIdentifier] = { | ||
type: "primitive", | ||
value: value | ||
}; | ||
recipe.valueOfIdentifier = valueOfIdentifier; | ||
return; | ||
} | ||
if (value instanceof RegExp) { | ||
var _valueOfIdentifier = nextIdentifier(); | ||
recipeArray[_valueOfIdentifier] = { | ||
type: "primitive", | ||
value: value | ||
}; | ||
recipe.valueOfIdentifier = _valueOfIdentifier; | ||
return; | ||
} // valueOf, mandatory to uneval new Date(10) for instance. | ||
recipe.valueOfIdentifier = identifierForValueOf(value); | ||
var prototypeValue = Object.getPrototypeOf(value); | ||
recipe.prototypeIdentifier = prototypeValueToIdentifier(prototypeValue); | ||
} | ||
}); | ||
return { | ||
recipeArray: recipeArray, | ||
mainIdentifier: mainIdentifier | ||
}; | ||
}; | ||
var primitiveToRecipe = function primitiveToRecipe(value) { | ||
if (_typeof(value) === "symbol") return symbolToRecipe(value); | ||
return createPimitiveRecipe(value); | ||
}; | ||
var symbolToRecipe = function symbolToRecipe(symbol) { | ||
var globalSymbolKey = Symbol.keyFor(symbol); | ||
if (globalSymbolKey !== undefined) return createGlobalSymbolRecipe(globalSymbolKey); | ||
var symbolGlobalPath = getPrimitiveGlobalPath(symbol); | ||
if (!symbolGlobalPath) throw new Error(createUnknownSymbolMessage({ | ||
symbol: symbol | ||
})); | ||
return createGlobalReferenceRecipe(symbolGlobalPath); | ||
}; | ||
var createPimitiveRecipe = function createPimitiveRecipe(value) { | ||
return { | ||
type: "primitive", | ||
value: value | ||
}; | ||
}; | ||
var createGlobalReferenceRecipe = function createGlobalReferenceRecipe(path) { | ||
var recipe = { | ||
type: "global-reference", | ||
path: path | ||
}; | ||
return recipe; | ||
}; | ||
var createGlobalSymbolRecipe = function createGlobalSymbolRecipe(key) { | ||
return { | ||
type: "global-symbol", | ||
key: key | ||
}; | ||
}; | ||
var createCompositeRecipe = function createCompositeRecipe(_ref2) { | ||
var prototypeIdentifier = _ref2.prototypeIdentifier, | ||
valueOfIdentifier = _ref2.valueOfIdentifier, | ||
propertiesDescription = _ref2.propertiesDescription, | ||
symbolsDescription = _ref2.symbolsDescription, | ||
methodsDescription = _ref2.methodsDescription, | ||
extensible = _ref2.extensible; | ||
return { | ||
type: "composite", | ||
prototypeIdentifier: prototypeIdentifier, | ||
valueOfIdentifier: valueOfIdentifier, | ||
propertiesDescription: propertiesDescription, | ||
symbolsDescription: symbolsDescription, | ||
methodsDescription: methodsDescription, | ||
extensible: extensible | ||
}; | ||
}; | ||
var createPromiseAreNotSupportedMessage = function createPromiseAreNotSupportedMessage(_ref3) { | ||
var path = _ref3.path; | ||
if (path.length === 0) return "promise are not supported."; | ||
return "promise are not supported.\npromise found at: ".concat(path.join("")); | ||
}; | ||
var createWeakSetAreNotSupportedMessage = function createWeakSetAreNotSupportedMessage(_ref4) { | ||
var path = _ref4.path; | ||
if (path.length === 0) return "weakSet are not supported."; | ||
return "weakSet are not supported.\nweakSet found at: ".concat(path.join("")); | ||
}; | ||
var createWeakMapAreNotSupportedMessage = function createWeakMapAreNotSupportedMessage(_ref5) { | ||
var path = _ref5.path; | ||
if (path.length === 0) return "weakMap are not supported."; | ||
return "weakMap are not supported.\nweakMap found at: ".concat(path.join("")); | ||
}; | ||
var createForbiddenFunctionMessage = function createForbiddenFunctionMessage(_ref6) { | ||
var path = _ref6.path; | ||
if (path.length === 0) return "function are not allowed."; | ||
return "function are not allowed.\nfunction found at: ".concat(path.join("")); | ||
}; | ||
var createForbiddenPropertyGetterMessage = function createForbiddenPropertyGetterMessage(_ref7) { | ||
var path = _ref7.path, | ||
propertyName = _ref7.propertyName; | ||
return "property getter are not allowed.\ngetter found on property: ".concat(propertyName, "\nat: ").concat(path.join("")); | ||
}; | ||
var createForbiddenPropertySetterMessage = function createForbiddenPropertySetterMessage(_ref8) { | ||
var path = _ref8.path, | ||
propertyName = _ref8.propertyName; | ||
return "property setter are not allowed.\nsetter found on property: ".concat(propertyName, "\nat: ").concat(path.join("")); | ||
}; | ||
var createUnexpectedValueOfReturnValueMessage = function createUnexpectedValueOfReturnValueMessage() { | ||
return "valueOf() must return a primitive of the object itself."; | ||
}; | ||
var createUnknownSymbolMessage = function createUnknownSymbolMessage(_ref9) { | ||
var symbol = _ref9.symbol; | ||
return "symbol must be global, like Symbol.iterator, or created using Symbol.for().\nsymbol: ".concat(symbol.toString()); | ||
}; | ||
var createUnknownPrototypeMessage = function createUnknownPrototypeMessage() { | ||
return "prototype must be global, like Object.prototype, or somewhere in the value."; | ||
}; | ||
// be carefull because this function is mutating recipe objects inside the recipeArray. | ||
// this is not an issue because each recipe object is not accessible from the outside | ||
// when used internally by uneval | ||
var compositionToRecipe = function compositionToRecipe(_ref) { | ||
var recipeArray = _ref.recipeArray, | ||
mainIdentifier = _ref.mainIdentifier; | ||
var findInRecipePrototypeChain = function findInRecipePrototypeChain(recipe, callback) { | ||
var currentRecipe = recipe; // eslint-disable-next-line no-constant-condition | ||
while (true) { | ||
if (currentRecipe.type !== "composite") break; | ||
var prototypeIdentifier = currentRecipe.prototypeIdentifier; | ||
if (prototypeIdentifier === undefined) break; | ||
currentRecipe = recipeArray[prototypeIdentifier]; | ||
if (callback(currentRecipe, prototypeIdentifier)) return prototypeIdentifier; | ||
} | ||
return undefined; | ||
}; | ||
var recipeArrayOrdered = recipeArray.slice(); | ||
recipeArrayOrdered.sort(function (leftRecipe, rightRecipe) { | ||
var leftType = leftRecipe.type; | ||
var rightType = rightRecipe.type; | ||
if (leftType === "composite" && rightType === "composite") { | ||
var rightRecipeIsInLeftRecipePrototypeChain = findInRecipePrototypeChain(leftRecipe, function (recipeCandidate) { | ||
return recipeCandidate === rightRecipe; | ||
}); // if left recipe requires right recipe, left must be after right | ||
if (rightRecipeIsInLeftRecipePrototypeChain) return 1; | ||
var leftRecipeIsInRightRecipePrototypeChain = findInRecipePrototypeChain(rightRecipe, function (recipeCandidate) { | ||
return recipeCandidate === leftRecipe; | ||
}); // if right recipe requires left recipe, right must be after left | ||
if (leftRecipeIsInRightRecipePrototypeChain) return -1; | ||
} | ||
if (leftType !== rightType) { | ||
// if left is a composite, left must be after right | ||
if (leftType === "composite") return 1; // if right is a composite, right must be after left | ||
if (rightType === "composite") return -1; | ||
} | ||
var leftIndex = recipeArray.indexOf(leftRecipe); | ||
var rightIndex = recipeArray.indexOf(rightRecipe); // left was before right, don't change that | ||
if (leftIndex < rightIndex) return -1; // right was after left, don't change that | ||
return 1; | ||
}); | ||
var moves = {}; | ||
recipeArray.forEach(function (recipe, index) { | ||
var indexOrdered = recipeArrayOrdered.indexOf(recipe); | ||
if (index !== indexOrdered) { | ||
moves[index] = indexOrdered; | ||
} | ||
}); | ||
var remapIdentifier = function remapIdentifier(identifier) { | ||
if (identifier in moves) return moves[identifier]; | ||
return identifier; | ||
}; | ||
var remapPropertyDescription = function remapPropertyDescription(propertyDescription) { | ||
var remappedPropertyDescription = {}; | ||
Object.keys(propertyDescription).forEach(function (descriptorNameIdentifier) { | ||
remappedPropertyDescription[remapIdentifier(descriptorNameIdentifier)] = remapIdentifier(propertyDescription[descriptorNameIdentifier]); | ||
}); | ||
return remappedPropertyDescription; | ||
}; | ||
recipeArrayOrdered.forEach(function (recipe) { | ||
if (recipe.type !== "composite") return; | ||
recipe.valueOfIdentifier = remapIdentifier(recipe.valueOfIdentifier); | ||
recipe.prototypeIdentifier = remapIdentifier(recipe.prototypeIdentifier); | ||
var propertiesDescription = recipe.propertiesDescription; | ||
var remappedPropertiesDescription = {}; | ||
Object.keys(propertiesDescription).forEach(function (propertyNameIdentifier) { | ||
remappedPropertiesDescription[remapIdentifier(propertyNameIdentifier)] = remapPropertyDescription(propertiesDescription[propertyNameIdentifier]); | ||
}); | ||
recipe.propertiesDescription = remappedPropertiesDescription; | ||
var symbolsDescription = recipe.symbolsDescription; | ||
var remappedSymbolsDescription = {}; | ||
Object.keys(symbolsDescription).forEach(function (symbolIdentifier) { | ||
remappedSymbolsDescription[remapIdentifier(symbolIdentifier)] = remapPropertyDescription(symbolsDescription[symbolIdentifier]); | ||
}); | ||
recipe.symbolsDescription = remappedSymbolsDescription; | ||
var methodsDescription = recipe.methodsDescription; | ||
var remappedMethodsDescription = {}; | ||
Object.keys(methodsDescription).forEach(function (methodNameIdentifier) { | ||
var callsDescription = methodsDescription[methodNameIdentifier]; | ||
var remappedCallsDescription = callsDescription.map(function (argumentIdentifiers) { | ||
return argumentIdentifiers.map(function (argumentIdentifier) { | ||
return remapIdentifier(argumentIdentifier); | ||
}); | ||
}); | ||
remappedMethodsDescription[remapIdentifier(methodNameIdentifier)] = remappedCallsDescription; | ||
}); | ||
recipe.methodsDescription = remappedMethodsDescription; | ||
}); | ||
return { | ||
recipeArray: recipeArrayOrdered, | ||
mainIdentifier: remapIdentifier(mainIdentifier) | ||
}; | ||
}; | ||
// This function would return recipes that does not contain default values | ||
// for instance we'll consider extensible as false by default | ||
// empty propertiesMap and symbolsMap can be omitted | ||
// it would decrease the size of value string representation a bit | ||
var minifyRecipe = function minifyRecipe(_ref) { | ||
var recipeArray = _ref.recipeArray, | ||
mainIdentifier = _ref.mainIdentifier; | ||
recipeArray.forEach(function (recipe) { | ||
if (recipe.type === "composite") { | ||
if (recipe.prototypeIdentifier === undefined) delete recipe.prototypeIdentifier; | ||
if (recipe.valueOfIdentifier === undefined) delete recipe.valueOfIdentifier; | ||
if (recipe.extensible === true) delete recipe.extensible; | ||
if (Object.keys(recipe.propertiesDescription).length === 0) delete recipe.propertiesDescription; | ||
if (Object.keys(recipe.symbolsDescription).length === 0) delete recipe.symbolsDescription; | ||
if (Object.keys(recipe.methodsDescription).length === 0) delete recipe.methodsDescription; | ||
} | ||
}); | ||
return { | ||
recipeArray: recipeArray, | ||
mainIdentifier: mainIdentifier | ||
}; | ||
}; | ||
function recompose(param) { | ||
var recipeArray = param.recipeArray; | ||
var mainIdentifier = param.mainIdentifier; | ||
var globalObject = (typeof window === "undefined" ? "undefined" : _typeof(window)) === "object" ? window : global; | ||
var materials = {}; | ||
function setupMaterial(recipe) { | ||
if (recipe.type === "primitive") return setupPrimitiveMaterial(recipe); | ||
if (recipe.type === "global-symbol") return setupGlobalSymbolMaterial(recipe); | ||
if (recipe.type === "global-reference") return setupGlobalReferenceMaterial(recipe); | ||
return setupCompositeMaterial(recipe); | ||
} | ||
function setupPrimitiveMaterial(recipe) { | ||
return recipe.value; | ||
} | ||
function setupGlobalSymbolMaterial(recipe) { | ||
return Symbol.for(recipe.key); | ||
} | ||
function setupGlobalReferenceMaterial(recipe) { | ||
var path = recipe.path; | ||
var currentValue = globalObject; | ||
var i = 0; | ||
while (i < path.length) { | ||
var part = path[i]; | ||
i++; | ||
if (part in currentValue === false) throw new Error(createValueNotFoundErrorMessage({ | ||
path: path, | ||
index: i | ||
})); | ||
currentValue = currentValue[part]; | ||
} | ||
return currentValue; | ||
} | ||
function setupCompositeMaterial(recipe) { | ||
var prototypeIdentifier = recipe.prototypeIdentifier; | ||
var valueOfIdentifier = recipe.valueOfIdentifier; // regexp and function | ||
if (prototypeIdentifier === undefined) return materials[valueOfIdentifier]; | ||
var prototypeValue = materials[prototypeIdentifier]; | ||
if (prototypeValue === null) return Object.create(null); | ||
var Constructor = prototypeValue.constructor; | ||
if (Constructor === Object) return Object.create(prototypeValue); | ||
if (valueOfIdentifier === undefined) return new Constructor(); | ||
var valueOfValue = materials[valueOfIdentifier]; | ||
return new Constructor(valueOfValue); | ||
} | ||
recipeArray.forEach(function (recipe, index) { | ||
var value = setupMaterial(recipe); | ||
materials[index] = value; | ||
}); | ||
function followRecipe(recipe, index) { | ||
if (recipe.type === "composite") followCompositeRecipe(recipe, index); | ||
} | ||
function followCompositeRecipe(recipe, index) { | ||
var composite = materials[index]; | ||
var propertiesDescription = recipe.propertiesDescription; | ||
if (propertiesDescription) { | ||
Object.keys(propertiesDescription).forEach(function (propertyNameIdentifier) { | ||
var propertyName = materials[propertyNameIdentifier]; | ||
var description = propertiesDescription[propertyNameIdentifier]; | ||
defineProperty(composite, propertyName, description); | ||
}); | ||
} | ||
var symbolsDescription = recipe.symbolsDescription; | ||
if (symbolsDescription) { | ||
Object.keys(symbolsDescription).forEach(function (symbolIdentifier) { | ||
var symbol = materials[symbolIdentifier]; | ||
var description = symbolsDescription[symbolIdentifier]; | ||
defineProperty(composite, symbol, description); | ||
}); | ||
} | ||
var methodsDescription = recipe.methodsDescription; | ||
if (methodsDescription) { | ||
Object.keys(methodsDescription).forEach(function (methodNameIdentifier) { | ||
var methodName = materials[methodNameIdentifier]; | ||
var calls = methodsDescription[methodNameIdentifier]; | ||
calls.forEach(function (argumentIdentifiers) { | ||
var argumentValues = argumentIdentifiers.map(function (argumentIdentifier) { | ||
return materials[argumentIdentifier]; | ||
}); | ||
composite[methodName].apply(composite, _toConsumableArray(argumentValues)); | ||
}); | ||
}); | ||
} | ||
var extensible = recipe.extensible || true; | ||
if (!extensible) Object.preventExtensions(composite); | ||
} | ||
function defineProperty(composite, propertyNameOrSymbol, propertyDescription) { | ||
var currentDescriptor = Object.getOwnPropertyDescriptor(composite, propertyNameOrSymbol); | ||
if (currentDescriptor && currentDescriptor.configurable === false) return; | ||
var descriptor = {}; | ||
Object.keys(propertyDescription).forEach(function (descriptorNameIdentifier) { | ||
var descriptorValueIdentifier = propertyDescription[descriptorNameIdentifier]; | ||
var descriptorName = materials[descriptorNameIdentifier]; | ||
var descriptorValue = materials[descriptorValueIdentifier]; | ||
descriptor[descriptorName] = descriptorValue; | ||
}); | ||
Object.defineProperty(composite, propertyNameOrSymbol, descriptor); | ||
} | ||
recipeArray.forEach(function (recipe, index) { | ||
followRecipe(recipe, index); | ||
}); | ||
function createValueNotFoundErrorMessage(data) { | ||
var path = data.path; | ||
var index = data.index; | ||
var message = "value not found for path."; | ||
message += "\n"; // eslint-disable-next-line prefer-template | ||
message += "part not found: " + path[index]; | ||
message += "\n"; // eslint-disable-next-line prefer-template | ||
message += "path: " + path.join(""); | ||
return message; | ||
} | ||
return materials[mainIdentifier]; | ||
} | ||
// https://github.com/joliss/js-string-escape/blob/master/index.js | ||
// http://javascript.crockford.com/remedial.html | ||
var escapeString = function escapeString(value) { | ||
var string = String(value); | ||
var i = 0; | ||
var j = string.length; | ||
var escapedString = ""; | ||
while (i < j) { | ||
var char = string[i]; | ||
var escapedChar = void 0; | ||
if (char === '"' || char === "'" || char === "\\") { | ||
escapedChar = "\\".concat(char); | ||
} else if (char === "\n") { | ||
escapedChar = "\\n"; | ||
} else if (char === "\r") { | ||
escapedChar = "\\r"; | ||
} else if (char === "\u2028") { | ||
escapedChar = "\\u2028"; | ||
} else if (char === "\u2029") { | ||
escapedChar = "\\u2029"; | ||
} else { | ||
escapedChar = char; | ||
} | ||
escapedString += escapedChar; | ||
i++; | ||
} | ||
return escapedString; | ||
}; | ||
var uneval = function uneval(value) { | ||
var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}, | ||
_ref$functionAllowed = _ref.functionAllowed, | ||
functionAllowed = _ref$functionAllowed === void 0 ? false : _ref$functionAllowed; | ||
var composition = decompose(value, { | ||
functionAllowed: functionAllowed | ||
}); | ||
var recipe = compositionToRecipe(composition); | ||
var recipeMinified = minifyRecipe(recipe); | ||
var recomposeSource = recompose.toString(); | ||
var recomposeParamSouce = recipeToSource(recipeMinified); | ||
return "(".concat(recomposeSource, ")(").concat(recomposeParamSouce, ")"); | ||
}; | ||
var recipeToSource = function recipeToSource(recipe) { | ||
var valueToSource = function valueToSource(value) { | ||
if (value instanceof Array) return arrayToSource(value); | ||
if (value instanceof RegExp) return value.toString(); | ||
if (value === null) return "null"; | ||
if (_typeof(value) === "object") return objectToSource(value); | ||
if (typeof value === "string") return "\"".concat(escapeString(value), "\""); | ||
if (Object.is(value, -0)) return "-0"; | ||
return String(value); | ||
}; | ||
var arrayToSource = function arrayToSource(array) { | ||
var valueSourceArray = array.map(function (value) { | ||
return valueToSource(value); | ||
}); | ||
return "[".concat(valueSourceArray.join(","), "]"); | ||
}; | ||
var objectToSource = function objectToSource(object) { | ||
var propertiesSources = Object.keys(object).map(function (key) { | ||
return "\"".concat(escapeString(key), "\":").concat(valueToSource(object[key])); | ||
}); | ||
return "{".concat(propertiesSources.join(","), "}"); | ||
}; | ||
return valueToSource(recipe); | ||
}; | ||
exports.uneval = uneval; | ||
//# sourceMappingURL=main.js.map |
@@ -1,548 +0,781 @@ | ||
var __dmail_uneval__ = function (t) { | ||
"use strict"; | ||
var __dmail_uneval__ = function (exports) { | ||
'use strict'; // https://mathiasbynens.be/notes/globalthis | ||
// eslint-disable-next-line no-extend-native | ||
Object.defineProperty(Object.prototype, "__global__", { | ||
get: function () { | ||
get: function get() { | ||
return this; | ||
}, | ||
configurable: !0 | ||
}); | ||
var e = __global__; | ||
configurable: true | ||
}); // eslint-disable-next-line no-undef | ||
function r(t) { | ||
return (r = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (t) { | ||
return typeof t; | ||
} : function (t) { | ||
return t && "function" == typeof Symbol && t.constructor === Symbol && t !== Symbol.prototype ? "symbol" : typeof t; | ||
})(t); | ||
var globalThis = __global__; | ||
delete Object.prototype.__global__; | ||
globalThis.globalThis = globalThis; | ||
function _typeof(obj) { | ||
if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { | ||
_typeof = function (obj) { | ||
return typeof obj; | ||
}; | ||
} else { | ||
_typeof = function (obj) { | ||
return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; | ||
}; | ||
} | ||
return _typeof(obj); | ||
} | ||
function n(t) { | ||
return function (t) { | ||
if (Array.isArray(t)) { | ||
for (var e = 0, r = new Array(t.length); e < t.length; e++) r[e] = t[e]; | ||
function _toConsumableArray(arr) { | ||
return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _nonIterableSpread(); | ||
} | ||
return r; | ||
} | ||
}(t) || function (t) { | ||
if (Symbol.iterator in Object(t) || "[object Arguments]" === Object.prototype.toString.call(t)) return Array.from(t); | ||
}(t) || function () { | ||
throw new TypeError("Invalid attempt to spread non-iterable instance"); | ||
}(); | ||
function _arrayWithoutHoles(arr) { | ||
if (Array.isArray(arr)) { | ||
for (var i = 0, arr2 = new Array(arr.length); i < arr.length; i++) arr2[i] = arr[i]; | ||
return arr2; | ||
} | ||
} | ||
delete Object.prototype.__global__, e.globalThis = e; | ||
function _iterableToArray(iter) { | ||
if (Symbol.iterator in Object(iter) || Object.prototype.toString.call(iter) === "[object Arguments]") return Array.from(iter); | ||
} | ||
var o = function (t) { | ||
if (null === t) return !1; | ||
var e = r(t); | ||
return "object" === e || "function" === e; | ||
}, | ||
i = new WeakMap(), | ||
c = new Map(), | ||
a = function (t) { | ||
return i.get(t); | ||
}, | ||
f = function (t) { | ||
!function t(e, r) { | ||
if (o(e)) { | ||
if (i.has(e)) return; | ||
i.set(e, r); | ||
function _nonIterableSpread() { | ||
throw new TypeError("Invalid attempt to spread non-iterable instance"); | ||
} // https://developer.mozilla.org/en-US/docs/Glossary/Primitive | ||
var a = function (o) { | ||
var i; | ||
var isComposite = function isComposite(value) { | ||
if (value === null) return false; | ||
var type = _typeof(value); | ||
if (type === "object") return true; | ||
if (type === "function") return true; | ||
return false; | ||
}; | ||
var compositeWellKnownMap = new WeakMap(); | ||
var primitiveWellKnownMap = new Map(); | ||
var getCompositeGlobalPath = function getCompositeGlobalPath(value) { | ||
return compositeWellKnownMap.get(value); | ||
}; | ||
var getPrimitiveGlobalPath = function getPrimitiveGlobalPath(value) { | ||
return primitiveWellKnownMap.get(value); | ||
}; | ||
var visitGlobalObject = function visitGlobalObject(value) { | ||
var visitValue = function visitValue(value, path) { | ||
if (isComposite(value)) { | ||
if (compositeWellKnownMap.has(value)) return; // prevent infinite recursion | ||
compositeWellKnownMap.set(value, path); | ||
var visitProperty = function visitProperty(property) { | ||
var descriptor; | ||
try { | ||
i = Object.getOwnPropertyDescriptor(e, o); | ||
} catch (t) { | ||
if ("SecurityError" === t.name) return; | ||
throw t; | ||
} | ||
descriptor = Object.getOwnPropertyDescriptor(value, property); | ||
} catch (e) { | ||
if (e.name === "SecurityError") { | ||
return; | ||
} | ||
if ("value" in i) { | ||
var c = i.value; | ||
t(c, n(r).concat([o])); | ||
throw e; | ||
} // do not trigger getter/setter | ||
if ("value" in descriptor) { | ||
var propertyValue = descriptor.value; | ||
visitValue(propertyValue, _toConsumableArray(path).concat([property])); | ||
} | ||
}; | ||
Object.getOwnPropertyNames(e).forEach(function (t) { | ||
return a(t); | ||
}), Object.getOwnPropertySymbols(e).forEach(function (t) { | ||
return a(t); | ||
Object.getOwnPropertyNames(value).forEach(function (name) { | ||
return visitProperty(name); | ||
}); | ||
Object.getOwnPropertySymbols(value).forEach(function (symbol) { | ||
return visitProperty(symbol); | ||
}); | ||
} | ||
c.set(e, r); | ||
}(t, []); | ||
primitiveWellKnownMap.set(value, path); | ||
return; | ||
}; | ||
visitValue(value, []); | ||
}; | ||
"object" === ("undefined" == typeof window ? "undefined" : r(window)) && f(window), "object" === ("undefined" == typeof global ? "undefined" : r(global)) && f(global); | ||
if ((typeof window === "undefined" ? "undefined" : _typeof(window)) === "object") visitGlobalObject(window); | ||
if ((typeof global === "undefined" ? "undefined" : _typeof(global)) === "object") visitGlobalObject(global); | ||
var u = function (t, e) { | ||
var r = e.functionAllowed, | ||
i = {}, | ||
c = [], | ||
f = function t(e) { | ||
var i = arguments.length > 1 && void 0 !== arguments[1] ? arguments[1] : []; | ||
var decompose = function decompose(mainValue, _ref) { | ||
var functionAllowed = _ref.functionAllowed; | ||
var valueMap = {}; | ||
var recipeArray = []; | ||
if (!o(e)) { | ||
var f = s(e); | ||
if (void 0 !== f) return f; | ||
var j = v(e); | ||
return c[j] = p(e), j; | ||
var valueToIdentifier = function valueToIdentifier(value) { | ||
var path = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : []; | ||
if (!isComposite(value)) { | ||
var _existingIdentifier = identifierForPrimitive(value); | ||
if (_existingIdentifier !== undefined) return _existingIdentifier; | ||
var _identifier = identifierForNewValue(value); | ||
recipeArray[_identifier] = primitiveToRecipe(value); | ||
return _identifier; | ||
} | ||
if ("function" == typeof Promise && e instanceof Promise) throw new Error(b({ | ||
path: i | ||
if (typeof Promise === "function" && value instanceof Promise) throw new Error(createPromiseAreNotSupportedMessage({ | ||
path: path | ||
})); | ||
if ("function" == typeof WeakSet && e instanceof WeakSet) throw new Error(h({ | ||
path: i | ||
if (typeof WeakSet === "function" && value instanceof WeakSet) throw new Error(createWeakSetAreNotSupportedMessage({ | ||
path: path | ||
})); | ||
if ("function" == typeof WeakMap && e instanceof WeakMap) throw new Error(m({ | ||
path: i | ||
if (typeof WeakMap === "function" && value instanceof WeakMap) throw new Error(createWeakMapAreNotSupportedMessage({ | ||
path: path | ||
})); | ||
if ("function" == typeof e && !r) throw new Error(O({ | ||
path: i | ||
if (typeof value === "function" && !functionAllowed) throw new Error(createForbiddenFunctionMessage({ | ||
path: path | ||
})); | ||
var E = l(e); | ||
if (void 0 !== E) return E; | ||
var k = v(e), | ||
D = a(e); | ||
if (D) return c[k] = y(D), k; | ||
var S = {}; | ||
Object.getOwnPropertyNames(e).forEach(function (o) { | ||
var c = Object.getOwnPropertyDescriptor(e, o), | ||
a = {}; | ||
Object.keys(c).forEach(function (e) { | ||
var f = c[e]; | ||
if ("set" === e && f && !r) throw new Error(g({ | ||
path: i, | ||
propertyName: o | ||
var existingIdentifier = identifierForComposite(value); | ||
if (existingIdentifier !== undefined) return existingIdentifier; | ||
var identifier = identifierForNewValue(value); | ||
var compositeGlobalPath = getCompositeGlobalPath(value); | ||
if (compositeGlobalPath) { | ||
recipeArray[identifier] = createGlobalReferenceRecipe(compositeGlobalPath); | ||
return identifier; | ||
} | ||
var propertiesDescription = {}; | ||
Object.getOwnPropertyNames(value).forEach(function (propertyName) { | ||
var propertyDescriptor = Object.getOwnPropertyDescriptor(value, propertyName); | ||
var propertyDescription = {}; | ||
Object.keys(propertyDescriptor).forEach(function (descriptorName) { | ||
var descriptorValue = propertyDescriptor[descriptorName]; | ||
if (descriptorName === "set" && descriptorValue && !functionAllowed) throw new Error(createForbiddenPropertySetterMessage({ | ||
path: path, | ||
propertyName: propertyName | ||
})); | ||
if ("get" === e && f && !r) throw new Error(w({ | ||
path: i, | ||
propertyName: o | ||
if (descriptorName === "get" && descriptorValue && !functionAllowed) throw new Error(createForbiddenPropertyGetterMessage({ | ||
path: path, | ||
propertyName: propertyName | ||
})); | ||
var u = t(e, n(i).concat(['["'.concat(o, '"]'), "[[propertyDescriptor:".concat(e, "]]")])), | ||
p = t(f, n(i).concat(['["'.concat(o, '"]'), "[[propertyDescriptor:".concat(e, "]]")])); | ||
a[u] = p; | ||
var descriptorNameIdentifier = valueToIdentifier(descriptorName, _toConsumableArray(path).concat(["[\"".concat(propertyName, "\"]"), "[[propertyDescriptor:".concat(descriptorName, "]]")])); | ||
var descriptorValueIdentifier = valueToIdentifier(descriptorValue, _toConsumableArray(path).concat(["[\"".concat(propertyName, "\"]"), "[[propertyDescriptor:".concat(descriptorName, "]]")])); | ||
propertyDescription[descriptorNameIdentifier] = descriptorValueIdentifier; | ||
}); | ||
var f = t(o, n(i).concat([o])); | ||
S[f] = a; | ||
var propertyNameIdentifier = valueToIdentifier(propertyName, _toConsumableArray(path).concat([propertyName])); | ||
propertiesDescription[propertyNameIdentifier] = propertyDescription; | ||
}); | ||
var I = {}; | ||
Object.getOwnPropertySymbols(e).forEach(function (r) { | ||
var o = Object.getOwnPropertyDescriptor(e, r), | ||
c = {}; | ||
Object.keys(o).forEach(function (e) { | ||
var a = t(e, n(i).concat(["[".concat(r.toString(), "]"), "[[propertyDescriptor:".concat(e, "]]")])), | ||
f = t(o[e], n(i).concat(["[".concat(r.toString(), "]"), "[[propertyDescriptor:".concat(e, "]]")])); | ||
c[a] = f; | ||
var symbolsDescription = {}; | ||
Object.getOwnPropertySymbols(value).forEach(function (symbol) { | ||
var propertyDescriptor = Object.getOwnPropertyDescriptor(value, symbol); | ||
var propertyDescription = {}; | ||
Object.keys(propertyDescriptor).forEach(function (descriptorName) { | ||
var descriptorNameIdentifier = valueToIdentifier(descriptorName, _toConsumableArray(path).concat(["[".concat(symbol.toString(), "]"), "[[propertyDescriptor:".concat(descriptorName, "]]")])); | ||
var descriptorValueIdentifier = valueToIdentifier(propertyDescriptor[descriptorName], _toConsumableArray(path).concat(["[".concat(symbol.toString(), "]"), "[[propertyDescriptor:".concat(descriptorName, "]]")])); | ||
propertyDescription[descriptorNameIdentifier] = descriptorValueIdentifier; | ||
}); | ||
var a = t(r, n(i).concat([r])); | ||
I[a] = c; | ||
var symbolIdentifier = valueToIdentifier(symbol, _toConsumableArray(path).concat([symbol])); | ||
symbolsDescription[symbolIdentifier] = propertyDescription; | ||
}); | ||
var methodsDescription = computeMethodsDescription(value, path); | ||
var extensible = Object.isExtensible(value); | ||
recipeArray[identifier] = createCompositeRecipe({ | ||
propertiesDescription: propertiesDescription, | ||
symbolsDescription: symbolsDescription, | ||
methodsDescription: methodsDescription, | ||
extensible: extensible | ||
}); | ||
return identifier; | ||
}; | ||
var _ = u(e, i), | ||
A = Object.isExtensible(e); | ||
var computeMethodsDescription = function computeMethodsDescription(value, path) { | ||
var methodsDescription = {}; | ||
return c[k] = d({ | ||
propertiesDescription: S, | ||
symbolsDescription: I, | ||
methodsDescription: _, | ||
extensible: A | ||
}), k; | ||
}, | ||
u = function (t, e) { | ||
var r = {}; | ||
if ("function" == typeof Set && t instanceof Set) { | ||
var o = []; | ||
t.forEach(function (t, r) { | ||
var i = f(t, n(e).concat(["[[SetEntryValue]]", r])); | ||
o.push([i]); | ||
}), r[f("add")] = o; | ||
if (typeof Set === "function" && value instanceof Set) { | ||
var addCallArray = []; | ||
value.forEach(function (entryValue, index) { | ||
var entryValueIdentifier = valueToIdentifier(entryValue, _toConsumableArray(path).concat(["[[SetEntryValue]]", index])); | ||
addCallArray.push([entryValueIdentifier]); | ||
}); | ||
methodsDescription[valueToIdentifier("add")] = addCallArray; | ||
} | ||
if ("function" == typeof Map && t instanceof Map) { | ||
var i = []; | ||
t.forEach(function (t, r) { | ||
var o = f(r, n(e).concat(["[[MapEntryKey]]", r])), | ||
c = f(t, n(e).concat(["[[MapEntryValue]]", t])); | ||
i.push([o, c]); | ||
}), r[f("set")] = i; | ||
if (typeof Map === "function" && value instanceof Map) { | ||
var setCallArray = []; | ||
value.forEach(function (entryValue, entryKey) { | ||
var entryKeyIdentifier = valueToIdentifier(entryKey, _toConsumableArray(path).concat(["[[MapEntryKey]]", entryKey])); | ||
var entryValueIdentifier = valueToIdentifier(entryValue, _toConsumableArray(path).concat(["[[MapEntryValue]]", entryValue])); | ||
setCallArray.push([entryKeyIdentifier, entryValueIdentifier]); | ||
}); | ||
methodsDescription[valueToIdentifier("set")] = setCallArray; | ||
} | ||
return r; | ||
}, | ||
s = function (t) { | ||
return Object.keys(i).find(function (e) { | ||
var r = i[e]; | ||
return !!Object.is(t, r) || t === r; | ||
return methodsDescription; | ||
}; | ||
var identifierForPrimitive = function identifierForPrimitive(value) { | ||
return Object.keys(valueMap).find(function (existingIdentifier) { | ||
var existingValue = valueMap[existingIdentifier]; | ||
if (Object.is(value, existingValue)) return true; | ||
return value === existingValue; | ||
}); | ||
}, | ||
l = function (t) { | ||
return Object.keys(i).find(function (e) { | ||
var r = i[e]; | ||
return t === r; | ||
}; | ||
var identifierForComposite = function identifierForComposite(value) { | ||
return Object.keys(valueMap).find(function (existingIdentifier) { | ||
var existingValue = valueMap[existingIdentifier]; | ||
return value === existingValue; | ||
}); | ||
}, | ||
v = function (t) { | ||
var e = D(); | ||
return i[e] = t, e; | ||
}, | ||
E = -1, | ||
D = function () { | ||
var t = String(parseInt(E) + 1); | ||
return E = t, t; | ||
}, | ||
S = f(t); | ||
}; | ||
return c.slice().forEach(function (t, e) { | ||
if ("composite" === t.type) { | ||
var r = i[e]; | ||
var identifierForNewValue = function identifierForNewValue(value) { | ||
var identifier = nextIdentifier(); | ||
valueMap[identifier] = value; | ||
return identifier; | ||
}; | ||
if ("function" == typeof r) { | ||
var u = D(); | ||
return c[u] = { | ||
type: "primitive", | ||
value: r | ||
}, void (t.valueOfIdentifier = u); | ||
} | ||
var currentIdentifier = -1; | ||
if (r instanceof RegExp) { | ||
var p = D(); | ||
return c[p] = { | ||
var nextIdentifier = function nextIdentifier() { | ||
var identifier = String(parseInt(currentIdentifier) + 1); | ||
currentIdentifier = identifier; | ||
return identifier; | ||
}; | ||
var mainIdentifier = valueToIdentifier(mainValue); // prototype, important to keep after the whole structure was visited | ||
// so that we discover if any prototype is part of the value | ||
var prototypeValueToIdentifier = function prototypeValueToIdentifier(prototypeValue) { | ||
// prototype is null | ||
if (prototypeValue === null) return valueToIdentifier(prototypeValue); // prototype found somewhere already | ||
var prototypeExistingIdentifier = identifierForComposite(prototypeValue); | ||
if (prototypeExistingIdentifier !== undefined) return prototypeExistingIdentifier; // mark prototype as visited | ||
var prototypeIdentifier = identifierForNewValue(prototypeValue); // prototype is a global reference ? | ||
var prototypeGlobalPath = getCompositeGlobalPath(prototypeValue); | ||
if (prototypeGlobalPath) { | ||
recipeArray[prototypeIdentifier] = createGlobalReferenceRecipe(prototypeGlobalPath); | ||
return prototypeIdentifier; | ||
} // otherwise prototype is unknown | ||
throw new Error(createUnknownPrototypeMessage({ | ||
prototypeValue: prototypeValue | ||
})); | ||
}; | ||
var identifierForValueOf = function identifierForValueOf(value) { | ||
var path = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : []; | ||
if (value instanceof Array) return valueToIdentifier(value.length, _toConsumableArray(path).concat(["length"])); | ||
if ("valueOf" in value === false) return undefined; | ||
if (typeof value.valueOf !== "function") return undefined; | ||
var valueOfReturnValue = value.valueOf(); | ||
if (!isComposite(valueOfReturnValue)) return valueToIdentifier(valueOfReturnValue, _toConsumableArray(path).concat(["valueOf()"])); | ||
if (valueOfReturnValue === value) return undefined; | ||
throw new Error(createUnexpectedValueOfReturnValueMessage()); | ||
}; | ||
recipeArray.slice().forEach(function (recipe, index) { | ||
if (recipe.type === "composite") { | ||
var value = valueMap[index]; | ||
if (typeof value === "function") { | ||
var valueOfIdentifier = nextIdentifier(); | ||
recipeArray[valueOfIdentifier] = { | ||
type: "primitive", | ||
value: r | ||
}, void (t.valueOfIdentifier = p); | ||
value: value | ||
}; | ||
recipe.valueOfIdentifier = valueOfIdentifier; | ||
return; | ||
} | ||
t.valueOfIdentifier = function (t) { | ||
var e = arguments.length > 1 && void 0 !== arguments[1] ? arguments[1] : []; | ||
if (t instanceof Array) return f(t.length, n(e).concat(["length"])); | ||
if (value instanceof RegExp) { | ||
var _valueOfIdentifier = nextIdentifier(); | ||
if ("valueOf" in t != 0 && "function" == typeof t.valueOf) { | ||
var r = t.valueOf(); | ||
if (!o(r)) return f(r, n(e).concat(["valueOf()"])); | ||
if (r !== t) throw new Error(j()); | ||
} | ||
}(r); | ||
recipeArray[_valueOfIdentifier] = { | ||
type: "primitive", | ||
value: value | ||
}; | ||
recipe.valueOfIdentifier = _valueOfIdentifier; | ||
return; | ||
} // valueOf, mandatory to uneval new Date(10) for instance. | ||
var s = Object.getPrototypeOf(r); | ||
t.prototypeIdentifier = function (t) { | ||
if (null === t) return f(t); | ||
var e = l(t); | ||
if (void 0 !== e) return e; | ||
var r = v(t), | ||
n = a(t); | ||
if (n) return c[r] = y(n), r; | ||
throw new Error(k({ | ||
prototypeValue: t | ||
})); | ||
}(s); | ||
recipe.valueOfIdentifier = identifierForValueOf(value); | ||
var prototypeValue = Object.getPrototypeOf(value); | ||
recipe.prototypeIdentifier = prototypeValueToIdentifier(prototypeValue); | ||
} | ||
}), { | ||
recipeArray: c, | ||
mainIdentifier: S | ||
}); | ||
return { | ||
recipeArray: recipeArray, | ||
mainIdentifier: mainIdentifier | ||
}; | ||
}, | ||
p = function (t) { | ||
return "symbol" === r(t) ? s(t) : l(t); | ||
}, | ||
s = function (t) { | ||
var e = Symbol.keyFor(t); | ||
if (void 0 !== e) return v(e); | ||
var r, | ||
n = (r = t, c.get(r)); | ||
if (!n) throw new Error(E({ | ||
symbol: t | ||
}; | ||
var primitiveToRecipe = function primitiveToRecipe(value) { | ||
if (_typeof(value) === "symbol") return symbolToRecipe(value); | ||
return createPimitiveRecipe(value); | ||
}; | ||
var symbolToRecipe = function symbolToRecipe(symbol) { | ||
var globalSymbolKey = Symbol.keyFor(symbol); | ||
if (globalSymbolKey !== undefined) return createGlobalSymbolRecipe(globalSymbolKey); | ||
var symbolGlobalPath = getPrimitiveGlobalPath(symbol); | ||
if (!symbolGlobalPath) throw new Error(createUnknownSymbolMessage({ | ||
symbol: symbol | ||
})); | ||
return y(n); | ||
}, | ||
l = function (t) { | ||
return createGlobalReferenceRecipe(symbolGlobalPath); | ||
}; | ||
var createPimitiveRecipe = function createPimitiveRecipe(value) { | ||
return { | ||
type: "primitive", | ||
value: t | ||
value: value | ||
}; | ||
}, | ||
y = function (t) { | ||
return { | ||
}; | ||
var createGlobalReferenceRecipe = function createGlobalReferenceRecipe(path) { | ||
var recipe = { | ||
type: "global-reference", | ||
path: t | ||
path: path | ||
}; | ||
}, | ||
v = function (t) { | ||
return recipe; | ||
}; | ||
var createGlobalSymbolRecipe = function createGlobalSymbolRecipe(key) { | ||
return { | ||
type: "global-symbol", | ||
key: t | ||
key: key | ||
}; | ||
}, | ||
d = function (t) { | ||
}; | ||
var createCompositeRecipe = function createCompositeRecipe(_ref2) { | ||
var prototypeIdentifier = _ref2.prototypeIdentifier, | ||
valueOfIdentifier = _ref2.valueOfIdentifier, | ||
propertiesDescription = _ref2.propertiesDescription, | ||
symbolsDescription = _ref2.symbolsDescription, | ||
methodsDescription = _ref2.methodsDescription, | ||
extensible = _ref2.extensible; | ||
return { | ||
type: "composite", | ||
prototypeIdentifier: t.prototypeIdentifier, | ||
valueOfIdentifier: t.valueOfIdentifier, | ||
propertiesDescription: t.propertiesDescription, | ||
symbolsDescription: t.symbolsDescription, | ||
methodsDescription: t.methodsDescription, | ||
extensible: t.extensible | ||
prototypeIdentifier: prototypeIdentifier, | ||
valueOfIdentifier: valueOfIdentifier, | ||
propertiesDescription: propertiesDescription, | ||
symbolsDescription: symbolsDescription, | ||
methodsDescription: methodsDescription, | ||
extensible: extensible | ||
}; | ||
}, | ||
b = function (t) { | ||
var e = t.path; | ||
return 0 === e.length ? "promise are not supported." : "promise are not supported.\npromise found at: ".concat(e.join("")); | ||
}, | ||
h = function (t) { | ||
var e = t.path; | ||
return 0 === e.length ? "weakSet are not supported." : "weakSet are not supported.\nweakSet found at: ".concat(e.join("")); | ||
}, | ||
m = function (t) { | ||
var e = t.path; | ||
return 0 === e.length ? "weakMap are not supported." : "weakMap are not supported.\nweakMap found at: ".concat(e.join("")); | ||
}, | ||
O = function (t) { | ||
var e = t.path; | ||
return 0 === e.length ? "function are not allowed." : "function are not allowed.\nfunction found at: ".concat(e.join("")); | ||
}, | ||
w = function (t) { | ||
var e = t.path, | ||
r = t.propertyName; | ||
return "property getter are not allowed.\ngetter found on property: ".concat(r, "\nat: ").concat(e.join("")); | ||
}, | ||
g = function (t) { | ||
var e = t.path, | ||
r = t.propertyName; | ||
return "property setter are not allowed.\nsetter found on property: ".concat(r, "\nat: ").concat(e.join("")); | ||
}, | ||
j = function () { | ||
}; | ||
var createPromiseAreNotSupportedMessage = function createPromiseAreNotSupportedMessage(_ref3) { | ||
var path = _ref3.path; | ||
if (path.length === 0) return "promise are not supported."; | ||
return "promise are not supported.\npromise found at: ".concat(path.join("")); | ||
}; | ||
var createWeakSetAreNotSupportedMessage = function createWeakSetAreNotSupportedMessage(_ref4) { | ||
var path = _ref4.path; | ||
if (path.length === 0) return "weakSet are not supported."; | ||
return "weakSet are not supported.\nweakSet found at: ".concat(path.join("")); | ||
}; | ||
var createWeakMapAreNotSupportedMessage = function createWeakMapAreNotSupportedMessage(_ref5) { | ||
var path = _ref5.path; | ||
if (path.length === 0) return "weakMap are not supported."; | ||
return "weakMap are not supported.\nweakMap found at: ".concat(path.join("")); | ||
}; | ||
var createForbiddenFunctionMessage = function createForbiddenFunctionMessage(_ref6) { | ||
var path = _ref6.path; | ||
if (path.length === 0) return "function are not allowed."; | ||
return "function are not allowed.\nfunction found at: ".concat(path.join("")); | ||
}; | ||
var createForbiddenPropertyGetterMessage = function createForbiddenPropertyGetterMessage(_ref7) { | ||
var path = _ref7.path, | ||
propertyName = _ref7.propertyName; | ||
return "property getter are not allowed.\ngetter found on property: ".concat(propertyName, "\nat: ").concat(path.join("")); | ||
}; | ||
var createForbiddenPropertySetterMessage = function createForbiddenPropertySetterMessage(_ref8) { | ||
var path = _ref8.path, | ||
propertyName = _ref8.propertyName; | ||
return "property setter are not allowed.\nsetter found on property: ".concat(propertyName, "\nat: ").concat(path.join("")); | ||
}; | ||
var createUnexpectedValueOfReturnValueMessage = function createUnexpectedValueOfReturnValueMessage() { | ||
return "valueOf() must return a primitive of the object itself."; | ||
}, | ||
E = function (t) { | ||
var e = t.symbol; | ||
return "symbol must be global, like Symbol.iterator, or created using Symbol.for().\nsymbol: ".concat(e.toString()); | ||
}, | ||
k = function () { | ||
}; | ||
var createUnknownSymbolMessage = function createUnknownSymbolMessage(_ref9) { | ||
var symbol = _ref9.symbol; | ||
return "symbol must be global, like Symbol.iterator, or created using Symbol.for().\nsymbol: ".concat(symbol.toString()); | ||
}; | ||
var createUnknownPrototypeMessage = function createUnknownPrototypeMessage() { | ||
return "prototype must be global, like Object.prototype, or somewhere in the value."; | ||
}, | ||
D = function (t) { | ||
var e = t.recipeArray, | ||
o = t.mainIdentifier, | ||
i = "object" === ("undefined" == typeof window ? "undefined" : r(window)) ? window : global, | ||
c = {}, | ||
a = function (t) { | ||
return t.value; | ||
}, | ||
f = function (t) { | ||
var e = t.key; | ||
return Symbol.for(e); | ||
}, | ||
u = function (t) { | ||
for (var e = t.path, r = i, n = 0; n < e.length;) { | ||
var o = e[n]; | ||
if (n++, o in r == !1) throw new Error(y({ | ||
path: e, | ||
index: n | ||
})); | ||
r = r[o]; | ||
}; // be carefull because this function is mutating recipe objects inside the recipeArray. | ||
// this is not an issue because each recipe object is not accessible from the outside | ||
// when used internally by uneval | ||
var compositionToRecipe = function compositionToRecipe(_ref) { | ||
var recipeArray = _ref.recipeArray, | ||
mainIdentifier = _ref.mainIdentifier; | ||
var findInRecipePrototypeChain = function findInRecipePrototypeChain(recipe, callback) { | ||
var currentRecipe = recipe; // eslint-disable-next-line no-constant-condition | ||
while (true) { | ||
if (currentRecipe.type !== "composite") break; | ||
var prototypeIdentifier = currentRecipe.prototypeIdentifier; | ||
if (prototypeIdentifier === undefined) break; | ||
currentRecipe = recipeArray[prototypeIdentifier]; | ||
if (callback(currentRecipe, prototypeIdentifier)) return prototypeIdentifier; | ||
} | ||
return r; | ||
}, | ||
p = function (t) { | ||
var e = t.prototypeIdentifier, | ||
r = t.valueOfIdentifier; | ||
if (void 0 === e) return c[r]; | ||
var n = c[e]; | ||
if (null === n) return Object.create(null); | ||
var o = n.constructor; | ||
return o === Object ? Object.create(n) : void 0 === r ? new o() : new o(c[r]); | ||
return undefined; | ||
}; | ||
e.forEach(function (t, e) { | ||
var r = function (t) { | ||
return "primitive" === t.type ? a(t) : "global-symbol" === t.type ? f(t) : "global-reference" === t.type ? u(t) : p(t); | ||
}(t); | ||
var recipeArrayOrdered = recipeArray.slice(); | ||
recipeArrayOrdered.sort(function (leftRecipe, rightRecipe) { | ||
var leftType = leftRecipe.type; | ||
var rightType = rightRecipe.type; | ||
c[e] = r; | ||
if (leftType === "composite" && rightType === "composite") { | ||
var rightRecipeIsInLeftRecipePrototypeChain = findInRecipePrototypeChain(leftRecipe, function (recipeCandidate) { | ||
return recipeCandidate === rightRecipe; | ||
}); // if left recipe requires right recipe, left must be after right | ||
if (rightRecipeIsInLeftRecipePrototypeChain) return 1; | ||
var leftRecipeIsInRightRecipePrototypeChain = findInRecipePrototypeChain(rightRecipe, function (recipeCandidate) { | ||
return recipeCandidate === leftRecipe; | ||
}); // if right recipe requires left recipe, right must be after left | ||
if (leftRecipeIsInRightRecipePrototypeChain) return -1; | ||
} | ||
if (leftType !== rightType) { | ||
// if left is a composite, left must be after right | ||
if (leftType === "composite") return 1; // if right is a composite, right must be after left | ||
if (rightType === "composite") return -1; | ||
} | ||
var leftIndex = recipeArray.indexOf(leftRecipe); | ||
var rightIndex = recipeArray.indexOf(rightRecipe); // left was before right, don't change that | ||
if (leftIndex < rightIndex) return -1; // right was after left, don't change that | ||
return 1; | ||
}); | ||
var moves = {}; | ||
recipeArray.forEach(function (recipe, index) { | ||
var indexOrdered = recipeArrayOrdered.indexOf(recipe); | ||
var s = function (t, e) { | ||
var r = t.propertiesDescription, | ||
o = t.symbolsDescription, | ||
i = t.methodsDescription, | ||
a = t.extensible, | ||
f = void 0 === a || a, | ||
u = c[e]; | ||
r && Object.keys(r).forEach(function (t) { | ||
var e = c[t], | ||
n = r[t]; | ||
l(u, e, n); | ||
}), o && Object.keys(o).forEach(function (t) { | ||
var e = c[t], | ||
r = o[t]; | ||
l(u, e, r); | ||
}), i && Object.keys(i).forEach(function (t) { | ||
var e = c[t]; | ||
i[t].forEach(function (t) { | ||
var r = t.map(function (t) { | ||
return c[t]; | ||
if (index !== indexOrdered) { | ||
moves[index] = indexOrdered; | ||
} | ||
}); | ||
var remapIdentifier = function remapIdentifier(identifier) { | ||
if (identifier in moves) return moves[identifier]; | ||
return identifier; | ||
}; | ||
var remapPropertyDescription = function remapPropertyDescription(propertyDescription) { | ||
var remappedPropertyDescription = {}; | ||
Object.keys(propertyDescription).forEach(function (descriptorNameIdentifier) { | ||
remappedPropertyDescription[remapIdentifier(descriptorNameIdentifier)] = remapIdentifier(propertyDescription[descriptorNameIdentifier]); | ||
}); | ||
return remappedPropertyDescription; | ||
}; | ||
recipeArrayOrdered.forEach(function (recipe) { | ||
if (recipe.type !== "composite") return; | ||
recipe.valueOfIdentifier = remapIdentifier(recipe.valueOfIdentifier); | ||
recipe.prototypeIdentifier = remapIdentifier(recipe.prototypeIdentifier); | ||
var propertiesDescription = recipe.propertiesDescription; | ||
var remappedPropertiesDescription = {}; | ||
Object.keys(propertiesDescription).forEach(function (propertyNameIdentifier) { | ||
remappedPropertiesDescription[remapIdentifier(propertyNameIdentifier)] = remapPropertyDescription(propertiesDescription[propertyNameIdentifier]); | ||
}); | ||
recipe.propertiesDescription = remappedPropertiesDescription; | ||
var symbolsDescription = recipe.symbolsDescription; | ||
var remappedSymbolsDescription = {}; | ||
Object.keys(symbolsDescription).forEach(function (symbolIdentifier) { | ||
remappedSymbolsDescription[remapIdentifier(symbolIdentifier)] = remapPropertyDescription(symbolsDescription[symbolIdentifier]); | ||
}); | ||
recipe.symbolsDescription = remappedSymbolsDescription; | ||
var methodsDescription = recipe.methodsDescription; | ||
var remappedMethodsDescription = {}; | ||
Object.keys(methodsDescription).forEach(function (methodNameIdentifier) { | ||
var callsDescription = methodsDescription[methodNameIdentifier]; | ||
var remappedCallsDescription = callsDescription.map(function (argumentIdentifiers) { | ||
return argumentIdentifiers.map(function (argumentIdentifier) { | ||
return remapIdentifier(argumentIdentifier); | ||
}); | ||
u[e].apply(u, n(r)); | ||
}); | ||
}), f || Object.preventExtensions(u); | ||
}, | ||
l = function (t, e, r) { | ||
var n = Object.getOwnPropertyDescriptor(t, e); | ||
remappedMethodsDescription[remapIdentifier(methodNameIdentifier)] = remappedCallsDescription; | ||
}); | ||
recipe.methodsDescription = remappedMethodsDescription; | ||
}); | ||
return { | ||
recipeArray: recipeArrayOrdered, | ||
mainIdentifier: remapIdentifier(mainIdentifier) | ||
}; | ||
}; // This function would return recipes that does not contain default values | ||
// for instance we'll consider extensible as false by default | ||
// empty propertiesMap and symbolsMap can be omitted | ||
// it would decrease the size of value string representation a bit | ||
if (!n || !1 !== n.configurable) { | ||
var o = {}; | ||
Object.keys(r).forEach(function (t) { | ||
var e = r[t], | ||
n = c[t], | ||
i = c[e]; | ||
o[n] = i; | ||
}), Object.defineProperty(t, e, o); | ||
var minifyRecipe = function minifyRecipe(_ref) { | ||
var recipeArray = _ref.recipeArray, | ||
mainIdentifier = _ref.mainIdentifier; | ||
recipeArray.forEach(function (recipe) { | ||
if (recipe.type === "composite") { | ||
if (recipe.prototypeIdentifier === undefined) delete recipe.prototypeIdentifier; | ||
if (recipe.valueOfIdentifier === undefined) delete recipe.valueOfIdentifier; | ||
if (recipe.extensible === true) delete recipe.extensible; | ||
if (Object.keys(recipe.propertiesDescription).length === 0) delete recipe.propertiesDescription; | ||
if (Object.keys(recipe.symbolsDescription).length === 0) delete recipe.symbolsDescription; | ||
if (Object.keys(recipe.methodsDescription).length === 0) delete recipe.methodsDescription; | ||
} | ||
}); | ||
return { | ||
recipeArray: recipeArray, | ||
mainIdentifier: mainIdentifier | ||
}; | ||
}; | ||
e.forEach(function (t, e) { | ||
!function (t, e) { | ||
"composite" === t.type && s(t, e); | ||
}(t, e); | ||
function recompose(param) { | ||
var recipeArray = param.recipeArray; | ||
var mainIdentifier = param.mainIdentifier; | ||
var globalObject = (typeof window === "undefined" ? "undefined" : _typeof(window)) === "object" ? window : global; | ||
var materials = {}; | ||
function setupMaterial(recipe) { | ||
if (recipe.type === "primitive") return setupPrimitiveMaterial(recipe); | ||
if (recipe.type === "global-symbol") return setupGlobalSymbolMaterial(recipe); | ||
if (recipe.type === "global-reference") return setupGlobalReferenceMaterial(recipe); | ||
return setupCompositeMaterial(recipe); | ||
} | ||
function setupPrimitiveMaterial(recipe) { | ||
return recipe.value; | ||
} | ||
function setupGlobalSymbolMaterial(recipe) { | ||
return Symbol.for(recipe.key); | ||
} | ||
function setupGlobalReferenceMaterial(recipe) { | ||
var path = recipe.path; | ||
var currentValue = globalObject; | ||
var i = 0; | ||
while (i < path.length) { | ||
var part = path[i]; | ||
i++; | ||
if (part in currentValue === false) throw new Error(createValueNotFoundErrorMessage({ | ||
path: path, | ||
index: i | ||
})); | ||
currentValue = currentValue[part]; | ||
} | ||
return currentValue; | ||
} | ||
function setupCompositeMaterial(recipe) { | ||
var prototypeIdentifier = recipe.prototypeIdentifier; | ||
var valueOfIdentifier = recipe.valueOfIdentifier; // regexp and function | ||
if (prototypeIdentifier === undefined) return materials[valueOfIdentifier]; | ||
var prototypeValue = materials[prototypeIdentifier]; | ||
if (prototypeValue === null) return Object.create(null); | ||
var Constructor = prototypeValue.constructor; | ||
if (Constructor === Object) return Object.create(prototypeValue); | ||
if (valueOfIdentifier === undefined) return new Constructor(); | ||
var valueOfValue = materials[valueOfIdentifier]; | ||
return new Constructor(valueOfValue); | ||
} | ||
recipeArray.forEach(function (recipe, index) { | ||
var value = setupMaterial(recipe); | ||
materials[index] = value; | ||
}); | ||
var y = function (t) { | ||
var e = t.path, | ||
r = t.index; | ||
return "value not found for path.\npart not found: ".concat(e[r], "\npath: ").concat(e.join(",")); | ||
}; | ||
function followRecipe(recipe, index) { | ||
if (recipe.type === "composite") followCompositeRecipe(recipe, index); | ||
} | ||
return c[o]; | ||
}, | ||
S = function (t) { | ||
for (var e = String(t), r = 0, n = e.length, o = ""; r < n;) { | ||
var i = e[r]; | ||
o += '"' === i || "'" === i || "\\" === i ? "\\".concat(i) : "\n" === i ? "\\n" : "\r" === i ? "\\r" : "\u2028" === i ? "\\u2028" : "\u2029" === i ? "\\u2029" : i, r++; | ||
function followCompositeRecipe(recipe, index) { | ||
var composite = materials[index]; | ||
var propertiesDescription = recipe.propertiesDescription; | ||
if (propertiesDescription) { | ||
Object.keys(propertiesDescription).forEach(function (propertyNameIdentifier) { | ||
var propertyName = materials[propertyNameIdentifier]; | ||
var description = propertiesDescription[propertyNameIdentifier]; | ||
defineProperty(composite, propertyName, description); | ||
}); | ||
} | ||
var symbolsDescription = recipe.symbolsDescription; | ||
if (symbolsDescription) { | ||
Object.keys(symbolsDescription).forEach(function (symbolIdentifier) { | ||
var symbol = materials[symbolIdentifier]; | ||
var description = symbolsDescription[symbolIdentifier]; | ||
defineProperty(composite, symbol, description); | ||
}); | ||
} | ||
var methodsDescription = recipe.methodsDescription; | ||
if (methodsDescription) { | ||
Object.keys(methodsDescription).forEach(function (methodNameIdentifier) { | ||
var methodName = materials[methodNameIdentifier]; | ||
var calls = methodsDescription[methodNameIdentifier]; | ||
calls.forEach(function (argumentIdentifiers) { | ||
var argumentValues = argumentIdentifiers.map(function (argumentIdentifier) { | ||
return materials[argumentIdentifier]; | ||
}); | ||
composite[methodName].apply(composite, _toConsumableArray(argumentValues)); | ||
}); | ||
}); | ||
} | ||
var extensible = recipe.extensible || true; | ||
if (!extensible) Object.preventExtensions(composite); | ||
} | ||
return o; | ||
}, | ||
I = function (t) { | ||
var e = function (t) { | ||
return t instanceof Array ? n(t) : t instanceof RegExp ? t.toString() : null === t ? "null" : "object" === r(t) ? o(t) : "string" == typeof t ? '"'.concat(S(t), '"') : Object.is(t, -0) ? "-0" : String(t); | ||
}, | ||
n = function (t) { | ||
var r = t.map(function (t) { | ||
return e(t); | ||
function defineProperty(composite, propertyNameOrSymbol, propertyDescription) { | ||
var currentDescriptor = Object.getOwnPropertyDescriptor(composite, propertyNameOrSymbol); | ||
if (currentDescriptor && currentDescriptor.configurable === false) return; | ||
var descriptor = {}; | ||
Object.keys(propertyDescription).forEach(function (descriptorNameIdentifier) { | ||
var descriptorValueIdentifier = propertyDescription[descriptorNameIdentifier]; | ||
var descriptorName = materials[descriptorNameIdentifier]; | ||
var descriptorValue = materials[descriptorValueIdentifier]; | ||
descriptor[descriptorName] = descriptorValue; | ||
}); | ||
return "[".concat(r.join(","), "]"); | ||
}, | ||
o = function (t) { | ||
var r = Object.keys(t).map(function (r) { | ||
return '"'.concat(S(r), '":').concat(e(t[r])); | ||
}); | ||
return "{".concat(r.join(","), "}"); | ||
}; | ||
Object.defineProperty(composite, propertyNameOrSymbol, descriptor); | ||
} | ||
return e(t); | ||
recipeArray.forEach(function (recipe, index) { | ||
followRecipe(recipe, index); | ||
}); | ||
function createValueNotFoundErrorMessage(data) { | ||
var path = data.path; | ||
var index = data.index; | ||
var message = "value not found for path."; | ||
message += "\n"; // eslint-disable-next-line prefer-template | ||
message += "part not found: " + path[index]; | ||
message += "\n"; // eslint-disable-next-line prefer-template | ||
message += "path: " + path.join(""); | ||
return message; | ||
} | ||
return materials[mainIdentifier]; | ||
} // https://github.com/joliss/js-string-escape/blob/master/index.js | ||
// http://javascript.crockford.com/remedial.html | ||
var escapeString = function escapeString(value) { | ||
var string = String(value); | ||
var i = 0; | ||
var j = string.length; | ||
var escapedString = ""; | ||
while (i < j) { | ||
var char = string[i]; | ||
var escapedChar = void 0; | ||
if (char === '"' || char === "'" || char === "\\") { | ||
escapedChar = "\\".concat(char); | ||
} else if (char === "\n") { | ||
escapedChar = "\\n"; | ||
} else if (char === "\r") { | ||
escapedChar = "\\r"; | ||
} else if (char === "\u2028") { | ||
escapedChar = "\\u2028"; | ||
} else if (char === "\u2029") { | ||
escapedChar = "\\u2029"; | ||
} else { | ||
escapedChar = char; | ||
} | ||
escapedString += escapedChar; | ||
i++; | ||
} | ||
return escapedString; | ||
}; | ||
return t.uneval = function (t) { | ||
var e = (arguments.length > 1 && void 0 !== arguments[1] ? arguments[1] : {}).functionAllowed, | ||
r = function (t) { | ||
var e = t.recipeArray, | ||
r = t.mainIdentifier; | ||
return e.forEach(function (t) { | ||
"composite" === t.type && (void 0 === t.prototypeIdentifier && delete t.prototypeIdentifier, void 0 === t.valueOfIdentifier && delete t.valueOfIdentifier, !0 === t.extensible && delete t.extensible, 0 === Object.keys(t.propertiesDescription).length && delete t.propertiesDescription, 0 === Object.keys(t.symbolsDescription).length && delete t.symbolsDescription, 0 === Object.keys(t.methodsDescription).length && delete t.methodsDescription); | ||
}), { | ||
recipeArray: e, | ||
mainIdentifier: r | ||
}; | ||
}(function (t) { | ||
var e = t.recipeArray, | ||
r = t.mainIdentifier, | ||
n = function (t, r) { | ||
for (var n = t; "composite" === n.type;) { | ||
var o = n.prototypeIdentifier; | ||
if (void 0 === o) break; | ||
if (r(n = e[o], o)) return o; | ||
} | ||
}, | ||
o = e.slice(); | ||
var uneval = function uneval(value) { | ||
var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}, | ||
_ref$functionAllowed = _ref.functionAllowed, | ||
functionAllowed = _ref$functionAllowed === void 0 ? false : _ref$functionAllowed; | ||
o.sort(function (t, r) { | ||
var o = t.type, | ||
i = r.type; | ||
var composition = decompose(value, { | ||
functionAllowed: functionAllowed | ||
}); | ||
var recipe = compositionToRecipe(composition); | ||
var recipeMinified = minifyRecipe(recipe); | ||
var recomposeSource = recompose.toString(); | ||
var recomposeParamSouce = recipeToSource(recipeMinified); | ||
return "(".concat(recomposeSource, ")(").concat(recomposeParamSouce, ")"); | ||
}; | ||
if ("composite" === o && "composite" === i) { | ||
if (n(t, function (t) { | ||
return t === r; | ||
})) return 1; | ||
if (n(r, function (e) { | ||
return e === t; | ||
})) return -1; | ||
} | ||
var recipeToSource = function recipeToSource(recipe) { | ||
var valueToSource = function valueToSource(value) { | ||
if (value instanceof Array) return arrayToSource(value); | ||
if (value instanceof RegExp) return value.toString(); | ||
if (value === null) return "null"; | ||
if (_typeof(value) === "object") return objectToSource(value); | ||
if (typeof value === "string") return "\"".concat(escapeString(value), "\""); | ||
if (Object.is(value, -0)) return "-0"; | ||
return String(value); | ||
}; | ||
if (o !== i) { | ||
if ("composite" === o) return 1; | ||
if ("composite" === i) return -1; | ||
} | ||
var arrayToSource = function arrayToSource(array) { | ||
var valueSourceArray = array.map(function (value) { | ||
return valueToSource(value); | ||
}); | ||
return "[".concat(valueSourceArray.join(","), "]"); | ||
}; | ||
return e.indexOf(t) < e.indexOf(r) ? -1 : 1; | ||
var objectToSource = function objectToSource(object) { | ||
var propertiesSources = Object.keys(object).map(function (key) { | ||
return "\"".concat(escapeString(key), "\":").concat(valueToSource(object[key])); | ||
}); | ||
var i = {}; | ||
e.forEach(function (t, e) { | ||
var r = o.indexOf(t); | ||
e !== r && (i[e] = r); | ||
}); | ||
return "{".concat(propertiesSources.join(","), "}"); | ||
}; | ||
var c = function (t) { | ||
return t in i ? i[t] : t; | ||
}, | ||
a = function (t) { | ||
var e = {}; | ||
return Object.keys(t).forEach(function (r) { | ||
e[c(r)] = c(t[r]); | ||
}), e; | ||
}; | ||
return valueToSource(recipe); | ||
}; | ||
return o.forEach(function (t) { | ||
if ("composite" === t.type) { | ||
t.valueOfIdentifier = c(t.valueOfIdentifier), t.prototypeIdentifier = c(t.prototypeIdentifier); | ||
var e = t.propertiesDescription, | ||
r = {}; | ||
Object.keys(e).forEach(function (t) { | ||
r[c(t)] = a(e[t]); | ||
}), t.propertiesDescription = r; | ||
var n = t.symbolsDescription, | ||
o = {}; | ||
Object.keys(n).forEach(function (t) { | ||
o[c(t)] = a(n[t]); | ||
}), t.symbolsDescription = o; | ||
var i = t.methodsDescription, | ||
f = {}; | ||
Object.keys(i).forEach(function (t) { | ||
var e = i[t].map(function (t) { | ||
return t.map(function (t) { | ||
return c(t); | ||
}); | ||
}); | ||
f[c(t)] = e; | ||
}), t.methodsDescription = f; | ||
} | ||
}), { | ||
recipeArray: o, | ||
mainIdentifier: c(r) | ||
}; | ||
}(u(t, { | ||
functionAllowed: void 0 !== e && e | ||
}))), | ||
n = D.toString(), | ||
o = I(r); | ||
return "(".concat(n, ")(").concat(o, ")"); | ||
}, t; | ||
exports.uneval = uneval; | ||
return exports; | ||
}({}); | ||
//# sourceMappingURL=./main.js.map |
{ | ||
"name": "@dmail/uneval", | ||
"version": "5.1.0", | ||
"version": "5.2.0", | ||
"license": "MIT", | ||
@@ -5,0 +5,0 @@ "repository": { |
@@ -1,6 +0,8 @@ | ||
export const recompose = ({ recipeArray, mainIdentifier }) => { | ||
const globalObject = typeof window === "object" ? window : global | ||
const materials = {} | ||
export function recompose(param) { | ||
var recipeArray = param.recipeArray | ||
var mainIdentifier = param.mainIdentifier | ||
var globalObject = typeof window === "object" ? window : global | ||
var materials = {} | ||
const setupMaterial = (recipe) => { | ||
function setupMaterial(recipe) { | ||
if (recipe.type === "primitive") return setupPrimitiveMaterial(recipe) | ||
@@ -12,11 +14,16 @@ if (recipe.type === "global-symbol") return setupGlobalSymbolMaterial(recipe) | ||
const setupPrimitiveMaterial = ({ value }) => value | ||
function setupPrimitiveMaterial(recipe) { | ||
return recipe.value | ||
} | ||
const setupGlobalSymbolMaterial = ({ key }) => Symbol.for(key) | ||
function setupGlobalSymbolMaterial(recipe) { | ||
return Symbol.for(recipe.key) | ||
} | ||
const setupGlobalReferenceMaterial = ({ path }) => { | ||
let currentValue = globalObject | ||
let i = 0 | ||
function setupGlobalReferenceMaterial(recipe) { | ||
var path = recipe.path | ||
var currentValue = globalObject | ||
var i = 0 | ||
while (i < path.length) { | ||
const part = path[i] | ||
var part = path[i] | ||
i++ | ||
@@ -30,10 +37,13 @@ if (part in currentValue === false) | ||
const setupCompositeMaterial = ({ prototypeIdentifier, valueOfIdentifier }) => { | ||
function setupCompositeMaterial(recipe) { | ||
var prototypeIdentifier = recipe.prototypeIdentifier | ||
var valueOfIdentifier = recipe.valueOfIdentifier | ||
// regexp and function | ||
if (prototypeIdentifier === undefined) return materials[valueOfIdentifier] | ||
const prototypeValue = materials[prototypeIdentifier] | ||
var prototypeValue = materials[prototypeIdentifier] | ||
if (prototypeValue === null) return Object.create(null) | ||
const Constructor = prototypeValue.constructor | ||
var Constructor = prototypeValue.constructor | ||
if (Constructor === Object) return Object.create(prototypeValue) | ||
@@ -43,25 +53,23 @@ | ||
const valueOfValue = materials[valueOfIdentifier] | ||
var valueOfValue = materials[valueOfIdentifier] | ||
return new Constructor(valueOfValue) | ||
} | ||
recipeArray.forEach((recipe, index) => { | ||
const value = setupMaterial(recipe) | ||
recipeArray.forEach(function(recipe, index) { | ||
var value = setupMaterial(recipe) | ||
materials[index] = value | ||
}) | ||
const followRecipe = (recipe, index) => { | ||
function followRecipe(recipe, index) { | ||
if (recipe.type === "composite") followCompositeRecipe(recipe, index) | ||
} | ||
const followCompositeRecipe = ( | ||
{ propertiesDescription, symbolsDescription, methodsDescription, extensible = true }, | ||
index, | ||
) => { | ||
const composite = materials[index] | ||
function followCompositeRecipe(recipe, index) { | ||
var composite = materials[index] | ||
var propertiesDescription = recipe.propertiesDescription | ||
if (propertiesDescription) { | ||
Object.keys(propertiesDescription).forEach((propertyNameIdentifier) => { | ||
const propertyName = materials[propertyNameIdentifier] | ||
const description = propertiesDescription[propertyNameIdentifier] | ||
Object.keys(propertiesDescription).forEach(function(propertyNameIdentifier) { | ||
var propertyName = materials[propertyNameIdentifier] | ||
var description = propertiesDescription[propertyNameIdentifier] | ||
defineProperty(composite, propertyName, description) | ||
@@ -71,6 +79,7 @@ }) | ||
var symbolsDescription = recipe.symbolsDescription | ||
if (symbolsDescription) { | ||
Object.keys(symbolsDescription).forEach((symbolIdentifier) => { | ||
const symbol = materials[symbolIdentifier] | ||
const description = symbolsDescription[symbolIdentifier] | ||
Object.keys(symbolsDescription).forEach(function(symbolIdentifier) { | ||
var symbol = materials[symbolIdentifier] | ||
var description = symbolsDescription[symbolIdentifier] | ||
defineProperty(composite, symbol, description) | ||
@@ -80,10 +89,11 @@ }) | ||
var methodsDescription = recipe.methodsDescription | ||
if (methodsDescription) { | ||
Object.keys(methodsDescription).forEach((methodNameIdentifier) => { | ||
const methodName = materials[methodNameIdentifier] | ||
const calls = methodsDescription[methodNameIdentifier] | ||
calls.forEach((argumentIdentifiers) => { | ||
const argumentValues = argumentIdentifiers.map( | ||
(argumentIdentifier) => materials[argumentIdentifier], | ||
) | ||
Object.keys(methodsDescription).forEach(function(methodNameIdentifier) { | ||
var methodName = materials[methodNameIdentifier] | ||
var calls = methodsDescription[methodNameIdentifier] | ||
calls.forEach(function(argumentIdentifiers) { | ||
var argumentValues = argumentIdentifiers.map(function(argumentIdentifier) { | ||
return materials[argumentIdentifier] | ||
}) | ||
composite[methodName](...argumentValues) | ||
@@ -94,14 +104,15 @@ }) | ||
var extensible = recipe.extensible || true | ||
if (!extensible) Object.preventExtensions(composite) | ||
} | ||
const defineProperty = (composite, propertyNameOrSymbol, propertyDescription) => { | ||
const currentDescriptor = Object.getOwnPropertyDescriptor(composite, propertyNameOrSymbol) | ||
function defineProperty(composite, propertyNameOrSymbol, propertyDescription) { | ||
var currentDescriptor = Object.getOwnPropertyDescriptor(composite, propertyNameOrSymbol) | ||
if (currentDescriptor && currentDescriptor.configurable === false) return | ||
const descriptor = {} | ||
Object.keys(propertyDescription).forEach((descriptorNameIdentifier) => { | ||
const descriptorValueIdentifier = propertyDescription[descriptorNameIdentifier] | ||
const descriptorName = materials[descriptorNameIdentifier] | ||
const descriptorValue = materials[descriptorValueIdentifier] | ||
var descriptor = {} | ||
Object.keys(propertyDescription).forEach(function(descriptorNameIdentifier) { | ||
var descriptorValueIdentifier = propertyDescription[descriptorNameIdentifier] | ||
var descriptorName = materials[descriptorNameIdentifier] | ||
var descriptorValue = materials[descriptorValueIdentifier] | ||
descriptor[descriptorName] = descriptorValue | ||
@@ -112,11 +123,20 @@ }) | ||
recipeArray.forEach((recipe, index) => { | ||
recipeArray.forEach(function(recipe, index) { | ||
followRecipe(recipe, index) | ||
}) | ||
const createValueNotFoundErrorMessage = ({ path, index }) => `value not found for path. | ||
part not found: ${path[index]} | ||
path: ${path.join(",")}` | ||
function createValueNotFoundErrorMessage(data) { | ||
var path = data.path | ||
var index = data.index | ||
var message = "value not found for path." | ||
message += "\n" | ||
// eslint-disable-next-line prefer-template | ||
message += "part not found: " + path[index] | ||
message += "\n" | ||
// eslint-disable-next-line prefer-template | ||
message += "path: " + path.join("") | ||
return message | ||
} | ||
return materials[mainIdentifier] | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
152782
1941