Comparing version 1.5.2 to 1.5.3
@@ -23,15 +23,11 @@ "use strict"; | ||
Object.defineProperty(Scope.prototype, "code", { | ||
get: function() { | ||
var names = Object.keys(this.used); | ||
Scope.prototype.generateCode = function() { | ||
var names = Object.keys(this.used); | ||
if(names.length === 0) { | ||
return ""; | ||
} | ||
if(names.length === 0) { | ||
return ""; | ||
} | ||
return "var " + names.join(", ") + ";"; | ||
}, | ||
configurable: true, | ||
enumerable: true | ||
}); | ||
return "var " + names.join(", ") + ";"; | ||
}; | ||
@@ -145,3 +141,3 @@ var voidTags = [ | ||
function compile(tree, options) { | ||
function compile(tree) { | ||
var context = { | ||
@@ -157,16 +153,24 @@ content: new utilities.CodeContext(), | ||
var code = | ||
context.scope.code + | ||
"\n__output = '';\n" + | ||
context.content.code + | ||
"\nreturn __output;"; | ||
var staticContent = context.content.generateStatic(); | ||
if(options.debug) { | ||
console.log(code); | ||
if(staticContent !== null) { | ||
return function() { | ||
return staticContent; | ||
}; | ||
} | ||
var compiled = new Function("__util, data", code); | ||
var functionBody = | ||
context.scope.generateCode() + | ||
"\n__output = '" + | ||
context.content.generateCode("text") + | ||
"\nreturn __output;"; | ||
var compiled = new Function("__util, data", functionBody); | ||
return function(data) { | ||
return compiled(utilities, data); | ||
try { | ||
return compiled(utilities, data); | ||
} catch(ex) { | ||
console.log(ex.stack); | ||
} | ||
}; | ||
@@ -281,13 +285,2 @@ } | ||
nodeHandlers.else = function(node, context) { | ||
// The parser has already taken care of it. | ||
return { | ||
content: new utilities.CodeContext(), | ||
attributes: new utilities.CodeContext(), | ||
scope: context.scope, | ||
parent: context, | ||
done: function() {} | ||
}; | ||
}; | ||
nodeHandlers.for = function(node, context) { | ||
@@ -294,0 +287,0 @@ var indexName = context.scope.createName("index"); |
{ | ||
"name": "razorleaf", | ||
"version": "1.5.2", | ||
"version": "1.5.3", | ||
"main": "razorleaf.js", | ||
@@ -5,0 +5,0 @@ "files": [ |
@@ -79,7 +79,6 @@ "use strict"; | ||
options = options || {}; | ||
tree = loadExtends(tree, [], options); | ||
loadIncludes(tree, [], options); | ||
return compiler.compile(tree, options); | ||
return compiler.compile(tree); | ||
} | ||
@@ -86,0 +85,0 @@ |
110
utilities.js
@@ -78,66 +78,78 @@ "use strict"; | ||
Object.defineProperty(CodeContext.prototype, "code", { | ||
get: function() { | ||
var current = "code"; | ||
var generated = ""; | ||
CodeContext.prototype.generateStatic = function() { | ||
var isStatic = function(part) { | ||
return part.type === "text"; | ||
}; | ||
for(var i = 0; i < this.parts.length; i++) { | ||
var part = this.parts[i]; | ||
if(!this.parts.every(isStatic)) { | ||
return null; | ||
} | ||
switch(part.type) { | ||
case "code": | ||
if(current === "text") { | ||
generated += "';\n"; | ||
} else if(current === "expression") { | ||
generated += ";\n"; | ||
} | ||
return this.parts.map(function(part) { | ||
return part.value; | ||
}).join(""); | ||
}; | ||
generated += part.value; | ||
current = "code"; | ||
CodeContext.prototype.generateCode = function(initial) { | ||
var current = initial || "code"; | ||
var generated = ""; | ||
break; | ||
case "text": | ||
if(current === "code") { | ||
generated += "__output += '"; | ||
} else if(current === "expression") { | ||
generated += " + '"; | ||
} | ||
for(var i = 0; i < this.parts.length; i++) { | ||
var part = this.parts[i]; | ||
generated += escapeStringLiteral(part.value); | ||
current = "text"; | ||
switch(part.type) { | ||
case "code": | ||
if(current === "text") { | ||
generated += "';\n"; | ||
} else if(current === "expression") { | ||
generated += ";\n"; | ||
} | ||
break; | ||
case "expression": | ||
if(current === "code") { | ||
generated += "__output += "; | ||
} else if(current === "text") { | ||
generated += "' + "; | ||
} else { | ||
generated += " + "; | ||
} | ||
generated += part.value; | ||
current = "code"; | ||
if(part.escapeFunction) { | ||
generated += "__util." + part.escapeFunction + "((" + part.value + "))"; | ||
} else { | ||
generated += "(" + part.value + ")"; | ||
} | ||
break; | ||
case "text": | ||
if(current === "code") { | ||
generated += "__output += '"; | ||
} else if(current === "expression") { | ||
generated += " + '"; | ||
} | ||
current = "expression"; | ||
generated += escapeStringLiteral(part.value); | ||
current = "text"; | ||
break; | ||
default: | ||
throw new Error("Unknown part type"); | ||
break; | ||
case "expression": | ||
if(current === "code") { | ||
generated += "__output += "; | ||
} else if(current === "text") { | ||
generated += "' + "; | ||
} else { | ||
generated += " + "; | ||
} | ||
} | ||
if(current === "text") { | ||
generated += "';"; | ||
} else if(current === "expression") { | ||
generated += ";"; | ||
if(part.escapeFunction) { | ||
generated += "__util." + part.escapeFunction + "((" + part.value + "))"; | ||
} else { | ||
generated += "(" + part.value + ")"; | ||
} | ||
current = "expression"; | ||
break; | ||
default: | ||
throw new Error("Unknown part type"); | ||
} | ||
} | ||
return generated; | ||
if(current === "text") { | ||
generated += "';"; | ||
} else if(current === "expression") { | ||
generated += ";"; | ||
} | ||
}); | ||
return generated; | ||
}; | ||
module.exports = utilities; |
Uses eval
Supply chain riskPackage uses dynamic code execution (e.g., eval()), which is a dangerous practice. This can prevent the code from running in certain environments and increases the risk that the code may contain exploits or malicious behavior.
Found 1 instance in 1 package
Uses eval
Supply chain riskPackage uses dynamic code execution (e.g., eval()), which is a dangerous practice. This can prevent the code from running in certain environments and increases the risk that the code may contain exploits or malicious behavior.
Found 1 instance in 1 package
30998
969