@mbler/mcx-core 0.1.1 → 0.1.2

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 (40) hide show
  1. package/dist/chunk-DEq-mXcV.js +15 -0
  2. package/dist/index.d.ts +4861 -5024
  3. package/dist/index.js +6384 -12177
  4. package/dist/index.js.map +1 -1
  5. package/package.json +14 -6
  6. package/dist/types/ast/index.d.ts +0 -7
  7. package/dist/types/ast/prop.d.ts +0 -8
  8. package/dist/types/ast/tag.d.ts +0 -66
  9. package/dist/types/compile-mcx/compiler/compileData.d.ts +0 -20
  10. package/dist/types/compile-mcx/compiler/index.d.ts +0 -36
  11. package/dist/types/compile-mcx/compiler/main.d.ts +0 -6
  12. package/dist/types/compile-mcx/compiler/utils.d.ts +0 -11
  13. package/dist/types/compile-mcx/index.d.ts +0 -1
  14. package/dist/types/compile-mcx/types.d.ts +0 -52
  15. package/dist/types/compile-mcx/utils.node.d.ts +0 -14
  16. package/dist/types/index.d.ts +0 -10
  17. package/dist/types/mcx-component/components/block.d.ts +0 -4
  18. package/dist/types/mcx-component/components/entity.d.ts +0 -1266
  19. package/dist/types/mcx-component/components/item.d.ts +0 -520
  20. package/dist/types/mcx-component/index.d.ts +0 -17
  21. package/dist/types/mcx-component/lib.d.ts +0 -32
  22. package/dist/types/mcx-component/types/AttackCriticalHitChoices.d.ts +0 -3
  23. package/dist/types/mcx-component/types/EnchantableSlot.d.ts +0 -9
  24. package/dist/types/mcx-component/types/ParticleType.d.ts +0 -8
  25. package/dist/types/mcx-component/types/SoundEvent.d.ts +0 -8
  26. package/dist/types/mcx-component/types/StartSoundChoices.d.ts +0 -3
  27. package/dist/types/mcx-component/types.d.ts +0 -3053
  28. package/dist/types/mcx-component/utils.d.ts +0 -2
  29. package/dist/types/mcx-component/vm.d.ts +0 -28
  30. package/dist/types/transforms/config.d.ts +0 -8
  31. package/dist/types/transforms/file_id.d.ts +0 -1
  32. package/dist/types/transforms/index.d.ts +0 -5
  33. package/dist/types/transforms/main.d.ts +0 -2
  34. package/dist/types/transforms/utils.d.ts +0 -22
  35. package/dist/types/transforms/x-comp/index.d.ts +0 -3
  36. package/dist/types/transforms/x-comp/x-app.d.ts +0 -2
  37. package/dist/types/transforms/x-comp/x-event.d.ts +0 -2
  38. package/dist/types/transforms/x-comp/x-ui.d.ts +0 -2
  39. package/dist/types/types.d.ts +0 -100
  40. package/dist/types/utils.d.ts +0 -18
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mbler/mcx-core",
3
- "version": "0.1.1",
3
+ "version": "0.1.2",
4
4
  "description": "a DSL compiler of mcx",
5
5
  "main": "dist/index.js",
6
6
  "keywords": [
@@ -29,12 +29,18 @@
29
29
  "@babel/types": "7.28.6",
30
30
  "@volar/language-core": "^2.4.28",
31
31
  "magic-string": "0.30.21",
32
- "rollup": "4.59.0",
33
- "rolldown": "1.0.0-rc.18",
34
32
  "typescript": "5.9.3",
35
33
  "@mbler/mcx-types": "0.0.4-rc.1"
36
34
  },
37
- "module": "commjs",
35
+ "devDependencies": {
36
+ "rolldown": "1.0.0-rc.18",
37
+ "rolldown-plugin-dts": "0.25.2",
38
+ "rollup": "4.59.0"
39
+ },
40
+ "peerDependencies": {
41
+ "rolldown": "1.0.0-rc.18",
42
+ "rollup": "4.59.0"
43
+ },
38
44
  "files": [
39
45
  "dist",
40
46
  "README.md",
@@ -48,10 +54,12 @@
48
54
  "types": "./dist/index.d.ts",
49
55
  "author": "ruanhor",
50
56
  "license": "MIT",
57
+ "type": "module",
51
58
  "scripts": {
52
59
  "lint": "eslint src --ext .js,.ts",
53
60
  "lint:fix": "eslint src --ext .js,.ts --fix",
54
- "test": "cd __test__ && npm run test",
55
- "build": "rollup -c"
61
+ "test": "vitest run",
62
+ "clean": "rm -rf dist",
63
+ "build": "rolldown -c"
56
64
  }
57
65
  }
