Compare commits

...

3 Commits
main ... 5.x

Author SHA1 Message Date
Eric MORAND
452bedc081 Merge branch 'issue-601' into '5.x'
Resolve issue #601 - [5.x] The `source` function doesn't trigger the `template` event of the environment

See merge request nightlycommit/twing!596
2023-12-30 10:28:58 +00:00
Eric MORAND
70b2cc85f7 Merge branch '5.x' into 'issue-601'
# Conflicts:
#   test/tests/unit/lib/template/test.ts
2023-12-30 01:26:53 +00:00
Eric MORAND
1bda045fb9 Resolve issue #601 2023-12-30 01:23:41 +00:00
4 changed files with 6 additions and 7 deletions

View File

@ -1,5 +1,3 @@
import {TwingEnvironment} from "../../../environment";
import {TwingSource} from "../../../source";
import {TwingErrorLoader} from "../../../error/loader";
import {TwingTemplate} from "../../../template";
@ -16,8 +14,8 @@ export function source(template: TwingTemplate, name: string, ignoreMissing: boo
let env = template.environment;
let from = template.source;
return env.getLoader().getSourceContext(name, from).then((source) => {
return source.getCode();
return env.resolveTemplate([name], from).then((template) => {
return template.source.getCode();
}).catch((e) => {
if (e instanceof TwingErrorLoader) {
if (!ignoreMissing) {

View File

@ -113,7 +113,7 @@ export class TwingNodeModule extends TwingNode {
.subcompile(this.getNode('constructor_start'))
.write('super(environment);\n\n')
.write('this._source = new this.Source(')
.string(compiler.getEnvironment().isDebug() || compiler.getEnvironment().isSourceMap() ? this.source.getCode() : '')
.string(this.source.getCode())
.raw(', ')
.string(this.source.getResolvedName())
.raw(");\n\n")

View File

@ -52,7 +52,7 @@ tape('node/module', (test) => {
constructor(environment) {
super(environment);
this._source = new this.Source(\`\`, \`foo.twig\`);
this._source = new this.Source(\`{{ foo }}\`, \`foo.twig\`);
let aliases = new this.Context();
aliases.proxy[\`_self\`] = this.aliases.proxy[\`_self\`] = this;
@ -94,7 +94,7 @@ tape('node/module', (test) => {
constructor(environment) {
super(environment);
this._source = new this.Source(\`\`, \`foo.twig\`);
this._source = new this.Source(\`{{ foo }}\`, \`foo.twig\`);
let aliases = new this.Context();
aliases.proxy[\`_self\`] = this.aliases.proxy[\`_self\`] = this;

View File

@ -188,6 +188,7 @@ tape('template', function (test) {
test.fail('should throw an Error');
} catch (e) {
test.true(e instanceof Error);
// Node.js v16 and later use a newer error message for properties of null.
// TODO: Remove the Node.js v15 and earlier test after EOL on 2023-04-30.
const oldErrorMessage = 'Cannot read property \'loadTemplate\' of null';