Fixes #695 - Default to ignoring unrecognized tags for XML files.

This commit is contained in:
Austin Kelleher 2017-05-18 20:46:15 -04:00
parent 3d757a20f3
commit 4cf05973a5
12 changed files with 48 additions and 10 deletions

1
.gitignore vendored
View File

@ -12,6 +12,7 @@ coverage
~*
/.cache
*.marko.js
*.marko.xml.js
/test/generated/
.nyc_output
yarn.lock

View File

@ -46,6 +46,10 @@ function relPath(path) {
}
}
function shouldIgnoreUnrecognizedTags(path) {
return path.endsWith('.xml') || path.endsWith('.xml.marko');
}
var args = require('argly').createParser({
'--help': {
type: 'boolean',
@ -293,8 +297,6 @@ if (args.clean) {
console.log('Deleted: ' + file);
context.endAsync();
});
}
}
},
@ -318,11 +320,18 @@ if (args.clean) {
return;
}
found[path] = true;
if (shouldIgnoreUnrecognizedTags(path)) {
compileOptions = compileOptions || {};
compileOptions.ignoreUnrecognizedTags = true;
}
found[path] = true;
var outPath = path + '.js';
console.log('Compiling:\n Input: ' + relPath(path) + '\n Output: ' + relPath(outPath) + '\n');
context.beginAsync();
markoCompiler.compileFile(path, compileOptions, function(err, src) {
if (err) {
failed.push('Failed to compile "' + relPath(path) + '". Error: ' + (err.stack || err));

View File

@ -110,6 +110,7 @@ class CompileContext extends EventEmitter {
this.compilerType = this.options.compilerType || 'marko';
this.compilerVersion = this.options.compilerVersion || markoPkgVersion;
this.writeVersionComment = writeVersionComment !== 'undefined' ? writeVersionComment : true;
this.ignoreUnrecognizedTags = this.options.ignoreUnrecognizedTags || false;
this._vars = {};
this._uniqueVars = new UniqueVars();
@ -423,7 +424,8 @@ class CompileContext extends EventEmitter {
if (!tagDef &&
!this.isMacro(tagName) &&
tagName.indexOf(':') === -1 &&
!htmlElements.isRegisteredElement(tagName, this.dirname)) {
!htmlElements.isRegisteredElement(tagName, this.dirname) &&
!this.ignoreUnrecognizedTags) {
if (this._parsingFinished) {
this.addErrorUnrecognizedTag(tagName, elNode);

View File

@ -138,7 +138,7 @@ class Compiler {
var ast = this.parser.parse(src, context);
context._parsingFinished = true;
if (context.unrecognizedTags) {
if (!context.ignoreUnrecognizedTags && context.unrecognizedTags) {
for(let i=0; i<context.unrecognizedTags.length; i++) {
let unrecognizedTag = context.unrecognizedTags[i];
// See if the tag is a macro

View File

@ -43,7 +43,13 @@ if (g.__MARKO_CONFIG) {
* Whether the version should be written to the template as a comment e.g.
* // Compiled using marko@4.0.0 - DO NOT EDIT
*/
writeVersionComment: true
writeVersionComment: true,
/**
* Whether unrecognized tags should be ignored or not. This flag will
* be enabled by default when compiling XML.
*/
ignoreUnrecognizedTags: false
};
}

View File

@ -4,6 +4,7 @@ exports.check = function(marko, markoCompiler, expect, helpers, done) {
expect(compiler.config.writeToDisk).to.equal(true);
expect(compiler.config.preserveWhitespace).to.equal(false);
expect(compiler.config.writeVersionComment).to.equal(true);
expect(compiler.config.ignoreUnrecognizedTags).to.equal(false);
compiler.configure({
preserveWhitespace: true

View File

@ -0,0 +1 @@
<urlset></urlset>

View File

@ -0,0 +1,8 @@
var expect = require('chai').expect;
exports.test = function(helpers) {
expect(helpers.existsSync('template.marko.xml.js')).to.equal(false);
var result = helpers.spawnSync(['template.marko.xml']);
expect(helpers.existsSync('template.marko.xml.js')).to.equal(true);
expect(result.status).to.equal(0);
};

View File

@ -0,0 +1 @@
<unrecognized></unrecognized>

View File

@ -0,0 +1 @@
<unrecognized></unrecognized>

View File

@ -0,0 +1,4 @@
var expect = require('chai').expect;
exports.templateData = {};
exports.ignoreUnrecognizedTags = true;

View File

@ -101,6 +101,10 @@ module.exports = function runRenderTest(dir, helpers, done, options) {
require('marko/compiler').defaultOptions.preserveWhitespace = true;
}
if (main.ignoreUnrecognizedTags) {
require('marko/compiler').defaultOptions.ignoreUnrecognizedTags = true;
}
var oldDone = done;
done = function(err) {
require('marko/compiler').configure();