@lwc/engine-core 2.25.0 → 2.26.0

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,7 +1,7 @@
1
1
  /* proxy-compat-disable */
2
2
  import { lwcRuntimeFlags } from '@lwc/features';
3
3
  export { setFeatureFlag, setFeatureFlagForTest } from '@lwc/features';
4
- import { seal, create, isUndefined as isUndefined$1, isFunction as isFunction$1, ArrayPush as ArrayPush$1, ArrayIndexOf, ArraySplice, StringToLowerCase, isNull, ArrayJoin, isFrozen, defineProperty, hasOwnProperty as hasOwnProperty$1, assign, forEach, keys, AriaPropNameToAttrNameMap, getPropertyDescriptor, defineProperties, getOwnPropertyNames as getOwnPropertyNames$1, getPrototypeOf as getPrototypeOf$1, setPrototypeOf, isObject, freeze, assert, KEY__SYNTHETIC_MODE, isFalse, isTrue, toString as toString$1, getOwnPropertyDescriptor as getOwnPropertyDescriptor$1, LWC_VERSION_COMMENT_REGEX, LWC_VERSION, htmlPropertyToAttribute, ArraySlice, ArrayMap, isArray as isArray$1, KEY__SCOPED_CSS, StringCharCodeAt, XML_NAMESPACE, XLINK_NAMESPACE, isString, StringSlice, SVG_NAMESPACE, KEY__SHADOW_STATIC, KEY__SHADOW_RESOLVER, isNumber, StringReplace, noop, ArrayUnshift, ArrayCopyWithin, ArrayFill, ArraySort, ArrayReverse, ArrayShift, ArrayPop } from '@lwc/shared';
4
+ import { seal, create, isUndefined as isUndefined$1, isFunction as isFunction$1, ArrayPush as ArrayPush$1, ArrayIndexOf, ArraySplice, StringToLowerCase, isNull, ArrayJoin, isFrozen, defineProperty, hasOwnProperty as hasOwnProperty$1, assign, forEach, keys, AriaPropNameToAttrNameMap, getPropertyDescriptor, defineProperties, getOwnPropertyNames as getOwnPropertyNames$1, getPrototypeOf as getPrototypeOf$1, setPrototypeOf, isObject, freeze, assert, KEY__SYNTHETIC_MODE, isFalse, isTrue, toString as toString$1, getOwnPropertyDescriptor as getOwnPropertyDescriptor$1, LWC_VERSION_COMMENT_REGEX, LWC_VERSION, htmlPropertyToAttribute, ArraySlice, ArrayMap, isArray as isArray$1, KEY__SCOPED_CSS, StringCharCodeAt, XML_NAMESPACE, XLINK_NAMESPACE, isString, StringSlice, SVG_NAMESPACE, KEY__SHADOW_STATIC, KEY__SHADOW_RESOLVER, isNumber, StringReplace, noop, ArrayUnshift, ArrayFilter, ArrayCopyWithin, ArrayFill, ArraySort, ArrayReverse, ArrayShift, ArrayPop } from '@lwc/shared';
5
5
 
