MCPcopy Create free account
hub / github.com/arktypeio/arktype / getLocationWithOffset

Function getLocationWithOffset

ark/fs/getCurrentLine.ts:134–184  ·  view source on GitHub ↗
(locations: Array<Location>, offset: Offset)

Source from the content-addressed store, hash-verified

132 * If none are found, return the failure location
133 */
134const getLocationWithOffset = (locations: Array<Location>, offset: Offset) => {
135 // Continue
136 let found: boolean = !offset.file && !offset.method
137
138 // use while loop so we can skip ahead
139 let i = 0
140 while (i < locations.length) {
141 const location = locations[i]
142
143 // the current location matches the offset
144 if (
145 (offset.file &&
146 (typeof offset.file === "string" ?
147 location.file.includes(offset.file)
148 : offset.file.test(location.file))) ||
149 (offset.method &&
150 (typeof offset.method === "string" ?
151 location.method.includes(offset.method)
152 : offset.method.test(location.method)))
153 ) {
154 // we are found, and we should exit immediatelyg, so return with the frame offset applied
155 if (offset.immediate) {
156 // apply frame offset
157 i += offset.frames || 0
158 // and return the result
159 return locations[i]
160 }
161 // otherwise, continue until the found condition has exited
162 else {
163 found = true
164 ++i
165 continue
166 }
167 }
168 // has been found, and the found condition has exited, so return with the frame offset applied
169 else if (found) {
170 // apply frame offset
171 i += offset.frames || 0
172 // and return the result
173 return locations[i]
174 }
175 // nothing has been found yet, so continue until we find the offset
176 else {
177 ++i
178 continue
179 }
180 }
181
182 // return failure
183 return failureLocation
184}
185
186/**
187 * Get each error stack frame's location information.

Callers 1

getLocationFromErrorFunction · 0.85

Calls 1

testMethod · 0.80

Tested by

no test coverage detected