Skip to content

Commit

Permalink
Merge d5689fe into d82cf19
Browse files Browse the repository at this point in the history
  • Loading branch information
rwaldron committed Feb 28, 2015
2 parents d82cf19 + d5689fe commit 4834178
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/jshint.js
Original file line number Diff line number Diff line change
Expand Up @@ -2074,6 +2074,15 @@ var JSHINT = (function() {
reservevar("Infinity");
reservevar("null");
reservevar("this", function(x) {
// ModuleBody (and everything contained therein) and ClassBody are
// strict by default, therefore cannot subject to "strict-mode violation" checks
var verb = funct["(context)"] && funct["(context)"]["(verb)"];

// "export" implies that this code is within a module
if (verb === "class" || verb === "export") {
return;
}

if (state.directive["use strict"] && !isMethod() &&
!state.option.validthis && ((funct["(statement)"] &&
funct["(name)"].charAt(0) > "Z") || funct["(global)"])) {
Expand Down
31 changes: 31 additions & 0 deletions tests/unit/fixtures/gh-2217.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
export class Value {
constructor() {
this.a = 1;
}
method() {
return this.a - 1;
}
}


export function foo() {
this.a = 1;
}

export default function() {
this.a = 1;
}

class Value {
constructor() {
this.a = 1;
}
method() {
return this.a - 1;
}
}


function foo() {
this.a = 1;
}
9 changes: 9 additions & 0 deletions tests/unit/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -1264,6 +1264,15 @@ exports.validthis = function (test) {
test.done();
};

exports["validthis checks do not apply to module or class bodies. gh-2217"] = function (test) {
var src = fs.readFileSync(__dirname + "/fixtures/gh-2217.js", "utf8");

TestRun(test)
.test(src, {esnext: true});

test.done();
};

/*
* Test string relevant options
* multistr allows multiline strings
Expand Down

0 comments on commit 4834178

Please sign in to comment.