/*\ title: js/JavaScriptParseTree.js This object stores a JavaScript parse tree in the format produced by the pegjs JavaScript parser. The parse tree represents the syntactical structure of a JavaScript program, represented as a tree structure built from JavaScript arrays and objects. The nodes of the tree are objects with a "type" field that indicates the type of the node (see the function renderNode() for a list of the types). Depending on the type, other fields provide further details about the node. The pegjs parser uses "StringLiteral" nodes to represent individual string literals. TiddlyWiki adds support for nodes of type "StringLiterals" that represent a contiguous sequence of string constants. This simplifies coalescing adjacent constants into a single string. \*/ (function(){ /*jslint node: true */ "use strict"; var utils = require("./Utils.js"); // Create a new JavaScript tree object var JavaScriptParseTree = function(tree) { this.tree = tree; }; // Render the entire JavaScript tree object to JavaScript source code JavaScriptParseTree.prototype.render = function() { var output = []; if(this.tree instanceof Array) { this.renderSubTree(output,this.tree); } else { this.renderNode(output,this.tree); } var r = output.join(""); return r; }; // Render a subtree of the parse tree to an array of fragments of JavaScript source code JavaScriptParseTree.prototype.renderSubTree = function(output,tree) { for(var t=0; t