tempo-sdk 0.0.18 → 0.0.19

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.
@@ -0,0 +1,650 @@
1
+ // assets/parser.ts
2
+ import { parseSync } from "oxc-parser";
3
+
4
+ // assets/types.ts
5
+ var UNRESOLVED_VALUE = Object.freeze({
6
+ $unresolved: true
7
+ });
8
+ function isUnresolvedValue(value) {
9
+ return typeof value === "object" && value !== null && $unresolvedKey in value && value.$unresolved === true;
10
+ }
11
+ var $unresolvedKey = "$unresolved";
12
+
13
+ // assets/parser.ts
14
+ var ASSET_SDK_IMPORT_SOURCE = "tempo-sdk/assets";
15
+ function parseAssetFile(filePath, source) {
16
+ const { program, errors } = parseAssetProgram(filePath, source);
17
+ if (!program) {
18
+ return { filePath, declarations: [], errors };
19
+ }
20
+ const imports = readAssetImports(program);
21
+ for (const misimport of imports.misimports) {
22
+ errors.push({
23
+ code: "misimported_define_asset",
24
+ severity: "structural",
25
+ message: `defineAsset must be imported from "${ASSET_SDK_IMPORT_SOURCE}" \u2014 found import from "${misimport.source}"`,
26
+ span: misimport.span
27
+ });
28
+ }
29
+ const scope = collectTopLevelScope(program);
30
+ const declarations = [];
31
+ const declaredBindings = /* @__PURE__ */ new Set();
32
+ const topLevelCalls = /* @__PURE__ */ new Set();
33
+ for (const statement of program.body ?? []) {
34
+ const call = readTopLevelTrustedCall(
35
+ statement,
36
+ imports.trustedDefineAssetNames
37
+ );
38
+ if (!call) continue;
39
+ topLevelCalls.add(call);
40
+ const declaration = readAssetDeclaration({
41
+ statement,
42
+ call,
43
+ scope,
44
+ imports,
45
+ program,
46
+ source,
47
+ errors,
48
+ declaredBindings
49
+ });
50
+ if (declaration) declarations.push(declaration);
51
+ }
52
+ walk(program, (node) => {
53
+ if (node.type === "CallExpression" && node.callee?.type === "Identifier" && imports.trustedDefineAssetNames.has(node.callee.name) && !topLevelCalls.has(node)) {
54
+ errors.push({
55
+ code: "non_top_level_call",
56
+ severity: "structural",
57
+ message: "defineAsset must be called as a top-level statement \u2014 in the file that defines the component, or in a canvas file that imports it",
58
+ span: toSourceSpan(node)
59
+ });
60
+ }
61
+ });
62
+ return { filePath, declarations, errors };
63
+ }
64
+ function parseAssetProgram(filePath, source) {
65
+ try {
66
+ const result = parseSync(filePath, source);
67
+ const errors = (result.errors ?? []).map(
68
+ (error) => ({
69
+ code: "unparseable_source",
70
+ severity: "structural",
71
+ message: error?.message ?? "Unable to parse asset source",
72
+ span: toSourceSpan(error) ?? toSourceSpan(error?.labels?.[0])
73
+ })
74
+ );
75
+ if (errors.length > 0) return { program: null, errors };
76
+ return { program: result.program, errors: [] };
77
+ } catch (error) {
78
+ return {
79
+ program: null,
80
+ errors: [
81
+ {
82
+ code: "unparseable_source",
83
+ severity: "structural",
84
+ message: error instanceof Error ? error.message : "Unable to parse asset source"
85
+ }
86
+ ]
87
+ };
88
+ }
89
+ }
90
+ function readSourceComments(filePath, source) {
91
+ try {
92
+ const result = parseSync(filePath, source);
93
+ if ((result.errors ?? []).length > 0) return null;
94
+ return (result.comments ?? []).flatMap(
95
+ (comment) => typeof comment?.value === "string" ? [
96
+ {
97
+ value: comment.value,
98
+ span: toSourceSpan(comment) ?? { start: 0, end: 0 }
99
+ }
100
+ ] : []
101
+ );
102
+ } catch {
103
+ return null;
104
+ }
105
+ }
106
+ function readAssetImports(program) {
107
+ const info = {
108
+ trustedDefineAssetNames: /* @__PURE__ */ new Set(),
109
+ importedBindings: /* @__PURE__ */ new Map(),
110
+ referenceableImports: /* @__PURE__ */ new Map(),
111
+ importDeclarationSpans: [],
112
+ misimports: []
113
+ };
114
+ for (const statement of program?.body ?? []) {
115
+ if (statement?.type !== "ImportDeclaration" || typeof statement.source?.value !== "string") {
116
+ continue;
117
+ }
118
+ const declarationSpan = toSourceSpan(statement);
119
+ if (declarationSpan) info.importDeclarationSpans.push(declarationSpan);
120
+ if (statement.importKind === "type") continue;
121
+ const source = statement.source.value;
122
+ const trusted = isTrustedAssetImportSource(source);
123
+ for (const specifier of statement.specifiers ?? []) {
124
+ if (specifier?.importKind === "type") continue;
125
+ const localName = specifier?.local?.name;
126
+ if (typeof localName !== "string") continue;
127
+ info.importedBindings.set(localName, source);
128
+ if (specifier.type === "ImportDefaultSpecifier") {
129
+ info.referenceableImports.set(localName, {
130
+ importSpecifier: source,
131
+ importedName: "default"
132
+ });
133
+ continue;
134
+ }
135
+ if (specifier.type !== "ImportSpecifier") continue;
136
+ const importedName = specifier.imported?.name ?? specifier.imported?.value ?? localName;
137
+ info.referenceableImports.set(localName, {
138
+ importSpecifier: source,
139
+ importedName
140
+ });
141
+ if (importedName !== "defineAsset") continue;
142
+ if (trusted) {
143
+ info.trustedDefineAssetNames.add(localName);
144
+ } else if (isMisimportedAssetSdkSource(source)) {
145
+ info.misimports.push({
146
+ source,
147
+ span: toSourceSpan(statement.source) ?? declarationSpan ?? { start: 0, end: 0 }
148
+ });
149
+ }
150
+ }
151
+ }
152
+ return info;
153
+ }
154
+ function isTrustedAssetImportSource(source) {
155
+ return source === ASSET_SDK_IMPORT_SOURCE || source.endsWith(`/${ASSET_SDK_IMPORT_SOURCE}`);
156
+ }
157
+ function isMisimportedAssetSdkSource(source) {
158
+ return (source === "tempo-sdk" || source.startsWith("tempo-sdk/")) && !isTrustedAssetImportSource(source);
159
+ }
160
+ function collectTopLevelScope(program) {
161
+ const bindings = /* @__PURE__ */ new Map();
162
+ const nonSimpleNames = /* @__PURE__ */ new Set();
163
+ const namedExports = /* @__PURE__ */ new Set();
164
+ const defaultExports = /* @__PURE__ */ new Set();
165
+ const register = (declaration, statementSpan, exported) => {
166
+ const markExported = (name) => {
167
+ if (exported === "named") namedExports.add(name);
168
+ if (exported === "default") defaultExports.add(name);
169
+ };
170
+ if (declaration?.type === "FunctionDeclaration" || declaration?.type === "ClassDeclaration") {
171
+ const name = declaration.id?.name;
172
+ if (typeof name === "string") {
173
+ bindings.set(name, { name, statementSpan, exportKind: "none" });
174
+ markExported(name);
175
+ }
176
+ return;
177
+ }
178
+ if (declaration?.type === "VariableDeclaration") {
179
+ for (const declarator of declaration.declarations ?? []) {
180
+ if (declarator?.id?.type === "Identifier") {
181
+ const name = declarator.id.name;
182
+ if (declarator.init) {
183
+ bindings.set(name, { name, statementSpan, exportKind: "none" });
184
+ markExported(name);
185
+ } else {
186
+ nonSimpleNames.add(name);
187
+ }
188
+ } else {
189
+ collectPatternNames(declarator?.id, nonSimpleNames);
190
+ }
191
+ }
192
+ }
193
+ };
194
+ for (const statement of program?.body ?? []) {
195
+ const statementSpan = toSourceSpan(statement) ?? { start: 0, end: 0 };
196
+ if (statement?.type === "ExportNamedDeclaration") {
197
+ if (statement.declaration) {
198
+ register(statement.declaration, statementSpan, "named");
199
+ }
200
+ if (!statement.source) {
201
+ for (const specifier of statement.specifiers ?? []) {
202
+ if (specifier?.type !== "ExportSpecifier") continue;
203
+ const localName = specifier.local?.name;
204
+ if (typeof localName !== "string") continue;
205
+ const exportedName = specifier.exported?.name ?? specifier.exported?.value;
206
+ (exportedName === "default" ? defaultExports : namedExports).add(
207
+ localName
208
+ );
209
+ }
210
+ }
211
+ continue;
212
+ }
213
+ if (statement?.type === "ExportDefaultDeclaration") {
214
+ const declaration = statement.declaration;
215
+ if (declaration?.type === "FunctionDeclaration" || declaration?.type === "ClassDeclaration") {
216
+ register(declaration, statementSpan, "default");
217
+ } else {
218
+ const expression = unwrapTsExpression(declaration);
219
+ if (expression?.type === "Identifier") {
220
+ defaultExports.add(expression.name);
221
+ }
222
+ }
223
+ continue;
224
+ }
225
+ register(statement, statementSpan, null);
226
+ }
227
+ for (const binding of bindings.values()) {
228
+ binding.exportKind = defaultExports.has(binding.name) ? "default" : namedExports.has(binding.name) ? "named" : "none";
229
+ }
230
+ return { bindings, nonSimpleNames };
231
+ }
232
+ function collectPatternNames(pattern, names) {
233
+ if (!pattern || typeof pattern !== "object") return;
234
+ if (pattern.type === "Identifier" && typeof pattern.name === "string") {
235
+ names.add(pattern.name);
236
+ return;
237
+ }
238
+ if (pattern.type === "ObjectPattern") {
239
+ for (const property of pattern.properties ?? []) {
240
+ collectPatternNames(property?.value ?? property?.argument, names);
241
+ }
242
+ return;
243
+ }
244
+ if (pattern.type === "ArrayPattern") {
245
+ for (const element of pattern.elements ?? []) {
246
+ collectPatternNames(element, names);
247
+ }
248
+ return;
249
+ }
250
+ if (pattern.type === "AssignmentPattern") {
251
+ collectPatternNames(pattern.left, names);
252
+ return;
253
+ }
254
+ if (pattern.type === "RestElement") {
255
+ collectPatternNames(pattern.argument, names);
256
+ }
257
+ }
258
+ function hasTopLevelDefineAssetCallFor(program, trustedNames, bindingName) {
259
+ for (const statement of program?.body ?? []) {
260
+ const call = readTopLevelTrustedCall(statement, trustedNames);
261
+ if (!call) continue;
262
+ const componentArg = unwrapTsExpression(call.arguments?.[0]);
263
+ if (componentArg?.type === "Identifier" && componentArg.name === bindingName) {
264
+ return true;
265
+ }
266
+ }
267
+ return false;
268
+ }
269
+ function collectIdentifierNames(program) {
270
+ const names = /* @__PURE__ */ new Set();
271
+ walk(program, (node) => {
272
+ if ((node.type === "Identifier" || node.type === "JSXIdentifier") && typeof node.name === "string") {
273
+ names.add(node.name);
274
+ }
275
+ });
276
+ return names;
277
+ }
278
+ function readTopLevelTrustedCall(statement, trustedNames) {
279
+ if (statement?.type !== "ExpressionStatement") return null;
280
+ const expression = unwrapTsExpression(statement.expression);
281
+ if (expression?.type === "CallExpression" && expression.callee?.type === "Identifier" && trustedNames.has(expression.callee.name)) {
282
+ return expression;
283
+ }
284
+ return null;
285
+ }
286
+ function readAssetDeclaration(input) {
287
+ const { statement, call, scope, imports, program, source, errors } = input;
288
+ const callSpan = statementSpanWithSemicolon(source, statement);
289
+ const args = call.arguments ?? [];
290
+ if (args.length !== 2) {
291
+ errors.push({
292
+ code: "invalid_call_arguments",
293
+ severity: "structural",
294
+ message: `defineAsset takes exactly two arguments (component, config) \u2014 found ${args.length}`,
295
+ span: callSpan
296
+ });
297
+ return null;
298
+ }
299
+ const componentArg = unwrapTsExpression(args[0]);
300
+ if (componentArg?.type !== "Identifier") {
301
+ errors.push({
302
+ code: "non_identifier_component",
303
+ severity: "structural",
304
+ message: "defineAsset's first argument must be an identifier naming a component defined in this file",
305
+ span: toSourceSpan(args[0]) ?? callSpan
306
+ });
307
+ return null;
308
+ }
309
+ const bindingName = componentArg.name;
310
+ const binding = scope.bindings.get(bindingName);
311
+ const reference = binding ? void 0 : imports.referenceableImports.get(bindingName);
312
+ if (!binding && !reference) {
313
+ errors.push(
314
+ classifyMissingBinding(
315
+ bindingName,
316
+ scope,
317
+ imports,
318
+ program,
319
+ toSourceSpan(componentArg) ?? callSpan
320
+ )
321
+ );
322
+ return null;
323
+ }
324
+ const configArg = unwrapTsExpression(args[1]);
325
+ if (configArg?.type !== "ObjectExpression") {
326
+ errors.push({
327
+ code: "config_not_object_literal",
328
+ severity: "structural",
329
+ message: "defineAsset's config must be an inline object literal \u2014 the span-based editor needs literal spans to mutate",
330
+ span: toSourceSpan(args[1]) ?? callSpan
331
+ });
332
+ return null;
333
+ }
334
+ if (input.declaredBindings.has(bindingName)) {
335
+ errors.push({
336
+ code: "duplicate_declaration",
337
+ severity: "structural",
338
+ message: `duplicate defineAsset call for "${bindingName}" \u2014 the first declaration stays authoritative`,
339
+ span: callSpan
340
+ });
341
+ return null;
342
+ }
343
+ input.declaredBindings.add(bindingName);
344
+ const warnings = [];
345
+ const spans = {
346
+ call: callSpan,
347
+ config: toSourceSpan(configArg) ?? callSpan,
348
+ libraryItems: []
349
+ };
350
+ const usageInstructions = readUsageInstructions(configArg);
351
+ const libraries = readLibraries(configArg, spans, warnings);
352
+ const variants = readVariants(configArg, warnings);
353
+ if (binding && binding.exportKind === "none") {
354
+ warnings.push({
355
+ code: "not_exported",
356
+ severity: "degraded",
357
+ message: `"${bindingName}" is not exported \u2014 other files cannot import this asset`,
358
+ span: callSpan
359
+ });
360
+ }
361
+ return {
362
+ bindingName,
363
+ exportKind: binding ? binding.exportKind : referenceExportKind(reference),
364
+ libraries,
365
+ ...usageInstructions === void 0 ? {} : { usageInstructions },
366
+ variants,
367
+ ...reference ? { reference } : {},
368
+ spans,
369
+ warnings
370
+ };
371
+ }
372
+ function referenceExportKind(reference) {
373
+ return reference.importedName === "default" ? "default" : "named";
374
+ }
375
+ function classifyMissingBinding(name, scope, imports, program, span) {
376
+ const importSource = imports.importedBindings.get(name);
377
+ if (importSource !== void 0) {
378
+ return {
379
+ code: "imported_binding",
380
+ severity: "structural",
381
+ message: `"${name}" is a namespace import from "${importSource}" \u2014 declare the asset on a named or default import of the component instead`,
382
+ span
383
+ };
384
+ }
385
+ if (scope.nonSimpleNames.has(name)) {
386
+ return {
387
+ code: "unknown_binding",
388
+ severity: "structural",
389
+ message: `"${name}" is not a plain initialized top-level binding \u2014 destructured and uninitialized declarations are not supported`,
390
+ span
391
+ };
392
+ }
393
+ if (hasNestedBinding(program, name)) {
394
+ return {
395
+ code: "non_top_level_binding",
396
+ severity: "structural",
397
+ message: `"${name}" is not declared at the top level of the module`,
398
+ span
399
+ };
400
+ }
401
+ return {
402
+ code: "unknown_binding",
403
+ severity: "structural",
404
+ message: `no top-level declaration of "${name}" found in this file`,
405
+ span
406
+ };
407
+ }
408
+ function hasNestedBinding(program, name) {
409
+ let found = false;
410
+ walk(program, (node) => {
411
+ if (found) return;
412
+ if ((node.type === "VariableDeclarator" || node.type === "FunctionDeclaration" || node.type === "ClassDeclaration") && node.id?.type === "Identifier" && node.id.name === name) {
413
+ found = true;
414
+ }
415
+ });
416
+ return found;
417
+ }
418
+ function readUsageInstructions(configNode) {
419
+ return readStaticStringProperty(configNode, "usageInstructions");
420
+ }
421
+ function readStaticStringProperty(configNode, name) {
422
+ const property = getObjectProperty(configNode, name);
423
+ if (!property) return void 0;
424
+ const value = readStaticValue(property.value);
425
+ return typeof value === "string" ? value : void 0;
426
+ }
427
+ function readLibraries(configNode, spans, warnings) {
428
+ const property = getObjectProperty(configNode, "libraries");
429
+ if (!property) return [];
430
+ spans.librariesProperty = toSourceSpan(property);
431
+ const value = unwrapTsExpression(property.value);
432
+ if (value?.type !== "ArrayExpression") {
433
+ warnings.push({
434
+ code: "non_literal_library",
435
+ severity: "degraded",
436
+ message: "libraries must be an inline array literal of string literals \u2014 its entries were dropped",
437
+ span: toSourceSpan(property.value) ?? spans.librariesProperty
438
+ });
439
+ return [];
440
+ }
441
+ spans.libraries = toSourceSpan(value);
442
+ const names = [];
443
+ for (const element of value.elements ?? []) {
444
+ const elementSpan = toSourceSpan(element) ?? spans.libraries;
445
+ const name = readStaticString(element);
446
+ if (name === null) {
447
+ warnings.push({
448
+ code: "non_literal_library",
449
+ severity: "degraded",
450
+ message: "libraries entries must be string literals \u2014 dropped a non-literal entry",
451
+ span: elementSpan
452
+ });
453
+ continue;
454
+ }
455
+ if (name === "") {
456
+ warnings.push({
457
+ code: "empty_library_name",
458
+ severity: "degraded",
459
+ message: "libraries entries must be non-empty \u2014 dropped an empty entry",
460
+ span: elementSpan
461
+ });
462
+ continue;
463
+ }
464
+ if (names.includes(name)) {
465
+ warnings.push({
466
+ code: "duplicate_library",
467
+ severity: "degraded",
468
+ message: `duplicate library name "${name}" \u2014 deduplicated`,
469
+ span: elementSpan
470
+ });
471
+ continue;
472
+ }
473
+ names.push(name);
474
+ if (elementSpan) spans.libraryItems.push(elementSpan);
475
+ }
476
+ return names;
477
+ }
478
+ function readVariants(configNode, warnings) {
479
+ const property = getObjectProperty(configNode, "variants");
480
+ if (!property) return [];
481
+ const value = unwrapTsExpression(property.value);
482
+ if (value?.type !== "ObjectExpression") {
483
+ warnings.push({
484
+ code: "unresolved_prop_value",
485
+ severity: "degraded",
486
+ message: "variants is not an inline object literal \u2014 variant props are not statically readable",
487
+ span: toSourceSpan(property.value) ?? toSourceSpan(property)
488
+ });
489
+ return [];
490
+ }
491
+ const properties = value.properties ?? [];
492
+ if (properties.length === 0) {
493
+ warnings.push({
494
+ code: "empty_variants",
495
+ severity: "degraded",
496
+ message: "variants is present but empty",
497
+ span: toSourceSpan(value)
498
+ });
499
+ return [];
500
+ }
501
+ const variants = [];
502
+ for (const entry of properties) {
503
+ const name = entry?.type === "Property" && !entry.computed ? readPropertyKeyName(entry.key) : null;
504
+ if (name === null) {
505
+ warnings.push({
506
+ code: "unresolved_prop_value",
507
+ severity: "degraded",
508
+ message: "variant names must be identifier or string keys \u2014 skipped an entry that is not statically readable",
509
+ span: toSourceSpan(entry) ?? toSourceSpan(value)
510
+ });
511
+ continue;
512
+ }
513
+ variants.push(readVariant(name, entry, warnings));
514
+ }
515
+ return variants;
516
+ }
517
+ function readVariant(name, entry, warnings) {
518
+ const value = unwrapTsExpression(entry.value);
519
+ const propsProperty = value?.type === "ObjectExpression" ? getObjectProperty(value, "props") : null;
520
+ const propsValue = propsProperty ? readStaticValue(propsProperty.value) : UNRESOLVED_VALUE;
521
+ const props = isPlainRecord(propsValue) ? propsValue : {};
522
+ const hasUnresolvedValues = !isPlainRecord(propsValue) || containsUnresolvedValue(propsValue);
523
+ if (hasUnresolvedValues) {
524
+ warnings.push({
525
+ code: "unresolved_prop_value",
526
+ severity: "degraded",
527
+ message: `variant "${name}" has prop values that are not statically readable`,
528
+ span: toSourceSpan(entry)
529
+ });
530
+ }
531
+ return { name, props, hasUnresolvedValues };
532
+ }
533
+ function readStaticValue(node) {
534
+ const expression = unwrapTsExpression(node);
535
+ if (!expression) return UNRESOLVED_VALUE;
536
+ switch (expression.type) {
537
+ case "Literal": {
538
+ if (expression.regex || expression.bigint) return UNRESOLVED_VALUE;
539
+ const { value } = expression;
540
+ return value === null || typeof value === "string" || typeof value === "number" || typeof value === "boolean" ? value : UNRESOLVED_VALUE;
541
+ }
542
+ case "TemplateLiteral": {
543
+ if ((expression.expressions ?? []).length > 0) return UNRESOLVED_VALUE;
544
+ const cooked = expression.quasis?.[0]?.value?.cooked;
545
+ return typeof cooked === "string" ? cooked : UNRESOLVED_VALUE;
546
+ }
547
+ case "UnaryExpression": {
548
+ if (expression.operator !== "-") return UNRESOLVED_VALUE;
549
+ const argument = unwrapTsExpression(expression.argument);
550
+ return argument?.type === "Literal" && typeof argument.value === "number" && Number.isFinite(argument.value) ? -argument.value : UNRESOLVED_VALUE;
551
+ }
552
+ case "ArrayExpression":
553
+ return (expression.elements ?? []).map(
554
+ (element) => element == null || element.type === "SpreadElement" ? UNRESOLVED_VALUE : readStaticValue(element)
555
+ );
556
+ case "ObjectExpression": {
557
+ const record = {};
558
+ for (const property of expression.properties ?? []) {
559
+ if (property?.type !== "Property" || property.computed) {
560
+ return UNRESOLVED_VALUE;
561
+ }
562
+ const key = readPropertyKeyName(property.key);
563
+ if (key === null) return UNRESOLVED_VALUE;
564
+ record[key] = readStaticValue(property.value);
565
+ }
566
+ return record;
567
+ }
568
+ default:
569
+ return UNRESOLVED_VALUE;
570
+ }
571
+ }
572
+ function readStaticString(node) {
573
+ const value = node == null ? UNRESOLVED_VALUE : readStaticValue(node);
574
+ return typeof value === "string" ? value : null;
575
+ }
576
+ function isPlainRecord(value) {
577
+ return typeof value === "object" && value !== null && !Array.isArray(value) && !isUnresolvedValue(value);
578
+ }
579
+ function containsUnresolvedValue(value) {
580
+ if (isUnresolvedValue(value)) return true;
581
+ if (Array.isArray(value)) return value.some(containsUnresolvedValue);
582
+ if (typeof value === "object" && value !== null) {
583
+ return Object.values(value).some(containsUnresolvedValue);
584
+ }
585
+ return false;
586
+ }
587
+ function statementSpanWithSemicolon(source, statement) {
588
+ const span = toSourceSpan(statement) ?? { start: 0, end: 0 };
589
+ if (source[span.end - 1] === ";") return span;
590
+ let end = span.end;
591
+ while (end < source.length && (source[end] === " " || source[end] === " ")) {
592
+ end++;
593
+ }
594
+ return source[end] === ";" ? { start: span.start, end: end + 1 } : span;
595
+ }
596
+ function unwrapTsExpression(node) {
597
+ let current = node;
598
+ while (current?.type === "TSSatisfiesExpression" || current?.type === "TSAsExpression" || current?.type === "TSNonNullExpression" || current?.type === "ParenthesizedExpression") {
599
+ current = current.expression;
600
+ }
601
+ return current;
602
+ }
603
+ function readPropertyKeyName(key) {
604
+ if (key?.type === "Identifier") return key.name;
605
+ if (key?.type === "Literal") {
606
+ if (typeof key.value === "string") return key.value;
607
+ if (typeof key.value === "number") return String(key.value);
608
+ }
609
+ return null;
610
+ }
611
+ function getObjectProperty(objectExpression, name) {
612
+ if (objectExpression?.type !== "ObjectExpression") return null;
613
+ for (const property of objectExpression.properties ?? []) {
614
+ if (property?.type !== "Property" || property.computed) continue;
615
+ if (readPropertyKeyName(property.key) === name) return property;
616
+ }
617
+ return null;
618
+ }
619
+ function toSourceSpan(node) {
620
+ return typeof node?.start === "number" && Number.isFinite(node.start) && typeof node?.end === "number" && Number.isFinite(node.end) ? { start: node.start, end: node.end } : void 0;
621
+ }
622
+ function walk(node, visitor, seen = /* @__PURE__ */ new Set()) {
623
+ if (!node || typeof node !== "object" || seen.has(node)) return;
624
+ seen.add(node);
625
+ if (typeof node.type === "string") visitor(node);
626
+ for (const value of Object.values(node)) {
627
+ if (!value || typeof value !== "object") continue;
628
+ if (Array.isArray(value)) {
629
+ for (const item of value) walk(item, visitor, seen);
630
+ } else {
631
+ walk(value, visitor, seen);
632
+ }
633
+ }
634
+ }
635
+
636
+ export {
637
+ UNRESOLVED_VALUE,
638
+ isUnresolvedValue,
639
+ ASSET_SDK_IMPORT_SOURCE,
640
+ parseAssetFile,
641
+ parseAssetProgram,
642
+ readSourceComments,
643
+ readAssetImports,
644
+ collectTopLevelScope,
645
+ hasTopLevelDefineAssetCallFor,
646
+ collectIdentifierNames,
647
+ unwrapTsExpression,
648
+ toSourceSpan
649
+ };
650
+ //# sourceMappingURL=chunk-IWULHYPW.js.map