|
import { exec, parse_route_id } from '../../utils/routing.js'; |
|
|
|
|
|
|
|
|
|
|
|
export function parse({ nodes, server_loads, dictionary, matchers }) { |
|
const layouts_with_server_load = new Set(server_loads); |
|
|
|
return Object.entries(dictionary).map(([id, [leaf, layouts, errors]]) => { |
|
const { pattern, params } = parse_route_id(id); |
|
|
|
const route = { |
|
id, |
|
|
|
exec: (path) => { |
|
const match = pattern.exec(path); |
|
if (match) return exec(match, params, matchers); |
|
}, |
|
errors: [1, ...(errors || [])].map((n) => nodes[n]), |
|
layouts: [0, ...(layouts || [])].map(create_layout_loader), |
|
leaf: create_leaf_loader(leaf) |
|
}; |
|
|
|
|
|
|
|
|
|
route.errors.length = route.layouts.length = Math.max( |
|
route.errors.length, |
|
route.layouts.length |
|
); |
|
|
|
return route; |
|
}); |
|
|
|
|
|
|
|
|
|
|
|
function create_leaf_loader(id) { |
|
|
|
|
|
const uses_server_data = id < 0; |
|
if (uses_server_data) id = ~id; |
|
return [uses_server_data, nodes[id]]; |
|
} |
|
|
|
|
|
|
|
|
|
|
|
function create_layout_loader(id) { |
|
|
|
|
|
return id === undefined ? id : [layouts_with_server_load.has(id), nodes[id]]; |
|
} |
|
} |
|
|