@vue/compiler-core 3.3.5 → 3.3.7

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.
@@ -1587,9 +1587,13 @@ function walk(node, context, doNotHoistNode = false) {
1587
1587
  context.transformHoist(children, context, node);
1588
1588
  }
1589
1589
  if (hoistedCount && hoistedCount === originalCount && node.type === 1 && node.tagType === 0 && node.codegenNode && node.codegenNode.type === 13 && shared.isArray(node.codegenNode.children)) {
1590
- node.codegenNode.children = context.hoist(
1590
+ const hoisted = context.hoist(
1591
1591
  createArrayExpression(node.codegenNode.children)
1592
1592
  );
1593
+ if (context.hmr) {
1594
+ hoisted.content = `[...${hoisted.content}]`;
1595
+ }
1596
+ node.codegenNode.children = hoisted;
1593
1597
  }
1594
1598
  }
1595
1599
  function getConstantType(node, context) {
@@ -1762,6 +1766,7 @@ function createTransformContext(root, {
1762
1766
  filename = "",
1763
1767
  prefixIdentifiers = false,
1764
1768
  hoistStatic: hoistStatic2 = false,
1769
+ hmr = false,
1765
1770
  cacheHandlers = false,
1766
1771
  nodeTransforms = [],
1767
1772
  directiveTransforms = {},
@@ -1787,6 +1792,7 @@ function createTransformContext(root, {
1787
1792
  selfName: nameMatch && shared.capitalize(shared.camelize(nameMatch[1])),
1788
1793
  prefixIdentifiers,
1789
1794
  hoistStatic: hoistStatic2,
1795
+ hmr,
1790
1796
  cacheHandlers,
1791
1797
  nodeTransforms,
1792
1798
  directiveTransforms,
@@ -1812,7 +1818,7 @@ function createTransformContext(root, {
1812
1818
  directives: /* @__PURE__ */ new Set(),
1813
1819
  hoists: [],
1814
1820
  imports: [],
1815
- constantCache: /* @__PURE__ */ new Map(),
1821
+ constantCache: /* @__PURE__ */ new WeakMap(),
1816
1822
  temps: 0,
1817
1823
  cached: 0,
1818
1824
  identifiers: /* @__PURE__ */ Object.create(null),
@@ -3831,7 +3837,7 @@ const trackVForSlotScopes = (node, context) => {
3831
3837
  }
3832
3838
  }
3833
3839
  };
3834
- const buildClientSlotFn = (props, children, loc) => createFunctionExpression(
3840
+ const buildClientSlotFn = (props, _vForExp, children, loc) => createFunctionExpression(
3835
3841
  props,
3836
3842
  children,
3837
3843
  false,
@@ -3856,7 +3862,7 @@ function buildSlots(node, context, buildSlotFn = buildClientSlotFn) {
3856
3862
  slotsProperties.push(
3857
3863
  createObjectProperty(
3858
3864
  arg || createSimpleExpression("default", true),
3859
- buildSlotFn(exp, children, loc)
3865
+ buildSlotFn(exp, void 0, children, loc)
3860
3866
  )
3861
3867
  );
3862
3868
  }
@@ -3893,10 +3899,15 @@ function buildSlots(node, context, buildSlotFn = buildClientSlotFn) {
3893
3899
  } else {
3894
3900
  hasDynamicSlots = true;
3895
3901
  }
3896
- const slotFunction = buildSlotFn(slotProps, slotChildren, slotLoc);
3902
+ const vFor = findDir(slotElement, "for");
3903
+ const slotFunction = buildSlotFn(
3904
+ slotProps,
3905
+ vFor == null ? void 0 : vFor.exp,
3906
+ slotChildren,
3907
+ slotLoc
3908
+ );
3897
3909
  let vIf;
3898
3910
  let vElse;
3899
- let vFor;
3900
3911
  if (vIf = findDir(slotElement, "if")) {
3901
3912
  hasDynamicSlots = true;
3902
3913
  dynamicSlots.push(
@@ -3941,7 +3952,7 @@ function buildSlots(node, context, buildSlotFn = buildClientSlotFn) {
3941
3952
  createCompilerError(30, vElse.loc)
3942
3953
  );
3943
3954
  }
3944
- } else if (vFor = findDir(slotElement, "for")) {
3955
+ } else if (vFor) {
3945
3956
  hasDynamicSlots = true;
3946
3957
  const parseResult = vFor.parseResult || parseForExpression(vFor.exp, context);
3947
3958
  if (parseResult) {
@@ -3982,7 +3993,7 @@ function buildSlots(node, context, buildSlotFn = buildClientSlotFn) {
3982
3993
  }
3983
3994
  if (!onComponentSlot) {
3984
3995
  const buildDefaultSlotProperty = (props, children2) => {
3985
- const fn = buildSlotFn(props, children2, loc);
3996
+ const fn = buildSlotFn(props, void 0, children2, loc);
3986
3997
  if (context.compatConfig) {
3987
3998
  fn.isNonScopedSlot = true;
3988
3999
  }
@@ -1546,9 +1546,13 @@ function walk(node, context, doNotHoistNode = false) {
1546
1546
  context.transformHoist(children, context, node);
1547
1547
  }
1548
1548
  if (hoistedCount && hoistedCount === originalCount && node.type === 1 && node.tagType === 0 && node.codegenNode && node.codegenNode.type === 13 && shared.isArray(node.codegenNode.children)) {
1549
- node.codegenNode.children = context.hoist(
1549
+ const hoisted = context.hoist(
1550
1550
  createArrayExpression(node.codegenNode.children)
1551
1551
  );
1552
+ if (context.hmr) {
1553
+ hoisted.content = `[...${hoisted.content}]`;
1554
+ }
1555
+ node.codegenNode.children = hoisted;
1552
1556
  }
1553
1557
  }
1554
1558
  function getConstantType(node, context) {
@@ -1721,6 +1725,7 @@ function createTransformContext(root, {
1721
1725
  filename = "",
1722
1726
  prefixIdentifiers = false,
1723
1727
  hoistStatic: hoistStatic2 = false,
1728
+ hmr = false,
1724
1729
  cacheHandlers = false,
1725
1730
  nodeTransforms = [],
1726
1731
  directiveTransforms = {},
@@ -1746,6 +1751,7 @@ function createTransformContext(root, {
1746
1751
  selfName: nameMatch && shared.capitalize(shared.camelize(nameMatch[1])),
1747
1752
  prefixIdentifiers,
1748
1753
  hoistStatic: hoistStatic2,
1754
+ hmr,
1749
1755
  cacheHandlers,
1750
1756
  nodeTransforms,
1751
1757
  directiveTransforms,
@@ -1771,7 +1777,7 @@ function createTransformContext(root, {
1771
1777
  directives: /* @__PURE__ */ new Set(),
1772
1778
  hoists: [],
1773
1779
  imports: [],
1774
- constantCache: /* @__PURE__ */ new Map(),
1780
+ constantCache: /* @__PURE__ */ new WeakMap(),
1775
1781
  temps: 0,
1776
1782
  cached: 0,
1777
1783
  identifiers: /* @__PURE__ */ Object.create(null),
@@ -3750,7 +3756,7 @@ const trackVForSlotScopes = (node, context) => {
3750
3756
  }
3751
3757
  }
3752
3758
  };
3753
- const buildClientSlotFn = (props, children, loc) => createFunctionExpression(
3759
+ const buildClientSlotFn = (props, _vForExp, children, loc) => createFunctionExpression(
3754
3760
  props,
3755
3761
  children,
3756
3762
  false,
@@ -3775,7 +3781,7 @@ function buildSlots(node, context, buildSlotFn = buildClientSlotFn) {
3775
3781
  slotsProperties.push(
3776
3782
  createObjectProperty(
3777
3783
  arg || createSimpleExpression("default", true),
3778
- buildSlotFn(exp, children, loc)
3784
+ buildSlotFn(exp, void 0, children, loc)
3779
3785
  )
3780
3786
  );
3781
3787
  }
@@ -3812,10 +3818,15 @@ function buildSlots(node, context, buildSlotFn = buildClientSlotFn) {
3812
3818
  } else {
3813
3819
  hasDynamicSlots = true;
3814
3820
  }
3815
- const slotFunction = buildSlotFn(slotProps, slotChildren, slotLoc);
3821
+ const vFor = findDir(slotElement, "for");
3822
+ const slotFunction = buildSlotFn(
3823
+ slotProps,
3824
+ vFor == null ? void 0 : vFor.exp,
3825
+ slotChildren,
3826
+ slotLoc
3827
+ );
3816
3828
  let vIf;
3817
3829
  let vElse;
3818
- let vFor;
3819
3830
  if (vIf = findDir(slotElement, "if")) {
3820
3831
  hasDynamicSlots = true;
3821
3832
  dynamicSlots.push(
@@ -3860,7 +3871,7 @@ function buildSlots(node, context, buildSlotFn = buildClientSlotFn) {
3860
3871
  createCompilerError(30, vElse.loc)
3861
3872
  );
3862
3873
  }
3863
- } else if (vFor = findDir(slotElement, "for")) {
3874
+ } else if (vFor) {
3864
3875
  hasDynamicSlots = true;
3865
3876
  const parseResult = vFor.parseResult || parseForExpression(vFor.exp, context);
3866
3877
  if (parseResult) {
@@ -3901,7 +3912,7 @@ function buildSlots(node, context, buildSlotFn = buildClientSlotFn) {
3901
3912
  }
3902
3913
  if (!onComponentSlot) {
3903
3914
  const buildDefaultSlotProperty = (props, children2) => {
3904
- const fn = buildSlotFn(props, children2, loc);
3915
+ const fn = buildSlotFn(props, void 0, children2, loc);
3905
3916
  if (context.compatConfig) {
3906
3917
  fn.isNonScopedSlot = true;
3907
3918
  }
@@ -90,10 +90,10 @@ export interface TransformContext extends Required<Omit<TransformOptions, 'filen
90
90
  removeIdentifiers(exp: ExpressionNode | string): void;
91
91
  hoist(exp: string | JSChildNode | ArrayExpression): SimpleExpressionNode;
92
92
  cache<T extends JSChildNode>(exp: T, isVNode?: boolean): CacheExpression | T;
93
- constantCache: Map<TemplateChildNode, ConstantTypes>;
93
+ constantCache: WeakMap<TemplateChildNode, ConstantTypes>;
94
94
  filters?: Set<string>;
95
95
  }
96
- export declare function createTransformContext(root: RootNode, { filename, prefixIdentifiers, hoistStatic, cacheHandlers, nodeTransforms, directiveTransforms, transformHoist, isBuiltInComponent, isCustomElement, expressionPlugins, scopeId, slotted, ssr, inSSR, ssrCssVars, bindingMetadata, inline, isTS, onError, onWarn, compatConfig }: TransformOptions): TransformContext;
96
+ export declare function createTransformContext(root: RootNode, { filename, prefixIdentifiers, hoistStatic, hmr, cacheHandlers, nodeTransforms, directiveTransforms, transformHoist, isBuiltInComponent, isCustomElement, expressionPlugins, scopeId, slotted, ssr, inSSR, ssrCssVars, bindingMetadata, inline, isTS, onError, onWarn, compatConfig }: TransformOptions): TransformContext;
97
97
  export declare function transform(root: RootNode, options: TransformOptions): void;
98
98
  export declare function traverseNode(node: RootNode | TemplateChildNode, context: TransformContext): void;
99
99
  export declare function createStructuralDirectiveTransform(name: string | RegExp, fn: StructuralDirectiveTransform): NodeTransform;
@@ -840,6 +840,12 @@ export interface TransformOptions extends SharedTransformCodegenOptions, ErrorHa
840
840
  * needed to render inline CSS variables on component root
841
841
  */
842
842
  ssrCssVars?: string;
843
+ /**
844
+ * Whether to compile the template assuming it needs to handle HMR.
845
+ * Some edge cases may need to generate different code for HMR to work
846
+ * correctly, e.g. #6938, #7138
847
+ */
848
+ hmr?: boolean;
843
849
  }
844
850
  export interface CodegenOptions extends SharedTransformCodegenOptions {
845
851
  /**
@@ -976,7 +982,7 @@ export declare function stringifyExpression(exp: ExpressionNode | string): strin
976
982
 
977
983
  export declare const trackSlotScopes: NodeTransform;
978
984
  export declare const trackVForSlotScopes: NodeTransform;
979
- export type SlotFnBuilder = (slotProps: ExpressionNode | undefined, slotChildren: TemplateChildNode[], loc: SourceLocation) => FunctionExpression;
985
+ export type SlotFnBuilder = (slotProps: ExpressionNode | undefined, vForExp: ExpressionNode | undefined, slotChildren: TemplateChildNode[], loc: SourceLocation) => FunctionExpression;
980
986
  export declare function buildSlots(node: ElementNode, context: TransformContext, buildSlotFn?: SlotFnBuilder): {
981
987
  slots: SlotsExpression;
982
988
  hasDynamicSlots: boolean;
@@ -1570,9 +1570,13 @@ function walk(node, context, doNotHoistNode = false) {
1570
1570
  context.transformHoist(children, context, node);
1571
1571
  }
1572
1572
  if (hoistedCount && hoistedCount === originalCount && node.type === 1 && node.tagType === 0 && node.codegenNode && node.codegenNode.type === 13 && isArray(node.codegenNode.children)) {
1573
- node.codegenNode.children = context.hoist(
1573
+ const hoisted = context.hoist(
1574
1574
  createArrayExpression(node.codegenNode.children)
1575
1575
  );
1576
+ if (context.hmr) {
1577
+ hoisted.content = `[...${hoisted.content}]`;
1578
+ }
1579
+ node.codegenNode.children = hoisted;
1576
1580
  }
1577
1581
  }
1578
1582
  function getConstantType(node, context) {
@@ -1746,6 +1750,7 @@ function createTransformContext(root, {
1746
1750
  filename = "",
1747
1751
  prefixIdentifiers = false,
1748
1752
  hoistStatic: hoistStatic2 = false,
1753
+ hmr = false,
1749
1754
  cacheHandlers = false,
1750
1755
  nodeTransforms = [],
1751
1756
  directiveTransforms = {},
@@ -1771,6 +1776,7 @@ function createTransformContext(root, {
1771
1776
  selfName: nameMatch && capitalize(camelize(nameMatch[1])),
1772
1777
  prefixIdentifiers,
1773
1778
  hoistStatic: hoistStatic2,
1779
+ hmr,
1774
1780
  cacheHandlers,
1775
1781
  nodeTransforms,
1776
1782
  directiveTransforms,
@@ -1796,7 +1802,7 @@ function createTransformContext(root, {
1796
1802
  directives: /* @__PURE__ */ new Set(),
1797
1803
  hoists: [],
1798
1804
  imports: [],
1799
- constantCache: /* @__PURE__ */ new Map(),
1805
+ constantCache: /* @__PURE__ */ new WeakMap(),
1800
1806
  temps: 0,
1801
1807
  cached: 0,
1802
1808
  identifiers: /* @__PURE__ */ Object.create(null),
@@ -3286,7 +3292,7 @@ const trackVForSlotScopes = (node, context) => {
3286
3292
  }
3287
3293
  }
3288
3294
  };
3289
- const buildClientSlotFn = (props, children, loc) => createFunctionExpression(
3295
+ const buildClientSlotFn = (props, _vForExp, children, loc) => createFunctionExpression(
3290
3296
  props,
3291
3297
  children,
3292
3298
  false,
@@ -3308,7 +3314,7 @@ function buildSlots(node, context, buildSlotFn = buildClientSlotFn) {
3308
3314
  slotsProperties.push(
3309
3315
  createObjectProperty(
3310
3316
  arg || createSimpleExpression("default", true),
3311
- buildSlotFn(exp, children, loc)
3317
+ buildSlotFn(exp, void 0, children, loc)
3312
3318
  )
3313
3319
  );
3314
3320
  }
@@ -3345,10 +3351,15 @@ function buildSlots(node, context, buildSlotFn = buildClientSlotFn) {
3345
3351
  } else {
3346
3352
  hasDynamicSlots = true;
3347
3353
  }
3348
- const slotFunction = buildSlotFn(slotProps, slotChildren, slotLoc);
3354
+ const vFor = findDir(slotElement, "for");
3355
+ const slotFunction = buildSlotFn(
3356
+ slotProps,
3357
+ vFor == null ? void 0 : vFor.exp,
3358
+ slotChildren,
3359
+ slotLoc
3360
+ );
3349
3361
  let vIf;
3350
3362
  let vElse;
3351
- let vFor;
3352
3363
  if (vIf = findDir(slotElement, "if")) {
3353
3364
  hasDynamicSlots = true;
3354
3365
  dynamicSlots.push(
@@ -3393,7 +3404,7 @@ function buildSlots(node, context, buildSlotFn = buildClientSlotFn) {
3393
3404
  createCompilerError(30, vElse.loc)
3394
3405
  );
3395
3406
  }
3396
- } else if (vFor = findDir(slotElement, "for")) {
3407
+ } else if (vFor) {
3397
3408
  hasDynamicSlots = true;
3398
3409
  const parseResult = vFor.parseResult || parseForExpression(vFor.exp, context);
3399
3410
  if (parseResult) {
@@ -3434,7 +3445,7 @@ function buildSlots(node, context, buildSlotFn = buildClientSlotFn) {
3434
3445
  }
3435
3446
  if (!onComponentSlot) {
3436
3447
  const buildDefaultSlotProperty = (props, children2) => {
3437
- const fn = buildSlotFn(props, children2, loc);
3448
+ const fn = buildSlotFn(props, void 0, children2, loc);
3438
3449
  if (context.compatConfig) {
3439
3450
  fn.isNonScopedSlot = true;
3440
3451
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vue/compiler-core",
3
- "version": "3.3.5",
3
+ "version": "3.3.7",
4
4
  "description": "@vue/compiler-core",
5
5
  "main": "index.js",
6
6
  "module": "dist/compiler-core.esm-bundler.js",
@@ -33,7 +33,7 @@
33
33
  "homepage": "https://github.com/vuejs/core/tree/main/packages/compiler-core#readme",
34
34
  "dependencies": {
35
35
  "@babel/parser": "^7.23.0",
36
- "@vue/shared": "3.3.5",
36
+ "@vue/shared": "3.3.7",
37
37
  "estree-walker": "^2.0.2",
38
38
  "source-map-js": "^1.0.2"
39
39
  },