lwc 2.36.0 → 2.37.1

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