@lwc/engine-core 2.43.0 → 2.45.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.
@@ -446,101 +446,6 @@ const defaultDefHTMLPropertyNames = [
446
446
  'tabIndex',
447
447
  'title',
448
448
  ];
449
- function offsetPropertyErrorMessage(name) {
450
- 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.`;
451
- }
452
- // Global HTML Attributes & Properties
453
- // https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes
454
- // https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement
455
- //
456
- // If you update this list, check for test files that recapitulate the same list. Searching the codebase
457
- // for e.g. "dropzone" should suffice.
458
- const globalHTMLProperties = {
459
- accessKey: {
460
- attribute: 'accesskey',
461
- },
462
- accessKeyLabel: {
463
- readOnly: true,
464
- },
465
- className: {
466
- attribute: 'class',
467
- 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.',
468
- },
469
- contentEditable: {
470
- attribute: 'contenteditable',
471
- },
472
- dataset: {
473
- readOnly: true,
474
- 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.",
475
- },
476
- dir: {
477
- attribute: 'dir',
478
- },
479
- draggable: {
480
- attribute: 'draggable',
481
- },
482
- dropzone: {
483
- attribute: 'dropzone',
484
- readOnly: true,
485
- },
486
- hidden: {
487
- attribute: 'hidden',
488
- },
489
- id: {
490
- attribute: 'id',
491
- },
492
- inputMode: {
493
- attribute: 'inputmode',
494
- },
495
- lang: {
496
- attribute: 'lang',
497
- },
498
- slot: {
499
- attribute: 'slot',
500
- error: 'Using the `slot` property is an anti-pattern.',
501
- },
502
- spellcheck: {
503
- attribute: 'spellcheck',
504
- },
505
- style: {
506
- attribute: 'style',
507
- },
508
- tabIndex: {
509
- attribute: 'tabindex',
510
- },
511
- title: {
512
- attribute: 'title',
513
- },
514
- translate: {
515
- attribute: 'translate',
516
- },
517
- // additional "global attributes" that are not present in the link above.
518
- isContentEditable: {
519
- readOnly: true,
520
- },
521
- offsetHeight: {
522
- readOnly: true,
523
- error: offsetPropertyErrorMessage('offsetHeight'),
524
- },
525
- offsetLeft: {
526
- readOnly: true,
527
- error: offsetPropertyErrorMessage('offsetLeft'),
528
- },
529
- offsetParent: {
530
- readOnly: true,
531
- },
532
- offsetTop: {
533
- readOnly: true,
534
- error: offsetPropertyErrorMessage('offsetTop'),
535
- },
536
- offsetWidth: {
537
- readOnly: true,
538
- error: offsetPropertyErrorMessage('offsetWidth'),
539
- },
540
- role: {
541
- attribute: 'role',
542
- },
543
- };
544
449
  let controlledElement = null;
545
450
  let controlledAttributeName;
546
451
  function isAttributeLocked(elm, attrName) {
@@ -725,8 +630,7 @@ function getShadowRootRestrictionsDescriptors(sr) {
725
630
  }),
726
631
  addEventListener: generateDataDescriptor({
727
632
  value(type, listener, options) {
728
- // TODO [#420]: this is triggered when the component author attempts to add a listener
729
- // programmatically into its Component's shadow root
633
+ // TODO [#1824]: Potentially relax this restriction
730
634
  if (!shared.isUndefined(options)) {
731
635
  logError('The `addEventListener` method on ShadowRoot does not support any options.', getAssociatedVMIfPresent(this));
732
636
  }
@@ -772,8 +676,7 @@ function getCustomElementRestrictionsDescriptors(elm) {
772
676
  }),
773
677
  addEventListener: generateDataDescriptor({
774
678
  value(type, listener, options) {
775
- // TODO [#420]: this is triggered when the component author attempts to add a listener
776
- // programmatically into a lighting element node
679
+ // TODO [#1824]: Potentially relax this restriction
777
680
  if (!shared.isUndefined(options)) {
778
681
  logError('The `addEventListener` method in `LightningElement` does not support any options.', getAssociatedVMIfPresent(this));
779
682
  }
@@ -801,7 +704,7 @@ function getComponentRestrictionsDescriptors() {
801
704
  function getLightningElementPrototypeRestrictionsDescriptors(proto) {
802
705
  assertNotProd(); // this method should never leak to prod
803
706
  const originalDispatchEvent = proto.dispatchEvent;
804
- const descriptors = {
707
+ return {
805
708
  dispatchEvent: generateDataDescriptor({
806
709
  value(event) {
807
710
  const vm = getAssociatedVM(this);
@@ -819,32 +722,6 @@ function getLightningElementPrototypeRestrictionsDescriptors(proto) {
819
722
  },
820
723
  }),
821
724
  };
822
- shared.forEach.call(shared.getOwnPropertyNames(globalHTMLProperties), (propName) => {
823
- if (propName in proto) {
824
- return; // no need to redefine something that we are already exposing
825
- }
826
- descriptors[propName] = generateAccessorDescriptor({
827
- get() {
828
- const { error, attribute } = globalHTMLProperties[propName];
829
- const msg = [];
830
- msg.push(`Accessing the global HTML property "${propName}" is disabled.`);
831
- if (error) {
832
- msg.push(error);
833
- }
834
- else if (attribute) {
835
- msg.push(`Instead access it via \`this.getAttribute("${attribute}")\`.`);
836
- }
837
- logError(msg.join('\n'), getAssociatedVM(this));
838
- },
839
- set() {
840
- const { readOnly } = globalHTMLProperties[propName];
841
- if (readOnly) {
842
- logError(`The global HTML property \`${propName}\` is read-only.`, getAssociatedVM(this));
843
- }
844
- },
845
- });
846
- });
847
- return descriptors;
848
725
  }
