mirror of
https://github.com/marko-js/marko.git
synced 2026-02-01 16:07:13 +00:00
Fixes #695 - Always ignore unrecognized tags for XML files when using the compiler.
This commit is contained in:
parent
7aac3aae38
commit
1967f85d06
@ -46,10 +46,6 @@ function relPath(path) {
|
||||
}
|
||||
}
|
||||
|
||||
function shouldIgnoreUnrecognizedTags(path) {
|
||||
return path.endsWith('.xml') || path.endsWith('.xml.marko');
|
||||
}
|
||||
|
||||
var args = require('argly').createParser({
|
||||
'--help': {
|
||||
type: 'boolean',
|
||||
@ -325,11 +321,6 @@ if (args.clean) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (shouldIgnoreUnrecognizedTags(path)) {
|
||||
compileOptions = compileOptions || {};
|
||||
compileOptions.ignoreUnrecognizedTags = true;
|
||||
}
|
||||
|
||||
found[path] = true;
|
||||
var outPath = path + '.js';
|
||||
|
||||
|
||||
@ -59,9 +59,13 @@ function createWalker(options) {
|
||||
return new Walker(options);
|
||||
}
|
||||
|
||||
function shouldIgnoreUnrecognizedTags(path) {
|
||||
return path.endsWith('.xml') || path.endsWith('.xml.marko');
|
||||
}
|
||||
|
||||
function _compile(src, filename, userOptions, callback) {
|
||||
registerCoreTaglibs();
|
||||
|
||||
|
||||
ok(filename, '"filename" argument is required');
|
||||
ok(typeof filename === 'string', '"filename" argument should be a string');
|
||||
|
||||
@ -75,6 +79,10 @@ function _compile(src, filename, userOptions, callback) {
|
||||
|
||||
var compiler = defaultCompiler;
|
||||
|
||||
if (shouldIgnoreUnrecognizedTags(filename)) {
|
||||
options.ignoreUnrecognizedTags = true;
|
||||
}
|
||||
|
||||
var context = new CompileContext(src, filename, compiler.builder, options);
|
||||
|
||||
if (callback) {
|
||||
|
||||
@ -0,0 +1 @@
|
||||
<urlset></urlset>
|
||||
@ -24,6 +24,7 @@ exports.check = function(marko, markoCompiler, expect, done) {
|
||||
expect(markoCompiler.config.preserveWhitespace).to.equal(true);
|
||||
|
||||
compileAndCheck('./a.marko', true /* should write to disk */);
|
||||
compileAndCheck('./e.xml.marko', true /* should write to disk */);
|
||||
|
||||
require('marko/node-require').install({
|
||||
compilerOptions: {
|
||||
@ -72,4 +73,4 @@ exports.check = function(marko, markoCompiler, expect, done) {
|
||||
compileAndCheck('./d.marko', false /* should write to disk */);
|
||||
|
||||
done();
|
||||
};
|
||||
};
|
||||
|
||||
13
test/autotests/compiler/xml-file/expected.js
Normal file
13
test/autotests/compiler/xml-file/expected.js
Normal file
@ -0,0 +1,13 @@
|
||||
"use strict";
|
||||
|
||||
var marko_template = module.exports = require("marko/src/html").t(__filename);
|
||||
|
||||
function render(input, out) {
|
||||
var data = input;
|
||||
|
||||
out.w("<urlset></urlset>");
|
||||
}
|
||||
|
||||
marko_template._ = render;
|
||||
|
||||
marko_template.meta = {};
|
||||
1
test/autotests/compiler/xml-file/template.xml.marko
Normal file
1
test/autotests/compiler/xml-file/template.xml.marko
Normal file
@ -0,0 +1 @@
|
||||
<urlset></urlset>
|
||||
@ -10,45 +10,65 @@ var fs = require('fs');
|
||||
|
||||
require('marko/node-require').install();
|
||||
|
||||
const EXTENSIONS = ['.marko', '.xml.marko'];
|
||||
|
||||
function runTestForExtension (dir, helpers, extension, done) {
|
||||
var templatePath = path.join(dir, `template${extension}`);
|
||||
|
||||
if (!fs.existsSync(templatePath)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
var mainPath = path.join(dir, 'test.js');
|
||||
var main;
|
||||
|
||||
if (fs.existsSync(mainPath)) {
|
||||
main = require(mainPath);
|
||||
}
|
||||
|
||||
var compilerOptions = { writeVersionComment: false };
|
||||
|
||||
if (main && main.checkError) {
|
||||
var e;
|
||||
|
||||
try {
|
||||
compiler.compileFile(templatePath, compilerOptions);
|
||||
} catch(_e) {
|
||||
e = _e;
|
||||
}
|
||||
|
||||
if (!e) {
|
||||
throw new Error('Error expected');
|
||||
}
|
||||
|
||||
main.checkError(e);
|
||||
done();
|
||||
|
||||
} else if(main && main.checkTemplate) {
|
||||
var template = require('marko').load(templatePath, Object.assign(compilerOptions, main.compilerOptions));
|
||||
main.checkTemplate(template);
|
||||
done();
|
||||
} else {
|
||||
var compiledSrc = compiler.compileFile(templatePath, Object.assign(compilerOptions, main && main.compilerOptions));
|
||||
compiledSrc = compiledSrc.replace(/marko\/dist\//g, 'marko/src/');
|
||||
helpers.compare(compiledSrc, '.js');
|
||||
done();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
describe('compiler', function() {
|
||||
var autoTestDir = path.join(__dirname, 'autotests/compiler');
|
||||
|
||||
autotest.scanDir(autoTestDir, function run(dir, helpers, done) {
|
||||
var templatePath = path.join(dir, 'template.marko');
|
||||
var mainPath = path.join(dir, 'test.js');
|
||||
var main;
|
||||
for (let i = 0; i < EXTENSIONS.length; i++) {
|
||||
const extension = EXTENSIONS[i];
|
||||
let complete = runTestForExtension(dir, helpers, extension, done);
|
||||
|
||||
if (fs.existsSync(mainPath)) {
|
||||
main = require(mainPath);
|
||||
}
|
||||
|
||||
var compilerOptions = { writeVersionComment: false };
|
||||
|
||||
if (main && main.checkError) {
|
||||
var e;
|
||||
|
||||
try {
|
||||
compiler.compileFile(templatePath, compilerOptions);
|
||||
} catch(_e) {
|
||||
e = _e;
|
||||
if (complete) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!e) {
|
||||
throw new Error('Error expected');
|
||||
}
|
||||
|
||||
main.checkError(e);
|
||||
done();
|
||||
|
||||
} else if(main && main.checkTemplate) {
|
||||
var template = require('marko').load(templatePath, Object.assign(compilerOptions, main.compilerOptions));
|
||||
main.checkTemplate(template);
|
||||
done();
|
||||
} else {
|
||||
var compiledSrc = compiler.compileFile(templatePath, Object.assign(compilerOptions, main && main.compilerOptions));
|
||||
compiledSrc = compiledSrc.replace(/marko\/dist\//g, 'marko/src/');
|
||||
helpers.compare(compiledSrc, '.js');
|
||||
done();
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user