Commit b37bf6ac authored by Eric MORAND's avatar Eric MORAND
Browse files

Resolve issue #640

parent 8c151c09
Loading
Loading
Loading
Loading
Loading
+9 −0
Original line number Diff line number Diff line
@@ -6,6 +6,7 @@ import {executeSynchronousTemplate, type TwingSynchronousTemplate, type TwingTem
import type {TwingCallable, TwingSynchronousCallable} from "../../../callable-wrapper";
import {iterableToMap, iteratorToMap} from "../../../helpers/iterator-to-map";
import {mergeIterables} from "../../../helpers/merge-iterables";
import type {TwingError} from "../../../error";

/**
 * Renders a template.
@@ -62,6 +63,10 @@ export const include: TwingCallable<[
    const resolveTemplate = (templates: Array<string | TwingTemplate | null>): Promise<TwingTemplate | null> => {
        return template.loadTemplate(executionContext, templates)
            .catch((error) => {
                if ((error as TwingError).name === "TwingParsingError") {
                    throw error;
                }
                
                if (!ignoreMissing) {
                    throw error;
                }
@@ -149,6 +154,10 @@ export const includeSynchronously: TwingSynchronousCallable<[
        try {
            return template.loadTemplate(executionContext, templates);
        } catch (error) {
            if ((error as TwingError).name === "TwingParsingError") {
                throw error;
            }
            
            if (!ignoreMissing) {
                throw error;
            }
+10 −1
Original line number Diff line number Diff line
@@ -28,6 +28,7 @@ import {
import type {TwingExecutionContext, TwingSynchronousExecutionContext} from "./execution-context";
import {iterableToMap, iteratorToMap} from "./helpers/iterator-to-map";
import {isAMapLike, type MapLike} from "./helpers/map-like";
import type {TwingError} from "./error";

export type TwingTemplateBlockMap = Map<string, [template: TwingTemplate, name: string]>;
export type TwingSynchronousTemplateBlockMap = Map<string, [template: TwingSynchronousTemplate, name: string]>;
@@ -482,7 +483,11 @@ export const createTemplate = (
                }
                else {
                    return template.loadTemplate(executionContext, name)
                        .catch(() => {
                        .catch((error) => {
                            if ((error as TwingError).name === "TwingParsingError") {
                                return Promise.reject(error);
                            }
                            
                            return loadTemplateAtIndex(index + 1);
                        });
                }
@@ -954,6 +959,10 @@ export const createSynchronousTemplate = (
                    try {
                        return template.loadTemplate(executionContext, name);
                    } catch (error) {
                        if ((error as TwingError).name === "TwingParsingError") {
                            throw error;
                        }
                        
                        return loadTemplateAtIndex(index + 1);
                    }
                }
+10 −0
Original line number Diff line number Diff line
import {runTest} from "../TestBase";

runTest({
    description: 'A parse error is thrown when an included template can\'t be parsed',
    templates: {
        "index.twig": '{{ include("unparseable.twig") }}',
        "unparseable.twig": '{{ }'
    },
    expectedErrorMessage: 'TwingParsingError: Unexpected "}" in "unparseable.twig" at line 1, column 4.'
});
+1 −0
Original line number Diff line number Diff line
import "./child_contents_outside_blocks";
import "./default_value_is_not_a_constant";
import "./include-function-with-parse-error";
import "./malformed_arguments";
import "./multiline_array_with_undefined_variable";
import "./multiline_array_with_undefined_variable_again";