Skip to content

Commit 28fecad

Browse files
refactor(javascript): read own keys in terser-option-names without an object type
Claude-Session: https://claude.ai/code/session_01Tgxgyb4N35ndP6cC4KcrXC
1 parent 70d4ecc commit 28fecad

1 file changed

Lines changed: 5 additions & 10 deletions

File tree

‎lib/javascript/terser-option-names.js‎

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -52,14 +52,6 @@ const TERSER_ALIASES = {
5252
parse: ["bare_returns", "html5_comments"]
5353
};
5454

55-
/**
56-
* @param {object} object an object
57-
* @param {PropertyKey} property a key
58-
* @returns {boolean} whether the object has it as its own
59-
*/
60-
const hasOwn = (object, property) =>
61-
Object.prototype.hasOwnProperty.call(object, property);
62-
6355
/**
6456
* @param {string} name a snake_case name
6557
* @returns {string} the same name in camelCase
@@ -86,14 +78,17 @@ const camelCaseOf = (name) =>
8678
*/
8779
const renameGroup = (group, aliases, toTerser) => {
8880
const given = /** @type {Record<string, T[keyof T]>} */ (group);
81+
const { hasOwnProperty } = Object.prototype;
8982
let renamed = given;
9083
for (const alias of aliases) {
9184
const name = camelCaseOf(alias);
9285
const from = toTerser ? name : alias;
9386
const to = toTerser ? alias : name;
94-
if (!hasOwn(given, from)) continue;
87+
if (!hasOwnProperty.call(given, from)) continue;
9588
if (renamed === given) renamed = { ...given };
96-
if (toTerser || !hasOwn(given, to)) renamed[to] = given[from];
89+
if (toTerser || !hasOwnProperty.call(given, to)) {
90+
renamed[to] = given[from];
91+
}
9792
delete renamed[from];
9893
}
9994
return /** @type {T} */ (renamed);

0 commit comments

Comments
 (0)