@mbler/mcx-core 0.1.2-rc.9 → 0.1.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/README.md +40 -40
- package/dist/chunk-6Ep1yQYe.js +16 -0
- package/dist/chunk-D0rfrjR5.js +21 -0
- package/dist/index.d.ts +6 -10
- package/dist/index.js +193 -304
- package/dist/index.js.map +1 -1
- package/package.json +8 -6
- package/client.d.ts +0 -17
package/dist/index.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { n as __require, t as __exportAll } from "./chunk-
|
|
1
|
+
import { n as __require, t as __exportAll } from "./chunk-D0rfrjR5.js";
|
|
2
2
|
import * as Module from "node:module";
|
|
3
3
|
import { createRequire } from "node:module";
|
|
4
|
+
import { NodeTypes, baseParse } from "@vue/compiler-core";
|
|
4
5
|
import * as path from "node:path";
|
|
5
6
|
import { extname } from "node:path";
|
|
6
7
|
import * as t from "@babel/types";
|
|
@@ -16,295 +17,165 @@ import * as vm from "node:vm";
|
|
|
16
17
|
import { Buffer } from "node:buffer";
|
|
17
18
|
import { existsSync, readFileSync } from "node:fs";
|
|
18
19
|
import { styleText } from "node:util";
|
|
19
|
-
import { BlockComponent, BlockComponent as BlockComponent$1, EntityComponent, EntityComponent as EntityComponent$1, GIFImageComponent, GIFImageComponent as GIFImageComponent$1, ItemComponent, ItemComponent as ItemComponent$1, JPGImageComponent, JPGImageComponent as JPGImageComponent$1, PNGImageComponent, PNGImageComponent as PNGImageComponent$1, SVGImageComponent, SVGImageComponent as SVGImageComponent$1 } from "@mbler/mcx-component";
|
|
20
20
|
import MagicString from "magic-string";
|
|
21
|
+
|
|
21
22
|
//#region src/ast/tag.ts
|
|
22
|
-
function
|
|
23
|
+
function getExpressionContent(expr) {
|
|
24
|
+
return expr?.content ?? "true";
|
|
25
|
+
}
|
|
26
|
+
/** Convert absolute character offset in source to MCX position (line: 1-indexed, column: 0-indexed) */
|
|
27
|
+
function absOffsetToMCXPos(source, absOffset) {
|
|
28
|
+
let line = 1;
|
|
29
|
+
let col = 0;
|
|
30
|
+
const len = Math.min(absOffset, source.length);
|
|
31
|
+
for (let i = 0; i < len; i++) if (source.charCodeAt(i) === 10) {
|
|
32
|
+
line++;
|
|
33
|
+
col = 0;
|
|
34
|
+
} else col++;
|
|
23
35
|
return {
|
|
24
36
|
line,
|
|
25
|
-
column
|
|
37
|
+
column: col
|
|
26
38
|
};
|
|
27
39
|
}
|
|
28
|
-
var
|
|
29
|
-
text;
|
|
30
|
-
constructor(text) {
|
|
31
|
-
this.text = text;
|
|
32
|
-
}
|
|
33
|
-
*splitTokens() {
|
|
34
|
-
const text = this.text;
|
|
35
|
-
let i = 0;
|
|
36
|
-
let line = 1;
|
|
37
|
-
let column = 0;
|
|
38
|
-
const len = text.length;
|
|
39
|
-
while (i < len) if (text[i] === "<") {
|
|
40
|
-
if (text.startsWith("!--", i + 1)) {
|
|
41
|
-
const commentStart = i;
|
|
42
|
-
const tokenStartLine = line;
|
|
43
|
-
const tokenStartColumn = column;
|
|
44
|
-
const endIdx = text.indexOf("-->", i + 4);
|
|
45
|
-
const commentEnd = endIdx === -1 ? len - 1 : endIdx + 2;
|
|
46
|
-
for (let j = i; j <= commentEnd; j++) if (text[j] === "\n") {
|
|
47
|
-
line++;
|
|
48
|
-
column = 0;
|
|
49
|
-
} else column++;
|
|
50
|
-
yield {
|
|
51
|
-
data: text.slice(commentStart, commentEnd + 1),
|
|
52
|
-
type: "Comment",
|
|
53
|
-
start: createPos(tokenStartLine, tokenStartColumn),
|
|
54
|
-
end: createPos(line, column)
|
|
55
|
-
};
|
|
56
|
-
i = commentEnd + 1;
|
|
57
|
-
if (i < len && text[i] === ">") column++;
|
|
58
|
-
continue;
|
|
59
|
-
}
|
|
60
|
-
const tokenStart = i;
|
|
61
|
-
const tokenStartLine = line;
|
|
62
|
-
const tokenStartColumn = column;
|
|
63
|
-
let j = i + 1;
|
|
64
|
-
let sawGt = false;
|
|
65
|
-
for (; j < len; j++) {
|
|
66
|
-
const c = text[j];
|
|
67
|
-
if (c === ">") {
|
|
68
|
-
sawGt = true;
|
|
69
|
-
break;
|
|
70
|
-
}
|
|
71
|
-
if (c === "\n") {
|
|
72
|
-
line++;
|
|
73
|
-
column = 0;
|
|
74
|
-
} else column++;
|
|
75
|
-
}
|
|
76
|
-
const buffer = text.slice(tokenStart, sawGt ? j + 1 : len);
|
|
77
|
-
yield {
|
|
78
|
-
data: buffer,
|
|
79
|
-
type: buffer.startsWith("</") ? "TagEnd" : "Tag",
|
|
80
|
-
start: createPos(tokenStartLine, tokenStartColumn),
|
|
81
|
-
end: createPos(line, column)
|
|
82
|
-
};
|
|
83
|
-
i = sawGt ? j + 1 : len;
|
|
84
|
-
if (sawGt) column++;
|
|
85
|
-
} else {
|
|
86
|
-
const contentStart = i;
|
|
87
|
-
const contentStartLine = line;
|
|
88
|
-
const contentStartColumn = column;
|
|
89
|
-
let j = i;
|
|
90
|
-
for (; j < len; j++) {
|
|
91
|
-
const c = text[j];
|
|
92
|
-
if (c === "<") break;
|
|
93
|
-
if (c === "\n") {
|
|
94
|
-
line++;
|
|
95
|
-
column = 0;
|
|
96
|
-
} else column++;
|
|
97
|
-
}
|
|
98
|
-
yield {
|
|
99
|
-
data: text.slice(contentStart, j),
|
|
100
|
-
type: "Content",
|
|
101
|
-
start: createPos(contentStartLine, contentStartColumn),
|
|
102
|
-
end: createPos(line, j > contentStart ? column - 1 : column)
|
|
103
|
-
};
|
|
104
|
-
i = j;
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
};
|
|
108
|
-
var Lexer$1 = class {
|
|
40
|
+
var McxAst = class McxAst {
|
|
109
41
|
text;
|
|
110
42
|
includeComments;
|
|
111
|
-
booleanProxyCache;
|
|
112
43
|
constructor(text, includeComments = false) {
|
|
113
44
|
this.text = text;
|
|
114
45
|
this.includeComments = includeComments;
|
|
115
|
-
this.booleanProxyCache = /* @__PURE__ */ new WeakMap();
|
|
116
46
|
}
|
|
117
|
-
|
|
118
|
-
const
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
47
|
+
parseAST() {
|
|
48
|
+
const ast = baseParse(this.text, {
|
|
49
|
+
comments: true,
|
|
50
|
+
whitespace: "preserve"
|
|
51
|
+
});
|
|
52
|
+
const result = [];
|
|
53
|
+
for (const child of ast.children) {
|
|
54
|
+
const node = this.convertTemplateChild(child);
|
|
55
|
+
if (node) result.push(node);
|
|
122
56
|
}
|
|
57
|
+
return result;
|
|
123
58
|
}
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
const
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
59
|
+
convertTemplateChild(node) {
|
|
60
|
+
if (node.type === NodeTypes.ELEMENT) return this.convertVueElement(node);
|
|
61
|
+
if (node.type === NodeTypes.TEXT) {
|
|
62
|
+
const textNode = node;
|
|
63
|
+
if (textNode.content.trim()) return {
|
|
64
|
+
data: textNode.content,
|
|
65
|
+
type: "TagContent"
|
|
66
|
+
};
|
|
67
|
+
return null;
|
|
68
|
+
}
|
|
69
|
+
if (node.type === NodeTypes.INTERPOLATION) return {
|
|
70
|
+
data: `{{ ${getExpressionContent(node.content)} }}`,
|
|
71
|
+
type: "TagContent"
|
|
72
|
+
};
|
|
73
|
+
if (this.includeComments && node.type === NodeTypes.COMMENT) {
|
|
74
|
+
const commentNode = node;
|
|
75
|
+
return {
|
|
76
|
+
data: commentNode.content,
|
|
77
|
+
type: "Comment",
|
|
78
|
+
loc: {
|
|
79
|
+
start: {
|
|
80
|
+
line: commentNode.loc.start.line,
|
|
81
|
+
column: commentNode.loc.start.column
|
|
82
|
+
},
|
|
83
|
+
end: {
|
|
84
|
+
line: commentNode.loc.end.line,
|
|
85
|
+
column: commentNode.loc.end.column
|
|
86
|
+
}
|
|
148
87
|
}
|
|
149
|
-
}
|
|
150
|
-
this.booleanProxyCache.set(this, proxy);
|
|
88
|
+
};
|
|
151
89
|
}
|
|
152
|
-
return
|
|
153
|
-
}
|
|
154
|
-
};
|
|
155
|
-
/** Parser - 负责将Token流解析为AST */
|
|
156
|
-
var Parser$1 = class {
|
|
157
|
-
lexer;
|
|
158
|
-
constructor(lexer) {
|
|
159
|
-
this.lexer = lexer;
|
|
90
|
+
return null;
|
|
160
91
|
}
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
const char = tagContent[i];
|
|
175
|
-
if (isTagName) {
|
|
176
|
-
if (char === " " || char === ">") {
|
|
177
|
-
name = currentKey.trim();
|
|
178
|
-
currentKey = "";
|
|
179
|
-
isTagName = false;
|
|
180
|
-
if (char === ">") break;
|
|
181
|
-
} else currentKey += char;
|
|
182
|
-
continue;
|
|
92
|
+
convertVueElement(node) {
|
|
93
|
+
const attrs = {};
|
|
94
|
+
for (const prop of node.props) if (prop.type === NodeTypes.ATTRIBUTE) {
|
|
95
|
+
const attr = prop;
|
|
96
|
+
attrs[attr.name] = attr.value?.content ?? "true";
|
|
97
|
+
} else if (prop.type === NodeTypes.DIRECTIVE) {
|
|
98
|
+
const dir = prop;
|
|
99
|
+
if (dir.name === "bind") {
|
|
100
|
+
const key = `:${getExpressionContent(dir.arg)}`;
|
|
101
|
+
attrs[key] = getExpressionContent(dir.exp);
|
|
102
|
+
} else if (dir.name === "on") {
|
|
103
|
+
const key = `@${getExpressionContent(dir.arg)}`;
|
|
104
|
+
attrs[key] = "true";
|
|
183
105
|
}
|
|
184
|
-
if (inValue) if (char === quoteChar && (currentValue.length === 0 || currentValue[currentValue.length - 1] !== "\\")) {
|
|
185
|
-
attributes[currentKey.trim()] = currentValue;
|
|
186
|
-
currentKey = "";
|
|
187
|
-
currentValue = "";
|
|
188
|
-
inKey = true;
|
|
189
|
-
inValue = false;
|
|
190
|
-
quoteChar = null;
|
|
191
|
-
} else currentValue += char;
|
|
192
|
-
else if (char === "=" && inKey) {
|
|
193
|
-
inKey = false;
|
|
194
|
-
inValue = true;
|
|
195
|
-
const nextIndex = i + 1;
|
|
196
|
-
const nextChar = nextIndex < tagContent.length ? tagContent[nextIndex] : " ";
|
|
197
|
-
if (nextChar === "\"" || nextChar === "'") {
|
|
198
|
-
quoteChar = nextChar;
|
|
199
|
-
i = nextIndex;
|
|
200
|
-
} else quoteChar = " ";
|
|
201
|
-
} else if (char === " " && inKey && currentKey) {
|
|
202
|
-
attributes[currentKey.trim()] = "true";
|
|
203
|
-
currentKey = "";
|
|
204
|
-
} else if (inKey) currentKey += char;
|
|
205
106
|
}
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
const rawTokens = Array.from(this.lexer.tokenStream());
|
|
219
|
-
const root = [];
|
|
220
|
-
const stack = [];
|
|
221
|
-
for (let idx = 0; idx < rawTokens.length; idx++) {
|
|
222
|
-
const token = rawTokens[idx];
|
|
223
|
-
if (!token) continue;
|
|
224
|
-
if (token.type === "Content") {
|
|
225
|
-
const contentNode = {
|
|
226
|
-
data: token.data,
|
|
227
|
-
type: "TagContent"
|
|
228
|
-
};
|
|
229
|
-
if (stack.length > 0) stack[stack.length - 1].content.push(contentNode);
|
|
230
|
-
else root.push(contentNode);
|
|
231
|
-
} else if (token.type === "Comment") {
|
|
232
|
-
const commentNode = {
|
|
233
|
-
data: token.data,
|
|
234
|
-
type: "Comment",
|
|
235
|
-
loc: {
|
|
236
|
-
start: { ...token.start },
|
|
237
|
-
end: { ...token.end }
|
|
238
|
-
}
|
|
239
|
-
};
|
|
240
|
-
if (stack.length > 0) stack[stack.length - 1].content.push(commentNode);
|
|
241
|
-
else root.push(commentNode);
|
|
242
|
-
} else if (token.type === "Tag") {
|
|
243
|
-
const inner = token.data.slice(1, -1).trim();
|
|
244
|
-
const isSelfClosing = inner.endsWith("/");
|
|
245
|
-
const arr = this.parseAttributes(isSelfClosing ? inner.slice(0, -1).trim() : inner);
|
|
246
|
-
const node = {
|
|
247
|
-
start: token,
|
|
248
|
-
name: arr.name,
|
|
249
|
-
arr: arr.arr,
|
|
250
|
-
content: [],
|
|
251
|
-
end: null,
|
|
252
|
-
type: "TagNode",
|
|
253
|
-
loc: {
|
|
254
|
-
start: { ...token.start },
|
|
255
|
-
end: { ...token.end }
|
|
256
|
-
}
|
|
257
|
-
};
|
|
258
|
-
if (isSelfClosing) if (stack.length > 0) stack[stack.length - 1].content.push(node);
|
|
259
|
-
else yield node;
|
|
260
|
-
else stack.push(node);
|
|
261
|
-
} else if (token.type === "TagEnd") {
|
|
262
|
-
const name = token.data.replace(/^<\/\s*/, "").replace(/\s*>$/, "").trim();
|
|
263
|
-
for (let s = stack.length - 1; s >= 0; s--) {
|
|
264
|
-
const candidate = stack[s];
|
|
265
|
-
if (candidate && candidate.name === name) {
|
|
266
|
-
candidate.end = token;
|
|
267
|
-
candidate.loc.end = { ...token.end };
|
|
268
|
-
stack.splice(s, 1);
|
|
269
|
-
if (stack.length > 0) stack[stack.length - 1].content.push(candidate);
|
|
270
|
-
else yield candidate;
|
|
271
|
-
break;
|
|
272
|
-
}
|
|
107
|
+
const children = this.convertVueChildren(node.children);
|
|
108
|
+
const fullSource = this.text;
|
|
109
|
+
const baseOffset = node.loc.start.offset;
|
|
110
|
+
const elementSource = node.loc.source;
|
|
111
|
+
let openEnd = elementSource.length;
|
|
112
|
+
let inQuote = null;
|
|
113
|
+
for (let i = 0; i < elementSource.length; i++) {
|
|
114
|
+
const c = elementSource[i];
|
|
115
|
+
if (inQuote) {
|
|
116
|
+
if (c === "\\") {
|
|
117
|
+
i++;
|
|
118
|
+
continue;
|
|
273
119
|
}
|
|
120
|
+
if (c === inQuote) inQuote = null;
|
|
121
|
+
} else if (c === "\"" || c === "'") inQuote = c;
|
|
122
|
+
else if (c === ">") {
|
|
123
|
+
openEnd = i + 1;
|
|
124
|
+
break;
|
|
274
125
|
}
|
|
275
126
|
}
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
127
|
+
let closeStart = -1;
|
|
128
|
+
if (!node.isSelfClosing) {
|
|
129
|
+
for (let i = elementSource.length - 2; i >= 0; i--) if (elementSource[i] === "<" && elementSource[i + 1] === "/") {
|
|
130
|
+
closeStart = i;
|
|
131
|
+
break;
|
|
132
|
+
}
|
|
280
133
|
}
|
|
134
|
+
const openTagStartAbs = baseOffset;
|
|
135
|
+
const openTagEndAbs = baseOffset + openEnd;
|
|
136
|
+
let endToken = null;
|
|
137
|
+
if (closeStart >= 0) {
|
|
138
|
+
const closeTagStartAbs = baseOffset + closeStart;
|
|
139
|
+
const closeTagEndAbs = baseOffset + elementSource.length;
|
|
140
|
+
endToken = {
|
|
141
|
+
data: elementSource.slice(closeStart),
|
|
142
|
+
type: "TagEnd",
|
|
143
|
+
start: absOffsetToMCXPos(fullSource, closeTagStartAbs),
|
|
144
|
+
end: absOffsetToMCXPos(fullSource, closeTagEndAbs)
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
return {
|
|
148
|
+
start: {
|
|
149
|
+
data: elementSource.slice(0, openEnd),
|
|
150
|
+
type: "Tag",
|
|
151
|
+
start: absOffsetToMCXPos(fullSource, openTagStartAbs),
|
|
152
|
+
end: absOffsetToMCXPos(fullSource, openTagEndAbs)
|
|
153
|
+
},
|
|
154
|
+
name: node.tag,
|
|
155
|
+
arr: attrs,
|
|
156
|
+
content: children,
|
|
157
|
+
end: endToken,
|
|
158
|
+
loc: {
|
|
159
|
+
start: {
|
|
160
|
+
line: node.loc.start.line,
|
|
161
|
+
column: node.loc.start.column
|
|
162
|
+
},
|
|
163
|
+
end: {
|
|
164
|
+
line: node.loc.end.line,
|
|
165
|
+
column: node.loc.end.column
|
|
166
|
+
}
|
|
167
|
+
},
|
|
168
|
+
type: "TagNode"
|
|
169
|
+
};
|
|
281
170
|
}
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
constructor(text, includeComments = false) {
|
|
290
|
-
this.text = text;
|
|
291
|
-
this.includeComments = includeComments;
|
|
292
|
-
}
|
|
293
|
-
getAST() {
|
|
294
|
-
const parser = new Parser$1(new Lexer$1(this.text, this.includeComments));
|
|
295
|
-
return Array.from(parser.parseAST());
|
|
296
|
-
}
|
|
297
|
-
get data() {
|
|
298
|
-
return this.getAST();
|
|
299
|
-
}
|
|
300
|
-
parseAST() {
|
|
301
|
-
return this.getAST();
|
|
171
|
+
convertVueChildren(children) {
|
|
172
|
+
const result = [];
|
|
173
|
+
for (const child of children) {
|
|
174
|
+
const node = this.convertTemplateChild(child);
|
|
175
|
+
if (node) result.push(node);
|
|
176
|
+
}
|
|
177
|
+
return result;
|
|
302
178
|
}
|
|
303
|
-
/**
|
|
304
|
-
* 生成代码字符串
|
|
305
|
-
* @param node 代码的AST节点
|
|
306
|
-
* @returns 代码字符串
|
|
307
|
-
*/
|
|
308
179
|
static generateCode(node) {
|
|
309
180
|
let code = `<${node.name}`;
|
|
310
181
|
for (const [key, value] of Object.entries(node.arr || {})) if (value === "true") code += ` ${key}`;
|
|
@@ -312,6 +183,7 @@ var McxAst = class McxAst {
|
|
|
312
183
|
code += ">";
|
|
313
184
|
const contentArr = node.content;
|
|
314
185
|
if (Array.isArray(contentArr)) for (const item of contentArr) if (item.type === "TagContent") code += item.data;
|
|
186
|
+
else if (item.type === "Comment") code += item.data;
|
|
315
187
|
else code += McxAst.generateCode(item);
|
|
316
188
|
code += `</${node.name}>`;
|
|
317
189
|
return code;
|
|
@@ -330,31 +202,32 @@ var MCXUtils = class MCXUtils {
|
|
|
330
202
|
static isAttributeMap(obj) {
|
|
331
203
|
return !!obj && typeof obj === "object" && !Array.isArray(obj);
|
|
332
204
|
}
|
|
333
|
-
static
|
|
334
|
-
return
|
|
205
|
+
static isParseNode(node) {
|
|
206
|
+
return Array.isArray(node) && node.every(MCXUtils.isTagNode);
|
|
335
207
|
}
|
|
336
|
-
static
|
|
337
|
-
return
|
|
208
|
+
static isToken(_obj) {
|
|
209
|
+
return false;
|
|
338
210
|
}
|
|
339
|
-
static
|
|
340
|
-
return
|
|
211
|
+
static isTagToken(_obj) {
|
|
212
|
+
return false;
|
|
341
213
|
}
|
|
342
|
-
static
|
|
343
|
-
return
|
|
214
|
+
static isTagEndToken(_obj) {
|
|
215
|
+
return false;
|
|
344
216
|
}
|
|
345
|
-
static
|
|
346
|
-
return
|
|
217
|
+
static isContentToken(_obj) {
|
|
218
|
+
return false;
|
|
347
219
|
}
|
|
348
|
-
static
|
|
349
|
-
return
|
|
220
|
+
static isCommentToken(_obj) {
|
|
221
|
+
return false;
|
|
350
222
|
}
|
|
351
|
-
static
|
|
352
|
-
return
|
|
223
|
+
static isBaseToken(_obj) {
|
|
224
|
+
return false;
|
|
353
225
|
}
|
|
354
|
-
static
|
|
355
|
-
return
|
|
226
|
+
static isTokenType(_value) {
|
|
227
|
+
return false;
|
|
356
228
|
}
|
|
357
229
|
};
|
|
230
|
+
|
|
358
231
|
//#endregion
|
|
359
232
|
//#region src/ast/prop.ts
|
|
360
233
|
const STATUS = [0, 1];
|
|
@@ -404,12 +277,14 @@ function PropParser(code) {
|
|
|
404
277
|
const lexer = new Lexer(code);
|
|
405
278
|
return Array.from(lexer.tokenize());
|
|
406
279
|
}
|
|
280
|
+
|
|
407
281
|
//#endregion
|
|
408
282
|
//#region src/ast/index.ts
|
|
409
283
|
var ast_default = {
|
|
410
284
|
tag: McxAst,
|
|
411
285
|
prop: PropParser
|
|
412
286
|
};
|
|
287
|
+
|
|
413
288
|
//#endregion
|
|
414
289
|
//#region src/compile-mcx/types.ts
|
|
415
290
|
const _MCXstructureLocComponentTypes = {
|
|
@@ -417,6 +292,7 @@ const _MCXstructureLocComponentTypes = {
|
|
|
417
292
|
blocks: "block",
|
|
418
293
|
entities: "entity"
|
|
419
294
|
};
|
|
295
|
+
|
|
420
296
|
//#endregion
|
|
421
297
|
//#region src/compile-mcx/compiler/compileData.ts
|
|
422
298
|
var JsCompileData = class {
|
|
@@ -449,6 +325,7 @@ var MCXCompileData = class {
|
|
|
449
325
|
this.File = dir;
|
|
450
326
|
}
|
|
451
327
|
};
|
|
328
|
+
|
|
452
329
|
//#endregion
|
|
453
330
|
//#region src/compile-mcx/compiler/utils.ts
|
|
454
331
|
var Utils$1 = class Utils$1 {
|
|
@@ -525,6 +402,7 @@ var Utils$1 = class Utils$1 {
|
|
|
525
402
|
};
|
|
526
403
|
}
|
|
527
404
|
};
|
|
405
|
+
|
|
528
406
|
//#endregion
|
|
529
407
|
//#region src/compile-mcx/compiler/index.ts
|
|
530
408
|
var compiler_exports = /* @__PURE__ */ __exportAll({
|
|
@@ -868,6 +746,7 @@ const compileMCXFn = ((mcxCode) => {
|
|
|
868
746
|
});
|
|
869
747
|
compileJSFn.cache = {};
|
|
870
748
|
compileMCXFn.cache = {};
|
|
749
|
+
|
|
871
750
|
//#endregion
|
|
872
751
|
//#region src/transforms/config.ts
|
|
873
752
|
var config_default = {
|
|
@@ -877,6 +756,7 @@ var config_default = {
|
|
|
877
756
|
eventExtendsName: "McxExtendsBy",
|
|
878
757
|
paramCtx: "__mcx__ctx"
|
|
879
758
|
};
|
|
759
|
+
|
|
880
760
|
//#endregion
|
|
881
761
|
//#region src/utils.ts
|
|
882
762
|
var Utils = class Utils {
|
|
@@ -925,12 +805,14 @@ var Utils = class Utils {
|
|
|
925
805
|
return path.isAbsolute(inputPath) ? inputPath : path.join(baseDir, inputPath);
|
|
926
806
|
}
|
|
927
807
|
};
|
|
808
|
+
|
|
928
809
|
//#endregion
|
|
929
810
|
//#region src/transforms/file_id.ts
|
|
930
811
|
let fileIdCounter = 0;
|
|
931
812
|
function generateFileId() {
|
|
932
813
|
return `__file_import_${fileIdCounter++}__`;
|
|
933
814
|
}
|
|
815
|
+
|
|
934
816
|
//#endregion
|
|
935
817
|
//#region src/transforms/utils.ts
|
|
936
818
|
function extractVarDefIdList(express) {
|
|
@@ -1049,6 +931,7 @@ function _enableWithData() {
|
|
|
1049
931
|
fn.prototype.enable = d;
|
|
1050
932
|
return fn;
|
|
1051
933
|
}
|
|
934
|
+
|
|
1052
935
|
//#endregion
|
|
1053
936
|
//#region src/transforms/transform/ui.ts
|
|
1054
937
|
async function Comp$2(ctx) {
|
|
@@ -1075,16 +958,19 @@ async function Comp$2(ctx) {
|
|
|
1075
958
|
line: uiClientTag.loc.start.line
|
|
1076
959
|
} : void 0);
|
|
1077
960
|
}
|
|
961
|
+
let _if;
|
|
962
|
+
if (typeof uiClientTag.arr.if === "string") _if = { useProp: uiClientTag.arr.if };
|
|
1078
963
|
UITree.push({
|
|
1079
964
|
arr: uiClientTag.arr,
|
|
1080
965
|
content: uiClientTag.content.map((i) => i.type == "TagContent" && i.data || "").join(""),
|
|
1081
966
|
type: uiClientTag.name,
|
|
1082
967
|
loc: uiClientTag.loc,
|
|
1083
|
-
for: _for
|
|
968
|
+
..._for ? { for: _for } : {},
|
|
969
|
+
..._if ? { if: _if } : {}
|
|
1084
970
|
});
|
|
1085
971
|
}
|
|
1086
972
|
const parsedObj = [];
|
|
1087
|
-
function pushToTree(name, params, content, _for) {
|
|
973
|
+
function pushToTree(name, params, content, _for, _if) {
|
|
1088
974
|
const props = [
|
|
1089
975
|
t.objectProperty(t.identifier("type"), t.stringLiteral(name)),
|
|
1090
976
|
t.objectProperty(t.identifier("params"), t.objectExpression(Object.entries(params).map(([key, value]) => {
|
|
@@ -1095,12 +981,14 @@ async function Comp$2(ctx) {
|
|
|
1095
981
|
t.objectProperty(t.identifier("content"), content.startsWith("{{ ") && content.endsWith(" }}") ? t.objectExpression([t.objectProperty(t.identifier("useProp"), t.stringLiteral(content.slice(3, content.length - 3).trim()))]) : t.stringLiteral(content))
|
|
1096
982
|
];
|
|
1097
983
|
if (_for) props.push(t.objectProperty(t.identifier("for"), t.objectExpression([t.objectProperty(t.identifier("variable"), t.stringLiteral(_for.variable)), t.objectProperty(t.identifier("useProp"), t.stringLiteral(_for.useProp))])));
|
|
984
|
+
if (_if) props.push(t.objectProperty(t.identifier("if"), t.objectExpression([t.objectProperty(t.identifier("useProp"), t.stringLiteral(_if.useProp))])));
|
|
1098
985
|
parsedObj.push(t.objectExpression(props));
|
|
1099
986
|
}
|
|
1100
987
|
for (const tp of UITree) {
|
|
1101
988
|
const name = tp.type;
|
|
1102
989
|
const cleanedArr = { ...tp.arr };
|
|
1103
990
|
delete cleanedArr.for;
|
|
991
|
+
delete cleanedArr.if;
|
|
1104
992
|
if ([
|
|
1105
993
|
"input",
|
|
1106
994
|
"dropdown",
|
|
@@ -1113,26 +1001,26 @@ async function Comp$2(ctx) {
|
|
|
1113
1001
|
column: tp.loc.start.column
|
|
1114
1002
|
} : void 0);
|
|
1115
1003
|
MCXUIType = "ModalFormData";
|
|
1116
|
-
pushToTree(name, cleanedArr, tp.content, tp.for);
|
|
1004
|
+
pushToTree(name, cleanedArr, tp.content, tp.for, tp.if);
|
|
1117
1005
|
} else if (["button-m"].includes(name)) {
|
|
1118
1006
|
if (MCXUIType && MCXUIType !== "MessageFormData") internalCtx.rollupContext.error("[UI]: ", tp.loc ? {
|
|
1119
1007
|
line: tp.loc.start.line,
|
|
1120
1008
|
column: tp.loc.start.column
|
|
1121
1009
|
} : void 0);
|
|
1122
1010
|
MCXUIType = "MessageFormData";
|
|
1123
|
-
pushToTree(name, cleanedArr, tp.content, tp.for);
|
|
1011
|
+
pushToTree(name, cleanedArr, tp.content, tp.for, tp.if);
|
|
1124
1012
|
} else if ([
|
|
1125
1013
|
"body",
|
|
1126
1014
|
"divider",
|
|
1127
1015
|
"title",
|
|
1128
1016
|
"label"
|
|
1129
|
-
].includes(name)) pushToTree(name, cleanedArr, tp.content, tp.for);
|
|
1017
|
+
].includes(name)) pushToTree(name, cleanedArr, tp.content, tp.for, tp.if);
|
|
1130
1018
|
else if (name == "button") {
|
|
1131
1019
|
if (MCXUIType !== "ActionFormData" && MCXUIType) internalCtx.rollupContext.error("[UI]: don't support use button for messageFormData", tp.loc ? {
|
|
1132
1020
|
line: tp.loc.start.line,
|
|
1133
1021
|
column: tp.loc.start.column
|
|
1134
1022
|
} : void 0);
|
|
1135
|
-
pushToTree(name, cleanedArr, tp.content, tp.for);
|
|
1023
|
+
pushToTree(name, cleanedArr, tp.content, tp.for, tp.if);
|
|
1136
1024
|
MCXUIType = "ActionFormData";
|
|
1137
1025
|
} else internalCtx.rollupContext.error("[UI]: don't support tag: " + name, tp.loc ? {
|
|
1138
1026
|
line: tp.loc.start.line,
|
|
@@ -1147,12 +1035,14 @@ async function Comp$2(ctx) {
|
|
|
1147
1035
|
]);
|
|
1148
1036
|
ctx.app([t.objectProperty(t.identifier("ui"), t.newExpression(t.identifier("__mcx__ui"), [finallyData, t.identifier(config_default.scriptCompileFn)]))]);
|
|
1149
1037
|
}
|
|
1038
|
+
|
|
1150
1039
|
//#endregion
|
|
1151
1040
|
//#region src/transforms/transform/event.ts
|
|
1152
1041
|
async function Comp$1(ctx) {
|
|
1153
1042
|
const appData = [t.objectProperty(t.identifier("event"), await generateEventConfig(ctx.ctx.compiledCode.raw.find((node) => node.name === "Event"), ctx.ctx, ctx.impBody))];
|
|
1154
1043
|
ctx.app(appData);
|
|
1155
1044
|
}
|
|
1045
|
+
|
|
1156
1046
|
//#endregion
|
|
1157
1047
|
//#region src/transforms/transform/app.ts
|
|
1158
1048
|
async function Comp(ctx) {
|
|
@@ -1194,6 +1084,7 @@ async function Comp(ctx) {
|
|
|
1194
1084
|
ctx.app(appData);
|
|
1195
1085
|
}
|
|
1196
1086
|
}
|
|
1087
|
+
|
|
1197
1088
|
//#endregion
|
|
1198
1089
|
//#region src/mcx-component/cjsTransform.ts
|
|
1199
1090
|
/**
|
|
@@ -1283,6 +1174,7 @@ function transformImportIRtoRequire(importIR) {
|
|
|
1283
1174
|
}
|
|
1284
1175
|
return define;
|
|
1285
1176
|
}
|
|
1177
|
+
|
|
1286
1178
|
//#endregion
|
|
1287
1179
|
//#region src/mcx-component/vm.ts
|
|
1288
1180
|
const BLOCKED_MODULES = new Set([
|
|
@@ -1394,17 +1286,11 @@ var RunScript = class {
|
|
|
1394
1286
|
}
|
|
1395
1287
|
static isCanUseEsmRunVm = typeof vm.SourceTextModule == "function";
|
|
1396
1288
|
};
|
|
1289
|
+
|
|
1397
1290
|
//#endregion
|
|
1398
1291
|
//#region src/mcx-component/index.ts
|
|
1399
1292
|
var mcx_component_exports = /* @__PURE__ */ __exportAll({
|
|
1400
|
-
BlockComponent: () => BlockComponent$1,
|
|
1401
|
-
EntityComponent: () => EntityComponent$1,
|
|
1402
|
-
GIFImageComponent: () => GIFImageComponent$1,
|
|
1403
|
-
ItemComponent: () => ItemComponent$1,
|
|
1404
|
-
JPGImageComponent: () => JPGImageComponent$1,
|
|
1405
|
-
PNGImageComponent: () => PNGImageComponent$1,
|
|
1406
1293
|
RunScript: () => RunScript,
|
|
1407
|
-
SVGImageComponent: () => SVGImageComponent$1,
|
|
1408
1294
|
clearCachedOptions: () => clearCachedOptions,
|
|
1409
1295
|
compileComponent: () => compileComponent,
|
|
1410
1296
|
execESMMethod: () => execESMMethod,
|
|
@@ -1650,6 +1536,7 @@ async function compileComponent(compiledCode, ctx) {
|
|
|
1650
1536
|
await writeFile(filePoint, JSON.stringify(json, null, 2));
|
|
1651
1537
|
}
|
|
1652
1538
|
}
|
|
1539
|
+
|
|
1653
1540
|
//#endregion
|
|
1654
1541
|
//#region src/transforms/main.ts
|
|
1655
1542
|
async function _transform(ctx) {
|
|
@@ -1695,6 +1582,7 @@ async function _transform(ctx) {
|
|
|
1695
1582
|
t.exportDefaultDeclaration(t.objectExpression(prop))
|
|
1696
1583
|
])).code;
|
|
1697
1584
|
}
|
|
1585
|
+
|
|
1698
1586
|
//#endregion
|
|
1699
1587
|
//#region src/transforms/index.ts
|
|
1700
1588
|
function createErrorProxy(err, id) {
|
|
@@ -1727,8 +1615,10 @@ async function transform(code, cache, id, context, opt, output) {
|
|
|
1727
1615
|
});
|
|
1728
1616
|
} catch (err) {
|
|
1729
1617
|
context.error(createErrorProxy(err, id));
|
|
1618
|
+
return;
|
|
1730
1619
|
}
|
|
1731
1620
|
}
|
|
1621
|
+
|
|
1732
1622
|
//#endregion
|
|
1733
1623
|
//#region src/compile-mcx/compiler/main.ts
|
|
1734
1624
|
function createMcxPlugin(opt, output) {
|
|
@@ -1859,14 +1749,11 @@ function createMcxPlugin(opt, output) {
|
|
|
1859
1749
|
compileData = cache.has(id) ? cache.get(id) : compileMCXFn(code);
|
|
1860
1750
|
cache.set(id, compileData);
|
|
1861
1751
|
} catch (err) {
|
|
1862
|
-
if (err instanceof CompileError) {
|
|
1863
|
-
|
|
1864
|
-
|
|
1865
|
-
|
|
1866
|
-
|
|
1867
|
-
});
|
|
1868
|
-
}
|
|
1869
|
-
this.error(err instanceof Error ? `${err.message} : ${err.stack}` : String(err));
|
|
1752
|
+
if (err instanceof CompileError) this.error(err.message, {
|
|
1753
|
+
column: err.loc.column,
|
|
1754
|
+
line: err.loc.line
|
|
1755
|
+
});
|
|
1756
|
+
else this.error(err instanceof Error ? `${err.message} : ${err.stack}` : String(err));
|
|
1870
1757
|
return;
|
|
1871
1758
|
}
|
|
1872
1759
|
compileData.setFilePath(id);
|
|
@@ -1905,16 +1792,18 @@ function rollupPlugin(opt, output) {
|
|
|
1905
1792
|
function rolldownPlugin(opt, output) {
|
|
1906
1793
|
return createMcxPlugin(opt, output);
|
|
1907
1794
|
}
|
|
1795
|
+
|
|
1908
1796
|
//#endregion
|
|
1909
1797
|
//#region src/types.ts
|
|
1910
1798
|
var types_exports$1 = /* @__PURE__ */ __exportAll({});
|
|
1799
|
+
|
|
1911
1800
|
//#endregion
|
|
1912
1801
|
//#region src/mcx-component/types.ts
|
|
1913
1802
|
var types_exports = /* @__PURE__ */ __exportAll({ createFileEdit: () => createFileEdit });
|
|
1914
1803
|
function createFileEdit(expression) {
|
|
1915
1804
|
return expression;
|
|
1916
1805
|
}
|
|
1917
|
-
//#endregion
|
|
1918
|
-
export { ast_default as AST, BlockComponent, types_exports as ComponentType, EntityComponent, GIFImageComponent, ItemComponent, JPGImageComponent, PNGImageComponent, types_exports$1 as PubType, SVGImageComponent, mcx_component_exports as compile_component, compiler_exports as compiler, rolldownPlugin, rollupPlugin, transform, Utils as utils };
|
|
1919
1806
|
|
|
1807
|
+
//#endregion
|
|
1808
|
+
export { ast_default as AST, types_exports as ComponentType, types_exports$1 as PubType, mcx_component_exports as compile_component, compiler_exports as compiler, rolldownPlugin, rollupPlugin, transform, Utils as utils };
|
|
1920
1809
|
//# sourceMappingURL=index.js.map
|