@lwc/engine-core 3.1.3 → 4.0.0-alpha.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.
package/dist/index.js CHANGED
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * Copyright (C) 2023 salesforce.com, inc.
3
3
  */
4
- import { noop, StringToLowerCase, isNull, ArrayPush as ArrayPush$1, ArrayJoin, isFrozen, isUndefined as isUndefined$1, defineProperty, ArrayIndexOf, ArraySplice, create, seal, isArray as isArray$1, isFunction as isFunction$1, keys, hasOwnProperty as hasOwnProperty$1, globalThis as globalThis$1, forEach, AriaPropNameToAttrNameMap, getPropertyDescriptor, defineProperties, getPrototypeOf as getPrototypeOf$1, setPrototypeOf, assign, isObject, freeze, KEY__SYNTHETIC_MODE, assert, toString as toString$1, getOwnPropertyDescriptor as getOwnPropertyDescriptor$1, isFalse, LWC_VERSION_COMMENT_REGEX, LWC_VERSION, getOwnPropertyNames as getOwnPropertyNames$1, htmlPropertyToAttribute, ArraySlice, ArrayMap, KEY__SCOPED_CSS, kebabCaseToCamelCase, StringCharCodeAt, XML_NAMESPACE, XLINK_NAMESPACE, isString, StringSlice, isTrue, SVG_NAMESPACE, KEY__SHADOW_STATIC, KEY__SHADOW_RESOLVER, ArraySome, ArrayPop, isNumber, StringReplace, ArrayUnshift, LOWEST_API_VERSION, KEY__NATIVE_GET_ELEMENT_BY_ID, KEY__NATIVE_QUERY_SELECTOR_ALL, ID_REFERENCING_ATTRIBUTES_SET, KEY__SHADOW_TOKEN, ArrayFilter, StringSplit, arrayEvery, ArrayIncludes, ArrayCopyWithin, ArrayFill, ArraySort, ArrayReverse, ArrayShift } from '@lwc/shared';
4
+ import { noop, StringToLowerCase, isNull, ArrayPush as ArrayPush$1, ArrayJoin, isFrozen, isUndefined as isUndefined$1, defineProperty, ArrayIndexOf, ArraySplice, create, seal, isArray as isArray$1, isFunction as isFunction$1, keys, hasOwnProperty as hasOwnProperty$1, globalThis as globalThis$1, forEach, AriaPropNameToAttrNameMap, getPropertyDescriptor, defineProperties, getPrototypeOf as getPrototypeOf$1, setPrototypeOf, assign, isObject, freeze, KEY__SYNTHETIC_MODE, assert, toString as toString$1, getOwnPropertyDescriptor as getOwnPropertyDescriptor$1, isFalse, LWC_VERSION_COMMENT_REGEX, LWC_VERSION, getOwnPropertyNames as getOwnPropertyNames$1, htmlPropertyToAttribute, ArraySlice, ArrayMap, KEY__SCOPED_CSS, kebabCaseToCamelCase, StringCharCodeAt, XML_NAMESPACE, XLINK_NAMESPACE, isString, StringSlice, isTrue, SVG_NAMESPACE, KEY__SHADOW_STATIC, KEY__SHADOW_RESOLVER, ArraySome, ArrayPop, isAPIFeatureEnabled, isNumber, StringReplace, ArrayUnshift, LOWEST_API_VERSION, KEY__NATIVE_GET_ELEMENT_BY_ID, KEY__NATIVE_QUERY_SELECTOR_ALL, ID_REFERENCING_ATTRIBUTES_SET, KEY__SHADOW_TOKEN, ArrayFilter, StringSplit, arrayEvery, ArrayIncludes, ArrayCopyWithin, ArrayFill, ArraySort, ArrayReverse, ArrayShift } from '@lwc/shared';
5
5
  import { applyAriaReflection } from '@lwc/aria-reflection';
6
6
  export { setFeatureFlag, setFeatureFlagForTest } from '@lwc/features';
7
7
 
@@ -1730,15 +1730,10 @@ for (const propName in HTMLElementOriginalDescriptors) {
1730
1730
  lightningBasedDescriptors[propName] = createBridgeToElementDescriptor(propName, HTMLElementOriginalDescriptors[propName]);
1731
1731
  }
1732
1732
  defineProperties(LightningElement.prototype, lightningBasedDescriptors);
