@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.
@@ -0,0 +1,2 @@
1
+ export declare const instrumentDef: any;
2
+ export declare const instrumentInstance: any;
@@ -12,14 +12,14 @@ export type StylesheetFactory = (stylesheetToken: string | undefined, useActualH
12
12
  * @import CSS declaration).
13
13
  */
14
14
  export type TemplateStylesheetFactories = Array<StylesheetFactory | TemplateStylesheetFactories>;
15
- export declare function updateStylesheetToken(vm: VM, template: Template): void;
15
+ export declare function updateStylesheetToken(vm: VM, template: Template, legacy: boolean): void;
16
16
  export declare function getStylesheetsContent(vm: VM, template: Template): string[];
17
17
  /**
18
18
  * If the component that is currently being rendered uses scoped styles,
19
19
  * this returns the unique token for that scoped stylesheet. Otherwise
20
20
  * it returns null.
21
21
  */
22
- export declare function getScopeTokenClass(owner: VM): string | null;
22
+ export declare function getScopeTokenClass(owner: VM, legacy: boolean): string | null;
23
23
  /**
24
24
  * This function returns the host style token for a custom element if it
25
25
  * exists. Otherwise it returns null.
@@ -10,6 +10,8 @@ export interface Template {
10
10
  stylesheets?: TemplateStylesheetFactories;
11
11
  /** The string used for synthetic shadow style scoping and light DOM style scoping. */
12
12
  stylesheetToken?: string;
13
+ /** Same as the above, but for legacy use cases (pre-LWC v3.0.0) */
14
+ legacyStylesheetToken?: string;
13
15
  /** Render mode for the template. Could be light or undefined (which means it's shadow) */
14
16
  renderMode?: 'light';
15
17
  /** True if this template contains template refs, undefined or false otherwise */
