@litsx/babel-preset-litsx 0.2.1 → 0.4.0
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/dist/index.cjs +8 -1
- package/dist/index.cjs.map +1 -1
- package/dist/internal/transform-litsx-components.cjs +625 -406
- package/dist/internal/transform-litsx-components.cjs.map +1 -1
- package/dist/internal/transform-litsx-renderer-props.cjs +399 -0
- package/dist/internal/transform-litsx-renderer-props.cjs.map +1 -0
- package/dist/pipeline.cjs +10 -1
- package/dist/pipeline.cjs.map +1 -1
- package/dist/shared/transform-litsx-element-candidates-JMFlPFXK.cjs +1170 -0
- package/dist/shared/transform-litsx-element-candidates-JMFlPFXK.cjs.map +1 -0
- package/package.json +10 -3
- package/src/internal/transform-litsx-components.js +82 -119
- package/src/internal/transform-litsx-element-candidates.js +1173 -0
- package/src/internal/transform-litsx-param-rewrites.js +1 -1
- package/src/internal/transform-litsx-program.js +32 -0
- package/src/internal/transform-litsx-render-body.js +113 -0
- package/src/internal/transform-litsx-renderer-calls.js +92 -0
- package/src/internal/transform-litsx-renderer-props.js +368 -0
- package/src/internal/transform-litsx-wrapper-utils.js +30 -1
- package/src/pipeline.js +3 -0
|
@@ -0,0 +1,399 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var jsxSyntaxPlugin = require('@babel/plugin-syntax-jsx');
|
|
6
|
+
var transformLitsxElementCandidates = require('../shared/transform-litsx-element-candidates-JMFlPFXK.cjs');
|
|
7
|
+
require('@babel/helper-plugin-utils');
|
|
8
|
+
require('@babel/traverse');
|
|
9
|
+
require('@litsx/babel-parser');
|
|
10
|
+
require('node:fs');
|
|
11
|
+
require('node:path');
|
|
12
|
+
require('@litsx/typescript-session');
|
|
13
|
+
require('./transform-litsx-properties.cjs');
|
|
14
|
+
require('module');
|
|
15
|
+
|
|
16
|
+
const KIND_TO_PREFIX = {
|
|
17
|
+
event: "@",
|
|
18
|
+
prop: ".",
|
|
19
|
+
bool: "?",
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
function decodeVirtualAttributeName(name) {
|
|
23
|
+
const match = /^__litsx_(event|prop|bool)_(.+)$/.exec(name);
|
|
24
|
+
|
|
25
|
+
if (!match) {
|
|
26
|
+
return null;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const [, kind, localName] = match;
|
|
30
|
+
return `${KIND_TO_PREFIX[kind]}${localName}`;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
let t;
|
|
34
|
+
|
|
35
|
+
function createHostReferenceExpression() {
|
|
36
|
+
return t.conditionalExpression(
|
|
37
|
+
t.binaryExpression(
|
|
38
|
+
"===",
|
|
39
|
+
t.unaryExpression("typeof", t.thisExpression(), true),
|
|
40
|
+
t.stringLiteral("undefined")
|
|
41
|
+
),
|
|
42
|
+
t.nullLiteral(),
|
|
43
|
+
t.thisExpression()
|
|
44
|
+
);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function stringifyJsxName(nameNode) {
|
|
48
|
+
if (t.isJSXIdentifier(nameNode)) {
|
|
49
|
+
return nameNode.name;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
if (t.isJSXMemberExpression(nameNode)) {
|
|
53
|
+
return `${stringifyJsxName(nameNode.object)}.${nameNode.property.name}`;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
if (t.isJSXNamespacedName(nameNode)) {
|
|
57
|
+
return `${nameNode.namespace.name}:${nameNode.name.name}`;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
return "unknown";
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
function getTag(node) {
|
|
64
|
+
const name = stringifyJsxName(node.name);
|
|
65
|
+
const isCapitalized =
|
|
66
|
+
name.charAt(0) === name.charAt(0).toUpperCase() &&
|
|
67
|
+
name.charAt(0) !== name.charAt(0).toLowerCase();
|
|
68
|
+
const isComponent =
|
|
69
|
+
node.name.type !== "JSXIdentifier" || isCapitalized || name.includes("-");
|
|
70
|
+
return { name, isComponent };
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
function unwrapExpression(node) {
|
|
74
|
+
let current = node;
|
|
75
|
+
|
|
76
|
+
while (current) {
|
|
77
|
+
if (t.isParenthesizedExpression?.(current)) {
|
|
78
|
+
current = current.expression;
|
|
79
|
+
continue;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
if (
|
|
83
|
+
t.isTSAsExpression?.(current) ||
|
|
84
|
+
t.isTSSatisfiesExpression?.(current) ||
|
|
85
|
+
t.isTypeCastExpression?.(current) ||
|
|
86
|
+
t.isTSNonNullExpression?.(current)
|
|
87
|
+
) {
|
|
88
|
+
current = current.expression;
|
|
89
|
+
continue;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
break;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
return current;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
function getFunctionNodeFromBinding(binding) {
|
|
99
|
+
if (!binding?.path) {
|
|
100
|
+
return null;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
if (binding.path.isFunctionDeclaration()) {
|
|
104
|
+
return binding.path.node;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
if (binding.path.isVariableDeclarator()) {
|
|
108
|
+
const init = unwrapExpression(binding.path.node.init);
|
|
109
|
+
if (t.isArrowFunctionExpression(init) || t.isFunctionExpression(init)) {
|
|
110
|
+
return init;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
return null;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
function mergeBooleanResults(results) {
|
|
118
|
+
return results.some(Boolean);
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
function jsxTreeNeedsRendererContext(node, scope, seenBindings = new Set()) {
|
|
122
|
+
if (!node) {
|
|
123
|
+
return false;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
if (t.isJSXFragment(node)) {
|
|
127
|
+
return mergeBooleanResults(
|
|
128
|
+
node.children.map((child) => jsxChildNeedsRendererContext(child, scope, seenBindings))
|
|
129
|
+
);
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
if (!t.isJSXElement(node)) {
|
|
133
|
+
return false;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
const { isComponent } = getTag(node.openingElement);
|
|
137
|
+
if (isComponent) {
|
|
138
|
+
return true;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
const childNeedsContext = mergeBooleanResults(
|
|
142
|
+
node.children.map((child) => jsxChildNeedsRendererContext(child, scope, seenBindings))
|
|
143
|
+
);
|
|
144
|
+
|
|
145
|
+
if (childNeedsContext) {
|
|
146
|
+
return true;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
return mergeBooleanResults(
|
|
150
|
+
node.openingElement.attributes.map((attr) => {
|
|
151
|
+
if (!t.isJSXAttribute(attr) || !t.isJSXExpressionContainer(attr.value)) {
|
|
152
|
+
return false;
|
|
153
|
+
}
|
|
154
|
+
return expressionNeedsRendererContext(attr.value.expression, scope, seenBindings);
|
|
155
|
+
})
|
|
156
|
+
);
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
function jsxChildNeedsRendererContext(child, scope, seenBindings) {
|
|
160
|
+
if (t.isJSXElement(child) || t.isJSXFragment(child)) {
|
|
161
|
+
return jsxTreeNeedsRendererContext(child, scope, seenBindings);
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
if (t.isJSXExpressionContainer(child)) {
|
|
165
|
+
return expressionNeedsRendererContext(child.expression, scope, seenBindings);
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
return false;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
function functionBodyNeedsRendererContext(body, scope, seenBindings = new Set()) {
|
|
172
|
+
if (!body) {
|
|
173
|
+
return false;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
if (t.isBlockStatement(body)) {
|
|
177
|
+
return mergeBooleanResults(
|
|
178
|
+
body.body.map((statement) => statementNeedsRendererContext(statement, scope, seenBindings))
|
|
179
|
+
);
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
return expressionNeedsRendererContext(body, scope, seenBindings);
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
function statementNeedsRendererContext(statement, scope, seenBindings) {
|
|
186
|
+
if (t.isReturnStatement(statement)) {
|
|
187
|
+
return expressionNeedsRendererContext(statement.argument, scope, seenBindings);
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
if (t.isIfStatement(statement)) {
|
|
191
|
+
return mergeBooleanResults([
|
|
192
|
+
statementNeedsRendererContext(statement.consequent, scope, seenBindings),
|
|
193
|
+
statement.alternate
|
|
194
|
+
? statementNeedsRendererContext(statement.alternate, scope, seenBindings)
|
|
195
|
+
: false,
|
|
196
|
+
]);
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
if (t.isBlockStatement(statement)) {
|
|
200
|
+
return functionBodyNeedsRendererContext(statement, scope, seenBindings);
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
return false;
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
function callExpressionNeedsRendererContext(node, scope, seenBindings) {
|
|
207
|
+
const callee = unwrapExpression(node.callee);
|
|
208
|
+
if (!t.isIdentifier(callee)) {
|
|
209
|
+
return false;
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
const binding = scope.getBinding(callee.name);
|
|
213
|
+
const functionNode = getFunctionNodeFromBinding(binding);
|
|
214
|
+
if (!functionNode) {
|
|
215
|
+
return false;
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
if (seenBindings.has(binding)) {
|
|
219
|
+
return false;
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
const nextSeenBindings = new Set(seenBindings);
|
|
223
|
+
nextSeenBindings.add(binding);
|
|
224
|
+
return functionBodyNeedsRendererContext(functionNode.body, binding.path.scope, nextSeenBindings);
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
function expressionNeedsRendererContext(node, scope, seenBindings = new Set()) {
|
|
228
|
+
const expression = unwrapExpression(node);
|
|
229
|
+
if (!expression) {
|
|
230
|
+
return false;
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
if (t.isJSXElement(expression) || t.isJSXFragment(expression)) {
|
|
234
|
+
return jsxTreeNeedsRendererContext(expression, scope, seenBindings);
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
if (t.isConditionalExpression(expression)) {
|
|
238
|
+
return mergeBooleanResults([
|
|
239
|
+
expressionNeedsRendererContext(expression.consequent, scope, seenBindings),
|
|
240
|
+
expressionNeedsRendererContext(expression.alternate, scope, seenBindings),
|
|
241
|
+
]);
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
if (t.isLogicalExpression(expression)) {
|
|
245
|
+
return mergeBooleanResults([
|
|
246
|
+
expressionNeedsRendererContext(expression.left, scope, seenBindings),
|
|
247
|
+
expressionNeedsRendererContext(expression.right, scope, seenBindings),
|
|
248
|
+
]);
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
if (t.isSequenceExpression(expression)) {
|
|
252
|
+
return mergeBooleanResults(
|
|
253
|
+
expression.expressions.map((part) => expressionNeedsRendererContext(part, scope, seenBindings))
|
|
254
|
+
);
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
if (t.isArrayExpression(expression)) {
|
|
258
|
+
return mergeBooleanResults(
|
|
259
|
+
expression.elements.filter(Boolean).map((part) => expressionNeedsRendererContext(part, scope, seenBindings))
|
|
260
|
+
);
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
if (t.isCallExpression(expression)) {
|
|
264
|
+
return callExpressionNeedsRendererContext(expression, scope, seenBindings);
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
return false;
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
function isBindableFunctionReference(expressionPath, options = {}) {
|
|
271
|
+
const expression = unwrapExpression(expressionPath.node);
|
|
272
|
+
if (
|
|
273
|
+
t.isArrowFunctionExpression(expression) ||
|
|
274
|
+
t.isFunctionExpression(expression)
|
|
275
|
+
) {
|
|
276
|
+
return functionBodyNeedsRendererContext(expression.body, expressionPath.scope);
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
if (t.isIdentifier(expression)) {
|
|
280
|
+
const binding = expressionPath.scope.getBinding(expression.name);
|
|
281
|
+
const functionNode = getFunctionNodeFromBinding(binding);
|
|
282
|
+
if (!functionNode) {
|
|
283
|
+
const programPath = expressionPath.findParent((entry) => entry.isProgram?.());
|
|
284
|
+
return transformLitsxElementCandidates.importedBindingNeedsRendererContext(
|
|
285
|
+
programPath,
|
|
286
|
+
expression.name,
|
|
287
|
+
options
|
|
288
|
+
);
|
|
289
|
+
}
|
|
290
|
+
return functionBodyNeedsRendererContext(functionNode.body, binding.path.scope, new Set([binding]));
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
return false;
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
function shouldBindRendererContext(attributePath, rawName, expressionPath, options = {}) {
|
|
297
|
+
if (typeof rawName !== "string" || rawName[0] !== ".") {
|
|
298
|
+
return false;
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
const openingElement = attributePath.parentPath;
|
|
302
|
+
if (!openingElement?.isJSXOpeningElement()) {
|
|
303
|
+
return false;
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
const { isComponent } = getTag(openingElement.node);
|
|
307
|
+
if (!isComponent) {
|
|
308
|
+
return false;
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
return isBindableFunctionReference(expressionPath, options);
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
function ensureRendererBindingImport(programPath) {
|
|
315
|
+
const bodyPaths = programPath.get("body");
|
|
316
|
+
const runtimeImports = bodyPaths.filter(
|
|
317
|
+
(path) =>
|
|
318
|
+
path.isImportDeclaration() &&
|
|
319
|
+
path.node.source.value === "@litsx/litsx/internal/runtime-render-context"
|
|
320
|
+
);
|
|
321
|
+
|
|
322
|
+
const importSpecifier = t.importSpecifier(
|
|
323
|
+
t.identifier("bindRendererContext"),
|
|
324
|
+
t.identifier("bindRendererContext")
|
|
325
|
+
);
|
|
326
|
+
|
|
327
|
+
for (const importPath of runtimeImports) {
|
|
328
|
+
const { specifiers } = importPath.node;
|
|
329
|
+
const hasImport = specifiers.some(
|
|
330
|
+
(specifier) =>
|
|
331
|
+
t.isImportSpecifier(specifier) &&
|
|
332
|
+
t.isIdentifier(specifier.imported, { name: "bindRendererContext" })
|
|
333
|
+
);
|
|
334
|
+
|
|
335
|
+
if (hasImport) {
|
|
336
|
+
return;
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
specifiers.push(importSpecifier);
|
|
340
|
+
return;
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
programPath.unshiftContainer("body", t.importDeclaration(
|
|
344
|
+
[importSpecifier],
|
|
345
|
+
t.stringLiteral("@litsx/litsx/internal/runtime-render-context")
|
|
346
|
+
));
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
function transformLitsxRendererProps(api) {
|
|
350
|
+
api.assertVersion?.(7);
|
|
351
|
+
t = api.types;
|
|
352
|
+
|
|
353
|
+
return {
|
|
354
|
+
name: "transform-litsx-renderer-props",
|
|
355
|
+
inherits: jsxSyntaxPlugin.default || jsxSyntaxPlugin,
|
|
356
|
+
visitor: {
|
|
357
|
+
Program: {
|
|
358
|
+
enter(_, state) {
|
|
359
|
+
state.__litsxNeedsRendererBindingImport = false;
|
|
360
|
+
},
|
|
361
|
+
exit(programPath, state) {
|
|
362
|
+
if (state.__litsxNeedsRendererBindingImport) {
|
|
363
|
+
ensureRendererBindingImport(programPath);
|
|
364
|
+
}
|
|
365
|
+
},
|
|
366
|
+
},
|
|
367
|
+
JSXAttribute(path, state) {
|
|
368
|
+
const { node } = path;
|
|
369
|
+
if (node.value?.type !== "JSXExpressionContainer") {
|
|
370
|
+
return;
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
const rawName = decodeVirtualAttributeName(node.name.name) ?? node.name.name;
|
|
374
|
+
const expressionPath = path.get("value.expression");
|
|
375
|
+
if (!expressionPath?.node) {
|
|
376
|
+
return;
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
if (!shouldBindRendererContext(path, rawName, expressionPath, {
|
|
380
|
+
filename: state.file?.opts?.filename || "",
|
|
381
|
+
})) {
|
|
382
|
+
return;
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
state.__litsxNeedsRendererBindingImport = true;
|
|
386
|
+
node.value.expression = t.callExpression(
|
|
387
|
+
t.identifier("bindRendererContext"),
|
|
388
|
+
[
|
|
389
|
+
createHostReferenceExpression(),
|
|
390
|
+
expressionPath.node,
|
|
391
|
+
]
|
|
392
|
+
);
|
|
393
|
+
},
|
|
394
|
+
},
|
|
395
|
+
};
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
exports.default = transformLitsxRendererProps;
|
|
399
|
+
//# sourceMappingURL=transform-litsx-renderer-props.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transform-litsx-renderer-props.cjs","sources":["../../../jsx-authoring/src/index.js","../../src/internal/transform-litsx-renderer-props.js"],"sourcesContent":["import MagicString from \"magic-string\";\n\nconst PREFIX_TO_KIND = {\n \"@\": \"event\",\n \".\": \"prop\",\n \"?\": \"bool\",\n};\n\nconst KIND_TO_PREFIX = {\n event: \"@\",\n prop: \".\",\n bool: \"?\",\n};\n\nconst ATTR_NAME_CHAR = /[\\w:-]/;\nconst TAG_NAME_START_CHAR = /[A-Za-z]/;\nconst TAG_NAME_CHAR = /[\\w:.-]/;\nconst MACRO_NAME_START_CHAR = /[A-Za-z$_]/;\nconst MACRO_NAME_CHAR = /[A-Za-z0-9$_]/;\n\nfunction isWhitespace(char) {\n return char === \" \" || char === \"\\t\" || char === \"\\n\" || char === \"\\r\";\n}\n\nfunction isReservedVirtualAttributeName(name) {\n return /^__litsx_(event|prop|bool)_/.test(name);\n}\n\nfunction sanitizeIdentifierTailChar(char) {\n return /[A-Za-z0-9$_]/.test(char) ? char : \"_\";\n}\n\nfunction encodeEditorVirtualAttributeName(name) {\n const prefix = name[0];\n const localName = name.slice(1);\n const encodedPrefix = prefix === \"@\" ? \"e\" : prefix === \".\" ? \"p\" : \"b\";\n return `${encodedPrefix}${Array.from(localName, sanitizeIdentifierTailChar).join(\"\")}`;\n}\n\nfunction encodeEditorStaticHoistName(originalName, macroName) {\n return `$${macroName}`;\n}\n\nfunction scanQuotedString(sourceText, start, quote) {\n let index = start + 1;\n\n while (index < sourceText.length) {\n const char = sourceText[index];\n if (char === \"\\\\\") {\n index += 2;\n continue;\n }\n if (char === quote) {\n return index + 1;\n }\n index += 1;\n }\n\n return index;\n}\n\nfunction scanLineComment(sourceText, start) {\n let index = start + 2;\n while (index < sourceText.length && sourceText[index] !== \"\\n\") {\n index += 1;\n }\n return index;\n}\n\nfunction scanBlockComment(sourceText, start) {\n let index = start + 2;\n while (index < sourceText.length) {\n if (sourceText[index] === \"*\" && sourceText[index + 1] === \"/\") {\n return index + 2;\n }\n index += 1;\n }\n return index;\n}\n\nfunction scanTemplateLiteral(sourceText, start) {\n let index = start + 1;\n\n while (index < sourceText.length) {\n const char = sourceText[index];\n if (char === \"\\\\\") {\n index += 2;\n continue;\n }\n if (char === \"`\") {\n return index + 1;\n }\n if (char === \"$\" && sourceText[index + 1] === \"{\") {\n index = scanBalancedBraces(sourceText, index + 1);\n continue;\n }\n index += 1;\n }\n\n return index;\n}\n\nfunction scanBalancedBraces(sourceText, start) {\n let depth = 0;\n let index = start;\n\n while (index < sourceText.length) {\n const char = sourceText[index];\n const next = sourceText[index + 1];\n\n if (char === \"'\" || char === \"\\\"\") {\n index = scanQuotedString(sourceText, index, char);\n continue;\n }\n\n if (char === \"`\") {\n index = scanTemplateLiteral(sourceText, index);\n continue;\n }\n\n if (char === \"/\" && next === \"/\") {\n index = scanLineComment(sourceText, index);\n continue;\n }\n\n if (char === \"/\" && next === \"*\") {\n index = scanBlockComment(sourceText, index);\n continue;\n }\n\n if (char === \"{\") {\n depth += 1;\n index += 1;\n continue;\n }\n\n if (char === \"}\") {\n depth -= 1;\n index += 1;\n if (depth <= 0) {\n return index;\n }\n continue;\n }\n\n index += 1;\n }\n\n return index;\n}\n\nfunction scanBalancedBracesWithJsx(sourceText, start, replacements, encodeAttributeName) {\n let depth = 0;\n let index = start;\n\n while (index < sourceText.length) {\n const char = sourceText[index];\n const next = sourceText[index + 1];\n\n if (char === \"'\" || char === \"\\\"\") {\n index = scanQuotedString(sourceText, index, char);\n continue;\n }\n\n if (char === \"`\") {\n index = scanTemplateLiteral(sourceText, index);\n continue;\n }\n\n if (char === \"/\" && next === \"/\") {\n index = scanLineComment(sourceText, index);\n continue;\n }\n\n if (char === \"/\" && next === \"*\") {\n index = scanBlockComment(sourceText, index);\n continue;\n }\n\n if (char === \"<\" && isLikelyJsxTagStart(sourceText, index)) {\n index = scanJsxElement(sourceText, index, replacements, encodeAttributeName);\n continue;\n }\n\n if (char === \"{\") {\n depth += 1;\n index += 1;\n continue;\n }\n\n if (char === \"}\") {\n depth -= 1;\n index += 1;\n if (depth <= 0) {\n return index;\n }\n continue;\n }\n\n index += 1;\n }\n\n return index;\n}\n\nfunction trimTrailingWhitespaceAndComments(sourceText) {\n let text = sourceText;\n let changed = true;\n\n while (changed) {\n changed = false;\n\n const trimmedWhitespace = text.replace(/\\s+$/u, \"\");\n if (trimmedWhitespace !== text) {\n text = trimmedWhitespace;\n changed = true;\n }\n\n const trimmedLineComment = text.replace(/\\/\\/[^\\n\\r]*$/u, \"\");\n if (trimmedLineComment !== text) {\n text = trimmedLineComment;\n changed = true;\n continue;\n }\n\n const trimmedBlockComment = text.replace(/\\/\\*[\\s\\S]*?\\*\\/$/u, \"\");\n if (trimmedBlockComment !== text) {\n text = trimmedBlockComment;\n changed = true;\n }\n }\n\n return text;\n}\n\nfunction previousSignificantIndex(sourceText, start) {\n let index = start - 1;\n while (index >= 0 && isWhitespace(sourceText[index])) {\n index -= 1;\n }\n return index;\n}\n\nfunction readPreviousWord(sourceText, endIndex) {\n let index = endIndex;\n while (index >= 0 && /[A-Za-z]/.test(sourceText[index])) {\n index -= 1;\n }\n return sourceText.slice(index + 1, endIndex + 1);\n}\n\nfunction isLikelyJsxTagStart(sourceText, index) {\n const next = sourceText[index + 1];\n if (!TAG_NAME_START_CHAR.test(next || \"\")) {\n return false;\n }\n\n const previousIndex = previousSignificantIndex(sourceText, index);\n if (previousIndex < 0) {\n return true;\n }\n\n const previousChar = sourceText[previousIndex];\n if (\"=({[,!?:;>&|\".includes(previousChar)) {\n return true;\n }\n\n const previousWord = readPreviousWord(sourceText, previousIndex);\n return [\"return\", \"case\", \"throw\", \"yield\", \"else\"].includes(previousWord);\n}\n\nfunction readJsxTagName(sourceText, start) {\n let index = start + 1;\n const isClosing = sourceText[index] === \"/\";\n\n if (isClosing) {\n index += 1;\n }\n\n if (!TAG_NAME_START_CHAR.test(sourceText[index] || \"\")) {\n return null;\n }\n\n const nameStart = index;\n\n while (index < sourceText.length && TAG_NAME_CHAR.test(sourceText[index])) {\n index += 1;\n }\n\n return {\n name: sourceText.slice(nameStart, index),\n isClosing,\n end: index,\n };\n}\n\nfunction scanJsxTag(sourceText, start, replacements, encodeAttributeName) {\n const tag = readJsxTagName(sourceText, start);\n\n if (!tag) {\n return {\n end: start + 1,\n tagName: null,\n isClosing: false,\n selfClosing: false,\n };\n }\n\n let index = tag.end;\n\n if (tag.isClosing) {\n while (index < sourceText.length) {\n if (sourceText[index] === \">\") {\n return {\n end: index + 1,\n tagName: tag.name,\n isClosing: true,\n selfClosing: false,\n };\n }\n\n index += 1;\n }\n\n return {\n end: index,\n tagName: tag.name,\n isClosing: true,\n selfClosing: false,\n };\n }\n\n function scanAttributeValue(valueStart) {\n let valueIndex = valueStart;\n\n while (valueIndex < sourceText.length && isWhitespace(sourceText[valueIndex])) {\n valueIndex += 1;\n }\n\n if (valueIndex >= sourceText.length) {\n return valueIndex;\n }\n\n const valueChar = sourceText[valueIndex];\n if (valueChar === \"{\") {\n return scanBalancedBracesWithJsx(\n sourceText,\n valueIndex,\n replacements,\n encodeAttributeName\n );\n }\n\n if (valueChar === \"'\" || valueChar === \"\\\"\") {\n return scanQuotedString(sourceText, valueIndex, valueChar);\n }\n\n while (\n valueIndex < sourceText.length &&\n !isWhitespace(sourceText[valueIndex]) &&\n sourceText[valueIndex] !== \">\" &&\n !(sourceText[valueIndex] === \"/\" && sourceText[valueIndex + 1] === \">\")\n ) {\n valueIndex += 1;\n }\n\n return valueIndex;\n }\n\n while (index < sourceText.length) {\n const char = sourceText[index];\n const next = sourceText[index + 1];\n\n if (char === \">\") {\n return {\n end: index + 1,\n tagName: tag.name,\n isClosing: false,\n selfClosing: false,\n };\n }\n\n if (char === \"/\" && next === \">\") {\n return {\n end: index + 2,\n tagName: tag.name,\n isClosing: false,\n selfClosing: true,\n };\n }\n\n if (isWhitespace(char)) {\n index += 1;\n continue;\n }\n\n if (char === \"{\") {\n index = scanBalancedBracesWithJsx(\n sourceText,\n index,\n replacements,\n encodeAttributeName\n );\n continue;\n }\n\n if (char === \"'\" || char === \"\\\"\") {\n index = scanQuotedString(sourceText, index, char);\n continue;\n }\n\n if (Object.hasOwn(PREFIX_TO_KIND, char) && ATTR_NAME_CHAR.test(next || \"\")) {\n const attrStart = index;\n index += 1;\n\n while (index < sourceText.length && ATTR_NAME_CHAR.test(sourceText[index])) {\n index += 1;\n }\n\n const originalName = sourceText.slice(attrStart, index);\n replacements.push({\n start: attrStart,\n end: index,\n originalName,\n replacement: encodeAttributeName(originalName),\n });\n\n while (index < sourceText.length && isWhitespace(sourceText[index])) {\n index += 1;\n }\n if (sourceText[index] === \"=\") {\n index = scanAttributeValue(index + 1);\n }\n continue;\n }\n\n const attrStart = index;\n while (\n index < sourceText.length &&\n !isWhitespace(sourceText[index]) &&\n sourceText[index] !== \"=\" &&\n sourceText[index] !== \">\" &&\n !(sourceText[index] === \"/\" && sourceText[index + 1] === \">\")\n ) {\n index += 1;\n }\n\n if (index === attrStart) {\n index += 1;\n continue;\n }\n\n while (index < sourceText.length && isWhitespace(sourceText[index])) {\n index += 1;\n }\n if (sourceText[index] === \"=\") {\n index = scanAttributeValue(index + 1);\n }\n }\n\n return {\n end: index,\n tagName: tag.name,\n isClosing: false,\n selfClosing: false,\n };\n}\n\nfunction scanJsxElement(sourceText, start, replacements, encodeAttributeName) {\n const openingTag = scanJsxTag(sourceText, start, replacements, encodeAttributeName);\n\n if (\n openingTag.isClosing ||\n openingTag.selfClosing ||\n !openingTag.tagName\n ) {\n return openingTag.end;\n }\n\n let index = openingTag.end;\n\n while (index < sourceText.length) {\n const char = sourceText[index];\n const next = sourceText[index + 1];\n\n if (char === \"'\" || char === \"\\\"\") {\n index = scanQuotedString(sourceText, index, char);\n continue;\n }\n\n if (char === \"`\") {\n index = scanTemplateLiteral(sourceText, index);\n continue;\n }\n\n if (char === \"/\" && next === \"/\") {\n index = scanLineComment(sourceText, index);\n continue;\n }\n\n if (char === \"/\" && next === \"*\") {\n index = scanBlockComment(sourceText, index);\n continue;\n }\n\n if (char === \"{\") {\n index = scanBalancedBracesWithJsx(\n sourceText,\n index,\n replacements,\n encodeAttributeName\n );\n continue;\n }\n\n if (char === \"<\") {\n const nestedTag = readJsxTagName(sourceText, index);\n\n if (!nestedTag) {\n index += 1;\n continue;\n }\n\n if (nestedTag.isClosing && nestedTag.name === openingTag.tagName) {\n return scanJsxTag(sourceText, index, replacements, encodeAttributeName).end;\n }\n\n if (!nestedTag.isClosing) {\n index = scanJsxElement(sourceText, index, replacements, encodeAttributeName);\n continue;\n }\n }\n\n index += 1;\n }\n\n return index;\n}\n\nexport function encodeVirtualAttributeName(name) {\n const prefix = name[0];\n const localName = name.slice(1);\n const kind = PREFIX_TO_KIND[prefix];\n\n if (!kind) {\n return name;\n }\n\n return `__litsx_${kind}_${localName}`;\n}\n\nexport function decodeVirtualAttributeName(name) {\n const match = /^__litsx_(event|prop|bool)_(.+)$/.exec(name);\n\n if (!match) {\n return null;\n }\n\n const [, kind, localName] = match;\n return `${KIND_TO_PREFIX[kind]}${localName}`;\n}\n\nexport function decodeVirtualStaticHoistName(name) {\n const match = /^__litsx_static_([A-Za-z$_][A-Za-z0-9$_]*)$/.exec(name);\n\n if (!match) {\n return null;\n }\n\n return `^${match[1]}`;\n}\n\nexport function remapVirtualText(text) {\n if (typeof text !== \"string\") {\n return text;\n }\n\n return text\n .replace(/__litsx_(event|prop|bool)_[\\w:-]+/g, (name) => (\n decodeVirtualAttributeName(name) ?? name\n ))\n .replace(/__litsx_static_[A-Za-z$_][A-Za-z0-9$_]*/g, (name) => (\n decodeVirtualStaticHoistName(name) ?? name\n ));\n}\n\nexport function looksLikeLitsxJsx(sourceText) {\n return (\n /<[\\w.-]+[^>]*\\s(?:[@.?][\\w:-]+)/m.test(sourceText) ||\n /(?:^|[;{}]\\s*)\\^[A-Za-z$_][A-Za-z0-9$_]*/m.test(sourceText) ||\n /^\\s*\\^[A-Za-z$_][A-Za-z0-9$_]*/m.test(sourceText)\n );\n}\n\nfunction isLikelyStaticMacroStart(sourceText, index) {\n const next = sourceText[index + 1];\n if (!MACRO_NAME_START_CHAR.test(next || \"\")) {\n return false;\n }\n\n const prefix = trimTrailingWhitespaceAndComments(sourceText.slice(0, index));\n if (!prefix) {\n return true;\n }\n\n const previousChar = prefix[prefix.length - 1];\n return previousChar === \";\" || previousChar === \"{\" || previousChar === \"}\";\n}\n\nfunction scanStaticMacro(sourceText, start, replacements, encodeMacroName) {\n let index = start + 1;\n\n while (index < sourceText.length && MACRO_NAME_CHAR.test(sourceText[index])) {\n index += 1;\n }\n\n const originalName = sourceText.slice(start, index);\n const macroName = originalName.slice(1);\n\n if (macroName === \"mixins\") {\n return index;\n }\n\n replacements.push({\n start,\n end: index,\n originalName,\n replacement: encodeMacroName(originalName, macroName),\n });\n\n return index;\n}\n\nexport function createVirtualLitsxJsxSource(sourceText, options = {}) {\n const strategy = options.strategy === \"editor\" ? \"editor\" : \"compiler\";\n const includeSourceMap = options.sourceMap === true;\n const encodeAttributeName =\n strategy === \"editor\"\n ? encodeEditorVirtualAttributeName\n : encodeVirtualAttributeName;\n const encodeMacroName =\n strategy === \"editor\"\n ? encodeEditorStaticHoistName\n : (_originalName, macroName) => `__litsx_static_${macroName}`;\n\n if (!sourceText || typeof sourceText !== \"string\") {\n return {\n code: sourceText,\n map: null,\n replacements: [],\n };\n }\n\n if (strategy === \"compiler\" && sourceText.includes(\"__litsx_\")) {\n return {\n code: sourceText,\n map: null,\n replacements: [],\n collision: true,\n };\n }\n\n if (!looksLikeLitsxJsx(sourceText)) {\n return {\n code: sourceText,\n map: null,\n replacements: [],\n };\n }\n\n const replacements = [];\n let index = 0;\n let braceDepth = 0;\n\n while (index < sourceText.length) {\n const char = sourceText[index];\n const next = sourceText[index + 1];\n\n if (char === \"'\" || char === \"\\\"\") {\n index = scanQuotedString(sourceText, index, char);\n continue;\n }\n\n if (char === \"`\") {\n index = scanTemplateLiteral(sourceText, index);\n continue;\n }\n\n if (char === \"/\" && next === \"/\") {\n index = scanLineComment(sourceText, index);\n continue;\n }\n\n if (char === \"/\" && next === \"*\") {\n index = scanBlockComment(sourceText, index);\n continue;\n }\n\n if (char === \"<\" && isLikelyJsxTagStart(sourceText, index)) {\n index = scanJsxElement(sourceText, index, replacements, encodeAttributeName);\n continue;\n }\n\n if (char === \"^\" && isLikelyStaticMacroStart(sourceText, index)) {\n index = scanStaticMacro(sourceText, index, replacements, encodeMacroName);\n continue;\n }\n\n if (char === \"{\") {\n braceDepth += 1;\n index += 1;\n continue;\n }\n\n if (char === \"}\") {\n braceDepth = Math.max(0, braceDepth - 1);\n index += 1;\n continue;\n }\n\n index += 1;\n }\n\n if (!replacements.length) {\n return {\n code: sourceText,\n map: null,\n replacements: [],\n };\n }\n\n let lastIndex = 0;\n let transformed = \"\";\n\n for (const replacement of replacements) {\n transformed += sourceText.slice(lastIndex, replacement.start);\n transformed += replacement.replacement;\n lastIndex = replacement.end;\n }\n\n transformed += sourceText.slice(lastIndex);\n\n return {\n code: transformed,\n map: includeSourceMap\n ? createVirtualLitsxJsxSourceMap(sourceText, replacements, {\n sourceFileName: options.sourceFileName,\n })\n : null,\n replacements,\n };\n}\n\nexport function createVirtualLitsxJsxSourceMap(\n sourceText,\n replacements = [],\n options = {}\n) {\n const editable = new MagicString(sourceText);\n applyVirtualAttributeReplacements(editable, replacements);\n\n return editable.generateMap({\n hires: true,\n source: options.sourceFileName,\n includeContent: true,\n });\n}\n\nfunction findReplacementByVirtualPosition(position, replacements) {\n let originalCursor = 0;\n let virtualCursor = 0;\n\n for (const replacement of replacements) {\n const untouchedLength = replacement.start - originalCursor;\n const replacementVirtualStart = virtualCursor + untouchedLength;\n const replacementVirtualEnd =\n replacementVirtualStart + replacement.replacement.length;\n\n if (position >= replacementVirtualStart && position < replacementVirtualEnd) {\n return {\n replacement,\n virtualStart: replacementVirtualStart,\n virtualEnd: replacementVirtualEnd,\n };\n }\n\n originalCursor = replacement.end;\n virtualCursor = replacementVirtualEnd;\n }\n\n return null;\n}\n\nexport function mapOriginalPositionToVirtual(position, replacements = []) {\n if (!replacements.length) {\n return position;\n }\n\n let offset = 0;\n\n for (const replacement of replacements) {\n if (position < replacement.start) {\n break;\n }\n\n const originalLength = replacement.end - replacement.start;\n const replacementLength = replacement.replacement.length;\n\n if (position < replacement.end) {\n return replacement.start + offset;\n }\n\n offset += replacementLength - originalLength;\n }\n\n return position + offset;\n}\n\nexport function remapTextSpanToOriginal(span, replacements = []) {\n if (!span || !replacements.length) {\n return span;\n }\n\n const startMapping = findReplacementByVirtualPosition(span.start, replacements);\n if (startMapping) {\n return {\n start: startMapping.replacement.start,\n length: startMapping.replacement.end - startMapping.replacement.start,\n };\n }\n\n let originalStart = span.start;\n let originalEnd = span.start + span.length;\n\n for (const replacement of replacements) {\n const originalLength = replacement.end - replacement.start;\n const replacementLength = replacement.replacement.length;\n const delta = originalLength - replacementLength;\n const virtualStart = mapOriginalPositionToVirtual(replacement.start, replacements);\n const virtualEnd = virtualStart + replacementLength;\n\n if (virtualEnd <= span.start) {\n originalStart += delta;\n originalEnd += delta;\n continue;\n }\n\n if (virtualStart < span.start) {\n originalStart = replacement.start;\n }\n\n if (virtualStart < span.start + span.length) {\n originalEnd += delta;\n }\n }\n\n return {\n start: originalStart,\n length: Math.max(0, originalEnd - originalStart),\n };\n}\n\nexport function remapVirtualPositionToOriginal(position, replacements = []) {\n const span = remapTextSpanToOriginal({ start: position, length: 0 }, replacements);\n return span.start;\n}\n\nexport const mapVirtualPositionToOriginal = remapVirtualPositionToOriginal;\n\nexport function applyVirtualAttributeReplacements(editable, replacements = []) {\n for (const replacement of replacements) {\n editable.overwrite(replacement.start, replacement.end, replacement.replacement);\n }\n}\n\nexport {\n isReservedVirtualAttributeName,\n};\n","import jsxSyntaxPlugin from \"@babel/plugin-syntax-jsx\";\nimport { decodeVirtualAttributeName } from \"@litsx/jsx-authoring\";\nimport { importedBindingNeedsRendererContext } from \"./transform-litsx-element-candidates.js\";\n\nlet t;\n\nfunction createHostReferenceExpression() {\n return t.conditionalExpression(\n t.binaryExpression(\n \"===\",\n t.unaryExpression(\"typeof\", t.thisExpression(), true),\n t.stringLiteral(\"undefined\")\n ),\n t.nullLiteral(),\n t.thisExpression()\n );\n}\n\nfunction stringifyJsxName(nameNode) {\n if (t.isJSXIdentifier(nameNode)) {\n return nameNode.name;\n }\n\n if (t.isJSXMemberExpression(nameNode)) {\n return `${stringifyJsxName(nameNode.object)}.${nameNode.property.name}`;\n }\n\n if (t.isJSXNamespacedName(nameNode)) {\n return `${nameNode.namespace.name}:${nameNode.name.name}`;\n }\n\n return \"unknown\";\n}\n\nfunction getTag(node) {\n const name = stringifyJsxName(node.name);\n const isCapitalized =\n name.charAt(0) === name.charAt(0).toUpperCase() &&\n name.charAt(0) !== name.charAt(0).toLowerCase();\n const isComponent =\n node.name.type !== \"JSXIdentifier\" || isCapitalized || name.includes(\"-\");\n return { name, isComponent };\n}\n\nfunction unwrapExpression(node) {\n let current = node;\n\n while (current) {\n if (t.isParenthesizedExpression?.(current)) {\n current = current.expression;\n continue;\n }\n\n if (\n t.isTSAsExpression?.(current) ||\n t.isTSSatisfiesExpression?.(current) ||\n t.isTypeCastExpression?.(current) ||\n t.isTSNonNullExpression?.(current)\n ) {\n current = current.expression;\n continue;\n }\n\n break;\n }\n\n return current;\n}\n\nfunction getFunctionNodeFromBinding(binding) {\n if (!binding?.path) {\n return null;\n }\n\n if (binding.path.isFunctionDeclaration()) {\n return binding.path.node;\n }\n\n if (binding.path.isVariableDeclarator()) {\n const init = unwrapExpression(binding.path.node.init);\n if (t.isArrowFunctionExpression(init) || t.isFunctionExpression(init)) {\n return init;\n }\n }\n\n return null;\n}\n\nfunction mergeBooleanResults(results) {\n return results.some(Boolean);\n}\n\nfunction jsxTreeNeedsRendererContext(node, scope, seenBindings = new Set()) {\n if (!node) {\n return false;\n }\n\n if (t.isJSXFragment(node)) {\n return mergeBooleanResults(\n node.children.map((child) => jsxChildNeedsRendererContext(child, scope, seenBindings))\n );\n }\n\n if (!t.isJSXElement(node)) {\n return false;\n }\n\n const { isComponent } = getTag(node.openingElement);\n if (isComponent) {\n return true;\n }\n\n const childNeedsContext = mergeBooleanResults(\n node.children.map((child) => jsxChildNeedsRendererContext(child, scope, seenBindings))\n );\n\n if (childNeedsContext) {\n return true;\n }\n\n return mergeBooleanResults(\n node.openingElement.attributes.map((attr) => {\n if (!t.isJSXAttribute(attr) || !t.isJSXExpressionContainer(attr.value)) {\n return false;\n }\n return expressionNeedsRendererContext(attr.value.expression, scope, seenBindings);\n })\n );\n}\n\nfunction jsxChildNeedsRendererContext(child, scope, seenBindings) {\n if (t.isJSXElement(child) || t.isJSXFragment(child)) {\n return jsxTreeNeedsRendererContext(child, scope, seenBindings);\n }\n\n if (t.isJSXExpressionContainer(child)) {\n return expressionNeedsRendererContext(child.expression, scope, seenBindings);\n }\n\n return false;\n}\n\nfunction functionBodyNeedsRendererContext(body, scope, seenBindings = new Set()) {\n if (!body) {\n return false;\n }\n\n if (t.isBlockStatement(body)) {\n return mergeBooleanResults(\n body.body.map((statement) => statementNeedsRendererContext(statement, scope, seenBindings))\n );\n }\n\n return expressionNeedsRendererContext(body, scope, seenBindings);\n}\n\nfunction statementNeedsRendererContext(statement, scope, seenBindings) {\n if (t.isReturnStatement(statement)) {\n return expressionNeedsRendererContext(statement.argument, scope, seenBindings);\n }\n\n if (t.isIfStatement(statement)) {\n return mergeBooleanResults([\n statementNeedsRendererContext(statement.consequent, scope, seenBindings),\n statement.alternate\n ? statementNeedsRendererContext(statement.alternate, scope, seenBindings)\n : false,\n ]);\n }\n\n if (t.isBlockStatement(statement)) {\n return functionBodyNeedsRendererContext(statement, scope, seenBindings);\n }\n\n return false;\n}\n\nfunction callExpressionNeedsRendererContext(node, scope, seenBindings) {\n const callee = unwrapExpression(node.callee);\n if (!t.isIdentifier(callee)) {\n return false;\n }\n\n const binding = scope.getBinding(callee.name);\n const functionNode = getFunctionNodeFromBinding(binding);\n if (!functionNode) {\n return false;\n }\n\n if (seenBindings.has(binding)) {\n return false;\n }\n\n const nextSeenBindings = new Set(seenBindings);\n nextSeenBindings.add(binding);\n return functionBodyNeedsRendererContext(functionNode.body, binding.path.scope, nextSeenBindings);\n}\n\nfunction expressionNeedsRendererContext(node, scope, seenBindings = new Set()) {\n const expression = unwrapExpression(node);\n if (!expression) {\n return false;\n }\n\n if (t.isJSXElement(expression) || t.isJSXFragment(expression)) {\n return jsxTreeNeedsRendererContext(expression, scope, seenBindings);\n }\n\n if (t.isConditionalExpression(expression)) {\n return mergeBooleanResults([\n expressionNeedsRendererContext(expression.consequent, scope, seenBindings),\n expressionNeedsRendererContext(expression.alternate, scope, seenBindings),\n ]);\n }\n\n if (t.isLogicalExpression(expression)) {\n return mergeBooleanResults([\n expressionNeedsRendererContext(expression.left, scope, seenBindings),\n expressionNeedsRendererContext(expression.right, scope, seenBindings),\n ]);\n }\n\n if (t.isSequenceExpression(expression)) {\n return mergeBooleanResults(\n expression.expressions.map((part) => expressionNeedsRendererContext(part, scope, seenBindings))\n );\n }\n\n if (t.isArrayExpression(expression)) {\n return mergeBooleanResults(\n expression.elements.filter(Boolean).map((part) => expressionNeedsRendererContext(part, scope, seenBindings))\n );\n }\n\n if (t.isCallExpression(expression)) {\n return callExpressionNeedsRendererContext(expression, scope, seenBindings);\n }\n\n return false;\n}\n\nfunction isBindableFunctionReference(expressionPath, options = {}) {\n const expression = unwrapExpression(expressionPath.node);\n if (\n t.isArrowFunctionExpression(expression) ||\n t.isFunctionExpression(expression)\n ) {\n return functionBodyNeedsRendererContext(expression.body, expressionPath.scope);\n }\n\n if (t.isIdentifier(expression)) {\n const binding = expressionPath.scope.getBinding(expression.name);\n const functionNode = getFunctionNodeFromBinding(binding);\n if (!functionNode) {\n const programPath = expressionPath.findParent((entry) => entry.isProgram?.());\n return importedBindingNeedsRendererContext(\n programPath,\n expression.name,\n options\n );\n }\n return functionBodyNeedsRendererContext(functionNode.body, binding.path.scope, new Set([binding]));\n }\n\n return false;\n}\n\nfunction shouldBindRendererContext(attributePath, rawName, expressionPath, options = {}) {\n if (typeof rawName !== \"string\" || rawName[0] !== \".\") {\n return false;\n }\n\n const openingElement = attributePath.parentPath;\n if (!openingElement?.isJSXOpeningElement()) {\n return false;\n }\n\n const { isComponent } = getTag(openingElement.node);\n if (!isComponent) {\n return false;\n }\n\n return isBindableFunctionReference(expressionPath, options);\n}\n\nfunction ensureRendererBindingImport(programPath) {\n const bodyPaths = programPath.get(\"body\");\n const runtimeImports = bodyPaths.filter(\n (path) =>\n path.isImportDeclaration() &&\n path.node.source.value === \"@litsx/litsx/internal/runtime-render-context\"\n );\n\n const importSpecifier = t.importSpecifier(\n t.identifier(\"bindRendererContext\"),\n t.identifier(\"bindRendererContext\")\n );\n\n for (const importPath of runtimeImports) {\n const { specifiers } = importPath.node;\n const hasImport = specifiers.some(\n (specifier) =>\n t.isImportSpecifier(specifier) &&\n t.isIdentifier(specifier.imported, { name: \"bindRendererContext\" })\n );\n\n if (hasImport) {\n return;\n }\n\n specifiers.push(importSpecifier);\n return;\n }\n\n programPath.unshiftContainer(\"body\", t.importDeclaration(\n [importSpecifier],\n t.stringLiteral(\"@litsx/litsx/internal/runtime-render-context\")\n ));\n}\n\nexport default function transformLitsxRendererProps(api) {\n api.assertVersion?.(7);\n t = api.types;\n\n return {\n name: \"transform-litsx-renderer-props\",\n inherits: jsxSyntaxPlugin.default || jsxSyntaxPlugin,\n visitor: {\n Program: {\n enter(_, state) {\n state.__litsxNeedsRendererBindingImport = false;\n },\n exit(programPath, state) {\n if (state.__litsxNeedsRendererBindingImport) {\n ensureRendererBindingImport(programPath);\n }\n },\n },\n JSXAttribute(path, state) {\n const { node } = path;\n if (node.value?.type !== \"JSXExpressionContainer\") {\n return;\n }\n\n const rawName = decodeVirtualAttributeName(node.name.name) ?? node.name.name;\n const expressionPath = path.get(\"value.expression\");\n if (!expressionPath?.node) {\n return;\n }\n\n if (!shouldBindRendererContext(path, rawName, expressionPath, {\n filename: state.file?.opts?.filename || \"\",\n })) {\n return;\n }\n\n state.__litsxNeedsRendererBindingImport = true;\n node.value.expression = t.callExpression(\n t.identifier(\"bindRendererContext\"),\n [\n createHostReferenceExpression(),\n expressionPath.node,\n ]\n );\n },\n },\n };\n}\n"],"names":["importedBindingNeedsRendererContext"],"mappings":";;;;;;;;;;;;;;;AAQA,MAAM,cAAc,GAAG;AACvB,EAAE,KAAK,EAAE,GAAG;AACZ,EAAE,IAAI,EAAE,GAAG;AACX,EAAE,IAAI,EAAE,GAAG;AACX,CAAC;;AA2hBM,SAAS,0BAA0B,CAAC,IAAI,EAAE;AACjD,EAAE,MAAM,KAAK,GAAG,kCAAkC,CAAC,IAAI,CAAC,IAAI,CAAC;;AAE7D,EAAE,IAAI,CAAC,KAAK,EAAE;AACd,IAAI,OAAO,IAAI;AACf,EAAE;;AAEF,EAAE,MAAM,G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ACA,SAAS;AACT,MAAM,CAAC;AACP,KAAK;AACL,GAAG;AACH;;;;"}
|
package/dist/pipeline.cjs
CHANGED
|
@@ -5,11 +5,18 @@ var transformLitsxScopedElements = require('@litsx/babel-plugin-transform-litsx-
|
|
|
5
5
|
var internal_transformLitsxDomRefs = require('./internal/transform-litsx-dom-refs.cjs');
|
|
6
6
|
var internal_transformLitsxHooks = require('./internal/transform-litsx-hooks.cjs');
|
|
7
7
|
var internal_transformLitsxComponents = require('./internal/transform-litsx-components.cjs');
|
|
8
|
+
var internal_transformLitsxRendererProps = require('./internal/transform-litsx-renderer-props.cjs');
|
|
8
9
|
var internal_transformLitsxProperties = require('./internal/transform-litsx-properties.cjs');
|
|
9
10
|
require('@litsx/babel-plugin-shared-hooks');
|
|
10
11
|
require('@babel/plugin-syntax-jsx');
|
|
11
|
-
require('
|
|
12
|
+
require('./shared/transform-litsx-element-candidates-JMFlPFXK.cjs');
|
|
13
|
+
require('@babel/helper-plugin-utils');
|
|
14
|
+
require('@babel/traverse');
|
|
15
|
+
require('@litsx/babel-parser');
|
|
16
|
+
require('node:fs');
|
|
17
|
+
require('node:path');
|
|
12
18
|
require('@litsx/typescript-session');
|
|
19
|
+
require('module');
|
|
13
20
|
|
|
14
21
|
const NATIVE_TRANSFORM_OPTION_KEYS = [
|
|
15
22
|
"defaultDomMode",
|
|
@@ -17,6 +24,7 @@ const NATIVE_TRANSFORM_OPTION_KEYS = [
|
|
|
17
24
|
"inMemoryFiles",
|
|
18
25
|
"typescriptSession",
|
|
19
26
|
"suppressNativeClassNameWarning",
|
|
27
|
+
"__litsxCompilationSession",
|
|
20
28
|
];
|
|
21
29
|
|
|
22
30
|
const HOOK_FEATURE_PATTERN = /\b(?:useOnConnect|useAfterUpdate|useOnCommit|useMemoValue|useStableCallback|useEvent|useEmit|usePrevious|useReducedState|useState|useControlledState|useAsyncState|useOptimistic|useExpose|useExternalStore|useHost|useHostContent|useSlot|useTextContent|useTransition|useDeferredValue|useStyle|useRef|useCallbackRef)\b/;
|
|
@@ -62,6 +70,7 @@ function shouldIncludeFeaturePlugin(sourceFeatures, key) {
|
|
|
62
70
|
|
|
63
71
|
function createLitsxPresetPlugins(options = {}, sourceFeatures = null) {
|
|
64
72
|
const plugins = [
|
|
73
|
+
[internal_transformLitsxRendererProps.default, options.transformLitsxRendererProps || {}],
|
|
65
74
|
[internal_transformLitsxComponents.default, normalizeTransformLitsxOptions(options)],
|
|
66
75
|
];
|
|
67
76
|
|
package/dist/pipeline.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pipeline.cjs","sources":["../src/pipeline.js"],"sourcesContent":["import transformJsxHtmlTemplate from \"@litsx/babel-plugin-transform-jsx-html-template\";\nimport transformLitsxScopedElements from \"@litsx/babel-plugin-transform-litsx-scoped-elements\";\nimport transformLitsxDomRefs from \"./internal/transform-litsx-dom-refs.js\";\nimport transformLitsxHooks from \"./internal/transform-litsx-hooks.js\";\nimport transformLitsxComponents from \"./internal/transform-litsx-components.js\";\n\nconst NATIVE_TRANSFORM_OPTION_KEYS = [\n \"defaultDomMode\",\n \"typeResolutionMode\",\n \"inMemoryFiles\",\n \"typescriptSession\",\n \"suppressNativeClassNameWarning\",\n];\n\nconst HOOK_FEATURE_PATTERN = /\\b(?:useOnConnect|useAfterUpdate|useOnCommit|useMemoValue|useStableCallback|useEvent|useEmit|usePrevious|useReducedState|useState|useControlledState|useAsyncState|useOptimistic|useExpose|useExternalStore|useHost|useHostContent|useSlot|useTextContent|useTransition|useDeferredValue|useStyle|useRef|useCallbackRef)\\b/;\nconst REF_FEATURE_PATTERN = /\\buseRef\\b|\\bref\\s*=/;\nconst SCOPED_ELEMENTS_PATTERN = /<\\s*(?:[A-Z][\\w.]*(?=[\\s/>])|[a-z][\\w]*-[\\w-]*(?=[\\s/>]))/;\nconst LIGHT_DOM_PATTERN = /\\^lightDom\\b/;\n\nexport function normalizeTransformLitsxOptions(options = {}) {\n const transformLitsxOptions = {\n ...(options.transformLitsx || {}),\n };\n\n for (const key of NATIVE_TRANSFORM_OPTION_KEYS) {\n if (Object.prototype.hasOwnProperty.call(options, key)) {\n transformLitsxOptions[key] = options[key];\n }\n }\n\n return transformLitsxOptions;\n}\n\nexport function detectLitsxSourceFeatures(source, options = {}) {\n const text = typeof source === \"string\" ? source : \"\";\n const transformOptions = normalizeTransformLitsxOptions(options);\n\n return {\n hooks: HOOK_FEATURE_PATTERN.test(text),\n domRefs: REF_FEATURE_PATTERN.test(text),\n scopedElements:\n transformOptions.defaultDomMode === \"light\" ||\n LIGHT_DOM_PATTERN.test(text) ||\n SCOPED_ELEMENTS_PATTERN.test(text),\n };\n}\n\nfunction shouldIncludeFeaturePlugin(sourceFeatures, key) {\n if (!sourceFeatures) {\n return true;\n }\n\n return sourceFeatures[key] === true;\n}\n\nexport function createLitsxPresetPlugins(options = {}, sourceFeatures = null) {\n const plugins = [\n [transformLitsxComponents, normalizeTransformLitsxOptions(options)],\n ];\n\n if (shouldIncludeFeaturePlugin(sourceFeatures, \"hooks\")) {\n plugins.push([transformLitsxHooks, options.transformLitsxHooks || {}]);\n }\n\n if (shouldIncludeFeaturePlugin(sourceFeatures, \"domRefs\")) {\n plugins.push([transformLitsxDomRefs, options.transformLitsxDomRefs || {}]);\n }\n\n if (shouldIncludeFeaturePlugin(sourceFeatures, \"scopedElements\")) {\n plugins.push([transformLitsxScopedElements, options.transformLitsxScopedElements || {}]);\n }\n\n if (options.jsxTemplate !== false) {\n if (options.jsxTemplateOptions && Object.keys(options.jsxTemplateOptions).length > 0) {\n plugins.push([transformJsxHtmlTemplate, options.jsxTemplateOptions]);\n } else {\n plugins.push(transformJsxHtmlTemplate);\n }\n }\n\n return plugins;\n}\n\nexport {\n default as transformLitsxComponents,\n createTransformFunctionToClassPlugin as createTransformLitsxComponentsPlugin,\n} from \"./internal/transform-litsx-components.js\";\nexport {\n setTypescriptModule,\n} from \"./internal/transform-litsx-properties.js\";\n"],"names":["transformLitsxComponents","transformLitsxHooks","transformLitsxDomRefs"],"mappings":"
|
|
1
|
+
{"version":3,"file":"pipeline.cjs","sources":["../src/pipeline.js"],"sourcesContent":["import transformJsxHtmlTemplate from \"@litsx/babel-plugin-transform-jsx-html-template\";\nimport transformLitsxScopedElements from \"@litsx/babel-plugin-transform-litsx-scoped-elements\";\nimport transformLitsxDomRefs from \"./internal/transform-litsx-dom-refs.js\";\nimport transformLitsxHooks from \"./internal/transform-litsx-hooks.js\";\nimport transformLitsxComponents from \"./internal/transform-litsx-components.js\";\nimport transformLitsxRendererProps from \"./internal/transform-litsx-renderer-props.js\";\n\nconst NATIVE_TRANSFORM_OPTION_KEYS = [\n \"defaultDomMode\",\n \"typeResolutionMode\",\n \"inMemoryFiles\",\n \"typescriptSession\",\n \"suppressNativeClassNameWarning\",\n \"__litsxCompilationSession\",\n];\n\nconst HOOK_FEATURE_PATTERN = /\\b(?:useOnConnect|useAfterUpdate|useOnCommit|useMemoValue|useStableCallback|useEvent|useEmit|usePrevious|useReducedState|useState|useControlledState|useAsyncState|useOptimistic|useExpose|useExternalStore|useHost|useHostContent|useSlot|useTextContent|useTransition|useDeferredValue|useStyle|useRef|useCallbackRef)\\b/;\nconst REF_FEATURE_PATTERN = /\\buseRef\\b|\\bref\\s*=/;\nconst SCOPED_ELEMENTS_PATTERN = /<\\s*(?:[A-Z][\\w.]*(?=[\\s/>])|[a-z][\\w]*-[\\w-]*(?=[\\s/>]))/;\nconst LIGHT_DOM_PATTERN = /\\^lightDom\\b/;\n\nexport function normalizeTransformLitsxOptions(options = {}) {\n const transformLitsxOptions = {\n ...(options.transformLitsx || {}),\n };\n\n for (const key of NATIVE_TRANSFORM_OPTION_KEYS) {\n if (Object.prototype.hasOwnProperty.call(options, key)) {\n transformLitsxOptions[key] = options[key];\n }\n }\n\n return transformLitsxOptions;\n}\n\nexport function detectLitsxSourceFeatures(source, options = {}) {\n const text = typeof source === \"string\" ? source : \"\";\n const transformOptions = normalizeTransformLitsxOptions(options);\n\n return {\n hooks: HOOK_FEATURE_PATTERN.test(text),\n domRefs: REF_FEATURE_PATTERN.test(text),\n scopedElements:\n transformOptions.defaultDomMode === \"light\" ||\n LIGHT_DOM_PATTERN.test(text) ||\n SCOPED_ELEMENTS_PATTERN.test(text),\n };\n}\n\nfunction shouldIncludeFeaturePlugin(sourceFeatures, key) {\n if (!sourceFeatures) {\n return true;\n }\n\n return sourceFeatures[key] === true;\n}\n\nexport function createLitsxPresetPlugins(options = {}, sourceFeatures = null) {\n const plugins = [\n [transformLitsxRendererProps, options.transformLitsxRendererProps || {}],\n [transformLitsxComponents, normalizeTransformLitsxOptions(options)],\n ];\n\n if (shouldIncludeFeaturePlugin(sourceFeatures, \"hooks\")) {\n plugins.push([transformLitsxHooks, options.transformLitsxHooks || {}]);\n }\n\n if (shouldIncludeFeaturePlugin(sourceFeatures, \"domRefs\")) {\n plugins.push([transformLitsxDomRefs, options.transformLitsxDomRefs || {}]);\n }\n\n if (shouldIncludeFeaturePlugin(sourceFeatures, \"scopedElements\")) {\n plugins.push([transformLitsxScopedElements, options.transformLitsxScopedElements || {}]);\n }\n\n if (options.jsxTemplate !== false) {\n if (options.jsxTemplateOptions && Object.keys(options.jsxTemplateOptions).length > 0) {\n plugins.push([transformJsxHtmlTemplate, options.jsxTemplateOptions]);\n } else {\n plugins.push(transformJsxHtmlTemplate);\n }\n }\n\n return plugins;\n}\n\nexport {\n default as transformLitsxComponents,\n createTransformFunctionToClassPlugin as createTransformLitsxComponentsPlugin,\n} from \"./internal/transform-litsx-components.js\";\nexport {\n setTypescriptModule,\n} from \"./internal/transform-litsx-properties.js\";\n"],"names":["transformLitsxRendererProps","transformLitsxComponents","transformLitsxHooks","transformLitsxDomRefs"],"mappings":";;;;;;;;;;;;;;;;;;;;AAOA,MAAM,4BAA4B,GAAG;AACrC,EAAE,gBAAgB;AAClB,EAAE,oBAAoB;AACtB,EAAE,eAAe;AACjB,EAAE,mBAAmB;AACrB,EAAE,gCAAgC;AAClC,EAAE,2BAA2B;AAC7B,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