| 15 | | ["remap", number, PropertyPath, ["import", number][], MapInstruction[]] |
| 16 | |
| 17 | class MapBuilder implements Exporter { |
| 18 | private context: |
| 19 | | {parent: undefined, captures: StubHook[], subject: StubHook, path: PropertyPath} |
| 20 | | {parent: MapBuilder, captures: number[], subject: number, path: PropertyPath}; |
| 21 | private captureMap: Map<StubHook, number> = new Map(); |
| 22 | |
| 23 | private instructions: MapInstruction[] = []; |
| 24 | |
| 25 | constructor(subject: StubHook, path: PropertyPath) { |
| 26 | if (currentMapBuilder) { |
| 27 | this.context = { |
| 28 | parent: currentMapBuilder, |
| 29 | captures: [], |
| 30 | subject: currentMapBuilder.capture(subject), |
| 31 | path |
| 32 | }; |
| 33 | } else { |
| 34 | this.context = { |
| 35 | parent: undefined, |
| 36 | captures: [], |
| 37 | subject, |
| 38 | path |
| 39 | }; |
| 40 | } |
| 41 | |
| 42 | currentMapBuilder = this; |
| 43 | } |
| 44 | |
| 45 | unregister() { |
| 46 | currentMapBuilder = this.context.parent; |
| 47 | } |
| 48 | |
| 49 | makeInput(): MapVariableHook { |
| 50 | return new MapVariableHook(this, 0); |
| 51 | } |
| 52 | |
| 53 | makeOutput(result: RpcPayload): StubHook { |
| 54 | let devalued: unknown; |
| 55 | try { |
| 56 | devalued = Devaluator.devaluate(result.value, undefined, this, result); |
| 57 | } finally { |
| 58 | result.dispose(); |
| 59 | } |
| 60 | |
| 61 | // The result is the final instruction. This doesn't actually fit our MapInstruction type |
| 62 | // signature, so we cheat a bit. |
| 63 | this.instructions.push(<any>devalued); |
| 64 | |
| 65 | if (this.context.parent) { |
| 66 | this.context.parent.instructions.push( |
| 67 | ["remap", this.context.subject, this.context.path, |
| 68 | this.context.captures.map(cap => ["import", cap]), |
| 69 | this.instructions] |
| 70 | ); |
| 71 | return new MapVariableHook(this.context.parent, this.context.parent.instructions.length); |
| 72 | } else { |
| 73 | return this.context.subject.map(this.context.path, this.context.captures, this.instructions); |
| 74 | } |
nothing calls this directly
no outgoing calls
no test coverage detected
searching dependent graphs…