@compelem/compiler 0.30.0-beta.1 → 0.30.0-beta.4
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/LICENSE +21 -21
- package/README.md +2 -2
- package/dist/index.d.ts +50 -51
- package/dist/index.js +2 -2
- package/dist/{vite-DU4Nznh4.js → vite-CY_6E-Ut.js} +5753 -4796
- package/dist/vite-CY_6E-Ut.js.map +1 -0
- package/dist/{vite-BtG-4Z6L.d.ts → vite-D178A0gy.d.ts} +77 -75
- package/dist/vite.d.ts +1 -1
- package/dist/vite.js +1 -1
- package/package.json +60 -64
- package/dist/vite-DU4Nznh4.js.map +0 -1
package/LICENSE
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2026 holyhigh2
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 holyhigh2
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
# @compelem/compiler
|
|
2
|
-
|
|
1
|
+
# @compelem/compiler
|
|
2
|
+
|
|
3
3
|
[compelem](https://github.com/holyhigh2/compelem) 的**编译器**
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { a as ComponentAnalysis, c as ReactiveKind, i as CompilerOptions, n as compelemCompiler, o as DEBUG_DIV, r as CompiledStatic, s as ReactiveField, t as VitePluginOptions } from "./vite-
|
|
1
|
+
import { a as ComponentAnalysis, c as ReactiveKind, i as CompilerOptions, n as compelemCompiler, o as DEBUG_DIV, r as CompiledStatic, s as ReactiveField, t as VitePluginOptions } from "./vite-D178A0gy.js";
|
|
2
2
|
|
|
3
|
-
//#region src/utils/
|
|
3
|
+
//#region src/utils/ast.d.ts
|
|
4
4
|
interface ParsedFile {
|
|
5
5
|
program: any;
|
|
6
6
|
/** 源码中所有 import 声明:本地名 → { source, imported } */
|
|
@@ -9,9 +9,10 @@ interface ParsedFile {
|
|
|
9
9
|
imported: string;
|
|
10
10
|
}>;
|
|
11
11
|
}
|
|
12
|
+
/** 解析 TS 源码为 AST(带缓存,LRU:命中回尾、超限逐出最老)。 */
|
|
13
|
+
declare function parse(code: string, id?: string): ParsedFile;
|
|
12
14
|
//#endregion
|
|
13
15
|
//#region src/analyze/component.d.ts
|
|
14
|
-
|
|
15
16
|
/** 判断某个 import source 是否指向 compelem 本体。 */
|
|
16
17
|
declare function isCompelemSource(source: string): boolean;
|
|
17
18
|
/** 从 import 表里挑出 compelem 相关绑定:本地名 → 原始导入名。 */
|
|
@@ -24,6 +25,11 @@ declare function collectCompelemImports(imports: ParsedFile['imports']): Map<str
|
|
|
24
25
|
*/
|
|
25
26
|
declare function analyzeFile(code: string, id: string, parsed: ParsedFile): ComponentAnalysis[];
|
|
26
27
|
//#endregion
|
|
28
|
+
//#region src/analyze/inline-template-methods.d.ts
|
|
29
|
+
|
|
30
|
+
/** 兼容旧 API:只返回改写后的源码。compile.ts 用 WithEdits 版本保留坐标映射。 */
|
|
31
|
+
declare function inlineTemplateMethods(code: string, parsed: ParsedFile): string;
|
|
32
|
+
//#endregion
|
|
27
33
|
//#region src/analyze/template.d.ts
|
|
28
34
|
|
|
29
35
|
interface TemplateIssue {
|
|
@@ -37,21 +43,20 @@ interface TemplateIssue {
|
|
|
37
43
|
}
|
|
38
44
|
//#endregion
|
|
39
45
|
//#region src/analyze/render-body.d.ts
|
|
40
|
-
|
|
41
46
|
/** 主视图依赖提取结果。 */
|
|
42
47
|
interface RenderAnalysis {
|
|
43
48
|
/** 主视图依赖路径(对应 ViewDepMap) */
|
|
44
49
|
viewDeps: string[];
|
|
45
50
|
/** 子视图依赖:回调节点 start 偏移 → 路径列表 */
|
|
46
51
|
subViewDeps: Map<number, string[]>;
|
|
47
|
-
/**
|
|
48
|
-
|
|
52
|
+
/** 阻断原因列表(空表示通过)。非空 ⇒ `assertStaticAnalysis` 抛 `StaticAnalysisError`。 */
|
|
53
|
+
blockers: string[];
|
|
49
54
|
/**
|
|
50
55
|
* 硬性违规(当前只有 D7:模板内直接嵌套模板)。
|
|
51
56
|
*
|
|
52
|
-
* 与
|
|
53
|
-
* errors
|
|
54
|
-
*
|
|
57
|
+
* 与 `blockers` 都是「不可编译」,二者的区别只在**归因**:`blockers` 是
|
|
58
|
+
* 「静态推不出结论」(D0/D3/D4/D5/D6),`errors` 是「写法违反约束,用户可修」
|
|
59
|
+
* (D7)—— 故 errors 带源码区间,供构建期定位到具体位置。
|
|
55
60
|
*/
|
|
56
61
|
errors: TemplateIssue[];
|
|
57
62
|
}
|
|
@@ -60,17 +65,14 @@ declare function analyzeRender(comp: ComponentAnalysis, sinks?: {
|
|
|
60
65
|
mainHits: any[];
|
|
61
66
|
}): RenderAnalysis;
|
|
62
67
|
//#endregion
|
|
63
|
-
//#region src/analyze/
|
|
68
|
+
//#region src/analyze/static-gate.d.ts
|
|
64
69
|
|
|
65
70
|
/**
|
|
66
|
-
*
|
|
67
|
-
*
|
|
71
|
+
* 静态分析闸门:汇总单个组件的结论,命中任何一条即抛 `StaticAnalysisError`。
|
|
72
|
+
*
|
|
73
|
+
* 无返回值 —— 只有「通过」与「抛错」两种结局(见本文件头 §架构前提)。
|
|
68
74
|
*/
|
|
69
|
-
declare function
|
|
70
|
-
degraded: false;
|
|
71
|
-
reason: null;
|
|
72
|
-
errors: RenderAnalysis['errors'];
|
|
73
|
-
};
|
|
75
|
+
declare function assertStaticAnalysis(comp: ComponentAnalysis, ra: RenderAnalysis): void;
|
|
74
76
|
/**
|
|
75
77
|
* 静态分析未通过。`name` 让它在堆栈里一眼可辨。 */
|
|
76
78
|
declare class StaticAnalysisError extends Error {
|
|
@@ -82,9 +84,7 @@ declare class StaticAnalysisError extends Error {
|
|
|
82
84
|
//#endregion
|
|
83
85
|
//#region src/codegen/inject.d.ts
|
|
84
86
|
interface InjectOptions {
|
|
85
|
-
/**
|
|
86
|
-
buildVars?: boolean;
|
|
87
|
-
/** 无视图组件标记:注入 noView: true(不创建 Shadow DOM) */
|
|
87
|
+
/** 无视图组件标记:注入 noView: true(不创建 Shadow DOM)*/
|
|
88
88
|
noView?: boolean;
|
|
89
89
|
}
|
|
90
90
|
/** `buildStaticLiteral` 可选生成物(任一缺失则对应字段不注入)。 */
|
|
@@ -99,20 +99,15 @@ interface StaticLiteralCodes {
|
|
|
99
99
|
fx?: string;
|
|
100
100
|
/** watch effect 工厂数组 */
|
|
101
101
|
watchEffects?: string;
|
|
102
|
+
/** `entries` 是否已内联**同文件**基类的 @watch —— 决定 watchEffects 是否还拼父类数组 */
|
|
103
|
+
inlinedWatchAncestors?: boolean;
|
|
102
104
|
/** cssVars effect 工厂(读 CSS 依赖信号 → 更新自定义属性) */
|
|
103
105
|
cssEffect?: string;
|
|
104
|
-
/** 结构指令元数据占位字段,运行时从不读取(分派参数在 pointEffects 内) */
|
|
105
|
-
dirMeta?: string;
|
|
106
106
|
buildTemplate?: string;
|
|
107
107
|
/** 子视图表(结构指令的子模板元数据):`subViews: { <subId>: { buildTemplate, fx } }` */
|
|
108
108
|
subViews?: string;
|
|
109
109
|
/**
|
|
110
|
-
|
|
111
|
-
* `__ce_s_METHOD(...a){return super.METHOD(...a)}`,
|
|
112
|
-
* 保留 home-object 的 super 绑定,供静态取值函数经 `__comp` 调用。
|
|
113
|
-
*/
|
|
114
|
-
superHelpers?: string[];
|
|
115
|
-
/** `__ce_static__.props` 字面量值(@prop 前移,analyze/field-extract.ts) */
|
|
110
|
+
/** `__ce_static__.props` 字面量值(@prop 前移,analyze/field-extract.ts) */
|
|
116
111
|
props?: string;
|
|
117
112
|
/** `__ce_static__.states` 字面量值(@state 前移) */
|
|
118
113
|
states?: string;
|
|
@@ -129,11 +124,23 @@ interface CtorInsertPlan {
|
|
|
129
124
|
pos: number;
|
|
130
125
|
/** true = 类无构造体 → 合成 `constructor(...__a){ super(...__a); ... }` */
|
|
131
126
|
synthesize: boolean;
|
|
127
|
+
/**
|
|
128
|
+
* 警告级诊断(W 通道):super(…) 不在构造体顶层语句位时给出——
|
|
129
|
+
* 插入点只能退到构造体末尾,prop/state 初始值写入晚于分支内用户语句,
|
|
130
|
+
* 与原生字段初始化时机不严格等价。调用方转成 severity:'warn' 诊断。
|
|
131
|
+
*/
|
|
132
|
+
warn?: string;
|
|
132
133
|
}
|
|
133
134
|
/** 文件级运行时函数 import 注入参数。 */
|
|
134
135
|
interface ImportInjectOptions {
|
|
135
136
|
/** 需要导入的运行时函数名(已定名,含可能的 __ce_ 别名) */
|
|
136
137
|
helpers?: string[];
|
|
138
|
+
/**
|
|
139
|
+
* helper 的本地名 → 原始导出名。仅当本地名与导出名不同(冲突别名)时需要;
|
|
140
|
+
* 缺省按同名导入。例如 `{ __ce_signal: 'signal' }` →
|
|
141
|
+
* `import { signal as __ce_signal } from 'compelem'`。
|
|
142
|
+
*/
|
|
143
|
+
helperAliases?: Record<string, string>;
|
|
137
144
|
/** 定位到的 compelem import 声明:有命名 specifier 则原位扩展,否则新增独立行 */
|
|
138
145
|
helperImport?: {
|
|
139
146
|
decl: any;
|
|
@@ -143,6 +150,8 @@ interface ImportInjectOptions {
|
|
|
143
150
|
helpersAnchor?: number;
|
|
144
151
|
/** 需要从 **myfx** 注入的运行时函数名(方法装饰器前移的 debounce/throttle/once) */
|
|
145
152
|
myfxHelpers?: string[];
|
|
153
|
+
/** myfx helper 的本地名 → 原始导出名(同 helperAliases) */
|
|
154
|
+
myfxAliases?: Record<string, string>;
|
|
146
155
|
/** 定位到的 myfx import 声明:有命名 specifier 则原位扩展,否则新增独立行 */
|
|
147
156
|
myfxImport?: {
|
|
148
157
|
decl: any;
|
|
@@ -155,6 +164,12 @@ interface ImportInjectOptions {
|
|
|
155
164
|
topLevel?: string;
|
|
156
165
|
/** topLevel 的插入锚点(紧跟其后的偏移) */
|
|
157
166
|
topLevelAnchor?: number;
|
|
167
|
+
/** inline 预变换的原始坐标编辑;在 class 注入前统一 overwrite。 */
|
|
168
|
+
inlineEdits?: Array<{
|
|
169
|
+
start: number;
|
|
170
|
+
end: number;
|
|
171
|
+
text: string;
|
|
172
|
+
}>;
|
|
158
173
|
}
|
|
159
174
|
/** 生成 `static __ce_static__ = {...}` 的源码文本。 */
|
|
160
175
|
declare function buildStaticLiteral(opts: InjectOptions, codes?: StaticLiteralCodes): string;
|
|
@@ -215,22 +230,15 @@ interface CompileResult {
|
|
|
215
230
|
/** 本次编译的诊断信息(组件级) */
|
|
216
231
|
diagnostics: Array<{
|
|
217
232
|
className: string;
|
|
218
|
-
degraded: boolean;
|
|
219
|
-
reason: string | null;
|
|
220
233
|
viewDeps: number;
|
|
221
|
-
/**
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
end: number;
|
|
225
|
-
exprStart: number;
|
|
226
|
-
exprEnd: number;
|
|
227
|
-
message: string;
|
|
228
|
-
}>;
|
|
229
|
-
/** 约定错误(emit/@prop/@computed/@csscope 静态校验),与降级无关 */
|
|
234
|
+
/**
|
|
235
|
+
* 约定错误(emit/@prop/@computed/@csscope 静态校验)。
|
|
236
|
+
*/
|
|
230
237
|
conventionErrors: Array<{
|
|
231
238
|
start: number;
|
|
232
239
|
end: number;
|
|
233
240
|
message: string;
|
|
241
|
+
severity?: 'warn';
|
|
234
242
|
}>;
|
|
235
243
|
/** 静态依赖清单(每组件无条件填充;options.verbose 时输出人类可读格式) */
|
|
236
244
|
deps?: DepSummary;
|
|
@@ -260,20 +268,11 @@ interface VarMapEntry {
|
|
|
260
268
|
}>;
|
|
261
269
|
}
|
|
262
270
|
/**
|
|
263
|
-
* 默认的参与编译判定:`.ts` 且源码里出现 `extends CompElem` 或 `@tag
|
|
264
|
-
*
|
|
265
|
-
* 额外放行**家族装饰器**形态:mixin 文件(`export function mix(B) { class M extends B { @prop … } }`)
|
|
266
|
-
* 既不含 `extends CompElem` 也不含 `@tag`(`@tag` 挂在具体组件上),但必须参与编译,
|
|
267
|
-
* 否则其中的 `@prop/@state/@computed` 不会被剥离、注入的 `__ce_static__` 缺失,
|
|
268
|
-
* 而运行时这几个装饰器是 no-op ⇒ 属性静默退化成普通实例字段。
|
|
269
|
-
* 精确性由 `collectMixinClasses` 的「顶层函数体内 + 带 compelem 家族装饰器」把关,
|
|
270
|
-
* 这里放宽只是让文件进入管线。
|
|
271
|
-
*
|
|
272
|
-
* ⚠️ 保持只收 `.ts`:IIFE 打包产物(`.js`)里指令名不在 scope,放宽会触发 D3 误报。
|
|
271
|
+
* 默认的参与编译判定:`.ts` 且源码里出现 `extends CompElem` 或 `@tag`
|
|
273
272
|
*/
|
|
274
273
|
declare function defaultInclude(id: string, code: string): boolean;
|
|
275
|
-
/**
|
|
274
|
+
/** 编译单个文件。解析失败时原样返回;静态分析/模板 codegen 失败会抛 StaticAnalysisError。 */
|
|
276
275
|
declare function compileFile(code: string, id: string, options?: CompilerOptions): CompileResult;
|
|
277
276
|
//#endregion
|
|
278
|
-
export { type CompileResult, type CompiledStatic, type CompilerOptions, type ComponentAnalysis, DEBUG_DIV, type DepSummary, type ReactiveField, type ReactiveKind, type RenderAnalysis, StaticAnalysisError, type VitePluginOptions, analyzeFile, analyzeRender, buildStaticLiteral, collectCompelemImports, compelemCompiler, compileFile,
|
|
277
|
+
export { type CompileResult, type CompiledStatic, type CompilerOptions, type ComponentAnalysis, DEBUG_DIV, type DepSummary, type ReactiveField, type ReactiveKind, type RenderAnalysis, StaticAnalysisError, type VitePluginOptions, analyzeFile, analyzeRender, assertStaticAnalysis, buildStaticLiteral, collectCompelemImports, compelemCompiler, compileFile, defaultInclude, injectInto, inlineTemplateMethods, isCompelemSource, parse };
|
|
279
278
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { a as buildStaticLiteral, c as
|
|
1
|
+
import { a as buildStaticLiteral, c as StaticAnalysisError, d as analyzeRender, f as analyzeFile, h as parse, i as defaultInclude, l as assertStaticAnalysis, m as isCompelemSource, o as injectInto, p as collectCompelemImports, r as compileFile, s as DEBUG_DIV, t as compelemCompiler, u as inlineTemplateMethods } from "./vite-CY_6E-Ut.js";
|
|
2
2
|
|
|
3
|
-
export { DEBUG_DIV, StaticAnalysisError, analyzeFile, analyzeRender, buildStaticLiteral, collectCompelemImports, compelemCompiler, compileFile,
|
|
3
|
+
export { DEBUG_DIV, StaticAnalysisError, analyzeFile, analyzeRender, assertStaticAnalysis, buildStaticLiteral, collectCompelemImports, compelemCompiler, compileFile, defaultInclude, injectInto, inlineTemplateMethods, isCompelemSource, parse };
|