Normalize error messages
This commit is contained in:
committed by
Richard van Velzen
parent
2149bfb707
commit
6c99816855
32
lib/parse.js
32
lib/parse.js
@@ -762,14 +762,14 @@ function parse($TEXT, options) {
|
|||||||
function unexpected(token) {
|
function unexpected(token) {
|
||||||
if (token == null)
|
if (token == null)
|
||||||
token = S.token;
|
token = S.token;
|
||||||
token_error(token, "Unexpected token: " + token.type + " (" + token.value + ")");
|
token_error(token, "SyntaxError: Unexpected token: " + token.type + " (" + token.value + ")");
|
||||||
};
|
};
|
||||||
|
|
||||||
function expect_token(type, val) {
|
function expect_token(type, val) {
|
||||||
if (is(type, val)) {
|
if (is(type, val)) {
|
||||||
return next();
|
return next();
|
||||||
}
|
}
|
||||||
token_error(S.token, "Unexpected token " + S.token.type + " «" + S.token.value + "»" + ", expected " + type + " «" + val + "»");
|
token_error(S.token, "SyntaxError: Unexpected token " + S.token.type + " «" + S.token.value + "»" + ", expected " + type + " «" + val + "»");
|
||||||
};
|
};
|
||||||
|
|
||||||
function expect(punc) { return expect_token("punc", punc); };
|
function expect(punc) { return expect_token("punc", punc); };
|
||||||
@@ -898,7 +898,7 @@ function parse($TEXT, options) {
|
|||||||
|
|
||||||
case "return":
|
case "return":
|
||||||
if (S.in_function == 0 && !options.bare_returns)
|
if (S.in_function == 0 && !options.bare_returns)
|
||||||
croak("'return' outside of function");
|
croak("SyntaxError: 'return' outside of function");
|
||||||
return new AST_Return({
|
return new AST_Return({
|
||||||
value: ( is("punc", ";")
|
value: ( is("punc", ";")
|
||||||
? (next(), null)
|
? (next(), null)
|
||||||
@@ -915,7 +915,7 @@ function parse($TEXT, options) {
|
|||||||
|
|
||||||
case "throw":
|
case "throw":
|
||||||
if (S.token.nlb)
|
if (S.token.nlb)
|
||||||
croak("Illegal newline after 'throw'");
|
croak("SyntaxError: Illegal newline after 'throw'");
|
||||||
return new AST_Throw({
|
return new AST_Throw({
|
||||||
value: (tmp = expression(true), semicolon(), tmp)
|
value: (tmp = expression(true), semicolon(), tmp)
|
||||||
});
|
});
|
||||||
@@ -931,7 +931,7 @@ function parse($TEXT, options) {
|
|||||||
|
|
||||||
case "with":
|
case "with":
|
||||||
if (S.input.has_directive("use strict")) {
|
if (S.input.has_directive("use strict")) {
|
||||||
croak("Strict mode may not include a with statement");
|
croak("SyntaxError: Strict mode may not include a with statement");
|
||||||
}
|
}
|
||||||
return new AST_With({
|
return new AST_With({
|
||||||
expression : parenthesised(),
|
expression : parenthesised(),
|
||||||
@@ -951,7 +951,7 @@ function parse($TEXT, options) {
|
|||||||
// syntactically incorrect if it contains a
|
// syntactically incorrect if it contains a
|
||||||
// LabelledStatement that is enclosed by a
|
// LabelledStatement that is enclosed by a
|
||||||
// LabelledStatement with the same Identifier as label.
|
// LabelledStatement with the same Identifier as label.
|
||||||
croak("Label " + label.name + " defined twice");
|
croak("SyntaxError: Label " + label.name + " defined twice");
|
||||||
}
|
}
|
||||||
expect(":");
|
expect(":");
|
||||||
S.labels.push(label);
|
S.labels.push(label);
|
||||||
@@ -964,7 +964,7 @@ function parse($TEXT, options) {
|
|||||||
label.references.forEach(function(ref){
|
label.references.forEach(function(ref){
|
||||||
if (ref instanceof AST_Continue) {
|
if (ref instanceof AST_Continue) {
|
||||||
ref = ref.label.start;
|
ref = ref.label.start;
|
||||||
croak("Continue label `" + label.name + "` refers to non-IterationStatement.",
|
croak("SyntaxError: Continue label `" + label.name + "` refers to non-IterationStatement.",
|
||||||
ref.line, ref.col, ref.pos);
|
ref.line, ref.col, ref.pos);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -984,11 +984,11 @@ function parse($TEXT, options) {
|
|||||||
if (label != null) {
|
if (label != null) {
|
||||||
ldef = find_if(function(l){ return l.name == label.name }, S.labels);
|
ldef = find_if(function(l){ return l.name == label.name }, S.labels);
|
||||||
if (!ldef)
|
if (!ldef)
|
||||||
croak("Undefined label " + label.name);
|
croak("SyntaxError: Undefined label " + label.name);
|
||||||
label.thedef = ldef;
|
label.thedef = ldef;
|
||||||
}
|
}
|
||||||
else if (S.in_loop == 0)
|
else if (S.in_loop == 0)
|
||||||
croak(type.TYPE + " not inside a loop or switch");
|
croak("SyntaxError: " + type.TYPE + " not inside a loop or switch");
|
||||||
semicolon();
|
semicolon();
|
||||||
var stat = new type({ label: label });
|
var stat = new type({ label: label });
|
||||||
if (ldef) ldef.references.push(stat);
|
if (ldef) ldef.references.push(stat);
|
||||||
@@ -1004,7 +1004,7 @@ function parse($TEXT, options) {
|
|||||||
: expression(true, true);
|
: expression(true, true);
|
||||||
if (is("operator", "in")) {
|
if (is("operator", "in")) {
|
||||||
if (init instanceof AST_Var && init.definitions.length > 1)
|
if (init instanceof AST_Var && init.definitions.length > 1)
|
||||||
croak("Only one variable declaration allowed in for..in loop");
|
croak("SyntaxError: Only one variable declaration allowed in for..in loop");
|
||||||
next();
|
next();
|
||||||
return for_in(init);
|
return for_in(init);
|
||||||
}
|
}
|
||||||
@@ -1154,7 +1154,7 @@ function parse($TEXT, options) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
if (!bcatch && !bfinally)
|
if (!bcatch && !bfinally)
|
||||||
croak("Missing catch/finally blocks");
|
croak("SyntaxError: Missing catch/finally blocks");
|
||||||
return new AST_Try({
|
return new AST_Try({
|
||||||
body : body,
|
body : body,
|
||||||
bcatch : bcatch,
|
bcatch : bcatch,
|
||||||
@@ -1248,8 +1248,8 @@ function parse($TEXT, options) {
|
|||||||
break;
|
break;
|
||||||
case "operator":
|
case "operator":
|
||||||
if (!is_identifier_string(tok.value)) {
|
if (!is_identifier_string(tok.value)) {
|
||||||
throw new JS_Parse_Error("Invalid getter/setter name: " + tok.value,
|
croak("SyntaxError: Invalid getter/setter name: " + tok.value,
|
||||||
tok.file, tok.line, tok.col, tok.pos);
|
tok.line, tok.col, tok.pos);
|
||||||
}
|
}
|
||||||
ret = _make_symbol(AST_SymbolRef);
|
ret = _make_symbol(AST_SymbolRef);
|
||||||
break;
|
break;
|
||||||
@@ -1399,7 +1399,7 @@ function parse($TEXT, options) {
|
|||||||
|
|
||||||
function as_symbol(type, noerror) {
|
function as_symbol(type, noerror) {
|
||||||
if (!is("name")) {
|
if (!is("name")) {
|
||||||
if (!noerror) croak("Name expected");
|
if (!noerror) croak("SyntaxError: Name expected");
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
var sym = _make_symbol(type);
|
var sym = _make_symbol(type);
|
||||||
@@ -1463,7 +1463,7 @@ function parse($TEXT, options) {
|
|||||||
|
|
||||||
function make_unary(ctor, op, expr) {
|
function make_unary(ctor, op, expr) {
|
||||||
if ((op == "++" || op == "--") && !is_assignable(expr))
|
if ((op == "++" || op == "--") && !is_assignable(expr))
|
||||||
croak("Invalid use of " + op + " operator");
|
croak("SyntaxError: Invalid use of " + op + " operator");
|
||||||
return new ctor({ operator: op, expression: expr });
|
return new ctor({ operator: op, expression: expr });
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -1527,7 +1527,7 @@ function parse($TEXT, options) {
|
|||||||
end : prev()
|
end : prev()
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
croak("Invalid assignment");
|
croak("SyntaxError: Invalid assignment");
|
||||||
}
|
}
|
||||||
return left;
|
return left;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -168,7 +168,7 @@ describe("Directives", function() {
|
|||||||
throw new Error("Expected parser to fail");
|
throw new Error("Expected parser to fail");
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
assert.strictEqual(e instanceof uglify.JS_Parse_Error, true);
|
assert.strictEqual(e instanceof uglify.JS_Parse_Error, true);
|
||||||
assert.strictEqual(e.message, "Unexpected token: punc (])");
|
assert.strictEqual(e.message, "SyntaxError: Unexpected token: punc (])");
|
||||||
}
|
}
|
||||||
|
|
||||||
test_directive(tokenizer, tests[i]);
|
test_directive(tokenizer, tests[i]);
|
||||||
|
|||||||
@@ -71,7 +71,7 @@ describe("Getters and setters", function() {
|
|||||||
var fail = function(data) {
|
var fail = function(data) {
|
||||||
return function (e) {
|
return function (e) {
|
||||||
return e instanceof UglifyJS.JS_Parse_Error &&
|
return e instanceof UglifyJS.JS_Parse_Error &&
|
||||||
e.message === "Invalid getter/setter name: " + data.operator;
|
e.message === "SyntaxError: Invalid getter/setter name: " + data.operator;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ describe("With", function() {
|
|||||||
}
|
}
|
||||||
var error = function(e) {
|
var error = function(e) {
|
||||||
return e instanceof uglify.JS_Parse_Error &&
|
return e instanceof uglify.JS_Parse_Error &&
|
||||||
e.message === "Strict mode may not include a with statement";
|
e.message === "SyntaxError: Strict mode may not include a with statement";
|
||||||
}
|
}
|
||||||
assert.throws(test, error);
|
assert.throws(test, error);
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user