lwc 2.32.1 → 2.34.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (41) hide show
  1. package/dist/engine-dom/esm/es2017/engine-dom.js +842 -595
  2. package/dist/engine-dom/iife/es2017/engine-dom.js +842 -595
  3. package/dist/engine-dom/iife/es2017/engine-dom.min.js +1 -1
  4. package/dist/engine-dom/iife/es2017/engine-dom_debug.js +758 -501
  5. package/dist/engine-dom/iife/es5/engine-dom.js +316 -177
  6. package/dist/engine-dom/iife/es5/engine-dom.min.js +1 -1
  7. package/dist/engine-dom/iife/es5/engine-dom_debug.js +329 -173
  8. package/dist/engine-dom/umd/es2017/engine-dom.js +842 -595
  9. package/dist/engine-dom/umd/es2017/engine-dom.min.js +1 -1
  10. package/dist/engine-dom/umd/es2017/engine-dom_debug.js +758 -501
  11. package/dist/engine-dom/umd/es5/engine-dom.js +316 -177
  12. package/dist/engine-dom/umd/es5/engine-dom.min.js +1 -1
  13. package/dist/engine-dom/umd/es5/engine-dom_debug.js +329 -173
  14. package/dist/engine-server/commonjs/es2017/engine-server.js +807 -507
  15. package/dist/engine-server/commonjs/es2017/engine-server.min.js +1 -1
  16. package/dist/engine-server/esm/es2017/engine-server.js +807 -507
  17. package/dist/synthetic-shadow/esm/es2017/synthetic-shadow.js +3 -3
  18. package/dist/synthetic-shadow/iife/es2017/synthetic-shadow.js +3 -3
  19. package/dist/synthetic-shadow/iife/es2017/synthetic-shadow.min.js +2 -2
  20. package/dist/synthetic-shadow/iife/es2017/synthetic-shadow_debug.js +3 -3
  21. package/dist/synthetic-shadow/iife/es5/synthetic-shadow.js +7 -5
  22. package/dist/synthetic-shadow/iife/es5/synthetic-shadow.min.js +2 -2
  23. package/dist/synthetic-shadow/iife/es5/synthetic-shadow_debug.js +7 -5
  24. package/dist/synthetic-shadow/umd/es2017/synthetic-shadow.js +3 -3
  25. package/dist/synthetic-shadow/umd/es2017/synthetic-shadow.min.js +2 -2
  26. package/dist/synthetic-shadow/umd/es2017/synthetic-shadow_debug.js +3 -3
  27. package/dist/synthetic-shadow/umd/es5/synthetic-shadow.js +7 -5
  28. package/dist/synthetic-shadow/umd/es5/synthetic-shadow.min.js +2 -2
  29. package/dist/synthetic-shadow/umd/es5/synthetic-shadow_debug.js +7 -5
  30. package/dist/wire-service/esm/es2017/wire-service.js +2 -2
  31. package/dist/wire-service/iife/es2017/wire-service.js +2 -2
  32. package/dist/wire-service/iife/es2017/wire-service_debug.js +2 -2
  33. package/dist/wire-service/iife/es5/wire-service.js +5 -3
  34. package/dist/wire-service/iife/es5/wire-service.min.js +1 -1
  35. package/dist/wire-service/iife/es5/wire-service_debug.js +5 -3
  36. package/dist/wire-service/umd/es2017/wire-service.js +2 -2
  37. package/dist/wire-service/umd/es2017/wire-service_debug.js +2 -2
  38. package/dist/wire-service/umd/es5/wire-service.js +5 -3
  39. package/dist/wire-service/umd/es5/wire-service.min.js +1 -1
  40. package/dist/wire-service/umd/es5/wire-service_debug.js +5 -3
  41. package/package.json +7 -7
