i18next-cli 1.33.0 → 1.33.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/cli.js +1 -1
- package/dist/cjs/extractor/core/extractor.js +1 -1
- package/dist/cjs/extractor/core/translation-manager.js +1 -1
- package/dist/cjs/extractor/parsers/jsx-handler.js +1 -1
- package/dist/cjs/extractor/parsers/jsx-parser.js +1 -1
- package/dist/esm/cli.js +1 -1
- package/dist/esm/extractor/core/extractor.js +1 -1
- package/dist/esm/extractor/core/translation-manager.js +1 -1
- package/dist/esm/extractor/parsers/jsx-handler.js +1 -1
- package/dist/esm/extractor/parsers/jsx-parser.js +1 -1
- package/package.json +1 -1
- package/types/extractor/core/extractor.d.ts.map +1 -1
- package/types/extractor/core/translation-manager.d.ts.map +1 -1
- package/types/extractor/parsers/jsx-handler.d.ts.map +1 -1
- package/types/extractor/parsers/jsx-parser.d.ts.map +1 -1
package/dist/cjs/cli.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
"use strict";var e=require("commander"),o=require("chokidar"),t=require("glob"),n=require("minimatch"),i=require("chalk"),r=require("./config.js"),a=require("./heuristic-config.js"),c=require("./extractor/core/extractor.js");require("node:path"),require("node:fs/promises"),require("jiti"),require("@croct/json5-parser");var s=require("./types-generator.js"),l=require("./syncer.js"),d=require("./migrator.js"),u=require("./init.js"),p=require("./linter.js"),g=require("./status.js"),f=require("./locize.js"),y=require("./rename-key.js");const h=new e.Command;h.name("i18next-cli").description("A unified, high-performance i18next CLI.").version("1.33.
|
|
2
|
+
"use strict";var e=require("commander"),o=require("chokidar"),t=require("glob"),n=require("minimatch"),i=require("chalk"),r=require("./config.js"),a=require("./heuristic-config.js"),c=require("./extractor/core/extractor.js");require("node:path"),require("node:fs/promises"),require("jiti"),require("@croct/json5-parser");var s=require("./types-generator.js"),l=require("./syncer.js"),d=require("./migrator.js"),u=require("./init.js"),p=require("./linter.js"),g=require("./status.js"),f=require("./locize.js"),y=require("./rename-key.js");const h=new e.Command;h.name("i18next-cli").description("A unified, high-performance i18next CLI.").version("1.33.2"),h.option("-c, --config <path>","Path to i18next-cli config file (overrides detection)"),h.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.").option("--sync-all","Sync primary language values with default values from code AND clear synced keys in all other locales.").action(async e=>{try{const t=h.opts().config,i=await r.ensureConfig(t),a=async()=>{const o=!!e.syncPrimary||!!e.syncAll,t=await c.runExtractor(i,{isWatchMode:!!e.watch,isDryRun:!!e.dryRun,syncPrimaryWithDefaults:o,syncAll:!!e.syncAll});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 a(),e.watch){console.log("\nWatching for changes...");const e=await x(i.extract.input),t=m(i.extract.ignore),r=w(i.extract.output),c=[...t,...r].filter(Boolean),s=e.filter(e=>!c.some(o=>n.minimatch(e,o,{dot:!0})));o.watch(s,{ignored:/node_modules/,persistent:!0}).on("change",e=>{console.log(`\nFile changed: ${e}`),a()})}}catch(e){console.error("Error running extractor:",e),process.exit(1)}}),h.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,o)=>{const t=h.opts().config;let n=await r.loadConfig(t);if(!n){console.log(i.blue("No config file found. Attempting to detect project structure..."));const e=await a.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 g.runStatus(n,{detail:e,namespace:o.namespace})}),h.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 t=h.opts().config,i=await r.ensureConfig(t),a=()=>s.runTypesGenerator(i);if(await a(),e.watch){console.log("\nWatching for changes...");const e=await x(i.types?.input||[]),t=[...m(i.extract?.ignore)].filter(Boolean),r=e.filter(e=>!t.some(o=>n.minimatch(e,o,{dot:!0})));o.watch(r,{persistent:!0}).on("change",e=>{console.log(`\nFile changed: ${e}`),a()})}}),h.command("sync").description("Synchronize secondary language files with the primary language file.").action(async()=>{const e=h.opts().config,o=await r.ensureConfig(e);await l.runSyncer(o)}),h.command("migrate-config [configPath]").description("Migrate a legacy i18next-parser.config.js to the new format.").action(async e=>{await d.runMigrator(e)}),h.command("init").description("Create a new i18next.config.ts/js file with an interactive setup wizard.").action(u.runInit),h.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 t=h.opts().config,c=async()=>{let e=await r.loadConfig(t);if(!e){console.log(i.blue("No config file found. Attempting to detect project structure..."));const o=await a.detectConfig();o||(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=o}await p.runLinterCli(e)};if(await c(),e.watch){console.log("\nWatching for changes...");const e=await r.loadConfig(t);if(e?.extract?.input){const t=await x(e.extract.input),i=[...m(e.extract.ignore),...w(e.extract.output)].filter(Boolean),r=t.filter(e=>!i.some(o=>n.minimatch(e,o,{dot:!0})));o.watch(r,{ignored:/node_modules/,persistent:!0}).on("change",e=>{console.log(`\nFile changed: ${e}`),c()})}}}),h.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.").option("--cdn-type <standard|pro>","Specify the cdn endpoint that should be used (depends on which cdn type you've in your locize project)").action(async e=>{const o=h.opts().config,t=await r.ensureConfig(o);await f.runLocizeSync(t,e)}),h.command("locize-download").description("Download all translations from your locize project.").option("--cdn-type <standard|pro>","Specify the cdn endpoint that should be used (depends on which cdn type you've in your locize project)").action(async e=>{const o=h.opts().config,t=await r.ensureConfig(o);await f.runLocizeDownload(t,e)}),h.command("locize-migrate").description("Migrate local translation files to a new locize project.").option("--cdn-type <standard|pro>","Specify the cdn endpoint that should be used (depends on which cdn type you've in your locize project)").action(async e=>{const o=h.opts().config,t=await r.ensureConfig(o);await f.runLocizeMigrate(t,e)}),h.command("rename-key <oldKey> <newKey>").description("Rename a translation key across all source files and translation files.").option("--dry-run","Preview changes without modifying files").action(async(e,o,t)=>{try{const n=h.opts().config,a=await r.ensureConfig(n),c=await y.runRenameKey(a,e,o,t);c.success||(c.conflicts&&(console.error(i.red("\n❌ Conflicts detected:")),c.conflicts.forEach(e=>console.error(` - ${e}`))),c.error&&console.error(i.red(`\n❌ ${c.error}`)),process.exit(1));0===c.sourceFiles.reduce((e,o)=>e+o.changes,0)&&console.log(i.yellow(`\n⚠️ No usages found for "${e}"`))}catch(e){console.error(i.red("Error renaming key:"),e),process.exit(1)}}),h.parse(process.argv);const m=e=>Array.isArray(e)?e:e?[e]:[],w=e=>e&&"string"==typeof e?[e.replace(/\{\{[^}]+\}\}/g,"*")]:[],x=async(e=[])=>{const o=m(e),n=await Promise.all(o.map(e=>t.glob(e||"",{nodir:!0})));return Array.from(new Set(n.flat()))};exports.program=h;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var t=require("ora"),e=require("chalk"),
|
|
1
|
+
"use strict";var t=require("ora"),e=require("chalk"),r=require("@swc/core"),a=require("node:fs/promises"),n=require("node:path"),s=require("./key-finder.js"),o=require("./translation-manager.js"),i=require("../../utils/validation.js"),c=require("../parsers/comment-parser.js"),l=require("../../utils/logger.js"),u=require("../../utils/file-utils.js"),m=require("../../utils/funnel-msg-tracker.js");exports.extract=async function(t,{syncPrimaryWithDefaults:e=!1}={}){t.extract.primaryLanguage||=t.locales[0]||"en",t.extract.secondaryLanguages||=t.locales.filter(e=>e!==t?.extract?.primaryLanguage),t.extract.functions||=["t","*.t"],t.extract.transComponents||=["Trans"];const{allKeys:r,objectKeys:a}=await s.findKeys(t);return o.getTranslations(r,a,t,{syncPrimaryWithDefaults:e})},exports.processFile=async function(t,s,o,u,m,g=new l.ConsoleLogger){try{let e=await a.readFile(t,"utf-8");for(const r of s)try{const a=await(r.onLoad?.(e,t));void 0!==a&&(e=a)}catch(t){g.warn(`Plugin ${r.name} onLoad failed:`,t)}const l=n.extname(t).toLowerCase(),y=".ts"===l||".tsx"===l||".mts"===l||".cts"===l,d=".tsx"===l,p=".jsx"===l;let f;try{f=await r.parse(e,{syntax:y?"typescript":"ecmascript",tsx:d,jsx:p,decorators:!0,dynamicImport:!0,comments:!0})}catch(a){if(".ts"!==l||d){if(".js"!==l||p)throw new i.ExtractorError("Failed to process file",t,a);try{f=await r.parse(e,{syntax:"ecmascript",jsx:!0,decorators:!0,dynamicImport:!0,comments:!0}),g.info?.(`Parsed ${t} using JSX fallback`)}catch(e){throw new i.ExtractorError("Failed to process file",t,e)}}else try{f=await r.parse(e,{syntax:"typescript",tsx:!0,decorators:!0,dynamicImport:!0,comments:!0}),g.info?.(`Parsed ${t} using TSX fallback`)}catch(e){throw new i.ExtractorError("Failed to process file",t,e)}}u.getVarFromScope=o.getVarFromScope.bind(o),o.setCurrentFile(t,e),o.visit(f),!1!==m.extract.extractFromComments&&c.extractKeysFromComments(e,u,m,o.getVarFromScope.bind(o))}catch(r){g.warn(`${e.yellow("Skipping file due to error:")} ${t}`);const a=r,n="string"==typeof a?.message&&a.message.trim().length>0?a.message:("string"==typeof a?a:"")||a?.toString?.()||"Unknown error";g.warn(` ${n}`),a?.message&&""!==String(a.message).trim()||!a?.stack||g.warn(` ${String(a.stack)}`)}},exports.runExtractor=async function(r,{isWatchMode:c=!1,isDryRun:g=!1,syncPrimaryWithDefaults:y=!1,syncAll:d=!1}={},p=new l.ConsoleLogger){r.extract.primaryLanguage||=r.locales[0]||"en",r.extract.secondaryLanguages||=r.locales.filter(t=>t!==r?.extract?.primaryLanguage),r.extract.functions||=["t","*.t"],r.extract.transComponents||=["Trans"],i.validateExtractorConfig(r);const f=r.plugins||[],x=t("Running i18next key extractor...\n").start();try{const{allKeys:t,objectKeys:i}=await s.findKeys(r,p);x.text=`Found ${t.size} unique keys. Updating translation files...`;const c=await o.getTranslations(t,i,r,{syncPrimaryWithDefaults:y,syncAll:d});let l=!1;for(const t of c)if(t.updated&&(l=!0,!g)){const s=r.extract.outputFormat??(t.path.endsWith(".json5")?"json5":"json"),o="json5"===s?await u.loadRawJson5Content(t.path)??void 0:void 0,i=u.serializeTranslationFile(t.newTranslations,s,r.extract.indentation,o);await a.mkdir(n.dirname(t.path),{recursive:!0}),await a.writeFile(t.path,i),p.info(e.green(`Updated: ${t.path}`))}if(f.length>0){x.text="Running post-extraction plugins...";for(const t of f)await(t.afterSync?.(c,r))}return x.succeed(e.bold("Extraction complete!")),l&&await async function(){if(!await m.shouldShowFunnel("extract"))return;return console.log(e.yellow.bold("\n💡 Tip: Tired of running the extractor manually?")),console.log(' Discover a real-time "push" workflow with `saveMissing` and Locize AI,'),console.log(" where keys are created and translated automatically as you code."),console.log(` Learn more: ${e.cyan("https://www.locize.com/blog/i18next-savemissing-ai-automation")}`),console.log(` Watch the video: ${e.cyan("https://youtu.be/joPsZghT3wM")}`),m.recordFunnelShown("extract")}(),l}catch(t){throw x.fail(e.red("Extraction failed.")),t}};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var e=require("node:path"),t=require("glob"),n=require("../../utils/nested-object.js"),
|
|
1
|
+
"use strict";var e=require("node:path"),t=require("glob"),n=require("../../utils/nested-object.js"),r=require("../../utils/file-utils.js"),s=require("../../utils/default-value.js");const a=[" ",",","?","!",";"];function o(e){const t=`^${e.replace(/[.+?^${}()|[\]\\]/g,"\\$&").replace(/\*/g,".*")}$`;return new RegExp(t)}function i(e,t,n,r){if(0===t.size)return!1;let s=e;const a=["zero","one","two","few","many","other"];for(const e of a){if(s.endsWith(`${n}${e}`)){s=s.slice(0,-(n.length+e.length));break}if(s.endsWith(`${n}ordinal${n}${e}`)){s=s.slice(0,-(n.length+7+n.length+e.length));break}}const o=s.split(r);if(o.length>1)for(let e=1;e<o.length;e++){const n=o.slice(0,-e).join(r);if(t.has(n))return!0}return!!t.has(s)}function l(e,t,n){if(!n)return!0;let r=!n.test(e);if(!r){const s=e.indexOf(t);s>0&&!n.test(e.substring(0,s))&&(r=!0)}return r}function c(e,t,n){if("object"!=typeof e||null===e||Array.isArray(e))return e;const r={},s=t?.extract?.pluralSeparator??"_",a=["zero","one","two","few","many","other"],o=a.map(e=>`ordinal${s}${e}`),i=Object.keys(e).sort((e,t)=>{const r=e=>{for(const t of o)if(e.endsWith(`${s}${t}`)){return{base:e.slice(0,-(s.length+t.length)),form:t,isOrdinal:!0,isPlural:!0,fullKey:e}}for(const t of a)if(e.endsWith(`${s}${t}`)){return{base:e.slice(0,-(s.length+t.length)),form:t,isOrdinal:!1,isPlural:!0,fullKey:e}}return{base:e,form:"",isOrdinal:!1,isPlural:!1,fullKey:e}},i=r(e),l=r(t);if(i.isPlural&&l.isPlural){const e=n?n(i.base,l.base):i.base.localeCompare(l.base,void 0,{sensitivity:"base"});if(0!==e)return e;if(i.isOrdinal!==l.isOrdinal)return i.isOrdinal?1:-1;const t=i.isOrdinal?o:a,r=t.indexOf(i.form),s=t.indexOf(l.form);return-1!==r&&-1!==s?r-s:i.form.localeCompare(l.form)}if(n)return n(e,t);const c=e.localeCompare(t,void 0,{sensitivity:"base"});return 0===c?e.localeCompare(t,void 0,{sensitivity:"case"}):c});for(const s of i)r[s]=c(e[s],t,n);return r}function u(e,t,r,u,f,d=[],p=new Set,g=!1,h=!1){const{keySeparator:y=".",sort:x=!0,removeUnusedKeys:$=!0,primaryLanguage:S,defaultValue:m="",pluralSeparator:O="_",contextSeparator:v="_",preserveContextVariants:N=!1}=r.extract,w="string"==typeof r.extract.nsSeparator?r.extract.nsSeparator:":",b=r.extract.defaultValue,k=(e,t,n)=>{if(n)return!1;if(null==t)return!0;const r=String(t);if(r===e)return!0;if(w&&f&&r===`${f}${w}${e}`)return!0;if("string"==typeof y&&y.length>0&&e.endsWith(`${y}${r}`))return!0;if(r&&e!==r){if(e.startsWith(r+O))return!0;if(e.startsWith(r+v))return!0}return!1},j=a.filter(e=>w.indexOf(e)<0&&("string"!=typeof y||y.indexOf(e)<0)),V=j.length>0?new RegExp(`(${j.map(e=>"?"===e?"\\?":e).join("|")})`):null,P=new Set;if(N)for(const{keyAcceptingContext:t}of e)t&&P.add(t);const W=new Set;let C=[],_=[];try{const e=new Intl.PluralRules(u,{type:"cardinal"}),t=new Intl.PluralRules(u,{type:"ordinal"});C=e.resolvedOptions().pluralCategories,_=t.resolvedOptions().pluralCategories,C.forEach(e=>W.add(e)),t.resolvedOptions().pluralCategories.forEach(e=>W.add(`ordinal_${e}`))}catch(e){const t=S||"en",n=new Intl.PluralRules(t,{type:"cardinal"}),r=new Intl.PluralRules(t,{type:"ordinal"});C=n.resolvedOptions().pluralCategories,_=r.resolvedOptions().pluralCategories,C.forEach(e=>W.add(e)),r.resolvedOptions().pluralCategories.forEach(e=>W.add(`ordinal_${e}`))}const E=r.extract.preservePatterns||[],A=e=>{if(d.some(t=>t.test(e)))return!0;for(const t of E)if("string"==typeof t){if(t.endsWith(`${w}*`)){const e=t.slice(0,-(w.length+1));if("*"===e||f&&e===f)return!0}if(t.includes(w)&&f){const[n,r]=t.split(w);if(n===f){if(o(r).test(e))return!0}}}return!1},D=e.filter(({key:e,hasCount:t,isOrdinal:n})=>{if((e=>{if(d.some(t=>t.test(e)))return!0;for(const e of E)if("string"==typeof e&&e.endsWith(`${w}*`)){const t=e.slice(0,-(w.length+1));if("*"===t||f&&t===f)return!0}return!1})(e))return!1;if(!t)return!0;const r=e.split(O);if(t&&1===r.length)return!0;if(1===C.length&&"other"===C[0]&&1===r.length)return!0;if(n&&r.includes("ordinal")){const e=r[r.length-1];return W.has(`ordinal_${e}`)}if(t){const e=r[r.length-1];return W.has(e)}return!0}),R=new Set;for(const e of D)if(e.isExpandedPlural){const t=String(e.key).split(O);t.length>=3&&"ordinal"===t[t.length-2]?R.add(t.slice(0,-2).join(O)):R.add(t.slice(0,-1).join(O))}let T=$?{}:JSON.parse(JSON.stringify(t));const I=n.getNestedKeys(t,y??".");for(const e of I){const r=A(e),s=!r&&i(e,P,O,v);if(r||N&&s){const r=n.getNestedValue(t,e,y??".");n.setNestedValue(T,e,r,y??".")}}if($){const e=n.getNestedKeys(t,y??".");for(const r of e){const e=r.split(O);if("zero"===e[e.length-1]){const s=e.slice(0,-1).join(O);if(D.some(({key:e})=>e.split(O).slice(0,-1).join(O)===s)){const e=n.getNestedValue(t,r,y??".");n.setNestedValue(T,r,e,y??".")}}}}for(const{key:e,defaultValue:a,explicitDefault:o,hasCount:i,isExpandedPlural:c,isOrdinal:d}of D){if(i&&!c){const t=String(e).split(O);let n=e;if(t.length>=3&&"ordinal"===t[t.length-2]?n=t.slice(0,-2).join(O):t.length>=2&&(n=t.slice(0,-1).join(O)),R.has(n))continue}if(i&&!c){if(1===String(e).split(O).length&&u!==S){const o=e;if(R.has(o));else{const e=d?_:C;for(const i of e){const e=d?`${o}${O}ordinal${O}${i}`:`${o}${O}${i}`,l=!e.startsWith("<")&&(y??"."),c=n.getNestedValue(t,e,l);if(void 0===c){let t;t="string"==typeof a?a:s.resolveDefaultValue(m,String(o),f||r?.extract?.defaultNS||"translation",u,a),n.setNestedValue(T,e,t,l)}else n.setNestedValue(T,e,c,l)}}continue}}let x=!e.startsWith("<")&&(y??".");x&&"string"==typeof x&&(l(e,x,V)||(x=!1));const $=n.getNestedValue(t,e,x),N=!1===y||!D.some(t=>t.key!==e&&t.key.startsWith(`${e}${y}`)),j="object"==typeof $&&null!==$&&(p.has(e)||!a||a===e),P="object"==typeof $&&null!==$&&N&&!p.has(e)&&!j;if(j){n.setNestedValue(T,e,$,x);continue}let W;if(void 0===$||P)if(u===S)if(g){const t=k(e,a,o);W=a&&!t?a:s.resolveDefaultValue(m,e,f||r?.extract?.defaultNS||"translation",u,a)}else{W=k(e,a,o)&&void 0!==b?s.resolveDefaultValue(b,e,f||r?.extract?.defaultNS||"translation",u,a):a||e}else W=s.resolveDefaultValue(m,e,f||r?.extract?.defaultNS||"translation",u,a);else if(u===S&&g){const t=a&&(a===e||w&&f&&a===`${f}${w}${e}`||e!==a&&(e.startsWith(a+O)||e.startsWith(a+v)));W=(e.includes(O)||e.includes(v))&&!o?$:a&&!t?s.resolveDefaultValue(a,e,f||r?.extract?.defaultNS||"translation",u,a):$}else W=h&&u!==S&&o?s.resolveDefaultValue(m,e,f||r?.extract?.defaultNS||"translation",u,a):$;n.setNestedValue(T,e,W,x)}if(!0===x)return c(T,r);if("function"==typeof x){const t={},n=Object.keys(T),s=new Map;for(const t of e)if(s.set(String(t.key),t),y){const e=String(t.key).split(y)[0];s.has(e)||s.set(e,t)}const a=(e,t)=>{const n=s.get(e),r=s.get(t);if(n&&r)return x(n,r);return x({key:e},{key:t})};n.sort(a);for(const e of n)t[e]=c(T[e],r,a);T=t}return T}exports.getTranslations=async function(n,s,i,{syncPrimaryWithDefaults:l=!1,syncAll:c=!1}={}){i.extract.primaryLanguage||=i.locales[0]||"en",i.extract.secondaryLanguages||=i.locales.filter(e=>e!==i?.extract?.primaryLanguage);const f=[...i.extract.preservePatterns||[]],d=i.extract.indentation??2;for(const e of s)f.push(`${e}.*`);const p=f.map(o),g="__no_namespace__",h=new Map,y="string"==typeof i.extract.nsSeparator?i.extract.nsSeparator:":",x=new RegExp(`(${a.map(e=>"?"===e?"\\?":e).join("|")})`);for(const e of n.values()){let t=e.ns,n=e.key;t&&x.test(t)&&(n=`${t}${y}${n}`,t=void 0);const r=e.nsIsImplicit&&!1===i.extract.defaultNS?g:String(t??i.extract.defaultNS??"translation");h.has(r)||h.set(r,[]),t!==e.ns||n!==e.key?h.get(r).push({...e,ns:t,key:n}):h.get(r).push(e)}const $=[],S=Array.isArray(i.extract.ignore)?i.extract.ignore:i.extract.ignore?[i.extract.ignore]:[];for(const n of i.locales){if(i.extract.mergeNamespaces||"string"==typeof i.extract.output&&!i.extract.output.includes("{{namespace}}")){const t={},a=r.getOutputPath(i.extract.output,n),o=e.resolve(process.cwd(),a),c=await r.loadTranslationFile(o)||{},f=Object.keys(c),y=!1!==i.extract.defaultNS&&f.some(e=>{const t=c[e];return"object"==typeof t&&null!==t&&!Array.isArray(t)})?new Set([...h.keys(),...f]):new Set([...h.keys(),g]);for(const e of y){const r=h.get(e)||[];if(e===g){const e=u(r,c,i,n,void 0,p,s,l);Object.assign(t,e)}else{const a=c[e]||{};t[e]=u(r,a,i,n,e,p,s,l)}}const x=JSON.stringify(c,null,d),S=JSON.stringify(t,null,d);$.push({path:o,updated:S!==x,newTranslations:t,existingTranslations:c})}else{const a=new Set(h.keys()),o=r.getOutputPath(i.extract.output,n,"*").replace(/\\/g,"/"),f=await t.glob(o,{ignore:S});for(const t of f)a.add(e.basename(t,e.extname(t)));for(const t of a){const a=h.get(t)||[],o=r.getOutputPath(i.extract.output,n,t),f=e.resolve(process.cwd(),o),g=await r.loadTranslationFile(f)||{},y=u(a,g,i,n,t,p,s,l,c),x=JSON.stringify(g,null,d),S=JSON.stringify(y,null,d);$.push({path:f,updated:S!==x,newTranslations:y,existingTranslations:g})}}}return $};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var e=require("./jsx-parser.js"),t=require("./ast-utils.js");exports.JSXHandler=class{config;pluginContext;expressionResolver;getCurrentFile;getCurrentCode;lastSearchIndex=0;constructor(e,t,n,o,i){this.config=e,this.pluginContext=t,this.expressionResolver=n,this.getCurrentFile=o,this.getCurrentCode=i}resetSearchIndex(){this.lastSearchIndex=0}getLocationFromNode(e){const t=this.getCurrentCode();let n;if("JSXElement"===e.type&&e.opening){const t=e.opening.name?.value;t&&(n=`<${t}`)}if(!n)return;const o=t.indexOf(n,this.lastSearchIndex);if(-1===o)return;this.lastSearchIndex=o+n.length;const i=t.substring(0,o).split("\n");return{line:i.length,column:i[i.length-1].length}}handleJSXElement(t,n){const o=this.getElementName(t);if(o&&(this.config.extract.transComponents||["Trans"]).includes(o)){
|
|
1
|
+
"use strict";var e=require("./jsx-parser.js"),t=require("./ast-utils.js");exports.JSXHandler=class{config;pluginContext;expressionResolver;getCurrentFile;getCurrentCode;lastSearchIndex=0;constructor(e,t,n,o,i){this.config=e,this.pluginContext=t,this.expressionResolver=n,this.getCurrentFile=o,this.getCurrentCode=i}resetSearchIndex(){this.lastSearchIndex=0}getLocationFromNode(e){const t=this.getCurrentCode();let n;if("JSXElement"===e.type&&e.opening){const t=e.opening.name?.value;t&&(n=`<${t}`)}if(!n)return;const o=t.indexOf(n,this.lastSearchIndex);if(-1===o)return;this.lastSearchIndex=o+n.length;const i=t.substring(0,o).split("\n");return{line:i.length,column:i[i.length-1].length}}handleJSXElement(t,n){const o=this.getElementName(t);if(o&&(this.config.extract.transComponents||["Trans"]).includes(o)){let i=null;try{i=e.extractFromTransComponent(t,this.config)}catch(e){const n=this.getLocationFromNode(t),i=n?`${this.getCurrentFile()}:${n.line}:${n.column}`:this.getCurrentFile(),s=e instanceof Error?e.message:("string"==typeof e?e:"")||String(e),a=this.pluginContext?.logger?.warn?.bind(this.pluginContext.logger)??console.warn.bind(console);return a(`Failed to extract <${o}> at ${i}`),void a(` ${s}`)}const s=[];if(i){if(i.keyExpression){const e=this.expressionResolver.resolvePossibleKeyStringValues(i.keyExpression);s.push(...e)}else s.push(i.serializedChildren);let e;const{contextExpression:o,optionsNode:a,defaultValue:l,hasCount:r,isOrdinal:u,serializedChildren:c}=i,f=this.getLocationFromNode(t),d=f?[{file:this.getCurrentFile(),line:f.line,column:f.column}]:void 0;if(i.ns){const{ns:t}=i;e=s.map(e=>({key:e,ns:t,defaultValue:l||c,hasCount:r,isOrdinal:u,locations:d}))}else{e=s.map(e=>{const t=this.config.extract.nsSeparator??":";let n;if(t&&e.includes(t)){let o;[n,...o]=e.split(t),e=o.join(t)}return{key:e,ns:n,defaultValue:l||c,hasCount:r,isOrdinal:u,explicitDefault:i.explicitDefault,locations:d}});const o=t.opening.attributes?.find(e=>"JSXAttribute"===e.type&&"Identifier"===e.name.type&&"t"===e.name.value);if("JSXAttribute"===o?.type&&"JSXExpressionContainer"===o.value?.type&&"Identifier"===o.value.expression.type){const t=n(o.value.expression.value);if(t?.defaultNs&&e.forEach(e=>{e.ns||(e.ns=t.defaultNs)}),t?.keyPrefix){const n=this.config.extract.keySeparator??".";for(const o of e){let e=o.key;if(e=!1!==n?String(t.keyPrefix).endsWith(String(n))?`${t.keyPrefix}${e}`:`${t.keyPrefix}${n}${e}`:`${t.keyPrefix}${e}`,!1!==n){if(String(e).split(String(n)).some(e=>""===e.trim()))continue}o.key=e}}}}if(e.forEach(e=>{e.ns||(e.ns=this.config.extract.defaultNS)}),o&&r)if(this.config.extract.disablePlurals){const t=this.expressionResolver.resolvePossibleContextStringValues(o),n=this.config.extract.contextSeparator??"_";if(t.length>0)if("StringLiteral"===o.type)for(const o of t)for(const t of e){const e=`${t.key}${n}${o}`;this.pluginContext.addKey({key:e,ns:t.ns,defaultValue:t.defaultValue,locations:t.locations})}else{e.forEach(e=>{this.pluginContext.addKey({key:e.key,ns:e.ns,defaultValue:e.defaultValue,locations:e.locations,keyAcceptingContext:e.key})});for(const o of t)for(const t of e){const e=`${t.key}${n}${o}`;this.pluginContext.addKey({key:e,ns:t.ns,defaultValue:t.defaultValue,locations:t.locations})}}else e.forEach(e=>{this.pluginContext.addKey({key:e.key,ns:e.ns,defaultValue:e.defaultValue,locations:e.locations,keyAcceptingContext:e.key})})}else{const n=t.opening.attributes?.find(e=>"JSXAttribute"===e.type&&"Identifier"===e.name.type&&"ordinal"===e.name.value),i=!!n,s=this.expressionResolver.resolvePossibleContextStringValues(o),l=this.config.extract.contextSeparator??"_";if(s.length>0){!1!==this.config.extract.generateBasePluralForms&&e.forEach(e=>this.generatePluralKeysForTrans(e.key,e.defaultValue,e.ns,i,a,void 0,e.locations,e.key));for(const t of s)for(const n of e){const e=`${n.key}${l}${t}`;this.generatePluralKeysForTrans(e,n.defaultValue,n.ns,i,a,n.explicitDefault,n.locations,n.key)}}else e.forEach(e=>this.generatePluralKeysForTrans(e.key,e.defaultValue,e.ns,i,a,e.explicitDefault,e.locations))}else if(o){const t=this.expressionResolver.resolvePossibleContextStringValues(o),n=this.config.extract.contextSeparator??"_";if(t.length>0){for(const o of t)for(const{key:t,ns:i,defaultValue:s,locations:a}of e)this.pluginContext.addKey({key:`${t}${n}${o}`,ns:i,defaultValue:s,locations:a});"StringLiteral"!==o.type&&e.forEach(e=>{this.pluginContext.addKey({key:e.key,ns:e.ns,defaultValue:e.defaultValue,locations:e.locations,keyAcceptingContext:e.key})})}else e.forEach(e=>{this.pluginContext.addKey({key:e.key,ns:e.ns,defaultValue:e.defaultValue,locations:e.locations,keyAcceptingContext:e.key})})}else if(r)if(this.config.extract.disablePlurals)e.forEach(e=>{this.pluginContext.addKey({key:e.key,ns:e.ns,defaultValue:e.defaultValue,locations:e.locations})});else{const n=t.opening.attributes?.find(e=>"JSXAttribute"===e.type&&"Identifier"===e.name.type&&"ordinal"===e.name.value),o=!!n;e.forEach(e=>this.generatePluralKeysForTrans(e.key,e.defaultValue,e.ns,o,a,e.explicitDefault,e.locations))}else e.forEach(e=>{this.pluginContext.addKey({key:e.key,ns:e.ns,defaultValue:e.defaultValue,locations:e.locations})})}}}generatePluralKeysForTrans(e,n,o,i,s,a,l,r){try{const u=i?"ordinal":"cardinal",c=new Intl.PluralRules(this.config.extract?.primaryLanguage,{type:u}).resolvedOptions().pluralCategories,f=this.config.extract.pluralSeparator??"_";let d,p;if(s&&(d=t.getObjectPropValue(s,`defaultValue${f}other`),p=t.getObjectPropValue(s,`defaultValue${f}ordinal${f}other`)),1===c.length&&"other"===c[0]){const u=s?t.getObjectPropValue(s,`defaultValue${f}other`):void 0,c="string"==typeof u?u:"string"==typeof n?n:e;return void this.pluginContext.addKey({key:e,ns:o,defaultValue:c,hasCount:!0,isOrdinal:i,explicitDefault:Boolean(a||"string"==typeof u||"string"==typeof d),locations:l,keyAcceptingContext:r})}for(const u of c){const c=i?`defaultValue${f}ordinal${f}${u}`:`defaultValue${f}${u}`,g=s?t.getObjectPropValue(s,c):void 0;let y;y="string"==typeof g?g:"one"===u&&"string"==typeof n?n:i&&"string"==typeof p?p:i||"string"!=typeof d?"string"==typeof n?n:e:d;const h=i?`${e}${f}ordinal${f}${u}`:`${e}${f}${u}`;this.pluginContext.addKey({key:h,ns:o,defaultValue:y,hasCount:!0,isOrdinal:i,explicitDefault:Boolean(a||"string"==typeof g||"string"==typeof d),locations:l,keyAcceptingContext:r})}}catch(t){this.pluginContext.addKey({key:e,ns:o,defaultValue:n,locations:l})}}getElementName(e){if("Identifier"===e.opening.name.type)return e.opening.name.value;if("JSXMemberExpression"===e.opening.name.type){let t=e.opening.name;const n=[];for(;"JSXMemberExpression"===t.type;)"Identifier"===t.property.type&&n.unshift(t.property.value),t=t.object;return"Identifier"===t.type&&n.unshift(t.value),n.join(".")}}};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var e=require("./ast-utils.js");function t(t){if(t)return"StringLiteral"===t.type?t.value:"TemplateLiteral"===t.type&&e.isSimpleTemplateLiteral(t)?t.quasis[0].cooked:void 0}function n(e){return"StringLiteral"===e.value?.type?e.value.value:"JSXExpressionContainer"===e.value?.type?t(e.value.expression):void 0}exports.extractFromTransComponent=function(i,s){const r=i.opening.attributes?.find(e=>"JSXAttribute"===e.type&&"Identifier"===e.name.type&&"i18nKey"===e.name.value),o=i.opening.attributes?.find(e=>"JSXAttribute"===e.type&&"Identifier"===e.name.type&&"defaults"===e.name.value),p=i.opening.attributes?.find(e=>"JSXAttribute"===e.type&&"Identifier"===e.name.type&&"count"===e.name.value),l=i.opening.attributes?.find(e=>"JSXAttribute"===e.type&&"Identifier"===e.name.type&&"values"===e.name.value);let a;p||"JSXAttribute"!==l?.type||"JSXExpressionContainer"!==l.value?.type||"ObjectExpression"!==l.value.expression.type||(a=e.getObjectPropValueExpression(l.value.expression,"count"));const c=!!p||!!a,u=i.opening.attributes?.find(e=>"JSXAttribute"===e.type&&"Identifier"===e.name.type&&"tOptions"===e.name.value),f="JSXAttribute"===u?.type&&"JSXExpressionContainer"===u.value?.type&&"ObjectExpression"===u.value.expression.type?u.value.expression:void 0,y=i.opening.attributes?.find(e=>"JSXAttribute"===e.type&&"Identifier"===e.name.type&&"ordinal"===e.name.value),d=!!y,g=i.opening.attributes?.find(e=>"JSXAttribute"===e.type&&"Identifier"===e.name.type&&"context"===e.name.value);let x="JSXAttribute"===g?.type&&"JSXExpressionContainer"===g.value?.type?g.value.expression:"JSXAttribute"===g?.type&&"StringLiteral"===g.value?.type?g.value:void 0;const h=i.opening.attributes?.find(e=>"JSXAttribute"===e.type&&"Identifier"===e.name.type&&"ns"===e.name.value);let S;S="JSXAttribute"===h?.type?n(h):void 0,f&&(void 0===S&&(S=e.getObjectPropValue(f,"ns")),void 0===x&&(x=e.getObjectPropValueExpression(f,"context")));const v=function(e,n){if(!e||0===e.length)return"";const i=new Set(n.extract.transKeepBasicHtmlNodesFor??["br","strong","i","p"]),s=e=>e&&"JSXText"===e.type&&/^\s*$/.test(e.value)&&e.value.includes("\n");function r(e,n,o=!1,p=!1){if(!e||!e.length)return;const l=p&&e.filter(e=>e&&"JSXElement"===e.type&&"p"===e.opening?.name?.value).length>1;let a=0,c=e.length-1;for(;a<=c&&s(e[a]);)a++;for(;c>=a&&s(e[c]);)c--;const u=a<=c?e.slice(a,c+1):[],f=u.some(e=>e&&("JSXElement"===e.type||"JSXFragment"===e.type));for(let e=0;e<u.length;e++){const a=u[e];if(a)if("JSXText"!==a.type){if("JSXExpressionContainer"===a.type){if(o&&!f&&a.expression){const e=a.expression.type;if("ObjectExpression"===e)continue;if(void 0!==t(a.expression))continue;if("Identifier"===e||"MemberExpression"===e||"CallExpression"===e)continue}const i=t(a.expression);if(void 0!==i){const t=/^\s*$/.test(i)&&!i.includes("\n"),r=u[e-1],o=u[e+1];if(t){const t=u[e+2];if(o&&"JSXText"===o.type&&s(o)&&t&&("JSXElement"===t.type||"JSXFragment"===t.type)){const t=u[e-1],n=u[e-2];if(!t||"JSXText"!==t.type&&n&&"JSXExpressionContainer"===n.type)continue}if(r&&("JSXElement"===r.type||"JSXFragment"===r.type)&&o&&"JSXText"===o.type&&s(o))continue;const i=!o||"JSXText"===o.type&&!s(o);if(r&&"JSXText"===r.type&&i){const e=n[n.length-1];if(e&&"JSXText"===e.type){e.value=String(e.value)+a.expression.value;continue}}if(r&&("JSXElement"===r.type||"JSXFragment"===r.type)&&o&&"JSXText"===o.type&&s(o))continue}}n.push(a);continue}if("JSXElement"===a.type){const e=a.opening&&a.opening.name&&"Identifier"===a.opening.name.type?a.opening.name.value:void 0;if(e&&i.has(e)){const o=a.opening&&Array.isArray(a.opening.attributes)&&a.opening.attributes.length>0,c=a.children||[],f=1===c.length&&("JSXText"===c[0]?.type||"JSXExpressionContainer"===c[0]?.type&&void 0!==t(c[0].expression)),y=!c.length,d=f;if(o&&!f)n.push(a),r(a.children||[],n,!0);else if(y)n.push(a);else if(!d){if((a.children||[]).some(e=>"JSXExpressionContainer"===e.type&&void 0===t(e.expression)))n.push(a),r(a.children||[],n,!0);else if("p"===e){const e=(c||[]).some(e=>{if(!e||"JSXElement"!==e.type)return!1;const n=e.opening&&e.opening.name&&"Identifier"===e.opening.name.type?e.opening.name.value:void 0,s=e.opening&&Array.isArray(e.opening.attributes)&&e.opening.attributes.length>0,r=e.children||[],o=1===r.length&&("JSXText"===r[0]?.type||"JSXExpressionContainer"===r[0]?.type&&void 0!==t(r[0].expression));return!(n&&i.has(n)&&!s&&(0===r.length||o))}),o=p&&u.some(e=>e&&e!==a&&"JSXText"===e.type&&!s(e));l||p&&e&&!o?(n.push(a),r(a.children||[],n,!0,!1)):r(a.children||[],n,!1,!1)}else r(a.children||[],n,!1,!1)}continue}n.push(a),r(a.children||[],n,!0);continue}"JSXFragment"!==a.type||r(a.children||[],n,o)}else{if(o&&!f)continue;if(o&&s(a))continue;if(s(a)){const t=u[e-1],i=u[e+1];if(t&&("JSXElement"===t.type||"JSXFragment"===t.type)&&i&&("JSXElement"===i.type||"JSXFragment"===i.type))continue;const s=n[n.length-1],r=u[e-1];if(s){if(r&&"JSXExpressionContainer"===r.type)continue;if("JSXText"===s.type&&r&&"JSXText"===r.type){s.value=String(s.value)+a.value;continue}}}if(o&&f&&0===e)continue;n.push(a)}}}const o=[];function p(e){if(!e||!e.length)return!1;let t=!1;for(const n of e)if(n)if("JSXElement"!==n.type){if("JSXExpressionContainer"===n.type&&-1!==o.indexOf(n))return t;if("JSXText"===n.type&&-1!==o.indexOf(n)){if(s(n))continue;if(!t)return!0;const i=e.indexOf(n);if(e.slice(i+1).some(e=>e&&"JSXElement"===e.type))return!0}}else t=!0;return!1}r(e,o,!1,!0);const l=new Set,a=e=>String(e).replace(/^\s*\n\s*/g,"").replace(/\s*\n\s*$/g,"");function c(e,n,r=!1){if(!e||0===e.length)return"";let u="";const f=e=>{if(!e)return-1;if(n&&n.has(e))return n.get(e);if(n)for(const[t,i]of n.entries())try{if(t&&e&&t.span&&e.span&&t.span.start===e.span.start&&t.span.end===e.span.end)return i}catch(e){}return o.indexOf(e)},y=t=>{if(!r)return o.indexOf(t);const n=e.indexOf(t);if(-1===n)return-1;let i=0;for(let t=0;t<n;t++){const n=e[t];n&&("JSXText"===n.type?s(n)||i++:"JSXExpressionContainer"===n.type?n.expression&&"JSXEmptyExpression"!==n.expression.type&&i++:"JSXElement"===n.type&&i++)}return i};for(let n=0;n<e.length;n++){const d=e[n];if(d){if("JSXText"===d.type){if(s(d))continue;const t=e[n+1],r=e[n-1];if(r&&"JSXElement"===r.type){const t="Identifier"===r.opening?.name?.type?r.opening.name.value:void 0,s=t&&i.has(t),o=0===(r.children||[]).length;if(s&&o&&/^\s*\n\s*/.test(d.value)){const e=d.value.replace(/^\s*\n\s*/,"");if(e){u+=e;continue}continue}if(!s&&/^\s*\n\s*/.test(d.value)){const t=d.value.replace(/^\s*\n\s*/,"");if(t){if(r&&"JSXElement"===r.type&&Array.isArray(r.children)&&0===r.children.length){u+=t;continue}const i=e[n-2];if(i&&"JSXText"===i.type){const e=i.value.replace(/\n\s*$/,""),n=/[A-Za-z0-9]$/.test(e),s=/^[A-Za-z0-9]/.test(t),r=/^[a-z]/.test(t);if(n&&s&&r){u+=t;continue}}u+=" "+t;continue}continue}}if(/\n\s*$/.test(d.value)&&t&&"JSXElement"===t.type){const r=d.value.replace(/\n\s*$/,"");if(r.trim()){const o="Identifier"===t.opening?.name?.type?t.opening.name.value:void 0,p=o&&i.has(o),a=(t.children||[]).length>0,c=/\s\n/.test(d.value),f=e[n+2],y=f&&"JSXText"===f.type&&!s(f)&&/[a-zA-Z0-9]/.test(f.value),g=!!(t.opening&&Array.isArray(t.opening.attributes)&&t.opening.attributes.length>0),x=/^\s/.test(r)&&!/^\n/.test(r),h=r.trim(),S=x?" "+h:h,v=/[A-Za-z0-9]$/.test(h),m=f&&"string"==typeof f.value&&/^[A-Za-z0-9]/.test(f.value.trim()),J=f&&"string"==typeof f.value&&/^[a-z]/.test(f.value.trim()),X=f&&"string"==typeof f.value&&/^\s/.test(f.value)&&!/^\n/.test(f.value),$=g&&a&&y&&!(v&&m&&J&&!c&&!x&&!X),E=f&&"string"==typeof f.value&&/^[,;:!?.]/.test(f.value.trim()),b=$&&!E;v&&m&&J&&!c&&!x&&!X&&l.add(t),u+=c||p&&a||!p&&y&&x||b?S+" ":S;continue}}u+=d.value;continue}if("JSXExpressionContainer"===d.type){const e=d.expression;if(!e)continue;const n=t(e);if(void 0!==n)u+=n;else if("Identifier"===e.type)u+=`{{${e.value}}}`;else if("TsAsExpression"===e.type&&"ObjectExpression"===e.expression?.type){const t=e.expression,n=t.properties.filter(e=>"KeyValueProperty"===e.type&&e.key&&"Identifier"===e.key.type).map(e=>e.key.value);if(n.length>0)u+=n.map(e=>`{{${e}}}`).join("");else{const e=t.properties[0];if(!e||"Identifier"!==e.type)throw new Error("Unrecognized expression in JSX placeholder");u+=`{{${e.value}}}`}}else if("ObjectExpression"===e.type){const t=e.properties[0];if(t&&"KeyValueProperty"===t.type&&t.key&&"Identifier"===t.key.type)u+=`{{${t.key.value}}}`;else{if(!t||"Identifier"!==t.type)throw new Error("Unrecognized expression in JSX placeholder");u+=`{{${t.value}}}`}}else if("MemberExpression"===e.type&&e.property&&"Identifier"===e.property.type)u+=`{{${e.property.value}}}`;else if("CallExpression"===e.type&&"Identifier"===e.callee?.type)u+=`{{${e.callee.value}}}`;else if("JSXEmptyExpression"!==e.type)throw new Error(`Unrecognized expression in JSX placeholder: ${e.type}`);continue}if("JSXElement"===d.type){const l=r?y(d):void 0;let g;if(d.opening&&d.opening.name&&"Identifier"===d.opening.name.type&&(g=d.opening.name.value),g&&i.has(g)){const y=d.opening&&Array.isArray(d.opening.attributes)&&d.opening.attributes.length>0,x=d.children||[],h=x.length>0,S=1===x.length&&("JSXText"===x[0]?.type||"JSXExpressionContainer"===x[0]?.type&&void 0!==t(x[0].expression)),v="p"===g;let m=0;if(v&&r&&(m=e.filter(e=>e&&"JSXElement"===e.type&&"p"===e.opening?.name?.value).length),!h||S){const t=S?c(x,void 0):"";if(""!==String(t).trim())if(i.has(g)&&"p"!==g)u+=`<${g}>${a(t)}</${g}>`;else if(v&&r&&m>1)u+=`<${g}>${a(t)}</${g}>`;else if(v){const e=r&&void 0!==l?l:o.indexOf(d);u+=`<${e}>${a(t)}</${e}>`}else{const e=r&&void 0!==l?l:o.indexOf(d);u+=`<${e}>${a(t)}</${e}>`}else{const t=e[n-1];t&&"JSXText"===t.type&&/\n\s*$/.test(t.value)&&(u=u.replace(/\s+$/,"")),u+=`<${g} />`}}else if(y&&!S){const e=x,n=r&&void 0!==l?l:f(d);if(p(e)){const s=new Map;let r=0;for(const n of e)if(n&&"JSXElement"===n.type){const e=n.opening&&n.opening.name&&"Identifier"===n.opening.name.type?n.opening.name.value:void 0;if(e&&i.has(e)){const e=n.opening&&Array.isArray(n.opening.attributes)&&n.opening.attributes.length>0,i=n.children||[],o=1===i.length&&("JSXText"===i[0]?.type||"JSXExpressionContainer"===i[0]?.type&&void 0!==t(i[0].expression));!e&&(!i.length||o)||s.set(n,r++)}else s.set(n,r++)}const o=c(e,s.size?s:void 0);u+=`<${n}>${a(o)}</${n}>`}else{const e=new Map;let s=0;for(const n of x)if(n&&"JSXElement"===n.type){const r=n.opening&&n.opening.name&&"Identifier"===n.opening.name.type?n.opening.name.value:void 0;if(r&&i.has(r)){const i=n.opening&&Array.isArray(n.opening.attributes)&&n.opening.attributes.length>0,r=n.children||[],o=1===r.length&&("JSXText"===r[0]?.type||"JSXExpressionContainer"===r[0]?.type&&void 0!==t(r[0].expression));!i&&(!r.length||o)||e.set(n,s++)}else e.set(n,s++)}const r=c(x,e.size?e:void 0);u+=`<${n}>${a(r)}</${n}>`}}else{const e=o.indexOf(d);if(-1!==e){const n=void 0!==l?l:e;if((()=>{let e=!1;for(const t of x)if(t)if("JSXElement"!==t.type){if("JSXExpressionContainer"===t.type&&-1!==o.indexOf(t))return e;if("JSXText"===t.type&&-1!==o.indexOf(t)){if(s(t))continue;if(!e)return!0;if(x.slice(x.indexOf(t)+1).some(e=>e&&"JSXElement"===e.type))return!0}}else e=!0;return!1})()){if(0===n){const e=c(x,void 0,!1);u+=`<${n}>${a(e)}</${n}>`;continue}const e=new Map;for(const e of x)if(e&&"JSXElement"===e.type){const s=e.opening&&e.opening.name&&"Identifier"===e.opening.name.type?e.opening.name.value:void 0;if(s&&i.has(s)){const i=e.opening&&Array.isArray(e.opening.attributes)&&e.opening.attributes.length>0,s=e.children||[],r=1===s.length&&("JSXText"===s[0]?.type||"JSXExpressionContainer"===s[0]?.type&&void 0!==t(s[0].expression));if(!(!i&&(!s.length||r))){const t=c(e.children,void 0,!1);u+=`<${n}>${a(t)}</${n}>`}}else{const t=c(e.children,void 0,!1);u+=`<${n}>${a(t)}</${n}>`}}const s=c(x,e.size?e:void 0,!1);u+=`<${n}>${a(s)}</${n}>`;continue}const r=new Map;let p=0;for(const e of x)if(e&&"JSXElement"===e.type){const n=e.opening&&e.opening.name&&"Identifier"===e.opening.name.type?e.opening.name.value:void 0;if(n&&i.has(n)){const n=e.opening&&Array.isArray(e.opening.attributes)&&e.opening.attributes.length>0,i=e.children||[],s=1===i.length&&("JSXText"===i[0]?.type||"JSXExpressionContainer"===i[0]?.type&&void 0!==t(i[0].expression));!n&&(!i.length||s)||r.set(e,p++)}else r.set(e,p++)}const f=c(x,r.size>0?r:void 0,!1);u+=`<${n}>${a(f)}</${n}>`}else{const e=c(x,void 0,!1);u+=`<${g}>${a(e)}</${g}>`}}}else{const e=d.children||[];if(e.some(e=>e&&("JSXText"===e.type||"JSXExpressionContainer"===e.type)&&-1!==o.indexOf(e))){const t=o.indexOf(d),n=c(e,void 0);u+=`<${t}>${a(n)}</${t}>`}else{const t=new Map,n=f(d);let s=0;for(const n of e)if(n&&"JSXElement"===n.type){const e=n.opening&&n.opening.name&&"Identifier"===n.opening.name.type?n.opening.name.value:void 0;if(e&&i.has(e)){const e=n.opening&&Array.isArray(n.opening.attributes)&&n.opening.attributes.length>0,i=n.children||[],r=1===i.length&&"JSXText"===i[0]?.type;!e&&(!i.length||r)||t.set(n,s++)}else t.set(n,s++)}const r=c(e,t.size?t:void 0);u+=`<${n}>${a(r)}</${n}>`}}continue}"JSXFragment"!==d.type||(u+=c(d.children||[]))}}return u}const u=c(e,void 0,!0),f=String(u).replace(/<br \/>\s*\n\s*/g,"<br />"),y=String(f),d=new Set;if(l&&l.size>0)for(let e=0;e<o.length;e++)l.has(o[e])&&d.add(e);let g=String(y);if(d&&d.size>0)for(const e of d)try{g=g.replace(new RegExp("\\s+<"+e+">","g"),"<"+e+">"),g=g.replace(new RegExp("<\\/"+e+">\\s+","g"),"</"+e+">")}catch(e){}g=g.replace(/<\/(\d+)>\s*\n\s*(\S)/g,(e,t,n)=>{const i=Number(t);return d.has(i)?`</${t}>${n}`:`</${t}> ${n}`}),g=g.replace(/(\S)\s*\n\s*<(\d+)/g,(e,t,n)=>{const i=Number(n);return d.has(i)?`${t}<${n}`:`${t} <${n}`}),g=g.replace(/\s*\n\s*/g," "),g=g.replace(/\s+/g," "),g=g.replace(/\s+([,;:!?.])/g,"$1");const x=g.trim();let h=String(x);if(d&&d.size>0)for(const e of d)try{h=h.replace(new RegExp("[\\s\\u00A0]+<"+e+">","g"),"<"+e+">"),h=h.replace(new RegExp("<\\/"+e+">[\\s\\u00A0]+","g"),"</"+e+">")}catch(e){}try{for(let e=0;e<o.length;e++){const t=o[e];if(!t||"JSXElement"!==t.type)continue;const n=o[e-1],i=o[e+1];if(!n||!i)continue;if("JSXText"!==n.type||"JSXText"!==i.type)continue;const s=String(n.value),r=String(i.value),p=s.replace(/\n\s*$/,""),l=/[A-Za-z0-9]$/.test(p),a=/^[A-Za-z0-9]/.test(r.trim()),c=/^[a-z]/.test(r.trim()),u=/\s\n/.test(s),f=r&&/^\s/.test(r)&&!/^\n/.test(r);if(l&&a&&c&&!u&&!f){const t=e;h=h.replace(new RegExp("\\s+<"+t+">","g"),"<"+t+">")}}}catch(e){}function S(e){if(!e||!e.includes("<"))return e;function t(e){const t=[],n=[];let i=0;const s=/<\/?(\d+)>|<[^>]+>/g;let r;for(;r=s.exec(e);){const o=r[0],p=r.index;if(p>i){const s={type:"text",text:e.slice(i,p)};n.length?n[n.length-1].node.children.push(s):t.push(s)}const l=/^<\/(\d+)>$/.exec(o),a=/^<(\d+)>$/.exec(o);if(a){const e=Number(a[1]),i={type:"ph",idx:e,children:[]};n.length?n[n.length-1].node.children.push(i):t.push(i),n.push({node:i,idx:e})}else if(l)n.length&&n.pop();else{const e={type:"text",text:o};n.length?n[n.length-1].node.children.push(e):t.push(e)}i=s.lastIndex}if(i<e.length){const s={type:"text",text:e.slice(i)};n.length?n[n.length-1].node.children.push(s):t.push(s)}return t}function n(e,t=null){let r="";for(const p of e)if("text"===p.type)r+=p.text;else{const e=p.children.filter(e=>"ph"===e.type);let l;if("number"==typeof p.idx){const t=o[p.idx];if(t&&Array.isArray(t.children)){const n=new Map;let i=0;for(const e of t.children){const t=o.indexOf(e);if("JSXText"===e.type){if(s(e))continue;-1!==t&&n.set(t,i),i++}else"JSXElement"===e.type?(-1!==t&&n.set(t,i),i++):"JSXExpressionContainer"===e.type&&-1!==t&&(n.set(t,i),i++)}e.every(e=>n.has(e.idx))&&(l=n)}}if(!l){const n=e.map(e=>e.idx);if(n.length<=1||n.every((e,t)=>0===t||e===n[t-1]+1)){l=new Map;let n=0;try{const s=o[p.idx];if(s&&s.span){const r=s.span.start,l=s.span.end;let a=0,c=-1;for(let e=p.idx+1;e<o.length;e++){const t=o[e];if(t&&t.span&&(t.span.start>=r&&t.span.end<=l&&"JSXElement"===t.type)){c=e;break}}if(-1!==c)for(let e=p.idx+1;e<c;e++){const t=o[e];t&&t.span&&(t.span.start>=r&&t.span.end<=l&&("JSXText"!==t.type&&"JSXExpressionContainer"!==t.type||a++))}else for(let e=p.idx+1;e<o.length;e++){const t=o[e];t&&t.span&&(t.span.start>=r&&t.span.end<=l&&("JSXText"!==t.type&&"JSXExpressionContainer"!==t.type||a++))}const u=s?.opening?.name?.value,f=u&&i.has(u),y=null===t;1===e.length&&(n=Math.max(1,a+1),!y||f||0!==e[0].idx||"a"!==u&&"p"!==u||(n=0))}}catch(e){}for(const t of e)l.has(t.idx)||l.set(t.idx,n++)}}const a=p.children.map(e=>{if("text"===e.type)return e.text;const t=e.idx,i=l&&l.has(t)?l.get(t):t;return`<${i}>${n(e.children,i)}</${i}>`}).join("");r+=`<${p.idx}>${a}</${p.idx}>`}return r}try{const i=t(e);return n(i)}catch(t){return e}}return h=S(h),h.trim()}(i.children,s);let m;const J="JSXAttribute"===o?.type?n(o):void 0;if(void 0!==J)m=J;else{const e=s.extract.defaultValue;m="string"==typeof e?e:""}let X,$;if("JSXAttribute"===r?.type){if("StringLiteral"===r.value?.type){if(X=r.value,$=X.value,!$||""===$.trim())return null;if(S&&"StringLiteral"===X.type){const e=s.extract.nsSeparator??":",t=X.value;if(e&&t.startsWith(`${S}${e}`)){if($=t.slice(`${S}${e}`.length),!$||""===$.trim())return null;X={...X,value:$}}}}else"JSXExpressionContainer"===r.value?.type&&"JSXEmptyExpression"!==r.value.expression.type&&(X=r.value.expression);if(!X)return null}return o||!$||v.trim()?!o&&v.trim()&&(m=v):m=$,{keyExpression:X,serializedChildren:v,ns:S,defaultValue:m,hasCount:c,isOrdinal:d,contextExpression:x,optionsNode:f,explicitDefault:void 0!==J||(e=>{if(!e||!Array.isArray(e.properties))return!1;for(const t of e.properties)if(t&&"KeyValueProperty"===t.type&&t.key){const e="Identifier"===t.key.type&&t.key.value||"StringLiteral"===t.key.type&&t.key.value;if("string"==typeof e&&e.startsWith("defaultValue"))return!0}return!1})(f)}};
|
|
1
|
+
"use strict";var e=require("./ast-utils.js");function t(t){if(t)return"StringLiteral"===t.type?t.value:"TemplateLiteral"===t.type&&e.isSimpleTemplateLiteral(t)?t.quasis[0].cooked:void 0}function n(t){if(t)return"StringLiteral"===t.type?t.value:"TemplateLiteral"===t.type&&e.isSimpleTemplateLiteral(t)?t.quasis?.[0]?.cooked:"ParenExpression"===t.type&&t.expr?n(t.expr):"ParenthesizedExpression"===t.type&&t.expression||"TsAsExpression"===t.type&&t.expression?n(t.expression):void 0}function i(e){return"StringLiteral"===e.value?.type?e.value.value:"JSXExpressionContainer"===e.value?.type?t(e.value.expression):void 0}exports.extractFromTransComponent=function(s,r){const o=s.opening.attributes?.find(e=>"JSXAttribute"===e.type&&"Identifier"===e.name.type&&"i18nKey"===e.name.value),p=s.opening.attributes?.find(e=>"JSXAttribute"===e.type&&"Identifier"===e.name.type&&"defaults"===e.name.value),l=s.opening.attributes?.find(e=>"JSXAttribute"===e.type&&"Identifier"===e.name.type&&"count"===e.name.value),a=s.opening.attributes?.find(e=>"JSXAttribute"===e.type&&"Identifier"===e.name.type&&"values"===e.name.value);let c;l||"JSXAttribute"!==a?.type||"JSXExpressionContainer"!==a.value?.type||"ObjectExpression"!==a.value.expression.type||(c=e.getObjectPropValueExpression(a.value.expression,"count"));const u=!!l||!!c,f=s.opening.attributes?.find(e=>"JSXAttribute"===e.type&&"Identifier"===e.name.type&&"tOptions"===e.name.value),y="JSXAttribute"===f?.type&&"JSXExpressionContainer"===f.value?.type&&"ObjectExpression"===f.value.expression.type?f.value.expression:void 0,d=s.opening.attributes?.find(e=>"JSXAttribute"===e.type&&"Identifier"===e.name.type&&"ordinal"===e.name.value),g=!!d,x=s.opening.attributes?.find(e=>"JSXAttribute"===e.type&&"Identifier"===e.name.type&&"context"===e.name.value);let h="JSXAttribute"===x?.type&&"JSXExpressionContainer"===x.value?.type?x.value.expression:"JSXAttribute"===x?.type&&"StringLiteral"===x.value?.type?x.value:void 0;const v=s.opening.attributes?.find(e=>"JSXAttribute"===e.type&&"Identifier"===e.name.type&&"ns"===e.name.value);let S;S="JSXAttribute"===v?.type?i(v):void 0,y&&(void 0===S&&(S=e.getObjectPropValue(y,"ns")),void 0===h&&(h=e.getObjectPropValueExpression(y,"context")));const m=function(e,i){if(!e||0===e.length)return"";const s=new Set(i.extract.transKeepBasicHtmlNodesFor??["br","strong","i","p"]),r=e=>e&&"JSXText"===e.type&&/^\s*$/.test(e.value)&&e.value.includes("\n"),o=e=>e&&("JSXElement"===e.type||"JSXFragment"===e.type),p=(e,t)=>{for(let n=t;n<e.length;n++){const t=e[n];if(t&&("JSXText"!==t.type||!r(t)))return t}};function l(e,n,i=!1,a=!1){if(!e||!e.length)return;const c=a&&e.filter(e=>e&&"JSXElement"===e.type&&"p"===e.opening?.name?.value).length>1;let u=0,f=e.length-1;for(;u<=f&&r(e[u]);)u++;for(;f>=u&&r(e[f]);)f--;const y=u<=f?e.slice(u,f+1):[],d=y.some(e=>e&&("JSXElement"===e.type||"JSXFragment"===e.type));for(let e=0;e<y.length;e++){const u=y[e];if(u)if("JSXText"!==u.type){if("JSXExpressionContainer"===u.type){if(i&&!d&&u.expression){const e=u.expression.type;if("ObjectExpression"===e)continue;if(void 0!==t(u.expression))continue;if("Identifier"===e||"MemberExpression"===e||"CallExpression"===e)continue}const s=t(u.expression);if(void 0!==s){const t=/^\s*$/.test(s)&&!s.includes("\n"),i=y[e-1],l=y[e+1];if(t){const t=p(y,e+1);if(o(i)&&o(t));else{const t=y[e+2];if(l&&"JSXText"===l.type&&r(l)&&t&&("JSXElement"===t.type||"JSXFragment"===t.type)){const t=y[e-1],n=y[e-2];if(!t||"JSXText"!==t.type&&n&&"JSXExpressionContainer"===n.type)continue}if(i&&("JSXElement"===i.type||"JSXFragment"===i.type)&&l&&"JSXText"===l.type&&r(l))continue;const s=!l||"JSXText"===l.type&&!r(l);if(i&&"JSXText"===i.type&&s){const e=n[n.length-1];if(e&&"JSXText"===e.type){e.value=String(e.value)+u.expression.value;continue}}if(i&&("JSXElement"===i.type||"JSXFragment"===i.type)&&l&&"JSXText"===l.type&&r(l))continue}}}n.push(u);continue}if("JSXElement"===u.type){const e=u.opening&&u.opening.name&&"Identifier"===u.opening.name.type?u.opening.name.value:void 0;if(e&&s.has(e)){const i=u.opening&&Array.isArray(u.opening.attributes)&&u.opening.attributes.length>0,o=u.children||[],p=1===o.length&&("JSXText"===o[0]?.type||"JSXExpressionContainer"===o[0]?.type&&void 0!==t(o[0].expression)),f=!o.length,d=p;if(i&&!p)n.push(u),l(u.children||[],n,!0);else if(f)n.push(u);else if(!d){if((u.children||[]).some(e=>"JSXExpressionContainer"===e.type&&void 0===t(e.expression)))n.push(u),l(u.children||[],n,!0);else if("p"===e){const e=(o||[]).some(e=>{if(!e||"JSXElement"!==e.type)return!1;const n=e.opening&&e.opening.name&&"Identifier"===e.opening.name.type?e.opening.name.value:void 0,i=e.opening&&Array.isArray(e.opening.attributes)&&e.opening.attributes.length>0,r=e.children||[],o=1===r.length&&("JSXText"===r[0]?.type||"JSXExpressionContainer"===r[0]?.type&&void 0!==t(r[0].expression));return!(n&&s.has(n)&&!i&&(0===r.length||o))}),i=a&&y.some(e=>e&&e!==u&&"JSXText"===e.type&&!r(e));c||a&&e&&!i?(n.push(u),l(u.children||[],n,!0,!1)):l(u.children||[],n,!1,!1)}else l(u.children||[],n,!1,!1)}continue}n.push(u),l(u.children||[],n,!0);continue}"JSXFragment"!==u.type||l(u.children||[],n,i)}else{if(i&&!d)continue;if(i&&r(u))continue;if(r(u)){const t=y[e-1],i=y[e+1];if(t&&("JSXElement"===t.type||"JSXFragment"===t.type)&&i&&("JSXElement"===i.type||"JSXFragment"===i.type))continue;const s=n[n.length-1],r=y[e-1];if(s){if(r&&"JSXExpressionContainer"===r.type)continue;if("JSXText"===s.type&&r&&"JSXText"===r.type){s.value=String(s.value)+u.value;continue}}}if(i&&d&&0===e)continue;n.push(u)}}}const a=[];function c(e){if(!e||!e.length)return!1;let t=!1;for(const n of e)if(n)if("JSXElement"!==n.type){if("JSXExpressionContainer"===n.type&&-1!==a.indexOf(n))return t;if("JSXText"===n.type&&-1!==a.indexOf(n)){if(r(n))continue;if(!t)return!0;const i=e.indexOf(n);if(e.slice(i+1).some(e=>e&&"JSXElement"===e.type))return!0}}else t=!0;return!1}l(e,a,!1,!0);const u=new Set,f=e=>String(e).replace(/^\s*\n\s*/g,"").replace(/\s*\n\s*$/g,"");function y(e,i,o=!1){if(!e||0===e.length)return"";let p="";const l=e=>{if(!e)return-1;if(i&&i.has(e))return i.get(e);if(i)for(const[t,n]of i.entries())try{if(t&&e&&t.span&&e.span&&t.span.start===e.span.start&&t.span.end===e.span.end)return n}catch(e){}return a.indexOf(e)},d=t=>{if(!o)return a.indexOf(t);const n=e.indexOf(t);if(-1===n)return-1;let i=0;for(let t=0;t<n;t++){const n=e[t];n&&("JSXText"===n.type?r(n)||i++:"JSXExpressionContainer"===n.type?n.expression&&"JSXEmptyExpression"!==n.expression.type&&i++:"JSXElement"===n.type&&i++)}return i};for(let i=0;i<e.length;i++){const g=e[i];if(g){if("JSXText"===g.type){if(r(g))continue;const t=e[i+1],n=e[i-1];if(n&&"JSXElement"===n.type){const t="Identifier"===n.opening?.name?.type?n.opening.name.value:void 0,r=t&&s.has(t),o=0===(n.children||[]).length;if(r&&o&&/^\s*\n\s*/.test(g.value)){const e=g.value.replace(/^\s*\n\s*/,"");if(e){p+=e;continue}continue}if(!r&&/^\s*\n\s*/.test(g.value)){const t=g.value.replace(/^\s*\n\s*/,"");if(t){if(n&&"JSXElement"===n.type&&Array.isArray(n.children)&&0===n.children.length){p+=t;continue}const s=e[i-2];if(s&&"JSXText"===s.type){const e=s.value.replace(/\n\s*$/,""),n=/[A-Za-z0-9]$/.test(e),i=/^[A-Za-z0-9]/.test(t),r=/^[a-z]/.test(t);if(n&&i&&r){p+=t;continue}}p+=" "+t;continue}continue}}if(/\n\s*$/.test(g.value)&&t&&"JSXElement"===t.type){const n=g.value.replace(/\n\s*$/,"");if(n.trim()){const o="Identifier"===t.opening?.name?.type?t.opening.name.value:void 0,l=o&&s.has(o),a=(t.children||[]).length>0,c=/\s\n/.test(g.value),f=e[i+2],y=f&&"JSXText"===f.type&&!r(f)&&/[a-zA-Z0-9]/.test(f.value),d=!!(t.opening&&Array.isArray(t.opening.attributes)&&t.opening.attributes.length>0),x=/^\s/.test(n)&&!/^\n/.test(n),h=n.trim(),v=x?" "+h:h,S=/[A-Za-z0-9]$/.test(h),m=f&&"string"==typeof f.value&&/^[A-Za-z0-9]/.test(f.value.trim()),J=f&&"string"==typeof f.value&&/^[a-z]/.test(f.value.trim()),X=f&&"string"==typeof f.value&&/^\s/.test(f.value)&&!/^\n/.test(f.value),E=d&&a&&y&&!(S&&m&&J&&!c&&!x&&!X),$=f&&"string"==typeof f.value&&/^[,;:!?.]/.test(f.value.trim()),b=E&&!$;S&&m&&J&&!c&&!x&&!X&&u.add(t),p+=c||l&&a||!l&&y&&x||b?v+" ":v;continue}}p+=g.value;continue}if("JSXExpressionContainer"===g.type){const e=g.expression;if(!e)continue;const i=t(e);if(void 0!==i)p+=i;else if("Identifier"===e.type)p+=`{{${e.value}}}`;else if("TsAsExpression"===e.type&&"ObjectExpression"===e.expression?.type){const t=e.expression,n=t.properties.filter(e=>"KeyValueProperty"===e.type&&e.key&&"Identifier"===e.key.type).map(e=>e.key.value);if(n.length>0)p+=n.map(e=>`{{${e}}}`).join("");else{const e=t.properties[0];if(!e||"Identifier"!==e.type)throw new Error("Unrecognized expression in JSX placeholder");p+=`{{${e.value}}}`}}else if("ObjectExpression"===e.type){const t=e.properties[0];if(t&&"KeyValueProperty"===t.type&&t.key&&"Identifier"===t.key.type)p+=`{{${t.key.value}}}`;else{if(!t||"Identifier"!==t.type)throw new Error("Unrecognized expression in JSX placeholder");p+=`{{${t.value}}}`}}else if("MemberExpression"===e.type&&e.property&&"Identifier"===e.property.type)p+=`{{${e.property.value}}}`;else if("CallExpression"===e.type&&"Identifier"===e.callee?.type)p+=`{{${e.callee.value}}}`;else if("ConditionalExpression"===e.type){const t=n(e.consequent),i=n(e.alternate);p+=void 0!==t&&void 0!==i?t.length>=i.length?t:i:void 0!==t?t:void 0!==i?i:""}else if("JSXEmptyExpression"!==e.type)throw new Error(`Unrecognized expression in JSX placeholder: ${e.type}`);continue}if("JSXElement"===g.type){const n=o?d(g):void 0;let u;if(g.opening&&g.opening.name&&"Identifier"===g.opening.name.type&&(u=g.opening.name.value),u&&s.has(u)){const d=g.opening&&Array.isArray(g.opening.attributes)&&g.opening.attributes.length>0,x=g.children||[],h=x.length>0,v=1===x.length&&("JSXText"===x[0]?.type||"JSXExpressionContainer"===x[0]?.type&&void 0!==t(x[0].expression)),S="p"===u;let m=0;if(S&&o&&(m=e.filter(e=>e&&"JSXElement"===e.type&&"p"===e.opening?.name?.value).length),!h||v){const t=v?y(x,void 0):"";if(""!==String(t).trim())if(s.has(u)&&"p"!==u)p+=`<${u}>${f(t)}</${u}>`;else if(S&&o&&m>1)p+=`<${u}>${f(t)}</${u}>`;else if(S){const e=o&&void 0!==n?n:a.indexOf(g);p+=`<${e}>${f(t)}</${e}>`}else{const e=o&&void 0!==n?n:a.indexOf(g);p+=`<${e}>${f(t)}</${e}>`}else{const t=e[i-1];t&&"JSXText"===t.type&&/\n\s*$/.test(t.value)&&(p=p.replace(/\s+$/,"")),p+=`<${u} />`}}else if(d&&!v){const e=x,i=o&&void 0!==n?n:l(g);if(c(e)){const n=new Map;let r=0;for(const i of e)if(i&&"JSXElement"===i.type){const e=i.opening&&i.opening.name&&"Identifier"===i.opening.name.type?i.opening.name.value:void 0;if(e&&s.has(e)){const e=i.opening&&Array.isArray(i.opening.attributes)&&i.opening.attributes.length>0,s=i.children||[],o=1===s.length&&("JSXText"===s[0]?.type||"JSXExpressionContainer"===s[0]?.type&&void 0!==t(s[0].expression));!e&&(!s.length||o)||n.set(i,r++)}else n.set(i,r++)}const o=y(e,n.size?n:void 0);p+=`<${i}>${f(o)}</${i}>`}else{const e=new Map;let n=0;for(const i of x)if(i&&"JSXElement"===i.type){const r=i.opening&&i.opening.name&&"Identifier"===i.opening.name.type?i.opening.name.value:void 0;if(r&&s.has(r)){const s=i.opening&&Array.isArray(i.opening.attributes)&&i.opening.attributes.length>0,r=i.children||[],o=1===r.length&&("JSXText"===r[0]?.type||"JSXExpressionContainer"===r[0]?.type&&void 0!==t(r[0].expression));!s&&(!r.length||o)||e.set(i,n++)}else e.set(i,n++)}const r=y(x,e.size?e:void 0);p+=`<${i}>${f(r)}</${i}>`}}else{const e=a.indexOf(g);if(-1!==e){const i=void 0!==n?n:e;if((()=>{let e=!1;for(const t of x)if(t)if("JSXElement"!==t.type){if("JSXExpressionContainer"===t.type&&-1!==a.indexOf(t))return e;if("JSXText"===t.type&&-1!==a.indexOf(t)){if(r(t))continue;if(!e)return!0;if(x.slice(x.indexOf(t)+1).some(e=>e&&"JSXElement"===e.type))return!0}}else e=!0;return!1})()){if(0===i){const e=y(x,void 0,!1);p+=`<${i}>${f(e)}</${i}>`;continue}const e=new Map;for(const e of x)if(e&&"JSXElement"===e.type){const n=e.opening&&e.opening.name&&"Identifier"===e.opening.name.type?e.opening.name.value:void 0;if(n&&s.has(n)){const n=e.opening&&Array.isArray(e.opening.attributes)&&e.opening.attributes.length>0,s=e.children||[],r=1===s.length&&("JSXText"===s[0]?.type||"JSXExpressionContainer"===s[0]?.type&&void 0!==t(s[0].expression));if(!(!n&&(!s.length||r))){const t=y(e.children,void 0,!1);p+=`<${i}>${f(t)}</${i}>`}}else{const t=y(e.children,void 0,!1);p+=`<${i}>${f(t)}</${i}>`}}const n=y(x,e.size?e:void 0,!1);p+=`<${i}>${f(n)}</${i}>`;continue}const o=new Map;let l=0;for(const e of x)if(e&&"JSXElement"===e.type){const n=e.opening&&e.opening.name&&"Identifier"===e.opening.name.type?e.opening.name.value:void 0;if(n&&s.has(n)){const n=e.opening&&Array.isArray(e.opening.attributes)&&e.opening.attributes.length>0,i=e.children||[],s=1===i.length&&("JSXText"===i[0]?.type||"JSXExpressionContainer"===i[0]?.type&&void 0!==t(i[0].expression));!n&&(!i.length||s)||o.set(e,l++)}else o.set(e,l++)}const c=y(x,o.size>0?o:void 0,!1);p+=`<${i}>${f(c)}</${i}>`}else{const e=y(x,void 0,!1);p+=`<${u}>${f(e)}</${u}>`}}}else{const e=g.children||[];if(e.some(e=>e&&("JSXText"===e.type||"JSXExpressionContainer"===e.type)&&-1!==a.indexOf(e))){const t=a.indexOf(g),n=y(e,void 0);p+=`<${t}>${f(n)}</${t}>`}else{const t=new Map,n=l(g);let i=0;for(const n of e)if(n&&"JSXElement"===n.type){const e=n.opening&&n.opening.name&&"Identifier"===n.opening.name.type?n.opening.name.value:void 0;if(e&&s.has(e)){const e=n.opening&&Array.isArray(n.opening.attributes)&&n.opening.attributes.length>0,s=n.children||[],r=1===s.length&&"JSXText"===s[0]?.type;!e&&(!s.length||r)||t.set(n,i++)}else t.set(n,i++)}const r=y(e,t.size?t:void 0);p+=`<${n}>${f(r)}</${n}>`}}continue}"JSXFragment"!==g.type||(p+=y(g.children||[]))}}return p}const d=y(e,void 0,!0),g=String(d).replace(/<br \/>\s*\n\s*/g,"<br />"),x=String(g),h=new Set;if(u&&u.size>0)for(let e=0;e<a.length;e++)u.has(a[e])&&h.add(e);let v=String(x);if(h&&h.size>0)for(const e of h)try{v=v.replace(new RegExp("\\s+<"+e+">","g"),"<"+e+">"),v=v.replace(new RegExp("<\\/"+e+">\\s+","g"),"</"+e+">")}catch(e){}v=v.replace(/<\/(\d+)>\s*\n\s*(\S)/g,(e,t,n)=>{const i=Number(t);return h.has(i)?`</${t}>${n}`:`</${t}> ${n}`}),v=v.replace(/(\S)\s*\n\s*<(\d+)/g,(e,t,n)=>{const i=Number(n);return h.has(i)?`${t}<${n}`:`${t} <${n}`}),v=v.replace(/\s*\n\s*/g," "),v=v.replace(/\s+/g," "),v=v.replace(/\s+([,;:!?.])/g,"$1");const S=v.trim();let m=String(S);if(h&&h.size>0)for(const e of h)try{m=m.replace(new RegExp("[\\s\\u00A0]+<"+e+">","g"),"<"+e+">"),m=m.replace(new RegExp("<\\/"+e+">[\\s\\u00A0]+","g"),"</"+e+">")}catch(e){}try{for(let e=0;e<a.length;e++){const t=a[e];if(!t||"JSXElement"!==t.type)continue;const n=a[e-1],i=a[e+1];if(!n||!i)continue;if("JSXText"!==n.type||"JSXText"!==i.type)continue;const s=String(n.value),r=String(i.value),o=s.replace(/\n\s*$/,""),p=/[A-Za-z0-9]$/.test(o),l=/^[A-Za-z0-9]/.test(r.trim()),c=/^[a-z]/.test(r.trim()),u=/\s\n/.test(s),f=r&&/^\s/.test(r)&&!/^\n/.test(r);if(p&&l&&c&&!u&&!f){const t=e;m=m.replace(new RegExp("\\s+<"+t+">","g"),"<"+t+">")}}}catch(e){}function J(e){if(!e||!e.includes("<"))return e;function t(e){const t=[],n=[];let i=0;const s=/<\/?(\d+)>|<[^>]+>/g;let r;for(;r=s.exec(e);){const o=r[0],p=r.index;if(p>i){const s={type:"text",text:e.slice(i,p)};n.length?n[n.length-1].node.children.push(s):t.push(s)}const l=/^<\/(\d+)>$/.exec(o),a=/^<(\d+)>$/.exec(o);if(a){const e=Number(a[1]),i={type:"ph",idx:e,children:[]};n.length?n[n.length-1].node.children.push(i):t.push(i),n.push({node:i,idx:e})}else if(l)n.length&&n.pop();else{const e={type:"text",text:o};n.length?n[n.length-1].node.children.push(e):t.push(e)}i=s.lastIndex}if(i<e.length){const s={type:"text",text:e.slice(i)};n.length?n[n.length-1].node.children.push(s):t.push(s)}return t}function n(e,t=null){let i="";for(const o of e)if("text"===o.type)i+=o.text;else{const e=o.children.filter(e=>"ph"===e.type);let p;if("number"==typeof o.idx){const t=a[o.idx];if(t&&Array.isArray(t.children)){const n=new Map;let i=0;for(const e of t.children){const t=a.indexOf(e);if("JSXText"===e.type){if(r(e))continue;-1!==t&&n.set(t,i),i++}else"JSXElement"===e.type?(-1!==t&&n.set(t,i),i++):"JSXExpressionContainer"===e.type&&-1!==t&&(n.set(t,i),i++)}e.every(e=>n.has(e.idx))&&(p=n)}}if(!p){const n=e.map(e=>e.idx);if(n.length<=1||n.every((e,t)=>0===t||e===n[t-1]+1)){p=new Map;let n=0;try{const i=a[o.idx];if(i&&i.span){const r=i.span.start,p=i.span.end;let l=0,c=-1;for(let e=o.idx+1;e<a.length;e++){const t=a[e];if(t&&t.span&&(t.span.start>=r&&t.span.end<=p&&"JSXElement"===t.type)){c=e;break}}if(-1!==c)for(let e=o.idx+1;e<c;e++){const t=a[e];t&&t.span&&(t.span.start>=r&&t.span.end<=p&&("JSXText"!==t.type&&"JSXExpressionContainer"!==t.type||l++))}else for(let e=o.idx+1;e<a.length;e++){const t=a[e];t&&t.span&&(t.span.start>=r&&t.span.end<=p&&("JSXText"!==t.type&&"JSXExpressionContainer"!==t.type||l++))}const u=i?.opening?.name?.value,f=u&&s.has(u),y=null===t;1===e.length&&(n=Math.max(1,l+1),!y||f||0!==e[0].idx||"a"!==u&&"p"!==u||(n=0))}}catch(e){}for(const t of e)p.has(t.idx)||p.set(t.idx,n++)}}const l=o.children.map(e=>{if("text"===e.type)return e.text;const t=e.idx,i=p&&p.has(t)?p.get(t):t;return`<${i}>${n(e.children,i)}</${i}>`}).join("");i+=`<${o.idx}>${l}</${o.idx}>`}return i}try{const i=t(e);return n(i)}catch(t){return e}}return m=J(m),m.trim()}(s.children,r);let J;const X="JSXAttribute"===p?.type?i(p):void 0;if(void 0!==X)J=X;else{const e=r.extract.defaultValue;J="string"==typeof e?e:""}let E,$;if("JSXAttribute"===o?.type){if("StringLiteral"===o.value?.type){if(E=o.value,$=E.value,!$||""===$.trim())return null;if(S&&"StringLiteral"===E.type){const e=r.extract.nsSeparator??":",t=E.value;if(e&&t.startsWith(`${S}${e}`)){if($=t.slice(`${S}${e}`.length),!$||""===$.trim())return null;E={...E,value:$}}}}else"JSXExpressionContainer"===o.value?.type&&"JSXEmptyExpression"!==o.value.expression.type&&(E=o.value.expression);if(!E)return null}return p||!$||m.trim()?!p&&m.trim()&&(J=m):J=$,{keyExpression:E,serializedChildren:m,ns:S,defaultValue:J,hasCount:u,isOrdinal:g,contextExpression:h,optionsNode:y,explicitDefault:void 0!==X||(e=>{if(!e||!Array.isArray(e.properties))return!1;for(const t of e.properties)if(t&&"KeyValueProperty"===t.type&&t.key){const e="Identifier"===t.key.type&&t.key.value||"StringLiteral"===t.key.type&&t.key.value;if("string"==typeof e&&e.startsWith("defaultValue"))return!0}return!1})(y)}};
|
package/dist/esm/cli.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import{Command as o}from"commander";import e from"chokidar";import{glob as t}from"glob";import{minimatch as n}from"minimatch";import i from"chalk";import{ensureConfig as r,loadConfig as a}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"@croct/json5-parser";import{runTypesGenerator as l}from"./types-generator.js";import{runSyncer as p}from"./syncer.js";import{runMigrator as d}from"./migrator.js";import{runInit as f}from"./init.js";import{runLinterCli as m}from"./linter.js";import{runStatus as u}from"./status.js";import{runLocizeSync as y,runLocizeDownload as g,runLocizeMigrate as h}from"./locize.js";import{runRenameKey as w}from"./rename-key.js";const x=new o;x.name("i18next-cli").description("A unified, high-performance i18next CLI.").version("1.33.
|
|
2
|
+
import{Command as o}from"commander";import e from"chokidar";import{glob as t}from"glob";import{minimatch as n}from"minimatch";import i from"chalk";import{ensureConfig as r,loadConfig as a}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"@croct/json5-parser";import{runTypesGenerator as l}from"./types-generator.js";import{runSyncer as p}from"./syncer.js";import{runMigrator as d}from"./migrator.js";import{runInit as f}from"./init.js";import{runLinterCli as m}from"./linter.js";import{runStatus as u}from"./status.js";import{runLocizeSync as y,runLocizeDownload as g,runLocizeMigrate as h}from"./locize.js";import{runRenameKey as w}from"./rename-key.js";const x=new o;x.name("i18next-cli").description("A unified, high-performance i18next CLI.").version("1.33.2"),x.option("-c, --config <path>","Path to i18next-cli config file (overrides detection)"),x.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.").option("--sync-all","Sync primary language values with default values from code AND clear synced keys in all other locales.").action(async o=>{try{const t=x.opts().config,i=await r(t),a=async()=>{const e=!!o.syncPrimary||!!o.syncAll,t=await s(i,{isWatchMode:!!o.watch,isDryRun:!!o.dryRun,syncPrimaryWithDefaults:e,syncAll:!!o.syncAll});return o.ci&&!t?(console.log("✅ No files were updated."),process.exit(0)):o.ci&&t&&(console.error("❌ Some files were updated. This should not happen in CI mode."),process.exit(1)),t};if(await a(),o.watch){console.log("\nWatching for changes...");const o=await z(i.extract.input),t=j(i.extract.ignore),r=v(i.extract.output),c=[...t,...r].filter(Boolean),s=o.filter(o=>!c.some(e=>n(o,e,{dot:!0})));e.watch(s,{ignored:/node_modules/,persistent:!0}).on("change",o=>{console.log(`\nFile changed: ${o}`),a()})}}catch(o){console.error("Error running extractor:",o),process.exit(1)}}),x.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(o,e)=>{const t=x.opts().config;let n=await a(t);if(!n){console.log(i.blue("No config file found. Attempting to detect project structure..."));const o=await c();o||(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=o}await u(n,{detail:o,namespace:e.namespace})}),x.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 o=>{const t=x.opts().config,i=await r(t),a=()=>l(i);if(await a(),o.watch){console.log("\nWatching for changes...");const o=await z(i.types?.input||[]),t=[...j(i.extract?.ignore)].filter(Boolean),r=o.filter(o=>!t.some(e=>n(o,e,{dot:!0})));e.watch(r,{persistent:!0}).on("change",o=>{console.log(`\nFile changed: ${o}`),a()})}}),x.command("sync").description("Synchronize secondary language files with the primary language file.").action(async()=>{const o=x.opts().config,e=await r(o);await p(e)}),x.command("migrate-config [configPath]").description("Migrate a legacy i18next-parser.config.js to the new format.").action(async o=>{await d(o)}),x.command("init").description("Create a new i18next.config.ts/js file with an interactive setup wizard.").action(f),x.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 o=>{const t=x.opts().config,r=async()=>{let o=await a(t);if(!o){console.log(i.blue("No config file found. Attempting to detect project structure..."));const e=await c();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!")),o=e}await m(o)};if(await r(),o.watch){console.log("\nWatching for changes...");const o=await a(t);if(o?.extract?.input){const t=await z(o.extract.input),i=[...j(o.extract.ignore),...v(o.extract.output)].filter(Boolean),a=t.filter(o=>!i.some(e=>n(o,e,{dot:!0})));e.watch(a,{ignored:/node_modules/,persistent:!0}).on("change",o=>{console.log(`\nFile changed: ${o}`),r()})}}}),x.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.").option("--cdn-type <standard|pro>","Specify the cdn endpoint that should be used (depends on which cdn type you've in your locize project)").action(async o=>{const e=x.opts().config,t=await r(e);await y(t,o)}),x.command("locize-download").description("Download all translations from your locize project.").option("--cdn-type <standard|pro>","Specify the cdn endpoint that should be used (depends on which cdn type you've in your locize project)").action(async o=>{const e=x.opts().config,t=await r(e);await g(t,o)}),x.command("locize-migrate").description("Migrate local translation files to a new locize project.").option("--cdn-type <standard|pro>","Specify the cdn endpoint that should be used (depends on which cdn type you've in your locize project)").action(async o=>{const e=x.opts().config,t=await r(e);await h(t,o)}),x.command("rename-key <oldKey> <newKey>").description("Rename a translation key across all source files and translation files.").option("--dry-run","Preview changes without modifying files").action(async(o,e,t)=>{try{const n=x.opts().config,a=await r(n),c=await w(a,o,e,t);c.success||(c.conflicts&&(console.error(i.red("\n❌ Conflicts detected:")),c.conflicts.forEach(o=>console.error(` - ${o}`))),c.error&&console.error(i.red(`\n❌ ${c.error}`)),process.exit(1));0===c.sourceFiles.reduce((o,e)=>o+e.changes,0)&&console.log(i.yellow(`\n⚠️ No usages found for "${o}"`))}catch(o){console.error(i.red("Error renaming key:"),o),process.exit(1)}}),x.parse(process.argv);const j=o=>Array.isArray(o)?o:o?[o]:[],v=o=>o&&"string"==typeof o?[o.replace(/\{\{[^}]+\}\}/g,"*")]:[],z=async(o=[])=>{const e=j(o),n=await Promise.all(e.map(o=>t(o||"",{nodir:!0})));return Array.from(new Set(n.flat()))};export{x as program};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import t from"ora";import a from"chalk";import{parse as e}from"@swc/core";import{mkdir as o,writeFile as r,readFile as n}from"node:fs/promises";import{dirname as s,extname as i}from"node:path";import{findKeys as c}from"./key-finder.js";import{getTranslations as l}from"./translation-manager.js";import{validateExtractorConfig as m,ExtractorError as p}from"../../utils/validation.js";import{extractKeysFromComments as f}from"../parsers/comment-parser.js";import{ConsoleLogger as
|
|
1
|
+
import t from"ora";import a from"chalk";import{parse as e}from"@swc/core";import{mkdir as o,writeFile as r,readFile as n}from"node:fs/promises";import{dirname as s,extname as i}from"node:path";import{findKeys as c}from"./key-finder.js";import{getTranslations as l}from"./translation-manager.js";import{validateExtractorConfig as m,ExtractorError as p}from"../../utils/validation.js";import{extractKeysFromComments as f}from"../parsers/comment-parser.js";import{ConsoleLogger as y}from"../../utils/logger.js";import{loadRawJson5Content as u,serializeTranslationFile as g}from"../../utils/file-utils.js";import{shouldShowFunnel as d,recordFunnelShown as w}from"../../utils/funnel-msg-tracker.js";async function x(e,{isWatchMode:n=!1,isDryRun:i=!1,syncPrimaryWithDefaults:p=!1,syncAll:f=!1}={},x=new y){e.extract.primaryLanguage||=e.locales[0]||"en",e.extract.secondaryLanguages||=e.locales.filter(t=>t!==e?.extract?.primaryLanguage),e.extract.functions||=["t","*.t"],e.extract.transComponents||=["Trans"],m(e);const h=e.plugins||[],j=t("Running i18next key extractor...\n").start();try{const{allKeys:t,objectKeys:n}=await c(e,x);j.text=`Found ${t.size} unique keys. Updating translation files...`;const m=await l(t,n,e,{syncPrimaryWithDefaults:p,syncAll:f});let y=!1;for(const t of m)if(t.updated&&(y=!0,!i)){const n=e.extract.outputFormat??(t.path.endsWith(".json5")?"json5":"json"),i="json5"===n?await u(t.path)??void 0:void 0,c=g(t.newTranslations,n,e.extract.indentation,i);await o(s(t.path),{recursive:!0}),await r(t.path,c),x.info(a.green(`Updated: ${t.path}`))}if(h.length>0){j.text="Running post-extraction plugins...";for(const t of h)await(t.afterSync?.(m,e))}return j.succeed(a.bold("Extraction complete!")),y&&await async function(){if(!await d("extract"))return;return console.log(a.yellow.bold("\n💡 Tip: Tired of running the extractor manually?")),console.log(' Discover a real-time "push" workflow with `saveMissing` and Locize AI,'),console.log(" where keys are created and translated automatically as you code."),console.log(` Learn more: ${a.cyan("https://www.locize.com/blog/i18next-savemissing-ai-automation")}`),console.log(` Watch the video: ${a.cyan("https://youtu.be/joPsZghT3wM")}`),w("extract")}(),y}catch(t){throw j.fail(a.red("Extraction failed.")),t}}async function h(t,o,r,s,c,l=new y){try{let a=await n(t,"utf-8");for(const e of o)try{const o=await(e.onLoad?.(a,t));void 0!==o&&(a=o)}catch(t){l.warn(`Plugin ${e.name} onLoad failed:`,t)}const m=i(t).toLowerCase(),y=".ts"===m||".tsx"===m||".mts"===m||".cts"===m,u=".tsx"===m,g=".jsx"===m;let d;try{d=await e(a,{syntax:y?"typescript":"ecmascript",tsx:u,jsx:g,decorators:!0,dynamicImport:!0,comments:!0})}catch(o){if(".ts"!==m||u){if(".js"!==m||g)throw new p("Failed to process file",t,o);try{d=await e(a,{syntax:"ecmascript",jsx:!0,decorators:!0,dynamicImport:!0,comments:!0}),l.info?.(`Parsed ${t} using JSX fallback`)}catch(a){throw new p("Failed to process file",t,a)}}else try{d=await e(a,{syntax:"typescript",tsx:!0,decorators:!0,dynamicImport:!0,comments:!0}),l.info?.(`Parsed ${t} using TSX fallback`)}catch(a){throw new p("Failed to process file",t,a)}}s.getVarFromScope=r.getVarFromScope.bind(r),r.setCurrentFile(t,a),r.visit(d),!1!==c.extract.extractFromComments&&f(a,s,c,r.getVarFromScope.bind(r))}catch(e){l.warn(`${a.yellow("Skipping file due to error:")} ${t}`);const o=e,r="string"==typeof o?.message&&o.message.trim().length>0?o.message:("string"==typeof o?o:"")||o?.toString?.()||"Unknown error";l.warn(` ${r}`),o?.message&&""!==String(o.message).trim()||!o?.stack||l.warn(` ${String(o.stack)}`)}}async function j(t,{syncPrimaryWithDefaults:a=!1}={}){t.extract.primaryLanguage||=t.locales[0]||"en",t.extract.secondaryLanguages||=t.locales.filter(a=>a!==t?.extract?.primaryLanguage),t.extract.functions||=["t","*.t"],t.extract.transComponents||=["Trans"];const{allKeys:e,objectKeys:o}=await c(t);return l(e,o,t,{syncPrimaryWithDefaults:a})}export{j as extract,h as processFile,x as runExtractor};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{resolve as t,basename as e,extname as n}from"node:path";import{glob as r}from"glob";import{getNestedKeys as s,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";const f=[" ",",","?","!",";"];function u(t){const e=`^${t.replace(/[.+?^${}()|[\]\\]/g,"\\$&").replace(/\*/g,".*")}$`;return new RegExp(e)}function p(t,e,n,r){if(0===e.size)return!1;let s=t;const o=["zero","one","two","few","many","other"];for(const t of o){if(s.endsWith(`${n}${t}`)){s=s.slice(0,-(n.length+t.length));break}if(s.endsWith(`${n}ordinal${n}${t}`)){s=s.slice(0,-(n.length+7+n.length+t.length));break}}const i=s.split(r);if(i.length>1)for(let t=1;t<i.length;t++){const n=i.slice(0,-t).join(r);if(e.has(n))return!0}return!!e.has(s)}function d(t,e,n){if(!n)return!0;let r=!n.test(t);if(!r){const s=t.indexOf(e);s>0&&!n.test(t.substring(0,s))&&(r=!0)}return r}function g(t,e,n){if("object"!=typeof t||null===t||Array.isArray(t))return t;const r={},s=e?.extract?.pluralSeparator??"_",o=["zero","one","two","few","many","other"],i=o.map(t=>`ordinal${s}${t}`),a=Object.keys(t).sort((t,e)=>{const r=t=>{for(const e of i)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 o)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}},a=r(t),l=r(e);if(a.isPlural&&l.isPlural){const t=n?n(a.base,l.base):a.base.localeCompare(l.base,void 0,{sensitivity:"base"});if(0!==t)return t;if(a.isOrdinal!==l.isOrdinal)return a.isOrdinal?1:-1;const e=a.isOrdinal?i:o,r=e.indexOf(a.form),s=e.indexOf(l.form);return-1!==r&&-1!==s?r-s:a.form.localeCompare(l.form)}if(n)return n(t,e);const c=t.localeCompare(e,void 0,{sensitivity:"base"});return 0===c?t.localeCompare(e,void 0,{sensitivity:"case"}):c});for(const s of a)r[s]=g(t[s],e,n);return r}function h(t,e,n,r,a,l=[],h=new Set,y=!1,x=!1){const{keySeparator
|
|
1
|
+
import{resolve as t,basename as e,extname as n}from"node:path";import{glob as r}from"glob";import{getNestedKeys as s,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";const f=[" ",",","?","!",";"];function u(t){const e=`^${t.replace(/[.+?^${}()|[\]\\]/g,"\\$&").replace(/\*/g,".*")}$`;return new RegExp(e)}function p(t,e,n,r){if(0===e.size)return!1;let s=t;const o=["zero","one","two","few","many","other"];for(const t of o){if(s.endsWith(`${n}${t}`)){s=s.slice(0,-(n.length+t.length));break}if(s.endsWith(`${n}ordinal${n}${t}`)){s=s.slice(0,-(n.length+7+n.length+t.length));break}}const i=s.split(r);if(i.length>1)for(let t=1;t<i.length;t++){const n=i.slice(0,-t).join(r);if(e.has(n))return!0}return!!e.has(s)}function d(t,e,n){if(!n)return!0;let r=!n.test(t);if(!r){const s=t.indexOf(e);s>0&&!n.test(t.substring(0,s))&&(r=!0)}return r}function g(t,e,n){if("object"!=typeof t||null===t||Array.isArray(t))return t;const r={},s=e?.extract?.pluralSeparator??"_",o=["zero","one","two","few","many","other"],i=o.map(t=>`ordinal${s}${t}`),a=Object.keys(t).sort((t,e)=>{const r=t=>{for(const e of i)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 o)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}},a=r(t),l=r(e);if(a.isPlural&&l.isPlural){const t=n?n(a.base,l.base):a.base.localeCompare(l.base,void 0,{sensitivity:"base"});if(0!==t)return t;if(a.isOrdinal!==l.isOrdinal)return a.isOrdinal?1:-1;const e=a.isOrdinal?i:o,r=e.indexOf(a.form),s=e.indexOf(l.form);return-1!==r&&-1!==s?r-s:a.form.localeCompare(l.form)}if(n)return n(t,e);const c=t.localeCompare(e,void 0,{sensitivity:"base"});return 0===c?t.localeCompare(e,void 0,{sensitivity:"case"}):c});for(const s of a)r[s]=g(t[s],e,n);return r}function h(t,e,n,r,a,l=[],h=new Set,y=!1,x=!1){const{keySeparator:$=".",sort:m=!0,removeUnusedKeys:S=!0,primaryLanguage:O,defaultValue:w="",pluralSeparator:k="_",contextSeparator:v="_",preserveContextVariants:b=!1}=n.extract,j="string"==typeof n.extract.nsSeparator?n.extract.nsSeparator:":",N=n.extract.defaultValue,W=(t,e,n)=>{if(n)return!1;if(null==e)return!0;const r=String(e);if(r===t)return!0;if(j&&a&&r===`${a}${j}${t}`)return!0;if("string"==typeof $&&$.length>0&&t.endsWith(`${$}${r}`))return!0;if(r&&t!==r){if(t.startsWith(r+k))return!0;if(t.startsWith(r+v))return!0}return!1},C=f.filter(t=>j.indexOf(t)<0&&("string"!=typeof $||$.indexOf(t)<0)),P=C.length>0?new RegExp(`(${C.map(t=>"?"===t?"\\?":t).join("|")})`):null,_=new Set;if(b)for(const{keyAcceptingContext:e}of t)e&&_.add(e);const E=new Set;let A=[],R=[];try{const t=new Intl.PluralRules(r,{type:"cardinal"}),e=new Intl.PluralRules(r,{type:"ordinal"});A=t.resolvedOptions().pluralCategories,R=e.resolvedOptions().pluralCategories,A.forEach(t=>E.add(t)),e.resolvedOptions().pluralCategories.forEach(t=>E.add(`ordinal_${t}`))}catch(t){const e=O||"en",n=new Intl.PluralRules(e,{type:"cardinal"}),r=new Intl.PluralRules(e,{type:"ordinal"});A=n.resolvedOptions().pluralCategories,R=r.resolvedOptions().pluralCategories,A.forEach(t=>E.add(t)),r.resolvedOptions().pluralCategories.forEach(t=>E.add(`ordinal_${t}`))}const I=n.extract.preservePatterns||[],J=t=>{if(l.some(e=>e.test(t)))return!0;for(const e of I)if("string"==typeof e){if(e.endsWith(`${j}*`)){const t=e.slice(0,-(j.length+1));if("*"===t||a&&t===a)return!0}if(e.includes(j)&&a){const[n,r]=e.split(j);if(n===a){if(u(r).test(t))return!0}}}return!1},z=t.filter(({key:t,hasCount:e,isOrdinal:n})=>{if((t=>{if(l.some(e=>e.test(t)))return!0;for(const t of I)if("string"==typeof t&&t.endsWith(`${j}*`)){const e=t.slice(0,-(j.length+1));if("*"===e||a&&e===a)return!0}return!1})(t))return!1;if(!e)return!0;const r=t.split(k);if(e&&1===r.length)return!0;if(1===A.length&&"other"===A[0]&&1===r.length)return!0;if(n&&r.includes("ordinal")){const t=r[r.length-1];return E.has(`ordinal_${t}`)}if(e){const t=r[r.length-1];return E.has(t)}return!0}),K=new Set;for(const t of z)if(t.isExpandedPlural){const e=String(t.key).split(k);e.length>=3&&"ordinal"===e[e.length-2]?K.add(e.slice(0,-2).join(k)):K.add(e.slice(0,-1).join(k))}let L=S?{}:JSON.parse(JSON.stringify(e));const T=s(e,$??".");for(const t of T){const n=J(t),r=!n&&p(t,_,k,v);if(n||b&&r){const n=o(e,t,$??".");i(L,t,n,$??".")}}if(S){const t=s(e,$??".");for(const n of t){const t=n.split(k);if("zero"===t[t.length-1]){const r=t.slice(0,-1).join(k);if(z.some(({key:t})=>t.split(k).slice(0,-1).join(k)===r)){const t=o(e,n,$??".");i(L,n,t,$??".")}}}}for(const{key:t,defaultValue:s,explicitDefault:l,hasCount:f,isExpandedPlural:u,isOrdinal:p}of z){if(f&&!u){const e=String(t).split(k);let n=t;if(e.length>=3&&"ordinal"===e[e.length-2]?n=e.slice(0,-2).join(k):e.length>=2&&(n=e.slice(0,-1).join(k)),K.has(n))continue}if(f&&!u){if(1===String(t).split(k).length&&r!==O){const l=t;if(K.has(l));else{const t=p?R:A;for(const f of t){const t=p?`${l}${k}ordinal${k}${f}`:`${l}${k}${f}`,u=!t.startsWith("<")&&($??"."),d=o(e,t,u);if(void 0===d){let e;e="string"==typeof s?s:c(w,String(l),a||n?.extract?.defaultNS||"translation",r,s),i(L,t,e,u)}else i(L,t,d,u)}}continue}}let g=!t.startsWith("<")&&($??".");g&&"string"==typeof g&&(d(t,g,P)||(g=!1));const m=o(e,t,g),S=!1===$||!z.some(e=>e.key!==t&&e.key.startsWith(`${t}${$}`)),b="object"==typeof m&&null!==m&&(h.has(t)||!s||s===t),C="object"==typeof m&&null!==m&&S&&!h.has(t)&&!b;if(b){i(L,t,m,g);continue}let _;if(void 0===m||C)if(r===O)if(y){const e=W(t,s,l);_=s&&!e?s:c(w,t,a||n?.extract?.defaultNS||"translation",r,s)}else{_=W(t,s,l)&&void 0!==N?c(N,t,a||n?.extract?.defaultNS||"translation",r,s):s||t}else _=c(w,t,a||n?.extract?.defaultNS||"translation",r,s);else if(r===O&&y){const e=s&&(s===t||j&&a&&s===`${a}${j}${t}`||t!==s&&(t.startsWith(s+k)||t.startsWith(s+v)));_=(t.includes(k)||t.includes(v))&&!l?m:s&&!e?c(s,t,a||n?.extract?.defaultNS||"translation",r,s):m}else _=x&&r!==O&&l?c(w,t,a||n?.extract?.defaultNS||"translation",r,s):m;i(L,t,_,g)}if(!0===m)return g(L,n);if("function"==typeof m){const e={},r=Object.keys(L),s=new Map;for(const e of t)if(s.set(String(e.key),e),$){const t=String(e.key).split($)[0];s.has(t)||s.set(t,e)}const o=(t,e)=>{const n=s.get(t),r=s.get(e);if(n&&r)return m(n,r);return m({key:t},{key:e})};r.sort(o);for(const t of r)e[t]=g(L[t],n,o);L=e}return L}async function y(s,o,i,{syncPrimaryWithDefaults:c=!1,syncAll:p=!1}={}){i.extract.primaryLanguage||=i.locales[0]||"en",i.extract.secondaryLanguages||=i.locales.filter(t=>t!==i?.extract?.primaryLanguage);const d=[...i.extract.preservePatterns||[]],g=i.extract.indentation??2;for(const t of o)d.push(`${t}.*`);const y=d.map(u),x="__no_namespace__",$=new Map,m="string"==typeof i.extract.nsSeparator?i.extract.nsSeparator:":",S=new RegExp(`(${f.map(t=>"?"===t?"\\?":t).join("|")})`);for(const t of s.values()){let e=t.ns,n=t.key;e&&S.test(e)&&(n=`${e}${m}${n}`,e=void 0);const r=t.nsIsImplicit&&!1===i.extract.defaultNS?x:String(e??i.extract.defaultNS??"translation");$.has(r)||$.set(r,[]),e!==t.ns||n!==t.key?$.get(r).push({...t,ns:e,key:n}):$.get(r).push(t)}const O=[],w=Array.isArray(i.extract.ignore)?i.extract.ignore:i.extract.ignore?[i.extract.ignore]:[];for(const s of i.locales){if(i.extract.mergeNamespaces||"string"==typeof i.extract.output&&!i.extract.output.includes("{{namespace}}")){const e={},n=a(i.extract.output,s),r=t(process.cwd(),n),f=await l(r)||{},u=Object.keys(f),p=!1!==i.extract.defaultNS&&u.some(t=>{const e=f[t];return"object"==typeof e&&null!==e&&!Array.isArray(e)})?new Set([...$.keys(),...u]):new Set([...$.keys(),x]);for(const t of p){const n=$.get(t)||[];if(t===x){const t=h(n,f,i,s,void 0,y,o,c);Object.assign(e,t)}else{const r=f[t]||{};e[t]=h(n,r,i,s,t,y,o,c)}}const d=JSON.stringify(f,null,g),m=JSON.stringify(e,null,g);O.push({path:r,updated:m!==d,newTranslations:e,existingTranslations:f})}else{const f=new Set($.keys()),u=a(i.extract.output,s,"*").replace(/\\/g,"/"),d=await r(u,{ignore:w});for(const t of d)f.add(e(t,n(t)));for(const e of f){const n=$.get(e)||[],r=a(i.extract.output,s,e),f=t(process.cwd(),r),u=await l(f)||{},d=h(n,u,i,s,e,y,o,c,p),x=JSON.stringify(u,null,g),m=JSON.stringify(d,null,g);O.push({path:f,updated:m!==x,newTranslations:d,existingTranslations:u})}}}return O}export{y as getTranslations};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{extractFromTransComponent as e}from"./jsx-parser.js";import{getObjectPropValue as t}from"./ast-utils.js";class n{config;pluginContext;expressionResolver;getCurrentFile;getCurrentCode;lastSearchIndex=0;constructor(e,t,n,i
|
|
1
|
+
import{extractFromTransComponent as e}from"./jsx-parser.js";import{getObjectPropValue as t}from"./ast-utils.js";class n{config;pluginContext;expressionResolver;getCurrentFile;getCurrentCode;lastSearchIndex=0;constructor(e,t,n,o,i){this.config=e,this.pluginContext=t,this.expressionResolver=n,this.getCurrentFile=o,this.getCurrentCode=i}resetSearchIndex(){this.lastSearchIndex=0}getLocationFromNode(e){const t=this.getCurrentCode();let n;if("JSXElement"===e.type&&e.opening){const t=e.opening.name?.value;t&&(n=`<${t}`)}if(!n)return;const o=t.indexOf(n,this.lastSearchIndex);if(-1===o)return;this.lastSearchIndex=o+n.length;const i=t.substring(0,o).split("\n");return{line:i.length,column:i[i.length-1].length}}handleJSXElement(t,n){const o=this.getElementName(t);if(o&&(this.config.extract.transComponents||["Trans"]).includes(o)){let i=null;try{i=e(t,this.config)}catch(e){const n=this.getLocationFromNode(t),i=n?`${this.getCurrentFile()}:${n.line}:${n.column}`:this.getCurrentFile(),s=e instanceof Error?e.message:("string"==typeof e?e:"")||String(e),l=this.pluginContext?.logger?.warn?.bind(this.pluginContext.logger)??console.warn.bind(console);return l(`Failed to extract <${o}> at ${i}`),void l(` ${s}`)}const s=[];if(i){if(i.keyExpression){const e=this.expressionResolver.resolvePossibleKeyStringValues(i.keyExpression);s.push(...e)}else s.push(i.serializedChildren);let e;const{contextExpression:o,optionsNode:l,defaultValue:a,hasCount:r,isOrdinal:u,serializedChildren:c}=i,f=this.getLocationFromNode(t),d=f?[{file:this.getCurrentFile(),line:f.line,column:f.column}]:void 0;if(i.ns){const{ns:t}=i;e=s.map(e=>({key:e,ns:t,defaultValue:a||c,hasCount:r,isOrdinal:u,locations:d}))}else{e=s.map(e=>{const t=this.config.extract.nsSeparator??":";let n;if(t&&e.includes(t)){let o;[n,...o]=e.split(t),e=o.join(t)}return{key:e,ns:n,defaultValue:a||c,hasCount:r,isOrdinal:u,explicitDefault:i.explicitDefault,locations:d}});const o=t.opening.attributes?.find(e=>"JSXAttribute"===e.type&&"Identifier"===e.name.type&&"t"===e.name.value);if("JSXAttribute"===o?.type&&"JSXExpressionContainer"===o.value?.type&&"Identifier"===o.value.expression.type){const t=n(o.value.expression.value);if(t?.defaultNs&&e.forEach(e=>{e.ns||(e.ns=t.defaultNs)}),t?.keyPrefix){const n=this.config.extract.keySeparator??".";for(const o of e){let e=o.key;if(e=!1!==n?String(t.keyPrefix).endsWith(String(n))?`${t.keyPrefix}${e}`:`${t.keyPrefix}${n}${e}`:`${t.keyPrefix}${e}`,!1!==n){if(String(e).split(String(n)).some(e=>""===e.trim()))continue}o.key=e}}}}if(e.forEach(e=>{e.ns||(e.ns=this.config.extract.defaultNS)}),o&&r)if(this.config.extract.disablePlurals){const t=this.expressionResolver.resolvePossibleContextStringValues(o),n=this.config.extract.contextSeparator??"_";if(t.length>0)if("StringLiteral"===o.type)for(const o of t)for(const t of e){const e=`${t.key}${n}${o}`;this.pluginContext.addKey({key:e,ns:t.ns,defaultValue:t.defaultValue,locations:t.locations})}else{e.forEach(e=>{this.pluginContext.addKey({key:e.key,ns:e.ns,defaultValue:e.defaultValue,locations:e.locations,keyAcceptingContext:e.key})});for(const o of t)for(const t of e){const e=`${t.key}${n}${o}`;this.pluginContext.addKey({key:e,ns:t.ns,defaultValue:t.defaultValue,locations:t.locations})}}else e.forEach(e=>{this.pluginContext.addKey({key:e.key,ns:e.ns,defaultValue:e.defaultValue,locations:e.locations,keyAcceptingContext:e.key})})}else{const n=t.opening.attributes?.find(e=>"JSXAttribute"===e.type&&"Identifier"===e.name.type&&"ordinal"===e.name.value),i=!!n,s=this.expressionResolver.resolvePossibleContextStringValues(o),a=this.config.extract.contextSeparator??"_";if(s.length>0){!1!==this.config.extract.generateBasePluralForms&&e.forEach(e=>this.generatePluralKeysForTrans(e.key,e.defaultValue,e.ns,i,l,void 0,e.locations,e.key));for(const t of s)for(const n of e){const e=`${n.key}${a}${t}`;this.generatePluralKeysForTrans(e,n.defaultValue,n.ns,i,l,n.explicitDefault,n.locations,n.key)}}else e.forEach(e=>this.generatePluralKeysForTrans(e.key,e.defaultValue,e.ns,i,l,e.explicitDefault,e.locations))}else if(o){const t=this.expressionResolver.resolvePossibleContextStringValues(o),n=this.config.extract.contextSeparator??"_";if(t.length>0){for(const o of t)for(const{key:t,ns:i,defaultValue:s,locations:l}of e)this.pluginContext.addKey({key:`${t}${n}${o}`,ns:i,defaultValue:s,locations:l});"StringLiteral"!==o.type&&e.forEach(e=>{this.pluginContext.addKey({key:e.key,ns:e.ns,defaultValue:e.defaultValue,locations:e.locations,keyAcceptingContext:e.key})})}else e.forEach(e=>{this.pluginContext.addKey({key:e.key,ns:e.ns,defaultValue:e.defaultValue,locations:e.locations,keyAcceptingContext:e.key})})}else if(r)if(this.config.extract.disablePlurals)e.forEach(e=>{this.pluginContext.addKey({key:e.key,ns:e.ns,defaultValue:e.defaultValue,locations:e.locations})});else{const n=t.opening.attributes?.find(e=>"JSXAttribute"===e.type&&"Identifier"===e.name.type&&"ordinal"===e.name.value),o=!!n;e.forEach(e=>this.generatePluralKeysForTrans(e.key,e.defaultValue,e.ns,o,l,e.explicitDefault,e.locations))}else e.forEach(e=>{this.pluginContext.addKey({key:e.key,ns:e.ns,defaultValue:e.defaultValue,locations:e.locations})})}}}generatePluralKeysForTrans(e,n,o,i,s,l,a,r){try{const u=i?"ordinal":"cardinal",c=new Intl.PluralRules(this.config.extract?.primaryLanguage,{type:u}).resolvedOptions().pluralCategories,f=this.config.extract.pluralSeparator??"_";let d,p;if(s&&(d=t(s,`defaultValue${f}other`),p=t(s,`defaultValue${f}ordinal${f}other`)),1===c.length&&"other"===c[0]){const u=s?t(s,`defaultValue${f}other`):void 0,c="string"==typeof u?u:"string"==typeof n?n:e;return void this.pluginContext.addKey({key:e,ns:o,defaultValue:c,hasCount:!0,isOrdinal:i,explicitDefault:Boolean(l||"string"==typeof u||"string"==typeof d),locations:a,keyAcceptingContext:r})}for(const u of c){const c=s?t(s,i?`defaultValue${f}ordinal${f}${u}`:`defaultValue${f}${u}`):void 0;let g;g="string"==typeof c?c:"one"===u&&"string"==typeof n?n:i&&"string"==typeof p?p:i||"string"!=typeof d?"string"==typeof n?n:e:d;const y=i?`${e}${f}ordinal${f}${u}`:`${e}${f}${u}`;this.pluginContext.addKey({key:y,ns:o,defaultValue:g,hasCount:!0,isOrdinal:i,explicitDefault:Boolean(l||"string"==typeof c||"string"==typeof d),locations:a,keyAcceptingContext:r})}}catch(t){this.pluginContext.addKey({key:e,ns:o,defaultValue:n,locations:a})}}getElementName(e){if("Identifier"===e.opening.name.type)return e.opening.name.value;if("JSXMemberExpression"===e.opening.name.type){let t=e.opening.name;const n=[];for(;"JSXMemberExpression"===t.type;)"Identifier"===t.property.type&&n.unshift(t.property.value),t=t.object;return"Identifier"===t.type&&n.unshift(t.value),n.join(".")}}}export{n as JSXHandler};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{getObjectPropValueExpression as e,getObjectPropValue as t,isSimpleTemplateLiteral as n}from"./ast-utils.js";function i(e){if(e)return"StringLiteral"===e.type?e.value:"TemplateLiteral"===e.type&&n(e)?e.quasis[0].cooked:void 0}function s(e){return"StringLiteral"===e.value?.type?e.value.value:"JSXExpressionContainer"===e.value?.type?i(e.value.expression):void 0}function r(n,r){const o=n.opening.attributes?.find(e=>"JSXAttribute"===e.type&&"Identifier"===e.name.type&&"i18nKey"===e.name.value),p=n.opening.attributes?.find(e=>"JSXAttribute"===e.type&&"Identifier"===e.name.type&&"defaults"===e.name.value),l=n.opening.attributes?.find(e=>"JSXAttribute"===e.type&&"Identifier"===e.name.type&&"count"===e.name.value),a=n.opening.attributes?.find(e=>"JSXAttribute"===e.type&&"Identifier"===e.name.type&&"values"===e.name.value);let c;l||"JSXAttribute"!==a?.type||"JSXExpressionContainer"!==a.value?.type||"ObjectExpression"!==a.value.expression.type||(c=e(a.value.expression,"count"));const u=!!l||!!c,f=n.opening.attributes?.find(e=>"JSXAttribute"===e.type&&"Identifier"===e.name.type&&"tOptions"===e.name.value),y="JSXAttribute"===f?.type&&"JSXExpressionContainer"===f.value?.type&&"ObjectExpression"===f.value.expression.type?f.value.expression:void 0,d=n.opening.attributes?.find(e=>"JSXAttribute"===e.type&&"Identifier"===e.name.type&&"ordinal"===e.name.value),g=!!d,x=n.opening.attributes?.find(e=>"JSXAttribute"===e.type&&"Identifier"===e.name.type&&"context"===e.name.value);let h="JSXAttribute"===x?.type&&"JSXExpressionContainer"===x.value?.type?x.value.expression:"JSXAttribute"===x?.type&&"StringLiteral"===x.value?.type?x.value:void 0;const S=n.opening.attributes?.find(e=>"JSXAttribute"===e.type&&"Identifier"===e.name.type&&"ns"===e.name.value);let v;v="JSXAttribute"===S?.type?s(S):void 0,y&&(void 0===v&&(v=t(y,"ns")),void 0===h&&(h=e(y,"context")));const m=function(e,t){if(!e||0===e.length)return"";const n=new Set(t.extract.transKeepBasicHtmlNodesFor??["br","strong","i","p"]),s=e=>e&&"JSXText"===e.type&&/^\s*$/.test(e.value)&&e.value.includes("\n");function r(e,t,o=!1,p=!1){if(!e||!e.length)return;const l=p&&e.filter(e=>e&&"JSXElement"===e.type&&"p"===e.opening?.name?.value).length>1;let a=0,c=e.length-1;for(;a<=c&&s(e[a]);)a++;for(;c>=a&&s(e[c]);)c--;const u=a<=c?e.slice(a,c+1):[],f=u.some(e=>e&&("JSXElement"===e.type||"JSXFragment"===e.type));for(let e=0;e<u.length;e++){const a=u[e];if(a)if("JSXText"!==a.type){if("JSXExpressionContainer"===a.type){if(o&&!f&&a.expression){const e=a.expression.type;if("ObjectExpression"===e)continue;if(void 0!==i(a.expression))continue;if("Identifier"===e||"MemberExpression"===e||"CallExpression"===e)continue}const n=i(a.expression);if(void 0!==n){const i=/^\s*$/.test(n)&&!n.includes("\n"),r=u[e-1],o=u[e+1];if(i){const n=u[e+2];if(o&&"JSXText"===o.type&&s(o)&&n&&("JSXElement"===n.type||"JSXFragment"===n.type)){const t=u[e-1],n=u[e-2];if(!t||"JSXText"!==t.type&&n&&"JSXExpressionContainer"===n.type)continue}if(r&&("JSXElement"===r.type||"JSXFragment"===r.type)&&o&&"JSXText"===o.type&&s(o))continue;const i=!o||"JSXText"===o.type&&!s(o);if(r&&"JSXText"===r.type&&i){const e=t[t.length-1];if(e&&"JSXText"===e.type){e.value=String(e.value)+a.expression.value;continue}}if(r&&("JSXElement"===r.type||"JSXFragment"===r.type)&&o&&"JSXText"===o.type&&s(o))continue}}t.push(a);continue}if("JSXElement"===a.type){const e=a.opening&&a.opening.name&&"Identifier"===a.opening.name.type?a.opening.name.value:void 0;if(e&&n.has(e)){const o=a.opening&&Array.isArray(a.opening.attributes)&&a.opening.attributes.length>0,c=a.children||[],f=1===c.length&&("JSXText"===c[0]?.type||"JSXExpressionContainer"===c[0]?.type&&void 0!==i(c[0].expression)),y=!c.length,d=f;if(o&&!f)t.push(a),r(a.children||[],t,!0);else if(y)t.push(a);else if(!d){if((a.children||[]).some(e=>"JSXExpressionContainer"===e.type&&void 0===i(e.expression)))t.push(a),r(a.children||[],t,!0);else if("p"===e){const e=(c||[]).some(e=>{if(!e||"JSXElement"!==e.type)return!1;const t=e.opening&&e.opening.name&&"Identifier"===e.opening.name.type?e.opening.name.value:void 0,s=e.opening&&Array.isArray(e.opening.attributes)&&e.opening.attributes.length>0,r=e.children||[],o=1===r.length&&("JSXText"===r[0]?.type||"JSXExpressionContainer"===r[0]?.type&&void 0!==i(r[0].expression));return!(t&&n.has(t)&&!s&&(0===r.length||o))}),o=p&&u.some(e=>e&&e!==a&&"JSXText"===e.type&&!s(e));l||p&&e&&!o?(t.push(a),r(a.children||[],t,!0,!1)):r(a.children||[],t,!1,!1)}else r(a.children||[],t,!1,!1)}continue}t.push(a),r(a.children||[],t,!0);continue}"JSXFragment"!==a.type||r(a.children||[],t,o)}else{if(o&&!f)continue;if(o&&s(a))continue;if(s(a)){const n=u[e-1],i=u[e+1];if(n&&("JSXElement"===n.type||"JSXFragment"===n.type)&&i&&("JSXElement"===i.type||"JSXFragment"===i.type))continue;const s=t[t.length-1],r=u[e-1];if(s){if(r&&"JSXExpressionContainer"===r.type)continue;if("JSXText"===s.type&&r&&"JSXText"===r.type){s.value=String(s.value)+a.value;continue}}}if(o&&f&&0===e)continue;t.push(a)}}}const o=[];function p(e){if(!e||!e.length)return!1;let t=!1;for(const n of e)if(n)if("JSXElement"!==n.type){if("JSXExpressionContainer"===n.type&&-1!==o.indexOf(n))return t;if("JSXText"===n.type&&-1!==o.indexOf(n)){if(s(n))continue;if(!t)return!0;const i=e.indexOf(n);if(e.slice(i+1).some(e=>e&&"JSXElement"===e.type))return!0}}else t=!0;return!1}r(e,o,!1,!0);const l=new Set,a=e=>String(e).replace(/^\s*\n\s*/g,"").replace(/\s*\n\s*$/g,"");function c(e,t,r=!1){if(!e||0===e.length)return"";let u="";const f=e=>{if(!e)return-1;if(t&&t.has(e))return t.get(e);if(t)for(const[n,i]of t.entries())try{if(n&&e&&n.span&&e.span&&n.span.start===e.span.start&&n.span.end===e.span.end)return i}catch(e){}return o.indexOf(e)},y=t=>{if(!r)return o.indexOf(t);const n=e.indexOf(t);if(-1===n)return-1;let i=0;for(let t=0;t<n;t++){const n=e[t];n&&("JSXText"===n.type?s(n)||i++:"JSXExpressionContainer"===n.type?n.expression&&"JSXEmptyExpression"!==n.expression.type&&i++:"JSXElement"===n.type&&i++)}return i};for(let t=0;t<e.length;t++){const d=e[t];if(d){if("JSXText"===d.type){if(s(d))continue;const i=e[t+1],r=e[t-1];if(r&&"JSXElement"===r.type){const i="Identifier"===r.opening?.name?.type?r.opening.name.value:void 0,s=i&&n.has(i),o=0===(r.children||[]).length;if(s&&o&&/^\s*\n\s*/.test(d.value)){const e=d.value.replace(/^\s*\n\s*/,"");if(e){u+=e;continue}continue}if(!s&&/^\s*\n\s*/.test(d.value)){const n=d.value.replace(/^\s*\n\s*/,"");if(n){if(r&&"JSXElement"===r.type&&Array.isArray(r.children)&&0===r.children.length){u+=n;continue}const i=e[t-2];if(i&&"JSXText"===i.type){const e=i.value.replace(/\n\s*$/,""),t=/[A-Za-z0-9]$/.test(e),s=/^[A-Za-z0-9]/.test(n),r=/^[a-z]/.test(n);if(t&&s&&r){u+=n;continue}}u+=" "+n;continue}continue}}if(/\n\s*$/.test(d.value)&&i&&"JSXElement"===i.type){const r=d.value.replace(/\n\s*$/,"");if(r.trim()){const o="Identifier"===i.opening?.name?.type?i.opening.name.value:void 0,p=o&&n.has(o),a=(i.children||[]).length>0,c=/\s\n/.test(d.value),f=e[t+2],y=f&&"JSXText"===f.type&&!s(f)&&/[a-zA-Z0-9]/.test(f.value),g=!!(i.opening&&Array.isArray(i.opening.attributes)&&i.opening.attributes.length>0),x=/^\s/.test(r)&&!/^\n/.test(r),h=r.trim(),S=x?" "+h:h,v=/[A-Za-z0-9]$/.test(h),m=f&&"string"==typeof f.value&&/^[A-Za-z0-9]/.test(f.value.trim()),J=f&&"string"==typeof f.value&&/^[a-z]/.test(f.value.trim()),X=f&&"string"==typeof f.value&&/^\s/.test(f.value)&&!/^\n/.test(f.value),$=g&&a&&y&&!(v&&m&&J&&!c&&!x&&!X),E=f&&"string"==typeof f.value&&/^[,;:!?.]/.test(f.value.trim()),b=$&&!E;v&&m&&J&&!c&&!x&&!X&&l.add(i),u+=c||p&&a||!p&&y&&x||b?S+" ":S;continue}}u+=d.value;continue}if("JSXExpressionContainer"===d.type){const e=d.expression;if(!e)continue;const t=i(e);if(void 0!==t)u+=t;else if("Identifier"===e.type)u+=`{{${e.value}}}`;else if("TsAsExpression"===e.type&&"ObjectExpression"===e.expression?.type){const t=e.expression,n=t.properties.filter(e=>"KeyValueProperty"===e.type&&e.key&&"Identifier"===e.key.type).map(e=>e.key.value);if(n.length>0)u+=n.map(e=>`{{${e}}}`).join("");else{const e=t.properties[0];if(!e||"Identifier"!==e.type)throw new Error("Unrecognized expression in JSX placeholder");u+=`{{${e.value}}}`}}else if("ObjectExpression"===e.type){const t=e.properties[0];if(t&&"KeyValueProperty"===t.type&&t.key&&"Identifier"===t.key.type)u+=`{{${t.key.value}}}`;else{if(!t||"Identifier"!==t.type)throw new Error("Unrecognized expression in JSX placeholder");u+=`{{${t.value}}}`}}else if("MemberExpression"===e.type&&e.property&&"Identifier"===e.property.type)u+=`{{${e.property.value}}}`;else if("CallExpression"===e.type&&"Identifier"===e.callee?.type)u+=`{{${e.callee.value}}}`;else if("JSXEmptyExpression"!==e.type)throw new Error(`Unrecognized expression in JSX placeholder: ${e.type}`);continue}if("JSXElement"===d.type){const l=r?y(d):void 0;let g;if(d.opening&&d.opening.name&&"Identifier"===d.opening.name.type&&(g=d.opening.name.value),g&&n.has(g)){const y=d.opening&&Array.isArray(d.opening.attributes)&&d.opening.attributes.length>0,x=d.children||[],h=x.length>0,S=1===x.length&&("JSXText"===x[0]?.type||"JSXExpressionContainer"===x[0]?.type&&void 0!==i(x[0].expression)),v="p"===g;let m=0;if(v&&r&&(m=e.filter(e=>e&&"JSXElement"===e.type&&"p"===e.opening?.name?.value).length),!h||S){const i=S?c(x,void 0):"";if(""!==String(i).trim())if(n.has(g)&&"p"!==g)u+=`<${g}>${a(i)}</${g}>`;else if(v&&r&&m>1)u+=`<${g}>${a(i)}</${g}>`;else if(v){const e=r&&void 0!==l?l:o.indexOf(d);u+=`<${e}>${a(i)}</${e}>`}else{const e=r&&void 0!==l?l:o.indexOf(d);u+=`<${e}>${a(i)}</${e}>`}else{const n=e[t-1];n&&"JSXText"===n.type&&/\n\s*$/.test(n.value)&&(u=u.replace(/\s+$/,"")),u+=`<${g} />`}}else if(y&&!S){const e=x,t=r&&void 0!==l?l:f(d);if(p(e)){const s=new Map;let r=0;for(const t of e)if(t&&"JSXElement"===t.type){const e=t.opening&&t.opening.name&&"Identifier"===t.opening.name.type?t.opening.name.value:void 0;if(e&&n.has(e)){const e=t.opening&&Array.isArray(t.opening.attributes)&&t.opening.attributes.length>0,n=t.children||[],o=1===n.length&&("JSXText"===n[0]?.type||"JSXExpressionContainer"===n[0]?.type&&void 0!==i(n[0].expression));!e&&(!n.length||o)||s.set(t,r++)}else s.set(t,r++)}const o=c(e,s.size?s:void 0);u+=`<${t}>${a(o)}</${t}>`}else{const e=new Map;let s=0;for(const t of x)if(t&&"JSXElement"===t.type){const r=t.opening&&t.opening.name&&"Identifier"===t.opening.name.type?t.opening.name.value:void 0;if(r&&n.has(r)){const n=t.opening&&Array.isArray(t.opening.attributes)&&t.opening.attributes.length>0,r=t.children||[],o=1===r.length&&("JSXText"===r[0]?.type||"JSXExpressionContainer"===r[0]?.type&&void 0!==i(r[0].expression));!n&&(!r.length||o)||e.set(t,s++)}else e.set(t,s++)}const r=c(x,e.size?e:void 0);u+=`<${t}>${a(r)}</${t}>`}}else{const e=o.indexOf(d);if(-1!==e){const t=void 0!==l?l:e;if((()=>{let e=!1;for(const t of x)if(t)if("JSXElement"!==t.type){if("JSXExpressionContainer"===t.type&&-1!==o.indexOf(t))return e;if("JSXText"===t.type&&-1!==o.indexOf(t)){if(s(t))continue;if(!e)return!0;if(x.slice(x.indexOf(t)+1).some(e=>e&&"JSXElement"===e.type))return!0}}else e=!0;return!1})()){if(0===t){const e=c(x,void 0,!1);u+=`<${t}>${a(e)}</${t}>`;continue}const e=new Map;for(const e of x)if(e&&"JSXElement"===e.type){const s=e.opening&&e.opening.name&&"Identifier"===e.opening.name.type?e.opening.name.value:void 0;if(s&&n.has(s)){const n=e.opening&&Array.isArray(e.opening.attributes)&&e.opening.attributes.length>0,s=e.children||[],r=1===s.length&&("JSXText"===s[0]?.type||"JSXExpressionContainer"===s[0]?.type&&void 0!==i(s[0].expression));if(!(!n&&(!s.length||r))){const n=c(e.children,void 0,!1);u+=`<${t}>${a(n)}</${t}>`}}else{const n=c(e.children,void 0,!1);u+=`<${t}>${a(n)}</${t}>`}}const s=c(x,e.size?e:void 0,!1);u+=`<${t}>${a(s)}</${t}>`;continue}const r=new Map;let p=0;for(const e of x)if(e&&"JSXElement"===e.type){const t=e.opening&&e.opening.name&&"Identifier"===e.opening.name.type?e.opening.name.value:void 0;if(t&&n.has(t)){const t=e.opening&&Array.isArray(e.opening.attributes)&&e.opening.attributes.length>0,n=e.children||[],s=1===n.length&&("JSXText"===n[0]?.type||"JSXExpressionContainer"===n[0]?.type&&void 0!==i(n[0].expression));!t&&(!n.length||s)||r.set(e,p++)}else r.set(e,p++)}const f=c(x,r.size>0?r:void 0,!1);u+=`<${t}>${a(f)}</${t}>`}else{const e=c(x,void 0,!1);u+=`<${g}>${a(e)}</${g}>`}}}else{const e=d.children||[];if(e.some(e=>e&&("JSXText"===e.type||"JSXExpressionContainer"===e.type)&&-1!==o.indexOf(e))){const t=o.indexOf(d),n=c(e,void 0);u+=`<${t}>${a(n)}</${t}>`}else{const t=new Map,i=f(d);let s=0;for(const i of e)if(i&&"JSXElement"===i.type){const e=i.opening&&i.opening.name&&"Identifier"===i.opening.name.type?i.opening.name.value:void 0;if(e&&n.has(e)){const e=i.opening&&Array.isArray(i.opening.attributes)&&i.opening.attributes.length>0,n=i.children||[],r=1===n.length&&"JSXText"===n[0]?.type;!e&&(!n.length||r)||t.set(i,s++)}else t.set(i,s++)}const r=c(e,t.size?t:void 0);u+=`<${i}>${a(r)}</${i}>`}}continue}"JSXFragment"!==d.type||(u+=c(d.children||[]))}}return u}const u=c(e,void 0,!0),f=String(u).replace(/<br \/>\s*\n\s*/g,"<br />"),y=String(f),d=new Set;if(l&&l.size>0)for(let e=0;e<o.length;e++)l.has(o[e])&&d.add(e);let g=String(y);if(d&&d.size>0)for(const e of d)try{g=g.replace(new RegExp("\\s+<"+e+">","g"),"<"+e+">"),g=g.replace(new RegExp("<\\/"+e+">\\s+","g"),"</"+e+">")}catch(e){}g=g.replace(/<\/(\d+)>\s*\n\s*(\S)/g,(e,t,n)=>{const i=Number(t);return d.has(i)?`</${t}>${n}`:`</${t}> ${n}`}),g=g.replace(/(\S)\s*\n\s*<(\d+)/g,(e,t,n)=>{const i=Number(n);return d.has(i)?`${t}<${n}`:`${t} <${n}`}),g=g.replace(/\s*\n\s*/g," "),g=g.replace(/\s+/g," "),g=g.replace(/\s+([,;:!?.])/g,"$1");const x=g.trim();let h=String(x);if(d&&d.size>0)for(const e of d)try{h=h.replace(new RegExp("[\\s\\u00A0]+<"+e+">","g"),"<"+e+">"),h=h.replace(new RegExp("<\\/"+e+">[\\s\\u00A0]+","g"),"</"+e+">")}catch(e){}try{for(let e=0;e<o.length;e++){const t=o[e];if(!t||"JSXElement"!==t.type)continue;const n=o[e-1],i=o[e+1];if(!n||!i)continue;if("JSXText"!==n.type||"JSXText"!==i.type)continue;const s=String(n.value),r=String(i.value),p=s.replace(/\n\s*$/,""),l=/[A-Za-z0-9]$/.test(p),a=/^[A-Za-z0-9]/.test(r.trim()),c=/^[a-z]/.test(r.trim()),u=/\s\n/.test(s),f=r&&/^\s/.test(r)&&!/^\n/.test(r);if(l&&a&&c&&!u&&!f){const t=e;h=h.replace(new RegExp("\\s+<"+t+">","g"),"<"+t+">")}}}catch(e){}function S(e){if(!e||!e.includes("<"))return e;function t(e){const t=[],n=[];let i=0;const s=/<\/?(\d+)>|<[^>]+>/g;let r;for(;r=s.exec(e);){const o=r[0],p=r.index;if(p>i){const s={type:"text",text:e.slice(i,p)};n.length?n[n.length-1].node.children.push(s):t.push(s)}const l=/^<\/(\d+)>$/.exec(o),a=/^<(\d+)>$/.exec(o);if(a){const e=Number(a[1]),i={type:"ph",idx:e,children:[]};n.length?n[n.length-1].node.children.push(i):t.push(i),n.push({node:i,idx:e})}else if(l)n.length&&n.pop();else{const e={type:"text",text:o};n.length?n[n.length-1].node.children.push(e):t.push(e)}i=s.lastIndex}if(i<e.length){const s={type:"text",text:e.slice(i)};n.length?n[n.length-1].node.children.push(s):t.push(s)}return t}function i(e,t=null){let r="";for(const p of e)if("text"===p.type)r+=p.text;else{const e=p.children.filter(e=>"ph"===e.type);let l;if("number"==typeof p.idx){const t=o[p.idx];if(t&&Array.isArray(t.children)){const n=new Map;let i=0;for(const e of t.children){const t=o.indexOf(e);if("JSXText"===e.type){if(s(e))continue;-1!==t&&n.set(t,i),i++}else"JSXElement"===e.type?(-1!==t&&n.set(t,i),i++):"JSXExpressionContainer"===e.type&&-1!==t&&(n.set(t,i),i++)}e.every(e=>n.has(e.idx))&&(l=n)}}if(!l){const i=e.map(e=>e.idx);if(i.length<=1||i.every((e,t)=>0===t||e===i[t-1]+1)){l=new Map;let i=0;try{const s=o[p.idx];if(s&&s.span){const r=s.span.start,l=s.span.end;let a=0,c=-1;for(let e=p.idx+1;e<o.length;e++){const t=o[e];if(t&&t.span&&(t.span.start>=r&&t.span.end<=l&&"JSXElement"===t.type)){c=e;break}}if(-1!==c)for(let e=p.idx+1;e<c;e++){const t=o[e];t&&t.span&&(t.span.start>=r&&t.span.end<=l&&("JSXText"!==t.type&&"JSXExpressionContainer"!==t.type||a++))}else for(let e=p.idx+1;e<o.length;e++){const t=o[e];t&&t.span&&(t.span.start>=r&&t.span.end<=l&&("JSXText"!==t.type&&"JSXExpressionContainer"!==t.type||a++))}const u=s?.opening?.name?.value,f=u&&n.has(u),y=null===t;1===e.length&&(i=Math.max(1,a+1),!y||f||0!==e[0].idx||"a"!==u&&"p"!==u||(i=0))}}catch(e){}for(const t of e)l.has(t.idx)||l.set(t.idx,i++)}}const a=p.children.map(e=>{if("text"===e.type)return e.text;const t=e.idx,n=l&&l.has(t)?l.get(t):t;return`<${n}>${i(e.children,n)}</${n}>`}).join("");r+=`<${p.idx}>${a}</${p.idx}>`}return r}try{const n=t(e);return i(n)}catch(t){return e}}return h=S(h),h.trim()}(n.children,r);let J;const X="JSXAttribute"===p?.type?s(p):void 0;if(void 0!==X)J=X;else{const e=r.extract.defaultValue;J="string"==typeof e?e:""}let $,E;if("JSXAttribute"===o?.type){if("StringLiteral"===o.value?.type){if($=o.value,E=$.value,!E||""===E.trim())return null;if(v&&"StringLiteral"===$.type){const e=r.extract.nsSeparator??":",t=$.value;if(e&&t.startsWith(`${v}${e}`)){if(E=t.slice(`${v}${e}`.length),!E||""===E.trim())return null;$={...$,value:E}}}}else"JSXExpressionContainer"===o.value?.type&&"JSXEmptyExpression"!==o.value.expression.type&&($=o.value.expression);if(!$)return null}p||!E||m.trim()?!p&&m.trim()&&(J=m):J=E;return{keyExpression:$,serializedChildren:m,ns:v,defaultValue:J,hasCount:u,isOrdinal:g,contextExpression:h,optionsNode:y,explicitDefault:void 0!==X||(e=>{if(!e||!Array.isArray(e.properties))return!1;for(const t of e.properties)if(t&&"KeyValueProperty"===t.type&&t.key){const e="Identifier"===t.key.type&&t.key.value||"StringLiteral"===t.key.type&&t.key.value;if("string"==typeof e&&e.startsWith("defaultValue"))return!0}return!1})(y)}}export{r as extractFromTransComponent};
|
|
1
|
+
import{getObjectPropValueExpression as e,getObjectPropValue as t,isSimpleTemplateLiteral as n}from"./ast-utils.js";function i(e){if(e)return"StringLiteral"===e.type?e.value:"TemplateLiteral"===e.type&&n(e)?e.quasis[0].cooked:void 0}function s(e){if(e)return"StringLiteral"===e.type?e.value:"TemplateLiteral"===e.type&&n(e)?e.quasis?.[0]?.cooked:"ParenExpression"===e.type&&e.expr?s(e.expr):"ParenthesizedExpression"===e.type&&e.expression||"TsAsExpression"===e.type&&e.expression?s(e.expression):void 0}function r(e){return"StringLiteral"===e.value?.type?e.value.value:"JSXExpressionContainer"===e.value?.type?i(e.value.expression):void 0}function o(n,o){const p=n.opening.attributes?.find(e=>"JSXAttribute"===e.type&&"Identifier"===e.name.type&&"i18nKey"===e.name.value),l=n.opening.attributes?.find(e=>"JSXAttribute"===e.type&&"Identifier"===e.name.type&&"defaults"===e.name.value),a=n.opening.attributes?.find(e=>"JSXAttribute"===e.type&&"Identifier"===e.name.type&&"count"===e.name.value),c=n.opening.attributes?.find(e=>"JSXAttribute"===e.type&&"Identifier"===e.name.type&&"values"===e.name.value);let u;a||"JSXAttribute"!==c?.type||"JSXExpressionContainer"!==c.value?.type||"ObjectExpression"!==c.value.expression.type||(u=e(c.value.expression,"count"));const f=!!a||!!u,y=n.opening.attributes?.find(e=>"JSXAttribute"===e.type&&"Identifier"===e.name.type&&"tOptions"===e.name.value),d="JSXAttribute"===y?.type&&"JSXExpressionContainer"===y.value?.type&&"ObjectExpression"===y.value.expression.type?y.value.expression:void 0,g=n.opening.attributes?.find(e=>"JSXAttribute"===e.type&&"Identifier"===e.name.type&&"ordinal"===e.name.value),x=!!g,h=n.opening.attributes?.find(e=>"JSXAttribute"===e.type&&"Identifier"===e.name.type&&"context"===e.name.value);let v="JSXAttribute"===h?.type&&"JSXExpressionContainer"===h.value?.type?h.value.expression:"JSXAttribute"===h?.type&&"StringLiteral"===h.value?.type?h.value:void 0;const S=n.opening.attributes?.find(e=>"JSXAttribute"===e.type&&"Identifier"===e.name.type&&"ns"===e.name.value);let m;m="JSXAttribute"===S?.type?r(S):void 0,d&&(void 0===m&&(m=t(d,"ns")),void 0===v&&(v=e(d,"context")));const J=function(e,t){if(!e||0===e.length)return"";const n=new Set(t.extract.transKeepBasicHtmlNodesFor??["br","strong","i","p"]),r=e=>e&&"JSXText"===e.type&&/^\s*$/.test(e.value)&&e.value.includes("\n"),o=e=>e&&("JSXElement"===e.type||"JSXFragment"===e.type),p=(e,t)=>{for(let n=t;n<e.length;n++){const t=e[n];if(t&&("JSXText"!==t.type||!r(t)))return t}};function l(e,t,s=!1,a=!1){if(!e||!e.length)return;const c=a&&e.filter(e=>e&&"JSXElement"===e.type&&"p"===e.opening?.name?.value).length>1;let u=0,f=e.length-1;for(;u<=f&&r(e[u]);)u++;for(;f>=u&&r(e[f]);)f--;const y=u<=f?e.slice(u,f+1):[],d=y.some(e=>e&&("JSXElement"===e.type||"JSXFragment"===e.type));for(let e=0;e<y.length;e++){const u=y[e];if(u)if("JSXText"!==u.type){if("JSXExpressionContainer"===u.type){if(s&&!d&&u.expression){const e=u.expression.type;if("ObjectExpression"===e)continue;if(void 0!==i(u.expression))continue;if("Identifier"===e||"MemberExpression"===e||"CallExpression"===e)continue}const n=i(u.expression);if(void 0!==n){const i=/^\s*$/.test(n)&&!n.includes("\n"),s=y[e-1],l=y[e+1];if(i){const n=p(y,e+1);if(o(s)&&o(n));else{const n=y[e+2];if(l&&"JSXText"===l.type&&r(l)&&n&&("JSXElement"===n.type||"JSXFragment"===n.type)){const t=y[e-1],n=y[e-2];if(!t||"JSXText"!==t.type&&n&&"JSXExpressionContainer"===n.type)continue}if(s&&("JSXElement"===s.type||"JSXFragment"===s.type)&&l&&"JSXText"===l.type&&r(l))continue;const i=!l||"JSXText"===l.type&&!r(l);if(s&&"JSXText"===s.type&&i){const e=t[t.length-1];if(e&&"JSXText"===e.type){e.value=String(e.value)+u.expression.value;continue}}if(s&&("JSXElement"===s.type||"JSXFragment"===s.type)&&l&&"JSXText"===l.type&&r(l))continue}}}t.push(u);continue}if("JSXElement"===u.type){const e=u.opening&&u.opening.name&&"Identifier"===u.opening.name.type?u.opening.name.value:void 0;if(e&&n.has(e)){const s=u.opening&&Array.isArray(u.opening.attributes)&&u.opening.attributes.length>0,o=u.children||[],p=1===o.length&&("JSXText"===o[0]?.type||"JSXExpressionContainer"===o[0]?.type&&void 0!==i(o[0].expression)),f=!o.length,d=p;if(s&&!p)t.push(u),l(u.children||[],t,!0);else if(f)t.push(u);else if(!d){if((u.children||[]).some(e=>"JSXExpressionContainer"===e.type&&void 0===i(e.expression)))t.push(u),l(u.children||[],t,!0);else if("p"===e){const e=(o||[]).some(e=>{if(!e||"JSXElement"!==e.type)return!1;const t=e.opening&&e.opening.name&&"Identifier"===e.opening.name.type?e.opening.name.value:void 0,s=e.opening&&Array.isArray(e.opening.attributes)&&e.opening.attributes.length>0,r=e.children||[],o=1===r.length&&("JSXText"===r[0]?.type||"JSXExpressionContainer"===r[0]?.type&&void 0!==i(r[0].expression));return!(t&&n.has(t)&&!s&&(0===r.length||o))}),s=a&&y.some(e=>e&&e!==u&&"JSXText"===e.type&&!r(e));c||a&&e&&!s?(t.push(u),l(u.children||[],t,!0,!1)):l(u.children||[],t,!1,!1)}else l(u.children||[],t,!1,!1)}continue}t.push(u),l(u.children||[],t,!0);continue}"JSXFragment"!==u.type||l(u.children||[],t,s)}else{if(s&&!d)continue;if(s&&r(u))continue;if(r(u)){const n=y[e-1],i=y[e+1];if(n&&("JSXElement"===n.type||"JSXFragment"===n.type)&&i&&("JSXElement"===i.type||"JSXFragment"===i.type))continue;const s=t[t.length-1],r=y[e-1];if(s){if(r&&"JSXExpressionContainer"===r.type)continue;if("JSXText"===s.type&&r&&"JSXText"===r.type){s.value=String(s.value)+u.value;continue}}}if(s&&d&&0===e)continue;t.push(u)}}}const a=[];function c(e){if(!e||!e.length)return!1;let t=!1;for(const n of e)if(n)if("JSXElement"!==n.type){if("JSXExpressionContainer"===n.type&&-1!==a.indexOf(n))return t;if("JSXText"===n.type&&-1!==a.indexOf(n)){if(r(n))continue;if(!t)return!0;const i=e.indexOf(n);if(e.slice(i+1).some(e=>e&&"JSXElement"===e.type))return!0}}else t=!0;return!1}l(e,a,!1,!0);const u=new Set,f=e=>String(e).replace(/^\s*\n\s*/g,"").replace(/\s*\n\s*$/g,"");function y(e,t,o=!1){if(!e||0===e.length)return"";let p="";const l=e=>{if(!e)return-1;if(t&&t.has(e))return t.get(e);if(t)for(const[n,i]of t.entries())try{if(n&&e&&n.span&&e.span&&n.span.start===e.span.start&&n.span.end===e.span.end)return i}catch(e){}return a.indexOf(e)},d=t=>{if(!o)return a.indexOf(t);const n=e.indexOf(t);if(-1===n)return-1;let i=0;for(let t=0;t<n;t++){const n=e[t];n&&("JSXText"===n.type?r(n)||i++:"JSXExpressionContainer"===n.type?n.expression&&"JSXEmptyExpression"!==n.expression.type&&i++:"JSXElement"===n.type&&i++)}return i};for(let t=0;t<e.length;t++){const g=e[t];if(g){if("JSXText"===g.type){if(r(g))continue;const i=e[t+1],s=e[t-1];if(s&&"JSXElement"===s.type){const i="Identifier"===s.opening?.name?.type?s.opening.name.value:void 0,r=i&&n.has(i),o=0===(s.children||[]).length;if(r&&o&&/^\s*\n\s*/.test(g.value)){const e=g.value.replace(/^\s*\n\s*/,"");if(e){p+=e;continue}continue}if(!r&&/^\s*\n\s*/.test(g.value)){const n=g.value.replace(/^\s*\n\s*/,"");if(n){if(s&&"JSXElement"===s.type&&Array.isArray(s.children)&&0===s.children.length){p+=n;continue}const i=e[t-2];if(i&&"JSXText"===i.type){const e=i.value.replace(/\n\s*$/,""),t=/[A-Za-z0-9]$/.test(e),s=/^[A-Za-z0-9]/.test(n),r=/^[a-z]/.test(n);if(t&&s&&r){p+=n;continue}}p+=" "+n;continue}continue}}if(/\n\s*$/.test(g.value)&&i&&"JSXElement"===i.type){const s=g.value.replace(/\n\s*$/,"");if(s.trim()){const o="Identifier"===i.opening?.name?.type?i.opening.name.value:void 0,l=o&&n.has(o),a=(i.children||[]).length>0,c=/\s\n/.test(g.value),f=e[t+2],y=f&&"JSXText"===f.type&&!r(f)&&/[a-zA-Z0-9]/.test(f.value),d=!!(i.opening&&Array.isArray(i.opening.attributes)&&i.opening.attributes.length>0),x=/^\s/.test(s)&&!/^\n/.test(s),h=s.trim(),v=x?" "+h:h,S=/[A-Za-z0-9]$/.test(h),m=f&&"string"==typeof f.value&&/^[A-Za-z0-9]/.test(f.value.trim()),J=f&&"string"==typeof f.value&&/^[a-z]/.test(f.value.trim()),X=f&&"string"==typeof f.value&&/^\s/.test(f.value)&&!/^\n/.test(f.value),$=d&&a&&y&&!(S&&m&&J&&!c&&!x&&!X),E=f&&"string"==typeof f.value&&/^[,;:!?.]/.test(f.value.trim()),b=$&&!E;S&&m&&J&&!c&&!x&&!X&&u.add(i),p+=c||l&&a||!l&&y&&x||b?v+" ":v;continue}}p+=g.value;continue}if("JSXExpressionContainer"===g.type){const e=g.expression;if(!e)continue;const t=i(e);if(void 0!==t)p+=t;else if("Identifier"===e.type)p+=`{{${e.value}}}`;else if("TsAsExpression"===e.type&&"ObjectExpression"===e.expression?.type){const t=e.expression,n=t.properties.filter(e=>"KeyValueProperty"===e.type&&e.key&&"Identifier"===e.key.type).map(e=>e.key.value);if(n.length>0)p+=n.map(e=>`{{${e}}}`).join("");else{const e=t.properties[0];if(!e||"Identifier"!==e.type)throw new Error("Unrecognized expression in JSX placeholder");p+=`{{${e.value}}}`}}else if("ObjectExpression"===e.type){const t=e.properties[0];if(t&&"KeyValueProperty"===t.type&&t.key&&"Identifier"===t.key.type)p+=`{{${t.key.value}}}`;else{if(!t||"Identifier"!==t.type)throw new Error("Unrecognized expression in JSX placeholder");p+=`{{${t.value}}}`}}else if("MemberExpression"===e.type&&e.property&&"Identifier"===e.property.type)p+=`{{${e.property.value}}}`;else if("CallExpression"===e.type&&"Identifier"===e.callee?.type)p+=`{{${e.callee.value}}}`;else if("ConditionalExpression"===e.type){const t=s(e.consequent),n=s(e.alternate);p+=void 0!==t&&void 0!==n?t.length>=n.length?t:n:void 0!==t?t:void 0!==n?n:""}else if("JSXEmptyExpression"!==e.type)throw new Error(`Unrecognized expression in JSX placeholder: ${e.type}`);continue}if("JSXElement"===g.type){const s=o?d(g):void 0;let u;if(g.opening&&g.opening.name&&"Identifier"===g.opening.name.type&&(u=g.opening.name.value),u&&n.has(u)){const d=g.opening&&Array.isArray(g.opening.attributes)&&g.opening.attributes.length>0,x=g.children||[],h=x.length>0,v=1===x.length&&("JSXText"===x[0]?.type||"JSXExpressionContainer"===x[0]?.type&&void 0!==i(x[0].expression)),S="p"===u;let m=0;if(S&&o&&(m=e.filter(e=>e&&"JSXElement"===e.type&&"p"===e.opening?.name?.value).length),!h||v){const i=v?y(x,void 0):"";if(""!==String(i).trim())if(n.has(u)&&"p"!==u)p+=`<${u}>${f(i)}</${u}>`;else if(S&&o&&m>1)p+=`<${u}>${f(i)}</${u}>`;else if(S){const e=o&&void 0!==s?s:a.indexOf(g);p+=`<${e}>${f(i)}</${e}>`}else{const e=o&&void 0!==s?s:a.indexOf(g);p+=`<${e}>${f(i)}</${e}>`}else{const n=e[t-1];n&&"JSXText"===n.type&&/\n\s*$/.test(n.value)&&(p=p.replace(/\s+$/,"")),p+=`<${u} />`}}else if(d&&!v){const e=x,t=o&&void 0!==s?s:l(g);if(c(e)){const s=new Map;let r=0;for(const t of e)if(t&&"JSXElement"===t.type){const e=t.opening&&t.opening.name&&"Identifier"===t.opening.name.type?t.opening.name.value:void 0;if(e&&n.has(e)){const e=t.opening&&Array.isArray(t.opening.attributes)&&t.opening.attributes.length>0,n=t.children||[],o=1===n.length&&("JSXText"===n[0]?.type||"JSXExpressionContainer"===n[0]?.type&&void 0!==i(n[0].expression));!e&&(!n.length||o)||s.set(t,r++)}else s.set(t,r++)}const o=y(e,s.size?s:void 0);p+=`<${t}>${f(o)}</${t}>`}else{const e=new Map;let s=0;for(const t of x)if(t&&"JSXElement"===t.type){const r=t.opening&&t.opening.name&&"Identifier"===t.opening.name.type?t.opening.name.value:void 0;if(r&&n.has(r)){const n=t.opening&&Array.isArray(t.opening.attributes)&&t.opening.attributes.length>0,r=t.children||[],o=1===r.length&&("JSXText"===r[0]?.type||"JSXExpressionContainer"===r[0]?.type&&void 0!==i(r[0].expression));!n&&(!r.length||o)||e.set(t,s++)}else e.set(t,s++)}const r=y(x,e.size?e:void 0);p+=`<${t}>${f(r)}</${t}>`}}else{const e=a.indexOf(g);if(-1!==e){const t=void 0!==s?s:e;if((()=>{let e=!1;for(const t of x)if(t)if("JSXElement"!==t.type){if("JSXExpressionContainer"===t.type&&-1!==a.indexOf(t))return e;if("JSXText"===t.type&&-1!==a.indexOf(t)){if(r(t))continue;if(!e)return!0;if(x.slice(x.indexOf(t)+1).some(e=>e&&"JSXElement"===e.type))return!0}}else e=!0;return!1})()){if(0===t){const e=y(x,void 0,!1);p+=`<${t}>${f(e)}</${t}>`;continue}const e=new Map;for(const e of x)if(e&&"JSXElement"===e.type){const s=e.opening&&e.opening.name&&"Identifier"===e.opening.name.type?e.opening.name.value:void 0;if(s&&n.has(s)){const n=e.opening&&Array.isArray(e.opening.attributes)&&e.opening.attributes.length>0,s=e.children||[],r=1===s.length&&("JSXText"===s[0]?.type||"JSXExpressionContainer"===s[0]?.type&&void 0!==i(s[0].expression));if(!(!n&&(!s.length||r))){const n=y(e.children,void 0,!1);p+=`<${t}>${f(n)}</${t}>`}}else{const n=y(e.children,void 0,!1);p+=`<${t}>${f(n)}</${t}>`}}const s=y(x,e.size?e:void 0,!1);p+=`<${t}>${f(s)}</${t}>`;continue}const o=new Map;let l=0;for(const e of x)if(e&&"JSXElement"===e.type){const t=e.opening&&e.opening.name&&"Identifier"===e.opening.name.type?e.opening.name.value:void 0;if(t&&n.has(t)){const t=e.opening&&Array.isArray(e.opening.attributes)&&e.opening.attributes.length>0,n=e.children||[],s=1===n.length&&("JSXText"===n[0]?.type||"JSXExpressionContainer"===n[0]?.type&&void 0!==i(n[0].expression));!t&&(!n.length||s)||o.set(e,l++)}else o.set(e,l++)}const c=y(x,o.size>0?o:void 0,!1);p+=`<${t}>${f(c)}</${t}>`}else{const e=y(x,void 0,!1);p+=`<${u}>${f(e)}</${u}>`}}}else{const e=g.children||[];if(e.some(e=>e&&("JSXText"===e.type||"JSXExpressionContainer"===e.type)&&-1!==a.indexOf(e))){const t=a.indexOf(g),n=y(e,void 0);p+=`<${t}>${f(n)}</${t}>`}else{const t=new Map,i=l(g);let s=0;for(const i of e)if(i&&"JSXElement"===i.type){const e=i.opening&&i.opening.name&&"Identifier"===i.opening.name.type?i.opening.name.value:void 0;if(e&&n.has(e)){const e=i.opening&&Array.isArray(i.opening.attributes)&&i.opening.attributes.length>0,n=i.children||[],r=1===n.length&&"JSXText"===n[0]?.type;!e&&(!n.length||r)||t.set(i,s++)}else t.set(i,s++)}const r=y(e,t.size?t:void 0);p+=`<${i}>${f(r)}</${i}>`}}continue}"JSXFragment"!==g.type||(p+=y(g.children||[]))}}return p}const d=y(e,void 0,!0),g=String(d).replace(/<br \/>\s*\n\s*/g,"<br />"),x=String(g),h=new Set;if(u&&u.size>0)for(let e=0;e<a.length;e++)u.has(a[e])&&h.add(e);let v=String(x);if(h&&h.size>0)for(const e of h)try{v=v.replace(new RegExp("\\s+<"+e+">","g"),"<"+e+">"),v=v.replace(new RegExp("<\\/"+e+">\\s+","g"),"</"+e+">")}catch(e){}v=v.replace(/<\/(\d+)>\s*\n\s*(\S)/g,(e,t,n)=>{const i=Number(t);return h.has(i)?`</${t}>${n}`:`</${t}> ${n}`}),v=v.replace(/(\S)\s*\n\s*<(\d+)/g,(e,t,n)=>{const i=Number(n);return h.has(i)?`${t}<${n}`:`${t} <${n}`}),v=v.replace(/\s*\n\s*/g," "),v=v.replace(/\s+/g," "),v=v.replace(/\s+([,;:!?.])/g,"$1");const S=v.trim();let m=String(S);if(h&&h.size>0)for(const e of h)try{m=m.replace(new RegExp("[\\s\\u00A0]+<"+e+">","g"),"<"+e+">"),m=m.replace(new RegExp("<\\/"+e+">[\\s\\u00A0]+","g"),"</"+e+">")}catch(e){}try{for(let e=0;e<a.length;e++){const t=a[e];if(!t||"JSXElement"!==t.type)continue;const n=a[e-1],i=a[e+1];if(!n||!i)continue;if("JSXText"!==n.type||"JSXText"!==i.type)continue;const s=String(n.value),r=String(i.value),o=s.replace(/\n\s*$/,""),p=/[A-Za-z0-9]$/.test(o),l=/^[A-Za-z0-9]/.test(r.trim()),c=/^[a-z]/.test(r.trim()),u=/\s\n/.test(s),f=r&&/^\s/.test(r)&&!/^\n/.test(r);if(p&&l&&c&&!u&&!f){const t=e;m=m.replace(new RegExp("\\s+<"+t+">","g"),"<"+t+">")}}}catch(e){}function J(e){if(!e||!e.includes("<"))return e;function t(e){const t=[],n=[];let i=0;const s=/<\/?(\d+)>|<[^>]+>/g;let r;for(;r=s.exec(e);){const o=r[0],p=r.index;if(p>i){const s={type:"text",text:e.slice(i,p)};n.length?n[n.length-1].node.children.push(s):t.push(s)}const l=/^<\/(\d+)>$/.exec(o),a=/^<(\d+)>$/.exec(o);if(a){const e=Number(a[1]),i={type:"ph",idx:e,children:[]};n.length?n[n.length-1].node.children.push(i):t.push(i),n.push({node:i,idx:e})}else if(l)n.length&&n.pop();else{const e={type:"text",text:o};n.length?n[n.length-1].node.children.push(e):t.push(e)}i=s.lastIndex}if(i<e.length){const s={type:"text",text:e.slice(i)};n.length?n[n.length-1].node.children.push(s):t.push(s)}return t}function i(e,t=null){let s="";for(const o of e)if("text"===o.type)s+=o.text;else{const e=o.children.filter(e=>"ph"===e.type);let p;if("number"==typeof o.idx){const t=a[o.idx];if(t&&Array.isArray(t.children)){const n=new Map;let i=0;for(const e of t.children){const t=a.indexOf(e);if("JSXText"===e.type){if(r(e))continue;-1!==t&&n.set(t,i),i++}else"JSXElement"===e.type?(-1!==t&&n.set(t,i),i++):"JSXExpressionContainer"===e.type&&-1!==t&&(n.set(t,i),i++)}e.every(e=>n.has(e.idx))&&(p=n)}}if(!p){const i=e.map(e=>e.idx);if(i.length<=1||i.every((e,t)=>0===t||e===i[t-1]+1)){p=new Map;let i=0;try{const s=a[o.idx];if(s&&s.span){const r=s.span.start,p=s.span.end;let l=0,c=-1;for(let e=o.idx+1;e<a.length;e++){const t=a[e];if(t&&t.span&&(t.span.start>=r&&t.span.end<=p&&"JSXElement"===t.type)){c=e;break}}if(-1!==c)for(let e=o.idx+1;e<c;e++){const t=a[e];t&&t.span&&(t.span.start>=r&&t.span.end<=p&&("JSXText"!==t.type&&"JSXExpressionContainer"!==t.type||l++))}else for(let e=o.idx+1;e<a.length;e++){const t=a[e];t&&t.span&&(t.span.start>=r&&t.span.end<=p&&("JSXText"!==t.type&&"JSXExpressionContainer"!==t.type||l++))}const u=s?.opening?.name?.value,f=u&&n.has(u),y=null===t;1===e.length&&(i=Math.max(1,l+1),!y||f||0!==e[0].idx||"a"!==u&&"p"!==u||(i=0))}}catch(e){}for(const t of e)p.has(t.idx)||p.set(t.idx,i++)}}const l=o.children.map(e=>{if("text"===e.type)return e.text;const t=e.idx,n=p&&p.has(t)?p.get(t):t;return`<${n}>${i(e.children,n)}</${n}>`}).join("");s+=`<${o.idx}>${l}</${o.idx}>`}return s}try{const n=t(e);return i(n)}catch(t){return e}}return m=J(m),m.trim()}(n.children,o);let X;const $="JSXAttribute"===l?.type?r(l):void 0;if(void 0!==$)X=$;else{const e=o.extract.defaultValue;X="string"==typeof e?e:""}let E,b;if("JSXAttribute"===p?.type){if("StringLiteral"===p.value?.type){if(E=p.value,b=E.value,!b||""===b.trim())return null;if(m&&"StringLiteral"===E.type){const e=o.extract.nsSeparator??":",t=E.value;if(e&&t.startsWith(`${m}${e}`)){if(b=t.slice(`${m}${e}`.length),!b||""===b.trim())return null;E={...E,value:b}}}}else"JSXExpressionContainer"===p.value?.type&&"JSXEmptyExpression"!==p.value.expression.type&&(E=p.value.expression);if(!E)return null}l||!b||J.trim()?!l&&J.trim()&&(X=J):X=b;return{keyExpression:E,serializedChildren:J,ns:m,defaultValue:X,hasCount:f,isOrdinal:x,contextExpression:v,optionsNode:d,explicitDefault:void 0!==$||(e=>{if(!e||!Array.isArray(e.properties))return!1;for(const t of e.properties)if(t&&"KeyValueProperty"===t.type&&t.key){const e="Identifier"===t.key.type&&t.key.value||"StringLiteral"===t.key.type&&t.key.value;if("string"==typeof e&&e.startsWith("defaultValue"))return!0}return!1})(d)}}export{o as extractFromTransComponent};
|
package/package.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"extractor.d.ts","sourceRoot":"","sources":["../../../src/extractor/core/extractor.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,MAAM,EAAE,oBAAoB,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,aAAa,CAAA;AAKtF,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAA;AAK5C;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,wBAAsB,YAAY,CAChC,MAAM,EAAE,oBAAoB,EAC5B,EACE,WAAmB,EACnB,QAAgB,EAChB,uBAA+B,EAC/B,OAAe,EAChB,GAAE;IACD,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,uBAAuB,CAAC,EAAE,OAAO,CAAC;IAClC,OAAO,CAAC,EAAE,OAAO,CAAC;CACd,EACN,MAAM,GAAE,MAA4B,GACnC,OAAO,CAAC,OAAO,CAAC,CA8DlB;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAsB,WAAW,CAC/B,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,MAAM,EAAE,EACjB,WAAW,EAAE,WAAW,EACxB,aAAa,EAAE,aAAa,EAC5B,MAAM,EAAE,IAAI,CAAC,oBAAoB,EAAE,SAAS,CAAC,EAC7C,MAAM,GAAE,MAA4B,GACnC,OAAO,CAAC,IAAI,CAAC,
|
|
1
|
+
{"version":3,"file":"extractor.d.ts","sourceRoot":"","sources":["../../../src/extractor/core/extractor.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,MAAM,EAAE,oBAAoB,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,aAAa,CAAA;AAKtF,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAA;AAK5C;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,wBAAsB,YAAY,CAChC,MAAM,EAAE,oBAAoB,EAC5B,EACE,WAAmB,EACnB,QAAgB,EAChB,uBAA+B,EAC/B,OAAe,EAChB,GAAE;IACD,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,uBAAuB,CAAC,EAAE,OAAO,CAAC;IAClC,OAAO,CAAC,EAAE,OAAO,CAAC;CACd,EACN,MAAM,GAAE,MAA4B,GACnC,OAAO,CAAC,OAAO,CAAC,CA8DlB;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAsB,WAAW,CAC/B,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,MAAM,EAAE,EACjB,WAAW,EAAE,WAAW,EACxB,aAAa,EAAE,aAAa,EAC5B,MAAM,EAAE,IAAI,CAAC,oBAAoB,EAAE,SAAS,CAAC,EAC7C,MAAM,GAAE,MAA4B,GACnC,OAAO,CAAC,IAAI,CAAC,CAiGf;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAsB,OAAO,CAAE,MAAM,EAAE,oBAAoB,EAAE,EAAE,uBAA+B,EAAE,GAAE;IAAE,uBAAuB,CAAC,EAAE,OAAO,CAAA;CAAO,sDAO3I"}
|
|
@@ -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;AA0rBnF;;;;;;;;;;;;;;;;;;;;;;;;;;;;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,EACE,uBAA+B,EAC/B,OAAe,EAChB,GAAE;IACD,uBAAuB,CAAC,EAAE,OAAO,CAAC;IAClC,OAAO,CAAC,EAAE,OAAO,CAAA;CACb,GACL,OAAO,CAAC,iBAAiB,EAAE,CAAC,CAoI9B"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"jsx-handler.d.ts","sourceRoot":"","sources":["../../../src/extractor/parsers/jsx-handler.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAoB,MAAM,WAAW,CAAA;AAC7D,OAAO,KAAK,EAAE,aAAa,EAAE,oBAAoB,EAAgB,MAAM,aAAa,CAAA;AACpF,OAAO,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAA;AAI1D,qBAAa,UAAU;IACrB,OAAO,CAAC,MAAM,CAAuC;IACrD,OAAO,CAAC,aAAa,CAAe;IACpC,OAAO,CAAC,kBAAkB,CAAoB;IAC9C,OAAO,CAAC,cAAc,CAAc;IACpC,OAAO,CAAC,cAAc,CAAc;IACpC,OAAO,CAAC,eAAe,CAAY;gBAGjC,MAAM,EAAE,IAAI,CAAC,oBAAoB,EAAE,SAAS,CAAC,EAC7C,aAAa,EAAE,aAAa,EAC5B,kBAAkB,EAAE,kBAAkB,EACtC,cAAc,EAAE,MAAM,MAAM,EAC5B,cAAc,EAAE,MAAM,MAAM;IAS9B;;OAEG;IACI,gBAAgB,IAAK,IAAI;IAIhC;;OAEG;IACH,OAAO,CAAC,mBAAmB;IA8B3B;;;;;;;;OAQG;IACH,gBAAgB,CAAE,IAAI,EAAE,UAAU,EAAE,YAAY,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK;QAAE,SAAS,CAAC,EAAE,MAAM,CAAC;QAAC,SAAS,CAAC,EAAE,MAAM,CAAA;KAAE,GAAG,SAAS,GAAG,IAAI;
|
|
1
|
+
{"version":3,"file":"jsx-handler.d.ts","sourceRoot":"","sources":["../../../src/extractor/parsers/jsx-handler.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAoB,MAAM,WAAW,CAAA;AAC7D,OAAO,KAAK,EAAE,aAAa,EAAE,oBAAoB,EAAgB,MAAM,aAAa,CAAA;AACpF,OAAO,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAA;AAI1D,qBAAa,UAAU;IACrB,OAAO,CAAC,MAAM,CAAuC;IACrD,OAAO,CAAC,aAAa,CAAe;IACpC,OAAO,CAAC,kBAAkB,CAAoB;IAC9C,OAAO,CAAC,cAAc,CAAc;IACpC,OAAO,CAAC,cAAc,CAAc;IACpC,OAAO,CAAC,eAAe,CAAY;gBAGjC,MAAM,EAAE,IAAI,CAAC,oBAAoB,EAAE,SAAS,CAAC,EAC7C,aAAa,EAAE,aAAa,EAC5B,kBAAkB,EAAE,kBAAkB,EACtC,cAAc,EAAE,MAAM,MAAM,EAC5B,cAAc,EAAE,MAAM,MAAM;IAS9B;;OAEG;IACI,gBAAgB,IAAK,IAAI;IAIhC;;OAEG;IACH,OAAO,CAAC,mBAAmB;IA8B3B;;;;;;;;OAQG;IACH,gBAAgB,CAAE,IAAI,EAAE,UAAU,EAAE,YAAY,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK;QAAE,SAAS,CAAC,EAAE,MAAM,CAAC;QAAC,SAAS,CAAC,EAAE,MAAM,CAAA;KAAE,GAAG,SAAS,GAAG,IAAI;IAwUjI;;;;;;;;;;;OAWG;IACH,OAAO,CAAC,0BAA0B;IAqGlC;;;;;;;;;OASG;IACH,OAAO,CAAC,cAAc;CAevB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"jsx-parser.d.ts","sourceRoot":"","sources":["../../../src/extractor/parsers/jsx-parser.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAgB,UAAU,EAAiB,gBAAgB,EAAE,MAAM,WAAW,CAAA;AACtG,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAA;AAGvD,MAAM,WAAW,sBAAsB;IACrC,gDAAgD;IAChD,aAAa,CAAC,EAAE,UAAU,CAAC;IAE3B,qDAAqD;IACrD,kBAAkB,EAAE,MAAM,CAAC;IAE3B,mDAAmD;IACnD,YAAY,CAAC,EAAE,MAAM,CAAC;IAEtB,8DAA8D;IAC9D,EAAE,CAAC,EAAE,MAAM,CAAC;IAEZ,oEAAoE;IACpE,QAAQ,CAAC,EAAE,OAAO,CAAC;IAEnB,0DAA0D;IAC1D,SAAS,CAAC,EAAE,OAAO,CAAC;IAEpB,8EAA8E;IAC9E,WAAW,CAAC,EAAE,gBAAgB,CAAC;IAE/B,mDAAmD;IACnD,iBAAiB,CAAC,EAAE,UAAU,CAAC;IAE/B,kHAAkH;IAClH,eAAe,CAAC,EAAE,OAAO,CAAC;CAC3B;
|
|
1
|
+
{"version":3,"file":"jsx-parser.d.ts","sourceRoot":"","sources":["../../../src/extractor/parsers/jsx-parser.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAgB,UAAU,EAAiB,gBAAgB,EAAE,MAAM,WAAW,CAAA;AACtG,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAA;AAGvD,MAAM,WAAW,sBAAsB;IACrC,gDAAgD;IAChD,aAAa,CAAC,EAAE,UAAU,CAAC;IAE3B,qDAAqD;IACrD,kBAAkB,EAAE,MAAM,CAAC;IAE3B,mDAAmD;IACnD,YAAY,CAAC,EAAE,MAAM,CAAC;IAEtB,8DAA8D;IAC9D,EAAE,CAAC,EAAE,MAAM,CAAC;IAEZ,oEAAoE;IACpE,QAAQ,CAAC,EAAE,OAAO,CAAC;IAEnB,0DAA0D;IAC1D,SAAS,CAAC,EAAE,OAAO,CAAC;IAEpB,8EAA8E;IAC9E,WAAW,CAAC,EAAE,gBAAgB,CAAC;IAE/B,mDAAmD;IACnD,iBAAiB,CAAC,EAAE,UAAU,CAAC;IAE/B,kHAAkH;IAClH,eAAe,CAAC,EAAE,OAAO,CAAC;CAC3B;AAuDD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH,wBAAgB,yBAAyB,CAAE,IAAI,EAAE,UAAU,EAAE,MAAM,EAAE,oBAAoB,GAAG,sBAAsB,GAAG,IAAI,CA2LxH"}
|