lwc 2.32.0 → 2.33.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (41) hide show
  1. package/dist/engine-dom/esm/es2017/engine-dom.js +898 -802
  2. package/dist/engine-dom/iife/es2017/engine-dom.js +898 -802
  3. package/dist/engine-dom/iife/es2017/engine-dom.min.js +1 -1
  4. package/dist/engine-dom/iife/es2017/engine-dom_debug.js +683 -608
  5. package/dist/engine-dom/iife/es5/engine-dom.js +324 -313
  6. package/dist/engine-dom/iife/es5/engine-dom.min.js +1 -1
  7. package/dist/engine-dom/iife/es5/engine-dom_debug.js +234 -270
  8. package/dist/engine-dom/umd/es2017/engine-dom.js +898 -802
  9. package/dist/engine-dom/umd/es2017/engine-dom.min.js +1 -1
  10. package/dist/engine-dom/umd/es2017/engine-dom_debug.js +683 -608
  11. package/dist/engine-dom/umd/es5/engine-dom.js +324 -313
  12. package/dist/engine-dom/umd/es5/engine-dom.min.js +1 -1
  13. package/dist/engine-dom/umd/es5/engine-dom_debug.js +234 -270
  14. package/dist/engine-server/commonjs/es2017/engine-server.js +871 -696
  15. package/dist/engine-server/commonjs/es2017/engine-server.min.js +1 -1
  16. package/dist/engine-server/esm/es2017/engine-server.js +871 -696
  17. package/dist/synthetic-shadow/esm/es2017/synthetic-shadow.js +676 -909
  18. package/dist/synthetic-shadow/iife/es2017/synthetic-shadow.js +676 -909
  19. package/dist/synthetic-shadow/iife/es2017/synthetic-shadow.min.js +2 -2
  20. package/dist/synthetic-shadow/iife/es2017/synthetic-shadow_debug.js +644 -882
  21. package/dist/synthetic-shadow/iife/es5/synthetic-shadow.js +89 -347
  22. package/dist/synthetic-shadow/iife/es5/synthetic-shadow.min.js +2 -2
  23. package/dist/synthetic-shadow/iife/es5/synthetic-shadow_debug.js +89 -347
  24. package/dist/synthetic-shadow/umd/es2017/synthetic-shadow.js +676 -909
  25. package/dist/synthetic-shadow/umd/es2017/synthetic-shadow.min.js +2 -2
  26. package/dist/synthetic-shadow/umd/es2017/synthetic-shadow_debug.js +644 -882
  27. package/dist/synthetic-shadow/umd/es5/synthetic-shadow.js +89 -347
  28. package/dist/synthetic-shadow/umd/es5/synthetic-shadow.min.js +2 -2
  29. package/dist/synthetic-shadow/umd/es5/synthetic-shadow_debug.js +89 -347
  30. package/dist/wire-service/esm/es2017/wire-service.js +2 -2
  31. package/dist/wire-service/iife/es2017/wire-service.js +2 -2
  32. package/dist/wire-service/iife/es2017/wire-service_debug.js +2 -2
  33. package/dist/wire-service/iife/es5/wire-service.js +5 -3
  34. package/dist/wire-service/iife/es5/wire-service.min.js +1 -1
  35. package/dist/wire-service/iife/es5/wire-service_debug.js +5 -3
  36. package/dist/wire-service/umd/es2017/wire-service.js +2 -2
  37. package/dist/wire-service/umd/es2017/wire-service_debug.js +2 -2
  38. package/dist/wire-service/umd/es5/wire-service.js +5 -3
  39. package/dist/wire-service/umd/es5/wire-service.min.js +1 -1
  40. package/dist/wire-service/umd/es5/wire-service_debug.js +5 -3
  41. package/package.json +7 -7
@@ -124,6 +124,9 @@
124
124
  * The above list of 46 aria attributes is consistent with the following resources:
125
125
  * https://github.com/w3c/aria/pull/708/files#diff-eacf331f0ffc35d4b482f1d15a887d3bR11060
126
126
  * https://wicg.github.io/aom/spec/aria-reflection.html
127
+ *
128
+ * NOTE: If you update this list, please update test files that implicitly reference this list!
129
+ * Searching the codebase for `aria-flowto` and `ariaFlowTo` should be good enough to find all usages.
127
130
  */
128
131
  const AriaPropertyNames = [
129
132
  'ariaActiveDescendant',
@@ -347,91 +350,9 @@
347
350
  * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
348
351
  */
349
352
  // Increment whenever the LWC template compiler changes
350
- const LWC_VERSION = "2.32.0";
353
+ const LWC_VERSION = "2.33.0";
351
354
  const LWC_VERSION_COMMENT_REGEX = /\/\*LWC compiler v([\d.]+)\*\/\s*}/;
352
- /** version: 2.32.0 */
353
-
354
- /**
355
- * Copyright (C) 2018 salesforce.com, inc.
356
- */
357
-
358
- /*
359
- * Copyright (c) 2018, salesforce.com, inc.
360
- * All rights reserved.
361
- * SPDX-License-Identifier: MIT
362
- * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
363
- */
364
- function detect(propName) {
365
- return getOwnPropertyDescriptor$1(Element.prototype, propName) === undefined;
366
- }
367
-
368
- /*
369
- * Copyright (c) 2018, salesforce.com, inc.
370
- * All rights reserved.
371
- * SPDX-License-Identifier: MIT
372
- * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
373
- */
374
- const nodeToAriaPropertyValuesMap = new WeakMap();
375
- function getAriaPropertyMap(elm) {
376
- let map = nodeToAriaPropertyValuesMap.get(elm);
377
- if (map === undefined) {
378
- map = {};
379
- nodeToAriaPropertyValuesMap.set(elm, map);
380
- }
381
- return map;
382
- }
383
- function getNormalizedAriaPropertyValue(value) {
384
- return value == null ? null : String(value);
385
- }
386
- function createAriaPropertyPropertyDescriptor(propName, attrName) {
387
- return {
388
- get() {
389
- const map = getAriaPropertyMap(this);
390
- if (hasOwnProperty$1.call(map, propName)) {
391
- return map[propName];
392
- }
393
- // otherwise just reflect what's in the attribute
394
- return this.hasAttribute(attrName) ? this.getAttribute(attrName) : null;
395
- },
396
- set(newValue) {
397
- const normalizedValue = getNormalizedAriaPropertyValue(newValue);
398
- const map = getAriaPropertyMap(this);
399
- map[propName] = normalizedValue;
400
- // reflect into the corresponding attribute
401
- if (newValue === null) {
402
- this.removeAttribute(attrName);
403
- }
404
- else {
405
- this.setAttribute(attrName, newValue);
406
- }
407
- },
408
- configurable: true,
409
- enumerable: true,
410
- };
411
- }
412
- function patch$1(propName) {
413
- // Typescript is inferring the wrong function type for this particular
414
- // overloaded method: https://github.com/Microsoft/TypeScript/issues/27972
415
- // @ts-ignore type-mismatch
416
- const attrName = AriaPropNameToAttrNameMap[propName];
417
- const descriptor = createAriaPropertyPropertyDescriptor(propName, attrName);
418
- Object.defineProperty(Element.prototype, propName, descriptor);
419
- }
420
-
421
- /*
422
- * Copyright (c) 2018, salesforce.com, inc.
423
- * All rights reserved.
424
- * SPDX-License-Identifier: MIT
425
- * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
426
- */
427
- const ElementPrototypeAriaPropertyNames = keys(AriaPropNameToAttrNameMap);
428
- for (let i = 0, len = ElementPrototypeAriaPropertyNames.length; i < len; i += 1) {
429
- const propName = ElementPrototypeAriaPropertyNames[i];
430
- if (detect(propName)) {
431
- patch$1(propName);
432
- }
433
- }
434
- /** version: 2.32.0 */
355
+ /** version: 2.33.0 */
435
356
 
436
357
  /**
437
358
  * Copyright (C) 2018 salesforce.com, inc.
@@ -445,19 +366,15 @@
445
366
  */
446
367
  const features = {
447
368
  DUMMY_TEST_FLAG: null,
448
- ENABLE_ELEMENT_PATCH: null,
449
369
  ENABLE_FORCE_NATIVE_SHADOW_MODE_FOR_TEST: null,
450
- ENABLE_HTML_COLLECTIONS_PATCH: null,
451
- ENABLE_INNER_OUTER_TEXT_PATCH: null,
452
370
  ENABLE_MIXED_SHADOW_MODE: null,
453
371
  ENABLE_NATIVE_CUSTOM_ELEMENT_LIFECYCLE: null,
454
- ENABLE_NODE_LIST_PATCH: null,
455
- ENABLE_NODE_PATCH: null,
456
- ENABLE_REACTIVE_SETTER: null,
457
372
  ENABLE_WIRE_SYNC_EMIT: null,
458
373
  ENABLE_LIGHT_GET_ROOT_NODE_PATCH: null,
459
374
  DISABLE_LIGHT_DOM_UNSCOPED_CSS: null,
460
375
  ENABLE_SCOPED_CUSTOM_ELEMENT_REGISTRY: null,
376
+ ENABLE_FROZEN_TEMPLATE: null,
377
+ DISABLE_ARIA_REFLECTION_POLYFILL: null,
461
378
  };
462
379
  if (!_globalThis.lwcRuntimeFlags) {
463
380
  Object.defineProperty(_globalThis, 'lwcRuntimeFlags', { value: create(null) });
@@ -511,7 +428,83 @@
511
428
  setFeatureFlag(name, value);
512
429
  }
513
430
  }
514
- /** version: 2.32.0 */
431
+ /** version: 2.33.0 */
432
+
433
+ /**
434
+ * Copyright (C) 2018 salesforce.com, inc.
435
+ */
436
+
437
+ /*
438
+ * Copyright (c) 2018, salesforce.com, inc.
439
+ * All rights reserved.
440
+ * SPDX-License-Identifier: MIT
441
+ * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
442
+ */
443
+ function detect(propName, prototype) {
444
+ return isUndefined$1(getOwnPropertyDescriptor$1(prototype, propName));
445
+ }
446
+
447
+ /*
448
+ * Copyright (c) 2018, 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
+ function createAriaPropertyPropertyDescriptor(attrName) {
454
+ // Note that we need to call this.{get,set,has,remove}Attribute rather than dereferencing
455
+ // from Element.prototype, because these methods are overridden in LightningElement.
456
+ return {
457
+ get() {
458
+ // reflect what's in the attribute
459
+ return this.hasAttribute(attrName) ? this.getAttribute(attrName) : null;
460
+ },
461
+ set(newValue) {
462
+ // reflect into the corresponding attribute
463
+ if (isNull(newValue)) {
464
+ this.removeAttribute(attrName);
465
+ }
466
+ else {
467
+ this.setAttribute(attrName, newValue);
468
+ }
469
+ },
470
+ configurable: true,
471
+ enumerable: true,
472
+ };
473
+ }
474
+ function patch$1(propName, prototype) {
475
+ const attrName = AriaPropNameToAttrNameMap[propName];
476
+ const descriptor = createAriaPropertyPropertyDescriptor(attrName);
477
+ defineProperty(prototype, propName, descriptor);
478
+ }
479
+
480
+ /*
481
+ * Copyright (c) 2018, salesforce.com, inc.
482
+ * All rights reserved.
483
+ * SPDX-License-Identifier: MIT
484
+ * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
485
+ */
486
+ function applyAriaReflection(prototype = Element.prototype) {
487
+ const ElementPrototypeAriaPropertyNames = keys(AriaPropNameToAttrNameMap);
488
+ for (let i = 0, len = ElementPrototypeAriaPropertyNames.length; i < len; i += 1) {
489
+ const propName = ElementPrototypeAriaPropertyNames[i];
490
+ if (detect(propName, prototype)) {
491
+ patch$1(propName, prototype);
492
+ }
493
+ }
494
+ }
495
+ /** version: 2.33.0 */
496
+
497
+ /*
498
+ * Copyright (c) 2018, salesforce.com, inc.
499
+ * All rights reserved.
500
+ * SPDX-License-Identifier: MIT
501
+ * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
502
+ */
503
+ if (!lwcRuntimeFlags.DISABLE_ARIA_REFLECTION_POLYFILL) {
504
+ // If DISABLE_ARIA_REFLECTION_POLYFILL is false, then we need to apply the ARIA reflection polyfill globally,
505
+ // i.e. to the global Element.prototype
506
+ applyAriaReflection();
507
+ }
515
508
 
