| 232 | } |
| 233 | |
| 234 | export class GenericKeyFn implements ExpressionKeyFn { |
| 235 | static readonly INSTANCE = new GenericKeyFn(); |
| 236 | |
| 237 | keyOf(expr: o.Expression): string { |
| 238 | if (expr instanceof o.LiteralExpr && typeof expr.value === 'string') { |
| 239 | return `"${expr.value}"`; |
| 240 | } else if (expr instanceof o.LiteralExpr) { |
| 241 | return String(expr.value); |
| 242 | } else if (expr instanceof o.RegularExpressionLiteralExpr) { |
| 243 | return `/${expr.body}/${expr.flags ?? ''}`; |
| 244 | } else if (expr instanceof o.LiteralArrayExpr) { |
| 245 | const entries: string[] = []; |
| 246 | for (const entry of expr.entries) { |
| 247 | entries.push(this.keyOf(entry)); |
| 248 | } |
| 249 | return `[${entries.join(',')}]`; |
| 250 | } else if (expr instanceof o.LiteralMapExpr) { |
| 251 | const entries: string[] = []; |
| 252 | for (const entry of expr.entries) { |
| 253 | if (entry instanceof o.LiteralMapSpreadAssignment) { |
| 254 | entries.push('...' + this.keyOf(entry.expression)); |
| 255 | } else { |
| 256 | let key = entry.key; |
| 257 | if (entry.quoted) { |
| 258 | key = `"${key}"`; |
| 259 | } |
| 260 | entries.push(key + ':' + this.keyOf(entry.value)); |
| 261 | } |
| 262 | } |
| 263 | return `{${entries.join(',')}}`; |
| 264 | } else if (expr instanceof o.ExternalExpr) { |
| 265 | return `import("${expr.value.moduleName}", ${expr.value.name})`; |
| 266 | } else if (expr instanceof o.ReadVarExpr) { |
| 267 | return `read(${expr.name})`; |
| 268 | } else if (expr instanceof o.TypeofExpr) { |
| 269 | return `typeof(${this.keyOf(expr.expr)})`; |
| 270 | } else if (expr instanceof o.SpreadElementExpr) { |
| 271 | return `...${this.keyOf(expr.expression)}`; |
| 272 | } else { |
| 273 | throw new Error( |
| 274 | `${this.constructor.name} does not handle expressions of type ${expr.constructor.name}`, |
| 275 | ); |
| 276 | } |
| 277 | } |
| 278 | } |
| 279 | |
| 280 | function isLongStringLiteral(expr: o.Expression): boolean { |
| 281 | return ( |
nothing calls this directly
no outgoing calls
no test coverage detected