Loading src/main/lib/extension/core/functions/include.ts +9 −0 Original line number Diff line number Diff line Loading @@ -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. Loading Loading @@ -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; } Loading Loading @@ -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; } Loading src/main/lib/template.ts +10 −1 Original line number Diff line number Diff line Loading @@ -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]>; Loading Loading @@ -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); }); } Loading Loading @@ -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); } } Loading src/test/tests/integration/errors/include-function-with-parse-error.ts 0 → 100644 +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.' }); src/test/tests/integration/errors/index.ts +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"; Loading Loading
src/main/lib/extension/core/functions/include.ts +9 −0 Original line number Diff line number Diff line Loading @@ -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. Loading Loading @@ -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; } Loading Loading @@ -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; } Loading
src/main/lib/template.ts +10 −1 Original line number Diff line number Diff line Loading @@ -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]>; Loading Loading @@ -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); }); } Loading Loading @@ -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); } } Loading
src/test/tests/integration/errors/include-function-with-parse-error.ts 0 → 100644 +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.' });
src/test/tests/integration/errors/index.ts +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"; Loading