diff --git a/.gitignore b/.gitignore index 5877b244e..0176dc830 100644 --- a/.gitignore +++ b/.gitignore @@ -12,6 +12,7 @@ coverage ~* /.cache *.marko.js +*.marko.xml.js /test/generated/ .nyc_output yarn.lock diff --git a/bin/markoc.js b/bin/markoc.js index aa767d7b6..91b2e0a65 100644 --- a/bin/markoc.js +++ b/bin/markoc.js @@ -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)); diff --git a/compiler/CompileContext.js b/compiler/CompileContext.js index 700484a52..46ec66627 100644 --- a/compiler/CompileContext.js +++ b/compiler/CompileContext.js @@ -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(); @@ -421,9 +422,10 @@ class CompileContext extends EventEmitter { if (typeof tagName === 'string') { tagDef = taglibLookup.getTag(tagName); if (!tagDef && - !this.isMacro(tagName) && - tagName.indexOf(':') === -1 && - !htmlElements.isRegisteredElement(tagName, this.dirname)) { + !this.isMacro(tagName) && + tagName.indexOf(':') === -1 && + !htmlElements.isRegisteredElement(tagName, this.dirname) && + !this.ignoreUnrecognizedTags) { if (this._parsingFinished) { this.addErrorUnrecognizedTag(tagName, elNode); diff --git a/compiler/Compiler.js b/compiler/Compiler.js index cf390cbd4..b2219ad14 100644 --- a/compiler/Compiler.js +++ b/compiler/Compiler.js @@ -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 diff --git a/test/autotests/markoc/single-xml-template/test.js b/test/autotests/markoc/single-xml-template/test.js new file mode 100644 index 000000000..322171b4e --- /dev/null +++ b/test/autotests/markoc/single-xml-template/test.js @@ -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); +}; diff --git a/test/autotests/render/ignore-unrecognized-tag/expected.html b/test/autotests/render/ignore-unrecognized-tag/expected.html new file mode 100644 index 000000000..ed32e175c --- /dev/null +++ b/test/autotests/render/ignore-unrecognized-tag/expected.html @@ -0,0 +1 @@ + diff --git a/test/autotests/render/ignore-unrecognized-tag/template.marko b/test/autotests/render/ignore-unrecognized-tag/template.marko new file mode 100644 index 000000000..ed32e175c --- /dev/null +++ b/test/autotests/render/ignore-unrecognized-tag/template.marko @@ -0,0 +1 @@ + diff --git a/test/autotests/render/ignore-unrecognized-tag/test.js b/test/autotests/render/ignore-unrecognized-tag/test.js new file mode 100644 index 000000000..a86ac4591 --- /dev/null +++ b/test/autotests/render/ignore-unrecognized-tag/test.js @@ -0,0 +1,4 @@ +var expect = require('chai').expect; + +exports.templateData = {}; +exports.ignoreUnrecognizedTags = true; diff --git a/test/util/runRenderTest.js b/test/util/runRenderTest.js index 937de5a0b..3e2b5f6d7 100644 --- a/test/util/runRenderTest.js +++ b/test/util/runRenderTest.js @@ -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(); @@ -225,4 +229,4 @@ module.exports = function runRenderTest(dir, helpers, done, options) { delete require('marko/compiler').defaultOptions.preserveWhitespace; } } -}; \ No newline at end of file +};