Skip to content

Commit

Permalink
handle objectMethod in scope.isPure (#11482)
Browse files Browse the repository at this point in the history
  • Loading branch information
Zzzen committed Apr 25, 2020
1 parent 0bbf2da commit 83d365a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
2 changes: 1 addition & 1 deletion packages/babel-traverse/src/scope/index.js
Expand Up @@ -723,7 +723,7 @@ export default class Scope {
if (!this.isPure(prop, constantsOnly)) return false;
}
return true;
} else if (t.isClassMethod(node)) {
} else if (t.isMethod(node)) {
if (node.computed && !this.isPure(node.key, constantsOnly)) return false;
if (node.kind === "get" || node.kind === "set") return false;
return true;
Expand Down
8 changes: 7 additions & 1 deletion packages/babel-traverse/test/scope.js
Expand Up @@ -203,11 +203,17 @@ describe("scope", () => {

it("purity", function() {
expect(
getPath("({ x: 1 })")
getPath("({ x: 1, foo() { return 1 } })")
.get("body")[0]
.get("expression")
.isPure(),
).toBeTruthy();
expect(
getPath("class X { get foo() { return 1 } }")
.get("body")[0]
.get("expression")
.isPure(),
).toBeFalsy();
expect(
getPath("`${a}`")
.get("body")[0]
Expand Down

0 comments on commit 83d365a

Please sign in to comment.