ventojs 2.0.0-canary.0 → 2.0.0-canary.2
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/CHANGELOG.md +28 -2
- package/core/environment.js +97 -41
- package/core/errors.js +253 -24
- package/core/reserved.js +1 -0
- package/core/tokenizer.js +11 -5
- package/loaders/file.js +1 -1
- package/loaders/filesystem.js +36 -0
- package/loaders/memory.js +7 -7
- package/loaders/module.js +51 -0
- package/loaders/url.js +3 -9
- package/loaders/utils.js +17 -0
- package/package.json +26 -8
- package/plugins/auto_trim.js +2 -1
- package/plugins/echo.js +2 -6
- package/plugins/escape.js +32 -9
- package/plugins/export.js +5 -7
- package/plugins/for.js +10 -6
- package/plugins/function.js +8 -12
- package/plugins/if.js +6 -5
- package/plugins/import.js +7 -5
- package/plugins/include.js +6 -3
- package/plugins/js.js +1 -1
- package/plugins/layout.js +8 -9
- package/plugins/set.js +5 -7
- package/types/core/environment.d.ts +14 -16
- package/types/core/errors.d.ts +43 -13
- package/types/core/tokenizer.d.ts +1 -1
- package/types/loaders/file.d.ts +1 -1
- package/types/loaders/filesystem.d.ts +12 -0
- package/types/loaders/memory.d.ts +1 -1
- package/types/loaders/module.d.ts +19 -0
- package/types/loaders/utils.d.ts +1 -0
- /package/types/{browser.d.ts → web.d.ts} +0 -0
- /package/{browser.js → web.js} +0 -0
@@ -3,20 +3,17 @@ export interface TemplateResult {
|
|
3
3
|
content: string;
|
4
4
|
[key: string]: unknown;
|
5
5
|
}
|
6
|
-
export interface
|
7
|
-
(data?: Record<string, unknown>): Promise<TemplateResult>;
|
6
|
+
export interface TemplateContext {
|
8
7
|
source: string;
|
9
8
|
code: string;
|
10
|
-
|
9
|
+
path?: string;
|
10
|
+
defaults?: Record<string, unknown>;
|
11
11
|
}
|
12
|
-
export interface
|
13
|
-
(data?: Record<string, unknown>): TemplateResult
|
14
|
-
source: string;
|
15
|
-
code: string;
|
16
|
-
file?: string;
|
12
|
+
export interface Template extends TemplateContext {
|
13
|
+
(data?: Record<string, unknown>): Promise<TemplateResult>;
|
17
14
|
}
|
18
15
|
export type TokenPreprocessor = (env: Environment, tokens: Token[], path?: string) => Token[] | void;
|
19
|
-
export type Tag = (env: Environment,
|
16
|
+
export type Tag = (env: Environment, token: Token, output: string, tokens: Token[]) => string | undefined;
|
20
17
|
export type FilterThis = {
|
21
18
|
data: Record<string, unknown>;
|
22
19
|
env: Environment;
|
@@ -27,8 +24,9 @@ export interface TemplateSource {
|
|
27
24
|
source: string;
|
28
25
|
data?: Record<string, unknown>;
|
29
26
|
}
|
27
|
+
export type PrecompiledTemplate = (env: Environment) => Template;
|
30
28
|
export interface Loader {
|
31
|
-
load(file: string): Promise<TemplateSource>;
|
29
|
+
load(file: string): Promise<TemplateSource | PrecompiledTemplate>;
|
32
30
|
resolve(from: string, file: string): string;
|
33
31
|
}
|
34
32
|
export interface Options {
|
@@ -46,13 +44,13 @@ export declare class Environment {
|
|
46
44
|
utils: Record<string, unknown>;
|
47
45
|
constructor(options: Options);
|
48
46
|
use(plugin: Plugin): void;
|
49
|
-
run(file: string, data?: Record<string, unknown>, from?: string): Promise<TemplateResult>;
|
47
|
+
run(file: string, data?: Record<string, unknown>, from?: string, position?: number): Promise<TemplateResult>;
|
50
48
|
runString(source: string, data?: Record<string, unknown>, file?: string): Promise<TemplateResult>;
|
51
|
-
|
52
|
-
compile(source: string, path?: string, defaults?: Record<string, unknown>, sync?: false): Template;
|
53
|
-
compile(source: string, path?: string, defaults?: Record<string, unknown>, sync?: true): TemplateSync;
|
49
|
+
compile(source: string, path?: string, defaults?: Record<string, unknown>): Template;
|
54
50
|
tokenize(source: string, path?: string): Token[];
|
55
|
-
load(file: string, from?: string): Promise<Template>;
|
56
|
-
compileTokens(tokens: Token[], outputVar?: string,
|
51
|
+
load(file: string, from?: string, position?: number): Promise<Template>;
|
52
|
+
compileTokens(tokens: Token[], outputVar?: string, closeToken?: string): string[];
|
57
53
|
compileFilters(tokens: Token[], output: string, autoescape?: boolean): string;
|
58
54
|
}
|
55
|
+
export declare class SafeString extends String {
|
56
|
+
}
|
package/types/core/errors.d.ts
CHANGED
@@ -1,16 +1,46 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
import type { TemplateContext } from "./environment.d.ts";
|
2
|
+
export interface ErrorContext {
|
3
|
+
type: string;
|
4
|
+
message: string;
|
5
|
+
source?: string;
|
6
|
+
position?: number;
|
7
|
+
code?: string;
|
8
|
+
line?: number;
|
9
|
+
column?: number;
|
10
|
+
file?: string;
|
3
11
|
}
|
4
|
-
export declare class
|
5
|
-
|
6
|
-
source: string;
|
7
|
-
position: number;
|
8
|
-
constructor(path?: string, source?: string, position?: number, cause?: Error);
|
12
|
+
export declare abstract class VentoError extends Error {
|
13
|
+
abstract getContext(): ErrorContext | Promise<ErrorContext>;
|
9
14
|
}
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
15
|
+
export declare class SourceError extends VentoError {
|
16
|
+
position?: number;
|
17
|
+
file?: string;
|
18
|
+
source?: string;
|
19
|
+
constructor(message: string, position?: number, file?: string, source?: string);
|
20
|
+
getContext(): {
|
21
|
+
type: string;
|
22
|
+
message: string;
|
23
|
+
position: number;
|
24
|
+
file: string;
|
25
|
+
source: string;
|
26
|
+
};
|
27
|
+
}
|
28
|
+
export declare class RuntimeError extends VentoError {
|
29
|
+
#private;
|
30
|
+
position?: number;
|
31
|
+
constructor(error: Error, context: TemplateContext, position?: number);
|
32
|
+
getContext(): Promise<ErrorContext>;
|
33
|
+
}
|
34
|
+
/** Create or complete VentoError with extra info from the template */
|
35
|
+
export declare function createError(error: Error, context: TemplateContext, position?: number): VentoError;
|
36
|
+
export interface ErrorFormat {
|
37
|
+
number: (n: string) => string;
|
38
|
+
dim: (line: string) => string;
|
39
|
+
error: (msg: string) => string;
|
40
|
+
}
|
41
|
+
declare const formats: Record<string, ErrorFormat>;
|
42
|
+
/** Prints an error to the console in a formatted way. */
|
43
|
+
export declare function printError(error: unknown, format?: ErrorFormat | keyof typeof formats): Promise<void>;
|
44
|
+
/** Converts an error context into a formatted string representation. */
|
45
|
+
export declare function stringifyError(context: ErrorContext, format?: ErrorFormat): string;
|
16
46
|
export {};
|
@@ -1,5 +1,5 @@
|
|
1
1
|
export type TokenType = "string" | "tag" | "filter" | "comment";
|
2
|
-
export type Token = [TokenType, string, number
|
2
|
+
export type Token = [TokenType, string, number];
|
3
3
|
export default function tokenize(source: string): Token[];
|
4
4
|
/**
|
5
5
|
* Parse a tag and return the indexes of the start and end brackets, and the filters between.
|
package/types/loaders/file.d.ts
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
import type { Loader, TemplateSource } from "../core/environment.d.ts";
|
2
2
|
/**
|
3
3
|
* Vento file loader for loading templates from the file system.
|
4
|
-
* Used by
|
4
|
+
* Used by Node-like runtimes (Node, Deno, Bun, ...)
|
5
5
|
*/
|
6
6
|
export declare class FileLoader implements Loader {
|
7
7
|
#private;
|
@@ -0,0 +1,12 @@
|
|
1
|
+
import type { Loader, TemplateSource } from "../core/environment.d.ts";
|
2
|
+
/**
|
3
|
+
* Vento FileSystem API loader for loading templates.
|
4
|
+
* Used by browser environments.
|
5
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/File_System_API
|
6
|
+
*/
|
7
|
+
export declare class FileSystemLoader implements Loader {
|
8
|
+
#private;
|
9
|
+
constructor(handle: FileSystemDirectoryHandle);
|
10
|
+
load(file: string): Promise<TemplateSource>;
|
11
|
+
resolve(from: string, file: string): string;
|
12
|
+
}
|
@@ -4,7 +4,7 @@ import type { Loader, TemplateSource } from "../core/environment.d.ts";
|
|
4
4
|
* Used for testing or in-memory operations.
|
5
5
|
*/
|
6
6
|
export declare class MemoryLoader implements Loader {
|
7
|
-
files:
|
7
|
+
files: Map<string, string>;
|
8
8
|
constructor(files: Record<string, string>);
|
9
9
|
load(file: string): Promise<TemplateSource>;
|
10
10
|
resolve(from: string, file: string): string;
|
@@ -0,0 +1,19 @@
|
|
1
|
+
import type { Loader, PrecompiledTemplate, Template } from "../core/environment.d.ts";
|
2
|
+
/**
|
3
|
+
* Vento loader for loading templates from a ES modules.
|
4
|
+
* Used to load precompiled templates.
|
5
|
+
*/
|
6
|
+
export declare class ModuleLoader implements Loader {
|
7
|
+
#private;
|
8
|
+
constructor(root: URL);
|
9
|
+
load(file: string): Promise<PrecompiledTemplate>;
|
10
|
+
resolve(from: string, file: string): string;
|
11
|
+
}
|
12
|
+
export interface ExportOptions {
|
13
|
+
source?: boolean;
|
14
|
+
}
|
15
|
+
/**
|
16
|
+
* Exports a template as a string that can be used in an ES module.
|
17
|
+
* This is useful for precompiled templates.
|
18
|
+
*/
|
19
|
+
export declare function exportTemplate(template: Template, options?: ExportOptions): string;
|
@@ -0,0 +1 @@
|
|
1
|
+
export declare function join(...paths: string[]): string;
|
File without changes
|
/package/{browser.js → web.js}
RENAMED
File without changes
|