@lwc/engine-core 2.13.0 → 2.13.3

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.
@@ -440,6 +440,20 @@ function logWarn(message, vm) {
440
440
  log('warn', message, vm);
441
441
  }
442
442
 
443
+ /*
444
+ * Copyright (c) 2020, salesforce.com, inc.
445
+ * All rights reserved.
446
+ * SPDX-License-Identifier: MIT
447
+ * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
448
+ */
449
+ function resolveCircularModuleDependency(fn) {
450
+ const module = fn();
451
+ return (module === null || module === void 0 ? void 0 : module.__esModule) ? module.default : module;
452
+ }
453
+ function isCircularModuleDependency(obj) {
454
+ return shared.isFunction(obj) && shared.hasOwnProperty.call(obj, '__circular__');
455
+ }
456
+
443
457
  /*
444
458
  * Copyright (c) 2018, salesforce.com, inc.
445
459
  * All rights reserved.
@@ -1805,64 +1819,7 @@ if (process.env.NODE_ENV !== 'production') {
1805
1819
  patchLightningElementPrototypeWithRestrictions(LightningElement.prototype);
1806
1820
  }
1807
1821
 
1808
- /*
1809
- * Copyright (c) 2018, salesforce.com, inc.
1810
- * All rights reserved.
1811
- * SPDX-License-Identifier: MIT
1812
- * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
1813
- */
1814
- /**
1815
- * @wire decorator to wire fields and methods to a wire adapter in
1816
- * LWC Components. This function implements the internals of this
1817
- * decorator.
1818
- */
1819
- function wire(_adapter, _config) {
1820
- if (process.env.NODE_ENV !== 'production') {
1821
- shared.assert.fail('@wire(adapter, config?) may only be used as a decorator.');
1822
- }
1823
- throw new Error();
1824
- }
1825
- function internalWireFieldDecorator(key) {
1826
- return {
1827
- get() {
1828
- const vm = getAssociatedVM(this);
1829
- componentValueObserved(vm, key);
1830
- return vm.cmpFields[key];
1831
- },
1832
- set(value) {
1833
- const vm = getAssociatedVM(this);
1834
- /**
1835
- * Reactivity for wired fields is provided in wiring.
1836
- * We intentionally add reactivity here since this is just
1837
- * letting the author to do the wrong thing, but it will keep our
1838
- * system to be backward compatible.
1839
- */
1840
- if (value !== vm.cmpFields[key]) {
1841
- vm.cmpFields[key] = value;
1842
- componentValueMutated(vm, key);
1843
- }
1844
- },
1845
- enumerable: true,
1846
- configurable: true,
1847
- };
1848
- }
1849
-
1850
- /*
1851
- * Copyright (c) 2018, salesforce.com, inc.
1852
- * All rights reserved.
1853
- * SPDX-License-Identifier: MIT
1854
- * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
1855
- */
1856
- function track(target) {
1857
- if (arguments.length === 1) {
1858
- return reactiveMembrane.getProxy(target);
1859
- }
1860
- if (process.env.NODE_ENV !== 'production') {
1861
- shared.assert.fail(`@track decorator can only be used with one argument to return a trackable object, or as a decorator function.`);
1862
- }
1863
- throw new Error();
1864
- }
1865
- function internalTrackDecorator(key) {
1822
+ function createObservedFieldPropertyDescriptor(key) {
1866
1823
  return {
1867
1824
  get() {
1868
1825
  const vm = getAssociatedVM(this);
@@ -1871,14 +1828,8 @@ function internalTrackDecorator(key) {
1871
1828
  },
1872
1829
  set(newValue) {
1873
1830
  const vm = getAssociatedVM(this);
1874
- if (process.env.NODE_ENV !== 'production') {
1875
- const vmBeingRendered = getVMBeingRendered();
1876
- shared.assert.invariant(!isInvokingRender, `${vmBeingRendered}.render() method has side effects on the state of ${vm}.${shared.toString(key)}`);
1877
- shared.assert.invariant(!isUpdatingTemplate, `Updating the template of ${vmBeingRendered} has side effects on the state of ${vm}.${shared.toString(key)}`);
1878
- }
1879
- const reactiveOrAnyValue = reactiveMembrane.getProxy(newValue);
1880
- if (reactiveOrAnyValue !== vm.cmpFields[key]) {
1881
- vm.cmpFields[key] = reactiveOrAnyValue;
1831
+ if (newValue !== vm.cmpFields[key]) {
1832
+ vm.cmpFields[key] = newValue;
1882
1833
  componentValueMutated(vm, key);
1883
1834
  }
1884
1835
  },
@@ -2042,7 +1993,22 @@ function createPublicAccessorDescriptor(key, descriptor) {
2042
1993
  };
2043
1994
  }
2044
1995
 
2045
- function createObservedFieldPropertyDescriptor(key) {
1996
+ /*
1997
+ * Copyright (c) 2018, salesforce.com, inc.
1998
+ * All rights reserved.
1999
+ * SPDX-License-Identifier: MIT
2000
+ * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
2001
+ */
2002
+ function track(target) {
2003
+ if (arguments.length === 1) {
2004
+ return reactiveMembrane.getProxy(target);
2005
+ }
2006
+ if (process.env.NODE_ENV !== 'production') {
2007
+ shared.assert.fail(`@track decorator can only be used with one argument to return a trackable object, or as a decorator function.`);
2008
+ }
2009
+ throw new Error();
2010
+ }
2011
+ function internalTrackDecorator(key) {
2046
2012
  return {
2047
2013
  get() {
2048
2014
  const vm = getAssociatedVM(this);
@@ -2051,8 +2017,56 @@ function createObservedFieldPropertyDescriptor(key) {
2051
2017
  },
2052
2018
  set(newValue) {
2053
2019
  const vm = getAssociatedVM(this);
2054
- if (newValue !== vm.cmpFields[key]) {
2055
- vm.cmpFields[key] = newValue;
2020
+ if (process.env.NODE_ENV !== 'production') {
2021
+ const vmBeingRendered = getVMBeingRendered();
2022
+ shared.assert.invariant(!isInvokingRender, `${vmBeingRendered}.render() method has side effects on the state of ${vm}.${shared.toString(key)}`);
2023
+ shared.assert.invariant(!isUpdatingTemplate, `Updating the template of ${vmBeingRendered} has side effects on the state of ${vm}.${shared.toString(key)}`);
2024
+ }
2025
+ const reactiveOrAnyValue = reactiveMembrane.getProxy(newValue);
2026
+ if (reactiveOrAnyValue !== vm.cmpFields[key]) {
2027
+ vm.cmpFields[key] = reactiveOrAnyValue;
2028
+ componentValueMutated(vm, key);
2029
+ }
2030
+ },
2031
+ enumerable: true,
2032
+ configurable: true,
2033
+ };
2034
+ }
2035
+
2036
+ /*
2037
+ * Copyright (c) 2018, salesforce.com, inc.
2038
+ * All rights reserved.
2039
+ * SPDX-License-Identifier: MIT
2040
+ * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
2041
+ */
2042
+ /**
2043
+ * @wire decorator to wire fields and methods to a wire adapter in
2044
+ * LWC Components. This function implements the internals of this
2045
+ * decorator.
2046
+ */
2047
+ function wire(_adapter, _config) {
2048
+ if (process.env.NODE_ENV !== 'production') {
2049
+ shared.assert.fail('@wire(adapter, config?) may only be used as a decorator.');
2050
+ }
2051
+ throw new Error();
2052
+ }
2053
+ function internalWireFieldDecorator(key) {
2054
+ return {
2055
+ get() {
2056
+ const vm = getAssociatedVM(this);
2057
+ componentValueObserved(vm, key);
2058
+ return vm.cmpFields[key];
2059
+ },
2060
+ set(value) {
2061
+ const vm = getAssociatedVM(this);
2062
+ /**
2063
+ * Reactivity for wired fields is provided in wiring.
2064
+ * We intentionally add reactivity here since this is just
2065
+ * letting the author to do the wrong thing, but it will keep our
2066
+ * system to be backward compatible.
2067
+ */
2068
+ if (value !== vm.cmpFields[key]) {
2069
+ vm.cmpFields[key] = value;
2056
2070
  componentValueMutated(vm, key);
2057
2071
  }
2058
2072
  },
@@ -2307,6 +2321,12 @@ function checkVersionMismatch(func, type) {
2307
2321
  }
2308
2322
  }
2309
2323
 
2324
+ /*
2325
+ * Copyright (c) 2018, salesforce.com, inc.
2326
+ * All rights reserved.
2327
+ * SPDX-License-Identifier: MIT
2328
+ * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
2329
+ */
2310
2330
  const signedTemplateSet = new Set();
2311
2331
  function defaultEmptyTemplate() {
2312
2332
  return [];
@@ -2324,6 +2344,30 @@ function registerTemplate(tpl) {
2324
2344
  checkVersionMismatch(tpl, 'template');
2325
2345
  }
2326
2346
  signedTemplateSet.add(tpl);
2347
+ // FIXME[@W-10950976]: the template object should be frozen, and it should not be possible to set
2348
+ // the stylesheets or stylesheetToken(s). For backwards compat, though, we shim stylesheetTokens
2349
+ // on top of stylesheetToken for anyone who is accessing the old internal API.
2350
+ // Details: https://salesforce.quip.com/v1rmAFu2cKAr
2351
+ shared.defineProperty(tpl, 'stylesheetTokens', {
2352
+ get() {
2353
+ const { stylesheetToken } = this;
2354
+ if (shared.isUndefined(stylesheetToken)) {
2355
+ return stylesheetToken;
2356
+ }
2357
+ // Shim for the old `stylesheetTokens` property
2358
+ // See https://github.com/salesforce/lwc/pull/2332/files#diff-7901555acef29969adaa6583185b3e9bce475cdc6f23e799a54e0018cb18abaa
2359
+ return {
2360
+ hostAttribute: `${stylesheetToken}-host`,
2361
+ shadowAttribute: stylesheetToken,
2362
+ };
2363
+ },
2364
+ set(value) {
2365
+ // If the value is null or some other exotic object, you would be broken anyway in the past
2366
+ // because the engine would try to access hostAttribute/shadowAttribute, which would throw an error.
2367
+ // However it may be undefined in newer versions of LWC, so we need to guard against that case.
2368
+ this.stylesheetToken = shared.isUndefined(value) ? undefined : value.shadowAttribute;
2369
+ },
2370
+ });
2327
2371
  // chaining this method as a way to wrap existing
2328
2372
  // assignment of templates easily, without too much transformation
2329
2373
  return tpl;
@@ -2486,20 +2530,6 @@ const BaseBridgeElement = HTMLBridgeElementFactory(HTMLElementConstructor, share
2486
2530
  shared.freeze(BaseBridgeElement);
2487
2531
  shared.seal(BaseBridgeElement.prototype);
2488
2532
 
2489
- /*
2490
- * Copyright (c) 2020, salesforce.com, inc.
2491
- * All rights reserved.
2492
- * SPDX-License-Identifier: MIT
2493
- * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
2494
- */
2495
- function resolveCircularModuleDependency(fn) {
2496
- const module = fn();
2497
- return (module === null || module === void 0 ? void 0 : module.__esModule) ? module.default : module;
2498
- }
2499
- function isCircularModuleDependency(obj) {
2500
- return shared.isFunction(obj) && shared.hasOwnProperty.call(obj, '__circular__');
2501
- }
2502
-
2503
2533
  /*
2504
2534
  * Copyright (c) 2020, salesforce.com, inc.
2505
2535
  * All rights reserved.
@@ -4892,20 +4922,9 @@ function removeVM(vm) {
4892
4922
 
4893
4923
  resetComponentStateWhenRemoved(vm);
4894
4924
  }
4895
-
4896
- function getNearestShadowAncestor(vm) {
4897
- let ancestor = vm.owner;
4898
-
4899
- while (!shared.isNull(ancestor) && ancestor.renderMode === 0
4900
- /* Light */
4901
- ) {
4902
- ancestor = ancestor.owner;
4903
- }
4904
-
4905
- return ancestor;
4906
- }
4907
-
4908
4925
  function createVM(elm, ctor, options) {
4926
+ var _a;
4927
+
4909
4928
  const {
4910
4929
  mode,
4911
4930
  owner,
@@ -4933,6 +4952,8 @@ function createVM(elm, ctor, options) {
4933
4952
  oar: shared.create(null),
4934
4953
  cmpTemplate: null,
4935
4954
  renderMode: def.renderMode,
4955
+ shadowMode: computeShadowMode(def, owner),
4956
+ nearestShadowMode: (owner === null || owner === void 0 ? void 0 : owner.shadowRoot) ? owner.shadowMode : (_a = owner === null || owner === void 0 ? void 0 : owner.nearestShadowMode) !== null && _a !== void 0 ? _a : null,
4936
4957
  context: {
4937
4958
  stylesheetToken: undefined,
4938
4959
  hasTokenInClass: undefined,
@@ -4945,7 +4966,6 @@ function createVM(elm, ctor, options) {
4945
4966
  },
4946
4967
  // Properties set right after VM creation.
4947
4968
  tro: null,
4948
- shadowMode: null,
4949
4969
  // Properties set by the LightningElement constructor.
4950
4970
  component: null,
4951
4971
  shadowRoot: null,
@@ -4954,7 +4974,6 @@ function createVM(elm, ctor, options) {
4954
4974
  setHook,
4955
4975
  getHook
4956
4976
  };
4957
- vm.shadowMode = computeShadowMode(vm);
4958
4977
  vm.tro = getTemplateReactiveObserver(vm);
4959
4978
 
4960
4979
  if (process.env.NODE_ENV !== 'production') {
@@ -4979,10 +4998,9 @@ function createVM(elm, ctor, options) {
4979
4998
  return vm;
4980
4999
  }
4981
5000
 
4982
- function computeShadowMode(vm) {
4983
- const {
4984
- def
4985
- } = vm;
5001
+ function computeShadowMode(def, owner) {
5002
+ var _a;
5003
+
4986
5004
  let shadowMode;
4987
5005
 
4988
5006
  if (isSyntheticShadowDefined) {
@@ -5005,23 +5023,13 @@ function computeShadowMode(vm) {
5005
5023
  /* Native */
5006
5024
  ;
5007
5025
  } else {
5008
- const shadowAncestor = getNearestShadowAncestor(vm);
5009
-
5010
- if (!shared.isNull(shadowAncestor) && shadowAncestor.shadowMode === 0
5011
- /* Native */
5012
- ) {
5013
- // Transitive support for native Shadow DOM. A component in native mode
5014
- // transitively opts all of its descendants into native.
5015
- shadowMode = 0
5016
- /* Native */
5017
- ;
5018
- } else {
5019
- // Synthetic if neither this component nor any of its ancestors are configured
5020
- // to be native.
5021
- shadowMode = 1
5022
- /* Synthetic */
5023
- ;
5024
- }
5026
+ // Transitive support for native Shadow DOM. A component in native mode
5027
+ // transitively opts all of its descendants into native.
5028
+ // Synthetic if neither this component nor any of its ancestors are configured
5029
+ // to be native.
5030
+ shadowMode = (_a = owner === null || owner === void 0 ? void 0 : owner.nearestShadowMode) !== null && _a !== void 0 ? _a : 1
5031
+ /* Synthetic */
5032
+ ;
5025
5033
  }
5026
5034
  } else {
5027
5035
  shadowMode = 1
@@ -6111,6 +6119,29 @@ function setHooks(hooks) {
6111
6119
  setSanitizeHtmlContentHook(hooks.sanitizeHtmlContent);
6112
6120
  }
6113
6121
 
6122
+ /*
6123
+ * Copyright (c) 2018, salesforce.com, inc.
6124
+ * All rights reserved.
6125
+ * SPDX-License-Identifier: MIT
6126
+ * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
6127
+ */
6128
+ /**
6129
+ * EXPERIMENTAL: This function provides access to the component constructor, given an HTMLElement.
6130
+ * This API is subject to change or being removed.
6131
+ */
6132
+ function getComponentConstructor(elm) {
6133
+ let ctor = null;
6134
+ // intentionally checking for undefined due to some funky libraries patching weakmap.get
6135
+ // to throw when undefined.
6136
+ if (!shared.isUndefined(elm)) {
6137
+ const vm = getAssociatedVMIfPresent(elm);
6138
+ if (!shared.isUndefined(vm)) {
6139
+ ctor = vm.def.ctor;
6140
+ }
6141
+ }
6142
+ return ctor;
6143
+ }
6144
+
6114
6145
  Object.defineProperty(exports, 'setFeatureFlag', {
6115
6146
  enumerable: true,
6116
6147
  get: function () { return features.setFeatureFlag; }
@@ -6127,6 +6158,7 @@ exports.createContextProvider = createContextProvider;
6127
6158
  exports.createVM = createVM;
6128
6159
  exports.disconnectRootElement = disconnectRootElement;
6129
6160
  exports.getAssociatedVMIfPresent = getAssociatedVMIfPresent;
6161
+ exports.getComponentConstructor = getComponentConstructor;
6130
6162
  exports.getComponentDef = getComponentDef;
6131
6163
  exports.getComponentHtmlPrototype = getComponentHtmlPrototype;
6132
6164
  exports.getUpgradableConstructor = getUpgradableConstructor;
@@ -6185,4 +6217,4 @@ exports.swapTemplate = swapTemplate;
6185
6217
  exports.track = track;
6186
6218
  exports.unwrap = unwrap;
6187
6219
  exports.wire = wire;
6188
- /* version: 2.13.0 */
6220
+ /* version: 2.13.3 */
@@ -1,5 +1,5 @@
1
1
  /* proxy-compat-disable */
2
- import { seal, create, isFunction as isFunction$1, ArrayPush as ArrayPush$1, isUndefined as isUndefined$1, ArrayIndexOf, ArraySplice, StringToLowerCase, ArrayJoin, isNull, isFrozen, defineProperty, assign, forEach, keys, AriaPropNameToAttrNameMap, getPropertyDescriptor, defineProperties, getOwnPropertyNames as getOwnPropertyNames$1, getPrototypeOf as getPrototypeOf$1, setPrototypeOf, isObject, assert, KEY__SYNTHETIC_MODE, toString as toString$1, isFalse, isTrue, getOwnPropertyDescriptor as getOwnPropertyDescriptor$1, LWC_VERSION_COMMENT_REGEX, LWC_VERSION, freeze, htmlPropertyToAttribute, ArraySlice, hasOwnProperty as hasOwnProperty$1, StringCharCodeAt, XML_NAMESPACE, XLINK_NAMESPACE, isString, StringSlice, SVG_NAMESPACE, KEY__SHADOW_RESOLVER, isArray as isArray$1, isNumber, StringReplace, KEY__SCOPED_CSS, noop, ArrayUnshift } from '@lwc/shared';
2
+ import { seal, create, isFunction as isFunction$1, ArrayPush as ArrayPush$1, isUndefined as isUndefined$1, ArrayIndexOf, ArraySplice, StringToLowerCase, ArrayJoin, isNull, isFrozen, defineProperty, hasOwnProperty as hasOwnProperty$1, assign, forEach, keys, AriaPropNameToAttrNameMap, getPropertyDescriptor, defineProperties, getOwnPropertyNames as getOwnPropertyNames$1, getPrototypeOf as getPrototypeOf$1, setPrototypeOf, isObject, assert, KEY__SYNTHETIC_MODE, toString as toString$1, isFalse, isTrue, getOwnPropertyDescriptor as getOwnPropertyDescriptor$1, LWC_VERSION_COMMENT_REGEX, LWC_VERSION, freeze, htmlPropertyToAttribute, ArraySlice, StringCharCodeAt, XML_NAMESPACE, XLINK_NAMESPACE, isString, StringSlice, SVG_NAMESPACE, KEY__SHADOW_RESOLVER, isArray as isArray$1, isNumber, StringReplace, KEY__SCOPED_CSS, noop, ArrayUnshift } from '@lwc/shared';
3
3
  import { runtimeFlags } from '@lwc/features';
4
4
  export { setFeatureFlag, setFeatureFlagForTest } from '@lwc/features';
5
5
 
@@ -437,6 +437,20 @@ function logWarn(message, vm) {
437
437
  log('warn', message, vm);
438
438
  }
439
439
 
440
+ /*
441
+ * Copyright (c) 2020, salesforce.com, inc.
442
+ * All rights reserved.
443
+ * SPDX-License-Identifier: MIT
444
+ * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
445
+ */
446
+ function resolveCircularModuleDependency(fn) {
447
+ const module = fn();
448
+ return (module === null || module === void 0 ? void 0 : module.__esModule) ? module.default : module;
449
+ }
450
+ function isCircularModuleDependency(obj) {
451
+ return isFunction$1(obj) && hasOwnProperty$1.call(obj, '__circular__');
452
+ }
453
+
440
454
  /*
441
455
  * Copyright (c) 2018, salesforce.com, inc.
442
456
  * All rights reserved.
@@ -1802,64 +1816,7 @@ if (process.env.NODE_ENV !== 'production') {
1802
1816
  patchLightningElementPrototypeWithRestrictions(LightningElement.prototype);
1803
1817
  }
1804
1818
 
1805
- /*
1806
- * Copyright (c) 2018, salesforce.com, inc.
1807
- * All rights reserved.
1808
- * SPDX-License-Identifier: MIT
1809
- * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
1810
- */
1811
- /**
1812
- * @wire decorator to wire fields and methods to a wire adapter in
1813
- * LWC Components. This function implements the internals of this
1814
- * decorator.
1815
- */
1816
- function wire(_adapter, _config) {
1817
- if (process.env.NODE_ENV !== 'production') {
1818
- assert.fail('@wire(adapter, config?) may only be used as a decorator.');
1819
- }
1820
- throw new Error();
1821
- }
1822
- function internalWireFieldDecorator(key) {
1823
- return {
1824
- get() {
1825
- const vm = getAssociatedVM(this);
1826
- componentValueObserved(vm, key);
1827
- return vm.cmpFields[key];
1828
- },
1829
- set(value) {
1830
- const vm = getAssociatedVM(this);
1831
- /**
1832
- * Reactivity for wired fields is provided in wiring.
1833
- * We intentionally add reactivity here since this is just
1834
- * letting the author to do the wrong thing, but it will keep our
1835
- * system to be backward compatible.
1836
- */
1837
- if (value !== vm.cmpFields[key]) {
1838
- vm.cmpFields[key] = value;
1839
- componentValueMutated(vm, key);
1840
- }
1841
- },
1842
- enumerable: true,
1843
- configurable: true,
1844
- };
1845
- }
1846
-
1847
- /*
1848
- * Copyright (c) 2018, salesforce.com, inc.
1849
- * All rights reserved.
1850
- * SPDX-License-Identifier: MIT
1851
- * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
1852
- */
1853
- function track(target) {
1854
- if (arguments.length === 1) {
1855
- return reactiveMembrane.getProxy(target);
1856
- }
1857
- if (process.env.NODE_ENV !== 'production') {
1858
- assert.fail(`@track decorator can only be used with one argument to return a trackable object, or as a decorator function.`);
1859
- }
1860
- throw new Error();
1861
- }
1862
- function internalTrackDecorator(key) {
1819
+ function createObservedFieldPropertyDescriptor(key) {
1863
1820
  return {
1864
1821
  get() {
1865
1822
  const vm = getAssociatedVM(this);
@@ -1868,14 +1825,8 @@ function internalTrackDecorator(key) {
1868
1825
  },
1869
1826
  set(newValue) {
1870
1827
  const vm = getAssociatedVM(this);
1871
- if (process.env.NODE_ENV !== 'production') {
1872
- const vmBeingRendered = getVMBeingRendered();
1873
- assert.invariant(!isInvokingRender, `${vmBeingRendered}.render() method has side effects on the state of ${vm}.${toString$1(key)}`);
1874
- assert.invariant(!isUpdatingTemplate, `Updating the template of ${vmBeingRendered} has side effects on the state of ${vm}.${toString$1(key)}`);
1875
- }
1876
- const reactiveOrAnyValue = reactiveMembrane.getProxy(newValue);
1877
- if (reactiveOrAnyValue !== vm.cmpFields[key]) {
1878
- vm.cmpFields[key] = reactiveOrAnyValue;
1828
+ if (newValue !== vm.cmpFields[key]) {
1829
+ vm.cmpFields[key] = newValue;
1879
1830
  componentValueMutated(vm, key);
1880
1831
  }
1881
1832
  },
@@ -2039,7 +1990,22 @@ function createPublicAccessorDescriptor(key, descriptor) {
2039
1990
  };
2040
1991
  }
2041
1992
 
2042
- function createObservedFieldPropertyDescriptor(key) {
1993
+ /*
1994
+ * Copyright (c) 2018, salesforce.com, inc.
1995
+ * All rights reserved.
1996
+ * SPDX-License-Identifier: MIT
1997
+ * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
1998
+ */
1999
+ function track(target) {
2000
+ if (arguments.length === 1) {
2001
+ return reactiveMembrane.getProxy(target);
2002
+ }
2003
+ if (process.env.NODE_ENV !== 'production') {
2004
+ assert.fail(`@track decorator can only be used with one argument to return a trackable object, or as a decorator function.`);
2005
+ }
2006
+ throw new Error();
2007
+ }
2008
+ function internalTrackDecorator(key) {
2043
2009
  return {
2044
2010
  get() {
2045
2011
  const vm = getAssociatedVM(this);
@@ -2048,8 +2014,56 @@ function createObservedFieldPropertyDescriptor(key) {
2048
2014
  },
2049
2015
  set(newValue) {
2050
2016
  const vm = getAssociatedVM(this);
2051
- if (newValue !== vm.cmpFields[key]) {
2052
- vm.cmpFields[key] = newValue;
2017
+ if (process.env.NODE_ENV !== 'production') {
2018
+ const vmBeingRendered = getVMBeingRendered();
2019
+ assert.invariant(!isInvokingRender, `${vmBeingRendered}.render() method has side effects on the state of ${vm}.${toString$1(key)}`);
2020
+ assert.invariant(!isUpdatingTemplate, `Updating the template of ${vmBeingRendered} has side effects on the state of ${vm}.${toString$1(key)}`);
2021
+ }
2022
+ const reactiveOrAnyValue = reactiveMembrane.getProxy(newValue);
2023
+ if (reactiveOrAnyValue !== vm.cmpFields[key]) {
2024
+ vm.cmpFields[key] = reactiveOrAnyValue;
2025
+ componentValueMutated(vm, key);
2026
+ }
2027
+ },
2028
+ enumerable: true,
2029
+ configurable: true,
2030
+ };
2031
+ }
2032
+
2033
+ /*
2034
+ * Copyright (c) 2018, salesforce.com, inc.
2035
+ * All rights reserved.
2036
+ * SPDX-License-Identifier: MIT
2037
+ * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
2038
+ */
2039
+ /**
2040
+ * @wire decorator to wire fields and methods to a wire adapter in
2041
+ * LWC Components. This function implements the internals of this
2042
+ * decorator.
2043
+ */
2044
+ function wire(_adapter, _config) {
2045
+ if (process.env.NODE_ENV !== 'production') {
2046
+ assert.fail('@wire(adapter, config?) may only be used as a decorator.');
2047
+ }
2048
+ throw new Error();
2049
+ }
2050
+ function internalWireFieldDecorator(key) {
2051
+ return {
2052
+ get() {
2053
+ const vm = getAssociatedVM(this);
2054
+ componentValueObserved(vm, key);
2055
+ return vm.cmpFields[key];
2056
+ },
2057
+ set(value) {
2058
+ const vm = getAssociatedVM(this);
2059
+ /**
2060
+ * Reactivity for wired fields is provided in wiring.
2061
+ * We intentionally add reactivity here since this is just
2062
+ * letting the author to do the wrong thing, but it will keep our
2063
+ * system to be backward compatible.
2064
+ */
2065
+ if (value !== vm.cmpFields[key]) {
2066
+ vm.cmpFields[key] = value;
2053
2067
  componentValueMutated(vm, key);
2054
2068
  }
2055
2069
  },
@@ -2304,6 +2318,12 @@ function checkVersionMismatch(func, type) {
2304
2318
  }
2305
2319
  }
2306
2320
 
2321
+ /*
2322
+ * Copyright (c) 2018, salesforce.com, inc.
2323
+ * All rights reserved.
2324
+ * SPDX-License-Identifier: MIT
2325
+ * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
2326
+ */
2307
2327
  const signedTemplateSet = new Set();
2308
2328
  function defaultEmptyTemplate() {
2309
2329
  return [];
@@ -2321,6 +2341,30 @@ function registerTemplate(tpl) {
2321
2341
  checkVersionMismatch(tpl, 'template');
2322
2342
  }
2323
2343
  signedTemplateSet.add(tpl);
2344
+ // FIXME[@W-10950976]: the template object should be frozen, and it should not be possible to set
2345
+ // the stylesheets or stylesheetToken(s). For backwards compat, though, we shim stylesheetTokens
2346
+ // on top of stylesheetToken for anyone who is accessing the old internal API.
2347
+ // Details: https://salesforce.quip.com/v1rmAFu2cKAr
2348
+ defineProperty(tpl, 'stylesheetTokens', {
2349
+ get() {
2350
+ const { stylesheetToken } = this;
2351
+ if (isUndefined$1(stylesheetToken)) {
2352
+ return stylesheetToken;
2353
+ }
2354
+ // Shim for the old `stylesheetTokens` property
2355
+ // See https://github.com/salesforce/lwc/pull/2332/files#diff-7901555acef29969adaa6583185b3e9bce475cdc6f23e799a54e0018cb18abaa
2356
+ return {
2357
+ hostAttribute: `${stylesheetToken}-host`,
2358
+ shadowAttribute: stylesheetToken,
2359
+ };
2360
+ },
2361
+ set(value) {
2362
+ // If the value is null or some other exotic object, you would be broken anyway in the past
2363
+ // because the engine would try to access hostAttribute/shadowAttribute, which would throw an error.
2364
+ // However it may be undefined in newer versions of LWC, so we need to guard against that case.
2365
+ this.stylesheetToken = isUndefined$1(value) ? undefined : value.shadowAttribute;
2366
+ },
2367
+ });
2324
2368
  // chaining this method as a way to wrap existing
2325
2369
  // assignment of templates easily, without too much transformation
2326
2370
  return tpl;
@@ -2483,20 +2527,6 @@ const BaseBridgeElement = HTMLBridgeElementFactory(HTMLElementConstructor, getOw
2483
2527
  freeze(BaseBridgeElement);
2484
2528
  seal(BaseBridgeElement.prototype);
2485
2529
 
2486
- /*
2487
- * Copyright (c) 2020, salesforce.com, inc.
2488
- * All rights reserved.
2489
- * SPDX-License-Identifier: MIT
2490
- * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
2491
- */
2492
- function resolveCircularModuleDependency(fn) {
2493
- const module = fn();
2494
- return (module === null || module === void 0 ? void 0 : module.__esModule) ? module.default : module;
2495
- }
2496
- function isCircularModuleDependency(obj) {
2497
- return isFunction$1(obj) && hasOwnProperty$1.call(obj, '__circular__');
2498
- }
2499
-
2500
2530
  /*
2501
2531
  * Copyright (c) 2020, salesforce.com, inc.
2502
2532
  * All rights reserved.
@@ -4889,20 +4919,9 @@ function removeVM(vm) {
4889
4919
 
4890
4920
  resetComponentStateWhenRemoved(vm);
4891
4921
  }
4892
-
4893
- function getNearestShadowAncestor(vm) {
4894
- let ancestor = vm.owner;
4895
-
4896
- while (!isNull(ancestor) && ancestor.renderMode === 0
4897
- /* Light */
4898
- ) {
4899
- ancestor = ancestor.owner;
4900
- }
4901
-
4902
- return ancestor;
4903
- }
4904
-
4905
4922
  function createVM(elm, ctor, options) {
4923
+ var _a;
4924
+
4906
4925
  const {
4907
4926
  mode,
4908
4927
  owner,
@@ -4930,6 +4949,8 @@ function createVM(elm, ctor, options) {
4930
4949
  oar: create(null),
4931
4950
  cmpTemplate: null,
4932
4951
  renderMode: def.renderMode,
4952
+ shadowMode: computeShadowMode(def, owner),
4953
+ nearestShadowMode: (owner === null || owner === void 0 ? void 0 : owner.shadowRoot) ? owner.shadowMode : (_a = owner === null || owner === void 0 ? void 0 : owner.nearestShadowMode) !== null && _a !== void 0 ? _a : null,
4933
4954
  context: {
4934
4955
  stylesheetToken: undefined,
4935
4956
  hasTokenInClass: undefined,
@@ -4942,7 +4963,6 @@ function createVM(elm, ctor, options) {
4942
4963
  },
4943
4964
  // Properties set right after VM creation.
4944
4965
  tro: null,
4945
- shadowMode: null,
4946
4966
  // Properties set by the LightningElement constructor.
4947
4967
  component: null,
4948
4968
  shadowRoot: null,
@@ -4951,7 +4971,6 @@ function createVM(elm, ctor, options) {
4951
4971
  setHook,
4952
4972
  getHook
4953
4973
  };
4954
- vm.shadowMode = computeShadowMode(vm);
4955
4974
  vm.tro = getTemplateReactiveObserver(vm);
4956
4975
 
4957
4976
  if (process.env.NODE_ENV !== 'production') {
@@ -4976,10 +4995,9 @@ function createVM(elm, ctor, options) {
4976
4995
  return vm;
4977
4996
  }
4978
4997
 
4979
- function computeShadowMode(vm) {
4980
- const {
4981
- def
4982
- } = vm;
4998
+ function computeShadowMode(def, owner) {
4999
+ var _a;
5000
+
4983
5001
  let shadowMode;
4984
5002
 
4985
5003
  if (isSyntheticShadowDefined) {
@@ -5002,23 +5020,13 @@ function computeShadowMode(vm) {
5002
5020
  /* Native */
5003
5021
  ;
5004
5022
  } else {
5005
- const shadowAncestor = getNearestShadowAncestor(vm);
5006
-
5007
- if (!isNull(shadowAncestor) && shadowAncestor.shadowMode === 0
5008
- /* Native */
5009
- ) {
5010
- // Transitive support for native Shadow DOM. A component in native mode
5011
- // transitively opts all of its descendants into native.
5012
- shadowMode = 0
5013
- /* Native */
5014
- ;
5015
- } else {
5016
- // Synthetic if neither this component nor any of its ancestors are configured
5017
- // to be native.
5018
- shadowMode = 1
5019
- /* Synthetic */
5020
- ;
5021
- }
5023
+ // Transitive support for native Shadow DOM. A component in native mode
5024
+ // transitively opts all of its descendants into native.
5025
+ // Synthetic if neither this component nor any of its ancestors are configured
5026
+ // to be native.
5027
+ shadowMode = (_a = owner === null || owner === void 0 ? void 0 : owner.nearestShadowMode) !== null && _a !== void 0 ? _a : 1
5028
+ /* Synthetic */
5029
+ ;
5022
5030
  }
5023
5031
  } else {
5024
5032
  shadowMode = 1
@@ -6108,5 +6116,28 @@ function setHooks(hooks) {
6108
6116
  setSanitizeHtmlContentHook(hooks.sanitizeHtmlContent);
6109
6117
  }
6110
6118
 
6111
- export { LightningElement, profilerControl as __unstable__ProfilerControl, api$1 as api, connectRootElement, createContextProvider, createVM, disconnectRootElement, getAssociatedVMIfPresent, getComponentDef, getComponentHtmlPrototype, getUpgradableConstructor, hydrateRoot, isComponentConstructor, readonly, register, registerComponent, registerDecorators, registerTemplate, sanitizeAttribute, setAddEventListener, setAssertInstanceOfHTMLElement, setAttachShadow, setCreateComment, setCreateElement, setCreateText, setDefineCustomElement, setDispatchEvent, setGetAttribute, setGetBoundingClientRect, setGetChildNodes, setGetChildren, setGetClassList, setGetCustomElement, setGetElementsByClassName, setGetElementsByTagName, setGetFirstChild, setGetFirstElementChild, setGetLastChild, setGetLastElementChild, setGetProperty, setHTMLElement, setHooks, setInsert, setInsertGlobalStylesheet, setInsertStylesheet, setIsConnected, setIsHydrating, setIsNativeShadowDefined, setIsSyntheticShadowDefined, setNextSibling, setQuerySelector, setQuerySelectorAll, setRemove, setRemoveAttribute, setRemoveEventListener, setSetAttribute, setSetCSSStyleProperty, setSetProperty, setSetText, setSsr, swapComponent, swapStyle, swapTemplate, track, unwrap, wire };
6112
- /* version: 2.13.0 */
6119
+ /*
6120
+ * Copyright (c) 2018, salesforce.com, inc.
6121
+ * All rights reserved.
6122
+ * SPDX-License-Identifier: MIT
6123
+ * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
6124
+ */
6125
+ /**
6126
+ * EXPERIMENTAL: This function provides access to the component constructor, given an HTMLElement.
6127
+ * This API is subject to change or being removed.
6128
+ */
6129
+ function getComponentConstructor(elm) {
6130
+ let ctor = null;
6131
+ // intentionally checking for undefined due to some funky libraries patching weakmap.get
6132
+ // to throw when undefined.
6133
+ if (!isUndefined$1(elm)) {
6134
+ const vm = getAssociatedVMIfPresent(elm);
6135
+ if (!isUndefined$1(vm)) {
6136
+ ctor = vm.def.ctor;
6137
+ }
6138
+ }
6139
+ return ctor;
6140
+ }
6141
+
6142
+ export { LightningElement, profilerControl as __unstable__ProfilerControl, api$1 as api, connectRootElement, createContextProvider, createVM, disconnectRootElement, getAssociatedVMIfPresent, getComponentConstructor, getComponentDef, getComponentHtmlPrototype, getUpgradableConstructor, hydrateRoot, isComponentConstructor, readonly, register, registerComponent, registerDecorators, registerTemplate, sanitizeAttribute, setAddEventListener, setAssertInstanceOfHTMLElement, setAttachShadow, setCreateComment, setCreateElement, setCreateText, setDefineCustomElement, setDispatchEvent, setGetAttribute, setGetBoundingClientRect, setGetChildNodes, setGetChildren, setGetClassList, setGetCustomElement, setGetElementsByClassName, setGetElementsByTagName, setGetFirstChild, setGetFirstElementChild, setGetLastChild, setGetLastElementChild, setGetProperty, setHTMLElement, setHooks, setInsert, setInsertGlobalStylesheet, setInsertStylesheet, setIsConnected, setIsHydrating, setIsNativeShadowDefined, setIsSyntheticShadowDefined, setNextSibling, setQuerySelector, setQuerySelectorAll, setRemove, setRemoveAttribute, setRemoveEventListener, setSetAttribute, setSetCSSStyleProperty, setSetProperty, setSetText, setSsr, swapComponent, swapStyle, swapTemplate, track, unwrap, wire };
6143
+ /* version: 2.13.3 */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lwc/engine-core",
3
- "version": "2.13.0",
3
+ "version": "2.13.3",
4
4
  "description": "Core LWC engine APIs.",
5
5
  "homepage": "https://lwc.dev/",
6
6
  "repository": {
@@ -25,8 +25,8 @@
25
25
  "types/"
26
26
  ],
27
27
  "dependencies": {
28
- "@lwc/features": "2.13.0",
29
- "@lwc/shared": "2.13.0"
28
+ "@lwc/features": "2.13.3",
29
+ "@lwc/shared": "2.13.3"
30
30
  },
31
31
  "devDependencies": {
32
32
  "observable-membrane": "2.0.0"
@@ -1,5 +1,5 @@
1
- import { VM } from './vm';
2
1
  import { ReactiveObserver } from '../libs/mutation-tracker';
2
+ import { VM } from './vm';
3
3
  import { LightningElementConstructor } from './base-lightning-element';
4
4
  import { Template } from './template';
5
5
  import { VNodes } from './vnodes';
@@ -6,10 +6,10 @@
6
6
  * This structure can be used to synthetically create proxies, and understand the
7
7
  * shape of a component. It is also used internally to apply extra optimizations.
8
8
  */
9
+ import { RenderMode, ShadowSupportMode } from '../framework/vm';
9
10
  import { Template } from './template';
10
11
  import { LightningElement, LightningElementConstructor } from './base-lightning-element';
11
12
  import { PropType } from './decorators/register';
12
- import { RenderMode, ShadowSupportMode } from '../framework/vm';
13
13
  import { HTMLElementConstructor } from './base-bridge-element';
14
14
  export interface ComponentDef {
15
15
  name: string;
@@ -0,0 +1,6 @@
1
+ import { LightningElement } from './base-lightning-element';
2
+ /**
3
+ * EXPERIMENTAL: This function provides access to the component constructor, given an HTMLElement.
4
+ * This API is subject to change or being removed.
5
+ */
6
+ export declare function getComponentConstructor(elm: HTMLElement): typeof LightningElement | null;
@@ -19,5 +19,6 @@ export { profilerControl as __unstable__ProfilerControl } from './profiler';
19
19
  export { getUpgradableConstructor } from './upgradable-element';
20
20
  export { swapTemplate, swapComponent, swapStyle } from './hot-swaps';
21
21
  export { setHooks } from './overridable-hooks';
22
+ export { getComponentConstructor } from './get-component-constructor';
22
23
  export type { ConfigValue as WireConfigValue, ContextValue as WireContextValue, DataCallback, WireAdapter, WireAdapterConstructor, WireAdapterSchemaValue, } from './wiring';
23
24
  export { setAssertInstanceOfHTMLElement, setAttachShadow, setCreateComment, setCreateElement, setCreateText, setDefineCustomElement, setDispatchEvent, setGetAttribute, setGetBoundingClientRect, setGetChildNodes, setGetChildren, setGetClassList, setGetCustomElement, setGetElementsByClassName, setGetElementsByTagName, setGetFirstChild, setGetFirstElementChild, setGetLastChild, setGetLastElementChild, setGetProperty, setHTMLElement, setInsert, setInsertGlobalStylesheet, setInsertStylesheet, setIsConnected, setIsHydrating, setIsNativeShadowDefined, setIsSyntheticShadowDefined, setNextSibling, setQuerySelector, setQuerySelectorAll, setRemove, setRemoveAttribute, setRemoveEventListener, setSetAttribute, setSetCSSStyleProperty, setSetProperty, setSetText, setSsr, setAddEventListener, } from '../renderer';
@@ -1,10 +1,10 @@
1
- import type { HostNode, HostElement } from '../renderer';
2
1
  import { Template } from './template';
3
2
  import { ComponentDef } from './def';
4
3
  import { LightningElement, LightningElementConstructor } from './base-lightning-element';
5
4
  import { ReactiveObserver } from './mutation-tracker';
6
5
  import { AccessorReactiveObserver } from './decorators/api';
7
6
  import { VNodes, VCustomElement, VNode } from './vnodes';
7
+ import type { HostNode, HostElement } from '../renderer';
8
8
  declare type ShadowRootMode = 'open' | 'closed';
9
9
  export interface TemplateCache {
10
10
  [key: string]: any;
@@ -63,8 +63,11 @@ export interface VM<N = HostNode, E = HostElement> {
63
63
  /** The owner VM or null for root elements. */
64
64
  readonly owner: VM<N, E> | null;
65
65
  /** Rendering operations associated with the VM */
66
- renderMode: RenderMode;
66
+ readonly renderMode: RenderMode;
67
67
  shadowMode: ShadowMode;
68
+ /** Transitive support for native Shadow DOM. A component in native mode
69
+ * transitively opts all of its descendants into native. */
70
+ readonly nearestShadowMode: ShadowMode | null;
68
71
  /** The component creation index. */
69
72
  idx: number;
70
73
  /** Component state, analogous to Element.isConnected */