lwc 2.32.0 → 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.
Files changed (41) hide show
  1. package/dist/engine-dom/esm/es2017/engine-dom.js +898 -802
  2. package/dist/engine-dom/iife/es2017/engine-dom.js +898 -802
  3. package/dist/engine-dom/iife/es2017/engine-dom.min.js +1 -1
  4. package/dist/engine-dom/iife/es2017/engine-dom_debug.js +683 -608
  5. package/dist/engine-dom/iife/es5/engine-dom.js +324 -313
  6. package/dist/engine-dom/iife/es5/engine-dom.min.js +1 -1
  7. package/dist/engine-dom/iife/es5/engine-dom_debug.js +234 -270
  8. package/dist/engine-dom/umd/es2017/engine-dom.js +898 -802
  9. package/dist/engine-dom/umd/es2017/engine-dom.min.js +1 -1
  10. package/dist/engine-dom/umd/es2017/engine-dom_debug.js +683 -608
  11. package/dist/engine-dom/umd/es5/engine-dom.js +324 -313
  12. package/dist/engine-dom/umd/es5/engine-dom.min.js +1 -1
  13. package/dist/engine-dom/umd/es5/engine-dom_debug.js +234 -270
  14. package/dist/engine-server/commonjs/es2017/engine-server.js +871 -696
  15. package/dist/engine-server/commonjs/es2017/engine-server.min.js +1 -1
  16. package/dist/engine-server/esm/es2017/engine-server.js +871 -696
  17. package/dist/synthetic-shadow/esm/es2017/synthetic-shadow.js +676 -909
  18. package/dist/synthetic-shadow/iife/es2017/synthetic-shadow.js +676 -909
  19. package/dist/synthetic-shadow/iife/es2017/synthetic-shadow.min.js +2 -2
  20. package/dist/synthetic-shadow/iife/es2017/synthetic-shadow_debug.js +644 -882
  21. package/dist/synthetic-shadow/iife/es5/synthetic-shadow.js +89 -347
  22. package/dist/synthetic-shadow/iife/es5/synthetic-shadow.min.js +2 -2
  23. package/dist/synthetic-shadow/iife/es5/synthetic-shadow_debug.js +89 -347
  24. package/dist/synthetic-shadow/umd/es2017/synthetic-shadow.js +676 -909
  25. package/dist/synthetic-shadow/umd/es2017/synthetic-shadow.min.js +2 -2
  26. package/dist/synthetic-shadow/umd/es2017/synthetic-shadow_debug.js +644 -882
  27. package/dist/synthetic-shadow/umd/es5/synthetic-shadow.js +89 -347
  28. package/dist/synthetic-shadow/umd/es5/synthetic-shadow.min.js +2 -2
  29. package/dist/synthetic-shadow/umd/es5/synthetic-shadow_debug.js +89 -347
  30. package/dist/wire-service/esm/es2017/wire-service.js +2 -2
  31. package/dist/wire-service/iife/es2017/wire-service.js +2 -2
  32. package/dist/wire-service/iife/es2017/wire-service_debug.js +2 -2
  33. package/dist/wire-service/iife/es5/wire-service.js +5 -3
  34. package/dist/wire-service/iife/es5/wire-service.min.js +1 -1
  35. package/dist/wire-service/iife/es5/wire-service_debug.js +5 -3
  36. package/dist/wire-service/umd/es2017/wire-service.js +2 -2
  37. package/dist/wire-service/umd/es2017/wire-service_debug.js +2 -2
  38. package/dist/wire-service/umd/es5/wire-service.js +5 -3
  39. package/dist/wire-service/umd/es5/wire-service.min.js +1 -1
  40. package/dist/wire-service/umd/es5/wire-service_debug.js +5 -3
  41. package/package.json +7 -7
@@ -118,6 +118,9 @@ function getPropertyDescriptor(o, p) {
118
118
  * The above list of 46 aria attributes is consistent with the following resources:
119
119
  * https://github.com/w3c/aria/pull/708/files#diff-eacf331f0ffc35d4b482f1d15a887d3bR11060
120
120
  * https://wicg.github.io/aom/spec/aria-reflection.html
121
+ *
122
+ * NOTE: If you update this list, please update test files that implicitly reference this list!
123
+ * Searching the codebase for `aria-flowto` and `ariaFlowTo` should be good enough to find all usages.
121
124
  */
122
125
  const AriaPropertyNames = [
123
126
  'ariaActiveDescendant',
@@ -467,9 +470,9 @@ function htmlEscape(str, attrMode = false) {
467
470
  * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
468
471
  */
469
472
  // Increment whenever the LWC template compiler changes
470
- const LWC_VERSION = "2.32.0";
473
+ const LWC_VERSION = "2.33.0";
471
474
  const LWC_VERSION_COMMENT_REGEX = /\/\*LWC compiler v([\d.]+)\*\/\s*}/;
472
- /** version: 2.32.0 */
475
+ /** version: 2.33.0 */
473
476
 
474
477
  /*
475
478
  * Copyright (c) 2020, salesforce.com, inc.
@@ -515,19 +518,15 @@ if (typeof CustomEvent !== 'function') {
515
518
  */
516
519
  const features = {
517
520
  DUMMY_TEST_FLAG: null,
518
- ENABLE_ELEMENT_PATCH: null,
519
521
  ENABLE_FORCE_NATIVE_SHADOW_MODE_FOR_TEST: null,
520
- ENABLE_HTML_COLLECTIONS_PATCH: null,
521
- ENABLE_INNER_OUTER_TEXT_PATCH: null,
522
522
  ENABLE_MIXED_SHADOW_MODE: null,
523
523
  ENABLE_NATIVE_CUSTOM_ELEMENT_LIFECYCLE: null,
524
- ENABLE_NODE_LIST_PATCH: null,
525
- ENABLE_NODE_PATCH: null,
526
- ENABLE_REACTIVE_SETTER: null,
527
524
  ENABLE_WIRE_SYNC_EMIT: null,
528
525
  ENABLE_LIGHT_GET_ROOT_NODE_PATCH: null,
529
526
  DISABLE_LIGHT_DOM_UNSCOPED_CSS: null,
530
527
  ENABLE_SCOPED_CUSTOM_ELEMENT_REGISTRY: null,
528
+ ENABLE_FROZEN_TEMPLATE: null,
529
+ DISABLE_ARIA_REFLECTION_POLYFILL: null,
531
530
  };
532
531
  if (!_globalThis.lwcRuntimeFlags) {
533
532
  Object.defineProperty(_globalThis, 'lwcRuntimeFlags', { value: create(null) });
@@ -581,7 +580,71 @@ function setFeatureFlagForTest(name, value) {
581
580
  setFeatureFlag(name, value);
582
581
  }
583
582
  }
584
- /** version: 2.32.0 */
583
+ /** version: 2.33.0 */
584
+
585
+ /**
586
+ * Copyright (C) 2018 salesforce.com, inc.
587
+ */
588
+
589
+ /*
590
+ * Copyright (c) 2018, salesforce.com, inc.
591
+ * All rights reserved.
592
+ * SPDX-License-Identifier: MIT
593
+ * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
594
+ */
595
+ function detect(propName, prototype) {
596
+ return isUndefined$1(getOwnPropertyDescriptor$1(prototype, propName));
597
+ }
598
+
599
+ /*
600
+ * Copyright (c) 2018, salesforce.com, inc.
601
+ * All rights reserved.
602
+ * SPDX-License-Identifier: MIT
603
+ * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
604
+ */
605
+ function createAriaPropertyPropertyDescriptor(attrName) {
606
+ // Note that we need to call this.{get,set,has,remove}Attribute rather than dereferencing
607
+ // from Element.prototype, because these methods are overridden in LightningElement.
608
+ return {
609
+ get() {
610
+ // reflect what's in the attribute
611
+ return this.hasAttribute(attrName) ? this.getAttribute(attrName) : null;
612
+ },
613
+ set(newValue) {
614
+ // reflect into the corresponding attribute
615
+ if (isNull(newValue)) {
616
+ this.removeAttribute(attrName);
617
+ }
618
+ else {
619
+ this.setAttribute(attrName, newValue);
620
+ }
621
+ },
622
+ configurable: true,
623
+ enumerable: true,
624
+ };
625
+ }
626
+ function patch$1(propName, prototype) {
627
+ const attrName = AriaPropNameToAttrNameMap[propName];
628
+ const descriptor = createAriaPropertyPropertyDescriptor(attrName);
629
+ defineProperty(prototype, propName, descriptor);
630
+ }
631
+
632
+ /*
633
+ * Copyright (c) 2018, salesforce.com, inc.
634
+ * All rights reserved.
635
+ * SPDX-License-Identifier: MIT
636
+ * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
637
+ */
638
+ function applyAriaReflection(prototype = Element.prototype) {
639
+ const ElementPrototypeAriaPropertyNames = keys(AriaPropNameToAttrNameMap);
640
+ for (let i = 0, len = ElementPrototypeAriaPropertyNames.length; i < len; i += 1) {
641
+ const propName = ElementPrototypeAriaPropertyNames[i];
642
+ if (detect(propName, prototype)) {
643
+ patch$1(propName, prototype);
644
+ }
645
+ }
646
+ }
647
+ /** version: 2.33.0 */
585
648
 
586
649
  /* proxy-compat-disable */
587
650
 
@@ -998,7 +1061,7 @@ function patchElementWithRestrictions(elm, options) {
998
1061
  }),
999
1062
  };
1000
1063
  // Apply extra restriction related to DOM manipulation if the element is not a portal.
