@lark.js/mvc 0.0.10 → 0.0.12

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.
@@ -6,40 +6,12 @@ interface CompileOptions {
6
6
  globalVars?: string[];
7
7
  /** File path for debug error messages (default: undefined) */
8
8
  file?: string;
9
+ /** Generate VDOM output instead of HTML string (default: false) */
10
+ virtualDom?: boolean;
11
+ /** Use SWC instead of Babel for parsing (default: false) */
12
+ useSwc?: boolean;
9
13
  }
10
14
 
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
15
  /**
44
16
  * Compile an HTML template string into a JS module string.
45
17
  * This is the main entry point for both Vite and Webpack loaders.
@@ -54,7 +26,35 @@ interface CompileOptions {
54
26
  * @param options - Compilation options
55
27
  * @returns ES module source code exporting the compiled template function
56
28
  */
57
- declare function compileTemplate(source: string, options?: CompileOptions): string;
29
+ declare function compileTemplate(source: string, options?: CompileOptions): Promise<string>;
30
+
31
+ /**
32
+ * Extract global variable names from a template source using AST analysis.
33
+ *
34
+ * 1. Convert template commands (<% %> blocks) into a form parseable by an AST parser
35
+ * 2. Walk the AST to find all Identifier nodes
36
+ * 3. Track variable declarations (VariableDeclarator, FunctionDeclaration) as local vars
37
+ * 4. Track function parameters as local vars
38
+ * 5. Remaining identifiers that are not local and not in the exclusion list are "global" —
39
+ * they must be passed in as part of the data context ($$)
40
+ *
41
+ * This replaces the old regex-based `extractVariables()` with proper scope analysis,
42
+ * eliminating false positives from local template variables and function parameters.
43
+ *
44
+ * @param source - The raw HTML template content (with {{ }} syntax)
45
+ * @returns Array of global variable names found in the template
46
+ */
47
+ declare function extractGlobalVars$1(source: string): Promise<string[]>;
48
+
49
+ /**
50
+ * Extract global variable names from a template source using SWC AST analysis.
51
+ *
52
+ * 1. Convert template commands ({{ }} blocks) into a form parseable by SWC
53
+ * 2. Walk the AST to find all Identifier nodes
54
+ * 3. Track variable declarations (VariableDeclarator, FunctionDeclaration) as local vars
55
+ * 4. Track function parameters as local vars
56
+ * 5. Remaining identifiers that are not local and not in the exclusion list are "global"
57
+ */
58
58
  /**
59
59
  * Extract global variable names from a template source using AST analysis.
60
60
  *
@@ -71,6 +71,6 @@ declare function compileTemplate(source: string, options?: CompileOptions): stri
71
71
  * @param source - The raw HTML template content (with {{ }} syntax)
72
72
  * @returns Array of global variable names found in the template
73
73
  */
74
- declare function extractGlobalVars(source: string): string[];
74
+ declare function extractGlobalVars(source: string): Promise<string[]>;
75
75
 
76
- export { compileTemplate, extractGlobalVars };
76
+ export { compileTemplate, extractGlobalVars$1 as extractGlobalVars, extractGlobalVars as extractGlobalVarsSwc };
@@ -6,40 +6,12 @@ interface CompileOptions {
6
6
  globalVars?: string[];
7
7
  /** File path for debug error messages (default: undefined) */
8
8
  file?: string;
9
+ /** Generate VDOM output instead of HTML string (default: false) */
10
+ virtualDom?: boolean;
11
+ /** Use SWC instead of Babel for parsing (default: false) */
12
+ useSwc?: boolean;
9
13
  }
10
14
 
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
15
  /**
44
16
  * Compile an HTML template string into a JS module string.
45
17
  * This is the main entry point for both Vite and Webpack loaders.
@@ -54,7 +26,35 @@ interface CompileOptions {
54
26
  * @param options - Compilation options
55
27
  * @returns ES module source code exporting the compiled template function
56
28
  */
57
- declare function compileTemplate(source: string, options?: CompileOptions): string;
29
+ declare function compileTemplate(source: string, options?: CompileOptions): Promise<string>;
30
+
31
+ /**
32
+ * Extract global variable names from a template source using AST analysis.
33
+ *
34
+ * 1. Convert template commands (<% %> blocks) into a form parseable by an AST parser
35
+ * 2. Walk the AST to find all Identifier nodes
36
+ * 3. Track variable declarations (VariableDeclarator, FunctionDeclaration) as local vars
37
+ * 4. Track function parameters as local vars
38
+ * 5. Remaining identifiers that are not local and not in the exclusion list are "global" —
39
+ * they must be passed in as part of the data context ($$)
40
+ *
41
+ * This replaces the old regex-based `extractVariables()` with proper scope analysis,
42
+ * eliminating false positives from local template variables and function parameters.
43
+ *
44
+ * @param source - The raw HTML template content (with {{ }} syntax)
45
+ * @returns Array of global variable names found in the template
46
+ */
47
+ declare function extractGlobalVars$1(source: string): Promise<string[]>;
48
+
49
+ /**
50
+ * Extract global variable names from a template source using SWC AST analysis.
51
+ *
52
+ * 1. Convert template commands ({{ }} blocks) into a form parseable by SWC
53
+ * 2. Walk the AST to find all Identifier nodes
54
+ * 3. Track variable declarations (VariableDeclarator, FunctionDeclaration) as local vars
55
+ * 4. Track function parameters as local vars
56
+ * 5. Remaining identifiers that are not local and not in the exclusion list are "global"
57
+ */
58
58
  /**
59
59
  * Extract global variable names from a template source using AST analysis.
60
60
  *
@@ -71,6 +71,6 @@ declare function compileTemplate(source: string, options?: CompileOptions): stri
71
71
  * @param source - The raw HTML template content (with {{ }} syntax)
72
72
  * @returns Array of global variable names found in the template
73
73
  */
74
- declare function extractGlobalVars(source: string): string[];
74
+ declare function extractGlobalVars(source: string): Promise<string[]>;
75
75
 
76
- export { compileTemplate, extractGlobalVars };
76
+ export { compileTemplate, extractGlobalVars$1 as extractGlobalVars, extractGlobalVars as extractGlobalVarsSwc };