(descriptors)
| 4 | ---*/ |
| 5 | |
| 6 | function func(descriptors) { |
| 7 | const obj = {} |
| 8 | |
| 9 | for (const [key, descriptor] of Object.entries(descriptors)) { |
| 10 | const type = |
| 11 | typeof descriptor.type == 'string' |
| 12 | ? descriptor.type.toLowerCase() |
| 13 | : typeof descriptor.type.name == 'string' |
| 14 | ? descriptor.type.name.toLowerCase() |
| 15 | : '' |
| 16 | if ((type == 'digital')) { |
| 17 | if (typeof descriptor.mode == 'string') { |
| 18 | // It should be possible to declare using const, but the let to be declared next will be treated as const. |
| 19 | const mode = descriptor.mode.toLowerCase() |
| 20 | if (mode == 'output') descriptor.mode = 1 |
| 21 | } |
| 22 | if (descriptor.mode == 1) { |
| 23 | let value = descriptor.default || false |
| 24 | //value = !value // ERROR!! set value: const! |
| 25 | |
| 26 | Object.defineProperty(obj, key, { |
| 27 | get() { |
| 28 | return value |
| 29 | }, |
| 30 | set(val) { |
| 31 | value = val // ERROR!! set value: const! |
| 32 | }, |
| 33 | enumerable: true, |
| 34 | }) |
| 35 | } |
| 36 | } |
| 37 | } |
| 38 | |
| 39 | return obj |
| 40 | } |
| 41 | |
| 42 | const obj = func({ |
| 43 | prop: { |
no outgoing calls
no test coverage detected