MCPcopy
hub / github.com/sveltejs/kit / walk

Function walk

packages/kit/src/core/sync/create_manifest_data/index.js:139–359  ·  view source on GitHub ↗
(depth, id, segment, parent)

Source from the content-addressed store, hash-verified

137 * @param {import('types').RouteData | null} parent
138 */
139 const walk = (depth, id, segment, parent) => {
140 const unescaped = id.replace(/\[([ux])\+([^\]]+)\]/gi, (match, type, code) => {
141 if (match !== match.toLowerCase()) {
142 throw new Error(`Character escape sequence in ${id} must be lowercase`);
143 }
144
145 if (!/[0-9a-f]+/.test(code)) {
146 throw new Error(`Invalid character escape sequence in ${id}`);
147 }
148
149 if (type === 'x') {
150 if (code.length !== 2) {
151 throw new Error(`Hexadecimal escape sequence in ${id} must be two characters`);
152 }
153
154 return String.fromCharCode(parseInt(code, 16));
155 } else {
156 if (code.length < 4 || code.length > 6) {
157 throw new Error(
158 `Unicode escape sequence in ${id} must be between four and six characters`
159 );
160 }
161
162 return String.fromCharCode(parseInt(code, 16));
163 }
164 });
165
166 if (/\]\[/.test(unescaped)) {
167 throw new Error(`Invalid route ${id} — parameters must be separated`);
168 }
169
170 if (count_occurrences('[', id) !== count_occurrences(']', id)) {
171 throw new Error(`Invalid route ${id} — brackets are unbalanced`);
172 }
173
174 if (/#/.test(segment)) {
175 // Vite will barf on files with # in them
176 throw new Error(`Route ${id} should be renamed to ${id.replace(/#/g, '[x+23]')}`);
177 }
178
179 if (/\[\.\.\.\w+\]\/\[\[/.test(id)) {
180 throw new Error(
181 `Invalid route ${id} — an [[optional]] route segment cannot follow a [...rest] route segment`
182 );
183 }
184
185 if (/\[\[\.\.\./.test(id)) {
186 throw new Error(
187 `Invalid route ${id} — a rest route segment is always optional, remove the outer square brackets`
188 );
189 }
190
191 const { pattern, params } = parse_route_id(id);
192
193 /** @type {import('types').RouteData} */
194 const route = {
195 id,
196 parent,

Callers 4

prerenderFunction · 0.90
write_all_typesFunction · 0.90
create_routes_and_nodesFunction · 0.90
create_remotesFunction · 0.90

Calls 5

parse_route_idFunction · 0.90
posixifyFunction · 0.90
count_occurrencesFunction · 0.85
duplicate_files_errorFunction · 0.85
analyzeFunction · 0.70

Tested by

no test coverage detected