@sveltejs/kit 1.0.0-next.351 → 1.0.0-next.354

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,78 +0,0 @@
1
- const param_pattern = /^(\.\.\.)?(\w+)(?:=(\w+))?$/;
2
-
3
- /** @param {string} id */
4
- function parse_route_id(id) {
5
- /** @type {string[]} */
6
- const names = [];
7
-
8
- /** @type {string[]} */
9
- const types = [];
10
-
11
- // `/foo` should get an optional trailing slash, `/foo.json` should not
12
- // const add_trailing_slash = !/\.[a-z]+$/.test(key);
13
- let add_trailing_slash = true;
14
-
15
- const pattern =
16
- id === ''
17
- ? /^\/$/
18
- : new RegExp(
19
- `^${decodeURIComponent(id)
20
- .split(/(?:@[a-zA-Z0-9_-]+)?(?:\/|$)/)
21
- .map((segment, i, segments) => {
22
- // special case — /[...rest]/ could contain zero segments
23
- const match = /^\[\.\.\.(\w+)(?:=(\w+))?\]$/.exec(segment);
24
- if (match) {
25
- names.push(match[1]);
26
- types.push(match[2]);
27
- return '(?:/(.*))?';
28
- }
29
-
30
- const is_last = i === segments.length - 1;
31
-
32
- return (
33
- segment &&
34
- '/' +
35
- segment
36
- .split(/\[(.+?)\]/)
37
- .map((content, i) => {
38
- if (i % 2) {
39
- const [, rest, name, type] = /** @type {RegExpMatchArray} */ (
40
- param_pattern.exec(content)
41
- );
42
- names.push(name);
43
- types.push(type);
44
- return rest ? '(.*?)' : '([^/]+?)';
45
- }
46
-
47
- if (is_last && content.includes('.')) add_trailing_slash = false;
48
-
49
- return (
50
- content // allow users to specify characters on the file system in an encoded manner
51
- .normalize()
52
- // We use [ and ] to denote parameters, so users must encode these on the file
53
- // system to match against them. We don't decode all characters since others
54
- // can already be epressed and so that '%' can be easily used directly in filenames
55
- .replace(/%5[Bb]/g, '[')
56
- .replace(/%5[Dd]/g, ']')
57
- // '#', '/', and '?' can only appear in URL path segments in an encoded manner.
58
- // They will not be touched by decodeURI so need to be encoded here, so
59
- // that we can match against them.
60
- // We skip '/' since you can't create a file with it on any OS
61
- .replace(/#/g, '%23')
62
- .replace(/\?/g, '%3F')
63
- // escape characters that have special meaning in regex
64
- .replace(/[.*+?^${}()|[\]\\]/g, '\\$&')
65
- ); // TODO handle encoding
66
- })
67
- .join('')
68
- );
69
- })
70
- .join('')}${add_trailing_slash ? '/?' : ''}$`
71
- );
72
-
73
- return { pattern, names, types };
74
- }
75
-
76
- const s = JSON.stringify;
77
-
78
- export { parse_route_id as p, s };
@@ -1,83 +0,0 @@
1
- /**
2
- * Takes zero or more objects and returns a new object that has all the values
3
- * deeply merged together. None of the original objects will be mutated at any
4
- * level, and the returned object will have no references to the original
5
- * objects at any depth. If there's a conflict the last one wins, except for
6
- * arrays which will be combined.
7
- * @param {...Object} objects
8
- * @returns {[Record<string, any>, string[]]} a 2-tuple with the merged object,
9
- * and a list of merge conflicts if there were any, in dotted notation
10
- */
11
- function deep_merge(...objects) {
12
- const result = {};
13
- /** @type {string[]} */
14
- const conflicts = [];
15
- objects.forEach((o) => merge_into(result, o, conflicts));
16
- return [result, conflicts];
17
- }
18
-
19
- /**
20
- * normalize kit.vite.resolve.alias as an array
21
- * @param {import('vite').AliasOptions} o
22
- * @returns {import('vite').Alias[]}
23
- */
24
- function normalize_alias(o) {
25
- if (Array.isArray(o)) return o;
26
- return Object.entries(o).map(([find, replacement]) => ({ find, replacement }));
27
- }
28
-
29
- /**
30
- * Merges b into a, recursively, mutating a.
31
- * @param {Record<string, any>} a
32
- * @param {Record<string, any>} b
33
- * @param {string[]} conflicts array to accumulate conflicts in
34
- * @param {string[]} path array of property names representing the current
35
- * location in the tree
36
- */
37
- function merge_into(a, b, conflicts = [], path = []) {
38
- /**
39
- * Checks for "plain old Javascript object", typically made as an object
40
- * literal. Excludes Arrays and built-in types like Buffer.
41
- * @param {any} x
42
- */
43
- const is_plain_object = (x) => typeof x === 'object' && x.constructor === Object;
44
-
45
- for (const prop in b) {
46
- // normalize alias objects to array
47
- if (prop === 'alias' && path[path.length - 1] === 'resolve') {
48
- if (a[prop]) a[prop] = normalize_alias(a[prop]);
49
- if (b[prop]) b[prop] = normalize_alias(b[prop]);
50
- }
51
-
52
- if (is_plain_object(b[prop])) {
53
- if (!is_plain_object(a[prop])) {
54
- if (a[prop] !== undefined) {
55
- conflicts.push([...path, prop].join('.'));
56
- }
57
- a[prop] = {};
58
- }
59
- merge_into(a[prop], b[prop], conflicts, [...path, prop]);
60
- } else if (Array.isArray(b[prop])) {
61
- if (!Array.isArray(a[prop])) {
62
- if (a[prop] !== undefined) {
63
- conflicts.push([...path, prop].join('.'));
64
- }
65
- a[prop] = [];
66
- }
67
- a[prop].push(...b[prop]);
68
- } else {
69
- // Since we're inside a for/in loop which loops over enumerable
70
- // properties only, we want parity here and to check if 'a' has
71
- // enumerable-only property 'prop'. Using 'hasOwnProperty' to
72
- // exclude inherited properties is close enough. It is possible
73
- // that someone uses Object.defineProperty to create a direct,
74
- // non-enumerable property but let's not worry about that.
75
- if (Object.prototype.hasOwnProperty.call(a, prop)) {
76
- conflicts.push([...path, prop].join('.'));
77
- }
78
- a[prop] = b[prop];
79
- }
80
- }
81
- }
82
-
83
- export { deep_merge as d };