How to use the @lwc/errors.invariant function in @lwc/errors

To help you get started, we’ve selected a few @lwc/errors 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 / compiler / src / compiler / options.ts View on Github external
function validateOutputConfig(config: OutputConfig) {
    invariant(
        isUndefinedOrBoolean(config.minify),
        CompilerValidationErrors.INVALID_MINIFY_PROPERTY,
        [config.minify]
    );

    invariant(
        isUndefinedOrBoolean(config.compat),
        CompilerValidationErrors.INVALID_COMPAT_PROPERTY,
        [config.compat]
    );

    invariant(
        isUndefinedOrBoolean(config.sourcemap),
        CompilerValidationErrors.INVALID_SOURCEMAP_PROPERTY,
        [config.sourcemap]
    );

    if (!isUndefined(config.env)) {
        invariant(isObject(config.env), CompilerValidationErrors.INVALID_ENV_PROPERTY, [
            config.env,
        ]);

        for (const [key, value] of Object.entries(config.env)) {
            invariant(KNOWN_ENV.has(key), CompilerValidationErrors.UNKNOWN_ENV_ENTRY_KEY, [key]);

            invariant(isString(value), CompilerValidationErrors.INVALID_ENV_ENTRY_VALUE, [
                key,
                value,
github salesforce / lwc / packages / @lwc / compiler / src / compiler / options.ts View on Github external
function validateOutputConfig(config: OutputConfig) {
    invariant(
        isUndefinedOrBoolean(config.minify),
        CompilerValidationErrors.INVALID_MINIFY_PROPERTY,
        [config.minify]
    );

    invariant(
        isUndefinedOrBoolean(config.compat),
        CompilerValidationErrors.INVALID_COMPAT_PROPERTY,
        [config.compat]
    );

    invariant(
        isUndefinedOrBoolean(config.sourcemap),
        CompilerValidationErrors.INVALID_SOURCEMAP_PROPERTY,
        [config.sourcemap]
    );
github salesforce / lwc / packages / @lwc / compiler / src / compiler / options.ts View on Github external
if (!isUndefined(customProperties)) {
        const { allowDefinition, resolution } = customProperties;

        invariant(
            isUndefined(allowDefinition) || isBoolean(allowDefinition),
            CompilerValidationErrors.INVALID_ALLOWDEFINITION_PROPERTY,
            [allowDefinition]
        );

        if (!isUndefined(resolution)) {
            invariant(isObject(resolution), CompilerValidationErrors.INVALID_RESOLUTION_PROPERTY, [
                resolution,
            ]);

            const { type } = resolution;
            invariant(
                type === 'native' || type === 'module',
                CompilerValidationErrors.INVALID_TYPE_PROPERTY,
                [type]
            );
        }
    }
}
github salesforce / lwc / packages / @lwc / compiler / src / compiler / options.ts View on Github external
export function validateOptions(options: CompilerOptions) {
    invariant(!isUndefined(options), CompilerValidationErrors.MISSING_OPTIONS_OBJECT, [options]);
    invariant(isString(options.name), CompilerValidationErrors.INVALID_NAME_PROPERTY, [
        options.name,
    ]);
    invariant(isString(options.namespace), CompilerValidationErrors.INVALID_NAMESPACE_PROPERTY, [
        options.namespace,
    ]);

    invariant(
        !isUndefined(options.files) && !!Object.keys(options.files).length,
        CompilerValidationErrors.INVALID_FILES_PROPERTY
    );

    for (const key of Object.keys(options.files)) {
        const value = options.files[key];
        invariant(
            !isUndefined(value) && isString(value),
github salesforce / lwc / packages / @lwc / compiler / src / compiler / options.ts View on Github external
function validateStylesheetConfig(config: StylesheetConfig) {
    const { customProperties } = config;

    if (!isUndefined(customProperties)) {
        const { allowDefinition, resolution } = customProperties;

        invariant(
            isUndefined(allowDefinition) || isBoolean(allowDefinition),
            CompilerValidationErrors.INVALID_ALLOWDEFINITION_PROPERTY,
            [allowDefinition]
        );

        if (!isUndefined(resolution)) {
            invariant(isObject(resolution), CompilerValidationErrors.INVALID_RESOLUTION_PROPERTY, [
                resolution,
            ]);

            const { type } = resolution;
            invariant(
                type === 'native' || type === 'module',
                CompilerValidationErrors.INVALID_TYPE_PROPERTY,
                [type]
            );
        }
    }
}
github salesforce / lwc / packages / @lwc / compiler / src / compiler / options.ts View on Github external
invariant(
        isUndefinedOrBoolean(config.sourcemap),
        CompilerValidationErrors.INVALID_SOURCEMAP_PROPERTY,
        [config.sourcemap]
    );

    if (!isUndefined(config.env)) {
        invariant(isObject(config.env), CompilerValidationErrors.INVALID_ENV_PROPERTY, [
            config.env,
        ]);

        for (const [key, value] of Object.entries(config.env)) {
            invariant(KNOWN_ENV.has(key), CompilerValidationErrors.UNKNOWN_ENV_ENTRY_KEY, [key]);

            invariant(isString(value), CompilerValidationErrors.INVALID_ENV_ENTRY_VALUE, [
                key,
                value,
            ]);
        }
    }
}
github salesforce / lwc / packages / @lwc / compiler / src / transformers / transformer.ts View on Github external
function validateArguments(src: string, filename: string) {
    invariant(isString(src), TransformerErrors.INVALID_SOURCE, [src]);
    invariant(isString(filename), TransformerErrors.INVALID_ID, [filename]);
}