How to use the @lwc/errors.DiagnosticLevel.Warning 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 / template-compiler / src / index.ts View on Github external
export function compileToFunction(source: string): Function {
    const options = mergeConfig({});
    options.format = 'function';

    const state = new State(source, options);

    const parsingResults = parseTemplate(source, state);

    for (const warning of parsingResults.warnings) {
        if (warning.level === DiagnosticLevel.Error) {
            throw CompilerError.from(warning);
        } else if (warning.level === DiagnosticLevel.Warning) {
            /* eslint-disable-next-line no-console */
            console.warn(warning.message);
        } else {
            /* eslint-disable-next-line no-console */
            console.log(warning.message);
        }
    }

    if (!parsingResults.root) {
        throw generateCompilerError(TemplateErrors.INVALID_TEMPLATE);
    }

    const { code } = generate(parsingResults.root, state);
    return new Function(TEMPLATE_MODULES_PARAMETER, code);
}
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 => {
        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,