i18next-cli 1.80.5 → 1.80.7

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 (36) hide show
  1. package/README.md +1 -0
  2. package/dist/cjs/cli.js +1 -1
  3. package/dist/cjs/config.js +2 -6
  4. package/dist/cjs/extractor/core/ast-visitors.js +13 -6
  5. package/dist/cjs/extractor/parsers/expression-resolver.js +93 -25
  6. package/dist/cjs/extractor/parsers/scope-manager.js +9 -5
  7. package/dist/cjs/init.js +2 -6
  8. package/dist/cjs/instrumenter/core/instrumenter.js +5 -9
  9. package/dist/cjs/localize/localize.js +6 -6
  10. package/dist/cjs/locize.js +21 -21
  11. package/dist/cjs/status.js +9 -9
  12. package/dist/cjs/utils/locize-onboarding.js +10 -10
  13. package/dist/cjs/utils/prompt.js +33 -0
  14. package/dist/cjs/utils/wrap-ora.js +12 -18
  15. package/dist/esm/cli.js +1 -1
  16. package/dist/esm/config.js +2 -2
  17. package/dist/esm/extractor/core/ast-visitors.js +13 -6
  18. package/dist/esm/extractor/parsers/expression-resolver.js +93 -26
  19. package/dist/esm/extractor/parsers/scope-manager.js +9 -5
  20. package/dist/esm/init.js +2 -2
  21. package/dist/esm/instrumenter/core/instrumenter.js +5 -5
  22. package/dist/esm/localize/localize.js +5 -5
  23. package/dist/esm/locize.js +19 -19
  24. package/dist/esm/status.js +8 -8
  25. package/dist/esm/utils/locize-onboarding.js +9 -9
  26. package/dist/esm/utils/prompt.js +24 -0
  27. package/dist/esm/utils/wrap-ora.js +11 -17
  28. package/package.json +8 -5
  29. package/types/extractor/core/ast-visitors.d.ts.map +1 -1
  30. package/types/extractor/parsers/expression-resolver.d.ts +17 -0
  31. package/types/extractor/parsers/expression-resolver.d.ts.map +1 -1
  32. package/types/extractor/parsers/scope-manager.d.ts +1 -0
  33. package/types/extractor/parsers/scope-manager.d.ts.map +1 -1
  34. package/types/utils/prompt.d.ts +8 -0
  35. package/types/utils/prompt.d.ts.map +1 -0
  36. package/types/utils/wrap-ora.d.ts +1 -1
@@ -1,7 +1,7 @@
1
1
  'use strict';
2
2
 
3
3
  var node_util = require('node:util');
4
- var ora = require('ora');
4
+ var yoctoSpinner = require('yocto-spinner');
5
5
  var node_path = require('node:path');
6
6
  var extractor = require('./extractor/core/extractor.js');
7
7
  var keyFinder = require('./extractor/core/key-finder.js');
@@ -19,7 +19,7 @@ var locizeFunnel = require('./utils/locize-funnel.js');
19
19
 
20
20
  function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
21
21
 
22
- var ora__default = /*#__PURE__*/_interopDefault(ora);
22
+ var yoctoSpinner__default = /*#__PURE__*/_interopDefault(yoctoSpinner);
23
23
 
24
24
  const LOCIZE_SIGNUP_URL = 'https://www.locize.app/register?from=i18next_cli__status';
