@lwc/engine-core 5.0.4 → 5.0.6

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.
package/dist/index.cjs.js CHANGED
@@ -424,17 +424,6 @@ var _a, _b;
424
424
  const instrumentDef = (_a = shared.globalThis.__lwc_instrument_cmp_def) !== null && _a !== void 0 ? _a : shared.noop;
425
425
  const instrumentInstance = (_b = shared.globalThis.__lwc_instrument_cmp_instance) !== null && _b !== void 0 ? _b : shared.noop;
426
426
 
427
- /*
428
- * Copyright (c) 2018, salesforce.com, inc.
429
- * All rights reserved.
430
- * SPDX-License-Identifier: MIT
431
- * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
432
- */
433
- // This is a temporary workaround to get the @lwc/engine-server to evaluate in node without having
434
- // to inject at runtime.
435
- const HTMLElementConstructor = typeof HTMLElement !== 'undefined' ? HTMLElement : function () { };
436
- const HTMLElementPrototype = HTMLElementConstructor.prototype;
437
-
438
427
  /*
439
428
  * Copyright (c) 2023, salesforce.com, inc.
440
429
  * All rights reserved.
@@ -443,36 +432,48 @@ const HTMLElementPrototype = HTMLElementConstructor.prototype;
443
432
  */
444
433
  // Apply ARIA string reflection behavior to a prototype.
445
434
  // This is deliberately kept separate from @lwc/aria-reflection. @lwc/aria-reflection is a global polyfill that is
446
- // needed for backwards compatibility in LEX, whereas this is designed to only apply to our own
435
+ // needed for backwards compatibility in LEX, whereas `applyAriaReflection` is designed to only apply to our own
447
436
  // LightningElement/BaseBridgeElement prototypes.
