UNPKG

@lwc/engine-server

Version:

Renders LWC components in a server environment.

1,368 lines (1,336 loc) 346 kB
/** * Copyright (c) 2026 Salesforce, Inc. */ 'use strict'; Object.defineProperty(exports, '__esModule', { value: true }); /** * Copyright (c) 2026 Salesforce, Inc. */ /* * Copyright (c) 2018, salesforce.com, inc. * All rights reserved. * SPDX-License-Identifier: MIT * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT */ /** * * @param value * @param msg */ function invariant(value, msg) { if (!value) { throw new Error(`Invariant Violation: ${msg}`); } } /** * * @param value * @param msg */ function isTrue$1(value, msg) { if (!value) { throw new Error(`Assert Violation: ${msg}`); } } /** * * @param value * @param msg */ function isFalse$1(value, msg) { if (value) { throw new Error(`Assert Violation: ${msg}`); } } /** * * @param msg */ function fail(msg) { throw new Error(msg); } var assert = /*#__PURE__*/Object.freeze({ __proto__: null, fail: fail, invariant: invariant, isFalse: isFalse$1, isTrue: isTrue$1 }); /* * Copyright (c) 2024, Salesforce, Inc. * All rights reserved. * SPDX-License-Identifier: MIT * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT */ const { /** Detached {@linkcode Object.assign}; see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/assign MDN Reference}. */ assign, /** Detached {@linkcode Object.create}; see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/create MDN Reference}. */ create, /** Detached {@linkcode Object.defineProperties}; see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/defineProperties MDN Reference}. */ defineProperties, /** Detached {@linkcode Object.defineProperty}; see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/defineProperty MDN Reference}. */ defineProperty, /** Detached {@linkcode Object.entries}; see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/entries MDN Reference}. */ entries, /** Detached {@linkcode Object.freeze}; see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/freeze MDN Reference}. */ freeze, /** Detached {@linkcode Object.getOwnPropertyDescriptor}; see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/getOwnPropertyDescriptor MDN Reference}. */ getOwnPropertyDescriptor: getOwnPropertyDescriptor$1, /** Detached {@linkcode Object.getOwnPropertyNames}; see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/getOwnPropertyNames MDN Reference}. */ getOwnPropertyNames: getOwnPropertyNames$1, /** Detached {@linkcode Object.getOwnPropertySymbols}; see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/getOwnPropertySymbols MDN Reference}. */ getOwnPropertySymbols: getOwnPropertySymbols$1, /** Detached {@linkcode Object.getPrototypeOf}; see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/getPrototypeOf MDN Reference}. */ getPrototypeOf: getPrototypeOf$1, /** Detached {@linkcode Object.hasOwnProperty}; see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/hasOwnProperty MDN Reference}. */ hasOwnProperty: hasOwnProperty$1, /** Detached {@linkcode Object.isFrozen}; see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/isFrozen MDN Reference}. */ isFrozen, /** Detached {@linkcode Object.keys}; see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/keys MDN Reference}. */ keys, /** Detached {@linkcode Object.seal}; see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/seal MDN Reference}. */ seal, /** Detached {@linkcode Object.setPrototypeOf}; see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/setPrototypeOf MDN Reference}. */ setPrototypeOf, } = Object; const { /** Detached {@linkcode Array.isArray}; see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/isArray MDN Reference}. */ isArray: isArray$1, /** Detached {@linkcode Array.from}; see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/from MDN Reference}. */ from: ArrayFrom, } = Array; // For some reason, JSDoc don't get picked up for multiple renamed destructured constants (even // though it works fine for one, e.g. isArray), so comments for these are added to the export // statement, rather than this declaration. const { copyWithin: ArrayCopyWithin, fill: ArrayFill, filter: ArrayFilter, join: ArrayJoin, map: ArrayMap, pop: ArrayPop, push: ArrayPush$1, reverse: ArrayReverse, shift: ArrayShift, slice: ArraySlice, some: ArraySome, sort: ArraySort, splice: ArraySplice, unshift: ArrayUnshift, forEach, // Weird anomaly! } = Array.prototype; /** Detached {@linkcode String.fromCharCode}; see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCharCode MDN Reference}. */ const { fromCharCode: StringFromCharCode } = String; // No JSDocs here - see comment for Array.prototype const { charAt: StringCharAt, charCodeAt: StringCharCodeAt, replace: StringReplace, slice: StringSlice, toLowerCase: StringToLowerCase, trim: StringTrim, } = String.prototype; /** * Determines whether the argument is `undefined`. * @param obj Value to test * @returns `true` if the value is `undefined`. */ function isUndefined$1(obj) { return obj === undefined; } /** * Determines whether the argument is `null`. * @param obj Value to test * @returns `true` if the value is `null`. */ function isNull(obj) { return obj === null; } /** * Determines whether the argument is `true`. * @param obj Value to test * @returns `true` if the value is `true`. */ function isTrue(obj) { return obj === true; } /** * Determines whether the argument is `false`. * @param obj Value to test * @returns `true` if the value is `false`. */ function isFalse(obj) { return obj === false; } /** * Determines whether the argument is a boolean. * @param obj Value to test * @returns `true` if the value is a boolean. */ function isBoolean(obj) { return typeof obj === 'boolean'; } /** * Determines whether the argument is a function. * @param obj Value to test * @returns `true` if the value is a function. */ // Replacing `Function` with a narrower type that works for all our use cases is tricky... // eslint-disable-next-line @typescript-eslint/no-unsafe-function-type function isFunction$1(obj) { return typeof obj === 'function'; } /** * Determines whether the argument is an object or null. * @param obj Value to test * @returns `true` if the value is an object or null. */ function isObject(obj) { return typeof obj === 'object'; } /** * Determines whether the argument is a string. * @param obj Value to test * @returns `true` if the value is a string. */ function isString(obj) { return typeof obj === 'string'; } /** * Determines whether the argument is a number. * @param obj Value to test * @returns `true` if the value is a number. */ function isNumber(obj) { return typeof obj === 'number'; } /** Does nothing! 🚀 */ function noop() { /* Do nothing */ } const OtS = {}.toString; /** * Converts the argument to a string, safely accounting for objects with "null" prototype. * Note that `toString(null)` returns `"[object Null]"` rather than `"null"`. * @param obj Value to convert to a string. * @returns String representation of the value. */ function toString(obj) { if (obj?.toString) { // Arrays might hold objects with "null" prototype So using // Array.prototype.toString directly will cause an error Iterate through // all the items and handle individually. if (isArray$1(obj)) { // This behavior is slightly different from Array#toString: // 1. Array#toString calls `this.join`, rather than Array#join // Ex: arr = []; arr.join = () => 1; arr.toString() === 1; toString(arr) === '' // 2. Array#toString delegates to Object#toString if `this.join` is not a function // Ex: arr = []; arr.join = 'no'; arr.toString() === '[object Array]; toString(arr) = '' // 3. Array#toString converts null/undefined to '' // Ex: arr = [null, undefined]; arr.toString() === ','; toString(arr) === '[object Null],undefined' // 4. Array#toString converts recursive references to arrays to '' // Ex: arr = [1]; arr.push(arr, 2); arr.toString() === '1,,2'; toString(arr) throws // Ref: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/toString return ArrayJoin.call(ArrayMap.call(obj, toString), ','); } return obj.toString(); } else if (typeof obj === 'object') { // This catches null and returns "[object Null]". Weird, but kept for backwards compatibility. return OtS.call(obj); } else { return String(obj); } } /** * Gets the property descriptor for the given object and property key. Similar to * {@linkcode Object.getOwnPropertyDescriptor}, but looks up the prototype chain. * @param o Value to get the property descriptor for * @param p Property key to get the descriptor for * @returns The property descriptor for the given object and property key. */ function getPropertyDescriptor(o, p) { do { const d = getOwnPropertyDescriptor$1(o, p); if (!isUndefined$1(d)) { return d; } o = getPrototypeOf$1(o); } while (o !== null); } /* * Copyright (c) 2023, salesforce.com, inc. * All rights reserved. * SPDX-License-Identifier: MIT * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT */ // These must be updated when the enum is updated. // It's a bit annoying to do have to do this manually, but this makes the file tree-shakeable, // passing the `verify-treeshakeable.js` test. const allVersions = [ 58 /* APIVersion.V58_244_SUMMER_23 */, 59 /* APIVersion.V59_246_WINTER_24 */, 60 /* APIVersion.V60_248_SPRING_24 */, 61 /* APIVersion.V61_250_SUMMER_24 */, 62 /* APIVersion.V62_252_WINTER_25 */, 63 /* APIVersion.V63_254_SPRING_25 */, 64 /* APIVersion.V64_256_SUMMER_25 */, 65 /* APIVersion.V65_258_WINTER_26 */, 66 /* APIVersion.V66_260_SPRING_26 */, ]; const LOWEST_API_VERSION = allVersions[0]; /** * @param apiVersionFeature */ function minApiVersion(apiVersionFeature) { switch (apiVersionFeature) { case 0 /* APIFeature.LOWERCASE_SCOPE_TOKENS */: case 1 /* APIFeature.TREAT_ALL_PARSE5_ERRORS_AS_ERRORS */: return 59 /* APIVersion.V59_246_WINTER_24 */; case 3 /* APIFeature.DISABLE_OBJECT_REST_SPREAD_TRANSFORMATION */: case 4 /* APIFeature.SKIP_UNNECESSARY_REGISTER_DECORATORS */: case 5 /* APIFeature.USE_COMMENTS_FOR_FRAGMENT_BOOKENDS */: case 2 /* APIFeature.USE_FRAGMENTS_FOR_LIGHT_DOM_SLOTS */: return 60 /* APIVersion.V60_248_SPRING_24 */; case 7 /* APIFeature.ENABLE_ELEMENT_INTERNALS_AND_FACE */: case 6 /* APIFeature.USE_LIGHT_DOM_SLOT_FORWARDING */: return 61 /* APIVersion.V61_250_SUMMER_24 */; case 8 /* APIFeature.ENABLE_THIS_DOT_HOST_ELEMENT */: case 9 /* APIFeature.ENABLE_THIS_DOT_STYLE */: case 10 /* APIFeature.TEMPLATE_CLASS_NAME_OBJECT_BINDING */: return 62 /* APIVersion.V62_252_WINTER_25 */; case 11 /* APIFeature.ENABLE_COMPLEX_TEMPLATE_EXPRESSIONS */: return 66 /* APIVersion.V66_260_SPRING_26 */; } } /** * * @param apiVersionFeature * @param apiVersion */ function isAPIFeatureEnabled(apiVersionFeature, apiVersion) { return apiVersion >= minApiVersion(apiVersionFeature); } /* * Copyright (c) 2018, salesforce.com, inc. * All rights reserved. * SPDX-License-Identifier: MIT * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT */ /** * According to the following list, there are 48 aria attributes of which two (ariaDropEffect and * ariaGrabbed) are deprecated: * https://www.w3.org/TR/wai-aria-1.1/#x6-6-definitions-of-states-and-properties-all-aria-attributes * * The above list of 46 aria attributes is consistent with the following resources: * https://github.com/w3c/aria/pull/708/files#diff-eacf331f0ffc35d4b482f1d15a887d3bR11060 * https://wicg.github.io/aom/spec/aria-reflection.html * * NOTE: If you update this list, please update test files that implicitly reference this list! * Searching the codebase for `aria-flowto` and `ariaFlowTo` should be good enough to find all usages. */ const AriaPropertyNames = [ 'ariaActiveDescendant', 'ariaAtomic', 'ariaAutoComplete', 'ariaBusy', 'ariaChecked', 'ariaColCount', 'ariaColIndex', 'ariaColIndexText', 'ariaColSpan', 'ariaControls', 'ariaCurrent', 'ariaDescribedBy', 'ariaDescription', 'ariaDetails', 'ariaDisabled', 'ariaErrorMessage', 'ariaExpanded', 'ariaFlowTo', 'ariaHasPopup', 'ariaHidden', 'ariaInvalid', 'ariaKeyShortcuts', 'ariaLabel', 'ariaLabelledBy', 'ariaLevel', 'ariaLive', 'ariaModal', 'ariaMultiLine', 'ariaMultiSelectable', 'ariaOrientation', 'ariaOwns', 'ariaPlaceholder', 'ariaPosInSet', 'ariaPressed', 'ariaReadOnly', 'ariaRelevant', 'ariaRequired', 'ariaRoleDescription', 'ariaRowCount', 'ariaRowIndex', 'ariaRowIndexText', 'ariaRowSpan', 'ariaSelected', 'ariaSetSize', 'ariaSort', 'ariaValueMax', 'ariaValueMin', 'ariaValueNow', 'ariaValueText', 'ariaBrailleLabel', 'ariaBrailleRoleDescription', 'role', ]; const { AriaAttrNameToPropNameMap, AriaPropNameToAttrNameMap } = /*@__PURE__*/ (() => { const AriaAttrNameToPropNameMap = create(null); const AriaPropNameToAttrNameMap = create(null); // Synthetic creation of all AOM property descriptors for Custom Elements forEach.call(AriaPropertyNames, (propName) => { const attrName = StringToLowerCase.call(StringReplace.call(propName, /^aria/, () => 'aria-')); // These type assertions are because the map types are a 1:1 mapping of ariaX to aria-x. // TypeScript knows we have one of ariaX | ariaY and one of aria-x | aria-y, and tries to // prevent us from doing ariaX: aria-y, but we that it's safe. AriaAttrNameToPropNameMap[attrName] = propName; AriaPropNameToAttrNameMap[propName] = attrName; }); return { AriaAttrNameToPropNameMap, AriaPropNameToAttrNameMap }; })(); /** * * @param attrName */ function isAriaAttribute(attrName) { return attrName in AriaAttrNameToPropNameMap; } /* * Copyright (c) 2024, salesforce.com, inc. * All rights reserved. * SPDX-License-Identifier: MIT * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT */ const ContextEventName = 'lightning:context-request'; let trustedContext; let contextKeys; function setContextKeys(config) { isFalse$1(contextKeys, '`setContextKeys` cannot be called more than once'); contextKeys = config; } function getContextKeys() { return contextKeys; } function setTrustedContextSet(context) { isFalse$1(trustedContext, 'Trusted Context Set is already set!'); trustedContext = context; } function addTrustedContext(contextParticipant) { // This should be a no-op when the trustedSignals set isn't set by runtime trustedContext?.add(contextParticipant); } function isTrustedContext(target) { if (!trustedContext) { // The runtime didn't set a trustedContext set // this check should only be performed for runtimes that care about filtering context participants to track return true; } return trustedContext.has(target); } /* * Copyright (c) 2023, Salesforce.com, inc. * All rights reserved. * SPDX-License-Identifier: MIT * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT */ const KEY__SHADOW_RESOLVER = '$shadowResolver$'; const KEY__SHADOW_STATIC = '$shadowStaticNode$'; const KEY__SYNTHETIC_MODE = '$$lwc-synthetic-mode'; const KEY__SCOPED_CSS = '$scoped$'; const KEY__NATIVE_ONLY_CSS = '$nativeOnly$'; const KEY__NATIVE_GET_ELEMENT_BY_ID = '$nativeGetElementById$'; const KEY__NATIVE_QUERY_SELECTOR_ALL = '$nativeQuerySelectorAll$'; /* * Copyright (c) 2022, salesforce.com, inc. * All rights reserved. * SPDX-License-Identifier: MIT * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT */ const HTML_NAMESPACE = 'http://www.w3.org/1999/xhtml'; const XML_NAMESPACE = 'http://www.w3.org/XML/1998/namespace'; const SVG_NAMESPACE = 'http://www.w3.org/2000/svg'; const XLINK_NAMESPACE = 'http://www.w3.org/1999/xlink'; /* * Copyright (c) 2020, salesforce.com, inc. * All rights reserved. * SPDX-License-Identifier: MIT * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT */ // Void elements are elements that self-close even without an explicit solidus (slash), // e.g. `</tagName>` or `<tagName />`. For instance, `<meta>` closes on its own; no need for a slash. // These only come from HTML; there are no void elements in the SVG or MathML namespaces. // See: https://html.spec.whatwg.org/multipage/syntax.html#syntax-tags const VOID_ELEMENTS = [ 'area', 'base', 'br', 'col', 'embed', 'hr', 'img', 'input', 'link', 'meta', 'source', 'track', 'wbr', ]; // These elements have been deprecated but preserving their usage for backwards compatibility // until we can officially deprecate them from LWC. // See: https://html.spec.whatwg.org/multipage/obsolete.html#obsolete-but-conforming-features const DEPRECATED_VOID_ELEMENTS = ['param', 'keygen', 'menuitem']; const VOID_ELEMENTS_SET = /*@__PURE__*/ new Set([...VOID_ELEMENTS, ...DEPRECATED_VOID_ELEMENTS]); /** * * @param name * @param namespace */ function isVoidElement(name, namespace) { return namespace === HTML_NAMESPACE && VOID_ELEMENTS_SET.has(name.toLowerCase()); } /* * Copyright (c) 2020, salesforce.com, inc. * All rights reserved. * SPDX-License-Identifier: MIT * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT */ const CAMEL_REGEX = /-([a-z])/g; /** * Maps boolean attribute name to supported tags: 'boolean attr name' => Set of allowed tag names * that supports them. */ const BOOLEAN_ATTRIBUTES = /*@__PURE__@*/ new Map([ ['autofocus', /*@__PURE__@*/ new Set(['button', 'input', 'keygen', 'select', 'textarea'])], ['autoplay', /*@__PURE__@*/ new Set(['audio', 'video'])], ['checked', /*@__PURE__@*/ new Set(['command', 'input'])], [ 'disabled', /*@__PURE__@*/ new Set([ 'button', 'command', 'fieldset', 'input', 'keygen', 'optgroup', 'select', 'textarea', ]), ], ['formnovalidate', /*@__PURE__@*/ new Set(['button'])], // button[type=submit] ['hidden', /*@__PURE__@*/ new Set()], // Global attribute ['loop', /*@__PURE__@*/ new Set(['audio', 'bgsound', 'marquee', 'video'])], ['multiple', /*@__PURE__@*/ new Set(['input', 'select'])], ['muted', /*@__PURE__@*/ new Set(['audio', 'video'])], ['novalidate', /*@__PURE__@*/ new Set(['form'])], ['open', /*@__PURE__@*/ new Set(['details'])], ['readonly', /*@__PURE__@*/ new Set(['input', 'textarea'])], ['readonly', /*@__PURE__@*/ new Set(['input', 'textarea'])], ['required', /*@__PURE__@*/ new Set(['input', 'select', 'textarea'])], ['reversed', /*@__PURE__@*/ new Set(['ol'])], ['selected', /*@__PURE__@*/ new Set(['option'])], ]); /** * * @param attrName * @param tagName */ function isBooleanAttribute(attrName, tagName) { const allowedTagNames = BOOLEAN_ATTRIBUTES.get(attrName); return (allowedTagNames !== undefined && (allowedTagNames.size === 0 || allowedTagNames.has(tagName))); } // These are HTML standard prop/attribute IDL mappings, but are not predictable based on camel/kebab-case conversion const SPECIAL_PROPERTY_ATTRIBUTE_MAPPING = /*@__PURE__@*/ new Map([ ['accessKey', 'accesskey'], ['readOnly', 'readonly'], ['tabIndex', 'tabindex'], ['bgColor', 'bgcolor'], ['colSpan', 'colspan'], ['rowSpan', 'rowspan'], ['contentEditable', 'contenteditable'], ['crossOrigin', 'crossorigin'], ['dateTime', 'datetime'], ['formAction', 'formaction'], ['isMap', 'ismap'], ['maxLength', 'maxlength'], ['minLength', 'minlength'], ['noValidate', 'novalidate'], ['useMap', 'usemap'], ['htmlFor', 'for'], ]); // Global properties that this framework currently reflects. For CSR, the native // descriptors for these properties are added from HTMLElement.prototype to // LightningElement.prototype. For SSR, in order to match CSR behavior, this // list is used to determine which attributes to reflect. const REFLECTIVE_GLOBAL_PROPERTY_SET = /*@__PURE__@*/ new Set([ 'accessKey', 'dir', 'draggable', 'hidden', 'id', 'lang', 'spellcheck', 'tabIndex', 'title', ]); /** * Map associating previously transformed HTML property into HTML attribute. */ const CACHED_PROPERTY_ATTRIBUTE_MAPPING = /*@__PURE__@*/ new Map(); /** * * @param propName */ function htmlPropertyToAttribute(propName) { const ariaAttributeName = AriaPropNameToAttrNameMap[propName]; if (!isUndefined$1(ariaAttributeName)) { return ariaAttributeName; } const specialAttributeName = SPECIAL_PROPERTY_ATTRIBUTE_MAPPING.get(propName); if (!isUndefined$1(specialAttributeName)) { return specialAttributeName; } const cachedAttributeName = CACHED_PROPERTY_ATTRIBUTE_MAPPING.get(propName); if (!isUndefined$1(cachedAttributeName)) { return cachedAttributeName; } let attributeName = ''; for (let i = 0, len = propName.length; i < len; i++) { const code = StringCharCodeAt.call(propName, i); if (code >= 65 && // "A" code <= 90 // "Z" ) { attributeName += '-' + StringFromCharCode(code + 32); } else { attributeName += StringFromCharCode(code); } } CACHED_PROPERTY_ATTRIBUTE_MAPPING.set(propName, attributeName); return attributeName; } /** * Map associating previously transformed kabab-case attributes into camel-case props. */ const CACHED_KEBAB_CAMEL_MAPPING = /*@__PURE__@*/ new Map(); /** * * @param attrName */ function kebabCaseToCamelCase(attrName) { let result = CACHED_KEBAB_CAMEL_MAPPING.get(attrName); if (isUndefined$1(result)) { result = StringReplace.call(attrName, CAMEL_REGEX, (g) => g[1].toUpperCase()); CACHED_KEBAB_CAMEL_MAPPING.set(attrName, result); } return result; } /* * Copyright (c) 2020, salesforce.com, inc. * All rights reserved. * SPDX-License-Identifier: MIT * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT */ const ESCAPED_CHARS = { '"': '&quot;', "'": '&#x27;', '<': '&lt;', '>': '&gt;', '&': '&amp;', }; /** * * @param str * @param attrMode */ function htmlEscape(str, attrMode = false) { const searchValue = attrMode ? /["&]/g : /["'<>&]/g; return str.replace(searchValue, (char) => ESCAPED_CHARS[char]); } /* * Copyright (c) 2018, salesforce.com, inc. * All rights reserved. * SPDX-License-Identifier: MIT * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT */ // Increment whenever the LWC template compiler changes const LWC_VERSION = "9.2.0"; const LWC_VERSION_COMMENT_REGEX = /\/\*LWC compiler v([\d.]+)\*\/\s*}/; /* * Copyright (c) 2020, salesforce.com, inc. * All rights reserved. * SPDX-License-Identifier: MIT * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT */ /** * [ncls] - Normalize class name attribute. * * Transforms the provided class property value from an object/string into a string the diffing algo * can operate on. * * This implementation is borrowed from Vue: * https://github.com/vuejs/core/blob/e790e1bdd7df7be39e14780529db86e4da47a3db/packages/shared/src/normalizeProp.ts#L63-L82 */ function normalizeClass(value) { if (isUndefined$1(value) || isNull(value)) { // Returning undefined here improves initial render cost, because the old vnode's class will be considered // undefined in the `patchClassAttribute` routine, so `oldClass === newClass` will be true so we return early return undefined; } let res = ''; if (isString(value)) { res = value; } else if (isArray$1(value)) { for (let i = 0; i < value.length; i++) { const normalized = normalizeClass(value[i]); if (normalized) { res += normalized + ' '; } } } else if (isObject(value) && !isNull(value)) { // Iterate own enumerable keys of the object const _keys = keys(value); for (let i = 0; i < _keys.length; i += 1) { const key = _keys[i]; if (value[key]) { res += key + ' '; } } } return StringTrim.call(res); } /* * Copyright (c) 2024, Salesforce, Inc. * All rights reserved. * SPDX-License-Identifier: MIT * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT */ let hooksAreSet = false; let sanitizeHtmlContentImpl = () => { // locker-service patches this function during runtime to sanitize HTML content. throw new Error('sanitizeHtmlContent hook must be implemented.'); }; /** * EXPERIMENTAL: This function acts like a hook for Lightning Locker Service and other similar * libraries to sanitize HTML content. This hook process the content passed via the template to * lwc:inner-html directive. * It is meant to be overridden via `setHooks`; it throws an error by default. */ const sanitizeHtmlContent = (value) => { return sanitizeHtmlContentImpl(value); }; function setHooks(hooks) { isFalse$1(hooksAreSet, 'Hooks are already overridden, only one definition is allowed.'); hooksAreSet = true; sanitizeHtmlContentImpl = hooks.sanitizeHtmlContent; } function flattenStylesheets(stylesheets) { const list = []; for (const stylesheet of stylesheets) { if (!isArray$1(stylesheet)) { list.push(stylesheet); } else { list.push(...flattenStylesheets(stylesheet)); } } return list; } function isTrustedSignal(target) { { return false; } } /** version: 9.2.0 */ /** * Copyright (c) 2026 Salesforce, Inc. */ /* * Copyright (c) 2024, Salesforce, Inc. * All rights reserved. * SPDX-License-Identifier: MIT * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT */ // When deprecating a feature flag, ensure that it is also no longer set in the application. For // example, in core, the flag should be removed from LwcPermAndPrefUtilImpl.java /** List of all feature flags available, with the default value `null`. */ const features = { PLACEHOLDER_TEST_FLAG: null, DISABLE_NATIVE_CUSTOM_ELEMENT_LIFECYCLE: null, ENABLE_WIRE_SYNC_EMIT: null, DISABLE_LIGHT_DOM_UNSCOPED_CSS: null, ENABLE_FROZEN_TEMPLATE: null, ENABLE_LEGACY_SCOPE_TOKENS: null, ENABLE_FORCE_SHADOW_MIGRATE_MODE: null, ENABLE_EXPERIMENTAL_SIGNALS: null, ENABLE_LEGACY_SIGNAL_CONTEXT_VALIDATION: null, DISABLE_SYNTHETIC_SHADOW: null, DISABLE_SCOPE_TOKEN_VALIDATION: null, DISABLE_STRICT_VALIDATION: null, DISABLE_DETACHED_REHYDRATION: null, ENABLE_LEGACY_CONTEXT_CONNECTION: null, }; if (!globalThis.lwcRuntimeFlags) { Object.defineProperty(globalThis, 'lwcRuntimeFlags', { value: create(null) }); } /** Feature flags that have been set. */ const flags = globalThis.lwcRuntimeFlags; /** * Set the value at runtime of a given feature flag. This method only be invoked once per feature * flag. It is meant to be used during the app initialization. * @param name Name of the feature flag to set * @param value Whether the feature flag should be enabled * @throws Will throw if a non-boolean value is provided when running in production. * @example setFeatureFlag("DISABLE_NATIVE_CUSTOM_ELEMENT_LIFECYCLE", true) */ function setFeatureFlag(name, value) { if (!isBoolean(value)) { const message = `Failed to set the value "${value}" for the runtime feature flag "${name}". Runtime feature flags can only be set to a boolean value.`; if (process.env.NODE_ENV !== 'production') { throw new TypeError(message); } else { // eslint-disable-next-line no-console console.error(message); return; } } if (isUndefined$1(features[name])) { // eslint-disable-next-line no-console console.info(`Attempt to set a value on an unknown feature flag "${name}" resulted in a NOOP.`); return; } // This may seem redundant, but `process.env.NODE_ENV === 'test-lwc-integration'` is replaced by integration tests if (process.env.NODE_ENV === 'test-lwc-integration' || process.env.NODE_ENV !== 'production') { // Allow the same flag to be set more than once outside of production to enable testing flags[name] = value; } else { // Disallow the same flag to be set more than once in production const runtimeValue = flags[name]; if (!isUndefined$1(runtimeValue)) { // eslint-disable-next-line no-console console.error(`Failed to set the value "${value}" for the runtime feature flag "${name}". "${name}" has already been set with the value "${runtimeValue}".`); return; } defineProperty(flags, name, { value }); } } /** * Set the value at runtime of a given feature flag. This method should only be used for testing * purposes. It is a no-op when invoked in production mode. * @param name Name of the feature flag to enable or disable * @param value Whether the feature flag should be enabled * @example setFeatureFlag("DISABLE_NATIVE_CUSTOM_ELEMENT_LIFECYCLE", true) */ function setFeatureFlagForTest(name, value) { // This may seem redundant, but `process.env.NODE_ENV === 'test-lwc-integration'` is replaced by Karma tests if (process.env.NODE_ENV === 'test-lwc-integration' || process.env.NODE_ENV !== 'production') { setFeatureFlag(name, value); } } /** version: 9.2.0 */ /* * Copyright (c) 2020, salesforce.com, inc. * All rights reserved. * SPDX-License-Identifier: MIT * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT */ /** * The following constructor might be used in either the constructor or the connectedCallback. In * order to ensure that the component evaluates, we attach those mock constructors to the global * object. * Also note that Event is defined in Node 16+, but CustomEvent is not, so they have to be * polyfilled separately. */ if (typeof Event !== 'function') { class Event { } defineProperty(globalThis, 'Event', { value: Event, configurable: true, writable: true, }); } if (typeof CustomEvent !== 'function') { class CustomEvent extends Event { } defineProperty(globalThis, 'CustomEvent', { value: CustomEvent, configurable: true, writable: true, }); } /** * Copyright (c) 2026 Salesforce, Inc. */ /** * Copyright (c) 2026 Salesforce, Inc. */ /* * Copyright (c) 2018, salesforce.com, inc. * All rights reserved. * SPDX-License-Identifier: MIT * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT */ /** * * @param value * @param msg */ /** * * @param value * @param msg */ /** version: 9.2.0 */ /* * Copyright (c) 2023, salesforce.com, inc. * All rights reserved. * SPDX-License-Identifier: MIT * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT */ class SignalBaseClass { constructor() { this.subscribers = new Set(); } subscribe(onUpdate) { this.subscribers.add(onUpdate); return () => { this.subscribers.delete(onUpdate); }; } notify() { for (const subscriber of this.subscribers) { subscriber(); } } } /** version: 9.2.0 */ /** * Copyright (c) 2026 Salesforce, Inc. */ /** * Report to the current dispatcher, if there is one. * @param reportingEventId * @param payload data to report */ function report(reportingEventId, payload) { } /* * Copyright (c) 2018, salesforce.com, inc. * All rights reserved. * SPDX-License-Identifier: MIT * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT */ function getComponentTag(vm) { return `<${StringToLowerCase.call(vm.tagName)}>`; } // TODO [#1695]: Unify getComponentStack and getErrorComponentStack function getComponentStack(vm) { const stack = []; let prefix = ''; while (!isNull(vm.owner)) { ArrayPush$1.call(stack, prefix + getComponentTag(vm)); vm = vm.owner; prefix += '\t'; } return ArrayJoin.call(stack, '\n'); } function getErrorComponentStack(vm) { const wcStack = []; let currentVm = vm; while (!isNull(currentVm)) { ArrayPush$1.call(wcStack, getComponentTag(currentVm)); currentVm = currentVm.owner; } return wcStack.reverse().join('\n\t'); } /* * Copyright (c) 2018, salesforce.com, inc. * All rights reserved. * SPDX-License-Identifier: MIT * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT */ function addErrorComponentStack(vm, error) { if (!isFrozen(error) && isUndefined$1(error.wcStack)) { const wcStack = getErrorComponentStack(vm); defineProperty(error, 'wcStack', { get() { return wcStack; }, }); } } /* * Copyright (c) 2024, Salesforce, Inc. * All rights reserved. * SPDX-License-Identifier: MIT * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT */ const alreadyLoggedMessages = new Set(); // Only used in LWC's integration tests if (process.env.NODE_ENV === 'test-lwc-integration') { window.__lwcResetAlreadyLoggedMessages = () => { alreadyLoggedMessages.clear(); }; } function log(method, message, vm, once) { let msg = `[LWC ${method}]: ${message}`; if (!isUndefined$1(vm)) { msg = `${msg}\n${getComponentStack(vm)}`; } if (once) { if (alreadyLoggedMessages.has(msg)) { return; } alreadyLoggedMessages.add(msg); } // In Vitest tests, reduce the warning and error verbosity by not printing the callstack if (process.env.NODE_ENV === 'test') { /* eslint-disable-next-line no-console */ console[method](msg); return; } try { throw new Error(msg); } catch (e) { /* eslint-disable-next-line no-console */ console[method](e); } } function logError(message, vm) { log('error', message, vm, false); } function logWarn(message, vm) { log('warn', message, vm, false); } function logWarnOnce(message, vm) { log('warn', message, vm, true); } const SPACE_CHAR = 32; const EmptyObject = seal(create(null)); const EmptyArray = seal([]); function guid() { function s4() { return Math.floor((1 + Math.random()) * 0x10000) .toString(16) .substring(1); } return s4() + s4() + '-' + s4() + '-' + s4() + '-' + s4() + '-' + s4() + s4() + s4(); } // Throw an error if we're running in prod mode. Ensures code is truly removed from prod mode. function assertNotProd() { /* istanbul ignore if */ if (process.env.NODE_ENV === 'production') { // this method should never leak to prod throw new ReferenceError(); } } function shouldBeFormAssociated(Ctor) { const ctorFormAssociated = Boolean(Ctor.formAssociated); const apiVersion = getComponentAPIVersion(Ctor); const apiFeatureEnabled = isAPIFeatureEnabled(7 /* APIFeature.ENABLE_ELEMENT_INTERNALS_AND_FACE */, apiVersion); if (process.env.NODE_ENV !== 'production' && ctorFormAssociated && !apiFeatureEnabled) { const tagName = getComponentRegisteredName(Ctor); logWarnOnce(`Component <${tagName}> set static formAssociated to true, but form ` + `association is not enabled because the API version is ${apiVersion}. To enable form association, ` + `update the LWC component API version to 61 or above. https://lwc.dev/guide/versioning`); } return ctorFormAssociated && apiFeatureEnabled; } /* * Copyright (c) 2024, Salesforce, Inc. * All rights reserved. * SPDX-License-Identifier: MIT * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT */ // // Do additional mutation tracking for DevTools performance profiling, in dev mode only. // const reactiveObserversToVMs = new WeakMap(); const targetsToPropertyKeys = new WeakMap(); let mutationLogs = []; // Create a human-readable member access notation like `obj.foo` or `arr[1]`, // handling edge cases like `obj[Symbol("bar")]` and `obj["spaces here"]` function toPrettyMemberNotation(parent, child) { if (isUndefined$1(parent)) { // Bare prop, just stringify the child return toString(child); } else if (!isString(child)) { // Symbol/number, e.g. `obj[Symbol("foo")]` or `obj[1234]` return `${toString(parent)}[${toString(child)}]`; } else if (/^\w+$/.test(child)) { // Dot-notation-safe string, e.g. `obj.foo` return `${toString(parent)}.${child}`; } else { // Bracket-notation-requiring string, e.g. `obj["prop with spaces"]` return `${toString(parent)}[${JSON.stringify(child)}]`; } } function safelyCallGetter(target, key) { // Arbitrary getters can throw. We don't want to throw an error just due to dev-mode-only mutation tracking // (which is only used for performance debugging) so ignore errors here. try { return target[key]; } catch (_err) { /* ignore */ } } function isRevokedProxy(target) { try { // `str in obj` will never throw for normal objects or active proxies, // but the operation is not allowed for revoked proxies // eslint-disable-next-line @typescript-eslint/no-unused-expressions '' in target; return false; } catch (_) { return true; } } /** * Log a new mutation for this reactive observer. * @param reactiveObserver - relevant ReactiveObserver * @param target - target object that is being observed * @param key - key (property) that was mutated */ function logMutation(reactiveObserver, target, key) { assertNotProd(); const parentKey = targetsToPropertyKeys.get(target); const vm = reactiveObserversToVMs.get(reactiveObserver); /* istanbul ignore if */ if (isUndefined$1(vm)) { // VM should only be undefined in Vitest tests, where a reactive observer is not always associated with a VM // because the unit tests just create Reactive Observers on-the-fly. // Note we could explicitly target Vitest with `process.env.NODE_ENV === 'test'`, but then that would also // affect our downstream consumers' Jest/Vitest tests, and we don't want to throw an error just for a logger. if (process.env.NODE_ENV === 'test-lwc-integration') { throw new Error('The VM should always be defined except possibly in unit tests'); } } else { const prop = toPrettyMemberNotation(parentKey, key); ArrayPush$1.call(mutationLogs, { vm, prop }); } } /** * Flush logs associated with a given VM. * @param vm - given VM */ function flushMutationLogsForVM(vm) { assertNotProd(); mutationLogs = ArrayFilter.call(mutationLogs, (log) => log.vm !== vm); } /** * Mark this ReactiveObserver as related to this VM. This is only needed for mutation tracking in dev mode. * @param reactiveObserver * @param vm */ function associateReactiveObserverWithVM(reactiveObserver, vm) { assertNotProd(); reactiveObserversToVMs.set(reactiveObserver, vm); } /** * Deeply track all objects in a target and associate with a given key. * @param key - key associated with the object in the component * @param target - tracked target object */ function trackTargetForMutationLogging(key, target) { assertNotProd(); if (targetsToPropertyKeys.has(target)) { // Guard against recursive objects - don't traverse forever return; } // Revoked proxies (e.g. window props in LWS sandboxes) throw an error if we try to track them if (isObject(target) && !isNull(target) && !isRevokedProxy(target)) { // only track non-primitives; others are invalid as WeakMap keys targetsToPropertyKeys.set(target, key); // Deeply traverse arrays and objects to track every object within if (isArray$1(target)) { for (let i = 0; i < target.length; i++) { trackTargetForMutationLogging(toPrettyMemberNotation(key, i), safelyCallGetter(target, i)); } } else { // Track only own property names and symbols (including non-enumerated) // This is consistent with what observable-membrane does: // https://github.com/salesforce/observable-membrane/blob/b85417f/src/base-handler.ts#L142-L143 // Note this code path is very hot, hence doing two separate for-loops rather than creating a new array. for (const prop of getOwnPropertyNames$1(target)) { trackTargetForMutationLogging(toPrettyMemberNotation(key, prop), safelyCallGetter(target, prop)); } for (const prop of getOwnPropertySymbols$1(target)) { trackTargetForMutationLogging(toPrettyMemberNotation(key, prop), safelyCallGetter(target, prop)); } } } } /* * Copyright (c) 2024, Salesforce, Inc. * All rights reserved. * SPDX-License-Identifier: MIT * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT */ const TargetToReactiveRecordMap = new WeakMap(); function valueMutated(target, key) { const reactiveRecord = TargetToReactiveRecordMap.get(target); if (!isUndefined$1(reactiveRecord)) { const reactiveObservers = reactiveRecord[key]; if (!isUndefined$1(reactiveObservers)) { for (let i = 0, len = reactiveObservers.length; i < len; i += 1) { const ro = reactiveObservers[i]; if (process.env.NODE_ENV !== 'production') { logMutation(ro, target, key); } ro.notify(); } } } } function valueObserved(target, key) { // We should determine if an active Observing Record is present to track mutations. { return; } } /* * Copyright (c) 2024, salesforce.com, inc. * All rights reserved. * SPDX-License-Identifier: MIT * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT */ /** * This map keeps track of objects to signals. There is an assumption that the signal is strongly referenced * on the object which allows the SignalTracker to be garbage collected along with the object. */ const TargetToSignalTrackerMap = new WeakMap(); function getSignalTracker(target) { let signalTracker = TargetToSignalTrackerMap.get(target); if (isUndefined$1(signalTracker)) { signalTracker = new SignalTracker(); TargetToSignalTrackerMap.set(target, signalTracker); } return signalTracker; } function unsubscribeFromSignals(target) { if (TargetToSignalTrackerMap.has(target)) { const signalTracker = getSignalTracker(target); signalTracker.unsubscribeFromSignals(); signalTracker.reset(); } } /** * A normalized string representation of an error, because browsers behave differently */ const errorWithStack = (err) => { if (typeof err !== 'object' || err === null) { return String(err); } const stack = 'stack' in err ? String(err.stack) : ''; const message = 'message' in err ? String(err.message) : ''; const constructor = err.constructor.name; return stack.includes(message) ? stack : `${constructor}: ${message}\n${stack}`; }; /** * This class is used to keep track of the signals associated to a given object. * It is used to prevent the LWC engine from subscribing duplicate callbacks multiple times * to the same signal. Additionally, it keeps track of all signal unsubscribe callbacks, handles invoking * them when necessary and discarding them. */ class SignalTracker { constructor() { this.signalToUnsubscribeMap = new Map(); } seen(signal) { return this.signalToUnsubscribeMap.has(signal); } subscribeToSignal(signal, update) { try { const unsubscribe = signal.subscribe(update); if (isFunction$1(unsubscribe)) { // TODO [#3978]: Evaluate how we should handle the case when unsubscribe is not a function. // Long term we should throw an error or log a warning. this.signalToUnsubscribeMap.set(signal, unsubscribe); } } catch (err) { logWarnOnce(`Attempted to subscribe to an object that has the shape of a signal but received the following error: ${errorWithStack(err)}`); } } unsubscribeFromSignals() { try { this.signalToUnsubscribeMap.forEach((unsubscribe) => unsubscribe()); } catch (err) { logWarnOnce(`Attempted to call a signal's unsubscribe callback but received the following error: ${errorWithStack(err)}`); } } reset() { this.signalToUnsubscribeMap.clear(); } } /* * Copyright (c) 2024, Salesforce, Inc. * All rights reserved. * SPDX-License-Identifier: MIT * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT */ const DUMMY_REACTIVE_OBSERVER = { observe(job) { job(); }, reset() { }, link() { }, }; function componentValueObserved(vm, key, target = {}) { const { component, tro } = vm; // The portion of reactivity that's exposed to signals is to subscribe a callback to re-render the VM (templates). // We check the following to ensure re-render is subscribed at the correct time. // 1. The template is currently being rendered (there is a template reactive observer) // 2. There was a call to a getter to access the signal (happens during vnode generation) if (lwcRuntimeFlags.ENABLE_EXPERIMENTAL_SIGNALS && isObject(target) && !isNull(target) && false) ; } function createReactiveObserver(callback) { // On the server side, we don't need mutation tracking. Skipping it improves performance. return DUMMY_REACTIVE_OBSERVER; } /* * Copyright (c) 2020, salesforce.com, inc. * All rights reserved. * SPDX-License-Identifier: MIT * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT */ function resolveCircularModuleDependency(fn) { const module = fn(); return module?.__esModule ? module.default : module; } function isCircularModuleDependency(obj) { return isFunction$1(obj) && hasOwnProperty$1.call(obj, '__circular__'); } /* * Copyright (c) 2023, salesforce.com, inc. * All rights reserved. * SPDX-License-Identifier: MIT * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT */ const instrumentDef = globalThis.__lwc_instrument_cmp_def ?? noop; const instrumentInstance = globalThis.__lwc_instrument_cmp_instance ?? noop; /* * Copyright (c) 2018, salesforce.com, inc. * All rights reserved. * SPDX-License-Identifier: MIT * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT */ // This is a temporary workaround to get the @lwc/engine-server to evaluate in node without having // to inject at runtime. const HTMLElementConstructor = typeof HTMLElement !== 'undefined' ? HTMLElement : function () { }; const HTMLElementPrototype = HTMLElementConstructor.prototype; /* * Copyright (c) 2023, salesforce.com, inc. * All rights reserved. * SPDX-License-Identifier: MIT * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT */ // Apply ARIA string reflection behavior to a prototype. // This is deliberately kept separate from @lwc/aria-reflection. @lwc/aria-reflection is a global polyfill that is // needed for backwards compatibility in LEX, whereas this is designed to only apply to our own // LightningElement/BaseBridgeElement prototypes. // Note we only need to handle ARIA reflections th