25
25
  function globToRegex(glob) {
@@ -121,10 +121,10 @@ function getOptionalPluralCategories(locale, isOrdinal) {
121
121
  async function runStatus(config, options = {}) {
122
122
  config.extract.primaryLanguage ||= config.locales[0] || 'en';
123
123
  config.extract.secondaryLanguages ||= config.locales.filter((l) => l !== config?.extract?.primaryLanguage);
124
- const spinner = ora__default.default('Analyzing project localization status...\n').start();
124
+ const spinner = yoctoSpinner__default.default({ text: 'Analyzing project localization status...\n' }).start();
125
125
  try {
126
126
  const report = await generateStatusReport(config);
127
- spinner.succeed('Analysis complete.');
127
+ spinner.success('Analysis complete.');
128
128
  await displayStatusReport(report, config, options);
129
129
  // When a specific locale is requested (`status <locale>`), the pass/fail
130
130
  // result must reflect THAT locale only — otherwise the displayed summary
@@ -161,14 +161,14 @@ async function runStatus(config, options = {}) {
161
161
  if (hasMissing) {
162
162
  // Name the locale when the check is scoped so the failure reason is clear
163
163
  // (the displayed summary already explains what is missing for it).
164
- spinner.fail(scopedLocale
164
+ spinner.error(scopedLocale
165
165
  ? `Error: Incomplete translations detected for "${scopedLocale}".`
166
166
  : 'Error: Incomplete translations detected.');
167
167
  process.exit(1);
168
168
  }
169
169
  }
170
170
  catch (error) {
171
- spinner.fail('Failed to generate status report.');
171
+ spinner.error('Failed to generate status report.');
172
172
  console.error(error);
173
173
  }
174
174
  }
@@ -871,14 +871,14 @@ async function runUnusedReport(config, options = {}) {
871
871
  // be active regardless of the user's config. The caller's config object
872
872
  // stays untouched.
873
873
  const cfg = { ...config, extract: { ...config.extract, removeUnusedKeys: true } };
874
- const spinner = ora__default.default('Analyzing project for unused translation keys...\n').start();
874
+ const spinner = yoctoSpinner__default.default({ text: 'Analyzing project for unused translation keys...\n' }).start();
875
875
  let extraction;
876
876
  try {
877
877
  extraction = await extractor.runExtractor(cfg, { isDryRun: true, quiet: true });
878
- spinner.succeed('Analysis complete.');
878
+ spinner.success('Analysis complete.');
879
879
  }
880
880
  catch (error) {
881
- spinner.fail('Failed to analyze unused translation keys.');
881
+ spinner.error('Failed to analyze unused translation keys.');
882
882
  console.error(error);
883
883
  process.exit(1);
884
884
  return;
@@ -1,11 +1,11 @@
1
1
  'use strict';
2
2
 
3
- var inquirer = require('inquirer');
4
- var execa = require('execa');
3
+ var prompt = require('./prompt.js');
4
+ var spawn = require('nano-spawn');
5
5
 
6
6
  function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
7
7
 
8
- var inquirer__default = /*#__PURE__*/_interopDefault(inquirer);
8
+ var spawn__default = /*#__PURE__*/_interopDefault(spawn);
9
9
 
10
10
  /** Rough 8-4-4-4-12 hex UUID shape — not strict (locize project IDs may evolve). */
11
11
  const UUID_SHAPE = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
@@ -25,29 +25,29 @@ async function openBrowser(url, opts = {}) {
25
25
  }
26
26
  try {
27
27
  if (process.platform === 'darwin') {
28
- await execa.execa('open', [url], { stdio: 'ignore' });
28
+ await spawn__default.default('open', [url], { stdio: 'ignore' });
29
29
  }
30
30
  else if (process.platform === 'win32') {
31
31
  // `start` is a cmd.exe builtin; the empty "" is the window-title slot
32
- await execa.execa('cmd', ['/c', 'start', '""', url], { stdio: 'ignore' });
32
+ await spawn__default.default('cmd', ['/c', 'start', '""', url], { stdio: 'ignore' });
33
33
  }
34
34
  else if (isWSL) {
35
35
  // WSL: try the wslu / wsl-open shims that bridge to the Windows side
36
36
  // before falling back to xdg-open (which usually isn't installed there).
37
37
  try {
38
- await execa.execa('wslview', [url], { stdio: 'ignore' });
38
+ await spawn__default.default('wslview', [url], { stdio: 'ignore' });
39
39
  }
40
40
  catch {
41
41
  try {
42
- await execa.execa('wsl-open', [url], { stdio: 'ignore' });
42
+ await spawn__default.default('wsl-open', [url], { stdio: 'ignore' });
43
43
  }
44
44
  catch {
45
- await execa.execa('xdg-open', [url], { stdio: 'ignore' });
45
+ await spawn__default.default('xdg-open', [url], { stdio: 'ignore' });
46
46
  }
47
47
  }
48
48
  }
49
49
  else {
50
- await execa.execa('xdg-open', [url], { stdio: 'ignore' });
50
+ await spawn__default.default('xdg-open', [url], { stdio: 'ignore' });
51
51
  }
52
52
  return true;
53
53
  }
@@ -60,7 +60,7 @@ async function openBrowser(url, opts = {}) {
60
60
  * Warns (but does not block) when the Project ID does not look like a UUID.
61
61
  */
62
62
  async function promptLocizeCredentials() {
63
- const credentials = await inquirer__default.default.prompt([
63
+ const credentials = await prompt.prompt([
64
64
  {
65
65
  type: 'input',
66
66
  name: 'projectId',
@@ -0,0 +1,33 @@
1
+ 'use strict';
2
+
3
+ var confirm = require('@inquirer/confirm');
4
+ var input = require('@inquirer/input');
5
+ var password = require('@inquirer/password');
6
+ var select = require('@inquirer/select');
7
+
8
+ function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
9
+
10
+ var confirm__default = /*#__PURE__*/_interopDefault(confirm);
11
+ var input__default = /*#__PURE__*/_interopDefault(input);
12
+ var password__default = /*#__PURE__*/_interopDefault(password);
13
+ var select__default = /*#__PURE__*/_interopDefault(select);
14
+
15
+ const prompts = { confirm: confirm__default.default, input: input__default.default, password: password__default.default, select: select__default.default };
16
+ /**
17
+ * Minimal stand-in for inquirer's legacy `prompt([...questions])`, covering what this CLI
18
+ * asks: input/password/confirm/select questions with default, choices, validate, filter
19
+ * and when. Using the single @inquirer prompts instead of the `inquirer` bundle keeps the
20
+ * editor prompt (and its iconv-lite/safer-buffer chain) out of the dependency tree.
21
+ */
22
+ async function prompt(questions) {
23
+ const answers = {};
24
+ for (const { type = 'input', name, when, filter, ...config } of questions) {
25
+ if (typeof when === 'function' ? !(await when(answers)) : when === false)
26
+ continue;
27
+ const value = await prompts[type](config);
28
+ answers[name] = filter ? await filter(value, answers) : value;
29
+ }
30
+ return answers;
31
+ }
32
+
33
+ exports.prompt = prompt;
@@ -1,26 +1,26 @@
1
1
  'use strict';
2
2
 
3
- var ora = require('ora');
3
+ var yoctoSpinner = require('yocto-spinner');
4
4
 
5
5
  function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
6
6
 
7
- var ora__default = /*#__PURE__*/_interopDefault(ora);
7
+ var yoctoSpinner__default = /*#__PURE__*/_interopDefault(yoctoSpinner);
8
8
 
9
9
  /**
10
10
  * Creates a spinner-like object that either:
11
11
  * - is fully silent (quiet mode),
12
12
  * - logs only start/succeed/fail events to a logger (no animation),
13
- * - or falls back to ora's default spinner.
13
+ * - or falls back to an animated yocto-spinner.
14
14
  *
15
15
  * This avoids flooding structured loggers with spinner frames and ensures clean output in CI, Vite, etc.
16
16
  */
17
17
  function createSpinnerLike(initialText, options = {}) {
18
18
  const { quiet, logger } = options;
19
19
  let text = initialText;
20
- // If interactive (no logger and not quiet), create a single real ora spinner
20
+ // If interactive (no logger and not quiet), create a single real spinner
21
21
  let realSpinner = null;
22
22
  if (!quiet && !logger) {
23
- realSpinner = ora__default.default({ text }).start();
23
+ realSpinner = yoctoSpinner__default.default({ text }).start();
24
24
  }
25
25
  const self = {
26
26
  get text() { return text; },
@@ -44,8 +44,8 @@ function createSpinnerLike(initialText, options = {}) {
44
44
  }
45
45
  else {
46
46
  if (!realSpinner)
47
- realSpinner = ora__default.default({ text }).start();
48
- realSpinner.succeed(message);
47
+ realSpinner = yoctoSpinner__default.default({ text }).start();
48
+ realSpinner.success(message);
49
49
  }
50
50
  },
51
51
  fail(msg) {
@@ -62,8 +62,8 @@ function createSpinnerLike(initialText, options = {}) {
62
62
  }
63
63
  else {
64
64
  if (!realSpinner)
65
- realSpinner = ora__default.default({ text }).start();
66
- realSpinner.fail(message);
65
+ realSpinner = yoctoSpinner__default.default({ text }).start();
66
+ realSpinner.error(message);
67
67
  }
68
68
  },
69
69
  warn(msg) {
@@ -80,14 +80,8 @@ function createSpinnerLike(initialText, options = {}) {
80
80
  }
81
81
  else {
82
82
  if (!realSpinner)
83
- realSpinner = ora__default.default({ text }).start();
84
- try {
85
- realSpinner.warn?.(message);
86
- }
87
- catch {
88
- realSpinner.stop();
89
- process.stderr.write(message + '\n');
90
- }
83
+ realSpinner = yoctoSpinner__default.default({ text }).start();
84
+ realSpinner.warning(message);
91
85
  }
92
86
  },
93
87
  stop() { if (realSpinner)
@@ -105,7 +99,7 @@ function createSpinnerLike(initialText, options = {}) {
105
99
  }
106
100
  else {
107
101
  if (!realSpinner)
108
- realSpinner = ora__default.default({ text }).start();
102
+ realSpinner = yoctoSpinner__default.default({ text }).start();
109
103
  realSpinner.text = String(msg);
110
104
  }
111
105
  }
package/dist/esm/cli.js CHANGED
@@ -33,7 +33,7 @@ const program = new Command();
33
33
  program
34
34
  .name('i18next-cli')
35
35
  .description('A unified, high-performance i18next CLI.')
36
- .version('1.80.5') // This string is replaced with the actual version at build time by rollup
36
+ .version('1.80.7') // This string is replaced with the actual version at build time by rollup
37
37
  .addHelpText('after', '\nUsing an AI coding agent? Install the i18next-localization skill: npx skills add i18next/i18next-cli\n');
38
38
  // new: global config override option
39
39
  program.option('-c, --config <path>', 'Path to i18next-cli config file (overrides detection)');
@@ -3,7 +3,7 @@ import { pathToFileURL } from 'node:url';
3
3
  import { access, readFile } from 'node:fs/promises';
4
4
  import { createJiti } from 'jiti';
5
5
  import { parse } from 'jsonc-parser';
6
- import inquirer from 'inquirer';
6
+ import { prompt } from './utils/prompt.js';
7
7
  import { styleText } from 'node:util';
8
8
  import { runInit } from './init.js';
9
9
  import { ConsoleLogger } from './utils/logger.js';
@@ -126,7 +126,7 @@ async function ensureConfig(configPath, logger = new ConsoleLogger()) {
126
126
  return config;
127
127
  }
128
128
  // No config found, so we prompt the user.
129
- const { shouldInit } = await inquirer.prompt([{
129
+ const { shouldInit } = await prompt([{
130
130
  type: 'confirm',
131
131
  name: 'shouldInit',
132
132
  message: styleText('yellow', 'Configuration file not found. Would you like to create one now?'),
@@ -98,6 +98,7 @@ class ASTVisitors {
98
98
  // `useTranslation(ns)` where `ns` is a param typed `'a' | 'b'` → first member
99
99
  // (same rule as `TFunction<'a' | 'b'>`).
100
100
  this.scopeManager.identifierFallback = (name) => this.expressionResolver.getVariableValues(name)?.[0];
101
+ this.scopeManager.isParameter = (name) => this.expressionResolver.isParameter(name);
101
102
  // use shared resolver when provided so captured enums/objects are visible across files
102
103
  this.expressionResolver = expressionResolver ?? new ExpressionResolver(this.hooks);
103
104
  this.callExpressionHandler = new CallExpressionHandler(config, pluginContext, logger, this.expressionResolver, () => this.getCurrentFile(), () => this.getCurrentCode(), (name) => this.scopeManager.resolveSimpleStringIdentifier(name));
@@ -134,6 +135,8 @@ class ASTVisitors {
134
135
  _walkForConstants(node) {
135
136
  if (!node || typeof node !== 'object')
136
137
  return;
138
+ // Like `walk`: a function's parameters hide the values declared under their names
139
+ const leaveParameters = Array.isArray(node.params) ? this.expressionResolver.enterParameters(node) : undefined;
137
140
  switch (node.type) {
138
141
  case 'VariableDeclarator':
139
142
  // String constants → ScopeManager.sharedConstants
@@ -191,6 +194,7 @@ class ASTVisitors {
191
194
  this._walkForConstants(child);
192
195
  }
193
196
  }
197
+ leaveParameters?.();
194
198
  }
195
199
  /**
196
200
  * Main entry point for AST traversal.
@@ -259,6 +263,9 @@ class ASTVisitors {
259
263
  }
260
264
  }
261
265
  }
266
+ // Any function, also a method or constructor: its parameters hide the values declared
267
+ // under their names while its body is walked (#316)
268
+ const leaveParameters = Array.isArray(node.params) ? this.expressionResolver.enterParameters(node) : undefined;
262
269
  // ENTER SCOPE for functions
263
270
  // Accept many SWC/TS AST variants for function-like nodes (declarations, expressions, arrow functions)
264
271
  if (node.type === 'Function' ||
@@ -647,6 +654,7 @@ class ASTVisitors {
647
654
  // --- END RECURSION ---
648
655
  // Remove temporary callback param binding if one was injected for this node
649
656
  arrayCallbackCleanup?.();
657
+ leaveParameters?.();
650
658
  // LEAVE SCOPE for functions
651
659
  if (isNewScope) {
652
660
  // Remove temporary parameter type bindings
@@ -880,12 +888,11 @@ class ASTVisitors {
880
888
  // The single argument to Object.keys/values must be a known identifier
881
889
  const mapArg = this.expressionResolver.unwrapNamespace(obj.arguments?.[0]?.expression);
882
890
  if (mapArg?.type === 'Identifier') {
883
- const mapEntry = this.expressionResolver.getObjectMap(mapArg.value);
884
- if (mapEntry) {
885
- const values = isKeys ? Object.keys(mapEntry) : Object.values(mapEntry);
886
- if (values.length > 0) {
887
- return this.extractCallbackParam(node, values, elementParamIndex);
888
- }
891
+ const values = isKeys
892
+ ? this.expressionResolver.getObjectKeys(mapArg.value)
893
+ : Object.values(this.expressionResolver.getObjectMap(mapArg.value) ?? {});
894
+ if (values?.length) {
895
+ return this.extractCallbackParam(node, values, elementParamIndex);
889
896
  }
890
897
  }
891
898
  }
@@ -60,6 +60,31 @@ const memberByKey = (members, key) => {
60
60
  }
61
61
  return index.get(key);
62
62
  };
63
+ // The names a function parameter binds: `options`, `{ a, b: [c] } = {}`, `...rest`, `private d`
64
+ const bindingNames = (pat) => {
65
+ switch (pat?.type) {
66
+ case 'Identifier': return [pat.value];
67
+ case 'Parameter': return bindingNames(pat.pat);
68
+ case 'TsParameterProperty': return bindingNames(pat.param);
69
+ case 'AssignmentPattern': return bindingNames(pat.left);
70
+ case 'RestElement': return bindingNames(pat.argument);
71
+ case 'ArrayPattern': return pat.elements.flatMap(bindingNames);
72
+ case 'ObjectPattern': return pat.properties.flatMap((p) => p.type === 'AssignmentPatternProperty' ? [p.key.value] : bindingNames(p.value ?? p.argument));
73
+ default: return [];
74
+ }
75
+ };
76
+ // A table of values (variables, object maps, enums, functions). Inside a function, a parameter
77
+ // hides the entry of its name: `options` there is never an `options` declared elsewhere (#316)
78
+ class ValueTable extends Map {
79
+ scope;
80
+ constructor(scope) {
81
+ super();
82
+ this.scope = scope;
83
+ }
84
+ get(name) {
85
+ return this.scope.isParameter(name) ? undefined : super.get(name);
86
+ }
87
+ }
63
88
  // `/src/api/github-api.ts`, `.d.ts`, or an import of `./github-api.js` -> `/src/api/github-api`
64
89
  const moduleKey = (path) => path.replace(/(\.d)?\.[cm]?[jt]sx?$/, '');
65
90
  /**
@@ -71,11 +96,16 @@ const moduleKey = (path) => path.replace(/(\.d)?\.[cm]?[jt]sx?$/, '');
71
96
  */
72
97
  class ModuleTable extends Map {
73
98
  scope;
74
- constructor(scope) {
99
+ holdsValues;
100
+ constructor(scope, holdsValues = false) {
75
101
  super();
76
102
  this.scope = scope;
103
+ this.holdsValues = holdsValues;
77
104
  }
78
105
  get(name) {
106
+ // Like a ValueTable: a parameter hides the value declared under its name in any file
107
+ if (this.holdsValues && this.scope.isParameter(name))
108
+ return undefined;
79
109
  for (const key of this.scope.keysOf(name)) {
80
110
  const value = super.get(key);
81
111
  if (value !== undefined)
@@ -129,18 +159,22 @@ class ExpressionResolver {
129
159
  // Maps variableName -> either:
130
160
  // - string[] (possible string values)
131
161
  // - Record<string, string> (object of static string properties)
132
- variableTable = new Map();
162
+ variableTable = new ValueTable(this);
133
163
  // Shared (cross-file) table for enums / exported object maps that should persist
134
- sharedEnumTable = new ModuleTable(this);
164
+ sharedEnumTable = new ModuleTable(this, true);
135
165
  // Per-file table for type aliases: Maps typeName -> string[]
136
166
  // e.g. `type ChangeType = 'all' | 'next' | 'this'` -> { ChangeType: ['all', 'next', 'this'] }
137
167
  typeAliasTable = new Map();
138
168
  // Shared (cross-file) table for string-array constants (e.g. `as const` arrays).
139
169
  // Persists across resetFileSymbols() so exported arrays are visible to importers.
140
- sharedVariableTable = new ModuleTable(this);
170
+ sharedVariableTable = new ModuleTable(this, true);
141
171
  // Shared (cross-file) table for as-const object maps, `export const LABELS = { … } as const`,
142
172
  // so `LABELS.save` and `Object.keys(LABELS)` resolve in importing files.
143
- sharedObjectMapTable = new ModuleTable(this);
173
+ sharedObjectMapTable = new ModuleTable(this, true);
174
+ // Shared (cross-file) literal keys of every object declared as `const MAP = { … }`, whatever
175
+ // its values are: the map tables above only hold string values, `keyof typeof MAP` and
176
+ // `Object.keys(MAP)` need all keys (#317).
177
+ sharedObjectKeysTable = new ModuleTable(this, true);
144
178
  // Shared (cross-file) table for type aliases — populated alongside typeAliasTable.
145
179
  // Persists across resetFileSymbols() so exported type aliases are visible to importers.
146
180
  sharedTypeAliasTable = new ModuleTable(this);
@@ -148,7 +182,7 @@ class ExpressionResolver {
148
182
  // both explicit return-type annotations and body-inferred return values so
149
183
  // that `t(fn())` / `const x = fn(); t(\`...${x}...\`)` work across files.
150
184
  // Persists across resetFileSymbols() just like the other shared tables.
151
- sharedFunctionReturnTable = new ModuleTable(this);
185
+ sharedFunctionReturnTable = new ModuleTable(this, true);
152
186
  // Temporary per-scope variable overrides, used to inject .map() / .forEach()
153
187
  // callback parameters while the callback body is being walked.
154
188
  temporaryVariables = new Map();
@@ -179,13 +213,13 @@ class ExpressionResolver {
179
213
  typeParamBindings = new Map();
180
214
  // Shared (cross-file) member maps of functions returning an object type,
181
215
  // e.g. `const getAnimal = (): Animal => …` -> { getAnimal: { type: ['DUCK', 'DOG'] } }
182
- sharedFunctionReturnMembers = new ModuleTable(this);
216
+ sharedFunctionReturnMembers = new ModuleTable(this, true);
183
217
  // Per-file identifiers holding an object type, from their annotation or from the
184
218
  // function they were initialised by: `const animal = getAnimal()` -> { animal: { type: [...] } }
185
- objectVariables = new Map();
219
+ objectVariables = new ValueTable(this);
186
220
  // Per-file object literals by variable, so `const params = { count }; t('key', params)`
187
221
  // reads its options like an inline object (#307)
188
- objectLiterals = new Map();
222
+ objectLiterals = new ValueTable(this);
189
223
  // Set while the pre-scan runs. Captures that read other declarations queue a
190
224
  // replay here, because what they read may be declared in a file scanned later.
191
225
  recording = false;
@@ -207,6 +241,8 @@ class ExpressionResolver {
207
241
  fileNamespaces = new Map();
208
242
  // module -> the variables it declares, which shadow the same names declared in other files
209
243
  fileVariables = new Map();
244
+ // The parameters of the functions being read, innermost last
245
+ parameters = [];
210
246
  // tsconfig `paths`, `@api` -> `/abs/src/api`
211
247
  pathAliases = {};
212
248
  constructor(hooks) {
@@ -249,6 +285,19 @@ class ExpressionResolver {
249
285
  keys.push(name);
250
286
  return keys;
251
287
  }
288
+ // ValueTable / ModuleTable: whether `name` is a parameter of a function being read
289
+ isParameter(name) {
290
+ return this.parameters.includes(name);
291
+ }
292
+ /**
293
+ * Hide the values declared under the names of `fn`'s parameters while its body is read.
294
+ * Call the returned function when leaving it.
295
+ */
296
+ enterParameters(fn) {
297
+ const names = (fn?.params ?? []).flatMap(bindingNames);
298
+ this.parameters.push(...names);
299
+ return () => { this.parameters.length -= names.length; };
300
+ }
252
301
  // ModuleTable: the key a declaration made in the current file is also stored under
253
302
  declaringKey(name) {
254
303
  return this.currentModule && !name.includes('#') ? `${this.currentModule}#${name}` : undefined;
@@ -293,6 +342,7 @@ class ExpressionResolver {
293
342
  this.arrayElementMembers.clear();
294
343
  this.objectVariables.clear();
295
344
  this.objectLiterals.clear();
345
+ this.parameters = [];
296
346
  }
297
347
  /**
298
348
  * Call once every file has been pre-scanned. Captures ran in file order, so one
@@ -449,6 +499,7 @@ class ExpressionResolver {
449
499
  if (unwrappedInit.type === 'ObjectExpression' && Array.isArray(unwrappedInit.properties)) {
450
500
  this.objectLiterals.set(name, unwrappedInit);
451
501
  const map = {};
502
+ const keys = [];
452
503
  for (const p of unwrappedInit.properties) {
453
504
  if (!p || p.type !== 'KeyValueProperty')
454
505
  continue;
@@ -456,6 +507,7 @@ class ExpressionResolver {
456
507
  const keyName = keyNode?.type === 'Identifier' ? keyNode.value : keyNode?.type === 'StringLiteral' ? keyNode.value : undefined;
457
508
  if (!keyName)
458
509
  continue;
510
+ keys.push(keyName);
459
511
  const valExpr = p.value;
460
512
  const vals = this.resolvePossibleStringValuesFromExpression(valExpr);
461
513
  // Only capture properties that we can statically resolve to a single string.
@@ -463,6 +515,8 @@ class ExpressionResolver {
463
515
  map[keyName] = vals[0];
464
516
  }
465
517
  }
518
+ if (keys.length > 0)
519
+ this.sharedObjectKeysTable.set(name, keys);
466
520
  // If at least one property was resolvable, record the partial map.
467
521
  if (Object.keys(map).length > 0) {
468
522
  this.variableTable.set(name, map);
@@ -996,15 +1050,26 @@ class ExpressionResolver {
996
1050
  // if (...) return OrganizationType.CONTRACTOR;
997
1051
  // }
998
1052
  const exprs = returnType ? [] : this.returnExpressions(fn);
999
- const vals = returnType
1000
- ? this.resolvePossibleStringValuesFromType(returnType)
1001
- : [...new Set(exprs.flatMap(e => this.resolvePossibleStringValuesFromExpression(e)))];
1053
+ // The body is read inside the function, where its parameters hide the values
1054
+ // declared under their names (#316)
1055
+ const leaveParameters = this.enterParameters(fn);
1056
+ let vals;
1057
+ let refs;
1058
+ try {
1059
+ vals = returnType
1060
+ ? this.resolvePossibleStringValuesFromType(returnType)
1061
+ : [...new Set(exprs.flatMap(e => this.resolvePossibleStringValuesFromExpression(e)))];
1062
+ // A replay has lost the file's local bindings, so it re-resolves only the
1063
+ // return type, or the returned enum / object members and calls of other
1064
+ // functions, kept as small nodes so no function body stays in memory.
1065
+ // It runs outside the function, so none of them may go through a parameter.
1066
+ refs = this.recording ? crossFileRefs(exprs).filter(e => !this.isParameter((e.object ?? e.callee).value)) : [];
1067
+ }
1068
+ finally {
1069
+ leaveParameters();
1070
+ }
1002
1071
  if (vals.length > 0)
1003
1072
  this.variableTable.set(name, vals);
1004
- // A replay has lost the file's local bindings, so it re-resolves only the
1005
- // return type, or the returned enum / object members and calls of other
1006
- // functions, kept as small nodes so no function body stays in memory.
1007
- const refs = this.recording ? crossFileRefs(exprs) : [];
1008
1073
  const store = () => {
1009
1074
  const all = returnType
1010
1075
  ? this.resolvePossibleStringValuesFromType(returnType)
@@ -1135,6 +1200,14 @@ class ExpressionResolver {
1135
1200
  return v;
1136
1201
  return this.sharedObjectMapTable.get(name) ?? this.sharedEnumTable.get(name);
1137
1202
  }
1203
+ /** All keys of an object map, also those whose value is not a string, or of an enum. */
1204
+ getObjectKeys(name) {
1205
+ const keys = this.sharedObjectKeysTable.get(name);
1206
+ if (keys)
1207
+ return keys;
1208
+ const map = this.getObjectMap(name);
1209
+ return map ? Object.keys(map) : undefined;
1210
+ }
1138
1211
  /**
1139
1212
  * Capture a TypeScript enum declaration so members can be resolved later.
1140
1213
  * Accepts SWC node shapes like `TsEnumDeclaration` / `TSEnumDeclaration`.
@@ -1567,15 +1640,9 @@ class ExpressionResolver {
1567
1640
  const exprName = inner.exprName ?? inner.expr ?? inner.entityName;
1568
1641
  const varName = this.typeQueryName(exprName);
1569
1642
  if (varName) {
1570
- // Look up in variableTable (local) or sharedObjectMapTable (cross-file) for object maps
1571
- const v = this.variableTable.get(varName) ?? this.sharedObjectMapTable.get(varName);
1572
- if (v && !Array.isArray(v) && typeof v === 'object') {
1573
- return Object.keys(v);
1574
- }
1575
- // Also check sharedEnumTable (enum keys)
1576
- const ev = this.sharedEnumTable.get(varName);
1577
- if (ev)
1578
- return Object.keys(ev);
1643
+ const keys = this.getObjectKeys(varName);
1644
+ if (keys)
1645
+ return keys;
1579
1646
  }
1580
1647
  }
1581
1648
  }
@@ -1633,4 +1700,4 @@ class ExpressionResolver {
1633
1700
  }
1634
1701
  }
1635
1702
 
1636
- export { ExpressionResolver, nestedMembers };
1703
+ export { ExpressionResolver, ValueTable, nestedMembers };
@@ -1,4 +1,5 @@
1
1
  import { getObjectPropValue } from './ast-utils.js';
2
+ import { ValueTable } from './expression-resolver.js';
2
3
 
3
4
  class ScopeManager {
4
5
  scopeStack = [];
@@ -10,20 +11,23 @@ class ScopeManager {
10
11
  // inside class methods.
11
12
  thisFieldStack = [];
12
13
  // Track simple local constants with string literal values to resolve identifier args
13
- simpleConstants = new Map();
14
+ simpleConstants = new ValueTable(this);
14
15
  // Track simple local constant objects with string literal property values
15
- simpleConstantObjects = new Map();
16
+ simpleConstantObjects = new ValueTable(this);
16
17
  // `const NS = ['a', 'b']` → used by resolveNsArg for `useTranslation(NS)`.
17
- simpleConstantArrays = new Map();
18
+ simpleConstantArrays = new ValueTable(this);
18
19
  // `({ ns = 'x' }) =>` / `(ns = 'x') =>` param defaults, set/cleared per function by the visitor.
19
20
  paramDefaults = new Map();
20
21
  // Last-resort identifier resolution for `useTranslation(ns)` (e.g. first member of
21
22
  // a param's union type), wired up by the visitor.
22
23
  identifierFallback;
24
+ // Whether `name` is a parameter of a function being walked, wired up by the visitor. The
25
+ // constant tables are ValueTables: `useTranslation(ns)` in `useT(ns)` is no `const ns` of another file
26
+ isParameter = () => false;
23
27
  // Shared (cross-file) tables so that exported constants from one file can be
24
28
  // resolved when imported in another. These are NOT cleared by reset().
25
- sharedConstants = new Map();
26
- sharedConstantObjects = new Map();
29
+ sharedConstants = new ValueTable(this);
30
+ sharedConstantObjects = new ValueTable(this);
27
31
  constructor(config) {
28
32
  this.config = config;
29
33
  }
package/dist/esm/init.js CHANGED
@@ -1,4 +1,4 @@
1
- import inquirer from 'inquirer';
1
+ import { prompt } from './utils/prompt.js';
2
2
  import { writeFile, readFile } from 'node:fs/promises';
3
3
  import { resolve } from 'node:path';
4
4
  import { detectConfig } from './heuristic-config.js';
@@ -171,7 +171,7 @@ async function runInit(options = {}) {
171
171
  answers = { ...defaults, ...given };
172
172
  }
173
173
  else {
174
- answers = { ...given, ...(remaining.length > 0 ? await inquirer.prompt(remaining) : {}) };
174
+ answers = { ...given, ...(remaining.length > 0 ? await prompt(remaining) : {}) };
175
175
  }
176
176
  let locizeConfig;
177
177
  const knownProjectId = options.projectId || process.env.LOCIZE_PROJECTID || process.env.LOCIZE_PID;