lwc 2.35.2 → 2.37.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.
Files changed (35) hide show
  1. package/dist/engine-dom/esm/es2017/engine-dom.js +260 -654
  2. package/dist/engine-dom/iife/es2017/engine-dom.js +260 -654
  3. package/dist/engine-dom/iife/es2017/engine-dom.min.js +1 -1
  4. package/dist/engine-dom/iife/es2017/engine-dom_debug.js +286 -608
  5. package/dist/engine-dom/iife/es5/engine-dom.js +406 -852
  6. package/dist/engine-dom/iife/es5/engine-dom.min.js +1 -1
  7. package/dist/engine-dom/iife/es5/engine-dom_debug.js +450 -778
  8. package/dist/engine-dom/umd/es2017/engine-dom.js +260 -654
  9. package/dist/engine-dom/umd/es2017/engine-dom.min.js +1 -1
  10. package/dist/engine-dom/umd/es2017/engine-dom_debug.js +286 -608
  11. package/dist/engine-dom/umd/es5/engine-dom.js +406 -852
  12. package/dist/engine-dom/umd/es5/engine-dom.min.js +1 -1
  13. package/dist/engine-dom/umd/es5/engine-dom_debug.js +450 -778
  14. package/dist/engine-server/commonjs/es2017/engine-server.js +153 -92
  15. package/dist/engine-server/commonjs/es2017/engine-server.min.js +1 -1
  16. package/dist/engine-server/esm/es2017/engine-server.js +153 -93
  17. package/dist/synthetic-shadow/esm/es2017/synthetic-shadow.js +3 -3
  18. package/dist/synthetic-shadow/iife/es2017/synthetic-shadow.js +3 -3
  19. package/dist/synthetic-shadow/iife/es2017/synthetic-shadow_debug.js +3 -3
  20. package/dist/synthetic-shadow/iife/es5/synthetic-shadow.js +3 -3
  21. package/dist/synthetic-shadow/iife/es5/synthetic-shadow_debug.js +3 -3
  22. package/dist/synthetic-shadow/umd/es2017/synthetic-shadow.js +3 -3
  23. package/dist/synthetic-shadow/umd/es2017/synthetic-shadow_debug.js +3 -3
  24. package/dist/synthetic-shadow/umd/es5/synthetic-shadow.js +3 -3
  25. package/dist/synthetic-shadow/umd/es5/synthetic-shadow_debug.js +3 -3
  26. package/dist/wire-service/esm/es2017/wire-service.js +2 -2
  27. package/dist/wire-service/iife/es2017/wire-service.js +2 -2
  28. package/dist/wire-service/iife/es2017/wire-service_debug.js +2 -2
  29. package/dist/wire-service/iife/es5/wire-service.js +2 -2
  30. package/dist/wire-service/iife/es5/wire-service_debug.js +2 -2
  31. package/dist/wire-service/umd/es2017/wire-service.js +2 -2
  32. package/dist/wire-service/umd/es2017/wire-service_debug.js +2 -2
  33. package/dist/wire-service/umd/es5/wire-service.js +2 -2
  34. package/dist/wire-service/umd/es5/wire-service_debug.js +2 -2
  35. package/package.json +7 -7
@@ -329,9 +329,9 @@ function htmlAttributeToProperty(attrName) {
329
329
  * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
330
330
  */
331
331
  // Increment whenever the LWC template compiler changes
332
- const LWC_VERSION = "2.35.2";
332
+ const LWC_VERSION = "2.37.0";
333
333
  const LWC_VERSION_COMMENT_REGEX = /\/\*LWC compiler v([\d.]+)\*\/\s*}/;
334
- /** version: 2.35.2 */
334
+ /** version: 2.37.0 */
335
335
 
336
336
  /**
337
337
  * Copyright (C) 2018 salesforce.com, inc.
@@ -351,10 +351,8 @@ const features = {
351
351
  ENABLE_WIRE_SYNC_EMIT: null,
352
352
  ENABLE_LIGHT_GET_ROOT_NODE_PATCH: null,
353
353
  DISABLE_LIGHT_DOM_UNSCOPED_CSS: null,
354
- ENABLE_SCOPED_CUSTOM_ELEMENT_REGISTRY: null,
355
354
  ENABLE_FROZEN_TEMPLATE: null,
356
355
  DISABLE_ARIA_REFLECTION_POLYFILL: null,
357
- ENABLE_PROGRAMMATIC_STYLESHEETS: null,
358
356
  };
359
357
  if (!_globalThis.lwcRuntimeFlags) {
360
358
  Object.defineProperty(_globalThis, 'lwcRuntimeFlags', { value: create(null) });
@@ -410,7 +408,7 @@ function setFeatureFlagForTest(name, value) {
410
408
  setFeatureFlag(name, value);
411
409
  }
412
410
  }
413
- /** version: 2.35.2 */
411
+ /** version: 2.37.0 */
414
412
 
415
413
  /**
416
414
  * Copyright (C) 2018 salesforce.com, inc.
@@ -474,7 +472,7 @@ function applyAriaReflection(prototype = Element.prototype) {
474
472
  }
475
473
  }
476
474
  }
477
- /** version: 2.35.2 */
475
+ /** version: 2.37.0 */
478
476
 
479
477
  /*
480
478
  * Copyright (c) 2018, salesforce.com, inc.
@@ -540,7 +538,6 @@ if (process.env.NODE_ENV === 'test-karma-lwc') {
540
538
  * SPDX-License-Identifier: MIT
541
539
  * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
542
540
  */
543
- /** Callbacks to invoke when reporting is enabled **/
544
541
  const onReportingEnabledCallbacks = [];
545
542
  /** The currently assigned reporting dispatcher. */
546
543
  let currentDispatcher$1 = noop;