849
726
  // This routine will prevent access to certain properties on a shadow root instance to guarantee
850
727
  // that all components will work fine in IE11 and other browsers without shadow dom support.
@@ -2195,12 +2072,7 @@ function createPublicPropertyDescriptor(key) {
2195
2072
  }
2196
2073
  function createPublicAccessorDescriptor(key, descriptor) {
2197
2074
  const { get, set, enumerable, configurable } = descriptor;
2198
- if (!shared.isFunction(get)) {
2199
- if (process.env.NODE_ENV !== 'production') {
2200
- shared.assert.invariant(shared.isFunction(get), `Invalid compiler output for public accessor ${shared.toString(key)} decorated with @api`);
2201
- }
2202
- throw new Error();
2203
- }
2075
+ shared.assert.invariant(shared.isFunction(get), `Invalid public accessor ${shared.toString(key)} decorated with @api. The property is missing a getter.`);
2204
2076
  return {
2205
2077
  get() {
2206
2078
  if (process.env.NODE_ENV !== 'production') {
@@ -2322,64 +2194,64 @@ function getClassDescriptorType(descriptor) {
2322
2194
  }
2323
2195
  }
2324
2196
  function validateObservedField(Ctor, fieldName, descriptor) {
2197
+ assertNotProd(); // this method should never leak to prod
2325
2198
  if (!shared.isUndefined(descriptor)) {
2326
2199
  const type = getClassDescriptorType(descriptor);
2327
2200
  const message = `Invalid observed ${fieldName} field. Found a duplicate ${type} with the same name.`;
2328
- // [W-9927596] Ideally we always throw an error when detecting duplicate observed field.
2329
- // This branch is only here for backward compatibility reasons.
2330
- if (type === "accessor" /* DescriptorType.Accessor */) {
2331
- logError(message);
2332
- }
2333
- else {
2334
- shared.assert.fail(message);
2335
- }
2201
+ // TODO [#3408]: this should throw, not log
2202
+ logError(message);
2336
2203
  }
2337
2204
  }
2338
2205
  function validateFieldDecoratedWithTrack(Ctor, fieldName, descriptor) {
2206
+ assertNotProd(); // this method should never leak to prod
2339
2207
  if (!shared.isUndefined(descriptor)) {
2340
2208
  const type = getClassDescriptorType(descriptor);
2341
- shared.assert.fail(`Invalid @track ${fieldName} field. Found a duplicate ${type} with the same name.`);
2209
+ // TODO [#3408]: this should throw, not log
2210
+ logError(`Invalid @track ${fieldName} field. Found a duplicate ${type} with the same name.`);
2342
2211
  }
2343
2212
  }
2344
2213
  function validateFieldDecoratedWithWire(Ctor, fieldName, descriptor) {
2214
+ assertNotProd(); // this method should never leak to prod
2345
2215
  if (!shared.isUndefined(descriptor)) {
2346
2216
  const type = getClassDescriptorType(descriptor);
2347
- shared.assert.fail(`Invalid @wire ${fieldName} field. Found a duplicate ${type} with the same name.`);
2217
+ // TODO [#3408]: this should throw, not log
2218
+ logError(`Invalid @wire ${fieldName} field. Found a duplicate ${type} with the same name.`);
2348
2219
  }
2349
2220
  }
2350
2221
  function validateMethodDecoratedWithWire(Ctor, methodName, descriptor) {
2222
+ assertNotProd(); // this method should never leak to prod
2351
2223
  if (shared.isUndefined(descriptor) || !shared.isFunction(descriptor.value) || shared.isFalse(descriptor.writable)) {
2352
- shared.assert.fail(`Invalid @wire ${methodName} method.`);
2224
+ // TODO [#3441]: This line of code does not seem possible to reach.
2225
+ logError(`Invalid @wire ${methodName} field. The field should have a valid writable descriptor.`);
2353
2226
  }
2354
2227
  }
2355
2228
  function validateFieldDecoratedWithApi(Ctor, fieldName, descriptor) {
2229
+ assertNotProd(); // this method should never leak to prod
2356
2230
  if (!shared.isUndefined(descriptor)) {
2357
2231
  const type = getClassDescriptorType(descriptor);
2358
2232
  const message = `Invalid @api ${fieldName} field. Found a duplicate ${type} with the same name.`;
2359
- // [W-9927596] Ideally we always throw an error when detecting duplicate public properties.
2360
- // This branch is only here for backward compatibility reasons.
2361
- if (type === "accessor" /* DescriptorType.Accessor */) {
2362
- logError(message);
2363
- }
2364
- else {
2365
- shared.assert.fail(message);
2366
- }
2233
+ // TODO [#3408]: this should throw, not log
2234
+ logError(message);
2367
2235
  }
2368
2236
  }
2369
2237
  function validateAccessorDecoratedWithApi(Ctor, fieldName, descriptor) {
2370
- if (shared.isUndefined(descriptor)) {
2371
- shared.assert.fail(`Invalid @api get ${fieldName} accessor.`);
2372
- }
2373
- else if (shared.isFunction(descriptor.set)) {
2374
- shared.assert.isTrue(shared.isFunction(descriptor.get), `Missing getter for property ${fieldName} decorated with @api in ${Ctor}. You cannot have a setter without the corresponding getter.`);
2238
+ assertNotProd(); // this method should never leak to prod
2239
+ if (shared.isFunction(descriptor.set)) {
2240
+ if (!shared.isFunction(descriptor.get)) {
2241
+ // TODO [#3441]: This line of code does not seem possible to reach.
2242
+ logError(`Missing getter for property ${fieldName} decorated with @api in ${Ctor}. You cannot have a setter without the corresponding getter.`);
2243
+ }
2375
2244
  }
2376
2245
  else if (!shared.isFunction(descriptor.get)) {
2377
- shared.assert.fail(`Missing @api get ${fieldName} accessor.`);
2246
+ // TODO [#3441]: This line of code does not seem possible to reach.
2247
+ logError(`Missing @api get ${fieldName} accessor.`);
2378
2248
  }
2379
2249
  }
2380
2250
  function validateMethodDecoratedWithApi(Ctor, methodName, descriptor) {
2251
+ assertNotProd(); // this method should never leak to prod
2381
2252
  if (shared.isUndefined(descriptor) || !shared.isFunction(descriptor.value) || shared.isFalse(descriptor.writable)) {
2382
- shared.assert.fail(`Invalid @api ${methodName} method.`);
2253
+ // TODO [#3441]: This line of code does not seem possible to reach.
2254
+ logError(`Invalid @api ${methodName} method.`);
2383
2255
  }
2384
2256
  }
2385
2257
  /**
@@ -2402,13 +2274,14 @@ function registerDecorators(Ctor, meta) {
2402
2274
  apiFieldsConfig[fieldName] = propConfig.config;
2403
2275
  descriptor = shared.getOwnPropertyDescriptor(proto, fieldName);
2404
2276
  if (propConfig.config > 0) {
2277
+ if (shared.isUndefined(descriptor)) {
2278
+ // TODO [#3441]: This line of code does not seem possible to reach.
2279
+ throw new Error();
2280
+ }
2405
2281
  // accessor declaration
2406
2282
  if (process.env.NODE_ENV !== 'production') {
2407
2283
  validateAccessorDecoratedWithApi(Ctor, fieldName, descriptor);
2408
2284
  }
2409
- if (shared.isUndefined(descriptor)) {
2410
- throw new Error();
2411
- }
2412
2285
  descriptor = createPublicAccessorDescriptor(fieldName, descriptor);
2413
2286
  }
2414
2287
  else {
@@ -2448,7 +2321,10 @@ function registerDecorators(Ctor, meta) {
2448
2321
  descriptor = shared.getOwnPropertyDescriptor(proto, fieldOrMethodName);
2449
2322
  if (method === 1) {
2450
2323
  if (process.env.NODE_ENV !== 'production') {
2451
- shared.assert.isTrue(adapter, `@wire on method "${fieldOrMethodName}": adapter id must be truthy.`);
2324
+ if (!adapter) {
2325
+ // TODO [#3408]: this should throw, not log
2326
+ logError(`@wire on method "${fieldOrMethodName}": adapter id must be truthy.`);
2327
+ }
2452
2328
  validateMethodDecoratedWithWire(Ctor, fieldOrMethodName, descriptor);
2453
2329
  }
2454
2330
  if (shared.isUndefined(descriptor)) {
@@ -2459,7 +2335,10 @@ function registerDecorators(Ctor, meta) {
2459
2335
  }
2460
2336
  else {
2461
2337
  if (process.env.NODE_ENV !== 'production') {
2462
- shared.assert.isTrue(adapter, `@wire on field "${fieldOrMethodName}": adapter id must be truthy.`);
2338
+ if (!adapter) {
2339
+ // TODO [#3408]: this should throw, not log
2340
+ logError(`@wire on field "${fieldOrMethodName}": adapter id must be truthy.`);
2341
+ }
2463
2342
  validateFieldDecoratedWithWire(Ctor, fieldOrMethodName, descriptor);
2464
2343
  }
2465
2344
  descriptor = internalWireFieldDecorator(fieldOrMethodName);
@@ -3265,15 +3144,6 @@ function evaluateStylesheetsContent(stylesheets, stylesheetToken, vm) {
3265
3144
  // the stylesheet, while internally, we have a replacement for it.
3266
3145
  stylesheet = getStyleOrSwappedStyle(stylesheet);
3267
3146
  }
3268
- // Check that this stylesheet was generated by our compiler
3269
- if (!isStylesheetRegistered(stylesheet)) {
3270
- if (process.env.NODE_ENV !== 'production') {
3271
- logWarnOnce(`TypeError: Unexpected LWC stylesheet content found for component <${vm.tagName.toLowerCase()}>.`);
3272
- }
3273
- report("UnexpectedStylesheetContent" /* ReportingEventId.UnexpectedStylesheetContent */, {
3274
- tagName: vm.tagName.toLowerCase(),
3275
- });
3276
- }
3277
3147
  const isScopedCss = stylesheet[shared.KEY__SCOPED_CSS];
3278
3148
  if (lwcRuntimeFlags.DISABLE_LIGHT_DOM_UNSCOPED_CSS &&
3279
3149
  !isScopedCss &&
@@ -3394,18 +3264,6 @@ function createStylesheet(vm, stylesheets) {
3394
3264
  }
3395
3265
  return null;
3396
3266
  }
3397
- const signedStylesheetSet = new Set();
3398
- /**
3399
- * INTERNAL: This function can only be invoked by compiled code. The compiler
3400
- * will prevent this function from being imported by userland code.
3401
- */
3402
- function registerStylesheet(stylesheet) {
3403
- signedStylesheetSet.add(stylesheet);
3404
- return stylesheet;
3405
- }
3406
- function isStylesheetRegistered(stylesheet) {
3407
- return signedStylesheetSet.has(stylesheet);
3408
- }
3409
3267
 
3410
3268
  /*
3411
3269
  * Copyright (c) 2018, salesforce.com, inc.
@@ -6225,7 +6083,7 @@ function checkAndReportViolation(elm, prop, isSetter, setValue) {
6225
6083
  const vm = findVM(elm);
6226
6084
  if (process.env.NODE_ENV !== 'production') {
6227
6085
  logWarnOnce(`Element <${elm.tagName.toLowerCase()}> ` +
6228
- (shared.isUndefined(vm) ? '' : `owned by <${vm.tagName.toLowerCase()}> `) +
6086
+ (shared.isUndefined(vm) ? '' : `owned by <${vm.elm.tagName.toLowerCase()}> `) +
6229
6087
  `uses non-standard property "${prop}". This will be removed in a future version of LWC. ` +
6230
6088
  `See https://sfdc.co/deprecated-aria`);
6231
6089
  }
@@ -6342,8 +6200,6 @@ function hydrateNode(node, vnode, renderer) {
6342
6200
  return renderer.nextSibling(hydratedNode);
6343
6201
  }
6344
6202
  const NODE_VALUE_PROP = 'nodeValue';
6345
- const PARENT_NODE_PROP = 'parentNode';
6346
- const TAG_NAME_PROP = 'tagName';
6347
6203
  function textNodeContentsAreEqual(node, vnode, renderer) {
6348
6204
  const { getProperty } = renderer;
6349
6205
  const nodeValue = getProperty(node, NODE_VALUE_PROP);
@@ -6355,22 +6211,6 @@ function textNodeContentsAreEqual(node, vnode, renderer) {
6355
6211
  if (nodeValue === '\u200D' && vnode.text === '') {
6356
6212
  return true;
6357
6213
  }
6358
- // Special case for text nodes inside `<style>` tags – these are escaped when rendered server-size,
6359
- // but not when generated by the engine client-side.
6360
- const parentNode = getProperty(node, PARENT_NODE_PROP);
6361
- // Should never be null, but just to be safe, we check.
6362
- /* istanbul ignore else */
6363
- if (!shared.isNull(parentNode)) {
6364
- const tagName = getProperty(parentNode, TAG_NAME_PROP);
6365
- // If the tagName is STYLE, then the following condition should always be true.
6366
- // The LWC compiler blocks using `<style>`s inside of templates, so it should be impossible
6367
- // for component authors to render different `<style>` text content on the client and server.
6368
- // But just to be safe, we check.
6369
- /* istanbul ignore next */
6370
- if (tagName === 'STYLE' && shared.htmlEscape(vnode.text) === nodeValue) {
6371
- return true;
6372
- }
6373
- }
6374
6214
  return false;
6375
6215
  }
6376
6216
  function hydrateText(node, vnode, renderer) {
@@ -6996,7 +6836,7 @@ function readonly(obj) {
6996
6836
  if (process.env.NODE_ENV !== 'production') {
6997
6837
  // TODO [#1292]: Remove the readonly decorator
6998
6838
  if (arguments.length !== 1) {
6999
- shared.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.');
6839
+ 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.');
7000
6840
  }
7001
6841
  }
7002
6842
  return getReadOnlyProxy(obj);
@@ -7031,7 +6871,6 @@ exports.readonly = readonly;
7031
6871
  exports.register = register;
7032
6872
  exports.registerComponent = registerComponent;
7033
6873
  exports.registerDecorators = registerDecorators;
7034
- exports.registerStylesheet = registerStylesheet;
7035
6874
  exports.registerTemplate = registerTemplate;
7036
6875
  exports.sanitizeAttribute = sanitizeAttribute;
7037
6876
  exports.setHooks = setHooks;
@@ -7041,5 +6880,5 @@ exports.swapTemplate = swapTemplate;
7041
6880
  exports.track = track;
7042
6881
  exports.unwrap = unwrap;
7043
6882
  exports.wire = wire;
7044
- /* version: 2.43.0 */
6883
+ /* version: 2.45.0 */
7045
6884
  //# sourceMappingURL=engine-core.cjs.js.map