@lwc/engine-core 2.43.0 → 2.44.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.
@@ -1,5 +1,5 @@
1
1
  /* proxy-compat-disable */
2
- 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, forEach, AriaPropNameToAttrNameMap, getPropertyDescriptor, defineProperties, getOwnPropertyNames as getOwnPropertyNames$1, getPrototypeOf as getPrototypeOf$1, setPrototypeOf, assign, isObject, assert, freeze, KEY__SYNTHETIC_MODE, toString as toString$1, getOwnPropertyDescriptor as getOwnPropertyDescriptor$1, isFalse, LWC_VERSION_COMMENT_REGEX, LWC_VERSION, htmlPropertyToAttribute, ArraySlice, ArrayMap, KEY__SCOPED_CSS, StringCharCodeAt, XML_NAMESPACE, XLINK_NAMESPACE, htmlAttributeToProperty, isString, StringSlice, isTrue, SVG_NAMESPACE, KEY__SHADOW_STATIC, KEY__SHADOW_RESOLVER, ArraySome, ArrayPop, isNumber, StringReplace, ArrayUnshift, globalThis as globalThis$1, KEY__NATIVE_GET_ELEMENT_BY_ID, KEY__NATIVE_QUERY_SELECTOR_ALL, ID_REFERENCING_ATTRIBUTES_SET, KEY__SHADOW_TOKEN, ArrayFilter, StringSplit, htmlEscape, ArrayCopyWithin, ArrayFill, ArraySort, ArrayReverse, ArrayShift } from '@lwc/shared';
2
+ 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, forEach, AriaPropNameToAttrNameMap, getPropertyDescriptor, defineProperties, getPrototypeOf as getPrototypeOf$1, setPrototypeOf, assign, isObject, assert, freeze, KEY__SYNTHETIC_MODE, 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, StringCharCodeAt, XML_NAMESPACE, XLINK_NAMESPACE, htmlAttributeToProperty, isString, StringSlice, isTrue, SVG_NAMESPACE, KEY__SHADOW_STATIC, KEY__SHADOW_RESOLVER, ArraySome, ArrayPop, isNumber, StringReplace, ArrayUnshift, globalThis as globalThis$1, KEY__NATIVE_GET_ELEMENT_BY_ID, KEY__NATIVE_QUERY_SELECTOR_ALL, ID_REFERENCING_ATTRIBUTES_SET, KEY__SHADOW_TOKEN, ArrayFilter, StringSplit, ArrayCopyWithin, ArrayFill, ArraySort, ArrayReverse, ArrayShift } from '@lwc/shared';
3
3
  import { applyAriaReflection } from '@lwc/aria-reflection';
4
4
  export { setFeatureFlag, setFeatureFlagForTest } from '@lwc/features';
5
5
 
@@ -444,101 +444,6 @@ const defaultDefHTMLPropertyNames = [
444
444
  'tabIndex',
445
445
  'title',
446
446
  ];
