Support ObjectProperty in purity check

This commit is contained in:
Amjad Masad 2015-12-09 16:49:16 -08:00
parent e96f3544f6
commit 2a2cb4f160
2 changed files with 5 additions and 1 deletions

View File

@ -593,7 +593,7 @@ export default class Scope {
if (node.computed && !this.isPure(node.key, constantsOnly)) return false; if (node.computed && !this.isPure(node.key, constantsOnly)) return false;
if (node.kind === "get" || node.kind === "set") return false; if (node.kind === "get" || node.kind === "set") return false;
return true; return true;
} else if (t.isClassProperty(node)) { } else if (t.isClassProperty(node) || t.isObjectProperty(node)) {
if (node.computed && !this.isPure(node.key, constantsOnly)) return false; if (node.computed && !this.isPure(node.key, constantsOnly)) return false;
return this.isPure(node.value, constantsOnly); return this.isPure(node.value, constantsOnly);
} else if (t.isUnaryExpression(node)) { } else if (t.isUnaryExpression(node)) {

View File

@ -34,5 +34,9 @@ suite("scope", function () {
assert.ok(getPath("var [ foo ] = null;").scope.getBinding("foo").path.type === "VariableDeclarator"); assert.ok(getPath("var [ foo ] = null;").scope.getBinding("foo").path.type === "VariableDeclarator");
assert.ok(getPath("var { bar: [ foo ] } = null;").scope.getBinding("foo").path.type === "VariableDeclarator"); assert.ok(getPath("var { bar: [ foo ] } = null;").scope.getBinding("foo").path.type === "VariableDeclarator");
}); });
test("purity", function () {
assert.ok(getPath("({ x: 1 })").get("body")[0].get("expression").isPure());
});
}); });
}); });