@compelem/compiler 0.30.0-beta.3 → 0.30.0-beta.5
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 +100 -21
- package/dist/index.js +2 -2
- package/dist/{vite-DwMiG3VM.js → vite-CLK9td6W.js} +2771 -2256
- package/dist/vite-CLK9td6W.js.map +1 -0
- package/dist/{vite-BAl4p1jA.d.ts → vite-D178A0gy.d.ts} +4 -12
- package/dist/vite.d.ts +1 -1
- package/dist/vite.js +1 -1
- package/package.json +60 -56
- package/dist/vite-DwMiG3VM.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,6 +9,8 @@ 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
16
|
/** 判断某个 import source 是否指向 compelem 本体。 */
|
|
@@ -23,6 +25,11 @@ declare function collectCompelemImports(imports: ParsedFile['imports']): Map<str
|
|
|
23
25
|
*/
|
|
24
26
|
declare function analyzeFile(code: string, id: string, parsed: ParsedFile): ComponentAnalysis[];
|
|
25
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
|
|
26
33
|
//#region src/analyze/template.d.ts
|
|
27
34
|
|
|
28
35
|
interface TemplateIssue {
|
|
@@ -36,7 +43,6 @@ interface TemplateIssue {
|
|
|
36
43
|
}
|
|
37
44
|
//#endregion
|
|
38
45
|
//#region src/analyze/render-body.d.ts
|
|
39
|
-
|
|
40
46
|
/** 主视图依赖提取结果。 */
|
|
41
47
|
interface RenderAnalysis {
|
|
42
48
|
/** 主视图依赖路径(对应 ViewDepMap) */
|
|
@@ -97,8 +103,6 @@ interface StaticLiteralCodes {
|
|
|
97
103
|
inlinedWatchAncestors?: boolean;
|
|
98
104
|
/** cssVars effect 工厂(读 CSS 依赖信号 → 更新自定义属性) */
|
|
99
105
|
cssEffect?: string;
|
|
100
|
-
/** 结构指令元数据占位字段,运行时从不读取(分派参数在 pointEffects 内) */
|
|
101
|
-
dirMeta?: string;
|
|
102
106
|
buildTemplate?: string;
|
|
103
107
|
/** 子视图表(结构指令的子模板元数据):`subViews: { <subId>: { buildTemplate, fx } }` */
|
|
104
108
|
subViews?: string;
|
|
@@ -120,11 +124,23 @@ interface CtorInsertPlan {
|
|
|
120
124
|
pos: number;
|
|
121
125
|
/** true = 类无构造体 → 合成 `constructor(...__a){ super(...__a); ... }` */
|
|
122
126
|
synthesize: boolean;
|
|
127
|
+
/**
|
|
128
|
+
* 警告级诊断(W 通道):super(…) 不在构造体顶层语句位时给出——
|
|
129
|
+
* 插入点只能退到构造体末尾,prop/state 初始值写入晚于分支内用户语句,
|
|
130
|
+
* 与原生字段初始化时机不严格等价。调用方转成 severity:'warn' 诊断。
|
|
131
|
+
*/
|
|
132
|
+
warn?: string;
|
|
123
133
|
}
|
|
124
134
|
/** 文件级运行时函数 import 注入参数。 */
|
|
125
135
|
interface ImportInjectOptions {
|
|
126
136
|
/** 需要导入的运行时函数名(已定名,含可能的 __ce_ 别名) */
|
|
127
137
|
helpers?: string[];
|
|
138
|
+
/**
|
|
139
|
+
* helper 的本地名 → 原始导出名。仅当本地名与导出名不同(冲突别名)时需要;
|
|
140
|
+
* 缺省按同名导入。例如 `{ __ce_signal: 'signal' }` →
|
|
141
|
+
* `import { signal as __ce_signal } from 'compelem'`。
|
|
142
|
+
*/
|
|
143
|
+
helperAliases?: Record<string, string>;
|
|
128
144
|
/** 定位到的 compelem import 声明:有命名 specifier 则原位扩展,否则新增独立行 */
|
|
129
145
|
helperImport?: {
|
|
130
146
|
decl: any;
|
|
@@ -134,6 +150,8 @@ interface ImportInjectOptions {
|
|
|
134
150
|
helpersAnchor?: number;
|
|
135
151
|
/** 需要从 **myfx** 注入的运行时函数名(方法装饰器前移的 debounce/throttle/once) */
|
|
136
152
|
myfxHelpers?: string[];
|
|
153
|
+
/** myfx helper 的本地名 → 原始导出名(同 helperAliases) */
|
|
154
|
+
myfxAliases?: Record<string, string>;
|
|
137
155
|
/** 定位到的 myfx import 声明:有命名 specifier 则原位扩展,否则新增独立行 */
|
|
138
156
|
myfxImport?: {
|
|
139
157
|
decl: any;
|
|
@@ -146,6 +164,12 @@ interface ImportInjectOptions {
|
|
|
146
164
|
topLevel?: string;
|
|
147
165
|
/** topLevel 的插入锚点(紧跟其后的偏移) */
|
|
148
166
|
topLevelAnchor?: number;
|
|
167
|
+
/** inline 预变换的原始坐标编辑;在 class 注入前统一 overwrite。 */
|
|
168
|
+
inlineEdits?: Array<{
|
|
169
|
+
start: number;
|
|
170
|
+
end: number;
|
|
171
|
+
text: string;
|
|
172
|
+
}>;
|
|
149
173
|
}
|
|
150
174
|
/** 生成 `static __ce_static__ = {...}` 的源码文本。 */
|
|
151
175
|
declare function buildStaticLiteral(opts: InjectOptions, codes?: StaticLiteralCodes): string;
|
|
@@ -209,15 +233,12 @@ interface CompileResult {
|
|
|
209
233
|
viewDeps: number;
|
|
210
234
|
/**
|
|
211
235
|
* 约定错误(emit/@prop/@computed/@csscope 静态校验)。
|
|
212
|
-
*
|
|
213
|
-
* ⚠️ 这里**只有**约定错误。静态分析未通过的组件不会出现在 diagnostics 里 ——
|
|
214
|
-
* `assertStaticAnalysis` 直接抛 `StaticAnalysisError`,模板 codegen 失败同样抛。
|
|
215
|
-
* 不合规就报错,没有「凑合能跑」的产物,因此诊断里不需要任何结论字段。
|
|
216
236
|
*/
|
|
217
237
|
conventionErrors: Array<{
|
|
218
238
|
start: number;
|
|
219
239
|
end: number;
|
|
220
240
|
message: string;
|
|
241
|
+
severity?: 'warn';
|
|
221
242
|
}>;
|
|
222
243
|
/** 静态依赖清单(每组件无条件填充;options.verbose 时输出人类可读格式) */
|
|
223
244
|
deps?: DepSummary;
|
|
@@ -247,20 +268,78 @@ interface VarMapEntry {
|
|
|
247
268
|
}>;
|
|
248
269
|
}
|
|
249
270
|
/**
|
|
250
|
-
* 默认的参与编译判定:`.ts` 且源码里出现 `extends CompElem` 或 `@tag
|
|
251
|
-
*
|
|
252
|
-
* 额外放行**家族装饰器**形态:mixin 文件(`export function mix(B) { class M extends B { @prop … } }`)
|
|
253
|
-
* 既不含 `extends CompElem` 也不含 `@tag`(`@tag` 挂在具体组件上),但必须参与编译,
|
|
254
|
-
* 否则其中的 `@prop/@state/@computed` 不会被剥离、注入的 `__ce_static__` 缺失,
|
|
255
|
-
* 而运行时这几个装饰器是 no-op ⇒ 属性静默退化成普通实例字段。
|
|
256
|
-
* 精确性由 `collectMixinClasses` 的「顶层函数体内 + 带 compelem 家族装饰器」把关,
|
|
257
|
-
* 这里放宽只是让文件进入管线。
|
|
258
|
-
*
|
|
259
|
-
* ⚠️ 保持只收 `.ts`:IIFE 打包产物(`.js`)里指令名不在 scope,放宽会触发 D3 误报。
|
|
271
|
+
* 默认的参与编译判定:`.ts` 且源码里出现 `extends CompElem` 或 `@tag`
|
|
260
272
|
*/
|
|
261
273
|
declare function defaultInclude(id: string, code: string): boolean;
|
|
262
|
-
/**
|
|
274
|
+
/** 编译单个文件。解析失败时原样返回;静态分析/模板 codegen 失败会抛 StaticAnalysisError。 */
|
|
263
275
|
declare function compileFile(code: string, id: string, options?: CompilerOptions): CompileResult;
|
|
276
|
+
/**
|
|
277
|
+
* 编译**已确定要编译**的源码,跳过 `include` 判定。
|
|
278
|
+
*
|
|
279
|
+
* 与 {@link compileFile} 的分工:
|
|
280
|
+
* - `compileFile` 面向「磁盘上可能是组件、也可能不是」的输入,先按扩展名 +
|
|
281
|
+
* 特征做 include 判定;
|
|
282
|
+
* - `compileSource` 面向「调用方已经决定要编译」的输入 —— 典型是 SFC 插件把
|
|
283
|
+
* `.ce` 分段拼成的虚拟 TypeScript 模块。虚拟模块的 id 仍是 `.ce`(为了
|
|
284
|
+
* sourcemap 指向真实文件),天然过不了 `defaultInclude` 的扩展名检查,
|
|
285
|
+
* 以前只能传 `include: () => true` 绕过整个判定(连 node_modules 排除也一起绕过)。
|
|
286
|
+
*
|
|
287
|
+
* `options.include` 在这里被忽略。
|
|
288
|
+
*/
|
|
289
|
+
declare function compileSource(code: string, id: string, options?: CompilerOptions): CompileResult;
|
|
290
|
+
//#endregion
|
|
291
|
+
//#region src/diagnostics.d.ts
|
|
292
|
+
/** 约定违规的处理力度:error 阻断构建 / warn 控制台提示 / silent 忽略。 */
|
|
293
|
+
type ConventionMode = 'error' | 'warn' | 'silent';
|
|
294
|
+
/** 已格式化为 `文件:行:列 [类名] 消息` 的两组诊断文本。 */
|
|
295
|
+
interface CollectedDiagnostics {
|
|
296
|
+
errs: string[];
|
|
297
|
+
warns: string[];
|
|
298
|
+
}
|
|
299
|
+
/** 惰性构建换行偏移索引(升序;仅在有诊断时付费一次)。 */
|
|
300
|
+
declare function newlineIndex(code: string): Int32Array;
|
|
301
|
+
/** 把源码偏移换算成 `行:列`(1 起算);带换行索引时走二分(O(log n))。 */
|
|
302
|
+
declare function offsetToLineCol(code: string, offset: number, nl?: Int32Array): string;
|
|
303
|
+
/** 相对 root 的展示路径(统一正斜杠,便于点击跳转)。 */
|
|
304
|
+
declare function relativeToRoot(id: string, root: string): string;
|
|
305
|
+
/**
|
|
306
|
+
* 从 diagnostics 收集**约定诊断**为可上报文本,按 severity 分为 errs(E-*)与 warns(W-*)。
|
|
307
|
+
*
|
|
308
|
+
* `root` 只用于把绝对路径压成相对路径,不影响判定。
|
|
309
|
+
*/
|
|
310
|
+
declare function collectDiagnostics(res: CompileResult, code: string, id: string, root: string): CollectedDiagnostics;
|
|
311
|
+
/**
|
|
312
|
+
* 按 mode 上报违规:error 走插件上下文的 `this.error`(阻断构建),warn 走控制台。
|
|
313
|
+
*
|
|
314
|
+
* `thisArg` 是 Rollup/Vite 的插件上下文;纯 API 调用时传 undefined 也能工作
|
|
315
|
+
* (退化为 `throw`)。
|
|
316
|
+
*/
|
|
317
|
+
declare function reportDiagnostics(msgs: string[], mode: ConventionMode, head: string, thisArg: any): void;
|
|
318
|
+
/**
|
|
319
|
+
* 一站式上报:W 码恒为控制台提示(不随档位阻断),E 码按 mode 处理。
|
|
320
|
+
*
|
|
321
|
+
* 返回是否发生了阻断(仅用于调用方决定是否继续)。
|
|
322
|
+
*/
|
|
323
|
+
declare function reportConventionDiagnostics(collected: CollectedDiagnostics, mode: ConventionMode, thisArg: any, tag?: string): void;
|
|
324
|
+
//#endregion
|
|
325
|
+
//#region src/tag-registry.d.ts
|
|
326
|
+
/** `@tag('x-foo')` / `@tag(\`x-foo\`)`;一次扫描内复用,调用方负责重置 lastIndex。 */
|
|
327
|
+
declare const TAG_RE: RegExp;
|
|
328
|
+
/** 默认只把 `.ts` / `.tsx` 当作组件来源。 */
|
|
329
|
+
declare const DEFAULT_TAG_EXT: RegExp;
|
|
330
|
+
interface ScanKnownTagsOptions {
|
|
331
|
+
/** 参与扫描的文件扩展名正则,默认 {@link DEFAULT_TAG_EXT}。 */
|
|
332
|
+
extensions?: RegExp;
|
|
333
|
+
/** 目录递归深度上限,默认 20。 */
|
|
334
|
+
maxDepth?: number;
|
|
335
|
+
}
|
|
336
|
+
/**
|
|
337
|
+
* 递归收集 root 下匹配 `extensions` 的文件里的 `@tag` 名,写入 `out`。
|
|
338
|
+
*
|
|
339
|
+
* 读失败的文件直接跳过:注册表是 best-effort 的,它只会**放宽**校验,
|
|
340
|
+
* 不该让一次权限错误打断构建。`node_modules` 等目录不参与扫描。
|
|
341
|
+
*/
|
|
342
|
+
declare function scanKnownTags(root: string, out: Set<string>, options?: ScanKnownTagsOptions): void;
|
|
264
343
|
//#endregion
|
|
265
|
-
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, isCompelemSource };
|
|
344
|
+
export { type CollectedDiagnostics, type CompileResult, type CompiledStatic, type CompilerOptions, type ComponentAnalysis, type ConventionMode, DEBUG_DIV, DEFAULT_TAG_EXT, type DepSummary, type ReactiveField, type ReactiveKind, type RenderAnalysis, type ScanKnownTagsOptions, StaticAnalysisError, TAG_RE, type VitePluginOptions, analyzeFile, analyzeRender, assertStaticAnalysis, buildStaticLiteral, collectCompelemImports, collectDiagnostics, compelemCompiler, compileFile, compileSource, defaultInclude, injectInto, inlineTemplateMethods, isCompelemSource, newlineIndex, offsetToLineCol, parse, relativeToRoot, reportConventionDiagnostics, reportDiagnostics, scanKnownTags };
|
|
266
345
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { a as
|
|
1
|
+
import { C as collectCompelemImports, S as analyzeFile, T as parse, _ as DEBUG_DIV, a as scanKnownTags, b as inlineTemplateMethods, c as offsetToLineCol, d as reportDiagnostics, f as compileFile, g as injectInto, h as buildStaticLiteral, i as TAG_RE, l as relativeToRoot, m as defaultInclude, o as collectDiagnostics, p as compileSource, r as DEFAULT_TAG_EXT, s as newlineIndex, t as compelemCompiler, u as reportConventionDiagnostics, v as StaticAnalysisError, w as isCompelemSource, x as analyzeRender, y as assertStaticAnalysis } from "./vite-CLK9td6W.js";
|
|
2
2
|
|
|
3
|
-
export { DEBUG_DIV, StaticAnalysisError, analyzeFile, analyzeRender, assertStaticAnalysis, buildStaticLiteral, collectCompelemImports, compelemCompiler, compileFile, defaultInclude, injectInto, isCompelemSource };
|
|
3
|
+
export { DEBUG_DIV, DEFAULT_TAG_EXT, StaticAnalysisError, TAG_RE, analyzeFile, analyzeRender, assertStaticAnalysis, buildStaticLiteral, collectCompelemImports, collectDiagnostics, compelemCompiler, compileFile, compileSource, defaultInclude, injectInto, inlineTemplateMethods, isCompelemSource, newlineIndex, offsetToLineCol, parse, relativeToRoot, reportConventionDiagnostics, reportDiagnostics, scanKnownTags };
|