check LHS of ForIn/ForOfStatement for constants - closes #1630
This commit is contained in:
parent
d3c643b004
commit
d1d95e0e49
@ -1,12 +1,12 @@
|
||||
import * as messages from "../../../messages";
|
||||
|
||||
export function AssignmentExpression(node, parent, scope, file) {
|
||||
var ids = this.getBindingIdentifiers();
|
||||
function checkPath(path, file) {
|
||||
var ids = path.getBindingIdentifiers();
|
||||
|
||||
for (var name in ids) {
|
||||
var id = ids[name];
|
||||
|
||||
var binding = scope.getBinding(name);
|
||||
var binding = path.scope.getBinding(name);
|
||||
|
||||
// no binding exists
|
||||
if (!binding) continue;
|
||||
@ -23,8 +23,19 @@ export function AssignmentExpression(node, parent, scope, file) {
|
||||
}
|
||||
}
|
||||
|
||||
export function AssignmentExpression(node, parent, scope, file) {
|
||||
checkPath(this, file);
|
||||
}
|
||||
|
||||
export { AssignmentExpression as UpdateExpression };
|
||||
|
||||
export function VariableDeclaration(node) {
|
||||
if (node.kind === "const") node.kind = "let";
|
||||
}
|
||||
|
||||
export function ForXStatement(node, parent, scope, file) {
|
||||
var left = this.get("left");
|
||||
if (left.isIdentifier() || left.isPattern()) {
|
||||
checkPath(left, file);
|
||||
}
|
||||
}
|
||||
|
||||
@ -46,6 +46,13 @@ var programReferenceVisitor = {
|
||||
}
|
||||
},
|
||||
|
||||
ForXStatement(node, parent, scope, state) {
|
||||
var left = this.get("left");
|
||||
if (left.isPattern() || left.isIdentifier()) {
|
||||
scope.registerConstantViolation(left);
|
||||
}
|
||||
},
|
||||
|
||||
Scopable(node, parent, scope, state) {
|
||||
for (var name in scope.bindings) {
|
||||
state.references[name] = true;
|
||||
|
||||
@ -44,8 +44,8 @@
|
||||
"ClassDeclaration": ["Scopable", "Class", "Statement", "Declaration"],
|
||||
"ClassExpression": ["Scopable", "Class", "Expression"],
|
||||
|
||||
"ForOfStatement": ["Scopable", "Statement", "For", "Loop"],
|
||||
"ForInStatement": ["Scopable", "Statement", "For", "Loop"],
|
||||
"ForOfStatement": ["Scopable", "Statement", "For", "Loop", "ForXStatement"],
|
||||
"ForInStatement": ["Scopable", "Statement", "For", "Loop", "ForXStatement"],
|
||||
"ForStatement": ["Scopable", "Statement", "For", "Loop"],
|
||||
|
||||
"ObjectPattern": ["Pattern"],
|
||||
|
||||
@ -0,0 +1,3 @@
|
||||
const MULTIPLIER = 5;
|
||||
|
||||
for (MULTIPLIER in arr);
|
||||
@ -0,0 +1,3 @@
|
||||
{
|
||||
"throws": "\"MULTIPLIER\" is read-only"
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user