MCPcopy Create free account
hub / github.com/Effect-TS/effect / resolveTable

Method resolveTable

packages/effect/src/unstable/encoding/Toml.ts:98–131  ·  view source on GitHub ↗
(path: ReadonlyArray<string>, array: boolean)

Source from the content-addressed store, hash-verified

96 }
97
98 private resolveTable(path: ReadonlyArray<string>, array: boolean): Table {
99 let table = this.root
100 for (let index = 0; index < path.length; index++) {
101 const key = path[index]
102 const last = index === path.length - 1
103 let value = table[key]
104
105 if (last && array) {
106 if (value === undefined) {
107 value = []
108 table[key] = value
109 }
110 if (!Array.isArray(value)) {
111 this.fail(`Cannot redefine existing key '${path.slice(0, index + 1).join(".")}'`)
112 }
113 const next = makeTable()
114 value.push(next)
115 return next
116 }
117
118 if (value === undefined) {
119 value = makeTable()
120 table[key] = value
121 }
122 if (Array.isArray(value)) {
123 value = value[value.length - 1]
124 }
125 if (!isTable(value)) {
126 this.fail(`Cannot redefine existing key '${path.slice(0, index + 1).join(".")}'`)
127 }
128 table = value
129 }
130 return table
131 }
132
133 private assign(target: Table, keys: ReadonlyArray<string>, value: unknown): void {
134 let table = target

Callers 1

parseHeaderMethod · 0.95

Calls 5

failMethod · 0.95
makeTableFunction · 0.85
isTableFunction · 0.85
joinMethod · 0.80
pushMethod · 0.80

Tested by

no test coverage detected