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