From 5d0d88493876e7fabecd0d83d144410012b1ddcd Mon Sep 17 00:00:00 2001 From: Yang Jun Date: Thu, 23 Jul 2026 22:38:50 +0800 Subject: [PATCH] refactor: drop redundant typeof in blocked key check Set.has already returns false for non-string PropertyKey values; widen BLOCKED_SCOPE_KEYS type so TypeScript accepts the direct has(key) call. Co-authored-by: Cursor --- src/context/context.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/context/context.ts b/src/context/context.ts index 2619be6b6..959a1d8f2 100644 --- a/src/context/context.ts +++ b/src/context/context.ts @@ -155,10 +155,10 @@ export class Context { } } -const BLOCKED_SCOPE_KEYS = new Set(['__proto__', 'constructor', 'prototype']) +const BLOCKED_SCOPE_KEYS: ReadonlySet = new Set(['__proto__', 'constructor', 'prototype']) export function readJSProperty (obj: Scope, key: PropertyKey, ownPropertyOnly: boolean) { - if (typeof key === 'string' && BLOCKED_SCOPE_KEYS.has(key)) { + if (BLOCKED_SCOPE_KEYS.has(key)) { if (ownPropertyOnly || !hasOwnProperty.call(obj, key)) return undefined } if (ownPropertyOnly && !hasOwnProperty.call(obj, key) && !(obj instanceof Drop)) return undefined