1001
- if (!options.isLight && !options.isPortal) {
1064
+ if (!options.isLight && options.isSynthetic && !options.isPortal) {
1002
1065
  const { appendChild, insertBefore, removeChild, replaceChild } = elm;
1003
1066
  const originalNodeValueDescriptor = getPropertyDescriptor(elm, 'nodeValue');
1004
1067
  const originalInnerHTMLDescriptor = getPropertyDescriptor(elm, 'innerHTML');
@@ -1838,45 +1901,50 @@ function getReactiveProxy(value) {
1838
1901
  * for the Base Lightning Element, it also include the reactivity bit, so the standard property is reactive.
1839
1902
  */
1840
1903
  function createBridgeToElementDescriptor(propName, descriptor) {
1841
- const { get, set, enumerable, configurable } = descriptor;
1842
- if (!isFunction$1(get)) {
1843
- if (process.env.NODE_ENV !== 'production') {
1844
- assert.fail(`Detected invalid public property descriptor for HTMLElement.prototype.${propName} definition. Missing the standard getter.`);
1845
- }
1846
- throw new TypeError();
1904
+ const {
1905
+ get,
1906
+ set,
1907
+ enumerable,
1908
+ configurable
1909
+ } = descriptor;
1910
+ if (!isFunction$1(get)) {
1911
+ if (process.env.NODE_ENV !== 'production') {
1912
+ assert.fail(`Detected invalid public property descriptor for HTMLElement.prototype.${propName} definition. Missing the standard getter.`);
1913
+ }
1914
+ throw new TypeError();
1915
+ }
1916
+ if (!isFunction$1(set)) {
1917
+ if (process.env.NODE_ENV !== 'production') {
1918
+ assert.fail(`Detected invalid public property descriptor for HTMLElement.prototype.${propName} definition. Missing the standard setter.`);
1847
1919
  }
1848
- if (!isFunction$1(set)) {
1920
+ throw new TypeError();
1921
+ }
1922
+ return {
1923
+ enumerable,
1924
+ configurable,
1925
+ get() {
1926
+ const vm = getAssociatedVM(this);
1927
+ if (isBeingConstructed(vm)) {
1849
1928
  if (process.env.NODE_ENV !== 'production') {
1850
- assert.fail(`Detected invalid public property descriptor for HTMLElement.prototype.${propName} definition. Missing the standard setter.`);
1929
+ 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);
1851
1930
  }
1852
- throw new TypeError();
1931
+ return;
1932
+ }
1933
+ return get.call(vm.elm);
1934
+ },
1935
+ set(newValue) {
1936
+ const vm = getAssociatedVM(this);
1937
+ if (process.env.NODE_ENV !== 'production') {
1938
+ const vmBeingRendered = getVMBeingRendered();
1939
+ assert.invariant(!isInvokingRender, `${vmBeingRendered}.render() method has side effects on the state of ${vm}.${propName}`);
1940
+ 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}`);
1941
+ assert.isFalse(isBeingConstructed(vm), `Failed to construct '${getComponentTag(vm)}': The result must not have attributes.`);
1942
+ assert.invariant(!isObject(newValue) || isNull(newValue), `Invalid value "${newValue}" for "${propName}" of ${vm}. Value cannot be an object, must be a primitive value.`);
1943
+ }
1944
+ updateComponentValue(vm, propName, newValue);
1945
+ return set.call(vm.elm, newValue);
1853
1946
  }
1854
- return {
1855
- enumerable,
1856
- configurable,
1857
- get() {
1858
- const vm = getAssociatedVM(this);
1859
- if (isBeingConstructed(vm)) {
1860
- if (process.env.NODE_ENV !== 'production') {
1861
- 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);
1862
- }
1863
- return;
1864
- }
1865
- return get.call(vm.elm);
1866
- },
1867
- set(newValue) {
1868
- const vm = getAssociatedVM(this);
1869
- if (process.env.NODE_ENV !== 'production') {
1870
- const vmBeingRendered = getVMBeingRendered();
1871
- assert.invariant(!isInvokingRender, `${vmBeingRendered}.render() method has side effects on the state of ${vm}.${propName}`);
1872
- 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}`);
1873
- assert.isFalse(isBeingConstructed(vm), `Failed to construct '${getComponentTag(vm)}': The result must not have attributes.`);
1874
- assert.invariant(!isObject(newValue) || isNull(newValue), `Invalid value "${newValue}" for "${propName}" of ${vm}. Value cannot be an object, must be a primitive value.`);
1875
- }
1876
- updateComponentValue(vm, propName, newValue);
1877
- return set.call(vm.elm, newValue);
1878
- },
1879
- };
1947
+ };
1880
1948
  }
1881
1949
  const EMPTY_REFS = freeze(create(null));
1882
1950
  const refsCache = new WeakMap();
@@ -1886,344 +1954,443 @@ const refsCache = new WeakMap();
1886
1954
  **/
1887
1955
  // @ts-ignore
1888
1956
  const LightningElement = function () {
1889
- // This should be as performant as possible, while any initialization should be done lazily
1890
- if (isNull(vmBeingConstructed)) {
1891
- // Thrown when doing something like `new LightningElement()` or
1892
- // `class Foo extends LightningElement {}; new Foo()`
1893
- throw new TypeError('Illegal constructor');
1894
- }
1895
- const vm = vmBeingConstructed;
1896
- const { def, elm } = vm;
1897
- const { bridge } = def;
1957
+ // This should be as performant as possible, while any initialization should be done lazily
1958
+ if (isNull(vmBeingConstructed)) {
1959
+ // Thrown when doing something like `new LightningElement()` or
1960
+ // `class Foo extends LightningElement {}; new Foo()`
1961
+ throw new TypeError('Illegal constructor');
1962
+ }
1963
+ const vm = vmBeingConstructed;
1964
+ const {
1965
+ def,
1966
+ elm
1967
+ } = vm;
1968
+ const {
1969
+ bridge
1970
+ } = def;
1971
+ if (process.env.NODE_ENV !== 'production') {
1972
+ const {
1973
+ assertInstanceOfHTMLElement
1974
+ } = vm.renderer;
1975
+ assertInstanceOfHTMLElement(vm.elm, `Component creation requires a DOM element to be associated to ${vm}.`);
1976
+ }
1977
+ const component = this;
1978
+ setPrototypeOf(elm, bridge.prototype);
1979
+ vm.component = this;
1980
+ // Locker hooks assignment. When the LWC engine run with Locker, Locker intercepts all the new
1981
+ // component creation and passes hooks to instrument all the component interactions with the
1982
+ // engine. We are intentionally hiding this argument from the formal API of LightningElement
1983
+ // because we don't want folks to know about it just yet.
1984
+ if (arguments.length === 1) {
1985
+ const {
1986
+ callHook,
1987
+ setHook,
1988
+ getHook
1989
+ } = arguments[0];
1990
+ vm.callHook = callHook;
1991
+ vm.setHook = setHook;
1992
+ vm.getHook = getHook;
1993
+ }
1994
+ // Linking elm, shadow root and component with the VM.
1995
+ associateVM(component, vm);
1996
+ associateVM(elm, vm);
1997
+ if (vm.renderMode === 1 /* RenderMode.Shadow */) {
1998
+ vm.renderRoot = doAttachShadow(vm);
1999
+ } else {
2000
+ vm.renderRoot = elm;
2001
+ }
2002
+ // Adding extra guard rails in DEV mode.
2003
+ if (process.env.NODE_ENV !== 'production') {
2004
+ patchCustomElementWithRestrictions(elm);
2005
+ patchComponentWithRestrictions(component);
2006
+ }
2007
+ return this;
2008
+ };
2009
+ function doAttachShadow(vm) {
2010
+ const {
2011
+ elm,
2012
+ mode,
2013
+ shadowMode,
2014
+ def: {
2015
+ ctor
2016
+ },
2017
+ renderer: {
2018
+ attachShadow
2019
+ }
2020
+ } = vm;
2021
+ const shadowRoot = attachShadow(elm, {
2022
+ [KEY__SYNTHETIC_MODE]: shadowMode === 1 /* ShadowMode.Synthetic */,
2023
+ delegatesFocus: Boolean(ctor.delegatesFocus),
2024
+ mode
2025
+ });
2026
+ vm.shadowRoot = shadowRoot;
2027
+ associateVM(shadowRoot, vm);
2028
+ if (process.env.NODE_ENV !== 'production') {
2029
+ patchShadowRootWithRestrictions(shadowRoot);
2030
+ }
2031
+ return shadowRoot;
2032
+ }
2033
+ function warnIfInvokedDuringConstruction(vm, methodOrPropName) {
2034
+ if (isBeingConstructed(vm)) {
2035
+ 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.`);
2036
+ }
2037
+ }
2038
+ // @ts-ignore
2039
+ LightningElement.prototype = {
2040
+ constructor: LightningElement,
2041
+ dispatchEvent(event) {
2042
+ const vm = getAssociatedVM(this);
2043
+ const {
2044
+ elm,
2045
+ renderer: {
2046
+ dispatchEvent
2047
+ }
2048
+ } = vm;
2049
+ return dispatchEvent(elm, event);
2050
+ },
2051
+ addEventListener(type, listener, options) {
2052
+ const vm = getAssociatedVM(this);
2053
+ const {
2054
+ elm,
2055
+ renderer: {
2056
+ addEventListener
2057
+ }
2058
+ } = vm;
1898
2059
  if (process.env.NODE_ENV !== 'production') {
1899
- const { assertInstanceOfHTMLElement } = vm.renderer;
1900
- assertInstanceOfHTMLElement(vm.elm, `Component creation requires a DOM element to be associated to ${vm}.`);
1901
- }
1902
- const component = this;
1903
- setPrototypeOf(elm, bridge.prototype);
1904
- vm.component = this;
1905
- // Locker hooks assignment. When the LWC engine run with Locker, Locker intercepts all the new
1906
- // component creation and passes hooks to instrument all the component interactions with the
1907
- // engine. We are intentionally hiding this argument from the formal API of LightningElement
1908
- // because we don't want folks to know about it just yet.
1909
- if (arguments.length === 1) {
1910
- const { callHook, setHook, getHook } = arguments[0];
1911
- vm.callHook = callHook;
1912
- vm.setHook = setHook;
1913
- vm.getHook = getHook;
2060
+ const vmBeingRendered = getVMBeingRendered();
2061
+ assert.invariant(!isInvokingRender, `${vmBeingRendered}.render() method has side effects on the state of ${vm} by adding an event listener for "${type}".`);
2062
+ assert.invariant(!isUpdatingTemplate, `Updating the template of ${vmBeingRendered} has side effects on the state of ${vm} by adding an event listener for "${type}".`);
2063
+ assert.invariant(isFunction$1(listener), `Invalid second argument for this.addEventListener() in ${vm} for event "${type}". Expected an EventListener but received ${listener}.`);
2064
+ }
2065
+ const wrappedListener = getWrappedComponentsListener(vm, listener);
2066
+ addEventListener(elm, type, wrappedListener, options);
2067
+ },
2068
+ removeEventListener(type, listener, options) {
2069
+ const vm = getAssociatedVM(this);
2070
+ const {
2071
+ elm,
2072
+ renderer: {
2073
+ removeEventListener
2074
+ }
2075
+ } = vm;
2076
+ const wrappedListener = getWrappedComponentsListener(vm, listener);
2077
+ removeEventListener(elm, type, wrappedListener, options);
2078
+ },
2079
+ hasAttribute(name) {
2080
+ const vm = getAssociatedVM(this);
2081
+ const {
2082
+ elm,
2083
+ renderer: {
2084
+ getAttribute
2085
+ }
2086
+ } = vm;
2087
+ return !isNull(getAttribute(elm, name));
2088
+ },
2089
+ hasAttributeNS(namespace, name) {
2090
+ const vm = getAssociatedVM(this);
2091
+ const {
2092
+ elm,
2093
+ renderer: {
2094
+ getAttribute
2095
+ }
2096
+ } = vm;
2097
+ return !isNull(getAttribute(elm, name, namespace));
2098
+ },
2099
+ removeAttribute(name) {
2100
+ const vm = getAssociatedVM(this);
2101
+ const {
2102
+ elm,
2103
+ renderer: {
2104
+ removeAttribute
2105
+ }
2106
+ } = vm;
2107
+ unlockAttribute(elm, name);
2108
+ removeAttribute(elm, name);
2109
+ lockAttribute();
2110
+ },
2111
+ removeAttributeNS(namespace, name) {
2112
+ const {
2113
+ elm,
2114
+ renderer: {
2115
+ removeAttribute
2116
+ }
2117
+ } = getAssociatedVM(this);
2118
+ unlockAttribute(elm, name);
2119
+ removeAttribute(elm, name, namespace);
2120
+ lockAttribute();
2121
+ },
2122
+ getAttribute(name) {
2123
+ const vm = getAssociatedVM(this);
2124
+ const {
2125
+ elm
2126
+ } = vm;
2127
+ const {
2128
+ getAttribute
2129
+ } = vm.renderer;
2130
+ return getAttribute(elm, name);
2131
+ },
2132
+ getAttributeNS(namespace, name) {
2133
+ const vm = getAssociatedVM(this);
2134
+ const {
2135
+ elm
2136
+ } = vm;
2137
+ const {
2138
+ getAttribute
2139
+ } = vm.renderer;
2140
+ return getAttribute(elm, name, namespace);
2141
+ },
2142
+ setAttribute(name, value) {
2143
+ const vm = getAssociatedVM(this);
2144
+ const {
2145
+ elm,
2146
+ renderer: {
2147
+ setAttribute
2148
+ }
2149
+ } = vm;
2150
+ if (process.env.NODE_ENV !== 'production') {
2151
+ assert.isFalse(isBeingConstructed(vm), `Failed to construct '${getComponentTag(vm)}': The result must not have attributes.`);
2152
+ }
2153
+ unlockAttribute(elm, name);
2154
+ setAttribute(elm, name, value);
2155
+ lockAttribute();
2156
+ },
2157
+ setAttributeNS(namespace, name, value) {
2158
+ const vm = getAssociatedVM(this);
2159
+ const {
2160
+ elm,
2161
+ renderer: {
2162
+ setAttribute
2163
+ }
2164
+ } = vm;
2165
+ if (process.env.NODE_ENV !== 'production') {
2166
+ assert.isFalse(isBeingConstructed(vm), `Failed to construct '${getComponentTag(vm)}': The result must not have attributes.`);
2167
+ }
2168
+ unlockAttribute(elm, name);
2169
+ setAttribute(elm, name, value, namespace);
2170
+ lockAttribute();
2171
+ },
2172
+ getBoundingClientRect() {
2173
+ const vm = getAssociatedVM(this);
2174
+ const {
2175
+ elm,
2176
+ renderer: {
2177
+ getBoundingClientRect
2178
+ }
2179
+ } = vm;
2180
+ if (process.env.NODE_ENV !== 'production') {
2181
+ warnIfInvokedDuringConstruction(vm, 'getBoundingClientRect()');
1914
2182
  }
1915
- // Linking elm, shadow root and component with the VM.
1916
- associateVM(component, vm);
1917
- associateVM(elm, vm);
1918
- if (vm.renderMode === 1 /* RenderMode.Shadow */) {
1919
- vm.renderRoot = doAttachShadow(vm);
2183
+ return getBoundingClientRect(elm);
2184
+ },
2185
+ get isConnected() {
2186
+ const vm = getAssociatedVM(this);
2187
+ const {
2188
+ elm,
2189
+ renderer: {
2190
+ isConnected
2191
+ }
2192
+ } = vm;
2193
+ return isConnected(elm);
2194
+ },
2195
+ get classList() {
2196
+ const vm = getAssociatedVM(this);
2197
+ const {
2198
+ elm,
2199
+ renderer: {
2200
+ getClassList
2201
+ }
2202
+ } = vm;
2203
+ if (process.env.NODE_ENV !== 'production') {
2204
+ // TODO [#1290]: this still fails in dev but works in production, eventually, we should
2205
+ // just throw in all modes
2206
+ 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.`);
2207
+ }
2208
+ return getClassList(elm);
2209
+ },
2210
+ get template() {
2211
+ const vm = getAssociatedVM(this);
2212
+ if (process.env.NODE_ENV !== 'production') {
2213
+ if (vm.renderMode === 0 /* RenderMode.Light */) {
2214
+ 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`.');
2215
+ }
1920
2216
  }
1921
- else {
1922
- vm.renderRoot = elm;
2217
+ return vm.shadowRoot;
2218
+ },
2219
+ get refs() {
2220
+ const vm = getAssociatedVM(this);
2221
+ if (isUpdatingTemplate) {
2222
+ if (process.env.NODE_ENV !== 'production') {
2223
+ 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().`);
2224
+ }
2225
+ // If the template is in the process of being updated, then we don't want to go through the normal
2226
+ // process of returning the refs and caching them, because the state of the refs is unstable.
2227
+ // This can happen if e.g. a template contains `<div class={foo}></div>` and `foo` is computed
2228
+ // based on `this.refs.bar`.
2229
+ return;
1923
2230
  }
