handle objectMethod in scope.isPure (#11482)
This commit is contained in:
parent
0bbf2da568
commit
83d365acb6
@ -723,7 +723,7 @@ export default class Scope {
|
|||||||
if (!this.isPure(prop, constantsOnly)) return false;
|
if (!this.isPure(prop, constantsOnly)) return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
} else if (t.isClassMethod(node)) {
|
} else if (t.isMethod(node)) {
|
||||||
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;
|
||||||
|
|||||||
@ -203,11 +203,17 @@ describe("scope", () => {
|
|||||||
|
|
||||||
it("purity", function() {
|
it("purity", function() {
|
||||||
expect(
|
expect(
|
||||||
getPath("({ x: 1 })")
|
getPath("({ x: 1, foo() { return 1 } })")
|
||||||
.get("body")[0]
|
.get("body")[0]
|
||||||
.get("expression")
|
.get("expression")
|
||||||
.isPure(),
|
.isPure(),
|
||||||
).toBeTruthy();
|
).toBeTruthy();
|
||||||
|
expect(
|
||||||
|
getPath("class X { get foo() { return 1 } }")
|
||||||
|
.get("body")[0]
|
||||||
|
.get("expression")
|
||||||
|
.isPure(),
|
||||||
|
).toBeFalsy();
|
||||||
expect(
|
expect(
|
||||||
getPath("`${a}`")
|
getPath("`${a}`")
|
||||||
.get("body")[0]
|
.get("body")[0]
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user