babel-plugin-jsx-dom-expressions 0.38.1 → 0.38.5
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/index.js +1890 -1888
- package/package.json +5 -3
- package/tsconfig.json +15 -0
package/index.js
CHANGED
|
@@ -25,60 +25,60 @@ function _interopNamespaceDefault(e) {
|
|
|
25
25
|
var t__namespace = /*#__PURE__*/_interopNamespaceDefault(t);
|
|
26
26
|
|
|
27
27
|
const booleans = [
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
const BooleanAttributes = /*#__PURE__*/
|
|
56
|
-
|
|
57
|
-
const Properties = /*#__PURE__*/
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
const ChildProperties = /*#__PURE__*/
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
28
|
+
"allowfullscreen",
|
|
29
|
+
"async",
|
|
30
|
+
"autofocus",
|
|
31
|
+
"autoplay",
|
|
32
|
+
"checked",
|
|
33
|
+
"controls",
|
|
34
|
+
"default",
|
|
35
|
+
"disabled",
|
|
36
|
+
"formnovalidate",
|
|
37
|
+
"hidden",
|
|
38
|
+
"indeterminate",
|
|
39
|
+
"inert",
|
|
40
|
+
"ismap",
|
|
41
|
+
"loop",
|
|
42
|
+
"multiple",
|
|
43
|
+
"muted",
|
|
44
|
+
"nomodule",
|
|
45
|
+
"novalidate",
|
|
46
|
+
"open",
|
|
47
|
+
"playsinline",
|
|
48
|
+
"readonly",
|
|
49
|
+
"required",
|
|
50
|
+
"reversed",
|
|
51
|
+
"seamless",
|
|
52
|
+
"selected"];
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
const BooleanAttributes = /*#__PURE__*/new Set(booleans);
|
|
56
|
+
|
|
57
|
+
const Properties = /*#__PURE__*/new Set([
|
|
58
|
+
"className",
|
|
59
|
+
"value",
|
|
60
|
+
"readOnly",
|
|
61
|
+
"formNoValidate",
|
|
62
|
+
"isMap",
|
|
63
|
+
"noModule",
|
|
64
|
+
"playsInline",
|
|
65
|
+
...booleans]);
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
const ChildProperties = /*#__PURE__*/new Set([
|
|
69
|
+
"innerHTML",
|
|
70
|
+
"textContent",
|
|
71
|
+
"innerText",
|
|
72
|
+
"children"]);
|
|
73
|
+
|
|
74
74
|
|
|
75
75
|
// React Compat
|
|
76
|
-
const Aliases = /*#__PURE__*/
|
|
76
|
+
const Aliases = /*#__PURE__*/Object.assign(Object.create(null), {
|
|
77
77
|
className: "class",
|
|
78
78
|
htmlFor: "for"
|
|
79
79
|
});
|
|
80
80
|
|
|
81
|
-
const PropAliases = /*#__PURE__*/
|
|
81
|
+
const PropAliases = /*#__PURE__*/Object.assign(Object.create(null), {
|
|
82
82
|
class: "className",
|
|
83
83
|
formnovalidate: {
|
|
84
84
|
$: "formNoValidate",
|
|
@@ -106,118 +106,118 @@ const PropAliases = /*#__PURE__*/ Object.assign(Object.create(null), {
|
|
|
106
106
|
|
|
107
107
|
function getPropAlias(prop, tagName) {
|
|
108
108
|
const a = PropAliases[prop];
|
|
109
|
-
return typeof a === "object" ?
|
|
109
|
+
return typeof a === "object" ? a[tagName] ? a["$"] : undefined : a;
|
|
110
110
|
}
|
|
111
111
|
|
|
112
112
|
// list of Element events that will be delegated
|
|
113
|
-
const DelegatedEvents = /*#__PURE__*/
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
const SVGElements = /*#__PURE__*/
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
113
|
+
const DelegatedEvents = /*#__PURE__*/new Set([
|
|
114
|
+
"beforeinput",
|
|
115
|
+
"click",
|
|
116
|
+
"dblclick",
|
|
117
|
+
"contextmenu",
|
|
118
|
+
"focusin",
|
|
119
|
+
"focusout",
|
|
120
|
+
"input",
|
|
121
|
+
"keydown",
|
|
122
|
+
"keyup",
|
|
123
|
+
"mousedown",
|
|
124
|
+
"mousemove",
|
|
125
|
+
"mouseout",
|
|
126
|
+
"mouseover",
|
|
127
|
+
"mouseup",
|
|
128
|
+
"pointerdown",
|
|
129
|
+
"pointermove",
|
|
130
|
+
"pointerout",
|
|
131
|
+
"pointerover",
|
|
132
|
+
"pointerup",
|
|
133
|
+
"touchend",
|
|
134
|
+
"touchmove",
|
|
135
|
+
"touchstart"]);
|
|
136
|
+
|
|
137
|
+
|
|
138
|
+
const SVGElements = /*#__PURE__*/new Set([
|
|
139
|
+
// "a",
|
|
140
|
+
"altGlyph",
|
|
141
|
+
"altGlyphDef",
|
|
142
|
+
"altGlyphItem",
|
|
143
|
+
"animate",
|
|
144
|
+
"animateColor",
|
|
145
|
+
"animateMotion",
|
|
146
|
+
"animateTransform",
|
|
147
|
+
"circle",
|
|
148
|
+
"clipPath",
|
|
149
|
+
"color-profile",
|
|
150
|
+
"cursor",
|
|
151
|
+
"defs",
|
|
152
|
+
"desc",
|
|
153
|
+
"ellipse",
|
|
154
|
+
"feBlend",
|
|
155
|
+
"feColorMatrix",
|
|
156
|
+
"feComponentTransfer",
|
|
157
|
+
"feComposite",
|
|
158
|
+
"feConvolveMatrix",
|
|
159
|
+
"feDiffuseLighting",
|
|
160
|
+
"feDisplacementMap",
|
|
161
|
+
"feDistantLight",
|
|
162
|
+
"feDropShadow",
|
|
163
|
+
"feFlood",
|
|
164
|
+
"feFuncA",
|
|
165
|
+
"feFuncB",
|
|
166
|
+
"feFuncG",
|
|
167
|
+
"feFuncR",
|
|
168
|
+
"feGaussianBlur",
|
|
169
|
+
"feImage",
|
|
170
|
+
"feMerge",
|
|
171
|
+
"feMergeNode",
|
|
172
|
+
"feMorphology",
|
|
173
|
+
"feOffset",
|
|
174
|
+
"fePointLight",
|
|
175
|
+
"feSpecularLighting",
|
|
176
|
+
"feSpotLight",
|
|
177
|
+
"feTile",
|
|
178
|
+
"feTurbulence",
|
|
179
|
+
"filter",
|
|
180
|
+
"font",
|
|
181
|
+
"font-face",
|
|
182
|
+
"font-face-format",
|
|
183
|
+
"font-face-name",
|
|
184
|
+
"font-face-src",
|
|
185
|
+
"font-face-uri",
|
|
186
|
+
"foreignObject",
|
|
187
|
+
"g",
|
|
188
|
+
"glyph",
|
|
189
|
+
"glyphRef",
|
|
190
|
+
"hkern",
|
|
191
|
+
"image",
|
|
192
|
+
"line",
|
|
193
|
+
"linearGradient",
|
|
194
|
+
"marker",
|
|
195
|
+
"mask",
|
|
196
|
+
"metadata",
|
|
197
|
+
"missing-glyph",
|
|
198
|
+
"mpath",
|
|
199
|
+
"path",
|
|
200
|
+
"pattern",
|
|
201
|
+
"polygon",
|
|
202
|
+
"polyline",
|
|
203
|
+
"radialGradient",
|
|
204
|
+
"rect",
|
|
205
|
+
// "script",
|
|
206
|
+
"set",
|
|
207
|
+
"stop",
|
|
208
|
+
// "style",
|
|
209
|
+
"svg",
|
|
210
|
+
"switch",
|
|
211
|
+
"symbol",
|
|
212
|
+
"text",
|
|
213
|
+
"textPath",
|
|
214
|
+
// "title",
|
|
215
|
+
"tref",
|
|
216
|
+
"tspan",
|
|
217
|
+
"use",
|
|
218
|
+
"view",
|
|
219
|
+
"vkern"]);
|
|
220
|
+
|
|
221
221
|
|
|
222
222
|
const SVGNamespace = {
|
|
223
223
|
xlink: "http://www.w3.org/1999/xlink",
|
|
@@ -225,33 +225,32 @@ const SVGNamespace = {
|
|
|
225
225
|
};
|
|
226
226
|
|
|
227
227
|
var VoidElements = [
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
];
|
|
228
|
+
'area',
|
|
229
|
+
'base',
|
|
230
|
+
'br',
|
|
231
|
+
'col',
|
|
232
|
+
'embed',
|
|
233
|
+
'hr',
|
|
234
|
+
'img',
|
|
235
|
+
'input',
|
|
236
|
+
'keygen',
|
|
237
|
+
'link',
|
|
238
|
+
'menuitem',
|
|
239
|
+
'meta',
|
|
240
|
+
'param',
|
|
241
|
+
'source',
|
|
242
|
+
'track',
|
|
243
|
+
'wbr'];
|
|
245
244
|
|
|
246
245
|
const reservedNameSpaces = new Set([
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
246
|
+
"class",
|
|
247
|
+
"on",
|
|
248
|
+
"oncapture",
|
|
249
|
+
"style",
|
|
250
|
+
"use",
|
|
251
|
+
"prop",
|
|
252
|
+
"attr"]);
|
|
253
|
+
|
|
255
254
|
|
|
256
255
|
const nonSpreadNameSpaces = new Set(["class", "style", "use", "prop", "attr"]);
|
|
257
256
|
|
|
@@ -261,13 +260,13 @@ function getConfig(path) {
|
|
|
261
260
|
|
|
262
261
|
const getRendererConfig = (path, renderer) => {
|
|
263
262
|
const config = getConfig(path);
|
|
264
|
-
return config?.renderers?.find(r => r.name === renderer) ?? config;
|
|
263
|
+
return config?.renderers?.find((r) => r.name === renderer) ?? config;
|
|
265
264
|
};
|
|
266
265
|
|
|
267
266
|
function registerImportMethod(path, name, moduleName) {
|
|
268
267
|
const imports =
|
|
269
|
-
|
|
270
|
-
|
|
268
|
+
path.scope.getProgramParent().data.imports || (
|
|
269
|
+
path.scope.getProgramParent().data.imports = new Map());
|
|
271
270
|
moduleName = moduleName || getConfig(path).moduleName;
|
|
272
271
|
if (!imports.has(`${moduleName}:${name}`)) {
|
|
273
272
|
let id = helperModuleImports.addNamed(path, name, moduleName, {
|
|
@@ -301,10 +300,10 @@ function getTagName(tag) {
|
|
|
301
300
|
|
|
302
301
|
function isComponent(tagName) {
|
|
303
302
|
return (
|
|
304
|
-
|
|
303
|
+
tagName[0] && tagName[0].toLowerCase() !== tagName[0] ||
|
|
305
304
|
tagName.includes(".") ||
|
|
306
|
-
/[^a-zA-Z]/.test(tagName[0])
|
|
307
|
-
|
|
305
|
+
/[^a-zA-Z]/.test(tagName[0]));
|
|
306
|
+
|
|
308
307
|
}
|
|
309
308
|
|
|
310
309
|
function isDynamic(path, { checkMember, checkTags, checkCallExpressions = true, native }) {
|
|
@@ -316,18 +315,18 @@ function isDynamic(path, { checkMember, checkTags, checkCallExpressions = true,
|
|
|
316
315
|
const expr = path.node;
|
|
317
316
|
if (t__namespace.isFunction(expr)) return false;
|
|
318
317
|
if (
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
318
|
+
expr.leadingComments &&
|
|
319
|
+
expr.leadingComments[0] &&
|
|
320
|
+
expr.leadingComments[0].value.trim() === config.staticMarker)
|
|
321
|
+
{
|
|
323
322
|
expr.leadingComments.shift();
|
|
324
323
|
return false;
|
|
325
324
|
}
|
|
326
325
|
|
|
327
326
|
if (
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
327
|
+
checkCallExpressions && (
|
|
328
|
+
t__namespace.isCallExpression(expr) || t__namespace.isOptionalCallExpression(expr)))
|
|
329
|
+
{
|
|
331
330
|
return true;
|
|
332
331
|
}
|
|
333
332
|
|
|
@@ -336,15 +335,15 @@ function isDynamic(path, { checkMember, checkTags, checkCallExpressions = true,
|
|
|
336
335
|
const object = path.get("object").node;
|
|
337
336
|
|
|
338
337
|
if (
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
338
|
+
t__namespace.isIdentifier(object) && (
|
|
339
|
+
!expr.computed ||
|
|
340
|
+
!isDynamic(path.get("property"), {
|
|
341
|
+
checkMember,
|
|
342
|
+
checkTags,
|
|
343
|
+
checkCallExpressions,
|
|
344
|
+
native
|
|
345
|
+
})))
|
|
346
|
+
{
|
|
348
347
|
const binding = path.scope.getBinding(object.name);
|
|
349
348
|
|
|
350
349
|
if (binding && binding.path.isImportNamespaceSpecifier()) {
|
|
@@ -356,15 +355,15 @@ function isDynamic(path, { checkMember, checkTags, checkCallExpressions = true,
|
|
|
356
355
|
}
|
|
357
356
|
|
|
358
357
|
if (
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
358
|
+
checkMember && (
|
|
359
|
+
t__namespace.isOptionalMemberExpression(expr) ||
|
|
360
|
+
t__namespace.isSpreadElement(expr) ||
|
|
361
|
+
t__namespace.isBinaryExpression(expr) && expr.operator === "in"))
|
|
362
|
+
{
|
|
364
363
|
return true;
|
|
365
364
|
}
|
|
366
365
|
|
|
367
|
-
if (checkTags && (t__namespace.isJSXElement(expr) ||
|
|
366
|
+
if (checkTags && (t__namespace.isJSXElement(expr) || t__namespace.isJSXFragment(expr) && expr.children.length)) {
|
|
368
367
|
return true;
|
|
369
368
|
}
|
|
370
369
|
|
|
@@ -412,28 +411,28 @@ function getStaticExpression(path) {
|
|
|
412
411
|
t__namespace.isJSXElement(path.parent) &&
|
|
413
412
|
!isComponent(getTagName(path.parent)) &&
|
|
414
413
|
!t__namespace.isSequenceExpression(node.expression) &&
|
|
415
|
-
(value = path.get("expression").evaluate().value) !== undefined &&
|
|
416
|
-
(
|
|
417
|
-
value
|
|
418
|
-
|
|
414
|
+
(value = path.get("expression").evaluate().value) !== undefined && (
|
|
415
|
+
(type = typeof value) === "string" || type === "number") &&
|
|
416
|
+
value);
|
|
417
|
+
|
|
419
418
|
}
|
|
420
419
|
|
|
421
420
|
// remove unnecessary JSX Text nodes
|
|
422
421
|
function filterChildren(children) {
|
|
423
422
|
return children.filter(
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
423
|
+
({ node: child }) =>
|
|
424
|
+
!(t__namespace.isJSXExpressionContainer(child) && t__namespace.isJSXEmptyExpression(child.expression)) && (
|
|
425
|
+
!t__namespace.isJSXText(child) || !/^[\r\n]\s*$/.test(child.extra.raw)));
|
|
426
|
+
|
|
428
427
|
}
|
|
429
428
|
|
|
430
429
|
function checkLength(children) {
|
|
431
430
|
let i = 0;
|
|
432
|
-
children.forEach(path => {
|
|
431
|
+
children.forEach((path) => {
|
|
433
432
|
const child = path.node;
|
|
434
|
-
!(t__namespace.isJSXExpressionContainer(child) && t__namespace.isJSXEmptyExpression(child.expression)) &&
|
|
435
|
-
|
|
436
|
-
|
|
433
|
+
!(t__namespace.isJSXExpressionContainer(child) && t__namespace.isJSXEmptyExpression(child.expression)) && (
|
|
434
|
+
!t__namespace.isJSXText(child) || !/^\s*$/.test(child.extra.raw) || /^ *$/.test(child.extra.raw)) &&
|
|
435
|
+
i++;
|
|
437
436
|
});
|
|
438
437
|
return i > 1;
|
|
439
438
|
}
|
|
@@ -441,11 +440,11 @@ function checkLength(children) {
|
|
|
441
440
|
function trimWhitespace(text) {
|
|
442
441
|
text = text.replace(/\r/g, "");
|
|
443
442
|
if (/\n/g.test(text)) {
|
|
444
|
-
text = text
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
443
|
+
text = text.
|
|
444
|
+
split("\n").
|
|
445
|
+
map((t, i) => i ? t.replace(/^\s*/g, "") : t).
|
|
446
|
+
filter((s) => !/^\s*$/.test(s)).
|
|
447
|
+
join(" ");
|
|
449
448
|
}
|
|
450
449
|
return text.replace(/\s+/g, " ");
|
|
451
450
|
}
|
|
@@ -487,20 +486,20 @@ function transformCondition(path, inline, deep) {
|
|
|
487
486
|
const memo = registerImportMethod(path, config.memoWrapper);
|
|
488
487
|
let dTest, cond, id;
|
|
489
488
|
if (
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
489
|
+
t__namespace.isConditionalExpression(expr) && (
|
|
490
|
+
isDynamic(path.get("consequent"), {
|
|
491
|
+
checkTags: true
|
|
492
|
+
}) ||
|
|
493
|
+
isDynamic(path.get("alternate"), { checkTags: true })))
|
|
494
|
+
{
|
|
496
495
|
dTest = isDynamic(path.get("test"), { checkMember: true });
|
|
497
496
|
if (dTest) {
|
|
498
497
|
cond = expr.test;
|
|
499
498
|
if (!t__namespace.isBinaryExpression(cond))
|
|
500
|
-
|
|
501
|
-
id = inline
|
|
502
|
-
|
|
503
|
-
|
|
499
|
+
cond = t__namespace.unaryExpression("!", t__namespace.unaryExpression("!", cond, true), true);
|
|
500
|
+
id = inline ?
|
|
501
|
+
t__namespace.callExpression(memo, [t__namespace.arrowFunctionExpression([], cond)]) :
|
|
502
|
+
path.scope.generateUidIdentifier("_c$");
|
|
504
503
|
expr.test = t__namespace.callExpression(id, []);
|
|
505
504
|
if (t__namespace.isConditionalExpression(expr.consequent) || t__namespace.isLogicalExpression(expr.consequent)) {
|
|
506
505
|
expr.consequent = transformCondition(path.get("consequent"), inline, true);
|
|
@@ -516,41 +515,41 @@ function transformCondition(path, inline, deep) {
|
|
|
516
515
|
nextPath = nextPath.get("left");
|
|
517
516
|
}
|
|
518
517
|
nextPath.node.operator === "&&" &&
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
518
|
+
isDynamic(nextPath.get("right"), { checkTags: true }) && (
|
|
519
|
+
dTest = isDynamic(nextPath.get("left"), {
|
|
520
|
+
checkMember: true
|
|
521
|
+
}));
|
|
523
522
|
if (dTest) {
|
|
524
523
|
cond = nextPath.node.left;
|
|
525
524
|
if (!t__namespace.isBinaryExpression(cond))
|
|
526
|
-
|
|
527
|
-
id = inline
|
|
528
|
-
|
|
529
|
-
|
|
525
|
+
cond = t__namespace.unaryExpression("!", t__namespace.unaryExpression("!", cond, true), true);
|
|
526
|
+
id = inline ?
|
|
527
|
+
t__namespace.callExpression(memo, [t__namespace.arrowFunctionExpression([], cond)]) :
|
|
528
|
+
path.scope.generateUidIdentifier("_c$");
|
|
530
529
|
nextPath.node.left = t__namespace.callExpression(id, []);
|
|
531
530
|
}
|
|
532
531
|
}
|
|
533
532
|
if (dTest && !inline) {
|
|
534
533
|
const statements = [
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
return deep
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
534
|
+
t__namespace.variableDeclaration("var", [
|
|
535
|
+
t__namespace.variableDeclarator(
|
|
536
|
+
id,
|
|
537
|
+
config.memoWrapper ?
|
|
538
|
+
t__namespace.callExpression(memo, [t__namespace.arrowFunctionExpression([], cond)]) :
|
|
539
|
+
t__namespace.arrowFunctionExpression([], cond))]),
|
|
540
|
+
|
|
541
|
+
|
|
542
|
+
t__namespace.arrowFunctionExpression([], expr)];
|
|
543
|
+
|
|
544
|
+
return deep ?
|
|
545
|
+
t__namespace.callExpression(
|
|
546
|
+
t__namespace.arrowFunctionExpression(
|
|
547
|
+
[],
|
|
548
|
+
t__namespace.blockStatement([statements[0], t__namespace.returnStatement(statements[1])])),
|
|
549
|
+
|
|
550
|
+
[]) :
|
|
551
|
+
|
|
552
|
+
statements;
|
|
554
553
|
}
|
|
555
554
|
return deep ? expr : t__namespace.arrowFunctionExpression([], expr);
|
|
556
555
|
}
|
|
@@ -609,9 +608,9 @@ function convertJSXIdentifier(node) {
|
|
|
609
608
|
}
|
|
610
609
|
} else if (t__namespace.isJSXMemberExpression(node)) {
|
|
611
610
|
return t__namespace.memberExpression(
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
611
|
+
convertJSXIdentifier(node.object),
|
|
612
|
+
convertJSXIdentifier(node.property));
|
|
613
|
+
|
|
615
614
|
} else if (t__namespace.isJSXNamespacedName(node)) {
|
|
616
615
|
return t__namespace.stringLiteral(`${node.namespace.name}:${node.name.name}`);
|
|
617
616
|
}
|
|
@@ -621,7 +620,7 @@ function convertJSXIdentifier(node) {
|
|
|
621
620
|
|
|
622
621
|
function canNativeSpread(key, { checkNameSpaces } = {}) {
|
|
623
622
|
if (checkNameSpaces && key.includes(":") && nonSpreadNameSpaces.has(key.split(":")[0]))
|
|
624
|
-
|
|
623
|
+
return false;
|
|
625
624
|
// TODO: figure out how to detect definitely function ref
|
|
626
625
|
if (key === "ref") return false;
|
|
627
626
|
return true;
|
|
@@ -644,146 +643,144 @@ function getNumberedId(num) {
|
|
|
644
643
|
}
|
|
645
644
|
|
|
646
645
|
function escapeStringForTemplate(str) {
|
|
647
|
-
|
|
646
|
+
return str.replace(/[{\\`\n\t\b\f\v\r\u2028\u2029]/g, (ch) => templateEscapes.get(ch));
|
|
648
647
|
}
|
|
649
648
|
|
|
650
649
|
const templateEscapes = new Map([
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
]);
|
|
650
|
+
['{', '\\{'],
|
|
651
|
+
['`', '\\`'],
|
|
652
|
+
['\\', '\\\\'],
|
|
653
|
+
['\n', '\\n'],
|
|
654
|
+
['\t', '\\t'],
|
|
655
|
+
['\b', '\\b'],
|
|
656
|
+
['\f', '\\f'],
|
|
657
|
+
['\v', '\\v'],
|
|
658
|
+
['\r', '\\r'],
|
|
659
|
+
['\u2028', '\\u2028'],
|
|
660
|
+
['\u2029', '\\u2029']]);
|
|
663
661
|
|
|
664
662
|
const InlineElements = [
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
663
|
+
"a",
|
|
664
|
+
"abbr",
|
|
665
|
+
"acronym",
|
|
666
|
+
"b",
|
|
667
|
+
"bdi",
|
|
668
|
+
"bdo",
|
|
669
|
+
"big",
|
|
670
|
+
"br",
|
|
671
|
+
"button",
|
|
672
|
+
"canvas",
|
|
673
|
+
"cite",
|
|
674
|
+
"code",
|
|
675
|
+
"data",
|
|
676
|
+
"datalist",
|
|
677
|
+
"del",
|
|
678
|
+
"dfn",
|
|
679
|
+
"em",
|
|
680
|
+
"embed",
|
|
681
|
+
"i",
|
|
682
|
+
"iframe",
|
|
683
|
+
"img",
|
|
684
|
+
"input",
|
|
685
|
+
"ins",
|
|
686
|
+
"kbd",
|
|
687
|
+
"label",
|
|
688
|
+
"map",
|
|
689
|
+
"mark",
|
|
690
|
+
"meter",
|
|
691
|
+
"noscript",
|
|
692
|
+
"object",
|
|
693
|
+
"output",
|
|
694
|
+
"picture",
|
|
695
|
+
"progress",
|
|
696
|
+
"q",
|
|
697
|
+
"ruby",
|
|
698
|
+
"s",
|
|
699
|
+
"samp",
|
|
700
|
+
"script",
|
|
701
|
+
"select",
|
|
702
|
+
"slot",
|
|
703
|
+
"small",
|
|
704
|
+
"span",
|
|
705
|
+
"strong",
|
|
706
|
+
"sub",
|
|
707
|
+
"sup",
|
|
708
|
+
"svg",
|
|
709
|
+
"template",
|
|
710
|
+
"textarea",
|
|
711
|
+
"time",
|
|
712
|
+
"u",
|
|
713
|
+
"tt",
|
|
714
|
+
"var",
|
|
715
|
+
"video"];
|
|
716
|
+
|
|
719
717
|
|
|
720
718
|
const BlockElements = [
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
];
|
|
719
|
+
"address",
|
|
720
|
+
"article",
|
|
721
|
+
"aside",
|
|
722
|
+
"blockquote",
|
|
723
|
+
"dd",
|
|
724
|
+
"details",
|
|
725
|
+
"dialog",
|
|
726
|
+
"div",
|
|
727
|
+
"dl",
|
|
728
|
+
"dt",
|
|
729
|
+
"fieldset",
|
|
730
|
+
"figcaption",
|
|
731
|
+
"figure",
|
|
732
|
+
"footer",
|
|
733
|
+
"form",
|
|
734
|
+
"h1",
|
|
735
|
+
"h2",
|
|
736
|
+
"h3",
|
|
737
|
+
"h4",
|
|
738
|
+
"h5",
|
|
739
|
+
"h6",
|
|
740
|
+
"header",
|
|
741
|
+
"hgroup",
|
|
742
|
+
"hr",
|
|
743
|
+
"li",
|
|
744
|
+
"main",
|
|
745
|
+
"menu",
|
|
746
|
+
"nav",
|
|
747
|
+
"ol",
|
|
748
|
+
"p",
|
|
749
|
+
"pre",
|
|
750
|
+
"section",
|
|
751
|
+
"table",
|
|
752
|
+
"ul"];
|
|
756
753
|
|
|
757
754
|
const alwaysClose = [
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
755
|
+
"title",
|
|
756
|
+
"style",
|
|
757
|
+
"a",
|
|
758
|
+
"strong",
|
|
759
|
+
"small",
|
|
760
|
+
"b",
|
|
761
|
+
"u",
|
|
762
|
+
"i",
|
|
763
|
+
"em",
|
|
764
|
+
"s",
|
|
765
|
+
"code",
|
|
766
|
+
"object",
|
|
767
|
+
"table",
|
|
768
|
+
"button",
|
|
769
|
+
"textarea",
|
|
770
|
+
"select",
|
|
771
|
+
"iframe",
|
|
772
|
+
"script",
|
|
773
|
+
"noscript",
|
|
774
|
+
"template",
|
|
775
|
+
"fieldset"];
|
|
776
|
+
|
|
780
777
|
|
|
781
778
|
function transformElement$3(path, info) {
|
|
782
779
|
let tagName = getTagName(path.node),
|
|
783
780
|
config = getConfig(path),
|
|
784
781
|
wrapSVG = info.topLevel && tagName != "svg" && SVGElements.has(tagName),
|
|
785
782
|
voidTag = VoidElements.indexOf(tagName) > -1,
|
|
786
|
-
isCustomElement = tagName.indexOf("-") > -1 || !!path.get("openingElement").get("attributes").find(a => a.node.name?.name === "is"),
|
|
783
|
+
isCustomElement = tagName.indexOf("-") > -1 || !!path.get("openingElement").get("attributes").find((a) => a.node.name?.name === "is"),
|
|
787
784
|
results = {
|
|
788
785
|
template: `<${tagName}`,
|
|
789
786
|
declarations: [],
|
|
@@ -800,20 +797,20 @@ function transformElement$3(path, info) {
|
|
|
800
797
|
results.skipTemplate = true;
|
|
801
798
|
if (tagName === "head" && info.topLevel) {
|
|
802
799
|
const createComponent = registerImportMethod(
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
800
|
+
path,
|
|
801
|
+
"createComponent",
|
|
802
|
+
getRendererConfig(path, "dom").moduleName);
|
|
803
|
+
|
|
807
804
|
const NoHydration = registerImportMethod(
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
805
|
+
path,
|
|
806
|
+
"NoHydration",
|
|
807
|
+
getRendererConfig(path, "dom").moduleName);
|
|
808
|
+
|
|
812
809
|
results.exprs.push(
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
810
|
+
t__namespace.expressionStatement(
|
|
811
|
+
t__namespace.callExpression(createComponent, [NoHydration, t__namespace.objectExpression([])])));
|
|
812
|
+
|
|
813
|
+
|
|
817
814
|
return results;
|
|
818
815
|
}
|
|
819
816
|
}
|
|
@@ -827,22 +824,22 @@ function transformElement$3(path, info) {
|
|
|
827
824
|
if (!voidTag) {
|
|
828
825
|
// always close tags can still be skipped if they have no closing parents and are the last element
|
|
829
826
|
const toBeClosed =
|
|
830
|
-
|
|
831
|
-
|
|
827
|
+
!info.lastElement ||
|
|
828
|
+
info.toBeClosed && (!config.omitNestedClosingTags || info.toBeClosed.has(tagName));
|
|
832
829
|
if (toBeClosed) {
|
|
833
830
|
results.toBeClosed = new Set(info.toBeClosed || alwaysClose);
|
|
834
831
|
results.toBeClosed.add(tagName);
|
|
835
|
-
if (InlineElements.includes(tagName)) BlockElements.forEach(i => results.toBeClosed.add(i));
|
|
832
|
+
if (InlineElements.includes(tagName)) BlockElements.forEach((i) => results.toBeClosed.add(i));
|
|
836
833
|
} else results.toBeClosed = info.toBeClosed;
|
|
837
834
|
if (tagName !== "noscript") transformChildren$2(path, results, config);
|
|
838
835
|
if (toBeClosed) results.template += `</${tagName}>`;
|
|
839
836
|
}
|
|
840
837
|
if (info.topLevel && config.hydratable && results.hasHydratableEvent) {
|
|
841
838
|
let runHydrationEvents = registerImportMethod(
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
839
|
+
path,
|
|
840
|
+
"runHydrationEvents",
|
|
841
|
+
getRendererConfig(path, "dom").moduleName);
|
|
842
|
+
|
|
846
843
|
results.postExprs.push(t__namespace.expressionStatement(t__namespace.callExpression(runHydrationEvents, [])));
|
|
847
844
|
}
|
|
848
845
|
if (wrapSVG) results.template += "</svg>";
|
|
@@ -862,73 +859,73 @@ function setAttr$2(path, elem, name, value, { isSVG, dynamic, prevId, isCE, tagN
|
|
|
862
859
|
if (namespace === "style") {
|
|
863
860
|
if (t__namespace.isStringLiteral(value)) {
|
|
864
861
|
return t__namespace.callExpression(
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
862
|
+
t__namespace.memberExpression(
|
|
863
|
+
t__namespace.memberExpression(elem, t__namespace.identifier("style")),
|
|
864
|
+
t__namespace.identifier("setProperty")),
|
|
865
|
+
|
|
866
|
+
[t__namespace.stringLiteral(name), value]);
|
|
867
|
+
|
|
871
868
|
}
|
|
872
869
|
if (t__namespace.isNullLiteral(value) || t__namespace.isIdentifier(value, { name: "undefined" })) {
|
|
873
870
|
return t__namespace.callExpression(
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
871
|
+
t__namespace.memberExpression(
|
|
872
|
+
t__namespace.memberExpression(elem, t__namespace.identifier("style")),
|
|
873
|
+
t__namespace.identifier("removeProperty")),
|
|
874
|
+
|
|
875
|
+
[t__namespace.stringLiteral(name)]);
|
|
876
|
+
|
|
880
877
|
}
|
|
881
878
|
return t__namespace.conditionalExpression(
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
879
|
+
t__namespace.binaryExpression("!=", value, t__namespace.nullLiteral()),
|
|
880
|
+
t__namespace.callExpression(
|
|
881
|
+
t__namespace.memberExpression(
|
|
882
|
+
t__namespace.memberExpression(elem, t__namespace.identifier("style")),
|
|
883
|
+
t__namespace.identifier("setProperty")),
|
|
884
|
+
|
|
885
|
+
[t__namespace.stringLiteral(name), prevId ? prevId : value]),
|
|
886
|
+
|
|
887
|
+
t__namespace.callExpression(
|
|
888
|
+
t__namespace.memberExpression(
|
|
889
|
+
t__namespace.memberExpression(elem, t__namespace.identifier("style")),
|
|
890
|
+
t__namespace.identifier("removeProperty")),
|
|
891
|
+
|
|
892
|
+
[t__namespace.stringLiteral(name)]));
|
|
893
|
+
|
|
894
|
+
|
|
898
895
|
}
|
|
899
896
|
|
|
900
897
|
if (namespace === "class") {
|
|
901
898
|
return t__namespace.callExpression(
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
899
|
+
t__namespace.memberExpression(
|
|
900
|
+
t__namespace.memberExpression(elem, t__namespace.identifier("classList")),
|
|
901
|
+
t__namespace.identifier("toggle")),
|
|
902
|
+
|
|
903
|
+
[
|
|
904
|
+
t__namespace.stringLiteral(name),
|
|
905
|
+
dynamic ? value : t__namespace.unaryExpression("!", t__namespace.unaryExpression("!", value))]);
|
|
906
|
+
|
|
907
|
+
|
|
911
908
|
}
|
|
912
909
|
|
|
913
910
|
if (name === "style") {
|
|
914
911
|
return t__namespace.callExpression(
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
912
|
+
registerImportMethod(path, "style", getRendererConfig(path, "dom").moduleName),
|
|
913
|
+
prevId ? [elem, value, prevId] : [elem, value]);
|
|
914
|
+
|
|
918
915
|
}
|
|
919
916
|
|
|
920
917
|
if (!isSVG && name === "class") {
|
|
921
918
|
return t__namespace.callExpression(
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
919
|
+
registerImportMethod(path, "className", getRendererConfig(path, "dom").moduleName),
|
|
920
|
+
[elem, value]);
|
|
921
|
+
|
|
925
922
|
}
|
|
926
923
|
|
|
927
924
|
if (name === "classList") {
|
|
928
925
|
return t__namespace.callExpression(
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
926
|
+
registerImportMethod(path, "classList", getRendererConfig(path, "dom").moduleName),
|
|
927
|
+
prevId ? [elem, value, prevId] : [elem, value]);
|
|
928
|
+
|
|
932
929
|
}
|
|
933
930
|
|
|
934
931
|
if (dynamic && name === "textContent") {
|
|
@@ -941,16 +938,16 @@ function setAttr$2(path, elem, name, value, { isSVG, dynamic, prevId, isCE, tagN
|
|
|
941
938
|
const isChildProp = ChildProperties.has(name);
|
|
942
939
|
const isProp = Properties.has(name);
|
|
943
940
|
const alias = getPropAlias(name, tagName.toUpperCase());
|
|
944
|
-
if (namespace !== "attr" && (isChildProp ||
|
|
941
|
+
if (namespace !== "attr" && (isChildProp || !isSVG && isProp || isCE || namespace === "prop")) {
|
|
945
942
|
if (isCE && !isChildProp && !isProp && namespace !== "prop") name = toPropertyName(name);
|
|
946
943
|
if (config.hydratable && namespace !== "prop") {
|
|
947
944
|
return t__namespace.callExpression(registerImportMethod(path, "setProperty"), [elem, t__namespace.stringLiteral(name), value]);
|
|
948
945
|
}
|
|
949
946
|
return t__namespace.assignmentExpression(
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
947
|
+
"=",
|
|
948
|
+
t__namespace.memberExpression(elem, t__namespace.identifier(alias || name)),
|
|
949
|
+
value);
|
|
950
|
+
|
|
954
951
|
}
|
|
955
952
|
|
|
956
953
|
let isNameSpaced = name.indexOf(":") > -1;
|
|
@@ -959,14 +956,14 @@ function setAttr$2(path, elem, name, value, { isSVG, dynamic, prevId, isCE, tagN
|
|
|
959
956
|
const ns = isNameSpaced && SVGNamespace[name.split(":")[0]];
|
|
960
957
|
if (ns) {
|
|
961
958
|
return t__namespace.callExpression(
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
959
|
+
registerImportMethod(path, "setAttributeNS", getRendererConfig(path, "dom").moduleName),
|
|
960
|
+
[elem, t__namespace.stringLiteral(ns), t__namespace.stringLiteral(name), value]);
|
|
961
|
+
|
|
965
962
|
} else {
|
|
966
963
|
return t__namespace.callExpression(
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
964
|
+
registerImportMethod(path, "setAttribute", getRendererConfig(path, "dom").moduleName),
|
|
965
|
+
[elem, t__namespace.stringLiteral(name), value]);
|
|
966
|
+
|
|
970
967
|
}
|
|
971
968
|
}
|
|
972
969
|
|
|
@@ -997,7 +994,7 @@ function transformAttributes$2(path, results) {
|
|
|
997
994
|
config = getConfig(path);
|
|
998
995
|
|
|
999
996
|
// preprocess spreads
|
|
1000
|
-
if (attributes.some(attribute => t__namespace.isJSXSpreadAttribute(attribute.node))) {
|
|
997
|
+
if (attributes.some((attribute) => t__namespace.isJSXSpreadAttribute(attribute.node))) {
|
|
1001
998
|
[attributes, spreadExpr] = processSpreads$1(path, attributes, {
|
|
1002
999
|
elem,
|
|
1003
1000
|
isSVG,
|
|
@@ -1005,66 +1002,66 @@ function transformAttributes$2(path, results) {
|
|
|
1005
1002
|
wrapConditionals: config.wrapConditionals
|
|
1006
1003
|
});
|
|
1007
1004
|
path.get("openingElement").set(
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1005
|
+
"attributes",
|
|
1006
|
+
attributes.map((a) => a.node));
|
|
1007
|
+
|
|
1011
1008
|
//NOTE: can't be checked at compile time so add to compiled output
|
|
1012
1009
|
hasHydratableEvent = true;
|
|
1013
1010
|
}
|
|
1014
1011
|
|
|
1015
1012
|
// preprocess styles
|
|
1016
|
-
const styleAttribute = path
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1013
|
+
const styleAttribute = path.
|
|
1014
|
+
get("openingElement").
|
|
1015
|
+
get("attributes").
|
|
1016
|
+
find(
|
|
1017
|
+
(a) =>
|
|
1018
|
+
a.node.name &&
|
|
1019
|
+
a.node.name.name === "style" &&
|
|
1020
|
+
t__namespace.isJSXExpressionContainer(a.node.value) &&
|
|
1021
|
+
t__namespace.isObjectExpression(a.node.value.expression) &&
|
|
1022
|
+
!a.node.value.expression.properties.some((p) => t__namespace.isSpreadElement(p)));
|
|
1023
|
+
|
|
1027
1024
|
if (styleAttribute) {
|
|
1028
1025
|
let i = 0,
|
|
1029
1026
|
leading = styleAttribute.node.value.expression.leadingComments;
|
|
1030
1027
|
styleAttribute.node.value.expression.properties.slice().forEach((p, index) => {
|
|
1031
1028
|
if (!p.computed) {
|
|
1032
1029
|
if (leading) p.value.leadingComments = leading;
|
|
1033
|
-
path
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1030
|
+
path.
|
|
1031
|
+
get("openingElement").
|
|
1032
|
+
node.attributes.splice(
|
|
1033
|
+
styleAttribute.key + ++i,
|
|
1034
|
+
0,
|
|
1035
|
+
t__namespace.jsxAttribute(
|
|
1036
|
+
t__namespace.jsxNamespacedName(
|
|
1037
|
+
t__namespace.jsxIdentifier("style"),
|
|
1038
|
+
t__namespace.jsxIdentifier(t__namespace.isIdentifier(p.key) ? p.key.name : p.key.value)),
|
|
1039
|
+
|
|
1040
|
+
t__namespace.jsxExpressionContainer(p.value)));
|
|
1041
|
+
|
|
1042
|
+
|
|
1046
1043
|
styleAttribute.node.value.expression.properties.splice(index - i - 1, 1);
|
|
1047
1044
|
}
|
|
1048
1045
|
});
|
|
1049
1046
|
if (!styleAttribute.node.value.expression.properties.length)
|
|
1050
|
-
|
|
1047
|
+
path.get("openingElement").node.attributes.splice(styleAttribute.key, 1);
|
|
1051
1048
|
}
|
|
1052
1049
|
|
|
1053
1050
|
// preprocess classList
|
|
1054
1051
|
attributes = path.get("openingElement").get("attributes");
|
|
1055
1052
|
const classListAttribute = attributes.find(
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1053
|
+
(a) =>
|
|
1054
|
+
a.node.name &&
|
|
1055
|
+
a.node.name.name === "classList" &&
|
|
1056
|
+
t__namespace.isJSXExpressionContainer(a.node.value) &&
|
|
1057
|
+
t__namespace.isObjectExpression(a.node.value.expression) &&
|
|
1058
|
+
!a.node.value.expression.properties.some(
|
|
1059
|
+
(p) =>
|
|
1060
|
+
t__namespace.isSpreadElement(p) ||
|
|
1061
|
+
p.computed ||
|
|
1062
|
+
t__namespace.isStringLiteral(p.key) && (p.key.value.includes(" ") || p.key.value.includes(":"))));
|
|
1063
|
+
|
|
1064
|
+
|
|
1068
1065
|
if (classListAttribute) {
|
|
1069
1066
|
let i = 0,
|
|
1070
1067
|
leading = classListAttribute.node.value.expression.leadingComments,
|
|
@@ -1074,42 +1071,42 @@ function transformAttributes$2(path, results) {
|
|
|
1074
1071
|
const { confident, value: computed } = propPath.get("value").evaluate();
|
|
1075
1072
|
if (leading) p.value.leadingComments = leading;
|
|
1076
1073
|
if (!confident) {
|
|
1077
|
-
path
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1074
|
+
path.
|
|
1075
|
+
get("openingElement").
|
|
1076
|
+
node.attributes.splice(
|
|
1077
|
+
classListAttribute.key + ++i,
|
|
1078
|
+
0,
|
|
1079
|
+
t__namespace.jsxAttribute(
|
|
1080
|
+
t__namespace.jsxNamespacedName(
|
|
1081
|
+
t__namespace.jsxIdentifier("class"),
|
|
1082
|
+
t__namespace.jsxIdentifier(t__namespace.isIdentifier(p.key) ? p.key.name : p.key.value)),
|
|
1083
|
+
|
|
1084
|
+
t__namespace.jsxExpressionContainer(p.value)));
|
|
1085
|
+
|
|
1086
|
+
|
|
1090
1087
|
} else if (computed) {
|
|
1091
|
-
path
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1088
|
+
path.
|
|
1089
|
+
get("openingElement").
|
|
1090
|
+
node.attributes.splice(
|
|
1091
|
+
classListAttribute.key + ++i,
|
|
1092
|
+
0,
|
|
1093
|
+
t__namespace.jsxAttribute(
|
|
1094
|
+
t__namespace.jsxIdentifier("class"),
|
|
1095
|
+
t__namespace.stringLiteral(t__namespace.isIdentifier(p.key) ? p.key.name : p.key.value)));
|
|
1096
|
+
|
|
1097
|
+
|
|
1101
1098
|
}
|
|
1102
1099
|
classListProperties.splice(index - i - 1, 1);
|
|
1103
1100
|
});
|
|
1104
1101
|
if (!classListProperties.length)
|
|
1105
|
-
|
|
1102
|
+
path.get("openingElement").node.attributes.splice(classListAttribute.key, 1);
|
|
1106
1103
|
}
|
|
1107
1104
|
|
|
1108
1105
|
// combine class properties
|
|
1109
1106
|
attributes = path.get("openingElement").get("attributes");
|
|
1110
1107
|
const classAttributes = attributes.filter(
|
|
1111
|
-
|
|
1112
|
-
|
|
1108
|
+
(a) => a.node.name && (a.node.name.name === "class" || a.node.name.name === "className"));
|
|
1109
|
+
|
|
1113
1110
|
if (classAttributes.length > 1) {
|
|
1114
1111
|
const first = classAttributes[0].node,
|
|
1115
1112
|
values = [],
|
|
@@ -1120,377 +1117,377 @@ function transformAttributes$2(path, results) {
|
|
|
1120
1117
|
if (!t__namespace.isJSXExpressionContainer(attr.value)) {
|
|
1121
1118
|
const prev = quasis.pop();
|
|
1122
1119
|
quasis.push(
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1120
|
+
t__namespace.templateElement({
|
|
1121
|
+
raw: (prev ? prev.value.raw : "") + `${attr.value.value}` + (isLast ? "" : " ")
|
|
1122
|
+
}));
|
|
1123
|
+
|
|
1127
1124
|
} else {
|
|
1128
1125
|
values.push(t__namespace.logicalExpression("||", attr.value.expression, t__namespace.stringLiteral("")));
|
|
1129
1126
|
quasis.push(t__namespace.templateElement({ raw: isLast ? "" : " " }));
|
|
1130
1127
|
}
|
|
1131
1128
|
i && attributes.splice(attributes.indexOf(classAttributes[i]), 1);
|
|
1132
1129
|
}
|
|
1133
|
-
if (values.length) first.value = t__namespace.jsxExpressionContainer(t__namespace.templateLiteral(quasis, values));
|
|
1134
|
-
|
|
1130
|
+
if (values.length) first.value = t__namespace.jsxExpressionContainer(t__namespace.templateLiteral(quasis, values));else
|
|
1131
|
+
first.value = t__namespace.stringLiteral(quasis[0].value.raw);
|
|
1135
1132
|
}
|
|
1136
1133
|
path.get("openingElement").set(
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1134
|
+
"attributes",
|
|
1135
|
+
attributes.map((a) => a.node));
|
|
1136
|
+
|
|
1140
1137
|
|
|
1141
1138
|
let needsSpacing = true;
|
|
1142
1139
|
|
|
1143
|
-
path
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
if (
|
|
1158
|
-
evaluated !== undefined &&
|
|
1159
|
-
((type = typeof evaluated) === "string" || type === "number")
|
|
1160
|
-
) {
|
|
1161
|
-
if (type === "number" && (Properties.has(key) || key.startsWith("prop:"))) {
|
|
1162
|
-
value = t__namespace.jsxExpressionContainer(t__namespace.numericLiteral(evaluated));
|
|
1163
|
-
} else value = t__namespace.stringLiteral(String(evaluated));
|
|
1164
|
-
}
|
|
1165
|
-
}
|
|
1140
|
+
path.
|
|
1141
|
+
get("openingElement").
|
|
1142
|
+
get("attributes").
|
|
1143
|
+
forEach((attribute) => {
|
|
1144
|
+
const node = attribute.node;
|
|
1145
|
+
let value = node.value,
|
|
1146
|
+
key = t__namespace.isJSXNamespacedName(node.name) ?
|
|
1147
|
+
`${node.name.namespace.name}:${node.name.name.name}` :
|
|
1148
|
+
node.name.name,
|
|
1149
|
+
reservedNameSpace =
|
|
1150
|
+
t__namespace.isJSXNamespacedName(node.name) && reservedNameSpaces.has(node.name.namespace.name);
|
|
1151
|
+
if (t__namespace.isJSXExpressionContainer(value) && !key.startsWith("use:")) {
|
|
1152
|
+
const evaluated = attribute.get("value").get("expression").evaluate().value;
|
|
1153
|
+
let type;
|
|
1166
1154
|
if (
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
|
|
1155
|
+
evaluated !== undefined && (
|
|
1156
|
+
(type = typeof evaluated) === "string" || type === "number"))
|
|
1157
|
+
{
|
|
1158
|
+
if (type === "number" && (Properties.has(key) || key.startsWith("prop:"))) {
|
|
1159
|
+
value = t__namespace.jsxExpressionContainer(t__namespace.numericLiteral(evaluated));
|
|
1160
|
+
} else value = t__namespace.stringLiteral(String(evaluated));
|
|
1172
1161
|
}
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1162
|
+
}
|
|
1163
|
+
if (
|
|
1164
|
+
t__namespace.isJSXNamespacedName(node.name) &&
|
|
1165
|
+
reservedNameSpace &&
|
|
1166
|
+
!t__namespace.isJSXExpressionContainer(value))
|
|
1167
|
+
{
|
|
1168
|
+
node.value = value = t__namespace.jsxExpressionContainer(value || t__namespace.jsxEmptyExpression());
|
|
1169
|
+
}
|
|
1170
|
+
if (
|
|
1171
|
+
t__namespace.isJSXExpressionContainer(value) && (
|
|
1172
|
+
reservedNameSpace ||
|
|
1173
|
+
!(t__namespace.isStringLiteral(value.expression) || t__namespace.isNumericLiteral(value.expression))))
|
|
1174
|
+
{
|
|
1175
|
+
if (key === "ref") {
|
|
1176
|
+
// Normalize expressions for non-null and type-as
|
|
1177
|
+
while (
|
|
1178
|
+
t__namespace.isTSNonNullExpression(value.expression) ||
|
|
1179
|
+
t__namespace.isTSAsExpression(value.expression))
|
|
1180
|
+
{
|
|
1181
|
+
value.expression = value.expression.expression;
|
|
1182
|
+
}
|
|
1183
|
+
let binding,
|
|
1184
|
+
isFunction =
|
|
1185
|
+
t__namespace.isIdentifier(value.expression) && (
|
|
1186
|
+
binding = path.scope.getBinding(value.expression.name)) &&
|
|
1187
|
+
binding.kind === "const";
|
|
1188
|
+
if (!isFunction && t__namespace.isLVal(value.expression)) {
|
|
1189
|
+
const refIdentifier = path.scope.generateUidIdentifier("_ref$");
|
|
1190
|
+
results.exprs.unshift(
|
|
1191
|
+
t__namespace.variableDeclaration("var", [
|
|
1192
|
+
t__namespace.variableDeclarator(refIdentifier, value.expression)]),
|
|
1193
|
+
|
|
1194
|
+
t__namespace.expressionStatement(
|
|
1195
|
+
t__namespace.conditionalExpression(
|
|
1196
|
+
t__namespace.binaryExpression(
|
|
1197
|
+
"===",
|
|
1198
|
+
t__namespace.unaryExpression("typeof", refIdentifier),
|
|
1199
|
+
t__namespace.stringLiteral("function")),
|
|
1200
|
+
|
|
1201
|
+
t__namespace.callExpression(
|
|
1202
|
+
registerImportMethod(path, "use", getRendererConfig(path, "dom").moduleName),
|
|
1203
|
+
[refIdentifier, elem]),
|
|
1204
|
+
|
|
1205
|
+
t__namespace.assignmentExpression("=", value.expression, elem))));
|
|
1206
|
+
|
|
1207
|
+
|
|
1208
|
+
|
|
1209
|
+
} else if (isFunction || t__namespace.isFunction(value.expression)) {
|
|
1210
|
+
results.exprs.unshift(
|
|
1211
|
+
t__namespace.expressionStatement(
|
|
1212
|
+
t__namespace.callExpression(
|
|
1213
|
+
registerImportMethod(path, "use", getRendererConfig(path, "dom").moduleName),
|
|
1214
|
+
[value.expression, elem])));
|
|
1215
|
+
|
|
1216
|
+
|
|
1217
|
+
|
|
1218
|
+
} else {
|
|
1219
|
+
const refIdentifier = path.scope.generateUidIdentifier("_ref$");
|
|
1220
|
+
results.exprs.unshift(
|
|
1221
|
+
t__namespace.variableDeclaration("var", [
|
|
1222
|
+
t__namespace.variableDeclarator(refIdentifier, value.expression)]),
|
|
1223
|
+
|
|
1224
|
+
t__namespace.expressionStatement(
|
|
1225
|
+
t__namespace.logicalExpression(
|
|
1226
|
+
"&&",
|
|
1227
|
+
t__namespace.binaryExpression(
|
|
1228
|
+
"===",
|
|
1229
|
+
t__namespace.unaryExpression("typeof", refIdentifier),
|
|
1230
|
+
t__namespace.stringLiteral("function")),
|
|
1231
|
+
|
|
1232
|
+
t__namespace.callExpression(
|
|
1233
|
+
registerImportMethod(path, "use", getRendererConfig(path, "dom").moduleName),
|
|
1234
|
+
[refIdentifier, elem]))));
|
|
1235
|
+
|
|
1236
|
+
|
|
1237
|
+
|
|
1238
|
+
|
|
1239
|
+
}
|
|
1240
|
+
} else if (key.startsWith("use:")) {
|
|
1241
|
+
// Some trick to treat JSXIdentifier as Identifier
|
|
1242
|
+
node.name.name.type = "Identifier";
|
|
1243
|
+
results.exprs.unshift(
|
|
1244
|
+
t__namespace.expressionStatement(
|
|
1245
|
+
t__namespace.callExpression(
|
|
1246
|
+
registerImportMethod(path, "use", getRendererConfig(path, "dom").moduleName),
|
|
1247
|
+
[
|
|
1248
|
+
node.name.name,
|
|
1249
|
+
elem,
|
|
1250
|
+
t__namespace.arrowFunctionExpression(
|
|
1251
|
+
[],
|
|
1252
|
+
t__namespace.isJSXEmptyExpression(value.expression) ?
|
|
1253
|
+
t__namespace.booleanLiteral(true) :
|
|
1254
|
+
value.expression)])));
|
|
1255
|
+
|
|
1256
|
+
|
|
1257
|
+
|
|
1258
|
+
|
|
1259
|
+
|
|
1260
|
+
} else if (key === "children") {
|
|
1261
|
+
children = value;
|
|
1262
|
+
} else if (key.startsWith("on")) {
|
|
1263
|
+
const ev = toEventName(key);
|
|
1264
|
+
if (key.startsWith("on:") || key.startsWith("oncapture:")) {
|
|
1265
|
+
const listenerOptions = [t__namespace.stringLiteral(key.split(":")[1]), value.expression];
|
|
1266
|
+
results.exprs.push(
|
|
1267
|
+
t__namespace.expressionStatement(
|
|
1268
|
+
t__namespace.callExpression(
|
|
1269
|
+
t__namespace.memberExpression(elem, t__namespace.identifier("addEventListener")),
|
|
1270
|
+
key.startsWith("oncapture:") ?
|
|
1271
|
+
listenerOptions.concat(t__namespace.booleanLiteral(true)) :
|
|
1272
|
+
listenerOptions)));
|
|
1273
|
+
|
|
1274
|
+
|
|
1275
|
+
|
|
1276
|
+
} else if (
|
|
1277
|
+
config.delegateEvents && (
|
|
1278
|
+
DelegatedEvents.has(ev) || config.delegatedEvents.indexOf(ev) !== -1))
|
|
1279
|
+
{
|
|
1280
|
+
// can only hydrate delegated events
|
|
1281
|
+
hasHydratableEvent = true;
|
|
1282
|
+
const events =
|
|
1283
|
+
attribute.scope.getProgramParent().data.events || (
|
|
1284
|
+
attribute.scope.getProgramParent().data.events = new Set());
|
|
1285
|
+
events.add(ev);
|
|
1286
|
+
let handler = value.expression;
|
|
1287
|
+
const resolveable = detectResolvableEventHandler(attribute, handler);
|
|
1288
|
+
if (t__namespace.isArrayExpression(handler)) {
|
|
1289
|
+
if (handler.elements.length > 1) {
|
|
1290
|
+
results.exprs.unshift(
|
|
1197
1291
|
t__namespace.expressionStatement(
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
),
|
|
1208
|
-
t__namespace.assignmentExpression("=", value.expression, elem)
|
|
1209
|
-
)
|
|
1210
|
-
)
|
|
1211
|
-
);
|
|
1212
|
-
} else if (isFunction || t__namespace.isFunction(value.expression)) {
|
|
1292
|
+
t__namespace.assignmentExpression(
|
|
1293
|
+
"=",
|
|
1294
|
+
t__namespace.memberExpression(elem, t__namespace.identifier(`$$${ev}Data`)),
|
|
1295
|
+
handler.elements[1])));
|
|
1296
|
+
|
|
1297
|
+
|
|
1298
|
+
|
|
1299
|
+
}
|
|
1300
|
+
handler = handler.elements[0];
|
|
1213
1301
|
results.exprs.unshift(
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1302
|
+
t__namespace.expressionStatement(
|
|
1303
|
+
t__namespace.assignmentExpression(
|
|
1304
|
+
"=",
|
|
1305
|
+
t__namespace.memberExpression(elem, t__namespace.identifier(`$$${ev}`)),
|
|
1306
|
+
handler)));
|
|
1307
|
+
|
|
1308
|
+
|
|
1309
|
+
|
|
1310
|
+
} else if (t__namespace.isFunction(handler) || resolveable) {
|
|
1311
|
+
results.exprs.unshift(
|
|
1312
|
+
t__namespace.expressionStatement(
|
|
1313
|
+
t__namespace.assignmentExpression(
|
|
1314
|
+
"=",
|
|
1315
|
+
t__namespace.memberExpression(elem, t__namespace.identifier(`$$${ev}`)),
|
|
1316
|
+
handler)));
|
|
1317
|
+
|
|
1318
|
+
|
|
1319
|
+
|
|
1221
1320
|
} else {
|
|
1222
|
-
const refIdentifier = path.scope.generateUidIdentifier("_ref$");
|
|
1223
1321
|
results.exprs.unshift(
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
t__namespace.callExpression(
|
|
1236
|
-
registerImportMethod(path, "use", getRendererConfig(path, "dom").moduleName),
|
|
1237
|
-
[refIdentifier, elem]
|
|
1238
|
-
)
|
|
1239
|
-
)
|
|
1240
|
-
)
|
|
1241
|
-
);
|
|
1322
|
+
t__namespace.expressionStatement(
|
|
1323
|
+
t__namespace.callExpression(
|
|
1324
|
+
registerImportMethod(
|
|
1325
|
+
path,
|
|
1326
|
+
"addEventListener",
|
|
1327
|
+
getRendererConfig(path, "dom").moduleName),
|
|
1328
|
+
|
|
1329
|
+
[elem, t__namespace.stringLiteral(ev), handler, t__namespace.booleanLiteral(true)])));
|
|
1330
|
+
|
|
1331
|
+
|
|
1332
|
+
|
|
1242
1333
|
}
|
|
1243
|
-
} else
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
|
|
1334
|
+
} else {
|
|
1335
|
+
let handler = value.expression;
|
|
1336
|
+
const resolveable = detectResolvableEventHandler(attribute, handler);
|
|
1337
|
+
if (t__namespace.isArrayExpression(handler)) {
|
|
1338
|
+
if (handler.elements.length > 1) {
|
|
1339
|
+
handler = t__namespace.arrowFunctionExpression(
|
|
1340
|
+
[t__namespace.identifier("e")],
|
|
1341
|
+
t__namespace.callExpression(handler.elements[0], [handler.elements[1], t__namespace.identifier("e")]));
|
|
1342
|
+
|
|
1343
|
+
} else handler = handler.elements[0];
|
|
1344
|
+
results.exprs.unshift(
|
|
1247
1345
|
t__namespace.expressionStatement(
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
} else if (key === "children") {
|
|
1264
|
-
children = value;
|
|
1265
|
-
} else if (key.startsWith("on")) {
|
|
1266
|
-
const ev = toEventName(key);
|
|
1267
|
-
if (key.startsWith("on:") || key.startsWith("oncapture:")) {
|
|
1268
|
-
const listenerOptions = [t__namespace.stringLiteral(key.split(":")[1]), value.expression];
|
|
1269
|
-
results.exprs.push(
|
|
1270
|
-
t__namespace.expressionStatement(
|
|
1271
|
-
t__namespace.callExpression(
|
|
1272
|
-
t__namespace.memberExpression(elem, t__namespace.identifier("addEventListener")),
|
|
1273
|
-
key.startsWith("oncapture:")
|
|
1274
|
-
? listenerOptions.concat(t__namespace.booleanLiteral(true))
|
|
1275
|
-
: listenerOptions
|
|
1276
|
-
)
|
|
1277
|
-
)
|
|
1278
|
-
);
|
|
1279
|
-
} else if (
|
|
1280
|
-
config.delegateEvents &&
|
|
1281
|
-
(DelegatedEvents.has(ev) || config.delegatedEvents.indexOf(ev) !== -1)
|
|
1282
|
-
) {
|
|
1283
|
-
// can only hydrate delegated events
|
|
1284
|
-
hasHydratableEvent = true;
|
|
1285
|
-
const events =
|
|
1286
|
-
attribute.scope.getProgramParent().data.events ||
|
|
1287
|
-
(attribute.scope.getProgramParent().data.events = new Set());
|
|
1288
|
-
events.add(ev);
|
|
1289
|
-
let handler = value.expression;
|
|
1290
|
-
const resolveable = detectResolvableEventHandler(attribute, handler);
|
|
1291
|
-
if (t__namespace.isArrayExpression(handler)) {
|
|
1292
|
-
if (handler.elements.length > 1) {
|
|
1293
|
-
results.exprs.unshift(
|
|
1294
|
-
t__namespace.expressionStatement(
|
|
1295
|
-
t__namespace.assignmentExpression(
|
|
1296
|
-
"=",
|
|
1297
|
-
t__namespace.memberExpression(elem, t__namespace.identifier(`$$${ev}Data`)),
|
|
1298
|
-
handler.elements[1]
|
|
1299
|
-
)
|
|
1300
|
-
)
|
|
1301
|
-
);
|
|
1302
|
-
}
|
|
1303
|
-
handler = handler.elements[0];
|
|
1304
|
-
results.exprs.unshift(
|
|
1305
|
-
t__namespace.expressionStatement(
|
|
1306
|
-
t__namespace.assignmentExpression(
|
|
1307
|
-
"=",
|
|
1308
|
-
t__namespace.memberExpression(elem, t__namespace.identifier(`$$${ev}`)),
|
|
1309
|
-
handler
|
|
1310
|
-
)
|
|
1311
|
-
)
|
|
1312
|
-
);
|
|
1313
|
-
} else if (t__namespace.isFunction(handler) || resolveable) {
|
|
1314
|
-
results.exprs.unshift(
|
|
1315
|
-
t__namespace.expressionStatement(
|
|
1316
|
-
t__namespace.assignmentExpression(
|
|
1317
|
-
"=",
|
|
1318
|
-
t__namespace.memberExpression(elem, t__namespace.identifier(`$$${ev}`)),
|
|
1319
|
-
handler
|
|
1320
|
-
)
|
|
1321
|
-
)
|
|
1322
|
-
);
|
|
1323
|
-
} else {
|
|
1324
|
-
results.exprs.unshift(
|
|
1325
|
-
t__namespace.expressionStatement(
|
|
1326
|
-
t__namespace.callExpression(
|
|
1327
|
-
registerImportMethod(
|
|
1328
|
-
path,
|
|
1329
|
-
"addEventListener",
|
|
1330
|
-
getRendererConfig(path, "dom").moduleName
|
|
1331
|
-
),
|
|
1332
|
-
[elem, t__namespace.stringLiteral(ev), handler, t__namespace.booleanLiteral(true)]
|
|
1333
|
-
)
|
|
1334
|
-
)
|
|
1335
|
-
);
|
|
1336
|
-
}
|
|
1346
|
+
t__namespace.callExpression(t__namespace.memberExpression(elem, t__namespace.identifier("addEventListener")), [
|
|
1347
|
+
t__namespace.stringLiteral(ev),
|
|
1348
|
+
handler])));
|
|
1349
|
+
|
|
1350
|
+
|
|
1351
|
+
|
|
1352
|
+
} else if (t__namespace.isFunction(handler) || resolveable) {
|
|
1353
|
+
results.exprs.unshift(
|
|
1354
|
+
t__namespace.expressionStatement(
|
|
1355
|
+
t__namespace.callExpression(t__namespace.memberExpression(elem, t__namespace.identifier("addEventListener")), [
|
|
1356
|
+
t__namespace.stringLiteral(ev),
|
|
1357
|
+
handler])));
|
|
1358
|
+
|
|
1359
|
+
|
|
1360
|
+
|
|
1337
1361
|
} else {
|
|
1338
|
-
|
|
1339
|
-
|
|
1340
|
-
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
t__namespace.stringLiteral(ev),
|
|
1351
|
-
handler
|
|
1352
|
-
])
|
|
1353
|
-
)
|
|
1354
|
-
);
|
|
1355
|
-
} else if (t__namespace.isFunction(handler) || resolveable) {
|
|
1356
|
-
results.exprs.unshift(
|
|
1357
|
-
t__namespace.expressionStatement(
|
|
1358
|
-
t__namespace.callExpression(t__namespace.memberExpression(elem, t__namespace.identifier("addEventListener")), [
|
|
1359
|
-
t__namespace.stringLiteral(ev),
|
|
1360
|
-
handler
|
|
1361
|
-
])
|
|
1362
|
-
)
|
|
1363
|
-
);
|
|
1364
|
-
} else {
|
|
1365
|
-
results.exprs.unshift(
|
|
1366
|
-
t__namespace.expressionStatement(
|
|
1367
|
-
t__namespace.callExpression(
|
|
1368
|
-
registerImportMethod(
|
|
1369
|
-
path,
|
|
1370
|
-
"addEventListener",
|
|
1371
|
-
getRendererConfig(path, "dom").moduleName
|
|
1372
|
-
),
|
|
1373
|
-
[elem, t__namespace.stringLiteral(ev), handler]
|
|
1374
|
-
)
|
|
1375
|
-
)
|
|
1376
|
-
);
|
|
1377
|
-
}
|
|
1378
|
-
}
|
|
1379
|
-
} else if (
|
|
1380
|
-
config.effectWrapper &&
|
|
1381
|
-
(isDynamic(attribute.get("value").get("expression"), {
|
|
1382
|
-
checkMember: true
|
|
1383
|
-
}) ||
|
|
1384
|
-
((key === "classList" || key === "style") &&
|
|
1385
|
-
!attribute.get("value").get("expression").evaluate().confident))
|
|
1386
|
-
) {
|
|
1387
|
-
let nextElem = elem;
|
|
1388
|
-
if (key === "value" || key === "checked") {
|
|
1389
|
-
const effectWrapperId = registerImportMethod(path, config.effectWrapper);
|
|
1390
|
-
results.postExprs.push(
|
|
1391
|
-
t__namespace.expressionStatement(
|
|
1392
|
-
t__namespace.callExpression(effectWrapperId, [
|
|
1393
|
-
t__namespace.arrowFunctionExpression(
|
|
1394
|
-
[],
|
|
1395
|
-
setAttr$2(path, elem, key, value.expression, {
|
|
1396
|
-
tagName,
|
|
1397
|
-
isSVG,
|
|
1398
|
-
isCE
|
|
1399
|
-
})
|
|
1400
|
-
)
|
|
1401
|
-
])
|
|
1402
|
-
)
|
|
1403
|
-
);
|
|
1404
|
-
return;
|
|
1405
|
-
}
|
|
1406
|
-
if (key === "textContent") {
|
|
1407
|
-
nextElem = attribute.scope.generateUidIdentifier("el$");
|
|
1408
|
-
children = t__namespace.jsxText(" ");
|
|
1409
|
-
children.extra = { raw: " ", rawValue: " " };
|
|
1410
|
-
results.declarations.push(
|
|
1411
|
-
t__namespace.variableDeclarator(nextElem, t__namespace.memberExpression(elem, t__namespace.identifier("firstChild")))
|
|
1412
|
-
);
|
|
1362
|
+
results.exprs.unshift(
|
|
1363
|
+
t__namespace.expressionStatement(
|
|
1364
|
+
t__namespace.callExpression(
|
|
1365
|
+
registerImportMethod(
|
|
1366
|
+
path,
|
|
1367
|
+
"addEventListener",
|
|
1368
|
+
getRendererConfig(path, "dom").moduleName),
|
|
1369
|
+
|
|
1370
|
+
[elem, t__namespace.stringLiteral(ev), handler])));
|
|
1371
|
+
|
|
1372
|
+
|
|
1373
|
+
|
|
1413
1374
|
}
|
|
1414
|
-
|
|
1415
|
-
|
|
1416
|
-
|
|
1417
|
-
|
|
1375
|
+
}
|
|
1376
|
+
} else if (
|
|
1377
|
+
config.effectWrapper && (
|
|
1378
|
+
isDynamic(attribute.get("value").get("expression"), {
|
|
1379
|
+
checkMember: true
|
|
1380
|
+
}) ||
|
|
1381
|
+
(key === "classList" || key === "style") &&
|
|
1382
|
+
!attribute.get("value").get("expression").evaluate().confident))
|
|
1383
|
+
{
|
|
1384
|
+
let nextElem = elem;
|
|
1385
|
+
if (key === "value" || key === "checked") {
|
|
1386
|
+
const effectWrapperId = registerImportMethod(path, config.effectWrapper);
|
|
1387
|
+
results.postExprs.push(
|
|
1388
|
+
t__namespace.expressionStatement(
|
|
1389
|
+
t__namespace.callExpression(effectWrapperId, [
|
|
1390
|
+
t__namespace.arrowFunctionExpression(
|
|
1391
|
+
[],
|
|
1392
|
+
setAttr$2(path, elem, key, value.expression, {
|
|
1393
|
+
tagName,
|
|
1418
1394
|
isSVG,
|
|
1419
|
-
isCE
|
|
1420
|
-
|
|
1421
|
-
|
|
1422
|
-
|
|
1423
|
-
|
|
1424
|
-
|
|
1425
|
-
|
|
1426
|
-
)
|
|
1427
|
-
);
|
|
1395
|
+
isCE
|
|
1396
|
+
}))])));
|
|
1397
|
+
|
|
1398
|
+
|
|
1399
|
+
|
|
1400
|
+
|
|
1401
|
+
return;
|
|
1428
1402
|
}
|
|
1403
|
+
if (key === "textContent") {
|
|
1404
|
+
nextElem = attribute.scope.generateUidIdentifier("el$");
|
|
1405
|
+
children = t__namespace.jsxText(" ");
|
|
1406
|
+
children.extra = { raw: " ", rawValue: " " };
|
|
1407
|
+
results.declarations.push(
|
|
1408
|
+
t__namespace.variableDeclarator(nextElem, t__namespace.memberExpression(elem, t__namespace.identifier("firstChild"))));
|
|
1409
|
+
|
|
1410
|
+
}
|
|
1411
|
+
results.dynamics.push({
|
|
1412
|
+
elem: nextElem,
|
|
1413
|
+
key,
|
|
1414
|
+
value: value.expression,
|
|
1415
|
+
isSVG,
|
|
1416
|
+
isCE,
|
|
1417
|
+
tagName
|
|
1418
|
+
});
|
|
1419
|
+
} else {
|
|
1420
|
+
results.exprs.push(
|
|
1421
|
+
t__namespace.expressionStatement(
|
|
1422
|
+
setAttr$2(attribute, elem, key, value.expression, { isSVG, isCE, tagName })));
|
|
1423
|
+
|
|
1424
|
+
|
|
1425
|
+
}
|
|
1426
|
+
} else {
|
|
1427
|
+
if (config.hydratable && key === "$ServerOnly") {
|
|
1428
|
+
results.skipTemplate = true;
|
|
1429
|
+
return;
|
|
1430
|
+
}
|
|
1431
|
+
if (t__namespace.isJSXExpressionContainer(value)) value = value.expression;
|
|
1432
|
+
key = Aliases[key] || key;
|
|
1433
|
+
if (value && ChildProperties.has(key)) {
|
|
1434
|
+
results.exprs.push(
|
|
1435
|
+
t__namespace.expressionStatement(setAttr$2(attribute, elem, key, value, { isSVG, isCE, tagName })));
|
|
1436
|
+
|
|
1429
1437
|
} else {
|
|
1430
|
-
|
|
1431
|
-
|
|
1438
|
+
!isSVG && (key = key.toLowerCase());
|
|
1439
|
+
results.template += `${needsSpacing ? ' ' : ''}${key}`;
|
|
1440
|
+
if (!value) {
|
|
1441
|
+
needsSpacing = true;
|
|
1432
1442
|
return;
|
|
1433
1443
|
}
|
|
1434
|
-
if (t__namespace.isJSXExpressionContainer(value)) value = value.expression;
|
|
1435
|
-
key = Aliases[key] || key;
|
|
1436
|
-
if (value && ChildProperties.has(key)) {
|
|
1437
|
-
results.exprs.push(
|
|
1438
|
-
t__namespace.expressionStatement(setAttr$2(attribute, elem, key, value, { isSVG, isCE, tagName }))
|
|
1439
|
-
);
|
|
1440
|
-
} else {
|
|
1441
|
-
!isSVG && (key = key.toLowerCase());
|
|
1442
|
-
results.template += `${needsSpacing ? ' ' : ''}${key}`;
|
|
1443
|
-
if (!value) {
|
|
1444
|
-
needsSpacing = true;
|
|
1445
|
-
return;
|
|
1446
|
-
}
|
|
1447
1444
|
|
|
1448
|
-
|
|
1449
|
-
|
|
1450
|
-
|
|
1445
|
+
let text = value.value;
|
|
1446
|
+
if (typeof text === "number") text = String(text);
|
|
1447
|
+
let needsQuoting = false;
|
|
1451
1448
|
|
|
1452
|
-
|
|
1453
|
-
|
|
1454
|
-
|
|
1455
|
-
|
|
1456
|
-
}
|
|
1449
|
+
if (key === "style" || key === "class") {
|
|
1450
|
+
text = trimWhitespace(text);
|
|
1451
|
+
if (key === "style") {
|
|
1452
|
+
text = text.replace(/; /g, ";").replace(/: /g, ":");
|
|
1457
1453
|
}
|
|
1454
|
+
}
|
|
1458
1455
|
|
|
1459
|
-
|
|
1460
|
-
|
|
1461
|
-
|
|
1462
|
-
|
|
1463
|
-
|
|
1456
|
+
if (!text.length) {
|
|
1457
|
+
needsSpacing = false;
|
|
1458
|
+
results.template += `=""`;
|
|
1459
|
+
return;
|
|
1460
|
+
}
|
|
1464
1461
|
|
|
1465
|
-
|
|
1466
|
-
|
|
1467
|
-
|
|
1468
|
-
if (
|
|
1469
|
-
char === "'" ||
|
|
1470
|
-
char === '"' ||
|
|
1471
|
-
char === " " ||
|
|
1472
|
-
char === "\t" ||
|
|
1473
|
-
char === "\n" ||
|
|
1474
|
-
char === "\r" ||
|
|
1475
|
-
char === "`" ||
|
|
1476
|
-
char === "=" ||
|
|
1477
|
-
char === "<" ||
|
|
1478
|
-
char === ">"
|
|
1479
|
-
) {
|
|
1480
|
-
needsQuoting = true;
|
|
1481
|
-
}
|
|
1482
|
-
}
|
|
1462
|
+
for (let i = 0, len = text.length; i < len; i++) {
|
|
1463
|
+
let char = text[i];
|
|
1483
1464
|
|
|
1484
|
-
if (
|
|
1485
|
-
|
|
1486
|
-
|
|
1487
|
-
|
|
1488
|
-
|
|
1489
|
-
|
|
1465
|
+
if (
|
|
1466
|
+
char === "'" ||
|
|
1467
|
+
char === '"' ||
|
|
1468
|
+
char === " " ||
|
|
1469
|
+
char === "\t" ||
|
|
1470
|
+
char === "\n" ||
|
|
1471
|
+
char === "\r" ||
|
|
1472
|
+
char === "`" ||
|
|
1473
|
+
char === "=" ||
|
|
1474
|
+
char === "<" ||
|
|
1475
|
+
char === ">")
|
|
1476
|
+
{
|
|
1477
|
+
needsQuoting = true;
|
|
1490
1478
|
}
|
|
1491
1479
|
}
|
|
1480
|
+
|
|
1481
|
+
if (needsQuoting) {
|
|
1482
|
+
needsSpacing = false;
|
|
1483
|
+
results.template += `="${escapeHTML(text, true)}"`;
|
|
1484
|
+
} else {
|
|
1485
|
+
needsSpacing = true;
|
|
1486
|
+
results.template += `=${escapeHTML(text, true)}`;
|
|
1487
|
+
}
|
|
1492
1488
|
}
|
|
1493
|
-
}
|
|
1489
|
+
}
|
|
1490
|
+
});
|
|
1494
1491
|
if (!hasChildren && children) {
|
|
1495
1492
|
path.node.children.push(children);
|
|
1496
1493
|
}
|
|
@@ -1505,11 +1502,11 @@ function findLastElement(children, hydratable) {
|
|
|
1505
1502
|
for (let i = children.length - 1; i >= 0; i--) {
|
|
1506
1503
|
const node = children[i].node;
|
|
1507
1504
|
if (
|
|
1508
|
-
|
|
1509
|
-
|
|
1510
|
-
|
|
1511
|
-
|
|
1512
|
-
|
|
1505
|
+
hydratable ||
|
|
1506
|
+
t__namespace.isJSXText(node) ||
|
|
1507
|
+
getStaticExpression(children[i]) !== false ||
|
|
1508
|
+
t__namespace.isJSXElement(node) && (tagName = getTagName(node)) && !isComponent(tagName))
|
|
1509
|
+
{
|
|
1513
1510
|
lastElement = i;
|
|
1514
1511
|
break;
|
|
1515
1512
|
}
|
|
@@ -1528,8 +1525,8 @@ function transformChildren$2(path, results, config) {
|
|
|
1528
1525
|
childNodes = filteredChildren.reduce((memo, child, index) => {
|
|
1529
1526
|
if (child.isJSXFragment()) {
|
|
1530
1527
|
throw new Error(
|
|
1531
|
-
|
|
1532
|
-
|
|
1528
|
+
`Fragments can only be used top level in JSX. Not used under a <${tagName}>.`);
|
|
1529
|
+
|
|
1533
1530
|
}
|
|
1534
1531
|
const transformed = transformNode(child, {
|
|
1535
1532
|
toBeClosed: results.toBeClosed,
|
|
@@ -1556,20 +1553,20 @@ function transformChildren$2(path, results, config) {
|
|
|
1556
1553
|
if (child.tagName === "head") {
|
|
1557
1554
|
if (config.hydratable) {
|
|
1558
1555
|
const createComponent = registerImportMethod(
|
|
1559
|
-
|
|
1560
|
-
|
|
1561
|
-
|
|
1562
|
-
|
|
1556
|
+
path,
|
|
1557
|
+
"createComponent",
|
|
1558
|
+
getRendererConfig(path, "dom").moduleName);
|
|
1559
|
+
|
|
1563
1560
|
const NoHydration = registerImportMethod(
|
|
1564
|
-
|
|
1565
|
-
|
|
1566
|
-
|
|
1567
|
-
|
|
1568
|
-
results.exprs.push(
|
|
1569
|
-
|
|
1570
|
-
|
|
1571
|
-
|
|
1572
|
-
|
|
1561
|
+
path,
|
|
1562
|
+
"NoHydration",
|
|
1563
|
+
getRendererConfig(path, "dom").moduleName);
|
|
1564
|
+
|
|
1565
|
+
results.exprs.push(
|
|
1566
|
+
t__namespace.expressionStatement(
|
|
1567
|
+
t__namespace.callExpression(createComponent, [NoHydration, t__namespace.objectExpression([])])));
|
|
1568
|
+
|
|
1569
|
+
|
|
1573
1570
|
}
|
|
1574
1571
|
return;
|
|
1575
1572
|
}
|
|
@@ -1577,23 +1574,23 @@ function transformChildren$2(path, results, config) {
|
|
|
1577
1574
|
let getNextMatch;
|
|
1578
1575
|
if (config.hydratable && tagName === "html") {
|
|
1579
1576
|
getNextMatch = registerImportMethod(
|
|
1580
|
-
|
|
1581
|
-
|
|
1582
|
-
|
|
1583
|
-
|
|
1577
|
+
path,
|
|
1578
|
+
"getNextMatch",
|
|
1579
|
+
getRendererConfig(path, "dom").moduleName);
|
|
1580
|
+
|
|
1584
1581
|
}
|
|
1585
1582
|
const walk = t__namespace.memberExpression(
|
|
1586
|
-
|
|
1587
|
-
|
|
1588
|
-
|
|
1583
|
+
t__namespace.identifier(tempPath),
|
|
1584
|
+
t__namespace.identifier(i === 0 ? "firstChild" : "nextSibling"));
|
|
1585
|
+
|
|
1589
1586
|
results.declarations.push(
|
|
1590
|
-
|
|
1591
|
-
|
|
1592
|
-
|
|
1593
|
-
|
|
1594
|
-
|
|
1595
|
-
|
|
1596
|
-
|
|
1587
|
+
t__namespace.variableDeclarator(
|
|
1588
|
+
child.id,
|
|
1589
|
+
config.hydratable && tagName === "html" ?
|
|
1590
|
+
t__namespace.callExpression(getNextMatch, [walk, t__namespace.stringLiteral(child.tagName)]) :
|
|
1591
|
+
walk));
|
|
1592
|
+
|
|
1593
|
+
|
|
1597
1594
|
results.declarations.push(...child.declarations);
|
|
1598
1595
|
results.exprs.push(...child.exprs);
|
|
1599
1596
|
results.dynamics.push(...child.dynamics);
|
|
@@ -1618,30 +1615,30 @@ function transformChildren$2(path, results, config) {
|
|
|
1618
1615
|
}
|
|
1619
1616
|
if (!markers) nextPlaceholder = exprId;
|
|
1620
1617
|
results.exprs.push(
|
|
1621
|
-
|
|
1622
|
-
|
|
1623
|
-
|
|
1624
|
-
|
|
1625
|
-
|
|
1626
|
-
|
|
1627
|
-
|
|
1628
|
-
|
|
1629
|
-
|
|
1618
|
+
t__namespace.expressionStatement(
|
|
1619
|
+
t__namespace.callExpression(
|
|
1620
|
+
insert,
|
|
1621
|
+
contentId ?
|
|
1622
|
+
[results.id, child.exprs[0], exprId, contentId] :
|
|
1623
|
+
[results.id, child.exprs[0], exprId])));
|
|
1624
|
+
|
|
1625
|
+
|
|
1626
|
+
|
|
1630
1627
|
tempPath = exprId.name;
|
|
1631
1628
|
} else if (multi) {
|
|
1632
1629
|
results.exprs.push(
|
|
1633
|
-
|
|
1634
|
-
|
|
1635
|
-
|
|
1636
|
-
|
|
1637
|
-
|
|
1638
|
-
|
|
1639
|
-
|
|
1640
|
-
|
|
1630
|
+
t__namespace.expressionStatement(
|
|
1631
|
+
t__namespace.callExpression(insert, [
|
|
1632
|
+
results.id,
|
|
1633
|
+
child.exprs[0],
|
|
1634
|
+
nextChild$1(childNodes, index) || t__namespace.nullLiteral()])));
|
|
1635
|
+
|
|
1636
|
+
|
|
1637
|
+
|
|
1641
1638
|
} else {
|
|
1642
1639
|
results.exprs.push(
|
|
1643
|
-
|
|
1644
|
-
|
|
1640
|
+
t__namespace.expressionStatement(t__namespace.callExpression(insert, [results.id, child.exprs[0]])));
|
|
1641
|
+
|
|
1645
1642
|
}
|
|
1646
1643
|
} else nextPlaceholder = null;
|
|
1647
1644
|
});
|
|
@@ -1656,24 +1653,24 @@ function createPlaceholder(path, results, tempPath, i, char) {
|
|
|
1656
1653
|
if (config.hydratable && char === "/") {
|
|
1657
1654
|
contentId = path.scope.generateUidIdentifier("co$");
|
|
1658
1655
|
results.declarations.push(
|
|
1659
|
-
|
|
1660
|
-
|
|
1661
|
-
|
|
1662
|
-
|
|
1663
|
-
|
|
1664
|
-
|
|
1665
|
-
|
|
1666
|
-
|
|
1656
|
+
t__namespace.variableDeclarator(
|
|
1657
|
+
t__namespace.arrayPattern([exprId, contentId]),
|
|
1658
|
+
t__namespace.callExpression(
|
|
1659
|
+
registerImportMethod(path, "getNextMarker", getRendererConfig(path, "dom").moduleName),
|
|
1660
|
+
[t__namespace.memberExpression(t__namespace.identifier(tempPath), t__namespace.identifier("nextSibling"))])));
|
|
1661
|
+
|
|
1662
|
+
|
|
1663
|
+
|
|
1667
1664
|
} else
|
|
1668
|
-
|
|
1669
|
-
|
|
1670
|
-
|
|
1671
|
-
|
|
1672
|
-
|
|
1673
|
-
|
|
1674
|
-
|
|
1675
|
-
|
|
1676
|
-
|
|
1665
|
+
results.declarations.push(
|
|
1666
|
+
t__namespace.variableDeclarator(
|
|
1667
|
+
exprId,
|
|
1668
|
+
t__namespace.memberExpression(
|
|
1669
|
+
t__namespace.identifier(tempPath),
|
|
1670
|
+
t__namespace.identifier(i === 0 ? "firstChild" : "nextSibling"))));
|
|
1671
|
+
|
|
1672
|
+
|
|
1673
|
+
|
|
1677
1674
|
return [exprId, contentId];
|
|
1678
1675
|
}
|
|
1679
1676
|
|
|
@@ -1686,11 +1683,11 @@ function detectExpressions(children, index, config) {
|
|
|
1686
1683
|
if (children[index - 1]) {
|
|
1687
1684
|
const node = children[index - 1].node;
|
|
1688
1685
|
if (
|
|
1689
|
-
|
|
1690
|
-
|
|
1691
|
-
|
|
1692
|
-
|
|
1693
|
-
|
|
1686
|
+
t__namespace.isJSXExpressionContainer(node) &&
|
|
1687
|
+
!t__namespace.isJSXEmptyExpression(node.expression) &&
|
|
1688
|
+
getStaticExpression(children[index - 1]) === false)
|
|
1689
|
+
|
|
1690
|
+
return true;
|
|
1694
1691
|
let tagName;
|
|
1695
1692
|
if (t__namespace.isJSXElement(node) && (tagName = getTagName(node)) && isComponent(tagName)) return true;
|
|
1696
1693
|
}
|
|
@@ -1698,26 +1695,26 @@ function detectExpressions(children, index, config) {
|
|
|
1698
1695
|
const child = children[i].node;
|
|
1699
1696
|
if (t__namespace.isJSXExpressionContainer(child)) {
|
|
1700
1697
|
if (!t__namespace.isJSXEmptyExpression(child.expression) && getStaticExpression(children[i]) === false)
|
|
1701
|
-
|
|
1698
|
+
return true;
|
|
1702
1699
|
} else if (t__namespace.isJSXElement(child)) {
|
|
1703
1700
|
const tagName = getTagName(child);
|
|
1704
1701
|
if (isComponent(tagName)) return true;
|
|
1705
1702
|
if (config.contextToCustomElements && (tagName === "slot" || tagName.indexOf("-") > -1))
|
|
1706
|
-
|
|
1703
|
+
return true;
|
|
1707
1704
|
if (
|
|
1708
|
-
|
|
1709
|
-
|
|
1710
|
-
|
|
1711
|
-
|
|
1712
|
-
|
|
1713
|
-
|
|
1714
|
-
|
|
1715
|
-
|
|
1716
|
-
|
|
1717
|
-
|
|
1718
|
-
|
|
1719
|
-
|
|
1720
|
-
|
|
1705
|
+
child.openingElement.attributes.some(
|
|
1706
|
+
(attr) =>
|
|
1707
|
+
t__namespace.isJSXSpreadAttribute(attr) ||
|
|
1708
|
+
["textContent", "innerHTML", "innerText"].includes(attr.name.name) ||
|
|
1709
|
+
attr.name.namespace && attr.name.namespace.name === "use" ||
|
|
1710
|
+
t__namespace.isJSXExpressionContainer(attr.value) &&
|
|
1711
|
+
!(
|
|
1712
|
+
t__namespace.isStringLiteral(attr.value.expression) ||
|
|
1713
|
+
t__namespace.isNumericLiteral(attr.value.expression))))
|
|
1714
|
+
|
|
1715
|
+
|
|
1716
|
+
|
|
1717
|
+
return true;
|
|
1721
1718
|
const nextChildren = filterChildren(children[i].get("children"));
|
|
1722
1719
|
if (nextChildren.length) if (detectExpressions(nextChildren, 0, config)) return true;
|
|
1723
1720
|
}
|
|
@@ -1726,17 +1723,17 @@ function detectExpressions(children, index, config) {
|
|
|
1726
1723
|
|
|
1727
1724
|
function contextToCustomElement(path, results) {
|
|
1728
1725
|
results.exprs.push(
|
|
1729
|
-
|
|
1730
|
-
|
|
1731
|
-
|
|
1732
|
-
|
|
1733
|
-
|
|
1734
|
-
|
|
1735
|
-
|
|
1736
|
-
|
|
1737
|
-
|
|
1738
|
-
|
|
1739
|
-
|
|
1726
|
+
t__namespace.expressionStatement(
|
|
1727
|
+
t__namespace.assignmentExpression(
|
|
1728
|
+
"=",
|
|
1729
|
+
t__namespace.memberExpression(results.id, t__namespace.identifier("_$owner")),
|
|
1730
|
+
t__namespace.callExpression(
|
|
1731
|
+
registerImportMethod(path, "getOwner", getRendererConfig(path, "dom").moduleName),
|
|
1732
|
+
[]))));
|
|
1733
|
+
|
|
1734
|
+
|
|
1735
|
+
|
|
1736
|
+
|
|
1740
1737
|
}
|
|
1741
1738
|
|
|
1742
1739
|
function processSpreads$1(path, attributes, { elem, isSVG, hasChildren, wrapConditionals }) {
|
|
@@ -1746,13 +1743,13 @@ function processSpreads$1(path, attributes, { elem, isSVG, hasChildren, wrapCond
|
|
|
1746
1743
|
let runningObject = [];
|
|
1747
1744
|
let dynamicSpread = false;
|
|
1748
1745
|
let firstSpread = false;
|
|
1749
|
-
attributes.forEach(attribute => {
|
|
1746
|
+
attributes.forEach((attribute) => {
|
|
1750
1747
|
const node = attribute.node;
|
|
1751
1748
|
const key =
|
|
1752
|
-
|
|
1753
|
-
|
|
1754
|
-
|
|
1755
|
-
|
|
1749
|
+
!t__namespace.isJSXSpreadAttribute(node) && (
|
|
1750
|
+
t__namespace.isJSXNamespacedName(node.name) ?
|
|
1751
|
+
`${node.name.namespace.name}:${node.name.name.name}` :
|
|
1752
|
+
node.name.name);
|
|
1756
1753
|
if (t__namespace.isJSXSpreadAttribute(node)) {
|
|
1757
1754
|
firstSpread = true;
|
|
1758
1755
|
if (runningObject.length) {
|
|
@@ -1760,52 +1757,52 @@ function processSpreads$1(path, attributes, { elem, isSVG, hasChildren, wrapCond
|
|
|
1760
1757
|
runningObject = [];
|
|
1761
1758
|
}
|
|
1762
1759
|
spreadArgs.push(
|
|
1763
|
-
|
|
1764
|
-
|
|
1765
|
-
|
|
1766
|
-
|
|
1767
|
-
|
|
1768
|
-
|
|
1769
|
-
|
|
1770
|
-
|
|
1771
|
-
|
|
1772
|
-
|
|
1773
|
-
|
|
1760
|
+
isDynamic(attribute.get("argument"), {
|
|
1761
|
+
checkMember: true
|
|
1762
|
+
}) && (dynamicSpread = true) ?
|
|
1763
|
+
t__namespace.isCallExpression(node.argument) &&
|
|
1764
|
+
!node.argument.arguments.length &&
|
|
1765
|
+
!t__namespace.isCallExpression(node.argument.callee) &&
|
|
1766
|
+
!t__namespace.isMemberExpression(node.argument.callee) ?
|
|
1767
|
+
node.argument.callee :
|
|
1768
|
+
t__namespace.arrowFunctionExpression([], node.argument) :
|
|
1769
|
+
node.argument);
|
|
1770
|
+
|
|
1774
1771
|
} else if (
|
|
1775
|
-
|
|
1776
|
-
|
|
1777
|
-
|
|
1778
|
-
|
|
1779
|
-
|
|
1772
|
+
(firstSpread ||
|
|
1773
|
+
t__namespace.isJSXExpressionContainer(node.value) &&
|
|
1774
|
+
isDynamic(attribute.get("value").get("expression"), { checkMember: true })) &&
|
|
1775
|
+
canNativeSpread(key, { checkNameSpaces: true }))
|
|
1776
|
+
{
|
|
1780
1777
|
const isContainer = t__namespace.isJSXExpressionContainer(node.value);
|
|
1781
1778
|
const dynamic =
|
|
1782
|
-
|
|
1779
|
+
isContainer && isDynamic(attribute.get("value").get("expression"), { checkMember: true });
|
|
1783
1780
|
if (dynamic) {
|
|
1784
1781
|
const id = convertJSXIdentifier(node.name);
|
|
1785
1782
|
let expr =
|
|
1786
|
-
|
|
1787
|
-
|
|
1788
|
-
|
|
1789
|
-
|
|
1790
|
-
|
|
1783
|
+
wrapConditionals && (
|
|
1784
|
+
t__namespace.isLogicalExpression(node.value.expression) ||
|
|
1785
|
+
t__namespace.isConditionalExpression(node.value.expression)) ?
|
|
1786
|
+
transformCondition(attribute.get("value").get("expression"), true) :
|
|
1787
|
+
t__namespace.arrowFunctionExpression([], node.value.expression);
|
|
1791
1788
|
runningObject.push(
|
|
1792
|
-
|
|
1793
|
-
|
|
1794
|
-
|
|
1795
|
-
|
|
1796
|
-
|
|
1797
|
-
|
|
1798
|
-
|
|
1799
|
-
|
|
1789
|
+
t__namespace.objectMethod(
|
|
1790
|
+
"get",
|
|
1791
|
+
id,
|
|
1792
|
+
[],
|
|
1793
|
+
t__namespace.blockStatement([t__namespace.returnStatement(expr.body)]),
|
|
1794
|
+
!t__namespace.isValidIdentifier(key)));
|
|
1795
|
+
|
|
1796
|
+
|
|
1800
1797
|
} else {
|
|
1801
1798
|
runningObject.push(
|
|
1802
|
-
|
|
1803
|
-
|
|
1804
|
-
|
|
1805
|
-
|
|
1806
|
-
|
|
1807
|
-
|
|
1808
|
-
|
|
1799
|
+
t__namespace.objectProperty(
|
|
1800
|
+
t__namespace.stringLiteral(key),
|
|
1801
|
+
isContainer ?
|
|
1802
|
+
node.value.expression :
|
|
1803
|
+
node.value || (Properties.has(key) ? t__namespace.booleanLiteral(true) : t__namespace.stringLiteral(""))));
|
|
1804
|
+
|
|
1805
|
+
|
|
1809
1806
|
}
|
|
1810
1807
|
} else filteredAttributes.push(attribute);
|
|
1811
1808
|
});
|
|
@@ -1815,19 +1812,19 @@ function processSpreads$1(path, attributes, { elem, isSVG, hasChildren, wrapCond
|
|
|
1815
1812
|
}
|
|
1816
1813
|
|
|
1817
1814
|
const props =
|
|
1818
|
-
|
|
1819
|
-
|
|
1820
|
-
|
|
1815
|
+
spreadArgs.length === 1 && !dynamicSpread ?
|
|
1816
|
+
spreadArgs[0] :
|
|
1817
|
+
t__namespace.callExpression(registerImportMethod(path, "mergeProps"), spreadArgs);
|
|
1821
1818
|
|
|
1822
1819
|
return [
|
|
1823
|
-
|
|
1824
|
-
|
|
1825
|
-
|
|
1826
|
-
|
|
1827
|
-
|
|
1828
|
-
|
|
1829
|
-
|
|
1830
|
-
|
|
1820
|
+
filteredAttributes,
|
|
1821
|
+
t__namespace.expressionStatement(
|
|
1822
|
+
t__namespace.callExpression(
|
|
1823
|
+
registerImportMethod(path, "spread", getRendererConfig(path, "dom").moduleName),
|
|
1824
|
+
[elem, props, t__namespace.booleanLiteral(isSVG), t__namespace.booleanLiteral(hasChildren)]))];
|
|
1825
|
+
|
|
1826
|
+
|
|
1827
|
+
|
|
1831
1828
|
}
|
|
1832
1829
|
|
|
1833
1830
|
function createTemplate$2(path, result, wrap) {
|
|
@@ -1835,25 +1832,25 @@ function createTemplate$2(path, result, wrap) {
|
|
|
1835
1832
|
if (result.id) {
|
|
1836
1833
|
registerTemplate(path, result);
|
|
1837
1834
|
if (
|
|
1838
|
-
|
|
1839
|
-
|
|
1840
|
-
|
|
1835
|
+
!(result.exprs.length || result.dynamics.length || result.postExprs.length) &&
|
|
1836
|
+
result.decl.declarations.length === 1)
|
|
1837
|
+
{
|
|
1841
1838
|
return result.decl.declarations[0].init;
|
|
1842
1839
|
} else {
|
|
1843
1840
|
return t__namespace.callExpression(
|
|
1844
|
-
|
|
1845
|
-
|
|
1846
|
-
|
|
1847
|
-
|
|
1848
|
-
|
|
1849
|
-
|
|
1850
|
-
|
|
1851
|
-
|
|
1852
|
-
|
|
1853
|
-
|
|
1854
|
-
|
|
1855
|
-
|
|
1856
|
-
|
|
1841
|
+
t__namespace.arrowFunctionExpression(
|
|
1842
|
+
[],
|
|
1843
|
+
t__namespace.blockStatement([
|
|
1844
|
+
result.decl,
|
|
1845
|
+
...result.exprs.concat(
|
|
1846
|
+
wrapDynamics$1(path, result.dynamics) || [],
|
|
1847
|
+
result.postExprs || []),
|
|
1848
|
+
|
|
1849
|
+
t__namespace.returnStatement(result.id)])),
|
|
1850
|
+
|
|
1851
|
+
|
|
1852
|
+
[]);
|
|
1853
|
+
|
|
1857
1854
|
}
|
|
1858
1855
|
}
|
|
1859
1856
|
if (wrap && result.dynamic && config.memoWrapper) {
|
|
@@ -1863,26 +1860,26 @@ function createTemplate$2(path, result, wrap) {
|
|
|
1863
1860
|
}
|
|
1864
1861
|
|
|
1865
1862
|
function appendTemplates$1(path, templates) {
|
|
1866
|
-
const declarators = templates.map(template => {
|
|
1863
|
+
const declarators = templates.map((template) => {
|
|
1867
1864
|
const tmpl = {
|
|
1868
1865
|
cooked: template.template,
|
|
1869
1866
|
raw: escapeStringForTemplate(template.template)
|
|
1870
1867
|
};
|
|
1871
1868
|
return t__namespace.variableDeclarator(
|
|
1872
|
-
|
|
1873
|
-
|
|
1874
|
-
|
|
1875
|
-
|
|
1876
|
-
|
|
1877
|
-
|
|
1878
|
-
|
|
1879
|
-
|
|
1880
|
-
|
|
1881
|
-
|
|
1882
|
-
|
|
1883
|
-
|
|
1884
|
-
|
|
1885
|
-
|
|
1869
|
+
template.id,
|
|
1870
|
+
t__namespace.addComment(
|
|
1871
|
+
t__namespace.callExpression(
|
|
1872
|
+
registerImportMethod(path, "template", getRendererConfig(path, "dom").moduleName),
|
|
1873
|
+
[t__namespace.templateLiteral([t__namespace.templateElement(tmpl, true)], [])].concat(
|
|
1874
|
+
template.isSVG || template.isCE ?
|
|
1875
|
+
[t__namespace.booleanLiteral(template.isCE), t__namespace.booleanLiteral(template.isSVG)] :
|
|
1876
|
+
[])),
|
|
1877
|
+
|
|
1878
|
+
|
|
1879
|
+
"leading",
|
|
1880
|
+
"#__PURE__"));
|
|
1881
|
+
|
|
1882
|
+
|
|
1886
1883
|
});
|
|
1887
1884
|
path.node.body.unshift(t__namespace.variableDeclaration("var", declarators));
|
|
1888
1885
|
}
|
|
@@ -1894,9 +1891,9 @@ function registerTemplate(path, results) {
|
|
|
1894
1891
|
let templateDef, templateId;
|
|
1895
1892
|
if (!results.skipTemplate) {
|
|
1896
1893
|
const templates =
|
|
1897
|
-
|
|
1898
|
-
|
|
1899
|
-
if (
|
|
1894
|
+
path.scope.getProgramParent().data.templates || (
|
|
1895
|
+
path.scope.getProgramParent().data.templates = []);
|
|
1896
|
+
if (templateDef = templates.find((t) => t.template === results.template)) {
|
|
1900
1897
|
templateId = templateDef.id;
|
|
1901
1898
|
} else {
|
|
1902
1899
|
templateId = path.scope.generateUidIdentifier("tmpl$");
|
|
@@ -1910,14 +1907,14 @@ function registerTemplate(path, results) {
|
|
|
1910
1907
|
}
|
|
1911
1908
|
}
|
|
1912
1909
|
decl = t__namespace.variableDeclarator(
|
|
1913
|
-
|
|
1914
|
-
|
|
1915
|
-
|
|
1916
|
-
|
|
1917
|
-
|
|
1918
|
-
|
|
1919
|
-
|
|
1920
|
-
|
|
1910
|
+
results.id,
|
|
1911
|
+
hydratable ?
|
|
1912
|
+
t__namespace.callExpression(
|
|
1913
|
+
registerImportMethod(path, "getNextElement", getRendererConfig(path, "dom").moduleName),
|
|
1914
|
+
templateId ? [templateId] : []) :
|
|
1915
|
+
|
|
1916
|
+
t__namespace.callExpression(templateId, []));
|
|
1917
|
+
|
|
1921
1918
|
}
|
|
1922
1919
|
results.declarations.unshift(decl);
|
|
1923
1920
|
results.decl = t__namespace.variableDeclaration("var", results.declarations);
|
|
@@ -1932,35 +1929,35 @@ function wrapDynamics$1(path, dynamics) {
|
|
|
1932
1929
|
if (dynamics.length === 1) {
|
|
1933
1930
|
let dynamicStyle;
|
|
1934
1931
|
const prevValue =
|
|
1935
|
-
|
|
1936
|
-
|
|
1937
|
-
|
|
1938
|
-
|
|
1939
|
-
|
|
1932
|
+
dynamics[0].key === "classList" ||
|
|
1933
|
+
dynamics[0].key === "style" || (
|
|
1934
|
+
dynamicStyle = dynamics[0].key.startsWith("style:")) ?
|
|
1935
|
+
t__namespace.identifier("_$p") :
|
|
1936
|
+
undefined;
|
|
1940
1937
|
if (dynamicStyle) {
|
|
1941
1938
|
dynamics[0].value = t__namespace.assignmentExpression("=", prevValue, dynamics[0].value);
|
|
1942
1939
|
} else if (
|
|
1943
|
-
|
|
1944
|
-
|
|
1945
|
-
|
|
1946
|
-
|
|
1940
|
+
dynamics[0].key.startsWith("class:") &&
|
|
1941
|
+
!t__namespace.isBooleanLiteral(dynamics[0].value) &&
|
|
1942
|
+
!t__namespace.isUnaryExpression(dynamics[0].value))
|
|
1943
|
+
{
|
|
1947
1944
|
dynamics[0].value = t__namespace.unaryExpression("!", t__namespace.unaryExpression("!", dynamics[0].value));
|
|
1948
1945
|
}
|
|
1949
1946
|
|
|
1950
1947
|
return t__namespace.expressionStatement(
|
|
1951
|
-
|
|
1952
|
-
|
|
1953
|
-
|
|
1954
|
-
|
|
1955
|
-
|
|
1956
|
-
|
|
1957
|
-
|
|
1958
|
-
|
|
1959
|
-
|
|
1960
|
-
|
|
1961
|
-
|
|
1962
|
-
|
|
1963
|
-
|
|
1948
|
+
t__namespace.callExpression(effectWrapperId, [
|
|
1949
|
+
t__namespace.arrowFunctionExpression(
|
|
1950
|
+
prevValue ? [prevValue] : [],
|
|
1951
|
+
setAttr$2(path, dynamics[0].elem, dynamics[0].key, dynamics[0].value, {
|
|
1952
|
+
isSVG: dynamics[0].isSVG,
|
|
1953
|
+
isCE: dynamics[0].isCE,
|
|
1954
|
+
tagName: dynamics[0].tagName,
|
|
1955
|
+
dynamic: true,
|
|
1956
|
+
prevId: prevValue
|
|
1957
|
+
}))]));
|
|
1958
|
+
|
|
1959
|
+
|
|
1960
|
+
|
|
1964
1961
|
}
|
|
1965
1962
|
|
|
1966
1963
|
const prevId = t__namespace.identifier("_p$");
|
|
@@ -1979,10 +1976,10 @@ function wrapDynamics$1(path, dynamics) {
|
|
|
1979
1976
|
const propMember = t__namespace.memberExpression(prevId, propIdent);
|
|
1980
1977
|
|
|
1981
1978
|
if (
|
|
1982
|
-
|
|
1983
|
-
|
|
1984
|
-
|
|
1985
|
-
|
|
1979
|
+
key.startsWith("class:") &&
|
|
1980
|
+
!t__namespace.isBooleanLiteral(value) &&
|
|
1981
|
+
!t__namespace.isUnaryExpression(value))
|
|
1982
|
+
{
|
|
1986
1983
|
value = t__namespace.unaryExpression("!", t__namespace.unaryExpression("!", value));
|
|
1987
1984
|
}
|
|
1988
1985
|
|
|
@@ -1991,55 +1988,55 @@ function wrapDynamics$1(path, dynamics) {
|
|
|
1991
1988
|
|
|
1992
1989
|
if (key === "classList" || key === "style") {
|
|
1993
1990
|
statements.push(
|
|
1994
|
-
|
|
1995
|
-
|
|
1996
|
-
|
|
1997
|
-
|
|
1998
|
-
|
|
1999
|
-
|
|
2000
|
-
|
|
2001
|
-
|
|
2002
|
-
|
|
2003
|
-
|
|
2004
|
-
|
|
2005
|
-
|
|
2006
|
-
|
|
2007
|
-
|
|
1991
|
+
t__namespace.expressionStatement(
|
|
1992
|
+
t__namespace.assignmentExpression(
|
|
1993
|
+
"=",
|
|
1994
|
+
propMember,
|
|
1995
|
+
setAttr$2(path, elem, key, varIdent, {
|
|
1996
|
+
isSVG,
|
|
1997
|
+
isCE,
|
|
1998
|
+
tagName,
|
|
1999
|
+
dynamic: true,
|
|
2000
|
+
prevId: propMember
|
|
2001
|
+
}))));
|
|
2002
|
+
|
|
2003
|
+
|
|
2004
|
+
|
|
2008
2005
|
} else {
|
|
2009
2006
|
const prev = key.startsWith("style:") ? varIdent : undefined;
|
|
2010
2007
|
statements.push(
|
|
2011
|
-
|
|
2012
|
-
|
|
2013
|
-
|
|
2014
|
-
|
|
2015
|
-
|
|
2016
|
-
|
|
2017
|
-
|
|
2018
|
-
|
|
2019
|
-
|
|
2020
|
-
|
|
2021
|
-
|
|
2022
|
-
|
|
2023
|
-
|
|
2024
|
-
|
|
2008
|
+
t__namespace.expressionStatement(
|
|
2009
|
+
t__namespace.logicalExpression(
|
|
2010
|
+
"&&",
|
|
2011
|
+
t__namespace.binaryExpression("!==", varIdent, propMember),
|
|
2012
|
+
setAttr$2(
|
|
2013
|
+
path,
|
|
2014
|
+
elem,
|
|
2015
|
+
key,
|
|
2016
|
+
t__namespace.assignmentExpression("=", propMember, varIdent),
|
|
2017
|
+
{ isSVG, isCE, tagName, dynamic: true, prevId: prev }))));
|
|
2018
|
+
|
|
2019
|
+
|
|
2020
|
+
|
|
2021
|
+
|
|
2025
2022
|
}
|
|
2026
2023
|
});
|
|
2027
2024
|
|
|
2028
2025
|
return t__namespace.expressionStatement(
|
|
2029
|
-
|
|
2030
|
-
|
|
2031
|
-
|
|
2032
|
-
|
|
2033
|
-
|
|
2034
|
-
|
|
2035
|
-
|
|
2036
|
-
|
|
2037
|
-
|
|
2038
|
-
|
|
2039
|
-
|
|
2040
|
-
|
|
2041
|
-
|
|
2042
|
-
|
|
2026
|
+
t__namespace.callExpression(effectWrapperId, [
|
|
2027
|
+
t__namespace.arrowFunctionExpression(
|
|
2028
|
+
[prevId],
|
|
2029
|
+
t__namespace.blockStatement([
|
|
2030
|
+
t__namespace.variableDeclaration("var", declarations),
|
|
2031
|
+
...statements,
|
|
2032
|
+
t__namespace.returnStatement(prevId)])),
|
|
2033
|
+
|
|
2034
|
+
|
|
2035
|
+
t__namespace.objectExpression(
|
|
2036
|
+
properties.map((id) => t__namespace.objectProperty(id, t__namespace.identifier("undefined"))))]));
|
|
2037
|
+
|
|
2038
|
+
|
|
2039
|
+
|
|
2043
2040
|
}
|
|
2044
2041
|
|
|
2045
2042
|
function createTemplate$1(path, result) {
|
|
@@ -2054,18 +2051,18 @@ function createTemplate$1(path, result) {
|
|
|
2054
2051
|
} else if (result.template.length === 1) {
|
|
2055
2052
|
template = t__namespace.stringLiteral(result.template[0]);
|
|
2056
2053
|
} else {
|
|
2057
|
-
const strings = result.template.map(tmpl => t__namespace.stringLiteral(tmpl));
|
|
2054
|
+
const strings = result.template.map((tmpl) => t__namespace.stringLiteral(tmpl));
|
|
2058
2055
|
template = t__namespace.arrayExpression(strings);
|
|
2059
2056
|
}
|
|
2060
2057
|
|
|
2061
2058
|
const templates =
|
|
2062
|
-
|
|
2063
|
-
|
|
2064
|
-
const found = templates.find(tmp => {
|
|
2059
|
+
path.scope.getProgramParent().data.templates || (
|
|
2060
|
+
path.scope.getProgramParent().data.templates = []);
|
|
2061
|
+
const found = templates.find((tmp) => {
|
|
2065
2062
|
if (t__namespace.isArrayExpression(tmp.template) && t__namespace.isArrayExpression(template)) {
|
|
2066
2063
|
return tmp.template.elements.every(
|
|
2067
|
-
|
|
2068
|
-
|
|
2064
|
+
(el, i) => template.elements[i] && el.value === template.elements[i].value);
|
|
2065
|
+
|
|
2069
2066
|
}
|
|
2070
2067
|
return tmp.template.value === template.value;
|
|
2071
2068
|
});
|
|
@@ -2079,35 +2076,35 @@ function createTemplate$1(path, result) {
|
|
|
2079
2076
|
} else id = found.id;
|
|
2080
2077
|
|
|
2081
2078
|
if (result.wontEscape) {
|
|
2082
|
-
if (!Array.isArray(result.template) || result.template.length === 1) return id;
|
|
2083
|
-
|
|
2084
|
-
|
|
2085
|
-
|
|
2086
|
-
|
|
2087
|
-
|
|
2088
|
-
|
|
2079
|
+
if (!Array.isArray(result.template) || result.template.length === 1) return id;else
|
|
2080
|
+
if (
|
|
2081
|
+
Array.isArray(result.template) &&
|
|
2082
|
+
result.template.length === 2 &&
|
|
2083
|
+
result.templateValues[0].type === "CallExpression" &&
|
|
2084
|
+
result.templateValues[0].callee.name === "_$ssrHydrationKey")
|
|
2085
|
+
{
|
|
2089
2086
|
// remove unnecessary ssr call when only hydration key is used
|
|
2090
2087
|
return t__namespace.binaryExpression(
|
|
2091
|
-
|
|
2092
|
-
|
|
2093
|
-
|
|
2094
|
-
|
|
2095
|
-
|
|
2096
|
-
|
|
2097
|
-
|
|
2098
|
-
|
|
2088
|
+
"+",
|
|
2089
|
+
t__namespace.binaryExpression(
|
|
2090
|
+
"+",
|
|
2091
|
+
t__namespace.memberExpression(id, t__namespace.numericLiteral(0), true),
|
|
2092
|
+
result.templateValues[0]),
|
|
2093
|
+
|
|
2094
|
+
t__namespace.memberExpression(id, t__namespace.numericLiteral(1), true));
|
|
2095
|
+
|
|
2099
2096
|
}
|
|
2100
2097
|
}
|
|
2101
2098
|
return t__namespace.callExpression(
|
|
2102
|
-
|
|
2103
|
-
|
|
2104
|
-
|
|
2105
|
-
|
|
2106
|
-
|
|
2099
|
+
registerImportMethod(path, "ssr"),
|
|
2100
|
+
Array.isArray(result.template) && result.template.length > 1 ?
|
|
2101
|
+
[id, ...result.templateValues] :
|
|
2102
|
+
[id]);
|
|
2103
|
+
|
|
2107
2104
|
}
|
|
2108
2105
|
|
|
2109
2106
|
function appendTemplates(path, templates) {
|
|
2110
|
-
const declarators = templates.map(template => {
|
|
2107
|
+
const declarators = templates.map((template) => {
|
|
2111
2108
|
return t__namespace.variableDeclarator(template.id, template.template);
|
|
2112
2109
|
});
|
|
2113
2110
|
path.node.body.unshift(t__namespace.variableDeclaration("var", declarators));
|
|
@@ -2125,8 +2122,8 @@ function appendToTemplate(template, value) {
|
|
|
2125
2122
|
function transformElement$2(path, info) {
|
|
2126
2123
|
const config = getConfig(path);
|
|
2127
2124
|
// contains spread attributes
|
|
2128
|
-
if (path.node.openingElement.attributes.some(a => t__namespace.isJSXSpreadAttribute(a)))
|
|
2129
|
-
|
|
2125
|
+
if (path.node.openingElement.attributes.some((a) => t__namespace.isJSXSpreadAttribute(a)))
|
|
2126
|
+
return createElement(path, { ...info, ...config });
|
|
2130
2127
|
|
|
2131
2128
|
const tagName = getTagName(path.node),
|
|
2132
2129
|
voidTag = VoidElements.indexOf(tagName) > -1,
|
|
@@ -2149,24 +2146,24 @@ function transformElement$2(path, info) {
|
|
|
2149
2146
|
const child = transformElement$2(path, { ...info, topLevel: false });
|
|
2150
2147
|
results.template = "";
|
|
2151
2148
|
results.exprs.push(
|
|
2152
|
-
|
|
2153
|
-
|
|
2154
|
-
|
|
2155
|
-
|
|
2156
|
-
|
|
2157
|
-
|
|
2158
|
-
|
|
2159
|
-
|
|
2160
|
-
|
|
2161
|
-
|
|
2162
|
-
|
|
2163
|
-
|
|
2149
|
+
t__namespace.callExpression(t__namespace.identifier("_$createComponent"), [
|
|
2150
|
+
t__namespace.identifier("_$NoHydration"),
|
|
2151
|
+
t__namespace.objectExpression([
|
|
2152
|
+
t__namespace.objectMethod(
|
|
2153
|
+
"get",
|
|
2154
|
+
t__namespace.identifier("children"),
|
|
2155
|
+
[],
|
|
2156
|
+
t__namespace.blockStatement([t__namespace.returnStatement(createTemplate$1(path, child))]))])]));
|
|
2157
|
+
|
|
2158
|
+
|
|
2159
|
+
|
|
2160
|
+
|
|
2164
2161
|
return results;
|
|
2165
2162
|
}
|
|
2166
2163
|
results.template.push("");
|
|
2167
2164
|
results.templateValues.push(
|
|
2168
|
-
|
|
2169
|
-
|
|
2165
|
+
t__namespace.callExpression(registerImportMethod(path, "ssrHydrationKey"), []));
|
|
2166
|
+
|
|
2170
2167
|
}
|
|
2171
2168
|
transformAttributes$1(path, results, { ...config, ...info });
|
|
2172
2169
|
appendToTemplate(results.template, ">");
|
|
@@ -2193,10 +2190,10 @@ function setAttr$1(attribute, results, name, value, isSVG) {
|
|
|
2193
2190
|
|
|
2194
2191
|
name = toAttribute(name, isSVG);
|
|
2195
2192
|
const attr = t__namespace.callExpression(registerImportMethod(attribute, "ssrAttribute"), [
|
|
2196
|
-
|
|
2197
|
-
|
|
2198
|
-
|
|
2199
|
-
|
|
2193
|
+
t__namespace.stringLiteral(name),
|
|
2194
|
+
value,
|
|
2195
|
+
t__namespace.booleanLiteral(false)]);
|
|
2196
|
+
|
|
2200
2197
|
if (results.template[results.template.length - 1].length) {
|
|
2201
2198
|
results.template.push("");
|
|
2202
2199
|
results.templateValues.push(attr);
|
|
@@ -2208,29 +2205,29 @@ function setAttr$1(attribute, results, name, value, isSVG) {
|
|
|
2208
2205
|
|
|
2209
2206
|
function escapeExpression(path, expression, attr, escapeLiterals) {
|
|
2210
2207
|
if (
|
|
2211
|
-
|
|
2212
|
-
|
|
2213
|
-
|
|
2214
|
-
|
|
2208
|
+
t__namespace.isStringLiteral(expression) ||
|
|
2209
|
+
t__namespace.isNumericLiteral(expression) ||
|
|
2210
|
+
t__namespace.isTemplateLiteral(expression) && expression.expressions.length === 0)
|
|
2211
|
+
{
|
|
2215
2212
|
if (escapeLiterals) {
|
|
2216
|
-
if (t__namespace.isStringLiteral(expression)) return t__namespace.stringLiteral(escapeHTML(expression.value, attr));
|
|
2217
|
-
|
|
2218
|
-
|
|
2213
|
+
if (t__namespace.isStringLiteral(expression)) return t__namespace.stringLiteral(escapeHTML(expression.value, attr));else
|
|
2214
|
+
if (t__namespace.isTemplateLiteral(expression))
|
|
2215
|
+
return t__namespace.stringLiteral(escapeHTML(expression.quasis[0].value.raw, attr));
|
|
2219
2216
|
}
|
|
2220
2217
|
return expression;
|
|
2221
2218
|
} else if (t__namespace.isFunction(expression)) {
|
|
2222
2219
|
if (t__namespace.isBlockStatement(expression.body)) {
|
|
2223
|
-
expression.body.body = expression.body.body.map(e => {
|
|
2220
|
+
expression.body.body = expression.body.body.map((e) => {
|
|
2224
2221
|
if (t__namespace.isReturnStatement(e))
|
|
2225
|
-
|
|
2222
|
+
e.argument = escapeExpression(path, e.argument, attr, escapeLiterals);
|
|
2226
2223
|
return e;
|
|
2227
2224
|
});
|
|
2228
2225
|
} else expression.body = escapeExpression(path, expression.body, attr, escapeLiterals);
|
|
2229
2226
|
return expression;
|
|
2230
2227
|
} else if (t__namespace.isTemplateLiteral(expression)) {
|
|
2231
|
-
expression.expressions = expression.expressions.map(e =>
|
|
2232
|
-
|
|
2233
|
-
|
|
2228
|
+
expression.expressions = expression.expressions.map((e) =>
|
|
2229
|
+
escapeExpression(path, e, attr, escapeLiterals));
|
|
2230
|
+
|
|
2234
2231
|
return expression;
|
|
2235
2232
|
} else if (t__namespace.isUnaryExpression(expression)) {
|
|
2236
2233
|
return expression;
|
|
@@ -2250,13 +2247,13 @@ function escapeExpression(path, expression, attr, escapeLiterals) {
|
|
|
2250
2247
|
return expression;
|
|
2251
2248
|
} else if (t__namespace.isCallExpression(expression) && t__namespace.isFunction(expression.callee)) {
|
|
2252
2249
|
if (t__namespace.isBlockStatement(expression.callee.body)) {
|
|
2253
|
-
expression.callee.body.body = expression.callee.body.body.map(e => {
|
|
2250
|
+
expression.callee.body.body = expression.callee.body.body.map((e) => {
|
|
2254
2251
|
if (t__namespace.isReturnStatement(e))
|
|
2255
|
-
|
|
2252
|
+
e.argument = escapeExpression(path, e.argument, attr, escapeLiterals);
|
|
2256
2253
|
return e;
|
|
2257
2254
|
});
|
|
2258
2255
|
} else
|
|
2259
|
-
|
|
2256
|
+
expression.callee.body = escapeExpression(path, expression.callee.body, attr, escapeLiterals);
|
|
2260
2257
|
return expression;
|
|
2261
2258
|
} else if (t__namespace.isJSXElement(expression) && !isComponent(getTagName(expression))) {
|
|
2262
2259
|
expression.wontEscape = true;
|
|
@@ -2264,14 +2261,14 @@ function escapeExpression(path, expression, attr, escapeLiterals) {
|
|
|
2264
2261
|
}
|
|
2265
2262
|
|
|
2266
2263
|
return t__namespace.callExpression(
|
|
2267
|
-
|
|
2268
|
-
|
|
2269
|
-
|
|
2264
|
+
registerImportMethod(path, "escape"),
|
|
2265
|
+
[expression].concat(attr ? [t__namespace.booleanLiteral(true)] : []));
|
|
2266
|
+
|
|
2270
2267
|
}
|
|
2271
2268
|
|
|
2272
2269
|
function transformToObject(attrName, attributes, selectedAttributes) {
|
|
2273
2270
|
const properties = [];
|
|
2274
|
-
const existingAttribute = attributes.find(a => a.node.name.name === attrName);
|
|
2271
|
+
const existingAttribute = attributes.find((a) => a.node.name.name === attrName);
|
|
2275
2272
|
for (let i = 0; i < selectedAttributes.length; i++) {
|
|
2276
2273
|
const attr = selectedAttributes[i].node;
|
|
2277
2274
|
const computed = !t__namespace.isValidIdentifier(attr.name.name.name);
|
|
@@ -2279,44 +2276,44 @@ function transformToObject(attrName, attributes, selectedAttributes) {
|
|
|
2279
2276
|
attr.name.name.type = "Identifier";
|
|
2280
2277
|
}
|
|
2281
2278
|
properties.push(
|
|
2282
|
-
|
|
2283
|
-
|
|
2284
|
-
|
|
2285
|
-
|
|
2286
|
-
|
|
2279
|
+
t__namespace.objectProperty(
|
|
2280
|
+
computed ? t__namespace.stringLiteral(attr.name.name.name) : attr.name.name,
|
|
2281
|
+
t__namespace.isJSXExpressionContainer(attr.value) ? attr.value.expression : attr.value));
|
|
2282
|
+
|
|
2283
|
+
|
|
2287
2284
|
(existingAttribute || i) && attributes.splice(selectedAttributes[i].key, 1);
|
|
2288
2285
|
}
|
|
2289
2286
|
if (
|
|
2290
|
-
|
|
2291
|
-
|
|
2292
|
-
|
|
2293
|
-
|
|
2287
|
+
existingAttribute &&
|
|
2288
|
+
t__namespace.isJSXExpressionContainer(existingAttribute.node.value) &&
|
|
2289
|
+
t__namespace.isObjectExpression(existingAttribute.node.value.expression))
|
|
2290
|
+
{
|
|
2294
2291
|
existingAttribute.node.value.expression.properties.push(...properties);
|
|
2295
2292
|
} else {
|
|
2296
2293
|
selectedAttributes[0].node = t__namespace.jsxAttribute(
|
|
2297
|
-
|
|
2298
|
-
|
|
2299
|
-
|
|
2294
|
+
t__namespace.jsxIdentifier(attrName),
|
|
2295
|
+
t__namespace.jsxExpressionContainer(t__namespace.objectExpression(properties)));
|
|
2296
|
+
|
|
2300
2297
|
}
|
|
2301
2298
|
}
|
|
2302
2299
|
|
|
2303
2300
|
function normalizeAttributes(path) {
|
|
2304
2301
|
const attributes = path.get("openingElement").get("attributes"),
|
|
2305
2302
|
styleAttributes = attributes.filter(
|
|
2306
|
-
|
|
2307
|
-
|
|
2303
|
+
(a) => t__namespace.isJSXNamespacedName(a.node.name) && a.node.name.namespace.name === "style"),
|
|
2304
|
+
|
|
2308
2305
|
classNamespaceAttributes = attributes.filter(
|
|
2309
|
-
|
|
2310
|
-
|
|
2306
|
+
(a) => t__namespace.isJSXNamespacedName(a.node.name) && a.node.name.namespace.name === "class");
|
|
2307
|
+
|
|
2311
2308
|
if (classNamespaceAttributes.length)
|
|
2312
|
-
|
|
2309
|
+
transformToObject("classList", attributes, classNamespaceAttributes);
|
|
2313
2310
|
const classAttributes = attributes.filter(
|
|
2314
|
-
|
|
2315
|
-
|
|
2316
|
-
|
|
2317
|
-
|
|
2318
|
-
|
|
2319
|
-
|
|
2311
|
+
(a) =>
|
|
2312
|
+
a.node.name && (
|
|
2313
|
+
a.node.name.name === "class" ||
|
|
2314
|
+
a.node.name.name === "className" ||
|
|
2315
|
+
a.node.name.name === "classList"));
|
|
2316
|
+
|
|
2320
2317
|
// combine class propertoes
|
|
2321
2318
|
if (classAttributes.length > 1) {
|
|
2322
2319
|
const first = classAttributes[0].node,
|
|
@@ -2328,17 +2325,17 @@ function normalizeAttributes(path) {
|
|
|
2328
2325
|
if (!t__namespace.isJSXExpressionContainer(attr.value)) {
|
|
2329
2326
|
const prev = quasis.pop();
|
|
2330
2327
|
quasis.push(
|
|
2331
|
-
|
|
2332
|
-
|
|
2333
|
-
|
|
2334
|
-
|
|
2335
|
-
|
|
2336
|
-
|
|
2337
|
-
|
|
2328
|
+
t__namespace.templateElement({
|
|
2329
|
+
raw:
|
|
2330
|
+
(prev ? prev.value.raw : "") +
|
|
2331
|
+
`${attr.value.value}` + (
|
|
2332
|
+
isLast ? "" : " ")
|
|
2333
|
+
}));
|
|
2334
|
+
|
|
2338
2335
|
} else {
|
|
2339
2336
|
let expr = attr.value.expression;
|
|
2340
2337
|
if (attr.name.name === "classList") {
|
|
2341
|
-
if (t__namespace.isObjectExpression(expr) && !expr.properties.some(p => t__namespace.isSpreadElement(p))) {
|
|
2338
|
+
if (t__namespace.isObjectExpression(expr) && !expr.properties.some((p) => t__namespace.isSpreadElement(p))) {
|
|
2342
2339
|
transformClasslistObject(path, expr, values, quasis);
|
|
2343
2340
|
if (!isLast) quasis[quasis.length - 1].value.raw += " ";
|
|
2344
2341
|
i && attributes.splice(attributes.indexOf(classAttributes[i]), 1);
|
|
@@ -2365,36 +2362,36 @@ function transformAttributes$1(path, results, info) {
|
|
|
2365
2362
|
attributes = normalizeAttributes(path);
|
|
2366
2363
|
let children;
|
|
2367
2364
|
|
|
2368
|
-
attributes.forEach(attribute => {
|
|
2365
|
+
attributes.forEach((attribute) => {
|
|
2369
2366
|
const node = attribute.node;
|
|
2370
2367
|
|
|
2371
2368
|
let value = node.value,
|
|
2372
|
-
key = t__namespace.isJSXNamespacedName(node.name)
|
|
2373
|
-
|
|
2374
|
-
|
|
2369
|
+
key = t__namespace.isJSXNamespacedName(node.name) ?
|
|
2370
|
+
`${node.name.namespace.name}:${node.name.name.name}` :
|
|
2371
|
+
node.name.name,
|
|
2375
2372
|
reservedNameSpace =
|
|
2376
|
-
|
|
2373
|
+
t__namespace.isJSXNamespacedName(node.name) && reservedNameSpaces.has(node.name.namespace.name);
|
|
2377
2374
|
if (
|
|
2378
|
-
|
|
2379
|
-
|
|
2380
|
-
|
|
2375
|
+
(t__namespace.isJSXNamespacedName(node.name) && reservedNameSpace || ChildProperties.has(key)) &&
|
|
2376
|
+
!t__namespace.isJSXExpressionContainer(value))
|
|
2377
|
+
{
|
|
2381
2378
|
node.value = value = t__namespace.jsxExpressionContainer(value || t__namespace.jsxEmptyExpression());
|
|
2382
2379
|
}
|
|
2383
2380
|
|
|
2384
2381
|
if (
|
|
2385
|
-
|
|
2386
|
-
|
|
2387
|
-
|
|
2388
|
-
|
|
2389
|
-
|
|
2382
|
+
t__namespace.isJSXExpressionContainer(value) && (
|
|
2383
|
+
reservedNameSpace ||
|
|
2384
|
+
ChildProperties.has(key) ||
|
|
2385
|
+
!(t__namespace.isStringLiteral(value.expression) || t__namespace.isNumericLiteral(value.expression) || t__namespace.isBooleanLiteral(value.expression))))
|
|
2386
|
+
{
|
|
2390
2387
|
if (
|
|
2391
|
-
|
|
2392
|
-
|
|
2393
|
-
|
|
2394
|
-
|
|
2395
|
-
|
|
2396
|
-
|
|
2397
|
-
|
|
2388
|
+
key === "ref" ||
|
|
2389
|
+
key.startsWith("use:") ||
|
|
2390
|
+
key.startsWith("prop:") ||
|
|
2391
|
+
key.startsWith("on"))
|
|
2392
|
+
|
|
2393
|
+
return;else
|
|
2394
|
+
if (ChildProperties.has(key)) {
|
|
2398
2395
|
if (info.hydratable && key === "textContent" && value && value.expression) {
|
|
2399
2396
|
value.expression = t__namespace.logicalExpression("||", value.expression, t__namespace.stringLiteral(" "));
|
|
2400
2397
|
}
|
|
@@ -2402,31 +2399,32 @@ function transformAttributes$1(path, results, info) {
|
|
|
2402
2399
|
children = value;
|
|
2403
2400
|
} else {
|
|
2404
2401
|
let doEscape = true;
|
|
2402
|
+
if (key.startsWith("attr:")) key = key.replace("attr:", "");
|
|
2405
2403
|
if (BooleanAttributes.has(key)) {
|
|
2406
2404
|
results.template.push("");
|
|
2407
2405
|
const fn = t__namespace.callExpression(registerImportMethod(attribute, "ssrAttribute"), [
|
|
2408
|
-
|
|
2409
|
-
|
|
2410
|
-
|
|
2411
|
-
|
|
2406
|
+
t__namespace.stringLiteral(key),
|
|
2407
|
+
value.expression,
|
|
2408
|
+
t__namespace.booleanLiteral(true)]);
|
|
2409
|
+
|
|
2412
2410
|
results.templateValues.push(fn);
|
|
2413
2411
|
return;
|
|
2414
2412
|
}
|
|
2415
2413
|
if (key === "style") {
|
|
2416
2414
|
if (
|
|
2417
|
-
|
|
2418
|
-
|
|
2419
|
-
|
|
2420
|
-
|
|
2415
|
+
t__namespace.isJSXExpressionContainer(value) &&
|
|
2416
|
+
t__namespace.isObjectExpression(value.expression) &&
|
|
2417
|
+
!value.expression.properties.some((p) => t__namespace.isSpreadElement(p)))
|
|
2418
|
+
{
|
|
2421
2419
|
const props = value.expression.properties.map((p, i) =>
|
|
2422
|
-
|
|
2423
|
-
|
|
2424
|
-
|
|
2425
|
-
|
|
2426
|
-
|
|
2427
|
-
|
|
2428
|
-
|
|
2429
|
-
|
|
2420
|
+
t__namespace.binaryExpression(
|
|
2421
|
+
"+",
|
|
2422
|
+
t__namespace.stringLiteral(
|
|
2423
|
+
(i ? ";" : "") + (t__namespace.isIdentifier(p.key) ? p.key.name : p.key.value) + ":"),
|
|
2424
|
+
|
|
2425
|
+
escapeExpression(path, p.value, true, true)));
|
|
2426
|
+
|
|
2427
|
+
|
|
2430
2428
|
let res = props[0];
|
|
2431
2429
|
for (let i = 1; i < props.length; i++) {
|
|
2432
2430
|
res = t__namespace.binaryExpression("+", res, props[i]);
|
|
@@ -2434,27 +2432,27 @@ function transformAttributes$1(path, results, info) {
|
|
|
2434
2432
|
value.expression = res;
|
|
2435
2433
|
} else {
|
|
2436
2434
|
value.expression = t__namespace.callExpression(registerImportMethod(path, "ssrStyle"), [
|
|
2437
|
-
|
|
2438
|
-
|
|
2435
|
+
value.expression]);
|
|
2436
|
+
|
|
2439
2437
|
}
|
|
2440
2438
|
doEscape = false;
|
|
2441
2439
|
}
|
|
2442
2440
|
if (key === "classList") {
|
|
2443
2441
|
if (
|
|
2444
|
-
|
|
2445
|
-
|
|
2446
|
-
|
|
2442
|
+
t__namespace.isObjectExpression(value.expression) &&
|
|
2443
|
+
!value.expression.properties.some((p) => t__namespace.isSpreadElement(p)))
|
|
2444
|
+
{
|
|
2447
2445
|
const values = [],
|
|
2448
2446
|
quasis = [t__namespace.templateElement({ raw: "" })];
|
|
2449
2447
|
transformClasslistObject(path, value.expression, values, quasis);
|
|
2450
|
-
if (!values.length) value.expression = t__namespace.stringLiteral(quasis[0].value.raw);
|
|
2451
|
-
|
|
2448
|
+
if (!values.length) value.expression = t__namespace.stringLiteral(quasis[0].value.raw);else
|
|
2449
|
+
if (values.length === 1 && !quasis[0].value.raw && !quasis[1].value.raw) {
|
|
2452
2450
|
value.expression = values[0];
|
|
2453
2451
|
} else value.expression = t__namespace.templateLiteral(quasis, values);
|
|
2454
2452
|
} else {
|
|
2455
2453
|
value.expression = t__namespace.callExpression(registerImportMethod(path, "ssrClassList"), [
|
|
2456
|
-
|
|
2457
|
-
|
|
2454
|
+
value.expression]);
|
|
2455
|
+
|
|
2458
2456
|
}
|
|
2459
2457
|
key = "class";
|
|
2460
2458
|
doEscape = false;
|
|
@@ -2495,23 +2493,23 @@ function transformClasslistObject(path, expr, values, quasis) {
|
|
|
2495
2493
|
expr.properties.forEach((prop, i) => {
|
|
2496
2494
|
const isLast = expr.properties.length - 1 === i;
|
|
2497
2495
|
let key = prop.key;
|
|
2498
|
-
if (t__namespace.isIdentifier(prop.key) && !prop.computed) key = t__namespace.stringLiteral(key.name);
|
|
2499
|
-
|
|
2496
|
+
if (t__namespace.isIdentifier(prop.key) && !prop.computed) key = t__namespace.stringLiteral(key.name);else
|
|
2497
|
+
if (prop.computed) {
|
|
2500
2498
|
key = t__namespace.callExpression(registerImportMethod(path, "escape"), [
|
|
2501
|
-
|
|
2502
|
-
|
|
2503
|
-
|
|
2499
|
+
prop.key,
|
|
2500
|
+
t__namespace.booleanLiteral(true)]);
|
|
2501
|
+
|
|
2504
2502
|
} else key = t__namespace.stringLiteral(escapeHTML(prop.key.value));
|
|
2505
2503
|
if (t__namespace.isBooleanLiteral(prop.value)) {
|
|
2506
2504
|
if (prop.value.value === true) {
|
|
2507
2505
|
if (!prop.computed) {
|
|
2508
2506
|
const prev = quasis.pop();
|
|
2509
2507
|
quasis.push(
|
|
2510
|
-
|
|
2511
|
-
|
|
2512
|
-
|
|
2513
|
-
|
|
2514
|
-
|
|
2508
|
+
t__namespace.templateElement({
|
|
2509
|
+
raw:
|
|
2510
|
+
(prev ? prev.value.raw : "") + (i ? " " : "") + `${key.value}` + (isLast ? "" : " ")
|
|
2511
|
+
}));
|
|
2512
|
+
|
|
2515
2513
|
} else {
|
|
2516
2514
|
values.push(key);
|
|
2517
2515
|
quasis.push(t__namespace.templateElement({ raw: isLast ? "" : " " }));
|
|
@@ -2529,25 +2527,25 @@ function transformChildren$1(path, results, { hydratable }) {
|
|
|
2529
2527
|
const filteredChildren = filterChildren(path.get("children"));
|
|
2530
2528
|
const multi = checkLength(filteredChildren),
|
|
2531
2529
|
markers = hydratable && multi;
|
|
2532
|
-
filteredChildren.forEach(node => {
|
|
2530
|
+
filteredChildren.forEach((node) => {
|
|
2533
2531
|
if (t__namespace.isJSXElement(node.node) && getTagName(node.node) === "head") {
|
|
2534
2532
|
const child = transformNode(node, { doNotEscape, hydratable: false });
|
|
2535
2533
|
registerImportMethod(path, "NoHydration");
|
|
2536
2534
|
registerImportMethod(path, "createComponent");
|
|
2537
2535
|
results.template.push("");
|
|
2538
2536
|
results.templateValues.push(
|
|
2539
|
-
|
|
2540
|
-
|
|
2541
|
-
|
|
2542
|
-
|
|
2543
|
-
|
|
2544
|
-
|
|
2545
|
-
|
|
2546
|
-
|
|
2547
|
-
|
|
2548
|
-
|
|
2549
|
-
|
|
2550
|
-
|
|
2537
|
+
t__namespace.callExpression(t__namespace.identifier("_$createComponent"), [
|
|
2538
|
+
t__namespace.identifier("_$NoHydration"),
|
|
2539
|
+
t__namespace.objectExpression([
|
|
2540
|
+
t__namespace.objectMethod(
|
|
2541
|
+
"get",
|
|
2542
|
+
t__namespace.identifier("children"),
|
|
2543
|
+
[],
|
|
2544
|
+
t__namespace.blockStatement([t__namespace.returnStatement(createTemplate$1(path, child))]))])]));
|
|
2545
|
+
|
|
2546
|
+
|
|
2547
|
+
|
|
2548
|
+
|
|
2551
2549
|
return;
|
|
2552
2550
|
}
|
|
2553
2551
|
const child = transformNode(node, { doNotEscape });
|
|
@@ -2556,7 +2554,7 @@ function transformChildren$1(path, results, { hydratable }) {
|
|
|
2556
2554
|
results.templateValues.push.apply(results.templateValues, child.templateValues || []);
|
|
2557
2555
|
if (child.exprs.length) {
|
|
2558
2556
|
if (!doNotEscape && !child.spreadElement)
|
|
2559
|
-
|
|
2557
|
+
child.exprs[0] = escapeExpression(path, child.exprs[0]);
|
|
2560
2558
|
|
|
2561
2559
|
// boxed by textNodes
|
|
2562
2560
|
if (markers && !child.spreadElement) {
|
|
@@ -2587,12 +2585,12 @@ function createElement(path, { topLevel, hydratable }) {
|
|
|
2587
2585
|
} else {
|
|
2588
2586
|
const child = transformNode(path);
|
|
2589
2587
|
if (markers && child.exprs.length && !child.spreadElement)
|
|
2590
|
-
|
|
2588
|
+
memo.push(t__namespace.stringLiteral("<!--$-->"));
|
|
2591
2589
|
if (child.exprs.length && !child.spreadElement)
|
|
2592
|
-
|
|
2590
|
+
child.exprs[0] = escapeExpression(path, child.exprs[0]);
|
|
2593
2591
|
memo.push(getCreateTemplate(config, path, child)(path, child, true));
|
|
2594
2592
|
if (markers && child.exprs.length && !child.spreadElement)
|
|
2595
|
-
|
|
2593
|
+
memo.push(t__namespace.stringLiteral("<!--/-->"));
|
|
2596
2594
|
}
|
|
2597
2595
|
return memo;
|
|
2598
2596
|
}, []);
|
|
@@ -2606,7 +2604,7 @@ function createElement(path, { topLevel, hydratable }) {
|
|
|
2606
2604
|
dynamicSpread = false,
|
|
2607
2605
|
hasChildren = path.node.children.length > 0;
|
|
2608
2606
|
|
|
2609
|
-
attributes.forEach(attribute => {
|
|
2607
|
+
attributes.forEach((attribute) => {
|
|
2610
2608
|
const node = attribute.node;
|
|
2611
2609
|
if (t__namespace.isJSXSpreadAttribute(node)) {
|
|
2612
2610
|
if (runningObject.length) {
|
|
@@ -2614,51 +2612,51 @@ function createElement(path, { topLevel, hydratable }) {
|
|
|
2614
2612
|
runningObject = [];
|
|
2615
2613
|
}
|
|
2616
2614
|
props.push(
|
|
2617
|
-
|
|
2618
|
-
|
|
2619
|
-
|
|
2620
|
-
|
|
2621
|
-
|
|
2622
|
-
|
|
2623
|
-
|
|
2624
|
-
|
|
2625
|
-
|
|
2626
|
-
|
|
2627
|
-
|
|
2615
|
+
isDynamic(attribute.get("argument"), {
|
|
2616
|
+
checkMember: true
|
|
2617
|
+
}) && (dynamicSpread = true) ?
|
|
2618
|
+
t__namespace.isCallExpression(node.argument) &&
|
|
2619
|
+
!node.argument.arguments.length &&
|
|
2620
|
+
!t__namespace.isCallExpression(node.argument.callee) &&
|
|
2621
|
+
!t__namespace.isMemberExpression(node.argument.callee) ?
|
|
2622
|
+
node.argument.callee :
|
|
2623
|
+
t__namespace.arrowFunctionExpression([], node.argument) :
|
|
2624
|
+
node.argument);
|
|
2625
|
+
|
|
2628
2626
|
} else {
|
|
2629
2627
|
const value = node.value || t__namespace.booleanLiteral(true),
|
|
2630
2628
|
id = convertJSXIdentifier(node.name),
|
|
2631
|
-
key = t__namespace.isJSXNamespacedName(node.name)
|
|
2632
|
-
|
|
2633
|
-
|
|
2629
|
+
key = t__namespace.isJSXNamespacedName(node.name) ?
|
|
2630
|
+
`${node.name.namespace.name}:${node.name.name.name}` :
|
|
2631
|
+
node.name.name;
|
|
2634
2632
|
|
|
2635
2633
|
if (hasChildren && key === "children") return;
|
|
2636
2634
|
if (
|
|
2637
|
-
|
|
2638
|
-
|
|
2639
|
-
|
|
2640
|
-
|
|
2641
|
-
|
|
2642
|
-
|
|
2643
|
-
if (t__namespace.isJSXExpressionContainer(value))
|
|
2635
|
+
key === "ref" ||
|
|
2636
|
+
key.startsWith("use:") ||
|
|
2637
|
+
key.startsWith("prop:") ||
|
|
2638
|
+
key.startsWith("on"))
|
|
2639
|
+
|
|
2640
|
+
return;
|
|
2641
|
+
if (t__namespace.isJSXExpressionContainer(value)) {
|
|
2644
2642
|
if (
|
|
2645
|
-
|
|
2646
|
-
|
|
2647
|
-
|
|
2648
|
-
|
|
2649
|
-
|
|
2643
|
+
isDynamic(attribute.get("value").get("expression"), {
|
|
2644
|
+
checkMember: true,
|
|
2645
|
+
checkTags: true
|
|
2646
|
+
}))
|
|
2647
|
+
{
|
|
2650
2648
|
let expr = t__namespace.arrowFunctionExpression([], value.expression);
|
|
2651
2649
|
runningObject.push(
|
|
2652
|
-
|
|
2653
|
-
|
|
2654
|
-
|
|
2655
|
-
|
|
2656
|
-
|
|
2657
|
-
|
|
2658
|
-
|
|
2659
|
-
|
|
2660
|
-
} else runningObject.push(t__namespace.objectProperty(id, value.expression));
|
|
2661
|
-
|
|
2650
|
+
t__namespace.objectMethod(
|
|
2651
|
+
"get",
|
|
2652
|
+
id,
|
|
2653
|
+
[],
|
|
2654
|
+
t__namespace.blockStatement([t__namespace.returnStatement(expr.body)]),
|
|
2655
|
+
!t__namespace.isValidIdentifier(key)));
|
|
2656
|
+
|
|
2657
|
+
|
|
2658
|
+
} else runningObject.push(t__namespace.objectProperty(id, value.expression));} else
|
|
2659
|
+
runningObject.push(t__namespace.objectProperty(id, value));
|
|
2662
2660
|
}
|
|
2663
2661
|
});
|
|
2664
2662
|
|
|
@@ -2670,22 +2668,22 @@ function createElement(path, { topLevel, hydratable }) {
|
|
|
2670
2668
|
}
|
|
2671
2669
|
|
|
2672
2670
|
const exprs = [
|
|
2673
|
-
|
|
2674
|
-
|
|
2675
|
-
|
|
2676
|
-
|
|
2677
|
-
|
|
2678
|
-
|
|
2679
|
-
|
|
2680
|
-
|
|
2681
|
-
|
|
2682
|
-
|
|
2683
|
-
|
|
2684
|
-
|
|
2685
|
-
|
|
2686
|
-
|
|
2687
|
-
|
|
2688
|
-
|
|
2671
|
+
t__namespace.callExpression(registerImportMethod(path, "ssrElement"), [
|
|
2672
|
+
t__namespace.stringLiteral(tagName),
|
|
2673
|
+
props[0],
|
|
2674
|
+
childNodes.length ?
|
|
2675
|
+
hydratable ?
|
|
2676
|
+
t__namespace.arrowFunctionExpression(
|
|
2677
|
+
[],
|
|
2678
|
+
childNodes.length === 1 ? childNodes[0] : t__namespace.arrayExpression(childNodes)) :
|
|
2679
|
+
|
|
2680
|
+
childNodes.length === 1 ?
|
|
2681
|
+
childNodes[0] :
|
|
2682
|
+
t__namespace.arrayExpression(childNodes) :
|
|
2683
|
+
t__namespace.identifier("undefined"),
|
|
2684
|
+
t__namespace.booleanLiteral(Boolean(topLevel && config.hydratable))])];
|
|
2685
|
+
|
|
2686
|
+
|
|
2689
2687
|
return { exprs, template: "", spreadElement: true };
|
|
2690
2688
|
}
|
|
2691
2689
|
|
|
@@ -2702,18 +2700,18 @@ function transformElement$1(path, info) {
|
|
|
2702
2700
|
};
|
|
2703
2701
|
|
|
2704
2702
|
results.declarations.push(
|
|
2705
|
-
|
|
2706
|
-
|
|
2707
|
-
|
|
2708
|
-
|
|
2709
|
-
|
|
2710
|
-
|
|
2711
|
-
|
|
2712
|
-
|
|
2713
|
-
|
|
2714
|
-
|
|
2715
|
-
|
|
2716
|
-
|
|
2703
|
+
t__namespace.variableDeclarator(
|
|
2704
|
+
results.id,
|
|
2705
|
+
t__namespace.callExpression(
|
|
2706
|
+
registerImportMethod(
|
|
2707
|
+
path,
|
|
2708
|
+
"createElement",
|
|
2709
|
+
getRendererConfig(path, "universal").moduleName),
|
|
2710
|
+
|
|
2711
|
+
[t__namespace.stringLiteral(tagName)])));
|
|
2712
|
+
|
|
2713
|
+
|
|
2714
|
+
|
|
2717
2715
|
|
|
2718
2716
|
transformAttributes(path, results);
|
|
2719
2717
|
transformChildren(path, results);
|
|
@@ -2729,147 +2727,147 @@ function transformAttributes(path, results) {
|
|
|
2729
2727
|
config = getConfig(path);
|
|
2730
2728
|
|
|
2731
2729
|
// preprocess spreads
|
|
2732
|
-
if (attributes.some(attribute => t__namespace.isJSXSpreadAttribute(attribute.node))) {
|
|
2730
|
+
if (attributes.some((attribute) => t__namespace.isJSXSpreadAttribute(attribute.node))) {
|
|
2733
2731
|
[attributes, spreadExpr] = processSpreads(path, attributes, {
|
|
2734
2732
|
elem,
|
|
2735
2733
|
hasChildren,
|
|
2736
2734
|
wrapConditionals: config.wrapConditionals
|
|
2737
2735
|
});
|
|
2738
2736
|
path.get("openingElement").set(
|
|
2739
|
-
|
|
2740
|
-
|
|
2741
|
-
|
|
2737
|
+
"attributes",
|
|
2738
|
+
attributes.map((a) => a.node));
|
|
2739
|
+
|
|
2742
2740
|
}
|
|
2743
2741
|
|
|
2744
|
-
path
|
|
2745
|
-
|
|
2746
|
-
|
|
2747
|
-
|
|
2748
|
-
|
|
2742
|
+
path.
|
|
2743
|
+
get("openingElement").
|
|
2744
|
+
get("attributes").
|
|
2745
|
+
forEach((attribute) => {
|
|
2746
|
+
const node = attribute.node;
|
|
2749
2747
|
|
|
2750
|
-
|
|
2751
|
-
|
|
2752
|
-
|
|
2753
|
-
|
|
2754
|
-
|
|
2755
|
-
|
|
2756
|
-
|
|
2757
|
-
|
|
2758
|
-
|
|
2759
|
-
|
|
2760
|
-
|
|
2761
|
-
|
|
2762
|
-
|
|
2763
|
-
|
|
2764
|
-
|
|
2765
|
-
|
|
2766
|
-
|
|
2767
|
-
|
|
2768
|
-
|
|
2769
|
-
|
|
2770
|
-
|
|
2771
|
-
|
|
2772
|
-
|
|
2773
|
-
results.exprs.unshift(
|
|
2774
|
-
t__namespace.variableDeclaration("var", [
|
|
2775
|
-
t__namespace.variableDeclarator(refIdentifier, value.expression)
|
|
2776
|
-
]),
|
|
2777
|
-
t__namespace.expressionStatement(
|
|
2778
|
-
t__namespace.conditionalExpression(
|
|
2779
|
-
t__namespace.binaryExpression(
|
|
2780
|
-
"===",
|
|
2781
|
-
t__namespace.unaryExpression("typeof", refIdentifier),
|
|
2782
|
-
t__namespace.stringLiteral("function")
|
|
2783
|
-
),
|
|
2784
|
-
t__namespace.callExpression(
|
|
2785
|
-
registerImportMethod(
|
|
2786
|
-
path,
|
|
2787
|
-
"use",
|
|
2788
|
-
getRendererConfig(path, "universal").moduleName
|
|
2789
|
-
),
|
|
2790
|
-
[refIdentifier, elem]
|
|
2791
|
-
),
|
|
2792
|
-
t__namespace.assignmentExpression("=", value.expression, elem)
|
|
2793
|
-
)
|
|
2794
|
-
)
|
|
2795
|
-
);
|
|
2796
|
-
} else if (t__namespace.isFunction(value.expression)) {
|
|
2797
|
-
results.exprs.unshift(
|
|
2798
|
-
t__namespace.expressionStatement(
|
|
2799
|
-
t__namespace.callExpression(
|
|
2800
|
-
registerImportMethod(
|
|
2801
|
-
path,
|
|
2802
|
-
"use",
|
|
2803
|
-
getRendererConfig(path, "universal").moduleName
|
|
2804
|
-
),
|
|
2805
|
-
[value.expression, elem]
|
|
2806
|
-
)
|
|
2807
|
-
)
|
|
2808
|
-
);
|
|
2809
|
-
} else {
|
|
2810
|
-
const refIdentifier = path.scope.generateUidIdentifier("_ref$");
|
|
2811
|
-
results.exprs.unshift(
|
|
2812
|
-
t__namespace.variableDeclaration("var", [
|
|
2813
|
-
t__namespace.variableDeclarator(refIdentifier, value.expression)
|
|
2814
|
-
]),
|
|
2815
|
-
t__namespace.expressionStatement(
|
|
2816
|
-
t__namespace.logicalExpression(
|
|
2817
|
-
"&&",
|
|
2818
|
-
t__namespace.binaryExpression(
|
|
2819
|
-
"===",
|
|
2820
|
-
t__namespace.unaryExpression("typeof", refIdentifier),
|
|
2821
|
-
t__namespace.stringLiteral("function")
|
|
2822
|
-
),
|
|
2823
|
-
t__namespace.callExpression(
|
|
2824
|
-
registerImportMethod(
|
|
2825
|
-
path,
|
|
2826
|
-
"use",
|
|
2827
|
-
getRendererConfig(path, "universal").moduleName
|
|
2828
|
-
),
|
|
2829
|
-
[refIdentifier, elem]
|
|
2830
|
-
)
|
|
2831
|
-
)
|
|
2832
|
-
)
|
|
2833
|
-
);
|
|
2834
|
-
}
|
|
2835
|
-
} else if (key.startsWith("use:")) {
|
|
2836
|
-
// Some trick to treat JSXIdentifier as Identifier
|
|
2837
|
-
node.name.name.type = "Identifier";
|
|
2748
|
+
let value = node.value,
|
|
2749
|
+
key = t__namespace.isJSXNamespacedName(node.name) ?
|
|
2750
|
+
`${node.name.namespace.name}:${node.name.name.name}` :
|
|
2751
|
+
node.name.name,
|
|
2752
|
+
reservedNameSpace = t__namespace.isJSXNamespacedName(node.name) && node.name.namespace.name === "use";
|
|
2753
|
+
if (
|
|
2754
|
+
t__namespace.isJSXNamespacedName(node.name) &&
|
|
2755
|
+
reservedNameSpace &&
|
|
2756
|
+
!t__namespace.isJSXExpressionContainer(value))
|
|
2757
|
+
{
|
|
2758
|
+
node.value = value = t__namespace.jsxExpressionContainer(value || t__namespace.jsxEmptyExpression());
|
|
2759
|
+
}
|
|
2760
|
+
if (t__namespace.isJSXExpressionContainer(value)) {
|
|
2761
|
+
if (key === "ref") {
|
|
2762
|
+
// Normalize expressions for non-null and type-as
|
|
2763
|
+
while (
|
|
2764
|
+
t__namespace.isTSNonNullExpression(value.expression) ||
|
|
2765
|
+
t__namespace.isTSAsExpression(value.expression))
|
|
2766
|
+
{
|
|
2767
|
+
value.expression = value.expression.expression;
|
|
2768
|
+
}
|
|
2769
|
+
if (t__namespace.isLVal(value.expression)) {
|
|
2770
|
+
const refIdentifier = path.scope.generateUidIdentifier("_ref$");
|
|
2838
2771
|
results.exprs.unshift(
|
|
2839
|
-
|
|
2840
|
-
|
|
2841
|
-
|
|
2842
|
-
|
|
2843
|
-
|
|
2844
|
-
|
|
2845
|
-
|
|
2846
|
-
|
|
2847
|
-
|
|
2848
|
-
|
|
2849
|
-
|
|
2850
|
-
|
|
2851
|
-
|
|
2852
|
-
|
|
2853
|
-
|
|
2854
|
-
|
|
2855
|
-
|
|
2856
|
-
|
|
2857
|
-
|
|
2858
|
-
|
|
2859
|
-
|
|
2860
|
-
|
|
2861
|
-
|
|
2862
|
-
|
|
2863
|
-
|
|
2772
|
+
t__namespace.variableDeclaration("var", [
|
|
2773
|
+
t__namespace.variableDeclarator(refIdentifier, value.expression)]),
|
|
2774
|
+
|
|
2775
|
+
t__namespace.expressionStatement(
|
|
2776
|
+
t__namespace.conditionalExpression(
|
|
2777
|
+
t__namespace.binaryExpression(
|
|
2778
|
+
"===",
|
|
2779
|
+
t__namespace.unaryExpression("typeof", refIdentifier),
|
|
2780
|
+
t__namespace.stringLiteral("function")),
|
|
2781
|
+
|
|
2782
|
+
t__namespace.callExpression(
|
|
2783
|
+
registerImportMethod(
|
|
2784
|
+
path,
|
|
2785
|
+
"use",
|
|
2786
|
+
getRendererConfig(path, "universal").moduleName),
|
|
2787
|
+
|
|
2788
|
+
[refIdentifier, elem]),
|
|
2789
|
+
|
|
2790
|
+
t__namespace.assignmentExpression("=", value.expression, elem))));
|
|
2791
|
+
|
|
2792
|
+
|
|
2793
|
+
|
|
2794
|
+
} else if (t__namespace.isFunction(value.expression)) {
|
|
2795
|
+
results.exprs.unshift(
|
|
2796
|
+
t__namespace.expressionStatement(
|
|
2797
|
+
t__namespace.callExpression(
|
|
2798
|
+
registerImportMethod(
|
|
2799
|
+
path,
|
|
2800
|
+
"use",
|
|
2801
|
+
getRendererConfig(path, "universal").moduleName),
|
|
2802
|
+
|
|
2803
|
+
[value.expression, elem])));
|
|
2804
|
+
|
|
2805
|
+
|
|
2806
|
+
|
|
2864
2807
|
} else {
|
|
2865
|
-
|
|
2866
|
-
|
|
2867
|
-
|
|
2808
|
+
const refIdentifier = path.scope.generateUidIdentifier("_ref$");
|
|
2809
|
+
results.exprs.unshift(
|
|
2810
|
+
t__namespace.variableDeclaration("var", [
|
|
2811
|
+
t__namespace.variableDeclarator(refIdentifier, value.expression)]),
|
|
2812
|
+
|
|
2813
|
+
t__namespace.expressionStatement(
|
|
2814
|
+
t__namespace.logicalExpression(
|
|
2815
|
+
"&&",
|
|
2816
|
+
t__namespace.binaryExpression(
|
|
2817
|
+
"===",
|
|
2818
|
+
t__namespace.unaryExpression("typeof", refIdentifier),
|
|
2819
|
+
t__namespace.stringLiteral("function")),
|
|
2820
|
+
|
|
2821
|
+
t__namespace.callExpression(
|
|
2822
|
+
registerImportMethod(
|
|
2823
|
+
path,
|
|
2824
|
+
"use",
|
|
2825
|
+
getRendererConfig(path, "universal").moduleName),
|
|
2826
|
+
|
|
2827
|
+
[refIdentifier, elem]))));
|
|
2828
|
+
|
|
2829
|
+
|
|
2830
|
+
|
|
2831
|
+
|
|
2868
2832
|
}
|
|
2833
|
+
} else if (key.startsWith("use:")) {
|
|
2834
|
+
// Some trick to treat JSXIdentifier as Identifier
|
|
2835
|
+
node.name.name.type = "Identifier";
|
|
2836
|
+
results.exprs.unshift(
|
|
2837
|
+
t__namespace.expressionStatement(
|
|
2838
|
+
t__namespace.callExpression(
|
|
2839
|
+
registerImportMethod(path, "use", getRendererConfig(path, "universal").moduleName),
|
|
2840
|
+
[
|
|
2841
|
+
node.name.name,
|
|
2842
|
+
elem,
|
|
2843
|
+
t__namespace.arrowFunctionExpression(
|
|
2844
|
+
[],
|
|
2845
|
+
t__namespace.isJSXEmptyExpression(value.expression) ?
|
|
2846
|
+
t__namespace.booleanLiteral(true) :
|
|
2847
|
+
value.expression)])));
|
|
2848
|
+
|
|
2849
|
+
|
|
2850
|
+
|
|
2851
|
+
|
|
2852
|
+
|
|
2853
|
+
} else if (key === "children") {
|
|
2854
|
+
children = value;
|
|
2855
|
+
} else if (
|
|
2856
|
+
config.effectWrapper &&
|
|
2857
|
+
isDynamic(attribute.get("value").get("expression"), {
|
|
2858
|
+
checkMember: true
|
|
2859
|
+
}))
|
|
2860
|
+
{
|
|
2861
|
+
results.dynamics.push({ elem, key, value: value.expression });
|
|
2869
2862
|
} else {
|
|
2870
|
-
results.exprs.push(
|
|
2863
|
+
results.exprs.push(
|
|
2864
|
+
t__namespace.expressionStatement(setAttr(attribute, elem, key, value.expression)));
|
|
2865
|
+
|
|
2871
2866
|
}
|
|
2872
|
-
}
|
|
2867
|
+
} else {
|
|
2868
|
+
results.exprs.push(t__namespace.expressionStatement(setAttr(attribute, elem, key, value)));
|
|
2869
|
+
}
|
|
2870
|
+
});
|
|
2873
2871
|
if (spreadExpr) results.exprs.push(spreadExpr);
|
|
2874
2872
|
if (!hasChildren && children) {
|
|
2875
2873
|
path.node.children.push(children);
|
|
@@ -2879,9 +2877,9 @@ function transformAttributes(path, results) {
|
|
|
2879
2877
|
function setAttr(path, elem, name, value, { prevId } = {}) {
|
|
2880
2878
|
if (!value) value = t__namespace.booleanLiteral(true);
|
|
2881
2879
|
return t__namespace.callExpression(
|
|
2882
|
-
|
|
2883
|
-
|
|
2884
|
-
|
|
2880
|
+
registerImportMethod(path, "setProp", getRendererConfig(path, "universal").moduleName),
|
|
2881
|
+
prevId ? [elem, t__namespace.stringLiteral(name), value, prevId] : [elem, t__namespace.stringLiteral(name), value]);
|
|
2882
|
+
|
|
2885
2883
|
}
|
|
2886
2884
|
|
|
2887
2885
|
function transformChildren(path, results) {
|
|
@@ -2905,30 +2903,30 @@ function transformChildren(path, results) {
|
|
|
2905
2903
|
}
|
|
2906
2904
|
if (child.id) {
|
|
2907
2905
|
let insertNode = registerImportMethod(
|
|
2908
|
-
|
|
2909
|
-
|
|
2910
|
-
|
|
2911
|
-
|
|
2906
|
+
path,
|
|
2907
|
+
"insertNode",
|
|
2908
|
+
getRendererConfig(path, "universal").moduleName);
|
|
2909
|
+
|
|
2912
2910
|
let insert = child.id;
|
|
2913
2911
|
if (child.text) {
|
|
2914
2912
|
let createTextNode = registerImportMethod(
|
|
2915
|
-
|
|
2916
|
-
|
|
2917
|
-
|
|
2918
|
-
|
|
2913
|
+
path,
|
|
2914
|
+
"createTextNode",
|
|
2915
|
+
getRendererConfig(path, "universal").moduleName);
|
|
2916
|
+
|
|
2919
2917
|
if (multi) {
|
|
2920
2918
|
results.declarations.push(
|
|
2921
|
-
|
|
2922
|
-
|
|
2923
|
-
|
|
2924
|
-
|
|
2925
|
-
|
|
2926
|
-
|
|
2927
|
-
|
|
2919
|
+
t__namespace.variableDeclarator(
|
|
2920
|
+
child.id,
|
|
2921
|
+
t__namespace.callExpression(createTextNode, [
|
|
2922
|
+
t__namespace.templateLiteral([t__namespace.templateElement({ raw: escapeStringForTemplate(child.template) })], [])])));
|
|
2923
|
+
|
|
2924
|
+
|
|
2925
|
+
|
|
2928
2926
|
} else
|
|
2929
|
-
|
|
2930
|
-
|
|
2931
|
-
|
|
2927
|
+
insert = t__namespace.callExpression(createTextNode, [
|
|
2928
|
+
t__namespace.templateLiteral([t__namespace.templateElement({ raw: escapeStringForTemplate(child.template) })], [])]);
|
|
2929
|
+
|
|
2932
2930
|
}
|
|
2933
2931
|
appends.push(t__namespace.expressionStatement(t__namespace.callExpression(insertNode, [results.id, insert])));
|
|
2934
2932
|
results.declarations.push(...child.declarations);
|
|
@@ -2936,24 +2934,24 @@ function transformChildren(path, results) {
|
|
|
2936
2934
|
results.dynamics.push(...child.dynamics);
|
|
2937
2935
|
} else if (child.exprs.length) {
|
|
2938
2936
|
let insert = registerImportMethod(
|
|
2939
|
-
|
|
2940
|
-
|
|
2941
|
-
|
|
2942
|
-
|
|
2937
|
+
path,
|
|
2938
|
+
"insert",
|
|
2939
|
+
getRendererConfig(path, "universal").moduleName);
|
|
2940
|
+
|
|
2943
2941
|
if (multi) {
|
|
2944
2942
|
results.exprs.push(
|
|
2945
|
-
|
|
2946
|
-
|
|
2947
|
-
|
|
2948
|
-
|
|
2949
|
-
|
|
2950
|
-
|
|
2951
|
-
|
|
2952
|
-
|
|
2943
|
+
t__namespace.expressionStatement(
|
|
2944
|
+
t__namespace.callExpression(insert, [
|
|
2945
|
+
results.id,
|
|
2946
|
+
child.exprs[0],
|
|
2947
|
+
nextChild(childNodes, index) || t__namespace.nullLiteral()])));
|
|
2948
|
+
|
|
2949
|
+
|
|
2950
|
+
|
|
2953
2951
|
} else {
|
|
2954
2952
|
results.exprs.push(
|
|
2955
|
-
|
|
2956
|
-
|
|
2953
|
+
t__namespace.expressionStatement(t__namespace.callExpression(insert, [results.id, child.exprs[0]])));
|
|
2954
|
+
|
|
2957
2955
|
}
|
|
2958
2956
|
}
|
|
2959
2957
|
});
|
|
@@ -2971,13 +2969,13 @@ function processSpreads(path, attributes, { elem, hasChildren, wrapConditionals
|
|
|
2971
2969
|
let runningObject = [];
|
|
2972
2970
|
let dynamicSpread = false;
|
|
2973
2971
|
let firstSpread = false;
|
|
2974
|
-
attributes.forEach(attribute => {
|
|
2972
|
+
attributes.forEach((attribute) => {
|
|
2975
2973
|
const node = attribute.node;
|
|
2976
2974
|
const key =
|
|
2977
|
-
|
|
2978
|
-
|
|
2979
|
-
|
|
2980
|
-
|
|
2975
|
+
!t__namespace.isJSXSpreadAttribute(node) && (
|
|
2976
|
+
t__namespace.isJSXNamespacedName(node.name) ?
|
|
2977
|
+
`${node.name.namespace.name}:${node.name.name.name}` :
|
|
2978
|
+
node.name.name);
|
|
2981
2979
|
if (t__namespace.isJSXSpreadAttribute(node)) {
|
|
2982
2980
|
firstSpread = true;
|
|
2983
2981
|
if (runningObject.length) {
|
|
@@ -2985,50 +2983,50 @@ function processSpreads(path, attributes, { elem, hasChildren, wrapConditionals
|
|
|
2985
2983
|
runningObject = [];
|
|
2986
2984
|
}
|
|
2987
2985
|
spreadArgs.push(
|
|
2988
|
-
|
|
2989
|
-
|
|
2990
|
-
|
|
2991
|
-
|
|
2992
|
-
|
|
2993
|
-
|
|
2994
|
-
|
|
2995
|
-
|
|
2996
|
-
|
|
2997
|
-
|
|
2998
|
-
|
|
2986
|
+
isDynamic(attribute.get("argument"), {
|
|
2987
|
+
checkMember: true
|
|
2988
|
+
}) && (dynamicSpread = true) ?
|
|
2989
|
+
t__namespace.isCallExpression(node.argument) &&
|
|
2990
|
+
!node.argument.arguments.length &&
|
|
2991
|
+
!t__namespace.isCallExpression(node.argument.callee) &&
|
|
2992
|
+
!t__namespace.isMemberExpression(node.argument.callee) ?
|
|
2993
|
+
node.argument.callee :
|
|
2994
|
+
t__namespace.arrowFunctionExpression([], node.argument) :
|
|
2995
|
+
node.argument);
|
|
2996
|
+
|
|
2999
2997
|
} else if (
|
|
3000
|
-
|
|
3001
|
-
|
|
3002
|
-
|
|
3003
|
-
|
|
3004
|
-
|
|
2998
|
+
(firstSpread ||
|
|
2999
|
+
t__namespace.isJSXExpressionContainer(node.value) &&
|
|
3000
|
+
isDynamic(attribute.get("value").get("expression"), { checkMember: true })) &&
|
|
3001
|
+
canNativeSpread(key, { checkNameSpaces: true }))
|
|
3002
|
+
{
|
|
3005
3003
|
const isContainer = t__namespace.isJSXExpressionContainer(node.value);
|
|
3006
3004
|
const dynamic =
|
|
3007
|
-
|
|
3005
|
+
isContainer && isDynamic(attribute.get("value").get("expression"), { checkMember: true });
|
|
3008
3006
|
if (dynamic) {
|
|
3009
3007
|
const id = convertJSXIdentifier(node.name);
|
|
3010
3008
|
let expr =
|
|
3011
|
-
|
|
3012
|
-
|
|
3013
|
-
|
|
3014
|
-
|
|
3015
|
-
|
|
3009
|
+
wrapConditionals && (
|
|
3010
|
+
t__namespace.isLogicalExpression(node.value.expression) ||
|
|
3011
|
+
t__namespace.isConditionalExpression(node.value.expression)) ?
|
|
3012
|
+
transformCondition(attribute.get("value").get("expression"), true) :
|
|
3013
|
+
t__namespace.arrowFunctionExpression([], node.value.expression);
|
|
3016
3014
|
runningObject.push(
|
|
3017
|
-
|
|
3018
|
-
|
|
3019
|
-
|
|
3020
|
-
|
|
3021
|
-
|
|
3022
|
-
|
|
3023
|
-
|
|
3024
|
-
|
|
3015
|
+
t__namespace.objectMethod(
|
|
3016
|
+
"get",
|
|
3017
|
+
id,
|
|
3018
|
+
[],
|
|
3019
|
+
t__namespace.blockStatement([t__namespace.returnStatement(expr.body)]),
|
|
3020
|
+
!t__namespace.isValidIdentifier(key)));
|
|
3021
|
+
|
|
3022
|
+
|
|
3025
3023
|
} else {
|
|
3026
3024
|
runningObject.push(
|
|
3027
|
-
|
|
3028
|
-
|
|
3029
|
-
|
|
3030
|
-
|
|
3031
|
-
|
|
3025
|
+
t__namespace.objectProperty(
|
|
3026
|
+
t__namespace.stringLiteral(key),
|
|
3027
|
+
isContainer ? node.value.expression : node.value || t__namespace.booleanLiteral(true)));
|
|
3028
|
+
|
|
3029
|
+
|
|
3032
3030
|
}
|
|
3033
3031
|
} else filteredAttributes.push(attribute);
|
|
3034
3032
|
});
|
|
@@ -3038,19 +3036,19 @@ function processSpreads(path, attributes, { elem, hasChildren, wrapConditionals
|
|
|
3038
3036
|
}
|
|
3039
3037
|
|
|
3040
3038
|
const props =
|
|
3041
|
-
|
|
3042
|
-
|
|
3043
|
-
|
|
3039
|
+
spreadArgs.length === 1 && !dynamicSpread ?
|
|
3040
|
+
spreadArgs[0] :
|
|
3041
|
+
t__namespace.callExpression(registerImportMethod(path, "mergeProps"), spreadArgs);
|
|
3044
3042
|
|
|
3045
3043
|
return [
|
|
3046
|
-
|
|
3047
|
-
|
|
3048
|
-
|
|
3049
|
-
|
|
3050
|
-
|
|
3051
|
-
|
|
3052
|
-
|
|
3053
|
-
|
|
3044
|
+
filteredAttributes,
|
|
3045
|
+
t__namespace.expressionStatement(
|
|
3046
|
+
t__namespace.callExpression(
|
|
3047
|
+
registerImportMethod(path, "spread", getRendererConfig(path, "universal").moduleName),
|
|
3048
|
+
[elem, props, t__namespace.booleanLiteral(hasChildren)]))];
|
|
3049
|
+
|
|
3050
|
+
|
|
3051
|
+
|
|
3054
3052
|
}
|
|
3055
3053
|
|
|
3056
3054
|
function createTemplate(path, result, wrap) {
|
|
@@ -3058,25 +3056,25 @@ function createTemplate(path, result, wrap) {
|
|
|
3058
3056
|
if (result.id) {
|
|
3059
3057
|
result.decl = t__namespace.variableDeclaration("var", result.declarations);
|
|
3060
3058
|
if (
|
|
3061
|
-
|
|
3062
|
-
|
|
3063
|
-
|
|
3059
|
+
!(result.exprs.length || result.dynamics.length || result.postExprs.length) &&
|
|
3060
|
+
result.decl.declarations.length === 1)
|
|
3061
|
+
{
|
|
3064
3062
|
return result.decl.declarations[0].init;
|
|
3065
3063
|
} else {
|
|
3066
3064
|
return t__namespace.callExpression(
|
|
3067
|
-
|
|
3068
|
-
|
|
3069
|
-
|
|
3070
|
-
|
|
3071
|
-
|
|
3072
|
-
|
|
3073
|
-
|
|
3074
|
-
|
|
3075
|
-
|
|
3076
|
-
|
|
3077
|
-
|
|
3078
|
-
|
|
3079
|
-
|
|
3065
|
+
t__namespace.arrowFunctionExpression(
|
|
3066
|
+
[],
|
|
3067
|
+
t__namespace.blockStatement([
|
|
3068
|
+
result.decl,
|
|
3069
|
+
...result.exprs.concat(
|
|
3070
|
+
wrapDynamics(path, result.dynamics) || [],
|
|
3071
|
+
result.postExprs || []),
|
|
3072
|
+
|
|
3073
|
+
t__namespace.returnStatement(result.id)])),
|
|
3074
|
+
|
|
3075
|
+
|
|
3076
|
+
[]);
|
|
3077
|
+
|
|
3080
3078
|
}
|
|
3081
3079
|
}
|
|
3082
3080
|
if (wrap && result.dynamic && config.memoWrapper) {
|
|
@@ -3095,16 +3093,16 @@ function wrapDynamics(path, dynamics) {
|
|
|
3095
3093
|
const prevValue = t__namespace.identifier("_$p");
|
|
3096
3094
|
|
|
3097
3095
|
return t__namespace.expressionStatement(
|
|
3098
|
-
|
|
3099
|
-
|
|
3100
|
-
|
|
3101
|
-
|
|
3102
|
-
|
|
3103
|
-
|
|
3104
|
-
|
|
3105
|
-
|
|
3106
|
-
|
|
3107
|
-
|
|
3096
|
+
t__namespace.callExpression(effectWrapperId, [
|
|
3097
|
+
t__namespace.arrowFunctionExpression(
|
|
3098
|
+
[prevValue],
|
|
3099
|
+
setAttr(path, dynamics[0].elem, dynamics[0].key, dynamics[0].value, {
|
|
3100
|
+
dynamic: true,
|
|
3101
|
+
prevId: prevValue
|
|
3102
|
+
}))]));
|
|
3103
|
+
|
|
3104
|
+
|
|
3105
|
+
|
|
3108
3106
|
}
|
|
3109
3107
|
|
|
3110
3108
|
const prevId = t__namespace.identifier("_p$");
|
|
@@ -3126,42 +3124,42 @@ function wrapDynamics(path, dynamics) {
|
|
|
3126
3124
|
declarations.push(t__namespace.variableDeclarator(varIdent, value));
|
|
3127
3125
|
|
|
3128
3126
|
statements.push(
|
|
3129
|
-
|
|
3130
|
-
|
|
3131
|
-
|
|
3132
|
-
|
|
3133
|
-
|
|
3134
|
-
|
|
3135
|
-
|
|
3136
|
-
|
|
3137
|
-
|
|
3138
|
-
|
|
3139
|
-
|
|
3140
|
-
|
|
3127
|
+
t__namespace.expressionStatement(
|
|
3128
|
+
t__namespace.logicalExpression(
|
|
3129
|
+
"&&",
|
|
3130
|
+
t__namespace.binaryExpression("!==", varIdent, propMember),
|
|
3131
|
+
t__namespace.assignmentExpression(
|
|
3132
|
+
"=",
|
|
3133
|
+
propMember,
|
|
3134
|
+
setAttr(path, elem, key, varIdent, { dynamic: true, prevId: propMember })))));
|
|
3135
|
+
|
|
3136
|
+
|
|
3137
|
+
|
|
3138
|
+
|
|
3141
3139
|
});
|
|
3142
3140
|
|
|
3143
3141
|
return t__namespace.expressionStatement(
|
|
3144
|
-
|
|
3145
|
-
|
|
3146
|
-
|
|
3147
|
-
|
|
3148
|
-
|
|
3149
|
-
|
|
3150
|
-
|
|
3151
|
-
|
|
3152
|
-
|
|
3153
|
-
|
|
3154
|
-
|
|
3155
|
-
|
|
3156
|
-
|
|
3157
|
-
|
|
3142
|
+
t__namespace.callExpression(effectWrapperId, [
|
|
3143
|
+
t__namespace.arrowFunctionExpression(
|
|
3144
|
+
[prevId],
|
|
3145
|
+
t__namespace.blockStatement([
|
|
3146
|
+
t__namespace.variableDeclaration("var", declarations),
|
|
3147
|
+
...statements,
|
|
3148
|
+
t__namespace.returnStatement(prevId)])),
|
|
3149
|
+
|
|
3150
|
+
|
|
3151
|
+
t__namespace.objectExpression(
|
|
3152
|
+
properties.map((id) => t__namespace.objectProperty(id, t__namespace.identifier("undefined"))))]));
|
|
3153
|
+
|
|
3154
|
+
|
|
3155
|
+
|
|
3158
3156
|
}
|
|
3159
3157
|
|
|
3160
3158
|
function convertComponentIdentifier(node) {
|
|
3161
3159
|
if (t__namespace.isJSXIdentifier(node)) {
|
|
3162
3160
|
if (node.name === 'this') return t__namespace.thisExpression();
|
|
3163
|
-
if (t__namespace.isValidIdentifier(node.name)) node.type = "Identifier";
|
|
3164
|
-
|
|
3161
|
+
if (t__namespace.isValidIdentifier(node.name)) node.type = "Identifier";else
|
|
3162
|
+
return t__namespace.stringLiteral(node.name);
|
|
3165
3163
|
} else if (t__namespace.isJSXMemberExpression(node)) {
|
|
3166
3164
|
const prop = convertComponentIdentifier(node.property);
|
|
3167
3165
|
const computed = t__namespace.isStringLiteral(prop);
|
|
@@ -3185,168 +3183,168 @@ function transformComponent(path) {
|
|
|
3185
3183
|
tagId.name = newTagId.name;
|
|
3186
3184
|
}
|
|
3187
3185
|
|
|
3188
|
-
path
|
|
3189
|
-
|
|
3190
|
-
|
|
3191
|
-
|
|
3192
|
-
|
|
3193
|
-
|
|
3194
|
-
|
|
3195
|
-
|
|
3196
|
-
|
|
3197
|
-
}
|
|
3198
|
-
props.push(
|
|
3199
|
-
isDynamic(attribute.get("argument"), {
|
|
3200
|
-
checkMember: true
|
|
3201
|
-
}) && (dynamicSpread = true)
|
|
3202
|
-
? t__namespace.isCallExpression(node.argument) &&
|
|
3203
|
-
!node.argument.arguments.length &&
|
|
3204
|
-
!t__namespace.isCallExpression(node.argument.callee) &&
|
|
3205
|
-
!t__namespace.isMemberExpression(node.argument.callee)
|
|
3206
|
-
? node.argument.callee
|
|
3207
|
-
: t__namespace.arrowFunctionExpression([], node.argument)
|
|
3208
|
-
: node.argument
|
|
3209
|
-
);
|
|
3210
|
-
} else {
|
|
3211
|
-
// handle weird babel bug around HTML entities
|
|
3212
|
-
const value = (t__namespace.isStringLiteral(node.value) ? t__namespace.stringLiteral(node.value.value): node.value) || t__namespace.booleanLiteral(true),
|
|
3213
|
-
id = convertJSXIdentifier(node.name),
|
|
3214
|
-
key = id.name;
|
|
3215
|
-
if (hasChildren && key === "children") return;
|
|
3216
|
-
if (t__namespace.isJSXExpressionContainer(value))
|
|
3217
|
-
if (key === "ref") {
|
|
3218
|
-
if (config.generate === "ssr") return;
|
|
3219
|
-
// Normalize expressions for non-null and type-as
|
|
3220
|
-
while (
|
|
3221
|
-
t__namespace.isTSNonNullExpression(value.expression) ||
|
|
3222
|
-
t__namespace.isTSAsExpression(value.expression) ||
|
|
3223
|
-
t__namespace.isTSSatisfiesExpression(value.expression)
|
|
3224
|
-
) {
|
|
3225
|
-
value.expression = value.expression.expression;
|
|
3226
|
-
}
|
|
3227
|
-
let binding,
|
|
3228
|
-
isFunction =
|
|
3229
|
-
t__namespace.isIdentifier(value.expression) &&
|
|
3230
|
-
(binding = path.scope.getBinding(value.expression.name)) &&
|
|
3231
|
-
binding.kind === "const";
|
|
3232
|
-
if (!isFunction && t__namespace.isLVal(value.expression)) {
|
|
3233
|
-
const refIdentifier = path.scope.generateUidIdentifier("_ref$");
|
|
3234
|
-
runningObject.push(
|
|
3235
|
-
t__namespace.objectMethod(
|
|
3236
|
-
"method",
|
|
3237
|
-
t__namespace.identifier("ref"),
|
|
3238
|
-
[t__namespace.identifier("r$")],
|
|
3239
|
-
t__namespace.blockStatement([
|
|
3240
|
-
t__namespace.variableDeclaration("var", [
|
|
3241
|
-
t__namespace.variableDeclarator(refIdentifier, value.expression)
|
|
3242
|
-
]),
|
|
3243
|
-
t__namespace.expressionStatement(
|
|
3244
|
-
t__namespace.conditionalExpression(
|
|
3245
|
-
t__namespace.binaryExpression(
|
|
3246
|
-
"===",
|
|
3247
|
-
t__namespace.unaryExpression("typeof", refIdentifier),
|
|
3248
|
-
t__namespace.stringLiteral("function")
|
|
3249
|
-
),
|
|
3250
|
-
t__namespace.callExpression(refIdentifier, [t__namespace.identifier("r$")]),
|
|
3251
|
-
t__namespace.assignmentExpression("=", value.expression, t__namespace.identifier("r$"))
|
|
3252
|
-
)
|
|
3253
|
-
)
|
|
3254
|
-
])
|
|
3255
|
-
)
|
|
3256
|
-
);
|
|
3257
|
-
} else if (isFunction || t__namespace.isFunction(value.expression)) {
|
|
3258
|
-
runningObject.push(t__namespace.objectProperty(t__namespace.identifier("ref"), value.expression));
|
|
3259
|
-
} else if (t__namespace.isCallExpression(value.expression)) {
|
|
3260
|
-
const refIdentifier = path.scope.generateUidIdentifier("_ref$");
|
|
3261
|
-
runningObject.push(
|
|
3262
|
-
t__namespace.objectMethod(
|
|
3263
|
-
"method",
|
|
3264
|
-
t__namespace.identifier("ref"),
|
|
3265
|
-
[t__namespace.identifier("r$")],
|
|
3266
|
-
t__namespace.blockStatement([
|
|
3267
|
-
t__namespace.variableDeclaration("var", [
|
|
3268
|
-
t__namespace.variableDeclarator(refIdentifier, value.expression)
|
|
3269
|
-
]),
|
|
3270
|
-
t__namespace.expressionStatement(
|
|
3271
|
-
t__namespace.logicalExpression(
|
|
3272
|
-
"&&",
|
|
3273
|
-
t__namespace.binaryExpression(
|
|
3274
|
-
"===",
|
|
3275
|
-
t__namespace.unaryExpression("typeof", refIdentifier),
|
|
3276
|
-
t__namespace.stringLiteral("function")
|
|
3277
|
-
),
|
|
3278
|
-
t__namespace.callExpression(refIdentifier, [t__namespace.identifier("r$")])
|
|
3279
|
-
)
|
|
3280
|
-
)
|
|
3281
|
-
])
|
|
3282
|
-
)
|
|
3283
|
-
);
|
|
3284
|
-
}
|
|
3285
|
-
} else if (
|
|
3286
|
-
isDynamic(attribute.get("value").get("expression"), {
|
|
3287
|
-
checkMember: true,
|
|
3288
|
-
checkTags: true
|
|
3289
|
-
})
|
|
3290
|
-
) {
|
|
3291
|
-
if (
|
|
3292
|
-
config.wrapConditionals &&
|
|
3293
|
-
config.generate !== "ssr" &&
|
|
3294
|
-
(t__namespace.isLogicalExpression(value.expression) ||
|
|
3295
|
-
t__namespace.isConditionalExpression(value.expression))
|
|
3296
|
-
) {
|
|
3297
|
-
const expr = transformCondition(attribute.get("value").get("expression"), true);
|
|
3298
|
-
|
|
3299
|
-
runningObject.push(
|
|
3300
|
-
t__namespace.objectMethod(
|
|
3301
|
-
"get",
|
|
3302
|
-
id,
|
|
3303
|
-
[],
|
|
3304
|
-
t__namespace.blockStatement([t__namespace.returnStatement(expr.body)]),
|
|
3305
|
-
!t__namespace.isValidIdentifier(key)
|
|
3306
|
-
)
|
|
3307
|
-
);
|
|
3308
|
-
} else if (
|
|
3309
|
-
t__namespace.isCallExpression(value.expression) &&
|
|
3310
|
-
t__namespace.isArrowFunctionExpression(value.expression.callee) &&
|
|
3311
|
-
value.expression.callee.params.length === 0
|
|
3312
|
-
) {
|
|
3313
|
-
const callee = value.expression.callee;
|
|
3314
|
-
const body = t__namespace.isBlockStatement(callee.body)
|
|
3315
|
-
? callee.body
|
|
3316
|
-
: t__namespace.blockStatement([t__namespace.returnStatement(callee.body)]);
|
|
3317
|
-
|
|
3318
|
-
runningObject.push(t__namespace.objectMethod("get", id, [], body, !t__namespace.isValidIdentifier(key)));
|
|
3319
|
-
} else {
|
|
3320
|
-
runningObject.push(
|
|
3321
|
-
t__namespace.objectMethod(
|
|
3322
|
-
"get",
|
|
3323
|
-
id,
|
|
3324
|
-
[],
|
|
3325
|
-
t__namespace.blockStatement([t__namespace.returnStatement(value.expression)]),
|
|
3326
|
-
!t__namespace.isValidIdentifier(key)
|
|
3327
|
-
)
|
|
3328
|
-
);
|
|
3329
|
-
}
|
|
3330
|
-
} else runningObject.push(t__namespace.objectProperty(id, value.expression));
|
|
3331
|
-
else runningObject.push(t__namespace.objectProperty(id, value));
|
|
3186
|
+
path.
|
|
3187
|
+
get("openingElement").
|
|
3188
|
+
get("attributes").
|
|
3189
|
+
forEach((attribute) => {
|
|
3190
|
+
const node = attribute.node;
|
|
3191
|
+
if (t__namespace.isJSXSpreadAttribute(node)) {
|
|
3192
|
+
if (runningObject.length) {
|
|
3193
|
+
props.push(t__namespace.objectExpression(runningObject));
|
|
3194
|
+
runningObject = [];
|
|
3332
3195
|
}
|
|
3333
|
-
|
|
3196
|
+
props.push(
|
|
3197
|
+
isDynamic(attribute.get("argument"), {
|
|
3198
|
+
checkMember: true
|
|
3199
|
+
}) && (dynamicSpread = true) ?
|
|
3200
|
+
t__namespace.isCallExpression(node.argument) &&
|
|
3201
|
+
!node.argument.arguments.length &&
|
|
3202
|
+
!t__namespace.isCallExpression(node.argument.callee) &&
|
|
3203
|
+
!t__namespace.isMemberExpression(node.argument.callee) ?
|
|
3204
|
+
node.argument.callee :
|
|
3205
|
+
t__namespace.arrowFunctionExpression([], node.argument) :
|
|
3206
|
+
node.argument);
|
|
3207
|
+
|
|
3208
|
+
} else {
|
|
3209
|
+
// handle weird babel bug around HTML entities
|
|
3210
|
+
const value = (t__namespace.isStringLiteral(node.value) ? t__namespace.stringLiteral(node.value.value) : node.value) || t__namespace.booleanLiteral(true),
|
|
3211
|
+
id = convertJSXIdentifier(node.name),
|
|
3212
|
+
key = id.name;
|
|
3213
|
+
if (hasChildren && key === "children") return;
|
|
3214
|
+
if (t__namespace.isJSXExpressionContainer(value)) {
|
|
3215
|
+
if (key === "ref") {
|
|
3216
|
+
if (config.generate === "ssr") return;
|
|
3217
|
+
// Normalize expressions for non-null and type-as
|
|
3218
|
+
while (
|
|
3219
|
+
t__namespace.isTSNonNullExpression(value.expression) ||
|
|
3220
|
+
t__namespace.isTSAsExpression(value.expression) ||
|
|
3221
|
+
t__namespace.isTSSatisfiesExpression(value.expression))
|
|
3222
|
+
{
|
|
3223
|
+
value.expression = value.expression.expression;
|
|
3224
|
+
}
|
|
3225
|
+
let binding,
|
|
3226
|
+
isFunction =
|
|
3227
|
+
t__namespace.isIdentifier(value.expression) && (
|
|
3228
|
+
binding = path.scope.getBinding(value.expression.name)) &&
|
|
3229
|
+
binding.kind === "const";
|
|
3230
|
+
if (!isFunction && t__namespace.isLVal(value.expression)) {
|
|
3231
|
+
const refIdentifier = path.scope.generateUidIdentifier("_ref$");
|
|
3232
|
+
runningObject.push(
|
|
3233
|
+
t__namespace.objectMethod(
|
|
3234
|
+
"method",
|
|
3235
|
+
t__namespace.identifier("ref"),
|
|
3236
|
+
[t__namespace.identifier("r$")],
|
|
3237
|
+
t__namespace.blockStatement([
|
|
3238
|
+
t__namespace.variableDeclaration("var", [
|
|
3239
|
+
t__namespace.variableDeclarator(refIdentifier, value.expression)]),
|
|
3240
|
+
|
|
3241
|
+
t__namespace.expressionStatement(
|
|
3242
|
+
t__namespace.conditionalExpression(
|
|
3243
|
+
t__namespace.binaryExpression(
|
|
3244
|
+
"===",
|
|
3245
|
+
t__namespace.unaryExpression("typeof", refIdentifier),
|
|
3246
|
+
t__namespace.stringLiteral("function")),
|
|
3247
|
+
|
|
3248
|
+
t__namespace.callExpression(refIdentifier, [t__namespace.identifier("r$")]),
|
|
3249
|
+
t__namespace.assignmentExpression("=", value.expression, t__namespace.identifier("r$"))))])));
|
|
3250
|
+
|
|
3251
|
+
|
|
3252
|
+
|
|
3253
|
+
|
|
3254
|
+
|
|
3255
|
+
} else if (isFunction || t__namespace.isFunction(value.expression)) {
|
|
3256
|
+
runningObject.push(t__namespace.objectProperty(t__namespace.identifier("ref"), value.expression));
|
|
3257
|
+
} else if (t__namespace.isCallExpression(value.expression)) {
|
|
3258
|
+
const refIdentifier = path.scope.generateUidIdentifier("_ref$");
|
|
3259
|
+
runningObject.push(
|
|
3260
|
+
t__namespace.objectMethod(
|
|
3261
|
+
"method",
|
|
3262
|
+
t__namespace.identifier("ref"),
|
|
3263
|
+
[t__namespace.identifier("r$")],
|
|
3264
|
+
t__namespace.blockStatement([
|
|
3265
|
+
t__namespace.variableDeclaration("var", [
|
|
3266
|
+
t__namespace.variableDeclarator(refIdentifier, value.expression)]),
|
|
3267
|
+
|
|
3268
|
+
t__namespace.expressionStatement(
|
|
3269
|
+
t__namespace.logicalExpression(
|
|
3270
|
+
"&&",
|
|
3271
|
+
t__namespace.binaryExpression(
|
|
3272
|
+
"===",
|
|
3273
|
+
t__namespace.unaryExpression("typeof", refIdentifier),
|
|
3274
|
+
t__namespace.stringLiteral("function")),
|
|
3275
|
+
|
|
3276
|
+
t__namespace.callExpression(refIdentifier, [t__namespace.identifier("r$")])))])));
|
|
3277
|
+
|
|
3278
|
+
|
|
3279
|
+
|
|
3280
|
+
|
|
3281
|
+
|
|
3282
|
+
}
|
|
3283
|
+
} else if (
|
|
3284
|
+
isDynamic(attribute.get("value").get("expression"), {
|
|
3285
|
+
checkMember: true,
|
|
3286
|
+
checkTags: true
|
|
3287
|
+
}))
|
|
3288
|
+
{
|
|
3289
|
+
if (
|
|
3290
|
+
config.wrapConditionals &&
|
|
3291
|
+
config.generate !== "ssr" && (
|
|
3292
|
+
t__namespace.isLogicalExpression(value.expression) ||
|
|
3293
|
+
t__namespace.isConditionalExpression(value.expression)))
|
|
3294
|
+
{
|
|
3295
|
+
const expr = transformCondition(attribute.get("value").get("expression"), true);
|
|
3296
|
+
|
|
3297
|
+
runningObject.push(
|
|
3298
|
+
t__namespace.objectMethod(
|
|
3299
|
+
"get",
|
|
3300
|
+
id,
|
|
3301
|
+
[],
|
|
3302
|
+
t__namespace.blockStatement([t__namespace.returnStatement(expr.body)]),
|
|
3303
|
+
!t__namespace.isValidIdentifier(key)));
|
|
3304
|
+
|
|
3305
|
+
|
|
3306
|
+
} else if (
|
|
3307
|
+
t__namespace.isCallExpression(value.expression) &&
|
|
3308
|
+
t__namespace.isArrowFunctionExpression(value.expression.callee) &&
|
|
3309
|
+
value.expression.callee.params.length === 0)
|
|
3310
|
+
{
|
|
3311
|
+
const callee = value.expression.callee;
|
|
3312
|
+
const body = t__namespace.isBlockStatement(callee.body) ?
|
|
3313
|
+
callee.body :
|
|
3314
|
+
t__namespace.blockStatement([t__namespace.returnStatement(callee.body)]);
|
|
3315
|
+
|
|
3316
|
+
runningObject.push(t__namespace.objectMethod("get", id, [], body, !t__namespace.isValidIdentifier(key)));
|
|
3317
|
+
} else {
|
|
3318
|
+
runningObject.push(
|
|
3319
|
+
t__namespace.objectMethod(
|
|
3320
|
+
"get",
|
|
3321
|
+
id,
|
|
3322
|
+
[],
|
|
3323
|
+
t__namespace.blockStatement([t__namespace.returnStatement(value.expression)]),
|
|
3324
|
+
!t__namespace.isValidIdentifier(key)));
|
|
3325
|
+
|
|
3326
|
+
|
|
3327
|
+
}
|
|
3328
|
+
} else runningObject.push(t__namespace.objectProperty(id, value.expression));} else
|
|
3329
|
+
runningObject.push(t__namespace.objectProperty(id, value));
|
|
3330
|
+
}
|
|
3331
|
+
});
|
|
3334
3332
|
|
|
3335
3333
|
const childResult = transformComponentChildren(path.get("children"), config);
|
|
3336
3334
|
if (childResult && childResult[0]) {
|
|
3337
3335
|
if (childResult[1]) {
|
|
3338
3336
|
const body =
|
|
3339
|
-
|
|
3340
|
-
|
|
3341
|
-
|
|
3337
|
+
t__namespace.isCallExpression(childResult[0]) && t__namespace.isFunction(childResult[0].arguments[0]) ?
|
|
3338
|
+
childResult[0].arguments[0].body :
|
|
3339
|
+
childResult[0].body ? childResult[0].body : childResult[0];
|
|
3342
3340
|
runningObject.push(
|
|
3343
|
-
|
|
3344
|
-
|
|
3345
|
-
|
|
3346
|
-
|
|
3347
|
-
|
|
3348
|
-
|
|
3349
|
-
|
|
3341
|
+
t__namespace.objectMethod(
|
|
3342
|
+
"get",
|
|
3343
|
+
t__namespace.identifier("children"),
|
|
3344
|
+
[],
|
|
3345
|
+
t__namespace.isExpression(body) ? t__namespace.blockStatement([t__namespace.returnStatement(body)]) : body));
|
|
3346
|
+
|
|
3347
|
+
|
|
3350
3348
|
} else runningObject.push(t__namespace.objectProperty(t__namespace.identifier("children"), childResult[0]));
|
|
3351
3349
|
}
|
|
3352
3350
|
if (runningObject.length || !props.length) props.push(t__namespace.objectExpression(runningObject));
|
|
@@ -3361,11 +3359,11 @@ function transformComponent(path) {
|
|
|
3361
3359
|
if (exprs.length > 1) {
|
|
3362
3360
|
const ret = exprs.pop();
|
|
3363
3361
|
exprs = [
|
|
3364
|
-
|
|
3365
|
-
|
|
3366
|
-
|
|
3367
|
-
|
|
3368
|
-
|
|
3362
|
+
t__namespace.callExpression(
|
|
3363
|
+
t__namespace.arrowFunctionExpression([], t__namespace.blockStatement([...exprs, t__namespace.returnStatement(ret)])),
|
|
3364
|
+
[])];
|
|
3365
|
+
|
|
3366
|
+
|
|
3369
3367
|
}
|
|
3370
3368
|
return { exprs, template: "", component: true };
|
|
3371
3369
|
}
|
|
@@ -3391,11 +3389,11 @@ function transformComponentChildren(children, config) {
|
|
|
3391
3389
|
});
|
|
3392
3390
|
dynamic = dynamic || child.dynamic;
|
|
3393
3391
|
if (
|
|
3394
|
-
|
|
3395
|
-
|
|
3396
|
-
|
|
3397
|
-
|
|
3398
|
-
|
|
3392
|
+
config.generate === "ssr" &&
|
|
3393
|
+
filteredChildren.length > 1 &&
|
|
3394
|
+
child.dynamic &&
|
|
3395
|
+
t__namespace.isFunction(child.exprs[0]))
|
|
3396
|
+
{
|
|
3399
3397
|
child.exprs[0] = child.exprs[0].body;
|
|
3400
3398
|
}
|
|
3401
3399
|
pathNodes.push(path.node);
|
|
@@ -3407,16 +3405,16 @@ function transformComponentChildren(children, config) {
|
|
|
3407
3405
|
if (transformedChildren.length === 1) {
|
|
3408
3406
|
transformedChildren = transformedChildren[0];
|
|
3409
3407
|
if (
|
|
3410
|
-
|
|
3411
|
-
|
|
3412
|
-
|
|
3413
|
-
|
|
3408
|
+
!t__namespace.isJSXExpressionContainer(pathNodes[0]) &&
|
|
3409
|
+
!t__namespace.isJSXSpreadChild(pathNodes[0]) &&
|
|
3410
|
+
!t__namespace.isJSXText(pathNodes[0]))
|
|
3411
|
+
{
|
|
3414
3412
|
transformedChildren =
|
|
3415
|
-
|
|
3416
|
-
|
|
3417
|
-
|
|
3418
|
-
|
|
3419
|
-
|
|
3413
|
+
t__namespace.isCallExpression(transformedChildren) &&
|
|
3414
|
+
!transformedChildren.arguments.length &&
|
|
3415
|
+
!t__namespace.isIdentifier(transformedChildren.callee) ?
|
|
3416
|
+
transformedChildren.callee :
|
|
3417
|
+
t__namespace.arrowFunctionExpression([], transformedChildren);
|
|
3420
3418
|
dynamic = true;
|
|
3421
3419
|
}
|
|
3422
3420
|
} else {
|
|
@@ -3445,14 +3443,14 @@ function transformJSX(path) {
|
|
|
3445
3443
|
const config = getConfig(path);
|
|
3446
3444
|
const replace = transformThis(path);
|
|
3447
3445
|
const result = transformNode(
|
|
3448
|
-
|
|
3449
|
-
|
|
3450
|
-
|
|
3451
|
-
|
|
3452
|
-
|
|
3453
|
-
|
|
3454
|
-
|
|
3455
|
-
|
|
3446
|
+
path,
|
|
3447
|
+
t__namespace.isJSXFragment(path.node) ?
|
|
3448
|
+
{} :
|
|
3449
|
+
{
|
|
3450
|
+
topLevel: true,
|
|
3451
|
+
lastElement: true
|
|
3452
|
+
});
|
|
3453
|
+
|
|
3456
3454
|
|
|
3457
3455
|
const template = getCreateTemplate(config, path, result);
|
|
3458
3456
|
|
|
@@ -3496,20 +3494,20 @@ function transformThis(path) {
|
|
|
3496
3494
|
}
|
|
3497
3495
|
}
|
|
3498
3496
|
});
|
|
3499
|
-
return node => {
|
|
3497
|
+
return (node) => {
|
|
3500
3498
|
if (thisId) {
|
|
3501
3499
|
if (!parent || parent.block.type === "ClassMethod") {
|
|
3502
3500
|
const decl = t__namespace.variableDeclaration("const", [
|
|
3503
|
-
|
|
3504
|
-
|
|
3501
|
+
t__namespace.variableDeclarator(thisId, t__namespace.thisExpression())]);
|
|
3502
|
+
|
|
3505
3503
|
if (parent) {
|
|
3506
3504
|
const stmt = path.getStatementParent();
|
|
3507
3505
|
stmt.insertBefore(decl);
|
|
3508
3506
|
} else {
|
|
3509
3507
|
return t__namespace.callExpression(
|
|
3510
|
-
|
|
3511
|
-
|
|
3512
|
-
|
|
3508
|
+
t__namespace.arrowFunctionExpression([], t__namespace.blockStatement([decl, t__namespace.returnStatement(node)])),
|
|
3509
|
+
[]);
|
|
3510
|
+
|
|
3513
3511
|
}
|
|
3514
3512
|
} else {
|
|
3515
3513
|
parent.push({
|
|
@@ -3536,11 +3534,11 @@ function transformNode(path, info = {}) {
|
|
|
3536
3534
|
return results;
|
|
3537
3535
|
} else if (t__namespace.isJSXText(node) || (staticValue = getStaticExpression(path)) !== false) {
|
|
3538
3536
|
const text =
|
|
3539
|
-
|
|
3540
|
-
|
|
3541
|
-
|
|
3542
|
-
|
|
3543
|
-
|
|
3537
|
+
staticValue !== undefined ?
|
|
3538
|
+
info.doNotEscape ?
|
|
3539
|
+
staticValue.toString() :
|
|
3540
|
+
escapeHTML(staticValue.toString()) :
|
|
3541
|
+
trimWhitespace(node.extra.raw);
|
|
3544
3542
|
if (!text.length) return null;
|
|
3545
3543
|
const results = {
|
|
3546
3544
|
template: text,
|
|
@@ -3551,56 +3549,56 @@ function transformNode(path, info = {}) {
|
|
|
3551
3549
|
text: true
|
|
3552
3550
|
};
|
|
3553
3551
|
if (!info.skipId && config.generate !== "ssr")
|
|
3554
|
-
|
|
3552
|
+
results.id = path.scope.generateUidIdentifier("el$");
|
|
3555
3553
|
return results;
|
|
3556
3554
|
} else if (t__namespace.isJSXExpressionContainer(node)) {
|
|
3557
3555
|
if (t__namespace.isJSXEmptyExpression(node.expression)) return null;
|
|
3558
3556
|
if (
|
|
3559
|
-
|
|
3560
|
-
|
|
3561
|
-
|
|
3562
|
-
|
|
3563
|
-
|
|
3564
|
-
|
|
3557
|
+
!isDynamic(path.get("expression"), {
|
|
3558
|
+
checkMember: true,
|
|
3559
|
+
checkTags: !!info.componentChild,
|
|
3560
|
+
native: !info.componentChild
|
|
3561
|
+
}))
|
|
3562
|
+
{
|
|
3565
3563
|
return { exprs: [node.expression], template: "" };
|
|
3566
3564
|
}
|
|
3567
3565
|
const expr =
|
|
3568
|
-
|
|
3569
|
-
|
|
3570
|
-
|
|
3571
|
-
|
|
3572
|
-
|
|
3573
|
-
|
|
3574
|
-
|
|
3575
|
-
|
|
3576
|
-
|
|
3577
|
-
|
|
3578
|
-
|
|
3579
|
-
|
|
3566
|
+
config.wrapConditionals &&
|
|
3567
|
+
config.generate !== "ssr" && (
|
|
3568
|
+
t__namespace.isLogicalExpression(node.expression) || t__namespace.isConditionalExpression(node.expression)) ?
|
|
3569
|
+
transformCondition(path.get("expression"), info.componentChild || info.fragmentChild) :
|
|
3570
|
+
!info.componentChild && (
|
|
3571
|
+
config.generate !== "ssr" || info.fragmentChild) &&
|
|
3572
|
+
t__namespace.isCallExpression(node.expression) &&
|
|
3573
|
+
!t__namespace.isCallExpression(node.expression.callee) &&
|
|
3574
|
+
!t__namespace.isMemberExpression(node.expression.callee) &&
|
|
3575
|
+
node.expression.arguments.length === 0 ?
|
|
3576
|
+
node.expression.callee :
|
|
3577
|
+
t__namespace.arrowFunctionExpression([], node.expression);
|
|
3580
3578
|
return {
|
|
3581
3579
|
exprs:
|
|
3582
|
-
|
|
3583
|
-
|
|
3584
|
-
|
|
3585
|
-
|
|
3586
|
-
|
|
3587
|
-
|
|
3588
|
-
|
|
3589
|
-
|
|
3590
|
-
|
|
3591
|
-
|
|
3592
|
-
|
|
3580
|
+
expr.length > 1 ?
|
|
3581
|
+
[
|
|
3582
|
+
t__namespace.callExpression(
|
|
3583
|
+
t__namespace.arrowFunctionExpression(
|
|
3584
|
+
[],
|
|
3585
|
+
t__namespace.blockStatement([expr[0], t__namespace.returnStatement(expr[1])])),
|
|
3586
|
+
|
|
3587
|
+
[])] :
|
|
3588
|
+
|
|
3589
|
+
|
|
3590
|
+
[expr],
|
|
3593
3591
|
template: "",
|
|
3594
3592
|
dynamic: true
|
|
3595
3593
|
};
|
|
3596
3594
|
} else if (t__namespace.isJSXSpreadChild(node)) {
|
|
3597
3595
|
if (
|
|
3598
|
-
|
|
3599
|
-
|
|
3600
|
-
|
|
3601
|
-
|
|
3602
|
-
|
|
3603
|
-
|
|
3596
|
+
!isDynamic(path.get("expression"), {
|
|
3597
|
+
checkMember: true,
|
|
3598
|
+
native: !info.componentChild
|
|
3599
|
+
}))
|
|
3600
|
+
|
|
3601
|
+
return { exprs: [node.expression], template: "" };
|
|
3604
3602
|
const expr = t__namespace.arrowFunctionExpression([], node.expression);
|
|
3605
3603
|
return {
|
|
3606
3604
|
exprs: [expr],
|
|
@@ -3611,7 +3609,7 @@ function transformNode(path, info = {}) {
|
|
|
3611
3609
|
}
|
|
3612
3610
|
|
|
3613
3611
|
function getCreateTemplate(config, path, result) {
|
|
3614
|
-
if (
|
|
3612
|
+
if (result.tagName && result.renderer === "dom" || config.generate === "dom") {
|
|
3615
3613
|
return createTemplate$2;
|
|
3616
3614
|
}
|
|
3617
3615
|
|
|
@@ -3631,9 +3629,9 @@ function transformElement(config, path, info = {}) {
|
|
|
3631
3629
|
// <div ...></div>
|
|
3632
3630
|
// const element = getTransformElemet(config, path, tagName);
|
|
3633
3631
|
|
|
3634
|
-
const tagRenderer = (config.renderers ?? []).find(renderer =>
|
|
3635
|
-
|
|
3636
|
-
|
|
3632
|
+
const tagRenderer = (config.renderers ?? []).find((renderer) =>
|
|
3633
|
+
renderer.elements.includes(tagName));
|
|
3634
|
+
|
|
3637
3635
|
|
|
3638
3636
|
if (tagRenderer?.name === "dom" || getConfig(path).generate === "dom") {
|
|
3639
3637
|
return transformElement$3(path, info);
|
|
@@ -3647,24 +3645,24 @@ function transformElement(config, path, info = {}) {
|
|
|
3647
3645
|
}
|
|
3648
3646
|
|
|
3649
3647
|
// add to the top/bottom of the module.
|
|
3650
|
-
var postprocess = path => {
|
|
3648
|
+
var postprocess = ((path) => {
|
|
3651
3649
|
if (path.scope.data.events) {
|
|
3652
3650
|
path.node.body.push(
|
|
3653
|
-
|
|
3654
|
-
|
|
3655
|
-
|
|
3656
|
-
|
|
3657
|
-
|
|
3658
|
-
|
|
3659
|
-
|
|
3651
|
+
t__namespace.expressionStatement(
|
|
3652
|
+
t__namespace.callExpression(
|
|
3653
|
+
registerImportMethod(path, "delegateEvents", getRendererConfig(path, "dom").moduleName),
|
|
3654
|
+
[t__namespace.arrayExpression(Array.from(path.scope.data.events).map((e) => t__namespace.stringLiteral(e)))])));
|
|
3655
|
+
|
|
3656
|
+
|
|
3657
|
+
|
|
3660
3658
|
}
|
|
3661
3659
|
if (path.scope.data.templates?.length) {
|
|
3662
|
-
let domTemplates = path.scope.data.templates.filter(temp => temp.renderer === "dom");
|
|
3663
|
-
let ssrTemplates = path.scope.data.templates.filter(temp => temp.renderer === "ssr");
|
|
3660
|
+
let domTemplates = path.scope.data.templates.filter((temp) => temp.renderer === "dom");
|
|
3661
|
+
let ssrTemplates = path.scope.data.templates.filter((temp) => temp.renderer === "ssr");
|
|
3664
3662
|
domTemplates.length > 0 && appendTemplates$1(path, domTemplates);
|
|
3665
3663
|
ssrTemplates.length > 0 && appendTemplates(path, ssrTemplates);
|
|
3666
3664
|
}
|
|
3667
|
-
};
|
|
3665
|
+
});
|
|
3668
3666
|
|
|
3669
3667
|
var config = {
|
|
3670
3668
|
moduleName: "dom",
|
|
@@ -3699,15 +3697,15 @@ const JSXValidator = {
|
|
|
3699
3697
|
if (!isComponent(parentElTagName)) {
|
|
3700
3698
|
if (!isValidHTMLNesting(parentElTagName, elTagName)) {
|
|
3701
3699
|
throw path.buildCodeFrameError(
|
|
3702
|
-
|
|
3703
|
-
|
|
3700
|
+
`Invalid JSX: <${elTagName}> cannot be child of <${parentElTagName}>`);
|
|
3701
|
+
|
|
3704
3702
|
}
|
|
3705
3703
|
}
|
|
3706
3704
|
}
|
|
3707
3705
|
};
|
|
3708
3706
|
|
|
3709
|
-
var preprocess = (path, { opts }) => {
|
|
3710
|
-
const merged =
|
|
3707
|
+
var preprocess = ((path, { opts }) => {
|
|
3708
|
+
const merged = path.hub.file.metadata.config = Object.assign({}, config, opts);
|
|
3711
3709
|
const lib = merged.requireImportSource;
|
|
3712
3710
|
if (lib) {
|
|
3713
3711
|
const comments = path.hub.file.ast.comments;
|
|
@@ -3726,9 +3724,13 @@ var preprocess = (path, { opts }) => {
|
|
|
3726
3724
|
}
|
|
3727
3725
|
}
|
|
3728
3726
|
if (merged.validate) path.traverse(JSXValidator);
|
|
3729
|
-
};
|
|
3727
|
+
});
|
|
3728
|
+
|
|
3729
|
+
var index = (() =>
|
|
3730
|
+
|
|
3730
3731
|
|
|
3731
|
-
|
|
3732
|
+
|
|
3733
|
+
{
|
|
3732
3734
|
return {
|
|
3733
3735
|
name: "JSX DOM Expressions",
|
|
3734
3736
|
inherits: SyntaxJSX.default,
|
|
@@ -3741,6 +3743,6 @@ var index = () => {
|
|
|
3741
3743
|
}
|
|
3742
3744
|
}
|
|
3743
3745
|
};
|
|
3744
|
-
};
|
|
3746
|
+
});
|
|
3745
3747
|
|
|
3746
3748
|
module.exports = index;
|