handle empty strings in compiler.

This commit is contained in:
Christopher Jeffrey 2013-02-24 19:20:56 -06:00
parent 7a7bc00777
commit 13a4f59ef6
2 changed files with 8 additions and 1 deletions

View File

@ -2,7 +2,7 @@ var Tput = require('../').Tput;
var tput = Tput({
term: process.argv[2] || 'xterm',
extended: false,
extended: !!~process.argv.indexOf('--extended'),
debug: true
});

View File

@ -452,6 +452,10 @@ Tput.prototype._compile = function(val) {
return function() {};
}
//if (!val) {
// return noop;
//}
var code = 'var v, dyn = {}, stat = {}, stack = [], out = [];'
, buff = ''
, cap;
@ -837,6 +841,7 @@ Tput.prototype._compile = function(val) {
stmt(';return out.join("");');
// TODO: Make this less ridiculous.
// Optimize
// ... out.push("foo");return out.join("");
// To:
@ -844,6 +849,8 @@ Tput.prototype._compile = function(val) {
v = code.split(/out = \[\];out\.push\(|\);return out/);
if (v.length === 3 && /^"[^"]+"$/.test(v[1])) {
code = 'return ' + v[1] + ';';
} else if (~code.indexOf('out = [];;return')) {
code = 'return "";';
}
if (this.debug) {