Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function setFeatureFlag(name: string, value: FeatureFlagValue) {
const isBoolean = isTrue(value) || isFalse(value);
if (!isBoolean) {
const message = `Invalid ${typeof value} value specified for the "${name}" flag. Runtime feature flags can only be set to a boolean value.`;
if (process.env.NODE_ENV === 'production') {
// eslint-disable-next-line no-console
console.error(message);
} else {
throw new TypeError(message);
}
}
if (!isUndefined(features[name])) {
runtimeFlags[name] = value;
} else {
// eslint-disable-next-line no-console
console.warn(
`LWC feature flag "${name}" is undefined. Possible reasons are that 1) it was misspelled or 2) it was removed from the @lwc/features package.`
);
function isQualifyingEventTarget(currentTarget: Window, evt: Event): boolean {
const originalTarget = eventTargetGetter.call(evt);
if (originalTarget === currentTarget) {
// dispatched on the window directly
return true;
}
const { composed } = evt;
// if the event reaches the window by propagation, it is because it is bubbling,
// in which the the only it really depends on the composed value
return isTrue(composed) || !isNodeShadowed(originalTarget as Node);
}
export function createViewModelHook(vnode: VCustomElement) {
const elm = vnode.elm as HTMLElement;
if (!isUndefined(getAssociatedVMIfPresent(elm))) {
// There is a possibility that a custom element is registered under tagName,
// in which case, the initialization is already carry on, and there is nothing else
// to do here since this hook is called right after invoking `document.createElement`.
return;
}
const { mode, ctor, owner } = vnode;
const def = getComponentDef(ctor);
setElementProto(elm, def);
if (isTrue(useSyntheticShadow)) {
const { shadowAttribute } = owner.context;
// when running in synthetic shadow mode, we need to set the shadowToken value
// into each element from the template, so they can be styled accordingly.
setElementShadowToken(elm, shadowAttribute);
}
createVM(elm, ctor, {
mode,
owner,
});
if (process.env.NODE_ENV !== 'production') {
assert.isTrue(
isArray(vnode.children),
`Invalid vnode for a custom element, it must have children defined.`
);
}
if (process.env.NODE_ENV !== 'production') {
export function fallbackElmHook(vnode: VElement) {
const { owner } = vnode;
const elm = vnode.elm as HTMLElement;
if (isTrue(useSyntheticShadow)) {
const {
data: { context },
} = vnode;
const { shadowAttribute } = owner.context;
if (
!isUndefined(context) &&
!isUndefined(context.lwc) &&
context.lwc.dom === LWCDOMMode.manual
) {
// this element will now accept any manual content inserted into it
observeElementChildNodes(elm);
}
// when running in synthetic shadow mode, we need to set the shadowToken value
// into each element from the template, so they can be styled accordingly.
setElementShadowToken(elm, shadowAttribute);
}
export function isRegisteredNode(node: Node): boolean {
return isTrue(getHiddenField(node, RegisteredFlag));
}
function rehydrate(vm: VM) {
if (process.env.NODE_ENV !== 'production') {
assert.isTrue(
vm.elm instanceof HTMLElement,
`rehydration can only happen after ${vm} was patched the first time.`
);
}
if (isTrue(vm.isDirty)) {
const children = renderComponent(vm);
patchShadowRoot(vm, children);
}
}
set(this: Element, v: boolean) {
this[DomManualPrivateKey] = v;
if (isTrue(v)) {
markElementAsPortal(this);
}
},
get() {
value(this: SyntheticShadowRootInterface, options?: GetRootNodeOptions): Node {
return !isUndefined(options) && isTrue(options.composed)
? getHost(this).getRootNode(options)
: this;
},
},