handle empty strings in compiler.
This commit is contained in:
parent
7a7bc00777
commit
13a4f59ef6
|
@ -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
|
||||
});
|
||||
|
||||
|
|
|
@ -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) {
|
||||
|
|
Loading…
Reference in New Issue