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
@@ -352,9 +352,9 @@
352
352
  * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
353
353
  */
354
354
  // Increment whenever the LWC template compiler changes
355
- var LWC_VERSION = "2.33.0";
355
+ var LWC_VERSION = "2.34.0";
356
356
  var LWC_VERSION_COMMENT_REGEX = /\/\*LWC compiler v([\d.]+)\*\/\s*}/;
357
- /** version: 2.33.0 */
357
+ /** version: 2.34.0 */
358
358
 
359
359
  /**
360
360
  * Copyright (C) 2018 salesforce.com, inc.
@@ -376,7 +376,8 @@
376
376
  DISABLE_LIGHT_DOM_UNSCOPED_CSS: null,
377
377
  ENABLE_SCOPED_CUSTOM_ELEMENT_REGISTRY: null,
378
378
  ENABLE_FROZEN_TEMPLATE: null,
379
- DISABLE_ARIA_REFLECTION_POLYFILL: null
379
+ DISABLE_ARIA_REFLECTION_POLYFILL: null,
380
+ ENABLE_PROGRAMMATIC_STYLESHEETS: null
380
381
  };
381
382
  if (!_globalThis.lwcRuntimeFlags) {
382
383
  Object.defineProperty(_globalThis, 'lwcRuntimeFlags', {
@@ -432,7 +433,7 @@
432
433
  setFeatureFlag(name, value);
433
434
  }
434
435
  }
435
- /** version: 2.33.0 */
436
+ /** version: 2.34.0 */
436
437
 
437
438
  /**
438
439
  * Copyright (C) 2018 salesforce.com, inc.
@@ -496,7 +497,7 @@
496
497
  }
497
498
  }
498
499
  }
499
- /** version: 2.33.0 */
500
+ /** version: 2.34.0 */
500
501
 
501
502
  /*
502
503
  * Copyright (c) 2018, salesforce.com, inc.
@@ -853,6 +854,7 @@
853
854
  if (!isUndefined$1(vm)) {
854
855
  msg = "".concat(msg, "\n").concat(getComponentStack(vm));
855
856
  }
857
+ // In Jest tests, reduce the warning and error verbosity by not printing the callstack
856
858
  if (process.env.NODE_ENV === 'test') {
857
859
  /* eslint-disable-next-line no-console */
858
860
  console[method](msg);
@@ -911,6 +913,9 @@
911
913
  // Global HTML Attributes & Properties
912
914
  // https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes
913
915
  // https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement
