@mbler/mcx-core 0.0.3-dev.202602291200 → 0.0.4-beta

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.
Files changed (30) hide show
  1. package/dist/index.d.ts +181 -108
  2. package/dist/index.js +715 -1716
  3. package/dist/index.js.map +1 -1
  4. package/dist/types/compile-mcx/compiler/index.d.ts +2 -2
  5. package/dist/types/compile-mcx/compiler/main.d.ts +2 -1
  6. package/dist/types/compile-mcx/index.d.ts +1 -0
  7. package/dist/types/compile-mcx/types.d.ts +4 -2
  8. package/dist/types/index.d.ts +4 -13
  9. package/dist/types/mcx-component/index.d.ts +2 -0
  10. package/dist/types/{compile-component → mcx-component}/lib.d.ts +0 -3
  11. package/dist/types/transforms/config.d.ts +1 -0
  12. package/dist/types/transforms/file_id.d.ts +1 -0
  13. package/dist/types/transforms/index.d.ts +3 -3
  14. package/dist/types/transforms/main.d.ts +2 -0
  15. package/dist/types/transforms/utils.d.ts +20 -5
  16. package/dist/types/transforms/x-comp/index.d.ts +3 -0
  17. package/dist/types/transforms/x-comp/x-app.d.ts +2 -0
  18. package/dist/types/transforms/x-comp/x-event.d.ts +2 -0
  19. package/dist/types/transforms/x-comp/x-ui.d.ts +2 -0
  20. package/dist/types/tsc/index.d.ts +1 -0
  21. package/dist/types/tsc/volar/index.d.ts +1 -0
  22. package/dist/types/tsc/volar/plugins/index.d.ts +1 -0
  23. package/dist/types/tsc/volar/plugins/mcx-file.d.ts +33 -0
  24. package/dist/types/types.d.ts +41 -14
  25. package/package.json +15 -11
  26. package/dist/types/compile-component/index.d.ts +0 -4
  27. package/dist/types/compile-mcx/compiler/bundler.d.ts +0 -2
  28. package/dist/types/compile-mcx/compiler/str.d.ts +0 -6
  29. /package/dist/types/{compile-component → mcx-component}/types.d.ts +0 -0
  30. /package/dist/types/{compile-component → mcx-component}/utils.d.ts +0 -0
package/dist/index.d.ts CHANGED
@@ -1,15 +1,83 @@
1
- import { CompileOpt } from '@mbler/mcx-types';
1
+ import { TransformPluginContext, Plugin } from 'rollup';
2
2
  import * as t from '@babel/types';
3
3
  import { Expression, CallExpression, SpreadElement, ArgumentPlaceholder, ImportDeclaration, ExportNamedDeclaration, ExportAllDeclaration, ExportDefaultDeclaration } from '@babel/types';
4
- import { TransformPluginContext } from 'rollup';
4
+ import { CompileOpt } from '@mbler/mcx-types';
5
+ import { VirtualCode, CodeMapping, LanguagePlugin } from '@volar/language-core';
6
+ import * as ts from 'typescript';
7
+ import { URI } from 'vscode-uri';
8
+
9
+ interface callList {
10
+ source: Expression;
11
+ set: (callEXp: CallExpression) => boolean;
12
+ arguments: Array<SpreadElement | Expression | ArgumentPlaceholder>;
13
+ remove: () => void;
14
+ }
15
+ interface ImportListImport {
16
+ isAll: boolean;
17
+ import?: string | undefined;
18
+ as: string;
19
+ }
20
+ interface ImportList {
21
+ source: string;
22
+ imported: ImportListImport[];
23
+ raw?: ImportDeclaration;
24
+ }
25
+ interface BuildCache {
26
+ call: callList[];
27
+ import: ImportList[];
28
+ export: Array<ExportNamedDeclaration | ExportAllDeclaration | ExportDefaultDeclaration>;
29
+ }
30
+ declare const _MCXstructureLocComponentTypes: {
31
+ readonly items: "item";
32
+ readonly blocks: "block";
33
+ readonly entities: "entity";
34
+ };
35
+ type MCXstructureLocComponentType = typeof _MCXstructureLocComponentTypes[keyof typeof _MCXstructureLocComponentTypes];
36
+ interface MCXstructureLoc {
37
+ script: string;
38
+ Event: {
39
+ on: "after" | "before";
40
+ subscribe: Record<string, string>;
41
+ loc: {
42
+ line: number;
43
+ column: number;
44
+ };
45
+ isLoad: boolean;
46
+ };
47
+ Component: Record<string, {
48
+ type: MCXstructureLocComponentType;
49
+ useExpore: string;
50
+ loc: {
51
+ line: number;
52
+ column: number;
53
+ };
54
+ }>;
55
+ UI: ParsedTagNode | null;
56
+ }
57
+
58
+ declare class JsCompileData {
59
+ node: t.Program;
60
+ BuildCache: BuildCache;
61
+ File: string;
62
+ isFile: boolean;
63
+ constructor(node: t.Program, BuildCache?: BuildCache);
64
+ setFilePath(dir: string): void;
65
+ }
66
+ declare class MCXCompileData {
67
+ raw: ParsedTagNode[];
68
+ JSIR: JsCompileData;
69
+ strLoc: MCXstructureLoc;
70
+ File: string;
71
+ isFile: boolean;
72
+ constructor(raw: ParsedTagNode[], JSIR: JsCompileData, strLoc: MCXstructureLoc);
73
+ setFilePath(dir: string): void;
74
+ }
5
75
 
