Skip to content

Commit

Permalink
Fixed #1134: Catch reserved words in ES3 mode.
Browse files Browse the repository at this point in the history
Closed #1139.
  • Loading branch information
kevnchu authored and valueof committed Jun 27, 2013
1 parent 87e3e6c commit 9782fc8
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 11 deletions.
10 changes: 5 additions & 5 deletions src/stable/jshint.js
Expand Up @@ -271,16 +271,17 @@ var JSHINT = (function () {
if (!token.reserved) {
return false;
}
var meta = token.meta;

if (token.meta && token.meta.isFutureReservedWord) {
if (meta && meta.isFutureReservedWord && state.option.inES5()) {
// ES3 FutureReservedWord in an ES5 environment.
if (state.option.inES5(true) && !token.meta.es5) {
if (!meta.es5) {
return false;
}

// Some ES5 FutureReservedWord identifiers are active only
// within a strict mode environment.
if (token.meta.strictOnly) {
if (meta.strictOnly) {
if (!state.option.strict && !state.directive["use strict"]) {
return false;
}
Expand Down Expand Up @@ -1445,15 +1446,14 @@ var JSHINT = (function () {
advance();

var curr = state.tokens.curr;
var meta = curr.meta || {};
var val = state.tokens.curr.value;

if (!isReserved(curr)) {
return val;
}

if (prop) {
if (state.option.inES5() || meta.isFutureReservedWord) {
if (state.option.inES5()) {
return val;
}
}
Expand Down
7 changes: 4 additions & 3 deletions src/stable/lex.js
Expand Up @@ -1491,16 +1491,17 @@ Lexer.prototype = {
if (!token.reserved) {
return false;
}
var meta = token.meta;

if (token.meta && token.meta.isFutureReservedWord) {
if (meta && meta.isFutureReservedWord && state.option.inES5()) {
// ES3 FutureReservedWord in an ES5 environment.
if (state.option.inES5(true) && !token.meta.es5) {
if (!meta.es5) {
return false;
}

// Some ES5 FutureReservedWord identifiers are active only
// within a strict mode environment.
if (token.meta.strictOnly) {
if (meta.strictOnly) {
if (!state.option.strict && !state.directive["use strict"]) {
return false;
}
Expand Down
5 changes: 4 additions & 1 deletion tests/stable/unit/core.js
Expand Up @@ -548,8 +548,11 @@ exports.testReserved = function (test) {
.addError(1, "Expected an identifier and instead saw 'volatile' (a reserved word).")
.addError(5, "Expected an identifier and instead saw 'let' (a reserved word).")
.addError(10, "Expected an identifier and instead saw 'let' (a reserved word).")
.addError(13, "Expected an identifier and instead saw 'class' (a reserved word).")
.addError(13, "Reserved words as properties can be used under the 'es5' option.")
.addError(14, "Expected an identifier and instead saw 'else' (a reserved word).")
.addError(14, "Reserved words as properties can be used under the 'es5' option.")
.addError(15, "Expected an identifier and instead saw 'throws' (a reserved word).")
.addError(16, "Expected an identifier and instead saw 'protected' (a reserved word).")
.test(src, {es3: true});

TestRun(test)
Expand Down
5 changes: 3 additions & 2 deletions tests/stable/unit/fixtures/reserved.js
Expand Up @@ -10,6 +10,7 @@ var let = 1;
var let = 2;
}());

var obj = {};
var obj = { class: 'foo' };
obj.else = 1;
obj.throws = 2;
obj.throws = 2;
obj.protected = 4;

0 comments on commit 9782fc8

Please sign in to comment.