How to use the @lwc/shared.hasOwnProperty.call function in @lwc/shared

To help you get started, we’ve selected a few @lwc/shared examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github salesforce / lwc / packages / @lwc / synthetic-shadow / src / env / node.ts View on Github external
'ownerDocument'
)!.get!;

const parentElementGetter: (this: Node) => Element | null = hasOwnProperty.call(
    Node.prototype,
    'parentElement'
)
    ? getOwnPropertyDescriptor(Node.prototype, 'parentElement')!.get!
    : getOwnPropertyDescriptor(HTMLElement.prototype, 'parentElement')!.get!; // IE11

const textContextSetter: (this: Node, s: string) => void = getOwnPropertyDescriptor(
    Node.prototype,
    'textContent'
)!.set!;

const childNodesGetter: (this: Node) => NodeListOf = hasOwnProperty.call(
    Node.prototype,
    'childNodes'
)
    ? getOwnPropertyDescriptor(Node.prototype, 'childNodes')!.get!
    : getOwnPropertyDescriptor(HTMLElement.prototype, 'childNodes')!.get!; // IE11

const isConnected = hasOwnProperty.call(Node.prototype, 'isConnected')
    ? getOwnPropertyDescriptor(Node.prototype, 'isConnected')!.get!
    : function(this: Node): boolean {
          const doc = ownerDocumentGetter.call(this);
          // IE11
          return (
              // if doc is null, it means `this` is actually a document instance which
              // is always connected
              doc === null ||
              (compareDocumentPosition.call(doc, this) & DOCUMENT_POSITION_CONTAINED_BY) !== 0
github salesforce / lwc / packages / @lwc / synthetic-shadow / src / env / document.ts View on Github external
/*
 * 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
 */
import { getOwnPropertyDescriptor, hasOwnProperty } from '@lwc/shared';

const DocumentPrototypeActiveElement: (this: Document) => Element | null = getOwnPropertyDescriptor(
    Document.prototype,
    'activeElement'
)!.get!;

const elementFromPoint: (x: number, y: number) => Element | null = hasOwnProperty.call(
    Document.prototype,
    'elementFromPoint'
)
    ? Document.prototype.elementFromPoint
    : (Document.prototype as any).msElementFromPoint; // IE11

// defaultView can be null when a document has no browsing context. For example, the owner document
// of a node in a template doesn't have a default view: https://jsfiddle.net/hv9z0q5a/
const defaultViewGetter: (this: Document) => Window | null = getOwnPropertyDescriptor(
    Document.prototype,
    'defaultView'
)!.get!;

const {
    createComment,
    querySelectorAll,
github salesforce / lwc / packages / @lwc / errors / src / __tests__ / errors.spec.ts View on Github external
Object.keys(object).forEach(key => {
        const property = object[key];
        if (property && hasOwnProperty.call(property, 'code')) {
            fn(property as LWCErrorInfo, `${path}.${key}`);
        } else if (property) {
            traverseErrorInfo(property, fn, `${path}.${key}`);
        }
    });
}
github salesforce / lwc / packages / @lwc / compiler / src / rollup-plugins / module-resolver.ts View on Github external
function fileExists(fileName: string, { files }: NormalizedCompileOptions): boolean {
    return hasOwnProperty.call(files, fileName);
}
github salesforce / lwc / packages / @lwc / compiler / src / rollup-plugins / module-resolver.ts View on Github external
function fileExists(fileName: string, { files }: NormalizedCompilerOptions): boolean {
    return hasOwnProperty.call(files, fileName);
}
github salesforce / lwc / packages / @lwc / compiler / src / rollup-plugins / module-resolver.ts View on Github external
        const ext = VALID_EXTENSIONS.find(ext => hasOwnProperty.call(files, fileName + ext)) || '';
        return fileName + ext;
github salesforce / lwc / packages / @lwc / template-compiler / src / parser / index.ts View on Github external
ParserDiagnostics.LWC_DOM_INVALID_CUSTOM_ELEMENT,
                element.__original,
                [`<${element.tag}>`]
            );
        }

        if (element.tag === 'slot') {
            return warnOnElement(
                ParserDiagnostics.LWC_DOM_INVALID_SLOT_ELEMENT,
                element.__original
            );
        }

        if (
            lwcDomAttribute.type !== IRAttributeType.String ||
            hasOwnProperty.call(LWCDirectiveDomMode, lwcDomAttribute.value) === false
        ) {
            const possibleValues = Object.keys(LWCDirectiveDomMode)
                .map(value => `"${value}"`)
                .join(', or ');
            return warnOnElement(ParserDiagnostics.LWC_DOM_INVALID_VALUE, element.__original, [
                possibleValues,
            ]);
        }

        if (element.children.length > 0) {
            return warnOnElement(ParserDiagnostics.LWC_DOM_INVALID_CONTENTS, element.__original);
        }

        lwcOpts.dom = lwcDomAttribute.value as LWCDirectiveDomMode;
    }