From dd27c3813c5442f70e997f644459617852bf629a Mon Sep 17 00:00:00 2001 From: toasted-nutbread Date: Wed, 14 Feb 2024 22:28:33 -0500 Subject: Simplify custom clone function (#678) --- dev/manifest-util.js | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) (limited to 'dev') diff --git a/dev/manifest-util.js b/dev/manifest-util.js index 741f8b31..40bde911 100644 --- a/dev/manifest-util.js +++ b/dev/manifest-util.js @@ -24,15 +24,6 @@ import {parseJson} from './json.js'; const dirname = path.dirname(fileURLToPath(import.meta.url)); -/** - * @template [T=unknown] - * @param {T} value - * @returns {T} - */ -function clone(value) { - return parseJson(JSON.stringify(value)); -} - export class ManifestUtil { constructor() { @@ -70,7 +61,7 @@ export class ManifestUtil { } } - return clone(this._manifest); + return structuredClone(this._manifest); } /** @@ -189,7 +180,7 @@ export class ManifestUtil { const {start, deleteCount, items} = modification; /** @type {unknown[]} */ const value = this._getObjectProperties(manifest, path2, path2.length); - const itemsNew = items.map((v) => clone(v)); + const itemsNew = items.map((v) => structuredClone(v)); value.splice(start, deleteCount, ...itemsNew); } break; @@ -229,7 +220,7 @@ export class ManifestUtil { const {items} = modification; /** @type {unknown[]} */ const value = this._getObjectProperties(manifest, path2, path2.length); - const itemsNew = items.map((v) => clone(v)); + const itemsNew = items.map((v) => structuredClone(v)); value.push(...itemsNew); } break; @@ -335,7 +326,7 @@ export class ManifestUtil { * @returns {import('dev/manifest').Manifest} */ _createVariantManifest(manifest, variant) { - let modifiedManifest = clone(manifest); + let modifiedManifest = structuredClone(manifest); for (const {modifications} of this._getInheritanceChain(variant)) { modifiedManifest = this._applyModifications(modifiedManifest, modifications); } -- cgit v1.2.3