516
509
  /*
517
510
  * Copyright (c) 2018, salesforce.com, inc.
@@ -1082,7 +1075,7 @@
1082
1075
  }),
1083
1076
  };
1084
1077
  // Apply extra restriction related to DOM manipulation if the element is not a portal.
1085
- if (!options.isLight && !options.isPortal) {
1078
+ if (!options.isLight && options.isSynthetic && !options.isPortal) {
1086
1079
  const { appendChild, insertBefore, removeChild, replaceChild } = elm;
1087
1080
  const originalNodeValueDescriptor = getPropertyDescriptor(elm, 'nodeValue');
1088
1081
  const originalInnerHTMLDescriptor = getPropertyDescriptor(elm, 'innerHTML');
@@ -1930,46 +1923,51 @@
1930
1923
  * for the Base Lightning Element, it also include the reactivity bit, so the standard property is reactive.
1931
1924
  */
1932
1925
  function createBridgeToElementDescriptor(propName, descriptor) {
1933
- const { get, set, enumerable, configurable } = 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.`);
1937
- }
1938
- throw new TypeError();
1926
+ const {
1927
+ get,
1928
+ set,
1929
+ enumerable,
1930
+ configurable
1931
+ } = descriptor;
1932
+ if (!isFunction$1(get)) {
1933
+ if (process.env.NODE_ENV !== 'production') {
1934
+ assert.fail(`Detected invalid public property descriptor for HTMLElement.prototype.${propName} definition. Missing the standard getter.`);
1939
1935
  }
1940
- if (!isFunction$1(set)) {
1936
+ throw new TypeError();
1937
+ }
1938
+ if (!isFunction$1(set)) {
1939
+ if (process.env.NODE_ENV !== 'production') {
1940
+ assert.fail(`Detected invalid public property descriptor for HTMLElement.prototype.${propName} definition. Missing the standard setter.`);
1941
+ }
1942
+ throw new TypeError();
1943
+ }
1944
+ return {
1945
+ enumerable,
1946
+ configurable,
1947
+ get() {
1948
+ const vm = getAssociatedVM(this);
1949
+ if (isBeingConstructed(vm)) {
1941
1950
  if (process.env.NODE_ENV !== 'production') {
1942
- assert.fail(`Detected invalid public property descriptor for HTMLElement.prototype.${propName} definition. Missing the standard setter.`);
1951
+ 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);
1943
1952
  }
1944
- throw new TypeError();
1953
+ return;
1954
+ }
1955
+ componentValueObserved(vm, propName);
1956
+ return get.call(vm.elm);
1957
+ },
1958
+ set(newValue) {
1959
+ const vm = getAssociatedVM(this);
1960
+ if (process.env.NODE_ENV !== 'production') {
1961
+ const vmBeingRendered = getVMBeingRendered();
1962
+ assert.invariant(!isInvokingRender, `${vmBeingRendered}.render() method has side effects on the state of ${vm}.${propName}`);
1963
+ 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}`);
1964
+ assert.isFalse(isBeingConstructed(vm), `Failed to construct '${getComponentTag(vm)}': The result must not have attributes.`);
1965
+ assert.invariant(!isObject(newValue) || isNull(newValue), `Invalid value "${newValue}" for "${propName}" of ${vm}. Value cannot be an object, must be a primitive value.`);
1966
+ }
1967
+ updateComponentValue(vm, propName, newValue);
1968
+ return set.call(vm.elm, newValue);
1945
1969
  }
1946
- return {
1947
- enumerable,
1948
- configurable,
1949
- get() {
1950
- const vm = getAssociatedVM(this);
1951
- if (isBeingConstructed(vm)) {
1952
- if (process.env.NODE_ENV !== 'production') {
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);
1954
- }
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);
1971
- },
1972
- };
1970
+ };
1973
1971
  }
1974
1972
  const EMPTY_REFS = freeze(create(null));
1975
1973
  const refsCache = new WeakMap();
@@ -1979,345 +1977,442 @@
1979
1977
  **/
1980
1978
  // @ts-ignore
