lwc 2.33.0 → 2.34.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (35) hide show
  1. package/dist/engine-dom/esm/es2017/engine-dom.js +166 -42
  2. package/dist/engine-dom/iife/es2017/engine-dom.js +166 -42
  3. package/dist/engine-dom/iife/es2017/engine-dom.min.js +1 -1
  4. package/dist/engine-dom/iife/es2017/engine-dom_debug.js +170 -39
  5. package/dist/engine-dom/iife/es5/engine-dom.js +204 -91
  6. package/dist/engine-dom/iife/es5/engine-dom.min.js +1 -1
  7. package/dist/engine-dom/iife/es5/engine-dom_debug.js +217 -88
  8. package/dist/engine-dom/umd/es2017/engine-dom.js +166 -42
  9. package/dist/engine-dom/umd/es2017/engine-dom.min.js +1 -1
  10. package/dist/engine-dom/umd/es2017/engine-dom_debug.js +170 -39
  11. package/dist/engine-dom/umd/es5/engine-dom.js +204 -91
  12. package/dist/engine-dom/umd/es5/engine-dom.min.js +1 -1
  13. package/dist/engine-dom/umd/es5/engine-dom_debug.js +217 -88
  14. package/dist/engine-server/commonjs/es2017/engine-server.js +158 -39
  15. package/dist/engine-server/commonjs/es2017/engine-server.min.js +1 -1
  16. package/dist/engine-server/esm/es2017/engine-server.js +158 -39
  17. package/dist/synthetic-shadow/esm/es2017/synthetic-shadow.js +3 -3
  18. package/dist/synthetic-shadow/iife/es2017/synthetic-shadow.js +3 -3
  19. package/dist/synthetic-shadow/iife/es2017/synthetic-shadow_debug.js +3 -3
  20. package/dist/synthetic-shadow/iife/es5/synthetic-shadow.js +3 -3
  21. package/dist/synthetic-shadow/iife/es5/synthetic-shadow_debug.js +3 -3
  22. package/dist/synthetic-shadow/umd/es2017/synthetic-shadow.js +3 -3
  23. package/dist/synthetic-shadow/umd/es2017/synthetic-shadow_debug.js +3 -3
  24. package/dist/synthetic-shadow/umd/es5/synthetic-shadow.js +3 -3
  25. package/dist/synthetic-shadow/umd/es5/synthetic-shadow_debug.js +3 -3
  26. package/dist/wire-service/esm/es2017/wire-service.js +2 -2
  27. package/dist/wire-service/iife/es2017/wire-service.js +2 -2
  28. package/dist/wire-service/iife/es2017/wire-service_debug.js +2 -2
  29. package/dist/wire-service/iife/es5/wire-service.js +2 -2
  30. package/dist/wire-service/iife/es5/wire-service_debug.js +2 -2
  31. package/dist/wire-service/umd/es2017/wire-service.js +2 -2
  32. package/dist/wire-service/umd/es2017/wire-service_debug.js +2 -2
  33. package/dist/wire-service/umd/es5/wire-service.js +2 -2
  34. package/dist/wire-service/umd/es5/wire-service_debug.js +2 -2
  35. package/package.json +7 -7
