@mbler/mcx-core 0.0.3-dev.20260229 → 0.0.3
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/dist/index.d.ts +185 -108
- package/dist/index.js +728 -1714
- package/dist/index.js.map +1 -1
- package/dist/types/compile-mcx/compiler/index.d.ts +2 -2
- package/dist/types/compile-mcx/compiler/main.d.ts +2 -1
- package/dist/types/compile-mcx/index.d.ts +1 -0
- package/dist/types/compile-mcx/types.d.ts +4 -2
- package/dist/types/index.d.ts +4 -13
- package/dist/types/mcx-component/index.d.ts +2 -0
- package/dist/types/{compile-component → mcx-component}/lib.d.ts +0 -3
- package/dist/types/transforms/config.d.ts +1 -0
- package/dist/types/transforms/file_id.d.ts +1 -0
- package/dist/types/transforms/index.d.ts +3 -3
- package/dist/types/transforms/main.d.ts +2 -0
- package/dist/types/transforms/utils.d.ts +20 -5
- package/dist/types/transforms/x-comp/index.d.ts +3 -0
- package/dist/types/transforms/x-comp/x-app.d.ts +2 -0
- package/dist/types/transforms/x-comp/x-event.d.ts +2 -0
- package/dist/types/transforms/x-comp/x-ui.d.ts +2 -0
- package/dist/types/tsc/index.d.ts +1 -0
- package/dist/types/tsc/volar/index.d.ts +1 -0
- package/dist/types/tsc/volar/plugins/index.d.ts +1 -0
- package/dist/types/tsc/volar/plugins/mcx-file.d.ts +37 -0
- package/dist/types/types.d.ts +41 -14
- package/package.json +20 -16
- package/dist/types/compile-component/index.d.ts +0 -4
- package/dist/types/compile-mcx/compiler/bundler.d.ts +0 -2
- package/dist/types/compile-mcx/compiler/str.d.ts +0 -6
- /package/dist/types/{compile-component → mcx-component}/types.d.ts +0 -0
- /package/dist/types/{compile-component → mcx-component}/utils.d.ts +0 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function generateFileId(): string;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
+
import { TransformPluginContext } from "rollup";
|
|
1
2
|
import { MCXCompileData } from "../compile-mcx/compiler/compileData";
|
|
2
|
-
import { CompileOpt } from "
|
|
3
|
-
|
|
4
|
-
export declare function transform(compileData: MCXCompileData, cache: Map<string, MCXCompileData>, id: string, context: TransformPluginContext, opt: CompileOpt): Promise<string>;
|
|
3
|
+
import { CompileOpt } from "@mbler/mcx-types";
|
|
4
|
+
export declare function transform(code: MCXCompileData, cache: Map<string, MCXCompileData>, id: string, context: TransformPluginContext, opt: CompileOpt): Promise<string>;
|
|
@@ -1,7 +1,22 @@
|
|
|
1
1
|
import * as t from "@babel/types";
|
|
2
2
|
import { JsCompileData } from "../compile-mcx/compiler/compileData";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
declare function
|
|
6
|
-
declare function
|
|
7
|
-
|
|
3
|
+
import { ParsedTagNode, transformCtx } from "../types";
|
|
4
|
+
declare function extrectVarDefIdList(express: t.LVal | t.VoidPattern): string[];
|
|
5
|
+
declare function extractIdList(expression: t.Declaration): string[];
|
|
6
|
+
declare function generateMain(code: JsCompileData): [t.Statement[], t.ImportDeclaration[]];
|
|
7
|
+
declare function generateEventConfig(eventTag: ParsedTagNode, ctx: transformCtx, impBody: t.ImportDeclaration[]): Promise<t.ObjectExpression>;
|
|
8
|
+
/**
|
|
9
|
+
* record enable
|
|
10
|
+
* @returns {(): void} - only call one
|
|
11
|
+
*/
|
|
12
|
+
declare function _enable(): (() => void) & {
|
|
13
|
+
prototype: {
|
|
14
|
+
enable: boolean;
|
|
15
|
+
};
|
|
16
|
+
};
|
|
17
|
+
declare function _enableWithData<T extends any>(): ((data: T) => void) & {
|
|
18
|
+
prototype: {
|
|
19
|
+
enable: T | null;
|
|
20
|
+
};
|
|
21
|
+
};
|
|
22
|
+
export { extractIdList, extrectVarDefIdList, generateEventConfig, _enable, generateMain, _enableWithData };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './volar';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { mcxVolarTscPlugin, MCXVirtualCode, createMCXVirtualCode } from './plugins';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { mcxVolarTscPlugin, MCXVirtualCode, createMCXVirtualCode } from './mcx-file';
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { CodeMapping, LanguagePlugin, VirtualCode } from '@volar/language-core';
|
|
2
|
+
import type * as ts from 'typescript';
|
|
3
|
+
import { URI } from 'vscode-uri';
|
|
4
|
+
/**
|
|
5
|
+
* MCX Volar TSC 插件
|
|
6
|
+
* 为 MCX 文件提供 TypeScript 智能感知支持
|
|
7
|
+
*/
|
|
8
|
+
declare const mcxVolarTscPlugin: LanguagePlugin<URI>;
|
|
9
|
+
/**
|
|
10
|
+
* MCX 虚拟代码
|
|
11
|
+
* 用于在 Volar 中表示 MCX 文件的内容
|
|
12
|
+
*/
|
|
13
|
+
declare class MCXVirtualCode implements VirtualCode {
|
|
14
|
+
snapshot: ts.IScriptSnapshot;
|
|
15
|
+
id: string;
|
|
16
|
+
languageId: string;
|
|
17
|
+
mappings: CodeMapping[];
|
|
18
|
+
embeddedCodes: VirtualCode[];
|
|
19
|
+
constructor(snapshot: ts.IScriptSnapshot, id?: string);
|
|
20
|
+
/**
|
|
21
|
+
* 从 MCX 文件中提取 script 标签内容
|
|
22
|
+
*/
|
|
23
|
+
private extractScriptContent;
|
|
24
|
+
/**
|
|
25
|
+
* 提取标签内容
|
|
26
|
+
*/
|
|
27
|
+
private extractContent;
|
|
28
|
+
/**
|
|
29
|
+
* 查找 script 标签在源文件中的起始位置
|
|
30
|
+
*/
|
|
31
|
+
private findScriptStart;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* 创建 MCX 虚拟代码实例
|
|
35
|
+
*/
|
|
36
|
+
export declare function createMCXVirtualCode(snapshot: ts.IScriptSnapshot, id?: string): VirtualCode;
|
|
37
|
+
export { mcxVolarTscPlugin, MCXVirtualCode };
|
package/dist/types/types.d.ts
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
|
+
import { TransformPluginContext } from "rollup";
|
|
2
|
+
import type { MCXCompileData } from "./compile-mcx/compiler/compileData";
|
|
3
|
+
import { CompileOpt } from "@mbler/mcx-types";
|
|
4
|
+
import * as t from "@babel/types";
|
|
1
5
|
interface BaseToken {
|
|
2
6
|
data: string;
|
|
3
7
|
type: TokenType;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
startLine?: number;
|
|
7
|
-
loc?: MCXLoc;
|
|
8
|
+
start: MCXPosition;
|
|
9
|
+
end: MCXPosition;
|
|
8
10
|
}
|
|
9
11
|
interface TagToken extends BaseToken {
|
|
10
12
|
type: 'Tag';
|
|
@@ -17,15 +19,14 @@ interface ContentToken extends BaseToken {
|
|
|
17
19
|
}
|
|
18
20
|
type Token = TagToken | TagEndToken | ContentToken;
|
|
19
21
|
type AttributeMap = Record<string, string | boolean>;
|
|
22
|
+
/** 统一的位置信息结构 */
|
|
23
|
+
interface MCXPosition {
|
|
24
|
+
line: number;
|
|
25
|
+
column: number;
|
|
26
|
+
}
|
|
20
27
|
interface MCXLoc {
|
|
21
|
-
start:
|
|
22
|
-
|
|
23
|
-
index: number;
|
|
24
|
-
};
|
|
25
|
-
end: {
|
|
26
|
-
line: number;
|
|
27
|
-
index: number;
|
|
28
|
-
};
|
|
28
|
+
start: MCXPosition;
|
|
29
|
+
end: MCXPosition;
|
|
29
30
|
}
|
|
30
31
|
interface ParsedTagNode {
|
|
31
32
|
start: TagToken;
|
|
@@ -34,6 +35,7 @@ interface ParsedTagNode {
|
|
|
34
35
|
content: (ParsedTagContentNode | ParsedTagNode)[];
|
|
35
36
|
end: TagEndToken | null;
|
|
36
37
|
loc: MCXLoc;
|
|
38
|
+
type: "TagNode";
|
|
37
39
|
}
|
|
38
40
|
interface ParsedTagContentNode {
|
|
39
41
|
data: string;
|
|
@@ -56,5 +58,30 @@ export interface ParseReadFileOpt {
|
|
|
56
58
|
want: 'string' | 'object';
|
|
57
59
|
}
|
|
58
60
|
export type ReadFileOpt = Partial<ParseReadFileOpt>;
|
|
59
|
-
export type mcxType = "component" | "event" | "app";
|
|
60
|
-
export type { Token, ContentToken, TagEndToken, TagToken, BaseToken, AttributeMap, PropValue, TokenType, ParsedTagContentNode, TypeVerifyBody, JsType, PropNode, ParsedTagNode, MCXLoc };
|
|
61
|
+
export type mcxType = "component" | "event" | "app" | "ui";
|
|
62
|
+
export type { Token, ContentToken, TagEndToken, TagToken, BaseToken, AttributeMap, PropValue, TokenType, ParsedTagContentNode, TypeVerifyBody, JsType, PropNode, ParsedTagNode, MCXLoc, MCXPosition };
|
|
63
|
+
export interface transformCtx {
|
|
64
|
+
rollupContext: TransformPluginContext;
|
|
65
|
+
compiledCode: MCXCompileData;
|
|
66
|
+
cache: Map<string, MCXCompileData>;
|
|
67
|
+
currentId: string;
|
|
68
|
+
scriptTag: ParsedTagNode;
|
|
69
|
+
currentAST: t.Program;
|
|
70
|
+
mainFn: {
|
|
71
|
+
param: t.FunctionParameter[];
|
|
72
|
+
body: t.Statement[];
|
|
73
|
+
};
|
|
74
|
+
impAST: t.ImportDeclaration[];
|
|
75
|
+
opt: CompileOpt;
|
|
76
|
+
}
|
|
77
|
+
export interface transformParseCtx {
|
|
78
|
+
prop: t.ObjectProperty[];
|
|
79
|
+
impBody: t.ImportDeclaration[];
|
|
80
|
+
mainFn: t.Statement[];
|
|
81
|
+
ctx: transformCtx;
|
|
82
|
+
app: ((data: t.ObjectProperty[]) => void) & {
|
|
83
|
+
prototype: {
|
|
84
|
+
enable: t.ObjectProperty[] | null;
|
|
85
|
+
};
|
|
86
|
+
};
|
|
87
|
+
}
|
package/package.json
CHANGED
|
@@ -1,12 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mbler/mcx-core",
|
|
3
|
-
"version": "0.0.3
|
|
3
|
+
"version": "0.0.3",
|
|
4
4
|
"description": "a DSL compiler of mcx",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
|
-
"scripts": {
|
|
7
|
-
"test": "cd __test__ && npm run test",
|
|
8
|
-
"build": "rollup -c"
|
|
9
|
-
},
|
|
10
6
|
"keywords": [
|
|
11
7
|
"compiler",
|
|
12
8
|
"minecraft",
|
|
@@ -16,12 +12,9 @@
|
|
|
16
12
|
"@babel/generator": "7.28.5",
|
|
17
13
|
"@babel/parser": "7.28.5",
|
|
18
14
|
"@babel/types": "7.28.6",
|
|
19
|
-
"@
|
|
20
|
-
"
|
|
21
|
-
"
|
|
22
|
-
"@rollup/plugin-typescript": "^12.3.0",
|
|
23
|
-
"magic-string": "^0.30.21",
|
|
24
|
-
"rollup": "^4.57.1"
|
|
15
|
+
"@volar/language-core": "^2.4.28",
|
|
16
|
+
"magic-string": "0.30.21",
|
|
17
|
+
"vscode-uri": "^3.1.0"
|
|
25
18
|
},
|
|
26
19
|
"module": "commjs",
|
|
27
20
|
"files": [
|
|
@@ -38,9 +31,20 @@
|
|
|
38
31
|
"license": "MIT",
|
|
39
32
|
"devDependencies": {
|
|
40
33
|
"@mbler/mcx-types": "latest",
|
|
41
|
-
"@
|
|
42
|
-
"@
|
|
43
|
-
"rollup
|
|
44
|
-
"
|
|
34
|
+
"@rollup/plugin-commonjs": "29.0.1",
|
|
35
|
+
"@rollup/plugin-json": "6.1.0",
|
|
36
|
+
"@rollup/plugin-node-resolve": "16.0.3",
|
|
37
|
+
"@rollup/plugin-typescript": "12.3.0",
|
|
38
|
+
"@types/babel__generator": "7.27.0",
|
|
39
|
+
"@types/babel__traverse": "7.28.0",
|
|
40
|
+
"@types/node": "25.3.5",
|
|
41
|
+
"rollup": "4.59.0",
|
|
42
|
+
"rollup-plugin-dts": "6.3.0",
|
|
43
|
+
"tslib": "2.8.1",
|
|
44
|
+
"typescript": "5.9.3"
|
|
45
|
+
},
|
|
46
|
+
"scripts": {
|
|
47
|
+
"test": "cd __test__ && npm run test",
|
|
48
|
+
"build": "rollup -c"
|
|
45
49
|
}
|
|
46
|
-
}
|
|
50
|
+
}
|
|
File without changes
|
|
File without changes
|