6
6
  /*
7
7
  * Copyright (c) 2018, salesforce.com, inc.
@@ -1462,7 +1462,9 @@ const refsCache = new WeakMap();
1462
1462
  const LightningElement = function () {
1463
1463
  // This should be as performant as possible, while any initialization should be done lazily
1464
1464
  if (isNull(vmBeingConstructed)) {
1465
- throw new ReferenceError('Illegal constructor');
1465
+ // Thrown when doing something like `new LightningElement()` or
1466
+ // `class Foo extends LightningElement {}; new Foo()`
1467
+ throw new TypeError('Illegal constructor');
1466
1468
  }
1467
1469
  const vm = vmBeingConstructed;
1468
1470
  const { def, elm } = vm;
@@ -2526,274 +2528,213 @@ const swappedStyleMap = new WeakMap();
2526
2528
  const activeTemplates = new WeakMap();
2527
2529
  const activeComponents = new WeakMap();
2528
2530
  const activeStyles = new WeakMap();
2529
-
2530
2531
  function rehydrateHotTemplate(tpl) {
2531
- const list = activeTemplates.get(tpl);
2532
-
2533
- if (!isUndefined$1(list)) {
2534
- list.forEach(vm => {
2535
- if (isFalse(vm.isDirty)) {
2536
- // forcing the vm to rehydrate in the micro-task:
2537
- markComponentAsDirty(vm);
2538
- scheduleRehydration(vm);
2539
- }
2540
- }); // resetting the Set to release the memory of those vm references
2541
- // since they are not longer related to this template, instead
2542
- // they will get re-associated once these instances are rehydrated.
2543
-
2544
- list.clear();
2545
- }
2546
-
2547
- return true;
2532
+ const list = activeTemplates.get(tpl);
2533
+ if (!isUndefined$1(list)) {
2534
+ list.forEach((vm) => {
2535
+ if (isFalse(vm.isDirty)) {
2536
+ // forcing the vm to rehydrate in the micro-task:
2537
+ markComponentAsDirty(vm);
2538
+ scheduleRehydration(vm);
2539
+ }
2540
+ });
2541
+ // resetting the Set to release the memory of those vm references
2542
+ // since they are not longer related to this template, instead
2543
+ // they will get re-associated once these instances are rehydrated.
2544
+ list.clear();
2545
+ }
2546
+ return true;
2548
2547
  }
2549
-
2550
2548
  function rehydrateHotStyle(style) {
2551
- const list = activeStyles.get(style);
2552
-
2553
- if (!isUndefined$1(list)) {
2554
- list.forEach(vm => {
2555
- // if a style definition is swapped, we must reset
2556
- // vm's template content in the next micro-task:
2557
- forceRehydration(vm);
2558
- }); // resetting the Set to release the memory of those vm references
2559
- // since they are not longer related to this style, instead
2560
- // they will get re-associated once these instances are rehydrated.
2561
-
2562
- list.clear();
2563
- }
2564
-
2565
- return true;
2549
+ const list = activeStyles.get(style);
2550
+ if (!isUndefined$1(list)) {
2551
+ list.forEach((vm) => {
2552
+ // if a style definition is swapped, we must reset
2553
+ // vm's template content in the next micro-task:
2554
+ forceRehydration(vm);
2555
+ });
2556
+ // resetting the Set to release the memory of those vm references
2557
+ // since they are not longer related to this style, instead
2558
+ // they will get re-associated once these instances are rehydrated.
2559
+ list.clear();
2560
+ }
2561
+ return true;
2566
2562
  }
2567
-
2568
2563
  function rehydrateHotComponent(Ctor) {
2569
- const list = activeComponents.get(Ctor);
2570
- let canRefreshAllInstances = true;
2571
-
2572
- if (!isUndefined$1(list)) {
2573
- list.forEach(vm => {
2574
- const {
2575
- owner
2576
- } = vm;
2577
-
2578
- if (!isNull(owner)) {
2579
- // if a component class definition is swapped, we must reset
2580
- // owner's template content in the next micro-task:
2581
- forceRehydration(owner);
2582
- } else {
2583
- // the hot swapping for components only work for instances of components
2584
- // created from a template, root elements can't be swapped because we
2585
- // don't have a way to force the creation of the element with the same state
2586
- // of the current element.
2587
- // Instead, we can report the problem to the caller so it can take action,
2588
- // for example: reload the entire page.
2589
- canRefreshAllInstances = false;
2590
- }
2591
- }); // resetting the Set to release the memory of those vm references
2592
- // since they are not longer related to this constructor, instead
2593
- // they will get re-associated once these instances are rehydrated.
2594
-
2595
- list.clear();
2596
- }
2597
-
2598
- return canRefreshAllInstances;
2564
+ const list = activeComponents.get(Ctor);
2565
+ let canRefreshAllInstances = true;
2566
+ if (!isUndefined$1(list)) {
2567
+ list.forEach((vm) => {
2568
+ const { owner } = vm;
2569
+ if (!isNull(owner)) {
2570
+ // if a component class definition is swapped, we must reset
2571
+ // owner's template content in the next micro-task:
2572
+ forceRehydration(owner);
2573
+ }
2574
+ else {
2575
+ // the hot swapping for components only work for instances of components
2576
+ // created from a template, root elements can't be swapped because we
2577
+ // don't have a way to force the creation of the element with the same state
2578
+ // of the current element.
2579
+ // Instead, we can report the problem to the caller so it can take action,
2580
+ // for example: reload the entire page.
2581
+ canRefreshAllInstances = false;
2582
+ }
2583
+ });
2584
+ // resetting the Set to release the memory of those vm references
2585
+ // since they are not longer related to this constructor, instead
2586
+ // they will get re-associated once these instances are rehydrated.
2587
+ list.clear();
2588
+ }
2589
+ return canRefreshAllInstances;
2599
2590
  }
2600
-
2601
2591
  function getTemplateOrSwappedTemplate(tpl) {
2602
- if (process.env.NODE_ENV === 'production') {
2603
- // this method should never leak to prod
2604
- throw new ReferenceError();
2605
- }
2606
-
2607
- if (lwcRuntimeFlags.ENABLE_HMR) {
2592
+ if (process.env.NODE_ENV === 'production') {
2593
+ // this method should never leak to prod
2594
+ throw new ReferenceError();
2595
+ }
2608
2596
  const visited = new Set();
2609
-
2610
2597
  while (swappedTemplateMap.has(tpl) && !visited.has(tpl)) {
2611
- visited.add(tpl);
2612
- tpl = swappedTemplateMap.get(tpl);
2598
+ visited.add(tpl);
2599
+ tpl = swappedTemplateMap.get(tpl);
2613
2600
  }
2614
- }
2615
-
2616
- return tpl;
2601
+ return tpl;
2617
2602
  }
2618
2603
  function getComponentOrSwappedComponent(Ctor) {
2619
- if (process.env.NODE_ENV === 'production') {
2620
- // this method should never leak to prod
2621
- throw new ReferenceError();
2622
- }
2623
-
2624
- if (lwcRuntimeFlags.ENABLE_HMR) {
2604
+ if (process.env.NODE_ENV === 'production') {
2605
+ // this method should never leak to prod
2606
+ throw new ReferenceError();
2607
+ }
2625
2608
  const visited = new Set();
2626
-
2627
2609
  while (swappedComponentMap.has(Ctor) && !visited.has(Ctor)) {
2628
- visited.add(Ctor);
2629
- Ctor = swappedComponentMap.get(Ctor);
2610
+ visited.add(Ctor);
2611
+ Ctor = swappedComponentMap.get(Ctor);
2630
2612
  }
2631
- }
2632
-
2633
- return Ctor;
2613
+ return Ctor;
2634
2614
  }
2635
2615
  function getStyleOrSwappedStyle(style) {
2636
- if (process.env.NODE_ENV === 'production') {
2637
- // this method should never leak to prod
2638
- throw new ReferenceError();
2639
- }
2640
-
2641
- if (lwcRuntimeFlags.ENABLE_HMR) {
2616
+ if (process.env.NODE_ENV === 'production') {
2617
+ // this method should never leak to prod
2618
+ throw new ReferenceError();
2619
+ }
2642
2620
  const visited = new Set();
2643
-
2644
2621
  while (swappedStyleMap.has(style) && !visited.has(style)) {
2645
- visited.add(style);
2646
- style = swappedStyleMap.get(style);
2622
+ visited.add(style);
2623
+ style = swappedStyleMap.get(style);
2647
2624
  }
2648
- }
2649
-
2650
- return style;
2625
+ return style;
2651
2626
  }
2652
2627
  function setActiveVM(vm) {
2653
- if (process.env.NODE_ENV === 'production') {
2654
- // this method should never leak to prod
2655
- throw new ReferenceError();
2656
- }
2657
-
2658
- if (lwcRuntimeFlags.ENABLE_HMR) {
2628
+ if (process.env.NODE_ENV === 'production') {
2629
+ // this method should never leak to prod
2630
+ throw new ReferenceError();
2631
+ }
2659
2632
  // tracking active component
2660
2633
  const Ctor = vm.def.ctor;
2661
2634
  let componentVMs = activeComponents.get(Ctor);
2662
-
2663
2635
  if (isUndefined$1(componentVMs)) {
2664
- componentVMs = new Set();
2665
- activeComponents.set(Ctor, componentVMs);
2666
- } // this will allow us to keep track of the hot components
2667
-
2668
-
2669
- componentVMs.add(vm); // tracking active template
2670
-
2636
+ componentVMs = new Set();
2637
+ activeComponents.set(Ctor, componentVMs);
2638
+ }
2639
+ // this will allow us to keep track of the hot components
2640
+ componentVMs.add(vm);
2641
+ // tracking active template
2671
2642
  const tpl = vm.cmpTemplate;
2672
-
2673
2643
  if (tpl) {
2674
- let templateVMs = activeTemplates.get(tpl);
2675
-
2676
- if (isUndefined$1(templateVMs)) {
2677
- templateVMs = new Set();
2678
- activeTemplates.set(tpl, templateVMs);
2679
- } // this will allow us to keep track of the templates that are
2680
- // being used by a hot component
2681
-
2682
-
2683
- templateVMs.add(vm); // tracking active styles associated to template
2684
-
2685
- const stylesheets = tpl.stylesheets;
2686
-
2687
- if (!isUndefined$1(stylesheets)) {
2688
- flattenStylesheets(stylesheets).forEach(stylesheet => {
2689
- // this is necessary because we don't hold the list of styles
2690
- // in the vm, we only hold the selected (already swapped template)
2691
- // but the styles attached to the template might not be the actual
2692
- // active ones, but the swapped versions of those.
2693
- stylesheet = getStyleOrSwappedStyle(stylesheet);
2694
- let stylesheetVMs = activeStyles.get(stylesheet);
2695
-
2696
- if (isUndefined$1(stylesheetVMs)) {
2697
- stylesheetVMs = new Set();
2698
- activeStyles.set(stylesheet, stylesheetVMs);
2699
- } // this will allow us to keep track of the stylesheet that are
2700
- // being used by a hot component
2701
-
2702
-
2703
- stylesheetVMs.add(vm);
2704
- });
2705
- }
2644
+ let templateVMs = activeTemplates.get(tpl);
2645
+ if (isUndefined$1(templateVMs)) {
2646
+ templateVMs = new Set();
2647
+ activeTemplates.set(tpl, templateVMs);
2648
+ }
2649
+ // this will allow us to keep track of the templates that are
2650
+ // being used by a hot component
2651
+ templateVMs.add(vm);
2652
+ // tracking active styles associated to template
2653
+ const stylesheets = tpl.stylesheets;
2654
+ if (!isUndefined$1(stylesheets)) {
2655
+ flattenStylesheets(stylesheets).forEach((stylesheet) => {
2656
+ // this is necessary because we don't hold the list of styles
2657
+ // in the vm, we only hold the selected (already swapped template)
2658
+ // but the styles attached to the template might not be the actual
2659
+ // active ones, but the swapped versions of those.
2660
+ stylesheet = getStyleOrSwappedStyle(stylesheet);
2661
+ let stylesheetVMs = activeStyles.get(stylesheet);
2662
+ if (isUndefined$1(stylesheetVMs)) {
2663
+ stylesheetVMs = new Set();
2664
+ activeStyles.set(stylesheet, stylesheetVMs);
2665
+ }
2666
+ // this will allow us to keep track of the stylesheet that are
2667
+ // being used by a hot component
2668
+ stylesheetVMs.add(vm);
2669
+ });
2670
+ }
2706
2671
  }
2707
- }
2708
2672
  }
2709
2673
  function removeActiveVM(vm) {
2710
- if (process.env.NODE_ENV === 'production') {
2711
- // this method should never leak to prod
2712
- throw new ReferenceError();
2713
- }
2714
-
2715
- if (lwcRuntimeFlags.ENABLE_HMR) {
2674
+ if (process.env.NODE_ENV === 'production') {
2675
+ // this method should never leak to prod
2676
+ throw new ReferenceError();
2677
+ }
2716
2678
  // tracking inactive component
2717
2679
  const Ctor = vm.def.ctor;
2718
2680
  let list = activeComponents.get(Ctor);
2719
-
2720
2681
  if (!isUndefined$1(list)) {
2721
- // deleting the vm from the set to avoid leaking memory
2722
- list.delete(vm);
2723
- } // removing inactive template
2724
-
2725
-
2726
- const tpl = vm.cmpTemplate;
2727
-
2728
- if (tpl) {
2729
- list = activeTemplates.get(tpl);
2730
-
2731
- if (!isUndefined$1(list)) {
2732
2682
  // deleting the vm from the set to avoid leaking memory
2733
2683
  list.delete(vm);
2734
- } // removing active styles associated to template
2735
-
2736
-
2737
- const styles = tpl.stylesheets;
2738
-
2739
- if (!isUndefined$1(styles)) {
2740
- flattenStylesheets(styles).forEach(style => {
2741
- list = activeStyles.get(style);
2742
-
2743
- if (!isUndefined$1(list)) {
2684
+ }
2685
+ // removing inactive template
2686
+ const tpl = vm.cmpTemplate;
2687
+ if (tpl) {
2688
+ list = activeTemplates.get(tpl);
2689
+ if (!isUndefined$1(list)) {
2744
2690
  // deleting the vm from the set to avoid leaking memory
2745
2691
  list.delete(vm);
2746
- }
2747
- });
2748
- }
2692
+ }
2693
+ // removing active styles associated to template
2694
+ const styles = tpl.stylesheets;
2695
+ if (!isUndefined$1(styles)) {
2696
+ flattenStylesheets(styles).forEach((style) => {
2697
+ list = activeStyles.get(style);
2698
+ if (!isUndefined$1(list)) {
2699
+ // deleting the vm from the set to avoid leaking memory
2700
+ list.delete(vm);
2701
+ }
2702
+ });
2703
+ }
2749
2704
  }
2750
- }
2751
2705
  }
2752
2706
  function swapTemplate(oldTpl, newTpl) {
2753
- if (process.env.NODE_ENV !== 'production') {
2754
- if (isTemplateRegistered(oldTpl) && isTemplateRegistered(newTpl)) {
2755
- swappedTemplateMap.set(oldTpl, newTpl);
2756
- return rehydrateHotTemplate(oldTpl);
2757
- } else {
2758
- throw new TypeError(`Invalid Template`);
2707
+ if (process.env.NODE_ENV !== 'production') {
2708
+ if (isTemplateRegistered(oldTpl) && isTemplateRegistered(newTpl)) {
2709
+ swappedTemplateMap.set(oldTpl, newTpl);
2710
+ return rehydrateHotTemplate(oldTpl);
2711
+ }
2712
+ else {
2713
+ throw new TypeError(`Invalid Template`);
2714
+ }
2759
2715
  }
2760
- }
2761
-
2762
- if (!lwcRuntimeFlags.ENABLE_HMR) {
2763
- throw new Error('HMR is not enabled');
2764
- }
2765
-
2766
- return false;
2716
+ return false;
2767
2717
  }
2768
2718
  function swapComponent(oldComponent, newComponent) {
2769
- if (process.env.NODE_ENV !== 'production') {
2770
- if (isComponentConstructor(oldComponent) && isComponentConstructor(newComponent)) {
2771
- swappedComponentMap.set(oldComponent, newComponent);
2772
- return rehydrateHotComponent(oldComponent);
2773
- } else {
2774
- throw new TypeError(`Invalid Component`);
2719
+ if (process.env.NODE_ENV !== 'production') {
2720
+ if (isComponentConstructor(oldComponent) && isComponentConstructor(newComponent)) {
2721
+ swappedComponentMap.set(oldComponent, newComponent);
2722
+ return rehydrateHotComponent(oldComponent);
2723
+ }
2724
+ else {
2725
+ throw new TypeError(`Invalid Component`);
2726
+ }
2775
2727
  }
2776
- }
2777
-
2778
- if (!lwcRuntimeFlags.ENABLE_HMR) {
2779
- throw new Error('HMR is not enabled');
2780
- }
2781
-
2782
- return false;
2728
+ return false;
2783
2729
  }
2784
2730
  function swapStyle(oldStyle, newStyle) {
2785
- if (process.env.NODE_ENV !== 'production') {
2786
- // TODO [#1887]: once the support for registering styles is implemented
2787
- // we can add the validation of both styles around this block.
2788
- swappedStyleMap.set(oldStyle, newStyle);
2789
- return rehydrateHotStyle(oldStyle);
2790
- }
2791
-
2792
- if (!lwcRuntimeFlags.ENABLE_HMR) {
2793
- throw new Error('HMR is not enabled');
2794
- }
2795
-
2796
- return false;
2731
+ if (process.env.NODE_ENV !== 'production') {
2732
+ // TODO [#1887]: once the support for registering styles is implemented
2733
+ // we can add the validation of both styles around this block.
2734
+ swappedStyleMap.set(oldStyle, newStyle);
2735
+ return rehydrateHotStyle(oldStyle);
2736
+ }
2737
+ return false;
2797
2738
  }
2798
2739
 
2799
2740
  /*
@@ -3000,244 +2941,273 @@ function getComponentDef(Ctor) {
3000
2941
  * SPDX-License-Identifier: MIT
3001
2942
  * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
3002
2943
  */
