The members of the object literal whose `{` is at `open`.
(s: string, open: number)
| 99 | |
| 100 | /** The members of the object literal whose `{` is at `open`. */ |
| 101 | function objectMembers(s: string, open: number): RawMember[] { |
| 102 | const close = matchClose(s, open); |
| 103 | if (close < 0) return []; |
| 104 | const out: RawMember[] = []; |
| 105 | let i = open + 1; |
| 106 | while (i < close) { |
| 107 | // Skip separators, whitespace and comments between members. |
| 108 | const ws = /^(?:\s|,|\/\/[^\n]*|\/\*[\s\S]*?\*\/)+/.exec(s.slice(i, close)); |
| 109 | if (ws) { |
| 110 | i += ws[0].length; |
| 111 | continue; |
| 112 | } |
| 113 | const start = i; |
| 114 | // `async name(…)`, `*name(…)`, `get name()`, `'quoted-key'`, `name`, `...spread` |
| 115 | const head = /^(?:(?:async|get|set)\s+(?=[\w$'"[]))?\*?\s*(?:([A-Za-z_$][\w$]*)|(['"])((?:(?!\2).)*)\2|(\[)|(\.\.\.))/.exec(s.slice(i, close)); |
| 116 | if (!head) { |
| 117 | i++; |
| 118 | continue; |
| 119 | } |
| 120 | const name = head[1] ?? head[3] ?? null; |
| 121 | let j = i + head[0].length; |
| 122 | if (head[5] !== undefined) { |
| 123 | // A computed key — `[KEY]() {}` — has no static name; step over it. |
| 124 | const keyClose = matchClose(s, j - 1); |
| 125 | if (keyClose < 0) return out; |
| 126 | j = keyClose + 1; |
| 127 | } |
| 128 | // Where this member ends: the next depth-0 comma, or the object's end. |
| 129 | let k = j; |
| 130 | while (k < close) { |
| 131 | const ch = s[k]!; |
| 132 | if (ch === '"' || ch === "'" || ch === '`') { |
| 133 | const end = skipQuoted(s, k); |
| 134 | if (end < 0) return out; |
| 135 | k = end; |
| 136 | continue; |
| 137 | } |
| 138 | if (ch === '/' && (s[k + 1] === '/' || s[k + 1] === '*')) { |
| 139 | const end = s[k + 1] === '/' ? s.indexOf('\n', k) : s.indexOf('*/', k + 2) + 1; |
| 140 | k = end <= 0 ? close : end + 1; |
| 141 | continue; |
| 142 | } |
| 143 | if (ch === '{' || ch === '[' || ch === '(') { |
| 144 | const end = matchClose(s, k); |
| 145 | if (end < 0) return out; |
| 146 | k = end + 1; |
| 147 | continue; |
| 148 | } |
| 149 | if (ch === ',') break; |
| 150 | k++; |
| 151 | } |
| 152 | const rest = s.slice(j, k); |
| 153 | const colon = /^\s*:/.exec(rest); |
| 154 | if (name !== null && head[6] === undefined) { |
| 155 | out.push({ |
| 156 | name, |
| 157 | start, |
| 158 | valueAt: colon ? j + colon[0].length : j, |
no test coverage detected