UNPKG

@lwc/engine-server

Version:

Renders LWC components in a server environment.

1,329 lines (1,300 loc) 652 kB
/** * Copyright (c) 2024 Salesforce, Inc. */ 'use strict'; Object.defineProperty(exports, '__esModule', { value: true }); /** * Copyright (c) 2024 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.getOwnPropertyDescriptors}; see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/getOwnPropertyDescriptors MDN Reference}. */ getOwnPropertyDescriptors, /** 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.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; /** Detached {@linkcode Array.isArray}; see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/isArray MDN Reference}. */ const { isArray: isArray$1 } = 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 { concat: ArrayConcat$1, copyWithin: ArrayCopyWithin, every: ArrayEvery, fill: ArrayFill, filter: ArrayFilter, find: ArrayFind, findIndex: ArrayFindIndex, includes: ArrayIncludes, indexOf: ArrayIndexOf, join: ArrayJoin, map: ArrayMap, pop: ArrayPop, push: ArrayPush$1, reduce: ArrayReduce, 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, split: StringSplit, slice: StringSlice, toLowerCase: StringToLowerCase, } = 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/ban-types 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$1(obj) { return typeof obj === 'number'; } /** Does nothing! 🚀 */ function noop() { /* Do nothing */ } const OtS$1 = {}.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$1(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$1), ','); } return obj.toString(); } else if (typeof obj === 'object') { // This catches null and returns "[object Null]". Weird, but kept for backwards compatibility. return OtS$1.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 LOWEST_API_VERSION = 58 /* APIVersion.V58_244_SUMMER_23 */; /** * * @param apiVersionFeature * @param apiVersion */ function isAPIFeatureEnabled(apiVersionFeature, apiVersion) { switch (apiVersionFeature) { case 0 /* APIFeature.LOWERCASE_SCOPE_TOKENS */: case 1 /* APIFeature.TREAT_ALL_PARSE5_ERRORS_AS_ERRORS */: return apiVersion >= 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 apiVersion >= 60 /* APIVersion.V60_248_SPRING_24 */; case 8 /* APIFeature.ENABLE_ELEMENT_INTERNALS_AND_FACE */: case 7 /* APIFeature.ENABLE_NATIVE_CUSTOM_ELEMENT_LIFECYCLE */: case 6 /* APIFeature.USE_LIGHT_DOM_SLOT_FORWARDING */: return apiVersion >= 61 /* APIVersion.V61_250_SUMMER_24 */; } } /* * 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-')); AriaAttrNameToPropNameMap[attrName] = propName; AriaPropNameToAttrNameMap[propName] = attrName; }); return { AriaAttrNameToPropNameMap, AriaPropNameToAttrNameMap }; })(); /** * * @param attrName */ function isAriaAttribute(attrName) { return attrName in AriaAttrNameToPropNameMap; } /* * 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_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))); } // This list is based on https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes const GLOBAL_ATTRIBUTE = /*@__PURE__*/ new Set([ 'accesskey', 'autocapitalize', 'autofocus', 'class', 'contenteditable', 'contextmenu', 'dir', 'draggable', 'enterkeyhint', 'exportparts', 'hidden', 'id', 'inputmode', 'is', 'itemid', 'itemprop', 'itemref', 'itemscope', 'itemtype', 'lang', 'nonce', 'part', 'slot', 'spellcheck', 'style', 'tabindex', 'title', 'translate', ]); /** * * @param attrName */ function isGlobalHtmlAttribute(attrName) { return GLOBAL_ATTRIBUTE.has(attrName); } // 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'], ]); /** * 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 = "6.5.1"; const LWC_VERSION_COMMENT_REGEX = /\/\*LWC compiler v([\d.]+)\*\/\s*}/; /** version: 6.5.1 */ /** * Copyright (c) 2024 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, }; 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-karma-lwc'` is replaced by Karma tests if (process.env.NODE_ENV === 'test-karma-lwc' || 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-karma-lwc'` is replaced by Karma tests if (process.env.NODE_ENV === 'test-karma-lwc' || process.env.NODE_ENV !== 'production') { setFeatureFlag(name, value); } } /** version: 6.5.1 */ /* * 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) 2024 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 */ 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 Karma tests if (process.env.NODE_ENV === 'test-karma-lwc') { 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 Jest 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); } /* * Copyright (c) 2019, 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 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]; 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 subscribeToSignal(target, signal, update) { const signalTracker = getSignalTracker(target); if (isFalse(signalTracker.seen(signal))) { signalTracker.subscribeToSignal(signal, update); } } function unsubscribeFromSignals(target) { if (TargetToSignalTrackerMap.has(target)) { const signalTracker = getSignalTracker(target); signalTracker.unsubscribeFromSignals(); signalTracker.reset(); } } /** * 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: ${err?.stack ?? err}`); } } unsubscribeFromSignals() { try { this.signalToUnsubscribeMap.forEach((unsubscribe) => unsubscribe()); } catch (err) { logWarnOnce(`Attempted to call a signal's unsubscribe callback but received the following error: ${err?.stack ?? err}`); } } reset() { this.signalToUnsubscribeMap.clear(); } } /* * 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 */ 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 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) && 'value' in target && 'subscribe' in target && isFunction$1(target.subscribe) && // Only subscribe if a template is being rendered by the engine tro.isObserving()) { // Subscribe the template reactive observer's notify method, which will mark the vm as dirty and schedule hydration. subscribeToSignal(component, target, tro.notify.bind(tro)); } } function createReactiveObserver(callback) { // On the server side, we don't need mutation tracking. Skipping it improves performance. return DUMMY_REACTIVE_OBSERVER; } 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(); } function shouldUseNativeCustomElementLifecycle(ctor) { if (lwcRuntimeFlags.DISABLE_NATIVE_CUSTOM_ELEMENT_LIFECYCLE) { // temporary "kill switch" return false; } const apiVersion = getComponentAPIVersion(ctor); return isAPIFeatureEnabled(7 /* APIFeature.ENABLE_NATIVE_CUSTOM_ELEMENT_LIFECYCLE */, apiVersion); } function flattenStylesheets(stylesheets) { const list = []; for (const stylesheet of stylesheets) { if (!isArray$1(stylesheet)) { list.push(stylesheet); } else { list.push(...flattenStylesheets(stylesheet)); } } return list; } // 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(8 /* 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) 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 that aren't already in Element.prototype const ariaReflectionPolyfillDescriptors = create(null); for (const [propName, attrName] of entries(AriaPropNameToAttrNameMap)) { if (isUndefined$1(getPropertyDescriptor(HTMLElementPrototype, propName))) { // Note that we need to call this.{get,set,has,remove}Attribute rather than dereferencing // from Element.prototype, because these methods are overridden in LightningElement. ariaReflectionPolyfillDescriptors[propName] = { get() { return this.getAttribute(attrName); }, set(newValue) { // TODO [#3284]: there is disagreement between browsers and the spec on how to treat undefined // Our historical behavior is to only treat null as removing the attribute // See also https://github.com/w3c/aria/issues/1858 if (isNull(newValue)) { this.removeAttribute(attrName); } else { this.setAttribute(attrName, newValue); } }, // configurable and enumerable to allow it to be overridden – this mimics Safari's/Chrome's behavior configurable: true, enumerable: true, }; } } /* * 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 */ // These properties get added to LWCElement.prototype publicProps automatically const defaultDefHTMLPropertyNames = [ 'accessKey', 'dir', 'draggable', 'hidden', 'id', 'lang', 'spellcheck', 'tabIndex', 'title', ]; /* * 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 descriptor map that contains * all standard properties that a Custom Element can support (including AOM properties), which * determines what kind of capabilities the Base HTML Element and * Base Lightning Element should support. */ const HTMLElementOriginalDescriptors = create(null); forEach.call(keys(AriaPropNameToAttrNameMap), (propName) => { // Note: intentionally using our in-house getPropertyDescriptor instead of getOwnPropertyDescriptor here because // in IE11, some properties are on Element.prototype instead of HTMLElement, just to be sure. const descriptor = getPropertyDescriptor(HTMLElementPrototype, propName); if (!isUndefined$1(descriptor)) { HTMLElementOriginalDescriptors[propName] = descriptor; } }); forEach.call(defaultDefHTMLPropertyNames, (propName) => { // Note: intentionally using our in-house getPropertyDescriptor instead of getOwnPropertyDescriptor here because // in IE11, id property is on Element.prototype instead of HTMLElement, and we suspect that more will fall into // this category, so, better to be sure. const descriptor = getPropertyDescriptor(HTMLElementPrototype, propName); if (!isUndefined$1(descriptor)) { HTMLElementOriginalDescriptors[propName] = descriptor; } }); /* * 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 generateDataDescriptor(options) { return assign({ configurable: true, enumerable: true, writable: true, }, options); } function generateAccessorDescriptor(options) { return assign({ configurable: true, enumerable: true, }, options); } let isDomMutationAllowed = false; function unlockDomMutation() { assertNotProd(); // this method should never leak to prod isDomMutationAllowed = true; } function lockDomMutation() { assertNotProd(); // this method should never leak to prod isDomMutationAllowed = false; } function logMissingPortalWarn(name, type) { return logWarn(`The \`${name}\` ${type} is available only on elements that use the \`lwc:dom="manual"\` directive.`); } function patchElementWithRestrictions(elm, options) { assertNotProd(); // this method should never leak to prod const originalOuterHTMLDescriptor = getPropertyDescriptor(elm, 'outerHTML'); const descriptors = { outerHTML: generateAccessorDescriptor({ get() { return originalOuterHTMLDescriptor.get.call(this); }, set(value) { logError(`Invalid attempt to set outerHTML on Element.`); return originalOuterHTMLDescriptor.set.call(this, value); }, }), }; // Apply extra restriction related to DOM manipulation if the element is not a portal. if (!options.isLight && options.isSynthetic && !options.isPortal) { const { appendChild, insertBefore, removeChild, replaceChild } = elm; const originalNodeValueDescriptor = getPropertyDescriptor(elm, 'nodeValue'); const originalInnerHTMLDescriptor = getPropertyDescriptor(elm, 'innerHTML'); const originalTextContentDescriptor = getPropertyDescriptor(elm, 'textContent'); assign(descriptors, { appendChild: generateDataDescriptor({ value(aChild) { logMissingPortalWarn('appendChild', 'method'); return appendChild.call(this, aChild); }, }), insertBefore: generateDataDescriptor({ value(newNode, referenceNode) { if (!isDomMutationAllowed) { logMissingPortalWarn('insertBefore', 'method'); } return insertBefore.call(this, newNode, referenceNode); }, }), removeChild: generateDataDescriptor({ value(aChild) { if (!isDomMutationAllowed) { logMissingPortalWarn('removeChild', 'method'); } return removeChild.call(this, aChild); }, }), replaceChild: generateDataDescriptor({ value(newChild, oldChild) { logMissingPortalWarn('replaceChild', 'method'); return replaceChild.call(this, newChild, oldChild); }, }), nodeValue: generateAccessorDescriptor({ get() { return originalNodeValueDescriptor.get.call(this); }, set(value) { if (!isDomMutationAllowed) { logMissingPortalWarn('nodeValue', 'property'); } originalNodeValueDescriptor.set.call(this, value); }, }), textContent: generateAccessorDescriptor({ get() { return originalTextContentDescriptor.get.call(this); }, set(value) { logMissingPortalWarn('textContent', 'property'); originalTextContentDescriptor.set.call(this, value); }, }), innerHTML: generateAccessorDescriptor({ get() { return originalInnerHTMLDescriptor.get.call(this); }, set(value) { logMissingPortalWarn('innerHTML', 'property'); return originalInnerHTMLDescriptor.set.call(this, value); }, }), }); } defineProperties(elm, descriptors); } function getShadowRootRestrictionsDescriptors(sr) { assertNotProd(); // this method should never leak to prod // Disallowing properties in dev mode only to avoid people doing the wrong // thing when using the real shadow root, because if that's the case, // the component will not work when running with synthetic shadow. const originalAddEventListener = sr.addEventListener; const originalInnerHTMLDescriptor = getPropertyDescriptor(sr, 'innerHTML'); const originalTextContentDescriptor = getPropertyDescriptor(sr, 'textContent'); return { innerHTML: generateAccessorDescriptor({ get() { return originalInnerHTMLDescriptor.get.call(this); }, set(value) { logError(`Invalid attempt to set innerHTML on ShadowRoot.`); return originalInnerHTMLDescriptor.set.call(this, value); }, }), textContent: generateAccessorDescriptor({ get() { return originalTextContentDescriptor.get.call(this); }, set(value) { logError(`Invalid attempt to set textContent on ShadowRoot.`); return originalTextContentDescriptor.set.call(this, value); }, }), addEventListener: generateDataDescriptor({ value(type, listener, options) { // TODO [#1824]: Potentially relax this restriction if (!isUndefined$1(options)) { logError('The `addEventListener` method on ShadowRoot does not support any options.', getAssociatedVMIfPresent(this)); } // Typescript does not like it when you treat the `arguments` object as an array // @ts-expect-error type-mismatch return originalAddEventListener.apply(this, arguments); }, }), }; } // Custom Elements Restrictions: // ----------------------------- function getCustomElementRestrictionsDescriptors(elm) { assertNotProd(); // this method should never leak to prod const originalAddEventListener = elm.addEventListener; const originalInnerHTMLDescriptor = getPropertyDescriptor(elm, 'innerHTML'); const originalOuterHTMLDescriptor = getPropertyDescriptor(elm, 'outerHTML'); const originalTextContentDescriptor = getPropertyDescriptor(elm, 'textContent'); return { innerHTML: generateAccessorDescriptor({ get() { return originalInnerHTMLDescriptor.get.call(this); }, set(value) { logError(`Invalid attempt to set innerHTML on HTMLElement.`); return originalInnerHTMLDescriptor.set.call(this, value); }, }), outerHTML: generateAccessorDescriptor({ get() { return originalOuterHTMLDescriptor.get.call(this); }, set(value) { logError(`Invalid attempt to set outerHTML on HTMLElement.`); return originalOuterHTMLDescriptor.set.call(this, value); }, }), textContent: generateAccessorDescriptor({ get() { return originalTextContentDescriptor.get.call(this); }, set(value) { logError(`Invalid attempt to set textContent on HTMLElement.`); return o