2944
+
3003
2945
  function makeHostToken(token) {
3004
- return `${token}-host`;
2946
+ return `${token}-host`;
3005
2947
  }
2948
+
3006
2949
  function createInlineStyleVNode(content) {
3007
- return api.h('style', {
3008
- key: 'style',
3009
- attrs: {
3010
- type: 'text/css',
3011
- },
3012
- }, [api.t(content)]);
2950
+ return api.h('style', {
2951
+ key: 'style',
2952
+ attrs: {
2953
+ type: 'text/css'
2954
+ }
2955
+ }, [api.t(content)]);
3013
2956
  }
2957
+
3014
2958
  function updateStylesheetToken(vm, template) {
3015
- const { elm, context, renderMode, shadowMode, renderer: { getClassList, removeAttribute, setAttribute }, } = vm;
3016
- const { stylesheets: newStylesheets, stylesheetToken: newStylesheetToken } = template;
3017
- const isSyntheticShadow = renderMode === 1 /* RenderMode.Shadow */ && shadowMode === 1 /* ShadowMode.Synthetic */;
3018
- const { hasScopedStyles } = context;
3019
- let newToken;
3020
- let newHasTokenInClass;
3021
- let newHasTokenInAttribute;
3022
- // Reset the styling token applied to the host element.
3023
- const { stylesheetToken: oldToken, hasTokenInClass: oldHasTokenInClass, hasTokenInAttribute: oldHasTokenInAttribute, } = context;
3024
- if (!isUndefined$1(oldToken)) {
3025
- if (oldHasTokenInClass) {
3026
- getClassList(elm).remove(makeHostToken(oldToken));
3027
- }
3028
- if (oldHasTokenInAttribute) {
3029
- removeAttribute(elm, makeHostToken(oldToken));
3030
- }
3031
- }
3032
- // Apply the new template styling token to the host element, if the new template has any
3033
- // associated stylesheets. In the case of light DOM, also ensure there is at least one scoped stylesheet.
3034
- if (!isUndefined$1(newStylesheets) && newStylesheets.length !== 0) {
3035
- newToken = newStylesheetToken;
3036
- }
3037
- // Set the new styling token on the host element
3038
- if (!isUndefined$1(newToken)) {
3039
- if (hasScopedStyles) {
3040
- getClassList(elm).add(makeHostToken(newToken));
3041
- newHasTokenInClass = true;
3042
- }
3043
- if (isSyntheticShadow) {
3044
- setAttribute(elm, makeHostToken(newToken), '');
3045
- newHasTokenInAttribute = true;
3046
- }
3047
- }
3048
- // Update the styling tokens present on the context object.
3049
- context.stylesheetToken = newToken;
3050
- context.hasTokenInClass = newHasTokenInClass;
3051
- context.hasTokenInAttribute = newHasTokenInAttribute;
2959
+ const {
2960
+ elm,
2961
+ context,
2962
+ renderMode,
2963
+ shadowMode,
2964
+ renderer: {
2965
+ getClassList,
2966
+ removeAttribute,
2967
+ setAttribute
2968
+ }
2969
+ } = vm;
2970
+ const {
2971
+ stylesheets: newStylesheets,
2972
+ stylesheetToken: newStylesheetToken
2973
+ } = template;
2974
+ const isSyntheticShadow = renderMode === 1
2975
+ /* RenderMode.Shadow */
2976
+ && shadowMode === 1
2977
+ /* ShadowMode.Synthetic */
2978
+ ;
2979
+ const {
2980
+ hasScopedStyles
2981
+ } = context;
2982
+ let newToken;
2983
+ let newHasTokenInClass;
2984
+ let newHasTokenInAttribute; // Reset the styling token applied to the host element.
2985
+
2986
+ const {
2987
+ stylesheetToken: oldToken,
2988
+ hasTokenInClass: oldHasTokenInClass,
2989
+ hasTokenInAttribute: oldHasTokenInAttribute
2990
+ } = context;
2991
+
2992
+ if (!isUndefined$1(oldToken)) {
2993
+ if (oldHasTokenInClass) {
2994
+ getClassList(elm).remove(makeHostToken(oldToken));
2995
+ }
2996
+
2997
+ if (oldHasTokenInAttribute) {
2998
+ removeAttribute(elm, makeHostToken(oldToken));
2999
+ }
3000
+ } // Apply the new template styling token to the host element, if the new template has any
3001
+ // associated stylesheets. In the case of light DOM, also ensure there is at least one scoped stylesheet.
3002
+
3003
+
3004
+ if (!isUndefined$1(newStylesheets) && newStylesheets.length !== 0) {
3005
+ newToken = newStylesheetToken;
3006
+ } // Set the new styling token on the host element
3007
+
3008
+
3009
+ if (!isUndefined$1(newToken)) {
3010
+ if (hasScopedStyles) {
3011
+ getClassList(elm).add(makeHostToken(newToken));
3012
+ newHasTokenInClass = true;
3013
+ }
3014
+
3015
+ if (isSyntheticShadow) {
3016
+ setAttribute(elm, makeHostToken(newToken), '');
3017
+ newHasTokenInAttribute = true;
3018
+ }
3019
+ } // Update the styling tokens present on the context object.
3020
+
3021
+
3022
+ context.stylesheetToken = newToken;
3023
+ context.hasTokenInClass = newHasTokenInClass;
3024
+ context.hasTokenInAttribute = newHasTokenInAttribute;
3052
3025
  }
