@compelem/compiler 0.0.0-stage → 0.30.0-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.
- package/LICENSE +21 -0
- package/README.md +2 -2
- package/dist/index.d.ts +279 -0
- package/dist/index.js +3 -0
- package/dist/vite-BtG-4Z6L.d.ts +220 -0
- package/dist/vite-DU4Nznh4.js +7693 -0
- package/dist/vite-DU4Nznh4.js.map +1 -0
- package/dist/vite.d.ts +2 -0
- package/dist/vite.js +3 -0
- package/package.json +62 -3
package/LICENSE
ADDED
|
@@ -0,0 +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.
|
package/README.md
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @compelem/compiler
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
[compelem](https://github.com/holyhigh2/compelem) 的**编译器**
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,279 @@
|
|
|
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-BtG-4Z6L.js";
|
|
2
|
+
|
|
3
|
+
//#region src/utils/oxc.d.ts
|
|
4
|
+
interface ParsedFile {
|
|
5
|
+
program: any;
|
|
6
|
+
/** 源码中所有 import 声明:本地名 → { source, imported } */
|
|
7
|
+
imports: Map<string, {
|
|
8
|
+
source: string;
|
|
9
|
+
imported: string;
|
|
10
|
+
}>;
|
|
11
|
+
}
|
|
12
|
+
//#endregion
|
|
13
|
+
//#region src/analyze/component.d.ts
|
|
14
|
+
|
|
15
|
+
/** 判断某个 import source 是否指向 compelem 本体。 */
|
|
16
|
+
declare function isCompelemSource(source: string): boolean;
|
|
17
|
+
/** 从 import 表里挑出 compelem 相关绑定:本地名 → 原始导入名。 */
|
|
18
|
+
declare function collectCompelemImports(imports: ParsedFile['imports']): Map<string, string>;
|
|
19
|
+
/**
|
|
20
|
+
* 分析单个源文件,返回所有 compelem 组件类的信息。
|
|
21
|
+
*
|
|
22
|
+
* `extraFields` 用于合并基类字段(编译器单文件分析,跨文件继承由调用方
|
|
23
|
+
* 通过 `componentIndex` 提供;本版本仅处理同文件继承 + 无继承两种)。
|
|
24
|
+
*/
|
|
25
|
+
declare function analyzeFile(code: string, id: string, parsed: ParsedFile): ComponentAnalysis[];
|
|
26
|
+
//#endregion
|
|
27
|
+
//#region src/analyze/template.d.ts
|
|
28
|
+
|
|
29
|
+
interface TemplateIssue {
|
|
30
|
+
/** 违规模板在源码中的起始/结束偏移 */
|
|
31
|
+
start: number;
|
|
32
|
+
end: number;
|
|
33
|
+
/** 违规插值表达式的偏移 */
|
|
34
|
+
exprStart: number;
|
|
35
|
+
exprEnd: number;
|
|
36
|
+
message: string;
|
|
37
|
+
}
|
|
38
|
+
//#endregion
|
|
39
|
+
//#region src/analyze/render-body.d.ts
|
|
40
|
+
|
|
41
|
+
/** 主视图依赖提取结果。 */
|
|
42
|
+
interface RenderAnalysis {
|
|
43
|
+
/** 主视图依赖路径(对应 ViewDepMap) */
|
|
44
|
+
viewDeps: string[];
|
|
45
|
+
/** 子视图依赖:回调节点 start 偏移 → 路径列表 */
|
|
46
|
+
subViewDeps: Map<number, string[]>;
|
|
47
|
+
/** 降级原因列表(空表示未降级) */
|
|
48
|
+
degrades: string[];
|
|
49
|
+
/**
|
|
50
|
+
* 硬性违规(当前只有 D7:模板内直接嵌套模板)。
|
|
51
|
+
*
|
|
52
|
+
* 与 degrades 的区别:degrades 是「静态推不出,放弃注入(降级)」,
|
|
53
|
+
* errors 是「写法违反约束,必须改代码」——二者都导致降级,但 errors 需要在
|
|
54
|
+
* 构建期报给用户,因为它是可修的、且修掉后才能启用编译期产物。
|
|
55
|
+
*/
|
|
56
|
+
errors: TemplateIssue[];
|
|
57
|
+
}
|
|
58
|
+
/** 对单个组件的 render() 做依赖分析。 */
|
|
59
|
+
declare function analyzeRender(comp: ComponentAnalysis, sinks?: {
|
|
60
|
+
mainHits: any[];
|
|
61
|
+
}): RenderAnalysis;
|
|
62
|
+
//#endregion
|
|
63
|
+
//#region src/analyze/degrade.d.ts
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* 汇总单个组件的静态分析结论。
|
|
67
|
+
* 命中任何一条 ⇒ 抛错(调用方拿不到「凑合能跑」的产物)。
|
|
68
|
+
*/
|
|
69
|
+
declare function decideDegrade(comp: ComponentAnalysis, ra: RenderAnalysis): {
|
|
70
|
+
degraded: false;
|
|
71
|
+
reason: null;
|
|
72
|
+
errors: RenderAnalysis['errors'];
|
|
73
|
+
};
|
|
74
|
+
/**
|
|
75
|
+
* 静态分析未通过。`name` 让它在堆栈里一眼可辨。 */
|
|
76
|
+
declare class StaticAnalysisError extends Error {
|
|
77
|
+
readonly className: string;
|
|
78
|
+
readonly reasons: string[];
|
|
79
|
+
readonly errors: RenderAnalysis['errors'];
|
|
80
|
+
constructor(className: string, reasons: string[], errors?: RenderAnalysis['errors']);
|
|
81
|
+
}
|
|
82
|
+
//#endregion
|
|
83
|
+
//#region src/codegen/inject.d.ts
|
|
84
|
+
interface InjectOptions {
|
|
85
|
+
/** 是否生成取值函数 */
|
|
86
|
+
buildVars?: boolean;
|
|
87
|
+
/** 无视图组件标记:注入 noView: true(不创建 Shadow DOM) */
|
|
88
|
+
noView?: boolean;
|
|
89
|
+
}
|
|
90
|
+
/** `buildStaticLiteral` 可选生成物(任一缺失则对应字段不注入)。 */
|
|
91
|
+
interface StaticLiteralCodes {
|
|
92
|
+
/** per-point effect 工厂数组(值/指令点的订阅与写 DOM) */
|
|
93
|
+
pointEffects?: string;
|
|
94
|
+
/**
|
|
95
|
+
* `fx`:与 ups 逐项 1:1 的工厂数组。值点返回 effect,指令点返回 DirectiveInstance,
|
|
96
|
+
* 事件/ref 点返回 handler / ref 对象。renderTemplate 借它取首屏值,运行时按
|
|
97
|
+
* up 上的 `ux` 下标索引(Q2 的前提:ups 与工厂 1:1 后才能互查)。
|
|
98
|
+
*/
|
|
99
|
+
fx?: string;
|
|
100
|
+
/** watch effect 工厂数组 */
|
|
101
|
+
watchEffects?: string;
|
|
102
|
+
/** cssVars effect 工厂(读 CSS 依赖信号 → 更新自定义属性) */
|
|
103
|
+
cssEffect?: string;
|
|
104
|
+
/** 结构指令元数据占位字段,运行时从不读取(分派参数在 pointEffects 内) */
|
|
105
|
+
dirMeta?: string;
|
|
106
|
+
buildTemplate?: string;
|
|
107
|
+
/** 子视图表(结构指令的子模板元数据):`subViews: { <subId>: { buildTemplate, fx } }` */
|
|
108
|
+
subViews?: string;
|
|
109
|
+
/**
|
|
110
|
+
* 抽出的表达式中用到的 `super.METHOD` 名。注入到 class 体:
|
|
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) */
|
|
116
|
+
props?: string;
|
|
117
|
+
/** `__ce_static__.states` 字面量值(@state 前移) */
|
|
118
|
+
states?: string;
|
|
119
|
+
/** `__ce_static__.computedGetters` 字面量值(@computed 前移,原 getter 体外提) */
|
|
120
|
+
computedGetters?: string;
|
|
121
|
+
/** 类体访问器源码(prop/state/computed 的 get/set + `@tag` 类的 observedAttributes),
|
|
122
|
+
* 接在 static 字面量之后注入。无 `@tag` 的类不带 observedAttributes —— 它们永不被
|
|
123
|
+
* `customElements.define`,浏览器不会读它们的表。 */
|
|
124
|
+
accessors?: string;
|
|
125
|
+
}
|
|
126
|
+
/** prop/state 初始值写入语句的构造体插入点计划。 */
|
|
127
|
+
interface CtorInsertPlan {
|
|
128
|
+
/** 插入点(原始源码偏移) */
|
|
129
|
+
pos: number;
|
|
130
|
+
/** true = 类无构造体 → 合成 `constructor(...__a){ super(...__a); ... }` */
|
|
131
|
+
synthesize: boolean;
|
|
132
|
+
}
|
|
133
|
+
/** 文件级运行时函数 import 注入参数。 */
|
|
134
|
+
interface ImportInjectOptions {
|
|
135
|
+
/** 需要导入的运行时函数名(已定名,含可能的 __ce_ 别名) */
|
|
136
|
+
helpers?: string[];
|
|
137
|
+
/** 定位到的 compelem import 声明:有命名 specifier 则原位扩展,否则新增独立行 */
|
|
138
|
+
helperImport?: {
|
|
139
|
+
decl: any;
|
|
140
|
+
source: string;
|
|
141
|
+
};
|
|
142
|
+
/** 新增独立 import 行时的锚点(首个 import 起点或首语句起点) */
|
|
143
|
+
helpersAnchor?: number;
|
|
144
|
+
/** 需要从 **myfx** 注入的运行时函数名(方法装饰器前移的 debounce/throttle/once) */
|
|
145
|
+
myfxHelpers?: string[];
|
|
146
|
+
/** 定位到的 myfx import 声明:有命名 specifier 则原位扩展,否则新增独立行 */
|
|
147
|
+
myfxImport?: {
|
|
148
|
+
decl: any;
|
|
149
|
+
source: string;
|
|
150
|
+
};
|
|
151
|
+
/**
|
|
152
|
+
* 顶层语句(模块级常量,如子模板 carrier `const __ce_t0 = Object.assign(...)`),
|
|
153
|
+
* 插在 `topLevelAnchor` 之后(通常取最后一个 import 声明的末尾偏移)。
|
|
154
|
+
*/
|
|
155
|
+
topLevel?: string;
|
|
156
|
+
/** topLevel 的插入锚点(紧跟其后的偏移) */
|
|
157
|
+
topLevelAnchor?: number;
|
|
158
|
+
}
|
|
159
|
+
/** 生成 `static __ce_static__ = {...}` 的源码文本。 */
|
|
160
|
+
declare function buildStaticLiteral(opts: InjectOptions, codes?: StaticLiteralCodes): string;
|
|
161
|
+
/**
|
|
162
|
+
* 把生成物注入到源文件。
|
|
163
|
+
*
|
|
164
|
+
* 多个组件在同文件时按 **end 倒序** 插入,避免前一次插入改变后一次偏移。
|
|
165
|
+
*/
|
|
166
|
+
declare function injectInto(code: string, edits: Array<{
|
|
167
|
+
comp: ComponentAnalysis;
|
|
168
|
+
literal: string;
|
|
169
|
+
removals?: Array<{
|
|
170
|
+
start: number;
|
|
171
|
+
end: number;
|
|
172
|
+
}>;
|
|
173
|
+
fieldInits?: Array<{
|
|
174
|
+
name: string;
|
|
175
|
+
initText: string;
|
|
176
|
+
computed?: boolean;
|
|
177
|
+
}>;
|
|
178
|
+
ctor?: CtorInsertPlan;
|
|
179
|
+
/** 方法装饰器(@debounced/@throttled/@onced)构造体注入语句 */
|
|
180
|
+
methodDecoCtor?: string;
|
|
181
|
+
/** 方法装饰器 destroy 注入语句(插到 destroy() 内) */
|
|
182
|
+
methodDecoDestroy?: string;
|
|
183
|
+
}>, id: string, extras?: ImportInjectOptions): {
|
|
184
|
+
code: string;
|
|
185
|
+
map: any;
|
|
186
|
+
injected: string[];
|
|
187
|
+
additions: string[];
|
|
188
|
+
};
|
|
189
|
+
//#endregion
|
|
190
|
+
//#region src/compile.d.ts
|
|
191
|
+
/** 静态编译完成后的组件依赖清单(`options.verbose` 时打印;结构化字段供工具/survey 消费)。 */
|
|
192
|
+
interface DepSummary {
|
|
193
|
+
kind: 'normal' | 'noView' | 'skipInjection';
|
|
194
|
+
/** 主视图响应式依赖(仅 verbose 依赖清单展示,不注入产物) */
|
|
195
|
+
viewDeps: string[];
|
|
196
|
+
/** cssVars getter 依赖;undefined = 未提取到 */
|
|
197
|
+
cssDeps?: string[];
|
|
198
|
+
/** @computed getter 依赖;undefined = 未提取到(该类全部 key 由运行时全根兜底) */
|
|
199
|
+
computedDeps?: Record<string, string[]>;
|
|
200
|
+
/** 结构指令子视图依赖(subId → 路径);undefined = 未提取到 */
|
|
201
|
+
subViewDeps?: Record<number, string[]>;
|
|
202
|
+
/** @watch 编译期解析产物(sources 即监视依赖) */
|
|
203
|
+
watchers?: Array<{
|
|
204
|
+
name: string;
|
|
205
|
+
sources: string[];
|
|
206
|
+
}>;
|
|
207
|
+
/** 主视图更新映射:每根变量 → 取值槽位 → 更新点下标 → DOM 点位(normal 组件且 verbose 展示时) */
|
|
208
|
+
varMap?: VarMapEntry[];
|
|
209
|
+
/** 子视图更新映射:subId → 每根路径的槽位/updater/DOM */
|
|
210
|
+
subVarMap?: Record<number, VarMapEntry[]>;
|
|
211
|
+
}
|
|
212
|
+
interface CompileResult {
|
|
213
|
+
code: string;
|
|
214
|
+
map: any;
|
|
215
|
+
/** 本次编译的诊断信息(组件级) */
|
|
216
|
+
diagnostics: Array<{
|
|
217
|
+
className: string;
|
|
218
|
+
degraded: boolean;
|
|
219
|
+
reason: string | null;
|
|
220
|
+
viewDeps: number;
|
|
221
|
+
/** 硬性违规(D7 嵌套模板),需在构建期暴露给用户 */
|
|
222
|
+
errors: Array<{
|
|
223
|
+
start: number;
|
|
224
|
+
end: number;
|
|
225
|
+
exprStart: number;
|
|
226
|
+
exprEnd: number;
|
|
227
|
+
message: string;
|
|
228
|
+
}>;
|
|
229
|
+
/** 约定错误(emit/@prop/@computed/@csscope 静态校验),与降级无关 */
|
|
230
|
+
conventionErrors: Array<{
|
|
231
|
+
start: number;
|
|
232
|
+
end: number;
|
|
233
|
+
message: string;
|
|
234
|
+
}>;
|
|
235
|
+
/** 静态依赖清单(每组件无条件填充;options.verbose 时输出人类可读格式) */
|
|
236
|
+
deps?: DepSummary;
|
|
237
|
+
}>;
|
|
238
|
+
/** 是否发生了源码改动 */
|
|
239
|
+
changed: boolean;
|
|
240
|
+
/** 本次编译从源码删除的 span(装饰器/字段成员/静态准入组件的 render 体,原始偏移;供最小侵入校验还原比对) */
|
|
241
|
+
removals?: Array<{
|
|
242
|
+
start: number;
|
|
243
|
+
end: number;
|
|
244
|
+
}>;
|
|
245
|
+
/** 本次编译新增的源码片段(注入的 import 片段 / 构造体写入语句;供最小侵入校验剥离) */
|
|
246
|
+
additions?: string[];
|
|
247
|
+
}
|
|
248
|
+
/** 单个根变量的更新映射(依赖清单展示):根 → 取值槽位 → 更新点下标 → DOM 点位。 */
|
|
249
|
+
interface VarMapEntry {
|
|
250
|
+
/** 根名(`''` = 常脏:动态 this / 不纯 / 未分类表达式) */
|
|
251
|
+
root: string;
|
|
252
|
+
/** 根类别:已知字段 kind / 自有 getter / 自有方法 / 跨文件未声明(基类 prop、state、@computed 等) */
|
|
253
|
+
kind?: 'prop' | 'state' | 'computed' | 'getter' | 'method' | 'unknown';
|
|
254
|
+
/** 该根驱动的取值槽位下标(脏集,仅对脏槽求值) */
|
|
255
|
+
vars: number[];
|
|
256
|
+
/** 消费这些槽位的更新点:updater = ups 数组下标(与 ups 同序),dom = 节点名 + 点位 */
|
|
257
|
+
updates: Array<{
|
|
258
|
+
updater: number;
|
|
259
|
+
dom: string;
|
|
260
|
+
}>;
|
|
261
|
+
}
|
|
262
|
+
/**
|
|
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 误报。
|
|
273
|
+
*/
|
|
274
|
+
declare function defaultInclude(id: string, code: string): boolean;
|
|
275
|
+
/** 编译单个文件。不会抛出:解析失败时原样返回。 */
|
|
276
|
+
declare function compileFile(code: string, id: string, options?: CompilerOptions): CompileResult;
|
|
277
|
+
//#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, decideDegrade, defaultInclude, injectInto, isCompelemSource };
|
|
279
|
+
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { a as buildStaticLiteral, c as analyzeRender, d as analyzeFile, f as collectCompelemImports, i as defaultInclude, l as StaticAnalysisError, o as injectInto, p as isCompelemSource, r as compileFile, s as DEBUG_DIV, t as compelemCompiler, u as decideDegrade } from "./vite-DU4Nznh4.js";
|
|
2
|
+
|
|
3
|
+
export { DEBUG_DIV, StaticAnalysisError, analyzeFile, analyzeRender, buildStaticLiteral, collectCompelemImports, compelemCompiler, compileFile, decideDegrade, defaultInclude, injectInto, isCompelemSource };
|
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
//#region src/types.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* @compelem/compiler — 类型定义
|
|
4
|
+
*
|
|
5
|
+
* 与 compelem 侧 `CompiledStatic`(src/types.ts)保持结构一致。
|
|
6
|
+
* 双份定义的取舍:compiler 不应强依赖 compelem 的类型包(peer 可选),
|
|
7
|
+
* 因此本地镜像一份,并在 `test/` 里做一致性断言防止漂移。
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* 每个类的 `props`/`states`/`computedGetters` 都是**沿构造器原型链浅替换合并后的
|
|
11
|
+
* 完整表**(子类字面量叠加 `Reflect.getPrototypeOf(this).__ce_static__`)。
|
|
12
|
+
*/
|
|
13
|
+
/** debug 分块产物的整行注释前缀:`//////// …… <标签>`(纯注释、不改行为)。产物默认按块生成,无开关。 */
|
|
14
|
+
declare const DEBUG_DIV = "////////////////////////////////////";
|
|
15
|
+
/**
|
|
16
|
+
* 编译器注入到组件类上的静态成员。
|
|
17
|
+
* 强制编译插件模式:`buildTemplate` 准入静态视图路径(缺失 = 无视图,无运行时回退);
|
|
18
|
+
* 其余字段可选。取值表达式一律内联进 fx/pointEffects 工厂,产物不携带取值函数或
|
|
19
|
+
* 静态依赖元数据;依赖在 effect 运行期动态建立(DepSummary 仅在 compile.ts 内部
|
|
20
|
+
* 计算,供 verbose 展示)。
|
|
21
|
+
*/
|
|
22
|
+
interface CompiledStatic {
|
|
23
|
+
version: number;
|
|
24
|
+
/**
|
|
25
|
+
* `buildTemplate` 静态实现:纯 `document` API 建 DOM 函数
|
|
26
|
+
* (以首个组件实例为 `this` 调用;与 compelem 侧 `CompiledStatic.buildTemplate` 同形)。
|
|
27
|
+
*/
|
|
28
|
+
buildTemplate?: (this: any) => {
|
|
29
|
+
fragment: any;
|
|
30
|
+
ups: any[];
|
|
31
|
+
emptyEvents?: Record<number, string[]>;
|
|
32
|
+
/** 文档序元素+文本节点(与 nodeSn 对齐;运行时免 collectNodes 回扫) */
|
|
33
|
+
nodes?: any[];
|
|
34
|
+
updateSns?: number[];
|
|
35
|
+
updatePaths?: number[][];
|
|
36
|
+
};
|
|
37
|
+
/** `@watch` 编译期解析产物(`analyze/watch-extract.ts` 序列化,装饰器被删时必须注入) */
|
|
38
|
+
watchers?: CompiledWatcher[];
|
|
39
|
+
/**
|
|
40
|
+
* 结构指令模板回调的子视图 codegen:`__subId` → 独立 buildTemplate + fx/pointEffects。
|
|
41
|
+
* 运行时结构指令经 `fn.__subId` 查表消费;缺失按构建期报错处理。
|
|
42
|
+
*/
|
|
43
|
+
subViews?: Record<number, {
|
|
44
|
+
buildTemplate?: (this: any) => {
|
|
45
|
+
fragment: any;
|
|
46
|
+
ups: any[];
|
|
47
|
+
emptyEvents?: Record<number, string[]>;
|
|
48
|
+
nodes?: any[];
|
|
49
|
+
updateSns?: number[];
|
|
50
|
+
updatePaths?: number[][];
|
|
51
|
+
};
|
|
52
|
+
}>;
|
|
53
|
+
/**
|
|
54
|
+
* 无视图组件标记:render() 不存在 / 返回 null / 继承链终点为 CompElem(其
|
|
55
|
+
* `render()` 返回 null)。注入后运行时不创建 Shadow DOM,仅支持 HOST/GLOBAL 样式。
|
|
56
|
+
*/
|
|
57
|
+
noView?: boolean;
|
|
58
|
+
}
|
|
59
|
+
/** `@watch` 编译期解析条目(与 compelem `CompiledWatcher` 同形) */
|
|
60
|
+
interface CompiledWatcher {
|
|
61
|
+
name: string;
|
|
62
|
+
sources: string[];
|
|
63
|
+
deep?: boolean;
|
|
64
|
+
immediate?: boolean;
|
|
65
|
+
once?: boolean;
|
|
66
|
+
static?: boolean;
|
|
67
|
+
}
|
|
68
|
+
/** 响应式字段类别,用于判定「该成员是否会被推入依赖收集列表」。 */
|
|
69
|
+
type ReactiveKind = 'prop' | 'state' | 'computed';
|
|
70
|
+
/** 组件内一个响应式成员的信息。 */
|
|
71
|
+
interface ReactiveField {
|
|
72
|
+
name: string;
|
|
73
|
+
kind: ReactiveKind;
|
|
74
|
+
/** 静态初始化器里的默认值表达式源码(用于静态取值内联),无则 undefined */
|
|
75
|
+
init?: string;
|
|
76
|
+
/** 是否为深层对象(init 是对象/数组字面量),影响依赖路径展开 */
|
|
77
|
+
shallow: boolean;
|
|
78
|
+
}
|
|
79
|
+
/** 一个组件的完整静态分析结果。 */
|
|
80
|
+
interface ComponentAnalysis {
|
|
81
|
+
className: string;
|
|
82
|
+
/**
|
|
83
|
+
* 该组件的 class AST 节点本体。
|
|
84
|
+
*
|
|
85
|
+
* 直接随分析结果下发节点本身:按名反查 `localClasses` 只覆盖**模块顶层**的
|
|
86
|
+
* `ClassDeclaration`,mixin 工厂内的类在函数作用域里按名查不到,会让
|
|
87
|
+
* `field-extract` / `watch-extract` / `conventions` 拿到 `undefined` 而静默
|
|
88
|
+
* 什么都不做。
|
|
89
|
+
*/
|
|
90
|
+
cls?: any;
|
|
91
|
+
/** 源文件中该 class 声明的起始/结束偏移(用于 MagicString 注入) */
|
|
92
|
+
start: number;
|
|
93
|
+
end: number;
|
|
94
|
+
/**
|
|
95
|
+
* 类体左花括号 `{` 的源码偏移(`cls.body.start`)。
|
|
96
|
+
*
|
|
97
|
+
* 注入锚点必须是它,不能用 `code.indexOf('{', start)` —— `extends mixin({ a: 1 })`
|
|
98
|
+
* 里第一个 `{` 落在 extends 子句中,扫到那里会把 `static __ce_static__` 插进
|
|
99
|
+
* 对象字面量里,产出整模块语法错误。-1 表示无 AST 可用(调用方应回退扫描)。
|
|
100
|
+
*/
|
|
101
|
+
bodyStart: number;
|
|
102
|
+
/** `@tag` 名称,无则 undefined */
|
|
103
|
+
tagName?: string;
|
|
104
|
+
/** 响应式字段(含继承链上收集到的,按声明顺序) */
|
|
105
|
+
fields: Map<string, ReactiveField>;
|
|
106
|
+
/** 本类自身定义的实例方法名(用于 D2 降级判定) */
|
|
107
|
+
ownMethods: Set<string>;
|
|
108
|
+
/** 本类自身定义的 getter 名(`@computed` 之外的普通 getter,D2 视为方法) */
|
|
109
|
+
ownGetters: Set<string>;
|
|
110
|
+
/** 是否有 render() */
|
|
111
|
+
hasRender: boolean;
|
|
112
|
+
/** render() 函数体 AST(Program 级 node),无则 null */
|
|
113
|
+
renderBody: any | null;
|
|
114
|
+
/** render() 函数体在源码中的偏移区间(不含大括号) */
|
|
115
|
+
renderBodyStart: number;
|
|
116
|
+
renderBodyEnd: number;
|
|
117
|
+
/** `get cssVars()` 函数体语句数组(无则 null),供 cssDeps 静态提取 */
|
|
118
|
+
cssVarsBody: any[] | null;
|
|
119
|
+
/** `@computed` getter 名 → 函数体语句数组,供 computedDeps 静态提取 */
|
|
120
|
+
computedBodies: Map<string, any[]>;
|
|
121
|
+
/** `@query` / `@queryAll` 字段名(非响应式 DOM 查询属性,依赖提取按死条目记录) */
|
|
122
|
+
queryFields?: Set<string>;
|
|
123
|
+
/** 本类方法 / getter / 箭头字段的函数体(name → BlockStatement 节点或表达式体),供依赖提取内联扫描 */
|
|
124
|
+
bodies?: Map<string, any>;
|
|
125
|
+
/** 降级原因;null 表示未降级 */
|
|
126
|
+
degradeReason: string | null;
|
|
127
|
+
/** 无视图组件(render() 不存在 / 返回 null / 继承链终点为 CompElem)→ 注入 noView: true */
|
|
128
|
+
noView: boolean;
|
|
129
|
+
/** 跳过注入(同文件继承链上有 render 的祖先,继承其 __ce_static__)→ 不生成注入语句 */
|
|
130
|
+
skipInjection: boolean;
|
|
131
|
+
/**
|
|
132
|
+
* **mixin 工厂内的 class 声明**(`export function mix(B) { class M extends B {} ; return M }`)。
|
|
133
|
+
*
|
|
134
|
+
* super 是调用方传入的形参 ⇒ 静态不可知链:不做 D6 报错、无 own render 时一律
|
|
135
|
+
* `skipInjection`(绝不判 `noView`,否则基类有视图时会静默白屏)。
|
|
136
|
+
* 家族表(props/states/computedGetters)的合并走 `Reflect.getPrototypeOf(this)`,
|
|
137
|
+
* 与本标记无关,mixin 声明的 @prop 会沿链传递到具体组件。
|
|
138
|
+
*
|
|
139
|
+
* 写法约束:必须是 class **声明**,不能是 class **表达式** —— TS 禁止在 class
|
|
140
|
+
* 表达式上写装饰器(TS1206),能带 `@prop` 的形态只有 class 声明。
|
|
141
|
+
*/
|
|
142
|
+
isMixin?: boolean;
|
|
143
|
+
/** 静态导入绑定:本地名 → 从 compelem 导入的原始名 */
|
|
144
|
+
compelemImports: Map<string, string>;
|
|
145
|
+
/**
|
|
146
|
+
* 模块级绑定名(顶层 const/let/var/function/class,以及全部 import 的本地名)。
|
|
147
|
+
* 用于 D3 判定:这些名字不是「自由标识符」。
|
|
148
|
+
*/
|
|
149
|
+
moduleBindings: Set<string>;
|
|
150
|
+
}
|
|
151
|
+
/** 插件选项。 */
|
|
152
|
+
interface CompilerOptions {
|
|
153
|
+
/**
|
|
154
|
+
* 参与编译的文件过滤。默认只处理 `.ts` 且源码里出现 `extends CompElem` 的文件。
|
|
155
|
+
* ⚠️ 不要放宽到 `.js`:IIFE 打包产物里指令名不在 scope,会触发 D3 误报。
|
|
156
|
+
*/
|
|
157
|
+
include?: (id: string, code: string) => boolean;
|
|
158
|
+
/**
|
|
159
|
+
* verbose 日志:依赖清单人类可读打印(vite 插件侧同时打印每文件编译状态行)。
|
|
160
|
+
* 也可用环境变量 `CE_DEPS_DEBUG`(非空且非 '0')单独开启清单打印,无需改配置。
|
|
161
|
+
* 注:产物的块分隔注释(`//////// …… <标签>`)默认始终生成,与本选项无关。
|
|
162
|
+
*/
|
|
163
|
+
verbose?: boolean;
|
|
164
|
+
/**
|
|
165
|
+
* 跨文件标签注册表:已知组件的 kebab 标签名(大小写不敏感)。
|
|
166
|
+
* 用于 SLOT 判定与 `.prop` 目标校验;vite 插件可跨文件累积后注入
|
|
167
|
+
* (TEMPLATE-CODEGEN.md §4)。
|
|
168
|
+
*/
|
|
169
|
+
knownTags?: Iterable<string>;
|
|
170
|
+
/** 关闭指定生成步骤(用于 A/B 实测对照) */
|
|
171
|
+
disable?: {
|
|
172
|
+
buildVars?: boolean;
|
|
173
|
+
};
|
|
174
|
+
}
|
|
175
|
+
//#endregion
|
|
176
|
+
//#region src/vite.d.ts
|
|
177
|
+
/** 极简的结构化插件类型,避免硬依赖 vite 的 types(peer 里 vite 是可选的)。 */
|
|
178
|
+
interface MinimalPlugin {
|
|
179
|
+
name: string;
|
|
180
|
+
enforce?: 'pre' | 'post';
|
|
181
|
+
transform?: (code: string, id: string) => {
|
|
182
|
+
code: string;
|
|
183
|
+
map: any;
|
|
184
|
+
} | null | undefined;
|
|
185
|
+
configResolved?: (config: any) => void;
|
|
186
|
+
buildStart?: (this: any) => void | Promise<void>;
|
|
187
|
+
}
|
|
188
|
+
interface VitePluginOptions extends CompilerOptions {
|
|
189
|
+
/** 是否输出每个文件的编译诊断 */
|
|
190
|
+
verbose?: boolean;
|
|
191
|
+
/**
|
|
192
|
+
* D7(模板内直接嵌套模板)命中的处理力度。
|
|
193
|
+
* - `'warn'`(默认):仅控制台提示 D7 消息
|
|
194
|
+
* - `'error'`:直接阻断构建,用于 CI 强制把关
|
|
195
|
+
* - `'silent'`:不提示
|
|
196
|
+
*/
|
|
197
|
+
d7?: 'warn' | 'error' | 'silent';
|
|
198
|
+
/**
|
|
199
|
+
* 约定错误(E-*:emit 未声明/非字面量、@prop 缺 type/命名/赋值、@computed 非 getter、
|
|
200
|
+
* @csscope 非 static getter)的处理力度。默认 `'error'` —— 约定违规直接阻断构建。
|
|
201
|
+
*/
|
|
202
|
+
conventions?: 'error' | 'warn' | 'silent';
|
|
203
|
+
/**
|
|
204
|
+
* 调试用:把编译产物写到源文件同级(`foo.ts` → `foo.js`),便于直接查看
|
|
205
|
+
* 注入后的 `__ce_static__` / buildTemplate / pointEffects / fx。
|
|
206
|
+
* 仅对真实文件生效(跳过 `?v=` 之类的虚拟 id),且只在编译确有改动时写。
|
|
207
|
+
*/
|
|
208
|
+
emitJs?: boolean;
|
|
209
|
+
/**
|
|
210
|
+
* 调试编译产物用:令 sourcemap 以上游注入后的 TS 为 0 级原�? * 这样 DevTools 直接显示编译后代码(含 `__ce_static__` / buildTemplate / fx),
|
|
211
|
+
* 在这些区域打的断点能命中。代价:跳过「编译后代码 → 原始模板」的映射,
|
|
212
|
+
* 栈帧行号指向注入后的 TS 而非用户源码里的模板位置。默认 `false`。
|
|
213
|
+
*/
|
|
214
|
+
debugSourceMap?: boolean;
|
|
215
|
+
}
|
|
216
|
+
/** compelem 编译期优化插件。 */
|
|
217
|
+
declare function compelemCompiler(options?: VitePluginOptions): MinimalPlugin;
|
|
218
|
+
//#endregion
|
|
219
|
+
export { ComponentAnalysis as a, ReactiveKind as c, CompilerOptions as i, compelemCompiler as n, DEBUG_DIV as o, CompiledStatic as r, ReactiveField as s, VitePluginOptions as t };
|
|
220
|
+
//# sourceMappingURL=vite-BtG-4Z6L.d.ts.map
|