mirror of
https://github.com/marko-js/marko.git
synced 2025-12-08 19:26:05 +00:00
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:
parent
44a32d34c4
commit
68eb6717dc
@ -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);
|
||||
};
|
||||
@ -138,7 +138,7 @@
|
||||
]
|
||||
},
|
||||
"<macro>": {
|
||||
"code-generator": "./macro-tag",
|
||||
"node-factory": "./macro-tag",
|
||||
"autocomplete": [
|
||||
{
|
||||
"displayText": "macro <name>(<parmas>)",
|
||||
|
||||
1
test/autotests/render/macros-ordering/expected.html
Normal file
1
test/autotests/render/macros-ordering/expected.html
Normal file
@ -0,0 +1 @@
|
||||
[a: Hello foo] [b: Hello bar]
|
||||
10
test/autotests/render/macros-ordering/template.marko
Normal file
10
test/autotests/render/macros-ordering/template.marko
Normal file
@ -0,0 +1,10 @@
|
||||
<macro a(name)>
|
||||
[a: Hello ${name}]
|
||||
<b('bar')/>
|
||||
</macro>
|
||||
|
||||
<macro b(name)>
|
||||
[b: Hello ${name}]
|
||||
</macro>
|
||||
|
||||
<a('foo')/>
|
||||
1
test/autotests/render/macros-ordering/test.js
Normal file
1
test/autotests/render/macros-ordering/test.js
Normal file
@ -0,0 +1 @@
|
||||
exports.templateData = {};
|
||||
Loading…
x
Reference in New Issue
Block a user