lwc 2.37.0 → 2.37.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (41) hide show
  1. package/dist/engine-dom/esm/es2017/engine-dom.js +2228 -2519
  2. package/dist/engine-dom/iife/es2017/engine-dom.js +8217 -8508
  3. package/dist/engine-dom/iife/es2017/engine-dom.min.js +1 -1
  4. package/dist/engine-dom/iife/es2017/engine-dom_debug.js +6603 -6857
  5. package/dist/engine-dom/iife/es5/engine-dom.js +8142 -8179
  6. package/dist/engine-dom/iife/es5/engine-dom.min.js +1 -1
  7. package/dist/engine-dom/iife/es5/engine-dom_debug.js +6730 -6721
  8. package/dist/engine-dom/umd/es2017/engine-dom.js +8218 -8509
  9. package/dist/engine-dom/umd/es2017/engine-dom.min.js +1 -1
  10. package/dist/engine-dom/umd/es2017/engine-dom_debug.js +6604 -6858
  11. package/dist/engine-dom/umd/es5/engine-dom.js +8143 -8180
  12. package/dist/engine-dom/umd/es5/engine-dom.min.js +1 -1
  13. package/dist/engine-dom/umd/es5/engine-dom_debug.js +6731 -6722
  14. package/dist/engine-server/commonjs/es2017/engine-server.js +1966 -2235
  15. package/dist/engine-server/commonjs/es2017/engine-server.min.js +1 -1
  16. package/dist/engine-server/esm/es2017/engine-server.js +1966 -2235
  17. package/dist/synthetic-shadow/esm/es2017/synthetic-shadow.js +211 -233
  18. package/dist/synthetic-shadow/iife/es2017/synthetic-shadow.js +4598 -4620
  19. package/dist/synthetic-shadow/iife/es2017/synthetic-shadow.min.js +9 -9
  20. package/dist/synthetic-shadow/iife/es2017/synthetic-shadow_debug.js +4422 -4423
  21. package/dist/synthetic-shadow/iife/es5/synthetic-shadow.js +4328 -4352
  22. package/dist/synthetic-shadow/iife/es5/synthetic-shadow.min.js +9 -9
  23. package/dist/synthetic-shadow/iife/es5/synthetic-shadow_debug.js +4170 -4172
  24. package/dist/synthetic-shadow/umd/es2017/synthetic-shadow.js +4599 -4621
  25. package/dist/synthetic-shadow/umd/es2017/synthetic-shadow.min.js +9 -9
  26. package/dist/synthetic-shadow/umd/es2017/synthetic-shadow_debug.js +4423 -4424
  27. package/dist/synthetic-shadow/umd/es5/synthetic-shadow.js +4329 -4353
  28. package/dist/synthetic-shadow/umd/es5/synthetic-shadow.min.js +9 -9
  29. package/dist/synthetic-shadow/umd/es5/synthetic-shadow_debug.js +4171 -4173
  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 +2 -2
  34. package/dist/wire-service/iife/es5/wire-service.min.js +1 -1
  35. package/dist/wire-service/iife/es5/wire-service_debug.js +2 -2
  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 +2 -2
  39. package/dist/wire-service/umd/es5/wire-service.min.js +1 -1
  40. package/dist/wire-service/umd/es5/wire-service_debug.js +2 -2
  41. package/package.json +7 -7
@@ -440,41 +440,9 @@ function htmlEscape(str, attrMode = false) {
440
440
  * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
441
441
  */
442
442
  // Increment whenever the LWC template compiler changes
443
- const LWC_VERSION = "2.37.0";
443
+ const LWC_VERSION = "2.37.2";
444
444
  const LWC_VERSION_COMMENT_REGEX = /\/\*LWC compiler v([\d.]+)\*\/\s*}/;
445
- /** version: 2.37.0 */
446
-
447
- /*
448
- * Copyright (c) 2020, salesforce.com, inc.
449
- * All rights reserved.
450
- * SPDX-License-Identifier: MIT
451
- * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
452
- */
453
- /**
454
- * The following constructor might be used in either the constructor or the connectedCallback. In
455
- * order to ensure that the component evaluates, we attach those mock constructors to the global
456
- * object.
457
- * Also note that Event is defined in Node 16+, but CustomEvent is not, so they have to be
458
- * polyfilled separately.
459
- */
460
- if (typeof Event !== 'function') {
461
- class Event {
462
- }
463
- defineProperty(_globalThis, 'Event', {
464
- value: Event,
465
- configurable: true,
466
- writable: true,
467
- });
468
- }
469
- if (typeof CustomEvent !== 'function') {
470
- class CustomEvent extends Event {
471
- }
472
- defineProperty(_globalThis, 'CustomEvent', {
473
- value: CustomEvent,
474
- configurable: true,
475
- writable: true,
476
- });
477
- }
445
+ /** version: 2.37.2 */
478
446
 
479
447
  /**
480
448
  * Copyright (C) 2018 salesforce.com, inc.
@@ -497,10 +465,12 @@ const features = {
497
465
  ENABLE_FROZEN_TEMPLATE: null,
498
466
  DISABLE_ARIA_REFLECTION_POLYFILL: null,
499
467
  };
468
+ // eslint-disable-next-line no-restricted-properties
500
469
  if (!_globalThis.lwcRuntimeFlags) {
501
470
  Object.defineProperty(_globalThis, 'lwcRuntimeFlags', { value: create(null) });
502
471
  }
503
- const lwcRuntimeFlags = _globalThis.lwcRuntimeFlags;
472
+ // eslint-disable-next-line no-restricted-properties
473
+ const flags = _globalThis.lwcRuntimeFlags;
504
474
  /**
505
475
  * Set the value at runtime of a given feature flag. This method only be invoked once per feature
506
476
  * flag. It is meant to be used during the app initialization.
@@ -528,17 +498,17 @@ function setFeatureFlag(name, value) {
528
498
  // This may seem redundant, but `process.env.NODE_ENV === 'test-karma-lwc'` is replaced by Karma tests
529
499
  if (process.env.NODE_ENV === 'test-karma-lwc' || process.env.NODE_ENV !== 'production') {
530
500
  // Allow the same flag to be set more than once outside of production to enable testing
531
- lwcRuntimeFlags[name] = value;
501
+ flags[name] = value;
532
502
  }
533
503
  else {
534
504
  // Disallow the same flag to be set more than once in production
535
- const runtimeValue = lwcRuntimeFlags[name];
505
+ const runtimeValue = flags[name];
536
506
  if (!isUndefined$1(runtimeValue)) {
537
507
  // eslint-disable-next-line no-console
538
508
  console.error(`Failed to set the value "${value}" for the runtime feature flag "${name}". "${name}" has already been set with the value "${runtimeValue}".`);
539
509
  return;
540
510
  }
541
- defineProperty(lwcRuntimeFlags, name, { value });
511
+ defineProperty(flags, name, { value });
542
512
  }
543
513
  }
544
514
  /**
@@ -551,7 +521,39 @@ function setFeatureFlagForTest(name, value) {
551
521
  setFeatureFlag(name, value);
552
522
  }
553
523
  }
554
- /** version: 2.37.0 */
524
+ /** version: 2.37.2 */
525
+
526
+ /*
527
+ * Copyright (c) 2020, salesforce.com, inc.
528
+ * All rights reserved.
529
+ * SPDX-License-Identifier: MIT
530
+ * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
531
+ */
532
+ /**
533
+ * The following constructor might be used in either the constructor or the connectedCallback. In
534
+ * order to ensure that the component evaluates, we attach those mock constructors to the global
535
+ * object.
536
+ * Also note that Event is defined in Node 16+, but CustomEvent is not, so they have to be
537
+ * polyfilled separately.
538
+ */
539
+ if (typeof Event !== 'function') {
540
+ class Event {
541
+ }
542
+ defineProperty(_globalThis, 'Event', {
543
+ value: Event,
544
+ configurable: true,
545
+ writable: true,
546
+ });
547
+ }
548
+ if (typeof CustomEvent !== 'function') {
549
+ class CustomEvent extends Event {
550
+ }
551
+ defineProperty(_globalThis, 'CustomEvent', {
552
+ value: CustomEvent,
553
+ configurable: true,
554
+ writable: true,
555
+ });
556
+ }
555
557
 
556
558
  /**
557
559
  * Copyright (C) 2018 salesforce.com, inc.
@@ -615,32 +617,10 @@ function applyAriaReflection(prototype = Element.prototype) {
615
617
  }
616
618
  }
617
619
  }
618
- /** version: 2.37.0 */
620
+ /** version: 2.37.2 */
619
621
 
620
622
  /* proxy-compat-disable */
621
623
 
622
- /*
623
- * Copyright (c) 2018, salesforce.com, inc.
624
- * All rights reserved.
625
- * SPDX-License-Identifier: MIT
626
- * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
627
- */
628
- // Only used in LWC's Karma tests
629
- if (process.env.NODE_ENV === 'test-karma-lwc') {
630
- window.addEventListener('test-dummy-flag', () => {
631
- let hasFlag = false;
632
- if (lwcRuntimeFlags.DUMMY_TEST_FLAG) {
633
- hasFlag = true;
634
- }
635
- window.dispatchEvent(new CustomEvent('has-dummy-flag', {
636
- detail: {
637
- package: '@lwc/engine-core',
638
- hasFlag
639
- }
640
- }));
641
- });
642
- }
643
-
644
624
  /*
645
625
  * Copyright (c) 2018, salesforce.com, inc.
646
626
  * All rights reserved.
@@ -1879,50 +1859,45 @@ function getReactiveProxy(value) {
1879
1859
  * for the Base Lightning Element, it also include the reactivity bit, so the standard property is reactive.
1880
1860
  */
1881
1861
  function createBridgeToElementDescriptor(propName, descriptor) {
1882
- const {
1883
- get,
1884
- set,
1885
- enumerable,
1886
- configurable
1887
- } = descriptor;
1888
- if (!isFunction$1(get)) {
1889
- if (process.env.NODE_ENV !== 'production') {
1890
- assert.fail(`Detected invalid public property descriptor for HTMLElement.prototype.${propName} definition. Missing the standard getter.`);
1891
- }
1892
- throw new TypeError();
1893
- }
1894
- if (!isFunction$1(set)) {
1895
- if (process.env.NODE_ENV !== 'production') {
1896
- assert.fail(`Detected invalid public property descriptor for HTMLElement.prototype.${propName} definition. Missing the standard setter.`);
1862
+ const { get, set, enumerable, configurable } = descriptor;
1863
+ if (!isFunction$1(get)) {
1864
+ if (process.env.NODE_ENV !== 'production') {
1865
+ assert.fail(`Detected invalid public property descriptor for HTMLElement.prototype.${propName} definition. Missing the standard getter.`);
1866
+ }
1867
+ throw new TypeError();
1897
1868
  }
1898
- throw new TypeError();
1899
- }
1900
- return {
1901
- enumerable,
1902
- configurable,
1903
- get() {
1904
- const vm = getAssociatedVM(this);
1905
- if (isBeingConstructed(vm)) {
1869
+ if (!isFunction$1(set)) {
1906
1870
  if (process.env.NODE_ENV !== 'production') {
1907
- 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);
1871
+ assert.fail(`Detected invalid public property descriptor for HTMLElement.prototype.${propName} definition. Missing the standard setter.`);
1908
1872
  }
1909
- return;
1910
- }
1911
- return get.call(vm.elm);
1912
- },
1913
- set(newValue) {
1914
- const vm = getAssociatedVM(this);
1915
- if (process.env.NODE_ENV !== 'production') {
1916
- const vmBeingRendered = getVMBeingRendered();
1917
- assert.invariant(!isInvokingRender, `${vmBeingRendered}.render() method has side effects on the state of ${vm}.${propName}`);
1918
- 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}`);
1919
- assert.isFalse(isBeingConstructed(vm), `Failed to construct '${getComponentTag(vm)}': The result must not have attributes.`);
1920
- assert.invariant(!isObject(newValue) || isNull(newValue), `Invalid value "${newValue}" for "${propName}" of ${vm}. Value cannot be an object, must be a primitive value.`);
1921
- }
1922
- updateComponentValue(vm, propName, newValue);
1923
- return set.call(vm.elm, newValue);
1873
+ throw new TypeError();
1924
1874
  }
1925
- };
1875
+ return {
1876
+ enumerable,
1877
+ configurable,
1878
+ get() {
1879
+ const vm = getAssociatedVM(this);
1880
+ if (isBeingConstructed(vm)) {
1881
+ if (process.env.NODE_ENV !== 'production') {
1882
+ 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);
1883
+ }
1884
+ return;
1885
+ }
1886
+ return get.call(vm.elm);
1887
+ },
1888
+ set(newValue) {
1889
+ const vm = getAssociatedVM(this);
1890
+ if (process.env.NODE_ENV !== 'production') {
1891
+ const vmBeingRendered = getVMBeingRendered();
1892
+ assert.invariant(!isInvokingRender, `${vmBeingRendered}.render() method has side effects on the state of ${vm}.${propName}`);
1893
+ 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}`);
1894
+ assert.isFalse(isBeingConstructed(vm), `Failed to construct '${getComponentTag(vm)}': The result must not have attributes.`);
1895
+ assert.invariant(!isObject(newValue) || isNull(newValue), `Invalid value "${newValue}" for "${propName}" of ${vm}. Value cannot be an object, must be a primitive value.`);
1896
+ }
1897
+ updateComponentValue(vm, propName, newValue);
1898
+ return set.call(vm.elm, newValue);
1899
+ },
1900
+ };
1926
1901
  }
1927
1902
  const refsCache = new WeakMap();
1928
1903
  /**
@@ -1931,436 +1906,347 @@ const refsCache = new WeakMap();
1931
1906
  **/
1932
1907
  // @ts-ignore
1933
1908
  const LightningElement = function () {
1934
- // This should be as performant as possible, while any initialization should be done lazily
1935
- if (isNull(vmBeingConstructed)) {
1936
- // Thrown when doing something like `new LightningElement()` or
1937
- // `class Foo extends LightningElement {}; new Foo()`
1938
- throw new TypeError('Illegal constructor');
1939
- }
1940
- const vm = vmBeingConstructed;
1941
- const {
1942
- def,
1943
- elm
1944
- } = vm;
1945
- const {
1946
- bridge
1947
- } = def;
1948
- if (process.env.NODE_ENV !== 'production') {
1949
- const {
1950
- assertInstanceOfHTMLElement
1951
- } = vm.renderer;
1952
- assertInstanceOfHTMLElement(vm.elm, `Component creation requires a DOM element to be associated to ${vm}.`);
1953
- }
1954
- const component = this;
1955
- setPrototypeOf(elm, bridge.prototype);
1956
- vm.component = this;
1957
- // Locker hooks assignment. When the LWC engine run with Locker, Locker intercepts all the new
1958
- // component creation and passes hooks to instrument all the component interactions with the
1959
- // engine. We are intentionally hiding this argument from the formal API of LightningElement
1960
- // because we don't want folks to know about it just yet.
1961
- if (arguments.length === 1) {
1962
- const {
1963
- callHook,
1964
- setHook,
1965
- getHook
1966
- } = arguments[0];
1967
- vm.callHook = callHook;
1968
- vm.setHook = setHook;
1969
- vm.getHook = getHook;
1970
- }
1971
- // Linking elm, shadow root and component with the VM.
1972
- associateVM(component, vm);
1973
- associateVM(elm, vm);
1974
- if (vm.renderMode === 1 /* RenderMode.Shadow */) {
1975
- vm.renderRoot = doAttachShadow(vm);
1976
- } else {
1977
- vm.renderRoot = elm;
1978
- }
1979
- // Adding extra guard rails in DEV mode.
1980
- if (process.env.NODE_ENV !== 'production') {
1981
- patchCustomElementWithRestrictions(elm);
1982
- patchComponentWithRestrictions(component);
1983
- }
1984
- return this;
1985
- };
1986
- function doAttachShadow(vm) {
1987
- const {
1988
- elm,
1989
- mode,
1990
- shadowMode,
1991
- def: {
1992
- ctor
1993
- },
1994
- renderer: {
1995
- attachShadow
1996
- }
1997
- } = vm;
1998
- const shadowRoot = attachShadow(elm, {
1999
- [KEY__SYNTHETIC_MODE]: shadowMode === 1 /* ShadowMode.Synthetic */,
2000
- delegatesFocus: Boolean(ctor.delegatesFocus),
2001
- mode
2002
- });
2003
- vm.shadowRoot = shadowRoot;
2004
- associateVM(shadowRoot, vm);
2005
- if (process.env.NODE_ENV !== 'production') {
2006
- patchShadowRootWithRestrictions(shadowRoot);
2007
- }
2008
- return shadowRoot;
2009
- }
2010
- function warnIfInvokedDuringConstruction(vm, methodOrPropName) {
2011
- if (isBeingConstructed(vm)) {
2012
- 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.`);
2013
- }
2014
- }
2015
- // @ts-ignore
2016
- LightningElement.prototype = {
2017
- constructor: LightningElement,
2018
- dispatchEvent(event) {
2019
- const vm = getAssociatedVM(this);
2020
- const {
2021
- elm,
2022
- renderer: {
2023
- dispatchEvent
2024
- }
2025
- } = vm;
2026
- return dispatchEvent(elm, event);
2027
- },
2028
- addEventListener(type, listener, options) {
2029
- const vm = getAssociatedVM(this);
2030
- const {
2031
- elm,
2032
- renderer: {
2033
- addEventListener
2034
- }
2035
- } = vm;
2036
- if (process.env.NODE_ENV !== 'production') {
2037
- const vmBeingRendered = getVMBeingRendered();
2038
- assert.invariant(!isInvokingRender, `${vmBeingRendered}.render() method has side effects on the state of ${vm} by adding an event listener for "${type}".`);
2039
- assert.invariant(!isUpdatingTemplate, `Updating the template of ${vmBeingRendered} has side effects on the state of ${vm} by adding an event listener for "${type}".`);
2040
- assert.invariant(isFunction$1(listener), `Invalid second argument for this.addEventListener() in ${vm} for event "${type}". Expected an EventListener but received ${listener}.`);
2041
- }
2042
- const wrappedListener = getWrappedComponentsListener(vm, listener);
2043
- addEventListener(elm, type, wrappedListener, options);
2044
- },
2045
- removeEventListener(type, listener, options) {
2046
- const vm = getAssociatedVM(this);
2047
- const {
2048
- elm,
2049
- renderer: {
2050
- removeEventListener
2051
- }
2052
- } = vm;
2053
- const wrappedListener = getWrappedComponentsListener(vm, listener);
2054
- removeEventListener(elm, type, wrappedListener, options);
2055
- },
2056
- hasAttribute(name) {
2057
- const vm = getAssociatedVM(this);
2058
- const {
2059
- elm,
2060
- renderer: {
2061
- getAttribute
2062
- }
2063
- } = vm;
2064
- return !isNull(getAttribute(elm, name));
2065
- },
2066
- hasAttributeNS(namespace, name) {
2067
- const vm = getAssociatedVM(this);
2068
- const {
2069
- elm,
2070
- renderer: {
2071
- getAttribute
2072
- }
2073
- } = vm;
2074
- return !isNull(getAttribute(elm, name, namespace));
2075
- },
2076
- removeAttribute(name) {
2077
- const vm = getAssociatedVM(this);
2078
- const {
2079
- elm,
2080
- renderer: {
2081
- removeAttribute
2082
- }
2083
- } = vm;
2084
- unlockAttribute(elm, name);
2085
- removeAttribute(elm, name);
2086
- lockAttribute();
2087
- },
2088
- removeAttributeNS(namespace, name) {
2089
- const {
2090
- elm,
2091
- renderer: {
2092
- removeAttribute
2093
- }
2094
- } = getAssociatedVM(this);
2095
- unlockAttribute(elm, name);
2096
- removeAttribute(elm, name, namespace);
2097
- lockAttribute();
2098
- },
2099
- getAttribute(name) {
2100
- const vm = getAssociatedVM(this);
2101
- const {
2102
- elm
2103
- } = vm;
2104
- const {
2105
- getAttribute
2106
- } = vm.renderer;
2107
- return getAttribute(elm, name);
2108
- },
2109
- getAttributeNS(namespace, name) {
2110
- const vm = getAssociatedVM(this);
2111
- const {
2112
- elm
2113
- } = vm;
2114
- const {
2115
- getAttribute
2116
- } = vm.renderer;
2117
- return getAttribute(elm, name, namespace);
2118
- },
2119
- setAttribute(name, value) {
2120
- const vm = getAssociatedVM(this);
2121
- const {
2122
- elm,
2123
- renderer: {
2124
- setAttribute
2125
- }
2126
- } = vm;
1909
+ // This should be as performant as possible, while any initialization should be done lazily
1910
+ if (isNull(vmBeingConstructed)) {
1911
+ // Thrown when doing something like `new LightningElement()` or
1912
+ // `class Foo extends LightningElement {}; new Foo()`
1913
+ throw new TypeError('Illegal constructor');
1914
+ }
1915
+ const vm = vmBeingConstructed;
1916
+ const { def, elm } = vm;
1917
+ const { bridge } = def;
2127
1918
  if (process.env.NODE_ENV !== 'production') {
2128
- assert.isFalse(isBeingConstructed(vm), `Failed to construct '${getComponentTag(vm)}': The result must not have attributes.`);
2129
- }
2130
- unlockAttribute(elm, name);
2131
- setAttribute(elm, name, value);
2132
- lockAttribute();
2133
- },
2134
- setAttributeNS(namespace, name, value) {
2135
- const vm = getAssociatedVM(this);
2136
- const {
2137
- elm,
2138
- renderer: {
2139
- setAttribute
2140
- }
2141
- } = vm;
2142
- if (process.env.NODE_ENV !== 'production') {
2143
- assert.isFalse(isBeingConstructed(vm), `Failed to construct '${getComponentTag(vm)}': The result must not have attributes.`);
2144
- }
2145
- unlockAttribute(elm, name);
2146
- setAttribute(elm, name, value, namespace);
2147
- lockAttribute();
2148
- },
2149
- getBoundingClientRect() {
2150
- const vm = getAssociatedVM(this);
2151
- const {
2152
- elm,
2153
- renderer: {
2154
- getBoundingClientRect
2155
- }
2156
- } = vm;
2157
- if (process.env.NODE_ENV !== 'production') {
2158
- warnIfInvokedDuringConstruction(vm, 'getBoundingClientRect()');
2159
- }
2160
- return getBoundingClientRect(elm);
2161
- },
2162
- get isConnected() {
2163
- const vm = getAssociatedVM(this);
2164
- const {
2165
- elm,
2166
- renderer: {
2167
- isConnected
2168
- }
2169
- } = vm;
2170
- return isConnected(elm);
2171
- },
2172
- get classList() {
2173
- const vm = getAssociatedVM(this);
2174
- const {
2175
- elm,
2176
- renderer: {
2177
- getClassList
2178
- }
2179
- } = vm;
2180
- if (process.env.NODE_ENV !== 'production') {
2181
- // TODO [#1290]: this still fails in dev but works in production, eventually, we should
2182
- // just throw in all modes
2183
- 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.`);
2184
- }
2185
- return getClassList(elm);
2186
- },
2187
- get template() {
2188
- const vm = getAssociatedVM(this);
2189
- if (process.env.NODE_ENV !== 'production') {
2190
- if (vm.renderMode === 0 /* RenderMode.Light */) {
2191
- 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`.');
2192
- }
2193
- }
2194
- return vm.shadowRoot;
2195
- },
2196
- get refs() {
2197
- const vm = getAssociatedVM(this);
2198
- if (isUpdatingTemplate) {
2199
- if (process.env.NODE_ENV !== 'production') {
2200
- 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().`);
2201
- }
2202
- // If the template is in the process of being updated, then we don't want to go through the normal
2203
- // process of returning the refs and caching them, because the state of the refs is unstable.
2204
- // This can happen if e.g. a template contains `<div class={foo}></div>` and `foo` is computed
2205
- // based on `this.refs.bar`.
2206
- return;
1919
+ const { assertInstanceOfHTMLElement } = vm.renderer;
1920
+ assertInstanceOfHTMLElement(vm.elm, `Component creation requires a DOM element to be associated to ${vm}.`);
1921
+ }
1922
+ const component = this;
1923
+ setPrototypeOf(elm, bridge.prototype);
1924
+ vm.component = this;
1925
+ // Locker hooks assignment. When the LWC engine run with Locker, Locker intercepts all the new
1926
+ // component creation and passes hooks to instrument all the component interactions with the
1927
+ // engine. We are intentionally hiding this argument from the formal API of LightningElement
1928
+ // because we don't want folks to know about it just yet.
1929
+ if (arguments.length === 1) {
1930
+ const { callHook, setHook, getHook } = arguments[0];
1931
+ vm.callHook = callHook;
1932
+ vm.setHook = setHook;
1933
+ vm.getHook = getHook;
2207
1934
  }
