Skip to content

Commit

Permalink
improve typing
Browse files Browse the repository at this point in the history
  • Loading branch information
liuxingbaoyu committed May 31, 2022
1 parent 405c399 commit b652c00
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions packages/babel-core/src/transformation/util/clone-deep.ts
@@ -1,8 +1,10 @@
import type { types } from "@babel/core";

//https://github.com/babel/babel/pull/14583#discussion_r882828856
function deepClone(value, cache) {
function deepClone(value: any, cache: Map<any, any>): any {
if (value !== null) {
if (cache.has(value)) return cache.get(value);
let cloned;
let cloned: any;
if (Array.isArray(value)) {
cloned = new Array(value.length);
for (let i = 0; i < value.length; i++) {
Expand All @@ -26,7 +28,7 @@ function deepClone(value, cache) {
return value;
}

export default function (value) {
export default function <T = types.Node>(value: T): T {
if (typeof value !== "object") return value;
return deepClone(value, new Map());
}

0 comments on commit b652c00

Please sign in to comment.