How to use the @lwc/shared.assert.isTrue 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 / engine / src / framework / template.ts View on Github external
stylesheets,
                            hostAttribute,
                            shadowAttribute
                        );
                    }

                    if (process.env.NODE_ENV !== 'production') {
                        // one time operation for any new template returned by render()
                        // so we can warn if the template is attempting to use a binding
                        // that is not provided by the component instance.
                        validateFields(vm, html);
                    }
                }

                if (process.env.NODE_ENV !== 'production') {
                    assert.isTrue(
                        isObject(context.tplCache),
                        `vm.context.tplCache must be an object associated to ${cmpTemplate}.`
                    );
                    // validating slots in every rendering since the allocated content might change over time
                    validateSlots(vm, html);
                }
                // right before producing the vnodes, we clear up all internal references
                // to custom elements from the template.
                vm.velements = [];
                // Set the global flag that template is being updated
                isUpdatingTemplate = true;

                vnodes = html.call(undefined, api, component, cmpSlots, context.tplCache!);
                const { styleVNode } = context;
                if (!isNull(styleVNode)) {
                    ArrayUnshift.call(vnodes, styleVNode);
github salesforce / lwc / packages / @lwc / engine / src / framework / def.ts View on Github external
function createComponentDef(
    Ctor: ComponentConstructor,
    meta: ComponentMeta,
    subclassComponentName: string
): ComponentDef {
    if (process.env.NODE_ENV !== 'production') {
        // local to dev block
        const ctorName = Ctor.name;
        // Removing the following assert until https://bugs.webkit.org/show_bug.cgi?id=190140 is fixed.
        // assert.isTrue(ctorName && isString(ctorName), `${toString(Ctor)} should have a "name" property with string value, but found ${ctorName}.`);
        assert.isTrue(
            Ctor.constructor,
            `Missing ${ctorName}.constructor, ${ctorName} should have a "constructor" property.`
        );
    }

    const { name } = meta;
    let { template } = meta;
    const decoratorsMeta = getDecoratorsRegisteredMeta(Ctor);
    let props: PropsDef = {};
    let methods: MethodDef = {};
    let wire: WireHash | undefined;
    let track: TrackDef = {};
    let fields: string[] | undefined;
    if (!isUndefined(decoratorsMeta)) {
        props = decoratorsMeta.props;
        methods = decoratorsMeta.methods;
github salesforce / lwc / packages / @lwc / engine / src / framework / upgrade.ts View on Github external
function callNodeSlot(node: Node, slot: symbol): Node {
    if (process.env.NODE_ENV !== 'production') {
        assert.isTrue(node, `callNodeSlot() should not be called for a non-object`);
    }

    const fn = getHiddenField(node, slot) as Function | undefined;

    if (!isUndefined(fn)) {
        fn();
    }
    return node; // for convenience
}
github salesforce / lwc / packages / @lwc / wire-service / src / index.ts View on Github external
segments.forEach(segment => {
                            assert.isTrue(
                                segment.length > 0,
                                `@wire on "${wireTarget}": reactive parameters must not be empty`
                            );
                        });
                        assert.isTrue(
                            segments[0] !== wireTarget,
                            `@wire on "${wireTarget}": reactive parameter "${segments[0]}" must not refer to self`
                        );
                        // restriction for dot-notation reactive parameters
                        if (segments.length > 1) {
                            // @wire emits a stream of immutable values. an emit sets the target property; it does not mutate a previously emitted value.
                            // restricting dot-notation reactive parameters to reference other @wire targets makes trapping the 'head' of the parameter
                            // sufficient to observe the value change.
                            assert.isTrue(
                                wireTargets.includes(segments[0]) &&
                                    wireStaticDef[segments[0]].method !== 1,
                                `@wire on "${wireTarget}": dot-notation reactive parameter "${prop}" must refer to a @wire property`
                            );
                        }
                    });
                }
