@lwc/engine-core 2.32.1 → 2.33.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -2,6 +2,7 @@
2
2
  import { lwcRuntimeFlags } from '@lwc/features';
3
3
  export { setFeatureFlag, setFeatureFlagForTest } from '@lwc/features';
4
4
  import { seal, create, isUndefined as isUndefined$1, isFunction as isFunction$1, ArrayPush as ArrayPush$1, ArrayIndexOf, ArraySplice, StringToLowerCase, isNull, ArrayJoin, isFrozen, defineProperty, hasOwnProperty as hasOwnProperty$1, assign, forEach, keys, AriaPropNameToAttrNameMap, getPropertyDescriptor, defineProperties, getOwnPropertyNames as getOwnPropertyNames$1, getPrototypeOf as getPrototypeOf$1, setPrototypeOf, isObject, freeze, assert, KEY__SYNTHETIC_MODE, toString as toString$1, getOwnPropertyDescriptor as getOwnPropertyDescriptor$1, isFalse, LWC_VERSION_COMMENT_REGEX, LWC_VERSION, htmlPropertyToAttribute, ArraySlice, ArrayMap, isArray as isArray$1, KEY__SCOPED_CSS, StringCharCodeAt, XML_NAMESPACE, XLINK_NAMESPACE, htmlAttributeToProperty, isString, StringSlice, isTrue, SVG_NAMESPACE, KEY__SHADOW_STATIC, KEY__SHADOW_RESOLVER, ArraySome, isNumber, StringReplace, noop, ArrayUnshift, ArrayFilter, ArrayCopyWithin, ArrayFill, ArraySort, ArrayReverse, ArrayShift, ArrayPop } from '@lwc/shared';
5
+ import { applyAriaReflection } from '@lwc/aria-reflection';
5
6
 
6
7
  /*
7
8
  * Copyright (c) 2018, salesforce.com, inc.
@@ -1409,46 +1410,51 @@ function markLockerLiveObject(obj) {
1409
1410
  * for the Base Lightning Element, it also include the reactivity bit, so the standard property is reactive.
1410
1411
  */
1411
1412
  function createBridgeToElementDescriptor(propName, descriptor) {
1412
- const { get, set, enumerable, configurable } = descriptor;
1413
- if (!isFunction$1(get)) {
1414
- if (process.env.NODE_ENV !== 'production') {
1415
- assert.fail(`Detected invalid public property descriptor for HTMLElement.prototype.${propName} definition. Missing the standard getter.`);
1416
- }
1417
- throw new TypeError();
1413
+ const {
1414
+ get,
1415
+ set,
1416
+ enumerable,
1417
+ configurable
1418
+ } = descriptor;
1419
+ if (!isFunction$1(get)) {
1420
+ if (process.env.NODE_ENV !== 'production') {
1421
+ assert.fail(`Detected invalid public property descriptor for HTMLElement.prototype.${propName} definition. Missing the standard getter.`);
1418
1422
  }
1419
- if (!isFunction$1(set)) {
1423
+ throw new TypeError();
1424
+ }
1425
+ if (!isFunction$1(set)) {
1426
+ if (process.env.NODE_ENV !== 'production') {
1427
+ assert.fail(`Detected invalid public property descriptor for HTMLElement.prototype.${propName} definition. Missing the standard setter.`);
1428
+ }
1429
+ throw new TypeError();
1430
+ }
1431
+ return {
1432
+ enumerable,
1433
+ configurable,
1434
+ get() {
1435
+ const vm = getAssociatedVM(this);
1436
+ if (isBeingConstructed(vm)) {
1420
1437
  if (process.env.NODE_ENV !== 'production') {
1421
- assert.fail(`Detected invalid public property descriptor for HTMLElement.prototype.${propName} definition. Missing the standard setter.`);
1438
+ 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);
1422
1439
  }
1423
- throw new TypeError();
1440
+ return;
1441
+ }
1442
+ componentValueObserved(vm, propName);
1443
+ return get.call(vm.elm);
1444
+ },
1445
+ set(newValue) {
1446
+ const vm = getAssociatedVM(this);
1447
+ if (process.env.NODE_ENV !== 'production') {
1448
+ const vmBeingRendered = getVMBeingRendered();
1449
+ assert.invariant(!isInvokingRender, `${vmBeingRendered}.render() method has side effects on the state of ${vm}.${propName}`);
1450
+ 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}`);
1451
+ assert.isFalse(isBeingConstructed(vm), `Failed to construct '${getComponentTag(vm)}': The result must not have attributes.`);
1452
+ assert.invariant(!isObject(newValue) || isNull(newValue), `Invalid value "${newValue}" for "${propName}" of ${vm}. Value cannot be an object, must be a primitive value.`);
1453
+ }
1454
+ updateComponentValue(vm, propName, newValue);
1455
+ return set.call(vm.elm, newValue);
1424
1456
  }
1425
- return {
1426
- enumerable,
1427
- configurable,
1428
- get() {
1429
- const vm = getAssociatedVM(this);
1430
- if (isBeingConstructed(vm)) {
1431
- if (process.env.NODE_ENV !== 'production') {
1432
- 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);
1433
- }
1434
- return;
1435
- }
1436
- componentValueObserved(vm, propName);
1437
- return get.call(vm.elm);
1438
- },
1439
- set(newValue) {
1440
- const vm = getAssociatedVM(this);
1441
- if (process.env.NODE_ENV !== 'production') {
1442
- const vmBeingRendered = getVMBeingRendered();
1443
- assert.invariant(!isInvokingRender, `${vmBeingRendered}.render() method has side effects on the state of ${vm}.${propName}`);
1444
- 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}`);
1445
- assert.isFalse(isBeingConstructed(vm), `Failed to construct '${getComponentTag(vm)}': The result must not have attributes.`);
1446
- assert.invariant(!isObject(newValue) || isNull(newValue), `Invalid value "${newValue}" for "${propName}" of ${vm}. Value cannot be an object, must be a primitive value.`);
1447
- }
1448
- updateComponentValue(vm, propName, newValue);
1449
- return set.call(vm.elm, newValue);
1450
- },
1451
- };
1457
+ };
1452
1458
  }
1453
1459
  const EMPTY_REFS = freeze(create(null));
1454
1460
  const refsCache = new WeakMap();
@@ -1458,345 +1464,444 @@ const refsCache = new WeakMap();
1458
1464
  **/
1459
1465
  // @ts-ignore
