@vue/compiler-dom 3.5.0-alpha.2 → 3.5.0-alpha.4

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/compiler-dom v3.5.0-alpha.2
2
+ * @vue/compiler-dom v3.5.0-alpha.4
3
3
  * (c) 2018-present Yuxi (Evan) You and Vue contributors
4
4
  * @license MIT
5
5
  **/
@@ -349,8 +349,7 @@ const transformClick = (key, event) => {
349
349
  const transformOn = (dir, node, context) => {
350
350
  return compilerCore.transformOn(dir, node, context, (baseResult) => {
351
351
  const { modifiers } = dir;
352
- if (!modifiers.length)
353
- return baseResult;
352
+ if (!modifiers.length) return baseResult;
354
353
  let { key, value: handlerExp } = baseResult.props[0];
355
354
  const { keyModifiers, nonKeyModifiers, eventOptionModifiers } = resolveModifiers(key, modifiers, context, dir.loc);
356
355
  if (nonKeyModifiers.includes("right")) {
@@ -446,6 +445,7 @@ const stringifyStatic = (children, context, parent) => {
446
445
  if (context.scopes.vSlot > 0) {
447
446
  return;
448
447
  }
448
+ const isParentCached = parent.type === 1 && parent.codegenNode && parent.codegenNode.type === 13 && parent.codegenNode.children && !shared.isArray(parent.codegenNode.children) && parent.codegenNode.children.type === 20;
449
449
  let nc = 0;
450
450
  let ec = 0;
451
451
  const currentChunk = [];
@@ -459,14 +459,25 @@ const stringifyStatic = (children, context, parent) => {
459
459
  // will insert / hydrate
460
460
  String(currentChunk.length)
461
461
  ]);
462
- replaceHoist(currentChunk[0], staticCall, context);
463
- if (currentChunk.length > 1) {
464
- for (let i2 = 1; i2 < currentChunk.length; i2++) {
465
- replaceHoist(currentChunk[i2], null, context);
462
+ if (isParentCached) {
463
+ parent.codegenNode.children.value = compilerCore.createArrayExpression([staticCall]);
464
+ } else {
465
+ currentChunk[0].codegenNode.value = staticCall;
466
+ if (currentChunk.length > 1) {
467
+ const deleteCount = currentChunk.length - 1;
468
+ children.splice(currentIndex - currentChunk.length + 1, deleteCount);
469
+ const cacheIndex = context.cached.indexOf(
470
+ currentChunk[currentChunk.length - 1].codegenNode
471
+ );
472
+ if (cacheIndex > -1) {
473
+ for (let i2 = cacheIndex; i2 < context.cached.length; i2++) {
474
+ const c = context.cached[i2];
475
+ if (c) c.index -= deleteCount;
476
+ }
477
+ context.cached.splice(cacheIndex - deleteCount + 1, deleteCount);
478
+ }
479
+ return deleteCount;
466
480
  }
467
- const deleteCount = currentChunk.length - 1;
468
- children.splice(currentIndex - currentChunk.length + 1, deleteCount);
469
- return deleteCount;
470
481
  }
471
482
  }
472
483
  return 0;
@@ -474,14 +485,13 @@ const stringifyStatic = (children, context, parent) => {
474
485
  let i = 0;
475
486
  for (; i < children.length; i++) {
476
487
  const child = children[i];
477
- const hoisted = getHoistedNode(child);
478
- if (hoisted) {
479
- const node = child;
480
- const result = analyzeNode(node);
488
+ const isCached = isParentCached || getCachedNode(child);
489
+ if (isCached) {
490
+ const result = analyzeNode(child);
481
491
  if (result) {
482
492
  nc += result[0];
483
493
  ec += result[1];
484
- currentChunk.push(node);
494
+ currentChunk.push(child);
485
495
  continue;
486
496
  }
487
497
  }
@@ -492,15 +502,15 @@ const stringifyStatic = (children, context, parent) => {
492
502
  }
493
503
  stringifyCurrentChunk(i);
494
504
  };
495
- const getHoistedNode = (node) => (node.type === 1 && node.tagType === 0 || node.type == 12) && node.codegenNode && node.codegenNode.type === 4 && node.codegenNode.hoisted;
505
+ const getCachedNode = (node) => {
506
+ if ((node.type === 1 && node.tagType === 0 || node.type === 12) && node.codegenNode && node.codegenNode.type === 20) {
507
+ return node.codegenNode;
508
+ }
509
+ };
496
510
  const dataAriaRE = /^(data|aria)-/;
497
511
  const isStringifiableAttr = (name, ns) => {
498
512
  return (ns === 0 ? shared.isKnownHtmlAttr(name) : ns === 1 ? shared.isKnownSvgAttr(name) : false) || dataAriaRE.test(name);
499
513
  };
500
- const replaceHoist = (node, replacement, context) => {
501
- const hoistToReplace = node.codegenNode.hoisted;
502
- context.hoists[context.hoists.indexOf(hoistToReplace)] = replacement;
503
- };
504
514
  const isNonStringifiable = /* @__PURE__ */ shared.makeMap(
505
515
  `caption,thead,tr,th,tbody,td,tfoot,colgroup,col`
506
516
  );
@@ -519,6 +529,7 @@ function analyzeNode(node) {
519
529
  return false;
520
530
  };
521
531
  function walk(node2) {
532
+ const isOptionTag = node2.tag === "option" && node2.ns === 0;
522
533
  for (let i = 0; i < node2.props.length; i++) {
523
534
  const p = node2.props[i];
524
535
  if (p.type === 6 && !isStringifiableAttr(p.name, node2.ns)) {
@@ -531,6 +542,9 @@ function analyzeNode(node) {
531
542
  if (p.exp && (p.exp.type === 8 || p.exp.constType < 3)) {
532
543
  return bail();
533
544
  }
545
+ if (isOptionTag && compilerCore.isStaticArgOf(p.arg, "value") && p.exp && p.exp.ast && p.exp.ast.type !== "StringLiteral") {
546
+ return bail();
547
+ }
534
548
  }
535
549
  }
536
550
  for (let i = 0; i < node2.children.length; i++) {
@@ -672,12 +686,10 @@ function isValidHTMLNesting(parent, child) {
672
686
  return onlyValidParents[child].has(parent);
673
687
  }
674
688
  if (parent in knownInvalidChildren) {
675
- if (knownInvalidChildren[parent].has(child))
676
- return false;
689
+ if (knownInvalidChildren[parent].has(child)) return false;
677
690
  }
678
691
  if (child in knownInvalidParents) {
679
- if (knownInvalidParents[child].has(parent))
680
- return false;
692
+ if (knownInvalidParents[child].has(parent)) return false;
681
693
  }
682
694
  return true;
683
695
  }
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @vue/compiler-dom v3.5.0-alpha.2
2
+ * @vue/compiler-dom v3.5.0-alpha.4
3
3
  * (c) 2018-present Yuxi (Evan) You and Vue contributors
4
4
  * @license MIT
5
5
  **/
@@ -331,8 +331,7 @@ const transformClick = (key, event) => {
331
331
  const transformOn = (dir, node, context) => {
332
332
  return compilerCore.transformOn(dir, node, context, (baseResult) => {
333
333
  const { modifiers } = dir;
334
- if (!modifiers.length)
335
- return baseResult;
334
+ if (!modifiers.length) return baseResult;
336
335
  let { key, value: handlerExp } = baseResult.props[0];
337
336
  const { keyModifiers, nonKeyModifiers, eventOptionModifiers } = resolveModifiers(key, modifiers, context, dir.loc);
338
337
  if (nonKeyModifiers.includes("right")) {
@@ -382,6 +381,7 @@ const stringifyStatic = (children, context, parent) => {
382
381
  if (context.scopes.vSlot > 0) {
383
382
  return;
384
383
  }
384
+ const isParentCached = parent.type === 1 && parent.codegenNode && parent.codegenNode.type === 13 && parent.codegenNode.children && !shared.isArray(parent.codegenNode.children) && parent.codegenNode.children.type === 20;
385
385
  let nc = 0;
386
386
  let ec = 0;
387
387
  const currentChunk = [];
@@ -395,14 +395,25 @@ const stringifyStatic = (children, context, parent) => {
395
395
  // will insert / hydrate
396
396
  String(currentChunk.length)
397
397
  ]);
398
- replaceHoist(currentChunk[0], staticCall, context);
399
- if (currentChunk.length > 1) {
400
- for (let i2 = 1; i2 < currentChunk.length; i2++) {
401
- replaceHoist(currentChunk[i2], null, context);
398
+ if (isParentCached) {
399
+ parent.codegenNode.children.value = compilerCore.createArrayExpression([staticCall]);
400
+ } else {
401
+ currentChunk[0].codegenNode.value = staticCall;
402
+ if (currentChunk.length > 1) {
403
+ const deleteCount = currentChunk.length - 1;
404
+ children.splice(currentIndex - currentChunk.length + 1, deleteCount);
405
+ const cacheIndex = context.cached.indexOf(
406
+ currentChunk[currentChunk.length - 1].codegenNode
407
+ );
408
+ if (cacheIndex > -1) {
409
+ for (let i2 = cacheIndex; i2 < context.cached.length; i2++) {
410
+ const c = context.cached[i2];
411
+ if (c) c.index -= deleteCount;
412
+ }
413
+ context.cached.splice(cacheIndex - deleteCount + 1, deleteCount);
414
+ }
415
+ return deleteCount;
402
416
  }
403
- const deleteCount = currentChunk.length - 1;
404
- children.splice(currentIndex - currentChunk.length + 1, deleteCount);
405
- return deleteCount;
406
417
  }
407
418
  }
408
419
  return 0;
@@ -410,14 +421,13 @@ const stringifyStatic = (children, context, parent) => {
410
421
  let i = 0;
411
422
  for (; i < children.length; i++) {
412
423
  const child = children[i];
413
- const hoisted = getHoistedNode(child);
414
- if (hoisted) {
415
- const node = child;
416
- const result = analyzeNode(node);
424
+ const isCached = isParentCached || getCachedNode(child);
425
+ if (isCached) {
426
+ const result = analyzeNode(child);
417
427
  if (result) {
418
428
  nc += result[0];
419
429
  ec += result[1];
420
- currentChunk.push(node);
430
+ currentChunk.push(child);
421
431
  continue;
422
432
  }
423
433
  }
@@ -428,15 +438,15 @@ const stringifyStatic = (children, context, parent) => {
428
438
  }
429
439
  stringifyCurrentChunk(i);
430
440
  };
431
- const getHoistedNode = (node) => (node.type === 1 && node.tagType === 0 || node.type == 12) && node.codegenNode && node.codegenNode.type === 4 && node.codegenNode.hoisted;
441
+ const getCachedNode = (node) => {
442
+ if ((node.type === 1 && node.tagType === 0 || node.type === 12) && node.codegenNode && node.codegenNode.type === 20) {
443
+ return node.codegenNode;
444
+ }
445
+ };
432
446
  const dataAriaRE = /^(data|aria)-/;
433
447
  const isStringifiableAttr = (name, ns) => {
434
448
  return (ns === 0 ? shared.isKnownHtmlAttr(name) : ns === 1 ? shared.isKnownSvgAttr(name) : false) || dataAriaRE.test(name);
435
449
  };
436
- const replaceHoist = (node, replacement, context) => {
437
- const hoistToReplace = node.codegenNode.hoisted;
438
- context.hoists[context.hoists.indexOf(hoistToReplace)] = replacement;
439
- };
440
450
  const isNonStringifiable = /* @__PURE__ */ shared.makeMap(
441
451
  `caption,thead,tr,th,tbody,td,tfoot,colgroup,col`
442
452
  );
@@ -455,6 +465,7 @@ function analyzeNode(node) {
455
465
  return false;
456
466
  };
457
467
  function walk(node2) {
468
+ const isOptionTag = node2.tag === "option" && node2.ns === 0;
458
469
  for (let i = 0; i < node2.props.length; i++) {
459
470
  const p = node2.props[i];
460
471
  if (p.type === 6 && !isStringifiableAttr(p.name, node2.ns)) {
@@ -467,6 +478,9 @@ function analyzeNode(node) {
467
478
  if (p.exp && (p.exp.type === 8 || p.exp.constType < 3)) {
468
479
  return bail();
469
480
  }
481
+ if (isOptionTag && compilerCore.isStaticArgOf(p.arg, "value") && p.exp && p.exp.ast && p.exp.ast.type !== "StringLiteral") {
482
+ return bail();
483
+ }
470
484
  }
471
485
  }
472
486
  for (let i = 0; i < node2.children.length; i++) {