handle objectMethod in scope.isPure (#11482)

This commit is contained in:
Zen 2020-04-26 00:34:52 +08:00 committed by GitHub
parent 0bbf2da568
commit 83d365acb6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 2 deletions

View File

@ -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;

View File

@ -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]