447
- function offsetPropertyErrorMessage(name) {
448
- return `Using the \`${name}\` property is an anti-pattern because it rounds the value to an integer. Instead, use the \`getBoundingClientRect\` method to obtain fractional values for the size of an element and its position relative to the viewport.`;
449
- }
450
- // Global HTML Attributes & Properties
451
- // https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes
452
- // https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement
453
- //
454
- // If you update this list, check for test files that recapitulate the same list. Searching the codebase
455
- // for e.g. "dropzone" should suffice.
456
- const globalHTMLProperties = {
457
- accessKey: {
458
- attribute: 'accesskey',
459
- },
460
- accessKeyLabel: {
461
- readOnly: true,
462
- },
463
- className: {
464
- attribute: 'class',
465
- error: 'Using the `className` property is an anti-pattern because of slow runtime behavior and potential conflicts with classes provided by the owner element. Use the `classList` API instead.',
466
- },
467
- contentEditable: {
468
- attribute: 'contenteditable',
469
- },
470
- dataset: {
471
- readOnly: true,
472
- error: "Using the `dataset` property is an anti-pattern because it can't be statically analyzed. Expose each property individually using the `@api` decorator instead.",
473
- },
474
- dir: {
475
- attribute: 'dir',
476
- },
477
- draggable: {
478
- attribute: 'draggable',
479
- },
480
- dropzone: {
481
- attribute: 'dropzone',
482
- readOnly: true,
483
- },
484
- hidden: {
485
- attribute: 'hidden',
486
- },
487
- id: {
488
- attribute: 'id',
489
- },
490
- inputMode: {
491
- attribute: 'inputmode',
492
- },
493
- lang: {
494
- attribute: 'lang',
495
- },
496
- slot: {
497
- attribute: 'slot',
498
- error: 'Using the `slot` property is an anti-pattern.',
499
- },
500
- spellcheck: {
501
- attribute: 'spellcheck',
502
- },
503
- style: {
504
- attribute: 'style',
505
- },
506
- tabIndex: {
507
- attribute: 'tabindex',
508
- },
509
- title: {
510
- attribute: 'title',
511
- },
512
- translate: {
513
- attribute: 'translate',
514
- },
515
- // additional "global attributes" that are not present in the link above.
516
- isContentEditable: {
517
- readOnly: true,
518
- },
519
- offsetHeight: {
520
- readOnly: true,
521
- error: offsetPropertyErrorMessage('offsetHeight'),
522
- },
523
- offsetLeft: {
524
- readOnly: true,
525
- error: offsetPropertyErrorMessage('offsetLeft'),
526
- },
527
- offsetParent: {
528
- readOnly: true,
529
- },
530
- offsetTop: {
531
- readOnly: true,
532
- error: offsetPropertyErrorMessage('offsetTop'),
533
- },
534
- offsetWidth: {
535
- readOnly: true,
536
- error: offsetPropertyErrorMessage('offsetWidth'),
537
- },
538
- role: {
539
- attribute: 'role',
540
- },
541
- };
542
447
  let controlledElement = null;
543
448
  let controlledAttributeName;
544
449
  function isAttributeLocked(elm, attrName) {
@@ -723,8 +628,7 @@ function getShadowRootRestrictionsDescriptors(sr) {
723
628
  }),
