Everything is working now on the new VM except for partials and inverse sections
This commit is contained in:
@@ -20,11 +20,11 @@ def remove_exports(string)
|
|||||||
match ? match[1] : string
|
match ? match[1] : string
|
||||||
end
|
end
|
||||||
|
|
||||||
minimal_deps = %w(parser compiler ast jison_ext handlebars_lexer runtime utils).map do |file|
|
minimal_deps = %w(parser compiler ast jison_ext handlebars_lexer runtime utils vm).map do |file|
|
||||||
"lib/handlebars/#{file}.js"
|
"lib/handlebars/#{file}.js"
|
||||||
end
|
end
|
||||||
|
|
||||||
debug_deps = %w(parser compiler ast jison_ext handlebars_lexer printer runtime utils).map do |file|
|
debug_deps = %w(parser compiler ast jison_ext handlebars_lexer printer runtime utils vm).map do |file|
|
||||||
"lib/handlebars/#{file}.js"
|
"lib/handlebars/#{file}.js"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -8,6 +8,9 @@ Handlebars.Context = require("Handlebars/runtime").Context;
|
|||||||
Handlebars.Utils = require("handlebars/utils").Utils;
|
Handlebars.Utils = require("handlebars/utils").Utils;
|
||||||
Handlebars.SafeString = require("handlebars/utils").SafeString;
|
Handlebars.SafeString = require("handlebars/utils").SafeString;
|
||||||
Handlebars.Exception = require("handlebars/utils").Exception;
|
Handlebars.Exception = require("handlebars/utils").Exception;
|
||||||
|
Handlebars.Compiler = require("handlebars/vm").Compiler;
|
||||||
|
Handlebars.JavaScriptCompiler = require("handlebars/vm").JavaScriptCompiler;
|
||||||
|
Handlebars.VM = require("handlebars/vm").VM;
|
||||||
|
|
||||||
// BEGIN(BROWSER)
|
// BEGIN(BROWSER)
|
||||||
|
|
||||||
|
|||||||
@@ -66,6 +66,7 @@ Handlebars.Exception = require("handlebars/utils").Exception;
|
|||||||
|
|
||||||
this.parts = dig;
|
this.parts = dig;
|
||||||
this.depth = depth;
|
this.depth = depth;
|
||||||
|
this.isSimple = (dig.length === 1) && (depth === 0)
|
||||||
};
|
};
|
||||||
|
|
||||||
Handlebars.AST.StringNode = function(string) {
|
Handlebars.AST.StringNode = function(string) {
|
||||||
|
|||||||
@@ -104,7 +104,7 @@ Handlebars.Runtime.prototype = {
|
|||||||
|
|
||||||
mustache: function(mustache) {
|
mustache: function(mustache) {
|
||||||
var idObj = this.ID(mustache.id);
|
var idObj = this.ID(mustache.id);
|
||||||
var params = mustache.params;
|
var params = mustache.params.slice(0);
|
||||||
var buf;
|
var buf;
|
||||||
|
|
||||||
for(var i=0, l=params.length; i<l; i++) {
|
for(var i=0, l=params.length; i<l; i++) {
|
||||||
|
|||||||
+18
-18
@@ -13,33 +13,32 @@ Handlebars.SafeString.prototype.toString = function() {
|
|||||||
return this.string.toString();
|
return this.string.toString();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
(function() {
|
||||||
|
var escape = {
|
||||||
|
"<": "<",
|
||||||
|
">": ">",
|
||||||
|
};
|
||||||
|
|
||||||
|
var badChars = /&(?!\w+;)|[<>]/g;
|
||||||
|
var possible = /[&<>]/
|
||||||
|
|
||||||
|
var escapeChar = function(chr) {
|
||||||
|
return escape[chr] || "&"
|
||||||
|
};
|
||||||
|
|
||||||
Handlebars.Utils = {
|
Handlebars.Utils = {
|
||||||
escapeExpression: function(string) {
|
escapeExpression: function(string) {
|
||||||
// don't escape SafeStrings, since they're already safe
|
// don't escape SafeStrings, since they're already safe
|
||||||
if (string instanceof Handlebars.SafeString) {
|
if (string instanceof Handlebars.SafeString) {
|
||||||
return string.toString();
|
return string.toString();
|
||||||
}
|
} else if (string === null) {
|
||||||
else if (string === null) {
|
|
||||||
string = "";
|
string = "";
|
||||||
}
|
}
|
||||||
|
|
||||||
return string.toString().replace(/&(?!\w+;)|["\\<>]/g, function(str) {
|
if(!possible.test(string)) { return string; }
|
||||||
switch(str) {
|
return string.replace(badChars, escapeChar);
|
||||||
case "&":
|
|
||||||
return "&";
|
|
||||||
case '"':
|
|
||||||
return "\"";
|
|
||||||
case "\\":
|
|
||||||
return "\\\\";
|
|
||||||
case "<":
|
|
||||||
return "<";
|
|
||||||
case ">":
|
|
||||||
return ">";
|
|
||||||
default:
|
|
||||||
return str;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
},
|
},
|
||||||
|
|
||||||
isEmpty: function(value) {
|
isEmpty: function(value) {
|
||||||
if (typeof value === "undefined") {
|
if (typeof value === "undefined") {
|
||||||
return true;
|
return true;
|
||||||
@@ -54,6 +53,7 @@ Handlebars.Utils = {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
})();
|
||||||
// END(BROWSER)
|
// END(BROWSER)
|
||||||
|
|
||||||
exports.Utils = Handlebars.Utils;
|
exports.Utils = Handlebars.Utils;
|
||||||
|
|||||||
+3
-3
@@ -7,7 +7,7 @@ Handlebars.registerHelper('helperMissing', function(helper, context) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
var shouldCompileTo = function(string, hash, expected, message) {
|
var shouldCompileTo = function(string, hash, expected, message) {
|
||||||
var template = Handlebars.compile(string);
|
var template = Handlebars.VM.compile(string);
|
||||||
if(Object.prototype.toString.call(hash) === "[object Array]") {
|
if(Object.prototype.toString.call(hash) === "[object Array]") {
|
||||||
if(hash[1]) {
|
if(hash[1]) {
|
||||||
for(var prop in Handlebars.helpers) {
|
for(var prop in Handlebars.helpers) {
|
||||||
@@ -80,7 +80,7 @@ test("escaping expressions", function() {
|
|||||||
shouldCompileTo("{{{awesome}}}", {awesome: "&\"\\<>"}, '&\"\\<>',
|
shouldCompileTo("{{{awesome}}}", {awesome: "&\"\\<>"}, '&\"\\<>',
|
||||||
"expressions with 3 handlebars aren't escaped");
|
"expressions with 3 handlebars aren't escaped");
|
||||||
|
|
||||||
shouldCompileTo("{{awesome}}", {awesome: "&\"\\<>"}, '&\"\\\\<>',
|
shouldCompileTo("{{awesome}}", {awesome: "&\"\\<>"}, '&\"\\<>',
|
||||||
"by default expressions should be escaped");
|
"by default expressions should be escaped");
|
||||||
|
|
||||||
shouldCompileTo("{{&awesome}}", {awesome: "&\"\\<>"}, '&\"\\<>',
|
shouldCompileTo("{{&awesome}}", {awesome: "&\"\\<>"}, '&\"\\<>',
|
||||||
@@ -452,7 +452,7 @@ test("block multi-params work", function() {
|
|||||||
var string = 'Message: {{#goodbye cruel world}}{{greeting}} {{adj}} {{noun}}{{/goodbye}}';
|
var string = 'Message: {{#goodbye cruel world}}{{greeting}} {{adj}} {{noun}}{{/goodbye}}';
|
||||||
var hash = {cruel: "cruel", world: "world"}
|
var hash = {cruel: "cruel", world: "world"}
|
||||||
var fallback = {goodbye: function(cruel, world, fn) {
|
var fallback = {goodbye: function(cruel, world, fn) {
|
||||||
return fn({greeting: "Goodbye", adj: "cruel", noun: "world"});
|
return fn({greeting: "Goodbye", adj: cruel, noun: world});
|
||||||
}}
|
}}
|
||||||
shouldCompileTo(string, [hash, fallback], "Message: Goodbye cruel world", "block helpers with multiple params");
|
shouldCompileTo(string, [hash, fallback], "Message: Goodbye cruel world", "block helpers with multiple params");
|
||||||
})
|
})
|
||||||
|
|||||||
+6
-1
@@ -54,10 +54,14 @@ module Handlebars
|
|||||||
context["exports"] = nil
|
context["exports"] = nil
|
||||||
|
|
||||||
context["p"] = proc do |val|
|
context["p"] = proc do |val|
|
||||||
p val
|
p val if ENV["DEBUG_JS"]
|
||||||
end
|
end
|
||||||
|
|
||||||
context["puts"] = proc do |val|
|
context["puts"] = proc do |val|
|
||||||
|
puts val if ENV["DEBUG_JS"]
|
||||||
|
end
|
||||||
|
|
||||||
|
context["puts_node"] = proc do |val|
|
||||||
puts context["Handlebars"]["PrintVisitor"].new.accept(val)
|
puts context["Handlebars"]["PrintVisitor"].new.accept(val)
|
||||||
puts
|
puts
|
||||||
end
|
end
|
||||||
@@ -76,6 +80,7 @@ module Handlebars
|
|||||||
Handlebars::Spec.js_load('lib/handlebars/printer.js')
|
Handlebars::Spec.js_load('lib/handlebars/printer.js')
|
||||||
Handlebars::Spec.js_load('lib/handlebars/runtime.js')
|
Handlebars::Spec.js_load('lib/handlebars/runtime.js')
|
||||||
Handlebars::Spec.js_load('lib/handlebars/utils.js')
|
Handlebars::Spec.js_load('lib/handlebars/utils.js')
|
||||||
|
Handlebars::Spec.js_load('lib/Handlebars/vm.js')
|
||||||
Handlebars::Spec.js_load('lib/handlebars.js')
|
Handlebars::Spec.js_load('lib/handlebars.js')
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user