lwc 2.34.0 → 2.35.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.
Files changed (39) hide show
  1. package/dist/engine-dom/esm/es2017/engine-dom.js +939 -763
  2. package/dist/engine-dom/iife/es2017/engine-dom.js +939 -762
  3. package/dist/engine-dom/iife/es2017/engine-dom.min.js +1 -1
  4. package/dist/engine-dom/iife/es2017/engine-dom_debug.js +846 -684
  5. package/dist/engine-dom/iife/es5/engine-dom.js +1115 -922
  6. package/dist/engine-dom/iife/es5/engine-dom.min.js +1 -1
  7. package/dist/engine-dom/iife/es5/engine-dom_debug.js +801 -619
  8. package/dist/engine-dom/umd/es2017/engine-dom.js +939 -762
  9. package/dist/engine-dom/umd/es2017/engine-dom.min.js +1 -1
  10. package/dist/engine-dom/umd/es2017/engine-dom_debug.js +846 -684
  11. package/dist/engine-dom/umd/es5/engine-dom.js +1115 -922
  12. package/dist/engine-dom/umd/es5/engine-dom.min.js +1 -1
  13. package/dist/engine-dom/umd/es5/engine-dom_debug.js +801 -619
  14. package/dist/engine-server/commonjs/es2017/engine-server.js +1025 -1082
  15. package/dist/engine-server/commonjs/es2017/engine-server.min.js +1 -1
  16. package/dist/engine-server/esm/es2017/engine-server.js +1025 -1082
  17. package/dist/synthetic-shadow/esm/es2017/synthetic-shadow.js +21 -41
  18. package/dist/synthetic-shadow/iife/es2017/synthetic-shadow.js +21 -41
  19. package/dist/synthetic-shadow/iife/es2017/synthetic-shadow.min.js +2 -2
  20. package/dist/synthetic-shadow/iife/es2017/synthetic-shadow_debug.js +20 -39
  21. package/dist/synthetic-shadow/iife/es5/synthetic-shadow.js +24 -38
  22. package/dist/synthetic-shadow/iife/es5/synthetic-shadow.min.js +2 -2
  23. package/dist/synthetic-shadow/iife/es5/synthetic-shadow_debug.js +23 -36
  24. package/dist/synthetic-shadow/umd/es2017/synthetic-shadow.js +21 -41
  25. package/dist/synthetic-shadow/umd/es2017/synthetic-shadow.min.js +2 -2
  26. package/dist/synthetic-shadow/umd/es2017/synthetic-shadow_debug.js +20 -39
  27. package/dist/synthetic-shadow/umd/es5/synthetic-shadow.js +24 -38
  28. package/dist/synthetic-shadow/umd/es5/synthetic-shadow.min.js +2 -2
  29. package/dist/synthetic-shadow/umd/es5/synthetic-shadow_debug.js +23 -36
  30. package/dist/wire-service/esm/es2017/wire-service.js +2 -2
  31. package/dist/wire-service/iife/es2017/wire-service.js +2 -2
  32. package/dist/wire-service/iife/es2017/wire-service_debug.js +2 -2
  33. package/dist/wire-service/iife/es5/wire-service.js +2 -2
  34. package/dist/wire-service/iife/es5/wire-service_debug.js +2 -2
  35. package/dist/wire-service/umd/es2017/wire-service.js +2 -2
  36. package/dist/wire-service/umd/es2017/wire-service_debug.js +2 -2
  37. package/dist/wire-service/umd/es5/wire-service.js +2 -2
  38. package/dist/wire-service/umd/es5/wire-service_debug.js +2 -2
  39. package/package.json +7 -7
@@ -48,7 +48,7 @@ var LWC = (function (exports) {
48
48
  const { isArray: isArray$1 } = Array;
49
49
  const { concat: ArrayConcat$1, copyWithin: ArrayCopyWithin, fill: ArrayFill, filter: ArrayFilter, find: ArrayFind, indexOf: ArrayIndexOf, join: ArrayJoin, map: ArrayMap, pop: ArrayPop, push: ArrayPush$1, reduce: ArrayReduce, reverse: ArrayReverse, shift: ArrayShift, slice: ArraySlice, some: ArraySome, sort: ArraySort, splice: ArraySplice, unshift: ArrayUnshift, forEach, } = Array.prototype;
50
50
  const { fromCharCode: StringFromCharCode } = String;
51
- const { charCodeAt: StringCharCodeAt, replace: StringReplace, slice: StringSlice, toLowerCase: StringToLowerCase, } = String.prototype;
51
+ const { charCodeAt: StringCharCodeAt, replace: StringReplace, split: StringSplit, slice: StringSlice, toLowerCase: StringToLowerCase, } = String.prototype;
52
52
  function isUndefined$1(obj) {
53
53
  return obj === undefined;
54
54
  }
@@ -185,6 +185,19 @@ var LWC = (function (exports) {
185
185
  });
186
186
  return { AriaAttrNameToPropNameMap, AriaPropNameToAttrNameMap };
187
187
  })();
188
+ // These attributes take either an ID or a list of IDs as values.
189
+ // This includes aria-* attributes as well as the special non-ARIA "for" attribute
190
+ const ID_REFERENCING_ATTRIBUTES_SET = new Set([
191
+ 'aria-activedescendant',
192
+ 'aria-controls',
193
+ 'aria-describedby',
194
+ 'aria-details',
195
+ 'aria-errormessage',
196
+ 'aria-flowto',
197
+ 'aria-labelledby',
198
+ 'aria-owns',
199
+ 'for',
200
+ ]);
188
201
 
189
202
  /*
190
203
  * Copyright (c) 2018, salesforce.com, inc.
@@ -192,41 +205,11 @@ var LWC = (function (exports) {
192
205
  * SPDX-License-Identifier: MIT
193
206
  * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
194
207
  */
195
- // Inspired from: https://mathiasbynens.be/notes/globalthis
196
- const _globalThis = /*@__PURE__*/ (function () {
197
- // On recent browsers, `globalThis` is already defined. In this case return it directly.
198
- if (typeof globalThis === 'object') {
199
- return globalThis;
200
- }
201
- let _globalThis;
202
- try {
203
- // eslint-disable-next-line no-extend-native
204
- Object.defineProperty(Object.prototype, '__magic__', {
205
- get: function () {
206
- return this;
207
- },
208
- configurable: true,
209
- });
210
- // __magic__ is undefined in Safari 10 and IE10 and older.
211
- // @ts-ignore
212
- // eslint-disable-next-line no-undef
213
- _globalThis = __magic__;
214
- // @ts-ignore
215
- delete Object.prototype.__magic__;
216
- }
217
- catch (ex) {
218
- // In IE8, Object.defineProperty only works on DOM objects.
219
- }
220
- finally {
221
- // If the magic above fails for some reason we assume that we are in a legacy browser.
222
- // Assume `window` exists in this case.
223
- if (typeof _globalThis === 'undefined') {
224
- // @ts-ignore
225
- _globalThis = window;
226
- }
227
- }
228
- return _globalThis;
229
- })();
208
+ // See browser support for globalThis:
209
+ // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/globalThis#browser_compatibility
210
+ /* istanbul ignore next */
211
+ // @ts-ignore
212
+ const _globalThis = typeof globalThis === 'object' ? globalThis : window;
230
213
 
231
214
  /*
232
215
  * Copyright (c) 2018, salesforce.com, inc.
@@ -240,6 +223,8 @@ var LWC = (function (exports) {
240
223
  const KEY__SHADOW_TOKEN = '$shadowToken$';
241
224
  const KEY__SYNTHETIC_MODE = '$$lwc-synthetic-mode';
242
225
  const KEY__SCOPED_CSS = '$scoped$';
226
+ const KEY__NATIVE_GET_ELEMENT_BY_ID = '$nativeGetElementById$';
227
+ const KEY__NATIVE_QUERY_SELECTOR_ALL = '$nativeQuerySelectorAll$';
243
228
  const XML_NAMESPACE = 'http://www.w3.org/XML/1998/namespace';
244
229
  const SVG_NAMESPACE = 'http://www.w3.org/2000/svg';
245
230
  const XLINK_NAMESPACE = 'http://www.w3.org/1999/xlink';
@@ -347,9 +332,9 @@ var LWC = (function (exports) {
347
332
  * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
348
333
  */
349
334
  // Increment whenever the LWC template compiler changes
350
- const LWC_VERSION = "2.34.0";
335
+ const LWC_VERSION = "2.35.1";
351
336
  const LWC_VERSION_COMMENT_REGEX = /\/\*LWC compiler v([\d.]+)\*\/\s*}/;
352
- /** version: 2.34.0 */
337
+ /** version: 2.35.1 */
353
338
 
354
339
  /**
355
340
  * Copyright (C) 2018 salesforce.com, inc.
@@ -402,7 +387,8 @@ var LWC = (function (exports) {
402
387
  console.warn(`Failed to set the value "${value}" for the runtime feature flag "${name}" because it is undefined. Available flags: ${availableFlags}.`);
403
388
  return;
404
389
  }
405
- if (process.env.NODE_ENV !== 'production') {
390
+ // This may seem redundant, but `process.env.NODE_ENV === 'test-karma-lwc'` is replaced by Karma tests
391
+ if (process.env.NODE_ENV === 'test-karma-lwc' || process.env.NODE_ENV !== 'production') {
406
392
  // Allow the same flag to be set more than once outside of production to enable testing
407
393
  lwcRuntimeFlags[name] = value;
408
394
  }
@@ -422,11 +408,12 @@ var LWC = (function (exports) {
422
408
  * purposes. It is a no-op when invoked in production mode.
423
409
  */
