Skip to content

Commit

Permalink
move some stuff out of client-facing code (#6557)
Browse files Browse the repository at this point in the history
  • Loading branch information
Rich-Harris authored Sep 4, 2022
1 parent e40a37c commit a36cdd9
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 20 deletions.
20 changes: 20 additions & 0 deletions packages/kit/src/core/sync/create_manifest_data/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,14 @@ function create_routes_and_nodes(cwd, config, fallback) {
* @param {import('types').RouteData | null} parent
*/
const walk = (depth, id, segment, parent) => {
if (/\]\[/.test(id)) {
throw new Error(`Invalid route ${id} — parameters must be separated`);
}

if (count_occurrences('[', id) !== count_occurrences(']', id)) {
throw new Error(`Invalid route ${id} — brackets are unbalanced`);
}

const { pattern, names, types } = parse_route_id(id);

const segments = id.split('/');
Expand Down Expand Up @@ -450,3 +458,15 @@ function list_files(dir) {

return files;
}

/**
* @param {string} needle
* @param {string} haystack
*/
function count_occurrences(needle, haystack) {
let count = 0;
for (let i = 0; i < haystack.length; i += 1) {
if (haystack[i] === needle) count += 1;
}
return count;
}
20 changes: 0 additions & 20 deletions packages/kit/src/utils/routing.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,6 @@ export function parse_route_id(id) {
// const add_trailing_slash = !/\.[a-z]+$/.test(key);
let add_trailing_slash = true;

if (/\]\[/.test(id)) {
throw new Error(`Invalid route ${id} — parameters must be separated`);
}

if (count_occurrences('[', id) !== count_occurrences(']', id)) {
throw new Error(`Invalid route ${id} — brackets are unbalanced`);
}

const pattern =
id === ''
? /^\/$/
Expand Down Expand Up @@ -123,15 +115,3 @@ export function exec(match, names, types, matchers) {

return params;
}

/**
* @param {string} needle
* @param {string} haystack
*/
function count_occurrences(needle, haystack) {
let count = 0;
for (let i = 0; i < haystack.length; i += 1) {
if (haystack[i] === needle) count += 1;
}
return count;
}

0 comments on commit a36cdd9

Please sign in to comment.