|
1 | 1 | import { HttpError, Redirect, ActionFailure } from '../runtime/control.js'; |
2 | 2 | import { BROWSER, DEV } from 'esm-env'; |
3 | | -import { get_route_segments } from '../utils/routing.js'; |
4 | 3 |
|
5 | 4 | export { VERSION } from '../version.js'; |
6 | 5 |
|
@@ -183,58 +182,3 @@ export function fail(status, data) { |
183 | 182 | // @ts-expect-error unique symbol missing |
184 | 183 | return new ActionFailure(status, data); |
185 | 184 | } |
186 | | - |
187 | | -const basic_param_pattern = /\[(\[)?(\.\.\.)?(\w+?)(?:=(\w+))?\]\]?/g; |
188 | | - |
189 | | -let warned = false; |
190 | | - |
191 | | -/** |
192 | | - * @deprecated Use `resolveRoute` from `$app/paths` instead. |
193 | | - * |
194 | | - * Populate a route ID with params to resolve a pathname. |
195 | | - * @example |
196 | | - * ```js |
197 | | - * resolvePath( |
198 | | - * `/blog/[slug]/[...somethingElse]`, |
199 | | - * { |
200 | | - * slug: 'hello-world', |
201 | | - * somethingElse: 'something/else' |
202 | | - * } |
203 | | - * ); // `/blog/hello-world/something/else` |
204 | | - * ``` |
205 | | - * @param {string} id |
206 | | - * @param {Record<string, string | undefined>} params |
207 | | - * @returns {string} |
208 | | - */ |
209 | | -export function resolvePath(id, params) { |
210 | | - if (!warned) { |
211 | | - console.warn('`resolvePath` is deprecated. Use `resolveRoute` from `$app/paths` instead.'); |
212 | | - warned = true; |
213 | | - } |
214 | | - |
215 | | - const segments = get_route_segments(id); |
216 | | - return ( |
217 | | - '/' + |
218 | | - segments |
219 | | - .map((segment) => |
220 | | - segment.replace(basic_param_pattern, (_, optional, rest, name) => { |
221 | | - const param_value = params[name]; |
222 | | - |
223 | | - // This is nested so TS correctly narrows the type |
224 | | - if (!param_value) { |
225 | | - if (optional) return ''; |
226 | | - if (rest && param_value !== undefined) return ''; |
227 | | - throw new Error(`Missing parameter '${name}' in route ${id}`); |
228 | | - } |
229 | | - |
230 | | - if (param_value.startsWith('/') || param_value.endsWith('/')) |
231 | | - throw new Error( |
232 | | - `Parameter '${name}' in route ${id} cannot start or end with a slash -- this would cause an invalid route like foo//bar` |
233 | | - ); |
234 | | - return param_value; |
235 | | - }) |
236 | | - ) |
237 | | - .filter(Boolean) |
238 | | - .join('/') |
239 | | - ); |
240 | | -} |
0 commit comments