724
629
  addEventListener: generateDataDescriptor({
725
630
  value(type, listener, options) {
726
- // TODO [#420]: this is triggered when the component author attempts to add a listener
727
- // programmatically into its Component's shadow root
631
+ // TODO [#1824]: Potentially relax this restriction
728
632
  if (!isUndefined$1(options)) {
729
633
  logError('The `addEventListener` method on ShadowRoot does not support any options.', getAssociatedVMIfPresent(this));
730
634
  }
@@ -770,8 +674,7 @@ function getCustomElementRestrictionsDescriptors(elm) {
770
674
  }),
771
675
  addEventListener: generateDataDescriptor({
772
676
  value(type, listener, options) {
773
- // TODO [#420]: this is triggered when the component author attempts to add a listener
774
- // programmatically into a lighting element node
677
+ // TODO [#1824]: Potentially relax this restriction
775
678
  if (!isUndefined$1(options)) {
776
679
  logError('The `addEventListener` method in `LightningElement` does not support any options.', getAssociatedVMIfPresent(this));
777
680
  }
@@ -799,7 +702,7 @@ function getComponentRestrictionsDescriptors() {
799
702
  function getLightningElementPrototypeRestrictionsDescriptors(proto) {
800
703
  assertNotProd(); // this method should never leak to prod
801
704
  const originalDispatchEvent = proto.dispatchEvent;
802
- const descriptors = {
705
+ return {
803
706
  dispatchEvent: generateDataDescriptor({
804
707
  value(event) {
805
708
  const vm = getAssociatedVM(this);
@@ -817,32 +720,6 @@ function getLightningElementPrototypeRestrictionsDescriptors(proto) {
817
720
  },
818
721
  }),
819
722
  };
820
- forEach.call(getOwnPropertyNames$1(globalHTMLProperties), (propName) => {
821
- if (propName in proto) {
822
- return; // no need to redefine something that we are already exposing
823
- }
824
- descriptors[propName] = generateAccessorDescriptor({
825
- get() {
826
- const { error, attribute } = globalHTMLProperties[propName];
827
- const msg = [];
828
- msg.push(`Accessing the global HTML property "${propName}" is disabled.`);
829
- if (error) {
830
- msg.push(error);
831
- }
832
- else if (attribute) {
833
- msg.push(`Instead access it via \`this.getAttribute("${attribute}")\`.`);
834
- }
835
- logError(msg.join('\n'), getAssociatedVM(this));
836
- },
837
- set() {
838
- const { readOnly } = globalHTMLProperties[propName];
839
- if (readOnly) {
840
- logError(`The global HTML property \`${propName}\` is read-only.`, getAssociatedVM(this));
841
- }
842
- },
843
- });
844
- });
845
- return descriptors;
846
723
  }
847
724
  // This routine will prevent access to certain properties on a shadow root instance to guarantee
848
725
  // that all components will work fine in IE11 and other browsers without shadow dom support.
@@ -2193,12 +2070,7 @@ function createPublicPropertyDescriptor(key) {
2193
2070
  }
2194
2071
  function createPublicAccessorDescriptor(key, descriptor) {
2195
2072
  const { get, set, enumerable, configurable } = descriptor;
2196
- if (!isFunction$1(get)) {
2197
- if (process.env.NODE_ENV !== 'production') {
2198
- assert.invariant(isFunction$1(get), `Invalid compiler output for public accessor ${toString$1(key)} decorated with @api`);
2199
- }
2200
- throw new Error();
2201
- }
2073
+ assert.invariant(isFunction$1(get), `Invalid public accessor ${toString$1(key)} decorated with @api. The property is missing a getter.`);
2202
2074
  return {
2203
2075
  get() {
2204
2076
  if (process.env.NODE_ENV !== 'production') {
@@ -2320,64 +2192,64 @@ function getClassDescriptorType(descriptor) {
2320
2192
  }
2321
2193
  }
2322
2194
  function validateObservedField(Ctor, fieldName, descriptor) {
2195
+ assertNotProd(); // this method should never leak to prod
2323
2196
  if (!isUndefined$1(descriptor)) {
2324
2197
  const type = getClassDescriptorType(descriptor);
2325
2198
  const message = `Invalid observed ${fieldName} field. Found a duplicate ${type} with the same name.`;
2326
- // [W-9927596] Ideally we always throw an error when detecting duplicate observed field.
2327
- // This branch is only here for backward compatibility reasons.
2328
- if (type === "accessor" /* DescriptorType.Accessor */) {
2329
- logError(message);
2330
- }
2331
- else {
2332
- assert.fail(message);
2333
- }
2199
+ // TODO [#3408]: this should throw, not log
2200
+ logError(message);
2334
2201
  }
2335
2202
  }
2336
2203
  function validateFieldDecoratedWithTrack(Ctor, fieldName, descriptor) {
2204
+ assertNotProd(); // this method should never leak to prod
2337
2205
  if (!isUndefined$1(descriptor)) {
2338
2206
  const type = getClassDescriptorType(descriptor);
2339
- assert.fail(`Invalid @track ${fieldName} field. Found a duplicate ${type} with the same name.`);
2207
+ // TODO [#3408]: this should throw, not log
2208
+ logError(`Invalid @track ${fieldName} field. Found a duplicate ${type} with the same name.`);
2340
2209
  }
2341
2210
  }
2342
2211
  function validateFieldDecoratedWithWire(Ctor, fieldName, descriptor) {
2212
+ assertNotProd(); // this method should never leak to prod
2343
2213
  if (!isUndefined$1(descriptor)) {
2344
2214
  const type = getClassDescriptorType(descriptor);
2345
- assert.fail(`Invalid @wire ${fieldName} field. Found a duplicate ${type} with the same name.`);
2215
+ // TODO [#3408]: this should throw, not log
2216
+ logError(`Invalid @wire ${fieldName} field. Found a duplicate ${type} with the same name.`);
2346
2217
  }
2347
2218
  }
2348
2219
  function validateMethodDecoratedWithWire(Ctor, methodName, descriptor) {
2220
+ assertNotProd(); // this method should never leak to prod
2349
2221
  if (isUndefined$1(descriptor) || !isFunction$1(descriptor.value) || isFalse(descriptor.writable)) {
2350
- assert.fail(`Invalid @wire ${methodName} method.`);
2222
+ // TODO [#3441]: This line of code does not seem possible to reach.
2223
+ logError(`Invalid @wire ${methodName} field. The field should have a valid writable descriptor.`);
2351
2224
  }
2352
2225
  }
2353
2226
  function validateFieldDecoratedWithApi(Ctor, fieldName, descriptor) {
2227
+ assertNotProd(); // this method should never leak to prod
2354
2228
  if (!isUndefined$1(descriptor)) {
2355
2229
  const type = getClassDescriptorType(descriptor);
2356
2230
  const message = `Invalid @api ${fieldName} field. Found a duplicate ${type} with the same name.`;
2357
- // [W-9927596] Ideally we always throw an error when detecting duplicate public properties.
2358
- // This branch is only here for backward compatibility reasons.
2359
- if (type === "accessor" /* DescriptorType.Accessor */) {
2360
- logError(message);
2361
- }
2362
- else {
2363
- assert.fail(message);
2364
- }
2231
+ // TODO [#3408]: this should throw, not log
2232
+ logError(message);
2365
2233
  }
2366
2234
  }
2367
2235
  function validateAccessorDecoratedWithApi(Ctor, fieldName, descriptor) {
2368
- if (isUndefined$1(descriptor)) {
2369
- assert.fail(`Invalid @api get ${fieldName} accessor.`);
2370
- }
2371
- else if (isFunction$1(descriptor.set)) {
2372
- assert.isTrue(isFunction$1(descriptor.get), `Missing getter for property ${fieldName} decorated with @api in ${Ctor}. You cannot have a setter without the corresponding getter.`);
2236
+ assertNotProd(); // this method should never leak to prod
2237
+ if (isFunction$1(descriptor.set)) {
2238
+ if (!isFunction$1(descriptor.get)) {
2239
+ // TODO [#3441]: This line of code does not seem possible to reach.
2240
+ logError(`Missing getter for property ${fieldName} decorated with @api in ${Ctor}. You cannot have a setter without the corresponding getter.`);
2241
+ }
2373
2242
  }
2374
2243
  else if (!isFunction$1(descriptor.get)) {
2375
- assert.fail(`Missing @api get ${fieldName} accessor.`);
2244
+ // TODO [#3441]: This line of code does not seem possible to reach.
2245
+ logError(`Missing @api get ${fieldName} accessor.`);
2376
2246
  }
2377
2247
  }
2378
2248
  function validateMethodDecoratedWithApi(Ctor, methodName, descriptor) {
2249
+ assertNotProd(); // this method should never leak to prod
2379
2250
  if (isUndefined$1(descriptor) || !isFunction$1(descriptor.value) || isFalse(descriptor.writable)) {
2380
- assert.fail(`Invalid @api ${methodName} method.`);
2251
+ // TODO [#3441]: This line of code does not seem possible to reach.
2252
+ logError(`Invalid @api ${methodName} method.`);
2381
2253
  }
2382
2254
  }
2383
2255
  /**
@@ -2400,13 +2272,14 @@ function registerDecorators(Ctor, meta) {
2400
2272
  apiFieldsConfig[fieldName] = propConfig.config;
2401
2273
  descriptor = getOwnPropertyDescriptor$1(proto, fieldName);
2402
2274
  if (propConfig.config > 0) {
2275
+ if (isUndefined$1(descriptor)) {
2276
+ // TODO [#3441]: This line of code does not seem possible to reach.
2277
+ throw new Error();
2278
+ }
2403
2279
  // accessor declaration
2404
2280
  if (process.env.NODE_ENV !== 'production') {
2405
2281
  validateAccessorDecoratedWithApi(Ctor, fieldName, descriptor);
2406
2282
  }
2407
- if (isUndefined$1(descriptor)) {
2408
- throw new Error();
2409
- }
2410
2283
  descriptor = createPublicAccessorDescriptor(fieldName, descriptor);
2411
2284
  }
2412
2285
  else {
@@ -2446,7 +2319,10 @@ function registerDecorators(Ctor, meta) {
2446
2319
  descriptor = getOwnPropertyDescriptor$1(proto, fieldOrMethodName);
2447
2320
  if (method === 1) {
2448
2321
  if (process.env.NODE_ENV !== 'production') {
2449
- assert.isTrue(adapter, `@wire on method "${fieldOrMethodName}": adapter id must be truthy.`);
2322
+ if (!adapter) {
2323
+ // TODO [#3408]: this should throw, not log
2324
+ logError(`@wire on method "${fieldOrMethodName}": adapter id must be truthy.`);
2325
+ }
2450
2326
  validateMethodDecoratedWithWire(Ctor, fieldOrMethodName, descriptor);
2451
2327
  }
2452
2328
  if (isUndefined$1(descriptor)) {
@@ -2457,7 +2333,10 @@ function registerDecorators(Ctor, meta) {
2457
2333
  }
2458
2334
  else {
2459
2335
  if (process.env.NODE_ENV !== 'production') {
2460
- assert.isTrue(adapter, `@wire on field "${fieldOrMethodName}": adapter id must be truthy.`);
2336
+ if (!adapter) {
2337
+ // TODO [#3408]: this should throw, not log
2338
+ logError(`@wire on field "${fieldOrMethodName}": adapter id must be truthy.`);
2339
+ }
2461
2340
  validateFieldDecoratedWithWire(Ctor, fieldOrMethodName, descriptor);
2462
2341
  }
2463
2342
  descriptor = internalWireFieldDecorator(fieldOrMethodName);
@@ -6340,8 +6219,6 @@ function hydrateNode(node, vnode, renderer) {
6340
6219
  return renderer.nextSibling(hydratedNode);
6341
6220
  }
6342
6221
  const NODE_VALUE_PROP = 'nodeValue';
6343
- const PARENT_NODE_PROP = 'parentNode';
6344
- const TAG_NAME_PROP = 'tagName';
6345
6222
  function textNodeContentsAreEqual(node, vnode, renderer) {
6346
6223
  const { getProperty } = renderer;
6347
6224
  const nodeValue = getProperty(node, NODE_VALUE_PROP);
@@ -6353,22 +6230,6 @@ function textNodeContentsAreEqual(node, vnode, renderer) {
6353
6230
  if (nodeValue === '\u200D' && vnode.text === '') {
6354
6231
  return true;
6355
6232
  }
6356
- // Special case for text nodes inside `<style>` tags – these are escaped when rendered server-size,
6357
- // but not when generated by the engine client-side.
6358
- const parentNode = getProperty(node, PARENT_NODE_PROP);
6359
- // Should never be null, but just to be safe, we check.
6360
- /* istanbul ignore else */
6361
- if (!isNull(parentNode)) {
6362
- const tagName = getProperty(parentNode, TAG_NAME_PROP);
6363
- // If the tagName is STYLE, then the following condition should always be true.
6364
- // The LWC compiler blocks using `<style>`s inside of templates, so it should be impossible
6365
- // for component authors to render different `<style>` text content on the client and server.
6366
- // But just to be safe, we check.
6367
- /* istanbul ignore next */
6368
- if (tagName === 'STYLE' && htmlEscape(vnode.text) === nodeValue) {
6369
- return true;
6370
- }
6371
- }
6372
6233
  return false;
6373
6234
  }
6374
6235
  function hydrateText(node, vnode, renderer) {
@@ -6994,12 +6855,12 @@ function readonly(obj) {
6994
6855
  if (process.env.NODE_ENV !== 'production') {
6995
6856
  // TODO [#1292]: Remove the readonly decorator
6996
6857
  if (arguments.length !== 1) {
6997
- assert.fail('@readonly cannot be used as a decorator just yet, use it as a function with one argument to produce a readonly version of the provided value.');
6858
+ logError('@readonly cannot be used as a decorator just yet, use it as a function with one argument to produce a readonly version of the provided value.');
6998
6859
  }
6999
6860
  }
7000
6861
  return getReadOnlyProxy(obj);
7001
6862
  }
7002
6863
 
7003
6864
  export { LightningElement, profilerControl as __unstable__ProfilerControl, reportingControl as __unstable__ReportingControl, api$1 as api, connectRootElement, createContextProviderWithRegister, createVM, disconnectRootElement, freezeTemplate, getAssociatedVMIfPresent, getComponentConstructor, getComponentDef, getComponentHtmlPrototype, hydrateRoot, isComponentConstructor, parseFragment, parseSVGFragment, readonly, register, registerComponent, registerDecorators, registerStylesheet, registerTemplate, sanitizeAttribute, setHooks, swapComponent, swapStyle, swapTemplate, track, unwrap, wire };
7004
- /* version: 2.43.0 */
6865
+ /* version: 2.44.0 */
7005
6866
  //# sourceMappingURL=engine-core.js.map