@lwc/engine-core 2.37.0 → 2.37.2

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