@@ -1,7 +0,0 @@
1
- import AST_tag from './tag.js';
2
- import AST_prop from './prop.js';
3
- declare const _default: {
4
- tag: typeof AST_tag;
5
- prop: typeof AST_prop;
6
- };
7
- export default _default;
@@ -1,8 +0,0 @@
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[];
@@ -1,66 +0,0 @@
1
- import type { BaseToken, TagToken, TagEndToken, ContentToken, CommentToken, Token, ParsedTagNode, AttributeMap, ParsedTagContentNode, ParsedCommentNode, TokenType } from './../types.js';
2
- declare class Tokenizer {
3
- private text;
4
- constructor(text: string);
5
- splitTokens(): IterableIterator<Token>;
6
- }
7
- declare class Lexer {
8
- private text;
9
- private includeComments;
10
- private booleanProxyCache;
11
- constructor(text: string, includeComments?: boolean);
12
- tokenStream(): IterableIterator<Token>;
13
- /**
14
- * 生成 Token 迭代器,用于遍历所有结构化 Token
15
- */
16
- tokenIterator(): IterableIterator<Token>;
17
- get tokens(): Iterable<Token>;
18
- /**
19
- * 创建一个动态布尔属性访问的 Proxy(可选功能)
20
- */
21
- getBooleanCheckProxy(): Record<string, boolean>;
22
- }
23
- /** Parser - 负责将Token流解析为AST */
24
- declare class Parser {
25
- private lexer;
26
- constructor(lexer: Lexer);
27
- /**
28
- * 解析标签属性,如:<div id="app" disabled />
29
- */
30
- private parseAttributes;
31
- /**
32
- * 基于stack的解析以支持嵌套,并为ParsedTagNode添加loc: { start, end }
33
- * Content和Comment改为递归节点数组 (ParsedTagContentNode | ParsedCommentNode | ParsedTagNode)[]
34
- */
35
- parseAST(): IterableIterator<ParsedTagNode>;
36
- get ast(): Iterable<ParsedTagNode>;
37
- }
38
- export default class McxAst {
39
- private text;
40
- private includeComments;
41
- constructor(text: string, includeComments?: boolean);
42
- private getAST;
43
- get data(): ParsedTagNode[];
44
- parseAST(): ParsedTagNode[];
45
- /**
46
- * 生成代码字符串
47
- * @param node 代码的AST节点
48
- * @returns 代码字符串
49
- */
50
- static generateCode(node: ParsedTagNode): string;
51
- }
52
- export { Tokenizer, Lexer, Parser, MCXUtils };
53
- declare class MCXUtils {
54
- static isTagNode(node: unknown): node is ParsedTagNode;
55
- static isTagContentNode(node: unknown): node is ParsedTagContentNode;
56
- static isCommentNode(node: unknown): node is ParsedCommentNode;
57
- static isAttributeMap(obj: unknown): obj is AttributeMap;
58
- static isToken(obj: unknown): obj is Token;
59
- static isTagToken(obj: unknown): obj is TagToken;
60
- static isTagEndToken(obj: unknown): obj is TagEndToken;
61
- static isContentToken(obj: unknown): obj is ContentToken;
62
- static isCommentToken(obj: unknown): obj is CommentToken;
63
- static isBaseToken(obj: unknown): obj is BaseToken;
64
- static isTokenType(value: unknown): value is TokenType;
65
- static isParseNode(node: unknown): node is ParsedTagNode[];
66
- }
@@ -1,20 +0,0 @@
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
- }
@@ -1,36 +0,0 @@
1
- import * as t from '@babel/types';
2
- import * as CompileData from './compileData';
3
- import Utils from './utils';
4
- export declare class CompileError extends Error {
5
- loc: {
6
- line: number;
7
- column: number;
8
- };
9
- constructor(message: string, loc: {
10
- line: number;
11
- column: number;
12
- });
13
- }
14
- export type Context = Record<string, t.Expression | {
15
- status: 'wait';
16
- }>;
17
- export declare class CompileJS {
18
- node: t.Program;
19
- constructor(node: t.Program);
20
- TopContext: Context;
21
- private indexTemp;
22
- private push;
23
- private writeBuildCache;
24
- private CompileData;
25
- getCompileData(): CompileData.JsCompileData;
26
- private tre;
27
- run(): void;
28
- }
29
- export declare const compileJSFn: ((code: string) => CompileData.JsCompileData) & {
30
- cache: Record<string, CompileData.JsCompileData>;
31
- };
32
- export declare const compileMCXFn: ((mcxCode: string) => CompileData.MCXCompileData) & {
33
- cache: Record<string, CompileData.MCXCompileData>;
34
- };
35
- export * from './compileData';
36
- export { Utils as MCXNodeUtils };
@@ -1,6 +0,0 @@
1
- import type { Plugin } from 'rollup';
2
- import type { Plugin as RolldownPlugin } from 'rolldown';
3
- import { CompileOpt } from '../types';
4
- import { transformCtx } from '../../types';
5
- export declare function rollupPlugin(opt: CompileOpt, output: transformCtx['output']): Plugin;
6
- export declare function rolldownPlugin(opt: CompileOpt, output: transformCtx['output']): RolldownPlugin;
@@ -1,11 +0,0 @@
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
- }
@@ -1 +0,0 @@
1
- export { rollupPlugin, rolldownPlugin } from './compiler/main';
@@ -1,52 +0,0 @@
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, };
@@ -1,14 +0,0 @@
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
- * Calc babel expression value
8
- * @param expression Babel AST node
9
- * @param currentContext current context
10
- * @param topContext top context
11
- * @returns {string | number | symbol | object}
12
- */
13
- static evaluateExpression(expression: Expression, currentContext?: Context, topContext?: Context): unknown;
14
- }
@@ -1,10 +0,0 @@
1
- import AST from './ast/index.js';
2
- import { rollupPlugin, rolldownPlugin } 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, AST, Compiler as compiler, utils, transform, compile_component, rollupPlugin, rolldownPlugin, };
9
- export { ItemComponent, BlockComponent, EntityComponent, PNGImageComponent, JPGImageComponent, SVGImageComponent, GIFImageComponent, } from './mcx-component/lib';
10
- export * as ComponentType from './mcx-component/types';
@@ -1,4 +0,0 @@
1
- declare class BlockComponent {
2
- toJSON(): {};
3
- }
4
- export { BlockComponent };