Support ObjectProperty in purity check
This commit is contained in:
parent
e96f3544f6
commit
2a2cb4f160
@ -593,7 +593,7 @@ export default class Scope {
|
||||
if (node.computed && !this.isPure(node.key, constantsOnly)) return false;
|
||||
if (node.kind === "get" || node.kind === "set") return false;
|
||||
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;
|
||||
return this.isPure(node.value, constantsOnly);
|
||||
} else if (t.isUnaryExpression(node)) {
|
||||
|
||||
@ -34,5 +34,9 @@ suite("scope", function () {
|
||||
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");
|
||||
});
|
||||
|
||||
test("purity", function () {
|
||||
assert.ok(getPath("({ x: 1 })").get("body")[0].get("expression").isPure());
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user