1981
1979
  const LightningElement = function () {
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 { def, elm } = vm;
1990
- const { bridge } = def;
1980
+ // This should be as performant as possible, while any initialization should be done lazily
1981
+ if (isNull(vmBeingConstructed)) {
1982
+ // Thrown when doing something like `new LightningElement()` or
1983
+ // `class Foo extends LightningElement {}; new Foo()`
1984
+ throw new TypeError('Illegal constructor');
1985
+ }
1986
+ const vm = vmBeingConstructed;
1987
+ const {
1988
+ def,
1989
+ elm
1990
+ } = vm;
1991
+ const {
1992
+ bridge
1993
+ } = def;
1994
+ if (process.env.NODE_ENV !== 'production') {
1995
+ const {
1996
+ assertInstanceOfHTMLElement
1997
+ } = vm.renderer;
1998
+ assertInstanceOfHTMLElement(vm.elm, `Component creation requires a DOM element to be associated to ${vm}.`);
1999
+ }
2000
+ const component = this;
2001
+ setPrototypeOf(elm, bridge.prototype);
2002
+ vm.component = this;
2003
+ // Locker hooks assignment. When the LWC engine run with Locker, Locker intercepts all the new
2004
+ // component creation and passes hooks to instrument all the component interactions with the
2005
+ // engine. We are intentionally hiding this argument from the formal API of LightningElement
2006
+ // because we don't want folks to know about it just yet.
2007
+ if (arguments.length === 1) {
2008
+ const {
2009
+ callHook,
2010
+ setHook,
2011
+ getHook
2012
+ } = arguments[0];
2013
+ vm.callHook = callHook;
2014
+ vm.setHook = setHook;
2015
+ vm.getHook = getHook;
2016
+ }
2017
+ markLockerLiveObject(this);
2018
+ // Linking elm, shadow root and component with the VM.
2019
+ associateVM(component, vm);
2020
+ associateVM(elm, vm);
2021
+ if (vm.renderMode === 1 /* RenderMode.Shadow */) {
2022
+ vm.renderRoot = doAttachShadow(vm);
2023
+ } else {
2024
+ vm.renderRoot = elm;
2025
+ }
2026
+ // Adding extra guard rails in DEV mode.
2027
+ if (process.env.NODE_ENV !== 'production') {
2028
+ patchCustomElementWithRestrictions(elm);
2029
+ patchComponentWithRestrictions(component);
2030
+ }
2031
+ return this;
2032
+ };
2033
+ function doAttachShadow(vm) {
2034
+ const {
2035
+ elm,
2036
+ mode,
2037
+ shadowMode,
2038
+ def: {
2039
+ ctor
2040
+ },
2041
+ renderer: {
2042
+ attachShadow
2043
+ }
2044
+ } = vm;
2045
+ const shadowRoot = attachShadow(elm, {
2046
+ [KEY__SYNTHETIC_MODE]: shadowMode === 1 /* ShadowMode.Synthetic */,
2047
+ delegatesFocus: Boolean(ctor.delegatesFocus),
2048
+ mode
2049
+ });
2050
+ vm.shadowRoot = shadowRoot;
2051
+ associateVM(shadowRoot, vm);
2052
+ if (process.env.NODE_ENV !== 'production') {
2053
+ patchShadowRootWithRestrictions(shadowRoot);
2054
+ }
2055
+ return shadowRoot;
2056
+ }
2057
+ function warnIfInvokedDuringConstruction(vm, methodOrPropName) {
2058
+ if (isBeingConstructed(vm)) {
2059
+ 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.`);
2060
+ }
2061
+ }
2062
+ // @ts-ignore
2063
+ LightningElement.prototype = {
2064
+ constructor: LightningElement,
2065
+ dispatchEvent(event) {
2066
+ const vm = getAssociatedVM(this);
2067
+ const {
2068
+ elm,
2069
+ renderer: {
2070
+ dispatchEvent
2071
+ }
2072
+ } = vm;
2073
+ return dispatchEvent(elm, event);
2074
+ },
2075
+ addEventListener(type, listener, options) {
2076
+ const vm = getAssociatedVM(this);
2077
+ const {
2078
+ elm,
2079
+ renderer: {
2080
+ addEventListener
2081
+ }
2082
+ } = vm;
1991
2083
  if (process.env.NODE_ENV !== 'production') {
1992
- const { assertInstanceOfHTMLElement } = vm.renderer;
1993
- assertInstanceOfHTMLElement(vm.elm, `Component creation requires a DOM element to be associated to ${vm}.`);
1994
- }
1995
- const component = this;
1996
- setPrototypeOf(elm, bridge.prototype);
1997
- vm.component = this;
1998
- // Locker hooks assignment. When the LWC engine run with Locker, Locker intercepts all the new
1999
- // component creation and passes hooks to instrument all the component interactions with the
2000
- // engine. We are intentionally hiding this argument from the formal API of LightningElement
2001
- // because we don't want folks to know about it just yet.
2002
- if (arguments.length === 1) {
2003
- const { callHook, setHook, getHook } = arguments[0];
2004
- vm.callHook = callHook;
2005
- vm.setHook = setHook;
2006
- vm.getHook = getHook;
2007
- }
2008
- markLockerLiveObject(this);
2009
- // Linking elm, shadow root and component with the VM.
2010
- associateVM(component, vm);
2011
- associateVM(elm, vm);
2012
- if (vm.renderMode === 1 /* RenderMode.Shadow */) {
2013
- vm.renderRoot = doAttachShadow(vm);
2084
+ const vmBeingRendered = getVMBeingRendered();
2085
+ assert.invariant(!isInvokingRender, `${vmBeingRendered}.render() method has side effects on the state of ${vm} by adding an event listener for "${type}".`);
2086
+ assert.invariant(!isUpdatingTemplate, `Updating the template of ${vmBeingRendered} has side effects on the state of ${vm} by adding an event listener for "${type}".`);
2087
+ assert.invariant(isFunction$1(listener), `Invalid second argument for this.addEventListener() in ${vm} for event "${type}". Expected an EventListener but received ${listener}.`);
2088
+ }
2089
+ const wrappedListener = getWrappedComponentsListener(vm, listener);
2090
+ addEventListener(elm, type, wrappedListener, options);
2091
+ },
2092
+ removeEventListener(type, listener, options) {
2093
+ const vm = getAssociatedVM(this);
2094
+ const {
2095
+ elm,
2096
+ renderer: {
2097
+ removeEventListener
2098
+ }
2099
+ } = vm;
2100
+ const wrappedListener = getWrappedComponentsListener(vm, listener);
2101
+ removeEventListener(elm, type, wrappedListener, options);
2102
+ },
2103
+ hasAttribute(name) {
2104
+ const vm = getAssociatedVM(this);
2105
+ const {
2106
+ elm,
2107
+ renderer: {
2108
+ getAttribute
2109
+ }
2110
+ } = vm;
2111
+ return !isNull(getAttribute(elm, name));
2112
+ },
2113
+ hasAttributeNS(namespace, name) {
2114
+ const vm = getAssociatedVM(this);
2115
+ const {
2116
+ elm,
2117
+ renderer: {
2118
+ getAttribute
2119
+ }
2120
+ } = vm;
2121
+ return !isNull(getAttribute(elm, name, namespace));
2122
+ },
2123
+ removeAttribute(name) {
2124
+ const vm = getAssociatedVM(this);
2125
+ const {
2126
+ elm,
2127
+ renderer: {
2128
+ removeAttribute
2129
+ }
2130
+ } = vm;
2131
+ unlockAttribute(elm, name);
2132
+ removeAttribute(elm, name);
2133
+ lockAttribute();
2134
+ },
2135
+ removeAttributeNS(namespace, name) {
2136
+ const {
2137
+ elm,
2138
+ renderer: {
2139
+ removeAttribute
2140
+ }
2141
+ } = getAssociatedVM(this);
2142
+ unlockAttribute(elm, name);
2143
+ removeAttribute(elm, name, namespace);
2144
+ lockAttribute();
2145
+ },
2146
+ getAttribute(name) {
2147
+ const vm = getAssociatedVM(this);
2148
+ const {
2149
+ elm
2150
+ } = vm;
2151
+ const {
2152
+ getAttribute
2153
+ } = vm.renderer;
2154
+ return getAttribute(elm, name);
2155
+ },
2156
+ getAttributeNS(namespace, name) {
2157
+ const vm = getAssociatedVM(this);
2158
+ const {
2159
+ elm
2160
+ } = vm;
2161
+ const {
2162
+ getAttribute
2163
+ } = vm.renderer;
2164
+ return getAttribute(elm, name, namespace);
2165
+ },
2166
+ setAttribute(name, value) {
2167
+ const vm = getAssociatedVM(this);
2168
+ const {
2169
+ elm,
2170
+ renderer: {
2171
+ setAttribute
2172
+ }
2173
+ } = vm;
2174
+ if (process.env.NODE_ENV !== 'production') {
2175
+ assert.isFalse(isBeingConstructed(vm), `Failed to construct '${getComponentTag(vm)}': The result must not have attributes.`);
2176
+ }
2177
+ unlockAttribute(elm, name);
2178
+ setAttribute(elm, name, value);
2179
+ lockAttribute();
2180
+ },
2181
+ setAttributeNS(namespace, name, value) {
2182
+ const vm = getAssociatedVM(this);
2183
+ const {
2184
+ elm,
2185
+ renderer: {
2186
+ setAttribute
2187
+ }
2188
+ } = vm;
2189
+ if (process.env.NODE_ENV !== 'production') {
2190
+ assert.isFalse(isBeingConstructed(vm), `Failed to construct '${getComponentTag(vm)}': The result must not have attributes.`);
2191
+ }
2192
+ unlockAttribute(elm, name);
2193
+ setAttribute(elm, name, value, namespace);
2194
+ lockAttribute();
2195
+ },
2196
+ getBoundingClientRect() {
2197
+ const vm = getAssociatedVM(this);
2198
+ const {
2199
+ elm,
2200
+ renderer: {
2201
+ getBoundingClientRect
2202
+ }
2203
+ } = vm;
2204
+ if (process.env.NODE_ENV !== 'production') {
2205
+ warnIfInvokedDuringConstruction(vm, 'getBoundingClientRect()');
2014
2206
  }
2015
- else {
2016
- vm.renderRoot = elm;
2207
+ return getBoundingClientRect(elm);
2208
+ },
2209
+ get isConnected() {
2210
+ const vm = getAssociatedVM(this);
2211
+ const {
2212
+ elm,
2213
+ renderer: {
2214
+ isConnected
2215
+ }
2216
+ } = vm;
2217
+ return isConnected(elm);
2218
+ },
2219
+ get classList() {
2220
+ const vm = getAssociatedVM(this);
2221
+ const {
2222
+ elm,
2223
+ renderer: {
2224
+ getClassList
2225
+ }
2226
+ } = vm;
2227
+ if (process.env.NODE_ENV !== 'production') {
2228
+ // TODO [#1290]: this still fails in dev but works in production, eventually, we should
2229
+ // just throw in all modes
2230
+ 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.`);
2231
+ }
2232
+ return getClassList(elm);
2233
+ },
2234
+ get template() {
2235
+ const vm = getAssociatedVM(this);
2236
+ if (process.env.NODE_ENV !== 'production') {
2237
+ if (vm.renderMode === 0 /* RenderMode.Light */) {
2238
+ 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`.');
2239
+ }
2240
+ }
2241
+ return vm.shadowRoot;
2242
+ },
2243
+ get refs() {
2244
+ const vm = getAssociatedVM(this);
2245
+ if (isUpdatingTemplate) {
2246
+ if (process.env.NODE_ENV !== 'production') {
2247
+ 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().`);
2248
+ }
2249
+ // If the template is in the process of being updated, then we don't want to go through the normal
2250
+ // process of returning the refs and caching them, because the state of the refs is unstable.
2251
+ // This can happen if e.g. a template contains `<div class={foo}></div>` and `foo` is computed
2252
+ // based on `this.refs.bar`.
2253
+ return;
2017
2254
  }
2018
- // Adding extra guard rails in DEV mode.
2019
2255
  if (process.env.NODE_ENV !== 'production') {
2020
- patchCustomElementWithRestrictions(elm);
2021
- patchComponentWithRestrictions(component);
2256
+ warnIfInvokedDuringConstruction(vm, 'refs');
2022
2257
  }