@@ -349,9 +349,9 @@ var LWC = (function (exports) {
349
349
  * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
350
350
  */
351
351
  // Increment whenever the LWC template compiler changes
352
- var LWC_VERSION = "2.33.0";
352
+ var LWC_VERSION = "2.34.0";
353
353
  var LWC_VERSION_COMMENT_REGEX = /\/\*LWC compiler v([\d.]+)\*\/\s*}/;
354
- /** version: 2.33.0 */
354
+ /** version: 2.34.0 */
355
355
 
356
356
  /**
357
357
  * Copyright (C) 2018 salesforce.com, inc.
@@ -373,7 +373,8 @@ var LWC = (function (exports) {
373
373
  DISABLE_LIGHT_DOM_UNSCOPED_CSS: null,
374
374
  ENABLE_SCOPED_CUSTOM_ELEMENT_REGISTRY: null,
375
375
  ENABLE_FROZEN_TEMPLATE: null,
376
- DISABLE_ARIA_REFLECTION_POLYFILL: null
376
+ DISABLE_ARIA_REFLECTION_POLYFILL: null,
377
+ ENABLE_PROGRAMMATIC_STYLESHEETS: null
377
378
  };
378
379
  if (!_globalThis.lwcRuntimeFlags) {
379
380
  Object.defineProperty(_globalThis, 'lwcRuntimeFlags', {
@@ -429,7 +430,7 @@ var LWC = (function (exports) {
429
430
  setFeatureFlag(name, value);
430
431
  }
431
432
  }
432
- /** version: 2.33.0 */
433
+ /** version: 2.34.0 */
433
434
 
434
435
  /**
435
436
  * Copyright (C) 2018 salesforce.com, inc.
@@ -493,7 +494,7 @@ var LWC = (function (exports) {
493
494
  }
494
495
  }
495
496
  }
496
- /** version: 2.33.0 */
497
+ /** version: 2.34.0 */
497
498
 
498
499
  /*
499
500
  * Copyright (c) 2018, salesforce.com, inc.
@@ -850,6 +851,7 @@ var LWC = (function (exports) {
850
851
  if (!isUndefined$1(vm)) {
851
852
  msg = "".concat(msg, "\n").concat(getComponentStack(vm));
852
853
  }
854
+ // In Jest tests, reduce the warning and error verbosity by not printing the callstack
853
855
  if (process.env.NODE_ENV === 'test') {
854
856
  /* eslint-disable-next-line no-console */
855
857
  console[method](msg);
@@ -908,6 +910,9 @@ var LWC = (function (exports) {
908
910
  // Global HTML Attributes & Properties
909
911
  // https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes
910
912
  // https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement
913
+ //
914
+ // If you update this list, check for test files that recapitulate the same list. Searching the codebase
915
+ // for e.g. "dropzone" should suffice.
911
916
  var globalHTMLProperties = assign(create(null), {
912
917
  accessKey: {
913
918
  attribute: 'accesskey'
@@ -3565,6 +3570,7 @@ var LWC = (function (exports) {
3565
3570
  setAttribute = _vm$renderer.setAttribute;
3566
3571
  var newStylesheets = template.stylesheets,
3567
3572
  newStylesheetToken = template.stylesheetToken;
3573
+ var newVmStylesheets = vm.stylesheets;
3568
3574
  var isSyntheticShadow = renderMode === 1 /* RenderMode.Shadow */ && shadowMode === 1 /* ShadowMode.Synthetic */;
3569
3575
  var hasScopedStyles = context.hasScopedStyles;
3570
3576
  var newToken;
@@ -3584,7 +3590,9 @@ var LWC = (function (exports) {
3584
3590
  }
3585
3591
  // Apply the new template styling token to the host element, if the new template has any
3586
3592
  // associated stylesheets. In the case of light DOM, also ensure there is at least one scoped stylesheet.
3587
- if (!isUndefined$1(newStylesheets) && newStylesheets.length !== 0) {
3593
+ var hasNewStylesheets = hasStyles(newStylesheets);
3594
+ var hasNewVmStylesheets = hasStyles(newVmStylesheets);
3595
+ if (hasNewStylesheets || hasNewVmStylesheets) {
3588
3596
  newToken = newStylesheetToken;
3589
3597
  }
3590
3598
  // Set the new styling token on the host element
@@ -3654,10 +3662,15 @@ var LWC = (function (exports) {
3654
3662
  function getStylesheetsContent(vm, template) {
3655
3663
  var stylesheets = template.stylesheets,
3656
3664
  stylesheetToken = template.stylesheetToken;
3665
+ var vmStylesheets = vm.stylesheets;
3657
3666
  var content = [];
3658
- if (!isUndefined$1(stylesheets) && stylesheets.length !== 0) {
3667
+ if (hasStyles(stylesheets)) {
3659
3668
  content = evaluateStylesheetsContent(stylesheets, stylesheetToken, vm);
3660
3669
  }
3670
+ // VM (component) stylesheets apply after template stylesheets
3671
+ if (hasStyles(vmStylesheets)) {
3672
+ ArrayPush$1.apply(content, evaluateStylesheetsContent(vmStylesheets, stylesheetToken, vm));
3673
+ }
3661
3674
  return content;
3662
3675
  }
3663
3676
  // It might be worth caching this to avoid doing the lookup repeatedly, but
@@ -3692,8 +3705,9 @@ var LWC = (function (exports) {
3692
3705
  function getStylesheetTokenHost(vnode) {
3693
3706
  var _getComponentInternal = getComponentInternalDef(vnode.ctor),
3694
3707
  template = _getComponentInternal.template;
3708
+ var vm = vnode.vm;
3695
3709
  var stylesheetToken = template.stylesheetToken;
3696
- return !isUndefined$1(stylesheetToken) && computeHasScopedStyles(template) ? makeHostToken(stylesheetToken) : null;
3710
+ return !isUndefined$1(stylesheetToken) && computeHasScopedStyles(template, vm) ? makeHostToken(stylesheetToken) : null;
3697
3711
  }
3698
3712
  function getNearestNativeShadowComponent(vm) {
3699
3713
  var owner = getNearestShadowComponent(vm);
@@ -4282,6 +4296,26 @@ var LWC = (function (exports) {
4282
4296
  // in fallback mode, the allocation will always set children to
4283
4297
  // empty and delegate the real allocation to the slot elements
4284
4298
  allocateChildren(n2, vm);
4299
+ // Solves an edge case with slotted VFragments in native shadow mode.
4300
+ //
4301
+ // During allocation, in native shadow, slotted VFragment nodes are flattened and their text delimiters are removed
4302
+ // to avoid interfering with native slot behavior. When this happens, if any of the fragments
4303
+ // were not stable, the children must go through the dynamic diffing algo.
4304
+ //
4305
+ // If the new children (n2.children) contain no VFragments, but the previous children (n1.children) were dynamic,
4306
+ // the new nodes must be marked dynamic so that all nodes are properly updated. The only indicator that the new
4307
+ // nodes need to be dynamic comes from the previous children, so we check that to determine whether we need to
4308
+ // mark the new children dynamic.
4309
+ //
4310
+ // Example:
4311
+ // n1.children: [div, VFragment('', div, null, ''), div] => [div, div, null, div]; // marked dynamic
4312
+ // n2.children: [div, null, div] => [div, null, div] // marked ???
4313
+ var shadowMode = vm.shadowMode,
4314
+ renderMode = vm.renderMode;
4315
+ if (shadowMode == 0 /* ShadowMode.Native */ && renderMode !== 0 /* RenderMode.Light */ && hasDynamicChildren(n1.children)) {
4316
+ // No-op if children has already been marked dynamic by 'allocateChildren()'.
4317
+ markAsDynamicChildren(n2.children);
4318
+ }
4285
4319
  }
4286
4320
  // in fallback mode, the children will be always empty, so, nothing
4287
4321
  // will happen, but in native, it does allocate the light dom
@@ -4460,7 +4494,6 @@ var LWC = (function (exports) {
4460
4494
  //
4461
4495
  // In case #2, we will always get a fresh VCustomElement.
4462
4496
  var children = vnode.aChildren || vnode.children;
4463
- vm.aChildren = children;
4464
4497
  var renderMode = vm.renderMode,
4465
4498
  shadowMode = vm.shadowMode;
4466
4499
  if (process.env.NODE_ENV !== 'production') {
@@ -4473,15 +4506,61 @@ var LWC = (function (exports) {
4473
4506
  logError("Invalid usage of 'lwc:slot-data' on ".concat(getComponentTag(vm), " tag. Scoped slot content can only be passed to a light dom child."));
4474
4507
  }
4475
4508
  }
4509
+ // If any of the children being allocated are VFragments, we remove the text delimiters and flatten all immediate
4510
+ // children VFragments to avoid them interfering with default slot behavior.
4511
+ var allocatedChildren = flattenFragmentsInChildren(children);
4512
+ vnode.children = allocatedChildren;
4513
+ vm.aChildren = allocatedChildren;
4476
4514
  if (shadowMode === 1 /* ShadowMode.Synthetic */ || renderMode === 0 /* RenderMode.Light */) {
4477
4515
  // slow path
4478
- allocateInSlot(vm, children, vnode.owner);
4516
+ allocateInSlot(vm, allocatedChildren, vnode.owner);
4479
4517
  // save the allocated children in case this vnode is reused.
4480
- vnode.aChildren = children;
4518
+ vnode.aChildren = allocatedChildren;
4481
4519
  // every child vnode is now allocated, and the host should receive none directly, it receives them via the shadow!
4482
4520
  vnode.children = EmptyArray;
4483
4521
  }
4484
4522
  }
4523
+ /**
4524
+ * Flattens the contents of all VFragments in an array of VNodes, removes the text delimiters on those VFragments, and
4525
+ * marks the resulting children array as dynamic. Uses a stack (array) to iteratively traverse the nested VFragments
4526
+ * and avoid the perf overhead of creating/destroying throwaway arrays/objects in a recursive approach.
4527
+ *
4528
+ * With the delimiters removed, the contents are marked dynamic so they are diffed correctly.
4529
+ *
4530
+ * This function is used for slotted VFragments to avoid the text delimiters interfering with slotting functionality.
4531
+ */
4532
+ function flattenFragmentsInChildren(children) {
4533
+ var flattenedChildren = [];
4534
+ // Initialize our stack with the direct children of the custom component and check whether we have a VFragment.
4535
+ // If no VFragment is found in children, we don't need to traverse anything or mark the children dynamic and can return early.
4536
+ var nodeStack = [];
4537
+ var fragmentFound = false;
4538
+ for (var _i15 = children.length - 1; _i15 > -1; _i15 -= 1) {
4539
+ var child = children[_i15];
4540
+ ArrayPush$1.call(nodeStack, child);
4541
+ fragmentFound = fragmentFound || !!(child && isVFragment(child));
4542
+ }
4543
+ if (!fragmentFound) {
4544
+ return children;
4545
+ }
4546
+ var currentNode;
4547
+ while (!isUndefined$1(currentNode = ArrayPop.call(nodeStack))) {
4548
+ if (!isNull(currentNode) && isVFragment(currentNode)) {
4549
+ var fChildren = currentNode.children;
4550
+ // Ignore the start and end text node delimiters
4551
+ for (var _i16 = fChildren.length - 2; _i16 > 0; _i16 -= 1) {
4552
+ ArrayPush$1.call(nodeStack, fChildren[_i16]);
4553
+ }
4554
+ } else {
4555
+ ArrayPush$1.call(flattenedChildren, currentNode);
4556
+ }
4557
+ }
4558
+ // We always mark the children as dynamic because nothing generates stable VFragments yet.
4559
+ // If/when stable VFragments are generated by the compiler, this code should be updated to
4560
+ // not mark dynamic if all flattened VFragments were stable.
4561
+ markAsDynamicChildren(flattenedChildren);
4562
+ return flattenedChildren;
4563
+ }
4485
4564
  function createViewModelHook(elm, vnode, renderer) {
4486
4565
  var vm = getAssociatedVMIfPresent(elm);
4487
4566
  // There is a possibility that a custom element is registered under tagName, in which case, the
@@ -4504,22 +4583,16 @@ var LWC = (function (exports) {
4504
4583
  }
4505
4584
  return vm;
4506
4585
  }
4507
- /**
4508
- * Collects all slots into a SlotSet, traversing through VFragment Nodes
4509
- */
4510
- function collectSlots(vm, children, cmpSlotsMapping) {
4586
+ function allocateInSlot(vm, children, owner) {
4511
4587
  var _a, _b;
4512
- for (var _i15 = 0, len = children.length; _i15 < len; _i15 += 1) {
4513
- var vnode = children[_i15];
4588
+ var oldSlotsMapping = vm.cmpSlots.slotAssignments;
4589
+ var cmpSlotsMapping = create(null);
4590
+ // Collect all slots into cmpSlotsMapping
4591
+ for (var _i17 = 0, len = children.length; _i17 < len; _i17 += 1) {
4592
+ var vnode = children[_i17];
4514
4593
  if (isNull(vnode)) {
4515
4594
  continue;
4516
4595
  }
4517
- // Dive further iff the content is wrapped in a VFragment
4518
- if (isVFragment(vnode)) {
4519
- // Remove the text delimiter nodes to avoid overriding default slot content
4520
- collectSlots(vm, vnode.children.slice(1, -1), cmpSlotsMapping);
4521
- continue;
4522
- }
4523
4596
  var slotName = '';
4524
4597
  if (isVBaseElement(vnode)) {
4525
4598
  slotName = (_b = (_a = vnode.data.attrs) === null || _a === void 0 ? void 0 : _a.slot) !== null && _b !== void 0 ? _b : '';
@@ -4529,11 +4602,6 @@ var LWC = (function (exports) {
4529
4602
  var vnodes = cmpSlotsMapping[slotName] = cmpSlotsMapping[slotName] || [];
4530
4603
  ArrayPush$1.call(vnodes, vnode);
4531
4604
  }
4532
- }
4533
- function allocateInSlot(vm, children, owner) {
4534
- var oldSlotsMapping = vm.cmpSlots.slotAssignments;
4535
- var cmpSlotsMapping = create(null);
4536
- collectSlots(vm, children, cmpSlotsMapping);
4537
4605
  vm.cmpSlots = {
4538
4606
  owner: owner,
4539
4607
  slotAssignments: cmpSlotsMapping
@@ -4546,16 +4614,16 @@ var LWC = (function (exports) {
4546
4614
  markComponentAsDirty(vm);
4547
4615
  return;
4548
4616
  }
4549
- for (var _i16 = 0, len = oldKeys.length; _i16 < len; _i16 += 1) {
4550
- var key = oldKeys[_i16];
4617
+ for (var _i18 = 0, _len2 = oldKeys.length; _i18 < _len2; _i18 += 1) {
4618
+ var key = oldKeys[_i18];
4551
4619
  if (isUndefined$1(cmpSlotsMapping[key]) || oldSlotsMapping[key].length !== cmpSlotsMapping[key].length) {
4552
4620
  markComponentAsDirty(vm);
4553
4621
  return;
4554
4622
  }
4555
4623
  var oldVNodes = oldSlotsMapping[key];
4556
- var vnodes = cmpSlotsMapping[key];
4624
+ var _vnodes = cmpSlotsMapping[key];
4557
4625
  for (var j = 0, a = cmpSlotsMapping[key].length; j < a; j += 1) {
4558
- if (oldVNodes[j] !== vnodes[j]) {
4626
+ if (oldVNodes[j] !== _vnodes[j]) {
4559
4627
  markComponentAsDirty(vm);
4560
4628
  return;
4561
4629
  }
@@ -4564,14 +4632,14 @@ var LWC = (function (exports) {
4564
4632
  }
4565
4633
  }
4566
4634
  // Using a WeakMap instead of a WeakSet because this one works in IE11 :(
4567
- var FromIteration = new WeakMap();
4568
- // dynamic children means it was generated by an iteration
4569
- // in a template, and will require a more complex diffing algo.
4635
+ var DynamicChildren = new WeakMap();
4636
+ // dynamic children means it was either generated by an iteration in a template
4637
+ // or part of an unstable fragment, and will require a more complex diffing algo.
4570
4638
  function markAsDynamicChildren(children) {
4571
- FromIteration.set(children, 1);
4639
+ DynamicChildren.set(children, 1);
4572
4640
  }
4573
4641
  function hasDynamicChildren(children) {
4574
- return FromIteration.has(children);
4642
+ return DynamicChildren.has(children);
4575
4643
  }
4576
4644
  function createKeyToOldIdx(children, beginIdx, endIdx) {
4577
4645
  var map = {};
@@ -4670,11 +4738,11 @@ var LWC = (function (exports) {
4670
4738
  if (oldStartIdx > oldEndIdx) {
4671
4739
  // There's some cases in which the sub array of vnodes to be inserted is followed by null(s) and an
4672
4740
  // already processed vnode, in such cases the vnodes to be inserted should be before that processed vnode.
4673
- var _i17 = newEndIdx;
4741
+ var _i19 = newEndIdx;
4674
4742
  var n;
4675
4743
  do {
4676
- n = newCh[++_i17];
4677
- } while (!isVNode(n) && _i17 < newChEnd);
4744
+ n = newCh[++_i19];
4745
+ } while (!isVNode(n) && _i19 < newChEnd);
4678
4746
  before = isVNode(n) ? n.elm : null;
4679
4747
  mountVNodes(newCh, parent, renderer, before, newStartIdx, newEndIdx + 1);
4680
4748
  } else {
@@ -4699,9 +4767,9 @@ var LWC = (function (exports) {
4699
4767
  // if the old list is not empty, the new list MUST have the same
4700
4768
  // amount of nodes, that's why we call this static children
4701
4769
  var anchor = null;
4702
- for (var _i18 = c2Length - 1; _i18 >= 0; _i18 -= 1) {
4703
- var n1 = c1[_i18];
4704
- var n2 = c2[_i18];
4770
+ for (var _i20 = c2Length - 1; _i20 >= 0; _i20 -= 1) {
4771
+ var n1 = c1[_i20];
4772
+ var n2 = c2[_i20];
4705
4773
  if (n2 !== n1) {
4706
4774
  if (isVNode(n1)) {
4707
4775
  if (isVNode(n2)) {
@@ -4826,8 +4894,8 @@ var LWC = (function (exports) {
4826
4894
  if (!isUndefined$1(slotset) && !isUndefined$1(slotset.slotAssignments) && !isUndefined$1(slotset.slotAssignments[slotName]) && slotset.slotAssignments[slotName].length !== 0) {
4827
4895
  var newChildren = [];
4828
4896
  var slotAssignments = slotset.slotAssignments[slotName];
4829
- for (var _i19 = 0; _i19 < slotAssignments.length; _i19++) {
4830
- var vnode = slotAssignments[_i19];
4897
+ for (var _i21 = 0; _i21 < slotAssignments.length; _i21++) {
4898
+ var vnode = slotAssignments[_i21];
4831
4899
  if (!isNull(vnode)) {
4832
4900
  var assignedNodeIsScopedSlot = isVScopedSlotFragment(vnode);
4833
4901
  // The only sniff test for a scoped <slot> element is the presence of `slotData`
@@ -5323,7 +5391,7 @@ var LWC = (function (exports) {
5323
5391
  }
5324
5392
  function buildParseFragmentFn(createFragmentFn) {
5325
5393
  return function (strings) {
5326
- for (var _len2 = arguments.length, keys = new Array(_len2 > 1 ? _len2 - 1 : 0), _key3 = 1; _key3 < _len2; _key3++) {
5394
+ for (var _len3 = arguments.length, keys = new Array(_len3 > 1 ? _len3 - 1 : 0), _key3 = 1; _key3 < _len3; _key3++) {
5327
5395
  keys[_key3 - 1] = arguments[_key3];
5328
5396
  }
5329
5397
  var cache = create(null);
@@ -5352,23 +5420,23 @@ var LWC = (function (exports) {
5352
5420
  var classAttrToken = hasScopedStyles && hasStyleToken ? " class=\"".concat(stylesheetToken, "\"") : '';
5353
5421
  var attrToken = hasStyleToken && isSyntheticShadow ? ' ' + stylesheetToken : '';
5354
5422
  var htmlFragment = '';
5355
- for (var _i20 = 0, n = keys.length; _i20 < n; _i20++) {
5356
- switch (keys[_i20]) {
5423
+ for (var _i22 = 0, n = keys.length; _i22 < n; _i22++) {
5424
+ switch (keys[_i22]) {
5357
5425
  case 0:
5358
5426
  // styleToken in existing class attr
5359
- htmlFragment += strings[_i20] + classToken;
5427
+ htmlFragment += strings[_i22] + classToken;
5360
5428
  break;
5361
5429
  case 1:
5362
5430
  // styleToken for added class attr
5363
- htmlFragment += strings[_i20] + classAttrToken;
5431
+ htmlFragment += strings[_i22] + classAttrToken;
5364
5432
  break;
5365
5433
  case 2:
5366
5434
  // styleToken as attr
5367
- htmlFragment += strings[_i20] + attrToken;
5435
+ htmlFragment += strings[_i22] + attrToken;
5368
5436
  break;
5369
5437
  case 3:
5370
5438
  // ${1}${2}
5371
- htmlFragment += strings[_i20] + classAttrToken + attrToken;
5439
+ htmlFragment += strings[_i22] + classAttrToken + attrToken;
5372
5440
  break;
5373
5441
  }
5374
5442
  }
@@ -5433,7 +5501,7 @@ var LWC = (function (exports) {
5433
5501
  // Create a brand new template cache for the swapped templated.
5434
5502
  context.tplCache = create(null);
5435
5503
  // Set the computeHasScopedStyles property in the context, to avoid recomputing it repeatedly.
5436
- context.hasScopedStyles = computeHasScopedStyles(html);
5504
+ context.hasScopedStyles = computeHasScopedStyles(html, vm);
5437
5505
  // Update the scoping token on the host element.
5438
5506
  updateStylesheetToken(vm, html);
5439
5507
  // Evaluate, create stylesheet and cache the produced VNode for future
@@ -5473,17 +5541,24 @@ var LWC = (function (exports) {
5473
5541
  }
5474
5542
  return vnodes;
5475
5543
  }
5476
- function computeHasScopedStyles(template) {
5477
- var stylesheets = template.stylesheets;
5478
- if (!isUndefined$1(stylesheets)) {
5479
- for (var _i21 = 0; _i21 < stylesheets.length; _i21++) {
5480
- if (isTrue(stylesheets[_i21][KEY__SCOPED_CSS])) {
5544
+ function computeHasScopedStylesInStylesheets(stylesheets) {
5545
+ if (hasStyles(stylesheets)) {
5546
+ for (var _i23 = 0; _i23 < stylesheets.length; _i23++) {
5547
+ if (isTrue(stylesheets[_i23][KEY__SCOPED_CSS])) {
5481
5548
  return true;
5482
5549
  }
5483
5550
  }
5484
5551
  }
5485
5552
  return false;
5486
5553
  }
5554
+ function computeHasScopedStyles(template, vm) {
5555
+ var stylesheets = template.stylesheets;
5556
+ var vmStylesheets = !isUndefined$1(vm) ? vm.stylesheets : null;
5557
+ return computeHasScopedStylesInStylesheets(stylesheets) || computeHasScopedStylesInStylesheets(vmStylesheets);
5558
+ }
5559
+ function hasStyles(stylesheets) {
5560
+ return !isUndefined$1(stylesheets) && !isNull(stylesheets) && stylesheets.length > 0;
5561
+ }
5487
5562
 
5488
5563
  /*
5489
5564
  * Copyright (c) 2018, salesforce.com, inc.
@@ -5665,8 +5740,8 @@ var LWC = (function (exports) {
5665
5740
  if (process.env.NODE_ENV !== 'production') {
5666
5741
  assert.isTrue(isObject(service), "Invalid service declaration, ".concat(service, ": service must be an object"));
5667
5742
  }
5668
- for (var _i22 = 0; _i22 < hooks.length; ++_i22) {
5669
- var hookName = hooks[_i22];
5743
+ for (var _i24 = 0; _i24 < hooks.length; ++_i24) {
5744
+ var hookName = hooks[_i24];
5670
5745
  if (hookName in service) {
5671
5746
  var l = Services[hookName];
5672
5747
  if (isUndefined$1(l)) {
@@ -5683,8 +5758,8 @@ var LWC = (function (exports) {
5683
5758
  var component = vm.component,
5684
5759
  def = vm.def,
5685
5760
  context = vm.context;
5686
- for (var _i23 = 0, len = cbs.length; _i23 < len; ++_i23) {
5687
- cbs[_i23].call(undefined, component, {}, def, context);
5761
+ for (var _i25 = 0, len = cbs.length; _i25 < len; ++_i25) {
5762
+ cbs[_i25].call(undefined, component, {}, def, context);
5688
5763
  }
5689
5764
  }
5690
5765
 
@@ -5803,6 +5878,7 @@ var LWC = (function (exports) {
5803
5878
  // Properties set right after VM creation.
5804
5879
  tro: null,
5805
5880
  shadowMode: null,
5881
+ stylesheets: null,
5806
5882
  // Properties set by the LightningElement constructor.
5807
5883
  component: null,
5808
5884
  shadowRoot: null,
@@ -5815,6 +5891,7 @@ var LWC = (function (exports) {
5815
5891
  if (process.env.NODE_ENV !== 'production') {
5816
5892
  vm.debugInfo = create(null);
5817
5893
  }
5894
+ vm.stylesheets = computeStylesheets(vm, def.ctor);
5818
5895
  vm.shadowMode = computeShadowMode(vm, renderer);
5819
5896
  vm.tro = getTemplateReactiveObserver(vm);
5820
5897
  if (process.env.NODE_ENV !== 'production') {
@@ -5833,6 +5910,40 @@ var LWC = (function (exports) {
5833
5910
  }
5834
5911
  return vm;
5835
5912
  }
5913
+ function validateComponentStylesheets(vm, stylesheets) {
5914
+ var valid = true;
5915
+ var validate = function validate(arrayOrStylesheet) {
5916
+ if (isArray$1(arrayOrStylesheet)) {
5917
+ for (var _i26 = 0; _i26 < arrayOrStylesheet.length; _i26++) {
5918
+ validate(arrayOrStylesheet[_i26]);
5919
+ }
5920
+ } else if (!isFunction$1(arrayOrStylesheet)) {
5921
+ // function assumed to be a stylesheet factory
5922
+ valid = false;
5923
+ }
5924
+ };
5925
+ if (!isArray$1(stylesheets)) {
5926
+ valid = false;
5927
+ } else {
5928
+ validate(stylesheets);
5929
+ }
5930
+ return valid;
5931
+ }
5932
+ // Validate and flatten any stylesheets defined as `static stylesheets`
5933
+ function computeStylesheets(vm, ctor) {
5934
+ if (lwcRuntimeFlags.ENABLE_PROGRAMMATIC_STYLESHEETS) {
5935
+ var stylesheets = ctor.stylesheets;
5936
+ if (!isUndefined$1(stylesheets)) {
5937
+ var valid = validateComponentStylesheets(vm, stylesheets);
5938
+ if (valid) {
5939
+ return flattenStylesheets(stylesheets);
5940
+ } else if (process.env.NODE_ENV !== 'production') {
5941
+ logError("static stylesheets must be an array of CSS stylesheets. Found invalid stylesheets on <".concat(vm.tagName, ">"), vm);
5942
+ }
5943
+ }
5944
+ }
5945
+ return null;
5946
+ }
5836
5947
  function computeShadowMode(vm, renderer) {
5837
5948
  var def = vm.def;
5838
5949
  var isSyntheticShadowDefined = renderer.isSyntheticShadowDefined,
@@ -5957,17 +6068,17 @@ var LWC = (function (exports) {
5957
6068
  return a.idx - b.idx;
5958
6069
  });
5959
6070
  rehydrateQueue = []; // reset to a new queue
5960
- for (var _i24 = 0, len = vms.length; _i24 < len; _i24 += 1) {
5961
- var vm = vms[_i24];
6071
+ for (var _i27 = 0, len = vms.length; _i27 < len; _i27 += 1) {
6072
+ var vm = vms[_i27];
5962
6073
  try {
5963
6074
  rehydrate(vm);
5964
6075
  } catch (error) {
5965
- if (_i24 + 1 < len) {
6076
+ if (_i27 + 1 < len) {
5966
6077
  // pieces of the queue are still pending to be rehydrated, those should have priority
5967
6078
  if (rehydrateQueue.length === 0) {
5968
6079
  addCallbackToNextTick(flushRehydrationQueue);
5969
6080
  }
5970
- ArrayUnshift.apply(rehydrateQueue, ArraySlice.call(vms, _i24 + 1));
6081
+ ArrayUnshift.apply(rehydrateQueue, ArraySlice.call(vms, _i27 + 1));
5971
6082
  }
5972
6083
  // we need to end the measure before throwing.
5973
6084
  logGlobalOperationEnd(8 /* OperationId.GlobalRehydrate */);
@@ -6036,8 +6147,8 @@ var LWC = (function (exports) {
6036
6147
  var vCustomElementCollection = vm.velements;
6037
6148
  // Reporting disconnection for every child in inverse order since they are
6038
6149
  // inserted in reserved order.
6039
- for (var _i25 = vCustomElementCollection.length - 1; _i25 >= 0; _i25 -= 1) {
6040
- var elm = vCustomElementCollection[_i25].elm;
6150
+ for (var _i28 = vCustomElementCollection.length - 1; _i28 >= 0; _i28 -= 1) {
6151
+ var elm = vCustomElementCollection[_i28].elm;
6041
6152
  // There are two cases where the element could be undefined:
6042
6153
  // * when there is an error during the construction phase, and an error
6043
6154
  // boundary picks it, there is a possibility that the VCustomElement
@@ -6068,8 +6179,8 @@ var LWC = (function (exports) {
6068
6179
  * defined on its shadow.
6069
6180
  */
6070
6181
  function recursivelyDisconnectChildren(vnodes) {
6071
- for (var _i26 = 0, len = vnodes.length; _i26 < len; _i26 += 1) {
6072
- var vnode = vnodes[_i26];
6182
+ for (var _i29 = 0, len = vnodes.length; _i29 < len; _i29 += 1) {
6183
+ var vnode = vnodes[_i29];
6073
6184
  if (!isNull(vnode) && !isUndefined$1(vnode.elm)) {
6074
6185
  switch (vnode.type) {
6075
6186
  case 2 /* VNodeType.Element */:
@@ -6093,8 +6204,8 @@ var LWC = (function (exports) {
6093
6204
  var children = vm.children,
6094
6205
  renderRoot = vm.renderRoot,
6095
6206
  remove = vm.renderer.remove;
6096
- for (var _i27 = 0, len = children.length; _i27 < len; _i27++) {
6097
- var child = children[_i27];
6207
+ for (var _i30 = 0, len = children.length; _i30 < len; _i30++) {
6208
+ var child = children[_i30];
6098
6209
  if (!isNull(child) && !isUndefined$1(child.elm)) {
6099
6210
  remove(child.elm, renderRoot);
6100
6211
  }
@@ -6432,16 +6543,16 @@ var LWC = (function (exports) {
6432
6543
  }
6433
6544
  function connectWireAdapters(vm) {
6434
6545
  var wiredConnecting = vm.context.wiredConnecting;
6435
- for (var _i28 = 0, len = wiredConnecting.length; _i28 < len; _i28 += 1) {
6436
- wiredConnecting[_i28]();
6546
+ for (var _i31 = 0, len = wiredConnecting.length; _i31 < len; _i31 += 1) {
6547
+ wiredConnecting[_i31]();
6437
6548
  }
6438
6549
  }
6439
6550
  function disconnectWireAdapters(vm) {
6440
6551
  var wiredDisconnecting = vm.context.wiredDisconnecting;
6441
6552
  runWithBoundaryProtection(vm, vm, noop, function () {
6442
6553
  // job
6443
- for (var _i29 = 0, len = wiredDisconnecting.length; _i29 < len; _i29 += 1) {
6444
- wiredDisconnecting[_i29]();
6554
+ for (var _i32 = 0, len = wiredDisconnecting.length; _i32 < len; _i32 += 1) {
6555
+ wiredDisconnecting[_i32]();
6445
6556
  }
6446
6557
  }, noop);
6447
6558
  }
@@ -6680,8 +6791,8 @@ var LWC = (function (exports) {
6680
6791
  var nextNode = node;
6681
6792
  var anchor = null;
6682
6793
  var renderer = owner.renderer;
6683
- for (var _i30 = 0; _i30 < children.length; _i30++) {
6684
- var childVnode = children[_i30];
6794
+ for (var _i33 = 0; _i33 < children.length; _i33++) {
6795
+ var childVnode = children[_i33];
6685
6796
  if (!isNull(childVnode)) {
6686
6797
  if (nextNode) {
6687
6798
  nextNode = hydrateNode(nextNode, childVnode, renderer);
@@ -6759,8 +6870,8 @@ var LWC = (function (exports) {
6759
6870
  var nodesAreCompatible = true;
6760
6871
  // Validate attributes, though we could always recovery from those by running the update mods.
6761
6872
  // Note: intentionally ONLY matching vnodes.attrs to elm.attrs, in case SSR is adding extra attributes.
6762
- for (var _i31 = 0, _Object$entries = Object.entries(attrs); _i31 < _Object$entries.length; _i31++) {
6763
- var _Object$entries$_i = _slicedToArray(_Object$entries[_i31], 2),
6873
+ for (var _i34 = 0, _Object$entries = Object.entries(attrs); _i34 < _Object$entries.length; _i34++) {
6874
+ var _Object$entries$_i = _slicedToArray(_Object$entries[_i34], 2),
6764
6875
  attrName = _Object$entries$_i[0],
6765
6876
  attrValue = _Object$entries$_i[1];
6766
6877
  var owner = vnode.owner;
@@ -6861,8 +6972,8 @@ var LWC = (function (exports) {
6861
6972
  var parsedVnodeStyle = parseStyleText(elmStyle);
6862
6973
  var expectedStyle = [];
6863
6974
  // styleMap is used when style is set to static value.
6864
- for (var _i32 = 0, n = styleDecls.length; _i32 < n; _i32++) {
6865
- var _styleDecls$_i2 = _slicedToArray(styleDecls[_i32], 3),
6975
+ for (var _i35 = 0, n = styleDecls.length; _i35 < n; _i35++) {
6976
+ var _styleDecls$_i2 = _slicedToArray(styleDecls[_i35], 3),
6866
6977
  prop = _styleDecls$_i2[0],
6867
6978
  value = _styleDecls$_i2[1],
6868
6979
  important = _styleDecls$_i2[2];
@@ -7050,8 +7161,8 @@ var LWC = (function (exports) {
7050
7161
  // Deep-traverse an array (of arrays) of stylesheet factory functions, and call the callback for every array/function
7051
7162
  function traverseStylesheets(stylesheets, callback) {
7052
7163
  callback(stylesheets);
7053
- for (var _i33 = 0; _i33 < stylesheets.length; _i33++) {
7054
- var stylesheet = stylesheets[_i33];
7164
+ for (var _i36 = 0; _i36 < stylesheets.length; _i36++) {
7165
+ var stylesheet = stylesheets[_i36];
7055
7166
  if (isArray$1(stylesheet)) {
7056
7167
  traverseStylesheets(stylesheet, callback);
7057
7168
  } else {
@@ -7164,7 +7275,7 @@ var LWC = (function (exports) {
7164
7275
  }
7165
7276
  return ctor;
7166
7277
  }
7167
- /* version: 2.33.0 */
7278
+ /* version: 2.34.0 */
7168
7279
 
7169
7280
  /*
7170
7281
  * Copyright (c) 2018, salesforce.com, inc.
@@ -7267,7 +7378,9 @@ var LWC = (function (exports) {
7267
7378
  //
7268
7379
  // Test utilities
7269
7380
  //
7270
- if (process.env.NODE_ENV === 'development') {
7381
+ // Only used in LWC's Karma tests
7382
+ // @ts-ignore
7383
+ if (process.env.NODE_ENV !== 'production' && typeof __karma__ !== 'undefined') {
7271
7384
  // @ts-ignore
7272
7385
  window.__lwcResetGlobalStylesheets = function () {
7273
7386
  stylesheetCache.clear();
@@ -8201,7 +8314,7 @@ var LWC = (function (exports) {
8201
8314
  function isNull(obj) {
8202
8315
  return obj === null;
8203
8316
  }
8204
- /** version: 2.33.0 */
8317
+ /** version: 2.34.0 */
8205
8318
 
8206
8319
  /*
8207
8320
  * Copyright (c) 2018, salesforce.com, inc.
@@ -8279,7 +8392,7 @@ var LWC = (function (exports) {
8279
8392
  doc.body.innerHTML = html;
8280
8393
  var content = doc.body;
8281
8394
  if (!isUndefined(wrapperTags)) {
8282
- for (var _i34 = 0; _i34 < wrapperTags.length; _i34++) {
8395
+ for (var _i37 = 0; _i37 < wrapperTags.length; _i37++) {
8283
8396
  content = content.firstChild;
8284
8397
  }
8285
8398
  }
@@ -8472,8 +8585,8 @@ var LWC = (function (exports) {
8472
8585
  tagName: element.tagName.toLowerCase(),
8473
8586
  hydrated: true
8474
8587
  });
8475
- for (var _i35 = 0, _Object$entries2 = Object.entries(props); _i35 < _Object$entries2.length; _i35++) {
8476
- var _Object$entries2$_i = _slicedToArray(_Object$entries2[_i35], 2),
8588
+ for (var _i38 = 0, _Object$entries2 = Object.entries(props); _i38 < _Object$entries2.length; _i38++) {
8589
+ var _Object$entries2$_i = _slicedToArray(_Object$entries2[_i38], 2),
8477
8590
  key = _Object$entries2$_i[0],
8478
8591
  value = _Object$entries2$_i[1];
8479
8592
  element[key] = value;
@@ -8767,7 +8880,7 @@ var LWC = (function (exports) {
8767
8880
  });
8768
8881
  freeze(LightningElement);
8769
8882
  seal(LightningElement.prototype);
8770
- /* version: 2.33.0 */
8883
+ /* version: 2.34.0 */
8771
8884
 
8772
8885
  exports.LightningElement = LightningElement;
8773
8886
  exports.__unstable__ProfilerControl = profilerControl;