Skip to content

Commit

Permalink
[Ready for merge] bugfix: util.inspect returns a string and obscure…
Browse files Browse the repository at this point in the history
…s some errors (#306)

* bugfix: `util.inspect` returns a string and obscures some errors

* Fix toffee tests

* Fix stylus tests

* Fix myth tests

* Fix jade tests

* Fix swig tests

* Fix dot tests

* Fix eco tests

* Fix csso tests

* Fix scss tests

* Fix for Yarn tests
  • Loading branch information
davej authored and jescalan committed Apr 20, 2017
1 parent 2476b00 commit f245de9
Show file tree
Hide file tree
Showing 22 changed files with 67 additions and 72 deletions.
3 changes: 2 additions & 1 deletion test/fixtures/csso/expected/basic.css
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
/*! keep this comment */.hello{margin:0;color:silver;border:1px solid}
/*! keep this comment */
.hello{margin:0;color:silver;border:1px solid}
2 changes: 1 addition & 1 deletion test/fixtures/csso/expected/opts.css
Original file line number Diff line number Diff line change
@@ -1 +1 @@
.hello{color:red}.hello{padding:10px}
.hello{color:red}.hello{padding:10px}
2 changes: 1 addition & 1 deletion test/fixtures/csso/expected/string.css
Original file line number Diff line number Diff line change
@@ -1 +1 @@
.hello{foo:bar;color:green}
.hello{foo:bar;color:green}
2 changes: 1 addition & 1 deletion test/fixtures/dot/expected/partial.html
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<div>Jake</div><div>Jake who?</div>
<div>Jake</div><div>31</div>
2 changes: 1 addition & 1 deletion test/fixtures/dot/expected/precompile.html
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<p>welcome to pen island</p><p>wow opts</p>
<p>precompilez</p><p>wow opts</p>
78 changes: 36 additions & 42 deletions test/fixtures/eco/expected/client.html
Original file line number Diff line number Diff line change
@@ -1,49 +1,43 @@
function (__obj) {
if (!__obj) __obj = {};
var __out = [], __capture = function(callback) {
var out = __out, result;
__out = [];
callback.call(this);
result = __out.join('');
__out = out;
return __safe(result);
}, __sanitize = function(value) {
if (value && value.ecoSafe) {
return value;
} else if (typeof value !== 'undefined' && value != null) {
return __escape(value);
} else {
return '';
}
}, __safe, __objSafe = __obj.safe, __escape = __obj.escape;
__safe = __obj.safe = function(value) {
if (value && value.ecoSafe) {
return value;
} else {
if (!(typeof value !== 'undefined' && value != null)) value = '';
var result = new String(value);
result.ecoSafe = true;
return result;
}
module.exports = function(__obj) {
var _safe = function(value) {
if (typeof value === 'undefined' && value == null)
value = '';
var result = new String(value);
result.ecoSafe = true;
return result;
};
if (!__escape) {
__escape = __obj.escape = function(value) {
return ('' + value)
.replace(/&/g, '&amp;')
.replace(/</g, '&lt;')
.replace(/>/g, '&gt;')
.replace(/"/g, '&quot;');
return (function() {
var __out = [], __self = this, _print = function(value) {
if (typeof value !== 'undefined' && value != null)
__out.push(value.ecoSafe ? value : __self.escape(value));
}, _capture = function(callback) {
var out = __out, result;
__out = [];
callback.call(this);
result = __out.join('');
__out = out;
return _safe(result);
};
}
(function() {
(function() {
__out.push('Woah look, a ');
_print(_safe('Woah look, a '));

__out.push(__sanitize(thing));
_print(thing);

}).call(this);

}).call(__obj);
__obj.safe = __objSafe, __obj.escape = __escape;
return __out.join('');
}
return __out.join('');
}).call((function() {
var obj = {
escape: function(value) {
return ('' + value)
.replace(/&/g, '&amp;')
.replace(/</g, '&lt;')
.replace(/>/g, '&gt;')
.replace(/"/g, '&quot;');
},
safe: _safe
}, key;
for (key in __obj) obj[key] = __obj[key];
return obj;
})());
};
12 changes: 5 additions & 7 deletions test/fixtures/eco/expected/cstring.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,12 @@
return _safe(result);
};
(function() {
_print(_safe('<p>precompilez</p><p>'));

_print(this.foo);

_print(_safe('</p>'));

_print(_safe('Woah look, a '));

_print(thing);

}).call(this);

return __out.join('');
}).call((function() {
var obj = {
Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/eco/expected/rstring.html
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<p>ejs yah</p><p>wow opts</p>
<p>eco yah</p><p>wow opts</p>
4 changes: 2 additions & 2 deletions test/fixtures/jade/expected/cstring.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
var jade_mixins = {};
var jade_interp;
;var locals_for_with = (locals || {});(function (foo) {
buf.push("<p>look at my browser-compatibility</p><p>" + (jade.escape(null == (jade_interp = foo) ? "" : jade_interp)) + "</p>");}.call(this,"foo" in locals_for_with?locals_for_with.foo:typeof foo!=="undefined"?foo:undefined));;return buf.join("");
}
buf.push("<p>imma firin mah lazer!</p><p>" + (jade.escape(null == (jade_interp = foo) ? "" : jade_interp)) + "</p>");}.call(this,"foo" in locals_for_with?locals_for_with.foo:typeof foo!=="undefined"?foo:undefined));;return buf.join("");
}
2 changes: 1 addition & 1 deletion test/fixtures/scss/expected/basic.css
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.test {
content: 'bar'; }
content: "bar"; }
.test .foo {
color: blue; }
2 changes: 1 addition & 1 deletion test/fixtures/scss/expected/external.css
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
.foo {
color: 'red'; }
color: "red"; }
2 changes: 1 addition & 1 deletion test/fixtures/scss/expected/string.css
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
foo {
bar: 'red'; }
bar: "red"; }
4 changes: 2 additions & 2 deletions test/fixtures/stylus/expected/embedurl-opts.css

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion test/fixtures/stylus/expected/embedurl.css

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions test/fixtures/stylus/expected/include_css.css
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
.foo {
color: green;
}

