@vue/shared 3.5.0-alpha.1 → 3.5.0-alpha.3

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,5 +1,5 @@
1
1
  /**
2
- * @vue/shared v3.5.0-alpha.1
2
+ * @vue/shared v3.5.0-alpha.3
3
3
  * (c) 2018-present Yuxi (Evan) You and Vue contributors
4
4
  * @license MIT
5
5
  **/
@@ -80,15 +80,16 @@ const toHandlerKey = cacheStringFunction((str) => {
80
80
  return s;
81
81
  });
82
82
  const hasChanged = (value, oldValue) => !Object.is(value, oldValue);
83
- const invokeArrayFns = (fns, arg) => {
83
+ const invokeArrayFns = (fns, ...arg) => {
84
84
  for (let i = 0; i < fns.length; i++) {
85
- fns[i](arg);
85
+ fns[i](...arg);
86
86
  }
87
87
  };
88
- const def = (obj, key, value) => {
88
+ const def = (obj, key, value, writable = false) => {
89
89
  Object.defineProperty(obj, key, {
90
90
  configurable: true,
91
91
  enumerable: false,
92
+ writable,
92
93
  value
93
94
  });
94
95
  };
@@ -134,8 +135,8 @@ const PatchFlags = {
134
135
  "1024": "DYNAMIC_SLOTS",
135
136
  "DEV_ROOT_FRAGMENT": 2048,
136
137
  "2048": "DEV_ROOT_FRAGMENT",
137
- "HOISTED": -1,
138
- "-1": "HOISTED",
138
+ "CACHED": -1,
139
+ "-1": "CACHED",
139
140
  "BAIL": -2,
140
141
  "-2": "BAIL"
141
142
  };
@@ -195,12 +196,15 @@ const slotFlagsText = {
195
196
  [3]: "FORWARDED"
196
197
  };
197
198
 
198
- const GLOBALS_ALLOWED = "Infinity,undefined,NaN,isFinite,isNaN,parseFloat,parseInt,decodeURI,decodeURIComponent,encodeURI,encodeURIComponent,Math,Number,Date,Array,Object,Boolean,String,RegExp,Map,Set,JSON,Intl,BigInt,console,Error";
199
+ const GLOBALS_ALLOWED = "Infinity,undefined,NaN,isFinite,isNaN,parseFloat,parseInt,decodeURI,decodeURIComponent,encodeURI,encodeURIComponent,Math,Number,Date,Array,Object,Boolean,String,RegExp,Map,Set,JSON,Intl,BigInt,console,Error,Symbol";
199
200
  const isGloballyAllowed = /* @__PURE__ */ makeMap(GLOBALS_ALLOWED);
200
201
  const isGloballyWhitelisted = isGloballyAllowed;
201
202
 
202
203
  const range = 2;
203
204
  function generateCodeFrame(source, start = 0, end = source.length) {
205
+ start = Math.max(0, Math.min(start, source.length));
206
+ end = Math.max(0, Math.min(end, source.length));
207
+ if (start > end) return "";
204
208
  let lines = source.split(/(\r?\n)/);
205
209
  const newlineSequences = lines.filter((_, idx) => idx % 2 === 1);
206
210
  lines = lines.filter((_, idx) => idx % 2 === 0);
@@ -210,8 +214,7 @@ function generateCodeFrame(source, start = 0, end = source.length) {
210
214
  count += lines[i].length + (newlineSequences[i] && newlineSequences[i].length || 0);
211
215
  if (count >= start) {
212
216
  for (let j = i - range; j <= i + range || end > count; j++) {
213
- if (j < 0 || j >= lines.length)
214
- continue;
217
+ if (j < 0 || j >= lines.length) continue;
215
218
  const line = j + 1;
216
219
  res.push(
217
220
  `${line}${" ".repeat(Math.max(3 - String(line).length, 0))}| ${lines[j]}`
@@ -276,8 +279,8 @@ function stringifyStyle(styles) {
276
279
  }
277
280
  for (const key in styles) {
278
281
  const value = styles[key];
279
- const normalizedKey = key.startsWith(`--`) ? key : hyphenate(key);
280
282
  if (isString(value) || typeof value === "number") {
283
+ const normalizedKey = key.startsWith(`--`) ? key : hyphenate(key);
281
284
  ret += `${normalizedKey}:${value};`;
282
285
  }
283
286
  }
@@ -304,8 +307,7 @@ function normalizeClass(value) {
304
307
  return res.trim();
305
308
  }
306
309
  function normalizeProps(props) {
307
- if (!props)
308
- return null;
310
+ if (!props) return null;
309
311
  let { class: klass, style } = props;
310
312
  if (klass && !isString(klass)) {
311
313
  props.class = normalizeClass(klass);
@@ -410,8 +412,7 @@ function escapeHtmlComment(src) {
410
412
  }
411
413
 
412
414
  function looseCompareArrays(a, b) {
413
- if (a.length !== b.length)
414
- return false;
415
+ if (a.length !== b.length) return false;
415
416
  let equal = true;
416
417
  for (let i = 0; equal && i < a.length; i++) {
417
418
  equal = looseEqual(a[i], b[i]);
@@ -419,8 +420,7 @@ function looseCompareArrays(a, b) {
419
420
  return equal;
420
421
  }
421
422
  function looseEqual(a, b) {
422
- if (a === b)
423
- return true;
423
+ if (a === b) return true;
424
424
  let aValidType = isDate(a);
425
425
  let bValidType = isDate(b);
426
426
  if (aValidType || bValidType) {
@@ -461,11 +461,14 @@ function looseIndexOf(arr, val) {
461
461
  return arr.findIndex((item) => looseEqual(item, val));
462
462
  }
463
463
 
464
+ const isRef = (val) => {
465
+ return !!(val && val["__v_isRef"] === true);
466
+ };
464
467
  const toDisplayString = (val) => {
465
- return isString(val) ? val : val == null ? "" : isArray(val) || isObject(val) && (val.toString === objectToString || !isFunction(val.toString)) ? JSON.stringify(val, replacer, 2) : String(val);
468
+ return isString(val) ? val : val == null ? "" : isArray(val) || isObject(val) && (val.toString === objectToString || !isFunction(val.toString)) ? isRef(val) ? toDisplayString(val.value) : JSON.stringify(val, replacer, 2) : String(val);
466
469
  };
467
470
  const replacer = (_key, val) => {
468
- if (val && val.__v_isRef) {
471
+ if (isRef(val)) {
469
472
  return replacer(_key, val.value);
470
473
  } else if (isMap(val)) {
471
474
  return {
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @vue/shared v3.5.0-alpha.1
2
+ * @vue/shared v3.5.0-alpha.3
3
3
  * (c) 2018-present Yuxi (Evan) You and Vue contributors
4
4
  * @license MIT
5
5
  **/
@@ -80,15 +80,16 @@ const toHandlerKey = cacheStringFunction((str) => {
80
80
  return s;
81
81
  });
82
82
  const hasChanged = (value, oldValue) => !Object.is(value, oldValue);
83
- const invokeArrayFns = (fns, arg) => {
83
+ const invokeArrayFns = (fns, ...arg) => {
84
84
  for (let i = 0; i < fns.length; i++) {
85
- fns[i](arg);
85
+ fns[i](...arg);
86
86
  }
87
87
  };
88
- const def = (obj, key, value) => {
88
+ const def = (obj, key, value, writable = false) => {
89
89
  Object.defineProperty(obj, key, {
90
90
  configurable: true,
91
91
  enumerable: false,
92
+ writable,
92
93
  value
93
94
  });
94
95
  };
@@ -134,8 +135,8 @@ const PatchFlags = {
134
135
  "1024": "DYNAMIC_SLOTS",
135
136
  "DEV_ROOT_FRAGMENT": 2048,
136
137
  "2048": "DEV_ROOT_FRAGMENT",
137
- "HOISTED": -1,
138
- "-1": "HOISTED",
138
+ "CACHED": -1,
139
+ "-1": "CACHED",
139
140
  "BAIL": -2,
140
141
  "-2": "BAIL"
141
142
  };
@@ -195,12 +196,15 @@ const slotFlagsText = {
195
196
  [3]: "FORWARDED"
196
197
  };
197
198
 
198
- const GLOBALS_ALLOWED = "Infinity,undefined,NaN,isFinite,isNaN,parseFloat,parseInt,decodeURI,decodeURIComponent,encodeURI,encodeURIComponent,Math,Number,Date,Array,Object,Boolean,String,RegExp,Map,Set,JSON,Intl,BigInt,console,Error";
199
+ const GLOBALS_ALLOWED = "Infinity,undefined,NaN,isFinite,isNaN,parseFloat,parseInt,decodeURI,decodeURIComponent,encodeURI,encodeURIComponent,Math,Number,Date,Array,Object,Boolean,String,RegExp,Map,Set,JSON,Intl,BigInt,console,Error,Symbol";
199
200
  const isGloballyAllowed = /* @__PURE__ */ makeMap(GLOBALS_ALLOWED);
200
201
  const isGloballyWhitelisted = isGloballyAllowed;
201
202
 
202
203
  const range = 2;
203
204
  function generateCodeFrame(source, start = 0, end = source.length) {
205
+ start = Math.max(0, Math.min(start, source.length));
206
+ end = Math.max(0, Math.min(end, source.length));
207
+ if (start > end) return "";
204
208
  let lines = source.split(/(\r?\n)/);
205
209
  const newlineSequences = lines.filter((_, idx) => idx % 2 === 1);
206
210
  lines = lines.filter((_, idx) => idx % 2 === 0);
@@ -210,8 +214,7 @@ function generateCodeFrame(source, start = 0, end = source.length) {
210
214
  count += lines[i].length + (newlineSequences[i] && newlineSequences[i].length || 0);
211
215
  if (count >= start) {
212
216
  for (let j = i - range; j <= i + range || end > count; j++) {
213
- if (j < 0 || j >= lines.length)
214
- continue;
217
+ if (j < 0 || j >= lines.length) continue;
215
218
  const line = j + 1;
216
219
  res.push(
217
220
  `${line}${" ".repeat(Math.max(3 - String(line).length, 0))}| ${lines[j]}`
@@ -276,8 +279,8 @@ function stringifyStyle(styles) {
276
279
  }
277
280
  for (const key in styles) {
278
281
  const value = styles[key];
279
- const normalizedKey = key.startsWith(`--`) ? key : hyphenate(key);
280
282
  if (isString(value) || typeof value === "number") {
283
+ const normalizedKey = key.startsWith(`--`) ? key : hyphenate(key);
281
284
  ret += `${normalizedKey}:${value};`;
282
285
  }
283
286
  }
@@ -304,8 +307,7 @@ function normalizeClass(value) {
304
307
  return res.trim();
305
308
  }
306
309
  function normalizeProps(props) {
307
- if (!props)
308
- return null;
310
+ if (!props) return null;
309
311
  let { class: klass, style } = props;
310
312
  if (klass && !isString(klass)) {
311
313
  props.class = normalizeClass(klass);
@@ -410,8 +412,7 @@ function escapeHtmlComment(src) {
410
412
  }
411
413
 
412
414
  function looseCompareArrays(a, b) {
413
- if (a.length !== b.length)
414
- return false;
415
+ if (a.length !== b.length) return false;
415
416
  let equal = true;
416
417
  for (let i = 0; equal && i < a.length; i++) {
417
418
  equal = looseEqual(a[i], b[i]);
@@ -419,8 +420,7 @@ function looseCompareArrays(a, b) {
419
420
  return equal;
420
421
  }
421
422
  function looseEqual(a, b) {
422
- if (a === b)
423
- return true;
423
+ if (a === b) return true;
424
424
  let aValidType = isDate(a);
425
425
  let bValidType = isDate(b);
426
426
  if (aValidType || bValidType) {
@@ -461,11 +461,14 @@ function looseIndexOf(arr, val) {
461
461
  return arr.findIndex((item) => looseEqual(item, val));
462
462
  }
463
463
 
464
+ const isRef = (val) => {
465
+ return !!(val && val["__v_isRef"] === true);
466
+ };
464
467
  const toDisplayString = (val) => {
465
- return isString(val) ? val : val == null ? "" : isArray(val) || isObject(val) && (val.toString === objectToString || !isFunction(val.toString)) ? JSON.stringify(val, replacer, 2) : String(val);
468
+ return isString(val) ? val : val == null ? "" : isArray(val) || isObject(val) && (val.toString === objectToString || !isFunction(val.toString)) ? isRef(val) ? toDisplayString(val.value) : JSON.stringify(val, replacer, 2) : String(val);
466
469
  };
467
470
  const replacer = (_key, val) => {
468
- if (val && val.__v_isRef) {
471
+ if (isRef(val)) {
469
472
  return replacer(_key, val.value);
470
473
  } else if (isMap(val)) {
471
474
  return {
package/dist/shared.d.ts CHANGED
@@ -61,8 +61,8 @@ export declare const capitalize: <T extends string>(str: T) => Capitalize<T>;
61
61
  */
62
62
  export declare const toHandlerKey: <T extends string>(str: T) => T extends "" ? "" : `on${Capitalize<T>}`;
63
63
  export declare const hasChanged: (value: any, oldValue: any) => boolean;
64
- export declare const invokeArrayFns: (fns: Function[], arg?: any) => void;
65
- export declare const def: (obj: object, key: string | symbol, value: any) => void;
64
+ export declare const invokeArrayFns: (fns: Function[], ...arg: any[]) => void;
65
+ export declare const def: (obj: object, key: string | symbol, value: any, writable?: boolean) => void;
66
66
  /**
67
67
  * "123-foo" will be parsed to 123
68
68
  * This is used for the .number modifier in v-model
@@ -174,10 +174,10 @@ export declare enum PatchFlags {
174
174
  * flag, simply check patchFlag === FLAG.
175
175
  */
176
176
  /**
177
- * Indicates a hoisted static vnode. This is a hint for hydration to skip
177
+ * Indicates a cached static vnode. This is also a hint for hydration to skip
178
178
  * the entire sub tree since static content never needs to be updated.
179
179
  */
180
- HOISTED = -1,
180
+ CACHED = -1,
181
181
  /**
182
182
  * A special flag that indicates that the diffing algorithm should bail out
183
183
  * of optimized mode. For example, on block fragments created by renderSlot()
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @vue/shared v3.5.0-alpha.1
2
+ * @vue/shared v3.5.0-alpha.3
3
3
  * (c) 2018-present Yuxi (Evan) You and Vue contributors
4
4
  * @license MIT
5
5
  **/
@@ -76,15 +76,16 @@ const toHandlerKey = cacheStringFunction((str) => {
76
76
  return s;
77
77
  });
78
78
  const hasChanged = (value, oldValue) => !Object.is(value, oldValue);
79
- const invokeArrayFns = (fns, arg) => {
79
+ const invokeArrayFns = (fns, ...arg) => {
80
80
  for (let i = 0; i < fns.length; i++) {
81
- fns[i](arg);
81
+ fns[i](...arg);
82
82
  }
83
83
  };
84
- const def = (obj, key, value) => {
84
+ const def = (obj, key, value, writable = false) => {
85
85
  Object.defineProperty(obj, key, {
86
86
  configurable: true,
87
87
  enumerable: false,
88
+ writable,
88
89
  value
89
90
  });
90
91
  };
@@ -130,8 +131,8 @@ const PatchFlags = {
130
131
  "1024": "DYNAMIC_SLOTS",
131
132
  "DEV_ROOT_FRAGMENT": 2048,
132
133
  "2048": "DEV_ROOT_FRAGMENT",
133
- "HOISTED": -1,
134
- "-1": "HOISTED",
134
+ "CACHED": -1,
135
+ "-1": "CACHED",
135
136
  "BAIL": -2,
136
137
  "-2": "BAIL"
137
138
  };
@@ -191,12 +192,15 @@ const slotFlagsText = {
191
192
  [3]: "FORWARDED"
192
193
  };
193
194
 
194
- const GLOBALS_ALLOWED = "Infinity,undefined,NaN,isFinite,isNaN,parseFloat,parseInt,decodeURI,decodeURIComponent,encodeURI,encodeURIComponent,Math,Number,Date,Array,Object,Boolean,String,RegExp,Map,Set,JSON,Intl,BigInt,console,Error";
195
+ const GLOBALS_ALLOWED = "Infinity,undefined,NaN,isFinite,isNaN,parseFloat,parseInt,decodeURI,decodeURIComponent,encodeURI,encodeURIComponent,Math,Number,Date,Array,Object,Boolean,String,RegExp,Map,Set,JSON,Intl,BigInt,console,Error,Symbol";
195
196
  const isGloballyAllowed = /* @__PURE__ */ makeMap(GLOBALS_ALLOWED);
196
197
  const isGloballyWhitelisted = isGloballyAllowed;
197
198
 
198
199
  const range = 2;
199
200
  function generateCodeFrame(source, start = 0, end = source.length) {
201
+ start = Math.max(0, Math.min(start, source.length));
202
+ end = Math.max(0, Math.min(end, source.length));
203
+ if (start > end) return "";
200
204
  let lines = source.split(/(\r?\n)/);
201
205
  const newlineSequences = lines.filter((_, idx) => idx % 2 === 1);
202
206
  lines = lines.filter((_, idx) => idx % 2 === 0);
@@ -206,8 +210,7 @@ function generateCodeFrame(source, start = 0, end = source.length) {
206
210
  count += lines[i].length + (newlineSequences[i] && newlineSequences[i].length || 0);
207
211
  if (count >= start) {
208
212
  for (let j = i - range; j <= i + range || end > count; j++) {
209
- if (j < 0 || j >= lines.length)
210
- continue;
213
+ if (j < 0 || j >= lines.length) continue;
211
214
  const line = j + 1;
212
215
  res.push(
213
216
  `${line}${" ".repeat(Math.max(3 - String(line).length, 0))}| ${lines[j]}`
@@ -272,8 +275,8 @@ function stringifyStyle(styles) {
272
275
  }
273
276
  for (const key in styles) {
274
277
  const value = styles[key];
275
- const normalizedKey = key.startsWith(`--`) ? key : hyphenate(key);
276
278
  if (isString(value) || typeof value === "number") {
279
+ const normalizedKey = key.startsWith(`--`) ? key : hyphenate(key);
277
280
  ret += `${normalizedKey}:${value};`;
278
281
  }
279
282
  }
@@ -300,8 +303,7 @@ function normalizeClass(value) {
300
303
  return res.trim();
301
304
  }
302
305
  function normalizeProps(props) {
303
- if (!props)
304
- return null;
306
+ if (!props) return null;
305
307
  let { class: klass, style } = props;
306
308
  if (klass && !isString(klass)) {
307
309
  props.class = normalizeClass(klass);
@@ -406,8 +408,7 @@ function escapeHtmlComment(src) {
406
408
  }
407
409
 
408
410
  function looseCompareArrays(a, b) {
409
- if (a.length !== b.length)
410
- return false;
411
+ if (a.length !== b.length) return false;
411
412
  let equal = true;
412
413
  for (let i = 0; equal && i < a.length; i++) {
413
414
  equal = looseEqual(a[i], b[i]);
@@ -415,8 +416,7 @@ function looseCompareArrays(a, b) {
415
416
  return equal;
416
417
  }
417
418
  function looseEqual(a, b) {
418
- if (a === b)
419
- return true;
419
+ if (a === b) return true;
420
420
  let aValidType = isDate(a);
421
421
  let bValidType = isDate(b);
422
422
  if (aValidType || bValidType) {
@@ -457,11 +457,14 @@ function looseIndexOf(arr, val) {
457
457
  return arr.findIndex((item) => looseEqual(item, val));
458
458
  }
459
459
 
460
+ const isRef = (val) => {
461
+ return !!(val && val["__v_isRef"] === true);
462
+ };
460
463
  const toDisplayString = (val) => {
461
- return isString(val) ? val : val == null ? "" : isArray(val) || isObject(val) && (val.toString === objectToString || !isFunction(val.toString)) ? JSON.stringify(val, replacer, 2) : String(val);
464
+ return isString(val) ? val : val == null ? "" : isArray(val) || isObject(val) && (val.toString === objectToString || !isFunction(val.toString)) ? isRef(val) ? toDisplayString(val.value) : JSON.stringify(val, replacer, 2) : String(val);
462
465
  };
463
466
  const replacer = (_key, val) => {
464
- if (val && val.__v_isRef) {
467
+ if (isRef(val)) {
465
468
  return replacer(_key, val.value);
466
469
  } else if (isMap(val)) {
467
470
  return {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vue/shared",
3
- "version": "3.5.0-alpha.1",
3
+ "version": "3.5.0-alpha.3",
4
4
  "description": "internal utils shared across @vue packages",
5
5
  "main": "index.js",
6
6
  "module": "dist/shared.esm-bundler.js",