@generaltranslation/vue-extractor 0.0.0 → 0.1.0-iris.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.
Files changed (87) hide show
  1. package/LICENSE.md +18 -102
  2. package/dist/detect.d.ts +8 -0
  3. package/dist/detect.js +2 -0
  4. package/dist/index.d.ts +3 -1
  5. package/dist/index.js +2 -1
  6. package/dist/inspect.d.ts +9 -0
  7. package/dist/inspect.js +2 -0
  8. package/dist/integration.d.ts +69 -0
  9. package/dist/integration.js +162 -0
  10. package/dist/integration.js.map +1 -0
  11. package/dist/internal/config/configFiles.d.ts +6 -0
  12. package/dist/internal/config/configFiles.js +34 -0
  13. package/dist/internal/config/configFiles.js.map +1 -0
  14. package/dist/internal/config/resolveVueCompilerOptions.d.ts +6 -0
  15. package/dist/internal/config/resolveVueCompilerOptions.js +74 -56
  16. package/dist/internal/config/resolveVueCompilerOptions.js.map +1 -1
  17. package/dist/internal/extractFromVueSource.d.ts +4 -3
  18. package/dist/internal/extractFromVueSource.js +255 -12
  19. package/dist/internal/extractFromVueSource.js.map +1 -1
  20. package/dist/internal/project/consumerUsage.d.ts +34 -0
  21. package/dist/internal/project/consumerUsage.js +1220 -0
  22. package/dist/internal/project/consumerUsage.js.map +1 -0
  23. package/dist/internal/project/detectVueProject.d.ts +13 -0
  24. package/dist/internal/project/detectVueProject.js +65 -0
  25. package/dist/internal/project/detectVueProject.js.map +1 -0
  26. package/dist/internal/project/extractFromVueProject.d.ts +10 -0
  27. package/dist/internal/project/extractFromVueProject.js +579 -0
  28. package/dist/internal/project/extractFromVueProject.js.map +1 -0
  29. package/dist/internal/project/inspectVueProject.d.ts +48 -0
  30. package/dist/internal/project/inspectVueProject.js +143 -0
  31. package/dist/internal/project/inspectVueProject.js.map +1 -0
  32. package/dist/internal/project/manifest.d.ts +64 -0
  33. package/dist/internal/project/manifest.js +270 -0
  34. package/dist/internal/project/manifest.js.map +1 -0
  35. package/dist/internal/project/mergeVueProjectExtraction.d.ts +18 -0
  36. package/dist/internal/project/mergeVueProjectExtraction.js +79 -0
  37. package/dist/internal/project/mergeVueProjectExtraction.js.map +1 -0
  38. package/dist/internal/project/moduleResolver.d.ts +18 -0
  39. package/dist/internal/project/moduleResolver.js +325 -0
  40. package/dist/internal/project/moduleResolver.js.map +1 -0
  41. package/dist/internal/project/scopes.d.ts +31 -0
  42. package/dist/internal/project/scopes.js +182 -0
  43. package/dist/internal/project/scopes.js.map +1 -0
  44. package/dist/internal/project/sourcePatterns.d.ts +4 -0
  45. package/dist/internal/project/sourcePatterns.js +32 -0
  46. package/dist/internal/project/sourcePatterns.js.map +1 -0
  47. package/dist/internal/project/viteAliases.d.ts +42 -0
  48. package/dist/internal/project/viteAliases.js +1020 -0
  49. package/dist/internal/project/viteAliases.js.map +1 -0
  50. package/dist/internal/project/vueSourceClassification.d.ts +13 -0
  51. package/dist/internal/project/vueSourceClassification.js +146 -0
  52. package/dist/internal/project/vueSourceClassification.js.map +1 -0
  53. package/dist/internal/project/workspaces.d.ts +31 -0
  54. package/dist/internal/project/workspaces.js +326 -0
  55. package/dist/internal/project/workspaces.js.map +1 -0
  56. package/dist/internal/project/wrapperProvenance.d.ts +21 -0
  57. package/dist/internal/project/wrapperProvenance.js +287 -0
  58. package/dist/internal/project/wrapperProvenance.js.map +1 -0
  59. package/dist/internal/script/analyze.js +252 -85
  60. package/dist/internal/script/analyze.js.map +1 -1
  61. package/dist/internal/script/jsx.d.ts +7 -4
  62. package/dist/internal/script/jsx.js +351 -79
  63. package/dist/internal/script/jsx.js.map +1 -1
  64. package/dist/internal/script/localModules.d.ts +23 -2
  65. package/dist/internal/script/localModules.js +533 -20
  66. package/dist/internal/script/localModules.js.map +1 -1
  67. package/dist/internal/script/model.d.ts +9 -2
  68. package/dist/internal/script/parser.js +2 -1
  69. package/dist/internal/script/parser.js.map +1 -1
  70. package/dist/internal/script/runtimeModules.d.ts +10 -0
  71. package/dist/internal/script/runtimeModules.js +27 -0
  72. package/dist/internal/script/runtimeModules.js.map +1 -0
  73. package/dist/internal/stringCalls.js +1 -1
  74. package/dist/internal/stringCalls.js.map +1 -1
  75. package/dist/internal/template.js +263 -141
  76. package/dist/internal/template.js.map +1 -1
  77. package/dist/internal/types.d.ts +4 -1
  78. package/dist/internal/utils.d.ts +14 -3
  79. package/dist/internal/utils.js +63 -3
  80. package/dist/internal/utils.js.map +1 -1
  81. package/dist/internal/vueCompiler.d.ts +9 -1
  82. package/dist/internal/vueCompiler.js +37 -14
  83. package/dist/internal/vueCompiler.js.map +1 -1
  84. package/dist/project.d.ts +11 -0
  85. package/dist/project.js +3 -0
  86. package/dist/types.d.ts +95 -4
  87. package/package.json +30 -4