@@ -121,6 +121,9 @@ var LWC = (function (exports) {
121
121
  * The above list of 46 aria attributes is consistent with the following resources:
122
122
  * https://github.com/w3c/aria/pull/708/files#diff-eacf331f0ffc35d4b482f1d15a887d3bR11060
123
123
  * https://wicg.github.io/aom/spec/aria-reflection.html
124
+ *
125
+ * NOTE: If you update this list, please update test files that implicitly reference this list!
126
+ * Searching the codebase for `aria-flowto` and `ariaFlowTo` should be good enough to find all usages.
124
127
  */
125
128
  const AriaPropertyNames = [
126
129
  'ariaActiveDescendant',
@@ -344,91 +347,9 @@ var LWC = (function (exports) {
344
347
  * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
345
348
  */
346
349
  // Increment whenever the LWC template compiler changes
347
- const LWC_VERSION = "2.32.1";
350
+ const LWC_VERSION = "2.34.0";
348
351
  const LWC_VERSION_COMMENT_REGEX = /\/\*LWC compiler v([\d.]+)\*\/\s*}/;
349
- /** version: 2.32.1 */
350
-
351
- /**
352
- * Copyright (C) 2018 salesforce.com, inc.
353
- */
354
-
355
- /*
356
- * Copyright (c) 2018, salesforce.com, inc.
357
- * All rights reserved.
358
- * SPDX-License-Identifier: MIT
359
- * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
360
- */
361
- function detect(propName) {
362
- return getOwnPropertyDescriptor$1(Element.prototype, propName) === undefined;
363
- }
364
-
365
- /*
366
- * Copyright (c) 2018, salesforce.com, inc.
367
- * All rights reserved.
368
- * SPDX-License-Identifier: MIT
369
- * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
370
- */
371
- const nodeToAriaPropertyValuesMap = new WeakMap();
372
- function getAriaPropertyMap(elm) {
373
- let map = nodeToAriaPropertyValuesMap.get(elm);
374
- if (map === undefined) {
375
- map = {};
376
- nodeToAriaPropertyValuesMap.set(elm, map);
377
- }
378
- return map;
379
- }
380
- function getNormalizedAriaPropertyValue(value) {
381
- return value == null ? null : String(value);
382
- }
383
- function createAriaPropertyPropertyDescriptor(propName, attrName) {
384
- return {
385
- get() {
386
- const map = getAriaPropertyMap(this);
387
- if (hasOwnProperty$1.call(map, propName)) {
388
- return map[propName];
389
- }
390
- // otherwise just reflect what's in the attribute
391
- return this.hasAttribute(attrName) ? this.getAttribute(attrName) : null;
392
- },
393
- set(newValue) {
394
- const normalizedValue = getNormalizedAriaPropertyValue(newValue);
395
- const map = getAriaPropertyMap(this);
396
- map[propName] = normalizedValue;
397
- // reflect into the corresponding attribute
398
- if (newValue === null) {
399
- this.removeAttribute(attrName);
400
- }
401
- else {
402
- this.setAttribute(attrName, newValue);
403
- }
404
- },
405
- configurable: true,
406
- enumerable: true,
407
- };
408
- }
409
- function patch$1(propName) {
410
- // Typescript is inferring the wrong function type for this particular
411
- // overloaded method: https://github.com/Microsoft/TypeScript/issues/27972
412
- // @ts-ignore type-mismatch
413
- const attrName = AriaPropNameToAttrNameMap[propName];
414
- const descriptor = createAriaPropertyPropertyDescriptor(propName, attrName);
415
- Object.defineProperty(Element.prototype, propName, descriptor);
416
- }
417
-
418
- /*
419
- * Copyright (c) 2018, salesforce.com, inc.
420
- * All rights reserved.
421
- * SPDX-License-Identifier: MIT
422
- * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
423
- */
424
- const ElementPrototypeAriaPropertyNames = keys(AriaPropNameToAttrNameMap);
425
- for (let i = 0, len = ElementPrototypeAriaPropertyNames.length; i < len; i += 1) {
426
- const propName = ElementPrototypeAriaPropertyNames[i];
427
- if (detect(propName)) {
428
- patch$1(propName);
429
- }
430
- }
431
- /** version: 2.32.1 */
352
+ /** version: 2.34.0 */
432
353
 
433
354
  /**
434
355
  * Copyright (C) 2018 salesforce.com, inc.
@@ -450,6 +371,8 @@ var LWC = (function (exports) {
450
371
  DISABLE_LIGHT_DOM_UNSCOPED_CSS: null,
451
372
  ENABLE_SCOPED_CUSTOM_ELEMENT_REGISTRY: null,
452
373
  ENABLE_FROZEN_TEMPLATE: null,
374
+ DISABLE_ARIA_REFLECTION_POLYFILL: null,
375
+ ENABLE_PROGRAMMATIC_STYLESHEETS: null,
453
376
  };
454
377
  if (!_globalThis.lwcRuntimeFlags) {
455
378
  Object.defineProperty(_globalThis, 'lwcRuntimeFlags', { value: create(null) });
@@ -503,7 +426,83 @@ var LWC = (function (exports) {
503
426
  setFeatureFlag(name, value);
504
427
  }
505
428
  }
506
- /** version: 2.32.1 */
429
+ /** version: 2.34.0 */
430
+
431
+ /**
432
+ * Copyright (C) 2018 salesforce.com, inc.
433
+ */
434
+
435
+ /*
436
+ * Copyright (c) 2018, salesforce.com, inc.
437
+ * All rights reserved.
438
+ * SPDX-License-Identifier: MIT
439
+ * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
440
+ */
441
+ function detect(propName, prototype) {
442
+ return isUndefined$1(getOwnPropertyDescriptor$1(prototype, propName));
443
+ }
444
+
445
+ /*
446
+ * Copyright (c) 2018, salesforce.com, inc.
447
+ * All rights reserved.
448
+ * SPDX-License-Identifier: MIT
449
+ * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
450
+ */
451
+ function createAriaPropertyPropertyDescriptor(attrName) {
452
+ // Note that we need to call this.{get,set,has,remove}Attribute rather than dereferencing
453
+ // from Element.prototype, because these methods are overridden in LightningElement.
454
+ return {
455
+ get() {
456
+ // reflect what's in the attribute
457
+ return this.hasAttribute(attrName) ? this.getAttribute(attrName) : null;
458
+ },
459
+ set(newValue) {
460
+ // reflect into the corresponding attribute
461
+ if (isNull(newValue)) {
462
+ this.removeAttribute(attrName);
463
+ }
464
+ else {
465
+ this.setAttribute(attrName, newValue);
466
+ }
467
+ },
468
+ configurable: true,
469
+ enumerable: true,
470
+ };
471
+ }
472
+ function patch$1(propName, prototype) {
473
+ const attrName = AriaPropNameToAttrNameMap[propName];
474
+ const descriptor = createAriaPropertyPropertyDescriptor(attrName);
475
+ defineProperty(prototype, propName, descriptor);
476
+ }
477
+
478
+ /*
479
+ * Copyright (c) 2018, salesforce.com, inc.
480
+ * All rights reserved.
481
+ * SPDX-License-Identifier: MIT
482
+ * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
483
+ */
484
+ function applyAriaReflection(prototype = Element.prototype) {
485
+ const ElementPrototypeAriaPropertyNames = keys(AriaPropNameToAttrNameMap);
486
+ for (let i = 0, len = ElementPrototypeAriaPropertyNames.length; i < len; i += 1) {
487
+ const propName = ElementPrototypeAriaPropertyNames[i];
488
+ if (detect(propName, prototype)) {
489
+ patch$1(propName, prototype);
490
+ }
491
+ }
492
+ }
493
+ /** version: 2.34.0 */
494
+
495
+ /*
496
+ * Copyright (c) 2018, salesforce.com, inc.
497
+ * All rights reserved.
498
+ * SPDX-License-Identifier: MIT
499
+ * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
500
+ */
501
+ if (!lwcRuntimeFlags.DISABLE_ARIA_REFLECTION_POLYFILL) {
502
+ // If DISABLE_ARIA_REFLECTION_POLYFILL is false, then we need to apply the ARIA reflection polyfill globally,
503
+ // i.e. to the global Element.prototype
504
+ applyAriaReflection();
505
+ }
507
506
 
508
507
  /*
509
508
  * Copyright (c) 2018, salesforce.com, inc.
@@ -820,6 +819,7 @@ var LWC = (function (exports) {
820
819
  if (!isUndefined$1(vm)) {
821
820
  msg = `${msg}\n${getComponentStack(vm)}`;
822
821
  }
822
+ // In Jest tests, reduce the warning and error verbosity by not printing the callstack
823
823
  if (process.env.NODE_ENV === 'test') {
824
824
  /* eslint-disable-next-line no-console */
825
825
  console[method](msg);
@@ -889,6 +889,9 @@ var LWC = (function (exports) {
889
889
  // Global HTML Attributes & Properties
890
890
  // https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes
891
891
  // https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement
892
+ //
893
+ // If you update this list, check for test files that recapitulate the same list. Searching the codebase
894
+ // for e.g. "dropzone" should suffice.
892
895
  const globalHTMLProperties = assign(create(null), {
893
896
  accessKey: {
894
897
  attribute: 'accesskey',
@@ -1922,46 +1925,51 @@ var LWC = (function (exports) {
1922
1925
  * for the Base Lightning Element, it also include the reactivity bit, so the standard property is reactive.
1923
1926
  */
1924
1927
  function createBridgeToElementDescriptor(propName, descriptor) {
1925
- const { get, set, enumerable, configurable } = descriptor;
1926
- if (!isFunction$1(get)) {
1927
- if (process.env.NODE_ENV !== 'production') {
1928
- assert.fail(`Detected invalid public property descriptor for HTMLElement.prototype.${propName} definition. Missing the standard getter.`);
1929
- }
1930
- throw new TypeError();
1928
+ const {
1929
+ get,
1930
+ set,
1931
+ enumerable,
1932
+ configurable
1933
+ } = descriptor;
1934
+ if (!isFunction$1(get)) {
1935
+ if (process.env.NODE_ENV !== 'production') {
1936
+ assert.fail(`Detected invalid public property descriptor for HTMLElement.prototype.${propName} definition. Missing the standard getter.`);
1931
1937
  }
1932
- if (!isFunction$1(set)) {
1938
+ throw new TypeError();
1939
+ }
1940
+ if (!isFunction$1(set)) {
1941
+ if (process.env.NODE_ENV !== 'production') {
1942
+ assert.fail(`Detected invalid public property descriptor for HTMLElement.prototype.${propName} definition. Missing the standard setter.`);
1943
+ }
1944
+ throw new TypeError();
1945
+ }
1946
+ return {
1947
+ enumerable,
1948
+ configurable,
1949
+ get() {
1950
+ const vm = getAssociatedVM(this);
1951
+ if (isBeingConstructed(vm)) {
1933
1952
  if (process.env.NODE_ENV !== 'production') {
1934
- assert.fail(`Detected invalid public property descriptor for HTMLElement.prototype.${propName} definition. Missing the standard setter.`);
1953
+ 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);
1935
1954
  }
1936
- throw new TypeError();
1955
+ return;
1956
+ }
1957
+ componentValueObserved(vm, propName);
1958
+ return get.call(vm.elm);
1959
+ },
1960
+ set(newValue) {
1961
+ const vm = getAssociatedVM(this);
1962
+ if (process.env.NODE_ENV !== 'production') {
1963
+ const vmBeingRendered = getVMBeingRendered();
1964
+ assert.invariant(!isInvokingRender, `${vmBeingRendered}.render() method has side effects on the state of ${vm}.${propName}`);
1965
+ 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}`);
1966
+ assert.isFalse(isBeingConstructed(vm), `Failed to construct '${getComponentTag(vm)}': The result must not have attributes.`);
1967
+ assert.invariant(!isObject(newValue) || isNull(newValue), `Invalid value "${newValue}" for "${propName}" of ${vm}. Value cannot be an object, must be a primitive value.`);
1968
+ }
1969
+ updateComponentValue(vm, propName, newValue);
1970
+ return set.call(vm.elm, newValue);
1937
1971
  }
1938
- return {
1939
- enumerable,
1940
- configurable,
1941
- get() {
1942
- const vm = getAssociatedVM(this);
1943
- if (isBeingConstructed(vm)) {
1944
- if (process.env.NODE_ENV !== 'production') {
1945
- 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);
1946
- }
1947
- return;
1948
- }
1949
- componentValueObserved(vm, propName);
1950
- return get.call(vm.elm);
1951
- },
1952
- set(newValue) {
1953
- const vm = getAssociatedVM(this);
1954
- if (process.env.NODE_ENV !== 'production') {
1955
- const vmBeingRendered = getVMBeingRendered();
1956
- assert.invariant(!isInvokingRender, `${vmBeingRendered}.render() method has side effects on the state of ${vm}.${propName}`);
1957
- 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}`);
1958
- assert.isFalse(isBeingConstructed(vm), `Failed to construct '${getComponentTag(vm)}': The result must not have attributes.`);
1959
- assert.invariant(!isObject(newValue) || isNull(newValue), `Invalid value "${newValue}" for "${propName}" of ${vm}. Value cannot be an object, must be a primitive value.`);
1960
- }
1961
- updateComponentValue(vm, propName, newValue);
1962
- return set.call(vm.elm, newValue);
1963
- },
1964
- };
1972
+ };
1965
1973
  }
1966
1974
  const EMPTY_REFS = freeze(create(null));
1967
1975
  const refsCache = new WeakMap();
@@ -1971,345 +1979,442 @@ var LWC = (function (exports) {
1971
1979
  **/
1972
1980
  // @ts-ignore
1973
1981
  const LightningElement = function () {
1974
- // This should be as performant as possible, while any initialization should be done lazily
1975
- if (isNull(vmBeingConstructed)) {
1976
- // Thrown when doing something like `new LightningElement()` or
1977
- // `class Foo extends LightningElement {}; new Foo()`
1978
- throw new TypeError('Illegal constructor');
1979
- }
1980
- const vm = vmBeingConstructed;
1981
- const { def, elm } = vm;
1982
- const { bridge } = def;
1982
+ // This should be as performant as possible, while any initialization should be done lazily
1983
+ if (isNull(vmBeingConstructed)) {
1984
+ // Thrown when doing something like `new LightningElement()` or
1985
+ // `class Foo extends LightningElement {}; new Foo()`
1986
+ throw new TypeError('Illegal constructor');
1987
+ }
1988
+ const vm = vmBeingConstructed;
1989
+ const {
1990
+ def,
1991
+ elm
1992
+ } = vm;
1993
+ const {
1994
+ bridge
1995
+ } = def;
1996
+ if (process.env.NODE_ENV !== 'production') {
1997
+ const {
1998
+ assertInstanceOfHTMLElement
1999
+ } = vm.renderer;
2000
+ assertInstanceOfHTMLElement(vm.elm, `Component creation requires a DOM element to be associated to ${vm}.`);
2001
+ }
2002
+ const component = this;
2003
+ setPrototypeOf(elm, bridge.prototype);
2004
+ vm.component = this;
2005
+ // Locker hooks assignment. When the LWC engine run with Locker, Locker intercepts all the new
2006
+ // component creation and passes hooks to instrument all the component interactions with the
2007
+ // engine. We are intentionally hiding this argument from the formal API of LightningElement
2008
+ // because we don't want folks to know about it just yet.
2009
+ if (arguments.length === 1) {
2010
+ const {
2011
+ callHook,
2012
+ setHook,
2013
+ getHook
2014
+ } = arguments[0];
2015
+ vm.callHook = callHook;
2016
+ vm.setHook = setHook;
2017
+ vm.getHook = getHook;
2018
+ }
2019
+ markLockerLiveObject(this);
2020
+ // Linking elm, shadow root and component with the VM.
2021
+ associateVM(component, vm);
2022
+ associateVM(elm, vm);
2023
+ if (vm.renderMode === 1 /* RenderMode.Shadow */) {
2024
+ vm.renderRoot = doAttachShadow(vm);
2025
+ } else {
2026
+ vm.renderRoot = elm;
2027
+ }
2028
+ // Adding extra guard rails in DEV mode.
2029
+ if (process.env.NODE_ENV !== 'production') {
2030
+ patchCustomElementWithRestrictions(elm);
2031
+ patchComponentWithRestrictions(component);
2032
+ }
2033
+ return this;
2034
+ };
2035
+ function doAttachShadow(vm) {
2036
+ const {
2037
+ elm,
2038
+ mode,
2039
+ shadowMode,
2040
+ def: {
2041
+ ctor
2042
+ },
2043
+ renderer: {
2044
+ attachShadow
2045
+ }
2046
+ } = vm;
2047
+ const shadowRoot = attachShadow(elm, {
2048
+ [KEY__SYNTHETIC_MODE]: shadowMode === 1 /* ShadowMode.Synthetic */,
2049
+ delegatesFocus: Boolean(ctor.delegatesFocus),
2050
+ mode
2051
+ });
2052
+ vm.shadowRoot = shadowRoot;
2053
+ associateVM(shadowRoot, vm);
2054
+ if (process.env.NODE_ENV !== 'production') {
2055
+ patchShadowRootWithRestrictions(shadowRoot);
2056
+ }
2057
+ return shadowRoot;
2058
+ }
2059
+ function warnIfInvokedDuringConstruction(vm, methodOrPropName) {
2060
+ if (isBeingConstructed(vm)) {
2061
+ 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.`);
2062
+ }
2063
+ }
2064
+ // @ts-ignore
2065
+ LightningElement.prototype = {
2066
+ constructor: LightningElement,
2067
+ dispatchEvent(event) {
2068
+ const vm = getAssociatedVM(this);
2069
+ const {
2070
+ elm,
2071
+ renderer: {
2072
+ dispatchEvent
2073
+ }
2074
+ } = vm;
2075
+ return dispatchEvent(elm, event);
2076
+ },
2077
+ addEventListener(type, listener, options) {
2078
+ const vm = getAssociatedVM(this);
2079
+ const {
2080
+ elm,
2081
+ renderer: {
2082
+ addEventListener
2083
+ }
2084
+ } = vm;
1983
2085
  if (process.env.NODE_ENV !== 'production') {
1984
- const { assertInstanceOfHTMLElement } = vm.renderer;
1985
- assertInstanceOfHTMLElement(vm.elm, `Component creation requires a DOM element to be associated to ${vm}.`);
1986
- }
1987
- const component = this;
1988
- setPrototypeOf(elm, bridge.prototype);
1989
- vm.component = this;
1990
- // Locker hooks assignment. When the LWC engine run with Locker, Locker intercepts all the new
1991
- // component creation and passes hooks to instrument all the component interactions with the
1992
- // engine. We are intentionally hiding this argument from the formal API of LightningElement
1993
- // because we don't want folks to know about it just yet.
1994
- if (arguments.length === 1) {
1995
- const { callHook, setHook, getHook } = arguments[0];
1996
- vm.callHook = callHook;
1997
- vm.setHook = setHook;
1998
- vm.getHook = getHook;
1999
- }
2000
- markLockerLiveObject(this);
2001
- // Linking elm, shadow root and component with the VM.
2002
- associateVM(component, vm);
2003
- associateVM(elm, vm);
2004
- if (vm.renderMode === 1 /* RenderMode.Shadow */) {
2005
- vm.renderRoot = doAttachShadow(vm);
2086
+ const vmBeingRendered = getVMBeingRendered();
2087
+ assert.invariant(!isInvokingRender, `${vmBeingRendered}.render() method has side effects on the state of ${vm} by adding an event listener for "${type}".`);
2088
+ assert.invariant(!isUpdatingTemplate, `Updating the template of ${vmBeingRendered} has side effects on the state of ${vm} by adding an event listener for "${type}".`);
2089
+ assert.invariant(isFunction$1(listener), `Invalid second argument for this.addEventListener() in ${vm} for event "${type}". Expected an EventListener but received ${listener}.`);
2090
+ }
2091
+ const wrappedListener = getWrappedComponentsListener(vm, listener);
2092
+ addEventListener(elm, type, wrappedListener, options);
2093
+ },
2094
+ removeEventListener(type, listener, options) {
2095
+ const vm = getAssociatedVM(this);
2096
+ const {
2097
+ elm,
2098
+ renderer: {
2099
+ removeEventListener
2100
+ }
2101
+ } = vm;
2102
+ const wrappedListener = getWrappedComponentsListener(vm, listener);
2103
+ removeEventListener(elm, type, wrappedListener, options);
2104
+ },
2105
+ hasAttribute(name) {
2106
+ const vm = getAssociatedVM(this);
2107
+ const {
2108
+ elm,
2109
+ renderer: {
2110
+ getAttribute
2111
+ }
2112
+ } = vm;
2113
+ return !isNull(getAttribute(elm, name));
2114
+ },
2115
+ hasAttributeNS(namespace, name) {
2116
+ const vm = getAssociatedVM(this);
2117
+ const {
2118
+ elm,
2119
+ renderer: {
2120
+ getAttribute
2121
+ }
2122
+ } = vm;
2123
+ return !isNull(getAttribute(elm, name, namespace));
2124
+ },
2125
+ removeAttribute(name) {
2126
+ const vm = getAssociatedVM(this);
2127
+ const {
2128
+ elm,
2129
+ renderer: {
2130
+ removeAttribute
2131
+ }
2132
+ } = vm;
2133
+ unlockAttribute(elm, name);
2134
+ removeAttribute(elm, name);
2135
+ lockAttribute();
2136
+ },
2137
+ removeAttributeNS(namespace, name) {
2138
+ const {
2139
+ elm,
2140
+ renderer: {
2141
+ removeAttribute
2142
+ }
2143
+ } = getAssociatedVM(this);
2144
+ unlockAttribute(elm, name);
2145
+ removeAttribute(elm, name, namespace);
2146
+ lockAttribute();
2147
+ },
2148
+ getAttribute(name) {
2149
+ const vm = getAssociatedVM(this);
2150
+ const {
2151
+ elm
2152
+ } = vm;
2153
+ const {
2154
+ getAttribute
2155
+ } = vm.renderer;
2156
+ return getAttribute(elm, name);
2157
+ },
2158
+ getAttributeNS(namespace, name) {
2159
+ const vm = getAssociatedVM(this);
2160
+ const {
2161
+ elm
2162
+ } = vm;
2163
+ const {
2164
+ getAttribute
2165
+ } = vm.renderer;
2166
+ return getAttribute(elm, name, namespace);
2167
+ },
2168
+ setAttribute(name, value) {
2169
+ const vm = getAssociatedVM(this);
2170
+ const {
2171
+ elm,
2172
+ renderer: {
2173
+ setAttribute
2174
+ }
2175
+ } = vm;
2176
+ if (process.env.NODE_ENV !== 'production') {
2177
+ assert.isFalse(isBeingConstructed(vm), `Failed to construct '${getComponentTag(vm)}': The result must not have attributes.`);
2178
+ }
2179
+ unlockAttribute(elm, name);
2180
+ setAttribute(elm, name, value);
2181
+ lockAttribute();
2182
+ },
2183
+ setAttributeNS(namespace, name, value) {
2184
+ const vm = getAssociatedVM(this);
2185
+ const {
2186
+ elm,
2187
+ renderer: {
2188
+ setAttribute
2189
+ }
2190
+ } = vm;
2191
+ if (process.env.NODE_ENV !== 'production') {
2192
+ assert.isFalse(isBeingConstructed(vm), `Failed to construct '${getComponentTag(vm)}': The result must not have attributes.`);
2193
+ }
2194
+ unlockAttribute(elm, name);
2195
+ setAttribute(elm, name, value, namespace);
2196
+ lockAttribute();
2197
+ },
2198
+ getBoundingClientRect() {
2199
+ const vm = getAssociatedVM(this);
2200
+ const {
2201
+ elm,
2202
+ renderer: {
2203
+ getBoundingClientRect
2204
+ }
2205
+ } = vm;
2206
+ if (process.env.NODE_ENV !== 'production') {
2207
+ warnIfInvokedDuringConstruction(vm, 'getBoundingClientRect()');
2006
2208
  }
2007
- else {
2008
- vm.renderRoot = elm;
2209
+ return getBoundingClientRect(elm);
2210
+ },
2211
+ get isConnected() {
2212
+ const vm = getAssociatedVM(this);
2213
+ const {
2214
+ elm,
2215
+ renderer: {
2216
+ isConnected
2217
+ }
2218
+ } = vm;
2219
+ return isConnected(elm);
2220
+ },
2221
+ get classList() {
2222
+ const vm = getAssociatedVM(this);
2223
+ const {
2224
+ elm,
2225
+ renderer: {
2226
+ getClassList
2227
+ }
2228
+ } = vm;
2229
+ if (process.env.NODE_ENV !== 'production') {
2230
+ // TODO [#1290]: this still fails in dev but works in production, eventually, we should
2231
+ // just throw in all modes
2232
+ 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.`);
2233
+ }
2234
+ return getClassList(elm);
2235
+ },
2236
+ get template() {
2237
+ const vm = getAssociatedVM(this);
2238
+ if (process.env.NODE_ENV !== 'production') {
2239
+ if (vm.renderMode === 0 /* RenderMode.Light */) {
2240
+ 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`.');
2241
+ }
2242
+ }
2243
+ return vm.shadowRoot;
2244
+ },
2245
+ get refs() {
2246
+ const vm = getAssociatedVM(this);
2247
+ if (isUpdatingTemplate) {
2248
+ if (process.env.NODE_ENV !== 'production') {
2249
+ 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().`);
2250
+ }
2251
+ // If the template is in the process of being updated, then we don't want to go through the normal
2252
+ // process of returning the refs and caching them, because the state of the refs is unstable.
2253
+ // This can happen if e.g. a template contains `<div class={foo}></div>` and `foo` is computed
2254
+ // based on `this.refs.bar`.
2255
+ return;
2009
2256
  }
2010
- // Adding extra guard rails in DEV mode.
2011
2257
  if (process.env.NODE_ENV !== 'production') {
2012
- patchCustomElementWithRestrictions(elm);
2013
- patchComponentWithRestrictions(component);
2258
+ warnIfInvokedDuringConstruction(vm, 'refs');
2014
2259
  }
2015
- return this;
2016
- };
2017
- function doAttachShadow(vm) {
2018
- const { elm, mode, shadowMode, def: { ctor }, renderer: { attachShadow }, } = vm;
2019
- const shadowRoot = attachShadow(elm, {
2020
- [KEY__SYNTHETIC_MODE]: shadowMode === 1 /* ShadowMode.Synthetic */,
2021
- delegatesFocus: Boolean(ctor.delegatesFocus),
2022
- mode,
2260
+ const {
2261
+ refVNodes,
2262
+ hasRefVNodes,
2263
+ cmpTemplate
2264
+ } = vm;
2265
+ // If the `cmpTemplate` is null, that means that the template has not been rendered yet. Most likely this occurs
2266
+ // if `this.refs` is called during the `connectedCallback` phase. The DOM elements have not been rendered yet,
2267
+ // so log a warning. Note we also check `isBeingConstructed()` to avoid a double warning (due to
2268
+ // `warnIfInvokedDuringConstruction` above).
2269
+ if (process.env.NODE_ENV !== 'production' && isNull(cmpTemplate) && !isBeingConstructed(vm)) {
2270
+ 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().`);
2271
+ }
2272
+ // For backwards compatibility with component written before template refs
2273
+ // were introduced, we return undefined if the template has no refs defined
2274
+ // anywhere. This fixes components that may want to add an expando called `refs`
2275
+ // and are checking if it exists with `if (this.refs)` before adding it.
2276
+ // Note it is not sufficient to just check if `refVNodes` is null or empty,
2277
+ // because a template may have `lwc:ref` defined within a falsy `if:true` block.
2278
+ if (!hasRefVNodes) {
2279
+ return;
2280
+ }
2281
+ // For templates that are using `lwc:ref`, if there are no refs currently available
2282
+ // (e.g. refs inside of a falsy `if:true` block), we return an empty object.
2283
+ if (isNull(refVNodes)) {
2284
+ return EMPTY_REFS;
2285
+ }
2286
+ // The refNodes can be cached based on the refVNodes, since the refVNodes
2287
+ // are recreated from scratch every time the template is rendered.
2288
+ // This happens with `vm.refVNodes = null` in `template.ts` in `@lwc/engine-core`.
2289
+ let refs = refsCache.get(refVNodes);
2290
+ if (isUndefined$1(refs)) {
2291
+ refs = create(null);
2292
+ for (const key of keys(refVNodes)) {
2293
+ refs[key] = refVNodes[key].elm;
2294
+ }
2295
+ freeze(refs);
2296
+ refsCache.set(refVNodes, refs);
2297
+ }
2298
+ return refs;
2299
+ },
2300
+ // For backwards compat, we allow component authors to set `refs` as an expando
2301
+ set refs(value) {
2302
+ defineProperty(this, 'refs', {
2303
+ configurable: true,
2304
+ enumerable: true,
2305
+ writable: true,
2306
+ value
2023
2307
  });
2024
- vm.shadowRoot = shadowRoot;
2025
- associateVM(shadowRoot, vm);
2308
+ },
2309
+ get shadowRoot() {
2310
+ // From within the component instance, the shadowRoot is always reported as "closed".
2311
+ // Authors should rely on this.template instead.
2312
+ return null;
2313
+ },
2314
+ get children() {
2315
+ const vm = getAssociatedVM(this);
2316
+ const renderer = vm.renderer;
2026
2317
  if (process.env.NODE_ENV !== 'production') {
2027
- patchShadowRootWithRestrictions(shadowRoot);
2318
+ warnIfInvokedDuringConstruction(vm, 'children');
2028
2319
  }
2029
- return shadowRoot;
2030
- }
2031
- function warnIfInvokedDuringConstruction(vm, methodOrPropName) {
2032
- if (isBeingConstructed(vm)) {
2033
- 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.`);
2320
+ return renderer.getChildren(vm.elm);
2321
+ },
2322
+ get childNodes() {
2323
+ const vm = getAssociatedVM(this);
2324
+ const renderer = vm.renderer;
2325
+ if (process.env.NODE_ENV !== 'production') {
2326
+ warnIfInvokedDuringConstruction(vm, 'childNodes');
2034
2327
  }
2035
- }
2036
- // @ts-ignore
2037
- LightningElement.prototype = {
2038
- constructor: LightningElement,
2039
- dispatchEvent(event) {
2040
- const vm = getAssociatedVM(this);
2041
- const { elm, renderer: { dispatchEvent }, } = vm;
2042
- return dispatchEvent(elm, event);
2043
- },
2044
- addEventListener(type, listener, options) {
2045
- const vm = getAssociatedVM(this);
2046
- const { elm, renderer: { addEventListener }, } = vm;
2047
- if (process.env.NODE_ENV !== 'production') {
2048
- const vmBeingRendered = getVMBeingRendered();
2049
- assert.invariant(!isInvokingRender, `${vmBeingRendered}.render() method has side effects on the state of ${vm} by adding an event listener for "${type}".`);
2050
- assert.invariant(!isUpdatingTemplate, `Updating the template of ${vmBeingRendered} has side effects on the state of ${vm} by adding an event listener for "${type}".`);
2051
- assert.invariant(isFunction$1(listener), `Invalid second argument for this.addEventListener() in ${vm} for event "${type}". Expected an EventListener but received ${listener}.`);
2052
- }
2053
- const wrappedListener = getWrappedComponentsListener(vm, listener);
2054
- addEventListener(elm, type, wrappedListener, options);
2055
- },
2056
- removeEventListener(type, listener, options) {
2057
- const vm = getAssociatedVM(this);
2058
- const { elm, renderer: { removeEventListener }, } = vm;
2059
- const wrappedListener = getWrappedComponentsListener(vm, listener);
2060
- removeEventListener(elm, type, wrappedListener, options);
2061
- },
2062
- hasAttribute(name) {
2063
- const vm = getAssociatedVM(this);
2064
- const { elm, renderer: { getAttribute }, } = vm;
2065
- return !isNull(getAttribute(elm, name));
2066
- },
2067
- hasAttributeNS(namespace, name) {
2068
- const vm = getAssociatedVM(this);
2069
- const { elm, renderer: { getAttribute }, } = vm;
2070
- return !isNull(getAttribute(elm, name, namespace));
2071
- },
2072
- removeAttribute(name) {
2073
- const vm = getAssociatedVM(this);
2074
- const { elm, renderer: { removeAttribute }, } = vm;
2075
- unlockAttribute(elm, name);
2076
- removeAttribute(elm, name);
2077
- lockAttribute();
2078
- },
2079
- removeAttributeNS(namespace, name) {
2080
- const { elm, renderer: { removeAttribute }, } = getAssociatedVM(this);
2081
- unlockAttribute(elm, name);
2082
- removeAttribute(elm, name, namespace);
2083
- lockAttribute();
2084
- },
2085
- getAttribute(name) {
2086
- const vm = getAssociatedVM(this);
2087
- const { elm } = vm;
2088
- const { getAttribute } = vm.renderer;
2089
- return getAttribute(elm, name);
2090
- },
2091
- getAttributeNS(namespace, name) {
2092
- const vm = getAssociatedVM(this);
2093
- const { elm } = vm;
2094
- const { getAttribute } = vm.renderer;
2095
- return getAttribute(elm, name, namespace);
2096
- },
2097
- setAttribute(name, value) {
2098
- const vm = getAssociatedVM(this);
2099
- const { elm, renderer: { setAttribute }, } = vm;
2100
- if (process.env.NODE_ENV !== 'production') {
2101
- assert.isFalse(isBeingConstructed(vm), `Failed to construct '${getComponentTag(vm)}': The result must not have attributes.`);
2102
- }
2103
- unlockAttribute(elm, name);
2104
- setAttribute(elm, name, value);
2105
- lockAttribute();
2106
- },
2107
- setAttributeNS(namespace, name, value) {
2108
- const vm = getAssociatedVM(this);
2109
- const { elm, renderer: { setAttribute }, } = vm;
2110
- if (process.env.NODE_ENV !== 'production') {
2111
- assert.isFalse(isBeingConstructed(vm), `Failed to construct '${getComponentTag(vm)}': The result must not have attributes.`);
2112
- }
2113
- unlockAttribute(elm, name);
2114
- setAttribute(elm, name, value, namespace);
2115
- lockAttribute();
2116
- },
2117
- getBoundingClientRect() {
2118
- const vm = getAssociatedVM(this);
2119
- const { elm, renderer: { getBoundingClientRect }, } = vm;
2120
- if (process.env.NODE_ENV !== 'production') {
2121
- warnIfInvokedDuringConstruction(vm, 'getBoundingClientRect()');
2122
- }
2123
- return getBoundingClientRect(elm);
2124
- },
2125
- get isConnected() {
2126
- const vm = getAssociatedVM(this);
2127
- const { elm, renderer: { isConnected }, } = vm;
2128
- return isConnected(elm);
2129
- },
2130
- get classList() {
2131
- const vm = getAssociatedVM(this);
2132
- const { elm, renderer: { getClassList }, } = vm;
2133
- if (process.env.NODE_ENV !== 'production') {
2134
- // TODO [#1290]: this still fails in dev but works in production, eventually, we should
2135
- // just throw in all modes
2136
- 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.`);
2137
- }
2138
- return getClassList(elm);
2139
- },
2140
- get template() {
2141
- const vm = getAssociatedVM(this);
2142
- if (process.env.NODE_ENV !== 'production') {
2143
- if (vm.renderMode === 0 /* RenderMode.Light */) {
2144
- 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`.');
2145
- }
2146
- }
2147
- return vm.shadowRoot;
2148
- },
2149
- get refs() {
2150
- const vm = getAssociatedVM(this);
2151
- if (isUpdatingTemplate) {
2152
- if (process.env.NODE_ENV !== 'production') {
2153
- 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().`);
2154
- }
2155
- // If the template is in the process of being updated, then we don't want to go through the normal
2156
- // process of returning the refs and caching them, because the state of the refs is unstable.
2157
- // This can happen if e.g. a template contains `<div class={foo}></div>` and `foo` is computed
2158
- // based on `this.refs.bar`.
2159
- return;
2160
- }
2161
- if (process.env.NODE_ENV !== 'production') {
2162
- warnIfInvokedDuringConstruction(vm, 'refs');
2163
- }
2164
- const { refVNodes, hasRefVNodes, cmpTemplate } = vm;
2165
- // If the `cmpTemplate` is null, that means that the template has not been rendered yet. Most likely this occurs
2166
- // if `this.refs` is called during the `connectedCallback` phase. The DOM elements have not been rendered yet,
2167
- // so log a warning. Note we also check `isBeingConstructed()` to avoid a double warning (due to
2168
- // `warnIfInvokedDuringConstruction` above).
2169
- if (process.env.NODE_ENV !== 'production' &&
2170
- isNull(cmpTemplate) &&
2171
- !isBeingConstructed(vm)) {
2172
- logError(`this.refs is undefined for ${getComponentTag(vm)}. This is either because the attached template has no "lwc:ref" directive, or this.refs was ` +
2173
- `invoked before renderedCallback(). Use this.refs only when the referenced HTML elements have ` +
2174
- `been rendered to the DOM, such as within renderedCallback() or disconnectedCallback().`);
2175
- }
2176
- // For backwards compatibility with component written before template refs
2177
- // were introduced, we return undefined if the template has no refs defined
2178
- // anywhere. This fixes components that may want to add an expando called `refs`
2179
- // and are checking if it exists with `if (this.refs)` before adding it.
2180
- // Note it is not sufficient to just check if `refVNodes` is null or empty,
2181
- // because a template may have `lwc:ref` defined within a falsy `if:true` block.
2182
- if (!hasRefVNodes) {
2183
- return;
2184
- }
2185
- // For templates that are using `lwc:ref`, if there are no refs currently available
2186
- // (e.g. refs inside of a falsy `if:true` block), we return an empty object.
2187
- if (isNull(refVNodes)) {
2188
- return EMPTY_REFS;
2189
- }
2190
- // The refNodes can be cached based on the refVNodes, since the refVNodes
2191
- // are recreated from scratch every time the template is rendered.
2192
- // This happens with `vm.refVNodes = null` in `template.ts` in `@lwc/engine-core`.
2193
- let refs = refsCache.get(refVNodes);
2194
- if (isUndefined$1(refs)) {
2195
- refs = create(null);
2196
- for (const key of keys(refVNodes)) {
2197
- refs[key] = refVNodes[key].elm;
2198
- }
2199
- freeze(refs);
2200
- refsCache.set(refVNodes, refs);
2201
- }
2202
- return refs;
2203
- },
2204
- // For backwards compat, we allow component authors to set `refs` as an expando
2205
- set refs(value) {
2206
- defineProperty(this, 'refs', {
2207
- configurable: true,
2208
- enumerable: true,
2209
- writable: true,
2210
- value,
2211
- });
2212
- },
2213
- get shadowRoot() {
2214
- // From within the component instance, the shadowRoot is always reported as "closed".
2215
- // Authors should rely on this.template instead.
2216
- return null;
2217
- },
2218
- get children() {
2219
- const vm = getAssociatedVM(this);
2220
- const renderer = vm.renderer;
2221
- if (process.env.NODE_ENV !== 'production') {
2222
- warnIfInvokedDuringConstruction(vm, 'children');
2223
- }
2224
- return renderer.getChildren(vm.elm);
2225
- },
2226
- get childNodes() {
2227
- const vm = getAssociatedVM(this);
2228
- const renderer = vm.renderer;
2229
- if (process.env.NODE_ENV !== 'production') {
2230
- warnIfInvokedDuringConstruction(vm, 'childNodes');
2231
- }
2232
- return renderer.getChildNodes(vm.elm);
2233
- },
2234
- get firstChild() {
2235
- const vm = getAssociatedVM(this);
2236
- const renderer = vm.renderer;
2237
- if (process.env.NODE_ENV !== 'production') {
2238
- warnIfInvokedDuringConstruction(vm, 'firstChild');
2239
- }
2240
- return renderer.getFirstChild(vm.elm);
2241
- },
2242
- get firstElementChild() {
2243
- const vm = getAssociatedVM(this);
2244
- const renderer = vm.renderer;
2245
- if (process.env.NODE_ENV !== 'production') {
2246
- warnIfInvokedDuringConstruction(vm, 'firstElementChild');
2247
- }
2248
- return renderer.getFirstElementChild(vm.elm);
2249
- },
2250
- get lastChild() {
2251
- const vm = getAssociatedVM(this);
2252
- const renderer = vm.renderer;
2253
- if (process.env.NODE_ENV !== 'production') {
2254
- warnIfInvokedDuringConstruction(vm, 'lastChild');
2255
- }
2256
- return renderer.getLastChild(vm.elm);
2257
- },
2258
- get lastElementChild() {
2259
- const vm = getAssociatedVM(this);
2260
- const renderer = vm.renderer;
2261
- if (process.env.NODE_ENV !== 'production') {
2262
- warnIfInvokedDuringConstruction(vm, 'lastElementChild');
2263
- }
2264
- return renderer.getLastElementChild(vm.elm);
2265
- },
2266
- render() {
2267
- const vm = getAssociatedVM(this);
2268
- return vm.def.template;
2269
- },
2270
- toString() {
2271
- const vm = getAssociatedVM(this);
2272
- return `[object ${vm.def.name}]`;
2273
- },
2328
+ return renderer.getChildNodes(vm.elm);
2329
+ },
2330
+ get firstChild() {
2331
+ const vm = getAssociatedVM(this);
2332
+ const renderer = vm.renderer;
2333
+ if (process.env.NODE_ENV !== 'production') {
2334
+ warnIfInvokedDuringConstruction(vm, 'firstChild');
2335
+ }
2336
+ return renderer.getFirstChild(vm.elm);
2337
+ },
2338
+ get firstElementChild() {
2339
+ const vm = getAssociatedVM(this);
2340
+ const renderer = vm.renderer;
2341
+ if (process.env.NODE_ENV !== 'production') {
2342
+ warnIfInvokedDuringConstruction(vm, 'firstElementChild');
2343
+ }
2344
+ return renderer.getFirstElementChild(vm.elm);
2345
+ },
2346
+ get lastChild() {
2347
+ const vm = getAssociatedVM(this);
2348
+ const renderer = vm.renderer;
2349
+ if (process.env.NODE_ENV !== 'production') {
2350
+ warnIfInvokedDuringConstruction(vm, 'lastChild');
2351
+ }
2352
+ return renderer.getLastChild(vm.elm);
2353
+ },
2354
+ get lastElementChild() {
2355
+ const vm = getAssociatedVM(this);
2356
+ const renderer = vm.renderer;
2357
+ if (process.env.NODE_ENV !== 'production') {
2358
+ warnIfInvokedDuringConstruction(vm, 'lastElementChild');
2359
+ }
2360
+ return renderer.getLastElementChild(vm.elm);
2361
+ },
2362
+ render() {
2363
+ const vm = getAssociatedVM(this);
2364
+ return vm.def.template;
2365
+ },
2366
+ toString() {
2367
+ const vm = getAssociatedVM(this);
2368
+ return `[object ${vm.def.name}]`;
2369
+ }
2274
2370
  };
2275
2371
  const queryAndChildGetterDescriptors = create(null);
2276
- const queryMethods = [
2277
- 'getElementsByClassName',
2278
- 'getElementsByTagName',
2279
- 'querySelector',
2280
- 'querySelectorAll',
2281
- ];
2372
+ const queryMethods = ['getElementsByClassName', 'getElementsByTagName', 'querySelector', 'querySelectorAll'];
2282
2373
  // Generic passthrough for query APIs on HTMLElement to the relevant Renderer APIs
2283
2374
  for (const queryMethod of queryMethods) {
2284
- queryAndChildGetterDescriptors[queryMethod] = {
2285
- value(arg) {
2286
- const vm = getAssociatedVM(this);
2287
- const { elm, renderer } = vm;
2288
- if (process.env.NODE_ENV !== 'production') {
2289
- warnIfInvokedDuringConstruction(vm, `${queryMethod}()`);
2290
- }
2291
- return renderer[queryMethod](elm, arg);
2292
- },
2293
- configurable: true,
2294
- enumerable: true,
2295
- writable: true,
2296
- };
2375
+ queryAndChildGetterDescriptors[queryMethod] = {
2376
+ value(arg) {
2377
+ const vm = getAssociatedVM(this);
2378
+ const {
2379
+ elm,
2380
+ renderer
2381
+ } = vm;
2382
+ if (process.env.NODE_ENV !== 'production') {
2383
+ warnIfInvokedDuringConstruction(vm, `${queryMethod}()`);
2384
+ }
2385
+ return renderer[queryMethod](elm, arg);
2386
+ },
2387
+ configurable: true,
2388
+ enumerable: true,
2389
+ writable: true
2390
+ };
2297
2391
  }
2298
2392
  defineProperties(LightningElement.prototype, queryAndChildGetterDescriptors);
2299
2393
  const lightningBasedDescriptors = create(null);
2300
2394
  for (const propName in HTMLElementOriginalDescriptors) {
2301
- lightningBasedDescriptors[propName] = createBridgeToElementDescriptor(propName, HTMLElementOriginalDescriptors[propName]);
2395
+ lightningBasedDescriptors[propName] = createBridgeToElementDescriptor(propName, HTMLElementOriginalDescriptors[propName]);
2302
2396
  }
2303
2397
  defineProperties(LightningElement.prototype, lightningBasedDescriptors);
2398
+ function applyAriaReflectionToLightningElement() {
2399
+ // If ARIA reflection is not applied globally to Element.prototype, or if we are running server-side,
2400
+ // apply it to LightningElement.prototype.
2401
+ // This allows `this.aria*` property accessors to work from inside a component, and to reflect `aria-*` attrs.
2402
+ applyAriaReflection(LightningElement.prototype);
2403
+ }
2404
+ // The reason for this odd if/else branching is limitations in @lwc/features:
2405
+ // https://github.com/salesforce/lwc/blob/master/packages/%40lwc/features/README.md#only-works-with-if-statements
2406
+ if (lwcRuntimeFlags.DISABLE_ARIA_REFLECTION_POLYFILL) {
2407
+ applyAriaReflectionToLightningElement();
2408
+ }
2304
2409
  defineProperty(LightningElement, 'CustomElementConstructor', {
2305
- get() {
2306
- // If required, a runtime-specific implementation must be defined.
2307
- throw new ReferenceError('The current runtime does not support CustomElementConstructor.');
2308
- },
2309
- configurable: true,
2410
+ get() {
2411
+ // If required, a runtime-specific implementation must be defined.
2412
+ throw new ReferenceError('The current runtime does not support CustomElementConstructor.');
2413
+ },
2414
+ configurable: true
2310
2415
  });
2311
2416
  if (process.env.NODE_ENV !== 'production') {
2312
- patchLightningElementPrototypeWithRestrictions(LightningElement.prototype);
2417
+ patchLightningElementPrototypeWithRestrictions(LightningElement.prototype);
2313
2418
  }
2314
2419
 
2315
2420
  function createObservedFieldPropertyDescriptor(key) {
@@ -2769,138 +2874,161 @@ var LWC = (function (exports) {
2769
2874
  const cachedGetterByKey = create(null);
2770
2875
  const cachedSetterByKey = create(null);
2771
2876
  function createGetter(key) {
2772
- let fn = cachedGetterByKey[key];
2773
- if (isUndefined$1(fn)) {
2774
- fn = cachedGetterByKey[key] = function () {
2775
- const vm = getAssociatedVM(this);
2776
- const { getHook } = vm;
2777
- return getHook(vm.component, key);
2778
- };
2779
- }
2780
- return fn;
2877
+ let fn = cachedGetterByKey[key];
2878
+ if (isUndefined$1(fn)) {
2879
+ fn = cachedGetterByKey[key] = function () {
2880
+ const vm = getAssociatedVM(this);
2881
+ const {
2882
+ getHook
2883
+ } = vm;
2884
+ return getHook(vm.component, key);
2885
+ };
2886
+ }
2887
+ return fn;
2781
2888
  }
2782
2889
  function createSetter(key) {
2783
- let fn = cachedSetterByKey[key];
2784
- if (isUndefined$1(fn)) {
2785
- fn = cachedSetterByKey[key] = function (newValue) {
2786
- const vm = getAssociatedVM(this);
2787
- const { setHook } = vm;
2788
- newValue = getReadOnlyProxy(newValue);
2789
- setHook(vm.component, key, newValue);
2790
- };
2791
- }
2792
- return fn;
2890
+ let fn = cachedSetterByKey[key];
2891
+ if (isUndefined$1(fn)) {
2892
+ fn = cachedSetterByKey[key] = function (newValue) {
2893
+ const vm = getAssociatedVM(this);
2894
+ const {
2895
+ setHook
2896
+ } = vm;
2897
+ newValue = getReadOnlyProxy(newValue);
2898
+ setHook(vm.component, key, newValue);
2899
+ };
2900
+ }
2901
+ return fn;
2793
2902
  }
2794
2903
  function createMethodCaller(methodName) {
2795
- return function () {
2796
- const vm = getAssociatedVM(this);
2797
- const { callHook, component } = vm;
2798
- const fn = component[methodName];
2799
- return callHook(vm.component, fn, ArraySlice.call(arguments));
2800
- };
2904
+ return function () {
2905
+ const vm = getAssociatedVM(this);
2906
+ const {
2907
+ callHook,
2908
+ component
2909
+ } = vm;
2910
+ const fn = component[methodName];
2911
+ return callHook(vm.component, fn, ArraySlice.call(arguments));
2912
+ };
2801
2913
  }
2802
2914
  function createAttributeChangedCallback(attributeToPropMap, superAttributeChangedCallback) {
2803
- return function attributeChangedCallback(attrName, oldValue, newValue) {
2804
- if (oldValue === newValue) {
2805
- // Ignore same values.
2806
- return;
2807
- }
2808
- const propName = attributeToPropMap[attrName];
2809
- if (isUndefined$1(propName)) {
2810
- if (!isUndefined$1(superAttributeChangedCallback)) {
2811
- // delegate unknown attributes to the super.
2812
- // Typescript does not like it when you treat the `arguments` object as an array
2813
- // @ts-ignore type-mismatch
2814
- superAttributeChangedCallback.apply(this, arguments);
2815
- }
2816
- return;
2817
- }
2818
- if (!isAttributeLocked(this, attrName)) {
2819
- // Ignore changes triggered by the engine itself during:
2820
- // * diffing when public props are attempting to reflect to the DOM
2821
- // * component via `this.setAttribute()`, should never update the prop
2822
- // Both cases, the setAttribute call is always wrapped by the unlocking of the
2823
- // attribute to be changed
2824
- return;
2825
- }
2826
- // Reflect attribute change to the corresponding property when changed from outside.
2827
- this[propName] = newValue;
2828
- };
2829
- }
2830
- function HTMLBridgeElementFactory(SuperClass, props, methods) {
2831
- let HTMLBridgeElement;
2832
- /**
2833
- * Modern browsers will have all Native Constructors as regular Classes
2834
- * and must be instantiated with the new keyword. In older browsers,
2835
- * specifically IE11, those are objects with a prototype property defined,
2836
- * since they are not supposed to be extended or instantiated with the
2837
- * new keyword. This forking logic supports both cases, specifically because
2838
- * wc.ts relies on the construction path of the bridges to create new
2839
- * fully qualifying web components.
2840
- */
2841
- if (isFunction$1(SuperClass)) {
2842
- HTMLBridgeElement = class extends SuperClass {
2843
- };
2844
- }
2845
- else {
2846
- HTMLBridgeElement = function () {
2847
- // Bridge classes are not supposed to be instantiated directly in
2848
- // browsers that do not support web components.
2849
- throw new TypeError('Illegal constructor');
2850
- };
2851
- // prototype inheritance dance
2852
- setPrototypeOf(HTMLBridgeElement, SuperClass);
2853
- setPrototypeOf(HTMLBridgeElement.prototype, SuperClass.prototype);
2854
- defineProperty(HTMLBridgeElement.prototype, 'constructor', {
2855
- writable: true,
2856
- configurable: true,
2857
- value: HTMLBridgeElement,
2858
- });
2915
+ return function attributeChangedCallback(attrName, oldValue, newValue) {
2916
+ if (oldValue === newValue) {
2917
+ // Ignore same values.
2918
+ return;
2859
2919
  }
2860
- // generating the hash table for attributes to avoid duplicate fields and facilitate validation
2861
- // and false positives in case of inheritance.
2862
- const attributeToPropMap = create(null);
2863
- const { attributeChangedCallback: superAttributeChangedCallback } = SuperClass.prototype;
2864
- const { observedAttributes: superObservedAttributes = [] } = SuperClass;
2865
- const descriptors = create(null);
2866
- // expose getters and setters for each public props on the new Element Bridge
2867
- for (let i = 0, len = props.length; i < len; i += 1) {
2868
- const propName = props[i];
2869
- attributeToPropMap[htmlPropertyToAttribute(propName)] = propName;
2870
- descriptors[propName] = {
2871
- get: createGetter(propName),
2872
- set: createSetter(propName),
2873
- enumerable: true,
2874
- configurable: true,
2875
- };
2920
+ const propName = attributeToPropMap[attrName];
2921
+ if (isUndefined$1(propName)) {
2922
+ if (!isUndefined$1(superAttributeChangedCallback)) {
2923
+ // delegate unknown attributes to the super.
2924
+ // Typescript does not like it when you treat the `arguments` object as an array
2925
+ // @ts-ignore type-mismatch
2926
+ superAttributeChangedCallback.apply(this, arguments);
2927
+ }
2928
+ return;
2876
2929
  }
2877
- // expose public methods as props on the new Element Bridge
2878
- for (let i = 0, len = methods.length; i < len; i += 1) {
2879
- const methodName = methods[i];
2880
- descriptors[methodName] = {
2881
- value: createMethodCaller(methodName),
2882
- writable: true,
2883
- configurable: true,
2884
- };
2930
+ if (!isAttributeLocked(this, attrName)) {
2931
+ // Ignore changes triggered by the engine itself during:
2932
+ // * diffing when public props are attempting to reflect to the DOM
2933
+ // * component via `this.setAttribute()`, should never update the prop
2934
+ // Both cases, the setAttribute call is always wrapped by the unlocking of the
2935
+ // attribute to be changed
2936
+ return;
2885
2937
  }
2886
- // creating a new attributeChangedCallback per bridge because they are bound to the corresponding
2887
- // map of attributes to props. We do this after all other props and methods to avoid the possibility
2888
- // of getting overrule by a class declaration in user-land, and we make it non-writable, non-configurable
2889
- // to preserve this definition.
2890
- descriptors.attributeChangedCallback = {
2891
- value: createAttributeChangedCallback(attributeToPropMap, superAttributeChangedCallback),
2938
+ // Reflect attribute change to the corresponding property when changed from outside.
2939
+ this[propName] = newValue;
2940
+ };
2941
+ }
2942
+ function HTMLBridgeElementFactory(SuperClass, props, methods) {
2943
+ let HTMLBridgeElement;
2944
+ /**
2945
+ * Modern browsers will have all Native Constructors as regular Classes
2946
+ * and must be instantiated with the new keyword. In older browsers,
2947
+ * specifically IE11, those are objects with a prototype property defined,
2948
+ * since they are not supposed to be extended or instantiated with the
2949
+ * new keyword. This forking logic supports both cases, specifically because
2950
+ * wc.ts relies on the construction path of the bridges to create new
2951
+ * fully qualifying web components.
2952
+ */
2953
+ if (isFunction$1(SuperClass)) {
2954
+ HTMLBridgeElement = class extends SuperClass {};
2955
+ } else {
2956
+ HTMLBridgeElement = function () {
2957
+ // Bridge classes are not supposed to be instantiated directly in
2958
+ // browsers that do not support web components.
2959
+ throw new TypeError('Illegal constructor');
2892
2960
  };
2893
- // Specify attributes for which we want to reflect changes back to their corresponding
2894
- // properties via attributeChangedCallback.
2895
- defineProperty(HTMLBridgeElement, 'observedAttributes', {
2896
- get() {
2897
- return [...superObservedAttributes, ...keys(attributeToPropMap)];
2898
- },
2961
+ // prototype inheritance dance
2962
+ setPrototypeOf(HTMLBridgeElement, SuperClass);
2963
+ setPrototypeOf(HTMLBridgeElement.prototype, SuperClass.prototype);
2964
+ defineProperty(HTMLBridgeElement.prototype, 'constructor', {
2965
+ writable: true,
2966
+ configurable: true,
2967
+ value: HTMLBridgeElement
2899
2968
  });
2900
- defineProperties(HTMLBridgeElement.prototype, descriptors);
2901
- return HTMLBridgeElement;
2969
+ }
2970
+ // generating the hash table for attributes to avoid duplicate fields and facilitate validation
2971
+ // and false positives in case of inheritance.
2972
+ const attributeToPropMap = create(null);
2973
+ const {
2974
+ attributeChangedCallback: superAttributeChangedCallback
2975
+ } = SuperClass.prototype;
2976
+ const {
2977
+ observedAttributes: superObservedAttributes = []
2978
+ } = SuperClass;
2979
+ const descriptors = create(null);
2980
+ // expose getters and setters for each public props on the new Element Bridge
2981
+ for (let i = 0, len = props.length; i < len; i += 1) {
2982
+ const propName = props[i];
2983
+ attributeToPropMap[htmlPropertyToAttribute(propName)] = propName;
2984
+ descriptors[propName] = {
2985
+ get: createGetter(propName),
2986
+ set: createSetter(propName),
2987
+ enumerable: true,
2988
+ configurable: true
2989
+ };
2990
+ }
2991
+ // expose public methods as props on the new Element Bridge
2992
+ for (let i = 0, len = methods.length; i < len; i += 1) {
2993
+ const methodName = methods[i];
2994
+ descriptors[methodName] = {
2995
+ value: createMethodCaller(methodName),
2996
+ writable: true,
2997
+ configurable: true
2998
+ };
2999
+ }
3000
+ // creating a new attributeChangedCallback per bridge because they are bound to the corresponding
3001
+ // map of attributes to props. We do this after all other props and methods to avoid the possibility
3002
+ // of getting overrule by a class declaration in user-land, and we make it non-writable, non-configurable
3003
+ // to preserve this definition.
3004
+ descriptors.attributeChangedCallback = {
3005
+ value: createAttributeChangedCallback(attributeToPropMap, superAttributeChangedCallback)
3006
+ };
3007
+ // Specify attributes for which we want to reflect changes back to their corresponding
3008
+ // properties via attributeChangedCallback.
3009
+ defineProperty(HTMLBridgeElement, 'observedAttributes', {
3010
+ get() {
3011
+ return [...superObservedAttributes, ...keys(attributeToPropMap)];
3012
+ }
3013
+ });
3014
+ defineProperties(HTMLBridgeElement.prototype, descriptors);
3015
+ return HTMLBridgeElement;
2902
3016
  }
2903
3017
  const BaseBridgeElement = HTMLBridgeElementFactory(HTMLElementConstructor, getOwnPropertyNames$1(HTMLElementOriginalDescriptors), []);
3018
+ {
3019
+ // This ARIA reflection only really makes sense in the browser. On the server, there is no `renderedCallback()`,
3020
+ // so you cannot do e.g. `this.template.querySelector('x-child').ariaBusy = 'true'`. So we don't need to expose
3021
+ // ARIA props outside the LightningElement
3022
+ if (lwcRuntimeFlags.DISABLE_ARIA_REFLECTION_POLYFILL) {
3023
+ // If ARIA reflection is not applied globally to Element.prototype, apply it to HTMLBridgeElement.prototype.
3024
+ // This allows `elm.aria*` property accessors to work from outside a component, and to reflect `aria-*` attrs.
3025
+ // This is especially important because the template compiler compiles aria-* attrs on components to aria* props
3026
+ //
3027
+ // Also note that we apply this to BaseBridgeElement.prototype to avoid excessively redefining property
3028
+ // accessors inside the HTMLBridgeElementFactory.
3029
+ applyAriaReflection(BaseBridgeElement.prototype);
3030
+ }
3031
+ }
2904
3032
  freeze(BaseBridgeElement);
2905
3033
  seal(BaseBridgeElement.prototype);
2906
3034
 
@@ -3356,6 +3484,9 @@ var LWC = (function (exports) {
3356
3484
  stylesheets: newStylesheets,
3357
3485
  stylesheetToken: newStylesheetToken
3358
3486
  } = template;
3487
+ const {
3488
+ stylesheets: newVmStylesheets
3489
+ } = vm;
3359
3490
  const isSyntheticShadow = renderMode === 1 /* RenderMode.Shadow */ && shadowMode === 1 /* ShadowMode.Synthetic */;
3360
3491
  const {
3361
3492
  hasScopedStyles
@@ -3379,7 +3510,9 @@ var LWC = (function (exports) {
3379
3510
  }
3380
3511
  // Apply the new template styling token to the host element, if the new template has any
3381
3512
  // associated stylesheets. In the case of light DOM, also ensure there is at least one scoped stylesheet.
3382
- if (!isUndefined$1(newStylesheets) && newStylesheets.length !== 0) {
3513
+ const hasNewStylesheets = hasStyles(newStylesheets);
3514
+ const hasNewVmStylesheets = hasStyles(newVmStylesheets);
3515
+ if (hasNewStylesheets || hasNewVmStylesheets) {
3383
3516
  newToken = newStylesheetToken;
3384
3517
  }
3385
3518
  // Set the new styling token on the host element
@@ -3451,10 +3584,17 @@ var LWC = (function (exports) {
3451
3584
  stylesheets,
3452
3585
  stylesheetToken
3453
3586
  } = template;
3587
+ const {
3588
+ stylesheets: vmStylesheets
3589
+ } = vm;
3454
3590
  let content = [];
3455
- if (!isUndefined$1(stylesheets) && stylesheets.length !== 0) {
3591
+ if (hasStyles(stylesheets)) {
3456
3592
  content = evaluateStylesheetsContent(stylesheets, stylesheetToken, vm);
3457
3593
  }
3594
+ // VM (component) stylesheets apply after template stylesheets
3595
+ if (hasStyles(vmStylesheets)) {
3596
+ ArrayPush$1.apply(content, evaluateStylesheetsContent(vmStylesheets, stylesheetToken, vm));
3597
+ }
3458
3598
  return content;
3459
3599
  }
3460
3600
  // It might be worth caching this to avoid doing the lookup repeatedly, but
@@ -3492,10 +3632,13 @@ var LWC = (function (exports) {
3492
3632
  const {
3493
3633
  template
3494
3634
  } = getComponentInternalDef(vnode.ctor);
3635
+ const {
3636
+ vm
3637
+ } = vnode;
3495
3638
  const {
3496
3639
  stylesheetToken
3497
3640
  } = template;
3498
- return !isUndefined$1(stylesheetToken) && computeHasScopedStyles(template) ? makeHostToken(stylesheetToken) : null;
3641
+ return !isUndefined$1(stylesheetToken) && computeHasScopedStyles(template, vm) ? makeHostToken(stylesheetToken) : null;
3499
3642
  }
3500
3643
  function getNearestNativeShadowComponent(vm) {
3501
3644
  const owner = getNearestShadowComponent(vm);
@@ -4108,6 +4251,28 @@ var LWC = (function (exports) {
4108
4251
  // in fallback mode, the allocation will always set children to
4109
4252
  // empty and delegate the real allocation to the slot elements
4110
4253
  allocateChildren(n2, vm);
4254
+ // Solves an edge case with slotted VFragments in native shadow mode.
4255
+ //
4256
+ // During allocation, in native shadow, slotted VFragment nodes are flattened and their text delimiters are removed
4257
+ // to avoid interfering with native slot behavior. When this happens, if any of the fragments
4258
+ // were not stable, the children must go through the dynamic diffing algo.
4259
+ //
4260
+ // If the new children (n2.children) contain no VFragments, but the previous children (n1.children) were dynamic,
4261
+ // the new nodes must be marked dynamic so that all nodes are properly updated. The only indicator that the new
4262
+ // nodes need to be dynamic comes from the previous children, so we check that to determine whether we need to
4263
+ // mark the new children dynamic.
4264
+ //
4265
+ // Example:
4266
+ // n1.children: [div, VFragment('', div, null, ''), div] => [div, div, null, div]; // marked dynamic
4267
+ // n2.children: [div, null, div] => [div, null, div] // marked ???
4268
+ const {
4269
+ shadowMode,
4270
+ renderMode
4271
+ } = vm;
4272
+ if (shadowMode == 0 /* ShadowMode.Native */ && renderMode !== 0 /* RenderMode.Light */ && hasDynamicChildren(n1.children)) {
4273
+ // No-op if children has already been marked dynamic by 'allocateChildren()'.
4274
+ markAsDynamicChildren(n2.children);
4275
+ }
4111
4276
  }
4112
4277
  // in fallback mode, the children will be always empty, so, nothing
4113
4278
  // will happen, but in native, it does allocate the light dom
@@ -4300,7 +4465,6 @@ var LWC = (function (exports) {
4300
4465
  //
4301
4466
  // In case #2, we will always get a fresh VCustomElement.
4302
4467
  const children = vnode.aChildren || vnode.children;
4303
- vm.aChildren = children;
4304
4468
  const {
4305
4469
  renderMode,
4306
4470
  shadowMode
@@ -4313,15 +4477,61 @@ var LWC = (function (exports) {
4313
4477
  logError(`Invalid usage of 'lwc:slot-data' on ${getComponentTag(vm)} tag. Scoped slot content can only be passed to a light dom child.`);
4314
4478
  }
4315
4479
  }
4480
+ // If any of the children being allocated are VFragments, we remove the text delimiters and flatten all immediate
4481
+ // children VFragments to avoid them interfering with default slot behavior.
4482
+ const allocatedChildren = flattenFragmentsInChildren(children);
4483
+ vnode.children = allocatedChildren;
4484
+ vm.aChildren = allocatedChildren;
4316
4485
  if (shadowMode === 1 /* ShadowMode.Synthetic */ || renderMode === 0 /* RenderMode.Light */) {
4317
4486
  // slow path
4318
- allocateInSlot(vm, children, vnode.owner);
4487
+ allocateInSlot(vm, allocatedChildren, vnode.owner);
4319
4488
  // save the allocated children in case this vnode is reused.
4320
- vnode.aChildren = children;
4489
+ vnode.aChildren = allocatedChildren;
4321
4490
  // every child vnode is now allocated, and the host should receive none directly, it receives them via the shadow!
4322
4491
  vnode.children = EmptyArray;
4323
4492
  }
4324
4493
  }
4494
+ /**
4495
+ * Flattens the contents of all VFragments in an array of VNodes, removes the text delimiters on those VFragments, and
4496
+ * marks the resulting children array as dynamic. Uses a stack (array) to iteratively traverse the nested VFragments
4497
+ * and avoid the perf overhead of creating/destroying throwaway arrays/objects in a recursive approach.
4498
+ *
4499
+ * With the delimiters removed, the contents are marked dynamic so they are diffed correctly.
4500
+ *
4501
+ * This function is used for slotted VFragments to avoid the text delimiters interfering with slotting functionality.
4502
+ */
4503
+ function flattenFragmentsInChildren(children) {
4504
+ const flattenedChildren = [];
4505
+ // Initialize our stack with the direct children of the custom component and check whether we have a VFragment.
4506
+ // If no VFragment is found in children, we don't need to traverse anything or mark the children dynamic and can return early.
4507
+ const nodeStack = [];
4508
+ let fragmentFound = false;
4509
+ for (let i = children.length - 1; i > -1; i -= 1) {
4510
+ const child = children[i];
4511
+ ArrayPush$1.call(nodeStack, child);
4512
+ fragmentFound = fragmentFound || !!(child && isVFragment(child));
4513
+ }
4514
+ if (!fragmentFound) {
4515
+ return children;
4516
+ }
4517
+ let currentNode;
4518
+ while (!isUndefined$1(currentNode = ArrayPop.call(nodeStack))) {
4519
+ if (!isNull(currentNode) && isVFragment(currentNode)) {
4520
+ const fChildren = currentNode.children;
4521
+ // Ignore the start and end text node delimiters
4522
+ for (let i = fChildren.length - 2; i > 0; i -= 1) {
4523
+ ArrayPush$1.call(nodeStack, fChildren[i]);
4524
+ }
4525
+ } else {
4526
+ ArrayPush$1.call(flattenedChildren, currentNode);
4527
+ }
4528
+ }
4529
+ // We always mark the children as dynamic because nothing generates stable VFragments yet.
4530
+ // If/when stable VFragments are generated by the compiler, this code should be updated to
4531
+ // not mark dynamic if all flattened VFragments were stable.
4532
+ markAsDynamicChildren(flattenedChildren);
4533
+ return flattenedChildren;
4534
+ }
4325
4535
  function createViewModelHook(elm, vnode, renderer) {
4326
4536
  let vm = getAssociatedVMIfPresent(elm);
4327
4537
  // There is a possibility that a custom element is registered under tagName, in which case, the
@@ -4346,22 +4556,20 @@ var LWC = (function (exports) {
4346
4556
  }
4347
4557
  return vm;
4348
4558
  }
4349
- /**
4350
- * Collects all slots into a SlotSet, traversing through VFragment Nodes
4351
- */
4352
- function collectSlots(vm, children, cmpSlotsMapping) {
4559
+ function allocateInSlot(vm, children, owner) {
4353
4560
  var _a, _b;
4561
+ const {
4562
+ cmpSlots: {
4563
+ slotAssignments: oldSlotsMapping
4564
+ }
4565
+ } = vm;
4566
+ const cmpSlotsMapping = create(null);
4567
+ // Collect all slots into cmpSlotsMapping
4354
4568
  for (let i = 0, len = children.length; i < len; i += 1) {
4355
4569
  const vnode = children[i];
4356
4570
  if (isNull(vnode)) {
4357
4571
  continue;
4358
4572
  }
4359
- // Dive further iff the content is wrapped in a VFragment
4360
- if (isVFragment(vnode)) {
4361
- // Remove the text delimiter nodes to avoid overriding default slot content
4362
- collectSlots(vm, vnode.children.slice(1, -1), cmpSlotsMapping);
4363
- continue;
4364
- }
4365
4573
  let slotName = '';
4366
4574
  if (isVBaseElement(vnode)) {
4367
4575
  slotName = (_b = (_a = vnode.data.attrs) === null || _a === void 0 ? void 0 : _a.slot) !== null && _b !== void 0 ? _b : '';
@@ -4371,15 +4579,6 @@ var LWC = (function (exports) {
4371
4579
  const vnodes = cmpSlotsMapping[slotName] = cmpSlotsMapping[slotName] || [];
4372
4580
  ArrayPush$1.call(vnodes, vnode);
4373
4581
  }
4374
- }
4375
- function allocateInSlot(vm, children, owner) {
4376
- const {
4377
- cmpSlots: {
4378
- slotAssignments: oldSlotsMapping
4379
- }
4380
- } = vm;
4381
- const cmpSlotsMapping = create(null);
4382
- collectSlots(vm, children, cmpSlotsMapping);
4383
4582
  vm.cmpSlots = {
4384
4583
  owner,
4385
4584
  slotAssignments: cmpSlotsMapping
@@ -4410,14 +4609,14 @@ var LWC = (function (exports) {
4410
4609
  }
4411
4610
  }
4412
4611
  // Using a WeakMap instead of a WeakSet because this one works in IE11 :(
4413
- const FromIteration = new WeakMap();
4414
- // dynamic children means it was generated by an iteration
4415
- // in a template, and will require a more complex diffing algo.
4612
+ const DynamicChildren = new WeakMap();
4613
+ // dynamic children means it was either generated by an iteration in a template
4614
+ // or part of an unstable fragment, and will require a more complex diffing algo.
4416
4615
  function markAsDynamicChildren(children) {
4417
- FromIteration.set(children, 1);
4616
+ DynamicChildren.set(children, 1);
4418
4617
  }
4419
4618
  function hasDynamicChildren(children) {
4420
- return FromIteration.has(children);
4619
+ return DynamicChildren.has(children);
4421
4620
  }
4422
4621
  function createKeyToOldIdx(children, beginIdx, endIdx) {
4423
4622
  const map = {};
@@ -5283,7 +5482,7 @@ var LWC = (function (exports) {
5283
5482
  // Create a brand new template cache for the swapped templated.
5284
5483
  context.tplCache = create(null);
5285
5484
  // Set the computeHasScopedStyles property in the context, to avoid recomputing it repeatedly.
5286
- context.hasScopedStyles = computeHasScopedStyles(html);
5485
+ context.hasScopedStyles = computeHasScopedStyles(html, vm);
5287
5486
  // Update the scoping token on the host element.
5288
5487
  updateStylesheetToken(vm, html);
5289
5488
  // Evaluate, create stylesheet and cache the produced VNode for future
@@ -5326,9 +5525,8 @@ var LWC = (function (exports) {
5326
5525
  }
5327
5526
  return vnodes;
5328
5527
  }
5329
- function computeHasScopedStyles(template) {
5330
- const { stylesheets } = template;
5331
- if (!isUndefined$1(stylesheets)) {
5528
+ function computeHasScopedStylesInStylesheets(stylesheets) {
5529
+ if (hasStyles(stylesheets)) {
5332
5530
  for (let i = 0; i < stylesheets.length; i++) {
5333
5531
  if (isTrue(stylesheets[i][KEY__SCOPED_CSS])) {
5334
5532
  return true;
@@ -5337,6 +5535,15 @@ var LWC = (function (exports) {
5337
5535
  }
5338
5536
  return false;
5339
5537
  }
5538
+ function computeHasScopedStyles(template, vm) {
5539
+ const { stylesheets } = template;
5540
+ const vmStylesheets = !isUndefined$1(vm) ? vm.stylesheets : null;
5541
+ return (computeHasScopedStylesInStylesheets(stylesheets) ||
5542
+ computeHasScopedStylesInStylesheets(vmStylesheets));
5543
+ }
5544
+ function hasStyles(stylesheets) {
5545
+ return !isUndefined$1(stylesheets) && !isNull(stylesheets) && stylesheets.length > 0;
5546
+ }
5340
5547
 
5341
5548
  /*
5342
5549
  * Copyright (c) 2018, salesforce.com, inc.
@@ -5652,6 +5859,7 @@ var LWC = (function (exports) {
5652
5859
  // Properties set right after VM creation.
5653
5860
  tro: null,
5654
5861
  shadowMode: null,
5862
+ stylesheets: null,
5655
5863
  // Properties set by the LightningElement constructor.
5656
5864
  component: null,
5657
5865
  shadowRoot: null,
@@ -5664,6 +5872,7 @@ var LWC = (function (exports) {
5664
5872
  if (process.env.NODE_ENV !== 'production') {
5665
5873
  vm.debugInfo = create(null);
5666
5874
  }
5875
+ vm.stylesheets = computeStylesheets(vm, def.ctor);
5667
5876
  vm.shadowMode = computeShadowMode(vm, renderer);
5668
5877
  vm.tro = getTemplateReactiveObserver(vm);
5669
5878
  if (process.env.NODE_ENV !== 'production') {
@@ -5682,6 +5891,42 @@ var LWC = (function (exports) {
5682
5891
  }
5683
5892
  return vm;
5684
5893
  }
5894
+ function validateComponentStylesheets(vm, stylesheets) {
5895
+ let valid = true;
5896
+ const validate = arrayOrStylesheet => {
5897
+ if (isArray$1(arrayOrStylesheet)) {
5898
+ for (let i = 0; i < arrayOrStylesheet.length; i++) {
5899
+ validate(arrayOrStylesheet[i]);
5900
+ }
5901
+ } else if (!isFunction$1(arrayOrStylesheet)) {
5902
+ // function assumed to be a stylesheet factory
5903
+ valid = false;
5904
+ }
5905
+ };
5906
+ if (!isArray$1(stylesheets)) {
5907
+ valid = false;
5908
+ } else {
5909
+ validate(stylesheets);
5910
+ }
5911
+ return valid;
5912
+ }
5913
+ // Validate and flatten any stylesheets defined as `static stylesheets`
5914
+ function computeStylesheets(vm, ctor) {
5915
+ if (lwcRuntimeFlags.ENABLE_PROGRAMMATIC_STYLESHEETS) {
5916
+ const {
5917
+ stylesheets
5918
+ } = ctor;
5919
+ if (!isUndefined$1(stylesheets)) {
5920
+ const valid = validateComponentStylesheets(vm, stylesheets);
5921
+ if (valid) {
5922
+ return flattenStylesheets(stylesheets);
5923
+ } else if (process.env.NODE_ENV !== 'production') {
5924
+ logError(`static stylesheets must be an array of CSS stylesheets. Found invalid stylesheets on <${vm.tagName}>`, vm);
5925
+ }
5926
+ }
5927
+ }
5928
+ return null;
5929
+ }
5685
5930
  function computeShadowMode(vm, renderer) {
5686
5931
  const {
5687
5932
  def
@@ -7000,7 +7245,7 @@ var LWC = (function (exports) {
7000
7245
  }
7001
7246
  return ctor;
7002
7247
  }
7003
- /* version: 2.32.1 */
7248
+ /* version: 2.34.0 */
7004
7249
 
7005
7250
  /*
7006
7251
  * Copyright (c) 2018, salesforce.com, inc.
@@ -7107,7 +7352,9 @@ var LWC = (function (exports) {
7107
7352
  //
7108
7353
  // Test utilities
7109
7354
  //
7110
- if (process.env.NODE_ENV === 'development') {
7355
+ // Only used in LWC's Karma tests
7356
+ // @ts-ignore
7357
+ if (process.env.NODE_ENV !== 'production' && typeof __karma__ !== 'undefined') {
7111
7358
  // @ts-ignore
7112
7359
  window.__lwcResetGlobalStylesheets = () => {
7113
7360
  stylesheetCache.clear();
@@ -7973,7 +8220,7 @@ var LWC = (function (exports) {
7973
8220
  function isNull(obj) {
7974
8221
  return obj === null;
7975
8222
  }
7976
- /** version: 2.32.1 */
8223
+ /** version: 2.34.0 */
7977
8224
 
7978
8225
  /*
7979
8226
  * Copyright (c) 2018, salesforce.com, inc.
@@ -8534,7 +8781,7 @@ var LWC = (function (exports) {
8534
8781
  });
8535
8782
  freeze(LightningElement);
8536
8783
  seal(LightningElement.prototype);
8537
- /* version: 2.32.1 */
8784
+ /* version: 2.34.0 */
8538
8785
 
8539
8786
  exports.LightningElement = LightningElement;
8540
8787
  exports.__unstable__ProfilerControl = profilerControl;