@vue/compiler-core 3.3.6 → 3.4.0-alpha.1

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,
@@ -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
  }
@@ -5425,6 +5436,7 @@ exports.createStructuralDirectiveTransform = createStructuralDirectiveTransform;
5425
5436
  exports.createTemplateLiteral = createTemplateLiteral;
5426
5437
  exports.createTransformContext = createTransformContext;
5427
5438
  exports.createVNodeCall = createVNodeCall;
5439
+ exports.errorMessages = errorMessages;
5428
5440
  exports.extractIdentifiers = extractIdentifiers;
5429
5441
  exports.findDir = findDir;
5430
5442
  exports.findProp = findProp;
@@ -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,
@@ -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
  }
@@ -5294,6 +5305,7 @@ exports.createStructuralDirectiveTransform = createStructuralDirectiveTransform;
5294
5305
  exports.createTemplateLiteral = createTemplateLiteral;
5295
5306
  exports.createTransformContext = createTransformContext;
5296
5307
  exports.createVNodeCall = createVNodeCall;
5308
+ exports.errorMessages = errorMessages;
5297
5309
  exports.extractIdentifiers = extractIdentifiers;
5298
5310
  exports.findDir = findDir;
5299
5311
  exports.findProp = findProp;
@@ -93,7 +93,7 @@ export interface TransformContext extends Required<Omit<TransformOptions, 'filen
93
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;
@@ -610,6 +610,7 @@ export declare const enum ErrorCodes {
610
610
  DEPRECATION_V_IS = 52,
611
611
  __EXTEND_POINT__ = 53
612
612
  }
613
+ export declare const errorMessages: Record<ErrorCodes, string>;
613
614
 
614
615
  interface ErrorHandlingOptions {
615
616
  onWarn?: (warning: CompilerError) => void;
@@ -840,6 +841,12 @@ export interface TransformOptions extends SharedTransformCodegenOptions, ErrorHa
840
841
  * needed to render inline CSS variables on component root
841
842
  */
842
843
  ssrCssVars?: string;
844
+ /**
845
+ * Whether to compile the template assuming it needs to handle HMR.
846
+ * Some edge cases may need to generate different code for HMR to work
847
+ * correctly, e.g. #6938, #7138
848
+ */
849
+ hmr?: boolean;
843
850
  }