@@ -42,6 +42,12 @@ export interface Context {
42
42
  hasTokenInClass: boolean | undefined;
43
43
  /** True if a stylesheetToken was added to the host attributes */
44
44
  hasTokenInAttribute: boolean | undefined;
45
+ /** The legacy string used for synthetic shadow DOM and light DOM style scoping. */
46
+ legacyStylesheetToken: string | undefined;
47
+ /** True if a legacyStylesheetToken was added to the host class */
48
+ hasLegacyTokenInClass: boolean | undefined;
49
+ /** True if a legacyStylesheetToken was added to the host attributes */
50
+ hasLegacyTokenInAttribute: boolean | undefined;
45
51
  /** Whether or not light DOM scoped styles are present in the stylesheets. */
46
52
  hasScopedStyles: boolean | undefined;
47
53
  /** The VNodes injected in all the shadow trees to apply the associated component stylesheets. */
package/dist/index.cjs.js CHANGED
@@ -429,6 +429,10 @@ function isCircularModuleDependency(obj) {
429
429
  return shared.isFunction(obj) && shared.hasOwnProperty.call(obj, '__circular__');
430
430
  }
431
431
 
432
+ var _a, _b;
433
+ const instrumentDef = (_a = shared.globalThis.__lwc_instrument_cmp_def) !== null && _a !== void 0 ? _a : shared.noop;
434
+ const instrumentInstance = (_b = shared.globalThis.__lwc_instrument_cmp_instance) !== null && _b !== void 0 ? _b : shared.noop;
435
+
432
436
  /*
433
437
  * Copyright (c) 2018, salesforce.com, inc.
434
438
  * All rights reserved.
@@ -1397,6 +1401,8 @@ const LightningElement = function () {
1397
1401
  // `class Foo extends LightningElement {}; new Foo()`
1398
1402
  throw new TypeError('Illegal constructor');
1399
1403
  }
1404
+ // This is a no-op unless Lightning DevTools are enabled.
1405
+ instrumentInstance(this, vmBeingConstructed);
1400
1406
  const vm = vmBeingConstructed;
1401
1407
  const { def, elm } = vm;
1402
1408
  const { bridge } = def;
@@ -2545,35 +2551,8 @@ function createAttributeChangedCallback(attributeToPropMap, superAttributeChange
2545
2551
  };
2546
2552
  }
2547
2553
  function HTMLBridgeElementFactory(SuperClass, props, methods) {
2548
- let HTMLBridgeElement;
2549
- /**
2550
- * Modern browsers will have all Native Constructors as regular Classes
2551
- * and must be instantiated with the new keyword. In older browsers,
2552
- * specifically IE11, those are objects with a prototype property defined,
2553
- * since they are not supposed to be extended or instantiated with the
2554
- * new keyword. This forking logic supports both cases, specifically because
2555
- * wc.ts relies on the construction path of the bridges to create new
2556
- * fully qualifying web components.
2557
- */
2558
- if (shared.isFunction(SuperClass)) {
2559
- HTMLBridgeElement = class extends SuperClass {
2560
- };
2561
- }
2562
- else {
2563
- HTMLBridgeElement = function () {
2564
- // Bridge classes are not supposed to be instantiated directly in
2565
- // browsers that do not support web components.
2566
- throw new TypeError('Illegal constructor');
2567
- };
2568
- // prototype inheritance dance
2569
- shared.setPrototypeOf(HTMLBridgeElement, SuperClass);
2570
- shared.setPrototypeOf(HTMLBridgeElement.prototype, SuperClass.prototype);
2571
- shared.defineProperty(HTMLBridgeElement.prototype, 'constructor', {
2572
- writable: true,
2573
- configurable: true,
2574
- value: HTMLBridgeElement,
2575
- });
2576
- }
2554
+ const HTMLBridgeElement = class extends SuperClass {
2555
+ };
2577
2556
  // generating the hash table for attributes to avoid duplicate fields and facilitate validation
2578
2557
  // and false positives in case of inheritance.
2579
2558
  const attributeToPropMap = shared.create(null);
@@ -2981,6 +2960,8 @@ function createComponentDef(Ctor) {
2981
2960
  errorCallback,
2982
2961
  render,
2983
2962
  };
2963
+ // This is a no-op unless Lightning DevTools are enabled.
2964
+ instrumentDef(def);
2984
2965
  if (process.env.NODE_ENV !== 'production') {
2985
2966
  shared.freeze(Ctor.prototype);
2986
2967
  }
@@ -3109,9 +3090,11 @@ function createInlineStyleVNode(content) {
3109
3090
  },
3110
3091
  }, [api.t(content)]);
3111
3092
  }
