mirror of
https://github.com/marko-js/marko.git
synced 2026-02-01 16:07:13 +00:00
Fixes #260 - Circular custom tags causes infinite recursion when writeToDisk is set to false
This commit is contained in:
parent
1ea1808c71
commit
1fe897c386
@ -91,7 +91,7 @@ exports.install = function(options) {
|
||||
module.exports = loaded.exports;
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
// Resolve the appropriate compiler relative to the location of the
|
||||
// marko template file on disk using the "resolve-from" module.
|
||||
var dirname = path.dirname(filename);
|
||||
|
||||
@ -54,10 +54,18 @@ fixFlush();
|
||||
function loadSource(templatePath, compiledSrc) {
|
||||
var templateModulePath = templatePath + '.js';
|
||||
|
||||
// Short-circuit loading if the template has already been cached in the Node.js require cache
|
||||
var cached = require.cache[templateModulePath];
|
||||
if (cached) {
|
||||
return cached.exports;
|
||||
}
|
||||
|
||||
var templateModule = new Module(templateModulePath, module);
|
||||
templateModule.paths = Module._nodeModulePaths(nodePath.dirname(templateModulePath));
|
||||
templateModule.filename = templateModulePath;
|
||||
|
||||
Module._cache[templateModulePath] = templateModule;
|
||||
|
||||
templateModule._compile(
|
||||
compiledSrc,
|
||||
templateModulePath);
|
||||
|
||||
1
test/fixtures/render/autotest/circular-tags-no-write-to-disk/expected.html
vendored
Normal file
1
test/fixtures/render/autotest/circular-tags-no-write-to-disk/expected.html
vendored
Normal file
@ -0,0 +1 @@
|
||||
<ul><li><b>a</b></li><li><b>b</b><ul><li><b>b1</b></li><li><b>b2</b></li></ul></li></ul>
|
||||
1
test/fixtures/render/autotest/circular-tags-no-write-to-disk/marko.json
vendored
Normal file
1
test/fixtures/render/autotest/circular-tags-no-write-to-disk/marko.json
vendored
Normal file
@ -0,0 +1 @@
|
||||
{ "tags-dir": "./tags/" }
|
||||
@ -0,0 +1,6 @@
|
||||
<ul>
|
||||
<li for(item in data.items)>
|
||||
<b>${item.label}</b>
|
||||
<navigation-item items=item.children if(item.children)/>
|
||||
</li>
|
||||
</ul>
|
||||
1
test/fixtures/render/autotest/circular-tags-no-write-to-disk/template.marko
vendored
Normal file
1
test/fixtures/render/autotest/circular-tags-no-write-to-disk/template.marko
vendored
Normal file
@ -0,0 +1 @@
|
||||
<navigation-item items=data.items/>
|
||||
20
test/fixtures/render/autotest/circular-tags-no-write-to-disk/test.js
vendored
Normal file
20
test/fixtures/render/autotest/circular-tags-no-write-to-disk/test.js
vendored
Normal file
@ -0,0 +1,20 @@
|
||||
exports.templateData = {
|
||||
items: [
|
||||
{
|
||||
label: 'a'
|
||||
},
|
||||
{
|
||||
label: 'b',
|
||||
children: [
|
||||
{
|
||||
label: 'b1'
|
||||
},
|
||||
{
|
||||
label: 'b2'
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
};
|
||||
|
||||
exports.writeToDisk = false;
|
||||
@ -20,28 +20,38 @@ describe('render', function() {
|
||||
var main = fs.existsSync(mainPath) ? require(mainPath) : {};
|
||||
var loadOptions = main && main.loadOptions;
|
||||
|
||||
if (main.checkError) {
|
||||
var e;
|
||||
if (main.writeToDisk === false) {
|
||||
require('marko/compiler').defaultOptions.writeToDisk = false;
|
||||
}
|
||||
|
||||
try {
|
||||
marko.load(templatePath, loadOptions);
|
||||
} catch(_e) {
|
||||
e = _e;
|
||||
var errorFile = path.join(dir, 'error.txt');
|
||||
fs.writeFileSync(errorFile, e.stack.toString(), { encoding: 'utf8' });
|
||||
try {
|
||||
if (main.checkError) {
|
||||
var e;
|
||||
|
||||
try {
|
||||
marko.load(templatePath, loadOptions);
|
||||
} catch(_e) {
|
||||
e = _e;
|
||||
var errorFile = path.join(dir, 'error.txt');
|
||||
fs.writeFileSync(errorFile, e.stack.toString(), { encoding: 'utf8' });
|
||||
}
|
||||
|
||||
if (!e) {
|
||||
throw new Error('Error expected');
|
||||
}
|
||||
|
||||
main.checkError(e);
|
||||
return '$PASS$';
|
||||
} else {
|
||||
var template = marko.load(templatePath, loadOptions);
|
||||
var templateData = main.templateData || {};
|
||||
var html = template.renderSync(templateData);
|
||||
return html;
|
||||
}
|
||||
|
||||
if (!e) {
|
||||
throw new Error('Error expected');
|
||||
} finally {
|
||||
if (main.writeToDisk === false) {
|
||||
require('marko/compiler').defaultOptions.writeToDisk = false;
|
||||
}
|
||||
|
||||
main.checkError(e);
|
||||
return '$PASS$';
|
||||
} else {
|
||||
var template = marko.load(templatePath, loadOptions);
|
||||
var templateData = main.templateData || {};
|
||||
var html = template.renderSync(templateData);
|
||||
return html;
|
||||
}
|
||||
},
|
||||
{
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user