@soda-gql/babel-transformer 0.2.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 ADDED
@@ -0,0 +1,1428 @@
1
+ //#region rolldown:runtime
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __copyProps = (to, from, except, desc) => {
9
+ if (from && typeof from === "object" || typeof from === "function") {
10
+ for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
11
+ key = keys[i];
12
+ if (!__hasOwnProp.call(to, key) && key !== except) {
13
+ __defProp(to, key, {
14
+ get: ((k) => from[k]).bind(null, key),
15
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
16
+ });
17
+ }
18
+ }
19
+ }
20
+ return to;
21
+ };
22
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
23
+ value: mod,
24
+ enumerable: true
25
+ }) : target, mod));
26
+
27
+ //#endregion
28
+ let __soda_gql_plugin_common = require("@soda-gql/plugin-common");
29
+ let neverthrow = require("neverthrow");
30
+ let __babel_types = require("@babel/types");
31
+ __babel_types = __toESM(__babel_types);
32
+ let __babel_core = require("@babel/core");
33
+ let __soda_gql_common = require("@soda-gql/common");
34
+ let __babel_generator = require("@babel/generator");
35
+ __babel_generator = __toESM(__babel_generator);
36
+ let __babel_parser = require("@babel/parser");
37
+ let __babel_traverse = require("@babel/traverse");
38
+ __babel_traverse = __toESM(__babel_traverse);
39
+ let __soda_gql_builder = require("@soda-gql/builder");
40
+
41
+ //#region packages/babel-transformer/src/ast/analysis.ts
42
+ const extractGqlCall = ({ nodePath, filename, metadata, getArtifact }) => {
43
+ const callExpression = nodePath.node;
44
+ const meta = metadata.get(callExpression);
45
+ if (!meta) return (0, neverthrow.err)(createMetadataMissingError({ filename }));
46
+ const canonicalId = (0, __soda_gql_plugin_common.resolveCanonicalId)(filename, meta.astPath);
47
+ const artifact = getArtifact(canonicalId);
48
+ if (!artifact) return (0, neverthrow.err)(createArtifactMissingError({
49
+ filename,
50
+ canonicalId
51
+ }));
52
+ if (artifact.type === "fragment") return (0, neverthrow.ok)({
53
+ nodePath,
54
+ canonicalId,
55
+ type: "fragment",
56
+ artifact
57
+ });
58
+ if (artifact.type === "operation") return (0, neverthrow.ok)({
59
+ nodePath,
60
+ canonicalId,
61
+ type: "operation",
62
+ artifact
63
+ });
64
+ return (0, neverthrow.err)(createUnsupportedArtifactTypeError({
65
+ filename,
66
+ canonicalId,
67
+ artifactType: artifact.type
68
+ }));
69
+ };
70
+ const createMetadataMissingError = ({ filename }) => ({
71
+ type: "PluginError",
72
+ stage: "analysis",
73
+ code: "SODA_GQL_METADATA_NOT_FOUND",
74
+ message: `No GraphQL metadata found for ${filename}`,
75
+ cause: { filename },
76
+ filename
77
+ });
78
+ const createArtifactMissingError = ({ filename, canonicalId }) => ({
79
+ type: "PluginError",
80
+ stage: "analysis",
81
+ code: "SODA_GQL_ANALYSIS_ARTIFACT_NOT_FOUND",
82
+ message: `No builder artifact found for canonical ID ${canonicalId}`,
83
+ cause: {
84
+ filename,
85
+ canonicalId
86
+ },
87
+ filename,
88
+ canonicalId
89
+ });
90
+ const createUnsupportedArtifactTypeError = ({ filename, canonicalId, artifactType }) => ({
91
+ type: "PluginError",
92
+ stage: "analysis",
93
+ code: "SODA_GQL_UNSUPPORTED_ARTIFACT_TYPE",
94
+ message: `Unsupported builder artifact type "${artifactType}" for canonical ID ${canonicalId}`,
95
+ cause: {
96
+ filename,
97
+ canonicalId,
98
+ artifactType
99
+ },
100
+ filename,
101
+ canonicalId,
102
+ artifactType
103
+ });
104
+
105
+ //#endregion
106
+ //#region packages/babel-transformer/src/ast/ast.ts
107
+ const createUnsupportedValueTypeError = (valueType) => ({
108
+ type: "PluginError",
109
+ stage: "transform",
110
+ code: "SODA_GQL_TRANSFORM_UNSUPPORTED_VALUE_TYPE",
111
+ message: `Unsupported value type: ${valueType}`,
112
+ cause: { valueType },
113
+ valueType
114
+ });
115
+ const buildLiteralFromValue = (value) => {
116
+ if (value === null) return (0, neverthrow.ok)(__babel_types.nullLiteral());
117
+ if (typeof value === "string") return (0, neverthrow.ok)(__babel_types.stringLiteral(value));
118
+ if (typeof value === "number") return (0, neverthrow.ok)(__babel_types.numericLiteral(value));
119
+ if (typeof value === "boolean") return (0, neverthrow.ok)(__babel_types.booleanLiteral(value));
120
+ if (Array.isArray(value)) {
121
+ const elements = [];
122
+ for (const item of value) {
123
+ const result = buildLiteralFromValue(item);
124
+ if (result.isErr()) return result;
125
+ elements.push(result.value);
126
+ }
127
+ return (0, neverthrow.ok)(__babel_types.arrayExpression(elements));
128
+ }
129
+ if (typeof value === "object") {
130
+ const properties = [];
131
+ for (const [key, val] of Object.entries(value)) {
132
+ const result = buildLiteralFromValue(val);
133
+ if (result.isErr()) return result;
134
+ properties.push(__babel_types.objectProperty(__babel_types.identifier(key), result.value));
135
+ }
136
+ return (0, neverthrow.ok)(__babel_types.objectExpression(properties));
137
+ }
138
+ return (0, neverthrow.err)(createUnsupportedValueTypeError(typeof value));
139
+ };
140
+ const clone = (node) => __babel_types.cloneNode(node, true);
141
+ const cloneCallExpression = (node) => __babel_types.callExpression(clone(node.callee), node.arguments.map(clone));
142
+ const stripTypeAnnotations = (node) => {
143
+ if ("typeParameters" in node) delete node.typeParameters;
144
+ if ("typeAnnotation" in node) delete node.typeAnnotation;
145
+ if ("returnType" in node) delete node.returnType;
146
+ };
147
+ const buildObjectExpression = (properties) => __babel_types.objectExpression(Object.entries(properties).map(([key, value]) => __babel_types.objectProperty(__babel_types.identifier(key), value)));
148
+
149
+ //#endregion
150
+ //#region packages/babel-transformer/src/ast/imports.ts
151
+ const RUNTIME_MODULE = "@soda-gql/runtime";
152
+ /**
153
+ * Ensure that the gqlRuntime require exists in the program for CJS output.
154
+ * Injects: const __soda_gql_runtime = require("@soda-gql/runtime");
155
+ */
156
+ const ensureGqlRuntimeRequire = (programPath) => {
157
+ if (programPath.node.body.find((statement) => __babel_core.types.isVariableDeclaration(statement) && statement.declarations.some((decl) => {
158
+ if (!__babel_core.types.isIdentifier(decl.id) || decl.id.name !== "__soda_gql_runtime") return false;
159
+ if (!decl.init || !__babel_core.types.isCallExpression(decl.init)) return false;
160
+ const callExpr = decl.init;
161
+ if (!__babel_core.types.isIdentifier(callExpr.callee) || callExpr.callee.name !== "require") return false;
162
+ const arg = callExpr.arguments[0];
163
+ return arg && __babel_core.types.isStringLiteral(arg) && arg.value === RUNTIME_MODULE;
164
+ }))) return;
165
+ const requireCall = __babel_core.types.callExpression(__babel_core.types.identifier("require"), [__babel_core.types.stringLiteral(RUNTIME_MODULE)]);
166
+ const variableDeclaration = __babel_core.types.variableDeclaration("const", [__babel_core.types.variableDeclarator(__babel_core.types.identifier("__soda_gql_runtime"), requireCall)]);
167
+ programPath.node.body.unshift(variableDeclaration);
168
+ };
169
+ /**
170
+ * Ensure that the gqlRuntime import exists in the program.
171
+ * gqlRuntime is always imported from @soda-gql/runtime.
172
+ */
173
+ const ensureGqlRuntimeImport = (programPath) => {
174
+ const existing = programPath.node.body.find((statement) => statement.type === "ImportDeclaration" && statement.source.value === RUNTIME_MODULE);
175
+ if (existing && __babel_core.types.isImportDeclaration(existing)) {
176
+ if (!existing.specifiers.some((specifier) => specifier.type === "ImportSpecifier" && specifier.imported.type === "Identifier" && specifier.imported.name === "gqlRuntime")) existing.specifiers = [...existing.specifiers, __babel_core.types.importSpecifier(__babel_core.types.identifier("gqlRuntime"), __babel_core.types.identifier("gqlRuntime"))];
177
+ return;
178
+ }
179
+ programPath.node.body.unshift(__babel_core.types.importDeclaration([__babel_core.types.importSpecifier(__babel_core.types.identifier("gqlRuntime"), __babel_core.types.identifier("gqlRuntime"))], __babel_core.types.stringLiteral(RUNTIME_MODULE)));
180
+ };
181
+ /**
182
+ * Remove the graphql-system import (runtimeModule) and gql-related exports from the program.
183
+ * After transformation, gqlRuntime is imported from @soda-gql/runtime instead,
184
+ * so the original graphql-system import should be completely removed.
185
+ *
186
+ * This handles both ESM imports and CommonJS require() statements.
187
+ */
188
+ const removeGraphqlSystemImports = (programPath, graphqlSystemIdentifyHelper, filename) => {
189
+ const toRemove = [];
190
+ programPath.traverse({
191
+ ImportDeclaration(path) {
192
+ if (__babel_core.types.isStringLiteral(path.node.source)) {
193
+ if (graphqlSystemIdentifyHelper.isGraphqlSystemImportSpecifier({
194
+ filePath: filename,
195
+ specifier: path.node.source.value
196
+ })) toRemove.push(path);
197
+ }
198
+ },
199
+ VariableDeclaration(path) {
200
+ if (path.node.declarations.every((decl) => {
201
+ const specifier = extractRequireTargetSpecifier(decl.init);
202
+ if (!specifier) return false;
203
+ return graphqlSystemIdentifyHelper.isGraphqlSystemImportSpecifier({
204
+ filePath: filename,
205
+ specifier
206
+ });
207
+ })) toRemove.push(path);
208
+ }
209
+ });
210
+ for (const path of toRemove) path.remove();
211
+ };
212
+ /**
213
+ * Check if an expression is a require() call and extract its target specifier.
214
+ * Handles multiple patterns:
215
+ * - require("@/graphql-system")
216
+ * - Object(require("@/graphql-system")) (interop helper pattern)
217
+ */
218
+ const extractRequireTargetSpecifier = (expr) => {
219
+ if (!expr) return;
220
+ if (__babel_core.types.isCallExpression(expr)) {
221
+ if (__babel_core.types.isIdentifier(expr.callee) && expr.callee.name === "require") {
222
+ const arg = expr.arguments[0];
223
+ if (arg && __babel_core.types.isStringLiteral(arg)) return arg.value;
224
+ }
225
+ if (__babel_core.types.isIdentifier(expr.callee) && (expr.callee.name === "Object" || expr.callee.name.startsWith("__import"))) {
226
+ const arg = expr.arguments[0];
227
+ if (arg && __babel_core.types.isCallExpression(arg)) {
228
+ if (__babel_core.types.isIdentifier(arg.callee) && arg.callee.name === "require") {
229
+ const requireArg = arg.arguments[0];
230
+ if (requireArg && __babel_core.types.isStringLiteral(requireArg)) return requireArg.value;
231
+ }
232
+ }
233
+ }
234
+ }
235
+ };
236
+
237
+ //#endregion
238
+ //#region packages/babel-transformer/src/ast/metadata.ts
239
+ const collectGqlDefinitionMetadata = ({ programPath, filename, createTracker }) => {
240
+ const exportBindings = collectExportBindings(programPath.node);
241
+ const tracker = (createTracker ?? __soda_gql_common.createCanonicalTracker)({
242
+ filePath: filename,
243
+ getExportName: (localName) => exportBindings.get(localName)
244
+ });
245
+ const getAnonymousName = createAnonymousNameFactory();
246
+ const scopeHandles = /* @__PURE__ */ new WeakMap();
247
+ const metadata = /* @__PURE__ */ new WeakMap();
248
+ programPath.traverse({
249
+ enter(path) {
250
+ if (path.isCallExpression() && isGqlDefinitionCall(path.node)) {
251
+ const depthBeforeRegister = tracker.currentDepth();
252
+ const { astPath } = tracker.registerDefinition();
253
+ const isTopLevel = depthBeforeRegister <= 1;
254
+ const exportInfo = isTopLevel ? resolveTopLevelExport(path, exportBindings) : null;
255
+ metadata.set(path.node, {
256
+ astPath,
257
+ isTopLevel,
258
+ isExported: exportInfo?.isExported ?? false,
259
+ exportBinding: exportInfo?.exportBinding
260
+ });
261
+ path.skip();
262
+ return;
263
+ }
264
+ const handle = maybeEnterScope(path, tracker, getAnonymousName);
265
+ if (handle) scopeHandles.set(path, handle);
266
+ },
267
+ exit(path) {
268
+ const handle = scopeHandles.get(path);
269
+ if (handle) {
270
+ tracker.exitScope(handle);
271
+ scopeHandles.delete(path);
272
+ }
273
+ }
274
+ });
275
+ return metadata;
276
+ };
277
+ const collectExportBindings = (program) => {
278
+ const bindings = /* @__PURE__ */ new Map();
279
+ for (const statement of program.body) {
280
+ if (__babel_core.types.isExportNamedDeclaration(statement) && statement.declaration) {
281
+ const { declaration } = statement;
282
+ if (__babel_core.types.isVariableDeclaration(declaration)) {
283
+ for (const declarator of declaration.declarations) if (__babel_core.types.isIdentifier(declarator.id)) bindings.set(declarator.id.name, declarator.id.name);
284
+ continue;
285
+ }
286
+ if ((__babel_core.types.isFunctionDeclaration(declaration) || __babel_core.types.isClassDeclaration(declaration)) && declaration.id) bindings.set(declaration.id.name, declaration.id.name);
287
+ continue;
288
+ }
289
+ if (__babel_core.types.isExpressionStatement(statement) && __babel_core.types.isAssignmentExpression(statement.expression)) {
290
+ const exportName = getCommonJsExportName(statement.expression.left);
291
+ if (exportName) bindings.set(exportName, exportName);
292
+ }
293
+ }
294
+ return bindings;
295
+ };
296
+ const getCommonJsExportName = (node) => {
297
+ if (!__babel_core.types.isMemberExpression(node) || node.computed) return null;
298
+ const isExports = __babel_core.types.isIdentifier(node.object, { name: "exports" });
299
+ const isModuleExports = __babel_core.types.isMemberExpression(node.object) && __babel_core.types.isIdentifier(node.object.object, { name: "module" }) && __babel_core.types.isIdentifier(node.object.property, { name: "exports" });
300
+ if (!isExports && !isModuleExports) return null;
301
+ if (__babel_core.types.isIdentifier(node.property)) return node.property.name;
302
+ if (__babel_core.types.isStringLiteral(node.property)) return node.property.value;
303
+ return null;
304
+ };
305
+ const createAnonymousNameFactory = () => {
306
+ const counters = /* @__PURE__ */ new Map();
307
+ return (kind) => {
308
+ const count = counters.get(kind) ?? 0;
309
+ counters.set(kind, count + 1);
310
+ return `${kind}#${count}`;
311
+ };
312
+ };
313
+ const isGqlDefinitionCall = (node) => __babel_core.types.isCallExpression(node) && __babel_core.types.isMemberExpression(node.callee) && isGqlReference(node.callee.object) && node.arguments.length > 0 && __babel_core.types.isArrowFunctionExpression(node.arguments[0]);
314
+ const isGqlReference = (expr) => {
315
+ if (__babel_core.types.isIdentifier(expr, { name: "gql" })) return true;
316
+ if (!__babel_core.types.isMemberExpression(expr) || expr.computed) return false;
317
+ if (__babel_core.types.isIdentifier(expr.property) && expr.property.name === "gql" || __babel_core.types.isStringLiteral(expr.property) && expr.property.value === "gql") return true;
318
+ return isGqlReference(expr.object);
319
+ };
320
+ const resolveTopLevelExport = (callPath, exportBindings) => {
321
+ const declarator = callPath.parentPath;
322
+ if (declarator?.isVariableDeclarator()) {
323
+ const { id } = declarator.node;
324
+ if (__babel_core.types.isIdentifier(id)) {
325
+ const exportBinding = exportBindings.get(id.name);
326
+ if (exportBinding) return {
327
+ isExported: true,
328
+ exportBinding
329
+ };
330
+ }
331
+ }
332
+ const assignment = callPath.parentPath;
333
+ if (assignment?.isAssignmentExpression()) {
334
+ const exportName = getCommonJsExportName(assignment.node.left);
335
+ if (exportName && exportBindings.has(exportName)) return {
336
+ isExported: true,
337
+ exportBinding: exportName
338
+ };
339
+ }
340
+ return null;
341
+ };
342
+ const maybeEnterScope = (path, tracker, getAnonymousName) => {
343
+ if (path.isAssignmentExpression()) {
344
+ const exportName = getCommonJsExportName(path.node.left);
345
+ if (exportName) return tracker.enterScope({
346
+ segment: exportName,
347
+ kind: "variable",
348
+ stableKey: `var:${exportName}`
349
+ });
350
+ }
351
+ if (path.isVariableDeclarator() && __babel_core.types.isIdentifier(path.node.id)) {
352
+ const name = path.node.id.name;
353
+ return tracker.enterScope({
354
+ segment: name,
355
+ kind: "variable",
356
+ stableKey: `var:${name}`
357
+ });
358
+ }
359
+ if (path.isArrowFunctionExpression()) {
360
+ const name = getAnonymousName("arrow");
361
+ return tracker.enterScope({
362
+ segment: name,
363
+ kind: "function",
364
+ stableKey: "arrow"
365
+ });
366
+ }
367
+ if (path.isFunctionDeclaration() || path.isFunctionExpression()) {
368
+ const name = path.node.id?.name ?? getAnonymousName("function");
369
+ return tracker.enterScope({
370
+ segment: name,
371
+ kind: "function",
372
+ stableKey: `func:${name}`
373
+ });
374
+ }
375
+ if (path.isClassDeclaration()) {
376
+ const name = path.node.id?.name ?? getAnonymousName("class");
377
+ return tracker.enterScope({
378
+ segment: name,
379
+ kind: "class",
380
+ stableKey: `class:${name}`
381
+ });
382
+ }
383
+ if (path.isClassMethod() && __babel_core.types.isIdentifier(path.node.key)) {
384
+ const name = path.node.key.name;
385
+ return tracker.enterScope({
386
+ segment: name,
387
+ kind: "method",
388
+ stableKey: `member:${name}`
389
+ });
390
+ }
391
+ if (path.isClassProperty() && __babel_core.types.isIdentifier(path.node.key)) {
392
+ const name = path.node.key.name;
393
+ return tracker.enterScope({
394
+ segment: name,
395
+ kind: "property",
396
+ stableKey: `member:${name}`
397
+ });
398
+ }
399
+ if (path.isObjectProperty()) {
400
+ const key = path.node.key;
401
+ const name = __babel_core.types.isIdentifier(key) ? key.name : __babel_core.types.isStringLiteral(key) ? key.value : null;
402
+ if (name) return tracker.enterScope({
403
+ segment: name,
404
+ kind: "property",
405
+ stableKey: `prop:${name}`
406
+ });
407
+ }
408
+ return null;
409
+ };
410
+
411
+ //#endregion
412
+ //#region packages/babel-transformer/src/ast/runtime.ts
413
+ const buildFragmentRuntimeCall = ({ artifact }) => {
414
+ return (0, neverthrow.ok)(__babel_core.types.callExpression(__babel_core.types.memberExpression(__babel_core.types.identifier("gqlRuntime"), __babel_core.types.identifier("fragment")), [buildObjectExpression({ prebuild: buildObjectExpression({ typename: __babel_core.types.stringLiteral(artifact.prebuild.typename) }) })]));
415
+ };
416
+ const buildOperationRuntimeComponents = ({ artifact }) => {
417
+ const runtimeCall = __babel_core.types.callExpression(__babel_core.types.memberExpression(__babel_core.types.identifier("gqlRuntime"), __babel_core.types.identifier("operation")), [buildObjectExpression({
418
+ prebuild: __babel_core.types.callExpression(__babel_core.types.memberExpression(__babel_core.types.identifier("JSON"), __babel_core.types.identifier("parse")), [__babel_core.types.stringLiteral(JSON.stringify(artifact.prebuild))]),
419
+ runtime: buildObjectExpression({})
420
+ })]);
421
+ return (0, neverthrow.ok)({
422
+ referenceCall: __babel_core.types.callExpression(__babel_core.types.memberExpression(__babel_core.types.identifier("gqlRuntime"), __babel_core.types.identifier("getOperation")), [__babel_core.types.stringLiteral(artifact.prebuild.operationName)]),
423
+ runtimeCall
424
+ });
425
+ };
426
+
427
+ //#endregion
428
+ //#region packages/babel-transformer/src/ast/transformer.ts
429
+ const transformCallExpression = ({ callPath, filename, metadata, getArtifact }) => {
430
+ if (!metadata.has(callPath.node)) return (0, neverthrow.ok)({ transformed: false });
431
+ const gqlCallResult = extractGqlCall({
432
+ nodePath: callPath,
433
+ filename,
434
+ metadata,
435
+ getArtifact
436
+ });
437
+ if (gqlCallResult.isErr()) return (0, neverthrow.err)(gqlCallResult.error);
438
+ const gqlCall = gqlCallResult.value;
439
+ return replaceWithRuntimeCall(callPath, gqlCall, filename);
440
+ };
441
+ const replaceWithRuntimeCall = (callPath, gqlCall, filename) => {
442
+ if (gqlCall.type === "fragment") {
443
+ const result = buildFragmentRuntimeCall({
444
+ ...gqlCall,
445
+ filename
446
+ });
447
+ if (result.isErr()) return (0, neverthrow.err)(result.error);
448
+ callPath.replaceWith(result.value);
449
+ return (0, neverthrow.ok)({ transformed: true });
450
+ }
451
+ if (gqlCall.type === "operation") {
452
+ const result = buildOperationRuntimeComponents({
453
+ ...gqlCall,
454
+ filename
455
+ });
456
+ if (result.isErr()) return (0, neverthrow.err)(result.error);
457
+ const { referenceCall, runtimeCall } = result.value;
458
+ callPath.replaceWith(referenceCall);
459
+ return (0, neverthrow.ok)({
460
+ transformed: true,
461
+ runtimeCall
462
+ });
463
+ }
464
+ return (0, neverthrow.ok)({ transformed: false });
465
+ };
466
+ const insertRuntimeCalls = (programPath, runtimeCalls) => {
467
+ if (runtimeCalls.length === 0) return;
468
+ programPath.traverse({ ImportDeclaration(importDeclPath) {
469
+ if (importDeclPath.node.source.value === "@soda-gql/runtime") importDeclPath.insertAfter([...runtimeCalls]);
470
+ } });
471
+ };
472
+
473
+ //#endregion
474
+ //#region node_modules/@jridgewell/sourcemap-codec/dist/sourcemap-codec.mjs
475
+ var comma = ",".charCodeAt(0);
476
+ var semicolon = ";".charCodeAt(0);
477
+ var chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
478
+ var intToChar = new Uint8Array(64);
479
+ var charToInt = new Uint8Array(128);
480
+ for (let i = 0; i < chars.length; i++) {
481
+ const c = chars.charCodeAt(i);
482
+ intToChar[i] = c;
483
+ charToInt[c] = i;
484
+ }
485
+ function decodeInteger(reader, relative) {
486
+ let value = 0;
487
+ let shift = 0;
488
+ let integer = 0;
489
+ do {
490
+ integer = charToInt[reader.next()];
491
+ value |= (integer & 31) << shift;
492
+ shift += 5;
493
+ } while (integer & 32);
494
+ const shouldNegate = value & 1;
495
+ value >>>= 1;
496
+ if (shouldNegate) value = -2147483648 | -value;
497
+ return relative + value;
498
+ }
499
+ function encodeInteger(builder, num, relative) {
500
+ let delta = num - relative;
501
+ delta = delta < 0 ? -delta << 1 | 1 : delta << 1;
502
+ do {
503
+ let clamped = delta & 31;
504
+ delta >>>= 5;
505
+ if (delta > 0) clamped |= 32;
506
+ builder.write(intToChar[clamped]);
507
+ } while (delta > 0);
508
+ return num;
509
+ }
510
+ function hasMoreVlq(reader, max) {
511
+ if (reader.pos >= max) return false;
512
+ return reader.peek() !== comma;
513
+ }
514
+ var bufLength = 1024 * 16;
515
+ var td = typeof TextDecoder !== "undefined" ? /* @__PURE__ */ new TextDecoder() : typeof Buffer !== "undefined" ? { decode(buf) {
516
+ return Buffer.from(buf.buffer, buf.byteOffset, buf.byteLength).toString();
517
+ } } : { decode(buf) {
518
+ let out = "";
519
+ for (let i = 0; i < buf.length; i++) out += String.fromCharCode(buf[i]);
520
+ return out;
521
+ } };
522
+ var StringWriter = class {
523
+ constructor() {
524
+ this.pos = 0;
525
+ this.out = "";
526
+ this.buffer = new Uint8Array(bufLength);
527
+ }
528
+ write(v) {
529
+ const { buffer } = this;
530
+ buffer[this.pos++] = v;
531
+ if (this.pos === bufLength) {
532
+ this.out += td.decode(buffer);
533
+ this.pos = 0;
534
+ }
535
+ }
536
+ flush() {
537
+ const { buffer, out, pos } = this;
538
+ return pos > 0 ? out + td.decode(buffer.subarray(0, pos)) : out;
539
+ }
540
+ };
541
+ var StringReader = class {
542
+ constructor(buffer) {
543
+ this.pos = 0;
544
+ this.buffer = buffer;
545
+ }
546
+ next() {
547
+ return this.buffer.charCodeAt(this.pos++);
548
+ }
549
+ peek() {
550
+ return this.buffer.charCodeAt(this.pos);
551
+ }
552
+ indexOf(char) {
553
+ const { buffer, pos } = this;
554
+ const idx = buffer.indexOf(char, pos);
555
+ return idx === -1 ? buffer.length : idx;
556
+ }
557
+ };
558
+ function decode(mappings) {
559
+ const { length } = mappings;
560
+ const reader = new StringReader(mappings);
561
+ const decoded = [];
562
+ let genColumn = 0;
563
+ let sourcesIndex = 0;
564
+ let sourceLine = 0;
565
+ let sourceColumn = 0;
566
+ let namesIndex = 0;
567
+ do {
568
+ const semi = reader.indexOf(";");
569
+ const line = [];
570
+ let sorted = true;
571
+ let lastCol = 0;
572
+ genColumn = 0;
573
+ while (reader.pos < semi) {
574
+ let seg;
575
+ genColumn = decodeInteger(reader, genColumn);
576
+ if (genColumn < lastCol) sorted = false;
577
+ lastCol = genColumn;
578
+ if (hasMoreVlq(reader, semi)) {
579
+ sourcesIndex = decodeInteger(reader, sourcesIndex);
580
+ sourceLine = decodeInteger(reader, sourceLine);
581
+ sourceColumn = decodeInteger(reader, sourceColumn);
582
+ if (hasMoreVlq(reader, semi)) {
583
+ namesIndex = decodeInteger(reader, namesIndex);
584
+ seg = [
585
+ genColumn,
586
+ sourcesIndex,
587
+ sourceLine,
588
+ sourceColumn,
589
+ namesIndex
590
+ ];
591
+ } else seg = [
592
+ genColumn,
593
+ sourcesIndex,
594
+ sourceLine,
595
+ sourceColumn
596
+ ];
597
+ } else seg = [genColumn];
598
+ line.push(seg);
599
+ reader.pos++;
600
+ }
601
+ if (!sorted) sort(line);
602
+ decoded.push(line);
603
+ reader.pos = semi + 1;
604
+ } while (reader.pos <= length);
605
+ return decoded;
606
+ }
607
+ function sort(line) {
608
+ line.sort(sortComparator$1);
609
+ }
610
+ function sortComparator$1(a, b) {
611
+ return a[0] - b[0];
612
+ }
613
+ function encode(decoded) {
614
+ const writer = new StringWriter();
615
+ let sourcesIndex = 0;
616
+ let sourceLine = 0;
617
+ let sourceColumn = 0;
618
+ let namesIndex = 0;
619
+ for (let i = 0; i < decoded.length; i++) {
620
+ const line = decoded[i];
621
+ if (i > 0) writer.write(semicolon);
622
+ if (line.length === 0) continue;
623
+ let genColumn = 0;
624
+ for (let j = 0; j < line.length; j++) {
625
+ const segment = line[j];
626
+ if (j > 0) writer.write(comma);
627
+ genColumn = encodeInteger(writer, segment[0], genColumn);
628
+ if (segment.length === 1) continue;
629
+ sourcesIndex = encodeInteger(writer, segment[1], sourcesIndex);
630
+ sourceLine = encodeInteger(writer, segment[2], sourceLine);
631
+ sourceColumn = encodeInteger(writer, segment[3], sourceColumn);
632
+ if (segment.length === 4) continue;
633
+ namesIndex = encodeInteger(writer, segment[4], namesIndex);
634
+ }
635
+ }
636
+ return writer.flush();
637
+ }
638
+
639
+ //#endregion
640
+ //#region node_modules/@jridgewell/resolve-uri/dist/resolve-uri.mjs
641
+ const schemeRegex = /^[\w+.-]+:\/\//;
642
+ /**
643
+ * Matches the parts of a URL:
644
+ * 1. Scheme, including ":", guaranteed.
645
+ * 2. User/password, including "@", optional.
646
+ * 3. Host, guaranteed.
647
+ * 4. Port, including ":", optional.
648
+ * 5. Path, including "/", optional.
649
+ * 6. Query, including "?", optional.
650
+ * 7. Hash, including "#", optional.
651
+ */
652
+ const urlRegex = /^([\w+.-]+:)\/\/([^@/#?]*@)?([^:/#?]*)(:\d+)?(\/[^#?]*)?(\?[^#]*)?(#.*)?/;
653
+ /**
654
+ * File URLs are weird. They dont' need the regular `//` in the scheme, they may or may not start
655
+ * with a leading `/`, they can have a domain (but only if they don't start with a Windows drive).
656
+ *
657
+ * 1. Host, optional.
658
+ * 2. Path, which may include "/", guaranteed.
659
+ * 3. Query, including "?", optional.
660
+ * 4. Hash, including "#", optional.
661
+ */
662
+ const fileRegex = /^file:(?:\/\/((?![a-z]:)[^/#?]*)?)?(\/?[^#?]*)(\?[^#]*)?(#.*)?/i;
663
+ function isAbsoluteUrl(input) {
664
+ return schemeRegex.test(input);
665
+ }
666
+ function isSchemeRelativeUrl(input) {
667
+ return input.startsWith("//");
668
+ }
669
+ function isAbsolutePath(input) {
670
+ return input.startsWith("/");
671
+ }
672
+ function isFileUrl(input) {
673
+ return input.startsWith("file:");
674
+ }
675
+ function isRelative(input) {
676
+ return /^[.?#]/.test(input);
677
+ }
678
+ function parseAbsoluteUrl(input) {
679
+ const match = urlRegex.exec(input);
680
+ return makeUrl(match[1], match[2] || "", match[3], match[4] || "", match[5] || "/", match[6] || "", match[7] || "");
681
+ }
682
+ function parseFileUrl(input) {
683
+ const match = fileRegex.exec(input);
684
+ const path = match[2];
685
+ return makeUrl("file:", "", match[1] || "", "", isAbsolutePath(path) ? path : "/" + path, match[3] || "", match[4] || "");
686
+ }
687
+ function makeUrl(scheme, user, host, port, path, query, hash) {
688
+ return {
689
+ scheme,
690
+ user,
691
+ host,
692
+ port,
693
+ path,
694
+ query,
695
+ hash,
696
+ type: 7
697
+ };
698
+ }
699
+ function parseUrl(input) {
700
+ if (isSchemeRelativeUrl(input)) {
701
+ const url$1 = parseAbsoluteUrl("http:" + input);
702
+ url$1.scheme = "";
703
+ url$1.type = 6;
704
+ return url$1;
705
+ }
706
+ if (isAbsolutePath(input)) {
707
+ const url$1 = parseAbsoluteUrl("http://foo.com" + input);
708
+ url$1.scheme = "";
709
+ url$1.host = "";
710
+ url$1.type = 5;
711
+ return url$1;
712
+ }
713
+ if (isFileUrl(input)) return parseFileUrl(input);
714
+ if (isAbsoluteUrl(input)) return parseAbsoluteUrl(input);
715
+ const url = parseAbsoluteUrl("http://foo.com/" + input);
716
+ url.scheme = "";
717
+ url.host = "";
718
+ url.type = input ? input.startsWith("?") ? 3 : input.startsWith("#") ? 2 : 4 : 1;
719
+ return url;
720
+ }
721
+ function stripPathFilename(path) {
722
+ if (path.endsWith("/..")) return path;
723
+ const index = path.lastIndexOf("/");
724
+ return path.slice(0, index + 1);
725
+ }
726
+ function mergePaths(url, base) {
727
+ normalizePath(base, base.type);
728
+ if (url.path === "/") url.path = base.path;
729
+ else url.path = stripPathFilename(base.path) + url.path;
730
+ }
731
+ /**
732
+ * The path can have empty directories "//", unneeded parents "foo/..", or current directory
733
+ * "foo/.". We need to normalize to a standard representation.
734
+ */
735
+ function normalizePath(url, type) {
736
+ const rel = type <= 4;
737
+ const pieces = url.path.split("/");
738
+ let pointer = 1;
739
+ let positive = 0;
740
+ let addTrailingSlash = false;
741
+ for (let i = 1; i < pieces.length; i++) {
742
+ const piece = pieces[i];
743
+ if (!piece) {
744
+ addTrailingSlash = true;
745
+ continue;
746
+ }
747
+ addTrailingSlash = false;
748
+ if (piece === ".") continue;
749
+ if (piece === "..") {
750
+ if (positive) {
751
+ addTrailingSlash = true;
752
+ positive--;
753
+ pointer--;
754
+ } else if (rel) pieces[pointer++] = piece;
755
+ continue;
756
+ }
757
+ pieces[pointer++] = piece;
758
+ positive++;
759
+ }
760
+ let path = "";
761
+ for (let i = 1; i < pointer; i++) path += "/" + pieces[i];
762
+ if (!path || addTrailingSlash && !path.endsWith("/..")) path += "/";
763
+ url.path = path;
764
+ }
765
+ /**
766
+ * Attempts to resolve `input` URL/path relative to `base`.
767
+ */
768
+ function resolve(input, base) {
769
+ if (!input && !base) return "";
770
+ const url = parseUrl(input);
771
+ let inputType = url.type;
772
+ if (base && inputType !== 7) {
773
+ const baseUrl = parseUrl(base);
774
+ const baseType = baseUrl.type;
775
+ switch (inputType) {
776
+ case 1: url.hash = baseUrl.hash;
777
+ case 2: url.query = baseUrl.query;
778
+ case 3:
779
+ case 4: mergePaths(url, baseUrl);
780
+ case 5:
781
+ url.user = baseUrl.user;
782
+ url.host = baseUrl.host;
783
+ url.port = baseUrl.port;
784
+ case 6: url.scheme = baseUrl.scheme;
785
+ }
786
+ if (baseType > inputType) inputType = baseType;
787
+ }
788
+ normalizePath(url, inputType);
789
+ const queryHash = url.query + url.hash;
790
+ switch (inputType) {
791
+ case 2:
792
+ case 3: return queryHash;
793
+ case 4: {
794
+ const path = url.path.slice(1);
795
+ if (!path) return queryHash || ".";
796
+ if (isRelative(base || input) && !isRelative(path)) return "./" + path + queryHash;
797
+ return path + queryHash;
798
+ }
799
+ case 5: return url.path + queryHash;
800
+ default: return url.scheme + "//" + url.user + url.host + url.port + url.path + queryHash;
801
+ }
802
+ }
803
+
804
+ //#endregion
805
+ //#region node_modules/@jridgewell/trace-mapping/dist/trace-mapping.mjs
806
+ function stripFilename(path) {
807
+ if (!path) return "";
808
+ const index = path.lastIndexOf("/");
809
+ return path.slice(0, index + 1);
810
+ }
811
+ function resolver(mapUrl, sourceRoot) {
812
+ const from = stripFilename(mapUrl);
813
+ const prefix = sourceRoot ? sourceRoot + "/" : "";
814
+ return (source) => resolve(prefix + (source || ""), from);
815
+ }
816
+ var COLUMN$1 = 0;
817
+ function maybeSort(mappings, owned) {
818
+ const unsortedIndex = nextUnsortedSegmentLine(mappings, 0);
819
+ if (unsortedIndex === mappings.length) return mappings;
820
+ if (!owned) mappings = mappings.slice();
821
+ for (let i = unsortedIndex; i < mappings.length; i = nextUnsortedSegmentLine(mappings, i + 1)) mappings[i] = sortSegments(mappings[i], owned);
822
+ return mappings;
823
+ }
824
+ function nextUnsortedSegmentLine(mappings, start) {
825
+ for (let i = start; i < mappings.length; i++) if (!isSorted(mappings[i])) return i;
826
+ return mappings.length;
827
+ }
828
+ function isSorted(line) {
829
+ for (let j = 1; j < line.length; j++) if (line[j][COLUMN$1] < line[j - 1][COLUMN$1]) return false;
830
+ return true;
831
+ }
832
+ function sortSegments(line, owned) {
833
+ if (!owned) line = line.slice();
834
+ return line.sort(sortComparator);
835
+ }
836
+ function sortComparator(a, b) {
837
+ return a[COLUMN$1] - b[COLUMN$1];
838
+ }
839
+ var found = false;
840
+ function binarySearch(haystack, needle, low, high) {
841
+ while (low <= high) {
842
+ const mid = low + (high - low >> 1);
843
+ const cmp = haystack[mid][COLUMN$1] - needle;
844
+ if (cmp === 0) {
845
+ found = true;
846
+ return mid;
847
+ }
848
+ if (cmp < 0) low = mid + 1;
849
+ else high = mid - 1;
850
+ }
851
+ found = false;
852
+ return low - 1;
853
+ }
854
+ function upperBound(haystack, needle, index) {
855
+ for (let i = index + 1; i < haystack.length; index = i++) if (haystack[i][COLUMN$1] !== needle) break;
856
+ return index;
857
+ }
858
+ function lowerBound(haystack, needle, index) {
859
+ for (let i = index - 1; i >= 0; index = i--) if (haystack[i][COLUMN$1] !== needle) break;
860
+ return index;
861
+ }
862
+ function memoizedState() {
863
+ return {
864
+ lastKey: -1,
865
+ lastNeedle: -1,
866
+ lastIndex: -1
867
+ };
868
+ }
869
+ function memoizedBinarySearch(haystack, needle, state, key) {
870
+ const { lastKey, lastNeedle, lastIndex } = state;
871
+ let low = 0;
872
+ let high = haystack.length - 1;
873
+ if (key === lastKey) {
874
+ if (needle === lastNeedle) {
875
+ found = lastIndex !== -1 && haystack[lastIndex][COLUMN$1] === needle;
876
+ return lastIndex;
877
+ }
878
+ if (needle >= lastNeedle) low = lastIndex === -1 ? 0 : lastIndex;
879
+ else high = lastIndex;
880
+ }
881
+ state.lastKey = key;
882
+ state.lastNeedle = needle;
883
+ return state.lastIndex = binarySearch(haystack, needle, low, high);
884
+ }
885
+ function parse$1(map) {
886
+ return typeof map === "string" ? JSON.parse(map) : map;
887
+ }
888
+ var LEAST_UPPER_BOUND = -1;
889
+ var GREATEST_LOWER_BOUND = 1;
890
+ var TraceMap = class {
891
+ constructor(map, mapUrl) {
892
+ const isString = typeof map === "string";
893
+ if (!isString && map._decodedMemo) return map;
894
+ const parsed = parse$1(map);
895
+ const { version, file, names, sourceRoot, sources, sourcesContent } = parsed;
896
+ this.version = version;
897
+ this.file = file;
898
+ this.names = names || [];
899
+ this.sourceRoot = sourceRoot;
900
+ this.sources = sources;
901
+ this.sourcesContent = sourcesContent;
902
+ this.ignoreList = parsed.ignoreList || parsed.x_google_ignoreList || void 0;
903
+ const resolve$1 = resolver(mapUrl, sourceRoot);
904
+ this.resolvedSources = sources.map(resolve$1);
905
+ const { mappings } = parsed;
906
+ if (typeof mappings === "string") {
907
+ this._encoded = mappings;
908
+ this._decoded = void 0;
909
+ } else if (Array.isArray(mappings)) {
910
+ this._encoded = void 0;
911
+ this._decoded = maybeSort(mappings, isString);
912
+ } else if (parsed.sections) throw new Error(`TraceMap passed sectioned source map, please use FlattenMap export instead`);
913
+ else throw new Error(`invalid source map: ${JSON.stringify(parsed)}`);
914
+ this._decodedMemo = memoizedState();
915
+ this._bySources = void 0;
916
+ this._bySourceMemos = void 0;
917
+ }
918
+ };
919
+ function cast$1(map) {
920
+ return map;
921
+ }
922
+ function decodedMappings(map) {
923
+ var _a;
924
+ return (_a = cast$1(map))._decoded || (_a._decoded = decode(cast$1(map)._encoded));
925
+ }
926
+ function traceSegment(map, line, column) {
927
+ const decoded = decodedMappings(map);
928
+ if (line >= decoded.length) return null;
929
+ const segments = decoded[line];
930
+ const index = traceSegmentInternal(segments, cast$1(map)._decodedMemo, line, column, GREATEST_LOWER_BOUND);
931
+ return index === -1 ? null : segments[index];
932
+ }
933
+ function traceSegmentInternal(segments, memo, line, column, bias) {
934
+ let index = memoizedBinarySearch(segments, column, memo, line);
935
+ if (found) index = (bias === LEAST_UPPER_BOUND ? upperBound : lowerBound)(segments, column, index);
936
+ else if (bias === LEAST_UPPER_BOUND) index++;
937
+ if (index === -1 || index === segments.length) return -1;
938
+ return index;
939
+ }
940
+
941
+ //#endregion
942
+ //#region node_modules/@jridgewell/gen-mapping/dist/gen-mapping.mjs
943
+ var SetArray = class {
944
+ constructor() {
945
+ this._indexes = { __proto__: null };
946
+ this.array = [];
947
+ }
948
+ };
949
+ function cast(set) {
950
+ return set;
951
+ }
952
+ function get(setarr, key) {
953
+ return cast(setarr)._indexes[key];
954
+ }
955
+ function put(setarr, key) {
956
+ const index = get(setarr, key);
957
+ if (index !== void 0) return index;
958
+ const { array, _indexes: indexes } = cast(setarr);
959
+ return indexes[key] = array.push(key) - 1;
960
+ }
961
+ function remove(setarr, key) {
962
+ const index = get(setarr, key);
963
+ if (index === void 0) return;
964
+ const { array, _indexes: indexes } = cast(setarr);
965
+ for (let i = index + 1; i < array.length; i++) {
966
+ const k = array[i];
967
+ array[i - 1] = k;
968
+ indexes[k]--;
969
+ }
970
+ indexes[key] = void 0;
971
+ array.pop();
972
+ }
973
+ var COLUMN = 0;
974
+ var SOURCES_INDEX = 1;
975
+ var SOURCE_LINE = 2;
976
+ var SOURCE_COLUMN = 3;
977
+ var NAMES_INDEX = 4;
978
+ var NO_NAME = -1;
979
+ var GenMapping = class {
980
+ constructor({ file, sourceRoot } = {}) {
981
+ this._names = new SetArray();
982
+ this._sources = new SetArray();
983
+ this._sourcesContent = [];
984
+ this._mappings = [];
985
+ this.file = file;
986
+ this.sourceRoot = sourceRoot;
987
+ this._ignoreList = new SetArray();
988
+ }
989
+ };
990
+ function cast2(map) {
991
+ return map;
992
+ }
993
+ var maybeAddSegment = (map, genLine, genColumn, source, sourceLine, sourceColumn, name, content) => {
994
+ return addSegmentInternal(true, map, genLine, genColumn, source, sourceLine, sourceColumn, name, content);
995
+ };
996
+ function setSourceContent(map, source, content) {
997
+ const { _sources: sources, _sourcesContent: sourcesContent } = cast2(map);
998
+ const index = put(sources, source);
999
+ sourcesContent[index] = content;
1000
+ }
1001
+ function setIgnore(map, source, ignore = true) {
1002
+ const { _sources: sources, _sourcesContent: sourcesContent, _ignoreList: ignoreList } = cast2(map);
1003
+ const index = put(sources, source);
1004
+ if (index === sourcesContent.length) sourcesContent[index] = null;
1005
+ if (ignore) put(ignoreList, index);
1006
+ else remove(ignoreList, index);
1007
+ }
1008
+ function toDecodedMap(map) {
1009
+ const { _mappings: mappings, _sources: sources, _sourcesContent: sourcesContent, _names: names, _ignoreList: ignoreList } = cast2(map);
1010
+ removeEmptyFinalLines(mappings);
1011
+ return {
1012
+ version: 3,
1013
+ file: map.file || void 0,
1014
+ names: names.array,
1015
+ sourceRoot: map.sourceRoot || void 0,
1016
+ sources: sources.array,
1017
+ sourcesContent,
1018
+ mappings,
1019
+ ignoreList: ignoreList.array
1020
+ };
1021
+ }
1022
+ function toEncodedMap(map) {
1023
+ const decoded = toDecodedMap(map);
1024
+ return Object.assign({}, decoded, { mappings: encode(decoded.mappings) });
1025
+ }
1026
+ function addSegmentInternal(skipable, map, genLine, genColumn, source, sourceLine, sourceColumn, name, content) {
1027
+ const { _mappings: mappings, _sources: sources, _sourcesContent: sourcesContent, _names: names } = cast2(map);
1028
+ const line = getIndex(mappings, genLine);
1029
+ const index = getColumnIndex(line, genColumn);
1030
+ if (!source) {
1031
+ if (skipable && skipSourceless(line, index)) return;
1032
+ return insert(line, index, [genColumn]);
1033
+ }
1034
+ assert(sourceLine);
1035
+ assert(sourceColumn);
1036
+ const sourcesIndex = put(sources, source);
1037
+ const namesIndex = name ? put(names, name) : NO_NAME;
1038
+ if (sourcesIndex === sourcesContent.length) sourcesContent[sourcesIndex] = content != null ? content : null;
1039
+ if (skipable && skipSource(line, index, sourcesIndex, sourceLine, sourceColumn, namesIndex)) return;
1040
+ return insert(line, index, name ? [
1041
+ genColumn,
1042
+ sourcesIndex,
1043
+ sourceLine,
1044
+ sourceColumn,
1045
+ namesIndex
1046
+ ] : [
1047
+ genColumn,
1048
+ sourcesIndex,
1049
+ sourceLine,
1050
+ sourceColumn
1051
+ ]);
1052
+ }
1053
+ function assert(_val) {}
1054
+ function getIndex(arr, index) {
1055
+ for (let i = arr.length; i <= index; i++) arr[i] = [];
1056
+ return arr[index];
1057
+ }
1058
+ function getColumnIndex(line, genColumn) {
1059
+ let index = line.length;
1060
+ for (let i = index - 1; i >= 0; index = i--) if (genColumn >= line[i][COLUMN]) break;
1061
+ return index;
1062
+ }
1063
+ function insert(array, index, value) {
1064
+ for (let i = array.length; i > index; i--) array[i] = array[i - 1];
1065
+ array[index] = value;
1066
+ }
1067
+ function removeEmptyFinalLines(mappings) {
1068
+ const { length } = mappings;
1069
+ let len = length;
1070
+ for (let i = len - 1; i >= 0; len = i, i--) if (mappings[i].length > 0) break;
1071
+ if (len < length) mappings.length = len;
1072
+ }
1073
+ function skipSourceless(line, index) {
1074
+ if (index === 0) return true;
1075
+ return line[index - 1].length === 1;
1076
+ }
1077
+ function skipSource(line, index, sourcesIndex, sourceLine, sourceColumn, namesIndex) {
1078
+ if (index === 0) return false;
1079
+ const prev = line[index - 1];
1080
+ if (prev.length === 1) return false;
1081
+ return sourcesIndex === prev[SOURCES_INDEX] && sourceLine === prev[SOURCE_LINE] && sourceColumn === prev[SOURCE_COLUMN] && namesIndex === (prev.length === 5 ? prev[NAMES_INDEX] : NO_NAME);
1082
+ }
1083
+
1084
+ //#endregion
1085
+ //#region node_modules/@ampproject/remapping/dist/remapping.mjs
1086
+ const SOURCELESS_MAPPING = /* @__PURE__ */ SegmentObject("", -1, -1, "", null, false);
1087
+ const EMPTY_SOURCES = [];
1088
+ function SegmentObject(source, line, column, name, content, ignore) {
1089
+ return {
1090
+ source,
1091
+ line,
1092
+ column,
1093
+ name,
1094
+ content,
1095
+ ignore
1096
+ };
1097
+ }
1098
+ function Source(map, sources, source, content, ignore) {
1099
+ return {
1100
+ map,
1101
+ sources,
1102
+ source,
1103
+ content,
1104
+ ignore
1105
+ };
1106
+ }
1107
+ /**
1108
+ * MapSource represents a single sourcemap, with the ability to trace mappings into its child nodes
1109
+ * (which may themselves be SourceMapTrees).
1110
+ */
1111
+ function MapSource(map, sources) {
1112
+ return Source(map, sources, "", null, false);
1113
+ }
1114
+ /**
1115
+ * A "leaf" node in the sourcemap tree, representing an original, unmodified source file. Recursive
1116
+ * segment tracing ends at the `OriginalSource`.
1117
+ */
1118
+ function OriginalSource(source, content, ignore) {
1119
+ return Source(null, EMPTY_SOURCES, source, content, ignore);
1120
+ }
1121
+ /**
1122
+ * traceMappings is only called on the root level SourceMapTree, and begins the process of
1123
+ * resolving each mapping in terms of the original source files.
1124
+ */
1125
+ function traceMappings(tree) {
1126
+ const gen = new GenMapping({ file: tree.map.file });
1127
+ const { sources: rootSources, map } = tree;
1128
+ const rootNames = map.names;
1129
+ const rootMappings = decodedMappings(map);
1130
+ for (let i = 0; i < rootMappings.length; i++) {
1131
+ const segments = rootMappings[i];
1132
+ for (let j = 0; j < segments.length; j++) {
1133
+ const segment = segments[j];
1134
+ const genCol = segment[0];
1135
+ let traced = SOURCELESS_MAPPING;
1136
+ if (segment.length !== 1) {
1137
+ const source$1 = rootSources[segment[1]];
1138
+ traced = originalPositionFor(source$1, segment[2], segment[3], segment.length === 5 ? rootNames[segment[4]] : "");
1139
+ if (traced == null) continue;
1140
+ }
1141
+ const { column, line, name, content, source, ignore } = traced;
1142
+ maybeAddSegment(gen, i, genCol, source, line, column, name);
1143
+ if (source && content != null) setSourceContent(gen, source, content);
1144
+ if (ignore) setIgnore(gen, source, true);
1145
+ }
1146
+ }
1147
+ return gen;
1148
+ }
1149
+ /**
1150
+ * originalPositionFor is only called on children SourceMapTrees. It recurses down into its own
1151
+ * child SourceMapTrees, until we find the original source map.
1152
+ */
1153
+ function originalPositionFor(source, line, column, name) {
1154
+ if (!source.map) return SegmentObject(source.source, line, column, name, source.content, source.ignore);
1155
+ const segment = traceSegment(source.map, line, column);
1156
+ if (segment == null) return null;
1157
+ if (segment.length === 1) return SOURCELESS_MAPPING;
1158
+ return originalPositionFor(source.sources[segment[1]], segment[2], segment[3], segment.length === 5 ? source.map.names[segment[4]] : name);
1159
+ }
1160
+ function asArray(value) {
1161
+ if (Array.isArray(value)) return value;
1162
+ return [value];
1163
+ }
1164
+ /**
1165
+ * Recursively builds a tree structure out of sourcemap files, with each node
1166
+ * being either an `OriginalSource` "leaf" or a `SourceMapTree` composed of
1167
+ * `OriginalSource`s and `SourceMapTree`s.
1168
+ *
1169
+ * Every sourcemap is composed of a collection of source files and mappings
1170
+ * into locations of those source files. When we generate a `SourceMapTree` for
1171
+ * the sourcemap, we attempt to load each source file's own sourcemap. If it
1172
+ * does not have an associated sourcemap, it is considered an original,
1173
+ * unmodified source file.
1174
+ */
1175
+ function buildSourceMapTree(input, loader) {
1176
+ const maps = asArray(input).map((m) => new TraceMap(m, ""));
1177
+ const map = maps.pop();
1178
+ for (let i = 0; i < maps.length; i++) if (maps[i].sources.length > 1) throw new Error(`Transformation map ${i} must have exactly one source file.\nDid you specify these with the most recent transformation maps first?`);
1179
+ let tree = build(map, loader, "", 0);
1180
+ for (let i = maps.length - 1; i >= 0; i--) tree = MapSource(maps[i], [tree]);
1181
+ return tree;
1182
+ }
1183
+ function build(map, loader, importer, importerDepth) {
1184
+ const { resolvedSources, sourcesContent, ignoreList } = map;
1185
+ const depth = importerDepth + 1;
1186
+ return MapSource(map, resolvedSources.map((sourceFile, i) => {
1187
+ const ctx = {
1188
+ importer,
1189
+ depth,
1190
+ source: sourceFile || "",
1191
+ content: void 0,
1192
+ ignore: void 0
1193
+ };
1194
+ const sourceMap = loader(ctx.source, ctx);
1195
+ const { source, content, ignore } = ctx;
1196
+ if (sourceMap) return build(new TraceMap(sourceMap, source), loader, source, depth);
1197
+ return OriginalSource(source, content !== void 0 ? content : sourcesContent ? sourcesContent[i] : null, ignore !== void 0 ? ignore : ignoreList ? ignoreList.includes(i) : false);
1198
+ }));
1199
+ }
1200
+ /**
1201
+ * A SourceMap v3 compatible sourcemap, which only includes fields that were
1202
+ * provided to it.
1203
+ */
1204
+ var SourceMap = class {
1205
+ constructor(map, options) {
1206
+ const out = options.decodedMappings ? toDecodedMap(map) : toEncodedMap(map);
1207
+ this.version = out.version;
1208
+ this.file = out.file;
1209
+ this.mappings = out.mappings;
1210
+ this.names = out.names;
1211
+ this.ignoreList = out.ignoreList;
1212
+ this.sourceRoot = out.sourceRoot;
1213
+ this.sources = out.sources;
1214
+ if (!options.excludeContent) this.sourcesContent = out.sourcesContent;
1215
+ }
1216
+ toString() {
1217
+ return JSON.stringify(this);
1218
+ }
1219
+ };
1220
+ /**
1221
+ * Traces through all the mappings in the root sourcemap, through the sources
1222
+ * (and their sourcemaps), all the way back to the original source location.
1223
+ *
1224
+ * `loader` will be called every time we encounter a source file. If it returns
1225
+ * a sourcemap, we will recurse into that sourcemap to continue the trace. If
1226
+ * it returns a falsey value, that source file is treated as an original,
1227
+ * unmodified source file.
1228
+ *
1229
+ * Pass `excludeContent` to exclude any self-containing source file content
1230
+ * from the output sourcemap.
1231
+ *
1232
+ * Pass `decodedMappings` to receive a SourceMap with decoded (instead of
1233
+ * VLQ encoded) mappings.
1234
+ */
1235
+ function remapping(input, loader, options) {
1236
+ const opts = typeof options === "object" ? options : {
1237
+ excludeContent: !!options,
1238
+ decodedMappings: false
1239
+ };
1240
+ return new SourceMap(traceMappings(buildSourceMapTree(input, loader)), opts);
1241
+ }
1242
+
1243
+ //#endregion
1244
+ //#region packages/babel-transformer/src/transformer.ts
1245
+ /**
1246
+ * Creates a Babel transformer with a single transform() method.
1247
+ * This matches the pattern used in the TypeScript plugin.
1248
+ */
1249
+ const createTransformer = ({ programPath, types, config }) => {
1250
+ const graphqlSystemIdentifyHelper = (0, __soda_gql_builder.createGraphqlSystemIdentifyHelper)(config);
1251
+ /**
1252
+ * Check if a node is a require() or __webpack_require__() call.
1253
+ */
1254
+ const isRequireCall = (node) => {
1255
+ if (!types.isCallExpression(node)) return false;
1256
+ const callee = node.callee;
1257
+ return types.isIdentifier(callee) && (callee.name === "require" || callee.name === "__webpack_require__");
1258
+ };
1259
+ /**
1260
+ * Find the last statement that loads a module (import or require).
1261
+ * Handles both ESM imports and CommonJS require() calls.
1262
+ */
1263
+ const findLastModuleLoader = () => {
1264
+ const bodyPaths = programPath.get("body");
1265
+ let lastLoader = null;
1266
+ for (const path of bodyPaths) {
1267
+ if (path.isImportDeclaration()) {
1268
+ lastLoader = path;
1269
+ continue;
1270
+ }
1271
+ if (path.isVariableDeclaration()) {
1272
+ for (const declarator of path.node.declarations) if (declarator.init && isRequireCall(declarator.init)) {
1273
+ lastLoader = path;
1274
+ break;
1275
+ }
1276
+ continue;
1277
+ }
1278
+ if (path.isExpressionStatement()) {
1279
+ if (isRequireCall(path.node.expression)) lastLoader = path;
1280
+ }
1281
+ }
1282
+ return lastLoader;
1283
+ };
1284
+ return { transform: (context) => {
1285
+ const metadata = collectGqlDefinitionMetadata({
1286
+ programPath,
1287
+ filename: context.filename
1288
+ });
1289
+ const runtimeCalls = [];
1290
+ let transformed = false;
1291
+ programPath.traverse({ CallExpression: (callPath) => {
1292
+ const result = transformCallExpression({
1293
+ callPath,
1294
+ filename: context.filename,
1295
+ metadata,
1296
+ getArtifact: context.artifactLookup
1297
+ });
1298
+ if (result.isErr()) {
1299
+ console.error(`[@soda-gql/babel-transformer] ${(0, __soda_gql_plugin_common.formatPluginError)(result.error)}`);
1300
+ return;
1301
+ }
1302
+ const transformResult = result.value;
1303
+ if (transformResult.transformed) {
1304
+ transformed = true;
1305
+ if (transformResult.runtimeCall) runtimeCalls.push(transformResult.runtimeCall);
1306
+ }
1307
+ } });
1308
+ if (!transformed) return {
1309
+ transformed: false,
1310
+ runtimeArtifacts: void 0
1311
+ };
1312
+ ensureGqlRuntimeImport(programPath);
1313
+ if (runtimeCalls.length > 0) {
1314
+ const statements = runtimeCalls.map((expr) => types.expressionStatement(expr));
1315
+ const lastLoaderPath = findLastModuleLoader();
1316
+ if (lastLoaderPath) lastLoaderPath.insertAfter(statements);
1317
+ else programPath.unshiftContainer("body", statements);
1318
+ }
1319
+ programPath.scope.crawl();
1320
+ removeGraphqlSystemImports(programPath, graphqlSystemIdentifyHelper, context.filename);
1321
+ return {
1322
+ transformed: true,
1323
+ runtimeArtifacts: void 0
1324
+ };
1325
+ } };
1326
+ };
1327
+
1328
+ //#endregion
1329
+ //#region packages/babel-transformer/src/transform.ts
1330
+ /**
1331
+ * Source-code based transform function for babel-transformer.
1332
+ *
1333
+ * This provides a similar interface to swc-transformer, taking source code
1334
+ * as input and returning transformed source code.
1335
+ */
1336
+ const traverse = typeof __babel_traverse.default === "function" ? __babel_traverse.default : __babel_traverse.default.default;
1337
+ const generate = typeof __babel_generator.default === "function" ? __babel_generator.default : __babel_generator.default.default;
1338
+ /**
1339
+ * Create a transformer instance.
1340
+ *
1341
+ * @param options - Transform options including config and artifact
1342
+ * @returns A transformer that can transform source files
1343
+ */
1344
+ const createBabelTransformer = (options) => {
1345
+ const { config, artifact, sourceMap = false } = options;
1346
+ return { transform: ({ sourceCode, sourcePath, inputSourceMap }) => {
1347
+ const ast = (0, __babel_parser.parse)(sourceCode, {
1348
+ sourceType: "module",
1349
+ plugins: ["typescript", "jsx"],
1350
+ sourceFilename: sourcePath
1351
+ });
1352
+ let programPath = null;
1353
+ traverse(ast, { Program(path) {
1354
+ programPath = path;
1355
+ path.stop();
1356
+ } });
1357
+ if (!programPath) return {
1358
+ transformed: false,
1359
+ sourceCode,
1360
+ sourceMap: void 0
1361
+ };
1362
+ if (!createTransformer({
1363
+ programPath,
1364
+ types: __babel_core.types,
1365
+ config
1366
+ }).transform({
1367
+ filename: sourcePath,
1368
+ artifactLookup: (canonicalId) => artifact.elements[canonicalId]
1369
+ }).transformed) return {
1370
+ transformed: false,
1371
+ sourceCode,
1372
+ sourceMap: void 0
1373
+ };
1374
+ const output = generate(ast, {
1375
+ sourceMaps: sourceMap,
1376
+ sourceFileName: sourcePath
1377
+ }, sourceCode);
1378
+ let finalSourceMap;
1379
+ if (sourceMap && output.map) if (inputSourceMap) {
1380
+ const merged = remapping([output.map, JSON.parse(inputSourceMap)], () => null);
1381
+ finalSourceMap = JSON.stringify(merged);
1382
+ } else finalSourceMap = JSON.stringify(output.map);
1383
+ return {
1384
+ transformed: true,
1385
+ sourceCode: output.code,
1386
+ sourceMap: finalSourceMap
1387
+ };
1388
+ } };
1389
+ };
1390
+ /**
1391
+ * Transform a single source file (one-shot).
1392
+ *
1393
+ * For transforming multiple files, use createBabelTransformer() to reuse the artifact.
1394
+ *
1395
+ * @param input - Transform input including source, path, artifact, and config
1396
+ * @returns Transform output
1397
+ */
1398
+ const transform = (input) => {
1399
+ return createBabelTransformer({
1400
+ config: input.config,
1401
+ artifact: input.artifact,
1402
+ sourceMap: input.sourceMap
1403
+ }).transform({
1404
+ sourceCode: input.sourceCode,
1405
+ sourcePath: input.sourcePath,
1406
+ inputSourceMap: input.inputSourceMap
1407
+ });
1408
+ };
1409
+
1410
+ //#endregion
1411
+ exports.buildFragmentRuntimeCall = buildFragmentRuntimeCall;
1412
+ exports.buildLiteralFromValue = buildLiteralFromValue;
1413
+ exports.buildObjectExpression = buildObjectExpression;
1414
+ exports.buildOperationRuntimeComponents = buildOperationRuntimeComponents;
1415
+ exports.clone = clone;
1416
+ exports.cloneCallExpression = cloneCallExpression;
1417
+ exports.collectGqlDefinitionMetadata = collectGqlDefinitionMetadata;
1418
+ exports.createBabelTransformer = createBabelTransformer;
1419
+ exports.createTransformer = createTransformer;
1420
+ exports.ensureGqlRuntimeImport = ensureGqlRuntimeImport;
1421
+ exports.ensureGqlRuntimeRequire = ensureGqlRuntimeRequire;
1422
+ exports.extractGqlCall = extractGqlCall;
1423
+ exports.insertRuntimeCalls = insertRuntimeCalls;
1424
+ exports.removeGraphqlSystemImports = removeGraphqlSystemImports;
1425
+ exports.stripTypeAnnotations = stripTypeAnnotations;
1426
+ exports.transform = transform;
1427
+ exports.transformCallExpression = transformCallExpression;
1428
+ //# sourceMappingURL=index.cjs.map