Skip to content

Commit 6031a33

Browse files
authored
disables optimization for external namespace when using the in operator (#6036)
1 parent 09794f1 commit 6031a33

File tree

4 files changed

+16
-5
lines changed

4 files changed

+16
-5
lines changed

src/ast/nodes/BinaryExpression.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import {
1313
UNKNOWN_PATH
1414
} from '../utils/PathTracker';
1515
import { getRenderedLiteralValue } from '../utils/renderLiteralValue';
16-
import type NamespaceVariable from '../variables/NamespaceVariable';
16+
import NamespaceVariable from '../variables/NamespaceVariable';
1717
import ExpressionStatement from './ExpressionStatement';
1818
import type { LiteralValue } from './Literal';
1919
import type * as NodeType from './NodeType';
@@ -105,10 +105,8 @@ export default class BinaryExpression extends NodeBase implements DeoptimizableE
105105
if (typeof leftValue === 'symbol') return UnknownValue;
106106

107107
// Optimize `'export' in namespace`
108-
if (this.operator === 'in' && this.right.variable?.isNamespace) {
109-
return (
110-
(this.right.variable as NamespaceVariable).context.traceExport(String(leftValue))[0] != null
111-
);
108+
if (this.operator === 'in' && this.right.variable instanceof NamespaceVariable) {
109+
return this.right.variable.context.traceExport(String(leftValue))[0] != null;
112110
}
113111

114112
const rightValue = this.right.getLiteralValueAtPath(EMPTY_PATH, recursionTracker, origin);
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
module.exports = {
2+
description: 'disables optimization for external namespace when using the in operator',
3+
options: {
4+
external: ['node:crypto']
5+
}
6+
};
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import * as nc from 'node:crypto';
2+
3+
const crypto = 'webcrypto' in nc;
4+
5+
export { crypto };
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
import * as nc from 'node:crypto';
2+
export const crypto = 'webcrypto' in nc;

0 commit comments

Comments
 (0)