@lark.js/mvc 0.0.6 → 0.0.8

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.
@@ -0,0 +1,76 @@
1
+ /** Options for compileTemplate() */
2
+ interface CompileOptions {
3
+ /** Enable debug mode with line tracking (default: false) */
4
+ debug?: boolean;
5
+ /** Global variable names to destructure from $$ (refData) */
6
+ globalVars?: string[];
7
+ /** File path for debug error messages (default: undefined) */
8
+ file?: string;
9
+ }
10
+
11
+ /**
12
+ * @lark.js/mvc Template Compiler
13
+ *
14
+ * convertArtSyntax() ({{}} → <% %>)
15
+ * processViewEvents() (@event prefix + param encoding)
16
+ * compileToFunction() (<% %> → JS template function)
17
+ * extractGlobalVars() (AST-based global var analysis via @babel/parser)
18
+ *
19
+ * - All template operators: = (escape), ! (raw), @ (ref lookup), : (binding)
20
+ * - @event attribute processing with $splitter prefix + \x1e separator
21
+ * - $strSafe (null-safe toString), $encHtml (HTML entity encode), $encUri (URI encode), $encQuote (quote encode), $refFn (ref lookup)
22
+ * - Debug mode with line tracking ($dbgExpr/$dbgArt/$dbgLine) and try-catch error wrapper
23
+ * - View ID injection (\x1f → '+$viewId+')
24
+ * - Post-processing cleanup of empty concatenations
25
+ * - 0 configuration: auto-extract variables via AST analysis
26
+ *
27
+ * Template syntax:
28
+ * {{=variable}} → escaped output
29
+ * {{:variable}} → two-way binding (same as = for rendering)
30
+ * {{!variable}} → raw output (no HTML escaping)
31
+ * {{@variable}} → reference lookup for component data passing
32
+ * {{forOf list as item}} → loop
33
+ * {{forOf list as item idx}} → loop with index
34
+ * {{forIn obj as val key}} → object iteration
35
+ * {{for(let i=0;i<n;i++)}} → generic for loop
36
+ * {{if condition}} → conditional
37
+ * {{else if condition}} → else-if
38
+ * {{else}} → else
39
+ * {{/if}} / {{/forOf}} / {{/forIn}} / {{/for}} → close blocks
40
+ * {{set a = b}} → variable declaration
41
+ */
42
+
43
+ /**
44
+ * Compile an HTML template string into a JS module string.
45
+ * This is the main entry point for both Vite and Webpack loaders.
46
+ *
47
+ * The output is an ES module that exports a function with the signature:
48
+ * (data, viewId, refData) => string
49
+ *
50
+ * Internally it calls the compiled template function with the standard
51
+ * signature: ($data,$viewId,$refAlt,$encHtml,$strSafe,$encUri,$refFn,$encQuote)
52
+ *
53
+ * @param source - The raw HTML template content
54
+ * @param options - Compilation options
55
+ * @returns ES module source code exporting the compiled template function
56
+ */
57
+ declare function compileTemplate(source: string, options?: CompileOptions): string;
58
+ /**
59
+ * Extract global variable names from a template source using AST analysis.
60
+ *
61
+ * 1. Convert template commands (<% %> blocks) into a form parseable by an AST parser
62
+ * 2. Walk the AST to find all Identifier nodes
63
+ * 3. Track variable declarations (VariableDeclarator, FunctionDeclaration) as local vars
64
+ * 4. Track function parameters as local vars
65
+ * 5. Remaining identifiers that are not local and not in the exclusion list are "global" —
66
+ * they must be passed in as part of the data context ($$)
67
+ *
68
+ * This replaces the old regex-based `extractVariables()` with proper scope analysis,
69
+ * eliminating false positives from local template variables and function parameters.
70
+ *
71
+ * @param source - The raw HTML template content (with {{ }} syntax)
72
+ * @returns Array of global variable names found in the template
73
+ */
74
+ declare function extractGlobalVars(source: string): string[];
75
+
76
+ export { compileTemplate, extractGlobalVars };
@@ -0,0 +1,76 @@
1
+ /** Options for compileTemplate() */
2
+ interface CompileOptions {
3
+ /** Enable debug mode with line tracking (default: false) */
4
+ debug?: boolean;
5
+ /** Global variable names to destructure from $$ (refData) */
6
+ globalVars?: string[];
7
+ /** File path for debug error messages (default: undefined) */
8
+ file?: string;
9
+ }
10
+
11
+ /**
12
+ * @lark.js/mvc Template Compiler
13
+ *
14
+ * convertArtSyntax() ({{}} → <% %>)
15
+ * processViewEvents() (@event prefix + param encoding)
16
+ * compileToFunction() (<% %> → JS template function)
17
+ * extractGlobalVars() (AST-based global var analysis via @babel/parser)
18
+ *
19
+ * - All template operators: = (escape), ! (raw), @ (ref lookup), : (binding)
20
+ * - @event attribute processing with $splitter prefix + \x1e separator
21
+ * - $strSafe (null-safe toString), $encHtml (HTML entity encode), $encUri (URI encode), $encQuote (quote encode), $refFn (ref lookup)
22
+ * - Debug mode with line tracking ($dbgExpr/$dbgArt/$dbgLine) and try-catch error wrapper
23
+ * - View ID injection (\x1f → '+$viewId+')
24
+ * - Post-processing cleanup of empty concatenations
25
+ * - 0 configuration: auto-extract variables via AST analysis
26
+ *
27
+ * Template syntax:
28
+ * {{=variable}} → escaped output
29
+ * {{:variable}} → two-way binding (same as = for rendering)
30
+ * {{!variable}} → raw output (no HTML escaping)
31
+ * {{@variable}} → reference lookup for component data passing
32
+ * {{forOf list as item}} → loop
33
+ * {{forOf list as item idx}} → loop with index
34
+ * {{forIn obj as val key}} → object iteration
35
+ * {{for(let i=0;i<n;i++)}} → generic for loop
36
+ * {{if condition}} → conditional
37
+ * {{else if condition}} → else-if
38
+ * {{else}} → else
39
+ * {{/if}} / {{/forOf}} / {{/forIn}} / {{/for}} → close blocks
40
+ * {{set a = b}} → variable declaration
41
+ */
42
+
43
+ /**
44
+ * Compile an HTML template string into a JS module string.
45
+ * This is the main entry point for both Vite and Webpack loaders.
46
+ *
47
+ * The output is an ES module that exports a function with the signature:
48
+ * (data, viewId, refData) => string
49
+ *
50
+ * Internally it calls the compiled template function with the standard
51
+ * signature: ($data,$viewId,$refAlt,$encHtml,$strSafe,$encUri,$refFn,$encQuote)
52
+ *
53
+ * @param source - The raw HTML template content
54
+ * @param options - Compilation options
55
+ * @returns ES module source code exporting the compiled template function
56
+ */
57
+ declare function compileTemplate(source: string, options?: CompileOptions): string;
58
+ /**
59
+ * Extract global variable names from a template source using AST analysis.
60
+ *
61
+ * 1. Convert template commands (<% %> blocks) into a form parseable by an AST parser
62
+ * 2. Walk the AST to find all Identifier nodes
63
+ * 3. Track variable declarations (VariableDeclarator, FunctionDeclaration) as local vars
64
+ * 4. Track function parameters as local vars
65
+ * 5. Remaining identifiers that are not local and not in the exclusion list are "global" —
66
+ * they must be passed in as part of the data context ($$)
67
+ *
68
+ * This replaces the old regex-based `extractVariables()` with proper scope analysis,
69
+ * eliminating false positives from local template variables and function parameters.
70
+ *
71
+ * @param source - The raw HTML template content (with {{ }} syntax)
72
+ * @returns Array of global variable names found in the template
73
+ */
74
+ declare function extractGlobalVars(source: string): string[];
75
+
76
+ export { compileTemplate, extractGlobalVars };