react / wstein / node_modules / jest-cli / node_modules / istanbul / node_modules / handlebars / dist / amd / handlebars / compiler / visitor.js
80738 viewsdefine(1["../exception","./ast","exports"],2function(__dependency1__, __dependency2__, __exports__) {3"use strict";4var Exception = __dependency1__["default"];5var AST = __dependency2__["default"];67function Visitor() {8this.parents = [];9}1011Visitor.prototype = {12constructor: Visitor,13mutating: false,1415// Visits a given value. If mutating, will replace the value if necessary.16acceptKey: function(node, name) {17var value = this.accept(node[name]);18if (this.mutating) {19// Hacky sanity check:20if (value && (!value.type || !AST[value.type])) {21throw new Exception('Unexpected node type "' + value.type + '" found when accepting ' + name + ' on ' + node.type);22}23node[name] = value;24}25},2627// Performs an accept operation with added sanity check to ensure28// required keys are not removed.29acceptRequired: function(node, name) {30this.acceptKey(node, name);3132if (!node[name]) {33throw new Exception(node.type + ' requires ' + name);34}35},3637// Traverses a given array. If mutating, empty respnses will be removed38// for child elements.39acceptArray: function(array) {40for (var i = 0, l = array.length; i < l; i++) {41this.acceptKey(array, i);4243if (!array[i]) {44array.splice(i, 1);45i--;46l--;47}48}49},5051accept: function(object) {52if (!object) {53return;54}5556if (this.current) {57this.parents.unshift(this.current);58}59this.current = object;6061var ret = this[object.type](object);6263this.current = this.parents.shift();6465if (!this.mutating || ret) {66return ret;67} else if (ret !== false) {68return object;69}70},7172Program: function(program) {73this.acceptArray(program.body);74},7576MustacheStatement: function(mustache) {77this.acceptRequired(mustache, 'path');78this.acceptArray(mustache.params);79this.acceptKey(mustache, 'hash');80},8182BlockStatement: function(block) {83this.acceptRequired(block, 'path');84this.acceptArray(block.params);85this.acceptKey(block, 'hash');8687this.acceptKey(block, 'program');88this.acceptKey(block, 'inverse');89},9091PartialStatement: function(partial) {92this.acceptRequired(partial, 'name');93this.acceptArray(partial.params);94this.acceptKey(partial, 'hash');95},9697ContentStatement: function(/* content */) {},98CommentStatement: function(/* comment */) {},99100SubExpression: function(sexpr) {101this.acceptRequired(sexpr, 'path');102this.acceptArray(sexpr.params);103this.acceptKey(sexpr, 'hash');104},105PartialExpression: function(partial) {106this.acceptRequired(partial, 'name');107this.acceptArray(partial.params);108this.acceptKey(partial, 'hash');109},110111PathExpression: function(/* path */) {},112113StringLiteral: function(/* string */) {},114NumberLiteral: function(/* number */) {},115BooleanLiteral: function(/* bool */) {},116117Hash: function(hash) {118this.acceptArray(hash.pairs);119},120HashPair: function(pair) {121this.acceptRequired(pair, 'value');122}123};124125__exports__["default"] = Visitor;126});127128