@compelem/compiler 0.30.0-beta.3 → 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 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-BAl4p1jA.js";
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/oxc.d.ts
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,11 @@ 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;
264
276
  //#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 };
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 };
266
278
  //# sourceMappingURL=index.d.ts.map
package/dist/index.js CHANGED
@@ -1,3 +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 assertStaticAnalysis } from "./vite-DwMiG3VM.js";
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, assertStaticAnalysis, buildStaticLiteral, collectCompelemImports, compelemCompiler, compileFile, defaultInclude, injectInto, isCompelemSource };
3
+ export { DEBUG_DIV, StaticAnalysisError, analyzeFile, analyzeRender, assertStaticAnalysis, buildStaticLiteral, collectCompelemImports, compelemCompiler, compileFile, defaultInclude, injectInto, inlineTemplateMethods, isCompelemSource, parse };