mirror of
https://github.com/marko-js/marko.git
synced 2025-12-08 19:26:05 +00:00
Added support for addBeforeCode and addAfterCode to all nodes
This commit is contained in:
parent
24929b8734
commit
cae229cc6a
@ -37,6 +37,8 @@ function Node(nodeType) {
|
||||
this.prefixMappings = {};
|
||||
this.transformersApplied = {};
|
||||
this.properties = {};
|
||||
this.beforeCode = [];
|
||||
this.afterCode = [];
|
||||
}
|
||||
}
|
||||
|
||||
@ -359,8 +361,24 @@ Node.prototype = {
|
||||
setStripExpression: function (stripExpression) {
|
||||
this.stripExpression = stripExpression;
|
||||
},
|
||||
|
||||
addBeforeCode: function (code) {
|
||||
this.beforeCode.push(code);
|
||||
},
|
||||
addAfterCode: function (code) {
|
||||
this.afterCode.push(code);
|
||||
},
|
||||
|
||||
generateCode: function (template) {
|
||||
this.compiler = template.compiler;
|
||||
|
||||
if (this.beforeCode.length) {
|
||||
this.beforeCode.forEach(function (code) {
|
||||
template.indent().code(code).code('\n');
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
var preserveWhitespace = this.isPreserveWhitespace();
|
||||
if (preserveWhitespace == null) {
|
||||
preserveWhitespace = template.options.preserveWhitespace;
|
||||
@ -409,6 +427,12 @@ Node.prototype = {
|
||||
} catch (e) {
|
||||
throw createError(new Error('Unable to generate code for node ' + this + ' at position [' + this.getPosition() + ']. Exception: ' + e), e);
|
||||
}
|
||||
|
||||
if (this.afterCode.length) {
|
||||
this.afterCode.forEach(function (code) {
|
||||
template.indent().code(code).code('\n');
|
||||
});
|
||||
}
|
||||
},
|
||||
isPreserveWhitespace: function () {
|
||||
return this.preserveWhitespace;
|
||||
|
||||
@ -63,8 +63,6 @@ function TagHandlerNode(tag) {
|
||||
}
|
||||
this.tag = tag;
|
||||
this.dynamicAttributes = null;
|
||||
this.preInvokeCode = [];
|
||||
this.postInvokeCode = [];
|
||||
this.inputExpression = null;
|
||||
}
|
||||
TagHandlerNode.convertNode = function (node, tag) {
|
||||
@ -81,12 +79,6 @@ TagHandlerNode.prototype = {
|
||||
setDynamicAttributesProperty: function(name) {
|
||||
this.dynamicAttributesProperty = name;
|
||||
},
|
||||
addPreInvokeCode: function (code) {
|
||||
this.preInvokeCode.push(code);
|
||||
},
|
||||
addPostInvokeCode: function (code) {
|
||||
this.postInvokeCode.push(code);
|
||||
},
|
||||
setInputExpression: function (expression) {
|
||||
this.inputExpression = expression;
|
||||
},
|
||||
@ -133,13 +125,6 @@ TagHandlerNode.prototype = {
|
||||
}
|
||||
variableNames.push(varName);
|
||||
}, this);
|
||||
if (_this.preInvokeCode.length) {
|
||||
_this.preInvokeCode.forEach(function (code) {
|
||||
template.indent().code(code).code('\n');
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
||||
template.contextHelperMethodCall('t', function () {
|
||||
template.code('\n').indent(function () {
|
||||
@ -166,12 +151,6 @@ TagHandlerNode.prototype = {
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
if (_this.postInvokeCode.length) {
|
||||
_this.postInvokeCode.forEach(function (code) {
|
||||
template.indent().code(code).code('\n');
|
||||
});
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user