Comparing version 0.1.7 to 0.1.8
@@ -118,3 +118,7 @@ define("htmlbars-runtime", | ||
__exports__.simple = simple;function hydrationHooks(extensions) { | ||
__exports__.simple = simple;function set(context, name, value) { | ||
context[name] = value; | ||
} | ||
__exports__.set = set;function hydrationHooks(extensions) { | ||
var base = { | ||
@@ -130,3 +134,4 @@ content: content, | ||
simple: simple, | ||
partial: partial | ||
partial: partial, | ||
set: set | ||
}; | ||
@@ -133,0 +138,0 @@ |
@@ -901,14 +901,17 @@ "use strict"; | ||
registerHelper('a', function(params, hash, options, env) { | ||
var context = Object.create(this); | ||
var span = document.createElement('span'); | ||
span.appendChild(options.render(this, env, document.body, ['W', 'X1'])); | ||
span.appendChild(options.render(context, env, document.body, ['W', 'X1'])); | ||
return 'A(' + span.innerHTML + ')'; | ||
}); | ||
registerHelper('b', function(params, hash, options, env) { | ||
var context = Object.create(this); | ||
var span = document.createElement('span'); | ||
span.appendChild(options.render(this, env, document.body, ['X2', 'Y'])); | ||
span.appendChild(options.render(context, env, document.body, ['X2', 'Y'])); | ||
return 'B(' + span.innerHTML + ')'; | ||
}); | ||
registerHelper('c', function(params, hash, options, env) { | ||
var context = Object.create(this); | ||
var span = document.createElement('span'); | ||
span.appendChild(options.render(this, env, document.body, ['Z'])); | ||
span.appendChild(options.render(context, env, document.body, ['Z'])); | ||
return 'C(' + span.innerHTML + ')'; | ||
@@ -922,2 +925,18 @@ // return "C(" + options.render() + ")"; | ||
test("Block params - Helper should know how many block params it was called with", function() { | ||
expect(4); | ||
registerHelper('without-block-params', function(params, hash, options) { | ||
ok(!('blockParams' in options), 'Helpers should not be passed a blockParams option if not called with block params.'); | ||
}); | ||
registerHelper('with-block-params', function(params, hash, options) { | ||
equal(options.blockParams, this.count, 'Helpers should recieve the correct number of block params in options.blockParams.'); | ||
}); | ||
compile('{{#without-block-params}}{{/without-block-params}}')({}, env, document.body); | ||
compile('{{#with-block-params as |x|}}{{/with-block-params}}')({ count: 1 }, env, document.body); | ||
compile('{{#with-block-params as |x y|}}{{/with-block-params}}')({ count: 2 }, env, document.body); | ||
compile('{{#with-block-params as |x y z|}}{{/with-block-params}}')({ count: 3 }, env, document.body); | ||
}); | ||
if (document.createElement('div').namespaceURI) { | ||
@@ -924,0 +943,0 @@ |
@@ -33,6 +33,17 @@ "use strict"; | ||
[ "stackLiteral", [ 0 ] ], | ||
[ "helper", [ 0, 0 ] ] | ||
[ "helper", [ 0, 0, 0 ] ] | ||
]); | ||
}); | ||
test("simple block with block params", function() { | ||
var opcodes = opcodesFor("<div>{{#foo as |bar baz|}}{{/foo}}</div>"); | ||
deepEqual(opcodes, [ | ||
[ "morph", [ 0, [ 0 ], null, null, true ] ], | ||
[ "program", [ 0, null ] ], | ||
[ "id", [ [ "foo" ] ] ], | ||
[ "stackLiteral", [ 0 ] ], | ||
[ "helper", [ 0, 0, 2 ] ] | ||
]); | ||
}); | ||
test("element with a sole mustache child", function() { | ||
@@ -39,0 +50,0 @@ var opcodes = opcodesFor("<div>{{foo}}</div>"); |
@@ -25,3 +25,3 @@ "use strict"; | ||
actionsEqual(input, [ | ||
['startProgram', [0, [], {}]], | ||
['startProgram', [0, []]], | ||
['endProgram', [0]] | ||
@@ -34,3 +34,3 @@ ]); | ||
actionsEqual(input, [ | ||
['startProgram', [0, [], {}]], | ||
['startProgram', [0, []]], | ||
['text', [0, 3, false]], | ||
@@ -47,3 +47,3 @@ ['mustache', [1, 3]], | ||
actionsEqual(input, [ | ||
['startProgram', [0, [], {}]], | ||
['startProgram', [0, []]], | ||
['openElement', [0, 2, false, 0, []]], | ||
@@ -64,3 +64,3 @@ ['closeElement', [0, 2, false]], | ||
actionsEqual(input, [ | ||
['startProgram', [0, [], {}]], | ||
['startProgram', [0, []]], | ||
['openElement', [0, 1, true, 2, []]], | ||
@@ -86,5 +86,5 @@ ['openElement', [0, 2, false, 1, []]], | ||
actionsEqual(input, [ | ||
['startProgram', [0, [], {}]], | ||
['startProgram', [0, []]], | ||
['endProgram', [1]], | ||
['startProgram', [1, [0, 1], {}]], | ||
['startProgram', [1, [0, 1]]], | ||
['text', [0, 3, false]], | ||
@@ -100,8 +100,8 @@ ['block', [1, 3]], | ||
actionsEqual(input, [ | ||
['startProgram', [0, [], {}]], | ||
['startProgram', [0, []]], | ||
['endProgram', [1]], | ||
['startProgram', [0, [], {}]], | ||
['startProgram', [0, []]], | ||
['text', [0, 1, true]], | ||
['endProgram', [1]], | ||
['startProgram', [2, [0, 1], {}]], | ||
['startProgram', [2, [0, 1]]], | ||
['text', [0, 3, false]], | ||
@@ -117,6 +117,6 @@ ['block', [1, 3]], | ||
actionsEqual(input, [ | ||
['startProgram', [0, [], {}]], | ||
['startProgram', [0, []]], | ||
['text', [0, 1, true]], | ||
['endProgram', [1]], | ||
['startProgram', [0, [0, 1], {}]], | ||
['startProgram', [0, [0, 1]]], | ||
['text', [0, 3, false]], | ||
@@ -126,7 +126,7 @@ ['mustache', [1, 3]], | ||
['endProgram', [2]], | ||
['startProgram', [0, [], {}]], | ||
['startProgram', [0, []]], | ||
['openElement', [0, 1, true, 0, []]], | ||
['closeElement', [0, 1, true]], | ||
['endProgram', [2]], | ||
['startProgram', [2, [0, 1, 2], {}]], | ||
['startProgram', [2, [0, 1, 2]]], | ||
['text', [0, 5, false]], | ||
@@ -138,3 +138,3 @@ ['block', [1, 5]], | ||
['endProgram', [1]], | ||
['startProgram', [2, [0, 1, 2], {}]], | ||
['startProgram', [2, [0, 1, 2]]], | ||
['text', [0, 5, false]], | ||
@@ -152,6 +152,6 @@ ['block', [1, 5]], | ||
actionsEqual(input, [ | ||
['startProgram', [0, [], {}]], | ||
['startProgram', [0, []]], | ||
['text', [0, 1, true]], | ||
['endProgram', [1]], | ||
['startProgram', [1, [0, 1], {}]], | ||
['startProgram', [1, [0, 1]]], | ||
['text', [0, 3, false]], | ||
@@ -158,0 +158,0 @@ ['component', [1, 3]], |
@@ -35,5 +35,2 @@ "use strict"; | ||
var options = []; | ||
if (name !== null) { | ||
options.push('type:' + type); | ||
} | ||
options.push('paramTypes:' + array(paramTypes)); | ||
@@ -40,0 +37,0 @@ options.push('hashTypes:' + hash(hashTypes)); |
@@ -36,3 +36,3 @@ "use strict"; | ||
HydrationOpcodeCompiler.prototype.startProgram = function(program, c, blankChildTextNodes, scopeVars) { | ||
HydrationOpcodeCompiler.prototype.startProgram = function(program, c, blankChildTextNodes) { | ||
this.opcodes.length = 0; | ||
@@ -44,3 +44,2 @@ this.paths.length = 0; | ||
this.morphNum = 0; | ||
this.scopeVars = scopeVars; | ||
@@ -97,8 +96,11 @@ if (blankChildTextNodes.length > 0){ | ||
HydrationOpcodeCompiler.prototype.block = function(block, childIndex, childrenLength) { | ||
var currentDOMChildIndex = this.currentDOMChildIndex, | ||
sexpr = block.sexpr; | ||
var sexpr = block.sexpr; | ||
var program = block.program; | ||
var start = (currentDOMChildIndex < 0 ? null : currentDOMChildIndex), | ||
end = (childIndex === childrenLength - 1 ? null : currentDOMChildIndex + 1); | ||
var blockParamsLength = program && program.blockParams ? program.blockParams.length : 0; | ||
var currentDOMChildIndex = this.currentDOMChildIndex; | ||
var start = (currentDOMChildIndex < 0) ? null : currentDOMChildIndex; | ||
var end = (childIndex === childrenLength - 1) ? null : currentDOMChildIndex + 1; | ||
var morphNum = this.morphNum++; | ||
@@ -109,3 +111,3 @@ this.morphs.push([morphNum, this.paths.slice(), start, end, true]); | ||
processSexpr(this, sexpr); | ||
this.opcode('helper', sexpr.params.length, morphNum); | ||
this.opcode('helper', sexpr.params.length, morphNum, blockParamsLength); | ||
}; | ||
@@ -198,19 +200,4 @@ | ||
HydrationOpcodeCompiler.prototype.mustacheInAttr = function(mustache) { | ||
if (mustache.isHelper) { | ||
this.opcode('program', null, null); | ||
processSexpr(this, mustache); | ||
this.opcode('helperAttr', mustache.params.length); | ||
} else { | ||
this.ID(mustache.id); | ||
this.opcode('ambiguousAttr'); | ||
} | ||
}; | ||
HydrationOpcodeCompiler.prototype.ID = function(id) { | ||
if (id.parts.length > 0 && this.scopeVars[id.parts[0]]) { | ||
this.opcode('scopeId', id.parts); | ||
} else { | ||
this.opcode('id', id.parts); | ||
} | ||
this.opcode('id', id.parts); | ||
}; | ||
@@ -217,0 +204,0 @@ |
@@ -68,13 +68,2 @@ "use strict"; | ||
prototype.scopeId = function(parts) { | ||
this.stack.push(string('value')); | ||
var id = '$' + parts[0]; | ||
var path = parts.slice(1).join('.'); | ||
if (parts.length === 1) { | ||
this.stack.push(id); | ||
} else { | ||
this.stack.push('get(' + id + ', ' + string(path) + ')'); | ||
} | ||
}; | ||
prototype.literal = function(literal) { | ||
@@ -94,5 +83,8 @@ this.stack.push(string(typeof literal)); | ||
prototype.helper = function(size, morphNum) { | ||
prototype.helper = function(size, morphNum, blockParamsLength) { | ||
var prepared = prepareHelper(this.stack, size); | ||
prepared.options.push('morph:morph'+morphNum); | ||
if (blockParamsLength) { | ||
prepared.options.push('blockParams:'+blockParamsLength); | ||
} | ||
this.pushMustacheInContent(prepared.name, prepared.params, prepared.hash, prepared.options, morphNum); | ||
@@ -109,5 +101,4 @@ }; | ||
var name = this.stack.pop(); | ||
var type = this.stack.pop(); | ||
this.stack.pop(); | ||
var options = []; | ||
options.push('type:'+type); | ||
options.push('morph:morph'+morphNum); | ||
@@ -119,16 +110,5 @@ this.pushMustacheInContent(name, '[]', '{}', options, morphNum); | ||
var prepared = prepareHelper(this.stack, size); | ||
this.source.push(this.indent + 'hooks.attribute(element' + elementNum + ', ' + string(name) + ', ' + quoted + ', context, ' + prepared.params + ', ' + hash(prepared.options) + ', env);\n'); | ||
this.source.push(this.indent + ' hooks.attribute(element' + elementNum + ', ' + string(name) + ', ' + quoted + ', context, ' + prepared.params + ', ' + hash(prepared.options) + ', env);\n'); | ||
}; | ||
prototype.ambiguousAttr = function() { | ||
var name = this.stack.pop(); | ||
var type = this.stack.pop(); | ||
this.stack.push('[' + name + ', [], {}, { type: ' + type + ' }]'); | ||
}; | ||
prototype.helperAttr = function(size) { | ||
var prepared = prepareHelper(this.stack, size); | ||
this.stack.push('['+prepared.name+','+prepared.params+','+ prepared.hash +',' + hash(prepared.options)+']'); | ||
}; | ||
prototype.sexpr = function(size) { | ||
@@ -135,0 +115,0 @@ var prepared = prepareHelper(this.stack, size); |
@@ -22,3 +22,2 @@ "use strict"; | ||
this.mustacheCount = 0; | ||
this.scopeVars = null; | ||
this.actions = []; | ||
@@ -94,16 +93,3 @@ } | ||
var programFrame = this.pushFrame(); | ||
programFrame.scopeVars = {}; | ||
if (parentFrame && parentFrame.scopeVars) { | ||
for (var name in parentFrame.scopeVars) { | ||
programFrame.scopeVars[name] = true; | ||
} | ||
} | ||
if (program.blockParams) { | ||
for (var j = 0; j < program.blockParams.length; j++) { | ||
programFrame.scopeVars[program.blockParams[j]] = true; | ||
} | ||
} | ||
programFrame.parentNode = program; | ||
@@ -122,4 +108,3 @@ programFrame.children = program.statements; | ||
program, programFrame.childTemplateCount, | ||
programFrame.blankChildTextNodes.reverse(), | ||
programFrame.scopeVars | ||
programFrame.blankChildTextNodes.reverse() | ||
]]); | ||
@@ -126,0 +111,0 @@ this.popFrame(); |
@@ -8,2 +8,3 @@ "use strict"; | ||
var processOpcodes = require("./utils").processOpcodes; | ||
var string = require("./quoting").string; | ||
var repeat = require("./quoting").repeat; | ||
@@ -30,5 +31,5 @@ | ||
TemplateCompiler.prototype.startProgram = function(program, childTemplateCount, blankChildTextNodes, scopeVars) { | ||
this.fragmentOpcodeCompiler.startProgram(program, childTemplateCount, blankChildTextNodes, scopeVars); | ||
this.hydrationOpcodeCompiler.startProgram(program, childTemplateCount, blankChildTextNodes, scopeVars); | ||
TemplateCompiler.prototype.startProgram = function(program, childTemplateCount, blankChildTextNodes) { | ||
this.fragmentOpcodeCompiler.startProgram(program, childTemplateCount, blankChildTextNodes); | ||
this.hydrationOpcodeCompiler.startProgram(program, childTemplateCount, blankChildTextNodes); | ||
@@ -41,12 +42,2 @@ this.childTemplates.length = 0; | ||
TemplateCompiler.prototype.getScopeVars = function(indent, blockParams) { | ||
var vars = ''; | ||
if (blockParams) { | ||
for (var i = 0; i < blockParams.length; i++) { | ||
vars += indent + 'var $' + blockParams[i] + ';\n'; | ||
} | ||
} | ||
return vars; | ||
}; | ||
TemplateCompiler.prototype.getChildTemplateVars = function(indent) { | ||
@@ -62,7 +53,7 @@ var vars = ''; | ||
TemplateCompiler.prototype.getScopeAssignments = function(indent, blockParams) { | ||
TemplateCompiler.prototype.getContextAssignments = function(indent, blockParams) { | ||
var assignments = ''; | ||
if (blockParams) { | ||
for (var i = 0; i < blockParams.length; i++) { | ||
assignments += indent + '$' + blockParams[i] + ' = blockArguments[' + i + '];\n'; | ||
assignments += indent + 'hooks.set(context, ' + string(blockParams[i]) +', blockArguments[' + i + ']);\n'; | ||
} | ||
@@ -104,3 +95,2 @@ } | ||
'(function() {\n' + | ||
this.getScopeVars(indent + ' ', blockParams) + | ||
this.getChildTemplateVars(indent + ' ') + | ||
@@ -110,4 +100,4 @@ fragmentProgram + | ||
indent+' return function template(' + templateSignature + ') {\n' + | ||
indent+' var dom = env.dom, hooks = env.hooks, get = env.get;\n' + | ||
this.getScopeAssignments(indent + ' ', blockParams) + | ||
indent+' var dom = env.dom, hooks = env.hooks;\n' + | ||
this.getContextAssignments(indent + ' ', blockParams) + | ||
indent+' dom.detectNamespace(contextualElement);\n' + | ||
@@ -114,0 +104,0 @@ indent+' if (cachedFragment === undefined) {\n' + |
@@ -17,3 +17,16 @@ "use strict"; | ||
test("hooks are present", function () { | ||
var hookNames = ["content", "component", "componentFallback", "element", "attribute", "concat", "partial", "subexpr", "lookupHelper", "simple", "hydrationHooks"]; | ||
var hookNames = [ | ||
"content", | ||
"component", | ||
"componentFallback", | ||
"element", | ||
"attribute", | ||
"concat", | ||
"partial", | ||
"subexpr", | ||
"lookupHelper", | ||
"simple", | ||
"hydrationHooks", | ||
"set" | ||
]; | ||
for (var i=0;i<hookNames.length;i++) { | ||
@@ -20,0 +33,0 @@ ok(hooks[hookNames[i]], "hook "+hookNames[i]+" is present"); |
@@ -107,3 +107,7 @@ "use strict"; | ||
exports.simple = simple;function hydrationHooks(extensions) { | ||
exports.simple = simple;function set(context, name, value) { | ||
context[name] = value; | ||
} | ||
exports.set = set;function hydrationHooks(extensions) { | ||
var base = { | ||
@@ -119,3 +123,4 @@ content: content, | ||
simple: simple, | ||
partial: partial | ||
partial: partial, | ||
set: set | ||
}; | ||
@@ -122,0 +127,0 @@ |
@@ -7,3 +7,3 @@ "use strict"; | ||
* See https://raw.githubusercontent.com/tildeio/htmlbars/master/LICENSE | ||
* @version 0.1.6 | ||
* @version 0.1.8 | ||
*/ | ||
@@ -10,0 +10,0 @@ |
@@ -33,5 +33,2 @@ import { array, hash } from "./quoting"; | ||
var options = []; | ||
if (name !== null) { | ||
options.push('type:' + type); | ||
} | ||
options.push('paramTypes:' + array(paramTypes)); | ||
@@ -38,0 +35,0 @@ options.push('hashTypes:' + hash(hashTypes)); |
@@ -35,3 +35,3 @@ import TemplateVisitor from "./template_visitor"; | ||
HydrationOpcodeCompiler.prototype.startProgram = function(program, c, blankChildTextNodes, scopeVars) { | ||
HydrationOpcodeCompiler.prototype.startProgram = function(program, c, blankChildTextNodes) { | ||
this.opcodes.length = 0; | ||
@@ -43,3 +43,2 @@ this.paths.length = 0; | ||
this.morphNum = 0; | ||
this.scopeVars = scopeVars; | ||
@@ -96,8 +95,11 @@ if (blankChildTextNodes.length > 0){ | ||
HydrationOpcodeCompiler.prototype.block = function(block, childIndex, childrenLength) { | ||
var currentDOMChildIndex = this.currentDOMChildIndex, | ||
sexpr = block.sexpr; | ||
var sexpr = block.sexpr; | ||
var program = block.program; | ||
var start = (currentDOMChildIndex < 0 ? null : currentDOMChildIndex), | ||
end = (childIndex === childrenLength - 1 ? null : currentDOMChildIndex + 1); | ||
var blockParamsLength = program && program.blockParams ? program.blockParams.length : 0; | ||
var currentDOMChildIndex = this.currentDOMChildIndex; | ||
var start = (currentDOMChildIndex < 0) ? null : currentDOMChildIndex; | ||
var end = (childIndex === childrenLength - 1) ? null : currentDOMChildIndex + 1; | ||
var morphNum = this.morphNum++; | ||
@@ -108,3 +110,3 @@ this.morphs.push([morphNum, this.paths.slice(), start, end, true]); | ||
processSexpr(this, sexpr); | ||
this.opcode('helper', sexpr.params.length, morphNum); | ||
this.opcode('helper', sexpr.params.length, morphNum, blockParamsLength); | ||
}; | ||
@@ -197,19 +199,4 @@ | ||
HydrationOpcodeCompiler.prototype.mustacheInAttr = function(mustache) { | ||
if (mustache.isHelper) { | ||
this.opcode('program', null, null); | ||
processSexpr(this, mustache); | ||
this.opcode('helperAttr', mustache.params.length); | ||
} else { | ||
this.ID(mustache.id); | ||
this.opcode('ambiguousAttr'); | ||
} | ||
}; | ||
HydrationOpcodeCompiler.prototype.ID = function(id) { | ||
if (id.parts.length > 0 && this.scopeVars[id.parts[0]]) { | ||
this.opcode('scopeId', id.parts); | ||
} else { | ||
this.opcode('id', id.parts); | ||
} | ||
this.opcode('id', id.parts); | ||
}; | ||
@@ -216,0 +203,0 @@ |
@@ -65,13 +65,2 @@ import { processOpcodes } from "./utils"; | ||
prototype.scopeId = function(parts) { | ||
this.stack.push(string('value')); | ||
var id = '$' + parts[0]; | ||
var path = parts.slice(1).join('.'); | ||
if (parts.length === 1) { | ||
this.stack.push(id); | ||
} else { | ||
this.stack.push('get(' + id + ', ' + string(path) + ')'); | ||
} | ||
}; | ||
prototype.literal = function(literal) { | ||
@@ -91,5 +80,8 @@ this.stack.push(string(typeof literal)); | ||
prototype.helper = function(size, morphNum) { | ||
prototype.helper = function(size, morphNum, blockParamsLength) { | ||
var prepared = prepareHelper(this.stack, size); | ||
prepared.options.push('morph:morph'+morphNum); | ||
if (blockParamsLength) { | ||
prepared.options.push('blockParams:'+blockParamsLength); | ||
} | ||
this.pushMustacheInContent(prepared.name, prepared.params, prepared.hash, prepared.options, morphNum); | ||
@@ -106,5 +98,4 @@ }; | ||
var name = this.stack.pop(); | ||
var type = this.stack.pop(); | ||
this.stack.pop(); | ||
var options = []; | ||
options.push('type:'+type); | ||
options.push('morph:morph'+morphNum); | ||
@@ -116,16 +107,5 @@ this.pushMustacheInContent(name, '[]', '{}', options, morphNum); | ||
var prepared = prepareHelper(this.stack, size); | ||
this.source.push(this.indent + 'hooks.attribute(element' + elementNum + ', ' + string(name) + ', ' + quoted + ', context, ' + prepared.params + ', ' + hash(prepared.options) + ', env);\n'); | ||
this.source.push(this.indent + ' hooks.attribute(element' + elementNum + ', ' + string(name) + ', ' + quoted + ', context, ' + prepared.params + ', ' + hash(prepared.options) + ', env);\n'); | ||
}; | ||
prototype.ambiguousAttr = function() { | ||
var name = this.stack.pop(); | ||
var type = this.stack.pop(); | ||
this.stack.push('[' + name + ', [], {}, { type: ' + type + ' }]'); | ||
}; | ||
prototype.helperAttr = function(size) { | ||
var prepared = prepareHelper(this.stack, size); | ||
this.stack.push('['+prepared.name+','+prepared.params+','+ prepared.hash +',' + hash(prepared.options)+']'); | ||
}; | ||
prototype.sexpr = function(size) { | ||
@@ -132,0 +112,0 @@ var prepared = prepareHelper(this.stack, size); |
@@ -21,3 +21,2 @@ var push = Array.prototype.push; | ||
this.mustacheCount = 0; | ||
this.scopeVars = null; | ||
this.actions = []; | ||
@@ -93,16 +92,3 @@ } | ||
var programFrame = this.pushFrame(); | ||
programFrame.scopeVars = {}; | ||
if (parentFrame && parentFrame.scopeVars) { | ||
for (var name in parentFrame.scopeVars) { | ||
programFrame.scopeVars[name] = true; | ||
} | ||
} | ||
if (program.blockParams) { | ||
for (var j = 0; j < program.blockParams.length; j++) { | ||
programFrame.scopeVars[program.blockParams[j]] = true; | ||
} | ||
} | ||
programFrame.parentNode = program; | ||
@@ -121,4 +107,3 @@ programFrame.children = program.statements; | ||
program, programFrame.childTemplateCount, | ||
programFrame.blankChildTextNodes.reverse(), | ||
programFrame.scopeVars | ||
programFrame.blankChildTextNodes.reverse() | ||
]]); | ||
@@ -125,0 +110,0 @@ this.popFrame(); |
@@ -7,3 +7,3 @@ import { FragmentOpcodeCompiler } from './fragment_opcode'; | ||
import { processOpcodes } from "./utils"; | ||
import { repeat } from "./quoting"; | ||
import { string, repeat } from "./quoting"; | ||
@@ -29,5 +29,5 @@ export function TemplateCompiler(options) { | ||
TemplateCompiler.prototype.startProgram = function(program, childTemplateCount, blankChildTextNodes, scopeVars) { | ||
this.fragmentOpcodeCompiler.startProgram(program, childTemplateCount, blankChildTextNodes, scopeVars); | ||
this.hydrationOpcodeCompiler.startProgram(program, childTemplateCount, blankChildTextNodes, scopeVars); | ||
TemplateCompiler.prototype.startProgram = function(program, childTemplateCount, blankChildTextNodes) { | ||
this.fragmentOpcodeCompiler.startProgram(program, childTemplateCount, blankChildTextNodes); | ||
this.hydrationOpcodeCompiler.startProgram(program, childTemplateCount, blankChildTextNodes); | ||
@@ -40,12 +40,2 @@ this.childTemplates.length = 0; | ||
TemplateCompiler.prototype.getScopeVars = function(indent, blockParams) { | ||
var vars = ''; | ||
if (blockParams) { | ||
for (var i = 0; i < blockParams.length; i++) { | ||
vars += indent + 'var $' + blockParams[i] + ';\n'; | ||
} | ||
} | ||
return vars; | ||
}; | ||
TemplateCompiler.prototype.getChildTemplateVars = function(indent) { | ||
@@ -61,7 +51,7 @@ var vars = ''; | ||
TemplateCompiler.prototype.getScopeAssignments = function(indent, blockParams) { | ||
TemplateCompiler.prototype.getContextAssignments = function(indent, blockParams) { | ||
var assignments = ''; | ||
if (blockParams) { | ||
for (var i = 0; i < blockParams.length; i++) { | ||
assignments += indent + '$' + blockParams[i] + ' = blockArguments[' + i + '];\n'; | ||
assignments += indent + 'hooks.set(context, ' + string(blockParams[i]) +', blockArguments[' + i + ']);\n'; | ||
} | ||
@@ -103,3 +93,2 @@ } | ||
'(function() {\n' + | ||
this.getScopeVars(indent + ' ', blockParams) + | ||
this.getChildTemplateVars(indent + ' ') + | ||
@@ -109,4 +98,4 @@ fragmentProgram + | ||
indent+' return function template(' + templateSignature + ') {\n' + | ||
indent+' var dom = env.dom, hooks = env.hooks, get = env.get;\n' + | ||
this.getScopeAssignments(indent + ' ', blockParams) + | ||
indent+' var dom = env.dom, hooks = env.hooks;\n' + | ||
this.getContextAssignments(indent + ' ', blockParams) + | ||
indent+' dom.detectNamespace(contextualElement);\n' + | ||
@@ -113,0 +102,0 @@ indent+' if (cachedFragment === undefined) {\n' + |
@@ -106,2 +106,6 @@ import { merge } from "./utils"; | ||
export function set(context, name, value) { | ||
context[name] = value; | ||
} | ||
export function hydrationHooks(extensions) { | ||
@@ -118,3 +122,4 @@ var base = { | ||
simple: simple, | ||
partial: partial | ||
partial: partial, | ||
set: set | ||
}; | ||
@@ -121,0 +126,0 @@ |
@@ -6,3 +6,3 @@ /* | ||
* See https://raw.githubusercontent.com/tildeio/htmlbars/master/LICENSE | ||
* @version 0.1.6 | ||
* @version 0.1.8 | ||
*/ | ||
@@ -9,0 +9,0 @@ |
@@ -47,3 +47,16 @@ define("htmlbars-runtime-tests/htmlbars-runtime.jshint", | ||
test("hooks are present", function () { | ||
var hookNames = ["content", "component", "componentFallback", "element", "attribute", "concat", "partial", "subexpr", "lookupHelper", "simple", "hydrationHooks"]; | ||
var hookNames = [ | ||
"content", | ||
"component", | ||
"componentFallback", | ||
"element", | ||
"attribute", | ||
"concat", | ||
"partial", | ||
"subexpr", | ||
"lookupHelper", | ||
"simple", | ||
"hydrationHooks", | ||
"set" | ||
]; | ||
for (var i=0;i<hookNames.length;i++) { | ||
@@ -50,0 +63,0 @@ ok(hooks[hookNames[i]], "hook "+hookNames[i]+" is present"); |
var packagesConfig = { | ||
"version": "0.1.6", | ||
"revision": "79f55657e56c3864659193b00fff6bd8618c4137", | ||
"version": "0.1.8", | ||
"revision": "f51212aa645b417ad70c05ff04e0edf8fa6ae6a3", | ||
"vendored": {}, | ||
@@ -5,0 +5,0 @@ "dependencies": { |
{ | ||
"name": "htmlbars", | ||
"version": "0.1.7", | ||
"version": "0.1.8", | ||
"description": "HTMLBars compiles Handlebars templates into document fragments rather than string buffers", | ||
@@ -5,0 +5,0 @@ "main": "dist/cjs/htmlbars.js", |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1156385
34280