Merge dcaee59b9e into 7d11b96f48
This commit is contained in:
commit
2d65c79312
21
lib/parse.js
21
lib/parse.js
|
|
@ -188,20 +188,29 @@ function parse_js_number(num) {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
function JS_Parse_Error(message, line, col, pos) {
|
// the right way to create a custom error: http://stackoverflow.com/questions/8802845/inheriting-from-the-error-object-where-is-the-message-property
|
||||||
this.message = message;
|
function JS_Parse_Error(message, filename, line, col, pos) {
|
||||||
|
var tmp = Error.call(this, message);
|
||||||
|
tmp.name = this.name = 'JS_Parse_Error'
|
||||||
|
|
||||||
|
this.stack = tmp.stack
|
||||||
|
this.message = tmp.message
|
||||||
this.line = line;
|
this.line = line;
|
||||||
this.col = col;
|
this.col = col;
|
||||||
this.pos = pos;
|
this.pos = pos;
|
||||||
this.stack = new Error().stack;
|
//this.file = filename // why isn't filename being used
|
||||||
};
|
|
||||||
|
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
var IntermediateInheritor = function() {}
|
||||||
|
IntermediateInheritor.prototype = Error.prototype;
|
||||||
|
JS_Parse_Error.prototype = new IntermediateInheritor()
|
||||||
JS_Parse_Error.prototype.toString = function() {
|
JS_Parse_Error.prototype.toString = function() {
|
||||||
return this.message + " (line: " + this.line + ", col: " + this.col + ", pos: " + this.pos + ")" + "\n\n" + this.stack;
|
return this.message + " ("+/*"file: " + this.file + ", "+*/"line: " + this.line + ", col: " + this.col + ", pos: " + this.pos + ")" + "\n\n" + this.stack;
|
||||||
};
|
};
|
||||||
|
|
||||||
function js_error(message, filename, line, col, pos) {
|
function js_error(message, filename, line, col, pos) {
|
||||||
throw new JS_Parse_Error(message, line, col, pos);
|
throw new JS_Parse_Error(message, filename, line, col, pos);
|
||||||
};
|
};
|
||||||
|
|
||||||
function is_token(token, type, val) {
|
function is_token(token, type, val) {
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@
|
||||||
"description": "JavaScript parser, mangler/compressor and beautifier toolkit",
|
"description": "JavaScript parser, mangler/compressor and beautifier toolkit",
|
||||||
"homepage": "http://lisperator.net/uglifyjs",
|
"homepage": "http://lisperator.net/uglifyjs",
|
||||||
"main": "tools/node.js",
|
"main": "tools/node.js",
|
||||||
"version": "2.4.3",
|
"version": "2.4.4",
|
||||||
"engines": { "node" : ">=0.4.0" },
|
"engines": { "node" : ">=0.4.0" },
|
||||||
"maintainers": [{
|
"maintainers": [{
|
||||||
"name": "Mihai Bazon",
|
"name": "Mihai Bazon",
|
||||||
|
|
@ -20,6 +20,9 @@
|
||||||
"optimist" : "~0.3.5",
|
"optimist" : "~0.3.5",
|
||||||
"uglify-to-browserify": "~1.0.0"
|
"uglify-to-browserify": "~1.0.0"
|
||||||
},
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"deadunit" : "1.0.7"
|
||||||
|
},
|
||||||
"browserify": {
|
"browserify": {
|
||||||
"transform": [ "uglify-to-browserify" ]
|
"transform": [ "uglify-to-browserify" ]
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@ var path = require("path");
|
||||||
var fs = require("fs");
|
var fs = require("fs");
|
||||||
var assert = require("assert");
|
var assert = require("assert");
|
||||||
var sys = require("util");
|
var sys = require("util");
|
||||||
|
var Unit = require("deadunit")
|
||||||
|
|
||||||
var tests_dir = path.dirname(module.filename);
|
var tests_dir = path.dirname(module.filename);
|
||||||
var failures = 0;
|
var failures = 0;
|
||||||
|
|
@ -17,6 +18,38 @@ if (failures) {
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Unit.test("pretty tests", function() {
|
||||||
|
this.test("proper errors", function() {
|
||||||
|
this.count(10)
|
||||||
|
|
||||||
|
try {
|
||||||
|
var js = "var = { invalid_js ]"
|
||||||
|
U.minify(js, {
|
||||||
|
fromString: true
|
||||||
|
})
|
||||||
|
} catch(e) {
|
||||||
|
|
||||||
|
this.ok(e instanceof U.JS_Parse_Error)
|
||||||
|
this.ok(e.line === 1, e.line)
|
||||||
|
this.ok(e.col === 4, e.col)
|
||||||
|
this.ok(e.pos === 4, e.pos)
|
||||||
|
this.ok(e.message === "Name expected", e.message)
|
||||||
|
this.ok(e.stack.indexOf("Name expected") !== -1, e.stack)
|
||||||
|
this.ok(e.toString().indexOf("Name expected (line: 1, col: 4, pos: 4)") !== -1, e.toString())
|
||||||
|
this.ok(e.stack.indexOf("JS_Parse_Error") !== -1, e.stack)
|
||||||
|
|
||||||
|
// the following test fails because the original calling line of code isn't included in the stack trace
|
||||||
|
// to be clear, its not ok that this fails - this needs to be fixed
|
||||||
|
this.ok(e.stack.indexOf("run-tests.js") !== -1, e.stack)
|
||||||
|
|
||||||
|
// I think the following fails because of the use of runInContext in tools/node.js
|
||||||
|
// again, this is *not* ok
|
||||||
|
this.ok(e instanceof Error)
|
||||||
|
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}).writeConsole()
|
||||||
|
|
||||||
/* -----[ utils ]----- */
|
/* -----[ utils ]----- */
|
||||||
|
|
||||||
function tmpl() {
|
function tmpl() {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user