@lwc/engine-core 3.0.1 → 3.0.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.
package/dist/index.js CHANGED
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * Copyright (C) 2023 salesforce.com, inc.
3
3
  */
4
- import { noop, StringToLowerCase, isNull, ArrayPush as ArrayPush$1, ArrayJoin, isFrozen, isUndefined as isUndefined$1, defineProperty, ArrayIndexOf, ArraySplice, create, seal, isArray as isArray$1, isFunction as isFunction$1, keys, hasOwnProperty as hasOwnProperty$1, forEach, AriaPropNameToAttrNameMap, getPropertyDescriptor, defineProperties, getPrototypeOf as getPrototypeOf$1, setPrototypeOf, assign, isObject, freeze, KEY__SYNTHETIC_MODE, assert, toString as toString$1, getOwnPropertyDescriptor as getOwnPropertyDescriptor$1, isFalse, LWC_VERSION_COMMENT_REGEX, LWC_VERSION, getOwnPropertyNames as getOwnPropertyNames$1, htmlPropertyToAttribute, ArraySlice, ArrayMap, KEY__SCOPED_CSS, kebabCaseToCamelCase, StringCharCodeAt, XML_NAMESPACE, XLINK_NAMESPACE, isString, StringSlice, isTrue, SVG_NAMESPACE, KEY__SHADOW_STATIC, KEY__SHADOW_RESOLVER, ArraySome, ArrayPop, isNumber, StringReplace, ArrayUnshift, LOWEST_API_VERSION, globalThis as globalThis$1, KEY__NATIVE_GET_ELEMENT_BY_ID, KEY__NATIVE_QUERY_SELECTOR_ALL, ID_REFERENCING_ATTRIBUTES_SET, KEY__SHADOW_TOKEN, ArrayFilter, StringSplit, arrayEvery, ArrayIncludes, ArrayCopyWithin, ArrayFill, ArraySort, ArrayReverse, ArrayShift } from '@lwc/shared';
4
+ import { noop, StringToLowerCase, isNull, ArrayPush as ArrayPush$1, ArrayJoin, isFrozen, isUndefined as isUndefined$1, defineProperty, ArrayIndexOf, ArraySplice, create, seal, isArray as isArray$1, isFunction as isFunction$1, keys, hasOwnProperty as hasOwnProperty$1, globalThis as globalThis$1, forEach, AriaPropNameToAttrNameMap, getPropertyDescriptor, defineProperties, getPrototypeOf as getPrototypeOf$1, setPrototypeOf, assign, isObject, freeze, KEY__SYNTHETIC_MODE, assert, toString as toString$1, getOwnPropertyDescriptor as getOwnPropertyDescriptor$1, isFalse, LWC_VERSION_COMMENT_REGEX, LWC_VERSION, getOwnPropertyNames as getOwnPropertyNames$1, htmlPropertyToAttribute, ArraySlice, ArrayMap, KEY__SCOPED_CSS, kebabCaseToCamelCase, StringCharCodeAt, XML_NAMESPACE, XLINK_NAMESPACE, isString, StringSlice, isTrue, SVG_NAMESPACE, KEY__SHADOW_STATIC, KEY__SHADOW_RESOLVER, ArraySome, ArrayPop, isNumber, StringReplace, ArrayUnshift, LOWEST_API_VERSION, KEY__NATIVE_GET_ELEMENT_BY_ID, KEY__NATIVE_QUERY_SELECTOR_ALL, ID_REFERENCING_ATTRIBUTES_SET, KEY__SHADOW_TOKEN, ArrayFilter, StringSplit, arrayEvery, ArrayIncludes, ArrayCopyWithin, ArrayFill, ArraySort, ArrayReverse, ArrayShift } from '@lwc/shared';
5
5
  import { applyAriaReflection } from '@lwc/aria-reflection';
6
6
  export { setFeatureFlag, setFeatureFlagForTest } from '@lwc/features';
7
7
 
@@ -425,6 +425,10 @@ function isCircularModuleDependency(obj) {
425
425
  return isFunction$1(obj) && hasOwnProperty$1.call(obj, '__circular__');
426
426
  }
427
427
 
