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