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