@@ -598,11 +595,11 @@ function onReportingEnabled(callback) {
598
595
  /**
599
596
  * Report to the current dispatcher, if there is one.
600
597
  * @param reportingEventId
601
- * @param vm
598
+ * @param payload - data to report
602
599
  */
603
- function report(reportingEventId, vm) {
600
+ function report(reportingEventId, payload) {
604
601
  if (enabled$1) {
605
- currentDispatcher$1(reportingEventId, vm.tagName, vm.idx);
602
+ currentDispatcher$1(reportingEventId, payload);
606
603
  }
607
604
  }
608
605
 
@@ -877,7 +874,7 @@ function parseStyleText(cssText) {
877
874
  // Make a shallow copy of an object but omit the given key
878
875
  function cloneAndOmitKey(object, keyToOmit) {
879
876
  const result = {};
880
- for (const key of Object.keys(object)) {
877
+ for (const key of keys(object)) {
881
878
  if (key !== keyToOmit) {
882
879
  result[key] = object[key];
883
880
  }
@@ -887,7 +884,7 @@ function cloneAndOmitKey(object, keyToOmit) {
887
884
  function flattenStylesheets(stylesheets) {
888
885
  const list = [];
889
886
  for (const stylesheet of stylesheets) {
890
- if (!Array.isArray(stylesheet)) {
887
+ if (!isArray$1(stylesheet)) {
891
888
  list.push(stylesheet);
892
889
  }
893
890
  else {
@@ -3164,6 +3161,10 @@ function checkVersionMismatch(func, type) {
3164
3161
  // stylesheets and templates do not have user-meaningful names, but components do
3165
3162
  const friendlyName = type === 'component' ? `${type} ${func.name}` : type;
3166
3163
  logError(`LWC WARNING: current engine is v${LWC_VERSION}, but ${friendlyName} was compiled with v${version}.\nPlease update your compiled code or LWC engine so that the versions match.\nNo further warnings will appear.`);
3164
+ report(1 /* ReportingEventId.CompilerRuntimeVersionMismatch */, {
3165
+ compilerVersion: version,
3166
+ runtimeVersion: LWC_VERSION,
3167
+ });
3167
3168
  }
3168
3169
  }
3169
3170
  }
@@ -4899,7 +4900,12 @@ function allocateInSlot(vm, children, owner) {
4899
4900
  } else if (isVScopedSlotFragment(vnode)) {
4900
4901
  slotName = vnode.slotName;
4901
4902
  }
4902
- const vnodes = cmpSlotsMapping[slotName] = cmpSlotsMapping[slotName] || [];
4903
+ // Can't use toString here because Symbol(1).toString() is 'Symbol(1)'
4904
+ // but elm.setAttribute('slot', Symbol(1)) is an error.
4905
+ // the following line also throws same error for symbols
4906
+ // Similar for Object.create(null)
4907
+ const normalizedSlotName = '' + slotName;
4908
+ const vnodes = cmpSlotsMapping[normalizedSlotName] = cmpSlotsMapping[normalizedSlotName] || [];
4903
4909
  ArrayPush$1.call(vnodes, vnode);
4904
4910
  }
4905
4911
  vm.cmpSlots = {
@@ -5965,6 +5971,8 @@ function registerComponent(
5965
5971
  Ctor, { tmpl }) {
5966
5972
  if (isFunction$1(Ctor)) {
5967
5973
  if (process.env.NODE_ENV !== 'production') {
5974
+ // There is no point in running this in production, because the version mismatch check relies
5975
+ // on code comments which are stripped out in production by minifiers
5968
5976
  checkVersionMismatch(Ctor, 'component');
5969
5977
  }
5970
5978
  signedTemplateMap.set(Ctor, tmpl);
@@ -6229,20 +6237,37 @@ function validateComponentStylesheets(vm, stylesheets) {
6229
6237
  }
6230
6238
  // Validate and flatten any stylesheets defined as `static stylesheets`
6231
6239
  function computeStylesheets(vm, ctor) {
6232
- if (lwcRuntimeFlags.ENABLE_PROGRAMMATIC_STYLESHEETS) {
6233
- const {
6240
+ warnOnStylesheetsMutation(ctor);
6241
+ const {
6242
+ stylesheets
6243
+ } = ctor;
6244
+ if (!isUndefined$1(stylesheets)) {
6245
+ const valid = validateComponentStylesheets(vm, stylesheets);
6246
+ if (valid) {
6247
+ return flattenStylesheets(stylesheets);
6248
+ } else if (process.env.NODE_ENV !== 'production') {
6249
+ logError(`static stylesheets must be an array of CSS stylesheets. Found invalid stylesheets on <${vm.tagName}>`, vm);
6250
+ }
6251
+ }
6252
+ return null;
6253
+ }
6254
+ function warnOnStylesheetsMutation(ctor) {
6255
+ if (process.env.NODE_ENV !== 'production') {
6256
+ let {
6234
6257
  stylesheets
6235
6258
  } = ctor;
6236
- if (!isUndefined$1(stylesheets)) {
6237
- const valid = validateComponentStylesheets(vm, stylesheets);
6238
- if (valid) {
6239
- return flattenStylesheets(stylesheets);
6240
- } else if (process.env.NODE_ENV !== 'production') {
6241
- logError(`static stylesheets must be an array of CSS stylesheets. Found invalid stylesheets on <${vm.tagName}>`, vm);
6259
+ defineProperty(ctor, 'stylesheets', {
6260
+ enumerable: true,
6261
+ configurable: true,
6262
+ get() {
6263
+ return stylesheets;
6264
+ },
6265
+ set(newValue) {
6266
+ logWarnOnce(`Dynamically setting the "stylesheets" static property on ${ctor.name} ` + 'will not affect the stylesheets injected.');
6267
+ stylesheets = newValue;
6242
6268
  }
6243
- }
6269
+ });
6244
6270
  }
6245
- return null;
6246
6271
  }
6247
6272
  function computeShadowMode(vm, renderer) {
6248
6273
  const {
@@ -6615,7 +6640,7 @@ function forceRehydration(vm) {
6615
6640
  // The goal of this code is to detect invalid cross-root ARIA references in synthetic shadow DOM.
6616
6641
  // These invalid references should be fixed before the offending components can be migrated to native shadow DOM.
6617
6642
  // When invalid usage is detected, we warn in dev mode and call the reporting API if enabled.
6618
- // See: https://lwc.dev/guide/accessibility#link-ids-and-aria-attributes-from-different-templates
6643
+ // See: https://sfdc.co/synthetic-aria
6619
6644
  //
6620
6645
  // Use the unpatched native getElementById/querySelectorAll rather than the synthetic one
6621
6646
  const getElementById = _globalThis[KEY__NATIVE_GET_ELEMENT_BY_ID];
@@ -6623,7 +6648,7 @@ const querySelectorAll = _globalThis[KEY__NATIVE_QUERY_SELECTOR_ALL];
6623
6648
  function isSyntheticShadowRootInstance(rootNode) {
6624
6649
  return rootNode !== document && isTrue(rootNode.synthetic);
6625
6650
  }
6626
- function reportViolation(source, target, attrName) {
6651
+ function reportViolation$1(source, target, attrName) {
6627
6652
  // The vm is either for the source, the target, or both. Either one or both must be using synthetic
6628
6653
  // shadow for a violation to be detected.
6629
6654
  let vm = getAssociatedVMIfPresent(source.getRootNode().host);
@@ -6634,12 +6659,15 @@ function reportViolation(source, target, attrName) {
6634
6659
  // vm should never be undefined here, but just to be safe, bail out and don't report
6635
6660
  return;
6636
6661
  }
6637
- report(0 /* ReportingEventId.CrossRootAriaInSyntheticShadow */, vm);
6662
+ report(0 /* ReportingEventId.CrossRootAriaInSyntheticShadow */, {
6663
+ tagName: vm.tagName,
6664
+ attributeName: attrName,
6665
+ });
6638
6666
  if (process.env.NODE_ENV !== 'production') {
6639
6667
  // Avoid excessively logging to the console in the case of duplicates.
6640
6668
  logWarnOnce(`Element <${source.tagName.toLowerCase()}> uses attribute "${attrName}" to reference element ` +
6641
6669
  `<${target.tagName.toLowerCase()}>, which is not in the same shadow root. This will break in native shadow DOM. ` +
6642
- `For details, see: https://lwc.dev/guide/accessibility#link-ids-and-aria-attributes-from-different-templates`, vm);
6670
+ `For details, see: https://sfdc.co/synthetic-aria`, vm);
6643
6671
  }
6644
6672
  }
6645
6673
  function parseIdRefAttributeValue(attrValue) {
@@ -6666,7 +6694,7 @@ function detectSyntheticCrossRootAria(elm, attrName, attrValue) {
6666
6694
  const sourceElement = sourceElements[i];
6667
6695
  const sourceRoot = sourceElement.getRootNode();
6668
6696
  if (sourceRoot !== root) {
6669
- reportViolation(sourceElement, elm, idRefAttrName);
6697
+ reportViolation$1(sourceElement, elm, idRefAttrName);
6670
6698
  break;
6671
6699
  }
6672
6700
  }
@@ -6681,7 +6709,7 @@ function detectSyntheticCrossRootAria(elm, attrName, attrValue) {
6681
6709
  const targetRoot = target.getRootNode();
6682
6710
  if (targetRoot !== root) {
6683
6711
  // target element's shadow root is not the same as ours
6684
- reportViolation(elm, target, attrName);
6712
+ reportViolation$1(elm, target, attrName);
6685
6713
  }
6686
6714
  }
6687
6715
  }
@@ -6690,7 +6718,7 @@ function detectSyntheticCrossRootAria(elm, attrName, attrValue) {
6690
6718
  let enabled = false;
6691
6719
  // We want to avoid patching globals whenever possible, so this should be tree-shaken out in prod-mode and if
6692
6720
  // reporting is not enabled. It should also only run once
6693
- function enableDetection() {
6721
+ function enableDetection$1() {
6694
6722
  if (enabled) {
6695
6723
  return; // don't double-apply the patches
6696
6724
  }
@@ -6742,12 +6770,110 @@ function isSyntheticShadowLoaded() {
6742
6770
  if (supportsCssEscape() && isSyntheticShadowLoaded()) {
6743
6771
  // Always run detection in dev mode, so we can at least print to the console
6744
6772
  if (process.env.NODE_ENV !== 'production') {
6745
- enableDetection();
6773
+ enableDetection$1();
6746
6774
  }
6747
6775
  else {
6748
6776
  // In prod mode, only enable detection if reporting is enabled
6749
- onReportingEnabled(enableDetection);
6777
+ onReportingEnabled(enableDetection$1);
6778
+ }
6779
+ }
6780
+
6781
+ /*
6782
+ * Copyright (c) 2018, salesforce.com, inc.
6783
+ * All rights reserved.
6784
+ * SPDX-License-Identifier: MIT
6785
+ * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
6786
+ */
6787
+ //
6788
+ // The goal of this code is to detect usages of non-standard reflected ARIA properties. These are caused by
6789
+ // legacy non-standard Element.prototype extensions added by the @lwc/aria-reflection package.
6790
+ //
6791
+ // See the README for @lwc/aria-reflection
6792
+ const NON_STANDARD_ARIA_PROPS = ['ariaActiveDescendant', 'ariaControls', 'ariaDescribedBy', 'ariaDetails', 'ariaErrorMessage', 'ariaFlowTo', 'ariaLabelledBy', 'ariaOwns'];
6793
+ function isLightningElement(elm) {
6794
+ // The former case is for `this.prop` (inside component) and the latter is for `element.prop` (outside component).
6795
+ // In both cases, we apply the non-standard prop even when the global polyfill is disabled, so this is kosher.
6796
+ return elm instanceof LightningElement || elm instanceof BaseBridgeElement;
6797
+ }
6798
+ function findVM(elm) {
6799
+ // If it's a shadow DOM component, then it has a host
6800
+ const {
6801
+ host
6802
+ } = elm.getRootNode();
6803
+ const vm = isUndefined$1(host) ? undefined : getAssociatedVMIfPresent(host);
6804
+ if (!isUndefined$1(vm)) {
6805
+ return vm;
6806
+ }
6807
+ // Else it might be a light DOM component. Walk up the tree trying to find the owner
6808
+ let parentElement = elm;
6809
+ while (!isNull(parentElement = parentElement.parentElement)) {
6810
+ if (isLightningElement(parentElement)) {
6811
+ const vm = getAssociatedVMIfPresent(parentElement);
6812
+ if (!isUndefined$1(vm)) {
6813
+ return vm;
6814
+ }
6815
+ }
6816
+ }
6817
+ // If we return undefined, it's because the element was rendered wholly outside a LightningElement
6818
+ }
6819
+
6820
+ function checkAndReportViolation(elm, prop) {
6821
+ if (!isLightningElement(elm)) {
6822
+ const vm = findVM(elm);
6823
+ if (process.env.NODE_ENV !== 'production') {
6824
+ logWarnOnce(`Element <${elm.tagName.toLowerCase()}> ` + (isUndefined$1(vm) ? '' : `owned by <${vm.elm.tagName.toLowerCase()}> `) + `uses non-standard property "${prop}". This will be removed in a future version of LWC. ` + `See https://sfdc.co/deprecated-aria`);
6825
+ }
6826
+ report(2 /* ReportingEventId.NonStandardAriaReflection */, {
6827
+ tagName: vm === null || vm === void 0 ? void 0 : vm.tagName,
6828
+ propertyName: prop
6829
+ });
6830
+ }
6831
+ }
6832
+ function enableDetection() {
6833
+ const {
6834
+ prototype
6835
+ } = Element;
6836
+ for (const prop of NON_STANDARD_ARIA_PROPS) {
6837
+ const descriptor = getOwnPropertyDescriptor$1(prototype, prop);
6838
+ // The descriptor should exist because the @lwc/aria-reflection polyfill has run by now.
6839
+ // This happens automatically because of the ordering of imports.
6840
+ if (process.env.NODE_ENV !== 'production') {
6841
+ /* istanbul ignore if */
6842
+ if (isUndefined$1(descriptor) || isUndefined$1(descriptor.get) || isUndefined$1(descriptor.set)) {
6843
+ // should never happen
6844
+ throw new Error('detect-non-standard-aria.ts loaded before @lwc/aria-reflection');
6845
+ }
6846
+ }
6847
+ // @ts-ignore
6848
+ const {
6849
+ get,
6850
+ set
6851
+ } = descriptor;
6852
+ defineProperty(prototype, prop, {
6853
+ get() {
6854
+ checkAndReportViolation(this, prop);
6855
+ return get.call(this);
6856
+ },
6857
+ set(val) {
6858
+ checkAndReportViolation(this, prop);
6859
+ return set.call(this, val);
6860
+ },
6861
+ configurable: true,
6862
+ enumerable: true
6863
+ });
6864
+ }
6865
+ }
6866
+ // No point in running this code if we're not in a browser, or if the global polyfill is not loaded
6867
+ {
6868
+ if (!lwcRuntimeFlags.DISABLE_ARIA_REFLECTION_POLYFILL) {
6869
+ // Always run detection in dev mode, so we can at least print to the console
6870
+ if (process.env.NODE_ENV !== 'production') {
6871
+ enableDetection();
6872
+ } else {
6873
+ // In prod mode, only enable detection if reporting is enabled
6874
+ onReportingEnabled(enableDetection);
6750
6875
  }
6876
+ }
6751
6877
  }
6752
6878
 
6753
6879
  /*
@@ -7234,12 +7360,13 @@ function setHooks(hooks) {
7234
7360
  */
7235
7361
  // See @lwc/engine-core/src/framework/template.ts
7236
7362
  const TEMPLATE_PROPS = ['slots', 'stylesheetToken', 'stylesheets', 'renderMode'];
7237
- // Via https://www.npmjs.com/package/object-observer
7238
- const ARRAY_MUTATION_METHODS = ['pop', 'push', 'shift', 'unshift', 'reverse', 'sort', 'fill', 'splice', 'copyWithin'];
7239
7363
  // Expandos that may be placed on a stylesheet factory function, and which are meaningful to LWC at runtime
7240
- const STYLESHEET_FUNCTION_EXPANDOS = [
7364
+ const STYLESHEET_PROPS = [
7241
7365
  // SEE `KEY__SCOPED_CSS` in @lwc/style-compiler
7242
7366
  '$scoped$'];
7367
+ // Via https://www.npmjs.com/package/object-observer
7368
+ const ARRAY_MUTATION_METHODS = ['pop', 'push', 'shift', 'unshift', 'reverse', 'sort', 'fill', 'splice', 'copyWithin'];
7369
+ let mutationTrackingDisabled = false;
7243
7370
  function getOriginalArrayMethod(prop) {
7244
7371
  switch (prop) {
7245
7372
  case 'pop':
@@ -7262,7 +7389,20 @@ function getOriginalArrayMethod(prop) {
7262
7389
  return ArrayCopyWithin;
7263
7390
  }
7264
7391
  }
7265
- let mutationWarningsSilenced = false;
7392
+ function reportViolation(type, eventId, prop) {
7393
+ if (process.env.NODE_ENV !== 'production') {
7394
+ logWarnOnce(`Mutating the "${prop}" property on a ${type} ` + `is deprecated and will be removed in a future version of LWC. ` + `See: https://sfdc.co/template-mutation`);
7395
+ }
7396
+ report(eventId, {
7397
+ propertyName: prop
7398
+ });
7399
+ }
7400
+ function reportTemplateViolation(prop) {
7401
+ reportViolation('template', 3 /* ReportingEventId.TemplateMutation */, prop);
7402
+ }
7403
+ function reportStylesheetViolation(prop) {
7404
+ reportViolation('stylesheet', 4 /* ReportingEventId.StylesheetMutation */, prop);
7405
+ }
7266
7406
  // Warn if the user tries to mutate a stylesheets array, e.g.:
7267
7407
  // `tmpl.stylesheets.push(someStylesheetFunction)`
7268
7408
  function warnOnArrayMutation(stylesheets) {
@@ -7271,7 +7411,7 @@ function warnOnArrayMutation(stylesheets) {
7271
7411
  for (const prop of ARRAY_MUTATION_METHODS) {
7272
7412
  const originalArrayMethod = getOriginalArrayMethod(prop);
7273
7413
  stylesheets[prop] = function arrayMutationWarningWrapper() {
7274
- logError(`Mutating the "stylesheets" array on a template function ` + `is deprecated and may be removed in a future version of LWC.`);
7414
+ reportTemplateViolation('stylesheets');
7275
7415
  // @ts-ignore
7276
7416
  return originalArrayMethod.apply(this, arguments);
7277
7417
  };
@@ -7280,8 +7420,7 @@ function warnOnArrayMutation(stylesheets) {
7280
7420
  // Warn if the user tries to mutate a stylesheet factory function, e.g.:
7281
7421
  // `stylesheet.$scoped$ = true`
7282
7422
  function warnOnStylesheetFunctionMutation(stylesheet) {
7283
- // We could warn on other properties, but in practice only certain expandos are meaningful to LWC at runtime
7284
- for (const prop of STYLESHEET_FUNCTION_EXPANDOS) {
7423
+ for (const prop of STYLESHEET_PROPS) {
7285
7424
  let value = stylesheet[prop];
7286
7425
  defineProperty(stylesheet, prop, {
7287
7426
  enumerable: true,
@@ -7290,14 +7429,14 @@ function warnOnStylesheetFunctionMutation(stylesheet) {
7290
7429
  return value;
7291
7430
  },
7292
7431
  set(newValue) {
7293
- logError(`Dynamically setting the "${prop}" property on a stylesheet function ` + `is deprecated and may be removed in a future version of LWC.`);
7432
+ reportStylesheetViolation(prop);
7294
7433
  value = newValue;
7295
7434
  }
7296
7435
  });
7297
7436
  }
7298
7437
  }
7299
7438
  // Warn on either array or stylesheet (function) mutation, in a deeply-nested array
7300
- function warnOnStylesheetsMutation(stylesheets) {
7439
+ function trackStylesheetsMutation(stylesheets) {
7301
7440
  traverseStylesheets(stylesheets, subStylesheets => {
7302
7441
  if (isArray$1(subStylesheets)) {
7303
7442
  warnOnArrayMutation(subStylesheets);
@@ -7324,7 +7463,70 @@ function traverseStylesheets(stylesheets, callback) {
7324
7463
  }
7325
7464
  }
7326
7465
  }
7466
+ function trackMutations(tmpl) {
7467
+ if (!isUndefined$1(tmpl.stylesheets)) {
7468
+ trackStylesheetsMutation(tmpl.stylesheets);
7469
+ }
7470
+ for (const prop of TEMPLATE_PROPS) {
7471
+ let value = tmpl[prop];
7472
+ defineProperty(tmpl, prop, {
7473
+ enumerable: true,
7474
+ configurable: true,
7475
+ get() {
7476
+ return value;
7477
+ },
7478
+ set(newValue) {
7479
+ if (!mutationTrackingDisabled) {
7480
+ reportTemplateViolation(prop);
7481
+ }
7482
+ value = newValue;
7483
+ }
7484
+ });
7485
+ }
7486
+ const originalDescriptor = getOwnPropertyDescriptor$1(tmpl, 'stylesheetTokens');
7487
+ defineProperty(tmpl, 'stylesheetTokens', {
7488
+ enumerable: true,
7489
+ configurable: true,
7490
+ get: originalDescriptor.get,
7491
+ set(value) {
7492
+ reportTemplateViolation('stylesheetTokens');
7493
+ // Avoid logging/reporting twice (for both stylesheetToken and stylesheetTokens)
7494
+ mutationTrackingDisabled = true;
7495
+ originalDescriptor.set.call(this, value);
7496
+ mutationTrackingDisabled = false;
7497
+ }
7498
+ });
7499
+ }
7500
+ function addLegacyStylesheetTokensShim(tmpl) {
7501
+ // When ENABLE_FROZEN_TEMPLATE is false, then we shim stylesheetTokens on top of stylesheetToken for anyone who
7502
+ // is accessing the old internal API (backwards compat). Details: https://salesforce.quip.com/v1rmAFu2cKAr
7503
+ defineProperty(tmpl, 'stylesheetTokens', {
7504
+ enumerable: true,
7505
+ configurable: true,
7506
+ get() {
7507
+ const {
7508
+ stylesheetToken
7509
+ } = this;
7510
+ if (isUndefined$1(stylesheetToken)) {
7511
+ return stylesheetToken;
7512
+ }
7513
+ // Shim for the old `stylesheetTokens` property
7514
+ // See https://github.com/salesforce/lwc/pull/2332/files#diff-7901555acef29969adaa6583185b3e9bce475cdc6f23e799a54e0018cb18abaa
7515
+ return {
7516
+ hostAttribute: `${stylesheetToken}-host`,
7517
+ shadowAttribute: stylesheetToken
7518
+ };
7519
+ },
7520
+ set(value) {
7521
+ // If the value is null or some other exotic object, you would be broken anyway in the past
7522
+ // because the engine would try to access hostAttribute/shadowAttribute, which would throw an error.
7523
+ // However it may be undefined in newer versions of LWC, so we need to guard against that case.
7524
+ this.stylesheetToken = isUndefined$1(value) ? undefined : value.shadowAttribute;
7525
+ }
7526
+ });
7527
+ }
7327
7528
  function freezeTemplate(tmpl) {
7529
+ // TODO [#2782]: remove this flag and delete the legacy behavior
7328
7530
  if (lwcRuntimeFlags.ENABLE_FROZEN_TEMPLATE) {
7329
7531
  // Deep freeze the template
7330
7532
  freeze(tmpl);
@@ -7332,66 +7534,16 @@ function freezeTemplate(tmpl) {
7332
7534
  deepFreeze(tmpl.stylesheets);
7333
7535
  }
7334
7536
  } else {
7335
- // TODO [#2782]: remove this flag and delete the legacy behavior
7336
- // When ENABLE_FROZEN_TEMPLATE is false, then we shim stylesheetTokens on top of stylesheetToken for anyone who
7337
- // is accessing the old internal API (backwards compat). Details: https://salesforce.quip.com/v1rmAFu2cKAr
7338
- defineProperty(tmpl, 'stylesheetTokens', {
7339
- enumerable: true,
7340
- configurable: true,
7341
- get() {
7342
- const {
7343
- stylesheetToken
7344
- } = this;
7345
- if (isUndefined$1(stylesheetToken)) {
7346
- return stylesheetToken;
7347
- }
7348
- // Shim for the old `stylesheetTokens` property
7349
- // See https://github.com/salesforce/lwc/pull/2332/files#diff-7901555acef29969adaa6583185b3e9bce475cdc6f23e799a54e0018cb18abaa
7350
- return {
7351
- hostAttribute: `${stylesheetToken}-host`,
7352
- shadowAttribute: stylesheetToken
7353
- };
7354
- },
7355
- set(value) {
7356
- // If the value is null or some other exotic object, you would be broken anyway in the past
7357
- // because the engine would try to access hostAttribute/shadowAttribute, which would throw an error.
7358
- // However it may be undefined in newer versions of LWC, so we need to guard against that case.
7359
- this.stylesheetToken = isUndefined$1(value) ? undefined : value.shadowAttribute;
7360
- }
7361
- });
7362
- // When ENABLE_FROZEN_TEMPLATE is false, warn in dev mode whenever someone is mutating the template
7537
+ // template is not frozen - shim, report, and warn
7538
+ // this shim should be applied in both dev and prod
7539
+ addLegacyStylesheetTokensShim(tmpl);
7540
+ // When ENABLE_FROZEN_TEMPLATE is false, we want to warn in dev mode whenever someone is mutating the template
7363
7541
  if (process.env.NODE_ENV !== 'production') {
7364
- if (!isUndefined$1(tmpl.stylesheets)) {
7365
- warnOnStylesheetsMutation(tmpl.stylesheets);
7366
- }
7367
- for (const prop of TEMPLATE_PROPS) {
7368
- let value = tmpl[prop];
7369
- defineProperty(tmpl, prop, {
7370
- enumerable: true,
7371
- configurable: true,
7372
- get() {
7373
- return value;
7374
- },
7375
- set(newValue) {
7376
- if (!mutationWarningsSilenced) {
7377
- logError(`Dynamically setting the "${prop}" property on a template function ` + `is deprecated and may be removed in a future version of LWC.`);
7378
- }
7379
- value = newValue;
7380
- }
7381
- });
7382
- }
7383
- const originalDescriptor = getOwnPropertyDescriptor$1(tmpl, 'stylesheetTokens');
7384
- defineProperty(tmpl, 'stylesheetTokens', {
7385
- enumerable: true,
7386
- configurable: true,
7387
- get: originalDescriptor.get,
7388
- set(value) {
7389
- logError(`Dynamically setting the "stylesheetTokens" property on a template function ` + `is deprecated and may be removed in a future version of LWC.`);
7390
- // Avoid logging twice (for both stylesheetToken and stylesheetTokens)
7391
- mutationWarningsSilenced = true;
7392
- originalDescriptor.set.call(this, value);
7393
- mutationWarningsSilenced = false;
7394
- }
7542
+ trackMutations(tmpl);
7543
+ } else {
7544
+ // In prod mode, we only track mutations if reporting is enabled
7545
+ onReportingEnabled(() => {
7546
+ trackMutations(tmpl);
7395
7547
  });
7396
7548
  }
7397
7549
  }
@@ -7419,7 +7571,7 @@ function getComponentConstructor(elm) {
7419
7571
  }
7420
7572
  return ctor;
7421
7573
  }
7422
- /* version: 2.35.2 */
7574
+ /* version: 2.37.0 */
7423
7575
 
7424
7576
  /*
7425
7577
  * Copyright (c) 2018, salesforce.com, inc.
@@ -7762,545 +7914,6 @@ const createCustomElementUsingUpgradableConstructor = (tagName, upgradeCallback,
7762
7914
  }
7763
7915
  };
7764
7916
 
7765
- /*
7766
- * Copyright (c) 2020, salesforce.com, inc.
7767
- * All rights reserved.
7768
- * SPDX-License-Identifier: MIT
7769
- * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
7770
- */
7771
- /**
7772
- * Create a scoped registry, i.e. a function that can create custom elements whose tag names
7773
- * do not conflict with third-party custom elements having the same tag name.
7774
- */
7775
- function createScopedRegistry() {
7776
- if (!hasCustomElements) {
7777
- // This code should never be reached, because we don't use the pivot registry if
7778
- // custom elements are unavailable.
7779
- throw new Error('Custom elements are not supported in this environment.');
7780
- }
7781
- const { HTMLElement: NativeHTMLElement } = window;
7782
- const { hasAttribute: nativeHasAttribute, setAttribute: nativeSetAttribute, removeAttribute: nativeRemoveAttribute, getAttribute: nativeGetAttribute, } = NativeHTMLElement.prototype;
7783
- const definitionForElement = new WeakMap();
7784
- const pendingRegistryForElement = new WeakMap();
7785
- const definitionForConstructor = new WeakMap();
7786
- const registeredUserCtors = new WeakSet();
7787
- const registeredPivotCtors = new WeakSet();
7788
- const pivotCtorByTag = new Map();
7789
- const globalDefinitionsByTag = new Map();
7790
- const globalDefinitionsByClass = new Map();
7791
- const awaitingUpgrade = new Map();
7792
- const pendingWhenDefinedCallbacks = new Map();
7793
- const EMPTY_SET = new Set();
7794
- function createDefinitionRecord(constructor) {
7795
- var _a;
7796
- const { connectedCallback, disconnectedCallback, formAssociatedCallback, formDisabledCallback, formResetCallback, formStateRestoreCallback, adoptedCallback, attributeChangedCallback, } = constructor.prototype;
7797
- const formAssociated = Boolean(constructor.formAssociated);
7798
- const observedAttributes = new Set((_a = constructor.observedAttributes) !== null && _a !== void 0 ? _a : []);
7799
- return {
7800
- UserCtor: constructor,
7801
- PivotCtor: undefined,
7802
- connectedCallback,
7803
- disconnectedCallback,
7804
- formAssociatedCallback,
7805
- formDisabledCallback,
7806
- formResetCallback,
7807
- formStateRestoreCallback,
7808
- adoptedCallback,
7809
- attributeChangedCallback,
7810
- observedAttributes,
7811
- formAssociated,
7812
- };
7813
- }
7814
- // Helper to create stand-in element for each tagName registered that delegates out to the registry for the given
7815
- // element. Note that the `registeredDefinition` represents the constructor that was used to register during
7816
- // `customElements.define()`. Whereas the `pivotDefinition` represents the constructor that is passed when the pivot
7817
- // constructor is invoked with another constructor.
7818
- function createPivotingClass(tagName, registeredDefinition) {
7819
- class PivotCtor extends NativeHTMLElement {
7820
- constructor(UserCtor) {
7821
- // This constructor can only be invoked by:
7822
- // a) the browser instantiating an element from parsing or via document.createElement.
7823
- // b) LWC new PivotClass (This constructor is NOT observable/accessible in user-land).
7824
- // b) new UserClass.
7825
- // When LWC instantiates it, it will pass the upgrading definition as an argument
7826
- // If the caller signals via UserCtor that this is in fact a controlled
7827
- // definition, we use that one, otherwise fallback to the global
7828
- // internal registry.
7829
- super();
7830
- const userCtorIsDefined = !isUndefined$1(UserCtor);
7831
- if (userCtorIsDefined) {
7832
- if (!isConstructor(UserCtor)) {
7833
- throw new TypeError(`Failed to create custom element: the provided constructor is not a constructor.`);
7834
- }
7835
- if (!registeredUserCtors.has(UserCtor)) {
7836
- throw new Error(`Failed to create custom element: the provided constructor is unregistered: ${UserCtor.name}.`);
7837
- }
7838
- }
7839
- const definition = userCtorIsDefined
7840
- ? getOrCreateDefinitionForConstructor(UserCtor)
7841
- : globalDefinitionsByTag.get(tagName);
7842
- if (!isUndefined$1(definition)) {
7843
- internalUpgrade(this, registeredDefinition, definition);
7844
- }
7845
- else {
7846
- // This is the case in which there is no global definition, and
7847
- // it is not handled by LWC (otherwise it will have a valid UserCtor)
7848
- // so we need to add it to the pending queue just in case it eventually
7849
- // gets defined in the global registry.
7850
- pendingRegistryForElement.set(this, registeredDefinition);
7851
- }
7852
- }
7853
- connectedCallback() {
7854
- var _a;
7855
- const definition = definitionForElement.get(this);
7856
- if (!isUndefined$1(definition)) {
7857
- // Delegate out to user callback
7858
- (_a = definition.connectedCallback) === null || _a === void 0 ? void 0 : _a.call(this);
7859
- }
7860
- else {
7861
- // Register for upgrade when defined (only when connected, so we don't leak)
7862
- let awaiting = awaitingUpgrade.get(tagName);
7863
- if (isUndefined$1(awaiting)) {
7864
- awaitingUpgrade.set(tagName, (awaiting = new Set()));
7865
- }
7866
- awaiting.add(this);
7867
- }
7868
- }
7869
- disconnectedCallback() {
7870
- var _a;
7871
- const definition = definitionForElement.get(this);
7872
- if (!isUndefined$1(definition)) {
7873
- // Delegate out to user callback
7874
- (_a = definition.disconnectedCallback) === null || _a === void 0 ? void 0 : _a.call(this);
7875
- }
7876
- else {
7877
- // Un-register for upgrade when defined (so we don't leak)
7878
- const awaiting = awaitingUpgrade.get(tagName);
7879
- // At this point, awaiting should never be undefined, because connectedCallback
7880
- // must have been called before disconnectedCallback. But just to be safe, we check
7881
- if (!isUndefined$1(awaiting)) {
7882
- awaiting.delete(this);
7883
- }
7884
- }
7885
- }
7886
- formAssociatedCallback(form) {
7887
- var _a;
7888
- const definition = definitionForElement.get(this);
7889
- (_a = definition === null || definition === void 0 ? void 0 : definition.formAssociatedCallback) === null || _a === void 0 ? void 0 : _a.call(this, form);
7890
- }
7891
- formDisabledCallback(disabled) {
7892
- var _a;
7893
- const definition = definitionForElement.get(this);
7894
- (_a = definition === null || definition === void 0 ? void 0 : definition.formDisabledCallback) === null || _a === void 0 ? void 0 : _a.call(this, disabled);
7895
- }
7896
- formResetCallback() {
7897
- var _a;
7898
- const definition = definitionForElement.get(this);
7899
- (_a = definition === null || definition === void 0 ? void 0 : definition.formResetCallback) === null || _a === void 0 ? void 0 : _a.call(this);
7900
- }
7901
- formStateRestoreCallback(state, mode) {
7902
- var _a;
7903
- const definition = definitionForElement.get(this);
7904
- (_a = definition === null || definition === void 0 ? void 0 : definition.formStateRestoreCallback) === null || _a === void 0 ? void 0 : _a.call(this, state, mode);
7905
- }
7906
- adoptedCallback() {
7907
- var _a;
7908
- const definition = definitionForElement.get(this);
7909
- (_a = definition === null || definition === void 0 ? void 0 : definition.adoptedCallback) === null || _a === void 0 ? void 0 : _a.call(this);
7910
- }
7911
- attributeChangedCallback(name, oldValue, newValue) {
7912
- var _a;
7913
- const definition = definitionForElement.get(this);
7914
- // if both definitions are the same, then the observedAttributes is the same,
7915
- // but if they are different, only if the runtime definition has the attribute
7916
- // marked as observed, then it should invoke attributeChangedCallback.
7917
- if (registeredDefinition === definition ||
7918
- (definition === null || definition === void 0 ? void 0 : definition.observedAttributes.has(name))) {
7919
- (_a = definition.attributeChangedCallback) === null || _a === void 0 ? void 0 : _a.apply(this, [name, oldValue, newValue]);
7920
- }
7921
- }
7922
- }
7923
- PivotCtor.observedAttributes = [...registeredDefinition.observedAttributes];
7924
- // TODO [#3000]: support case where registeredDefinition is not form-associated, but later definition is.
7925
- PivotCtor.formAssociated = registeredDefinition.formAssociated;
7926
- registeredPivotCtors.add(PivotCtor);
7927
- return PivotCtor;
7928
- }
7929
- function getNewObservedAttributes(registeredDefinition, pivotDefinition) {
7930
- const { observedAttributes, attributeChangedCallback } = pivotDefinition;
7931
- if (observedAttributes.size === 0 || isUndefined$1(attributeChangedCallback)) {
7932
- // This instance does not need to observe any attributes, no need to patch
7933
- return EMPTY_SET;
7934
- }
7935
- // Natively, the attributes observed by the registered definition are going to be taken
7936
- // care of by the browser, only the difference between the two sets has to be taken
7937
- // care by the patched version.
7938
- return new Set([...pivotDefinition.observedAttributes].filter((x) => !registeredDefinition.observedAttributes.has(x)));
7939
- }
7940
- function throwAsyncError(error) {
7941
- // Per native custom element behavior, errors thrown in attributeChangedCallback
7942
- // become unhandled async errors. We use setTimeout() instead of Promise.resolve()
7943
- // to make it an unhandled error rather than an unhandled rejection.
7944
- setTimeout(() => {
7945
- throw error;
7946
- });
7947
- }
7948
- // Helper to patch `setAttribute`/`getAttribute` to implement `attributeChangedCallback`.
7949
- // Why is this necessary? Well basically, you can't change the `observedAttributes` after
7950
- // a custom element is defined. So with pivots, if two classes share the same tag name,
7951
- // and the second class observes attributes that aren't observed by the first one,
7952
- // then those attributes can never be observed by the native `observedAttributes` system.
7953
- // So we have to simulate it by patching `getAttribute`/`removeAttribute`. Note that
7954
- // we only do this when absolutely necessary, though; i.e. because we've determined
7955
- // that we aren't observing the attributes we need to.
7956
- function patchAttributes(instance, registeredDefinition, pivotDefinition) {
7957
- const newObservedAttributes = getNewObservedAttributes(registeredDefinition, pivotDefinition);
7958
- if (newObservedAttributes.size === 0) {
7959
- return;
7960
- }
7961
- const { attributeChangedCallback } = pivotDefinition;
7962
- // Patch the instance.
7963
- // Note we use the native `getAttribute` rather than the super's `getAttribute` because
7964
- // we don't actually want it to be observable that we're calling `getAttribute` from
7965
- // `setAttribute` and `removeAttribute`.
7966
- // TODO [#2994]: this should handle reflected properties such as `ariaLabel` and `role`.
7967
- defineProperties(instance, {
7968
- setAttribute: {
7969
- value: function setAttribute(name, value) {
7970
- if (newObservedAttributes.has(name)) {
7971
- const old = nativeGetAttribute.call(this, name);
7972
- nativeSetAttribute.call(this, name, value);
7973
- try {
7974
- attributeChangedCallback.call(this, name, old, value + '');
7975
- }
7976
- catch (error) {
7977
- throwAsyncError(error);
7978
- }
7979
- }
7980
- else {
7981
- nativeSetAttribute.call(this, name, value);
7982
- }
7983
- },
7984
- writable: true,
7985
- enumerable: true,
7986
- configurable: true,
7987
- },
7988
- removeAttribute: {
7989
- value: function removeAttribute(name) {
7990
- if (newObservedAttributes.has(name)) {
7991
- const old = nativeGetAttribute.call(this, name);
7992
- nativeRemoveAttribute.call(this, name);
7993
- try {
7994
- attributeChangedCallback.call(this, name, old, null);
7995
- }
7996
- catch (error) {
7997
- throwAsyncError(error);
7998
- }
7999
- }
8000
- else {
8001
- nativeRemoveAttribute.call(this, name);
8002
- }
8003
- },
8004
- writable: true,
8005
- enumerable: true,
8006
- configurable: true,
8007
- },
8008
- });
8009
- }
8010
- function patchAttributesDuringUpgrade(instance, registeredDefinition, pivotDefinition) {
8011
- // The below case patches observed attributes for the case where the HTML element is upgraded
8012
- // from a pre-existing one in the DOM.
8013
- const newObservedAttributes = getNewObservedAttributes(registeredDefinition, pivotDefinition);
8014
- if (getNewObservedAttributes(registeredDefinition, pivotDefinition).size === 0) {
8015
- return;
8016
- }
8017
- const { attributeChangedCallback } = pivotDefinition;
8018
- // Approximate observedAttributes from the user class, but only for the new observed attributes
8019
- newObservedAttributes.forEach((name) => {
8020
- if (nativeHasAttribute.call(instance, name)) {
8021
- const newValue = nativeGetAttribute.call(instance, name);
8022
- attributeChangedCallback.call(instance, name, null, newValue);
8023
- }
8024
- });
8025
- }
8026
- // User extends this HTMLElement, which returns the CE being upgraded
8027
- let upgradingInstance;
8028
- // Helper to upgrade an instance with a CE definition using "constructor call trick"
8029
- function internalUpgrade(instance, registeredDefinition, pivotDefinition) {
8030
- setPrototypeOf(instance, pivotDefinition.UserCtor.prototype);
8031
- definitionForElement.set(instance, pivotDefinition);
8032
- // attributes patches when needed
8033
- if (pivotDefinition !== registeredDefinition) {
8034
- patchAttributes(instance, registeredDefinition, pivotDefinition);
8035
- }
8036
- // Tricking the construction path to believe that a new instance is being created,
8037
- // that way it will execute the super initialization mechanism but the HTMLElement
8038
- // constructor will reuse the instance by returning the upgradingInstance.
8039
- // This is by far the most important piece of the puzzle
8040
- upgradingInstance = instance;
8041
- // By `new`ing the UserCtor, we now jump to the constructor for the overridden global HTMLElement
8042
- // The reason this happens is that the UserCtor extends HTMLElement, so it calls the `super()`.
8043
- // Note that `upgradingInstance` is explicitly handled in the HTMLElement constructor.
8044
- new pivotDefinition.UserCtor();
8045
- patchAttributesDuringUpgrade(instance, registeredDefinition, pivotDefinition);
8046
- }
8047
- function isConstructor(constructor) {
8048
- return isFunction$1(constructor) && isObject(constructor.prototype);
8049
- }
8050
- function getOrCreateDefinitionForConstructor(constructor) {
8051
- if (!isConstructor(constructor)) {
8052
- throw new TypeError('The referenced constructor is not a constructor.');
8053
- }
8054
- const definition = definitionForConstructor.get(constructor);
8055
- if (!isUndefined$1(definition)) {
8056
- return definition;
8057
- }
8058
- return createDefinitionRecord(constructor);
8059
- }
8060
- // Defer a `whenDefined()` callback until an externally-visible custom element is defined
8061
- function createPendingWhenDefinedCallback(tagName) {
8062
- return new Promise((resolve) => {
8063
- let resolvers = pendingWhenDefinedCallbacks.get(tagName);
8064
- if (isUndefined$1(resolvers)) {
8065
- resolvers = [];
8066
- pendingWhenDefinedCallbacks.set(tagName, resolvers);
8067
- }
8068
- resolvers.push(resolve);
8069
- });
8070
- }
8071
- // Call any pending `whenDefined()` callbacks
8072
- function flushPendingWhenDefinedCallbacks(tagName, ctor) {
8073
- const resolvers = pendingWhenDefinedCallbacks.get(tagName);
8074
- if (!isUndefined$1(resolvers)) {
8075
- for (const resolver of resolvers) {
8076
- resolver(ctor);
8077
- }
8078
- }
8079
- pendingWhenDefinedCallbacks.delete(tagName);
8080
- }
8081
- const { customElements: nativeRegistry } = window;
8082
- const { define: nativeDefine, whenDefined: nativeWhenDefined, get: nativeGet } = nativeRegistry;
8083
- // patch for the global registry define mechanism
8084
- CustomElementRegistry.prototype.define = function define(tagName, constructor, options) {
8085
- if (options && options.extends) {
8086
- // TODO [#2983]: should we support `extends`?
8087
- throw new DOMException('NotSupportedError: "extends" key in customElements.define() options is not supported.');
8088
- }
8089
- if (globalDefinitionsByTag.has(tagName)) {
8090
- throw new DOMException(`Failed to execute 'define' on 'CustomElementRegistry': the name "${tagName}" has already been used with this registry`);
8091
- }
8092
- if (!isUndefined$1(globalDefinitionsByClass.get(constructor))) {
8093
- throw new DOMException(`Failed to execute 'define' on 'CustomElementRegistry': this constructor has already been used with this registry`);
8094
- }
8095
- const definition = getOrCreateDefinitionForConstructor(constructor);
8096
- registeredUserCtors.add(constructor);
8097
- let PivotCtor = pivotCtorByTag.get(tagName);
8098
- if (isUndefined$1(PivotCtor)) {
8099
- PivotCtor = createPivotingClass(tagName, definition);
8100
- // Register a pivoting class which will handle global registry initializations
8101
- nativeDefine.call(nativeRegistry, tagName, PivotCtor);
8102
- }
8103
- // Only cache after nativeDefine has been called, because if it throws an error
8104
- // (e.g. for an invalid tag name), then we don't want to cache anything.
8105
- definitionForConstructor.set(constructor, definition);
8106
- pivotCtorByTag.set(tagName, PivotCtor);
8107
- globalDefinitionsByTag.set(tagName, definition);
8108
- globalDefinitionsByClass.set(constructor, definition);
8109
- // For globally defined custom elements, the definition associated
8110
- // to the UserCtor has a back-pointer to PivotCtor in case the user
8111
- // new the UserCtor, so we know how to create the underlying element.
8112
- definition.PivotCtor = PivotCtor;
8113
- // Upgrade any elements created in this scope before customElements.define
8114
- // was called, which should be exhibited by the following steps:
8115
- // 1) LWC registers a tagName for an LWC component.
8116
- // 2) Element with same tagName is created with document.createElement()
8117
- // and inserted into DOM.
8118
- // 3) customElements.define() is called with tagName and non-LWC constructor.
8119
- // This requires immediate upgrade when the new global tagName is defined.
8120
- const awaiting = awaitingUpgrade.get(tagName);
8121
- if (!isUndefined$1(awaiting)) {
8122
- awaitingUpgrade.delete(tagName);
8123
- for (const element of awaiting) {
8124
- const registeredDefinition = pendingRegistryForElement.get(element);
8125
- // At this point, registeredDefinition should never be undefined because awaitingUpgrade
8126
- // is only populated when we haven't run internalUpgrade yet, and we only populate
8127
- // pendingRegistryForElement when internalUpgrade hasn't run yet.
8128
- // But just to be safe, we check.
8129
- if (!isUndefined$1(registeredDefinition)) {
8130
- pendingRegistryForElement.delete(element);
8131
- internalUpgrade(element, registeredDefinition, definition);
8132
- }
8133
- }
8134
- }
8135
- // If anyone called customElements.whenDefined() and is still waiting for a promise resolution, resolve now
8136
- flushPendingWhenDefinedCallbacks(tagName, constructor);
8137
- };
8138
- CustomElementRegistry.prototype.get = function get(tagName) {
8139
- const NativeCtor = nativeGet.call(nativeRegistry, tagName);
8140
- if (!isUndefined$1(NativeCtor)) {
8141
- const definition = globalDefinitionsByTag.get(tagName);
8142
- if (!isUndefined$1(definition)) {
8143
- return definition.UserCtor; // defined by the patched custom elements registry
8144
- }
8145
- if (registeredPivotCtors.has(NativeCtor)) {
8146
- return undefined; // pivot constructors should not be observable, return undefined
8147
- }
8148
- return NativeCtor; // constructor that existed before patching
8149
- }
8150
- };
8151
- CustomElementRegistry.prototype.whenDefined = function whenDefined(tagName) {
8152
- return nativeWhenDefined.call(nativeRegistry, tagName).then((NativeCtor) => {
8153
- const definition = globalDefinitionsByTag.get(tagName);
8154
- if (!isUndefined$1(definition)) {
8155
- return definition.UserCtor;
8156
- }
8157
- // In this case, the custom element must have been defined before the registry patches
8158
- // were applied. So return the non-pivot constructor
8159
- if (isUndefined$1(NativeCtor)) {
8160
- // Chromium bug: https://bugs.chromium.org/p/chromium/issues/detail?id=1335247
8161
- // We can patch the correct behavior using customElements.get()
8162
- NativeCtor = nativeGet.call(nativeRegistry, tagName);
8163
- }
8164
- if (registeredPivotCtors.has(NativeCtor)) {
8165
- // Pivot constructors should not be observable. Wait to resolve the promise
8166
- // if a constructor is ever defined in userland
8167
- return createPendingWhenDefinedCallback(tagName);
8168
- }
8169
- return NativeCtor;
8170
- });
8171
- };
8172
- // This constructor is invoked when we call `new pivotDefinition.UserCtor()`
8173
- // @ts-ignore
8174
- window.HTMLElement = function HTMLElement() {
8175
- // Upgrading case: the pivoting class constructor was run by the browser's
8176
- // native custom elements and we're in the process of running the
8177
- // "constructor-call trick" on the natively constructed instance, so just
8178
- // return that here.
8179
- // This code path is also called when LWC `new`s a PivotCtor.
8180
- const instance = upgradingInstance;
8181
- if (!isUndefined$1(instance)) {
8182
- upgradingInstance = undefined;
8183
- return instance;
8184
- }
8185
- // Construction case: we need to construct the pivoting instance and return it.
8186
- // This is possible when the user register it via global registry and instantiate
8187
- // it via `new Ctor()`.
8188
- const { constructor } = this;
8189
- const definition = globalDefinitionsByClass.get(constructor);
8190
- if (isUndefined$1(definition) || isUndefined$1(definition.PivotCtor)) {
8191
- // This code path is hit if someone `new`s a class that extends `HTMLElement` without
8192
- // doing `customElements.define()` first. This matches native browser behavior:
8193
- // https://stackoverflow.com/a/61883392
8194
- throw new TypeError('Illegal constructor');
8195
- }
8196
- // This constructor is ONLY invoked when it is the user instantiating
8197
- // an element via new Ctor while Ctor is a registered global constructor.
8198
- const { PivotCtor, UserCtor } = definition;
8199
- return new PivotCtor(UserCtor);
8200
- };
8201
- HTMLElement.prototype = NativeHTMLElement.prototype;
8202
- /**
8203
- * Create a new PivotConstructor for the given tagName, which is capable of being constructed
8204
- * with a UserConstructor defining the behavior. Passing in the UserConstructor here
8205
- * is a hint that can be used when registering a custom element with the global custom elements
8206
- * registry for the first time, which provides certain optimizations. It also marks the UserConstructor
8207
- * as "safe" to be used when passed in to a PivotConstructor.
8208
- *
8209
- * @param tagName - element tag name
8210
- * @param UserCtor - userland custom element constructor
8211
- * @returns a new custom element constructor
8212
- */
8213
- return function createPivotConstructor(tagName, UserCtor) {
8214
- tagName = StringToLowerCase.call(tagName);
8215
- let PivotCtor = pivotCtorByTag.get(tagName);
8216
- if (isUndefined$1(PivotCtor)) {
8217
- const definition = getOrCreateDefinitionForConstructor(UserCtor);
8218
- PivotCtor = createPivotingClass(tagName, definition);
8219
- // Register a pivoting class as a global custom element
8220
- nativeDefine.call(nativeRegistry, tagName, PivotCtor);
8221
- definition.PivotCtor = PivotCtor;
8222
- // Only cache after nativeDefine has been called, because if it throws an error
8223
- // (e.g. for an invalid tag name), then we don't want to cache anything.
8224
- definitionForConstructor.set(UserCtor, definition);
8225
- pivotCtorByTag.set(tagName, PivotCtor);
8226
- }
8227
- // Register a UserConstructor as "safe" to be used within a PivotConstructor
8228
- registeredUserCtors.add(UserCtor);
8229
- return PivotCtor;
8230
- };
8231
- }
8232
-
8233
- /*
8234
- * Copyright (c) 2018, salesforce.com, inc.
8235
- * All rights reserved.
8236
- * SPDX-License-Identifier: MIT
8237
- * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
8238
- */
8239
- let createScopedConstructor;
8240
- let CachedHTMLElement;
8241
- // We only call `createScopedRegistry()` if the browser supports custom elements and
8242
- // ENABLE_SCOPED_CUSTOM_ELEMENT_REGISTRY is enabled, because we don't want to patch eagerly if the flag is disabled
8243
- // or we're in a legacy browser.
8244
- if (lwcRuntimeFlags.ENABLE_SCOPED_CUSTOM_ELEMENT_REGISTRY) {
8245
- if (hasCustomElements) {
8246
- // If ENABLE_SCOPED_CUSTOM_ELEMENT_REGISTRY is true, then we eagerly initialize the scoped registry.
8247
- // It's assumed that ENABLE_SCOPED_CUSTOM_ELEMENT_REGISTRY is set *before* LWC loads, and never changes.
8248
- //
8249
- // Why not lazily patch in `createCustomElement`? Well, this could lead to subtle bugs, e.g.:
8250
- //
8251
- // 1. LWC loads
8252
- // 2. `const Ctor = class extends HTMLElement {}`
8253
- // 3. `lwc.createElement(...)` // here we lazily patch
8254
- // 4. `customElements.define('x-foo', Ctor)` // throws error because class is bound to stale HTMLElement
8255
- //
8256
- // To reduce the risk of this, it's safer to patch the registry eagerly.
8257
- createScopedConstructor = createScopedRegistry();
8258
- // It's important to cache window.HTMLElement here. Otherwise, someone else could overwrite window.HTMLElement (e.g.
8259
- // another copy of the engine, or another scoping implementation) and we would get "Illegal constructor" errors
8260
- // because the HTMLElement prototypes are mixed up.
8261
- //
8262
- // The reason this happens is that the scoping implementation overwrites window.HTMLElement and expects to work
8263
- // with that version of HTMLElement. So if you load two copies of the scoping implementation in the same environment,
8264
- // the second one may accidentally grab window.HTMLElement from the first (when doing `class extends HTMLElement`).
8265
- // Caching avoids this problem.
8266
- CachedHTMLElement = window.HTMLElement;
8267
- }
8268
- }
8269
- // Creates a constructor that is intended to be used as the UserConstructor in a scoped (pivots) registry.
8270
- // In this case, the upgradeCallback only needs to be defined once because we create these on-demand,
8271
- // multiple times per tag name.
8272
- const createUserConstructor = (HTMLElementToExtend, upgradeCallback, connectedCallback, disconnectedCallback) => {
8273
- // TODO [#2972]: this class should expose observedAttributes as necessary
8274
- return class UserConstructor extends HTMLElementToExtend {
8275
- constructor() {
8276
- super();
8277
- upgradeCallback(this);
8278
- }
8279
- // Note that there is no need to do the "avoid defining connectedCallback/disconnectedCallback" optimization
8280
- // here, because in create-scoped-registry.ts, the registered class will always have these callbacks anyway.
8281
- // See: https://github.com/salesforce/lwc/pull/3162#issuecomment-1311851174
8282
- connectedCallback() {
8283
- if (!isUndefined$1(connectedCallback)) {
8284
- connectedCallback(this);
8285
- }
8286
- }
8287
- disconnectedCallback() {
8288
- if (!isUndefined$1(disconnectedCallback)) {
8289
- disconnectedCallback(this);
8290
- }
8291
- }
8292
- };
8293
- };
8294
- function createCustomElementScoped(tagName, upgradeCallback, connectedCallback, disconnectedCallback) {
8295
- if (isUndefined$1(createScopedConstructor) || isUndefined$1(CachedHTMLElement)) {
8296
- // This error should be impossible to hit
8297
- throw new Error('The flag ENABLE_SCOPED_CUSTOM_ELEMENT_REGISTRY must be set to true to use this feature');
8298
- }
8299
- const UserConstructor = createUserConstructor(CachedHTMLElement, upgradeCallback, connectedCallback, disconnectedCallback);
8300
- const ScopedConstructor = createScopedConstructor(tagName, UserConstructor);
8301
- return new ScopedConstructor(UserConstructor);
8302
- }
8303
-
8304
7917
  /*
8305
7918
  * Copyright (c) 2018, salesforce.com, inc.
8306
7919
  * All rights reserved.
@@ -8308,29 +7921,22 @@ function createCustomElementScoped(tagName, upgradeCallback, connectedCallback,
8308
7921
  * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
8309
7922
  */
8310
7923
  /**
8311
- * We have three modes for creating custom elements:
7924
+ * We have two modes for creating custom elements:
8312
7925
  *
8313
7926
  * 1. Compat (legacy) browser support (e.g. IE11). Totally custom, doesn't rely on native browser APIs.
8314
7927
  * 2. "Upgradable constructor" custom element. This allows us to have two LWC components with the same tag name,
8315
7928
  * via a trick: every custom element constructor we define in the registry is basically the same. It's essentially
8316
7929
  * a dummy `class extends HTMLElement` that accepts an `upgradeCallback` in its constructor ("upgradable
8317
7930
  * constructor"), which allows us to have completely customized functionality for different components.
8318
- * 3. "Scoped" (or "pivot") custom elements. This relies on a sophisticated system that emulates the "scoped custom
8319
- * elements registry" proposal, with support for avoiding conflicts in tag names both between LWC components and
8320
- * between LWC components and third-party elements. This uses a similar trick to #2, but is much more complex
8321
- * because it must patch the global `customElements` and `HTMLElement` objects.
8322
7931
  */
8323
7932
  let createCustomElement;
8324
7933
  if (hasCustomElements) {
8325
- if (lwcRuntimeFlags.ENABLE_SCOPED_CUSTOM_ELEMENT_REGISTRY) {
8326
- createCustomElement = createCustomElementScoped;
8327
- } else {
8328
7934
  // use the global registry, with an upgradable constructor for the defined custom element
8329
7935
  createCustomElement = createCustomElementUsingUpgradableConstructor;
8330
- }
8331
- } else {
8332
- // no registry available here
8333
- createCustomElement = createCustomElementCompat;
7936
+ }
7937
+ else {
7938
+ // no registry available here
7939
+ createCustomElement = createCustomElementCompat;
8334
7940
  }
8335
7941
 
8336
7942
  /*
@@ -8393,7 +7999,7 @@ function rendererFactory(baseRenderer) {
8393
7999
  function isNull(obj) {
8394
8000
  return obj === null;
8395
8001
  }
8396
- /** version: 2.35.2 */
8002
+ /** version: 2.37.0 */
8397
8003
 
8398
8004
  /*
8399
8005
  * Copyright (c) 2018, salesforce.com, inc.
@@ -8954,6 +8560,6 @@ defineProperty(LightningElement, 'CustomElementConstructor', {
8954
8560
  });
8955
8561
  freeze(LightningElement);
8956
8562
  seal(LightningElement.prototype);
8957
- /* version: 2.35.2 */
8563
+ /* version: 2.37.0 */
8958
8564
 
8959
8565
  export { LightningElement, profilerControl as __unstable__ProfilerControl, reportingControl as __unstable__ReportingControl, api$1 as api, deprecatedBuildCustomElementConstructor as buildCustomElementConstructor, createContextProvider, createElement, freezeTemplate, getComponentConstructor, getComponentDef, hydrateComponent, isComponentConstructor, isNodeShadowed as isNodeFromTemplate, parseFragment, parseSVGFragment, readonly, register, registerComponent, registerDecorators, registerTemplate, renderer, rendererFactory, sanitizeAttribute, setFeatureFlag, setFeatureFlagForTest, setHooks, swapComponent, swapStyle, swapTemplate, track, unwrap, wire };