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