428
+ var _a, _b;
429
+ const instrumentDef = (_a = globalThis$1.__lwc_instrument_cmp_def) !== null && _a !== void 0 ? _a : noop;
430
+ const instrumentInstance = (_b = globalThis$1.__lwc_instrument_cmp_instance) !== null && _b !== void 0 ? _b : noop;
431
+
428
432
  /*
429
433
  * Copyright (c) 2018, salesforce.com, inc.
430
434
  * All rights reserved.
@@ -1393,6 +1397,8 @@ const LightningElement = function () {
1393
1397
  // `class Foo extends LightningElement {}; new Foo()`
1394
1398
  throw new TypeError('Illegal constructor');
1395
1399
  }
1400
+ // This is a no-op unless Lightning DevTools are enabled.
1401
+ instrumentInstance(this, vmBeingConstructed);
1396
1402
  const vm = vmBeingConstructed;
1397
1403
  const { def, elm } = vm;
1398
1404
  const { bridge } = def;
@@ -2541,35 +2547,8 @@ function createAttributeChangedCallback(attributeToPropMap, superAttributeChange
2541
2547
  };
2542
2548
  }
2543
2549
  function HTMLBridgeElementFactory(SuperClass, props, methods) {
2544
- let HTMLBridgeElement;
2545
- /**
2546
- * Modern browsers will have all Native Constructors as regular Classes
2547
- * and must be instantiated with the new keyword. In older browsers,
2548
- * specifically IE11, those are objects with a prototype property defined,
2549
- * since they are not supposed to be extended or instantiated with the
2550
- * new keyword. This forking logic supports both cases, specifically because
2551
- * wc.ts relies on the construction path of the bridges to create new
2552
- * fully qualifying web components.
2553
- */
2554
- if (isFunction$1(SuperClass)) {
2555
- HTMLBridgeElement = class extends SuperClass {
2556
- };
2557
- }
2558
- else {
2559
- HTMLBridgeElement = function () {
2560
- // Bridge classes are not supposed to be instantiated directly in
2561
- // browsers that do not support web components.
2562
- throw new TypeError('Illegal constructor');
2563
- };
2564
- // prototype inheritance dance
2565
- setPrototypeOf(HTMLBridgeElement, SuperClass);
2566
- setPrototypeOf(HTMLBridgeElement.prototype, SuperClass.prototype);
2567
- defineProperty(HTMLBridgeElement.prototype, 'constructor', {
2568
- writable: true,
2569
- configurable: true,
2570
- value: HTMLBridgeElement,
2571
- });
2572
- }
2550
+ const HTMLBridgeElement = class extends SuperClass {
2551
+ };
2573
2552
  // generating the hash table for attributes to avoid duplicate fields and facilitate validation
2574
2553
  // and false positives in case of inheritance.
2575
2554
  const attributeToPropMap = create(null);
@@ -2977,6 +2956,8 @@ function createComponentDef(Ctor) {
2977
2956
  errorCallback,
2978
2957
  render,
2979
2958
  };
2959
+ // This is a no-op unless Lightning DevTools are enabled.
2960
+ instrumentDef(def);
2980
2961
  if (process.env.NODE_ENV !== 'production') {
2981
2962
  freeze(Ctor.prototype);
2982
2963
  }
@@ -3105,9 +3086,11 @@ function createInlineStyleVNode(content) {
3105
3086
  },
3106
3087
  }, [api.t(content)]);
3107
3088
  }
