@fuzdev/fuz_util 0.54.0 → 0.56.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/args.d.ts +12 -12
- package/dist/args.js +11 -11
- package/dist/async.d.ts +12 -12
- package/dist/async.js +12 -12
- package/dist/benchmark.d.ts +24 -24
- package/dist/benchmark.js +26 -26
- package/dist/benchmark_baseline.d.ts +17 -11
- package/dist/benchmark_baseline.d.ts.map +1 -1
- package/dist/benchmark_baseline.js +26 -19
- package/dist/benchmark_format.d.ts +15 -15
- package/dist/benchmark_format.js +15 -15
- package/dist/benchmark_stats.d.ts +30 -10
- package/dist/benchmark_stats.d.ts.map +1 -1
- package/dist/benchmark_stats.js +48 -40
- package/dist/benchmark_types.d.ts +7 -7
- package/dist/bytes.d.ts +4 -4
- package/dist/bytes.js +4 -4
- package/dist/dag.d.ts +2 -2
- package/dist/dag.js +2 -2
- package/dist/deep_equal.d.ts +2 -2
- package/dist/deep_equal.js +2 -2
- package/dist/diff.d.ts +17 -17
- package/dist/diff.js +17 -17
- package/dist/dom.d.ts +4 -4
- package/dist/dom.js +4 -4
- package/dist/fetch.d.ts +1 -1
- package/dist/fetch.js +1 -1
- package/dist/git.d.ts +1 -1
- package/dist/git.js +1 -1
- package/dist/hash.d.ts +6 -6
- package/dist/hash.js +8 -8
- package/dist/hash_blake3.d.ts +1 -1
- package/dist/hash_blake3.js +1 -1
- package/dist/hex.d.ts +4 -4
- package/dist/hex.js +4 -4
- package/dist/json.d.ts +2 -2
- package/dist/json.js +2 -2
- package/dist/log.d.ts +12 -12
- package/dist/log.js +11 -11
- package/dist/map.d.ts +1 -1
- package/dist/map.js +1 -1
- package/dist/object.d.ts +1 -1
- package/dist/object.js +1 -1
- package/dist/package_json.d.ts +1 -1
- package/dist/package_json.js +1 -1
- package/dist/path.d.ts +5 -5
- package/dist/path.js +5 -5
- package/dist/process.d.ts +22 -22
- package/dist/process.js +22 -22
- package/dist/random.d.ts +2 -2
- package/dist/random.js +2 -2
- package/dist/result.d.ts +6 -6
- package/dist/result.js +6 -6
- package/dist/sort.d.ts +3 -3
- package/dist/sort.js +3 -3
- package/dist/source_json.d.ts +3 -3
- package/dist/source_json.js +3 -3
- package/dist/stats.d.ts +17 -17
- package/dist/stats.js +17 -17
- package/dist/string.d.ts +6 -6
- package/dist/string.js +6 -6
- package/dist/svelte_preprocess_helpers.d.ts +42 -42
- package/dist/svelte_preprocess_helpers.js +42 -42
- package/dist/testing.d.ts +44 -0
- package/dist/testing.d.ts.map +1 -0
- package/dist/testing.js +59 -0
- package/dist/time.d.ts +19 -19
- package/dist/time.js +19 -19
- package/dist/zod.d.ts +16 -16
- package/dist/zod.d.ts.map +1 -1
- package/dist/zod.js +24 -24
- package/package.json +6 -6
- package/src/lib/args.ts +12 -12
- package/src/lib/async.ts +12 -12
- package/src/lib/benchmark.ts +28 -28
- package/src/lib/benchmark_baseline.ts +37 -20
- package/src/lib/benchmark_format.ts +15 -15
- package/src/lib/benchmark_stats.ts +66 -44
- package/src/lib/benchmark_types.ts +7 -7
- package/src/lib/bytes.ts +4 -4
- package/src/lib/dag.ts +2 -2
- package/src/lib/deep_equal.ts +2 -2
- package/src/lib/diff.ts +17 -17
- package/src/lib/dom.ts +4 -4
- package/src/lib/fetch.ts +1 -1
- package/src/lib/git.ts +1 -1
- package/src/lib/hash.ts +8 -8
- package/src/lib/hash_blake3.ts +1 -1
- package/src/lib/hex.ts +4 -4
- package/src/lib/json.ts +2 -2
- package/src/lib/log.ts +12 -12
- package/src/lib/map.ts +1 -1
- package/src/lib/object.ts +1 -1
- package/src/lib/package_json.ts +1 -1
- package/src/lib/path.ts +5 -5
- package/src/lib/process.ts +22 -22
- package/src/lib/random.ts +2 -2
- package/src/lib/result.ts +6 -6
- package/src/lib/sort.ts +3 -3
- package/src/lib/source_json.ts +3 -3
- package/src/lib/stats.ts +17 -17
- package/src/lib/string.ts +6 -6
- package/src/lib/svelte_preprocess_helpers.ts +42 -42
- package/src/lib/testing.ts +80 -0
- package/src/lib/time.ts +19 -19
- package/src/lib/zod.ts +24 -24
|
@@ -33,9 +33,9 @@ export interface ResolvedComponentImport {
|
|
|
33
33
|
* Iterates the node's `attributes` array and returns the first `Attribute`
|
|
34
34
|
* node whose `name` matches. Skips `SpreadAttribute`, directive, and other node types.
|
|
35
35
|
*
|
|
36
|
-
* @param node
|
|
37
|
-
* @param name
|
|
38
|
-
* @returns
|
|
36
|
+
* @param node - the component AST node to search
|
|
37
|
+
* @param name - the attribute name to find
|
|
38
|
+
* @returns the matching `Attribute` node, or `undefined` if not found
|
|
39
39
|
*/
|
|
40
40
|
export declare const find_attribute: (node: AST.Component, name: string) => AST.Attribute | undefined;
|
|
41
41
|
/**
|
|
@@ -46,9 +46,9 @@ export declare const find_attribute: (node: AST.Component, name: string) => AST.
|
|
|
46
46
|
* via an optional bindings map built by `build_static_bindings`.
|
|
47
47
|
* Returns `null` for dynamic expressions, non-string literals, or unsupported node types.
|
|
48
48
|
*
|
|
49
|
-
* @param expr
|
|
50
|
-
* @param bindings
|
|
51
|
-
* @returns
|
|
49
|
+
* @param expr - an ESTree expression AST node
|
|
50
|
+
* @param bindings - optional map of variable names to their resolved static string values
|
|
51
|
+
* @returns the resolved static string, or `null` if the expression is dynamic
|
|
52
52
|
*/
|
|
53
53
|
export declare const evaluate_static_expr: (expr: Expression, bindings?: ReadonlyMap<string, string>) => string | null;
|
|
54
54
|
/**
|
|
@@ -62,9 +62,9 @@ export declare const evaluate_static_expr: (expr: Expression, bindings?: Readonl
|
|
|
62
62
|
*
|
|
63
63
|
* Returns `null` for null literals, mixed arrays, dynamic expressions, and non-string values.
|
|
64
64
|
*
|
|
65
|
-
* @param value
|
|
66
|
-
* @param bindings
|
|
67
|
-
* @returns
|
|
65
|
+
* @param value - the attribute value from `AST.Attribute['value']`
|
|
66
|
+
* @param bindings - optional map of variable names to their resolved static string values
|
|
67
|
+
* @returns the resolved static string, or `null` if the value is dynamic
|
|
68
68
|
*/
|
|
69
69
|
export declare const extract_static_string: (value: AST.Attribute["value"], bindings?: ReadonlyMap<string, string>) => string | null;
|
|
70
70
|
/** A single branch in a conditional chain extracted from nested ternary expressions. */
|
|
@@ -88,10 +88,10 @@ export interface ConditionalChainBranch {
|
|
|
88
88
|
*
|
|
89
89
|
* A 2-branch result covers the simple ternary case (`a ? 'x' : 'y'`).
|
|
90
90
|
*
|
|
91
|
-
* @param value
|
|
92
|
-
* @param source
|
|
93
|
-
* @param bindings
|
|
94
|
-
* @returns
|
|
91
|
+
* @param value - the attribute value from `AST.Attribute['value']`
|
|
92
|
+
* @param source - the full source string (needed to slice test expression source text)
|
|
93
|
+
* @param bindings - map of variable names to their resolved static string values
|
|
94
|
+
* @returns array of conditional chain branches, or `null` if not extractable
|
|
95
95
|
*/
|
|
96
96
|
export declare const try_extract_conditional_chain: (value: AST.Attribute["value"], source: string, bindings: ReadonlyMap<string, string>) => Array<ConditionalChainBranch> | null;
|
|
97
97
|
/**
|
|
@@ -105,8 +105,8 @@ export declare const try_extract_conditional_chain: (value: AST.Attribute["value
|
|
|
105
105
|
* Skips destructuring patterns, `let`/`var` declarations, and declarations
|
|
106
106
|
* whose initializers reference dynamic values.
|
|
107
107
|
*
|
|
108
|
-
* @param ast
|
|
109
|
-
* @returns
|
|
108
|
+
* @param ast - the parsed Svelte AST root node
|
|
109
|
+
* @returns map of variable names to their resolved static string values
|
|
110
110
|
*/
|
|
111
111
|
export declare const build_static_bindings: (ast: AST.Root) => Map<string, string>;
|
|
112
112
|
/**
|
|
@@ -117,9 +117,9 @@ export declare const build_static_bindings: (ast: AST.Root) => Map<string, strin
|
|
|
117
117
|
* and `import type` declarations (both whole-declaration and per-specifier).
|
|
118
118
|
* Returns import node references alongside names to support import removal.
|
|
119
119
|
*
|
|
120
|
-
* @param ast
|
|
121
|
-
* @param component_imports
|
|
122
|
-
* @returns
|
|
120
|
+
* @param ast - the parsed Svelte AST root node
|
|
121
|
+
* @param component_imports - array of import source paths to match against
|
|
122
|
+
* @returns map of local names to their resolved import info
|
|
123
123
|
*/
|
|
124
124
|
export declare const resolve_component_names: (ast: AST.Root, component_imports: Array<string>) => Map<string, ResolvedComponentImport>;
|
|
125
125
|
/**
|
|
@@ -128,8 +128,8 @@ export declare const resolve_component_names: (ast: AST.Root, component_imports:
|
|
|
128
128
|
* Returns the end position of the last `ImportDeclaration`, or the start
|
|
129
129
|
* of the script body content if no imports exist.
|
|
130
130
|
*
|
|
131
|
-
* @param script
|
|
132
|
-
* @returns
|
|
131
|
+
* @param script - the parsed `AST.Script` node
|
|
132
|
+
* @returns the character position where new imports should be inserted
|
|
133
133
|
*/
|
|
134
134
|
export declare const find_import_insert_position: (script: AST.Script) => number;
|
|
135
135
|
/**
|
|
@@ -138,9 +138,9 @@ export declare const find_import_insert_position: (script: AST.Script) => number
|
|
|
138
138
|
* Default imports produce `import Name from 'path';` lines.
|
|
139
139
|
* Named imports are grouped by path into `import {a, b} from 'path';` lines.
|
|
140
140
|
*
|
|
141
|
-
* @param imports
|
|
142
|
-
* @param indent
|
|
143
|
-
* @returns
|
|
141
|
+
* @param imports - map of local names to their import info
|
|
142
|
+
* @param indent - indentation prefix for each line @default '\t'
|
|
143
|
+
* @returns a string of newline-separated import statements
|
|
144
144
|
*/
|
|
145
145
|
export declare const generate_import_lines: (imports: Map<string, PreprocessImportInfo>, indent?: string) => string;
|
|
146
146
|
/**
|
|
@@ -158,10 +158,10 @@ export declare const generate_import_lines: (imports: Map<string, PreprocessImpo
|
|
|
158
158
|
* Safe for Svelte template ASTs: `Component.name` is a plain string property
|
|
159
159
|
* (not an `Identifier` node), so `<Mdz>` tags do not produce false matches.
|
|
160
160
|
*
|
|
161
|
-
* @param node
|
|
162
|
-
* @param name
|
|
163
|
-
* @param skip
|
|
164
|
-
* @returns `true` if a matching `Identifier` node is found
|
|
161
|
+
* @param node - the AST subtree to search
|
|
162
|
+
* @param name - the identifier name to look for
|
|
163
|
+
* @param skip - set of AST nodes to skip during traversal
|
|
164
|
+
* @returns `true` if a matching `Identifier` node is found
|
|
165
165
|
*/
|
|
166
166
|
export declare const has_identifier_in_tree: (node: unknown, name: string, skip?: Set<unknown>) => boolean;
|
|
167
167
|
/**
|
|
@@ -188,9 +188,9 @@ export declare const escape_svelte_text: (text: string) => string;
|
|
|
188
188
|
* blank lines. Only safe for single-declarator statements (`const x = 'val';`);
|
|
189
189
|
* callers must verify `node.declarations.length === 1` before calling.
|
|
190
190
|
*
|
|
191
|
-
* @param s
|
|
192
|
-
* @param declaration_node
|
|
193
|
-
* @param source
|
|
191
|
+
* @param s - the MagicString instance to modify
|
|
192
|
+
* @param declaration_node - the `VariableDeclaration` AST node with Svelte position data
|
|
193
|
+
* @param source - the original source string
|
|
194
194
|
*/
|
|
195
195
|
export declare const remove_variable_declaration: (s: {
|
|
196
196
|
remove: (start: number, end: number) => unknown;
|
|
@@ -204,9 +204,9 @@ export declare const remove_variable_declaration: (s: {
|
|
|
204
204
|
* Consumes leading whitespace (tabs/spaces) and trailing newline to avoid leaving
|
|
205
205
|
* blank lines.
|
|
206
206
|
*
|
|
207
|
-
* @param s
|
|
208
|
-
* @param import_node
|
|
209
|
-
* @param source
|
|
207
|
+
* @param s - the MagicString instance to modify
|
|
208
|
+
* @param import_node - the `ImportDeclaration` AST node with Svelte position data
|
|
209
|
+
* @param source - the original source string
|
|
210
210
|
*/
|
|
211
211
|
export declare const remove_import_declaration: (s: {
|
|
212
212
|
remove: (start: number, end: number) => unknown;
|
|
@@ -225,11 +225,11 @@ export declare const remove_import_declaration: (s: {
|
|
|
225
225
|
* - `import {default as Mdz, other} from '...'` → `import {other} from '...'`
|
|
226
226
|
* - `import {Mdz, other} from '...'` → `import {other} from '...'`
|
|
227
227
|
*
|
|
228
|
-
* @param s
|
|
229
|
-
* @param node
|
|
230
|
-
* @param specifier_to_remove
|
|
231
|
-
* @param source
|
|
232
|
-
* @param additional_lines
|
|
228
|
+
* @param s - the MagicString instance to modify
|
|
229
|
+
* @param node - the positioned `ImportDeclaration` AST node
|
|
230
|
+
* @param specifier_to_remove - the specifier to remove from the import
|
|
231
|
+
* @param source - the original source string
|
|
232
|
+
* @param additional_lines - extra content appended after the reconstructed import
|
|
233
233
|
* (used to bundle new imports into the overwrite to avoid MagicString boundary conflicts).
|
|
234
234
|
*/
|
|
235
235
|
export declare const remove_import_specifier: (s: {
|
|
@@ -241,10 +241,10 @@ export declare const remove_import_specifier: (s: {
|
|
|
241
241
|
/**
|
|
242
242
|
* Handles errors during Svelte preprocessing with configurable behavior.
|
|
243
243
|
*
|
|
244
|
-
* @param error
|
|
245
|
-
* @param prefix
|
|
246
|
-
* @param filename
|
|
247
|
-
* @param on_error `'throw'` to re-throw as a new Error, `'log'` to console.error
|
|
244
|
+
* @param error - the caught error
|
|
245
|
+
* @param prefix - log prefix (e.g. `'[fuz-mdz]'`, `'[fuz-code]'`)
|
|
246
|
+
* @param filename - the file being processed
|
|
247
|
+
* @param on_error - `'throw'` to re-throw as a new Error, `'log'` to console.error
|
|
248
248
|
*/
|
|
249
249
|
export declare const handle_preprocess_error: (error: unknown, prefix: string, filename: string | undefined, on_error: "throw" | "log") => void;
|
|
250
250
|
//# sourceMappingURL=svelte_preprocess_helpers.d.ts.map
|
|
@@ -17,9 +17,9 @@
|
|
|
17
17
|
* Iterates the node's `attributes` array and returns the first `Attribute`
|
|
18
18
|
* node whose `name` matches. Skips `SpreadAttribute`, directive, and other node types.
|
|
19
19
|
*
|
|
20
|
-
* @param node
|
|
21
|
-
* @param name
|
|
22
|
-
* @returns
|
|
20
|
+
* @param node - the component AST node to search
|
|
21
|
+
* @param name - the attribute name to find
|
|
22
|
+
* @returns the matching `Attribute` node, or `undefined` if not found
|
|
23
23
|
*/
|
|
24
24
|
export const find_attribute = (node, name) => {
|
|
25
25
|
for (const attr of node.attributes) {
|
|
@@ -37,9 +37,9 @@ export const find_attribute = (node, name) => {
|
|
|
37
37
|
* via an optional bindings map built by `build_static_bindings`.
|
|
38
38
|
* Returns `null` for dynamic expressions, non-string literals, or unsupported node types.
|
|
39
39
|
*
|
|
40
|
-
* @param expr
|
|
41
|
-
* @param bindings
|
|
42
|
-
* @returns
|
|
40
|
+
* @param expr - an ESTree expression AST node
|
|
41
|
+
* @param bindings - optional map of variable names to their resolved static string values
|
|
42
|
+
* @returns the resolved static string, or `null` if the expression is dynamic
|
|
43
43
|
*/
|
|
44
44
|
export const evaluate_static_expr = (expr, bindings) => {
|
|
45
45
|
if (expr.type === 'Literal' && typeof expr.value === 'string')
|
|
@@ -89,9 +89,9 @@ export const evaluate_static_expr = (expr, bindings) => {
|
|
|
89
89
|
*
|
|
90
90
|
* Returns `null` for null literals, mixed arrays, dynamic expressions, and non-string values.
|
|
91
91
|
*
|
|
92
|
-
* @param value
|
|
93
|
-
* @param bindings
|
|
94
|
-
* @returns
|
|
92
|
+
* @param value - the attribute value from `AST.Attribute['value']`
|
|
93
|
+
* @param bindings - optional map of variable names to their resolved static string values
|
|
94
|
+
* @returns the resolved static string, or `null` if the value is dynamic
|
|
95
95
|
*/
|
|
96
96
|
export const extract_static_string = (value, bindings) => {
|
|
97
97
|
// Boolean attribute (e.g., <Mdz inline />)
|
|
@@ -126,10 +126,10 @@ export const extract_static_string = (value, bindings) => {
|
|
|
126
126
|
*
|
|
127
127
|
* A 2-branch result covers the simple ternary case (`a ? 'x' : 'y'`).
|
|
128
128
|
*
|
|
129
|
-
* @param value
|
|
130
|
-
* @param source
|
|
131
|
-
* @param bindings
|
|
132
|
-
* @returns
|
|
129
|
+
* @param value - the attribute value from `AST.Attribute['value']`
|
|
130
|
+
* @param source - the full source string (needed to slice test expression source text)
|
|
131
|
+
* @param bindings - map of variable names to their resolved static string values
|
|
132
|
+
* @returns array of conditional chain branches, or `null` if not extractable
|
|
133
133
|
*/
|
|
134
134
|
export const try_extract_conditional_chain = (value, source, bindings) => {
|
|
135
135
|
if (value === true || Array.isArray(value))
|
|
@@ -178,8 +178,8 @@ export const try_extract_conditional_chain = (value, source, bindings) => {
|
|
|
178
178
|
* Skips destructuring patterns, `let`/`var` declarations, and declarations
|
|
179
179
|
* whose initializers reference dynamic values.
|
|
180
180
|
*
|
|
181
|
-
* @param ast
|
|
182
|
-
* @returns
|
|
181
|
+
* @param ast - the parsed Svelte AST root node
|
|
182
|
+
* @returns map of variable names to their resolved static string values
|
|
183
183
|
*/
|
|
184
184
|
export const build_static_bindings = (ast) => {
|
|
185
185
|
const bindings = new Map();
|
|
@@ -211,9 +211,9 @@ export const build_static_bindings = (ast) => {
|
|
|
211
211
|
* and `import type` declarations (both whole-declaration and per-specifier).
|
|
212
212
|
* Returns import node references alongside names to support import removal.
|
|
213
213
|
*
|
|
214
|
-
* @param ast
|
|
215
|
-
* @param component_imports
|
|
216
|
-
* @returns
|
|
214
|
+
* @param ast - the parsed Svelte AST root node
|
|
215
|
+
* @param component_imports - array of import source paths to match against
|
|
216
|
+
* @returns map of local names to their resolved import info
|
|
217
217
|
*/
|
|
218
218
|
export const resolve_component_names = (ast, component_imports) => {
|
|
219
219
|
const names = new Map();
|
|
@@ -247,8 +247,8 @@ export const resolve_component_names = (ast, component_imports) => {
|
|
|
247
247
|
* Returns the end position of the last `ImportDeclaration`, or the start
|
|
248
248
|
* of the script body content if no imports exist.
|
|
249
249
|
*
|
|
250
|
-
* @param script
|
|
251
|
-
* @returns
|
|
250
|
+
* @param script - the parsed `AST.Script` node
|
|
251
|
+
* @returns the character position where new imports should be inserted
|
|
252
252
|
*/
|
|
253
253
|
export const find_import_insert_position = (script) => {
|
|
254
254
|
let last_import_end = -1;
|
|
@@ -269,9 +269,9 @@ export const find_import_insert_position = (script) => {
|
|
|
269
269
|
* Default imports produce `import Name from 'path';` lines.
|
|
270
270
|
* Named imports are grouped by path into `import {a, b} from 'path';` lines.
|
|
271
271
|
*
|
|
272
|
-
* @param imports
|
|
273
|
-
* @param indent
|
|
274
|
-
* @returns
|
|
272
|
+
* @param imports - map of local names to their import info
|
|
273
|
+
* @param indent - indentation prefix for each line @default '\t'
|
|
274
|
+
* @returns a string of newline-separated import statements
|
|
275
275
|
*/
|
|
276
276
|
export const generate_import_lines = (imports, indent = '\t') => {
|
|
277
277
|
const default_imports = [];
|
|
@@ -333,10 +333,10 @@ const NON_REFERENCE_FIELDS = new Map([
|
|
|
333
333
|
* Safe for Svelte template ASTs: `Component.name` is a plain string property
|
|
334
334
|
* (not an `Identifier` node), so `<Mdz>` tags do not produce false matches.
|
|
335
335
|
*
|
|
336
|
-
* @param node
|
|
337
|
-
* @param name
|
|
338
|
-
* @param skip
|
|
339
|
-
* @returns `true` if a matching `Identifier` node is found
|
|
336
|
+
* @param node - the AST subtree to search
|
|
337
|
+
* @param name - the identifier name to look for
|
|
338
|
+
* @param skip - set of AST nodes to skip during traversal
|
|
339
|
+
* @returns `true` if a matching `Identifier` node is found
|
|
340
340
|
*/
|
|
341
341
|
export const has_identifier_in_tree = (node, name, skip) => {
|
|
342
342
|
if (node === null || node === undefined || typeof node !== 'object')
|
|
@@ -396,9 +396,9 @@ export const escape_svelte_text = (text) => text.replace(/[{}<&]/g, (ch) => {
|
|
|
396
396
|
* blank lines. Only safe for single-declarator statements (`const x = 'val';`);
|
|
397
397
|
* callers must verify `node.declarations.length === 1` before calling.
|
|
398
398
|
*
|
|
399
|
-
* @param s
|
|
400
|
-
* @param declaration_node
|
|
401
|
-
* @param source
|
|
399
|
+
* @param s - the MagicString instance to modify
|
|
400
|
+
* @param declaration_node - the `VariableDeclaration` AST node with Svelte position data
|
|
401
|
+
* @param source - the original source string
|
|
402
402
|
*/
|
|
403
403
|
export const remove_variable_declaration = (s, declaration_node, source) => {
|
|
404
404
|
remove_positioned_node(s, declaration_node, source);
|
|
@@ -409,9 +409,9 @@ export const remove_variable_declaration = (s, declaration_node, source) => {
|
|
|
409
409
|
* Consumes leading whitespace (tabs/spaces) and trailing newline to avoid leaving
|
|
410
410
|
* blank lines.
|
|
411
411
|
*
|
|
412
|
-
* @param s
|
|
413
|
-
* @param import_node
|
|
414
|
-
* @param source
|
|
412
|
+
* @param s - the MagicString instance to modify
|
|
413
|
+
* @param import_node - the `ImportDeclaration` AST node with Svelte position data
|
|
414
|
+
* @param source - the original source string
|
|
415
415
|
*/
|
|
416
416
|
export const remove_import_declaration = (s, import_node, source) => {
|
|
417
417
|
remove_positioned_node(s, import_node, source);
|
|
@@ -450,11 +450,11 @@ const remove_positioned_node = (s, node, source) => {
|
|
|
450
450
|
* - `import {default as Mdz, other} from '...'` → `import {other} from '...'`
|
|
451
451
|
* - `import {Mdz, other} from '...'` → `import {other} from '...'`
|
|
452
452
|
*
|
|
453
|
-
* @param s
|
|
454
|
-
* @param node
|
|
455
|
-
* @param specifier_to_remove
|
|
456
|
-
* @param source
|
|
457
|
-
* @param additional_lines
|
|
453
|
+
* @param s - the MagicString instance to modify
|
|
454
|
+
* @param node - the positioned `ImportDeclaration` AST node
|
|
455
|
+
* @param specifier_to_remove - the specifier to remove from the import
|
|
456
|
+
* @param source - the original source string
|
|
457
|
+
* @param additional_lines - extra content appended after the reconstructed import
|
|
458
458
|
* (used to bundle new imports into the overwrite to avoid MagicString boundary conflicts).
|
|
459
459
|
*/
|
|
460
460
|
export const remove_import_specifier = (s, node, specifier_to_remove, source, additional_lines = '') => {
|
|
@@ -501,10 +501,10 @@ const format_named_specifiers = (specs) => specs
|
|
|
501
501
|
/**
|
|
502
502
|
* Handles errors during Svelte preprocessing with configurable behavior.
|
|
503
503
|
*
|
|
504
|
-
* @param error
|
|
505
|
-
* @param prefix
|
|
506
|
-
* @param filename
|
|
507
|
-
* @param on_error `'throw'` to re-throw as a new Error, `'log'` to console.error
|
|
504
|
+
* @param error - the caught error
|
|
505
|
+
* @param prefix - log prefix (e.g. `'[fuz-mdz]'`, `'[fuz-code]'`)
|
|
506
|
+
* @param filename - the file being processed
|
|
507
|
+
* @param on_error - `'throw'` to re-throw as a new Error, `'log'` to console.error
|
|
508
508
|
*/
|
|
509
509
|
export const handle_preprocess_error = (error, prefix, filename, on_error) => {
|
|
510
510
|
const message = `${prefix} Preprocessing failed${filename ? ` in ${filename}` : ''}: ${error instanceof Error ? error.message : String(error)}`;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared test assertions for the `@fuzdev` ecosystem.
|
|
3
|
+
*
|
|
4
|
+
* Extends the fuz-stack testing conventions (`assert` from vitest, tests in `src/test/`,
|
|
5
|
+
* plain object mocks) with reusable helpers for patterns that appear across multiple repos.
|
|
6
|
+
* Only depends on vitest — safe for fuz_util's zero-runtime-deps constraint.
|
|
7
|
+
*
|
|
8
|
+
* @module
|
|
9
|
+
*/
|
|
10
|
+
import type { Logger } from './log.js';
|
|
11
|
+
/**
|
|
12
|
+
* Asserts that `fn` rejects with an `Error`.
|
|
13
|
+
* Optionally matches the error message against `pattern`.
|
|
14
|
+
* Returns the caught `Error` for further assertions by the caller.
|
|
15
|
+
*
|
|
16
|
+
* `assert.fail` is placed after the catch block so that assertion failures
|
|
17
|
+
* from the test itself are not swallowed by the catch.
|
|
18
|
+
*
|
|
19
|
+
* @param fn - async function expected to reject
|
|
20
|
+
* @param pattern - optional regex to match against the error message
|
|
21
|
+
* @returns the caught `Error`
|
|
22
|
+
*/
|
|
23
|
+
export declare const assert_rejects: (fn: () => Promise<unknown>, pattern?: RegExp) => Promise<Error>;
|
|
24
|
+
/**
|
|
25
|
+
* A mock `Logger` with `vi.fn()` methods and call tracking arrays.
|
|
26
|
+
* Assignable to `Logger` for use in code under test.
|
|
27
|
+
* Each tracking array captures the first argument of each call.
|
|
28
|
+
* For full call details, use `vi.fn()` introspection on the methods directly.
|
|
29
|
+
*/
|
|
30
|
+
export type MockLogger = Logger & {
|
|
31
|
+
error_calls: Array<unknown>;
|
|
32
|
+
warn_calls: Array<unknown>;
|
|
33
|
+
info_calls: Array<unknown>;
|
|
34
|
+
debug_calls: Array<unknown>;
|
|
35
|
+
};
|
|
36
|
+
/**
|
|
37
|
+
* Creates a mock `Logger` with `vi.fn()` on each logging method
|
|
38
|
+
* and tracking arrays for inspecting logged messages.
|
|
39
|
+
* Follows the fuz-stack convention of plain object mocks over mocking libraries.
|
|
40
|
+
*
|
|
41
|
+
* @returns a `MockLogger` assignable to `Logger`
|
|
42
|
+
*/
|
|
43
|
+
export declare const create_mock_logger: () => MockLogger;
|
|
44
|
+
//# sourceMappingURL=testing.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"testing.d.ts","sourceRoot":"../src/lib/","sources":["../src/lib/testing.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAIH,OAAO,KAAK,EAAC,MAAM,EAAC,MAAM,UAAU,CAAC;AAErC;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,cAAc,GAC1B,IAAI,MAAM,OAAO,CAAC,OAAO,CAAC,EAC1B,UAAU,MAAM,KACd,OAAO,CAAC,KAAK,CAWf,CAAC;AAEF;;;;;GAKG;AACH,MAAM,MAAM,UAAU,GAAG,MAAM,GAAG;IACjC,WAAW,EAAE,KAAK,CAAC,OAAO,CAAC,CAAC;IAC5B,UAAU,EAAE,KAAK,CAAC,OAAO,CAAC,CAAC;IAC3B,UAAU,EAAE,KAAK,CAAC,OAAO,CAAC,CAAC;IAC3B,WAAW,EAAE,KAAK,CAAC,OAAO,CAAC,CAAC;CAC5B,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,kBAAkB,QAAO,UAiBrC,CAAC"}
|
package/dist/testing.js
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared test assertions for the `@fuzdev` ecosystem.
|
|
3
|
+
*
|
|
4
|
+
* Extends the fuz-stack testing conventions (`assert` from vitest, tests in `src/test/`,
|
|
5
|
+
* plain object mocks) with reusable helpers for patterns that appear across multiple repos.
|
|
6
|
+
* Only depends on vitest — safe for fuz_util's zero-runtime-deps constraint.
|
|
7
|
+
*
|
|
8
|
+
* @module
|
|
9
|
+
*/
|
|
10
|
+
import { assert, vi } from 'vitest';
|
|
11
|
+
/**
|
|
12
|
+
* Asserts that `fn` rejects with an `Error`.
|
|
13
|
+
* Optionally matches the error message against `pattern`.
|
|
14
|
+
* Returns the caught `Error` for further assertions by the caller.
|
|
15
|
+
*
|
|
16
|
+
* `assert.fail` is placed after the catch block so that assertion failures
|
|
17
|
+
* from the test itself are not swallowed by the catch.
|
|
18
|
+
*
|
|
19
|
+
* @param fn - async function expected to reject
|
|
20
|
+
* @param pattern - optional regex to match against the error message
|
|
21
|
+
* @returns the caught `Error`
|
|
22
|
+
*/
|
|
23
|
+
export const assert_rejects = async (fn, pattern) => {
|
|
24
|
+
try {
|
|
25
|
+
await fn();
|
|
26
|
+
}
|
|
27
|
+
catch (err) {
|
|
28
|
+
assert(err instanceof Error, 'Expected rejection to be an Error');
|
|
29
|
+
if (pattern) {
|
|
30
|
+
assert.match(err.message, pattern);
|
|
31
|
+
}
|
|
32
|
+
return err;
|
|
33
|
+
}
|
|
34
|
+
assert.fail('Expected to throw');
|
|
35
|
+
};
|
|
36
|
+
/**
|
|
37
|
+
* Creates a mock `Logger` with `vi.fn()` on each logging method
|
|
38
|
+
* and tracking arrays for inspecting logged messages.
|
|
39
|
+
* Follows the fuz-stack convention of plain object mocks over mocking libraries.
|
|
40
|
+
*
|
|
41
|
+
* @returns a `MockLogger` assignable to `Logger`
|
|
42
|
+
*/
|
|
43
|
+
export const create_mock_logger = () => {
|
|
44
|
+
const error_calls = [];
|
|
45
|
+
const warn_calls = [];
|
|
46
|
+
const info_calls = [];
|
|
47
|
+
const debug_calls = [];
|
|
48
|
+
return {
|
|
49
|
+
error: vi.fn((msg) => error_calls.push(msg)),
|
|
50
|
+
warn: vi.fn((msg) => warn_calls.push(msg)),
|
|
51
|
+
info: vi.fn((msg) => info_calls.push(msg)),
|
|
52
|
+
debug: vi.fn((msg) => debug_calls.push(msg)),
|
|
53
|
+
raw: vi.fn(),
|
|
54
|
+
error_calls,
|
|
55
|
+
warn_calls,
|
|
56
|
+
info_calls,
|
|
57
|
+
debug_calls,
|
|
58
|
+
};
|
|
59
|
+
};
|
package/dist/time.d.ts
CHANGED
|
@@ -65,23 +65,23 @@ export declare const TIME_UNIT_DISPLAY: Record<TimeUnit, string>;
|
|
|
65
65
|
/**
|
|
66
66
|
* Detect the best time unit for a set of nanosecond values.
|
|
67
67
|
* Chooses the unit where most values fall in the range 1-9999.
|
|
68
|
-
* @param values_ns -
|
|
69
|
-
* @returns
|
|
68
|
+
* @param values_ns - array of times in nanoseconds
|
|
69
|
+
* @returns best unit to use for all values
|
|
70
70
|
*/
|
|
71
71
|
export declare const time_unit_detect_best: (values_ns: Array<number>) => TimeUnit;
|
|
72
72
|
/**
|
|
73
73
|
* Format time with a specific unit.
|
|
74
|
-
* @param ns -
|
|
75
|
-
* @param unit -
|
|
76
|
-
* @param decimals -
|
|
77
|
-
* @returns
|
|
74
|
+
* @param ns - time in nanoseconds
|
|
75
|
+
* @param unit - unit to use ('ns', 'us', 'ms', 's')
|
|
76
|
+
* @param decimals - number of decimal places (default: 2)
|
|
77
|
+
* @returns formatted string like "3.87μs"
|
|
78
78
|
*/
|
|
79
79
|
export declare const time_format: (ns: number, unit: TimeUnit, decimals?: number) => string;
|
|
80
80
|
/**
|
|
81
81
|
* Format time with adaptive units (ns/μs/ms/s) based on magnitude.
|
|
82
|
-
* @param ns -
|
|
83
|
-
* @param decimals -
|
|
84
|
-
* @returns
|
|
82
|
+
* @param ns - time in nanoseconds
|
|
83
|
+
* @param decimals - number of decimal places (default: 2)
|
|
84
|
+
* @returns formatted string like "3.87μs" or "1.23ms"
|
|
85
85
|
*
|
|
86
86
|
* @example
|
|
87
87
|
* ```ts
|
|
@@ -110,9 +110,9 @@ export interface TimeResult {
|
|
|
110
110
|
}
|
|
111
111
|
/**
|
|
112
112
|
* Time an asynchronous function execution.
|
|
113
|
-
* @param fn -
|
|
114
|
-
* @param timer -
|
|
115
|
-
* @returns
|
|
113
|
+
* @param fn - async function to time
|
|
114
|
+
* @param timer - timer to use (defaults to `timer_default`)
|
|
115
|
+
* @returns object containing the function result and timing information
|
|
116
116
|
*
|
|
117
117
|
* @example
|
|
118
118
|
* ```ts
|
|
@@ -129,9 +129,9 @@ export declare const time_async: <T>(fn: () => Promise<T>, timer?: Timer) => Pro
|
|
|
129
129
|
}>;
|
|
130
130
|
/**
|
|
131
131
|
* Time a synchronous function execution.
|
|
132
|
-
* @param fn -
|
|
133
|
-
* @param timer -
|
|
134
|
-
* @returns
|
|
132
|
+
* @param fn - sync function to time
|
|
133
|
+
* @param timer - timer to use (defaults to `timer_default`)
|
|
134
|
+
* @returns object containing the function result and timing information
|
|
135
135
|
*
|
|
136
136
|
* @example
|
|
137
137
|
* ```ts
|
|
@@ -147,10 +147,10 @@ export declare const time_sync: <T>(fn: () => T, timer?: Timer) => {
|
|
|
147
147
|
};
|
|
148
148
|
/**
|
|
149
149
|
* Measure multiple executions of a function and return all timings.
|
|
150
|
-
* @param fn -
|
|
151
|
-
* @param iterations -
|
|
152
|
-
* @param timer -
|
|
153
|
-
* @returns
|
|
150
|
+
* @param fn - function to measure (sync or async)
|
|
151
|
+
* @param iterations - number of times to execute
|
|
152
|
+
* @param timer - timer to use (defaults to `timer_default`)
|
|
153
|
+
* @returns array of elapsed times in nanoseconds
|
|
154
154
|
*
|
|
155
155
|
* @example
|
|
156
156
|
* ```ts
|
package/dist/time.js
CHANGED
|
@@ -96,8 +96,8 @@ export const TIME_UNIT_DISPLAY = { ns: 'ns', us: 'μs', ms: 'ms', s: 's' };
|
|
|
96
96
|
/**
|
|
97
97
|
* Detect the best time unit for a set of nanosecond values.
|
|
98
98
|
* Chooses the unit where most values fall in the range 1-9999.
|
|
99
|
-
* @param values_ns -
|
|
100
|
-
* @returns
|
|
99
|
+
* @param values_ns - array of times in nanoseconds
|
|
100
|
+
* @returns best unit to use for all values
|
|
101
101
|
*/
|
|
102
102
|
export const time_unit_detect_best = (values_ns) => {
|
|
103
103
|
if (values_ns.length === 0)
|
|
@@ -125,10 +125,10 @@ export const time_unit_detect_best = (values_ns) => {
|
|
|
125
125
|
};
|
|
126
126
|
/**
|
|
127
127
|
* Format time with a specific unit.
|
|
128
|
-
* @param ns -
|
|
129
|
-
* @param unit -
|
|
130
|
-
* @param decimals -
|
|
131
|
-
* @returns
|
|
128
|
+
* @param ns - time in nanoseconds
|
|
129
|
+
* @param unit - unit to use ('ns', 'us', 'ms', 's')
|
|
130
|
+
* @param decimals - number of decimal places (default: 2)
|
|
131
|
+
* @returns formatted string like "3.87μs"
|
|
132
132
|
*/
|
|
133
133
|
export const time_format = (ns, unit, decimals = 2) => {
|
|
134
134
|
if (!isFinite(ns))
|
|
@@ -146,9 +146,9 @@ export const time_format = (ns, unit, decimals = 2) => {
|
|
|
146
146
|
};
|
|
147
147
|
/**
|
|
148
148
|
* Format time with adaptive units (ns/μs/ms/s) based on magnitude.
|
|
149
|
-
* @param ns -
|
|
150
|
-
* @param decimals -
|
|
151
|
-
* @returns
|
|
149
|
+
* @param ns - time in nanoseconds
|
|
150
|
+
* @param decimals - number of decimal places (default: 2)
|
|
151
|
+
* @returns formatted string like "3.87μs" or "1.23ms"
|
|
152
152
|
*
|
|
153
153
|
* @example
|
|
154
154
|
* ```ts
|
|
@@ -177,9 +177,9 @@ export const time_format_adaptive = (ns, decimals = 2) => {
|
|
|
177
177
|
};
|
|
178
178
|
/**
|
|
179
179
|
* Time an asynchronous function execution.
|
|
180
|
-
* @param fn -
|
|
181
|
-
* @param timer -
|
|
182
|
-
* @returns
|
|
180
|
+
* @param fn - async function to time
|
|
181
|
+
* @param timer - timer to use (defaults to `timer_default`)
|
|
182
|
+
* @returns object containing the function result and timing information
|
|
183
183
|
*
|
|
184
184
|
* @example
|
|
185
185
|
* ```ts
|
|
@@ -208,9 +208,9 @@ export const time_async = async (fn, timer = timer_default) => {
|
|
|
208
208
|
};
|
|
209
209
|
/**
|
|
210
210
|
* Time a synchronous function execution.
|
|
211
|
-
* @param fn -
|
|
212
|
-
* @param timer -
|
|
213
|
-
* @returns
|
|
211
|
+
* @param fn - sync function to time
|
|
212
|
+
* @param timer - timer to use (defaults to `timer_default`)
|
|
213
|
+
* @returns object containing the function result and timing information
|
|
214
214
|
*
|
|
215
215
|
* @example
|
|
216
216
|
* ```ts
|
|
@@ -238,10 +238,10 @@ export const time_sync = (fn, timer = timer_default) => {
|
|
|
238
238
|
};
|
|
239
239
|
/**
|
|
240
240
|
* Measure multiple executions of a function and return all timings.
|
|
241
|
-
* @param fn -
|
|
242
|
-
* @param iterations -
|
|
243
|
-
* @param timer -
|
|
244
|
-
* @returns
|
|
241
|
+
* @param fn - function to measure (sync or async)
|
|
242
|
+
* @param iterations - number of times to execute
|
|
243
|
+
* @param timer - timer to use (defaults to `timer_default`)
|
|
244
|
+
* @returns array of elapsed times in nanoseconds
|
|
245
245
|
*
|
|
246
246
|
* @example
|
|
247
247
|
* ```ts
|