How to use @lwc/template-compiler - 4 common examples

To help you get started, we’ve selected a few @lwc/template-compiler 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 / scripts / jest / test-utils.js View on Github external
function compileTemplate(source, config = {}) {
    const { modules = {} } = config;

    // Check if the same template has already been compiled
    if (!(source in TEMPLATE_CACHE)) {
        TEMPLATE_CACHE[source] = compileToFunction(source);
    }

    const templateFactory = TEMPLATE_CACHE[source];
    return registerTemplate(templateFactory(modules));
}
github salesforce / lwc / packages / @lwc / compiler / src / transformers / template.ts View on Github external
export default function templateTransform(
    src: string,
    filename: string,
    options: NormalizedTransformOptions
): FileTransformerResult {
    let result;

    try {
        result = compile(src, {
            experimentalDynamicDirective: !!options.experimentalDynamicComponent,
        });
    } catch (e) {
        throw normalizeToCompilerError(TransformerErrors.HTML_TRANSFORMER_ERROR, e, { filename });
    }

    const fatalError = result.warnings.find(warning => warning.level === DiagnosticLevel.Error);
    if (fatalError) {
        throw CompilerError.from(fatalError, { filename });
    }

    // Rollup only cares about the mappings property on the map. Since producing a source map for
    // the template doesn't make sense, the transform returns an empty mappings.
    return {
        code: serialize(result.code, filename, options),
        map: { mappings: '' },
github salesforce / lwc / packages / @lwc / compiler / src / transformers / template.ts View on Github external
export default function templateTransform(
    src: string,
    filename: string,
    options: NormalizedCompilerOptions
): FileTransformerResult {
    let result;

    try {
        result = compile(src, {
            experimentalDynamicDirective: !!options.experimentalDynamicComponent,
        });
    } catch (e) {
        throw normalizeToCompilerError(TransformerErrors.HTML_TRANSFORMER_ERROR, e, { filename });
    }

    const fatalError = result.warnings.find(warning => warning.level === DiagnosticLevel.Error);
    if (fatalError) {
        throw CompilerError.from(fatalError, { filename });
    }

    // Rollup only cares about the mappings property on the map. Since producing a source map for
    // the template doesn't make sense, the transform returns an empty mappings.
    return {
        code: serialize(result.code, filename, options),
        map: { mappings: '' },
github forcedotcom / lightning-language-server / packages / lwc-language-server / src / template / linter.ts View on Github external
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,
        };
    });
}

@lwc/template-compiler

Template compiler package

MIT
Latest version published 2 days ago

Package Health Score

90 / 100
Full package analysis