Skip to content

Commit

Permalink
Revert "Only evaluate own String/Number/Math methods (babel#16033)"
Browse files Browse the repository at this point in the history
This reverts commit b13376b.
  • Loading branch information
Astrabacus committed Nov 5, 2023
1 parent dab8e95 commit 9ec1cb5
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 11 deletions.
7 changes: 2 additions & 5 deletions packages/babel-traverse/src/path/evaluation.ts
Expand Up @@ -444,11 +444,8 @@ function _evaluate(path: NodePath, state: State): any {
!isInvalidMethod(property.node.name)
) {
context = global[object.node.name];
const key = property.node.name;
// TODO(Babel 8): Use Object.hasOwn
if (Object.hasOwnProperty.call(context, key)) {
func = context[key as keyof typeof context];
}
// @ts-expect-error property may not exist in context object
func = context[property.node.name];
}

// "abc".charCodeAt(4)
Expand Down
6 changes: 0 additions & 6 deletions packages/babel-traverse/test/evaluation.js
Expand Up @@ -152,12 +152,6 @@ describe("evaluation", function () {
expect(eval_invalid_call.confident).toBe(false);
});

it("should not evaluate inherited methods", function () {
const path = getPath("Math.hasOwnProperty('min')");
const evalResult = path.get("body.0.expression").evaluate();
expect(evalResult.confident).toBe(false);
});

it("should evaluate global call expressions", function () {
expect(
getPath("isFinite(1);").get("body.0.expression").evaluate().value,
Expand Down

0 comments on commit 9ec1cb5

Please sign in to comment.