github salesforce / lwc / packages / @lwc / engine / src / framework / api.ts View on Github external
export function c(
    sel: string,
    Ctor: ComponentConstructor,
    data: CustomElementCompilerData,
    children?: VNodes
): VCustomElement {
    if (isCircularModuleDependency(Ctor)) {
        Ctor = resolveCircularModuleDependency(Ctor);
    }
    const vmBeingRendered = getVMBeingRendered();
    if (process.env.NODE_ENV !== 'production') {
        assert.isTrue(isString(sel), `c() 1st argument sel must be a string.`);
        assert.isTrue(isFunction(Ctor), `c() 2nd argument Ctor must be a function.`);
        assert.isTrue(isObject(data), `c() 3nd argument data must be an object.`);
        assert.isTrue(
            arguments.length === 3 || isArray(children),
            `c() 4nd argument data must be an array.`
        );
        // checking reserved internal data properties
        assert.isFalse(
            data.className && data.classMap,
            `vnode.data.className and vnode.data.classMap ambiguous declaration.`
        );
        assert.isFalse(
            data.styleMap && data.style,
            `vnode.data.styleMap and vnode.data.style ambiguous declaration.`
        );
        if (data.style && !isString(data.style)) {
github salesforce / lwc / packages / @lwc / engine / src / framework / api.ts View on Github external
export function c(
    sel: string,
    Ctor: ComponentConstructor,
    data: CustomElementCompilerData,
    children?: VNodes
): VCustomElement {
    if (isCircularModuleDependency(Ctor)) {
        Ctor = resolveCircularModuleDependency(Ctor);
    }
    const vmBeingRendered = getVMBeingRendered();
    if (process.env.NODE_ENV !== 'production') {
        assert.isTrue(isString(sel), `c() 1st argument sel must be a string.`);
        assert.isTrue(isFunction(Ctor), `c() 2nd argument Ctor must be a function.`);
        assert.isTrue(isObject(data), `c() 3nd argument data must be an object.`);
        assert.isTrue(
            arguments.length === 3 || isArray(children),
            `c() 4nd argument data must be an array.`
        );
        // checking reserved internal data properties
        assert.isFalse(
            data.className && data.classMap,
            `vnode.data.className and vnode.data.classMap ambiguous declaration.`
        );
        assert.isFalse(
            data.styleMap && data.style,
            `vnode.data.styleMap and vnode.data.style ambiguous declaration.`
        );
        if (data.style && !isString(data.style)) {
            logError(
                `Invalid 'style' attribute passed to <${sel}> is ignored. This attribute must be a string value.`,
github salesforce / lwc / packages / @lwc / wire-service / src / index.ts View on Github external
connected: (cmp: EventTarget, data: object, def: ElementDef, context: Context) => {
        let listeners: NoArgumentListener[];
        if (process.env.NODE_ENV !== 'production') {
            assert.isTrue(
                !def.wire || context[CONTEXT_ID],
                'wire service was not initialized prior to component creation:  "connected" service hook invoked without necessary context'
            );
        }
        if (!def.wire || !(listeners = context[CONTEXT_ID][CONTEXT_CONNECTED])) {
            return;
        }
        invokeListener(listeners);
    },
github salesforce / lwc / packages / @lwc / wire-service / src / index.ts View on Github external
export function register(adapterId: any, adapterFactory: WireAdapterFactory) {
    if (process.env.NODE_ENV !== 'production') {
        assert.isTrue(adapterId, 'adapter id must be truthy');
        assert.isTrue(typeof adapterFactory === 'function', 'adapter factory must be a callable');
    }
    adapterFactories.set(adapterId, adapterFactory);
}
github salesforce / lwc / packages / @lwc / wire-service / src / index.ts View on Github external
export function register(adapterId: any, adapterFactory: WireAdapterFactory) {
    if (process.env.NODE_ENV !== 'production') {
        assert.isTrue(adapterId, 'adapter id must be truthy');
        assert.isTrue(typeof adapterFactory === 'function', 'adapter factory must be a callable');
    }
    adapterFactories.set(adapterId, adapterFactory);
}
github salesforce / lwc / packages / @lwc / engine / src / framework / decorators / wire.ts View on Github external
function wireDecorator(
    target: ComponentConstructor,
    prop: PropertyKey,
    descriptor: PropertyDescriptor | undefined
): PropertyDescriptor | any {
    if (process.env.NODE_ENV !== 'production') {
        if (!isUndefined(descriptor)) {
            const { get, set, configurable, writable } = descriptor;
            assert.isTrue(
                !get && !set,
                `Compiler Error: A @wire decorator can only be applied to a public field.`
            );
            assert.isTrue(
                configurable !== false,
                `Compiler Error: A @wire decorator can only be applied to a configurable property.`
            );
            assert.isTrue(
                writable !== false,
                `Compiler Error: A @wire decorator can only be applied to a writable property.`
            );
        }
    }
    return createTrackedPropertyDescriptor(
        target,
        prop,