2208
- if (process.env.NODE_ENV !== 'production') {
2209
- warnIfInvokedDuringConstruction(vm, 'refs');
2210
- }
2211
- const {
2212
- refVNodes,
2213
- cmpTemplate
2214
- } = vm;
2215
- // If the `cmpTemplate` is null, that means that the template has not been rendered yet. Most likely this occurs
2216
- // if `this.refs` is called during the `connectedCallback` phase. The DOM elements have not been rendered yet,
2217
- // so log a warning. Note we also check `isBeingConstructed()` to avoid a double warning (due to
2218
- // `warnIfInvokedDuringConstruction` above).
2219
- if (process.env.NODE_ENV !== 'production' && isNull(cmpTemplate) && !isBeingConstructed(vm)) {
2220
- 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().`);
2221
- }
2222
- // For backwards compatibility with component written before template refs
2223
- // were introduced, we return undefined if the template has no refs defined
2224
- // anywhere. This fixes components that may want to add an expando called `refs`
2225
- // and are checking if it exists with `if (this.refs)` before adding it.
2226
- // Note we use a null refVNodes to indicate that the template has no refs defined.
2227
- if (isNull(refVNodes)) {
2228
- return;
2229
- }
2230
- // The refNodes can be cached based on the refVNodes, since the refVNodes
2231
- // are recreated from scratch every time the template is rendered.
2232
- // This happens with `vm.refVNodes = null` in `template.ts` in `@lwc/engine-core`.
2233
- let refs = refsCache.get(refVNodes);
2234
- if (isUndefined$1(refs)) {
2235
- refs = create(null);
2236
- for (const key of keys(refVNodes)) {
2237
- refs[key] = refVNodes[key].elm;
2238
- }
2239
- freeze(refs);
2240
- refsCache.set(refVNodes, refs);
2241
- }
2242
- return refs;
2243
- },
2244
- // For backwards compat, we allow component authors to set `refs` as an expando
2245
- set refs(value) {
2246
- defineProperty(this, 'refs', {
2247
- configurable: true,
2248
- enumerable: true,
2249
- writable: true,
2250
- value
2251
- });
2252
- },
2253
- get shadowRoot() {
2254
- // From within the component instance, the shadowRoot is always reported as "closed".
2255
- // Authors should rely on this.template instead.
2256
- return null;
2257
- },
2258
- get children() {
2259
- const vm = getAssociatedVM(this);
2260
- const renderer = vm.renderer;
2261
- if (process.env.NODE_ENV !== 'production') {
2262
- warnIfInvokedDuringConstruction(vm, 'children');
1935
+ // Linking elm, shadow root and component with the VM.
1936
+ associateVM(component, vm);
1937
+ associateVM(elm, vm);
1938
+ if (vm.renderMode === 1 /* RenderMode.Shadow */) {
1939
+ vm.renderRoot = doAttachShadow(vm);
2263
1940
  }
2264
- return renderer.getChildren(vm.elm);
2265
- },
2266
- get childNodes() {
2267
- const vm = getAssociatedVM(this);
2268
- const renderer = vm.renderer;
2269
- if (process.env.NODE_ENV !== 'production') {
2270
- warnIfInvokedDuringConstruction(vm, 'childNodes');
1941
+ else {
1942
+ vm.renderRoot = elm;
2271
1943
  }
2272
- return renderer.getChildNodes(vm.elm);
2273
- },
2274
- get firstChild() {
2275
- const vm = getAssociatedVM(this);
2276
- const renderer = vm.renderer;
1944
+ // Adding extra guard rails in DEV mode.
2277
1945
  if (process.env.NODE_ENV !== 'production') {
2278
- warnIfInvokedDuringConstruction(vm, 'firstChild');
1946
+ patchCustomElementWithRestrictions(elm);
1947
+ patchComponentWithRestrictions(component);
2279
1948
  }
2280
- return renderer.getFirstChild(vm.elm);
2281
- },
2282
- get firstElementChild() {
2283
- const vm = getAssociatedVM(this);
2284
- const renderer = vm.renderer;
1949
+ return this;
1950
+ };
1951
+ function doAttachShadow(vm) {
1952
+ const { elm, mode, shadowMode, def: { ctor }, renderer: { attachShadow }, } = vm;
1953
+ const shadowRoot = attachShadow(elm, {
1954
+ [KEY__SYNTHETIC_MODE]: shadowMode === 1 /* ShadowMode.Synthetic */,
1955
+ delegatesFocus: Boolean(ctor.delegatesFocus),
1956
+ mode,
1957
+ });
1958
+ vm.shadowRoot = shadowRoot;
1959
+ associateVM(shadowRoot, vm);
2285
1960
  if (process.env.NODE_ENV !== 'production') {
2286
- warnIfInvokedDuringConstruction(vm, 'firstElementChild');
1961
+ patchShadowRootWithRestrictions(shadowRoot);
2287
1962
  }
2288
- return renderer.getFirstElementChild(vm.elm);
2289
- },
2290
- get lastChild() {
2291
- const vm = getAssociatedVM(this);
2292
- const renderer = vm.renderer;
2293
- if (process.env.NODE_ENV !== 'production') {
2294
- warnIfInvokedDuringConstruction(vm, 'lastChild');
1963
+ return shadowRoot;
1964
+ }
1965
+ function warnIfInvokedDuringConstruction(vm, methodOrPropName) {
1966
+ if (isBeingConstructed(vm)) {
1967
+ 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.`);
2295
1968
  }
