@zeus-js/compiler 0.1.0 → 0.1.1-beta.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.
@@ -1,135 +1,43 @@
1
- import * as _babel_core from '@babel/core';
2
- import { SourceSpan, SourcePosition } from '@zeus-js/compiler-shared';
3
- export * from '@zeus-js/compiler-shared';
4
-
5
- /**
6
- * Compiler configuration interface.
7
- */
8
- export interface CompilerOptions {
9
- /**
10
- * The name of the runtime module to import the methods from.
11
- */
12
- moduleName: string;
13
- /**
14
- * The output mode of the compiler. Can be "dom"(default), "ssr". "dom" is standard output. "ssr" is for server side rendering of strings.
15
- * @default 'dom'
16
- */
17
- generate: 'dom';
18
- /**
19
- * Indicate whether the output should contain hydratable markers.
20
- * @default true
21
- */
22
- hydratable: boolean;
23
- /**
24
- * Boolean to indicate whether to enable automatic event delegation on camelCase.
25
- * @default true
26
- */
27
- delegateEvents: boolean;
28
- /**
29
- * Array of Component exports from module, that aren't included by default with the library. This plugin will automatically import them if it comes across them in the JSX.
30
- * @default []
31
- */
32
- delegatedEvents: string[];
33
- /**
34
- * Array of Component exports from module, that aren't included by default with the library. This plugin will automatically import them if it comes across them in the JSX.
35
- * @default []
36
- */
37
- builtIns: string[];
38
- /**
39
- * When set to a string value, this option restricts JSX transformation to only files that contain a specific JSX import source pragma comment. The plugin will only transform JSX in files that include a comment with `@jsxImportSource` followed by the specified value. If the comment is missing or specifies a different import source, the transformation is skipped for that file.
40
- * @default false
41
- */
42
- /**
43
- * Boolean indicates whether smart conditional detection should be used. This optimizes simple boolean expressions and ternaries in JSX.
44
- * @default true
45
- */
46
- wrapConditionals: boolean;
47
- omitNestedClosingTags: boolean;
48
- /**
49
- * Removes tags from the template output if they have no closing parents and are the last element. This may not work in all browser-like environments the same. The solution has been tested again Chrome/Edge/Firefox/Safari.
50
- * @default true
51
- */
52
- omitLastClosingTag: boolean;
53
- /**
54
- * Removes quotes for html attributes when possible from the template output. This may not work in all browser-like environments the same. The solution has been tested again Chrome/Edge/Firefox/Safari.
55
- * @default true
56
- */
57
- omitQuotes: boolean;
58
- /**
59
- * Boolean indicates whether to set current render context on Custom Elements and slots. Useful for seemless Context API with Web Components.
60
- * @default false
61
- */
62
- contextToCustomElements: boolean;
63
- /**
64
- * Comment decorator string indicates the static expression, used to tell the compiler not to wrap them by `effect` function, defaults to `@once`.
65
- * @default '@once'
66
- */
67
- staticMarker: string;
68
- /**
69
- * This plugin leverages a heuristic for reactive wrapping and lazy evaluation of JSX expressions. This option indicates the reactive wrapper function name (`effect`), defaults to `effect`.
70
- * @default 'effect'
71
- */
72
- effectWrapper: string;
73
- /**
74
- * Memos let you efficiently use a derived value in many reactive computations. This option indicates the memo function name, defaults to `memo`.
75
- * @default 'memo'
76
- */
77
- memoWrapper: string;
78
- /**
79
- * Checks for properly formed HTML by checking for elements that would not be allowed in certain parent elements. This validation isn't complete but includes places where browser would "correct" it and break the DOM walks.
80
- * @default true
81
- */
82
- validate: boolean;
83
- /**
84
- * Boolean indicates whether to inline styles into the template output.
85
- * @default true
86
- */
87
- inlineStyles: boolean;
88
- }
89
-
90
- export declare const CompilerErrorCode: {
91
- readonly UNSUPPORTED_SPREAD_ATTRIBUTE: "ZEUS_UNSUPPORTED_SPREAD_ATTRIBUTE";
92
- readonly UNSUPPORTED_SPREAD_CHILD: "ZEUS_UNSUPPORTED_SPREAD_CHILD";
93
- readonly UNSUPPORTED_FRAGMENT: "ZEUS_UNSUPPORTED_FRAGMENT";
94
- readonly UNSUPPORTED_FRAGMENT_CHILD: "ZEUS_UNSUPPORTED_FRAGMENT_CHILD";
95
- readonly UNSUPPORTED_COMPONENT_PROP: "ZEUS_UNSUPPORTED_COMPONENT_PROP";
96
- readonly EMPTY_EXPRESSION: "ZEUS_EMPTY_EXPRESSION";
97
- readonly INVALID_TRANSFORM_RESULT: "ZEUS_INVALID_TRANSFORM_RESULT";
98
- readonly UNSUPPORTED_NODE: "ZEUS_UNSUPPORTED_NODE";
99
- readonly INVALID_BUILTIN_USAGE: "ZEUS_INVALID_BUILTIN_USAGE";
100
- readonly INVALID_REF_USAGE: "ZEUS_INVALID_REF_USAGE";
101
- };
102
- export type CompilerErrorCode = (typeof CompilerErrorCode)[keyof typeof CompilerErrorCode];
103
-
104
- export type CompilerDiagnosticSeverity = 'error' | 'warning';
105
1
  export interface CompilerDiagnostic {
106
- code: CompilerErrorCode;
107
- severity: CompilerDiagnosticSeverity;
2
+ code: string;
108
3
  message: string;
4
+ severity: 'error' | 'warning';
5
+ filename: string;
109
6
  hint?: string;
110
- filename?: string;
111
7
  span?: SourceSpan;
112
8
  }
