Skip to content

Commit 10ab90e

Browse files
authored
refactor: Use object.prototype to check for reserved properties (#5670)
1 parent e1cba8e commit 10ab90e

File tree

1 file changed

+16
-8
lines changed

1 file changed

+16
-8
lines changed

src/finalisers/shared/setupNamespace.ts

+16-8
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,18 @@ export default function setupNamespace(
1313
log?: LogHandler
1414
): string {
1515
const parts = name.split('.');
16-
// Check if the key is exist in the prototype of the object
17-
const isReserved = parts[0] in {};
16+
// Check if the key exists in the object's prototype.
17+
const isReserved = parts[0] in Object.prototype;
1818
if (log && isReserved) {
1919
log(LOGLEVEL_WARN, logReservedNamespace(parts[0]));
2020
}
2121
parts[0] =
22-
(typeof globals === 'function' ? globals(parts[0]) : isReserved ? null : globals[parts[0]]) ||
23-
parts[0];
22+
(typeof globals === 'function'
23+
? globals(parts[0])
24+
: isReserved
25+
? parts[0]
26+
: globals[parts[0]]) || parts[0];
27+
2428
parts.pop();
2529

2630
let propertyPath = root;
@@ -43,14 +47,18 @@ export function assignToDeepVariable(
4347
log?: LogHandler
4448
): string {
4549
const parts = deepName.split('.');
46-
// Check if the key is exist in the prototype of the object
47-
const isReserved = parts[0] in {};
50+
// Check if the key exists in the object's prototype.
51+
const isReserved = parts[0] in Object.prototype;
4852
if (log && isReserved) {
4953
log(LOGLEVEL_WARN, logReservedNamespace(parts[0]));
5054
}
5155
parts[0] =
52-
(typeof globals === 'function' ? globals(parts[0]) : isReserved ? null : globals[parts[0]]) ||
53-
parts[0];
56+
(typeof globals === 'function'
57+
? globals(parts[0])
58+
: isReserved
59+
? parts[0]
60+
: globals[parts[0]]) || parts[0];
61+
5462
const last = parts.pop()!;
5563

5664
let propertyPath = root;

0 commit comments

Comments
 (0)