Fixes #544 - Usage of macro before it is defined not handled correctly

Register macro when the node is created instead of waiting until code generation
This commit is contained in:
Patrick Steele-Idem 2017-01-21 09:39:49 -07:00
parent 44a32d34c4
commit 68eb6717dc
5 changed files with 19 additions and 4 deletions

View File

@ -1,10 +1,11 @@
module.exports = function codeGenerator(elNode, codegen) {
module.exports = function nodeFactory(elNode, context) {
var attributes = elNode.attributes;
var defAttr = attributes[0];
if(!defAttr || defAttr.value !== undefined) {
return codegen.addError('The <macro> tag must contain a name as its first attribute, example: <macro greeting()>');
context.addError(elNode, 'The <macro> tag must contain a name as its first attribute, example: <macro greeting()>');
return elNode;
}
var body = elNode.body;
@ -17,7 +18,9 @@ module.exports = function codeGenerator(elNode, codegen) {
params = [];
}
var builder = codegen.builder;
var builder = context.builder;
context.registerMacro(macroName, params);
return builder.macro(macroName, params, body);
};

View File

@ -138,7 +138,7 @@
]
},
"<macro>": {
"code-generator": "./macro-tag",
"node-factory": "./macro-tag",
"autocomplete": [
{
"displayText": "macro <name>(<parmas>)",

View File

@ -0,0 +1 @@
[a: Hello foo] [b: Hello bar]

View File

@ -0,0 +1,10 @@
<macro a(name)>
[a: Hello ${name}]
<b('bar')/>
</macro>
<macro b(name)>
[b: Hello ${name}]
</macro>
<a('foo')/>

View File

@ -0,0 +1 @@
exports.templateData = {};