htm-transform 0.1.3 → 0.1.5

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/index.d.ts ADDED
@@ -0,0 +1,75 @@
1
+ /**
2
+ * @typedef {Object} ElementNode
3
+ * @property {'element'} type
4
+ * @property {boolean | {type: 'expression', expr: import('acorn').Node}} tag
5
+ * @property {Object<string, string | boolean | {type: 'expression', expr: import('acorn').Node}>} props
6
+ * @property {Array<ElementNode | TextNode | ExpressionNode>} children
7
+ */
8
+ /**
9
+ * @typedef {object} TextNode
10
+ * @property {'text'} type
11
+ * @property {string} value
12
+ */
13
+ /**
14
+ * @typedef {object} ExpressionNode
15
+ * @property {'expression'} type
16
+ * @property {string} value
17
+ * @property {import('acorn').Node} [expr]
18
+ */
19
+ /**
20
+ * @typedef {object} Token
21
+ * @property {'openTag' | 'closeTag' | 'text' | 'expression'} type
22
+ * @property {string} [tag]
23
+ * @property {Record<string, string | boolean>} [props]
24
+ * @property {boolean} [selfClosing]
25
+ * @property {string} [value]
26
+ */
27
+ /**
28
+ * Transforms htm tagged templates into h function calls
29
+ * @param {string} code - JavaScript code containing htm tagged templates
30
+ * @param {object} [options] - Transform options
31
+ * @param {string} [options.pragma] - The h function name (default: 'h')
32
+ * @param {string} [options.tag] - The tag name to look for (default: 'html')
33
+ * @param {object} [options.import] - Import configuration
34
+ * @param {string} options.import.from - Module to import from (e.g., 'preact', 'react')
35
+ * @param {string} options.import.name - Export name to import (e.g., 'h', 'createElement')
36
+ * @returns {string} - Transformed code
37
+ */
38
+ export default function transform(code: string, options?: {
39
+ pragma?: string;
40
+ tag?: string;
41
+ import?: {
42
+ from: string;
43
+ name: string;
44
+ };
45
+ }): string;
46
+ export type ElementNode = {
47
+ type: "element";
48
+ tag: boolean | {
49
+ type: "expression";
50
+ expr: import("acorn").Node;
51
+ };
52
+ props: {
53
+ [x: string]: string | boolean | {
54
+ type: "expression";
55
+ expr: import("acorn").Node;
56
+ };
57
+ };
58
+ children: Array<ElementNode | TextNode | ExpressionNode>;
59
+ };
60
+ export type TextNode = {
61
+ type: "text";
62
+ value: string;
63
+ };
64
+ export type ExpressionNode = {
65
+ type: "expression";
66
+ value: string;
67
+ expr?: import("acorn").Node;
68
+ };
69
+ export type Token = {
70
+ type: "openTag" | "closeTag" | "text" | "expression";
71
+ tag?: string;
72
+ props?: Record<string, string | boolean>;
73
+ selfClosing?: boolean;
74
+ value?: string;
75
+ };