@lithent/lithent-template-parser 0.1.0 → 0.1.1
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/README.md +1 -1
- package/dist/codegen/createElement.d.cts +10 -0
- package/dist/codegen/createElement.d.ts +1 -1
- package/dist/codegen/index.d.cts +1 -0
- package/dist/codegen/index.d.ts +1 -1
- package/dist/compiler.d.cts +26 -0
- package/dist/compiler.d.ts +8 -8
- package/dist/docPipe/index.d.cts +40 -0
- package/dist/docPipe/index.d.ts +2 -2
- package/dist/docPipe/scan.d.cts +8 -0
- package/dist/docPipe/scan.d.ts +2 -0
- package/dist/index.d.cts +13 -0
- package/dist/index.d.ts +9 -9
- package/dist/index.mjs +955 -1192
- package/dist/index.mjs.map +1 -1
- package/dist/index.umd.cjs +12 -12
- package/dist/index.umd.cjs.map +1 -1
- package/dist/parser/ast.d.cts +207 -0
- package/dist/parser/ast.d.ts +1 -1
- package/dist/parser/lexer.d.cts +109 -0
- package/dist/parser/lexer.d.ts +1 -1
- package/dist/parser/parser.d.cts +80 -0
- package/dist/parser/parser.d.ts +5 -4
- package/dist/parser/tokens.d.cts +51 -0
- package/dist/transform/directives.d.cts +30 -0
- package/dist/transform/directives.d.ts +1 -1
- package/dist/transform/index.d.cts +14 -0
- package/dist/transform/index.d.ts +5 -5
- package/dist/transform/optimize.d.cts +21 -0
- package/dist/transform/optimize.d.ts +1 -1
- package/package.json +2 -2
- package/src/codegen/createElement.ts +48 -332
- package/src/compiler.ts +1 -1
- package/src/docPipe/scan.ts +209 -246
- package/src/parser/lexer.ts +41 -91
- package/src/parser/parser.ts +45 -39
- package/src/tests/compiler.test.ts +2 -2
- package/src/tests/parser.test.ts +2 -2
- package/src/tests/regressions.test.ts +200 -0
- package/src/transform/directives.ts +25 -2
- package/src/transform/optimize.ts +37 -25
package/README.md
CHANGED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { RootNode } from '../parser/ast.cjs';
|
|
2
|
+
/**
|
|
3
|
+
* Generate JavaScript code from AST
|
|
4
|
+
*/
|
|
5
|
+
export declare function generate(ast: RootNode, options?: GenerateOptions): string;
|
|
6
|
+
export interface GenerateOptions {
|
|
7
|
+
templateFactory?: string;
|
|
8
|
+
templateFragmentFactory?: string;
|
|
9
|
+
}
|
|
10
|
+
export declare function formatCode(code: string): string;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './createElement.cjs';
|
package/dist/codegen/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export * from './createElement';
|
|
1
|
+
export * from './createElement.js';
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { TransformOptions } from './transform/index.cjs';
|
|
2
|
+
import { GenerateOptions } from './codegen/index.cjs';
|
|
3
|
+
/**
|
|
4
|
+
* Compile a Lithent template to JavaScript code
|
|
5
|
+
*/
|
|
6
|
+
export declare function compile(template: string, options?: CompileOptions): CompileResult;
|
|
7
|
+
export interface CompileOptions {
|
|
8
|
+
transform?: TransformOptions;
|
|
9
|
+
generate?: GenerateOptions;
|
|
10
|
+
}
|
|
11
|
+
export interface CompileResult {
|
|
12
|
+
code: string;
|
|
13
|
+
ast: any;
|
|
14
|
+
errors: CompileError[];
|
|
15
|
+
}
|
|
16
|
+
export interface CompileError {
|
|
17
|
+
message: string;
|
|
18
|
+
line: number;
|
|
19
|
+
column: number;
|
|
20
|
+
}
|
|
21
|
+
export * from './parser/tokens.cjs';
|
|
22
|
+
export * from './parser/lexer.cjs';
|
|
23
|
+
export * from './parser/parser.cjs';
|
|
24
|
+
export * from './parser/ast.cjs';
|
|
25
|
+
export * from './transform/index.cjs';
|
|
26
|
+
export * from './codegen/index.cjs';
|
package/dist/compiler.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { TransformOptions } from './transform';
|
|
2
|
-
import { GenerateOptions } from './codegen';
|
|
1
|
+
import { TransformOptions } from './transform/index.js';
|
|
2
|
+
import { GenerateOptions } from './codegen/index.js';
|
|
3
3
|
/**
|
|
4
4
|
* Compile a Lithent template to JavaScript code
|
|
5
5
|
*/
|
|
@@ -18,9 +18,9 @@ export interface CompileError {
|
|
|
18
18
|
line: number;
|
|
19
19
|
column: number;
|
|
20
20
|
}
|
|
21
|
-
export * from './parser/tokens';
|
|
22
|
-
export * from './parser/lexer';
|
|
23
|
-
export * from './parser/parser';
|
|
24
|
-
export * from './parser/ast';
|
|
25
|
-
export * from './transform';
|
|
26
|
-
export * from './codegen';
|
|
21
|
+
export * from './parser/tokens.js';
|
|
22
|
+
export * from './parser/lexer.js';
|
|
23
|
+
export * from './parser/parser.js';
|
|
24
|
+
export * from './parser/ast.js';
|
|
25
|
+
export * from './transform/index.js';
|
|
26
|
+
export * from './codegen/index.js';
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { type SourceMap } from 'magic-string';
|
|
2
|
+
import { type CompileError, type CompileOptions } from '../compiler.cjs';
|
|
3
|
+
import { scanTemplates, type TemplateMatch } from './scan.cjs';
|
|
4
|
+
export interface DocumentTransformOptions {
|
|
5
|
+
/**
|
|
6
|
+
* Include original source name in generated source map.
|
|
7
|
+
*/
|
|
8
|
+
source?: string;
|
|
9
|
+
/**
|
|
10
|
+
* Emit a source map when true.
|
|
11
|
+
*/
|
|
12
|
+
generateSourceMap?: boolean;
|
|
13
|
+
/**
|
|
14
|
+
* Forwarded compile options for each template block.
|
|
15
|
+
*/
|
|
16
|
+
compileOptions?: CompileOptions;
|
|
17
|
+
}
|
|
18
|
+
export interface DocumentTransformError {
|
|
19
|
+
match: TemplateMatch;
|
|
20
|
+
error: CompileError;
|
|
21
|
+
}
|
|
22
|
+
export interface DocumentTransformResult {
|
|
23
|
+
code: string;
|
|
24
|
+
map: SourceMap | null;
|
|
25
|
+
/**
|
|
26
|
+
* `true` when at least one replacement succeeded.
|
|
27
|
+
*/
|
|
28
|
+
transformed: boolean;
|
|
29
|
+
/**
|
|
30
|
+
* Errors produced while compiling templates.
|
|
31
|
+
*/
|
|
32
|
+
errors: DocumentTransformError[];
|
|
33
|
+
/**
|
|
34
|
+
* All template matches discovered in the source.
|
|
35
|
+
*/
|
|
36
|
+
matches: TemplateMatch[];
|
|
37
|
+
}
|
|
38
|
+
export declare const transformDocument: (source: string, options?: DocumentTransformOptions) => DocumentTransformResult;
|
|
39
|
+
export { scanTemplates };
|
|
40
|
+
export type { TemplateMatch };
|
package/dist/docPipe/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { type SourceMap } from 'magic-string';
|
|
2
|
-
import { type CompileError, type CompileOptions } from '../compiler';
|
|
3
|
-
import { scanTemplates, type TemplateMatch } from './scan';
|
|
2
|
+
import { type CompileError, type CompileOptions } from '../compiler.js';
|
|
3
|
+
import { scanTemplates, type TemplateMatch } from './scan.js';
|
|
4
4
|
export interface DocumentTransformOptions {
|
|
5
5
|
/**
|
|
6
6
|
* Include original source name in generated source map.
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export interface TemplateMatch {
|
|
2
|
+
start: number;
|
|
3
|
+
end: number;
|
|
4
|
+
snippet: string;
|
|
5
|
+
}
|
|
6
|
+
/** Return the offset after a matching }, starting immediately after the opening {. */
|
|
7
|
+
export declare const skipJsExpression: (source: string, index: number) => number | null;
|
|
8
|
+
export declare const scanTemplates: (code: string) => TemplateMatch[];
|
package/dist/docPipe/scan.d.ts
CHANGED
|
@@ -3,4 +3,6 @@ export interface TemplateMatch {
|
|
|
3
3
|
end: number;
|
|
4
4
|
snippet: string;
|
|
5
5
|
}
|
|
6
|
+
/** Return the offset after a matching }, starting immediately after the opening {. */
|
|
7
|
+
export declare const skipJsExpression: (source: string, index: number) => number | null;
|
|
6
8
|
export declare const scanTemplates: (code: string) => TemplateMatch[];
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Lithent Template Parser
|
|
3
|
+
* A Vue-like template parser for Lithent
|
|
4
|
+
*/
|
|
5
|
+
export { compile } from './compiler.cjs';
|
|
6
|
+
export type { CompileOptions, CompileResult, CompileError } from './compiler.cjs';
|
|
7
|
+
export * from './parser/tokens.cjs';
|
|
8
|
+
export * from './parser/lexer.cjs';
|
|
9
|
+
export * from './parser/parser.cjs';
|
|
10
|
+
export * from './parser/ast.cjs';
|
|
11
|
+
export * from './transform/index.cjs';
|
|
12
|
+
export * from './codegen/index.cjs';
|
|
13
|
+
export * from './docPipe/index.cjs';
|
package/dist/index.d.ts
CHANGED
|
@@ -2,12 +2,12 @@
|
|
|
2
2
|
* Lithent Template Parser
|
|
3
3
|
* A Vue-like template parser for Lithent
|
|
4
4
|
*/
|
|
5
|
-
export { compile } from './compiler';
|
|
6
|
-
export type { CompileOptions, CompileResult, CompileError } from './compiler';
|
|
7
|
-
export * from './parser/tokens';
|
|
8
|
-
export * from './parser/lexer';
|
|
9
|
-
export * from './parser/parser';
|
|
10
|
-
export * from './parser/ast';
|
|
11
|
-
export * from './transform';
|
|
12
|
-
export * from './codegen';
|
|
13
|
-
export * from './docPipe';
|
|
5
|
+
export { compile } from './compiler.js';
|
|
6
|
+
export type { CompileOptions, CompileResult, CompileError } from './compiler.js';
|
|
7
|
+
export * from './parser/tokens.js';
|
|
8
|
+
export * from './parser/lexer.js';
|
|
9
|
+
export * from './parser/parser.js';
|
|
10
|
+
export * from './parser/ast.js';
|
|
11
|
+
export * from './transform/index.js';
|
|
12
|
+
export * from './codegen/index.js';
|
|
13
|
+
export * from './docPipe/index.js';
|