Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Push to 3.0.0beta2

lib/filters now uses lib/util for JavaScript uglify
Fixed uglify() function in lib/util to work with Uglify-js 1.x and >=2.3 (fixes #118)
Note: Uglify-js 2.3 has not yet been released
Fixed test suite
  • Loading branch information...
commit 2b77d6cf9532e85c2c01c7f35b123366e5d56db5 1 parent a462423
@bminer authored
View
17 lib/filters.js
@@ -1,3 +1,5 @@
+var bladeutil = require("./util");
+
exports['nl2br'] = function(text) {
return require('./runtime').escape(text).replace(/\n/g, "<br/>");
}
@@ -25,19 +27,8 @@ exports['coffeescript'] = exports['cs'] = function(text) {
};
exports['javascript'] = exports['js'] = function(text, opts) {
opts = opts || {};
- try {
- var uglifyjs = require('uglify-js');
- var ast = uglifyjs.parser.parse(text),
- ugly = uglifyjs.uglify;
- if(opts.minify)
- {
- ast = ugly.ast_mangle(ast);
- ast = ugly.ast_squeeze(ast);
- }
- text = ugly.gen_code(ast, {'beautify': !opts.minify});
- }
- catch(e) {}
- return '<script type="text/javascript">\n' + text + '\n</script>';
+ return '<script type="text/javascript">\n' +
+ bladeutil.uglify(text) + '\n</script>';
};
exports['stylus'] = cssTemplate('stylus');
exports['less'] = cssTemplate('less');
View
40 lib/util.js
@@ -32,22 +32,32 @@ try {
exports.uglify = function(str, minify) {
if(uglifyjs)
{
- var ast = uglifyjs.parse(str);
- if(minify)
+ if(uglifyjs.minify)
{
- //compress
- ast.figure_out_scope();
- var comp = uglifyjs.Compressor();
- ast = ast.transform(comp);
- //mangle
- ast.figure_out_scope();
- ast.compute_char_frequency();
- ast.mangle_names();
+ //Version 2.3+
+ var opts = {"fromString": true};
+ if(!minify)
+ {
+ opts.compress = opts.mangle = false;
+ opts.output = {
+ "beautify": true,
+ "comments": true
+ }
+ }
+ str = uglifyjs.minify(str, opts).code;
+ }
+ else if(uglifyjs.parser)
+ {
+ //Version 1.x - kept for legacy support and to work with Meteor
+ var ast = uglifyjs.parser.parse(str),
+ ugly = uglifyjs.uglify;
+ if(minify)
+ {
+ ast = ugly.ast_mangle(ast);
+ ast = ugly.ast_squeeze(ast);
+ }
+ str = ugly.gen_code(ast, {'beautify': !minify});
}
- //output
- var stream = uglifyjs.OutputStream({"beautify": !minify});
- ast.print(stream);
- str = stream.toString();
}
return str;
-};
+};
View
6 package.json
@@ -15,7 +15,7 @@
"live binding",
"meteor"
],
- "version": "3.0.0beta1",
+ "version": "3.0.0beta2",
"homepage": "https://github.com/bminer/node-blade",
"repository": {
"type": "git",
@@ -29,10 +29,10 @@
},
"devDependencies": {
"pegjs": ">=0.7",
- "uglify-js": "~2"
+ "uglify-js": ">=2.3 || >=1.2 <2"
},
"optionalDependencies": {
- "uglify-js": "~2"
+ "uglify-js": ">=2.3 || >=1.2 <2"
},
"engines": {
"node": ">=0.6"
View
2  smart.json
@@ -3,7 +3,7 @@
"author": "Blake Miner <miner.blake@gmail.com> (http://www.blakeminer.com/)",
"description": "Blade - HTML Template Compiler, inspired by Jade & Haml",
"homepage": "https://github.com/bminer/node-blade",
- "version": "3.0.0beta1",
+ "version": "3.0.0beta2",
"git": "https://github.com/bminer/node-blade.git",
"packages": {
}
View
2  test/output/filters.html
@@ -1,6 +1,6 @@
<head><script type="text/javascript">
$(document).ready(function() {
- console.log("This is only a test");
+ console.log("This is only a test");
});
</script></head><body>This is only a test<br/><br/>I am testing &lt;to&gt; see if this got &quot;escaped&quot;<br/><br/><br/><br/><br/>to see if this worked right...
<![CDATA[
Please sign in to comment.
Something went wrong with that request. Please try again.