@mbler/mcx-core 0.0.3-alpha.r20260312 → 0.0.3-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.
- package/dist/types/ast/index.d.ts +7 -0
- package/dist/types/ast/prop.d.ts +8 -0
- package/dist/types/ast/tag.d.ts +26 -0
- package/dist/types/compile-mcx/compile.d.ts +5 -0
- package/dist/types/compile-mcx/compiler/compileData.d.ts +20 -0
- package/dist/types/compile-mcx/compiler/index.d.ts +33 -0
- package/dist/types/compile-mcx/compiler/main.d.ts +4 -0
- package/dist/types/compile-mcx/compiler/utils.d.ts +11 -0
- package/dist/types/compile-mcx/index.d.ts +3 -0
- package/dist/types/compile-mcx/types.d.ts +52 -0
- package/dist/types/compile-mcx/utils.node.d.ts +14 -0
- package/dist/types/index.d.ts +8 -0
- package/dist/types/mcx-component/index.d.ts +2 -0
- package/dist/types/mcx-component/lib.d.ts +29 -0
- package/dist/types/mcx-component/types.d.ts +44 -0
- package/dist/types/mcx-component/utils.d.ts +2 -0
- package/dist/types/transforms/config.d.ts +8 -0
- package/dist/types/transforms/index.d.ts +4 -0
- package/dist/types/transforms/main.d.ts +2 -0
- package/dist/types/transforms/utils.d.ts +22 -0
- 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/types.d.ts +90 -0
- package/dist/types/utils.d.ts +19 -0
- package/package.json +2 -3
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { PropNode, PropValue } from "../types.js";
|
|
2
|
+
export declare class Lexer {
|
|
3
|
+
private code;
|
|
4
|
+
constructor(code: string);
|
|
5
|
+
tokenize(): IterableIterator<PropNode>;
|
|
6
|
+
HandlerValue(value: string): PropValue;
|
|
7
|
+
}
|
|
8
|
+
export default function PropParser(code: string): PropNode[];
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { BaseToken, TagToken, TagEndToken, ContentToken, Token, ParsedTagNode, AttributeMap, ParsedTagContentNode, TokenType } from "./../types.js";
|
|
2
|
+
export default class McxAst {
|
|
3
|
+
private text;
|
|
4
|
+
constructor(text: string);
|
|
5
|
+
private getAST;
|
|
6
|
+
get data(): ParsedTagNode[];
|
|
7
|
+
parseAST(): ParsedTagNode[];
|
|
8
|
+
/**
|
|
9
|
+
* 生成代码字符串(递归处理 content 数组)
|
|
10
|
+
* @param node 要生成代码的AST节点
|
|
11
|
+
* @returns 生成的代码字符串
|
|
12
|
+
*/
|
|
13
|
+
static generateCode(node: ParsedTagNode): string;
|
|
14
|
+
}
|
|
15
|
+
export declare class MCXUtils {
|
|
16
|
+
static isTagNode(node: unknown): node is ParsedTagNode;
|
|
17
|
+
static isTagContentNode(node: unknown): node is ParsedTagContentNode;
|
|
18
|
+
static isAttributeMap(obj: unknown): obj is AttributeMap;
|
|
19
|
+
static isToken(obj: unknown): obj is Token;
|
|
20
|
+
static isTagToken(obj: unknown): obj is TagToken;
|
|
21
|
+
static isTagEndToken(obj: unknown): obj is TagEndToken;
|
|
22
|
+
static isContentToken(obj: unknown): obj is ContentToken;
|
|
23
|
+
static isBaseToken(obj: unknown): obj is BaseToken;
|
|
24
|
+
static isTokenType(value: unknown): value is TokenType;
|
|
25
|
+
static isParseNode(node: unknown): node is ParsedTagNode[];
|
|
26
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import * as t from "@babel/types";
|
|
2
|
+
import { BuildCache, MCXstructureLoc } from "../types";
|
|
3
|
+
import { ParsedTagNode } from "../../types";
|
|
4
|
+
export declare class JsCompileData {
|
|
5
|
+
node: t.Program;
|
|
6
|
+
BuildCache: BuildCache;
|
|
7
|
+
File: string;
|
|
8
|
+
isFile: boolean;
|
|
9
|
+
constructor(node: t.Program, BuildCache?: BuildCache);
|
|
10
|
+
setFilePath(dir: string): void;
|
|
11
|
+
}
|
|
12
|
+
export declare class MCXCompileData {
|
|
13
|
+
raw: ParsedTagNode[];
|
|
14
|
+
JSIR: JsCompileData;
|
|
15
|
+
strLoc: MCXstructureLoc;
|
|
16
|
+
File: string;
|
|
17
|
+
isFile: boolean;
|
|
18
|
+
constructor(raw: ParsedTagNode[], JSIR: JsCompileData, strLoc: MCXstructureLoc);
|
|
19
|
+
setFilePath(dir: string): void;
|
|
20
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import * as t from "@babel/types";
|
|
2
|
+
import * as CompileData from "./compileData";
|
|
3
|
+
export declare class CompileError extends Error {
|
|
4
|
+
loc: {
|
|
5
|
+
line: number;
|
|
6
|
+
column: number;
|
|
7
|
+
};
|
|
8
|
+
constructor(message: string, loc: {
|
|
9
|
+
line: number;
|
|
10
|
+
column: number;
|
|
11
|
+
});
|
|
12
|
+
}
|
|
13
|
+
export type Context = Record<string, t.Expression | {
|
|
14
|
+
status: "wait";
|
|
15
|
+
}>;
|
|
16
|
+
export declare class CompileJS {
|
|
17
|
+
node: t.Program;
|
|
18
|
+
constructor(node: t.Program);
|
|
19
|
+
TopContext: Context;
|
|
20
|
+
private indexTemp;
|
|
21
|
+
private push;
|
|
22
|
+
private takeInnerMost;
|
|
23
|
+
private writeImportKeys;
|
|
24
|
+
private extractIdentifierNames;
|
|
25
|
+
private writeBuildCache;
|
|
26
|
+
private CompileData;
|
|
27
|
+
getCompileData(): CompileData.JsCompileData;
|
|
28
|
+
private conditionalInTempImport;
|
|
29
|
+
private tre;
|
|
30
|
+
run(): void;
|
|
31
|
+
}
|
|
32
|
+
export declare function compileJSFn(code: string): CompileData.JsCompileData;
|
|
33
|
+
export declare function compileMCXFn(mcxCode: string): CompileData.MCXCompileData;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import * as Parser from "@babel/parser";
|
|
2
|
+
import { ImportList } from "../types";
|
|
3
|
+
import * as t from "@babel/types";
|
|
4
|
+
export default class Utils {
|
|
5
|
+
static FileAST(fileDir: string, parserOpt: Parser.ParserOptions): Promise<t.Program>;
|
|
6
|
+
static FileContent(fileDir: string): Promise<string>;
|
|
7
|
+
private static nodeStringValue;
|
|
8
|
+
private static CheckImportNode;
|
|
9
|
+
static CacheToImportNode(ir: ImportList): t.ImportDeclaration;
|
|
10
|
+
static ImportToCache(node: t.ImportDeclaration): ImportList;
|
|
11
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import type { ImportDeclaration, ExportAllDeclaration, ExportDefaultDeclaration, ExportNamedDeclaration, Expression, SpreadElement, ArgumentPlaceholder, CallExpression } from "@babel/types";
|
|
2
|
+
import { CompileOpt } from "@mbler/mcx-types";
|
|
3
|
+
import { ParsedTagNode } from "../types";
|
|
4
|
+
interface callList {
|
|
5
|
+
source: Expression;
|
|
6
|
+
set: (callEXp: CallExpression) => boolean;
|
|
7
|
+
arguments: Array<SpreadElement | Expression | ArgumentPlaceholder>;
|
|
8
|
+
remove: () => void;
|
|
9
|
+
}
|
|
10
|
+
interface ImportListImport {
|
|
11
|
+
isAll: boolean;
|
|
12
|
+
import?: string | undefined;
|
|
13
|
+
as: string;
|
|
14
|
+
}
|
|
15
|
+
interface ImportList {
|
|
16
|
+
source: string;
|
|
17
|
+
imported: ImportListImport[];
|
|
18
|
+
raw?: ImportDeclaration;
|
|
19
|
+
}
|
|
20
|
+
interface BuildCache {
|
|
21
|
+
call: callList[];
|
|
22
|
+
import: ImportList[];
|
|
23
|
+
export: Array<ExportNamedDeclaration | ExportAllDeclaration | ExportDefaultDeclaration>;
|
|
24
|
+
}
|
|
25
|
+
export declare const _MCXstructureLocComponentTypes: {
|
|
26
|
+
readonly items: "item";
|
|
27
|
+
readonly blocks: "block";
|
|
28
|
+
readonly entities: "entity";
|
|
29
|
+
};
|
|
30
|
+
type MCXstructureLocComponentType = typeof _MCXstructureLocComponentTypes[keyof typeof _MCXstructureLocComponentTypes];
|
|
31
|
+
interface MCXstructureLoc {
|
|
32
|
+
script: string;
|
|
33
|
+
Event: {
|
|
34
|
+
on: "after" | "before";
|
|
35
|
+
subscribe: Record<string, string>;
|
|
36
|
+
loc: {
|
|
37
|
+
line: number;
|
|
38
|
+
column: number;
|
|
39
|
+
};
|
|
40
|
+
isLoad: boolean;
|
|
41
|
+
};
|
|
42
|
+
Component: Record<string, {
|
|
43
|
+
type: MCXstructureLocComponentType;
|
|
44
|
+
useExpore: string;
|
|
45
|
+
loc: {
|
|
46
|
+
line: number;
|
|
47
|
+
column: number;
|
|
48
|
+
};
|
|
49
|
+
}>;
|
|
50
|
+
UI: ParsedTagNode | null;
|
|
51
|
+
}
|
|
52
|
+
export type { BuildCache, ImportList, ImportListImport, callList, CompileOpt, MCXstructureLoc, MCXstructureLocComponentType };
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { MemberExpression, Expression } from '@babel/types';
|
|
2
|
+
import { Context } from './compiler';
|
|
3
|
+
export default class NodeUtils {
|
|
4
|
+
static stringArrayToMemberExpression(stringArray: string[]): MemberExpression;
|
|
5
|
+
static memberExpressionToStringArray(memberExpression: MemberExpression, maxLength: number): string[];
|
|
6
|
+
/**
|
|
7
|
+
* 计算表达式的值
|
|
8
|
+
* @param expression Babel AST 表达式节点
|
|
9
|
+
* @param currentContext 当前上下文变量
|
|
10
|
+
* @param topContext 顶层上下文变量
|
|
11
|
+
* @returns 计算结果 (string | number | symbol | object)
|
|
12
|
+
*/
|
|
13
|
+
static evaluateExpression(expression: Expression, currentContext?: Context, topContext?: Context): string | number | symbol | object;
|
|
14
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import AST from "./ast/index.js";
|
|
2
|
+
import compiler, { plugin } from "./compile-mcx/index.js";
|
|
3
|
+
import utils from "./utils.js";
|
|
4
|
+
import * as Compiler from "./compile-mcx/compiler";
|
|
5
|
+
import * as PUBTYPE from "./types.js";
|
|
6
|
+
import * as compile_component from "./mcx-component/index.js";
|
|
7
|
+
import { transform } from "./transforms";
|
|
8
|
+
export { PUBTYPE, compiler as compile, AST, Compiler, utils, transform, compile_component, plugin };
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import * as t from "./types";
|
|
2
|
+
export declare class ItemComponent {
|
|
3
|
+
#private;
|
|
4
|
+
constructor(opt: t.ItemComponentOpt);
|
|
5
|
+
toJSON(): t.ItemJSON;
|
|
6
|
+
/**
|
|
7
|
+
* set name
|
|
8
|
+
* @throws {Error}&
|
|
9
|
+
* @param {string} newValue
|
|
10
|
+
* @returns {void}
|
|
11
|
+
*/
|
|
12
|
+
setName(newValue: string): void;
|
|
13
|
+
setIcon(newValue: string): void;
|
|
14
|
+
/**
|
|
15
|
+
* get name
|
|
16
|
+
* @returns {string} name
|
|
17
|
+
*/
|
|
18
|
+
getName(): string;
|
|
19
|
+
/**
|
|
20
|
+
* set identifier
|
|
21
|
+
* @param {string} newValue
|
|
22
|
+
*/
|
|
23
|
+
setId(newValue: string): void;
|
|
24
|
+
getId(): void;
|
|
25
|
+
}
|
|
26
|
+
declare const _default: {
|
|
27
|
+
Item: typeof ItemComponent;
|
|
28
|
+
};
|
|
29
|
+
export default _default;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
interface ItemComponentOpt {
|
|
2
|
+
id: string;
|
|
3
|
+
name: string;
|
|
4
|
+
format: string;
|
|
5
|
+
components: {
|
|
6
|
+
offHand: boolean;
|
|
7
|
+
damage: number;
|
|
8
|
+
DestroyInCreate: boolean;
|
|
9
|
+
icon: string;
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
type JSONValue<T> = T | {
|
|
13
|
+
value: T;
|
|
14
|
+
};
|
|
15
|
+
type ItemGroupEnum = "minecraft:itemGroup.name.planks" | "minecraft:itemGroup.name.walls" | "minecraft:itemGroup.name.fence" | "minecraft:itemGroup.name.fenceGate" | "minecraft:itemGroup.name.glass" | "minecraft:itemGroup.name.trapdoor" | "minecraft:itemGroup.name.door" | "minecraft:itemGroup.name.stairs" | "minecraft:itemGroup.name.glassPane" | "minecraft:itemGroup.name.slab" | "minecraft:itemGroup.name.stoneBrick" | "minecraft:itemGroup.name.sandstone" | "minecraft:itemGroup.name.copper" | "minecraft:itemGroup.name.wool" | "minecraft:itemGroup.name.woolCarpet" | "minecraft:itemGroup.name.concretePowder" | "minecraft:itemGroup.name.concrete" | "minecraft:itemGroup.name.stainedClay" | "minecraft:itemGroup.name.glazedTerracotta" | "minecraft:itemGroup.name.ore" | "minecraft:itemGroup.name.stone" | "minecraft:itemGroup.name.log" | "minecraft:itemGroup.name.wood" | "minecraft:itemGroup.name.leaves" | "minecraft:itemGroup.name.sapling" | "minecraft:itemGroup.name.seed" | "minecraft:itemGroup.name.crop" | "minecraft:itemGroup.name.grass" | "minecraft:itemGroup.name.coral_decorations" | "minecraft:itemGroup.name.flower" | "minecraft:itemGroup.name.dye" | "minecraft:itemGroup.name.rawFood" | "minecraft:itemGroup.name.mushroom" | "minecraft:itemGroup.name.monsterStoneEgg" | "minecraft:itemGroup.name.mobEgg" | "minecraft:itemGroup.name.coral" | "minecraft:itemGroup.name.sculk" | "minecraft:itemGroup.name.helmet" | "minecraft:itemGroup.name.chestplate" | "minecraft:itemGroup.name.leggings" | "minecraft:itemGroup.name.boots" | "minecraft:itemGroup.name.sword" | "minecraft:itemGroup.name.axe" | "minecraft:itemGroup.name.pickaxe" | "minecraft:itemGroup.name.shovel" | "minecraft:itemGroup.name.hoe" | "minecraft:itemGroup.name.arrow" | "minecraft:itemGroup.name.cookedFood" | "minecraft:itemGroup.name.miscFood" | "minecraft:itemGroup.name.goatHorn" | "minecraft:itemGroup.name.bundles" | "minecraft:itemGroup.name.horseArmor" | "minecraft:itemGroup.name.potion" | "minecraft:itemGroup.name.splashPotion" | "minecraft:itemGroup.name.lingeringPotion" | "minecraft:itemGroup.name.ominousBottle" | "minecraft:itemGroup.name.bed" | "minecraft:itemGroup.name.candles" | "minecraft:itemGroup.name.anvil" | "minecraft:itemGroup.name.chest" | "minecraft:itemGroup.name.shulkerBox" | "minecraft:itemGroup.name.record" | "minecraft:itemGroup.name.sign" | "minecraft:itemGroup.name.hanging_sign" | "minecraft:itemGroup.name.skull" | "minecraft:itemGroup.name.boat" | "minecraft:itemGroup.name.chestboat" | "minecraft:itemGroup.name.rail" | "minecraft:itemGroup.name.minecart" | "minecraft:itemGroup.name.buttons" | "minecraft:itemGroup.name.pressurePlate" | "minecraft:itemGroup.name.banner_pattern" | "minecraft:itemGroup.name.potterySherds" | "minecraft:itemGroup.name.smithing_templates";
|
|
16
|
+
interface ItemJSON {
|
|
17
|
+
format_version: string;
|
|
18
|
+
"minecraft:item": {
|
|
19
|
+
description: {
|
|
20
|
+
identifier: string;
|
|
21
|
+
category?: string;
|
|
22
|
+
menu_category?: {
|
|
23
|
+
category: string;
|
|
24
|
+
group: ItemGroupEnum;
|
|
25
|
+
};
|
|
26
|
+
};
|
|
27
|
+
components: {
|
|
28
|
+
"minecraft:display_name"?: JSONValue<string>;
|
|
29
|
+
"minecraft:allow_off_hand"?: JSONValue<boolean>;
|
|
30
|
+
"minecraft:can_destroy_in_creative"?: JSONValue<boolean>;
|
|
31
|
+
"minecraft:compostable"?: {
|
|
32
|
+
composting_chance: number;
|
|
33
|
+
};
|
|
34
|
+
"minecraft:cooldown"?: {
|
|
35
|
+
category: string;
|
|
36
|
+
duration: number;
|
|
37
|
+
type: "use" | "attack";
|
|
38
|
+
};
|
|
39
|
+
"minecraft:damage"?: JSONValue<number>;
|
|
40
|
+
"minecraft:icon"?: JSONValue<string>;
|
|
41
|
+
};
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
export type { ItemComponentOpt, ItemGroupEnum, ItemJSON };
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { TransformPluginContext } from "rollup";
|
|
2
|
+
import { MCXCompileData } from "../compile-mcx/compiler/compileData";
|
|
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>;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import * as t from "@babel/types";
|
|
2
|
+
import { JsCompileData } from "../compile-mcx/compiler/compileData";
|
|
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,90 @@
|
|
|
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";
|
|
5
|
+
interface BaseToken {
|
|
6
|
+
data: string;
|
|
7
|
+
type: TokenType;
|
|
8
|
+
startIndex?: number;
|
|
9
|
+
endIndex?: number;
|
|
10
|
+
startLine?: number;
|
|
11
|
+
loc?: MCXLoc;
|
|
12
|
+
}
|
|
13
|
+
interface TagToken extends BaseToken {
|
|
14
|
+
type: 'Tag';
|
|
15
|
+
}
|
|
16
|
+
interface TagEndToken extends BaseToken {
|
|
17
|
+
type: 'TagEnd';
|
|
18
|
+
}
|
|
19
|
+
interface ContentToken extends BaseToken {
|
|
20
|
+
type: 'Content';
|
|
21
|
+
}
|
|
22
|
+
type Token = TagToken | TagEndToken | ContentToken;
|
|
23
|
+
type AttributeMap = Record<string, string | boolean>;
|
|
24
|
+
interface MCXLoc {
|
|
25
|
+
start: {
|
|
26
|
+
line: number;
|
|
27
|
+
index: number;
|
|
28
|
+
};
|
|
29
|
+
end: {
|
|
30
|
+
line: number;
|
|
31
|
+
index: number;
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
interface ParsedTagNode {
|
|
35
|
+
start: TagToken;
|
|
36
|
+
name: string;
|
|
37
|
+
arr: AttributeMap;
|
|
38
|
+
content: (ParsedTagContentNode | ParsedTagNode)[];
|
|
39
|
+
end: TagEndToken | null;
|
|
40
|
+
loc: MCXLoc;
|
|
41
|
+
type: "TagNode";
|
|
42
|
+
}
|
|
43
|
+
interface ParsedTagContentNode {
|
|
44
|
+
data: string;
|
|
45
|
+
type: 'TagContent';
|
|
46
|
+
}
|
|
47
|
+
type TokenType = 'Tag' | 'TagEnd' | 'Content';
|
|
48
|
+
type PropValue = number | string | object;
|
|
49
|
+
interface PropNode {
|
|
50
|
+
key: string;
|
|
51
|
+
value: PropValue;
|
|
52
|
+
type: "PropChar" | "PropObject";
|
|
53
|
+
}
|
|
54
|
+
type JsType = "boolean" | "number" | "string" | "object" | "function" | "bigint" | "symbol";
|
|
55
|
+
interface TypeVerifyBody {
|
|
56
|
+
[key: string]: JsType;
|
|
57
|
+
}
|
|
58
|
+
export interface ParseReadFileOpt {
|
|
59
|
+
delay: number;
|
|
60
|
+
maxRetries: number;
|
|
61
|
+
want: 'string' | 'object';
|
|
62
|
+
}
|
|
63
|
+
export type ReadFileOpt = Partial<ParseReadFileOpt>;
|
|
64
|
+
export type mcxType = "component" | "event" | "app" | "ui";
|
|
65
|
+
export type { Token, ContentToken, TagEndToken, TagToken, BaseToken, AttributeMap, PropValue, TokenType, ParsedTagContentNode, TypeVerifyBody, JsType, PropNode, ParsedTagNode, MCXLoc };
|
|
66
|
+
export interface transformCtx {
|
|
67
|
+
rollupContext: TransformPluginContext;
|
|
68
|
+
compiledCode: MCXCompileData;
|
|
69
|
+
cache: Map<string, MCXCompileData>;
|
|
70
|
+
currentId: string;
|
|
71
|
+
scriptTag: ParsedTagNode;
|
|
72
|
+
currentAST: t.Program;
|
|
73
|
+
mainFn: {
|
|
74
|
+
param: t.FunctionParameter[];
|
|
75
|
+
body: t.Statement[];
|
|
76
|
+
};
|
|
77
|
+
impAST: t.ImportDeclaration[];
|
|
78
|
+
opt: CompileOpt;
|
|
79
|
+
}
|
|
80
|
+
export interface transformParseCtx {
|
|
81
|
+
prop: t.ObjectProperty[];
|
|
82
|
+
impBody: t.ImportDeclaration[];
|
|
83
|
+
mainFn: t.Statement[];
|
|
84
|
+
ctx: transformCtx;
|
|
85
|
+
app: ((data: t.ObjectProperty[]) => void) & {
|
|
86
|
+
prototype: {
|
|
87
|
+
enable: t.ObjectProperty[] | null;
|
|
88
|
+
};
|
|
89
|
+
};
|
|
90
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { ReadFileOpt, TypeVerifyBody } from "./types.js";
|
|
2
|
+
export default class McxUtlis {
|
|
3
|
+
/**
|
|
4
|
+
* 检查文件是否存在
|
|
5
|
+
* @param path 文件路径
|
|
6
|
+
* @returns 是否存在
|
|
7
|
+
*/
|
|
8
|
+
static FileExsit(path: string): Promise<boolean>;
|
|
9
|
+
/**
|
|
10
|
+
* 读取文件内容,支持返回 string 或 object,带重试机制
|
|
11
|
+
* @param filePath 文件路径
|
|
12
|
+
* @param opt 配置选项
|
|
13
|
+
* @returns 文件内容(string | object),出错时返回 {}
|
|
14
|
+
*/
|
|
15
|
+
static readFile(filePath: string, opt?: ReadFileOpt): Promise<object | string>;
|
|
16
|
+
static sleep(time: number): Promise<void>;
|
|
17
|
+
static TypeVerify(obj: any, types: TypeVerifyBody): boolean;
|
|
18
|
+
static AbsoluteJoin(baseDir: string, inputPath: string): string;
|
|
19
|
+
}
|
package/package.json
CHANGED
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mbler/mcx-core",
|
|
3
|
-
"version": "0.0.3-
|
|
3
|
+
"version": "0.0.3-beta",
|
|
4
4
|
"description": "a DSL compiler of mcx",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"scripts": {
|
|
7
7
|
"test": "cd __test__ && npm run test",
|
|
8
|
-
"build": "rollup -c"
|
|
9
|
-
"publish": "npm run build"
|
|
8
|
+
"build": "rollup -c"
|
|
10
9
|
},
|
|
11
10
|
"keywords": [
|
|
12
11
|
"compiler",
|