lwc 2.32.1 → 2.34.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 +842 -595
  2. package/dist/engine-dom/iife/es2017/engine-dom.js +842 -595
  3. package/dist/engine-dom/iife/es2017/engine-dom.min.js +1 -1
  4. package/dist/engine-dom/iife/es2017/engine-dom_debug.js +758 -501
  5. package/dist/engine-dom/iife/es5/engine-dom.js +316 -177
  6. package/dist/engine-dom/iife/es5/engine-dom.min.js +1 -1
  7. package/dist/engine-dom/iife/es5/engine-dom_debug.js +329 -173
  8. package/dist/engine-dom/umd/es2017/engine-dom.js +842 -595
  9. package/dist/engine-dom/umd/es2017/engine-dom.min.js +1 -1
  10. package/dist/engine-dom/umd/es2017/engine-dom_debug.js +758 -501
  11. package/dist/engine-dom/umd/es5/engine-dom.js +316 -177
  12. package/dist/engine-dom/umd/es5/engine-dom.min.js +1 -1
  13. package/dist/engine-dom/umd/es5/engine-dom_debug.js +329 -173
  14. package/dist/engine-server/commonjs/es2017/engine-server.js +807 -507
  15. package/dist/engine-server/commonjs/es2017/engine-server.min.js +1 -1
  16. package/dist/engine-server/esm/es2017/engine-server.js +807 -507
  17. package/dist/synthetic-shadow/esm/es2017/synthetic-shadow.js +3 -3
  18. package/dist/synthetic-shadow/iife/es2017/synthetic-shadow.js +3 -3
  19. package/dist/synthetic-shadow/iife/es2017/synthetic-shadow.min.js +2 -2
  20. package/dist/synthetic-shadow/iife/es2017/synthetic-shadow_debug.js +3 -3
  21. package/dist/synthetic-shadow/iife/es5/synthetic-shadow.js +7 -5
  22. package/dist/synthetic-shadow/iife/es5/synthetic-shadow.min.js +2 -2
  23. package/dist/synthetic-shadow/iife/es5/synthetic-shadow_debug.js +7 -5
  24. package/dist/synthetic-shadow/umd/es2017/synthetic-shadow.js +3 -3
  25. package/dist/synthetic-shadow/umd/es2017/synthetic-shadow.min.js +2 -2
  26. package/dist/synthetic-shadow/umd/es2017/synthetic-shadow_debug.js +3 -3
  27. package/dist/synthetic-shadow/umd/es5/synthetic-shadow.js +7 -5
  28. package/dist/synthetic-shadow/umd/es5/synthetic-shadow.min.js +2 -2
  29. package/dist/synthetic-shadow/umd/es5/synthetic-shadow_debug.js +7 -5
  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.1";
473
+ const LWC_VERSION = "2.34.0";
471
474
  const LWC_VERSION_COMMENT_REGEX = /\/\*LWC compiler v([\d.]+)\*\/\s*}/;
472
- /** version: 2.32.1 */
475
+ /** version: 2.34.0 */
473
476
 
474
477
  /*
475
478
  * Copyright (c) 2020, salesforce.com, inc.
@@ -523,6 +526,8 @@ const features = {
523
526
  DISABLE_LIGHT_DOM_UNSCOPED_CSS: null,
524
527
  ENABLE_SCOPED_CUSTOM_ELEMENT_REGISTRY: null,
525
528
  ENABLE_FROZEN_TEMPLATE: null,
529
+ DISABLE_ARIA_REFLECTION_POLYFILL: null,
530
+ ENABLE_PROGRAMMATIC_STYLESHEETS: null,
526
531
  };
527
532
  if (!_globalThis.lwcRuntimeFlags) {
528
533
  Object.defineProperty(_globalThis, 'lwcRuntimeFlags', { value: create(null) });
@@ -576,7 +581,71 @@ function setFeatureFlagForTest(name, value) {
576
581
  setFeatureFlag(name, value);
577
582
  }
578
583
  }
579
- /** version: 2.32.1 */
584
+ /** version: 2.34.0 */
585
+
586
+ /**
587
+ * Copyright (C) 2018 salesforce.com, inc.
588
+ */
589
+
590
+ /*
591
+ * Copyright (c) 2018, salesforce.com, inc.
592
+ * All rights reserved.
593
+ * SPDX-License-Identifier: MIT
594
+ * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
595
+ */
596
+ function detect(propName, prototype) {
597
+ return isUndefined$1(getOwnPropertyDescriptor$1(prototype, propName));
598
+ }
599
+
600
+ /*
601
+ * Copyright (c) 2018, salesforce.com, inc.
602
+ * All rights reserved.
603
+ * SPDX-License-Identifier: MIT
604
+ * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
605
+ */
606
+ function createAriaPropertyPropertyDescriptor(attrName) {
607
+ // Note that we need to call this.{get,set,has,remove}Attribute rather than dereferencing
608
+ // from Element.prototype, because these methods are overridden in LightningElement.
609
+ return {
610
+ get() {
611
+ // reflect what's in the attribute
612
+ return this.hasAttribute(attrName) ? this.getAttribute(attrName) : null;
613
+ },
614
+ set(newValue) {
615
+ // reflect into the corresponding attribute
616
+ if (isNull(newValue)) {
617
+ this.removeAttribute(attrName);
618
+ }
619
+ else {
620
+ this.setAttribute(attrName, newValue);
621
+ }
622
+ },
623
+ configurable: true,
624
+ enumerable: true,
625
+ };
626
+ }
627
+ function patch$1(propName, prototype) {
628
+ const attrName = AriaPropNameToAttrNameMap[propName];
629
+ const descriptor = createAriaPropertyPropertyDescriptor(attrName);
630
+ defineProperty(prototype, propName, descriptor);
631
+ }
632
+
633
+ /*
634
+ * Copyright (c) 2018, salesforce.com, inc.
635
+ * All rights reserved.
636
+ * SPDX-License-Identifier: MIT
637
+ * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
638
+ */
639
+ function applyAriaReflection(prototype = Element.prototype) {
640
+ const ElementPrototypeAriaPropertyNames = keys(AriaPropNameToAttrNameMap);
641
+ for (let i = 0, len = ElementPrototypeAriaPropertyNames.length; i < len; i += 1) {
642
+ const propName = ElementPrototypeAriaPropertyNames[i];
643
+ if (detect(propName, prototype)) {
644
+ patch$1(propName, prototype);
645
+ }
646
+ }
647
+ }
648
+ /** version: 2.34.0 */
580
649
 
581
650
  /* proxy-compat-disable */
582
651
 