916
+ //
917
+ // If you update this list, check for test files that recapitulate the same list. Searching the codebase
918
+ // for e.g. "dropzone" should suffice.
914
919
  var globalHTMLProperties = assign(create(null), {
915
920
  accessKey: {
916
921
  attribute: 'accesskey'
@@ -3568,6 +3573,7 @@
3568
3573
  setAttribute = _vm$renderer.setAttribute;
3569
3574
  var newStylesheets = template.stylesheets,
3570
3575
  newStylesheetToken = template.stylesheetToken;
3576
+ var newVmStylesheets = vm.stylesheets;
3571
3577
  var isSyntheticShadow = renderMode === 1 /* RenderMode.Shadow */ && shadowMode === 1 /* ShadowMode.Synthetic */;
3572
3578
  var hasScopedStyles = context.hasScopedStyles;
3573
3579
  var newToken;
@@ -3587,7 +3593,9 @@
3587
3593
  }
3588
3594
  // Apply the new template styling token to the host element, if the new template has any
3589
3595
  // associated stylesheets. In the case of light DOM, also ensure there is at least one scoped stylesheet.
3590
- if (!isUndefined$1(newStylesheets) && newStylesheets.length !== 0) {
3596
+ var hasNewStylesheets = hasStyles(newStylesheets);
3597
+ var hasNewVmStylesheets = hasStyles(newVmStylesheets);
3598
+ if (hasNewStylesheets || hasNewVmStylesheets) {
3591
3599
  newToken = newStylesheetToken;
3592
3600
  }
3593
3601
  // Set the new styling token on the host element
@@ -3657,10 +3665,15 @@
3657
3665
  function getStylesheetsContent(vm, template) {
3658
3666
  var stylesheets = template.stylesheets,
3659
3667
  stylesheetToken = template.stylesheetToken;
3668
+ var vmStylesheets = vm.stylesheets;
3660
3669
  var content = [];
3661
- if (!isUndefined$1(stylesheets) && stylesheets.length !== 0) {
3670
+ if (hasStyles(stylesheets)) {
3662
3671
  content = evaluateStylesheetsContent(stylesheets, stylesheetToken, vm);
3663
3672
  }
3673
+ // VM (component) stylesheets apply after template stylesheets
3674
+ if (hasStyles(vmStylesheets)) {
3675
+ ArrayPush$1.apply(content, evaluateStylesheetsContent(vmStylesheets, stylesheetToken, vm));
3676
+ }
3664
3677
  return content;
3665
3678
  }
3666
3679
  // It might be worth caching this to avoid doing the lookup repeatedly, but
@@ -3695,8 +3708,9 @@
3695
3708
  function getStylesheetTokenHost(vnode) {
3696
3709
  var _getComponentInternal = getComponentInternalDef(vnode.ctor),
3697
3710
  template = _getComponentInternal.template;
3711
+ var vm = vnode.vm;
3698
3712
  var stylesheetToken = template.stylesheetToken;
3699
- return !isUndefined$1(stylesheetToken) && computeHasScopedStyles(template) ? makeHostToken(stylesheetToken) : null;
3713
+ return !isUndefined$1(stylesheetToken) && computeHasScopedStyles(template, vm) ? makeHostToken(stylesheetToken) : null;
3700
3714
  }
3701
3715
  function getNearestNativeShadowComponent(vm) {
3702
3716
  var owner = getNearestShadowComponent(vm);
@@ -4285,6 +4299,26 @@
4285
4299
  // in fallback mode, the allocation will always set children to
4286
4300
  // empty and delegate the real allocation to the slot elements
4287
4301
  allocateChildren(n2, vm);
4302
+ // Solves an edge case with slotted VFragments in native shadow mode.
4303
+ //
4304
+ // During allocation, in native shadow, slotted VFragment nodes are flattened and their text delimiters are removed
4305
+ // to avoid interfering with native slot behavior. When this happens, if any of the fragments
4306
+ // were not stable, the children must go through the dynamic diffing algo.
4307
+ //
4308
+ // If the new children (n2.children) contain no VFragments, but the previous children (n1.children) were dynamic,
4309
+ // the new nodes must be marked dynamic so that all nodes are properly updated. The only indicator that the new
4310
+ // nodes need to be dynamic comes from the previous children, so we check that to determine whether we need to
4311
+ // mark the new children dynamic.
4312
+ //
4313
+ // Example:
4314
+ // n1.children: [div, VFragment('', div, null, ''), div] => [div, div, null, div]; // marked dynamic
4315
+ // n2.children: [div, null, div] => [div, null, div] // marked ???
4316
+ var shadowMode = vm.shadowMode,
4317
+ renderMode = vm.renderMode;
4318
+ if (shadowMode == 0 /* ShadowMode.Native */ && renderMode !== 0 /* RenderMode.Light */ && hasDynamicChildren(n1.children)) {
4319
+ // No-op if children has already been marked dynamic by 'allocateChildren()'.
4320
+ markAsDynamicChildren(n2.children);
4321
+ }
4288
4322
  }
4289
4323
  // in fallback mode, the children will be always empty, so, nothing
4290
4324
  // will happen, but in native, it does allocate the light dom
@@ -4463,7 +4497,6 @@
4463
4497
  //
4464
4498
  // In case #2, we will always get a fresh VCustomElement.
4465
4499
  var children = vnode.aChildren || vnode.children;
4466
- vm.aChildren = children;
4467
4500
  var renderMode = vm.renderMode,
4468
4501
  shadowMode = vm.shadowMode;
4469
4502
  if (process.env.NODE_ENV !== 'production') {
@@ -4476,15 +4509,61 @@
4476
4509
  logError("Invalid usage of 'lwc:slot-data' on ".concat(getComponentTag(vm), " tag. Scoped slot content can only be passed to a light dom child."));
4477
4510
  }
4478
4511
  }
4512
+ // If any of the children being allocated are VFragments, we remove the text delimiters and flatten all immediate
4513
+ // children VFragments to avoid them interfering with default slot behavior.
4514
+ var allocatedChildren = flattenFragmentsInChildren(children);
4515
+ vnode.children = allocatedChildren;
4516
+ vm.aChildren = allocatedChildren;
4479
4517
  if (shadowMode === 1 /* ShadowMode.Synthetic */ || renderMode === 0 /* RenderMode.Light */) {
4480
4518
  // slow path
4481
- allocateInSlot(vm, children, vnode.owner);
4519
+ allocateInSlot(vm, allocatedChildren, vnode.owner);
4482
4520
  // save the allocated children in case this vnode is reused.
4483
- vnode.aChildren = children;
4521
+ vnode.aChildren = allocatedChildren;
4484
4522
  // every child vnode is now allocated, and the host should receive none directly, it receives them via the shadow!
4485
4523
  vnode.children = EmptyArray;
4486
4524
  }
4487
4525
  }
4526
+ /**
4527
+ * Flattens the contents of all VFragments in an array of VNodes, removes the text delimiters on those VFragments, and
4528
+ * marks the resulting children array as dynamic. Uses a stack (array) to iteratively traverse the nested VFragments
4529
+ * and avoid the perf overhead of creating/destroying throwaway arrays/objects in a recursive approach.
4530
+ *
4531
+ * With the delimiters removed, the contents are marked dynamic so they are diffed correctly.
4532
+ *
4533
+ * This function is used for slotted VFragments to avoid the text delimiters interfering with slotting functionality.
4534
+ */
4535
+ function flattenFragmentsInChildren(children) {
4536
+ var flattenedChildren = [];
4537
+ // Initialize our stack with the direct children of the custom component and check whether we have a VFragment.
4538
+ // If no VFragment is found in children, we don't need to traverse anything or mark the children dynamic and can return early.
4539
+ var nodeStack = [];
4540
+ var fragmentFound = false;
4541
+ for (var _i15 = children.length - 1; _i15 > -1; _i15 -= 1) {
4542
+ var child = children[_i15];
4543
+ ArrayPush$1.call(nodeStack, child);
4544
+ fragmentFound = fragmentFound || !!(child && isVFragment(child));
4545
+ }
4546
+ if (!fragmentFound) {
4547
+ return children;
4548
+ }
4549
+ var currentNode;
4550
+ while (!isUndefined$1(currentNode = ArrayPop.call(nodeStack))) {
4551
+ if (!isNull(currentNode) && isVFragment(currentNode)) {
4552
+ var fChildren = currentNode.children;
4553
+ // Ignore the start and end text node delimiters
4554
+ for (var _i16 = fChildren.length - 2; _i16 > 0; _i16 -= 1) {
4555
+ ArrayPush$1.call(nodeStack, fChildren[_i16]);
4556
+ }
4557
+ } else {
4558
+ ArrayPush$1.call(flattenedChildren, currentNode);
4559
+ }
4560
+ }
4561
+ // We always mark the children as dynamic because nothing generates stable VFragments yet.
4562
+ // If/when stable VFragments are generated by the compiler, this code should be updated to
4563
+ // not mark dynamic if all flattened VFragments were stable.
4564
+ markAsDynamicChildren(flattenedChildren);
4565
+ return flattenedChildren;
4566
+ }
4488
4567
  function createViewModelHook(elm, vnode, renderer) {
4489
4568
  var vm = getAssociatedVMIfPresent(elm);
4490
4569
  // There is a possibility that a custom element is registered under tagName, in which case, the
@@ -4507,22 +4586,16 @@
4507
4586
  }
4508
4587
  return vm;
4509
4588
  }
4510
- /**
4511
- * Collects all slots into a SlotSet, traversing through VFragment Nodes
4512
- */
4513
- function collectSlots(vm, children, cmpSlotsMapping) {
4589
+ function allocateInSlot(vm, children, owner) {
4514
4590
  var _a, _b;
4515
- for (var _i15 = 0, len = children.length; _i15 < len; _i15 += 1) {
4516
- var vnode = children[_i15];
4591
+ var oldSlotsMapping = vm.cmpSlots.slotAssignments;
4592
+ var cmpSlotsMapping = create(null);
4593
+ // Collect all slots into cmpSlotsMapping
4594
+ for (var _i17 = 0, len = children.length; _i17 < len; _i17 += 1) {
4595
+ var vnode = children[_i17];
4517
4596
  if (isNull(vnode)) {
4518
4597
  continue;
4519
4598
  }
4520
- // Dive further iff the content is wrapped in a VFragment
4521
- if (isVFragment(vnode)) {
4522
- // Remove the text delimiter nodes to avoid overriding default slot content
4523
- collectSlots(vm, vnode.children.slice(1, -1), cmpSlotsMapping);
4524
- continue;
4525
- }
4526
4599
  var slotName = '';
4527
4600
  if (isVBaseElement(vnode)) {
4528
4601
  slotName = (_b = (_a = vnode.data.attrs) === null || _a === void 0 ? void 0 : _a.slot) !== null && _b !== void 0 ? _b : '';
@@ -4532,11 +4605,6 @@
4532
4605
  var vnodes = cmpSlotsMapping[slotName] = cmpSlotsMapping[slotName] || [];
4533
4606
  ArrayPush$1.call(vnodes, vnode);
4534
4607
  }
4535
- }
4536
- function allocateInSlot(vm, children, owner) {
4537
- var oldSlotsMapping = vm.cmpSlots.slotAssignments;
4538
- var cmpSlotsMapping = create(null);
4539
- collectSlots(vm, children, cmpSlotsMapping);
4540
4608
  vm.cmpSlots = {
4541
4609
  owner: owner,
4542
4610
  slotAssignments: cmpSlotsMapping
@@ -4549,16 +4617,16 @@
4549
4617
  markComponentAsDirty(vm);
4550
4618
  return;
4551
4619
  }
4552
- for (var _i16 = 0, len = oldKeys.length; _i16 < len; _i16 += 1) {
4553
- var key = oldKeys[_i16];
4620
+ for (var _i18 = 0, _len2 = oldKeys.length; _i18 < _len2; _i18 += 1) {
4621
+ var key = oldKeys[_i18];
4554
4622
  if (isUndefined$1(cmpSlotsMapping[key]) || oldSlotsMapping[key].length !== cmpSlotsMapping[key].length) {
4555
4623
  markComponentAsDirty(vm);
4556
4624
  return;
4557
4625
  }
4558
4626
  var oldVNodes = oldSlotsMapping[key];
4559
- var vnodes = cmpSlotsMapping[key];
4627
+ var _vnodes = cmpSlotsMapping[key];
4560
4628
  for (var j = 0, a = cmpSlotsMapping[key].length; j < a; j += 1) {
4561
- if (oldVNodes[j] !== vnodes[j]) {
4629
+ if (oldVNodes[j] !== _vnodes[j]) {
4562
4630
  markComponentAsDirty(vm);
4563
4631
  return;
4564
4632
  }
@@ -4567,14 +4635,14 @@
4567
4635
  }
4568
4636
  }
4569
4637
  // Using a WeakMap instead of a WeakSet because this one works in IE11 :(
4570
- var FromIteration = new WeakMap();
4571
- // dynamic children means it was generated by an iteration
4572
- // in a template, and will require a more complex diffing algo.
4638
+ var DynamicChildren = new WeakMap();
4639
+ // dynamic children means it was either generated by an iteration in a template
4640
+ // or part of an unstable fragment, and will require a more complex diffing algo.
4573
4641
  function markAsDynamicChildren(children) {
4574
- FromIteration.set(children, 1);
4642
+ DynamicChildren.set(children, 1);
4575
4643
  }
4576
4644
  function hasDynamicChildren(children) {
4577
- return FromIteration.has(children);
4645
+ return DynamicChildren.has(children);
4578
4646
  }
4579
4647
  function createKeyToOldIdx(children, beginIdx, endIdx) {
4580
4648
  var map = {};
@@ -4673,11 +4741,11 @@
4673
4741
  if (oldStartIdx > oldEndIdx) {
4674
4742
  // There's some cases in which the sub array of vnodes to be inserted is followed by null(s) and an
4675
4743
  // already processed vnode, in such cases the vnodes to be inserted should be before that processed vnode.
4676
- var _i17 = newEndIdx;
4744
+ var _i19 = newEndIdx;
4677
4745
  var n;
4678
4746
  do {
4679
- n = newCh[++_i17];
4680
- } while (!isVNode(n) && _i17 < newChEnd);
4747
+ n = newCh[++_i19];
4748
+ } while (!isVNode(n) && _i19 < newChEnd);
4681
4749
  before = isVNode(n) ? n.elm : null;
4682
4750
  mountVNodes(newCh, parent, renderer, before, newStartIdx, newEndIdx + 1);
4683
4751
  } else {
@@ -4702,9 +4770,9 @@
4702
4770
  // if the old list is not empty, the new list MUST have the same
4703
4771
  // amount of nodes, that's why we call this static children
4704
4772
  var anchor = null;
4705
- for (var _i18 = c2Length - 1; _i18 >= 0; _i18 -= 1) {
4706
- var n1 = c1[_i18];
4707
- var n2 = c2[_i18];
4773
+ for (var _i20 = c2Length - 1; _i20 >= 0; _i20 -= 1) {
4774
+ var n1 = c1[_i20];
4775
+ var n2 = c2[_i20];
4708
4776
  if (n2 !== n1) {
4709
4777
  if (isVNode(n1)) {
4710
4778
  if (isVNode(n2)) {
@@ -4829,8 +4897,8 @@
4829
4897
  if (!isUndefined$1(slotset) && !isUndefined$1(slotset.slotAssignments) && !isUndefined$1(slotset.slotAssignments[slotName]) && slotset.slotAssignments[slotName].length !== 0) {
4830
4898
  var newChildren = [];
4831
4899
  var slotAssignments = slotset.slotAssignments[slotName];
4832
- for (var _i19 = 0; _i19 < slotAssignments.length; _i19++) {
4833
- var vnode = slotAssignments[_i19];
4900
+ for (var _i21 = 0; _i21 < slotAssignments.length; _i21++) {
4901
+ var vnode = slotAssignments[_i21];
4834
4902
  if (!isNull(vnode)) {
4835
4903
  var assignedNodeIsScopedSlot = isVScopedSlotFragment(vnode);
4836
4904
  // The only sniff test for a scoped <slot> element is the presence of `slotData`
@@ -5326,7 +5394,7 @@
5326
5394
  }
5327
5395
  function buildParseFragmentFn(createFragmentFn) {
5328
5396
  return function (strings) {
5329
- for (var _len2 = arguments.length, keys = new Array(_len2 > 1 ? _len2 - 1 : 0), _key3 = 1; _key3 < _len2; _key3++) {
5397
+ for (var _len3 = arguments.length, keys = new Array(_len3 > 1 ? _len3 - 1 : 0), _key3 = 1; _key3 < _len3; _key3++) {
5330
5398
  keys[_key3 - 1] = arguments[_key3];
5331
5399
  }
5332
5400
  var cache = create(null);
@@ -5355,23 +5423,23 @@
5355
5423
  var classAttrToken = hasScopedStyles && hasStyleToken ? " class=\"".concat(stylesheetToken, "\"") : '';
5356
5424
  var attrToken = hasStyleToken && isSyntheticShadow ? ' ' + stylesheetToken : '';
5357
5425
  var htmlFragment = '';
5358
- for (var _i20 = 0, n = keys.length; _i20 < n; _i20++) {
5359
- switch (keys[_i20]) {
5426
+ for (var _i22 = 0, n = keys.length; _i22 < n; _i22++) {
5427
+ switch (keys[_i22]) {
5360
5428
  case 0:
5361
5429
  // styleToken in existing class attr
5362
- htmlFragment += strings[_i20] + classToken;
5430
+ htmlFragment += strings[_i22] + classToken;
5363
5431
  break;
5364
5432
  case 1:
5365
5433
  // styleToken for added class attr
5366
- htmlFragment += strings[_i20] + classAttrToken;
5434
+ htmlFragment += strings[_i22] + classAttrToken;
5367
5435
  break;
5368
5436
  case 2:
5369
5437
  // styleToken as attr
5370
- htmlFragment += strings[_i20] + attrToken;
5438
+ htmlFragment += strings[_i22] + attrToken;
5371
5439
  break;
5372
5440
  case 3:
5373
5441
  // ${1}${2}
5374
- htmlFragment += strings[_i20] + classAttrToken + attrToken;
5442
+ htmlFragment += strings[_i22] + classAttrToken + attrToken;
5375
5443
  break;
5376
5444
  }
5377
5445
  }
@@ -5436,7 +5504,7 @@
5436
5504
  // Create a brand new template cache for the swapped templated.
5437
5505
  context.tplCache = create(null);
5438
5506
  // Set the computeHasScopedStyles property in the context, to avoid recomputing it repeatedly.
5439
- context.hasScopedStyles = computeHasScopedStyles(html);
5507
+ context.hasScopedStyles = computeHasScopedStyles(html, vm);
5440
5508
  // Update the scoping token on the host element.
5441
5509
  updateStylesheetToken(vm, html);
5442
5510
  // Evaluate, create stylesheet and cache the produced VNode for future
@@ -5476,17 +5544,24 @@
5476
5544
  }
5477
5545
  return vnodes;
5478
5546
  }
5479
- function computeHasScopedStyles(template) {
5480
- var stylesheets = template.stylesheets;
5481
- if (!isUndefined$1(stylesheets)) {
5482
- for (var _i21 = 0; _i21 < stylesheets.length; _i21++) {
5483
- if (isTrue(stylesheets[_i21][KEY__SCOPED_CSS])) {
5547
+ function computeHasScopedStylesInStylesheets(stylesheets) {
5548
+ if (hasStyles(stylesheets)) {
5549
+ for (var _i23 = 0; _i23 < stylesheets.length; _i23++) {
5550
+ if (isTrue(stylesheets[_i23][KEY__SCOPED_CSS])) {
5484
5551
  return true;
5485
5552
  }
5486
5553
  }
5487
5554
  }
5488
5555
  return false;
5489
5556
  }
5557
+ function computeHasScopedStyles(template, vm) {
5558
+ var stylesheets = template.stylesheets;
5559
+ var vmStylesheets = !isUndefined$1(vm) ? vm.stylesheets : null;
5560
+ return computeHasScopedStylesInStylesheets(stylesheets) || computeHasScopedStylesInStylesheets(vmStylesheets);
5561
+ }
5562
+ function hasStyles(stylesheets) {
5563
+ return !isUndefined$1(stylesheets) && !isNull(stylesheets) && stylesheets.length > 0;
5564
+ }
5490
5565
 
5491
5566
  /*
5492
5567
  * Copyright (c) 2018, salesforce.com, inc.
@@ -5668,8 +5743,8 @@
5668
5743
  if (process.env.NODE_ENV !== 'production') {
5669
5744
  assert.isTrue(isObject(service), "Invalid service declaration, ".concat(service, ": service must be an object"));
5670
5745
  }
5671
- for (var _i22 = 0; _i22 < hooks.length; ++_i22) {
5672
- var hookName = hooks[_i22];
5746
+ for (var _i24 = 0; _i24 < hooks.length; ++_i24) {
5747
+ var hookName = hooks[_i24];
5673
5748
  if (hookName in service) {
5674
5749
  var l = Services[hookName];
5675
5750
  if (isUndefined$1(l)) {
@@ -5686,8 +5761,8 @@
5686
5761
  var component = vm.component,
5687
5762
  def = vm.def,
5688
5763
  context = vm.context;
5689
- for (var _i23 = 0, len = cbs.length; _i23 < len; ++_i23) {
5690
- cbs[_i23].call(undefined, component, {}, def, context);
5764
+ for (var _i25 = 0, len = cbs.length; _i25 < len; ++_i25) {
5765
+ cbs[_i25].call(undefined, component, {}, def, context);
5691
5766
  }
5692
5767
  }
5693
5768
 
@@ -5806,6 +5881,7 @@
5806
5881
  // Properties set right after VM creation.
5807
5882
  tro: null,
5808
5883
  shadowMode: null,
5884
+ stylesheets: null,
5809
5885
  // Properties set by the LightningElement constructor.
5810
5886
  component: null,
5811
5887
  shadowRoot: null,
@@ -5818,6 +5894,7 @@
5818
5894
  if (process.env.NODE_ENV !== 'production') {
5819
5895
  vm.debugInfo = create(null);
5820
5896
  }
5897
+ vm.stylesheets = computeStylesheets(vm, def.ctor);
5821
5898
  vm.shadowMode = computeShadowMode(vm, renderer);
5822
5899
  vm.tro = getTemplateReactiveObserver(vm);
5823
5900
  if (process.env.NODE_ENV !== 'production') {
@@ -5836,6 +5913,40 @@
5836
5913
  }
5837
5914
  return vm;
5838
5915
  }
5916
+ function validateComponentStylesheets(vm, stylesheets) {
5917
+ var valid = true;
5918
+ var validate = function validate(arrayOrStylesheet) {
5919
+ if (isArray$1(arrayOrStylesheet)) {
5920
+ for (var _i26 = 0; _i26 < arrayOrStylesheet.length; _i26++) {
5921
+ validate(arrayOrStylesheet[_i26]);
5922
+ }
5923
+ } else if (!isFunction$1(arrayOrStylesheet)) {
5924
+ // function assumed to be a stylesheet factory
5925
+ valid = false;
5926
+ }
5927
+ };
5928
+ if (!isArray$1(stylesheets)) {
5929
+ valid = false;
5930
+ } else {
5931
+ validate(stylesheets);
5932
+ }
5933
+ return valid;
5934
+ }
5935
+ // Validate and flatten any stylesheets defined as `static stylesheets`
5936
+ function computeStylesheets(vm, ctor) {
5937
+ if (lwcRuntimeFlags.ENABLE_PROGRAMMATIC_STYLESHEETS) {
5938
+ var stylesheets = ctor.stylesheets;
5939
+ if (!isUndefined$1(stylesheets)) {
5940
+ var valid = validateComponentStylesheets(vm, stylesheets);
5941
+ if (valid) {
5942
+ return flattenStylesheets(stylesheets);
5943
+ } else if (process.env.NODE_ENV !== 'production') {
5944
+ logError("static stylesheets must be an array of CSS stylesheets. Found invalid stylesheets on <".concat(vm.tagName, ">"), vm);
5945
+ }
5946
+ }
5947
+ }
5948
+ return null;
5949
+ }
5839
5950
  function computeShadowMode(vm, renderer) {
5840
5951
  var def = vm.def;
5841
5952
  var isSyntheticShadowDefined = renderer.isSyntheticShadowDefined,
@@ -5960,17 +6071,17 @@
5960
6071
  return a.idx - b.idx;
5961
6072
  });
5962
6073
  rehydrateQueue = []; // reset to a new queue
5963
- for (var _i24 = 0, len = vms.length; _i24 < len; _i24 += 1) {
5964
- var vm = vms[_i24];
6074
+ for (var _i27 = 0, len = vms.length; _i27 < len; _i27 += 1) {
6075
+ var vm = vms[_i27];
5965
6076
  try {
5966
6077
  rehydrate(vm);
5967
6078
  } catch (error) {
5968
- if (_i24 + 1 < len) {
6079
+ if (_i27 + 1 < len) {
5969
6080
  // pieces of the queue are still pending to be rehydrated, those should have priority
5970
6081
  if (rehydrateQueue.length === 0) {
5971
6082
  addCallbackToNextTick(flushRehydrationQueue);
5972
6083
  }
5973
- ArrayUnshift.apply(rehydrateQueue, ArraySlice.call(vms, _i24 + 1));
6084
+ ArrayUnshift.apply(rehydrateQueue, ArraySlice.call(vms, _i27 + 1));
5974
6085
  }
5975
6086
  // we need to end the measure before throwing.
5976
6087
  logGlobalOperationEnd(8 /* OperationId.GlobalRehydrate */);
@@ -6039,8 +6150,8 @@
6039
6150
  var vCustomElementCollection = vm.velements;
6040
6151
  // Reporting disconnection for every child in inverse order since they are
6041
6152
  // inserted in reserved order.
6042
- for (var _i25 = vCustomElementCollection.length - 1; _i25 >= 0; _i25 -= 1) {
6043
- var elm = vCustomElementCollection[_i25].elm;
6153
+ for (var _i28 = vCustomElementCollection.length - 1; _i28 >= 0; _i28 -= 1) {
6154
+ var elm = vCustomElementCollection[_i28].elm;
6044
6155
  // There are two cases where the element could be undefined:
6045
6156
  // * when there is an error during the construction phase, and an error
6046
6157
  // boundary picks it, there is a possibility that the VCustomElement
@@ -6071,8 +6182,8 @@
6071
6182
  * defined on its shadow.
6072
6183
  */
6073
6184
  function recursivelyDisconnectChildren(vnodes) {
6074
- for (var _i26 = 0, len = vnodes.length; _i26 < len; _i26 += 1) {
6075
- var vnode = vnodes[_i26];
6185
+ for (var _i29 = 0, len = vnodes.length; _i29 < len; _i29 += 1) {
6186
+ var vnode = vnodes[_i29];
6076
6187
  if (!isNull(vnode) && !isUndefined$1(vnode.elm)) {
6077
6188
  switch (vnode.type) {
6078
6189
  case 2 /* VNodeType.Element */:
@@ -6096,8 +6207,8 @@
6096
6207
  var children = vm.children,
6097
6208
  renderRoot = vm.renderRoot,
6098
6209
  remove = vm.renderer.remove;
6099
- for (var _i27 = 0, len = children.length; _i27 < len; _i27++) {
6100
- var child = children[_i27];
6210
+ for (var _i30 = 0, len = children.length; _i30 < len; _i30++) {
6211
+ var child = children[_i30];
6101
6212
  if (!isNull(child) && !isUndefined$1(child.elm)) {
6102
6213
  remove(child.elm, renderRoot);
6103
6214
  }
@@ -6435,16 +6546,16 @@
6435
6546
  }
6436
6547
  function connectWireAdapters(vm) {
6437
6548
  var wiredConnecting = vm.context.wiredConnecting;
6438
- for (var _i28 = 0, len = wiredConnecting.length; _i28 < len; _i28 += 1) {
6439
- wiredConnecting[_i28]();
6549
+ for (var _i31 = 0, len = wiredConnecting.length; _i31 < len; _i31 += 1) {
6550
+ wiredConnecting[_i31]();
6440
6551
  }
6441
6552
  }
6442
6553
  function disconnectWireAdapters(vm) {
6443
6554
  var wiredDisconnecting = vm.context.wiredDisconnecting;
6444
6555
  runWithBoundaryProtection(vm, vm, noop, function () {
6445
6556
  // job
6446
- for (var _i29 = 0, len = wiredDisconnecting.length; _i29 < len; _i29 += 1) {
6447
- wiredDisconnecting[_i29]();
6557
+ for (var _i32 = 0, len = wiredDisconnecting.length; _i32 < len; _i32 += 1) {
6558
+ wiredDisconnecting[_i32]();
6448
6559
  }
6449
6560
  }, noop);
6450
6561
  }
@@ -6683,8 +6794,8 @@
6683
6794
  var nextNode = node;
6684
6795
  var anchor = null;
6685
6796
  var renderer = owner.renderer;
6686
- for (var _i30 = 0; _i30 < children.length; _i30++) {
6687
- var childVnode = children[_i30];
6797
+ for (var _i33 = 0; _i33 < children.length; _i33++) {
6798
+ var childVnode = children[_i33];
6688
6799
  if (!isNull(childVnode)) {
6689
6800
  if (nextNode) {
6690
6801
  nextNode = hydrateNode(nextNode, childVnode, renderer);
@@ -6762,8 +6873,8 @@
6762
6873
  var nodesAreCompatible = true;
6763
6874
  // Validate attributes, though we could always recovery from those by running the update mods.
6764
6875
  // Note: intentionally ONLY matching vnodes.attrs to elm.attrs, in case SSR is adding extra attributes.
6765
- for (var _i31 = 0, _Object$entries = Object.entries(attrs); _i31 < _Object$entries.length; _i31++) {
6766
- var _Object$entries$_i = _slicedToArray(_Object$entries[_i31], 2),
6876
+ for (var _i34 = 0, _Object$entries = Object.entries(attrs); _i34 < _Object$entries.length; _i34++) {
6877
+ var _Object$entries$_i = _slicedToArray(_Object$entries[_i34], 2),
6767
6878
  attrName = _Object$entries$_i[0],
6768
6879
  attrValue = _Object$entries$_i[1];
6769
6880
  var owner = vnode.owner;
@@ -6864,8 +6975,8 @@
6864
6975
  var parsedVnodeStyle = parseStyleText(elmStyle);
6865
6976
  var expectedStyle = [];
6866
6977
  // styleMap is used when style is set to static value.
6867
- for (var _i32 = 0, n = styleDecls.length; _i32 < n; _i32++) {
6868
- var _styleDecls$_i2 = _slicedToArray(styleDecls[_i32], 3),
6978
+ for (var _i35 = 0, n = styleDecls.length; _i35 < n; _i35++) {
6979
+ var _styleDecls$_i2 = _slicedToArray(styleDecls[_i35], 3),
6869
6980
  prop = _styleDecls$_i2[0],
6870
6981
  value = _styleDecls$_i2[1],
6871
6982
  important = _styleDecls$_i2[2];
@@ -7053,8 +7164,8 @@
7053
7164
  // Deep-traverse an array (of arrays) of stylesheet factory functions, and call the callback for every array/function
7054
7165
  function traverseStylesheets(stylesheets, callback) {
7055
7166
  callback(stylesheets);
7056
- for (var _i33 = 0; _i33 < stylesheets.length; _i33++) {
7057
- var stylesheet = stylesheets[_i33];
7167
+ for (var _i36 = 0; _i36 < stylesheets.length; _i36++) {
7168
+ var stylesheet = stylesheets[_i36];
7058
7169
  if (isArray$1(stylesheet)) {
7059
7170
  traverseStylesheets(stylesheet, callback);
7060
7171
  } else {
@@ -7167,7 +7278,7 @@
7167
7278
  }
7168
7279
  return ctor;
7169
7280
  }
7170
- /* version: 2.33.0 */
7281
+ /* version: 2.34.0 */
7171
7282
 
7172
7283
  /*
7173
7284
  * Copyright (c) 2018, salesforce.com, inc.
@@ -7270,7 +7381,9 @@
7270
7381
  //
7271
7382
  // Test utilities
7272
7383
  //
7273
- if (process.env.NODE_ENV === 'development') {
7384
+ // Only used in LWC's Karma tests
7385
+ // @ts-ignore
7386
+ if (process.env.NODE_ENV !== 'production' && typeof __karma__ !== 'undefined') {
7274
7387
  // @ts-ignore
7275
7388
  window.__lwcResetGlobalStylesheets = function () {
7276
7389
  stylesheetCache.clear();
@@ -8204,7 +8317,7 @@
8204
8317
  function isNull(obj) {
8205
8318
  return obj === null;
8206
8319
  }
8207
- /** version: 2.33.0 */
8320
+ /** version: 2.34.0 */
8208
8321
 
8209
8322
  /*
8210
8323
  * Copyright (c) 2018, salesforce.com, inc.
@@ -8282,7 +8395,7 @@
8282
8395
  doc.body.innerHTML = html;
8283
8396
  var content = doc.body;
8284
8397
  if (!isUndefined(wrapperTags)) {
8285
- for (var _i34 = 0; _i34 < wrapperTags.length; _i34++) {
8398
+ for (var _i37 = 0; _i37 < wrapperTags.length; _i37++) {
8286
8399
  content = content.firstChild;
8287
8400
  }
8288
8401
  }
@@ -8475,8 +8588,8 @@
8475
8588
  tagName: element.tagName.toLowerCase(),
8476
8589
  hydrated: true
8477
8590
  });
8478
- for (var _i35 = 0, _Object$entries2 = Object.entries(props); _i35 < _Object$entries2.length; _i35++) {
8479
- var _Object$entries2$_i = _slicedToArray(_Object$entries2[_i35], 2),
8591
+ for (var _i38 = 0, _Object$entries2 = Object.entries(props); _i38 < _Object$entries2.length; _i38++) {
8592
+ var _Object$entries2$_i = _slicedToArray(_Object$entries2[_i38], 2),
8480
8593
  key = _Object$entries2$_i[0],
8481
8594
  value = _Object$entries2$_i[1];
8482
8595
  element[key] = value;
@@ -8770,7 +8883,7 @@
8770
8883
  });
8771
8884
  freeze(LightningElement);
8772
8885
  seal(LightningElement.prototype);
8773
- /* version: 2.33.0 */
8886
+ /* version: 2.34.0 */
8774
8887
 
8775
8888
  exports.LightningElement = LightningElement;
8776
8889
  exports.__unstable__ProfilerControl = profilerControl;