How to use the @lwc/errors.generateCompilerDiagnostic 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
plugins,
            onwarn: handleRollupWarning(diagnostics),
        });

        const { output } = await rollupBundler.generate({
            amd: { id: namespace + '/' + name },
            strict: false,
            sourcemap: outputConfig.sourcemap,
            format,
        });

        // Rollup produces multiple chunks when a module uses "import()" with a relative import
        // path. We need to ensure the compiled module only contains the main chunk.
        if (output.length > 1) {
            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);
    }
github salesforce / lwc / packages / @lwc / template-compiler / src / parser / index.ts View on Github external
function warnAt(
        errorInfo: LWCErrorInfo,
        messageArgs?: any[],
        location?: parse5.MarkupData.Location
    ) {
        addDiagnostic(
            generateCompilerDiagnostic(errorInfo, {
                messageArgs,
                origin: {
                    location: normalizeLocation(location),
                },
            })
        );
    }
github salesforce / lwc / packages / @lwc / template-compiler / src / parser / html.ts View on Github external
const validateClosingTag = (node: parse5.AST.Default.Element) => {
        if (!node.__location) {
            return;
        }

        const { startTag, endTag } = node.__location;
        const isVoidElement = VOID_ELEMENT_SET.has(node.tagName);
        const missingClosingTag = !!startTag && !endTag;

        if (!isVoidElement && missingClosingTag) {
            parsingErrors.push(
                generateCompilerDiagnostic(ParserDiagnostics.NO_MATCHING_CLOSING_TAGS, {
                    messageArgs: [node.tagName],
                    origin: {
                        location: {
                            line: startTag.startLine || startTag.line,
                            column: startTag.startCol || startTag.col,
                            start: startTag.startOffset,
                            length: startTag.endOffset - startTag.startOffset,
                        },
                    },
                })
            );
        }
    };
github salesforce / lwc / packages / @lwc / template-compiler / src / parser / html.ts View on Github external
const onParseError = (err: parse5.Errors.ParsingError) => {
        const { code, startLine, startCol, startOffset, endOffset } = err;

        parsingErrors.push(
            generateCompilerDiagnostic(ParserDiagnostics.INVALID_HTML_SYNTAX, {
                messageArgs: [code],
                origin: {
                    location: {
                        line: startLine,
                        column: startCol,
                        start: startOffset,
                        length: endOffset - startOffset,
                    },
                },
            })
        );
    };
github salesforce / lwc / packages / @lwc / template-compiler / src / parser / index.ts View on Github external
const location = (toLocate as parse5.AST.Default.Element).__location;

            if (!location) {
                return getLocation(treeAdapter.getParentNode(toLocate));
            } else {
                return {
                    line: location.line || location.startLine,
                    column: location.col || location.startCol,
                    start: location.startOffset,
                    length: location.endOffset - location.startOffset,
                };
            }
        };

        addDiagnostic(
            generateCompilerDiagnostic(errorInfo, {
                messageArgs,
                origin: {
                    location: getLocation(node),
                },
            })
        );
    }