@tamagui/compiler-core 0.0.0-bootstrap.0 → 3.0.0-beta.637.1

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.
Files changed (98) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +57 -1
  3. package/dist/cjs/ast.cjs +95 -0
  4. package/dist/cjs/contracts.cjs +62 -0
  5. package/dist/cjs/diagnostics.cjs +69 -0
  6. package/dist/cjs/evaluate.cjs +351 -0
  7. package/dist/cjs/graph.cjs +279 -0
  8. package/dist/cjs/hash.cjs +49 -0
  9. package/dist/cjs/index.cjs +44 -0
  10. package/dist/cjs/ir.cjs +33 -0
  11. package/dist/cjs/lower.cjs +225 -0
  12. package/dist/cjs/materialize.cjs +200 -0
  13. package/dist/cjs/normalize.cjs +622 -0
  14. package/dist/cjs/output.cjs +149 -0
  15. package/dist/cjs/planCache.cjs +224 -0
  16. package/dist/cjs/session.cjs +119 -0
  17. package/dist/cjs/yuku.cjs +159 -0
  18. package/dist/cjs/zero.cjs +387 -0
  19. package/dist/esm/ast.mjs +65 -0
  20. package/dist/esm/ast.mjs.map +1 -0
  21. package/dist/esm/contracts.mjs +34 -0
  22. package/dist/esm/contracts.mjs.map +1 -0
  23. package/dist/esm/diagnostics.mjs +44 -0
  24. package/dist/esm/diagnostics.mjs.map +1 -0
  25. package/dist/esm/evaluate.mjs +327 -0
  26. package/dist/esm/evaluate.mjs.map +1 -0
  27. package/dist/esm/graph.mjs +256 -0
  28. package/dist/esm/graph.mjs.map +1 -0
  29. package/dist/esm/hash.mjs +26 -0
  30. package/dist/esm/hash.mjs.map +1 -0
  31. package/dist/esm/index.mjs +30 -0
  32. package/dist/esm/ir.mjs +12 -0
  33. package/dist/esm/ir.mjs.map +1 -0
  34. package/dist/esm/lower.mjs +202 -0
  35. package/dist/esm/lower.mjs.map +1 -0
  36. package/dist/esm/materialize.mjs +179 -0
  37. package/dist/esm/materialize.mjs.map +1 -0
  38. package/dist/esm/normalize.mjs +596 -0
  39. package/dist/esm/normalize.mjs.map +1 -0
  40. package/dist/esm/output.mjs +119 -0
  41. package/dist/esm/output.mjs.map +1 -0
  42. package/dist/esm/planCache.mjs +194 -0
  43. package/dist/esm/planCache.mjs.map +1 -0
  44. package/dist/esm/session.mjs +99 -0
  45. package/dist/esm/session.mjs.map +1 -0
  46. package/dist/esm/yuku.mjs +136 -0
  47. package/dist/esm/yuku.mjs.map +1 -0
  48. package/dist/esm/zero.mjs +352 -0
  49. package/dist/esm/zero.mjs.map +1 -0
  50. package/package.json +42 -4
  51. package/src/ast.ts +86 -0
  52. package/src/contracts.ts +148 -0
  53. package/src/diagnostics.ts +96 -0
  54. package/src/evaluate.ts +497 -0
  55. package/src/graph.ts +347 -0
  56. package/src/hash.ts +36 -0
  57. package/src/index.ts +15 -0
  58. package/src/ir.ts +154 -0
  59. package/src/lower.ts +418 -0
  60. package/src/materialize.ts +330 -0
  61. package/src/normalize.ts +846 -0
  62. package/src/output.ts +175 -0
  63. package/src/planCache.ts +327 -0
  64. package/src/session.ts +172 -0
  65. package/src/yuku.ts +189 -0
  66. package/src/zero.ts +598 -0
  67. package/types/ast.d.ts +10 -0
  68. package/types/ast.d.ts.map +1 -0
  69. package/types/contracts.d.ts +97 -0
  70. package/types/contracts.d.ts.map +1 -0
  71. package/types/diagnostics.d.ts +31 -0
  72. package/types/diagnostics.d.ts.map +1 -0
  73. package/types/evaluate.d.ts +36 -0
  74. package/types/evaluate.d.ts.map +1 -0
  75. package/types/graph.d.ts +37 -0
  76. package/types/graph.d.ts.map +1 -0
  77. package/types/hash.d.ts +8 -0
  78. package/types/hash.d.ts.map +1 -0
  79. package/types/index.d.ts +16 -0
  80. package/types/index.d.ts.map +1 -0
  81. package/types/ir.d.ts +118 -0
  82. package/types/ir.d.ts.map +1 -0
  83. package/types/lower.d.ts +99 -0
  84. package/types/lower.d.ts.map +1 -0
  85. package/types/materialize.d.ts +104 -0
  86. package/types/materialize.d.ts.map +1 -0
  87. package/types/normalize.d.ts +8 -0
  88. package/types/normalize.d.ts.map +1 -0
  89. package/types/output.d.ts +32 -0
  90. package/types/output.d.ts.map +1 -0
  91. package/types/planCache.d.ts +113 -0
  92. package/types/planCache.d.ts.map +1 -0
  93. package/types/session.d.ts +44 -0
  94. package/types/session.d.ts.map +1 -0
  95. package/types/yuku.d.ts +4 -0
  96. package/types/yuku.d.ts.map +1 -0
  97. package/types/zero.d.ts +98 -0
  98. package/types/zero.d.ts.map +1 -0