2296
- return renderer.getLastChild(vm.elm);
2297
- },
2298
- get lastElementChild() {
2299
- const vm = getAssociatedVM(this);
2300
- const renderer = vm.renderer;
2301
- if (process.env.NODE_ENV !== 'production') {
2302
- warnIfInvokedDuringConstruction(vm, 'lastElementChild');
2303
- }
2304
- return renderer.getLastElementChild(vm.elm);
2305
- },
2306
- render() {
2307
- const vm = getAssociatedVM(this);
2308
- return vm.def.template;
2309
- },
2310
- toString() {
2311
- const vm = getAssociatedVM(this);
2312
- return `[object ${vm.def.name}]`;
2313
- }
1969
+ }
1970
+ // @ts-ignore
1971
+ LightningElement.prototype = {
1972
+ constructor: LightningElement,
1973
+ dispatchEvent(event) {
1974
+ const vm = getAssociatedVM(this);
1975
+ const { elm, renderer: { dispatchEvent }, } = vm;
1976
+ return dispatchEvent(elm, event);
1977
+ },
1978
+ addEventListener(type, listener, options) {
1979
+ const vm = getAssociatedVM(this);
1980
+ const { elm, renderer: { addEventListener }, } = vm;
1981
+ if (process.env.NODE_ENV !== 'production') {
1982
+ const vmBeingRendered = getVMBeingRendered();
1983
+ assert.invariant(!isInvokingRender, `${vmBeingRendered}.render() method has side effects on the state of ${vm} by adding an event listener for "${type}".`);
1984
+ assert.invariant(!isUpdatingTemplate, `Updating the template of ${vmBeingRendered} has side effects on the state of ${vm} by adding an event listener for "${type}".`);
1985
+ assert.invariant(isFunction$1(listener), `Invalid second argument for this.addEventListener() in ${vm} for event "${type}". Expected an EventListener but received ${listener}.`);
1986
+ }
1987
+ const wrappedListener = getWrappedComponentsListener(vm, listener);
1988
+ addEventListener(elm, type, wrappedListener, options);
1989
+ },
1990
+ removeEventListener(type, listener, options) {
1991
+ const vm = getAssociatedVM(this);
1992
+ const { elm, renderer: { removeEventListener }, } = vm;
1993
+ const wrappedListener = getWrappedComponentsListener(vm, listener);
1994
+ removeEventListener(elm, type, wrappedListener, options);
1995
+ },
1996
+ hasAttribute(name) {
1997
+ const vm = getAssociatedVM(this);
1998
+ const { elm, renderer: { getAttribute }, } = vm;
1999
+ return !isNull(getAttribute(elm, name));
2000
+ },
2001
+ hasAttributeNS(namespace, name) {
2002
+ const vm = getAssociatedVM(this);
2003
+ const { elm, renderer: { getAttribute }, } = vm;
2004
+ return !isNull(getAttribute(elm, name, namespace));
2005
+ },
2006
+ removeAttribute(name) {
2007
+ const vm = getAssociatedVM(this);
2008
+ const { elm, renderer: { removeAttribute }, } = vm;
2009
+ unlockAttribute(elm, name);
2010
+ removeAttribute(elm, name);
2011
+ lockAttribute();
2012
+ },
2013
+ removeAttributeNS(namespace, name) {
2014
+ const { elm, renderer: { removeAttribute }, } = getAssociatedVM(this);
2015
+ unlockAttribute(elm, name);
2016
+ removeAttribute(elm, name, namespace);
2017
+ lockAttribute();
2018
+ },
2019
+ getAttribute(name) {
2020
+ const vm = getAssociatedVM(this);
2021
+ const { elm } = vm;
2022
+ const { getAttribute } = vm.renderer;
2023
+ return getAttribute(elm, name);
2024
+ },
2025
+ getAttributeNS(namespace, name) {
2026
+ const vm = getAssociatedVM(this);
2027
+ const { elm } = vm;
2028
+ const { getAttribute } = vm.renderer;
2029
+ return getAttribute(elm, name, namespace);
2030
+ },
2031
+ setAttribute(name, value) {
2032
+ const vm = getAssociatedVM(this);
2033
+ const { elm, renderer: { setAttribute }, } = vm;
2034
+ if (process.env.NODE_ENV !== 'production') {
2035
+ assert.isFalse(isBeingConstructed(vm), `Failed to construct '${getComponentTag(vm)}': The result must not have attributes.`);
2036
+ }
2037
+ unlockAttribute(elm, name);
2038
+ setAttribute(elm, name, value);
2039
+ lockAttribute();
2040
+ },
2041
+ setAttributeNS(namespace, name, value) {
2042
+ const vm = getAssociatedVM(this);
2043
+ const { elm, renderer: { setAttribute }, } = vm;
2044
+ if (process.env.NODE_ENV !== 'production') {
2045
+ assert.isFalse(isBeingConstructed(vm), `Failed to construct '${getComponentTag(vm)}': The result must not have attributes.`);
2046
+ }
2047
+ unlockAttribute(elm, name);
2048
+ setAttribute(elm, name, value, namespace);
2049
+ lockAttribute();
2050
+ },
2051
+ getBoundingClientRect() {
2052
+ const vm = getAssociatedVM(this);
2053
+ const { elm, renderer: { getBoundingClientRect }, } = vm;
2054
+ if (process.env.NODE_ENV !== 'production') {
2055
+ warnIfInvokedDuringConstruction(vm, 'getBoundingClientRect()');
2056
+ }
2057
+ return getBoundingClientRect(elm);
2058
+ },
2059
+ get isConnected() {
2060
+ const vm = getAssociatedVM(this);
2061
+ const { elm, renderer: { isConnected }, } = vm;
2062
+ return isConnected(elm);
2063
+ },
2064
+ get classList() {
2065
+ const vm = getAssociatedVM(this);
2066
+ const { elm, renderer: { getClassList }, } = vm;
2067
+ if (process.env.NODE_ENV !== 'production') {
2068
+ // TODO [#1290]: this still fails in dev but works in production, eventually, we should
2069
+ // just throw in all modes
2070
+ 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.`);
2071
+ }
2072
+ return getClassList(elm);
2073
+ },
2074
+ get template() {
2075
+ const vm = getAssociatedVM(this);
2076
+ if (process.env.NODE_ENV !== 'production') {
2077
+ if (vm.renderMode === 0 /* RenderMode.Light */) {
2078
+ 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`.');
2079
+ }
2080
+ }
2081
+ return vm.shadowRoot;
2082
+ },
2083
+ get refs() {
2084
+ const vm = getAssociatedVM(this);
2085
+ if (isUpdatingTemplate) {
2086
+ if (process.env.NODE_ENV !== 'production') {
2087
+ 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().`);
2088
+ }
2089
+ // If the template is in the process of being updated, then we don't want to go through the normal
2090
+ // process of returning the refs and caching them, because the state of the refs is unstable.
2091
+ // This can happen if e.g. a template contains `<div class={foo}></div>` and `foo` is computed
2092
+ // based on `this.refs.bar`.
2093
+ return;
2094
+ }
2095
+ if (process.env.NODE_ENV !== 'production') {
2096
+ warnIfInvokedDuringConstruction(vm, 'refs');
2097
+ }
2098
+ const { refVNodes, cmpTemplate } = vm;
2099
+ // If the `cmpTemplate` is null, that means that the template has not been rendered yet. Most likely this occurs
2100
+ // if `this.refs` is called during the `connectedCallback` phase. The DOM elements have not been rendered yet,
2101
+ // so log a warning. Note we also check `isBeingConstructed()` to avoid a double warning (due to
2102
+ // `warnIfInvokedDuringConstruction` above).
2103
+ if (process.env.NODE_ENV !== 'production' &&
2104
+ isNull(cmpTemplate) &&
2105
+ !isBeingConstructed(vm)) {
2106
+ logError(`this.refs is undefined for ${getComponentTag(vm)}. This is either because the attached template has no "lwc:ref" directive, or this.refs was ` +
2107
+ `invoked before renderedCallback(). Use this.refs only when the referenced HTML elements have ` +
2108
+ `been rendered to the DOM, such as within renderedCallback() or disconnectedCallback().`);
2109
+ }
2110
+ // For backwards compatibility with component written before template refs
2111
+ // were introduced, we return undefined if the template has no refs defined
2112
+ // anywhere. This fixes components that may want to add an expando called `refs`
2113
+ // and are checking if it exists with `if (this.refs)` before adding it.
2114
+ // Note we use a null refVNodes to indicate that the template has no refs defined.
2115
+ if (isNull(refVNodes)) {
2116
+ return;
2117
+ }
2118
+ // The refNodes can be cached based on the refVNodes, since the refVNodes
2119
+ // are recreated from scratch every time the template is rendered.
2120
+ // This happens with `vm.refVNodes = null` in `template.ts` in `@lwc/engine-core`.
2121
+ let refs = refsCache.get(refVNodes);
2122
+ if (isUndefined$1(refs)) {
2123
+ refs = create(null);
2124
+ for (const key of keys(refVNodes)) {
2125
+ refs[key] = refVNodes[key].elm;
2126
+ }
2127
+ freeze(refs);
2128
+ refsCache.set(refVNodes, refs);
2129
+ }
2130
+ return refs;
2131
+ },
2132
+ // For backwards compat, we allow component authors to set `refs` as an expando
2133
+ set refs(value) {
2134
+ defineProperty(this, 'refs', {
2135
+ configurable: true,
2136
+ enumerable: true,
2137
+ writable: true,
2138
+ value,
2139
+ });
2140
+ },
2141
+ get shadowRoot() {
2142
+ // From within the component instance, the shadowRoot is always reported as "closed".
2143
+ // Authors should rely on this.template instead.
2144
+ return null;
2145
+ },
2146
+ get children() {
2147
+ const vm = getAssociatedVM(this);
2148
+ const renderer = vm.renderer;
2149
+ if (process.env.NODE_ENV !== 'production') {
2150
+ warnIfInvokedDuringConstruction(vm, 'children');
2151
+ }
2152
+ return renderer.getChildren(vm.elm);
2153
+ },
2154
+ get childNodes() {
2155
+ const vm = getAssociatedVM(this);
2156
+ const renderer = vm.renderer;
2157
+ if (process.env.NODE_ENV !== 'production') {
2158
+ warnIfInvokedDuringConstruction(vm, 'childNodes');
2159
+ }
2160
+ return renderer.getChildNodes(vm.elm);
2161
+ },
2162
+ get firstChild() {
2163
+ const vm = getAssociatedVM(this);
2164
+ const renderer = vm.renderer;
2165
+ if (process.env.NODE_ENV !== 'production') {
2166
+ warnIfInvokedDuringConstruction(vm, 'firstChild');
2167
+ }
2168
+ return renderer.getFirstChild(vm.elm);
2169
+ },
2170
+ get firstElementChild() {
2171
+ const vm = getAssociatedVM(this);
2172
+ const renderer = vm.renderer;
2173
+ if (process.env.NODE_ENV !== 'production') {
2174
+ warnIfInvokedDuringConstruction(vm, 'firstElementChild');
2175
+ }
2176
+ return renderer.getFirstElementChild(vm.elm);
2177
+ },
2178
+ get lastChild() {
2179
+ const vm = getAssociatedVM(this);
2180
+ const renderer = vm.renderer;
2181
+ if (process.env.NODE_ENV !== 'production') {
2182
+ warnIfInvokedDuringConstruction(vm, 'lastChild');
2183
+ }
2184
+ return renderer.getLastChild(vm.elm);
2185
+ },
2186
+ get lastElementChild() {
2187
+ const vm = getAssociatedVM(this);
2188
+ const renderer = vm.renderer;
2189
+ if (process.env.NODE_ENV !== 'production') {
2190
+ warnIfInvokedDuringConstruction(vm, 'lastElementChild');
2191
+ }
2192
+ return renderer.getLastElementChild(vm.elm);
2193
+ },
2194
+ render() {
2195
+ const vm = getAssociatedVM(this);
2196
+ return vm.def.template;
2197
+ },
2198
+ toString() {
2199
+ const vm = getAssociatedVM(this);
2200
+ return `[object ${vm.def.name}]`;
2201
+ },
2314
2202
  };
2315
2203
  const queryAndChildGetterDescriptors = create(null);
2316
- const queryMethods = ['getElementsByClassName', 'getElementsByTagName', 'querySelector', 'querySelectorAll'];
2204
+ const queryMethods = [
2205
+ 'getElementsByClassName',
2206
+ 'getElementsByTagName',
2207
+ 'querySelector',
2208
+ 'querySelectorAll',
2209
+ ];
2317
2210
  // Generic passthrough for query APIs on HTMLElement to the relevant Renderer APIs
2318
2211
  for (const queryMethod of queryMethods) {
2319
- queryAndChildGetterDescriptors[queryMethod] = {
2320
- value(arg) {
2321
- const vm = getAssociatedVM(this);
2322
- const {
2323
- elm,
2324
- renderer
2325
- } = vm;
2326
- if (process.env.NODE_ENV !== 'production') {
2327
- warnIfInvokedDuringConstruction(vm, `${queryMethod}()`);
2328
- }
2329
- return renderer[queryMethod](elm, arg);
2330
- },
2331
- configurable: true,
2332
- enumerable: true,
2333
- writable: true
2334
- };
2212
+ queryAndChildGetterDescriptors[queryMethod] = {
2213
+ value(arg) {
2214
+ const vm = getAssociatedVM(this);
2215
+ const { elm, renderer } = vm;
2216
+ if (process.env.NODE_ENV !== 'production') {
2217
+ warnIfInvokedDuringConstruction(vm, `${queryMethod}()`);
2218
+ }
2219
+ return renderer[queryMethod](elm, arg);
2220
+ },
2221
+ configurable: true,
2222
+ enumerable: true,
2223
+ writable: true,
2224
+ };
2335
2225
  }
2336
2226
  defineProperties(LightningElement.prototype, queryAndChildGetterDescriptors);
2337
2227
  const lightningBasedDescriptors = create(null);
2338
2228
  for (const propName in HTMLElementOriginalDescriptors) {
2339
- lightningBasedDescriptors[propName] = createBridgeToElementDescriptor(propName, HTMLElementOriginalDescriptors[propName]);
2229
+ lightningBasedDescriptors[propName] = createBridgeToElementDescriptor(propName, HTMLElementOriginalDescriptors[propName]);
2340
2230
  }
2341
2231
  defineProperties(LightningElement.prototype, lightningBasedDescriptors);
2342
2232
  function applyAriaReflectionToLightningElement() {
2343
- // If ARIA reflection is not applied globally to Element.prototype, or if we are running server-side,
2344
- // apply it to LightningElement.prototype.
2345
- // This allows `this.aria*` property accessors to work from inside a component, and to reflect `aria-*` attrs.
2346
- applyAriaReflection(LightningElement.prototype);
2347
- }
2348
- // The reason for this odd if/else branching is limitations in @lwc/features:
2349
- // https://github.com/salesforce/lwc/blob/master/packages/%40lwc/features/README.md#only-works-with-if-statements
2350
- if (lwcRuntimeFlags.DISABLE_ARIA_REFLECTION_POLYFILL) {
2351
- applyAriaReflectionToLightningElement();
2352
- } else {
2353
- applyAriaReflectionToLightningElement();
2233
+ // If ARIA reflection is not applied globally to Element.prototype, or if we are running server-side,
2234
+ // apply it to LightningElement.prototype.
2235
+ // This allows `this.aria*` property accessors to work from inside a component, and to reflect `aria-*` attrs.
2236
+ applyAriaReflection(LightningElement.prototype);
2237
+ }
2238
+ {
2239
+ applyAriaReflectionToLightningElement();
2354
2240
  }
2355
2241
  defineProperty(LightningElement, 'CustomElementConstructor', {
2356
- get() {
2357
- // If required, a runtime-specific implementation must be defined.
2358
- throw new ReferenceError('The current runtime does not support CustomElementConstructor.');
2359
- },
2360
- configurable: true
2242
+ get() {
2243
+ // If required, a runtime-specific implementation must be defined.
2244
+ throw new ReferenceError('The current runtime does not support CustomElementConstructor.');
2245
+ },
2246
+ configurable: true,
2361
2247
  });
2362
2248
  if (process.env.NODE_ENV !== 'production') {
2363
- patchLightningElementPrototypeWithRestrictions(LightningElement.prototype);
2249
+ patchLightningElementPrototypeWithRestrictions(LightningElement.prototype);
2364
2250
  }
2365
2251
 
2366
2252
  function createObservedFieldPropertyDescriptor(key) {
@@ -2389,268 +2275,234 @@ const DeprecatedWiredParamsMeta = '$$DeprecatedWiredParamsMetaKey$$';
2389
2275
  const WIRE_DEBUG_ENTRY = '@wire';
2390
2276
  const WireMetaMap = new Map();
2391
2277
  class WireContextRegistrationEvent extends CustomEvent {
2392
- constructor(adapterToken, {
2393
- setNewContext,
2394
- setDisconnectedCallback
2395
- }) {
2396
- super(adapterToken, {
2397
- bubbles: true,
2398
- composed: true
2399
- });
2400
- defineProperties(this, {
2401
- setNewContext: {
2402
- value: setNewContext
2403
- },
2404
- setDisconnectedCallback: {
2405
- value: setDisconnectedCallback
2406
- }
2407
- });
2408
- }
2278
+ constructor(adapterToken, { setNewContext, setDisconnectedCallback }) {
2279
+ super(adapterToken, {
2280
+ bubbles: true,
2281
+ composed: true,
2282
+ });
2283
+ defineProperties(this, {
2284
+ setNewContext: {
2285
+ value: setNewContext,
2286
+ },
2287
+ setDisconnectedCallback: {
2288
+ value: setDisconnectedCallback,
2289
+ },
2290
+ });
2291
+ }
2409
2292
  }
2410
2293
  function createFieldDataCallback(vm, name) {
2411
- return value => {
2412
- updateComponentValue(vm, name, value);
2413
- };
2294
+ return (value) => {
2295
+ updateComponentValue(vm, name, value);
2296
+ };
2414
2297
  }
2415
2298
  function createMethodDataCallback(vm, method) {
2416
- return value => {
2417
- // dispatching new value into the wired method
2418
- runWithBoundaryProtection(vm, vm.owner, noop, () => {
2419
- // job
2420
- method.call(vm.component, value);
2421
- }, noop);
2422
- };
2299
+ return (value) => {
2300
+ // dispatching new value into the wired method
2301
+ runWithBoundaryProtection(vm, vm.owner, noop, () => {
2302
+ // job
2303
+ method.call(vm.component, value);
2304
+ }, noop);
2305
+ };
2423
2306
  }
2424
2307
  function createConfigWatcher(component, configCallback, callbackWhenConfigIsReady) {
2425
- // creating the reactive observer for reactive params when needed
2426
- const ro = createReactiveObserver();
2427
- const computeConfigAndUpdate = () => {
2428
- let config;
2429
- ro.observe(() => config = configCallback(component));
2430
- // eslint-disable-next-line @lwc/lwc-internal/no-invalid-todo
2431
- // TODO: dev-mode validation of config based on the adapter.configSchema
2432
- // @ts-ignore it is assigned in the observe() callback
2433
- callbackWhenConfigIsReady(config);
2434
- };
2435
- return {
2436
- computeConfigAndUpdate,
2437
- ro
2438
- };
2308
+ // creating the reactive observer for reactive params when needed
2309
+ const ro = createReactiveObserver();
2310
+ const computeConfigAndUpdate = () => {
2311
+ let config;
2312
+ ro.observe(() => (config = configCallback(component)));
2313
+ // eslint-disable-next-line @lwc/lwc-internal/no-invalid-todo
2314
+ // TODO: dev-mode validation of config based on the adapter.configSchema
2315
+ // @ts-ignore it is assigned in the observe() callback
2316
+ callbackWhenConfigIsReady(config);
2317
+ };
2318
+ return {
2319
+ computeConfigAndUpdate,
2320
+ ro,
2321
+ };
2439
2322
  }
2440
2323
  function createContextWatcher(vm, wireDef, callbackWhenContextIsReady) {
2441
- const {
2442
- adapter
2443
- } = wireDef;
2444
- const adapterContextToken = getAdapterToken(adapter);
2445
- if (isUndefined$1(adapterContextToken)) {
2446
- return; // no provider found, nothing to be done
2447
- }
2448
-
2449
- const {
2450
- elm,
2451
- context: {
2452
- wiredConnecting,
2453
- wiredDisconnecting
2454
- },
2455
- renderer: {
2456
- dispatchEvent
2457
- }
2458
- } = vm;
2459
- // waiting for the component to be connected to formally request the context via the token
2460
- ArrayPush$1.call(wiredConnecting, () => {
2461
- // This event is responsible for connecting the host element with another
2462
- // element in the composed path that is providing contextual data. The provider
2463
- // must be listening for a special dom event with the name corresponding to the value of
2464
- // `adapterContextToken`, which will remain secret and internal to this file only to
2465
- // guarantee that the linkage can be forged.
2466
- const contextRegistrationEvent = new WireContextRegistrationEvent(adapterContextToken, {
2467
- setNewContext(newContext) {
2468
- // eslint-disable-next-line @lwc/lwc-internal/no-invalid-todo
2469
- // TODO: dev-mode validation of config based on the adapter.contextSchema
2470
- callbackWhenContextIsReady(newContext);
2471
- },
2472
- setDisconnectedCallback(disconnectCallback) {
2473
- // adds this callback into the disconnect bucket so it gets disconnected from parent
2474
- // the the element hosting the wire is disconnected
2475
- ArrayPush$1.call(wiredDisconnecting, disconnectCallback);
2476
- }
2324
+ const { adapter } = wireDef;
2325
+ const adapterContextToken = getAdapterToken(adapter);
2326
+ if (isUndefined$1(adapterContextToken)) {
2327
+ return; // no provider found, nothing to be done
2328
+ }
2329
+ const { elm, context: { wiredConnecting, wiredDisconnecting }, renderer: { dispatchEvent }, } = vm;
2330
+ // waiting for the component to be connected to formally request the context via the token
2331
+ ArrayPush$1.call(wiredConnecting, () => {
2332
+ // This event is responsible for connecting the host element with another
2333
+ // element in the composed path that is providing contextual data. The provider
2334
+ // must be listening for a special dom event with the name corresponding to the value of
2335
+ // `adapterContextToken`, which will remain secret and internal to this file only to
2336
+ // guarantee that the linkage can be forged.
2337
+ const contextRegistrationEvent = new WireContextRegistrationEvent(adapterContextToken, {
2338
+ setNewContext(newContext) {
2339
+ // eslint-disable-next-line @lwc/lwc-internal/no-invalid-todo
2340
+ // TODO: dev-mode validation of config based on the adapter.contextSchema
2341
+ callbackWhenContextIsReady(newContext);
2342
+ },
2343
+ setDisconnectedCallback(disconnectCallback) {
2344
+ // adds this callback into the disconnect bucket so it gets disconnected from parent
2345
+ // the the element hosting the wire is disconnected
2346
+ ArrayPush$1.call(wiredDisconnecting, disconnectCallback);
2347
+ },
2348
+ });
2349
+ dispatchEvent(elm, contextRegistrationEvent);
2477
2350
  });
2478
- dispatchEvent(elm, contextRegistrationEvent);
2479
- });
2480
2351
  }
2481
2352
  function createConnector(vm, name, wireDef) {
2482
- const {
2483
- method,
2484
- adapter,
2485
- configCallback,
2486
- dynamic
2487
- } = wireDef;
2488
- let debugInfo;
2489
- if (process.env.NODE_ENV !== 'production') {
2490
- const wiredPropOrMethod = isUndefined$1(method) ? name : method.name;
2491
- debugInfo = create(null);
2492
- debugInfo.wasDataProvisionedForConfig = false;
2493
- vm.debugInfo[WIRE_DEBUG_ENTRY][wiredPropOrMethod] = debugInfo;
2494
- }
2495
- const fieldOrMethodCallback = isUndefined$1(method) ? createFieldDataCallback(vm, name) : createMethodDataCallback(vm, method);
2496
- const dataCallback = value => {
2353
+ const { method, adapter, configCallback, dynamic } = wireDef;
2354
+ let debugInfo;
2497
2355
  if (process.env.NODE_ENV !== 'production') {
2498
- debugInfo.data = value;
2499
- // Note: most of the time, the data provided is for the current config, but there may be
2500
- // some conditions in which it does not, ex:
2501
- // race conditions in a poor network while the adapter does not cancel a previous request.
2502
- debugInfo.wasDataProvisionedForConfig = true;
2503
- }
2504
- fieldOrMethodCallback(value);
2505
- };
2506
- let context;
2507
- let connector;
2508
- // Workaround to pass the component element associated to this wire adapter instance.
2509
- defineProperty(dataCallback, DeprecatedWiredElementHost, {
2510
- value: vm.elm
2511
- });
2512
- defineProperty(dataCallback, DeprecatedWiredParamsMeta, {
2513
- value: dynamic
2514
- });
2515
- runWithBoundaryProtection(vm, vm, noop, () => {
2516
- // job
2517
- connector = new adapter(dataCallback);
2518
- }, noop);
2519
- const updateConnectorConfig = config => {
2520
- // every time the config is recomputed due to tracking,
2521
- // this callback will be invoked with the new computed config
2522
- runWithBoundaryProtection(vm, vm, noop, () => {
2523
- // job
2524
- if (process.env.NODE_ENV !== 'production') {
2525
- debugInfo.config = config;
2526
- debugInfo.context = context;
2356
+ const wiredPropOrMethod = isUndefined$1(method) ? name : method.name;
2357
+ debugInfo = create(null);
2527
2358
  debugInfo.wasDataProvisionedForConfig = false;
2528
- }
2529
- connector.update(config, context);
2530
- }, noop);
2531
- };
2532
- // Computes the current wire config and calls the update method on the wire adapter.
2533
- // If it has params, we will need to observe changes in the next tick.
2534
- const {
2535
- computeConfigAndUpdate,
2536
- ro
2537
- } = createConfigWatcher(vm.component, configCallback, updateConnectorConfig);
2538
- // if the adapter needs contextualization, we need to watch for new context and push it alongside the config
2539
- if (!isUndefined$1(adapter.contextSchema)) {
2540
- createContextWatcher(vm, wireDef, newContext => {
2541
- // every time the context is pushed into this component,
2542
- // this callback will be invoked with the new computed context
2543
- if (context !== newContext) {
2544
- context = newContext;
2545
- // Note: when new context arrives, the config will be recomputed and pushed along side the new
2546
- // context, this is to preserve the identity characteristics, config should not have identity
2547
- // (ever), while context can have identity
2548
- if (vm.state === 1 /* VMState.connected */) {
2549
- computeConfigAndUpdate();
2550
- }
2551
- }
2359
+ vm.debugInfo[WIRE_DEBUG_ENTRY][wiredPropOrMethod] = debugInfo;
2360
+ }
2361
+ const fieldOrMethodCallback = isUndefined$1(method)
2362
+ ? createFieldDataCallback(vm, name)
2363
+ : createMethodDataCallback(vm, method);
2364
+ const dataCallback = (value) => {
2365
+ if (process.env.NODE_ENV !== 'production') {
2366
+ debugInfo.data = value;
2367
+ // Note: most of the time, the data provided is for the current config, but there may be
2368
+ // some conditions in which it does not, ex:
2369
+ // race conditions in a poor network while the adapter does not cancel a previous request.
2370
+ debugInfo.wasDataProvisionedForConfig = true;
2371
+ }
2372
+ fieldOrMethodCallback(value);
2373
+ };
2374
+ let context;
2375
+ let connector;
2376
+ // Workaround to pass the component element associated to this wire adapter instance.
2377
+ defineProperty(dataCallback, DeprecatedWiredElementHost, {
2378
+ value: vm.elm,
2379
+ });
2380
+ defineProperty(dataCallback, DeprecatedWiredParamsMeta, {
2381
+ value: dynamic,
2552
2382
  });
2553
- }
2554
- return {
2555
- // @ts-ignore the boundary protection executes sync, connector is always defined
2556
- connector,
2557
- computeConfigAndUpdate,
2558
- resetConfigWatcher: () => ro.reset()
2559
- };
2383
+ runWithBoundaryProtection(vm, vm, noop, () => {
2384
+ // job
2385
+ connector = new adapter(dataCallback);
2386
+ }, noop);
2387
+ const updateConnectorConfig = (config) => {
2388
+ // every time the config is recomputed due to tracking,
2389
+ // this callback will be invoked with the new computed config
2390
+ runWithBoundaryProtection(vm, vm, noop, () => {
2391
+ // job
2392
+ if (process.env.NODE_ENV !== 'production') {
2393
+ debugInfo.config = config;
2394
+ debugInfo.context = context;
2395
+ debugInfo.wasDataProvisionedForConfig = false;
2396
+ }
2397
+ connector.update(config, context);
2398
+ }, noop);
2399
+ };
2400
+ // Computes the current wire config and calls the update method on the wire adapter.
2401
+ // If it has params, we will need to observe changes in the next tick.
2402
+ const { computeConfigAndUpdate, ro } = createConfigWatcher(vm.component, configCallback, updateConnectorConfig);
2403
+ // if the adapter needs contextualization, we need to watch for new context and push it alongside the config
2404
+ if (!isUndefined$1(adapter.contextSchema)) {
2405
+ createContextWatcher(vm, wireDef, (newContext) => {
2406
+ // every time the context is pushed into this component,
2407
+ // this callback will be invoked with the new computed context
2408
+ if (context !== newContext) {
2409
+ context = newContext;
2410
+ // Note: when new context arrives, the config will be recomputed and pushed along side the new
2411
+ // context, this is to preserve the identity characteristics, config should not have identity
2412
+ // (ever), while context can have identity
2413
+ if (vm.state === 1 /* VMState.connected */) {
2414
+ computeConfigAndUpdate();
2415
+ }
2416
+ }
2417
+ });
2418
+ }
2419
+ return {
2420
+ // @ts-ignore the boundary protection executes sync, connector is always defined
2421
+ connector,
2422
+ computeConfigAndUpdate,
2423
+ resetConfigWatcher: () => ro.reset(),
2424
+ };
2560
2425
  }
2561
2426
  const AdapterToTokenMap = new Map();
2562
2427
  function getAdapterToken(adapter) {
2563
- return AdapterToTokenMap.get(adapter);
2428
+ return AdapterToTokenMap.get(adapter);
2564
2429
  }
2565
2430
  function setAdapterToken(adapter, token) {
2566
- AdapterToTokenMap.set(adapter, token);
2431
+ AdapterToTokenMap.set(adapter, token);
2567
2432
  }
2568
2433
  function storeWiredMethodMeta(descriptor, adapter, configCallback, dynamic) {
2569
- // support for callable adapters
2570
- if (adapter.adapter) {
2571
- adapter = adapter.adapter;
2572
- }
2573
- const method = descriptor.value;
2574
- const def = {
2575
- adapter,
2576
- method,
2577
- configCallback,
2578
- dynamic
2579
- };
2580
- WireMetaMap.set(descriptor, def);
2434
+ // support for callable adapters
2435
+ if (adapter.adapter) {
2436
+ adapter = adapter.adapter;
2437
+ }
2438
+ const method = descriptor.value;
2439
+ const def = {
2440
+ adapter,
2441
+ method,
2442
+ configCallback,
2443
+ dynamic,
2444
+ };
2445
+ WireMetaMap.set(descriptor, def);
2581
2446
  }
2582
2447
  function storeWiredFieldMeta(descriptor, adapter, configCallback, dynamic) {
2583
- // support for callable adapters
2584
- if (adapter.adapter) {
2585
- adapter = adapter.adapter;
2586
- }
2587
- const def = {
2588
- adapter,
2589
- configCallback,
2590
- dynamic
2591
- };
2592
- WireMetaMap.set(descriptor, def);
2448
+ // support for callable adapters
2449
+ if (adapter.adapter) {
2450
+ adapter = adapter.adapter;
2451
+ }
2452
+ const def = {
2453
+ adapter,
2454
+ configCallback,
2455
+ dynamic,
2456
+ };
2457
+ WireMetaMap.set(descriptor, def);
2593
2458
  }
2594
2459
  function installWireAdapters(vm) {
2595
- const {
2596
- context,
2597
- def: {
2598
- wire
2599
- }
2600
- } = vm;
2601
- if (process.env.NODE_ENV !== 'production') {
2602
- vm.debugInfo[WIRE_DEBUG_ENTRY] = create(null);
2603
- }
2604
- const wiredConnecting = context.wiredConnecting = [];
2605
- const wiredDisconnecting = context.wiredDisconnecting = [];
2606
- for (const fieldNameOrMethod in wire) {
2607
- const descriptor = wire[fieldNameOrMethod];
2608
- const wireDef = WireMetaMap.get(descriptor);
2460
+ const { context, def: { wire }, } = vm;
2609
2461
  if (process.env.NODE_ENV !== 'production') {
2610
- assert.invariant(wireDef, `Internal Error: invalid wire definition found.`);
2462
+ vm.debugInfo[WIRE_DEBUG_ENTRY] = create(null);
2611
2463
  }
2612
- if (!isUndefined$1(wireDef)) {
2613
- const {
2614
- connector,
2615
- computeConfigAndUpdate,
2616
- resetConfigWatcher
2617
- } = createConnector(vm, fieldNameOrMethod, wireDef);
2618
- const hasDynamicParams = wireDef.dynamic.length > 0;
2619
- ArrayPush$1.call(wiredConnecting, () => {
2620
- connector.connect();
2621
- if (!lwcRuntimeFlags.ENABLE_WIRE_SYNC_EMIT) {
2622
- if (hasDynamicParams) {
2623
- Promise.resolve().then(computeConfigAndUpdate);
2624
- return;
2625
- }
2464
+ const wiredConnecting = (context.wiredConnecting = []);
2465
+ const wiredDisconnecting = (context.wiredDisconnecting = []);
2466
+ for (const fieldNameOrMethod in wire) {
2467
+ const descriptor = wire[fieldNameOrMethod];
2468
+ const wireDef = WireMetaMap.get(descriptor);
2469
+ if (process.env.NODE_ENV !== 'production') {
2470
+ assert.invariant(wireDef, `Internal Error: invalid wire definition found.`);
2471
+ }
2472
+ if (!isUndefined$1(wireDef)) {
2473
+ const { connector, computeConfigAndUpdate, resetConfigWatcher } = createConnector(vm, fieldNameOrMethod, wireDef);
2474
+ const hasDynamicParams = wireDef.dynamic.length > 0;
2475
+ ArrayPush$1.call(wiredConnecting, () => {
2476
+ connector.connect();
2477
+ if (!lwcRuntimeFlags.ENABLE_WIRE_SYNC_EMIT) {
2478
+ if (hasDynamicParams) {
2479
+ Promise.resolve().then(computeConfigAndUpdate);
2480
+ return;
2481
+ }
2482
+ }
2483
+ computeConfigAndUpdate();
2484
+ });
2485
+ ArrayPush$1.call(wiredDisconnecting, () => {
2486
+ connector.disconnect();
2487
+ resetConfigWatcher();
2488
+ });
2626
2489
  }
2627
- computeConfigAndUpdate();
2628
- });
2629
- ArrayPush$1.call(wiredDisconnecting, () => {
2630
- connector.disconnect();
2631
- resetConfigWatcher();
2632
- });
2633
2490
  }
2634
- }
2635
2491
  }
2636
2492
  function connectWireAdapters(vm) {
2637
- const {
2638
- wiredConnecting
2639
- } = vm.context;
2640
- for (let i = 0, len = wiredConnecting.length; i < len; i += 1) {
2641
- wiredConnecting[i]();
2642
- }
2493
+ const { wiredConnecting } = vm.context;
2494
+ for (let i = 0, len = wiredConnecting.length; i < len; i += 1) {
2495
+ wiredConnecting[i]();
2496
+ }
2643
2497
  }
2644
2498
  function disconnectWireAdapters(vm) {
2645
- const {
2646
- wiredDisconnecting
2647
- } = vm.context;
2648
- runWithBoundaryProtection(vm, vm, noop, () => {
2649
- // job
2650
- for (let i = 0, len = wiredDisconnecting.length; i < len; i += 1) {
2651
- wiredDisconnecting[i]();
2652
- }
2653
- }, noop);
2499
+ const { wiredDisconnecting } = vm.context;
2500
+ runWithBoundaryProtection(vm, vm, noop, () => {
2501
+ // job
2502
+ for (let i = 0, len = wiredDisconnecting.length; i < len; i += 1) {
2503
+ wiredDisconnecting[i]();
2504
+ }
2505
+ }, noop);
2654
2506
  }
2655
2507
 
2656
2508
  /*
@@ -3090,145 +2942,136 @@ function sanitizeAttribute(tagName, namespaceUri, attrName, attrValue) {
3090
2942
  const cachedGetterByKey = create(null);
3091
2943
  const cachedSetterByKey = create(null);
3092
2944
  function createGetter(key) {
3093
- let fn = cachedGetterByKey[key];
3094
- if (isUndefined$1(fn)) {
3095
- fn = cachedGetterByKey[key] = function () {
3096
- const vm = getAssociatedVM(this);
3097
- const {
3098
- getHook
3099
- } = vm;
3100
- return getHook(vm.component, key);
3101
- };
3102
- }
3103
- return fn;
2945
+ let fn = cachedGetterByKey[key];
2946
+ if (isUndefined$1(fn)) {
2947
+ fn = cachedGetterByKey[key] = function () {
2948
+ const vm = getAssociatedVM(this);
2949
+ const { getHook } = vm;
2950
+ return getHook(vm.component, key);
2951
+ };
2952
+ }
2953
+ return fn;
3104
2954
  }
3105
2955
  function createSetter(key) {
3106
- let fn = cachedSetterByKey[key];
3107
- if (isUndefined$1(fn)) {
3108
- fn = cachedSetterByKey[key] = function (newValue) {
3109
- const vm = getAssociatedVM(this);
3110
- const {
3111
- setHook
3112
- } = vm;
3113
- newValue = getReadOnlyProxy(newValue);
3114
- setHook(vm.component, key, newValue);
3115
- };
3116
- }
3117
- return fn;
2956
+ let fn = cachedSetterByKey[key];
2957
+ if (isUndefined$1(fn)) {
2958
+ fn = cachedSetterByKey[key] = function (newValue) {
2959
+ const vm = getAssociatedVM(this);
2960
+ const { setHook } = vm;
2961
+ newValue = getReadOnlyProxy(newValue);
2962
+ setHook(vm.component, key, newValue);
2963
+ };
2964
+ }
2965
+ return fn;
3118
2966
  }
3119
2967
  function createMethodCaller(methodName) {
3120
- return function () {
3121
- const vm = getAssociatedVM(this);
3122
- const {
3123
- callHook,
3124
- component
3125
- } = vm;
3126
- const fn = component[methodName];
3127
- return callHook(vm.component, fn, ArraySlice.call(arguments));
3128
- };
2968
+ return function () {
2969
+ const vm = getAssociatedVM(this);
2970
+ const { callHook, component } = vm;
2971
+ const fn = component[methodName];
2972
+ return callHook(vm.component, fn, ArraySlice.call(arguments));
2973
+ };
3129
2974
  }
3130
2975
  function createAttributeChangedCallback(attributeToPropMap, superAttributeChangedCallback) {
3131
- return function attributeChangedCallback(attrName, oldValue, newValue) {
3132
- if (oldValue === newValue) {
3133
- // Ignore same values.
3134
- return;
3135
- }
3136
- const propName = attributeToPropMap[attrName];
3137
- if (isUndefined$1(propName)) {
3138
- if (!isUndefined$1(superAttributeChangedCallback)) {
3139
- // delegate unknown attributes to the super.
3140
- // Typescript does not like it when you treat the `arguments` object as an array
3141
- // @ts-ignore type-mismatch
3142
- superAttributeChangedCallback.apply(this, arguments);
3143
- }
3144
- return;
3145
- }
3146
- if (!isAttributeLocked(this, attrName)) {
3147
- // Ignore changes triggered by the engine itself during:
3148
- // * diffing when public props are attempting to reflect to the DOM
3149
- // * component via `this.setAttribute()`, should never update the prop
3150
- // Both cases, the setAttribute call is always wrapped by the unlocking of the
3151
- // attribute to be changed
3152
- return;
3153
- }
3154
- // Reflect attribute change to the corresponding property when changed from outside.
3155
- this[propName] = newValue;
3156
- };
2976
+ return function attributeChangedCallback(attrName, oldValue, newValue) {
2977
+ if (oldValue === newValue) {
2978
+ // Ignore same values.
2979
+ return;
2980
+ }
2981
+ const propName = attributeToPropMap[attrName];
2982
+ if (isUndefined$1(propName)) {
2983
+ if (!isUndefined$1(superAttributeChangedCallback)) {
2984
+ // delegate unknown attributes to the super.
2985
+ // Typescript does not like it when you treat the `arguments` object as an array
2986
+ // @ts-ignore type-mismatch
2987
+ superAttributeChangedCallback.apply(this, arguments);
2988
+ }
2989
+ return;
2990
+ }
2991
+ if (!isAttributeLocked(this, attrName)) {
2992
+ // Ignore changes triggered by the engine itself during:
2993
+ // * diffing when public props are attempting to reflect to the DOM
2994
+ // * component via `this.setAttribute()`, should never update the prop
2995
+ // Both cases, the setAttribute call is always wrapped by the unlocking of the
2996
+ // attribute to be changed
2997
+ return;
2998
+ }
2999
+ // Reflect attribute change to the corresponding property when changed from outside.
3000
+ this[propName] = newValue;
3001
+ };
3157
3002
  }
3158
3003
  function HTMLBridgeElementFactory(SuperClass, props, methods) {
3159
- let HTMLBridgeElement;
3160
- /**
3161
- * Modern browsers will have all Native Constructors as regular Classes
3162
- * and must be instantiated with the new keyword. In older browsers,
3163
- * specifically IE11, those are objects with a prototype property defined,
3164
- * since they are not supposed to be extended or instantiated with the
3165
- * new keyword. This forking logic supports both cases, specifically because
3166
- * wc.ts relies on the construction path of the bridges to create new
3167
- * fully qualifying web components.
3168
- */
3169
- if (isFunction$1(SuperClass)) {
3170
- HTMLBridgeElement = class extends SuperClass {};
3171
- } else {
3172
- HTMLBridgeElement = function () {
3173
- // Bridge classes are not supposed to be instantiated directly in
3174
- // browsers that do not support web components.
3175
- throw new TypeError('Illegal constructor');
3004
+ let HTMLBridgeElement;
3005
+ /**
3006
+ * Modern browsers will have all Native Constructors as regular Classes
3007
+ * and must be instantiated with the new keyword. In older browsers,
3008
+ * specifically IE11, those are objects with a prototype property defined,
3009
+ * since they are not supposed to be extended or instantiated with the
3010
+ * new keyword. This forking logic supports both cases, specifically because
3011
+ * wc.ts relies on the construction path of the bridges to create new
3012
+ * fully qualifying web components.
3013
+ */
3014
+ if (isFunction$1(SuperClass)) {
3015
+ HTMLBridgeElement = class extends SuperClass {
3016
+ };
3017
+ }
3018
+ else {
3019
+ HTMLBridgeElement = function () {
3020
+ // Bridge classes are not supposed to be instantiated directly in
3021
+ // browsers that do not support web components.
3022
+ throw new TypeError('Illegal constructor');
3023
+ };
3024
+ // prototype inheritance dance
3025
+ setPrototypeOf(HTMLBridgeElement, SuperClass);
3026
+ setPrototypeOf(HTMLBridgeElement.prototype, SuperClass.prototype);
3027
+ defineProperty(HTMLBridgeElement.prototype, 'constructor', {
3028
+ writable: true,
3029
+ configurable: true,
3030
+ value: HTMLBridgeElement,
3031
+ });
3032
+ }
3033
+ // generating the hash table for attributes to avoid duplicate fields and facilitate validation
3034
+ // and false positives in case of inheritance.
3035
+ const attributeToPropMap = create(null);
3036
+ const { attributeChangedCallback: superAttributeChangedCallback } = SuperClass.prototype;
3037
+ const { observedAttributes: superObservedAttributes = [] } = SuperClass;
3038
+ const descriptors = create(null);
3039
+ // expose getters and setters for each public props on the new Element Bridge
3040
+ for (let i = 0, len = props.length; i < len; i += 1) {
3041
+ const propName = props[i];
3042
+ attributeToPropMap[htmlPropertyToAttribute(propName)] = propName;
3043
+ descriptors[propName] = {
3044
+ get: createGetter(propName),
3045
+ set: createSetter(propName),
3046
+ enumerable: true,
3047
+ configurable: true,
3048
+ };
3049
+ }
3050
+ // expose public methods as props on the new Element Bridge
3051
+ for (let i = 0, len = methods.length; i < len; i += 1) {
3052
+ const methodName = methods[i];
3053
+ descriptors[methodName] = {
3054
+ value: createMethodCaller(methodName),
3055
+ writable: true,
3056
+ configurable: true,
3057
+ };
3058
+ }
3059
+ // creating a new attributeChangedCallback per bridge because they are bound to the corresponding
3060
+ // map of attributes to props. We do this after all other props and methods to avoid the possibility
3061
+ // of getting overrule by a class declaration in user-land, and we make it non-writable, non-configurable
3062
+ // to preserve this definition.
3063
+ descriptors.attributeChangedCallback = {
3064
+ value: createAttributeChangedCallback(attributeToPropMap, superAttributeChangedCallback),
3176
3065
  };
3177
- // prototype inheritance dance
3178
- setPrototypeOf(HTMLBridgeElement, SuperClass);
3179
- setPrototypeOf(HTMLBridgeElement.prototype, SuperClass.prototype);
3180
- defineProperty(HTMLBridgeElement.prototype, 'constructor', {
3181
- writable: true,
3182
- configurable: true,
3183
- value: HTMLBridgeElement
3066
+ // Specify attributes for which we want to reflect changes back to their corresponding
3067
+ // properties via attributeChangedCallback.
3068
+ defineProperty(HTMLBridgeElement, 'observedAttributes', {
3069
+ get() {
3070
+ return [...superObservedAttributes, ...keys(attributeToPropMap)];
3071
+ },
3184
3072
  });
3185
- }
3186
- // generating the hash table for attributes to avoid duplicate fields and facilitate validation
3187
- // and false positives in case of inheritance.
3188
- const attributeToPropMap = create(null);
3189
- const {
3190
- attributeChangedCallback: superAttributeChangedCallback
3191
- } = SuperClass.prototype;
3192
- const {
3193
- observedAttributes: superObservedAttributes = []
3194
- } = SuperClass;
3195
- const descriptors = create(null);
3196
- // expose getters and setters for each public props on the new Element Bridge
3197
- for (let i = 0, len = props.length; i < len; i += 1) {
3198
- const propName = props[i];
3199
- attributeToPropMap[htmlPropertyToAttribute(propName)] = propName;
3200
- descriptors[propName] = {
3201
- get: createGetter(propName),
3202
- set: createSetter(propName),
3203
- enumerable: true,
3204
- configurable: true
3205
- };
3206
- }
3207
- // expose public methods as props on the new Element Bridge
3208
- for (let i = 0, len = methods.length; i < len; i += 1) {
3209
- const methodName = methods[i];
3210
- descriptors[methodName] = {
3211
- value: createMethodCaller(methodName),
3212
- writable: true,
3213
- configurable: true
3214
- };
3215
- }
3216
- // creating a new attributeChangedCallback per bridge because they are bound to the corresponding
3217
- // map of attributes to props. We do this after all other props and methods to avoid the possibility
3218
- // of getting overrule by a class declaration in user-land, and we make it non-writable, non-configurable
3219
- // to preserve this definition.
3220
- descriptors.attributeChangedCallback = {
3221
- value: createAttributeChangedCallback(attributeToPropMap, superAttributeChangedCallback)
3222
- };
3223
- // Specify attributes for which we want to reflect changes back to their corresponding
3224
- // properties via attributeChangedCallback.
3225
- defineProperty(HTMLBridgeElement, 'observedAttributes', {
3226
- get() {
3227
- return [...superObservedAttributes, ...keys(attributeToPropMap)];
3228
- }
3229
- });
3230
- defineProperties(HTMLBridgeElement.prototype, descriptors);
3231
- return HTMLBridgeElement;
3073
+ defineProperties(HTMLBridgeElement.prototype, descriptors);
3074
+ return HTMLBridgeElement;
3232
3075
  }
3233
3076
  const BaseBridgeElement = HTMLBridgeElementFactory(HTMLElementConstructor, getOwnPropertyNames$1(HTMLElementOriginalDescriptors), []);
3234
3077
  freeze(BaseBridgeElement);
@@ -3548,157 +3391,137 @@ function getComponentDef(Ctor) {
3548
3391
  * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
3549
3392
  */
3550
3393
  function makeHostToken(token) {
3551
- return `${token}-host`;
3394
+ return `${token}-host`;
3552
3395
  }
3553
3396
  function createInlineStyleVNode(content) {
3554
- return api.h('style', {
3555
- key: 'style',
3556
- attrs: {
3557
- type: 'text/css'
3558
- }
3559
- }, [api.t(content)]);
3397
+ return api.h('style', {
3398
+ key: 'style',
3399
+ attrs: {
3400
+ type: 'text/css',
3401
+ },
3402
+ }, [api.t(content)]);
3560
3403
  }
3561
3404
  function updateStylesheetToken(vm, template) {
3562
- const {
3563
- elm,
3564
- context,
3565
- renderMode,
3566
- shadowMode,
3567
- renderer: {
3568
- getClassList,
3569
- removeAttribute,
3570
- setAttribute
3571
- }
3572
- } = vm;
3573
- const {
3574
- stylesheets: newStylesheets,
3575
- stylesheetToken: newStylesheetToken
3576
- } = template;
3577
- const {
3578
- stylesheets: newVmStylesheets
3579
- } = vm;
3580
- const isSyntheticShadow = renderMode === 1 /* RenderMode.Shadow */ && shadowMode === 1 /* ShadowMode.Synthetic */;
3581
- const {
3582
- hasScopedStyles
3583
- } = context;
3584
- let newToken;
3585
- let newHasTokenInClass;
3586
- let newHasTokenInAttribute;
3587
- // Reset the styling token applied to the host element.
3588
- const {
3589
- stylesheetToken: oldToken,
3590
- hasTokenInClass: oldHasTokenInClass,
3591
- hasTokenInAttribute: oldHasTokenInAttribute
3592
- } = context;
3593
- if (!isUndefined$1(oldToken)) {
3594
- if (oldHasTokenInClass) {
3595
- getClassList(elm).remove(makeHostToken(oldToken));
3596
- }
3597
- if (oldHasTokenInAttribute) {
3598
- removeAttribute(elm, makeHostToken(oldToken));
3599
- }
3600
- }
3601
- // Apply the new template styling token to the host element, if the new template has any
3602
- // associated stylesheets. In the case of light DOM, also ensure there is at least one scoped stylesheet.
3603
- const hasNewStylesheets = hasStyles(newStylesheets);
3604
- const hasNewVmStylesheets = hasStyles(newVmStylesheets);
3605
- if (hasNewStylesheets || hasNewVmStylesheets) {
3606
- newToken = newStylesheetToken;
3607
- }
3608
- // Set the new styling token on the host element
3609
- if (!isUndefined$1(newToken)) {
3610
- if (hasScopedStyles) {
3611
- getClassList(elm).add(makeHostToken(newToken));
3612
- newHasTokenInClass = true;
3613
- }
3614
- if (isSyntheticShadow) {
3615
- setAttribute(elm, makeHostToken(newToken), '');
3616
- newHasTokenInAttribute = true;
3617
- }
3618
- }
3619
- // Update the styling tokens present on the context object.
3620
- context.stylesheetToken = newToken;
3621
- context.hasTokenInClass = newHasTokenInClass;
3622
- context.hasTokenInAttribute = newHasTokenInAttribute;
3405
+ const { elm, context, renderMode, shadowMode, renderer: { getClassList, removeAttribute, setAttribute }, } = vm;
3406
+ const { stylesheets: newStylesheets, stylesheetToken: newStylesheetToken } = template;
3407
+ const { stylesheets: newVmStylesheets } = vm;
3408
+ const isSyntheticShadow = renderMode === 1 /* RenderMode.Shadow */ && shadowMode === 1 /* ShadowMode.Synthetic */;
3409
+ const { hasScopedStyles } = context;
3410
+ let newToken;
3411
+ let newHasTokenInClass;
3412
+ let newHasTokenInAttribute;
3413
+ // Reset the styling token applied to the host element.
3414
+ const { stylesheetToken: oldToken, hasTokenInClass: oldHasTokenInClass, hasTokenInAttribute: oldHasTokenInAttribute, } = context;
3415
+ if (!isUndefined$1(oldToken)) {
3416
+ if (oldHasTokenInClass) {
3417
+ getClassList(elm).remove(makeHostToken(oldToken));
3418
+ }
3419
+ if (oldHasTokenInAttribute) {
3420
+ removeAttribute(elm, makeHostToken(oldToken));
3421
+ }
3422
+ }
3423
+ // Apply the new template styling token to the host element, if the new template has any
3424
+ // associated stylesheets. In the case of light DOM, also ensure there is at least one scoped stylesheet.
3425
+ const hasNewStylesheets = hasStyles(newStylesheets);
3426
+ const hasNewVmStylesheets = hasStyles(newVmStylesheets);
3427
+ if (hasNewStylesheets || hasNewVmStylesheets) {
3428
+ newToken = newStylesheetToken;
3429
+ }
3430
+ // Set the new styling token on the host element
3431
+ if (!isUndefined$1(newToken)) {
3432
+ if (hasScopedStyles) {
3433
+ getClassList(elm).add(makeHostToken(newToken));
3434
+ newHasTokenInClass = true;
3435
+ }
3436
+ if (isSyntheticShadow) {
3437
+ setAttribute(elm, makeHostToken(newToken), '');
3438
+ newHasTokenInAttribute = true;
3439
+ }
3440
+ }
3441
+ // Update the styling tokens present on the context object.
3442
+ context.stylesheetToken = newToken;
3443
+ context.hasTokenInClass = newHasTokenInClass;
3444
+ context.hasTokenInAttribute = newHasTokenInAttribute;
3623
3445
  }
3624
3446
  function evaluateStylesheetsContent(stylesheets, stylesheetToken, vm) {
3625
- const content = [];
3626
- let root;
3627
- for (let i = 0; i < stylesheets.length; i++) {
3628
- let stylesheet = stylesheets[i];
3629
- if (isArray$1(stylesheet)) {
3630
- ArrayPush$1.apply(content, evaluateStylesheetsContent(stylesheet, stylesheetToken, vm));
3631
- } else {
3632
- if (process.env.NODE_ENV !== 'production') {
3633
- // Check for compiler version mismatch in dev mode only
3634
- checkVersionMismatch(stylesheet, 'stylesheet');
3635
- // in dev-mode, we support hot swapping of stylesheet, which means that
3636
- // the component instance might be attempting to use an old version of
3637
- // the stylesheet, while internally, we have a replacement for it.
3638
- stylesheet = getStyleOrSwappedStyle(stylesheet);
3639
- }
3640
- const isScopedCss = stylesheet[KEY__SCOPED_CSS];
3641
- if (lwcRuntimeFlags.DISABLE_LIGHT_DOM_UNSCOPED_CSS) {
3642
- if (!isScopedCss && vm.renderMode === 0 /* RenderMode.Light */) {
3643
- logError('Unscoped CSS is not supported in Light DOM. Please use scoped CSS (*.scoped.css) instead of unscoped CSS (*.css).');
3644
- continue;
3645
- }
3646
- }
3647
- // Apply the scope token only if the stylesheet itself is scoped, or if we're rendering synthetic shadow.
3648
- const scopeToken = isScopedCss || vm.shadowMode === 1 /* ShadowMode.Synthetic */ && vm.renderMode === 1 /* RenderMode.Shadow */ ? stylesheetToken : undefined;
3649
- // Use the actual `:host` selector if we're rendering global CSS for light DOM, or if we're rendering
3650
- // native shadow DOM. Synthetic shadow DOM never uses `:host`.
3651
- const useActualHostSelector = vm.renderMode === 0 /* RenderMode.Light */ ? !isScopedCss : vm.shadowMode === 0 /* ShadowMode.Native */;
3652
- // Use the native :dir() pseudoclass only in native shadow DOM. Otherwise, in synthetic shadow,
3653
- // we use an attribute selector on the host to simulate :dir().
3654
- let useNativeDirPseudoclass;
3655
- if (vm.renderMode === 1 /* RenderMode.Shadow */) {
3656
- useNativeDirPseudoclass = vm.shadowMode === 0 /* ShadowMode.Native */;
3657
- } else {
3658
- // Light DOM components should only render `[dir]` if they're inside of a synthetic shadow root.
3659
- // At the top level (root is null) or inside of a native shadow root, they should use `:dir()`.
3660
- if (isUndefined$1(root)) {
3661
- // Only calculate the root once as necessary
3662
- root = getNearestShadowComponent(vm);
3663
- }
3664
- useNativeDirPseudoclass = isNull(root) || root.shadowMode === 0 /* ShadowMode.Native */;
3665
- }
3666
-
3667
- ArrayPush$1.call(content, stylesheet(scopeToken, useActualHostSelector, useNativeDirPseudoclass));
3447
+ const content = [];
3448
+ let root;
3449
+ for (let i = 0; i < stylesheets.length; i++) {
3450
+ let stylesheet = stylesheets[i];
3451
+ if (isArray$1(stylesheet)) {
3452
+ ArrayPush$1.apply(content, evaluateStylesheetsContent(stylesheet, stylesheetToken, vm));
3453
+ }
3454
+ else {
3455
+ if (process.env.NODE_ENV !== 'production') {
3456
+ // Check for compiler version mismatch in dev mode only
3457
+ checkVersionMismatch(stylesheet, 'stylesheet');
3458
+ // in dev-mode, we support hot swapping of stylesheet, which means that
3459
+ // the component instance might be attempting to use an old version of
3460
+ // the stylesheet, while internally, we have a replacement for it.
3461
+ stylesheet = getStyleOrSwappedStyle(stylesheet);
3462
+ }
3463
+ const isScopedCss = stylesheet[KEY__SCOPED_CSS];
3464
+ if (lwcRuntimeFlags.DISABLE_LIGHT_DOM_UNSCOPED_CSS &&
3465
+ !isScopedCss &&
3466
+ vm.renderMode === 0 /* RenderMode.Light */) {
3467
+ logError('Unscoped CSS is not supported in Light DOM. Please use scoped CSS (*.scoped.css) instead of unscoped CSS (*.css).');
3468
+ continue;
3469
+ }
3470
+ // Apply the scope token only if the stylesheet itself is scoped, or if we're rendering synthetic shadow.
3471
+ const scopeToken = isScopedCss ||
3472
+ (vm.shadowMode === 1 /* ShadowMode.Synthetic */ && vm.renderMode === 1 /* RenderMode.Shadow */)
3473
+ ? stylesheetToken
3474
+ : undefined;
3475
+ // Use the actual `:host` selector if we're rendering global CSS for light DOM, or if we're rendering
3476
+ // native shadow DOM. Synthetic shadow DOM never uses `:host`.
3477
+ const useActualHostSelector = vm.renderMode === 0 /* RenderMode.Light */
3478
+ ? !isScopedCss
3479
+ : vm.shadowMode === 0 /* ShadowMode.Native */;
3480
+ // Use the native :dir() pseudoclass only in native shadow DOM. Otherwise, in synthetic shadow,
3481
+ // we use an attribute selector on the host to simulate :dir().
3482
+ let useNativeDirPseudoclass;
3483
+ if (vm.renderMode === 1 /* RenderMode.Shadow */) {
3484
+ useNativeDirPseudoclass = vm.shadowMode === 0 /* ShadowMode.Native */;
3485
+ }
3486
+ else {
3487
+ // Light DOM components should only render `[dir]` if they're inside of a synthetic shadow root.
3488
+ // At the top level (root is null) or inside of a native shadow root, they should use `:dir()`.
3489
+ if (isUndefined$1(root)) {
3490
+ // Only calculate the root once as necessary
3491
+ root = getNearestShadowComponent(vm);
3492
+ }
3493
+ useNativeDirPseudoclass = isNull(root) || root.shadowMode === 0 /* ShadowMode.Native */;
3494
+ }
3495
+ ArrayPush$1.call(content, stylesheet(scopeToken, useActualHostSelector, useNativeDirPseudoclass));
3496
+ }
3668
3497
  }
3669
- }
3670
- return content;
3498
+ return content;
3671
3499
  }
3672
3500
  function getStylesheetsContent(vm, template) {
3673
- const {
3674
- stylesheets,
3675
- stylesheetToken
3676
- } = template;
3677
- const {
3678
- stylesheets: vmStylesheets
3679
- } = vm;
3680
- let content = [];
3681
- if (hasStyles(stylesheets)) {
3682
- content = evaluateStylesheetsContent(stylesheets, stylesheetToken, vm);
3683
- }
3684
- // VM (component) stylesheets apply after template stylesheets
3685
- if (hasStyles(vmStylesheets)) {
3686
- ArrayPush$1.apply(content, evaluateStylesheetsContent(vmStylesheets, stylesheetToken, vm));
3687
- }
3688
- return content;
3501
+ const { stylesheets, stylesheetToken } = template;
3502
+ const { stylesheets: vmStylesheets } = vm;
3503
+ let content = [];
3504
+ if (hasStyles(stylesheets)) {
3505
+ content = evaluateStylesheetsContent(stylesheets, stylesheetToken, vm);
3506
+ }
3507
+ // VM (component) stylesheets apply after template stylesheets
3508
+ if (hasStyles(vmStylesheets)) {
3509
+ ArrayPush$1.apply(content, evaluateStylesheetsContent(vmStylesheets, stylesheetToken, vm));
3510
+ }
3511
+ return content;
3689
3512
  }
3690
3513
  // It might be worth caching this to avoid doing the lookup repeatedly, but
3691
3514
  // perf testing has not shown it to be a huge improvement yet:
3692
3515
  // https://github.com/salesforce/lwc/pull/2460#discussion_r691208892
3693
3516
  function getNearestShadowComponent(vm) {
3694
- let owner = vm;
3695
- while (!isNull(owner)) {
3696
- if (owner.renderMode === 1 /* RenderMode.Shadow */) {
3697
- return owner;
3517
+ let owner = vm;
3518
+ while (!isNull(owner)) {
3519
+ if (owner.renderMode === 1 /* RenderMode.Shadow */) {
3520
+ return owner;
3521
+ }
3522
+ owner = owner.owner;
3698
3523
  }
3699
- owner = owner.owner;
3700
- }
3701
- return owner;
3524
+ return owner;
3702
3525
  }
3703
3526
  /**
3704
3527
  * If the component that is currently being rendered uses scoped styles,
@@ -3706,32 +3529,24 @@ function getNearestShadowComponent(vm) {
3706
3529
  * it returns null.
3707
3530
  */
3708
3531
  function getScopeTokenClass(owner) {
3709
- const {
3710
- cmpTemplate,
3711
- context
3712
- } = owner;
3713
- return context.hasScopedStyles && (cmpTemplate === null || cmpTemplate === void 0 ? void 0 : cmpTemplate.stylesheetToken) || null;
3532
+ const { cmpTemplate, context } = owner;
3533
+ return (context.hasScopedStyles && (cmpTemplate === null || cmpTemplate === void 0 ? void 0 : cmpTemplate.stylesheetToken)) || null;
3714
3534
  }
3715
3535
  function createStylesheet(vm, stylesheets) {
3716
- const {
3717
- renderMode,
3718
- shadowMode,
3719
- renderer: {
3720
- insertStylesheet
3721
- }
3722
- } = vm;
3723
- if (renderMode === 1 /* RenderMode.Shadow */ && shadowMode === 1 /* ShadowMode.Synthetic */) {
3724
- for (let i = 0; i < stylesheets.length; i++) {
3725
- insertStylesheet(stylesheets[i]);
3536
+ const { renderMode, shadowMode, renderer: { insertStylesheet }, } = vm;
3537
+ if (renderMode === 1 /* RenderMode.Shadow */ && shadowMode === 1 /* ShadowMode.Synthetic */) {
3538
+ for (let i = 0; i < stylesheets.length; i++) {
3539
+ insertStylesheet(stylesheets[i]);
3540
+ }
3726
3541
  }
3727
- } else {
3728
- // Note: We need to ensure that during hydration, the stylesheets method is the same as those in ssr.
3729
- // This works in the client, because the stylesheets are created, and cached in the VM
3730
- // the first time the VM renders.
3731
- // native shadow or light DOM, SSR
3732
- return ArrayMap.call(stylesheets, createInlineStyleVNode);
3733
- }
3734
- return null;
3542
+ else {
3543
+ // Note: We need to ensure that during hydration, the stylesheets method is the same as those in ssr.
3544
+ // This works in the client, because the stylesheets are created, and cached in the VM
3545
+ // the first time the VM renders.
3546
+ // native shadow or light DOM, SSR
3547
+ return ArrayMap.call(stylesheets, createInlineStyleVNode);
3548
+ }
3549
+ return null;
3735
3550
  }
3736
3551
 
3737
3552
  /*
@@ -4039,496 +3854,433 @@ function applyStaticStyleAttribute(vnode, renderer) {
4039
3854
  * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
4040
3855
  */
4041
3856
  function patchChildren(c1, c2, parent, renderer) {
4042
- if (hasDynamicChildren(c2)) {
4043
- updateDynamicChildren(c1, c2, parent, renderer);
4044
- } else {
4045
- updateStaticChildren(c1, c2, parent, renderer);
4046
- }
3857
+ if (hasDynamicChildren(c2)) {
3858
+ updateDynamicChildren(c1, c2, parent, renderer);
3859
+ }
3860
+ else {
3861
+ updateStaticChildren(c1, c2, parent, renderer);
3862
+ }
4047
3863
  }
4048
3864
  function patch(n1, n2, parent, renderer) {
4049
- var _a, _b;
4050
- if (n1 === n2) {
4051
- return;
4052
- }
4053
- if (process.env.NODE_ENV !== 'production') {
4054
- if (!isSameVnode(n1, n2)) {
4055
- throw new Error('Expected these VNodes to be the same: ' + JSON.stringify({
4056
- sel: n1.sel,
4057
- key: n1.key
4058
- }) + ', ' + JSON.stringify({
4059
- sel: n2.sel,
4060
- key: n2.key
4061
- }));
4062
- }
4063
- }
4064
- switch (n2.type) {
4065
- case 0 /* VNodeType.Text */:
4066
- // VText has no special capability, fallback to the owner's renderer
4067
- patchText(n1, n2, renderer);
4068
- break;
4069
- case 1 /* VNodeType.Comment */:
4070
- // VComment has no special capability, fallback to the owner's renderer
4071
- patchComment(n1, n2, renderer);
4072
- break;
4073
- case 4 /* VNodeType.Static */:
4074
- n2.elm = n1.elm;
4075
- break;
4076
- case 5 /* VNodeType.Fragment */:
4077
- patchFragment(n1, n2, parent, renderer);
4078
- break;
4079
- case 2 /* VNodeType.Element */:
4080
- patchElement(n1, n2, (_a = n2.data.renderer) !== null && _a !== void 0 ? _a : renderer);
4081
- break;
4082
- case 3 /* VNodeType.CustomElement */:
4083
- patchCustomElement(n1, n2, parent, (_b = n2.data.renderer) !== null && _b !== void 0 ? _b : renderer);
4084
- break;
4085
- }
3865
+ var _a, _b;
3866
+ if (n1 === n2) {
3867
+ return;
3868
+ }
3869
+ if (process.env.NODE_ENV !== 'production') {
3870
+ if (!isSameVnode(n1, n2)) {
3871
+ throw new Error('Expected these VNodes to be the same: ' +
3872
+ JSON.stringify({ sel: n1.sel, key: n1.key }) +
3873
+ ', ' +
3874
+ JSON.stringify({ sel: n2.sel, key: n2.key }));
3875
+ }
3876
+ }
3877
+ switch (n2.type) {
3878
+ case 0 /* VNodeType.Text */:
3879
+ // VText has no special capability, fallback to the owner's renderer
3880
+ patchText(n1, n2, renderer);
3881
+ break;
3882
+ case 1 /* VNodeType.Comment */:
3883
+ // VComment has no special capability, fallback to the owner's renderer
3884
+ patchComment(n1, n2, renderer);
3885
+ break;
3886
+ case 4 /* VNodeType.Static */:
3887
+ n2.elm = n1.elm;
3888
+ break;
3889
+ case 5 /* VNodeType.Fragment */:
3890
+ patchFragment(n1, n2, parent, renderer);
3891
+ break;
3892
+ case 2 /* VNodeType.Element */:
3893
+ patchElement(n1, n2, (_a = n2.data.renderer) !== null && _a !== void 0 ? _a : renderer);
3894
+ break;
3895
+ case 3 /* VNodeType.CustomElement */:
3896
+ patchCustomElement(n1, n2, parent, (_b = n2.data.renderer) !== null && _b !== void 0 ? _b : renderer);
3897
+ break;
3898
+ }
4086
3899
  }
4087
3900
  function mount(node, parent, renderer, anchor) {
4088
- var _a, _b;
4089
- switch (node.type) {
4090
- case 0 /* VNodeType.Text */:
4091
- // VText has no special capability, fallback to the owner's renderer
4092
- mountText(node, parent, anchor, renderer);
4093
- break;
4094
- case 1 /* VNodeType.Comment */:
4095
- // VComment has no special capability, fallback to the owner's renderer
4096
- mountComment(node, parent, anchor, renderer);
4097
- break;
4098
- case 4 /* VNodeType.Static */:
4099
- // VStatic cannot have a custom renderer associated to them, using owner's renderer
4100
- mountStatic(node, parent, anchor, renderer);
4101
- break;
4102
- case 5 /* VNodeType.Fragment */:
4103
- mountFragment(node, parent, anchor, renderer);
4104
- break;
4105
- case 2 /* VNodeType.Element */:
4106
- // If the vnode data has a renderer override use it, else fallback to owner's renderer
4107
- mountElement(node, parent, anchor, (_a = node.data.renderer) !== null && _a !== void 0 ? _a : renderer);
4108
- break;
4109
- case 3 /* VNodeType.CustomElement */:
4110
- // If the vnode data has a renderer override use it, else fallback to owner's renderer
4111
- mountCustomElement(node, parent, anchor, (_b = node.data.renderer) !== null && _b !== void 0 ? _b : renderer);
4112
- break;
4113
- }
3901
+ var _a, _b;
3902
+ switch (node.type) {
3903
+ case 0 /* VNodeType.Text */:
3904
+ // VText has no special capability, fallback to the owner's renderer
3905
+ mountText(node, parent, anchor, renderer);
3906
+ break;
3907
+ case 1 /* VNodeType.Comment */:
3908
+ // VComment has no special capability, fallback to the owner's renderer
3909
+ mountComment(node, parent, anchor, renderer);
3910
+ break;
3911
+ case 4 /* VNodeType.Static */:
3912
+ // VStatic cannot have a custom renderer associated to them, using owner's renderer
3913
+ mountStatic(node, parent, anchor, renderer);
3914
+ break;
3915
+ case 5 /* VNodeType.Fragment */:
3916
+ mountFragment(node, parent, anchor, renderer);
3917
+ break;
3918
+ case 2 /* VNodeType.Element */:
3919
+ // If the vnode data has a renderer override use it, else fallback to owner's renderer
3920
+ mountElement(node, parent, anchor, (_a = node.data.renderer) !== null && _a !== void 0 ? _a : renderer);
3921
+ break;
3922
+ case 3 /* VNodeType.CustomElement */:
3923
+ // If the vnode data has a renderer override use it, else fallback to owner's renderer
3924
+ mountCustomElement(node, parent, anchor, (_b = node.data.renderer) !== null && _b !== void 0 ? _b : renderer);
3925
+ break;
3926
+ }
4114
3927
  }
4115
3928
  function patchText(n1, n2, renderer) {
4116
- n2.elm = n1.elm;
4117
- if (n2.text !== n1.text) {
4118
- updateTextContent(n2, renderer);
4119
- }
3929
+ n2.elm = n1.elm;
3930
+ if (n2.text !== n1.text) {
3931
+ updateTextContent(n2, renderer);
3932
+ }
4120
3933
  }
4121
3934
  function mountText(vnode, parent, anchor, renderer) {
4122
- const {
4123
- owner
4124
- } = vnode;
4125
- const {
4126
- createText
4127
- } = renderer;
4128
- const textNode = vnode.elm = createText(vnode.text);
4129
- linkNodeToShadow(textNode, owner, renderer);
4130
- insertNode(textNode, parent, anchor, renderer);
3935
+ const { owner } = vnode;
3936
+ const { createText } = renderer;
3937
+ const textNode = (vnode.elm = createText(vnode.text));
3938
+ linkNodeToShadow(textNode, owner, renderer);
3939
+ insertNode(textNode, parent, anchor, renderer);
4131
3940
  }
4132
3941
  function patchComment(n1, n2, renderer) {
4133
- n2.elm = n1.elm;
4134
- // FIXME: Comment nodes should be static, we shouldn't need to diff them together. However
4135
- // it is the case today.
4136
- if (n2.text !== n1.text) {
4137
- updateTextContent(n2, renderer);
4138
- }
3942
+ n2.elm = n1.elm;
3943
+ // FIXME: Comment nodes should be static, we shouldn't need to diff them together. However
3944
+ // it is the case today.
3945
+ if (n2.text !== n1.text) {
3946
+ updateTextContent(n2, renderer);
3947
+ }
4139
3948
  }
4140
3949
  function mountComment(vnode, parent, anchor, renderer) {
4141
- const {
4142
- owner
4143
- } = vnode;
4144
- const {
4145
- createComment
4146
- } = renderer;
4147
- const commentNode = vnode.elm = createComment(vnode.text);
4148
- linkNodeToShadow(commentNode, owner, renderer);
4149
- insertNode(commentNode, parent, anchor, renderer);
3950
+ const { owner } = vnode;
3951
+ const { createComment } = renderer;
3952
+ const commentNode = (vnode.elm = createComment(vnode.text));
3953
+ linkNodeToShadow(commentNode, owner, renderer);
3954
+ insertNode(commentNode, parent, anchor, renderer);
4150
3955
  }
4151
3956
  function mountFragment(vnode, parent, anchor, renderer) {
4152
- const {
4153
- children
4154
- } = vnode;
4155
- mountVNodes(children, parent, renderer, anchor);
4156
- // children of a fragment will always have at least the two delimiters.
4157
- vnode.elm = children[children.length - 1].elm;
3957
+ const { children } = vnode;
3958
+ mountVNodes(children, parent, renderer, anchor);
3959
+ // children of a fragment will always have at least the two delimiters.
3960
+ vnode.elm = children[children.length - 1].elm;
4158
3961
  }
4159
3962
  function patchFragment(n1, n2, parent, renderer) {
4160
- const {
4161
- children,
4162
- stable
4163
- } = n2;
4164
- if (stable) {
4165
- updateStaticChildren(n1.children, children, parent, renderer);
4166
- } else {
4167
- updateDynamicChildren(n1.children, children, parent, renderer);
4168
- }
4169
- // Note: not reusing n1.elm, because during patching, it may be patched with another text node.
4170
- n2.elm = children[children.length - 1].elm;
3963
+ const { children, stable } = n2;
3964
+ if (stable) {
3965
+ updateStaticChildren(n1.children, children, parent, renderer);
3966
+ }
3967
+ else {
3968
+ updateDynamicChildren(n1.children, children, parent, renderer);
3969
+ }
3970
+ // Note: not reusing n1.elm, because during patching, it may be patched with another text node.
3971
+ n2.elm = children[children.length - 1].elm;
4171
3972
  }
4172
3973
  function mountElement(vnode, parent, anchor, renderer) {
4173
- const {
4174
- sel,
4175
- owner,
4176
- data: {
4177
- svg
4178
- }
4179
- } = vnode;
4180
- const {
4181
- createElement
4182
- } = renderer;
4183
- const namespace = isTrue(svg) ? SVG_NAMESPACE : undefined;
4184
- const elm = vnode.elm = createElement(sel, namespace);
4185
- linkNodeToShadow(elm, owner, renderer);
4186
- applyStyleScoping(elm, owner, renderer);
4187
- applyDomManual(elm, vnode);
4188
- applyElementRestrictions(elm, vnode);
4189
- patchElementPropsAndAttrs$1(null, vnode, renderer);
4190
- insertNode(elm, parent, anchor, renderer);
4191
- mountVNodes(vnode.children, elm, renderer, null);
3974
+ const { sel, owner, data: { svg }, } = vnode;
3975
+ const { createElement } = renderer;
3976
+ const namespace = isTrue(svg) ? SVG_NAMESPACE : undefined;
3977
+ const elm = (vnode.elm = createElement(sel, namespace));
3978
+ linkNodeToShadow(elm, owner, renderer);
3979
+ applyStyleScoping(elm, owner, renderer);
3980
+ applyDomManual(elm, vnode);
3981
+ applyElementRestrictions(elm, vnode);
3982
+ patchElementPropsAndAttrs$1(null, vnode, renderer);
3983
+ insertNode(elm, parent, anchor, renderer);
3984
+ mountVNodes(vnode.children, elm, renderer, null);
4192
3985
  }
4193
3986
  function patchElement(n1, n2, renderer) {
4194
- const elm = n2.elm = n1.elm;
4195
- patchElementPropsAndAttrs$1(n1, n2, renderer);
4196
- patchChildren(n1.children, n2.children, elm, renderer);
3987
+ const elm = (n2.elm = n1.elm);
3988
+ patchElementPropsAndAttrs$1(n1, n2, renderer);
3989
+ patchChildren(n1.children, n2.children, elm, renderer);
4197
3990
  }
4198
3991
  function mountStatic(vnode, parent, anchor, renderer) {
4199
- const {
4200
- owner
4201
- } = vnode;
4202
- const {
4203
- cloneNode,
4204
- isSyntheticShadowDefined
4205
- } = renderer;
4206
- const elm = vnode.elm = cloneNode(vnode.fragment, true);
4207
- linkNodeToShadow(elm, owner, renderer);
4208
- applyElementRestrictions(elm, vnode);
4209
- // Marks this node as Static to propagate the shadow resolver. must happen after elm is assigned to the proper shadow
4210
- const {
4211
- renderMode,
4212
- shadowMode
4213
- } = owner;
4214
- if (isSyntheticShadowDefined) {
4215
- if (shadowMode === 1 /* ShadowMode.Synthetic */ || renderMode === 0 /* RenderMode.Light */) {
4216
- elm[KEY__SHADOW_STATIC] = true;
3992
+ const { owner } = vnode;
3993
+ const { cloneNode, isSyntheticShadowDefined } = renderer;
3994
+ const elm = (vnode.elm = cloneNode(vnode.fragment, true));
3995
+ linkNodeToShadow(elm, owner, renderer);
3996
+ applyElementRestrictions(elm, vnode);
3997
+ // Marks this node as Static to propagate the shadow resolver. must happen after elm is assigned to the proper shadow
3998
+ const { renderMode, shadowMode } = owner;
3999
+ if (isSyntheticShadowDefined) {
4000
+ if (shadowMode === 1 /* ShadowMode.Synthetic */ || renderMode === 0 /* RenderMode.Light */) {
4001
+ elm[KEY__SHADOW_STATIC] = true;
4002
+ }
4217
4003
  }
4218
- }
4219
- insertNode(elm, parent, anchor, renderer);
4004
+ insertNode(elm, parent, anchor, renderer);
4220
4005
  }
4221
4006
  function mountCustomElement(vnode, parent, anchor, renderer) {
4222
- const {
4223
- sel,
4224
- owner
4225
- } = vnode;
4226
- const {
4227
- createCustomElement
4228
- } = renderer;
4229
- /**
4230
- * Note: if the upgradable constructor does not expect, or throw when we new it
4231
- * with a callback as the first argument, we could implement a more advanced
4232
- * mechanism that only passes that argument if the constructor is known to be
4233
- * an upgradable custom element.
4234
- */
4235
- let vm;
4236
- const upgradeCallback = elm => {
4237
- // the custom element from the registry is expecting an upgrade callback
4238
- vm = createViewModelHook(elm, vnode, renderer);
4239
- };
4240
- let connectedCallback;
4241
- let disconnectedCallback;
4242
- if (lwcRuntimeFlags.ENABLE_NATIVE_CUSTOM_ELEMENT_LIFECYCLE) {
4243
- connectedCallback = elm => {
4244
- connectRootElement(elm);
4245
- };
4246
- disconnectedCallback = elm => {
4247
- disconnectRootElement(elm);
4007
+ const { sel, owner } = vnode;
4008
+ const { createCustomElement } = renderer;
4009
+ /**
4010
+ * Note: if the upgradable constructor does not expect, or throw when we new it
4011
+ * with a callback as the first argument, we could implement a more advanced
4012
+ * mechanism that only passes that argument if the constructor is known to be
4013
+ * an upgradable custom element.
4014
+ */
4015
+ let vm;
4016
+ const upgradeCallback = (elm) => {
4017
+ // the custom element from the registry is expecting an upgrade callback
4018
+ vm = createViewModelHook(elm, vnode, renderer);
4248
4019
  };
4249
- }
4250
- // Should never get a tag with upper case letter at this point; the compiler
4251
- // should produce only tags with lowercase letters. However, the Java
4252
- // compiler may generate tagnames with uppercase letters so - for backwards
4253
- // compatibility, we lower case the tagname here.
4254
- const normalizedTagname = sel.toLowerCase();
4255
- const elm = createCustomElement(normalizedTagname, upgradeCallback, connectedCallback, disconnectedCallback);
4256
- vnode.elm = elm;
4257
- vnode.vm = vm;
4258
- linkNodeToShadow(elm, owner, renderer);
4259
- applyStyleScoping(elm, owner, renderer);
4260
- if (vm) {
4261
- allocateChildren(vnode, vm);
4262
- }
4263
- patchElementPropsAndAttrs$1(null, vnode, renderer);
4264
- insertNode(elm, parent, anchor, renderer);
4265
- if (vm) {
4266
- {
4267
- // On the server, we don't have native custom element lifecycle callbacks, so we must
4268
- // manually invoke the connectedCallback for a child component.
4269
- runConnectedCallback(vm);
4020
+ let connectedCallback;
4021
+ let disconnectedCallback;
4022
+ if (lwcRuntimeFlags.ENABLE_NATIVE_CUSTOM_ELEMENT_LIFECYCLE) {
4023
+ connectedCallback = (elm) => {
4024
+ connectRootElement(elm);
4025
+ };
4026
+ disconnectedCallback = (elm) => {
4027
+ disconnectRootElement(elm);
4028
+ };
4029
+ }
4030
+ // Should never get a tag with upper case letter at this point; the compiler
4031
+ // should produce only tags with lowercase letters. However, the Java
4032
+ // compiler may generate tagnames with uppercase letters so - for backwards
4033
+ // compatibility, we lower case the tagname here.
4034
+ const normalizedTagname = sel.toLowerCase();
4035
+ const elm = createCustomElement(normalizedTagname, upgradeCallback, connectedCallback, disconnectedCallback);
4036
+ vnode.elm = elm;
4037
+ vnode.vm = vm;
4038
+ linkNodeToShadow(elm, owner, renderer);
4039
+ applyStyleScoping(elm, owner, renderer);
4040
+ if (vm) {
4041
+ allocateChildren(vnode, vm);
4042
+ }
4043
+ patchElementPropsAndAttrs$1(null, vnode, renderer);
4044
+ insertNode(elm, parent, anchor, renderer);
4045
+ if (vm) {
4046
+ {
4047
+ // On the server, we don't have native custom element lifecycle callbacks, so we must
4048
+ // manually invoke the connectedCallback for a child component.
4049
+ runConnectedCallback(vm);
4050
+ }
4051
+ }
4052
+ mountVNodes(vnode.children, elm, renderer, null);
4053
+ if (vm) {
4054
+ appendVM(vm);
4270
4055
  }
4271
- }
4272
- mountVNodes(vnode.children, elm, renderer, null);
4273
- if (vm) {
4274
- appendVM(vm);
4275
- }
4276
4056
  }
4277
4057
  function patchCustomElement(n1, n2, parent, renderer) {
4278
- if (n1.ctor !== n2.ctor) {
4279
- // If the constructor, unmount the current component and mount a new one using the new
4280
- // constructor.
4281
- const anchor = renderer.nextSibling(n1.elm);
4282
- unmount(n1, parent, renderer, true);
4283
- mountCustomElement(n2, parent, anchor, renderer);
4284
- } else {
4285
- // Otherwise patch the existing component with new props/attrs/etc.
4286
- const elm = n2.elm = n1.elm;
4287
- const vm = n2.vm = n1.vm;
4288
- patchElementPropsAndAttrs$1(n1, n2, renderer);
4289
- if (!isUndefined$1(vm)) {
4290
- // in fallback mode, the allocation will always set children to
4291
- // empty and delegate the real allocation to the slot elements
4292
- allocateChildren(n2, vm);
4293
- // Solves an edge case with slotted VFragments in native shadow mode.
4294
- //
4295
- // During allocation, in native shadow, slotted VFragment nodes are flattened and their text delimiters are removed
4296
- // to avoid interfering with native slot behavior. When this happens, if any of the fragments
4297
- // were not stable, the children must go through the dynamic diffing algo.
4298
- //
4299
- // If the new children (n2.children) contain no VFragments, but the previous children (n1.children) were dynamic,
4300
- // the new nodes must be marked dynamic so that all nodes are properly updated. The only indicator that the new
4301
- // nodes need to be dynamic comes from the previous children, so we check that to determine whether we need to
4302
- // mark the new children dynamic.
4303
- //
4304
- // Example:
4305
- // n1.children: [div, VFragment('', div, null, ''), div] => [div, div, null, div]; // marked dynamic
4306
- // n2.children: [div, null, div] => [div, null, div] // marked ???
4307
- const {
4308
- shadowMode,
4309
- renderMode
4310
- } = vm;
4311
- if (shadowMode == 0 /* ShadowMode.Native */ && renderMode !== 0 /* RenderMode.Light */ && hasDynamicChildren(n1.children)) {
4312
- // No-op if children has already been marked dynamic by 'allocateChildren()'.
4313
- markAsDynamicChildren(n2.children);
4314
- }
4315
- }
4316
- // in fallback mode, the children will be always empty, so, nothing
4317
- // will happen, but in native, it does allocate the light dom
4318
- patchChildren(n1.children, n2.children, elm, renderer);
4319
- if (!isUndefined$1(vm)) {
4320
- // this will probably update the shadowRoot, but only if the vm is in a dirty state
4321
- // this is important to preserve the top to bottom synchronous rendering phase.
4322
- rerenderVM(vm);
4058
+ if (n1.ctor !== n2.ctor) {
4059
+ // If the constructor, unmount the current component and mount a new one using the new
4060
+ // constructor.
4061
+ const anchor = renderer.nextSibling(n1.elm);
4062
+ unmount(n1, parent, renderer, true);
4063
+ mountCustomElement(n2, parent, anchor, renderer);
4064
+ }
4065
+ else {
4066
+ // Otherwise patch the existing component with new props/attrs/etc.
4067
+ const elm = (n2.elm = n1.elm);
4068
+ const vm = (n2.vm = n1.vm);
4069
+ patchElementPropsAndAttrs$1(n1, n2, renderer);
4070
+ if (!isUndefined$1(vm)) {
4071
+ // in fallback mode, the allocation will always set children to
4072
+ // empty and delegate the real allocation to the slot elements
4073
+ allocateChildren(n2, vm);
4074
+ // Solves an edge case with slotted VFragments in native shadow mode.
4075
+ //
4076
+ // During allocation, in native shadow, slotted VFragment nodes are flattened and their text delimiters are removed
4077
+ // to avoid interfering with native slot behavior. When this happens, if any of the fragments
4078
+ // were not stable, the children must go through the dynamic diffing algo.
4079
+ //
4080
+ // If the new children (n2.children) contain no VFragments, but the previous children (n1.children) were dynamic,
4081
+ // the new nodes must be marked dynamic so that all nodes are properly updated. The only indicator that the new
4082
+ // nodes need to be dynamic comes from the previous children, so we check that to determine whether we need to
4083
+ // mark the new children dynamic.
4084
+ //
4085
+ // Example:
4086
+ // n1.children: [div, VFragment('', div, null, ''), div] => [div, div, null, div]; // marked dynamic
4087
+ // n2.children: [div, null, div] => [div, null, div] // marked ???
4088
+ const { shadowMode, renderMode } = vm;
4089
+ if (shadowMode == 0 /* ShadowMode.Native */ &&
4090
+ renderMode !== 0 /* RenderMode.Light */ &&
4091
+ hasDynamicChildren(n1.children)) {
4092
+ // No-op if children has already been marked dynamic by 'allocateChildren()'.
4093
+ markAsDynamicChildren(n2.children);
4094
+ }
4095
+ }
4096
+ // in fallback mode, the children will be always empty, so, nothing
4097
+ // will happen, but in native, it does allocate the light dom
4098
+ patchChildren(n1.children, n2.children, elm, renderer);
4099
+ if (!isUndefined$1(vm)) {
4100
+ // this will probably update the shadowRoot, but only if the vm is in a dirty state
4101
+ // this is important to preserve the top to bottom synchronous rendering phase.
4102
+ rerenderVM(vm);
4103
+ }
4323
4104
  }
4324
- }
4325
4105
  }
4326
4106
  function mountVNodes(vnodes, parent, renderer, anchor, start = 0, end = vnodes.length) {
4327
- for (; start < end; ++start) {
4328
- const vnode = vnodes[start];
4329
- if (isVNode(vnode)) {
4330
- mount(vnode, parent, renderer, anchor);
4107
+ for (; start < end; ++start) {
4108
+ const vnode = vnodes[start];
4109
+ if (isVNode(vnode)) {
4110
+ mount(vnode, parent, renderer, anchor);
4111
+ }
4331
4112
  }
4332
- }
4333
4113
  }
4334
4114
  function unmount(vnode, parent, renderer, doRemove = false) {
4335
- const {
4336
- type,
4337
- elm,
4338
- sel
4339
- } = vnode;
4340
- // When unmounting a VNode subtree not all the elements have to removed from the DOM. The
4341
- // subtree root, is the only element worth unmounting from the subtree.
4342
- if (doRemove) {
4343
- if (type === 5 /* VNodeType.Fragment */) {
4344
- unmountVNodes(vnode.children, parent, renderer, doRemove);
4345
- } else {
4346
- // The vnode might or might not have a data.renderer associated to it
4347
- // but the removal used here is from the owner instead.
4348
- removeNode(elm, parent, renderer);
4349
- }
4350
- }
4351
- switch (type) {
4352
- case 2 /* VNodeType.Element */:
4353
- {
4354
- // Slot content is removed to trigger slotchange event when removing slot.
4355
- // Only required for synthetic shadow.
4356
- const shouldRemoveChildren = sel === 'slot' && vnode.owner.shadowMode === 1 /* ShadowMode.Synthetic */;
4357
- unmountVNodes(vnode.children, elm, renderer, shouldRemoveChildren);
4358
- break;
4359
- }
4360
- case 3 /* VNodeType.CustomElement */:
4361
- {
4362
- const {
4363
- vm
4364
- } = vnode;
4365
- // No need to unmount the children here, `removeVM` will take care of removing the
4366
- // children.
4367
- if (!isUndefined$1(vm)) {
4368
- removeVM(vm);
4115
+ const { type, elm, sel } = vnode;
4116
+ // When unmounting a VNode subtree not all the elements have to removed from the DOM. The
4117
+ // subtree root, is the only element worth unmounting from the subtree.
4118
+ if (doRemove) {
4119
+ if (type === 5 /* VNodeType.Fragment */) {
4120
+ unmountVNodes(vnode.children, parent, renderer, doRemove);
4121
+ }
4122
+ else {
4123
+ // The vnode might or might not have a data.renderer associated to it
4124
+ // but the removal used here is from the owner instead.
4125
+ removeNode(elm, parent, renderer);
4126
+ }
4127
+ }
4128
+ switch (type) {
4129
+ case 2 /* VNodeType.Element */: {
4130
+ // Slot content is removed to trigger slotchange event when removing slot.
4131
+ // Only required for synthetic shadow.
4132
+ const shouldRemoveChildren = sel === 'slot' && vnode.owner.shadowMode === 1 /* ShadowMode.Synthetic */;
4133
+ unmountVNodes(vnode.children, elm, renderer, shouldRemoveChildren);
4134
+ break;
4135
+ }
4136
+ case 3 /* VNodeType.CustomElement */: {
4137
+ const { vm } = vnode;
4138
+ // No need to unmount the children here, `removeVM` will take care of removing the
4139
+ // children.
4140
+ if (!isUndefined$1(vm)) {
4141
+ removeVM(vm);
4142
+ }
4369
4143
  }
4370
- }
4371
- }
4144
+ }
4372
4145
  }
4373
4146
  function unmountVNodes(vnodes, parent, renderer, doRemove = false, start = 0, end = vnodes.length) {
4374
- for (; start < end; ++start) {
4375
- const ch = vnodes[start];
4376
- if (isVNode(ch)) {
4377
- unmount(ch, parent, renderer, doRemove);
4147
+ for (; start < end; ++start) {
4148
+ const ch = vnodes[start];
4149
+ if (isVNode(ch)) {
4150
+ unmount(ch, parent, renderer, doRemove);
4151
+ }
4378
4152
  }
4379
- }
4380
4153
  }
4381
4154
  function isVNode(vnode) {
4382
- return vnode != null;
4155
+ return vnode != null;
4383
4156
  }
4384
4157
  function linkNodeToShadow(elm, owner, renderer) {
4385
- const {
4386
- renderRoot,
4387
- renderMode,
4388
- shadowMode
4389
- } = owner;
4390
- const {
4391
- isSyntheticShadowDefined
4392
- } = renderer;
4393
- // TODO [#1164]: this should eventually be done by the polyfill directly
4394
- if (isSyntheticShadowDefined) {
4395
- if (shadowMode === 1 /* ShadowMode.Synthetic */ || renderMode === 0 /* RenderMode.Light */) {
4396
- elm[KEY__SHADOW_RESOLVER] = renderRoot[KEY__SHADOW_RESOLVER];
4158
+ const { renderRoot, renderMode, shadowMode } = owner;
4159
+ const { isSyntheticShadowDefined } = renderer;
4160
+ // TODO [#1164]: this should eventually be done by the polyfill directly
4161
+ if (isSyntheticShadowDefined) {
4162
+ if (shadowMode === 1 /* ShadowMode.Synthetic */ || renderMode === 0 /* RenderMode.Light */) {
4163
+ elm[KEY__SHADOW_RESOLVER] = renderRoot[KEY__SHADOW_RESOLVER];
4164
+ }
4397
4165
  }
4398
- }
4399
4166
  }
4400
4167
  function updateTextContent(vnode, renderer) {
4401
- const {
4402
- elm,
4403
- text
4404
- } = vnode;
4405
- const {
4406
- setText
4407
- } = renderer;
4408
- if (process.env.NODE_ENV !== 'production') {
4409
- unlockDomMutation();
4410
- }
4411
- setText(elm, text);
4412
- if (process.env.NODE_ENV !== 'production') {
4413
- lockDomMutation();
4414
- }
4168
+ const { elm, text } = vnode;
4169
+ const { setText } = renderer;
4170
+ if (process.env.NODE_ENV !== 'production') {
4171
+ unlockDomMutation();
4172
+ }
4173
+ setText(elm, text);
4174
+ if (process.env.NODE_ENV !== 'production') {
4175
+ lockDomMutation();
4176
+ }
4415
4177
  }
4416
4178
  function insertNode(node, parent, anchor, renderer) {
4417
- if (process.env.NODE_ENV !== 'production') {
4418
- unlockDomMutation();
4419
- }
4420
- renderer.insert(node, parent, anchor);
4421
- if (process.env.NODE_ENV !== 'production') {
4422
- lockDomMutation();
4423
- }
4179
+ if (process.env.NODE_ENV !== 'production') {
4180
+ unlockDomMutation();
4181
+ }
4182
+ renderer.insert(node, parent, anchor);
4183
+ if (process.env.NODE_ENV !== 'production') {
4184
+ lockDomMutation();
4185
+ }
4424
4186
  }
4425
4187
  function removeNode(node, parent, renderer) {
4426
- if (process.env.NODE_ENV !== 'production') {
4427
- unlockDomMutation();
4428
- }
4429
- renderer.remove(node, parent);
4430
- if (process.env.NODE_ENV !== 'production') {
4431
- lockDomMutation();
4432
- }
4188
+ if (process.env.NODE_ENV !== 'production') {
4189
+ unlockDomMutation();
4190
+ }
4191
+ renderer.remove(node, parent);
4192
+ if (process.env.NODE_ENV !== 'production') {
4193
+ lockDomMutation();
4194
+ }
4433
4195
  }
4434
4196
  function patchElementPropsAndAttrs$1(oldVnode, vnode, renderer) {
4435
- if (isNull(oldVnode)) {
4436
- applyEventListeners(vnode, renderer);
4437
- applyStaticClassAttribute(vnode, renderer);
4438
- applyStaticStyleAttribute(vnode, renderer);
4439
- }
4440
- // Attrs need to be applied to element before props IE11 will wipe out value on radio inputs if
4441
- // value is set before type=radio.
4442
- patchClassAttribute(oldVnode, vnode, renderer);
4443
- patchStyleAttribute(oldVnode, vnode, renderer);
4444
- if (vnode.data.external) {
4445
- patchAttrUnlessProp(oldVnode, vnode, renderer);
4446
- } else {
4447
- patchAttributes(oldVnode, vnode, renderer);
4448
- }
4449
- patchProps(oldVnode, vnode, renderer);
4197
+ if (isNull(oldVnode)) {
4198
+ applyEventListeners(vnode, renderer);
4199
+ applyStaticClassAttribute(vnode, renderer);
4200
+ applyStaticStyleAttribute(vnode, renderer);
4201
+ }
4202
+ // Attrs need to be applied to element before props IE11 will wipe out value on radio inputs if
4203
+ // value is set before type=radio.
4204
+ patchClassAttribute(oldVnode, vnode, renderer);
4205
+ patchStyleAttribute(oldVnode, vnode, renderer);
4206
+ if (vnode.data.external) {
4207
+ patchAttrUnlessProp(oldVnode, vnode, renderer);
4208
+ }
4209
+ else {
4210
+ patchAttributes(oldVnode, vnode, renderer);
4211
+ }
4212
+ patchProps(oldVnode, vnode, renderer);
4450
4213
  }
4451
4214
  function applyStyleScoping(elm, owner, renderer) {
4452
- // Set the class name for `*.scoped.css` style scoping.
4453
- const scopeToken = getScopeTokenClass(owner);
4454
- if (!isNull(scopeToken)) {
4455
- const {
4456
- getClassList
4457
- } = renderer;
4458
- // TODO [#2762]: this dot notation with add is probably problematic
4459
- // probably we should have a renderer api for just the add operation
4460
- getClassList(elm).add(scopeToken);
4461
- }
4462
- // Set property element for synthetic shadow DOM style scoping.
4463
- const {
4464
- stylesheetToken: syntheticToken
4465
- } = owner.context;
4466
- if (owner.shadowMode === 1 /* ShadowMode.Synthetic */ && !isUndefined$1(syntheticToken)) {
4467
- elm.$shadowToken$ = syntheticToken;
4468
- }
4215
+ // Set the class name for `*.scoped.css` style scoping.
4216
+ const scopeToken = getScopeTokenClass(owner);
4217
+ if (!isNull(scopeToken)) {
4218
+ const { getClassList } = renderer;
4219
+ // TODO [#2762]: this dot notation with add is probably problematic
4220
+ // probably we should have a renderer api for just the add operation
4221
+ getClassList(elm).add(scopeToken);
4222
+ }
4223
+ // Set property element for synthetic shadow DOM style scoping.
4224
+ const { stylesheetToken: syntheticToken } = owner.context;
4225
+ if (owner.shadowMode === 1 /* ShadowMode.Synthetic */ && !isUndefined$1(syntheticToken)) {
4226
+ elm.$shadowToken$ = syntheticToken;
4227
+ }
4469
4228
  }
4470
4229
  function applyDomManual(elm, vnode) {
4471
- var _a;
4472
- const {
4473
- owner,
4474
- data: {
4475
- context
4230
+ var _a;
4231
+ const { owner, data: { context }, } = vnode;
4232
+ if (owner.shadowMode === 1 /* ShadowMode.Synthetic */ && ((_a = context === null || context === void 0 ? void 0 : context.lwc) === null || _a === void 0 ? void 0 : _a.dom) === "manual" /* LwcDomMode.Manual */) {
4233
+ elm.$domManual$ = true;
4476
4234
  }
4477
- } = vnode;
4478
- if (owner.shadowMode === 1 /* ShadowMode.Synthetic */ && ((_a = context === null || context === void 0 ? void 0 : context.lwc) === null || _a === void 0 ? void 0 : _a.dom) === "manual" /* LwcDomMode.Manual */) {
4479
- elm.$domManual$ = true;
4480
- }
4481
4235
  }
4482
4236
  function applyElementRestrictions(elm, vnode) {
4483
- var _a, _b;
4484
- if (process.env.NODE_ENV !== 'production') {
4485
- const isSynthetic = vnode.owner.shadowMode === 1 /* ShadowMode.Synthetic */;
4486
- 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 */;
4487
- const isLight = vnode.owner.renderMode === 0 /* RenderMode.Light */;
4488
- patchElementWithRestrictions(elm, {
4489
- isPortal,
4490
- isLight,
4491
- isSynthetic
4492
- });
4493
- }
4237
+ var _a, _b;
4238
+ if (process.env.NODE_ENV !== 'production') {
4239
+ const isSynthetic = vnode.owner.shadowMode === 1 /* ShadowMode.Synthetic */;
4240
+ 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 */;
4241
+ const isLight = vnode.owner.renderMode === 0 /* RenderMode.Light */;
4242
+ patchElementWithRestrictions(elm, {
4243
+ isPortal,
4244
+ isLight,
4245
+ isSynthetic,
4246
+ });
4247
+ }
4494
4248
  }
4495
4249
  function allocateChildren(vnode, vm) {
4496
- // A component with slots will re-render because:
4497
- // 1- There is a change of the internal state.
4498
- // 2- There is a change on the external api (ex: slots)
4499
- //
4500
- // In case #1, the vnodes in the cmpSlots will be reused since they didn't changed. This routine emptied the
4501
- // slotted children when those VCustomElement were rendered and therefore in subsequent calls to allocate children
4502
- // in a reused VCustomElement, there won't be any slotted children.
4503
- // For those cases, we will use the reference for allocated children stored when rendering the fresh VCustomElement.
4504
- //
4505
- // In case #2, we will always get a fresh VCustomElement.
4506
- const children = vnode.aChildren || vnode.children;
4507
- const {
4508
- renderMode,
4509
- shadowMode
4510
- } = vm;
4511
- if (process.env.NODE_ENV !== 'production') {
4512
- // If any of the children being allocated is a scoped slot fragment, make sure the receiving
4513
- // component is a light DOM component. This is mainly to validate light dom parent running
4514
- // in native shadow mode.
4515
- if (renderMode !== 0 /* RenderMode.Light */ && ArraySome.call(children, child => !isNull(child) && isVScopedSlotFragment(child))) {
4516
- logError(`Invalid usage of 'lwc:slot-data' on ${getComponentTag(vm)} tag. Scoped slot content can only be passed to a light dom child.`);
4517
- }
4518
- }
4519
- // If any of the children being allocated are VFragments, we remove the text delimiters and flatten all immediate
4520
- // children VFragments to avoid them interfering with default slot behavior.
4521
- const allocatedChildren = flattenFragmentsInChildren(children);
4522
- vnode.children = allocatedChildren;
4523
- vm.aChildren = allocatedChildren;
4524
- if (shadowMode === 1 /* ShadowMode.Synthetic */ || renderMode === 0 /* RenderMode.Light */) {
4525
- // slow path
4526
- allocateInSlot(vm, allocatedChildren, vnode.owner);
4527
- // save the allocated children in case this vnode is reused.
4528
- vnode.aChildren = allocatedChildren;
4529
- // every child vnode is now allocated, and the host should receive none directly, it receives them via the shadow!
4530
- vnode.children = EmptyArray;
4531
- }
4250
+ // A component with slots will re-render because:
4251
+ // 1- There is a change of the internal state.
4252
+ // 2- There is a change on the external api (ex: slots)
4253
+ //
4254
+ // In case #1, the vnodes in the cmpSlots will be reused since they didn't changed. This routine emptied the
4255
+ // slotted children when those VCustomElement were rendered and therefore in subsequent calls to allocate children
4256
+ // in a reused VCustomElement, there won't be any slotted children.
4257
+ // For those cases, we will use the reference for allocated children stored when rendering the fresh VCustomElement.
4258
+ //
4259
+ // In case #2, we will always get a fresh VCustomElement.
4260
+ const children = vnode.aChildren || vnode.children;
4261
+ const { renderMode, shadowMode } = vm;
4262
+ if (process.env.NODE_ENV !== 'production') {
4263
+ // If any of the children being allocated is a scoped slot fragment, make sure the receiving
4264
+ // component is a light DOM component. This is mainly to validate light dom parent running
4265
+ // in native shadow mode.
4266
+ if (renderMode !== 0 /* RenderMode.Light */ &&
4267
+ ArraySome.call(children, (child) => !isNull(child) && isVScopedSlotFragment(child))) {
4268
+ logError(`Invalid usage of 'lwc:slot-data' on ${getComponentTag(vm)} tag. Scoped slot content can only be passed to a light dom child.`);
4269
+ }
4270
+ }
4271
+ // If any of the children being allocated are VFragments, we remove the text delimiters and flatten all immediate
4272
+ // children VFragments to avoid them interfering with default slot behavior.
4273
+ const allocatedChildren = flattenFragmentsInChildren(children);
4274
+ vnode.children = allocatedChildren;
4275
+ vm.aChildren = allocatedChildren;
4276
+ if (shadowMode === 1 /* ShadowMode.Synthetic */ || renderMode === 0 /* RenderMode.Light */) {
4277
+ // slow path
4278
+ allocateInSlot(vm, allocatedChildren, vnode.owner);
4279
+ // save the allocated children in case this vnode is reused.
4280
+ vnode.aChildren = allocatedChildren;
4281
+ // every child vnode is now allocated, and the host should receive none directly, it receives them via the shadow!
4282
+ vnode.children = EmptyArray;
4283
+ }
4532
4284
  }
4533
4285
  /**
4534
4286
  * Flattens the contents of all VFragments in an array of VNodes, removes the text delimiters on those VFragments, and
@@ -4540,275 +4292,278 @@ function allocateChildren(vnode, vm) {
4540
4292
  * This function is used for slotted VFragments to avoid the text delimiters interfering with slotting functionality.
4541
4293
  */
4542
4294
  function flattenFragmentsInChildren(children) {
4543
- const flattenedChildren = [];
4544
- // Initialize our stack with the direct children of the custom component and check whether we have a VFragment.
4545
- // If no VFragment is found in children, we don't need to traverse anything or mark the children dynamic and can return early.
4546
- const nodeStack = [];
4547
- let fragmentFound = false;
4548
- for (let i = children.length - 1; i > -1; i -= 1) {
4549
- const child = children[i];
4550
- ArrayPush$1.call(nodeStack, child);
4551
- fragmentFound = fragmentFound || !!(child && isVFragment(child));
4552
- }
4553
- if (!fragmentFound) {
4554
- return children;
4555
- }
4556
- let currentNode;
4557
- while (!isUndefined$1(currentNode = ArrayPop.call(nodeStack))) {
4558
- if (!isNull(currentNode) && isVFragment(currentNode)) {
4559
- const fChildren = currentNode.children;
4560
- // Ignore the start and end text node delimiters
4561
- for (let i = fChildren.length - 2; i > 0; i -= 1) {
4562
- ArrayPush$1.call(nodeStack, fChildren[i]);
4563
- }
4564
- } else {
4565
- ArrayPush$1.call(flattenedChildren, currentNode);
4566
- }
4567
- }
4568
- // We always mark the children as dynamic because nothing generates stable VFragments yet.
4569
- // If/when stable VFragments are generated by the compiler, this code should be updated to
4570
- // not mark dynamic if all flattened VFragments were stable.
4571
- markAsDynamicChildren(flattenedChildren);
4572
- return flattenedChildren;
4295
+ const flattenedChildren = [];
4296
+ // Initialize our stack with the direct children of the custom component and check whether we have a VFragment.
4297
+ // If no VFragment is found in children, we don't need to traverse anything or mark the children dynamic and can return early.
4298
+ const nodeStack = [];
4299
+ let fragmentFound = false;
4300
+ for (let i = children.length - 1; i > -1; i -= 1) {
4301
+ const child = children[i];
4302
+ ArrayPush$1.call(nodeStack, child);
4303
+ fragmentFound = fragmentFound || !!(child && isVFragment(child));
4304
+ }
4305
+ if (!fragmentFound) {
4306
+ return children;
4307
+ }
4308
+ let currentNode;
4309
+ while (!isUndefined$1((currentNode = ArrayPop.call(nodeStack)))) {
4310
+ if (!isNull(currentNode) && isVFragment(currentNode)) {
4311
+ const fChildren = currentNode.children;
4312
+ // Ignore the start and end text node delimiters
4313
+ for (let i = fChildren.length - 2; i > 0; i -= 1) {
4314
+ ArrayPush$1.call(nodeStack, fChildren[i]);
4315
+ }
4316
+ }
4317
+ else {
4318
+ ArrayPush$1.call(flattenedChildren, currentNode);
4319
+ }
4320
+ }
4321
+ // We always mark the children as dynamic because nothing generates stable VFragments yet.
4322
+ // If/when stable VFragments are generated by the compiler, this code should be updated to
4323
+ // not mark dynamic if all flattened VFragments were stable.
4324
+ markAsDynamicChildren(flattenedChildren);
4325
+ return flattenedChildren;
4573
4326
  }
4574
4327
  function createViewModelHook(elm, vnode, renderer) {
4575
- let vm = getAssociatedVMIfPresent(elm);
4576
- // There is a possibility that a custom element is registered under tagName, in which case, the
4577
- // initialization is already carry on, and there is nothing else to do here since this hook is
4578
- // called right after invoking `document.createElement`.
4579
- if (!isUndefined$1(vm)) {
4328
+ let vm = getAssociatedVMIfPresent(elm);
4329
+ // There is a possibility that a custom element is registered under tagName, in which case, the
4330
+ // initialization is already carry on, and there is nothing else to do here since this hook is
4331
+ // called right after invoking `document.createElement`.
4332
+ if (!isUndefined$1(vm)) {
4333
+ return vm;
4334
+ }
4335
+ const { sel, mode, ctor, owner } = vnode;
4336
+ vm = createVM(elm, ctor, renderer, {
4337
+ mode,
4338
+ owner,
4339
+ tagName: sel,
4340
+ });
4341
+ if (process.env.NODE_ENV !== 'production') {
4342
+ assert.isTrue(isArray$1(vnode.children), `Invalid vnode for a custom element, it must have children defined.`);
4343
+ }
4580
4344
  return vm;
4581
- }
4582
- const {
4583
- sel,
4584
- mode,
4585
- ctor,
4586
- owner
4587
- } = vnode;
4588
- vm = createVM(elm, ctor, renderer, {
4589
- mode,
4590
- owner,
4591
- tagName: sel
4592
- });
4593
- if (process.env.NODE_ENV !== 'production') {
4594
- assert.isTrue(isArray$1(vnode.children), `Invalid vnode for a custom element, it must have children defined.`);
4595
- }
4596
- return vm;
4597
4345
  }
4598
4346
  function allocateInSlot(vm, children, owner) {
4599
- var _a, _b;
4600
- const {
4601
- cmpSlots: {
4602
- slotAssignments: oldSlotsMapping
4603
- }
4604
- } = vm;
4605
- const cmpSlotsMapping = create(null);
4606
- // Collect all slots into cmpSlotsMapping
4607
- for (let i = 0, len = children.length; i < len; i += 1) {
4608
- const vnode = children[i];
4609
- if (isNull(vnode)) {
4610
- continue;
4611
- }
4612
- let slotName = '';
4613
- if (isVBaseElement(vnode)) {
4614
- slotName = (_b = (_a = vnode.data.attrs) === null || _a === void 0 ? void 0 : _a.slot) !== null && _b !== void 0 ? _b : '';
4615
- } else if (isVScopedSlotFragment(vnode)) {
4616
- slotName = vnode.slotName;
4617
- }
4618
- // Can't use toString here because Symbol(1).toString() is 'Symbol(1)'
4619
- // but elm.setAttribute('slot', Symbol(1)) is an error.
4620
- // the following line also throws same error for symbols
4621
- // Similar for Object.create(null)
4622
- const normalizedSlotName = '' + slotName;
4623
- const vnodes = cmpSlotsMapping[normalizedSlotName] = cmpSlotsMapping[normalizedSlotName] || [];
4624
- ArrayPush$1.call(vnodes, vnode);
4625
- }
4626
- vm.cmpSlots = {
4627
- owner,
4628
- slotAssignments: cmpSlotsMapping
4629
- };
4630
- if (isFalse(vm.isDirty)) {
4631
- // We need to determine if the old allocation is really different from the new one
4632
- // and mark the vm as dirty
4633
- const oldKeys = keys(oldSlotsMapping);
4634
- if (oldKeys.length !== keys(cmpSlotsMapping).length) {
4635
- markComponentAsDirty(vm);
4636
- return;
4637
- }
4638
- for (let i = 0, len = oldKeys.length; i < len; i += 1) {
4639
- const key = oldKeys[i];
4640
- if (isUndefined$1(cmpSlotsMapping[key]) || oldSlotsMapping[key].length !== cmpSlotsMapping[key].length) {
4641
- markComponentAsDirty(vm);
4642
- return;
4643
- }
4644
- const oldVNodes = oldSlotsMapping[key];
4645
- const vnodes = cmpSlotsMapping[key];
4646
- for (let j = 0, a = cmpSlotsMapping[key].length; j < a; j += 1) {
4647
- if (oldVNodes[j] !== vnodes[j]) {
4648
- markComponentAsDirty(vm);
4649
- return;
4347
+ var _a, _b;
4348
+ const { cmpSlots: { slotAssignments: oldSlotsMapping }, } = vm;
4349
+ const cmpSlotsMapping = create(null);
4350
+ // Collect all slots into cmpSlotsMapping
4351
+ for (let i = 0, len = children.length; i < len; i += 1) {
4352
+ const vnode = children[i];
4353
+ if (isNull(vnode)) {
4354
+ continue;
4355
+ }
4356
+ let slotName = '';
4357
+ if (isVBaseElement(vnode)) {
4358
+ slotName = (_b = (_a = vnode.data.attrs) === null || _a === void 0 ? void 0 : _a.slot) !== null && _b !== void 0 ? _b : '';
4359
+ }
4360
+ else if (isVScopedSlotFragment(vnode)) {
4361
+ slotName = vnode.slotName;
4362
+ }
4363
+ // Can't use toString here because Symbol(1).toString() is 'Symbol(1)'
4364
+ // but elm.setAttribute('slot', Symbol(1)) is an error.
4365
+ // the following line also throws same error for symbols
4366
+ // Similar for Object.create(null)
4367
+ const normalizedSlotName = '' + slotName;
4368
+ const vnodes = (cmpSlotsMapping[normalizedSlotName] =
4369
+ cmpSlotsMapping[normalizedSlotName] || []);
4370
+ ArrayPush$1.call(vnodes, vnode);
4371
+ }
4372
+ vm.cmpSlots = { owner, slotAssignments: cmpSlotsMapping };
4373
+ if (isFalse(vm.isDirty)) {
4374
+ // We need to determine if the old allocation is really different from the new one
4375
+ // and mark the vm as dirty
4376
+ const oldKeys = keys(oldSlotsMapping);
4377
+ if (oldKeys.length !== keys(cmpSlotsMapping).length) {
4378
+ markComponentAsDirty(vm);
4379
+ return;
4380
+ }
4381
+ for (let i = 0, len = oldKeys.length; i < len; i += 1) {
4382
+ const key = oldKeys[i];
4383
+ if (isUndefined$1(cmpSlotsMapping[key]) ||
4384
+ oldSlotsMapping[key].length !== cmpSlotsMapping[key].length) {
4385
+ markComponentAsDirty(vm);
4386
+ return;
4387
+ }
4388
+ const oldVNodes = oldSlotsMapping[key];
4389
+ const vnodes = cmpSlotsMapping[key];
4390
+ for (let j = 0, a = cmpSlotsMapping[key].length; j < a; j += 1) {
4391
+ if (oldVNodes[j] !== vnodes[j]) {
4392
+ markComponentAsDirty(vm);
4393
+ return;
4394
+ }
4395
+ }
4650
4396
  }
4651
- }
4652
4397
  }
4653
- }
4654
4398
  }
4655
4399
  // Using a WeakMap instead of a WeakSet because this one works in IE11 :(
4656
4400
  const DynamicChildren = new WeakMap();
4657
4401
  // dynamic children means it was either generated by an iteration in a template
4658
4402
  // or part of an unstable fragment, and will require a more complex diffing algo.
4659
4403
  function markAsDynamicChildren(children) {
4660
- DynamicChildren.set(children, 1);
4404
+ DynamicChildren.set(children, 1);
4661
4405
  }
4662
4406
  function hasDynamicChildren(children) {
4663
- return DynamicChildren.has(children);
4407
+ return DynamicChildren.has(children);
4664
4408
  }
4665
4409
  function createKeyToOldIdx(children, beginIdx, endIdx) {
4666
- const map = {};
4667
- // TODO [#1637]: simplify this by assuming that all vnodes has keys
4668
- for (let j = beginIdx; j <= endIdx; ++j) {
4669
- const ch = children[j];
4670
- if (isVNode(ch)) {
4671
- const {
4672
- key
4673
- } = ch;
4674
- if (key !== undefined) {
4675
- map[key] = j;
4676
- }
4677
- }
4678
- }
4679
- return map;
4410
+ const map = {};
4411
+ // TODO [#1637]: simplify this by assuming that all vnodes has keys
4412
+ for (let j = beginIdx; j <= endIdx; ++j) {
4413
+ const ch = children[j];
4414
+ if (isVNode(ch)) {
4415
+ const { key } = ch;
4416
+ if (key !== undefined) {
4417
+ map[key] = j;
4418
+ }
4419
+ }
4420
+ }
4421
+ return map;
4680
4422
  }
4681
4423
  function updateDynamicChildren(oldCh, newCh, parent, renderer) {
4682
- let oldStartIdx = 0;
4683
- let newStartIdx = 0;
4684
- let oldEndIdx = oldCh.length - 1;
4685
- let oldStartVnode = oldCh[0];
4686
- let oldEndVnode = oldCh[oldEndIdx];
4687
- const newChEnd = newCh.length - 1;
4688
- let newEndIdx = newChEnd;
4689
- let newStartVnode = newCh[0];
4690
- let newEndVnode = newCh[newEndIdx];
4691
- let oldKeyToIdx;
4692
- let idxInOld;
4693
- let elmToMove;
4694
- let before;
4695
- let clonedOldCh = false;
4696
- while (oldStartIdx <= oldEndIdx && newStartIdx <= newEndIdx) {
4697
- if (!isVNode(oldStartVnode)) {
4698
- oldStartVnode = oldCh[++oldStartIdx]; // Vnode might have been moved left
4699
- } else if (!isVNode(oldEndVnode)) {
4700
- oldEndVnode = oldCh[--oldEndIdx];
4701
- } else if (!isVNode(newStartVnode)) {
4702
- newStartVnode = newCh[++newStartIdx];
4703
- } else if (!isVNode(newEndVnode)) {
4704
- newEndVnode = newCh[--newEndIdx];
4705
- } else if (isSameVnode(oldStartVnode, newStartVnode)) {
4706
- patch(oldStartVnode, newStartVnode, parent, renderer);
4707
- oldStartVnode = oldCh[++oldStartIdx];
4708
- newStartVnode = newCh[++newStartIdx];
4709
- } else if (isSameVnode(oldEndVnode, newEndVnode)) {
4710
- patch(oldEndVnode, newEndVnode, parent, renderer);
4711
- oldEndVnode = oldCh[--oldEndIdx];
4712
- newEndVnode = newCh[--newEndIdx];
4713
- } else if (isSameVnode(oldStartVnode, newEndVnode)) {
4714
- // Vnode moved right
4715
- patch(oldStartVnode, newEndVnode, parent, renderer);
4716
- insertNode(oldStartVnode.elm, parent, renderer.nextSibling(oldEndVnode.elm), renderer);
4717
- oldStartVnode = oldCh[++oldStartIdx];
4718
- newEndVnode = newCh[--newEndIdx];
4719
- } else if (isSameVnode(oldEndVnode, newStartVnode)) {
4720
- // Vnode moved left
4721
- patch(oldEndVnode, newStartVnode, parent, renderer);
4722
- insertNode(newStartVnode.elm, parent, oldStartVnode.elm, renderer);
4723
- oldEndVnode = oldCh[--oldEndIdx];
4724
- newStartVnode = newCh[++newStartIdx];
4725
- } else {
4726
- if (oldKeyToIdx === undefined) {
4727
- oldKeyToIdx = createKeyToOldIdx(oldCh, oldStartIdx, oldEndIdx);
4728
- }
4729
- idxInOld = oldKeyToIdx[newStartVnode.key];
4730
- if (isUndefined$1(idxInOld)) {
4731
- // New element
4732
- mount(newStartVnode, parent, renderer, oldStartVnode.elm);
4733
- newStartVnode = newCh[++newStartIdx];
4734
- } else {
4735
- elmToMove = oldCh[idxInOld];
4736
- if (isVNode(elmToMove)) {
4737
- if (elmToMove.sel !== newStartVnode.sel) {
4738
- // New element
4739
- mount(newStartVnode, parent, renderer, oldStartVnode.elm);
4740
- } else {
4741
- patch(elmToMove, newStartVnode, parent, renderer);
4742
- // Delete the old child, but copy the array since it is read-only.
4743
- // The `oldCh` will be GC'ed after `updateDynamicChildren` is complete,
4744
- // so we only care about the `oldCh` object inside this function.
4745
- // To avoid cloning over and over again, we check `clonedOldCh`
4746
- // and only clone once.
4747
- if (!clonedOldCh) {
4748
- clonedOldCh = true;
4749
- oldCh = [...oldCh];
4424
+ let oldStartIdx = 0;
4425
+ let newStartIdx = 0;
4426
+ let oldEndIdx = oldCh.length - 1;
4427
+ let oldStartVnode = oldCh[0];
4428
+ let oldEndVnode = oldCh[oldEndIdx];
4429
+ const newChEnd = newCh.length - 1;
4430
+ let newEndIdx = newChEnd;
4431
+ let newStartVnode = newCh[0];
4432
+ let newEndVnode = newCh[newEndIdx];
4433
+ let oldKeyToIdx;
4434
+ let idxInOld;
4435
+ let elmToMove;
4436
+ let before;
4437
+ let clonedOldCh = false;
4438
+ while (oldStartIdx <= oldEndIdx && newStartIdx <= newEndIdx) {
4439
+ if (!isVNode(oldStartVnode)) {
4440
+ oldStartVnode = oldCh[++oldStartIdx]; // Vnode might have been moved left
4441
+ }
4442
+ else if (!isVNode(oldEndVnode)) {
4443
+ oldEndVnode = oldCh[--oldEndIdx];
4444
+ }
4445
+ else if (!isVNode(newStartVnode)) {
4446
+ newStartVnode = newCh[++newStartIdx];
4447
+ }
4448
+ else if (!isVNode(newEndVnode)) {
4449
+ newEndVnode = newCh[--newEndIdx];
4450
+ }
4451
+ else if (isSameVnode(oldStartVnode, newStartVnode)) {
4452
+ patch(oldStartVnode, newStartVnode, parent, renderer);
4453
+ oldStartVnode = oldCh[++oldStartIdx];
4454
+ newStartVnode = newCh[++newStartIdx];
4455
+ }
4456
+ else if (isSameVnode(oldEndVnode, newEndVnode)) {
4457
+ patch(oldEndVnode, newEndVnode, parent, renderer);
4458
+ oldEndVnode = oldCh[--oldEndIdx];
4459
+ newEndVnode = newCh[--newEndIdx];
4460
+ }
4461
+ else if (isSameVnode(oldStartVnode, newEndVnode)) {
4462
+ // Vnode moved right
4463
+ patch(oldStartVnode, newEndVnode, parent, renderer);
4464
+ insertNode(oldStartVnode.elm, parent, renderer.nextSibling(oldEndVnode.elm), renderer);
4465
+ oldStartVnode = oldCh[++oldStartIdx];
4466
+ newEndVnode = newCh[--newEndIdx];
4467
+ }
4468
+ else if (isSameVnode(oldEndVnode, newStartVnode)) {
4469
+ // Vnode moved left
4470
+ patch(oldEndVnode, newStartVnode, parent, renderer);
4471
+ insertNode(newStartVnode.elm, parent, oldStartVnode.elm, renderer);
4472
+ oldEndVnode = oldCh[--oldEndIdx];
4473
+ newStartVnode = newCh[++newStartIdx];
4474
+ }
4475
+ else {
4476
+ if (oldKeyToIdx === undefined) {
4477
+ oldKeyToIdx = createKeyToOldIdx(oldCh, oldStartIdx, oldEndIdx);
4750
4478
  }
4751
- // We've already cloned at least once, so it's no longer read-only
4752
- oldCh[idxInOld] = undefined;
4753
- insertNode(elmToMove.elm, parent, oldStartVnode.elm, renderer);
4754
- }
4755
- }
4756
- newStartVnode = newCh[++newStartIdx];
4757
- }
4758
- }
4759
- }
4760
- if (oldStartIdx <= oldEndIdx || newStartIdx <= newEndIdx) {
4761
- if (oldStartIdx > oldEndIdx) {
4762
- // There's some cases in which the sub array of vnodes to be inserted is followed by null(s) and an
4763
- // already processed vnode, in such cases the vnodes to be inserted should be before that processed vnode.
4764
- let i = newEndIdx;
4765
- let n;
4766
- do {
4767
- n = newCh[++i];
4768
- } while (!isVNode(n) && i < newChEnd);
4769
- before = isVNode(n) ? n.elm : null;
4770
- mountVNodes(newCh, parent, renderer, before, newStartIdx, newEndIdx + 1);
4771
- } else {
4772
- unmountVNodes(oldCh, parent, renderer, true, oldStartIdx, oldEndIdx + 1);
4773
- }
4774
- }
4479
+ idxInOld = oldKeyToIdx[newStartVnode.key];
4480
+ if (isUndefined$1(idxInOld)) {
4481
+ // New element
4482
+ mount(newStartVnode, parent, renderer, oldStartVnode.elm);
4483
+ newStartVnode = newCh[++newStartIdx];
4484
+ }
4485
+ else {
4486
+ elmToMove = oldCh[idxInOld];
4487
+ if (isVNode(elmToMove)) {
4488
+ if (elmToMove.sel !== newStartVnode.sel) {
4489
+ // New element
4490
+ mount(newStartVnode, parent, renderer, oldStartVnode.elm);
4491
+ }
4492
+ else {
4493
+ patch(elmToMove, newStartVnode, parent, renderer);
4494
+ // Delete the old child, but copy the array since it is read-only.
4495
+ // The `oldCh` will be GC'ed after `updateDynamicChildren` is complete,
4496
+ // so we only care about the `oldCh` object inside this function.
4497
+ // To avoid cloning over and over again, we check `clonedOldCh`
4498
+ // and only clone once.
4499
+ if (!clonedOldCh) {
4500
+ clonedOldCh = true;
4501
+ oldCh = [...oldCh];
4502
+ }
4503
+ // We've already cloned at least once, so it's no longer read-only
4504
+ oldCh[idxInOld] = undefined;
4505
+ insertNode(elmToMove.elm, parent, oldStartVnode.elm, renderer);
4506
+ }
4507
+ }
4508
+ newStartVnode = newCh[++newStartIdx];
4509
+ }
4510
+ }
4511
+ }
4512
+ if (oldStartIdx <= oldEndIdx || newStartIdx <= newEndIdx) {
4513
+ if (oldStartIdx > oldEndIdx) {
4514
+ // There's some cases in which the sub array of vnodes to be inserted is followed by null(s) and an
4515
+ // already processed vnode, in such cases the vnodes to be inserted should be before that processed vnode.
4516
+ let i = newEndIdx;
4517
+ let n;
4518
+ do {
4519
+ n = newCh[++i];
4520
+ } while (!isVNode(n) && i < newChEnd);
4521
+ before = isVNode(n) ? n.elm : null;
4522
+ mountVNodes(newCh, parent, renderer, before, newStartIdx, newEndIdx + 1);
4523
+ }
4524
+ else {
4525
+ unmountVNodes(oldCh, parent, renderer, true, oldStartIdx, oldEndIdx + 1);
4526
+ }
4527
+ }
4775
4528
  }
4776
4529
  function updateStaticChildren(c1, c2, parent, renderer) {
4777
- const c1Length = c1.length;
4778
- const c2Length = c2.length;
4779
- if (c1Length === 0) {
4780
- // the old list is empty, we can directly insert anything new
4781
- mountVNodes(c2, parent, renderer, null);
4782
- return;
4783
- }
4784
- if (c2Length === 0) {
4785
- // the old list is nonempty and the new list is empty so we can directly remove all old nodes
4786
- // this is the case in which the dynamic children of an if-directive should be removed
4787
- unmountVNodes(c1, parent, renderer, true);
4788
- return;
4789
- }
4790
- // if the old list is not empty, the new list MUST have the same
4791
- // amount of nodes, that's why we call this static children
4792
- let anchor = null;
4793
- for (let i = c2Length - 1; i >= 0; i -= 1) {
4794
- const n1 = c1[i];
4795
- const n2 = c2[i];
4796
- if (n2 !== n1) {
4797
- if (isVNode(n1)) {
4798
- if (isVNode(n2)) {
4799
- // both vnodes are equivalent, and we just need to patch them
4800
- patch(n1, n2, parent, renderer);
4801
- anchor = n2.elm;
4802
- } else {
4803
- // removing the old vnode since the new one is null
4804
- unmount(n1, parent, renderer, true);
4805
- }
4806
- } else if (isVNode(n2)) {
4807
- mount(n2, parent, renderer, anchor);
4808
- anchor = n2.elm;
4809
- }
4810
- }
4811
- }
4530
+ const c1Length = c1.length;
4531
+ const c2Length = c2.length;
4532
+ if (c1Length === 0) {
4533
+ // the old list is empty, we can directly insert anything new
4534
+ mountVNodes(c2, parent, renderer, null);
4535
+ return;
4536
+ }
4537
+ if (c2Length === 0) {
4538
+ // the old list is nonempty and the new list is empty so we can directly remove all old nodes
4539
+ // this is the case in which the dynamic children of an if-directive should be removed
4540
+ unmountVNodes(c1, parent, renderer, true);
4541
+ return;
4542
+ }
4543
+ // if the old list is not empty, the new list MUST have the same
4544
+ // amount of nodes, that's why we call this static children
4545
+ let anchor = null;
4546
+ for (let i = c2Length - 1; i >= 0; i -= 1) {
4547
+ const n1 = c1[i];
4548
+ const n2 = c2[i];
4549
+ if (n2 !== n1) {
4550
+ if (isVNode(n1)) {
4551
+ if (isVNode(n2)) {
4552
+ // both vnodes are equivalent, and we just need to patch them
4553
+ patch(n1, n2, parent, renderer);
4554
+ anchor = n2.elm;
4555
+ }
4556
+ else {
4557
+ // removing the old vnode since the new one is null
4558
+ unmount(n1, parent, renderer, true);
4559
+ }
4560
+ }
4561
+ else if (isVNode(n2)) {
4562
+ mount(n2, parent, renderer, anchor);
4563
+ anchor = n2.elm;
4564
+ }
4565
+ }
4566
+ }
4812
4567
  }
4813
4568
 
4814
4569
  /*
@@ -5745,398 +5500,366 @@ let idx = 0;
5745
5500
  /** The internal slot used to associate different objects the engine manipulates with the VM */
5746
5501
  const ViewModelReflection = new WeakMap();
5747
5502
  function callHook(cmp, fn, args = []) {
5748
- return fn.apply(cmp, args);
5503
+ return fn.apply(cmp, args);
5749
5504
  }
5750
5505
  function setHook(cmp, prop, newValue) {
5751
- cmp[prop] = newValue;
5506
+ cmp[prop] = newValue;
5752
5507
  }
5753
5508
  function getHook(cmp, prop) {
5754
- return cmp[prop];
5509
+ return cmp[prop];
5755
5510
  }
5756
5511
  function rerenderVM(vm) {
5757
- rehydrate(vm);
5512
+ rehydrate(vm);
5758
5513
  }
5759
5514
  function connectRootElement(elm) {
5760
- const vm = getAssociatedVM(elm);
5761
- logGlobalOperationStart(7 /* OperationId.GlobalHydrate */, vm);
5762
- // Usually means moving the element from one place to another, which is observable via
5763
- // life-cycle hooks.
5764
- if (vm.state === 1 /* VMState.connected */) {
5765
- disconnectRootElement(elm);
5766
- }
5767
- runConnectedCallback(vm);
5768
- rehydrate(vm);
5769
- logGlobalOperationEnd(7 /* OperationId.GlobalHydrate */, vm);
5515
+ const vm = getAssociatedVM(elm);
5516
+ logGlobalOperationStart(7 /* OperationId.GlobalHydrate */, vm);
5517
+ // Usually means moving the element from one place to another, which is observable via
5518
+ // life-cycle hooks.
5519
+ if (vm.state === 1 /* VMState.connected */) {
5520
+ disconnectRootElement(elm);
5521
+ }
5522
+ runConnectedCallback(vm);
5523
+ rehydrate(vm);
5524
+ logGlobalOperationEnd(7 /* OperationId.GlobalHydrate */, vm);
5770
5525
  }
5771
5526
  function disconnectRootElement(elm) {
5772
- const vm = getAssociatedVM(elm);
5773
- resetComponentStateWhenRemoved(vm);
5527
+ const vm = getAssociatedVM(elm);
5528
+ resetComponentStateWhenRemoved(vm);
5774
5529
  }
5775
5530
  function appendVM(vm) {
5776
- rehydrate(vm);
5531
+ rehydrate(vm);
5777
5532
  }
5778
5533
  // just in case the component comes back, with this we guarantee re-rendering it
5779
5534
  // while preventing any attempt to rehydration until after reinsertion.
5780
5535
  function resetComponentStateWhenRemoved(vm) {
5781
- const {
5782
- state
5783
- } = vm;
5784
- if (state !== 2 /* VMState.disconnected */) {
5785
- const {
5786
- tro
5787
- } = vm;
5788
- // Making sure that any observing record will not trigger the rehydrated on this vm
5789
- tro.reset();
5790
- runDisconnectedCallback(vm);
5791
- // Spec: https://dom.spec.whatwg.org/#concept-node-remove (step 14-15)
5792
- runChildNodesDisconnectedCallback(vm);
5793
- runLightChildNodesDisconnectedCallback(vm);
5794
- }
5795
- if (process.env.NODE_ENV !== 'production') {
5796
- removeActiveVM(vm);
5797
- }
5536
+ const { state } = vm;
5537
+ if (state !== 2 /* VMState.disconnected */) {
5538
+ const { tro } = vm;
5539
+ // Making sure that any observing record will not trigger the rehydrated on this vm
5540
+ tro.reset();
5541
+ runDisconnectedCallback(vm);
5542
+ // Spec: https://dom.spec.whatwg.org/#concept-node-remove (step 14-15)
5543
+ runChildNodesDisconnectedCallback(vm);
5544
+ runLightChildNodesDisconnectedCallback(vm);
5545
+ }
5546
+ if (process.env.NODE_ENV !== 'production') {
5547
+ removeActiveVM(vm);
5548
+ }
5798
5549
  }
5799
5550
  // this method is triggered by the diffing algo only when a vnode from the
5800
5551
  // old vnode.children is removed from the DOM.
5801
5552
  function removeVM(vm) {
5802
- if (process.env.NODE_ENV !== 'production') {
5803
- assert.isTrue(vm.state === 1 /* VMState.connected */ || vm.state === 2 /* VMState.disconnected */, `${vm} must have been connected.`);
5804
- }
5805
- resetComponentStateWhenRemoved(vm);
5553
+ if (process.env.NODE_ENV !== 'production') {
5554
+ assert.isTrue(vm.state === 1 /* VMState.connected */ || vm.state === 2 /* VMState.disconnected */, `${vm} must have been connected.`);
5555
+ }
5556
+ resetComponentStateWhenRemoved(vm);
5806
5557
  }
5807
5558
  function getNearestShadowAncestor(vm) {
5808
- let ancestor = vm.owner;
5809
- while (!isNull(ancestor) && ancestor.renderMode === 0 /* RenderMode.Light */) {
5810
- ancestor = ancestor.owner;
5811
- }
5812
- return ancestor;
5559
+ let ancestor = vm.owner;
5560
+ while (!isNull(ancestor) && ancestor.renderMode === 0 /* RenderMode.Light */) {
5561
+ ancestor = ancestor.owner;
5562
+ }
5563
+ return ancestor;
5813
5564
  }
5814
5565
  function createVM(elm, ctor, renderer, options) {
5815
- const {
5816
- mode,
5817
- owner,
5818
- tagName,
5819
- hydrated
5820
- } = options;
5821
- const def = getComponentInternalDef(ctor);
5822
- const vm = {
5823
- elm,
5824
- def,
5825
- idx: idx++,
5826
- state: 0 /* VMState.created */,
5827
- isScheduled: false,
5828
- isDirty: true,
5829
- tagName,
5830
- mode,
5831
- owner,
5832
- refVNodes: null,
5833
- children: EmptyArray,
5834
- aChildren: EmptyArray,
5835
- velements: EmptyArray,
5836
- cmpProps: create(null),
5837
- cmpFields: create(null),
5838
- cmpSlots: {
5839
- slotAssignments: create(null)
5840
- },
5841
- cmpTemplate: null,
5842
- hydrated: Boolean(hydrated),
5843
- renderMode: def.renderMode,
5844
- context: {
5845
- stylesheetToken: undefined,
5846
- hasTokenInClass: undefined,
5847
- hasTokenInAttribute: undefined,
5848
- hasScopedStyles: undefined,
5849
- styleVNodes: null,
5850
- tplCache: EmptyObject,
5851
- wiredConnecting: EmptyArray,
5852
- wiredDisconnecting: EmptyArray
5853
- },
5854
- // Properties set right after VM creation.
5855
- tro: null,
5856
- shadowMode: null,
5857
- stylesheets: null,
5858
- // Properties set by the LightningElement constructor.
5859
- component: null,
5860
- shadowRoot: null,
5861
- renderRoot: null,
5862
- callHook,
5863
- setHook,
5864
- getHook,
5865
- renderer
5866
- };
5867
- if (process.env.NODE_ENV !== 'production') {
5868
- vm.debugInfo = create(null);
5869
- }
5870
- vm.stylesheets = computeStylesheets(vm, def.ctor);
5871
- vm.shadowMode = computeShadowMode(vm, renderer);
5872
- vm.tro = getTemplateReactiveObserver();
5873
- if (process.env.NODE_ENV !== 'production') {
5874
- vm.toString = () => {
5875
- return `[object:vm ${def.name} (${vm.idx})]`;
5566
+ const { mode, owner, tagName, hydrated } = options;
5567
+ const def = getComponentInternalDef(ctor);
5568
+ const vm = {
5569
+ elm,
5570
+ def,
5571
+ idx: idx++,
5572
+ state: 0 /* VMState.created */,
5573
+ isScheduled: false,
5574
+ isDirty: true,
5575
+ tagName,
5576
+ mode,
5577
+ owner,
5578
+ refVNodes: null,
5579
+ children: EmptyArray,
5580
+ aChildren: EmptyArray,
5581
+ velements: EmptyArray,
5582
+ cmpProps: create(null),
5583
+ cmpFields: create(null),
5584
+ cmpSlots: { slotAssignments: create(null) },
5585
+ cmpTemplate: null,
5586
+ hydrated: Boolean(hydrated),
5587
+ renderMode: def.renderMode,
5588
+ context: {
5589
+ stylesheetToken: undefined,
5590
+ hasTokenInClass: undefined,
5591
+ hasTokenInAttribute: undefined,
5592
+ hasScopedStyles: undefined,
5593
+ styleVNodes: null,
5594
+ tplCache: EmptyObject,
5595
+ wiredConnecting: EmptyArray,
5596
+ wiredDisconnecting: EmptyArray,
5597
+ },
5598
+ // Properties set right after VM creation.
5599
+ tro: null,
5600
+ shadowMode: null,
5601
+ stylesheets: null,
5602
+ // Properties set by the LightningElement constructor.
5603
+ component: null,
5604
+ shadowRoot: null,
5605
+ renderRoot: null,
5606
+ callHook,
5607
+ setHook,
5608
+ getHook,
5609
+ renderer,
5876
5610
  };
5877
- if (lwcRuntimeFlags.ENABLE_FORCE_NATIVE_SHADOW_MODE_FOR_TEST) {
5878
- vm.shadowMode = 0 /* ShadowMode.Native */;
5879
- }
5880
- }
5881
- // Create component instance associated to the vm and the element.
5882
- invokeComponentConstructor(vm, def.ctor);
5883
- // Initializing the wire decorator per instance only when really needed
5884
- if (hasWireAdapters(vm)) {
5885
- installWireAdapters(vm);
5886
- }
5887
- return vm;
5611
+ if (process.env.NODE_ENV !== 'production') {
5612
+ vm.debugInfo = create(null);
5613
+ }
5614
+ vm.stylesheets = computeStylesheets(vm, def.ctor);
5615
+ vm.shadowMode = computeShadowMode(vm, renderer);
5616
+ vm.tro = getTemplateReactiveObserver();
5617
+ if (process.env.NODE_ENV !== 'production') {
5618
+ vm.toString = () => {
5619
+ return `[object:vm ${def.name} (${vm.idx})]`;
5620
+ };
5621
+ if (lwcRuntimeFlags.ENABLE_FORCE_NATIVE_SHADOW_MODE_FOR_TEST) {
5622
+ vm.shadowMode = 0 /* ShadowMode.Native */;
5623
+ }
5624
+ }
5625
+ // Create component instance associated to the vm and the element.
5626
+ invokeComponentConstructor(vm, def.ctor);
5627
+ // Initializing the wire decorator per instance only when really needed
5628
+ if (hasWireAdapters(vm)) {
5629
+ installWireAdapters(vm);
5630
+ }
5631
+ return vm;
5888
5632
  }
5889
5633
  function validateComponentStylesheets(vm, stylesheets) {
5890
- let valid = true;
5891
- const validate = arrayOrStylesheet => {
5892
- if (isArray$1(arrayOrStylesheet)) {
5893
- for (let i = 0; i < arrayOrStylesheet.length; i++) {
5894
- validate(arrayOrStylesheet[i]);
5895
- }
5896
- } else if (!isFunction$1(arrayOrStylesheet)) {
5897
- // function assumed to be a stylesheet factory
5898
- valid = false;
5899
- }
5900
- };
5901
- if (!isArray$1(stylesheets)) {
5902
- valid = false;
5903
- } else {
5904
- validate(stylesheets);
5905
- }
5906
- return valid;
5634
+ let valid = true;
5635
+ const validate = (arrayOrStylesheet) => {
5636
+ if (isArray$1(arrayOrStylesheet)) {
5637
+ for (let i = 0; i < arrayOrStylesheet.length; i++) {
5638
+ validate(arrayOrStylesheet[i]);
5639
+ }
5640
+ }
5641
+ else if (!isFunction$1(arrayOrStylesheet)) {
5642
+ // function assumed to be a stylesheet factory
5643
+ valid = false;
5644
+ }
5645
+ };
5646
+ if (!isArray$1(stylesheets)) {
5647
+ valid = false;
5648
+ }
5649
+ else {
5650
+ validate(stylesheets);
5651
+ }
5652
+ return valid;
5907
5653
  }
5908
5654
  // Validate and flatten any stylesheets defined as `static stylesheets`
5909
5655
  function computeStylesheets(vm, ctor) {
5910
- warnOnStylesheetsMutation(ctor);
5911
- const {
5912
- stylesheets
5913
- } = ctor;
5914
- if (!isUndefined$1(stylesheets)) {
5915
- const valid = validateComponentStylesheets(vm, stylesheets);
5916
- if (valid) {
5917
- return flattenStylesheets(stylesheets);
5918
- } else if (process.env.NODE_ENV !== 'production') {
5919
- logError(`static stylesheets must be an array of CSS stylesheets. Found invalid stylesheets on <${vm.tagName}>`, vm);
5920
- }
5921
- }
5922
- return null;
5656
+ warnOnStylesheetsMutation(ctor);
5657
+ const { stylesheets } = ctor;
5658
+ if (!isUndefined$1(stylesheets)) {
5659
+ const valid = validateComponentStylesheets(vm, stylesheets);
5660
+ if (valid) {
5661
+ return flattenStylesheets(stylesheets);
5662
+ }
5663
+ else if (process.env.NODE_ENV !== 'production') {
5664
+ logError(`static stylesheets must be an array of CSS stylesheets. Found invalid stylesheets on <${vm.tagName}>`, vm);
5665
+ }
5666
+ }
5667
+ return null;
5923
5668
  }
5924
5669
  function warnOnStylesheetsMutation(ctor) {
5925
- if (process.env.NODE_ENV !== 'production') {
5926
- let {
5927
- stylesheets
5928
- } = ctor;
5929
- defineProperty(ctor, 'stylesheets', {
5930
- enumerable: true,
5931
- configurable: true,
5932
- get() {
5933
- return stylesheets;
5934
- },
5935
- set(newValue) {
5936
- logWarnOnce(`Dynamically setting the "stylesheets" static property on ${ctor.name} ` + 'will not affect the stylesheets injected.');
5937
- stylesheets = newValue;
5938
- }
5939
- });
5940
- }
5670
+ if (process.env.NODE_ENV !== 'production') {
5671
+ let { stylesheets } = ctor;
5672
+ defineProperty(ctor, 'stylesheets', {
5673
+ enumerable: true,
5674
+ configurable: true,
5675
+ get() {
5676
+ return stylesheets;
5677
+ },
5678
+ set(newValue) {
5679
+ logWarnOnce(`Dynamically setting the "stylesheets" static property on ${ctor.name} ` +
5680
+ 'will not affect the stylesheets injected.');
5681
+ stylesheets = newValue;
5682
+ },
5683
+ });
5684
+ }
5941
5685
  }
5942
5686
  function computeShadowMode(vm, renderer) {
5943
- const {
5944
- def
5945
- } = vm;
5946
- const {
5947
- isSyntheticShadowDefined,
5948
- isNativeShadowDefined
5949
- } = renderer;
5950
- let shadowMode;
5951
- if (isSyntheticShadowDefined) {
5952
- if (def.renderMode === 0 /* RenderMode.Light */) {
5953
- // ShadowMode.Native implies "not synthetic shadow" which is consistent with how
5954
- // everything defaults to native when the synthetic shadow polyfill is unavailable.
5955
- shadowMode = 0 /* ShadowMode.Native */;
5956
- } else if (isNativeShadowDefined) {
5957
- // Not combined with above condition because @lwc/features only supports identifiers in
5958
- // the if-condition.
5959
- if (lwcRuntimeFlags.ENABLE_MIXED_SHADOW_MODE) {
5960
- if (def.shadowSupportMode === "any" /* ShadowSupportMode.Any */) {
5961
- shadowMode = 0 /* ShadowMode.Native */;
5962
- } else {
5963
- const shadowAncestor = getNearestShadowAncestor(vm);
5964
- if (!isNull(shadowAncestor) && shadowAncestor.shadowMode === 0 /* ShadowMode.Native */) {
5965
- // Transitive support for native Shadow DOM. A component in native mode
5966
- // transitively opts all of its descendants into native.
5687
+ const { def } = vm;
5688
+ const { isSyntheticShadowDefined, isNativeShadowDefined } = renderer;
5689
+ let shadowMode;
5690
+ if (isSyntheticShadowDefined) {
5691
+ if (def.renderMode === 0 /* RenderMode.Light */) {
5692
+ // ShadowMode.Native implies "not synthetic shadow" which is consistent with how
5693
+ // everything defaults to native when the synthetic shadow polyfill is unavailable.
5967
5694
  shadowMode = 0 /* ShadowMode.Native */;
5968
- } else {
5969
- // Synthetic if neither this component nor any of its ancestors are configured
5970
- // to be native.
5695
+ }
5696
+ else if (isNativeShadowDefined) {
5697
+ // Not combined with above condition because @lwc/features only supports identifiers in
5698
+ // the if-condition.
5699
+ if (lwcRuntimeFlags.ENABLE_MIXED_SHADOW_MODE) {
5700
+ if (def.shadowSupportMode === "any" /* ShadowSupportMode.Any */) {
5701
+ shadowMode = 0 /* ShadowMode.Native */;
5702
+ }
5703
+ else {
5704
+ const shadowAncestor = getNearestShadowAncestor(vm);
5705
+ if (!isNull(shadowAncestor) &&
5706
+ shadowAncestor.shadowMode === 0 /* ShadowMode.Native */) {
5707
+ // Transitive support for native Shadow DOM. A component in native mode
5708
+ // transitively opts all of its descendants into native.
5709
+ shadowMode = 0 /* ShadowMode.Native */;
5710
+ }
5711
+ else {
5712
+ // Synthetic if neither this component nor any of its ancestors are configured
5713
+ // to be native.
5714
+ shadowMode = 1 /* ShadowMode.Synthetic */;
5715
+ }
5716
+ }
5717
+ }
5718
+ else {
5719
+ shadowMode = 1 /* ShadowMode.Synthetic */;
5720
+ }
5721
+ }
5722
+ else {
5723
+ // Synthetic if there is no native Shadow DOM support.
5971
5724
  shadowMode = 1 /* ShadowMode.Synthetic */;
5972
- }
5973
- }
5974
- } else {
5975
- shadowMode = 1 /* ShadowMode.Synthetic */;
5976
- }
5977
- } else {
5978
- // Synthetic if there is no native Shadow DOM support.
5979
- shadowMode = 1 /* ShadowMode.Synthetic */;
5980
- }
5981
- } else {
5982
- // Native if the synthetic shadow polyfill is unavailable.
5983
- shadowMode = 0 /* ShadowMode.Native */;
5984
- }
5985
-
5986
- return shadowMode;
5725
+ }
5726
+ }
5727
+ else {
5728
+ // Native if the synthetic shadow polyfill is unavailable.
5729
+ shadowMode = 0 /* ShadowMode.Native */;
5730
+ }
5731
+ return shadowMode;
5987
5732
  }
5988
5733
  function assertIsVM(obj) {
5989
- if (isNull(obj) || !isObject(obj) || !('renderRoot' in obj)) {
5990
- throw new TypeError(`${obj} is not a VM.`);
5991
- }
5734
+ if (isNull(obj) || !isObject(obj) || !('renderRoot' in obj)) {
5735
+ throw new TypeError(`${obj} is not a VM.`);
5736
+ }
5992
5737
  }
5993
5738
  function associateVM(obj, vm) {
5994
- ViewModelReflection.set(obj, vm);
5739
+ ViewModelReflection.set(obj, vm);
5995
5740
  }
5996
5741
  function getAssociatedVM(obj) {
5997
- const vm = ViewModelReflection.get(obj);
5998
- if (process.env.NODE_ENV !== 'production') {
5999
- assertIsVM(vm);
6000
- }
6001
- return vm;
5742
+ const vm = ViewModelReflection.get(obj);
5743
+ if (process.env.NODE_ENV !== 'production') {
5744
+ assertIsVM(vm);
5745
+ }
5746
+ return vm;
6002
5747
  }
6003
5748
  function getAssociatedVMIfPresent(obj) {
6004
- const maybeVm = ViewModelReflection.get(obj);
6005
- if (process.env.NODE_ENV !== 'production') {
6006
- if (!isUndefined$1(maybeVm)) {
6007
- assertIsVM(maybeVm);
5749
+ const maybeVm = ViewModelReflection.get(obj);
5750
+ if (process.env.NODE_ENV !== 'production') {
5751
+ if (!isUndefined$1(maybeVm)) {
5752
+ assertIsVM(maybeVm);
5753
+ }
6008
5754
  }
6009
- }
6010
- return maybeVm;
5755
+ return maybeVm;
6011
5756
  }
6012
5757
  function rehydrate(vm) {
6013
- if (isTrue(vm.isDirty)) {
6014
- const children = renderComponent$1(vm);
6015
- patchShadowRoot(vm, children);
6016
- }
5758
+ if (isTrue(vm.isDirty)) {
5759
+ const children = renderComponent$1(vm);
5760
+ patchShadowRoot(vm, children);
5761
+ }
6017
5762
  }
6018
5763
  function patchShadowRoot(vm, newCh) {
6019
- const {
6020
- renderRoot,
6021
- children: oldCh,
6022
- renderer
6023
- } = vm;
6024
- // caching the new children collection
6025
- vm.children = newCh;
6026
- if (newCh.length > 0 || oldCh.length > 0) {
6027
- // patch function mutates vnodes by adding the element reference,
6028
- // however, if patching fails it contains partial changes.
6029
- if (oldCh !== newCh) {
6030
- runWithBoundaryProtection(vm, vm, () => {
6031
- // pre
6032
- logOperationStart(2 /* OperationId.Patch */, vm);
6033
- }, () => {
6034
- // job
6035
- patchChildren(oldCh, newCh, renderRoot, renderer);
6036
- }, () => {
6037
- // post
6038
- logOperationEnd(2 /* OperationId.Patch */, vm);
6039
- });
5764
+ const { renderRoot, children: oldCh, renderer } = vm;
5765
+ // caching the new children collection
5766
+ vm.children = newCh;
5767
+ if (newCh.length > 0 || oldCh.length > 0) {
5768
+ // patch function mutates vnodes by adding the element reference,
5769
+ // however, if patching fails it contains partial changes.
5770
+ if (oldCh !== newCh) {
5771
+ runWithBoundaryProtection(vm, vm, () => {
5772
+ // pre
5773
+ logOperationStart(2 /* OperationId.Patch */, vm);
5774
+ }, () => {
5775
+ // job
5776
+ patchChildren(oldCh, newCh, renderRoot, renderer);
5777
+ }, () => {
5778
+ // post
5779
+ logOperationEnd(2 /* OperationId.Patch */, vm);
5780
+ });
5781
+ }
6040
5782
  }
6041
- }
6042
- if (vm.state === 1 /* VMState.connected */) ;
5783
+ if (vm.state === 1 /* VMState.connected */) ;
6043
5784
  }
6044
-
6045
5785
  function runConnectedCallback(vm) {
6046
- const {
6047
- state
6048
- } = vm;
6049
- if (state === 1 /* VMState.connected */) {
6050
- return; // nothing to do since it was already connected
6051
- }
6052
-
6053
- vm.state = 1 /* VMState.connected */;
6054
- // reporting connection
6055
- const {
6056
- connected
6057
- } = Services;
6058
- if (connected) {
6059
- invokeServiceHook(vm, connected);
6060
- }
6061
- if (hasWireAdapters(vm)) {
6062
- connectWireAdapters(vm);
6063
- }
6064
- const {
6065
- connectedCallback
6066
- } = vm.def;
6067
- if (!isUndefined$1(connectedCallback)) {
6068
- logOperationStart(3 /* OperationId.ConnectedCallback */, vm);
6069
- invokeComponentCallback(vm, connectedCallback);
6070
- logOperationEnd(3 /* OperationId.ConnectedCallback */, vm);
6071
- }
5786
+ const { state } = vm;
5787
+ if (state === 1 /* VMState.connected */) {
5788
+ return; // nothing to do since it was already connected
5789
+ }
5790
+ vm.state = 1 /* VMState.connected */;
5791
+ // reporting connection
5792
+ const { connected } = Services;
5793
+ if (connected) {
5794
+ invokeServiceHook(vm, connected);
5795
+ }
5796
+ if (hasWireAdapters(vm)) {
5797
+ connectWireAdapters(vm);
5798
+ }
5799
+ const { connectedCallback } = vm.def;
5800
+ if (!isUndefined$1(connectedCallback)) {
5801
+ logOperationStart(3 /* OperationId.ConnectedCallback */, vm);
5802
+ invokeComponentCallback(vm, connectedCallback);
5803
+ logOperationEnd(3 /* OperationId.ConnectedCallback */, vm);
5804
+ }
6072
5805
  }
6073
5806
  function hasWireAdapters(vm) {
6074
- return getOwnPropertyNames$1(vm.def.wire).length > 0;
5807
+ return getOwnPropertyNames$1(vm.def.wire).length > 0;
6075
5808
  }
6076
5809
  function runDisconnectedCallback(vm) {
6077
- if (process.env.NODE_ENV !== 'production') {
6078
- assert.isTrue(vm.state !== 2 /* VMState.disconnected */, `${vm} must be inserted.`);
6079
- }
6080
- if (isFalse(vm.isDirty)) {
6081
- // this guarantees that if the component is reused/reinserted,
6082
- // it will be re-rendered because we are disconnecting the reactivity
6083
- // linking, so mutations are not automatically reflected on the state
6084
- // of disconnected components.
6085
- vm.isDirty = true;
6086
- }
6087
- vm.state = 2 /* VMState.disconnected */;
6088
- // reporting disconnection
6089
- const {
6090
- disconnected
6091
- } = Services;
6092
- if (disconnected) {
6093
- invokeServiceHook(vm, disconnected);
6094
- }
6095
- if (hasWireAdapters(vm)) {
6096
- disconnectWireAdapters(vm);
6097
- }
6098
- const {
6099
- disconnectedCallback
6100
- } = vm.def;
6101
- if (!isUndefined$1(disconnectedCallback)) {
6102
- logOperationStart(5 /* OperationId.DisconnectedCallback */, vm);
6103
- invokeComponentCallback(vm, disconnectedCallback);
6104
- logOperationEnd(5 /* OperationId.DisconnectedCallback */, vm);
6105
- }
5810
+ if (process.env.NODE_ENV !== 'production') {
5811
+ assert.isTrue(vm.state !== 2 /* VMState.disconnected */, `${vm} must be inserted.`);
5812
+ }
5813
+ if (isFalse(vm.isDirty)) {
5814
+ // this guarantees that if the component is reused/reinserted,
5815
+ // it will be re-rendered because we are disconnecting the reactivity
5816
+ // linking, so mutations are not automatically reflected on the state
5817
+ // of disconnected components.
5818
+ vm.isDirty = true;
5819
+ }
5820
+ vm.state = 2 /* VMState.disconnected */;
5821
+ // reporting disconnection
5822
+ const { disconnected } = Services;
5823
+ if (disconnected) {
5824
+ invokeServiceHook(vm, disconnected);
5825
+ }
5826
+ if (hasWireAdapters(vm)) {
5827
+ disconnectWireAdapters(vm);
5828
+ }
5829
+ const { disconnectedCallback } = vm.def;
5830
+ if (!isUndefined$1(disconnectedCallback)) {
5831
+ logOperationStart(5 /* OperationId.DisconnectedCallback */, vm);
5832
+ invokeComponentCallback(vm, disconnectedCallback);
5833
+ logOperationEnd(5 /* OperationId.DisconnectedCallback */, vm);
5834
+ }
6106
5835
  }
6107
5836
  function runChildNodesDisconnectedCallback(vm) {
6108
- const {
6109
- velements: vCustomElementCollection
6110
- } = vm;
6111
- // Reporting disconnection for every child in inverse order since they are
6112
- // inserted in reserved order.
6113
- for (let i = vCustomElementCollection.length - 1; i >= 0; i -= 1) {
6114
- const {
6115
- elm
6116
- } = vCustomElementCollection[i];
6117
- // There are two cases where the element could be undefined:
6118
- // * when there is an error during the construction phase, and an error
6119
- // boundary picks it, there is a possibility that the VCustomElement
6120
- // is not properly initialized, and therefore is should be ignored.
6121
- // * when slotted custom element is not used by the element where it is
6122
- // slotted into it, as a result, the custom element was never
6123
- // initialized.
6124
- if (!isUndefined$1(elm)) {
6125
- const childVM = getAssociatedVMIfPresent(elm);
6126
- // The VM associated with the element might be associated undefined
6127
- // in the case where the VM failed in the middle of its creation,
6128
- // eg: constructor throwing before invoking super().
6129
- if (!isUndefined$1(childVM)) {
6130
- resetComponentStateWhenRemoved(childVM);
6131
- }
6132
- }
6133
- }
5837
+ const { velements: vCustomElementCollection } = vm;
5838
+ // Reporting disconnection for every child in inverse order since they are
5839
+ // inserted in reserved order.
5840
+ for (let i = vCustomElementCollection.length - 1; i >= 0; i -= 1) {
5841
+ const { elm } = vCustomElementCollection[i];
5842
+ // There are two cases where the element could be undefined:
5843
+ // * when there is an error during the construction phase, and an error
5844
+ // boundary picks it, there is a possibility that the VCustomElement
5845
+ // is not properly initialized, and therefore is should be ignored.
5846
+ // * when slotted custom element is not used by the element where it is
5847
+ // slotted into it, as a result, the custom element was never
5848
+ // initialized.
5849
+ if (!isUndefined$1(elm)) {
5850
+ const childVM = getAssociatedVMIfPresent(elm);
5851
+ // The VM associated with the element might be associated undefined
5852
+ // in the case where the VM failed in the middle of its creation,
5853
+ // eg: constructor throwing before invoking super().
5854
+ if (!isUndefined$1(childVM)) {
5855
+ resetComponentStateWhenRemoved(childVM);
5856
+ }
5857
+ }
5858
+ }
6134
5859
  }
6135
5860
  function runLightChildNodesDisconnectedCallback(vm) {
6136
- const {
6137
- aChildren: adoptedChildren
6138
- } = vm;
6139
- recursivelyDisconnectChildren(adoptedChildren);
5861
+ const { aChildren: adoptedChildren } = vm;
5862
+ recursivelyDisconnectChildren(adoptedChildren);
6140
5863
  }
6141
5864
  /**
6142
5865
  * The recursion doesn't need to be a complete traversal of the vnode graph,
@@ -6146,78 +5869,72 @@ function runLightChildNodesDisconnectedCallback(vm) {
6146
5869
  * defined on its shadow.
6147
5870
  */
6148
5871
  function recursivelyDisconnectChildren(vnodes) {
6149
- for (let i = 0, len = vnodes.length; i < len; i += 1) {
6150
- const vnode = vnodes[i];
6151
- if (!isNull(vnode) && !isUndefined$1(vnode.elm)) {
6152
- switch (vnode.type) {
6153
- case 2 /* VNodeType.Element */:
6154
- recursivelyDisconnectChildren(vnode.children);
6155
- break;
6156
- case 3 /* VNodeType.CustomElement */:
6157
- {
6158
- const vm = getAssociatedVM(vnode.elm);
6159
- resetComponentStateWhenRemoved(vm);
6160
- break;
6161
- }
6162
- }
5872
+ for (let i = 0, len = vnodes.length; i < len; i += 1) {
5873
+ const vnode = vnodes[i];
5874
+ if (!isNull(vnode) && !isUndefined$1(vnode.elm)) {
5875
+ switch (vnode.type) {
5876
+ case 2 /* VNodeType.Element */:
5877
+ recursivelyDisconnectChildren(vnode.children);
5878
+ break;
5879
+ case 3 /* VNodeType.CustomElement */: {
5880
+ const vm = getAssociatedVM(vnode.elm);
5881
+ resetComponentStateWhenRemoved(vm);
5882
+ break;
5883
+ }
5884
+ }
5885
+ }
6163
5886
  }
6164
- }
6165
5887
  }
6166
5888
  // This is a super optimized mechanism to remove the content of the root node (shadow root
6167
5889
  // for shadow DOM components and the root element itself for light DOM) without having to go
6168
5890
  // into snabbdom. Especially useful when the reset is a consequence of an error, in which case the
6169
5891
  // children VNodes might not be representing the current state of the DOM.
6170
5892
  function resetComponentRoot(vm) {
6171
- const {
6172
- children,
6173
- renderRoot,
6174
- renderer: {
6175
- remove
6176
- }
6177
- } = vm;
6178
- for (let i = 0, len = children.length; i < len; i++) {
6179
- const child = children[i];
6180
- if (!isNull(child) && !isUndefined$1(child.elm)) {
6181
- remove(child.elm, renderRoot);
6182
- }
6183
- }
6184
- vm.children = EmptyArray;
6185
- runChildNodesDisconnectedCallback(vm);
6186
- vm.velements = EmptyArray;
5893
+ const { children, renderRoot, renderer: { remove }, } = vm;
5894
+ for (let i = 0, len = children.length; i < len; i++) {
5895
+ const child = children[i];
5896
+ if (!isNull(child) && !isUndefined$1(child.elm)) {
5897
+ remove(child.elm, renderRoot);
5898
+ }
5899
+ }
5900
+ vm.children = EmptyArray;
5901
+ runChildNodesDisconnectedCallback(vm);
5902
+ vm.velements = EmptyArray;
6187
5903
  }
6188
5904
  function getErrorBoundaryVM(vm) {
6189
- let currentVm = vm;
6190
- while (!isNull(currentVm)) {
6191
- if (!isUndefined$1(currentVm.def.errorCallback)) {
6192
- return currentVm;
5905
+ let currentVm = vm;
5906
+ while (!isNull(currentVm)) {
5907
+ if (!isUndefined$1(currentVm.def.errorCallback)) {
5908
+ return currentVm;
5909
+ }
5910
+ currentVm = currentVm.owner;
6193
5911
  }
6194
- currentVm = currentVm.owner;
6195
- }
6196
5912
  }
6197
5913
  function runWithBoundaryProtection(vm, owner, pre, job, post) {
6198
- let error;
6199
- pre();
6200
- try {
6201
- job();
6202
- } catch (e) {
6203
- error = Object(e);
6204
- } finally {
6205
- post();
6206
- if (!isUndefined$1(error)) {
6207
- addErrorComponentStack(vm, error);
6208
- const errorBoundaryVm = isNull(owner) ? undefined : getErrorBoundaryVM(owner);
6209
- if (isUndefined$1(errorBoundaryVm)) {
6210
- throw error; // eslint-disable-line no-unsafe-finally
6211
- }
6212
-
6213
- resetComponentRoot(vm); // remove offenders
6214
- logOperationStart(6 /* OperationId.ErrorCallback */, vm);
6215
- // error boundaries must have an ErrorCallback
6216
- const errorCallback = errorBoundaryVm.def.errorCallback;
6217
- invokeComponentCallback(errorBoundaryVm, errorCallback, [error, error.wcStack]);
6218
- logOperationEnd(6 /* OperationId.ErrorCallback */, vm);
5914
+ let error;
5915
+ pre();
5916
+ try {
5917
+ job();
5918
+ }
5919
+ catch (e) {
5920
+ error = Object(e);
5921
+ }
5922
+ finally {
5923
+ post();
5924
+ if (!isUndefined$1(error)) {
5925
+ addErrorComponentStack(vm, error);
5926
+ const errorBoundaryVm = isNull(owner) ? undefined : getErrorBoundaryVM(owner);
5927
+ if (isUndefined$1(errorBoundaryVm)) {
5928
+ throw error; // eslint-disable-line no-unsafe-finally
5929
+ }
5930
+ resetComponentRoot(vm); // remove offenders
5931
+ logOperationStart(6 /* OperationId.ErrorCallback */, vm);
5932
+ // error boundaries must have an ErrorCallback
5933
+ const errorCallback = errorBoundaryVm.def.errorCallback;
5934
+ invokeComponentCallback(errorBoundaryVm, errorCallback, [error, error.wcStack]);
5935
+ logOperationEnd(6 /* OperationId.ErrorCallback */, vm);
5936
+ }
6219
5937
  }
6220
- }
6221
5938
  }
6222
5939
 
6223
5940
  /*
@@ -6304,185 +6021,199 @@ function setHooks(hooks) {
6304
6021
  const TEMPLATE_PROPS = ['slots', 'stylesheetToken', 'stylesheets', 'renderMode'];
6305
6022
  // Expandos that may be placed on a stylesheet factory function, and which are meaningful to LWC at runtime
6306
6023
  const STYLESHEET_PROPS = [
6307
- // SEE `KEY__SCOPED_CSS` in @lwc/style-compiler
6308
- '$scoped$'];
6024
+ // SEE `KEY__SCOPED_CSS` in @lwc/style-compiler
6025
+ '$scoped$',
6026
+ ];
6309
6027
  // Via https://www.npmjs.com/package/object-observer
6310
- const ARRAY_MUTATION_METHODS = ['pop', 'push', 'shift', 'unshift', 'reverse', 'sort', 'fill', 'splice', 'copyWithin'];
6028
+ const ARRAY_MUTATION_METHODS = [
6029
+ 'pop',
6030
+ 'push',
6031
+ 'shift',
6032
+ 'unshift',
6033
+ 'reverse',
6034
+ 'sort',
6035
+ 'fill',
6036
+ 'splice',
6037
+ 'copyWithin',
6038
+ ];
6311
6039
  let mutationTrackingDisabled = false;
6312
6040
  function getOriginalArrayMethod(prop) {
6313
- switch (prop) {
6314
- case 'pop':
6315
- return ArrayPop;
6316
- case 'push':
6317
- return ArrayPush$1;
6318
- case 'shift':
6319
- return ArrayShift;
6320
- case 'unshift':
6321
- return ArrayUnshift;
6322
- case 'reverse':
6323
- return ArrayReverse;
6324
- case 'sort':
6325
- return ArraySort;
6326
- case 'fill':
6327
- return ArrayFill;
6328
- case 'splice':
6329
- return ArraySplice;
6330
- case 'copyWithin':
6331
- return ArrayCopyWithin;
6332
- }
6041
+ switch (prop) {
6042
+ case 'pop':
6043
+ return ArrayPop;
6044
+ case 'push':
6045
+ return ArrayPush$1;
6046
+ case 'shift':
6047
+ return ArrayShift;
6048
+ case 'unshift':
6049
+ return ArrayUnshift;
6050
+ case 'reverse':
6051
+ return ArrayReverse;
6052
+ case 'sort':
6053
+ return ArraySort;
6054
+ case 'fill':
6055
+ return ArrayFill;
6056
+ case 'splice':
6057
+ return ArraySplice;
6058
+ case 'copyWithin':
6059
+ return ArrayCopyWithin;
6060
+ }
6333
6061
  }
6334
6062
  function reportViolation(type, eventId, prop) {
6335
- if (process.env.NODE_ENV !== 'production') {
6336
- logWarnOnce(`Mutating the "${prop}" property on a ${type} ` + `is deprecated and will be removed in a future version of LWC. ` + `See: https://sfdc.co/template-mutation`);
6337
- }
6063
+ if (process.env.NODE_ENV !== 'production') {
6064
+ logWarnOnce(`Mutating the "${prop}" property on a ${type} ` +
6065
+ `is deprecated and will be removed in a future version of LWC. ` +
6066
+ `See: https://sfdc.co/template-mutation`);
6067
+ }
6338
6068
  }
6339
6069
  function reportTemplateViolation(prop) {
6340
- reportViolation('template', 3 /* ReportingEventId.TemplateMutation */, prop);
6070
+ reportViolation('template', "TemplateMutation" /* ReportingEventId.TemplateMutation */, prop);
6341
6071
  }
6342
6072
  function reportStylesheetViolation(prop) {
6343
- reportViolation('stylesheet', 4 /* ReportingEventId.StylesheetMutation */, prop);
6073
+ reportViolation('stylesheet', "StylesheetMutation" /* ReportingEventId.StylesheetMutation */, prop);
6344
6074
  }
6345
6075
  // Warn if the user tries to mutate a stylesheets array, e.g.:
6346
6076
  // `tmpl.stylesheets.push(someStylesheetFunction)`
6347
6077
  function warnOnArrayMutation(stylesheets) {
6348
- // We can't handle users calling Array.prototype.slice.call(tmpl.stylesheets), but
6349
- // we can at least warn when they use the most common mutation methods.
6350
- for (const prop of ARRAY_MUTATION_METHODS) {
6351
- const originalArrayMethod = getOriginalArrayMethod(prop);
6352
- stylesheets[prop] = function arrayMutationWarningWrapper() {
6353
- reportTemplateViolation('stylesheets');
6354
- // @ts-ignore
6355
- return originalArrayMethod.apply(this, arguments);
6356
- };
6357
- }
6078
+ // We can't handle users calling Array.prototype.slice.call(tmpl.stylesheets), but
6079
+ // we can at least warn when they use the most common mutation methods.
6080
+ for (const prop of ARRAY_MUTATION_METHODS) {
6081
+ const originalArrayMethod = getOriginalArrayMethod(prop);
6082
+ stylesheets[prop] = function arrayMutationWarningWrapper() {
6083
+ reportTemplateViolation('stylesheets');
6084
+ // @ts-ignore
6085
+ return originalArrayMethod.apply(this, arguments);
6086
+ };
6087
+ }
6358
6088
  }
6359
6089
  // Warn if the user tries to mutate a stylesheet factory function, e.g.:
6360
6090
  // `stylesheet.$scoped$ = true`
6361
6091
  function warnOnStylesheetFunctionMutation(stylesheet) {
6362
- for (const prop of STYLESHEET_PROPS) {
6363
- let value = stylesheet[prop];
6364
- defineProperty(stylesheet, prop, {
6365
- enumerable: true,
6366
- configurable: true,
6367
- get() {
6368
- return value;
6369
- },
6370
- set(newValue) {
6371
- reportStylesheetViolation(prop);
6372
- value = newValue;
6373
- }
6374
- });
6375
- }
6092
+ for (const prop of STYLESHEET_PROPS) {
6093
+ let value = stylesheet[prop];
6094
+ defineProperty(stylesheet, prop, {
6095
+ enumerable: true,
6096
+ configurable: true,
6097
+ get() {
6098
+ return value;
6099
+ },
6100
+ set(newValue) {
6101
+ reportStylesheetViolation(prop);
6102
+ value = newValue;
6103
+ },
6104
+ });
6105
+ }
6376
6106
  }
6377
6107
  // Warn on either array or stylesheet (function) mutation, in a deeply-nested array
6378
6108
  function trackStylesheetsMutation(stylesheets) {
6379
- traverseStylesheets(stylesheets, subStylesheets => {
6380
- if (isArray$1(subStylesheets)) {
6381
- warnOnArrayMutation(subStylesheets);
6382
- } else {
6383
- warnOnStylesheetFunctionMutation(subStylesheets);
6384
- }
6385
- });
6109
+ traverseStylesheets(stylesheets, (subStylesheets) => {
6110
+ if (isArray$1(subStylesheets)) {
6111
+ warnOnArrayMutation(subStylesheets);
6112
+ }
6113
+ else {
6114
+ warnOnStylesheetFunctionMutation(subStylesheets);
6115
+ }
6116
+ });
6386
6117
  }
6387
6118
  // Deeply freeze the entire array (of arrays) of stylesheet factory functions
6388
6119
  function deepFreeze(stylesheets) {
6389
- traverseStylesheets(stylesheets, subStylesheets => {
6390
- freeze(subStylesheets);
6391
- });
6120
+ traverseStylesheets(stylesheets, (subStylesheets) => {
6121
+ freeze(subStylesheets);
6122
+ });
6392
6123
  }
6393
6124
  // Deep-traverse an array (of arrays) of stylesheet factory functions, and call the callback for every array/function
6394
6125
  function traverseStylesheets(stylesheets, callback) {
6395
- callback(stylesheets);
6396
- for (let i = 0; i < stylesheets.length; i++) {
6397
- const stylesheet = stylesheets[i];
6398
- if (isArray$1(stylesheet)) {
6399
- traverseStylesheets(stylesheet, callback);
6400
- } else {
6401
- callback(stylesheet);
6126
+ callback(stylesheets);
6127
+ for (let i = 0; i < stylesheets.length; i++) {
6128
+ const stylesheet = stylesheets[i];
6129
+ if (isArray$1(stylesheet)) {
6130
+ traverseStylesheets(stylesheet, callback);
6131
+ }
6132
+ else {
6133
+ callback(stylesheet);
6134
+ }
6402
6135
  }
6403
- }
6404
6136
  }
6405
6137
  function trackMutations(tmpl) {
6406
- if (!isUndefined$1(tmpl.stylesheets)) {
6407
- trackStylesheetsMutation(tmpl.stylesheets);
6408
- }
6409
- for (const prop of TEMPLATE_PROPS) {
6410
- let value = tmpl[prop];
6411
- defineProperty(tmpl, prop, {
6412
- enumerable: true,
6413
- configurable: true,
6414
- get() {
6415
- return value;
6416
- },
6417
- set(newValue) {
6418
- if (!mutationTrackingDisabled) {
6419
- reportTemplateViolation(prop);
6420
- }
6421
- value = newValue;
6422
- }
6423
- });
6424
- }
6425
- const originalDescriptor = getOwnPropertyDescriptor$1(tmpl, 'stylesheetTokens');
6426
- defineProperty(tmpl, 'stylesheetTokens', {
6427
- enumerable: true,
6428
- configurable: true,
6429
- get: originalDescriptor.get,
6430
- set(value) {
6431
- reportTemplateViolation('stylesheetTokens');
6432
- // Avoid logging/reporting twice (for both stylesheetToken and stylesheetTokens)
6433
- mutationTrackingDisabled = true;
6434
- originalDescriptor.set.call(this, value);
6435
- mutationTrackingDisabled = false;
6138
+ if (!isUndefined$1(tmpl.stylesheets)) {
6139
+ trackStylesheetsMutation(tmpl.stylesheets);
6436
6140
  }
6437
- });
6141
+ for (const prop of TEMPLATE_PROPS) {
6142
+ let value = tmpl[prop];
6143
+ defineProperty(tmpl, prop, {
6144
+ enumerable: true,
6145
+ configurable: true,
6146
+ get() {
6147
+ return value;
6148
+ },
6149
+ set(newValue) {
6150
+ if (!mutationTrackingDisabled) {
6151
+ reportTemplateViolation(prop);
6152
+ }
6153
+ value = newValue;
6154
+ },
6155
+ });
6156
+ }
6157
+ const originalDescriptor = getOwnPropertyDescriptor$1(tmpl, 'stylesheetTokens');
6158
+ defineProperty(tmpl, 'stylesheetTokens', {
6159
+ enumerable: true,
6160
+ configurable: true,
6161
+ get: originalDescriptor.get,
6162
+ set(value) {
6163
+ reportTemplateViolation('stylesheetTokens');
6164
+ // Avoid logging/reporting twice (for both stylesheetToken and stylesheetTokens)
6165
+ mutationTrackingDisabled = true;
6166
+ originalDescriptor.set.call(this, value);
6167
+ mutationTrackingDisabled = false;
6168
+ },
6169
+ });
6438
6170
  }
6439
6171
  function addLegacyStylesheetTokensShim(tmpl) {
6440
- // When ENABLE_FROZEN_TEMPLATE is false, then we shim stylesheetTokens on top of stylesheetToken for anyone who
6441
- // is accessing the old internal API (backwards compat). Details: https://salesforce.quip.com/v1rmAFu2cKAr
6442
- defineProperty(tmpl, 'stylesheetTokens', {
6443
- enumerable: true,
6444
- configurable: true,
6445
- get() {
6446
- const {
6447
- stylesheetToken
6448
- } = this;
6449
- if (isUndefined$1(stylesheetToken)) {
6450
- return stylesheetToken;
6451
- }
6452
- // Shim for the old `stylesheetTokens` property
6453
- // See https://github.com/salesforce/lwc/pull/2332/files#diff-7901555acef29969adaa6583185b3e9bce475cdc6f23e799a54e0018cb18abaa
6454
- return {
6455
- hostAttribute: `${stylesheetToken}-host`,
6456
- shadowAttribute: stylesheetToken
6457
- };
6458
- },
6459
- set(value) {
6460
- // If the value is null or some other exotic object, you would be broken anyway in the past
6461
- // because the engine would try to access hostAttribute/shadowAttribute, which would throw an error.
6462
- // However it may be undefined in newer versions of LWC, so we need to guard against that case.
6463
- this.stylesheetToken = isUndefined$1(value) ? undefined : value.shadowAttribute;
6464
- }
6465
- });
6172
+ // When ENABLE_FROZEN_TEMPLATE is false, then we shim stylesheetTokens on top of stylesheetToken for anyone who
6173
+ // is accessing the old internal API (backwards compat). Details: https://salesforce.quip.com/v1rmAFu2cKAr
6174
+ defineProperty(tmpl, 'stylesheetTokens', {
6175
+ enumerable: true,
6176
+ configurable: true,
6177
+ get() {
6178
+ const { stylesheetToken } = this;
6179
+ if (isUndefined$1(stylesheetToken)) {
6180
+ return stylesheetToken;
6181
+ }
6182
+ // Shim for the old `stylesheetTokens` property
6183
+ // See https://github.com/salesforce/lwc/pull/2332/files#diff-7901555acef29969adaa6583185b3e9bce475cdc6f23e799a54e0018cb18abaa
6184
+ return {
6185
+ hostAttribute: `${stylesheetToken}-host`,
6186
+ shadowAttribute: stylesheetToken,
6187
+ };
6188
+ },
6189
+ set(value) {
6190
+ // If the value is null or some other exotic object, you would be broken anyway in the past
6191
+ // because the engine would try to access hostAttribute/shadowAttribute, which would throw an error.
6192
+ // However it may be undefined in newer versions of LWC, so we need to guard against that case.
6193
+ this.stylesheetToken = isUndefined$1(value) ? undefined : value.shadowAttribute;
6194
+ },
6195
+ });
6466
6196
  }
6467
6197
  function freezeTemplate(tmpl) {
6468
- // TODO [#2782]: remove this flag and delete the legacy behavior
6469
- if (lwcRuntimeFlags.ENABLE_FROZEN_TEMPLATE) {
6470
- // Deep freeze the template
6471
- freeze(tmpl);
6472
- if (!isUndefined$1(tmpl.stylesheets)) {
6473
- deepFreeze(tmpl.stylesheets);
6198
+ // TODO [#2782]: remove this flag and delete the legacy behavior
6199
+ if (lwcRuntimeFlags.ENABLE_FROZEN_TEMPLATE) {
6200
+ // Deep freeze the template
6201
+ freeze(tmpl);
6202
+ if (!isUndefined$1(tmpl.stylesheets)) {
6203
+ deepFreeze(tmpl.stylesheets);
6204
+ }
6474
6205
  }
6475
- } else {
6476
- // template is not frozen - shim, report, and warn
6477
- // this shim should be applied in both dev and prod
6478
- addLegacyStylesheetTokensShim(tmpl);
6479
- // When ENABLE_FROZEN_TEMPLATE is false, we want to warn in dev mode whenever someone is mutating the template
6480
- if (process.env.NODE_ENV !== 'production') {
6481
- trackMutations(tmpl);
6206
+ else {
6207
+ // template is not frozen - shim, report, and warn
6208
+ // this shim should be applied in both dev and prod
6209
+ addLegacyStylesheetTokensShim(tmpl);
6210
+ // When ENABLE_FROZEN_TEMPLATE is false, we want to warn in dev mode whenever someone is mutating the template
6211
+ if (process.env.NODE_ENV !== 'production') {
6212
+ trackMutations(tmpl);
6213
+ }
6482
6214
  }
6483
- }
6484
6215
  }
6485
- /* version: 2.37.0 */
6216
+ /* version: 2.37.2 */
6486
6217
 
6487
6218
  /*
6488
6219
  * Copyright (c) 2020, salesforce.com, inc.
@@ -6970,6 +6701,6 @@ seal(LightningElement.prototype);
6970
6701
  function createElement() {
6971
6702
  throw new Error('createElement is not supported in @lwc/engine-server, only @lwc/engine-dom.');
6972
6703
  }
6973
- /* version: 2.37.0 */
6704
+ /* version: 2.37.2 */
6974
6705
 
6975
6706
  export { LightningElement, api$1 as api, createContextProvider, createElement, freezeTemplate, getComponentDef, isComponentConstructor, parseFragment, parseFragment as parseSVGFragment, readonly, register, registerComponent, registerDecorators, registerTemplate, renderComponent, renderer, sanitizeAttribute, setFeatureFlag, setFeatureFlagForTest, setHooks, track, unwrap, wire };