forked from github-mirror/twing
Compare commits
3 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
452bedc081 | ||
|
70b2cc85f7 | ||
|
1bda045fb9 |
@ -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) {
|
||||
|
@ -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")
|
||||
|
@ -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;
|
||||
|
@ -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';
|
||||
|
Loading…
Reference in New Issue
Block a user