fix constants transformer not accurately checking nodes
This commit is contained in:
parent
92621d71c7
commit
6d1953d9c3
@ -7,12 +7,12 @@ exports.BlockStatement =
|
||||
exports.ForInStatement =
|
||||
exports.ForOfStatement =
|
||||
exports.ForStatement = function (node, parent, file) {
|
||||
var constants = [];
|
||||
var constants = {};
|
||||
|
||||
var check = function (node, names, parent) {
|
||||
_.each(names, function (name) {
|
||||
if (!_.has(constants, name)) return;
|
||||
if (t.isBlockStatement(parent) && parent !== constants[name]) return;
|
||||
if (parent && t.isBlockStatement(parent) && parent !== constants[name]) return;
|
||||
|
||||
throw file.errorWithNode(node, name + " is read-only");
|
||||
});
|
||||
@ -38,13 +38,13 @@ exports.ForStatement = function (node, parent, file) {
|
||||
}
|
||||
});
|
||||
|
||||
if (!constants.length) return;
|
||||
if (_.isEmpty(constants)) return;
|
||||
|
||||
traverse(node, function (child) {
|
||||
traverse(node, function (child, parent) {
|
||||
if (child._ignoreConstant) return;
|
||||
|
||||
if (t.isVariableDeclarator(child) || t.isDeclaration(child) || t.isAssignmentExpression(child)) {
|
||||
check(child, getIds(child));
|
||||
if (t.isDeclaration(child) || t.isAssignmentExpression(child)) {
|
||||
check(child, getIds(child), parent);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user