3108
- function updateStylesheetToken(vm, template) {
3089
+ // TODO [#3733]: remove support for legacy scope tokens
3090
+ function updateStylesheetToken(vm, template, legacy) {
3109
3091
  const { elm, context, renderMode, shadowMode, renderer: { getClassList, removeAttribute, setAttribute }, } = vm;
3110
- const { stylesheets: newStylesheets, stylesheetToken: newStylesheetToken } = template;
3092
+ const { stylesheets: newStylesheets } = template;
3093
+ const newStylesheetToken = legacy ? template.legacyStylesheetToken : template.stylesheetToken;
3111
3094
  const { stylesheets: newVmStylesheets } = vm;
3112
3095
  const isSyntheticShadow = renderMode === 1 /* RenderMode.Shadow */ && shadowMode === 1 /* ShadowMode.Synthetic */;
3113
3096
  const { hasScopedStyles } = context;
@@ -3115,7 +3098,19 @@ function updateStylesheetToken(vm, template) {
3115
3098
  let newHasTokenInClass;
3116
3099
  let newHasTokenInAttribute;
3117
3100
  // Reset the styling token applied to the host element.
3118
- const { stylesheetToken: oldToken, hasTokenInClass: oldHasTokenInClass, hasTokenInAttribute: oldHasTokenInAttribute, } = context;
3101
+ let oldToken;
3102
+ let oldHasTokenInClass;
3103
+ let oldHasTokenInAttribute;
3104
+ if (legacy) {
3105
+ oldToken = context.legacyStylesheetToken;
3106
+ oldHasTokenInClass = context.hasLegacyTokenInClass;
3107
+ oldHasTokenInAttribute = context.hasLegacyTokenInAttribute;
3108
+ }
3109
+ else {
3110
+ oldToken = context.stylesheetToken;
3111
+ oldHasTokenInClass = context.hasTokenInClass;
3112
+ oldHasTokenInAttribute = context.hasTokenInAttribute;
3113
+ }
3119
3114
  if (!isUndefined$1(oldToken)) {
3120
3115
  if (oldHasTokenInClass) {
3121
3116
  getClassList(elm).remove(makeHostToken(oldToken));
@@ -3143,9 +3138,16 @@ function updateStylesheetToken(vm, template) {
3143
3138
  }
3144
3139
  }
3145
3140
  // Update the styling tokens present on the context object.
3146
- context.stylesheetToken = newToken;
3147
- context.hasTokenInClass = newHasTokenInClass;
3148
- context.hasTokenInAttribute = newHasTokenInAttribute;
3141
+ if (legacy) {
3142
+ context.legacyStylesheetToken = newToken;
3143
+ context.hasLegacyTokenInClass = newHasTokenInClass;
3144
+ context.hasLegacyTokenInAttribute = newHasTokenInAttribute;
3145
+ }
3146
+ else {
3147
+ context.stylesheetToken = newToken;
3148
+ context.hasTokenInClass = newHasTokenInClass;
3149
+ context.hasTokenInAttribute = newHasTokenInAttribute;
3150
+ }
3149
3151
  }
3150
3152
  function evaluateStylesheetsContent(stylesheets, stylesheetToken, vm) {
3151
3153
  const content = [];
@@ -3232,9 +3234,12 @@ function getNearestShadowComponent(vm) {
3232
3234
  * this returns the unique token for that scoped stylesheet. Otherwise
3233
3235
  * it returns null.
3234
3236
  */
3235
- function getScopeTokenClass(owner) {
3237
+ // TODO [#3733]: remove support for legacy scope tokens
3238
+ function getScopeTokenClass(owner, legacy) {
3236
3239
  const { cmpTemplate, context } = owner;
3237
- return (context.hasScopedStyles && (cmpTemplate === null || cmpTemplate === void 0 ? void 0 : cmpTemplate.stylesheetToken)) || null;
3240
+ return ((context.hasScopedStyles &&
3241
+ (legacy ? cmpTemplate === null || cmpTemplate === void 0 ? void 0 : cmpTemplate.legacyStylesheetToken : cmpTemplate === null || cmpTemplate === void 0 ? void 0 : cmpTemplate.stylesheetToken)) ||
3242
+ null);
3238
3243
  }
3239
3244
  /**
3240
3245
  * This function returns the host style token for a custom element if it
@@ -3960,18 +3965,35 @@ function patchElementPropsAndAttrs$1(oldVnode, vnode, renderer) {
3960
3965
  patchProps(oldVnode, vnode, renderer);
3961
3966
  }
3962
3967
  function applyStyleScoping(elm, owner, renderer) {
3968
+ const { getClassList } = renderer;
3963
3969
  // Set the class name for `*.scoped.css` style scoping.
3964
- const scopeToken = getScopeTokenClass(owner);
3970
+ const scopeToken = getScopeTokenClass(owner, /* legacy */ false);
3965
3971
  if (!isNull(scopeToken)) {
3966
- const { getClassList } = renderer;
3967
3972
  // TODO [#2762]: this dot notation with add is probably problematic
3968
3973
  // probably we should have a renderer api for just the add operation
3969
3974
  getClassList(elm).add(scopeToken);
3970
3975
  }
3976
+ // TODO [#3733]: remove support for legacy scope tokens
3977
+ if (lwcRuntimeFlags.ENABLE_LEGACY_SCOPE_TOKENS) {
3978
+ const legacyScopeToken = getScopeTokenClass(owner, /* legacy */ true);
3979
+ if (!isNull(legacyScopeToken)) {
3980
+ // TODO [#2762]: this dot notation with add is probably problematic
3981
+ // probably we should have a renderer api for just the add operation
3982
+ getClassList(elm).add(legacyScopeToken);
3983
+ }
3984
+ }
3971
3985
  // Set property element for synthetic shadow DOM style scoping.
3972
3986
  const { stylesheetToken: syntheticToken } = owner.context;
3973
- if (owner.shadowMode === 1 /* ShadowMode.Synthetic */ && !isUndefined$1(syntheticToken)) {
3974
- elm.$shadowToken$ = syntheticToken;
3987
+ if (owner.shadowMode === 1 /* ShadowMode.Synthetic */) {
3988
+ if (!isUndefined$1(syntheticToken)) {
3989
+ elm.$shadowToken$ = syntheticToken;
3990
+ }
3991
+ if (lwcRuntimeFlags.ENABLE_LEGACY_SCOPE_TOKENS) {
3992
+ const legacyToken = owner.context.legacyStylesheetToken;
3993
+ if (!isUndefined$1(legacyToken)) {
3994
+ elm.$legacyShadowToken$ = legacyToken;
3995
+ }
3996
+ }
3975
3997
  }
3976
3998
  }
3977
3999
  function applyDomManual(elm, vnode) {
@@ -4144,12 +4166,11 @@ function allocateInSlot(vm, children, owner) {
4144
4166
  }
4145
4167
  }
4146
4168
  }
4147
- // Using a WeakMap instead of a WeakSet because this one works in IE11 :(
4148
- const DynamicChildren = new WeakMap();
4169
+ const DynamicChildren = new WeakSet();
4149
4170
  // dynamic children means it was either generated by an iteration in a template
4150
4171
  // or part of an unstable fragment, and will require a more complex diffing algo.
4151
4172
  function markAsDynamicChildren(children) {
4152
- DynamicChildren.set(children, 1);
4173
+ DynamicChildren.add(children);
4153
4174
  }
4154
4175
  function hasDynamicChildren(children) {
4155
4176
  return DynamicChildren.has(children);
@@ -4999,9 +5020,10 @@ function buildParseFragmentFn(createFragmentFn) {
4999
5020
  return (strings, ...keys) => {
5000
5021
  const cache = create(null);
5001
5022
  return function () {
5002
- const { context: { hasScopedStyles, stylesheetToken }, shadowMode, renderer, } = getVMBeingRendered();
5023
+ const { context: { hasScopedStyles, stylesheetToken, legacyStylesheetToken }, shadowMode, renderer, } = getVMBeingRendered();
5003
5024
  const hasStyleToken = !isUndefined$1(stylesheetToken);
5004
5025
  const isSyntheticShadow = shadowMode === 1 /* ShadowMode.Synthetic */;
5026
+ const hasLegacyToken = lwcRuntimeFlags.ENABLE_LEGACY_SCOPE_TOKENS && !isUndefined$1(legacyStylesheetToken);
5005
5027
  let cacheKey = 0;
5006
5028
  if (hasStyleToken && hasScopedStyles) {
5007
5029
  cacheKey |= 1 /* FragmentCache.HAS_SCOPED_STYLE */;
@@ -5009,12 +5031,19 @@ function buildParseFragmentFn(createFragmentFn) {
5009
5031
  if (hasStyleToken && isSyntheticShadow) {
5010
5032
  cacheKey |= 2 /* FragmentCache.SHADOW_MODE_SYNTHETIC */;
5011
5033
  }
5034
+ if (hasLegacyToken) {
5035
+ // This isn't strictly required for prod, but it's required for our karma tests
5036
+ // since the lwcRuntimeFlag may change over time
5037
+ cacheKey |= 4 /* FragmentCache.HAS_LEGACY_SCOPE_TOKEN */;
5038
+ }
5012
5039
  if (!isUndefined$1(cache[cacheKey])) {
5013
5040
  return cache[cacheKey];
5014
5041
  }
5015
- const classToken = hasScopedStyles && hasStyleToken ? ' ' + stylesheetToken : '';
5016
- const classAttrToken = hasScopedStyles && hasStyleToken ? ` class="${stylesheetToken}"` : '';
5017
- const attrToken = hasStyleToken && isSyntheticShadow ? ' ' + stylesheetToken : '';
5042
+ // If legacy stylesheet tokens are required, then add them to the rendered string
5043
+ const stylesheetTokenToRender = stylesheetToken + (hasLegacyToken ? ` ${legacyStylesheetToken}` : '');
5044
+ const classToken = hasScopedStyles && hasStyleToken ? ' ' + stylesheetTokenToRender : '';
5045
+ const classAttrToken = hasScopedStyles && hasStyleToken ? ` class="${stylesheetTokenToRender}"` : '';
5046
+ const attrToken = hasStyleToken && isSyntheticShadow ? ' ' + stylesheetTokenToRender : '';
5018
5047
  let htmlFragment = '';
5019
5048
  for (let i = 0, n = keys.length; i < n; i++) {
5020
5049
  switch (keys[i]) {
@@ -5090,7 +5119,10 @@ function evaluateTemplate(vm, html) {
5090
5119
  // Set the computeHasScopedStyles property in the context, to avoid recomputing it repeatedly.
5091
5120
  context.hasScopedStyles = computeHasScopedStyles(html, vm);
5092
5121
  // Update the scoping token on the host element.
5093
- updateStylesheetToken(vm, html);
5122
+ updateStylesheetToken(vm, html, /* legacy */ false);
5123
+ if (lwcRuntimeFlags.ENABLE_LEGACY_SCOPE_TOKENS) {
5124
+ updateStylesheetToken(vm, html, /* legacy */ true);
5125
+ }
5094
5126
  // Evaluate, create stylesheet and cache the produced VNode for future
5095
5127
  // re-rendering.
5096
5128
  const stylesheetsContent = getStylesheetsContent(vm, html);
@@ -5460,6 +5492,9 @@ function createVM(elm, ctor, renderer, options) {
5460
5492
  stylesheetToken: undefined,
5461
5493
  hasTokenInClass: undefined,
5462
5494
  hasTokenInAttribute: undefined,
5495
+ legacyStylesheetToken: undefined,
5496
+ hasLegacyTokenInClass: undefined,
5497
+ hasLegacyTokenInAttribute: undefined,
5463
5498
  hasScopedStyles: undefined,
5464
5499
  styleVNodes: null,
5465
5500
  tplCache: EmptyObject,
@@ -6493,7 +6528,8 @@ function validateClassAttr(vnode, elm, renderer) {
6493
6528
  const { data, owner } = vnode;
6494
6529
  let { className, classMap } = data;
6495
6530
  const { getProperty, getClassList, getAttribute } = renderer;
6496
- const scopedToken = getScopeTokenClass(owner);
6531
+ // we don't care about legacy for hydration. it's a new use case
6532
+ const scopedToken = getScopeTokenClass(owner, /* legacy */ false);
6497
6533
  const stylesheetTokenHost = isVCustomElement(vnode) ? getStylesheetTokenHost(vnode) : null;
6498
6534
  // Classnames for scoped CSS are added directly to the DOM during rendering,
6499
6535
  // or to the VDOM on the server in the case of SSR. As such, these classnames
@@ -6903,5 +6939,5 @@ function readonly(obj) {
6903
6939
  }
6904
6940
 
6905
6941
  export { LightningElement, profilerControl as __unstable__ProfilerControl, reportingControl as __unstable__ReportingControl, api$1 as api, connectRootElement, createContextProviderWithRegister, createVM, disconnectRootElement, freezeTemplate, getAssociatedVMIfPresent, getComponentAPIVersion, getComponentConstructor, getComponentDef, getComponentHtmlPrototype, hydrateRoot, isComponentConstructor, parseFragment, parseSVGFragment, readonly, register, registerComponent, registerDecorators, registerTemplate, sanitizeAttribute, setHooks, swapComponent, swapStyle, swapTemplate, track, unwrap, wire };
6906
- /** version: 3.0.1 */
6942
+ /** version: 3.0.3 */
6907
6943
  //# sourceMappingURL=index.js.map