vite-plugin-utils
Advanced tools
Comparing version 0.3.2 to 0.3.3
@@ -24,10 +24,10 @@ export declare function cleanUrl(url: string): string; | ||
*/ | ||
export declare function walk(ast: Record<string, any>, visitors: { | ||
[type: string]: (node: Record<string, any>) => void | Promise<void>; | ||
}): Promise<void>; | ||
export declare function walk<T = Record<string, any>>(ast: T, visitors: { | ||
[type: string]: (node: T, ancestors: T[]) => void | Promise<void>; | ||
}, ancestors?: T[]): Promise<void>; | ||
export declare namespace walk { | ||
var sync: (ast: Record<string, any>, visitors: { | ||
[type: string]: (node: Record<string, any>) => void | Promise<void>; | ||
}) => void; | ||
var sync: <T = Record<string, any>>(ast: T, visitors: { | ||
[type: string]: (node: T, ancestors: T[]) => void; | ||
}, ancestors?: T[]) => void; | ||
} | ||
export declare function normalizePath(id: string): string; |
@@ -63,3 +63,3 @@ import path from 'node:path'; | ||
*/ | ||
export async function walk(ast, visitors) { | ||
export async function walk(ast, visitors, ancestors = []) { | ||
var _a; | ||
@@ -70,13 +70,14 @@ if (!ast) | ||
for (const element of ast) { | ||
await walk(element, visitors); | ||
await walk(element, visitors, ancestors); | ||
} | ||
} | ||
else { | ||
ancestors = ancestors.concat(ast); | ||
for (const key of Object.keys(ast)) { | ||
await (typeof ast[key] === 'object' && walk(ast[key], visitors)); | ||
await (typeof ast[key] === 'object' && walk(ast[key], visitors, ancestors)); | ||
} | ||
} | ||
await ((_a = visitors[ast.type]) === null || _a === void 0 ? void 0 : _a.call(visitors, ast)); | ||
await ((_a = visitors[ast.type]) === null || _a === void 0 ? void 0 : _a.call(visitors, ast, ancestors)); | ||
} | ||
walk.sync = function walkSync(ast, visitors) { | ||
walk.sync = function walkSync(ast, visitors, ancestors = []) { | ||
var _a; | ||
@@ -87,11 +88,12 @@ if (!ast) | ||
for (const element of ast) { | ||
walk.sync(element, visitors); | ||
walkSync(element, visitors, ancestors); | ||
} | ||
} | ||
else { | ||
ancestors = ancestors.concat(ast); | ||
for (const key of Object.keys(ast)) { | ||
typeof ast[key] === 'object' && walk.sync(ast[key], visitors); | ||
typeof ast[key] === 'object' && walkSync(ast[key], visitors, ancestors); | ||
} | ||
} | ||
(_a = visitors[ast.type]) === null || _a === void 0 ? void 0 : _a.call(visitors, ast); | ||
(_a = visitors[ast.type]) === null || _a === void 0 ? void 0 : _a.call(visitors, ast, ancestors); | ||
}; | ||
@@ -98,0 +100,0 @@ const isWindows = os.platform() === 'win32'; |
{ | ||
"name": "vite-plugin-utils", | ||
"description": "A collection of opinionated Vite plugin utils", | ||
"version": "0.3.2", | ||
"version": "0.3.3", | ||
"type": "module", | ||
@@ -6,0 +6,0 @@ "main": "", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
22721
640