From 6aef4d100f01f43e93b4d4463a8ef94cdfc7d193 Mon Sep 17 00:00:00 2001 From: Michael Rawlings Date: Thu, 2 Jun 2016 16:04:46 -0700 Subject: [PATCH] tag now requires a name as its first attribute, which may or may not be an argument attribute --- taglibs/core/macro-tag.js | 9 +++------ test/autotests/render/error-macro-no-name/marko.json | 5 +++++ .../render/error-macro-no-name/template.marko | 7 +++++++ test/autotests/render/error-macro-no-name/test.js | 11 +++++++++++ test/autotests/render/macro-no-args/expected.html | 2 +- test/autotests/render/macro-no-args/template.marko | 8 +++++++- 6 files changed, 34 insertions(+), 8 deletions(-) create mode 100644 test/autotests/render/error-macro-no-name/marko.json create mode 100644 test/autotests/render/error-macro-no-name/template.marko create mode 100644 test/autotests/render/error-macro-no-name/test.js diff --git a/taglibs/core/macro-tag.js b/taglibs/core/macro-tag.js index 9cdef04a4..70f510212 100644 --- a/taglibs/core/macro-tag.js +++ b/taglibs/core/macro-tag.js @@ -1,13 +1,10 @@ module.exports = function codeGenerator(elNode, codegen) { var attributes = elNode.attributes; - if (!attributes.length) { - return; - } - var defAttr = attributes[0]; - if (defAttr.argument == null) { - return; + + if(!defAttr || defAttr.value !== undefined) { + return codegen.addError('The tag must contain a name as its first attribute, example: '); } var body = elNode.body; diff --git a/test/autotests/render/error-macro-no-name/marko.json b/test/autotests/render/error-macro-no-name/marko.json new file mode 100644 index 000000000..35cf25b45 --- /dev/null +++ b/test/autotests/render/error-macro-no-name/marko.json @@ -0,0 +1,5 @@ +{ + "": { + "open-tag-only": true + } +} \ No newline at end of file diff --git a/test/autotests/render/error-macro-no-name/template.marko b/test/autotests/render/error-macro-no-name/template.marko new file mode 100644 index 000000000..adbca906b --- /dev/null +++ b/test/autotests/render/error-macro-no-name/template.marko @@ -0,0 +1,7 @@ + + This is bad. + + + + This is also bad. + \ No newline at end of file diff --git a/test/autotests/render/error-macro-no-name/test.js b/test/autotests/render/error-macro-no-name/test.js new file mode 100644 index 000000000..4ffd94392 --- /dev/null +++ b/test/autotests/render/error-macro-no-name/test.js @@ -0,0 +1,11 @@ +var expect = require('chai').expect; + +exports.templateData = {}; + +exports.checkError = function(e) { + expect(Array.isArray(e.errors)).to.equal(true); + expect(e.errors.length).to.equal(2); + + var message = e.toString(); + expect(message).to.contain('The tag must contain a name as its first attribute, example: '); +}; \ No newline at end of file diff --git a/test/autotests/render/macro-no-args/expected.html b/test/autotests/render/macro-no-args/expected.html index 5ca8959ea..066d4f79f 100644 --- a/test/autotests/render/macro-no-args/expected.html +++ b/test/autotests/render/macro-no-args/expected.html @@ -1 +1 @@ -Marko is awesomeMarko is awesome \ No newline at end of file +Marko is awesomeMarko is awesomeMarko is really awesomeMarko is really awesome \ No newline at end of file diff --git a/test/autotests/render/macro-no-args/template.marko b/test/autotests/render/macro-no-args/template.marko index 34023b780..6113a6674 100644 --- a/test/autotests/render/macro-no-args/template.marko +++ b/test/autotests/render/macro-no-args/template.marko @@ -2,5 +2,11 @@ Marko is awesome + + Marko is really awesome + + - \ No newline at end of file + + + \ No newline at end of file