Skip to content

Commit

Permalink
Do not mark in and instanceof as constant expressions (#15106)
Browse files Browse the repository at this point in the history
Do not mark `in` and `instanceof` as constant
  • Loading branch information
nicolo-ribaudo committed Oct 31, 2022
1 parent d6fbba5 commit e4bc031
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 0 deletions.
@@ -0,0 +1,7 @@
expect(() => {
class X { [0 in 0]; }
}).toThrow();

expect(() => {
class X { [0 instanceof 0]; }
}).toThrow();
@@ -0,0 +1,4 @@
class X {
[ 0 in 0 ];
[ 0 instanceof 0 ];
}
@@ -0,0 +1,3 @@
{
"plugins": ["proposal-class-properties"]
}
@@ -0,0 +1,9 @@
let _ref, _ref2;
_ref = 0 in 0;
_ref2 = 0 instanceof 0;
class X {
constructor() {
babelHelpers.defineProperty(this, _ref, void 0);
babelHelpers.defineProperty(this, _ref2, void 0);
}
}
3 changes: 3 additions & 0 deletions packages/babel-traverse/src/path/introspection.ts
Expand Up @@ -634,7 +634,10 @@ export function isConstantExpression(this: NodePath): boolean {
}

if (this.isBinaryExpression()) {
const { operator } = this.node;
return (
operator !== "in" &&
operator !== "instanceof" &&
this.get("left").isConstantExpression() &&
this.get("right").isConstantExpression()
);
Expand Down

0 comments on commit e4bc031

Please sign in to comment.