diff options
Diffstat (limited to 'lib/ast.js')
-rw-r--r-- | lib/ast.js | 22 |
1 files changed, 19 insertions, 3 deletions
@@ -118,9 +118,25 @@ var AST_Node = DEFNODE("Node", "start end", { } }, null); -AST_Node.warn = function(txt, props) { - if (AST_Node.warn_function) AST_Node.warn_function(string_template(txt, props)); -}; +(AST_Node.log_function = function(fn, verbose) { + var printed = Object.create(null); + if (fn) { + AST_Node.info = verbose ? function(text, props) { + log("INFO: " + string_template(text, props)); + } : noop; + AST_Node.warn = function(text, props) { + log("WARN: " + string_template(text, props)); + }; + } else { + AST_Node.info = AST_Node.warn = noop; + } + + function log(msg) { + if (printed[msg]) return; + printed[msg] = true; + fn(msg); + } +})(); /* -----[ statements ]----- */ |