@@ -0,0 +1,622 @@
1
+
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all) __defProp(target, name, {
8
+ get: all[name],
9
+ enumerable: true
10
+ });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
15
+ get: () => from[key],
16
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
17
+ });
18
+ }
19
+ return to;
20
+ };
21
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
22
+ var normalize_exports = {};
23
+ __export(normalize_exports, {
24
+ asAstNode: () => asAstNode,
25
+ declarationForName: () => declarationForName,
26
+ definitionFromDeclaration: () => definitionFromDeclaration,
27
+ nodeAtSpan: () => nodeAtSpan,
28
+ normalizeElements: () => normalizeElements
29
+ });
30
+ module.exports = __toCommonJS(normalize_exports);
31
+ var import_ast = require("./ast.cjs");
32
+ var import_contracts = require("./contracts.cjs");
33
+ var import_diagnostics = require("./diagnostics.cjs");
34
+ var import_ir = require("./ir.cjs");
35
+ function finalizeElement(base, entries, bailouts) {
36
+ if (bailouts.length === 0) {
37
+ return {
38
+ ...base,
39
+ complete: true,
40
+ entries,
41
+ bailouts: []
42
+ };
43
+ }
44
+ return {
45
+ ...base,
46
+ complete: false,
47
+ bailedEntries: entries,
48
+ bailouts
49
+ };
50
+ }
51
+ function definitionFromDeclaration(id, name, program, declaration) {
52
+ let identifier = declaration;
53
+ let initializer = null;
54
+ let constant = false;
55
+ if (declaration.type === "VariableDeclarator") {
56
+ identifier = (0, import_ast.childNode)(declaration, "id") ?? declaration;
57
+ initializer = (0, import_ast.childNode)(declaration, "init");
58
+ constant = !!(0, import_ast.findAstNode)(program, (node) => node.type === "VariableDeclaration" && node.kind === "const" && (0, import_ast.childNodes)(node, "declarations").some((candidate) => candidate.start === declaration.start));
59
+ } else if (declaration.type === "Identifier") {
60
+ const declarator = (0, import_ast.findAstNode)(program, (node) => node.type === "VariableDeclarator" && (0, import_ast.childNode)(node, "id")?.start === declaration.start);
61
+ if (declarator) {
62
+ initializer = (0, import_ast.childNode)(declarator, "init");
63
+ constant = !!(0, import_ast.findAstNode)(program, (node) => node.type === "VariableDeclaration" && node.kind === "const" && (0, import_ast.childNodes)(node, "declarations").some((candidate) => candidate.start === declarator.start));
64
+ }
65
+ }
66
+ return {
67
+ id: (0, import_contracts.resolvedModuleId)(id),
68
+ name,
69
+ start: identifier.start,
70
+ end: identifier.end,
71
+ initializer,
72
+ constant
73
+ };
74
+ }
75
+ function importBinding(program, localName) {
76
+ for (const statement of (0, import_ast.childNodes)(program, "body")) {
77
+ if (statement.type !== "ImportDeclaration") continue;
78
+ const source = (0, import_ast.childNode)(statement, "source");
79
+ const sourceValue = source && typeof source.value === "string" ? source.value : null;
80
+ if (!sourceValue) continue;
81
+ for (const specifier of (0, import_ast.childNodes)(statement, "specifiers")) {
82
+ if ((0, import_ast.identifierName)((0, import_ast.childNode)(specifier, "local")) !== localName) continue;
83
+ if (specifier.type === "ImportDefaultSpecifier") {
84
+ return {
85
+ source: sourceValue,
86
+ imported: "default"
87
+ };
88
+ }
89
+ if (specifier.type === "ImportNamespaceSpecifier") {
90
+ return {
91
+ source: sourceValue,
92
+ imported: "*"
93
+ };
94
+ }
95
+ const imported = (0, import_ast.childNode)(specifier, "imported");
96
+ const importedName = (0, import_ast.identifierName)(imported) ?? (typeof imported?.value === "string" ? imported.value : null);
97
+ return importedName ? {
98
+ source: sourceValue,
99
+ imported: importedName
100
+ } : null;
101
+ }
102
+ }
103
+ return null;
104
+ }
105
+ function asStaticValue(node) {
106
+ if (!node) return void 0;
107
+ if (node.type === "NullLiteral") return null;
108
+ if (node.type === "Literal" || node.type.endsWith("Literal")) {
109
+ const value = node.value;
110
+ if (typeof value === "string" || typeof value === "number" || typeof value === "boolean" || value === null) {
111
+ return value;
112
+ }
113
+ }
114
+ return void 0;
115
+ }
116
+ function elementValue(id, node) {
117
+ const staticValue = asStaticValue(node);
118
+ return staticValue === void 0 ? (0, import_contracts.expressionReference)(id, node) : {
119
+ kind: "static",
120
+ value: staticValue,
121
+ span: (0, import_contracts.spanOf)(id, node)
122
+ };
123
+ }
124
+ function symbolDefinition(definition) {
125
+ if (!definition) return null;
126
+ return {
127
+ id: definition.id,
128
+ name: definition.name,
129
+ span: {
130
+ id: definition.id,
131
+ start: definition.start,
132
+ end: definition.end
133
+ },
134
+ initializer: definition.initializer ? (0, import_contracts.expressionReference)(definition.id, definition.initializer) : null,
135
+ constant: definition.constant
136
+ };
137
+ }
138
+ function componentFromNode(candidate, id, program, imports, node, bailouts) {
139
+ const literal = asStaticValue(node);
140
+ if (typeof literal === "string") {
141
+ return {
142
+ kind: "intrinsic",
143
+ name: literal,
144
+ span: (0, import_contracts.spanOf)(id, node),
145
+ closingSpan: null,
146
+ definition: null,
147
+ provenance: null
148
+ };
149
+ }
150
+ if ((node.type === "MemberExpression" || node.type === "JSXMemberExpression") && node.computed !== true) {
151
+ const objectName = (0, import_ast.identifierName)((0, import_ast.childNode)(node, "object"));
152
+ const memberName = (0, import_ast.identifierName)((0, import_ast.childNode)(node, "property"));
153
+ const binding2 = objectName ? importBinding(program, objectName) : null;
154
+ if (memberName && binding2?.imported === "html") {
155
+ const provenance2 = (0, import_ir.hostImportProvenance)(imports, binding2.source, binding2.imported);
156
+ if (provenance2) {
157
+ return {
158
+ kind: "binding",
159
+ name: memberName,
160
+ span: (0, import_contracts.spanOf)(id, node),
161
+ closingSpan: null,
162
+ definition: null,
163
+ provenance: provenance2
164
+ };
165
+ }
166
+ }
167
+ }
168
+ const name = (0, import_ast.identifierName)(node);
169
+ if (!name) {
170
+ bailouts.push((0, import_diagnostics.localBailout)("local/unsupported-element-name", (0, import_contracts.spanOf)(id, node), `Element target ${node.type} is not a stable identifier or intrinsic tag`));
171
+ return null;
172
+ }
173
+ const intrinsic = /^[a-z]/.test(name);
174
+ const binding = intrinsic ? null : importBinding(program, name);
175
+ const provenance = binding ? (0, import_ir.hostImportProvenance)(imports, binding.source, binding.imported) : null;
176
+ const definition = intrinsic ? null : symbolDefinition(candidate.definitionOf(id, name));
177
+ if (!intrinsic && !definition && !provenance) {
178
+ bailouts.push((0, import_diagnostics.linkedBailout)("linked/unresolved-component-binding", (0, import_contracts.spanOf)(id, node), `Component binding ${name} has no linked definition`));
179
+ }
180
+ return {
181
+ kind: intrinsic ? "intrinsic" : "binding",
182
+ name,
183
+ span: (0, import_contracts.spanOf)(id, node),
184
+ closingSpan: null,
185
+ definition,
186
+ provenance
187
+ };
188
+ }
189
+ function jsxComponentNode(opening) {
190
+ return (0, import_ast.childNode)(opening, "name");
191
+ }
192
+ function jsxEntries(id, element, opening, bailouts) {
193
+ const entries = [];
194
+ for (const attribute of (0, import_ast.childNodes)(opening, "attributes")) {
195
+ if (attribute.type === "JSXSpreadAttribute") {
196
+ const argument = (0, import_ast.childNode)(attribute, "argument");
197
+ if (argument) {
198
+ entries.push({
199
+ kind: "spread",
200
+ span: (0, import_contracts.spanOf)(id, attribute),
201
+ value: (0, import_contracts.expressionReference)(id, argument)
202
+ });
203
+ }
204
+ continue;
205
+ }
206
+ if (attribute.type !== "JSXAttribute") continue;
207
+ const nameNode = (0, import_ast.childNode)(attribute, "name");
208
+ const name = (0, import_ast.identifierName)(nameNode);
209
+ if (!name) {
210
+ bailouts.push((0, import_diagnostics.localBailout)("local/unsupported-prop-key", (0, import_contracts.spanOf)(id, attribute), "Namespaced JSX attributes are not statically supported"));
211
+ continue;
212
+ }
213
+ const rawValue = (0, import_ast.childNode)(attribute, "value");
214
+ let value;
215
+ if (!rawValue) {
216
+ value = {
217
+ kind: "static",
218
+ value: true,
219
+ span: (0, import_contracts.spanOf)(id, attribute)
220
+ };
221
+ } else if (rawValue.type === "JSXExpressionContainer") {
222
+ const expression = (0, import_ast.childNode)(rawValue, "expression");
223
+ if (!expression || expression.type === "JSXEmptyExpression") {
224
+ bailouts.push((0, import_diagnostics.localBailout)("local/unsupported-expression", (0, import_contracts.spanOf)(id, rawValue), `JSX prop ${name} has no expression`));
225
+ continue;
226
+ }
227
+ value = elementValue(id, expression);
228
+ } else {
229
+ value = elementValue(id, rawValue);
230
+ }
231
+ entries.push({
232
+ kind: "prop",
233
+ name,
234
+ span: (0, import_contracts.spanOf)(id, attribute),
235
+ value
236
+ });
237
+ }
238
+ for (const child of (0, import_ast.childNodes)(element, "children")) {
239
+ let value;
240
+ if (child.type === "JSXText") {
241
+ if (typeof child.value !== "string" || child.value.trim() === "") continue;
242
+ value = {
243
+ kind: "static",
244
+ value: child.value,
245
+ span: (0, import_contracts.spanOf)(id, child)
246
+ };
247
+ } else if (child.type === "JSXExpressionContainer") {
248
+ const expression = (0, import_ast.childNode)(child, "expression");
249
+ value = !expression || expression.type === "JSXEmptyExpression" ? {
250
+ kind: "empty",
251
+ span: (0, import_contracts.spanOf)(id, child)
252
+ } : elementValue(id, expression);
253
+ } else if (child.type === "JSXElement" || child.type === "JSXFragment") {
254
+ value = {
255
+ kind: "element",
256
+ span: (0, import_contracts.spanOf)(id, child)
257
+ };
258
+ } else {
259
+ bailouts.push((0, import_diagnostics.localBailout)("local/unsupported-child", (0, import_contracts.spanOf)(id, child), `JSX child ${child.type} cannot be normalized`));
260
+ continue;
261
+ }
262
+ entries.push({
263
+ kind: "child",
264
+ span: (0, import_contracts.spanOf)(id, child),
265
+ value
266
+ });
267
+ }
268
+ return entries.sort((left, right) => left.span.start - right.span.start);
269
+ }
270
+ function propertyName(property) {
271
+ if (property.computed === true) return null;
272
+ const key = (0, import_ast.childNode)(property, "key");
273
+ const name = (0, import_ast.identifierName)(key);
274
+ if (name) return name;
275
+ const literal = asStaticValue(key);
276
+ return typeof literal === "string" || typeof literal === "number" ? String(literal) : null;
277
+ }
278
+ function runtimeChildEntries(id, program, node, bailouts) {
279
+ const rawNodes = node.type === "ArrayExpression" ? node.elements : null;
280
+ if (Array.isArray(rawNodes) && rawNodes.some((child) => child === null || !(0, import_ast.isAstNode)(child))) {
281
+ bailouts.push((0, import_diagnostics.localBailout)("local/unsupported-child", (0, import_contracts.spanOf)(id, node), "Sparse compiled children cannot be normalized without changing order"));
282
+ return [];
283
+ }
284
+ const nodes = Array.isArray(rawNodes) ? rawNodes.filter(import_ast.isAstNode) : [node];
285
+ return nodes.flatMap((child) => {
286
+ if (child.type === "SpreadElement") {
287
+ bailouts.push((0, import_diagnostics.localBailout)("local/unsupported-child", (0, import_contracts.spanOf)(id, child), "Spread children cannot be statically ordered"));
288
+ return [];
289
+ }
290
+ if (child.type === "CallExpression" && runtimeCall(program, child)) {
291
+ return [{
292
+ kind: "child",
293
+ span: (0, import_contracts.spanOf)(id, child),
294
+ value: {
295
+ kind: "element",
296
+ span: (0, import_contracts.spanOf)(id, child)
297
+ }
298
+ }];
299
+ }
300
+ return [{
301
+ kind: "child",
302
+ span: (0, import_contracts.spanOf)(id, child),
303
+ value: elementValue(id, child)
304
+ }];
305
+ });
306
+ }
307
+ function objectEntries(id, program, object, bailouts) {
308
+ const entries = [];
309
+ for (const property of (0, import_ast.childNodes)(object, "properties")) {
310
+ if (property.type === "SpreadElement") {
311
+ const argument = (0, import_ast.childNode)(property, "argument");
312
+ if (argument) {
313
+ const spread = {
314
+ kind: "spread",
315
+ span: (0, import_contracts.spanOf)(id, property),
316
+ value: (0, import_contracts.expressionReference)(id, argument)
317
+ };
318
+ entries.push(spread);
319
+ }
320
+ continue;
321
+ }
322
+ if (property.type !== "Property" && property.type !== "ObjectProperty") {
323
+ bailouts.push((0, import_diagnostics.localBailout)("local/unsupported-prop-key", (0, import_contracts.spanOf)(id, property), `Runtime props entry ${property.type} is not a data property`));
324
+ continue;
325
+ }
326
+ const name = propertyName(property);
327
+ const valueNode = (0, import_ast.childNode)(property, "value");
328
+ if (!name || !valueNode) {
329
+ bailouts.push((0, import_diagnostics.localBailout)("local/unsupported-prop-key", (0, import_contracts.spanOf)(id, property), "Computed runtime prop keys are not statically supported"));
330
+ continue;
331
+ }
332
+ if (name === "children") {
333
+ entries.push(...runtimeChildEntries(id, program, valueNode, bailouts));
334
+ continue;
335
+ }
336
+ const prop = {
337
+ kind: "prop",
338
+ name,
339
+ span: (0, import_contracts.spanOf)(id, property),
340
+ value: elementValue(id, valueNode)
341
+ };
342
+ entries.push(prop);
343
+ }
344
+ return entries;
345
+ }
346
+ function runtimeCall(program, call) {
347
+ const callee = (0, import_ast.childNode)(call, "callee");
348
+ if (!callee) return null;
349
+ const directName = (0, import_ast.identifierName)(callee);
350
+ if (directName) {
351
+ const provenance2 = importBinding(program, directName);
352
+ if (provenance2?.source === "react/jsx-runtime" && (provenance2.imported === "jsx" || provenance2.imported === "jsxs")) {
353
+ return { form: "jsx-runtime" };
354
+ }
355
+ if (provenance2?.source === "react" && provenance2.imported === "createElement") {
356
+ return { form: "create-element" };
357
+ }
358
+ }
359
+ if (callee.type !== "MemberExpression" || callee.computed === true) return null;
360
+ const objectName = (0, import_ast.identifierName)((0, import_ast.childNode)(callee, "object"));
361
+ const propertyName2 = (0, import_ast.identifierName)((0, import_ast.childNode)(callee, "property"));
362
+ if (propertyName2 !== "createElement" || !objectName) return null;
363
+ const provenance = importBinding(program, objectName);
364
+ return provenance?.source === "react" && (provenance.imported === "default" || provenance.imported === "*") ? { form: "create-element" } : null;
365
+ }
366
+ function normalizeRuntimeElement(candidate, id, program, imports, call, runtime, bailouts) {
367
+ const bailoutStart = bailouts.length;
368
+ const args = (0, import_ast.childNodes)(call, "arguments");
369
+ const target = args[0];
370
+ if (!target) {
371
+ bailouts.push((0, import_diagnostics.localBailout)("local/invalid-element-call", (0, import_contracts.spanOf)(id, call), `${runtime.form} call has no element target`));
372
+ return null;
373
+ }
374
+ const component = componentFromNode(candidate, id, program, imports, target, bailouts);
375
+ if (!component) return null;
376
+ const entries = [];
377
+ const props = args[1];
378
+ if (props && asStaticValue(props) !== null) {
379
+ if (props.type === "ObjectExpression") {
380
+ entries.push(...objectEntries(id, program, props, bailouts));
381
+ } else {
382
+ entries.push({
383
+ kind: "spread",
384
+ span: (0, import_contracts.spanOf)(id, props),
385
+ value: (0, import_contracts.expressionReference)(id, props)
386
+ });
387
+ }
388
+ }
389
+ if (runtime.form === "create-element") {
390
+ for (const child of args.slice(2)) {
391
+ entries.push(...runtimeChildEntries(id, program, child, bailouts));
392
+ }
393
+ }
394
+ return finalizeElement({
395
+ kind: "element",
396
+ form: runtime.form,
397
+ id,
398
+ span: (0, import_contracts.spanOf)(id, call),
399
+ propsSpan: props ? (0, import_contracts.spanOf)(id, props) : null,
400
+ component
401
+ }, entries.sort((left, right) => left.span.start - right.span.start), bailouts.slice(bailoutStart));
402
+ }
403
+ function styledDefinitions(candidate, id, program, imports, bailouts) {
404
+ const definitions = [];
405
+ (0, import_ast.walkAst)(program, (node) => {
406
+ if (node.type !== "VariableDeclarator") return;
407
+ const identifier = (0, import_ast.childNode)(node, "id");
408
+ const name = (0, import_ast.identifierName)(identifier);
409
+ const call = (0, import_ast.childNode)(node, "init");
410
+ if (!name || !identifier || call?.type !== "CallExpression") return;
411
+ const callee = (0, import_ast.childNode)(call, "callee");
412
+ const factoryName = callee && (0, import_ast.identifierName)(callee);
413
+ if (!factoryName) return;
414
+ const binding = importBinding(program, factoryName);
415
+ if (!binding || binding.imported !== "styled") return;
416
+ const factory = (0, import_ir.hostImportProvenance)(imports, binding.source, binding.imported);
417
+ if (!factory) return;
418
+ const definitionBailouts = [];
419
+ const args = (0, import_ast.childNodes)(call, "arguments");
420
+ const baseNode = args[0];
421
+ const optionsNode = args.length >= 3 ? args[2] : args[1];
422
+ if (!baseNode || !optionsNode) {
423
+ definitionBailouts.push((0, import_diagnostics.localBailout)("local/unsupported-styled-definition", (0, import_contracts.spanOf)(id, call), `styled definition ${name} must provide a base and options object`));
424
+ bailouts.push(...definitionBailouts);
425
+ return;
426
+ }
427
+ const base = componentFromNode(candidate, id, program, imports, baseNode, definitionBailouts);
428
+ if (!base) {
429
+ bailouts.push(...definitionBailouts);
430
+ return;
431
+ }
432
+ const baseClassNode = args.length >= 3 ? args[1] : null;
433
+ const baseDefinition = {
434
+ kind: "styled-definition",
435
+ id,
436
+ name,
437
+ span: (0, import_contracts.spanOf)(id, call),
438
+ definitionSpan: (0, import_contracts.spanOf)(id, identifier),
439
+ factory,
440
+ base,
441
+ baseClassName: baseClassNode ? elementValue(id, baseClassNode) : null,
442
+ options: (0, import_contracts.expressionReference)(id, optionsNode)
443
+ };
444
+ definitions.push(definitionBailouts.length === 0 ? {
445
+ ...baseDefinition,
446
+ complete: true,
447
+ bailouts: []
448
+ } : {
449
+ ...baseDefinition,
450
+ complete: false,
451
+ bailouts: definitionBailouts
452
+ });
453
+ bailouts.push(...definitionBailouts);
454
+ });
455
+ return definitions.sort((left, right) => left.span.start - right.span.start);
456
+ }
457
+ const DOM_STYLE_FRONTENDS = /* @__PURE__ */ new Set([
458
+ "tamagui/dom",
459
+ "@tamagui/core/dom",
460
+ "@tamagui/tailwind"
461
+ ]);
462
+ function domStyleDefinitions(id, program, imports) {
463
+ const definitions = [];
464
+ (0, import_ast.walkAst)(program, (node) => {
465
+ if (node.type !== "VariableDeclarator") return;
466
+ const identifier = (0, import_ast.childNode)(node, "id");
467
+ const name = (0, import_ast.identifierName)(identifier);
468
+ const call = (0, import_ast.childNode)(node, "init");
469
+ if (!name || !identifier || call?.type !== "CallExpression") return;
470
+ const callee = (0, import_ast.childNode)(call, "callee");
471
+ const factoryName = callee && (0, import_ast.identifierName)(callee);
472
+ if (!factoryName) return;
473
+ const binding = importBinding(program, factoryName);
474
+ if (!binding || binding.imported !== "style" || !DOM_STYLE_FRONTENDS.has(binding.source)) {
475
+ return;
476
+ }
477
+ const factory = (0, import_ir.hostImportProvenance)(imports, binding.source, binding.imported);
478
+ const value = (0, import_ast.childNodes)(call, "arguments")[0];
479
+ if (!factory || !value) return;
480
+ definitions.push({
481
+ kind: "dom-style-definition",
482
+ id,
483
+ name,
484
+ span: (0, import_contracts.spanOf)(id, call),
485
+ definitionSpan: (0, import_contracts.spanOf)(id, identifier),
486
+ factory,
487
+ value: (0, import_contracts.expressionReference)(id, value)
488
+ });
489
+ });
490
+ return definitions.sort((left, right) => left.span.start - right.span.start);
491
+ }
492
+ function domStyleArgument(candidate, id, program, node) {
493
+ let call = node;
494
+ if (node.type === "Identifier") {
495
+ const name = (0, import_ast.identifierName)(node);
496
+ const definition = name ? candidate.definitionOf(id, name) : null;
497
+ if (!definition?.constant || !definition.initializer) return null;
498
+ call = definition.initializer;
499
+ }
500
+ if (call.type !== "CallExpression") return null;
501
+ const callee = (0, import_ast.childNode)(call, "callee");
502
+ const factoryName = callee && (0, import_ast.identifierName)(callee);
503
+ if (!factoryName) return null;
504
+ const binding = importBinding(program, factoryName);
505
+ if (!binding || binding.imported !== "style" || !DOM_STYLE_FRONTENDS.has(binding.source)) {
506
+ return null;
507
+ }
508
+ return (0, import_ast.childNodes)(call, "arguments")[0] ?? null;
509
+ }
510
+ function domStyleProgram(candidate, id, program, node) {
511
+ if (node.type !== "ArrayExpression" || !Array.isArray(node.elements)) {
512
+ const argument = domStyleArgument(candidate, id, program, node);
513
+ return argument ? {
514
+ kind: "dom-style",
515
+ span: (0, import_contracts.spanOf)(id, node),
516
+ items: [{
517
+ condition: null,
518
+ value: (0, import_contracts.expressionReference)(id, argument)
519
+ }]
520
+ } : null;
521
+ }
522
+ const items = [];
523
+ for (const rawItem of node.elements) {
524
+ if (!(0, import_ast.isAstNode)(rawItem)) return null;
525
+ let item = rawItem;
526
+ let condition = null;
527
+ if (item.type === "LogicalExpression" && item.operator === "&&") {
528
+ const left = (0, import_ast.childNode)(item, "left");
529
+ const right = (0, import_ast.childNode)(item, "right");
530
+ if (!left || !right) return null;
531
+ condition = (0, import_contracts.expressionReference)(id, left);
532
+ item = right;
533
+ }
534
+ const argument = domStyleArgument(candidate, id, program, item);
535
+ if (!argument) {
536
+ const staticValue = asStaticValue(item);
537
+ if (staticValue === false || staticValue === null) continue;
538
+ return null;
539
+ }
540
+ items.push({
541
+ condition,
542
+ value: (0, import_contracts.expressionReference)(id, argument)
543
+ });
544
+ }
545
+ return {
546
+ kind: "dom-style",
547
+ span: (0, import_contracts.spanOf)(id, node),
548
+ items
549
+ };
550
+ }
551
+ function normalizeElements(candidate, rawId, imports = []) {
552
+ const id = (0, import_contracts.resolvedModuleId)(rawId);
553
+ const program = candidate.programOf(id);
554
+ const elements = [];
555
+ const bailouts = [];
556
+ (0, import_ast.walkAst)(program, (node) => {
557
+ if (node.type === "JSXElement") {
558
+ const bailoutStart = bailouts.length;
559
+ const opening = (0, import_ast.childNode)(node, "openingElement");
560
+ const target = opening && jsxComponentNode(opening);
561
+ if (!opening || !target) return;
562
+ const component = componentFromNode(candidate, id, program, imports, target, bailouts);
563
+ if (!component) return;
564
+ const closingElement = (0, import_ast.childNode)(node, "closingElement");
565
+ const closingName = closingElement && (0, import_ast.childNode)(closingElement, "name");
566
+ if (closingName) component.closingSpan = (0, import_contracts.spanOf)(id, closingName);
567
+ const entries = jsxEntries(id, node, opening, bailouts);
568
+ for (const entry of entries) {
569
+ if (entry.kind !== "prop" || entry.name !== "style") continue;
570
+ const raw = entry.value.kind === "expression" ? nodeAtSpan(program, entry.value.start, entry.value.end) : null;
571
+ const styleProgram = raw && domStyleProgram(candidate, id, program, raw);
572
+ const argument = raw && domStyleArgument(candidate, id, program, raw);
573
+ if (styleProgram) entry.value = styleProgram;
574
+ else if (argument) entry.value = (0, import_contracts.expressionReference)(id, argument);
575
+ }
576
+ elements.push(finalizeElement({
577
+ kind: "element",
578
+ form: "jsx",
579
+ id,
580
+ span: (0, import_contracts.spanOf)(id, node),
581
+ propsSpan: (0, import_contracts.spanOf)(id, opening),
582
+ component
583
+ }, entries, bailouts.slice(bailoutStart)));
584
+ return;
585
+ }
586
+ if (node.type !== "CallExpression") return;
587
+ const runtime = runtimeCall(program, node);
588
+ if (!runtime) return;
589
+ const element = normalizeRuntimeElement(candidate, id, program, imports, node, runtime, bailouts);
590
+ if (element) {
591
+ const entries = element.complete ? element.entries : element.bailedEntries;
592
+ for (const entry of entries) {
593
+ if (entry.kind !== "prop" || entry.name !== "style") continue;
594
+ const raw = entry.value.kind === "expression" ? nodeAtSpan(program, entry.value.start, entry.value.end) : null;
595
+ const styleProgram = raw && domStyleProgram(candidate, id, program, raw);
596
+ const argument = raw && domStyleArgument(candidate, id, program, raw);
597
+ if (styleProgram) entry.value = styleProgram;
598
+ else if (argument) entry.value = (0, import_contracts.expressionReference)(id, argument);
599
+ }
600
+ elements.push(element);
601
+ }
602
+ });
603
+ return {
604
+ elements: elements.sort((left, right) => left.span.start - right.span.start),
605
+ styledDefinitions: styledDefinitions(candidate, id, program, imports, bailouts),
606
+ domStyleDefinitions: domStyleDefinitions(id, program, imports),
607
+ bailouts: bailouts.sort((left, right) => left.span.start - right.span.start)
608
+ };
609
+ }
610
+ function declarationForName(program, name) {
611
+ return (0, import_ast.findAstNode)(program, (node) => {
612
+ if (node.type !== "VariableDeclarator") return false;
613
+ return (0, import_ast.identifierName)((0, import_ast.childNode)(node, "id")) === name;
614
+ });
615
+ }
616
+ function nodeAtSpan(program, start, end) {
617
+ return (0, import_ast.findAstNode)(program, (node) => node.start === start && node.end === end);
618
+ }
619
+ function asAstNode(value, label) {
620
+ if (!(0, import_ast.isAstNode)(value)) throw new Error(`${label} is not an AST node`);
621
+ return value;
622
+ }