How to use the @lwc/errors.DiagnosticLevel.Fatal 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 / bundler / bundler.ts View on Github external
diagnostics.push(
                generateCompilerDiagnostic(ModuleResolutionErrors.RELATIVE_DYNAMIC_IMPORT)
            );
        }

        const result = output[0];
        code = result.code;
        map = result.map;
    } catch (e) {
        // Rollup may have clobbered error.code with its own data
        if (e instanceof CompilerError && (e as any).pluginCode) {
            e.code = (e as any).pluginCode;
        }

        const diagnostic = normalizeToDiagnostic(ModuleResolutionErrors.MODULE_RESOLUTION_ERROR, e);
        diagnostic.level = DiagnosticLevel.Fatal;
        diagnostics.push(diagnostic);
    }

    return {
        diagnostics,
        code,
        map,
    };
}
github salesforce / lwc / packages / @lwc / compiler / src / rollup-plugins / __tests__ / module-resolver.spec.ts View on Github external
test('compiler should report fatal diagnostic when invalid entry path is specified', async () => {
        const COMPILER_CONFIG_BASEDIR = {
            name: 'modules/foo',
            namespace: 'x',
            files: {
                'foo.js': ``,
            },
        };

        const { diagnostics, success } = await compile(COMPILER_CONFIG_BASEDIR);
        expect(success).toBe(false);
        expect(diagnostics[0].level).toBe(DiagnosticLevel.Fatal);
    });
github salesforce / lwc / packages / @lwc / compiler / src / compiler / __tests__ / result.spec.ts View on Github external
test('compiler returns diagnostic errors when module resolution encounters an error', async () => {
        const config = {
            name: 'foo',
            namespace: 'x',
            files: {
                'foo.js': `import something from './nothing';`,
            },
        };
        const { success, diagnostics } = await compile(config);
        expect(success).toBe(false);
        expect(diagnostics.length).toBe(1);

        const { level, message, code } = diagnostics[0];

        expect(level).toBe(DiagnosticLevel.Fatal);
        expect(message).toContain(
            'Failed to resolve import "./nothing" from "foo.js". Please add "nothing" file to the component folder.'
        );
        expect(code).toBe(1011);
    });
github salesforce / lwc / packages / @lwc / compiler / src / compiler / __tests__ / result.spec.ts View on Github external
test('compiler returns diagnostic errors when transformation encounters an error in javascript', async () => {
        const config = {
            name: 'foo',
            namespace: 'x',
            files: {
                'foo.js': `throw`,
            },
        };
        const { success, diagnostics } = await compile(config);

        expect(success).toBe(false);
        expect(diagnostics.length).toBe(1);

        const { level, message } = diagnostics[0];

        expect(level).toBe(DiagnosticLevel.Fatal);
        expect(message).toContain('Unexpected token (1:5)');
    });
github salesforce / lwc / packages / @lwc / compiler / src / compiler / __tests__ / result.spec.ts View on Github external
name: 'foo',
            namespace: 'x',
            files: {
                'foo.js': `import { LightningElement } from 'lwc';
                export default class Test extends LightningElement {}
                `,
                'foo.html': `<template></template>`,
                'foo.css': `a {`,
            },
        };
        const { success, diagnostics } = await compile(config);

        expect(success).toBe(false);
        expect(diagnostics).toMatchObject([
            {
                level: DiagnosticLevel.Fatal,
                message: expect.stringContaining('Unclosed block'),
            },
        ]);
    });
github salesforce / lwc / packages / @lwc / compiler / src / compiler / compiler.ts View on Github external
return diagnostics.some(d => {
        return d.level === DiagnosticLevel.Error || d.level === DiagnosticLevel.Fatal;
    });
}
github salesforce / lwc / packages / @lwc / compiler / src / compiler / compiler.ts View on Github external
return diagnostics.some(d => {
        return d.level === DiagnosticLevel.Error || d.level === DiagnosticLevel.Fatal;
    });
}
github forcedotcom / lightning-language-server / packages / lwc-language-server / src / template / linter.ts View on Github external
import { DiagnosticLevel } from '@lwc/errors';
import templateCompiler from '@lwc/template-compiler';
import { TextDocument, Diagnostic, DiagnosticSeverity, Range } from 'vscode-languageserver';
import { DIAGNOSTIC_SOURCE } from '../constants';

const LEVEL_MAPPING: Map = new Map([
    [DiagnosticLevel.Log, DiagnosticSeverity.Information],
    [DiagnosticLevel.Warning, DiagnosticSeverity.Warning],
    [DiagnosticLevel.Error, DiagnosticSeverity.Error],
    [DiagnosticLevel.Fatal, DiagnosticSeverity.Error],
]);

export default function lint(document: TextDocument): Diagnostic[] {
    const source = document.getText();
    const { warnings } = templateCompiler(source, {});

    return warnings.map(warning =&gt; {
        const { start = 0, length = 0 } = warning.location || { start: 0, length: 0 };

        return {
            range: toRange(document, start, length),
            message: warning.message,
            severity: LEVEL_MAPPING.get(warning.level),
            source: DIAGNOSTIC_SOURCE,
        };
    });