424
410
  function setFeatureFlagForTest(name, value) {
425
- if (process.env.NODE_ENV !== 'production') {
411
+ // This may seem redundant, but `process.env.NODE_ENV === 'test-karma-lwc'` is replaced by Karma tests
412
+ if (process.env.NODE_ENV === 'test-karma-lwc' || process.env.NODE_ENV !== 'production') {
426
413
  setFeatureFlag(name, value);
427
414
  }
428
415
  }
429
- /** version: 2.34.0 */
416
+ /** version: 2.35.1 */
430
417
 
431
418
  /**
432
419
  * Copyright (C) 2018 salesforce.com, inc.
@@ -490,7 +477,7 @@ var LWC = (function (exports) {
490
477
  }
491
478
  }
492
479
  }
493
- /** version: 2.34.0 */
480
+ /** version: 2.35.1 */
494
481
 
495
482
  /*
496
483
  * Copyright (c) 2018, salesforce.com, inc.
@@ -511,8 +498,7 @@ var LWC = (function (exports) {
511
498
  * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
512
499
  */
513
500
  // Only used in LWC's Karma tests
514
- // @ts-ignore
515
- if (process.env.NODE_ENV !== 'production' && typeof __karma__ !== 'undefined') {
501
+ if (process.env.NODE_ENV === 'test-karma-lwc') {
516
502
  window.addEventListener('test-dummy-flag', () => {
517
503
  let hasFlag = false;
518
504
  if (lwcRuntimeFlags.DUMMY_TEST_FLAG) {
@@ -536,8 +522,7 @@ var LWC = (function (exports) {
536
522
  * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
537
523
  */
538
524
  // Only used in LWC's Karma tests
539
- // @ts-ignore
540
- if (process.env.NODE_ENV !== 'production' && typeof __karma__ !== 'undefined') {
525
+ if (process.env.NODE_ENV === 'test-karma-lwc') {
541
526
  window.addEventListener('test-dummy-flag', () => {
542
527
  let hasFlag = false;
543
528
  if (lwcRuntimeFlags.DUMMY_TEST_FLAG) {
@@ -558,94 +543,167 @@ var LWC = (function (exports) {
558
543
  * SPDX-License-Identifier: MIT
559
544
  * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
560
545
  */
561
- let nextTickCallbackQueue = [];
562
- const SPACE_CHAR = 32;
563
- const EmptyObject = seal(create(null));
564
- const EmptyArray = seal([]);
565
- function flushCallbackQueue() {
566
- if (process.env.NODE_ENV !== 'production') {
567
- if (nextTickCallbackQueue.length === 0) {
568
- throw new Error(`Internal Error: If callbackQueue is scheduled, it is because there must be at least one callback on this pending queue.`);
546
+ /** Callbacks to invoke when reporting is enabled **/
547
+ const onReportingEnabledCallbacks = [];
548
+ /** The currently assigned reporting dispatcher. */
549
+ let currentDispatcher$1 = noop;
550
+ /**
551
+ * Whether reporting is enabled.
552
+ *
553
+ * Note that this may seem redundant, given you can just check if the currentDispatcher is undefined,
554
+ * but it turns out that Terser only strips out unused code if we use this explicit boolean.
555
+ */
556
+ let enabled$1 = false;
557
+ const reportingControl = {
558
+ /**
559
+ * Attach a new reporting control (aka dispatcher).
560
+ *
561
+ * @param dispatcher - reporting control
562
+ */
563
+ attachDispatcher(dispatcher) {
564
+ enabled$1 = true;
565
+ currentDispatcher$1 = dispatcher;
566
+ for (const callback of onReportingEnabledCallbacks) {
567
+ try {
568
+ callback();
569
+ }
570
+ catch (err) {
571
+ // This should never happen. But if it does, we don't want one callback to cause another to fail
572
+ // eslint-disable-next-line no-console
573
+ console.error('Could not invoke callback', err);
574
+ }
569
575
  }
576
+ onReportingEnabledCallbacks.length = 0; // clear the array
577
+ },
578
+ /**
579
+ * Detach the current reporting control (aka dispatcher).
580
+ */
581
+ detachDispatcher() {
582
+ enabled$1 = false;
583
+ currentDispatcher$1 = noop;
584
+ },
585
+ };
586
+ /**
587
+ * Call a callback when reporting is enabled, or immediately if reporting is already enabled.
588
+ * Will only ever be called once.
589
+ * @param callback
590
+ */
591
+ function onReportingEnabled(callback) {
592
+ if (enabled$1) {
593
+ // call immediately
594
+ callback();
570
595
  }
571
- const callbacks = nextTickCallbackQueue;
572
- nextTickCallbackQueue = []; // reset to a new queue
573
- for (let i = 0, len = callbacks.length; i < len; i += 1) {
574
- callbacks[i]();
596
+ else {
597
+ // call later
598
+ onReportingEnabledCallbacks.push(callback);
575
599
  }
576
600
  }
577
- function addCallbackToNextTick(callback) {
578
- if (process.env.NODE_ENV !== 'production') {
579
- if (!isFunction$1(callback)) {
580
- throw new Error(`Internal Error: addCallbackToNextTick() can only accept a function callback`);
581
- }
582
- }
583
- if (nextTickCallbackQueue.length === 0) {
584
- Promise.resolve().then(flushCallbackQueue);
601
+ /**
602
+ * Report to the current dispatcher, if there is one.
603
+ * @param reportingEventId
604
+ * @param vm
605
+ */
606
+ function report(reportingEventId, vm) {
607
+ if (enabled$1) {
608
+ currentDispatcher$1(reportingEventId, vm.tagName, vm.idx);
585
609
  }
586
- ArrayPush$1.call(nextTickCallbackQueue, callback);
587
610
  }
588
- function guid() {
589
- function s4() {
590
- return Math.floor((1 + Math.random()) * 0x10000)
591
- .toString(16)
592
- .substring(1);
611
+
612
+ /*
613
+ * Copyright (c) 2018, salesforce.com, inc.
614
+ * All rights reserved.
615
+ * SPDX-License-Identifier: MIT
616
+ * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
617
+ */
618
+ function getComponentTag(vm) {
619
+ return `<${StringToLowerCase.call(vm.tagName)}>`;
620
+ }
621
+ // TODO [#1695]: Unify getComponentStack and getErrorComponentStack
622
+ function getComponentStack(vm) {
623
+ const stack = [];
624
+ let prefix = '';
625
+ while (!isNull(vm.owner)) {
626
+ ArrayPush$1.call(stack, prefix + getComponentTag(vm));
627
+ vm = vm.owner;
628
+ prefix += '\t';
593
629
  }
594
- return s4() + s4() + '-' + s4() + '-' + s4() + '-' + s4() + '-' + s4() + s4() + s4();
630
+ return ArrayJoin.call(stack, '\n');
595
631
  }
596
- // Borrowed from Vue template compiler.
597
- // https://github.com/vuejs/vue/blob/531371b818b0e31a989a06df43789728f23dc4e8/src/platforms/web/util/style.js#L5-L16
598
- const DECLARATION_DELIMITER = /;(?![^(]*\))/g;
599
- const PROPERTY_DELIMITER = /:(.+)/;
600
- function parseStyleText(cssText) {
601
- const styleMap = {};
602
- const declarations = cssText.split(DECLARATION_DELIMITER);
603
- for (const declaration of declarations) {
604
- if (declaration) {
605
- const [prop, value] = declaration.split(PROPERTY_DELIMITER);
606
- if (prop !== undefined && value !== undefined) {
607
- styleMap[prop.trim()] = value.trim();
608
- }
609
- }
632
+ function getErrorComponentStack(vm) {
633
+ const wcStack = [];
634
+ let currentVm = vm;
635
+ while (!isNull(currentVm)) {
636
+ ArrayPush$1.call(wcStack, getComponentTag(currentVm));
637
+ currentVm = currentVm.owner;
610
638
  }
611
- return styleMap;
639
+ return wcStack.reverse().join('\n\t');
612
640
  }
613
- // Make a shallow copy of an object but omit the given key
614
- function cloneAndOmitKey(object, keyToOmit) {
615
- const result = {};
616
- for (const key of Object.keys(object)) {
617
- if (key !== keyToOmit) {
618
- result[key] = object[key];
619
- }
641
+
642
+ /*
643
+ * Copyright (c) 2018, salesforce.com, inc.
644
+ * All rights reserved.
645
+ * SPDX-License-Identifier: MIT
646
+ * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
647
+ */
648
+ function addErrorComponentStack(vm, error) {
649
+ if (!isFrozen(error) && isUndefined$1(error.wcStack)) {
650
+ const wcStack = getErrorComponentStack(vm);
651
+ defineProperty(error, 'wcStack', {
652
+ get() {
653
+ return wcStack;
654
+ },
655
+ });
620
656
  }
621
- return result;
622
657
  }
623
- function flattenStylesheets(stylesheets) {
624
- const list = [];
625
- for (const stylesheet of stylesheets) {
626
- if (!Array.isArray(stylesheet)) {
627
- list.push(stylesheet);
628
- }
629
- else {
630
- list.push(...flattenStylesheets(stylesheet));
658
+
659
+ /*
660
+ * Copyright (c) 2018, salesforce.com, inc.
661
+ * All rights reserved.
662
+ * SPDX-License-Identifier: MIT
663
+ * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
664
+ */
665
+ const alreadyLoggedMessages = new Set();
666
+ // Only used in LWC's Karma tests
667
+ if (process.env.NODE_ENV === 'test-karma-lwc') {
668
+ // @ts-ignore
669
+ window.__lwcResetAlreadyLoggedMessages = () => {
670
+ alreadyLoggedMessages.clear();
671
+ };
672
+ }
673
+ function log(method, message, vm, once) {
674
+ let msg = `[LWC ${method}]: ${message}`;
675
+ if (!isUndefined$1(vm)) {
676
+ msg = `${msg}\n${getComponentStack(vm)}`;
677
+ }
678
+ if (once) {
679
+ if (alreadyLoggedMessages.has(msg)) {
680
+ return;
631
681
  }
682
+ alreadyLoggedMessages.add(msg);
632
683
  }
633
- return list;
634
- }
635
- // Set a ref (lwc:ref) on a VM, from a template API
636
- function setRefVNode(vm, ref, vnode) {
637
- if (process.env.NODE_ENV !== 'production' && isUndefined$1(vm.refVNodes)) {
638
- throw new Error('refVNodes must be defined when setting a ref');
684
+ // In Jest tests, reduce the warning and error verbosity by not printing the callstack
685
+ if (process.env.NODE_ENV === 'test') {
686
+ /* eslint-disable-next-line no-console */
687
+ console[method](msg);
688
+ return;
639
689
  }
640
- // If this method is called, then vm.refVNodes is set as the template has refs.
641
- // If not, then something went wrong and we threw an error above.
642
- const refVNodes = vm.refVNodes;
643
- // In cases of conflict (two elements with the same ref), prefer, the last one,
644
- // in depth-first traversal order.
645
- if (!(ref in refVNodes) || refVNodes[ref].key < vnode.key) {
646
- refVNodes[ref] = vnode;
690
+ try {
691
+ throw new Error(msg);
692
+ }
693
+ catch (e) {
694
+ /* eslint-disable-next-line no-console */
695
+ console[method](e);
647
696
  }
648
697
  }
698
+ function logError(message, vm) {
699
+ log('error', message, vm, false);
700
+ }
701
+ function logWarn(message, vm) {
702
+ log('warn', message, vm, false);
703
+ }
704
+ function logWarnOnce(message, vm) {
705
+ log('warn', message, vm, true);
706
+ }
649
707
 
650
708
  /*
651
709
  * Copyright (c) 2019, salesforce.com, inc.
@@ -767,77 +825,101 @@ var LWC = (function (exports) {
767
825
  * SPDX-License-Identifier: MIT
768
826
  * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
769
827
  */
770
- function getComponentTag(vm) {
771
- return `<${StringToLowerCase.call(vm.tagName)}>`;
772
- }
773
- // TODO [#1695]: Unify getComponentStack and getErrorComponentStack
774
- function getComponentStack(vm) {
775
- const stack = [];
776
- let prefix = '';
777
- while (!isNull(vm.owner)) {
778
- ArrayPush$1.call(stack, prefix + getComponentTag(vm));
779
- vm = vm.owner;
780
- prefix += '\t';
828
+ let nextTickCallbackQueue = [];
829
+ const SPACE_CHAR = 32;
830
+ const EmptyObject = seal(create(null));
831
+ const EmptyArray = seal([]);
832
+ function flushCallbackQueue() {
833
+ if (process.env.NODE_ENV !== 'production') {
834
+ if (nextTickCallbackQueue.length === 0) {
835
+ throw new Error(`Internal Error: If callbackQueue is scheduled, it is because there must be at least one callback on this pending queue.`);
836
+ }
781
837
  }
782
- return ArrayJoin.call(stack, '\n');
783
- }
784
- function getErrorComponentStack(vm) {
785
- const wcStack = [];
786
- let currentVm = vm;
787
- while (!isNull(currentVm)) {
788
- ArrayPush$1.call(wcStack, getComponentTag(currentVm));
789
- currentVm = currentVm.owner;
838
+ const callbacks = nextTickCallbackQueue;
839
+ nextTickCallbackQueue = []; // reset to a new queue
840
+ for (let i = 0, len = callbacks.length; i < len; i += 1) {
841
+ callbacks[i]();
790
842
  }
791
- return wcStack.reverse().join('\n\t');
792
843
  }
793
-
794
- /*
795
- * Copyright (c) 2018, salesforce.com, inc.
796
- * All rights reserved.
797
- * SPDX-License-Identifier: MIT
798
- * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
799
- */
800
- function addErrorComponentStack(vm, error) {
801
- if (!isFrozen(error) && isUndefined$1(error.wcStack)) {
802
- const wcStack = getErrorComponentStack(vm);
803
- defineProperty(error, 'wcStack', {
804
- get() {
805
- return wcStack;
806
- },
807
- });
844
+ function addCallbackToNextTick(callback) {
845
+ if (process.env.NODE_ENV !== 'production') {
846
+ if (!isFunction$1(callback)) {
847
+ throw new Error(`Internal Error: addCallbackToNextTick() can only accept a function callback`);
848
+ }
849
+ }
850
+ if (nextTickCallbackQueue.length === 0) {
851
+ Promise.resolve().then(flushCallbackQueue);
808
852
  }
853
+ ArrayPush$1.call(nextTickCallbackQueue, callback);
809
854
  }
810
-
811
- /*
812
- * Copyright (c) 2018, salesforce.com, inc.
813
- * All rights reserved.
814
- * SPDX-License-Identifier: MIT
815
- * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
816
- */
817
- function log(method, message, vm) {
818
- let msg = `[LWC ${method}]: ${message}`;
819
- if (!isUndefined$1(vm)) {
820
- msg = `${msg}\n${getComponentStack(vm)}`;
855
+ function guid() {
856
+ function s4() {
857
+ return Math.floor((1 + Math.random()) * 0x10000)
858
+ .toString(16)
859
+ .substring(1);
821
860
  }
822
- // In Jest tests, reduce the warning and error verbosity by not printing the callstack
823
- if (process.env.NODE_ENV === 'test') {
824
- /* eslint-disable-next-line no-console */
825
- console[method](msg);
826
- return;
861
+ return s4() + s4() + '-' + s4() + '-' + s4() + '-' + s4() + '-' + s4() + s4() + s4();
862
+ }
863
+ // Borrowed from Vue template compiler.
864
+ // https://github.com/vuejs/vue/blob/531371b818b0e31a989a06df43789728f23dc4e8/src/platforms/web/util/style.js#L5-L16
865
+ const DECLARATION_DELIMITER = /;(?![^(]*\))/g;
866
+ const PROPERTY_DELIMITER = /:(.+)/;
867
+ function parseStyleText(cssText) {
868
+ const styleMap = {};
869
+ const declarations = cssText.split(DECLARATION_DELIMITER);
870
+ for (const declaration of declarations) {
871
+ if (declaration) {
872
+ const [prop, value] = declaration.split(PROPERTY_DELIMITER);
873
+ if (prop !== undefined && value !== undefined) {
874
+ styleMap[prop.trim()] = value.trim();
875
+ }
876
+ }
827
877
  }
828
- try {
829
- throw new Error(msg);
878
+ return styleMap;
879
+ }
880
+ // Make a shallow copy of an object but omit the given key
881
+ function cloneAndOmitKey(object, keyToOmit) {
882
+ const result = {};
883
+ for (const key of Object.keys(object)) {
884
+ if (key !== keyToOmit) {
885
+ result[key] = object[key];
886
+ }
830
887
  }
831
- catch (e) {
832
- /* eslint-disable-next-line no-console */
833
- console[method](e);
888
+ return result;
889
+ }
890
+ function flattenStylesheets(stylesheets) {
891
+ const list = [];
892
+ for (const stylesheet of stylesheets) {
893
+ if (!Array.isArray(stylesheet)) {
894
+ list.push(stylesheet);
895
+ }
896
+ else {
897
+ list.push(...flattenStylesheets(stylesheet));
898
+ }
834
899
  }
900
+ return list;
835
901
  }
836
- function logError(message, vm) {
837
- log('error', message, vm);
902
+ // Set a ref (lwc:ref) on a VM, from a template API
903
+ function setRefVNode(vm, ref, vnode) {
904
+ if (process.env.NODE_ENV !== 'production' && isUndefined$1(vm.refVNodes)) {
905
+ throw new Error('refVNodes must be defined when setting a ref');
906
+ }
907
+ // If this method is called, then vm.refVNodes is set as the template has refs.
908
+ // If not, then something went wrong and we threw an error above.
909
+ const refVNodes = vm.refVNodes;
910
+ // In cases of conflict (two elements with the same ref), prefer, the last one,
911
+ // in depth-first traversal order.
912
+ if (!(ref in refVNodes) || refVNodes[ref].key < vnode.key) {
913
+ refVNodes[ref] = vnode;
914
+ }
838
915
  }
839
- function logWarn(message, vm) {
840
- log('warn', message, vm);
916
+ // Throw an error if we're running in prod mode. Ensures code is truly removed from prod mode.
917
+ function assertNotProd() {
918
+ /* istanbul ignore if */
919
+ if (process.env.NODE_ENV === 'production') {
920
+ // this method should never leak to prod
921
+ throw new ReferenceError();
922
+ }
841
923
  }
842
924
 
843
925
  /*
@@ -892,7 +974,7 @@ var LWC = (function (exports) {
892
974
  //
893
975
  // If you update this list, check for test files that recapitulate the same list. Searching the codebase
894
976
  // for e.g. "dropzone" should suffice.
895
- const globalHTMLProperties = assign(create(null), {
977
+ const globalHTMLProperties = {
896
978
  accessKey: {
897
979
  attribute: 'accesskey',
898
980
  },
@@ -977,7 +1059,7 @@ var LWC = (function (exports) {
977
1059
  role: {
978
1060
  attribute: 'role',
979
1061
  },
980
- });
1062
+ };
981
1063
  let controlledElement = null;
982
1064
  let controlledAttributeName;
983
1065
  function isAttributeLocked(elm, attrName) {
@@ -1044,27 +1126,18 @@ var LWC = (function (exports) {
1044
1126
  }
1045
1127
  let isDomMutationAllowed = false;
1046
1128
  function unlockDomMutation() {
1047
- if (process.env.NODE_ENV === 'production') {
1048
- // this method should never leak to prod
1049
- throw new ReferenceError();
1050
- }
1129
+ assertNotProd(); // this method should never leak to prod
1051
1130
  isDomMutationAllowed = true;
1052
1131
  }
1053
1132
  function lockDomMutation() {
1054
- if (process.env.NODE_ENV === 'production') {
1055
- // this method should never leak to prod
1056
- throw new ReferenceError();
1057
- }
1133
+ assertNotProd(); // this method should never leak to prod
1058
1134
  isDomMutationAllowed = false;
1059
1135
  }
1060
1136
  function logMissingPortalError(name, type) {
1061
1137
  return logError(`The \`${name}\` ${type} is available only on elements that use the \`lwc:dom="manual"\` directive.`);
1062
1138
  }
1063
1139
  function patchElementWithRestrictions(elm, options) {
1064
- if (process.env.NODE_ENV === 'production') {
1065
- // this method should never leak to prod
1066
- throw new ReferenceError();
1067
- }
1140
+ assertNotProd(); // this method should never leak to prod
1068
1141
  const originalOuterHTMLDescriptor = getPropertyDescriptor(elm, 'outerHTML');
1069
1142
  const descriptors = {
1070
1143
  outerHTML: generateAccessorDescriptor({
@@ -1145,10 +1218,7 @@ var LWC = (function (exports) {
1145
1218
  defineProperties(elm, descriptors);
1146
1219
  }
1147
1220
  function getShadowRootRestrictionsDescriptors(sr) {
1148
- if (process.env.NODE_ENV === 'production') {
1149
- // this method should never leak to prod
1150
- throw new ReferenceError();
1151
- }
1221
+ assertNotProd(); // this method should never leak to prod
1152
1222
  // Disallowing properties in dev mode only to avoid people doing the wrong
1153
1223
  // thing when using the real shadow root, because if that's the case,
1154
1224
  // the component will not work when running with synthetic shadow.
@@ -1189,10 +1259,7 @@ var LWC = (function (exports) {
1189
1259
  // Custom Elements Restrictions:
1190
1260
  // -----------------------------
1191
1261
  function getCustomElementRestrictionsDescriptors(elm) {
1192
- if (process.env.NODE_ENV === 'production') {
1193
- // this method should never leak to prod
1194
- throw new ReferenceError();
1195
- }
1262
+ assertNotProd(); // this method should never leak to prod
1196
1263
  const originalAddEventListener = elm.addEventListener;
1197
1264
  const originalInnerHTMLDescriptor = getPropertyDescriptor(elm, 'innerHTML');
1198
1265
  const originalOuterHTMLDescriptor = getPropertyDescriptor(elm, 'outerHTML');
@@ -1237,10 +1304,7 @@ var LWC = (function (exports) {
1237
1304
  };
1238
1305
  }
1239
1306
  function getComponentRestrictionsDescriptors() {
1240
- if (process.env.NODE_ENV === 'production') {
1241
- // this method should never leak to prod
1242
- throw new ReferenceError();
1243
- }
1307
+ assertNotProd(); // this method should never leak to prod
1244
1308
  return {
1245
1309
  tagName: generateAccessorDescriptor({
1246
1310
  get() {
@@ -1254,10 +1318,7 @@ var LWC = (function (exports) {
1254
1318
  };
1255
1319
  }
1256
1320
  function getLightningElementPrototypeRestrictionsDescriptors(proto) {
1257
- if (process.env.NODE_ENV === 'production') {
1258
- // this method should never leak to prod
1259
- throw new ReferenceError();
1260
- }
1321
+ assertNotProd(); // this method should never leak to prod
1261
1322
  const originalDispatchEvent = proto.dispatchEvent;
1262
1323
  const descriptors = {
1263
1324
  dispatchEvent: generateDataDescriptor({
@@ -1971,7 +2032,6 @@ var LWC = (function (exports) {
1971
2032
  }
1972
2033
  };
1973
2034
  }
1974
- const EMPTY_REFS = freeze(create(null));
1975
2035
  const refsCache = new WeakMap();
1976
2036
  /**
1977
2037
  * This class is the base class for any LWC element.
@@ -2259,7 +2319,6 @@ var LWC = (function (exports) {
2259
2319
  }
2260
2320
  const {
2261
2321
  refVNodes,
2262
- hasRefVNodes,
2263
2322
  cmpTemplate
2264
2323
  } = vm;
2265
2324
  // If the `cmpTemplate` is null, that means that the template has not been rendered yet. Most likely this occurs
@@ -2273,15 +2332,9 @@ var LWC = (function (exports) {
2273
2332
  // were introduced, we return undefined if the template has no refs defined
2274
2333
  // anywhere. This fixes components that may want to add an expando called `refs`
2275
2334
  // and are checking if it exists with `if (this.refs)` before adding it.
2276
- // Note it is not sufficient to just check if `refVNodes` is null or empty,
2277
- // because a template may have `lwc:ref` defined within a falsy `if:true` block.
2278
- if (!hasRefVNodes) {
2279
- return;
2280
- }
2281
- // For templates that are using `lwc:ref`, if there are no refs currently available
2282
- // (e.g. refs inside of a falsy `if:true` block), we return an empty object.
2335
+ // Note we use a null refVNodes to indicate that the template has no refs defined.
2283
2336
  if (isNull(refVNodes)) {
2284
- return EMPTY_REFS;
2337
+ return;
2285
2338
  }
2286
2339
  // The refNodes can be cached based on the refVNodes, since the refVNodes
2287
2340
  // are recreated from scratch every time the template is rendered.
@@ -2439,109 +2492,286 @@ var LWC = (function (exports) {
2439
2492
  * SPDX-License-Identifier: MIT
2440
2493
  * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
2441
2494
  */
2442
- function api$1() {
2443
- if (process.env.NODE_ENV !== 'production') {
2444
- assert.fail(`@api decorator can only be used as a decorator function.`);
2445
- }
2446
- throw new Error();
2495
+ const DeprecatedWiredElementHost = '$$DeprecatedWiredElementHostKey$$';
2496
+ const DeprecatedWiredParamsMeta = '$$DeprecatedWiredParamsMetaKey$$';
2497
+ const WIRE_DEBUG_ENTRY = '@wire';
2498
+ const WireMetaMap = new Map();
2499
+ class WireContextRegistrationEvent extends CustomEvent {
2500
+ constructor(adapterToken, {
2501
+ setNewContext,
2502
+ setDisconnectedCallback
2503
+ }) {
2504
+ super(adapterToken, {
2505
+ bubbles: true,
2506
+ composed: true
2507
+ });
2508
+ defineProperties(this, {
2509
+ setNewContext: {
2510
+ value: setNewContext
2511
+ },
2512
+ setDisconnectedCallback: {
2513
+ value: setDisconnectedCallback
2514
+ }
2515
+ });
2516
+ }
2447
2517
  }
2448
- function createPublicPropertyDescriptor(key) {
2449
- return {
2450
- get() {
2451
- const vm = getAssociatedVM(this);
2452
- if (isBeingConstructed(vm)) {
2453
- if (process.env.NODE_ENV !== 'production') {
2454
- logError(`Can’t read the value of property \`${toString$1(key)}\` from the constructor because the owner component hasn’t set the value yet. Instead, use the constructor to set a default value for the property.`, vm);
2455
- }
2456
- return;
2457
- }
2458
- componentValueObserved(vm, key);
2459
- return vm.cmpProps[key];
2460
- },
2461
- set(newValue) {
2462
- const vm = getAssociatedVM(this);
2463
- if (process.env.NODE_ENV !== 'production') {
2464
- const vmBeingRendered = getVMBeingRendered();
2465
- assert.invariant(!isInvokingRender, `${vmBeingRendered}.render() method has side effects on the state of ${vm}.${toString$1(key)}`);
2466
- assert.invariant(!isUpdatingTemplate, `Updating the template of ${vmBeingRendered} has side effects on the state of ${vm}.${toString$1(key)}`);
2467
- }
2468
- vm.cmpProps[key] = newValue;
2469
- componentValueMutated(vm, key);
2470
- },
2471
- enumerable: true,
2472
- configurable: true,
2473
- };
2518
+ function createFieldDataCallback(vm, name) {
2519
+ return value => {
2520
+ updateComponentValue(vm, name, value);
2521
+ };
2474
2522
  }
2475
- function createPublicAccessorDescriptor(key, descriptor) {
2476
- const { get, set, enumerable, configurable } = descriptor;
2477
- if (!isFunction$1(get)) {
2478
- if (process.env.NODE_ENV !== 'production') {
2479
- assert.invariant(isFunction$1(get), `Invalid compiler output for public accessor ${toString$1(key)} decorated with @api`);
2480
- }
2481
- throw new Error();
2523
+ function createMethodDataCallback(vm, method) {
2524
+ return value => {
2525
+ // dispatching new value into the wired method
2526
+ runWithBoundaryProtection(vm, vm.owner, noop, () => {
2527
+ // job
2528
+ method.call(vm.component, value);
2529
+ }, noop);
2530
+ };
2531
+ }
2532
+ function createConfigWatcher(component, configCallback, callbackWhenConfigIsReady) {
2533
+ let hasPendingConfig = false;
2534
+ // creating the reactive observer for reactive params when needed
2535
+ const ro = createReactiveObserver(() => {
2536
+ if (hasPendingConfig === false) {
2537
+ hasPendingConfig = true;
2538
+ // collect new config in the micro-task
2539
+ Promise.resolve().then(() => {
2540
+ hasPendingConfig = false;
2541
+ // resetting current reactive params
2542
+ ro.reset();
2543
+ // dispatching a new config due to a change in the configuration
2544
+ computeConfigAndUpdate();
2545
+ });
2482
2546
  }
2483
- return {
2484
- get() {
2485
- if (process.env.NODE_ENV !== 'production') {
2486
- // Assert that the this value is an actual Component with an associated VM.
2487
- getAssociatedVM(this);
2488
- }
2489
- return get.call(this);
2490
- },
2491
- set(newValue) {
2492
- const vm = getAssociatedVM(this);
2493
- if (process.env.NODE_ENV !== 'production') {
2494
- const vmBeingRendered = getVMBeingRendered();
2495
- assert.invariant(!isInvokingRender, `${vmBeingRendered}.render() method has side effects on the state of ${vm}.${toString$1(key)}`);
2496
- assert.invariant(!isUpdatingTemplate, `Updating the template of ${vmBeingRendered} has side effects on the state of ${vm}.${toString$1(key)}`);
2497
- }
2498
- if (set) {
2499
- set.call(this, newValue);
2500
- }
2501
- else if (process.env.NODE_ENV !== 'production') {
2502
- assert.fail(`Invalid attempt to set a new value for property ${toString$1(key)} of ${vm} that does not has a setter decorated with @api.`);
2503
- }
2504
- },
2505
- enumerable,
2506
- configurable,
2507
- };
2547
+ });
2548
+ const computeConfigAndUpdate = () => {
2549
+ let config;
2550
+ ro.observe(() => config = configCallback(component));
2551
+ // eslint-disable-next-line @lwc/lwc-internal/no-invalid-todo
2552
+ // TODO: dev-mode validation of config based on the adapter.configSchema
2553
+ // @ts-ignore it is assigned in the observe() callback
2554
+ callbackWhenConfigIsReady(config);
2555
+ };
2556
+ return {
2557
+ computeConfigAndUpdate,
2558
+ ro
2559
+ };
2508
2560
  }
2561
+ function createContextWatcher(vm, wireDef, callbackWhenContextIsReady) {
2562
+ const {
2563
+ adapter
2564
+ } = wireDef;
2565
+ const adapterContextToken = getAdapterToken(adapter);
2566
+ if (isUndefined$1(adapterContextToken)) {
2567
+ return; // no provider found, nothing to be done
2568
+ }
2509
2569
 
2510
- /*
2511
- * Copyright (c) 2018, salesforce.com, inc.
2512
- * All rights reserved.
2513
- * SPDX-License-Identifier: MIT
2514
- * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
2515
- */
2516
- function track(target) {
2517
- if (arguments.length === 1) {
2518
- return getReactiveProxy(target);
2519
- }
2520
- if (process.env.NODE_ENV !== 'production') {
2521
- assert.fail(`@track decorator can only be used with one argument to return a trackable object, or as a decorator function.`);
2570
+ const {
2571
+ elm,
2572
+ context: {
2573
+ wiredConnecting,
2574
+ wiredDisconnecting
2575
+ },
2576
+ renderer: {
2577
+ dispatchEvent
2522
2578
  }
2523
- throw new Error();
2524
- }
2525
- function internalTrackDecorator(key) {
2526
- return {
2527
- get() {
2528
- const vm = getAssociatedVM(this);
2529
- componentValueObserved(vm, key);
2530
- return vm.cmpFields[key];
2531
- },
2532
- set(newValue) {
2533
- const vm = getAssociatedVM(this);
2534
- if (process.env.NODE_ENV !== 'production') {
2535
- const vmBeingRendered = getVMBeingRendered();
2536
- assert.invariant(!isInvokingRender, `${vmBeingRendered}.render() method has side effects on the state of ${vm}.${toString$1(key)}`);
2537
- assert.invariant(!isUpdatingTemplate, `Updating the template of ${vmBeingRendered} has side effects on the state of ${vm}.${toString$1(key)}`);
2538
- }
2539
- const reactiveOrAnyValue = getReactiveProxy(newValue);
2540
- updateComponentValue(vm, key, reactiveOrAnyValue);
2541
- },
2542
- enumerable: true,
2543
- configurable: true,
2544
- };
2579
+ } = vm;
2580
+ // waiting for the component to be connected to formally request the context via the token
2581
+ ArrayPush$1.call(wiredConnecting, () => {
2582
+ // This event is responsible for connecting the host element with another
2583
+ // element in the composed path that is providing contextual data. The provider
2584
+ // must be listening for a special dom event with the name corresponding to the value of
2585
+ // `adapterContextToken`, which will remain secret and internal to this file only to
2586
+ // guarantee that the linkage can be forged.
2587
+ const contextRegistrationEvent = new WireContextRegistrationEvent(adapterContextToken, {
2588
+ setNewContext(newContext) {
2589
+ // eslint-disable-next-line @lwc/lwc-internal/no-invalid-todo
2590
+ // TODO: dev-mode validation of config based on the adapter.contextSchema
2591
+ callbackWhenContextIsReady(newContext);
2592
+ },
2593
+ setDisconnectedCallback(disconnectCallback) {
2594
+ // adds this callback into the disconnect bucket so it gets disconnected from parent
2595
+ // the the element hosting the wire is disconnected
2596
+ ArrayPush$1.call(wiredDisconnecting, disconnectCallback);
2597
+ }
2598
+ });
2599
+ dispatchEvent(elm, contextRegistrationEvent);
2600
+ });
2601
+ }
2602
+ function createConnector(vm, name, wireDef) {
2603
+ const {
2604
+ method,
2605
+ adapter,
2606
+ configCallback,
2607
+ dynamic
2608
+ } = wireDef;
2609
+ let debugInfo;
2610
+ if (process.env.NODE_ENV !== 'production') {
2611
+ const wiredPropOrMethod = isUndefined$1(method) ? name : method.name;
2612
+ debugInfo = create(null);
2613
+ debugInfo.wasDataProvisionedForConfig = false;
2614
+ vm.debugInfo[WIRE_DEBUG_ENTRY][wiredPropOrMethod] = debugInfo;
2615
+ }
2616
+ const fieldOrMethodCallback = isUndefined$1(method) ? createFieldDataCallback(vm, name) : createMethodDataCallback(vm, method);
2617
+ const dataCallback = value => {
2618
+ if (process.env.NODE_ENV !== 'production') {
2619
+ debugInfo.data = value;
2620
+ // Note: most of the time, the data provided is for the current config, but there may be
2621
+ // some conditions in which it does not, ex:
2622
+ // race conditions in a poor network while the adapter does not cancel a previous request.
2623
+ debugInfo.wasDataProvisionedForConfig = true;
2624
+ }
2625
+ fieldOrMethodCallback(value);
2626
+ };
2627
+ let context;
2628
+ let connector;
2629
+ // Workaround to pass the component element associated to this wire adapter instance.
2630
+ defineProperty(dataCallback, DeprecatedWiredElementHost, {
2631
+ value: vm.elm
2632
+ });
2633
+ defineProperty(dataCallback, DeprecatedWiredParamsMeta, {
2634
+ value: dynamic
2635
+ });
2636
+ runWithBoundaryProtection(vm, vm, noop, () => {
2637
+ // job
2638
+ connector = new adapter(dataCallback);
2639
+ }, noop);
2640
+ const updateConnectorConfig = config => {
2641
+ // every time the config is recomputed due to tracking,
2642
+ // this callback will be invoked with the new computed config
2643
+ runWithBoundaryProtection(vm, vm, noop, () => {
2644
+ // job
2645
+ if (process.env.NODE_ENV !== 'production') {
2646
+ debugInfo.config = config;
2647
+ debugInfo.context = context;
2648
+ debugInfo.wasDataProvisionedForConfig = false;
2649
+ }
2650
+ connector.update(config, context);
2651
+ }, noop);
2652
+ };
2653
+ // Computes the current wire config and calls the update method on the wire adapter.
2654
+ // If it has params, we will need to observe changes in the next tick.
2655
+ const {
2656
+ computeConfigAndUpdate,
2657
+ ro
2658
+ } = createConfigWatcher(vm.component, configCallback, updateConnectorConfig);
2659
+ // if the adapter needs contextualization, we need to watch for new context and push it alongside the config
2660
+ if (!isUndefined$1(adapter.contextSchema)) {
2661
+ createContextWatcher(vm, wireDef, newContext => {
2662
+ // every time the context is pushed into this component,
2663
+ // this callback will be invoked with the new computed context
2664
+ if (context !== newContext) {
2665
+ context = newContext;
2666
+ // Note: when new context arrives, the config will be recomputed and pushed along side the new
2667
+ // context, this is to preserve the identity characteristics, config should not have identity
2668
+ // (ever), while context can have identity
2669
+ if (vm.state === 1 /* VMState.connected */) {
2670
+ computeConfigAndUpdate();
2671
+ }
2672
+ }
2673
+ });
2674
+ }
2675
+ return {
2676
+ // @ts-ignore the boundary protection executes sync, connector is always defined
2677
+ connector,
2678
+ computeConfigAndUpdate,
2679
+ resetConfigWatcher: () => ro.reset()
2680
+ };
2681
+ }
2682
+ const AdapterToTokenMap = new Map();
2683
+ function getAdapterToken(adapter) {
2684
+ return AdapterToTokenMap.get(adapter);
2685
+ }
2686
+ function setAdapterToken(adapter, token) {
2687
+ AdapterToTokenMap.set(adapter, token);
2688
+ }
2689
+ function storeWiredMethodMeta(descriptor, adapter, configCallback, dynamic) {
2690
+ // support for callable adapters
2691
+ if (adapter.adapter) {
2692
+ adapter = adapter.adapter;
2693
+ }
2694
+ const method = descriptor.value;
2695
+ const def = {
2696
+ adapter,
2697
+ method,
2698
+ configCallback,
2699
+ dynamic
2700
+ };
2701
+ WireMetaMap.set(descriptor, def);
2702
+ }
2703
+ function storeWiredFieldMeta(descriptor, adapter, configCallback, dynamic) {
2704
+ // support for callable adapters
2705
+ if (adapter.adapter) {
2706
+ adapter = adapter.adapter;
2707
+ }
2708
+ const def = {
2709
+ adapter,
2710
+ configCallback,
2711
+ dynamic
2712
+ };
2713
+ WireMetaMap.set(descriptor, def);
2714
+ }
2715
+ function installWireAdapters(vm) {
2716
+ const {
2717
+ context,
2718
+ def: {
2719
+ wire
2720
+ }
2721
+ } = vm;
2722
+ if (process.env.NODE_ENV !== 'production') {
2723
+ vm.debugInfo[WIRE_DEBUG_ENTRY] = create(null);
2724
+ }
2725
+ const wiredConnecting = context.wiredConnecting = [];
2726
+ const wiredDisconnecting = context.wiredDisconnecting = [];
2727
+ for (const fieldNameOrMethod in wire) {
2728
+ const descriptor = wire[fieldNameOrMethod];
2729
+ const wireDef = WireMetaMap.get(descriptor);
2730
+ if (process.env.NODE_ENV !== 'production') {
2731
+ assert.invariant(wireDef, `Internal Error: invalid wire definition found.`);
2732
+ }
2733
+ if (!isUndefined$1(wireDef)) {
2734
+ const {
2735
+ connector,
2736
+ computeConfigAndUpdate,
2737
+ resetConfigWatcher
2738
+ } = createConnector(vm, fieldNameOrMethod, wireDef);
2739
+ const hasDynamicParams = wireDef.dynamic.length > 0;
2740
+ ArrayPush$1.call(wiredConnecting, () => {
2741
+ connector.connect();
2742
+ if (!lwcRuntimeFlags.ENABLE_WIRE_SYNC_EMIT) {
2743
+ if (hasDynamicParams) {
2744
+ Promise.resolve().then(computeConfigAndUpdate);
2745
+ return;
2746
+ }
2747
+ }
2748
+ computeConfigAndUpdate();
2749
+ });
2750
+ ArrayPush$1.call(wiredDisconnecting, () => {
2751
+ connector.disconnect();
2752
+ resetConfigWatcher();
2753
+ });
2754
+ }
2755
+ }
2756
+ }
2757
+ function connectWireAdapters(vm) {
2758
+ const {
2759
+ wiredConnecting
2760
+ } = vm.context;
2761
+ for (let i = 0, len = wiredConnecting.length; i < len; i += 1) {
2762
+ wiredConnecting[i]();
2763
+ }
2764
+ }
2765
+ function disconnectWireAdapters(vm) {
2766
+ const {
2767
+ wiredDisconnecting
2768
+ } = vm.context;
2769
+ runWithBoundaryProtection(vm, vm, noop, () => {
2770
+ // job
2771
+ for (let i = 0, len = wiredDisconnecting.length; i < len; i += 1) {
2772
+ wiredDisconnecting[i]();
2773
+ }
2774
+ }, noop);
2545
2775
  }
2546
2776
 
2547
2777
  /*
@@ -2550,46 +2780,157 @@ var LWC = (function (exports) {
2550
2780
  * SPDX-License-Identifier: MIT
2551
2781
  * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
2552
2782
  */
2553
- /**
2554
- * @wire decorator to wire fields and methods to a wire adapter in
2555
- * LWC Components. This function implements the internals of this
2556
- * decorator.
2557
- */
2558
- function wire(_adapter, _config) {
2783
+ function api$1() {
2559
2784
  if (process.env.NODE_ENV !== 'production') {
2560
- assert.fail('@wire(adapter, config?) may only be used as a decorator.');
2785
+ assert.fail(`@api decorator can only be used as a decorator function.`);
2561
2786
  }
2562
2787
  throw new Error();
2563
2788
  }
2564
- function internalWireFieldDecorator(key) {
2789
+ function createPublicPropertyDescriptor(key) {
2565
2790
  return {
2566
2791
  get() {
2567
2792
  const vm = getAssociatedVM(this);
2793
+ if (isBeingConstructed(vm)) {
2794
+ if (process.env.NODE_ENV !== 'production') {
2795
+ logError(`Can’t read the value of property \`${toString$1(key)}\` from the constructor because the owner component hasn’t set the value yet. Instead, use the constructor to set a default value for the property.`, vm);
2796
+ }
2797
+ return;
2798
+ }
2568
2799
  componentValueObserved(vm, key);
2569
- return vm.cmpFields[key];
2800
+ return vm.cmpProps[key];
2570
2801
  },
2571
- set(value) {
2802
+ set(newValue) {
2572
2803
  const vm = getAssociatedVM(this);
2573
- /**
2574
- * Reactivity for wired fields is provided in wiring.
2575
- * We intentionally add reactivity here since this is just
2576
- * letting the author to do the wrong thing, but it will keep our
2577
- * system to be backward compatible.
2578
- */
2579
- updateComponentValue(vm, key, value);
2804
+ if (process.env.NODE_ENV !== 'production') {
2805
+ const vmBeingRendered = getVMBeingRendered();
2806
+ assert.invariant(!isInvokingRender, `${vmBeingRendered}.render() method has side effects on the state of ${vm}.${toString$1(key)}`);
2807
+ assert.invariant(!isUpdatingTemplate, `Updating the template of ${vmBeingRendered} has side effects on the state of ${vm}.${toString$1(key)}`);
2808
+ }
2809
+ vm.cmpProps[key] = newValue;
2810
+ componentValueMutated(vm, key);
2580
2811
  },
2581
2812
  enumerable: true,
2582
2813
  configurable: true,
2583
2814
  };
2584
2815
  }
2585
-
2586
- /*
2587
- * Copyright (c) 2018, salesforce.com, inc.
2588
- * All rights reserved.
2589
- * SPDX-License-Identifier: MIT
2590
- * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
2591
- */
2592
- function getClassDescriptorType(descriptor) {
2816
+ function createPublicAccessorDescriptor(key, descriptor) {
2817
+ const { get, set, enumerable, configurable } = descriptor;
2818
+ if (!isFunction$1(get)) {
2819
+ if (process.env.NODE_ENV !== 'production') {
2820
+ assert.invariant(isFunction$1(get), `Invalid compiler output for public accessor ${toString$1(key)} decorated with @api`);
2821
+ }
2822
+ throw new Error();
2823
+ }
2824
+ return {
2825
+ get() {
2826
+ if (process.env.NODE_ENV !== 'production') {
2827
+ // Assert that the this value is an actual Component with an associated VM.
2828
+ getAssociatedVM(this);
2829
+ }
2830
+ return get.call(this);
2831
+ },
2832
+ set(newValue) {
2833
+ const vm = getAssociatedVM(this);
2834
+ if (process.env.NODE_ENV !== 'production') {
2835
+ const vmBeingRendered = getVMBeingRendered();
2836
+ assert.invariant(!isInvokingRender, `${vmBeingRendered}.render() method has side effects on the state of ${vm}.${toString$1(key)}`);
2837
+ assert.invariant(!isUpdatingTemplate, `Updating the template of ${vmBeingRendered} has side effects on the state of ${vm}.${toString$1(key)}`);
2838
+ }
2839
+ if (set) {
2840
+ set.call(this, newValue);
2841
+ }
2842
+ else if (process.env.NODE_ENV !== 'production') {
2843
+ assert.fail(`Invalid attempt to set a new value for property ${toString$1(key)} of ${vm} that does not has a setter decorated with @api.`);
2844
+ }
2845
+ },
2846
+ enumerable,
2847
+ configurable,
2848
+ };
2849
+ }
2850
+
2851
+ /*
2852
+ * Copyright (c) 2018, salesforce.com, inc.
2853
+ * All rights reserved.
2854
+ * SPDX-License-Identifier: MIT
2855
+ * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
2856
+ */
2857
+ function track(target) {
2858
+ if (arguments.length === 1) {
2859
+ return getReactiveProxy(target);
2860
+ }
2861
+ if (process.env.NODE_ENV !== 'production') {
2862
+ assert.fail(`@track decorator can only be used with one argument to return a trackable object, or as a decorator function.`);
2863
+ }
2864
+ throw new Error();
2865
+ }
2866
+ function internalTrackDecorator(key) {
2867
+ return {
2868
+ get() {
2869
+ const vm = getAssociatedVM(this);
2870
+ componentValueObserved(vm, key);
2871
+ return vm.cmpFields[key];
2872
+ },
2873
+ set(newValue) {
2874
+ const vm = getAssociatedVM(this);
2875
+ if (process.env.NODE_ENV !== 'production') {
2876
+ const vmBeingRendered = getVMBeingRendered();
2877
+ assert.invariant(!isInvokingRender, `${vmBeingRendered}.render() method has side effects on the state of ${vm}.${toString$1(key)}`);
2878
+ assert.invariant(!isUpdatingTemplate, `Updating the template of ${vmBeingRendered} has side effects on the state of ${vm}.${toString$1(key)}`);
2879
+ }
2880
+ const reactiveOrAnyValue = getReactiveProxy(newValue);
2881
+ updateComponentValue(vm, key, reactiveOrAnyValue);
2882
+ },
2883
+ enumerable: true,
2884
+ configurable: true,
2885
+ };
2886
+ }
2887
+
2888
+ /*
2889
+ * Copyright (c) 2018, salesforce.com, inc.
2890
+ * All rights reserved.
2891
+ * SPDX-License-Identifier: MIT
2892
+ * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
2893
+ */
2894
+ /**
2895
+ * @wire decorator to wire fields and methods to a wire adapter in
2896
+ * LWC Components. This function implements the internals of this
2897
+ * decorator.
2898
+ */
2899
+ function wire(_adapter, _config) {
2900
+ if (process.env.NODE_ENV !== 'production') {
2901
+ assert.fail('@wire(adapter, config?) may only be used as a decorator.');
2902
+ }
2903
+ throw new Error();
2904
+ }
2905
+ function internalWireFieldDecorator(key) {
2906
+ return {
2907
+ get() {
2908
+ const vm = getAssociatedVM(this);
2909
+ componentValueObserved(vm, key);
2910
+ return vm.cmpFields[key];
2911
+ },
2912
+ set(value) {
2913
+ const vm = getAssociatedVM(this);
2914
+ /**
2915
+ * Reactivity for wired fields is provided in wiring.
2916
+ * We intentionally add reactivity here since this is just
2917
+ * letting the author to do the wrong thing, but it will keep our
2918
+ * system to be backward compatible.
2919
+ */
2920
+ updateComponentValue(vm, key, value);
2921
+ },
2922
+ enumerable: true,
2923
+ configurable: true,
2924
+ };
2925
+ }
2926
+
2927
+ /*
2928
+ * Copyright (c) 2018, salesforce.com, inc.
2929
+ * All rights reserved.
2930
+ * SPDX-License-Identifier: MIT
2931
+ * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
2932
+ */
2933
+ function getClassDescriptorType(descriptor) {
2593
2934
  if (isFunction$1(descriptor.value)) {
2594
2935
  return "method" /* DescriptorType.Method */;
2595
2936
  }
@@ -2808,8 +3149,8 @@ var LWC = (function (exports) {
2808
3149
  * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
2809
3150
  */
2810
3151
  let warned = false;
2811
- // @ts-ignore
2812
- if (process.env.NODE_ENV !== 'production' && typeof __karma__ !== 'undefined') {
3152
+ // Only used in LWC's Karma tests
3153
+ if (process.env.NODE_ENV === 'test-karma-lwc') {
2813
3154
  // @ts-ignore
2814
3155
  window.__lwcResetWarnedOnVersionMismatch = () => {
2815
3156
  warned = false;
@@ -3105,10 +3446,7 @@ var LWC = (function (exports) {
3105
3446
  return canRefreshAllInstances;
3106
3447
  }
3107
3448
  function getTemplateOrSwappedTemplate(tpl) {
3108
- if (process.env.NODE_ENV === 'production') {
3109
- // this method should never leak to prod
3110
- throw new ReferenceError();
3111
- }
3449
+ assertNotProd(); // this method should never leak to prod
3112
3450
  const visited = new Set();
3113
3451
  while (swappedTemplateMap.has(tpl) && !visited.has(tpl)) {
3114
3452
  visited.add(tpl);
@@ -3117,10 +3455,7 @@ var LWC = (function (exports) {
3117
3455
  return tpl;
3118
3456
  }
3119
3457
  function getComponentOrSwappedComponent(Ctor) {
3120
- if (process.env.NODE_ENV === 'production') {
3121
- // this method should never leak to prod
3122
- throw new ReferenceError();
3123
- }
3458
+ assertNotProd(); // this method should never leak to prod
3124
3459
  const visited = new Set();
3125
3460
  while (swappedComponentMap.has(Ctor) && !visited.has(Ctor)) {
3126
3461
  visited.add(Ctor);
@@ -3129,10 +3464,7 @@ var LWC = (function (exports) {
3129
3464
  return Ctor;
3130
3465
  }
3131
3466
  function getStyleOrSwappedStyle(style) {
3132
- if (process.env.NODE_ENV === 'production') {
3133
- // this method should never leak to prod
3134
- throw new ReferenceError();
3135
- }
3467
+ assertNotProd(); // this method should never leak to prod
3136
3468
  const visited = new Set();
3137
3469
  while (swappedStyleMap.has(style) && !visited.has(style)) {
3138
3470
  visited.add(style);
@@ -3141,10 +3473,7 @@ var LWC = (function (exports) {
3141
3473
  return style;
3142
3474
  }
3143
3475
  function setActiveVM(vm) {
3144
- if (process.env.NODE_ENV === 'production') {
3145
- // this method should never leak to prod
3146
- throw new ReferenceError();
3147
- }
3476
+ assertNotProd(); // this method should never leak to prod
3148
3477
  // tracking active component
3149
3478
  const Ctor = vm.def.ctor;
3150
3479
  let componentVMs = activeComponents.get(Ctor);
@@ -3187,10 +3516,7 @@ var LWC = (function (exports) {
3187
3516
  }
3188
3517
  }
3189
3518
  function removeActiveVM(vm) {
3190
- if (process.env.NODE_ENV === 'production') {
3191
- // this method should never leak to prod
3192
- throw new ReferenceError();
3193
- }
3519
+ assertNotProd(); // this method should never leak to prod
3194
3520
  // tracking inactive component
3195
3521
  const Ctor = vm.def.ctor;
3196
3522
  let list = activeComponents.get(Ctor);
@@ -5363,10 +5689,7 @@ var LWC = (function (exports) {
5363
5689
  vmBeingRendered = vm;
5364
5690
  }
5365
5691
  function validateSlots(vm, html) {
5366
- if (process.env.NODE_ENV === 'production') {
5367
- // this method should never leak to prod
5368
- throw new ReferenceError();
5369
- }
5692
+ assertNotProd(); // this method should never leak to prod
5370
5693
  const { cmpSlots } = vm;
5371
5694
  const { slots = EmptyArray } = html;
5372
5695
  for (const slotName in cmpSlots.slotAssignments) {
@@ -5500,9 +5823,7 @@ var LWC = (function (exports) {
5500
5823
  setActiveVM(vm);
5501
5824
  }
5502
5825
  // reset the refs; they will be set during the tmpl() instantiation
5503
- const hasRefVNodes = Boolean(html.hasRefs);
5504
- vm.hasRefVNodes = hasRefVNodes;
5505
- vm.refVNodes = hasRefVNodes ? create(null) : null;
5826
+ vm.refVNodes = html.hasRefs ? create(null) : null;
5506
5827
  // right before producing the vnodes, we clear up all internal references
5507
5828
  // to custom elements from the template.
5508
5829
  vm.velements = [];
@@ -5689,7 +6010,7 @@ var LWC = (function (exports) {
5689
6010
  const cmpEventListenerMap = new WeakMap();
5690
6011
  function getWrappedComponentsListener(vm, listener) {
5691
6012
  if (!isFunction$1(listener)) {
5692
- throw new TypeError(); // avoiding problems with non-valid listeners
6013
+ throw new TypeError('Expected an EventListener but received ' + typeof listener); // avoiding problems with non-valid listeners
5693
6014
  }
5694
6015
  let wrappedListener = cmpEventListenerMap.get(listener);
5695
6016
  if (isUndefined$1(wrappedListener)) {
@@ -5834,7 +6155,6 @@ var LWC = (function (exports) {
5834
6155
  mode,
5835
6156
  owner,
5836
6157
  refVNodes: null,
5837
- hasRefVNodes: false,
5838
6158
  children: EmptyArray,
5839
6159
  aChildren: EmptyArray,
5840
6160
  velements: EmptyArray,
@@ -6167,413 +6487,270 @@ var LWC = (function (exports) {
6167
6487
  const childVM = getAssociatedVMIfPresent(elm);
6168
6488
  // The VM associated with the element might be associated undefined
6169
6489
  // in the case where the VM failed in the middle of its creation,
6170
- // eg: constructor throwing before invoking super().
6171
- if (!isUndefined$1(childVM)) {
6172
- resetComponentStateWhenRemoved(childVM);
6173
- }
6174
- }
6175
- }
6176
- }
6177
- function runLightChildNodesDisconnectedCallback(vm) {
6178
- const {
6179
- aChildren: adoptedChildren
6180
- } = vm;
6181
- recursivelyDisconnectChildren(adoptedChildren);
6182
- }
6183
- /**
6184
- * The recursion doesn't need to be a complete traversal of the vnode graph,
6185
- * instead it can be partial, when a custom element vnode is found, we don't
6186
- * need to continue into its children because by attempting to disconnect the
6187
- * custom element itself will trigger the removal of anything slotted or anything
6188
- * defined on its shadow.
6189
- */
6190
- function recursivelyDisconnectChildren(vnodes) {
6191
- for (let i = 0, len = vnodes.length; i < len; i += 1) {
6192
- const vnode = vnodes[i];
6193
- if (!isNull(vnode) && !isUndefined$1(vnode.elm)) {
6194
- switch (vnode.type) {
6195
- case 2 /* VNodeType.Element */:
6196
- recursivelyDisconnectChildren(vnode.children);
6197
- break;
6198
- case 3 /* VNodeType.CustomElement */:
6199
- {
6200
- const vm = getAssociatedVM(vnode.elm);
6201
- resetComponentStateWhenRemoved(vm);
6202
- break;
6203
- }
6204
- }
6205
- }
6206
- }
6207
- }
6208
- // This is a super optimized mechanism to remove the content of the root node (shadow root
6209
- // for shadow DOM components and the root element itself for light DOM) without having to go
6210
- // into snabbdom. Especially useful when the reset is a consequence of an error, in which case the
6211
- // children VNodes might not be representing the current state of the DOM.
6212
- function resetComponentRoot(vm) {
6213
- const {
6214
- children,
6215
- renderRoot,
6216
- renderer: {
6217
- remove
6218
- }
6219
- } = vm;
6220
- for (let i = 0, len = children.length; i < len; i++) {
6221
- const child = children[i];
6222
- if (!isNull(child) && !isUndefined$1(child.elm)) {
6223
- remove(child.elm, renderRoot);
6224
- }
6225
- }
6226
- vm.children = EmptyArray;
6227
- runChildNodesDisconnectedCallback(vm);
6228
- vm.velements = EmptyArray;
6229
- }
6230
- function scheduleRehydration(vm) {
6231
- if (isTrue(vm.isScheduled)) {
6232
- return;
6233
- }
6234
- vm.isScheduled = true;
6235
- if (rehydrateQueue.length === 0) {
6236
- addCallbackToNextTick(flushRehydrationQueue);
6237
- }
6238
- ArrayPush$1.call(rehydrateQueue, vm);
6239
- }
6240
- function getErrorBoundaryVM(vm) {
6241
- let currentVm = vm;
6242
- while (!isNull(currentVm)) {
6243
- if (!isUndefined$1(currentVm.def.errorCallback)) {
6244
- return currentVm;
6245
- }
6246
- currentVm = currentVm.owner;
6247
- }
6248
- }
6249
- function runWithBoundaryProtection(vm, owner, pre, job, post) {
6250
- let error;
6251
- pre();
6252
- try {
6253
- job();
6254
- } catch (e) {
6255
- error = Object(e);
6256
- } finally {
6257
- post();
6258
- if (!isUndefined$1(error)) {
6259
- addErrorComponentStack(vm, error);
6260
- const errorBoundaryVm = isNull(owner) ? undefined : getErrorBoundaryVM(owner);
6261
- if (isUndefined$1(errorBoundaryVm)) {
6262
- throw error; // eslint-disable-line no-unsafe-finally
6263
- }
6264
-
6265
- resetComponentRoot(vm); // remove offenders
6266
- logOperationStart(6 /* OperationId.ErrorCallback */, vm);
6267
- // error boundaries must have an ErrorCallback
6268
- const errorCallback = errorBoundaryVm.def.errorCallback;
6269
- invokeComponentCallback(errorBoundaryVm, errorCallback, [error, error.wcStack]);
6270
- logOperationEnd(6 /* OperationId.ErrorCallback */, vm);
6271
- }
6272
- }
6273
- }
6274
- function forceRehydration(vm) {
6275
- // if we must reset the shadowRoot content and render the template
6276
- // from scratch on an active instance, the way to force the reset
6277
- // is by replacing the value of old template, which is used during
6278
- // to determine if the template has changed or not during the rendering
6279
- // process. If the template returned by render() is different from the
6280
- // previous stored template, the styles will be reset, along with the
6281
- // content of the shadowRoot, this way we can guarantee that all children
6282
- // elements will be throw away, and new instances will be created.
6283
- vm.cmpTemplate = () => [];
6284
- if (isFalse(vm.isDirty)) {
6285
- // forcing the vm to rehydrate in the next tick
6286
- markComponentAsDirty(vm);
6287
- scheduleRehydration(vm);
6288
- }
6289
- }
6290
-
6291
- /*
6292
- * Copyright (c) 2018, salesforce.com, inc.
6293
- * All rights reserved.
6294
- * SPDX-License-Identifier: MIT
6295
- * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
6296
- */
6297
- const DeprecatedWiredElementHost = '$$DeprecatedWiredElementHostKey$$';
6298
- const DeprecatedWiredParamsMeta = '$$DeprecatedWiredParamsMetaKey$$';
6299
- const WIRE_DEBUG_ENTRY = '@wire';
6300
- const WireMetaMap = new Map();
6301
- class WireContextRegistrationEvent extends CustomEvent {
6302
- constructor(adapterToken, {
6303
- setNewContext,
6304
- setDisconnectedCallback
6305
- }) {
6306
- super(adapterToken, {
6307
- bubbles: true,
6308
- composed: true
6309
- });
6310
- defineProperties(this, {
6311
- setNewContext: {
6312
- value: setNewContext
6313
- },
6314
- setDisconnectedCallback: {
6315
- value: setDisconnectedCallback
6316
- }
6317
- });
6318
- }
6319
- }
6320
- function createFieldDataCallback(vm, name) {
6321
- return value => {
6322
- updateComponentValue(vm, name, value);
6323
- };
6324
- }
6325
- function createMethodDataCallback(vm, method) {
6326
- return value => {
6327
- // dispatching new value into the wired method
6328
- runWithBoundaryProtection(vm, vm.owner, noop, () => {
6329
- // job
6330
- method.call(vm.component, value);
6331
- }, noop);
6332
- };
6333
- }
6334
- function createConfigWatcher(component, configCallback, callbackWhenConfigIsReady) {
6335
- let hasPendingConfig = false;
6336
- // creating the reactive observer for reactive params when needed
6337
- const ro = createReactiveObserver(() => {
6338
- if (hasPendingConfig === false) {
6339
- hasPendingConfig = true;
6340
- // collect new config in the micro-task
6341
- Promise.resolve().then(() => {
6342
- hasPendingConfig = false;
6343
- // resetting current reactive params
6344
- ro.reset();
6345
- // dispatching a new config due to a change in the configuration
6346
- computeConfigAndUpdate();
6347
- });
6348
- }
6349
- });
6350
- const computeConfigAndUpdate = () => {
6351
- let config;
6352
- ro.observe(() => config = configCallback(component));
6353
- // eslint-disable-next-line @lwc/lwc-internal/no-invalid-todo
6354
- // TODO: dev-mode validation of config based on the adapter.configSchema
6355
- // @ts-ignore it is assigned in the observe() callback
6356
- callbackWhenConfigIsReady(config);
6357
- };
6358
- return {
6359
- computeConfigAndUpdate,
6360
- ro
6361
- };
6362
- }
6363
- function createContextWatcher(vm, wireDef, callbackWhenContextIsReady) {
6364
- const {
6365
- adapter
6366
- } = wireDef;
6367
- const adapterContextToken = getAdapterToken(adapter);
6368
- if (isUndefined$1(adapterContextToken)) {
6369
- return; // no provider found, nothing to be done
6370
- }
6371
-
6372
- const {
6373
- elm,
6374
- context: {
6375
- wiredConnecting,
6376
- wiredDisconnecting
6377
- },
6378
- renderer: {
6379
- dispatchEvent
6380
- }
6381
- } = vm;
6382
- // waiting for the component to be connected to formally request the context via the token
6383
- ArrayPush$1.call(wiredConnecting, () => {
6384
- // This event is responsible for connecting the host element with another
6385
- // element in the composed path that is providing contextual data. The provider
6386
- // must be listening for a special dom event with the name corresponding to the value of
6387
- // `adapterContextToken`, which will remain secret and internal to this file only to
6388
- // guarantee that the linkage can be forged.
6389
- const contextRegistrationEvent = new WireContextRegistrationEvent(adapterContextToken, {
6390
- setNewContext(newContext) {
6391
- // eslint-disable-next-line @lwc/lwc-internal/no-invalid-todo
6392
- // TODO: dev-mode validation of config based on the adapter.contextSchema
6393
- callbackWhenContextIsReady(newContext);
6394
- },
6395
- setDisconnectedCallback(disconnectCallback) {
6396
- // adds this callback into the disconnect bucket so it gets disconnected from parent
6397
- // the the element hosting the wire is disconnected
6398
- ArrayPush$1.call(wiredDisconnecting, disconnectCallback);
6399
- }
6400
- });
6401
- dispatchEvent(elm, contextRegistrationEvent);
6402
- });
6403
- }
6404
- function createConnector(vm, name, wireDef) {
6405
- const {
6406
- method,
6407
- adapter,
6408
- configCallback,
6409
- dynamic
6410
- } = wireDef;
6411
- let debugInfo;
6412
- if (process.env.NODE_ENV !== 'production') {
6413
- const wiredPropOrMethod = isUndefined$1(method) ? name : method.name;
6414
- debugInfo = create(null);
6415
- debugInfo.wasDataProvisionedForConfig = false;
6416
- vm.debugInfo[WIRE_DEBUG_ENTRY][wiredPropOrMethod] = debugInfo;
6417
- }
6418
- const fieldOrMethodCallback = isUndefined$1(method) ? createFieldDataCallback(vm, name) : createMethodDataCallback(vm, method);
6419
- const dataCallback = value => {
6420
- if (process.env.NODE_ENV !== 'production') {
6421
- debugInfo.data = value;
6422
- // Note: most of the time, the data provided is for the current config, but there may be
6423
- // some conditions in which it does not, ex:
6424
- // race conditions in a poor network while the adapter does not cancel a previous request.
6425
- debugInfo.wasDataProvisionedForConfig = true;
6426
- }
6427
- fieldOrMethodCallback(value);
6428
- };
6429
- let context;
6430
- let connector;
6431
- // Workaround to pass the component element associated to this wire adapter instance.
6432
- defineProperty(dataCallback, DeprecatedWiredElementHost, {
6433
- value: vm.elm
6434
- });
6435
- defineProperty(dataCallback, DeprecatedWiredParamsMeta, {
6436
- value: dynamic
6437
- });
6438
- runWithBoundaryProtection(vm, vm, noop, () => {
6439
- // job
6440
- connector = new adapter(dataCallback);
6441
- }, noop);
6442
- const updateConnectorConfig = config => {
6443
- // every time the config is recomputed due to tracking,
6444
- // this callback will be invoked with the new computed config
6445
- runWithBoundaryProtection(vm, vm, noop, () => {
6446
- // job
6447
- if (process.env.NODE_ENV !== 'production') {
6448
- debugInfo.config = config;
6449
- debugInfo.context = context;
6450
- debugInfo.wasDataProvisionedForConfig = false;
6490
+ // eg: constructor throwing before invoking super().
6491
+ if (!isUndefined$1(childVM)) {
6492
+ resetComponentStateWhenRemoved(childVM);
6451
6493
  }
6452
- connector.update(config, context);
6453
- }, noop);
6454
- };
6455
- // Computes the current wire config and calls the update method on the wire adapter.
6456
- // If it has params, we will need to observe changes in the next tick.
6494
+ }
6495
+ }
6496
+ }
6497
+ function runLightChildNodesDisconnectedCallback(vm) {
6457
6498
  const {
6458
- computeConfigAndUpdate,
6459
- ro
6460
- } = createConfigWatcher(vm.component, configCallback, updateConnectorConfig);
6461
- // if the adapter needs contextualization, we need to watch for new context and push it alongside the config
6462
- if (!isUndefined$1(adapter.contextSchema)) {
6463
- createContextWatcher(vm, wireDef, newContext => {
6464
- // every time the context is pushed into this component,
6465
- // this callback will be invoked with the new computed context
6466
- if (context !== newContext) {
6467
- context = newContext;
6468
- // Note: when new context arrives, the config will be recomputed and pushed along side the new
6469
- // context, this is to preserve the identity characteristics, config should not have identity
6470
- // (ever), while context can have identity
6471
- if (vm.state === 1 /* VMState.connected */) {
6472
- computeConfigAndUpdate();
6473
- }
6499
+ aChildren: adoptedChildren
6500
+ } = vm;
6501
+ recursivelyDisconnectChildren(adoptedChildren);
6502
+ }
6503
+ /**
6504
+ * The recursion doesn't need to be a complete traversal of the vnode graph,
6505
+ * instead it can be partial, when a custom element vnode is found, we don't
6506
+ * need to continue into its children because by attempting to disconnect the
6507
+ * custom element itself will trigger the removal of anything slotted or anything
6508
+ * defined on its shadow.
6509
+ */
6510
+ function recursivelyDisconnectChildren(vnodes) {
6511
+ for (let i = 0, len = vnodes.length; i < len; i += 1) {
6512
+ const vnode = vnodes[i];
6513
+ if (!isNull(vnode) && !isUndefined$1(vnode.elm)) {
6514
+ switch (vnode.type) {
6515
+ case 2 /* VNodeType.Element */:
6516
+ recursivelyDisconnectChildren(vnode.children);
6517
+ break;
6518
+ case 3 /* VNodeType.CustomElement */:
6519
+ {
6520
+ const vm = getAssociatedVM(vnode.elm);
6521
+ resetComponentStateWhenRemoved(vm);
6522
+ break;
6523
+ }
6474
6524
  }
6475
- });
6525
+ }
6476
6526
  }
6477
- return {
6478
- // @ts-ignore the boundary protection executes sync, connector is always defined
6479
- connector,
6480
- computeConfigAndUpdate,
6481
- resetConfigWatcher: () => ro.reset()
6482
- };
6483
- }
6484
- const AdapterToTokenMap = new Map();
6485
- function getAdapterToken(adapter) {
6486
- return AdapterToTokenMap.get(adapter);
6487
6527
  }
6488
- function setAdapterToken(adapter, token) {
6489
- AdapterToTokenMap.set(adapter, token);
6528
+ // This is a super optimized mechanism to remove the content of the root node (shadow root
6529
+ // for shadow DOM components and the root element itself for light DOM) without having to go
6530
+ // into snabbdom. Especially useful when the reset is a consequence of an error, in which case the
6531
+ // children VNodes might not be representing the current state of the DOM.
6532
+ function resetComponentRoot(vm) {
6533
+ const {
6534
+ children,
6535
+ renderRoot,
6536
+ renderer: {
6537
+ remove
6538
+ }
6539
+ } = vm;
6540
+ for (let i = 0, len = children.length; i < len; i++) {
6541
+ const child = children[i];
6542
+ if (!isNull(child) && !isUndefined$1(child.elm)) {
6543
+ remove(child.elm, renderRoot);
6544
+ }
6545
+ }
6546
+ vm.children = EmptyArray;
6547
+ runChildNodesDisconnectedCallback(vm);
6548
+ vm.velements = EmptyArray;
6490
6549
  }
6491
- function storeWiredMethodMeta(descriptor, adapter, configCallback, dynamic) {
6492
- // support for callable adapters
6493
- if (adapter.adapter) {
6494
- adapter = adapter.adapter;
6550
+ function scheduleRehydration(vm) {
6551
+ if (isTrue(vm.isScheduled)) {
6552
+ return;
6495
6553
  }
6496
- const method = descriptor.value;
6497
- const def = {
6498
- adapter,
6499
- method,
6500
- configCallback,
6501
- dynamic
6502
- };
6503
- WireMetaMap.set(descriptor, def);
6554
+ vm.isScheduled = true;
6555
+ if (rehydrateQueue.length === 0) {
6556
+ addCallbackToNextTick(flushRehydrationQueue);
6557
+ }
6558
+ ArrayPush$1.call(rehydrateQueue, vm);
6504
6559
  }
6505
- function storeWiredFieldMeta(descriptor, adapter, configCallback, dynamic) {
6506
- // support for callable adapters
6507
- if (adapter.adapter) {
6508
- adapter = adapter.adapter;
6560
+ function getErrorBoundaryVM(vm) {
6561
+ let currentVm = vm;
6562
+ while (!isNull(currentVm)) {
6563
+ if (!isUndefined$1(currentVm.def.errorCallback)) {
6564
+ return currentVm;
6565
+ }
6566
+ currentVm = currentVm.owner;
6509
6567
  }
6510
- const def = {
6511
- adapter,
6512
- configCallback,
6513
- dynamic
6514
- };
6515
- WireMetaMap.set(descriptor, def);
6516
6568
  }
6517
- function installWireAdapters(vm) {
6518
- const {
6519
- context,
6520
- def: {
6521
- wire
6569
+ function runWithBoundaryProtection(vm, owner, pre, job, post) {
6570
+ let error;
6571
+ pre();
6572
+ try {
6573
+ job();
6574
+ } catch (e) {
6575
+ error = Object(e);
6576
+ } finally {
6577
+ post();
6578
+ if (!isUndefined$1(error)) {
6579
+ addErrorComponentStack(vm, error);
6580
+ const errorBoundaryVm = isNull(owner) ? undefined : getErrorBoundaryVM(owner);
6581
+ if (isUndefined$1(errorBoundaryVm)) {
6582
+ throw error; // eslint-disable-line no-unsafe-finally
6583
+ }
6584
+
6585
+ resetComponentRoot(vm); // remove offenders
6586
+ logOperationStart(6 /* OperationId.ErrorCallback */, vm);
6587
+ // error boundaries must have an ErrorCallback
6588
+ const errorCallback = errorBoundaryVm.def.errorCallback;
6589
+ invokeComponentCallback(errorBoundaryVm, errorCallback, [error, error.wcStack]);
6590
+ logOperationEnd(6 /* OperationId.ErrorCallback */, vm);
6522
6591
  }
6523
- } = vm;
6524
- if (process.env.NODE_ENV !== 'production') {
6525
- vm.debugInfo[WIRE_DEBUG_ENTRY] = create(null);
6526
6592
  }
6527
- const wiredConnecting = context.wiredConnecting = [];
6528
- const wiredDisconnecting = context.wiredDisconnecting = [];
6529
- for (const fieldNameOrMethod in wire) {
6530
- const descriptor = wire[fieldNameOrMethod];
6531
- const wireDef = WireMetaMap.get(descriptor);
6593
+ }
6594
+ function forceRehydration(vm) {
6595
+ // if we must reset the shadowRoot content and render the template
6596
+ // from scratch on an active instance, the way to force the reset
6597
+ // is by replacing the value of old template, which is used during
6598
+ // to determine if the template has changed or not during the rendering
6599
+ // process. If the template returned by render() is different from the
6600
+ // previous stored template, the styles will be reset, along with the
6601
+ // content of the shadowRoot, this way we can guarantee that all children
6602
+ // elements will be throw away, and new instances will be created.
6603
+ vm.cmpTemplate = () => [];
6604
+ if (isFalse(vm.isDirty)) {
6605
+ // forcing the vm to rehydrate in the next tick
6606
+ markComponentAsDirty(vm);
6607
+ scheduleRehydration(vm);
6608
+ }
6609
+ }
6610
+
6611
+ /*
6612
+ * Copyright (c) 2018, salesforce.com, inc.
6613
+ * All rights reserved.
6614
+ * SPDX-License-Identifier: MIT
6615
+ * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
6616
+ */
6617
+ //
6618
+ // The goal of this code is to detect invalid cross-root ARIA references in synthetic shadow DOM.
6619
+ // These invalid references should be fixed before the offending components can be migrated to native shadow DOM.
6620
+ // When invalid usage is detected, we warn in dev mode and call the reporting API if enabled.
6621
+ // See: https://lwc.dev/guide/accessibility#link-ids-and-aria-attributes-from-different-templates
6622
+ //
6623
+ // Use the unpatched native getElementById/querySelectorAll rather than the synthetic one
6624
+ const getElementById = _globalThis[KEY__NATIVE_GET_ELEMENT_BY_ID];
6625
+ const querySelectorAll = _globalThis[KEY__NATIVE_QUERY_SELECTOR_ALL];
6626
+ function isSyntheticShadowRootInstance(rootNode) {
6627
+ return rootNode !== document && isTrue(rootNode.synthetic);
6628
+ }
6629
+ function reportViolation(source, target, attrName) {
6630
+ // The vm is either for the source, the target, or both. Either one or both must be using synthetic
6631
+ // shadow for a violation to be detected.
6632
+ let vm = getAssociatedVMIfPresent(source.getRootNode().host);
6633
+ if (isUndefined$1(vm)) {
6634
+ vm = getAssociatedVMIfPresent(target.getRootNode().host);
6635
+ }
6636
+ if (isUndefined$1(vm)) {
6637
+ // vm should never be undefined here, but just to be safe, bail out and don't report
6638
+ return;
6639
+ }
6640
+ report(0 /* ReportingEventId.CrossRootAriaInSyntheticShadow */, vm);
6532
6641
  if (process.env.NODE_ENV !== 'production') {
6533
- assert.invariant(wireDef, `Internal Error: invalid wire definition found.`);
6642
+ // Avoid excessively logging to the console in the case of duplicates.
6643
+ logWarnOnce(`Element <${source.tagName.toLowerCase()}> uses attribute "${attrName}" to reference element ` +
6644
+ `<${target.tagName.toLowerCase()}>, which is not in the same shadow root. This will break in native shadow DOM. ` +
6645
+ `For details, see: https://lwc.dev/guide/accessibility#link-ids-and-aria-attributes-from-different-templates`, vm);
6534
6646
  }
6535
- if (!isUndefined$1(wireDef)) {
6536
- const {
6537
- connector,
6538
- computeConfigAndUpdate,
6539
- resetConfigWatcher
6540
- } = createConnector(vm, fieldNameOrMethod, wireDef);
6541
- const hasDynamicParams = wireDef.dynamic.length > 0;
6542
- ArrayPush$1.call(wiredConnecting, () => {
6543
- connector.connect();
6544
- if (!lwcRuntimeFlags.ENABLE_WIRE_SYNC_EMIT) {
6545
- if (hasDynamicParams) {
6546
- Promise.resolve().then(computeConfigAndUpdate);
6647
+ }
6648
+ function parseIdRefAttributeValue(attrValue) {
6649
+ // split on whitespace and skip empty strings after splitting
6650
+ return isString(attrValue) ? ArrayFilter.call(StringSplit.call(attrValue, /\s+/), Boolean) : [];
6651
+ }
6652
+ function detectSyntheticCrossRootAria(elm, attrName, attrValue) {
6653
+ const root = elm.getRootNode();
6654
+ if (!isSyntheticShadowRootInstance(root)) {
6655
+ return;
6656
+ }
6657
+ if (attrName === 'id') {
6658
+ // elm is the target, find the source
6659
+ if (!isString(attrValue) || attrValue.length === 0) {
6660
+ // if our id is null or empty, nobody can reference us
6547
6661
  return;
6548
- }
6549
6662
  }
6550
- computeConfigAndUpdate();
6551
- });
6552
- ArrayPush$1.call(wiredDisconnecting, () => {
6553
- connector.disconnect();
6554
- resetConfigWatcher();
6555
- });
6663
+ for (const idRefAttrName of ID_REFERENCING_ATTRIBUTES_SET) {
6664
+ // Query all global elements with this attribute. The attribute selector syntax `~=` is for values
6665
+ // that reference multiple IDs, separated by whitespace.
6666
+ const query = `[${idRefAttrName}~="${CSS.escape(attrValue)}"]`;
6667
+ const sourceElements = querySelectorAll.call(document, query);
6668
+ for (let i = 0; i < sourceElements.length; i++) {
6669
+ const sourceElement = sourceElements[i];
6670
+ const sourceRoot = sourceElement.getRootNode();
6671
+ if (sourceRoot !== root) {
6672
+ reportViolation(sourceElement, elm, idRefAttrName);
6673
+ break;
6674
+ }
6675
+ }
6676
+ }
6677
+ }
6678
+ else {
6679
+ // elm is the source, find the target
6680
+ const ids = parseIdRefAttributeValue(attrValue);
6681
+ for (const id of ids) {
6682
+ const target = getElementById.call(document, id);
6683
+ if (!isNull(target)) {
6684
+ const targetRoot = target.getRootNode();
6685
+ if (targetRoot !== root) {
6686
+ // target element's shadow root is not the same as ours
6687
+ reportViolation(elm, target, attrName);
6688
+ }
6689
+ }
6690
+ }
6556
6691
  }
6557
- }
6558
6692
  }
6559
- function connectWireAdapters(vm) {
6560
- const {
6561
- wiredConnecting
6562
- } = vm.context;
6563
- for (let i = 0, len = wiredConnecting.length; i < len; i += 1) {
6564
- wiredConnecting[i]();
6565
- }
6693
+ let enabled = false;
6694
+ // We want to avoid patching globals whenever possible, so this should be tree-shaken out in prod-mode and if
6695
+ // reporting is not enabled. It should also only run once
6696
+ function enableDetection() {
6697
+ if (enabled) {
6698
+ return; // don't double-apply the patches
6699
+ }
6700
+ enabled = true;
6701
+ const { setAttribute } = Element.prototype;
6702
+ // Detect calling `setAttribute` to set an idref or an id
6703
+ assign(Element.prototype, {
6704
+ setAttribute(attrName, attrValue) {
6705
+ setAttribute.call(this, attrName, attrValue);
6706
+ if (attrName === 'id' || ID_REFERENCING_ATTRIBUTES_SET.has(attrName)) {
6707
+ detectSyntheticCrossRootAria(this, attrName, attrValue);
6708
+ }
6709
+ },
6710
+ });
6711
+ // Detect `elm.id = 'foo'`
6712
+ const idDescriptor = getOwnPropertyDescriptor$1(Element.prototype, 'id');
6713
+ if (!isUndefined$1(idDescriptor)) {
6714
+ const { get, set } = idDescriptor;
6715
+ // These should always be a getter and a setter, but if someone is monkeying with the global descriptor, ignore it
6716
+ if (isFunction$1(get) && isFunction$1(set)) {
6717
+ defineProperty(Element.prototype, 'id', {
6718
+ get() {
6719
+ return get.call(this);
6720
+ },
6721
+ set(value) {
6722
+ set.call(this, value);
6723
+ detectSyntheticCrossRootAria(this, 'id', value);
6724
+ },
6725
+ // On the default descriptor for 'id', enumerable and configurable are true
6726
+ enumerable: true,
6727
+ configurable: true,
6728
+ });
6729
+ }
6730
+ }
6566
6731
  }
6567
- function disconnectWireAdapters(vm) {
6568
- const {
6569
- wiredDisconnecting
6570
- } = vm.context;
6571
- runWithBoundaryProtection(vm, vm, noop, () => {
6572
- // job
6573
- for (let i = 0, len = wiredDisconnecting.length; i < len; i += 1) {
6574
- wiredDisconnecting[i]();
6732
+ // Our detection logic relies on some modern browser features. We can just skip reporting the data
6733
+ // for unsupported browsers
6734
+ function supportsCssEscape() {
6735
+ return typeof CSS !== 'undefined' && isFunction$1(CSS.escape);
6736
+ }
6737
+ // If this page is not using synthetic shadow, then we don't need to install detection. Note
6738
+ // that we are assuming synthetic shadow is loaded before LWC.
6739
+ function isSyntheticShadowLoaded() {
6740
+ // We should probably be calling `renderer.isSyntheticShadowDefined`, but 1) we don't have access to the renderer,
6741
+ // and 2) this code needs to run in @lwc/engine-core, so it can access `logWarn()` and `report()`.
6742
+ return hasOwnProperty$1.call(Element.prototype, KEY__SHADOW_TOKEN);
6743
+ }
6744
+ // Detecting cross-root ARIA in synthetic shadow only makes sense for the browser
6745
+ if (supportsCssEscape() && isSyntheticShadowLoaded()) {
6746
+ // Always run detection in dev mode, so we can at least print to the console
6747
+ if (process.env.NODE_ENV !== 'production') {
6748
+ enableDetection();
6749
+ }
6750
+ else {
6751
+ // In prod mode, only enable detection if reporting is enabled
6752
+ onReportingEnabled(enableDetection);
6575
6753
  }
6576
- }, noop);
6577
6754
  }
6578
6755
 
6579
6756
  /*
@@ -7245,7 +7422,7 @@ var LWC = (function (exports) {
7245
7422
  }
7246
7423
  return ctor;
7247
7424
  }
7248
- /* version: 2.34.0 */
7425
+ /* version: 2.35.1 */
7249
7426
 
7250
7427
  /*
7251
7428
  * Copyright (c) 2018, salesforce.com, inc.
@@ -7353,8 +7530,7 @@ var LWC = (function (exports) {
7353
7530
  // Test utilities
7354
7531
  //
7355
7532
  // Only used in LWC's Karma tests
7356
- // @ts-ignore
7357
- if (process.env.NODE_ENV !== 'production' && typeof __karma__ !== 'undefined') {
7533
+ if (process.env.NODE_ENV === 'test-karma-lwc') {
7358
7534
  // @ts-ignore
7359
7535
  window.__lwcResetGlobalStylesheets = () => {
7360
7536
  stylesheetCache.clear();
@@ -8220,7 +8396,7 @@ var LWC = (function (exports) {
8220
8396
  function isNull(obj) {
8221
8397
  return obj === null;
8222
8398
  }
8223
- /** version: 2.34.0 */
8399
+ /** version: 2.35.1 */
8224
8400
 
8225
8401
  /*
8226
8402
  * Copyright (c) 2018, salesforce.com, inc.
@@ -8781,10 +8957,11 @@ var LWC = (function (exports) {
8781
8957
  });
8782
8958
  freeze(LightningElement);
8783
8959
  seal(LightningElement.prototype);
8784
- /* version: 2.34.0 */
8960
+ /* version: 2.35.1 */
8785
8961
 
8786
8962
  exports.LightningElement = LightningElement;
8787
8963
  exports.__unstable__ProfilerControl = profilerControl;
8964
+ exports.__unstable__ReportingControl = reportingControl;
8788
8965
  exports.api = api$1;
8789
8966
  exports.buildCustomElementConstructor = deprecatedBuildCustomElementConstructor;
8790
8967
  exports.createContextProvider = createContextProvider;