@@ -742,6 +811,7 @@ function log(method, message, vm) {
742
811
  if (!isUndefined$1(vm)) {
743
812
  msg = `${msg}\n${getComponentStack(vm)}`;
744
813
  }
814
+ // In Jest tests, reduce the warning and error verbosity by not printing the callstack
745
815
  if (process.env.NODE_ENV === 'test') {
746
816
  /* eslint-disable-next-line no-console */
747
817
  console[method](msg);
@@ -808,6 +878,9 @@ function offsetPropertyErrorMessage(name) {
808
878
  // Global HTML Attributes & Properties
809
879
  // https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes
810
880
  // https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement
881
+ //
882
+ // If you update this list, check for test files that recapitulate the same list. Searching the codebase
883
+ // for e.g. "dropzone" should suffice.
811
884
  const globalHTMLProperties = assign(create(null), {
812
885
  accessKey: {
813
886
  attribute: 'accesskey',
@@ -1833,45 +1906,50 @@ function getReactiveProxy(value) {
1833
1906
  * for the Base Lightning Element, it also include the reactivity bit, so the standard property is reactive.
1834
1907
  */
1835
1908
  function createBridgeToElementDescriptor(propName, descriptor) {
1836
- const { get, set, enumerable, configurable } = descriptor;
1837
- if (!isFunction$1(get)) {
1838
- if (process.env.NODE_ENV !== 'production') {
1839
- assert.fail(`Detected invalid public property descriptor for HTMLElement.prototype.${propName} definition. Missing the standard getter.`);
1840
- }
1841
- throw new TypeError();
1909
+ const {
1910
+ get,
1911
+ set,
1912
+ enumerable,
1913
+ configurable
1914
+ } = descriptor;
1915
+ if (!isFunction$1(get)) {
1916
+ if (process.env.NODE_ENV !== 'production') {
1917
+ assert.fail(`Detected invalid public property descriptor for HTMLElement.prototype.${propName} definition. Missing the standard getter.`);
1918
+ }
1919
+ throw new TypeError();
1920
+ }
1921
+ if (!isFunction$1(set)) {
1922
+ if (process.env.NODE_ENV !== 'production') {
1923
+ assert.fail(`Detected invalid public property descriptor for HTMLElement.prototype.${propName} definition. Missing the standard setter.`);
1842
1924
  }
1843
- if (!isFunction$1(set)) {
1925
+ throw new TypeError();
1926
+ }
1927
+ return {
1928
+ enumerable,
1929
+ configurable,
1930
+ get() {
1931
+ const vm = getAssociatedVM(this);
1932
+ if (isBeingConstructed(vm)) {
1844
1933
  if (process.env.NODE_ENV !== 'production') {
1845
- assert.fail(`Detected invalid public property descriptor for HTMLElement.prototype.${propName} definition. Missing the standard setter.`);
1934
+ 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);
1846
1935
  }
1847
- throw new TypeError();
1936
+ return;
1937
+ }
1938
+ return get.call(vm.elm);
1939
+ },
1940
+ set(newValue) {
1941
+ const vm = getAssociatedVM(this);
1942
+ if (process.env.NODE_ENV !== 'production') {
1943
+ const vmBeingRendered = getVMBeingRendered();
1944
+ assert.invariant(!isInvokingRender, `${vmBeingRendered}.render() method has side effects on the state of ${vm}.${propName}`);
1945
+ 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}`);
1946
+ assert.isFalse(isBeingConstructed(vm), `Failed to construct '${getComponentTag(vm)}': The result must not have attributes.`);
1947
+ assert.invariant(!isObject(newValue) || isNull(newValue), `Invalid value "${newValue}" for "${propName}" of ${vm}. Value cannot be an object, must be a primitive value.`);
1948
+ }
1949
+ updateComponentValue(vm, propName, newValue);
1950
+ return set.call(vm.elm, newValue);
1848
1951
  }
1849
- return {
1850
- enumerable,
1851
- configurable,
1852
- get() {
1853
- const vm = getAssociatedVM(this);
1854
- if (isBeingConstructed(vm)) {
1855
- if (process.env.NODE_ENV !== 'production') {
1856
- 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);
1857
- }
1858
- return;
1859
- }
1860
- return get.call(vm.elm);
1861
- },
1862
- set(newValue) {
1863
- const vm = getAssociatedVM(this);
1864
- if (process.env.NODE_ENV !== 'production') {
1865
- const vmBeingRendered = getVMBeingRendered();
1866
- assert.invariant(!isInvokingRender, `${vmBeingRendered}.render() method has side effects on the state of ${vm}.${propName}`);
1867
- 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}`);
1868
- assert.isFalse(isBeingConstructed(vm), `Failed to construct '${getComponentTag(vm)}': The result must not have attributes.`);
1869
- assert.invariant(!isObject(newValue) || isNull(newValue), `Invalid value "${newValue}" for "${propName}" of ${vm}. Value cannot be an object, must be a primitive value.`);
1870
- }
1871
- updateComponentValue(vm, propName, newValue);
1872
- return set.call(vm.elm, newValue);
1873
- },
1874
- };
1952
+ };
1875
1953
  }
1876
1954
  const EMPTY_REFS = freeze(create(null));
1877
1955
  const refsCache = new WeakMap();
@@ -1881,344 +1959,443 @@ const refsCache = new WeakMap();
1881
1959
  **/
1882
1960
  // @ts-ignore
1883
1961
  const LightningElement = function () {
1884
- // This should be as performant as possible, while any initialization should be done lazily
1885
- if (isNull(vmBeingConstructed)) {
1886
- // Thrown when doing something like `new LightningElement()` or
1887
- // `class Foo extends LightningElement {}; new Foo()`
1888
- throw new TypeError('Illegal constructor');
1889
- }
1890
- const vm = vmBeingConstructed;
1891
- const { def, elm } = vm;
1892
- const { bridge } = def;
1962
+ // This should be as performant as possible, while any initialization should be done lazily
1963
+ if (isNull(vmBeingConstructed)) {
1964
+ // Thrown when doing something like `new LightningElement()` or
1965
+ // `class Foo extends LightningElement {}; new Foo()`
1966
+ throw new TypeError('Illegal constructor');
1967
+ }
1968
+ const vm = vmBeingConstructed;
1969
+ const {
1970
+ def,
1971
+ elm
1972
+ } = vm;
1973
+ const {
1974
+ bridge
1975
+ } = def;
1976
+ if (process.env.NODE_ENV !== 'production') {
1977
+ const {
1978
+ assertInstanceOfHTMLElement
1979
+ } = vm.renderer;
1980
+ assertInstanceOfHTMLElement(vm.elm, `Component creation requires a DOM element to be associated to ${vm}.`);
1981
+ }
1982
+ const component = this;
1983
+ setPrototypeOf(elm, bridge.prototype);
1984
+ vm.component = this;
1985
+ // Locker hooks assignment. When the LWC engine run with Locker, Locker intercepts all the new
1986
+ // component creation and passes hooks to instrument all the component interactions with the
1987
+ // engine. We are intentionally hiding this argument from the formal API of LightningElement
1988
+ // because we don't want folks to know about it just yet.
1989
+ if (arguments.length === 1) {
1990
+ const {
1991
+ callHook,
1992
+ setHook,
1993
+ getHook
1994
+ } = arguments[0];
1995
+ vm.callHook = callHook;
1996
+ vm.setHook = setHook;
1997
+ vm.getHook = getHook;
1998
+ }
1999
+ // Linking elm, shadow root and component with the VM.
2000
+ associateVM(component, vm);
2001
+ associateVM(elm, vm);
2002
+ if (vm.renderMode === 1 /* RenderMode.Shadow */) {
2003
+ vm.renderRoot = doAttachShadow(vm);
2004
+ } else {
2005
+ vm.renderRoot = elm;
2006
+ }
2007
+ // Adding extra guard rails in DEV mode.
2008
+ if (process.env.NODE_ENV !== 'production') {
2009
+ patchCustomElementWithRestrictions(elm);
2010
+ patchComponentWithRestrictions(component);
2011
+ }
2012
+ return this;
2013
+ };
2014
+ function doAttachShadow(vm) {
2015
+ const {
2016
+ elm,
2017
+ mode,
2018
+ shadowMode,
2019
+ def: {
2020
+ ctor
2021
+ },
2022
+ renderer: {
2023
+ attachShadow
2024
+ }
2025
+ } = vm;
2026
+ const shadowRoot = attachShadow(elm, {
2027
+ [KEY__SYNTHETIC_MODE]: shadowMode === 1 /* ShadowMode.Synthetic */,
2028
+ delegatesFocus: Boolean(ctor.delegatesFocus),
2029
+ mode
2030
+ });
2031
+ vm.shadowRoot = shadowRoot;
2032
+ associateVM(shadowRoot, vm);
2033
+ if (process.env.NODE_ENV !== 'production') {
2034
+ patchShadowRootWithRestrictions(shadowRoot);
2035
+ }
2036
+ return shadowRoot;
2037
+ }
2038
+ function warnIfInvokedDuringConstruction(vm, methodOrPropName) {
2039
+ if (isBeingConstructed(vm)) {
2040
+ 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.`);
2041
+ }
2042
+ }
2043
+ // @ts-ignore
2044
+ LightningElement.prototype = {
2045
+ constructor: LightningElement,
2046
+ dispatchEvent(event) {
2047
+ const vm = getAssociatedVM(this);
2048
+ const {
2049
+ elm,
2050
+ renderer: {
2051
+ dispatchEvent
2052
+ }
2053
+ } = vm;
2054
+ return dispatchEvent(elm, event);
2055
+ },
2056
+ addEventListener(type, listener, options) {
2057
+ const vm = getAssociatedVM(this);
2058
+ const {
2059
+ elm,
2060
+ renderer: {
2061
+ addEventListener
2062
+ }
2063
+ } = vm;
1893
2064
  if (process.env.NODE_ENV !== 'production') {
1894
- const { assertInstanceOfHTMLElement } = vm.renderer;
1895
- assertInstanceOfHTMLElement(vm.elm, `Component creation requires a DOM element to be associated to ${vm}.`);
1896
- }
1897
- const component = this;
1898
- setPrototypeOf(elm, bridge.prototype);
1899
- vm.component = this;
1900
- // Locker hooks assignment. When the LWC engine run with Locker, Locker intercepts all the new
1901
- // component creation and passes hooks to instrument all the component interactions with the
1902
- // engine. We are intentionally hiding this argument from the formal API of LightningElement
1903
- // because we don't want folks to know about it just yet.
1904
- if (arguments.length === 1) {
1905
- const { callHook, setHook, getHook } = arguments[0];
1906
- vm.callHook = callHook;
1907
- vm.setHook = setHook;
1908
- vm.getHook = getHook;
2065
+ const vmBeingRendered = getVMBeingRendered();
2066
+ assert.invariant(!isInvokingRender, `${vmBeingRendered}.render() method has side effects on the state of ${vm} by adding an event listener for "${type}".`);
2067
+ assert.invariant(!isUpdatingTemplate, `Updating the template of ${vmBeingRendered} has side effects on the state of ${vm} by adding an event listener for "${type}".`);
2068
+ assert.invariant(isFunction$1(listener), `Invalid second argument for this.addEventListener() in ${vm} for event "${type}". Expected an EventListener but received ${listener}.`);
2069
+ }
2070
+ const wrappedListener = getWrappedComponentsListener(vm, listener);
2071
+ addEventListener(elm, type, wrappedListener, options);
2072
+ },
2073
+ removeEventListener(type, listener, options) {
2074
+ const vm = getAssociatedVM(this);
2075
+ const {
2076
+ elm,
2077
+ renderer: {
2078
+ removeEventListener
2079
+ }
2080
+ } = vm;
2081
+ const wrappedListener = getWrappedComponentsListener(vm, listener);
2082
+ removeEventListener(elm, type, wrappedListener, options);
2083
+ },
2084
+ hasAttribute(name) {
2085
+ const vm = getAssociatedVM(this);
2086
+ const {
2087
+ elm,
2088
+ renderer: {
2089
+ getAttribute
2090
+ }
2091
+ } = vm;
2092
+ return !isNull(getAttribute(elm, name));
2093
+ },
2094
+ hasAttributeNS(namespace, name) {
2095
+ const vm = getAssociatedVM(this);
2096
+ const {
2097
+ elm,
2098
+ renderer: {
2099
+ getAttribute
2100
+ }
2101
+ } = vm;
2102
+ return !isNull(getAttribute(elm, name, namespace));
2103
+ },
2104
+ removeAttribute(name) {
2105
+ const vm = getAssociatedVM(this);
2106
+ const {
2107
+ elm,
2108
+ renderer: {
2109
+ removeAttribute
2110
+ }
2111
+ } = vm;
2112
+ unlockAttribute(elm, name);
2113
+ removeAttribute(elm, name);
2114
+ lockAttribute();
2115
+ },
2116
+ removeAttributeNS(namespace, name) {
2117
+ const {
2118
+ elm,
2119
+ renderer: {
2120
+ removeAttribute
2121
+ }
2122
+ } = getAssociatedVM(this);
2123
+ unlockAttribute(elm, name);
2124
+ removeAttribute(elm, name, namespace);
2125
+ lockAttribute();
2126
+ },
2127
+ getAttribute(name) {
2128
+ const vm = getAssociatedVM(this);
2129
+ const {
2130
+ elm
2131
+ } = vm;
2132
+ const {
2133
+ getAttribute
2134
+ } = vm.renderer;
2135
+ return getAttribute(elm, name);
2136
+ },
2137
+ getAttributeNS(namespace, name) {
2138
+ const vm = getAssociatedVM(this);
2139
+ const {
2140
+ elm
2141
+ } = vm;
2142
+ const {
2143
+ getAttribute
2144
+ } = vm.renderer;
2145
+ return getAttribute(elm, name, namespace);
2146
+ },
2147
+ setAttribute(name, value) {
2148
+ const vm = getAssociatedVM(this);
2149
+ const {
2150
+ elm,
2151
+ renderer: {
2152
+ setAttribute
2153
+ }
2154
+ } = vm;
2155
+ if (process.env.NODE_ENV !== 'production') {
2156
+ assert.isFalse(isBeingConstructed(vm), `Failed to construct '${getComponentTag(vm)}': The result must not have attributes.`);
2157
+ }
2158
+ unlockAttribute(elm, name);
2159
+ setAttribute(elm, name, value);
2160
+ lockAttribute();
2161
+ },
2162
+ setAttributeNS(namespace, name, value) {
2163
+ const vm = getAssociatedVM(this);
2164
+ const {
2165
+ elm,
2166
+ renderer: {
2167
+ setAttribute
2168
+ }
2169
+ } = vm;
2170
+ if (process.env.NODE_ENV !== 'production') {
2171
+ assert.isFalse(isBeingConstructed(vm), `Failed to construct '${getComponentTag(vm)}': The result must not have attributes.`);
2172
+ }
2173
+ unlockAttribute(elm, name);
2174
+ setAttribute(elm, name, value, namespace);
2175
+ lockAttribute();
2176
+ },
2177
+ getBoundingClientRect() {
2178
+ const vm = getAssociatedVM(this);
2179
+ const {
2180
+ elm,
2181
+ renderer: {
2182
+ getBoundingClientRect
2183
+ }
2184
+ } = vm;
2185
+ if (process.env.NODE_ENV !== 'production') {
2186
+ warnIfInvokedDuringConstruction(vm, 'getBoundingClientRect()');
1909
2187
  }
1910
- // Linking elm, shadow root and component with the VM.
1911
- associateVM(component, vm);
1912
- associateVM(elm, vm);
1913
- if (vm.renderMode === 1 /* RenderMode.Shadow */) {
1914
- vm.renderRoot = doAttachShadow(vm);
2188
+ return getBoundingClientRect(elm);
2189
+ },
2190
+ get isConnected() {
2191
+ const vm = getAssociatedVM(this);
2192
+ const {
2193
+ elm,
2194
+ renderer: {
2195
+ isConnected
2196
+ }
2197
+ } = vm;
2198
+ return isConnected(elm);
2199
+ },
2200
+ get classList() {
2201
+ const vm = getAssociatedVM(this);
2202
+ const {
2203
+ elm,
2204
+ renderer: {
2205
+ getClassList
2206
+ }
2207
+ } = vm;
2208
+ if (process.env.NODE_ENV !== 'production') {
2209
+ // TODO [#1290]: this still fails in dev but works in production, eventually, we should
2210
+ // just throw in all modes
2211
+ 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.`);
2212
+ }
2213
+ return getClassList(elm);
2214
+ },
2215
+ get template() {
2216
+ const vm = getAssociatedVM(this);
2217
+ if (process.env.NODE_ENV !== 'production') {
2218
+ if (vm.renderMode === 0 /* RenderMode.Light */) {
2219
+ 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`.');
2220
+ }
1915
2221
  }
1916
- else {
1917
- vm.renderRoot = elm;
2222
+ return vm.shadowRoot;
2223
+ },
2224
+ get refs() {
2225
+ const vm = getAssociatedVM(this);
2226
+ if (isUpdatingTemplate) {
2227
+ if (process.env.NODE_ENV !== 'production') {
2228
+ 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().`);
2229
+ }
2230
+ // If the template is in the process of being updated, then we don't want to go through the normal
2231
+ // process of returning the refs and caching them, because the state of the refs is unstable.
2232
+ // This can happen if e.g. a template contains `<div class={foo}></div>` and `foo` is computed
2233
+ // based on `this.refs.bar`.
2234
+ return;
1918
2235
  }
1919
- // Adding extra guard rails in DEV mode.
1920
2236
  if (process.env.NODE_ENV !== 'production') {
1921
- patchCustomElementWithRestrictions(elm);
1922
- patchComponentWithRestrictions(component);
2237
+ warnIfInvokedDuringConstruction(vm, 'refs');
1923
2238
  }
1924
- return this;
1925
- };
1926
- function doAttachShadow(vm) {
1927
- const { elm, mode, shadowMode, def: { ctor }, renderer: { attachShadow }, } = vm;
1928
- const shadowRoot = attachShadow(elm, {
1929
- [KEY__SYNTHETIC_MODE]: shadowMode === 1 /* ShadowMode.Synthetic */,
1930
- delegatesFocus: Boolean(ctor.delegatesFocus),
1931
- mode,
2239
+ const {
2240
+ refVNodes,
2241
+ hasRefVNodes,
2242
+ cmpTemplate
2243
+ } = vm;
2244
+ // If the `cmpTemplate` is null, that means that the template has not been rendered yet. Most likely this occurs
2245
+ // if `this.refs` is called during the `connectedCallback` phase. The DOM elements have not been rendered yet,
2246
+ // so log a warning. Note we also check `isBeingConstructed()` to avoid a double warning (due to
2247
+ // `warnIfInvokedDuringConstruction` above).
2248
+ if (process.env.NODE_ENV !== 'production' && isNull(cmpTemplate) && !isBeingConstructed(vm)) {
2249
+ 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().`);
2250
+ }
2251
+ // For backwards compatibility with component written before template refs
2252
+ // were introduced, we return undefined if the template has no refs defined
2253
+ // anywhere. This fixes components that may want to add an expando called `refs`
2254
+ // and are checking if it exists with `if (this.refs)` before adding it.
2255
+ // Note it is not sufficient to just check if `refVNodes` is null or empty,
2256
+ // because a template may have `lwc:ref` defined within a falsy `if:true` block.
2257
+ if (!hasRefVNodes) {
2258
+ return;
2259
+ }
2260
+ // For templates that are using `lwc:ref`, if there are no refs currently available
2261
+ // (e.g. refs inside of a falsy `if:true` block), we return an empty object.
2262
+ if (isNull(refVNodes)) {
2263
+ return EMPTY_REFS;
2264
+ }
2265
+ // The refNodes can be cached based on the refVNodes, since the refVNodes
2266
+ // are recreated from scratch every time the template is rendered.
2267
+ // This happens with `vm.refVNodes = null` in `template.ts` in `@lwc/engine-core`.
2268
+ let refs = refsCache.get(refVNodes);
2269
+ if (isUndefined$1(refs)) {
2270
+ refs = create(null);
2271
+ for (const key of keys(refVNodes)) {
2272
+ refs[key] = refVNodes[key].elm;
2273
+ }
2274
+ freeze(refs);
2275
+ refsCache.set(refVNodes, refs);
2276
+ }
2277
+ return refs;
2278
+ },
2279
+ // For backwards compat, we allow component authors to set `refs` as an expando
2280
+ set refs(value) {
2281
+ defineProperty(this, 'refs', {
2282
+ configurable: true,
2283
+ enumerable: true,
2284
+ writable: true,
2285
+ value
1932
2286
  });
1933
- vm.shadowRoot = shadowRoot;
1934
- associateVM(shadowRoot, vm);
2287
+ },
2288
+ get shadowRoot() {
2289
+ // From within the component instance, the shadowRoot is always reported as "closed".
2290
+ // Authors should rely on this.template instead.
2291
+ return null;
2292
+ },
2293
+ get children() {
2294
+ const vm = getAssociatedVM(this);
2295
+ const renderer = vm.renderer;
1935
2296
  if (process.env.NODE_ENV !== 'production') {
1936
- patchShadowRootWithRestrictions(shadowRoot);
2297
+ warnIfInvokedDuringConstruction(vm, 'children');
1937
2298
  }
1938
- return shadowRoot;
1939
- }
1940
- function warnIfInvokedDuringConstruction(vm, methodOrPropName) {
1941
- if (isBeingConstructed(vm)) {
1942
- 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.`);
2299
+ return renderer.getChildren(vm.elm);
2300
+ },
2301
+ get childNodes() {
2302
+ const vm = getAssociatedVM(this);
2303
+ const renderer = vm.renderer;
2304
+ if (process.env.NODE_ENV !== 'production') {
2305
+ warnIfInvokedDuringConstruction(vm, 'childNodes');
1943
2306
  }
1944
- }
1945
- // @ts-ignore
1946
- LightningElement.prototype = {
1947
- constructor: LightningElement,
1948
- dispatchEvent(event) {
1949
- const vm = getAssociatedVM(this);
1950
- const { elm, renderer: { dispatchEvent }, } = vm;
1951
- return dispatchEvent(elm, event);
1952
- },
1953
- addEventListener(type, listener, options) {
1954
- const vm = getAssociatedVM(this);
1955
- const { elm, renderer: { addEventListener }, } = vm;
1956
- if (process.env.NODE_ENV !== 'production') {
1957
- const vmBeingRendered = getVMBeingRendered();
1958
- assert.invariant(!isInvokingRender, `${vmBeingRendered}.render() method has side effects on the state of ${vm} by adding an event listener for "${type}".`);
1959
- assert.invariant(!isUpdatingTemplate, `Updating the template of ${vmBeingRendered} has side effects on the state of ${vm} by adding an event listener for "${type}".`);
1960
- assert.invariant(isFunction$1(listener), `Invalid second argument for this.addEventListener() in ${vm} for event "${type}". Expected an EventListener but received ${listener}.`);
1961
- }
1962
- const wrappedListener = getWrappedComponentsListener(vm, listener);
1963
- addEventListener(elm, type, wrappedListener, options);
1964
- },
1965
- removeEventListener(type, listener, options) {
1966
- const vm = getAssociatedVM(this);
1967
- const { elm, renderer: { removeEventListener }, } = vm;
1968
- const wrappedListener = getWrappedComponentsListener(vm, listener);
1969
- removeEventListener(elm, type, wrappedListener, options);
1970
- },
1971
- hasAttribute(name) {
1972
- const vm = getAssociatedVM(this);
1973
- const { elm, renderer: { getAttribute }, } = vm;
1974
- return !isNull(getAttribute(elm, name));
1975
- },
1976
- hasAttributeNS(namespace, name) {
1977
- const vm = getAssociatedVM(this);
1978
- const { elm, renderer: { getAttribute }, } = vm;
1979
- return !isNull(getAttribute(elm, name, namespace));
1980
- },
1981
- removeAttribute(name) {
1982
- const vm = getAssociatedVM(this);
1983
- const { elm, renderer: { removeAttribute }, } = vm;
1984
- unlockAttribute(elm, name);
1985
- removeAttribute(elm, name);
1986
- lockAttribute();
1987
- },
1988
- removeAttributeNS(namespace, name) {
1989
- const { elm, renderer: { removeAttribute }, } = getAssociatedVM(this);
1990
- unlockAttribute(elm, name);
1991
- removeAttribute(elm, name, namespace);
1992
- lockAttribute();
1993
- },
1994
- getAttribute(name) {
1995
- const vm = getAssociatedVM(this);
1996
- const { elm } = vm;
1997
- const { getAttribute } = vm.renderer;
1998
- return getAttribute(elm, name);
1999
- },
2000
- getAttributeNS(namespace, name) {
2001
- const vm = getAssociatedVM(this);
2002
- const { elm } = vm;
2003
- const { getAttribute } = vm.renderer;
2004
- return getAttribute(elm, name, namespace);
2005
- },
2006
- setAttribute(name, value) {
2007
- const vm = getAssociatedVM(this);
2008
- const { elm, renderer: { setAttribute }, } = vm;
2009
- if (process.env.NODE_ENV !== 'production') {
2010
- assert.isFalse(isBeingConstructed(vm), `Failed to construct '${getComponentTag(vm)}': The result must not have attributes.`);
2011
- }
2012
- unlockAttribute(elm, name);
2013
- setAttribute(elm, name, value);
2014
- lockAttribute();
2015
- },
2016
- setAttributeNS(namespace, name, value) {
2017
- const vm = getAssociatedVM(this);
2018
- const { elm, renderer: { setAttribute }, } = vm;
2019
- if (process.env.NODE_ENV !== 'production') {
2020
- assert.isFalse(isBeingConstructed(vm), `Failed to construct '${getComponentTag(vm)}': The result must not have attributes.`);
2021
- }
2022
- unlockAttribute(elm, name);
2023
- setAttribute(elm, name, value, namespace);
2024
- lockAttribute();
2025
- },
2026
- getBoundingClientRect() {
2027
- const vm = getAssociatedVM(this);
2028
- const { elm, renderer: { getBoundingClientRect }, } = vm;
2029
- if (process.env.NODE_ENV !== 'production') {
2030
- warnIfInvokedDuringConstruction(vm, 'getBoundingClientRect()');
2031
- }
2032
- return getBoundingClientRect(elm);
2033
- },
2034
- get isConnected() {
2035
- const vm = getAssociatedVM(this);
2036
- const { elm, renderer: { isConnected }, } = vm;
2037
- return isConnected(elm);
2038
- },
2039
- get classList() {
2040
- const vm = getAssociatedVM(this);
2041
- const { elm, renderer: { getClassList }, } = vm;
2042
- if (process.env.NODE_ENV !== 'production') {
2043
- // TODO [#1290]: this still fails in dev but works in production, eventually, we should
2044
- // just throw in all modes
2045
- 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.`);
2046
- }
2047
- return getClassList(elm);
2048
- },
2049
- get template() {
2050
- const vm = getAssociatedVM(this);
2051
- if (process.env.NODE_ENV !== 'production') {
2052
- if (vm.renderMode === 0 /* RenderMode.Light */) {
2053
- 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`.');
2054
- }
2055
- }
2056
- return vm.shadowRoot;
2057
- },
2058
- get refs() {
2059
- const vm = getAssociatedVM(this);
2060
- if (isUpdatingTemplate) {
2061
- if (process.env.NODE_ENV !== 'production') {
2062
- 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().`);
2063
- }
2064
- // If the template is in the process of being updated, then we don't want to go through the normal
2065
- // process of returning the refs and caching them, because the state of the refs is unstable.
2066
- // This can happen if e.g. a template contains `<div class={foo}></div>` and `foo` is computed
2067
- // based on `this.refs.bar`.
2068
- return;
2069
- }
2070
- if (process.env.NODE_ENV !== 'production') {
2071
- warnIfInvokedDuringConstruction(vm, 'refs');
2072
- }
2073
- const { refVNodes, hasRefVNodes, cmpTemplate } = vm;
2074
- // If the `cmpTemplate` is null, that means that the template has not been rendered yet. Most likely this occurs
2075
- // if `this.refs` is called during the `connectedCallback` phase. The DOM elements have not been rendered yet,
2076
- // so log a warning. Note we also check `isBeingConstructed()` to avoid a double warning (due to
2077
- // `warnIfInvokedDuringConstruction` above).
2078
- if (process.env.NODE_ENV !== 'production' &&
2079
- isNull(cmpTemplate) &&
2080
- !isBeingConstructed(vm)) {
2081
- logError(`this.refs is undefined for ${getComponentTag(vm)}. This is either because the attached template has no "lwc:ref" directive, or this.refs was ` +
2082
- `invoked before renderedCallback(). Use this.refs only when the referenced HTML elements have ` +
2083
- `been rendered to the DOM, such as within renderedCallback() or disconnectedCallback().`);
2084
- }
2085
- // For backwards compatibility with component written before template refs
2086
- // were introduced, we return undefined if the template has no refs defined
2087
- // anywhere. This fixes components that may want to add an expando called `refs`
2088
- // and are checking if it exists with `if (this.refs)` before adding it.
2089
- // Note it is not sufficient to just check if `refVNodes` is null or empty,
2090
- // because a template may have `lwc:ref` defined within a falsy `if:true` block.
2091
- if (!hasRefVNodes) {
2092
- return;
2093
- }
2094
- // For templates that are using `lwc:ref`, if there are no refs currently available
2095
- // (e.g. refs inside of a falsy `if:true` block), we return an empty object.
2096
- if (isNull(refVNodes)) {
2097
- return EMPTY_REFS;
2098
- }
2099
- // The refNodes can be cached based on the refVNodes, since the refVNodes
2100
- // are recreated from scratch every time the template is rendered.
2101
- // This happens with `vm.refVNodes = null` in `template.ts` in `@lwc/engine-core`.
2102
- let refs = refsCache.get(refVNodes);
2103
- if (isUndefined$1(refs)) {
2104
- refs = create(null);
2105
- for (const key of keys(refVNodes)) {
2106
- refs[key] = refVNodes[key].elm;
2107
- }
2108
- freeze(refs);
2109
- refsCache.set(refVNodes, refs);
2110
- }
2111
- return refs;
2112
- },
2113
- // For backwards compat, we allow component authors to set `refs` as an expando
2114
- set refs(value) {
2115
- defineProperty(this, 'refs', {
2116
- configurable: true,
2117
- enumerable: true,
2118
- writable: true,
2119
- value,
2120
- });
2121
- },
2122
- get shadowRoot() {
2123
- // From within the component instance, the shadowRoot is always reported as "closed".
2124
- // Authors should rely on this.template instead.
2125
- return null;
2126
- },
2127
- get children() {
2128
- const vm = getAssociatedVM(this);
2129
- const renderer = vm.renderer;
2130
- if (process.env.NODE_ENV !== 'production') {
2131
- warnIfInvokedDuringConstruction(vm, 'children');
2132
- }
2133
- return renderer.getChildren(vm.elm);
2134
- },
2135
- get childNodes() {
2136
- const vm = getAssociatedVM(this);
2137
- const renderer = vm.renderer;
2138
- if (process.env.NODE_ENV !== 'production') {
2139
- warnIfInvokedDuringConstruction(vm, 'childNodes');
2140
- }
2141
- return renderer.getChildNodes(vm.elm);
2142
- },
2143
- get firstChild() {
2144
- const vm = getAssociatedVM(this);
2145
- const renderer = vm.renderer;
2146
- if (process.env.NODE_ENV !== 'production') {
2147
- warnIfInvokedDuringConstruction(vm, 'firstChild');
2148
- }
2149
- return renderer.getFirstChild(vm.elm);
2150
- },
2151
- get firstElementChild() {
2152
- const vm = getAssociatedVM(this);
2153
- const renderer = vm.renderer;
2154
- if (process.env.NODE_ENV !== 'production') {
2155
- warnIfInvokedDuringConstruction(vm, 'firstElementChild');
2156
- }
2157
- return renderer.getFirstElementChild(vm.elm);
2158
- },
2159
- get lastChild() {
2160
- const vm = getAssociatedVM(this);
2161
- const renderer = vm.renderer;
2162
- if (process.env.NODE_ENV !== 'production') {
2163
- warnIfInvokedDuringConstruction(vm, 'lastChild');
2164
- }
2165
- return renderer.getLastChild(vm.elm);
2166
- },
2167
- get lastElementChild() {
2168
- const vm = getAssociatedVM(this);
2169
- const renderer = vm.renderer;
2170
- if (process.env.NODE_ENV !== 'production') {
2171
- warnIfInvokedDuringConstruction(vm, 'lastElementChild');
2172
- }
2173
- return renderer.getLastElementChild(vm.elm);
2174
- },
2175
- render() {
2176
- const vm = getAssociatedVM(this);
2177
- return vm.def.template;
2178
- },
2179
- toString() {
2180
- const vm = getAssociatedVM(this);
2181
- return `[object ${vm.def.name}]`;
2182
- },
2307
+ return renderer.getChildNodes(vm.elm);
2308
+ },
2309
+ get firstChild() {
2310
+ const vm = getAssociatedVM(this);
2311
+ const renderer = vm.renderer;
2312
+ if (process.env.NODE_ENV !== 'production') {
2313
+ warnIfInvokedDuringConstruction(vm, 'firstChild');
2314
+ }
2315
+ return renderer.getFirstChild(vm.elm);
2316
+ },
2317
+ get firstElementChild() {
2318
+ const vm = getAssociatedVM(this);
2319
+ const renderer = vm.renderer;
2320
+ if (process.env.NODE_ENV !== 'production') {
2321
+ warnIfInvokedDuringConstruction(vm, 'firstElementChild');
2322
+ }
2323
+ return renderer.getFirstElementChild(vm.elm);
2324
+ },
2325
+ get lastChild() {
2326
+ const vm = getAssociatedVM(this);
2327
+ const renderer = vm.renderer;
2328
+ if (process.env.NODE_ENV !== 'production') {
2329
+ warnIfInvokedDuringConstruction(vm, 'lastChild');
2330
+ }
2331
+ return renderer.getLastChild(vm.elm);
2332
+ },
2333
+ get lastElementChild() {
2334
+ const vm = getAssociatedVM(this);
2335
+ const renderer = vm.renderer;
2336
+ if (process.env.NODE_ENV !== 'production') {
2337
+ warnIfInvokedDuringConstruction(vm, 'lastElementChild');
2338
+ }
2339
+ return renderer.getLastElementChild(vm.elm);
2340
+ },
2341
+ render() {
2342
+ const vm = getAssociatedVM(this);
2343
+ return vm.def.template;
2344
+ },
2345
+ toString() {
2346
+ const vm = getAssociatedVM(this);
2347
+ return `[object ${vm.def.name}]`;
2348
+ }
2183
2349
  };
2184
2350
  const queryAndChildGetterDescriptors = create(null);
2185
- const queryMethods = [
2186
- 'getElementsByClassName',
2187
- 'getElementsByTagName',
2188
- 'querySelector',
2189
- 'querySelectorAll',
2190
- ];
2351
+ const queryMethods = ['getElementsByClassName', 'getElementsByTagName', 'querySelector', 'querySelectorAll'];
2191
2352
  // Generic passthrough for query APIs on HTMLElement to the relevant Renderer APIs
2192
2353
  for (const queryMethod of queryMethods) {
2193
- queryAndChildGetterDescriptors[queryMethod] = {
2194
- value(arg) {
2195
- const vm = getAssociatedVM(this);
2196
- const { elm, renderer } = vm;
2197
- if (process.env.NODE_ENV !== 'production') {
2198
- warnIfInvokedDuringConstruction(vm, `${queryMethod}()`);
2199
- }
2200
- return renderer[queryMethod](elm, arg);
2201
- },
2202
- configurable: true,
2203
- enumerable: true,
2204
- writable: true,
2205
- };
2354
+ queryAndChildGetterDescriptors[queryMethod] = {
2355
+ value(arg) {
2356
+ const vm = getAssociatedVM(this);
2357
+ const {
2358
+ elm,
2359
+ renderer
2360
+ } = vm;
2361
+ if (process.env.NODE_ENV !== 'production') {
2362
+ warnIfInvokedDuringConstruction(vm, `${queryMethod}()`);
2363
+ }
2364
+ return renderer[queryMethod](elm, arg);
2365
+ },
2366
+ configurable: true,
2367
+ enumerable: true,
2368
+ writable: true
2369
+ };
2206
2370
  }
2207
2371
  defineProperties(LightningElement.prototype, queryAndChildGetterDescriptors);
2208
2372
  const lightningBasedDescriptors = create(null);
2209
2373
  for (const propName in HTMLElementOriginalDescriptors) {
2210
- lightningBasedDescriptors[propName] = createBridgeToElementDescriptor(propName, HTMLElementOriginalDescriptors[propName]);
2374
+ lightningBasedDescriptors[propName] = createBridgeToElementDescriptor(propName, HTMLElementOriginalDescriptors[propName]);
2211
2375
  }
2212
2376
  defineProperties(LightningElement.prototype, lightningBasedDescriptors);
2377
+ function applyAriaReflectionToLightningElement() {
2378
+ // If ARIA reflection is not applied globally to Element.prototype, or if we are running server-side,
2379
+ // apply it to LightningElement.prototype.
2380
+ // This allows `this.aria*` property accessors to work from inside a component, and to reflect `aria-*` attrs.
2381
+ applyAriaReflection(LightningElement.prototype);
2382
+ }
2383
+ // The reason for this odd if/else branching is limitations in @lwc/features:
2384
+ // https://github.com/salesforce/lwc/blob/master/packages/%40lwc/features/README.md#only-works-with-if-statements
2385
+ if (lwcRuntimeFlags.DISABLE_ARIA_REFLECTION_POLYFILL) {
2386
+ applyAriaReflectionToLightningElement();
2387
+ } else {
2388
+ applyAriaReflectionToLightningElement();
2389
+ }
2213
2390
  defineProperty(LightningElement, 'CustomElementConstructor', {
2214
- get() {
2215
- // If required, a runtime-specific implementation must be defined.
2216
- throw new ReferenceError('The current runtime does not support CustomElementConstructor.');
2217
- },
2218
- configurable: true,
2391
+ get() {
2392
+ // If required, a runtime-specific implementation must be defined.
2393
+ throw new ReferenceError('The current runtime does not support CustomElementConstructor.');
2394
+ },
2395
+ configurable: true
2219
2396
  });
2220
2397
  if (process.env.NODE_ENV !== 'production') {
2221
- patchLightningElementPrototypeWithRestrictions(LightningElement.prototype);
2398
+ patchLightningElementPrototypeWithRestrictions(LightningElement.prototype);
2222
2399
  }
2223
2400
 
2224
2401
  function createObservedFieldPropertyDescriptor(key) {
@@ -2673,136 +2850,145 @@ function sanitizeAttribute(tagName, namespaceUri, attrName, attrValue) {
2673
2850
  const cachedGetterByKey = create(null);
2674
2851
  const cachedSetterByKey = create(null);
2675
2852
  function createGetter(key) {
2676
- let fn = cachedGetterByKey[key];
2677
- if (isUndefined$1(fn)) {
2678
- fn = cachedGetterByKey[key] = function () {
2679
- const vm = getAssociatedVM(this);
2680
- const { getHook } = vm;
2681
- return getHook(vm.component, key);
2682
- };
2683
- }
2684
- return fn;
2853
+ let fn = cachedGetterByKey[key];
2854
+ if (isUndefined$1(fn)) {
2855
+ fn = cachedGetterByKey[key] = function () {
2856
+ const vm = getAssociatedVM(this);
2857
+ const {
2858
+ getHook
2859
+ } = vm;
2860
+ return getHook(vm.component, key);
2861
+ };
2862
+ }
2863
+ return fn;
2685
2864
  }
2686
2865
  function createSetter(key) {
2687
- let fn = cachedSetterByKey[key];
2688
- if (isUndefined$1(fn)) {
2689
- fn = cachedSetterByKey[key] = function (newValue) {
2690
- const vm = getAssociatedVM(this);
2691
- const { setHook } = vm;
2692
- newValue = getReadOnlyProxy(newValue);
2693
- setHook(vm.component, key, newValue);
2694
- };
2695
- }
2696
- return fn;
2866
+ let fn = cachedSetterByKey[key];
2867
+ if (isUndefined$1(fn)) {
2868
+ fn = cachedSetterByKey[key] = function (newValue) {
2869
+ const vm = getAssociatedVM(this);
2870
+ const {
2871
+ setHook
2872
+ } = vm;
2873
+ newValue = getReadOnlyProxy(newValue);
2874
+ setHook(vm.component, key, newValue);
2875
+ };
2876
+ }
2877
+ return fn;
2697
2878
  }
2698
2879
  function createMethodCaller(methodName) {
2699
- return function () {
2700
- const vm = getAssociatedVM(this);
2701
- const { callHook, component } = vm;
2702
- const fn = component[methodName];
2703
- return callHook(vm.component, fn, ArraySlice.call(arguments));
2704
- };
2880
+ return function () {
2881
+ const vm = getAssociatedVM(this);
2882
+ const {
2883
+ callHook,
2884
+ component
2885
+ } = vm;
2886
+ const fn = component[methodName];
2887
+ return callHook(vm.component, fn, ArraySlice.call(arguments));
2888
+ };
2705
2889
  }
2706
2890
  function createAttributeChangedCallback(attributeToPropMap, superAttributeChangedCallback) {
2707
- return function attributeChangedCallback(attrName, oldValue, newValue) {
2708
- if (oldValue === newValue) {
2709
- // Ignore same values.
2710
- return;
2711
- }
2712
- const propName = attributeToPropMap[attrName];
2713
- if (isUndefined$1(propName)) {
2714
- if (!isUndefined$1(superAttributeChangedCallback)) {
2715
- // delegate unknown attributes to the super.
2716
- // Typescript does not like it when you treat the `arguments` object as an array
2717
- // @ts-ignore type-mismatch
2718
- superAttributeChangedCallback.apply(this, arguments);
2719
- }
2720
- return;
2721
- }
2722
- if (!isAttributeLocked(this, attrName)) {
2723
- // Ignore changes triggered by the engine itself during:
2724
- // * diffing when public props are attempting to reflect to the DOM
2725
- // * component via `this.setAttribute()`, should never update the prop
2726
- // Both cases, the setAttribute call is always wrapped by the unlocking of the
2727
- // attribute to be changed
2728
- return;
2729
- }
2730
- // Reflect attribute change to the corresponding property when changed from outside.
2731
- this[propName] = newValue;
2732
- };
2733
- }
2734
- function HTMLBridgeElementFactory(SuperClass, props, methods) {
2735
- let HTMLBridgeElement;
2736
- /**
2737
- * Modern browsers will have all Native Constructors as regular Classes
2738
- * and must be instantiated with the new keyword. In older browsers,
2739
- * specifically IE11, those are objects with a prototype property defined,
2740
- * since they are not supposed to be extended or instantiated with the
2741
- * new keyword. This forking logic supports both cases, specifically because
2742
- * wc.ts relies on the construction path of the bridges to create new
2743
- * fully qualifying web components.
2744
- */
2745
- if (isFunction$1(SuperClass)) {
2746
- HTMLBridgeElement = class extends SuperClass {
2747
- };
2748
- }
2749
- else {
2750
- HTMLBridgeElement = function () {
2751
- // Bridge classes are not supposed to be instantiated directly in
2752
- // browsers that do not support web components.
2753
- throw new TypeError('Illegal constructor');
2754
- };
2755
- // prototype inheritance dance
2756
- setPrototypeOf(HTMLBridgeElement, SuperClass);
2757
- setPrototypeOf(HTMLBridgeElement.prototype, SuperClass.prototype);
2758
- defineProperty(HTMLBridgeElement.prototype, 'constructor', {
2759
- writable: true,
2760
- configurable: true,
2761
- value: HTMLBridgeElement,
2762
- });
2891
+ return function attributeChangedCallback(attrName, oldValue, newValue) {
2892
+ if (oldValue === newValue) {
2893
+ // Ignore same values.
2894
+ return;
2763
2895
  }
2764
- // generating the hash table for attributes to avoid duplicate fields and facilitate validation
2765
- // and false positives in case of inheritance.
2766
- const attributeToPropMap = create(null);
2767
- const { attributeChangedCallback: superAttributeChangedCallback } = SuperClass.prototype;
2768
- const { observedAttributes: superObservedAttributes = [] } = SuperClass;
2769
- const descriptors = create(null);
2770
- // expose getters and setters for each public props on the new Element Bridge
2771
- for (let i = 0, len = props.length; i < len; i += 1) {
2772
- const propName = props[i];
2773
- attributeToPropMap[htmlPropertyToAttribute(propName)] = propName;
2774
- descriptors[propName] = {
2775
- get: createGetter(propName),
2776
- set: createSetter(propName),
2777
- enumerable: true,
2778
- configurable: true,
2779
- };
2896
+ const propName = attributeToPropMap[attrName];
2897
+ if (isUndefined$1(propName)) {
2898
+ if (!isUndefined$1(superAttributeChangedCallback)) {
2899
+ // delegate unknown attributes to the super.
2900
+ // Typescript does not like it when you treat the `arguments` object as an array
2901
+ // @ts-ignore type-mismatch
2902
+ superAttributeChangedCallback.apply(this, arguments);
2903
+ }
2904
+ return;
2780
2905
  }
2781
- // expose public methods as props on the new Element Bridge
2782
- for (let i = 0, len = methods.length; i < len; i += 1) {
2783
- const methodName = methods[i];
2784
- descriptors[methodName] = {
2785
- value: createMethodCaller(methodName),
2786
- writable: true,
2787
- configurable: true,
2788
- };
2906
+ if (!isAttributeLocked(this, attrName)) {
2907
+ // Ignore changes triggered by the engine itself during:
2908
+ // * diffing when public props are attempting to reflect to the DOM
2909
+ // * component via `this.setAttribute()`, should never update the prop
2910
+ // Both cases, the setAttribute call is always wrapped by the unlocking of the
2911
+ // attribute to be changed
2912
+ return;
2789
2913
  }
2790
- // creating a new attributeChangedCallback per bridge because they are bound to the corresponding
2791
- // map of attributes to props. We do this after all other props and methods to avoid the possibility
2792
- // of getting overrule by a class declaration in user-land, and we make it non-writable, non-configurable
2793
- // to preserve this definition.
2794
- descriptors.attributeChangedCallback = {
2795
- value: createAttributeChangedCallback(attributeToPropMap, superAttributeChangedCallback),
2914
+ // Reflect attribute change to the corresponding property when changed from outside.
2915
+ this[propName] = newValue;
2916
+ };
2917
+ }
2918
+ function HTMLBridgeElementFactory(SuperClass, props, methods) {
2919
+ let HTMLBridgeElement;
2920
+ /**
2921
+ * Modern browsers will have all Native Constructors as regular Classes
2922
+ * and must be instantiated with the new keyword. In older browsers,
2923
+ * specifically IE11, those are objects with a prototype property defined,
2924
+ * since they are not supposed to be extended or instantiated with the
2925
+ * new keyword. This forking logic supports both cases, specifically because
2926
+ * wc.ts relies on the construction path of the bridges to create new
2927
+ * fully qualifying web components.
2928
+ */
2929
+ if (isFunction$1(SuperClass)) {
2930
+ HTMLBridgeElement = class extends SuperClass {};
2931
+ } else {
2932
+ HTMLBridgeElement = function () {
2933
+ // Bridge classes are not supposed to be instantiated directly in
2934
+ // browsers that do not support web components.
2935
+ throw new TypeError('Illegal constructor');
2796
2936
  };
2797
- // Specify attributes for which we want to reflect changes back to their corresponding
2798
- // properties via attributeChangedCallback.
2799
- defineProperty(HTMLBridgeElement, 'observedAttributes', {
2800
- get() {
2801
- return [...superObservedAttributes, ...keys(attributeToPropMap)];
2802
- },
2937
+ // prototype inheritance dance
2938
+ setPrototypeOf(HTMLBridgeElement, SuperClass);
2939
+ setPrototypeOf(HTMLBridgeElement.prototype, SuperClass.prototype);
2940
+ defineProperty(HTMLBridgeElement.prototype, 'constructor', {
2941
+ writable: true,
2942
+ configurable: true,
2943
+ value: HTMLBridgeElement
2803
2944
  });
2804
- defineProperties(HTMLBridgeElement.prototype, descriptors);
2805
- return HTMLBridgeElement;
2945
+ }
2946
+ // generating the hash table for attributes to avoid duplicate fields and facilitate validation
2947
+ // and false positives in case of inheritance.
2948
+ const attributeToPropMap = create(null);
2949
+ const {
2950
+ attributeChangedCallback: superAttributeChangedCallback
2951
+ } = SuperClass.prototype;
2952
+ const {
2953
+ observedAttributes: superObservedAttributes = []
2954
+ } = SuperClass;
2955
+ const descriptors = create(null);
2956
+ // expose getters and setters for each public props on the new Element Bridge
2957
+ for (let i = 0, len = props.length; i < len; i += 1) {
2958
+ const propName = props[i];
2959
+ attributeToPropMap[htmlPropertyToAttribute(propName)] = propName;
2960
+ descriptors[propName] = {
2961
+ get: createGetter(propName),
2962
+ set: createSetter(propName),
2963
+ enumerable: true,
2964
+ configurable: true
2965
+ };
2966
+ }
2967
+ // expose public methods as props on the new Element Bridge
2968
+ for (let i = 0, len = methods.length; i < len; i += 1) {
2969
+ const methodName = methods[i];
2970
+ descriptors[methodName] = {
2971
+ value: createMethodCaller(methodName),
2972
+ writable: true,
2973
+ configurable: true
2974
+ };
2975
+ }
2976
+ // creating a new attributeChangedCallback per bridge because they are bound to the corresponding
2977
+ // map of attributes to props. We do this after all other props and methods to avoid the possibility
2978
+ // of getting overrule by a class declaration in user-land, and we make it non-writable, non-configurable
2979
+ // to preserve this definition.
2980
+ descriptors.attributeChangedCallback = {
2981
+ value: createAttributeChangedCallback(attributeToPropMap, superAttributeChangedCallback)
2982
+ };
2983
+ // Specify attributes for which we want to reflect changes back to their corresponding
2984
+ // properties via attributeChangedCallback.
2985
+ defineProperty(HTMLBridgeElement, 'observedAttributes', {
2986
+ get() {
2987
+ return [...superObservedAttributes, ...keys(attributeToPropMap)];
2988
+ }
2989
+ });
2990
+ defineProperties(HTMLBridgeElement.prototype, descriptors);
2991
+ return HTMLBridgeElement;
2806
2992
  }
2807
2993
  const BaseBridgeElement = HTMLBridgeElementFactory(HTMLElementConstructor, getOwnPropertyNames$1(HTMLElementOriginalDescriptors), []);
2808
2994
  freeze(BaseBridgeElement);
@@ -3163,6 +3349,9 @@ function updateStylesheetToken(vm, template) {
3163
3349
  stylesheets: newStylesheets,
3164
3350
  stylesheetToken: newStylesheetToken
3165
3351
  } = template;
3352
+ const {
3353
+ stylesheets: newVmStylesheets
3354
+ } = vm;
3166
3355
  const isSyntheticShadow = renderMode === 1 /* RenderMode.Shadow */ && shadowMode === 1 /* ShadowMode.Synthetic */;
3167
3356
  const {
3168
3357
  hasScopedStyles
@@ -3186,7 +3375,9 @@ function updateStylesheetToken(vm, template) {
3186
3375
  }
3187
3376
  // Apply the new template styling token to the host element, if the new template has any
3188
3377
  // associated stylesheets. In the case of light DOM, also ensure there is at least one scoped stylesheet.
3189
- if (!isUndefined$1(newStylesheets) && newStylesheets.length !== 0) {
3378
+ const hasNewStylesheets = hasStyles(newStylesheets);
3379
+ const hasNewVmStylesheets = hasStyles(newVmStylesheets);
3380
+ if (hasNewStylesheets || hasNewVmStylesheets) {
3190
3381
  newToken = newStylesheetToken;
3191
3382
  }
3192
3383
  // Set the new styling token on the host element
@@ -3258,10 +3449,17 @@ function getStylesheetsContent(vm, template) {
3258
3449
  stylesheets,
3259
3450
  stylesheetToken
3260
3451
  } = template;
3452
+ const {
3453
+ stylesheets: vmStylesheets
3454
+ } = vm;
3261
3455
  let content = [];
3262
- if (!isUndefined$1(stylesheets) && stylesheets.length !== 0) {
3456
+ if (hasStyles(stylesheets)) {
3263
3457
  content = evaluateStylesheetsContent(stylesheets, stylesheetToken, vm);
3264
3458
  }
3459
+ // VM (component) stylesheets apply after template stylesheets
3460
+ if (hasStyles(vmStylesheets)) {
3461
+ ArrayPush$1.apply(content, evaluateStylesheetsContent(vmStylesheets, stylesheetToken, vm));
3462
+ }
3265
3463
  return content;
3266
3464
  }
3267
3465
  // It might be worth caching this to avoid doing the lookup repeatedly, but
@@ -3867,6 +4065,28 @@ function patchCustomElement(n1, n2, parent, renderer) {
3867
4065
  // in fallback mode, the allocation will always set children to
3868
4066
  // empty and delegate the real allocation to the slot elements
3869
4067
  allocateChildren(n2, vm);
4068
+ // Solves an edge case with slotted VFragments in native shadow mode.
4069
+ //
4070
+ // During allocation, in native shadow, slotted VFragment nodes are flattened and their text delimiters are removed
4071
+ // to avoid interfering with native slot behavior. When this happens, if any of the fragments
4072
+ // were not stable, the children must go through the dynamic diffing algo.
4073
+ //
4074
+ // If the new children (n2.children) contain no VFragments, but the previous children (n1.children) were dynamic,
4075
+ // the new nodes must be marked dynamic so that all nodes are properly updated. The only indicator that the new
4076
+ // nodes need to be dynamic comes from the previous children, so we check that to determine whether we need to
4077
+ // mark the new children dynamic.
4078
+ //
4079
+ // Example:
4080
+ // n1.children: [div, VFragment('', div, null, ''), div] => [div, div, null, div]; // marked dynamic
4081
+ // n2.children: [div, null, div] => [div, null, div] // marked ???
4082
+ const {
4083
+ shadowMode,
4084
+ renderMode
4085
+ } = vm;
4086
+ if (shadowMode == 0 /* ShadowMode.Native */ && renderMode !== 0 /* RenderMode.Light */ && hasDynamicChildren(n1.children)) {
4087
+ // No-op if children has already been marked dynamic by 'allocateChildren()'.
4088
+ markAsDynamicChildren(n2.children);
4089
+ }
3870
4090
  }
3871
4091
  // in fallback mode, the children will be always empty, so, nothing
3872
4092
  // will happen, but in native, it does allocate the light dom
@@ -4059,7 +4279,6 @@ function allocateChildren(vnode, vm) {
4059
4279
  //
4060
4280
  // In case #2, we will always get a fresh VCustomElement.
4061
4281
  const children = vnode.aChildren || vnode.children;
4062
- vm.aChildren = children;
4063
4282
  const {
4064
4283
  renderMode,
4065
4284
  shadowMode
@@ -4072,15 +4291,61 @@ function allocateChildren(vnode, vm) {
4072
4291
  logError(`Invalid usage of 'lwc:slot-data' on ${getComponentTag(vm)} tag. Scoped slot content can only be passed to a light dom child.`);
4073
4292
  }
4074
4293
  }
4294
+ // If any of the children being allocated are VFragments, we remove the text delimiters and flatten all immediate
4295
+ // children VFragments to avoid them interfering with default slot behavior.
4296
+ const allocatedChildren = flattenFragmentsInChildren(children);
4297
+ vnode.children = allocatedChildren;
4298
+ vm.aChildren = allocatedChildren;
4075
4299
  if (shadowMode === 1 /* ShadowMode.Synthetic */ || renderMode === 0 /* RenderMode.Light */) {
4076
4300
  // slow path
4077
- allocateInSlot(vm, children, vnode.owner);
4301
+ allocateInSlot(vm, allocatedChildren, vnode.owner);
4078
4302
  // save the allocated children in case this vnode is reused.
4079
- vnode.aChildren = children;
4303
+ vnode.aChildren = allocatedChildren;
4080
4304
  // every child vnode is now allocated, and the host should receive none directly, it receives them via the shadow!
4081
4305
  vnode.children = EmptyArray;
4082
4306
  }
4083
4307
  }
4308
+ /**
4309
+ * Flattens the contents of all VFragments in an array of VNodes, removes the text delimiters on those VFragments, and
4310
+ * marks the resulting children array as dynamic. Uses a stack (array) to iteratively traverse the nested VFragments
4311
+ * and avoid the perf overhead of creating/destroying throwaway arrays/objects in a recursive approach.
4312
+ *
4313
+ * With the delimiters removed, the contents are marked dynamic so they are diffed correctly.
4314
+ *
4315
+ * This function is used for slotted VFragments to avoid the text delimiters interfering with slotting functionality.
4316
+ */
4317
+ function flattenFragmentsInChildren(children) {
4318
+ const flattenedChildren = [];
4319
+ // Initialize our stack with the direct children of the custom component and check whether we have a VFragment.
4320
+ // If no VFragment is found in children, we don't need to traverse anything or mark the children dynamic and can return early.
4321
+ const nodeStack = [];
4322
+ let fragmentFound = false;
4323
+ for (let i = children.length - 1; i > -1; i -= 1) {
4324
+ const child = children[i];
4325
+ ArrayPush$1.call(nodeStack, child);
4326
+ fragmentFound = fragmentFound || !!(child && isVFragment(child));
4327
+ }
4328
+ if (!fragmentFound) {
4329
+ return children;
4330
+ }
4331
+ let currentNode;
4332
+ while (!isUndefined$1(currentNode = ArrayPop.call(nodeStack))) {
4333
+ if (!isNull(currentNode) && isVFragment(currentNode)) {
4334
+ const fChildren = currentNode.children;
4335
+ // Ignore the start and end text node delimiters
4336
+ for (let i = fChildren.length - 2; i > 0; i -= 1) {
4337
+ ArrayPush$1.call(nodeStack, fChildren[i]);
4338
+ }
4339
+ } else {
4340
+ ArrayPush$1.call(flattenedChildren, currentNode);
4341
+ }
4342
+ }
4343
+ // We always mark the children as dynamic because nothing generates stable VFragments yet.
4344
+ // If/when stable VFragments are generated by the compiler, this code should be updated to
4345
+ // not mark dynamic if all flattened VFragments were stable.
4346
+ markAsDynamicChildren(flattenedChildren);
4347
+ return flattenedChildren;
4348
+ }
4084
4349
  function createViewModelHook(elm, vnode, renderer) {
4085
4350
  let vm = getAssociatedVMIfPresent(elm);
4086
4351
  // There is a possibility that a custom element is registered under tagName, in which case, the
@@ -4105,22 +4370,20 @@ function createViewModelHook(elm, vnode, renderer) {
4105
4370
  }
4106
4371
  return vm;
4107
4372
  }
4108
- /**
4109
- * Collects all slots into a SlotSet, traversing through VFragment Nodes
4110
- */
4111
- function collectSlots(vm, children, cmpSlotsMapping) {
4373
+ function allocateInSlot(vm, children, owner) {
4112
4374
  var _a, _b;
4375
+ const {
4376
+ cmpSlots: {
4377
+ slotAssignments: oldSlotsMapping
4378
+ }
4379
+ } = vm;
4380
+ const cmpSlotsMapping = create(null);
4381
+ // Collect all slots into cmpSlotsMapping
4113
4382
  for (let i = 0, len = children.length; i < len; i += 1) {
4114
4383
  const vnode = children[i];
4115
4384
  if (isNull(vnode)) {
4116
4385
  continue;
4117
4386
  }
4118
- // Dive further iff the content is wrapped in a VFragment
4119
- if (isVFragment(vnode)) {
4120
- // Remove the text delimiter nodes to avoid overriding default slot content
4121
- collectSlots(vm, vnode.children.slice(1, -1), cmpSlotsMapping);
4122
- continue;
4123
- }
4124
4387
  let slotName = '';
4125
4388
  if (isVBaseElement(vnode)) {
4126
4389
  slotName = (_b = (_a = vnode.data.attrs) === null || _a === void 0 ? void 0 : _a.slot) !== null && _b !== void 0 ? _b : '';
@@ -4130,15 +4393,6 @@ function collectSlots(vm, children, cmpSlotsMapping) {
4130
4393
  const vnodes = cmpSlotsMapping[slotName] = cmpSlotsMapping[slotName] || [];
4131
4394
  ArrayPush$1.call(vnodes, vnode);
4132
4395
  }
4133
- }
4134
- function allocateInSlot(vm, children, owner) {
4135
- const {
4136
- cmpSlots: {
4137
- slotAssignments: oldSlotsMapping
4138
- }
4139
- } = vm;
4140
- const cmpSlotsMapping = create(null);
4141
- collectSlots(vm, children, cmpSlotsMapping);
4142
4396
  vm.cmpSlots = {
4143
4397
  owner,
4144
4398
  slotAssignments: cmpSlotsMapping
@@ -4169,14 +4423,14 @@ function allocateInSlot(vm, children, owner) {
4169
4423
  }
4170
4424
  }
4171
4425
  // Using a WeakMap instead of a WeakSet because this one works in IE11 :(
4172
- const FromIteration = new WeakMap();
4173
- // dynamic children means it was generated by an iteration
4174
- // in a template, and will require a more complex diffing algo.
4426
+ const DynamicChildren = new WeakMap();
4427
+ // dynamic children means it was either generated by an iteration in a template
4428
+ // or part of an unstable fragment, and will require a more complex diffing algo.
4175
4429
  function markAsDynamicChildren(children) {
4176
- FromIteration.set(children, 1);
4430
+ DynamicChildren.set(children, 1);
4177
4431
  }
4178
4432
  function hasDynamicChildren(children) {
4179
- return FromIteration.has(children);
4433
+ return DynamicChildren.has(children);
4180
4434
  }
4181
4435
  function createKeyToOldIdx(children, beginIdx, endIdx) {
4182
4436
  const map = {};
@@ -5003,7 +5257,7 @@ function evaluateTemplate(vm, html) {
5003
5257
  // Create a brand new template cache for the swapped templated.
5004
5258
  context.tplCache = create(null);
5005
5259
  // Set the computeHasScopedStyles property in the context, to avoid recomputing it repeatedly.
5006
- context.hasScopedStyles = computeHasScopedStyles(html);
5260
+ context.hasScopedStyles = computeHasScopedStyles(html, vm);
5007
5261
  // Update the scoping token on the host element.
5008
5262
  updateStylesheetToken(vm, html);
5009
5263
  // Evaluate, create stylesheet and cache the produced VNode for future
@@ -5046,9 +5300,8 @@ function evaluateTemplate(vm, html) {
5046
5300
  }
5047
5301
  return vnodes;
5048
5302
  }
5049
- function computeHasScopedStyles(template) {
5050
- const { stylesheets } = template;
5051
- if (!isUndefined$1(stylesheets)) {
5303
+ function computeHasScopedStylesInStylesheets(stylesheets) {
5304
+ if (hasStyles(stylesheets)) {
5052
5305
  for (let i = 0; i < stylesheets.length; i++) {
5053
5306
  if (isTrue(stylesheets[i][KEY__SCOPED_CSS])) {
5054
5307
  return true;
@@ -5057,6 +5310,15 @@ function computeHasScopedStyles(template) {
5057
5310
  }
5058
5311
  return false;
5059
5312
  }
5313
+ function computeHasScopedStyles(template, vm) {
5314
+ const { stylesheets } = template;
5315
+ const vmStylesheets = !isUndefined$1(vm) ? vm.stylesheets : null;
5316
+ return (computeHasScopedStylesInStylesheets(stylesheets) ||
5317
+ computeHasScopedStylesInStylesheets(vmStylesheets));
5318
+ }
5319
+ function hasStyles(stylesheets) {
5320
+ return !isUndefined$1(stylesheets) && !isNull(stylesheets) && stylesheets.length > 0;
5321
+ }
5060
5322
 
5061
5323
  /*
5062
5324
  * Copyright (c) 2018, salesforce.com, inc.
@@ -5366,6 +5628,7 @@ function createVM(elm, ctor, renderer, options) {
5366
5628
  // Properties set right after VM creation.
5367
5629
  tro: null,
5368
5630
  shadowMode: null,
5631
+ stylesheets: null,
5369
5632
  // Properties set by the LightningElement constructor.
5370
5633
  component: null,
5371
5634
  shadowRoot: null,
@@ -5378,6 +5641,7 @@ function createVM(elm, ctor, renderer, options) {
5378
5641
  if (process.env.NODE_ENV !== 'production') {
5379
5642
  vm.debugInfo = create(null);
5380
5643
  }
5644
+ vm.stylesheets = computeStylesheets(vm, def.ctor);
5381
5645
  vm.shadowMode = computeShadowMode(vm, renderer);
5382
5646
  vm.tro = getTemplateReactiveObserver();
5383
5647
  if (process.env.NODE_ENV !== 'production') {
@@ -5396,6 +5660,42 @@ function createVM(elm, ctor, renderer, options) {
5396
5660
  }
5397
5661
  return vm;
5398
5662
  }
5663
+ function validateComponentStylesheets(vm, stylesheets) {
5664
+ let valid = true;
5665
+ const validate = arrayOrStylesheet => {
5666
+ if (isArray$1(arrayOrStylesheet)) {
5667
+ for (let i = 0; i < arrayOrStylesheet.length; i++) {
5668
+ validate(arrayOrStylesheet[i]);
5669
+ }
5670
+ } else if (!isFunction$1(arrayOrStylesheet)) {
5671
+ // function assumed to be a stylesheet factory
5672
+ valid = false;
5673
+ }
5674
+ };
5675
+ if (!isArray$1(stylesheets)) {
5676
+ valid = false;
5677
+ } else {
5678
+ validate(stylesheets);
5679
+ }
5680
+ return valid;
5681
+ }
5682
+ // Validate and flatten any stylesheets defined as `static stylesheets`
5683
+ function computeStylesheets(vm, ctor) {
5684
+ if (lwcRuntimeFlags.ENABLE_PROGRAMMATIC_STYLESHEETS) {
5685
+ const {
5686
+ stylesheets
5687
+ } = ctor;
5688
+ if (!isUndefined$1(stylesheets)) {
5689
+ const valid = validateComponentStylesheets(vm, stylesheets);
5690
+ if (valid) {
5691
+ return flattenStylesheets(stylesheets);
5692
+ } else if (process.env.NODE_ENV !== 'production') {
5693
+ logError(`static stylesheets must be an array of CSS stylesheets. Found invalid stylesheets on <${vm.tagName}>`, vm);
5694
+ }
5695
+ }
5696
+ }
5697
+ return null;
5698
+ }
5399
5699
  function computeShadowMode(vm, renderer) {
5400
5700
  const {
5401
5701
  def
@@ -6196,7 +6496,7 @@ function freezeTemplate(tmpl) {
6196
6496
  }
6197
6497
  }
6198
6498
  }
6199
- /* version: 2.32.1 */
6499
+ /* version: 2.34.0 */
6200
6500
 
6201
6501
  /*
6202
6502
  * Copyright (c) 2020, salesforce.com, inc.
@@ -6667,6 +6967,6 @@ function renderComponent(tagName, Ctor, props = {}) {
6667
6967
  */
6668
6968
  freeze(LightningElement);
6669
6969
  seal(LightningElement.prototype);
6670
- /* version: 2.32.1 */
6970
+ /* version: 2.34.0 */
6671
6971
 
6672
6972
  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 };