.red {
color: #00f;
}
2 changes: 1 addition & 1 deletion test/fixtures/stylus/expected/rawdefine.css
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
.testing {
background-color: #0000BB
background-color: #0000FF;
}
2 changes: 1 addition & 1 deletion test/fixtures/stylus/rawdefine.styl
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
.testing
background-color: rdefine.blue1
background-color: unquote(rdefine.blue1)
7 changes: 4 additions & 3 deletions test/fixtures/swig/expected/client-complex.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion test/fixtures/toffee/expected/basic.html
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<li>mop</li><li>trashbin</li><li>flashlight</li>
<li>mop</li><li>trash bin</li><li>flashlight</li>
2 changes: 1 addition & 1 deletion test/fixtures/toffee/expected/my_templates-2.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
var toffee;("undefined"==typeof toffee||null===toffee)&&(toffee={}),toffee.templates||(toffee.templates={}),toffee.states={TOFFEE:1,COFFEE:2},toffee.__json=function(e,t){return null==t?"null":""+JSON.stringify(t).replace(/</g,"\\u003C").replace(/>/g,"\\u003E").replace(/&/g,"\\u0026")},toffee.__raw=function(e,t){return t},toffee.__html=function(e,t){return(""+t).replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;")},toffee.__escape=function(e,t){var f;return f=null!=e.__toffee.autoEscape?e.__toffee.autoEscape:!0,f?void 0===t?"":null!=t&&"object"==typeof t?e.json(t):e.html(t):t},toffee.__augmentLocals=function(e,t){var f,n;return f=e,n=f.__toffee={out:[]},null==f.print&&(f.print=function(e){return toffee.__print(f,e)}),null==f.json&&(f.json=function(e){return toffee.__json(f,e)}),null==f.raw&&(f.raw=function(e){return toffee.__raw(f,e)}),null==f.html&&(f.html=function(e){return toffee.__html(f,e)}),null==f.escape&&(f.escape=function(e){return toffee.__escape(f,e)}),null==f.partial&&(f.partial=function(e,n){return toffee.__partial(toffee.templates[""+t],f,e,n)}),null==f.snippet&&(f.snippet=function(e,n){return toffee.__snippet(toffee.templates[""+t],f,e,n)}),null==f.load&&(f.load=function(e,n){return toffee.__load(toffee.templates[""+t],f,e,n)}),n.print=f.print,n.json=f.json,n.raw=f.raw,n.html=f.html,n.escape=f.escape,n.partial=f.partial,n.snippet=f.snippet,n.load=f.load},toffee.__print=function(e,t){return e.__toffee.state===toffee.states.COFFEE?(e.__toffee.out.push(t),""):""+t},toffee.__normalize=function(e){var t,f,n,o,l;if(null==e||"/"===e)return e;for(l=e.split("/"),n=[],l[0]&&n.push(""),t=0,f=l.length;f>t;t++)o=l[t],".."===o?n.length>1?n.pop():n.push(o):"."!==o&&n.push(o);return e=n.join("/"),e||(e="/"),e},toffee.__partial=function(e,t,f,n){return f=toffee.__normalize(e.bundlePath+"/../"+f),toffee.__inlineInclude(f,n,t)},toffee.__snippet=function(e,t,f,n){return f=toffee.__normalize(e.bundlePath+"/../"+f),n=null!=n?n:{},n.__toffee=n.__toffee||{},n.__toffee.noInheritance=!0,toffee.__inlineInclude(f,n,t)},toffee.__load=function(e,t,f,n){return f=toffee.__normalize(e.bundlePath+"/../"+f),n=null!=n?n:{},n.__toffee=n.__toffee||{},n.__toffee.repress=!0,toffee.__inlineInclude(f,n,t)},toffee.__inlineInclude=function(e,t,f){var n,o,l,r,u,_,a,i,p;for(r=t||{},r.passback={},r.__toffee=r.__toffee||{},i={},u=["passback","load","print","partial","snippet","layout","__toffee","postProcess"],n=0,l=u.length;l>n;n++)o=u[n],i[o]=!0;if(!r.__toffee.noInheritance)for(o in f)p=f[o],null==(null!=t?t[o]:void 0)&&null==i[o]&&(r[o]=p);if(toffee.templates[e]){a=toffee.templates[e].pub(r),_=r.passback;for(o in _)p=_[o],f[o]=p;return a}return"Inline toffee include: Could not find "+e};
var toffee;"undefined"!=typeof toffee&&null!==toffee||(toffee={}),toffee.templates||(toffee.templates={}),toffee.states={TOFFEE:1,COFFEE:2},toffee.__json=function(e,t){return null==t?"null":""+JSON.stringify(t).replace(/</g,"\\u003C").replace(/>/g,"\\u003E").replace(/&/g,"\\u0026")},toffee.__raw=function(e,t){return t},toffee.__html=function(e,t){return(""+t).replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;")},toffee.__escape=function(e,t){var f;return f=null==e.__toffee.autoEscape||e.__toffee.autoEscape,f?void 0===t?"":null!=t&&"object"==typeof t?e.json(t):e.html(t):t},toffee.__augmentLocals=function(e,t){var f,n;return f=e,n=f.__toffee={out:[]},null==f.print&&(f.print=function(e){return toffee.__print(f,e)}),null==f.json&&(f.json=function(e){return toffee.__json(f,e)}),null==f.raw&&(f.raw=function(e){return toffee.__raw(f,e)}),null==f.html&&(f.html=function(e){return toffee.__html(f,e)}),null==f.escape&&(f.escape=function(e){return toffee.__escape(f,e)}),null==f.partial&&(f.partial=function(e,n){return toffee.__partial(toffee.templates[""+t],f,e,n)}),null==f.snippet&&(f.snippet=function(e,n){return toffee.__snippet(toffee.templates[""+t],f,e,n)}),null==f.load&&(f.load=function(e,n){return toffee.__load(toffee.templates[""+t],f,e,n)}),n.print=f.print,n.json=f.json,n.raw=f.raw,n.html=f.html,n.escape=f.escape,n.partial=f.partial,n.snippet=f.snippet,n.load=f.load},toffee.__print=function(e,t){return e.__toffee.state===toffee.states.COFFEE?(e.__toffee.out.push(t),""):""+t},toffee.__normalize=function(e){var t,f,n,o,l;if(null==e||"/"===e)return e;for(l=e.split("/"),n=[],l[0]&&n.push(""),t=0,f=l.length;t<f;t++)o=l[t],".."===o?n.length>1?n.pop():n.push(o):"."!==o&&n.push(o);return e=n.join("/"),e||(e="/"),e},toffee.__partial=function(e,t,f,n){return f=toffee.__normalize(e.bundlePath+"/../"+f),toffee.__inlineInclude(f,n,t)},toffee.__snippet=function(e,t,f,n){return f=toffee.__normalize(e.bundlePath+"/../"+f),n=null!=n?n:{},n.__toffee=n.__toffee||{},n.__toffee.noInheritance=!0,toffee.__inlineInclude(f,n,t)},toffee.__load=function(e,t,f,n){return f=toffee.__normalize(e.bundlePath+"/../"+f),n=null!=n?n:{},n.__toffee=n.__toffee||{},n.__toffee.repress=!0,toffee.__inlineInclude(f,n,t)},toffee.__inlineInclude=function(e,t,f){var n,o,l,r,u,_,a,i,p;for(r=t||{},r.passback={},r.__toffee=r.__toffee||{},i={},u=["passback","load","print","partial","snippet","layout","__toffee","postProcess"],n=0,l=u.length;n<l;n++)o=u[n],i[o]=!0;if(!r.__toffee.noInheritance)for(o in f)p=f[o],null==(null!=t?t[o]:void 0)&&null==i[o]&&(r[o]=p);if(toffee.templates[e]){a=toffee.templates[e].pub(r),_=r.passback;for(o in _)p=_[o],f[o]=p;return a}return"Inline toffee include: Could not find "+e};
;
(function() {
var tmpl;
Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/toffee/expected/my_templates.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
var toffee;("undefined"==typeof toffee||null===toffee)&&(toffee={}),toffee.templates||(toffee.templates={}),toffee.states={TOFFEE:1,COFFEE:2},toffee.__json=function(e,t){return null==t?"null":""+JSON.stringify(t).replace(/</g,"\\u003C").replace(/>/g,"\\u003E").replace(/&/g,"\\u0026")},toffee.__raw=function(e,t){return t},toffee.__html=function(e,t){return(""+t).replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;")},toffee.__escape=function(e,t){var f;return f=null!=e.__toffee.autoEscape?e.__toffee.autoEscape:!0,f?void 0===t?"":null!=t&&"object"==typeof t?e.json(t):e.html(t):t},toffee.__augmentLocals=function(e,t){var f,n;return f=e,n=f.__toffee={out:[]},null==f.print&&(f.print=function(e){return toffee.__print(f,e)}),null==f.json&&(f.json=function(e){return toffee.__json(f,e)}),null==f.raw&&(f.raw=function(e){return toffee.__raw(f,e)}),null==f.html&&(f.html=function(e){return toffee.__html(f,e)}),null==f.escape&&(f.escape=function(e){return toffee.__escape(f,e)}),null==f.partial&&(f.partial=function(e,n){return toffee.__partial(toffee.templates[""+t],f,e,n)}),null==f.snippet&&(f.snippet=function(e,n){return toffee.__snippet(toffee.templates[""+t],f,e,n)}),null==f.load&&(f.load=function(e,n){return toffee.__load(toffee.templates[""+t],f,e,n)}),n.print=f.print,n.json=f.json,n.raw=f.raw,n.html=f.html,n.escape=f.escape,n.partial=f.partial,n.snippet=f.snippet,n.load=f.load},toffee.__print=function(e,t){return e.__toffee.state===toffee.states.COFFEE?(e.__toffee.out.push(t),""):""+t},toffee.__normalize=function(e){var t,f,n,o,l;if(null==e||"/"===e)return e;for(l=e.split("/"),n=[],l[0]&&n.push(""),t=0,f=l.length;f>t;t++)o=l[t],".."===o?n.length>1?n.pop():n.push(o):"."!==o&&n.push(o);return e=n.join("/"),e||(e="/"),e},toffee.__partial=function(e,t,f,n){return f=toffee.__normalize(e.bundlePath+"/../"+f),toffee.__inlineInclude(f,n,t)},toffee.__snippet=function(e,t,f,n){return f=toffee.__normalize(e.bundlePath+"/../"+f),n=null!=n?n:{},n.__toffee=n.__toffee||{},n.__toffee.noInheritance=!0,toffee.__inlineInclude(f,n,t)},toffee.__load=function(e,t,f,n){return f=toffee.__normalize(e.bundlePath+"/../"+f),n=null!=n?n:{},n.__toffee=n.__toffee||{},n.__toffee.repress=!0,toffee.__inlineInclude(f,n,t)},toffee.__inlineInclude=function(e,t,f){var n,o,l,r,u,_,a,i,p;for(r=t||{},r.passback={},r.__toffee=r.__toffee||{},i={},u=["passback","load","print","partial","snippet","layout","__toffee","postProcess"],n=0,l=u.length;l>n;n++)o=u[n],i[o]=!0;if(!r.__toffee.noInheritance)for(o in f)p=f[o],null==(null!=t?t[o]:void 0)&&null==i[o]&&(r[o]=p);if(toffee.templates[e]){a=toffee.templates[e].pub(r),_=r.passback;for(o in _)p=_[o],f[o]=p;return a}return"Inline toffee include: Could not find "+e};
var toffee;"undefined"!=typeof toffee&&null!==toffee||(toffee={}),toffee.templates||(toffee.templates={}),toffee.states={TOFFEE:1,COFFEE:2},toffee.__json=function(e,t){return null==t?"null":""+JSON.stringify(t).replace(/</g,"\\u003C").replace(/>/g,"\\u003E").replace(/&/g,"\\u0026")},toffee.__raw=function(e,t){return t},toffee.__html=function(e,t){return(""+t).replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;")},toffee.__escape=function(e,t){var f;return f=null==e.__toffee.autoEscape||e.__toffee.autoEscape,f?void 0===t?"":null!=t&&"object"==typeof t?e.json(t):e.html(t):t},toffee.__augmentLocals=function(e,t){var f,n;return f=e,n=f.__toffee={out:[]},null==f.print&&(f.print=function(e){return toffee.__print(f,e)}),null==f.json&&(f.json=function(e){return toffee.__json(f,e)}),null==f.raw&&(f.raw=function(e){return toffee.__raw(f,e)}),null==f.html&&(f.html=function(e){return toffee.__html(f,e)}),null==f.escape&&(f.escape=function(e){return toffee.__escape(f,e)}),null==f.partial&&(f.partial=function(e,n){return toffee.__partial(toffee.templates[""+t],f,e,n)}),null==f.snippet&&(f.snippet=function(e,n){return toffee.__snippet(toffee.templates[""+t],f,e,n)}),null==f.load&&(f.load=function(e,n){return toffee.__load(toffee.templates[""+t],f,e,n)}),n.print=f.print,n.json=f.json,n.raw=f.raw,n.html=f.html,n.escape=f.escape,n.partial=f.partial,n.snippet=f.snippet,n.load=f.load},toffee.__print=function(e,t){return e.__toffee.state===toffee.states.COFFEE?(e.__toffee.out.push(t),""):""+t},toffee.__normalize=function(e){var t,f,n,o,l;if(null==e||"/"===e)return e;for(l=e.split("/"),n=[],l[0]&&n.push(""),t=0,f=l.length;t<f;t++)o=l[t],".."===o?n.length>1?n.pop():n.push(o):"."!==o&&n.push(o);return e=n.join("/"),e||(e="/"),e},toffee.__partial=function(e,t,f,n){return f=toffee.__normalize(e.bundlePath+"/../"+f),toffee.__inlineInclude(f,n,t)},toffee.__snippet=function(e,t,f,n){return f=toffee.__normalize(e.bundlePath+"/../"+f),n=null!=n?n:{},n.__toffee=n.__toffee||{},n.__toffee.noInheritance=!0,toffee.__inlineInclude(f,n,t)},toffee.__load=function(e,t,f,n){return f=toffee.__normalize(e.bundlePath+"/../"+f),n=null!=n?n:{},n.__toffee=n.__toffee||{},n.__toffee.repress=!0,toffee.__inlineInclude(f,n,t)},toffee.__inlineInclude=function(e,t,f){var n,o,l,r,u,_,a,i,p;for(r=t||{},r.passback={},r.__toffee=r.__toffee||{},i={},u=["passback","load","print","partial","snippet","layout","__toffee","postProcess"],n=0,l=u.length;n<l;n++)o=u[n],i[o]=!0;if(!r.__toffee.noInheritance)for(o in f)p=f[o],null==(null!=t?t[o]:void 0)&&null==i[o]&&(r[o]=p);if(toffee.templates[e]){a=toffee.templates[e].pub(r),_=r.passback;for(o in _)p=_[o],f[o]=p;return a}return"Inline toffee include: Could not find "+e};
;
(function() {
var tmpl;
Expand Down
2 changes: 1 addition & 1 deletion test/support/all.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,5 @@ global.should.match_expected = function (compiler, content, epath) {
var expected = parser(fs.readFileSync(expected_path, 'utf8').trim())
var results = parser(content.trim())

util.inspect(expected).should.deep.eql(util.inspect(results))
expected.should.deep.eql(results)
}

0 comments on commit f245de9

Please sign in to comment.