Comparing version 2.0.7 to 2.0.8
@@ -15,11 +15,9 @@ "use strict"; | ||
var m; | ||
while (m = JS_IDENTIFIER.exec(code)) { | ||
code.match(JS_IDENTIFIER).forEach(function (m) { | ||
possibleConflicts[JSON.parse('"' + m + '"')] = true; | ||
} | ||
}); | ||
} | ||
function passThrough(compiler, context, node) { | ||
node.children.forEach(function(child) { | ||
node.children.forEach(function (child) { | ||
compileNode(compiler, context, child); | ||
@@ -33,3 +31,3 @@ }); | ||
Scope.prototype.getName = function(name) { | ||
Scope.prototype.getName = function (name) { | ||
while (this.used.hasOwnProperty(name)) { | ||
@@ -51,3 +49,3 @@ name += "_"; | ||
block: passThrough, | ||
element: function(compiler, context, node) { | ||
element: function (compiler, context, node) { | ||
if (!context.content) { | ||
@@ -66,3 +64,3 @@ throw node.unexpected; | ||
node.children.forEach(function(child) { | ||
node.children.forEach(function (child) { | ||
compileNode(compiler, newContext, child); | ||
@@ -87,3 +85,3 @@ }); | ||
}, | ||
attribute: function(compiler, context, node) { | ||
attribute: function (compiler, context, node) { | ||
if (!context.attributes) { | ||
@@ -109,3 +107,3 @@ throw node.unexpected; | ||
}, | ||
string: function(compiler, context, node) { | ||
string: function (compiler, context, node) { | ||
if (!context.content) { | ||
@@ -125,3 +123,3 @@ throw node.unexpected; | ||
}, | ||
class: function(compiler, context, node) { | ||
class: function (compiler, context, node) { | ||
if (!context.classes) { | ||
@@ -133,3 +131,3 @@ throw node.unexpected; | ||
}, | ||
code: function(compiler, context, node) { | ||
code: function (compiler, context, node) { | ||
if (node.children.length) { | ||
@@ -142,3 +140,3 @@ context.content.addCode(node.code + (POSSIBLE_COMMENT.test(node.code) ? "\n{" : " {")); | ||
node.children.forEach(function(child) { | ||
node.children.forEach(function (child) { | ||
compileNode(compiler, newContext, child); | ||
@@ -154,3 +152,3 @@ }); | ||
}, | ||
include: function(compiler, context, node) { | ||
include: function (compiler, context, node) { | ||
var subtree = compiler.options.load(node.template); | ||
@@ -160,3 +158,3 @@ | ||
}, | ||
if: function(compiler, context, node) { | ||
if: function (compiler, context, node) { | ||
var condition = POSSIBLE_COMMENT.test(node.condition) ? node.condition + "\n" : node.condition; | ||
@@ -172,3 +170,3 @@ | ||
node.children.forEach(function(child) { | ||
node.children.forEach(function (child) { | ||
compileNode(compiler, newContext, child); | ||
@@ -198,3 +196,3 @@ }); | ||
node.else.children.forEach(function(child) { | ||
node.else.children.forEach(function (child) { | ||
compileNode(compiler, elseContext, child); | ||
@@ -244,3 +242,3 @@ }); | ||
}, | ||
for: function(compiler, context, node) { | ||
for: function (compiler, context, node) { | ||
var newContext = { | ||
@@ -270,3 +268,3 @@ content: context.content | ||
node.children.forEach(function(child) { | ||
node.children.forEach(function (child) { | ||
compileNode(compiler, newContext, child); | ||
@@ -321,2 +319,3 @@ }); | ||
// jshint evil: true | ||
return new Function("data", code); | ||
@@ -323,0 +322,0 @@ } |
{ | ||
"name": "razorleaf", | ||
"version": "2.0.7", | ||
"version": "2.0.8", | ||
"main": "razorleaf.js", | ||
@@ -5,0 +5,0 @@ "files": [ |
@@ -27,2 +27,4 @@ "use strict"; | ||
function isExpression(js) { | ||
// jshint evil: true, nonew: false | ||
try { | ||
@@ -45,3 +47,3 @@ new Function("'use strict'; (" + js + "\n)"); | ||
var states = { | ||
indent: function(parser, c) { | ||
indent: function (parser, c) { | ||
if (c === null && parser.indentString) { | ||
@@ -117,3 +119,3 @@ parser.warn("Trailing whitespace"); | ||
}, | ||
content: function(parser, c) { | ||
content: function (parser, c) { | ||
if (c === null) { | ||
@@ -175,3 +177,3 @@ return; | ||
}, | ||
comment: function(parser, c) { | ||
comment: function (parser, c) { | ||
if (c === null || c === "\n") { | ||
@@ -183,3 +185,3 @@ return states.content(parser, c); | ||
}, | ||
code: function(parser, c) { | ||
code: function (parser, c) { | ||
if (c === null || c === "\n") { | ||
@@ -206,3 +208,3 @@ parser.context = { | ||
}, | ||
identifier: function(parser, c) { | ||
identifier: function (parser, c) { | ||
if (c === ":") { | ||
@@ -238,3 +240,3 @@ return states.possibleAttribute; | ||
}, | ||
className: function(parser, c) { | ||
className: function (parser, c) { | ||
if (c !== null && IDENTIFIER.test(c)) { | ||
@@ -262,3 +264,3 @@ parser.identifier += c; | ||
}, | ||
possibleAttribute: function(parser, c) { | ||
possibleAttribute: function (parser, c) { | ||
if (c !== null && IDENTIFIER.test(c)) { | ||
@@ -290,3 +292,3 @@ parser.identifier += ":" + c; | ||
}, | ||
rawString: function(parser, c) { | ||
rawString: function (parser, c) { | ||
if (c !== '"') { | ||
@@ -298,3 +300,3 @@ throw parser.error("Expected beginning quote of raw string, not " + describe(c)); | ||
}, | ||
string: function(parser, c) { | ||
string: function (parser, c) { | ||
if (c === null) { | ||
@@ -342,3 +344,3 @@ throw parser.error("Expected end of string before end of file"); | ||
}, | ||
stringPound: function(parser, c) { | ||
stringPound: function (parser, c) { | ||
if (c === "{") { | ||
@@ -352,3 +354,3 @@ parser.interpolation = ""; | ||
}, | ||
interpolation: function(parser, c) { | ||
interpolation: function (parser, c) { | ||
if (c === null) { | ||
@@ -367,3 +369,3 @@ throw parser.error("Interpolated section never resolves to a valid JavaScript expression"); // TODO: Where did it start? | ||
}, | ||
escape: function(parser, c) { | ||
escape: function (parser, c) { | ||
if (c === null) { | ||
@@ -395,3 +397,3 @@ throw parser.error("Expected escape character"); | ||
}, | ||
escapeX1: function(parser, c) { | ||
escapeX1: function (parser, c) { | ||
if (c === null || !HEX.test(c)) { | ||
@@ -404,3 +406,3 @@ throw parser.error("Expected hexadecimal digit"); | ||
}, | ||
escapeX2: function(parser, c) { | ||
escapeX2: function (parser, c) { | ||
if (c === null || !HEX.test(c)) { | ||
@@ -420,3 +422,3 @@ throw parser.error("Expected hexadecimal digit"); | ||
}, | ||
escapeU1: function(parser, c) { | ||
escapeU1: function (parser, c) { | ||
if (c === null || !HEX.test(c)) { | ||
@@ -429,3 +431,3 @@ throw parser.error("Expected hexadecimal digit"); | ||
}, | ||
escapeU2: function(parser, c) { | ||
escapeU2: function (parser, c) { | ||
if (c === null || !HEX.test(c)) { | ||
@@ -438,3 +440,3 @@ throw parser.error("Expected hexadecimal digit"); | ||
}, | ||
escapeU3: function(parser, c) { | ||
escapeU3: function (parser, c) { | ||
if (c === null || !HEX.test(c)) { | ||
@@ -447,3 +449,3 @@ throw parser.error("Expected hexadecimal digit"); | ||
}, | ||
escapeU4: function(parser, c) { | ||
escapeU4: function (parser, c) { | ||
if (c === null || !HEX.test(c)) { | ||
@@ -466,3 +468,3 @@ throw parser.error("Expected hexadecimal digit"); | ||
var keywords = { | ||
doctype: function(parser, c) { | ||
doctype: function (parser, c) { | ||
parser.context.children.push({ | ||
@@ -480,3 +482,3 @@ type: "string", | ||
}, | ||
include: function(parser, c) { | ||
include: function (parser, c) { | ||
function leadingWhitespace(parser, c) { | ||
@@ -516,3 +518,3 @@ if (c === " ") { | ||
}, | ||
extends: function(parser, c) { | ||
extends: function (parser, c) { | ||
if (parser.root.children.length || parser.root.extends) { | ||
@@ -523,3 +525,3 @@ throw parser.error("extends must appear first in a template"); | ||
parser.root.children = { | ||
push: function() { | ||
push: function () { | ||
throw parser.error("A template that extends another can only contain block actions directly"); | ||
@@ -557,3 +559,3 @@ } | ||
}, | ||
block: function(parser, c) { | ||
block: function (parser, c) { | ||
function leadingWhitespace(parser, c) { | ||
@@ -598,3 +600,3 @@ if (c === " ") { | ||
}, | ||
replace: function(parser, c) { | ||
replace: function (parser, c) { | ||
function leadingWhitespace(parser, c) { | ||
@@ -623,3 +625,3 @@ if (c === " ") { | ||
var action = function(block) { | ||
var action = function (block) { | ||
block.children = newBlock.children; | ||
@@ -645,3 +647,3 @@ }; | ||
}, | ||
append: function(parser, c) { | ||
append: function (parser, c) { | ||
function leadingWhitespace(parser, c) { | ||
@@ -670,3 +672,3 @@ if (c === " ") { | ||
var action = function(block) { | ||
var action = function (block) { | ||
push.apply(block.children, newBlock.children); | ||
@@ -692,3 +694,3 @@ }; | ||
}, | ||
if: function(parser, c) { | ||
if: function (parser, c) { | ||
var condition_ = ""; | ||
@@ -735,3 +737,3 @@ | ||
}, | ||
elif: function(parser, c) { | ||
elif: function (parser, c) { | ||
var condition_ = ""; | ||
@@ -783,3 +785,3 @@ | ||
}, | ||
else: function(parser, c) { | ||
else: function (parser, c) { | ||
var previous = parser.context.children && parser.context.children[parser.context.children.length - 1]; | ||
@@ -806,3 +808,3 @@ | ||
}, | ||
for: function(parser, c) { | ||
for: function (parser, c) { | ||
var collection_ = ""; | ||
@@ -994,3 +996,3 @@ | ||
}, | ||
error: function(message, position) { | ||
error: function (message, position) { | ||
position = position || parser.position; | ||
@@ -1000,3 +1002,3 @@ var where = eof ? "EOF" : "line " + position.line + ", character " + position.character; | ||
}, | ||
warn: function(message) { | ||
warn: function (message) { | ||
if (options.debug) { | ||
@@ -1003,0 +1005,0 @@ var where = eof ? "EOF" : "line " + parser.position.line + ", character " + parser.position.character; |
@@ -40,3 +40,3 @@ "use strict"; | ||
var loaderOptions = { | ||
load: function(name) { | ||
load: function (name) { | ||
return parser.parse(loader.read(name), combine(defaults, loaderOptions, { name: name }, loader.options)); | ||
@@ -51,7 +51,7 @@ } | ||
DirectoryLoader.prototype.read = function(name) { | ||
DirectoryLoader.prototype.read = function (name) { | ||
return fs.readFileSync(path.join(this.root, name + ".leaf"), "utf-8"); | ||
}; | ||
DirectoryLoader.prototype.load = function(name) { | ||
DirectoryLoader.prototype.load = function (name) { | ||
return compile(this.read(name), this.options); | ||
@@ -58,0 +58,0 @@ }; |
"use strict"; | ||
function escapeLiteral(text) { | ||
return text.replace(/\\/g, "\\\\") | ||
.replace(/'/g, "\\'") | ||
.replace(/\r/g, "\\r") | ||
.replace(/\n/g, "\\n") | ||
.replace(/\u2028/g, "\\u2028") | ||
.replace(/\u2029/g, "\\u2029"); | ||
return text | ||
.replace(/\\/g, "\\\\") | ||
.replace(/'/g, "\\'") | ||
.replace(/\r/g, "\\r") | ||
.replace(/\n/g, "\\n") | ||
.replace(/\u2028/g, "\\u2028") | ||
.replace(/\u2029/g, "\\u2029"); | ||
} | ||
function escapeAttributeValue(value) { | ||
return ("" + value).replace(/&/g, "&") | ||
.replace(/"/g, """); | ||
return ("" + value) | ||
.replace(/&/g, "&") | ||
.replace(/"/g, """); | ||
} | ||
function escapeContent(value) { | ||
return ("" + value).replace(/&/g, "&") | ||
.replace(/</g, "<") | ||
.replace(/>/g, ">"); | ||
return ("" + value) | ||
.replace(/&/g, "&") | ||
.replace(/</g, "<") | ||
.replace(/>/g, ">"); | ||
} | ||
@@ -27,3 +30,3 @@ | ||
CodeBlock.prototype.addText = function(text) { | ||
CodeBlock.prototype.addText = function (text) { | ||
this.parts.push({ | ||
@@ -37,3 +40,3 @@ type: "text", | ||
CodeBlock.prototype.addExpression = function(escapeFunction, expression) { | ||
CodeBlock.prototype.addExpression = function (escapeFunction, expression) { | ||
this.parts.push({ | ||
@@ -48,3 +51,3 @@ type: "expression", | ||
CodeBlock.prototype.addCode = function(code) { | ||
CodeBlock.prototype.addCode = function (code) { | ||
this.parts.push({ | ||
@@ -58,3 +61,3 @@ type: "code", | ||
CodeBlock.prototype.addBlock = function(block) { | ||
CodeBlock.prototype.addBlock = function (block) { | ||
Array.prototype.push.apply(this.parts, block.parts); | ||
@@ -65,3 +68,3 @@ | ||
CodeBlock.prototype.toCode = function(outputVariable, initialState) { | ||
CodeBlock.prototype.toCode = function (outputVariable, initialState) { | ||
var code = ""; | ||
@@ -68,0 +71,0 @@ var currentType = initialState; |
971562
25672