3112
- function updateStylesheetToken(vm, template) {
3093
+ // TODO [#3733]: remove support for legacy scope tokens
3094
+ function updateStylesheetToken(vm, template, legacy) {
3113
3095
  const { elm, context, renderMode, shadowMode, renderer: { getClassList, removeAttribute, setAttribute }, } = vm;
3114
- const { stylesheets: newStylesheets, stylesheetToken: newStylesheetToken } = template;
3096
+ const { stylesheets: newStylesheets } = template;
3097
+ const newStylesheetToken = legacy ? template.legacyStylesheetToken : template.stylesheetToken;
3115
3098
  const { stylesheets: newVmStylesheets } = vm;
3116
3099
  const isSyntheticShadow = renderMode === 1 /* RenderMode.Shadow */ && shadowMode === 1 /* ShadowMode.Synthetic */;
3117
3100
  const { hasScopedStyles } = context;
@@ -3119,7 +3102,19 @@ function updateStylesheetToken(vm, template) {
3119
3102
  let newHasTokenInClass;
3120
3103
  let newHasTokenInAttribute;
3121
3104
  // Reset the styling token applied to the host element.
3122
- const { stylesheetToken: oldToken, hasTokenInClass: oldHasTokenInClass, hasTokenInAttribute: oldHasTokenInAttribute, } = context;
3105
+ let oldToken;
3106
+ let oldHasTokenInClass;
3107
+ let oldHasTokenInAttribute;
3108
+ if (legacy) {
3109
+ oldToken = context.legacyStylesheetToken;
3110
+ oldHasTokenInClass = context.hasLegacyTokenInClass;
3111
+ oldHasTokenInAttribute = context.hasLegacyTokenInAttribute;
3112
+ }
3113
+ else {
3114
+ oldToken = context.stylesheetToken;
3115
+ oldHasTokenInClass = context.hasTokenInClass;
3116
+ oldHasTokenInAttribute = context.hasTokenInAttribute;
3117
+ }
3123
3118
  if (!shared.isUndefined(oldToken)) {
3124
3119
  if (oldHasTokenInClass) {
3125
3120
  getClassList(elm).remove(makeHostToken(oldToken));
@@ -3147,9 +3142,16 @@ function updateStylesheetToken(vm, template) {
3147
3142
  }
3148
3143
  }
3149
3144
  // Update the styling tokens present on the context object.
3150
- context.stylesheetToken = newToken;
3151
- context.hasTokenInClass = newHasTokenInClass;
3152
- context.hasTokenInAttribute = newHasTokenInAttribute;
3145
+ if (legacy) {
3146
+ context.legacyStylesheetToken = newToken;
3147
+ context.hasLegacyTokenInClass = newHasTokenInClass;
3148
+ context.hasLegacyTokenInAttribute = newHasTokenInAttribute;
3149
+ }
3150
+ else {
3151
+ context.stylesheetToken = newToken;
3152
+ context.hasTokenInClass = newHasTokenInClass;
3153
+ context.hasTokenInAttribute = newHasTokenInAttribute;
3154
+ }
3153
3155
  }
3154
3156
  function evaluateStylesheetsContent(stylesheets, stylesheetToken, vm) {
3155
3157
  const content = [];
@@ -3236,9 +3238,12 @@ function getNearestShadowComponent(vm) {
3236
3238
  * this returns the unique token for that scoped stylesheet. Otherwise
3237
3239
  * it returns null.
3238
3240
  */
3239
- function getScopeTokenClass(owner) {
3241
+ // TODO [#3733]: remove support for legacy scope tokens
3242
+ function getScopeTokenClass(owner, legacy) {
3240
3243
  const { cmpTemplate, context } = owner;
3241
- return (context.hasScopedStyles && (cmpTemplate === null || cmpTemplate === void 0 ? void 0 : cmpTemplate.stylesheetToken)) || null;
3244
+ return ((context.hasScopedStyles &&
3245
+ (legacy ? cmpTemplate === null || cmpTemplate === void 0 ? void 0 : cmpTemplate.legacyStylesheetToken : cmpTemplate === null || cmpTemplate === void 0 ? void 0 : cmpTemplate.stylesheetToken)) ||
3246
+ null);
3242
3247
  }
3243
3248
  /**
3244
3249
  * This function returns the host style token for a custom element if it
@@ -3964,18 +3969,35 @@ function patchElementPropsAndAttrs$1(oldVnode, vnode, renderer) {
3964
3969
  patchProps(oldVnode, vnode, renderer);
3965
3970
  }
3966
3971
  function applyStyleScoping(elm, owner, renderer) {
3972
+ const { getClassList } = renderer;
3967
3973
  // Set the class name for `*.scoped.css` style scoping.
3968
- const scopeToken = getScopeTokenClass(owner);
3974
+ const scopeToken = getScopeTokenClass(owner, /* legacy */ false);
3969
3975
  if (!shared.isNull(scopeToken)) {
3970
- const { getClassList } = renderer;
3971
3976
  // TODO [#2762]: this dot notation with add is probably problematic
3972
3977
  // probably we should have a renderer api for just the add operation
3973
3978
  getClassList(elm).add(scopeToken);
3974
3979
  }
3980
+ // TODO [#3733]: remove support for legacy scope tokens
3981
+ if (lwcRuntimeFlags.ENABLE_LEGACY_SCOPE_TOKENS) {
3982
+ const legacyScopeToken = getScopeTokenClass(owner, /* legacy */ true);
3983
+ if (!shared.isNull(legacyScopeToken)) {
3984
+ // TODO [#2762]: this dot notation with add is probably problematic
3985
+ // probably we should have a renderer api for just the add operation
3986
+ getClassList(elm).add(legacyScopeToken);
3987
+ }
3988
+ }
3975
3989
  // Set property element for synthetic shadow DOM style scoping.
3976
3990
  const { stylesheetToken: syntheticToken } = owner.context;
3977
- if (owner.shadowMode === 1 /* ShadowMode.Synthetic */ && !shared.isUndefined(syntheticToken)) {
3978
- elm.$shadowToken$ = syntheticToken;
3991
+ if (owner.shadowMode === 1 /* ShadowMode.Synthetic */) {
3992
+ if (!shared.isUndefined(syntheticToken)) {
3993
+ elm.$shadowToken$ = syntheticToken;
3994
+ }
3995
+ if (lwcRuntimeFlags.ENABLE_LEGACY_SCOPE_TOKENS) {
3996
+ const legacyToken = owner.context.legacyStylesheetToken;
3997
+ if (!shared.isUndefined(legacyToken)) {
3998
+ elm.$legacyShadowToken$ = legacyToken;
3999
+ }
4000
+ }
3979
4001
  }
3980
4002
  }
3981
4003
  function applyDomManual(elm, vnode) {
@@ -4148,12 +4170,11 @@ function allocateInSlot(vm, children, owner) {
4148
4170
  }
4149
4171
  }
4150
4172
  }
4151
- // Using a WeakMap instead of a WeakSet because this one works in IE11 :(
4152
- const DynamicChildren = new WeakMap();
4173
+ const DynamicChildren = new WeakSet();
4153
4174
  // dynamic children means it was either generated by an iteration in a template
4154
4175
  // or part of an unstable fragment, and will require a more complex diffing algo.
4155
4176
  function markAsDynamicChildren(children) {
4156
- DynamicChildren.set(children, 1);
4177
+ DynamicChildren.add(children);
4157
4178
  }
4158
4179
  function hasDynamicChildren(children) {
4159
4180
  return DynamicChildren.has(children);
@@ -5003,9 +5024,10 @@ function buildParseFragmentFn(createFragmentFn) {
5003
5024
  return (strings, ...keys) => {
5004
5025
  const cache = shared.create(null);
5005
5026
  return function () {
5006
- const { context: { hasScopedStyles, stylesheetToken }, shadowMode, renderer, } = getVMBeingRendered();
5027
+ const { context: { hasScopedStyles, stylesheetToken, legacyStylesheetToken }, shadowMode, renderer, } = getVMBeingRendered();
5007
5028
  const hasStyleToken = !shared.isUndefined(stylesheetToken);
5008
5029
  const isSyntheticShadow = shadowMode === 1 /* ShadowMode.Synthetic */;
5030
+ const hasLegacyToken = lwcRuntimeFlags.ENABLE_LEGACY_SCOPE_TOKENS && !shared.isUndefined(legacyStylesheetToken);
5009
5031
  let cacheKey = 0;
5010
5032
  if (hasStyleToken && hasScopedStyles) {
5011
5033
  cacheKey |= 1 /* FragmentCache.HAS_SCOPED_STYLE */;
@@ -5013,12 +5035,19 @@ function buildParseFragmentFn(createFragmentFn) {
5013
5035
  if (hasStyleToken && isSyntheticShadow) {
5014
5036
  cacheKey |= 2 /* FragmentCache.SHADOW_MODE_SYNTHETIC */;
5015
5037
  }
5038
+ if (hasLegacyToken) {
5039
+ // This isn't strictly required for prod, but it's required for our karma tests
5040
+ // since the lwcRuntimeFlag may change over time
5041
+ cacheKey |= 4 /* FragmentCache.HAS_LEGACY_SCOPE_TOKEN */;
5042
+ }
5016
5043
  if (!shared.isUndefined(cache[cacheKey])) {
5017
5044
  return cache[cacheKey];
5018
5045
  }
5019
- const classToken = hasScopedStyles && hasStyleToken ? ' ' + stylesheetToken : '';
5020
- const classAttrToken = hasScopedStyles && hasStyleToken ? ` class="${stylesheetToken}"` : '';
5021
- const attrToken = hasStyleToken && isSyntheticShadow ? ' ' + stylesheetToken : '';
5046
+ // If legacy stylesheet tokens are required, then add them to the rendered string
5047
+ const stylesheetTokenToRender = stylesheetToken + (hasLegacyToken ? ` ${legacyStylesheetToken}` : '');
5048
+ const classToken = hasScopedStyles && hasStyleToken ? ' ' + stylesheetTokenToRender : '';
5049
+ const classAttrToken = hasScopedStyles && hasStyleToken ? ` class="${stylesheetTokenToRender}"` : '';
5050
+ const attrToken = hasStyleToken && isSyntheticShadow ? ' ' + stylesheetTokenToRender : '';
5022
5051
  let htmlFragment = '';
5023
5052
  for (let i = 0, n = keys.length; i < n; i++) {
5024
5053
  switch (keys[i]) {
@@ -5094,7 +5123,10 @@ function evaluateTemplate(vm, html) {
5094
5123
  // Set the computeHasScopedStyles property in the context, to avoid recomputing it repeatedly.
5095
5124
  context.hasScopedStyles = computeHasScopedStyles(html, vm);
5096
5125
  // Update the scoping token on the host element.
5097
- updateStylesheetToken(vm, html);
5126
+ updateStylesheetToken(vm, html, /* legacy */ false);
5127
+ if (lwcRuntimeFlags.ENABLE_LEGACY_SCOPE_TOKENS) {
5128
+ updateStylesheetToken(vm, html, /* legacy */ true);
5129
+ }
5098
5130
  // Evaluate, create stylesheet and cache the produced VNode for future
5099
5131
  // re-rendering.
5100
5132
  const stylesheetsContent = getStylesheetsContent(vm, html);
@@ -5464,6 +5496,9 @@ function createVM(elm, ctor, renderer, options) {
5464
5496
  stylesheetToken: undefined,
5465
5497
  hasTokenInClass: undefined,
5466
5498
  hasTokenInAttribute: undefined,
5499
+ legacyStylesheetToken: undefined,
5500
+ hasLegacyTokenInClass: undefined,
5501
+ hasLegacyTokenInAttribute: undefined,
5467
5502
  hasScopedStyles: undefined,
5468
5503
  styleVNodes: null,
5469
5504
  tplCache: EmptyObject,
@@ -6497,7 +6532,8 @@ function validateClassAttr(vnode, elm, renderer) {
6497
6532
  const { data, owner } = vnode;
6498
6533
  let { className, classMap } = data;
6499
6534
  const { getProperty, getClassList, getAttribute } = renderer;
6500
- const scopedToken = getScopeTokenClass(owner);
6535
+ // we don't care about legacy for hydration. it's a new use case
6536
+ const scopedToken = getScopeTokenClass(owner, /* legacy */ false);
6501
6537
  const stylesheetTokenHost = isVCustomElement(vnode) ? getStylesheetTokenHost(vnode) : null;
6502
6538
  // Classnames for scoped CSS are added directly to the DOM during rendering,
6503
6539
  // or to the VDOM on the server in the case of SSR. As such, these classnames
@@ -6945,5 +6981,5 @@ exports.swapTemplate = swapTemplate;
6945
6981
  exports.track = track;
6946
6982
  exports.unwrap = unwrap;
6947
6983
  exports.wire = wire;
6948
- /** version: 3.0.1 */
6984
+ /** version: 3.0.3 */
6949
6985
  //# sourceMappingURL=index.cjs.js.map