Skip to content

Commit 5613c8d

Browse files
committed
fix: use Object.prototype.hasOwnProperty instead of Object.hasOwn to improve compatibility
1 parent 302969c commit 5613c8d

3 files changed

Lines changed: 8 additions & 5 deletions

File tree

packages/core/src/parameter.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { DOUBLE_DASH } from "@clerc/parser";
2-
import { camelCase } from "@clerc/utils";
2+
import { camelCase, hasOwn } from "@clerc/utils";
33

44
import { InvalidParametersError } from "./errors";
55
import type { ParameterDefinitionValue } from "./types/parameter";
@@ -56,7 +56,7 @@ function _parseParameters(
5656
normalized.key,
5757
);
5858

59-
if (Object.hasOwn(result, name)) {
59+
if (hasOwn(result, name)) {
6060
throw new InvalidParametersError(`Duplicate parameter name: ${name}`);
6161
}
6262

packages/parser/src/utils.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { looseIsArray } from "@clerc/utils";
1+
import { hasOwn, looseIsArray } from "@clerc/utils";
22

33
import type { FlagOptions, TypeValue } from "./types";
44

@@ -121,7 +121,7 @@ export function appendDotValues(obj: any, path: string, value: any): void {
121121
const key = keys[i];
122122
// Check if the key exists and is not an object (path conflict)
123123
if (
124-
Object.hasOwn(current, key) &&
124+
hasOwn(current, key) &&
125125
(typeof current[key] !== "object" || current[key] === null)
126126
) {
127127
// current value is a primitive, cannot set nested property
@@ -132,7 +132,7 @@ export function appendDotValues(obj: any, path: string, value: any): void {
132132
}
133133
const lastKey = keys[keys.length - 1];
134134

135-
if (Object.hasOwn(current, lastKey)) {
135+
if (hasOwn(current, lastKey)) {
136136
const existing = current[lastKey];
137137
if (Array.isArray(existing)) {
138138
existing.push(value);

packages/utils/src/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,3 +96,6 @@ export const objectIsEmpty = (obj: Record<string, any>): boolean =>
9696

9797
export const resolveValue = <T>(value: MaybeGetter<T>): T =>
9898
typeof value === "function" ? (value as () => T)() : value;
99+
100+
export const hasOwn = (obj: object, key: PropertyKey): boolean =>
101+
Object.prototype.hasOwnProperty.call(obj, key);

0 commit comments

Comments
 (0)