844
851
  export interface CodegenOptions extends SharedTransformCodegenOptions {
845
852
  /**
@@ -976,7 +983,7 @@ export declare function stringifyExpression(exp: ExpressionNode | string): strin
976
983
 
977
984
  export declare const trackSlotScopes: NodeTransform;
978
985
  export declare const trackVForSlotScopes: NodeTransform;
979
- export type SlotFnBuilder = (slotProps: ExpressionNode | undefined, slotChildren: TemplateChildNode[], loc: SourceLocation) => FunctionExpression;
986
+ export type SlotFnBuilder = (slotProps: ExpressionNode | undefined, vForExp: ExpressionNode | undefined, slotChildren: TemplateChildNode[], loc: SourceLocation) => FunctionExpression;
980
987
  export declare function buildSlots(node: ElementNode, context: TransformContext, buildSlotFn?: SlotFnBuilder): {
981
988
  slots: SlotsExpression;
982
989
  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,
@@ -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
  }
@@ -4691,4 +4702,4 @@ function baseCompile(template, options = {}) {
4691
4702
 
4692
4703
  const noopDirectiveTransform = () => ({ props: [] });
4693
4704
 
4694
- export { BASE_TRANSITION, CAMELIZE, CAPITALIZE, CREATE_BLOCK, CREATE_COMMENT, CREATE_ELEMENT_BLOCK, CREATE_ELEMENT_VNODE, CREATE_SLOTS, CREATE_STATIC, CREATE_TEXT, CREATE_VNODE, FRAGMENT, GUARD_REACTIVE_PROPS, IS_MEMO_SAME, IS_REF, KEEP_ALIVE, MERGE_PROPS, NORMALIZE_CLASS, NORMALIZE_PROPS, NORMALIZE_STYLE, OPEN_BLOCK, POP_SCOPE_ID, PUSH_SCOPE_ID, RENDER_LIST, RENDER_SLOT, RESOLVE_COMPONENT, RESOLVE_DIRECTIVE, RESOLVE_DYNAMIC_COMPONENT, RESOLVE_FILTER, SET_BLOCK_TRACKING, SUSPENSE, TELEPORT, TO_DISPLAY_STRING, TO_HANDLERS, TO_HANDLER_KEY, TS_NODE_TYPES, UNREF, WITH_CTX, WITH_DIRECTIVES, WITH_MEMO, advancePositionWithClone, advancePositionWithMutation, assert, baseCompile, baseParse, buildDirectiveArgs, buildProps, buildSlots, checkCompatEnabled, convertToBlock, createArrayExpression, createAssignmentExpression, createBlockStatement, createCacheExpression, createCallExpression, createCompilerError, createCompoundExpression, createConditionalExpression, createForLoopParams, createFunctionExpression, createIfStatement, createInterpolation, createObjectExpression, createObjectProperty, createReturnStatement, createRoot, createSequenceExpression, createSimpleExpression, createStructuralDirectiveTransform, createTemplateLiteral, createTransformContext, createVNodeCall, extractIdentifiers, findDir, findProp, generate, getBaseTransformPreset, getConstantType, getInnerRange, getMemoedVNodeCall, getVNodeBlockHelper, getVNodeHelper, hasDynamicKeyVBind, hasScopeRef, helperNameMap, injectProp, isBuiltInType, isCoreComponent, isFunctionType, isInDestructureAssignment, isMemberExpression, isMemberExpressionBrowser, isMemberExpressionNode, isReferencedIdentifier, isSimpleIdentifier, isSlotOutlet, isStaticArgOf, isStaticExp, isStaticProperty, isStaticPropertyKey, isTemplateNode, isText$1 as isText, isVSlot, locStub, noopDirectiveTransform, processExpression, processFor, processIf, processSlotOutlet, registerRuntimeHelpers, resolveComponentType, stringifyExpression, toValidAssetId, trackSlotScopes, trackVForSlotScopes, transform, transformBind, transformElement, transformExpression, transformModel, transformOn, traverseNode, walkBlockDeclarations, walkFunctionParams, walkIdentifiers, warnDeprecation };
4705
+ export { BASE_TRANSITION, CAMELIZE, CAPITALIZE, CREATE_BLOCK, CREATE_COMMENT, CREATE_ELEMENT_BLOCK, CREATE_ELEMENT_VNODE, CREATE_SLOTS, CREATE_STATIC, CREATE_TEXT, CREATE_VNODE, FRAGMENT, GUARD_REACTIVE_PROPS, IS_MEMO_SAME, IS_REF, KEEP_ALIVE, MERGE_PROPS, NORMALIZE_CLASS, NORMALIZE_PROPS, NORMALIZE_STYLE, OPEN_BLOCK, POP_SCOPE_ID, PUSH_SCOPE_ID, RENDER_LIST, RENDER_SLOT, RESOLVE_COMPONENT, RESOLVE_DIRECTIVE, RESOLVE_DYNAMIC_COMPONENT, RESOLVE_FILTER, SET_BLOCK_TRACKING, SUSPENSE, TELEPORT, TO_DISPLAY_STRING, TO_HANDLERS, TO_HANDLER_KEY, TS_NODE_TYPES, UNREF, WITH_CTX, WITH_DIRECTIVES, WITH_MEMO, advancePositionWithClone, advancePositionWithMutation, assert, baseCompile, baseParse, buildDirectiveArgs, buildProps, buildSlots, checkCompatEnabled, convertToBlock, createArrayExpression, createAssignmentExpression, createBlockStatement, createCacheExpression, createCallExpression, createCompilerError, createCompoundExpression, createConditionalExpression, createForLoopParams, createFunctionExpression, createIfStatement, createInterpolation, createObjectExpression, createObjectProperty, createReturnStatement, createRoot, createSequenceExpression, createSimpleExpression, createStructuralDirectiveTransform, createTemplateLiteral, createTransformContext, createVNodeCall, errorMessages, extractIdentifiers, findDir, findProp, generate, getBaseTransformPreset, getConstantType, getInnerRange, getMemoedVNodeCall, getVNodeBlockHelper, getVNodeHelper, hasDynamicKeyVBind, hasScopeRef, helperNameMap, injectProp, isBuiltInType, isCoreComponent, isFunctionType, isInDestructureAssignment, isMemberExpression, isMemberExpressionBrowser, isMemberExpressionNode, isReferencedIdentifier, isSimpleIdentifier, isSlotOutlet, isStaticArgOf, isStaticExp, isStaticProperty, isStaticPropertyKey, isTemplateNode, isText$1 as isText, isVSlot, locStub, noopDirectiveTransform, processExpression, processFor, processIf, processSlotOutlet, registerRuntimeHelpers, resolveComponentType, stringifyExpression, toValidAssetId, trackSlotScopes, trackVForSlotScopes, transform, transformBind, transformElement, transformExpression, transformModel, transformOn, traverseNode, walkBlockDeclarations, walkFunctionParams, walkIdentifiers, warnDeprecation };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vue/compiler-core",
3
- "version": "3.3.6",
3
+ "version": "3.4.0-alpha.1",
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.6",
36
+ "@vue/shared": "3.4.0-alpha.1",
37
37
  "estree-walker": "^2.0.2",
38
38
  "source-map-js": "^1.0.2"
39
39
  },