diff options
author | toasted-nutbread <toasted-nutbread@users.noreply.github.com> | 2024-02-14 22:28:33 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-02-15 03:28:33 +0000 |
commit | dd27c3813c5442f70e997f644459617852bf629a (patch) | |
tree | 9d9c245fc5bcbb6d9edaa91d6c3a09c7efde6c13 /dev | |
parent | cb34e706ffa9366c73dfd7afc93e3da688ea6c4d (diff) |
Simplify custom clone function (#678)
Diffstat (limited to 'dev')
-rw-r--r-- | dev/manifest-util.js | 17 |
1 files changed, 4 insertions, 13 deletions
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); } |