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 <[email protected]>
This commit is contained in:
Yang Jun
2026-07-23 22:38:50 +08:00
co-authored by Cursor
parent 33e455282d
commit 5d0d884938
+2 -2
View File
@@ -155,10 +155,10 @@ export class Context {
}
}
const BLOCKED_SCOPE_KEYS = new Set(['__proto__', 'constructor', 'prototype'])
const BLOCKED_SCOPE_KEYS: ReadonlySet<PropertyKey> = 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