mirror of
https://github.com/marko-js/marko.git
synced 2025-12-08 19:26:05 +00:00
When compiling templates that use string concatenation, treat null and undefined as empty strings so that the the literal "null" and "undefined" don't get written
This commit is contained in:
parent
8a25b7eab9
commit
a49554b4cb
@ -250,9 +250,12 @@ function TemplateBuilder(compiler, path, rootNode) {
|
|||||||
this.helperFunctionsAdded = {};
|
this.helperFunctionsAdded = {};
|
||||||
this.vars = [];
|
this.vars = [];
|
||||||
this.varsLookup = {};
|
this.varsLookup = {};
|
||||||
|
|
||||||
|
this.getStaticHelperFunction('toString', 's');
|
||||||
this.getStaticHelperFunction('empty', 'e');
|
this.getStaticHelperFunction('empty', 'e');
|
||||||
this.getStaticHelperFunction('notEmpty', 'ne');
|
this.getStaticHelperFunction('notEmpty', 'ne');
|
||||||
}
|
}
|
||||||
|
|
||||||
TemplateBuilder.prototype = {
|
TemplateBuilder.prototype = {
|
||||||
|
|
||||||
captureCode: function (func, thisObj) {
|
captureCode: function (func, thisObj) {
|
||||||
@ -283,7 +286,7 @@ TemplateBuilder.prototype = {
|
|||||||
addStaticVar: function (name, expression) {
|
addStaticVar: function (name, expression) {
|
||||||
name = safeVarName(name);
|
name = safeVarName(name);
|
||||||
|
|
||||||
if (!this.staticVarsLookup[name]) {
|
if (!this.staticVarsLookup.hasOwnProperty(name)) {
|
||||||
this.staticVarsLookup[name] = true;
|
this.staticVarsLookup[name] = true;
|
||||||
this.staticVars.push({
|
this.staticVars.push({
|
||||||
name: name,
|
name: name,
|
||||||
|
|||||||
@ -238,7 +238,7 @@ ExpressionParserHelper.prototype = {
|
|||||||
// We don't need to surround with parentheses if
|
// We don't need to surround with parentheses if
|
||||||
// the expression will be escaped since the expression
|
// the expression will be escaped since the expression
|
||||||
// is an argument to a function call
|
// is an argument to a function call
|
||||||
expression = '(' + expression + ')';
|
expression = 'toString(' + expression + ')';
|
||||||
}
|
}
|
||||||
expression = new Expression(expression);
|
expression = new Expression(expression);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -14,6 +14,10 @@ function notEmpty(o) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
|
s: function(str) {
|
||||||
|
return (str == null) ? '' : str;
|
||||||
|
},
|
||||||
|
|
||||||
fv: function (array, callback) {
|
fv: function (array, callback) {
|
||||||
if (!array) {
|
if (!array) {
|
||||||
return;
|
return;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user