1924
- // Adding extra guard rails in DEV mode.
1925
2231
  if (process.env.NODE_ENV !== 'production') {
1926
- patchCustomElementWithRestrictions(elm);
1927
- patchComponentWithRestrictions(component);
2232
+ warnIfInvokedDuringConstruction(vm, 'refs');
1928
2233
  }
1929
- return this;
1930
- };
1931
- function doAttachShadow(vm) {
1932
- const { elm, mode, shadowMode, def: { ctor }, renderer: { attachShadow }, } = vm;
1933
- const shadowRoot = attachShadow(elm, {
1934
- [KEY__SYNTHETIC_MODE]: shadowMode === 1 /* ShadowMode.Synthetic */,
1935
- delegatesFocus: Boolean(ctor.delegatesFocus),
1936
- mode,
2234
+ const {
2235
+ refVNodes,
2236
+ hasRefVNodes,
2237
+ cmpTemplate
2238
+ } = vm;
2239
+ // If the `cmpTemplate` is null, that means that the template has not been rendered yet. Most likely this occurs
2240
+ // if `this.refs` is called during the `connectedCallback` phase. The DOM elements have not been rendered yet,
2241
+ // so log a warning. Note we also check `isBeingConstructed()` to avoid a double warning (due to
2242
+ // `warnIfInvokedDuringConstruction` above).
2243
+ if (process.env.NODE_ENV !== 'production' && isNull(cmpTemplate) && !isBeingConstructed(vm)) {
2244
+ 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().`);
2245
+ }
2246
+ // For backwards compatibility with component written before template refs
2247
+ // were introduced, we return undefined if the template has no refs defined
2248
+ // anywhere. This fixes components that may want to add an expando called `refs`
2249
+ // and are checking if it exists with `if (this.refs)` before adding it.
2250
+ // Note it is not sufficient to just check if `refVNodes` is null or empty,
2251
+ // because a template may have `lwc:ref` defined within a falsy `if:true` block.
2252
+ if (!hasRefVNodes) {
2253
+ return;
2254
+ }
2255
+ // For templates that are using `lwc:ref`, if there are no refs currently available
2256
+ // (e.g. refs inside of a falsy `if:true` block), we return an empty object.
2257
+ if (isNull(refVNodes)) {
2258
+ return EMPTY_REFS;
2259
+ }
2260
+ // The refNodes can be cached based on the refVNodes, since the refVNodes
2261
+ // are recreated from scratch every time the template is rendered.
2262
+ // This happens with `vm.refVNodes = null` in `template.ts` in `@lwc/engine-core`.
2263
+ let refs = refsCache.get(refVNodes);
2264
+ if (isUndefined$1(refs)) {
2265
+ refs = create(null);
2266
+ for (const key of keys(refVNodes)) {
2267
+ refs[key] = refVNodes[key].elm;
2268
+ }
2269
+ freeze(refs);
2270
+ refsCache.set(refVNodes, refs);
2271
+ }
2272
+ return refs;
2273
+ },
2274
+ // For backwards compat, we allow component authors to set `refs` as an expando
2275
+ set refs(value) {
2276
+ defineProperty(this, 'refs', {
2277
+ configurable: true,
2278
+ enumerable: true,
2279
+ writable: true,
2280
+ value
1937
2281
  });
1938
- vm.shadowRoot = shadowRoot;
1939
- associateVM(shadowRoot, vm);
2282
+ },
2283
+ get shadowRoot() {
2284
+ // From within the component instance, the shadowRoot is always reported as "closed".
2285
+ // Authors should rely on this.template instead.
2286
+ return null;
2287
+ },
2288
+ get children() {
2289
+ const vm = getAssociatedVM(this);
2290
+ const renderer = vm.renderer;
1940
2291
  if (process.env.NODE_ENV !== 'production') {
1941
- patchShadowRootWithRestrictions(shadowRoot);
2292
+ warnIfInvokedDuringConstruction(vm, 'children');
1942
2293
  }
1943
- return shadowRoot;
1944
- }
1945
- function warnIfInvokedDuringConstruction(vm, methodOrPropName) {
1946
- if (isBeingConstructed(vm)) {
1947
- 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.`);
2294
+ return renderer.getChildren(vm.elm);
2295
+ },
2296
+ get childNodes() {
2297
+ const vm = getAssociatedVM(this);
2298
+ const renderer = vm.renderer;
2299
+ if (process.env.NODE_ENV !== 'production') {
2300
+ warnIfInvokedDuringConstruction(vm, 'childNodes');
1948
2301
  }
1949
- }
1950
- // @ts-ignore
1951
- LightningElement.prototype = {
1952
- constructor: LightningElement,
1953
- dispatchEvent(event) {
1954
- const vm = getAssociatedVM(this);
1955
- const { elm, renderer: { dispatchEvent }, } = vm;
1956
- return dispatchEvent(elm, event);
1957
- },
1958
- addEventListener(type, listener, options) {
1959
- const vm = getAssociatedVM(this);
1960
- const { elm, renderer: { addEventListener }, } = vm;
1961
- if (process.env.NODE_ENV !== 'production') {
1962
- const vmBeingRendered = getVMBeingRendered();
1963
- assert.invariant(!isInvokingRender, `${vmBeingRendered}.render() method has side effects on the state of ${vm} by adding an event listener for "${type}".`);
1964
- assert.invariant(!isUpdatingTemplate, `Updating the template of ${vmBeingRendered} has side effects on the state of ${vm} by adding an event listener for "${type}".`);
1965
- assert.invariant(isFunction$1(listener), `Invalid second argument for this.addEventListener() in ${vm} for event "${type}". Expected an EventListener but received ${listener}.`);
1966
- }
1967
- const wrappedListener = getWrappedComponentsListener(vm, listener);
1968
- addEventListener(elm, type, wrappedListener, options);
1969
- },
1970
- removeEventListener(type, listener, options) {
1971
- const vm = getAssociatedVM(this);
1972
- const { elm, renderer: { removeEventListener }, } = vm;
1973
- const wrappedListener = getWrappedComponentsListener(vm, listener);
1974
- removeEventListener(elm, type, wrappedListener, options);
1975
- },
1976
- hasAttribute(name) {
1977
- const vm = getAssociatedVM(this);
1978
- const { elm, renderer: { getAttribute }, } = vm;
1979
- return !isNull(getAttribute(elm, name));
1980
- },
1981
- hasAttributeNS(namespace, name) {
1982
- const vm = getAssociatedVM(this);
1983
- const { elm, renderer: { getAttribute }, } = vm;
1984
- return !isNull(getAttribute(elm, name, namespace));
1985
- },
1986
- removeAttribute(name) {
1987
- const vm = getAssociatedVM(this);
1988
- const { elm, renderer: { removeAttribute }, } = vm;
1989
- unlockAttribute(elm, name);
1990
- removeAttribute(elm, name);
1991
- lockAttribute();
1992
- },
1993
- removeAttributeNS(namespace, name) {
1994
- const { elm, renderer: { removeAttribute }, } = getAssociatedVM(this);
1995
- unlockAttribute(elm, name);
1996
- removeAttribute(elm, name, namespace);
1997
- lockAttribute();
1998
- },
1999
- getAttribute(name) {
2000
- const vm = getAssociatedVM(this);
2001
- const { elm } = vm;
2002
- const { getAttribute } = vm.renderer;
2003
- return getAttribute(elm, name);
2004
- },
2005
- getAttributeNS(namespace, name) {
2006
- const vm = getAssociatedVM(this);
2007
- const { elm } = vm;
2008
- const { getAttribute } = vm.renderer;
2009
- return getAttribute(elm, name, namespace);
2010
- },
2011
- setAttribute(name, value) {
2012
- const vm = getAssociatedVM(this);
2013
- const { elm, renderer: { setAttribute }, } = vm;
2014
- if (process.env.NODE_ENV !== 'production') {
2015
- assert.isFalse(isBeingConstructed(vm), `Failed to construct '${getComponentTag(vm)}': The result must not have attributes.`);
2016
- }
2017
- unlockAttribute(elm, name);
2018
- setAttribute(elm, name, value);
2019
- lockAttribute();
2020
- },
2021
- setAttributeNS(namespace, name, value) {
2022
- const vm = getAssociatedVM(this);
2023
- const { elm, renderer: { setAttribute }, } = vm;
2024
- if (process.env.NODE_ENV !== 'production') {
2025
- assert.isFalse(isBeingConstructed(vm), `Failed to construct '${getComponentTag(vm)}': The result must not have attributes.`);
2026
- }
2027
- unlockAttribute(elm, name);
2028
- setAttribute(elm, name, value, namespace);
2029
- lockAttribute();
2030
- },
2031
- getBoundingClientRect() {
2032
- const vm = getAssociatedVM(this);
2033
- const { elm, renderer: { getBoundingClientRect }, } = vm;
2034
- if (process.env.NODE_ENV !== 'production') {
2035
- warnIfInvokedDuringConstruction(vm, 'getBoundingClientRect()');
2036
- }
2037
- return getBoundingClientRect(elm);
2038
- },
2039
- get isConnected() {
2040
- const vm = getAssociatedVM(this);
2041
- const { elm, renderer: { isConnected }, } = vm;
2042
- return isConnected(elm);
2043
- },
2044
- get classList() {
2045
- const vm = getAssociatedVM(this);
2046
- const { elm, renderer: { getClassList }, } = vm;
2047
- if (process.env.NODE_ENV !== 'production') {
2048
- // TODO [#1290]: this still fails in dev but works in production, eventually, we should
2049
- // just throw in all modes
2050
- 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.`);
2051
- }
2052
- return getClassList(elm);
2053
- },
2054
- get template() {
2055
- const vm = getAssociatedVM(this);
2056
- if (process.env.NODE_ENV !== 'production') {
2057
- if (vm.renderMode === 0 /* RenderMode.Light */) {
2058
- 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`.');
2059
- }
2060
- }
2061
- return vm.shadowRoot;
2062
- },
2063
- get refs() {
2064
- const vm = getAssociatedVM(this);
2065
- if (isUpdatingTemplate) {
2066
- if (process.env.NODE_ENV !== 'production') {
2067
- 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().`);
2068
- }
2069
- // If the template is in the process of being updated, then we don't want to go through the normal
2070
- // process of returning the refs and caching them, because the state of the refs is unstable.
2071
- // This can happen if e.g. a template contains `<div class={foo}></div>` and `foo` is computed
2072
- // based on `this.refs.bar`.
2073
- return;
2074
- }
2075
- if (process.env.NODE_ENV !== 'production') {
2076
- warnIfInvokedDuringConstruction(vm, 'refs');
2077
- }
2078
- const { refVNodes, hasRefVNodes, cmpTemplate } = vm;
2079
- // If the `cmpTemplate` is null, that means that the template has not been rendered yet. Most likely this occurs
2080
- // if `this.refs` is called during the `connectedCallback` phase. The DOM elements have not been rendered yet,
2081
- // so log a warning. Note we also check `isBeingConstructed()` to avoid a double warning (due to
2082
- // `warnIfInvokedDuringConstruction` above).
2083
- if (process.env.NODE_ENV !== 'production' &&
2084
- isNull(cmpTemplate) &&
2085
- !isBeingConstructed(vm)) {
2086
- logError(`this.refs is undefined for ${getComponentTag(vm)}. This is either because the attached template has no "lwc:ref" directive, or this.refs was ` +
2087
- `invoked before renderedCallback(). Use this.refs only when the referenced HTML elements have ` +
2088
- `been rendered to the DOM, such as within renderedCallback() or disconnectedCallback().`);
2089
- }
2090
- // For backwards compatibility with component written before template refs
2091
- // were introduced, we return undefined if the template has no refs defined
2092
- // anywhere. This fixes components that may want to add an expando called `refs`
2093
- // and are checking if it exists with `if (this.refs)` before adding it.
2094
- // Note it is not sufficient to just check if `refVNodes` is null or empty,
2095
- // because a template may have `lwc:ref` defined within a falsy `if:true` block.
2096
- if (!hasRefVNodes) {
2097
- return;
2098
- }
2099
- // For templates that are using `lwc:ref`, if there are no refs currently available
2100
- // (e.g. refs inside of a falsy `if:true` block), we return an empty object.
2101
- if (isNull(refVNodes)) {
2102
- return EMPTY_REFS;
2103
- }
2104
- // The refNodes can be cached based on the refVNodes, since the refVNodes
2105
- // are recreated from scratch every time the template is rendered.
2106
- // This happens with `vm.refVNodes = null` in `template.ts` in `@lwc/engine-core`.
2107
- let refs = refsCache.get(refVNodes);
2108
- if (isUndefined$1(refs)) {
2109
- refs = create(null);
2110
- for (const key of keys(refVNodes)) {
2111
- refs[key] = refVNodes[key].elm;
2112
- }
2113
- freeze(refs);
2114
- refsCache.set(refVNodes, refs);
2115
- }
2116
- return refs;
2117
- },
2118
- // For backwards compat, we allow component authors to set `refs` as an expando
2119
- set refs(value) {
2120
- defineProperty(this, 'refs', {
2121
- configurable: true,
2122
- enumerable: true,
2123
- writable: true,
2124
- value,
2125
- });
2126
- },
2127
- get shadowRoot() {
2128
- // From within the component instance, the shadowRoot is always reported as "closed".
2129
- // Authors should rely on this.template instead.
2130
- return null;
2131
- },
2132
- get children() {
2133
- const vm = getAssociatedVM(this);
2134
- const renderer = vm.renderer;
2135
- if (process.env.NODE_ENV !== 'production') {
2136
- warnIfInvokedDuringConstruction(vm, 'children');
2137
- }
2138
- return renderer.getChildren(vm.elm);
2139
- },
2140
- get childNodes() {
2141
- const vm = getAssociatedVM(this);
2142
- const renderer = vm.renderer;
2143
- if (process.env.NODE_ENV !== 'production') {
2144
- warnIfInvokedDuringConstruction(vm, 'childNodes');
2145
- }
2146
- return renderer.getChildNodes(vm.elm);
2147
- },
2148
- get firstChild() {
2149
- const vm = getAssociatedVM(this);
2150
- const renderer = vm.renderer;
2151
- if (process.env.NODE_ENV !== 'production') {
2152
- warnIfInvokedDuringConstruction(vm, 'firstChild');
2153
- }
2154
- return renderer.getFirstChild(vm.elm);
2155
- },
2156
- get firstElementChild() {
2157
- const vm = getAssociatedVM(this);
2158
- const renderer = vm.renderer;
2159
- if (process.env.NODE_ENV !== 'production') {
2160
- warnIfInvokedDuringConstruction(vm, 'firstElementChild');
2161
- }
2162
- return renderer.getFirstElementChild(vm.elm);
2163
- },
2164
- get lastChild() {
2165
- const vm = getAssociatedVM(this);
2166
- const renderer = vm.renderer;
2167
- if (process.env.NODE_ENV !== 'production') {
2168
- warnIfInvokedDuringConstruction(vm, 'lastChild');
2169
- }
2170
- return renderer.getLastChild(vm.elm);
2171
- },
2172
- get lastElementChild() {
2173
- const vm = getAssociatedVM(this);
2174
- const renderer = vm.renderer;
2175
- if (process.env.NODE_ENV !== 'production') {
2176
- warnIfInvokedDuringConstruction(vm, 'lastElementChild');
2177
- }
2178
- return renderer.getLastElementChild(vm.elm);
2179
- },
2180
- render() {
2181
- const vm = getAssociatedVM(this);
2182
- return vm.def.template;
2183
- },
2184
- toString() {
2185
- const vm = getAssociatedVM(this);
2186
- return `[object ${vm.def.name}]`;
2187
- },
2302
+ return renderer.getChildNodes(vm.elm);
2303
+ },
2304
+ get firstChild() {
2305
+ const vm = getAssociatedVM(this);
2306
+ const renderer = vm.renderer;
2307
+ if (process.env.NODE_ENV !== 'production') {
2308
+ warnIfInvokedDuringConstruction(vm, 'firstChild');
2309
+ }
2310
+ return renderer.getFirstChild(vm.elm);
2311
+ },
2312
+ get firstElementChild() {
2313
+ const vm = getAssociatedVM(this);
2314
+ const renderer = vm.renderer;
2315
+ if (process.env.NODE_ENV !== 'production') {
2316
+ warnIfInvokedDuringConstruction(vm, 'firstElementChild');
2317
+ }
2318
+ return renderer.getFirstElementChild(vm.elm);
2319
+ },
2320
+ get lastChild() {
2321
+ const vm = getAssociatedVM(this);
2322
+ const renderer = vm.renderer;
2323
+ if (process.env.NODE_ENV !== 'production') {
2324
+ warnIfInvokedDuringConstruction(vm, 'lastChild');
2325
+ }
2326
+ return renderer.getLastChild(vm.elm);
2327
+ },
2328
+ get lastElementChild() {
2329
+ const vm = getAssociatedVM(this);
2330
+ const renderer = vm.renderer;
2331
+ if (process.env.NODE_ENV !== 'production') {
2332
+ warnIfInvokedDuringConstruction(vm, 'lastElementChild');
2333
+ }
2334
+ return renderer.getLastElementChild(vm.elm);
2335
+ },
2336
+ render() {
2337
+ const vm = getAssociatedVM(this);
2338
+ return vm.def.template;
2339
+ },
2340
+ toString() {
2341
+ const vm = getAssociatedVM(this);
2342
+ return `[object ${vm.def.name}]`;
2343
+ }
2188
2344
  };
2189
- const queryAndChildGetterDescriptors = create(null);
2190
- const queryMethods = [
2191
- 'getElementsByClassName',
2192
- 'getElementsByTagName',
2193
- 'querySelector',
2194
- 'querySelectorAll',
2195
- ];
2196
- // Generic passthrough for query APIs on HTMLElement to the relevant Renderer APIs
2197
- for (const queryMethod of queryMethods) {
2198
- queryAndChildGetterDescriptors[queryMethod] = {
2199
- value(arg) {
2200
- const vm = getAssociatedVM(this);
2201
- const { elm, renderer } = vm;
2202
- if (process.env.NODE_ENV !== 'production') {
2203
- warnIfInvokedDuringConstruction(vm, `${queryMethod}()`);
2204
- }
2205
- return renderer[queryMethod](elm, arg);
2206
- },
2207
- configurable: true,
2208
- enumerable: true,
2209
- writable: true,
2210
- };
2345
+ const queryAndChildGetterDescriptors = create(null);
2346
+ const queryMethods = ['getElementsByClassName', 'getElementsByTagName', 'querySelector', 'querySelectorAll'];
2347
+ // Generic passthrough for query APIs on HTMLElement to the relevant Renderer APIs
2348
+ for (const queryMethod of queryMethods) {
2349
+ queryAndChildGetterDescriptors[queryMethod] = {
2350
+ value(arg) {
2351
+ const vm = getAssociatedVM(this);
2352
+ const {
2353
+ elm,
2354
+ renderer
2355
+ } = vm;
2356
+ if (process.env.NODE_ENV !== 'production') {
2357
+ warnIfInvokedDuringConstruction(vm, `${queryMethod}()`);
2358
+ }
2359
+ return renderer[queryMethod](elm, arg);
2360
+ },
2361
+ configurable: true,
2362
+ enumerable: true,
2363
+ writable: true
2364
+ };
2211
2365
  }
2212
2366
  defineProperties(LightningElement.prototype, queryAndChildGetterDescriptors);
2213
2367
  const lightningBasedDescriptors = create(null);
2214
2368
  for (const propName in HTMLElementOriginalDescriptors) {
2215
- lightningBasedDescriptors[propName] = createBridgeToElementDescriptor(propName, HTMLElementOriginalDescriptors[propName]);
2369
+ lightningBasedDescriptors[propName] = createBridgeToElementDescriptor(propName, HTMLElementOriginalDescriptors[propName]);
2216
2370
  }
2217
2371
  defineProperties(LightningElement.prototype, lightningBasedDescriptors);
2372
+ function applyAriaReflectionToLightningElement() {
2373
+ // If ARIA reflection is not applied globally to Element.prototype, or if we are running server-side,
2374
+ // apply it to LightningElement.prototype.
2375
+ // This allows `this.aria*` property accessors to work from inside a component, and to reflect `aria-*` attrs.
2376
+ applyAriaReflection(LightningElement.prototype);
2377
+ }
2378
+ // The reason for this odd if/else branching is limitations in @lwc/features:
2379
+ // https://github.com/salesforce/lwc/blob/master/packages/%40lwc/features/README.md#only-works-with-if-statements
2380
+ if (lwcRuntimeFlags.DISABLE_ARIA_REFLECTION_POLYFILL) {
2381
+ applyAriaReflectionToLightningElement();
2382
+ } else {
2383
+ applyAriaReflectionToLightningElement();
2384
+ }
2218
2385
  defineProperty(LightningElement, 'CustomElementConstructor', {
2219
- get() {
2220
- // If required, a runtime-specific implementation must be defined.
2221
- throw new ReferenceError('The current runtime does not support CustomElementConstructor.');
2222
- },
2223
- configurable: true,
2386
+ get() {
2387
+ // If required, a runtime-specific implementation must be defined.
2388
+ throw new ReferenceError('The current runtime does not support CustomElementConstructor.');
2389
+ },
2390
+ configurable: true
2224
2391
  });
2225
2392
  if (process.env.NODE_ENV !== 'production') {
2226
- patchLightningElementPrototypeWithRestrictions(LightningElement.prototype);
2393
+ patchLightningElementPrototypeWithRestrictions(LightningElement.prototype);
2227
2394
  }
2228
2395
 
2229
2396
  function createObservedFieldPropertyDescriptor(key) {
@@ -2241,24 +2408,6 @@ function createObservedFieldPropertyDescriptor(key) {
2241
2408
  };
2242
2409
  }
2243
2410
 
2244
- /*
2245
- * Copyright (c) 2018, salesforce.com, inc.
2246
- * All rights reserved.
2247
- * SPDX-License-Identifier: MIT
2248
- * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
2249
- */
2250
- const DUMMY_ACCESSOR_REACTIVE_OBSERVER = {
2251
- observe(job) {
2252
- job();
2253
- },
2254
- reset() { },
2255
- link() { },
2256
- };
2257
- function createAccessorReactiveObserver(vm, set) {
2258
- // On the server side, we don't need mutation tracking. Skipping it improves performance.
2259
- return DUMMY_ACCESSOR_REACTIVE_OBSERVER;
2260
- }
2261
-
2262
2411
  /*
2263
2412
  * Copyright (c) 2018, salesforce.com, inc.
2264
2413
  * All rights reserved.
@@ -2266,88 +2415,69 @@ function createAccessorReactiveObserver(vm, set) {
2266
2415
  * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
2267
2416
  */
2268
2417
  function api$1() {
2269
- if (process.env.NODE_ENV !== 'production') {
2270
- assert.fail(`@api decorator can only be used as a decorator function.`);
2271
- }
2272
- throw new Error();
2418
+ if (process.env.NODE_ENV !== 'production') {
2419
+ assert.fail(`@api decorator can only be used as a decorator function.`);
2420
+ }
2421
+ throw new Error();
2273
2422
  }
2274
2423
  function createPublicPropertyDescriptor(key) {
2275
- return {
2276
- get() {
2277
- const vm = getAssociatedVM(this);
2278
- if (isBeingConstructed(vm)) {
2279
- if (process.env.NODE_ENV !== 'production') {
2280
- logError(`Can’t read the value of property \`${toString$1(key)}\` 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);
2281
- }
2282
- return;
2283
- }
2284
- return vm.cmpProps[key];
2285
- },
2286
- set(newValue) {
2287
- const vm = getAssociatedVM(this);
2288
- if (process.env.NODE_ENV !== 'production') {
2289
- const vmBeingRendered = getVMBeingRendered();
2290
- assert.invariant(!isInvokingRender, `${vmBeingRendered}.render() method has side effects on the state of ${vm}.${toString$1(key)}`);
2291
- assert.invariant(!isUpdatingTemplate, `Updating the template of ${vmBeingRendered} has side effects on the state of ${vm}.${toString$1(key)}`);
2292
- }
2293
- vm.cmpProps[key] = newValue;
2294
- },
2295
- enumerable: true,
2296
- configurable: true
2297
- };
2424
+ return {
2425
+ get() {
2426
+ const vm = getAssociatedVM(this);
2427
+ if (isBeingConstructed(vm)) {
2428
+ if (process.env.NODE_ENV !== 'production') {
2429
+ logError(`Can’t read the value of property \`${toString$1(key)}\` 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);
2430
+ }
2431
+ return;
2432
+ }
2433
+ return vm.cmpProps[key];
2434
+ },
2435
+ set(newValue) {
2436
+ const vm = getAssociatedVM(this);
2437
+ if (process.env.NODE_ENV !== 'production') {
2438
+ const vmBeingRendered = getVMBeingRendered();
2439
+ assert.invariant(!isInvokingRender, `${vmBeingRendered}.render() method has side effects on the state of ${vm}.${toString$1(key)}`);
2440
+ assert.invariant(!isUpdatingTemplate, `Updating the template of ${vmBeingRendered} has side effects on the state of ${vm}.${toString$1(key)}`);
2441
+ }
2442
+ vm.cmpProps[key] = newValue;
2443
+ },
2444
+ enumerable: true,
2445
+ configurable: true,
2446
+ };
2298
2447
  }
2299
2448
  function createPublicAccessorDescriptor(key, descriptor) {
2300
- const {
2301
- get,
2302
- set,
2303
- enumerable,
2304
- configurable
2305
- } = descriptor;
2306
- if (!isFunction$1(get)) {
2307
- if (process.env.NODE_ENV !== 'production') {
2308
- assert.invariant(isFunction$1(get), `Invalid compiler output for public accessor ${toString$1(key)} decorated with @api`);
2309
- }
2310
- throw new Error();
2311
- }
2312
- return {
2313
- get() {
2314
- if (process.env.NODE_ENV !== 'production') {
2315
- // Assert that the this value is an actual Component with an associated VM.
2316
- getAssociatedVM(this);
2317
- }
2318
- return get.call(this);
2319
- },
2320
- set(newValue) {
2321
- const vm = getAssociatedVM(this);
2322
- if (process.env.NODE_ENV !== 'production') {
2323
- const vmBeingRendered = getVMBeingRendered();
2324
- assert.invariant(!isInvokingRender, `${vmBeingRendered}.render() method has side effects on the state of ${vm}.${toString$1(key)}`);
2325
- assert.invariant(!isUpdatingTemplate, `Updating the template of ${vmBeingRendered} has side effects on the state of ${vm}.${toString$1(key)}`);
2326
- }
2327
- if (set) {
2328
- if (lwcRuntimeFlags.ENABLE_REACTIVE_SETTER) {
2329
- let ro = vm.oar[key];
2330
- if (isUndefined$1(ro)) {
2331
- ro = vm.oar[key] = createAccessorReactiveObserver();
2332
- }
2333
- // every time we invoke this setter from outside (through this wrapper setter)
2334
- // we should reset the value and then debounce just in case there is a pending
2335
- // invocation the next tick that is not longer relevant since the value is changing
2336
- // from outside.
2337
- ro.reset(newValue);
2338
- ro.observe(() => {
2339
- set.call(this, newValue);
2340
- });
2341
- } else {
2342
- set.call(this, newValue);
2449
+ const { get, set, enumerable, configurable } = descriptor;
2450
+ if (!isFunction$1(get)) {
2451
+ if (process.env.NODE_ENV !== 'production') {
2452
+ assert.invariant(isFunction$1(get), `Invalid compiler output for public accessor ${toString$1(key)} decorated with @api`);
2343
2453
  }
2344
- } else if (process.env.NODE_ENV !== 'production') {
2345
- assert.fail(`Invalid attempt to set a new value for property ${toString$1(key)} of ${vm} that does not has a setter decorated with @api.`);
2346
- }
2347
- },
2348
- enumerable,
2349
- configurable
2350
- };
2454
+ throw new Error();
2455
+ }
2456
+ return {
2457
+ get() {
2458
+ if (process.env.NODE_ENV !== 'production') {
2459
+ // Assert that the this value is an actual Component with an associated VM.
2460
+ getAssociatedVM(this);
2461
+ }
2462
+ return get.call(this);
2463
+ },
2464
+ set(newValue) {
2465
+ const vm = getAssociatedVM(this);
2466
+ if (process.env.NODE_ENV !== 'production') {
2467
+ const vmBeingRendered = getVMBeingRendered();
2468
+ assert.invariant(!isInvokingRender, `${vmBeingRendered}.render() method has side effects on the state of ${vm}.${toString$1(key)}`);
2469
+ assert.invariant(!isUpdatingTemplate, `Updating the template of ${vmBeingRendered} has side effects on the state of ${vm}.${toString$1(key)}`);
2470
+ }
2471
+ if (set) {
2472
+ set.call(this, newValue);
2473
+ }
2474
+ else if (process.env.NODE_ENV !== 'production') {
2475
+ assert.fail(`Invalid attempt to set a new value for property ${toString$1(key)} of ${vm} that does not has a setter decorated with @api.`);
2476
+ }
2477
+ },
2478
+ enumerable,
2479
+ configurable,
2480
+ };
2351
2481
  }
2352
2482
 
2353
2483
  /*
@@ -2671,12 +2801,6 @@ function checkVersionMismatch(func, type) {
2671
2801
  }
2672
2802
  }
2673
2803
 
2674
- /*
2675
- * Copyright (c) 2018, salesforce.com, inc.
2676
- * All rights reserved.
2677
- * SPDX-License-Identifier: MIT
2678
- * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
2679
- */
2680
2804
  const signedTemplateSet = new Set();
2681
2805
  function defaultEmptyTemplate() {
2682
2806
  return [];
@@ -2694,32 +2818,6 @@ function registerTemplate(tpl) {
2694
2818
  checkVersionMismatch(tpl, 'template');
2695
2819
  }
2696
2820
  signedTemplateSet.add(tpl);
2697
- // FIXME[@W-10950976]: the template object should be frozen, and it should not be possible to set
2698
- // the stylesheets or stylesheetToken(s). For backwards compat, though, we shim stylesheetTokens
2699
- // on top of stylesheetToken for anyone who is accessing the old internal API.
2700
- // Details: https://salesforce.quip.com/v1rmAFu2cKAr
2701
- defineProperty(tpl, 'stylesheetTokens', {
2702
- enumerable: true,
2703
- configurable: true,
2704
- get() {
2705
- const { stylesheetToken } = this;
2706
- if (isUndefined$1(stylesheetToken)) {
2707
- return stylesheetToken;
2708
- }
2709
- // Shim for the old `stylesheetTokens` property
2710
- // See https://github.com/salesforce/lwc/pull/2332/files#diff-7901555acef29969adaa6583185b3e9bce475cdc6f23e799a54e0018cb18abaa
2711
- return {
2712
- hostAttribute: `${stylesheetToken}-host`,
2713
- shadowAttribute: stylesheetToken,
2714
- };
2715
- },
2716
- set(value) {
2717
- // If the value is null or some other exotic object, you would be broken anyway in the past
2718
- // because the engine would try to access hostAttribute/shadowAttribute, which would throw an error.
2719
- // However it may be undefined in newer versions of LWC, so we need to guard against that case.
2720
- this.stylesheetToken = isUndefined$1(value) ? undefined : value.shadowAttribute;
2721
- },
2722
- });
2723
2821
  // chaining this method as a way to wrap existing
2724
2822
  // assignment of templates easily, without too much transformation
2725
2823
  return tpl;
@@ -2747,136 +2845,145 @@ function sanitizeAttribute(tagName, namespaceUri, attrName, attrValue) {
2747
2845
  const cachedGetterByKey = create(null);
2748
2846
  const cachedSetterByKey = create(null);
2749
2847
  function createGetter(key) {
2750
- let fn = cachedGetterByKey[key];
2751
- if (isUndefined$1(fn)) {
2752
- fn = cachedGetterByKey[key] = function () {
2753
- const vm = getAssociatedVM(this);
2754
- const { getHook } = vm;
2755
- return getHook(vm.component, key);
2756
- };
2757
- }
2758
- return fn;
2848
+ let fn = cachedGetterByKey[key];
2849
+ if (isUndefined$1(fn)) {
2850
+ fn = cachedGetterByKey[key] = function () {
2851
+ const vm = getAssociatedVM(this);
2852
+ const {
2853
+ getHook
2854
+ } = vm;
2855
+ return getHook(vm.component, key);
2856
+ };
2857
+ }
2858
+ return fn;
2759
2859
  }
2760
2860
  function createSetter(key) {
2761
- let fn = cachedSetterByKey[key];
2762
- if (isUndefined$1(fn)) {
2763
- fn = cachedSetterByKey[key] = function (newValue) {
2764
- const vm = getAssociatedVM(this);
2765
- const { setHook } = vm;
2766
- newValue = getReadOnlyProxy(newValue);
2767
- setHook(vm.component, key, newValue);
2768
- };
2769
- }
2770
- return fn;
2861
+ let fn = cachedSetterByKey[key];
2862
+ if (isUndefined$1(fn)) {
2863
+ fn = cachedSetterByKey[key] = function (newValue) {
2864
+ const vm = getAssociatedVM(this);
2865
+ const {
2866
+ setHook
2867
+ } = vm;
2868
+ newValue = getReadOnlyProxy(newValue);
2869
+ setHook(vm.component, key, newValue);
2870
+ };
2871
+ }
2872
+ return fn;
2771
2873
  }
2772
2874
  function createMethodCaller(methodName) {
2773
- return function () {
2774
- const vm = getAssociatedVM(this);
2775
- const { callHook, component } = vm;
2776
- const fn = component[methodName];
2777
- return callHook(vm.component, fn, ArraySlice.call(arguments));
2778
- };
2875
+ return function () {
2876
+ const vm = getAssociatedVM(this);
2877
+ const {
2878
+ callHook,
2879
+ component
2880
+ } = vm;
2881
+ const fn = component[methodName];
2882
+ return callHook(vm.component, fn, ArraySlice.call(arguments));
2883
+ };
2779
2884
  }
2780
2885
  function createAttributeChangedCallback(attributeToPropMap, superAttributeChangedCallback) {
2781
- return function attributeChangedCallback(attrName, oldValue, newValue) {
2782
- if (oldValue === newValue) {
2783
- // Ignore same values.
2784
- return;
2785
- }
2786
- const propName = attributeToPropMap[attrName];
2787
- if (isUndefined$1(propName)) {
2788
- if (!isUndefined$1(superAttributeChangedCallback)) {
2789
- // delegate unknown attributes to the super.
2790
- // Typescript does not like it when you treat the `arguments` object as an array
2791
- // @ts-ignore type-mismatch
2792
- superAttributeChangedCallback.apply(this, arguments);
2793
- }
2794
- return;
2795
- }
2796
- if (!isAttributeLocked(this, attrName)) {
2797
- // Ignore changes triggered by the engine itself during:
2798
- // * diffing when public props are attempting to reflect to the DOM
2799
- // * component via `this.setAttribute()`, should never update the prop
2800
- // Both cases, the setAttribute call is always wrapped by the unlocking of the
2801
- // attribute to be changed
2802
- return;
2803
- }
2804
- // Reflect attribute change to the corresponding property when changed from outside.
2805
- this[propName] = newValue;
2806
- };
2807
- }
2808
- function HTMLBridgeElementFactory(SuperClass, props, methods) {
2809
- let HTMLBridgeElement;
2810
- /**
2811
- * Modern browsers will have all Native Constructors as regular Classes
2812
- * and must be instantiated with the new keyword. In older browsers,
2813
- * specifically IE11, those are objects with a prototype property defined,
2814
- * since they are not supposed to be extended or instantiated with the
2815
- * new keyword. This forking logic supports both cases, specifically because
2816
- * wc.ts relies on the construction path of the bridges to create new
2817
- * fully qualifying web components.
2818
- */
2819
- if (isFunction$1(SuperClass)) {
2820
- HTMLBridgeElement = class extends SuperClass {
2821
- };
2822
- }
2823
- else {
2824
- HTMLBridgeElement = function () {
2825
- // Bridge classes are not supposed to be instantiated directly in
2826
- // browsers that do not support web components.
2827
- throw new TypeError('Illegal constructor');
2828
- };
2829
- // prototype inheritance dance
2830
- setPrototypeOf(HTMLBridgeElement, SuperClass);
2831
- setPrototypeOf(HTMLBridgeElement.prototype, SuperClass.prototype);
2832
- defineProperty(HTMLBridgeElement.prototype, 'constructor', {
2833
- writable: true,
2834
- configurable: true,
2835
- value: HTMLBridgeElement,
2836
- });
2886
+ return function attributeChangedCallback(attrName, oldValue, newValue) {
2887
+ if (oldValue === newValue) {
2888
+ // Ignore same values.
2889
+ return;
2837
2890
  }
2838
- // generating the hash table for attributes to avoid duplicate fields and facilitate validation
2839
- // and false positives in case of inheritance.
2840
- const attributeToPropMap = create(null);
2841
- const { attributeChangedCallback: superAttributeChangedCallback } = SuperClass.prototype;
2842
- const { observedAttributes: superObservedAttributes = [] } = SuperClass;
2843
- const descriptors = create(null);
2844
- // expose getters and setters for each public props on the new Element Bridge
2845
- for (let i = 0, len = props.length; i < len; i += 1) {
2846
- const propName = props[i];
2847
- attributeToPropMap[htmlPropertyToAttribute(propName)] = propName;
2848
- descriptors[propName] = {
2849
- get: createGetter(propName),
2850
- set: createSetter(propName),
2851
- enumerable: true,
2852
- configurable: true,
2853
- };
2891
+ const propName = attributeToPropMap[attrName];
2892
+ if (isUndefined$1(propName)) {
2893
+ if (!isUndefined$1(superAttributeChangedCallback)) {
2894
+ // delegate unknown attributes to the super.
2895
+ // Typescript does not like it when you treat the `arguments` object as an array
2896
+ // @ts-ignore type-mismatch
2897
+ superAttributeChangedCallback.apply(this, arguments);
2898
+ }
2899
+ return;
2854
2900
  }
2855
- // expose public methods as props on the new Element Bridge
2856
- for (let i = 0, len = methods.length; i < len; i += 1) {
2857
- const methodName = methods[i];
2858
- descriptors[methodName] = {
2859
- value: createMethodCaller(methodName),
2860
- writable: true,
2861
- configurable: true,
2862
- };
2901
+ if (!isAttributeLocked(this, attrName)) {
2902
+ // Ignore changes triggered by the engine itself during:
2903
+ // * diffing when public props are attempting to reflect to the DOM
2904
+ // * component via `this.setAttribute()`, should never update the prop
2905
+ // Both cases, the setAttribute call is always wrapped by the unlocking of the
2906
+ // attribute to be changed
2907
+ return;
2863
2908
  }
2864
- // creating a new attributeChangedCallback per bridge because they are bound to the corresponding
2865
- // map of attributes to props. We do this after all other props and methods to avoid the possibility
2866
- // of getting overrule by a class declaration in user-land, and we make it non-writable, non-configurable
2867
- // to preserve this definition.
2868
- descriptors.attributeChangedCallback = {
2869
- value: createAttributeChangedCallback(attributeToPropMap, superAttributeChangedCallback),
2909
+ // Reflect attribute change to the corresponding property when changed from outside.
2910
+ this[propName] = newValue;
2911
+ };
2912
+ }
2913
+ function HTMLBridgeElementFactory(SuperClass, props, methods) {
2914
+ let HTMLBridgeElement;
2915
+ /**
2916
+ * Modern browsers will have all Native Constructors as regular Classes
2917
+ * and must be instantiated with the new keyword. In older browsers,
2918
+ * specifically IE11, those are objects with a prototype property defined,
2919
+ * since they are not supposed to be extended or instantiated with the
2920
+ * new keyword. This forking logic supports both cases, specifically because
2921
+ * wc.ts relies on the construction path of the bridges to create new
2922
+ * fully qualifying web components.
2923
+ */
2924
+ if (isFunction$1(SuperClass)) {
2925
+ HTMLBridgeElement = class extends SuperClass {};
2926
+ } else {
2927
+ HTMLBridgeElement = function () {
2928
+ // Bridge classes are not supposed to be instantiated directly in
2929
+ // browsers that do not support web components.
2930
+ throw new TypeError('Illegal constructor');
2870
2931
  };
2871
- // Specify attributes for which we want to reflect changes back to their corresponding
2872
- // properties via attributeChangedCallback.
2873
- defineProperty(HTMLBridgeElement, 'observedAttributes', {
2874
- get() {
2875
- return [...superObservedAttributes, ...keys(attributeToPropMap)];
2876
- },
2932
+ // prototype inheritance dance
2933
+ setPrototypeOf(HTMLBridgeElement, SuperClass);
2934
+ setPrototypeOf(HTMLBridgeElement.prototype, SuperClass.prototype);
2935
+ defineProperty(HTMLBridgeElement.prototype, 'constructor', {
2936
+ writable: true,
2937
+ configurable: true,
2938
+ value: HTMLBridgeElement
2877
2939
  });
2878
- defineProperties(HTMLBridgeElement.prototype, descriptors);
2879
- return HTMLBridgeElement;
2940
+ }
2941
+ // generating the hash table for attributes to avoid duplicate fields and facilitate validation
2942
+ // and false positives in case of inheritance.
2943
+ const attributeToPropMap = create(null);
2944
+ const {
2945
+ attributeChangedCallback: superAttributeChangedCallback
2946
+ } = SuperClass.prototype;
2947
+ const {
2948
+ observedAttributes: superObservedAttributes = []
2949
+ } = SuperClass;
2950
+ const descriptors = create(null);
2951
+ // expose getters and setters for each public props on the new Element Bridge
2952
+ for (let i = 0, len = props.length; i < len; i += 1) {
2953
+ const propName = props[i];
2954
+ attributeToPropMap[htmlPropertyToAttribute(propName)] = propName;
2955
+ descriptors[propName] = {
2956
+ get: createGetter(propName),
2957
+ set: createSetter(propName),
2958
+ enumerable: true,
2959
+ configurable: true
2960
+ };
2961
+ }
2962
+ // expose public methods as props on the new Element Bridge
2963
+ for (let i = 0, len = methods.length; i < len; i += 1) {
2964
+ const methodName = methods[i];
2965
+ descriptors[methodName] = {
2966
+ value: createMethodCaller(methodName),
2967
+ writable: true,
2968
+ configurable: true
2969
+ };
2970
+ }
2971
+ // creating a new attributeChangedCallback per bridge because they are bound to the corresponding
2972
+ // map of attributes to props. We do this after all other props and methods to avoid the possibility
2973
+ // of getting overrule by a class declaration in user-land, and we make it non-writable, non-configurable
2974
+ // to preserve this definition.
2975
+ descriptors.attributeChangedCallback = {
2976
+ value: createAttributeChangedCallback(attributeToPropMap, superAttributeChangedCallback)
2977
+ };
2978
+ // Specify attributes for which we want to reflect changes back to their corresponding
2979
+ // properties via attributeChangedCallback.
2980
+ defineProperty(HTMLBridgeElement, 'observedAttributes', {
2981
+ get() {
2982
+ return [...superObservedAttributes, ...keys(attributeToPropMap)];
2983
+ }
2984
+ });
2985
+ defineProperties(HTMLBridgeElement.prototype, descriptors);
2986
+ return HTMLBridgeElement;
2880
2987
  }
2881
2988
  const BaseBridgeElement = HTMLBridgeElementFactory(HTMLElementConstructor, getOwnPropertyNames$1(HTMLElementOriginalDescriptors), []);
2882
2989
  freeze(BaseBridgeElement);
@@ -4111,11 +4218,13 @@ function applyDomManual(elm, vnode) {
4111
4218
  function applyElementRestrictions(elm, vnode) {
4112
4219
  var _a, _b;
4113
4220
  if (process.env.NODE_ENV !== 'production') {
4221
+ const isSynthetic = vnode.owner.shadowMode === 1 /* ShadowMode.Synthetic */;
4114
4222
  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 */;
4115
4223
  const isLight = vnode.owner.renderMode === 0 /* RenderMode.Light */;
4116
4224
  patchElementWithRestrictions(elm, {
4117
4225
  isPortal,
4118
- isLight
4226
+ isLight,
4227
+ isSynthetic
4119
4228
  });
4120
4229
  }
4121
4230
  }
@@ -4531,7 +4640,7 @@ function s(slotName, data, children, slotset) {
4531
4640
  // undefined is for root components, but root components cannot accept slotted content
4532
4641
  setVMBeingRendered(slotset.owner);
4533
4642
  try {
4534
- ArrayPush$1.apply(newChildren, vnode.factory(data.slotData));
4643
+ ArrayPush$1.call(newChildren, vnode.factory(data.slotData, data.key));
4535
4644
  }
4536
4645
  finally {
4537
4646
  setVMBeingRendered(vmBeingRenderedInception);
@@ -5366,15 +5475,10 @@ function resetComponentStateWhenRemoved(vm) {
5366
5475
  } = vm;
5367
5476
  if (state !== 2 /* VMState.disconnected */) {
5368
5477
  const {
5369
- oar,
5370
5478
  tro
5371
5479
  } = vm;
5372
5480
  // Making sure that any observing record will not trigger the rehydrated on this vm
5373
5481
  tro.reset();
5374
- // Making sure that any observing accessor record will not trigger the setter to be reinvoked
5375
- for (const key in oar) {
5376
- oar[key].reset();
5377
- }
5378
5482
  runDisconnectedCallback(vm);
5379
5483
  // Spec: https://dom.spec.whatwg.org/#concept-node-remove (step 14-15)
5380
5484
  runChildNodesDisconnectedCallback(vm);
@@ -5427,7 +5531,6 @@ function createVM(elm, ctor, renderer, options) {
5427
5531
  cmpSlots: {
5428
5532
  slotAssignments: create(null)
5429
5533
  },
5430
- oar: create(null),
5431
5534
  cmpTemplate: null,
5432
5535
  hydrated: Boolean(hydrated),
5433
5536
  renderMode: def.renderMode,
@@ -6113,96 +6216,168 @@ function setHooks(hooks) {
6113
6216
  // See @lwc/engine-core/src/framework/template.ts
6114
6217
  const TEMPLATE_PROPS = ['slots', 'stylesheetToken', 'stylesheets', 'renderMode'];
6115
6218
  // Via https://www.npmjs.com/package/object-observer
6116
- const ARRAY_MUTATION_METHODS = [
6117
- 'pop',
6118
- 'push',
6119
- 'shift',
6120
- 'unshift',
6121
- 'reverse',
6122
- 'sort',
6123
- 'fill',
6124
- 'splice',
6125
- 'copyWithin',
6126
- ];
6219
+ const ARRAY_MUTATION_METHODS = ['pop', 'push', 'shift', 'unshift', 'reverse', 'sort', 'fill', 'splice', 'copyWithin'];
6220
+ // Expandos that may be placed on a stylesheet factory function, and which are meaningful to LWC at runtime
6221
+ const STYLESHEET_FUNCTION_EXPANDOS = [
6222
+ // SEE `KEY__SCOPED_CSS` in @lwc/style-compiler
6223
+ '$scoped$'];
6127
6224
  function getOriginalArrayMethod(prop) {
6128
- switch (prop) {
6129
- case 'pop':
6130
- return ArrayPop;
6131
- case 'push':
6132
- return ArrayPush$1;
6133
- case 'shift':
6134
- return ArrayShift;
6135
- case 'unshift':
6136
- return ArrayUnshift;
6137
- case 'reverse':
6138
- return ArrayReverse;
6139
- case 'sort':
6140
- return ArraySort;
6141
- case 'fill':
6142
- return ArrayFill;
6143
- case 'splice':
6144
- return ArraySplice;
6145
- case 'copyWithin':
6146
- return ArrayCopyWithin;
6147
- }
6225
+ switch (prop) {
6226
+ case 'pop':
6227
+ return ArrayPop;
6228
+ case 'push':
6229
+ return ArrayPush$1;
6230
+ case 'shift':
6231
+ return ArrayShift;
6232
+ case 'unshift':
6233
+ return ArrayUnshift;
6234
+ case 'reverse':
6235
+ return ArrayReverse;
6236
+ case 'sort':
6237
+ return ArraySort;
6238
+ case 'fill':
6239
+ return ArrayFill;
6240
+ case 'splice':
6241
+ return ArraySplice;
6242
+ case 'copyWithin':
6243
+ return ArrayCopyWithin;
6244
+ }
6148
6245
  }
6149
6246
  let mutationWarningsSilenced = false;
6150
- // Warn if the user tries to mutate tmpl.stylesheets, e.g.:
6247
+ // Warn if the user tries to mutate a stylesheets array, e.g.:
6151
6248
  // `tmpl.stylesheets.push(someStylesheetFunction)`
6152
6249
  function warnOnArrayMutation(stylesheets) {
6153
- // We can't handle users calling Array.prototype.slice.call(tmpl.stylesheets), but
6154
- // we can at least warn when they use the most common mutation methods.
6155
- for (const prop of ARRAY_MUTATION_METHODS) {
6156
- const originalArrayMethod = getOriginalArrayMethod(prop);
6157
- stylesheets[prop] = function arrayMutationWarningWrapper() {
6158
- logError(`Mutating the "stylesheets" array on a template function ` +
6159
- `is deprecated and may be removed in a future version of LWC.`);
6160
- // @ts-ignore
6161
- return originalArrayMethod.apply(this, arguments);
6162
- };
6250
+ // We can't handle users calling Array.prototype.slice.call(tmpl.stylesheets), but
6251
+ // we can at least warn when they use the most common mutation methods.
6252
+ for (const prop of ARRAY_MUTATION_METHODS) {
6253
+ const originalArrayMethod = getOriginalArrayMethod(prop);
6254
+ stylesheets[prop] = function arrayMutationWarningWrapper() {
6255
+ logError(`Mutating the "stylesheets" array on a template function ` + `is deprecated and may be removed in a future version of LWC.`);
6256
+ // @ts-ignore
6257
+ return originalArrayMethod.apply(this, arguments);
6258
+ };
6259
+ }
6260
+ }
6261
+ // Warn if the user tries to mutate a stylesheet factory function, e.g.:
6262
+ // `stylesheet.$scoped$ = true`
6263
+ function warnOnStylesheetFunctionMutation(stylesheet) {
6264
+ // We could warn on other properties, but in practice only certain expandos are meaningful to LWC at runtime
6265
+ for (const prop of STYLESHEET_FUNCTION_EXPANDOS) {
6266
+ let value = stylesheet[prop];
6267
+ defineProperty(stylesheet, prop, {
6268
+ enumerable: true,
6269
+ configurable: true,
6270
+ get() {
6271
+ return value;
6272
+ },
6273
+ set(newValue) {
6274
+ logError(`Dynamically setting the "${prop}" property on a stylesheet function ` + `is deprecated and may be removed in a future version of LWC.`);
6275
+ value = newValue;
6276
+ }
6277
+ });
6278
+ }
6279
+ }
6280
+ // Warn on either array or stylesheet (function) mutation, in a deeply-nested array
6281
+ function warnOnStylesheetsMutation(stylesheets) {
6282
+ traverseStylesheets(stylesheets, subStylesheets => {
6283
+ if (isArray$1(subStylesheets)) {
6284
+ warnOnArrayMutation(subStylesheets);
6285
+ } else {
6286
+ warnOnStylesheetFunctionMutation(subStylesheets);
6287
+ }
6288
+ });
6289
+ }
6290
+ // Deeply freeze the entire array (of arrays) of stylesheet factory functions
6291
+ function deepFreeze(stylesheets) {
6292
+ traverseStylesheets(stylesheets, subStylesheets => {
6293
+ freeze(subStylesheets);
6294
+ });
6295
+ }
6296
+ // Deep-traverse an array (of arrays) of stylesheet factory functions, and call the callback for every array/function
6297
+ function traverseStylesheets(stylesheets, callback) {
6298
+ callback(stylesheets);
6299
+ for (let i = 0; i < stylesheets.length; i++) {
6300
+ const stylesheet = stylesheets[i];
6301
+ if (isArray$1(stylesheet)) {
6302
+ traverseStylesheets(stylesheet, callback);
6303
+ } else {
6304
+ callback(stylesheet);
6163
6305
  }
6306
+ }
6164
6307
  }
6165
- // TODO [#2782]: eventually freezeTemplate() will _actually_ freeze the tmpl object. Today it
6166
- // just warns on mutation.
6167
6308
  function freezeTemplate(tmpl) {
6309
+ if (lwcRuntimeFlags.ENABLE_FROZEN_TEMPLATE) {
6310
+ // Deep freeze the template
6311
+ freeze(tmpl);
6312
+ if (!isUndefined$1(tmpl.stylesheets)) {
6313
+ deepFreeze(tmpl.stylesheets);
6314
+ }
6315
+ } else {
6316
+ // TODO [#2782]: remove this flag and delete the legacy behavior
6317
+ // When ENABLE_FROZEN_TEMPLATE is false, then we shim stylesheetTokens on top of stylesheetToken for anyone who
6318
+ // is accessing the old internal API (backwards compat). Details: https://salesforce.quip.com/v1rmAFu2cKAr
6319
+ defineProperty(tmpl, 'stylesheetTokens', {
6320
+ enumerable: true,
6321
+ configurable: true,
6322
+ get() {
6323
+ const {
6324
+ stylesheetToken
6325
+ } = this;
6326
+ if (isUndefined$1(stylesheetToken)) {
6327
+ return stylesheetToken;
6328
+ }
6329
+ // Shim for the old `stylesheetTokens` property
6330
+ // See https://github.com/salesforce/lwc/pull/2332/files#diff-7901555acef29969adaa6583185b3e9bce475cdc6f23e799a54e0018cb18abaa
6331
+ return {
6332
+ hostAttribute: `${stylesheetToken}-host`,
6333
+ shadowAttribute: stylesheetToken
6334
+ };
6335
+ },
6336
+ set(value) {
6337
+ // If the value is null or some other exotic object, you would be broken anyway in the past
6338
+ // because the engine would try to access hostAttribute/shadowAttribute, which would throw an error.
6339
+ // However it may be undefined in newer versions of LWC, so we need to guard against that case.
6340
+ this.stylesheetToken = isUndefined$1(value) ? undefined : value.shadowAttribute;
6341
+ }
6342
+ });
6343
+ // When ENABLE_FROZEN_TEMPLATE is false, warn in dev mode whenever someone is mutating the template
6168
6344
  if (process.env.NODE_ENV !== 'production') {
6169
- if (!isUndefined$1(tmpl.stylesheets)) {
6170
- warnOnArrayMutation(tmpl.stylesheets);
6171
- }
6172
- for (const prop of TEMPLATE_PROPS) {
6173
- let value = tmpl[prop];
6174
- defineProperty(tmpl, prop, {
6175
- enumerable: true,
6176
- configurable: true,
6177
- get() {
6178
- return value;
6179
- },
6180
- set(newValue) {
6181
- if (!mutationWarningsSilenced) {
6182
- logError(`Dynamically setting the "${prop}" property on a template function ` +
6183
- `is deprecated and may be removed in a future version of LWC.`);
6184
- }
6185
- value = newValue;
6186
- },
6187
- });
6188
- }
6189
- const originalDescriptor = getOwnPropertyDescriptor$1(tmpl, 'stylesheetTokens');
6190
- defineProperty(tmpl, 'stylesheetTokens', {
6191
- enumerable: true,
6192
- configurable: true,
6193
- get: originalDescriptor.get,
6194
- set(value) {
6195
- logError(`Dynamically setting the "stylesheetTokens" property on a template function ` +
6196
- `is deprecated and may be removed in a future version of LWC.`);
6197
- // Avoid logging twice (for both stylesheetToken and stylesheetTokens)
6198
- mutationWarningsSilenced = true;
6199
- originalDescriptor.set.call(this, value);
6200
- mutationWarningsSilenced = false;
6201
- },
6345
+ if (!isUndefined$1(tmpl.stylesheets)) {
6346
+ warnOnStylesheetsMutation(tmpl.stylesheets);
6347
+ }
6348
+ for (const prop of TEMPLATE_PROPS) {
6349
+ let value = tmpl[prop];
6350
+ defineProperty(tmpl, prop, {
6351
+ enumerable: true,
6352
+ configurable: true,
6353
+ get() {
6354
+ return value;
6355
+ },
6356
+ set(newValue) {
6357
+ if (!mutationWarningsSilenced) {
6358
+ logError(`Dynamically setting the "${prop}" property on a template function ` + `is deprecated and may be removed in a future version of LWC.`);
6359
+ }
6360
+ value = newValue;
6361
+ }
6202
6362
  });
6363
+ }
6364
+ const originalDescriptor = getOwnPropertyDescriptor$1(tmpl, 'stylesheetTokens');
6365
+ defineProperty(tmpl, 'stylesheetTokens', {
6366
+ enumerable: true,
6367
+ configurable: true,
6368
+ get: originalDescriptor.get,
6369
+ set(value) {
6370
+ logError(`Dynamically setting the "stylesheetTokens" property on a template function ` + `is deprecated and may be removed in a future version of LWC.`);
6371
+ // Avoid logging twice (for both stylesheetToken and stylesheetTokens)
6372
+ mutationWarningsSilenced = true;
6373
+ originalDescriptor.set.call(this, value);
6374
+ mutationWarningsSilenced = false;
6375
+ }
6376
+ });
6203
6377
  }
6378
+ }
6204
6379
  }
6205
- /* version: 2.32.0 */
6380
+ /* version: 2.33.0 */
6206
6381
 
6207
6382
  /*
6208
6383
  * Copyright (c) 2020, salesforce.com, inc.
@@ -6673,6 +6848,6 @@ function renderComponent(tagName, Ctor, props = {}) {
6673
6848
  */
6674
6849
  freeze(LightningElement);
6675
6850
  seal(LightningElement.prototype);
6676
- /* version: 2.32.0 */
6851
+ /* version: 2.33.0 */
6677
6852
 
6678
6853
  export { LightningElement, api$1 as api, createContextProvider, freezeTemplate, getComponentDef, isComponentConstructor, parseFragment, parseFragment as parseSVGFragment, readonly, register, registerComponent, registerDecorators, registerTemplate, renderComponent, renderer, sanitizeAttribute, setFeatureFlag, setFeatureFlagForTest, setHooks, track, unwrap, wire };