babel-plugin-jsx-dom-expressions 0.38.0 → 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 +1893 -1889
- 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
|
}
|
|
@@ -1521,14 +1518,15 @@ function transformChildren$2(path, results, config) {
|
|
|
1521
1518
|
let tempPath = results.id && results.id.name,
|
|
1522
1519
|
tagName = getTagName(path.node),
|
|
1523
1520
|
nextPlaceholder,
|
|
1521
|
+
childPostExprs = [],
|
|
1524
1522
|
i = 0;
|
|
1525
1523
|
const filteredChildren = filterChildren(path.get("children")),
|
|
1526
1524
|
lastElement = findLastElement(filteredChildren, config.hydratable),
|
|
1527
1525
|
childNodes = filteredChildren.reduce((memo, child, index) => {
|
|
1528
1526
|
if (child.isJSXFragment()) {
|
|
1529
1527
|
throw new Error(
|
|
1530
|
-
|
|
1531
|
-
|
|
1528
|
+
`Fragments can only be used top level in JSX. Not used under a <${tagName}>.`);
|
|
1529
|
+
|
|
1532
1530
|
}
|
|
1533
1531
|
const transformed = transformNode(child, {
|
|
1534
1532
|
toBeClosed: results.toBeClosed,
|
|
@@ -1555,20 +1553,20 @@ function transformChildren$2(path, results, config) {
|
|
|
1555
1553
|
if (child.tagName === "head") {
|
|
1556
1554
|
if (config.hydratable) {
|
|
1557
1555
|
const createComponent = registerImportMethod(
|
|
1558
|
-
|
|
1559
|
-
|
|
1560
|
-
|
|
1561
|
-
|
|
1556
|
+
path,
|
|
1557
|
+
"createComponent",
|
|
1558
|
+
getRendererConfig(path, "dom").moduleName);
|
|
1559
|
+
|
|
1562
1560
|
const NoHydration = registerImportMethod(
|
|
1563
|
-
|
|
1564
|
-
|
|
1565
|
-
|
|
1566
|
-
|
|
1567
|
-
results.exprs.push(
|
|
1568
|
-
|
|
1569
|
-
|
|
1570
|
-
|
|
1571
|
-
|
|
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
|
+
|
|
1572
1570
|
}
|
|
1573
1571
|
return;
|
|
1574
1572
|
}
|
|
@@ -1576,27 +1574,27 @@ function transformChildren$2(path, results, config) {
|
|
|
1576
1574
|
let getNextMatch;
|
|
1577
1575
|
if (config.hydratable && tagName === "html") {
|
|
1578
1576
|
getNextMatch = registerImportMethod(
|
|
1579
|
-
|
|
1580
|
-
|
|
1581
|
-
|
|
1582
|
-
|
|
1577
|
+
path,
|
|
1578
|
+
"getNextMatch",
|
|
1579
|
+
getRendererConfig(path, "dom").moduleName);
|
|
1580
|
+
|
|
1583
1581
|
}
|
|
1584
1582
|
const walk = t__namespace.memberExpression(
|
|
1585
|
-
|
|
1586
|
-
|
|
1587
|
-
|
|
1583
|
+
t__namespace.identifier(tempPath),
|
|
1584
|
+
t__namespace.identifier(i === 0 ? "firstChild" : "nextSibling"));
|
|
1585
|
+
|
|
1588
1586
|
results.declarations.push(
|
|
1589
|
-
|
|
1590
|
-
|
|
1591
|
-
|
|
1592
|
-
|
|
1593
|
-
|
|
1594
|
-
|
|
1595
|
-
|
|
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
|
+
|
|
1596
1594
|
results.declarations.push(...child.declarations);
|
|
1597
1595
|
results.exprs.push(...child.exprs);
|
|
1598
1596
|
results.dynamics.push(...child.dynamics);
|
|
1599
|
-
|
|
1597
|
+
childPostExprs.push(...child.postExprs);
|
|
1600
1598
|
results.hasHydratableEvent = results.hasHydratableEvent || child.hasHydratableEvent;
|
|
1601
1599
|
results.hasCustomElement = results.hasCustomElement || child.hasCustomElement;
|
|
1602
1600
|
tempPath = child.id.name;
|
|
@@ -1617,33 +1615,34 @@ function transformChildren$2(path, results, config) {
|
|
|
1617
1615
|
}
|
|
1618
1616
|
if (!markers) nextPlaceholder = exprId;
|
|
1619
1617
|
results.exprs.push(
|
|
1620
|
-
|
|
1621
|
-
|
|
1622
|
-
|
|
1623
|
-
|
|
1624
|
-
|
|
1625
|
-
|
|
1626
|
-
|
|
1627
|
-
|
|
1628
|
-
|
|
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
|
+
|
|
1629
1627
|
tempPath = exprId.name;
|
|
1630
1628
|
} else if (multi) {
|
|
1631
1629
|
results.exprs.push(
|
|
1632
|
-
|
|
1633
|
-
|
|
1634
|
-
|
|
1635
|
-
|
|
1636
|
-
|
|
1637
|
-
|
|
1638
|
-
|
|
1639
|
-
|
|
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
|
+
|
|
1640
1638
|
} else {
|
|
1641
1639
|
results.exprs.push(
|
|
1642
|
-
|
|
1643
|
-
|
|
1640
|
+
t__namespace.expressionStatement(t__namespace.callExpression(insert, [results.id, child.exprs[0]])));
|
|
1641
|
+
|
|
1644
1642
|
}
|
|
1645
1643
|
} else nextPlaceholder = null;
|
|
1646
1644
|
});
|
|
1645
|
+
results.postExprs.unshift(...childPostExprs);
|
|
1647
1646
|
}
|
|
1648
1647
|
|
|
1649
1648
|
function createPlaceholder(path, results, tempPath, i, char) {
|
|
@@ -1654,24 +1653,24 @@ function createPlaceholder(path, results, tempPath, i, char) {
|
|
|
1654
1653
|
if (config.hydratable && char === "/") {
|
|
1655
1654
|
contentId = path.scope.generateUidIdentifier("co$");
|
|
1656
1655
|
results.declarations.push(
|
|
1657
|
-
|
|
1658
|
-
|
|
1659
|
-
|
|
1660
|
-
|
|
1661
|
-
|
|
1662
|
-
|
|
1663
|
-
|
|
1664
|
-
|
|
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
|
+
|
|
1665
1664
|
} else
|
|
1666
|
-
|
|
1667
|
-
|
|
1668
|
-
|
|
1669
|
-
|
|
1670
|
-
|
|
1671
|
-
|
|
1672
|
-
|
|
1673
|
-
|
|
1674
|
-
|
|
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
|
+
|
|
1675
1674
|
return [exprId, contentId];
|
|
1676
1675
|
}
|
|
1677
1676
|
|
|
@@ -1684,11 +1683,11 @@ function detectExpressions(children, index, config) {
|
|
|
1684
1683
|
if (children[index - 1]) {
|
|
1685
1684
|
const node = children[index - 1].node;
|
|
1686
1685
|
if (
|
|
1687
|
-
|
|
1688
|
-
|
|
1689
|
-
|
|
1690
|
-
|
|
1691
|
-
|
|
1686
|
+
t__namespace.isJSXExpressionContainer(node) &&
|
|
1687
|
+
!t__namespace.isJSXEmptyExpression(node.expression) &&
|
|
1688
|
+
getStaticExpression(children[index - 1]) === false)
|
|
1689
|
+
|
|
1690
|
+
return true;
|
|
1692
1691
|
let tagName;
|
|
1693
1692
|
if (t__namespace.isJSXElement(node) && (tagName = getTagName(node)) && isComponent(tagName)) return true;
|
|
1694
1693
|
}
|
|
@@ -1696,26 +1695,26 @@ function detectExpressions(children, index, config) {
|
|
|
1696
1695
|
const child = children[i].node;
|
|
1697
1696
|
if (t__namespace.isJSXExpressionContainer(child)) {
|
|
1698
1697
|
if (!t__namespace.isJSXEmptyExpression(child.expression) && getStaticExpression(children[i]) === false)
|
|
1699
|
-
|
|
1698
|
+
return true;
|
|
1700
1699
|
} else if (t__namespace.isJSXElement(child)) {
|
|
1701
1700
|
const tagName = getTagName(child);
|
|
1702
1701
|
if (isComponent(tagName)) return true;
|
|
1703
1702
|
if (config.contextToCustomElements && (tagName === "slot" || tagName.indexOf("-") > -1))
|
|
1704
|
-
|
|
1703
|
+
return true;
|
|
1705
1704
|
if (
|
|
1706
|
-
|
|
1707
|
-
|
|
1708
|
-
|
|
1709
|
-
|
|
1710
|
-
|
|
1711
|
-
|
|
1712
|
-
|
|
1713
|
-
|
|
1714
|
-
|
|
1715
|
-
|
|
1716
|
-
|
|
1717
|
-
|
|
1718
|
-
|
|
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;
|
|
1719
1718
|
const nextChildren = filterChildren(children[i].get("children"));
|
|
1720
1719
|
if (nextChildren.length) if (detectExpressions(nextChildren, 0, config)) return true;
|
|
1721
1720
|
}
|
|
@@ -1724,17 +1723,17 @@ function detectExpressions(children, index, config) {
|
|
|
1724
1723
|
|
|
1725
1724
|
function contextToCustomElement(path, results) {
|
|
1726
1725
|
results.exprs.push(
|
|
1727
|
-
|
|
1728
|
-
|
|
1729
|
-
|
|
1730
|
-
|
|
1731
|
-
|
|
1732
|
-
|
|
1733
|
-
|
|
1734
|
-
|
|
1735
|
-
|
|
1736
|
-
|
|
1737
|
-
|
|
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
|
+
|
|
1738
1737
|
}
|
|
1739
1738
|
|
|
1740
1739
|
function processSpreads$1(path, attributes, { elem, isSVG, hasChildren, wrapConditionals }) {
|
|
@@ -1744,13 +1743,13 @@ function processSpreads$1(path, attributes, { elem, isSVG, hasChildren, wrapCond
|
|
|
1744
1743
|
let runningObject = [];
|
|
1745
1744
|
let dynamicSpread = false;
|
|
1746
1745
|
let firstSpread = false;
|
|
1747
|
-
attributes.forEach(attribute => {
|
|
1746
|
+
attributes.forEach((attribute) => {
|
|
1748
1747
|
const node = attribute.node;
|
|
1749
1748
|
const key =
|
|
1750
|
-
|
|
1751
|
-
|
|
1752
|
-
|
|
1753
|
-
|
|
1749
|
+
!t__namespace.isJSXSpreadAttribute(node) && (
|
|
1750
|
+
t__namespace.isJSXNamespacedName(node.name) ?
|
|
1751
|
+
`${node.name.namespace.name}:${node.name.name.name}` :
|
|
1752
|
+
node.name.name);
|
|
1754
1753
|
if (t__namespace.isJSXSpreadAttribute(node)) {
|
|
1755
1754
|
firstSpread = true;
|
|
1756
1755
|
if (runningObject.length) {
|
|
@@ -1758,52 +1757,52 @@ function processSpreads$1(path, attributes, { elem, isSVG, hasChildren, wrapCond
|
|
|
1758
1757
|
runningObject = [];
|
|
1759
1758
|
}
|
|
1760
1759
|
spreadArgs.push(
|
|
1761
|
-
|
|
1762
|
-
|
|
1763
|
-
|
|
1764
|
-
|
|
1765
|
-
|
|
1766
|
-
|
|
1767
|
-
|
|
1768
|
-
|
|
1769
|
-
|
|
1770
|
-
|
|
1771
|
-
|
|
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
|
+
|
|
1772
1771
|
} else if (
|
|
1773
|
-
|
|
1774
|
-
|
|
1775
|
-
|
|
1776
|
-
|
|
1777
|
-
|
|
1772
|
+
(firstSpread ||
|
|
1773
|
+
t__namespace.isJSXExpressionContainer(node.value) &&
|
|
1774
|
+
isDynamic(attribute.get("value").get("expression"), { checkMember: true })) &&
|
|
1775
|
+
canNativeSpread(key, { checkNameSpaces: true }))
|
|
1776
|
+
{
|
|
1778
1777
|
const isContainer = t__namespace.isJSXExpressionContainer(node.value);
|
|
1779
1778
|
const dynamic =
|
|
1780
|
-
|
|
1779
|
+
isContainer && isDynamic(attribute.get("value").get("expression"), { checkMember: true });
|
|
1781
1780
|
if (dynamic) {
|
|
1782
1781
|
const id = convertJSXIdentifier(node.name);
|
|
1783
1782
|
let expr =
|
|
1784
|
-
|
|
1785
|
-
|
|
1786
|
-
|
|
1787
|
-
|
|
1788
|
-
|
|
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);
|
|
1789
1788
|
runningObject.push(
|
|
1790
|
-
|
|
1791
|
-
|
|
1792
|
-
|
|
1793
|
-
|
|
1794
|
-
|
|
1795
|
-
|
|
1796
|
-
|
|
1797
|
-
|
|
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
|
+
|
|
1798
1797
|
} else {
|
|
1799
1798
|
runningObject.push(
|
|
1800
|
-
|
|
1801
|
-
|
|
1802
|
-
|
|
1803
|
-
|
|
1804
|
-
|
|
1805
|
-
|
|
1806
|
-
|
|
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
|
+
|
|
1807
1806
|
}
|
|
1808
1807
|
} else filteredAttributes.push(attribute);
|
|
1809
1808
|
});
|
|
@@ -1813,19 +1812,19 @@ function processSpreads$1(path, attributes, { elem, isSVG, hasChildren, wrapCond
|
|
|
1813
1812
|
}
|
|
1814
1813
|
|
|
1815
1814
|
const props =
|
|
1816
|
-
|
|
1817
|
-
|
|
1818
|
-
|
|
1815
|
+
spreadArgs.length === 1 && !dynamicSpread ?
|
|
1816
|
+
spreadArgs[0] :
|
|
1817
|
+
t__namespace.callExpression(registerImportMethod(path, "mergeProps"), spreadArgs);
|
|
1819
1818
|
|
|
1820
1819
|
return [
|
|
1821
|
-
|
|
1822
|
-
|
|
1823
|
-
|
|
1824
|
-
|
|
1825
|
-
|
|
1826
|
-
|
|
1827
|
-
|
|
1828
|
-
|
|
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
|
+
|
|
1829
1828
|
}
|
|
1830
1829
|
|
|
1831
1830
|
function createTemplate$2(path, result, wrap) {
|
|
@@ -1833,25 +1832,25 @@ function createTemplate$2(path, result, wrap) {
|
|
|
1833
1832
|
if (result.id) {
|
|
1834
1833
|
registerTemplate(path, result);
|
|
1835
1834
|
if (
|
|
1836
|
-
|
|
1837
|
-
|
|
1838
|
-
|
|
1835
|
+
!(result.exprs.length || result.dynamics.length || result.postExprs.length) &&
|
|
1836
|
+
result.decl.declarations.length === 1)
|
|
1837
|
+
{
|
|
1839
1838
|
return result.decl.declarations[0].init;
|
|
1840
1839
|
} else {
|
|
1841
1840
|
return t__namespace.callExpression(
|
|
1842
|
-
|
|
1843
|
-
|
|
1844
|
-
|
|
1845
|
-
|
|
1846
|
-
|
|
1847
|
-
|
|
1848
|
-
|
|
1849
|
-
|
|
1850
|
-
|
|
1851
|
-
|
|
1852
|
-
|
|
1853
|
-
|
|
1854
|
-
|
|
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
|
+
|
|
1855
1854
|
}
|
|
1856
1855
|
}
|
|
1857
1856
|
if (wrap && result.dynamic && config.memoWrapper) {
|
|
@@ -1861,26 +1860,26 @@ function createTemplate$2(path, result, wrap) {
|
|
|
1861
1860
|
}
|
|
1862
1861
|
|
|
1863
1862
|
function appendTemplates$1(path, templates) {
|
|
1864
|
-
const declarators = templates.map(template => {
|
|
1863
|
+
const declarators = templates.map((template) => {
|
|
1865
1864
|
const tmpl = {
|
|
1866
1865
|
cooked: template.template,
|
|
1867
1866
|
raw: escapeStringForTemplate(template.template)
|
|
1868
1867
|
};
|
|
1869
1868
|
return t__namespace.variableDeclarator(
|
|
1870
|
-
|
|
1871
|
-
|
|
1872
|
-
|
|
1873
|
-
|
|
1874
|
-
|
|
1875
|
-
|
|
1876
|
-
|
|
1877
|
-
|
|
1878
|
-
|
|
1879
|
-
|
|
1880
|
-
|
|
1881
|
-
|
|
1882
|
-
|
|
1883
|
-
|
|
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
|
+
|
|
1884
1883
|
});
|
|
1885
1884
|
path.node.body.unshift(t__namespace.variableDeclaration("var", declarators));
|
|
1886
1885
|
}
|
|
@@ -1892,9 +1891,9 @@ function registerTemplate(path, results) {
|
|
|
1892
1891
|
let templateDef, templateId;
|
|
1893
1892
|
if (!results.skipTemplate) {
|
|
1894
1893
|
const templates =
|
|
1895
|
-
|
|
1896
|
-
|
|
1897
|
-
if (
|
|
1894
|
+
path.scope.getProgramParent().data.templates || (
|
|
1895
|
+
path.scope.getProgramParent().data.templates = []);
|
|
1896
|
+
if (templateDef = templates.find((t) => t.template === results.template)) {
|
|
1898
1897
|
templateId = templateDef.id;
|
|
1899
1898
|
} else {
|
|
1900
1899
|
templateId = path.scope.generateUidIdentifier("tmpl$");
|
|
@@ -1908,14 +1907,14 @@ function registerTemplate(path, results) {
|
|
|
1908
1907
|
}
|
|
1909
1908
|
}
|
|
1910
1909
|
decl = t__namespace.variableDeclarator(
|
|
1911
|
-
|
|
1912
|
-
|
|
1913
|
-
|
|
1914
|
-
|
|
1915
|
-
|
|
1916
|
-
|
|
1917
|
-
|
|
1918
|
-
|
|
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
|
+
|
|
1919
1918
|
}
|
|
1920
1919
|
results.declarations.unshift(decl);
|
|
1921
1920
|
results.decl = t__namespace.variableDeclaration("var", results.declarations);
|
|
@@ -1930,35 +1929,35 @@ function wrapDynamics$1(path, dynamics) {
|
|
|
1930
1929
|
if (dynamics.length === 1) {
|
|
1931
1930
|
let dynamicStyle;
|
|
1932
1931
|
const prevValue =
|
|
1933
|
-
|
|
1934
|
-
|
|
1935
|
-
|
|
1936
|
-
|
|
1937
|
-
|
|
1932
|
+
dynamics[0].key === "classList" ||
|
|
1933
|
+
dynamics[0].key === "style" || (
|
|
1934
|
+
dynamicStyle = dynamics[0].key.startsWith("style:")) ?
|
|
1935
|
+
t__namespace.identifier("_$p") :
|
|
1936
|
+
undefined;
|
|
1938
1937
|
if (dynamicStyle) {
|
|
1939
1938
|
dynamics[0].value = t__namespace.assignmentExpression("=", prevValue, dynamics[0].value);
|
|
1940
1939
|
} else if (
|
|
1941
|
-
|
|
1942
|
-
|
|
1943
|
-
|
|
1944
|
-
|
|
1940
|
+
dynamics[0].key.startsWith("class:") &&
|
|
1941
|
+
!t__namespace.isBooleanLiteral(dynamics[0].value) &&
|
|
1942
|
+
!t__namespace.isUnaryExpression(dynamics[0].value))
|
|
1943
|
+
{
|
|
1945
1944
|
dynamics[0].value = t__namespace.unaryExpression("!", t__namespace.unaryExpression("!", dynamics[0].value));
|
|
1946
1945
|
}
|
|
1947
1946
|
|
|
1948
1947
|
return t__namespace.expressionStatement(
|
|
1949
|
-
|
|
1950
|
-
|
|
1951
|
-
|
|
1952
|
-
|
|
1953
|
-
|
|
1954
|
-
|
|
1955
|
-
|
|
1956
|
-
|
|
1957
|
-
|
|
1958
|
-
|
|
1959
|
-
|
|
1960
|
-
|
|
1961
|
-
|
|
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
|
+
|
|
1962
1961
|
}
|
|
1963
1962
|
|
|
1964
1963
|
const prevId = t__namespace.identifier("_p$");
|
|
@@ -1977,10 +1976,10 @@ function wrapDynamics$1(path, dynamics) {
|
|
|
1977
1976
|
const propMember = t__namespace.memberExpression(prevId, propIdent);
|
|
1978
1977
|
|
|
1979
1978
|
if (
|
|
1980
|
-
|
|
1981
|
-
|
|
1982
|
-
|
|
1983
|
-
|
|
1979
|
+
key.startsWith("class:") &&
|
|
1980
|
+
!t__namespace.isBooleanLiteral(value) &&
|
|
1981
|
+
!t__namespace.isUnaryExpression(value))
|
|
1982
|
+
{
|
|
1984
1983
|
value = t__namespace.unaryExpression("!", t__namespace.unaryExpression("!", value));
|
|
1985
1984
|
}
|
|
1986
1985
|
|
|
@@ -1989,55 +1988,55 @@ function wrapDynamics$1(path, dynamics) {
|
|
|
1989
1988
|
|
|
1990
1989
|
if (key === "classList" || key === "style") {
|
|
1991
1990
|
statements.push(
|
|
1992
|
-
|
|
1993
|
-
|
|
1994
|
-
|
|
1995
|
-
|
|
1996
|
-
|
|
1997
|
-
|
|
1998
|
-
|
|
1999
|
-
|
|
2000
|
-
|
|
2001
|
-
|
|
2002
|
-
|
|
2003
|
-
|
|
2004
|
-
|
|
2005
|
-
|
|
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
|
+
|
|
2006
2005
|
} else {
|
|
2007
2006
|
const prev = key.startsWith("style:") ? varIdent : undefined;
|
|
2008
2007
|
statements.push(
|
|
2009
|
-
|
|
2010
|
-
|
|
2011
|
-
|
|
2012
|
-
|
|
2013
|
-
|
|
2014
|
-
|
|
2015
|
-
|
|
2016
|
-
|
|
2017
|
-
|
|
2018
|
-
|
|
2019
|
-
|
|
2020
|
-
|
|
2021
|
-
|
|
2022
|
-
|
|
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
|
+
|
|
2023
2022
|
}
|
|
2024
2023
|
});
|
|
2025
2024
|
|
|
2026
2025
|
return t__namespace.expressionStatement(
|
|
2027
|
-
|
|
2028
|
-
|
|
2029
|
-
|
|
2030
|
-
|
|
2031
|
-
|
|
2032
|
-
|
|
2033
|
-
|
|
2034
|
-
|
|
2035
|
-
|
|
2036
|
-
|
|
2037
|
-
|
|
2038
|
-
|
|
2039
|
-
|
|
2040
|
-
|
|
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
|
+
|
|
2041
2040
|
}
|
|
2042
2041
|
|
|
2043
2042
|
function createTemplate$1(path, result) {
|
|
@@ -2052,18 +2051,18 @@ function createTemplate$1(path, result) {
|
|
|
2052
2051
|
} else if (result.template.length === 1) {
|
|
2053
2052
|
template = t__namespace.stringLiteral(result.template[0]);
|
|
2054
2053
|
} else {
|
|
2055
|
-
const strings = result.template.map(tmpl => t__namespace.stringLiteral(tmpl));
|
|
2054
|
+
const strings = result.template.map((tmpl) => t__namespace.stringLiteral(tmpl));
|
|
2056
2055
|
template = t__namespace.arrayExpression(strings);
|
|
2057
2056
|
}
|
|
2058
2057
|
|
|
2059
2058
|
const templates =
|
|
2060
|
-
|
|
2061
|
-
|
|
2062
|
-
const found = templates.find(tmp => {
|
|
2059
|
+
path.scope.getProgramParent().data.templates || (
|
|
2060
|
+
path.scope.getProgramParent().data.templates = []);
|
|
2061
|
+
const found = templates.find((tmp) => {
|
|
2063
2062
|
if (t__namespace.isArrayExpression(tmp.template) && t__namespace.isArrayExpression(template)) {
|
|
2064
2063
|
return tmp.template.elements.every(
|
|
2065
|
-
|
|
2066
|
-
|
|
2064
|
+
(el, i) => template.elements[i] && el.value === template.elements[i].value);
|
|
2065
|
+
|
|
2067
2066
|
}
|
|
2068
2067
|
return tmp.template.value === template.value;
|
|
2069
2068
|
});
|
|
@@ -2077,35 +2076,35 @@ function createTemplate$1(path, result) {
|
|
|
2077
2076
|
} else id = found.id;
|
|
2078
2077
|
|
|
2079
2078
|
if (result.wontEscape) {
|
|
2080
|
-
if (!Array.isArray(result.template) || result.template.length === 1) return id;
|
|
2081
|
-
|
|
2082
|
-
|
|
2083
|
-
|
|
2084
|
-
|
|
2085
|
-
|
|
2086
|
-
|
|
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
|
+
{
|
|
2087
2086
|
// remove unnecessary ssr call when only hydration key is used
|
|
2088
2087
|
return t__namespace.binaryExpression(
|
|
2089
|
-
|
|
2090
|
-
|
|
2091
|
-
|
|
2092
|
-
|
|
2093
|
-
|
|
2094
|
-
|
|
2095
|
-
|
|
2096
|
-
|
|
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
|
+
|
|
2097
2096
|
}
|
|
2098
2097
|
}
|
|
2099
2098
|
return t__namespace.callExpression(
|
|
2100
|
-
|
|
2101
|
-
|
|
2102
|
-
|
|
2103
|
-
|
|
2104
|
-
|
|
2099
|
+
registerImportMethod(path, "ssr"),
|
|
2100
|
+
Array.isArray(result.template) && result.template.length > 1 ?
|
|
2101
|
+
[id, ...result.templateValues] :
|
|
2102
|
+
[id]);
|
|
2103
|
+
|
|
2105
2104
|
}
|
|
2106
2105
|
|
|
2107
2106
|
function appendTemplates(path, templates) {
|
|
2108
|
-
const declarators = templates.map(template => {
|
|
2107
|
+
const declarators = templates.map((template) => {
|
|
2109
2108
|
return t__namespace.variableDeclarator(template.id, template.template);
|
|
2110
2109
|
});
|
|
2111
2110
|
path.node.body.unshift(t__namespace.variableDeclaration("var", declarators));
|
|
@@ -2123,8 +2122,8 @@ function appendToTemplate(template, value) {
|
|
|
2123
2122
|
function transformElement$2(path, info) {
|
|
2124
2123
|
const config = getConfig(path);
|
|
2125
2124
|
// contains spread attributes
|
|
2126
|
-
if (path.node.openingElement.attributes.some(a => t__namespace.isJSXSpreadAttribute(a)))
|
|
2127
|
-
|
|
2125
|
+
if (path.node.openingElement.attributes.some((a) => t__namespace.isJSXSpreadAttribute(a)))
|
|
2126
|
+
return createElement(path, { ...info, ...config });
|
|
2128
2127
|
|
|
2129
2128
|
const tagName = getTagName(path.node),
|
|
2130
2129
|
voidTag = VoidElements.indexOf(tagName) > -1,
|
|
@@ -2147,24 +2146,24 @@ function transformElement$2(path, info) {
|
|
|
2147
2146
|
const child = transformElement$2(path, { ...info, topLevel: false });
|
|
2148
2147
|
results.template = "";
|
|
2149
2148
|
results.exprs.push(
|
|
2150
|
-
|
|
2151
|
-
|
|
2152
|
-
|
|
2153
|
-
|
|
2154
|
-
|
|
2155
|
-
|
|
2156
|
-
|
|
2157
|
-
|
|
2158
|
-
|
|
2159
|
-
|
|
2160
|
-
|
|
2161
|
-
|
|
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
|
+
|
|
2162
2161
|
return results;
|
|
2163
2162
|
}
|
|
2164
2163
|
results.template.push("");
|
|
2165
2164
|
results.templateValues.push(
|
|
2166
|
-
|
|
2167
|
-
|
|
2165
|
+
t__namespace.callExpression(registerImportMethod(path, "ssrHydrationKey"), []));
|
|
2166
|
+
|
|
2168
2167
|
}
|
|
2169
2168
|
transformAttributes$1(path, results, { ...config, ...info });
|
|
2170
2169
|
appendToTemplate(results.template, ">");
|
|
@@ -2191,10 +2190,10 @@ function setAttr$1(attribute, results, name, value, isSVG) {
|
|
|
2191
2190
|
|
|
2192
2191
|
name = toAttribute(name, isSVG);
|
|
2193
2192
|
const attr = t__namespace.callExpression(registerImportMethod(attribute, "ssrAttribute"), [
|
|
2194
|
-
|
|
2195
|
-
|
|
2196
|
-
|
|
2197
|
-
|
|
2193
|
+
t__namespace.stringLiteral(name),
|
|
2194
|
+
value,
|
|
2195
|
+
t__namespace.booleanLiteral(false)]);
|
|
2196
|
+
|
|
2198
2197
|
if (results.template[results.template.length - 1].length) {
|
|
2199
2198
|
results.template.push("");
|
|
2200
2199
|
results.templateValues.push(attr);
|
|
@@ -2206,29 +2205,29 @@ function setAttr$1(attribute, results, name, value, isSVG) {
|
|
|
2206
2205
|
|
|
2207
2206
|
function escapeExpression(path, expression, attr, escapeLiterals) {
|
|
2208
2207
|
if (
|
|
2209
|
-
|
|
2210
|
-
|
|
2211
|
-
|
|
2212
|
-
|
|
2208
|
+
t__namespace.isStringLiteral(expression) ||
|
|
2209
|
+
t__namespace.isNumericLiteral(expression) ||
|
|
2210
|
+
t__namespace.isTemplateLiteral(expression) && expression.expressions.length === 0)
|
|
2211
|
+
{
|
|
2213
2212
|
if (escapeLiterals) {
|
|
2214
|
-
if (t__namespace.isStringLiteral(expression)) return t__namespace.stringLiteral(escapeHTML(expression.value, attr));
|
|
2215
|
-
|
|
2216
|
-
|
|
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));
|
|
2217
2216
|
}
|
|
2218
2217
|
return expression;
|
|
2219
2218
|
} else if (t__namespace.isFunction(expression)) {
|
|
2220
2219
|
if (t__namespace.isBlockStatement(expression.body)) {
|
|
2221
|
-
expression.body.body = expression.body.body.map(e => {
|
|
2220
|
+
expression.body.body = expression.body.body.map((e) => {
|
|
2222
2221
|
if (t__namespace.isReturnStatement(e))
|
|
2223
|
-
|
|
2222
|
+
e.argument = escapeExpression(path, e.argument, attr, escapeLiterals);
|
|
2224
2223
|
return e;
|
|
2225
2224
|
});
|
|
2226
2225
|
} else expression.body = escapeExpression(path, expression.body, attr, escapeLiterals);
|
|
2227
2226
|
return expression;
|
|
2228
2227
|
} else if (t__namespace.isTemplateLiteral(expression)) {
|
|
2229
|
-
expression.expressions = expression.expressions.map(e =>
|
|
2230
|
-
|
|
2231
|
-
|
|
2228
|
+
expression.expressions = expression.expressions.map((e) =>
|
|
2229
|
+
escapeExpression(path, e, attr, escapeLiterals));
|
|
2230
|
+
|
|
2232
2231
|
return expression;
|
|
2233
2232
|
} else if (t__namespace.isUnaryExpression(expression)) {
|
|
2234
2233
|
return expression;
|
|
@@ -2248,13 +2247,13 @@ function escapeExpression(path, expression, attr, escapeLiterals) {
|
|
|
2248
2247
|
return expression;
|
|
2249
2248
|
} else if (t__namespace.isCallExpression(expression) && t__namespace.isFunction(expression.callee)) {
|
|
2250
2249
|
if (t__namespace.isBlockStatement(expression.callee.body)) {
|
|
2251
|
-
expression.callee.body.body = expression.callee.body.body.map(e => {
|
|
2250
|
+
expression.callee.body.body = expression.callee.body.body.map((e) => {
|
|
2252
2251
|
if (t__namespace.isReturnStatement(e))
|
|
2253
|
-
|
|
2252
|
+
e.argument = escapeExpression(path, e.argument, attr, escapeLiterals);
|
|
2254
2253
|
return e;
|
|
2255
2254
|
});
|
|
2256
2255
|
} else
|
|
2257
|
-
|
|
2256
|
+
expression.callee.body = escapeExpression(path, expression.callee.body, attr, escapeLiterals);
|
|
2258
2257
|
return expression;
|
|
2259
2258
|
} else if (t__namespace.isJSXElement(expression) && !isComponent(getTagName(expression))) {
|
|
2260
2259
|
expression.wontEscape = true;
|
|
@@ -2262,14 +2261,14 @@ function escapeExpression(path, expression, attr, escapeLiterals) {
|
|
|
2262
2261
|
}
|
|
2263
2262
|
|
|
2264
2263
|
return t__namespace.callExpression(
|
|
2265
|
-
|
|
2266
|
-
|
|
2267
|
-
|
|
2264
|
+
registerImportMethod(path, "escape"),
|
|
2265
|
+
[expression].concat(attr ? [t__namespace.booleanLiteral(true)] : []));
|
|
2266
|
+
|
|
2268
2267
|
}
|
|
2269
2268
|
|
|
2270
2269
|
function transformToObject(attrName, attributes, selectedAttributes) {
|
|
2271
2270
|
const properties = [];
|
|
2272
|
-
const existingAttribute = attributes.find(a => a.node.name.name === attrName);
|
|
2271
|
+
const existingAttribute = attributes.find((a) => a.node.name.name === attrName);
|
|
2273
2272
|
for (let i = 0; i < selectedAttributes.length; i++) {
|
|
2274
2273
|
const attr = selectedAttributes[i].node;
|
|
2275
2274
|
const computed = !t__namespace.isValidIdentifier(attr.name.name.name);
|
|
@@ -2277,44 +2276,44 @@ function transformToObject(attrName, attributes, selectedAttributes) {
|
|
|
2277
2276
|
attr.name.name.type = "Identifier";
|
|
2278
2277
|
}
|
|
2279
2278
|
properties.push(
|
|
2280
|
-
|
|
2281
|
-
|
|
2282
|
-
|
|
2283
|
-
|
|
2284
|
-
|
|
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
|
+
|
|
2285
2284
|
(existingAttribute || i) && attributes.splice(selectedAttributes[i].key, 1);
|
|
2286
2285
|
}
|
|
2287
2286
|
if (
|
|
2288
|
-
|
|
2289
|
-
|
|
2290
|
-
|
|
2291
|
-
|
|
2287
|
+
existingAttribute &&
|
|
2288
|
+
t__namespace.isJSXExpressionContainer(existingAttribute.node.value) &&
|
|
2289
|
+
t__namespace.isObjectExpression(existingAttribute.node.value.expression))
|
|
2290
|
+
{
|
|
2292
2291
|
existingAttribute.node.value.expression.properties.push(...properties);
|
|
2293
2292
|
} else {
|
|
2294
2293
|
selectedAttributes[0].node = t__namespace.jsxAttribute(
|
|
2295
|
-
|
|
2296
|
-
|
|
2297
|
-
|
|
2294
|
+
t__namespace.jsxIdentifier(attrName),
|
|
2295
|
+
t__namespace.jsxExpressionContainer(t__namespace.objectExpression(properties)));
|
|
2296
|
+
|
|
2298
2297
|
}
|
|
2299
2298
|
}
|
|
2300
2299
|
|
|
2301
2300
|
function normalizeAttributes(path) {
|
|
2302
2301
|
const attributes = path.get("openingElement").get("attributes"),
|
|
2303
2302
|
styleAttributes = attributes.filter(
|
|
2304
|
-
|
|
2305
|
-
|
|
2303
|
+
(a) => t__namespace.isJSXNamespacedName(a.node.name) && a.node.name.namespace.name === "style"),
|
|
2304
|
+
|
|
2306
2305
|
classNamespaceAttributes = attributes.filter(
|
|
2307
|
-
|
|
2308
|
-
|
|
2306
|
+
(a) => t__namespace.isJSXNamespacedName(a.node.name) && a.node.name.namespace.name === "class");
|
|
2307
|
+
|
|
2309
2308
|
if (classNamespaceAttributes.length)
|
|
2310
|
-
|
|
2309
|
+
transformToObject("classList", attributes, classNamespaceAttributes);
|
|
2311
2310
|
const classAttributes = attributes.filter(
|
|
2312
|
-
|
|
2313
|
-
|
|
2314
|
-
|
|
2315
|
-
|
|
2316
|
-
|
|
2317
|
-
|
|
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
|
+
|
|
2318
2317
|
// combine class propertoes
|
|
2319
2318
|
if (classAttributes.length > 1) {
|
|
2320
2319
|
const first = classAttributes[0].node,
|
|
@@ -2326,17 +2325,17 @@ function normalizeAttributes(path) {
|
|
|
2326
2325
|
if (!t__namespace.isJSXExpressionContainer(attr.value)) {
|
|
2327
2326
|
const prev = quasis.pop();
|
|
2328
2327
|
quasis.push(
|
|
2329
|
-
|
|
2330
|
-
|
|
2331
|
-
|
|
2332
|
-
|
|
2333
|
-
|
|
2334
|
-
|
|
2335
|
-
|
|
2328
|
+
t__namespace.templateElement({
|
|
2329
|
+
raw:
|
|
2330
|
+
(prev ? prev.value.raw : "") +
|
|
2331
|
+
`${attr.value.value}` + (
|
|
2332
|
+
isLast ? "" : " ")
|
|
2333
|
+
}));
|
|
2334
|
+
|
|
2336
2335
|
} else {
|
|
2337
2336
|
let expr = attr.value.expression;
|
|
2338
2337
|
if (attr.name.name === "classList") {
|
|
2339
|
-
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))) {
|
|
2340
2339
|
transformClasslistObject(path, expr, values, quasis);
|
|
2341
2340
|
if (!isLast) quasis[quasis.length - 1].value.raw += " ";
|
|
2342
2341
|
i && attributes.splice(attributes.indexOf(classAttributes[i]), 1);
|
|
@@ -2363,36 +2362,36 @@ function transformAttributes$1(path, results, info) {
|
|
|
2363
2362
|
attributes = normalizeAttributes(path);
|
|
2364
2363
|
let children;
|
|
2365
2364
|
|
|
2366
|
-
attributes.forEach(attribute => {
|
|
2365
|
+
attributes.forEach((attribute) => {
|
|
2367
2366
|
const node = attribute.node;
|
|
2368
2367
|
|
|
2369
2368
|
let value = node.value,
|
|
2370
|
-
key = t__namespace.isJSXNamespacedName(node.name)
|
|
2371
|
-
|
|
2372
|
-
|
|
2369
|
+
key = t__namespace.isJSXNamespacedName(node.name) ?
|
|
2370
|
+
`${node.name.namespace.name}:${node.name.name.name}` :
|
|
2371
|
+
node.name.name,
|
|
2373
2372
|
reservedNameSpace =
|
|
2374
|
-
|
|
2373
|
+
t__namespace.isJSXNamespacedName(node.name) && reservedNameSpaces.has(node.name.namespace.name);
|
|
2375
2374
|
if (
|
|
2376
|
-
|
|
2377
|
-
|
|
2378
|
-
|
|
2375
|
+
(t__namespace.isJSXNamespacedName(node.name) && reservedNameSpace || ChildProperties.has(key)) &&
|
|
2376
|
+
!t__namespace.isJSXExpressionContainer(value))
|
|
2377
|
+
{
|
|
2379
2378
|
node.value = value = t__namespace.jsxExpressionContainer(value || t__namespace.jsxEmptyExpression());
|
|
2380
2379
|
}
|
|
2381
2380
|
|
|
2382
2381
|
if (
|
|
2383
|
-
|
|
2384
|
-
|
|
2385
|
-
|
|
2386
|
-
|
|
2387
|
-
|
|
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
|
+
{
|
|
2388
2387
|
if (
|
|
2389
|
-
|
|
2390
|
-
|
|
2391
|
-
|
|
2392
|
-
|
|
2393
|
-
|
|
2394
|
-
|
|
2395
|
-
|
|
2388
|
+
key === "ref" ||
|
|
2389
|
+
key.startsWith("use:") ||
|
|
2390
|
+
key.startsWith("prop:") ||
|
|
2391
|
+
key.startsWith("on"))
|
|
2392
|
+
|
|
2393
|
+
return;else
|
|
2394
|
+
if (ChildProperties.has(key)) {
|
|
2396
2395
|
if (info.hydratable && key === "textContent" && value && value.expression) {
|
|
2397
2396
|
value.expression = t__namespace.logicalExpression("||", value.expression, t__namespace.stringLiteral(" "));
|
|
2398
2397
|
}
|
|
@@ -2400,31 +2399,32 @@ function transformAttributes$1(path, results, info) {
|
|
|
2400
2399
|
children = value;
|
|
2401
2400
|
} else {
|
|
2402
2401
|
let doEscape = true;
|
|
2402
|
+
if (key.startsWith("attr:")) key = key.replace("attr:", "");
|
|
2403
2403
|
if (BooleanAttributes.has(key)) {
|
|
2404
2404
|
results.template.push("");
|
|
2405
2405
|
const fn = t__namespace.callExpression(registerImportMethod(attribute, "ssrAttribute"), [
|
|
2406
|
-
|
|
2407
|
-
|
|
2408
|
-
|
|
2409
|
-
|
|
2406
|
+
t__namespace.stringLiteral(key),
|
|
2407
|
+
value.expression,
|
|
2408
|
+
t__namespace.booleanLiteral(true)]);
|
|
2409
|
+
|
|
2410
2410
|
results.templateValues.push(fn);
|
|
2411
2411
|
return;
|
|
2412
2412
|
}
|
|
2413
2413
|
if (key === "style") {
|
|
2414
2414
|
if (
|
|
2415
|
-
|
|
2416
|
-
|
|
2417
|
-
|
|
2418
|
-
|
|
2415
|
+
t__namespace.isJSXExpressionContainer(value) &&
|
|
2416
|
+
t__namespace.isObjectExpression(value.expression) &&
|
|
2417
|
+
!value.expression.properties.some((p) => t__namespace.isSpreadElement(p)))
|
|
2418
|
+
{
|
|
2419
2419
|
const props = value.expression.properties.map((p, i) =>
|
|
2420
|
-
|
|
2421
|
-
|
|
2422
|
-
|
|
2423
|
-
|
|
2424
|
-
|
|
2425
|
-
|
|
2426
|
-
|
|
2427
|
-
|
|
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
|
+
|
|
2428
2428
|
let res = props[0];
|
|
2429
2429
|
for (let i = 1; i < props.length; i++) {
|
|
2430
2430
|
res = t__namespace.binaryExpression("+", res, props[i]);
|
|
@@ -2432,27 +2432,27 @@ function transformAttributes$1(path, results, info) {
|
|
|
2432
2432
|
value.expression = res;
|
|
2433
2433
|
} else {
|
|
2434
2434
|
value.expression = t__namespace.callExpression(registerImportMethod(path, "ssrStyle"), [
|
|
2435
|
-
|
|
2436
|
-
|
|
2435
|
+
value.expression]);
|
|
2436
|
+
|
|
2437
2437
|
}
|
|
2438
2438
|
doEscape = false;
|
|
2439
2439
|
}
|
|
2440
2440
|
if (key === "classList") {
|
|
2441
2441
|
if (
|
|
2442
|
-
|
|
2443
|
-
|
|
2444
|
-
|
|
2442
|
+
t__namespace.isObjectExpression(value.expression) &&
|
|
2443
|
+
!value.expression.properties.some((p) => t__namespace.isSpreadElement(p)))
|
|
2444
|
+
{
|
|
2445
2445
|
const values = [],
|
|
2446
2446
|
quasis = [t__namespace.templateElement({ raw: "" })];
|
|
2447
2447
|
transformClasslistObject(path, value.expression, values, quasis);
|
|
2448
|
-
if (!values.length) value.expression = t__namespace.stringLiteral(quasis[0].value.raw);
|
|
2449
|
-
|
|
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) {
|
|
2450
2450
|
value.expression = values[0];
|
|
2451
2451
|
} else value.expression = t__namespace.templateLiteral(quasis, values);
|
|
2452
2452
|
} else {
|
|
2453
2453
|
value.expression = t__namespace.callExpression(registerImportMethod(path, "ssrClassList"), [
|
|
2454
|
-
|
|
2455
|
-
|
|
2454
|
+
value.expression]);
|
|
2455
|
+
|
|
2456
2456
|
}
|
|
2457
2457
|
key = "class";
|
|
2458
2458
|
doEscape = false;
|
|
@@ -2493,23 +2493,23 @@ function transformClasslistObject(path, expr, values, quasis) {
|
|
|
2493
2493
|
expr.properties.forEach((prop, i) => {
|
|
2494
2494
|
const isLast = expr.properties.length - 1 === i;
|
|
2495
2495
|
let key = prop.key;
|
|
2496
|
-
if (t__namespace.isIdentifier(prop.key) && !prop.computed) key = t__namespace.stringLiteral(key.name);
|
|
2497
|
-
|
|
2496
|
+
if (t__namespace.isIdentifier(prop.key) && !prop.computed) key = t__namespace.stringLiteral(key.name);else
|
|
2497
|
+
if (prop.computed) {
|
|
2498
2498
|
key = t__namespace.callExpression(registerImportMethod(path, "escape"), [
|
|
2499
|
-
|
|
2500
|
-
|
|
2501
|
-
|
|
2499
|
+
prop.key,
|
|
2500
|
+
t__namespace.booleanLiteral(true)]);
|
|
2501
|
+
|
|
2502
2502
|
} else key = t__namespace.stringLiteral(escapeHTML(prop.key.value));
|
|
2503
2503
|
if (t__namespace.isBooleanLiteral(prop.value)) {
|
|
2504
2504
|
if (prop.value.value === true) {
|
|
2505
2505
|
if (!prop.computed) {
|
|
2506
2506
|
const prev = quasis.pop();
|
|
2507
2507
|
quasis.push(
|
|
2508
|
-
|
|
2509
|
-
|
|
2510
|
-
|
|
2511
|
-
|
|
2512
|
-
|
|
2508
|
+
t__namespace.templateElement({
|
|
2509
|
+
raw:
|
|
2510
|
+
(prev ? prev.value.raw : "") + (i ? " " : "") + `${key.value}` + (isLast ? "" : " ")
|
|
2511
|
+
}));
|
|
2512
|
+
|
|
2513
2513
|
} else {
|
|
2514
2514
|
values.push(key);
|
|
2515
2515
|
quasis.push(t__namespace.templateElement({ raw: isLast ? "" : " " }));
|
|
@@ -2527,25 +2527,25 @@ function transformChildren$1(path, results, { hydratable }) {
|
|
|
2527
2527
|
const filteredChildren = filterChildren(path.get("children"));
|
|
2528
2528
|
const multi = checkLength(filteredChildren),
|
|
2529
2529
|
markers = hydratable && multi;
|
|
2530
|
-
filteredChildren.forEach(node => {
|
|
2530
|
+
filteredChildren.forEach((node) => {
|
|
2531
2531
|
if (t__namespace.isJSXElement(node.node) && getTagName(node.node) === "head") {
|
|
2532
2532
|
const child = transformNode(node, { doNotEscape, hydratable: false });
|
|
2533
2533
|
registerImportMethod(path, "NoHydration");
|
|
2534
2534
|
registerImportMethod(path, "createComponent");
|
|
2535
2535
|
results.template.push("");
|
|
2536
2536
|
results.templateValues.push(
|
|
2537
|
-
|
|
2538
|
-
|
|
2539
|
-
|
|
2540
|
-
|
|
2541
|
-
|
|
2542
|
-
|
|
2543
|
-
|
|
2544
|
-
|
|
2545
|
-
|
|
2546
|
-
|
|
2547
|
-
|
|
2548
|
-
|
|
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
|
+
|
|
2549
2549
|
return;
|
|
2550
2550
|
}
|
|
2551
2551
|
const child = transformNode(node, { doNotEscape });
|
|
@@ -2554,7 +2554,7 @@ function transformChildren$1(path, results, { hydratable }) {
|
|
|
2554
2554
|
results.templateValues.push.apply(results.templateValues, child.templateValues || []);
|
|
2555
2555
|
if (child.exprs.length) {
|
|
2556
2556
|
if (!doNotEscape && !child.spreadElement)
|
|
2557
|
-
|
|
2557
|
+
child.exprs[0] = escapeExpression(path, child.exprs[0]);
|
|
2558
2558
|
|
|
2559
2559
|
// boxed by textNodes
|
|
2560
2560
|
if (markers && !child.spreadElement) {
|
|
@@ -2585,12 +2585,12 @@ function createElement(path, { topLevel, hydratable }) {
|
|
|
2585
2585
|
} else {
|
|
2586
2586
|
const child = transformNode(path);
|
|
2587
2587
|
if (markers && child.exprs.length && !child.spreadElement)
|
|
2588
|
-
|
|
2588
|
+
memo.push(t__namespace.stringLiteral("<!--$-->"));
|
|
2589
2589
|
if (child.exprs.length && !child.spreadElement)
|
|
2590
|
-
|
|
2590
|
+
child.exprs[0] = escapeExpression(path, child.exprs[0]);
|
|
2591
2591
|
memo.push(getCreateTemplate(config, path, child)(path, child, true));
|
|
2592
2592
|
if (markers && child.exprs.length && !child.spreadElement)
|
|
2593
|
-
|
|
2593
|
+
memo.push(t__namespace.stringLiteral("<!--/-->"));
|
|
2594
2594
|
}
|
|
2595
2595
|
return memo;
|
|
2596
2596
|
}, []);
|
|
@@ -2604,7 +2604,7 @@ function createElement(path, { topLevel, hydratable }) {
|
|
|
2604
2604
|
dynamicSpread = false,
|
|
2605
2605
|
hasChildren = path.node.children.length > 0;
|
|
2606
2606
|
|
|
2607
|
-
attributes.forEach(attribute => {
|
|
2607
|
+
attributes.forEach((attribute) => {
|
|
2608
2608
|
const node = attribute.node;
|
|
2609
2609
|
if (t__namespace.isJSXSpreadAttribute(node)) {
|
|
2610
2610
|
if (runningObject.length) {
|
|
@@ -2612,51 +2612,51 @@ function createElement(path, { topLevel, hydratable }) {
|
|
|
2612
2612
|
runningObject = [];
|
|
2613
2613
|
}
|
|
2614
2614
|
props.push(
|
|
2615
|
-
|
|
2616
|
-
|
|
2617
|
-
|
|
2618
|
-
|
|
2619
|
-
|
|
2620
|
-
|
|
2621
|
-
|
|
2622
|
-
|
|
2623
|
-
|
|
2624
|
-
|
|
2625
|
-
|
|
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
|
+
|
|
2626
2626
|
} else {
|
|
2627
2627
|
const value = node.value || t__namespace.booleanLiteral(true),
|
|
2628
2628
|
id = convertJSXIdentifier(node.name),
|
|
2629
|
-
key = t__namespace.isJSXNamespacedName(node.name)
|
|
2630
|
-
|
|
2631
|
-
|
|
2629
|
+
key = t__namespace.isJSXNamespacedName(node.name) ?
|
|
2630
|
+
`${node.name.namespace.name}:${node.name.name.name}` :
|
|
2631
|
+
node.name.name;
|
|
2632
2632
|
|
|
2633
2633
|
if (hasChildren && key === "children") return;
|
|
2634
2634
|
if (
|
|
2635
|
-
|
|
2636
|
-
|
|
2637
|
-
|
|
2638
|
-
|
|
2639
|
-
|
|
2640
|
-
|
|
2641
|
-
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)) {
|
|
2642
2642
|
if (
|
|
2643
|
-
|
|
2644
|
-
|
|
2645
|
-
|
|
2646
|
-
|
|
2647
|
-
|
|
2643
|
+
isDynamic(attribute.get("value").get("expression"), {
|
|
2644
|
+
checkMember: true,
|
|
2645
|
+
checkTags: true
|
|
2646
|
+
}))
|
|
2647
|
+
{
|
|
2648
2648
|
let expr = t__namespace.arrowFunctionExpression([], value.expression);
|
|
2649
2649
|
runningObject.push(
|
|
2650
|
-
|
|
2651
|
-
|
|
2652
|
-
|
|
2653
|
-
|
|
2654
|
-
|
|
2655
|
-
|
|
2656
|
-
|
|
2657
|
-
|
|
2658
|
-
} else runningObject.push(t__namespace.objectProperty(id, value.expression));
|
|
2659
|
-
|
|
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));
|
|
2660
2660
|
}
|
|
2661
2661
|
});
|
|
2662
2662
|
|
|
@@ -2668,22 +2668,22 @@ function createElement(path, { topLevel, hydratable }) {
|
|
|
2668
2668
|
}
|
|
2669
2669
|
|
|
2670
2670
|
const exprs = [
|
|
2671
|
-
|
|
2672
|
-
|
|
2673
|
-
|
|
2674
|
-
|
|
2675
|
-
|
|
2676
|
-
|
|
2677
|
-
|
|
2678
|
-
|
|
2679
|
-
|
|
2680
|
-
|
|
2681
|
-
|
|
2682
|
-
|
|
2683
|
-
|
|
2684
|
-
|
|
2685
|
-
|
|
2686
|
-
|
|
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
|
+
|
|
2687
2687
|
return { exprs, template: "", spreadElement: true };
|
|
2688
2688
|
}
|
|
2689
2689
|
|
|
@@ -2700,18 +2700,18 @@ function transformElement$1(path, info) {
|
|
|
2700
2700
|
};
|
|
2701
2701
|
|
|
2702
2702
|
results.declarations.push(
|
|
2703
|
-
|
|
2704
|
-
|
|
2705
|
-
|
|
2706
|
-
|
|
2707
|
-
|
|
2708
|
-
|
|
2709
|
-
|
|
2710
|
-
|
|
2711
|
-
|
|
2712
|
-
|
|
2713
|
-
|
|
2714
|
-
|
|
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
|
+
|
|
2715
2715
|
|
|
2716
2716
|
transformAttributes(path, results);
|
|
2717
2717
|
transformChildren(path, results);
|
|
@@ -2727,147 +2727,147 @@ function transformAttributes(path, results) {
|
|
|
2727
2727
|
config = getConfig(path);
|
|
2728
2728
|
|
|
2729
2729
|
// preprocess spreads
|
|
2730
|
-
if (attributes.some(attribute => t__namespace.isJSXSpreadAttribute(attribute.node))) {
|
|
2730
|
+
if (attributes.some((attribute) => t__namespace.isJSXSpreadAttribute(attribute.node))) {
|
|
2731
2731
|
[attributes, spreadExpr] = processSpreads(path, attributes, {
|
|
2732
2732
|
elem,
|
|
2733
2733
|
hasChildren,
|
|
2734
2734
|
wrapConditionals: config.wrapConditionals
|
|
2735
2735
|
});
|
|
2736
2736
|
path.get("openingElement").set(
|
|
2737
|
-
|
|
2738
|
-
|
|
2739
|
-
|
|
2737
|
+
"attributes",
|
|
2738
|
+
attributes.map((a) => a.node));
|
|
2739
|
+
|
|
2740
2740
|
}
|
|
2741
2741
|
|
|
2742
|
-
path
|
|
2743
|
-
|
|
2744
|
-
|
|
2745
|
-
|
|
2746
|
-
|
|
2742
|
+
path.
|
|
2743
|
+
get("openingElement").
|
|
2744
|
+
get("attributes").
|
|
2745
|
+
forEach((attribute) => {
|
|
2746
|
+
const node = attribute.node;
|
|
2747
2747
|
|
|
2748
|
-
|
|
2749
|
-
|
|
2750
|
-
|
|
2751
|
-
|
|
2752
|
-
|
|
2753
|
-
|
|
2754
|
-
|
|
2755
|
-
|
|
2756
|
-
|
|
2757
|
-
|
|
2758
|
-
|
|
2759
|
-
|
|
2760
|
-
|
|
2761
|
-
|
|
2762
|
-
|
|
2763
|
-
|
|
2764
|
-
|
|
2765
|
-
|
|
2766
|
-
|
|
2767
|
-
|
|
2768
|
-
|
|
2769
|
-
|
|
2770
|
-
|
|
2771
|
-
results.exprs.unshift(
|
|
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
|
-
);
|
|
2807
|
-
} else {
|
|
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
|
-
);
|
|
2832
|
-
}
|
|
2833
|
-
} else if (key.startsWith("use:")) {
|
|
2834
|
-
// Some trick to treat JSXIdentifier as Identifier
|
|
2835
|
-
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$");
|
|
2836
2771
|
results.exprs.unshift(
|
|
2837
|
-
|
|
2838
|
-
|
|
2839
|
-
|
|
2840
|
-
|
|
2841
|
-
|
|
2842
|
-
|
|
2843
|
-
|
|
2844
|
-
|
|
2845
|
-
|
|
2846
|
-
|
|
2847
|
-
|
|
2848
|
-
|
|
2849
|
-
|
|
2850
|
-
|
|
2851
|
-
|
|
2852
|
-
|
|
2853
|
-
|
|
2854
|
-
|
|
2855
|
-
|
|
2856
|
-
|
|
2857
|
-
|
|
2858
|
-
|
|
2859
|
-
|
|
2860
|
-
|
|
2861
|
-
|
|
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
|
+
|
|
2862
2807
|
} else {
|
|
2863
|
-
|
|
2864
|
-
|
|
2865
|
-
|
|
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
|
+
|
|
2866
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 });
|
|
2867
2862
|
} else {
|
|
2868
|
-
results.exprs.push(
|
|
2863
|
+
results.exprs.push(
|
|
2864
|
+
t__namespace.expressionStatement(setAttr(attribute, elem, key, value.expression)));
|
|
2865
|
+
|
|
2869
2866
|
}
|
|
2870
|
-
}
|
|
2867
|
+
} else {
|
|
2868
|
+
results.exprs.push(t__namespace.expressionStatement(setAttr(attribute, elem, key, value)));
|
|
2869
|
+
}
|
|
2870
|
+
});
|
|
2871
2871
|
if (spreadExpr) results.exprs.push(spreadExpr);
|
|
2872
2872
|
if (!hasChildren && children) {
|
|
2873
2873
|
path.node.children.push(children);
|
|
@@ -2877,9 +2877,9 @@ function transformAttributes(path, results) {
|
|
|
2877
2877
|
function setAttr(path, elem, name, value, { prevId } = {}) {
|
|
2878
2878
|
if (!value) value = t__namespace.booleanLiteral(true);
|
|
2879
2879
|
return t__namespace.callExpression(
|
|
2880
|
-
|
|
2881
|
-
|
|
2882
|
-
|
|
2880
|
+
registerImportMethod(path, "setProp", getRendererConfig(path, "universal").moduleName),
|
|
2881
|
+
prevId ? [elem, t__namespace.stringLiteral(name), value, prevId] : [elem, t__namespace.stringLiteral(name), value]);
|
|
2882
|
+
|
|
2883
2883
|
}
|
|
2884
2884
|
|
|
2885
2885
|
function transformChildren(path, results) {
|
|
@@ -2903,30 +2903,30 @@ function transformChildren(path, results) {
|
|
|
2903
2903
|
}
|
|
2904
2904
|
if (child.id) {
|
|
2905
2905
|
let insertNode = registerImportMethod(
|
|
2906
|
-
|
|
2907
|
-
|
|
2908
|
-
|
|
2909
|
-
|
|
2906
|
+
path,
|
|
2907
|
+
"insertNode",
|
|
2908
|
+
getRendererConfig(path, "universal").moduleName);
|
|
2909
|
+
|
|
2910
2910
|
let insert = child.id;
|
|
2911
2911
|
if (child.text) {
|
|
2912
2912
|
let createTextNode = registerImportMethod(
|
|
2913
|
-
|
|
2914
|
-
|
|
2915
|
-
|
|
2916
|
-
|
|
2913
|
+
path,
|
|
2914
|
+
"createTextNode",
|
|
2915
|
+
getRendererConfig(path, "universal").moduleName);
|
|
2916
|
+
|
|
2917
2917
|
if (multi) {
|
|
2918
2918
|
results.declarations.push(
|
|
2919
|
-
|
|
2920
|
-
|
|
2921
|
-
|
|
2922
|
-
|
|
2923
|
-
|
|
2924
|
-
|
|
2925
|
-
|
|
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
|
+
|
|
2926
2926
|
} else
|
|
2927
|
-
|
|
2928
|
-
|
|
2929
|
-
|
|
2927
|
+
insert = t__namespace.callExpression(createTextNode, [
|
|
2928
|
+
t__namespace.templateLiteral([t__namespace.templateElement({ raw: escapeStringForTemplate(child.template) })], [])]);
|
|
2929
|
+
|
|
2930
2930
|
}
|
|
2931
2931
|
appends.push(t__namespace.expressionStatement(t__namespace.callExpression(insertNode, [results.id, insert])));
|
|
2932
2932
|
results.declarations.push(...child.declarations);
|
|
@@ -2934,24 +2934,24 @@ function transformChildren(path, results) {
|
|
|
2934
2934
|
results.dynamics.push(...child.dynamics);
|
|
2935
2935
|
} else if (child.exprs.length) {
|
|
2936
2936
|
let insert = registerImportMethod(
|
|
2937
|
-
|
|
2938
|
-
|
|
2939
|
-
|
|
2940
|
-
|
|
2937
|
+
path,
|
|
2938
|
+
"insert",
|
|
2939
|
+
getRendererConfig(path, "universal").moduleName);
|
|
2940
|
+
|
|
2941
2941
|
if (multi) {
|
|
2942
2942
|
results.exprs.push(
|
|
2943
|
-
|
|
2944
|
-
|
|
2945
|
-
|
|
2946
|
-
|
|
2947
|
-
|
|
2948
|
-
|
|
2949
|
-
|
|
2950
|
-
|
|
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
|
+
|
|
2951
2951
|
} else {
|
|
2952
2952
|
results.exprs.push(
|
|
2953
|
-
|
|
2954
|
-
|
|
2953
|
+
t__namespace.expressionStatement(t__namespace.callExpression(insert, [results.id, child.exprs[0]])));
|
|
2954
|
+
|
|
2955
2955
|
}
|
|
2956
2956
|
}
|
|
2957
2957
|
});
|
|
@@ -2969,13 +2969,13 @@ function processSpreads(path, attributes, { elem, hasChildren, wrapConditionals
|
|
|
2969
2969
|
let runningObject = [];
|
|
2970
2970
|
let dynamicSpread = false;
|
|
2971
2971
|
let firstSpread = false;
|
|
2972
|
-
attributes.forEach(attribute => {
|
|
2972
|
+
attributes.forEach((attribute) => {
|
|
2973
2973
|
const node = attribute.node;
|
|
2974
2974
|
const key =
|
|
2975
|
-
|
|
2976
|
-
|
|
2977
|
-
|
|
2978
|
-
|
|
2975
|
+
!t__namespace.isJSXSpreadAttribute(node) && (
|
|
2976
|
+
t__namespace.isJSXNamespacedName(node.name) ?
|
|
2977
|
+
`${node.name.namespace.name}:${node.name.name.name}` :
|
|
2978
|
+
node.name.name);
|
|
2979
2979
|
if (t__namespace.isJSXSpreadAttribute(node)) {
|
|
2980
2980
|
firstSpread = true;
|
|
2981
2981
|
if (runningObject.length) {
|
|
@@ -2983,50 +2983,50 @@ function processSpreads(path, attributes, { elem, hasChildren, wrapConditionals
|
|
|
2983
2983
|
runningObject = [];
|
|
2984
2984
|
}
|
|
2985
2985
|
spreadArgs.push(
|
|
2986
|
-
|
|
2987
|
-
|
|
2988
|
-
|
|
2989
|
-
|
|
2990
|
-
|
|
2991
|
-
|
|
2992
|
-
|
|
2993
|
-
|
|
2994
|
-
|
|
2995
|
-
|
|
2996
|
-
|
|
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
|
+
|
|
2997
2997
|
} else if (
|
|
2998
|
-
|
|
2999
|
-
|
|
3000
|
-
|
|
3001
|
-
|
|
3002
|
-
|
|
2998
|
+
(firstSpread ||
|
|
2999
|
+
t__namespace.isJSXExpressionContainer(node.value) &&
|
|
3000
|
+
isDynamic(attribute.get("value").get("expression"), { checkMember: true })) &&
|
|
3001
|
+
canNativeSpread(key, { checkNameSpaces: true }))
|
|
3002
|
+
{
|
|
3003
3003
|
const isContainer = t__namespace.isJSXExpressionContainer(node.value);
|
|
3004
3004
|
const dynamic =
|
|
3005
|
-
|
|
3005
|
+
isContainer && isDynamic(attribute.get("value").get("expression"), { checkMember: true });
|
|
3006
3006
|
if (dynamic) {
|
|
3007
3007
|
const id = convertJSXIdentifier(node.name);
|
|
3008
3008
|
let expr =
|
|
3009
|
-
|
|
3010
|
-
|
|
3011
|
-
|
|
3012
|
-
|
|
3013
|
-
|
|
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);
|
|
3014
3014
|
runningObject.push(
|
|
3015
|
-
|
|
3016
|
-
|
|
3017
|
-
|
|
3018
|
-
|
|
3019
|
-
|
|
3020
|
-
|
|
3021
|
-
|
|
3022
|
-
|
|
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
|
+
|
|
3023
3023
|
} else {
|
|
3024
3024
|
runningObject.push(
|
|
3025
|
-
|
|
3026
|
-
|
|
3027
|
-
|
|
3028
|
-
|
|
3029
|
-
|
|
3025
|
+
t__namespace.objectProperty(
|
|
3026
|
+
t__namespace.stringLiteral(key),
|
|
3027
|
+
isContainer ? node.value.expression : node.value || t__namespace.booleanLiteral(true)));
|
|
3028
|
+
|
|
3029
|
+
|
|
3030
3030
|
}
|
|
3031
3031
|
} else filteredAttributes.push(attribute);
|
|
3032
3032
|
});
|
|
@@ -3036,19 +3036,19 @@ function processSpreads(path, attributes, { elem, hasChildren, wrapConditionals
|
|
|
3036
3036
|
}
|
|
3037
3037
|
|
|
3038
3038
|
const props =
|
|
3039
|
-
|
|
3040
|
-
|
|
3041
|
-
|
|
3039
|
+
spreadArgs.length === 1 && !dynamicSpread ?
|
|
3040
|
+
spreadArgs[0] :
|
|
3041
|
+
t__namespace.callExpression(registerImportMethod(path, "mergeProps"), spreadArgs);
|
|
3042
3042
|
|
|
3043
3043
|
return [
|
|
3044
|
-
|
|
3045
|
-
|
|
3046
|
-
|
|
3047
|
-
|
|
3048
|
-
|
|
3049
|
-
|
|
3050
|
-
|
|
3051
|
-
|
|
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
|
+
|
|
3052
3052
|
}
|
|
3053
3053
|
|
|
3054
3054
|
function createTemplate(path, result, wrap) {
|
|
@@ -3056,25 +3056,25 @@ function createTemplate(path, result, wrap) {
|
|
|
3056
3056
|
if (result.id) {
|
|
3057
3057
|
result.decl = t__namespace.variableDeclaration("var", result.declarations);
|
|
3058
3058
|
if (
|
|
3059
|
-
|
|
3060
|
-
|
|
3061
|
-
|
|
3059
|
+
!(result.exprs.length || result.dynamics.length || result.postExprs.length) &&
|
|
3060
|
+
result.decl.declarations.length === 1)
|
|
3061
|
+
{
|
|
3062
3062
|
return result.decl.declarations[0].init;
|
|
3063
3063
|
} else {
|
|
3064
3064
|
return t__namespace.callExpression(
|
|
3065
|
-
|
|
3066
|
-
|
|
3067
|
-
|
|
3068
|
-
|
|
3069
|
-
|
|
3070
|
-
|
|
3071
|
-
|
|
3072
|
-
|
|
3073
|
-
|
|
3074
|
-
|
|
3075
|
-
|
|
3076
|
-
|
|
3077
|
-
|
|
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
|
+
|
|
3078
3078
|
}
|
|
3079
3079
|
}
|
|
3080
3080
|
if (wrap && result.dynamic && config.memoWrapper) {
|
|
@@ -3093,16 +3093,16 @@ function wrapDynamics(path, dynamics) {
|
|
|
3093
3093
|
const prevValue = t__namespace.identifier("_$p");
|
|
3094
3094
|
|
|
3095
3095
|
return t__namespace.expressionStatement(
|
|
3096
|
-
|
|
3097
|
-
|
|
3098
|
-
|
|
3099
|
-
|
|
3100
|
-
|
|
3101
|
-
|
|
3102
|
-
|
|
3103
|
-
|
|
3104
|
-
|
|
3105
|
-
|
|
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
|
+
|
|
3106
3106
|
}
|
|
3107
3107
|
|
|
3108
3108
|
const prevId = t__namespace.identifier("_p$");
|
|
@@ -3124,42 +3124,42 @@ function wrapDynamics(path, dynamics) {
|
|
|
3124
3124
|
declarations.push(t__namespace.variableDeclarator(varIdent, value));
|
|
3125
3125
|
|
|
3126
3126
|
statements.push(
|
|
3127
|
-
|
|
3128
|
-
|
|
3129
|
-
|
|
3130
|
-
|
|
3131
|
-
|
|
3132
|
-
|
|
3133
|
-
|
|
3134
|
-
|
|
3135
|
-
|
|
3136
|
-
|
|
3137
|
-
|
|
3138
|
-
|
|
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
|
+
|
|
3139
3139
|
});
|
|
3140
3140
|
|
|
3141
3141
|
return t__namespace.expressionStatement(
|
|
3142
|
-
|
|
3143
|
-
|
|
3144
|
-
|
|
3145
|
-
|
|
3146
|
-
|
|
3147
|
-
|
|
3148
|
-
|
|
3149
|
-
|
|
3150
|
-
|
|
3151
|
-
|
|
3152
|
-
|
|
3153
|
-
|
|
3154
|
-
|
|
3155
|
-
|
|
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
|
+
|
|
3156
3156
|
}
|
|
3157
3157
|
|
|
3158
3158
|
function convertComponentIdentifier(node) {
|
|
3159
3159
|
if (t__namespace.isJSXIdentifier(node)) {
|
|
3160
3160
|
if (node.name === 'this') return t__namespace.thisExpression();
|
|
3161
|
-
if (t__namespace.isValidIdentifier(node.name)) node.type = "Identifier";
|
|
3162
|
-
|
|
3161
|
+
if (t__namespace.isValidIdentifier(node.name)) node.type = "Identifier";else
|
|
3162
|
+
return t__namespace.stringLiteral(node.name);
|
|
3163
3163
|
} else if (t__namespace.isJSXMemberExpression(node)) {
|
|
3164
3164
|
const prop = convertComponentIdentifier(node.property);
|
|
3165
3165
|
const computed = t__namespace.isStringLiteral(prop);
|
|
@@ -3183,168 +3183,168 @@ function transformComponent(path) {
|
|
|
3183
3183
|
tagId.name = newTagId.name;
|
|
3184
3184
|
}
|
|
3185
3185
|
|
|
3186
|
-
path
|
|
3187
|
-
|
|
3188
|
-
|
|
3189
|
-
|
|
3190
|
-
|
|
3191
|
-
|
|
3192
|
-
|
|
3193
|
-
|
|
3194
|
-
|
|
3195
|
-
}
|
|
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));
|
|
3329
|
-
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 = [];
|
|
3330
3195
|
}
|
|
3331
|
-
|
|
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
|
+
});
|
|
3332
3332
|
|
|
3333
3333
|
const childResult = transformComponentChildren(path.get("children"), config);
|
|
3334
3334
|
if (childResult && childResult[0]) {
|
|
3335
3335
|
if (childResult[1]) {
|
|
3336
3336
|
const body =
|
|
3337
|
-
|
|
3338
|
-
|
|
3339
|
-
|
|
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];
|
|
3340
3340
|
runningObject.push(
|
|
3341
|
-
|
|
3342
|
-
|
|
3343
|
-
|
|
3344
|
-
|
|
3345
|
-
|
|
3346
|
-
|
|
3347
|
-
|
|
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
|
+
|
|
3348
3348
|
} else runningObject.push(t__namespace.objectProperty(t__namespace.identifier("children"), childResult[0]));
|
|
3349
3349
|
}
|
|
3350
3350
|
if (runningObject.length || !props.length) props.push(t__namespace.objectExpression(runningObject));
|
|
@@ -3359,11 +3359,11 @@ function transformComponent(path) {
|
|
|
3359
3359
|
if (exprs.length > 1) {
|
|
3360
3360
|
const ret = exprs.pop();
|
|
3361
3361
|
exprs = [
|
|
3362
|
-
|
|
3363
|
-
|
|
3364
|
-
|
|
3365
|
-
|
|
3366
|
-
|
|
3362
|
+
t__namespace.callExpression(
|
|
3363
|
+
t__namespace.arrowFunctionExpression([], t__namespace.blockStatement([...exprs, t__namespace.returnStatement(ret)])),
|
|
3364
|
+
[])];
|
|
3365
|
+
|
|
3366
|
+
|
|
3367
3367
|
}
|
|
3368
3368
|
return { exprs, template: "", component: true };
|
|
3369
3369
|
}
|
|
@@ -3389,11 +3389,11 @@ function transformComponentChildren(children, config) {
|
|
|
3389
3389
|
});
|
|
3390
3390
|
dynamic = dynamic || child.dynamic;
|
|
3391
3391
|
if (
|
|
3392
|
-
|
|
3393
|
-
|
|
3394
|
-
|
|
3395
|
-
|
|
3396
|
-
|
|
3392
|
+
config.generate === "ssr" &&
|
|
3393
|
+
filteredChildren.length > 1 &&
|
|
3394
|
+
child.dynamic &&
|
|
3395
|
+
t__namespace.isFunction(child.exprs[0]))
|
|
3396
|
+
{
|
|
3397
3397
|
child.exprs[0] = child.exprs[0].body;
|
|
3398
3398
|
}
|
|
3399
3399
|
pathNodes.push(path.node);
|
|
@@ -3405,16 +3405,16 @@ function transformComponentChildren(children, config) {
|
|
|
3405
3405
|
if (transformedChildren.length === 1) {
|
|
3406
3406
|
transformedChildren = transformedChildren[0];
|
|
3407
3407
|
if (
|
|
3408
|
-
|
|
3409
|
-
|
|
3410
|
-
|
|
3411
|
-
|
|
3408
|
+
!t__namespace.isJSXExpressionContainer(pathNodes[0]) &&
|
|
3409
|
+
!t__namespace.isJSXSpreadChild(pathNodes[0]) &&
|
|
3410
|
+
!t__namespace.isJSXText(pathNodes[0]))
|
|
3411
|
+
{
|
|
3412
3412
|
transformedChildren =
|
|
3413
|
-
|
|
3414
|
-
|
|
3415
|
-
|
|
3416
|
-
|
|
3417
|
-
|
|
3413
|
+
t__namespace.isCallExpression(transformedChildren) &&
|
|
3414
|
+
!transformedChildren.arguments.length &&
|
|
3415
|
+
!t__namespace.isIdentifier(transformedChildren.callee) ?
|
|
3416
|
+
transformedChildren.callee :
|
|
3417
|
+
t__namespace.arrowFunctionExpression([], transformedChildren);
|
|
3418
3418
|
dynamic = true;
|
|
3419
3419
|
}
|
|
3420
3420
|
} else {
|
|
@@ -3443,14 +3443,14 @@ function transformJSX(path) {
|
|
|
3443
3443
|
const config = getConfig(path);
|
|
3444
3444
|
const replace = transformThis(path);
|
|
3445
3445
|
const result = transformNode(
|
|
3446
|
-
|
|
3447
|
-
|
|
3448
|
-
|
|
3449
|
-
|
|
3450
|
-
|
|
3451
|
-
|
|
3452
|
-
|
|
3453
|
-
|
|
3446
|
+
path,
|
|
3447
|
+
t__namespace.isJSXFragment(path.node) ?
|
|
3448
|
+
{} :
|
|
3449
|
+
{
|
|
3450
|
+
topLevel: true,
|
|
3451
|
+
lastElement: true
|
|
3452
|
+
});
|
|
3453
|
+
|
|
3454
3454
|
|
|
3455
3455
|
const template = getCreateTemplate(config, path, result);
|
|
3456
3456
|
|
|
@@ -3494,20 +3494,20 @@ function transformThis(path) {
|
|
|
3494
3494
|
}
|
|
3495
3495
|
}
|
|
3496
3496
|
});
|
|
3497
|
-
return node => {
|
|
3497
|
+
return (node) => {
|
|
3498
3498
|
if (thisId) {
|
|
3499
3499
|
if (!parent || parent.block.type === "ClassMethod") {
|
|
3500
3500
|
const decl = t__namespace.variableDeclaration("const", [
|
|
3501
|
-
|
|
3502
|
-
|
|
3501
|
+
t__namespace.variableDeclarator(thisId, t__namespace.thisExpression())]);
|
|
3502
|
+
|
|
3503
3503
|
if (parent) {
|
|
3504
3504
|
const stmt = path.getStatementParent();
|
|
3505
3505
|
stmt.insertBefore(decl);
|
|
3506
3506
|
} else {
|
|
3507
3507
|
return t__namespace.callExpression(
|
|
3508
|
-
|
|
3509
|
-
|
|
3510
|
-
|
|
3508
|
+
t__namespace.arrowFunctionExpression([], t__namespace.blockStatement([decl, t__namespace.returnStatement(node)])),
|
|
3509
|
+
[]);
|
|
3510
|
+
|
|
3511
3511
|
}
|
|
3512
3512
|
} else {
|
|
3513
3513
|
parent.push({
|
|
@@ -3534,11 +3534,11 @@ function transformNode(path, info = {}) {
|
|
|
3534
3534
|
return results;
|
|
3535
3535
|
} else if (t__namespace.isJSXText(node) || (staticValue = getStaticExpression(path)) !== false) {
|
|
3536
3536
|
const text =
|
|
3537
|
-
|
|
3538
|
-
|
|
3539
|
-
|
|
3540
|
-
|
|
3541
|
-
|
|
3537
|
+
staticValue !== undefined ?
|
|
3538
|
+
info.doNotEscape ?
|
|
3539
|
+
staticValue.toString() :
|
|
3540
|
+
escapeHTML(staticValue.toString()) :
|
|
3541
|
+
trimWhitespace(node.extra.raw);
|
|
3542
3542
|
if (!text.length) return null;
|
|
3543
3543
|
const results = {
|
|
3544
3544
|
template: text,
|
|
@@ -3549,56 +3549,56 @@ function transformNode(path, info = {}) {
|
|
|
3549
3549
|
text: true
|
|
3550
3550
|
};
|
|
3551
3551
|
if (!info.skipId && config.generate !== "ssr")
|
|
3552
|
-
|
|
3552
|
+
results.id = path.scope.generateUidIdentifier("el$");
|
|
3553
3553
|
return results;
|
|
3554
3554
|
} else if (t__namespace.isJSXExpressionContainer(node)) {
|
|
3555
3555
|
if (t__namespace.isJSXEmptyExpression(node.expression)) return null;
|
|
3556
3556
|
if (
|
|
3557
|
-
|
|
3558
|
-
|
|
3559
|
-
|
|
3560
|
-
|
|
3561
|
-
|
|
3562
|
-
|
|
3557
|
+
!isDynamic(path.get("expression"), {
|
|
3558
|
+
checkMember: true,
|
|
3559
|
+
checkTags: !!info.componentChild,
|
|
3560
|
+
native: !info.componentChild
|
|
3561
|
+
}))
|
|
3562
|
+
{
|
|
3563
3563
|
return { exprs: [node.expression], template: "" };
|
|
3564
3564
|
}
|
|
3565
3565
|
const expr =
|
|
3566
|
-
|
|
3567
|
-
|
|
3568
|
-
|
|
3569
|
-
|
|
3570
|
-
|
|
3571
|
-
|
|
3572
|
-
|
|
3573
|
-
|
|
3574
|
-
|
|
3575
|
-
|
|
3576
|
-
|
|
3577
|
-
|
|
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);
|
|
3578
3578
|
return {
|
|
3579
3579
|
exprs:
|
|
3580
|
-
|
|
3581
|
-
|
|
3582
|
-
|
|
3583
|
-
|
|
3584
|
-
|
|
3585
|
-
|
|
3586
|
-
|
|
3587
|
-
|
|
3588
|
-
|
|
3589
|
-
|
|
3590
|
-
|
|
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],
|
|
3591
3591
|
template: "",
|
|
3592
3592
|
dynamic: true
|
|
3593
3593
|
};
|
|
3594
3594
|
} else if (t__namespace.isJSXSpreadChild(node)) {
|
|
3595
3595
|
if (
|
|
3596
|
-
|
|
3597
|
-
|
|
3598
|
-
|
|
3599
|
-
|
|
3600
|
-
|
|
3601
|
-
|
|
3596
|
+
!isDynamic(path.get("expression"), {
|
|
3597
|
+
checkMember: true,
|
|
3598
|
+
native: !info.componentChild
|
|
3599
|
+
}))
|
|
3600
|
+
|
|
3601
|
+
return { exprs: [node.expression], template: "" };
|
|
3602
3602
|
const expr = t__namespace.arrowFunctionExpression([], node.expression);
|
|
3603
3603
|
return {
|
|
3604
3604
|
exprs: [expr],
|
|
@@ -3609,7 +3609,7 @@ function transformNode(path, info = {}) {
|
|
|
3609
3609
|
}
|
|
3610
3610
|
|
|
3611
3611
|
function getCreateTemplate(config, path, result) {
|
|
3612
|
-
if (
|
|
3612
|
+
if (result.tagName && result.renderer === "dom" || config.generate === "dom") {
|
|
3613
3613
|
return createTemplate$2;
|
|
3614
3614
|
}
|
|
3615
3615
|
|
|
@@ -3629,9 +3629,9 @@ function transformElement(config, path, info = {}) {
|
|
|
3629
3629
|
// <div ...></div>
|
|
3630
3630
|
// const element = getTransformElemet(config, path, tagName);
|
|
3631
3631
|
|
|
3632
|
-
const tagRenderer = (config.renderers ?? []).find(renderer =>
|
|
3633
|
-
|
|
3634
|
-
|
|
3632
|
+
const tagRenderer = (config.renderers ?? []).find((renderer) =>
|
|
3633
|
+
renderer.elements.includes(tagName));
|
|
3634
|
+
|
|
3635
3635
|
|
|
3636
3636
|
if (tagRenderer?.name === "dom" || getConfig(path).generate === "dom") {
|
|
3637
3637
|
return transformElement$3(path, info);
|
|
@@ -3645,24 +3645,24 @@ function transformElement(config, path, info = {}) {
|
|
|
3645
3645
|
}
|
|
3646
3646
|
|
|
3647
3647
|
// add to the top/bottom of the module.
|
|
3648
|
-
var postprocess = path => {
|
|
3648
|
+
var postprocess = ((path) => {
|
|
3649
3649
|
if (path.scope.data.events) {
|
|
3650
3650
|
path.node.body.push(
|
|
3651
|
-
|
|
3652
|
-
|
|
3653
|
-
|
|
3654
|
-
|
|
3655
|
-
|
|
3656
|
-
|
|
3657
|
-
|
|
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
|
+
|
|
3658
3658
|
}
|
|
3659
3659
|
if (path.scope.data.templates?.length) {
|
|
3660
|
-
let domTemplates = path.scope.data.templates.filter(temp => temp.renderer === "dom");
|
|
3661
|
-
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");
|
|
3662
3662
|
domTemplates.length > 0 && appendTemplates$1(path, domTemplates);
|
|
3663
3663
|
ssrTemplates.length > 0 && appendTemplates(path, ssrTemplates);
|
|
3664
3664
|
}
|
|
3665
|
-
};
|
|
3665
|
+
});
|
|
3666
3666
|
|
|
3667
3667
|
var config = {
|
|
3668
3668
|
moduleName: "dom",
|
|
@@ -3697,15 +3697,15 @@ const JSXValidator = {
|
|
|
3697
3697
|
if (!isComponent(parentElTagName)) {
|
|
3698
3698
|
if (!isValidHTMLNesting(parentElTagName, elTagName)) {
|
|
3699
3699
|
throw path.buildCodeFrameError(
|
|
3700
|
-
|
|
3701
|
-
|
|
3700
|
+
`Invalid JSX: <${elTagName}> cannot be child of <${parentElTagName}>`);
|
|
3701
|
+
|
|
3702
3702
|
}
|
|
3703
3703
|
}
|
|
3704
3704
|
}
|
|
3705
3705
|
};
|
|
3706
3706
|
|
|
3707
|
-
var preprocess = (path, { opts }) => {
|
|
3708
|
-
const merged =
|
|
3707
|
+
var preprocess = ((path, { opts }) => {
|
|
3708
|
+
const merged = path.hub.file.metadata.config = Object.assign({}, config, opts);
|
|
3709
3709
|
const lib = merged.requireImportSource;
|
|
3710
3710
|
if (lib) {
|
|
3711
3711
|
const comments = path.hub.file.ast.comments;
|
|
@@ -3724,9 +3724,13 @@ var preprocess = (path, { opts }) => {
|
|
|
3724
3724
|
}
|
|
3725
3725
|
}
|
|
3726
3726
|
if (merged.validate) path.traverse(JSXValidator);
|
|
3727
|
-
};
|
|
3727
|
+
});
|
|
3728
|
+
|
|
3729
|
+
var index = (() =>
|
|
3730
|
+
|
|
3728
3731
|
|
|
3729
|
-
|
|
3732
|
+
|
|
3733
|
+
{
|
|
3730
3734
|
return {
|
|
3731
3735
|
name: "JSX DOM Expressions",
|
|
3732
3736
|
inherits: SyntaxJSX.default,
|
|
@@ -3739,6 +3743,6 @@ var index = () => {
|
|
|
3739
3743
|
}
|
|
3740
3744
|
}
|
|
3741
3745
|
};
|
|
3742
|
-
};
|
|
3746
|
+
});
|
|
3743
3747
|
|
|
3744
3748
|
module.exports = index;
|