2023
- return this;
2024
- };
2025
- function doAttachShadow(vm) {
2026
- const { elm, mode, shadowMode, def: { ctor }, renderer: { attachShadow }, } = vm;
2027
- const shadowRoot = attachShadow(elm, {
2028
- [KEY__SYNTHETIC_MODE]: shadowMode === 1 /* ShadowMode.Synthetic */,
2029
- delegatesFocus: Boolean(ctor.delegatesFocus),
2030
- mode,
2258
+ const {
2259
+ refVNodes,
2260
+ hasRefVNodes,
2261
+ cmpTemplate
2262
+ } = vm;
2263
+ // If the `cmpTemplate` is null, that means that the template has not been rendered yet. Most likely this occurs
2264
+ // if `this.refs` is called during the `connectedCallback` phase. The DOM elements have not been rendered yet,
2265
+ // so log a warning. Note we also check `isBeingConstructed()` to avoid a double warning (due to
2266
+ // `warnIfInvokedDuringConstruction` above).
2267
+ if (process.env.NODE_ENV !== 'production' && isNull(cmpTemplate) && !isBeingConstructed(vm)) {
2268
+ 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().`);
2269
+ }
2270
+ // For backwards compatibility with component written before template refs
2271
+ // were introduced, we return undefined if the template has no refs defined
2272
+ // anywhere. This fixes components that may want to add an expando called `refs`
2273
+ // and are checking if it exists with `if (this.refs)` before adding it.
2274
+ // Note it is not sufficient to just check if `refVNodes` is null or empty,
2275
+ // because a template may have `lwc:ref` defined within a falsy `if:true` block.
2276
+ if (!hasRefVNodes) {
2277
+ return;
2278
+ }
2279
+ // For templates that are using `lwc:ref`, if there are no refs currently available
2280
+ // (e.g. refs inside of a falsy `if:true` block), we return an empty object.
2281
+ if (isNull(refVNodes)) {
2282
+ return EMPTY_REFS;
2283
+ }
2284
+ // The refNodes can be cached based on the refVNodes, since the refVNodes
2285
+ // are recreated from scratch every time the template is rendered.
2286
+ // This happens with `vm.refVNodes = null` in `template.ts` in `@lwc/engine-core`.
2287
+ let refs = refsCache.get(refVNodes);
2288
+ if (isUndefined$1(refs)) {
2289
+ refs = create(null);
2290
+ for (const key of keys(refVNodes)) {
2291
+ refs[key] = refVNodes[key].elm;
2292
+ }
2293
+ freeze(refs);
2294
+ refsCache.set(refVNodes, refs);
2295
+ }
2296
+ return refs;
2297
+ },
2298
+ // For backwards compat, we allow component authors to set `refs` as an expando
2299
+ set refs(value) {
2300
+ defineProperty(this, 'refs', {
2301
+ configurable: true,
2302
+ enumerable: true,
2303
+ writable: true,
2304
+ value
2031
2305
  });
2032
- vm.shadowRoot = shadowRoot;
2033
- associateVM(shadowRoot, vm);
2306
+ },
2307
+ get shadowRoot() {
2308
+ // From within the component instance, the shadowRoot is always reported as "closed".
2309
+ // Authors should rely on this.template instead.
2310
+ return null;
2311
+ },
2312
+ get children() {
2313
+ const vm = getAssociatedVM(this);
2314
+ const renderer = vm.renderer;
2034
2315
  if (process.env.NODE_ENV !== 'production') {
2035
- patchShadowRootWithRestrictions(shadowRoot);
2316
+ warnIfInvokedDuringConstruction(vm, 'children');
2036
2317
  }
2037
- return shadowRoot;
2038
- }
2039
- function warnIfInvokedDuringConstruction(vm, methodOrPropName) {
2040
- if (isBeingConstructed(vm)) {
2041
- 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.`);
2318
+ return renderer.getChildren(vm.elm);
2319
+ },
2320
+ get childNodes() {
2321
+ const vm = getAssociatedVM(this);
2322
+ const renderer = vm.renderer;
2323
+ if (process.env.NODE_ENV !== 'production') {
2324
+ warnIfInvokedDuringConstruction(vm, 'childNodes');
2042
2325
  }
2043
- }
2044
- // @ts-ignore
2045
- LightningElement.prototype = {
2046
- constructor: LightningElement,
2047
- dispatchEvent(event) {
2048
- const vm = getAssociatedVM(this);
2049
- const { elm, renderer: { dispatchEvent }, } = vm;
2050
- return dispatchEvent(elm, event);
2051
- },
2052
- addEventListener(type, listener, options) {
2053
- const vm = getAssociatedVM(this);
2054
- const { elm, renderer: { addEventListener }, } = vm;
2055
- if (process.env.NODE_ENV !== 'production') {
2056
- const vmBeingRendered = getVMBeingRendered();
2057
- assert.invariant(!isInvokingRender, `${vmBeingRendered}.render() method has side effects on the state of ${vm} by adding an event listener for "${type}".`);
2058
- assert.invariant(!isUpdatingTemplate, `Updating the template of ${vmBeingRendered} has side effects on the state of ${vm} by adding an event listener for "${type}".`);
2059
- assert.invariant(isFunction$1(listener), `Invalid second argument for this.addEventListener() in ${vm} for event "${type}". Expected an EventListener but received ${listener}.`);
2060
- }
2061
- const wrappedListener = getWrappedComponentsListener(vm, listener);
2062
- addEventListener(elm, type, wrappedListener, options);
2063
- },
2064
- removeEventListener(type, listener, options) {
2065
- const vm = getAssociatedVM(this);
2066
- const { elm, renderer: { removeEventListener }, } = vm;
2067
- const wrappedListener = getWrappedComponentsListener(vm, listener);
2068
- removeEventListener(elm, type, wrappedListener, options);
2069
- },
2070
- hasAttribute(name) {
2071
- const vm = getAssociatedVM(this);
2072
- const { elm, renderer: { getAttribute }, } = vm;
2073
- return !isNull(getAttribute(elm, name));
2074
- },
2075
- hasAttributeNS(namespace, name) {
2076
- const vm = getAssociatedVM(this);
2077
- const { elm, renderer: { getAttribute }, } = vm;
2078
- return !isNull(getAttribute(elm, name, namespace));
2079
- },
2080
- removeAttribute(name) {
2081
- const vm = getAssociatedVM(this);
2082
- const { elm, renderer: { removeAttribute }, } = vm;
2083
- unlockAttribute(elm, name);
2084
- removeAttribute(elm, name);
2085
- lockAttribute();
2086
- },
2087
- removeAttributeNS(namespace, name) {
2088
- const { elm, renderer: { removeAttribute }, } = getAssociatedVM(this);
2089
- unlockAttribute(elm, name);
2090
- removeAttribute(elm, name, namespace);
2091
- lockAttribute();
2092
- },
2093
- getAttribute(name) {
2094
- const vm = getAssociatedVM(this);
2095
- const { elm } = vm;
2096
- const { getAttribute } = vm.renderer;
2097
- return getAttribute(elm, name);
2098
- },
2099
- getAttributeNS(namespace, name) {
2100
- const vm = getAssociatedVM(this);
2101
- const { elm } = vm;
2102
- const { getAttribute } = vm.renderer;
2103
- return getAttribute(elm, name, namespace);
2104
- },
2105
- setAttribute(name, value) {
2106
- const vm = getAssociatedVM(this);
2107
- const { elm, renderer: { setAttribute }, } = vm;
2108
- if (process.env.NODE_ENV !== 'production') {
2109
- assert.isFalse(isBeingConstructed(vm), `Failed to construct '${getComponentTag(vm)}': The result must not have attributes.`);
2110
- }
2111
- unlockAttribute(elm, name);
2112
- setAttribute(elm, name, value);
2113
- lockAttribute();
2114
- },
2115
- setAttributeNS(namespace, name, value) {
2116
- const vm = getAssociatedVM(this);
2117
- const { elm, renderer: { setAttribute }, } = vm;
2118
- if (process.env.NODE_ENV !== 'production') {
2119
- assert.isFalse(isBeingConstructed(vm), `Failed to construct '${getComponentTag(vm)}': The result must not have attributes.`);
2120
- }
2121
- unlockAttribute(elm, name);
2122
- setAttribute(elm, name, value, namespace);
2123
- lockAttribute();
2124
- },
2125
- getBoundingClientRect() {
2126
- const vm = getAssociatedVM(this);
2127
- const { elm, renderer: { getBoundingClientRect }, } = vm;
2128
- if (process.env.NODE_ENV !== 'production') {
2129
- warnIfInvokedDuringConstruction(vm, 'getBoundingClientRect()');
2130
- }
2131
- return getBoundingClientRect(elm);
2132
- },
2133
- get isConnected() {
2134
- const vm = getAssociatedVM(this);
2135
- const { elm, renderer: { isConnected }, } = vm;
2136
- return isConnected(elm);
2137
- },
2138
- get classList() {
2139
- const vm = getAssociatedVM(this);
2140
- const { elm, renderer: { getClassList }, } = vm;
2141
- if (process.env.NODE_ENV !== 'production') {
2142
- // TODO [#1290]: this still fails in dev but works in production, eventually, we should
2143
- // just throw in all modes
2144
- 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.`);
2145
- }
2146
- return getClassList(elm);
2147
- },
2148
- get template() {
2149
- const vm = getAssociatedVM(this);
2150
- if (process.env.NODE_ENV !== 'production') {
2151
- if (vm.renderMode === 0 /* RenderMode.Light */) {
2152
- 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`.');
2153
- }
2154
- }
2155
- return vm.shadowRoot;
2156
- },
2157
- get refs() {
2158
- const vm = getAssociatedVM(this);
2159
- if (isUpdatingTemplate) {
2160
- if (process.env.NODE_ENV !== 'production') {
2161
- 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().`);
2162
- }
2163
- // If the template is in the process of being updated, then we don't want to go through the normal
2164
- // process of returning the refs and caching them, because the state of the refs is unstable.
2165
- // This can happen if e.g. a template contains `<div class={foo}></div>` and `foo` is computed
2166
- // based on `this.refs.bar`.
2167
- return;
2168
- }
2169
- if (process.env.NODE_ENV !== 'production') {
2170
- warnIfInvokedDuringConstruction(vm, 'refs');
2171
- }
2172
- const { refVNodes, hasRefVNodes, cmpTemplate } = vm;
2173
- // If the `cmpTemplate` is null, that means that the template has not been rendered yet. Most likely this occurs
2174
- // if `this.refs` is called during the `connectedCallback` phase. The DOM elements have not been rendered yet,
2175
- // so log a warning. Note we also check `isBeingConstructed()` to avoid a double warning (due to
2176
- // `warnIfInvokedDuringConstruction` above).
2177
- if (process.env.NODE_ENV !== 'production' &&
2178
- isNull(cmpTemplate) &&
2179
- !isBeingConstructed(vm)) {
2180
- logError(`this.refs is undefined for ${getComponentTag(vm)}. This is either because the attached template has no "lwc:ref" directive, or this.refs was ` +
2181
- `invoked before renderedCallback(). Use this.refs only when the referenced HTML elements have ` +
2182
- `been rendered to the DOM, such as within renderedCallback() or disconnectedCallback().`);
2183
- }
2184
- // For backwards compatibility with component written before template refs
2185
- // were introduced, we return undefined if the template has no refs defined
2186
- // anywhere. This fixes components that may want to add an expando called `refs`
2187
- // and are checking if it exists with `if (this.refs)` before adding it.
2188
- // Note it is not sufficient to just check if `refVNodes` is null or empty,
2189
- // because a template may have `lwc:ref` defined within a falsy `if:true` block.
2190
- if (!hasRefVNodes) {
2191
- return;
2192
- }
2193
- // For templates that are using `lwc:ref`, if there are no refs currently available
2194
- // (e.g. refs inside of a falsy `if:true` block), we return an empty object.
2195
- if (isNull(refVNodes)) {
2196
- return EMPTY_REFS;
2197
- }
2198
- // The refNodes can be cached based on the refVNodes, since the refVNodes
2199
- // are recreated from scratch every time the template is rendered.
2200
- // This happens with `vm.refVNodes = null` in `template.ts` in `@lwc/engine-core`.
2201
- let refs = refsCache.get(refVNodes);
2202
- if (isUndefined$1(refs)) {
2203
- refs = create(null);
2204
- for (const key of keys(refVNodes)) {
2205
- refs[key] = refVNodes[key].elm;
2206
- }
2207
- freeze(refs);
2208
- refsCache.set(refVNodes, refs);
2209
- }
2210
- return refs;
2211
- },
2212
- // For backwards compat, we allow component authors to set `refs` as an expando
2213
- set refs(value) {
2214
- defineProperty(this, 'refs', {
2215
- configurable: true,
2216
- enumerable: true,
2217
- writable: true,
2218
- value,
2219
- });
2220
- },
2221
- get shadowRoot() {
2222
- // From within the component instance, the shadowRoot is always reported as "closed".
2223
- // Authors should rely on this.template instead.
2224
- return null;
2225
- },
2226
- get children() {
2227
- const vm = getAssociatedVM(this);
2228
- const renderer = vm.renderer;
2229
- if (process.env.NODE_ENV !== 'production') {
2230
- warnIfInvokedDuringConstruction(vm, 'children');
2231
- }
2232
- return renderer.getChildren(vm.elm);
2233
- },
2234
- get childNodes() {
2235
- const vm = getAssociatedVM(this);
2236
- const renderer = vm.renderer;
2237
- if (process.env.NODE_ENV !== 'production') {
2238
- warnIfInvokedDuringConstruction(vm, 'childNodes');
2239
- }
2240
- return renderer.getChildNodes(vm.elm);
2241
- },
2242
- get firstChild() {
2243
- const vm = getAssociatedVM(this);
2244
- const renderer = vm.renderer;
2245
- if (process.env.NODE_ENV !== 'production') {
2246
- warnIfInvokedDuringConstruction(vm, 'firstChild');
2247
- }
2248
- return renderer.getFirstChild(vm.elm);
2249
- },
2250
- get firstElementChild() {
2251
- const vm = getAssociatedVM(this);
2252
- const renderer = vm.renderer;
2253
- if (process.env.NODE_ENV !== 'production') {
2254
- warnIfInvokedDuringConstruction(vm, 'firstElementChild');
2255
- }
2256
- return renderer.getFirstElementChild(vm.elm);
2257
- },
2258
- get lastChild() {
2259
- const vm = getAssociatedVM(this);
2260
- const renderer = vm.renderer;
2261
- if (process.env.NODE_ENV !== 'production') {
2262
- warnIfInvokedDuringConstruction(vm, 'lastChild');
2263
- }
2264
- return renderer.getLastChild(vm.elm);
2265
- },
2266
- get lastElementChild() {
2267
- const vm = getAssociatedVM(this);
2268
- const renderer = vm.renderer;
2269
- if (process.env.NODE_ENV !== 'production') {
2270
- warnIfInvokedDuringConstruction(vm, 'lastElementChild');
2271
- }
2272
- return renderer.getLastElementChild(vm.elm);
2273
- },
2274
- render() {
2275
- const vm = getAssociatedVM(this);
2276
- return vm.def.template;
2277
- },
2278
- toString() {
2279
- const vm = getAssociatedVM(this);
2280
- return `[object ${vm.def.name}]`;
2281
- },
2326
+ return renderer.getChildNodes(vm.elm);
2327
+ },
2328
+ get firstChild() {
2329
+ const vm = getAssociatedVM(this);
2330
+ const renderer = vm.renderer;
2331
+ if (process.env.NODE_ENV !== 'production') {
2332
+ warnIfInvokedDuringConstruction(vm, 'firstChild');
2333
+ }
2334
+ return renderer.getFirstChild(vm.elm);
2335
+ },
2336
+ get firstElementChild() {
2337
+ const vm = getAssociatedVM(this);
2338
+ const renderer = vm.renderer;
2339
+ if (process.env.NODE_ENV !== 'production') {
2340
+ warnIfInvokedDuringConstruction(vm, 'firstElementChild');
2341
+ }
2342
+ return renderer.getFirstElementChild(vm.elm);
2343
+ },
2344
+ get lastChild() {
2345
+ const vm = getAssociatedVM(this);
2346
+ const renderer = vm.renderer;
2347
+ if (process.env.NODE_ENV !== 'production') {
2348
+ warnIfInvokedDuringConstruction(vm, 'lastChild');
2349
+ }
2350
+ return renderer.getLastChild(vm.elm);
2351
+ },
2352
+ get lastElementChild() {
2353
+ const vm = getAssociatedVM(this);
2354
+ const renderer = vm.renderer;
2355
+ if (process.env.NODE_ENV !== 'production') {
2356
+ warnIfInvokedDuringConstruction(vm, 'lastElementChild');
2357
+ }
2358
+ return renderer.getLastElementChild(vm.elm);
2359
+ },
2360
+ render() {
2361
+ const vm = getAssociatedVM(this);
2362
+ return vm.def.template;
2363
+ },
2364
+ toString() {
2365
+ const vm = getAssociatedVM(this);
2366
+ return `[object ${vm.def.name}]`;
2367
+ }
2282
2368
  };
2283
2369
  const queryAndChildGetterDescriptors = create(null);
2284
- const queryMethods = [
2285
- 'getElementsByClassName',
2286
- 'getElementsByTagName',
2287
- 'querySelector',
2288
- 'querySelectorAll',
2289
- ];
2370
+ const queryMethods = ['getElementsByClassName', 'getElementsByTagName', 'querySelector', 'querySelectorAll'];
2290
2371
  // Generic passthrough for query APIs on HTMLElement to the relevant Renderer APIs
2291
2372
  for (const queryMethod of queryMethods) {
2292
- queryAndChildGetterDescriptors[queryMethod] = {
2293
- value(arg) {
2294
- const vm = getAssociatedVM(this);
2295
- const { elm, renderer } = vm;
2296
- if (process.env.NODE_ENV !== 'production') {
2297
- warnIfInvokedDuringConstruction(vm, `${queryMethod}()`);
2298
- }
2299
- return renderer[queryMethod](elm, arg);
2300
- },
2301
- configurable: true,
2302
- enumerable: true,
2303
- writable: true,
2304
- };
2373
+ queryAndChildGetterDescriptors[queryMethod] = {
2374
+ value(arg) {
2375
+ const vm = getAssociatedVM(this);
2376
+ const {
2377
+ elm,
2378
+ renderer
2379
+ } = vm;
2380
+ if (process.env.NODE_ENV !== 'production') {
2381
+ warnIfInvokedDuringConstruction(vm, `${queryMethod}()`);
2382
+ }
2383
+ return renderer[queryMethod](elm, arg);
2384
+ },
2385
+ configurable: true,
2386
+ enumerable: true,
2387
+ writable: true
2388
+ };
2305
2389
  }
2306
2390
  defineProperties(LightningElement.prototype, queryAndChildGetterDescriptors);
2307
2391
  const lightningBasedDescriptors = create(null);
2308
2392
  for (const propName in HTMLElementOriginalDescriptors) {
2309
- lightningBasedDescriptors[propName] = createBridgeToElementDescriptor(propName, HTMLElementOriginalDescriptors[propName]);
2393
+ lightningBasedDescriptors[propName] = createBridgeToElementDescriptor(propName, HTMLElementOriginalDescriptors[propName]);
2310
2394
  }
2311
2395
  defineProperties(LightningElement.prototype, lightningBasedDescriptors);
2396
+ function applyAriaReflectionToLightningElement() {
2397
+ // If ARIA reflection is not applied globally to Element.prototype, or if we are running server-side,
2398
+ // apply it to LightningElement.prototype.
2399
+ // This allows `this.aria*` property accessors to work from inside a component, and to reflect `aria-*` attrs.
2400
+ applyAriaReflection(LightningElement.prototype);
2401
+ }
2402
+ // The reason for this odd if/else branching is limitations in @lwc/features:
2403
+ // https://github.com/salesforce/lwc/blob/master/packages/%40lwc/features/README.md#only-works-with-if-statements
2404
+ if (lwcRuntimeFlags.DISABLE_ARIA_REFLECTION_POLYFILL) {
2405
+ applyAriaReflectionToLightningElement();
2406
+ }
2312
2407
  defineProperty(LightningElement, 'CustomElementConstructor', {
2313
- get() {
2314
- // If required, a runtime-specific implementation must be defined.
2315
- throw new ReferenceError('The current runtime does not support CustomElementConstructor.');
2316
- },
2317
- configurable: true,
2408
+ get() {
2409
+ // If required, a runtime-specific implementation must be defined.
2410
+ throw new ReferenceError('The current runtime does not support CustomElementConstructor.');
2411
+ },
2412
+ configurable: true
2318
2413
  });
2319
2414
  if (process.env.NODE_ENV !== 'production') {
2320
- patchLightningElementPrototypeWithRestrictions(LightningElement.prototype);
2415
+ patchLightningElementPrototypeWithRestrictions(LightningElement.prototype);
2321
2416
  }
2322
2417
 
2323
2418
  function createObservedFieldPropertyDescriptor(key) {
@@ -2335,45 +2430,6 @@
2335
2430
  configurable: true,
2336
2431
  };
2337
2432
  }
2338
- class AccessorReactiveObserver extends ReactiveObserver {
2339
- constructor(vm, set) {
2340
- super(() => {
2341
- if (isFalse(this.debouncing)) {
2342
- this.debouncing = true;
2343
- addCallbackToNextTick(() => {
2344
- if (isTrue(this.debouncing)) {
2345
- const { value } = this;
2346
- const { isDirty: dirtyStateBeforeSetterCall, component, idx } = vm;
2347
- set.call(component, value);
2348
- // de-bouncing after the call to the original setter to prevent
2349
- // infinity loop if the setter itself is mutating things that
2350
- // were accessed during the previous invocation.
2351
- this.debouncing = false;
2352
- if (isTrue(vm.isDirty) && isFalse(dirtyStateBeforeSetterCall) && idx > 0) {
2353
- // immediate rehydration due to a setter driven mutation, otherwise
2354
- // the component will get rendered on the second tick, which it is not
2355
- // desirable.
2356
- rerenderVM(vm);
2357
- }
2358
- }
2359
- });
2360
- }
2361
- });
2362
- this.debouncing = false;
2363
- }
2364
- reset(value) {
2365
- super.reset();
2366
- this.debouncing = false;
2367
- if (arguments.length > 0) {
2368
- this.value = value;
2369
- }
2370
- }
2371
- }
2372
- function createAccessorReactiveObserver(vm, set) {
2373
- // On the server side, we don't need mutation tracking. Skipping it improves performance.
2374
- return new AccessorReactiveObserver(vm, set)
2375
- ;
2376
- }
2377
2433
 
2378
2434
  /*
2379
2435
  * Copyright (c) 2018, salesforce.com, inc.
@@ -2382,90 +2438,71 @@
2382
2438
  * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
2383
2439
  */
2384
2440
  function api$1() {
2385
- if (process.env.NODE_ENV !== 'production') {
2386
- assert.fail(`@api decorator can only be used as a decorator function.`);
2387
- }
2388
- throw new Error();
2441
+ if (process.env.NODE_ENV !== 'production') {
2442
+ assert.fail(`@api decorator can only be used as a decorator function.`);
2443
+ }
2444
+ throw new Error();
2389
2445
  }
2390
2446
  function createPublicPropertyDescriptor(key) {
2391
- return {
2392
- get() {
2393
- const vm = getAssociatedVM(this);
2394
- if (isBeingConstructed(vm)) {
2395
- if (process.env.NODE_ENV !== 'production') {
2396
- logError(`Can’t read the value of property \`${toString$1(key)}\` from the constructor because the owner component hasn’t set the value yet. Instead, use the constructor to set a default value for the property.`, vm);
2397
- }
2398
- return;
2399
- }
2400
- componentValueObserved(vm, key);
2401
- return vm.cmpProps[key];
2402
- },
2403
- set(newValue) {
2404
- const vm = getAssociatedVM(this);
2405
- if (process.env.NODE_ENV !== 'production') {
2406
- const vmBeingRendered = getVMBeingRendered();
2407
- assert.invariant(!isInvokingRender, `${vmBeingRendered}.render() method has side effects on the state of ${vm}.${toString$1(key)}`);
2408
- assert.invariant(!isUpdatingTemplate, `Updating the template of ${vmBeingRendered} has side effects on the state of ${vm}.${toString$1(key)}`);
2409
- }
2410
- vm.cmpProps[key] = newValue;
2411
- componentValueMutated(vm, key);
2412
- },
2413
- enumerable: true,
2414
- configurable: true
2415
- };
2447
+ return {
2448
+ get() {
2449
+ const vm = getAssociatedVM(this);
2450
+ if (isBeingConstructed(vm)) {
2451
+ if (process.env.NODE_ENV !== 'production') {
2452
+ logError(`Can’t read the value of property \`${toString$1(key)}\` from the constructor because the owner component hasn’t set the value yet. Instead, use the constructor to set a default value for the property.`, vm);
2453
+ }
2454
+ return;
2455
+ }
2456
+ componentValueObserved(vm, key);
2457
+ return vm.cmpProps[key];
2458
+ },
2459
+ set(newValue) {
2460
+ const vm = getAssociatedVM(this);
2461
+ if (process.env.NODE_ENV !== 'production') {
2462
+ const vmBeingRendered = getVMBeingRendered();
2463
+ assert.invariant(!isInvokingRender, `${vmBeingRendered}.render() method has side effects on the state of ${vm}.${toString$1(key)}`);
2464
+ assert.invariant(!isUpdatingTemplate, `Updating the template of ${vmBeingRendered} has side effects on the state of ${vm}.${toString$1(key)}`);
2465
+ }
2466
+ vm.cmpProps[key] = newValue;
2467
+ componentValueMutated(vm, key);
2468
+ },
2469
+ enumerable: true,
2470
+ configurable: true,
2471
+ };
2416
2472
  }
