i18next-cli 1.18.0 → 1.19.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/CHANGELOG.md +8 -0
- package/dist/cjs/cli.js +1 -1
- package/dist/cjs/extractor/core/ast-visitors.js +1 -1
- package/dist/cjs/extractor/core/translation-manager.js +1 -1
- package/dist/cjs/extractor/parsers/expression-resolver.js +1 -1
- package/dist/esm/cli.js +1 -1
- package/dist/esm/extractor/core/ast-visitors.js +1 -1
- package/dist/esm/extractor/core/translation-manager.js +1 -1
- package/dist/esm/extractor/parsers/expression-resolver.js +1 -1
- package/package.json +1 -1
- package/src/cli.ts +1 -1
- package/src/extractor/core/ast-visitors.ts +5 -0
- package/src/extractor/core/translation-manager.ts +18 -3
- package/src/extractor/parsers/expression-resolver.ts +100 -0
- package/types/extractor/core/ast-visitors.d.ts.map +1 -1
- package/types/extractor/core/translation-manager.d.ts.map +1 -1
- package/types/extractor/parsers/expression-resolver.d.ts +12 -0
- package/types/extractor/parsers/expression-resolver.d.ts.map +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,14 @@ All notable changes to this project will be documented in this file.
|
|
|
5
5
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
6
6
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
7
|
|
|
8
|
+
## [1.19.0](https://github.com/i18next/i18next-cli/compare/v1.18.1...v1.19.0) - 2025-10-31
|
|
9
|
+
|
|
10
|
+
- feat(extractor): improve key extraction to detect translation keys stored in local variables, object properties and simple string expressions [#83](https://github.com/i18next/i18next-cli/issues/83)
|
|
11
|
+
|
|
12
|
+
## [1.18.1](https://github.com/i18next/i18next-cli/compare/v1.18.0...v1.18.1) - 2025-10-30
|
|
13
|
+
|
|
14
|
+
- improve regression introduced in v1.17.2 [#82](https://github.com/i18next/i18next-cli/issues/82)
|
|
15
|
+
|
|
8
16
|
## [1.18.0](https://github.com/i18next/i18next-cli/compare/v1.17.2...v1.18.0) - 2025-10-30
|
|
9
17
|
|
|
10
18
|
- fix regression introduced in v1.17.2 [#82](https://github.com/i18next/i18next-cli/issues/82)
|
package/dist/cjs/cli.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
"use strict";var e=require("commander"),t=require("chokidar"),o=require("glob"),n=require("minimatch"),i=require("chalk"),a=require("./config.js"),r=require("./heuristic-config.js"),c=require("./extractor/core/extractor.js");require("node:path"),require("node:fs/promises"),require("jiti");var s=require("./types-generator.js"),l=require("./syncer.js"),u=require("./migrator.js"),g=require("./init.js"),d=require("./linter.js"),p=require("./status.js"),f=require("./locize.js");const m=new e.Command;m.name("i18next-cli").description("A unified, high-performance i18next CLI.").version("1.
|
|
2
|
+
"use strict";var e=require("commander"),t=require("chokidar"),o=require("glob"),n=require("minimatch"),i=require("chalk"),a=require("./config.js"),r=require("./heuristic-config.js"),c=require("./extractor/core/extractor.js");require("node:path"),require("node:fs/promises"),require("jiti");var s=require("./types-generator.js"),l=require("./syncer.js"),u=require("./migrator.js"),g=require("./init.js"),d=require("./linter.js"),p=require("./status.js"),f=require("./locize.js");const m=new e.Command;m.name("i18next-cli").description("A unified, high-performance i18next CLI.").version("1.19.0"),m.option("-c, --config <path>","Path to i18next-cli config file (overrides detection)"),m.command("extract").description("Extract translation keys from source files and update resource files.").option("-w, --watch","Watch for file changes and re-run the extractor.").option("--ci","Exit with a non-zero status code if any files are updated.").option("--dry-run","Run the extractor without writing any files to disk.").option("--sync-primary","Sync primary language values with default values from code.").action(async e=>{try{const o=m.opts().config,i=await a.ensureConfig(o),r=async()=>{const t=await c.runExtractor(i,{isWatchMode:!!e.watch,isDryRun:!!e.dryRun,syncPrimaryWithDefaults:!!e.syncPrimary});return e.ci&&!t?(console.log("✅ No files were updated."),process.exit(0)):e.ci&&t&&(console.error("❌ Some files were updated. This should not happen in CI mode."),process.exit(1)),t};if(await r(),e.watch){console.log("\nWatching for changes...");const e=await w(i.extract.input),o=y(i.extract.ignore),a=h(i.extract.output),c=[...o,...a].filter(Boolean),s=e.filter(e=>!c.some(t=>n.minimatch(e,t,{dot:!0})));t.watch(s,{ignored:/node_modules/,persistent:!0}).on("change",e=>{console.log(`\nFile changed: ${e}`),r()})}}catch(e){console.error("Error running extractor:",e),process.exit(1)}}),m.command("status [locale]").description("Display translation status. Provide a locale for a detailed key-by-key view.").option("-n, --namespace <ns>","Filter the status report by a specific namespace").action(async(e,t)=>{const o=m.opts().config;let n=await a.loadConfig(o);if(!n){console.log(i.blue("No config file found. Attempting to detect project structure..."));const e=await r.detectConfig();e||(console.error(i.red("Could not automatically detect your project structure.")),console.log(`Please create a config file first by running: ${i.cyan("npx i18next-cli init")}`),process.exit(1)),console.log(i.green("Project structure detected successfully!")),n=e}await p.runStatus(n,{detail:e,namespace:t.namespace})}),m.command("types").description("Generate TypeScript definitions from translation resource files.").option("-w, --watch","Watch for file changes and re-run the type generator.").action(async e=>{const o=m.opts().config,i=await a.ensureConfig(o),r=()=>s.runTypesGenerator(i);if(await r(),e.watch){console.log("\nWatching for changes...");const e=await w(i.types?.input||[]),o=[...y(i.extract?.ignore)].filter(Boolean),a=e.filter(e=>!o.some(t=>n.minimatch(e,t,{dot:!0})));t.watch(a,{persistent:!0}).on("change",e=>{console.log(`\nFile changed: ${e}`),r()})}}),m.command("sync").description("Synchronize secondary language files with the primary language file.").action(async()=>{const e=m.opts().config,t=await a.ensureConfig(e);await l.runSyncer(t)}),m.command("migrate-config [configPath]").description("Migrate a legacy i18next-parser.config.js to the new format.").action(async e=>{await u.runMigrator(e)}),m.command("init").description("Create a new i18next.config.ts/js file with an interactive setup wizard.").action(g.runInit),m.command("lint").description("Find potential issues like hardcoded strings in your codebase.").option("-w, --watch","Watch for file changes and re-run the linter.").action(async e=>{const o=m.opts().config,c=async()=>{let e=await a.loadConfig(o);if(!e){console.log(i.blue("No config file found. Attempting to detect project structure..."));const t=await r.detectConfig();t||(console.error(i.red("Could not automatically detect your project structure.")),console.log(`Please create a config file first by running: ${i.cyan("npx i18next-cli init")}`),process.exit(1)),console.log(i.green("Project structure detected successfully!")),e=t}await d.runLinterCli(e)};if(await c(),e.watch){console.log("\nWatching for changes...");const e=await a.loadConfig(o);if(e?.extract?.input){const o=await w(e.extract.input),i=[...y(e.extract.ignore),...h(e.extract.output)].filter(Boolean),a=o.filter(e=>!i.some(t=>n.minimatch(e,t,{dot:!0})));t.watch(a,{ignored:/node_modules/,persistent:!0}).on("change",e=>{console.log(`\nFile changed: ${e}`),c()})}}}),m.command("locize-sync").description("Synchronize local translations with your locize project.").option("--update-values","Update values of existing translations on locize.").option("--src-lng-only","Check for changes in source language only.").option("--compare-mtime","Compare modification times when syncing.").option("--dry-run","Run the command without making any changes.").action(async e=>{const t=m.opts().config,o=await a.ensureConfig(t);await f.runLocizeSync(o,e)}),m.command("locize-download").description("Download all translations from your locize project.").action(async e=>{const t=m.opts().config,o=await a.ensureConfig(t);await f.runLocizeDownload(o,e)}),m.command("locize-migrate").description("Migrate local translation files to a new locize project.").action(async e=>{const t=m.opts().config,o=await a.ensureConfig(t);await f.runLocizeMigrate(o,e)}),m.parse(process.argv);const y=e=>Array.isArray(e)?e:e?[e]:[],h=e=>e&&"string"==typeof e?[e.replace(/\{\{[^}]+\}\}/g,"*")]:[],w=async(e=[])=>{const t=y(e),n=await Promise.all(t.map(e=>o.glob(e||"",{nodir:!0})));return Array.from(new Set(n.flat()))};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var e=require("../parsers/scope-manager.js"),s=require("../parsers/expression-resolver.js"),r=require("../parsers/call-expression-handler.js"),o=require("../parsers/jsx-handler.js");exports.ASTVisitors=class{pluginContext;config;logger;hooks;get objectKeys(){return this.callExpressionHandler.objectKeys}scopeManager;expressionResolver;callExpressionHandler;jsxHandler;constructor(a,t,i,n){this.pluginContext=t,this.config=a,this.logger=i,this.hooks={onBeforeVisitNode:n?.onBeforeVisitNode,onAfterVisitNode:n?.onAfterVisitNode,resolvePossibleKeyStringValues:n?.resolvePossibleKeyStringValues,resolvePossibleContextStringValues:n?.resolvePossibleContextStringValues},this.scopeManager=new e.ScopeManager(a),this.expressionResolver=new s.ExpressionResolver(this.hooks),this.callExpressionHandler=new r.CallExpressionHandler(a,t,i,this.expressionResolver),this.jsxHandler=new o.JSXHandler(a,t,this.expressionResolver)}visit(e){this.scopeManager.reset(),this.scopeManager.enterScope(),this.walk(e),this.scopeManager.exitScope()}walk(e){if(!e)return;let s=!1;switch("Function"!==e.type&&"ArrowFunctionExpression"!==e.type&&"FunctionExpression"!==e.type||(this.scopeManager.enterScope(),s=!0),this.hooks.onBeforeVisitNode?.(e),e.type){case"VariableDeclarator":this.scopeManager.handleVariableDeclarator(e);break;case"CallExpression":this.callExpressionHandler.handleCallExpression(e,this.scopeManager.getVarFromScope.bind(this.scopeManager));break;case"JSXElement":this.jsxHandler.handleJSXElement(e,this.scopeManager.getVarFromScope.bind(this.scopeManager))}this.hooks.onAfterVisitNode?.(e);for(const s in e){if("span"===s)continue;const r=e[s];if(Array.isArray(r)){for(const e of r)if(e&&"object"==typeof e)if("VariableDeclarator"!==e.type){if("VariableDeclaration"===e.type&&Array.isArray(e.declarations))for(const s of e.declarations)s&&"object"==typeof s&&"VariableDeclarator"===s.type&&this.scopeManager.handleVariableDeclarator(s)}else this.scopeManager.handleVariableDeclarator(e);for(const e of r)e&&"object"==typeof e&&this.walk(e)}else r&&"object"==typeof r&&this.walk(r)}s&&this.scopeManager.exitScope()}getVarFromScope(e){return this.scopeManager.getVarFromScope(e)}};
|
|
1
|
+
"use strict";var e=require("../parsers/scope-manager.js"),s=require("../parsers/expression-resolver.js"),r=require("../parsers/call-expression-handler.js"),o=require("../parsers/jsx-handler.js");exports.ASTVisitors=class{pluginContext;config;logger;hooks;get objectKeys(){return this.callExpressionHandler.objectKeys}scopeManager;expressionResolver;callExpressionHandler;jsxHandler;constructor(a,t,i,n){this.pluginContext=t,this.config=a,this.logger=i,this.hooks={onBeforeVisitNode:n?.onBeforeVisitNode,onAfterVisitNode:n?.onAfterVisitNode,resolvePossibleKeyStringValues:n?.resolvePossibleKeyStringValues,resolvePossibleContextStringValues:n?.resolvePossibleContextStringValues},this.scopeManager=new e.ScopeManager(a),this.expressionResolver=new s.ExpressionResolver(this.hooks),this.callExpressionHandler=new r.CallExpressionHandler(a,t,i,this.expressionResolver),this.jsxHandler=new o.JSXHandler(a,t,this.expressionResolver)}visit(e){this.scopeManager.reset(),this.scopeManager.enterScope(),this.walk(e),this.scopeManager.exitScope()}walk(e){if(!e)return;let s=!1;switch("Function"!==e.type&&"ArrowFunctionExpression"!==e.type&&"FunctionExpression"!==e.type||(this.scopeManager.enterScope(),s=!0),this.hooks.onBeforeVisitNode?.(e),e.type){case"VariableDeclarator":this.scopeManager.handleVariableDeclarator(e),this.expressionResolver.captureVariableDeclarator(e);break;case"CallExpression":this.callExpressionHandler.handleCallExpression(e,this.scopeManager.getVarFromScope.bind(this.scopeManager));break;case"JSXElement":this.jsxHandler.handleJSXElement(e,this.scopeManager.getVarFromScope.bind(this.scopeManager))}this.hooks.onAfterVisitNode?.(e);for(const s in e){if("span"===s)continue;const r=e[s];if(Array.isArray(r)){for(const e of r)if(e&&"object"==typeof e)if("VariableDeclarator"!==e.type){if("VariableDeclaration"===e.type&&Array.isArray(e.declarations))for(const s of e.declarations)s&&"object"==typeof s&&"VariableDeclarator"===s.type&&(this.scopeManager.handleVariableDeclarator(s),this.expressionResolver.captureVariableDeclarator(s))}else this.scopeManager.handleVariableDeclarator(e),this.expressionResolver.captureVariableDeclarator(e);for(const e of r)e&&"object"==typeof e&&this.walk(e)}else r&&"object"==typeof r&&this.walk(r)}s&&this.scopeManager.exitScope()}getVarFromScope(e){return this.scopeManager.getVarFromScope(e)}};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var e=require("node:path"),t=require("glob"),s=require("../../utils/nested-object.js"),n=require("../../utils/file-utils.js"),r=require("../../utils/default-value.js");function
|
|
1
|
+
"use strict";var e=require("node:path"),t=require("glob"),s=require("../../utils/nested-object.js"),n=require("../../utils/file-utils.js"),r=require("../../utils/default-value.js");function a(e){const t=`^${e.replace(/[.+?^${}()|[\]\\]/g,"\\$&").replace(/\*/g,".*")}$`;return new RegExp(t)}function o(e,t){if("object"!=typeof e||null===e||Array.isArray(e))return e;const s={},n=t?.extract?.pluralSeparator??"_",r=["zero","one","two","few","many","other"],a=r.map(e=>`ordinal${n}${e}`),l=Object.keys(e).sort((e,t)=>{const s=e=>{for(const t of a)if(e.endsWith(`${n}${t}`)){return{base:e.slice(0,-(n.length+t.length)),form:t,isOrdinal:!0,isPlural:!0,fullKey:e}}for(const t of r)if(e.endsWith(`${n}${t}`)){return{base:e.slice(0,-(n.length+t.length)),form:t,isOrdinal:!1,isPlural:!0,fullKey:e}}return{base:e,form:"",isOrdinal:!1,isPlural:!1,fullKey:e}},o=s(e),l=s(t);if(o.isPlural&&l.isPlural){const e=o.base.localeCompare(l.base,void 0,{sensitivity:"base"});if(0!==e)return e;if(o.isOrdinal!==l.isOrdinal)return o.isOrdinal?1:-1;const t=o.isOrdinal?a:r,s=t.indexOf(o.form),n=t.indexOf(l.form);return-1!==s&&-1!==n?s-n:o.form.localeCompare(l.form)}const i=e.localeCompare(t,void 0,{sensitivity:"base"});return 0===i?e.localeCompare(t,void 0,{sensitivity:"case"}):i});for(const n of l)s[n]=o(e[n],t);return s}function l(e,t,n,a,l,i=[],c=new Set,u=!1){const{keySeparator:f=".",sort:d=!0,removeUnusedKeys:p=!0,primaryLanguage:g,defaultValue:y="",pluralSeparator:h="_",contextSeparator:x="_"}=n.extract,m=new Set;let O=[],v=[];try{const e=new Intl.PluralRules(a,{type:"cardinal"}),t=new Intl.PluralRules(a,{type:"ordinal"});O=e.resolvedOptions().pluralCategories,v=t.resolvedOptions().pluralCategories,O.forEach(e=>m.add(e)),t.resolvedOptions().pluralCategories.forEach(e=>m.add(`ordinal_${e}`))}catch(e){const t=g||"en",s=new Intl.PluralRules(t,{type:"cardinal"}),n=new Intl.PluralRules(t,{type:"ordinal"});O=s.resolvedOptions().pluralCategories,v=n.resolvedOptions().pluralCategories,O.forEach(e=>m.add(e)),n.resolvedOptions().pluralCategories.forEach(e=>m.add(`ordinal_${e}`))}const S=e.filter(({key:e,hasCount:t,isOrdinal:s})=>{if(i.some(t=>t.test(e)))return!1;if(!t)return!0;const n=e.split(h);if(t&&1===n.length)return!0;if(1===O.length&&"other"===O[0]&&1===n.length)return!0;if(s&&n.includes("ordinal")){const e=n[n.length-1];return m.has(`ordinal_${e}`)}if(t){const e=n[n.length-1];return m.has(e)}return!0}),N=new Set;for(const e of S)if(e.isExpandedPlural){const t=String(e.key).split(h);t.length>=3&&"ordinal"===t[t.length-2]?N.add(t.slice(0,-2).join(h)):N.add(t.slice(0,-1).join(h))}let $=p?{}:JSON.parse(JSON.stringify(t));const w=s.getNestedKeys(t,f??".");for(const e of w)if(i.some(t=>t.test(e))){const n=s.getNestedValue(t,e,f??".");s.setNestedValue($,e,n,f??".")}if(p){const e=s.getNestedKeys(t,f??".");for(const n of e){const e=n.split(h);if("zero"===e[e.length-1]){const r=e.slice(0,-1).join(h);if(S.some(({key:e})=>e.split(h).slice(0,-1).join(h)===r)){const e=s.getNestedValue(t,n,f??".");s.setNestedValue($,n,e,f??".")}}}}for(const{key:e,defaultValue:o,explicitDefault:i,hasCount:d,isExpandedPlural:p,isOrdinal:m}of S){if(d&&!p){const t=String(e).split(h);let s=e;if(t.length>=3&&"ordinal"===t[t.length-2]?s=t.slice(0,-2).join(h):t.length>=2&&(s=t.slice(0,-1).join(h)),N.has(s))continue}if(d&&!p){if(1===String(e).split(h).length&&a!==g){const i=e;if(N.has(i));else{const e=m?v:O;for(const c of e){const e=m?`${i}${h}ordinal${h}${c}`:`${i}${h}${c}`,u=s.getNestedValue(t,e,f??".");if(void 0===u){let t;t="string"==typeof o?o:r.resolveDefaultValue(y,String(i),l||n?.extract?.defaultNS||"translation",a,o),s.setNestedValue($,e,t,f??".")}else s.setNestedValue($,e,u,f??".")}}continue}}const w=s.getNestedValue(t,e,f??"."),b=!S.some(t=>t.key.startsWith(`${e}${f}`)&&t.key!==e),j="object"==typeof w&&null!==w&&(c.has(e)||!o||o===e),P="object"==typeof w&&null!==w&&b&&!c.has(e)&&!j;if(j){s.setNestedValue($,e,w,f??".");continue}let V;if(void 0===w||P)if(a===g)if(u){const t=o&&(o===e||e!==o&&(e.startsWith(o+h)||e.startsWith(o+x)));V=o&&!t?o:r.resolveDefaultValue(y,e,l||n?.extract?.defaultNS||"translation",a,o)}else V=o||e;else V=r.resolveDefaultValue(y,e,l||n?.extract?.defaultNS||"translation",a,o);else if(a===g&&u){const t=o&&(o===e||e!==o&&(e.startsWith(o+h)||e.startsWith(o+x)));V=(e.includes(h)||e.includes(x))&&!i?w:o&&!t?o:w}else V=w;s.setNestedValue($,e,V,f??".")}if(!0===d)return o($,n);if("function"==typeof d){const e={},t=Object.keys($),s=new Map;for(const e of S){const t=!1===f?e.key:e.key.split(f)[0];s.has(t)||s.set(t,e)}t.sort((e,t)=>{if("function"==typeof d){const n=s.get(e),r=s.get(t);if(n&&r)return d(n,r)}return e.localeCompare(t,void 0,{sensitivity:"base"})});for(const s of t)e[s]=o($[s],n);$=e}return $}exports.getTranslations=async function(s,r,o,{syncPrimaryWithDefaults:i=!1}={}){o.extract.primaryLanguage||=o.locales[0]||"en",o.extract.secondaryLanguages||=o.locales.filter(e=>e!==o?.extract?.primaryLanguage);const c=[...o.extract.preservePatterns||[]],u=o.extract.indentation??2;for(const e of r)c.push(`${e}.*`);const f=c.map(a),d="__no_namespace__",p=new Map;for(const e of s.values()){const t=e.nsIsImplicit&&!1===o.extract.defaultNS?d:String(e.ns??o.extract.defaultNS??"translation");p.has(t)||p.set(t,[]),p.get(t).push(e)}const g=[],y=Array.isArray(o.extract.ignore)?o.extract.ignore:o.extract.ignore?[o.extract.ignore]:[];for(const s of o.locales){if(o.extract.mergeNamespaces||"string"==typeof o.extract.output&&!o.extract.output.includes("{{namespace}}")){const t={},a=n.getOutputPath(o.extract.output,s),c=e.resolve(process.cwd(),a),y=await n.loadTranslationFile(c)||{},h=new Set([...p.keys(),...Object.keys(y)]);for(const e of h){const n=p.get(e)||[];if(e===d){const e=l(n,y,o,s,void 0,f,r,i);Object.assign(t,e)}else{const a=y[e]||{};t[e]=l(n,a,o,s,e,f,r,i)}}const x=JSON.stringify(y,null,u),m=JSON.stringify(t,null,u);g.push({path:c,updated:m!==x,newTranslations:t,existingTranslations:y})}else{const a=new Set(p.keys()),c=n.getOutputPath(o.extract.output,s,"*").replace(/\\/g,"/"),d=await t.glob(c,{ignore:y});for(const t of d)a.add(e.basename(t,e.extname(t)));for(const t of a){const a=p.get(t)||[],c=n.getOutputPath(o.extract.output,s,t),d=e.resolve(process.cwd(),c),y=await n.loadTranslationFile(d)||{},h=l(a,y,o,s,t,f,r,i),x=JSON.stringify(y,null,u),m=JSON.stringify(h,null,u);g.push({path:d,updated:m!==x,newTranslations:h,existingTranslations:y})}}}return g};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";exports.ExpressionResolver=class{hooks;constructor(e){this.hooks=e}resolvePossibleContextStringValues(e){return[...this.hooks.resolvePossibleContextStringValues?.(e)??[],...this.resolvePossibleStringValuesFromExpression(e)]}resolvePossibleKeyStringValues(e){return[...this.hooks.resolvePossibleKeyStringValues?.(e)??[],...this.resolvePossibleStringValuesFromExpression(e)]}resolvePossibleStringValuesFromExpression(e,s=!1){if("StringLiteral"===e.type)return e.value||s?[e.value]:[];if("ConditionalExpression"===e.type){return[...this.resolvePossibleStringValuesFromExpression(e.consequent,s),...this.resolvePossibleStringValuesFromExpression(e.alternate,s)]}if("Identifier"===e.type&&"undefined"===e.value)return[];if("TemplateLiteral"===e.type)return this.resolvePossibleStringValuesFromTemplateString(e);if("NumericLiteral"===e.type||"BooleanLiteral"===e.type)return[`${e.value}`];if("TsSatisfiesExpression"===e.type||"TsAsExpression"===e.type){const
|
|
1
|
+
"use strict";exports.ExpressionResolver=class{hooks;symbolTable=new Map;constructor(e){this.hooks=e}captureVariableDeclarator(e){try{if(!e||!e.id||!e.init)return;if("Identifier"!==e.id.type)return;const s=e.id.value,t=e.init;if("ObjectExpression"===t.type&&Array.isArray(t.properties)){const e={};for(const s of t.properties){if(!s||"KeyValueProperty"!==s.type)continue;const t=s.key,r="Identifier"===t?.type||"StringLiteral"===t?.type?t.value:void 0;if(!r)continue;const i=s.value,o=this.resolvePossibleStringValuesFromExpression(i);1===o.length&&(e[r]=o[0])}if(Object.keys(e).length>0)return void this.symbolTable.set(s,e)}const r=this.resolvePossibleStringValuesFromExpression(t);r.length>0&&this.symbolTable.set(s,r)}catch{}}resolvePossibleContextStringValues(e){return[...this.hooks.resolvePossibleContextStringValues?.(e)??[],...this.resolvePossibleStringValuesFromExpression(e)]}resolvePossibleKeyStringValues(e){return[...this.hooks.resolvePossibleKeyStringValues?.(e)??[],...this.resolvePossibleStringValuesFromExpression(e)]}resolvePossibleStringValuesFromExpression(e,s=!1){if("StringLiteral"===e.type)return e.value||s?[e.value]:[];if("ConditionalExpression"===e.type){return[...this.resolvePossibleStringValuesFromExpression(e.consequent,s),...this.resolvePossibleStringValuesFromExpression(e.alternate,s)]}if("Identifier"===e.type&&"undefined"===e.value)return[];if("TemplateLiteral"===e.type)return this.resolvePossibleStringValuesFromTemplateString(e);if("MemberExpression"===e.type)try{const s=e.object,t=e.property;if("Identifier"===s.type){const e=this.symbolTable.get(s.value);if(e&&"string"!=typeof e&&!Array.isArray(e)){let s;if("Identifier"===t.type?s=t.value:"Computed"===t.type&&"StringLiteral"===t.expression?.type&&(s=t.expression.value),s&&void 0!==e[s])return[e[s]]}}}catch{}if(e.left&&e.right)try{const t=this.resolvePossibleStringValuesFromExpression(e.left,s),r=this.resolvePossibleStringValuesFromExpression(e.right,s);if(t.length>0&&r.length>0){const e=[];for(const s of t)for(const t of r)e.push(`${s}${t}`);return e}}catch{}if("NumericLiteral"===e.type||"BooleanLiteral"===e.type)return[`${e.value}`];if("TsSatisfiesExpression"===e.type||"TsAsExpression"===e.type){const t=e.typeAnnotation;return this.resolvePossibleStringValuesFromType(t,s)}if("Identifier"===e.type){const s=this.symbolTable.get(e.value);return s&&Array.isArray(s)?s:[]}return[]}resolvePossibleStringValuesFromType(e,s=!1){if("TsUnionType"===e.type)return e.types.flatMap(e=>this.resolvePossibleStringValuesFromType(e,s));if("TsLiteralType"===e.type){if("StringLiteral"===e.literal.type)return e.literal.value||s?[e.literal.value]:[];if("TemplateLiteral"===e.literal.type)return this.resolvePossibleStringValuesFromTemplateLiteralType(e.literal);if("NumericLiteral"===e.literal.type||"BooleanLiteral"===e.literal.type)return[`${e.literal.value}`]}return[]}resolvePossibleStringValuesFromTemplateString(e){if(1===e.quasis.length&&0===e.expressions.length)return[e.quasis[0].cooked||""];const[s,...t]=e.quasis;return e.expressions.reduce((e,s,r)=>e.flatMap(e=>{const i=t[r]?.cooked??"";return this.resolvePossibleStringValuesFromExpression(s,!0).map(s=>`${e}${s}${i}`)}),[s.cooked??""])}resolvePossibleStringValuesFromTemplateLiteralType(e){if(1===e.quasis.length&&0===e.types.length)return[e.quasis[0].cooked||""];const[s,...t]=e.quasis;return e.types.reduce((e,s,r)=>e.flatMap(e=>{const i=t[r]?.cooked??"";return this.resolvePossibleStringValuesFromType(s,!0).map(s=>`${e}${s}${i}`)}),[s.cooked??""])}};
|
package/dist/esm/cli.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import{Command as t}from"commander";import o from"chokidar";import{glob as e}from"glob";import{minimatch as i}from"minimatch";import n from"chalk";import{ensureConfig as a,loadConfig as r}from"./config.js";import{detectConfig as c}from"./heuristic-config.js";import{runExtractor as s}from"./extractor/core/extractor.js";import"node:path";import"node:fs/promises";import"jiti";import{runTypesGenerator as l}from"./types-generator.js";import{runSyncer as p}from"./syncer.js";import{runMigrator as m}from"./migrator.js";import{runInit as f}from"./init.js";import{runLinterCli as d}from"./linter.js";import{runStatus as g}from"./status.js";import{runLocizeSync as u,runLocizeDownload as y,runLocizeMigrate as h}from"./locize.js";const w=new t;w.name("i18next-cli").description("A unified, high-performance i18next CLI.").version("1.
|
|
2
|
+
import{Command as t}from"commander";import o from"chokidar";import{glob as e}from"glob";import{minimatch as i}from"minimatch";import n from"chalk";import{ensureConfig as a,loadConfig as r}from"./config.js";import{detectConfig as c}from"./heuristic-config.js";import{runExtractor as s}from"./extractor/core/extractor.js";import"node:path";import"node:fs/promises";import"jiti";import{runTypesGenerator as l}from"./types-generator.js";import{runSyncer as p}from"./syncer.js";import{runMigrator as m}from"./migrator.js";import{runInit as f}from"./init.js";import{runLinterCli as d}from"./linter.js";import{runStatus as g}from"./status.js";import{runLocizeSync as u,runLocizeDownload as y,runLocizeMigrate as h}from"./locize.js";const w=new t;w.name("i18next-cli").description("A unified, high-performance i18next CLI.").version("1.19.0"),w.option("-c, --config <path>","Path to i18next-cli config file (overrides detection)"),w.command("extract").description("Extract translation keys from source files and update resource files.").option("-w, --watch","Watch for file changes and re-run the extractor.").option("--ci","Exit with a non-zero status code if any files are updated.").option("--dry-run","Run the extractor without writing any files to disk.").option("--sync-primary","Sync primary language values with default values from code.").action(async t=>{try{const e=w.opts().config,n=await a(e),r=async()=>{const o=await s(n,{isWatchMode:!!t.watch,isDryRun:!!t.dryRun,syncPrimaryWithDefaults:!!t.syncPrimary});return t.ci&&!o?(console.log("✅ No files were updated."),process.exit(0)):t.ci&&o&&(console.error("❌ Some files were updated. This should not happen in CI mode."),process.exit(1)),o};if(await r(),t.watch){console.log("\nWatching for changes...");const t=await z(n.extract.input),e=x(n.extract.ignore),a=j(n.extract.output),c=[...e,...a].filter(Boolean),s=t.filter(t=>!c.some(o=>i(t,o,{dot:!0})));o.watch(s,{ignored:/node_modules/,persistent:!0}).on("change",t=>{console.log(`\nFile changed: ${t}`),r()})}}catch(t){console.error("Error running extractor:",t),process.exit(1)}}),w.command("status [locale]").description("Display translation status. Provide a locale for a detailed key-by-key view.").option("-n, --namespace <ns>","Filter the status report by a specific namespace").action(async(t,o)=>{const e=w.opts().config;let i=await r(e);if(!i){console.log(n.blue("No config file found. Attempting to detect project structure..."));const t=await c();t||(console.error(n.red("Could not automatically detect your project structure.")),console.log(`Please create a config file first by running: ${n.cyan("npx i18next-cli init")}`),process.exit(1)),console.log(n.green("Project structure detected successfully!")),i=t}await g(i,{detail:t,namespace:o.namespace})}),w.command("types").description("Generate TypeScript definitions from translation resource files.").option("-w, --watch","Watch for file changes and re-run the type generator.").action(async t=>{const e=w.opts().config,n=await a(e),r=()=>l(n);if(await r(),t.watch){console.log("\nWatching for changes...");const t=await z(n.types?.input||[]),e=[...x(n.extract?.ignore)].filter(Boolean),a=t.filter(t=>!e.some(o=>i(t,o,{dot:!0})));o.watch(a,{persistent:!0}).on("change",t=>{console.log(`\nFile changed: ${t}`),r()})}}),w.command("sync").description("Synchronize secondary language files with the primary language file.").action(async()=>{const t=w.opts().config,o=await a(t);await p(o)}),w.command("migrate-config [configPath]").description("Migrate a legacy i18next-parser.config.js to the new format.").action(async t=>{await m(t)}),w.command("init").description("Create a new i18next.config.ts/js file with an interactive setup wizard.").action(f),w.command("lint").description("Find potential issues like hardcoded strings in your codebase.").option("-w, --watch","Watch for file changes and re-run the linter.").action(async t=>{const e=w.opts().config,a=async()=>{let t=await r(e);if(!t){console.log(n.blue("No config file found. Attempting to detect project structure..."));const o=await c();o||(console.error(n.red("Could not automatically detect your project structure.")),console.log(`Please create a config file first by running: ${n.cyan("npx i18next-cli init")}`),process.exit(1)),console.log(n.green("Project structure detected successfully!")),t=o}await d(t)};if(await a(),t.watch){console.log("\nWatching for changes...");const t=await r(e);if(t?.extract?.input){const e=await z(t.extract.input),n=[...x(t.extract.ignore),...j(t.extract.output)].filter(Boolean),r=e.filter(t=>!n.some(o=>i(t,o,{dot:!0})));o.watch(r,{ignored:/node_modules/,persistent:!0}).on("change",t=>{console.log(`\nFile changed: ${t}`),a()})}}}),w.command("locize-sync").description("Synchronize local translations with your locize project.").option("--update-values","Update values of existing translations on locize.").option("--src-lng-only","Check for changes in source language only.").option("--compare-mtime","Compare modification times when syncing.").option("--dry-run","Run the command without making any changes.").action(async t=>{const o=w.opts().config,e=await a(o);await u(e,t)}),w.command("locize-download").description("Download all translations from your locize project.").action(async t=>{const o=w.opts().config,e=await a(o);await y(e,t)}),w.command("locize-migrate").description("Migrate local translation files to a new locize project.").action(async t=>{const o=w.opts().config,e=await a(o);await h(e,t)}),w.parse(process.argv);const x=t=>Array.isArray(t)?t:t?[t]:[],j=t=>t&&"string"==typeof t?[t.replace(/\{\{[^}]+\}\}/g,"*")]:[],z=async(t=[])=>{const o=x(t),i=await Promise.all(o.map(t=>e(t||"",{nodir:!0})));return Array.from(new Set(i.flat()))};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{ScopeManager as e}from"../parsers/scope-manager.js";import{ExpressionResolver as s}from"../parsers/expression-resolver.js";import{CallExpressionHandler as
|
|
1
|
+
import{ScopeManager as e}from"../parsers/scope-manager.js";import{ExpressionResolver as s}from"../parsers/expression-resolver.js";import{CallExpressionHandler as r}from"../parsers/call-expression-handler.js";import{JSXHandler as o}from"../parsers/jsx-handler.js";class a{pluginContext;config;logger;hooks;get objectKeys(){return this.callExpressionHandler.objectKeys}scopeManager;expressionResolver;callExpressionHandler;jsxHandler;constructor(a,t,i,n){this.pluginContext=t,this.config=a,this.logger=i,this.hooks={onBeforeVisitNode:n?.onBeforeVisitNode,onAfterVisitNode:n?.onAfterVisitNode,resolvePossibleKeyStringValues:n?.resolvePossibleKeyStringValues,resolvePossibleContextStringValues:n?.resolvePossibleContextStringValues},this.scopeManager=new e(a),this.expressionResolver=new s(this.hooks),this.callExpressionHandler=new r(a,t,i,this.expressionResolver),this.jsxHandler=new o(a,t,this.expressionResolver)}visit(e){this.scopeManager.reset(),this.scopeManager.enterScope(),this.walk(e),this.scopeManager.exitScope()}walk(e){if(!e)return;let s=!1;switch("Function"!==e.type&&"ArrowFunctionExpression"!==e.type&&"FunctionExpression"!==e.type||(this.scopeManager.enterScope(),s=!0),this.hooks.onBeforeVisitNode?.(e),e.type){case"VariableDeclarator":this.scopeManager.handleVariableDeclarator(e),this.expressionResolver.captureVariableDeclarator(e);break;case"CallExpression":this.callExpressionHandler.handleCallExpression(e,this.scopeManager.getVarFromScope.bind(this.scopeManager));break;case"JSXElement":this.jsxHandler.handleJSXElement(e,this.scopeManager.getVarFromScope.bind(this.scopeManager))}this.hooks.onAfterVisitNode?.(e);for(const s in e){if("span"===s)continue;const r=e[s];if(Array.isArray(r)){for(const e of r)if(e&&"object"==typeof e)if("VariableDeclarator"!==e.type){if("VariableDeclaration"===e.type&&Array.isArray(e.declarations))for(const s of e.declarations)s&&"object"==typeof s&&"VariableDeclarator"===s.type&&(this.scopeManager.handleVariableDeclarator(s),this.expressionResolver.captureVariableDeclarator(s))}else this.scopeManager.handleVariableDeclarator(e),this.expressionResolver.captureVariableDeclarator(e);for(const e of r)e&&"object"==typeof e&&this.walk(e)}else r&&"object"==typeof r&&this.walk(r)}s&&this.scopeManager.exitScope()}getVarFromScope(e){return this.scopeManager.getVarFromScope(e)}}export{a as ASTVisitors};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{resolve as t,basename as e,extname as n}from"node:path";import{glob as s}from"glob";import{getNestedKeys as r,getNestedValue as o,setNestedValue as i}from"../../utils/nested-object.js";import{getOutputPath as a,loadTranslationFile as l}from"../../utils/file-utils.js";import{resolveDefaultValue as c}from"../../utils/default-value.js";function f(t){const e=`^${t.replace(/[.+?^${}()|[\]\\]/g,"\\$&").replace(/\*/g,".*")}$`;return new RegExp(e)}function u(t,e){if("object"!=typeof t||null===t||Array.isArray(t))return t;const n={},s=e?.extract?.pluralSeparator??"_",r=["zero","one","two","few","many","other"],o=r.map(t=>`ordinal${s}${t}`),i=Object.keys(t).sort((t,e)=>{const n=t=>{for(const e of o)if(t.endsWith(`${s}${e}`)){return{base:t.slice(0,-(s.length+e.length)),form:e,isOrdinal:!0,isPlural:!0,fullKey:t}}for(const e of r)if(t.endsWith(`${s}${e}`)){return{base:t.slice(0,-(s.length+e.length)),form:e,isOrdinal:!1,isPlural:!0,fullKey:t}}return{base:t,form:"",isOrdinal:!1,isPlural:!1,fullKey:t}},i=n(t),a=n(e);if(i.isPlural&&a.isPlural){const t=i.base.localeCompare(a.base,void 0,{sensitivity:"base"});if(0!==t)return t;if(i.isOrdinal!==a.isOrdinal)return i.isOrdinal?1:-1;const e=i.isOrdinal?o:r,n=e.indexOf(i.form),s=e.indexOf(a.form);return-1!==n&&-1!==s?n-s:i.form.localeCompare(a.form)}const l=t.localeCompare(e,void 0,{sensitivity:"base"});return 0===l?t.localeCompare(e,void 0,{sensitivity:"case"}):l});for(const s of i)n[s]=u(t[s],e);return n}function p(t,e,n,s,a,l=[],f=new Set,p=!1){const{keySeparator:d=".",sort:g=!0,removeUnusedKeys:y=!0,primaryLanguage:h,defaultValue:m="",pluralSeparator:x="_",contextSeparator:O="_"}=n.extract,S=new Set;let $=[],v=[];try{const t=new Intl.PluralRules(s,{type:"cardinal"}),e=new Intl.PluralRules(s,{type:"ordinal"});$=t.resolvedOptions().pluralCategories,v=e.resolvedOptions().pluralCategories,$.forEach(t=>S.add(t)),e.resolvedOptions().pluralCategories.forEach(t=>S.add(`ordinal_${t}`))}catch(t){const e=h||"en",n=new Intl.PluralRules(e,{type:"cardinal"}),s=new Intl.PluralRules(e,{type:"ordinal"});$=n.resolvedOptions().pluralCategories,v=s.resolvedOptions().pluralCategories,$.forEach(t=>S.add(t)),s.resolvedOptions().pluralCategories.forEach(t=>S.add(`ordinal_${t}`))}const w=t.filter(({key:t,hasCount:e,isOrdinal:n})=>{if(l.some(e=>e.test(t)))return!1;if(!e)return!0;const s=t.split(x);if(e&&1===s.length)return!0;if(1===$.length&&"other"===$[0]&&1===s.length)return!0;if(n&&s.includes("ordinal")){const t=s[s.length-1];return S.has(`ordinal_${t}`)}if(e){const t=s[s.length-1];return S.has(t)}return!0}),b=new Set;for(const t of w)if(t.isExpandedPlural){const e=String(t.key).split(x);e.length>=3&&"ordinal"===e[e.length-2]?b.add(e.slice(0,-2).join(x)):b.add(e.slice(0,-1).join(x))}let j=y?{}:JSON.parse(JSON.stringify(e));const k=r(e,d??".");for(const t of k)if(l.some(e=>e.test(t))){const n=o(e,t,d??".");i(j,t,n,d??".")}if(y){const t=r(e,d??".");for(const n of t){const t=n.split(x);if("zero"===t[t.length-1]){const s=t.slice(0,-1).join(x);if(w.some(({key:t})=>t.split(x).slice(0,-1).join(x)===s)){const t=o(e,n,d??".");i(j,n,t,d??".")}}}}for(const{key:t,defaultValue:r,explicitDefault:l,hasCount:u,isExpandedPlural:g,isOrdinal:y}of w){if(u&&!g){const e=String(t).split(x);let n=t;if(e.length>=3&&"ordinal"===e[e.length-2]?n=e.slice(0,-2).join(x):e.length>=2&&(n=e.slice(0,-1).join(x)),b.has(n))continue}if(u&&!g){if(1===String(t).split(x).length&&s!==h){const
|
|
1
|
+
import{resolve as t,basename as e,extname as n}from"node:path";import{glob as s}from"glob";import{getNestedKeys as r,getNestedValue as o,setNestedValue as i}from"../../utils/nested-object.js";import{getOutputPath as a,loadTranslationFile as l}from"../../utils/file-utils.js";import{resolveDefaultValue as c}from"../../utils/default-value.js";function f(t){const e=`^${t.replace(/[.+?^${}()|[\]\\]/g,"\\$&").replace(/\*/g,".*")}$`;return new RegExp(e)}function u(t,e){if("object"!=typeof t||null===t||Array.isArray(t))return t;const n={},s=e?.extract?.pluralSeparator??"_",r=["zero","one","two","few","many","other"],o=r.map(t=>`ordinal${s}${t}`),i=Object.keys(t).sort((t,e)=>{const n=t=>{for(const e of o)if(t.endsWith(`${s}${e}`)){return{base:t.slice(0,-(s.length+e.length)),form:e,isOrdinal:!0,isPlural:!0,fullKey:t}}for(const e of r)if(t.endsWith(`${s}${e}`)){return{base:t.slice(0,-(s.length+e.length)),form:e,isOrdinal:!1,isPlural:!0,fullKey:t}}return{base:t,form:"",isOrdinal:!1,isPlural:!1,fullKey:t}},i=n(t),a=n(e);if(i.isPlural&&a.isPlural){const t=i.base.localeCompare(a.base,void 0,{sensitivity:"base"});if(0!==t)return t;if(i.isOrdinal!==a.isOrdinal)return i.isOrdinal?1:-1;const e=i.isOrdinal?o:r,n=e.indexOf(i.form),s=e.indexOf(a.form);return-1!==n&&-1!==s?n-s:i.form.localeCompare(a.form)}const l=t.localeCompare(e,void 0,{sensitivity:"base"});return 0===l?t.localeCompare(e,void 0,{sensitivity:"case"}):l});for(const s of i)n[s]=u(t[s],e);return n}function p(t,e,n,s,a,l=[],f=new Set,p=!1){const{keySeparator:d=".",sort:g=!0,removeUnusedKeys:y=!0,primaryLanguage:h,defaultValue:m="",pluralSeparator:x="_",contextSeparator:O="_"}=n.extract,S=new Set;let $=[],v=[];try{const t=new Intl.PluralRules(s,{type:"cardinal"}),e=new Intl.PluralRules(s,{type:"ordinal"});$=t.resolvedOptions().pluralCategories,v=e.resolvedOptions().pluralCategories,$.forEach(t=>S.add(t)),e.resolvedOptions().pluralCategories.forEach(t=>S.add(`ordinal_${t}`))}catch(t){const e=h||"en",n=new Intl.PluralRules(e,{type:"cardinal"}),s=new Intl.PluralRules(e,{type:"ordinal"});$=n.resolvedOptions().pluralCategories,v=s.resolvedOptions().pluralCategories,$.forEach(t=>S.add(t)),s.resolvedOptions().pluralCategories.forEach(t=>S.add(`ordinal_${t}`))}const w=t.filter(({key:t,hasCount:e,isOrdinal:n})=>{if(l.some(e=>e.test(t)))return!1;if(!e)return!0;const s=t.split(x);if(e&&1===s.length)return!0;if(1===$.length&&"other"===$[0]&&1===s.length)return!0;if(n&&s.includes("ordinal")){const t=s[s.length-1];return S.has(`ordinal_${t}`)}if(e){const t=s[s.length-1];return S.has(t)}return!0}),b=new Set;for(const t of w)if(t.isExpandedPlural){const e=String(t.key).split(x);e.length>=3&&"ordinal"===e[e.length-2]?b.add(e.slice(0,-2).join(x)):b.add(e.slice(0,-1).join(x))}let j=y?{}:JSON.parse(JSON.stringify(e));const k=r(e,d??".");for(const t of k)if(l.some(e=>e.test(t))){const n=o(e,t,d??".");i(j,t,n,d??".")}if(y){const t=r(e,d??".");for(const n of t){const t=n.split(x);if("zero"===t[t.length-1]){const s=t.slice(0,-1).join(x);if(w.some(({key:t})=>t.split(x).slice(0,-1).join(x)===s)){const t=o(e,n,d??".");i(j,n,t,d??".")}}}}for(const{key:t,defaultValue:r,explicitDefault:l,hasCount:u,isExpandedPlural:g,isOrdinal:y}of w){if(u&&!g){const e=String(t).split(x);let n=t;if(e.length>=3&&"ordinal"===e[e.length-2]?n=e.slice(0,-2).join(x):e.length>=2&&(n=e.slice(0,-1).join(x)),b.has(n))continue}if(u&&!g){if(1===String(t).split(x).length&&s!==h){const l=t;if(b.has(l));else{const t=y?v:$;for(const f of t){const t=y?`${l}${x}ordinal${x}${f}`:`${l}${x}${f}`,u=o(e,t,d??".");if(void 0===u){let e;e="string"==typeof r?r:c(m,String(l),a||n?.extract?.defaultNS||"translation",s,r),i(j,t,e,d??".")}else i(j,t,u,d??".")}}continue}}const S=o(e,t,d??"."),k=!w.some(e=>e.key.startsWith(`${t}${d}`)&&e.key!==t),C="object"==typeof S&&null!==S&&(f.has(t)||!r||r===t),P="object"==typeof S&&null!==S&&k&&!f.has(t)&&!C;if(C){i(j,t,S,d??".");continue}let N;if(void 0===S||P)if(s===h)if(p){const e=r&&(r===t||t!==r&&(t.startsWith(r+x)||t.startsWith(r+O)));N=r&&!e?r:c(m,t,a||n?.extract?.defaultNS||"translation",s,r)}else N=r||t;else N=c(m,t,a||n?.extract?.defaultNS||"translation",s,r);else if(s===h&&p){const e=r&&(r===t||t!==r&&(t.startsWith(r+x)||t.startsWith(r+O)));N=(t.includes(x)||t.includes(O))&&!l?S:r&&!e?r:S}else N=S;i(j,t,N,d??".")}if(!0===g)return u(j,n);if("function"==typeof g){const t={},e=Object.keys(j),s=new Map;for(const t of w){const e=!1===d?t.key:t.key.split(d)[0];s.has(e)||s.set(e,t)}e.sort((t,e)=>{if("function"==typeof g){const n=s.get(t),r=s.get(e);if(n&&r)return g(n,r)}return t.localeCompare(e,void 0,{sensitivity:"base"})});for(const s of e)t[s]=u(j[s],n);j=t}return j}async function d(r,o,i,{syncPrimaryWithDefaults:c=!1}={}){i.extract.primaryLanguage||=i.locales[0]||"en",i.extract.secondaryLanguages||=i.locales.filter(t=>t!==i?.extract?.primaryLanguage);const u=[...i.extract.preservePatterns||[]],d=i.extract.indentation??2;for(const t of o)u.push(`${t}.*`);const g=u.map(f),y="__no_namespace__",h=new Map;for(const t of r.values()){const e=t.nsIsImplicit&&!1===i.extract.defaultNS?y:String(t.ns??i.extract.defaultNS??"translation");h.has(e)||h.set(e,[]),h.get(e).push(t)}const m=[],x=Array.isArray(i.extract.ignore)?i.extract.ignore:i.extract.ignore?[i.extract.ignore]:[];for(const r of i.locales){if(i.extract.mergeNamespaces||"string"==typeof i.extract.output&&!i.extract.output.includes("{{namespace}}")){const e={},n=a(i.extract.output,r),s=t(process.cwd(),n),f=await l(s)||{},u=new Set([...h.keys(),...Object.keys(f)]);for(const t of u){const n=h.get(t)||[];if(t===y){const t=p(n,f,i,r,void 0,g,o,c);Object.assign(e,t)}else{const s=f[t]||{};e[t]=p(n,s,i,r,t,g,o,c)}}const x=JSON.stringify(f,null,d),O=JSON.stringify(e,null,d);m.push({path:s,updated:O!==x,newTranslations:e,existingTranslations:f})}else{const f=new Set(h.keys()),u=a(i.extract.output,r,"*").replace(/\\/g,"/"),y=await s(u,{ignore:x});for(const t of y)f.add(e(t,n(t)));for(const e of f){const n=h.get(e)||[],s=a(i.extract.output,r,e),f=t(process.cwd(),s),u=await l(f)||{},y=p(n,u,i,r,e,g,o,c),x=JSON.stringify(u,null,d),O=JSON.stringify(y,null,d);m.push({path:f,updated:O!==x,newTranslations:y,existingTranslations:u})}}}return m}export{d as getTranslations};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
class e{hooks;constructor(e){this.hooks=e}resolvePossibleContextStringValues(e){return[...this.hooks.resolvePossibleContextStringValues?.(e)??[],...this.resolvePossibleStringValuesFromExpression(e)]}resolvePossibleKeyStringValues(e){return[...this.hooks.resolvePossibleKeyStringValues?.(e)??[],...this.resolvePossibleStringValuesFromExpression(e)]}resolvePossibleStringValuesFromExpression(e,s=!1){if("StringLiteral"===e.type)return e.value||s?[e.value]:[];if("ConditionalExpression"===e.type){return[...this.resolvePossibleStringValuesFromExpression(e.consequent,s),...this.resolvePossibleStringValuesFromExpression(e.alternate,s)]}if("Identifier"===e.type&&"undefined"===e.value)return[];if("TemplateLiteral"===e.type)return this.resolvePossibleStringValuesFromTemplateString(e);if("NumericLiteral"===e.type||"BooleanLiteral"===e.type)return[`${e.value}`];if("TsSatisfiesExpression"===e.type||"TsAsExpression"===e.type){const
|
|
1
|
+
class e{hooks;symbolTable=new Map;constructor(e){this.hooks=e}captureVariableDeclarator(e){try{if(!e||!e.id||!e.init)return;if("Identifier"!==e.id.type)return;const s=e.id.value,t=e.init;if("ObjectExpression"===t.type&&Array.isArray(t.properties)){const e={};for(const s of t.properties){if(!s||"KeyValueProperty"!==s.type)continue;const t=s.key,r="Identifier"===t?.type||"StringLiteral"===t?.type?t.value:void 0;if(!r)continue;const i=s.value,o=this.resolvePossibleStringValuesFromExpression(i);1===o.length&&(e[r]=o[0])}if(Object.keys(e).length>0)return void this.symbolTable.set(s,e)}const r=this.resolvePossibleStringValuesFromExpression(t);r.length>0&&this.symbolTable.set(s,r)}catch{}}resolvePossibleContextStringValues(e){return[...this.hooks.resolvePossibleContextStringValues?.(e)??[],...this.resolvePossibleStringValuesFromExpression(e)]}resolvePossibleKeyStringValues(e){return[...this.hooks.resolvePossibleKeyStringValues?.(e)??[],...this.resolvePossibleStringValuesFromExpression(e)]}resolvePossibleStringValuesFromExpression(e,s=!1){if("StringLiteral"===e.type)return e.value||s?[e.value]:[];if("ConditionalExpression"===e.type){return[...this.resolvePossibleStringValuesFromExpression(e.consequent,s),...this.resolvePossibleStringValuesFromExpression(e.alternate,s)]}if("Identifier"===e.type&&"undefined"===e.value)return[];if("TemplateLiteral"===e.type)return this.resolvePossibleStringValuesFromTemplateString(e);if("MemberExpression"===e.type)try{const s=e.object,t=e.property;if("Identifier"===s.type){const e=this.symbolTable.get(s.value);if(e&&"string"!=typeof e&&!Array.isArray(e)){let s;if("Identifier"===t.type?s=t.value:"Computed"===t.type&&"StringLiteral"===t.expression?.type&&(s=t.expression.value),s&&void 0!==e[s])return[e[s]]}}}catch{}if(e.left&&e.right)try{const t=this.resolvePossibleStringValuesFromExpression(e.left,s),r=this.resolvePossibleStringValuesFromExpression(e.right,s);if(t.length>0&&r.length>0){const e=[];for(const s of t)for(const t of r)e.push(`${s}${t}`);return e}}catch{}if("NumericLiteral"===e.type||"BooleanLiteral"===e.type)return[`${e.value}`];if("TsSatisfiesExpression"===e.type||"TsAsExpression"===e.type){const t=e.typeAnnotation;return this.resolvePossibleStringValuesFromType(t,s)}if("Identifier"===e.type){const s=this.symbolTable.get(e.value);return s&&Array.isArray(s)?s:[]}return[]}resolvePossibleStringValuesFromType(e,s=!1){if("TsUnionType"===e.type)return e.types.flatMap(e=>this.resolvePossibleStringValuesFromType(e,s));if("TsLiteralType"===e.type){if("StringLiteral"===e.literal.type)return e.literal.value||s?[e.literal.value]:[];if("TemplateLiteral"===e.literal.type)return this.resolvePossibleStringValuesFromTemplateLiteralType(e.literal);if("NumericLiteral"===e.literal.type||"BooleanLiteral"===e.literal.type)return[`${e.literal.value}`]}return[]}resolvePossibleStringValuesFromTemplateString(e){if(1===e.quasis.length&&0===e.expressions.length)return[e.quasis[0].cooked||""];const[s,...t]=e.quasis;return e.expressions.reduce((e,s,r)=>e.flatMap(e=>{const i=t[r]?.cooked??"";return this.resolvePossibleStringValuesFromExpression(s,!0).map(s=>`${e}${s}${i}`)}),[s.cooked??""])}resolvePossibleStringValuesFromTemplateLiteralType(e){if(1===e.quasis.length&&0===e.types.length)return[e.quasis[0].cooked||""];const[s,...t]=e.quasis;return e.types.reduce((e,s,r)=>e.flatMap(e=>{const i=t[r]?.cooked??"";return this.resolvePossibleStringValuesFromType(s,!0).map(s=>`${e}${s}${i}`)}),[s.cooked??""])}}export{e as ExpressionResolver};
|
package/package.json
CHANGED
package/src/cli.ts
CHANGED
|
@@ -22,7 +22,7 @@ const program = new Command()
|
|
|
22
22
|
program
|
|
23
23
|
.name('i18next-cli')
|
|
24
24
|
.description('A unified, high-performance i18next CLI.')
|
|
25
|
-
.version('1.
|
|
25
|
+
.version('1.19.0')
|
|
26
26
|
|
|
27
27
|
// new: global config override option
|
|
28
28
|
program.option('-c, --config <path>', 'Path to i18next-cli config file (overrides detection)')
|
|
@@ -115,6 +115,9 @@ export class ASTVisitors {
|
|
|
115
115
|
switch (node.type) {
|
|
116
116
|
case 'VariableDeclarator':
|
|
117
117
|
this.scopeManager.handleVariableDeclarator(node)
|
|
118
|
+
// Capture simple variable initializers so the expressionResolver can
|
|
119
|
+
// resolve identifiers / member expressions that reference them.
|
|
120
|
+
this.expressionResolver.captureVariableDeclarator(node)
|
|
118
121
|
break
|
|
119
122
|
case 'CallExpression':
|
|
120
123
|
this.callExpressionHandler.handleCallExpression(node, this.scopeManager.getVarFromScope.bind(this.scopeManager))
|
|
@@ -146,6 +149,7 @@ export class ASTVisitors {
|
|
|
146
149
|
// Direct declarator present in arrays (rare)
|
|
147
150
|
if (item.type === 'VariableDeclarator') {
|
|
148
151
|
this.scopeManager.handleVariableDeclarator(item)
|
|
152
|
+
this.expressionResolver.captureVariableDeclarator(item)
|
|
149
153
|
continue
|
|
150
154
|
}
|
|
151
155
|
|
|
@@ -154,6 +158,7 @@ export class ASTVisitors {
|
|
|
154
158
|
for (const decl of item.declarations) {
|
|
155
159
|
if (decl && typeof decl === 'object' && decl.type === 'VariableDeclarator') {
|
|
156
160
|
this.scopeManager.handleVariableDeclarator(decl)
|
|
161
|
+
this.expressionResolver.captureVariableDeclarator(decl)
|
|
157
162
|
}
|
|
158
163
|
}
|
|
159
164
|
}
|
|
@@ -286,9 +286,24 @@ function buildNewTranslationsForNs (
|
|
|
286
286
|
? `${base}${pluralSeparator}ordinal${pluralSeparator}${category}`
|
|
287
287
|
: `${base}${pluralSeparator}${category}`
|
|
288
288
|
|
|
289
|
-
//
|
|
290
|
-
const
|
|
291
|
-
|
|
289
|
+
// Preserve existing translation if present; otherwise set a sensible default
|
|
290
|
+
const existingVariantValue = getNestedValue(existingTranslations, finalKey, keySeparator ?? '.')
|
|
291
|
+
if (existingVariantValue === undefined) {
|
|
292
|
+
// Prefer explicit defaultValue extracted for this key; fall back to configured defaultValue
|
|
293
|
+
// (resolved via resolveDefaultValue which handles functions or strings and accepts the full parameter set).
|
|
294
|
+
let resolvedValue: string
|
|
295
|
+
if (typeof defaultValue === 'string') {
|
|
296
|
+
resolvedValue = defaultValue
|
|
297
|
+
} else {
|
|
298
|
+
// Use resolveDefaultValue to compute a sensible default, providing namespace and locale context.
|
|
299
|
+
resolvedValue = resolveDefaultValue(emptyDefaultValue, String(base), namespace || config?.extract?.defaultNS || 'translation', locale, defaultValue)
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
setNestedValue(newTranslations, finalKey, resolvedValue, keySeparator ?? '.')
|
|
303
|
+
} else {
|
|
304
|
+
// Keep existing translation
|
|
305
|
+
setNestedValue(newTranslations, finalKey, existingVariantValue, keySeparator ?? '.')
|
|
306
|
+
}
|
|
292
307
|
}
|
|
293
308
|
}
|
|
294
309
|
// We've expanded variants for this base key; skip the normal single-key handling.
|
|
@@ -3,11 +3,66 @@ import type { ASTVisitorHooks } from '../../types'
|
|
|
3
3
|
|
|
4
4
|
export class ExpressionResolver {
|
|
5
5
|
private hooks: ASTVisitorHooks
|
|
6
|
+
// Simple per-file symbol table for statically analyzable variables.
|
|
7
|
+
// Maps variableName -> either:
|
|
8
|
+
// - string[] (possible string values)
|
|
9
|
+
// - Record<string, string> (object of static string properties)
|
|
10
|
+
private symbolTable: Map<string, string[] | Record<string, string>> = new Map()
|
|
6
11
|
|
|
7
12
|
constructor (hooks: ASTVisitorHooks) {
|
|
8
13
|
this.hooks = hooks
|
|
9
14
|
}
|
|
10
15
|
|
|
16
|
+
/**
|
|
17
|
+
* Capture a VariableDeclarator node to record simple statically analyzable
|
|
18
|
+
* initializers (string literals, object expressions of string literals,
|
|
19
|
+
* template literals and simple concatenations).
|
|
20
|
+
*
|
|
21
|
+
* This is called during AST traversal before deeper walking so later
|
|
22
|
+
* identifier/member-expression usage can be resolved.
|
|
23
|
+
*
|
|
24
|
+
* @param node - VariableDeclarator-like node (has .id and .init)
|
|
25
|
+
*/
|
|
26
|
+
captureVariableDeclarator (node: any): void {
|
|
27
|
+
try {
|
|
28
|
+
if (!node || !node.id || !node.init) return
|
|
29
|
+
// only handle simple identifier bindings like `const x = ...`
|
|
30
|
+
if (node.id.type !== 'Identifier') return
|
|
31
|
+
const name = node.id.value
|
|
32
|
+
const init = node.init
|
|
33
|
+
|
|
34
|
+
// ObjectExpression -> map of string props
|
|
35
|
+
if (init.type === 'ObjectExpression' && Array.isArray(init.properties)) {
|
|
36
|
+
const map: Record<string, string> = {}
|
|
37
|
+
for (const p of init.properties as any[]) {
|
|
38
|
+
if (!p || p.type !== 'KeyValueProperty') continue
|
|
39
|
+
const keyNode = p.key
|
|
40
|
+
const keyName = keyNode?.type === 'Identifier' ? keyNode.value : keyNode?.type === 'StringLiteral' ? keyNode.value : undefined
|
|
41
|
+
if (!keyName) continue
|
|
42
|
+
const valExpr = p.value
|
|
43
|
+
const vals = this.resolvePossibleStringValuesFromExpression(valExpr)
|
|
44
|
+
// Only capture properties that we can statically resolve to a single string.
|
|
45
|
+
if (vals.length === 1) {
|
|
46
|
+
map[keyName] = vals[0]
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
// If at least one property was resolvable, record the partial map.
|
|
50
|
+
if (Object.keys(map).length > 0) {
|
|
51
|
+
this.symbolTable.set(name, map)
|
|
52
|
+
return
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// For other initializers, try to resolve to one-or-more strings
|
|
57
|
+
const vals = this.resolvePossibleStringValuesFromExpression(init)
|
|
58
|
+
if (vals.length > 0) {
|
|
59
|
+
this.symbolTable.set(name, vals)
|
|
60
|
+
}
|
|
61
|
+
} catch {
|
|
62
|
+
// be silent - conservative only
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
11
66
|
/**
|
|
12
67
|
* Resolves an expression to one or more possible context string values that can be
|
|
13
68
|
* determined statically from the AST. This is a wrapper around the plugin hook
|
|
@@ -73,6 +128,42 @@ export class ExpressionResolver {
|
|
|
73
128
|
return this.resolvePossibleStringValuesFromTemplateString(expression)
|
|
74
129
|
}
|
|
75
130
|
|
|
131
|
+
// MemberExpression: try to resolve object identifier to an object map in the symbol table
|
|
132
|
+
if (expression.type === 'MemberExpression') {
|
|
133
|
+
try {
|
|
134
|
+
const obj = expression.object
|
|
135
|
+
const prop = expression.property
|
|
136
|
+
// only handle simple identifier base + simple property (Identifier or computed StringLiteral)
|
|
137
|
+
if (obj.type === 'Identifier') {
|
|
138
|
+
const base = this.symbolTable.get(obj.value)
|
|
139
|
+
if (base && typeof base !== 'string' && !Array.isArray(base)) {
|
|
140
|
+
let propName: string | undefined
|
|
141
|
+
if (prop.type === 'Identifier') propName = prop.value
|
|
142
|
+
else if (prop.type === 'Computed' && prop.expression?.type === 'StringLiteral') propName = prop.expression.value
|
|
143
|
+
if (propName && base[propName] !== undefined) return [base[propName]]
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
} catch {}
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
// Binary concatenation support (e.g., a + '_' + b)
|
|
150
|
+
// SWC binary expr can be represented as `BinExpr` with left/right; be permissive:
|
|
151
|
+
if ((expression as any).left && (expression as any).right) {
|
|
152
|
+
try {
|
|
153
|
+
const leftVals = this.resolvePossibleStringValuesFromExpression((expression as any).left, returnEmptyStrings)
|
|
154
|
+
const rightVals = this.resolvePossibleStringValuesFromExpression((expression as any).right, returnEmptyStrings)
|
|
155
|
+
if (leftVals.length > 0 && rightVals.length > 0) {
|
|
156
|
+
const combos: string[] = []
|
|
157
|
+
for (const L of leftVals) {
|
|
158
|
+
for (const R of rightVals) {
|
|
159
|
+
combos.push(`${L}${R}`)
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
return combos
|
|
163
|
+
}
|
|
164
|
+
} catch {}
|
|
165
|
+
}
|
|
166
|
+
|
|
76
167
|
if (expression.type === 'NumericLiteral' || expression.type === 'BooleanLiteral') {
|
|
77
168
|
return [`${expression.value}`] // Handle literals like 5 or true
|
|
78
169
|
}
|
|
@@ -84,6 +175,15 @@ export class ExpressionResolver {
|
|
|
84
175
|
return this.resolvePossibleStringValuesFromType(annotation, returnEmptyStrings)
|
|
85
176
|
}
|
|
86
177
|
|
|
178
|
+
// Identifier resolution via captured symbol table
|
|
179
|
+
if (expression.type === 'Identifier') {
|
|
180
|
+
const v = this.symbolTable.get(expression.value)
|
|
181
|
+
if (!v) return []
|
|
182
|
+
if (Array.isArray(v)) return v
|
|
183
|
+
// object map - cannot be used directly as key, so return empty
|
|
184
|
+
return []
|
|
185
|
+
}
|
|
186
|
+
|
|
87
187
|
// We can't statically determine the value of other expressions (e.g., variables, function calls)
|
|
88
188
|
return []
|
|
89
189
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ast-visitors.d.ts","sourceRoot":"","sources":["../../../src/extractor/core/ast-visitors.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAQ,MAAM,WAAW,CAAA;AAC7C,OAAO,KAAK,EAAE,aAAa,EAAE,oBAAoB,EAAE,MAAM,EAAE,eAAe,EAAE,SAAS,EAAE,MAAM,aAAa,CAAA;AAM1G;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,qBAAa,WAAW;IACtB,OAAO,CAAC,QAAQ,CAAC,aAAa,CAAe;IAC7C,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAuC;IAC9D,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAQ;IAC/B,OAAO,CAAC,KAAK,CAAiB;IAE9B,IAAW,UAAU,gBAEpB;IAED,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAc;IAC3C,OAAO,CAAC,QAAQ,CAAC,kBAAkB,CAAoB;IACvD,OAAO,CAAC,QAAQ,CAAC,qBAAqB,CAAuB;IAC7D,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAY;IAEvC;;;;;;OAMG;gBAED,MAAM,EAAE,IAAI,CAAC,oBAAoB,EAAE,SAAS,CAAC,EAC7C,aAAa,EAAE,aAAa,EAC5B,MAAM,EAAE,MAAM,EACd,KAAK,CAAC,EAAE,eAAe;IAkBzB;;;;;OAKG;IACI,KAAK,CAAE,IAAI,EAAE,MAAM,GAAG,IAAI;IAQjC;;;;;;;;;;;;OAYG;IACH,OAAO,CAAC,IAAI;
|
|
1
|
+
{"version":3,"file":"ast-visitors.d.ts","sourceRoot":"","sources":["../../../src/extractor/core/ast-visitors.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAQ,MAAM,WAAW,CAAA;AAC7C,OAAO,KAAK,EAAE,aAAa,EAAE,oBAAoB,EAAE,MAAM,EAAE,eAAe,EAAE,SAAS,EAAE,MAAM,aAAa,CAAA;AAM1G;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,qBAAa,WAAW;IACtB,OAAO,CAAC,QAAQ,CAAC,aAAa,CAAe;IAC7C,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAuC;IAC9D,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAQ;IAC/B,OAAO,CAAC,KAAK,CAAiB;IAE9B,IAAW,UAAU,gBAEpB;IAED,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAc;IAC3C,OAAO,CAAC,QAAQ,CAAC,kBAAkB,CAAoB;IACvD,OAAO,CAAC,QAAQ,CAAC,qBAAqB,CAAuB;IAC7D,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAY;IAEvC;;;;;;OAMG;gBAED,MAAM,EAAE,IAAI,CAAC,oBAAoB,EAAE,SAAS,CAAC,EAC7C,aAAa,EAAE,aAAa,EAC5B,MAAM,EAAE,MAAM,EACd,KAAK,CAAC,EAAE,eAAe;IAkBzB;;;;;OAKG;IACI,KAAK,CAAE,IAAI,EAAE,MAAM,GAAG,IAAI;IAQjC;;;;;;;;;;;;OAYG;IACH,OAAO,CAAC,IAAI;IAuFZ;;;;;;;;OAQG;IACI,eAAe,CAAE,IAAI,EAAE,MAAM,GAAG,SAAS,GAAG,SAAS;CAG7D"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"translation-manager.d.ts","sourceRoot":"","sources":["../../../src/extractor/core/translation-manager.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,YAAY,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAA;
|
|
1
|
+
{"version":3,"file":"translation-manager.d.ts","sourceRoot":"","sources":["../../../src/extractor/core/translation-manager.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,YAAY,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAA;AAibnF;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,wBAAsB,eAAe,CACnC,IAAI,EAAE,GAAG,CAAC,MAAM,EAAE,YAAY,CAAC,EAC/B,UAAU,EAAE,GAAG,CAAC,MAAM,CAAC,EACvB,MAAM,EAAE,oBAAoB,EAC5B,EAAE,uBAA+B,EAAE,GAAE;IAAE,uBAAuB,CAAC,EAAE,OAAO,CAAA;CAAO,GAC9E,OAAO,CAAC,iBAAiB,EAAE,CAAC,CA6F9B"}
|
|
@@ -2,7 +2,19 @@ import type { Expression } from '@swc/core';
|
|
|
2
2
|
import type { ASTVisitorHooks } from '../../types';
|
|
3
3
|
export declare class ExpressionResolver {
|
|
4
4
|
private hooks;
|
|
5
|
+
private symbolTable;
|
|
5
6
|
constructor(hooks: ASTVisitorHooks);
|
|
7
|
+
/**
|
|
8
|
+
* Capture a VariableDeclarator node to record simple statically analyzable
|
|
9
|
+
* initializers (string literals, object expressions of string literals,
|
|
10
|
+
* template literals and simple concatenations).
|
|
11
|
+
*
|
|
12
|
+
* This is called during AST traversal before deeper walking so later
|
|
13
|
+
* identifier/member-expression usage can be resolved.
|
|
14
|
+
*
|
|
15
|
+
* @param node - VariableDeclarator-like node (has .id and .init)
|
|
16
|
+
*/
|
|
17
|
+
captureVariableDeclarator(node: any): void;
|
|
6
18
|
/**
|
|
7
19
|
* Resolves an expression to one or more possible context string values that can be
|
|
8
20
|
* determined statically from the AST. This is a wrapper around the plugin hook
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"expression-resolver.d.ts","sourceRoot":"","sources":["../../../src/extractor/parsers/expression-resolver.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAkD,MAAM,WAAW,CAAA;AAC3F,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA;AAElD,qBAAa,kBAAkB;IAC7B,OAAO,CAAC,KAAK,CAAiB;
|
|
1
|
+
{"version":3,"file":"expression-resolver.d.ts","sourceRoot":"","sources":["../../../src/extractor/parsers/expression-resolver.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAkD,MAAM,WAAW,CAAA;AAC3F,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA;AAElD,qBAAa,kBAAkB;IAC7B,OAAO,CAAC,KAAK,CAAiB;IAK9B,OAAO,CAAC,WAAW,CAA4D;gBAElE,KAAK,EAAE,eAAe;IAInC;;;;;;;;;OASG;IACH,yBAAyB,CAAE,IAAI,EAAE,GAAG,GAAG,IAAI;IAwC3C;;;;;;;OAOG;IACH,kCAAkC,CAAE,UAAU,EAAE,UAAU,GAAG,MAAM,EAAE;IAKrE;;;;;;;OAOG;IACH,8BAA8B,CAAE,UAAU,EAAE,UAAU,GAAG,MAAM,EAAE;IAKjE;;;;;;;;;;;;;;;;;;OAkBG;IACH,OAAO,CAAC,yCAAyC;IAgFjD,OAAO,CAAC,mCAAmC;IAwB3C;;;;;;OAMG;IACH,OAAO,CAAC,6CAA6C;IAyBrD;;;;;;OAMG;IACH,OAAO,CAAC,kDAAkD;CAwB3D"}
|