Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function invokeListenersByPlacement(placement: EventListenerContext) {
forEach.call(bookkeeping, (listener: WrappedListener) => {
if (isFalse(immediatePropagationStopped) && listener.placement === placement) {
// making sure that the listener was not removed from the original listener queue
if (ArrayIndexOf.call(listeners, listener) !== -1) {
// all handlers on the custom element should be called with undefined 'this'
listener.call(undefined, evt);
}
}
});
}
forEach.call(ElementPrototypeAriaPropertyNames, (propName: string) => {
// Typescript is inferring the wrong function type for this particular
// overloaded method: https://github.com/Microsoft/TypeScript/issues/27972
// @ts-ignore type-mismatch
const attrName = StringToLowerCase.call(StringReplace.call(propName, /^aria/, 'aria-'));
AttrNameToPropNameMap[attrName] = propName;
PropNameToAttrNameMap[propName] = attrName;
});
forEach.call(defaultDefHTMLPropertyNames, propName => {
const attrName = StringToLowerCase.call(propName);
AttrNameToPropNameMap[attrName] = propName;
PropNameToAttrNameMap[propName] = attrName;
});
forEach.call(HTMLPropertyNamesWithLowercasedReflectiveAttributes, propName => {
const attrName = StringToLowerCase.call(propName);
AttrNameToPropNameMap[attrName] = propName;
PropNameToAttrNameMap[propName] = attrName;
});
const CAMEL_REGEX = /-([a-z])/g;
/**
* This method maps between attribute names
* and the corresponding property name.
*/
export function getPropNameFromAttrName(attrName: string): string {
if (isUndefined(AttrNameToPropNameMap[attrName])) {
AttrNameToPropNameMap[attrName] = StringReplace.call(
attrName,
CAMEL_REGEX,
return new MutationObserver(mutations => {
forEach.call(mutations, mutation => {
/**
* This routine will process all nodes added or removed from elm (which is marked as a portal)
* When adding a node to the portal element, we should add the ownership.
* When removing a node from the portal element, this ownership should be removed.
*
* There is some special cases in which MutationObserver may call with stacked mutations (the same node
* will be in addedNodes and removedNodes) or with false positives (a node that is removed and re-appended
* in the same tick) for those cases, we cover by checking that the node is contained
* (or not in the case of removal) by the element.
*/
const { target: elm, addedNodes, removedNodes } = mutation;
// the target of the mutation should always have a ShadowRootResolver attached to it
const fn = getShadowRootResolver(elm) as ShadowRootResolver;
const shadowToken = getShadowToken(elm);
// Process removals first to handle the case where an element is removed and reinserted
* 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.
*/
export const HTMLElementOriginalDescriptors: PropertyDescriptorMap = create(null);
forEach.call(ElementPrototypeAriaPropertyNames, (propName: string) => {
// 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(HTMLElement.prototype, propName);
if (!isUndefined(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(HTMLElement.prototype, propName);
if (!isUndefined(descriptor)) {
HTMLElementOriginalDescriptors[propName] = descriptor;
}
});
* SPDX-License-Identifier: MIT
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
*/
import { create, forEach, getPropertyDescriptor, isUndefined } from '@lwc/shared';
import { defaultDefHTMLPropertyNames } from './attributes';
import { ElementPrototypeAriaPropertyNames } from '../polyfills/aria-properties/main';
/**
* 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.
*/
export const HTMLElementOriginalDescriptors: PropertyDescriptorMap = create(null);
forEach.call(ElementPrototypeAriaPropertyNames, (propName: string) => {
// 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(HTMLElement.prototype, propName);
if (!isUndefined(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(HTMLElement.prototype, propName);
if (!isUndefined(descriptor)) {
HTMLElementOriginalDescriptors[propName] = descriptor;
}
});
while (last === false) {
// implementing a look-back-approach because we need to know if the element is the last
next = iterator.next();
last = next.done;
// template factory logic based on the previous collected value
const vnode = factory(value, j, j === 0, last);
if (isArray(vnode)) {
ArrayPush.apply(list, vnode);
} else {
ArrayPush.call(list, vnode);
}
if (process.env.NODE_ENV !== 'production') {
const vnodes = isArray(vnode) ? vnode : [vnode];
forEach.call(vnodes, (childVnode: VNode | null) => {
if (!isNull(childVnode) && isObject(childVnode) && !isUndefined(childVnode.sel)) {
const { key } = childVnode;
if (isString(key) || isNumber(key)) {
if (keyMap[key] === 1 && isUndefined(iterationError)) {
iterationError = `Duplicated "key" attribute value for "<${childVnode.sel}>" in ${vmBeingRendered} for item number ${j}. A key with value "${childVnode.key}" appears more than once in the iteration. Key values must be unique numbers or strings.`;
}
keyMap[key] = 1;
} else if (isUndefined(iterationError)) {
iterationError = `Invalid "key" attribute value in "<${childVnode.sel}>" in ${vmBeingRendered} for item number ${j}. Set a unique "key" value on all iterated child elements.`;
}
}
});
}
// preparing next value
j += 1;
export function createStaticHTMLCollection(items: T[]): HTMLCollectionOf {
const collection: HTMLCollectionOf = create(StaticHTMLCollection.prototype);
setHiddenField(collection, Items, items);
// setting static indexes
forEach.call(items, (item: T, index: number) => {
defineProperty(collection, index, {
value: item,
enumerable: true,
configurable: true,
});
});
return collection;
}
function validateFields(vm: VM, html: Template) {
if (process.env.NODE_ENV === 'production') {
// this method should never leak to prod
throw new ReferenceError();
}
const { component } = vm;
// validating identifiers used by template that should be provided by the component
const { ids = [] } = html;
forEach.call(ids, (propName: string) => {
if (!(propName in component)) {
// eslint-disable-next-line lwc-internal/no-production-assert
logError(
`The template rendered by ${vm} references \`this.${propName}\`, which is not declared. Check for a typo in the template.`,
vm
);
}
});
}
function collectStylesheets(stylesheets, hostSelector, shadowSelector, isNative, aggregatorFn) {
forEach.call(stylesheets, sheet => {
if (isArray(sheet)) {
collectStylesheets(sheet, hostSelector, shadowSelector, isNative, aggregatorFn);
} else {
aggregatorFn(sheet(hostSelector, shadowSelector, isNative));
}
});
}