2417
2473
  function createPublicAccessorDescriptor(key, descriptor) {
2418
- const {
2419
- get,
2420
- set,
2421
- enumerable,
2422
- configurable
2423
- } = descriptor;
2424
- if (!isFunction$1(get)) {
2425
- if (process.env.NODE_ENV !== 'production') {
2426
- assert.invariant(isFunction$1(get), `Invalid compiler output for public accessor ${toString$1(key)} decorated with @api`);
2427
- }
2428
- throw new Error();
2429
- }
2430
- return {
2431
- get() {
2432
- if (process.env.NODE_ENV !== 'production') {
2433
- // Assert that the this value is an actual Component with an associated VM.
2434
- getAssociatedVM(this);
2435
- }
2436
- return get.call(this);
2437
- },
2438
- set(newValue) {
2439
- const vm = getAssociatedVM(this);
2440
- if (process.env.NODE_ENV !== 'production') {
2441
- const vmBeingRendered = getVMBeingRendered();
2442
- assert.invariant(!isInvokingRender, `${vmBeingRendered}.render() method has side effects on the state of ${vm}.${toString$1(key)}`);
2443
- assert.invariant(!isUpdatingTemplate, `Updating the template of ${vmBeingRendered} has side effects on the state of ${vm}.${toString$1(key)}`);
2444
- }
2445
- if (set) {
2446
- if (lwcRuntimeFlags.ENABLE_REACTIVE_SETTER) {
2447
- let ro = vm.oar[key];
2448
- if (isUndefined$1(ro)) {
2449
- ro = vm.oar[key] = createAccessorReactiveObserver(vm, set);
2450
- }
2451
- // every time we invoke this setter from outside (through this wrapper setter)
2452
- // we should reset the value and then debounce just in case there is a pending
2453
- // invocation the next tick that is not longer relevant since the value is changing
2454
- // from outside.
2455
- ro.reset(newValue);
2456
- ro.observe(() => {
2457
- set.call(this, newValue);
2458
- });
2459
- } else {
2460
- set.call(this, newValue);
2474
+ const { get, set, enumerable, configurable } = descriptor;
2475
+ if (!isFunction$1(get)) {
2476
+ if (process.env.NODE_ENV !== 'production') {
2477
+ assert.invariant(isFunction$1(get), `Invalid compiler output for public accessor ${toString$1(key)} decorated with @api`);
2461
2478
  }
2462
- } else if (process.env.NODE_ENV !== 'production') {
2463
- assert.fail(`Invalid attempt to set a new value for property ${toString$1(key)} of ${vm} that does not has a setter decorated with @api.`);
2464
- }
2465
- },
2466
- enumerable,
2467
- configurable
2468
- };
2479
+ throw new Error();
2480
+ }
2481
+ return {
2482
+ get() {
2483
+ if (process.env.NODE_ENV !== 'production') {
2484
+ // Assert that the this value is an actual Component with an associated VM.
2485
+ getAssociatedVM(this);
2486
+ }
2487
+ return get.call(this);
2488
+ },
2489
+ set(newValue) {
2490
+ const vm = getAssociatedVM(this);
2491
+ if (process.env.NODE_ENV !== 'production') {
2492
+ const vmBeingRendered = getVMBeingRendered();
2493
+ assert.invariant(!isInvokingRender, `${vmBeingRendered}.render() method has side effects on the state of ${vm}.${toString$1(key)}`);
2494
+ assert.invariant(!isUpdatingTemplate, `Updating the template of ${vmBeingRendered} has side effects on the state of ${vm}.${toString$1(key)}`);
2495
+ }
2496
+ if (set) {
2497
+ set.call(this, newValue);
2498
+ }
2499
+ else if (process.env.NODE_ENV !== 'production') {
2500
+ assert.fail(`Invalid attempt to set a new value for property ${toString$1(key)} of ${vm} that does not has a setter decorated with @api.`);
2501
+ }
2502
+ },
2503
+ enumerable,
2504
+ configurable,
2505
+ };
2469
2506
  }
2470
2507
 
2471
2508
  /*
@@ -2791,12 +2828,6 @@
2791
2828
  }
2792
2829
  }
2793
2830
 
2794
- /*
2795
- * Copyright (c) 2018, salesforce.com, inc.
2796
- * All rights reserved.
2797
- * SPDX-License-Identifier: MIT
2798
- * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
2799
- */
2800
2831
  const signedTemplateSet = new Set();
2801
2832
  function defaultEmptyTemplate() {
2802
2833
  return [];
@@ -2814,32 +2845,6 @@
2814
2845
  checkVersionMismatch(tpl, 'template');
2815
2846
  }
2816
2847
  signedTemplateSet.add(tpl);
2817
- // FIXME[@W-10950976]: the template object should be frozen, and it should not be possible to set
2818
- // the stylesheets or stylesheetToken(s). For backwards compat, though, we shim stylesheetTokens
2819
- // on top of stylesheetToken for anyone who is accessing the old internal API.
2820
- // Details: https://salesforce.quip.com/v1rmAFu2cKAr
2821
- defineProperty(tpl, 'stylesheetTokens', {
2822
- enumerable: true,
2823
- configurable: true,
2824
- get() {
2825
- const { stylesheetToken } = this;
2826
- if (isUndefined$1(stylesheetToken)) {
2827
- return stylesheetToken;
2828
- }
2829
- // Shim for the old `stylesheetTokens` property
2830
- // See https://github.com/salesforce/lwc/pull/2332/files#diff-7901555acef29969adaa6583185b3e9bce475cdc6f23e799a54e0018cb18abaa
2831
- return {
2832
- hostAttribute: `${stylesheetToken}-host`,
2833
- shadowAttribute: stylesheetToken,
2834
- };
2835
- },
2836
- set(value) {
2837
- // If the value is null or some other exotic object, you would be broken anyway in the past
2838
- // because the engine would try to access hostAttribute/shadowAttribute, which would throw an error.
2839
- // However it may be undefined in newer versions of LWC, so we need to guard against that case.
2840
- this.stylesheetToken = isUndefined$1(value) ? undefined : value.shadowAttribute;
2841
- },
2842
- });
2843
2848
  // chaining this method as a way to wrap existing
2844
2849
  // assignment of templates easily, without too much transformation
2845
2850
  return tpl;
@@ -2867,138 +2872,161 @@
2867
2872
  const cachedGetterByKey = create(null);
2868
2873
  const cachedSetterByKey = create(null);
2869
2874
  function createGetter(key) {
2870
- let fn = cachedGetterByKey[key];
2871
- if (isUndefined$1(fn)) {
2872
- fn = cachedGetterByKey[key] = function () {
2873
- const vm = getAssociatedVM(this);
2874
- const { getHook } = vm;
2875
- return getHook(vm.component, key);
2876
- };
2877
- }
2878
- return fn;
2875
+ let fn = cachedGetterByKey[key];
2876
+ if (isUndefined$1(fn)) {
2877
+ fn = cachedGetterByKey[key] = function () {
2878
+ const vm = getAssociatedVM(this);
2879
+ const {
2880
+ getHook
2881
+ } = vm;
2882
+ return getHook(vm.component, key);
2883
+ };
2884
+ }
2885
+ return fn;
2879
2886
  }
2880
2887
  function createSetter(key) {
2881
- let fn = cachedSetterByKey[key];
2882
- if (isUndefined$1(fn)) {
2883
- fn = cachedSetterByKey[key] = function (newValue) {
2884
- const vm = getAssociatedVM(this);
2885
- const { setHook } = vm;
2886
- newValue = getReadOnlyProxy(newValue);
2887
- setHook(vm.component, key, newValue);
2888
- };
2889
- }
2890
- return fn;
2888
+ let fn = cachedSetterByKey[key];
2889
+ if (isUndefined$1(fn)) {
2890
+ fn = cachedSetterByKey[key] = function (newValue) {
2891
+ const vm = getAssociatedVM(this);
2892
+ const {
2893
+ setHook
2894
+ } = vm;
2895
+ newValue = getReadOnlyProxy(newValue);
2896
+ setHook(vm.component, key, newValue);
2897
+ };
2898
+ }
2899
+ return fn;
2891
2900
  }
2892
2901
  function createMethodCaller(methodName) {
2893
- return function () {
2894
- const vm = getAssociatedVM(this);
2895
- const { callHook, component } = vm;
2896
- const fn = component[methodName];
2897
- return callHook(vm.component, fn, ArraySlice.call(arguments));
2898
- };
2902
+ return function () {
2903
+ const vm = getAssociatedVM(this);
2904
+ const {
2905
+ callHook,
2906
+ component
2907
+ } = vm;
2908
+ const fn = component[methodName];
2909
+ return callHook(vm.component, fn, ArraySlice.call(arguments));
2910
+ };
2899
2911
  }
2900
2912
  function createAttributeChangedCallback(attributeToPropMap, superAttributeChangedCallback) {
2901
- return function attributeChangedCallback(attrName, oldValue, newValue) {
2902
- if (oldValue === newValue) {
2903
- // Ignore same values.
2904
- return;
2905
- }
2906
- const propName = attributeToPropMap[attrName];
2907
- if (isUndefined$1(propName)) {
2908
- if (!isUndefined$1(superAttributeChangedCallback)) {
2909
- // delegate unknown attributes to the super.
2910
- // Typescript does not like it when you treat the `arguments` object as an array
2911
- // @ts-ignore type-mismatch
2912
- superAttributeChangedCallback.apply(this, arguments);
2913
- }
2914
- return;
2915
- }
2916
- if (!isAttributeLocked(this, attrName)) {
2917
- // Ignore changes triggered by the engine itself during:
2918
- // * diffing when public props are attempting to reflect to the DOM
2919
- // * component via `this.setAttribute()`, should never update the prop
2920
- // Both cases, the setAttribute call is always wrapped by the unlocking of the
2921
- // attribute to be changed
2922
- return;
2923
- }
2924
- // Reflect attribute change to the corresponding property when changed from outside.
2925
- this[propName] = newValue;
2926
- };
2927
- }
2928
- function HTMLBridgeElementFactory(SuperClass, props, methods) {
2929
- let HTMLBridgeElement;
2930
- /**
2931
- * Modern browsers will have all Native Constructors as regular Classes
2932
- * and must be instantiated with the new keyword. In older browsers,
2933
- * specifically IE11, those are objects with a prototype property defined,
2934
- * since they are not supposed to be extended or instantiated with the
2935
- * new keyword. This forking logic supports both cases, specifically because
2936
- * wc.ts relies on the construction path of the bridges to create new
2937
- * fully qualifying web components.
2938
- */
2939
- if (isFunction$1(SuperClass)) {
2940
- HTMLBridgeElement = class extends SuperClass {
2941
- };
2942
- }
2943
- else {
2944
- HTMLBridgeElement = function () {
2945
- // Bridge classes are not supposed to be instantiated directly in
2946
- // browsers that do not support web components.
2947
- throw new TypeError('Illegal constructor');
2948
- };
2949
- // prototype inheritance dance
2950
- setPrototypeOf(HTMLBridgeElement, SuperClass);
2951
- setPrototypeOf(HTMLBridgeElement.prototype, SuperClass.prototype);
2952
- defineProperty(HTMLBridgeElement.prototype, 'constructor', {
2953
- writable: true,
2954
- configurable: true,
2955
- value: HTMLBridgeElement,
2956
- });
2913
+ return function attributeChangedCallback(attrName, oldValue, newValue) {
2914
+ if (oldValue === newValue) {
2915
+ // Ignore same values.
2916
+ return;
2957
2917
  }
2958
- // generating the hash table for attributes to avoid duplicate fields and facilitate validation
2959
- // and false positives in case of inheritance.
2960
- const attributeToPropMap = create(null);
2961
- const { attributeChangedCallback: superAttributeChangedCallback } = SuperClass.prototype;
2962
- const { observedAttributes: superObservedAttributes = [] } = SuperClass;
2963
- const descriptors = create(null);
2964
- // expose getters and setters for each public props on the new Element Bridge
2965
- for (let i = 0, len = props.length; i < len; i += 1) {
2966
- const propName = props[i];
2967
- attributeToPropMap[htmlPropertyToAttribute(propName)] = propName;
2968
- descriptors[propName] = {
2969
- get: createGetter(propName),
2970
- set: createSetter(propName),
2971
- enumerable: true,
2972
- configurable: true,
2973
- };
2918
+ const propName = attributeToPropMap[attrName];
2919
+ if (isUndefined$1(propName)) {
2920
+ if (!isUndefined$1(superAttributeChangedCallback)) {
2921
+ // delegate unknown attributes to the super.
2922
+ // Typescript does not like it when you treat the `arguments` object as an array
2923
+ // @ts-ignore type-mismatch
2924
+ superAttributeChangedCallback.apply(this, arguments);
2925
+ }
2926
+ return;
2974
2927
  }
2975
- // expose public methods as props on the new Element Bridge
2976
- for (let i = 0, len = methods.length; i < len; i += 1) {
2977
- const methodName = methods[i];
2978
- descriptors[methodName] = {
2979
- value: createMethodCaller(methodName),
2980
- writable: true,
2981
- configurable: true,
2982
- };
2928
+ if (!isAttributeLocked(this, attrName)) {
2929
+ // Ignore changes triggered by the engine itself during:
2930
+ // * diffing when public props are attempting to reflect to the DOM
2931
+ // * component via `this.setAttribute()`, should never update the prop
2932
+ // Both cases, the setAttribute call is always wrapped by the unlocking of the
2933
+ // attribute to be changed
2934
+ return;
2983
2935
  }
2984
- // creating a new attributeChangedCallback per bridge because they are bound to the corresponding
2985
- // map of attributes to props. We do this after all other props and methods to avoid the possibility
2986
- // of getting overrule by a class declaration in user-land, and we make it non-writable, non-configurable
2987
- // to preserve this definition.
2988
- descriptors.attributeChangedCallback = {
2989
- value: createAttributeChangedCallback(attributeToPropMap, superAttributeChangedCallback),
2936
+ // Reflect attribute change to the corresponding property when changed from outside.
2937
+ this[propName] = newValue;
2938
+ };
2939
+ }
2940
+ function HTMLBridgeElementFactory(SuperClass, props, methods) {
2941
+ let HTMLBridgeElement;
2942
+ /**
2943
+ * Modern browsers will have all Native Constructors as regular Classes
2944
+ * and must be instantiated with the new keyword. In older browsers,
2945
+ * specifically IE11, those are objects with a prototype property defined,
2946
+ * since they are not supposed to be extended or instantiated with the
2947
+ * new keyword. This forking logic supports both cases, specifically because
2948
+ * wc.ts relies on the construction path of the bridges to create new
2949
+ * fully qualifying web components.
2950
+ */
2951
+ if (isFunction$1(SuperClass)) {
2952
+ HTMLBridgeElement = class extends SuperClass {};
2953
+ } else {
2954
+ HTMLBridgeElement = function () {
2955
+ // Bridge classes are not supposed to be instantiated directly in
2956
+ // browsers that do not support web components.
2957
+ throw new TypeError('Illegal constructor');
2990
2958
  };
2991
- // Specify attributes for which we want to reflect changes back to their corresponding
2992
- // properties via attributeChangedCallback.
2993
- defineProperty(HTMLBridgeElement, 'observedAttributes', {
2994
- get() {
2995
- return [...superObservedAttributes, ...keys(attributeToPropMap)];
2996
- },
2959
+ // prototype inheritance dance
2960
+ setPrototypeOf(HTMLBridgeElement, SuperClass);
2961
+ setPrototypeOf(HTMLBridgeElement.prototype, SuperClass.prototype);
2962
+ defineProperty(HTMLBridgeElement.prototype, 'constructor', {
2963
+ writable: true,
2964
+ configurable: true,
2965
+ value: HTMLBridgeElement
2997
2966
  });
2998
- defineProperties(HTMLBridgeElement.prototype, descriptors);
2999
- return HTMLBridgeElement;
2967
+ }
2968
+ // generating the hash table for attributes to avoid duplicate fields and facilitate validation
2969
+ // and false positives in case of inheritance.
2970
+ const attributeToPropMap = create(null);
2971
+ const {
2972
+ attributeChangedCallback: superAttributeChangedCallback
2973
+ } = SuperClass.prototype;
2974
+ const {
2975
+ observedAttributes: superObservedAttributes = []
2976
+ } = SuperClass;
2977
+ const descriptors = create(null);
2978
+ // expose getters and setters for each public props on the new Element Bridge
2979
+ for (let i = 0, len = props.length; i < len; i += 1) {
2980
+ const propName = props[i];
2981
+ attributeToPropMap[htmlPropertyToAttribute(propName)] = propName;
2982
+ descriptors[propName] = {
2983
+ get: createGetter(propName),
2984
+ set: createSetter(propName),
2985
+ enumerable: true,
2986
+ configurable: true
2987
+ };
2988
+ }
2989
+ // expose public methods as props on the new Element Bridge
2990
+ for (let i = 0, len = methods.length; i < len; i += 1) {
2991
+ const methodName = methods[i];
2992
+ descriptors[methodName] = {
2993
+ value: createMethodCaller(methodName),
2994
+ writable: true,
2995
+ configurable: true
2996
+ };
2997
+ }
2998
+ // creating a new attributeChangedCallback per bridge because they are bound to the corresponding
2999
+ // map of attributes to props. We do this after all other props and methods to avoid the possibility
3000
+ // of getting overrule by a class declaration in user-land, and we make it non-writable, non-configurable
3001
+ // to preserve this definition.
3002
+ descriptors.attributeChangedCallback = {
3003
+ value: createAttributeChangedCallback(attributeToPropMap, superAttributeChangedCallback)
3004
+ };
3005
+ // Specify attributes for which we want to reflect changes back to their corresponding
3006
+ // properties via attributeChangedCallback.
3007
+ defineProperty(HTMLBridgeElement, 'observedAttributes', {
3008
+ get() {
3009
+ return [...superObservedAttributes, ...keys(attributeToPropMap)];
3010
+ }
3011
+ });
3012
+ defineProperties(HTMLBridgeElement.prototype, descriptors);
3013
+ return HTMLBridgeElement;
3000
3014
  }
3001
3015
  const BaseBridgeElement = HTMLBridgeElementFactory(HTMLElementConstructor, getOwnPropertyNames$1(HTMLElementOriginalDescriptors), []);
3016
+ {
3017
+ // This ARIA reflection only really makes sense in the browser. On the server, there is no `renderedCallback()`,
3018
+ // so you cannot do e.g. `this.template.querySelector('x-child').ariaBusy = 'true'`. So we don't need to expose
3019
+ // ARIA props outside the LightningElement
3020
+ if (lwcRuntimeFlags.DISABLE_ARIA_REFLECTION_POLYFILL) {
3021
+ // If ARIA reflection is not applied globally to Element.prototype, apply it to HTMLBridgeElement.prototype.
3022
+ // This allows `elm.aria*` property accessors to work from outside a component, and to reflect `aria-*` attrs.
3023
+ // This is especially important because the template compiler compiles aria-* attrs on components to aria* props
3024
+ //
3025
+ // Also note that we apply this to BaseBridgeElement.prototype to avoid excessively redefining property
3026
+ // accessors inside the HTMLBridgeElementFactory.
3027
+ applyAriaReflection(BaseBridgeElement.prototype);
3028
+ }
3029
+ }
3002
3030
  freeze(BaseBridgeElement);
3003
3031
  seal(BaseBridgeElement.prototype);
3004
3032
 
@@ -4376,11 +4404,13 @@
4376
4404
  function applyElementRestrictions(elm, vnode) {
4377
4405
  var _a, _b;
4378
4406
  if (process.env.NODE_ENV !== 'production') {
4407
+ const isSynthetic = vnode.owner.shadowMode === 1 /* ShadowMode.Synthetic */;
4379
4408
  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 */;
4380
4409
  const isLight = vnode.owner.renderMode === 0 /* RenderMode.Light */;
4381
4410
  patchElementWithRestrictions(elm, {
4382
4411
  isPortal,
4383
- isLight
4412
+ isLight,
4413
+ isSynthetic
4384
4414
  });
4385
4415
  }
4386
4416
  }
@@ -4796,7 +4826,7 @@
4796
4826
  // undefined is for root components, but root components cannot accept slotted content
4797
4827
  setVMBeingRendered(slotset.owner);
4798
4828
  try {
4799
- ArrayPush$1.apply(newChildren, vnode.factory(data.slotData));
4829
+ ArrayPush$1.call(newChildren, vnode.factory(data.slotData, data.key));
4800
4830
  }
4801
4831
  finally {
4802
4832
  setVMBeingRendered(vmBeingRenderedInception);
@@ -5676,15 +5706,10 @@
5676
5706
  } = vm;
5677
5707
  if (state !== 2 /* VMState.disconnected */) {
5678
5708
  const {
5679
- oar,
5680
5709
  tro
5681
5710
  } = vm;
5682
5711
  // Making sure that any observing record will not trigger the rehydrated on this vm
5683
5712
  tro.reset();
5684
- // Making sure that any observing accessor record will not trigger the setter to be reinvoked
5685
- for (const key in oar) {
5686
- oar[key].reset();
5687
- }
5688
5713
  runDisconnectedCallback(vm);
5689
5714
  // Spec: https://dom.spec.whatwg.org/#concept-node-remove (step 14-15)
5690
5715
  runChildNodesDisconnectedCallback(vm);
@@ -5737,7 +5762,6 @@
5737
5762
  cmpSlots: {
5738
5763
  slotAssignments: create(null)
5739
5764
  },
5740
- oar: create(null),
5741
5765
  cmpTemplate: null,
5742
5766
  hydrated: Boolean(hydrated),
5743
5767
  renderMode: def.renderMode,
@@ -6918,94 +6942,166 @@
6918
6942
  // See @lwc/engine-core/src/framework/template.ts
6919
6943
  const TEMPLATE_PROPS = ['slots', 'stylesheetToken', 'stylesheets', 'renderMode'];
6920
6944
  // Via https://www.npmjs.com/package/object-observer
6921
- const ARRAY_MUTATION_METHODS = [
6922
- 'pop',
6923
- 'push',
6924
- 'shift',
6925
- 'unshift',
6926
- 'reverse',
6927
- 'sort',
6928
- 'fill',
6929
- 'splice',
6930
- 'copyWithin',
6931
- ];
6945
+ const ARRAY_MUTATION_METHODS = ['pop', 'push', 'shift', 'unshift', 'reverse', 'sort', 'fill', 'splice', 'copyWithin'];
6946
+ // Expandos that may be placed on a stylesheet factory function, and which are meaningful to LWC at runtime
6947
+ const STYLESHEET_FUNCTION_EXPANDOS = [
6948
+ // SEE `KEY__SCOPED_CSS` in @lwc/style-compiler
6949
+ '$scoped$'];
6932
6950
  function getOriginalArrayMethod(prop) {
6933
- switch (prop) {
6934
- case 'pop':
6935
- return ArrayPop;
6936
- case 'push':
6937
- return ArrayPush$1;
6938
- case 'shift':
6939
- return ArrayShift;
6940
- case 'unshift':
6941
- return ArrayUnshift;
6942
- case 'reverse':
6943
- return ArrayReverse;
6944
- case 'sort':
6945
- return ArraySort;
6946
- case 'fill':
6947
- return ArrayFill;
6948
- case 'splice':
6949
- return ArraySplice;
6950
- case 'copyWithin':
6951
- return ArrayCopyWithin;
6952
- }
6951
+ switch (prop) {
6952
+ case 'pop':
6953
+ return ArrayPop;
6954
+ case 'push':
6955
+ return ArrayPush$1;
6956
+ case 'shift':
6957
+ return ArrayShift;
6958
+ case 'unshift':
6959
+ return ArrayUnshift;
6960
+ case 'reverse':
6961
+ return ArrayReverse;
6962
+ case 'sort':
6963
+ return ArraySort;
6964
+ case 'fill':
6965
+ return ArrayFill;
6966
+ case 'splice':
6967
+ return ArraySplice;
6968
+ case 'copyWithin':
6969
+ return ArrayCopyWithin;
6970
+ }
6953
6971
  }
6954
6972
  let mutationWarningsSilenced = false;
6955
- // Warn if the user tries to mutate tmpl.stylesheets, e.g.:
6973
+ // Warn if the user tries to mutate a stylesheets array, e.g.:
6956
6974
  // `tmpl.stylesheets.push(someStylesheetFunction)`
6957
6975
  function warnOnArrayMutation(stylesheets) {
6958
- // We can't handle users calling Array.prototype.slice.call(tmpl.stylesheets), but
6959
- // we can at least warn when they use the most common mutation methods.
6960
- for (const prop of ARRAY_MUTATION_METHODS) {
6961
- const originalArrayMethod = getOriginalArrayMethod(prop);
6962
- stylesheets[prop] = function arrayMutationWarningWrapper() {
6963
- logError(`Mutating the "stylesheets" array on a template function ` +
6964
- `is deprecated and may be removed in a future version of LWC.`);
6965
- // @ts-ignore
6966
- return originalArrayMethod.apply(this, arguments);
6967
- };
6976
+ // We can't handle users calling Array.prototype.slice.call(tmpl.stylesheets), but
6977
+ // we can at least warn when they use the most common mutation methods.
6978
+ for (const prop of ARRAY_MUTATION_METHODS) {
6979
+ const originalArrayMethod = getOriginalArrayMethod(prop);
6980
+ stylesheets[prop] = function arrayMutationWarningWrapper() {
6981
+ logError(`Mutating the "stylesheets" array on a template function ` + `is deprecated and may be removed in a future version of LWC.`);
6982
+ // @ts-ignore
6983
+ return originalArrayMethod.apply(this, arguments);
6984
+ };
6985
+ }
6986
+ }
6987
+ // Warn if the user tries to mutate a stylesheet factory function, e.g.:
6988
+ // `stylesheet.$scoped$ = true`
6989
+ function warnOnStylesheetFunctionMutation(stylesheet) {
6990
+ // We could warn on other properties, but in practice only certain expandos are meaningful to LWC at runtime
6991
+ for (const prop of STYLESHEET_FUNCTION_EXPANDOS) {
6992
+ let value = stylesheet[prop];
6993
+ defineProperty(stylesheet, prop, {
6994
+ enumerable: true,
6995
+ configurable: true,
6996
+ get() {
6997
+ return value;
6998
+ },
6999
+ set(newValue) {
7000
+ logError(`Dynamically setting the "${prop}" property on a stylesheet function ` + `is deprecated and may be removed in a future version of LWC.`);
7001
+ value = newValue;
7002
+ }
7003
+ });
7004
+ }
7005
+ }
7006
+ // Warn on either array or stylesheet (function) mutation, in a deeply-nested array
7007
+ function warnOnStylesheetsMutation(stylesheets) {
7008
+ traverseStylesheets(stylesheets, subStylesheets => {
7009
+ if (isArray$1(subStylesheets)) {
7010
+ warnOnArrayMutation(subStylesheets);
7011
+ } else {
7012
+ warnOnStylesheetFunctionMutation(subStylesheets);
7013
+ }
7014
+ });
7015
+ }
7016
+ // Deeply freeze the entire array (of arrays) of stylesheet factory functions
7017
+ function deepFreeze(stylesheets) {
7018
+ traverseStylesheets(stylesheets, subStylesheets => {
7019
+ freeze(subStylesheets);
7020
+ });
7021
+ }
7022
+ // Deep-traverse an array (of arrays) of stylesheet factory functions, and call the callback for every array/function
7023
+ function traverseStylesheets(stylesheets, callback) {
7024
+ callback(stylesheets);
7025
+ for (let i = 0; i < stylesheets.length; i++) {
7026
+ const stylesheet = stylesheets[i];
7027
+ if (isArray$1(stylesheet)) {
7028
+ traverseStylesheets(stylesheet, callback);
7029
+ } else {
7030
+ callback(stylesheet);
6968
7031
  }
7032
+ }
6969
7033
  }
6970
- // TODO [#2782]: eventually freezeTemplate() will _actually_ freeze the tmpl object. Today it
6971
- // just warns on mutation.
6972
7034
  function freezeTemplate(tmpl) {
6973
- if (process.env.NODE_ENV !== 'production') {
6974
- if (!isUndefined$1(tmpl.stylesheets)) {
6975
- warnOnArrayMutation(tmpl.stylesheets);
6976
- }
6977
- for (const prop of TEMPLATE_PROPS) {
6978
- let value = tmpl[prop];
6979
- defineProperty(tmpl, prop, {
6980
- enumerable: true,
6981
- configurable: true,
6982
- get() {
6983
- return value;
6984
- },
6985
- set(newValue) {
6986
- if (!mutationWarningsSilenced) {
6987
- logError(`Dynamically setting the "${prop}" property on a template function ` +
6988
- `is deprecated and may be removed in a future version of LWC.`);
6989
- }
6990
- value = newValue;
6991
- },
6992
- });
7035
+ if (lwcRuntimeFlags.ENABLE_FROZEN_TEMPLATE) {
7036
+ // Deep freeze the template
7037
+ freeze(tmpl);
7038
+ if (!isUndefined$1(tmpl.stylesheets)) {
7039
+ deepFreeze(tmpl.stylesheets);
7040
+ }
7041
+ } else {
7042
+ // TODO [#2782]: remove this flag and delete the legacy behavior
7043
+ // When ENABLE_FROZEN_TEMPLATE is false, then we shim stylesheetTokens on top of stylesheetToken for anyone who
7044
+ // is accessing the old internal API (backwards compat). Details: https://salesforce.quip.com/v1rmAFu2cKAr
7045
+ defineProperty(tmpl, 'stylesheetTokens', {
7046
+ enumerable: true,
7047
+ configurable: true,
7048
+ get() {
7049
+ const {
7050
+ stylesheetToken
7051
+ } = this;
7052
+ if (isUndefined$1(stylesheetToken)) {
7053
+ return stylesheetToken;
6993
7054
  }
6994
- const originalDescriptor = getOwnPropertyDescriptor$1(tmpl, 'stylesheetTokens');
6995
- defineProperty(tmpl, 'stylesheetTokens', {
6996
- enumerable: true,
6997
- configurable: true,
6998
- get: originalDescriptor.get,
6999
- set(value) {
7000
- logError(`Dynamically setting the "stylesheetTokens" property on a template function ` +
7001
- `is deprecated and may be removed in a future version of LWC.`);
7002
- // Avoid logging twice (for both stylesheetToken and stylesheetTokens)
7003
- mutationWarningsSilenced = true;
7004
- originalDescriptor.set.call(this, value);
7005
- mutationWarningsSilenced = false;
7006
- },
7055
+ // Shim for the old `stylesheetTokens` property
7056
+ // See https://github.com/salesforce/lwc/pull/2332/files#diff-7901555acef29969adaa6583185b3e9bce475cdc6f23e799a54e0018cb18abaa
7057
+ return {
7058
+ hostAttribute: `${stylesheetToken}-host`,
7059
+ shadowAttribute: stylesheetToken
7060
+ };
7061
+ },
7062
+ set(value) {
7063
+ // If the value is null or some other exotic object, you would be broken anyway in the past
7064
+ // because the engine would try to access hostAttribute/shadowAttribute, which would throw an error.
7065
+ // However it may be undefined in newer versions of LWC, so we need to guard against that case.
7066
+ this.stylesheetToken = isUndefined$1(value) ? undefined : value.shadowAttribute;
7067
+ }
7068
+ });
7069
+ // When ENABLE_FROZEN_TEMPLATE is false, warn in dev mode whenever someone is mutating the template
7070
+ if (process.env.NODE_ENV !== 'production') {
7071
+ if (!isUndefined$1(tmpl.stylesheets)) {
7072
+ warnOnStylesheetsMutation(tmpl.stylesheets);
7073
+ }
7074
+ for (const prop of TEMPLATE_PROPS) {
7075
+ let value = tmpl[prop];
7076
+ defineProperty(tmpl, prop, {
7077
+ enumerable: true,
7078
+ configurable: true,
7079
+ get() {
7080
+ return value;
7081
+ },
7082
+ set(newValue) {
7083
+ if (!mutationWarningsSilenced) {
7084
+ logError(`Dynamically setting the "${prop}" property on a template function ` + `is deprecated and may be removed in a future version of LWC.`);
7085
+ }
7086
+ value = newValue;
7087
+ }
7007
7088
  });
7089
+ }
7090
+ const originalDescriptor = getOwnPropertyDescriptor$1(tmpl, 'stylesheetTokens');
7091
+ defineProperty(tmpl, 'stylesheetTokens', {
7092
+ enumerable: true,
7093
+ configurable: true,
7094
+ get: originalDescriptor.get,
7095
+ set(value) {
7096
+ logError(`Dynamically setting the "stylesheetTokens" property on a template function ` + `is deprecated and may be removed in a future version of LWC.`);
7097
+ // Avoid logging twice (for both stylesheetToken and stylesheetTokens)
7098
+ mutationWarningsSilenced = true;
7099
+ originalDescriptor.set.call(this, value);
7100
+ mutationWarningsSilenced = false;
7101
+ }
7102
+ });
7008
7103
  }
7104
+ }
7009
7105
  }
7010
7106
 
7011
7107
  /*
@@ -7030,7 +7126,7 @@
7030
7126
  }
7031
7127
  return ctor;
7032
7128
  }
7033
- /* version: 2.32.0 */
7129
+ /* version: 2.33.0 */
7034
7130
 
7035
7131
  /*
7036
7132
  * Copyright (c) 2018, salesforce.com, inc.
@@ -8003,7 +8099,7 @@
8003
8099
  function isNull(obj) {
8004
8100
  return obj === null;
8005
8101
  }
8006
- /** version: 2.32.0 */
8102
+ /** version: 2.33.0 */
8007
8103
 
8008
8104
  /*
8009
8105
  * Copyright (c) 2018, salesforce.com, inc.
@@ -8564,7 +8660,7 @@
8564
8660
  });
8565
8661
  freeze(LightningElement);
8566
8662
  seal(LightningElement.prototype);
8567
- /* version: 2.32.0 */
8663
+ /* version: 2.33.0 */
8568
8664
 
8569
8665
  exports.LightningElement = LightningElement;
8570
8666
  exports.__unstable__ProfilerControl = profilerControl;