3026
+
3053
3027
  function evaluateStylesheetsContent(stylesheets, stylesheetToken, vm) {
3054
- const content = [];
3055
- let root;
3056
- for (let i = 0; i < stylesheets.length; i++) {
3057
- let stylesheet = stylesheets[i];
3058
- if (isArray$1(stylesheet)) {
3059
- ArrayPush$1.apply(content, evaluateStylesheetsContent(stylesheet, stylesheetToken, vm));
3028
+ const content = [];
3029
+ let root;
3030
+
3031
+ for (let i = 0; i < stylesheets.length; i++) {
3032
+ let stylesheet = stylesheets[i];
3033
+
3034
+ if (isArray$1(stylesheet)) {
3035
+ ArrayPush$1.apply(content, evaluateStylesheetsContent(stylesheet, stylesheetToken, vm));
3036
+ } else {
3037
+ if (process.env.NODE_ENV !== 'production') {
3038
+ // Check for compiler version mismatch in dev mode only
3039
+ checkVersionMismatch(stylesheet, 'stylesheet'); // in dev-mode, we support hot swapping of stylesheet, which means that
3040
+ // the component instance might be attempting to use an old version of
3041
+ // the stylesheet, while internally, we have a replacement for it.
3042
+
3043
+ stylesheet = getStyleOrSwappedStyle(stylesheet);
3044
+ }
3045
+
3046
+ const isScopedCss = stylesheet[KEY__SCOPED_CSS];
3047
+
3048
+ if (lwcRuntimeFlags.DISABLE_LIGHT_DOM_UNSCOPED_CSS) {
3049
+ if (!isScopedCss && vm.renderMode === 0
3050
+ /* RenderMode.Light */
3051
+ ) {
3052
+ logError('Unscoped CSS is not supported in Light DOM. Please use scoped CSS (*.scoped.css) instead of unscoped CSS (*.css).');
3053
+ continue;
3060
3054
  }
3061
- else {
3062
- if (process.env.NODE_ENV !== 'production') {
3063
- // Check for compiler version mismatch in dev mode only
3064
- checkVersionMismatch(stylesheet, 'stylesheet');
3065
- // in dev-mode, we support hot swapping of stylesheet, which means that
3066
- // the component instance might be attempting to use an old version of
3067
- // the stylesheet, while internally, we have a replacement for it.
3068
- stylesheet = getStyleOrSwappedStyle(stylesheet);
3069
- }
3070
- const isScopedCss = stylesheet[KEY__SCOPED_CSS];
3071
- // Apply the scope token only if the stylesheet itself is scoped, or if we're rendering synthetic shadow.
3072
- const scopeToken = isScopedCss ||
3073
- (vm.shadowMode === 1 /* ShadowMode.Synthetic */ && vm.renderMode === 1 /* RenderMode.Shadow */)
3074
- ? stylesheetToken
3075
- : undefined;
3076
- // Use the actual `:host` selector if we're rendering global CSS for light DOM, or if we're rendering
3077
- // native shadow DOM. Synthetic shadow DOM never uses `:host`.
3078
- const useActualHostSelector = vm.renderMode === 0 /* RenderMode.Light */
3079
- ? !isScopedCss
3080
- : vm.shadowMode === 0 /* ShadowMode.Native */;
3081
- // Use the native :dir() pseudoclass only in native shadow DOM. Otherwise, in synthetic shadow,
3082
- // we use an attribute selector on the host to simulate :dir().
3083
- let useNativeDirPseudoclass;
3084
- if (vm.renderMode === 1 /* RenderMode.Shadow */) {
3085
- useNativeDirPseudoclass = vm.shadowMode === 0 /* ShadowMode.Native */;
3086
- }
3087
- else {
3088
- // Light DOM components should only render `[dir]` if they're inside of a synthetic shadow root.
3089
- // At the top level (root is null) or inside of a native shadow root, they should use `:dir()`.
3090
- if (isUndefined$1(root)) {
3091
- // Only calculate the root once as necessary
3092
- root = getNearestShadowComponent(vm);
3093
- }
3094
- useNativeDirPseudoclass = isNull(root) || root.shadowMode === 0 /* ShadowMode.Native */;
3095
- }
3096
- ArrayPush$1.call(content, stylesheet(scopeToken, useActualHostSelector, useNativeDirPseudoclass));
3055
+ } // Apply the scope token only if the stylesheet itself is scoped, or if we're rendering synthetic shadow.
3056
+
3057
+
3058
+ const scopeToken = isScopedCss || vm.shadowMode === 1
3059
+ /* ShadowMode.Synthetic */
3060
+ && vm.renderMode === 1
3061
+ /* RenderMode.Shadow */
3062
+ ? stylesheetToken : undefined; // Use the actual `:host` selector if we're rendering global CSS for light DOM, or if we're rendering
3063
+ // native shadow DOM. Synthetic shadow DOM never uses `:host`.
3064
+
3065
+ const useActualHostSelector = vm.renderMode === 0
3066
+ /* RenderMode.Light */
3067
+ ? !isScopedCss : vm.shadowMode === 0
3068
+ /* ShadowMode.Native */
3069
+ ; // Use the native :dir() pseudoclass only in native shadow DOM. Otherwise, in synthetic shadow,
3070
+ // we use an attribute selector on the host to simulate :dir().
3071
+
3072
+ let useNativeDirPseudoclass;
3073
+
3074
+ if (vm.renderMode === 1
3075
+ /* RenderMode.Shadow */
3076
+ ) {
3077
+ useNativeDirPseudoclass = vm.shadowMode === 0
3078
+ /* ShadowMode.Native */
3079
+ ;
3080
+ } else {
3081
+ // Light DOM components should only render `[dir]` if they're inside of a synthetic shadow root.
3082
+ // At the top level (root is null) or inside of a native shadow root, they should use `:dir()`.
3083
+ if (isUndefined$1(root)) {
3084
+ // Only calculate the root once as necessary
3085
+ root = getNearestShadowComponent(vm);
3097
3086
  }
3087
+
3088
+ useNativeDirPseudoclass = isNull(root) || root.shadowMode === 0
3089
+ /* ShadowMode.Native */
3090
+ ;
3091
+ }
3092
+
3093
+ ArrayPush$1.call(content, stylesheet(scopeToken, useActualHostSelector, useNativeDirPseudoclass));
3098
3094
  }
3099
- return content;
3095
+ }
3096
+
3097
+ return content;
3100
3098
  }
3099
+
3101
3100
  function getStylesheetsContent(vm, template) {
3102
- const { stylesheets, stylesheetToken } = template;
3103
- let content = [];
3104
- if (!isUndefined$1(stylesheets) && stylesheets.length !== 0) {
3105
- content = evaluateStylesheetsContent(stylesheets, stylesheetToken, vm);
3106
- }
3107
- return content;
3108
- }
3109
- // It might be worth caching this to avoid doing the lookup repeatedly, but
3101
+ const {
3102
+ stylesheets,
3103
+ stylesheetToken
3104
+ } = template;
3105
+ let content = [];
3106
+
3107
+ if (!isUndefined$1(stylesheets) && stylesheets.length !== 0) {
3108
+ content = evaluateStylesheetsContent(stylesheets, stylesheetToken, vm);
3109
+ }
3110
+
3111
+ return content;
3112
+ } // It might be worth caching this to avoid doing the lookup repeatedly, but
3110
3113
  // perf testing has not shown it to be a huge improvement yet:
3111
3114
  // https://github.com/salesforce/lwc/pull/2460#discussion_r691208892
3115
+
3112
3116
  function getNearestShadowComponent(vm) {
3113
- let owner = vm;
3114
- while (!isNull(owner)) {
3115
- if (owner.renderMode === 1 /* RenderMode.Shadow */) {
3116
- return owner;
3117
- }
3118
- owner = owner.owner;
3117
+ let owner = vm;
3118
+
3119
+ while (!isNull(owner)) {
3120
+ if (owner.renderMode === 1
3121
+ /* RenderMode.Shadow */
3122
+ ) {
3123
+ return owner;
3119
3124
  }
3120
- return owner;
3125
+
3126
+ owner = owner.owner;
3127
+ }
3128
+
3129
+ return owner;
3121
3130
  }
3122
3131
  /**
3123
3132
  * If the component that is currently being rendered uses scoped styles,
3124
3133
  * this returns the unique token for that scoped stylesheet. Otherwise
3125
3134
  * it returns null.
3126
3135
  */
3136
+
3137
+
3127
3138
  function getScopeTokenClass(owner) {
3128
- const { cmpTemplate, context } = owner;
3129
- return (context.hasScopedStyles && (cmpTemplate === null || cmpTemplate === void 0 ? void 0 : cmpTemplate.stylesheetToken)) || null;
3139
+ const {
3140
+ cmpTemplate,
3141
+ context
3142
+ } = owner;
3143
+ return context.hasScopedStyles && (cmpTemplate === null || cmpTemplate === void 0 ? void 0 : cmpTemplate.stylesheetToken) || null;
3130
3144
  }
3131
3145
  /**
3132
3146
  * This function returns the host style token for a custom element if it
3133
3147
  * exists. Otherwise it returns null.
3148
+ *
3149
+ * A host style token is applied to the component if scoped styles are used.
3134
3150
  */
3151
+
3135
3152
  function getStylesheetTokenHost(vnode) {
3136
- const { template: { stylesheetToken }, } = getComponentInternalDef(vnode.ctor);
3137
- return !isUndefined$1(stylesheetToken) ? makeHostToken(stylesheetToken) : null;
3138
- }
3139
- function getNearestNativeShadowComponent(vm) {
3140
- const owner = getNearestShadowComponent(vm);
3141
- if (!isNull(owner) && owner.shadowMode === 1 /* ShadowMode.Synthetic */) {
3142
- // Synthetic-within-native is impossible. So if the nearest shadow component is
3143
- // synthetic, we know we won't find a native component if we go any further.
3144
- return null;
3145
- }
3146
- return owner;
3147
- }
3148
- function createStylesheet(vm, stylesheets) {
3149
- const { renderMode, shadowMode, renderer: { insertStylesheet }, } = vm;
3150
- if (renderMode === 1 /* RenderMode.Shadow */ && shadowMode === 1 /* ShadowMode.Synthetic */) {
3151
- for (let i = 0; i < stylesheets.length; i++) {
3152
- insertStylesheet(stylesheets[i]);
3153
- }
3154
- }
3155
- else if (!process.env.IS_BROWSER || vm.hydrated) {
3156
- // Note: We need to ensure that during hydration, the stylesheets method is the same as those in ssr.
3157
- // This works in the client, because the stylesheets are created, and cached in the VM
3158
- // the first time the VM renders.
3159
- // native shadow or light DOM, SSR
3160
- return ArrayMap.call(stylesheets, createInlineStyleVNode);
3161
- }
3162
- else {
3163
- // native shadow or light DOM, DOM renderer
3164
- const root = getNearestNativeShadowComponent(vm);
3165
- // null root means a global style
3166
- const target = isNull(root) ? undefined : root.shadowRoot;
3167
- for (let i = 0; i < stylesheets.length; i++) {
3168
- insertStylesheet(stylesheets[i], target);
3169
- }
3170
- }
3171
- return null;
3153
+ const {
3154
+ template
3155
+ } = getComponentInternalDef(vnode.ctor);
3156
+ const {
3157
+ stylesheetToken
3158
+ } = template;
3159
+ return !isUndefined$1(stylesheetToken) && computeHasScopedStyles(template) ? makeHostToken(stylesheetToken) : null;
3172
3160
  }
3173
3161
 
3174
- /*
3175
- * Copyright (c) 2020, salesforce.com, inc.
3176
- * All rights reserved.
3177
- * SPDX-License-Identifier: MIT
3178
- * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
3179
- */
3180
-
3181
- function checkHasVM(elm) {
3182
- const hasVM = !isUndefined$1(getAssociatedVMIfPresent(elm));
3162
+ function getNearestNativeShadowComponent(vm) {
3163
+ const owner = getNearestShadowComponent(vm);
3183
3164
 
3184
- if (process.env.NODE_ENV !== 'production' && !hasVM) {
3185
- // Occurs when an element is manually created with the same tag name as an existing LWC component. In that case,
3186
- // we skip calling the LWC connectedCallback/disconnectedCallback logic and log an error.
3187
- logError(`VM for tag name "${elm.tagName.toLowerCase()}" is undefined. ` + `This indicates that an element was created with this tag name, ` + `which is already reserved by an LWC component. Use lwc.createElement ` + `instead to create elements.`);
3165
+ if (!isNull(owner) && owner.shadowMode === 1
3166
+ /* ShadowMode.Synthetic */
3167
+ ) {
3168
+ // Synthetic-within-native is impossible. So if the nearest shadow component is
3169
+ // synthetic, we know we won't find a native component if we go any further.
3170
+ return null;
3188
3171
  }
3189
3172
 
3190
- return hasVM;
3173
+ return owner;
3191
3174
  }
3192
3175
 
3193
- function getUpgradableConstructor(tagName, renderer) {
3176
+ function createStylesheet(vm, stylesheets) {
3194
3177
  const {
3195
- getCustomElement,
3196
- HTMLElementExported: RendererHTMLElement,
3197
- defineCustomElement
3198
- } = renderer; // Should never get a tag with upper case letter at this point, the compiler should
3199
- // produce only tags with lowercase letters
3200
- // But, for backwards compatibility, we will lower case the tagName
3201
-
3202
- tagName = tagName.toLowerCase();
3203
- let CE = getCustomElement(tagName);
3204
-
3205
- if (!isUndefined$1(CE)) {
3206
- return CE;
3207
- }
3208
- /**
3209
- * LWC Upgradable Element reference to an element that was created
3210
- * via the scoped registry mechanism, and that is ready to be upgraded.
3211
- */
3212
-
3213
-
3214
- CE = class LWCUpgradableElement extends RendererHTMLElement {
3215
- constructor(upgradeCallback) {
3216
- super();
3217
-
3218
- if (isFunction$1(upgradeCallback)) {
3219
- upgradeCallback(this); // nothing to do with the result for now
3220
- }
3178
+ renderMode,
3179
+ shadowMode,
3180
+ renderer: {
3181
+ insertStylesheet
3221
3182
  }
3183
+ } = vm;
3222
3184
 
3223
- };
3185
+ if (renderMode === 1
3186
+ /* RenderMode.Shadow */
3187
+ && shadowMode === 1
3188
+ /* ShadowMode.Synthetic */
3189
+ ) {
3190
+ for (let i = 0; i < stylesheets.length; i++) {
3191
+ insertStylesheet(stylesheets[i]);
3192
+ }
3193
+ } else if (!process.env.IS_BROWSER || vm.hydrated) {
3194
+ // Note: We need to ensure that during hydration, the stylesheets method is the same as those in ssr.
3195
+ // This works in the client, because the stylesheets are created, and cached in the VM
3196
+ // the first time the VM renders.
3197
+ // native shadow or light DOM, SSR
3198
+ return ArrayMap.call(stylesheets, createInlineStyleVNode);
3199
+ } else {
3200
+ // native shadow or light DOM, DOM renderer
3201
+ const root = getNearestNativeShadowComponent(vm); // null root means a global style
3224
3202
 
3225
- if (lwcRuntimeFlags.ENABLE_NATIVE_CUSTOM_ELEMENT_LIFECYCLE) {
3226
- CE.prototype.connectedCallback = function () {
3227
- if (checkHasVM(this)) {
3228
- connectRootElement(this);
3229
- }
3230
- };
3203
+ const target = isNull(root) ? undefined : root.shadowRoot;
3231
3204
 
3232
- CE.prototype.disconnectedCallback = function () {
3233
- if (checkHasVM(this)) {
3234
- disconnectRootElement(this);
3235
- }
3236
- };
3205
+ for (let i = 0; i < stylesheets.length; i++) {
3206
+ insertStylesheet(stylesheets[i], target);
3207
+ }
3237
3208
  }
3238
3209
 
3239
- defineCustomElement(tagName, CE);
3240
- return CE;
3210
+ return null;
3241
3211
  }
3242
3212
 
3243
3213
  /*
@@ -3753,7 +3723,9 @@ function mountCustomElement(vnode, parent, anchor, renderer) {
3753
3723
  sel,
3754
3724
  owner
3755
3725
  } = vnode;
3756
- const UpgradableConstructor = getUpgradableConstructor(sel, renderer);
3726
+ const {
3727
+ createCustomElement
3728
+ } = renderer;
3757
3729
  /**
3758
3730
  * Note: if the upgradable constructor does not expect, or throw when we new it
3759
3731
  * with a callback as the first argument, we could implement a more advanced
@@ -3762,10 +3734,25 @@ function mountCustomElement(vnode, parent, anchor, renderer) {
3762
3734
  */
3763
3735
 
3764
3736
  let vm;
3765
- const elm = new UpgradableConstructor(elm => {
3737
+
3738
+ const upgradeCallback = elm => {
3766
3739
  // the custom element from the registry is expecting an upgrade callback
3767
3740
  vm = createViewModelHook(elm, vnode, renderer);
3768
- });
3741
+ };
3742
+
3743
+ const connectedCallback = elm => {
3744
+ if (lwcRuntimeFlags.ENABLE_NATIVE_CUSTOM_ELEMENT_LIFECYCLE) {
3745
+ connectRootElement(elm);
3746
+ }
3747
+ };
3748
+
3749
+ const disconnectedCallback = elm => {
3750
+ if (lwcRuntimeFlags.ENABLE_NATIVE_CUSTOM_ELEMENT_LIFECYCLE) {
3751
+ disconnectRootElement(elm);
3752
+ }
3753
+ };
3754
+
3755
+ const elm = createCustomElement(sel, upgradeCallback, connectedCallback, disconnectedCallback);
3769
3756
  vnode.elm = elm;
3770
3757
  vnode.vm = vm;
3771
3758
  linkNodeToShadow(elm, owner, renderer);
@@ -3773,8 +3760,6 @@ function mountCustomElement(vnode, parent, anchor, renderer) {
3773
3760
 
3774
3761
  if (vm) {
3775
3762
  allocateChildren(vnode, vm);
3776
- } else if (vnode.ctor !== UpgradableConstructor) {
3777
- throw new TypeError(`Incorrect Component Constructor`);
3778
3763
  }
3779
3764
 
3780
3765
  patchElementPropsAndAttrs$1(null, vnode, renderer);
@@ -6556,19 +6541,23 @@ function validateClassAttr(vnode, elm, renderer) {
6556
6541
  //
6557
6542
  // Consequently, hydration mismatches will occur if scoped CSS token classnames
6558
6543
  // are rendered during SSR. This needs to be accounted for when validating.
6559
- if (scopedToken) {
6544
+ if (!isNull(scopedToken) || !isNull(stylesheetTokenHost)) {
6560
6545
  if (!isUndefined$1(className)) {
6561
- className = isNull(stylesheetTokenHost)
6562
- ? `${scopedToken} ${className}`
6563
- : `${scopedToken} ${className} ${stylesheetTokenHost}`;
6546
+ // The order of the className should be scopedToken className stylesheetTokenHost
6547
+ const classTokens = [scopedToken, className, stylesheetTokenHost];
6548
+ const classNames = ArrayFilter.call(classTokens, (token) => !isNull(token));
6549
+ className = ArrayJoin.call(classNames, ' ');
6564
6550
  }
6565
6551
  else if (!isUndefined$1(classMap)) {
6566
- classMap = Object.assign(Object.assign(Object.assign({}, classMap), { [scopedToken]: true }), (isNull(stylesheetTokenHost) ? {} : { [stylesheetTokenHost]: true }));
6552
+ classMap = Object.assign(Object.assign(Object.assign({}, classMap), (!isNull(scopedToken) ? { [scopedToken]: true } : {})), (!isNull(stylesheetTokenHost) ? { [stylesheetTokenHost]: true } : {}));
6567
6553
  }
6568
6554
  else {
6569
- className = isNull(stylesheetTokenHost)
6570
- ? `${scopedToken}`
6571
- : `${scopedToken} ${stylesheetTokenHost}`;
6555
+ // The order of the className should be scopedToken stylesheetTokenHost
6556
+ const classTokens = [scopedToken, stylesheetTokenHost];
6557
+ const classNames = ArrayFilter.call(classTokens, (token) => !isNull(token));
6558
+ if (classNames.length) {
6559
+ className = ArrayJoin.call(classNames, ' ');
6560
+ }
6572
6561
  }
6573
6562
  }
6574
6563
  let nodesAreCompatible = true;
@@ -6811,5 +6800,5 @@ function getComponentConstructor(elm) {
6811
6800
  return ctor;
6812
6801
  }
6813
6802
 
6814
- export { LightningElement, profilerControl as __unstable__ProfilerControl, api$1 as api, connectRootElement, createContextProvider, createVM, disconnectRootElement, freezeTemplate, getAssociatedVMIfPresent, getComponentConstructor, getComponentDef, getComponentHtmlPrototype, getUpgradableConstructor, hydrateRoot, isComponentConstructor, parseFragment, parseSVGFragment, readonly, register, registerComponent, registerDecorators, registerTemplate, sanitizeAttribute, setHooks, swapComponent, swapStyle, swapTemplate, track, unwrap, wire };
6815
- /* version: 2.25.0 */
6803
+ export { LightningElement, profilerControl as __unstable__ProfilerControl, api$1 as api, connectRootElement, createContextProvider, createVM, disconnectRootElement, freezeTemplate, getAssociatedVMIfPresent, getComponentConstructor, getComponentDef, getComponentHtmlPrototype, hydrateRoot, isComponentConstructor, parseFragment, parseSVGFragment, readonly, register, registerComponent, registerDecorators, registerTemplate, sanitizeAttribute, setHooks, swapComponent, swapStyle, swapTemplate, track, unwrap, wire };
6804
+ /* version: 2.26.0 */