babel-plugin-transform-solid-jsx 4.0.0-beta.84
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +174 -0
- package/README.md +51 -0
- package/dist/index.js +3457 -0
- package/index.js +35 -0
- package/package.json +38 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,3457 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var SyntaxJSX = require('@babel/plugin-syntax-jsx');
|
|
4
|
+
var t = require('@babel/types');
|
|
5
|
+
var helperModuleImports = require('@babel/helper-module-imports');
|
|
6
|
+
var htmlEntities = require('html-entities');
|
|
7
|
+
|
|
8
|
+
function _interopNamespaceDefault(e) {
|
|
9
|
+
var n = Object.create(null);
|
|
10
|
+
if (e) {
|
|
11
|
+
Object.keys(e).forEach(function (k) {
|
|
12
|
+
if (k !== 'default') {
|
|
13
|
+
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
14
|
+
Object.defineProperty(n, k, d.get ? d : {
|
|
15
|
+
enumerable: true,
|
|
16
|
+
get: function () { return e[k]; }
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
n.default = e;
|
|
22
|
+
return Object.freeze(n);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
var t__namespace = /*#__PURE__*/_interopNamespaceDefault(t);
|
|
26
|
+
|
|
27
|
+
const reservedNameSpaces = new Set(['class', 'on', 'oncapture', 'style', 'use', 'prop', 'attr']);
|
|
28
|
+
|
|
29
|
+
const nonSpreadNameSpaces = new Set(['class', 'style', 'use', 'prop', 'attr']);
|
|
30
|
+
|
|
31
|
+
function getConfig(path) {
|
|
32
|
+
return path.hub.file.metadata.config
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function getTaroComponentsMap(path) {
|
|
36
|
+
return path.hub.file.metadata.taroComponentsMap || new Map()
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const getRendererConfig = (path, renderer) => {
|
|
40
|
+
const config = getConfig(path);
|
|
41
|
+
return config?.renderers?.find((r) => r.name === renderer) ?? config
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
function registerImportMethod(path, name, moduleName) {
|
|
45
|
+
const imports = path.scope.getProgramParent().data.imports || (path.scope.getProgramParent().data.imports = new Map());
|
|
46
|
+
moduleName = moduleName || getConfig(path).moduleName;
|
|
47
|
+
if (!imports.has(`${moduleName}:${name}`)) {
|
|
48
|
+
const id = helperModuleImports.addNamed(path, name, moduleName, {
|
|
49
|
+
nameHint: `_$${name}`,
|
|
50
|
+
});
|
|
51
|
+
imports.set(`${moduleName}:${name}`, id);
|
|
52
|
+
return id
|
|
53
|
+
} else {
|
|
54
|
+
const iden = imports.get(`${moduleName}:${name}`);
|
|
55
|
+
// the cloning is required to play well with babel-preset-env which is
|
|
56
|
+
// transpiling import as we add them and using the same identifier causes
|
|
57
|
+
// problems with the multiple identifiers of the same thing
|
|
58
|
+
return t__namespace.cloneNode(iden)
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
function jsxElementNameToString(node) {
|
|
63
|
+
if (t__namespace.isJSXMemberExpression(node)) {
|
|
64
|
+
return `${jsxElementNameToString(node.object)}.${node.property.name}`
|
|
65
|
+
}
|
|
66
|
+
if (t__namespace.isJSXIdentifier(node) || t__namespace.isIdentifier(node)) {
|
|
67
|
+
return node.name
|
|
68
|
+
}
|
|
69
|
+
return `${node.namespace.name}:${node.name.name}`
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
function getTagName(tag) {
|
|
73
|
+
const jsxName = tag.openingElement.name;
|
|
74
|
+
return jsxElementNameToString(jsxName)
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
function isComponent(tagName) {
|
|
78
|
+
return (
|
|
79
|
+
(tagName[0] && tagName[0].toLowerCase() !== tagName[0]) || tagName.includes('.') || /[^a-zA-Z]/.test(tagName[0])
|
|
80
|
+
)
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
function isDynamic(path, { checkMember, checkTags, checkCallExpressions = true, native }) {
|
|
84
|
+
const config = getConfig(path);
|
|
85
|
+
if (config.generate === 'ssr' && native) {
|
|
86
|
+
checkMember = false;
|
|
87
|
+
checkCallExpressions = false;
|
|
88
|
+
}
|
|
89
|
+
const expr = path.node;
|
|
90
|
+
if (t__namespace.isFunction(expr)) return false
|
|
91
|
+
if (expr.leadingComments && expr.leadingComments[0] && expr.leadingComments[0].value.trim() === config.staticMarker) {
|
|
92
|
+
expr.leadingComments.shift();
|
|
93
|
+
return false
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
if (checkCallExpressions && (t__namespace.isCallExpression(expr) || t__namespace.isOptionalCallExpression(expr))) {
|
|
97
|
+
return true
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
if (checkMember && t__namespace.isMemberExpression(expr)) {
|
|
101
|
+
// Do not assume property access on namespaced imports as dynamic.
|
|
102
|
+
const object = path.get('object').node;
|
|
103
|
+
|
|
104
|
+
if (
|
|
105
|
+
t__namespace.isIdentifier(object) &&
|
|
106
|
+
(!expr.computed ||
|
|
107
|
+
!isDynamic(path.get('property'), {
|
|
108
|
+
checkMember,
|
|
109
|
+
checkTags,
|
|
110
|
+
checkCallExpressions,
|
|
111
|
+
native,
|
|
112
|
+
}))
|
|
113
|
+
) {
|
|
114
|
+
const binding = path.scope.getBinding(object.name);
|
|
115
|
+
|
|
116
|
+
if (binding && binding.path.isImportNamespaceSpecifier()) {
|
|
117
|
+
return false
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
return true
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
if (
|
|
125
|
+
checkMember &&
|
|
126
|
+
(t__namespace.isOptionalMemberExpression(expr) ||
|
|
127
|
+
t__namespace.isSpreadElement(expr) ||
|
|
128
|
+
(t__namespace.isBinaryExpression(expr) && expr.operator === 'in'))
|
|
129
|
+
) {
|
|
130
|
+
return true
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
if (checkTags && (t__namespace.isJSXElement(expr) || (t__namespace.isJSXFragment(expr) && expr.children.length))) {
|
|
134
|
+
return true
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
let dynamic;
|
|
138
|
+
path.traverse({
|
|
139
|
+
Function(p) {
|
|
140
|
+
if (t__namespace.isObjectMethod(p.node) && p.node.computed) {
|
|
141
|
+
dynamic = isDynamic(p.get('key'), { checkMember, checkTags, checkCallExpressions, native });
|
|
142
|
+
}
|
|
143
|
+
p.skip();
|
|
144
|
+
},
|
|
145
|
+
CallExpression(p) {
|
|
146
|
+
checkCallExpressions && (dynamic = true) && p.stop();
|
|
147
|
+
},
|
|
148
|
+
OptionalCallExpression(p) {
|
|
149
|
+
checkCallExpressions && (dynamic = true) && p.stop();
|
|
150
|
+
},
|
|
151
|
+
MemberExpression(p) {
|
|
152
|
+
checkMember && (dynamic = true) && p.stop();
|
|
153
|
+
},
|
|
154
|
+
OptionalMemberExpression(p) {
|
|
155
|
+
checkMember && (dynamic = true) && p.stop();
|
|
156
|
+
},
|
|
157
|
+
SpreadElement(p) {
|
|
158
|
+
checkMember && (dynamic = true) && p.stop();
|
|
159
|
+
},
|
|
160
|
+
BinaryExpression(p) {
|
|
161
|
+
checkMember && p.node.operator === 'in' && (dynamic = true) && p.stop();
|
|
162
|
+
},
|
|
163
|
+
JSXElement(p) {
|
|
164
|
+
checkTags ? (dynamic = true) && p.stop() : p.skip();
|
|
165
|
+
},
|
|
166
|
+
JSXFragment(p) {
|
|
167
|
+
checkTags && p.node.children.length ? (dynamic = true) && p.stop() : p.skip();
|
|
168
|
+
},
|
|
169
|
+
});
|
|
170
|
+
return dynamic
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
function getStaticExpression(path) {
|
|
174
|
+
const node = path.node;
|
|
175
|
+
let value, type;
|
|
176
|
+
return (
|
|
177
|
+
t__namespace.isJSXExpressionContainer(node) &&
|
|
178
|
+
t__namespace.isJSXElement(path.parent) &&
|
|
179
|
+
!isComponent(getTagName(path.parent)) &&
|
|
180
|
+
!t__namespace.isSequenceExpression(node.expression) &&
|
|
181
|
+
(value = path.get('expression').evaluate().value) !== undefined &&
|
|
182
|
+
((type = typeof value) === 'string' || type === 'number') &&
|
|
183
|
+
value
|
|
184
|
+
)
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
// remove unnecessary JSX Text nodes
|
|
188
|
+
function filterChildren(children) {
|
|
189
|
+
return children.filter(
|
|
190
|
+
({ node: child }) =>
|
|
191
|
+
!(t__namespace.isJSXExpressionContainer(child) && t__namespace.isJSXEmptyExpression(child.expression)) &&
|
|
192
|
+
(!t__namespace.isJSXText(child) || !/^[\r\n]\s*$/.test(child.extra.raw))
|
|
193
|
+
)
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
function checkLength(children) {
|
|
197
|
+
let i = 0;
|
|
198
|
+
children.forEach((path) => {
|
|
199
|
+
const child = path.node;
|
|
200
|
+
!(t__namespace.isJSXExpressionContainer(child) && t__namespace.isJSXEmptyExpression(child.expression)) &&
|
|
201
|
+
(!t__namespace.isJSXText(child) || !/^\s*$/.test(child.extra.raw) || /^ *$/.test(child.extra.raw)) &&
|
|
202
|
+
i++;
|
|
203
|
+
});
|
|
204
|
+
return i > 1
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
function trimWhitespace(text) {
|
|
208
|
+
text = text.replace(/\r/g, '');
|
|
209
|
+
if (/\n/g.test(text)) {
|
|
210
|
+
text = text
|
|
211
|
+
.split('\n')
|
|
212
|
+
.map((t, i) => (i ? t.replace(/^\s*/g, '') : t))
|
|
213
|
+
.filter((s) => !/^\s*$/.test(s))
|
|
214
|
+
.join(' ');
|
|
215
|
+
}
|
|
216
|
+
return text.replace(/\s+/g, ' ')
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
function toEventName(name) {
|
|
220
|
+
return name.slice(2).toLowerCase()
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
function toPropertyName(name) {
|
|
224
|
+
return name.toLowerCase().replace(/-([a-z])/g, (_, w) => w.toUpperCase())
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
function wrappedByText(list, startIndex) {
|
|
228
|
+
let index = startIndex;
|
|
229
|
+
let wrapped;
|
|
230
|
+
while (--index >= 0) {
|
|
231
|
+
const node = list[index];
|
|
232
|
+
if (!node) continue
|
|
233
|
+
if (node.text) {
|
|
234
|
+
wrapped = true;
|
|
235
|
+
break
|
|
236
|
+
}
|
|
237
|
+
if (node.id) return false
|
|
238
|
+
}
|
|
239
|
+
if (!wrapped) return false
|
|
240
|
+
index = startIndex;
|
|
241
|
+
while (++index < list.length) {
|
|
242
|
+
const node = list[index];
|
|
243
|
+
if (!node) continue
|
|
244
|
+
if (node.text) return true
|
|
245
|
+
if (node.id) return false
|
|
246
|
+
}
|
|
247
|
+
return false
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
function transformCondition(path, inline, deep) {
|
|
251
|
+
const config = getConfig(path);
|
|
252
|
+
const expr = path.node;
|
|
253
|
+
const memo = registerImportMethod(path, config.memoWrapper);
|
|
254
|
+
let dTest, cond, id;
|
|
255
|
+
if (
|
|
256
|
+
t__namespace.isConditionalExpression(expr) &&
|
|
257
|
+
(isDynamic(path.get('consequent'), {
|
|
258
|
+
checkTags: true,
|
|
259
|
+
}) ||
|
|
260
|
+
isDynamic(path.get('alternate'), { checkTags: true }))
|
|
261
|
+
) {
|
|
262
|
+
dTest = isDynamic(path.get('test'), { checkMember: true });
|
|
263
|
+
if (dTest) {
|
|
264
|
+
cond = expr.test;
|
|
265
|
+
if (!t__namespace.isBinaryExpression(cond)) cond = t__namespace.unaryExpression('!', t__namespace.unaryExpression('!', cond, true), true);
|
|
266
|
+
id = inline
|
|
267
|
+
? t__namespace.callExpression(memo, [t__namespace.arrowFunctionExpression([], cond)])
|
|
268
|
+
: path.scope.generateUidIdentifier('_c$');
|
|
269
|
+
expr.test = t__namespace.callExpression(id, []);
|
|
270
|
+
if (t__namespace.isConditionalExpression(expr.consequent) || t__namespace.isLogicalExpression(expr.consequent)) {
|
|
271
|
+
expr.consequent = transformCondition(path.get('consequent'), inline, true);
|
|
272
|
+
}
|
|
273
|
+
if (t__namespace.isConditionalExpression(expr.alternate) || t__namespace.isLogicalExpression(expr.alternate)) {
|
|
274
|
+
expr.alternate = transformCondition(path.get('alternate'), inline, true);
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
} else if (t__namespace.isLogicalExpression(expr)) {
|
|
278
|
+
let nextPath = path;
|
|
279
|
+
// handle top-level or, ie cond && <A/> || <B/>
|
|
280
|
+
while (nextPath.node.operator !== '&&' && t__namespace.isLogicalExpression(nextPath.node.left)) {
|
|
281
|
+
nextPath = nextPath.get('left');
|
|
282
|
+
}
|
|
283
|
+
nextPath.node.operator === '&&' &&
|
|
284
|
+
isDynamic(nextPath.get('right'), { checkTags: true }) &&
|
|
285
|
+
(dTest = isDynamic(nextPath.get('left'), {
|
|
286
|
+
checkMember: true,
|
|
287
|
+
}));
|
|
288
|
+
if (dTest) {
|
|
289
|
+
cond = nextPath.node.left;
|
|
290
|
+
if (!t__namespace.isBinaryExpression(cond)) cond = t__namespace.unaryExpression('!', t__namespace.unaryExpression('!', cond, true), true);
|
|
291
|
+
id = inline
|
|
292
|
+
? t__namespace.callExpression(memo, [t__namespace.arrowFunctionExpression([], cond)])
|
|
293
|
+
: path.scope.generateUidIdentifier('_c$');
|
|
294
|
+
nextPath.node.left = t__namespace.callExpression(id, []);
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
if (dTest && !inline) {
|
|
298
|
+
const statements = [
|
|
299
|
+
t__namespace.variableDeclaration('var', [
|
|
300
|
+
t__namespace.variableDeclarator(
|
|
301
|
+
id,
|
|
302
|
+
config.memoWrapper
|
|
303
|
+
? t__namespace.callExpression(memo, [t__namespace.arrowFunctionExpression([], cond)])
|
|
304
|
+
: t__namespace.arrowFunctionExpression([], cond)
|
|
305
|
+
),
|
|
306
|
+
]),
|
|
307
|
+
t__namespace.arrowFunctionExpression([], expr),
|
|
308
|
+
];
|
|
309
|
+
return deep
|
|
310
|
+
? t__namespace.callExpression(
|
|
311
|
+
t__namespace.arrowFunctionExpression([], t__namespace.blockStatement([statements[0], t__namespace.returnStatement(statements[1])])),
|
|
312
|
+
[]
|
|
313
|
+
)
|
|
314
|
+
: statements
|
|
315
|
+
}
|
|
316
|
+
return deep ? expr : t__namespace.arrowFunctionExpression([], expr)
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
function escapeHTML(s, attr) {
|
|
320
|
+
if (typeof s !== 'string') return s
|
|
321
|
+
const delim = attr ? '"' : '<';
|
|
322
|
+
const escDelim = attr ? '"' : '<';
|
|
323
|
+
let iDelim = s.indexOf(delim);
|
|
324
|
+
let iAmp = s.indexOf('&');
|
|
325
|
+
|
|
326
|
+
if (iDelim < 0 && iAmp < 0) return s
|
|
327
|
+
|
|
328
|
+
let left = 0;
|
|
329
|
+
let out = '';
|
|
330
|
+
|
|
331
|
+
while (iDelim >= 0 && iAmp >= 0) {
|
|
332
|
+
if (iDelim < iAmp) {
|
|
333
|
+
if (left < iDelim) out += s.substring(left, iDelim);
|
|
334
|
+
out += escDelim;
|
|
335
|
+
left = iDelim + 1;
|
|
336
|
+
iDelim = s.indexOf(delim, left);
|
|
337
|
+
} else {
|
|
338
|
+
if (left < iAmp) out += s.substring(left, iAmp);
|
|
339
|
+
out += '&';
|
|
340
|
+
left = iAmp + 1;
|
|
341
|
+
iAmp = s.indexOf('&', left);
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
if (iDelim >= 0) {
|
|
346
|
+
do {
|
|
347
|
+
if (left < iDelim) out += s.substring(left, iDelim);
|
|
348
|
+
out += escDelim;
|
|
349
|
+
left = iDelim + 1;
|
|
350
|
+
iDelim = s.indexOf(delim, left);
|
|
351
|
+
} while (iDelim >= 0)
|
|
352
|
+
} else {
|
|
353
|
+
while (iAmp >= 0) {
|
|
354
|
+
if (left < iAmp) out += s.substring(left, iAmp);
|
|
355
|
+
out += '&';
|
|
356
|
+
left = iAmp + 1;
|
|
357
|
+
iAmp = s.indexOf('&', left);
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
return left < s.length ? out + s.substring(left) : out
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
function convertJSXIdentifier(node) {
|
|
365
|
+
if (t__namespace.isJSXIdentifier(node)) {
|
|
366
|
+
if (t__namespace.isValidIdentifier(node.name)) {
|
|
367
|
+
node.type = 'Identifier';
|
|
368
|
+
} else {
|
|
369
|
+
return t__namespace.stringLiteral(node.name)
|
|
370
|
+
}
|
|
371
|
+
} else if (t__namespace.isJSXMemberExpression(node)) {
|
|
372
|
+
return t__namespace.memberExpression(convertJSXIdentifier(node.object), convertJSXIdentifier(node.property))
|
|
373
|
+
} else if (t__namespace.isJSXNamespacedName(node)) {
|
|
374
|
+
return t__namespace.stringLiteral(`${node.namespace.name}:${node.name.name}`)
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
return node
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
function canNativeSpread(key, { checkNameSpaces } = {}) {
|
|
381
|
+
if (checkNameSpaces && key.includes(':') && nonSpreadNameSpaces.has(key.split(':')[0])) return false
|
|
382
|
+
// TODO: figure out how to detect definitely function ref
|
|
383
|
+
if (key === 'ref') return false
|
|
384
|
+
return true
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
const chars = 'etaoinshrdlucwmfygpbTAOISWCBvkxjqzPHFMDRELNGUKVYJQZX_$';
|
|
388
|
+
const base = chars.length;
|
|
389
|
+
|
|
390
|
+
function getNumberedId(num) {
|
|
391
|
+
let out = '';
|
|
392
|
+
|
|
393
|
+
do {
|
|
394
|
+
const digit = num % base;
|
|
395
|
+
|
|
396
|
+
num = Math.floor(num / base);
|
|
397
|
+
out = chars[digit] + out;
|
|
398
|
+
} while (num !== 0)
|
|
399
|
+
|
|
400
|
+
return out
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
const templateEscapes = new Map([
|
|
404
|
+
['{', '\\{'],
|
|
405
|
+
['`', '\\`'],
|
|
406
|
+
['\\', '\\\\'],
|
|
407
|
+
['\n', '\\n'],
|
|
408
|
+
['\t', '\\t'],
|
|
409
|
+
['\b', '\\b'],
|
|
410
|
+
['\f', '\\f'],
|
|
411
|
+
['\v', '\\v'],
|
|
412
|
+
['\r', '\\r'],
|
|
413
|
+
['\u2028', '\\u2028'],
|
|
414
|
+
['\u2029', '\\u2029'],
|
|
415
|
+
]);
|
|
416
|
+
|
|
417
|
+
function escapeStringForTemplate(str) {
|
|
418
|
+
return str.replace(/[{\\`\n\t\b\f\v\r\u2028\u2029]/g, (ch) => templateEscapes.get(ch))
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
function convertCamelToKebabCase(camelCaseStr) {
|
|
422
|
+
return camelCaseStr.replace(/([a-z])([A-Z])/g, '$1-$2').toLowerCase()
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
function isTaroComponent(packageName) {
|
|
426
|
+
return packageName === '@tarojs/components'
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
const booleans = [
|
|
430
|
+
'allowfullscreen',
|
|
431
|
+
'async',
|
|
432
|
+
'autofocus',
|
|
433
|
+
'autoplay',
|
|
434
|
+
'checked',
|
|
435
|
+
'controls',
|
|
436
|
+
'default',
|
|
437
|
+
'disabled',
|
|
438
|
+
'formnovalidate',
|
|
439
|
+
'hidden',
|
|
440
|
+
'indeterminate',
|
|
441
|
+
'inert',
|
|
442
|
+
'ismap',
|
|
443
|
+
'loop',
|
|
444
|
+
'multiple',
|
|
445
|
+
'muted',
|
|
446
|
+
'nomodule',
|
|
447
|
+
'novalidate',
|
|
448
|
+
'open',
|
|
449
|
+
'playsinline',
|
|
450
|
+
'readonly',
|
|
451
|
+
'required',
|
|
452
|
+
'reversed',
|
|
453
|
+
'seamless',
|
|
454
|
+
'selected',
|
|
455
|
+
];
|
|
456
|
+
|
|
457
|
+
const BooleanAttributes = /* #__PURE__ */ new Set(booleans);
|
|
458
|
+
|
|
459
|
+
const Properties = /* #__PURE__ */ new Set([
|
|
460
|
+
'className',
|
|
461
|
+
'value',
|
|
462
|
+
'readOnly',
|
|
463
|
+
'formNoValidate',
|
|
464
|
+
'isMap',
|
|
465
|
+
'noModule',
|
|
466
|
+
'playsInline',
|
|
467
|
+
...booleans,
|
|
468
|
+
]);
|
|
469
|
+
|
|
470
|
+
const ChildProperties = /* #__PURE__ */ new Set(['innerHTML', 'textContent', 'innerText', 'children']);
|
|
471
|
+
|
|
472
|
+
// React Compat
|
|
473
|
+
const Aliases = /* #__PURE__ */ Object.assign(Object.create(null), {
|
|
474
|
+
className: 'class',
|
|
475
|
+
htmlFor: 'for',
|
|
476
|
+
});
|
|
477
|
+
|
|
478
|
+
const PropAliases = /* #__PURE__ */ Object.assign(Object.create(null), {
|
|
479
|
+
class: 'className',
|
|
480
|
+
formnovalidate: {
|
|
481
|
+
$: 'formNoValidate',
|
|
482
|
+
BUTTON: 1,
|
|
483
|
+
INPUT: 1,
|
|
484
|
+
},
|
|
485
|
+
ismap: {
|
|
486
|
+
$: 'isMap',
|
|
487
|
+
IMG: 1,
|
|
488
|
+
},
|
|
489
|
+
nomodule: {
|
|
490
|
+
$: 'noModule',
|
|
491
|
+
SCRIPT: 1,
|
|
492
|
+
},
|
|
493
|
+
playsinline: {
|
|
494
|
+
$: 'playsInline',
|
|
495
|
+
VIDEO: 1,
|
|
496
|
+
},
|
|
497
|
+
readonly: {
|
|
498
|
+
$: 'readOnly',
|
|
499
|
+
INPUT: 1,
|
|
500
|
+
TEXTAREA: 1,
|
|
501
|
+
},
|
|
502
|
+
});
|
|
503
|
+
|
|
504
|
+
function getPropAlias(prop, tagName) {
|
|
505
|
+
const a = PropAliases[prop];
|
|
506
|
+
return typeof a === 'object' ? (a[tagName] ? a.$ : undefined) : a
|
|
507
|
+
}
|
|
508
|
+
|
|
509
|
+
// list of Element events that will be delegated
|
|
510
|
+
const DelegatedEvents = /* #__PURE__ */ new Set([
|
|
511
|
+
'beforeinput',
|
|
512
|
+
'click',
|
|
513
|
+
'dblclick',
|
|
514
|
+
'contextmenu',
|
|
515
|
+
'focusin',
|
|
516
|
+
'focusout',
|
|
517
|
+
'input',
|
|
518
|
+
'keydown',
|
|
519
|
+
'keyup',
|
|
520
|
+
'mousedown',
|
|
521
|
+
'mousemove',
|
|
522
|
+
'mouseout',
|
|
523
|
+
'mouseover',
|
|
524
|
+
'mouseup',
|
|
525
|
+
'pointerdown',
|
|
526
|
+
'pointermove',
|
|
527
|
+
'pointerout',
|
|
528
|
+
'pointerover',
|
|
529
|
+
'pointerup',
|
|
530
|
+
'touchend',
|
|
531
|
+
'touchmove',
|
|
532
|
+
'touchstart',
|
|
533
|
+
]);
|
|
534
|
+
|
|
535
|
+
const SVGElements = /* #__PURE__ */ new Set([
|
|
536
|
+
// "a",
|
|
537
|
+
'altGlyph',
|
|
538
|
+
'altGlyphDef',
|
|
539
|
+
'altGlyphItem',
|
|
540
|
+
'animate',
|
|
541
|
+
'animateColor',
|
|
542
|
+
'animateMotion',
|
|
543
|
+
'animateTransform',
|
|
544
|
+
'circle',
|
|
545
|
+
'clipPath',
|
|
546
|
+
'color-profile',
|
|
547
|
+
'cursor',
|
|
548
|
+
'defs',
|
|
549
|
+
'desc',
|
|
550
|
+
'ellipse',
|
|
551
|
+
'feBlend',
|
|
552
|
+
'feColorMatrix',
|
|
553
|
+
'feComponentTransfer',
|
|
554
|
+
'feComposite',
|
|
555
|
+
'feConvolveMatrix',
|
|
556
|
+
'feDiffuseLighting',
|
|
557
|
+
'feDisplacementMap',
|
|
558
|
+
'feDistantLight',
|
|
559
|
+
'feDropShadow',
|
|
560
|
+
'feFlood',
|
|
561
|
+
'feFuncA',
|
|
562
|
+
'feFuncB',
|
|
563
|
+
'feFuncG',
|
|
564
|
+
'feFuncR',
|
|
565
|
+
'feGaussianBlur',
|
|
566
|
+
'feImage',
|
|
567
|
+
'feMerge',
|
|
568
|
+
'feMergeNode',
|
|
569
|
+
'feMorphology',
|
|
570
|
+
'feOffset',
|
|
571
|
+
'fePointLight',
|
|
572
|
+
'feSpecularLighting',
|
|
573
|
+
'feSpotLight',
|
|
574
|
+
'feTile',
|
|
575
|
+
'feTurbulence',
|
|
576
|
+
'filter',
|
|
577
|
+
'font',
|
|
578
|
+
'font-face',
|
|
579
|
+
'font-face-format',
|
|
580
|
+
'font-face-name',
|
|
581
|
+
'font-face-src',
|
|
582
|
+
'font-face-uri',
|
|
583
|
+
'foreignObject',
|
|
584
|
+
'g',
|
|
585
|
+
'glyph',
|
|
586
|
+
'glyphRef',
|
|
587
|
+
'hkern',
|
|
588
|
+
'image',
|
|
589
|
+
'line',
|
|
590
|
+
'linearGradient',
|
|
591
|
+
'marker',
|
|
592
|
+
'mask',
|
|
593
|
+
'metadata',
|
|
594
|
+
'missing-glyph',
|
|
595
|
+
'mpath',
|
|
596
|
+
'path',
|
|
597
|
+
'pattern',
|
|
598
|
+
'polygon',
|
|
599
|
+
'polyline',
|
|
600
|
+
'radialGradient',
|
|
601
|
+
'rect',
|
|
602
|
+
// "script",
|
|
603
|
+
'set',
|
|
604
|
+
'stop',
|
|
605
|
+
// "style",
|
|
606
|
+
'svg',
|
|
607
|
+
'switch',
|
|
608
|
+
'symbol',
|
|
609
|
+
'text',
|
|
610
|
+
'textPath',
|
|
611
|
+
// "title",
|
|
612
|
+
'tref',
|
|
613
|
+
'tspan',
|
|
614
|
+
'use',
|
|
615
|
+
'view',
|
|
616
|
+
'vkern',
|
|
617
|
+
]);
|
|
618
|
+
|
|
619
|
+
const SVGNamespace = {
|
|
620
|
+
xlink: 'http://www.w3.org/1999/xlink',
|
|
621
|
+
xml: 'http://www.w3.org/XML/1998/namespace',
|
|
622
|
+
};
|
|
623
|
+
|
|
624
|
+
var VoidElements = [
|
|
625
|
+
'area',
|
|
626
|
+
'base',
|
|
627
|
+
'br',
|
|
628
|
+
'col',
|
|
629
|
+
'embed',
|
|
630
|
+
'hr',
|
|
631
|
+
'img',
|
|
632
|
+
'input',
|
|
633
|
+
'keygen',
|
|
634
|
+
'link',
|
|
635
|
+
'menuitem',
|
|
636
|
+
'meta',
|
|
637
|
+
'param',
|
|
638
|
+
'source',
|
|
639
|
+
'track',
|
|
640
|
+
'wbr'
|
|
641
|
+
];
|
|
642
|
+
|
|
643
|
+
function createTemplate$2(path, result) {
|
|
644
|
+
if (!result.template) {
|
|
645
|
+
return result.exprs[0]
|
|
646
|
+
}
|
|
647
|
+
|
|
648
|
+
let template, id;
|
|
649
|
+
|
|
650
|
+
if (!Array.isArray(result.template)) {
|
|
651
|
+
template = t__namespace.stringLiteral(result.template);
|
|
652
|
+
} else if (result.template.length === 1) {
|
|
653
|
+
template = t__namespace.stringLiteral(result.template[0]);
|
|
654
|
+
} else {
|
|
655
|
+
const strings = result.template.map(tmpl => t__namespace.stringLiteral(tmpl));
|
|
656
|
+
template = t__namespace.arrayExpression(strings);
|
|
657
|
+
}
|
|
658
|
+
|
|
659
|
+
const templates =
|
|
660
|
+
path.scope.getProgramParent().data.templates ||
|
|
661
|
+
(path.scope.getProgramParent().data.templates = []);
|
|
662
|
+
const found = templates.find(tmp => {
|
|
663
|
+
if (t__namespace.isArrayExpression(tmp.template) && t__namespace.isArrayExpression(template)) {
|
|
664
|
+
return tmp.template.elements.every(
|
|
665
|
+
(el, i) => template.elements[i] && el.value === template.elements[i].value
|
|
666
|
+
)
|
|
667
|
+
}
|
|
668
|
+
return tmp.template.value === template.value
|
|
669
|
+
});
|
|
670
|
+
if (!found) {
|
|
671
|
+
id = path.scope.generateUidIdentifier('tmpl$');
|
|
672
|
+
templates.push({
|
|
673
|
+
id,
|
|
674
|
+
template,
|
|
675
|
+
renderer: 'ssr'
|
|
676
|
+
});
|
|
677
|
+
} else id = found.id;
|
|
678
|
+
|
|
679
|
+
if (result.wontEscape) {
|
|
680
|
+
if (!Array.isArray(result.template) || result.template.length === 1) return id
|
|
681
|
+
else if (
|
|
682
|
+
Array.isArray(result.template) &&
|
|
683
|
+
result.template.length === 2 &&
|
|
684
|
+
result.templateValues[0].type === 'CallExpression' &&
|
|
685
|
+
result.templateValues[0].callee.name === '_$ssrHydrationKey'
|
|
686
|
+
) {
|
|
687
|
+
// remove unnecessary ssr call when only hydration key is used
|
|
688
|
+
return t__namespace.binaryExpression(
|
|
689
|
+
'+',
|
|
690
|
+
t__namespace.binaryExpression(
|
|
691
|
+
'+',
|
|
692
|
+
t__namespace.memberExpression(id, t__namespace.numericLiteral(0), true),
|
|
693
|
+
result.templateValues[0]
|
|
694
|
+
),
|
|
695
|
+
t__namespace.memberExpression(id, t__namespace.numericLiteral(1), true)
|
|
696
|
+
)
|
|
697
|
+
}
|
|
698
|
+
}
|
|
699
|
+
return t__namespace.callExpression(
|
|
700
|
+
registerImportMethod(path, 'ssr'),
|
|
701
|
+
Array.isArray(result.template) && result.template.length > 1
|
|
702
|
+
? [id, ...result.templateValues]
|
|
703
|
+
: [id]
|
|
704
|
+
)
|
|
705
|
+
}
|
|
706
|
+
|
|
707
|
+
function appendTemplates$1(path, templates) {
|
|
708
|
+
const declarators = templates.map(template => {
|
|
709
|
+
return t__namespace.variableDeclarator(template.id, template.template)
|
|
710
|
+
});
|
|
711
|
+
path.node.body.unshift(t__namespace.variableDeclaration('var', declarators));
|
|
712
|
+
}
|
|
713
|
+
|
|
714
|
+
function appendToTemplate(template, value) {
|
|
715
|
+
let array;
|
|
716
|
+
if (Array.isArray(value)) {
|
|
717
|
+
[value, ...array] = value;
|
|
718
|
+
}
|
|
719
|
+
template[template.length - 1] += value;
|
|
720
|
+
if (array && array.length) template.push.apply(template, array);
|
|
721
|
+
}
|
|
722
|
+
|
|
723
|
+
function transformElement$3(path, info) {
|
|
724
|
+
const config = getConfig(path);
|
|
725
|
+
// contains spread attributes
|
|
726
|
+
if (path.node.openingElement.attributes.some((a) => t__namespace.isJSXSpreadAttribute(a))) {
|
|
727
|
+
return createElement(path, { ...info, ...config })
|
|
728
|
+
}
|
|
729
|
+
|
|
730
|
+
const tagName = getTagName(path.node);
|
|
731
|
+
const voidTag = VoidElements.indexOf(tagName) > -1;
|
|
732
|
+
const results = {
|
|
733
|
+
template: [`<${tagName}`],
|
|
734
|
+
templateValues: [],
|
|
735
|
+
declarations: [],
|
|
736
|
+
exprs: [],
|
|
737
|
+
dynamics: [],
|
|
738
|
+
tagName,
|
|
739
|
+
wontEscape: path.node.wontEscape,
|
|
740
|
+
renderer: 'ssr',
|
|
741
|
+
};
|
|
742
|
+
if (tagName === 'script' || tagName === 'style') path.doNotEscape = true;
|
|
743
|
+
|
|
744
|
+
if (info.topLevel && config.hydratable) {
|
|
745
|
+
if (tagName === 'head') {
|
|
746
|
+
registerImportMethod(path, 'NoHydration');
|
|
747
|
+
registerImportMethod(path, 'createComponent');
|
|
748
|
+
const child = transformElement$3(path, { ...info, topLevel: false });
|
|
749
|
+
results.template = '';
|
|
750
|
+
results.exprs.push(
|
|
751
|
+
t__namespace.callExpression(t__namespace.identifier('_$createComponent'), [
|
|
752
|
+
t__namespace.identifier('_$NoHydration'),
|
|
753
|
+
t__namespace.objectExpression([
|
|
754
|
+
t__namespace.objectMethod(
|
|
755
|
+
'get',
|
|
756
|
+
t__namespace.identifier('children'),
|
|
757
|
+
[],
|
|
758
|
+
t__namespace.blockStatement([t__namespace.returnStatement(createTemplate$2(path, child))])
|
|
759
|
+
),
|
|
760
|
+
]),
|
|
761
|
+
])
|
|
762
|
+
);
|
|
763
|
+
return results
|
|
764
|
+
}
|
|
765
|
+
results.template.push('');
|
|
766
|
+
results.templateValues.push(t__namespace.callExpression(registerImportMethod(path, 'ssrHydrationKey'), []));
|
|
767
|
+
}
|
|
768
|
+
transformAttributes$2(path, results, { ...config, ...info });
|
|
769
|
+
appendToTemplate(results.template, '>');
|
|
770
|
+
if (!voidTag) {
|
|
771
|
+
transformChildren$2(path, results, { ...config, ...info });
|
|
772
|
+
appendToTemplate(results.template, `</${tagName}>`);
|
|
773
|
+
}
|
|
774
|
+
return results
|
|
775
|
+
}
|
|
776
|
+
|
|
777
|
+
function toAttribute(key, isSVG) {
|
|
778
|
+
key = Aliases[key] || key;
|
|
779
|
+
!isSVG && (key = key.toLowerCase());
|
|
780
|
+
return key
|
|
781
|
+
}
|
|
782
|
+
|
|
783
|
+
function setAttr$2(attribute, results, name, value, isSVG) {
|
|
784
|
+
// strip out namespaces for now, everything at this point is an attribute
|
|
785
|
+
let parts;
|
|
786
|
+
if ((parts = name.split(':')) && parts[1] && reservedNameSpaces.has(parts[0])) {
|
|
787
|
+
name = parts[1];
|
|
788
|
+
}
|
|
789
|
+
|
|
790
|
+
name = toAttribute(name, isSVG);
|
|
791
|
+
const attr = t__namespace.callExpression(registerImportMethod(attribute, 'ssrAttribute'), [
|
|
792
|
+
t__namespace.stringLiteral(name),
|
|
793
|
+
value,
|
|
794
|
+
t__namespace.booleanLiteral(false),
|
|
795
|
+
]);
|
|
796
|
+
if (results.template[results.template.length - 1].length) {
|
|
797
|
+
results.template.push('');
|
|
798
|
+
results.templateValues.push(attr);
|
|
799
|
+
} else {
|
|
800
|
+
const last = results.templateValues.length - 1;
|
|
801
|
+
results.templateValues[last] = t__namespace.binaryExpression('+', results.templateValues[last], attr);
|
|
802
|
+
}
|
|
803
|
+
}
|
|
804
|
+
|
|
805
|
+
function escapeExpression(path, expression, attr, escapeLiterals) {
|
|
806
|
+
if (
|
|
807
|
+
t__namespace.isStringLiteral(expression) ||
|
|
808
|
+
t__namespace.isNumericLiteral(expression) ||
|
|
809
|
+
(t__namespace.isTemplateLiteral(expression) && expression.expressions.length === 0)
|
|
810
|
+
) {
|
|
811
|
+
if (escapeLiterals) {
|
|
812
|
+
if (t__namespace.isStringLiteral(expression)) return t__namespace.stringLiteral(escapeHTML(expression.value, attr))
|
|
813
|
+
else if (t__namespace.isTemplateLiteral(expression)) return t__namespace.stringLiteral(escapeHTML(expression.quasis[0].value.raw, attr))
|
|
814
|
+
}
|
|
815
|
+
return expression
|
|
816
|
+
} else if (t__namespace.isFunction(expression)) {
|
|
817
|
+
if (t__namespace.isBlockStatement(expression.body)) {
|
|
818
|
+
expression.body.body = expression.body.body.map((e) => {
|
|
819
|
+
if (t__namespace.isReturnStatement(e)) e.argument = escapeExpression(path, e.argument, attr, escapeLiterals);
|
|
820
|
+
return e
|
|
821
|
+
});
|
|
822
|
+
} else expression.body = escapeExpression(path, expression.body, attr, escapeLiterals);
|
|
823
|
+
return expression
|
|
824
|
+
} else if (t__namespace.isTemplateLiteral(expression)) {
|
|
825
|
+
expression.expressions = expression.expressions.map((e) => escapeExpression(path, e, attr, escapeLiterals));
|
|
826
|
+
return expression
|
|
827
|
+
} else if (t__namespace.isUnaryExpression(expression)) {
|
|
828
|
+
return expression
|
|
829
|
+
} else if (t__namespace.isBinaryExpression(expression)) {
|
|
830
|
+
expression.left = escapeExpression(path, expression.left, attr, escapeLiterals);
|
|
831
|
+
expression.right = escapeExpression(path, expression.right, attr, escapeLiterals);
|
|
832
|
+
return expression
|
|
833
|
+
} else if (t__namespace.isConditionalExpression(expression)) {
|
|
834
|
+
expression.consequent = escapeExpression(path, expression.consequent, attr, escapeLiterals);
|
|
835
|
+
expression.alternate = escapeExpression(path, expression.alternate, attr, escapeLiterals);
|
|
836
|
+
return expression
|
|
837
|
+
} else if (t__namespace.isLogicalExpression(expression)) {
|
|
838
|
+
expression.right = escapeExpression(path, expression.right, attr, escapeLiterals);
|
|
839
|
+
if (expression.operator !== '&&') {
|
|
840
|
+
expression.left = escapeExpression(path, expression.left, attr, escapeLiterals);
|
|
841
|
+
}
|
|
842
|
+
return expression
|
|
843
|
+
} else if (t__namespace.isCallExpression(expression) && t__namespace.isFunction(expression.callee)) {
|
|
844
|
+
if (t__namespace.isBlockStatement(expression.callee.body)) {
|
|
845
|
+
expression.callee.body.body = expression.callee.body.body.map((e) => {
|
|
846
|
+
if (t__namespace.isReturnStatement(e)) e.argument = escapeExpression(path, e.argument, attr, escapeLiterals);
|
|
847
|
+
return e
|
|
848
|
+
});
|
|
849
|
+
} else expression.callee.body = escapeExpression(path, expression.callee.body, attr, escapeLiterals);
|
|
850
|
+
return expression
|
|
851
|
+
} else if (t__namespace.isJSXElement(expression) && !isComponent(getTagName(expression))) {
|
|
852
|
+
expression.wontEscape = true;
|
|
853
|
+
return expression
|
|
854
|
+
}
|
|
855
|
+
|
|
856
|
+
return t__namespace.callExpression(
|
|
857
|
+
registerImportMethod(path, 'escape'),
|
|
858
|
+
[expression].concat(attr ? [t__namespace.booleanLiteral(true)] : [])
|
|
859
|
+
)
|
|
860
|
+
}
|
|
861
|
+
|
|
862
|
+
function transformToObject(attrName, attributes, selectedAttributes) {
|
|
863
|
+
const properties = [];
|
|
864
|
+
const existingAttribute = attributes.find((a) => a.node.name.name === attrName);
|
|
865
|
+
for (let i = 0; i < selectedAttributes.length; i++) {
|
|
866
|
+
const attr = selectedAttributes[i].node;
|
|
867
|
+
const computed = !t__namespace.isValidIdentifier(attr.name.name.name);
|
|
868
|
+
if (!computed) {
|
|
869
|
+
attr.name.name.type = 'Identifier';
|
|
870
|
+
}
|
|
871
|
+
properties.push(
|
|
872
|
+
t__namespace.objectProperty(
|
|
873
|
+
computed ? t__namespace.stringLiteral(attr.name.name.name) : attr.name.name,
|
|
874
|
+
t__namespace.isJSXExpressionContainer(attr.value) ? attr.value.expression : attr.value
|
|
875
|
+
)
|
|
876
|
+
)
|
|
877
|
+
;(existingAttribute || i) && attributes.splice(selectedAttributes[i].key, 1);
|
|
878
|
+
}
|
|
879
|
+
if (
|
|
880
|
+
existingAttribute &&
|
|
881
|
+
t__namespace.isJSXExpressionContainer(existingAttribute.node.value) &&
|
|
882
|
+
t__namespace.isObjectExpression(existingAttribute.node.value.expression)
|
|
883
|
+
) {
|
|
884
|
+
existingAttribute.node.value.expression.properties.push(...properties);
|
|
885
|
+
} else {
|
|
886
|
+
selectedAttributes[0].node = t__namespace.jsxAttribute(
|
|
887
|
+
t__namespace.jsxIdentifier(attrName),
|
|
888
|
+
t__namespace.jsxExpressionContainer(t__namespace.objectExpression(properties))
|
|
889
|
+
);
|
|
890
|
+
}
|
|
891
|
+
}
|
|
892
|
+
|
|
893
|
+
function normalizeAttributes(path) {
|
|
894
|
+
const attributes = path.get('openingElement').get('attributes');
|
|
895
|
+
const styleAttributes = attributes.filter(
|
|
896
|
+
(a) => t__namespace.isJSXNamespacedName(a.node.name) && a.node.name.namespace.name === 'style'
|
|
897
|
+
);
|
|
898
|
+
const classNamespaceAttributes = attributes.filter(
|
|
899
|
+
(a) => t__namespace.isJSXNamespacedName(a.node.name) && a.node.name.namespace.name === 'class'
|
|
900
|
+
);
|
|
901
|
+
if (classNamespaceAttributes.length) transformToObject('classList', attributes, classNamespaceAttributes);
|
|
902
|
+
const classAttributes = attributes.filter(
|
|
903
|
+
(a) =>
|
|
904
|
+
a.node.name &&
|
|
905
|
+
(a.node.name.name === 'class' || a.node.name.name === 'className' || a.node.name.name === 'classList')
|
|
906
|
+
);
|
|
907
|
+
// combine class propertoes
|
|
908
|
+
if (classAttributes.length > 1) {
|
|
909
|
+
const first = classAttributes[0].node;
|
|
910
|
+
const values = [];
|
|
911
|
+
const quasis = [t__namespace.templateElement({ raw: '' })];
|
|
912
|
+
for (let i = 0; i < classAttributes.length; i++) {
|
|
913
|
+
const attr = classAttributes[i].node;
|
|
914
|
+
const isLast = i === classAttributes.length - 1;
|
|
915
|
+
if (!t__namespace.isJSXExpressionContainer(attr.value)) {
|
|
916
|
+
const prev = quasis.pop();
|
|
917
|
+
quasis.push(
|
|
918
|
+
t__namespace.templateElement({
|
|
919
|
+
raw: (prev ? prev.value.raw : '') + `${attr.value.value}` + (isLast ? '' : ' '),
|
|
920
|
+
})
|
|
921
|
+
);
|
|
922
|
+
} else {
|
|
923
|
+
let expr = attr.value.expression;
|
|
924
|
+
if (attr.name.name === 'classList') {
|
|
925
|
+
if (t__namespace.isObjectExpression(expr) && !expr.properties.some((p) => t__namespace.isSpreadElement(p))) {
|
|
926
|
+
transformClasslistObject(path, expr, values, quasis);
|
|
927
|
+
if (!isLast) quasis[quasis.length - 1].value.raw += ' ';
|
|
928
|
+
i && attributes.splice(attributes.indexOf(classAttributes[i]), 1);
|
|
929
|
+
continue
|
|
930
|
+
}
|
|
931
|
+
expr = t__namespace.callExpression(registerImportMethod(path, 'ssrClassList'), [expr]);
|
|
932
|
+
}
|
|
933
|
+
values.push(t__namespace.logicalExpression('||', expr, t__namespace.stringLiteral('')));
|
|
934
|
+
quasis.push(t__namespace.templateElement({ raw: isLast ? '' : ' ' }));
|
|
935
|
+
}
|
|
936
|
+
i && attributes.splice(attributes.indexOf(classAttributes[i]), 1);
|
|
937
|
+
}
|
|
938
|
+
first.name = t__namespace.jsxIdentifier('class');
|
|
939
|
+
first.value = t__namespace.jsxExpressionContainer(t__namespace.templateLiteral(quasis, values));
|
|
940
|
+
}
|
|
941
|
+
if (styleAttributes.length) transformToObject('style', attributes, styleAttributes);
|
|
942
|
+
return attributes
|
|
943
|
+
}
|
|
944
|
+
|
|
945
|
+
function transformAttributes$2(path, results, info) {
|
|
946
|
+
const tagName = getTagName(path.node);
|
|
947
|
+
const isSVG = SVGElements.has(tagName);
|
|
948
|
+
const hasChildren = path.node.children.length > 0;
|
|
949
|
+
const attributes = normalizeAttributes(path);
|
|
950
|
+
let children;
|
|
951
|
+
|
|
952
|
+
attributes.forEach((attribute) => {
|
|
953
|
+
const node = attribute.node;
|
|
954
|
+
|
|
955
|
+
let value = node.value;
|
|
956
|
+
let key = t__namespace.isJSXNamespacedName(node.name) ? `${node.name.namespace.name}:${node.name.name.name}` : node.name.name;
|
|
957
|
+
const reservedNameSpace = t__namespace.isJSXNamespacedName(node.name) && reservedNameSpaces.has(node.name.namespace.name);
|
|
958
|
+
if (
|
|
959
|
+
((t__namespace.isJSXNamespacedName(node.name) && reservedNameSpace) || ChildProperties.has(key)) &&
|
|
960
|
+
!t__namespace.isJSXExpressionContainer(value)
|
|
961
|
+
) {
|
|
962
|
+
node.value = value = t__namespace.jsxExpressionContainer(value || t__namespace.jsxEmptyExpression());
|
|
963
|
+
}
|
|
964
|
+
|
|
965
|
+
if (
|
|
966
|
+
t__namespace.isJSXExpressionContainer(value) &&
|
|
967
|
+
(reservedNameSpace ||
|
|
968
|
+
ChildProperties.has(key) ||
|
|
969
|
+
!(
|
|
970
|
+
t__namespace.isStringLiteral(value.expression) ||
|
|
971
|
+
t__namespace.isNumericLiteral(value.expression) ||
|
|
972
|
+
t__namespace.isBooleanLiteral(value.expression)
|
|
973
|
+
))
|
|
974
|
+
) {
|
|
975
|
+
if (key === 'ref' || key.startsWith('use:') || key.startsWith('prop:') || key.startsWith('on')) return false
|
|
976
|
+
else if (ChildProperties.has(key)) {
|
|
977
|
+
if (info.hydratable && key === 'textContent' && value && value.expression) {
|
|
978
|
+
value.expression = t__namespace.logicalExpression('||', value.expression, t__namespace.stringLiteral(' '));
|
|
979
|
+
}
|
|
980
|
+
if (key === 'innerHTML') path.doNotEscape = true;
|
|
981
|
+
children = value;
|
|
982
|
+
} else {
|
|
983
|
+
let doEscape = true;
|
|
984
|
+
if (BooleanAttributes.has(key)) {
|
|
985
|
+
results.template.push('');
|
|
986
|
+
const fn = t__namespace.callExpression(registerImportMethod(attribute, 'ssrAttribute'), [
|
|
987
|
+
t__namespace.stringLiteral(key),
|
|
988
|
+
value.expression,
|
|
989
|
+
t__namespace.booleanLiteral(true),
|
|
990
|
+
]);
|
|
991
|
+
results.templateValues.push(fn);
|
|
992
|
+
return
|
|
993
|
+
}
|
|
994
|
+
if (key === 'style') {
|
|
995
|
+
if (
|
|
996
|
+
t__namespace.isJSXExpressionContainer(value) &&
|
|
997
|
+
t__namespace.isObjectExpression(value.expression) &&
|
|
998
|
+
!value.expression.properties.some((p) => t__namespace.isSpreadElement(p))
|
|
999
|
+
) {
|
|
1000
|
+
const props = value.expression.properties.map((p, i) =>
|
|
1001
|
+
t__namespace.binaryExpression(
|
|
1002
|
+
'+',
|
|
1003
|
+
t__namespace.stringLiteral((i ? ';' : '') + (t__namespace.isIdentifier(p.key) ? p.key.name : p.key.value) + ':'),
|
|
1004
|
+
escapeExpression(path, p.value, true, true)
|
|
1005
|
+
)
|
|
1006
|
+
);
|
|
1007
|
+
let res = props[0];
|
|
1008
|
+
for (let i = 1; i < props.length; i++) {
|
|
1009
|
+
res = t__namespace.binaryExpression('+', res, props[i]);
|
|
1010
|
+
}
|
|
1011
|
+
value.expression = res;
|
|
1012
|
+
} else {
|
|
1013
|
+
value.expression = t__namespace.callExpression(registerImportMethod(path, 'ssrStyle'), [value.expression]);
|
|
1014
|
+
}
|
|
1015
|
+
doEscape = false;
|
|
1016
|
+
}
|
|
1017
|
+
if (key === 'classList') {
|
|
1018
|
+
if (
|
|
1019
|
+
t__namespace.isObjectExpression(value.expression) &&
|
|
1020
|
+
!value.expression.properties.some((p) => t__namespace.isSpreadElement(p))
|
|
1021
|
+
) {
|
|
1022
|
+
const values = [];
|
|
1023
|
+
const quasis = [t__namespace.templateElement({ raw: '' })];
|
|
1024
|
+
transformClasslistObject(path, value.expression, values, quasis);
|
|
1025
|
+
if (!values.length) value.expression = t__namespace.stringLiteral(quasis[0].value.raw);
|
|
1026
|
+
else if (values.length === 1 && !quasis[0].value.raw && !quasis[1].value.raw) {
|
|
1027
|
+
value.expression = values[0];
|
|
1028
|
+
} else value.expression = t__namespace.templateLiteral(quasis, values);
|
|
1029
|
+
} else {
|
|
1030
|
+
value.expression = t__namespace.callExpression(registerImportMethod(path, 'ssrClassList'), [value.expression]);
|
|
1031
|
+
}
|
|
1032
|
+
key = 'class';
|
|
1033
|
+
doEscape = false;
|
|
1034
|
+
}
|
|
1035
|
+
if (doEscape) value.expression = escapeExpression(path, value.expression, true);
|
|
1036
|
+
|
|
1037
|
+
if (!doEscape || t__namespace.isLiteral(value.expression)) {
|
|
1038
|
+
key = toAttribute(key, isSVG);
|
|
1039
|
+
appendToTemplate(results.template, ` ${key}="`);
|
|
1040
|
+
results.template.push(`"`);
|
|
1041
|
+
results.templateValues.push(value.expression);
|
|
1042
|
+
} else setAttr$2(attribute, results, key, value.expression, isSVG);
|
|
1043
|
+
}
|
|
1044
|
+
} else {
|
|
1045
|
+
if (key === '$ServerOnly') return
|
|
1046
|
+
if (t__namespace.isJSXExpressionContainer(value)) value = value.expression;
|
|
1047
|
+
key = toAttribute(key, isSVG);
|
|
1048
|
+
const isBoolean = BooleanAttributes.has(key);
|
|
1049
|
+
if (isBoolean && value && value.value !== '' && !value.value) return
|
|
1050
|
+
appendToTemplate(results.template, ` ${key}`);
|
|
1051
|
+
if (!value) return
|
|
1052
|
+
let text = isBoolean ? '' : value.value;
|
|
1053
|
+
if (key === 'style' || key === 'class') {
|
|
1054
|
+
text = trimWhitespace(text);
|
|
1055
|
+
if (key === 'style') {
|
|
1056
|
+
text = text.replace(/; /g, ';').replace(/: /g, ':');
|
|
1057
|
+
}
|
|
1058
|
+
}
|
|
1059
|
+
appendToTemplate(results.template, `="${escapeHTML(text, true)}"`);
|
|
1060
|
+
}
|
|
1061
|
+
});
|
|
1062
|
+
if (!hasChildren && children) {
|
|
1063
|
+
path.node.children.push(children);
|
|
1064
|
+
}
|
|
1065
|
+
}
|
|
1066
|
+
|
|
1067
|
+
function transformClasslistObject(path, expr, values, quasis) {
|
|
1068
|
+
expr.properties.forEach((prop, i) => {
|
|
1069
|
+
const isLast = expr.properties.length - 1 === i;
|
|
1070
|
+
let key = prop.key;
|
|
1071
|
+
if (t__namespace.isIdentifier(prop.key) && !prop.computed) key = t__namespace.stringLiteral(key.name);
|
|
1072
|
+
else if (prop.computed) {
|
|
1073
|
+
key = t__namespace.callExpression(registerImportMethod(path, 'escape'), [prop.key, t__namespace.booleanLiteral(true)]);
|
|
1074
|
+
} else key = t__namespace.stringLiteral(escapeHTML(prop.key.value));
|
|
1075
|
+
if (t__namespace.isBooleanLiteral(prop.value)) {
|
|
1076
|
+
if (prop.value.value === true) {
|
|
1077
|
+
if (!prop.computed) {
|
|
1078
|
+
const prev = quasis.pop();
|
|
1079
|
+
quasis.push(
|
|
1080
|
+
t__namespace.templateElement({
|
|
1081
|
+
raw: (prev ? prev.value.raw : '') + (i ? ' ' : '') + `${key.value}` + (isLast ? '' : ' '),
|
|
1082
|
+
})
|
|
1083
|
+
);
|
|
1084
|
+
} else {
|
|
1085
|
+
values.push(key);
|
|
1086
|
+
quasis.push(t__namespace.templateElement({ raw: isLast ? '' : ' ' }));
|
|
1087
|
+
}
|
|
1088
|
+
}
|
|
1089
|
+
} else {
|
|
1090
|
+
values.push(t__namespace.conditionalExpression(prop.value, key, t__namespace.stringLiteral('')));
|
|
1091
|
+
quasis.push(t__namespace.templateElement({ raw: isLast ? '' : ' ' }));
|
|
1092
|
+
}
|
|
1093
|
+
});
|
|
1094
|
+
}
|
|
1095
|
+
|
|
1096
|
+
function transformChildren$2(path, results, { hydratable }) {
|
|
1097
|
+
const doNotEscape = path.doNotEscape;
|
|
1098
|
+
const filteredChildren = filterChildren(path.get('children'));
|
|
1099
|
+
const multi = checkLength(filteredChildren);
|
|
1100
|
+
const markers = hydratable && multi;
|
|
1101
|
+
filteredChildren.forEach((node) => {
|
|
1102
|
+
if (t__namespace.isJSXElement(node.node) && getTagName(node.node) === 'head') {
|
|
1103
|
+
const child = transformNode(node, { doNotEscape, hydratable: false });
|
|
1104
|
+
registerImportMethod(path, 'NoHydration');
|
|
1105
|
+
registerImportMethod(path, 'createComponent');
|
|
1106
|
+
results.template.push('');
|
|
1107
|
+
results.templateValues.push(
|
|
1108
|
+
t__namespace.callExpression(t__namespace.identifier('_$createComponent'), [
|
|
1109
|
+
t__namespace.identifier('_$NoHydration'),
|
|
1110
|
+
t__namespace.objectExpression([
|
|
1111
|
+
t__namespace.objectMethod(
|
|
1112
|
+
'get',
|
|
1113
|
+
t__namespace.identifier('children'),
|
|
1114
|
+
[],
|
|
1115
|
+
t__namespace.blockStatement([t__namespace.returnStatement(createTemplate$2(path, child))])
|
|
1116
|
+
),
|
|
1117
|
+
]),
|
|
1118
|
+
])
|
|
1119
|
+
);
|
|
1120
|
+
return
|
|
1121
|
+
}
|
|
1122
|
+
const child = transformNode(node, { doNotEscape });
|
|
1123
|
+
if (!child) return
|
|
1124
|
+
appendToTemplate(results.template, child.template);
|
|
1125
|
+
results.templateValues.push.apply(results.templateValues, child.templateValues || []);
|
|
1126
|
+
if (child.exprs.length) {
|
|
1127
|
+
if (!doNotEscape && !child.spreadElement) child.exprs[0] = escapeExpression(path, child.exprs[0]);
|
|
1128
|
+
|
|
1129
|
+
// boxed by textNodes
|
|
1130
|
+
if (markers && !child.spreadElement) {
|
|
1131
|
+
appendToTemplate(results.template, `<!--$-->`);
|
|
1132
|
+
results.template.push('');
|
|
1133
|
+
results.templateValues.push(child.exprs[0]);
|
|
1134
|
+
appendToTemplate(results.template, `<!--/-->`);
|
|
1135
|
+
} else {
|
|
1136
|
+
results.template.push('');
|
|
1137
|
+
results.templateValues.push(child.exprs[0]);
|
|
1138
|
+
}
|
|
1139
|
+
}
|
|
1140
|
+
});
|
|
1141
|
+
}
|
|
1142
|
+
|
|
1143
|
+
function createElement(path, { topLevel, hydratable }) {
|
|
1144
|
+
const tagName = getTagName(path.node);
|
|
1145
|
+
const config = getConfig(path);
|
|
1146
|
+
const attributes = normalizeAttributes(path);
|
|
1147
|
+
|
|
1148
|
+
const filteredChildren = filterChildren(path.get('children'));
|
|
1149
|
+
const multi = checkLength(filteredChildren);
|
|
1150
|
+
const markers = hydratable && multi;
|
|
1151
|
+
const childNodes = filteredChildren.reduce((memo, path) => {
|
|
1152
|
+
if (t__namespace.isJSXText(path.node)) {
|
|
1153
|
+
const v = htmlEntities.decode(trimWhitespace(path.node.extra.raw));
|
|
1154
|
+
if (v.length) memo.push(t__namespace.stringLiteral(v));
|
|
1155
|
+
} else {
|
|
1156
|
+
const child = transformNode(path);
|
|
1157
|
+
if (markers && child.exprs.length && !child.spreadElement) memo.push(t__namespace.stringLiteral('<!--$-->'));
|
|
1158
|
+
if (child.exprs.length && !child.spreadElement) child.exprs[0] = escapeExpression(path, child.exprs[0]);
|
|
1159
|
+
memo.push(getCreateTemplate(config, path, child)(path, child, true));
|
|
1160
|
+
if (markers && child.exprs.length && !child.spreadElement) memo.push(t__namespace.stringLiteral('<!--/-->'));
|
|
1161
|
+
}
|
|
1162
|
+
return memo
|
|
1163
|
+
}, []);
|
|
1164
|
+
|
|
1165
|
+
let props;
|
|
1166
|
+
if (attributes.length === 1) {
|
|
1167
|
+
props = [attributes[0].node.argument];
|
|
1168
|
+
} else {
|
|
1169
|
+
props = [];
|
|
1170
|
+
let runningObject = [];
|
|
1171
|
+
let dynamicSpread = false;
|
|
1172
|
+
const hasChildren = path.node.children.length > 0;
|
|
1173
|
+
|
|
1174
|
+
attributes.forEach((attribute) => {
|
|
1175
|
+
const node = attribute.node;
|
|
1176
|
+
if (t__namespace.isJSXSpreadAttribute(node)) {
|
|
1177
|
+
if (runningObject.length) {
|
|
1178
|
+
props.push(t__namespace.objectExpression(runningObject));
|
|
1179
|
+
runningObject = [];
|
|
1180
|
+
}
|
|
1181
|
+
props.push(
|
|
1182
|
+
isDynamic(attribute.get('argument'), {
|
|
1183
|
+
checkMember: true,
|
|
1184
|
+
}) && (dynamicSpread = true)
|
|
1185
|
+
? t__namespace.isCallExpression(node.argument) &&
|
|
1186
|
+
!node.argument.arguments.length &&
|
|
1187
|
+
!t__namespace.isCallExpression(node.argument.callee) &&
|
|
1188
|
+
!t__namespace.isMemberExpression(node.argument.callee)
|
|
1189
|
+
? node.argument.callee
|
|
1190
|
+
: t__namespace.arrowFunctionExpression([], node.argument)
|
|
1191
|
+
: node.argument
|
|
1192
|
+
);
|
|
1193
|
+
} else {
|
|
1194
|
+
const value = node.value || t__namespace.booleanLiteral(true);
|
|
1195
|
+
const id = convertJSXIdentifier(node.name);
|
|
1196
|
+
const key = t__namespace.isJSXNamespacedName(node.name) ? `${node.name.namespace.name}:${node.name.name.name}` : node.name.name;
|
|
1197
|
+
|
|
1198
|
+
if (hasChildren && key === 'children') return
|
|
1199
|
+
if (key === 'ref' || key.startsWith('use:') || key.startsWith('prop:') || key.startsWith('on')) return
|
|
1200
|
+
if (t__namespace.isJSXExpressionContainer(value)) {
|
|
1201
|
+
if (
|
|
1202
|
+
isDynamic(attribute.get('value').get('expression'), {
|
|
1203
|
+
checkMember: true,
|
|
1204
|
+
checkTags: true,
|
|
1205
|
+
})
|
|
1206
|
+
) {
|
|
1207
|
+
const expr = t__namespace.arrowFunctionExpression([], value.expression);
|
|
1208
|
+
runningObject.push(
|
|
1209
|
+
t__namespace.objectMethod('get', id, [], t__namespace.blockStatement([t__namespace.returnStatement(expr.body)]), !t__namespace.isValidIdentifier(key))
|
|
1210
|
+
);
|
|
1211
|
+
} else runningObject.push(t__namespace.objectProperty(id, value.expression));
|
|
1212
|
+
} else runningObject.push(t__namespace.objectProperty(id, value));
|
|
1213
|
+
}
|
|
1214
|
+
});
|
|
1215
|
+
|
|
1216
|
+
if (runningObject.length || !props.length) props.push(t__namespace.objectExpression(runningObject));
|
|
1217
|
+
|
|
1218
|
+
if (props.length > 1 || dynamicSpread) {
|
|
1219
|
+
props = [t__namespace.callExpression(registerImportMethod(path, 'mergeProps'), props)];
|
|
1220
|
+
}
|
|
1221
|
+
}
|
|
1222
|
+
|
|
1223
|
+
const exprs = [
|
|
1224
|
+
t__namespace.callExpression(registerImportMethod(path, 'ssrElement'), [
|
|
1225
|
+
t__namespace.stringLiteral(tagName),
|
|
1226
|
+
props[0],
|
|
1227
|
+
childNodes.length
|
|
1228
|
+
? hydratable
|
|
1229
|
+
? t__namespace.arrowFunctionExpression([], childNodes.length === 1 ? childNodes[0] : t__namespace.arrayExpression(childNodes))
|
|
1230
|
+
: childNodes.length === 1
|
|
1231
|
+
? childNodes[0]
|
|
1232
|
+
: t__namespace.arrayExpression(childNodes)
|
|
1233
|
+
: t__namespace.identifier('undefined'),
|
|
1234
|
+
t__namespace.booleanLiteral(Boolean(topLevel && config.hydratable)),
|
|
1235
|
+
]),
|
|
1236
|
+
];
|
|
1237
|
+
return { exprs, template: '', spreadElement: true }
|
|
1238
|
+
}
|
|
1239
|
+
|
|
1240
|
+
function transformElement$2(path) {
|
|
1241
|
+
let tagName = getTagName(path.node);
|
|
1242
|
+
const config = getConfig(path);
|
|
1243
|
+
if (config.uniqueTransform) {
|
|
1244
|
+
const taroComponent = getTaroComponentsMap(path).get(tagName);
|
|
1245
|
+
if (taroComponent) {
|
|
1246
|
+
tagName = convertCamelToKebabCase(taroComponent);
|
|
1247
|
+
}
|
|
1248
|
+
}
|
|
1249
|
+
const results = {
|
|
1250
|
+
id: path.scope.generateUidIdentifier('el$'),
|
|
1251
|
+
declarations: [],
|
|
1252
|
+
exprs: [],
|
|
1253
|
+
dynamics: [],
|
|
1254
|
+
postExprs: [],
|
|
1255
|
+
tagName,
|
|
1256
|
+
renderer: 'universal',
|
|
1257
|
+
};
|
|
1258
|
+
|
|
1259
|
+
results.declarations.push(
|
|
1260
|
+
t__namespace.variableDeclarator(
|
|
1261
|
+
results.id,
|
|
1262
|
+
t__namespace.callExpression(registerImportMethod(path, 'createElement', getRendererConfig(path, 'universal').moduleName), [
|
|
1263
|
+
t__namespace.stringLiteral(tagName),
|
|
1264
|
+
])
|
|
1265
|
+
)
|
|
1266
|
+
);
|
|
1267
|
+
|
|
1268
|
+
transformAttributes$1(path, results);
|
|
1269
|
+
transformChildren$1(path, results);
|
|
1270
|
+
|
|
1271
|
+
return results
|
|
1272
|
+
}
|
|
1273
|
+
|
|
1274
|
+
function transformAttributes$1(path, results) {
|
|
1275
|
+
let children, spreadExpr;
|
|
1276
|
+
let attributes = path.get('openingElement').get('attributes');
|
|
1277
|
+
const elem = results.id;
|
|
1278
|
+
const hasChildren = path.node.children.length > 0;
|
|
1279
|
+
const config = getConfig(path);
|
|
1280
|
+
|
|
1281
|
+
// preprocess spreads
|
|
1282
|
+
if (attributes.some((attribute) => t__namespace.isJSXSpreadAttribute(attribute.node))) {
|
|
1283
|
+
[attributes, spreadExpr] = processSpreads$1(path, attributes, {
|
|
1284
|
+
elem,
|
|
1285
|
+
hasChildren,
|
|
1286
|
+
wrapConditionals: config.wrapConditionals,
|
|
1287
|
+
});
|
|
1288
|
+
path.get('openingElement').set(
|
|
1289
|
+
'attributes',
|
|
1290
|
+
attributes.map((a) => a.node)
|
|
1291
|
+
);
|
|
1292
|
+
}
|
|
1293
|
+
|
|
1294
|
+
path
|
|
1295
|
+
.get('openingElement')
|
|
1296
|
+
.get('attributes')
|
|
1297
|
+
.forEach((attribute) => {
|
|
1298
|
+
const node = attribute.node;
|
|
1299
|
+
|
|
1300
|
+
let value = node.value;
|
|
1301
|
+
const key = t__namespace.isJSXNamespacedName(node.name)
|
|
1302
|
+
? `${node.name.namespace.name}:${node.name.name.name}`
|
|
1303
|
+
: node.name.name;
|
|
1304
|
+
const reservedNameSpace = t__namespace.isJSXNamespacedName(node.name) && node.name.namespace.name === 'use';
|
|
1305
|
+
if (t__namespace.isJSXNamespacedName(node.name) && reservedNameSpace && !t__namespace.isJSXExpressionContainer(value)) {
|
|
1306
|
+
node.value = value = t__namespace.jsxExpressionContainer(value || t__namespace.jsxEmptyExpression());
|
|
1307
|
+
}
|
|
1308
|
+
if (t__namespace.isJSXExpressionContainer(value)) {
|
|
1309
|
+
if (key === 'ref') {
|
|
1310
|
+
// Normalize expressions for non-null and type-as
|
|
1311
|
+
while (t__namespace.isTSNonNullExpression(value.expression) || t__namespace.isTSAsExpression(value.expression)) {
|
|
1312
|
+
value.expression = value.expression.expression;
|
|
1313
|
+
}
|
|
1314
|
+
if (t__namespace.isLVal(value.expression)) {
|
|
1315
|
+
const refIdentifier = path.scope.generateUidIdentifier('_ref$');
|
|
1316
|
+
results.exprs.unshift(
|
|
1317
|
+
t__namespace.variableDeclaration('var', [t__namespace.variableDeclarator(refIdentifier, value.expression)]),
|
|
1318
|
+
t__namespace.expressionStatement(
|
|
1319
|
+
t__namespace.conditionalExpression(
|
|
1320
|
+
t__namespace.binaryExpression('===', t__namespace.unaryExpression('typeof', refIdentifier), t__namespace.stringLiteral('function')),
|
|
1321
|
+
t__namespace.callExpression(registerImportMethod(path, 'use', getRendererConfig(path, 'universal').moduleName), [
|
|
1322
|
+
refIdentifier,
|
|
1323
|
+
elem,
|
|
1324
|
+
]),
|
|
1325
|
+
t__namespace.assignmentExpression('=', value.expression, elem)
|
|
1326
|
+
)
|
|
1327
|
+
)
|
|
1328
|
+
);
|
|
1329
|
+
} else if (t__namespace.isFunction(value.expression)) {
|
|
1330
|
+
results.exprs.unshift(
|
|
1331
|
+
t__namespace.expressionStatement(
|
|
1332
|
+
t__namespace.callExpression(registerImportMethod(path, 'use', getRendererConfig(path, 'universal').moduleName), [
|
|
1333
|
+
value.expression,
|
|
1334
|
+
elem,
|
|
1335
|
+
])
|
|
1336
|
+
)
|
|
1337
|
+
);
|
|
1338
|
+
} else if (t__namespace.isCallExpression(value.expression)) {
|
|
1339
|
+
const refIdentifier = path.scope.generateUidIdentifier('_ref$');
|
|
1340
|
+
results.exprs.unshift(
|
|
1341
|
+
t__namespace.variableDeclaration('var', [t__namespace.variableDeclarator(refIdentifier, value.expression)]),
|
|
1342
|
+
t__namespace.expressionStatement(
|
|
1343
|
+
t__namespace.logicalExpression(
|
|
1344
|
+
'&&',
|
|
1345
|
+
t__namespace.binaryExpression('===', t__namespace.unaryExpression('typeof', refIdentifier), t__namespace.stringLiteral('function')),
|
|
1346
|
+
t__namespace.callExpression(registerImportMethod(path, 'use', getRendererConfig(path, 'universal').moduleName), [
|
|
1347
|
+
refIdentifier,
|
|
1348
|
+
elem,
|
|
1349
|
+
])
|
|
1350
|
+
)
|
|
1351
|
+
)
|
|
1352
|
+
);
|
|
1353
|
+
}
|
|
1354
|
+
} else if (key.startsWith('use:')) {
|
|
1355
|
+
// Some trick to treat JSXIdentifier as Identifier
|
|
1356
|
+
node.name.name.type = 'Identifier';
|
|
1357
|
+
results.exprs.unshift(
|
|
1358
|
+
t__namespace.expressionStatement(
|
|
1359
|
+
t__namespace.callExpression(registerImportMethod(path, 'use', getRendererConfig(path, 'universal').moduleName), [
|
|
1360
|
+
node.name.name,
|
|
1361
|
+
elem,
|
|
1362
|
+
t__namespace.arrowFunctionExpression(
|
|
1363
|
+
[],
|
|
1364
|
+
t__namespace.isJSXEmptyExpression(value.expression) ? t__namespace.booleanLiteral(true) : value.expression
|
|
1365
|
+
),
|
|
1366
|
+
])
|
|
1367
|
+
)
|
|
1368
|
+
);
|
|
1369
|
+
} else if (key === 'children') {
|
|
1370
|
+
children = value;
|
|
1371
|
+
} else if (
|
|
1372
|
+
config.effectWrapper &&
|
|
1373
|
+
isDynamic(attribute.get('value').get('expression'), {
|
|
1374
|
+
checkMember: true,
|
|
1375
|
+
})
|
|
1376
|
+
) {
|
|
1377
|
+
results.dynamics.push({ elem, key, value: value.expression });
|
|
1378
|
+
} else {
|
|
1379
|
+
results.exprs.push(t__namespace.expressionStatement(setAttr$1(attribute, elem, key, value.expression)));
|
|
1380
|
+
}
|
|
1381
|
+
} else {
|
|
1382
|
+
results.exprs.push(t__namespace.expressionStatement(setAttr$1(attribute, elem, key, value)));
|
|
1383
|
+
}
|
|
1384
|
+
});
|
|
1385
|
+
if (spreadExpr) results.exprs.push(spreadExpr);
|
|
1386
|
+
if (!hasChildren && children) {
|
|
1387
|
+
path.node.children.push(children);
|
|
1388
|
+
}
|
|
1389
|
+
}
|
|
1390
|
+
|
|
1391
|
+
function setAttr$1(path, elem, name, value, { prevId } = {}) {
|
|
1392
|
+
if (!value) value = t__namespace.booleanLiteral(true);
|
|
1393
|
+
return t__namespace.callExpression(
|
|
1394
|
+
registerImportMethod(path, 'setProp', getRendererConfig(path, 'universal').moduleName),
|
|
1395
|
+
prevId ? [elem, t__namespace.stringLiteral(name), value, prevId] : [elem, t__namespace.stringLiteral(name), value]
|
|
1396
|
+
)
|
|
1397
|
+
}
|
|
1398
|
+
|
|
1399
|
+
function transformChildren$1(path, results) {
|
|
1400
|
+
const filteredChildren = filterChildren(path.get('children'));
|
|
1401
|
+
const multi = checkLength(filteredChildren);
|
|
1402
|
+
const childNodes = filteredChildren.map(transformNode).reduce((memo, child) => {
|
|
1403
|
+
if (!child) return memo
|
|
1404
|
+
const i = memo.length;
|
|
1405
|
+
if (child.text && i && memo[i - 1].text) {
|
|
1406
|
+
memo[i - 1].template += child.template;
|
|
1407
|
+
} else memo.push(child);
|
|
1408
|
+
return memo
|
|
1409
|
+
}, []);
|
|
1410
|
+
|
|
1411
|
+
const appends = [];
|
|
1412
|
+
childNodes.forEach((child, index) => {
|
|
1413
|
+
if (!child) return
|
|
1414
|
+
if (child.tagName && child.renderer !== 'universal') {
|
|
1415
|
+
throw new Error(`<${child.tagName}> is not supported in <${getTagName(path.node)}>.
|
|
1416
|
+
Wrap the usage with a component that would render this element, eg. Canvas`)
|
|
1417
|
+
}
|
|
1418
|
+
if (child.id) {
|
|
1419
|
+
const insertNode = registerImportMethod(path, 'insertNode', getRendererConfig(path, 'universal').moduleName);
|
|
1420
|
+
let insert = child.id;
|
|
1421
|
+
if (child.text) {
|
|
1422
|
+
const createTextNode = registerImportMethod(
|
|
1423
|
+
path,
|
|
1424
|
+
'createTextNode',
|
|
1425
|
+
getRendererConfig(path, 'universal').moduleName
|
|
1426
|
+
);
|
|
1427
|
+
if (multi) {
|
|
1428
|
+
results.declarations.push(
|
|
1429
|
+
t__namespace.variableDeclarator(
|
|
1430
|
+
child.id,
|
|
1431
|
+
t__namespace.callExpression(createTextNode, [
|
|
1432
|
+
t__namespace.templateLiteral([t__namespace.templateElement({ raw: escapeStringForTemplate(child.template) })], []),
|
|
1433
|
+
])
|
|
1434
|
+
)
|
|
1435
|
+
);
|
|
1436
|
+
} else {
|
|
1437
|
+
insert = t__namespace.callExpression(createTextNode, [
|
|
1438
|
+
t__namespace.templateLiteral([t__namespace.templateElement({ raw: escapeStringForTemplate(child.template) })], []),
|
|
1439
|
+
]);
|
|
1440
|
+
}
|
|
1441
|
+
}
|
|
1442
|
+
appends.push(t__namespace.expressionStatement(t__namespace.callExpression(insertNode, [results.id, insert])));
|
|
1443
|
+
results.declarations.push(...child.declarations);
|
|
1444
|
+
results.exprs.push(...child.exprs);
|
|
1445
|
+
results.dynamics.push(...child.dynamics);
|
|
1446
|
+
} else if (child.exprs.length) {
|
|
1447
|
+
const insert = registerImportMethod(path, 'insert', getRendererConfig(path, 'universal').moduleName);
|
|
1448
|
+
if (multi) {
|
|
1449
|
+
results.exprs.push(
|
|
1450
|
+
t__namespace.expressionStatement(
|
|
1451
|
+
t__namespace.callExpression(insert, [results.id, child.exprs[0], nextChild$1(childNodes, index) || t__namespace.nullLiteral()])
|
|
1452
|
+
)
|
|
1453
|
+
);
|
|
1454
|
+
} else {
|
|
1455
|
+
results.exprs.push(t__namespace.expressionStatement(t__namespace.callExpression(insert, [results.id, child.exprs[0]])));
|
|
1456
|
+
}
|
|
1457
|
+
}
|
|
1458
|
+
});
|
|
1459
|
+
results.exprs.unshift(...appends);
|
|
1460
|
+
}
|
|
1461
|
+
|
|
1462
|
+
function nextChild$1(children, index) {
|
|
1463
|
+
return children[index + 1] && (children[index + 1].id || nextChild$1(children, index + 1))
|
|
1464
|
+
}
|
|
1465
|
+
|
|
1466
|
+
function processSpreads$1(path, attributes, { elem, hasChildren, wrapConditionals }) {
|
|
1467
|
+
// TODO: skip but collect the names of any properties after the last spread to not overwrite them
|
|
1468
|
+
const filteredAttributes = [];
|
|
1469
|
+
const spreadArgs = [];
|
|
1470
|
+
let runningObject = [];
|
|
1471
|
+
let dynamicSpread = false;
|
|
1472
|
+
let firstSpread = false;
|
|
1473
|
+
attributes.forEach((attribute) => {
|
|
1474
|
+
const node = attribute.node;
|
|
1475
|
+
const key =
|
|
1476
|
+
!t__namespace.isJSXSpreadAttribute(node) &&
|
|
1477
|
+
(t__namespace.isJSXNamespacedName(node.name) ? `${node.name.namespace.name}:${node.name.name.name}` : node.name.name);
|
|
1478
|
+
if (t__namespace.isJSXSpreadAttribute(node)) {
|
|
1479
|
+
firstSpread = true;
|
|
1480
|
+
if (runningObject.length) {
|
|
1481
|
+
spreadArgs.push(t__namespace.objectExpression(runningObject));
|
|
1482
|
+
runningObject = [];
|
|
1483
|
+
}
|
|
1484
|
+
spreadArgs.push(
|
|
1485
|
+
isDynamic(attribute.get('argument'), {
|
|
1486
|
+
checkMember: true,
|
|
1487
|
+
}) && (dynamicSpread = true)
|
|
1488
|
+
? t__namespace.isCallExpression(node.argument) &&
|
|
1489
|
+
!node.argument.arguments.length &&
|
|
1490
|
+
!t__namespace.isCallExpression(node.argument.callee) &&
|
|
1491
|
+
!t__namespace.isMemberExpression(node.argument.callee)
|
|
1492
|
+
? node.argument.callee
|
|
1493
|
+
: t__namespace.arrowFunctionExpression([], node.argument)
|
|
1494
|
+
: node.argument
|
|
1495
|
+
);
|
|
1496
|
+
} else if (
|
|
1497
|
+
(firstSpread ||
|
|
1498
|
+
(t__namespace.isJSXExpressionContainer(node.value) &&
|
|
1499
|
+
isDynamic(attribute.get('value').get('expression'), { checkMember: true }))) &&
|
|
1500
|
+
canNativeSpread(key, { checkNameSpaces: true })
|
|
1501
|
+
) {
|
|
1502
|
+
const isContainer = t__namespace.isJSXExpressionContainer(node.value);
|
|
1503
|
+
const dynamic = isContainer && isDynamic(attribute.get('value').get('expression'), { checkMember: true });
|
|
1504
|
+
if (dynamic) {
|
|
1505
|
+
const id = convertJSXIdentifier(node.name);
|
|
1506
|
+
const expr =
|
|
1507
|
+
wrapConditionals &&
|
|
1508
|
+
(t__namespace.isLogicalExpression(node.value.expression) || t__namespace.isConditionalExpression(node.value.expression))
|
|
1509
|
+
? transformCondition(attribute.get('value').get('expression'), true)
|
|
1510
|
+
: t__namespace.arrowFunctionExpression([], node.value.expression);
|
|
1511
|
+
runningObject.push(
|
|
1512
|
+
t__namespace.objectMethod('get', id, [], t__namespace.blockStatement([t__namespace.returnStatement(expr.body)]), !t__namespace.isValidIdentifier(key))
|
|
1513
|
+
);
|
|
1514
|
+
} else {
|
|
1515
|
+
runningObject.push(
|
|
1516
|
+
t__namespace.objectProperty(
|
|
1517
|
+
t__namespace.stringLiteral(key),
|
|
1518
|
+
isContainer ? node.value.expression : node.value || t__namespace.booleanLiteral(true)
|
|
1519
|
+
)
|
|
1520
|
+
);
|
|
1521
|
+
}
|
|
1522
|
+
} else filteredAttributes.push(attribute);
|
|
1523
|
+
});
|
|
1524
|
+
|
|
1525
|
+
if (runningObject.length) {
|
|
1526
|
+
spreadArgs.push(t__namespace.objectExpression(runningObject));
|
|
1527
|
+
}
|
|
1528
|
+
|
|
1529
|
+
const props =
|
|
1530
|
+
spreadArgs.length === 1 && !dynamicSpread
|
|
1531
|
+
? spreadArgs[0]
|
|
1532
|
+
: t__namespace.callExpression(registerImportMethod(path, 'mergeProps'), spreadArgs);
|
|
1533
|
+
|
|
1534
|
+
return [
|
|
1535
|
+
filteredAttributes,
|
|
1536
|
+
t__namespace.expressionStatement(
|
|
1537
|
+
t__namespace.callExpression(registerImportMethod(path, 'spread', getRendererConfig(path, 'universal').moduleName), [
|
|
1538
|
+
elem,
|
|
1539
|
+
props,
|
|
1540
|
+
t__namespace.booleanLiteral(hasChildren),
|
|
1541
|
+
])
|
|
1542
|
+
),
|
|
1543
|
+
]
|
|
1544
|
+
}
|
|
1545
|
+
|
|
1546
|
+
function createTemplate$1(path, result, wrap) {
|
|
1547
|
+
const config = getConfig(path);
|
|
1548
|
+
if (result.id) {
|
|
1549
|
+
result.decl = t__namespace.variableDeclaration('var', result.declarations);
|
|
1550
|
+
if (
|
|
1551
|
+
!(result.exprs.length || result.dynamics.length || result.postExprs.length) &&
|
|
1552
|
+
result.decl.declarations.length === 1
|
|
1553
|
+
) {
|
|
1554
|
+
return result.decl.declarations[0].init
|
|
1555
|
+
} else {
|
|
1556
|
+
return t__namespace.callExpression(
|
|
1557
|
+
t__namespace.arrowFunctionExpression(
|
|
1558
|
+
[],
|
|
1559
|
+
t__namespace.blockStatement([
|
|
1560
|
+
result.decl,
|
|
1561
|
+
...result.exprs.concat(
|
|
1562
|
+
wrapDynamics$1(path, result.dynamics) || [],
|
|
1563
|
+
result.postExprs || []
|
|
1564
|
+
),
|
|
1565
|
+
t__namespace.returnStatement(result.id)
|
|
1566
|
+
])
|
|
1567
|
+
),
|
|
1568
|
+
[]
|
|
1569
|
+
)
|
|
1570
|
+
}
|
|
1571
|
+
}
|
|
1572
|
+
if (wrap && result.dynamic && config.memoWrapper) {
|
|
1573
|
+
return t__namespace.callExpression(registerImportMethod(path, config.memoWrapper), [result.exprs[0]])
|
|
1574
|
+
}
|
|
1575
|
+
return result.exprs[0]
|
|
1576
|
+
}
|
|
1577
|
+
|
|
1578
|
+
function wrapDynamics$1(path, dynamics) {
|
|
1579
|
+
if (!dynamics.length) return
|
|
1580
|
+
const config = getConfig(path);
|
|
1581
|
+
|
|
1582
|
+
const effectWrapperId = registerImportMethod(path, config.effectWrapper);
|
|
1583
|
+
|
|
1584
|
+
if (dynamics.length === 1) {
|
|
1585
|
+
const prevValue = t__namespace.identifier('_$p');
|
|
1586
|
+
|
|
1587
|
+
return t__namespace.expressionStatement(
|
|
1588
|
+
t__namespace.callExpression(effectWrapperId, [
|
|
1589
|
+
t__namespace.arrowFunctionExpression(
|
|
1590
|
+
[prevValue],
|
|
1591
|
+
setAttr$1(path, dynamics[0].elem, dynamics[0].key, dynamics[0].value, {
|
|
1592
|
+
dynamic: true,
|
|
1593
|
+
prevId: prevValue
|
|
1594
|
+
})
|
|
1595
|
+
)
|
|
1596
|
+
])
|
|
1597
|
+
)
|
|
1598
|
+
}
|
|
1599
|
+
|
|
1600
|
+
const prevId = t__namespace.identifier('_p$');
|
|
1601
|
+
|
|
1602
|
+
/** @type {t.VariableDeclarator[]} */
|
|
1603
|
+
const declarations = [];
|
|
1604
|
+
/** @type {t.ExpressionStatement[]} */
|
|
1605
|
+
const statements = [];
|
|
1606
|
+
/** @type {t.Identifier[]} */
|
|
1607
|
+
const properties = [];
|
|
1608
|
+
|
|
1609
|
+
dynamics.forEach(({ elem, key, value }, index) => {
|
|
1610
|
+
const varIdent = path.scope.generateUidIdentifier('v$');
|
|
1611
|
+
|
|
1612
|
+
const propIdent = t__namespace.identifier(getNumberedId(index));
|
|
1613
|
+
const propMember = t__namespace.memberExpression(prevId, propIdent);
|
|
1614
|
+
|
|
1615
|
+
properties.push(propIdent);
|
|
1616
|
+
declarations.push(t__namespace.variableDeclarator(varIdent, value));
|
|
1617
|
+
|
|
1618
|
+
statements.push(
|
|
1619
|
+
t__namespace.expressionStatement(
|
|
1620
|
+
t__namespace.logicalExpression(
|
|
1621
|
+
'&&',
|
|
1622
|
+
t__namespace.binaryExpression('!==', varIdent, propMember),
|
|
1623
|
+
t__namespace.assignmentExpression(
|
|
1624
|
+
'=',
|
|
1625
|
+
propMember,
|
|
1626
|
+
setAttr$1(path, elem, key, varIdent, { dynamic: true, prevId: propMember }),
|
|
1627
|
+
),
|
|
1628
|
+
),
|
|
1629
|
+
),
|
|
1630
|
+
);
|
|
1631
|
+
});
|
|
1632
|
+
|
|
1633
|
+
return t__namespace.expressionStatement(
|
|
1634
|
+
t__namespace.callExpression(effectWrapperId, [
|
|
1635
|
+
t__namespace.arrowFunctionExpression(
|
|
1636
|
+
[prevId],
|
|
1637
|
+
t__namespace.blockStatement([
|
|
1638
|
+
t__namespace.variableDeclaration('var', declarations),
|
|
1639
|
+
...statements,
|
|
1640
|
+
t__namespace.returnStatement(prevId),
|
|
1641
|
+
]),
|
|
1642
|
+
),
|
|
1643
|
+
t__namespace.objectExpression(
|
|
1644
|
+
properties.map((id) => t__namespace.objectProperty(id, t__namespace.identifier('undefined'))),
|
|
1645
|
+
),
|
|
1646
|
+
]),
|
|
1647
|
+
)
|
|
1648
|
+
}
|
|
1649
|
+
|
|
1650
|
+
function convertComponentIdentifier(node) {
|
|
1651
|
+
if (t__namespace.isJSXIdentifier(node)) {
|
|
1652
|
+
if (node.name === 'this') return t__namespace.thisExpression()
|
|
1653
|
+
if (t__namespace.isValidIdentifier(node.name)) node.type = 'Identifier';
|
|
1654
|
+
else return t__namespace.stringLiteral(node.name)
|
|
1655
|
+
} else if (t__namespace.isJSXMemberExpression(node)) {
|
|
1656
|
+
const prop = convertComponentIdentifier(node.property);
|
|
1657
|
+
const computed = t__namespace.isStringLiteral(prop);
|
|
1658
|
+
return t__namespace.memberExpression(convertComponentIdentifier(node.object), prop, computed)
|
|
1659
|
+
}
|
|
1660
|
+
|
|
1661
|
+
return node
|
|
1662
|
+
}
|
|
1663
|
+
|
|
1664
|
+
function transformComponent(path) {
|
|
1665
|
+
let exprs = [];
|
|
1666
|
+
const config = getConfig(path);
|
|
1667
|
+
const tagId = convertComponentIdentifier(path.node.openingElement.name);
|
|
1668
|
+
let props = [];
|
|
1669
|
+
let runningObject = [];
|
|
1670
|
+
let dynamicSpread = false;
|
|
1671
|
+
const hasChildren = path.node.children.length > 0;
|
|
1672
|
+
|
|
1673
|
+
if (config.builtIns.indexOf(tagId.name) > -1 && !path.scope.hasBinding(tagId.name)) {
|
|
1674
|
+
const newTagId = registerImportMethod(path, tagId.name);
|
|
1675
|
+
tagId.name = newTagId.name;
|
|
1676
|
+
}
|
|
1677
|
+
|
|
1678
|
+
path
|
|
1679
|
+
.get('openingElement')
|
|
1680
|
+
.get('attributes')
|
|
1681
|
+
.forEach((attribute) => {
|
|
1682
|
+
const node = attribute.node;
|
|
1683
|
+
if (t__namespace.isJSXSpreadAttribute(node)) {
|
|
1684
|
+
if (runningObject.length) {
|
|
1685
|
+
props.push(t__namespace.objectExpression(runningObject));
|
|
1686
|
+
runningObject = [];
|
|
1687
|
+
}
|
|
1688
|
+
props.push(
|
|
1689
|
+
isDynamic(attribute.get('argument'), {
|
|
1690
|
+
checkMember: true,
|
|
1691
|
+
}) && (dynamicSpread = true)
|
|
1692
|
+
? t__namespace.isCallExpression(node.argument) &&
|
|
1693
|
+
!node.argument.arguments.length &&
|
|
1694
|
+
!t__namespace.isCallExpression(node.argument.callee) &&
|
|
1695
|
+
!t__namespace.isMemberExpression(node.argument.callee)
|
|
1696
|
+
? node.argument.callee
|
|
1697
|
+
: t__namespace.arrowFunctionExpression([], node.argument)
|
|
1698
|
+
: node.argument
|
|
1699
|
+
);
|
|
1700
|
+
} else {
|
|
1701
|
+
// handle weird babel bug around HTML entities
|
|
1702
|
+
const value =
|
|
1703
|
+
(t__namespace.isStringLiteral(node.value) ? t__namespace.stringLiteral(node.value.value) : node.value) || t__namespace.booleanLiteral(true);
|
|
1704
|
+
const id = convertJSXIdentifier(node.name);
|
|
1705
|
+
const key = id.name;
|
|
1706
|
+
if (hasChildren && key === 'children') return
|
|
1707
|
+
if (t__namespace.isJSXExpressionContainer(value)) {
|
|
1708
|
+
if (key === 'ref') {
|
|
1709
|
+
if (config.generate === 'ssr') return
|
|
1710
|
+
// Normalize expressions for non-null and type-as
|
|
1711
|
+
while (
|
|
1712
|
+
t__namespace.isTSNonNullExpression(value.expression) ||
|
|
1713
|
+
t__namespace.isTSAsExpression(value.expression) ||
|
|
1714
|
+
t__namespace.isTSSatisfiesExpression(value.expression)
|
|
1715
|
+
) {
|
|
1716
|
+
value.expression = value.expression.expression;
|
|
1717
|
+
}
|
|
1718
|
+
let binding;
|
|
1719
|
+
const isFunction =
|
|
1720
|
+
t__namespace.isIdentifier(value.expression) &&
|
|
1721
|
+
(binding = path.scope.getBinding(value.expression.name)) &&
|
|
1722
|
+
binding.kind === 'const';
|
|
1723
|
+
if (!isFunction && t__namespace.isLVal(value.expression)) {
|
|
1724
|
+
const refIdentifier = path.scope.generateUidIdentifier('_ref$');
|
|
1725
|
+
runningObject.push(
|
|
1726
|
+
t__namespace.objectMethod(
|
|
1727
|
+
'method',
|
|
1728
|
+
t__namespace.identifier('ref'),
|
|
1729
|
+
[t__namespace.identifier('r$')],
|
|
1730
|
+
t__namespace.blockStatement([
|
|
1731
|
+
t__namespace.variableDeclaration('var', [t__namespace.variableDeclarator(refIdentifier, value.expression)]),
|
|
1732
|
+
t__namespace.expressionStatement(
|
|
1733
|
+
t__namespace.conditionalExpression(
|
|
1734
|
+
t__namespace.binaryExpression(
|
|
1735
|
+
'===',
|
|
1736
|
+
t__namespace.unaryExpression('typeof', refIdentifier),
|
|
1737
|
+
t__namespace.stringLiteral('function')
|
|
1738
|
+
),
|
|
1739
|
+
t__namespace.callExpression(refIdentifier, [t__namespace.identifier('r$')]),
|
|
1740
|
+
t__namespace.assignmentExpression('=', value.expression, t__namespace.identifier('r$'))
|
|
1741
|
+
)
|
|
1742
|
+
),
|
|
1743
|
+
])
|
|
1744
|
+
)
|
|
1745
|
+
);
|
|
1746
|
+
} else if (isFunction || t__namespace.isFunction(value.expression)) {
|
|
1747
|
+
runningObject.push(t__namespace.objectProperty(t__namespace.identifier('ref'), value.expression));
|
|
1748
|
+
} else if (t__namespace.isCallExpression(value.expression)) {
|
|
1749
|
+
const refIdentifier = path.scope.generateUidIdentifier('_ref$');
|
|
1750
|
+
runningObject.push(
|
|
1751
|
+
t__namespace.objectMethod(
|
|
1752
|
+
'method',
|
|
1753
|
+
t__namespace.identifier('ref'),
|
|
1754
|
+
[t__namespace.identifier('r$')],
|
|
1755
|
+
t__namespace.blockStatement([
|
|
1756
|
+
t__namespace.variableDeclaration('var', [t__namespace.variableDeclarator(refIdentifier, value.expression)]),
|
|
1757
|
+
t__namespace.expressionStatement(
|
|
1758
|
+
t__namespace.logicalExpression(
|
|
1759
|
+
'&&',
|
|
1760
|
+
t__namespace.binaryExpression(
|
|
1761
|
+
'===',
|
|
1762
|
+
t__namespace.unaryExpression('typeof', refIdentifier),
|
|
1763
|
+
t__namespace.stringLiteral('function')
|
|
1764
|
+
),
|
|
1765
|
+
t__namespace.callExpression(refIdentifier, [t__namespace.identifier('r$')])
|
|
1766
|
+
)
|
|
1767
|
+
),
|
|
1768
|
+
])
|
|
1769
|
+
)
|
|
1770
|
+
);
|
|
1771
|
+
}
|
|
1772
|
+
} else if (
|
|
1773
|
+
isDynamic(attribute.get('value').get('expression'), {
|
|
1774
|
+
checkMember: true,
|
|
1775
|
+
checkTags: true,
|
|
1776
|
+
})
|
|
1777
|
+
) {
|
|
1778
|
+
if (
|
|
1779
|
+
config.wrapConditionals &&
|
|
1780
|
+
config.generate !== 'ssr' &&
|
|
1781
|
+
(t__namespace.isLogicalExpression(value.expression) || t__namespace.isConditionalExpression(value.expression))
|
|
1782
|
+
) {
|
|
1783
|
+
const expr = transformCondition(attribute.get('value').get('expression'), true);
|
|
1784
|
+
|
|
1785
|
+
runningObject.push(
|
|
1786
|
+
t__namespace.objectMethod(
|
|
1787
|
+
'get',
|
|
1788
|
+
id,
|
|
1789
|
+
[],
|
|
1790
|
+
t__namespace.blockStatement([t__namespace.returnStatement(expr.body)]),
|
|
1791
|
+
!t__namespace.isValidIdentifier(key)
|
|
1792
|
+
)
|
|
1793
|
+
);
|
|
1794
|
+
} else if (t__namespace.isCallExpression(value.expression) && t__namespace.isArrowFunctionExpression(value.expression.callee)) {
|
|
1795
|
+
const callee = value.expression.callee;
|
|
1796
|
+
const body = t__namespace.isBlockStatement(callee.body)
|
|
1797
|
+
? callee.body
|
|
1798
|
+
: t__namespace.blockStatement([t__namespace.returnStatement(callee.body)]);
|
|
1799
|
+
|
|
1800
|
+
runningObject.push(t__namespace.objectMethod('get', id, [], body, !t__namespace.isValidIdentifier(key)));
|
|
1801
|
+
} else {
|
|
1802
|
+
runningObject.push(
|
|
1803
|
+
t__namespace.objectMethod(
|
|
1804
|
+
'get',
|
|
1805
|
+
id,
|
|
1806
|
+
[],
|
|
1807
|
+
t__namespace.blockStatement([t__namespace.returnStatement(value.expression)]),
|
|
1808
|
+
!t__namespace.isValidIdentifier(key)
|
|
1809
|
+
)
|
|
1810
|
+
);
|
|
1811
|
+
}
|
|
1812
|
+
} else runningObject.push(t__namespace.objectProperty(id, value.expression));
|
|
1813
|
+
} else runningObject.push(t__namespace.objectProperty(id, value));
|
|
1814
|
+
}
|
|
1815
|
+
});
|
|
1816
|
+
|
|
1817
|
+
const childResult = transformComponentChildren(path.get('children'), config);
|
|
1818
|
+
if (childResult && childResult[0]) {
|
|
1819
|
+
if (childResult[1]) {
|
|
1820
|
+
const body =
|
|
1821
|
+
t__namespace.isCallExpression(childResult[0]) && t__namespace.isFunction(childResult[0].arguments[0])
|
|
1822
|
+
? childResult[0].arguments[0].body
|
|
1823
|
+
: childResult[0].body
|
|
1824
|
+
? childResult[0].body
|
|
1825
|
+
: childResult[0];
|
|
1826
|
+
runningObject.push(
|
|
1827
|
+
t__namespace.objectMethod(
|
|
1828
|
+
'get',
|
|
1829
|
+
t__namespace.identifier('children'),
|
|
1830
|
+
[],
|
|
1831
|
+
t__namespace.isExpression(body) ? t__namespace.blockStatement([t__namespace.returnStatement(body)]) : body
|
|
1832
|
+
)
|
|
1833
|
+
);
|
|
1834
|
+
} else runningObject.push(t__namespace.objectProperty(t__namespace.identifier('children'), childResult[0]));
|
|
1835
|
+
}
|
|
1836
|
+
if (runningObject.length || !props.length) props.push(t__namespace.objectExpression(runningObject));
|
|
1837
|
+
|
|
1838
|
+
if (props.length > 1 || dynamicSpread) {
|
|
1839
|
+
props = [t__namespace.callExpression(registerImportMethod(path, 'mergeProps'), props)];
|
|
1840
|
+
}
|
|
1841
|
+
const componentArgs = [tagId, props[0]];
|
|
1842
|
+
exprs.push(t__namespace.callExpression(registerImportMethod(path, 'createComponent'), componentArgs));
|
|
1843
|
+
|
|
1844
|
+
// handle hoisting conditionals
|
|
1845
|
+
if (exprs.length > 1) {
|
|
1846
|
+
const ret = exprs.pop();
|
|
1847
|
+
exprs = [t__namespace.callExpression(t__namespace.arrowFunctionExpression([], t__namespace.blockStatement([...exprs, t__namespace.returnStatement(ret)])), [])];
|
|
1848
|
+
}
|
|
1849
|
+
return { exprs, template: '', component: true }
|
|
1850
|
+
}
|
|
1851
|
+
|
|
1852
|
+
function transformComponentChildren(children, config) {
|
|
1853
|
+
const filteredChildren = filterChildren(children);
|
|
1854
|
+
if (!filteredChildren.length) return
|
|
1855
|
+
let dynamic = false;
|
|
1856
|
+
const pathNodes = [];
|
|
1857
|
+
|
|
1858
|
+
let transformedChildren = filteredChildren.reduce((memo, path) => {
|
|
1859
|
+
if (t__namespace.isJSXText(path.node)) {
|
|
1860
|
+
const v = htmlEntities.decode(trimWhitespace(path.node.extra.raw));
|
|
1861
|
+
if (v.length) {
|
|
1862
|
+
pathNodes.push(path.node);
|
|
1863
|
+
memo.push(t__namespace.stringLiteral(v));
|
|
1864
|
+
}
|
|
1865
|
+
} else {
|
|
1866
|
+
const child = transformNode(path, {
|
|
1867
|
+
topLevel: true,
|
|
1868
|
+
componentChild: true,
|
|
1869
|
+
lastElement: true,
|
|
1870
|
+
});
|
|
1871
|
+
dynamic = dynamic || child.dynamic;
|
|
1872
|
+
if (config.generate === 'ssr' && filteredChildren.length > 1 && child.dynamic && t__namespace.isFunction(child.exprs[0])) {
|
|
1873
|
+
child.exprs[0] = child.exprs[0].body;
|
|
1874
|
+
}
|
|
1875
|
+
pathNodes.push(path.node);
|
|
1876
|
+
memo.push(getCreateTemplate(config, path, child)(path, child, filteredChildren.length > 1));
|
|
1877
|
+
}
|
|
1878
|
+
return memo
|
|
1879
|
+
}, []);
|
|
1880
|
+
|
|
1881
|
+
if (transformedChildren.length === 1) {
|
|
1882
|
+
transformedChildren = transformedChildren[0];
|
|
1883
|
+
if (!t__namespace.isJSXExpressionContainer(pathNodes[0]) && !t__namespace.isJSXSpreadChild(pathNodes[0]) && !t__namespace.isJSXText(pathNodes[0])) {
|
|
1884
|
+
transformedChildren =
|
|
1885
|
+
t__namespace.isCallExpression(transformedChildren) &&
|
|
1886
|
+
!transformedChildren.arguments.length &&
|
|
1887
|
+
!t__namespace.isIdentifier(transformedChildren.callee)
|
|
1888
|
+
? transformedChildren.callee
|
|
1889
|
+
: t__namespace.arrowFunctionExpression([], transformedChildren);
|
|
1890
|
+
dynamic = true;
|
|
1891
|
+
}
|
|
1892
|
+
} else {
|
|
1893
|
+
transformedChildren = t__namespace.arrowFunctionExpression([], t__namespace.arrayExpression(transformedChildren));
|
|
1894
|
+
dynamic = true;
|
|
1895
|
+
}
|
|
1896
|
+
return [transformedChildren, dynamic]
|
|
1897
|
+
}
|
|
1898
|
+
|
|
1899
|
+
function transformFragmentChildren(children, results, config) {
|
|
1900
|
+
const filteredChildren = filterChildren(children);
|
|
1901
|
+
const childNodes = filteredChildren.reduce((memo, path) => {
|
|
1902
|
+
if (t__namespace.isJSXText(path.node)) {
|
|
1903
|
+
const v = htmlEntities.decode(trimWhitespace(path.node.extra.raw));
|
|
1904
|
+
if (v.length) memo.push(t__namespace.stringLiteral(v));
|
|
1905
|
+
} else {
|
|
1906
|
+
const child = transformNode(path, { topLevel: true, fragmentChild: true, lastElement: true });
|
|
1907
|
+
memo.push(getCreateTemplate(config, path, child)(path, child, true));
|
|
1908
|
+
}
|
|
1909
|
+
return memo
|
|
1910
|
+
}, []);
|
|
1911
|
+
results.exprs.push(childNodes.length === 1 ? childNodes[0] : t__namespace.arrayExpression(childNodes));
|
|
1912
|
+
}
|
|
1913
|
+
|
|
1914
|
+
function transformJSX(path) {
|
|
1915
|
+
const config = getConfig(path);
|
|
1916
|
+
const replace = transformThis(path);
|
|
1917
|
+
const result = transformNode(
|
|
1918
|
+
path,
|
|
1919
|
+
t__namespace.isJSXFragment(path.node)
|
|
1920
|
+
? {}
|
|
1921
|
+
: {
|
|
1922
|
+
topLevel: true,
|
|
1923
|
+
lastElement: true,
|
|
1924
|
+
}
|
|
1925
|
+
);
|
|
1926
|
+
|
|
1927
|
+
const template = getCreateTemplate(config, path, result);
|
|
1928
|
+
|
|
1929
|
+
path.replaceWith(replace(template(path, result, false)));
|
|
1930
|
+
}
|
|
1931
|
+
|
|
1932
|
+
function getTargetFunctionParent(path, parent) {
|
|
1933
|
+
let current = path.scope.getFunctionParent();
|
|
1934
|
+
while (current !== parent && current.path.isArrowFunctionExpression()) {
|
|
1935
|
+
current = current.path.parentPath.scope.getFunctionParent();
|
|
1936
|
+
}
|
|
1937
|
+
return current
|
|
1938
|
+
}
|
|
1939
|
+
|
|
1940
|
+
function transformThis(path) {
|
|
1941
|
+
const parent = path.scope.getFunctionParent();
|
|
1942
|
+
let thisId;
|
|
1943
|
+
path.traverse({
|
|
1944
|
+
ThisExpression(path) {
|
|
1945
|
+
const current = getTargetFunctionParent(path, parent);
|
|
1946
|
+
if (current === parent) {
|
|
1947
|
+
thisId || (thisId = path.scope.generateUidIdentifier('self$'));
|
|
1948
|
+
path.replaceWith(thisId);
|
|
1949
|
+
}
|
|
1950
|
+
},
|
|
1951
|
+
JSXElement(path) {
|
|
1952
|
+
let source = path.get('openingElement').get('name');
|
|
1953
|
+
while (source.isJSXMemberExpression()) {
|
|
1954
|
+
source = source.get('object');
|
|
1955
|
+
}
|
|
1956
|
+
if (source.isJSXIdentifier() && source.node.name === 'this') {
|
|
1957
|
+
const current = getTargetFunctionParent(path, parent);
|
|
1958
|
+
if (current === parent) {
|
|
1959
|
+
thisId || (thisId = path.scope.generateUidIdentifier('self$'));
|
|
1960
|
+
source.replaceWith(t__namespace.jsxIdentifier(thisId.name));
|
|
1961
|
+
|
|
1962
|
+
if (path.node.closingElement) {
|
|
1963
|
+
path.node.closingElement.name = path.node.openingElement.name;
|
|
1964
|
+
}
|
|
1965
|
+
}
|
|
1966
|
+
}
|
|
1967
|
+
},
|
|
1968
|
+
});
|
|
1969
|
+
return (node) => {
|
|
1970
|
+
if (thisId) {
|
|
1971
|
+
parent.push({
|
|
1972
|
+
id: thisId,
|
|
1973
|
+
init: t__namespace.thisExpression(),
|
|
1974
|
+
kind: 'const',
|
|
1975
|
+
});
|
|
1976
|
+
}
|
|
1977
|
+
return node
|
|
1978
|
+
}
|
|
1979
|
+
}
|
|
1980
|
+
|
|
1981
|
+
function transformNode(path, info = {}) {
|
|
1982
|
+
const config = getConfig(path);
|
|
1983
|
+
const node = path.node;
|
|
1984
|
+
let staticValue;
|
|
1985
|
+
if (t__namespace.isJSXElement(node)) {
|
|
1986
|
+
return transformElement$1(config, path, info)
|
|
1987
|
+
} else if (t__namespace.isJSXFragment(node)) {
|
|
1988
|
+
const results = { template: '', declarations: [], exprs: [], dynamics: [] };
|
|
1989
|
+
// <><div /><Component /></>
|
|
1990
|
+
transformFragmentChildren(path.get('children'), results, config);
|
|
1991
|
+
return results
|
|
1992
|
+
} else if (t__namespace.isJSXText(node) || (staticValue = getStaticExpression(path)) !== false) {
|
|
1993
|
+
const text =
|
|
1994
|
+
staticValue !== undefined
|
|
1995
|
+
? info.doNotEscape
|
|
1996
|
+
? staticValue.toString()
|
|
1997
|
+
: escapeHTML(staticValue.toString())
|
|
1998
|
+
: trimWhitespace(node.extra.raw);
|
|
1999
|
+
if (!text.length) return null
|
|
2000
|
+
const results = {
|
|
2001
|
+
template: text,
|
|
2002
|
+
declarations: [],
|
|
2003
|
+
exprs: [],
|
|
2004
|
+
dynamics: [],
|
|
2005
|
+
postExprs: [],
|
|
2006
|
+
text: true,
|
|
2007
|
+
};
|
|
2008
|
+
if (!info.skipId && config.generate !== 'ssr') results.id = path.scope.generateUidIdentifier('el$');
|
|
2009
|
+
return results
|
|
2010
|
+
} else if (t__namespace.isJSXExpressionContainer(node)) {
|
|
2011
|
+
if (t__namespace.isJSXEmptyExpression(node.expression)) return null
|
|
2012
|
+
if (
|
|
2013
|
+
!isDynamic(path.get('expression'), {
|
|
2014
|
+
checkMember: true,
|
|
2015
|
+
checkTags: !!info.componentChild,
|
|
2016
|
+
native: !info.componentChild,
|
|
2017
|
+
})
|
|
2018
|
+
) {
|
|
2019
|
+
return { exprs: [node.expression], template: '' }
|
|
2020
|
+
}
|
|
2021
|
+
const expr =
|
|
2022
|
+
config.wrapConditionals &&
|
|
2023
|
+
config.generate !== 'ssr' &&
|
|
2024
|
+
(t__namespace.isLogicalExpression(node.expression) || t__namespace.isConditionalExpression(node.expression))
|
|
2025
|
+
? transformCondition(path.get('expression'), info.componentChild || info.fragmentChild)
|
|
2026
|
+
: !info.componentChild &&
|
|
2027
|
+
(config.generate !== 'ssr' || info.fragmentChild) &&
|
|
2028
|
+
t__namespace.isCallExpression(node.expression) &&
|
|
2029
|
+
!t__namespace.isMemberExpression(node.expression.callee) &&
|
|
2030
|
+
node.expression.arguments.length === 0
|
|
2031
|
+
? node.expression.callee
|
|
2032
|
+
: t__namespace.arrowFunctionExpression([], node.expression);
|
|
2033
|
+
return {
|
|
2034
|
+
exprs:
|
|
2035
|
+
expr.length > 1
|
|
2036
|
+
? [
|
|
2037
|
+
t__namespace.callExpression(
|
|
2038
|
+
t__namespace.arrowFunctionExpression([], t__namespace.blockStatement([expr[0], t__namespace.returnStatement(expr[1])])),
|
|
2039
|
+
[]
|
|
2040
|
+
),
|
|
2041
|
+
]
|
|
2042
|
+
: [expr],
|
|
2043
|
+
template: '',
|
|
2044
|
+
dynamic: true,
|
|
2045
|
+
}
|
|
2046
|
+
} else if (t__namespace.isJSXSpreadChild(node)) {
|
|
2047
|
+
if (
|
|
2048
|
+
!isDynamic(path.get('expression'), {
|
|
2049
|
+
checkMember: true,
|
|
2050
|
+
native: !info.componentChild,
|
|
2051
|
+
})
|
|
2052
|
+
) { return { exprs: [node.expression], template: '' } }
|
|
2053
|
+
const expr = t__namespace.arrowFunctionExpression([], node.expression);
|
|
2054
|
+
return {
|
|
2055
|
+
exprs: [expr],
|
|
2056
|
+
template: '',
|
|
2057
|
+
dynamic: true,
|
|
2058
|
+
}
|
|
2059
|
+
}
|
|
2060
|
+
}
|
|
2061
|
+
|
|
2062
|
+
function getCreateTemplate(config, path, result) {
|
|
2063
|
+
if ((result.tagName && result.renderer === 'dom') || config.generate === 'dom') {
|
|
2064
|
+
return createTemplate
|
|
2065
|
+
}
|
|
2066
|
+
|
|
2067
|
+
if (result.renderer === 'ssr' || config.generate === 'ssr') {
|
|
2068
|
+
return createTemplate$2
|
|
2069
|
+
}
|
|
2070
|
+
|
|
2071
|
+
return createTemplate$1
|
|
2072
|
+
}
|
|
2073
|
+
|
|
2074
|
+
function transformElement$1(config, path, info = {}) {
|
|
2075
|
+
const node = path.node;
|
|
2076
|
+
let tagName = getTagName(node);
|
|
2077
|
+
if (config.uniqueTransform) {
|
|
2078
|
+
const taroComponent = getTaroComponentsMap(path).get(tagName);
|
|
2079
|
+
if (taroComponent) {
|
|
2080
|
+
tagName = convertCamelToKebabCase(taroComponent);
|
|
2081
|
+
}
|
|
2082
|
+
}
|
|
2083
|
+
// <Component ...></Component>
|
|
2084
|
+
if (isComponent(tagName)) return transformComponent(path)
|
|
2085
|
+
|
|
2086
|
+
// <div ...></div>
|
|
2087
|
+
// const element = getTransformElemet(config, path, tagName);
|
|
2088
|
+
|
|
2089
|
+
const tagRenderer = (config.renderers ?? []).find((renderer) => renderer.elements.includes(tagName));
|
|
2090
|
+
|
|
2091
|
+
if (tagRenderer?.name === 'dom' || getConfig(path).generate === 'dom') {
|
|
2092
|
+
return transformElement(path, info)
|
|
2093
|
+
}
|
|
2094
|
+
|
|
2095
|
+
if (getConfig(path).generate === 'ssr') {
|
|
2096
|
+
return transformElement$3(path, info)
|
|
2097
|
+
}
|
|
2098
|
+
|
|
2099
|
+
return transformElement$2(path)
|
|
2100
|
+
}
|
|
2101
|
+
|
|
2102
|
+
const InlineElements = [
|
|
2103
|
+
'a',
|
|
2104
|
+
'abbr',
|
|
2105
|
+
'acronym',
|
|
2106
|
+
'b',
|
|
2107
|
+
'bdi',
|
|
2108
|
+
'bdo',
|
|
2109
|
+
'big',
|
|
2110
|
+
'br',
|
|
2111
|
+
'button',
|
|
2112
|
+
'canvas',
|
|
2113
|
+
'cite',
|
|
2114
|
+
'code',
|
|
2115
|
+
'data',
|
|
2116
|
+
'datalist',
|
|
2117
|
+
'del',
|
|
2118
|
+
'dfn',
|
|
2119
|
+
'em',
|
|
2120
|
+
'embed',
|
|
2121
|
+
'i',
|
|
2122
|
+
'iframe',
|
|
2123
|
+
'img',
|
|
2124
|
+
'input',
|
|
2125
|
+
'ins',
|
|
2126
|
+
'kbd',
|
|
2127
|
+
'label',
|
|
2128
|
+
'map',
|
|
2129
|
+
'mark',
|
|
2130
|
+
'meter',
|
|
2131
|
+
'noscript',
|
|
2132
|
+
'object',
|
|
2133
|
+
'output',
|
|
2134
|
+
'picture',
|
|
2135
|
+
'progress',
|
|
2136
|
+
'q',
|
|
2137
|
+
'ruby',
|
|
2138
|
+
's',
|
|
2139
|
+
'samp',
|
|
2140
|
+
'script',
|
|
2141
|
+
'select',
|
|
2142
|
+
'slot',
|
|
2143
|
+
'small',
|
|
2144
|
+
'span',
|
|
2145
|
+
'strong',
|
|
2146
|
+
'sub',
|
|
2147
|
+
'sup',
|
|
2148
|
+
'svg',
|
|
2149
|
+
'template',
|
|
2150
|
+
'textarea',
|
|
2151
|
+
'time',
|
|
2152
|
+
'u',
|
|
2153
|
+
'tt',
|
|
2154
|
+
'var',
|
|
2155
|
+
'video'
|
|
2156
|
+
];
|
|
2157
|
+
|
|
2158
|
+
const BlockElements = [
|
|
2159
|
+
'address',
|
|
2160
|
+
'article',
|
|
2161
|
+
'aside',
|
|
2162
|
+
'blockquote',
|
|
2163
|
+
'dd',
|
|
2164
|
+
'details',
|
|
2165
|
+
'dialog',
|
|
2166
|
+
'div',
|
|
2167
|
+
'dl',
|
|
2168
|
+
'dt',
|
|
2169
|
+
'fieldset',
|
|
2170
|
+
'figcaption',
|
|
2171
|
+
'figure',
|
|
2172
|
+
'footer',
|
|
2173
|
+
'form',
|
|
2174
|
+
'h1',
|
|
2175
|
+
'h2',
|
|
2176
|
+
'h3',
|
|
2177
|
+
'h4',
|
|
2178
|
+
'h5',
|
|
2179
|
+
'h6',
|
|
2180
|
+
'header',
|
|
2181
|
+
'hgroup',
|
|
2182
|
+
'hr',
|
|
2183
|
+
'li',
|
|
2184
|
+
'main',
|
|
2185
|
+
'menu',
|
|
2186
|
+
'nav',
|
|
2187
|
+
'ol',
|
|
2188
|
+
'p',
|
|
2189
|
+
'pre',
|
|
2190
|
+
'section',
|
|
2191
|
+
'table',
|
|
2192
|
+
'ul'
|
|
2193
|
+
];
|
|
2194
|
+
|
|
2195
|
+
const alwaysClose = [
|
|
2196
|
+
'title',
|
|
2197
|
+
'style',
|
|
2198
|
+
'a',
|
|
2199
|
+
'strong',
|
|
2200
|
+
'small',
|
|
2201
|
+
'b',
|
|
2202
|
+
'u',
|
|
2203
|
+
'i',
|
|
2204
|
+
'em',
|
|
2205
|
+
's',
|
|
2206
|
+
'code',
|
|
2207
|
+
'object',
|
|
2208
|
+
'table',
|
|
2209
|
+
'button',
|
|
2210
|
+
'textarea',
|
|
2211
|
+
'select',
|
|
2212
|
+
'iframe',
|
|
2213
|
+
'script',
|
|
2214
|
+
'template',
|
|
2215
|
+
'fieldset',
|
|
2216
|
+
];
|
|
2217
|
+
|
|
2218
|
+
function transformElement(path, info) {
|
|
2219
|
+
const tagName = getTagName(path.node);
|
|
2220
|
+
const config = getConfig(path);
|
|
2221
|
+
const wrapSVG = info.topLevel && tagName !== 'svg' && SVGElements.has(tagName);
|
|
2222
|
+
const voidTag = VoidElements.indexOf(tagName) > -1;
|
|
2223
|
+
const isCustomElement = tagName.indexOf('-') > -1;
|
|
2224
|
+
const results = {
|
|
2225
|
+
template: `<${tagName}`,
|
|
2226
|
+
declarations: [],
|
|
2227
|
+
exprs: [],
|
|
2228
|
+
dynamics: [],
|
|
2229
|
+
postExprs: [],
|
|
2230
|
+
isSVG: wrapSVG,
|
|
2231
|
+
hasCustomElement: isCustomElement,
|
|
2232
|
+
tagName,
|
|
2233
|
+
renderer: 'dom',
|
|
2234
|
+
skipTemplate: false,
|
|
2235
|
+
};
|
|
2236
|
+
if (config.hydratable && (tagName === 'html' || tagName === 'head' || tagName === 'body')) {
|
|
2237
|
+
results.skipTemplate = true;
|
|
2238
|
+
if (tagName === 'head' && info.topLevel) {
|
|
2239
|
+
const createComponent = registerImportMethod(path, 'createComponent', getRendererConfig(path, 'dom').moduleName);
|
|
2240
|
+
const NoHydration = registerImportMethod(path, 'NoHydration', getRendererConfig(path, 'dom').moduleName);
|
|
2241
|
+
results.exprs.push(
|
|
2242
|
+
t__namespace.expressionStatement(t__namespace.callExpression(createComponent, [NoHydration, t__namespace.objectExpression([])]))
|
|
2243
|
+
);
|
|
2244
|
+
return results
|
|
2245
|
+
}
|
|
2246
|
+
}
|
|
2247
|
+
if (wrapSVG) results.template = '<svg>' + results.template;
|
|
2248
|
+
if (!info.skipId) results.id = path.scope.generateUidIdentifier('el$');
|
|
2249
|
+
transformAttributes(path, results);
|
|
2250
|
+
if (config.contextToCustomElements && (tagName === 'slot' || isCustomElement)) {
|
|
2251
|
+
contextToCustomElement(path, results);
|
|
2252
|
+
}
|
|
2253
|
+
results.template += '>';
|
|
2254
|
+
if (!voidTag) {
|
|
2255
|
+
// always close tags can still be skipped if they have no closing parents and are the last element
|
|
2256
|
+
const toBeClosed =
|
|
2257
|
+
!info.lastElement || (info.toBeClosed && (!config.omitNestedClosingTags || info.toBeClosed.has(tagName)));
|
|
2258
|
+
if (toBeClosed) {
|
|
2259
|
+
results.toBeClosed = new Set(info.toBeClosed || alwaysClose);
|
|
2260
|
+
results.toBeClosed.add(tagName);
|
|
2261
|
+
if (InlineElements.includes(tagName)) BlockElements.forEach((i) => results.toBeClosed.add(i));
|
|
2262
|
+
} else results.toBeClosed = info.toBeClosed;
|
|
2263
|
+
transformChildren(path, results, config);
|
|
2264
|
+
if (toBeClosed) results.template += `</${tagName}>`;
|
|
2265
|
+
}
|
|
2266
|
+
if (info.topLevel && config.hydratable && results.hasHydratableEvent) {
|
|
2267
|
+
const runHydrationEvents = registerImportMethod(
|
|
2268
|
+
path,
|
|
2269
|
+
'runHydrationEvents',
|
|
2270
|
+
getRendererConfig(path, 'dom').moduleName
|
|
2271
|
+
);
|
|
2272
|
+
results.postExprs.push(t__namespace.expressionStatement(t__namespace.callExpression(runHydrationEvents, [])));
|
|
2273
|
+
}
|
|
2274
|
+
if (wrapSVG) results.template += '</svg>';
|
|
2275
|
+
return results
|
|
2276
|
+
}
|
|
2277
|
+
|
|
2278
|
+
function setAttr(path, elem, name, value, { isSVG, dynamic, prevId, isCE, tagName }) {
|
|
2279
|
+
// pull out namespace
|
|
2280
|
+
const config = getConfig(path);
|
|
2281
|
+
let parts, namespace;
|
|
2282
|
+
if ((parts = name.split(':')) && parts[1] && reservedNameSpaces.has(parts[0])) {
|
|
2283
|
+
name = parts[1];
|
|
2284
|
+
namespace = parts[0];
|
|
2285
|
+
}
|
|
2286
|
+
|
|
2287
|
+
// TODO: consider moving to a helper
|
|
2288
|
+
if (namespace === 'style') {
|
|
2289
|
+
if (t__namespace.isStringLiteral(value)) {
|
|
2290
|
+
return t__namespace.callExpression(
|
|
2291
|
+
t__namespace.memberExpression(t__namespace.memberExpression(elem, t__namespace.identifier('style')), t__namespace.identifier('setProperty')),
|
|
2292
|
+
[t__namespace.stringLiteral(name), value]
|
|
2293
|
+
)
|
|
2294
|
+
}
|
|
2295
|
+
if (t__namespace.isNullLiteral(value) || t__namespace.isIdentifier(value, { name: 'undefined' })) {
|
|
2296
|
+
return t__namespace.callExpression(
|
|
2297
|
+
t__namespace.memberExpression(t__namespace.memberExpression(elem, t__namespace.identifier('style')), t__namespace.identifier('removeProperty')),
|
|
2298
|
+
[t__namespace.stringLiteral(name)]
|
|
2299
|
+
)
|
|
2300
|
+
}
|
|
2301
|
+
return t__namespace.conditionalExpression(
|
|
2302
|
+
t__namespace.binaryExpression('!=', value, t__namespace.nullLiteral()),
|
|
2303
|
+
t__namespace.callExpression(
|
|
2304
|
+
t__namespace.memberExpression(t__namespace.memberExpression(elem, t__namespace.identifier('style')), t__namespace.identifier('setProperty')),
|
|
2305
|
+
[t__namespace.stringLiteral(name), prevId || value]
|
|
2306
|
+
),
|
|
2307
|
+
t__namespace.callExpression(
|
|
2308
|
+
t__namespace.memberExpression(t__namespace.memberExpression(elem, t__namespace.identifier('style')), t__namespace.identifier('removeProperty')),
|
|
2309
|
+
[t__namespace.stringLiteral(name)]
|
|
2310
|
+
)
|
|
2311
|
+
)
|
|
2312
|
+
}
|
|
2313
|
+
|
|
2314
|
+
if (namespace === 'class') {
|
|
2315
|
+
return t__namespace.callExpression(
|
|
2316
|
+
t__namespace.memberExpression(t__namespace.memberExpression(elem, t__namespace.identifier('classList')), t__namespace.identifier('toggle')),
|
|
2317
|
+
[t__namespace.stringLiteral(name), dynamic ? value : t__namespace.unaryExpression('!', t__namespace.unaryExpression('!', value))]
|
|
2318
|
+
)
|
|
2319
|
+
}
|
|
2320
|
+
|
|
2321
|
+
if (name === 'style') {
|
|
2322
|
+
return t__namespace.callExpression(
|
|
2323
|
+
registerImportMethod(path, 'style', getRendererConfig(path, 'dom').moduleName),
|
|
2324
|
+
prevId ? [elem, value, prevId] : [elem, value]
|
|
2325
|
+
)
|
|
2326
|
+
}
|
|
2327
|
+
|
|
2328
|
+
if (!isSVG && name === 'class') {
|
|
2329
|
+
return t__namespace.callExpression(registerImportMethod(path, 'className', getRendererConfig(path, 'dom').moduleName), [
|
|
2330
|
+
elem,
|
|
2331
|
+
value,
|
|
2332
|
+
])
|
|
2333
|
+
}
|
|
2334
|
+
|
|
2335
|
+
if (name === 'classList') {
|
|
2336
|
+
return t__namespace.callExpression(
|
|
2337
|
+
registerImportMethod(path, 'classList', getRendererConfig(path, 'dom').moduleName),
|
|
2338
|
+
prevId ? [elem, value, prevId] : [elem, value]
|
|
2339
|
+
)
|
|
2340
|
+
}
|
|
2341
|
+
|
|
2342
|
+
if (dynamic && name === 'textContent') {
|
|
2343
|
+
if (config.hydratable) {
|
|
2344
|
+
return t__namespace.callExpression(registerImportMethod(path, 'setProperty'), [elem, t__namespace.stringLiteral('data'), value])
|
|
2345
|
+
}
|
|
2346
|
+
return t__namespace.assignmentExpression('=', t__namespace.memberExpression(elem, t__namespace.identifier('data')), value)
|
|
2347
|
+
}
|
|
2348
|
+
|
|
2349
|
+
const isChildProp = ChildProperties.has(name);
|
|
2350
|
+
const isProp = Properties.has(name);
|
|
2351
|
+
const alias = getPropAlias(name, tagName.toUpperCase());
|
|
2352
|
+
if (namespace !== 'attr' && (isChildProp || (!isSVG && isProp) || isCE || namespace === 'prop')) {
|
|
2353
|
+
if (isCE && !isChildProp && !isProp && namespace !== 'prop') name = toPropertyName(name);
|
|
2354
|
+
if (config.hydratable && namespace !== 'prop') {
|
|
2355
|
+
return t__namespace.callExpression(registerImportMethod(path, 'setProperty'), [elem, t__namespace.stringLiteral(name), value])
|
|
2356
|
+
}
|
|
2357
|
+
return t__namespace.assignmentExpression('=', t__namespace.memberExpression(elem, t__namespace.identifier(alias || name)), value)
|
|
2358
|
+
}
|
|
2359
|
+
|
|
2360
|
+
const isNameSpaced = name.indexOf(':') > -1;
|
|
2361
|
+
name = Aliases[name] || name;
|
|
2362
|
+
!isSVG && (name = name.toLowerCase());
|
|
2363
|
+
const ns = isNameSpaced && SVGNamespace[name.split(':')[0]];
|
|
2364
|
+
if (ns) {
|
|
2365
|
+
return t__namespace.callExpression(registerImportMethod(path, 'setAttributeNS', getRendererConfig(path, 'dom').moduleName), [
|
|
2366
|
+
elem,
|
|
2367
|
+
t__namespace.stringLiteral(ns),
|
|
2368
|
+
t__namespace.stringLiteral(name),
|
|
2369
|
+
value,
|
|
2370
|
+
])
|
|
2371
|
+
} else {
|
|
2372
|
+
return t__namespace.callExpression(registerImportMethod(path, 'setAttribute', getRendererConfig(path, 'dom').moduleName), [
|
|
2373
|
+
elem,
|
|
2374
|
+
t__namespace.stringLiteral(name),
|
|
2375
|
+
value,
|
|
2376
|
+
])
|
|
2377
|
+
}
|
|
2378
|
+
}
|
|
2379
|
+
|
|
2380
|
+
function detectResolvableEventHandler(attribute, handler) {
|
|
2381
|
+
while (t__namespace.isIdentifier(handler)) {
|
|
2382
|
+
const lookup = attribute.scope.getBinding(handler.name);
|
|
2383
|
+
if (lookup) {
|
|
2384
|
+
if (t__namespace.isVariableDeclarator(lookup.path.node)) {
|
|
2385
|
+
handler = lookup.path.node.init;
|
|
2386
|
+
} else if (t__namespace.isFunctionDeclaration(lookup.path.node)) {
|
|
2387
|
+
return true
|
|
2388
|
+
} else return false
|
|
2389
|
+
} else return false
|
|
2390
|
+
}
|
|
2391
|
+
return t__namespace.isFunction(handler)
|
|
2392
|
+
}
|
|
2393
|
+
|
|
2394
|
+
function transformAttributes(path, results) {
|
|
2395
|
+
const elem = results.id;
|
|
2396
|
+
let hasHydratableEvent = false;
|
|
2397
|
+
let children;
|
|
2398
|
+
let spreadExpr;
|
|
2399
|
+
let attributes = path.get('openingElement').get('attributes');
|
|
2400
|
+
const tagName = getTagName(path.node);
|
|
2401
|
+
const isSVG = SVGElements.has(tagName);
|
|
2402
|
+
const isCE = tagName.includes('-');
|
|
2403
|
+
const hasChildren = path.node.children.length > 0;
|
|
2404
|
+
const config = getConfig(path);
|
|
2405
|
+
|
|
2406
|
+
// preprocess spreads
|
|
2407
|
+
if (attributes.some((attribute) => t__namespace.isJSXSpreadAttribute(attribute.node))) {
|
|
2408
|
+
[attributes, spreadExpr] = processSpreads(path, attributes, {
|
|
2409
|
+
elem,
|
|
2410
|
+
isSVG,
|
|
2411
|
+
hasChildren,
|
|
2412
|
+
wrapConditionals: config.wrapConditionals,
|
|
2413
|
+
});
|
|
2414
|
+
path.get('openingElement').set(
|
|
2415
|
+
'attributes',
|
|
2416
|
+
attributes.map((a) => a.node)
|
|
2417
|
+
);
|
|
2418
|
+
// NOTE: can't be checked at compile time so add to compiled output
|
|
2419
|
+
hasHydratableEvent = true;
|
|
2420
|
+
}
|
|
2421
|
+
|
|
2422
|
+
// preprocess styles
|
|
2423
|
+
const styleAttribute = path
|
|
2424
|
+
.get('openingElement')
|
|
2425
|
+
.get('attributes')
|
|
2426
|
+
.find(
|
|
2427
|
+
(a) =>
|
|
2428
|
+
a.node.name &&
|
|
2429
|
+
a.node.name.name === 'style' &&
|
|
2430
|
+
t__namespace.isJSXExpressionContainer(a.node.value) &&
|
|
2431
|
+
t__namespace.isObjectExpression(a.node.value.expression) &&
|
|
2432
|
+
!a.node.value.expression.properties.some((p) => t__namespace.isSpreadElement(p))
|
|
2433
|
+
);
|
|
2434
|
+
if (styleAttribute) {
|
|
2435
|
+
let i = 0;
|
|
2436
|
+
const leading = styleAttribute.node.value.expression.leadingComments;
|
|
2437
|
+
styleAttribute.node.value.expression.properties.slice().forEach((p, index) => {
|
|
2438
|
+
if (!p.computed) {
|
|
2439
|
+
if (leading) p.value.leadingComments = leading;
|
|
2440
|
+
path
|
|
2441
|
+
.get('openingElement')
|
|
2442
|
+
.node.attributes.splice(
|
|
2443
|
+
styleAttribute.key + ++i,
|
|
2444
|
+
0,
|
|
2445
|
+
t__namespace.jsxAttribute(
|
|
2446
|
+
t__namespace.jsxNamespacedName(
|
|
2447
|
+
t__namespace.jsxIdentifier('style'),
|
|
2448
|
+
t__namespace.jsxIdentifier(t__namespace.isIdentifier(p.key) ? p.key.name : p.key.value)
|
|
2449
|
+
),
|
|
2450
|
+
t__namespace.jsxExpressionContainer(p.value)
|
|
2451
|
+
)
|
|
2452
|
+
);
|
|
2453
|
+
styleAttribute.node.value.expression.properties.splice(index - i - 1, 1);
|
|
2454
|
+
}
|
|
2455
|
+
});
|
|
2456
|
+
if (!styleAttribute.node.value.expression.properties.length) {
|
|
2457
|
+
path.get('openingElement').node.attributes.splice(styleAttribute.key, 1);
|
|
2458
|
+
}
|
|
2459
|
+
}
|
|
2460
|
+
|
|
2461
|
+
// preprocess classList
|
|
2462
|
+
attributes = path.get('openingElement').get('attributes');
|
|
2463
|
+
const classListAttribute = attributes.find(
|
|
2464
|
+
(a) =>
|
|
2465
|
+
a.node.name &&
|
|
2466
|
+
a.node.name.name === 'classList' &&
|
|
2467
|
+
t__namespace.isJSXExpressionContainer(a.node.value) &&
|
|
2468
|
+
t__namespace.isObjectExpression(a.node.value.expression) &&
|
|
2469
|
+
!a.node.value.expression.properties.some(
|
|
2470
|
+
(p) =>
|
|
2471
|
+
t__namespace.isSpreadElement(p) ||
|
|
2472
|
+
p.computed ||
|
|
2473
|
+
(t__namespace.isStringLiteral(p.key) && (p.key.value.includes(' ') || p.key.value.includes(':')))
|
|
2474
|
+
)
|
|
2475
|
+
);
|
|
2476
|
+
if (classListAttribute) {
|
|
2477
|
+
let i = 0;
|
|
2478
|
+
const leading = classListAttribute.node.value.expression.leadingComments;
|
|
2479
|
+
const classListProperties = classListAttribute.get('value').get('expression').get('properties');
|
|
2480
|
+
classListProperties.slice().forEach((propPath, index) => {
|
|
2481
|
+
const p = propPath.node;
|
|
2482
|
+
const { confident, value: computed } = propPath.get('value').evaluate();
|
|
2483
|
+
if (leading) p.value.leadingComments = leading;
|
|
2484
|
+
if (!confident) {
|
|
2485
|
+
path
|
|
2486
|
+
.get('openingElement')
|
|
2487
|
+
.node.attributes.splice(
|
|
2488
|
+
classListAttribute.key + ++i,
|
|
2489
|
+
0,
|
|
2490
|
+
t__namespace.jsxAttribute(
|
|
2491
|
+
t__namespace.jsxNamespacedName(
|
|
2492
|
+
t__namespace.jsxIdentifier('class'),
|
|
2493
|
+
t__namespace.jsxIdentifier(t__namespace.isIdentifier(p.key) ? p.key.name : p.key.value)
|
|
2494
|
+
),
|
|
2495
|
+
t__namespace.jsxExpressionContainer(p.value)
|
|
2496
|
+
)
|
|
2497
|
+
);
|
|
2498
|
+
} else if (computed) {
|
|
2499
|
+
path
|
|
2500
|
+
.get('openingElement')
|
|
2501
|
+
.node.attributes.splice(
|
|
2502
|
+
classListAttribute.key + ++i,
|
|
2503
|
+
0,
|
|
2504
|
+
t__namespace.jsxAttribute(t__namespace.jsxIdentifier('class'), t__namespace.stringLiteral(t__namespace.isIdentifier(p.key) ? p.key.name : p.key.value))
|
|
2505
|
+
);
|
|
2506
|
+
}
|
|
2507
|
+
classListProperties.splice(index - i - 1, 1);
|
|
2508
|
+
});
|
|
2509
|
+
if (!classListProperties.length) path.get('openingElement').node.attributes.splice(classListAttribute.key, 1);
|
|
2510
|
+
}
|
|
2511
|
+
|
|
2512
|
+
// combine class properties
|
|
2513
|
+
attributes = path.get('openingElement').get('attributes');
|
|
2514
|
+
const classAttributes = attributes.filter(
|
|
2515
|
+
(a) => a.node.name && (a.node.name.name === 'class' || a.node.name.name === 'className')
|
|
2516
|
+
);
|
|
2517
|
+
if (classAttributes.length > 1) {
|
|
2518
|
+
const first = classAttributes[0].node;
|
|
2519
|
+
const values = [];
|
|
2520
|
+
const quasis = [t__namespace.templateElement({ raw: '' })];
|
|
2521
|
+
for (let i = 0; i < classAttributes.length; i++) {
|
|
2522
|
+
const attr = classAttributes[i].node;
|
|
2523
|
+
const isLast = i === classAttributes.length - 1;
|
|
2524
|
+
if (!t__namespace.isJSXExpressionContainer(attr.value)) {
|
|
2525
|
+
const prev = quasis.pop();
|
|
2526
|
+
quasis.push(
|
|
2527
|
+
t__namespace.templateElement({
|
|
2528
|
+
raw: (prev ? prev.value.raw : '') + `${attr.value.value}` + (isLast ? '' : ' '),
|
|
2529
|
+
})
|
|
2530
|
+
);
|
|
2531
|
+
} else {
|
|
2532
|
+
values.push(t__namespace.logicalExpression('||', attr.value.expression, t__namespace.stringLiteral('')));
|
|
2533
|
+
quasis.push(t__namespace.templateElement({ raw: isLast ? '' : ' ' }));
|
|
2534
|
+
}
|
|
2535
|
+
i && attributes.splice(attributes.indexOf(classAttributes[i]), 1);
|
|
2536
|
+
}
|
|
2537
|
+
if (values.length) first.value = t__namespace.jsxExpressionContainer(t__namespace.templateLiteral(quasis, values));
|
|
2538
|
+
else first.value = t__namespace.stringLiteral(quasis[0].value.raw);
|
|
2539
|
+
}
|
|
2540
|
+
path.get('openingElement').set(
|
|
2541
|
+
'attributes',
|
|
2542
|
+
attributes.map((a) => a.node)
|
|
2543
|
+
);
|
|
2544
|
+
|
|
2545
|
+
let needsSpacing = true;
|
|
2546
|
+
|
|
2547
|
+
path
|
|
2548
|
+
.get('openingElement')
|
|
2549
|
+
.get('attributes')
|
|
2550
|
+
.forEach((attribute) => {
|
|
2551
|
+
const node = attribute.node;
|
|
2552
|
+
let value = node.value;
|
|
2553
|
+
let key = t__namespace.isJSXNamespacedName(node.name) ? `${node.name.namespace.name}:${node.name.name.name}` : node.name.name;
|
|
2554
|
+
const reservedNameSpace = t__namespace.isJSXNamespacedName(node.name) && reservedNameSpaces.has(node.name.namespace.name);
|
|
2555
|
+
if (t__namespace.isJSXExpressionContainer(value) && !key.startsWith('use:')) {
|
|
2556
|
+
const evaluated = attribute.get('value').get('expression').evaluate().value;
|
|
2557
|
+
let type;
|
|
2558
|
+
if (evaluated !== undefined && ((type = typeof evaluated) === 'string' || type === 'number')) {
|
|
2559
|
+
if (type === 'number' && (Properties.has(key) || key.startsWith('prop:'))) {
|
|
2560
|
+
value = t__namespace.jsxExpressionContainer(t__namespace.numericLiteral(evaluated));
|
|
2561
|
+
} else value = t__namespace.stringLiteral(String(evaluated));
|
|
2562
|
+
}
|
|
2563
|
+
}
|
|
2564
|
+
if (t__namespace.isJSXNamespacedName(node.name) && reservedNameSpace && !t__namespace.isJSXExpressionContainer(value)) {
|
|
2565
|
+
node.value = value = t__namespace.jsxExpressionContainer(value || t__namespace.jsxEmptyExpression());
|
|
2566
|
+
}
|
|
2567
|
+
if (
|
|
2568
|
+
t__namespace.isJSXExpressionContainer(value) &&
|
|
2569
|
+
(reservedNameSpace || !(t__namespace.isStringLiteral(value.expression) || t__namespace.isNumericLiteral(value.expression)))
|
|
2570
|
+
) {
|
|
2571
|
+
if (key === 'ref') {
|
|
2572
|
+
// Normalize expressions for non-null and type-as
|
|
2573
|
+
while (t__namespace.isTSNonNullExpression(value.expression) || t__namespace.isTSAsExpression(value.expression)) {
|
|
2574
|
+
value.expression = value.expression.expression;
|
|
2575
|
+
}
|
|
2576
|
+
let binding;
|
|
2577
|
+
const isFunction =
|
|
2578
|
+
t__namespace.isIdentifier(value.expression) &&
|
|
2579
|
+
(binding = path.scope.getBinding(value.expression.name)) &&
|
|
2580
|
+
binding.kind === 'const';
|
|
2581
|
+
if (!isFunction && t__namespace.isLVal(value.expression)) {
|
|
2582
|
+
const refIdentifier = path.scope.generateUidIdentifier('_ref$');
|
|
2583
|
+
results.exprs.unshift(
|
|
2584
|
+
t__namespace.variableDeclaration('var', [t__namespace.variableDeclarator(refIdentifier, value.expression)]),
|
|
2585
|
+
t__namespace.expressionStatement(
|
|
2586
|
+
t__namespace.conditionalExpression(
|
|
2587
|
+
t__namespace.binaryExpression('===', t__namespace.unaryExpression('typeof', refIdentifier), t__namespace.stringLiteral('function')),
|
|
2588
|
+
t__namespace.callExpression(registerImportMethod(path, 'use', getRendererConfig(path, 'dom').moduleName), [
|
|
2589
|
+
refIdentifier,
|
|
2590
|
+
elem,
|
|
2591
|
+
]),
|
|
2592
|
+
t__namespace.assignmentExpression('=', value.expression, elem)
|
|
2593
|
+
)
|
|
2594
|
+
)
|
|
2595
|
+
);
|
|
2596
|
+
} else if (isFunction || t__namespace.isFunction(value.expression)) {
|
|
2597
|
+
results.exprs.unshift(
|
|
2598
|
+
t__namespace.expressionStatement(
|
|
2599
|
+
t__namespace.callExpression(registerImportMethod(path, 'use', getRendererConfig(path, 'dom').moduleName), [
|
|
2600
|
+
value.expression,
|
|
2601
|
+
elem,
|
|
2602
|
+
])
|
|
2603
|
+
)
|
|
2604
|
+
);
|
|
2605
|
+
} else if (t__namespace.isCallExpression(value.expression)) {
|
|
2606
|
+
const refIdentifier = path.scope.generateUidIdentifier('_ref$');
|
|
2607
|
+
results.exprs.unshift(
|
|
2608
|
+
t__namespace.variableDeclaration('var', [t__namespace.variableDeclarator(refIdentifier, value.expression)]),
|
|
2609
|
+
t__namespace.expressionStatement(
|
|
2610
|
+
t__namespace.logicalExpression(
|
|
2611
|
+
'&&',
|
|
2612
|
+
t__namespace.binaryExpression('===', t__namespace.unaryExpression('typeof', refIdentifier), t__namespace.stringLiteral('function')),
|
|
2613
|
+
t__namespace.callExpression(registerImportMethod(path, 'use', getRendererConfig(path, 'dom').moduleName), [
|
|
2614
|
+
refIdentifier,
|
|
2615
|
+
elem,
|
|
2616
|
+
])
|
|
2617
|
+
)
|
|
2618
|
+
)
|
|
2619
|
+
);
|
|
2620
|
+
}
|
|
2621
|
+
} else if (key.startsWith('use:')) {
|
|
2622
|
+
// Some trick to treat JSXIdentifier as Identifier
|
|
2623
|
+
node.name.name.type = 'Identifier';
|
|
2624
|
+
results.exprs.unshift(
|
|
2625
|
+
t__namespace.expressionStatement(
|
|
2626
|
+
t__namespace.callExpression(registerImportMethod(path, 'use', getRendererConfig(path, 'dom').moduleName), [
|
|
2627
|
+
node.name.name,
|
|
2628
|
+
elem,
|
|
2629
|
+
t__namespace.arrowFunctionExpression(
|
|
2630
|
+
[],
|
|
2631
|
+
t__namespace.isJSXEmptyExpression(value.expression) ? t__namespace.booleanLiteral(true) : value.expression
|
|
2632
|
+
),
|
|
2633
|
+
])
|
|
2634
|
+
)
|
|
2635
|
+
);
|
|
2636
|
+
} else if (key === 'children') {
|
|
2637
|
+
children = value;
|
|
2638
|
+
} else if (key.startsWith('on')) {
|
|
2639
|
+
const ev = toEventName(key);
|
|
2640
|
+
if (key.startsWith('on:') || key.startsWith('oncapture:')) {
|
|
2641
|
+
const listenerOptions = [t__namespace.stringLiteral(key.split(':')[1]), value.expression];
|
|
2642
|
+
results.exprs.push(
|
|
2643
|
+
t__namespace.expressionStatement(
|
|
2644
|
+
t__namespace.callExpression(
|
|
2645
|
+
t__namespace.memberExpression(elem, t__namespace.identifier('addEventListener')),
|
|
2646
|
+
key.startsWith('oncapture:') ? listenerOptions.concat(t__namespace.booleanLiteral(true)) : listenerOptions
|
|
2647
|
+
)
|
|
2648
|
+
)
|
|
2649
|
+
);
|
|
2650
|
+
} else if (config.delegateEvents && (DelegatedEvents.has(ev) || config.delegatedEvents.indexOf(ev) !== -1)) {
|
|
2651
|
+
// can only hydrate delegated events
|
|
2652
|
+
hasHydratableEvent = true;
|
|
2653
|
+
const events =
|
|
2654
|
+
attribute.scope.getProgramParent().data.events ||
|
|
2655
|
+
(attribute.scope.getProgramParent().data.events = new Set());
|
|
2656
|
+
events.add(ev);
|
|
2657
|
+
let handler = value.expression;
|
|
2658
|
+
const resolveable = detectResolvableEventHandler(attribute, handler);
|
|
2659
|
+
if (t__namespace.isArrayExpression(handler)) {
|
|
2660
|
+
if (handler.elements.length > 1) {
|
|
2661
|
+
results.exprs.unshift(
|
|
2662
|
+
t__namespace.expressionStatement(
|
|
2663
|
+
t__namespace.assignmentExpression(
|
|
2664
|
+
'=',
|
|
2665
|
+
t__namespace.memberExpression(elem, t__namespace.identifier(`$$${ev}Data`)),
|
|
2666
|
+
handler.elements[1]
|
|
2667
|
+
)
|
|
2668
|
+
)
|
|
2669
|
+
);
|
|
2670
|
+
}
|
|
2671
|
+
handler = handler.elements[0];
|
|
2672
|
+
results.exprs.unshift(
|
|
2673
|
+
t__namespace.expressionStatement(
|
|
2674
|
+
t__namespace.assignmentExpression('=', t__namespace.memberExpression(elem, t__namespace.identifier(`$$${ev}`)), handler)
|
|
2675
|
+
)
|
|
2676
|
+
);
|
|
2677
|
+
} else if (t__namespace.isFunction(handler) || resolveable) {
|
|
2678
|
+
results.exprs.unshift(
|
|
2679
|
+
t__namespace.expressionStatement(
|
|
2680
|
+
t__namespace.assignmentExpression('=', t__namespace.memberExpression(elem, t__namespace.identifier(`$$${ev}`)), handler)
|
|
2681
|
+
)
|
|
2682
|
+
);
|
|
2683
|
+
} else {
|
|
2684
|
+
results.exprs.unshift(
|
|
2685
|
+
t__namespace.expressionStatement(
|
|
2686
|
+
t__namespace.callExpression(
|
|
2687
|
+
registerImportMethod(path, 'addEventListener', getRendererConfig(path, 'dom').moduleName),
|
|
2688
|
+
[elem, t__namespace.stringLiteral(ev), handler, t__namespace.booleanLiteral(true)]
|
|
2689
|
+
)
|
|
2690
|
+
)
|
|
2691
|
+
);
|
|
2692
|
+
}
|
|
2693
|
+
} else {
|
|
2694
|
+
let handler = value.expression;
|
|
2695
|
+
const resolveable = detectResolvableEventHandler(attribute, handler);
|
|
2696
|
+
if (t__namespace.isArrayExpression(handler)) {
|
|
2697
|
+
if (handler.elements.length > 1) {
|
|
2698
|
+
handler = t__namespace.arrowFunctionExpression(
|
|
2699
|
+
[t__namespace.identifier('e')],
|
|
2700
|
+
t__namespace.callExpression(handler.elements[0], [handler.elements[1], t__namespace.identifier('e')])
|
|
2701
|
+
);
|
|
2702
|
+
} else handler = handler.elements[0];
|
|
2703
|
+
results.exprs.unshift(
|
|
2704
|
+
t__namespace.expressionStatement(
|
|
2705
|
+
t__namespace.callExpression(t__namespace.memberExpression(elem, t__namespace.identifier('addEventListener')), [
|
|
2706
|
+
t__namespace.stringLiteral(ev),
|
|
2707
|
+
handler,
|
|
2708
|
+
])
|
|
2709
|
+
)
|
|
2710
|
+
);
|
|
2711
|
+
} else if (t__namespace.isFunction(handler) || resolveable) {
|
|
2712
|
+
results.exprs.unshift(
|
|
2713
|
+
t__namespace.expressionStatement(
|
|
2714
|
+
t__namespace.callExpression(t__namespace.memberExpression(elem, t__namespace.identifier('addEventListener')), [
|
|
2715
|
+
t__namespace.stringLiteral(ev),
|
|
2716
|
+
handler,
|
|
2717
|
+
])
|
|
2718
|
+
)
|
|
2719
|
+
);
|
|
2720
|
+
} else {
|
|
2721
|
+
results.exprs.unshift(
|
|
2722
|
+
t__namespace.expressionStatement(
|
|
2723
|
+
t__namespace.callExpression(
|
|
2724
|
+
registerImportMethod(path, 'addEventListener', getRendererConfig(path, 'dom').moduleName),
|
|
2725
|
+
[elem, t__namespace.stringLiteral(ev), handler]
|
|
2726
|
+
)
|
|
2727
|
+
)
|
|
2728
|
+
);
|
|
2729
|
+
}
|
|
2730
|
+
}
|
|
2731
|
+
} else if (
|
|
2732
|
+
config.effectWrapper &&
|
|
2733
|
+
(isDynamic(attribute.get('value').get('expression'), {
|
|
2734
|
+
checkMember: true,
|
|
2735
|
+
}) ||
|
|
2736
|
+
((key === 'classList' || key === 'style') &&
|
|
2737
|
+
!attribute.get('value').get('expression').evaluate().confident))
|
|
2738
|
+
) {
|
|
2739
|
+
let nextElem = elem;
|
|
2740
|
+
if (key === 'value' || key === 'checked') {
|
|
2741
|
+
const effectWrapperId = registerImportMethod(path, config.effectWrapper);
|
|
2742
|
+
results.postExprs.push(
|
|
2743
|
+
t__namespace.expressionStatement(
|
|
2744
|
+
t__namespace.callExpression(effectWrapperId, [
|
|
2745
|
+
t__namespace.arrowFunctionExpression(
|
|
2746
|
+
[],
|
|
2747
|
+
setAttr(path, elem, key, value.expression, {
|
|
2748
|
+
tagName,
|
|
2749
|
+
isSVG,
|
|
2750
|
+
isCE,
|
|
2751
|
+
})
|
|
2752
|
+
),
|
|
2753
|
+
])
|
|
2754
|
+
)
|
|
2755
|
+
);
|
|
2756
|
+
return
|
|
2757
|
+
}
|
|
2758
|
+
if (key === 'textContent') {
|
|
2759
|
+
nextElem = attribute.scope.generateUidIdentifier('el$');
|
|
2760
|
+
children = t__namespace.jsxText(' ');
|
|
2761
|
+
children.extra = { raw: ' ', rawValue: ' ' };
|
|
2762
|
+
results.declarations.push(
|
|
2763
|
+
t__namespace.variableDeclarator(nextElem, t__namespace.memberExpression(elem, t__namespace.identifier('firstChild')))
|
|
2764
|
+
);
|
|
2765
|
+
}
|
|
2766
|
+
results.dynamics.push({
|
|
2767
|
+
elem: nextElem,
|
|
2768
|
+
key,
|
|
2769
|
+
value: value.expression,
|
|
2770
|
+
isSVG,
|
|
2771
|
+
isCE,
|
|
2772
|
+
tagName,
|
|
2773
|
+
});
|
|
2774
|
+
} else {
|
|
2775
|
+
results.exprs.push(
|
|
2776
|
+
t__namespace.expressionStatement(setAttr(attribute, elem, key, value.expression, { isSVG, isCE, tagName }))
|
|
2777
|
+
);
|
|
2778
|
+
}
|
|
2779
|
+
} else {
|
|
2780
|
+
if (config.hydratable && key === '$ServerOnly') {
|
|
2781
|
+
results.skipTemplate = true;
|
|
2782
|
+
return
|
|
2783
|
+
}
|
|
2784
|
+
if (t__namespace.isJSXExpressionContainer(value)) value = value.expression;
|
|
2785
|
+
key = Aliases[key] || key;
|
|
2786
|
+
if (value && ChildProperties.has(key)) {
|
|
2787
|
+
results.exprs.push(t__namespace.expressionStatement(setAttr(attribute, elem, key, value, { isSVG, isCE, tagName })));
|
|
2788
|
+
} else {
|
|
2789
|
+
!isSVG && (key = key.toLowerCase());
|
|
2790
|
+
results.template += `${needsSpacing ? ' ' : ''}${key}`;
|
|
2791
|
+
if (!value) {
|
|
2792
|
+
needsSpacing = true;
|
|
2793
|
+
return
|
|
2794
|
+
}
|
|
2795
|
+
|
|
2796
|
+
let text = value.value;
|
|
2797
|
+
let needsQuoting = false;
|
|
2798
|
+
|
|
2799
|
+
if (key === 'style' || key === 'class') {
|
|
2800
|
+
text = trimWhitespace(text);
|
|
2801
|
+
if (key === 'style') {
|
|
2802
|
+
text = text.replace(/; /g, ';').replace(/: /g, ':');
|
|
2803
|
+
}
|
|
2804
|
+
}
|
|
2805
|
+
|
|
2806
|
+
if (!text.length) {
|
|
2807
|
+
needsSpacing = false;
|
|
2808
|
+
results.template += `=""`;
|
|
2809
|
+
return
|
|
2810
|
+
}
|
|
2811
|
+
|
|
2812
|
+
for (let i = 0, len = text.length; i < len; i++) {
|
|
2813
|
+
const char = text[i];
|
|
2814
|
+
|
|
2815
|
+
if (
|
|
2816
|
+
char === "'" ||
|
|
2817
|
+
char === '"' ||
|
|
2818
|
+
char === ' ' ||
|
|
2819
|
+
char === '\t' ||
|
|
2820
|
+
char === '\n' ||
|
|
2821
|
+
char === '\r' ||
|
|
2822
|
+
char === '`' ||
|
|
2823
|
+
char === '=' ||
|
|
2824
|
+
char === '<' ||
|
|
2825
|
+
char === '>'
|
|
2826
|
+
) {
|
|
2827
|
+
needsQuoting = true;
|
|
2828
|
+
}
|
|
2829
|
+
}
|
|
2830
|
+
|
|
2831
|
+
if (needsQuoting) {
|
|
2832
|
+
needsSpacing = false;
|
|
2833
|
+
results.template += `="${escapeHTML(text, true)}"`;
|
|
2834
|
+
} else {
|
|
2835
|
+
needsSpacing = true;
|
|
2836
|
+
results.template += `=${escapeHTML(text, true)}`;
|
|
2837
|
+
}
|
|
2838
|
+
}
|
|
2839
|
+
}
|
|
2840
|
+
});
|
|
2841
|
+
if (!hasChildren && children) {
|
|
2842
|
+
path.node.children.push(children);
|
|
2843
|
+
}
|
|
2844
|
+
if (spreadExpr) results.exprs.push(spreadExpr);
|
|
2845
|
+
|
|
2846
|
+
results.hasHydratableEvent = results.hasHydratableEvent || hasHydratableEvent;
|
|
2847
|
+
}
|
|
2848
|
+
|
|
2849
|
+
function findLastElement(children, hydratable) {
|
|
2850
|
+
let lastElement = -1;
|
|
2851
|
+
let tagName;
|
|
2852
|
+
for (let i = children.length - 1; i >= 0; i--) {
|
|
2853
|
+
const node = children[i].node;
|
|
2854
|
+
if (
|
|
2855
|
+
hydratable ||
|
|
2856
|
+
t__namespace.isJSXText(node) ||
|
|
2857
|
+
getStaticExpression(children[i]) !== false ||
|
|
2858
|
+
(t__namespace.isJSXElement(node) && (tagName = getTagName(node)) && !isComponent(tagName))
|
|
2859
|
+
) {
|
|
2860
|
+
lastElement = i;
|
|
2861
|
+
break
|
|
2862
|
+
}
|
|
2863
|
+
}
|
|
2864
|
+
return lastElement
|
|
2865
|
+
}
|
|
2866
|
+
|
|
2867
|
+
function transformChildren(path, results, config) {
|
|
2868
|
+
let tempPath = results.id && results.id.name;
|
|
2869
|
+
const tagName = getTagName(path.node);
|
|
2870
|
+
let nextPlaceholder;
|
|
2871
|
+
let i = 0;
|
|
2872
|
+
const filteredChildren = filterChildren(path.get('children'));
|
|
2873
|
+
const lastElement = findLastElement(filteredChildren, config.hydratable);
|
|
2874
|
+
const childNodes = filteredChildren.reduce((memo, child, index) => {
|
|
2875
|
+
if (child.isJSXFragment()) {
|
|
2876
|
+
throw new Error(`Fragments can only be used top level in JSX. Not used under a <${tagName}>.`)
|
|
2877
|
+
}
|
|
2878
|
+
const transformed = transformNode(child, {
|
|
2879
|
+
toBeClosed: results.toBeClosed,
|
|
2880
|
+
lastElement: index === lastElement,
|
|
2881
|
+
skipId: !results.id || !detectExpressions(filteredChildren, index, config),
|
|
2882
|
+
});
|
|
2883
|
+
if (!transformed) return memo
|
|
2884
|
+
const i = memo.length;
|
|
2885
|
+
if (transformed.text && i && memo[i - 1].text) {
|
|
2886
|
+
memo[i - 1].template += transformed.template;
|
|
2887
|
+
} else memo.push(transformed);
|
|
2888
|
+
return memo
|
|
2889
|
+
}, []);
|
|
2890
|
+
|
|
2891
|
+
childNodes.forEach((child, index) => {
|
|
2892
|
+
if (!child) return
|
|
2893
|
+
if (child.tagName && child.renderer !== 'dom') {
|
|
2894
|
+
throw new Error(`<${child.tagName}> is not supported in <${tagName}>.
|
|
2895
|
+
Wrap the usage with a component that would render this element, eg. Canvas`)
|
|
2896
|
+
}
|
|
2897
|
+
|
|
2898
|
+
results.template += child.template;
|
|
2899
|
+
if (child.id) {
|
|
2900
|
+
if (child.tagName === 'head') {
|
|
2901
|
+
if (config.hydratable) {
|
|
2902
|
+
const createComponent = registerImportMethod(
|
|
2903
|
+
path,
|
|
2904
|
+
'createComponent',
|
|
2905
|
+
getRendererConfig(path, 'dom').moduleName
|
|
2906
|
+
);
|
|
2907
|
+
const NoHydration = registerImportMethod(path, 'NoHydration', getRendererConfig(path, 'dom').moduleName);
|
|
2908
|
+
results.exprs.push(
|
|
2909
|
+
t__namespace.expressionStatement(t__namespace.callExpression(createComponent, [NoHydration, t__namespace.objectExpression([])]))
|
|
2910
|
+
);
|
|
2911
|
+
}
|
|
2912
|
+
return
|
|
2913
|
+
}
|
|
2914
|
+
|
|
2915
|
+
let getNextMatch;
|
|
2916
|
+
if (config.hydratable && tagName === 'html') {
|
|
2917
|
+
getNextMatch = registerImportMethod(path, 'getNextMatch', getRendererConfig(path, 'dom').moduleName);
|
|
2918
|
+
}
|
|
2919
|
+
const walk = t__namespace.memberExpression(t__namespace.identifier(tempPath), t__namespace.identifier(i === 0 ? 'firstChild' : 'nextSibling'));
|
|
2920
|
+
results.declarations.push(
|
|
2921
|
+
t__namespace.variableDeclarator(
|
|
2922
|
+
child.id,
|
|
2923
|
+
config.hydratable && tagName === 'html'
|
|
2924
|
+
? t__namespace.callExpression(getNextMatch, [walk, t__namespace.stringLiteral(child.tagName)])
|
|
2925
|
+
: walk
|
|
2926
|
+
)
|
|
2927
|
+
);
|
|
2928
|
+
results.declarations.push(...child.declarations);
|
|
2929
|
+
results.exprs.push(...child.exprs);
|
|
2930
|
+
results.dynamics.push(...child.dynamics);
|
|
2931
|
+
results.postExprs.push(...child.postExprs);
|
|
2932
|
+
results.hasHydratableEvent = results.hasHydratableEvent || child.hasHydratableEvent;
|
|
2933
|
+
results.hasCustomElement = results.hasCustomElement || child.hasCustomElement;
|
|
2934
|
+
tempPath = child.id.name;
|
|
2935
|
+
nextPlaceholder = null;
|
|
2936
|
+
i++;
|
|
2937
|
+
} else if (child.exprs.length) {
|
|
2938
|
+
const insert = registerImportMethod(path, 'insert', getRendererConfig(path, 'dom').moduleName);
|
|
2939
|
+
const multi = checkLength(filteredChildren);
|
|
2940
|
+
const markers = config.hydratable && multi;
|
|
2941
|
+
// boxed by textNodes
|
|
2942
|
+
if (markers || wrappedByText(childNodes, index)) {
|
|
2943
|
+
let exprId, contentId;
|
|
2944
|
+
if (markers) tempPath = createPlaceholder(path, results, tempPath, i++, '$')[0].name;
|
|
2945
|
+
if (nextPlaceholder) {
|
|
2946
|
+
exprId = nextPlaceholder;
|
|
2947
|
+
} else {
|
|
2948
|
+
[exprId, contentId] = createPlaceholder(path, results, tempPath, i++, markers ? '/' : '');
|
|
2949
|
+
}
|
|
2950
|
+
if (!markers) nextPlaceholder = exprId;
|
|
2951
|
+
results.exprs.push(
|
|
2952
|
+
t__namespace.expressionStatement(
|
|
2953
|
+
t__namespace.callExpression(
|
|
2954
|
+
insert,
|
|
2955
|
+
contentId ? [results.id, child.exprs[0], exprId, contentId] : [results.id, child.exprs[0], exprId]
|
|
2956
|
+
)
|
|
2957
|
+
)
|
|
2958
|
+
);
|
|
2959
|
+
tempPath = exprId.name;
|
|
2960
|
+
} else if (multi) {
|
|
2961
|
+
results.exprs.push(
|
|
2962
|
+
t__namespace.expressionStatement(
|
|
2963
|
+
t__namespace.callExpression(insert, [results.id, child.exprs[0], nextChild(childNodes, index) || t__namespace.nullLiteral()])
|
|
2964
|
+
)
|
|
2965
|
+
);
|
|
2966
|
+
} else {
|
|
2967
|
+
results.exprs.push(t__namespace.expressionStatement(t__namespace.callExpression(insert, [results.id, child.exprs[0]])));
|
|
2968
|
+
}
|
|
2969
|
+
} else nextPlaceholder = null;
|
|
2970
|
+
});
|
|
2971
|
+
}
|
|
2972
|
+
|
|
2973
|
+
function createPlaceholder(path, results, tempPath, i, char) {
|
|
2974
|
+
const exprId = path.scope.generateUidIdentifier('el$');
|
|
2975
|
+
const config = getConfig(path);
|
|
2976
|
+
let contentId;
|
|
2977
|
+
results.template += `<!${char}>`;
|
|
2978
|
+
if (config.hydratable && char === '/') {
|
|
2979
|
+
contentId = path.scope.generateUidIdentifier('co$');
|
|
2980
|
+
results.declarations.push(
|
|
2981
|
+
t__namespace.variableDeclarator(
|
|
2982
|
+
t__namespace.arrayPattern([exprId, contentId]),
|
|
2983
|
+
t__namespace.callExpression(registerImportMethod(path, 'getNextMarker', getRendererConfig(path, 'dom').moduleName), [
|
|
2984
|
+
t__namespace.memberExpression(t__namespace.identifier(tempPath), t__namespace.identifier('nextSibling')),
|
|
2985
|
+
])
|
|
2986
|
+
)
|
|
2987
|
+
);
|
|
2988
|
+
} else {
|
|
2989
|
+
results.declarations.push(
|
|
2990
|
+
t__namespace.variableDeclarator(
|
|
2991
|
+
exprId,
|
|
2992
|
+
t__namespace.memberExpression(t__namespace.identifier(tempPath), t__namespace.identifier(i === 0 ? 'firstChild' : 'nextSibling'))
|
|
2993
|
+
)
|
|
2994
|
+
);
|
|
2995
|
+
}
|
|
2996
|
+
return [exprId, contentId]
|
|
2997
|
+
}
|
|
2998
|
+
|
|
2999
|
+
function nextChild(children, index) {
|
|
3000
|
+
return children[index + 1] && (children[index + 1].id || nextChild(children, index + 1))
|
|
3001
|
+
}
|
|
3002
|
+
|
|
3003
|
+
// reduce unnecessary refs
|
|
3004
|
+
function detectExpressions(children, index, config) {
|
|
3005
|
+
if (children[index - 1]) {
|
|
3006
|
+
const node = children[index - 1].node;
|
|
3007
|
+
if (
|
|
3008
|
+
t__namespace.isJSXExpressionContainer(node) &&
|
|
3009
|
+
!t__namespace.isJSXEmptyExpression(node.expression) &&
|
|
3010
|
+
getStaticExpression(children[index - 1]) === false
|
|
3011
|
+
) {
|
|
3012
|
+
return true
|
|
3013
|
+
}
|
|
3014
|
+
let tagName;
|
|
3015
|
+
if (t__namespace.isJSXElement(node) && (tagName = getTagName(node)) && isComponent(tagName)) return true
|
|
3016
|
+
}
|
|
3017
|
+
for (let i = index; i < children.length; i++) {
|
|
3018
|
+
const child = children[i].node;
|
|
3019
|
+
if (t__namespace.isJSXExpressionContainer(child)) {
|
|
3020
|
+
if (!t__namespace.isJSXEmptyExpression(child.expression) && getStaticExpression(children[i]) === false) return true
|
|
3021
|
+
} else if (t__namespace.isJSXElement(child)) {
|
|
3022
|
+
const tagName = getTagName(child);
|
|
3023
|
+
if (isComponent(tagName)) return true
|
|
3024
|
+
if (config.contextToCustomElements && (tagName === 'slot' || tagName.indexOf('-') > -1)) return true
|
|
3025
|
+
if (
|
|
3026
|
+
child.openingElement.attributes.some(
|
|
3027
|
+
(attr) =>
|
|
3028
|
+
t__namespace.isJSXSpreadAttribute(attr) ||
|
|
3029
|
+
['textContent', 'innerHTML', 'innerText'].includes(attr.name.name) ||
|
|
3030
|
+
(attr.name.namespace && attr.name.namespace.name === 'use') ||
|
|
3031
|
+
(t__namespace.isJSXExpressionContainer(attr.value) &&
|
|
3032
|
+
!(t__namespace.isStringLiteral(attr.value.expression) || t__namespace.isNumericLiteral(attr.value.expression)))
|
|
3033
|
+
)
|
|
3034
|
+
) {
|
|
3035
|
+
return true
|
|
3036
|
+
}
|
|
3037
|
+
const nextChildren = filterChildren(children[i].get('children'));
|
|
3038
|
+
if (nextChildren.length) if (detectExpressions(nextChildren, 0, config)) return true
|
|
3039
|
+
}
|
|
3040
|
+
}
|
|
3041
|
+
}
|
|
3042
|
+
|
|
3043
|
+
function contextToCustomElement(path, results) {
|
|
3044
|
+
results.exprs.push(
|
|
3045
|
+
t__namespace.expressionStatement(
|
|
3046
|
+
t__namespace.assignmentExpression(
|
|
3047
|
+
'=',
|
|
3048
|
+
t__namespace.memberExpression(results.id, t__namespace.identifier('_$owner')),
|
|
3049
|
+
t__namespace.callExpression(registerImportMethod(path, 'getOwner', getRendererConfig(path, 'dom').moduleName), [])
|
|
3050
|
+
)
|
|
3051
|
+
)
|
|
3052
|
+
);
|
|
3053
|
+
}
|
|
3054
|
+
|
|
3055
|
+
function processSpreads(path, attributes, { elem, isSVG, hasChildren, wrapConditionals }) {
|
|
3056
|
+
// TODO: skip but collect the names of any properties after the last spread to not overwrite them
|
|
3057
|
+
const filteredAttributes = [];
|
|
3058
|
+
const spreadArgs = [];
|
|
3059
|
+
let runningObject = [];
|
|
3060
|
+
let dynamicSpread = false;
|
|
3061
|
+
let firstSpread = false;
|
|
3062
|
+
attributes.forEach((attribute) => {
|
|
3063
|
+
const node = attribute.node;
|
|
3064
|
+
const key =
|
|
3065
|
+
!t__namespace.isJSXSpreadAttribute(node) &&
|
|
3066
|
+
(t__namespace.isJSXNamespacedName(node.name) ? `${node.name.namespace.name}:${node.name.name.name}` : node.name.name);
|
|
3067
|
+
if (t__namespace.isJSXSpreadAttribute(node)) {
|
|
3068
|
+
firstSpread = true;
|
|
3069
|
+
if (runningObject.length) {
|
|
3070
|
+
spreadArgs.push(t__namespace.objectExpression(runningObject));
|
|
3071
|
+
runningObject = [];
|
|
3072
|
+
}
|
|
3073
|
+
spreadArgs.push(
|
|
3074
|
+
isDynamic(attribute.get('argument'), {
|
|
3075
|
+
checkMember: true,
|
|
3076
|
+
}) && (dynamicSpread = true)
|
|
3077
|
+
? t__namespace.isCallExpression(node.argument) &&
|
|
3078
|
+
!node.argument.arguments.length &&
|
|
3079
|
+
!t__namespace.isCallExpression(node.argument.callee) &&
|
|
3080
|
+
!t__namespace.isMemberExpression(node.argument.callee)
|
|
3081
|
+
? node.argument.callee
|
|
3082
|
+
: t__namespace.arrowFunctionExpression([], node.argument)
|
|
3083
|
+
: node.argument
|
|
3084
|
+
);
|
|
3085
|
+
} else if (
|
|
3086
|
+
(firstSpread ||
|
|
3087
|
+
(t__namespace.isJSXExpressionContainer(node.value) &&
|
|
3088
|
+
isDynamic(attribute.get('value').get('expression'), { checkMember: true }))) &&
|
|
3089
|
+
canNativeSpread(key, { checkNameSpaces: true })
|
|
3090
|
+
) {
|
|
3091
|
+
const isContainer = t__namespace.isJSXExpressionContainer(node.value);
|
|
3092
|
+
const dynamic = isContainer && isDynamic(attribute.get('value').get('expression'), { checkMember: true });
|
|
3093
|
+
if (dynamic) {
|
|
3094
|
+
const id = convertJSXIdentifier(node.name);
|
|
3095
|
+
const expr =
|
|
3096
|
+
wrapConditionals &&
|
|
3097
|
+
(t__namespace.isLogicalExpression(node.value.expression) || t__namespace.isConditionalExpression(node.value.expression))
|
|
3098
|
+
? transformCondition(attribute.get('value').get('expression'), true)
|
|
3099
|
+
: t__namespace.arrowFunctionExpression([], node.value.expression);
|
|
3100
|
+
runningObject.push(
|
|
3101
|
+
t__namespace.objectMethod('get', id, [], t__namespace.blockStatement([t__namespace.returnStatement(expr.body)]), !t__namespace.isValidIdentifier(key))
|
|
3102
|
+
);
|
|
3103
|
+
} else {
|
|
3104
|
+
runningObject.push(
|
|
3105
|
+
t__namespace.objectProperty(
|
|
3106
|
+
t__namespace.stringLiteral(key),
|
|
3107
|
+
isContainer
|
|
3108
|
+
? node.value.expression
|
|
3109
|
+
: node.value || (Properties.has(key) ? t__namespace.booleanLiteral(true) : t__namespace.stringLiteral(''))
|
|
3110
|
+
)
|
|
3111
|
+
);
|
|
3112
|
+
}
|
|
3113
|
+
} else filteredAttributes.push(attribute);
|
|
3114
|
+
});
|
|
3115
|
+
|
|
3116
|
+
if (runningObject.length) {
|
|
3117
|
+
spreadArgs.push(t__namespace.objectExpression(runningObject));
|
|
3118
|
+
}
|
|
3119
|
+
|
|
3120
|
+
const props =
|
|
3121
|
+
spreadArgs.length === 1 && !dynamicSpread
|
|
3122
|
+
? spreadArgs[0]
|
|
3123
|
+
: t__namespace.callExpression(registerImportMethod(path, 'mergeProps'), spreadArgs);
|
|
3124
|
+
|
|
3125
|
+
return [
|
|
3126
|
+
filteredAttributes,
|
|
3127
|
+
t__namespace.expressionStatement(
|
|
3128
|
+
t__namespace.callExpression(registerImportMethod(path, 'spread', getRendererConfig(path, 'dom').moduleName), [
|
|
3129
|
+
elem,
|
|
3130
|
+
props,
|
|
3131
|
+
t__namespace.booleanLiteral(isSVG),
|
|
3132
|
+
t__namespace.booleanLiteral(hasChildren),
|
|
3133
|
+
])
|
|
3134
|
+
),
|
|
3135
|
+
]
|
|
3136
|
+
}
|
|
3137
|
+
|
|
3138
|
+
function createTemplate(path, result, wrap) {
|
|
3139
|
+
const config = getConfig(path);
|
|
3140
|
+
if (result.id) {
|
|
3141
|
+
registerTemplate(path, result);
|
|
3142
|
+
if (
|
|
3143
|
+
!(result.exprs.length || result.dynamics.length || result.postExprs.length) &&
|
|
3144
|
+
result.decl.declarations.length === 1
|
|
3145
|
+
) {
|
|
3146
|
+
return result.decl.declarations[0].init
|
|
3147
|
+
} else {
|
|
3148
|
+
return t__namespace.callExpression(
|
|
3149
|
+
t__namespace.arrowFunctionExpression(
|
|
3150
|
+
[],
|
|
3151
|
+
t__namespace.blockStatement([
|
|
3152
|
+
result.decl,
|
|
3153
|
+
...result.exprs.concat(
|
|
3154
|
+
wrapDynamics(path, result.dynamics) || [],
|
|
3155
|
+
result.postExprs || []
|
|
3156
|
+
),
|
|
3157
|
+
t__namespace.returnStatement(result.id)
|
|
3158
|
+
])
|
|
3159
|
+
),
|
|
3160
|
+
[]
|
|
3161
|
+
)
|
|
3162
|
+
}
|
|
3163
|
+
}
|
|
3164
|
+
if (wrap && result.dynamic && config.memoWrapper) {
|
|
3165
|
+
return t__namespace.callExpression(registerImportMethod(path, config.memoWrapper), [result.exprs[0]])
|
|
3166
|
+
}
|
|
3167
|
+
return result.exprs[0]
|
|
3168
|
+
}
|
|
3169
|
+
|
|
3170
|
+
function appendTemplates(path, templates) {
|
|
3171
|
+
const declarators = templates.map(template => {
|
|
3172
|
+
const tmpl = {
|
|
3173
|
+
cooked: template.template,
|
|
3174
|
+
raw: escapeStringForTemplate(template.template)
|
|
3175
|
+
};
|
|
3176
|
+
return t__namespace.variableDeclarator(
|
|
3177
|
+
template.id,
|
|
3178
|
+
t__namespace.addComment(
|
|
3179
|
+
t__namespace.callExpression(
|
|
3180
|
+
registerImportMethod(path, 'template', getRendererConfig(path, 'dom').moduleName),
|
|
3181
|
+
[t__namespace.templateLiteral([t__namespace.templateElement(tmpl, true)], [])].concat(
|
|
3182
|
+
template.isSVG || template.isCE
|
|
3183
|
+
? [t__namespace.booleanLiteral(template.isCE), t__namespace.booleanLiteral(template.isSVG)]
|
|
3184
|
+
: []
|
|
3185
|
+
)
|
|
3186
|
+
),
|
|
3187
|
+
'leading',
|
|
3188
|
+
'#__PURE__'
|
|
3189
|
+
)
|
|
3190
|
+
)
|
|
3191
|
+
});
|
|
3192
|
+
path.node.body.unshift(t__namespace.variableDeclaration('var', declarators));
|
|
3193
|
+
}
|
|
3194
|
+
|
|
3195
|
+
function registerTemplate(path, results) {
|
|
3196
|
+
const { hydratable } = getConfig(path);
|
|
3197
|
+
let decl;
|
|
3198
|
+
if (results.template.length) {
|
|
3199
|
+
let templateDef, templateId;
|
|
3200
|
+
if (!results.skipTemplate) {
|
|
3201
|
+
const templates =
|
|
3202
|
+
path.scope.getProgramParent().data.templates ||
|
|
3203
|
+
(path.scope.getProgramParent().data.templates = []);
|
|
3204
|
+
if ((templateDef = templates.find(t => t.template === results.template))) {
|
|
3205
|
+
templateId = templateDef.id;
|
|
3206
|
+
} else {
|
|
3207
|
+
templateId = path.scope.generateUidIdentifier('tmpl$');
|
|
3208
|
+
templates.push({
|
|
3209
|
+
id: templateId,
|
|
3210
|
+
template: results.template,
|
|
3211
|
+
isSVG: results.isSVG,
|
|
3212
|
+
isCE: results.hasCustomElement,
|
|
3213
|
+
renderer: 'dom'
|
|
3214
|
+
});
|
|
3215
|
+
}
|
|
3216
|
+
}
|
|
3217
|
+
decl = t__namespace.variableDeclarator(
|
|
3218
|
+
results.id,
|
|
3219
|
+
hydratable
|
|
3220
|
+
? t__namespace.callExpression(
|
|
3221
|
+
registerImportMethod(path, 'getNextElement', getRendererConfig(path, 'dom').moduleName),
|
|
3222
|
+
templateId ? [templateId] : []
|
|
3223
|
+
)
|
|
3224
|
+
: t__namespace.callExpression(templateId, [])
|
|
3225
|
+
);
|
|
3226
|
+
}
|
|
3227
|
+
results.declarations.unshift(decl);
|
|
3228
|
+
results.decl = t__namespace.variableDeclaration('var', results.declarations);
|
|
3229
|
+
}
|
|
3230
|
+
|
|
3231
|
+
function wrapDynamics(path, dynamics) {
|
|
3232
|
+
if (!dynamics.length) return
|
|
3233
|
+
const config = getConfig(path);
|
|
3234
|
+
|
|
3235
|
+
const effectWrapperId = registerImportMethod(path, config.effectWrapper);
|
|
3236
|
+
|
|
3237
|
+
if (dynamics.length === 1) {
|
|
3238
|
+
const prevValue =
|
|
3239
|
+
dynamics[0].key === 'classList' || dynamics[0].key === 'style'
|
|
3240
|
+
? t__namespace.identifier('_$p')
|
|
3241
|
+
: undefined;
|
|
3242
|
+
if (
|
|
3243
|
+
dynamics[0].key.startsWith('class:') &&
|
|
3244
|
+
!t__namespace.isBooleanLiteral(dynamics[0].value) &&
|
|
3245
|
+
!t__namespace.isUnaryExpression(dynamics[0].value)
|
|
3246
|
+
) {
|
|
3247
|
+
dynamics[0].value = t__namespace.unaryExpression('!', t__namespace.unaryExpression('!', dynamics[0].value));
|
|
3248
|
+
}
|
|
3249
|
+
|
|
3250
|
+
return t__namespace.expressionStatement(
|
|
3251
|
+
t__namespace.callExpression(effectWrapperId, [
|
|
3252
|
+
t__namespace.arrowFunctionExpression(
|
|
3253
|
+
prevValue ? [prevValue] : [],
|
|
3254
|
+
setAttr(path, dynamics[0].elem, dynamics[0].key, dynamics[0].value, {
|
|
3255
|
+
isSVG: dynamics[0].isSVG,
|
|
3256
|
+
isCE: dynamics[0].isCE,
|
|
3257
|
+
tagName: dynamics[0].tagName,
|
|
3258
|
+
dynamic: true,
|
|
3259
|
+
prevId: prevValue
|
|
3260
|
+
})
|
|
3261
|
+
)
|
|
3262
|
+
])
|
|
3263
|
+
)
|
|
3264
|
+
}
|
|
3265
|
+
|
|
3266
|
+
const prevId = t__namespace.identifier('_p$');
|
|
3267
|
+
|
|
3268
|
+
/** @type {t.VariableDeclarator[]} */
|
|
3269
|
+
const declarations = [];
|
|
3270
|
+
/** @type {t.ExpressionStatement[]} */
|
|
3271
|
+
const statements = [];
|
|
3272
|
+
/** @type {t.Identifier[]} */
|
|
3273
|
+
const properties = [];
|
|
3274
|
+
|
|
3275
|
+
dynamics.forEach(({ elem, key, value, isSVG, isCE, tagName }, index) => {
|
|
3276
|
+
const varIdent = path.scope.generateUidIdentifier('v$');
|
|
3277
|
+
|
|
3278
|
+
const propIdent = t__namespace.identifier(getNumberedId(index));
|
|
3279
|
+
const propMember = t__namespace.memberExpression(prevId, propIdent);
|
|
3280
|
+
|
|
3281
|
+
if (
|
|
3282
|
+
key.startsWith('class:') &&
|
|
3283
|
+
!t__namespace.isBooleanLiteral(value) &&
|
|
3284
|
+
!t__namespace.isUnaryExpression(value)
|
|
3285
|
+
) {
|
|
3286
|
+
value = t__namespace.unaryExpression('!', t__namespace.unaryExpression('!', value));
|
|
3287
|
+
}
|
|
3288
|
+
|
|
3289
|
+
properties.push(propIdent);
|
|
3290
|
+
declarations.push(t__namespace.variableDeclarator(varIdent, value));
|
|
3291
|
+
|
|
3292
|
+
if (key === 'classList' || key === 'style') {
|
|
3293
|
+
statements.push(
|
|
3294
|
+
t__namespace.expressionStatement(
|
|
3295
|
+
t__namespace.assignmentExpression(
|
|
3296
|
+
'=',
|
|
3297
|
+
propMember,
|
|
3298
|
+
setAttr(path, elem, key, varIdent, {
|
|
3299
|
+
isSVG,
|
|
3300
|
+
isCE,
|
|
3301
|
+
tagName,
|
|
3302
|
+
dynamic: true,
|
|
3303
|
+
prevId: propMember,
|
|
3304
|
+
}),
|
|
3305
|
+
),
|
|
3306
|
+
),
|
|
3307
|
+
);
|
|
3308
|
+
} else {
|
|
3309
|
+
const prev = key.startsWith('style:') ? varIdent : undefined;
|
|
3310
|
+
statements.push(
|
|
3311
|
+
t__namespace.expressionStatement(
|
|
3312
|
+
t__namespace.logicalExpression(
|
|
3313
|
+
'&&',
|
|
3314
|
+
t__namespace.binaryExpression('!==', varIdent, propMember),
|
|
3315
|
+
setAttr(
|
|
3316
|
+
path,
|
|
3317
|
+
elem,
|
|
3318
|
+
key,
|
|
3319
|
+
t__namespace.assignmentExpression('=', propMember, varIdent),
|
|
3320
|
+
{ isSVG, isCE, tagName, dynamic: true, prevId: prev },
|
|
3321
|
+
),
|
|
3322
|
+
),
|
|
3323
|
+
),
|
|
3324
|
+
);
|
|
3325
|
+
}
|
|
3326
|
+
});
|
|
3327
|
+
|
|
3328
|
+
return t__namespace.expressionStatement(
|
|
3329
|
+
t__namespace.callExpression(effectWrapperId, [
|
|
3330
|
+
t__namespace.arrowFunctionExpression(
|
|
3331
|
+
[prevId],
|
|
3332
|
+
t__namespace.blockStatement([
|
|
3333
|
+
t__namespace.variableDeclaration('var', declarations),
|
|
3334
|
+
...statements,
|
|
3335
|
+
t__namespace.returnStatement(prevId),
|
|
3336
|
+
]),
|
|
3337
|
+
),
|
|
3338
|
+
t__namespace.objectExpression(
|
|
3339
|
+
properties.map((id) => t__namespace.objectProperty(id, t__namespace.identifier('undefined'))),
|
|
3340
|
+
),
|
|
3341
|
+
]),
|
|
3342
|
+
)
|
|
3343
|
+
}
|
|
3344
|
+
|
|
3345
|
+
// add to the top/bottom of the module.
|
|
3346
|
+
var postprocess = (path) => {
|
|
3347
|
+
if (path.scope.data.events) {
|
|
3348
|
+
path.node.body.push(
|
|
3349
|
+
t__namespace.expressionStatement(
|
|
3350
|
+
t__namespace.callExpression(registerImportMethod(path, 'delegateEvents', getRendererConfig(path, 'dom').moduleName), [
|
|
3351
|
+
t__namespace.arrayExpression(Array.from(path.scope.data.events).map((e) => t__namespace.stringLiteral(e))),
|
|
3352
|
+
])
|
|
3353
|
+
)
|
|
3354
|
+
);
|
|
3355
|
+
}
|
|
3356
|
+
if (path.scope.data.templates?.length) {
|
|
3357
|
+
const domTemplates = path.scope.data.templates.filter((temp) => temp.renderer === 'dom');
|
|
3358
|
+
const ssrTemplates = path.scope.data.templates.filter((temp) => temp.renderer === 'ssr');
|
|
3359
|
+
domTemplates.length > 0 && appendTemplates(path, domTemplates);
|
|
3360
|
+
ssrTemplates.length > 0 && appendTemplates$1(path, ssrTemplates);
|
|
3361
|
+
}
|
|
3362
|
+
|
|
3363
|
+
const taroComponentsMap = getTaroComponentsMap(path);
|
|
3364
|
+
taroComponentsMap.clear();
|
|
3365
|
+
};
|
|
3366
|
+
|
|
3367
|
+
var config = {
|
|
3368
|
+
moduleName: 'dom',
|
|
3369
|
+
generate: 'dom',
|
|
3370
|
+
hydratable: false,
|
|
3371
|
+
delegateEvents: true,
|
|
3372
|
+
delegatedEvents: [],
|
|
3373
|
+
builtIns: [],
|
|
3374
|
+
requireImportSource: false,
|
|
3375
|
+
wrapConditionals: true,
|
|
3376
|
+
omitNestedClosingTags: false,
|
|
3377
|
+
contextToCustomElements: false,
|
|
3378
|
+
staticMarker: '@once',
|
|
3379
|
+
effectWrapper: 'effect',
|
|
3380
|
+
memoWrapper: 'memo',
|
|
3381
|
+
validate: true
|
|
3382
|
+
};
|
|
3383
|
+
|
|
3384
|
+
const { isValidHTMLNesting } = require('validate-html-nesting');
|
|
3385
|
+
|
|
3386
|
+
// From https://github.com/MananTank/babel-plugin-validate-jsx-nesting/blob/main/src/index.js
|
|
3387
|
+
const JSXValidator = {
|
|
3388
|
+
JSXElement(path) {
|
|
3389
|
+
const elName = path.node.openingElement.name;
|
|
3390
|
+
const parent = path.parent;
|
|
3391
|
+
if (!t__namespace.isJSXElement(parent) || !t__namespace.isJSXIdentifier(elName)) return
|
|
3392
|
+
const elTagName = elName.name;
|
|
3393
|
+
if (isComponent(elTagName)) return
|
|
3394
|
+
const parentElName = parent.openingElement.name;
|
|
3395
|
+
if (!t__namespace.isJSXIdentifier(parentElName)) return
|
|
3396
|
+
const parentElTagName = parentElName.name;
|
|
3397
|
+
if (!isComponent(parentElTagName)) {
|
|
3398
|
+
if (!isValidHTMLNesting(parentElTagName, elTagName)) {
|
|
3399
|
+
throw path.buildCodeFrameError(`Invalid JSX: <${elTagName}> cannot be child of <${parentElTagName}>`)
|
|
3400
|
+
}
|
|
3401
|
+
}
|
|
3402
|
+
},
|
|
3403
|
+
};
|
|
3404
|
+
|
|
3405
|
+
var preprocess = (path, { opts }) => {
|
|
3406
|
+
const merged = (path.hub.file.metadata.config = Object.assign({}, config, opts));
|
|
3407
|
+
const taroComponentsMap = (path.hub.file.metadata.taroComponentsMap ||= new Map());
|
|
3408
|
+
const lib = merged.requireImportSource;
|
|
3409
|
+
if (lib) {
|
|
3410
|
+
const comments = path.hub.file.ast.comments;
|
|
3411
|
+
let process = false;
|
|
3412
|
+
for (let i = 0; i < comments.length; i++) {
|
|
3413
|
+
const comment = comments[i];
|
|
3414
|
+
const index = comment.value.indexOf('@jsxImportSource');
|
|
3415
|
+
if (index > -1 && comment.value.slice(index).includes(lib)) {
|
|
3416
|
+
process = true;
|
|
3417
|
+
break
|
|
3418
|
+
}
|
|
3419
|
+
}
|
|
3420
|
+
if (!process) {
|
|
3421
|
+
path.skip();
|
|
3422
|
+
return
|
|
3423
|
+
}
|
|
3424
|
+
}
|
|
3425
|
+
for (const stmt of path.get('body')) {
|
|
3426
|
+
if (t__namespace.isImportDeclaration(stmt.node)) {
|
|
3427
|
+
if (isTaroComponent(stmt.node.source.value)) {
|
|
3428
|
+
stmt.node.specifiers.forEach((specifier) => {
|
|
3429
|
+
// 包体导出的变量名
|
|
3430
|
+
const importedName = specifier.imported.name;
|
|
3431
|
+
// 当前使用的变量名 防止别名
|
|
3432
|
+
// import { Button as MyButton } from '@tarojs/components'
|
|
3433
|
+
const localName = specifier.local.name;
|
|
3434
|
+
taroComponentsMap.set(localName, importedName);
|
|
3435
|
+
});
|
|
3436
|
+
}
|
|
3437
|
+
}
|
|
3438
|
+
}
|
|
3439
|
+
if (merged.validate) path.traverse(JSXValidator);
|
|
3440
|
+
};
|
|
3441
|
+
|
|
3442
|
+
var index = () => {
|
|
3443
|
+
return {
|
|
3444
|
+
name: 'JSX DOM Expressions',
|
|
3445
|
+
inherits: SyntaxJSX.default,
|
|
3446
|
+
visitor: {
|
|
3447
|
+
JSXElement: transformJSX,
|
|
3448
|
+
JSXFragment: transformJSX,
|
|
3449
|
+
Program: {
|
|
3450
|
+
enter: preprocess,
|
|
3451
|
+
exit: postprocess
|
|
3452
|
+
}
|
|
3453
|
+
}
|
|
3454
|
+
}
|
|
3455
|
+
};
|
|
3456
|
+
|
|
3457
|
+
module.exports = index;
|