@lwc/engine-core 2.37.0 → 2.37.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.
@@ -1,30 +1,7 @@
1
1
  /* proxy-compat-disable */
2
- import { lwcRuntimeFlags } from '@lwc/features';
3
- export { setFeatureFlag, setFeatureFlagForTest } from '@lwc/features';
4
2
  import { noop, StringToLowerCase, isNull, ArrayPush as ArrayPush$1, ArrayJoin, isFrozen, isUndefined as isUndefined$1, defineProperty, ArrayIndexOf, ArraySplice, create, seal, isArray as isArray$1, isFunction as isFunction$1, keys, hasOwnProperty as hasOwnProperty$1, forEach, AriaPropNameToAttrNameMap, getPropertyDescriptor, defineProperties, getOwnPropertyNames as getOwnPropertyNames$1, getPrototypeOf as getPrototypeOf$1, setPrototypeOf, assign, isObject, assert, freeze, KEY__SYNTHETIC_MODE, toString as toString$1, getOwnPropertyDescriptor as getOwnPropertyDescriptor$1, isFalse, LWC_VERSION_COMMENT_REGEX, LWC_VERSION, htmlPropertyToAttribute, ArraySlice, ArrayMap, KEY__SCOPED_CSS, StringCharCodeAt, XML_NAMESPACE, XLINK_NAMESPACE, htmlAttributeToProperty, isString, StringSlice, isTrue, SVG_NAMESPACE, KEY__SHADOW_STATIC, KEY__SHADOW_RESOLVER, ArraySome, ArrayPop, isNumber, StringReplace, ArrayUnshift, globalThis as globalThis$1, KEY__NATIVE_GET_ELEMENT_BY_ID, KEY__NATIVE_QUERY_SELECTOR_ALL, ID_REFERENCING_ATTRIBUTES_SET, KEY__SHADOW_TOKEN, ArrayFilter, StringSplit, ArrayCopyWithin, ArrayFill, ArraySort, ArrayReverse, ArrayShift } from '@lwc/shared';
5
3
  import { applyAriaReflection } from '@lwc/aria-reflection';
6
-
7
- /*
8
- * Copyright (c) 2018, salesforce.com, inc.
9
- * All rights reserved.
10
- * SPDX-License-Identifier: MIT
11
- * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
12
- */
13
- // Only used in LWC's Karma tests
14
- if (process.env.NODE_ENV === 'test-karma-lwc') {
15
- window.addEventListener('test-dummy-flag', () => {
16
- let hasFlag = false;
17
- if (lwcRuntimeFlags.DUMMY_TEST_FLAG) {
18
- hasFlag = true;
19
- }
20
- window.dispatchEvent(new CustomEvent('has-dummy-flag', {
21
- detail: {
22
- package: '@lwc/engine-core',
23
- hasFlag
24
- }
25
- }));
26
- });
27
- }
4
+ export { setFeatureFlag, setFeatureFlagForTest } from '@lwc/features';
28
5
 
29
6
  /*
30
7
  * Copyright (c) 2018, salesforce.com, inc.
@@ -1488,51 +1465,46 @@ function markLockerLiveObject(obj) {
1488
1465
  * for the Base Lightning Element, it also include the reactivity bit, so the standard property is reactive.
1489
1466
  */
