@lwc/engine-core 2.44.0 → 2.45.1

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.
@@ -530,8 +530,9 @@ function patchElementWithRestrictions(elm, options) {
530
530
  get() {
531
531
  return originalOuterHTMLDescriptor.get.call(this);
532
532
  },
533
- set(_value) {
534
- throw new TypeError(`Invalid attempt to set outerHTML on Element.`);
533
+ set(value) {
534
+ logError(`Invalid attempt to set outerHTML on Element.`);
535
+ return originalOuterHTMLDescriptor.set.call(this, value);
535
536
  },
536
537
  }),
537
538
  };
@@ -616,16 +617,18 @@ function getShadowRootRestrictionsDescriptors(sr) {
616
617
  get() {
617
618
  return originalInnerHTMLDescriptor.get.call(this);
618
619
  },
619
- set(_value) {
620
- throw new TypeError(`Invalid attempt to set innerHTML on ShadowRoot.`);
620
+ set(value) {
621
+ logError(`Invalid attempt to set innerHTML on ShadowRoot.`);
622
+ return originalInnerHTMLDescriptor.set.call(this, value);
621
623
  },
622
624
  }),
623
625
  textContent: generateAccessorDescriptor({
624
626
  get() {
625
627
  return originalTextContentDescriptor.get.call(this);
626
628
  },
627
- set(_value) {
628
- throw new TypeError(`Invalid attempt to set textContent on ShadowRoot.`);
629
+ set(value) {
630
+ logError(`Invalid attempt to set textContent on ShadowRoot.`);
631
+ return originalTextContentDescriptor.set.call(this, value);
629
632
  },
630
633
  }),
631
634
  addEventListener: generateDataDescriptor({
@@ -654,24 +657,27 @@ function getCustomElementRestrictionsDescriptors(elm) {
654
657
  get() {
655
658
  return originalInnerHTMLDescriptor.get.call(this);
656
659
  },
657
- set(_value) {
658
- throw new TypeError(`Invalid attempt to set innerHTML on HTMLElement.`);
660
+ set(value) {
661
+ logError(`Invalid attempt to set innerHTML on HTMLElement.`);
662
+ return originalInnerHTMLDescriptor.set.call(this, value);
659
663
  },
660
664
  }),
661
665
  outerHTML: generateAccessorDescriptor({
662
666
  get() {
663
667
  return originalOuterHTMLDescriptor.get.call(this);
664
668
  },
665
- set(_value) {
666
- throw new TypeError(`Invalid attempt to set outerHTML on HTMLElement.`);
669
+ set(value) {
670
+ logError(`Invalid attempt to set outerHTML on HTMLElement.`);
671
+ return originalOuterHTMLDescriptor.set.call(this, value);
667
672
  },
668
673
  }),
669
674
  textContent: generateAccessorDescriptor({
670
675
  get() {
671
676
  return originalTextContentDescriptor.get.call(this);
672
677
  },
673
- set(_value) {
674
- throw new TypeError(`Invalid attempt to set textContent on HTMLElement.`);
678
+ set(value) {
679
+ logError(`Invalid attempt to set textContent on HTMLElement.`);
680
+ return originalTextContentDescriptor.set.call(this, value);
675
681
  },
676
682
  }),
677
683
  addEventListener: generateDataDescriptor({
@@ -687,20 +693,6 @@ function getCustomElementRestrictionsDescriptors(elm) {
687
693
  }),
688
694
  };
689
695
  }
690
- function getComponentRestrictionsDescriptors() {
691
- assertNotProd(); // this method should never leak to prod
692
- return {
693
- tagName: generateAccessorDescriptor({
694
- get() {
695
- throw new Error(`Usage of property \`tagName\` is disallowed because the component itself does` +
696
- ` not know which tagName will be used to create the element, therefore writing` +
697
- ` code that check for that value is error prone.`);
698
- },
699
- configurable: true,
700
- enumerable: false, // no enumerable properties on component
701
- }),
702
- };
703
- }
704
696
  function getLightningElementPrototypeRestrictionsDescriptors(proto) {
705
697
  assertNotProd(); // this method should never leak to prod
706
698
  const originalDispatchEvent = proto.dispatchEvent;
@@ -733,9 +725,6 @@ function patchCustomElementWithRestrictions(elm) {
733
725
  const elmProto = shared.getPrototypeOf(elm);
734
726
  shared.setPrototypeOf(elm, shared.create(elmProto, restrictionsDescriptors));
735
727
  }
736
- function patchComponentWithRestrictions(cmp) {
737
- shared.defineProperties(cmp, getComponentRestrictionsDescriptors());
738
- }
739
728
  function patchLightningElementPrototypeWithRestrictions(proto) {
740
729
  shared.defineProperties(proto, getLightningElementPrototypeRestrictionsDescriptors(proto));
741
730
  }
@@ -1346,16 +1335,10 @@ function markLockerLiveObject(obj) {
1346
1335
  function createBridgeToElementDescriptor(propName, descriptor) {
1347
1336
  const { get, set, enumerable, configurable } = descriptor;
1348
1337
  if (!shared.isFunction(get)) {
1349
- if (process.env.NODE_ENV !== 'production') {
1350
- shared.assert.fail(`Detected invalid public property descriptor for HTMLElement.prototype.${propName} definition. Missing the standard getter.`);
1351
- }
1352
- throw new TypeError();
1338
+ throw new TypeError(`Detected invalid public property descriptor for HTMLElement.prototype.${propName} definition. Missing the standard getter.`);
1353
1339
  }
1354
1340
  if (!shared.isFunction(set)) {
1355
- if (process.env.NODE_ENV !== 'production') {
1356
- shared.assert.fail(`Detected invalid public property descriptor for HTMLElement.prototype.${propName} definition. Missing the standard setter.`);
1357
- }
1358
- throw new TypeError();
1341
+ throw new TypeError(`Detected invalid public property descriptor for HTMLElement.prototype.${propName} definition. Missing the standard setter.`);
1359
1342
  }
1360
1343
  return {
1361
1344
  enumerable,
@@ -1375,10 +1358,18 @@ function createBridgeToElementDescriptor(propName, descriptor) {
1375
1358
  const vm = getAssociatedVM(this);
1376
1359
  if (process.env.NODE_ENV !== 'production') {
1377
1360
  const vmBeingRendered = getVMBeingRendered();
1378
- shared.assert.invariant(!isInvokingRender, `${vmBeingRendered}.render() method has side effects on the state of ${vm}.${propName}`);
1379
- shared.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}`);
1380
- shared.assert.isFalse(isBeingConstructed(vm), `Failed to construct '${getComponentTag(vm)}': The result must not have attributes.`);
1381
- shared.assert.invariant(!shared.isObject(newValue) || shared.isNull(newValue), `Invalid value "${newValue}" for "${propName}" of ${vm}. Value cannot be an object, must be a primitive value.`);
1361
+ if (isInvokingRender) {
1362
+ logError(`${vmBeingRendered}.render() method has side effects on the state of ${vm}.${propName}`);
1363
+ }
1364
+ if (isUpdatingTemplate) {
1365
+ logError(`When updating the template of ${vmBeingRendered}, one of the accessors used by the template has side effects on the state of ${vm}.${propName}`);
1366
+ }
1367
+ if (isBeingConstructed(vm)) {
1368
+ logError(`Failed to construct '${getComponentTag(vm)}': The result must not have attributes.`);
1369
+ }
1370
+ if (shared.isObject(newValue) && !shared.isNull(newValue)) {
1371
+ logError(`Invalid value "${newValue}" for "${propName}" of ${vm}. Value cannot be an object, must be a primitive value.`);
1372
+ }
1382
1373
  }
1383
1374
  updateComponentValue(vm, propName, newValue);
1384
1375
  return set.call(vm.elm, newValue);
@@ -1431,7 +1422,6 @@ const LightningElement = function () {
1431
1422
  // Adding extra guard rails in DEV mode.
1432
1423
  if (process.env.NODE_ENV !== 'production') {
1433
1424
  patchCustomElementWithRestrictions(elm);
1434
- patchComponentWithRestrictions(component);
1435
1425
  }
1436
1426
  return this;
1437
1427
  };
@@ -1467,9 +1457,15 @@ LightningElement.prototype = {
1467
1457
  const { elm, renderer: { addEventListener }, } = vm;
1468
1458
  if (process.env.NODE_ENV !== 'production') {
1469
1459
  const vmBeingRendered = getVMBeingRendered();
1470
- shared.assert.invariant(!isInvokingRender, `${vmBeingRendered}.render() method has side effects on the state of ${vm} by adding an event listener for "${type}".`);
1471
- shared.assert.invariant(!isUpdatingTemplate, `Updating the template of ${vmBeingRendered} has side effects on the state of ${vm} by adding an event listener for "${type}".`);
1472
- shared.assert.invariant(shared.isFunction(listener), `Invalid second argument for this.addEventListener() in ${vm} for event "${type}". Expected an EventListener but received ${listener}.`);
1460
+ if (isInvokingRender) {
1461
+ logError(`${vmBeingRendered}.render() method has side effects on the state of ${vm} by adding an event listener for "${type}".`);
1462
+ }
1463
+ if (isUpdatingTemplate) {
1464
+ logError(`Updating the template of ${vmBeingRendered} has side effects on the state of ${vm} by adding an event listener for "${type}".`);
1465
+ }
1466
+ if (!shared.isFunction(listener)) {
1467
+ logError(`Invalid second argument for this.addEventListener() in ${vm} for event "${type}". Expected an EventListener but received ${listener}.`);
1468
+ }
1473
1469
  }
1474
1470
  const wrappedListener = getWrappedComponentsListener(vm, listener);
1475
1471
  addEventListener(elm, type, wrappedListener, options);
@@ -1519,7 +1515,9 @@ LightningElement.prototype = {
1519
1515
  const vm = getAssociatedVM(this);
1520
1516
  const { elm, renderer: { setAttribute }, } = vm;
1521
1517
  if (process.env.NODE_ENV !== 'production') {
1522
- shared.assert.isFalse(isBeingConstructed(vm), `Failed to construct '${getComponentTag(vm)}': The result must not have attributes.`);
1518
+ if (isBeingConstructed(vm)) {
1519
+ logError(`Failed to construct '${getComponentTag(vm)}': The result must not have attributes.`);
1520
+ }
1523
1521
  }
1524
1522
  unlockAttribute(elm, name);
1525
1523
  setAttribute(elm, name, value);
@@ -1529,7 +1527,9 @@ LightningElement.prototype = {
1529
1527
  const vm = getAssociatedVM(this);
1530
1528
  const { elm, renderer: { setAttribute }, } = vm;
1531
1529
  if (process.env.NODE_ENV !== 'production') {
1532
- shared.assert.isFalse(isBeingConstructed(vm), `Failed to construct '${getComponentTag(vm)}': The result must not have attributes.`);
1530
+ if (isBeingConstructed(vm)) {
1531
+ logError(`Failed to construct '${getComponentTag(vm)}': The result must not have attributes.`);
1532
+ }
1533
1533
  }
1534
1534
  unlockAttribute(elm, name);
1535
1535
  setAttribute(elm, name, value, namespace);
@@ -1552,9 +1552,9 @@ LightningElement.prototype = {
1552
1552
  const vm = getAssociatedVM(this);
1553
1553
  const { elm, renderer: { getClassList }, } = vm;
1554
1554
  if (process.env.NODE_ENV !== 'production') {
1555
- // TODO [#1290]: this still fails in dev but works in production, eventually, we should
1556
- // just throw in all modes
1557
- shared.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.`);
1555
+ if (isBeingConstructed(vm)) {
1556
+ logError(`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.`);
1557
+ }
1558
1558
  }
1559
1559
  return getClassList(elm);
1560
1560
  },
@@ -2060,8 +2060,12 @@ function createPublicPropertyDescriptor(key) {
2060
2060
  const vm = getAssociatedVM(this);
2061
2061
  if (process.env.NODE_ENV !== 'production') {
2062
2062
  const vmBeingRendered = getVMBeingRendered();
2063
- shared.assert.invariant(!isInvokingRender, `${vmBeingRendered}.render() method has side effects on the state of ${vm}.${shared.toString(key)}`);
2064
- shared.assert.invariant(!isUpdatingTemplate, `Updating the template of ${vmBeingRendered} has side effects on the state of ${vm}.${shared.toString(key)}`);
2063
+ if (isInvokingRender) {
2064
+ logError(`render() method has side effects on the state of property "${shared.toString(key)}"`, shared.isNull(vmBeingRendered) ? vm : vmBeingRendered);
2065
+ }
2066
+ if (isUpdatingTemplate) {
2067
+ logError(`Updating the template has side effects on the state of property "${shared.toString(key)}"`, shared.isNull(vmBeingRendered) ? vm : vmBeingRendered);
2068
+ }
2065
2069
  }
2066
2070
  vm.cmpProps[key] = newValue;
2067
2071
  componentValueMutated(vm, key);
@@ -2085,14 +2089,18 @@ function createPublicAccessorDescriptor(key, descriptor) {
2085
2089
  const vm = getAssociatedVM(this);
2086
2090
  if (process.env.NODE_ENV !== 'production') {
2087
2091
  const vmBeingRendered = getVMBeingRendered();
2088
- shared.assert.invariant(!isInvokingRender, `${vmBeingRendered}.render() method has side effects on the state of ${vm}.${shared.toString(key)}`);
2089
- shared.assert.invariant(!isUpdatingTemplate, `Updating the template of ${vmBeingRendered} has side effects on the state of ${vm}.${shared.toString(key)}`);
2092
+ if (isInvokingRender) {
2093
+ logError(`render() method has side effects on the state of property "${shared.toString(key)}"`, shared.isNull(vmBeingRendered) ? vm : vmBeingRendered);
2094
+ }
2095
+ if (isUpdatingTemplate) {
2096
+ logError(`Updating the template has side effects on the state of property "${shared.toString(key)}"`, shared.isNull(vmBeingRendered) ? vm : vmBeingRendered);
2097
+ }
2090
2098
  }
2091
2099
  if (set) {
2092
2100
  set.call(this, newValue);
2093
2101
  }
2094
2102
  else if (process.env.NODE_ENV !== 'production') {
2095
- shared.assert.fail(`Invalid attempt to set a new value for property ${shared.toString(key)} of ${vm} that does not has a setter decorated with @api.`);
2103
+ logError(`Invalid attempt to set a new value for property "${shared.toString(key)}" that does not has a setter decorated with @api.`, vm);
2096
2104
  }
2097
2105
  },
2098
2106
  enumerable,
@@ -2126,8 +2134,12 @@ function internalTrackDecorator(key) {
2126
2134
  const vm = getAssociatedVM(this);
2127
2135
  if (process.env.NODE_ENV !== 'production') {
2128
2136
  const vmBeingRendered = getVMBeingRendered();
2129
- shared.assert.invariant(!isInvokingRender, `${vmBeingRendered}.render() method has side effects on the state of ${vm}.${shared.toString(key)}`);
2130
- shared.assert.invariant(!isUpdatingTemplate, `Updating the template of ${vmBeingRendered} has side effects on the state of ${vm}.${shared.toString(key)}`);
2137
+ if (isInvokingRender) {
2138
+ logError(`${vmBeingRendered}.render() method has side effects on the state of ${vm}.${shared.toString(key)}`);
2139
+ }
2140
+ if (isUpdatingTemplate) {
2141
+ logError(`Updating the template of ${vmBeingRendered} has side effects on the state of ${vm}.${shared.toString(key)}`);
2142
+ }
2131
2143
  }
2132
2144
  const reactiveOrAnyValue = getReactiveProxy(newValue);
2133
2145
  updateComponentValue(vm, key, reactiveOrAnyValue);
@@ -2904,13 +2916,20 @@ function createComponentDef(Ctor) {
2904
2916
  const ctorName = Ctor.name;
2905
2917
  // Removing the following assert until https://bugs.webkit.org/show_bug.cgi?id=190140 is fixed.
2906
2918
  // assert.isTrue(ctorName && isString(ctorName), `${toString(Ctor)} should have a "name" property with string value, but found ${ctorName}.`);
2907
- shared.assert.isTrue(Ctor.constructor, `Missing ${ctorName}.constructor, ${ctorName} should have a "constructor" property.`);
2908
- if (!shared.isUndefined(ctorShadowSupportMode)) {
2909
- shared.assert.invariant(ctorShadowSupportMode === "any" /* ShadowSupportMode.Any */ ||
2910
- ctorShadowSupportMode === "reset" /* ShadowSupportMode.Default */, `Invalid value for static property shadowSupportMode: '${ctorShadowSupportMode}'`);
2919
+ if (!Ctor.constructor) {
2920
+ // This error seems impossible to hit, due to an earlier check in `isComponentConstructor()`.
2921
+ // But we keep it here just in case.
2922
+ logError(`Missing ${ctorName}.constructor, ${ctorName} should have a "constructor" property.`);
2911
2923
  }
2912
- if (!shared.isUndefined(ctorRenderMode)) {
2913
- shared.assert.invariant(ctorRenderMode === 'light' || ctorRenderMode === 'shadow', `Invalid value for static property renderMode: '${ctorRenderMode}'. renderMode must be either 'light' or 'shadow'.`);
2924
+ if (!shared.isUndefined(ctorShadowSupportMode) &&
2925
+ ctorShadowSupportMode !== "any" /* ShadowSupportMode.Any */ &&
2926
+ ctorShadowSupportMode !== "reset" /* ShadowSupportMode.Default */) {
2927
+ logError(`Invalid value for static property shadowSupportMode: '${ctorShadowSupportMode}'`);
2928
+ }
2929
+ if (!shared.isUndefined(ctorRenderMode) &&
2930
+ ctorRenderMode !== 'light' &&
2931
+ ctorRenderMode !== 'shadow') {
2932
+ logError(`Invalid value for static property renderMode: '${ctorRenderMode}'. renderMode must be either 'light' or 'shadow'.`);
2914
2933
  }
2915
2934
  }
2916
2935
  const decoratorsMeta = getDecoratorsMeta(Ctor);
@@ -3144,15 +3163,6 @@ function evaluateStylesheetsContent(stylesheets, stylesheetToken, vm) {
3144
3163
  // the stylesheet, while internally, we have a replacement for it.
3145
3164
  stylesheet = getStyleOrSwappedStyle(stylesheet);
3146
3165
  }
3147
- // Check that this stylesheet was generated by our compiler
3148
- if (!isStylesheetRegistered(stylesheet)) {
3149
- if (process.env.NODE_ENV !== 'production') {
3150
- logWarnOnce(`TypeError: Unexpected LWC stylesheet content found for component <${vm.tagName.toLowerCase()}>.`);
3151
- }
3152
- report("UnexpectedStylesheetContent" /* ReportingEventId.UnexpectedStylesheetContent */, {
3153
- tagName: vm.tagName.toLowerCase(),
3154
- });
3155
- }
3156
3166
  const isScopedCss = stylesheet[shared.KEY__SCOPED_CSS];
3157
3167
  if (lwcRuntimeFlags.DISABLE_LIGHT_DOM_UNSCOPED_CSS &&
3158
3168
  !isScopedCss &&
@@ -3273,18 +3283,6 @@ function createStylesheet(vm, stylesheets) {
3273
3283
  }
3274
3284
  return null;
3275
3285
  }
3276
- const signedStylesheetSet = new Set();
3277
- /**
3278
- * INTERNAL: This function can only be invoked by compiled code. The compiler
3279
- * will prevent this function from being imported by userland code.
3280
- */
3281
- function registerStylesheet(stylesheet) {
3282
- signedStylesheetSet.add(stylesheet);
3283
- return stylesheet;
3284
- }
3285
- function isStylesheetRegistered(stylesheet) {
3286
- return signedStylesheetSet.has(stylesheet);
3287
- }
3288
3286
 
3289
3287
  /*
3290
3288
  * Copyright (c) 2018, salesforce.com, inc.
@@ -4713,7 +4711,7 @@ function k(compilerKey, obj) {
4713
4711
  return compilerKey + ':' + obj;
4714
4712
  case 'object':
4715
4713
  if (process.env.NODE_ENV !== 'production') {
4716
- shared.assert.fail(`Invalid key value "${obj}" in ${getVMBeingRendered()}. Key must be a string or number.`);
4714
+ logError(`Invalid key value "${obj}" in ${getVMBeingRendered()}. Key must be a string or number.`);
4717
4715
  }
4718
4716
  }
4719
4717
  }
@@ -5003,13 +5001,19 @@ function validateSlots(vm) {
5003
5001
  }
5004
5002
  }
5005
5003
  function validateLightDomTemplate(template, vm) {
5006
- if (template === defaultEmptyTemplate)
5004
+ assertNotProd(); // should never leak to prod mode
5005
+ if (template === defaultEmptyTemplate) {
5007
5006
  return;
5007
+ }
5008
5008
  if (vm.renderMode === 0 /* RenderMode.Light */) {
5009
- shared.assert.isTrue(template.renderMode === 'light', `Light DOM components can't render shadow DOM templates. Add an 'lwc:render-mode="light"' directive to the root template tag of ${getComponentTag(vm)}.`);
5009
+ if (template.renderMode !== 'light') {
5010
+ logError(`Light DOM components can't render shadow DOM templates. Add an 'lwc:render-mode="light"' directive to the root template tag of ${getComponentTag(vm)}.`);
5011
+ }
5010
5012
  }
5011
5013
  else {
5012
- shared.assert.isTrue(shared.isUndefined(template.renderMode), `Shadow DOM components template can't render light DOM templates. Either remove the 'lwc:render-mode' directive from ${getComponentTag(vm)} or set it to 'lwc:render-mode="shadow"`);
5014
+ if (!shared.isUndefined(template.renderMode)) {
5015
+ logError(`Shadow DOM components template can't render light DOM templates. Either remove the 'lwc:render-mode' directive from ${getComponentTag(vm)} or set it to 'lwc:render-mode="shadow"`);
5016
+ }
5013
5017
  }
5014
5018
  }
5015
5019
  function buildParseFragmentFn(createFragmentFn) {
@@ -5142,7 +5146,9 @@ function evaluateTemplate(vm, html) {
5142
5146
  logOperationEnd(1 /* OperationId.Render */, vm);
5143
5147
  });
5144
5148
  if (process.env.NODE_ENV !== 'production') {
5145
- shared.assert.invariant(shared.isArray(vnodes), `Compiler should produce html functions that always return an array.`);
5149
+ if (!shared.isArray(vnodes)) {
5150
+ logError(`Compiler should produce html functions that always return an array.`);
5151
+ }
5146
5152
  }
5147
5153
  return vnodes;
5148
5154
  }
@@ -6104,7 +6110,7 @@ function checkAndReportViolation(elm, prop, isSetter, setValue) {
6104
6110
  const vm = findVM(elm);
6105
6111
  if (process.env.NODE_ENV !== 'production') {
6106
6112
  logWarnOnce(`Element <${elm.tagName.toLowerCase()}> ` +
6107
- (shared.isUndefined(vm) ? '' : `owned by <${vm.tagName.toLowerCase()}> `) +
6113
+ (shared.isUndefined(vm) ? '' : `owned by <${vm.elm.tagName.toLowerCase()}> `) +
6108
6114
  `uses non-standard property "${prop}". This will be removed in a future version of LWC. ` +
6109
6115
  `See https://sfdc.co/deprecated-aria`);
6110
6116
  }
@@ -6892,7 +6898,6 @@ exports.readonly = readonly;
6892
6898
  exports.register = register;
6893
6899
  exports.registerComponent = registerComponent;
6894
6900
  exports.registerDecorators = registerDecorators;
6895
- exports.registerStylesheet = registerStylesheet;
6896
6901
  exports.registerTemplate = registerTemplate;
6897
6902
  exports.sanitizeAttribute = sanitizeAttribute;
6898
6903
  exports.setHooks = setHooks;
@@ -6902,5 +6907,5 @@ exports.swapTemplate = swapTemplate;
6902
6907
  exports.track = track;
6903
6908
  exports.unwrap = unwrap;
6904
6909
  exports.wire = wire;
6905
- /* version: 2.44.0 */
6910
+ /* version: 2.45.1 */
6906
6911
  //# sourceMappingURL=engine-core.cjs.js.map