1733
- function applyAriaReflectionToLightningElement() {
1734
- // If ARIA reflection is not applied globally to Element.prototype, or if we are running server-side,
1735
- // apply it to LightningElement.prototype.
1736
- // This allows `this.aria*` property accessors to work from inside a component, and to reflect `aria-*` attrs.
1737
- applyAriaReflection(LightningElement.prototype);
1738
- }
1739
- if (!process.env.IS_BROWSER || lwcRuntimeFlags.DISABLE_ARIA_REFLECTION_POLYFILL) {
1740
- applyAriaReflectionToLightningElement();
1741
- }
1733
+ // Apply ARIA reflection to LightningElement.prototype, on both the browser and server.
1734
+ // This allows `this.aria*` property accessors to work from inside a component, and to reflect `aria-*` attrs.
1735
+ // Note this works regardless of whether the global ARIA reflection polyfill is applied or not.
1736
+ applyAriaReflection(LightningElement.prototype);
1742
1737
  defineProperty(LightningElement, 'CustomElementConstructor', {
1743
1738
  get() {
1744
1739
  // If required, a runtime-specific implementation must be defined.
@@ -2601,15 +2596,15 @@ if (process.env.IS_BROWSER) {
2601
2596
  // This ARIA reflection only really makes sense in the browser. On the server, there is no `renderedCallback()`,
2602
2597
  // so you cannot do e.g. `this.template.querySelector('x-child').ariaBusy = 'true'`. So we don't need to expose
2603
2598
  // ARIA props outside the LightningElement
2604
- if (lwcRuntimeFlags.DISABLE_ARIA_REFLECTION_POLYFILL) {
2605
- // If ARIA reflection is not applied globally to Element.prototype, apply it to HTMLBridgeElement.prototype.
2606
- // This allows `elm.aria*` property accessors to work from outside a component, and to reflect `aria-*` attrs.
2607
- // This is especially important because the template compiler compiles aria-* attrs on components to aria* props
2608
- //
2609
- // Also note that we apply this to BaseBridgeElement.prototype to avoid excessively redefining property
2610
- // accessors inside the HTMLBridgeElementFactory.
2611
- applyAriaReflection(BaseBridgeElement.prototype);
2612
- }
2599
+ //
2600
+ // Apply ARIA reflection to HTMLBridgeElement.prototype. This allows `elm.aria*` property accessors to work from
2601
+ // outside a component, and to reflect `aria-*` attrs. This is especially important because the template compiler
2602
+ // compiles aria-* attrs on components to aria* props.
2603
+ // Note this works regardless of whether the global ARIA reflection polyfill is applied or not.
2604
+ //
2605
+ // Also note that we apply this to BaseBridgeElement.prototype to avoid excessively redefining property
2606
+ // accessors inside the HTMLBridgeElementFactory.
2607
+ applyAriaReflection(BaseBridgeElement.prototype);
2613
2608
  }
2614
2609
  freeze(BaseBridgeElement);
2615
2610
  seal(BaseBridgeElement.prototype);
@@ -3725,16 +3720,16 @@ function mountCustomElement(vnode, parent, anchor, renderer) {
3725
3720
  // the custom element from the registry is expecting an upgrade callback
3726
3721
  vm = createViewModelHook(elm, vnode, renderer);
3727
3722
  };
3728
- let connectedCallback;
3729
- let disconnectedCallback;
3730
- if (lwcRuntimeFlags.ENABLE_NATIVE_CUSTOM_ELEMENT_LIFECYCLE) {
3731
- connectedCallback = (elm) => {
3723
+ const connectedCallback = (elm) => {
3724
+ if (shouldUseNativeCustomElementLifecycle(vm)) {
3732
3725
  connectRootElement(elm);
3733
- };
3734
- disconnectedCallback = (elm) => {
3726
+ }
3727
+ };
3728
+ const disconnectedCallback = (elm) => {
3729
+ if (shouldUseNativeCustomElementLifecycle(vm)) {
3735
3730
  disconnectRootElement(elm);
3736
- };
3737
- }
3731
+ }
3732
+ };
3738
3733
  // Should never get a tag with upper case letter at this point; the compiler
3739
3734
  // should produce only tags with lowercase letters. However, the Java
3740
3735
  // compiler may generate tagnames with uppercase letters so - for backwards
@@ -3752,7 +3747,7 @@ function mountCustomElement(vnode, parent, anchor, renderer) {
3752
3747
  insertNode(elm, parent, anchor, renderer);
3753
3748
  if (vm) {
3754
3749
  if (process.env.IS_BROWSER) {
3755
- if (!lwcRuntimeFlags.ENABLE_NATIVE_CUSTOM_ELEMENT_LIFECYCLE) {
3750
+ if (!shouldUseNativeCustomElementLifecycle(vm)) {
3756
3751
  if (process.env.NODE_ENV !== 'production') {
3757
3752
  // With synthetic lifecycle callbacks, it's possible for elements to be removed without the engine
3758
3753
  // noticing it (e.g. `appendChild` the same host element twice). This test ensures we don't regress.
@@ -4317,6 +4312,14 @@ function updateStaticChildren(c1, c2, parent, renderer) {
4317
4312
  }
4318
4313
  }
4319
4314
  }
4315
+ function shouldUseNativeCustomElementLifecycle(vm) {
4316
+ if (lwcRuntimeFlags.DISABLE_NATIVE_CUSTOM_ELEMENT_LIFECYCLE) {
4317
+ // temporary "kill switch"
4318
+ return false;
4319
+ }
4320
+ const apiVersion = getComponentAPIVersion(vm.component.constructor);
4321
+ return isAPIFeatureEnabled(5 /* APIFeature.ENABLE_NATIVE_CUSTOM_ELEMENT_LIFECYCLE */, apiVersion);
4322
+ }
4320
4323
 
4321
4324
  /*
4322
4325
  * Copyright (c) 2018, salesforce.com, inc.
@@ -4482,10 +4485,16 @@ function s(slotName, data, children, slotset) {
4482
4485
  children = newChildren;
4483
4486
  }
4484
4487
  const vmBeingRendered = getVMBeingRendered();
4485
- const { renderMode, shadowMode } = vmBeingRendered;
4488
+ const { renderMode, shadowMode, apiVersion } = vmBeingRendered;
4486
4489
  if (renderMode === 0 /* RenderMode.Light */) {
4487
- sc(children);
4488
- return children;
4490
+ // light DOM slots - backwards-compatible behavior uses flattening, new behavior uses fragments
4491
+ if (isAPIFeatureEnabled(2 /* APIFeature.USE_FRAGMENTS_FOR_LIGHT_DOM_SLOTS */, apiVersion)) {
4492
+ return fr(data.key, children, 0);
4493
+ }
4494
+ else {
4495
+ sc(children);
4496
+ return children;
4497
+ }
4489
4498
  }
4490
4499
  if (shadowMode === 1 /* ShadowMode.Synthetic */) {
4491
4500
  // TODO [#1276]: compiler should give us some sort of indicator when a vnodes collection is dynamic
@@ -5261,9 +5270,8 @@ function getComponentAPIVersion(Ctor) {
5261
5270
  const metadata = registeredComponentMap.get(Ctor);
5262
5271
  const apiVersion = metadata === null || metadata === void 0 ? void 0 : metadata.apiVersion;
5263
5272
  if (isUndefined$1(apiVersion)) {
5264
- // This should only occur in our Karma tests; in practice every component
5265
- // is registered, and so this code path should not get hit. But to be safe,
5266
- // return the lowest possible version.
5273
+ // This should only occur in two places: 1) our Karma tests, with unregistered components, and
5274
+ // 2) the ACT compiler. To be safe, return the lowest possible API version.
5267
5275
  return LOWEST_API_VERSION;
5268
5276
  }
5269
5277
  return apiVersion;
@@ -5421,6 +5429,7 @@ function getNearestShadowAncestor(vm) {
5421
5429
  function createVM(elm, ctor, renderer, options) {
5422
5430
  const { mode, owner, tagName, hydrated } = options;
5423
5431
  const def = getComponentInternalDef(ctor);
5432
+ const apiVersion = getComponentAPIVersion(ctor);
5424
5433
  const vm = {
5425
5434
  elm,
5426
5435
  def,
@@ -5463,6 +5472,7 @@ function createVM(elm, ctor, renderer, options) {
5463
5472
  setHook,
5464
5473
  getHook,
5465
5474
  renderer,
5475
+ apiVersion,
5466
5476
  };
5467
5477
  if (process.env.NODE_ENV !== 'production') {
5468
5478
  vm.debugInfo = create(null);
@@ -6047,11 +6057,6 @@ const NON_STANDARD_ARIA_PROPS = [
6047
6057
  'ariaLabelledBy',
6048
6058
  'ariaOwns',
6049
6059
  ];
6050
- function isLightningElement(elm) {
6051
- // The former case is for `this.prop` (inside component) and the latter is for `element.prop` (outside component).
6052
- // In both cases, we apply the non-standard prop even when the global polyfill is disabled, so this is kosher.
6053
- return elm instanceof LightningElement || elm instanceof BaseBridgeElement;
6054
- }
6055
6060
  function findVM(elm) {
6056
6061
  // If it's a shadow DOM component, then it has a host
6057
6062
  const { host } = elm.getRootNode();
@@ -6062,7 +6067,8 @@ function findVM(elm) {
6062
6067
  // Else it might be a light DOM component. Walk up the tree trying to find the owner
6063
6068
  let parentElement = elm;
6064
6069
  while (!isNull((parentElement = parentElement.parentElement))) {
6065
- if (isLightningElement(parentElement)) {
6070
+ if (parentElement instanceof BaseBridgeElement) {
6071
+ // parentElement is an LWC component
6066
6072
  const vm = getAssociatedVMIfPresent(parentElement);
6067
6073
  if (!isUndefined$1(vm)) {
6068
6074
  return vm;
@@ -6072,28 +6078,26 @@ function findVM(elm) {
6072
6078
  // If we return undefined, it's because the element was rendered wholly outside a LightningElement
6073
6079
  }
6074
6080
  function checkAndReportViolation(elm, prop, isSetter, setValue) {
6075
- if (!isLightningElement(elm)) {
6076
- const vm = findVM(elm);
6077
- if (process.env.NODE_ENV !== 'production') {
6078
- logWarnOnce(`Element <${elm.tagName.toLowerCase()}> ` +
6079
- (isUndefined$1(vm) ? '' : `owned by <${vm.elm.tagName.toLowerCase()}> `) +
6080
- `uses non-standard property "${prop}". This will be removed in a future version of LWC. ` +
6081
- `See https://sfdc.co/deprecated-aria`);
6082
- }
6083
- let setValueType;
6084
- if (isSetter) {
6085
- // `typeof null` is "object" which is not very useful for detecting null.
6086
- // We mostly want to know null vs undefined vs other types here, due to
6087
- // https://github.com/salesforce/lwc/issues/3284
6088
- setValueType = isNull(setValue) ? 'null' : typeof setValue;
6089
- }
6090
- report("NonStandardAriaReflection" /* ReportingEventId.NonStandardAriaReflection */, {
6091
- tagName: vm === null || vm === void 0 ? void 0 : vm.tagName,
6092
- propertyName: prop,
6093
- isSetter,
6094
- setValueType,
6095
- });
6096
- }
6081
+ const vm = findVM(elm);
6082
+ if (process.env.NODE_ENV !== 'production') {
6083
+ logWarnOnce(`Element <${elm.tagName.toLowerCase()}> ` +
6084
+ (isUndefined$1(vm) ? '' : `owned by <${vm.elm.tagName.toLowerCase()}> `) +
6085
+ `uses non-standard property "${prop}". This will be removed in a future version of LWC. ` +
6086
+ `See https://sfdc.co/deprecated-aria`);
6087
+ }
6088
+ let setValueType;
6089
+ if (isSetter) {
6090
+ // `typeof null` is "object" which is not very useful for detecting null.
6091
+ // We mostly want to know null vs undefined vs other types here, due to
6092
+ // https://github.com/salesforce/lwc/issues/3284
6093
+ setValueType = isNull(setValue) ? 'null' : typeof setValue;
6094
+ }
6095
+ report("NonStandardAriaReflection" /* ReportingEventId.NonStandardAriaReflection */, {
6096
+ tagName: vm === null || vm === void 0 ? void 0 : vm.tagName,
6097
+ propertyName: prop,
6098
+ isSetter,
6099
+ setValueType,
6100
+ });
6097
6101
  }
6098
6102
  function enableDetection() {
6099
6103
  const { prototype } = Element;
@@ -6128,7 +6132,7 @@ function enableDetection() {
6128
6132
  }
6129
6133
  // No point in running this code if we're not in a browser, or if the global polyfill is not loaded
6130
6134
  if (process.env.IS_BROWSER) {
6131
- if (!lwcRuntimeFlags.DISABLE_ARIA_REFLECTION_POLYFILL) {
6135
+ if (lwcRuntimeFlags.ENABLE_ARIA_REFLECTION_GLOBAL_POLYFILL) {
6132
6136
  // Always run detection in dev mode, so we can at least print to the console
6133
6137
  if (process.env.NODE_ENV !== 'production') {
6134
6138
  enableDetection();
@@ -6879,5 +6883,5 @@ function readonly(obj) {
6879
6883
  }
6880
6884
 
6881
6885
  export { LightningElement, profilerControl as __unstable__ProfilerControl, reportingControl as __unstable__ReportingControl, api$1 as api, connectRootElement, createContextProviderWithRegister, createVM, disconnectRootElement, freezeTemplate, getAssociatedVMIfPresent, getComponentAPIVersion, getComponentConstructor, getComponentDef, getComponentHtmlPrototype, hydrateRoot, isComponentConstructor, parseFragment, parseSVGFragment, readonly, register, registerComponent, registerDecorators, registerTemplate, sanitizeAttribute, setHooks, swapComponent, swapStyle, swapTemplate, track, unwrap, wire };
6882
- /** version: 3.1.3 */
6886
+ /** version: 4.0.0-alpha.0 */
6883
6887
  //# sourceMappingURL=index.js.map