448
- // Note we only need to handle ARIA reflections that aren't already in Element.prototype
449
- const ariaReflectionPolyfillDescriptors = shared.create(null);
450
- for (const [propName, attrName] of shared.entries(shared.AriaPropNameToAttrNameMap)) {
451
- if (shared.isUndefined(shared.getPropertyDescriptor(HTMLElementPrototype, propName))) {
452
- // Note that we need to call this.{get,set,has,remove}Attribute rather than dereferencing
453
- // from Element.prototype, because these methods are overridden in LightningElement.
454
- ariaReflectionPolyfillDescriptors[propName] = {
455
- get() {
456
- return this.getAttribute(attrName);
457
- },
458
- set(newValue) {
459
- // TODO [#3284]: there is disagreement between browsers and the spec on how to treat undefined
460
- // Our historical behavior is to only treat null as removing the attribute
461
- // See also https://github.com/w3c/aria/issues/1858
462
- if (shared.isNull(newValue)) {
463
- this.removeAttribute(attrName);
464
- }
465
- else {
466
- this.setAttribute(attrName, newValue);
467
- }
468
- },
469
- // configurable and enumerable to allow it to be overridden – this mimics Safari's/Chrome's behavior
470
- configurable: true,
471
- enumerable: true,
472
- };
437
+ function applyAriaReflection(prototype) {
438
+ for (const propName of shared.keys(shared.AriaPropNameToAttrNameMap)) {
439
+ const attrName = shared.AriaPropNameToAttrNameMap[propName];
440
+ if (shared.isUndefined(shared.getOwnPropertyDescriptor(prototype, propName))) {
441
+ // Note that we need to call this.{get,set,has,remove}Attribute rather than dereferencing
442
+ // from Element.prototype, because these methods are overridden in LightningElement.
443
+ shared.defineProperty(prototype, propName, {
444
+ get() {
445
+ return this.getAttribute(attrName);
446
+ },
447
+ set(newValue) {
448
+ // TODO [#3284]: there is disagreement between browsers and the spec on how to treat undefined
449
+ // Our historical behavior is to only treat null as removing the attribute
450
+ // See also https://github.com/w3c/aria/issues/1858
451
+ if (shared.isNull(newValue)) {
452
+ this.removeAttribute(attrName);
453
+ }
454
+ else {
455
+ this.setAttribute(attrName, newValue);
456
+ }
457
+ },
458
+ // configurable and enumerable to allow it to be overridden – this mimics Safari's/Chrome's behavior
459
+ configurable: true,
460
+ enumerable: true,
461
+ });
462
+ }
473
463
  }
474
464
  }
475
465
 
466
+ /*
467
+ * Copyright (c) 2018, salesforce.com, inc.
468
+ * All rights reserved.
469
+ * SPDX-License-Identifier: MIT
470
+ * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
471
+ */
472
+ // This is a temporary workaround to get the @lwc/engine-server to evaluate in node without having
473
+ // to inject at runtime.
474
+ const HTMLElementConstructor = typeof HTMLElement !== 'undefined' ? HTMLElement : function () { };
475
+ const HTMLElementPrototype = HTMLElementConstructor.prototype;
476
+
476
477
  /*
477
478
  * Copyright (c) 2018, salesforce.com, inc.
478
479
  * All rights reserved.
@@ -1845,22 +1846,11 @@ const lightningBasedDescriptors = shared.create(null);
1845
1846
  for (const propName in HTMLElementOriginalDescriptors) {
1846
1847
  lightningBasedDescriptors[propName] = createBridgeToElementDescriptor(propName, HTMLElementOriginalDescriptors[propName]);
1847
1848
  }
1849
+ shared.defineProperties(LightningElement.prototype, lightningBasedDescriptors);
1848
1850
  // Apply ARIA reflection to LightningElement.prototype, on both the browser and server.
1849
1851
  // This allows `this.aria*` property accessors to work from inside a component, and to reflect `aria-*` attrs.
1850
1852
  // Note this works regardless of whether the global ARIA reflection polyfill is applied or not.
1851
- if (process.env.IS_BROWSER) {
1852
- // In the browser, we use createBridgeToElementDescriptor, so we can get the normal reactivity lifecycle for
1853
- // aria* properties
1854
- for (const [propName, descriptor] of shared.entries(ariaReflectionPolyfillDescriptors)) {
1855
- lightningBasedDescriptors[propName] = createBridgeToElementDescriptor(propName, descriptor);
1856
- }
1857
- }
1858
- else {
1859
- // On the server, we cannot use createBridgeToElementDescriptor because getAttribute/setAttribute are
1860
- // not supported on HTMLElement. So apply the polyfill directly on top of LightningElement
1861
- shared.defineProperties(LightningElement.prototype, ariaReflectionPolyfillDescriptors);
1862
- }
1863
- shared.defineProperties(LightningElement.prototype, lightningBasedDescriptors);
1853
+ applyAriaReflection(LightningElement.prototype);
1864
1854
  shared.defineProperty(LightningElement, 'CustomElementConstructor', {
1865
1855
  get() {
1866
1856
  // If required, a runtime-specific implementation must be defined.
@@ -2710,8 +2700,7 @@ function HTMLBridgeElementFactory(SuperClass, publicProperties, methods, observe
2710
2700
  // and can break tooling that expects it to be iterable or defined, e.g. Jest:
2711
2701
  // https://github.com/jestjs/jest/blob/b4c9587/packages/pretty-format/src/plugins/DOMElement.ts#L95
2712
2702
  // It also doesn't make sense to override e.g. "constructor".
2713
- .filter((propName) => !(propName in HTMLElementPrototype) &&
2714
- !(propName in ariaReflectionPolyfillDescriptors)));
2703
+ .filter((propName) => !(propName in HTMLElementPrototype)));
2715
2704
  for (const propName of nonPublicPropertiesToWarnOn) {
2716
2705
  if (shared.ArrayIndexOf.call(publicProperties, propName) === -1) {
2717
2706
  descriptors[propName] = createAccessorThatWarns(propName);
@@ -2781,22 +2770,21 @@ function HTMLBridgeElementFactory(SuperClass, publicProperties, methods, observe
2781
2770
  shared.defineProperties(HTMLBridgeElement.prototype, descriptors);
2782
2771
  return HTMLBridgeElement;
2783
2772
  }
2784
- // We do some special handling of non-standard ARIA props like ariaLabelledBy as well as props without (as of this
2785
- // writing) broad cross-browser support like ariaBrailleLabel. This is so the reflection works correctly and preserves
2786
- // backwards compatibility with the previous global polyfill approach.
2787
- //
2788
- // The goal here is to expose `elm.aria*` property accessors to work from outside a component, and to reflect `aria-*`
2789
- // attrs. This is especially important because the template compiler compiles aria-* attrs on components to aria* props.
2790
- // Note this works regardless of whether the global ARIA reflection polyfill is applied or not.
2791
- //
2792
- // Also note this ARIA reflection only really makes sense in the browser. On the server, there is no
2793
- // `renderedCallback()`, so you cannot do e.g. `this.template.querySelector('x-child').ariaBusy = 'true'`. So we don't
2794
- // need to expose ARIA props outside the LightningElement
2795
- const basePublicProperties = [
2796
- ...shared.getOwnPropertyNames(HTMLElementOriginalDescriptors),
2797
- ...(process.env.IS_BROWSER ? shared.getOwnPropertyNames(ariaReflectionPolyfillDescriptors) : []),
2798
- ];
2799
- const BaseBridgeElement = HTMLBridgeElementFactory(HTMLElementConstructor, basePublicProperties, [], [], null, false);
2773
+ const BaseBridgeElement = HTMLBridgeElementFactory(HTMLElementConstructor, shared.getOwnPropertyNames(HTMLElementOriginalDescriptors), [], [], null, false);
2774
+ if (process.env.IS_BROWSER) {
2775
+ // This ARIA reflection only really makes sense in the browser. On the server, there is no `renderedCallback()`,
2776
+ // so you cannot do e.g. `this.template.querySelector('x-child').ariaBusy = 'true'`. So we don't need to expose
2777
+ // ARIA props outside the LightningElement
2778
+ //
2779
+ // Apply ARIA reflection to HTMLBridgeElement.prototype. This allows `elm.aria*` property accessors to work from
2780
+ // outside a component, and to reflect `aria-*` attrs. This is especially important because the template compiler
2781
+ // compiles aria-* attrs on components to aria* props.
2782
+ // Note this works regardless of whether the global ARIA reflection polyfill is applied or not.
2783
+ //
2784
+ // Also note that we apply this to BaseBridgeElement.prototype to avoid excessively redefining property
2785
+ // accessors inside the HTMLBridgeElementFactory.
2786
+ applyAriaReflection(BaseBridgeElement.prototype);
2787
+ }
2800
2788
  shared.freeze(BaseBridgeElement);
2801
2789
  shared.seal(BaseBridgeElement.prototype);
2802
2790
 
@@ -7371,5 +7359,5 @@ exports.swapTemplate = swapTemplate;
7371
7359
  exports.track = track;
7372
7360
  exports.unwrap = unwrap;
7373
7361
  exports.wire = wire;
7374
- /** version: 5.0.4 */
7362
+ /** version: 5.0.6 */
7375
7363
  //# sourceMappingURL=index.cjs.js.map