/
opt
/
canhelp
/
node_modules
/
next
/
dist
/
shared
/
lib
/
router
/
utils
/
/opt/canhelp/node_modules/next/dist/shared/lib/router/utils
mkdir
upload
Name
Size
Mode
Actions
add-locale.d.ts
365
0644
edit
dl
rm
add-locale.js
1049
0644
edit
dl
rm
add-locale.js.map
1715
0644
edit
dl
rm
add-path-prefix.d.ts
200
0644
edit
dl
rm
add-path-prefix.js
536
0644
edit
dl
rm
add-path-prefix.js.map
885
0644
edit
dl
rm
add-path-suffix.d.ts
258
0644
edit
dl
rm
add-path-suffix.js
536
0644
edit
dl
rm
add-path-suffix.js.map
944
0644
edit
dl
rm
app-paths.d.ts
900
0644
edit
dl
rm
app-paths.js
1504
0644
edit
dl
rm
app-paths.js.map
2712
0644
edit
dl
rm
as-path-to-search-params.d.ts
79
0644
edit
dl
rm
as-path-to-search-params.js
484
0644
edit
dl
rm
as-path-to-search-params.js.map
565
0644
edit
dl
rm
cache-busting-search-param.d.ts
257
0644
edit
dl
rm
cache-busting-search-param.js
832
0644
edit
dl
rm
cache-busting-search-param.js.map
1315
0644
edit
dl
rm
compare-states.d.ts
146
0644
edit
dl
rm
compare-states.js
1070
0644
edit
dl
rm
compare-states.js.map
1931
0644
edit
dl
rm
disable-smooth-scroll.d.ts
304
0644
edit
dl
rm
disable-smooth-scroll.js
2515
0644
edit
dl
rm
disable-smooth-scroll.js.map
3621
0644
edit
dl
rm
escape-path-delimiters.d.ts
96
0644
edit
dl
rm
escape-path-delimiters.js
508
0644
edit
dl
rm
escape-path-delimiters.js.map
753
0644
edit
dl
rm
format-next-pathname-info.d.ts
261
0644
edit
dl
rm
format-next-pathname-info.js
1290
0644
edit
dl
rm
format-next-pathname-info.js.map
2090
0644
edit
dl
rm
format-url.d.ts
216
0644
edit
dl
rm
format-url.js
3955
0644
edit
dl
rm
format-url.js.map
5739
0644
edit
dl
rm
get-asset-path-from-route.d.ts
84
0644
edit
dl
rm
get-asset-path-from-route.js
639
0644
edit
dl
rm
get-asset-path-from-route.js.map
846
0644
edit
dl
rm
get-dynamic-param.d.ts
2775
0644
edit
dl
rm
get-dynamic-param.js
3976
0644
edit
dl
rm
get-dynamic-param.js.map
7442
0644
edit
dl
rm
get-next-pathname-info.d.ts
1450
0644
edit
dl
rm
get-next-pathname-info.js
2479
0644
edit
dl
rm
get-next-pathname-info.js.map
5178
0644
edit
dl
rm
get-route-from-asset-path.d.ts
88
0644
edit
dl
rm
get-route-from-asset-path.js
931
0644
edit
dl
rm
get-route-from-asset-path.js.map
1324
0644
edit
dl
rm
html-bots.d.ts
53
0644
edit
dl
rm
html-bots.js
1135
0644
edit
dl
rm
html-bots.js.map
1145
0644
edit
dl
rm
index.d.ts
121
0644
edit
dl
rm
index.js
766
0644
edit
dl
rm
index.js.map
430
0644
edit
dl
rm
interception-routes.d.ts
312
0644
edit
dl
rm
interception-routes.js
4354
0644
edit
dl
rm
interception-routes.js.map
5054
0644
edit
dl
rm
interpolate-as.d.ts
195
0644
edit
dl
rm
interpolate-as.js
2242
0644
edit
dl
rm
interpolate-as.js.map
3801
0644
edit
dl
rm
is-bot.d.ts
291
0644
edit
dl
rm
is-bot.js
1764
0644
edit
dl
rm
is-bot.js.map
1998
0644
edit
dl
rm
is-dynamic.d.ts
316
0644
edit
dl
rm
is-dynamic.js
867
0644
edit
dl
rm
is-dynamic.js.map
1489
0644
edit
dl
rm
is-local-url.d.ts
147
0644
edit
dl
rm
is-local-url.js
854
0644
edit
dl
rm
is-local-url.js.map
1271
0644
edit
dl
rm
middleware-route-matcher.d.ts
463
0644
edit
dl
rm
middleware-route-matcher.js
947
0644
edit
dl
rm
middleware-route-matcher.js.map
1762
0644
edit
dl
rm
omit.d.ts
126
0644
edit
dl
rm
omit.js
440
0644
edit
dl
rm
omit.js.map
778
0644
edit
dl
rm
parse-path.d.ts
320
0644
edit
dl
rm
parse-path.js
1041
0644
edit
dl
rm
parse-path.js.map
1510
0644
edit
dl
rm
parse-relative-url.d.ts
745
0644
edit
dl
rm
parse-relative-url.js
1476
0644
edit
dl
rm
parse-relative-url.js.map
3015
0644
edit
dl
rm
parse-url.d.ts
365
0644
edit
dl
rm
parse-url.js
954
0644
edit
dl
rm
parse-url.js.map
1843
0644
edit
dl
rm
path-has-prefix.d.ts
364
0644
edit
dl
rm
path-has-prefix.js
535
0644
edit
dl
rm
path-has-prefix.js.map
996
0644
edit
dl
rm
path-match.d.ts
989
0644
edit
dl
rm
path-match.js
1961
0644
edit
dl
rm
path-match.js.map
3773
0644
edit
dl
rm
prepare-destination.d.ts
1527
0644
edit
dl
rm
prepare-destination.js
10637
0644
edit
dl
rm
prepare-destination.js.map
17187
0644
edit
dl
rm
querystring.d.ts
348
0644
edit
dl
rm
querystring.js
2281
0644
edit
dl
rm
querystring.js.map
3287
0644
edit
dl
rm
relativize-url.d.ts
679
0644
edit
dl
rm
relativize-url.js
1121
0644
edit
dl
rm
relativize-url.js.map
1872
0644
edit
dl
rm
remove-path-prefix.d.ts
389
0644
edit
dl
rm
remove-path-prefix.js
1261
0644
edit
dl
rm
remove-path-prefix.js.map
2000
0644
edit
dl
rm
remove-trailing-slash.d.ts
259
0644
edit
dl
rm
remove-trailing-slash.js
552
0644
edit
dl
rm
remove-trailing-slash.js.map
598
0644
edit
dl
rm
resolve-rewrites.d.ts
682
0644
edit
dl
rm
resolve-rewrites.js
4670
0644
edit
dl
rm
resolve-rewrites.js.map
7781
0644
edit
dl
rm
route-match-utils.d.ts
1513
0644
edit
dl
rm
route-match-utils.js
3675
0644
edit
dl
rm
route-match-utils.js.map
5754
0644
edit
dl
rm
route-matcher.d.ts
384
0644
edit
dl
rm
route-matcher.js
1509
0644
edit
dl
rm
route-matcher.js.map
2558
0644
edit
dl
rm
route-regex.d.ts
3492
0644
edit
dl
rm
route-regex.js
9498
0644
edit
dl
rm
route-regex.js.map
17577
0644
edit
dl
rm
sortable-routes.d.ts
4249
0644
edit
dl
rm
sortable-routes.js
6321
0644
edit
dl
rm
sortable-routes.js.map
12530
0644
edit
dl
rm
sorted-routes.d.ts
344
0644
edit
dl
rm
sorted-routes.js
11664
0644
edit
dl
rm
sorted-routes.js.map
14788
0644
edit
dl
rm
Edit:
/opt/canhelp/node_modules/next/dist/shared/lib/router/utils/sorted-routes.js
(11664B)
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); 0 && (module.exports = { getSortedRouteObjects: null, getSortedRoutes: null }); function _export(target, all) { for(var name in all)Object.defineProperty(target, name, { enumerable: true, get: all[name] }); } _export(exports, { getSortedRouteObjects: function() { return getSortedRouteObjects; }, getSortedRoutes: function() { return getSortedRoutes; } }); class UrlNode { insert(urlPath) { this._insert(urlPath.split('/').filter(Boolean), [], false); } smoosh() { return this._smoosh(); } _smoosh(prefix) { if (prefix === void 0) prefix = '/'; const childrenPaths = [ ...this.children.keys() ].sort(); if (this.slugName !== null) { childrenPaths.splice(childrenPaths.indexOf('[]'), 1); } if (this.restSlugName !== null) { childrenPaths.splice(childrenPaths.indexOf('[...]'), 1); } if (this.optionalRestSlugName !== null) { childrenPaths.splice(childrenPaths.indexOf('[[...]]'), 1); } const routes = childrenPaths.map((c)=>this.children.get(c)._smoosh("" + prefix + c + "/")).reduce((prev, curr)=>[ ...prev, ...curr ], []); if (this.slugName !== null) { routes.push(...this.children.get('[]')._smoosh(prefix + "[" + this.slugName + "]/")); } if (!this.placeholder) { const r = prefix === '/' ? '/' : prefix.slice(0, -1); if (this.optionalRestSlugName != null) { throw Object.defineProperty(new Error('You cannot define a route with the same specificity as a optional catch-all route ("' + r + '" and "' + r + "[[..." + this.optionalRestSlugName + ']]").'), "__NEXT_ERROR_CODE", { value: "E458", enumerable: false, configurable: true }); } routes.unshift(r); } if (this.restSlugName !== null) { routes.push(...this.children.get('[...]')._smoosh(prefix + "[..." + this.restSlugName + "]/")); } if (this.optionalRestSlugName !== null) { routes.push(...this.children.get('[[...]]')._smoosh(prefix + "[[..." + this.optionalRestSlugName + "]]/")); } return routes; } _insert(urlPaths, slugNames, isCatchAll) { if (urlPaths.length === 0) { this.placeholder = false; return; } if (isCatchAll) { throw Object.defineProperty(new Error("Catch-all must be the last part of the URL."), "__NEXT_ERROR_CODE", { value: "E392", enumerable: false, configurable: true }); } // The next segment in the urlPaths list let nextSegment = urlPaths[0]; // Check if the segment matches `[something]` if (nextSegment.startsWith('[') && nextSegment.endsWith(']')) { // Strip `[` and `]`, leaving only `something` let segmentName = nextSegment.slice(1, -1); let isOptional = false; if (segmentName.startsWith('[') && segmentName.endsWith(']')) { // Strip optional `[` and `]`, leaving only `something` segmentName = segmentName.slice(1, -1); isOptional = true; } if (segmentName.startsWith('…')) { throw Object.defineProperty(new Error("Detected a three-dot character ('…') at ('" + segmentName + "'). Did you mean ('...')?"), "__NEXT_ERROR_CODE", { value: "E147", enumerable: false, configurable: true }); } if (segmentName.startsWith('...')) { // Strip `...`, leaving only `something` segmentName = segmentName.substring(3); isCatchAll = true; } if (segmentName.startsWith('[') || segmentName.endsWith(']')) { throw Object.defineProperty(new Error("Segment names may not start or end with extra brackets ('" + segmentName + "')."), "__NEXT_ERROR_CODE", { value: "E421", enumerable: false, configurable: true }); } if (segmentName.startsWith('.')) { throw Object.defineProperty(new Error("Segment names may not start with erroneous periods ('" + segmentName + "')."), "__NEXT_ERROR_CODE", { value: "E288", enumerable: false, configurable: true }); } function handleSlug(previousSlug, nextSlug) { if (previousSlug !== null) { // If the specific segment already has a slug but the slug is not `something` // This prevents collisions like: // pages/[post]/index.js // pages/[id]/index.js // Because currently multiple dynamic params on the same segment level are not supported if (previousSlug !== nextSlug) { // TODO: This error seems to be confusing for users, needs an error link, the description can be based on above comment. throw Object.defineProperty(new Error("You cannot use different slug names for the same dynamic path ('" + previousSlug + "' !== '" + nextSlug + "')."), "__NEXT_ERROR_CODE", { value: "E337", enumerable: false, configurable: true }); } } slugNames.forEach((slug)=>{ if (slug === nextSlug) { throw Object.defineProperty(new Error('You cannot have the same slug name "' + nextSlug + '" repeat within a single dynamic path'), "__NEXT_ERROR_CODE", { value: "E247", enumerable: false, configurable: true }); } if (slug.replace(/\W/g, '') === nextSegment.replace(/\W/g, '')) { throw Object.defineProperty(new Error('You cannot have the slug names "' + slug + '" and "' + nextSlug + '" differ only by non-word symbols within a single dynamic path'), "__NEXT_ERROR_CODE", { value: "E499", enumerable: false, configurable: true }); } }); slugNames.push(nextSlug); } if (isCatchAll) { if (isOptional) { if (this.restSlugName != null) { throw Object.defineProperty(new Error('You cannot use both an required and optional catch-all route at the same level ("[...' + this.restSlugName + ']" and "' + urlPaths[0] + '" ).'), "__NEXT_ERROR_CODE", { value: "E299", enumerable: false, configurable: true }); } handleSlug(this.optionalRestSlugName, segmentName); // slugName is kept as it can only be one particular slugName this.optionalRestSlugName = segmentName; // nextSegment is overwritten to [[...]] so that it can later be sorted specifically nextSegment = '[[...]]'; } else { if (this.optionalRestSlugName != null) { throw Object.defineProperty(new Error('You cannot use both an optional and required catch-all route at the same level ("[[...' + this.optionalRestSlugName + ']]" and "' + urlPaths[0] + '").'), "__NEXT_ERROR_CODE", { value: "E300", enumerable: false, configurable: true }); } handleSlug(this.restSlugName, segmentName); // slugName is kept as it can only be one particular slugName this.restSlugName = segmentName; // nextSegment is overwritten to [...] so that it can later be sorted specifically nextSegment = '[...]'; } } else { if (isOptional) { throw Object.defineProperty(new Error('Optional route parameters are not yet supported ("' + urlPaths[0] + '").'), "__NEXT_ERROR_CODE", { value: "E435", enumerable: false, configurable: true }); } handleSlug(this.slugName, segmentName); // slugName is kept as it can only be one particular slugName this.slugName = segmentName; // nextSegment is overwritten to [] so that it can later be sorted specifically nextSegment = '[]'; } } // If this UrlNode doesn't have the nextSegment yet we create a new child UrlNode if (!this.children.has(nextSegment)) { this.children.set(nextSegment, new UrlNode()); } this.children.get(nextSegment)._insert(urlPaths.slice(1), slugNames, isCatchAll); } constructor(){ this.placeholder = true; this.children = new Map(); this.slugName = null; this.restSlugName = null; this.optionalRestSlugName = null; } } function getSortedRoutes(normalizedPages) { // First the UrlNode is created, and every UrlNode can have only 1 dynamic segment // Eg you can't have pages/[post]/abc.js and pages/[hello]/something-else.js // Only 1 dynamic segment per nesting level // So in the case that is test/integration/dynamic-routing it'll be this: // pages/[post]/comments.js // pages/blog/[post]/comment/[id].js // Both are fine because `pages/[post]` and `pages/blog` are on the same level // So in this case `UrlNode` created here has `this.slugName === 'post'` // And since your PR passed through `slugName` as an array basically it'd including it in too many possibilities // Instead what has to be passed through is the upwards path's dynamic names const root = new UrlNode(); // Here the `root` gets injected multiple paths, and insert will break them up into sublevels normalizedPages.forEach((pagePath)=>root.insert(pagePath)); // Smoosh will then sort those sublevels up to the point where you get the correct route definition priority return root.smoosh(); } function getSortedRouteObjects(objects, getter) { // We're assuming here that all the pathnames are unique, that way we can // sort the list and use the index as the key. const indexes = {}; const pathnames = []; for(let i = 0; i < objects.length; i++){ const pathname = getter(objects[i]); indexes[pathname] = i; pathnames[i] = pathname; } // Sort the pathnames. const sorted = getSortedRoutes(pathnames); // Map the sorted pathnames back to the original objects using the new sorted // index. return sorted.map((pathname)=>objects[indexes[pathname]]); } //# sourceMappingURL=sorted-routes.js.map
Save
cmd:
run