1460
1466
  const LightningElement = function () {
1461
- // This should be as performant as possible, while any initialization should be done lazily
1462
- if (isNull(vmBeingConstructed)) {
1463
- // Thrown when doing something like `new LightningElement()` or
1464
- // `class Foo extends LightningElement {}; new Foo()`
1465
- throw new TypeError('Illegal constructor');
1466
- }
1467
- const vm = vmBeingConstructed;
1468
- const { def, elm } = vm;
1469
- const { bridge } = def;
1467
+ // This should be as performant as possible, while any initialization should be done lazily
1468
+ if (isNull(vmBeingConstructed)) {
1469
+ // Thrown when doing something like `new LightningElement()` or
1470
+ // `class Foo extends LightningElement {}; new Foo()`
1471
+ throw new TypeError('Illegal constructor');
1472
+ }
1473
+ const vm = vmBeingConstructed;
1474
+ const {
1475
+ def,
1476
+ elm
1477
+ } = vm;
1478
+ const {
1479
+ bridge
1480
+ } = def;
1481
+ if (process.env.NODE_ENV !== 'production') {
1482
+ const {
1483
+ assertInstanceOfHTMLElement
1484
+ } = vm.renderer;
1485
+ assertInstanceOfHTMLElement(vm.elm, `Component creation requires a DOM element to be associated to ${vm}.`);
1486
+ }
1487
+ const component = this;
1488
+ setPrototypeOf(elm, bridge.prototype);
1489
+ vm.component = this;
1490
+ // Locker hooks assignment. When the LWC engine run with Locker, Locker intercepts all the new
1491
+ // component creation and passes hooks to instrument all the component interactions with the
1492
+ // engine. We are intentionally hiding this argument from the formal API of LightningElement
1493
+ // because we don't want folks to know about it just yet.
1494
+ if (arguments.length === 1) {
1495
+ const {
1496
+ callHook,
1497
+ setHook,
1498
+ getHook
1499
+ } = arguments[0];
1500
+ vm.callHook = callHook;
1501
+ vm.setHook = setHook;
1502
+ vm.getHook = getHook;
1503
+ }
1504
+ markLockerLiveObject(this);
1505
+ // Linking elm, shadow root and component with the VM.
1506
+ associateVM(component, vm);
1507
+ associateVM(elm, vm);
1508
+ if (vm.renderMode === 1 /* RenderMode.Shadow */) {
1509
+ vm.renderRoot = doAttachShadow(vm);
1510
+ } else {
1511
+ vm.renderRoot = elm;
1512
+ }
1513
+ // Adding extra guard rails in DEV mode.
1514
+ if (process.env.NODE_ENV !== 'production') {
1515
+ patchCustomElementWithRestrictions(elm);
1516
+ patchComponentWithRestrictions(component);
1517
+ }
1518
+ return this;
1519
+ };
1520
+ function doAttachShadow(vm) {
1521
+ const {
1522
+ elm,
1523
+ mode,
1524
+ shadowMode,
1525
+ def: {
1526
+ ctor
1527
+ },
1528
+ renderer: {
1529
+ attachShadow
1530
+ }
1531
+ } = vm;
1532
+ const shadowRoot = attachShadow(elm, {
1533
+ [KEY__SYNTHETIC_MODE]: shadowMode === 1 /* ShadowMode.Synthetic */,
1534
+ delegatesFocus: Boolean(ctor.delegatesFocus),
1535
+ mode
1536
+ });
1537
+ vm.shadowRoot = shadowRoot;
1538
+ associateVM(shadowRoot, vm);
1539
+ if (process.env.NODE_ENV !== 'production') {
1540
+ patchShadowRootWithRestrictions(shadowRoot);
1541
+ }
1542
+ return shadowRoot;
1543
+ }
1544
+ function warnIfInvokedDuringConstruction(vm, methodOrPropName) {
1545
+ if (isBeingConstructed(vm)) {
1546
+ 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.`);
1547
+ }
1548
+ }
1549
+ // @ts-ignore
1550
+ LightningElement.prototype = {
1551
+ constructor: LightningElement,
1552
+ dispatchEvent(event) {
1553
+ const vm = getAssociatedVM(this);
1554
+ const {
1555
+ elm,
1556
+ renderer: {
1557
+ dispatchEvent
1558
+ }
1559
+ } = vm;
1560
+ return dispatchEvent(elm, event);
1561
+ },
1562
+ addEventListener(type, listener, options) {
1563
+ const vm = getAssociatedVM(this);
1564
+ const {
1565
+ elm,
1566
+ renderer: {
1567
+ addEventListener
1568
+ }
1569
+ } = vm;
1470
1570
  if (process.env.NODE_ENV !== 'production') {
1471
- const { assertInstanceOfHTMLElement } = vm.renderer;
1472
- assertInstanceOfHTMLElement(vm.elm, `Component creation requires a DOM element to be associated to ${vm}.`);
1473
- }
1474
- const component = this;
1475
- setPrototypeOf(elm, bridge.prototype);
1476
- vm.component = this;
1477
- // Locker hooks assignment. When the LWC engine run with Locker, Locker intercepts all the new
1478
- // component creation and passes hooks to instrument all the component interactions with the
1479
- // engine. We are intentionally hiding this argument from the formal API of LightningElement
1480
- // because we don't want folks to know about it just yet.
1481
- if (arguments.length === 1) {
1482
- const { callHook, setHook, getHook } = arguments[0];
1483
- vm.callHook = callHook;
1484
- vm.setHook = setHook;
1485
- vm.getHook = getHook;
1486
- }
1487
- markLockerLiveObject(this);
1488
- // Linking elm, shadow root and component with the VM.
1489
- associateVM(component, vm);
1490
- associateVM(elm, vm);
1491
- if (vm.renderMode === 1 /* RenderMode.Shadow */) {
1492
- vm.renderRoot = doAttachShadow(vm);
1571
+ const vmBeingRendered = getVMBeingRendered();
1572
+ assert.invariant(!isInvokingRender, `${vmBeingRendered}.render() method has side effects on the state of ${vm} by adding an event listener for "${type}".`);
1573
+ assert.invariant(!isUpdatingTemplate, `Updating the template of ${vmBeingRendered} has side effects on the state of ${vm} by adding an event listener for "${type}".`);
1574
+ assert.invariant(isFunction$1(listener), `Invalid second argument for this.addEventListener() in ${vm} for event "${type}". Expected an EventListener but received ${listener}.`);
1575
+ }
1576
+ const wrappedListener = getWrappedComponentsListener(vm, listener);
1577
+ addEventListener(elm, type, wrappedListener, options);
1578
+ },
1579
+ removeEventListener(type, listener, options) {
1580
+ const vm = getAssociatedVM(this);
1581
+ const {
1582
+ elm,
1583
+ renderer: {
1584
+ removeEventListener
1585
+ }
1586
+ } = vm;
1587
+ const wrappedListener = getWrappedComponentsListener(vm, listener);
1588
+ removeEventListener(elm, type, wrappedListener, options);
1589
+ },
1590
+ hasAttribute(name) {
1591
+ const vm = getAssociatedVM(this);
1592
+ const {
1593
+ elm,
1594
+ renderer: {
1595
+ getAttribute
1596
+ }
1597
+ } = vm;
1598
+ return !isNull(getAttribute(elm, name));
1599
+ },
1600
+ hasAttributeNS(namespace, name) {
1601
+ const vm = getAssociatedVM(this);
1602
+ const {
1603
+ elm,
1604
+ renderer: {
1605
+ getAttribute
1606
+ }
1607
+ } = vm;
1608
+ return !isNull(getAttribute(elm, name, namespace));
1609
+ },
1610
+ removeAttribute(name) {
1611
+ const vm = getAssociatedVM(this);
1612
+ const {
1613
+ elm,
1614
+ renderer: {
1615
+ removeAttribute
1616
+ }
1617
+ } = vm;
1618
+ unlockAttribute(elm, name);
1619
+ removeAttribute(elm, name);
1620
+ lockAttribute();
1621
+ },
1622
+ removeAttributeNS(namespace, name) {
1623
+ const {
1624
+ elm,
1625
+ renderer: {
1626
+ removeAttribute
1627
+ }
1628
+ } = getAssociatedVM(this);
1629
+ unlockAttribute(elm, name);
1630
+ removeAttribute(elm, name, namespace);
1631
+ lockAttribute();
1632
+ },
1633
+ getAttribute(name) {
1634
+ const vm = getAssociatedVM(this);
1635
+ const {
1636
+ elm
1637
+ } = vm;
1638
+ const {
1639
+ getAttribute
1640
+ } = vm.renderer;
1641
+ return getAttribute(elm, name);
1642
+ },
1643
+ getAttributeNS(namespace, name) {
1644
+ const vm = getAssociatedVM(this);
1645
+ const {
1646
+ elm
1647
+ } = vm;
1648
+ const {
1649
+ getAttribute
1650
+ } = vm.renderer;
1651
+ return getAttribute(elm, name, namespace);
1652
+ },
1653
+ setAttribute(name, value) {
1654
+ const vm = getAssociatedVM(this);
1655
+ const {
1656
+ elm,
1657
+ renderer: {
1658
+ setAttribute
1659
+ }
1660
+ } = vm;
1661
+ if (process.env.NODE_ENV !== 'production') {
1662
+ assert.isFalse(isBeingConstructed(vm), `Failed to construct '${getComponentTag(vm)}': The result must not have attributes.`);
1663
+ }
1664
+ unlockAttribute(elm, name);
1665
+ setAttribute(elm, name, value);
1666
+ lockAttribute();
1667
+ },
1668
+ setAttributeNS(namespace, name, value) {
1669
+ const vm = getAssociatedVM(this);
1670
+ const {
1671
+ elm,
1672
+ renderer: {
1673
+ setAttribute
1674
+ }
1675
+ } = vm;
1676
+ if (process.env.NODE_ENV !== 'production') {
1677
+ assert.isFalse(isBeingConstructed(vm), `Failed to construct '${getComponentTag(vm)}': The result must not have attributes.`);
1678
+ }
1679
+ unlockAttribute(elm, name);
1680
+ setAttribute(elm, name, value, namespace);
1681
+ lockAttribute();
1682
+ },
1683
+ getBoundingClientRect() {
1684
+ const vm = getAssociatedVM(this);
1685
+ const {
1686
+ elm,
1687
+ renderer: {
1688
+ getBoundingClientRect
1689
+ }
1690
+ } = vm;
1691
+ if (process.env.NODE_ENV !== 'production') {
1692
+ warnIfInvokedDuringConstruction(vm, 'getBoundingClientRect()');
1493
1693
  }
1494
- else {
1495
- vm.renderRoot = elm;
1694
+ return getBoundingClientRect(elm);
1695
+ },
1696
+ get isConnected() {
1697
+ const vm = getAssociatedVM(this);
1698
+ const {
1699
+ elm,
1700
+ renderer: {
1701
+ isConnected
1702
+ }
1703
+ } = vm;
1704
+ return isConnected(elm);
1705
+ },
1706
+ get classList() {
1707
+ const vm = getAssociatedVM(this);
1708
+ const {
1709
+ elm,
1710
+ renderer: {
1711
+ getClassList
1712
+ }
1713
+ } = vm;
1714
+ if (process.env.NODE_ENV !== 'production') {
1715
+ // TODO [#1290]: this still fails in dev but works in production, eventually, we should
1716
+ // just throw in all modes
1717
+ 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.`);
1718
+ }
1719
+ return getClassList(elm);
1720
+ },
1721
+ get template() {
1722
+ const vm = getAssociatedVM(this);
1723
+ if (process.env.NODE_ENV !== 'production') {
1724
+ if (vm.renderMode === 0 /* RenderMode.Light */) {
1725
+ 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`.');
1726
+ }
1727
+ }
1728
+ return vm.shadowRoot;
1729
+ },
1730
+ get refs() {
1731
+ const vm = getAssociatedVM(this);
1732
+ if (isUpdatingTemplate) {
1733
+ if (process.env.NODE_ENV !== 'production') {
1734
+ 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().`);
1735
+ }
1736
+ // If the template is in the process of being updated, then we don't want to go through the normal
1737
+ // process of returning the refs and caching them, because the state of the refs is unstable.
1738
+ // This can happen if e.g. a template contains `<div class={foo}></div>` and `foo` is computed
1739
+ // based on `this.refs.bar`.
1740
+ return;
1496
1741
  }