113
- export declare function formatCompilerDiagnostic(diagnostic: CompilerDiagnostic): string;
114
-
115
- export interface CompilerErrorOptions {
116
- code: CompilerErrorCode;
117
- message: string;
118
- hint?: string;
119
- filename?: string;
120
- span?: SourceSpan;
9
+ export interface SourcePosition {
10
+ offset: number;
11
+ line: number;
12
+ column: number;
121
13
  }
122
- export declare class CompilerError extends Error {
123
- readonly diagnostic: CompilerDiagnostic;
124
- readonly code: CompilerDiagnostic['code'];
125
- readonly severity: 'error';
126
- readonly hint?: string;
127
- readonly filename?: string;
128
- readonly span?: SourceSpan;
129
- readonly loc?: Pick<SourcePosition, 'line' | 'column'>;
130
- constructor(options: CompilerErrorOptions);
14
+ export interface SourceSpan {
15
+ start: SourcePosition;
16
+ end: SourcePosition;
131
17
  }
18
+ export interface RawSourceMap {
19
+ version: number;
20
+ file?: string;
21
+ sources: string[];
22
+ sourceRoot?: string;
23
+ sourcesContent: Array<string | null>;
24
+ names: string[];
25
+ mappings: string;
26
+ }
27
+ export interface TransformModuleOptions {
28
+ source: string;
29
+ filename: string;
30
+ target: 'dom' | 'ssr';
31
+ runtimeModule: string;
32
+ delegateEvents: boolean;
33
+ sourceMap: boolean;
34
+ hmr?: boolean;
35
+ }
36
+ export interface TransformModuleResult {
37
+ code: string;
38
+ map: RawSourceMap | null;
39
+ diagnostics: CompilerDiagnostic[];
40
+ }
41
+ export declare const transformModule: (options: TransformModuleOptions) => TransformModuleResult;
132
42
 
133
- declare const _default: (api: _babel_core.PluginAPI, options: CompilerOptions | null | undefined, dirname: string) => _babel_core.PluginObject<object & _babel_core.PluginPass<object>>;
134
-
135
- export { _default as default };
43
+ export { transformModule as default };