babel-plugin-essor 0.0.8 → 0.0.10-beta.21
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/LICENSE +20 -20
- package/README.md +28 -14
- package/dist/index.cjs +221 -462
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +224 -462
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
package/dist/index.cjs
CHANGED
|
@@ -2,7 +2,21 @@
|
|
|
2
2
|
var __defProp = Object.defineProperty;
|
|
3
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
5
6
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
8
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
9
|
+
var __spreadValues = (a, b) => {
|
|
10
|
+
for (var prop in b || (b = {}))
|
|
11
|
+
if (__hasOwnProp.call(b, prop))
|
|
12
|
+
__defNormalProp(a, prop, b[prop]);
|
|
13
|
+
if (__getOwnPropSymbols)
|
|
14
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
15
|
+
if (__propIsEnum.call(b, prop))
|
|
16
|
+
__defNormalProp(a, prop, b[prop]);
|
|
17
|
+
}
|
|
18
|
+
return a;
|
|
19
|
+
};
|
|
6
20
|
var __export = (target, all) => {
|
|
7
21
|
for (var name in all)
|
|
8
22
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
@@ -24,6 +38,9 @@ __export(src_exports, {
|
|
|
24
38
|
});
|
|
25
39
|
module.exports = __toCommonJS(src_exports);
|
|
26
40
|
|
|
41
|
+
// src/jsx/index.ts
|
|
42
|
+
var import_core3 = require("@babel/core");
|
|
43
|
+
|
|
27
44
|
// ../shared/dist/essor-shared.js
|
|
28
45
|
var isArray = Array.isArray;
|
|
29
46
|
function isString(val) {
|
|
@@ -40,15 +57,18 @@ var capitalizeFirstLetter = (inputString) => {
|
|
|
40
57
|
return inputString.charAt(0).toUpperCase() + inputString.slice(1);
|
|
41
58
|
};
|
|
42
59
|
|
|
43
|
-
// src/jsx/server.ts
|
|
44
|
-
var import_core3 = require("@babel/core");
|
|
45
|
-
|
|
46
60
|
// src/program.ts
|
|
47
61
|
var import_core = require("@babel/core");
|
|
48
62
|
var imports = /* @__PURE__ */ new Set();
|
|
63
|
+
var defaultOption = {
|
|
64
|
+
ssg: false,
|
|
65
|
+
symbol: "$",
|
|
66
|
+
props: true
|
|
67
|
+
};
|
|
49
68
|
var transformProgram = {
|
|
50
69
|
enter(path, state) {
|
|
51
70
|
imports.clear();
|
|
71
|
+
state.opts = __spreadValues(__spreadValues({}, defaultOption), state.opts);
|
|
52
72
|
path.state = {
|
|
53
73
|
h: path.scope.generateUidIdentifier("h$"),
|
|
54
74
|
renderTemplate: path.scope.generateUidIdentifier("renderTemplate$"),
|
|
@@ -84,46 +104,7 @@ function createImport(state, from) {
|
|
|
84
104
|
return import_core.types.importDeclaration(ImportSpecifier, importSource);
|
|
85
105
|
}
|
|
86
106
|
|
|
87
|
-
// src/
|
|
88
|
-
var selfClosingTags = [
|
|
89
|
-
"area",
|
|
90
|
-
"base",
|
|
91
|
-
"br",
|
|
92
|
-
"col",
|
|
93
|
-
"embed",
|
|
94
|
-
"hr",
|
|
95
|
-
"img",
|
|
96
|
-
"input",
|
|
97
|
-
"link",
|
|
98
|
-
"meta",
|
|
99
|
-
"param",
|
|
100
|
-
"source",
|
|
101
|
-
"track",
|
|
102
|
-
"wbr"
|
|
103
|
-
];
|
|
104
|
-
var svgTags = [
|
|
105
|
-
"circle",
|
|
106
|
-
"clipPath",
|
|
107
|
-
"defs",
|
|
108
|
-
"ellipse",
|
|
109
|
-
"filter",
|
|
110
|
-
"g",
|
|
111
|
-
"line",
|
|
112
|
-
"linearGradient",
|
|
113
|
-
"mask",
|
|
114
|
-
"path",
|
|
115
|
-
"pattern",
|
|
116
|
-
"polygon",
|
|
117
|
-
"polyline",
|
|
118
|
-
"radialGradient",
|
|
119
|
-
"rect",
|
|
120
|
-
"stop",
|
|
121
|
-
"symbol",
|
|
122
|
-
"text",
|
|
123
|
-
"use"
|
|
124
|
-
];
|
|
125
|
-
|
|
126
|
-
// src/jsx/shared.ts
|
|
107
|
+
// src/shared.ts
|
|
127
108
|
var import_core2 = require("@babel/core");
|
|
128
109
|
function hasSiblingElement(path) {
|
|
129
110
|
const siblings = path.getAllPrevSiblings().concat(path.getAllNextSiblings());
|
|
@@ -180,363 +161,126 @@ function setNodeText(path, text) {
|
|
|
180
161
|
}
|
|
181
162
|
}
|
|
182
163
|
}
|
|
183
|
-
|
|
184
|
-
// src/jsx/server.ts
|
|
185
|
-
function transformJSXService(path) {
|
|
186
|
-
const result = {
|
|
187
|
-
index: 0,
|
|
188
|
-
isLastChild: false,
|
|
189
|
-
parentIndex: 0,
|
|
190
|
-
props: {},
|
|
191
|
-
template: []
|
|
192
|
-
// 修改为数组
|
|
193
|
-
};
|
|
194
|
-
transformJSXServiceElement(path, result, true);
|
|
195
|
-
path.replaceWith(createEssorNode(path, result));
|
|
196
|
-
}
|
|
197
|
-
function createEssorNode(path, result) {
|
|
198
|
-
var _a;
|
|
164
|
+
function isSymbolStart(path, name) {
|
|
199
165
|
const state = path.state;
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
tmpl = import_core3.types.identifier(getTagName(path.node));
|
|
203
|
-
} else {
|
|
204
|
-
tmpl = path.scope.generateUidIdentifier("_tmpl$");
|
|
205
|
-
const template = import_core3.types.arrayExpression(result.template.map(import_core3.types.stringLiteral));
|
|
206
|
-
const declarator = import_core3.types.variableDeclarator(tmpl, template);
|
|
207
|
-
state.tmplDeclaration.declarations.push(declarator);
|
|
208
|
-
}
|
|
209
|
-
const args = [tmpl, createProps(result.props)];
|
|
210
|
-
const key = result.props.key || ((_a = result.props[0]) == null ? void 0 : _a.key);
|
|
211
|
-
if (key) {
|
|
212
|
-
args.push(key);
|
|
213
|
-
}
|
|
214
|
-
imports.add("renderTemplate");
|
|
215
|
-
return import_core3.types.callExpression(state.renderTemplate, args);
|
|
216
|
-
}
|
|
217
|
-
function createProps(props) {
|
|
218
|
-
const result = [];
|
|
219
|
-
for (const prop in props) {
|
|
220
|
-
let value = props[prop];
|
|
221
|
-
if (prop === "key") {
|
|
222
|
-
continue;
|
|
223
|
-
}
|
|
224
|
-
if (Array.isArray(value)) {
|
|
225
|
-
value = import_core3.types.arrayExpression(value);
|
|
226
|
-
}
|
|
227
|
-
if (typeof value === "object" && value !== null && !import_core3.types.isNode(value)) {
|
|
228
|
-
value = createProps(value);
|
|
229
|
-
}
|
|
230
|
-
if (typeof value === "string") {
|
|
231
|
-
value = import_core3.types.stringLiteral(value);
|
|
232
|
-
}
|
|
233
|
-
if (typeof value === "number") {
|
|
234
|
-
value = import_core3.types.numericLiteral(value);
|
|
235
|
-
}
|
|
236
|
-
if (typeof value === "boolean") {
|
|
237
|
-
value = import_core3.types.booleanLiteral(value);
|
|
238
|
-
}
|
|
239
|
-
if (value === void 0) {
|
|
240
|
-
value = import_core3.types.tsUndefinedKeyword();
|
|
241
|
-
}
|
|
242
|
-
if (value === null) {
|
|
243
|
-
value = import_core3.types.nullLiteral();
|
|
244
|
-
}
|
|
245
|
-
if (prop === "_$spread$") {
|
|
246
|
-
result.push(import_core3.types.spreadElement(value));
|
|
247
|
-
} else {
|
|
248
|
-
result.push(import_core3.types.objectProperty(import_core3.types.stringLiteral(prop), value));
|
|
249
|
-
}
|
|
250
|
-
}
|
|
251
|
-
return import_core3.types.objectExpression(result);
|
|
252
|
-
}
|
|
253
|
-
function transformJSXServiceElement(path, result, isRoot = false) {
|
|
254
|
-
if (path.isJSXElement()) {
|
|
255
|
-
const tagName = getTagName(path.node);
|
|
256
|
-
const tagIsComponent = isComponent(tagName);
|
|
257
|
-
const isSelfClose = !tagIsComponent && selfClosingTags.includes(tagName);
|
|
258
|
-
const isSvg = svgTags.includes(tagName) && result.index === 1;
|
|
259
|
-
const { props, hasExpression } = getAttrProps(path);
|
|
260
|
-
if (tagIsComponent) {
|
|
261
|
-
if (isRoot) {
|
|
262
|
-
result.props = props;
|
|
263
|
-
const children = getChildren(path);
|
|
264
|
-
if (children.length > 0) {
|
|
265
|
-
const childrenGenerator = children.length === 1 ? children[0] : import_core3.types.arrayExpression(children);
|
|
266
|
-
result.props.children = childrenGenerator;
|
|
267
|
-
}
|
|
268
|
-
} else {
|
|
269
|
-
transformJSXService(path);
|
|
270
|
-
replaceChild(path.node, result);
|
|
271
|
-
}
|
|
272
|
-
} else {
|
|
273
|
-
if (isSvg) {
|
|
274
|
-
result.template.push("<svg _svg_>");
|
|
275
|
-
}
|
|
276
|
-
result.template.push(`<${tagName}`);
|
|
277
|
-
handleAttributes(props, result);
|
|
278
|
-
if (hasExpression) {
|
|
279
|
-
result.template.push(isSelfClose ? "/>" : ">");
|
|
280
|
-
result.props || (result.props = {});
|
|
281
|
-
} else {
|
|
282
|
-
result.template[result.template.length - 1] += isSelfClose ? "/>" : ">";
|
|
283
|
-
}
|
|
284
|
-
transformChildren(path, result);
|
|
285
|
-
if (!isSelfClose) {
|
|
286
|
-
result.template.push(`</${tagName}>`);
|
|
287
|
-
}
|
|
288
|
-
}
|
|
289
|
-
} else {
|
|
290
|
-
result.index--;
|
|
291
|
-
transformChildren(path, result);
|
|
292
|
-
}
|
|
166
|
+
const { symbol } = state.opts;
|
|
167
|
+
return startsWith(name, symbol);
|
|
293
168
|
}
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
169
|
+
|
|
170
|
+
// src/jsx/constants.ts
|
|
171
|
+
var selfClosingTags = [
|
|
172
|
+
"area",
|
|
173
|
+
"base",
|
|
174
|
+
"br",
|
|
175
|
+
"col",
|
|
176
|
+
"embed",
|
|
177
|
+
"hr",
|
|
178
|
+
"img",
|
|
179
|
+
"input",
|
|
180
|
+
"link",
|
|
181
|
+
"meta",
|
|
182
|
+
"param",
|
|
183
|
+
"source",
|
|
184
|
+
"track",
|
|
185
|
+
"wbr"
|
|
186
|
+
];
|
|
187
|
+
var svgTags = [
|
|
188
|
+
"circle",
|
|
189
|
+
"clipPath",
|
|
190
|
+
"defs",
|
|
191
|
+
"ellipse",
|
|
192
|
+
"filter",
|
|
193
|
+
"g",
|
|
194
|
+
"line",
|
|
195
|
+
"linearGradient",
|
|
196
|
+
"mask",
|
|
197
|
+
"path",
|
|
198
|
+
"pattern",
|
|
199
|
+
"polygon",
|
|
200
|
+
"polyline",
|
|
201
|
+
"radialGradient",
|
|
202
|
+
"rect",
|
|
203
|
+
"stop",
|
|
204
|
+
"symbol",
|
|
205
|
+
"text",
|
|
206
|
+
"use"
|
|
207
|
+
];
|
|
208
|
+
|
|
209
|
+
// src/jsx/index.ts
|
|
210
|
+
var isSsg = false;
|
|
211
|
+
function addToTemplate(result, content) {
|
|
212
|
+
if (isSsg) {
|
|
213
|
+
result.template.push(content);
|
|
327
214
|
} else {
|
|
328
|
-
|
|
329
|
-
}
|
|
330
|
-
}
|
|
331
|
-
function getNodeText(path) {
|
|
332
|
-
if (path.isJSXText()) {
|
|
333
|
-
return path.node.value;
|
|
334
|
-
}
|
|
335
|
-
if (path.isJSXExpressionContainer()) {
|
|
336
|
-
const expression = path.get("expression");
|
|
337
|
-
if (expression.isStringLiteral() || expression.isNumericLiteral()) {
|
|
338
|
-
return String(expression.node.value);
|
|
339
|
-
}
|
|
340
|
-
}
|
|
341
|
-
return "";
|
|
342
|
-
}
|
|
343
|
-
function handleAttributes(props, result) {
|
|
344
|
-
let klass = "";
|
|
345
|
-
let style = "";
|
|
346
|
-
for (const prop in props) {
|
|
347
|
-
const value = props[prop];
|
|
348
|
-
if (prop === "class" && typeof value === "string") {
|
|
349
|
-
klass += ` ${value}`;
|
|
350
|
-
delete props[prop];
|
|
351
|
-
continue;
|
|
352
|
-
}
|
|
353
|
-
if (prop === "style" && typeof value === "string") {
|
|
354
|
-
style += `${value}${value.at(-1) === ";" ? "" : ";"}`;
|
|
355
|
-
delete props[prop];
|
|
356
|
-
continue;
|
|
357
|
-
}
|
|
358
|
-
if (value === true) {
|
|
359
|
-
result.template[result.template.length - 1] += ` ${prop}`;
|
|
360
|
-
delete props[prop];
|
|
361
|
-
}
|
|
362
|
-
if (value === false) {
|
|
363
|
-
delete props[prop];
|
|
364
|
-
}
|
|
365
|
-
if (typeof value === "string" || typeof value === "number") {
|
|
366
|
-
result.template[result.template.length - 1] += ` ${prop}="${value}"`;
|
|
367
|
-
delete props[prop];
|
|
368
|
-
}
|
|
369
|
-
}
|
|
370
|
-
if (Object.keys(props).length > 0) {
|
|
371
|
-
result.props[result.index] = props;
|
|
372
|
-
}
|
|
373
|
-
klass = klass.trim();
|
|
374
|
-
style = style.trim();
|
|
375
|
-
if (klass) {
|
|
376
|
-
result.template[result.template.length - 1] += ` class="${klass}"`;
|
|
377
|
-
}
|
|
378
|
-
if (style) {
|
|
379
|
-
result.template[result.template.length - 1] += ` style="${style}"`;
|
|
380
|
-
}
|
|
381
|
-
}
|
|
382
|
-
function replaceChild(node, result) {
|
|
383
|
-
var _a, _b, _c, _d, _e;
|
|
384
|
-
if (result.isLastChild) {
|
|
385
|
-
result.index--;
|
|
386
|
-
}
|
|
387
|
-
(_c = (_a = result.props)[_b = result.parentIndex]) != null ? _c : _a[_b] = {};
|
|
388
|
-
(_e = (_d = result.props[result.parentIndex]).children) != null ? _e : _d.children = [];
|
|
389
|
-
result.props[result.parentIndex].children.push(
|
|
390
|
-
import_core3.types.arrayExpression([
|
|
391
|
-
import_core3.types.arrowFunctionExpression([], node),
|
|
392
|
-
import_core3.types.identifier(String(result.template.length))
|
|
393
|
-
])
|
|
394
|
-
);
|
|
395
|
-
}
|
|
396
|
-
function getChildren(path) {
|
|
397
|
-
return path.get("children").filter((child) => isValidChild(child)).map((child) => {
|
|
398
|
-
if (child.isJSXElement() || child.isJSXFragment()) {
|
|
399
|
-
transformJSXService(child);
|
|
400
|
-
} else if (child.isJSXExpressionContainer()) {
|
|
401
|
-
child.replaceWith(child.get("expression"));
|
|
402
|
-
} else if (child.isJSXText()) {
|
|
403
|
-
child.replaceWith(import_core3.types.stringLiteral(child.node.value));
|
|
404
|
-
} else {
|
|
405
|
-
throw new Error("Unsupported child type");
|
|
406
|
-
}
|
|
407
|
-
return child.node;
|
|
408
|
-
});
|
|
409
|
-
}
|
|
410
|
-
function isValidChild(path) {
|
|
411
|
-
const regex = /^\s*$/;
|
|
412
|
-
if (path.isStringLiteral() || path.isJSXText()) {
|
|
413
|
-
return !regex.test(path.node.value);
|
|
215
|
+
result.template += content;
|
|
414
216
|
}
|
|
415
|
-
return Object.keys(path.node).length > 0;
|
|
416
|
-
}
|
|
417
|
-
function getAttrProps(path) {
|
|
418
|
-
const props = {};
|
|
419
|
-
let hasExpression = false;
|
|
420
|
-
path.get("openingElement").get("attributes").forEach((attribute) => {
|
|
421
|
-
if (attribute.isJSXAttribute()) {
|
|
422
|
-
const name = getAttrName(attribute.node);
|
|
423
|
-
const value = attribute.get("value");
|
|
424
|
-
if (!value.node) {
|
|
425
|
-
props[name] = true;
|
|
426
|
-
} else if (value.isStringLiteral()) {
|
|
427
|
-
props[name] = value.node.value;
|
|
428
|
-
} else {
|
|
429
|
-
if (value.isJSXExpressionContainer()) {
|
|
430
|
-
const expression = value.get("expression");
|
|
431
|
-
if (expression.isStringLiteral()) {
|
|
432
|
-
props[name] = expression.node.value;
|
|
433
|
-
} else if (expression.isNumericLiteral()) {
|
|
434
|
-
props[name] = expression.node.value;
|
|
435
|
-
} else if (expression.isJSXElement() || expression.isJSXFragment()) {
|
|
436
|
-
transformJSXService(expression);
|
|
437
|
-
props[name] = expression.node;
|
|
438
|
-
} else if (expression.isExpression()) {
|
|
439
|
-
hasExpression = true;
|
|
440
|
-
if (/^key|ref|on.+$/.test(name)) {
|
|
441
|
-
props[name] = expression.node;
|
|
442
|
-
} else if (/^bind:.+/.test(name)) {
|
|
443
|
-
const value2 = path.scope.generateUidIdentifier("value");
|
|
444
|
-
const bindName = name.slice(5).toLocaleLowerCase();
|
|
445
|
-
props[bindName] = expression.node;
|
|
446
|
-
props[`update${capitalizeFirstLetter(bindName)}`] = import_core3.types.arrowFunctionExpression(
|
|
447
|
-
[value2],
|
|
448
|
-
import_core3.types.assignmentExpression("=", expression.node, value2)
|
|
449
|
-
);
|
|
450
|
-
} else {
|
|
451
|
-
if (expression.isConditionalExpression()) {
|
|
452
|
-
props[name] = import_core3.types.arrowFunctionExpression([], expression.node);
|
|
453
|
-
} else {
|
|
454
|
-
props[name] = expression.node;
|
|
455
|
-
}
|
|
456
|
-
}
|
|
457
|
-
}
|
|
458
|
-
} else if (value.isJSXElement() || value.isJSXFragment()) {
|
|
459
|
-
transformJSXService(value);
|
|
460
|
-
props[name] = value.node;
|
|
461
|
-
}
|
|
462
|
-
}
|
|
463
|
-
} else if (attribute.isJSXSpreadAttribute()) {
|
|
464
|
-
props._$spread$ = attribute.get("argument").node;
|
|
465
|
-
hasExpression = true;
|
|
466
|
-
} else {
|
|
467
|
-
throw new Error("Unsupported attribute type");
|
|
468
|
-
}
|
|
469
|
-
});
|
|
470
|
-
return {
|
|
471
|
-
props,
|
|
472
|
-
hasExpression
|
|
473
|
-
};
|
|
474
217
|
}
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
function transformJSXClient(path) {
|
|
218
|
+
function transformJSX(path) {
|
|
219
|
+
const state = path.state;
|
|
220
|
+
isSsg = state.opts.ssg;
|
|
479
221
|
const result = {
|
|
480
222
|
index: 1,
|
|
481
223
|
isLastChild: false,
|
|
482
224
|
parentIndex: 0,
|
|
483
225
|
props: {},
|
|
484
|
-
template: ""
|
|
226
|
+
template: isSsg ? [] : ""
|
|
485
227
|
};
|
|
486
228
|
transformJSXElement(path, result, true);
|
|
487
|
-
path.replaceWith(
|
|
229
|
+
path.replaceWith(createEssorNode(path, result));
|
|
488
230
|
}
|
|
489
|
-
function
|
|
231
|
+
function createEssorNode(path, result) {
|
|
490
232
|
var _a;
|
|
491
233
|
const state = path.state;
|
|
492
234
|
let tmpl;
|
|
493
235
|
if (path.isJSXElement() && isComponent(getTagName(path.node))) {
|
|
494
|
-
tmpl =
|
|
236
|
+
tmpl = import_core3.types.identifier(getTagName(path.node));
|
|
495
237
|
} else {
|
|
496
238
|
tmpl = path.scope.generateUidIdentifier("_tmpl$");
|
|
497
|
-
const template =
|
|
498
|
-
const declarator =
|
|
239
|
+
const template = isSsg ? import_core3.types.arrayExpression(result.template.map(import_core3.types.stringLiteral)) : import_core3.types.callExpression(state.template, [import_core3.types.stringLiteral(result.template)]);
|
|
240
|
+
const declarator = import_core3.types.variableDeclarator(tmpl, template);
|
|
499
241
|
state.tmplDeclaration.declarations.push(declarator);
|
|
500
|
-
|
|
242
|
+
if (!isSsg) {
|
|
243
|
+
imports.add("template");
|
|
244
|
+
}
|
|
501
245
|
}
|
|
502
|
-
const args = [tmpl,
|
|
246
|
+
const args = [tmpl, createProps(result.props)];
|
|
503
247
|
const key = result.props.key || ((_a = result.props[0]) == null ? void 0 : _a.key);
|
|
504
248
|
if (key) {
|
|
505
249
|
args.push(key);
|
|
506
250
|
}
|
|
507
|
-
imports.add("h");
|
|
508
|
-
return
|
|
251
|
+
imports.add(isSsg ? "renderTemplate" : "h");
|
|
252
|
+
return import_core3.types.callExpression(isSsg ? state.renderTemplate : state.h, args);
|
|
509
253
|
}
|
|
510
|
-
function
|
|
254
|
+
function createProps(props) {
|
|
511
255
|
const toAstNode = (value) => {
|
|
512
256
|
if (Array.isArray(value)) {
|
|
513
|
-
return
|
|
257
|
+
return import_core3.types.arrayExpression(value.map(toAstNode));
|
|
514
258
|
}
|
|
515
|
-
if (value && typeof value === "object" && !
|
|
516
|
-
return
|
|
259
|
+
if (value && typeof value === "object" && !import_core3.types.isNode(value)) {
|
|
260
|
+
return createProps(value);
|
|
517
261
|
}
|
|
518
262
|
switch (typeof value) {
|
|
519
263
|
case "string":
|
|
520
|
-
return
|
|
264
|
+
return import_core3.types.stringLiteral(value);
|
|
521
265
|
case "number":
|
|
522
|
-
return
|
|
266
|
+
return import_core3.types.numericLiteral(value);
|
|
523
267
|
case "boolean":
|
|
524
|
-
return
|
|
268
|
+
return import_core3.types.booleanLiteral(value);
|
|
525
269
|
case "undefined":
|
|
526
|
-
return
|
|
270
|
+
return import_core3.types.tsUndefinedKeyword();
|
|
527
271
|
case void 0:
|
|
528
|
-
return
|
|
272
|
+
return import_core3.types.tsUndefinedKeyword();
|
|
529
273
|
case null:
|
|
530
|
-
return
|
|
274
|
+
return import_core3.types.nullLiteral();
|
|
531
275
|
default:
|
|
532
276
|
return value;
|
|
533
277
|
}
|
|
534
278
|
};
|
|
535
279
|
const result = Object.keys(props).filter((prop) => prop !== "key").map((prop) => {
|
|
536
280
|
const value = toAstNode(props[prop]);
|
|
537
|
-
return prop === "_$spread$" ?
|
|
281
|
+
return prop === "_$spread$" ? import_core3.types.spreadElement(value) : import_core3.types.objectProperty(import_core3.types.stringLiteral(prop), value);
|
|
538
282
|
});
|
|
539
|
-
return
|
|
283
|
+
return import_core3.types.objectExpression(result);
|
|
540
284
|
}
|
|
541
285
|
function transformJSXElement(path, result, isRoot = false) {
|
|
542
286
|
if (path.isJSXElement()) {
|
|
@@ -544,45 +288,45 @@ function transformJSXElement(path, result, isRoot = false) {
|
|
|
544
288
|
const tagIsComponent = isComponent(tagName);
|
|
545
289
|
const isSelfClose = !tagIsComponent && selfClosingTags.includes(tagName);
|
|
546
290
|
const isSvg = svgTags.includes(tagName) && result.index === 1;
|
|
547
|
-
const props =
|
|
291
|
+
const props = getAttrProps(path);
|
|
548
292
|
if (tagIsComponent) {
|
|
549
293
|
if (isRoot) {
|
|
550
294
|
result.props = props;
|
|
551
|
-
const children =
|
|
295
|
+
const children = getChildren(path);
|
|
552
296
|
if (children.length > 0) {
|
|
553
|
-
const childrenGenerator = children.length === 1 ? children[0] :
|
|
297
|
+
const childrenGenerator = children.length === 1 ? children[0] : import_core3.types.arrayExpression(children);
|
|
554
298
|
result.props.children = childrenGenerator;
|
|
555
299
|
}
|
|
556
300
|
} else {
|
|
557
|
-
|
|
558
|
-
|
|
301
|
+
transformJSX(path);
|
|
302
|
+
replaceChild(path.node, result);
|
|
559
303
|
}
|
|
560
304
|
} else {
|
|
561
305
|
if (isSvg) {
|
|
562
|
-
result.template = "<svg _svg_>";
|
|
306
|
+
result.template = isSsg ? ["<svg _svg_>"] : "<svg _svg_>";
|
|
563
307
|
}
|
|
564
|
-
result
|
|
565
|
-
|
|
566
|
-
result
|
|
308
|
+
addToTemplate(result, `<${tagName}`);
|
|
309
|
+
handleAttributes(props, result);
|
|
310
|
+
addToTemplate(result, isSelfClose ? "/>" : ">");
|
|
567
311
|
if (!isSelfClose) {
|
|
568
|
-
|
|
312
|
+
transformChildren(path, result);
|
|
569
313
|
if (hasSiblingElement(path)) {
|
|
570
|
-
result
|
|
314
|
+
addToTemplate(result, `</${tagName}>`);
|
|
571
315
|
}
|
|
572
316
|
}
|
|
573
317
|
}
|
|
574
318
|
} else {
|
|
575
319
|
result.index--;
|
|
576
|
-
|
|
320
|
+
transformChildren(path, result);
|
|
577
321
|
}
|
|
578
322
|
}
|
|
579
|
-
function
|
|
580
|
-
const parentIndex = result.index;
|
|
323
|
+
function transformChildren(path, result) {
|
|
324
|
+
const parentIndex = isSsg ? result.template.length : result.index;
|
|
581
325
|
path.get("children").reduce((pre, cur) => {
|
|
582
|
-
if (
|
|
326
|
+
if (isValidChild(cur)) {
|
|
583
327
|
const lastChild = pre.at(-1);
|
|
584
328
|
if (lastChild && isTextChild(cur) && isTextChild(lastChild)) {
|
|
585
|
-
setNodeText(lastChild,
|
|
329
|
+
setNodeText(lastChild, getNodeText(lastChild) + getNodeText(cur));
|
|
586
330
|
} else {
|
|
587
331
|
pre.push(cur);
|
|
588
332
|
}
|
|
@@ -591,30 +335,30 @@ function transformChildren2(path, result) {
|
|
|
591
335
|
}, []).forEach((child, i, arr) => {
|
|
592
336
|
result.parentIndex = parentIndex;
|
|
593
337
|
result.isLastChild = i === arr.length - 1;
|
|
594
|
-
|
|
338
|
+
transformChild(child, result);
|
|
595
339
|
});
|
|
596
340
|
}
|
|
597
|
-
function
|
|
341
|
+
function transformChild(child, result) {
|
|
598
342
|
result.index++;
|
|
599
343
|
if (child.isJSXElement() || child.isJSXFragment()) {
|
|
600
344
|
transformJSXElement(child, result, false);
|
|
601
345
|
} else if (child.isJSXExpressionContainer()) {
|
|
602
346
|
const expression = child.get("expression");
|
|
603
347
|
if (expression.isStringLiteral() || expression.isNumericLiteral()) {
|
|
604
|
-
result
|
|
348
|
+
addToTemplate(result, String(expression.node.value));
|
|
605
349
|
} else if (expression.isExpression()) {
|
|
606
|
-
|
|
607
|
-
} else if (
|
|
350
|
+
replaceChild(expression.node, result);
|
|
351
|
+
} else if (import_core3.types.isJSXEmptyExpression(expression.node)) {
|
|
608
352
|
} else {
|
|
609
353
|
throw new Error("Unsupported child type");
|
|
610
354
|
}
|
|
611
355
|
} else if (child.isJSXText()) {
|
|
612
|
-
result
|
|
356
|
+
addToTemplate(result, String(child.node.value));
|
|
613
357
|
} else {
|
|
614
358
|
throw new Error("Unsupported child type");
|
|
615
359
|
}
|
|
616
360
|
}
|
|
617
|
-
function
|
|
361
|
+
function getNodeText(path) {
|
|
618
362
|
if (path.isJSXText()) {
|
|
619
363
|
return path.node.value;
|
|
620
364
|
}
|
|
@@ -626,7 +370,7 @@ function getNodeText2(path) {
|
|
|
626
370
|
}
|
|
627
371
|
return "";
|
|
628
372
|
}
|
|
629
|
-
function
|
|
373
|
+
function handleAttributes(props, result) {
|
|
630
374
|
let klass = "";
|
|
631
375
|
let style = "";
|
|
632
376
|
for (const prop in props) {
|
|
@@ -642,32 +386,41 @@ function handleAttributes2(props, result) {
|
|
|
642
386
|
continue;
|
|
643
387
|
}
|
|
644
388
|
if (value === true) {
|
|
645
|
-
result
|
|
389
|
+
addToTemplate(result, ` ${prop}`);
|
|
646
390
|
delete props[prop];
|
|
647
391
|
}
|
|
648
392
|
if (value === false) {
|
|
649
393
|
delete props[prop];
|
|
650
394
|
}
|
|
651
395
|
if (typeof value === "string" || typeof value === "number") {
|
|
652
|
-
result
|
|
396
|
+
addToTemplate(result, ` ${prop}="${value}"`);
|
|
653
397
|
delete props[prop];
|
|
654
398
|
}
|
|
655
|
-
if (
|
|
399
|
+
if (import_core3.types.isConditionalExpression(value)) {
|
|
656
400
|
const { test, consequent, alternate } = value;
|
|
657
|
-
value =
|
|
401
|
+
value = import_core3.types.arrowFunctionExpression([], import_core3.types.conditionalExpression(test, consequent, alternate));
|
|
658
402
|
props[prop] = value;
|
|
659
403
|
}
|
|
660
|
-
if (
|
|
404
|
+
if (import_core3.types.isObjectExpression(value)) {
|
|
661
405
|
let hasConditional = false;
|
|
662
406
|
value.properties.forEach((property) => {
|
|
663
|
-
if (
|
|
407
|
+
if (import_core3.types.isObjectProperty(property) && import_core3.types.isConditionalExpression(property.value)) {
|
|
664
408
|
hasConditional = true;
|
|
665
409
|
}
|
|
666
410
|
});
|
|
667
411
|
if (hasConditional) {
|
|
668
|
-
value =
|
|
412
|
+
value = import_core3.types.arrowFunctionExpression([], value);
|
|
413
|
+
props[prop] = value;
|
|
414
|
+
} else {
|
|
415
|
+
if (prop === "style") {
|
|
416
|
+
value.properties.forEach((property) => {
|
|
417
|
+
if (import_core3.types.isObjectProperty(property)) {
|
|
418
|
+
style += `${property.key.name}:${property.value.value};`;
|
|
419
|
+
}
|
|
420
|
+
});
|
|
421
|
+
delete props[prop];
|
|
422
|
+
}
|
|
669
423
|
}
|
|
670
|
-
props[prop] = value;
|
|
671
424
|
}
|
|
672
425
|
}
|
|
673
426
|
if (Object.keys(props).length > 0) {
|
|
@@ -676,50 +429,50 @@ function handleAttributes2(props, result) {
|
|
|
676
429
|
klass = klass.trim();
|
|
677
430
|
style = style.trim();
|
|
678
431
|
if (klass) {
|
|
679
|
-
result
|
|
432
|
+
addToTemplate(result, ` class="${klass}"`);
|
|
680
433
|
}
|
|
681
434
|
if (style) {
|
|
682
|
-
result
|
|
435
|
+
addToTemplate(result, ` style="${style}"`);
|
|
683
436
|
}
|
|
684
437
|
}
|
|
685
|
-
function
|
|
438
|
+
function replaceChild(node, result) {
|
|
686
439
|
var _a, _b, _c, _d, _e;
|
|
687
440
|
if (result.isLastChild) {
|
|
688
441
|
result.index--;
|
|
689
442
|
} else {
|
|
690
|
-
result
|
|
443
|
+
addToTemplate(result, "<!>");
|
|
691
444
|
}
|
|
692
445
|
(_c = (_a = result.props)[_b = result.parentIndex]) != null ? _c : _a[_b] = {};
|
|
693
446
|
(_e = (_d = result.props[result.parentIndex]).children) != null ? _e : _d.children = [];
|
|
694
447
|
result.props[result.parentIndex].children.push(
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
result.isLastChild ?
|
|
448
|
+
import_core3.types.arrayExpression([
|
|
449
|
+
import_core3.types.arrowFunctionExpression([], node),
|
|
450
|
+
result.isLastChild ? import_core3.types.nullLiteral() : import_core3.types.identifier(String(result.index))
|
|
698
451
|
])
|
|
699
452
|
);
|
|
700
453
|
}
|
|
701
|
-
function
|
|
702
|
-
return path.get("children").filter((child) =>
|
|
454
|
+
function getChildren(path) {
|
|
455
|
+
return path.get("children").filter((child) => isValidChild(child)).map((child) => {
|
|
703
456
|
if (child.isJSXElement() || child.isJSXFragment()) {
|
|
704
|
-
|
|
457
|
+
transformJSX(child);
|
|
705
458
|
} else if (child.isJSXExpressionContainer()) {
|
|
706
459
|
child.replaceWith(child.get("expression"));
|
|
707
460
|
} else if (child.isJSXText()) {
|
|
708
|
-
child.replaceWith(
|
|
461
|
+
child.replaceWith(import_core3.types.stringLiteral(child.node.value));
|
|
709
462
|
} else {
|
|
710
463
|
throw new Error("Unsupported child type");
|
|
711
464
|
}
|
|
712
465
|
return child.node;
|
|
713
466
|
});
|
|
714
467
|
}
|
|
715
|
-
function
|
|
468
|
+
function isValidChild(path) {
|
|
716
469
|
const regex = /^\s*$/;
|
|
717
470
|
if (path.isStringLiteral() || path.isJSXText()) {
|
|
718
471
|
return !regex.test(path.node.value);
|
|
719
472
|
}
|
|
720
473
|
return Object.keys(path.node).length > 0;
|
|
721
474
|
}
|
|
722
|
-
function
|
|
475
|
+
function getAttrProps(path) {
|
|
723
476
|
const props = {};
|
|
724
477
|
path.get("openingElement").get("attributes").forEach((attribute) => {
|
|
725
478
|
if (attribute.isJSXAttribute()) {
|
|
@@ -737,7 +490,7 @@ function getAttrProps2(path) {
|
|
|
737
490
|
} else if (expression.isNumericLiteral()) {
|
|
738
491
|
props[name] = expression.node.value;
|
|
739
492
|
} else if (expression.isJSXElement() || expression.isJSXFragment()) {
|
|
740
|
-
|
|
493
|
+
transformJSX(expression);
|
|
741
494
|
props[name] = expression.node;
|
|
742
495
|
} else if (expression.isExpression()) {
|
|
743
496
|
if (/^key|ref|on.+$/.test(name)) {
|
|
@@ -746,20 +499,20 @@ function getAttrProps2(path) {
|
|
|
746
499
|
const value2 = path.scope.generateUidIdentifier("value");
|
|
747
500
|
const bindName = name.slice(5).toLocaleLowerCase();
|
|
748
501
|
props[bindName] = expression.node;
|
|
749
|
-
props[`update${capitalizeFirstLetter(bindName)}`] =
|
|
502
|
+
props[`update${capitalizeFirstLetter(bindName)}`] = import_core3.types.arrowFunctionExpression(
|
|
750
503
|
[value2],
|
|
751
|
-
|
|
504
|
+
import_core3.types.assignmentExpression("=", expression.node, value2)
|
|
752
505
|
);
|
|
753
506
|
} else {
|
|
754
507
|
if (expression.isConditionalExpression()) {
|
|
755
|
-
props[name] =
|
|
508
|
+
props[name] = import_core3.types.arrowFunctionExpression([], expression.node);
|
|
756
509
|
} else {
|
|
757
510
|
props[name] = expression.node;
|
|
758
511
|
}
|
|
759
512
|
}
|
|
760
513
|
}
|
|
761
514
|
} else if (value.isJSXElement() || value.isJSXFragment()) {
|
|
762
|
-
|
|
515
|
+
transformJSX(value);
|
|
763
516
|
props[name] = value.node;
|
|
764
517
|
}
|
|
765
518
|
}
|
|
@@ -772,41 +525,34 @@ function getAttrProps2(path) {
|
|
|
772
525
|
return props;
|
|
773
526
|
}
|
|
774
527
|
|
|
775
|
-
// src/jsx/index.ts
|
|
776
|
-
function transformJSX(path) {
|
|
777
|
-
const state = path.state;
|
|
778
|
-
const isSsg = state.opts.ssg;
|
|
779
|
-
return isSsg ? transformJSXService(path) : transformJSXClient(path);
|
|
780
|
-
}
|
|
781
|
-
|
|
782
528
|
// src/signal/symbol.ts
|
|
783
|
-
var
|
|
529
|
+
var import_core4 = require("@babel/core");
|
|
784
530
|
function replaceSymbol(path) {
|
|
785
531
|
const init = path.node.init;
|
|
786
532
|
const variableName = path.node.id.name;
|
|
787
|
-
if (
|
|
533
|
+
if (import_core4.types.isObjectPattern(path.node.id) || import_core4.types.isArrayPattern(path.node.id)) {
|
|
788
534
|
return;
|
|
789
535
|
}
|
|
790
|
-
if (!
|
|
536
|
+
if (!isSymbolStart(path, variableName)) {
|
|
791
537
|
return;
|
|
792
538
|
}
|
|
793
|
-
if (init && (
|
|
794
|
-
const newInit =
|
|
539
|
+
if (init && (import_core4.types.isFunctionExpression(init) || import_core4.types.isArrowFunctionExpression(init)) && path.parent.kind === "const") {
|
|
540
|
+
const newInit = import_core4.types.callExpression(import_core4.types.identifier(path.state.useComputed.name), init ? [init] : []);
|
|
795
541
|
imports.add("useComputed");
|
|
796
542
|
path.node.init = newInit;
|
|
797
543
|
} else {
|
|
798
|
-
const newInit =
|
|
544
|
+
const newInit = import_core4.types.callExpression(import_core4.types.identifier(path.state.useSignal.name), init ? [init] : []);
|
|
799
545
|
imports.add("useSignal");
|
|
800
546
|
path.node.init = newInit;
|
|
801
547
|
}
|
|
802
548
|
}
|
|
803
549
|
function symbolIdentifier(path) {
|
|
804
550
|
const parentPath = path.parentPath;
|
|
805
|
-
if (!parentPath ||
|
|
551
|
+
if (!parentPath || import_core4.types.isVariableDeclarator(parentPath) || import_core4.types.isImportSpecifier(parentPath) || import_core4.types.isObjectProperty(parentPath) || import_core4.types.isArrayPattern(parentPath) || import_core4.types.isObjectPattern(parentPath)) {
|
|
806
552
|
return;
|
|
807
553
|
}
|
|
808
554
|
const { node } = path;
|
|
809
|
-
if (node.name
|
|
555
|
+
if (isSymbolStart(path, node.name)) {
|
|
810
556
|
let currentPath = path;
|
|
811
557
|
while (currentPath.parentPath && !currentPath.parentPath.isProgram()) {
|
|
812
558
|
if (currentPath.parentPath.isMemberExpression() && currentPath.parentPath.node.property.name === "value") {
|
|
@@ -814,27 +560,27 @@ function symbolIdentifier(path) {
|
|
|
814
560
|
}
|
|
815
561
|
currentPath = currentPath.parentPath;
|
|
816
562
|
}
|
|
817
|
-
const newNode =
|
|
563
|
+
const newNode = import_core4.types.memberExpression(import_core4.types.identifier(node.name), import_core4.types.identifier("value"));
|
|
818
564
|
path.replaceWith(newNode);
|
|
819
565
|
}
|
|
820
566
|
}
|
|
821
567
|
function symbolObjectPattern(path) {
|
|
822
568
|
path.node.properties.forEach((property) => {
|
|
823
|
-
if (
|
|
824
|
-
const newKey =
|
|
569
|
+
if (import_core4.types.isObjectProperty(property) && import_core4.types.isIdentifier(property.key) && isSymbolStart(path, property.key.name)) {
|
|
570
|
+
const newKey = import_core4.types.identifier(property.key.name);
|
|
825
571
|
property.key = newKey;
|
|
826
572
|
}
|
|
827
573
|
});
|
|
828
574
|
}
|
|
829
575
|
function symbolArrayPattern(path) {
|
|
830
576
|
path.node.elements.forEach((element) => {
|
|
831
|
-
if (
|
|
832
|
-
const newElement =
|
|
577
|
+
if (import_core4.types.isIdentifier(element) && element.name.startsWith("$")) {
|
|
578
|
+
const newElement = import_core4.types.identifier(element.name);
|
|
833
579
|
element.name = newElement.name;
|
|
834
|
-
} else if (
|
|
580
|
+
} else if (import_core4.types.isObjectPattern(element)) {
|
|
835
581
|
element.properties.forEach((property) => {
|
|
836
|
-
if (
|
|
837
|
-
const newKey =
|
|
582
|
+
if (import_core4.types.isObjectProperty(property) && import_core4.types.isIdentifier(property.key) && isSymbolStart(path, property.key.name)) {
|
|
583
|
+
const newKey = import_core4.types.identifier(property.key.name);
|
|
838
584
|
property.key = newKey;
|
|
839
585
|
}
|
|
840
586
|
});
|
|
@@ -843,7 +589,17 @@ function symbolArrayPattern(path) {
|
|
|
843
589
|
}
|
|
844
590
|
|
|
845
591
|
// src/signal/import.ts
|
|
846
|
-
var
|
|
592
|
+
var import_core5 = require("@babel/core");
|
|
593
|
+
function replaceImportDeclaration(path) {
|
|
594
|
+
const imports2 = path.node.specifiers;
|
|
595
|
+
imports2.forEach((specifier) => {
|
|
596
|
+
const variableName = specifier.local.name;
|
|
597
|
+
if (startsWith(variableName, "$") && !isVariableUsedAsObject(path, variableName)) {
|
|
598
|
+
path.scope.rename(variableName, `${variableName}.value`);
|
|
599
|
+
specifier.local.name = `${variableName}`;
|
|
600
|
+
}
|
|
601
|
+
});
|
|
602
|
+
}
|
|
847
603
|
function isVariableUsedAsObject(path, variableName) {
|
|
848
604
|
const binding = path.scope.getBinding(variableName);
|
|
849
605
|
let isUsedObject = false;
|
|
@@ -851,30 +607,28 @@ function isVariableUsedAsObject(path, variableName) {
|
|
|
851
607
|
return isUsedObject;
|
|
852
608
|
}
|
|
853
609
|
for (const referencePath of binding.referencePaths) {
|
|
854
|
-
if (
|
|
855
|
-
|
|
610
|
+
if (import_core5.types.isMemberExpression(referencePath.parent)) {
|
|
611
|
+
const memberExprParent = referencePath.parent;
|
|
612
|
+
if (import_core5.types.isIdentifier(memberExprParent.object, { name: variableName })) {
|
|
613
|
+
const newMemberExpr = import_core5.types.memberExpression(
|
|
614
|
+
import_core5.types.memberExpression(memberExprParent.object, import_core5.types.identifier("value")),
|
|
615
|
+
memberExprParent.property
|
|
616
|
+
);
|
|
617
|
+
referencePath.parentPath.replaceWith(newMemberExpr);
|
|
618
|
+
isUsedObject = true;
|
|
619
|
+
}
|
|
856
620
|
}
|
|
857
621
|
}
|
|
858
622
|
return isUsedObject;
|
|
859
623
|
}
|
|
860
|
-
function replaceImportDeclaration(path) {
|
|
861
|
-
const imports2 = path.node.specifiers;
|
|
862
|
-
imports2.forEach((specifier) => {
|
|
863
|
-
const variableName = specifier.local.name;
|
|
864
|
-
if (startsWith(variableName, "$") && !isVariableUsedAsObject(path, variableName)) {
|
|
865
|
-
path.scope.rename(variableName, `${variableName}.value`);
|
|
866
|
-
specifier.local.name = `${variableName}`;
|
|
867
|
-
}
|
|
868
|
-
});
|
|
869
|
-
}
|
|
870
624
|
|
|
871
625
|
// src/signal/props.ts
|
|
872
|
-
var
|
|
626
|
+
var import_core6 = require("@babel/core");
|
|
873
627
|
function replaceProps(path) {
|
|
874
628
|
var _a;
|
|
875
629
|
const state = path.state;
|
|
876
630
|
const firstParam = path.node.params[0];
|
|
877
|
-
if (!firstParam || !
|
|
631
|
+
if (!firstParam || !import_core6.types.isObjectPattern(firstParam)) {
|
|
878
632
|
return;
|
|
879
633
|
}
|
|
880
634
|
const returnStatement = path.get("body").get("body").find((statement) => statement.isReturnStatement());
|
|
@@ -882,18 +636,18 @@ function replaceProps(path) {
|
|
|
882
636
|
return;
|
|
883
637
|
}
|
|
884
638
|
const returnValue = (_a = returnStatement.node) == null ? void 0 : _a.argument;
|
|
885
|
-
if (!
|
|
639
|
+
if (!import_core6.types.isJSXElement(returnValue)) {
|
|
886
640
|
return;
|
|
887
641
|
}
|
|
888
642
|
function replaceProperties(properties2, parentPath) {
|
|
889
643
|
properties2.forEach((property) => {
|
|
890
|
-
if (
|
|
644
|
+
if (import_core6.types.isObjectProperty(property)) {
|
|
891
645
|
const keyName = property.key.name;
|
|
892
|
-
if (
|
|
646
|
+
if (import_core6.types.isIdentifier(property.value)) {
|
|
893
647
|
const propertyName = property.value.name;
|
|
894
648
|
const newName = `${parentPath}${keyName}`;
|
|
895
649
|
path.scope.rename(propertyName, newName);
|
|
896
|
-
} else if (
|
|
650
|
+
} else if (import_core6.types.isObjectPattern(property.value)) {
|
|
897
651
|
replaceProperties(property.value.properties, `${parentPath}${keyName}.`);
|
|
898
652
|
}
|
|
899
653
|
}
|
|
@@ -901,10 +655,10 @@ function replaceProps(path) {
|
|
|
901
655
|
}
|
|
902
656
|
const properties = firstParam.properties;
|
|
903
657
|
replaceProperties(
|
|
904
|
-
properties.filter((property) => !
|
|
658
|
+
properties.filter((property) => !import_core6.types.isRestElement(property)),
|
|
905
659
|
"__props."
|
|
906
660
|
);
|
|
907
|
-
const notRestProperties = properties.filter((property) => !
|
|
661
|
+
const notRestProperties = properties.filter((property) => !import_core6.types.isRestElement(property));
|
|
908
662
|
const notRestNames = notRestProperties.map(
|
|
909
663
|
(property) => property.key.name
|
|
910
664
|
);
|
|
@@ -912,19 +666,19 @@ function replaceProps(path) {
|
|
|
912
666
|
console.warn("props name can not start with $");
|
|
913
667
|
return;
|
|
914
668
|
}
|
|
915
|
-
const restElement = properties.find((property) =>
|
|
916
|
-
path.node.params[0] =
|
|
669
|
+
const restElement = properties.find((property) => import_core6.types.isRestElement(property));
|
|
670
|
+
path.node.params[0] = import_core6.types.identifier("__props");
|
|
917
671
|
if (restElement) {
|
|
918
672
|
const restName = restElement.argument.name;
|
|
919
673
|
if (notRestProperties.length === 0) {
|
|
920
|
-
path.node.params[0] =
|
|
674
|
+
path.node.params[0] = import_core6.types.identifier(restName);
|
|
921
675
|
} else {
|
|
922
|
-
const restVariableDeclaration =
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
676
|
+
const restVariableDeclaration = import_core6.types.variableDeclaration("const", [
|
|
677
|
+
import_core6.types.variableDeclarator(
|
|
678
|
+
import_core6.types.identifier(restName),
|
|
679
|
+
import_core6.types.callExpression(state.useReactive, [
|
|
680
|
+
import_core6.types.identifier("__props"),
|
|
681
|
+
import_core6.types.arrayExpression(notRestNames.map((name) => import_core6.types.stringLiteral(name)))
|
|
928
682
|
])
|
|
929
683
|
)
|
|
930
684
|
]);
|
|
@@ -946,16 +700,21 @@ function src_default() {
|
|
|
946
700
|
},
|
|
947
701
|
visitor: {
|
|
948
702
|
Program: transformProgram,
|
|
949
|
-
JSXElement: transformJSX,
|
|
950
|
-
JSXFragment: transformJSX,
|
|
951
703
|
FunctionDeclaration: replaceProps,
|
|
952
704
|
ArrowFunctionExpression: replaceProps,
|
|
953
705
|
VariableDeclarator: replaceSymbol,
|
|
954
706
|
ImportDeclaration: replaceImportDeclaration,
|
|
955
707
|
Identifier: symbolIdentifier,
|
|
956
708
|
ObjectPattern: symbolObjectPattern,
|
|
957
|
-
ArrayPattern: symbolArrayPattern
|
|
709
|
+
ArrayPattern: symbolArrayPattern,
|
|
710
|
+
JSXElement: transformJSX,
|
|
711
|
+
JSXFragment: transformJSX
|
|
958
712
|
}
|
|
959
713
|
};
|
|
960
714
|
}
|
|
715
|
+
/**
|
|
716
|
+
* @estjs/shared v0.0.10-beta.20
|
|
717
|
+
* (c) 2023-Present jiangxd <jiangxd2016@gmail.com>
|
|
718
|
+
* @license MIT
|
|
719
|
+
**/
|
|
961
720
|
//# sourceMappingURL=index.cjs.map
|