(properties, start = 0)
| 80 | * @returns {string} chain of property accesses |
| 81 | */ |
| 82 | const propertyAccess = (properties, start = 0) => { |
| 83 | let str = ""; |
| 84 | for (let i = start; i < properties.length; i++) { |
| 85 | const p = properties[i]; |
| 86 | // Only first chars 0-9, "-", "N", "I" can begin a canonical numeric form |
| 87 | // (number, NaN, Infinity); skip the Number() round-trip otherwise. |
| 88 | const c = p.charCodeAt(0); |
| 89 | if ( |
| 90 | ((c >= 48 && c <= 57) || c === 45 || c === 78 || c === 73) && |
| 91 | `${Number(p)}` === p |
| 92 | ) { |
| 93 | str += `[${p}]`; |
| 94 | } else if (SAFE_IDENTIFIER.test(p) && !RESERVED_IDENTIFIER.has(p)) { |
| 95 | str += `.${p}`; |
| 96 | } else { |
| 97 | str += `[${JSON.stringify(p)}]`; |
| 98 | } |
| 99 | } |
| 100 | return str; |
| 101 | }; |
| 102 | |
| 103 | module.exports = { |
| 104 | RESERVED_IDENTIFIER, |
no test coverage detected