Skip to content

Commit bed7cd2

Browse files
committed
Fix JavaScript minificator.
1 parent 17728fe commit bed7cd2

5 files changed

Lines changed: 21 additions & 12 deletions

File tree

index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -464,7 +464,7 @@ function Framework() {
464464

465465
this.id = null;
466466
this.version = 2100;
467-
this.version_header = '2.1.0-23';
467+
this.version_header = '2.1.0-24';
468468
this.version_node = process.version.toString().replace('v', '').replace(/\./g, '').parseFloat();
469469

470470
this.config = {

internal.js

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1122,7 +1122,6 @@ function minify_javascript(data) {
11221122
var white = /\W/;
11231123
var skip = { '$': true, '_': true };
11241124
var regexp = false;
1125-
var skipnext = false;
11261125
var scope;
11271126
var prev;
11281127
var next;
@@ -1188,18 +1187,15 @@ function minify_javascript(data) {
11881187
regexp = (last === '=' || last === '(' || last === ':') && (c === '/');
11891188
}
11901189

1191-
/*
1192-
WTF? For what?
1193-
if (scope && prev === '\\' && c === '\\') {
1190+
if (scope && c === '\\') {
11941191
output.push(c);
1195-
skipnext = true;
1192+
output.push(next);
1193+
index++;
1194+
last = next;
11961195
continue;
11971196
}
1198-
*/
1199-
1200-
if (!regexp && (c === '"' || c === '\'' || c === '`') && (prev !== '\\' || skipnext)) {
12011197

1202-
skipnext = false;
1198+
if (!regexp && (c === '"' || c === '\'' || c === '`')) {
12031199

12041200
if (scope && scope !== c) {
12051201
output.push(c);
@@ -1219,7 +1215,7 @@ function minify_javascript(data) {
12191215
last = c;
12201216
}
12211217

1222-
return output.join('');
1218+
return output.join('').trim();
12231219
}
12241220

12251221
exports.compile_css = function(value, filename) {

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@
7575
"name": "Peter Štolc",
7676
"email": "stolcp@gmail.com"
7777
}],
78-
"version": "2.1.0-23",
78+
"version": "2.1.0-24",
7979
"homepage": "http://www.totaljs.com",
8080
"bugs": {
8181
"url": "https://github.com/totaljs/framework/issues",

test/javascript.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// FOR UNITTEST
2+
return '\\' + 2;
3+
4+
var attributes = "\\[" + a + "*(" + b + ")(?:" + c +
5+
// Operator (capture 2)
6+
"*([*^$|!~]?=)" + d +
7+
// "Attribute values must be CSS identifiers [capture 5] or strings [capture 3 or capture 4]"
8+
"*(?:'((?:\\\\.|[^\\\\'])*)'|\"((?:\\\\.|[^\\\\\"])*)\"|(" + e + "))|)" + f +
9+
"*\\]";
10+
11+
var a = 200;

test/test-javascript.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
var assert = require('assert');
22
var javascript = require('../internal');
3+
var fs = require('fs');
34

45
var buffer = [];
56
buffer.push('<script type="text/javascript">');
@@ -13,6 +14,7 @@ buffer.push('</script>');
1314

1415
var result1 = '<script type="text/javascript">function skuska(name,value){var arr=[1,2,3,4,5];var obj={Name:"Peter",Age:"28"}}console.log("OK");</script>';
1516
assert.ok(javascript.compile_javascript(buffer.join('\n')) === result1, 'javascript');
17+
assert.ok(new Buffer(javascript.compile_javascript(fs.readFileSync('javascript.js').toString('utf8'))).toString('base64') === 'cmV0dXJuJ1xcJysyO3ZhciBhdHRyaWJ1dGVzPSJcXFsiK2ErIiooIitiKyIpKD86IitjKyIqKFsqXiR8IX5dPz0pIitkKyIqKD86JygoPzpcXFxcLnxbXlxcXFwnXSkqKSd8XCIoKD86XFxcXC58W15cXFxcXCJdKSopXCJ8KCIrZSsiKSl8KSIrZisiKlxcXSI7dmFyIGE9MjAwOw==', 'Problem 1');
1618

1719
console.log('================================================');
1820
console.log('success - OK');

0 commit comments

Comments
 (0)