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.prefixMappings = {};
|
||||||
this.transformersApplied = {};
|
this.transformersApplied = {};
|
||||||
this.properties = {};
|
this.properties = {};
|
||||||
|
this.beforeCode = [];
|
||||||
|
this.afterCode = [];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -359,8 +361,24 @@ Node.prototype = {
|
|||||||
setStripExpression: function (stripExpression) {
|
setStripExpression: function (stripExpression) {
|
||||||
this.stripExpression = stripExpression;
|
this.stripExpression = stripExpression;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
addBeforeCode: function (code) {
|
||||||
|
this.beforeCode.push(code);
|
||||||
|
},
|
||||||
|
addAfterCode: function (code) {
|
||||||
|
this.afterCode.push(code);
|
||||||
|
},
|
||||||
|
|
||||||
generateCode: function (template) {
|
generateCode: function (template) {
|
||||||
this.compiler = template.compiler;
|
this.compiler = template.compiler;
|
||||||
|
|
||||||
|
if (this.beforeCode.length) {
|
||||||
|
this.beforeCode.forEach(function (code) {
|
||||||
|
template.indent().code(code).code('\n');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
var preserveWhitespace = this.isPreserveWhitespace();
|
var preserveWhitespace = this.isPreserveWhitespace();
|
||||||
if (preserveWhitespace == null) {
|
if (preserveWhitespace == null) {
|
||||||
preserveWhitespace = template.options.preserveWhitespace;
|
preserveWhitespace = template.options.preserveWhitespace;
|
||||||
@ -409,6 +427,12 @@ Node.prototype = {
|
|||||||
} catch (e) {
|
} catch (e) {
|
||||||
throw createError(new Error('Unable to generate code for node ' + this + ' at position [' + this.getPosition() + ']. Exception: ' + e), 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 () {
|
isPreserveWhitespace: function () {
|
||||||
return this.preserveWhitespace;
|
return this.preserveWhitespace;
|
||||||
|
|||||||
@ -63,8 +63,6 @@ function TagHandlerNode(tag) {
|
|||||||
}
|
}
|
||||||
this.tag = tag;
|
this.tag = tag;
|
||||||
this.dynamicAttributes = null;
|
this.dynamicAttributes = null;
|
||||||
this.preInvokeCode = [];
|
|
||||||
this.postInvokeCode = [];
|
|
||||||
this.inputExpression = null;
|
this.inputExpression = null;
|
||||||
}
|
}
|
||||||
TagHandlerNode.convertNode = function (node, tag) {
|
TagHandlerNode.convertNode = function (node, tag) {
|
||||||
@ -81,12 +79,6 @@ TagHandlerNode.prototype = {
|
|||||||
setDynamicAttributesProperty: function(name) {
|
setDynamicAttributesProperty: function(name) {
|
||||||
this.dynamicAttributesProperty = name;
|
this.dynamicAttributesProperty = name;
|
||||||
},
|
},
|
||||||
addPreInvokeCode: function (code) {
|
|
||||||
this.preInvokeCode.push(code);
|
|
||||||
},
|
|
||||||
addPostInvokeCode: function (code) {
|
|
||||||
this.postInvokeCode.push(code);
|
|
||||||
},
|
|
||||||
setInputExpression: function (expression) {
|
setInputExpression: function (expression) {
|
||||||
this.inputExpression = expression;
|
this.inputExpression = expression;
|
||||||
},
|
},
|
||||||
@ -133,13 +125,6 @@ TagHandlerNode.prototype = {
|
|||||||
}
|
}
|
||||||
variableNames.push(varName);
|
variableNames.push(varName);
|
||||||
}, this);
|
}, this);
|
||||||
if (_this.preInvokeCode.length) {
|
|
||||||
_this.preInvokeCode.forEach(function (code) {
|
|
||||||
template.indent().code(code).code('\n');
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
template.contextHelperMethodCall('t', function () {
|
template.contextHelperMethodCall('t', function () {
|
||||||
template.code('\n').indent(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