@intlayer/vue-compiler 8.9.2 → 8.9.4-canary.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"extractVueFieldUsage.cjs","names":["vueSfc"],"sources":["../../src/extractVueFieldUsage.ts"],"sourcesContent":["/**\n * Extracts intlayer dictionary field usage from a Vue SFC for a set of\n * plain variable bindings (i.e. `const content = useIntlayer('key')`).\n *\n * Two access patterns are recognised:\n *\n * 1. `varName.value.fieldName` in script blocks\n * Vue's `useIntlayer` returns a reactive `Ref<Content>`, so fields are\n * accessed one level deeper via `.value`.\n *\n * 2. `varName.fieldName` in the template block\n * Inside `<template>`, Vue automatically unwraps top-level refs, so\n * fields are accessed directly without `.value`.\n *\n * The template block is extracted via `@vue/compiler-sfc` so that nested\n * `<template v-for>` / `<template v-if>` tags do not confuse the parser.\n * Falls back to a greedy regex when the package is unavailable.\n */\n\nimport vueSfc from '@vue/compiler-sfc';\n\n/** Escapes special regex characters in a string used as a regex literal. */\nconst escapeRegExp = (str: string): string =>\n str.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\$&');\n\n/** Input descriptor for a single plain variable binding. */\nexport type PlainVariableInfo = {\n /** The local variable name in the script (`content` in `const content = useIntlayer(…)`). */\n variableName: string;\n /** The intlayer dictionary key passed to `useIntlayer`. */\n dictionaryKey: string;\n};\n\n/**\n * Splits a Vue SFC source string into its script and template regions.\n *\n * Uses `@vue/compiler-sfc` to get exact character offsets so that nested\n * `<template>` tags (used by Vue directives like `v-for` / `v-if`) never\n * cause the template region to be mis-identified.\n */\nconst splitVueSfc = (\n code: string\n): { scriptSource: string; templateSource: string } => {\n try {\n const { descriptor } = (\n vueSfc.parse as (src: string) => { descriptor: any }\n )(code);\n\n const templateSource: string = descriptor.template?.content ?? '';\n\n const scriptParts: string[] = [];\n if (descriptor.script?.content) scriptParts.push(descriptor.script.content);\n if (descriptor.scriptSetup?.content)\n scriptParts.push(descriptor.scriptSetup.content);\n const scriptSource = scriptParts.join('\\n');\n\n return { scriptSource, templateSource };\n } catch {\n // @vue/compiler-sfc not available or parse failed.\n // Fall back: use a greedy regex to capture everything between the\n // outermost <template> tags (robust against nested tags unlike the\n // non-greedy variant).\n const templateMatch = /<template(?:[^>]*)>([\\s\\S]*)<\\/template>/i.exec(\n code\n );\n const templateSource = templateMatch ? templateMatch[1] : '';\n const scriptSource = code.replace(/<template[\\s\\S]*<\\/template>/gi, '');\n return { scriptSource, templateSource };\n }\n};\n\n/**\n * Analyzes a Vue SFC source string and returns the top-level content field\n * names that are statically accessed for each plain intlayer variable binding.\n *\n * @param code - Full `.vue` file source.\n * @param plainVariables - List of plain variable bindings to analyse.\n * @returns Map from dictionary key to the set of accessed top-level field names.\n * If no fields can be determined for a given key it is omitted from the\n * map so the caller can fall back to `'all'`.\n */\nexport const extractVueIntlayerFieldUsage = (\n code: string,\n plainVariables: PlainVariableInfo[]\n): Map<string, Set<string>> => {\n const result = new Map<string, Set<string>>();\n\n if (plainVariables.length === 0) return result;\n\n const { scriptSource, templateSource } = splitVueSfc(code);\n\n for (const { variableName, dictionaryKey } of plainVariables) {\n const fields = new Set<string>();\n const esc = escapeRegExp(variableName);\n\n // ── 1. Script pattern: varName.value.fieldName ─────────────────────────\n // Vue's reactive ref accessor; the actual content fields live one level\n // deeper than the variable itself.\n const scriptRe = new RegExp(`\\\\b${esc}\\\\.value\\\\.(\\\\w+)`, 'g');\n scriptRe.lastIndex = 0;\n for (\n let m = scriptRe.exec(scriptSource);\n m !== null;\n m = scriptRe.exec(scriptSource)\n ) {\n const field = m[1];\n // Skip chained `.value.value` artefacts\n if (field !== 'value') fields.add(field);\n }\n\n // ── 2. Template pattern: varName.fieldName ─────────────────────────────\n // Inside `<template>` Vue auto-unwraps refs, so content is accessed\n // directly without `.value`.\n if (templateSource) {\n const templateRe = new RegExp(`\\\\b${esc}\\\\.(\\\\w+)`, 'g');\n\n templateRe.lastIndex = 0;\n for (\n let m = templateRe.exec(templateSource);\n m !== null;\n m = templateRe.exec(templateSource)\n ) {\n fields.add(m[1]);\n }\n }\n\n if (fields.size > 0) {\n result.set(dictionaryKey, fields);\n }\n }\n\n return result;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAsBA,MAAM,gBAAgB,QACpB,IAAI,QAAQ,uBAAuB,OAAO;;;;;;;;AAiB5C,MAAM,eACJ,SACqD;
|
|
1
|
+
{"version":3,"file":"extractVueFieldUsage.cjs","names":["vueSfc"],"sources":["../../src/extractVueFieldUsage.ts"],"sourcesContent":["/**\n * Extracts intlayer dictionary field usage from a Vue SFC for a set of\n * plain variable bindings (i.e. `const content = useIntlayer('key')`).\n *\n * Two access patterns are recognised:\n *\n * 1. `varName.value.fieldName` in script blocks\n * Vue's `useIntlayer` returns a reactive `Ref<Content>`, so fields are\n * accessed one level deeper via `.value`.\n *\n * 2. `varName.fieldName` in the template block\n * Inside `<template>`, Vue automatically unwraps top-level refs, so\n * fields are accessed directly without `.value`.\n *\n * The template block is extracted via `@vue/compiler-sfc` so that nested\n * `<template v-for>` / `<template v-if>` tags do not confuse the parser.\n * Falls back to a greedy regex when the package is unavailable.\n */\n\nimport vueSfc from '@vue/compiler-sfc';\n\n/** Escapes special regex characters in a string used as a regex literal. */\nconst escapeRegExp = (str: string): string =>\n str.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\$&');\n\n/** Input descriptor for a single plain variable binding. */\nexport type PlainVariableInfo = {\n /** The local variable name in the script (`content` in `const content = useIntlayer(…)`). */\n variableName: string;\n /** The intlayer dictionary key passed to `useIntlayer`. */\n dictionaryKey: string;\n};\n\n/**\n * Splits a Vue SFC source string into its script and template regions.\n *\n * Uses `@vue/compiler-sfc` to get exact character offsets so that nested\n * `<template>` tags (used by Vue directives like `v-for` / `v-if`) never\n * cause the template region to be mis-identified.\n */\nconst splitVueSfc = (\n code: string\n): { scriptSource: string; templateSource: string } => {\n try {\n const { descriptor } = (\n vueSfc.parse as (src: string) => { descriptor: any }\n )(code);\n\n const templateSource: string = descriptor.template?.content ?? '';\n\n const scriptParts: string[] = [];\n if (descriptor.script?.content) scriptParts.push(descriptor.script.content);\n if (descriptor.scriptSetup?.content)\n scriptParts.push(descriptor.scriptSetup.content);\n const scriptSource = scriptParts.join('\\n');\n\n return { scriptSource, templateSource };\n } catch {\n // @vue/compiler-sfc not available or parse failed.\n // Fall back: use a greedy regex to capture everything between the\n // outermost <template> tags (robust against nested tags unlike the\n // non-greedy variant).\n const templateMatch = /<template(?:[^>]*)>([\\s\\S]*)<\\/template>/i.exec(\n code\n );\n const templateSource = templateMatch ? templateMatch[1] : '';\n const scriptSource = code.replace(/<template[\\s\\S]*<\\/template>/gi, '');\n return { scriptSource, templateSource };\n }\n};\n\n/**\n * Analyzes a Vue SFC source string and returns the top-level content field\n * names that are statically accessed for each plain intlayer variable binding.\n *\n * @param code - Full `.vue` file source.\n * @param plainVariables - List of plain variable bindings to analyse.\n * @returns Map from dictionary key to the set of accessed top-level field names.\n * If no fields can be determined for a given key it is omitted from the\n * map so the caller can fall back to `'all'`.\n */\nexport const extractVueIntlayerFieldUsage = (\n code: string,\n plainVariables: PlainVariableInfo[]\n): Map<string, Set<string>> => {\n const result = new Map<string, Set<string>>();\n\n if (plainVariables.length === 0) return result;\n\n const { scriptSource, templateSource } = splitVueSfc(code);\n\n for (const { variableName, dictionaryKey } of plainVariables) {\n const fields = new Set<string>();\n const esc = escapeRegExp(variableName);\n\n // ── 1. Script pattern: varName.value.fieldName ─────────────────────────\n // Vue's reactive ref accessor; the actual content fields live one level\n // deeper than the variable itself.\n const scriptRe = new RegExp(`\\\\b${esc}\\\\.value\\\\.(\\\\w+)`, 'g');\n scriptRe.lastIndex = 0;\n for (\n let m = scriptRe.exec(scriptSource);\n m !== null;\n m = scriptRe.exec(scriptSource)\n ) {\n const field = m[1];\n // Skip chained `.value.value` artefacts\n if (field !== 'value') fields.add(field);\n }\n\n // ── 2. Template pattern: varName.fieldName ─────────────────────────────\n // Inside `<template>` Vue auto-unwraps refs, so content is accessed\n // directly without `.value`.\n if (templateSource) {\n const templateRe = new RegExp(`\\\\b${esc}\\\\.(\\\\w+)`, 'g');\n\n templateRe.lastIndex = 0;\n for (\n let m = templateRe.exec(templateSource);\n m !== null;\n m = templateRe.exec(templateSource)\n ) {\n fields.add(m[1]);\n }\n }\n\n if (fields.size > 0) {\n result.set(dictionaryKey, fields);\n }\n }\n\n return result;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAsBA,MAAM,gBAAgB,QACpB,IAAI,QAAQ,uBAAuB,OAAO;;;;;;;;AAiB5C,MAAM,eACJ,SACqD;CACrD,IAAI;EACF,MAAM,EAAE,eACNA,0BAAO,MACP,KAAK;EAEP,MAAM,iBAAyB,WAAW,UAAU,WAAW;EAE/D,MAAM,cAAwB,EAAE;EAChC,IAAI,WAAW,QAAQ,SAAS,YAAY,KAAK,WAAW,OAAO,QAAQ;EAC3E,IAAI,WAAW,aAAa,SAC1B,YAAY,KAAK,WAAW,YAAY,QAAQ;EAGlD,OAAO;GAAE,cAFY,YAAY,KAAK,KAEjB;GAAE;GAAgB;SACjC;EAKN,MAAM,gBAAgB,4CAA4C,KAChE,KACD;EACD,MAAM,iBAAiB,gBAAgB,cAAc,KAAK;EAE1D,OAAO;GAAE,cADY,KAAK,QAAQ,kCAAkC,GAC/C;GAAE;GAAgB;;;;;;;;;;;;;AAc3C,MAAa,gCACX,MACA,mBAC6B;CAC7B,MAAM,yBAAS,IAAI,KAA0B;CAE7C,IAAI,eAAe,WAAW,GAAG,OAAO;CAExC,MAAM,EAAE,cAAc,mBAAmB,YAAY,KAAK;CAE1D,KAAK,MAAM,EAAE,cAAc,mBAAmB,gBAAgB;EAC5D,MAAM,yBAAS,IAAI,KAAa;EAChC,MAAM,MAAM,aAAa,aAAa;EAKtC,MAAM,WAAW,IAAI,OAAO,MAAM,IAAI,oBAAoB,IAAI;EAC9D,SAAS,YAAY;EACrB,KACE,IAAI,IAAI,SAAS,KAAK,aAAa,EACnC,MAAM,MACN,IAAI,SAAS,KAAK,aAAa,EAC/B;GACA,MAAM,QAAQ,EAAE;GAEhB,IAAI,UAAU,SAAS,OAAO,IAAI,MAAM;;EAM1C,IAAI,gBAAgB;GAClB,MAAM,aAAa,IAAI,OAAO,MAAM,IAAI,YAAY,IAAI;GAExD,WAAW,YAAY;GACvB,KACE,IAAI,IAAI,WAAW,KAAK,eAAe,EACvC,MAAM,MACN,IAAI,WAAW,KAAK,eAAe,EAEnC,OAAO,IAAI,EAAE,GAAG;;EAIpB,IAAI,OAAO,OAAO,GAChB,OAAO,IAAI,eAAe,OAAO;;CAIrC,OAAO"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"vue-intlayer-extract.cjs","names":["t","DEFAULT_LOCALE","vueSfc","MagicString"],"sources":["../../src/vue-intlayer-extract.ts"],"sourcesContent":["import { readFileSync, writeFileSync } from 'node:fs';\nimport { parse as babelParse, types as t, traverse } from '@babel/core';\nimport { DEFAULT_LOCALE } from '@intlayer/config/defaultValues';\nimport type { Locale } from '@intlayer/types/allLocales';\nimport vueSfc from '@vue/compiler-sfc';\nimport MagicString from 'magic-string';\n\ntype ExistingCallInfo = {\n isDestructured: boolean;\n existingDestructuredKeys: string[];\n /** The variable name used to store the call result (e.g. `t` in `const t = useIntlayer(...)`) */\n variableName: string;\n /** Absolute position of `}` in the full file — only valid when `isDestructured` */\n closingBraceAbsolutePos: number;\n /** Absolute position of end of last property — only valid when `isDestructured` */\n lastPropAbsoluteEnd: number;\n} | null;\n\n/**\n * Detects whether the script block already contains a `useIntlayer` /\n * `getIntlayer` call and, if so, whether its result is destructured.\n *\n * @param scriptText Raw text of the script block content.\n * @param absoluteOffset Byte offset of `scriptText[0]` in the full SFC source.\n */\nconst detectExistingIntlayerCall = (\n scriptText: string,\n absoluteOffset: number\n): ExistingCallInfo => {\n let info: ExistingCallInfo = null;\n\n try {\n const ast = babelParse(scriptText, {\n parserOpts: { sourceType: 'module', plugins: ['typescript', 'jsx'] },\n });\n\n if (!ast) return null;\n\n traverse(ast, {\n CallExpression(path: any) {\n const callee = path.node.callee;\n\n if (\n !t.isIdentifier(callee) ||\n (callee.name !== 'useIntlayer' && callee.name !== 'getIntlayer')\n )\n return;\n\n const parent = path.parent;\n\n if (t.isVariableDeclarator(parent) && t.isObjectPattern(parent.id)) {\n const properties = parent.id.properties;\n const existingDestructuredKeys = properties\n .filter(\n (property: any): property is typeof t.objectProperty =>\n t.isObjectProperty(property) && t.isIdentifier(property.key)\n )\n .map((property: any) => (property.key as any).name as string);\n const lastProp = properties[properties.length - 1];\n\n info = {\n isDestructured: true,\n variableName: 'content',\n existingDestructuredKeys,\n closingBraceAbsolutePos: absoluteOffset + (parent.id.end! - 1),\n lastPropAbsoluteEnd: absoluteOffset + lastProp.end!,\n };\n } else {\n const variableName =\n t.isVariableDeclarator(parent) && t.isIdentifier(parent.id)\n ? parent.id.name\n : 'content';\n\n info = {\n isDestructured: false,\n variableName,\n existingDestructuredKeys: [],\n closingBraceAbsolutePos: -1,\n lastPropAbsoluteEnd: -1,\n };\n }\n\n path.stop();\n },\n });\n } catch {\n // Silently ignore parse failures — fall back to no-info\n }\n\n return info;\n};\n\nexport type ExtractedContent = Record<string, string>;\n\nexport type ExtractResult = {\n dictionaryKey: string;\n filePath: string;\n content: ExtractedContent;\n locale: Locale;\n};\n\nexport type ExtractPluginOptions = {\n defaultLocale?: Locale;\n packageName?: string;\n filesList?: string[];\n shouldExtract?: (text: string) => boolean;\n onExtract?: (result: ExtractResult) => void;\n dictionaryKey?: string;\n attributesToExtract?: readonly string[];\n extractDictionaryKeyFromPath?: (path: string) => string;\n generateKey?: (text: string, existingKeys: Set<string>) => string;\n};\n\ntype Replacement = {\n start: number;\n end: number;\n replacement: string;\n key: string;\n value: string;\n};\n\nexport const shouldProcessFile = (\n filename: string | undefined,\n filesList?: string[]\n): boolean => {\n if (!filename) return false;\n if (!filesList || filesList.length === 0) return true;\n\n const normalizedFilename = filename.replace(/\\\\/g, '/');\n return filesList.some((f) => {\n const normalizedF = f.replace(/\\\\/g, '/');\n return normalizedF === normalizedFilename;\n });\n};\n\ntype VueParseResult = {\n descriptor: {\n template?: {\n ast: VueAstNode;\n loc: { start: { offset: number }; end: { offset: number } };\n };\n script?: {\n content: string;\n loc: { start: { offset: number }; end: { offset: number } };\n };\n scriptSetup?: {\n content: string;\n loc: { start: { offset: number }; end: { offset: number } };\n };\n };\n};\n\ntype VueAstNode = {\n type: number;\n content?: string;\n children?: VueAstNode[];\n props?: VueAstProp[];\n loc: { start: { offset: number }; end: { offset: number } };\n};\n\ntype VueAstProp = {\n type: number;\n name: string;\n value?: { content: string };\n loc: { start: { offset: number }; end: { offset: number } };\n};\n\nconst NODE_TYPES = {\n TEXT: 2,\n ELEMENT: 1,\n ATTRIBUTE: 6,\n INTERPOLATION: 5,\n};\n\nexport const intlayerVueExtract = (\n code: string,\n filename: string,\n options: ExtractPluginOptions = {}\n): { code: string; map?: unknown; extracted: boolean } | null => {\n const {\n defaultLocale = DEFAULT_LOCALE,\n packageName = 'vue-intlayer',\n filesList,\n shouldExtract,\n onExtract,\n dictionaryKey: dictionaryKeyOption,\n attributesToExtract = [],\n extractDictionaryKeyFromPath,\n generateKey,\n } = options;\n\n if (!shouldProcessFile(filename, filesList)) return null;\n if (!filename.endsWith('.vue')) return null;\n\n let parseVue: (code: string) => VueParseResult;\n\n try {\n parseVue = vueSfc.parse as unknown as (code: string) => VueParseResult;\n } catch {\n console.warn('Vue extraction: @vue/compiler-sfc not found.');\n return null;\n }\n\n const sfc = parseVue(code);\n const magic = new MagicString(code);\n\n const extractedContent: ExtractedContent = {};\n const existingKeys = new Set<string>();\n const dictionaryKey =\n dictionaryKeyOption ?? extractDictionaryKeyFromPath?.(filename) ?? '';\n const replacements: Replacement[] = [];\n\n // Detect existing useIntlayer / getIntlayer call in the script block BEFORE\n // walking the template, so the correct access pattern can be chosen.\n const scriptBlock = sfc.descriptor.scriptSetup ?? sfc.descriptor.script;\n const existingCallInfo = scriptBlock\n ? detectExistingIntlayerCall(\n scriptBlock.content,\n scriptBlock.loc.start.offset\n )\n : null;\n\n const isDestructured = existingCallInfo?.isDestructured ?? false;\n const varName = existingCallInfo?.variableName ?? 'content';\n\n // Walk Vue Template AST\n if (sfc.descriptor.template) {\n const walkVueAst = (node: VueAstNode) => {\n if (node.type === NODE_TYPES.TEXT) {\n const text = node.content ?? '';\n\n if (shouldExtract?.(text) && generateKey) {\n const key = generateKey(text, existingKeys);\n existingKeys.add(key);\n // When the existing call is destructured, access the key directly;\n // otherwise use the `content` variable.\n const ref = isDestructured ? key : `${varName}.${key}`;\n replacements.push({\n start: node.loc.start.offset,\n end: node.loc.end.offset,\n replacement: `{{ ${ref} }}`,\n key,\n value: text.replace(/\\s+/g, ' ').trim(),\n });\n }\n } else if (node.type === NODE_TYPES.ELEMENT) {\n const children = node.children ?? [];\n\n // Try to handle as insertion (mixed TEXT + INTERPOLATION children)\n if (\n children.length > 0 &&\n children.some((c) => c.type === NODE_TYPES.INTERPOLATION)\n ) {\n const parts: {\n type: 'text' | 'var';\n value: string;\n originalExpr: string;\n }[] = [];\n let hasSignificantText = false;\n let isValid = true;\n\n for (const child of children) {\n if (child.type === NODE_TYPES.TEXT) {\n const text = child.content ?? '';\n if (text.trim().length > 0) hasSignificantText = true;\n parts.push({ type: 'text', value: text, originalExpr: '' });\n } else if (child.type === NODE_TYPES.INTERPOLATION) {\n // Extract the expression source between {{ and }}\n const exprCode = code\n .slice(child.loc.start.offset + 2, child.loc.end.offset - 2)\n .trim();\n const varName = exprCode.includes('.')\n ? exprCode\n .split('.')\n .pop()!\n .replace(/[^\\w$]/g, '')\n : exprCode;\n parts.push({\n type: 'var',\n value: varName,\n originalExpr: exprCode,\n });\n } else {\n isValid = false;\n break;\n }\n }\n\n if (\n isValid &&\n hasSignificantText &&\n parts.some((p) => p.type === 'var')\n ) {\n let combined = '';\n for (const p of parts) {\n combined += p.type === 'var' ? `{{${p.value}}}` : p.value;\n }\n const cleanString = combined.replace(/\\s+/g, ' ').trim();\n\n if (shouldExtract?.(cleanString) && generateKey) {\n const key = generateKey(cleanString, existingKeys);\n existingKeys.add(key);\n const ref = isDestructured ? key : `${varName}.${key}`;\n\n const uniqueVarPairs = [\n ...new Set(\n parts\n .filter((p) => p.type === 'var')\n .map((p) => `${p.value}: ${p.originalExpr}`)\n ),\n ];\n const varArgs = uniqueVarPairs.join(', ');\n const replacement = `{{ ${ref}({ ${varArgs} }) }}`;\n\n const firstChild = children[0];\n const lastChild = children[children.length - 1];\n replacements.push({\n start: firstChild.loc.start.offset,\n end: lastChild.loc.end.offset,\n replacement,\n key,\n value: cleanString,\n });\n\n // Process props but skip children (they are replaced)\n node.props?.forEach((prop) => {\n if (\n prop.type === NODE_TYPES.ATTRIBUTE &&\n (attributesToExtract as readonly string[]).includes(\n prop.name\n ) &&\n prop.value\n ) {\n const text = prop.value.content;\n if (shouldExtract?.(text) && generateKey) {\n const propKey = generateKey(text, existingKeys);\n existingKeys.add(propKey);\n const propRef = isDestructured\n ? propKey\n : `${varName}.${propKey}`;\n replacements.push({\n start: prop.loc.start.offset,\n end: prop.loc.end.offset,\n replacement: `:${prop.name}=\"${propRef}\"`,\n key: propKey,\n value: text.trim(),\n });\n }\n }\n });\n return; // don't recurse into children\n }\n }\n }\n\n // Regular element: handle props\n node.props?.forEach((prop) => {\n if (\n prop.type === NODE_TYPES.ATTRIBUTE &&\n (attributesToExtract as readonly string[]).includes(prop.name) &&\n prop.value\n ) {\n const text = prop.value.content;\n\n if (shouldExtract?.(text) && generateKey) {\n const key = generateKey(text, existingKeys);\n existingKeys.add(key);\n const ref = isDestructured ? key : `${varName}.${key}`;\n replacements.push({\n start: prop.loc.start.offset,\n end: prop.loc.end.offset,\n replacement: `:${prop.name}=\"${ref}\"`,\n key,\n value: text.trim(),\n });\n }\n }\n });\n }\n\n if (node.children) {\n node.children.forEach(walkVueAst);\n }\n };\n\n walkVueAst(sfc.descriptor.template.ast);\n }\n\n // Extract and Walk Script using Babel\n if (scriptBlock) {\n const scriptText = scriptBlock.content;\n const offset = scriptBlock.loc.start.offset;\n\n try {\n const ast = babelParse(scriptText, {\n parserOpts: {\n sourceType: 'module',\n plugins: ['typescript', 'jsx'],\n },\n });\n\n if (ast) {\n traverse(ast, {\n StringLiteral(path: any) {\n if (path.parentPath.isImportDeclaration()) return;\n\n if (path.parentPath.isExportDeclaration()) return;\n\n if (path.parentPath.isImportSpecifier()) return;\n\n if (path.parentPath.isObjectProperty() && path.key === 'key')\n return;\n\n if (path.parentPath.isCallExpression()) {\n const callee = path.parentPath.node.callee;\n\n if (\n t.isMemberExpression(callee) &&\n t.isIdentifier(callee.object) &&\n callee.object.name === 'console'\n )\n return;\n\n if (\n t.isIdentifier(callee) &&\n (callee.name === 'useIntlayer' || callee.name === 't')\n )\n return;\n\n if (callee.type === 'Import') return;\n\n if (t.isIdentifier(callee) && callee.name === 'require') return;\n }\n\n const text = path.node.value;\n\n if (shouldExtract?.(text) && generateKey) {\n const key = generateKey(text, existingKeys);\n existingKeys.add(key);\n\n if (path.node.start != null && path.node.end != null) {\n const ref = isDestructured ? key : `${varName}.${key}`;\n replacements.push({\n start: offset + path.node.start,\n end: offset + path.node.end,\n replacement: ref,\n key,\n value: text.trim(),\n });\n }\n }\n },\n });\n }\n } catch (e) {\n console.warn(\n `Vue extraction: Failed to parse script content for ${filename}`,\n e\n );\n }\n }\n\n // Abort if nothing was extracted\n if (replacements.length === 0) return null;\n\n // Apply Replacements in Reverse Order\n replacements.sort((a, b) => b.start - a.start);\n\n for (const { start, end, replacement, key, value } of replacements) {\n magic.overwrite(start, end, replacement);\n extractedContent[key] = value;\n }\n\n // When the existing call is destructured, inject only the missing keys into\n // the ObjectPattern — no new `content` variable is needed.\n if (\n existingCallInfo?.isDestructured &&\n existingCallInfo.closingBraceAbsolutePos >= 0\n ) {\n const missingKeys = Object.keys(extractedContent).filter(\n (k) => !existingCallInfo.existingDestructuredKeys.includes(k)\n );\n\n if (missingKeys.length > 0) {\n // Insert right after the last property so the space/newline before `}`\n // is naturally preserved: `{ a }` → `{ a, b }`.\n magic.appendLeft(\n existingCallInfo.lastPropAbsoluteEnd,\n `, ${missingKeys.join(', ')}`\n );\n }\n }\n\n // Inject necessary imports and setup (only when no existing call was detected)\n const finalScriptContent = scriptBlock?.content ?? '';\n\n const hasUseIntlayerImport =\n /import\\s*{[^}]*useIntlayer[^}]*}\\s*from\\s*['\"][^'\"]+['\"]/.test(\n finalScriptContent\n ) ||\n /import\\s+useIntlayer\\s+from\\s*['\"][^'\"]+['\"]/.test(finalScriptContent);\n\n // An existing call (destructured or not) means no new declaration is needed.\n const hasContentDeclaration =\n existingCallInfo !== null ||\n /const\\s+content\\s*=\\s*useIntlayer\\s*\\(/.test(finalScriptContent);\n\n const importStmt = hasUseIntlayerImport\n ? ''\n : `import { useIntlayer } from '${packageName}';`;\n const contentDecl = hasContentDeclaration\n ? ''\n : `const content = useIntlayer('${dictionaryKey}');`;\n\n const injectionParts = [importStmt, contentDecl].filter(Boolean);\n\n if (injectionParts.length > 0) {\n const injection = `\\n${injectionParts.join('\\n')}\\n`;\n\n if (sfc.descriptor.scriptSetup) {\n magic.appendLeft(sfc.descriptor.scriptSetup.loc.start.offset, injection);\n } else if (sfc.descriptor.script) {\n magic.appendLeft(sfc.descriptor.script.loc.start.offset, injection);\n } else {\n magic.prepend(\n `<script setup>\\n${importStmt}\\n${contentDecl}\\n</script>\\n`\n );\n }\n }\n\n if (onExtract) {\n onExtract({\n dictionaryKey,\n filePath: filename,\n content: { ...extractedContent },\n locale: defaultLocale,\n });\n }\n\n return {\n code: magic.toString(),\n map: magic.generateMap({ source: filename, includeContent: true }),\n extracted: true,\n };\n};\n\ntype Tools = {\n generateKey: (text: string, existingKeys: Set<string>) => string;\n shouldExtract: (text: string) => boolean;\n extractDictionaryKeyFromPath: (path: string) => string;\n attributesToExtract: readonly string[];\n extractTsContent: any;\n};\n\nexport const processVueFile = (\n filePath: string,\n _componentKey: string,\n packageName: string,\n tools: Tools,\n save: boolean = true,\n providedCode?: string\n): {\n extractedContent: Record<string, string>;\n code: string;\n map?: any;\n} | null => {\n const code = providedCode ?? readFileSync(filePath, 'utf-8');\n let extractedContent: Record<string, string> = {};\n\n const result = intlayerVueExtract(code, filePath, {\n packageName,\n dictionaryKey: _componentKey,\n shouldExtract: tools.shouldExtract,\n generateKey: tools.generateKey,\n extractDictionaryKeyFromPath: tools.extractDictionaryKeyFromPath,\n attributesToExtract: tools.attributesToExtract,\n onExtract: (extractResult) => {\n extractedContent = extractResult.content;\n },\n });\n\n if (!result) return null;\n\n if (save) {\n writeFileSync(filePath, result.code);\n }\n\n return {\n extractedContent,\n code: result.code,\n map: result.map,\n };\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAyBA,MAAM,8BACJ,YACA,mBACqB;CACrB,IAAI,OAAyB;AAE7B,KAAI;EACF,MAAM,6BAAiB,YAAY,EACjC,YAAY;GAAE,YAAY;GAAU,SAAS,CAAC,cAAc,MAAM;GAAE,EACrE,CAAC;AAEF,MAAI,CAAC,IAAK,QAAO;AAEjB,4BAAS,KAAK,EACZ,eAAe,MAAW;GACxB,MAAM,SAAS,KAAK,KAAK;AAEzB,OACE,CAACA,kBAAE,aAAa,OAAO,IACtB,OAAO,SAAS,iBAAiB,OAAO,SAAS,cAElD;GAEF,MAAM,SAAS,KAAK;AAEpB,OAAIA,kBAAE,qBAAqB,OAAO,IAAIA,kBAAE,gBAAgB,OAAO,GAAG,EAAE;IAClE,MAAM,aAAa,OAAO,GAAG;IAC7B,MAAM,2BAA2B,WAC9B,QACE,aACCA,kBAAE,iBAAiB,SAAS,IAAIA,kBAAE,aAAa,SAAS,IAAI,CAC/D,CACA,KAAK,aAAmB,SAAS,IAAY,KAAe;IAC/D,MAAM,WAAW,WAAW,WAAW,SAAS;AAEhD,WAAO;KACL,gBAAgB;KAChB,cAAc;KACd;KACA,yBAAyB,kBAAkB,OAAO,GAAG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BAAiB,CAAC,YAAY,YAAY,CAAC,OAAO,QAAQ;AAEhE,KAAI,eAAe,SAAS,GAAG;EAC7B,MAAM,YAAY,KAAK,eAAe,KAAK,KAAK,CAAC;AAEjD,MAAI,IAAI,WAAW,YACjB,OAAM,WAAW,IAAI,WAAW,YAAY,IAAI,MAAM,QAAQ,UAAU;WAC/D,IAAI,WAAW,OACxB,OAAM,WAAW,IAAI,WAAW,OAAO,IAAI,MAAM,QAAQ,UAAU;MAEnE,OAAM,QACJ,mBAAmB,WAAW,IAAI,YAAY,gBAC/C;;AAIL,KAAI,UACF,WAAU;EACR;EACA,UAAU;EACV,SAAS,EAAE,GAAG,kBAAkB;EAChC,QAAQ;EACT,CAAC;AAGJ,QAAO;EACL,MAAM,MAAM,UAAU;EACtB,KAAK,MAAM,YAAY;GAAE,QAAQ;GAAU,gBAAgB;GAAM,CAAC;EAClE,WAAW;EACZ;;AAWH,MAAa,kBACX,UACA,eACA,aACA,OACA,OAAgB,MAChB,iBAKU;CACV,MAAM,OAAO,0CAA6B,UAAU,QAAQ;CAC5D,IAAI,mBAA2C,EAAE;CAEjD,MAAM,SAAS,mBAAmB,MAAM,UAAU;EAChD;EACA,eAAe;EACf,eAAe,MAAM;EACrB,aAAa,MAAM;EACnB,8BAA8B,MAAM;EACpC,qBAAqB,MAAM;EAC3B,YAAY,kBAAkB;AAC5B,sBAAmB,cAAc;;EAEpC,CAAC;AAEF,KAAI,CAAC,OAAQ,QAAO;AAEpB,KAAI,KACF,4BAAc,UAAU,OAAO,KAAK;AAGtC,QAAO;EACL;EACA,MAAM,OAAO;EACb,KAAK,OAAO;EACb"}
|
|
1
|
+
{"version":3,"file":"vue-intlayer-extract.cjs","names":["t","DEFAULT_LOCALE","vueSfc","MagicString"],"sources":["../../src/vue-intlayer-extract.ts"],"sourcesContent":["import { readFileSync, writeFileSync } from 'node:fs';\nimport { parse as babelParse, types as t, traverse } from '@babel/core';\nimport { DEFAULT_LOCALE } from '@intlayer/config/defaultValues';\nimport type { Locale } from '@intlayer/types/allLocales';\nimport vueSfc from '@vue/compiler-sfc';\nimport MagicString from 'magic-string';\n\ntype ExistingCallInfo = {\n isDestructured: boolean;\n existingDestructuredKeys: string[];\n /** The variable name used to store the call result (e.g. `t` in `const t = useIntlayer(...)`) */\n variableName: string;\n /** Absolute position of `}` in the full file — only valid when `isDestructured` */\n closingBraceAbsolutePos: number;\n /** Absolute position of end of last property — only valid when `isDestructured` */\n lastPropAbsoluteEnd: number;\n} | null;\n\n/**\n * Detects whether the script block already contains a `useIntlayer` /\n * `getIntlayer` call and, if so, whether its result is destructured.\n *\n * @param scriptText Raw text of the script block content.\n * @param absoluteOffset Byte offset of `scriptText[0]` in the full SFC source.\n */\nconst detectExistingIntlayerCall = (\n scriptText: string,\n absoluteOffset: number\n): ExistingCallInfo => {\n let info: ExistingCallInfo = null;\n\n try {\n const ast = babelParse(scriptText, {\n parserOpts: { sourceType: 'module', plugins: ['typescript', 'jsx'] },\n });\n\n if (!ast) return null;\n\n traverse(ast, {\n CallExpression(path: any) {\n const callee = path.node.callee;\n\n if (\n !t.isIdentifier(callee) ||\n (callee.name !== 'useIntlayer' && callee.name !== 'getIntlayer')\n )\n return;\n\n const parent = path.parent;\n\n if (t.isVariableDeclarator(parent) && t.isObjectPattern(parent.id)) {\n const properties = parent.id.properties;\n const existingDestructuredKeys = properties\n .filter(\n (property: any): property is typeof t.objectProperty =>\n t.isObjectProperty(property) && t.isIdentifier(property.key)\n )\n .map((property: any) => (property.key as any).name as string);\n const lastProp = properties[properties.length - 1];\n\n info = {\n isDestructured: true,\n variableName: 'content',\n existingDestructuredKeys,\n closingBraceAbsolutePos: absoluteOffset + (parent.id.end! - 1),\n lastPropAbsoluteEnd: absoluteOffset + lastProp.end!,\n };\n } else {\n const variableName =\n t.isVariableDeclarator(parent) && t.isIdentifier(parent.id)\n ? parent.id.name\n : 'content';\n\n info = {\n isDestructured: false,\n variableName,\n existingDestructuredKeys: [],\n closingBraceAbsolutePos: -1,\n lastPropAbsoluteEnd: -1,\n };\n }\n\n path.stop();\n },\n });\n } catch {\n // Silently ignore parse failures — fall back to no-info\n }\n\n return info;\n};\n\nexport type ExtractedContent = Record<string, string>;\n\nexport type ExtractResult = {\n dictionaryKey: string;\n filePath: string;\n content: ExtractedContent;\n locale: Locale;\n};\n\nexport type ExtractPluginOptions = {\n defaultLocale?: Locale;\n packageName?: string;\n filesList?: string[];\n shouldExtract?: (text: string) => boolean;\n onExtract?: (result: ExtractResult) => void;\n dictionaryKey?: string;\n attributesToExtract?: readonly string[];\n extractDictionaryKeyFromPath?: (path: string) => string;\n generateKey?: (text: string, existingKeys: Set<string>) => string;\n};\n\ntype Replacement = {\n start: number;\n end: number;\n replacement: string;\n key: string;\n value: string;\n};\n\nexport const shouldProcessFile = (\n filename: string | undefined,\n filesList?: string[]\n): boolean => {\n if (!filename) return false;\n if (!filesList || filesList.length === 0) return true;\n\n const normalizedFilename = filename.replace(/\\\\/g, '/');\n return filesList.some((f) => {\n const normalizedF = f.replace(/\\\\/g, '/');\n return normalizedF === normalizedFilename;\n });\n};\n\ntype VueParseResult = {\n descriptor: {\n template?: {\n ast: VueAstNode;\n loc: { start: { offset: number }; end: { offset: number } };\n };\n script?: {\n content: string;\n loc: { start: { offset: number }; end: { offset: number } };\n };\n scriptSetup?: {\n content: string;\n loc: { start: { offset: number }; end: { offset: number } };\n };\n };\n};\n\ntype VueAstNode = {\n type: number;\n content?: string;\n children?: VueAstNode[];\n props?: VueAstProp[];\n loc: { start: { offset: number }; end: { offset: number } };\n};\n\ntype VueAstProp = {\n type: number;\n name: string;\n value?: { content: string };\n loc: { start: { offset: number }; end: { offset: number } };\n};\n\nconst NODE_TYPES = {\n TEXT: 2,\n ELEMENT: 1,\n ATTRIBUTE: 6,\n INTERPOLATION: 5,\n};\n\nexport const intlayerVueExtract = (\n code: string,\n filename: string,\n options: ExtractPluginOptions = {}\n): { code: string; map?: unknown; extracted: boolean } | null => {\n const {\n defaultLocale = DEFAULT_LOCALE,\n packageName = 'vue-intlayer',\n filesList,\n shouldExtract,\n onExtract,\n dictionaryKey: dictionaryKeyOption,\n attributesToExtract = [],\n extractDictionaryKeyFromPath,\n generateKey,\n } = options;\n\n if (!shouldProcessFile(filename, filesList)) return null;\n if (!filename.endsWith('.vue')) return null;\n\n let parseVue: (code: string) => VueParseResult;\n\n try {\n parseVue = vueSfc.parse as unknown as (code: string) => VueParseResult;\n } catch {\n console.warn('Vue extraction: @vue/compiler-sfc not found.');\n return null;\n }\n\n const sfc = parseVue(code);\n const magic = new MagicString(code);\n\n const extractedContent: ExtractedContent = {};\n const existingKeys = new Set<string>();\n const dictionaryKey =\n dictionaryKeyOption ?? extractDictionaryKeyFromPath?.(filename) ?? '';\n const replacements: Replacement[] = [];\n\n // Detect existing useIntlayer / getIntlayer call in the script block BEFORE\n // walking the template, so the correct access pattern can be chosen.\n const scriptBlock = sfc.descriptor.scriptSetup ?? sfc.descriptor.script;\n const existingCallInfo = scriptBlock\n ? detectExistingIntlayerCall(\n scriptBlock.content,\n scriptBlock.loc.start.offset\n )\n : null;\n\n const isDestructured = existingCallInfo?.isDestructured ?? false;\n const varName = existingCallInfo?.variableName ?? 'content';\n\n // Walk Vue Template AST\n if (sfc.descriptor.template) {\n const walkVueAst = (node: VueAstNode) => {\n if (node.type === NODE_TYPES.TEXT) {\n const text = node.content ?? '';\n\n if (shouldExtract?.(text) && generateKey) {\n const key = generateKey(text, existingKeys);\n existingKeys.add(key);\n // When the existing call is destructured, access the key directly;\n // otherwise use the `content` variable.\n const ref = isDestructured ? key : `${varName}.${key}`;\n replacements.push({\n start: node.loc.start.offset,\n end: node.loc.end.offset,\n replacement: `{{ ${ref} }}`,\n key,\n value: text.replace(/\\s+/g, ' ').trim(),\n });\n }\n } else if (node.type === NODE_TYPES.ELEMENT) {\n const children = node.children ?? [];\n\n // Try to handle as insertion (mixed TEXT + INTERPOLATION children)\n if (\n children.length > 0 &&\n children.some((c) => c.type === NODE_TYPES.INTERPOLATION)\n ) {\n const parts: {\n type: 'text' | 'var';\n value: string;\n originalExpr: string;\n }[] = [];\n let hasSignificantText = false;\n let isValid = true;\n\n for (const child of children) {\n if (child.type === NODE_TYPES.TEXT) {\n const text = child.content ?? '';\n if (text.trim().length > 0) hasSignificantText = true;\n parts.push({ type: 'text', value: text, originalExpr: '' });\n } else if (child.type === NODE_TYPES.INTERPOLATION) {\n // Extract the expression source between {{ and }}\n const exprCode = code\n .slice(child.loc.start.offset + 2, child.loc.end.offset - 2)\n .trim();\n const varName = exprCode.includes('.')\n ? exprCode\n .split('.')\n .pop()!\n .replace(/[^\\w$]/g, '')\n : exprCode;\n parts.push({\n type: 'var',\n value: varName,\n originalExpr: exprCode,\n });\n } else {\n isValid = false;\n break;\n }\n }\n\n if (\n isValid &&\n hasSignificantText &&\n parts.some((p) => p.type === 'var')\n ) {\n let combined = '';\n for (const p of parts) {\n combined += p.type === 'var' ? `{{${p.value}}}` : p.value;\n }\n const cleanString = combined.replace(/\\s+/g, ' ').trim();\n\n if (shouldExtract?.(cleanString) && generateKey) {\n const key = generateKey(cleanString, existingKeys);\n existingKeys.add(key);\n const ref = isDestructured ? key : `${varName}.${key}`;\n\n const uniqueVarPairs = [\n ...new Set(\n parts\n .filter((p) => p.type === 'var')\n .map((p) => `${p.value}: ${p.originalExpr}`)\n ),\n ];\n const varArgs = uniqueVarPairs.join(', ');\n const replacement = `{{ ${ref}({ ${varArgs} }) }}`;\n\n const firstChild = children[0];\n const lastChild = children[children.length - 1];\n replacements.push({\n start: firstChild.loc.start.offset,\n end: lastChild.loc.end.offset,\n replacement,\n key,\n value: cleanString,\n });\n\n // Process props but skip children (they are replaced)\n node.props?.forEach((prop) => {\n if (\n prop.type === NODE_TYPES.ATTRIBUTE &&\n (attributesToExtract as readonly string[]).includes(\n prop.name\n ) &&\n prop.value\n ) {\n const text = prop.value.content;\n if (shouldExtract?.(text) && generateKey) {\n const propKey = generateKey(text, existingKeys);\n existingKeys.add(propKey);\n const propRef = isDestructured\n ? propKey\n : `${varName}.${propKey}`;\n replacements.push({\n start: prop.loc.start.offset,\n end: prop.loc.end.offset,\n replacement: `:${prop.name}=\"${propRef}\"`,\n key: propKey,\n value: text.trim(),\n });\n }\n }\n });\n return; // don't recurse into children\n }\n }\n }\n\n // Regular element: handle props\n node.props?.forEach((prop) => {\n if (\n prop.type === NODE_TYPES.ATTRIBUTE &&\n (attributesToExtract as readonly string[]).includes(prop.name) &&\n prop.value\n ) {\n const text = prop.value.content;\n\n if (shouldExtract?.(text) && generateKey) {\n const key = generateKey(text, existingKeys);\n existingKeys.add(key);\n const ref = isDestructured ? key : `${varName}.${key}`;\n replacements.push({\n start: prop.loc.start.offset,\n end: prop.loc.end.offset,\n replacement: `:${prop.name}=\"${ref}\"`,\n key,\n value: text.trim(),\n });\n }\n }\n });\n }\n\n if (node.children) {\n node.children.forEach(walkVueAst);\n }\n };\n\n walkVueAst(sfc.descriptor.template.ast);\n }\n\n // Extract and Walk Script using Babel\n if (scriptBlock) {\n const scriptText = scriptBlock.content;\n const offset = scriptBlock.loc.start.offset;\n\n try {\n const ast = babelParse(scriptText, {\n parserOpts: {\n sourceType: 'module',\n plugins: ['typescript', 'jsx'],\n },\n });\n\n if (ast) {\n traverse(ast, {\n StringLiteral(path: any) {\n if (path.parentPath.isImportDeclaration()) return;\n\n if (path.parentPath.isExportDeclaration()) return;\n\n if (path.parentPath.isImportSpecifier()) return;\n\n if (path.parentPath.isObjectProperty() && path.key === 'key')\n return;\n\n if (path.parentPath.isCallExpression()) {\n const callee = path.parentPath.node.callee;\n\n if (\n t.isMemberExpression(callee) &&\n t.isIdentifier(callee.object) &&\n callee.object.name === 'console'\n )\n return;\n\n if (\n t.isIdentifier(callee) &&\n (callee.name === 'useIntlayer' || callee.name === 't')\n )\n return;\n\n if (callee.type === 'Import') return;\n\n if (t.isIdentifier(callee) && callee.name === 'require') return;\n }\n\n const text = path.node.value;\n\n if (shouldExtract?.(text) && generateKey) {\n const key = generateKey(text, existingKeys);\n existingKeys.add(key);\n\n if (path.node.start != null && path.node.end != null) {\n const ref = isDestructured ? key : `${varName}.${key}`;\n replacements.push({\n start: offset + path.node.start,\n end: offset + path.node.end,\n replacement: ref,\n key,\n value: text.trim(),\n });\n }\n }\n },\n });\n }\n } catch (e) {\n console.warn(\n `Vue extraction: Failed to parse script content for ${filename}`,\n e\n );\n }\n }\n\n // Abort if nothing was extracted\n if (replacements.length === 0) return null;\n\n // Apply Replacements in Reverse Order\n replacements.sort((a, b) => b.start - a.start);\n\n for (const { start, end, replacement, key, value } of replacements) {\n magic.overwrite(start, end, replacement);\n extractedContent[key] = value;\n }\n\n // When the existing call is destructured, inject only the missing keys into\n // the ObjectPattern — no new `content` variable is needed.\n if (\n existingCallInfo?.isDestructured &&\n existingCallInfo.closingBraceAbsolutePos >= 0\n ) {\n const missingKeys = Object.keys(extractedContent).filter(\n (k) => !existingCallInfo.existingDestructuredKeys.includes(k)\n );\n\n if (missingKeys.length > 0) {\n // Insert right after the last property so the space/newline before `}`\n // is naturally preserved: `{ a }` → `{ a, b }`.\n magic.appendLeft(\n existingCallInfo.lastPropAbsoluteEnd,\n `, ${missingKeys.join(', ')}`\n );\n }\n }\n\n // Inject necessary imports and setup (only when no existing call was detected)\n const finalScriptContent = scriptBlock?.content ?? '';\n\n const hasUseIntlayerImport =\n /import\\s*{[^}]*useIntlayer[^}]*}\\s*from\\s*['\"][^'\"]+['\"]/.test(\n finalScriptContent\n ) ||\n /import\\s+useIntlayer\\s+from\\s*['\"][^'\"]+['\"]/.test(finalScriptContent);\n\n // An existing call (destructured or not) means no new declaration is needed.\n const hasContentDeclaration =\n existingCallInfo !== null ||\n /const\\s+content\\s*=\\s*useIntlayer\\s*\\(/.test(finalScriptContent);\n\n const importStmt = hasUseIntlayerImport\n ? ''\n : `import { useIntlayer } from '${packageName}';`;\n const contentDecl = hasContentDeclaration\n ? ''\n : `const content = useIntlayer('${dictionaryKey}');`;\n\n const injectionParts = [importStmt, contentDecl].filter(Boolean);\n\n if (injectionParts.length > 0) {\n const injection = `\\n${injectionParts.join('\\n')}\\n`;\n\n if (sfc.descriptor.scriptSetup) {\n magic.appendLeft(sfc.descriptor.scriptSetup.loc.start.offset, injection);\n } else if (sfc.descriptor.script) {\n magic.appendLeft(sfc.descriptor.script.loc.start.offset, injection);\n } else {\n magic.prepend(\n `<script setup>\\n${importStmt}\\n${contentDecl}\\n</script>\\n`\n );\n }\n }\n\n if (onExtract) {\n onExtract({\n dictionaryKey,\n filePath: filename,\n content: { ...extractedContent },\n locale: defaultLocale,\n });\n }\n\n return {\n code: magic.toString(),\n map: magic.generateMap({ source: filename, includeContent: true }),\n extracted: true,\n };\n};\n\ntype Tools = {\n generateKey: (text: string, existingKeys: Set<string>) => string;\n shouldExtract: (text: string) => boolean;\n extractDictionaryKeyFromPath: (path: string) => string;\n attributesToExtract: readonly string[];\n extractTsContent: any;\n};\n\nexport const processVueFile = (\n filePath: string,\n _componentKey: string,\n packageName: string,\n tools: Tools,\n save: boolean = true,\n providedCode?: string\n): {\n extractedContent: Record<string, string>;\n code: string;\n map?: any;\n} | null => {\n const code = providedCode ?? readFileSync(filePath, 'utf-8');\n let extractedContent: Record<string, string> = {};\n\n const result = intlayerVueExtract(code, filePath, {\n packageName,\n dictionaryKey: _componentKey,\n shouldExtract: tools.shouldExtract,\n generateKey: tools.generateKey,\n extractDictionaryKeyFromPath: tools.extractDictionaryKeyFromPath,\n attributesToExtract: tools.attributesToExtract,\n onExtract: (extractResult) => {\n extractedContent = extractResult.content;\n },\n });\n\n if (!result) return null;\n\n if (save) {\n writeFileSync(filePath, result.code);\n }\n\n return {\n extractedContent,\n code: result.code,\n map: result.map,\n };\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAyBA,MAAM,8BACJ,YACA,mBACqB;CACrB,IAAI,OAAyB;CAE7B,IAAI;EACF,MAAM,6BAAiB,YAAY,EACjC,YAAY;GAAE,YAAY;GAAU,SAAS,CAAC,cAAc,MAAM;GAAE,EACrE,CAAC;EAEF,IAAI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EAAE;CAEjD,MAAM,SAAS,mBAAmB,MAAM,UAAU;EAChD;EACA,eAAe;EACf,eAAe,MAAM;EACrB,aAAa,MAAM;EACnB,8BAA8B,MAAM;EACpC,qBAAqB,MAAM;EAC3B,YAAY,kBAAkB;GAC5B,mBAAmB,cAAc;;EAEpC,CAAC;CAEF,IAAI,CAAC,QAAQ,OAAO;CAEpB,IAAI,MACF,2BAAc,UAAU,OAAO,KAAK;CAGtC,OAAO;EACL;EACA,MAAM,OAAO;EACb,KAAK,OAAO;EACb"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"extractVueFieldUsage.mjs","names":[],"sources":["../../src/extractVueFieldUsage.ts"],"sourcesContent":["/**\n * Extracts intlayer dictionary field usage from a Vue SFC for a set of\n * plain variable bindings (i.e. `const content = useIntlayer('key')`).\n *\n * Two access patterns are recognised:\n *\n * 1. `varName.value.fieldName` in script blocks\n * Vue's `useIntlayer` returns a reactive `Ref<Content>`, so fields are\n * accessed one level deeper via `.value`.\n *\n * 2. `varName.fieldName` in the template block\n * Inside `<template>`, Vue automatically unwraps top-level refs, so\n * fields are accessed directly without `.value`.\n *\n * The template block is extracted via `@vue/compiler-sfc` so that nested\n * `<template v-for>` / `<template v-if>` tags do not confuse the parser.\n * Falls back to a greedy regex when the package is unavailable.\n */\n\nimport vueSfc from '@vue/compiler-sfc';\n\n/** Escapes special regex characters in a string used as a regex literal. */\nconst escapeRegExp = (str: string): string =>\n str.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\$&');\n\n/** Input descriptor for a single plain variable binding. */\nexport type PlainVariableInfo = {\n /** The local variable name in the script (`content` in `const content = useIntlayer(…)`). */\n variableName: string;\n /** The intlayer dictionary key passed to `useIntlayer`. */\n dictionaryKey: string;\n};\n\n/**\n * Splits a Vue SFC source string into its script and template regions.\n *\n * Uses `@vue/compiler-sfc` to get exact character offsets so that nested\n * `<template>` tags (used by Vue directives like `v-for` / `v-if`) never\n * cause the template region to be mis-identified.\n */\nconst splitVueSfc = (\n code: string\n): { scriptSource: string; templateSource: string } => {\n try {\n const { descriptor } = (\n vueSfc.parse as (src: string) => { descriptor: any }\n )(code);\n\n const templateSource: string = descriptor.template?.content ?? '';\n\n const scriptParts: string[] = [];\n if (descriptor.script?.content) scriptParts.push(descriptor.script.content);\n if (descriptor.scriptSetup?.content)\n scriptParts.push(descriptor.scriptSetup.content);\n const scriptSource = scriptParts.join('\\n');\n\n return { scriptSource, templateSource };\n } catch {\n // @vue/compiler-sfc not available or parse failed.\n // Fall back: use a greedy regex to capture everything between the\n // outermost <template> tags (robust against nested tags unlike the\n // non-greedy variant).\n const templateMatch = /<template(?:[^>]*)>([\\s\\S]*)<\\/template>/i.exec(\n code\n );\n const templateSource = templateMatch ? templateMatch[1] : '';\n const scriptSource = code.replace(/<template[\\s\\S]*<\\/template>/gi, '');\n return { scriptSource, templateSource };\n }\n};\n\n/**\n * Analyzes a Vue SFC source string and returns the top-level content field\n * names that are statically accessed for each plain intlayer variable binding.\n *\n * @param code - Full `.vue` file source.\n * @param plainVariables - List of plain variable bindings to analyse.\n * @returns Map from dictionary key to the set of accessed top-level field names.\n * If no fields can be determined for a given key it is omitted from the\n * map so the caller can fall back to `'all'`.\n */\nexport const extractVueIntlayerFieldUsage = (\n code: string,\n plainVariables: PlainVariableInfo[]\n): Map<string, Set<string>> => {\n const result = new Map<string, Set<string>>();\n\n if (plainVariables.length === 0) return result;\n\n const { scriptSource, templateSource } = splitVueSfc(code);\n\n for (const { variableName, dictionaryKey } of plainVariables) {\n const fields = new Set<string>();\n const esc = escapeRegExp(variableName);\n\n // ── 1. Script pattern: varName.value.fieldName ─────────────────────────\n // Vue's reactive ref accessor; the actual content fields live one level\n // deeper than the variable itself.\n const scriptRe = new RegExp(`\\\\b${esc}\\\\.value\\\\.(\\\\w+)`, 'g');\n scriptRe.lastIndex = 0;\n for (\n let m = scriptRe.exec(scriptSource);\n m !== null;\n m = scriptRe.exec(scriptSource)\n ) {\n const field = m[1];\n // Skip chained `.value.value` artefacts\n if (field !== 'value') fields.add(field);\n }\n\n // ── 2. Template pattern: varName.fieldName ─────────────────────────────\n // Inside `<template>` Vue auto-unwraps refs, so content is accessed\n // directly without `.value`.\n if (templateSource) {\n const templateRe = new RegExp(`\\\\b${esc}\\\\.(\\\\w+)`, 'g');\n\n templateRe.lastIndex = 0;\n for (\n let m = templateRe.exec(templateSource);\n m !== null;\n m = templateRe.exec(templateSource)\n ) {\n fields.add(m[1]);\n }\n }\n\n if (fields.size > 0) {\n result.set(dictionaryKey, fields);\n }\n }\n\n return result;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAsBA,MAAM,gBAAgB,QACpB,IAAI,QAAQ,uBAAuB,OAAO;;;;;;;;AAiB5C,MAAM,eACJ,SACqD;
|
|
1
|
+
{"version":3,"file":"extractVueFieldUsage.mjs","names":[],"sources":["../../src/extractVueFieldUsage.ts"],"sourcesContent":["/**\n * Extracts intlayer dictionary field usage from a Vue SFC for a set of\n * plain variable bindings (i.e. `const content = useIntlayer('key')`).\n *\n * Two access patterns are recognised:\n *\n * 1. `varName.value.fieldName` in script blocks\n * Vue's `useIntlayer` returns a reactive `Ref<Content>`, so fields are\n * accessed one level deeper via `.value`.\n *\n * 2. `varName.fieldName` in the template block\n * Inside `<template>`, Vue automatically unwraps top-level refs, so\n * fields are accessed directly without `.value`.\n *\n * The template block is extracted via `@vue/compiler-sfc` so that nested\n * `<template v-for>` / `<template v-if>` tags do not confuse the parser.\n * Falls back to a greedy regex when the package is unavailable.\n */\n\nimport vueSfc from '@vue/compiler-sfc';\n\n/** Escapes special regex characters in a string used as a regex literal. */\nconst escapeRegExp = (str: string): string =>\n str.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\$&');\n\n/** Input descriptor for a single plain variable binding. */\nexport type PlainVariableInfo = {\n /** The local variable name in the script (`content` in `const content = useIntlayer(…)`). */\n variableName: string;\n /** The intlayer dictionary key passed to `useIntlayer`. */\n dictionaryKey: string;\n};\n\n/**\n * Splits a Vue SFC source string into its script and template regions.\n *\n * Uses `@vue/compiler-sfc` to get exact character offsets so that nested\n * `<template>` tags (used by Vue directives like `v-for` / `v-if`) never\n * cause the template region to be mis-identified.\n */\nconst splitVueSfc = (\n code: string\n): { scriptSource: string; templateSource: string } => {\n try {\n const { descriptor } = (\n vueSfc.parse as (src: string) => { descriptor: any }\n )(code);\n\n const templateSource: string = descriptor.template?.content ?? '';\n\n const scriptParts: string[] = [];\n if (descriptor.script?.content) scriptParts.push(descriptor.script.content);\n if (descriptor.scriptSetup?.content)\n scriptParts.push(descriptor.scriptSetup.content);\n const scriptSource = scriptParts.join('\\n');\n\n return { scriptSource, templateSource };\n } catch {\n // @vue/compiler-sfc not available or parse failed.\n // Fall back: use a greedy regex to capture everything between the\n // outermost <template> tags (robust against nested tags unlike the\n // non-greedy variant).\n const templateMatch = /<template(?:[^>]*)>([\\s\\S]*)<\\/template>/i.exec(\n code\n );\n const templateSource = templateMatch ? templateMatch[1] : '';\n const scriptSource = code.replace(/<template[\\s\\S]*<\\/template>/gi, '');\n return { scriptSource, templateSource };\n }\n};\n\n/**\n * Analyzes a Vue SFC source string and returns the top-level content field\n * names that are statically accessed for each plain intlayer variable binding.\n *\n * @param code - Full `.vue` file source.\n * @param plainVariables - List of plain variable bindings to analyse.\n * @returns Map from dictionary key to the set of accessed top-level field names.\n * If no fields can be determined for a given key it is omitted from the\n * map so the caller can fall back to `'all'`.\n */\nexport const extractVueIntlayerFieldUsage = (\n code: string,\n plainVariables: PlainVariableInfo[]\n): Map<string, Set<string>> => {\n const result = new Map<string, Set<string>>();\n\n if (plainVariables.length === 0) return result;\n\n const { scriptSource, templateSource } = splitVueSfc(code);\n\n for (const { variableName, dictionaryKey } of plainVariables) {\n const fields = new Set<string>();\n const esc = escapeRegExp(variableName);\n\n // ── 1. Script pattern: varName.value.fieldName ─────────────────────────\n // Vue's reactive ref accessor; the actual content fields live one level\n // deeper than the variable itself.\n const scriptRe = new RegExp(`\\\\b${esc}\\\\.value\\\\.(\\\\w+)`, 'g');\n scriptRe.lastIndex = 0;\n for (\n let m = scriptRe.exec(scriptSource);\n m !== null;\n m = scriptRe.exec(scriptSource)\n ) {\n const field = m[1];\n // Skip chained `.value.value` artefacts\n if (field !== 'value') fields.add(field);\n }\n\n // ── 2. Template pattern: varName.fieldName ─────────────────────────────\n // Inside `<template>` Vue auto-unwraps refs, so content is accessed\n // directly without `.value`.\n if (templateSource) {\n const templateRe = new RegExp(`\\\\b${esc}\\\\.(\\\\w+)`, 'g');\n\n templateRe.lastIndex = 0;\n for (\n let m = templateRe.exec(templateSource);\n m !== null;\n m = templateRe.exec(templateSource)\n ) {\n fields.add(m[1]);\n }\n }\n\n if (fields.size > 0) {\n result.set(dictionaryKey, fields);\n }\n }\n\n return result;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAsBA,MAAM,gBAAgB,QACpB,IAAI,QAAQ,uBAAuB,OAAO;;;;;;;;AAiB5C,MAAM,eACJ,SACqD;CACrD,IAAI;EACF,MAAM,EAAE,eACN,OAAO,MACP,KAAK;EAEP,MAAM,iBAAyB,WAAW,UAAU,WAAW;EAE/D,MAAM,cAAwB,EAAE;EAChC,IAAI,WAAW,QAAQ,SAAS,YAAY,KAAK,WAAW,OAAO,QAAQ;EAC3E,IAAI,WAAW,aAAa,SAC1B,YAAY,KAAK,WAAW,YAAY,QAAQ;EAGlD,OAAO;GAAE,cAFY,YAAY,KAAK,KAEjB;GAAE;GAAgB;SACjC;EAKN,MAAM,gBAAgB,4CAA4C,KAChE,KACD;EACD,MAAM,iBAAiB,gBAAgB,cAAc,KAAK;EAE1D,OAAO;GAAE,cADY,KAAK,QAAQ,kCAAkC,GAC/C;GAAE;GAAgB;;;;;;;;;;;;;AAc3C,MAAa,gCACX,MACA,mBAC6B;CAC7B,MAAM,yBAAS,IAAI,KAA0B;CAE7C,IAAI,eAAe,WAAW,GAAG,OAAO;CAExC,MAAM,EAAE,cAAc,mBAAmB,YAAY,KAAK;CAE1D,KAAK,MAAM,EAAE,cAAc,mBAAmB,gBAAgB;EAC5D,MAAM,yBAAS,IAAI,KAAa;EAChC,MAAM,MAAM,aAAa,aAAa;EAKtC,MAAM,WAAW,IAAI,OAAO,MAAM,IAAI,oBAAoB,IAAI;EAC9D,SAAS,YAAY;EACrB,KACE,IAAI,IAAI,SAAS,KAAK,aAAa,EACnC,MAAM,MACN,IAAI,SAAS,KAAK,aAAa,EAC/B;GACA,MAAM,QAAQ,EAAE;GAEhB,IAAI,UAAU,SAAS,OAAO,IAAI,MAAM;;EAM1C,IAAI,gBAAgB;GAClB,MAAM,aAAa,IAAI,OAAO,MAAM,IAAI,YAAY,IAAI;GAExD,WAAW,YAAY;GACvB,KACE,IAAI,IAAI,WAAW,KAAK,eAAe,EACvC,MAAM,MACN,IAAI,WAAW,KAAK,eAAe,EAEnC,OAAO,IAAI,EAAE,GAAG;;EAIpB,IAAI,OAAO,OAAO,GAChB,OAAO,IAAI,eAAe,OAAO;;CAIrC,OAAO"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"vue-intlayer-extract.mjs","names":["babelParse","t"],"sources":["../../src/vue-intlayer-extract.ts"],"sourcesContent":["import { readFileSync, writeFileSync } from 'node:fs';\nimport { parse as babelParse, types as t, traverse } from '@babel/core';\nimport { DEFAULT_LOCALE } from '@intlayer/config/defaultValues';\nimport type { Locale } from '@intlayer/types/allLocales';\nimport vueSfc from '@vue/compiler-sfc';\nimport MagicString from 'magic-string';\n\ntype ExistingCallInfo = {\n isDestructured: boolean;\n existingDestructuredKeys: string[];\n /** The variable name used to store the call result (e.g. `t` in `const t = useIntlayer(...)`) */\n variableName: string;\n /** Absolute position of `}` in the full file — only valid when `isDestructured` */\n closingBraceAbsolutePos: number;\n /** Absolute position of end of last property — only valid when `isDestructured` */\n lastPropAbsoluteEnd: number;\n} | null;\n\n/**\n * Detects whether the script block already contains a `useIntlayer` /\n * `getIntlayer` call and, if so, whether its result is destructured.\n *\n * @param scriptText Raw text of the script block content.\n * @param absoluteOffset Byte offset of `scriptText[0]` in the full SFC source.\n */\nconst detectExistingIntlayerCall = (\n scriptText: string,\n absoluteOffset: number\n): ExistingCallInfo => {\n let info: ExistingCallInfo = null;\n\n try {\n const ast = babelParse(scriptText, {\n parserOpts: { sourceType: 'module', plugins: ['typescript', 'jsx'] },\n });\n\n if (!ast) return null;\n\n traverse(ast, {\n CallExpression(path: any) {\n const callee = path.node.callee;\n\n if (\n !t.isIdentifier(callee) ||\n (callee.name !== 'useIntlayer' && callee.name !== 'getIntlayer')\n )\n return;\n\n const parent = path.parent;\n\n if (t.isVariableDeclarator(parent) && t.isObjectPattern(parent.id)) {\n const properties = parent.id.properties;\n const existingDestructuredKeys = properties\n .filter(\n (property: any): property is typeof t.objectProperty =>\n t.isObjectProperty(property) && t.isIdentifier(property.key)\n )\n .map((property: any) => (property.key as any).name as string);\n const lastProp = properties[properties.length - 1];\n\n info = {\n isDestructured: true,\n variableName: 'content',\n existingDestructuredKeys,\n closingBraceAbsolutePos: absoluteOffset + (parent.id.end! - 1),\n lastPropAbsoluteEnd: absoluteOffset + lastProp.end!,\n };\n } else {\n const variableName =\n t.isVariableDeclarator(parent) && t.isIdentifier(parent.id)\n ? parent.id.name\n : 'content';\n\n info = {\n isDestructured: false,\n variableName,\n existingDestructuredKeys: [],\n closingBraceAbsolutePos: -1,\n lastPropAbsoluteEnd: -1,\n };\n }\n\n path.stop();\n },\n });\n } catch {\n // Silently ignore parse failures — fall back to no-info\n }\n\n return info;\n};\n\nexport type ExtractedContent = Record<string, string>;\n\nexport type ExtractResult = {\n dictionaryKey: string;\n filePath: string;\n content: ExtractedContent;\n locale: Locale;\n};\n\nexport type ExtractPluginOptions = {\n defaultLocale?: Locale;\n packageName?: string;\n filesList?: string[];\n shouldExtract?: (text: string) => boolean;\n onExtract?: (result: ExtractResult) => void;\n dictionaryKey?: string;\n attributesToExtract?: readonly string[];\n extractDictionaryKeyFromPath?: (path: string) => string;\n generateKey?: (text: string, existingKeys: Set<string>) => string;\n};\n\ntype Replacement = {\n start: number;\n end: number;\n replacement: string;\n key: string;\n value: string;\n};\n\nexport const shouldProcessFile = (\n filename: string | undefined,\n filesList?: string[]\n): boolean => {\n if (!filename) return false;\n if (!filesList || filesList.length === 0) return true;\n\n const normalizedFilename = filename.replace(/\\\\/g, '/');\n return filesList.some((f) => {\n const normalizedF = f.replace(/\\\\/g, '/');\n return normalizedF === normalizedFilename;\n });\n};\n\ntype VueParseResult = {\n descriptor: {\n template?: {\n ast: VueAstNode;\n loc: { start: { offset: number }; end: { offset: number } };\n };\n script?: {\n content: string;\n loc: { start: { offset: number }; end: { offset: number } };\n };\n scriptSetup?: {\n content: string;\n loc: { start: { offset: number }; end: { offset: number } };\n };\n };\n};\n\ntype VueAstNode = {\n type: number;\n content?: string;\n children?: VueAstNode[];\n props?: VueAstProp[];\n loc: { start: { offset: number }; end: { offset: number } };\n};\n\ntype VueAstProp = {\n type: number;\n name: string;\n value?: { content: string };\n loc: { start: { offset: number }; end: { offset: number } };\n};\n\nconst NODE_TYPES = {\n TEXT: 2,\n ELEMENT: 1,\n ATTRIBUTE: 6,\n INTERPOLATION: 5,\n};\n\nexport const intlayerVueExtract = (\n code: string,\n filename: string,\n options: ExtractPluginOptions = {}\n): { code: string; map?: unknown; extracted: boolean } | null => {\n const {\n defaultLocale = DEFAULT_LOCALE,\n packageName = 'vue-intlayer',\n filesList,\n shouldExtract,\n onExtract,\n dictionaryKey: dictionaryKeyOption,\n attributesToExtract = [],\n extractDictionaryKeyFromPath,\n generateKey,\n } = options;\n\n if (!shouldProcessFile(filename, filesList)) return null;\n if (!filename.endsWith('.vue')) return null;\n\n let parseVue: (code: string) => VueParseResult;\n\n try {\n parseVue = vueSfc.parse as unknown as (code: string) => VueParseResult;\n } catch {\n console.warn('Vue extraction: @vue/compiler-sfc not found.');\n return null;\n }\n\n const sfc = parseVue(code);\n const magic = new MagicString(code);\n\n const extractedContent: ExtractedContent = {};\n const existingKeys = new Set<string>();\n const dictionaryKey =\n dictionaryKeyOption ?? extractDictionaryKeyFromPath?.(filename) ?? '';\n const replacements: Replacement[] = [];\n\n // Detect existing useIntlayer / getIntlayer call in the script block BEFORE\n // walking the template, so the correct access pattern can be chosen.\n const scriptBlock = sfc.descriptor.scriptSetup ?? sfc.descriptor.script;\n const existingCallInfo = scriptBlock\n ? detectExistingIntlayerCall(\n scriptBlock.content,\n scriptBlock.loc.start.offset\n )\n : null;\n\n const isDestructured = existingCallInfo?.isDestructured ?? false;\n const varName = existingCallInfo?.variableName ?? 'content';\n\n // Walk Vue Template AST\n if (sfc.descriptor.template) {\n const walkVueAst = (node: VueAstNode) => {\n if (node.type === NODE_TYPES.TEXT) {\n const text = node.content ?? '';\n\n if (shouldExtract?.(text) && generateKey) {\n const key = generateKey(text, existingKeys);\n existingKeys.add(key);\n // When the existing call is destructured, access the key directly;\n // otherwise use the `content` variable.\n const ref = isDestructured ? key : `${varName}.${key}`;\n replacements.push({\n start: node.loc.start.offset,\n end: node.loc.end.offset,\n replacement: `{{ ${ref} }}`,\n key,\n value: text.replace(/\\s+/g, ' ').trim(),\n });\n }\n } else if (node.type === NODE_TYPES.ELEMENT) {\n const children = node.children ?? [];\n\n // Try to handle as insertion (mixed TEXT + INTERPOLATION children)\n if (\n children.length > 0 &&\n children.some((c) => c.type === NODE_TYPES.INTERPOLATION)\n ) {\n const parts: {\n type: 'text' | 'var';\n value: string;\n originalExpr: string;\n }[] = [];\n let hasSignificantText = false;\n let isValid = true;\n\n for (const child of children) {\n if (child.type === NODE_TYPES.TEXT) {\n const text = child.content ?? '';\n if (text.trim().length > 0) hasSignificantText = true;\n parts.push({ type: 'text', value: text, originalExpr: '' });\n } else if (child.type === NODE_TYPES.INTERPOLATION) {\n // Extract the expression source between {{ and }}\n const exprCode = code\n .slice(child.loc.start.offset + 2, child.loc.end.offset - 2)\n .trim();\n const varName = exprCode.includes('.')\n ? exprCode\n .split('.')\n .pop()!\n .replace(/[^\\w$]/g, '')\n : exprCode;\n parts.push({\n type: 'var',\n value: varName,\n originalExpr: exprCode,\n });\n } else {\n isValid = false;\n break;\n }\n }\n\n if (\n isValid &&\n hasSignificantText &&\n parts.some((p) => p.type === 'var')\n ) {\n let combined = '';\n for (const p of parts) {\n combined += p.type === 'var' ? `{{${p.value}}}` : p.value;\n }\n const cleanString = combined.replace(/\\s+/g, ' ').trim();\n\n if (shouldExtract?.(cleanString) && generateKey) {\n const key = generateKey(cleanString, existingKeys);\n existingKeys.add(key);\n const ref = isDestructured ? key : `${varName}.${key}`;\n\n const uniqueVarPairs = [\n ...new Set(\n parts\n .filter((p) => p.type === 'var')\n .map((p) => `${p.value}: ${p.originalExpr}`)\n ),\n ];\n const varArgs = uniqueVarPairs.join(', ');\n const replacement = `{{ ${ref}({ ${varArgs} }) }}`;\n\n const firstChild = children[0];\n const lastChild = children[children.length - 1];\n replacements.push({\n start: firstChild.loc.start.offset,\n end: lastChild.loc.end.offset,\n replacement,\n key,\n value: cleanString,\n });\n\n // Process props but skip children (they are replaced)\n node.props?.forEach((prop) => {\n if (\n prop.type === NODE_TYPES.ATTRIBUTE &&\n (attributesToExtract as readonly string[]).includes(\n prop.name\n ) &&\n prop.value\n ) {\n const text = prop.value.content;\n if (shouldExtract?.(text) && generateKey) {\n const propKey = generateKey(text, existingKeys);\n existingKeys.add(propKey);\n const propRef = isDestructured\n ? propKey\n : `${varName}.${propKey}`;\n replacements.push({\n start: prop.loc.start.offset,\n end: prop.loc.end.offset,\n replacement: `:${prop.name}=\"${propRef}\"`,\n key: propKey,\n value: text.trim(),\n });\n }\n }\n });\n return; // don't recurse into children\n }\n }\n }\n\n // Regular element: handle props\n node.props?.forEach((prop) => {\n if (\n prop.type === NODE_TYPES.ATTRIBUTE &&\n (attributesToExtract as readonly string[]).includes(prop.name) &&\n prop.value\n ) {\n const text = prop.value.content;\n\n if (shouldExtract?.(text) && generateKey) {\n const key = generateKey(text, existingKeys);\n existingKeys.add(key);\n const ref = isDestructured ? key : `${varName}.${key}`;\n replacements.push({\n start: prop.loc.start.offset,\n end: prop.loc.end.offset,\n replacement: `:${prop.name}=\"${ref}\"`,\n key,\n value: text.trim(),\n });\n }\n }\n });\n }\n\n if (node.children) {\n node.children.forEach(walkVueAst);\n }\n };\n\n walkVueAst(sfc.descriptor.template.ast);\n }\n\n // Extract and Walk Script using Babel\n if (scriptBlock) {\n const scriptText = scriptBlock.content;\n const offset = scriptBlock.loc.start.offset;\n\n try {\n const ast = babelParse(scriptText, {\n parserOpts: {\n sourceType: 'module',\n plugins: ['typescript', 'jsx'],\n },\n });\n\n if (ast) {\n traverse(ast, {\n StringLiteral(path: any) {\n if (path.parentPath.isImportDeclaration()) return;\n\n if (path.parentPath.isExportDeclaration()) return;\n\n if (path.parentPath.isImportSpecifier()) return;\n\n if (path.parentPath.isObjectProperty() && path.key === 'key')\n return;\n\n if (path.parentPath.isCallExpression()) {\n const callee = path.parentPath.node.callee;\n\n if (\n t.isMemberExpression(callee) &&\n t.isIdentifier(callee.object) &&\n callee.object.name === 'console'\n )\n return;\n\n if (\n t.isIdentifier(callee) &&\n (callee.name === 'useIntlayer' || callee.name === 't')\n )\n return;\n\n if (callee.type === 'Import') return;\n\n if (t.isIdentifier(callee) && callee.name === 'require') return;\n }\n\n const text = path.node.value;\n\n if (shouldExtract?.(text) && generateKey) {\n const key = generateKey(text, existingKeys);\n existingKeys.add(key);\n\n if (path.node.start != null && path.node.end != null) {\n const ref = isDestructured ? key : `${varName}.${key}`;\n replacements.push({\n start: offset + path.node.start,\n end: offset + path.node.end,\n replacement: ref,\n key,\n value: text.trim(),\n });\n }\n }\n },\n });\n }\n } catch (e) {\n console.warn(\n `Vue extraction: Failed to parse script content for ${filename}`,\n e\n );\n }\n }\n\n // Abort if nothing was extracted\n if (replacements.length === 0) return null;\n\n // Apply Replacements in Reverse Order\n replacements.sort((a, b) => b.start - a.start);\n\n for (const { start, end, replacement, key, value } of replacements) {\n magic.overwrite(start, end, replacement);\n extractedContent[key] = value;\n }\n\n // When the existing call is destructured, inject only the missing keys into\n // the ObjectPattern — no new `content` variable is needed.\n if (\n existingCallInfo?.isDestructured &&\n existingCallInfo.closingBraceAbsolutePos >= 0\n ) {\n const missingKeys = Object.keys(extractedContent).filter(\n (k) => !existingCallInfo.existingDestructuredKeys.includes(k)\n );\n\n if (missingKeys.length > 0) {\n // Insert right after the last property so the space/newline before `}`\n // is naturally preserved: `{ a }` → `{ a, b }`.\n magic.appendLeft(\n existingCallInfo.lastPropAbsoluteEnd,\n `, ${missingKeys.join(', ')}`\n );\n }\n }\n\n // Inject necessary imports and setup (only when no existing call was detected)\n const finalScriptContent = scriptBlock?.content ?? '';\n\n const hasUseIntlayerImport =\n /import\\s*{[^}]*useIntlayer[^}]*}\\s*from\\s*['\"][^'\"]+['\"]/.test(\n finalScriptContent\n ) ||\n /import\\s+useIntlayer\\s+from\\s*['\"][^'\"]+['\"]/.test(finalScriptContent);\n\n // An existing call (destructured or not) means no new declaration is needed.\n const hasContentDeclaration =\n existingCallInfo !== null ||\n /const\\s+content\\s*=\\s*useIntlayer\\s*\\(/.test(finalScriptContent);\n\n const importStmt = hasUseIntlayerImport\n ? ''\n : `import { useIntlayer } from '${packageName}';`;\n const contentDecl = hasContentDeclaration\n ? ''\n : `const content = useIntlayer('${dictionaryKey}');`;\n\n const injectionParts = [importStmt, contentDecl].filter(Boolean);\n\n if (injectionParts.length > 0) {\n const injection = `\\n${injectionParts.join('\\n')}\\n`;\n\n if (sfc.descriptor.scriptSetup) {\n magic.appendLeft(sfc.descriptor.scriptSetup.loc.start.offset, injection);\n } else if (sfc.descriptor.script) {\n magic.appendLeft(sfc.descriptor.script.loc.start.offset, injection);\n } else {\n magic.prepend(\n `<script setup>\\n${importStmt}\\n${contentDecl}\\n</script>\\n`\n );\n }\n }\n\n if (onExtract) {\n onExtract({\n dictionaryKey,\n filePath: filename,\n content: { ...extractedContent },\n locale: defaultLocale,\n });\n }\n\n return {\n code: magic.toString(),\n map: magic.generateMap({ source: filename, includeContent: true }),\n extracted: true,\n };\n};\n\ntype Tools = {\n generateKey: (text: string, existingKeys: Set<string>) => string;\n shouldExtract: (text: string) => boolean;\n extractDictionaryKeyFromPath: (path: string) => string;\n attributesToExtract: readonly string[];\n extractTsContent: any;\n};\n\nexport const processVueFile = (\n filePath: string,\n _componentKey: string,\n packageName: string,\n tools: Tools,\n save: boolean = true,\n providedCode?: string\n): {\n extractedContent: Record<string, string>;\n code: string;\n map?: any;\n} | null => {\n const code = providedCode ?? readFileSync(filePath, 'utf-8');\n let extractedContent: Record<string, string> = {};\n\n const result = intlayerVueExtract(code, filePath, {\n packageName,\n dictionaryKey: _componentKey,\n shouldExtract: tools.shouldExtract,\n generateKey: tools.generateKey,\n extractDictionaryKeyFromPath: tools.extractDictionaryKeyFromPath,\n attributesToExtract: tools.attributesToExtract,\n onExtract: (extractResult) => {\n extractedContent = extractResult.content;\n },\n });\n\n if (!result) return null;\n\n if (save) {\n writeFileSync(filePath, result.code);\n }\n\n return {\n extractedContent,\n code: result.code,\n map: result.map,\n };\n};\n"],"mappings":";;;;;;;;;;;;;;AAyBA,MAAM,8BACJ,YACA,mBACqB;CACrB,IAAI,OAAyB;AAE7B,KAAI;EACF,MAAM,MAAMA,MAAW,YAAY,EACjC,YAAY;GAAE,YAAY;GAAU,SAAS,CAAC,cAAc,MAAM;GAAE,EACrE,CAAC;AAEF,MAAI,CAAC,IAAK,QAAO;AAEjB,WAAS,KAAK,EACZ,eAAe,MAAW;GACxB,MAAM,SAAS,KAAK,KAAK;AAEzB,OACE,CAACC,MAAE,aAAa,OAAO,IACtB,OAAO,SAAS,iBAAiB,OAAO,SAAS,cAElD;GAEF,MAAM,SAAS,KAAK;AAEpB,OAAIA,MAAE,qBAAqB,OAAO,IAAIA,MAAE,gBAAgB,OAAO,GAAG,EAAE;IAClE,MAAM,aAAa,OAAO,GAAG;IAC7B,MAAM,2BAA2B,WAC9B,QACE,aACCA,MAAE,iBAAiB,SAAS,IAAIA,MAAE,aAAa,SAAS,IAAI,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ayer-extract.ts"],"sourcesContent":["import { readFileSync, writeFileSync } from 'node:fs';\nimport { parse as babelParse, types as t, traverse } from '@babel/core';\nimport { DEFAULT_LOCALE } from '@intlayer/config/defaultValues';\nimport type { Locale } from '@intlayer/types/allLocales';\nimport vueSfc from '@vue/compiler-sfc';\nimport MagicString from 'magic-string';\n\ntype ExistingCallInfo = {\n isDestructured: boolean;\n existingDestructuredKeys: string[];\n /** The variable name used to store the call result (e.g. `t` in `const t = useIntlayer(...)`) */\n variableName: string;\n /** Absolute position of `}` in the full file — only valid when `isDestructured` */\n closingBraceAbsolutePos: number;\n /** Absolute position of end of last property — only valid when `isDestructured` */\n lastPropAbsoluteEnd: number;\n} | null;\n\n/**\n * Detects whether the script block already contains a `useIntlayer` /\n * `getIntlayer` call and, if so, whether its result is destructured.\n *\n * @param scriptText Raw text of the script block content.\n * @param absoluteOffset Byte offset of `scriptText[0]` in the full SFC source.\n */\nconst detectExistingIntlayerCall = (\n scriptText: string,\n absoluteOffset: number\n): ExistingCallInfo => {\n let info: ExistingCallInfo = null;\n\n try {\n const ast = babelParse(scriptText, {\n parserOpts: { sourceType: 'module', plugins: ['typescript', 'jsx'] },\n });\n\n if (!ast) return null;\n\n traverse(ast, {\n CallExpression(path: any) {\n const callee = path.node.callee;\n\n if (\n !t.isIdentifier(callee) ||\n (callee.name !== 'useIntlayer' && callee.name !== 'getIntlayer')\n )\n return;\n\n const parent = path.parent;\n\n if (t.isVariableDeclarator(parent) && t.isObjectPattern(parent.id)) {\n const properties = parent.id.properties;\n const existingDestructuredKeys = properties\n .filter(\n (property: any): property is typeof t.objectProperty =>\n t.isObjectProperty(property) && t.isIdentifier(property.key)\n )\n .map((property: any) => (property.key as any).name as string);\n const lastProp = properties[properties.length - 1];\n\n info = {\n isDestructured: true,\n variableName: 'content',\n existingDestructuredKeys,\n closingBraceAbsolutePos: absoluteOffset + (parent.id.end! - 1),\n lastPropAbsoluteEnd: absoluteOffset + lastProp.end!,\n };\n } else {\n const variableName =\n t.isVariableDeclarator(parent) && t.isIdentifier(parent.id)\n ? parent.id.name\n : 'content';\n\n info = {\n isDestructured: false,\n variableName,\n existingDestructuredKeys: [],\n closingBraceAbsolutePos: -1,\n lastPropAbsoluteEnd: -1,\n };\n }\n\n path.stop();\n },\n });\n } catch {\n // Silently ignore parse failures — fall back to no-info\n }\n\n return info;\n};\n\nexport type ExtractedContent = Record<string, string>;\n\nexport type ExtractResult = {\n dictionaryKey: string;\n filePath: string;\n content: ExtractedContent;\n locale: Locale;\n};\n\nexport type ExtractPluginOptions = {\n defaultLocale?: Locale;\n packageName?: string;\n filesList?: string[];\n shouldExtract?: (text: string) => boolean;\n onExtract?: (result: ExtractResult) => void;\n dictionaryKey?: string;\n attributesToExtract?: readonly string[];\n extractDictionaryKeyFromPath?: (path: string) => string;\n generateKey?: (text: string, existingKeys: Set<string>) => string;\n};\n\ntype Replacement = {\n start: number;\n end: number;\n replacement: string;\n key: string;\n value: string;\n};\n\nexport const shouldProcessFile = (\n filename: string | undefined,\n filesList?: string[]\n): boolean => {\n if (!filename) return false;\n if (!filesList || filesList.length === 0) return true;\n\n const normalizedFilename = filename.replace(/\\\\/g, '/');\n return filesList.some((f) => {\n const normalizedF = f.replace(/\\\\/g, '/');\n return normalizedF === normalizedFilename;\n });\n};\n\ntype VueParseResult = {\n descriptor: {\n template?: {\n ast: VueAstNode;\n loc: { start: { offset: number }; end: { offset: number } };\n };\n script?: {\n content: string;\n loc: { start: { offset: number }; end: { offset: number } };\n };\n scriptSetup?: {\n content: string;\n loc: { start: { offset: number }; end: { offset: number } };\n };\n };\n};\n\ntype VueAstNode = {\n type: number;\n content?: string;\n children?: VueAstNode[];\n props?: VueAstProp[];\n loc: { start: { offset: number }; end: { offset: number } };\n};\n\ntype VueAstProp = {\n type: number;\n name: string;\n value?: { content: string };\n loc: { start: { offset: number }; end: { offset: number } };\n};\n\nconst NODE_TYPES = {\n TEXT: 2,\n ELEMENT: 1,\n ATTRIBUTE: 6,\n INTERPOLATION: 5,\n};\n\nexport const intlayerVueExtract = (\n code: string,\n filename: string,\n options: ExtractPluginOptions = {}\n): { code: string; map?: unknown; extracted: boolean } | null => {\n const {\n defaultLocale = DEFAULT_LOCALE,\n packageName = 'vue-intlayer',\n filesList,\n shouldExtract,\n onExtract,\n dictionaryKey: dictionaryKeyOption,\n attributesToExtract = [],\n extractDictionaryKeyFromPath,\n generateKey,\n } = options;\n\n if (!shouldProcessFile(filename, filesList)) return null;\n if (!filename.endsWith('.vue')) return null;\n\n let parseVue: (code: string) => VueParseResult;\n\n try {\n parseVue = vueSfc.parse as unknown as (code: string) => VueParseResult;\n } catch {\n console.warn('Vue extraction: @vue/compiler-sfc not found.');\n return null;\n }\n\n const sfc = parseVue(code);\n const magic = new MagicString(code);\n\n const extractedContent: ExtractedContent = {};\n const existingKeys = new Set<string>();\n const dictionaryKey =\n dictionaryKeyOption ?? extractDictionaryKeyFromPath?.(filename) ?? '';\n const replacements: Replacement[] = [];\n\n // Detect existing useIntlayer / getIntlayer call in the script block BEFORE\n // walking the template, so the correct access pattern can be chosen.\n const scriptBlock = sfc.descriptor.scriptSetup ?? sfc.descriptor.script;\n const existingCallInfo = scriptBlock\n ? detectExistingIntlayerCall(\n scriptBlock.content,\n scriptBlock.loc.start.offset\n )\n : null;\n\n const isDestructured = existingCallInfo?.isDestructured ?? false;\n const varName = existingCallInfo?.variableName ?? 'content';\n\n // Walk Vue Template AST\n if (sfc.descriptor.template) {\n const walkVueAst = (node: VueAstNode) => {\n if (node.type === NODE_TYPES.TEXT) {\n const text = node.content ?? '';\n\n if (shouldExtract?.(text) && generateKey) {\n const key = generateKey(text, existingKeys);\n existingKeys.add(key);\n // When the existing call is destructured, access the key directly;\n // otherwise use the `content` variable.\n const ref = isDestructured ? key : `${varName}.${key}`;\n replacements.push({\n start: node.loc.start.offset,\n end: node.loc.end.offset,\n replacement: `{{ ${ref} }}`,\n key,\n value: text.replace(/\\s+/g, ' ').trim(),\n });\n }\n } else if (node.type === NODE_TYPES.ELEMENT) {\n const children = node.children ?? [];\n\n // Try to handle as insertion (mixed TEXT + INTERPOLATION children)\n if (\n children.length > 0 &&\n children.some((c) => c.type === NODE_TYPES.INTERPOLATION)\n ) {\n const parts: {\n type: 'text' | 'var';\n value: string;\n originalExpr: string;\n }[] = [];\n let hasSignificantText = false;\n let isValid = true;\n\n for (const child of children) {\n if (child.type === NODE_TYPES.TEXT) {\n const text = child.content ?? '';\n if (text.trim().length > 0) hasSignificantText = true;\n parts.push({ type: 'text', value: text, originalExpr: '' });\n } else if (child.type === NODE_TYPES.INTERPOLATION) {\n // Extract the expression source between {{ and }}\n const exprCode = code\n .slice(child.loc.start.offset + 2, child.loc.end.offset - 2)\n .trim();\n const varName = exprCode.includes('.')\n ? exprCode\n .split('.')\n .pop()!\n .replace(/[^\\w$]/g, '')\n : exprCode;\n parts.push({\n type: 'var',\n value: varName,\n originalExpr: exprCode,\n });\n } else {\n isValid = false;\n break;\n }\n }\n\n if (\n isValid &&\n hasSignificantText &&\n parts.some((p) => p.type === 'var')\n ) {\n let combined = '';\n for (const p of parts) {\n combined += p.type === 'var' ? `{{${p.value}}}` : p.value;\n }\n const cleanString = combined.replace(/\\s+/g, ' ').trim();\n\n if (shouldExtract?.(cleanString) && generateKey) {\n const key = generateKey(cleanString, existingKeys);\n existingKeys.add(key);\n const ref = isDestructured ? key : `${varName}.${key}`;\n\n const uniqueVarPairs = [\n ...new Set(\n parts\n .filter((p) => p.type === 'var')\n .map((p) => `${p.value}: ${p.originalExpr}`)\n ),\n ];\n const varArgs = uniqueVarPairs.join(', ');\n const replacement = `{{ ${ref}({ ${varArgs} }) }}`;\n\n const firstChild = children[0];\n const lastChild = children[children.length - 1];\n replacements.push({\n start: firstChild.loc.start.offset,\n end: lastChild.loc.end.offset,\n replacement,\n key,\n value: cleanString,\n });\n\n // Process props but skip children (they are replaced)\n node.props?.forEach((prop) => {\n if (\n prop.type === NODE_TYPES.ATTRIBUTE &&\n (attributesToExtract as readonly string[]).includes(\n prop.name\n ) &&\n prop.value\n ) {\n const text = prop.value.content;\n if (shouldExtract?.(text) && generateKey) {\n const propKey = generateKey(text, existingKeys);\n existingKeys.add(propKey);\n const propRef = isDestructured\n ? propKey\n : `${varName}.${propKey}`;\n replacements.push({\n start: prop.loc.start.offset,\n end: prop.loc.end.offset,\n replacement: `:${prop.name}=\"${propRef}\"`,\n key: propKey,\n value: text.trim(),\n });\n }\n }\n });\n return; // don't recurse into children\n }\n }\n }\n\n // Regular element: handle props\n node.props?.forEach((prop) => {\n if (\n prop.type === NODE_TYPES.ATTRIBUTE &&\n (attributesToExtract as readonly string[]).includes(prop.name) &&\n prop.value\n ) {\n const text = prop.value.content;\n\n if (shouldExtract?.(text) && generateKey) {\n const key = generateKey(text, existingKeys);\n existingKeys.add(key);\n const ref = isDestructured ? key : `${varName}.${key}`;\n replacements.push({\n start: prop.loc.start.offset,\n end: prop.loc.end.offset,\n replacement: `:${prop.name}=\"${ref}\"`,\n key,\n value: text.trim(),\n });\n }\n }\n });\n }\n\n if (node.children) {\n node.children.forEach(walkVueAst);\n }\n };\n\n walkVueAst(sfc.descriptor.template.ast);\n }\n\n // Extract and Walk Script using Babel\n if (scriptBlock) {\n const scriptText = scriptBlock.content;\n const offset = scriptBlock.loc.start.offset;\n\n try {\n const ast = babelParse(scriptText, {\n parserOpts: {\n sourceType: 'module',\n plugins: ['typescript', 'jsx'],\n },\n });\n\n if (ast) {\n traverse(ast, {\n StringLiteral(path: any) {\n if (path.parentPath.isImportDeclaration()) return;\n\n if (path.parentPath.isExportDeclaration()) return;\n\n if (path.parentPath.isImportSpecifier()) return;\n\n if (path.parentPath.isObjectProperty() && path.key === 'key')\n return;\n\n if (path.parentPath.isCallExpression()) {\n const callee = path.parentPath.node.callee;\n\n if (\n t.isMemberExpression(callee) &&\n t.isIdentifier(callee.object) &&\n callee.object.name === 'console'\n )\n return;\n\n if (\n t.isIdentifier(callee) &&\n (callee.name === 'useIntlayer' || callee.name === 't')\n )\n return;\n\n if (callee.type === 'Import') return;\n\n if (t.isIdentifier(callee) && callee.name === 'require') return;\n }\n\n const text = path.node.value;\n\n if (shouldExtract?.(text) && generateKey) {\n const key = generateKey(text, existingKeys);\n existingKeys.add(key);\n\n if (path.node.start != null && path.node.end != null) {\n const ref = isDestructured ? key : `${varName}.${key}`;\n replacements.push({\n start: offset + path.node.start,\n end: offset + path.node.end,\n replacement: ref,\n key,\n value: text.trim(),\n });\n }\n }\n },\n });\n }\n } catch (e) {\n console.warn(\n `Vue extraction: Failed to parse script content for ${filename}`,\n e\n );\n }\n }\n\n // Abort if nothing was extracted\n if (replacements.length === 0) return null;\n\n // Apply Replacements in Reverse Order\n replacements.sort((a, b) => b.start - a.start);\n\n for (const { start, end, replacement, key, value } of replacements) {\n magic.overwrite(start, end, replacement);\n extractedContent[key] = value;\n }\n\n // When the existing call is destructured, inject only the missing keys into\n // the ObjectPattern — no new `content` variable is needed.\n if (\n existingCallInfo?.isDestructured &&\n existingCallInfo.closingBraceAbsolutePos >= 0\n ) {\n const missingKeys = Object.keys(extractedContent).filter(\n (k) => !existingCallInfo.existingDestructuredKeys.includes(k)\n );\n\n if (missingKeys.length > 0) {\n // Insert right after the last property so the space/newline before `}`\n // is naturally preserved: `{ a }` → `{ a, b }`.\n magic.appendLeft(\n existingCallInfo.lastPropAbsoluteEnd,\n `, ${missingKeys.join(', ')}`\n );\n }\n }\n\n // Inject necessary imports and setup (only when no existing call was detected)\n const finalScriptContent = scriptBlock?.content ?? '';\n\n const hasUseIntlayerImport =\n /import\\s*{[^}]*useIntlayer[^}]*}\\s*from\\s*['\"][^'\"]+['\"]/.test(\n finalScriptContent\n ) ||\n /import\\s+useIntlayer\\s+from\\s*['\"][^'\"]+['\"]/.test(finalScriptContent);\n\n // An existing call (destructured or not) means no new declaration is needed.\n const hasContentDeclaration =\n existingCallInfo !== null ||\n /const\\s+content\\s*=\\s*useIntlayer\\s*\\(/.test(finalScriptContent);\n\n const importStmt = hasUseIntlayerImport\n ? ''\n : `import { useIntlayer } from '${packageName}';`;\n const contentDecl = hasContentDeclaration\n ? ''\n : `const content = useIntlayer('${dictionaryKey}');`;\n\n const injectionParts = [importStmt, contentDecl].filter(Boolean);\n\n if (injectionParts.length > 0) {\n const injection = `\\n${injectionParts.join('\\n')}\\n`;\n\n if (sfc.descriptor.scriptSetup) {\n magic.appendLeft(sfc.descriptor.scriptSetup.loc.start.offset, injection);\n } else if (sfc.descriptor.script) {\n magic.appendLeft(sfc.descriptor.script.loc.start.offset, injection);\n } else {\n magic.prepend(\n `<script setup>\\n${importStmt}\\n${contentDecl}\\n</script>\\n`\n );\n }\n }\n\n if (onExtract) {\n onExtract({\n dictionaryKey,\n filePath: filename,\n content: { ...extractedContent },\n locale: defaultLocale,\n });\n }\n\n return {\n code: magic.toString(),\n map: magic.generateMap({ source: filename, includeContent: true }),\n extracted: true,\n };\n};\n\ntype Tools = {\n generateKey: (text: string, existingKeys: Set<string>) => string;\n shouldExtract: (text: string) => boolean;\n extractDictionaryKeyFromPath: (path: string) => string;\n attributesToExtract: readonly string[];\n extractTsContent: any;\n};\n\nexport const processVueFile = (\n filePath: string,\n _componentKey: string,\n packageName: string,\n tools: Tools,\n save: boolean = true,\n providedCode?: string\n): {\n extractedContent: Record<string, string>;\n code: string;\n map?: any;\n} | null => {\n const code = providedCode ?? readFileSync(filePath, 'utf-8');\n let extractedContent: Record<string, string> = {};\n\n const result = intlayerVueExtract(code, filePath, {\n packageName,\n dictionaryKey: _componentKey,\n shouldExtract: tools.shouldExtract,\n generateKey: tools.generateKey,\n extractDictionaryKeyFromPath: tools.extractDictionaryKeyFromPath,\n attributesToExtract: tools.attributesToExtract,\n onExtract: (extractResult) => {\n extractedContent = extractResult.content;\n },\n });\n\n if (!result) return null;\n\n if (save) {\n writeFileSync(filePath, result.code);\n }\n\n return {\n extractedContent,\n code: result.code,\n map: result.map,\n };\n};\n"],"mappings":";;;;;;;;;;;;;;AAyBA,MAAM,8BACJ,YACA,mBACqB;CACrB,IAAI,OAAy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MAAa,kBACX,UACA,eACA,aACA,OACA,OAAgB,MAChB,iBAKU;CACV,MAAM,OAAO,gBAAgB,aAAa,UAAU,QAAQ;CAC5D,IAAI,mBAA2C,EAAE;CAEjD,MAAM,SAAS,mBAAmB,MAAM,UAAU;EAChD;EACA,eAAe;EACf,eAAe,MAAM;EACrB,aAAa,MAAM;EACnB,8BAA8B,MAAM;EACpC,qBAAqB,MAAM;EAC3B,YAAY,kBAAkB;GAC5B,mBAAmB,cAAc;;EAEpC,CAAC;CAEF,IAAI,CAAC,QAAQ,OAAO;CAEpB,IAAI,MACF,cAAc,UAAU,OAAO,KAAK;CAGtC,OAAO;EACL;EACA,MAAM,OAAO;EACb,KAAK,OAAO;EACb"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@intlayer/vue-compiler",
|
|
3
|
-
"version": "8.9.
|
|
3
|
+
"version": "8.9.4-canary.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "Vite-compatible compiler plugin for Vue with Intlayer, providing HMR support, file transformation, and optimized dictionary loading for Vue applications.",
|
|
6
6
|
"keywords": [
|
|
@@ -78,8 +78,8 @@
|
|
|
78
78
|
},
|
|
79
79
|
"dependencies": {
|
|
80
80
|
"@babel/core": "7.29.0",
|
|
81
|
-
"@intlayer/config": "8.9.
|
|
82
|
-
"@intlayer/types": "8.9.
|
|
81
|
+
"@intlayer/config": "8.9.4-canary.0",
|
|
82
|
+
"@intlayer/types": "8.9.4-canary.0",
|
|
83
83
|
"@vue/compiler-sfc": ">=3.0.0",
|
|
84
84
|
"fast-glob": "3.3.3",
|
|
85
85
|
"magic-string": "0.30.21"
|
|
@@ -88,12 +88,12 @@
|
|
|
88
88
|
"@types/babel__core": "7.20.5",
|
|
89
89
|
"@types/babel__generator": "7.27.0",
|
|
90
90
|
"@types/babel__traverse": "7.28.0",
|
|
91
|
-
"@types/node": "25.6.
|
|
91
|
+
"@types/node": "25.6.2",
|
|
92
92
|
"@utils/ts-config": "1.0.4",
|
|
93
93
|
"@utils/ts-config-types": "1.0.4",
|
|
94
94
|
"@utils/tsdown-config": "1.0.4",
|
|
95
95
|
"rimraf": "6.1.3",
|
|
96
|
-
"tsdown": "0.
|
|
96
|
+
"tsdown": "0.22.00",
|
|
97
97
|
"typescript": "6.0.3",
|
|
98
98
|
"vitest": "4.1.5"
|
|
99
99
|
},
|