1490
1467
  function createBridgeToElementDescriptor(propName, descriptor) {
1491
- const {
1492
- get,
1493
- set,
1494
- enumerable,
1495
- configurable
1496
- } = descriptor;
1497
- if (!isFunction$1(get)) {
1498
- if (process.env.NODE_ENV !== 'production') {
1499
- assert.fail(`Detected invalid public property descriptor for HTMLElement.prototype.${propName} definition. Missing the standard getter.`);
1500
- }
1501
- throw new TypeError();
1502
- }
1503
- if (!isFunction$1(set)) {
1504
- if (process.env.NODE_ENV !== 'production') {
1505
- assert.fail(`Detected invalid public property descriptor for HTMLElement.prototype.${propName} definition. Missing the standard setter.`);
1468
+ const { get, set, enumerable, configurable } = descriptor;
1469
+ if (!isFunction$1(get)) {
1470
+ if (process.env.NODE_ENV !== 'production') {
1471
+ assert.fail(`Detected invalid public property descriptor for HTMLElement.prototype.${propName} definition. Missing the standard getter.`);
1472
+ }
1473
+ throw new TypeError();
1506
1474
  }
1507
- throw new TypeError();
1508
- }
1509
- return {
1510
- enumerable,
1511
- configurable,
1512
- get() {
1513
- const vm = getAssociatedVM(this);
1514
- if (isBeingConstructed(vm)) {
1475
+ if (!isFunction$1(set)) {
1515
1476
  if (process.env.NODE_ENV !== 'production') {
1516
- logError(`The value of property \`${propName}\` can't be read from the constructor because the owner component hasn't set the value yet. Instead, use the constructor to set a default value for the property.`, vm);
1477
+ assert.fail(`Detected invalid public property descriptor for HTMLElement.prototype.${propName} definition. Missing the standard setter.`);
1517
1478
  }
1518
- return;
1519
- }
1520
- componentValueObserved(vm, propName);
1521
- return get.call(vm.elm);
1522
- },
1523
- set(newValue) {
1524
- const vm = getAssociatedVM(this);
1525
- if (process.env.NODE_ENV !== 'production') {
1526
- const vmBeingRendered = getVMBeingRendered();
1527
- assert.invariant(!isInvokingRender, `${vmBeingRendered}.render() method has side effects on the state of ${vm}.${propName}`);
1528
- assert.invariant(!isUpdatingTemplate, `When updating the template of ${vmBeingRendered}, one of the accessors used by the template has side effects on the state of ${vm}.${propName}`);
1529
- assert.isFalse(isBeingConstructed(vm), `Failed to construct '${getComponentTag(vm)}': The result must not have attributes.`);
1530
- assert.invariant(!isObject(newValue) || isNull(newValue), `Invalid value "${newValue}" for "${propName}" of ${vm}. Value cannot be an object, must be a primitive value.`);
1531
- }
1532
- updateComponentValue(vm, propName, newValue);
1533
- return set.call(vm.elm, newValue);
1479
+ throw new TypeError();
1534
1480
  }
1535
- };
1481
+ return {
1482
+ enumerable,
1483
+ configurable,
1484
+ get() {
1485
+ const vm = getAssociatedVM(this);
1486
+ if (isBeingConstructed(vm)) {
1487
+ if (process.env.NODE_ENV !== 'production') {
1488
+ logError(`The value of property \`${propName}\` can't be read from the constructor because the owner component hasn't set the value yet. Instead, use the constructor to set a default value for the property.`, vm);
1489
+ }
1490
+ return;
1491
+ }
1492
+ componentValueObserved(vm, propName);
1493
+ return get.call(vm.elm);
1494
+ },
1495
+ set(newValue) {
1496
+ const vm = getAssociatedVM(this);
1497
+ if (process.env.NODE_ENV !== 'production') {
1498
+ const vmBeingRendered = getVMBeingRendered();
1499
+ assert.invariant(!isInvokingRender, `${vmBeingRendered}.render() method has side effects on the state of ${vm}.${propName}`);
1500
+ assert.invariant(!isUpdatingTemplate, `When updating the template of ${vmBeingRendered}, one of the accessors used by the template has side effects on the state of ${vm}.${propName}`);
1501
+ assert.isFalse(isBeingConstructed(vm), `Failed to construct '${getComponentTag(vm)}': The result must not have attributes.`);
1502
+ assert.invariant(!isObject(newValue) || isNull(newValue), `Invalid value "${newValue}" for "${propName}" of ${vm}. Value cannot be an object, must be a primitive value.`);
1503
+ }
1504
+ updateComponentValue(vm, propName, newValue);
1505
+ return set.call(vm.elm, newValue);
1506
+ },
1507
+ };
1536
1508
  }
1537
1509
  const refsCache = new WeakMap();
1538
1510
  /**
@@ -1541,437 +1513,348 @@ const refsCache = new WeakMap();
1541
1513
  **/
1542
1514
  // @ts-ignore
1543
1515
  const LightningElement = function () {
1544
- // This should be as performant as possible, while any initialization should be done lazily
1545
- if (isNull(vmBeingConstructed)) {
1546
- // Thrown when doing something like `new LightningElement()` or
1547
- // `class Foo extends LightningElement {}; new Foo()`
1548
- throw new TypeError('Illegal constructor');
1549
- }
1550
- const vm = vmBeingConstructed;
1551
- const {
1552
- def,
1553
- elm
1554
- } = vm;
1555
- const {
1556
- bridge
1557
- } = def;
1558
- if (process.env.NODE_ENV !== 'production') {
1559
- const {
1560
- assertInstanceOfHTMLElement
1561
- } = vm.renderer;
1562
- assertInstanceOfHTMLElement(vm.elm, `Component creation requires a DOM element to be associated to ${vm}.`);
1563
- }
1564
- const component = this;
1565
- setPrototypeOf(elm, bridge.prototype);
1566
- vm.component = this;
1567
- // Locker hooks assignment. When the LWC engine run with Locker, Locker intercepts all the new
1568
- // component creation and passes hooks to instrument all the component interactions with the
1569
- // engine. We are intentionally hiding this argument from the formal API of LightningElement
1570
- // because we don't want folks to know about it just yet.
1571
- if (arguments.length === 1) {
1572
- const {
1573
- callHook,
1574
- setHook,
1575
- getHook
1576
- } = arguments[0];
1577
- vm.callHook = callHook;
1578
- vm.setHook = setHook;
1579
- vm.getHook = getHook;
1580
- }
1581
- markLockerLiveObject(this);
1582
- // Linking elm, shadow root and component with the VM.
1583
- associateVM(component, vm);
1584
- associateVM(elm, vm);
1585
- if (vm.renderMode === 1 /* RenderMode.Shadow */) {
1586
- vm.renderRoot = doAttachShadow(vm);
1587
- } else {
1588
- vm.renderRoot = elm;
1589
- }
1590
- // Adding extra guard rails in DEV mode.
1591
- if (process.env.NODE_ENV !== 'production') {
1592
- patchCustomElementWithRestrictions(elm);
1593
- patchComponentWithRestrictions(component);
1594
- }
1595
- return this;
1596
- };
1597
- function doAttachShadow(vm) {
1598
- const {
1599
- elm,
1600
- mode,
1601
- shadowMode,
1602
- def: {
1603
- ctor
1604
- },
1605
- renderer: {
1606
- attachShadow
1607
- }
1608
- } = vm;
1609
- const shadowRoot = attachShadow(elm, {
1610
- [KEY__SYNTHETIC_MODE]: shadowMode === 1 /* ShadowMode.Synthetic */,
1611
- delegatesFocus: Boolean(ctor.delegatesFocus),
1612
- mode
1613
- });
1614
- vm.shadowRoot = shadowRoot;
1615
- associateVM(shadowRoot, vm);
1616
- if (process.env.NODE_ENV !== 'production') {
1617
- patchShadowRootWithRestrictions(shadowRoot);
1618
- }
1619
- return shadowRoot;
1620
- }
1621
- function warnIfInvokedDuringConstruction(vm, methodOrPropName) {
1622
- if (isBeingConstructed(vm)) {
1623
- logError(`this.${methodOrPropName} should not be called during the construction of the custom element for ${getComponentTag(vm)} because the element is not yet in the DOM or has no children yet.`);
1624
- }
1625
- }
1626
- // @ts-ignore
1627
- LightningElement.prototype = {
1628
- constructor: LightningElement,
1629
- dispatchEvent(event) {
1630
- const vm = getAssociatedVM(this);
1631
- const {
1632
- elm,
1633
- renderer: {
1634
- dispatchEvent
1635
- }
1636
- } = vm;
1637
- return dispatchEvent(elm, event);
1638
- },
1639
- addEventListener(type, listener, options) {
1640
- const vm = getAssociatedVM(this);
1641
- const {
1642
- elm,
1643
- renderer: {
1644
- addEventListener
1645
- }
1646
- } = vm;
1647
- if (process.env.NODE_ENV !== 'production') {
1648
- const vmBeingRendered = getVMBeingRendered();
1649
- assert.invariant(!isInvokingRender, `${vmBeingRendered}.render() method has side effects on the state of ${vm} by adding an event listener for "${type}".`);
1650
- assert.invariant(!isUpdatingTemplate, `Updating the template of ${vmBeingRendered} has side effects on the state of ${vm} by adding an event listener for "${type}".`);
1651
- assert.invariant(isFunction$1(listener), `Invalid second argument for this.addEventListener() in ${vm} for event "${type}". Expected an EventListener but received ${listener}.`);
1652
- }
1653
- const wrappedListener = getWrappedComponentsListener(vm, listener);
1654
- addEventListener(elm, type, wrappedListener, options);
1655
- },
1656
- removeEventListener(type, listener, options) {
1657
- const vm = getAssociatedVM(this);
1658
- const {
1659
- elm,
1660
- renderer: {
1661
- removeEventListener
1662
- }
1663
- } = vm;
1664
- const wrappedListener = getWrappedComponentsListener(vm, listener);
1665
- removeEventListener(elm, type, wrappedListener, options);
1666
- },
1667
- hasAttribute(name) {
1668
- const vm = getAssociatedVM(this);
1669
- const {
1670
- elm,
1671
- renderer: {
1672
- getAttribute
1673
- }
1674
- } = vm;
1675
- return !isNull(getAttribute(elm, name));
1676
- },
1677
- hasAttributeNS(namespace, name) {
1678
- const vm = getAssociatedVM(this);
1679
- const {
1680
- elm,
1681
- renderer: {
1682
- getAttribute
1683
- }
1684
- } = vm;
1685
- return !isNull(getAttribute(elm, name, namespace));
1686
- },
1687
- removeAttribute(name) {
1688
- const vm = getAssociatedVM(this);
1689
- const {
1690
- elm,
1691
- renderer: {
1692
- removeAttribute
1693
- }
1694
- } = vm;
1695
- unlockAttribute(elm, name);
1696
- removeAttribute(elm, name);
1697
- lockAttribute();
1698
- },
1699
- removeAttributeNS(namespace, name) {
1700
- const {
1701
- elm,
1702
- renderer: {
1703
- removeAttribute
1704
- }
1705
- } = getAssociatedVM(this);
1706
- unlockAttribute(elm, name);
1707
- removeAttribute(elm, name, namespace);
1708
- lockAttribute();
1709
- },
1710
- getAttribute(name) {
1711
- const vm = getAssociatedVM(this);
1712
- const {
1713
- elm
1714
- } = vm;
1715
- const {
1716
- getAttribute
1717
- } = vm.renderer;
1718
- return getAttribute(elm, name);
1719
- },
1720
- getAttributeNS(namespace, name) {
1721
- const vm = getAssociatedVM(this);
1722
- const {
1723
- elm
1724
- } = vm;
1725
- const {
1726
- getAttribute
1727
- } = vm.renderer;
1728
- return getAttribute(elm, name, namespace);
1729
- },
1730
- setAttribute(name, value) {
1731
- const vm = getAssociatedVM(this);
1732
- const {
1733
- elm,
1734
- renderer: {
1735
- setAttribute
1736
- }
1737
- } = vm;
1738
- if (process.env.NODE_ENV !== 'production') {
1739
- assert.isFalse(isBeingConstructed(vm), `Failed to construct '${getComponentTag(vm)}': The result must not have attributes.`);
1740
- }
1741
- unlockAttribute(elm, name);
1742
- setAttribute(elm, name, value);
1743
- lockAttribute();
1744
- },
1745
- setAttributeNS(namespace, name, value) {
1746
- const vm = getAssociatedVM(this);
1747
- const {
1748
- elm,
1749
- renderer: {
1750
- setAttribute
1751
- }
1752
- } = vm;
1753
- if (process.env.NODE_ENV !== 'production') {
1754
- assert.isFalse(isBeingConstructed(vm), `Failed to construct '${getComponentTag(vm)}': The result must not have attributes.`);
1755
- }
1756
- unlockAttribute(elm, name);
1757
- setAttribute(elm, name, value, namespace);
1758
- lockAttribute();
1759
- },
1760
- getBoundingClientRect() {
1761
- const vm = getAssociatedVM(this);
1762
- const {
1763
- elm,
1764
- renderer: {
1765
- getBoundingClientRect
1766
- }
1767
- } = vm;
1768
- if (process.env.NODE_ENV !== 'production') {
1769
- warnIfInvokedDuringConstruction(vm, 'getBoundingClientRect()');
1770
- }
1771
- return getBoundingClientRect(elm);
1772
- },
1773
- get isConnected() {
1774
- const vm = getAssociatedVM(this);
1775
- const {
1776
- elm,
1777
- renderer: {
1778
- isConnected
1779
- }
1780
- } = vm;
1781
- return isConnected(elm);
1782
- },
1783
- get classList() {
1784
- const vm = getAssociatedVM(this);
1785
- const {
1786
- elm,
1787
- renderer: {
1788
- getClassList
1789
- }
1790
- } = vm;
1791
- if (process.env.NODE_ENV !== 'production') {
1792
- // TODO [#1290]: this still fails in dev but works in production, eventually, we should
1793
- // just throw in all modes
1794
- assert.isFalse(isBeingConstructed(vm), `Failed to construct ${vm}: The result must not have attributes. Adding or tampering with classname in constructor is not allowed in a web component, use connectedCallback() instead.`);
1795
- }
1796
- return getClassList(elm);
1797
- },
1798
- get template() {
1799
- const vm = getAssociatedVM(this);
1800
- if (process.env.NODE_ENV !== 'production') {
1801
- if (vm.renderMode === 0 /* RenderMode.Light */) {
1802
- logError('`this.template` returns null for light DOM components. Since there is no shadow, the rendered content can be accessed via `this` itself. e.g. instead of `this.template.querySelector`, use `this.querySelector`.');
1803
- }
1804
- }
1805
- return vm.shadowRoot;
1806
- },
1807
- get refs() {
1808
- const vm = getAssociatedVM(this);
1809
- if (isUpdatingTemplate) {
1810
- if (process.env.NODE_ENV !== 'production') {
1811
- logError(`this.refs should not be called while ${getComponentTag(vm)} is rendering. Use this.refs only when the DOM is stable, e.g. in renderedCallback().`);
1812
- }
1813
- // If the template is in the process of being updated, then we don't want to go through the normal
1814
- // process of returning the refs and caching them, because the state of the refs is unstable.
1815
- // This can happen if e.g. a template contains `<div class={foo}></div>` and `foo` is computed
1816
- // based on `this.refs.bar`.
1817
- return;
1818
- }
1516
+ // This should be as performant as possible, while any initialization should be done lazily
1517
+ if (isNull(vmBeingConstructed)) {
1518
+ // Thrown when doing something like `new LightningElement()` or
1519
+ // `class Foo extends LightningElement {}; new Foo()`
1520
+ throw new TypeError('Illegal constructor');
1521
+ }
1522
+ const vm = vmBeingConstructed;
1523
+ const { def, elm } = vm;
1524
+ const { bridge } = def;
1819
1525
  if (process.env.NODE_ENV !== 'production') {
1820
- warnIfInvokedDuringConstruction(vm, 'refs');
1821
- }
1822
- const {
1823
- refVNodes,
1824
- cmpTemplate
1825
- } = vm;
1826
- // If the `cmpTemplate` is null, that means that the template has not been rendered yet. Most likely this occurs
1827
- // if `this.refs` is called during the `connectedCallback` phase. The DOM elements have not been rendered yet,
1828
- // so log a warning. Note we also check `isBeingConstructed()` to avoid a double warning (due to
1829
- // `warnIfInvokedDuringConstruction` above).
1830
- if (process.env.NODE_ENV !== 'production' && isNull(cmpTemplate) && !isBeingConstructed(vm)) {
1831
- logError(`this.refs is undefined for ${getComponentTag(vm)}. This is either because the attached template has no "lwc:ref" directive, or this.refs was ` + `invoked before renderedCallback(). Use this.refs only when the referenced HTML elements have ` + `been rendered to the DOM, such as within renderedCallback() or disconnectedCallback().`);
1832
- }
1833
- // For backwards compatibility with component written before template refs
1834
- // were introduced, we return undefined if the template has no refs defined
1835
- // anywhere. This fixes components that may want to add an expando called `refs`
1836
- // and are checking if it exists with `if (this.refs)` before adding it.
1837
- // Note we use a null refVNodes to indicate that the template has no refs defined.
1838
- if (isNull(refVNodes)) {
1839
- return;
1840
- }
1841
- // The refNodes can be cached based on the refVNodes, since the refVNodes
1842
- // are recreated from scratch every time the template is rendered.
1843
- // This happens with `vm.refVNodes = null` in `template.ts` in `@lwc/engine-core`.
1844
- let refs = refsCache.get(refVNodes);
1845
- if (isUndefined$1(refs)) {
1846
- refs = create(null);
1847
- for (const key of keys(refVNodes)) {
1848
- refs[key] = refVNodes[key].elm;
1849
- }
1850
- freeze(refs);
1851
- refsCache.set(refVNodes, refs);
1852
- }
1853
- return refs;
1854
- },
1855
- // For backwards compat, we allow component authors to set `refs` as an expando
1856
- set refs(value) {
1857
- defineProperty(this, 'refs', {
1858
- configurable: true,
1859
- enumerable: true,
1860
- writable: true,
1861
- value
1862
- });
1863
- },
1864
- get shadowRoot() {
1865
- // From within the component instance, the shadowRoot is always reported as "closed".
1866
- // Authors should rely on this.template instead.
1867
- return null;
1868
- },
1869
- get children() {
1870
- const vm = getAssociatedVM(this);
1871
- const renderer = vm.renderer;
1872
- if (process.env.NODE_ENV !== 'production') {
1873
- warnIfInvokedDuringConstruction(vm, 'children');
1526
+ const { assertInstanceOfHTMLElement } = vm.renderer;
1527
+ assertInstanceOfHTMLElement(vm.elm, `Component creation requires a DOM element to be associated to ${vm}.`);
1528
+ }
1529
+ const component = this;
1530
+ setPrototypeOf(elm, bridge.prototype);
1531
+ vm.component = this;
1532
+ // Locker hooks assignment. When the LWC engine run with Locker, Locker intercepts all the new
1533
+ // component creation and passes hooks to instrument all the component interactions with the
1534
+ // engine. We are intentionally hiding this argument from the formal API of LightningElement
1535
+ // because we don't want folks to know about it just yet.
1536
+ if (arguments.length === 1) {
1537
+ const { callHook, setHook, getHook } = arguments[0];
1538
+ vm.callHook = callHook;
1539
+ vm.setHook = setHook;
1540
+ vm.getHook = getHook;
1541
+ }
1542
+ markLockerLiveObject(this);
1543
+ // Linking elm, shadow root and component with the VM.
1544
+ associateVM(component, vm);
1545
+ associateVM(elm, vm);
1546
+ if (vm.renderMode === 1 /* RenderMode.Shadow */) {
1547
+ vm.renderRoot = doAttachShadow(vm);
1874
1548
  }
1875
- return renderer.getChildren(vm.elm);
1876
- },
1877
- get childNodes() {
1878
- const vm = getAssociatedVM(this);
1879
- const renderer = vm.renderer;
1880
- if (process.env.NODE_ENV !== 'production') {
1881
- warnIfInvokedDuringConstruction(vm, 'childNodes');
1549
+ else {
1550
+ vm.renderRoot = elm;
1882
1551
  }
1883
- return renderer.getChildNodes(vm.elm);
1884
- },
1885
- get firstChild() {
1886
- const vm = getAssociatedVM(this);
1887
- const renderer = vm.renderer;
1552
+ // Adding extra guard rails in DEV mode.
1888
1553
  if (process.env.NODE_ENV !== 'production') {
1889
- warnIfInvokedDuringConstruction(vm, 'firstChild');
1554
+ patchCustomElementWithRestrictions(elm);
1555
+ patchComponentWithRestrictions(component);
1890
1556
  }
1891
- return renderer.getFirstChild(vm.elm);
1892
- },
1893
- get firstElementChild() {
1894
- const vm = getAssociatedVM(this);
1895
- const renderer = vm.renderer;
1557
+ return this;
1558
+ };
1559
+ function doAttachShadow(vm) {
1560
+ const { elm, mode, shadowMode, def: { ctor }, renderer: { attachShadow }, } = vm;
1561
+ const shadowRoot = attachShadow(elm, {
1562
+ [KEY__SYNTHETIC_MODE]: shadowMode === 1 /* ShadowMode.Synthetic */,
1563
+ delegatesFocus: Boolean(ctor.delegatesFocus),
1564
+ mode,
1565
+ });
1566
+ vm.shadowRoot = shadowRoot;
1567
+ associateVM(shadowRoot, vm);
1896
1568
  if (process.env.NODE_ENV !== 'production') {
1897
- warnIfInvokedDuringConstruction(vm, 'firstElementChild');
1569
+ patchShadowRootWithRestrictions(shadowRoot);
1898
1570
  }
1899
- return renderer.getFirstElementChild(vm.elm);
1900
- },
1901
- get lastChild() {
1902
- const vm = getAssociatedVM(this);
1903
- const renderer = vm.renderer;
1904
- if (process.env.NODE_ENV !== 'production') {
1905
- warnIfInvokedDuringConstruction(vm, 'lastChild');
1571
+ return shadowRoot;
1572
+ }
1573
+ function warnIfInvokedDuringConstruction(vm, methodOrPropName) {
1574
+ if (isBeingConstructed(vm)) {
1575
+ logError(`this.${methodOrPropName} should not be called during the construction of the custom element for ${getComponentTag(vm)} because the element is not yet in the DOM or has no children yet.`);
1906
1576
  }
1907
- return renderer.getLastChild(vm.elm);
1908
- },
1909
- get lastElementChild() {
1910
- const vm = getAssociatedVM(this);
1911
- const renderer = vm.renderer;
1912
- if (process.env.NODE_ENV !== 'production') {
1913
- warnIfInvokedDuringConstruction(vm, 'lastElementChild');
1914
- }
1915
- return renderer.getLastElementChild(vm.elm);
1916
- },
1917
- render() {
1918
- const vm = getAssociatedVM(this);
1919
- return vm.def.template;
1920
- },
1921
- toString() {
1922
- const vm = getAssociatedVM(this);
1923
- return `[object ${vm.def.name}]`;
1924
- }
1577
+ }
1578
+ // @ts-ignore
1579
+ LightningElement.prototype = {
1580
+ constructor: LightningElement,
1581
+ dispatchEvent(event) {
1582
+ const vm = getAssociatedVM(this);
1583
+ const { elm, renderer: { dispatchEvent }, } = vm;
1584
+ return dispatchEvent(elm, event);
1585
+ },
1586
+ addEventListener(type, listener, options) {
1587
+ const vm = getAssociatedVM(this);
1588
+ const { elm, renderer: { addEventListener }, } = vm;
1589
+ if (process.env.NODE_ENV !== 'production') {
1590
+ const vmBeingRendered = getVMBeingRendered();
1591
+ assert.invariant(!isInvokingRender, `${vmBeingRendered}.render() method has side effects on the state of ${vm} by adding an event listener for "${type}".`);
1592
+ assert.invariant(!isUpdatingTemplate, `Updating the template of ${vmBeingRendered} has side effects on the state of ${vm} by adding an event listener for "${type}".`);
1593
+ assert.invariant(isFunction$1(listener), `Invalid second argument for this.addEventListener() in ${vm} for event "${type}". Expected an EventListener but received ${listener}.`);
1594
+ }
1595
+ const wrappedListener = getWrappedComponentsListener(vm, listener);
1596
+ addEventListener(elm, type, wrappedListener, options);
1597
+ },
1598
+ removeEventListener(type, listener, options) {
1599
+ const vm = getAssociatedVM(this);
1600
+ const { elm, renderer: { removeEventListener }, } = vm;
1601
+ const wrappedListener = getWrappedComponentsListener(vm, listener);
1602
+ removeEventListener(elm, type, wrappedListener, options);
1603
+ },
1604
+ hasAttribute(name) {
1605
+ const vm = getAssociatedVM(this);
1606
+ const { elm, renderer: { getAttribute }, } = vm;
1607
+ return !isNull(getAttribute(elm, name));
1608
+ },
1609
+ hasAttributeNS(namespace, name) {
1610
+ const vm = getAssociatedVM(this);
1611
+ const { elm, renderer: { getAttribute }, } = vm;
1612
+ return !isNull(getAttribute(elm, name, namespace));
1613
+ },
1614
+ removeAttribute(name) {
1615
+ const vm = getAssociatedVM(this);
1616
+ const { elm, renderer: { removeAttribute }, } = vm;
1617
+ unlockAttribute(elm, name);
1618
+ removeAttribute(elm, name);
1619
+ lockAttribute();
1620
+ },
1621
+ removeAttributeNS(namespace, name) {
1622
+ const { elm, renderer: { removeAttribute }, } = getAssociatedVM(this);
1623
+ unlockAttribute(elm, name);
1624
+ removeAttribute(elm, name, namespace);
1625
+ lockAttribute();
1626
+ },
1627
+ getAttribute(name) {
1628
+ const vm = getAssociatedVM(this);
1629
+ const { elm } = vm;
1630
+ const { getAttribute } = vm.renderer;
1631
+ return getAttribute(elm, name);
1632
+ },
1633
+ getAttributeNS(namespace, name) {
1634
+ const vm = getAssociatedVM(this);
1635
+ const { elm } = vm;
1636
+ const { getAttribute } = vm.renderer;
1637
+ return getAttribute(elm, name, namespace);
1638
+ },
1639
+ setAttribute(name, value) {
1640
+ const vm = getAssociatedVM(this);
1641
+ const { elm, renderer: { setAttribute }, } = vm;
1642
+ if (process.env.NODE_ENV !== 'production') {
1643
+ assert.isFalse(isBeingConstructed(vm), `Failed to construct '${getComponentTag(vm)}': The result must not have attributes.`);
1644
+ }
1645
+ unlockAttribute(elm, name);
1646
+ setAttribute(elm, name, value);
1647
+ lockAttribute();
1648
+ },
1649
+ setAttributeNS(namespace, name, value) {
1650
+ const vm = getAssociatedVM(this);
1651
+ const { elm, renderer: { setAttribute }, } = vm;
1652
+ if (process.env.NODE_ENV !== 'production') {
1653
+ assert.isFalse(isBeingConstructed(vm), `Failed to construct '${getComponentTag(vm)}': The result must not have attributes.`);
1654
+ }
1655
+ unlockAttribute(elm, name);
1656
+ setAttribute(elm, name, value, namespace);
1657
+ lockAttribute();
1658
+ },
1659
+ getBoundingClientRect() {
1660
+ const vm = getAssociatedVM(this);
1661
+ const { elm, renderer: { getBoundingClientRect }, } = vm;
1662
+ if (process.env.NODE_ENV !== 'production') {
1663
+ warnIfInvokedDuringConstruction(vm, 'getBoundingClientRect()');
1664
+ }
1665
+ return getBoundingClientRect(elm);
1666
+ },
1667
+ get isConnected() {
1668
+ const vm = getAssociatedVM(this);
1669
+ const { elm, renderer: { isConnected }, } = vm;
1670
+ return isConnected(elm);
1671
+ },
1672
+ get classList() {
1673
+ const vm = getAssociatedVM(this);
1674
+ const { elm, renderer: { getClassList }, } = vm;
1675
+ if (process.env.NODE_ENV !== 'production') {
1676
+ // TODO [#1290]: this still fails in dev but works in production, eventually, we should
1677
+ // just throw in all modes
1678
+ assert.isFalse(isBeingConstructed(vm), `Failed to construct ${vm}: The result must not have attributes. Adding or tampering with classname in constructor is not allowed in a web component, use connectedCallback() instead.`);
1679
+ }
1680
+ return getClassList(elm);
1681
+ },
1682
+ get template() {
1683
+ const vm = getAssociatedVM(this);
1684
+ if (process.env.NODE_ENV !== 'production') {
1685
+ if (vm.renderMode === 0 /* RenderMode.Light */) {
1686
+ logError('`this.template` returns null for light DOM components. Since there is no shadow, the rendered content can be accessed via `this` itself. e.g. instead of `this.template.querySelector`, use `this.querySelector`.');
1687
+ }
1688
+ }
1689
+ return vm.shadowRoot;
1690
+ },
1691
+ get refs() {
1692
+ const vm = getAssociatedVM(this);
1693
+ if (isUpdatingTemplate) {
1694
+ if (process.env.NODE_ENV !== 'production') {
1695
+ logError(`this.refs should not be called while ${getComponentTag(vm)} is rendering. Use this.refs only when the DOM is stable, e.g. in renderedCallback().`);
1696
+ }
1697
+ // If the template is in the process of being updated, then we don't want to go through the normal
1698
+ // process of returning the refs and caching them, because the state of the refs is unstable.
1699
+ // This can happen if e.g. a template contains `<div class={foo}></div>` and `foo` is computed
1700
+ // based on `this.refs.bar`.
1701
+ return;
1702
+ }
1703
+ if (process.env.NODE_ENV !== 'production') {
1704
+ warnIfInvokedDuringConstruction(vm, 'refs');
1705
+ }
1706
+ const { refVNodes, cmpTemplate } = vm;
1707
+ // If the `cmpTemplate` is null, that means that the template has not been rendered yet. Most likely this occurs
1708
+ // if `this.refs` is called during the `connectedCallback` phase. The DOM elements have not been rendered yet,
1709
+ // so log a warning. Note we also check `isBeingConstructed()` to avoid a double warning (due to
1710
+ // `warnIfInvokedDuringConstruction` above).
1711
+ if (process.env.NODE_ENV !== 'production' &&
1712
+ isNull(cmpTemplate) &&
1713
+ !isBeingConstructed(vm)) {
1714
+ logError(`this.refs is undefined for ${getComponentTag(vm)}. This is either because the attached template has no "lwc:ref" directive, or this.refs was ` +
1715
+ `invoked before renderedCallback(). Use this.refs only when the referenced HTML elements have ` +
1716
+ `been rendered to the DOM, such as within renderedCallback() or disconnectedCallback().`);
1717
+ }
1718
+ // For backwards compatibility with component written before template refs
1719
+ // were introduced, we return undefined if the template has no refs defined
1720
+ // anywhere. This fixes components that may want to add an expando called `refs`
1721
+ // and are checking if it exists with `if (this.refs)` before adding it.
1722
+ // Note we use a null refVNodes to indicate that the template has no refs defined.
1723
+ if (isNull(refVNodes)) {
1724
+ return;
1725
+ }
1726
+ // The refNodes can be cached based on the refVNodes, since the refVNodes
1727
+ // are recreated from scratch every time the template is rendered.
1728
+ // This happens with `vm.refVNodes = null` in `template.ts` in `@lwc/engine-core`.
1729
+ let refs = refsCache.get(refVNodes);
1730
+ if (isUndefined$1(refs)) {
1731
+ refs = create(null);
1732
+ for (const key of keys(refVNodes)) {
1733
+ refs[key] = refVNodes[key].elm;
1734
+ }
1735
+ freeze(refs);
1736
+ refsCache.set(refVNodes, refs);
1737
+ }
1738
+ return refs;
1739
+ },
1740
+ // For backwards compat, we allow component authors to set `refs` as an expando
1741
+ set refs(value) {
1742
+ defineProperty(this, 'refs', {
1743
+ configurable: true,
1744
+ enumerable: true,
1745
+ writable: true,
1746
+ value,
1747
+ });
1748
+ },
1749
+ get shadowRoot() {
1750
+ // From within the component instance, the shadowRoot is always reported as "closed".
1751
+ // Authors should rely on this.template instead.
1752
+ return null;
1753
+ },
1754
+ get children() {
1755
+ const vm = getAssociatedVM(this);
1756
+ const renderer = vm.renderer;
1757
+ if (process.env.NODE_ENV !== 'production') {
1758
+ warnIfInvokedDuringConstruction(vm, 'children');
1759
+ }
1760
+ return renderer.getChildren(vm.elm);
1761
+ },
1762
+ get childNodes() {
1763
+ const vm = getAssociatedVM(this);
1764
+ const renderer = vm.renderer;
1765
+ if (process.env.NODE_ENV !== 'production') {
1766
+ warnIfInvokedDuringConstruction(vm, 'childNodes');
1767
+ }
1768
+ return renderer.getChildNodes(vm.elm);
1769
+ },
1770
+ get firstChild() {
1771
+ const vm = getAssociatedVM(this);
1772
+ const renderer = vm.renderer;
1773
+ if (process.env.NODE_ENV !== 'production') {
1774
+ warnIfInvokedDuringConstruction(vm, 'firstChild');
1775
+ }
1776
+ return renderer.getFirstChild(vm.elm);
1777
+ },
1778
+ get firstElementChild() {
1779
+ const vm = getAssociatedVM(this);
1780
+ const renderer = vm.renderer;
1781
+ if (process.env.NODE_ENV !== 'production') {
1782
+ warnIfInvokedDuringConstruction(vm, 'firstElementChild');
1783
+ }
1784
+ return renderer.getFirstElementChild(vm.elm);
1785
+ },
1786
+ get lastChild() {
1787
+ const vm = getAssociatedVM(this);
1788
+ const renderer = vm.renderer;
1789
+ if (process.env.NODE_ENV !== 'production') {
1790
+ warnIfInvokedDuringConstruction(vm, 'lastChild');
1791
+ }
1792
+ return renderer.getLastChild(vm.elm);
1793
+ },
1794
+ get lastElementChild() {
1795
+ const vm = getAssociatedVM(this);
1796
+ const renderer = vm.renderer;
1797
+ if (process.env.NODE_ENV !== 'production') {
1798
+ warnIfInvokedDuringConstruction(vm, 'lastElementChild');
1799
+ }
1800
+ return renderer.getLastElementChild(vm.elm);
1801
+ },
1802
+ render() {
1803
+ const vm = getAssociatedVM(this);
1804
+ return vm.def.template;
1805
+ },
1806
+ toString() {
1807
+ const vm = getAssociatedVM(this);
1808
+ return `[object ${vm.def.name}]`;
1809
+ },
1925
1810
  };
1926
1811
  const queryAndChildGetterDescriptors = create(null);
1927
- const queryMethods = ['getElementsByClassName', 'getElementsByTagName', 'querySelector', 'querySelectorAll'];
1812
+ const queryMethods = [
1813
+ 'getElementsByClassName',
1814
+ 'getElementsByTagName',
1815
+ 'querySelector',
1816
+ 'querySelectorAll',
1817
+ ];
1928
1818
  // Generic passthrough for query APIs on HTMLElement to the relevant Renderer APIs
1929
1819
  for (const queryMethod of queryMethods) {
1930
- queryAndChildGetterDescriptors[queryMethod] = {
1931
- value(arg) {
1932
- const vm = getAssociatedVM(this);
1933
- const {
1934
- elm,
1935
- renderer
1936
- } = vm;
1937
- if (process.env.NODE_ENV !== 'production') {
1938
- warnIfInvokedDuringConstruction(vm, `${queryMethod}()`);
1939
- }
1940
- return renderer[queryMethod](elm, arg);
1941
- },
1942
- configurable: true,
1943
- enumerable: true,
1944
- writable: true
1945
- };
1820
+ queryAndChildGetterDescriptors[queryMethod] = {
1821
+ value(arg) {
1822
+ const vm = getAssociatedVM(this);
1823
+ const { elm, renderer } = vm;
1824
+ if (process.env.NODE_ENV !== 'production') {
1825
+ warnIfInvokedDuringConstruction(vm, `${queryMethod}()`);
1826
+ }
1827
+ return renderer[queryMethod](elm, arg);
1828
+ },
1829
+ configurable: true,
1830
+ enumerable: true,
1831
+ writable: true,
1832
+ };
1946
1833
  }
1947
1834
  defineProperties(LightningElement.prototype, queryAndChildGetterDescriptors);
1948
1835
  const lightningBasedDescriptors = create(null);
1949
1836
  for (const propName in HTMLElementOriginalDescriptors) {
1950
- lightningBasedDescriptors[propName] = createBridgeToElementDescriptor(propName, HTMLElementOriginalDescriptors[propName]);
1837
+ lightningBasedDescriptors[propName] = createBridgeToElementDescriptor(propName, HTMLElementOriginalDescriptors[propName]);
1951
1838
  }
1952
1839
  defineProperties(LightningElement.prototype, lightningBasedDescriptors);
1953
1840
  function applyAriaReflectionToLightningElement() {
1954
- // If ARIA reflection is not applied globally to Element.prototype, or if we are running server-side,
1955
- // apply it to LightningElement.prototype.
1956
- // This allows `this.aria*` property accessors to work from inside a component, and to reflect `aria-*` attrs.
1957
- applyAriaReflection(LightningElement.prototype);
1958
- }
1959
- // The reason for this odd if/else branching is limitations in @lwc/features:
1960
- // https://github.com/salesforce/lwc/blob/master/packages/%40lwc/features/README.md#only-works-with-if-statements
1961
- if (lwcRuntimeFlags.DISABLE_ARIA_REFLECTION_POLYFILL) {
1962
- applyAriaReflectionToLightningElement();
1963
- } else if (!process.env.IS_BROWSER) {
1964
- applyAriaReflectionToLightningElement();
1841
+ // If ARIA reflection is not applied globally to Element.prototype, or if we are running server-side,
1842
+ // apply it to LightningElement.prototype.
1843
+ // This allows `this.aria*` property accessors to work from inside a component, and to reflect `aria-*` attrs.
1844
+ applyAriaReflection(LightningElement.prototype);
1845
+ }
1846
+ if (!process.env.IS_BROWSER || lwcRuntimeFlags.DISABLE_ARIA_REFLECTION_POLYFILL) {
1847
+ applyAriaReflectionToLightningElement();
1965
1848
  }
1966
1849
  defineProperty(LightningElement, 'CustomElementConstructor', {
1967
- get() {
1968
- // If required, a runtime-specific implementation must be defined.
1969
- throw new ReferenceError('The current runtime does not support CustomElementConstructor.');
1970
- },
1971
- configurable: true
1850
+ get() {
1851
+ // If required, a runtime-specific implementation must be defined.
1852
+ throw new ReferenceError('The current runtime does not support CustomElementConstructor.');
1853
+ },
1854
+ configurable: true,
1972
1855
  });
1973
1856
  if (process.env.NODE_ENV !== 'production') {
1974
- patchLightningElementPrototypeWithRestrictions(LightningElement.prototype);
1857
+ patchLightningElementPrototypeWithRestrictions(LightningElement.prototype);
1975
1858
  }
1976
1859
 
1977
1860
  function createObservedFieldPropertyDescriptor(key) {
@@ -2001,281 +1884,247 @@ const DeprecatedWiredParamsMeta = '$$DeprecatedWiredParamsMetaKey$$';
2001
1884
  const WIRE_DEBUG_ENTRY = '@wire';
2002
1885
  const WireMetaMap = new Map();
2003
1886
  class WireContextRegistrationEvent extends CustomEvent {
2004
- constructor(adapterToken, {
2005
- setNewContext,
2006
- setDisconnectedCallback
2007
- }) {
2008
- super(adapterToken, {
2009
- bubbles: true,
2010
- composed: true
2011
- });
2012
- defineProperties(this, {
2013
- setNewContext: {
2014
- value: setNewContext
2015
- },
2016
- setDisconnectedCallback: {
2017
- value: setDisconnectedCallback
2018
- }
2019
- });
2020
- }
1887
+ constructor(adapterToken, { setNewContext, setDisconnectedCallback }) {
1888
+ super(adapterToken, {
1889
+ bubbles: true,
1890
+ composed: true,
1891
+ });
1892
+ defineProperties(this, {
1893
+ setNewContext: {
1894
+ value: setNewContext,
1895
+ },
1896
+ setDisconnectedCallback: {
1897
+ value: setDisconnectedCallback,
1898
+ },
1899
+ });
1900
+ }
2021
1901
  }
2022
1902
  function createFieldDataCallback(vm, name) {
2023
- return value => {
2024
- updateComponentValue(vm, name, value);
2025
- };
1903
+ return (value) => {
1904
+ updateComponentValue(vm, name, value);
1905
+ };
2026
1906
  }
2027
1907
  function createMethodDataCallback(vm, method) {
2028
- return value => {
2029
- // dispatching new value into the wired method
2030
- runWithBoundaryProtection(vm, vm.owner, noop, () => {
2031
- // job
2032
- method.call(vm.component, value);
2033
- }, noop);
2034
- };
1908
+ return (value) => {
1909
+ // dispatching new value into the wired method
1910
+ runWithBoundaryProtection(vm, vm.owner, noop, () => {
1911
+ // job
1912
+ method.call(vm.component, value);
1913
+ }, noop);
1914
+ };
2035
1915
  }
2036
1916
  function createConfigWatcher(component, configCallback, callbackWhenConfigIsReady) {
2037
- let hasPendingConfig = false;
2038
- // creating the reactive observer for reactive params when needed
2039
- const ro = createReactiveObserver(() => {
2040
- if (hasPendingConfig === false) {
2041
- hasPendingConfig = true;
2042
- // collect new config in the micro-task
2043
- Promise.resolve().then(() => {
2044
- hasPendingConfig = false;
2045
- // resetting current reactive params
2046
- ro.reset();
2047
- // dispatching a new config due to a change in the configuration
2048
- computeConfigAndUpdate();
2049
- });
2050
- }
2051
- });
2052
- const computeConfigAndUpdate = () => {
2053
- let config;
2054
- ro.observe(() => config = configCallback(component));
2055
- // eslint-disable-next-line @lwc/lwc-internal/no-invalid-todo
2056
- // TODO: dev-mode validation of config based on the adapter.configSchema
2057
- // @ts-ignore it is assigned in the observe() callback
2058
- callbackWhenConfigIsReady(config);
2059
- };
2060
- return {
2061
- computeConfigAndUpdate,
2062
- ro
2063
- };
1917
+ let hasPendingConfig = false;
1918
+ // creating the reactive observer for reactive params when needed
1919
+ const ro = createReactiveObserver(() => {
1920
+ if (hasPendingConfig === false) {
1921
+ hasPendingConfig = true;
1922
+ // collect new config in the micro-task
1923
+ Promise.resolve().then(() => {
1924
+ hasPendingConfig = false;
1925
+ // resetting current reactive params
1926
+ ro.reset();
1927
+ // dispatching a new config due to a change in the configuration
1928
+ computeConfigAndUpdate();
1929
+ });
1930
+ }
1931
+ });
1932
+ const computeConfigAndUpdate = () => {
1933
+ let config;
1934
+ ro.observe(() => (config = configCallback(component)));
1935
+ // eslint-disable-next-line @lwc/lwc-internal/no-invalid-todo
1936
+ // TODO: dev-mode validation of config based on the adapter.configSchema
1937
+ // @ts-ignore it is assigned in the observe() callback
1938
+ callbackWhenConfigIsReady(config);
1939
+ };
1940
+ return {
1941
+ computeConfigAndUpdate,
1942
+ ro,
1943
+ };
2064
1944
  }
2065
1945
  function createContextWatcher(vm, wireDef, callbackWhenContextIsReady) {
2066
- const {
2067
- adapter
2068
- } = wireDef;
2069
- const adapterContextToken = getAdapterToken(adapter);
2070
- if (isUndefined$1(adapterContextToken)) {
2071
- return; // no provider found, nothing to be done
2072
- }
2073
-
2074
- const {
2075
- elm,
2076
- context: {
2077
- wiredConnecting,
2078
- wiredDisconnecting
2079
- },
2080
- renderer: {
2081
- dispatchEvent
2082
- }
2083
- } = vm;
2084
- // waiting for the component to be connected to formally request the context via the token
2085
- ArrayPush$1.call(wiredConnecting, () => {
2086
- // This event is responsible for connecting the host element with another
2087
- // element in the composed path that is providing contextual data. The provider
2088
- // must be listening for a special dom event with the name corresponding to the value of
2089
- // `adapterContextToken`, which will remain secret and internal to this file only to
2090
- // guarantee that the linkage can be forged.
2091
- const contextRegistrationEvent = new WireContextRegistrationEvent(adapterContextToken, {
2092
- setNewContext(newContext) {
2093
- // eslint-disable-next-line @lwc/lwc-internal/no-invalid-todo
2094
- // TODO: dev-mode validation of config based on the adapter.contextSchema
2095
- callbackWhenContextIsReady(newContext);
2096
- },
2097
- setDisconnectedCallback(disconnectCallback) {
2098
- // adds this callback into the disconnect bucket so it gets disconnected from parent
2099
- // the the element hosting the wire is disconnected
2100
- ArrayPush$1.call(wiredDisconnecting, disconnectCallback);
2101
- }
1946
+ const { adapter } = wireDef;
1947
+ const adapterContextToken = getAdapterToken(adapter);
1948
+ if (isUndefined$1(adapterContextToken)) {
1949
+ return; // no provider found, nothing to be done
1950
+ }
1951
+ const { elm, context: { wiredConnecting, wiredDisconnecting }, renderer: { dispatchEvent }, } = vm;
1952
+ // waiting for the component to be connected to formally request the context via the token
1953
+ ArrayPush$1.call(wiredConnecting, () => {
1954
+ // This event is responsible for connecting the host element with another
1955
+ // element in the composed path that is providing contextual data. The provider
1956
+ // must be listening for a special dom event with the name corresponding to the value of
1957
+ // `adapterContextToken`, which will remain secret and internal to this file only to
1958
+ // guarantee that the linkage can be forged.
1959
+ const contextRegistrationEvent = new WireContextRegistrationEvent(adapterContextToken, {
1960
+ setNewContext(newContext) {
1961
+ // eslint-disable-next-line @lwc/lwc-internal/no-invalid-todo
1962
+ // TODO: dev-mode validation of config based on the adapter.contextSchema
1963
+ callbackWhenContextIsReady(newContext);
1964
+ },
1965
+ setDisconnectedCallback(disconnectCallback) {
1966
+ // adds this callback into the disconnect bucket so it gets disconnected from parent
1967
+ // the the element hosting the wire is disconnected
1968
+ ArrayPush$1.call(wiredDisconnecting, disconnectCallback);
1969
+ },
1970
+ });
1971
+ dispatchEvent(elm, contextRegistrationEvent);
2102
1972
  });
2103
- dispatchEvent(elm, contextRegistrationEvent);
2104
- });
2105
1973
  }
2106
1974
  function createConnector(vm, name, wireDef) {
2107
- const {
2108
- method,
2109
- adapter,
2110
- configCallback,
2111
- dynamic
2112
- } = wireDef;
2113
- let debugInfo;
2114
- if (process.env.NODE_ENV !== 'production') {
2115
- const wiredPropOrMethod = isUndefined$1(method) ? name : method.name;
2116
- debugInfo = create(null);
2117
- debugInfo.wasDataProvisionedForConfig = false;
2118
- vm.debugInfo[WIRE_DEBUG_ENTRY][wiredPropOrMethod] = debugInfo;
2119
- }
2120
- const fieldOrMethodCallback = isUndefined$1(method) ? createFieldDataCallback(vm, name) : createMethodDataCallback(vm, method);
2121
- const dataCallback = value => {
1975
+ const { method, adapter, configCallback, dynamic } = wireDef;
1976
+ let debugInfo;
2122
1977
  if (process.env.NODE_ENV !== 'production') {
2123
- debugInfo.data = value;
2124
- // Note: most of the time, the data provided is for the current config, but there may be
2125
- // some conditions in which it does not, ex:
2126
- // race conditions in a poor network while the adapter does not cancel a previous request.
2127
- debugInfo.wasDataProvisionedForConfig = true;
2128
- }
2129
- fieldOrMethodCallback(value);
2130
- };
2131
- let context;
2132
- let connector;
2133
- // Workaround to pass the component element associated to this wire adapter instance.
2134
- defineProperty(dataCallback, DeprecatedWiredElementHost, {
2135
- value: vm.elm
2136
- });
2137
- defineProperty(dataCallback, DeprecatedWiredParamsMeta, {
2138
- value: dynamic
2139
- });
2140
- runWithBoundaryProtection(vm, vm, noop, () => {
2141
- // job
2142
- connector = new adapter(dataCallback);
2143
- }, noop);
2144
- const updateConnectorConfig = config => {
2145
- // every time the config is recomputed due to tracking,
2146
- // this callback will be invoked with the new computed config
2147
- runWithBoundaryProtection(vm, vm, noop, () => {
2148
- // job
2149
- if (process.env.NODE_ENV !== 'production') {
2150
- debugInfo.config = config;
2151
- debugInfo.context = context;
1978
+ const wiredPropOrMethod = isUndefined$1(method) ? name : method.name;
1979
+ debugInfo = create(null);
2152
1980
  debugInfo.wasDataProvisionedForConfig = false;
2153
- }
2154
- connector.update(config, context);
2155
- }, noop);
2156
- };
2157
- // Computes the current wire config and calls the update method on the wire adapter.
2158
- // If it has params, we will need to observe changes in the next tick.
2159
- const {
2160
- computeConfigAndUpdate,
2161
- ro
2162
- } = createConfigWatcher(vm.component, configCallback, updateConnectorConfig);
2163
- // if the adapter needs contextualization, we need to watch for new context and push it alongside the config
2164
- if (!isUndefined$1(adapter.contextSchema)) {
2165
- createContextWatcher(vm, wireDef, newContext => {
2166
- // every time the context is pushed into this component,
2167
- // this callback will be invoked with the new computed context
2168
- if (context !== newContext) {
2169
- context = newContext;
2170
- // Note: when new context arrives, the config will be recomputed and pushed along side the new
2171
- // context, this is to preserve the identity characteristics, config should not have identity
2172
- // (ever), while context can have identity
2173
- if (vm.state === 1 /* VMState.connected */) {
2174
- computeConfigAndUpdate();
2175
- }
2176
- }
1981
+ vm.debugInfo[WIRE_DEBUG_ENTRY][wiredPropOrMethod] = debugInfo;
1982
+ }
1983
+ const fieldOrMethodCallback = isUndefined$1(method)
1984
+ ? createFieldDataCallback(vm, name)
1985
+ : createMethodDataCallback(vm, method);
1986
+ const dataCallback = (value) => {
1987
+ if (process.env.NODE_ENV !== 'production') {
1988
+ debugInfo.data = value;
1989
+ // Note: most of the time, the data provided is for the current config, but there may be
1990
+ // some conditions in which it does not, ex:
1991
+ // race conditions in a poor network while the adapter does not cancel a previous request.
1992
+ debugInfo.wasDataProvisionedForConfig = true;
1993
+ }
1994
+ fieldOrMethodCallback(value);
1995
+ };
1996
+ let context;
1997
+ let connector;
1998
+ // Workaround to pass the component element associated to this wire adapter instance.
1999
+ defineProperty(dataCallback, DeprecatedWiredElementHost, {
2000
+ value: vm.elm,
2177
2001
  });
2178
- }
2179
- return {
2180
- // @ts-ignore the boundary protection executes sync, connector is always defined
2181
- connector,
2182
- computeConfigAndUpdate,
2183
- resetConfigWatcher: () => ro.reset()
2184
- };
2002
+ defineProperty(dataCallback, DeprecatedWiredParamsMeta, {
2003
+ value: dynamic,
2004
+ });
2005
+ runWithBoundaryProtection(vm, vm, noop, () => {
2006
+ // job
2007
+ connector = new adapter(dataCallback);
2008
+ }, noop);
2009
+ const updateConnectorConfig = (config) => {
2010
+ // every time the config is recomputed due to tracking,
2011
+ // this callback will be invoked with the new computed config
2012
+ runWithBoundaryProtection(vm, vm, noop, () => {
2013
+ // job
2014
+ if (process.env.NODE_ENV !== 'production') {
2015
+ debugInfo.config = config;
2016
+ debugInfo.context = context;
2017
+ debugInfo.wasDataProvisionedForConfig = false;
2018
+ }
2019
+ connector.update(config, context);
2020
+ }, noop);
2021
+ };
2022
+ // Computes the current wire config and calls the update method on the wire adapter.
2023
+ // If it has params, we will need to observe changes in the next tick.
2024
+ const { computeConfigAndUpdate, ro } = createConfigWatcher(vm.component, configCallback, updateConnectorConfig);
2025
+ // if the adapter needs contextualization, we need to watch for new context and push it alongside the config
2026
+ if (!isUndefined$1(adapter.contextSchema)) {
2027
+ createContextWatcher(vm, wireDef, (newContext) => {
2028
+ // every time the context is pushed into this component,
2029
+ // this callback will be invoked with the new computed context
2030
+ if (context !== newContext) {
2031
+ context = newContext;
2032
+ // Note: when new context arrives, the config will be recomputed and pushed along side the new
2033
+ // context, this is to preserve the identity characteristics, config should not have identity
2034
+ // (ever), while context can have identity
2035
+ if (vm.state === 1 /* VMState.connected */) {
2036
+ computeConfigAndUpdate();
2037
+ }
2038
+ }
2039
+ });
2040
+ }
2041
+ return {
2042
+ // @ts-ignore the boundary protection executes sync, connector is always defined
2043
+ connector,
2044
+ computeConfigAndUpdate,
2045
+ resetConfigWatcher: () => ro.reset(),
2046
+ };
2185
2047
  }
2186
2048
  const AdapterToTokenMap = new Map();
2187
2049
  function getAdapterToken(adapter) {
2188
- return AdapterToTokenMap.get(adapter);
2050
+ return AdapterToTokenMap.get(adapter);
2189
2051
  }
2190
2052
  function setAdapterToken(adapter, token) {
2191
- AdapterToTokenMap.set(adapter, token);
2053
+ AdapterToTokenMap.set(adapter, token);
2192
2054
  }
2193
2055
  function storeWiredMethodMeta(descriptor, adapter, configCallback, dynamic) {
2194
- // support for callable adapters
2195
- if (adapter.adapter) {
2196
- adapter = adapter.adapter;
2197
- }
2198
- const method = descriptor.value;
2199
- const def = {
2200
- adapter,
2201
- method,
2202
- configCallback,
2203
- dynamic
2204
- };
2205
- WireMetaMap.set(descriptor, def);
2056
+ // support for callable adapters
2057
+ if (adapter.adapter) {
2058
+ adapter = adapter.adapter;
2059
+ }
2060
+ const method = descriptor.value;
2061
+ const def = {
2062
+ adapter,
2063
+ method,
2064
+ configCallback,
2065
+ dynamic,
2066
+ };
2067
+ WireMetaMap.set(descriptor, def);
2206
2068
  }
2207
2069
  function storeWiredFieldMeta(descriptor, adapter, configCallback, dynamic) {
2208
- // support for callable adapters
2209
- if (adapter.adapter) {
2210
- adapter = adapter.adapter;
2211
- }
2212
- const def = {
2213
- adapter,
2214
- configCallback,
2215
- dynamic
2216
- };
2217
- WireMetaMap.set(descriptor, def);
2070
+ // support for callable adapters
2071
+ if (adapter.adapter) {
2072
+ adapter = adapter.adapter;
2073
+ }
2074
+ const def = {
2075
+ adapter,
2076
+ configCallback,
2077
+ dynamic,
2078
+ };
2079
+ WireMetaMap.set(descriptor, def);
2218
2080
  }
2219
2081
  function installWireAdapters(vm) {
2220
- const {
2221
- context,
2222
- def: {
2223
- wire
2224
- }
2225
- } = vm;
2226
- if (process.env.NODE_ENV !== 'production') {
2227
- vm.debugInfo[WIRE_DEBUG_ENTRY] = create(null);
2228
- }
2229
- const wiredConnecting = context.wiredConnecting = [];
2230
- const wiredDisconnecting = context.wiredDisconnecting = [];
2231
- for (const fieldNameOrMethod in wire) {
2232
- const descriptor = wire[fieldNameOrMethod];
2233
- const wireDef = WireMetaMap.get(descriptor);
2082
+ const { context, def: { wire }, } = vm;
2234
2083
  if (process.env.NODE_ENV !== 'production') {
2235
- assert.invariant(wireDef, `Internal Error: invalid wire definition found.`);
2084
+ vm.debugInfo[WIRE_DEBUG_ENTRY] = create(null);
2236
2085
  }
2237
- if (!isUndefined$1(wireDef)) {
2238
- const {
2239
- connector,
2240
- computeConfigAndUpdate,
2241
- resetConfigWatcher
2242
- } = createConnector(vm, fieldNameOrMethod, wireDef);
2243
- const hasDynamicParams = wireDef.dynamic.length > 0;
2244
- ArrayPush$1.call(wiredConnecting, () => {
2245
- connector.connect();
2246
- if (!lwcRuntimeFlags.ENABLE_WIRE_SYNC_EMIT) {
2247
- if (hasDynamicParams) {
2248
- Promise.resolve().then(computeConfigAndUpdate);
2249
- return;
2250
- }
2086
+ const wiredConnecting = (context.wiredConnecting = []);
2087
+ const wiredDisconnecting = (context.wiredDisconnecting = []);
2088
+ for (const fieldNameOrMethod in wire) {
2089
+ const descriptor = wire[fieldNameOrMethod];
2090
+ const wireDef = WireMetaMap.get(descriptor);
2091
+ if (process.env.NODE_ENV !== 'production') {
2092
+ assert.invariant(wireDef, `Internal Error: invalid wire definition found.`);
2093
+ }
2094
+ if (!isUndefined$1(wireDef)) {
2095
+ const { connector, computeConfigAndUpdate, resetConfigWatcher } = createConnector(vm, fieldNameOrMethod, wireDef);
2096
+ const hasDynamicParams = wireDef.dynamic.length > 0;
2097
+ ArrayPush$1.call(wiredConnecting, () => {
2098
+ connector.connect();
2099
+ if (!lwcRuntimeFlags.ENABLE_WIRE_SYNC_EMIT) {
2100
+ if (hasDynamicParams) {
2101
+ Promise.resolve().then(computeConfigAndUpdate);
2102
+ return;
2103
+ }
2104
+ }
2105
+ computeConfigAndUpdate();
2106
+ });
2107
+ ArrayPush$1.call(wiredDisconnecting, () => {
2108
+ connector.disconnect();
2109
+ resetConfigWatcher();
2110
+ });
2251
2111
  }
2252
- computeConfigAndUpdate();
2253
- });
2254
- ArrayPush$1.call(wiredDisconnecting, () => {
2255
- connector.disconnect();
2256
- resetConfigWatcher();
2257
- });
2258
2112
  }
2259
- }
2260
2113
  }
2261
2114
  function connectWireAdapters(vm) {
2262
- const {
2263
- wiredConnecting
2264
- } = vm.context;
2265
- for (let i = 0, len = wiredConnecting.length; i < len; i += 1) {
2266
- wiredConnecting[i]();
2267
- }
2115
+ const { wiredConnecting } = vm.context;
2116
+ for (let i = 0, len = wiredConnecting.length; i < len; i += 1) {
2117
+ wiredConnecting[i]();
2118
+ }
2268
2119
  }
2269
2120
  function disconnectWireAdapters(vm) {
2270
- const {
2271
- wiredDisconnecting
2272
- } = vm.context;
2273
- runWithBoundaryProtection(vm, vm, noop, () => {
2274
- // job
2275
- for (let i = 0, len = wiredDisconnecting.length; i < len; i += 1) {
2276
- wiredDisconnecting[i]();
2277
- }
2278
- }, noop);
2121
+ const { wiredDisconnecting } = vm.context;
2122
+ runWithBoundaryProtection(vm, vm, noop, () => {
2123
+ // job
2124
+ for (let i = 0, len = wiredDisconnecting.length; i < len; i += 1) {
2125
+ wiredDisconnecting[i]();
2126
+ }
2127
+ }, noop);
2279
2128
  }
2280
2129
 
2281
2130
  /*
@@ -2723,160 +2572,151 @@ function sanitizeAttribute(tagName, namespaceUri, attrName, attrValue) {
2723
2572
  const cachedGetterByKey = create(null);
2724
2573
  const cachedSetterByKey = create(null);
2725
2574
  function createGetter(key) {
2726
- let fn = cachedGetterByKey[key];
2727
- if (isUndefined$1(fn)) {
2728
- fn = cachedGetterByKey[key] = function () {
2729
- const vm = getAssociatedVM(this);
2730
- const {
2731
- getHook
2732
- } = vm;
2733
- return getHook(vm.component, key);
2734
- };
2735
- }
2736
- return fn;
2575
+ let fn = cachedGetterByKey[key];
2576
+ if (isUndefined$1(fn)) {
2577
+ fn = cachedGetterByKey[key] = function () {
2578
+ const vm = getAssociatedVM(this);
2579
+ const { getHook } = vm;
2580
+ return getHook(vm.component, key);
2581
+ };
2582
+ }
2583
+ return fn;
2737
2584
  }
2738
2585
  function createSetter(key) {
2739
- let fn = cachedSetterByKey[key];
2740
- if (isUndefined$1(fn)) {
2741
- fn = cachedSetterByKey[key] = function (newValue) {
2742
- const vm = getAssociatedVM(this);
2743
- const {
2744
- setHook
2745
- } = vm;
2746
- newValue = getReadOnlyProxy(newValue);
2747
- setHook(vm.component, key, newValue);
2748
- };
2749
- }
2750
- return fn;
2586
+ let fn = cachedSetterByKey[key];
2587
+ if (isUndefined$1(fn)) {
2588
+ fn = cachedSetterByKey[key] = function (newValue) {
2589
+ const vm = getAssociatedVM(this);
2590
+ const { setHook } = vm;
2591
+ newValue = getReadOnlyProxy(newValue);
2592
+ setHook(vm.component, key, newValue);
2593
+ };
2594
+ }
2595
+ return fn;
2751
2596
  }
2752
2597
  function createMethodCaller(methodName) {
2753
- return function () {
2754
- const vm = getAssociatedVM(this);
2755
- const {
2756
- callHook,
2757
- component
2758
- } = vm;
2759
- const fn = component[methodName];
2760
- return callHook(vm.component, fn, ArraySlice.call(arguments));
2761
- };
2598
+ return function () {
2599
+ const vm = getAssociatedVM(this);
2600
+ const { callHook, component } = vm;
2601
+ const fn = component[methodName];
2602
+ return callHook(vm.component, fn, ArraySlice.call(arguments));
2603
+ };
2762
2604
  }
2763
2605
  function createAttributeChangedCallback(attributeToPropMap, superAttributeChangedCallback) {
2764
- return function attributeChangedCallback(attrName, oldValue, newValue) {
2765
- if (oldValue === newValue) {
2766
- // Ignore same values.
2767
- return;
2768
- }
2769
- const propName = attributeToPropMap[attrName];
2770
- if (isUndefined$1(propName)) {
2771
- if (!isUndefined$1(superAttributeChangedCallback)) {
2772
- // delegate unknown attributes to the super.
2773
- // Typescript does not like it when you treat the `arguments` object as an array
2774
- // @ts-ignore type-mismatch
2775
- superAttributeChangedCallback.apply(this, arguments);
2776
- }
2777
- return;
2778
- }
2779
- if (!isAttributeLocked(this, attrName)) {
2780
- // Ignore changes triggered by the engine itself during:
2781
- // * diffing when public props are attempting to reflect to the DOM
2782
- // * component via `this.setAttribute()`, should never update the prop
2783
- // Both cases, the setAttribute call is always wrapped by the unlocking of the
2784
- // attribute to be changed
2785
- return;
2786
- }
2787
- // Reflect attribute change to the corresponding property when changed from outside.
2788
- this[propName] = newValue;
2789
- };
2606
+ return function attributeChangedCallback(attrName, oldValue, newValue) {
2607
+ if (oldValue === newValue) {
2608
+ // Ignore same values.
2609
+ return;
2610
+ }
2611
+ const propName = attributeToPropMap[attrName];
2612
+ if (isUndefined$1(propName)) {
2613
+ if (!isUndefined$1(superAttributeChangedCallback)) {
2614
+ // delegate unknown attributes to the super.
2615
+ // Typescript does not like it when you treat the `arguments` object as an array
2616
+ // @ts-ignore type-mismatch
2617
+ superAttributeChangedCallback.apply(this, arguments);
2618
+ }
2619
+ return;
2620
+ }
2621
+ if (!isAttributeLocked(this, attrName)) {
2622
+ // Ignore changes triggered by the engine itself during:
2623
+ // * diffing when public props are attempting to reflect to the DOM
2624
+ // * component via `this.setAttribute()`, should never update the prop
2625
+ // Both cases, the setAttribute call is always wrapped by the unlocking of the
2626
+ // attribute to be changed
2627
+ return;
2628
+ }
2629
+ // Reflect attribute change to the corresponding property when changed from outside.
2630
+ this[propName] = newValue;
2631
+ };
2790
2632
  }
2791
2633
  function HTMLBridgeElementFactory(SuperClass, props, methods) {
2792
- let HTMLBridgeElement;
2793
- /**
2794
- * Modern browsers will have all Native Constructors as regular Classes
2795
- * and must be instantiated with the new keyword. In older browsers,
2796
- * specifically IE11, those are objects with a prototype property defined,
2797
- * since they are not supposed to be extended or instantiated with the
2798
- * new keyword. This forking logic supports both cases, specifically because
2799
- * wc.ts relies on the construction path of the bridges to create new
2800
- * fully qualifying web components.
2801
- */
2802
- if (isFunction$1(SuperClass)) {
2803
- HTMLBridgeElement = class extends SuperClass {};
2804
- } else {
2805
- HTMLBridgeElement = function () {
2806
- // Bridge classes are not supposed to be instantiated directly in
2807
- // browsers that do not support web components.
2808
- throw new TypeError('Illegal constructor');
2634
+ let HTMLBridgeElement;
2635
+ /**
2636
+ * Modern browsers will have all Native Constructors as regular Classes
2637
+ * and must be instantiated with the new keyword. In older browsers,
2638
+ * specifically IE11, those are objects with a prototype property defined,
2639
+ * since they are not supposed to be extended or instantiated with the
2640
+ * new keyword. This forking logic supports both cases, specifically because
2641
+ * wc.ts relies on the construction path of the bridges to create new
2642
+ * fully qualifying web components.
2643
+ */
2644
+ if (isFunction$1(SuperClass)) {
2645
+ HTMLBridgeElement = class extends SuperClass {
2646
+ };
2647
+ }
2648
+ else {
2649
+ HTMLBridgeElement = function () {
2650
+ // Bridge classes are not supposed to be instantiated directly in
2651
+ // browsers that do not support web components.
2652
+ throw new TypeError('Illegal constructor');
2653
+ };
2654
+ // prototype inheritance dance
2655
+ setPrototypeOf(HTMLBridgeElement, SuperClass);
2656
+ setPrototypeOf(HTMLBridgeElement.prototype, SuperClass.prototype);
2657
+ defineProperty(HTMLBridgeElement.prototype, 'constructor', {
2658
+ writable: true,
2659
+ configurable: true,
2660
+ value: HTMLBridgeElement,
2661
+ });
2662
+ }
2663
+ // generating the hash table for attributes to avoid duplicate fields and facilitate validation
2664
+ // and false positives in case of inheritance.
2665
+ const attributeToPropMap = create(null);
2666
+ const { attributeChangedCallback: superAttributeChangedCallback } = SuperClass.prototype;
2667
+ const { observedAttributes: superObservedAttributes = [] } = SuperClass;
2668
+ const descriptors = create(null);
2669
+ // expose getters and setters for each public props on the new Element Bridge
2670
+ for (let i = 0, len = props.length; i < len; i += 1) {
2671
+ const propName = props[i];
2672
+ attributeToPropMap[htmlPropertyToAttribute(propName)] = propName;
2673
+ descriptors[propName] = {
2674
+ get: createGetter(propName),
2675
+ set: createSetter(propName),
2676
+ enumerable: true,
2677
+ configurable: true,
2678
+ };
2679
+ }
2680
+ // expose public methods as props on the new Element Bridge
2681
+ for (let i = 0, len = methods.length; i < len; i += 1) {
2682
+ const methodName = methods[i];
2683
+ descriptors[methodName] = {
2684
+ value: createMethodCaller(methodName),
2685
+ writable: true,
2686
+ configurable: true,
2687
+ };
2688
+ }
2689
+ // creating a new attributeChangedCallback per bridge because they are bound to the corresponding
2690
+ // map of attributes to props. We do this after all other props and methods to avoid the possibility
2691
+ // of getting overrule by a class declaration in user-land, and we make it non-writable, non-configurable
2692
+ // to preserve this definition.
2693
+ descriptors.attributeChangedCallback = {
2694
+ value: createAttributeChangedCallback(attributeToPropMap, superAttributeChangedCallback),
2809
2695
  };
2810
- // prototype inheritance dance
2811
- setPrototypeOf(HTMLBridgeElement, SuperClass);
2812
- setPrototypeOf(HTMLBridgeElement.prototype, SuperClass.prototype);
2813
- defineProperty(HTMLBridgeElement.prototype, 'constructor', {
2814
- writable: true,
2815
- configurable: true,
2816
- value: HTMLBridgeElement
2696
+ // Specify attributes for which we want to reflect changes back to their corresponding
2697
+ // properties via attributeChangedCallback.
2698
+ defineProperty(HTMLBridgeElement, 'observedAttributes', {
2699
+ get() {
2700
+ return [...superObservedAttributes, ...keys(attributeToPropMap)];
2701
+ },
2817
2702
  });
2818
- }
2819
- // generating the hash table for attributes to avoid duplicate fields and facilitate validation
2820
- // and false positives in case of inheritance.
2821
- const attributeToPropMap = create(null);
2822
- const {
2823
- attributeChangedCallback: superAttributeChangedCallback
2824
- } = SuperClass.prototype;
2825
- const {
2826
- observedAttributes: superObservedAttributes = []
2827
- } = SuperClass;
2828
- const descriptors = create(null);
2829
- // expose getters and setters for each public props on the new Element Bridge
2830
- for (let i = 0, len = props.length; i < len; i += 1) {
2831
- const propName = props[i];
2832
- attributeToPropMap[htmlPropertyToAttribute(propName)] = propName;
2833
- descriptors[propName] = {
2834
- get: createGetter(propName),
2835
- set: createSetter(propName),
2836
- enumerable: true,
2837
- configurable: true
2838
- };
2839
- }
2840
- // expose public methods as props on the new Element Bridge
2841
- for (let i = 0, len = methods.length; i < len; i += 1) {
2842
- const methodName = methods[i];
2843
- descriptors[methodName] = {
2844
- value: createMethodCaller(methodName),
2845
- writable: true,
2846
- configurable: true
2847
- };
2848
- }
2849
- // creating a new attributeChangedCallback per bridge because they are bound to the corresponding
2850
- // map of attributes to props. We do this after all other props and methods to avoid the possibility
2851
- // of getting overrule by a class declaration in user-land, and we make it non-writable, non-configurable
2852
- // to preserve this definition.
2853
- descriptors.attributeChangedCallback = {
2854
- value: createAttributeChangedCallback(attributeToPropMap, superAttributeChangedCallback)
2855
- };
2856
- // Specify attributes for which we want to reflect changes back to their corresponding
2857
- // properties via attributeChangedCallback.
2858
- defineProperty(HTMLBridgeElement, 'observedAttributes', {
2859
- get() {
2860
- return [...superObservedAttributes, ...keys(attributeToPropMap)];
2861
- }
2862
- });
2863
- defineProperties(HTMLBridgeElement.prototype, descriptors);
2864
- return HTMLBridgeElement;
2703
+ defineProperties(HTMLBridgeElement.prototype, descriptors);
2704
+ return HTMLBridgeElement;
2865
2705
  }
2866
2706
  const BaseBridgeElement = HTMLBridgeElementFactory(HTMLElementConstructor, getOwnPropertyNames$1(HTMLElementOriginalDescriptors), []);
2867
2707
  if (process.env.IS_BROWSER) {
2868
- // This ARIA reflection only really makes sense in the browser. On the server, there is no `renderedCallback()`,
2869
- // so you cannot do e.g. `this.template.querySelector('x-child').ariaBusy = 'true'`. So we don't need to expose
2870
- // ARIA props outside the LightningElement
2871
- if (lwcRuntimeFlags.DISABLE_ARIA_REFLECTION_POLYFILL) {
2872
- // If ARIA reflection is not applied globally to Element.prototype, apply it to HTMLBridgeElement.prototype.
2873
- // This allows `elm.aria*` property accessors to work from outside a component, and to reflect `aria-*` attrs.
2874
- // This is especially important because the template compiler compiles aria-* attrs on components to aria* props
2875
- //
2876
- // Also note that we apply this to BaseBridgeElement.prototype to avoid excessively redefining property
2877
- // accessors inside the HTMLBridgeElementFactory.
2878
- applyAriaReflection(BaseBridgeElement.prototype);
2879
- }
2708
+ // This ARIA reflection only really makes sense in the browser. On the server, there is no `renderedCallback()`,
2709
+ // so you cannot do e.g. `this.template.querySelector('x-child').ariaBusy = 'true'`. So we don't need to expose
2710
+ // ARIA props outside the LightningElement
2711
+ if (lwcRuntimeFlags.DISABLE_ARIA_REFLECTION_POLYFILL) {
2712
+ // If ARIA reflection is not applied globally to Element.prototype, apply it to HTMLBridgeElement.prototype.
2713
+ // This allows `elm.aria*` property accessors to work from outside a component, and to reflect `aria-*` attrs.
2714
+ // This is especially important because the template compiler compiles aria-* attrs on components to aria* props
2715
+ //
2716
+ // Also note that we apply this to BaseBridgeElement.prototype to avoid excessively redefining property
2717
+ // accessors inside the HTMLBridgeElementFactory.
2718
+ applyAriaReflection(BaseBridgeElement.prototype);
2719
+ }
2880
2720
  }
2881
2721
  freeze(BaseBridgeElement);
2882
2722
  seal(BaseBridgeElement.prototype);
@@ -3292,157 +3132,137 @@ function getComponentDef(Ctor) {
3292
3132
  * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
3293
3133
  */
3294
3134
  function makeHostToken(token) {
3295
- return `${token}-host`;
3135
+ return `${token}-host`;
3296
3136
  }
3297
3137
  function createInlineStyleVNode(content) {
3298
- return api.h('style', {
3299
- key: 'style',
3300
- attrs: {
3301
- type: 'text/css'
3302
- }
3303
- }, [api.t(content)]);
3138
+ return api.h('style', {
3139
+ key: 'style',
3140
+ attrs: {
3141
+ type: 'text/css',
3142
+ },
3143
+ }, [api.t(content)]);
3304
3144
  }
3305
3145
  function updateStylesheetToken(vm, template) {
3306
- const {
3307
- elm,
3308
- context,
3309
- renderMode,
3310
- shadowMode,
3311
- renderer: {
3312
- getClassList,
3313
- removeAttribute,
3314
- setAttribute
3315
- }
3316
- } = vm;
3317
- const {
3318
- stylesheets: newStylesheets,
3319
- stylesheetToken: newStylesheetToken
3320
- } = template;
3321
- const {
3322
- stylesheets: newVmStylesheets
3323
- } = vm;
3324
- const isSyntheticShadow = renderMode === 1 /* RenderMode.Shadow */ && shadowMode === 1 /* ShadowMode.Synthetic */;
3325
- const {
3326
- hasScopedStyles
3327
- } = context;
3328
- let newToken;
3329
- let newHasTokenInClass;
3330
- let newHasTokenInAttribute;
3331
- // Reset the styling token applied to the host element.
3332
- const {
3333
- stylesheetToken: oldToken,
3334
- hasTokenInClass: oldHasTokenInClass,
3335
- hasTokenInAttribute: oldHasTokenInAttribute
3336
- } = context;
3337
- if (!isUndefined$1(oldToken)) {
3338
- if (oldHasTokenInClass) {
3339
- getClassList(elm).remove(makeHostToken(oldToken));
3340
- }
3341
- if (oldHasTokenInAttribute) {
3342
- removeAttribute(elm, makeHostToken(oldToken));
3343
- }
3344
- }
3345
- // Apply the new template styling token to the host element, if the new template has any
3346
- // associated stylesheets. In the case of light DOM, also ensure there is at least one scoped stylesheet.
3347
- const hasNewStylesheets = hasStyles(newStylesheets);
3348
- const hasNewVmStylesheets = hasStyles(newVmStylesheets);
3349
- if (hasNewStylesheets || hasNewVmStylesheets) {
3350
- newToken = newStylesheetToken;
3351
- }
3352
- // Set the new styling token on the host element
3353
- if (!isUndefined$1(newToken)) {
3354
- if (hasScopedStyles) {
3355
- getClassList(elm).add(makeHostToken(newToken));
3356
- newHasTokenInClass = true;
3357
- }
3358
- if (isSyntheticShadow) {
3359
- setAttribute(elm, makeHostToken(newToken), '');
3360
- newHasTokenInAttribute = true;
3361
- }
3362
- }
3363
- // Update the styling tokens present on the context object.
3364
- context.stylesheetToken = newToken;
3365
- context.hasTokenInClass = newHasTokenInClass;
3366
- context.hasTokenInAttribute = newHasTokenInAttribute;
3146
+ const { elm, context, renderMode, shadowMode, renderer: { getClassList, removeAttribute, setAttribute }, } = vm;
3147
+ const { stylesheets: newStylesheets, stylesheetToken: newStylesheetToken } = template;
3148
+ const { stylesheets: newVmStylesheets } = vm;
3149
+ const isSyntheticShadow = renderMode === 1 /* RenderMode.Shadow */ && shadowMode === 1 /* ShadowMode.Synthetic */;
3150
+ const { hasScopedStyles } = context;
3151
+ let newToken;
3152
+ let newHasTokenInClass;
3153
+ let newHasTokenInAttribute;
3154
+ // Reset the styling token applied to the host element.
3155
+ const { stylesheetToken: oldToken, hasTokenInClass: oldHasTokenInClass, hasTokenInAttribute: oldHasTokenInAttribute, } = context;
3156
+ if (!isUndefined$1(oldToken)) {
3157
+ if (oldHasTokenInClass) {
3158
+ getClassList(elm).remove(makeHostToken(oldToken));
3159
+ }
3160
+ if (oldHasTokenInAttribute) {
3161
+ removeAttribute(elm, makeHostToken(oldToken));
3162
+ }
3163
+ }
3164
+ // Apply the new template styling token to the host element, if the new template has any
3165
+ // associated stylesheets. In the case of light DOM, also ensure there is at least one scoped stylesheet.
3166
+ const hasNewStylesheets = hasStyles(newStylesheets);
3167
+ const hasNewVmStylesheets = hasStyles(newVmStylesheets);
3168
+ if (hasNewStylesheets || hasNewVmStylesheets) {
3169
+ newToken = newStylesheetToken;
3170
+ }
3171
+ // Set the new styling token on the host element
3172
+ if (!isUndefined$1(newToken)) {
3173
+ if (hasScopedStyles) {
3174
+ getClassList(elm).add(makeHostToken(newToken));
3175
+ newHasTokenInClass = true;
3176
+ }
3177
+ if (isSyntheticShadow) {
3178
+ setAttribute(elm, makeHostToken(newToken), '');
3179
+ newHasTokenInAttribute = true;
3180
+ }
3181
+ }
3182
+ // Update the styling tokens present on the context object.
3183
+ context.stylesheetToken = newToken;
3184
+ context.hasTokenInClass = newHasTokenInClass;
3185
+ context.hasTokenInAttribute = newHasTokenInAttribute;
3367
3186
  }
3368
3187
  function evaluateStylesheetsContent(stylesheets, stylesheetToken, vm) {
3369
- const content = [];
3370
- let root;
3371
- for (let i = 0; i < stylesheets.length; i++) {
3372
- let stylesheet = stylesheets[i];
3373
- if (isArray$1(stylesheet)) {
3374
- ArrayPush$1.apply(content, evaluateStylesheetsContent(stylesheet, stylesheetToken, vm));
3375
- } else {
3376
- if (process.env.NODE_ENV !== 'production') {
3377
- // Check for compiler version mismatch in dev mode only
3378
- checkVersionMismatch(stylesheet, 'stylesheet');
3379
- // in dev-mode, we support hot swapping of stylesheet, which means that
3380
- // the component instance might be attempting to use an old version of
3381
- // the stylesheet, while internally, we have a replacement for it.
3382
- stylesheet = getStyleOrSwappedStyle(stylesheet);
3383
- }
3384
- const isScopedCss = stylesheet[KEY__SCOPED_CSS];
3385
- if (lwcRuntimeFlags.DISABLE_LIGHT_DOM_UNSCOPED_CSS) {
3386
- if (!isScopedCss && vm.renderMode === 0 /* RenderMode.Light */) {
3387
- logError('Unscoped CSS is not supported in Light DOM. Please use scoped CSS (*.scoped.css) instead of unscoped CSS (*.css).');
3388
- continue;
3389
- }
3390
- }
3391
- // Apply the scope token only if the stylesheet itself is scoped, or if we're rendering synthetic shadow.
3392
- const scopeToken = isScopedCss || vm.shadowMode === 1 /* ShadowMode.Synthetic */ && vm.renderMode === 1 /* RenderMode.Shadow */ ? stylesheetToken : undefined;
3393
- // Use the actual `:host` selector if we're rendering global CSS for light DOM, or if we're rendering
3394
- // native shadow DOM. Synthetic shadow DOM never uses `:host`.
3395
- const useActualHostSelector = vm.renderMode === 0 /* RenderMode.Light */ ? !isScopedCss : vm.shadowMode === 0 /* ShadowMode.Native */;
3396
- // Use the native :dir() pseudoclass only in native shadow DOM. Otherwise, in synthetic shadow,
3397
- // we use an attribute selector on the host to simulate :dir().
3398
- let useNativeDirPseudoclass;
3399
- if (vm.renderMode === 1 /* RenderMode.Shadow */) {
3400
- useNativeDirPseudoclass = vm.shadowMode === 0 /* ShadowMode.Native */;
3401
- } else {
3402
- // Light DOM components should only render `[dir]` if they're inside of a synthetic shadow root.
3403
- // At the top level (root is null) or inside of a native shadow root, they should use `:dir()`.
3404
- if (isUndefined$1(root)) {
3405
- // Only calculate the root once as necessary
3406
- root = getNearestShadowComponent(vm);
3407
- }
3408
- useNativeDirPseudoclass = isNull(root) || root.shadowMode === 0 /* ShadowMode.Native */;
3409
- }
3410
-
3411
- ArrayPush$1.call(content, stylesheet(scopeToken, useActualHostSelector, useNativeDirPseudoclass));
3188
+ const content = [];
3189
+ let root;
3190
+ for (let i = 0; i < stylesheets.length; i++) {
3191
+ let stylesheet = stylesheets[i];
3192
+ if (isArray$1(stylesheet)) {
3193
+ ArrayPush$1.apply(content, evaluateStylesheetsContent(stylesheet, stylesheetToken, vm));
3194
+ }
3195
+ else {
3196
+ if (process.env.NODE_ENV !== 'production') {
3197
+ // Check for compiler version mismatch in dev mode only
3198
+ checkVersionMismatch(stylesheet, 'stylesheet');
3199
+ // in dev-mode, we support hot swapping of stylesheet, which means that
3200
+ // the component instance might be attempting to use an old version of
3201
+ // the stylesheet, while internally, we have a replacement for it.
3202
+ stylesheet = getStyleOrSwappedStyle(stylesheet);
3203
+ }
3204
+ const isScopedCss = stylesheet[KEY__SCOPED_CSS];
3205
+ if (lwcRuntimeFlags.DISABLE_LIGHT_DOM_UNSCOPED_CSS &&
3206
+ !isScopedCss &&
3207
+ vm.renderMode === 0 /* RenderMode.Light */) {
3208
+ logError('Unscoped CSS is not supported in Light DOM. Please use scoped CSS (*.scoped.css) instead of unscoped CSS (*.css).');
3209
+ continue;
3210
+ }
3211
+ // Apply the scope token only if the stylesheet itself is scoped, or if we're rendering synthetic shadow.
3212
+ const scopeToken = isScopedCss ||
3213
+ (vm.shadowMode === 1 /* ShadowMode.Synthetic */ && vm.renderMode === 1 /* RenderMode.Shadow */)
3214
+ ? stylesheetToken
3215
+ : undefined;
3216
+ // Use the actual `:host` selector if we're rendering global CSS for light DOM, or if we're rendering
3217
+ // native shadow DOM. Synthetic shadow DOM never uses `:host`.
3218
+ const useActualHostSelector = vm.renderMode === 0 /* RenderMode.Light */
3219
+ ? !isScopedCss
3220
+ : vm.shadowMode === 0 /* ShadowMode.Native */;
3221
+ // Use the native :dir() pseudoclass only in native shadow DOM. Otherwise, in synthetic shadow,
3222
+ // we use an attribute selector on the host to simulate :dir().
3223
+ let useNativeDirPseudoclass;
3224
+ if (vm.renderMode === 1 /* RenderMode.Shadow */) {
3225
+ useNativeDirPseudoclass = vm.shadowMode === 0 /* ShadowMode.Native */;
3226
+ }
3227
+ else {
3228
+ // Light DOM components should only render `[dir]` if they're inside of a synthetic shadow root.
3229
+ // At the top level (root is null) or inside of a native shadow root, they should use `:dir()`.
3230
+ if (isUndefined$1(root)) {
3231
+ // Only calculate the root once as necessary
3232
+ root = getNearestShadowComponent(vm);
3233
+ }
3234
+ useNativeDirPseudoclass = isNull(root) || root.shadowMode === 0 /* ShadowMode.Native */;
3235
+ }
3236
+ ArrayPush$1.call(content, stylesheet(scopeToken, useActualHostSelector, useNativeDirPseudoclass));
3237
+ }
3412
3238
  }
3413
- }
3414
- return content;
3239
+ return content;
3415
3240
  }
3416
3241
  function getStylesheetsContent(vm, template) {
3417
- const {
3418
- stylesheets,
3419
- stylesheetToken
3420
- } = template;
3421
- const {
3422
- stylesheets: vmStylesheets
3423
- } = vm;
3424
- let content = [];
3425
- if (hasStyles(stylesheets)) {
3426
- content = evaluateStylesheetsContent(stylesheets, stylesheetToken, vm);
3427
- }
3428
- // VM (component) stylesheets apply after template stylesheets
3429
- if (hasStyles(vmStylesheets)) {
3430
- ArrayPush$1.apply(content, evaluateStylesheetsContent(vmStylesheets, stylesheetToken, vm));
3431
- }
3432
- return content;
3242
+ const { stylesheets, stylesheetToken } = template;
3243
+ const { stylesheets: vmStylesheets } = vm;
3244
+ let content = [];
3245
+ if (hasStyles(stylesheets)) {
3246
+ content = evaluateStylesheetsContent(stylesheets, stylesheetToken, vm);
3247
+ }
3248
+ // VM (component) stylesheets apply after template stylesheets
3249
+ if (hasStyles(vmStylesheets)) {
3250
+ ArrayPush$1.apply(content, evaluateStylesheetsContent(vmStylesheets, stylesheetToken, vm));
3251
+ }
3252
+ return content;
3433
3253
  }
3434
3254
  // It might be worth caching this to avoid doing the lookup repeatedly, but
3435
3255
  // perf testing has not shown it to be a huge improvement yet:
3436
3256
  // https://github.com/salesforce/lwc/pull/2460#discussion_r691208892
3437
3257
  function getNearestShadowComponent(vm) {
3438
- let owner = vm;
3439
- while (!isNull(owner)) {
3440
- if (owner.renderMode === 1 /* RenderMode.Shadow */) {
3441
- return owner;
3258
+ let owner = vm;
3259
+ while (!isNull(owner)) {
3260
+ if (owner.renderMode === 1 /* RenderMode.Shadow */) {
3261
+ return owner;
3262
+ }
3263
+ owner = owner.owner;
3442
3264
  }
3443
- owner = owner.owner;
3444
- }
3445
- return owner;
3265
+ return owner;
3446
3266
  }
3447
3267
  /**
3448
3268
  * If the component that is currently being rendered uses scoped styles,
@@ -3450,11 +3270,8 @@ function getNearestShadowComponent(vm) {
3450
3270
  * it returns null.
3451
3271
  */
3452
3272
  function getScopeTokenClass(owner) {
3453
- const {
3454
- cmpTemplate,
3455
- context
3456
- } = owner;
3457
- return context.hasScopedStyles && (cmpTemplate === null || cmpTemplate === void 0 ? void 0 : cmpTemplate.stylesheetToken) || null;
3273
+ const { cmpTemplate, context } = owner;
3274
+ return (context.hasScopedStyles && (cmpTemplate === null || cmpTemplate === void 0 ? void 0 : cmpTemplate.stylesheetToken)) || null;
3458
3275
  }
3459
3276
  /**
3460
3277
  * This function returns the host style token for a custom element if it
@@ -3463,54 +3280,46 @@ function getScopeTokenClass(owner) {
3463
3280
  * A host style token is applied to the component if scoped styles are used.
3464
3281
  */
3465
3282
  function getStylesheetTokenHost(vnode) {
3466
- const {
3467
- template
3468
- } = getComponentInternalDef(vnode.ctor);
3469
- const {
3470
- vm
3471
- } = vnode;
3472
- const {
3473
- stylesheetToken
3474
- } = template;
3475
- return !isUndefined$1(stylesheetToken) && computeHasScopedStyles(template, vm) ? makeHostToken(stylesheetToken) : null;
3283
+ const { template } = getComponentInternalDef(vnode.ctor);
3284
+ const { vm } = vnode;
3285
+ const { stylesheetToken } = template;
3286
+ return !isUndefined$1(stylesheetToken) && computeHasScopedStyles(template, vm)
3287
+ ? makeHostToken(stylesheetToken)
3288
+ : null;
3476
3289
  }
3477
3290
  function getNearestNativeShadowComponent(vm) {
3478
- const owner = getNearestShadowComponent(vm);
3479
- if (!isNull(owner) && owner.shadowMode === 1 /* ShadowMode.Synthetic */) {
3480
- // Synthetic-within-native is impossible. So if the nearest shadow component is
3481
- // synthetic, we know we won't find a native component if we go any further.
3482
- return null;
3483
- }
3484
- return owner;
3291
+ const owner = getNearestShadowComponent(vm);
3292
+ if (!isNull(owner) && owner.shadowMode === 1 /* ShadowMode.Synthetic */) {
3293
+ // Synthetic-within-native is impossible. So if the nearest shadow component is
3294
+ // synthetic, we know we won't find a native component if we go any further.
3295
+ return null;
3296
+ }
3297
+ return owner;
3485
3298
  }
3486
3299
  function createStylesheet(vm, stylesheets) {
3487
- const {
3488
- renderMode,
3489
- shadowMode,
3490
- renderer: {
3491
- insertStylesheet
3492
- }
3493
- } = vm;
3494
- if (renderMode === 1 /* RenderMode.Shadow */ && shadowMode === 1 /* ShadowMode.Synthetic */) {
3495
- for (let i = 0; i < stylesheets.length; i++) {
3496
- insertStylesheet(stylesheets[i]);
3497
- }
3498
- } else if (!process.env.IS_BROWSER || vm.hydrated) {
3499
- // Note: We need to ensure that during hydration, the stylesheets method is the same as those in ssr.
3500
- // This works in the client, because the stylesheets are created, and cached in the VM
3501
- // the first time the VM renders.
3502
- // native shadow or light DOM, SSR
3503
- return ArrayMap.call(stylesheets, createInlineStyleVNode);
3504
- } else {
3505
- // native shadow or light DOM, DOM renderer
3506
- const root = getNearestNativeShadowComponent(vm);
3507
- // null root means a global style
3508
- const target = isNull(root) ? undefined : root.shadowRoot;
3509
- for (let i = 0; i < stylesheets.length; i++) {
3510
- insertStylesheet(stylesheets[i], target);
3300
+ const { renderMode, shadowMode, renderer: { insertStylesheet }, } = vm;
3301
+ if (renderMode === 1 /* RenderMode.Shadow */ && shadowMode === 1 /* ShadowMode.Synthetic */) {
3302
+ for (let i = 0; i < stylesheets.length; i++) {
3303
+ insertStylesheet(stylesheets[i]);
3304
+ }
3305
+ }
3306
+ else if (!process.env.IS_BROWSER || vm.hydrated) {
3307
+ // Note: We need to ensure that during hydration, the stylesheets method is the same as those in ssr.
3308
+ // This works in the client, because the stylesheets are created, and cached in the VM
3309
+ // the first time the VM renders.
3310
+ // native shadow or light DOM, SSR
3311
+ return ArrayMap.call(stylesheets, createInlineStyleVNode);
3511
3312
  }
3512
- }
3513
- return null;
3313
+ else {
3314
+ // native shadow or light DOM, DOM renderer
3315
+ const root = getNearestNativeShadowComponent(vm);
3316
+ // null root means a global style
3317
+ const target = isNull(root) ? undefined : root.shadowRoot;
3318
+ for (let i = 0; i < stylesheets.length; i++) {
3319
+ insertStylesheet(stylesheets[i], target);
3320
+ }
3321
+ }
3322
+ return null;
3514
3323
  }
3515
3324
 
3516
3325
  /*
@@ -3829,505 +3638,443 @@ function applyStaticStyleAttribute(vnode, renderer) {
3829
3638
  * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
3830
3639
  */
3831
3640
  function patchChildren(c1, c2, parent, renderer) {
3832
- if (hasDynamicChildren(c2)) {
3833
- updateDynamicChildren(c1, c2, parent, renderer);
3834
- } else {
3835
- updateStaticChildren(c1, c2, parent, renderer);
3836
- }
3641
+ if (hasDynamicChildren(c2)) {
3642
+ updateDynamicChildren(c1, c2, parent, renderer);
3643
+ }
3644
+ else {
3645
+ updateStaticChildren(c1, c2, parent, renderer);
3646
+ }
3837
3647
  }
3838
3648
  function patch(n1, n2, parent, renderer) {
3839
- var _a, _b;
3840
- if (n1 === n2) {
3841
- return;
3842
- }
3843
- if (process.env.NODE_ENV !== 'production') {
3844
- if (!isSameVnode(n1, n2)) {
3845
- throw new Error('Expected these VNodes to be the same: ' + JSON.stringify({
3846
- sel: n1.sel,
3847
- key: n1.key
3848
- }) + ', ' + JSON.stringify({
3849
- sel: n2.sel,
3850
- key: n2.key
3851
- }));
3852
- }
3853
- }
3854
- switch (n2.type) {
3855
- case 0 /* VNodeType.Text */:
3856
- // VText has no special capability, fallback to the owner's renderer
3857
- patchText(n1, n2, renderer);
3858
- break;
3859
- case 1 /* VNodeType.Comment */:
3860
- // VComment has no special capability, fallback to the owner's renderer
3861
- patchComment(n1, n2, renderer);
3862
- break;
3863
- case 4 /* VNodeType.Static */:
3864
- n2.elm = n1.elm;
3865
- break;
3866
- case 5 /* VNodeType.Fragment */:
3867
- patchFragment(n1, n2, parent, renderer);
3868
- break;
3869
- case 2 /* VNodeType.Element */:
3870
- patchElement(n1, n2, (_a = n2.data.renderer) !== null && _a !== void 0 ? _a : renderer);
3871
- break;
3872
- case 3 /* VNodeType.CustomElement */:
3873
- patchCustomElement(n1, n2, parent, (_b = n2.data.renderer) !== null && _b !== void 0 ? _b : renderer);
3874
- break;
3875
- }
3649
+ var _a, _b;
3650
+ if (n1 === n2) {
3651
+ return;
3652
+ }
3653
+ if (process.env.NODE_ENV !== 'production') {
3654
+ if (!isSameVnode(n1, n2)) {
3655
+ throw new Error('Expected these VNodes to be the same: ' +
3656
+ JSON.stringify({ sel: n1.sel, key: n1.key }) +
3657
+ ', ' +
3658
+ JSON.stringify({ sel: n2.sel, key: n2.key }));
3659
+ }
3660
+ }
3661
+ switch (n2.type) {
3662
+ case 0 /* VNodeType.Text */:
3663
+ // VText has no special capability, fallback to the owner's renderer
3664
+ patchText(n1, n2, renderer);
3665
+ break;
3666
+ case 1 /* VNodeType.Comment */:
3667
+ // VComment has no special capability, fallback to the owner's renderer
3668
+ patchComment(n1, n2, renderer);
3669
+ break;
3670
+ case 4 /* VNodeType.Static */:
3671
+ n2.elm = n1.elm;
3672
+ break;
3673
+ case 5 /* VNodeType.Fragment */:
3674
+ patchFragment(n1, n2, parent, renderer);
3675
+ break;
3676
+ case 2 /* VNodeType.Element */:
3677
+ patchElement(n1, n2, (_a = n2.data.renderer) !== null && _a !== void 0 ? _a : renderer);
3678
+ break;
3679
+ case 3 /* VNodeType.CustomElement */:
3680
+ patchCustomElement(n1, n2, parent, (_b = n2.data.renderer) !== null && _b !== void 0 ? _b : renderer);
3681
+ break;
3682
+ }
3876
3683
  }
3877
3684
  function mount(node, parent, renderer, anchor) {
3878
- var _a, _b;
3879
- switch (node.type) {
3880
- case 0 /* VNodeType.Text */:
3881
- // VText has no special capability, fallback to the owner's renderer
3882
- mountText(node, parent, anchor, renderer);
3883
- break;
3884
- case 1 /* VNodeType.Comment */:
3885
- // VComment has no special capability, fallback to the owner's renderer
3886
- mountComment(node, parent, anchor, renderer);
3887
- break;
3888
- case 4 /* VNodeType.Static */:
3889
- // VStatic cannot have a custom renderer associated to them, using owner's renderer
3890
- mountStatic(node, parent, anchor, renderer);
3891
- break;
3892
- case 5 /* VNodeType.Fragment */:
3893
- mountFragment(node, parent, anchor, renderer);
3894
- break;
3895
- case 2 /* VNodeType.Element */:
3896
- // If the vnode data has a renderer override use it, else fallback to owner's renderer
3897
- mountElement(node, parent, anchor, (_a = node.data.renderer) !== null && _a !== void 0 ? _a : renderer);
3898
- break;
3899
- case 3 /* VNodeType.CustomElement */:
3900
- // If the vnode data has a renderer override use it, else fallback to owner's renderer
3901
- mountCustomElement(node, parent, anchor, (_b = node.data.renderer) !== null && _b !== void 0 ? _b : renderer);
3902
- break;
3903
- }
3685
+ var _a, _b;
3686
+ switch (node.type) {
3687
+ case 0 /* VNodeType.Text */:
3688
+ // VText has no special capability, fallback to the owner's renderer
3689
+ mountText(node, parent, anchor, renderer);
3690
+ break;
3691
+ case 1 /* VNodeType.Comment */:
3692
+ // VComment has no special capability, fallback to the owner's renderer
3693
+ mountComment(node, parent, anchor, renderer);
3694
+ break;
3695
+ case 4 /* VNodeType.Static */:
3696
+ // VStatic cannot have a custom renderer associated to them, using owner's renderer
3697
+ mountStatic(node, parent, anchor, renderer);
3698
+ break;
3699
+ case 5 /* VNodeType.Fragment */:
3700
+ mountFragment(node, parent, anchor, renderer);
3701
+ break;
3702
+ case 2 /* VNodeType.Element */:
3703
+ // If the vnode data has a renderer override use it, else fallback to owner's renderer
3704
+ mountElement(node, parent, anchor, (_a = node.data.renderer) !== null && _a !== void 0 ? _a : renderer);
3705
+ break;
3706
+ case 3 /* VNodeType.CustomElement */:
3707
+ // If the vnode data has a renderer override use it, else fallback to owner's renderer
3708
+ mountCustomElement(node, parent, anchor, (_b = node.data.renderer) !== null && _b !== void 0 ? _b : renderer);
3709
+ break;
3710
+ }
3904
3711
  }
3905
3712
  function patchText(n1, n2, renderer) {
3906
- n2.elm = n1.elm;
3907
- if (n2.text !== n1.text) {
3908
- updateTextContent(n2, renderer);
3909
- }
3713
+ n2.elm = n1.elm;
3714
+ if (n2.text !== n1.text) {
3715
+ updateTextContent(n2, renderer);
3716
+ }
3910
3717
  }
3911
3718
  function mountText(vnode, parent, anchor, renderer) {
3912
- const {
3913
- owner
3914
- } = vnode;
3915
- const {
3916
- createText
3917
- } = renderer;
3918
- const textNode = vnode.elm = createText(vnode.text);
3919
- linkNodeToShadow(textNode, owner, renderer);
3920
- insertNode(textNode, parent, anchor, renderer);
3719
+ const { owner } = vnode;
3720
+ const { createText } = renderer;
3721
+ const textNode = (vnode.elm = createText(vnode.text));
3722
+ linkNodeToShadow(textNode, owner, renderer);
3723
+ insertNode(textNode, parent, anchor, renderer);
3921
3724
  }
3922
3725
  function patchComment(n1, n2, renderer) {
3923
- n2.elm = n1.elm;
3924
- // FIXME: Comment nodes should be static, we shouldn't need to diff them together. However
3925
- // it is the case today.
3926
- if (n2.text !== n1.text) {
3927
- updateTextContent(n2, renderer);
3928
- }
3726
+ n2.elm = n1.elm;
3727
+ // FIXME: Comment nodes should be static, we shouldn't need to diff them together. However
3728
+ // it is the case today.
3729
+ if (n2.text !== n1.text) {
3730
+ updateTextContent(n2, renderer);
3731
+ }
3929
3732
  }
3930
3733
  function mountComment(vnode, parent, anchor, renderer) {
3931
- const {
3932
- owner
3933
- } = vnode;
3934
- const {
3935
- createComment
3936
- } = renderer;
3937
- const commentNode = vnode.elm = createComment(vnode.text);
3938
- linkNodeToShadow(commentNode, owner, renderer);
3939
- insertNode(commentNode, parent, anchor, renderer);
3734
+ const { owner } = vnode;
3735
+ const { createComment } = renderer;
3736
+ const commentNode = (vnode.elm = createComment(vnode.text));
3737
+ linkNodeToShadow(commentNode, owner, renderer);
3738
+ insertNode(commentNode, parent, anchor, renderer);
3940
3739
  }
3941
3740
  function mountFragment(vnode, parent, anchor, renderer) {
3942
- const {
3943
- children
3944
- } = vnode;
3945
- mountVNodes(children, parent, renderer, anchor);
3946
- // children of a fragment will always have at least the two delimiters.
3947
- vnode.elm = children[children.length - 1].elm;
3741
+ const { children } = vnode;
3742
+ mountVNodes(children, parent, renderer, anchor);
3743
+ // children of a fragment will always have at least the two delimiters.
3744
+ vnode.elm = children[children.length - 1].elm;
3948
3745
  }
3949
3746
  function patchFragment(n1, n2, parent, renderer) {
3950
- const {
3951
- children,
3952
- stable
3953
- } = n2;
3954
- if (stable) {
3955
- updateStaticChildren(n1.children, children, parent, renderer);
3956
- } else {
3957
- updateDynamicChildren(n1.children, children, parent, renderer);
3958
- }
3959
- // Note: not reusing n1.elm, because during patching, it may be patched with another text node.
3960
- n2.elm = children[children.length - 1].elm;
3747
+ const { children, stable } = n2;
3748
+ if (stable) {
3749
+ updateStaticChildren(n1.children, children, parent, renderer);
3750
+ }
3751
+ else {
3752
+ updateDynamicChildren(n1.children, children, parent, renderer);
3753
+ }
3754
+ // Note: not reusing n1.elm, because during patching, it may be patched with another text node.
3755
+ n2.elm = children[children.length - 1].elm;
3961
3756
  }
3962
3757
  function mountElement(vnode, parent, anchor, renderer) {
3963
- const {
3964
- sel,
3965
- owner,
3966
- data: {
3967
- svg
3968
- }
3969
- } = vnode;
3970
- const {
3971
- createElement
3972
- } = renderer;
3973
- const namespace = isTrue(svg) ? SVG_NAMESPACE : undefined;
3974
- const elm = vnode.elm = createElement(sel, namespace);
3975
- linkNodeToShadow(elm, owner, renderer);
3976
- applyStyleScoping(elm, owner, renderer);
3977
- applyDomManual(elm, vnode);
3978
- applyElementRestrictions(elm, vnode);
3979
- patchElementPropsAndAttrs$1(null, vnode, renderer);
3980
- insertNode(elm, parent, anchor, renderer);
3981
- mountVNodes(vnode.children, elm, renderer, null);
3758
+ const { sel, owner, data: { svg }, } = vnode;
3759
+ const { createElement } = renderer;
3760
+ const namespace = isTrue(svg) ? SVG_NAMESPACE : undefined;
3761
+ const elm = (vnode.elm = createElement(sel, namespace));
3762
+ linkNodeToShadow(elm, owner, renderer);
3763
+ applyStyleScoping(elm, owner, renderer);
3764
+ applyDomManual(elm, vnode);
3765
+ applyElementRestrictions(elm, vnode);
3766
+ patchElementPropsAndAttrs$1(null, vnode, renderer);
3767
+ insertNode(elm, parent, anchor, renderer);
3768
+ mountVNodes(vnode.children, elm, renderer, null);
3982
3769
  }
3983
3770
  function patchElement(n1, n2, renderer) {
3984
- const elm = n2.elm = n1.elm;
3985
- patchElementPropsAndAttrs$1(n1, n2, renderer);
3986
- patchChildren(n1.children, n2.children, elm, renderer);
3771
+ const elm = (n2.elm = n1.elm);
3772
+ patchElementPropsAndAttrs$1(n1, n2, renderer);
3773
+ patchChildren(n1.children, n2.children, elm, renderer);
3987
3774
  }
3988
3775
  function mountStatic(vnode, parent, anchor, renderer) {
3989
- const {
3990
- owner
3991
- } = vnode;
3992
- const {
3993
- cloneNode,
3994
- isSyntheticShadowDefined
3995
- } = renderer;
3996
- const elm = vnode.elm = cloneNode(vnode.fragment, true);
3997
- linkNodeToShadow(elm, owner, renderer);
3998
- applyElementRestrictions(elm, vnode);
3999
- // Marks this node as Static to propagate the shadow resolver. must happen after elm is assigned to the proper shadow
4000
- const {
4001
- renderMode,
4002
- shadowMode
4003
- } = owner;
4004
- if (isSyntheticShadowDefined) {
4005
- if (shadowMode === 1 /* ShadowMode.Synthetic */ || renderMode === 0 /* RenderMode.Light */) {
4006
- elm[KEY__SHADOW_STATIC] = true;
3776
+ const { owner } = vnode;
3777
+ const { cloneNode, isSyntheticShadowDefined } = renderer;
3778
+ const elm = (vnode.elm = cloneNode(vnode.fragment, true));
3779
+ linkNodeToShadow(elm, owner, renderer);
3780
+ applyElementRestrictions(elm, vnode);
3781
+ // Marks this node as Static to propagate the shadow resolver. must happen after elm is assigned to the proper shadow
3782
+ const { renderMode, shadowMode } = owner;
3783
+ if (isSyntheticShadowDefined) {
3784
+ if (shadowMode === 1 /* ShadowMode.Synthetic */ || renderMode === 0 /* RenderMode.Light */) {
3785
+ elm[KEY__SHADOW_STATIC] = true;
3786
+ }
4007
3787
  }
4008
- }
4009
- insertNode(elm, parent, anchor, renderer);
3788
+ insertNode(elm, parent, anchor, renderer);
4010
3789
  }
4011
3790
  function mountCustomElement(vnode, parent, anchor, renderer) {
4012
- const {
4013
- sel,
4014
- owner
4015
- } = vnode;
4016
- const {
4017
- createCustomElement
4018
- } = renderer;
4019
- /**
4020
- * Note: if the upgradable constructor does not expect, or throw when we new it
4021
- * with a callback as the first argument, we could implement a more advanced
4022
- * mechanism that only passes that argument if the constructor is known to be
4023
- * an upgradable custom element.
4024
- */
4025
- let vm;
4026
- const upgradeCallback = elm => {
4027
- // the custom element from the registry is expecting an upgrade callback
4028
- vm = createViewModelHook(elm, vnode, renderer);
4029
- };
4030
- let connectedCallback;
4031
- let disconnectedCallback;
4032
- if (lwcRuntimeFlags.ENABLE_NATIVE_CUSTOM_ELEMENT_LIFECYCLE) {
4033
- connectedCallback = elm => {
4034
- connectRootElement(elm);
4035
- };
4036
- disconnectedCallback = elm => {
4037
- disconnectRootElement(elm);
3791
+ const { sel, owner } = vnode;
3792
+ const { createCustomElement } = renderer;
3793
+ /**
3794
+ * Note: if the upgradable constructor does not expect, or throw when we new it
3795
+ * with a callback as the first argument, we could implement a more advanced
3796
+ * mechanism that only passes that argument if the constructor is known to be
3797
+ * an upgradable custom element.
3798
+ */
3799
+ let vm;
3800
+ const upgradeCallback = (elm) => {
3801
+ // the custom element from the registry is expecting an upgrade callback
3802
+ vm = createViewModelHook(elm, vnode, renderer);
4038
3803
  };
4039
- }
4040
- // Should never get a tag with upper case letter at this point; the compiler
4041
- // should produce only tags with lowercase letters. However, the Java
4042
- // compiler may generate tagnames with uppercase letters so - for backwards
4043
- // compatibility, we lower case the tagname here.
4044
- const normalizedTagname = sel.toLowerCase();
4045
- const elm = createCustomElement(normalizedTagname, upgradeCallback, connectedCallback, disconnectedCallback);
4046
- vnode.elm = elm;
4047
- vnode.vm = vm;
4048
- linkNodeToShadow(elm, owner, renderer);
4049
- applyStyleScoping(elm, owner, renderer);
4050
- if (vm) {
4051
- allocateChildren(vnode, vm);
4052
- }
4053
- patchElementPropsAndAttrs$1(null, vnode, renderer);
4054
- insertNode(elm, parent, anchor, renderer);
4055
- if (vm) {
4056
- if (process.env.IS_BROWSER) {
4057
- if (!lwcRuntimeFlags.ENABLE_NATIVE_CUSTOM_ELEMENT_LIFECYCLE) {
4058
- if (process.env.NODE_ENV !== 'production') {
4059
- // With synthetic lifecycle callbacks, it's possible for elements to be removed without the engine
4060
- // noticing it (e.g. `appendChild` the same host element twice). This test ensures we don't regress.
4061
- assert.isTrue(vm.state === 0 /* VMState.created */, `${vm} cannot be recycled.`);
4062
- }
4063
- runConnectedCallback(vm);
4064
- }
4065
- } else {
4066
- // On the server, we don't have native custom element lifecycle callbacks, so we must
4067
- // manually invoke the connectedCallback for a child component.
4068
- runConnectedCallback(vm);
4069
- }
4070
- }
4071
- mountVNodes(vnode.children, elm, renderer, null);
4072
- if (vm) {
4073
- appendVM(vm);
4074
- }
3804
+ let connectedCallback;
3805
+ let disconnectedCallback;
3806
+ if (lwcRuntimeFlags.ENABLE_NATIVE_CUSTOM_ELEMENT_LIFECYCLE) {
3807
+ connectedCallback = (elm) => {
3808
+ connectRootElement(elm);
3809
+ };
3810
+ disconnectedCallback = (elm) => {
3811
+ disconnectRootElement(elm);
3812
+ };
3813
+ }
3814
+ // Should never get a tag with upper case letter at this point; the compiler
3815
+ // should produce only tags with lowercase letters. However, the Java
3816
+ // compiler may generate tagnames with uppercase letters so - for backwards
3817
+ // compatibility, we lower case the tagname here.
3818
+ const normalizedTagname = sel.toLowerCase();
3819
+ const elm = createCustomElement(normalizedTagname, upgradeCallback, connectedCallback, disconnectedCallback);
3820
+ vnode.elm = elm;
3821
+ vnode.vm = vm;
3822
+ linkNodeToShadow(elm, owner, renderer);
3823
+ applyStyleScoping(elm, owner, renderer);
3824
+ if (vm) {
3825
+ allocateChildren(vnode, vm);
3826
+ }
3827
+ patchElementPropsAndAttrs$1(null, vnode, renderer);
3828
+ insertNode(elm, parent, anchor, renderer);
3829
+ if (vm) {
3830
+ if (process.env.IS_BROWSER) {
3831
+ if (!lwcRuntimeFlags.ENABLE_NATIVE_CUSTOM_ELEMENT_LIFECYCLE) {
3832
+ if (process.env.NODE_ENV !== 'production') {
3833
+ // With synthetic lifecycle callbacks, it's possible for elements to be removed without the engine
3834
+ // noticing it (e.g. `appendChild` the same host element twice). This test ensures we don't regress.
3835
+ assert.isTrue(vm.state === 0 /* VMState.created */, `${vm} cannot be recycled.`);
3836
+ }
3837
+ runConnectedCallback(vm);
3838
+ }
3839
+ }
3840
+ else {
3841
+ // On the server, we don't have native custom element lifecycle callbacks, so we must
3842
+ // manually invoke the connectedCallback for a child component.
3843
+ runConnectedCallback(vm);
3844
+ }
3845
+ }
3846
+ mountVNodes(vnode.children, elm, renderer, null);
3847
+ if (vm) {
3848
+ appendVM(vm);
3849
+ }
4075
3850
  }
4076
3851
  function patchCustomElement(n1, n2, parent, renderer) {
4077
- if (n1.ctor !== n2.ctor) {
4078
- // If the constructor, unmount the current component and mount a new one using the new
4079
- // constructor.
4080
- const anchor = renderer.nextSibling(n1.elm);
4081
- unmount(n1, parent, renderer, true);
4082
- mountCustomElement(n2, parent, anchor, renderer);
4083
- } else {
4084
- // Otherwise patch the existing component with new props/attrs/etc.
4085
- const elm = n2.elm = n1.elm;
4086
- const vm = n2.vm = n1.vm;
4087
- patchElementPropsAndAttrs$1(n1, n2, renderer);
4088
- if (!isUndefined$1(vm)) {
4089
- // in fallback mode, the allocation will always set children to
4090
- // empty and delegate the real allocation to the slot elements
4091
- allocateChildren(n2, vm);
4092
- // Solves an edge case with slotted VFragments in native shadow mode.
4093
- //
4094
- // During allocation, in native shadow, slotted VFragment nodes are flattened and their text delimiters are removed
4095
- // to avoid interfering with native slot behavior. When this happens, if any of the fragments
4096
- // were not stable, the children must go through the dynamic diffing algo.
4097
- //
4098
- // If the new children (n2.children) contain no VFragments, but the previous children (n1.children) were dynamic,
4099
- // the new nodes must be marked dynamic so that all nodes are properly updated. The only indicator that the new
4100
- // nodes need to be dynamic comes from the previous children, so we check that to determine whether we need to
4101
- // mark the new children dynamic.
4102
- //
4103
- // Example:
4104
- // n1.children: [div, VFragment('', div, null, ''), div] => [div, div, null, div]; // marked dynamic
4105
- // n2.children: [div, null, div] => [div, null, div] // marked ???
4106
- const {
4107
- shadowMode,
4108
- renderMode
4109
- } = vm;
4110
- if (shadowMode == 0 /* ShadowMode.Native */ && renderMode !== 0 /* RenderMode.Light */ && hasDynamicChildren(n1.children)) {
4111
- // No-op if children has already been marked dynamic by 'allocateChildren()'.
4112
- markAsDynamicChildren(n2.children);
4113
- }
4114
- }
4115
- // in fallback mode, the children will be always empty, so, nothing
4116
- // will happen, but in native, it does allocate the light dom
4117
- patchChildren(n1.children, n2.children, elm, renderer);
4118
- if (!isUndefined$1(vm)) {
4119
- // this will probably update the shadowRoot, but only if the vm is in a dirty state
4120
- // this is important to preserve the top to bottom synchronous rendering phase.
4121
- rerenderVM(vm);
3852
+ if (n1.ctor !== n2.ctor) {
3853
+ // If the constructor, unmount the current component and mount a new one using the new
3854
+ // constructor.
3855
+ const anchor = renderer.nextSibling(n1.elm);
3856
+ unmount(n1, parent, renderer, true);
3857
+ mountCustomElement(n2, parent, anchor, renderer);
3858
+ }
3859
+ else {
3860
+ // Otherwise patch the existing component with new props/attrs/etc.
3861
+ const elm = (n2.elm = n1.elm);
3862
+ const vm = (n2.vm = n1.vm);
3863
+ patchElementPropsAndAttrs$1(n1, n2, renderer);
3864
+ if (!isUndefined$1(vm)) {
3865
+ // in fallback mode, the allocation will always set children to
3866
+ // empty and delegate the real allocation to the slot elements
3867
+ allocateChildren(n2, vm);
3868
+ // Solves an edge case with slotted VFragments in native shadow mode.
3869
+ //
3870
+ // During allocation, in native shadow, slotted VFragment nodes are flattened and their text delimiters are removed
3871
+ // to avoid interfering with native slot behavior. When this happens, if any of the fragments
3872
+ // were not stable, the children must go through the dynamic diffing algo.
3873
+ //
3874
+ // If the new children (n2.children) contain no VFragments, but the previous children (n1.children) were dynamic,
3875
+ // the new nodes must be marked dynamic so that all nodes are properly updated. The only indicator that the new
3876
+ // nodes need to be dynamic comes from the previous children, so we check that to determine whether we need to
3877
+ // mark the new children dynamic.
3878
+ //
3879
+ // Example:
3880
+ // n1.children: [div, VFragment('', div, null, ''), div] => [div, div, null, div]; // marked dynamic
3881
+ // n2.children: [div, null, div] => [div, null, div] // marked ???
3882
+ const { shadowMode, renderMode } = vm;
3883
+ if (shadowMode == 0 /* ShadowMode.Native */ &&
3884
+ renderMode !== 0 /* RenderMode.Light */ &&
3885
+ hasDynamicChildren(n1.children)) {
3886
+ // No-op if children has already been marked dynamic by 'allocateChildren()'.
3887
+ markAsDynamicChildren(n2.children);
3888
+ }
3889
+ }
3890
+ // in fallback mode, the children will be always empty, so, nothing
3891
+ // will happen, but in native, it does allocate the light dom
3892
+ patchChildren(n1.children, n2.children, elm, renderer);
3893
+ if (!isUndefined$1(vm)) {
3894
+ // this will probably update the shadowRoot, but only if the vm is in a dirty state
3895
+ // this is important to preserve the top to bottom synchronous rendering phase.
3896
+ rerenderVM(vm);
3897
+ }
4122
3898
  }
4123
- }
4124
3899
  }
4125
3900
  function mountVNodes(vnodes, parent, renderer, anchor, start = 0, end = vnodes.length) {
4126
- for (; start < end; ++start) {
4127
- const vnode = vnodes[start];
4128
- if (isVNode(vnode)) {
4129
- mount(vnode, parent, renderer, anchor);
3901
+ for (; start < end; ++start) {
3902
+ const vnode = vnodes[start];
3903
+ if (isVNode(vnode)) {
3904
+ mount(vnode, parent, renderer, anchor);
3905
+ }
4130
3906
  }
4131
- }
4132
3907
  }
4133
3908
  function unmount(vnode, parent, renderer, doRemove = false) {
4134
- const {
4135
- type,
4136
- elm,
4137
- sel
4138
- } = vnode;
4139
- // When unmounting a VNode subtree not all the elements have to removed from the DOM. The
4140
- // subtree root, is the only element worth unmounting from the subtree.
4141
- if (doRemove) {
4142
- if (type === 5 /* VNodeType.Fragment */) {
4143
- unmountVNodes(vnode.children, parent, renderer, doRemove);
4144
- } else {
4145
- // The vnode might or might not have a data.renderer associated to it
4146
- // but the removal used here is from the owner instead.
4147
- removeNode(elm, parent, renderer);
4148
- }
4149
- }
4150
- switch (type) {
4151
- case 2 /* VNodeType.Element */:
4152
- {
4153
- // Slot content is removed to trigger slotchange event when removing slot.
4154
- // Only required for synthetic shadow.
4155
- const shouldRemoveChildren = sel === 'slot' && vnode.owner.shadowMode === 1 /* ShadowMode.Synthetic */;
4156
- unmountVNodes(vnode.children, elm, renderer, shouldRemoveChildren);
4157
- break;
4158
- }
4159
- case 3 /* VNodeType.CustomElement */:
4160
- {
4161
- const {
4162
- vm
4163
- } = vnode;
4164
- // No need to unmount the children here, `removeVM` will take care of removing the
4165
- // children.
4166
- if (!isUndefined$1(vm)) {
4167
- removeVM(vm);
3909
+ const { type, elm, sel } = vnode;
3910
+ // When unmounting a VNode subtree not all the elements have to removed from the DOM. The
3911
+ // subtree root, is the only element worth unmounting from the subtree.
3912
+ if (doRemove) {
3913
+ if (type === 5 /* VNodeType.Fragment */) {
3914
+ unmountVNodes(vnode.children, parent, renderer, doRemove);
3915
+ }
3916
+ else {
3917
+ // The vnode might or might not have a data.renderer associated to it
3918
+ // but the removal used here is from the owner instead.
3919
+ removeNode(elm, parent, renderer);
4168
3920
  }
4169
- }
4170
- }
3921
+ }
3922
+ switch (type) {
3923
+ case 2 /* VNodeType.Element */: {
3924
+ // Slot content is removed to trigger slotchange event when removing slot.
3925
+ // Only required for synthetic shadow.
3926
+ const shouldRemoveChildren = sel === 'slot' && vnode.owner.shadowMode === 1 /* ShadowMode.Synthetic */;
3927
+ unmountVNodes(vnode.children, elm, renderer, shouldRemoveChildren);
3928
+ break;
3929
+ }
3930
+ case 3 /* VNodeType.CustomElement */: {
3931
+ const { vm } = vnode;
3932
+ // No need to unmount the children here, `removeVM` will take care of removing the
3933
+ // children.
3934
+ if (!isUndefined$1(vm)) {
3935
+ removeVM(vm);
3936
+ }
3937
+ }
3938
+ }
4171
3939
  }
4172
3940
  function unmountVNodes(vnodes, parent, renderer, doRemove = false, start = 0, end = vnodes.length) {
4173
- for (; start < end; ++start) {
4174
- const ch = vnodes[start];
4175
- if (isVNode(ch)) {
4176
- unmount(ch, parent, renderer, doRemove);
3941
+ for (; start < end; ++start) {
3942
+ const ch = vnodes[start];
3943
+ if (isVNode(ch)) {
3944
+ unmount(ch, parent, renderer, doRemove);
3945
+ }
4177
3946
  }
4178
- }
4179
3947
  }
4180
3948
  function isVNode(vnode) {
4181
- return vnode != null;
3949
+ return vnode != null;
4182
3950
  }
4183
3951
  function linkNodeToShadow(elm, owner, renderer) {
4184
- const {
4185
- renderRoot,
4186
- renderMode,
4187
- shadowMode
4188
- } = owner;
4189
- const {
4190
- isSyntheticShadowDefined
4191
- } = renderer;
4192
- // TODO [#1164]: this should eventually be done by the polyfill directly
4193
- if (isSyntheticShadowDefined) {
4194
- if (shadowMode === 1 /* ShadowMode.Synthetic */ || renderMode === 0 /* RenderMode.Light */) {
4195
- elm[KEY__SHADOW_RESOLVER] = renderRoot[KEY__SHADOW_RESOLVER];
3952
+ const { renderRoot, renderMode, shadowMode } = owner;
3953
+ const { isSyntheticShadowDefined } = renderer;
3954
+ // TODO [#1164]: this should eventually be done by the polyfill directly
3955
+ if (isSyntheticShadowDefined) {
3956
+ if (shadowMode === 1 /* ShadowMode.Synthetic */ || renderMode === 0 /* RenderMode.Light */) {
3957
+ elm[KEY__SHADOW_RESOLVER] = renderRoot[KEY__SHADOW_RESOLVER];
3958
+ }
4196
3959
  }
4197
- }
4198
3960
  }
4199
3961
  function updateTextContent(vnode, renderer) {
4200
- const {
4201
- elm,
4202
- text
4203
- } = vnode;
4204
- const {
4205
- setText
4206
- } = renderer;
4207
- if (process.env.NODE_ENV !== 'production') {
4208
- unlockDomMutation();
4209
- }
4210
- setText(elm, text);
4211
- if (process.env.NODE_ENV !== 'production') {
4212
- lockDomMutation();
4213
- }
3962
+ const { elm, text } = vnode;
3963
+ const { setText } = renderer;
3964
+ if (process.env.NODE_ENV !== 'production') {
3965
+ unlockDomMutation();
3966
+ }
3967
+ setText(elm, text);
3968
+ if (process.env.NODE_ENV !== 'production') {
3969
+ lockDomMutation();
3970
+ }
4214
3971
  }
4215
3972
  function insertNode(node, parent, anchor, renderer) {
4216
- if (process.env.NODE_ENV !== 'production') {
4217
- unlockDomMutation();
4218
- }
4219
- renderer.insert(node, parent, anchor);
4220
- if (process.env.NODE_ENV !== 'production') {
4221
- lockDomMutation();
4222
- }
3973
+ if (process.env.NODE_ENV !== 'production') {
3974
+ unlockDomMutation();
3975
+ }
3976
+ renderer.insert(node, parent, anchor);
3977
+ if (process.env.NODE_ENV !== 'production') {
3978
+ lockDomMutation();
3979
+ }
4223
3980
  }
4224
3981
  function removeNode(node, parent, renderer) {
4225
- if (process.env.NODE_ENV !== 'production') {
4226
- unlockDomMutation();
4227
- }
4228
- renderer.remove(node, parent);
4229
- if (process.env.NODE_ENV !== 'production') {
4230
- lockDomMutation();
4231
- }
3982
+ if (process.env.NODE_ENV !== 'production') {
3983
+ unlockDomMutation();
3984
+ }
3985
+ renderer.remove(node, parent);
3986
+ if (process.env.NODE_ENV !== 'production') {
3987
+ lockDomMutation();
3988
+ }
4232
3989
  }
4233
3990
  function patchElementPropsAndAttrs$1(oldVnode, vnode, renderer) {
4234
- if (isNull(oldVnode)) {
4235
- applyEventListeners(vnode, renderer);
4236
- applyStaticClassAttribute(vnode, renderer);
4237
- applyStaticStyleAttribute(vnode, renderer);
4238
- }
4239
- // Attrs need to be applied to element before props IE11 will wipe out value on radio inputs if
4240
- // value is set before type=radio.
4241
- patchClassAttribute(oldVnode, vnode, renderer);
4242
- patchStyleAttribute(oldVnode, vnode, renderer);
4243
- if (vnode.data.external) {
4244
- patchAttrUnlessProp(oldVnode, vnode, renderer);
4245
- } else {
4246
- patchAttributes(oldVnode, vnode, renderer);
4247
- }
4248
- patchProps(oldVnode, vnode, renderer);
3991
+ if (isNull(oldVnode)) {
3992
+ applyEventListeners(vnode, renderer);
3993
+ applyStaticClassAttribute(vnode, renderer);
3994
+ applyStaticStyleAttribute(vnode, renderer);
3995
+ }
3996
+ // Attrs need to be applied to element before props IE11 will wipe out value on radio inputs if
3997
+ // value is set before type=radio.
3998
+ patchClassAttribute(oldVnode, vnode, renderer);
3999
+ patchStyleAttribute(oldVnode, vnode, renderer);
4000
+ if (vnode.data.external) {
4001
+ patchAttrUnlessProp(oldVnode, vnode, renderer);
4002
+ }
4003
+ else {
4004
+ patchAttributes(oldVnode, vnode, renderer);
4005
+ }
4006
+ patchProps(oldVnode, vnode, renderer);
4249
4007
  }
4250
4008
  function applyStyleScoping(elm, owner, renderer) {
4251
- // Set the class name for `*.scoped.css` style scoping.
4252
- const scopeToken = getScopeTokenClass(owner);
4253
- if (!isNull(scopeToken)) {
4254
- const {
4255
- getClassList
4256
- } = renderer;
4257
- // TODO [#2762]: this dot notation with add is probably problematic
4258
- // probably we should have a renderer api for just the add operation
4259
- getClassList(elm).add(scopeToken);
4260
- }
4261
- // Set property element for synthetic shadow DOM style scoping.
4262
- const {
4263
- stylesheetToken: syntheticToken
4264
- } = owner.context;
4265
- if (owner.shadowMode === 1 /* ShadowMode.Synthetic */ && !isUndefined$1(syntheticToken)) {
4266
- elm.$shadowToken$ = syntheticToken;
4267
- }
4009
+ // Set the class name for `*.scoped.css` style scoping.
4010
+ const scopeToken = getScopeTokenClass(owner);
4011
+ if (!isNull(scopeToken)) {
4012
+ const { getClassList } = renderer;
4013
+ // TODO [#2762]: this dot notation with add is probably problematic
4014
+ // probably we should have a renderer api for just the add operation
4015
+ getClassList(elm).add(scopeToken);
4016
+ }
4017
+ // Set property element for synthetic shadow DOM style scoping.
4018
+ const { stylesheetToken: syntheticToken } = owner.context;
4019
+ if (owner.shadowMode === 1 /* ShadowMode.Synthetic */ && !isUndefined$1(syntheticToken)) {
4020
+ elm.$shadowToken$ = syntheticToken;
4021
+ }
4268
4022
  }
4269
4023
  function applyDomManual(elm, vnode) {
4270
- var _a;
4271
- const {
4272
- owner,
4273
- data: {
4274
- context
4024
+ var _a;
4025
+ const { owner, data: { context }, } = vnode;
4026
+ if (owner.shadowMode === 1 /* ShadowMode.Synthetic */ && ((_a = context === null || context === void 0 ? void 0 : context.lwc) === null || _a === void 0 ? void 0 : _a.dom) === "manual" /* LwcDomMode.Manual */) {
4027
+ elm.$domManual$ = true;
4275
4028
  }
4276
- } = vnode;
4277
- if (owner.shadowMode === 1 /* ShadowMode.Synthetic */ && ((_a = context === null || context === void 0 ? void 0 : context.lwc) === null || _a === void 0 ? void 0 : _a.dom) === "manual" /* LwcDomMode.Manual */) {
4278
- elm.$domManual$ = true;
4279
- }
4280
4029
  }
4281
4030
  function applyElementRestrictions(elm, vnode) {
4282
- var _a, _b;
4283
- if (process.env.NODE_ENV !== 'production') {
4284
- const isSynthetic = vnode.owner.shadowMode === 1 /* ShadowMode.Synthetic */;
4285
- const isPortal = vnode.type === 2 /* VNodeType.Element */ && ((_b = (_a = vnode.data.context) === null || _a === void 0 ? void 0 : _a.lwc) === null || _b === void 0 ? void 0 : _b.dom) === "manual" /* LwcDomMode.Manual */;
4286
- const isLight = vnode.owner.renderMode === 0 /* RenderMode.Light */;
4287
- patchElementWithRestrictions(elm, {
4288
- isPortal,
4289
- isLight,
4290
- isSynthetic
4291
- });
4292
- }
4031
+ var _a, _b;
4032
+ if (process.env.NODE_ENV !== 'production') {
4033
+ const isSynthetic = vnode.owner.shadowMode === 1 /* ShadowMode.Synthetic */;
4034
+ const isPortal = vnode.type === 2 /* VNodeType.Element */ && ((_b = (_a = vnode.data.context) === null || _a === void 0 ? void 0 : _a.lwc) === null || _b === void 0 ? void 0 : _b.dom) === "manual" /* LwcDomMode.Manual */;
4035
+ const isLight = vnode.owner.renderMode === 0 /* RenderMode.Light */;
4036
+ patchElementWithRestrictions(elm, {
4037
+ isPortal,
4038
+ isLight,
4039
+ isSynthetic,
4040
+ });
4041
+ }
4293
4042
  }
4294
4043
  function allocateChildren(vnode, vm) {
4295
- // A component with slots will re-render because:
4296
- // 1- There is a change of the internal state.
4297
- // 2- There is a change on the external api (ex: slots)
4298
- //
4299
- // In case #1, the vnodes in the cmpSlots will be reused since they didn't changed. This routine emptied the
4300
- // slotted children when those VCustomElement were rendered and therefore in subsequent calls to allocate children
4301
- // in a reused VCustomElement, there won't be any slotted children.
4302
- // For those cases, we will use the reference for allocated children stored when rendering the fresh VCustomElement.
4303
- //
4304
- // In case #2, we will always get a fresh VCustomElement.
4305
- const children = vnode.aChildren || vnode.children;
4306
- const {
4307
- renderMode,
4308
- shadowMode
4309
- } = vm;
4310
- if (process.env.NODE_ENV !== 'production') {
4311
- // If any of the children being allocated is a scoped slot fragment, make sure the receiving
4312
- // component is a light DOM component. This is mainly to validate light dom parent running
4313
- // in native shadow mode.
4314
- if (renderMode !== 0 /* RenderMode.Light */ && ArraySome.call(children, child => !isNull(child) && isVScopedSlotFragment(child))) {
4315
- logError(`Invalid usage of 'lwc:slot-data' on ${getComponentTag(vm)} tag. Scoped slot content can only be passed to a light dom child.`);
4316
- }
4317
- }
4318
- // If any of the children being allocated are VFragments, we remove the text delimiters and flatten all immediate
4319
- // children VFragments to avoid them interfering with default slot behavior.
4320
- const allocatedChildren = flattenFragmentsInChildren(children);
4321
- vnode.children = allocatedChildren;
4322
- vm.aChildren = allocatedChildren;
4323
- if (shadowMode === 1 /* ShadowMode.Synthetic */ || renderMode === 0 /* RenderMode.Light */) {
4324
- // slow path
4325
- allocateInSlot(vm, allocatedChildren, vnode.owner);
4326
- // save the allocated children in case this vnode is reused.
4327
- vnode.aChildren = allocatedChildren;
4328
- // every child vnode is now allocated, and the host should receive none directly, it receives them via the shadow!
4329
- vnode.children = EmptyArray;
4330
- }
4044
+ // A component with slots will re-render because:
4045
+ // 1- There is a change of the internal state.
4046
+ // 2- There is a change on the external api (ex: slots)
4047
+ //
4048
+ // In case #1, the vnodes in the cmpSlots will be reused since they didn't changed. This routine emptied the
4049
+ // slotted children when those VCustomElement were rendered and therefore in subsequent calls to allocate children
4050
+ // in a reused VCustomElement, there won't be any slotted children.
4051
+ // For those cases, we will use the reference for allocated children stored when rendering the fresh VCustomElement.
4052
+ //
4053
+ // In case #2, we will always get a fresh VCustomElement.
4054
+ const children = vnode.aChildren || vnode.children;
4055
+ const { renderMode, shadowMode } = vm;
4056
+ if (process.env.NODE_ENV !== 'production') {
4057
+ // If any of the children being allocated is a scoped slot fragment, make sure the receiving
4058
+ // component is a light DOM component. This is mainly to validate light dom parent running
4059
+ // in native shadow mode.
4060
+ if (renderMode !== 0 /* RenderMode.Light */ &&
4061
+ ArraySome.call(children, (child) => !isNull(child) && isVScopedSlotFragment(child))) {
4062
+ logError(`Invalid usage of 'lwc:slot-data' on ${getComponentTag(vm)} tag. Scoped slot content can only be passed to a light dom child.`);
4063
+ }
4064
+ }
4065
+ // If any of the children being allocated are VFragments, we remove the text delimiters and flatten all immediate
4066
+ // children VFragments to avoid them interfering with default slot behavior.
4067
+ const allocatedChildren = flattenFragmentsInChildren(children);
4068
+ vnode.children = allocatedChildren;
4069
+ vm.aChildren = allocatedChildren;
4070
+ if (shadowMode === 1 /* ShadowMode.Synthetic */ || renderMode === 0 /* RenderMode.Light */) {
4071
+ // slow path
4072
+ allocateInSlot(vm, allocatedChildren, vnode.owner);
4073
+ // save the allocated children in case this vnode is reused.
4074
+ vnode.aChildren = allocatedChildren;
4075
+ // every child vnode is now allocated, and the host should receive none directly, it receives them via the shadow!
4076
+ vnode.children = EmptyArray;
4077
+ }
4331
4078
  }
4332
4079
  /**
4333
4080
  * Flattens the contents of all VFragments in an array of VNodes, removes the text delimiters on those VFragments, and
@@ -4339,275 +4086,278 @@ function allocateChildren(vnode, vm) {
4339
4086
  * This function is used for slotted VFragments to avoid the text delimiters interfering with slotting functionality.
4340
4087
  */
4341
4088
  function flattenFragmentsInChildren(children) {
4342
- const flattenedChildren = [];
4343
- // Initialize our stack with the direct children of the custom component and check whether we have a VFragment.
4344
- // If no VFragment is found in children, we don't need to traverse anything or mark the children dynamic and can return early.
4345
- const nodeStack = [];
4346
- let fragmentFound = false;
4347
- for (let i = children.length - 1; i > -1; i -= 1) {
4348
- const child = children[i];
4349
- ArrayPush$1.call(nodeStack, child);
4350
- fragmentFound = fragmentFound || !!(child && isVFragment(child));
4351
- }
4352
- if (!fragmentFound) {
4353
- return children;
4354
- }
4355
- let currentNode;
4356
- while (!isUndefined$1(currentNode = ArrayPop.call(nodeStack))) {
4357
- if (!isNull(currentNode) && isVFragment(currentNode)) {
4358
- const fChildren = currentNode.children;
4359
- // Ignore the start and end text node delimiters
4360
- for (let i = fChildren.length - 2; i > 0; i -= 1) {
4361
- ArrayPush$1.call(nodeStack, fChildren[i]);
4362
- }
4363
- } else {
4364
- ArrayPush$1.call(flattenedChildren, currentNode);
4365
- }
4366
- }
4367
- // We always mark the children as dynamic because nothing generates stable VFragments yet.
4368
- // If/when stable VFragments are generated by the compiler, this code should be updated to
4369
- // not mark dynamic if all flattened VFragments were stable.
4370
- markAsDynamicChildren(flattenedChildren);
4371
- return flattenedChildren;
4089
+ const flattenedChildren = [];
4090
+ // Initialize our stack with the direct children of the custom component and check whether we have a VFragment.
4091
+ // If no VFragment is found in children, we don't need to traverse anything or mark the children dynamic and can return early.
4092
+ const nodeStack = [];
4093
+ let fragmentFound = false;
4094
+ for (let i = children.length - 1; i > -1; i -= 1) {
4095
+ const child = children[i];
4096
+ ArrayPush$1.call(nodeStack, child);
4097
+ fragmentFound = fragmentFound || !!(child && isVFragment(child));
4098
+ }
4099
+ if (!fragmentFound) {
4100
+ return children;
4101
+ }
4102
+ let currentNode;
4103
+ while (!isUndefined$1((currentNode = ArrayPop.call(nodeStack)))) {
4104
+ if (!isNull(currentNode) && isVFragment(currentNode)) {
4105
+ const fChildren = currentNode.children;
4106
+ // Ignore the start and end text node delimiters
4107
+ for (let i = fChildren.length - 2; i > 0; i -= 1) {
4108
+ ArrayPush$1.call(nodeStack, fChildren[i]);
4109
+ }
4110
+ }
4111
+ else {
4112
+ ArrayPush$1.call(flattenedChildren, currentNode);
4113
+ }
4114
+ }
4115
+ // We always mark the children as dynamic because nothing generates stable VFragments yet.
4116
+ // If/when stable VFragments are generated by the compiler, this code should be updated to
4117
+ // not mark dynamic if all flattened VFragments were stable.
4118
+ markAsDynamicChildren(flattenedChildren);
4119
+ return flattenedChildren;
4372
4120
  }
4373
4121
  function createViewModelHook(elm, vnode, renderer) {
4374
- let vm = getAssociatedVMIfPresent(elm);
4375
- // There is a possibility that a custom element is registered under tagName, in which case, the
4376
- // initialization is already carry on, and there is nothing else to do here since this hook is
4377
- // called right after invoking `document.createElement`.
4378
- if (!isUndefined$1(vm)) {
4122
+ let vm = getAssociatedVMIfPresent(elm);
4123
+ // There is a possibility that a custom element is registered under tagName, in which case, the
4124
+ // initialization is already carry on, and there is nothing else to do here since this hook is
4125
+ // called right after invoking `document.createElement`.
4126
+ if (!isUndefined$1(vm)) {
4127
+ return vm;
4128
+ }
4129
+ const { sel, mode, ctor, owner } = vnode;
4130
+ vm = createVM(elm, ctor, renderer, {
4131
+ mode,
4132
+ owner,
4133
+ tagName: sel,
4134
+ });
4135
+ if (process.env.NODE_ENV !== 'production') {
4136
+ assert.isTrue(isArray$1(vnode.children), `Invalid vnode for a custom element, it must have children defined.`);
4137
+ }
4379
4138
  return vm;
4380
- }
4381
- const {
4382
- sel,
4383
- mode,
4384
- ctor,
4385
- owner
4386
- } = vnode;
4387
- vm = createVM(elm, ctor, renderer, {
4388
- mode,
4389
- owner,
4390
- tagName: sel
4391
- });
4392
- if (process.env.NODE_ENV !== 'production') {
4393
- assert.isTrue(isArray$1(vnode.children), `Invalid vnode for a custom element, it must have children defined.`);
4394
- }
4395
- return vm;
4396
4139
  }
4397
4140
  function allocateInSlot(vm, children, owner) {
4398
- var _a, _b;
4399
- const {
4400
- cmpSlots: {
4401
- slotAssignments: oldSlotsMapping
4402
- }
4403
- } = vm;
4404
- const cmpSlotsMapping = create(null);
4405
- // Collect all slots into cmpSlotsMapping
4406
- for (let i = 0, len = children.length; i < len; i += 1) {
4407
- const vnode = children[i];
4408
- if (isNull(vnode)) {
4409
- continue;
4410
- }
4411
- let slotName = '';
4412
- if (isVBaseElement(vnode)) {
4413
- slotName = (_b = (_a = vnode.data.attrs) === null || _a === void 0 ? void 0 : _a.slot) !== null && _b !== void 0 ? _b : '';
4414
- } else if (isVScopedSlotFragment(vnode)) {
4415
- slotName = vnode.slotName;
4416
- }
4417
- // Can't use toString here because Symbol(1).toString() is 'Symbol(1)'
4418
- // but elm.setAttribute('slot', Symbol(1)) is an error.
4419
- // the following line also throws same error for symbols
4420
- // Similar for Object.create(null)
4421
- const normalizedSlotName = '' + slotName;
4422
- const vnodes = cmpSlotsMapping[normalizedSlotName] = cmpSlotsMapping[normalizedSlotName] || [];
4423
- ArrayPush$1.call(vnodes, vnode);
4424
- }
4425
- vm.cmpSlots = {
4426
- owner,
4427
- slotAssignments: cmpSlotsMapping
4428
- };
4429
- if (isFalse(vm.isDirty)) {
4430
- // We need to determine if the old allocation is really different from the new one
4431
- // and mark the vm as dirty
4432
- const oldKeys = keys(oldSlotsMapping);
4433
- if (oldKeys.length !== keys(cmpSlotsMapping).length) {
4434
- markComponentAsDirty(vm);
4435
- return;
4436
- }
4437
- for (let i = 0, len = oldKeys.length; i < len; i += 1) {
4438
- const key = oldKeys[i];
4439
- if (isUndefined$1(cmpSlotsMapping[key]) || oldSlotsMapping[key].length !== cmpSlotsMapping[key].length) {
4440
- markComponentAsDirty(vm);
4441
- return;
4442
- }
4443
- const oldVNodes = oldSlotsMapping[key];
4444
- const vnodes = cmpSlotsMapping[key];
4445
- for (let j = 0, a = cmpSlotsMapping[key].length; j < a; j += 1) {
4446
- if (oldVNodes[j] !== vnodes[j]) {
4447
- markComponentAsDirty(vm);
4448
- return;
4141
+ var _a, _b;
4142
+ const { cmpSlots: { slotAssignments: oldSlotsMapping }, } = vm;
4143
+ const cmpSlotsMapping = create(null);
4144
+ // Collect all slots into cmpSlotsMapping
4145
+ for (let i = 0, len = children.length; i < len; i += 1) {
4146
+ const vnode = children[i];
4147
+ if (isNull(vnode)) {
4148
+ continue;
4149
+ }
4150
+ let slotName = '';
4151
+ if (isVBaseElement(vnode)) {
4152
+ slotName = (_b = (_a = vnode.data.attrs) === null || _a === void 0 ? void 0 : _a.slot) !== null && _b !== void 0 ? _b : '';
4153
+ }
4154
+ else if (isVScopedSlotFragment(vnode)) {
4155
+ slotName = vnode.slotName;
4156
+ }
4157
+ // Can't use toString here because Symbol(1).toString() is 'Symbol(1)'
4158
+ // but elm.setAttribute('slot', Symbol(1)) is an error.
4159
+ // the following line also throws same error for symbols
4160
+ // Similar for Object.create(null)
4161
+ const normalizedSlotName = '' + slotName;
4162
+ const vnodes = (cmpSlotsMapping[normalizedSlotName] =
4163
+ cmpSlotsMapping[normalizedSlotName] || []);
4164
+ ArrayPush$1.call(vnodes, vnode);
4165
+ }
4166
+ vm.cmpSlots = { owner, slotAssignments: cmpSlotsMapping };
4167
+ if (isFalse(vm.isDirty)) {
4168
+ // We need to determine if the old allocation is really different from the new one
4169
+ // and mark the vm as dirty
4170
+ const oldKeys = keys(oldSlotsMapping);
4171
+ if (oldKeys.length !== keys(cmpSlotsMapping).length) {
4172
+ markComponentAsDirty(vm);
4173
+ return;
4174
+ }
4175
+ for (let i = 0, len = oldKeys.length; i < len; i += 1) {
4176
+ const key = oldKeys[i];
4177
+ if (isUndefined$1(cmpSlotsMapping[key]) ||
4178
+ oldSlotsMapping[key].length !== cmpSlotsMapping[key].length) {
4179
+ markComponentAsDirty(vm);
4180
+ return;
4181
+ }
4182
+ const oldVNodes = oldSlotsMapping[key];
4183
+ const vnodes = cmpSlotsMapping[key];
4184
+ for (let j = 0, a = cmpSlotsMapping[key].length; j < a; j += 1) {
4185
+ if (oldVNodes[j] !== vnodes[j]) {
4186
+ markComponentAsDirty(vm);
4187
+ return;
4188
+ }
4189
+ }
4449
4190
  }
4450
- }
4451
4191
  }
4452
- }
4453
4192
  }
4454
4193
  // Using a WeakMap instead of a WeakSet because this one works in IE11 :(
4455
4194
  const DynamicChildren = new WeakMap();
4456
4195
  // dynamic children means it was either generated by an iteration in a template
4457
4196
  // or part of an unstable fragment, and will require a more complex diffing algo.
4458
4197
  function markAsDynamicChildren(children) {
4459
- DynamicChildren.set(children, 1);
4198
+ DynamicChildren.set(children, 1);
4460
4199
  }
4461
4200
  function hasDynamicChildren(children) {
4462
- return DynamicChildren.has(children);
4201
+ return DynamicChildren.has(children);
4463
4202
  }
4464
4203
  function createKeyToOldIdx(children, beginIdx, endIdx) {
4465
- const map = {};
4466
- // TODO [#1637]: simplify this by assuming that all vnodes has keys
4467
- for (let j = beginIdx; j <= endIdx; ++j) {
4468
- const ch = children[j];
4469
- if (isVNode(ch)) {
4470
- const {
4471
- key
4472
- } = ch;
4473
- if (key !== undefined) {
4474
- map[key] = j;
4475
- }
4476
- }
4477
- }
4478
- return map;
4204
+ const map = {};
4205
+ // TODO [#1637]: simplify this by assuming that all vnodes has keys
4206
+ for (let j = beginIdx; j <= endIdx; ++j) {
4207
+ const ch = children[j];
4208
+ if (isVNode(ch)) {
4209
+ const { key } = ch;
4210
+ if (key !== undefined) {
4211
+ map[key] = j;
4212
+ }
4213
+ }
4214
+ }
4215
+ return map;
4479
4216
  }
4480
4217
  function updateDynamicChildren(oldCh, newCh, parent, renderer) {
4481
- let oldStartIdx = 0;
4482
- let newStartIdx = 0;
4483
- let oldEndIdx = oldCh.length - 1;
4484
- let oldStartVnode = oldCh[0];
4485
- let oldEndVnode = oldCh[oldEndIdx];
4486
- const newChEnd = newCh.length - 1;
4487
- let newEndIdx = newChEnd;
4488
- let newStartVnode = newCh[0];
4489
- let newEndVnode = newCh[newEndIdx];
4490
- let oldKeyToIdx;
4491
- let idxInOld;
4492
- let elmToMove;
4493
- let before;
4494
- let clonedOldCh = false;
4495
- while (oldStartIdx <= oldEndIdx && newStartIdx <= newEndIdx) {
4496
- if (!isVNode(oldStartVnode)) {
4497
- oldStartVnode = oldCh[++oldStartIdx]; // Vnode might have been moved left
4498
- } else if (!isVNode(oldEndVnode)) {
4499
- oldEndVnode = oldCh[--oldEndIdx];
4500
- } else if (!isVNode(newStartVnode)) {
4501
- newStartVnode = newCh[++newStartIdx];
4502
- } else if (!isVNode(newEndVnode)) {
4503
- newEndVnode = newCh[--newEndIdx];
4504
- } else if (isSameVnode(oldStartVnode, newStartVnode)) {
4505
- patch(oldStartVnode, newStartVnode, parent, renderer);
4506
- oldStartVnode = oldCh[++oldStartIdx];
4507
- newStartVnode = newCh[++newStartIdx];
4508
- } else if (isSameVnode(oldEndVnode, newEndVnode)) {
4509
- patch(oldEndVnode, newEndVnode, parent, renderer);
4510
- oldEndVnode = oldCh[--oldEndIdx];
4511
- newEndVnode = newCh[--newEndIdx];
4512
- } else if (isSameVnode(oldStartVnode, newEndVnode)) {
4513
- // Vnode moved right
4514
- patch(oldStartVnode, newEndVnode, parent, renderer);
4515
- insertNode(oldStartVnode.elm, parent, renderer.nextSibling(oldEndVnode.elm), renderer);
4516
- oldStartVnode = oldCh[++oldStartIdx];
4517
- newEndVnode = newCh[--newEndIdx];
4518
- } else if (isSameVnode(oldEndVnode, newStartVnode)) {
4519
- // Vnode moved left
4520
- patch(oldEndVnode, newStartVnode, parent, renderer);
4521
- insertNode(newStartVnode.elm, parent, oldStartVnode.elm, renderer);
4522
- oldEndVnode = oldCh[--oldEndIdx];
4523
- newStartVnode = newCh[++newStartIdx];
4524
- } else {
4525
- if (oldKeyToIdx === undefined) {
4526
- oldKeyToIdx = createKeyToOldIdx(oldCh, oldStartIdx, oldEndIdx);
4527
- }
4528
- idxInOld = oldKeyToIdx[newStartVnode.key];
4529
- if (isUndefined$1(idxInOld)) {
4530
- // New element
4531
- mount(newStartVnode, parent, renderer, oldStartVnode.elm);
4532
- newStartVnode = newCh[++newStartIdx];
4533
- } else {
4534
- elmToMove = oldCh[idxInOld];
4535
- if (isVNode(elmToMove)) {
4536
- if (elmToMove.sel !== newStartVnode.sel) {
4537
- // New element
4538
- mount(newStartVnode, parent, renderer, oldStartVnode.elm);
4539
- } else {
4540
- patch(elmToMove, newStartVnode, parent, renderer);
4541
- // Delete the old child, but copy the array since it is read-only.
4542
- // The `oldCh` will be GC'ed after `updateDynamicChildren` is complete,
4543
- // so we only care about the `oldCh` object inside this function.
4544
- // To avoid cloning over and over again, we check `clonedOldCh`
4545
- // and only clone once.
4546
- if (!clonedOldCh) {
4547
- clonedOldCh = true;
4548
- oldCh = [...oldCh];
4218
+ let oldStartIdx = 0;
4219
+ let newStartIdx = 0;
4220
+ let oldEndIdx = oldCh.length - 1;
4221
+ let oldStartVnode = oldCh[0];
4222
+ let oldEndVnode = oldCh[oldEndIdx];
4223
+ const newChEnd = newCh.length - 1;
4224
+ let newEndIdx = newChEnd;
4225
+ let newStartVnode = newCh[0];
4226
+ let newEndVnode = newCh[newEndIdx];
4227
+ let oldKeyToIdx;
4228
+ let idxInOld;
4229
+ let elmToMove;
4230
+ let before;
4231
+ let clonedOldCh = false;
4232
+ while (oldStartIdx <= oldEndIdx && newStartIdx <= newEndIdx) {
4233
+ if (!isVNode(oldStartVnode)) {
4234
+ oldStartVnode = oldCh[++oldStartIdx]; // Vnode might have been moved left
4235
+ }
4236
+ else if (!isVNode(oldEndVnode)) {
4237
+ oldEndVnode = oldCh[--oldEndIdx];
4238
+ }
4239
+ else if (!isVNode(newStartVnode)) {
4240
+ newStartVnode = newCh[++newStartIdx];
4241
+ }
4242
+ else if (!isVNode(newEndVnode)) {
4243
+ newEndVnode = newCh[--newEndIdx];
4244
+ }
4245
+ else if (isSameVnode(oldStartVnode, newStartVnode)) {
4246
+ patch(oldStartVnode, newStartVnode, parent, renderer);
4247
+ oldStartVnode = oldCh[++oldStartIdx];
4248
+ newStartVnode = newCh[++newStartIdx];
4249
+ }
4250
+ else if (isSameVnode(oldEndVnode, newEndVnode)) {
4251
+ patch(oldEndVnode, newEndVnode, parent, renderer);
4252
+ oldEndVnode = oldCh[--oldEndIdx];
4253
+ newEndVnode = newCh[--newEndIdx];
4254
+ }
4255
+ else if (isSameVnode(oldStartVnode, newEndVnode)) {
4256
+ // Vnode moved right
4257
+ patch(oldStartVnode, newEndVnode, parent, renderer);
4258
+ insertNode(oldStartVnode.elm, parent, renderer.nextSibling(oldEndVnode.elm), renderer);
4259
+ oldStartVnode = oldCh[++oldStartIdx];
4260
+ newEndVnode = newCh[--newEndIdx];
4261
+ }
4262
+ else if (isSameVnode(oldEndVnode, newStartVnode)) {
4263
+ // Vnode moved left
4264
+ patch(oldEndVnode, newStartVnode, parent, renderer);
4265
+ insertNode(newStartVnode.elm, parent, oldStartVnode.elm, renderer);
4266
+ oldEndVnode = oldCh[--oldEndIdx];
4267
+ newStartVnode = newCh[++newStartIdx];
4268
+ }
4269
+ else {
4270
+ if (oldKeyToIdx === undefined) {
4271
+ oldKeyToIdx = createKeyToOldIdx(oldCh, oldStartIdx, oldEndIdx);
4549
4272
  }
4550
- // We've already cloned at least once, so it's no longer read-only
4551
- oldCh[idxInOld] = undefined;
4552
- insertNode(elmToMove.elm, parent, oldStartVnode.elm, renderer);
4553
- }
4554
- }
4555
- newStartVnode = newCh[++newStartIdx];
4556
- }
4557
- }
4558
- }
4559
- if (oldStartIdx <= oldEndIdx || newStartIdx <= newEndIdx) {
4560
- if (oldStartIdx > oldEndIdx) {
4561
- // There's some cases in which the sub array of vnodes to be inserted is followed by null(s) and an
4562
- // already processed vnode, in such cases the vnodes to be inserted should be before that processed vnode.
4563
- let i = newEndIdx;
4564
- let n;
4565
- do {
4566
- n = newCh[++i];
4567
- } while (!isVNode(n) && i < newChEnd);
4568
- before = isVNode(n) ? n.elm : null;
4569
- mountVNodes(newCh, parent, renderer, before, newStartIdx, newEndIdx + 1);
4570
- } else {
4571
- unmountVNodes(oldCh, parent, renderer, true, oldStartIdx, oldEndIdx + 1);
4572
- }
4573
- }
4273
+ idxInOld = oldKeyToIdx[newStartVnode.key];
4274
+ if (isUndefined$1(idxInOld)) {
4275
+ // New element
4276
+ mount(newStartVnode, parent, renderer, oldStartVnode.elm);
4277
+ newStartVnode = newCh[++newStartIdx];
4278
+ }
4279
+ else {
4280
+ elmToMove = oldCh[idxInOld];
4281
+ if (isVNode(elmToMove)) {
4282
+ if (elmToMove.sel !== newStartVnode.sel) {
4283
+ // New element
4284
+ mount(newStartVnode, parent, renderer, oldStartVnode.elm);
4285
+ }
4286
+ else {
4287
+ patch(elmToMove, newStartVnode, parent, renderer);
4288
+ // Delete the old child, but copy the array since it is read-only.
4289
+ // The `oldCh` will be GC'ed after `updateDynamicChildren` is complete,
4290
+ // so we only care about the `oldCh` object inside this function.
4291
+ // To avoid cloning over and over again, we check `clonedOldCh`
4292
+ // and only clone once.
4293
+ if (!clonedOldCh) {
4294
+ clonedOldCh = true;
4295
+ oldCh = [...oldCh];
4296
+ }
4297
+ // We've already cloned at least once, so it's no longer read-only
4298
+ oldCh[idxInOld] = undefined;
4299
+ insertNode(elmToMove.elm, parent, oldStartVnode.elm, renderer);
4300
+ }
4301
+ }
4302
+ newStartVnode = newCh[++newStartIdx];
4303
+ }
4304
+ }
4305
+ }
4306
+ if (oldStartIdx <= oldEndIdx || newStartIdx <= newEndIdx) {
4307
+ if (oldStartIdx > oldEndIdx) {
4308
+ // There's some cases in which the sub array of vnodes to be inserted is followed by null(s) and an
4309
+ // already processed vnode, in such cases the vnodes to be inserted should be before that processed vnode.
4310
+ let i = newEndIdx;
4311
+ let n;
4312
+ do {
4313
+ n = newCh[++i];
4314
+ } while (!isVNode(n) && i < newChEnd);
4315
+ before = isVNode(n) ? n.elm : null;
4316
+ mountVNodes(newCh, parent, renderer, before, newStartIdx, newEndIdx + 1);
4317
+ }
4318
+ else {
4319
+ unmountVNodes(oldCh, parent, renderer, true, oldStartIdx, oldEndIdx + 1);
4320
+ }
4321
+ }
4574
4322
  }
4575
4323
  function updateStaticChildren(c1, c2, parent, renderer) {
4576
- const c1Length = c1.length;
4577
- const c2Length = c2.length;
4578
- if (c1Length === 0) {
4579
- // the old list is empty, we can directly insert anything new
4580
- mountVNodes(c2, parent, renderer, null);
4581
- return;
4582
- }
4583
- if (c2Length === 0) {
4584
- // the old list is nonempty and the new list is empty so we can directly remove all old nodes
4585
- // this is the case in which the dynamic children of an if-directive should be removed
4586
- unmountVNodes(c1, parent, renderer, true);
4587
- return;
4588
- }
4589
- // if the old list is not empty, the new list MUST have the same
4590
- // amount of nodes, that's why we call this static children
4591
- let anchor = null;
4592
- for (let i = c2Length - 1; i >= 0; i -= 1) {
4593
- const n1 = c1[i];
4594
- const n2 = c2[i];
4595
- if (n2 !== n1) {
4596
- if (isVNode(n1)) {
4597
- if (isVNode(n2)) {
4598
- // both vnodes are equivalent, and we just need to patch them
4599
- patch(n1, n2, parent, renderer);
4600
- anchor = n2.elm;
4601
- } else {
4602
- // removing the old vnode since the new one is null
4603
- unmount(n1, parent, renderer, true);
4604
- }
4605
- } else if (isVNode(n2)) {
4606
- mount(n2, parent, renderer, anchor);
4607
- anchor = n2.elm;
4608
- }
4609
- }
4610
- }
4324
+ const c1Length = c1.length;
4325
+ const c2Length = c2.length;
4326
+ if (c1Length === 0) {
4327
+ // the old list is empty, we can directly insert anything new
4328
+ mountVNodes(c2, parent, renderer, null);
4329
+ return;
4330
+ }
4331
+ if (c2Length === 0) {
4332
+ // the old list is nonempty and the new list is empty so we can directly remove all old nodes
4333
+ // this is the case in which the dynamic children of an if-directive should be removed
4334
+ unmountVNodes(c1, parent, renderer, true);
4335
+ return;
4336
+ }
4337
+ // if the old list is not empty, the new list MUST have the same
4338
+ // amount of nodes, that's why we call this static children
4339
+ let anchor = null;
4340
+ for (let i = c2Length - 1; i >= 0; i -= 1) {
4341
+ const n1 = c1[i];
4342
+ const n2 = c2[i];
4343
+ if (n2 !== n1) {
4344
+ if (isVNode(n1)) {
4345
+ if (isVNode(n2)) {
4346
+ // both vnodes are equivalent, and we just need to patch them
4347
+ patch(n1, n2, parent, renderer);
4348
+ anchor = n2.elm;
4349
+ }
4350
+ else {
4351
+ // removing the old vnode since the new one is null
4352
+ unmount(n1, parent, renderer, true);
4353
+ }
4354
+ }
4355
+ else if (isVNode(n2)) {
4356
+ mount(n2, parent, renderer, anchor);
4357
+ anchor = n2.elm;
4358
+ }
4359
+ }
4360
+ }
4611
4361
  }
4612
4362
 
4613
4363
  /*
@@ -5589,455 +5339,417 @@ let idx = 0;
5589
5339
  /** The internal slot used to associate different objects the engine manipulates with the VM */
5590
5340
  const ViewModelReflection = new WeakMap();
5591
5341
  function callHook(cmp, fn, args = []) {
5592
- return fn.apply(cmp, args);
5342
+ return fn.apply(cmp, args);
5593
5343
  }
5594
5344
  function setHook(cmp, prop, newValue) {
5595
- cmp[prop] = newValue;
5345
+ cmp[prop] = newValue;
5596
5346
  }
5597
5347
  function getHook(cmp, prop) {
5598
- return cmp[prop];
5348
+ return cmp[prop];
5599
5349
  }
5600
5350
  function rerenderVM(vm) {
5601
- rehydrate(vm);
5351
+ rehydrate(vm);
5602
5352
  }
5603
5353
  function connectRootElement(elm) {
5604
- const vm = getAssociatedVM(elm);
5605
- logGlobalOperationStart(7 /* OperationId.GlobalHydrate */, vm);
5606
- // Usually means moving the element from one place to another, which is observable via
5607
- // life-cycle hooks.
5608
- if (vm.state === 1 /* VMState.connected */) {
5609
- disconnectRootElement(elm);
5610
- }
5611
- runConnectedCallback(vm);
5612
- rehydrate(vm);
5613
- logGlobalOperationEnd(7 /* OperationId.GlobalHydrate */, vm);
5354
+ const vm = getAssociatedVM(elm);
5355
+ logGlobalOperationStart(7 /* OperationId.GlobalHydrate */, vm);
5356
+ // Usually means moving the element from one place to another, which is observable via
5357
+ // life-cycle hooks.
5358
+ if (vm.state === 1 /* VMState.connected */) {
5359
+ disconnectRootElement(elm);
5360
+ }
5361
+ runConnectedCallback(vm);
5362
+ rehydrate(vm);
5363
+ logGlobalOperationEnd(7 /* OperationId.GlobalHydrate */, vm);
5614
5364
  }
5615
5365
  function disconnectRootElement(elm) {
5616
- const vm = getAssociatedVM(elm);
5617
- resetComponentStateWhenRemoved(vm);
5366
+ const vm = getAssociatedVM(elm);
5367
+ resetComponentStateWhenRemoved(vm);
5618
5368
  }
5619
5369
  function appendVM(vm) {
5620
- rehydrate(vm);
5370
+ rehydrate(vm);
5621
5371
  }
5622
5372
  // just in case the component comes back, with this we guarantee re-rendering it
5623
5373
  // while preventing any attempt to rehydration until after reinsertion.
5624
5374
  function resetComponentStateWhenRemoved(vm) {
5625
- const {
5626
- state
5627
- } = vm;
5628
- if (state !== 2 /* VMState.disconnected */) {
5629
- const {
5630
- tro
5631
- } = vm;
5632
- // Making sure that any observing record will not trigger the rehydrated on this vm
5633
- tro.reset();
5634
- runDisconnectedCallback(vm);
5635
- // Spec: https://dom.spec.whatwg.org/#concept-node-remove (step 14-15)
5636
- runChildNodesDisconnectedCallback(vm);
5637
- runLightChildNodesDisconnectedCallback(vm);
5638
- }
5639
- if (process.env.NODE_ENV !== 'production') {
5640
- removeActiveVM(vm);
5641
- }
5375
+ const { state } = vm;
5376
+ if (state !== 2 /* VMState.disconnected */) {
5377
+ const { tro } = vm;
5378
+ // Making sure that any observing record will not trigger the rehydrated on this vm
5379
+ tro.reset();
5380
+ runDisconnectedCallback(vm);
5381
+ // Spec: https://dom.spec.whatwg.org/#concept-node-remove (step 14-15)
5382
+ runChildNodesDisconnectedCallback(vm);
5383
+ runLightChildNodesDisconnectedCallback(vm);
5384
+ }
5385
+ if (process.env.NODE_ENV !== 'production') {
5386
+ removeActiveVM(vm);
5387
+ }
5642
5388
  }
5643
5389
  // this method is triggered by the diffing algo only when a vnode from the
5644
5390
  // old vnode.children is removed from the DOM.
5645
5391
  function removeVM(vm) {
5646
- if (process.env.NODE_ENV !== 'production') {
5647
- assert.isTrue(vm.state === 1 /* VMState.connected */ || vm.state === 2 /* VMState.disconnected */, `${vm} must have been connected.`);
5648
- }
5649
- resetComponentStateWhenRemoved(vm);
5392
+ if (process.env.NODE_ENV !== 'production') {
5393
+ assert.isTrue(vm.state === 1 /* VMState.connected */ || vm.state === 2 /* VMState.disconnected */, `${vm} must have been connected.`);
5394
+ }
5395
+ resetComponentStateWhenRemoved(vm);
5650
5396
  }
5651
5397
  function getNearestShadowAncestor(vm) {
5652
- let ancestor = vm.owner;
5653
- while (!isNull(ancestor) && ancestor.renderMode === 0 /* RenderMode.Light */) {
5654
- ancestor = ancestor.owner;
5655
- }
5656
- return ancestor;
5398
+ let ancestor = vm.owner;
5399
+ while (!isNull(ancestor) && ancestor.renderMode === 0 /* RenderMode.Light */) {
5400
+ ancestor = ancestor.owner;
5401
+ }
5402
+ return ancestor;
5657
5403
  }
5658
5404
  function createVM(elm, ctor, renderer, options) {
5659
- const {
5660
- mode,
5661
- owner,
5662
- tagName,
5663
- hydrated
5664
- } = options;
5665
- const def = getComponentInternalDef(ctor);
5666
- const vm = {
5667
- elm,
5668
- def,
5669
- idx: idx++,
5670
- state: 0 /* VMState.created */,
5671
- isScheduled: false,
5672
- isDirty: true,
5673
- tagName,
5674
- mode,
5675
- owner,
5676
- refVNodes: null,
5677
- children: EmptyArray,
5678
- aChildren: EmptyArray,
5679
- velements: EmptyArray,
5680
- cmpProps: create(null),
5681
- cmpFields: create(null),
5682
- cmpSlots: {
5683
- slotAssignments: create(null)
5684
- },
5685
- cmpTemplate: null,
5686
- hydrated: Boolean(hydrated),
5687
- renderMode: def.renderMode,
5688
- context: {
5689
- stylesheetToken: undefined,
5690
- hasTokenInClass: undefined,
5691
- hasTokenInAttribute: undefined,
5692
- hasScopedStyles: undefined,
5693
- styleVNodes: null,
5694
- tplCache: EmptyObject,
5695
- wiredConnecting: EmptyArray,
5696
- wiredDisconnecting: EmptyArray
5697
- },
5698
- // Properties set right after VM creation.
5699
- tro: null,
5700
- shadowMode: null,
5701
- stylesheets: null,
5702
- // Properties set by the LightningElement constructor.
5703
- component: null,
5704
- shadowRoot: null,
5705
- renderRoot: null,
5706
- callHook,
5707
- setHook,
5708
- getHook,
5709
- renderer
5710
- };
5711
- if (process.env.NODE_ENV !== 'production') {
5712
- vm.debugInfo = create(null);
5713
- }
5714
- vm.stylesheets = computeStylesheets(vm, def.ctor);
5715
- vm.shadowMode = computeShadowMode(vm, renderer);
5716
- vm.tro = getTemplateReactiveObserver(vm);
5717
- if (process.env.NODE_ENV !== 'production') {
5718
- vm.toString = () => {
5719
- return `[object:vm ${def.name} (${vm.idx})]`;
5405
+ const { mode, owner, tagName, hydrated } = options;
5406
+ const def = getComponentInternalDef(ctor);
5407
+ const vm = {
5408
+ elm,
5409
+ def,
5410
+ idx: idx++,
5411
+ state: 0 /* VMState.created */,
5412
+ isScheduled: false,
5413
+ isDirty: true,
5414
+ tagName,
5415
+ mode,
5416
+ owner,
5417
+ refVNodes: null,
5418
+ children: EmptyArray,
5419
+ aChildren: EmptyArray,
5420
+ velements: EmptyArray,
5421
+ cmpProps: create(null),
5422
+ cmpFields: create(null),
5423
+ cmpSlots: { slotAssignments: create(null) },
5424
+ cmpTemplate: null,
5425
+ hydrated: Boolean(hydrated),
5426
+ renderMode: def.renderMode,
5427
+ context: {
5428
+ stylesheetToken: undefined,
5429
+ hasTokenInClass: undefined,
5430
+ hasTokenInAttribute: undefined,
5431
+ hasScopedStyles: undefined,
5432
+ styleVNodes: null,
5433
+ tplCache: EmptyObject,
5434
+ wiredConnecting: EmptyArray,
5435
+ wiredDisconnecting: EmptyArray,
5436
+ },
5437
+ // Properties set right after VM creation.
5438
+ tro: null,
5439
+ shadowMode: null,
5440
+ stylesheets: null,
5441
+ // Properties set by the LightningElement constructor.
5442
+ component: null,
5443
+ shadowRoot: null,
5444
+ renderRoot: null,
5445
+ callHook,
5446
+ setHook,
5447
+ getHook,
5448
+ renderer,
5720
5449
  };
5721
- if (lwcRuntimeFlags.ENABLE_FORCE_NATIVE_SHADOW_MODE_FOR_TEST) {
5722
- vm.shadowMode = 0 /* ShadowMode.Native */;
5723
- }
5724
- }
5725
- // Create component instance associated to the vm and the element.
5726
- invokeComponentConstructor(vm, def.ctor);
5727
- // Initializing the wire decorator per instance only when really needed
5728
- if (hasWireAdapters(vm)) {
5729
- installWireAdapters(vm);
5730
- }
5731
- return vm;
5450
+ if (process.env.NODE_ENV !== 'production') {
5451
+ vm.debugInfo = create(null);
5452
+ }
5453
+ vm.stylesheets = computeStylesheets(vm, def.ctor);
5454
+ vm.shadowMode = computeShadowMode(vm, renderer);
5455
+ vm.tro = getTemplateReactiveObserver(vm);
5456
+ if (process.env.NODE_ENV !== 'production') {
5457
+ vm.toString = () => {
5458
+ return `[object:vm ${def.name} (${vm.idx})]`;
5459
+ };
5460
+ if (lwcRuntimeFlags.ENABLE_FORCE_NATIVE_SHADOW_MODE_FOR_TEST) {
5461
+ vm.shadowMode = 0 /* ShadowMode.Native */;
5462
+ }
5463
+ }
5464
+ // Create component instance associated to the vm and the element.
5465
+ invokeComponentConstructor(vm, def.ctor);
5466
+ // Initializing the wire decorator per instance only when really needed
5467
+ if (hasWireAdapters(vm)) {
5468
+ installWireAdapters(vm);
5469
+ }
5470
+ return vm;
5732
5471
  }
5733
5472
  function validateComponentStylesheets(vm, stylesheets) {
5734
- let valid = true;
5735
- const validate = arrayOrStylesheet => {
5736
- if (isArray$1(arrayOrStylesheet)) {
5737
- for (let i = 0; i < arrayOrStylesheet.length; i++) {
5738
- validate(arrayOrStylesheet[i]);
5739
- }
5740
- } else if (!isFunction$1(arrayOrStylesheet)) {
5741
- // function assumed to be a stylesheet factory
5742
- valid = false;
5743
- }
5744
- };
5745
- if (!isArray$1(stylesheets)) {
5746
- valid = false;
5747
- } else {
5748
- validate(stylesheets);
5749
- }
5750
- return valid;
5473
+ let valid = true;
5474
+ const validate = (arrayOrStylesheet) => {
5475
+ if (isArray$1(arrayOrStylesheet)) {
5476
+ for (let i = 0; i < arrayOrStylesheet.length; i++) {
5477
+ validate(arrayOrStylesheet[i]);
5478
+ }
5479
+ }
5480
+ else if (!isFunction$1(arrayOrStylesheet)) {
5481
+ // function assumed to be a stylesheet factory
5482
+ valid = false;
5483
+ }
5484
+ };
5485
+ if (!isArray$1(stylesheets)) {
5486
+ valid = false;
5487
+ }
5488
+ else {
5489
+ validate(stylesheets);
5490
+ }
5491
+ return valid;
5751
5492
  }
5752
5493
  // Validate and flatten any stylesheets defined as `static stylesheets`
5753
5494
  function computeStylesheets(vm, ctor) {
5754
- warnOnStylesheetsMutation(ctor);
5755
- const {
5756
- stylesheets
5757
- } = ctor;
5758
- if (!isUndefined$1(stylesheets)) {
5759
- const valid = validateComponentStylesheets(vm, stylesheets);
5760
- if (valid) {
5761
- return flattenStylesheets(stylesheets);
5762
- } else if (process.env.NODE_ENV !== 'production') {
5763
- logError(`static stylesheets must be an array of CSS stylesheets. Found invalid stylesheets on <${vm.tagName}>`, vm);
5764
- }
5765
- }
5766
- return null;
5495
+ warnOnStylesheetsMutation(ctor);
5496
+ const { stylesheets } = ctor;
5497
+ if (!isUndefined$1(stylesheets)) {
5498
+ const valid = validateComponentStylesheets(vm, stylesheets);
5499
+ if (valid) {
5500
+ return flattenStylesheets(stylesheets);
5501
+ }
5502
+ else if (process.env.NODE_ENV !== 'production') {
5503
+ logError(`static stylesheets must be an array of CSS stylesheets. Found invalid stylesheets on <${vm.tagName}>`, vm);
5504
+ }
5505
+ }
5506
+ return null;
5767
5507
  }
5768
5508
  function warnOnStylesheetsMutation(ctor) {
5769
- if (process.env.NODE_ENV !== 'production') {
5770
- let {
5771
- stylesheets
5772
- } = ctor;
5773
- defineProperty(ctor, 'stylesheets', {
5774
- enumerable: true,
5775
- configurable: true,
5776
- get() {
5777
- return stylesheets;
5778
- },
5779
- set(newValue) {
5780
- logWarnOnce(`Dynamically setting the "stylesheets" static property on ${ctor.name} ` + 'will not affect the stylesheets injected.');
5781
- stylesheets = newValue;
5782
- }
5783
- });
5784
- }
5509
+ if (process.env.NODE_ENV !== 'production') {
5510
+ let { stylesheets } = ctor;
5511
+ defineProperty(ctor, 'stylesheets', {
5512
+ enumerable: true,
5513
+ configurable: true,
5514
+ get() {
5515
+ return stylesheets;
5516
+ },
5517
+ set(newValue) {
5518
+ logWarnOnce(`Dynamically setting the "stylesheets" static property on ${ctor.name} ` +
5519
+ 'will not affect the stylesheets injected.');
5520
+ stylesheets = newValue;
5521
+ },
5522
+ });
5523
+ }
5785
5524
  }
5786
5525
  function computeShadowMode(vm, renderer) {
5787
- const {
5788
- def
5789
- } = vm;
5790
- const {
5791
- isSyntheticShadowDefined,
5792
- isNativeShadowDefined
5793
- } = renderer;
5794
- let shadowMode;
5795
- if (isSyntheticShadowDefined) {
5796
- if (def.renderMode === 0 /* RenderMode.Light */) {
5797
- // ShadowMode.Native implies "not synthetic shadow" which is consistent with how
5798
- // everything defaults to native when the synthetic shadow polyfill is unavailable.
5799
- shadowMode = 0 /* ShadowMode.Native */;
5800
- } else if (isNativeShadowDefined) {
5801
- // Not combined with above condition because @lwc/features only supports identifiers in
5802
- // the if-condition.
5803
- if (lwcRuntimeFlags.ENABLE_MIXED_SHADOW_MODE) {
5804
- if (def.shadowSupportMode === "any" /* ShadowSupportMode.Any */) {
5805
- shadowMode = 0 /* ShadowMode.Native */;
5806
- } else {
5807
- const shadowAncestor = getNearestShadowAncestor(vm);
5808
- if (!isNull(shadowAncestor) && shadowAncestor.shadowMode === 0 /* ShadowMode.Native */) {
5809
- // Transitive support for native Shadow DOM. A component in native mode
5810
- // transitively opts all of its descendants into native.
5526
+ const { def } = vm;
5527
+ const { isSyntheticShadowDefined, isNativeShadowDefined } = renderer;
5528
+ let shadowMode;
5529
+ if (isSyntheticShadowDefined) {
5530
+ if (def.renderMode === 0 /* RenderMode.Light */) {
5531
+ // ShadowMode.Native implies "not synthetic shadow" which is consistent with how
5532
+ // everything defaults to native when the synthetic shadow polyfill is unavailable.
5811
5533
  shadowMode = 0 /* ShadowMode.Native */;
5812
- } else {
5813
- // Synthetic if neither this component nor any of its ancestors are configured
5814
- // to be native.
5534
+ }
5535
+ else if (isNativeShadowDefined) {
5536
+ // Not combined with above condition because @lwc/features only supports identifiers in
5537
+ // the if-condition.
5538
+ if (lwcRuntimeFlags.ENABLE_MIXED_SHADOW_MODE) {
5539
+ if (def.shadowSupportMode === "any" /* ShadowSupportMode.Any */) {
5540
+ shadowMode = 0 /* ShadowMode.Native */;
5541
+ }
5542
+ else {
5543
+ const shadowAncestor = getNearestShadowAncestor(vm);
5544
+ if (!isNull(shadowAncestor) &&
5545
+ shadowAncestor.shadowMode === 0 /* ShadowMode.Native */) {
5546
+ // Transitive support for native Shadow DOM. A component in native mode
5547
+ // transitively opts all of its descendants into native.
5548
+ shadowMode = 0 /* ShadowMode.Native */;
5549
+ }
5550
+ else {
5551
+ // Synthetic if neither this component nor any of its ancestors are configured
5552
+ // to be native.
5553
+ shadowMode = 1 /* ShadowMode.Synthetic */;
5554
+ }
5555
+ }
5556
+ }
5557
+ else {
5558
+ shadowMode = 1 /* ShadowMode.Synthetic */;
5559
+ }
5560
+ }
5561
+ else {
5562
+ // Synthetic if there is no native Shadow DOM support.
5815
5563
  shadowMode = 1 /* ShadowMode.Synthetic */;
5816
- }
5817
- }
5818
- } else {
5819
- shadowMode = 1 /* ShadowMode.Synthetic */;
5820
- }
5821
- } else {
5822
- // Synthetic if there is no native Shadow DOM support.
5823
- shadowMode = 1 /* ShadowMode.Synthetic */;
5824
- }
5825
- } else {
5826
- // Native if the synthetic shadow polyfill is unavailable.
5827
- shadowMode = 0 /* ShadowMode.Native */;
5828
- }
5829
-
5830
- return shadowMode;
5564
+ }
5565
+ }
5566
+ else {
5567
+ // Native if the synthetic shadow polyfill is unavailable.
5568
+ shadowMode = 0 /* ShadowMode.Native */;
5569
+ }
5570
+ return shadowMode;
5831
5571
  }
5832
5572
  function assertIsVM(obj) {
5833
- if (isNull(obj) || !isObject(obj) || !('renderRoot' in obj)) {
5834
- throw new TypeError(`${obj} is not a VM.`);
5835
- }
5573
+ if (isNull(obj) || !isObject(obj) || !('renderRoot' in obj)) {
5574
+ throw new TypeError(`${obj} is not a VM.`);
5575
+ }
5836
5576
  }
5837
5577
  function associateVM(obj, vm) {
5838
- ViewModelReflection.set(obj, vm);
5578
+ ViewModelReflection.set(obj, vm);
5839
5579
  }
5840
5580
  function getAssociatedVM(obj) {
5841
- const vm = ViewModelReflection.get(obj);
5842
- if (process.env.NODE_ENV !== 'production') {
5843
- assertIsVM(vm);
5844
- }
5845
- return vm;
5581
+ const vm = ViewModelReflection.get(obj);
5582
+ if (process.env.NODE_ENV !== 'production') {
5583
+ assertIsVM(vm);
5584
+ }
5585
+ return vm;
5846
5586
  }
5847
5587
  function getAssociatedVMIfPresent(obj) {
5848
- const maybeVm = ViewModelReflection.get(obj);
5849
- if (process.env.NODE_ENV !== 'production') {
5850
- if (!isUndefined$1(maybeVm)) {
5851
- assertIsVM(maybeVm);
5588
+ const maybeVm = ViewModelReflection.get(obj);
5589
+ if (process.env.NODE_ENV !== 'production') {
5590
+ if (!isUndefined$1(maybeVm)) {
5591
+ assertIsVM(maybeVm);
5592
+ }
5852
5593
  }
5853
- }
5854
- return maybeVm;
5594
+ return maybeVm;
5855
5595
  }
5856
5596
  function rehydrate(vm) {
5857
- if (isTrue(vm.isDirty)) {
5858
- const children = renderComponent(vm);
5859
- patchShadowRoot(vm, children);
5860
- }
5597
+ if (isTrue(vm.isDirty)) {
5598
+ const children = renderComponent(vm);
5599
+ patchShadowRoot(vm, children);
5600
+ }
5861
5601
  }
5862
5602
  function patchShadowRoot(vm, newCh) {
5863
- const {
5864
- renderRoot,
5865
- children: oldCh,
5866
- renderer
5867
- } = vm;
5868
- // caching the new children collection
5869
- vm.children = newCh;
5870
- if (newCh.length > 0 || oldCh.length > 0) {
5871
- // patch function mutates vnodes by adding the element reference,
5872
- // however, if patching fails it contains partial changes.
5873
- if (oldCh !== newCh) {
5874
- runWithBoundaryProtection(vm, vm, () => {
5875
- // pre
5876
- logOperationStart(2 /* OperationId.Patch */, vm);
5877
- }, () => {
5878
- // job
5879
- patchChildren(oldCh, newCh, renderRoot, renderer);
5880
- }, () => {
5881
- // post
5882
- logOperationEnd(2 /* OperationId.Patch */, vm);
5883
- });
5884
- }
5885
- }
5886
- if (vm.state === 1 /* VMState.connected */) {
5887
- // If the element is connected, that means connectedCallback was already issued, and
5888
- // any successive rendering should finish with the call to renderedCallback, otherwise
5889
- // the connectedCallback will take care of calling it in the right order at the end of
5890
- // the current rehydration process.
5891
- runRenderedCallback(vm);
5892
- }
5603
+ const { renderRoot, children: oldCh, renderer } = vm;
5604
+ // caching the new children collection
5605
+ vm.children = newCh;
5606
+ if (newCh.length > 0 || oldCh.length > 0) {
5607
+ // patch function mutates vnodes by adding the element reference,
5608
+ // however, if patching fails it contains partial changes.
5609
+ if (oldCh !== newCh) {
5610
+ runWithBoundaryProtection(vm, vm, () => {
5611
+ // pre
5612
+ logOperationStart(2 /* OperationId.Patch */, vm);
5613
+ }, () => {
5614
+ // job
5615
+ patchChildren(oldCh, newCh, renderRoot, renderer);
5616
+ }, () => {
5617
+ // post
5618
+ logOperationEnd(2 /* OperationId.Patch */, vm);
5619
+ });
5620
+ }
5621
+ }
5622
+ if (vm.state === 1 /* VMState.connected */) {
5623
+ // If the element is connected, that means connectedCallback was already issued, and
5624
+ // any successive rendering should finish with the call to renderedCallback, otherwise
5625
+ // the connectedCallback will take care of calling it in the right order at the end of
5626
+ // the current rehydration process.
5627
+ runRenderedCallback(vm);
5628
+ }
5893
5629
  }
5894
5630
  function runRenderedCallback(vm) {
5895
- const {
5896
- def: {
5897
- renderedCallback
5898
- }
5899
- } = vm;
5900
- if (!process.env.IS_BROWSER) {
5901
- return;
5902
- }
5903
- const {
5904
- rendered
5905
- } = Services;
5906
- if (rendered) {
5907
- invokeServiceHook(vm, rendered);
5908
- }
5909
- if (!isUndefined$1(renderedCallback)) {
5910
- logOperationStart(4 /* OperationId.RenderedCallback */, vm);
5911
- invokeComponentCallback(vm, renderedCallback);
5912
- logOperationEnd(4 /* OperationId.RenderedCallback */, vm);
5913
- }
5631
+ const { def: { renderedCallback }, } = vm;
5632
+ if (!process.env.IS_BROWSER) {
5633
+ return;
5634
+ }
5635
+ const { rendered } = Services;
5636
+ if (rendered) {
5637
+ invokeServiceHook(vm, rendered);
5638
+ }
5639
+ if (!isUndefined$1(renderedCallback)) {
5640
+ logOperationStart(4 /* OperationId.RenderedCallback */, vm);
5641
+ invokeComponentCallback(vm, renderedCallback);
5642
+ logOperationEnd(4 /* OperationId.RenderedCallback */, vm);
5643
+ }
5914
5644
  }
5915
5645
  let rehydrateQueue = [];
5916
5646
  function flushRehydrationQueue() {
5917
- logGlobalOperationStart(8 /* OperationId.GlobalRehydrate */);
5918
- if (process.env.NODE_ENV !== 'production') {
5919
- assert.invariant(rehydrateQueue.length, `If rehydrateQueue was scheduled, it is because there must be at least one VM on this pending queue instead of ${rehydrateQueue}.`);
5920
- }
5921
- const vms = rehydrateQueue.sort((a, b) => a.idx - b.idx);
5922
- rehydrateQueue = []; // reset to a new queue
5923
- for (let i = 0, len = vms.length; i < len; i += 1) {
5924
- const vm = vms[i];
5925
- try {
5926
- rehydrate(vm);
5927
- } catch (error) {
5928
- if (i + 1 < len) {
5929
- // pieces of the queue are still pending to be rehydrated, those should have priority
5930
- if (rehydrateQueue.length === 0) {
5931
- addCallbackToNextTick(flushRehydrationQueue);
5932
- }
5933
- ArrayUnshift.apply(rehydrateQueue, ArraySlice.call(vms, i + 1));
5934
- }
5935
- // we need to end the measure before throwing.
5936
- logGlobalOperationEnd(8 /* OperationId.GlobalRehydrate */);
5937
- // re-throwing the original error will break the current tick, but since the next tick is
5938
- // already scheduled, it should continue patching the rest.
5939
- throw error; // eslint-disable-line no-unsafe-finally
5940
- }
5941
- }
5942
-
5943
- logGlobalOperationEnd(8 /* OperationId.GlobalRehydrate */);
5647
+ logGlobalOperationStart(8 /* OperationId.GlobalRehydrate */);
5648
+ if (process.env.NODE_ENV !== 'production') {
5649
+ assert.invariant(rehydrateQueue.length, `If rehydrateQueue was scheduled, it is because there must be at least one VM on this pending queue instead of ${rehydrateQueue}.`);
5650
+ }
5651
+ const vms = rehydrateQueue.sort((a, b) => a.idx - b.idx);
5652
+ rehydrateQueue = []; // reset to a new queue
5653
+ for (let i = 0, len = vms.length; i < len; i += 1) {
5654
+ const vm = vms[i];
5655
+ try {
5656
+ rehydrate(vm);
5657
+ }
5658
+ catch (error) {
5659
+ if (i + 1 < len) {
5660
+ // pieces of the queue are still pending to be rehydrated, those should have priority
5661
+ if (rehydrateQueue.length === 0) {
5662
+ addCallbackToNextTick(flushRehydrationQueue);
5663
+ }
5664
+ ArrayUnshift.apply(rehydrateQueue, ArraySlice.call(vms, i + 1));
5665
+ }
5666
+ // we need to end the measure before throwing.
5667
+ logGlobalOperationEnd(8 /* OperationId.GlobalRehydrate */);
5668
+ // re-throwing the original error will break the current tick, but since the next tick is
5669
+ // already scheduled, it should continue patching the rest.
5670
+ throw error; // eslint-disable-line no-unsafe-finally
5671
+ }
5672
+ }
5673
+ logGlobalOperationEnd(8 /* OperationId.GlobalRehydrate */);
5944
5674
  }
5945
-
5946
5675
  function runConnectedCallback(vm) {
5947
- const {
5948
- state
5949
- } = vm;
5950
- if (state === 1 /* VMState.connected */) {
5951
- return; // nothing to do since it was already connected
5952
- }
5953
-
5954
- vm.state = 1 /* VMState.connected */;
5955
- // reporting connection
5956
- const {
5957
- connected
5958
- } = Services;
5959
- if (connected) {
5960
- invokeServiceHook(vm, connected);
5961
- }
5962
- if (hasWireAdapters(vm)) {
5963
- connectWireAdapters(vm);
5964
- }
5965
- const {
5966
- connectedCallback
5967
- } = vm.def;
5968
- if (!isUndefined$1(connectedCallback)) {
5969
- logOperationStart(3 /* OperationId.ConnectedCallback */, vm);
5970
- invokeComponentCallback(vm, connectedCallback);
5971
- logOperationEnd(3 /* OperationId.ConnectedCallback */, vm);
5972
- }
5676
+ const { state } = vm;
5677
+ if (state === 1 /* VMState.connected */) {
5678
+ return; // nothing to do since it was already connected
5679
+ }
5680
+ vm.state = 1 /* VMState.connected */;
5681
+ // reporting connection
5682
+ const { connected } = Services;
5683
+ if (connected) {
5684
+ invokeServiceHook(vm, connected);
5685
+ }
5686
+ if (hasWireAdapters(vm)) {
5687
+ connectWireAdapters(vm);
5688
+ }
5689
+ const { connectedCallback } = vm.def;
5690
+ if (!isUndefined$1(connectedCallback)) {
5691
+ logOperationStart(3 /* OperationId.ConnectedCallback */, vm);
5692
+ invokeComponentCallback(vm, connectedCallback);
5693
+ logOperationEnd(3 /* OperationId.ConnectedCallback */, vm);
5694
+ }
5973
5695
  }
5974
5696
  function hasWireAdapters(vm) {
5975
- return getOwnPropertyNames$1(vm.def.wire).length > 0;
5697
+ return getOwnPropertyNames$1(vm.def.wire).length > 0;
5976
5698
  }
5977
5699
  function runDisconnectedCallback(vm) {
5978
- if (process.env.NODE_ENV !== 'production') {
5979
- assert.isTrue(vm.state !== 2 /* VMState.disconnected */, `${vm} must be inserted.`);
5980
- }
5981
- if (isFalse(vm.isDirty)) {
5982
- // this guarantees that if the component is reused/reinserted,
5983
- // it will be re-rendered because we are disconnecting the reactivity
5984
- // linking, so mutations are not automatically reflected on the state
5985
- // of disconnected components.
5986
- vm.isDirty = true;
5987
- }
5988
- vm.state = 2 /* VMState.disconnected */;
5989
- // reporting disconnection
5990
- const {
5991
- disconnected
5992
- } = Services;
5993
- if (disconnected) {
5994
- invokeServiceHook(vm, disconnected);
5995
- }
5996
- if (hasWireAdapters(vm)) {
5997
- disconnectWireAdapters(vm);
5998
- }
5999
- const {
6000
- disconnectedCallback
6001
- } = vm.def;
6002
- if (!isUndefined$1(disconnectedCallback)) {
6003
- logOperationStart(5 /* OperationId.DisconnectedCallback */, vm);
6004
- invokeComponentCallback(vm, disconnectedCallback);
6005
- logOperationEnd(5 /* OperationId.DisconnectedCallback */, vm);
6006
- }
5700
+ if (process.env.NODE_ENV !== 'production') {
5701
+ assert.isTrue(vm.state !== 2 /* VMState.disconnected */, `${vm} must be inserted.`);
5702
+ }
5703
+ if (isFalse(vm.isDirty)) {
5704
+ // this guarantees that if the component is reused/reinserted,
5705
+ // it will be re-rendered because we are disconnecting the reactivity
5706
+ // linking, so mutations are not automatically reflected on the state
5707
+ // of disconnected components.
5708
+ vm.isDirty = true;
5709
+ }
5710
+ vm.state = 2 /* VMState.disconnected */;
5711
+ // reporting disconnection
5712
+ const { disconnected } = Services;
5713
+ if (disconnected) {
5714
+ invokeServiceHook(vm, disconnected);
5715
+ }
5716
+ if (hasWireAdapters(vm)) {
5717
+ disconnectWireAdapters(vm);
5718
+ }
5719
+ const { disconnectedCallback } = vm.def;
5720
+ if (!isUndefined$1(disconnectedCallback)) {
5721
+ logOperationStart(5 /* OperationId.DisconnectedCallback */, vm);
5722
+ invokeComponentCallback(vm, disconnectedCallback);
5723
+ logOperationEnd(5 /* OperationId.DisconnectedCallback */, vm);
5724
+ }
6007
5725
  }
6008
5726
  function runChildNodesDisconnectedCallback(vm) {
6009
- const {
6010
- velements: vCustomElementCollection
6011
- } = vm;
6012
- // Reporting disconnection for every child in inverse order since they are
6013
- // inserted in reserved order.
6014
- for (let i = vCustomElementCollection.length - 1; i >= 0; i -= 1) {
6015
- const {
6016
- elm
6017
- } = vCustomElementCollection[i];
6018
- // There are two cases where the element could be undefined:
6019
- // * when there is an error during the construction phase, and an error
6020
- // boundary picks it, there is a possibility that the VCustomElement
6021
- // is not properly initialized, and therefore is should be ignored.
6022
- // * when slotted custom element is not used by the element where it is
6023
- // slotted into it, as a result, the custom element was never
6024
- // initialized.
6025
- if (!isUndefined$1(elm)) {
6026
- const childVM = getAssociatedVMIfPresent(elm);
6027
- // The VM associated with the element might be associated undefined
6028
- // in the case where the VM failed in the middle of its creation,
6029
- // eg: constructor throwing before invoking super().
6030
- if (!isUndefined$1(childVM)) {
6031
- resetComponentStateWhenRemoved(childVM);
6032
- }
5727
+ const { velements: vCustomElementCollection } = vm;
5728
+ // Reporting disconnection for every child in inverse order since they are
5729
+ // inserted in reserved order.
5730
+ for (let i = vCustomElementCollection.length - 1; i >= 0; i -= 1) {
5731
+ const { elm } = vCustomElementCollection[i];
5732
+ // There are two cases where the element could be undefined:
5733
+ // * when there is an error during the construction phase, and an error
5734
+ // boundary picks it, there is a possibility that the VCustomElement
5735
+ // is not properly initialized, and therefore is should be ignored.
5736
+ // * when slotted custom element is not used by the element where it is
5737
+ // slotted into it, as a result, the custom element was never
5738
+ // initialized.
5739
+ if (!isUndefined$1(elm)) {
5740
+ const childVM = getAssociatedVMIfPresent(elm);
5741
+ // The VM associated with the element might be associated undefined
5742
+ // in the case where the VM failed in the middle of its creation,
5743
+ // eg: constructor throwing before invoking super().
5744
+ if (!isUndefined$1(childVM)) {
5745
+ resetComponentStateWhenRemoved(childVM);
5746
+ }
5747
+ }
6033
5748
  }
6034
- }
6035
5749
  }
6036
5750
  function runLightChildNodesDisconnectedCallback(vm) {
6037
- const {
6038
- aChildren: adoptedChildren
6039
- } = vm;
6040
- recursivelyDisconnectChildren(adoptedChildren);
5751
+ const { aChildren: adoptedChildren } = vm;
5752
+ recursivelyDisconnectChildren(adoptedChildren);
6041
5753
  }
6042
5754
  /**
6043
5755
  * The recursion doesn't need to be a complete traversal of the vnode graph,
@@ -6047,104 +5759,98 @@ function runLightChildNodesDisconnectedCallback(vm) {
6047
5759
  * defined on its shadow.
6048
5760
  */
6049
5761
  function recursivelyDisconnectChildren(vnodes) {
6050
- for (let i = 0, len = vnodes.length; i < len; i += 1) {
6051
- const vnode = vnodes[i];
6052
- if (!isNull(vnode) && !isUndefined$1(vnode.elm)) {
6053
- switch (vnode.type) {
6054
- case 2 /* VNodeType.Element */:
6055
- recursivelyDisconnectChildren(vnode.children);
6056
- break;
6057
- case 3 /* VNodeType.CustomElement */:
6058
- {
6059
- const vm = getAssociatedVM(vnode.elm);
6060
- resetComponentStateWhenRemoved(vm);
6061
- break;
6062
- }
6063
- }
5762
+ for (let i = 0, len = vnodes.length; i < len; i += 1) {
5763
+ const vnode = vnodes[i];
5764
+ if (!isNull(vnode) && !isUndefined$1(vnode.elm)) {
5765
+ switch (vnode.type) {
5766
+ case 2 /* VNodeType.Element */:
5767
+ recursivelyDisconnectChildren(vnode.children);
5768
+ break;
5769
+ case 3 /* VNodeType.CustomElement */: {
5770
+ const vm = getAssociatedVM(vnode.elm);
5771
+ resetComponentStateWhenRemoved(vm);
5772
+ break;
5773
+ }
5774
+ }
5775
+ }
6064
5776
  }
6065
- }
6066
5777
  }
6067
5778
  // This is a super optimized mechanism to remove the content of the root node (shadow root
6068
5779
  // for shadow DOM components and the root element itself for light DOM) without having to go
6069
5780
  // into snabbdom. Especially useful when the reset is a consequence of an error, in which case the
6070
5781
  // children VNodes might not be representing the current state of the DOM.
6071
5782
  function resetComponentRoot(vm) {
6072
- const {
6073
- children,
6074
- renderRoot,
6075
- renderer: {
6076
- remove
6077
- }
6078
- } = vm;
6079
- for (let i = 0, len = children.length; i < len; i++) {
6080
- const child = children[i];
6081
- if (!isNull(child) && !isUndefined$1(child.elm)) {
6082
- remove(child.elm, renderRoot);
6083
- }
6084
- }
6085
- vm.children = EmptyArray;
6086
- runChildNodesDisconnectedCallback(vm);
6087
- vm.velements = EmptyArray;
5783
+ const { children, renderRoot, renderer: { remove }, } = vm;
5784
+ for (let i = 0, len = children.length; i < len; i++) {
5785
+ const child = children[i];
5786
+ if (!isNull(child) && !isUndefined$1(child.elm)) {
5787
+ remove(child.elm, renderRoot);
5788
+ }
5789
+ }
5790
+ vm.children = EmptyArray;
5791
+ runChildNodesDisconnectedCallback(vm);
5792
+ vm.velements = EmptyArray;
6088
5793
  }
6089
5794
  function scheduleRehydration(vm) {
6090
- if (!process.env.IS_BROWSER || isTrue(vm.isScheduled)) {
6091
- return;
6092
- }
6093
- vm.isScheduled = true;
6094
- if (rehydrateQueue.length === 0) {
6095
- addCallbackToNextTick(flushRehydrationQueue);
6096
- }
6097
- ArrayPush$1.call(rehydrateQueue, vm);
5795
+ if (!process.env.IS_BROWSER || isTrue(vm.isScheduled)) {
5796
+ return;
5797
+ }
5798
+ vm.isScheduled = true;
5799
+ if (rehydrateQueue.length === 0) {
5800
+ addCallbackToNextTick(flushRehydrationQueue);
5801
+ }
5802
+ ArrayPush$1.call(rehydrateQueue, vm);
6098
5803
  }
6099
5804
  function getErrorBoundaryVM(vm) {
6100
- let currentVm = vm;
6101
- while (!isNull(currentVm)) {
6102
- if (!isUndefined$1(currentVm.def.errorCallback)) {
6103
- return currentVm;
5805
+ let currentVm = vm;
5806
+ while (!isNull(currentVm)) {
5807
+ if (!isUndefined$1(currentVm.def.errorCallback)) {
5808
+ return currentVm;
5809
+ }
5810
+ currentVm = currentVm.owner;
6104
5811
  }
6105
- currentVm = currentVm.owner;
6106
- }
6107
5812
  }
6108
5813
  function runWithBoundaryProtection(vm, owner, pre, job, post) {
6109
- let error;
6110
- pre();
6111
- try {
6112
- job();
6113
- } catch (e) {
6114
- error = Object(e);
6115
- } finally {
6116
- post();
6117
- if (!isUndefined$1(error)) {
6118
- addErrorComponentStack(vm, error);
6119
- const errorBoundaryVm = isNull(owner) ? undefined : getErrorBoundaryVM(owner);
6120
- if (isUndefined$1(errorBoundaryVm)) {
6121
- throw error; // eslint-disable-line no-unsafe-finally
6122
- }
6123
-
6124
- resetComponentRoot(vm); // remove offenders
6125
- logOperationStart(6 /* OperationId.ErrorCallback */, vm);
6126
- // error boundaries must have an ErrorCallback
6127
- const errorCallback = errorBoundaryVm.def.errorCallback;
6128
- invokeComponentCallback(errorBoundaryVm, errorCallback, [error, error.wcStack]);
6129
- logOperationEnd(6 /* OperationId.ErrorCallback */, vm);
5814
+ let error;
5815
+ pre();
5816
+ try {
5817
+ job();
5818
+ }
5819
+ catch (e) {
5820
+ error = Object(e);
5821
+ }
5822
+ finally {
5823
+ post();
5824
+ if (!isUndefined$1(error)) {
5825
+ addErrorComponentStack(vm, error);
5826
+ const errorBoundaryVm = isNull(owner) ? undefined : getErrorBoundaryVM(owner);
5827
+ if (isUndefined$1(errorBoundaryVm)) {
5828
+ throw error; // eslint-disable-line no-unsafe-finally
5829
+ }
5830
+ resetComponentRoot(vm); // remove offenders
5831
+ logOperationStart(6 /* OperationId.ErrorCallback */, vm);
5832
+ // error boundaries must have an ErrorCallback
5833
+ const errorCallback = errorBoundaryVm.def.errorCallback;
5834
+ invokeComponentCallback(errorBoundaryVm, errorCallback, [error, error.wcStack]);
5835
+ logOperationEnd(6 /* OperationId.ErrorCallback */, vm);
5836
+ }
6130
5837
  }
6131
- }
6132
5838
  }
6133
5839
  function forceRehydration(vm) {
6134
- // if we must reset the shadowRoot content and render the template
6135
- // from scratch on an active instance, the way to force the reset
6136
- // is by replacing the value of old template, which is used during
6137
- // to determine if the template has changed or not during the rendering
6138
- // process. If the template returned by render() is different from the
6139
- // previous stored template, the styles will be reset, along with the
6140
- // content of the shadowRoot, this way we can guarantee that all children
6141
- // elements will be throw away, and new instances will be created.
6142
- vm.cmpTemplate = () => [];
6143
- if (isFalse(vm.isDirty)) {
6144
- // forcing the vm to rehydrate in the next tick
6145
- markComponentAsDirty(vm);
6146
- scheduleRehydration(vm);
6147
- }
5840
+ // if we must reset the shadowRoot content and render the template
5841
+ // from scratch on an active instance, the way to force the reset
5842
+ // is by replacing the value of old template, which is used during
5843
+ // to determine if the template has changed or not during the rendering
5844
+ // process. If the template returned by render() is different from the
5845
+ // previous stored template, the styles will be reset, along with the
5846
+ // content of the shadowRoot, this way we can guarantee that all children
5847
+ // elements will be throw away, and new instances will be created.
5848
+ vm.cmpTemplate = () => [];
5849
+ if (isFalse(vm.isDirty)) {
5850
+ // forcing the vm to rehydrate in the next tick
5851
+ markComponentAsDirty(vm);
5852
+ scheduleRehydration(vm);
5853
+ }
6148
5854
  }
6149
5855
 
6150
5856
  /*
@@ -6306,91 +6012,107 @@ if (process.env.IS_BROWSER && supportsCssEscape() && isSyntheticShadowLoaded())
6306
6012
  // legacy non-standard Element.prototype extensions added by the @lwc/aria-reflection package.
6307
6013
  //
6308
6014
  // See the README for @lwc/aria-reflection
6309
- const NON_STANDARD_ARIA_PROPS = ['ariaActiveDescendant', 'ariaControls', 'ariaDescribedBy', 'ariaDetails', 'ariaErrorMessage', 'ariaFlowTo', 'ariaLabelledBy', 'ariaOwns'];
6015
+ const NON_STANDARD_ARIA_PROPS = [
6016
+ 'ariaActiveDescendant',
6017
+ 'ariaControls',
6018
+ 'ariaDescribedBy',
6019
+ 'ariaDetails',
6020
+ 'ariaErrorMessage',
6021
+ 'ariaFlowTo',
6022
+ 'ariaLabelledBy',
6023
+ 'ariaOwns',
6024
+ ];
6310
6025
  function isLightningElement(elm) {
6311
- // The former case is for `this.prop` (inside component) and the latter is for `element.prop` (outside component).
6312
- // In both cases, we apply the non-standard prop even when the global polyfill is disabled, so this is kosher.
6313
- return elm instanceof LightningElement || elm instanceof BaseBridgeElement;
6026
+ // The former case is for `this.prop` (inside component) and the latter is for `element.prop` (outside component).
6027
+ // In both cases, we apply the non-standard prop even when the global polyfill is disabled, so this is kosher.
6028
+ return elm instanceof LightningElement || elm instanceof BaseBridgeElement;
6314
6029
  }
6315
6030
  function findVM(elm) {
6316
- // If it's a shadow DOM component, then it has a host
6317
- const {
6318
- host
6319
- } = elm.getRootNode();
6320
- const vm = isUndefined$1(host) ? undefined : getAssociatedVMIfPresent(host);
6321
- if (!isUndefined$1(vm)) {
6322
- return vm;
6323
- }
6324
- // Else it might be a light DOM component. Walk up the tree trying to find the owner
6325
- let parentElement = elm;
6326
- while (!isNull(parentElement = parentElement.parentElement)) {
6327
- if (isLightningElement(parentElement)) {
6328
- const vm = getAssociatedVMIfPresent(parentElement);
6329
- if (!isUndefined$1(vm)) {
6031
+ // If it's a shadow DOM component, then it has a host
6032
+ const { host } = elm.getRootNode();
6033
+ const vm = isUndefined$1(host) ? undefined : getAssociatedVMIfPresent(host);
6034
+ if (!isUndefined$1(vm)) {
6330
6035
  return vm;
6331
- }
6332
6036
  }
6333
- }
6334
- // If we return undefined, it's because the element was rendered wholly outside a LightningElement
6037
+ // Else it might be a light DOM component. Walk up the tree trying to find the owner
6038
+ let parentElement = elm;
6039
+ while (!isNull((parentElement = parentElement.parentElement))) {
6040
+ if (isLightningElement(parentElement)) {
6041
+ const vm = getAssociatedVMIfPresent(parentElement);
6042
+ if (!isUndefined$1(vm)) {
6043
+ return vm;
6044
+ }
6045
+ }
6046
+ }
6047
+ // If we return undefined, it's because the element was rendered wholly outside a LightningElement
6335
6048
  }
6336
-
6337
- function checkAndReportViolation(elm, prop) {
6338
- if (!isLightningElement(elm)) {
6339
- const vm = findVM(elm);
6340
- if (process.env.NODE_ENV !== 'production') {
6341
- logWarnOnce(`Element <${elm.tagName.toLowerCase()}> ` + (isUndefined$1(vm) ? '' : `owned by <${vm.elm.tagName.toLowerCase()}> `) + `uses non-standard property "${prop}". This will be removed in a future version of LWC. ` + `See https://sfdc.co/deprecated-aria`);
6049
+ function checkAndReportViolation(elm, prop, isSetter, setValue) {
6050
+ if (!isLightningElement(elm)) {
6051
+ const vm = findVM(elm);
6052
+ if (process.env.NODE_ENV !== 'production') {
6053
+ logWarnOnce(`Element <${elm.tagName.toLowerCase()}> ` +
6054
+ (isUndefined$1(vm) ? '' : `owned by <${vm.elm.tagName.toLowerCase()}> `) +
6055
+ `uses non-standard property "${prop}". This will be removed in a future version of LWC. ` +
6056
+ `See https://sfdc.co/deprecated-aria`);
6057
+ }
6058
+ let setValueType;
6059
+ if (isSetter) {
6060
+ // `typeof null` is "object" which is not very useful for detecting null.
6061
+ // We mostly want to know null vs undefined vs other types here, due to
6062
+ // https://github.com/salesforce/lwc/issues/3284
6063
+ setValueType = isNull(setValue) ? 'null' : typeof setValue;
6064
+ }
6065
+ report(2 /* ReportingEventId.NonStandardAriaReflection */, {
6066
+ tagName: vm === null || vm === void 0 ? void 0 : vm.tagName,
6067
+ propertyName: prop,
6068
+ isSetter,
6069
+ setValueType,
6070
+ });
6342
6071
  }
6343
- report(2 /* ReportingEventId.NonStandardAriaReflection */, {
6344
- tagName: vm === null || vm === void 0 ? void 0 : vm.tagName,
6345
- propertyName: prop
6346
- });
6347
- }
6348
6072
  }
6349
6073
  function enableDetection() {
6350
- const {
6351
- prototype
6352
- } = Element;
6353
- for (const prop of NON_STANDARD_ARIA_PROPS) {
6354
- const descriptor = getOwnPropertyDescriptor$1(prototype, prop);
6355
- // The descriptor should exist because the @lwc/aria-reflection polyfill has run by now.
6356
- // This happens automatically because of the ordering of imports.
6357
- if (process.env.NODE_ENV !== 'production') {
6358
- /* istanbul ignore if */
6359
- if (isUndefined$1(descriptor) || isUndefined$1(descriptor.get) || isUndefined$1(descriptor.set)) {
6360
- // should never happen
6361
- throw new Error('detect-non-standard-aria.ts loaded before @lwc/aria-reflection');
6362
- }
6074
+ const { prototype } = Element;
6075
+ for (const prop of NON_STANDARD_ARIA_PROPS) {
6076
+ const descriptor = getOwnPropertyDescriptor$1(prototype, prop);
6077
+ // The descriptor should exist because the @lwc/aria-reflection polyfill has run by now.
6078
+ // This happens automatically because of the ordering of imports.
6079
+ if (process.env.NODE_ENV !== 'production') {
6080
+ /* istanbul ignore if */
6081
+ if (isUndefined$1(descriptor) ||
6082
+ isUndefined$1(descriptor.get) ||
6083
+ isUndefined$1(descriptor.set)) {
6084
+ // should never happen
6085
+ throw new Error('detect-non-standard-aria.ts loaded before @lwc/aria-reflection');
6086
+ }
6087
+ }
6088
+ // @ts-ignore
6089
+ const { get, set } = descriptor;
6090
+ defineProperty(prototype, prop, {
6091
+ get() {
6092
+ checkAndReportViolation(this, prop, false, undefined);
6093
+ return get.call(this);
6094
+ },
6095
+ set(val) {
6096
+ checkAndReportViolation(this, prop, true, val);
6097
+ return set.call(this, val);
6098
+ },
6099
+ configurable: true,
6100
+ enumerable: true,
6101
+ });
6363
6102
  }
6364
- // @ts-ignore
6365
- const {
6366
- get,
6367
- set
6368
- } = descriptor;
6369
- defineProperty(prototype, prop, {
6370
- get() {
6371
- checkAndReportViolation(this, prop);
6372
- return get.call(this);
6373
- },
6374
- set(val) {
6375
- checkAndReportViolation(this, prop);
6376
- return set.call(this, val);
6377
- },
6378
- configurable: true,
6379
- enumerable: true
6380
- });
6381
- }
6382
6103
  }
6383
6104
  // No point in running this code if we're not in a browser, or if the global polyfill is not loaded
6384
6105
  if (process.env.IS_BROWSER) {
6385
- if (!lwcRuntimeFlags.DISABLE_ARIA_REFLECTION_POLYFILL) {
6386
- // Always run detection in dev mode, so we can at least print to the console
6387
- if (process.env.NODE_ENV !== 'production') {
6388
- enableDetection();
6389
- } else {
6390
- // In prod mode, only enable detection if reporting is enabled
6391
- onReportingEnabled(enableDetection);
6106
+ if (!lwcRuntimeFlags.DISABLE_ARIA_REFLECTION_POLYFILL) {
6107
+ // Always run detection in dev mode, so we can at least print to the console
6108
+ if (process.env.NODE_ENV !== 'production') {
6109
+ enableDetection();
6110
+ }
6111
+ else {
6112
+ // In prod mode, only enable detection if reporting is enabled
6113
+ onReportingEnabled(enableDetection);
6114
+ }
6392
6115
  }
6393
- }
6394
6116
  }
6395
6117
 
6396
6118
  /*
@@ -6879,191 +6601,204 @@ function setHooks(hooks) {
6879
6601
  const TEMPLATE_PROPS = ['slots', 'stylesheetToken', 'stylesheets', 'renderMode'];
6880
6602
  // Expandos that may be placed on a stylesheet factory function, and which are meaningful to LWC at runtime
6881
6603
  const STYLESHEET_PROPS = [
6882
- // SEE `KEY__SCOPED_CSS` in @lwc/style-compiler
6883
- '$scoped$'];
6604
+ // SEE `KEY__SCOPED_CSS` in @lwc/style-compiler
6605
+ '$scoped$',
6606
+ ];
6884
6607
  // Via https://www.npmjs.com/package/object-observer
6885
- const ARRAY_MUTATION_METHODS = ['pop', 'push', 'shift', 'unshift', 'reverse', 'sort', 'fill', 'splice', 'copyWithin'];
6608
+ const ARRAY_MUTATION_METHODS = [
6609
+ 'pop',
6610
+ 'push',
6611
+ 'shift',
6612
+ 'unshift',
6613
+ 'reverse',
6614
+ 'sort',
6615
+ 'fill',
6616
+ 'splice',
6617
+ 'copyWithin',
6618
+ ];
6886
6619
  let mutationTrackingDisabled = false;
6887
6620
  function getOriginalArrayMethod(prop) {
6888
- switch (prop) {
6889
- case 'pop':
6890
- return ArrayPop;
6891
- case 'push':
6892
- return ArrayPush$1;
6893
- case 'shift':
6894
- return ArrayShift;
6895
- case 'unshift':
6896
- return ArrayUnshift;
6897
- case 'reverse':
6898
- return ArrayReverse;
6899
- case 'sort':
6900
- return ArraySort;
6901
- case 'fill':
6902
- return ArrayFill;
6903
- case 'splice':
6904
- return ArraySplice;
6905
- case 'copyWithin':
6906
- return ArrayCopyWithin;
6907
- }
6621
+ switch (prop) {
6622
+ case 'pop':
6623
+ return ArrayPop;
6624
+ case 'push':
6625
+ return ArrayPush$1;
6626
+ case 'shift':
6627
+ return ArrayShift;
6628
+ case 'unshift':
6629
+ return ArrayUnshift;
6630
+ case 'reverse':
6631
+ return ArrayReverse;
6632
+ case 'sort':
6633
+ return ArraySort;
6634
+ case 'fill':
6635
+ return ArrayFill;
6636
+ case 'splice':
6637
+ return ArraySplice;
6638
+ case 'copyWithin':
6639
+ return ArrayCopyWithin;
6640
+ }
6908
6641
  }
6909
6642
  function reportViolation(type, eventId, prop) {
6910
- if (process.env.NODE_ENV !== 'production') {
6911
- logWarnOnce(`Mutating the "${prop}" property on a ${type} ` + `is deprecated and will be removed in a future version of LWC. ` + `See: https://sfdc.co/template-mutation`);
6912
- }
6913
- report(eventId, {
6914
- propertyName: prop
6915
- });
6643
+ if (process.env.NODE_ENV !== 'production') {
6644
+ logWarnOnce(`Mutating the "${prop}" property on a ${type} ` +
6645
+ `is deprecated and will be removed in a future version of LWC. ` +
6646
+ `See: https://sfdc.co/template-mutation`);
6647
+ }
6648
+ report(eventId, { propertyName: prop });
6916
6649
  }
6917
6650
  function reportTemplateViolation(prop) {
6918
- reportViolation('template', 3 /* ReportingEventId.TemplateMutation */, prop);
6651
+ reportViolation('template', 3 /* ReportingEventId.TemplateMutation */, prop);
6919
6652
  }
6920
6653
  function reportStylesheetViolation(prop) {
6921
- reportViolation('stylesheet', 4 /* ReportingEventId.StylesheetMutation */, prop);
6654
+ reportViolation('stylesheet', 4 /* ReportingEventId.StylesheetMutation */, prop);
6922
6655
  }
6923
6656
  // Warn if the user tries to mutate a stylesheets array, e.g.:
6924
6657
  // `tmpl.stylesheets.push(someStylesheetFunction)`
6925
6658
  function warnOnArrayMutation(stylesheets) {
6926
- // We can't handle users calling Array.prototype.slice.call(tmpl.stylesheets), but
6927
- // we can at least warn when they use the most common mutation methods.
6928
- for (const prop of ARRAY_MUTATION_METHODS) {
6929
- const originalArrayMethod = getOriginalArrayMethod(prop);
6930
- stylesheets[prop] = function arrayMutationWarningWrapper() {
6931
- reportTemplateViolation('stylesheets');
6932
- // @ts-ignore
6933
- return originalArrayMethod.apply(this, arguments);
6934
- };
6935
- }
6659
+ // We can't handle users calling Array.prototype.slice.call(tmpl.stylesheets), but
6660
+ // we can at least warn when they use the most common mutation methods.
6661
+ for (const prop of ARRAY_MUTATION_METHODS) {
6662
+ const originalArrayMethod = getOriginalArrayMethod(prop);
6663
+ stylesheets[prop] = function arrayMutationWarningWrapper() {
6664
+ reportTemplateViolation('stylesheets');
6665
+ // @ts-ignore
6666
+ return originalArrayMethod.apply(this, arguments);
6667
+ };
6668
+ }
6936
6669
  }
6937
6670
  // Warn if the user tries to mutate a stylesheet factory function, e.g.:
6938
6671
  // `stylesheet.$scoped$ = true`
6939
6672
  function warnOnStylesheetFunctionMutation(stylesheet) {
6940
- for (const prop of STYLESHEET_PROPS) {
6941
- let value = stylesheet[prop];
6942
- defineProperty(stylesheet, prop, {
6943
- enumerable: true,
6944
- configurable: true,
6945
- get() {
6946
- return value;
6947
- },
6948
- set(newValue) {
6949
- reportStylesheetViolation(prop);
6950
- value = newValue;
6951
- }
6952
- });
6953
- }
6673
+ for (const prop of STYLESHEET_PROPS) {
6674
+ let value = stylesheet[prop];
6675
+ defineProperty(stylesheet, prop, {
6676
+ enumerable: true,
6677
+ configurable: true,
6678
+ get() {
6679
+ return value;
6680
+ },
6681
+ set(newValue) {
6682
+ reportStylesheetViolation(prop);
6683
+ value = newValue;
6684
+ },
6685
+ });
6686
+ }
6954
6687
  }
6955
6688
  // Warn on either array or stylesheet (function) mutation, in a deeply-nested array
6956
6689
  function trackStylesheetsMutation(stylesheets) {
6957
- traverseStylesheets(stylesheets, subStylesheets => {
6958
- if (isArray$1(subStylesheets)) {
6959
- warnOnArrayMutation(subStylesheets);
6960
- } else {
6961
- warnOnStylesheetFunctionMutation(subStylesheets);
6962
- }
6963
- });
6690
+ traverseStylesheets(stylesheets, (subStylesheets) => {
6691
+ if (isArray$1(subStylesheets)) {
6692
+ warnOnArrayMutation(subStylesheets);
6693
+ }
6694
+ else {
6695
+ warnOnStylesheetFunctionMutation(subStylesheets);
6696
+ }
6697
+ });
6964
6698
  }
6965
6699
  // Deeply freeze the entire array (of arrays) of stylesheet factory functions
6966
6700
  function deepFreeze(stylesheets) {
6967
- traverseStylesheets(stylesheets, subStylesheets => {
6968
- freeze(subStylesheets);
6969
- });
6701
+ traverseStylesheets(stylesheets, (subStylesheets) => {
6702
+ freeze(subStylesheets);
6703
+ });
6970
6704
  }
6971
6705
  // Deep-traverse an array (of arrays) of stylesheet factory functions, and call the callback for every array/function
6972
6706
  function traverseStylesheets(stylesheets, callback) {
6973
- callback(stylesheets);
6974
- for (let i = 0; i < stylesheets.length; i++) {
6975
- const stylesheet = stylesheets[i];
6976
- if (isArray$1(stylesheet)) {
6977
- traverseStylesheets(stylesheet, callback);
6978
- } else {
6979
- callback(stylesheet);
6707
+ callback(stylesheets);
6708
+ for (let i = 0; i < stylesheets.length; i++) {
6709
+ const stylesheet = stylesheets[i];
6710
+ if (isArray$1(stylesheet)) {
6711
+ traverseStylesheets(stylesheet, callback);
6712
+ }
6713
+ else {
6714
+ callback(stylesheet);
6715
+ }
6980
6716
  }
6981
- }
6982
6717
  }
6983
6718
  function trackMutations(tmpl) {
6984
- if (!isUndefined$1(tmpl.stylesheets)) {
6985
- trackStylesheetsMutation(tmpl.stylesheets);
6986
- }
6987
- for (const prop of TEMPLATE_PROPS) {
6988
- let value = tmpl[prop];
6989
- defineProperty(tmpl, prop, {
6990
- enumerable: true,
6991
- configurable: true,
6992
- get() {
6993
- return value;
6994
- },
6995
- set(newValue) {
6996
- if (!mutationTrackingDisabled) {
6997
- reportTemplateViolation(prop);
6998
- }
6999
- value = newValue;
7000
- }
7001
- });
7002
- }
7003
- const originalDescriptor = getOwnPropertyDescriptor$1(tmpl, 'stylesheetTokens');
7004
- defineProperty(tmpl, 'stylesheetTokens', {
7005
- enumerable: true,
7006
- configurable: true,
7007
- get: originalDescriptor.get,
7008
- set(value) {
7009
- reportTemplateViolation('stylesheetTokens');
7010
- // Avoid logging/reporting twice (for both stylesheetToken and stylesheetTokens)
7011
- mutationTrackingDisabled = true;
7012
- originalDescriptor.set.call(this, value);
7013
- mutationTrackingDisabled = false;
6719
+ if (!isUndefined$1(tmpl.stylesheets)) {
6720
+ trackStylesheetsMutation(tmpl.stylesheets);
6721
+ }
6722
+ for (const prop of TEMPLATE_PROPS) {
6723
+ let value = tmpl[prop];
6724
+ defineProperty(tmpl, prop, {
6725
+ enumerable: true,
6726
+ configurable: true,
6727
+ get() {
6728
+ return value;
6729
+ },
6730
+ set(newValue) {
6731
+ if (!mutationTrackingDisabled) {
6732
+ reportTemplateViolation(prop);
6733
+ }
6734
+ value = newValue;
6735
+ },
6736
+ });
7014
6737
  }
7015
- });
6738
+ const originalDescriptor = getOwnPropertyDescriptor$1(tmpl, 'stylesheetTokens');
6739
+ defineProperty(tmpl, 'stylesheetTokens', {
6740
+ enumerable: true,
6741
+ configurable: true,
6742
+ get: originalDescriptor.get,
6743
+ set(value) {
6744
+ reportTemplateViolation('stylesheetTokens');
6745
+ // Avoid logging/reporting twice (for both stylesheetToken and stylesheetTokens)
6746
+ mutationTrackingDisabled = true;
6747
+ originalDescriptor.set.call(this, value);
6748
+ mutationTrackingDisabled = false;
6749
+ },
6750
+ });
7016
6751
  }
7017
6752
  function addLegacyStylesheetTokensShim(tmpl) {
7018
- // When ENABLE_FROZEN_TEMPLATE is false, then we shim stylesheetTokens on top of stylesheetToken for anyone who
7019
- // is accessing the old internal API (backwards compat). Details: https://salesforce.quip.com/v1rmAFu2cKAr
7020
- defineProperty(tmpl, 'stylesheetTokens', {
7021
- enumerable: true,
7022
- configurable: true,
7023
- get() {
7024
- const {
7025
- stylesheetToken
7026
- } = this;
7027
- if (isUndefined$1(stylesheetToken)) {
7028
- return stylesheetToken;
7029
- }
7030
- // Shim for the old `stylesheetTokens` property
7031
- // See https://github.com/salesforce/lwc/pull/2332/files#diff-7901555acef29969adaa6583185b3e9bce475cdc6f23e799a54e0018cb18abaa
7032
- return {
7033
- hostAttribute: `${stylesheetToken}-host`,
7034
- shadowAttribute: stylesheetToken
7035
- };
7036
- },
7037
- set(value) {
7038
- // If the value is null or some other exotic object, you would be broken anyway in the past
7039
- // because the engine would try to access hostAttribute/shadowAttribute, which would throw an error.
7040
- // However it may be undefined in newer versions of LWC, so we need to guard against that case.
7041
- this.stylesheetToken = isUndefined$1(value) ? undefined : value.shadowAttribute;
7042
- }
7043
- });
6753
+ // When ENABLE_FROZEN_TEMPLATE is false, then we shim stylesheetTokens on top of stylesheetToken for anyone who
6754
+ // is accessing the old internal API (backwards compat). Details: https://salesforce.quip.com/v1rmAFu2cKAr
6755
+ defineProperty(tmpl, 'stylesheetTokens', {
6756
+ enumerable: true,
6757
+ configurable: true,
6758
+ get() {
6759
+ const { stylesheetToken } = this;
6760
+ if (isUndefined$1(stylesheetToken)) {
6761
+ return stylesheetToken;
6762
+ }
6763
+ // Shim for the old `stylesheetTokens` property
6764
+ // See https://github.com/salesforce/lwc/pull/2332/files#diff-7901555acef29969adaa6583185b3e9bce475cdc6f23e799a54e0018cb18abaa
6765
+ return {
6766
+ hostAttribute: `${stylesheetToken}-host`,
6767
+ shadowAttribute: stylesheetToken,
6768
+ };
6769
+ },
6770
+ set(value) {
6771
+ // If the value is null or some other exotic object, you would be broken anyway in the past
6772
+ // because the engine would try to access hostAttribute/shadowAttribute, which would throw an error.
6773
+ // However it may be undefined in newer versions of LWC, so we need to guard against that case.
6774
+ this.stylesheetToken = isUndefined$1(value) ? undefined : value.shadowAttribute;
6775
+ },
6776
+ });
7044
6777
  }
7045
6778
  function freezeTemplate(tmpl) {
7046
- // TODO [#2782]: remove this flag and delete the legacy behavior
7047
- if (lwcRuntimeFlags.ENABLE_FROZEN_TEMPLATE) {
7048
- // Deep freeze the template
7049
- freeze(tmpl);
7050
- if (!isUndefined$1(tmpl.stylesheets)) {
7051
- deepFreeze(tmpl.stylesheets);
6779
+ // TODO [#2782]: remove this flag and delete the legacy behavior
6780
+ if (lwcRuntimeFlags.ENABLE_FROZEN_TEMPLATE) {
6781
+ // Deep freeze the template
6782
+ freeze(tmpl);
6783
+ if (!isUndefined$1(tmpl.stylesheets)) {
6784
+ deepFreeze(tmpl.stylesheets);
6785
+ }
7052
6786
  }
7053
- } else {
7054
- // template is not frozen - shim, report, and warn
7055
- // this shim should be applied in both dev and prod
7056
- addLegacyStylesheetTokensShim(tmpl);
7057
- // When ENABLE_FROZEN_TEMPLATE is false, we want to warn in dev mode whenever someone is mutating the template
7058
- if (process.env.NODE_ENV !== 'production') {
7059
- trackMutations(tmpl);
7060
- } else {
7061
- // In prod mode, we only track mutations if reporting is enabled
7062
- onReportingEnabled(() => {
7063
- trackMutations(tmpl);
7064
- });
6787
+ else {
6788
+ // template is not frozen - shim, report, and warn
6789
+ // this shim should be applied in both dev and prod
6790
+ addLegacyStylesheetTokensShim(tmpl);
6791
+ // When ENABLE_FROZEN_TEMPLATE is false, we want to warn in dev mode whenever someone is mutating the template
6792
+ if (process.env.NODE_ENV !== 'production') {
6793
+ trackMutations(tmpl);
6794
+ }
6795
+ else {
6796
+ // In prod mode, we only track mutations if reporting is enabled
6797
+ onReportingEnabled(() => {
6798
+ trackMutations(tmpl);
6799
+ });
6800
+ }
7065
6801
  }
7066
- }
7067
6802
  }
7068
6803
 
7069
6804
  /*
@@ -7090,4 +6825,4 @@ function getComponentConstructor(elm) {
7090
6825
  }
7091
6826
 
7092
6827
  export { LightningElement, profilerControl as __unstable__ProfilerControl, reportingControl as __unstable__ReportingControl, 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 };
7093
- /* version: 2.37.0 */
6828
+ /* version: 2.37.1 */