Skip to content

Commit

Permalink
Fix syntax error message strings.
Browse files Browse the repository at this point in the history
Made all syntax errors related to labels, continue, break and return to be identical to those from V8.

http://code.google.com/p/esprima/issues/detail?id=209
http://code.google.com/p/v8/source/browse/branches/bleeding_edge/src/messages.js
  • Loading branch information
jboekesteijn committed Mar 4, 2012
1 parent 49cb9de commit a5cc6e0
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 26 deletions.
30 changes: 15 additions & 15 deletions esprima.js
Expand Up @@ -134,11 +134,11 @@ parseStatement: true, parseSourceElement: true */
InvalidRegExp: 'Invalid regular expression',
UnterminatedRegExp: 'Invalid regular expression: missing /',
NoCatchOrFinally: 'Missing catch or finally after try',
LabelNotFound: 'Label \'%0\' not found',
DuplicateLabel: 'Duplicate label \'%0\'',
NotInIteration: 'Continue must be inside loop',
NotInIterationOrSwitch: 'Unlabeled break must be inside loop or switch',
InvalidReturn: 'Return statement must be inside function body',
UnknownLabel: 'Undefined label \'%0\'',
Redeclaration: '%0 \'%1\' has already been declared',
IllegalContinue: 'Illegal continue statement',
IllegalBreak: 'Illegal break statement',
IllegalReturn: 'Illegal return statement',
StrictModeWith: 'Strict mode code may not include a with statement',
StrictCatchVariable: 'Catch variable may not be eval or arguments in strict mode',
StrictVarName: 'Variable name may not be eval or arguments in strict mode',
Expand Down Expand Up @@ -2385,7 +2385,7 @@ parseStatement: true, parseSourceElement: true */
lex();

if (!inIteration) {
throwError({}, Messages.NotInIteration);
throwError({}, Messages.IllegalContinue);
}

return {
Expand All @@ -2396,7 +2396,7 @@ parseStatement: true, parseSourceElement: true */

if (peekLineTerminator()) {
if (!inIteration) {
throwError({}, Messages.NotInIteration);
throwError({}, Messages.IllegalContinue);
}

return {
Expand All @@ -2410,14 +2410,14 @@ parseStatement: true, parseSourceElement: true */
label = parseVariableIdentifier();

if (!Object.prototype.hasOwnProperty.call(labelSet, label.name)) {
throwError({}, Messages.LabelNotFound, label.name);
throwError({}, Messages.UnknownLabel, label.name);
}
}

consumeSemicolon();

if (label === null && !inIteration) {
throwError({}, Messages.NotInIteration);
throwError({}, Messages.IllegalContinue);
}

return {
Expand All @@ -2438,7 +2438,7 @@ parseStatement: true, parseSourceElement: true */
lex();

if (!(inIteration || inSwitch)) {
throwError({}, Messages.NotInIterationOrSwitch);
throwError({}, Messages.IllegalBreak);
}

return {
Expand All @@ -2449,7 +2449,7 @@ parseStatement: true, parseSourceElement: true */

if (peekLineTerminator()) {
if (!(inIteration || inSwitch)) {
throwError({}, Messages.NotInIterationOrSwitch);
throwError({}, Messages.IllegalBreak);
}

return {
Expand All @@ -2463,14 +2463,14 @@ parseStatement: true, parseSourceElement: true */
label = parseVariableIdentifier();

if (!Object.prototype.hasOwnProperty.call(labelSet, label.name)) {
throwError({}, Messages.LabelNotFound, label.name);
throwError({}, Messages.UnknownLabel, label.name);
}
}

consumeSemicolon();

if (label === null && !(inIteration || inSwitch)) {
throwError({}, Messages.NotInIterationOrSwitch);
throwError({}, Messages.IllegalBreak);
}

return {
Expand All @@ -2487,7 +2487,7 @@ parseStatement: true, parseSourceElement: true */
expectKeyword('return');

if (!inFunctionBody) {
throwError({}, Messages.InvalidReturn);
throwError({}, Messages.IllegalReturn);
}

// 'return' followed by a space and an identifier is very common.
Expand Down Expand Up @@ -2780,7 +2780,7 @@ parseStatement: true, parseSourceElement: true */
lex();

if (Object.prototype.hasOwnProperty.call(labelSet, expr.name)) {
throwError({}, Messages.DuplicateLabel, expr.name);
throwError({}, Messages.Redeclaration, 'Label', expr.name);
}

labelSet[expr.name] = true;
Expand Down
22 changes: 11 additions & 11 deletions test/test.js
Expand Up @@ -20334,77 +20334,77 @@ data = {
index: 6,
lineNumber: 1,
column: 7,
message: 'Error: Line 1: Return statement must be inside function body'
message: 'Error: Line 1: Illegal return statement'
},

'break': {
index: 5,
lineNumber: 1,
column: 6,
message: 'Error: Line 1: Unlabeled break must be inside loop or switch'
message: 'Error: Line 1: Illegal break statement'
},

'continue': {
index: 8,
lineNumber: 1,
column: 9,
message: 'Error: Line 1: Continue must be inside loop'
message: 'Error: Line 1: Illegal continue statement'
},

'switch (x) { default: continue; }': {
index: 31,
lineNumber: 1,
column: 32,
message: 'Error: Line 1: Continue must be inside loop'
message: 'Error: Line 1: Illegal continue statement'
},

'while (true) { break x; }': {
index: 22,
lineNumber: 1,
column: 23,
message: 'Error: Line 1: Label \'x\' not found'
message: 'Error: Line 1: Undefined label \'x\''
},

'while (true) { continue x; }': {
index: 25,
lineNumber: 1,
column: 26,
message: 'Error: Line 1: Label \'x\' not found'
message: 'Error: Line 1: Undefined label \'x\''
},

'x: while (true) { (function () { break x; }); }': {
index: 40,
lineNumber: 1,
column: 41,
message: 'Error: Line 1: Label \'x\' not found'
message: 'Error: Line 1: Undefined label \'x\''
},

'x: while (true) { (function () { continue x; }); }': {
index: 43,
lineNumber: 1,
column: 44,
message: 'Error: Line 1: Label \'x\' not found'
message: 'Error: Line 1: Undefined label \'x\''
},

'x: while (true) { (function () { break; }); }': {
index: 39,
lineNumber: 1,
column: 40,
message: 'Error: Line 1: Unlabeled break must be inside loop or switch'
message: 'Error: Line 1: Illegal break statement'
},

'x: while (true) { (function () { continue; }); }': {
index: 42,
lineNumber: 1,
column: 43,
message: 'Error: Line 1: Continue must be inside loop'
message: 'Error: Line 1: Illegal continue statement'
},

'x: while (true) { x: while (true) { } }': {
index: 20,
lineNumber: 1,
column: 21,
message: 'Error: Line 1: Duplicate label \'x\''
message: 'Error: Line 1: Label \'x\' has already been declared'
},

'(function () { \'use strict\'; delete i; }())': {
Expand Down

0 comments on commit a5cc6e0

Please sign in to comment.