@@ -0,0 +1,1020 @@
1
+ import { NUXT_CONFIG_FILES, VITE_CONFIG_EXTENSIONS, VITE_CONFIG_FILES } from "../config/configFiles.js";
2
+ import { createRequire } from "node:module";
3
+ import fs from "node:fs";
4
+ import path from "node:path";
5
+ import { parse } from "@babel/parser";
6
+ import traverseModule from "@babel/traverse";
7
+ import { fileURLToPath, pathToFileURL } from "node:url";
8
+ //#region src/internal/project/viteAliases.ts
9
+ const traverse = traverseModule.default || traverseModule;
10
+ /**
11
+ * Reads string aliases from statically analyzable Vite and Nuxt config.
12
+ *
13
+ * Config files are parsed as source and are never imported or executed.
14
+ * Dynamic aliases, regular-expression find values, and unsupported syntax are
15
+ * ignored so alias discovery cannot make otherwise valid extraction fatal.
16
+ */
17
+ function resolveVueProjectAliases(cwd, options = {}) {
18
+ return resolveVueProjectAliasConfiguration(cwd, options).aliases;
19
+ }
20
+ /**
21
+ * Resolves aliases and reports whether the active alias surface was proven.
22
+ *
23
+ * Incomplete analysis never returns partial aliases. This lets project-level
24
+ * integrations distinguish a project with no configured aliases from one
25
+ * whose dynamic resolver behavior must block safe static extraction.
26
+ */
27
+ function resolveVueProjectAliasConfiguration(cwd, options = {}) {
28
+ const packageRoot = path.resolve(cwd);
29
+ const hasExplicitConfig = options.viteConfigPath !== void 0;
30
+ const explicitConfig = options.viteConfigPath !== void 0 ? resolveExplicitConfig(packageRoot, options.viteConfigPath) : void 0;
31
+ const discovery = hasExplicitConfig ? explicitConfig ? {
32
+ complete: true,
33
+ source: {
34
+ file: explicitConfig,
35
+ kind: "vite"
36
+ }
37
+ } : { complete: false } : discoverConfigSource(packageRoot);
38
+ if (!discovery.complete) return incompleteAliasConfiguration();
39
+ if (!discovery.source) return completeAliasConfiguration();
40
+ return readConfigAliases(discovery.source, packageRoot, options.nuxtMajorVersion);
41
+ }
42
+ function discoverConfigSource(cwd) {
43
+ const viteConfig = findFirstConfig(cwd, VITE_CONFIG_FILES);
44
+ const nuxtConfig = findFirstConfig(cwd, NUXT_CONFIG_FILES);
45
+ if (!viteConfig.complete || !nuxtConfig.complete) return { complete: false };
46
+ if (viteConfig.file && nuxtConfig.file) return { complete: false };
47
+ if (nuxtConfig.file) return {
48
+ complete: true,
49
+ source: {
50
+ file: nuxtConfig.file,
51
+ kind: "nuxt"
52
+ }
53
+ };
54
+ if (viteConfig.file) return {
55
+ complete: true,
56
+ source: {
57
+ file: viteConfig.file,
58
+ kind: "vite"
59
+ }
60
+ };
61
+ return { complete: true };
62
+ }
63
+ function findFirstConfig(cwd, filenames) {
64
+ for (const filename of filenames) {
65
+ const candidate = path.join(cwd, filename);
66
+ try {
67
+ return fs.statSync(candidate).isFile() ? {
68
+ complete: true,
69
+ file: candidate
70
+ } : { complete: false };
71
+ } catch (error) {
72
+ if (isMissingPathError(error)) continue;
73
+ return { complete: false };
74
+ }
75
+ }
76
+ return { complete: true };
77
+ }
78
+ function resolveExplicitConfig(cwd, configuredPath) {
79
+ if (!configuredPath.trim()) return void 0;
80
+ const candidate = path.resolve(cwd, configuredPath);
81
+ if (!isInsideDirectory(cwd, candidate)) return void 0;
82
+ if (!VITE_CONFIG_EXTENSIONS.has(path.extname(candidate).toLowerCase())) return;
83
+ try {
84
+ if (!fs.statSync(candidate).isFile()) return void 0;
85
+ const realRoot = fs.realpathSync(cwd);
86
+ const realCandidate = fs.realpathSync(candidate);
87
+ if (!isInsideDirectory(realRoot, realCandidate)) return void 0;
88
+ if (path.relative(realRoot, realCandidate).split(path.sep).includes("node_modules")) return;
89
+ return candidate;
90
+ } catch {
91
+ return;
92
+ }
93
+ }
94
+ function isInsideDirectory(root, candidate) {
95
+ const relative = path.relative(root, candidate);
96
+ return relative !== ".." && !relative.startsWith(`..${path.sep}`) && !path.isAbsolute(relative);
97
+ }
98
+ function isMissingPathError(error) {
99
+ return Boolean(error && typeof error === "object" && "code" in error && (error.code === "ENOENT" || error.code === "ENOTDIR"));
100
+ }
101
+ function completeAliasConfiguration(aliases = /* @__PURE__ */ new Map()) {
102
+ return {
103
+ aliases,
104
+ complete: true
105
+ };
106
+ }
107
+ function incompleteAliasConfiguration(potentialAliasKeys = [], potentialAliases = /* @__PURE__ */ new Map()) {
108
+ const keys = new Set(potentialAliasKeys);
109
+ const aliases = clonePotentialAliases(potentialAliases);
110
+ for (const key of aliases.keys()) keys.add(key);
111
+ return {
112
+ aliases: /* @__PURE__ */ new Map(),
113
+ complete: false,
114
+ ...aliases.size > 0 && { potentialAliases: aliases },
115
+ ...keys.size > 0 && { potentialAliasKeys: keys }
116
+ };
117
+ }
118
+ function collectAliasResolutionKeys(...sources) {
119
+ const keys = /* @__PURE__ */ new Set();
120
+ for (const source of sources) {
121
+ if (!source) continue;
122
+ if ("ok" in source) {
123
+ addAll(keys, source.ok ? source.aliases.entries.map(([find]) => find) : source.potentialAliasKeys);
124
+ continue;
125
+ }
126
+ for (const [find] of source.entries) keys.add(find);
127
+ }
128
+ return keys;
129
+ }
130
+ function collectAliasResolutionCandidates(...sources) {
131
+ const aliases = /* @__PURE__ */ new Map();
132
+ for (const source of sources) {
133
+ if (!source) continue;
134
+ if ("ok" in source) {
135
+ if (source.ok) for (const [find, replacement] of source.aliases.entries) addPotentialAlias(aliases, find, replacement);
136
+ else mergePotentialAliases(aliases, source.potentialAliases);
137
+ continue;
138
+ }
139
+ for (const [find, replacement] of source.entries) addPotentialAlias(aliases, find, replacement);
140
+ }
141
+ return aliases;
142
+ }
143
+ function readConfigAliases(source, packageRoot, configuredNuxtMajor) {
144
+ const ast = parseConfig(source.file);
145
+ if (!ast) return incompleteAliasConfiguration();
146
+ const { helpers, scopes } = collectAnalysisContext(ast);
147
+ const activeExport = findActiveConfigExport(ast);
148
+ if (!activeExport) return incompleteAliasConfiguration();
149
+ const context = {
150
+ configFile: source.file,
151
+ helpers,
152
+ nuxtMajorVersion: configuredNuxtMajor ?? readInstalledNuxtMajor(packageRoot),
153
+ packageRoot,
154
+ scopes
155
+ };
156
+ const root = resolveConfigRoot(activeExport, context, /* @__PURE__ */ new Set());
157
+ const config = root ? resolveStaticObject(root, context, /* @__PURE__ */ new Set(), "config") : void 0;
158
+ if (!config) return incompleteAliasConfiguration();
159
+ if (source.kind === "vite") {
160
+ const aliases = readNestedAliasObject(config, ["resolve", "alias"], context);
161
+ if (!aliases) return completeAliasConfiguration();
162
+ return aliases.ok ? completeAliasConfiguration(toFirstMatchMap(aliases.aliases.entries)) : incompleteAliasConfiguration(aliases.potentialAliasKeys, aliases.potentialAliases);
163
+ }
164
+ const builtInAliases = readNuxtBuiltInAliases(config, context);
165
+ if (!builtInAliases) return incompleteAliasConfiguration();
166
+ const configuredNuxtAliases = readNestedAliasObject(config, ["alias"], context);
167
+ const viteAliases = readNestedAliasObject(config, [
168
+ "vite",
169
+ "resolve",
170
+ "alias"
171
+ ], context);
172
+ if (configuredNuxtAliases && !configuredNuxtAliases.ok) return incompleteAliasConfiguration(collectAliasResolutionKeys(builtInAliases, configuredNuxtAliases, viteAliases), collectAliasResolutionCandidates(builtInAliases, configuredNuxtAliases, viteAliases));
173
+ if (viteAliases && !viteAliases.ok) return incompleteAliasConfiguration(collectAliasResolutionKeys(builtInAliases, configuredNuxtAliases, viteAliases), collectAliasResolutionCandidates(builtInAliases, configuredNuxtAliases, viteAliases));
174
+ if (configuredNuxtAliases?.ok && configuredNuxtAliases.aliases.form !== "object") return incompleteAliasConfiguration(collectAliasResolutionKeys(builtInAliases, configuredNuxtAliases, viteAliases), collectAliasResolutionCandidates(builtInAliases, configuredNuxtAliases, viteAliases));
175
+ return completeAliasConfiguration(mergeNuxtAliases(mergeObjectAliases(builtInAliases, configuredNuxtAliases?.ok ? configuredNuxtAliases.aliases : void 0), viteAliases?.ok ? viteAliases.aliases : void 0));
176
+ }
177
+ function readNuxtBuiltInAliases(config, context) {
178
+ const configuredRoot = config.get("rootDir");
179
+ const rootDirValue = configuredRoot ? resolveStaticString(configuredRoot, context, /* @__PURE__ */ new Set()) : void 0;
180
+ if (configuredRoot && rootDirValue === void 0) return void 0;
181
+ const rootDir = resolveSafeNuxtDirectory(context.packageRoot, rootDirValue ?? ".");
182
+ if (!rootDir) return void 0;
183
+ const configuredSource = config.get("srcDir");
184
+ const sourceValue = configuredSource ? resolveStaticString(configuredSource, context, /* @__PURE__ */ new Set()) : void 0;
185
+ if (configuredSource && sourceValue === void 0) return void 0;
186
+ const compatibilityMajor = readNuxtCompatibilityMajor(config, context);
187
+ if (compatibilityMajor === null) return void 0;
188
+ const effectiveNuxtMajor = compatibilityMajor ?? context.nuxtMajorVersion;
189
+ const hasExplicitSource = Boolean(configuredSource && sourceValue);
190
+ if (!hasExplicitSource && effectiveNuxtMajor === void 0) return void 0;
191
+ const srcDir = hasExplicitSource ? resolveSafeNuxtDirectory(rootDir, sourceValue) : effectiveNuxtMajor >= 4 ? resolveDefaultNuxt4SourceDirectory(rootDir) : rootDir;
192
+ if (!srcDir) return void 0;
193
+ const sourceAlias = withTrailingSlash(srcDir);
194
+ const rootAlias = withTrailingSlash(rootDir);
195
+ return {
196
+ entries: [
197
+ ["~", sourceAlias],
198
+ ["@", sourceAlias],
199
+ ["~~", rootAlias],
200
+ ["@@", rootAlias]
201
+ ],
202
+ form: "object"
203
+ };
204
+ }
205
+ function readNuxtCompatibilityMajor(config, context) {
206
+ const futureEntry = config.get("future");
207
+ if (!futureEntry) return void 0;
208
+ const future = resolveStaticObject(futureEntry, context, /* @__PURE__ */ new Set(), "config");
209
+ if (!future) return null;
210
+ const compatibilityEntry = future.get("compatibilityVersion");
211
+ if (!compatibilityEntry) return void 0;
212
+ return resolveStaticInteger(compatibilityEntry, context, /* @__PURE__ */ new Set()) ?? null;
213
+ }
214
+ function resolveStaticInteger(entry, context, seen) {
215
+ const unwrapped = unwrapEntry(entry);
216
+ if (seen.has(unwrapped.node)) return void 0;
217
+ seen.add(unwrapped.node);
218
+ try {
219
+ if (unwrapped.node.type === "NumericLiteral" && Number.isInteger(unwrapped.node.value)) return unwrapped.node.value;
220
+ if (unwrapped.node.type === "StringLiteral" && /^\d+$/.test(unwrapped.node.value)) return Number(unwrapped.node.value);
221
+ if (unwrapped.node.type !== "Identifier") return void 0;
222
+ const bound = resolveImmutableBinding(unwrapped, context, "none");
223
+ return bound ? resolveStaticInteger(bound, context, seen) : void 0;
224
+ } finally {
225
+ seen.delete(unwrapped.node);
226
+ }
227
+ }
228
+ function resolveSafeNuxtDirectory(root, configuredPath) {
229
+ const candidate = path.resolve(root, configuredPath);
230
+ if (!isInsideDirectory(root, candidate)) return void 0;
231
+ if (path.relative(root, candidate).split(path.sep).includes("node_modules")) return;
232
+ try {
233
+ const realRoot = fs.realpathSync(root);
234
+ let existingAncestor = candidate;
235
+ while (!fs.existsSync(existingAncestor)) {
236
+ const parent = path.dirname(existingAncestor);
237
+ if (parent === existingAncestor) return void 0;
238
+ existingAncestor = parent;
239
+ }
240
+ const realAncestor = fs.realpathSync(existingAncestor);
241
+ return isInsideDirectory(realRoot, path.resolve(realAncestor, path.relative(existingAncestor, candidate))) ? candidate : void 0;
242
+ } catch {
243
+ return;
244
+ }
245
+ }
246
+ function resolveDefaultNuxt4SourceDirectory(rootDir) {
247
+ const appDir = path.join(rootDir, "app");
248
+ try {
249
+ if (!fs.statSync(appDir).isDirectory()) return rootDir;
250
+ if (fs.readdirSync(appDir).filter((entry) => entry !== "spa-loading-template.html" && !entry.startsWith("router.options")).length > 0) return appDir;
251
+ if ([
252
+ "app.vue",
253
+ "App.vue",
254
+ "assets",
255
+ "layouts",
256
+ "middleware",
257
+ "pages",
258
+ "plugins"
259
+ ].map((entry) => path.join(rootDir, entry)).some((entry) => fs.existsSync(entry))) return rootDir;
260
+ return appDir;
261
+ } catch {
262
+ return rootDir;
263
+ }
264
+ }
265
+ function withTrailingSlash(directory) {
266
+ return `${directory.replaceAll(path.sep, "/")}/`;
267
+ }
268
+ function readInstalledNuxtMajor(cwd) {
269
+ try {
270
+ const manifestPath = createRequire(path.join(cwd, "package.json")).resolve("nuxt/package.json");
271
+ const manifest = JSON.parse(fs.readFileSync(manifestPath, "utf8"));
272
+ if (typeof manifest.version !== "string") return void 0;
273
+ const major = Number(manifest.version.split(".")[0]);
274
+ return Number.isInteger(major) ? major : void 0;
275
+ } catch {
276
+ return;
277
+ }
278
+ }
279
+ function parseConfig(configFile) {
280
+ try {
281
+ return parse(fs.readFileSync(configFile, "utf8"), {
282
+ allowAwaitOutsideFunction: true,
283
+ plugins: [
284
+ "decorators-legacy",
285
+ "typescript",
286
+ "jsx",
287
+ "importAttributes"
288
+ ],
289
+ sourceType: "unambiguous"
290
+ });
291
+ } catch {
292
+ return;
293
+ }
294
+ }
295
+ function collectAnalysisContext(ast) {
296
+ const helpers = {
297
+ configFunctions: /* @__PURE__ */ new Set(),
298
+ configNamespaces: /* @__PURE__ */ new Set(),
299
+ fileURLToPathFunctions: /* @__PURE__ */ new Set(),
300
+ pathNamespaces: /* @__PURE__ */ new Set(),
301
+ pathResolveFunctions: /* @__PURE__ */ new Set(),
302
+ urlConstructors: /* @__PURE__ */ new Set(),
303
+ urlNamespaces: /* @__PURE__ */ new Set()
304
+ };
305
+ const scopes = /* @__PURE__ */ new WeakMap();
306
+ traverse(ast, {
307
+ enter(nodePath) {
308
+ scopes.set(nodePath.node, nodePath.scope);
309
+ },
310
+ ImportDeclaration(importPath) {
311
+ const source = importPath.node.source.value;
312
+ for (const specifierPath of importPath.get("specifiers")) {
313
+ const binding = specifierPath.scope.getBinding(specifierPath.node.local.name);
314
+ if (!binding || !binding.constant || hasDirectMemberMutation(binding)) continue;
315
+ registerHelperBinding(helpers, source, specifierPath.node.type === "ImportSpecifier" ? specifierPath.node.imported.type === "Identifier" ? specifierPath.node.imported.name : specifierPath.node.imported.value : specifierPath.node.type === "ImportDefaultSpecifier" ? "default" : "*", binding);
316
+ }
317
+ },
318
+ VariableDeclarator(variablePath) {
319
+ registerRequireBinding(variablePath, helpers);
320
+ }
321
+ });
322
+ return {
323
+ helpers,
324
+ scopes
325
+ };
326
+ }
327
+ function registerHelperBinding(helpers, source, importedName, binding) {
328
+ if (source === "vite" || source === "nuxt/config" || source === "nuxt" || source === "#imports") {
329
+ if (importedName === "defineConfig" || importedName === "defineNuxtConfig") helpers.configFunctions.add(binding);
330
+ else if (importedName === "*" || importedName === "default") helpers.configNamespaces.add(binding);
331
+ return;
332
+ }
333
+ if (source === "node:path" || source === "path") {
334
+ if (importedName === "resolve") helpers.pathResolveFunctions.add(binding);
335
+ else if (importedName === "*" || importedName === "default") helpers.pathNamespaces.add(binding);
336
+ return;
337
+ }
338
+ if (source === "node:url" || source === "url") {
339
+ if (importedName === "fileURLToPath") helpers.fileURLToPathFunctions.add(binding);
340
+ else if (importedName === "URL") helpers.urlConstructors.add(binding);
341
+ else if (importedName === "*" || importedName === "default") helpers.urlNamespaces.add(binding);
342
+ }
343
+ }
344
+ function registerRequireBinding(variablePath, helpers) {
345
+ const source = readRequireSource(variablePath.node.init);
346
+ if (!source) return;
347
+ const idPath = variablePath.get("id");
348
+ if (idPath.isIdentifier()) {
349
+ const binding = idPath.scope.getBinding(idPath.node.name);
350
+ if (!binding || !binding.constant || hasDirectMemberMutation(binding)) return;
351
+ registerHelperBinding(helpers, source, "*", binding);
352
+ return;
353
+ }
354
+ if (!idPath.isObjectPattern()) return;
355
+ for (const propertyPath of idPath.get("properties")) {
356
+ if (!propertyPath.isObjectProperty()) continue;
357
+ const importedName = readPropertyKey(propertyPath.node);
358
+ const valuePath = propertyPath.get("value");
359
+ const localPath = valuePath.isAssignmentPattern() ? valuePath.get("left") : valuePath;
360
+ if (!importedName || !localPath.isIdentifier()) continue;
361
+ const binding = localPath.scope.getBinding(localPath.node.name);
362
+ if (binding?.constant && !hasDirectMemberMutation(binding)) registerHelperBinding(helpers, source, importedName, binding);
363
+ }
364
+ }
365
+ function readRequireSource(node) {
366
+ const unwrapped = unwrapNode(node);
367
+ if (!unwrapped || unwrapped.type !== "CallExpression" || unwrapped.callee.type !== "Identifier" || unwrapped.callee.name !== "require" || unwrapped.arguments.length !== 1 || unwrapped.arguments[0]?.type !== "StringLiteral") return;
368
+ return unwrapped.arguments[0].value;
369
+ }
370
+ function findActiveConfigExport(ast) {
371
+ const candidates = [];
372
+ traverse(ast, {
373
+ ExportDefaultDeclaration(exportPath) {
374
+ candidates.push({
375
+ node: exportPath.node.declaration,
376
+ scope: exportPath.scope,
377
+ start: exportPath.node.start ?? -1
378
+ });
379
+ },
380
+ ExportNamedDeclaration(exportPath) {
381
+ for (const specifierPath of exportPath.get("specifiers")) {
382
+ if (!specifierPath.isExportSpecifier()) continue;
383
+ const exported = specifierPath.node.exported;
384
+ if ((exported.type === "Identifier" ? exported.name : exported.value) !== "default") continue;
385
+ candidates.push({
386
+ node: specifierPath.node.local,
387
+ scope: specifierPath.scope,
388
+ start: exportPath.node.start ?? -1
389
+ });
390
+ }
391
+ },
392
+ TSExportAssignment(exportPath) {
393
+ candidates.push({
394
+ node: exportPath.node.expression,
395
+ scope: exportPath.scope,
396
+ start: exportPath.node.start ?? -1
397
+ });
398
+ },
399
+ AssignmentExpression(assignmentPath) {
400
+ if (!isCommonJsConfigExport(assignmentPath.node.left)) return;
401
+ candidates.push({
402
+ node: assignmentPath.node.right,
403
+ scope: assignmentPath.scope,
404
+ start: assignmentPath.node.start ?? -1
405
+ });
406
+ }
407
+ });
408
+ candidates.sort((left, right) => left.start - right.start);
409
+ return candidates.at(-1);
410
+ }
411
+ function isCommonJsConfigExport(node) {
412
+ if (node.type !== "MemberExpression" || node.computed) return false;
413
+ if (node.object.type === "Identifier" && node.property.type === "Identifier") return node.object.name === "module" && node.property.name === "exports" || node.object.name === "exports" && node.property.name === "default";
414
+ if (node.object.type === "MemberExpression" && !node.object.computed && node.object.object.type === "Identifier" && node.object.object.name === "module" && node.object.property.type === "Identifier" && node.object.property.name === "exports" && node.property.type === "Identifier" && node.property.name === "default") return true;
415
+ return false;
416
+ }
417
+ function resolveConfigRoot(entry, context, seen) {
418
+ const unwrapped = unwrapEntry(entry);
419
+ if (seen.has(unwrapped.node)) return void 0;
420
+ seen.add(unwrapped.node);
421
+ try {
422
+ if (unwrapped.node.type === "Identifier") {
423
+ const bound = resolveImmutableBinding(unwrapped, context, "config");
424
+ return bound ? resolveConfigRoot(bound, context, seen) : void 0;
425
+ }
426
+ if (unwrapped.node.type === "CallExpression" || unwrapped.node.type === "OptionalCallExpression") {
427
+ if (!isConfigHelperCall(unwrapped, context.helpers)) return void 0;
428
+ const argument = unwrapped.node.arguments[0];
429
+ if (!argument || argument.type === "SpreadElement" || argument.type === "ArgumentPlaceholder") return;
430
+ return resolveConfigRoot(scopedEntry(argument, unwrapped.scope, context), context, seen);
431
+ }
432
+ if (unwrapped.node.type === "ArrowFunctionExpression" || unwrapped.node.type === "FunctionExpression" || unwrapped.node.type === "FunctionDeclaration") {
433
+ const returned = readStaticFunctionReturn(unwrapped, context);
434
+ return returned ? resolveConfigRoot(returned, context, seen) : void 0;
435
+ }
436
+ return unwrapped;
437
+ } finally {
438
+ seen.delete(unwrapped.node);
439
+ }
440
+ }
441
+ function isConfigHelperCall(entry, helpers) {
442
+ if (entry.node.type !== "CallExpression" && entry.node.type !== "OptionalCallExpression") return false;
443
+ const callee = unwrapNode(entry.node.callee);
444
+ if (!callee) return false;
445
+ if (callee.type === "Identifier") {
446
+ const binding = entry.scope.getBinding(callee.name);
447
+ return binding ? helpers.configFunctions.has(binding) : callee.name === "defineConfig" || callee.name === "defineNuxtConfig";
448
+ }
449
+ if (callee.type === "MemberExpression" && !callee.computed && callee.object.type === "Identifier" && callee.property.type === "Identifier" && (callee.property.name === "defineConfig" || callee.property.name === "defineNuxtConfig")) {
450
+ const binding = entry.scope.getBinding(callee.object.name);
451
+ return Boolean(binding && helpers.configNamespaces.has(binding));
452
+ }
453
+ return false;
454
+ }
455
+ function readStaticFunctionReturn(entry, context) {
456
+ if (entry.node.type !== "ArrowFunctionExpression" && entry.node.type !== "FunctionExpression" && entry.node.type !== "FunctionDeclaration") return;
457
+ if (entry.node.body.type !== "BlockStatement") return scopedEntry(entry.node.body, entry.scope, context);
458
+ const returns = entry.node.body.body.filter((statement) => statement.type === "ReturnStatement" && Boolean(statement.argument));
459
+ if (returns.length !== 1 || !returns[0].argument) return void 0;
460
+ return scopedEntry(returns[0].argument, entry.scope, context);
461
+ }
462
+ function readNestedAliasObject(root, keys, context) {
463
+ let entry;
464
+ let object = root;
465
+ for (const [index, key] of keys.entries()) {
466
+ entry = object.get(key);
467
+ if (!entry) return void 0;
468
+ if (isDefinitelyAbsentAliasValue(entry, context, /* @__PURE__ */ new Set())) return;
469
+ if (index === keys.length - 1) break;
470
+ const nested = resolveStaticObject(entry, context, /* @__PURE__ */ new Set(), "config");
471
+ if (!nested) return {
472
+ ok: false,
473
+ potentialAliasKeys: /* @__PURE__ */ new Set(),
474
+ potentialAliases: /* @__PURE__ */ new Map()
475
+ };
476
+ object = nested;
477
+ }
478
+ return entry ? readAliasValue(entry, context) : void 0;
479
+ }
480
+ function isDefinitelyAbsentAliasValue(entry, context, seen) {
481
+ const unwrapped = unwrapEntry(entry);
482
+ if (seen.has(unwrapped.node)) return false;
483
+ seen.add(unwrapped.node);
484
+ try {
485
+ if (unwrapped.node.type === "NullLiteral") return true;
486
+ if (unwrapped.node.type === "BooleanLiteral" && !unwrapped.node.value) return true;
487
+ if (unwrapped.node.type === "Identifier" && unwrapped.node.name === "undefined" && !unwrapped.scope.getBinding("undefined")) return true;
488
+ if (unwrapped.node.type === "UnaryExpression" && unwrapped.node.operator === "void") return true;
489
+ if (unwrapped.node.type !== "Identifier") return false;
490
+ const bound = resolveImmutableBinding(unwrapped, context, "none");
491
+ return bound ? isDefinitelyAbsentAliasValue(bound, context, seen) : false;
492
+ } finally {
493
+ seen.delete(unwrapped.node);
494
+ }
495
+ }
496
+ function readAliasValue(entry, context) {
497
+ const potentialAliasKeys = collectPotentialAliasKeys(entry, context, /* @__PURE__ */ new Set());
498
+ const potentialAliases = collectPotentialAliases(entry, context, /* @__PURE__ */ new Set());
499
+ const object = resolveStaticObject(entry, context, /* @__PURE__ */ new Set(), "alias");
500
+ if (object) {
501
+ const entries = [];
502
+ for (const [find, replacementEntry] of object) {
503
+ const replacement = resolveStaticString(replacementEntry, context, /* @__PURE__ */ new Set());
504
+ if (replacement === void 0) return {
505
+ ok: false,
506
+ potentialAliasKeys,
507
+ potentialAliases
508
+ };
509
+ entries.push([find, replacement]);
510
+ }
511
+ return {
512
+ ok: true,
513
+ aliases: {
514
+ entries,
515
+ form: "object"
516
+ }
517
+ };
518
+ }
519
+ const entries = resolveStaticArray(entry, context, /* @__PURE__ */ new Set(), "alias");
520
+ if (!entries) return {
521
+ ok: false,
522
+ potentialAliasKeys,
523
+ potentialAliases
524
+ };
525
+ const arrayAliases = /* @__PURE__ */ new Map();
526
+ for (const item of entries) {
527
+ const aliasObject = resolveStaticObject(item, context, /* @__PURE__ */ new Set(), "alias");
528
+ if (!aliasObject || aliasObject.has("customResolver")) return {
529
+ ok: false,
530
+ potentialAliasKeys,
531
+ potentialAliases
532
+ };
533
+ const findEntry = aliasObject.get("find");
534
+ const replacementEntry = aliasObject.get("replacement");
535
+ if (!findEntry || !replacementEntry) return {
536
+ ok: false,
537
+ potentialAliasKeys,
538
+ potentialAliases
539
+ };
540
+ const find = resolveStaticString(findEntry, context, /* @__PURE__ */ new Set());
541
+ const replacement = resolveStaticString(replacementEntry, context, /* @__PURE__ */ new Set());
542
+ if (find === void 0 || replacement === void 0) return {
543
+ ok: false,
544
+ potentialAliasKeys,
545
+ potentialAliases
546
+ };
547
+ if (!arrayAliases.has(find)) arrayAliases.set(find, replacement);
548
+ }
549
+ return {
550
+ ok: true,
551
+ aliases: {
552
+ entries: [...arrayAliases],
553
+ form: "array"
554
+ }
555
+ };
556
+ }
557
+ /** Collects only fully static key-to-replacement candidates. */
558
+ function collectPotentialAliases(entry, context, seen) {
559
+ const unwrapped = unwrapEntry(entry);
560
+ if (seen.has(unwrapped.node)) return /* @__PURE__ */ new Map();
561
+ seen.add(unwrapped.node);
562
+ try {
563
+ if (unwrapped.node.type === "Identifier") {
564
+ const bound = resolveImmutableBinding(unwrapped, context, "none");
565
+ return bound ? collectPotentialAliases(bound, context, seen) : /* @__PURE__ */ new Map();
566
+ }
567
+ if (unwrapped.node.type === "ObjectExpression") {
568
+ const aliases = /* @__PURE__ */ new Map();
569
+ for (const property of unwrapped.node.properties) {
570
+ if (property.type === "SpreadElement") {
571
+ mergePotentialAliases(aliases, collectPotentialAliases(scopedEntry(property.argument, unwrapped.scope, context), context, seen));
572
+ continue;
573
+ }
574
+ if (property.type !== "ObjectProperty") continue;
575
+ const find = readPropertyKey(property);
576
+ if (find === void 0) continue;
577
+ const replacement = resolveStaticString(scopedEntry(property.value, unwrapped.scope, context), context, /* @__PURE__ */ new Set());
578
+ if (replacement !== void 0) addPotentialAlias(aliases, find, replacement);
579
+ }
580
+ return aliases;
581
+ }
582
+ if (unwrapped.node.type === "ArrayExpression") {
583
+ const aliases = /* @__PURE__ */ new Map();
584
+ for (const element of unwrapped.node.elements) {
585
+ if (!element) continue;
586
+ if (element.type === "SpreadElement") {
587
+ mergePotentialAliases(aliases, collectPotentialAliases(scopedEntry(element.argument, unwrapped.scope, context), context, seen));
588
+ continue;
589
+ }
590
+ const aliasObject = resolveStaticObject(scopedEntry(element, unwrapped.scope, context), context, /* @__PURE__ */ new Set(), "none");
591
+ const findEntry = aliasObject?.get("find");
592
+ const replacementEntry = aliasObject?.get("replacement");
593
+ if (!findEntry || !replacementEntry) continue;
594
+ const find = resolveStaticString(findEntry, context, /* @__PURE__ */ new Set());
595
+ const replacement = resolveStaticString(replacementEntry, context, /* @__PURE__ */ new Set());
596
+ if (find !== void 0 && replacement !== void 0) addPotentialAlias(aliases, find, replacement);
597
+ }
598
+ return aliases;
599
+ }
600
+ return /* @__PURE__ */ new Map();
601
+ } finally {
602
+ seen.delete(unwrapped.node);
603
+ }
604
+ }
605
+ /**
606
+ * Collects statically visible alias keys without claiming that their final
607
+ * replacement or precedence is known. Dynamic spreads and overrides can make
608
+ * the full alias surface incomplete, but the observed keys remain useful as
609
+ * narrowly scoped evidence that an import may belong to the Vue project.
610
+ */
611
+ function collectPotentialAliasKeys(entry, context, seen) {
612
+ const unwrapped = unwrapEntry(entry);
613
+ if (seen.has(unwrapped.node)) return /* @__PURE__ */ new Set();
614
+ seen.add(unwrapped.node);
615
+ try {
616
+ if (unwrapped.node.type === "Identifier") {
617
+ const bound = resolveImmutableBinding(unwrapped, context, "none");
618
+ return bound ? collectPotentialAliasKeys(bound, context, seen) : /* @__PURE__ */ new Set();
619
+ }
620
+ if (unwrapped.node.type === "ObjectExpression") {
621
+ const keys = /* @__PURE__ */ new Set();
622
+ for (const property of unwrapped.node.properties) {
623
+ if (property.type === "SpreadElement") {
624
+ addAll(keys, collectPotentialAliasKeys(scopedEntry(property.argument, unwrapped.scope, context), context, seen));
625
+ continue;
626
+ }
627
+ if (property.type !== "ObjectProperty" && property.type !== "ObjectMethod") continue;
628
+ const key = readPropertyKey(property);
629
+ if (key !== void 0) keys.add(key);
630
+ }
631
+ return keys;
632
+ }
633
+ if (unwrapped.node.type === "ArrayExpression") {
634
+ const keys = /* @__PURE__ */ new Set();
635
+ for (const element of unwrapped.node.elements) {
636
+ if (!element) continue;
637
+ if (element.type === "SpreadElement") {
638
+ addAll(keys, collectPotentialAliasKeys(scopedEntry(element.argument, unwrapped.scope, context), context, seen));
639
+ continue;
640
+ }
641
+ addAll(keys, collectPotentialArrayAliasKeys(scopedEntry(element, unwrapped.scope, context), context, seen));
642
+ }
643
+ return keys;
644
+ }
645
+ return /* @__PURE__ */ new Set();
646
+ } finally {
647
+ seen.delete(unwrapped.node);
648
+ }
649
+ }
650
+ function collectPotentialArrayAliasKeys(entry, context, seen) {
651
+ const unwrapped = unwrapEntry(entry);
652
+ if (seen.has(unwrapped.node)) return /* @__PURE__ */ new Set();
653
+ seen.add(unwrapped.node);
654
+ try {
655
+ if (unwrapped.node.type === "Identifier") {
656
+ const bound = resolveImmutableBinding(unwrapped, context, "none");
657
+ return bound ? collectPotentialArrayAliasKeys(bound, context, seen) : /* @__PURE__ */ new Set();
658
+ }
659
+ if (unwrapped.node.type !== "ObjectExpression") return /* @__PURE__ */ new Set();
660
+ const keys = /* @__PURE__ */ new Set();
661
+ for (const property of unwrapped.node.properties) {
662
+ if (property.type === "SpreadElement") {
663
+ addAll(keys, collectPotentialArrayAliasKeys(scopedEntry(property.argument, unwrapped.scope, context), context, seen));
664
+ continue;
665
+ }
666
+ if (property.type !== "ObjectProperty" || readPropertyKey(property) !== "find") continue;
667
+ const find = resolveStaticString(scopedEntry(property.value, unwrapped.scope, context), context, /* @__PURE__ */ new Set());
668
+ if (find !== void 0) keys.add(find);
669
+ }
670
+ return keys;
671
+ } finally {
672
+ seen.delete(unwrapped.node);
673
+ }
674
+ }
675
+ function addAll(target, values) {
676
+ for (const value of values) target.add(value);
677
+ }
678
+ function addPotentialAlias(target, find, replacement) {
679
+ const replacements = target.get(find) ?? /* @__PURE__ */ new Set();
680
+ replacements.add(replacement);
681
+ target.set(find, replacements);
682
+ }
683
+ function mergePotentialAliases(target, source) {
684
+ for (const [find, replacements] of source) for (const replacement of replacements) addPotentialAlias(target, find, replacement);
685
+ }
686
+ function clonePotentialAliases(aliases) {
687
+ const clone = /* @__PURE__ */ new Map();
688
+ mergePotentialAliases(clone, aliases);
689
+ return clone;
690
+ }
691
+ function resolveStaticObject(entry, context, seen, bindingSafety) {
692
+ const unwrapped = unwrapEntry(entry);
693
+ if (seen.has(unwrapped.node)) return void 0;
694
+ seen.add(unwrapped.node);
695
+ try {
696
+ if (unwrapped.node.type === "Identifier") {
697
+ const bound = resolveImmutableBinding(unwrapped, context, bindingSafety);
698
+ return bound ? resolveStaticObject(bound, context, seen, bindingSafety) : void 0;
699
+ }
700
+ if (unwrapped.node.type !== "ObjectExpression") return void 0;
701
+ const object = /* @__PURE__ */ new Map();
702
+ for (const property of unwrapped.node.properties) {
703
+ if (property.type === "SpreadElement") {
704
+ const spread = resolveStaticObject(scopedEntry(property.argument, unwrapped.scope, context), context, seen, bindingSafety);
705
+ if (!spread) return void 0;
706
+ for (const pair of spread) object.set(...pair);
707
+ continue;
708
+ }
709
+ if (property.type !== "ObjectProperty" && property.type !== "ObjectMethod") continue;
710
+ const key = readPropertyKey(property);
711
+ if (key === void 0) return void 0;
712
+ object.set(key, scopedEntry(property.type === "ObjectProperty" ? property.value : property, unwrapped.scope, context));
713
+ }
714
+ return object;
715
+ } finally {
716
+ seen.delete(unwrapped.node);
717
+ }
718
+ }
719
+ function resolveStaticArray(entry, context, seen, bindingSafety) {
720
+ const unwrapped = unwrapEntry(entry);
721
+ if (seen.has(unwrapped.node)) return void 0;
722
+ seen.add(unwrapped.node);
723
+ try {
724
+ if (unwrapped.node.type === "Identifier") {
725
+ const bound = resolveImmutableBinding(unwrapped, context, bindingSafety);
726
+ return bound ? resolveStaticArray(bound, context, seen, bindingSafety) : void 0;
727
+ }
728
+ if (unwrapped.node.type !== "ArrayExpression") return void 0;
729
+ const result = [];
730
+ for (const element of unwrapped.node.elements) {
731
+ if (!element) continue;
732
+ if (element.type === "SpreadElement") {
733
+ const spread = resolveStaticArray(scopedEntry(element.argument, unwrapped.scope, context), context, seen, bindingSafety);
734
+ if (!spread) return void 0;
735
+ result.push(...spread);
736
+ continue;
737
+ }
738
+ result.push(scopedEntry(element, unwrapped.scope, context));
739
+ }
740
+ return result;
741
+ } finally {
742
+ seen.delete(unwrapped.node);
743
+ }
744
+ }
745
+ function resolveStaticString(entry, context, seen) {
746
+ const unwrapped = unwrapEntry(entry);
747
+ if (seen.has(unwrapped.node)) return void 0;
748
+ seen.add(unwrapped.node);
749
+ try {
750
+ const node = unwrapped.node;
751
+ if (node.type === "StringLiteral") return node.value;
752
+ if (node.type === "Identifier") {
753
+ if (node.name === "__dirname" && !unwrapped.scope.getBinding(node.name)) return path.dirname(context.configFile);
754
+ const bound = resolveImmutableBinding(unwrapped, context, "none");
755
+ return bound ? resolveStaticString(bound, context, seen) : void 0;
756
+ }
757
+ if (node.type === "TemplateLiteral") {
758
+ let value = node.quasis[0]?.value.cooked ?? "";
759
+ for (const [index, expression] of node.expressions.entries()) {
760
+ const resolved = resolveStaticString(scopedEntry(expression, unwrapped.scope, context), context, seen);
761
+ if (resolved === void 0) return void 0;
762
+ value += resolved + (node.quasis[index + 1]?.value.cooked ?? "");
763
+ }
764
+ return value;
765
+ }
766
+ if (node.type === "BinaryExpression" && node.operator === "+") {
767
+ const left = resolveStaticString(scopedEntry(node.left, unwrapped.scope, context), context, seen);
768
+ const right = resolveStaticString(scopedEntry(node.right, unwrapped.scope, context), context, seen);
769
+ return left === void 0 || right === void 0 ? void 0 : left + right;
770
+ }
771
+ if (node.type === "CallExpression" || node.type === "OptionalCallExpression") {
772
+ if (isPathResolveCall(unwrapped, context.helpers)) {
773
+ const parts = [];
774
+ for (const argument of node.arguments) {
775
+ if (argument.type === "SpreadElement" || argument.type === "ArgumentPlaceholder") return;
776
+ const part = resolveStaticString(scopedEntry(argument, unwrapped.scope, context), context, seen);
777
+ if (part === void 0) return void 0;
778
+ parts.push(part);
779
+ }
780
+ if (parts.length === 0 || !path.isAbsolute(parts[0])) return;
781
+ return path.resolve(...parts);
782
+ }
783
+ if (isFileURLToPathCall(unwrapped, context.helpers)) {
784
+ const argument = node.arguments[0];
785
+ if (!argument || argument.type === "SpreadElement" || argument.type === "ArgumentPlaceholder") return;
786
+ const url = resolveStaticUrl(scopedEntry(argument, unwrapped.scope, context), context, seen);
787
+ if (!url || url.protocol !== "file:") return void 0;
788
+ return fileURLToPath(url);
789
+ }
790
+ }
791
+ if (node.type === "MemberExpression" && !node.computed && node.object.type === "MetaProperty" && node.object.meta.name === "import" && node.object.property.name === "meta" && node.property.type === "Identifier" && node.property.name === "dirname") return path.dirname(context.configFile);
792
+ return;
793
+ } finally {
794
+ seen.delete(unwrapped.node);
795
+ }
796
+ }
797
+ function resolveStaticUrl(entry, context, seen) {
798
+ const unwrapped = unwrapEntry(entry);
799
+ if (seen.has(unwrapped.node)) return void 0;
800
+ seen.add(unwrapped.node);
801
+ try {
802
+ if (unwrapped.node.type === "Identifier") {
803
+ const bound = resolveImmutableBinding(unwrapped, context, "none");
804
+ return bound ? resolveStaticUrl(bound, context, seen) : void 0;
805
+ }
806
+ if (unwrapped.node.type !== "NewExpression" || unwrapped.node.callee.type !== "Identifier" || unwrapped.node.callee.name !== "URL" || !isTrustedUrlConstructor(unwrapped, context.helpers) || unwrapped.node.arguments.length !== 2) return;
807
+ const [relativeArgument, baseArgument] = unwrapped.node.arguments;
808
+ if (!relativeArgument || relativeArgument.type === "SpreadElement" || relativeArgument.type === "ArgumentPlaceholder" || !baseArgument || baseArgument.type === "SpreadElement" || baseArgument.type === "ArgumentPlaceholder" || !isImportMetaUrl(baseArgument)) return;
809
+ const relative = resolveStaticString(scopedEntry(relativeArgument, unwrapped.scope, context), context, seen);
810
+ if (relative === void 0) return void 0;
811
+ return new URL(relative, pathToFileURL(context.configFile));
812
+ } catch {
813
+ return;
814
+ } finally {
815
+ seen.delete(unwrapped.node);
816
+ }
817
+ }
818
+ /** Accepts the global URL constructor and immutable imports from node:url. */
819
+ function isTrustedUrlConstructor(entry, helpers) {
820
+ if (entry.node.type !== "NewExpression" || entry.node.callee.type !== "Identifier" || entry.node.callee.name !== "URL") return false;
821
+ const binding = entry.scope.getBinding(entry.node.callee.name);
822
+ return binding === void 0 || helpers.urlConstructors.has(binding);
823
+ }
824
+ function isPathResolveCall(entry, helpers) {
825
+ if (entry.node.type !== "CallExpression" && entry.node.type !== "OptionalCallExpression") return false;
826
+ const callee = unwrapNode(entry.node.callee);
827
+ if (!callee) return false;
828
+ if (callee.type === "Identifier") {
829
+ const binding = entry.scope.getBinding(callee.name);
830
+ return Boolean(binding && helpers.pathResolveFunctions.has(binding));
831
+ }
832
+ if (callee.type === "MemberExpression" && !callee.computed && callee.object.type === "Identifier" && callee.property.type === "Identifier" && callee.property.name === "resolve") {
833
+ const binding = entry.scope.getBinding(callee.object.name);
834
+ return Boolean(binding && helpers.pathNamespaces.has(binding));
835
+ }
836
+ return false;
837
+ }
838
+ function isFileURLToPathCall(entry, helpers) {
839
+ if (entry.node.type !== "CallExpression" && entry.node.type !== "OptionalCallExpression") return false;
840
+ const callee = unwrapNode(entry.node.callee);
841
+ if (!callee) return false;
842
+ if (callee.type === "Identifier") {
843
+ const binding = entry.scope.getBinding(callee.name);
844
+ return Boolean(binding && helpers.fileURLToPathFunctions.has(binding));
845
+ }
846
+ if (callee.type === "MemberExpression" && !callee.computed && callee.object.type === "Identifier" && callee.property.type === "Identifier" && callee.property.name === "fileURLToPath") {
847
+ const binding = entry.scope.getBinding(callee.object.name);
848
+ return Boolean(binding && helpers.urlNamespaces.has(binding));
849
+ }
850
+ return false;
851
+ }
852
+ function isImportMetaUrl(node) {
853
+ const unwrapped = unwrapNode(node);
854
+ return Boolean(unwrapped && unwrapped.type === "MemberExpression" && !unwrapped.computed && unwrapped.object.type === "MetaProperty" && unwrapped.object.meta.name === "import" && unwrapped.object.property.name === "meta" && unwrapped.property.type === "Identifier" && unwrapped.property.name === "url");
855
+ }
856
+ function resolveImmutableBinding(entry, context, safety) {
857
+ if (entry.node.type !== "Identifier") return void 0;
858
+ const binding = entry.scope.getBinding(entry.node.name);
859
+ if (!binding || binding.kind !== "const" || !binding.constant || binding.constantViolations.length > 0 || !binding.path.isVariableDeclarator() || hasDirectMemberMutation(binding) || safety === "alias" && hasUnsafeAliasBindingUse(binding, context, /* @__PURE__ */ new Set()) || safety === "config" && !isSafeConfigBinding(binding, context, /* @__PURE__ */ new Set()) || !binding.path.node.init) return;
860
+ return scopedEntry(binding.path.node.init, binding.path.scope, context);
861
+ }
862
+ function hasUnsafeAliasBindingUse(binding, context, seen) {
863
+ if (seen.has(binding)) return false;
864
+ seen.add(binding);
865
+ try {
866
+ return binding.referencePaths.some((referencePath) => {
867
+ let targetPath = unwrapReferencePath(referencePath);
868
+ while ((targetPath.parentPath?.isMemberExpression() || targetPath.parentPath?.isOptionalMemberExpression()) && targetPath.parentPath.node.object === targetPath.node) targetPath = targetPath.parentPath;
869
+ const parentPath = targetPath.parentPath;
870
+ if (!parentPath) return true;
871
+ if (parentPath.isAssignmentExpression()) return true;
872
+ if (parentPath.isUpdateExpression()) return true;
873
+ if (parentPath.isUnaryExpression({ operator: "delete" })) return true;
874
+ if (parentPath.isCallExpression() || parentPath.isOptionalCallExpression()) {
875
+ if (parentPath.node.callee === targetPath.node) return true;
876
+ return !isConfigHelperCall({
877
+ node: parentPath.node,
878
+ scope: parentPath.scope
879
+ }, context.helpers);
880
+ }
881
+ if (parentPath.isSpreadElement()) return !isSafeConfigValuePath(parentPath.parentPath, context, seen);
882
+ if (parentPath.isObjectProperty()) return !(parentPath.node.value === targetPath.node && readPropertyKey(parentPath.node) === "alias" && isSafeConfigValuePath(parentPath.parentPath, context, seen));
883
+ if (parentPath.isArrayExpression()) return !isSafeConfigValuePath(parentPath, context, seen);
884
+ if (parentPath.isVariableDeclarator()) {
885
+ if (parentPath.node.init !== targetPath.node || parentPath.node.id.type !== "Identifier" || !parentPath.parentPath?.isVariableDeclaration({ kind: "const" })) return true;
886
+ const aliasBinding = parentPath.scope.getBinding(parentPath.node.id.name);
887
+ return !aliasBinding || hasUnsafeAliasBindingUse(aliasBinding, context, seen);
888
+ }
889
+ return true;
890
+ });
891
+ } finally {
892
+ seen.delete(binding);
893
+ }
894
+ }
895
+ function hasDirectMemberMutation(binding) {
896
+ return binding.referencePaths.some((referencePath) => {
897
+ let targetPath = unwrapReferencePath(referencePath);
898
+ while ((targetPath.parentPath?.isMemberExpression() || targetPath.parentPath?.isOptionalMemberExpression()) && targetPath.parentPath.node.object === targetPath.node) targetPath = targetPath.parentPath;
899
+ const parentPath = targetPath.parentPath;
900
+ return Boolean(parentPath && (parentPath.isAssignmentExpression() || parentPath.isUpdateExpression() || parentPath.isUnaryExpression({ operator: "delete" })));
901
+ });
902
+ }
903
+ function isSafeConfigValuePath(inputPath, context, seen) {
904
+ if (!inputPath) return false;
905
+ const targetPath = unwrapReferencePath(inputPath);
906
+ const parentPath = targetPath.parentPath;
907
+ if (!parentPath) return false;
908
+ if (parentPath.isObjectProperty()) {
909
+ if (parentPath.node.value !== targetPath.node) return false;
910
+ return isSafeConfigValuePath(parentPath.parentPath, context, seen);
911
+ }
912
+ if (parentPath.isSpreadElement()) return isSafeConfigValuePath(parentPath.parentPath, context, seen);
913
+ if (parentPath.isArrowFunctionExpression()) {
914
+ if (parentPath.node.body !== targetPath.node) return false;
915
+ return isSafeConfigValuePath(parentPath, context, seen);
916
+ }
917
+ if (parentPath.isReturnStatement()) {
918
+ const functionScope = parentPath.scope.getFunctionParent();
919
+ return functionScope ? isSafeConfigValuePath(functionScope.path, context, seen) : false;
920
+ }
921
+ if (parentPath.isVariableDeclarator()) {
922
+ if (parentPath.node.init !== targetPath.node || parentPath.node.id.type !== "Identifier" || !parentPath.parentPath?.isVariableDeclaration({ kind: "const" })) return false;
923
+ const binding = parentPath.scope.getBinding(parentPath.node.id.name);
924
+ return binding ? isSafeConfigBinding(binding, context, seen) : false;
925
+ }
926
+ if (parentPath.isCallExpression() || parentPath.isOptionalCallExpression()) {
927
+ if (!parentPath.node.arguments.includes(targetPath.node)) return false;
928
+ return isConfigHelperCall({
929
+ node: parentPath.node,
930
+ scope: parentPath.scope
931
+ }, context.helpers);
932
+ }
933
+ if (parentPath.isExportDefaultDeclaration()) return true;
934
+ if (parentPath.isExportSpecifier()) {
935
+ const exported = parentPath.node.exported;
936
+ return (exported.type === "Identifier" ? exported.name : exported.value) === "default";
937
+ }
938
+ if (parentPath.isAssignmentExpression()) return parentPath.node.right === targetPath.node && isCommonJsConfigExport(parentPath.node.left);
939
+ return false;
940
+ }
941
+ function isSafeConfigBinding(binding, context, seen) {
942
+ if (seen.has(binding)) return true;
943
+ if (binding.kind !== "const" || !binding.constant || binding.constantViolations.length > 0) return false;
944
+ seen.add(binding);
945
+ try {
946
+ return binding.referencePaths.every((referencePath) => isSafeConfigValuePath(referencePath, context, seen));
947
+ } finally {
948
+ seen.delete(binding);
949
+ }
950
+ }
951
+ function unwrapReferencePath(referencePath) {
952
+ let targetPath = referencePath;
953
+ while (targetPath.parentPath && isTransparentExpression(targetPath.parentPath.node) && targetPath.parentPath.node.expression === targetPath.node) targetPath = targetPath.parentPath;
954
+ return targetPath;
955
+ }
956
+ function isTransparentExpression(node) {
957
+ return node.type === "TSAsExpression" || node.type === "TSSatisfiesExpression" || node.type === "TSNonNullExpression" || node.type === "TypeCastExpression" || node.type === "ParenthesizedExpression" || node.type === "TSInstantiationExpression";
958
+ }
959
+ function scopedEntry(node, fallbackScope, context) {
960
+ return {
961
+ node,
962
+ scope: context.scopes.get(node) ?? fallbackScope
963
+ };
964
+ }
965
+ function toFirstMatchMap(entries) {
966
+ const aliases = /* @__PURE__ */ new Map();
967
+ for (const [find, replacement] of entries) if (!aliases.has(find)) aliases.set(find, replacement);
968
+ return aliases;
969
+ }
970
+ function mergeObjectAliases(defaults, overrides) {
971
+ if (!overrides) return defaults;
972
+ const entries = new Map(defaults.entries);
973
+ for (const [find, replacement] of overrides.entries) entries.set(find, replacement);
974
+ return {
975
+ entries: [...entries],
976
+ form: "object"
977
+ };
978
+ }
979
+ /**
980
+ * Mirrors Vite's mergeAlias behavior used by Nuxt. Two object forms merge in
981
+ * property order with nested `vite.resolve.alias` values overriding duplicate
982
+ * Nuxt aliases. If either side is an array, nested Vite aliases are prepended
983
+ * because Vite resolves array aliases from first to last.
984
+ */
985
+ function mergeNuxtAliases(nuxtAliases, viteAliases) {
986
+ if (!nuxtAliases) return toFirstMatchMap(viteAliases?.entries ?? []);
987
+ if (!viteAliases) return toFirstMatchMap(nuxtAliases.entries);
988
+ if (nuxtAliases.form === "object" && viteAliases.form === "object") {
989
+ const merged = new Map(nuxtAliases.entries);
990
+ for (const [find, replacement] of viteAliases.entries) merged.set(find, replacement);
991
+ return merged;
992
+ }
993
+ return toFirstMatchMap([...viteAliases.entries, ...nuxtAliases.entries]);
994
+ }
995
+ function readPropertyKey(property) {
996
+ if (!property.computed && property.key.type === "Identifier") return property.key.name;
997
+ if (property.key.type === "StringLiteral") return property.key.value;
998
+ if (property.key.type === "NumericLiteral") return String(property.key.value);
999
+ }
1000
+ function unwrapEntry(entry) {
1001
+ return {
1002
+ node: unwrapNode(entry.node) ?? entry.node,
1003
+ scope: entry.scope
1004
+ };
1005
+ }
1006
+ function unwrapNode(node) {
1007
+ let current = node;
1008
+ while (current) {
1009
+ if (isTransparentExpression(current)) {
1010
+ current = current.expression;
1011
+ continue;
1012
+ }
1013
+ break;
1014
+ }
1015
+ return current ?? void 0;
1016
+ }
1017
+ //#endregion
1018
+ export { resolveVueProjectAliasConfiguration, resolveVueProjectAliases };
1019
+
1020
+ //# sourceMappingURL=viteAliases.js.map