@fuzdev/mdz 0.2.0 → 0.3.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/Mdz.svelte +15 -7
- package/dist/Mdz.svelte.d.ts +9 -2
- package/dist/Mdz.svelte.d.ts.map +1 -1
- package/dist/MdzNodeView.svelte +118 -112
- package/dist/MdzNodeView.svelte.d.ts +6 -2
- package/dist/MdzNodeView.svelte.d.ts.map +1 -1
- package/dist/MdzStream.svelte +3 -3
- package/dist/MdzStream.svelte.d.ts.map +1 -1
- package/dist/MdzStreamNodeView.svelte +117 -114
- package/dist/MdzStreamNodeView.svelte.d.ts +6 -2
- package/dist/MdzStreamNodeView.svelte.d.ts.map +1 -1
- package/dist/mdz.d.ts +6 -0
- package/dist/mdz.d.ts.map +1 -1
- package/dist/mdz.js +8 -0
- package/dist/mdz_debug_work.d.ts +38 -0
- package/dist/mdz_debug_work.d.ts.map +1 -0
- package/dist/mdz_debug_work.js +37 -0
- package/dist/mdz_helpers.d.ts +61 -0
- package/dist/mdz_helpers.d.ts.map +1 -1
- package/dist/mdz_helpers.js +72 -0
- package/dist/mdz_lexer.d.ts +12 -0
- package/dist/mdz_lexer.d.ts.map +1 -1
- package/dist/mdz_lexer.js +164 -24
- package/dist/mdz_stream_parser_inline.d.ts.map +1 -1
- package/dist/mdz_stream_parser_inline.js +19 -17
- package/dist/mdz_stream_parser_link.d.ts.map +1 -1
- package/dist/mdz_stream_parser_link.js +88 -56
- package/dist/mdz_stream_parser_list.d.ts.map +1 -1
- package/dist/mdz_stream_parser_list.js +10 -2
- package/dist/mdz_stream_parser_state.d.ts +29 -0
- package/dist/mdz_stream_parser_state.d.ts.map +1 -1
- package/dist/mdz_stream_parser_state.js +52 -3
- package/dist/mdz_stream_parser_table.d.ts +3 -2
- package/dist/mdz_stream_parser_table.d.ts.map +1 -1
- package/dist/mdz_stream_parser_table.js +18 -7
- package/dist/mdz_stream_parser_text.d.ts.map +1 -1
- package/dist/mdz_stream_parser_text.js +35 -24
- package/dist/mdz_to_svelte.d.ts.map +1 -1
- package/dist/mdz_to_svelte.js +28 -31
- package/dist/mdz_token_parser.d.ts.map +1 -1
- package/dist/mdz_token_parser.js +15 -16
- package/dist/svelte_preprocess_mdz.js +31 -37
- package/package.json +7 -4
- package/src/lib/mdz.ts +9 -0
- package/src/lib/mdz_debug_work.ts +38 -0
- package/src/lib/mdz_helpers.ts +97 -0
- package/src/lib/mdz_lexer.ts +168 -28
- package/src/lib/mdz_stream_parser_inline.ts +21 -17
- package/src/lib/mdz_stream_parser_link.ts +89 -56
- package/src/lib/mdz_stream_parser_list.ts +10 -4
- package/src/lib/mdz_stream_parser_state.ts +76 -4
- package/src/lib/mdz_stream_parser_table.ts +18 -7
- package/src/lib/mdz_stream_parser_text.ts +38 -37
- package/src/lib/mdz_to_svelte.ts +23 -31
- package/src/lib/mdz_token_parser.ts +17 -20
- package/src/lib/svelte_preprocess_mdz.ts +34 -35
|
@@ -37,7 +37,7 @@ import {
|
|
|
37
37
|
} from '@fuzdev/fuz_util/svelte_preprocess_helpers.ts';
|
|
38
38
|
|
|
39
39
|
import {mdz_parse} from './mdz.ts';
|
|
40
|
-
import {mdz_to_svelte} from './mdz_to_svelte.ts';
|
|
40
|
+
import {mdz_to_svelte, type MdzToSvelteResult} from './mdz_to_svelte.ts';
|
|
41
41
|
|
|
42
42
|
/**
|
|
43
43
|
* An estree `ImportDeclaration` augmented with Svelte's position data.
|
|
@@ -296,6 +296,33 @@ const collect_consumed_bindings = (
|
|
|
296
296
|
return consumed;
|
|
297
297
|
};
|
|
298
298
|
|
|
299
|
+
/**
|
|
300
|
+
* Parse a static mdz string and render it to Svelte markup. Returns `null` to
|
|
301
|
+
* leave the usage for the runtime — either the content raised a parse error
|
|
302
|
+
* (reported via `on_error`) or it contains unconfigured tags (which the
|
|
303
|
+
* precompiler emits nothing for; the runtime renders the fallback chrome).
|
|
304
|
+
*/
|
|
305
|
+
const render_static_mdz = (
|
|
306
|
+
content: string,
|
|
307
|
+
base: string | undefined,
|
|
308
|
+
context: FindMdzUsagesContext,
|
|
309
|
+
): MdzToSvelteResult | null => {
|
|
310
|
+
let result: MdzToSvelteResult;
|
|
311
|
+
try {
|
|
312
|
+
result = mdz_to_svelte(mdz_parse(content), {
|
|
313
|
+
components: context.components,
|
|
314
|
+
elements: context.elements,
|
|
315
|
+
base,
|
|
316
|
+
code_component_import: context.code_component_import,
|
|
317
|
+
codeblock_component_import: context.codeblock_component_import,
|
|
318
|
+
});
|
|
319
|
+
} catch (error) {
|
|
320
|
+
handle_preprocess_error(error, '[fuz-mdz]', context.filename, context.on_error);
|
|
321
|
+
return null;
|
|
322
|
+
}
|
|
323
|
+
return result.has_unconfigured_tags ? null : result;
|
|
324
|
+
};
|
|
325
|
+
|
|
299
326
|
/**
|
|
300
327
|
* Walks the AST to find `Mdz` component usages with static `content` props
|
|
301
328
|
* and generates transformations to replace them with `MdzPrecompiled` children.
|
|
@@ -346,24 +373,8 @@ const find_mdz_usages = (
|
|
|
346
373
|
// Extract static string value
|
|
347
374
|
const content_value = extract_static_string(content_attr.value, context.bindings);
|
|
348
375
|
if (content_value !== null) {
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
try {
|
|
352
|
-
const nodes = mdz_parse(content_value);
|
|
353
|
-
result = mdz_to_svelte(nodes, {
|
|
354
|
-
components: context.components,
|
|
355
|
-
elements: context.elements,
|
|
356
|
-
base,
|
|
357
|
-
code_component_import: context.code_component_import,
|
|
358
|
-
codeblock_component_import: context.codeblock_component_import,
|
|
359
|
-
});
|
|
360
|
-
} catch (error) {
|
|
361
|
-
handle_preprocess_error(error, '[fuz-mdz]', context.filename, context.on_error);
|
|
362
|
-
return;
|
|
363
|
-
}
|
|
364
|
-
|
|
365
|
-
// If content has unconfigured tags, skip this usage (fall back to runtime)
|
|
366
|
-
if (result.has_unconfigured_tags) return;
|
|
376
|
+
const result = render_static_mdz(content_value, base, context);
|
|
377
|
+
if (result === null) return; // parse error or unconfigured tags — leave for runtime
|
|
367
378
|
|
|
368
379
|
const consumed = collect_consumed_bindings(content_attr.value, context.bindings);
|
|
369
380
|
const replacement = build_replacement(node, exclude_attrs, result.markup, context.source);
|
|
@@ -390,22 +401,10 @@ const find_mdz_usages = (
|
|
|
390
401
|
// Parse and render each branch
|
|
391
402
|
const branch_results: Array<{markup: string; imports: Map<string, PreprocessImportInfo>}> =
|
|
392
403
|
[];
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
components: context.components,
|
|
398
|
-
elements: context.elements,
|
|
399
|
-
base,
|
|
400
|
-
code_component_import: context.code_component_import,
|
|
401
|
-
codeblock_component_import: context.codeblock_component_import,
|
|
402
|
-
});
|
|
403
|
-
if (result.has_unconfigured_tags) return;
|
|
404
|
-
branch_results.push({markup: result.markup, imports: result.imports});
|
|
405
|
-
}
|
|
406
|
-
} catch (error) {
|
|
407
|
-
handle_preprocess_error(error, '[fuz-mdz]', context.filename, context.on_error);
|
|
408
|
-
return;
|
|
404
|
+
for (const branch of chain) {
|
|
405
|
+
const result = render_static_mdz(branch.value, base, context);
|
|
406
|
+
if (result === null) return; // parse error or unconfigured tags — leave for runtime
|
|
407
|
+
branch_results.push({markup: result.markup, imports: result.imports});
|
|
409
408
|
}
|
|
410
409
|
|
|
411
410
|
// Build {#if}/{:else if}/{:else} markup
|