Reduce/enforce complexity in property-override
MODIFY
packages/enable-property-overrides/.eslintrc.json
packages/enable-property-overrides/.eslintrc.json
"es6": true
},
"rules": {
+ "complexity": ["error", 8],
"implicit-arrow-linebreak": "off",
"function-paren-newline": "off",
"arrow-parens": "off",

MODIFY
packages/enable-property-overrides/src/main.js
packages/enable-property-overrides/src/main.js
import enablements from './enablements.js';
const {
- assign,
defineProperties,
getOwnPropertyNames,
getOwnPropertyDescriptor,
@@ -34,29 +33,20 @@ function isObject(obj) {
*/
// TODO exmplain parameters
-export default function enablePropertyOverrides(
- intrinsics,
- attachPropertyValues = false,
-) {
+export default function enablePropertyOverrides(intrinsics) {
const detachedProperties = {};
function enable(path, obj, prop, desc) {
if ('value' in desc && desc.configurable) {
const { value } = desc;
+ detachedProperties[path] = value;
+
// eslint-disable-next-line no-inner-declarations
function getter() {
return value;
}
- if (attachPropertyValues) {
- // Re-attach the property value on the object so
- // it can be found by the deep-freeze traversal process.
- getter.value = value;
- } else {
- detachedProperties[path] = value;
- }
-
// eslint-disable-next-line no-inner-declarations
function setter(newValue) {
if (obj === this) {
@@ -119,20 +109,13 @@ export default function enablePropertyOverrides(
const subPath = `${path}.${prop}`;
const subPlan = plan[prop];
- switch (subPlan) {
- case true:
+ if (subPlan === true) {
enableProperty(subPath, obj, prop);
- break;
-
- case '*':
+ } else if (subPlan === '*') {
enableAllProperties(subPath, desc.value);
- break;
-
- default:
- if (isObject(subPlan)) {
+ } else if (isObject(subPlan)) {
enableProperties(subPath, desc.value, subPlan);
- break;
- }
+ } else {
throw new TypeError(`Unexpected override enablement plan ${subPath}`);
}
}

Reduce/enforce complexity in property-override