babel-plugin-essor 0.0.7-beta.6 → 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/README.md +20 -6
- package/dist/index.cjs +228 -452
- 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 +231 -452
- package/dist/index.js.map +1 -1
- package/package.json +5 -5
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());
|
|
@@ -155,7 +136,7 @@ function jsxElementNameToString(node) {
|
|
|
155
136
|
return `${node.namespace.name}:${node.name.name}`;
|
|
156
137
|
}
|
|
157
138
|
function isComponent(tagName) {
|
|
158
|
-
return tagName[0] && tagName[0].toLowerCase() !== tagName[0] || tagName.includes(".") || /[^
|
|
139
|
+
return tagName[0] && tagName[0].toLowerCase() !== tagName[0] || tagName.includes(".") || /[^a-z]/i.test(tagName[0]);
|
|
159
140
|
}
|
|
160
141
|
function isTextChild(path) {
|
|
161
142
|
if (path.isJSXExpressionContainer()) {
|
|
@@ -180,18 +161,71 @@ function setNodeText(path, text) {
|
|
|
180
161
|
}
|
|
181
162
|
}
|
|
182
163
|
}
|
|
164
|
+
function isSymbolStart(path, name) {
|
|
165
|
+
const state = path.state;
|
|
166
|
+
const { symbol } = state.opts;
|
|
167
|
+
return startsWith(name, symbol);
|
|
168
|
+
}
|
|
183
169
|
|
|
184
|
-
// src/jsx/
|
|
185
|
-
|
|
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);
|
|
214
|
+
} else {
|
|
215
|
+
result.template += content;
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
function transformJSX(path) {
|
|
219
|
+
const state = path.state;
|
|
220
|
+
isSsg = state.opts.ssg;
|
|
186
221
|
const result = {
|
|
187
|
-
index:
|
|
222
|
+
index: 1,
|
|
188
223
|
isLastChild: false,
|
|
189
224
|
parentIndex: 0,
|
|
190
225
|
props: {},
|
|
191
|
-
template: []
|
|
192
|
-
// 修改为数组
|
|
226
|
+
template: isSsg ? [] : ""
|
|
193
227
|
};
|
|
194
|
-
|
|
228
|
+
transformJSXElement(path, result, true);
|
|
195
229
|
path.replaceWith(createEssorNode(path, result));
|
|
196
230
|
}
|
|
197
231
|
function createEssorNode(path, result) {
|
|
@@ -202,61 +236,59 @@ function createEssorNode(path, result) {
|
|
|
202
236
|
tmpl = import_core3.types.identifier(getTagName(path.node));
|
|
203
237
|
} else {
|
|
204
238
|
tmpl = path.scope.generateUidIdentifier("_tmpl$");
|
|
205
|
-
const template = import_core3.types.arrayExpression(result.template.map(import_core3.types.stringLiteral));
|
|
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)]);
|
|
206
240
|
const declarator = import_core3.types.variableDeclarator(tmpl, template);
|
|
207
241
|
state.tmplDeclaration.declarations.push(declarator);
|
|
242
|
+
if (!isSsg) {
|
|
243
|
+
imports.add("template");
|
|
244
|
+
}
|
|
208
245
|
}
|
|
209
246
|
const args = [tmpl, createProps(result.props)];
|
|
210
247
|
const key = result.props.key || ((_a = result.props[0]) == null ? void 0 : _a.key);
|
|
211
248
|
if (key) {
|
|
212
249
|
args.push(key);
|
|
213
250
|
}
|
|
214
|
-
imports.add("renderTemplate");
|
|
215
|
-
return import_core3.types.callExpression(state.renderTemplate, args);
|
|
251
|
+
imports.add(isSsg ? "renderTemplate" : "h");
|
|
252
|
+
return import_core3.types.callExpression(isSsg ? state.renderTemplate : state.h, args);
|
|
216
253
|
}
|
|
217
254
|
function createProps(props) {
|
|
218
|
-
const
|
|
219
|
-
for (const prop in props) {
|
|
220
|
-
let value = props[prop];
|
|
221
|
-
if (prop === "key") {
|
|
222
|
-
continue;
|
|
223
|
-
}
|
|
255
|
+
const toAstNode = (value) => {
|
|
224
256
|
if (Array.isArray(value)) {
|
|
225
|
-
|
|
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);
|
|
257
|
+
return import_core3.types.arrayExpression(value.map(toAstNode));
|
|
232
258
|
}
|
|
233
|
-
if (typeof value === "
|
|
234
|
-
|
|
259
|
+
if (value && typeof value === "object" && !import_core3.types.isNode(value)) {
|
|
260
|
+
return createProps(value);
|
|
235
261
|
}
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
262
|
+
switch (typeof value) {
|
|
263
|
+
case "string":
|
|
264
|
+
return import_core3.types.stringLiteral(value);
|
|
265
|
+
case "number":
|
|
266
|
+
return import_core3.types.numericLiteral(value);
|
|
267
|
+
case "boolean":
|
|
268
|
+
return import_core3.types.booleanLiteral(value);
|
|
269
|
+
case "undefined":
|
|
270
|
+
return import_core3.types.tsUndefinedKeyword();
|
|
271
|
+
case void 0:
|
|
272
|
+
return import_core3.types.tsUndefinedKeyword();
|
|
273
|
+
case null:
|
|
274
|
+
return import_core3.types.nullLiteral();
|
|
275
|
+
default:
|
|
276
|
+
return value;
|
|
249
277
|
}
|
|
250
|
-
}
|
|
278
|
+
};
|
|
279
|
+
const result = Object.keys(props).filter((prop) => prop !== "key").map((prop) => {
|
|
280
|
+
const value = toAstNode(props[prop]);
|
|
281
|
+
return prop === "_$spread$" ? import_core3.types.spreadElement(value) : import_core3.types.objectProperty(import_core3.types.stringLiteral(prop), value);
|
|
282
|
+
});
|
|
251
283
|
return import_core3.types.objectExpression(result);
|
|
252
284
|
}
|
|
253
|
-
function
|
|
285
|
+
function transformJSXElement(path, result, isRoot = false) {
|
|
254
286
|
if (path.isJSXElement()) {
|
|
255
287
|
const tagName = getTagName(path.node);
|
|
256
288
|
const tagIsComponent = isComponent(tagName);
|
|
257
289
|
const isSelfClose = !tagIsComponent && selfClosingTags.includes(tagName);
|
|
258
290
|
const isSvg = svgTags.includes(tagName) && result.index === 1;
|
|
259
|
-
const
|
|
291
|
+
const props = getAttrProps(path);
|
|
260
292
|
if (tagIsComponent) {
|
|
261
293
|
if (isRoot) {
|
|
262
294
|
result.props = props;
|
|
@@ -266,24 +298,21 @@ function transformJSXServiceElement(path, result, isRoot = false) {
|
|
|
266
298
|
result.props.children = childrenGenerator;
|
|
267
299
|
}
|
|
268
300
|
} else {
|
|
269
|
-
|
|
301
|
+
transformJSX(path);
|
|
270
302
|
replaceChild(path.node, result);
|
|
271
303
|
}
|
|
272
304
|
} else {
|
|
273
305
|
if (isSvg) {
|
|
274
|
-
result.template
|
|
306
|
+
result.template = isSsg ? ["<svg _svg_>"] : "<svg _svg_>";
|
|
275
307
|
}
|
|
276
|
-
result
|
|
308
|
+
addToTemplate(result, `<${tagName}`);
|
|
277
309
|
handleAttributes(props, result);
|
|
278
|
-
|
|
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);
|
|
310
|
+
addToTemplate(result, isSelfClose ? "/>" : ">");
|
|
285
311
|
if (!isSelfClose) {
|
|
286
|
-
result
|
|
312
|
+
transformChildren(path, result);
|
|
313
|
+
if (hasSiblingElement(path)) {
|
|
314
|
+
addToTemplate(result, `</${tagName}>`);
|
|
315
|
+
}
|
|
287
316
|
}
|
|
288
317
|
}
|
|
289
318
|
} else {
|
|
@@ -292,7 +321,7 @@ function transformJSXServiceElement(path, result, isRoot = false) {
|
|
|
292
321
|
}
|
|
293
322
|
}
|
|
294
323
|
function transformChildren(path, result) {
|
|
295
|
-
const parentIndex = result.template.length;
|
|
324
|
+
const parentIndex = isSsg ? result.template.length : result.index;
|
|
296
325
|
path.get("children").reduce((pre, cur) => {
|
|
297
326
|
if (isValidChild(cur)) {
|
|
298
327
|
const lastChild = pre.at(-1);
|
|
@@ -310,12 +339,13 @@ function transformChildren(path, result) {
|
|
|
310
339
|
});
|
|
311
340
|
}
|
|
312
341
|
function transformChild(child, result) {
|
|
342
|
+
result.index++;
|
|
313
343
|
if (child.isJSXElement() || child.isJSXFragment()) {
|
|
314
|
-
|
|
344
|
+
transformJSXElement(child, result, false);
|
|
315
345
|
} else if (child.isJSXExpressionContainer()) {
|
|
316
346
|
const expression = child.get("expression");
|
|
317
347
|
if (expression.isStringLiteral() || expression.isNumericLiteral()) {
|
|
318
|
-
result
|
|
348
|
+
addToTemplate(result, String(expression.node.value));
|
|
319
349
|
} else if (expression.isExpression()) {
|
|
320
350
|
replaceChild(expression.node, result);
|
|
321
351
|
} else if (import_core3.types.isJSXEmptyExpression(expression.node)) {
|
|
@@ -323,7 +353,7 @@ function transformChild(child, result) {
|
|
|
323
353
|
throw new Error("Unsupported child type");
|
|
324
354
|
}
|
|
325
355
|
} else if (child.isJSXText()) {
|
|
326
|
-
result
|
|
356
|
+
addToTemplate(result, String(child.node.value));
|
|
327
357
|
} else {
|
|
328
358
|
throw new Error("Unsupported child type");
|
|
329
359
|
}
|
|
@@ -344,7 +374,7 @@ function handleAttributes(props, result) {
|
|
|
344
374
|
let klass = "";
|
|
345
375
|
let style = "";
|
|
346
376
|
for (const prop in props) {
|
|
347
|
-
|
|
377
|
+
let value = props[prop];
|
|
348
378
|
if (prop === "class" && typeof value === "string") {
|
|
349
379
|
klass += ` ${value}`;
|
|
350
380
|
delete props[prop];
|
|
@@ -356,16 +386,42 @@ function handleAttributes(props, result) {
|
|
|
356
386
|
continue;
|
|
357
387
|
}
|
|
358
388
|
if (value === true) {
|
|
359
|
-
result
|
|
389
|
+
addToTemplate(result, ` ${prop}`);
|
|
360
390
|
delete props[prop];
|
|
361
391
|
}
|
|
362
392
|
if (value === false) {
|
|
363
393
|
delete props[prop];
|
|
364
394
|
}
|
|
365
395
|
if (typeof value === "string" || typeof value === "number") {
|
|
366
|
-
result
|
|
396
|
+
addToTemplate(result, ` ${prop}="${value}"`);
|
|
367
397
|
delete props[prop];
|
|
368
398
|
}
|
|
399
|
+
if (import_core3.types.isConditionalExpression(value)) {
|
|
400
|
+
const { test, consequent, alternate } = value;
|
|
401
|
+
value = import_core3.types.arrowFunctionExpression([], import_core3.types.conditionalExpression(test, consequent, alternate));
|
|
402
|
+
props[prop] = value;
|
|
403
|
+
}
|
|
404
|
+
if (import_core3.types.isObjectExpression(value)) {
|
|
405
|
+
let hasConditional = false;
|
|
406
|
+
value.properties.forEach((property) => {
|
|
407
|
+
if (import_core3.types.isObjectProperty(property) && import_core3.types.isConditionalExpression(property.value)) {
|
|
408
|
+
hasConditional = true;
|
|
409
|
+
}
|
|
410
|
+
});
|
|
411
|
+
if (hasConditional) {
|
|
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
|
+
}
|
|
423
|
+
}
|
|
424
|
+
}
|
|
369
425
|
}
|
|
370
426
|
if (Object.keys(props).length > 0) {
|
|
371
427
|
result.props[result.index] = props;
|
|
@@ -373,30 +429,32 @@ function handleAttributes(props, result) {
|
|
|
373
429
|
klass = klass.trim();
|
|
374
430
|
style = style.trim();
|
|
375
431
|
if (klass) {
|
|
376
|
-
result
|
|
432
|
+
addToTemplate(result, ` class="${klass}"`);
|
|
377
433
|
}
|
|
378
434
|
if (style) {
|
|
379
|
-
result
|
|
435
|
+
addToTemplate(result, ` style="${style}"`);
|
|
380
436
|
}
|
|
381
437
|
}
|
|
382
438
|
function replaceChild(node, result) {
|
|
383
439
|
var _a, _b, _c, _d, _e;
|
|
384
440
|
if (result.isLastChild) {
|
|
385
441
|
result.index--;
|
|
442
|
+
} else {
|
|
443
|
+
addToTemplate(result, "<!>");
|
|
386
444
|
}
|
|
387
445
|
(_c = (_a = result.props)[_b = result.parentIndex]) != null ? _c : _a[_b] = {};
|
|
388
446
|
(_e = (_d = result.props[result.parentIndex]).children) != null ? _e : _d.children = [];
|
|
389
447
|
result.props[result.parentIndex].children.push(
|
|
390
448
|
import_core3.types.arrayExpression([
|
|
391
449
|
import_core3.types.arrowFunctionExpression([], node),
|
|
392
|
-
import_core3.types.identifier(String(result.
|
|
450
|
+
result.isLastChild ? import_core3.types.nullLiteral() : import_core3.types.identifier(String(result.index))
|
|
393
451
|
])
|
|
394
452
|
);
|
|
395
453
|
}
|
|
396
454
|
function getChildren(path) {
|
|
397
455
|
return path.get("children").filter((child) => isValidChild(child)).map((child) => {
|
|
398
456
|
if (child.isJSXElement() || child.isJSXFragment()) {
|
|
399
|
-
|
|
457
|
+
transformJSX(child);
|
|
400
458
|
} else if (child.isJSXExpressionContainer()) {
|
|
401
459
|
child.replaceWith(child.get("expression"));
|
|
402
460
|
} else if (child.isJSXText()) {
|
|
@@ -416,7 +474,6 @@ function isValidChild(path) {
|
|
|
416
474
|
}
|
|
417
475
|
function getAttrProps(path) {
|
|
418
476
|
const props = {};
|
|
419
|
-
let hasExpression = false;
|
|
420
477
|
path.get("openingElement").get("attributes").forEach((attribute) => {
|
|
421
478
|
if (attribute.isJSXAttribute()) {
|
|
422
479
|
const name = getAttrName(attribute.node);
|
|
@@ -433,10 +490,9 @@ function getAttrProps(path) {
|
|
|
433
490
|
} else if (expression.isNumericLiteral()) {
|
|
434
491
|
props[name] = expression.node.value;
|
|
435
492
|
} else if (expression.isJSXElement() || expression.isJSXFragment()) {
|
|
436
|
-
|
|
493
|
+
transformJSX(expression);
|
|
437
494
|
props[name] = expression.node;
|
|
438
495
|
} else if (expression.isExpression()) {
|
|
439
|
-
hasExpression = true;
|
|
440
496
|
if (/^key|ref|on.+$/.test(name)) {
|
|
441
497
|
props[name] = expression.node;
|
|
442
498
|
} else if (/^bind:.+/.test(name)) {
|
|
@@ -456,293 +512,7 @@ function getAttrProps(path) {
|
|
|
456
512
|
}
|
|
457
513
|
}
|
|
458
514
|
} else if (value.isJSXElement() || value.isJSXFragment()) {
|
|
459
|
-
|
|
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
|
-
}
|
|
475
|
-
|
|
476
|
-
// src/jsx/client.ts
|
|
477
|
-
var import_core4 = require("@babel/core");
|
|
478
|
-
function transformJSXClient(path) {
|
|
479
|
-
const result = {
|
|
480
|
-
index: 1,
|
|
481
|
-
isLastChild: false,
|
|
482
|
-
parentIndex: 0,
|
|
483
|
-
props: {},
|
|
484
|
-
template: ""
|
|
485
|
-
};
|
|
486
|
-
transformJSXElement(path, result, true);
|
|
487
|
-
path.replaceWith(createEssorNode2(path, result));
|
|
488
|
-
}
|
|
489
|
-
function createEssorNode2(path, result) {
|
|
490
|
-
var _a;
|
|
491
|
-
const state = path.state;
|
|
492
|
-
let tmpl;
|
|
493
|
-
if (path.isJSXElement() && isComponent(getTagName(path.node))) {
|
|
494
|
-
tmpl = import_core4.types.identifier(getTagName(path.node));
|
|
495
|
-
} else {
|
|
496
|
-
tmpl = path.scope.generateUidIdentifier("_tmpl$");
|
|
497
|
-
const template = import_core4.types.callExpression(state.template, [import_core4.types.stringLiteral(result.template)]);
|
|
498
|
-
const declarator = import_core4.types.variableDeclarator(tmpl, template);
|
|
499
|
-
state.tmplDeclaration.declarations.push(declarator);
|
|
500
|
-
imports.add("template");
|
|
501
|
-
}
|
|
502
|
-
const args = [tmpl, createProps2(result.props)];
|
|
503
|
-
const key = result.props.key || ((_a = result.props[0]) == null ? void 0 : _a.key);
|
|
504
|
-
if (key) {
|
|
505
|
-
args.push(key);
|
|
506
|
-
}
|
|
507
|
-
imports.add("h");
|
|
508
|
-
return import_core4.types.callExpression(state.h, args);
|
|
509
|
-
}
|
|
510
|
-
function createProps2(props) {
|
|
511
|
-
const toAstNode = (value) => {
|
|
512
|
-
if (Array.isArray(value)) {
|
|
513
|
-
return import_core4.types.arrayExpression(value.map(toAstNode));
|
|
514
|
-
}
|
|
515
|
-
if (value && typeof value === "object" && !import_core4.types.isNode(value)) {
|
|
516
|
-
return createProps2(value);
|
|
517
|
-
}
|
|
518
|
-
switch (typeof value) {
|
|
519
|
-
case "string":
|
|
520
|
-
return import_core4.types.stringLiteral(value);
|
|
521
|
-
case "number":
|
|
522
|
-
return import_core4.types.numericLiteral(value);
|
|
523
|
-
case "boolean":
|
|
524
|
-
return import_core4.types.booleanLiteral(value);
|
|
525
|
-
case "undefined":
|
|
526
|
-
return import_core4.types.tsUndefinedKeyword();
|
|
527
|
-
case void 0:
|
|
528
|
-
return import_core4.types.tsUndefinedKeyword();
|
|
529
|
-
case null:
|
|
530
|
-
return import_core4.types.nullLiteral();
|
|
531
|
-
default:
|
|
532
|
-
return value;
|
|
533
|
-
}
|
|
534
|
-
};
|
|
535
|
-
const result = Object.keys(props).filter((prop) => prop !== "key").map((prop) => {
|
|
536
|
-
const value = toAstNode(props[prop]);
|
|
537
|
-
return prop === "_$spread$" ? import_core4.types.spreadElement(value) : import_core4.types.objectProperty(import_core4.types.stringLiteral(prop), value);
|
|
538
|
-
});
|
|
539
|
-
return import_core4.types.objectExpression(result);
|
|
540
|
-
}
|
|
541
|
-
function transformJSXElement(path, result, isRoot = false) {
|
|
542
|
-
if (path.isJSXElement()) {
|
|
543
|
-
const tagName = getTagName(path.node);
|
|
544
|
-
const tagIsComponent = isComponent(tagName);
|
|
545
|
-
const isSelfClose = !tagIsComponent && selfClosingTags.includes(tagName);
|
|
546
|
-
const isSvg = svgTags.includes(tagName) && result.index === 1;
|
|
547
|
-
const props = getAttrProps2(path);
|
|
548
|
-
if (tagIsComponent) {
|
|
549
|
-
if (isRoot) {
|
|
550
|
-
result.props = props;
|
|
551
|
-
const children = getChildren2(path);
|
|
552
|
-
if (children.length > 0) {
|
|
553
|
-
const childrenGenerator = children.length === 1 ? children[0] : import_core4.types.arrayExpression(children);
|
|
554
|
-
result.props.children = childrenGenerator;
|
|
555
|
-
}
|
|
556
|
-
} else {
|
|
557
|
-
transformJSXClient(path);
|
|
558
|
-
replaceChild2(path.node, result);
|
|
559
|
-
}
|
|
560
|
-
} else {
|
|
561
|
-
if (isSvg) {
|
|
562
|
-
result.template = "<svg _svg_>";
|
|
563
|
-
}
|
|
564
|
-
result.template += `<${tagName}`;
|
|
565
|
-
handleAttributes2(props, result);
|
|
566
|
-
result.template += isSelfClose ? "/>" : ">";
|
|
567
|
-
if (!isSelfClose) {
|
|
568
|
-
transformChildren2(path, result);
|
|
569
|
-
if (hasSiblingElement(path)) {
|
|
570
|
-
result.template += `</${tagName}>`;
|
|
571
|
-
}
|
|
572
|
-
}
|
|
573
|
-
}
|
|
574
|
-
} else {
|
|
575
|
-
result.index--;
|
|
576
|
-
transformChildren2(path, result);
|
|
577
|
-
}
|
|
578
|
-
}
|
|
579
|
-
function transformChildren2(path, result) {
|
|
580
|
-
const parentIndex = result.index;
|
|
581
|
-
path.get("children").reduce((pre, cur) => {
|
|
582
|
-
if (isValidChild2(cur)) {
|
|
583
|
-
const lastChild = pre.at(-1);
|
|
584
|
-
if (lastChild && isTextChild(cur) && isTextChild(lastChild)) {
|
|
585
|
-
setNodeText(lastChild, getNodeText2(lastChild) + getNodeText2(cur));
|
|
586
|
-
} else {
|
|
587
|
-
pre.push(cur);
|
|
588
|
-
}
|
|
589
|
-
}
|
|
590
|
-
return pre;
|
|
591
|
-
}, []).forEach((child, i, arr) => {
|
|
592
|
-
result.parentIndex = parentIndex;
|
|
593
|
-
result.isLastChild = i === arr.length - 1;
|
|
594
|
-
transformChild2(child, result);
|
|
595
|
-
});
|
|
596
|
-
}
|
|
597
|
-
function transformChild2(child, result) {
|
|
598
|
-
result.index++;
|
|
599
|
-
if (child.isJSXElement() || child.isJSXFragment()) {
|
|
600
|
-
transformJSXElement(child, result, false);
|
|
601
|
-
} else if (child.isJSXExpressionContainer()) {
|
|
602
|
-
const expression = child.get("expression");
|
|
603
|
-
if (expression.isStringLiteral() || expression.isNumericLiteral()) {
|
|
604
|
-
result.template += String(expression.node.value);
|
|
605
|
-
} else if (expression.isExpression()) {
|
|
606
|
-
replaceChild2(expression.node, result);
|
|
607
|
-
} else if (import_core4.types.isJSXEmptyExpression(expression.node)) {
|
|
608
|
-
} else {
|
|
609
|
-
throw new Error("Unsupported child type");
|
|
610
|
-
}
|
|
611
|
-
} else if (child.isJSXText()) {
|
|
612
|
-
result.template += String(child.node.value);
|
|
613
|
-
} else {
|
|
614
|
-
throw new Error("Unsupported child type");
|
|
615
|
-
}
|
|
616
|
-
}
|
|
617
|
-
function getNodeText2(path) {
|
|
618
|
-
if (path.isJSXText()) {
|
|
619
|
-
return path.node.value;
|
|
620
|
-
}
|
|
621
|
-
if (path.isJSXExpressionContainer()) {
|
|
622
|
-
const expression = path.get("expression");
|
|
623
|
-
if (expression.isStringLiteral() || expression.isNumericLiteral()) {
|
|
624
|
-
return String(expression.node.value);
|
|
625
|
-
}
|
|
626
|
-
}
|
|
627
|
-
return "";
|
|
628
|
-
}
|
|
629
|
-
function handleAttributes2(props, result) {
|
|
630
|
-
let klass = "";
|
|
631
|
-
let style = "";
|
|
632
|
-
for (const prop in props) {
|
|
633
|
-
const value = props[prop];
|
|
634
|
-
if (prop === "class" && typeof value === "string") {
|
|
635
|
-
klass += ` ${value}`;
|
|
636
|
-
delete props[prop];
|
|
637
|
-
continue;
|
|
638
|
-
}
|
|
639
|
-
if (prop === "style" && typeof value === "string") {
|
|
640
|
-
style += `${value}${value.at(-1) === ";" ? "" : ";"}`;
|
|
641
|
-
delete props[prop];
|
|
642
|
-
continue;
|
|
643
|
-
}
|
|
644
|
-
if (value === true) {
|
|
645
|
-
result.template += ` ${prop}`;
|
|
646
|
-
delete props[prop];
|
|
647
|
-
}
|
|
648
|
-
if (value === false) {
|
|
649
|
-
delete props[prop];
|
|
650
|
-
}
|
|
651
|
-
if (typeof value === "string" || typeof value === "number") {
|
|
652
|
-
result.template += ` ${prop}="${value}"`;
|
|
653
|
-
delete props[prop];
|
|
654
|
-
}
|
|
655
|
-
}
|
|
656
|
-
if (Object.keys(props).length > 0) {
|
|
657
|
-
result.props[result.index] = props;
|
|
658
|
-
}
|
|
659
|
-
klass = klass.trim();
|
|
660
|
-
style = style.trim();
|
|
661
|
-
if (klass) {
|
|
662
|
-
result.template += ` class="${klass}"`;
|
|
663
|
-
}
|
|
664
|
-
if (style) {
|
|
665
|
-
result.template += ` style="${style}"`;
|
|
666
|
-
}
|
|
667
|
-
}
|
|
668
|
-
function replaceChild2(node, result) {
|
|
669
|
-
var _a, _b, _c, _d, _e;
|
|
670
|
-
if (result.isLastChild) {
|
|
671
|
-
result.index--;
|
|
672
|
-
} else {
|
|
673
|
-
result.template += "<!>";
|
|
674
|
-
}
|
|
675
|
-
(_c = (_a = result.props)[_b = result.parentIndex]) != null ? _c : _a[_b] = {};
|
|
676
|
-
(_e = (_d = result.props[result.parentIndex]).children) != null ? _e : _d.children = [];
|
|
677
|
-
result.props[result.parentIndex].children.push(
|
|
678
|
-
import_core4.types.arrayExpression([
|
|
679
|
-
import_core4.types.arrowFunctionExpression([], node),
|
|
680
|
-
result.isLastChild ? import_core4.types.nullLiteral() : import_core4.types.identifier(String(result.index))
|
|
681
|
-
])
|
|
682
|
-
);
|
|
683
|
-
}
|
|
684
|
-
function getChildren2(path) {
|
|
685
|
-
return path.get("children").filter((child) => isValidChild2(child)).map((child) => {
|
|
686
|
-
if (child.isJSXElement() || child.isJSXFragment()) {
|
|
687
|
-
transformJSXClient(child);
|
|
688
|
-
} else if (child.isJSXExpressionContainer()) {
|
|
689
|
-
child.replaceWith(child.get("expression"));
|
|
690
|
-
} else if (child.isJSXText()) {
|
|
691
|
-
child.replaceWith(import_core4.types.stringLiteral(child.node.value));
|
|
692
|
-
} else {
|
|
693
|
-
throw new Error("Unsupported child type");
|
|
694
|
-
}
|
|
695
|
-
return child.node;
|
|
696
|
-
});
|
|
697
|
-
}
|
|
698
|
-
function isValidChild2(path) {
|
|
699
|
-
const regex = /^\s*$/;
|
|
700
|
-
if (path.isStringLiteral() || path.isJSXText()) {
|
|
701
|
-
return !regex.test(path.node.value);
|
|
702
|
-
}
|
|
703
|
-
return Object.keys(path.node).length > 0;
|
|
704
|
-
}
|
|
705
|
-
function getAttrProps2(path) {
|
|
706
|
-
const props = {};
|
|
707
|
-
path.get("openingElement").get("attributes").forEach((attribute) => {
|
|
708
|
-
if (attribute.isJSXAttribute()) {
|
|
709
|
-
const name = getAttrName(attribute.node);
|
|
710
|
-
const value = attribute.get("value");
|
|
711
|
-
if (!value.node) {
|
|
712
|
-
props[name] = true;
|
|
713
|
-
} else if (value.isStringLiteral()) {
|
|
714
|
-
props[name] = value.node.value;
|
|
715
|
-
} else {
|
|
716
|
-
if (value.isJSXExpressionContainer()) {
|
|
717
|
-
const expression = value.get("expression");
|
|
718
|
-
if (expression.isStringLiteral()) {
|
|
719
|
-
props[name] = expression.node.value;
|
|
720
|
-
} else if (expression.isNumericLiteral()) {
|
|
721
|
-
props[name] = expression.node.value;
|
|
722
|
-
} else if (expression.isJSXElement() || expression.isJSXFragment()) {
|
|
723
|
-
transformJSXClient(expression);
|
|
724
|
-
props[name] = expression.node;
|
|
725
|
-
} else if (expression.isExpression()) {
|
|
726
|
-
if (/^key|ref|on.+$/.test(name)) {
|
|
727
|
-
props[name] = expression.node;
|
|
728
|
-
} else if (/^bind:.+/.test(name)) {
|
|
729
|
-
const value2 = path.scope.generateUidIdentifier("value");
|
|
730
|
-
const bindName = name.slice(5).toLocaleLowerCase();
|
|
731
|
-
props[bindName] = expression.node;
|
|
732
|
-
props[`update${capitalizeFirstLetter(bindName)}`] = import_core4.types.arrowFunctionExpression(
|
|
733
|
-
[value2],
|
|
734
|
-
import_core4.types.assignmentExpression("=", expression.node, value2)
|
|
735
|
-
);
|
|
736
|
-
} else {
|
|
737
|
-
if (expression.isConditionalExpression()) {
|
|
738
|
-
props[name] = import_core4.types.arrowFunctionExpression([], expression.node);
|
|
739
|
-
} else {
|
|
740
|
-
props[name] = expression.node;
|
|
741
|
-
}
|
|
742
|
-
}
|
|
743
|
-
}
|
|
744
|
-
} else if (value.isJSXElement() || value.isJSXFragment()) {
|
|
745
|
-
transformJSXClient(value);
|
|
515
|
+
transformJSX(value);
|
|
746
516
|
props[name] = value.node;
|
|
747
517
|
}
|
|
748
518
|
}
|
|
@@ -755,41 +525,34 @@ function getAttrProps2(path) {
|
|
|
755
525
|
return props;
|
|
756
526
|
}
|
|
757
527
|
|
|
758
|
-
// src/jsx/index.ts
|
|
759
|
-
function transformJSX(path) {
|
|
760
|
-
const state = path.state;
|
|
761
|
-
const isSsg = state.opts.ssg;
|
|
762
|
-
return isSsg ? transformJSXService(path) : transformJSXClient(path);
|
|
763
|
-
}
|
|
764
|
-
|
|
765
528
|
// src/signal/symbol.ts
|
|
766
|
-
var
|
|
529
|
+
var import_core4 = require("@babel/core");
|
|
767
530
|
function replaceSymbol(path) {
|
|
768
531
|
const init = path.node.init;
|
|
769
532
|
const variableName = path.node.id.name;
|
|
770
|
-
if (
|
|
533
|
+
if (import_core4.types.isObjectPattern(path.node.id) || import_core4.types.isArrayPattern(path.node.id)) {
|
|
771
534
|
return;
|
|
772
535
|
}
|
|
773
|
-
if (!
|
|
536
|
+
if (!isSymbolStart(path, variableName)) {
|
|
774
537
|
return;
|
|
775
538
|
}
|
|
776
|
-
if (init && (
|
|
777
|
-
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] : []);
|
|
778
541
|
imports.add("useComputed");
|
|
779
542
|
path.node.init = newInit;
|
|
780
543
|
} else {
|
|
781
|
-
const newInit =
|
|
544
|
+
const newInit = import_core4.types.callExpression(import_core4.types.identifier(path.state.useSignal.name), init ? [init] : []);
|
|
782
545
|
imports.add("useSignal");
|
|
783
546
|
path.node.init = newInit;
|
|
784
547
|
}
|
|
785
548
|
}
|
|
786
549
|
function symbolIdentifier(path) {
|
|
787
550
|
const parentPath = path.parentPath;
|
|
788
|
-
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)) {
|
|
789
552
|
return;
|
|
790
553
|
}
|
|
791
554
|
const { node } = path;
|
|
792
|
-
if (node.name
|
|
555
|
+
if (isSymbolStart(path, node.name)) {
|
|
793
556
|
let currentPath = path;
|
|
794
557
|
while (currentPath.parentPath && !currentPath.parentPath.isProgram()) {
|
|
795
558
|
if (currentPath.parentPath.isMemberExpression() && currentPath.parentPath.node.property.name === "value") {
|
|
@@ -797,27 +560,27 @@ function symbolIdentifier(path) {
|
|
|
797
560
|
}
|
|
798
561
|
currentPath = currentPath.parentPath;
|
|
799
562
|
}
|
|
800
|
-
const newNode =
|
|
563
|
+
const newNode = import_core4.types.memberExpression(import_core4.types.identifier(node.name), import_core4.types.identifier("value"));
|
|
801
564
|
path.replaceWith(newNode);
|
|
802
565
|
}
|
|
803
566
|
}
|
|
804
567
|
function symbolObjectPattern(path) {
|
|
805
568
|
path.node.properties.forEach((property) => {
|
|
806
|
-
if (
|
|
807
|
-
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);
|
|
808
571
|
property.key = newKey;
|
|
809
572
|
}
|
|
810
573
|
});
|
|
811
574
|
}
|
|
812
575
|
function symbolArrayPattern(path) {
|
|
813
576
|
path.node.elements.forEach((element) => {
|
|
814
|
-
if (
|
|
815
|
-
const newElement =
|
|
577
|
+
if (import_core4.types.isIdentifier(element) && element.name.startsWith("$")) {
|
|
578
|
+
const newElement = import_core4.types.identifier(element.name);
|
|
816
579
|
element.name = newElement.name;
|
|
817
|
-
} else if (
|
|
580
|
+
} else if (import_core4.types.isObjectPattern(element)) {
|
|
818
581
|
element.properties.forEach((property) => {
|
|
819
|
-
if (
|
|
820
|
-
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);
|
|
821
584
|
property.key = newKey;
|
|
822
585
|
}
|
|
823
586
|
});
|
|
@@ -826,7 +589,17 @@ function symbolArrayPattern(path) {
|
|
|
826
589
|
}
|
|
827
590
|
|
|
828
591
|
// src/signal/import.ts
|
|
829
|
-
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
|
+
}
|
|
830
603
|
function isVariableUsedAsObject(path, variableName) {
|
|
831
604
|
const binding = path.scope.getBinding(variableName);
|
|
832
605
|
let isUsedObject = false;
|
|
@@ -834,30 +607,28 @@ function isVariableUsedAsObject(path, variableName) {
|
|
|
834
607
|
return isUsedObject;
|
|
835
608
|
}
|
|
836
609
|
for (const referencePath of binding.referencePaths) {
|
|
837
|
-
if (
|
|
838
|
-
|
|
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
|
+
}
|
|
839
620
|
}
|
|
840
621
|
}
|
|
841
622
|
return isUsedObject;
|
|
842
623
|
}
|
|
843
|
-
function replaceImportDeclaration(path) {
|
|
844
|
-
const imports2 = path.node.specifiers;
|
|
845
|
-
imports2.forEach((specifier) => {
|
|
846
|
-
const variableName = specifier.local.name;
|
|
847
|
-
if (startsWith(variableName, "$") && !isVariableUsedAsObject(path, variableName)) {
|
|
848
|
-
path.scope.rename(variableName, `${variableName}.value`);
|
|
849
|
-
specifier.local.name = `${variableName}`;
|
|
850
|
-
}
|
|
851
|
-
});
|
|
852
|
-
}
|
|
853
624
|
|
|
854
625
|
// src/signal/props.ts
|
|
855
|
-
var
|
|
626
|
+
var import_core6 = require("@babel/core");
|
|
856
627
|
function replaceProps(path) {
|
|
857
628
|
var _a;
|
|
858
629
|
const state = path.state;
|
|
859
630
|
const firstParam = path.node.params[0];
|
|
860
|
-
if (!firstParam || !
|
|
631
|
+
if (!firstParam || !import_core6.types.isObjectPattern(firstParam)) {
|
|
861
632
|
return;
|
|
862
633
|
}
|
|
863
634
|
const returnStatement = path.get("body").get("body").find((statement) => statement.isReturnStatement());
|
|
@@ -865,18 +636,18 @@ function replaceProps(path) {
|
|
|
865
636
|
return;
|
|
866
637
|
}
|
|
867
638
|
const returnValue = (_a = returnStatement.node) == null ? void 0 : _a.argument;
|
|
868
|
-
if (!
|
|
639
|
+
if (!import_core6.types.isJSXElement(returnValue)) {
|
|
869
640
|
return;
|
|
870
641
|
}
|
|
871
642
|
function replaceProperties(properties2, parentPath) {
|
|
872
643
|
properties2.forEach((property) => {
|
|
873
|
-
if (
|
|
644
|
+
if (import_core6.types.isObjectProperty(property)) {
|
|
874
645
|
const keyName = property.key.name;
|
|
875
|
-
if (
|
|
646
|
+
if (import_core6.types.isIdentifier(property.value)) {
|
|
876
647
|
const propertyName = property.value.name;
|
|
877
648
|
const newName = `${parentPath}${keyName}`;
|
|
878
649
|
path.scope.rename(propertyName, newName);
|
|
879
|
-
} else if (
|
|
650
|
+
} else if (import_core6.types.isObjectPattern(property.value)) {
|
|
880
651
|
replaceProperties(property.value.properties, `${parentPath}${keyName}.`);
|
|
881
652
|
}
|
|
882
653
|
}
|
|
@@ -884,10 +655,10 @@ function replaceProps(path) {
|
|
|
884
655
|
}
|
|
885
656
|
const properties = firstParam.properties;
|
|
886
657
|
replaceProperties(
|
|
887
|
-
properties.filter((property) => !
|
|
658
|
+
properties.filter((property) => !import_core6.types.isRestElement(property)),
|
|
888
659
|
"__props."
|
|
889
660
|
);
|
|
890
|
-
const notRestProperties = properties.filter((property) => !
|
|
661
|
+
const notRestProperties = properties.filter((property) => !import_core6.types.isRestElement(property));
|
|
891
662
|
const notRestNames = notRestProperties.map(
|
|
892
663
|
(property) => property.key.name
|
|
893
664
|
);
|
|
@@ -895,19 +666,19 @@ function replaceProps(path) {
|
|
|
895
666
|
console.warn("props name can not start with $");
|
|
896
667
|
return;
|
|
897
668
|
}
|
|
898
|
-
const restElement = properties.find((property) =>
|
|
899
|
-
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");
|
|
900
671
|
if (restElement) {
|
|
901
672
|
const restName = restElement.argument.name;
|
|
902
673
|
if (notRestProperties.length === 0) {
|
|
903
|
-
path.node.params[0] =
|
|
674
|
+
path.node.params[0] = import_core6.types.identifier(restName);
|
|
904
675
|
} else {
|
|
905
|
-
const restVariableDeclaration =
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
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)))
|
|
911
682
|
])
|
|
912
683
|
)
|
|
913
684
|
]);
|
|
@@ -929,16 +700,21 @@ function src_default() {
|
|
|
929
700
|
},
|
|
930
701
|
visitor: {
|
|
931
702
|
Program: transformProgram,
|
|
932
|
-
JSXElement: transformJSX,
|
|
933
|
-
JSXFragment: transformJSX,
|
|
934
703
|
FunctionDeclaration: replaceProps,
|
|
935
704
|
ArrowFunctionExpression: replaceProps,
|
|
936
705
|
VariableDeclarator: replaceSymbol,
|
|
937
706
|
ImportDeclaration: replaceImportDeclaration,
|
|
938
707
|
Identifier: symbolIdentifier,
|
|
939
708
|
ObjectPattern: symbolObjectPattern,
|
|
940
|
-
ArrayPattern: symbolArrayPattern
|
|
709
|
+
ArrayPattern: symbolArrayPattern,
|
|
710
|
+
JSXElement: transformJSX,
|
|
711
|
+
JSXFragment: transformJSX
|
|
941
712
|
}
|
|
942
713
|
};
|
|
943
714
|
}
|
|
715
|
+
/**
|
|
716
|
+
* @estjs/shared v0.0.10-beta.20
|
|
717
|
+
* (c) 2023-Present jiangxd <jiangxd2016@gmail.com>
|
|
718
|
+
* @license MIT
|
|
719
|
+
**/
|
|
944
720
|
//# sourceMappingURL=index.cjs.map
|