6
76
  interface BaseToken {
7
77
  data: string;
8
78
  type: TokenType;
9
- startIndex?: number;
10
- endIndex?: number;
11
- startLine?: number;
12
- loc?: MCXLoc;
79
+ start: MCXPosition;
80
+ end: MCXPosition;
13
81
  }
14
82
  interface TagToken extends BaseToken {
15
83
  type: 'Tag';
@@ -22,15 +90,14 @@ interface ContentToken extends BaseToken {
22
90
  }
23
91
  type Token = TagToken | TagEndToken | ContentToken;
24
92
  type AttributeMap = Record<string, string | boolean>;
93
+ /** 统一的位置信息结构 */
94
+ interface MCXPosition {
95
+ line: number;
96
+ column: number;
97
+ }
25
98
  interface MCXLoc {
26
- start: {
27
- line: number;
28
- index: number;
29
- };
30
- end: {
31
- line: number;
32
- index: number;
33
- };
99
+ start: MCXPosition;
100
+ end: MCXPosition;
34
101
  }
35
102
  interface ParsedTagNode {
36
103
  start: TagToken;
@@ -39,6 +106,7 @@ interface ParsedTagNode {
39
106
  content: (ParsedTagContentNode | ParsedTagNode)[];
40
107
  end: TagEndToken | null;
41
108
  loc: MCXLoc;
109
+ type: "TagNode";
42
110
  }
43
111
  interface ParsedTagContentNode {
44
112
  data: string;
@@ -61,13 +129,40 @@ interface ParseReadFileOpt {
61
129
  want: 'string' | 'object';
62
130
  }
63
131
  type ReadFileOpt = Partial<ParseReadFileOpt>;
64
- type mcxType = "component" | "event" | "app";
132
+ type mcxType = "component" | "event" | "app" | "ui";
133
+
134
+ interface transformCtx {
135
+ rollupContext: TransformPluginContext;
136
+ compiledCode: MCXCompileData;
137
+ cache: Map<string, MCXCompileData>;
138
+ currentId: string;
139
+ scriptTag: ParsedTagNode;
140
+ currentAST: t.Program;
141
+ mainFn: {
142
+ param: t.FunctionParameter[];
143
+ body: t.Statement[];
144
+ };
145
+ impAST: t.ImportDeclaration[];
146
+ opt: CompileOpt;
147
+ }
148
+ interface transformParseCtx {
149
+ prop: t.ObjectProperty[];
150
+ impBody: t.ImportDeclaration[];
151
+ mainFn: t.Statement[];
152
+ ctx: transformCtx;
153
+ app: ((data: t.ObjectProperty[]) => void) & {
154
+ prototype: {
155
+ enable: t.ObjectProperty[] | null;
156
+ };
157
+ };
158
+ }
65
159
 
66
160
  type types_AttributeMap = AttributeMap;
67
161
  type types_BaseToken = BaseToken;
68
162
  type types_ContentToken = ContentToken;
69
163
  type types_JsType = JsType;
70
164
  type types_MCXLoc = MCXLoc;
165
+ type types_MCXPosition = MCXPosition;
71
166
  type types_ParseReadFileOpt = ParseReadFileOpt;
72
167
  type types_ParsedTagContentNode = ParsedTagContentNode;
73
168
  type types_ParsedTagNode = ParsedTagNode;
@@ -80,12 +175,12 @@ type types_Token = Token;
80
175
  type types_TokenType = TokenType;
81
176
  type types_TypeVerifyBody = TypeVerifyBody;
82
177
  type types_mcxType = mcxType;
178
+ type types_transformCtx = transformCtx;
179
+ type types_transformParseCtx = transformParseCtx;
83
180
  declare namespace types {
84
- export type { types_AttributeMap as AttributeMap, types_BaseToken as BaseToken, types_ContentToken as ContentToken, types_JsType as JsType, types_MCXLoc as MCXLoc, types_ParseReadFileOpt as ParseReadFileOpt, types_ParsedTagContentNode as ParsedTagContentNode, types_ParsedTagNode as ParsedTagNode, types_PropNode as PropNode, types_PropValue as PropValue, types_ReadFileOpt as ReadFileOpt, types_TagEndToken as TagEndToken, types_TagToken as TagToken, types_Token as Token, types_TokenType as TokenType, types_TypeVerifyBody as TypeVerifyBody, types_mcxType as mcxType };
181
+ export type { types_AttributeMap as AttributeMap, types_BaseToken as BaseToken, types_ContentToken as ContentToken, types_JsType as JsType, types_MCXLoc as MCXLoc, types_MCXPosition as MCXPosition, types_ParseReadFileOpt as ParseReadFileOpt, types_ParsedTagContentNode as ParsedTagContentNode, types_ParsedTagNode as ParsedTagNode, types_PropNode as PropNode, types_PropValue as PropValue, types_ReadFileOpt as ReadFileOpt, types_TagEndToken as TagEndToken, types_TagToken as TagToken, types_Token as Token, types_TokenType as TokenType, types_TypeVerifyBody as TypeVerifyBody, types_mcxType as mcxType, types_transformCtx as transformCtx, types_transformParseCtx as transformParseCtx };
85
182
  }
86
183
 
87
- declare function PropParser(code: string): PropNode[];
88
-
89
184
  declare class McxAst {
90
185
  private text;
91
186
  constructor(text: string);
@@ -100,58 +195,14 @@ declare class McxAst {
100
195
  static generateCode(node: ParsedTagNode): string;
101
196
  }
102
197
 
103
- declare const _default$1: {
198
+ declare function PropParser(code: string): PropNode[];
199
+
200
+ declare const _default: {
104
201
  tag: typeof McxAst;
105
202
  prop: typeof PropParser;
106
203
  };
107
204
 
108
- interface callList {
109
- source: Expression;
110
- set: (callEXp: CallExpression) => boolean;
111
- arguments: Array<SpreadElement | Expression | ArgumentPlaceholder>;
112
- remove: () => void;
113
- }
114
- interface ImportListImport {
115
- isAll: boolean;
116
- import?: string | undefined;
117
- as: string;
118
- }
119
- interface ImportList {
120
- source: string;
121
- imported: ImportListImport[];
122
- raw?: ImportDeclaration;
123
- }
124
- interface BuildCache {
125
- call: callList[];
126
- import: ImportList[];
127
- export: Array<ExportNamedDeclaration | ExportAllDeclaration | ExportDefaultDeclaration>;
128
- }
129
- declare const _MCXstructureLocComponentTypes: {
130
- readonly items: "item";
131
- readonly blocks: "block";
132
- readonly entities: "entity";
133
- };
134
- type MCXstructureLocComponentType = typeof _MCXstructureLocComponentTypes[keyof typeof _MCXstructureLocComponentTypes];
135
- interface MCXstructureLoc {
136
- script: string;
137
- Event: {
138
- on: "after" | "before";
139
- subscribe: Record<string, string>;
140
- loc: {
141
- line: number;
142
- pos: number;
143
- };
144
- isLoad: boolean;
145
- };
146
- Component: Record<string, {
147
- type: MCXstructureLocComponentType;
148
- useExpore: string;
149
- loc: {
150
- line: number;
151
- pos: number;
152
- };
153
- }>;
154
- }
205
+ declare function mcxPlugn(opt: CompileOpt): Plugin;
155
206
 
156
207
  declare function CompileMcxDir(BuildOpt: CompileOpt): Promise<void>;
157
208
 
@@ -174,32 +225,14 @@ declare class McxUtlis {
174
225
  static AbsoluteJoin(baseDir: string, inputPath: string): string;
175
226
  }
176
227
 
177
- declare class JsCompileData {
178
- node: t.Program;
179
- BuildCache: BuildCache;
180
- File: string;
181
- isFile: boolean;
182
- constructor(node: t.Program, BuildCache?: BuildCache);
183
- setFilePath(dir: string): void;
184
- }
185
- declare class MCXCompileData {
186
- raw: ParsedTagNode[];
187
- JSIR: JsCompileData;
188
- strLoc: MCXstructureLoc;
189
- File: string;
190
- isFile: boolean;
191
- constructor(raw: ParsedTagNode[], JSIR: JsCompileData, strLoc: MCXstructureLoc);
192
- setFilePath(dir: string): void;
193
- }
194
-
195
228
  declare class CompileError extends Error {
196
229
  loc: {
197
230
  line: number;
198
- pos: number;
231
+ column: number;
199
232
  };
200
233
  constructor(message: string, loc: {
201
234
  line: number;
202
- pos: number;
235
+ column: number;
203
236
  });
204
237
  }
205
238
  type Context = Record<string, t.Expression | {
@@ -224,29 +257,69 @@ declare class CompileJS {
224
257
  declare function compileJSFn(code: string): JsCompileData;
225
258
  declare function compileMCXFn(mcxCode: string): MCXCompileData;
226
259
 
227
- type Compiler_CompileError = CompileError;
228
- declare const Compiler_CompileError: typeof CompileError;
229
- type Compiler_CompileJS = CompileJS;
230
- declare const Compiler_CompileJS: typeof CompileJS;
231
- type Compiler_Context = Context;
232
- declare const Compiler_compileJSFn: typeof compileJSFn;
233
- declare const Compiler_compileMCXFn: typeof compileMCXFn;
234
- declare namespace Compiler {
235
- export { Compiler_CompileError as CompileError, Compiler_CompileJS as CompileJS, Compiler_compileJSFn as compileJSFn, Compiler_compileMCXFn as compileMCXFn };
236
- export type { Compiler_Context as Context };
260
+ type index$2_CompileError = CompileError;
261
+ declare const index$2_CompileError: typeof CompileError;
262
+ type index$2_CompileJS = CompileJS;
263
+ declare const index$2_CompileJS: typeof CompileJS;
264
+ type index$2_Context = Context;
265
+ declare const index$2_compileJSFn: typeof compileJSFn;
266
+ declare const index$2_compileMCXFn: typeof compileMCXFn;
267
+ declare namespace index$2 {
268
+ export { index$2_CompileError as CompileError, index$2_CompileJS as CompileJS, index$2_compileJSFn as compileJSFn, index$2_compileMCXFn as compileMCXFn };
269
+ export type { index$2_Context as Context };
237
270
  }
238
271
 
239
- declare function transform(compileData: MCXCompileData, cache: Map<string, MCXCompileData>, id: string, context: TransformPluginContext, opt: CompileOpt): Promise<string>;
272
+ declare function compileComponent(compiledCode: MCXCompileData, project: string): Promise<void>;
240
273
 
241
- declare const _default: {
242
- pulgn: typeof CompileMcxDir;
243
- AST: {
244
- tag: typeof McxAst;
245
- prop: typeof PropParser;
246
- };
247
- Compiler: typeof Compiler;
248
- utils: typeof McxUtlis;
249
- transform: typeof transform;
250
- };
274
+ declare const index$1_compileComponent: typeof compileComponent;
275
+ declare namespace index$1 {
276
+ export {
277
+ index$1_compileComponent as compileComponent,
278
+ };
279
+ }
280
+
281
+ declare function transform(code: MCXCompileData, cache: Map<string, MCXCompileData>, id: string, context: TransformPluginContext, opt: CompileOpt): Promise<string>;
282
+
283
+ /**
284
+ * MCX Volar TSC 插件
285
+ * 为 MCX 文件提供 TypeScript 智能感知支持
286
+ */
287
+ declare const mcxVolarTscPlugin: LanguagePlugin<URI>;
288
+ /**
289
+ * MCX 虚拟代码
290
+ * 用于在 Volar 中表示 MCX 文件的内容
291
+ */
292
+ declare class MCXVirtualCode implements VirtualCode {
293
+ snapshot: ts.IScriptSnapshot;
294
+ id: string;
295
+ languageId: string;
296
+ mappings: CodeMapping[];
297
+ embeddedCodes: VirtualCode[];
298
+ constructor(snapshot: ts.IScriptSnapshot, id?: string);
299
+ /**
300
+ * 从 MCX 文件中提取 script 标签内容
301
+ */
302
+ private extractScriptContent;
303
+ /**
304
+ * 计算 script 内容在源文件中的起始偏移量
305
+ */
306
+ private calculateScriptOffset;
307
+ }
308
+ /**
309
+ * 创建 MCX 虚拟代码实例
310
+ */
311
+ declare function createMCXVirtualCode(snapshot: ts.IScriptSnapshot, id?: string): VirtualCode;
312
+
313
+ type index_MCXVirtualCode = MCXVirtualCode;
314
+ declare const index_MCXVirtualCode: typeof MCXVirtualCode;
315
+ declare const index_createMCXVirtualCode: typeof createMCXVirtualCode;
316
+ declare const index_mcxVolarTscPlugin: typeof mcxVolarTscPlugin;
317
+ declare namespace index {
318
+ export {
319
+ index_MCXVirtualCode as MCXVirtualCode,
320
+ index_createMCXVirtualCode as createMCXVirtualCode,
321
+ index_mcxVolarTscPlugin as mcxVolarTscPlugin,
322
+ };
323
+ }
251
324
 
252
- export { _default$1 as AST, Compiler, types as PUBTYPE, _default as default, transform, McxUtlis as utils };
325
+ export { _default as AST, index$2 as Compiler, types as PUBTYPE, index as TSC, CompileMcxDir as compile, index$1 as compile_component, mcxPlugn as plugin, transform, McxUtlis as utils };