transforms data's elements, into the copy before the first change or, without one, in place
( data: array, ctx: InternalTraversal, copy: ((data: array) => object) | undefined )
| 397 | |
| 398 | /** transforms data's elements, into the copy before the first change or, without one, in place */ |
| 399 | tfElems( |
| 400 | data: array, |
| 401 | ctx: InternalTraversal, |
| 402 | copy: ((data: array) => object) | undefined |
| 403 | ): array { |
| 404 | let out = data as unknown[] |
| 405 | for (let i = 0; i < data.length; i++) { |
| 406 | const node = this.atIndex(data, i).node |
| 407 | if (!node.tfs) continue |
| 408 | // an undefined a default replaces isn't transformed first |
| 409 | if ( |
| 410 | i >= this.preLen && |
| 411 | i < this.preLen + this.defLen && |
| 412 | !this.holdsElement(data, i) |
| 413 | ) |
| 414 | continue |
| 415 | const element = data[i] |
| 416 | const transformed = travKey(i, () => transform(ctx, node, element), ctx) |
| 417 | if (Object.is(transformed, element)) continue |
| 418 | if (out === data && copy) out = copy(data) as unknown[] |
| 419 | out[i] = transformed |
| 420 | } |
| 421 | return out |
| 422 | } |
| 423 | |
| 424 | // minLength/maxLength compilation should be handled by Intersection |
| 425 | compile(js: NodeCompiler): void { |