1497
- // Adding extra guard rails in DEV mode.
1498
1742
  if (process.env.NODE_ENV !== 'production') {
1499
- patchCustomElementWithRestrictions(elm);
1500
- patchComponentWithRestrictions(component);
1743
+ warnIfInvokedDuringConstruction(vm, 'refs');
1501
1744
  }
1502
- return this;
1503
- };
1504
- function doAttachShadow(vm) {
1505
- const { elm, mode, shadowMode, def: { ctor }, renderer: { attachShadow }, } = vm;
1506
- const shadowRoot = attachShadow(elm, {
1507
- [KEY__SYNTHETIC_MODE]: shadowMode === 1 /* ShadowMode.Synthetic */,
1508
- delegatesFocus: Boolean(ctor.delegatesFocus),
1509
- mode,
1745
+ const {
1746
+ refVNodes,
1747
+ hasRefVNodes,
1748
+ cmpTemplate
1749
+ } = vm;
1750
+ // If the `cmpTemplate` is null, that means that the template has not been rendered yet. Most likely this occurs
1751
+ // if `this.refs` is called during the `connectedCallback` phase. The DOM elements have not been rendered yet,
1752
+ // so log a warning. Note we also check `isBeingConstructed()` to avoid a double warning (due to
1753
+ // `warnIfInvokedDuringConstruction` above).
1754
+ if (process.env.NODE_ENV !== 'production' && isNull(cmpTemplate) && !isBeingConstructed(vm)) {
1755
+ 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().`);
1756
+ }
1757
+ // For backwards compatibility with component written before template refs
1758
+ // were introduced, we return undefined if the template has no refs defined
1759
+ // anywhere. This fixes components that may want to add an expando called `refs`
1760
+ // and are checking if it exists with `if (this.refs)` before adding it.
1761
+ // Note it is not sufficient to just check if `refVNodes` is null or empty,
1762
+ // because a template may have `lwc:ref` defined within a falsy `if:true` block.
1763
+ if (!hasRefVNodes) {
1764
+ return;
1765
+ }
1766
+ // For templates that are using `lwc:ref`, if there are no refs currently available
1767
+ // (e.g. refs inside of a falsy `if:true` block), we return an empty object.
1768
+ if (isNull(refVNodes)) {
1769
+ return EMPTY_REFS;
1770
+ }
1771
+ // The refNodes can be cached based on the refVNodes, since the refVNodes
1772
+ // are recreated from scratch every time the template is rendered.
1773
+ // This happens with `vm.refVNodes = null` in `template.ts` in `@lwc/engine-core`.
1774
+ let refs = refsCache.get(refVNodes);
1775
+ if (isUndefined$1(refs)) {
1776
+ refs = create(null);
1777
+ for (const key of keys(refVNodes)) {
1778
+ refs[key] = refVNodes[key].elm;
1779
+ }
1780
+ freeze(refs);
1781
+ refsCache.set(refVNodes, refs);
1782
+ }
1783
+ return refs;
1784
+ },
1785
+ // For backwards compat, we allow component authors to set `refs` as an expando
1786
+ set refs(value) {
1787
+ defineProperty(this, 'refs', {
1788
+ configurable: true,
1789
+ enumerable: true,
1790
+ writable: true,
1791
+ value
1510
1792
  });
1511
- vm.shadowRoot = shadowRoot;
1512
- associateVM(shadowRoot, vm);
1793
+ },
1794
+ get shadowRoot() {
1795
+ // From within the component instance, the shadowRoot is always reported as "closed".
1796
+ // Authors should rely on this.template instead.
1797
+ return null;
1798
+ },
1799
+ get children() {
1800
+ const vm = getAssociatedVM(this);
1801
+ const renderer = vm.renderer;
1513
1802
  if (process.env.NODE_ENV !== 'production') {
1514
- patchShadowRootWithRestrictions(shadowRoot);
1803
+ warnIfInvokedDuringConstruction(vm, 'children');
1515
1804
  }
1516
- return shadowRoot;
1517
- }
1518
- function warnIfInvokedDuringConstruction(vm, methodOrPropName) {
1519
- if (isBeingConstructed(vm)) {
1520
- 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.`);
1805
+ return renderer.getChildren(vm.elm);
1806
+ },
1807
+ get childNodes() {
1808
+ const vm = getAssociatedVM(this);
1809
+ const renderer = vm.renderer;
1810
+ if (process.env.NODE_ENV !== 'production') {
1811
+ warnIfInvokedDuringConstruction(vm, 'childNodes');
1521
1812
  }
1522
- }
1523
- // @ts-ignore
1524
- LightningElement.prototype = {
1525
- constructor: LightningElement,
1526
- dispatchEvent(event) {
1527
- const vm = getAssociatedVM(this);
1528
- const { elm, renderer: { dispatchEvent }, } = vm;
1529
- return dispatchEvent(elm, event);
1530
- },
1531
- addEventListener(type, listener, options) {
1532
- const vm = getAssociatedVM(this);
1533
- const { elm, renderer: { addEventListener }, } = vm;
1534
- if (process.env.NODE_ENV !== 'production') {
1535
- const vmBeingRendered = getVMBeingRendered();
1536
- assert.invariant(!isInvokingRender, `${vmBeingRendered}.render() method has side effects on the state of ${vm} by adding an event listener for "${type}".`);
1537
- assert.invariant(!isUpdatingTemplate, `Updating the template of ${vmBeingRendered} has side effects on the state of ${vm} by adding an event listener for "${type}".`);
1538
- assert.invariant(isFunction$1(listener), `Invalid second argument for this.addEventListener() in ${vm} for event "${type}". Expected an EventListener but received ${listener}.`);
1539
- }
1540
- const wrappedListener = getWrappedComponentsListener(vm, listener);
1541
- addEventListener(elm, type, wrappedListener, options);
1542
- },
1543
- removeEventListener(type, listener, options) {
1544
- const vm = getAssociatedVM(this);
1545
- const { elm, renderer: { removeEventListener }, } = vm;
1546
- const wrappedListener = getWrappedComponentsListener(vm, listener);
1547
- removeEventListener(elm, type, wrappedListener, options);
1548
- },
1549
- hasAttribute(name) {
1550
- const vm = getAssociatedVM(this);
1551
- const { elm, renderer: { getAttribute }, } = vm;
1552
- return !isNull(getAttribute(elm, name));
1553
- },
1554
- hasAttributeNS(namespace, name) {
1555
- const vm = getAssociatedVM(this);
1556
- const { elm, renderer: { getAttribute }, } = vm;
1557
- return !isNull(getAttribute(elm, name, namespace));
1558
- },
1559
- removeAttribute(name) {
1560
- const vm = getAssociatedVM(this);
1561
- const { elm, renderer: { removeAttribute }, } = vm;
1562
- unlockAttribute(elm, name);
1563
- removeAttribute(elm, name);
1564
- lockAttribute();
1565
- },
1566
- removeAttributeNS(namespace, name) {
1567
- const { elm, renderer: { removeAttribute }, } = getAssociatedVM(this);
1568
- unlockAttribute(elm, name);
1569
- removeAttribute(elm, name, namespace);
1570
- lockAttribute();
1571
- },
1572
- getAttribute(name) {
1573
- const vm = getAssociatedVM(this);
1574
- const { elm } = vm;
1575
- const { getAttribute } = vm.renderer;
1576
- return getAttribute(elm, name);
1577
- },
1578
- getAttributeNS(namespace, name) {
1579
- const vm = getAssociatedVM(this);
1580
- const { elm } = vm;
1581
- const { getAttribute } = vm.renderer;
1582
- return getAttribute(elm, name, namespace);
1583
- },
1584
- setAttribute(name, value) {
1585
- const vm = getAssociatedVM(this);
1586
- const { elm, renderer: { setAttribute }, } = vm;
1587
- if (process.env.NODE_ENV !== 'production') {
1588
- assert.isFalse(isBeingConstructed(vm), `Failed to construct '${getComponentTag(vm)}': The result must not have attributes.`);
1589
- }
1590
- unlockAttribute(elm, name);
1591
- setAttribute(elm, name, value);
1592
- lockAttribute();
1593
- },
1594
- setAttributeNS(namespace, name, value) {
1595
- const vm = getAssociatedVM(this);
1596
- const { elm, renderer: { setAttribute }, } = vm;
1597
- if (process.env.NODE_ENV !== 'production') {
1598
- assert.isFalse(isBeingConstructed(vm), `Failed to construct '${getComponentTag(vm)}': The result must not have attributes.`);
1599
- }
1600
- unlockAttribute(elm, name);
1601
- setAttribute(elm, name, value, namespace);
1602
- lockAttribute();
1603
- },
1604
- getBoundingClientRect() {
1605
- const vm = getAssociatedVM(this);
1606
- const { elm, renderer: { getBoundingClientRect }, } = vm;
1607
- if (process.env.NODE_ENV !== 'production') {
1608
- warnIfInvokedDuringConstruction(vm, 'getBoundingClientRect()');
1609
- }
1610
- return getBoundingClientRect(elm);
1611
- },
1612
- get isConnected() {
1613
- const vm = getAssociatedVM(this);
1614
- const { elm, renderer: { isConnected }, } = vm;
1615
- return isConnected(elm);
1616
- },
1617
- get classList() {
1618
- const vm = getAssociatedVM(this);
1619
- const { elm, renderer: { getClassList }, } = vm;
1620
- if (process.env.NODE_ENV !== 'production') {
1621
- // TODO [#1290]: this still fails in dev but works in production, eventually, we should
1622
- // just throw in all modes
1623
- 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.`);
1624
- }
1625
- return getClassList(elm);
1626
- },
1627
- get template() {
1628
- const vm = getAssociatedVM(this);
1629
- if (process.env.NODE_ENV !== 'production') {
1630
- if (vm.renderMode === 0 /* RenderMode.Light */) {
1631
- 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`.');
1632
- }
1633
- }
1634
- return vm.shadowRoot;
1635
- },
1636
- get refs() {
1637
- const vm = getAssociatedVM(this);
1638
- if (isUpdatingTemplate) {
1639
- if (process.env.NODE_ENV !== 'production') {
1640
- 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().`);
1641
- }
1642
- // If the template is in the process of being updated, then we don't want to go through the normal
1643
- // process of returning the refs and caching them, because the state of the refs is unstable.
1644
- // This can happen if e.g. a template contains `<div class={foo}></div>` and `foo` is computed
1645
- // based on `this.refs.bar`.
1646
- return;
1647
- }
1648
- if (process.env.NODE_ENV !== 'production') {
1649
- warnIfInvokedDuringConstruction(vm, 'refs');
1650
- }
1651
- const { refVNodes, hasRefVNodes, cmpTemplate } = vm;
1652
- // If the `cmpTemplate` is null, that means that the template has not been rendered yet. Most likely this occurs
1653
- // if `this.refs` is called during the `connectedCallback` phase. The DOM elements have not been rendered yet,
1654
- // so log a warning. Note we also check `isBeingConstructed()` to avoid a double warning (due to
1655
- // `warnIfInvokedDuringConstruction` above).
1656
- if (process.env.NODE_ENV !== 'production' &&
1657
- isNull(cmpTemplate) &&
1658
- !isBeingConstructed(vm)) {
1659
- logError(`this.refs is undefined for ${getComponentTag(vm)}. This is either because the attached template has no "lwc:ref" directive, or this.refs was ` +
1660
- `invoked before renderedCallback(). Use this.refs only when the referenced HTML elements have ` +
1661
- `been rendered to the DOM, such as within renderedCallback() or disconnectedCallback().`);
1662
- }
1663
- // For backwards compatibility with component written before template refs
1664
- // were introduced, we return undefined if the template has no refs defined
1665
- // anywhere. This fixes components that may want to add an expando called `refs`
1666
- // and are checking if it exists with `if (this.refs)` before adding it.
1667
- // Note it is not sufficient to just check if `refVNodes` is null or empty,
1668
- // because a template may have `lwc:ref` defined within a falsy `if:true` block.
1669
- if (!hasRefVNodes) {
1670
- return;
1671
- }
1672
- // For templates that are using `lwc:ref`, if there are no refs currently available
1673
- // (e.g. refs inside of a falsy `if:true` block), we return an empty object.
1674
- if (isNull(refVNodes)) {
1675
- return EMPTY_REFS;
1676
- }
1677
- // The refNodes can be cached based on the refVNodes, since the refVNodes
1678
- // are recreated from scratch every time the template is rendered.
1679
- // This happens with `vm.refVNodes = null` in `template.ts` in `@lwc/engine-core`.
1680
- let refs = refsCache.get(refVNodes);
1681
- if (isUndefined$1(refs)) {
1682
- refs = create(null);
1683
- for (const key of keys(refVNodes)) {
1684
- refs[key] = refVNodes[key].elm;
1685
- }
1686
- freeze(refs);
1687
- refsCache.set(refVNodes, refs);
1688
- }
1689
- return refs;
1690
- },
1691
- // For backwards compat, we allow component authors to set `refs` as an expando
1692
- set refs(value) {
1693
- defineProperty(this, 'refs', {
1694
- configurable: true,
1695
- enumerable: true,
1696
- writable: true,
1697
- value,
1698
- });
1699
- },
1700
- get shadowRoot() {
1701
- // From within the component instance, the shadowRoot is always reported as "closed".
1702
- // Authors should rely on this.template instead.
1703
- return null;
1704
- },
1705
- get children() {
1706
- const vm = getAssociatedVM(this);
1707
- const renderer = vm.renderer;
1708
- if (process.env.NODE_ENV !== 'production') {
1709
- warnIfInvokedDuringConstruction(vm, 'children');
1710
- }
1711
- return renderer.getChildren(vm.elm);
1712
- },
1713
- get childNodes() {
1714
- const vm = getAssociatedVM(this);
1715
- const renderer = vm.renderer;
1716
- if (process.env.NODE_ENV !== 'production') {
1717
- warnIfInvokedDuringConstruction(vm, 'childNodes');
1718
- }
1719
- return renderer.getChildNodes(vm.elm);
1720
- },
1721
- get firstChild() {
1722
- const vm = getAssociatedVM(this);
1723
- const renderer = vm.renderer;
1724
- if (process.env.NODE_ENV !== 'production') {
1725
- warnIfInvokedDuringConstruction(vm, 'firstChild');
1726
- }
1727
- return renderer.getFirstChild(vm.elm);
1728
- },
1729
- get firstElementChild() {
1730
- const vm = getAssociatedVM(this);
1731
- const renderer = vm.renderer;
1732
- if (process.env.NODE_ENV !== 'production') {
1733
- warnIfInvokedDuringConstruction(vm, 'firstElementChild');
1734
- }
1735
- return renderer.getFirstElementChild(vm.elm);
1736
- },
1737
- get lastChild() {
1738
- const vm = getAssociatedVM(this);
1739
- const renderer = vm.renderer;
1740
- if (process.env.NODE_ENV !== 'production') {
1741
- warnIfInvokedDuringConstruction(vm, 'lastChild');
1742
- }
1743
- return renderer.getLastChild(vm.elm);
1744
- },
1745
- get lastElementChild() {
1746
- const vm = getAssociatedVM(this);
1747
- const renderer = vm.renderer;
1748
- if (process.env.NODE_ENV !== 'production') {
1749
- warnIfInvokedDuringConstruction(vm, 'lastElementChild');
1750
- }
1751
- return renderer.getLastElementChild(vm.elm);
1752
- },
1753
- render() {
1754
- const vm = getAssociatedVM(this);
1755
- return vm.def.template;
1756
- },
1757
- toString() {
1758
- const vm = getAssociatedVM(this);
1759
- return `[object ${vm.def.name}]`;
1760
- },
1813
+ return renderer.getChildNodes(vm.elm);
1814
+ },
1815
+ get firstChild() {
1816
+ const vm = getAssociatedVM(this);
1817
+ const renderer = vm.renderer;
1818
+ if (process.env.NODE_ENV !== 'production') {
1819
+ warnIfInvokedDuringConstruction(vm, 'firstChild');
1820
+ }
1821
+ return renderer.getFirstChild(vm.elm);
1822
+ },
1823
+ get firstElementChild() {
1824
+ const vm = getAssociatedVM(this);
1825
+ const renderer = vm.renderer;
1826
+ if (process.env.NODE_ENV !== 'production') {
1827
+ warnIfInvokedDuringConstruction(vm, 'firstElementChild');
1828
+ }
1829
+ return renderer.getFirstElementChild(vm.elm);
1830
+ },
1831
+ get lastChild() {
1832
+ const vm = getAssociatedVM(this);
1833
+ const renderer = vm.renderer;
1834
+ if (process.env.NODE_ENV !== 'production') {
1835
+ warnIfInvokedDuringConstruction(vm, 'lastChild');
1836
+ }
1837
+ return renderer.getLastChild(vm.elm);
1838
+ },
1839
+ get lastElementChild() {
1840
+ const vm = getAssociatedVM(this);
1841
+ const renderer = vm.renderer;
1842
+ if (process.env.NODE_ENV !== 'production') {
1843
+ warnIfInvokedDuringConstruction(vm, 'lastElementChild');
1844
+ }
1845
+ return renderer.getLastElementChild(vm.elm);
1846
+ },
1847
+ render() {
1848
+ const vm = getAssociatedVM(this);
1849
+ return vm.def.template;
1850
+ },
1851
+ toString() {
1852
+ const vm = getAssociatedVM(this);
1853
+ return `[object ${vm.def.name}]`;
1854
+ }
1761
1855
  };
1762
1856
  const queryAndChildGetterDescriptors = create(null);
1763
- const queryMethods = [
1764
- 'getElementsByClassName',
1765
- 'getElementsByTagName',
1766
- 'querySelector',
1767
- 'querySelectorAll',
1768
- ];
1857
+ const queryMethods = ['getElementsByClassName', 'getElementsByTagName', 'querySelector', 'querySelectorAll'];
1769
1858
  // Generic passthrough for query APIs on HTMLElement to the relevant Renderer APIs
1770
1859
  for (const queryMethod of queryMethods) {
1771
- queryAndChildGetterDescriptors[queryMethod] = {
1772
- value(arg) {
1773
- const vm = getAssociatedVM(this);
1774
- const { elm, renderer } = vm;
1775
- if (process.env.NODE_ENV !== 'production') {
1776
- warnIfInvokedDuringConstruction(vm, `${queryMethod}()`);
1777
- }
1778
- return renderer[queryMethod](elm, arg);
1779
- },
1780
- configurable: true,
1781
- enumerable: true,
1782
- writable: true,
1783
- };
1860
+ queryAndChildGetterDescriptors[queryMethod] = {
1861
+ value(arg) {
1862
+ const vm = getAssociatedVM(this);
1863
+ const {
1864
+ elm,
1865
+ renderer
1866
+ } = vm;
1867
+ if (process.env.NODE_ENV !== 'production') {
1868
+ warnIfInvokedDuringConstruction(vm, `${queryMethod}()`);
1869
+ }
1870
+ return renderer[queryMethod](elm, arg);
1871
+ },
1872
+ configurable: true,
1873
+ enumerable: true,
1874
+ writable: true
1875
+ };
1784
1876
  }
1785
1877
  defineProperties(LightningElement.prototype, queryAndChildGetterDescriptors);
1786
1878
  const lightningBasedDescriptors = create(null);
1787
1879
  for (const propName in HTMLElementOriginalDescriptors) {
1788
- lightningBasedDescriptors[propName] = createBridgeToElementDescriptor(propName, HTMLElementOriginalDescriptors[propName]);
1880
+ lightningBasedDescriptors[propName] = createBridgeToElementDescriptor(propName, HTMLElementOriginalDescriptors[propName]);
1789
1881
  }
1790
1882
  defineProperties(LightningElement.prototype, lightningBasedDescriptors);
1883
+ function applyAriaReflectionToLightningElement() {
1884
+ // If ARIA reflection is not applied globally to Element.prototype, or if we are running server-side,
1885
+ // apply it to LightningElement.prototype.
1886
+ // This allows `this.aria*` property accessors to work from inside a component, and to reflect `aria-*` attrs.
1887
+ applyAriaReflection(LightningElement.prototype);
1888
+ }
1889
+ // The reason for this odd if/else branching is limitations in @lwc/features:
1890
+ // https://github.com/salesforce/lwc/blob/master/packages/%40lwc/features/README.md#only-works-with-if-statements
1891
+ if (lwcRuntimeFlags.DISABLE_ARIA_REFLECTION_POLYFILL) {
1892
+ applyAriaReflectionToLightningElement();
1893
+ } else if (!process.env.IS_BROWSER) {
1894
+ applyAriaReflectionToLightningElement();
1895
+ }
1791
1896
  defineProperty(LightningElement, 'CustomElementConstructor', {
1792
- get() {
1793
- // If required, a runtime-specific implementation must be defined.
1794
- throw new ReferenceError('The current runtime does not support CustomElementConstructor.');
1795
- },
1796
- configurable: true,
1897
+ get() {
1898
+ // If required, a runtime-specific implementation must be defined.
1899
+ throw new ReferenceError('The current runtime does not support CustomElementConstructor.');
1900
+ },
1901
+ configurable: true
1797
1902
  });
1798
1903
  if (process.env.NODE_ENV !== 'production') {
1799
- patchLightningElementPrototypeWithRestrictions(LightningElement.prototype);
1904
+ patchLightningElementPrototypeWithRestrictions(LightningElement.prototype);
1800
1905
  }
1801
1906
 
1802
1907
  function createObservedFieldPropertyDescriptor(key) {
@@ -2256,138 +2361,161 @@ function sanitizeAttribute(tagName, namespaceUri, attrName, attrValue) {
2256
2361
  const cachedGetterByKey = create(null);
2257
2362
  const cachedSetterByKey = create(null);
2258
2363
  function createGetter(key) {
2259
- let fn = cachedGetterByKey[key];
2260
- if (isUndefined$1(fn)) {
2261
- fn = cachedGetterByKey[key] = function () {
2262
- const vm = getAssociatedVM(this);
2263
- const { getHook } = vm;
2264
- return getHook(vm.component, key);
2265
- };
2266
- }
2267
- return fn;
2364
+ let fn = cachedGetterByKey[key];
2365
+ if (isUndefined$1(fn)) {
2366
+ fn = cachedGetterByKey[key] = function () {
2367
+ const vm = getAssociatedVM(this);
2368
+ const {
2369
+ getHook
2370
+ } = vm;
2371
+ return getHook(vm.component, key);
2372
+ };
2373
+ }
2374
+ return fn;
2268
2375
  }
2269
2376
  function createSetter(key) {
2270
- let fn = cachedSetterByKey[key];
2271
- if (isUndefined$1(fn)) {
2272
- fn = cachedSetterByKey[key] = function (newValue) {
2273
- const vm = getAssociatedVM(this);
2274
- const { setHook } = vm;
2275
- newValue = getReadOnlyProxy(newValue);
2276
- setHook(vm.component, key, newValue);
2277
- };
2278
- }
2279
- return fn;
2377
+ let fn = cachedSetterByKey[key];
2378
+ if (isUndefined$1(fn)) {
2379
+ fn = cachedSetterByKey[key] = function (newValue) {
2380
+ const vm = getAssociatedVM(this);
2381
+ const {
2382
+ setHook
2383
+ } = vm;
2384
+ newValue = getReadOnlyProxy(newValue);
2385
+ setHook(vm.component, key, newValue);
2386
+ };
2387
+ }
2388
+ return fn;
2280
2389
  }
2281
2390
  function createMethodCaller(methodName) {
2282
- return function () {
2283
- const vm = getAssociatedVM(this);
2284
- const { callHook, component } = vm;
2285
- const fn = component[methodName];
2286
- return callHook(vm.component, fn, ArraySlice.call(arguments));
2287
- };
2391
+ return function () {
2392
+ const vm = getAssociatedVM(this);
2393
+ const {
2394
+ callHook,
2395
+ component
2396
+ } = vm;
2397
+ const fn = component[methodName];
2398
+ return callHook(vm.component, fn, ArraySlice.call(arguments));
2399
+ };
2288
2400
  }
2289
2401
  function createAttributeChangedCallback(attributeToPropMap, superAttributeChangedCallback) {
2290
- return function attributeChangedCallback(attrName, oldValue, newValue) {
2291
- if (oldValue === newValue) {
2292
- // Ignore same values.
2293
- return;
2294
- }
2295
- const propName = attributeToPropMap[attrName];
2296
- if (isUndefined$1(propName)) {
2297
- if (!isUndefined$1(superAttributeChangedCallback)) {
2298
- // delegate unknown attributes to the super.
2299
- // Typescript does not like it when you treat the `arguments` object as an array
2300
- // @ts-ignore type-mismatch
2301
- superAttributeChangedCallback.apply(this, arguments);
2302
- }
2303
- return;
2304
- }
2305
- if (!isAttributeLocked(this, attrName)) {
2306
- // Ignore changes triggered by the engine itself during:
2307
- // * diffing when public props are attempting to reflect to the DOM
2308
- // * component via `this.setAttribute()`, should never update the prop
2309
- // Both cases, the setAttribute call is always wrapped by the unlocking of the
2310
- // attribute to be changed
2311
- return;
2312
- }
2313
- // Reflect attribute change to the corresponding property when changed from outside.
2314
- this[propName] = newValue;
2315
- };
2316
- }
2317
- function HTMLBridgeElementFactory(SuperClass, props, methods) {
2318
- let HTMLBridgeElement;
2319
- /**
2320
- * Modern browsers will have all Native Constructors as regular Classes
2321
- * and must be instantiated with the new keyword. In older browsers,
2322
- * specifically IE11, those are objects with a prototype property defined,
2323
- * since they are not supposed to be extended or instantiated with the
2324
- * new keyword. This forking logic supports both cases, specifically because
2325
- * wc.ts relies on the construction path of the bridges to create new
2326
- * fully qualifying web components.
2327
- */
2328
- if (isFunction$1(SuperClass)) {
2329
- HTMLBridgeElement = class extends SuperClass {
2330
- };
2331
- }
2332
- else {
2333
- HTMLBridgeElement = function () {
2334
- // Bridge classes are not supposed to be instantiated directly in
2335
- // browsers that do not support web components.
2336
- throw new TypeError('Illegal constructor');
2337
- };
2338
- // prototype inheritance dance
2339
- setPrototypeOf(HTMLBridgeElement, SuperClass);
2340
- setPrototypeOf(HTMLBridgeElement.prototype, SuperClass.prototype);
2341
- defineProperty(HTMLBridgeElement.prototype, 'constructor', {
2342
- writable: true,
2343
- configurable: true,
2344
- value: HTMLBridgeElement,
2345
- });
2402
+ return function attributeChangedCallback(attrName, oldValue, newValue) {
2403
+ if (oldValue === newValue) {
2404
+ // Ignore same values.
2405
+ return;
2346
2406
  }
2347
- // generating the hash table for attributes to avoid duplicate fields and facilitate validation
2348
- // and false positives in case of inheritance.
2349
- const attributeToPropMap = create(null);
2350
- const { attributeChangedCallback: superAttributeChangedCallback } = SuperClass.prototype;
2351
- const { observedAttributes: superObservedAttributes = [] } = SuperClass;
2352
- const descriptors = create(null);
2353
- // expose getters and setters for each public props on the new Element Bridge
2354
- for (let i = 0, len = props.length; i < len; i += 1) {
2355
- const propName = props[i];
2356
- attributeToPropMap[htmlPropertyToAttribute(propName)] = propName;
2357
- descriptors[propName] = {
2358
- get: createGetter(propName),
2359
- set: createSetter(propName),
2360
- enumerable: true,
2361
- configurable: true,
2362
- };
2407
+ const propName = attributeToPropMap[attrName];
2408
+ if (isUndefined$1(propName)) {
2409
+ if (!isUndefined$1(superAttributeChangedCallback)) {
2410
+ // delegate unknown attributes to the super.
2411
+ // Typescript does not like it when you treat the `arguments` object as an array
2412
+ // @ts-ignore type-mismatch
2413
+ superAttributeChangedCallback.apply(this, arguments);
2414
+ }
2415
+ return;
2363
2416
  }
2364
- // expose public methods as props on the new Element Bridge
2365
- for (let i = 0, len = methods.length; i < len; i += 1) {
2366
- const methodName = methods[i];
2367
- descriptors[methodName] = {
2368
- value: createMethodCaller(methodName),
2369
- writable: true,
2370
- configurable: true,
2371
- };
2417
+ if (!isAttributeLocked(this, attrName)) {
2418
+ // Ignore changes triggered by the engine itself during:
2419
+ // * diffing when public props are attempting to reflect to the DOM
2420
+ // * component via `this.setAttribute()`, should never update the prop
2421
+ // Both cases, the setAttribute call is always wrapped by the unlocking of the
2422
+ // attribute to be changed
2423
+ return;
2372
2424
  }
2373
- // creating a new attributeChangedCallback per bridge because they are bound to the corresponding
2374
- // map of attributes to props. We do this after all other props and methods to avoid the possibility
2375
- // of getting overrule by a class declaration in user-land, and we make it non-writable, non-configurable
2376
- // to preserve this definition.
2377
- descriptors.attributeChangedCallback = {
2378
- value: createAttributeChangedCallback(attributeToPropMap, superAttributeChangedCallback),
2425
+ // Reflect attribute change to the corresponding property when changed from outside.
2426
+ this[propName] = newValue;
2427
+ };
2428
+ }
2429
+ function HTMLBridgeElementFactory(SuperClass, props, methods) {
2430
+ let HTMLBridgeElement;
2431
+ /**
2432
+ * Modern browsers will have all Native Constructors as regular Classes
2433
+ * and must be instantiated with the new keyword. In older browsers,
2434
+ * specifically IE11, those are objects with a prototype property defined,
2435
+ * since they are not supposed to be extended or instantiated with the
2436
+ * new keyword. This forking logic supports both cases, specifically because
2437
+ * wc.ts relies on the construction path of the bridges to create new
2438
+ * fully qualifying web components.
2439
+ */
2440
+ if (isFunction$1(SuperClass)) {
2441
+ HTMLBridgeElement = class extends SuperClass {};
2442
+ } else {
2443
+ HTMLBridgeElement = function () {
2444
+ // Bridge classes are not supposed to be instantiated directly in
2445
+ // browsers that do not support web components.
2446
+ throw new TypeError('Illegal constructor');
2379
2447
  };
2380
- // Specify attributes for which we want to reflect changes back to their corresponding
2381
- // properties via attributeChangedCallback.
2382
- defineProperty(HTMLBridgeElement, 'observedAttributes', {
2383
- get() {
2384
- return [...superObservedAttributes, ...keys(attributeToPropMap)];
2385
- },
2448
+ // prototype inheritance dance
2449
+ setPrototypeOf(HTMLBridgeElement, SuperClass);
2450
+ setPrototypeOf(HTMLBridgeElement.prototype, SuperClass.prototype);
2451
+ defineProperty(HTMLBridgeElement.prototype, 'constructor', {
2452
+ writable: true,
2453
+ configurable: true,
2454
+ value: HTMLBridgeElement
2386
2455
  });
2387
- defineProperties(HTMLBridgeElement.prototype, descriptors);
2388
- return HTMLBridgeElement;
2456
+ }
2457
+ // generating the hash table for attributes to avoid duplicate fields and facilitate validation
2458
+ // and false positives in case of inheritance.
2459
+ const attributeToPropMap = create(null);
2460
+ const {
2461
+ attributeChangedCallback: superAttributeChangedCallback
2462
+ } = SuperClass.prototype;
2463
+ const {
2464
+ observedAttributes: superObservedAttributes = []
2465
+ } = SuperClass;
2466
+ const descriptors = create(null);
2467
+ // expose getters and setters for each public props on the new Element Bridge
2468
+ for (let i = 0, len = props.length; i < len; i += 1) {
2469
+ const propName = props[i];
2470
+ attributeToPropMap[htmlPropertyToAttribute(propName)] = propName;
2471
+ descriptors[propName] = {
2472
+ get: createGetter(propName),
2473
+ set: createSetter(propName),
2474
+ enumerable: true,
2475
+ configurable: true
2476
+ };
2477
+ }
2478
+ // expose public methods as props on the new Element Bridge
2479
+ for (let i = 0, len = methods.length; i < len; i += 1) {
2480
+ const methodName = methods[i];
2481
+ descriptors[methodName] = {
2482
+ value: createMethodCaller(methodName),
2483
+ writable: true,
2484
+ configurable: true
2485
+ };
2486
+ }
2487
+ // creating a new attributeChangedCallback per bridge because they are bound to the corresponding
2488
+ // map of attributes to props. We do this after all other props and methods to avoid the possibility
2489
+ // of getting overrule by a class declaration in user-land, and we make it non-writable, non-configurable
2490
+ // to preserve this definition.
2491
+ descriptors.attributeChangedCallback = {
2492
+ value: createAttributeChangedCallback(attributeToPropMap, superAttributeChangedCallback)
2493
+ };
2494
+ // Specify attributes for which we want to reflect changes back to their corresponding
2495
+ // properties via attributeChangedCallback.
2496
+ defineProperty(HTMLBridgeElement, 'observedAttributes', {
2497
+ get() {
2498
+ return [...superObservedAttributes, ...keys(attributeToPropMap)];
2499
+ }
2500
+ });
2501
+ defineProperties(HTMLBridgeElement.prototype, descriptors);
2502
+ return HTMLBridgeElement;
2389
2503
  }
2390
2504
  const BaseBridgeElement = HTMLBridgeElementFactory(HTMLElementConstructor, getOwnPropertyNames$1(HTMLElementOriginalDescriptors), []);
2505
+ if (process.env.IS_BROWSER) {
2506
+ // This ARIA reflection only really makes sense in the browser. On the server, there is no `renderedCallback()`,
2507
+ // so you cannot do e.g. `this.template.querySelector('x-child').ariaBusy = 'true'`. So we don't need to expose
2508
+ // ARIA props outside the LightningElement
2509
+ if (lwcRuntimeFlags.DISABLE_ARIA_REFLECTION_POLYFILL) {
2510
+ // If ARIA reflection is not applied globally to Element.prototype, apply it to HTMLBridgeElement.prototype.
2511
+ // This allows `elm.aria*` property accessors to work from outside a component, and to reflect `aria-*` attrs.
2512
+ // This is especially important because the template compiler compiles aria-* attrs on components to aria* props
2513
+ //
2514
+ // Also note that we apply this to BaseBridgeElement.prototype to avoid excessively redefining property
2515
+ // accessors inside the HTMLBridgeElementFactory.
2516
+ applyAriaReflection(BaseBridgeElement.prototype);
2517
+ }
2518
+ }
2391
2519
  freeze(BaseBridgeElement);
2392
2520
  seal(BaseBridgeElement.prototype);
2393
2521
 
@@ -6496,4 +6624,4 @@ function getComponentConstructor(elm) {
6496
6624
  }
6497
6625
 
6498
6626
  export { LightningElement, profilerControl as __unstable__ProfilerControl, api$1 as api, connectRootElement, createContextProvider, createVM, disconnectRootElement, freezeTemplate, getAssociatedVMIfPresent, getComponentConstructor, getComponentDef, getComponentHtmlPrototype, hydrateRoot, isComponentConstructor, parseFragment, parseSVGFragment, readonly, register, registerComponent, registerDecorators, registerTemplate, sanitizeAttribute, setHooks, swapComponent, swapStyle, swapTemplate, track, unwrap, wire };
6499
- /* version: 2.32.1 */
6627
+ /* version: 2.33.0 */