@intlayer/vue-compiler 8.4.4 → 8.4.5

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.
@@ -0,0 +1,29 @@
1
+ //#region \0rolldown/runtime.js
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __copyProps = (to, from, except, desc) => {
9
+ if (from && typeof from === "object" || typeof from === "function") {
10
+ for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
11
+ key = keys[i];
12
+ if (!__hasOwnProp.call(to, key) && key !== except) {
13
+ __defProp(to, key, {
14
+ get: ((k) => from[k]).bind(null, key),
15
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
16
+ });
17
+ }
18
+ }
19
+ }
20
+ return to;
21
+ };
22
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
23
+ value: mod,
24
+ enumerable: true
25
+ }) : target, mod));
26
+
27
+ //#endregion
28
+
29
+ exports.__toESM = __toESM;
@@ -1 +1,6 @@
1
- Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require(`./vue-intlayer-extract-Dgb1qjP9.cjs`);exports.intlayerVueExtract=e.t,exports.processVueFile=e.n,exports.shouldProcessFile=e.r;
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
+ const require_vue_intlayer_extract = require('./vue-intlayer-extract.cjs');
3
+
4
+ exports.intlayerVueExtract = require_vue_intlayer_extract.intlayerVueExtract;
5
+ exports.processVueFile = require_vue_intlayer_extract.processVueFile;
6
+ exports.shouldProcessFile = require_vue_intlayer_extract.shouldProcessFile;
@@ -1 +1,295 @@
1
- Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require(`./vue-intlayer-extract-Dgb1qjP9.cjs`);exports.intlayerVueExtract=e.t,exports.processVueFile=e.n,exports.shouldProcessFile=e.r;
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
+ const require_runtime = require('./_virtual/_rolldown/runtime.cjs');
3
+ let node_fs = require("node:fs");
4
+ let _babel_core = require("@babel/core");
5
+ let _intlayer_config_defaultValues = require("@intlayer/config/defaultValues");
6
+ let _vue_compiler_sfc = require("@vue/compiler-sfc");
7
+ _vue_compiler_sfc = require_runtime.__toESM(_vue_compiler_sfc);
8
+ let magic_string = require("magic-string");
9
+ magic_string = require_runtime.__toESM(magic_string);
10
+
11
+ //#region src/vue-intlayer-extract.ts
12
+ /**
13
+ * Detects whether the script block already contains a `useIntlayer` /
14
+ * `getIntlayer` call and, if so, whether its result is destructured.
15
+ *
16
+ * @param scriptText Raw text of the script block content.
17
+ * @param absoluteOffset Byte offset of `scriptText[0]` in the full SFC source.
18
+ */
19
+ const detectExistingIntlayerCall = (scriptText, absoluteOffset) => {
20
+ let info = null;
21
+ try {
22
+ const ast = (0, _babel_core.parse)(scriptText, { parserOpts: {
23
+ sourceType: "module",
24
+ plugins: ["typescript", "jsx"]
25
+ } });
26
+ if (!ast) return null;
27
+ (0, _babel_core.traverse)(ast, { CallExpression(path) {
28
+ const callee = path.node.callee;
29
+ if (!_babel_core.types.isIdentifier(callee) || callee.name !== "useIntlayer" && callee.name !== "getIntlayer") return;
30
+ const parent = path.parent;
31
+ if (_babel_core.types.isVariableDeclarator(parent) && _babel_core.types.isObjectPattern(parent.id)) {
32
+ const properties = parent.id.properties;
33
+ const existingDestructuredKeys = properties.filter((property) => _babel_core.types.isObjectProperty(property) && _babel_core.types.isIdentifier(property.key)).map((property) => property.key.name);
34
+ const lastProp = properties[properties.length - 1];
35
+ info = {
36
+ isDestructured: true,
37
+ variableName: "content",
38
+ existingDestructuredKeys,
39
+ closingBraceAbsolutePos: absoluteOffset + (parent.id.end - 1),
40
+ lastPropAbsoluteEnd: absoluteOffset + lastProp.end
41
+ };
42
+ } else info = {
43
+ isDestructured: false,
44
+ variableName: _babel_core.types.isVariableDeclarator(parent) && _babel_core.types.isIdentifier(parent.id) ? parent.id.name : "content",
45
+ existingDestructuredKeys: [],
46
+ closingBraceAbsolutePos: -1,
47
+ lastPropAbsoluteEnd: -1
48
+ };
49
+ path.stop();
50
+ } });
51
+ } catch {}
52
+ return info;
53
+ };
54
+ const shouldProcessFile = (filename, filesList) => {
55
+ if (!filename) return false;
56
+ if (!filesList || filesList.length === 0) return true;
57
+ const normalizedFilename = filename.replace(/\\/g, "/");
58
+ return filesList.some((f) => {
59
+ return f.replace(/\\/g, "/") === normalizedFilename;
60
+ });
61
+ };
62
+ const NODE_TYPES = {
63
+ TEXT: 2,
64
+ ELEMENT: 1,
65
+ ATTRIBUTE: 6,
66
+ INTERPOLATION: 5
67
+ };
68
+ const intlayerVueExtract = (code, filename, options = {}) => {
69
+ const { defaultLocale = _intlayer_config_defaultValues.DEFAULT_LOCALE, packageName = "vue-intlayer", filesList, shouldExtract, onExtract, dictionaryKey: dictionaryKeyOption, attributesToExtract = [], extractDictionaryKeyFromPath, generateKey } = options;
70
+ if (!shouldProcessFile(filename, filesList)) return null;
71
+ if (!filename.endsWith(".vue")) return null;
72
+ let parseVue;
73
+ try {
74
+ parseVue = _vue_compiler_sfc.default.parse;
75
+ } catch {
76
+ console.warn("Vue extraction: @vue/compiler-sfc not found.");
77
+ return null;
78
+ }
79
+ const sfc = parseVue(code);
80
+ const magic = new magic_string.default(code);
81
+ const extractedContent = {};
82
+ const existingKeys = /* @__PURE__ */ new Set();
83
+ const dictionaryKey = dictionaryKeyOption ?? extractDictionaryKeyFromPath?.(filename) ?? "";
84
+ const replacements = [];
85
+ const scriptBlock = sfc.descriptor.scriptSetup ?? sfc.descriptor.script;
86
+ const existingCallInfo = scriptBlock ? detectExistingIntlayerCall(scriptBlock.content, scriptBlock.loc.start.offset) : null;
87
+ const isDestructured = existingCallInfo?.isDestructured ?? false;
88
+ const varName = existingCallInfo?.variableName ?? "content";
89
+ if (sfc.descriptor.template) {
90
+ const walkVueAst = (node) => {
91
+ if (node.type === NODE_TYPES.TEXT) {
92
+ const text = node.content ?? "";
93
+ if (shouldExtract?.(text) && generateKey) {
94
+ const key = generateKey(text, existingKeys);
95
+ existingKeys.add(key);
96
+ const ref = isDestructured ? key : `${varName}.${key}`;
97
+ replacements.push({
98
+ start: node.loc.start.offset,
99
+ end: node.loc.end.offset,
100
+ replacement: `{{ ${ref} }}`,
101
+ key,
102
+ value: text.replace(/\s+/g, " ").trim()
103
+ });
104
+ }
105
+ } else if (node.type === NODE_TYPES.ELEMENT) {
106
+ const children = node.children ?? [];
107
+ if (children.length > 0 && children.some((c) => c.type === NODE_TYPES.INTERPOLATION)) {
108
+ const parts = [];
109
+ let hasSignificantText = false;
110
+ let isValid = true;
111
+ for (const child of children) if (child.type === NODE_TYPES.TEXT) {
112
+ const text = child.content ?? "";
113
+ if (text.trim().length > 0) hasSignificantText = true;
114
+ parts.push({
115
+ type: "text",
116
+ value: text,
117
+ originalExpr: ""
118
+ });
119
+ } else if (child.type === NODE_TYPES.INTERPOLATION) {
120
+ const exprCode = code.slice(child.loc.start.offset + 2, child.loc.end.offset - 2).trim();
121
+ const varName = exprCode.includes(".") ? exprCode.split(".").pop().replace(/[^\w$]/g, "") : exprCode;
122
+ parts.push({
123
+ type: "var",
124
+ value: varName,
125
+ originalExpr: exprCode
126
+ });
127
+ } else {
128
+ isValid = false;
129
+ break;
130
+ }
131
+ if (isValid && hasSignificantText && parts.some((p) => p.type === "var")) {
132
+ let combined = "";
133
+ for (const p of parts) combined += p.type === "var" ? `{{${p.value}}}` : p.value;
134
+ const cleanString = combined.replace(/\s+/g, " ").trim();
135
+ if (shouldExtract?.(cleanString) && generateKey) {
136
+ const key = generateKey(cleanString, existingKeys);
137
+ existingKeys.add(key);
138
+ const replacement = `{{ ${isDestructured ? key : `${varName}.${key}`}({ ${[...new Set(parts.filter((p) => p.type === "var").map((p) => `${p.value}: ${p.originalExpr}`))].join(", ")} }) }}`;
139
+ const firstChild = children[0];
140
+ const lastChild = children[children.length - 1];
141
+ replacements.push({
142
+ start: firstChild.loc.start.offset,
143
+ end: lastChild.loc.end.offset,
144
+ replacement,
145
+ key,
146
+ value: cleanString
147
+ });
148
+ node.props?.forEach((prop) => {
149
+ if (prop.type === NODE_TYPES.ATTRIBUTE && attributesToExtract.includes(prop.name) && prop.value) {
150
+ const text = prop.value.content;
151
+ if (shouldExtract?.(text) && generateKey) {
152
+ const propKey = generateKey(text, existingKeys);
153
+ existingKeys.add(propKey);
154
+ const propRef = isDestructured ? propKey : `${varName}.${propKey}`;
155
+ replacements.push({
156
+ start: prop.loc.start.offset,
157
+ end: prop.loc.end.offset,
158
+ replacement: `:${prop.name}="${propRef}"`,
159
+ key: propKey,
160
+ value: text.trim()
161
+ });
162
+ }
163
+ }
164
+ });
165
+ return;
166
+ }
167
+ }
168
+ }
169
+ node.props?.forEach((prop) => {
170
+ if (prop.type === NODE_TYPES.ATTRIBUTE && attributesToExtract.includes(prop.name) && prop.value) {
171
+ const text = prop.value.content;
172
+ if (shouldExtract?.(text) && generateKey) {
173
+ const key = generateKey(text, existingKeys);
174
+ existingKeys.add(key);
175
+ const ref = isDestructured ? key : `${varName}.${key}`;
176
+ replacements.push({
177
+ start: prop.loc.start.offset,
178
+ end: prop.loc.end.offset,
179
+ replacement: `:${prop.name}="${ref}"`,
180
+ key,
181
+ value: text.trim()
182
+ });
183
+ }
184
+ }
185
+ });
186
+ }
187
+ if (node.children) node.children.forEach(walkVueAst);
188
+ };
189
+ walkVueAst(sfc.descriptor.template.ast);
190
+ }
191
+ if (scriptBlock) {
192
+ const scriptText = scriptBlock.content;
193
+ const offset = scriptBlock.loc.start.offset;
194
+ try {
195
+ const ast = (0, _babel_core.parse)(scriptText, { parserOpts: {
196
+ sourceType: "module",
197
+ plugins: ["typescript", "jsx"]
198
+ } });
199
+ if (ast) (0, _babel_core.traverse)(ast, { StringLiteral(path) {
200
+ if (path.parentPath.isImportDeclaration()) return;
201
+ if (path.parentPath.isExportDeclaration()) return;
202
+ if (path.parentPath.isImportSpecifier()) return;
203
+ if (path.parentPath.isObjectProperty() && path.key === "key") return;
204
+ if (path.parentPath.isCallExpression()) {
205
+ const callee = path.parentPath.node.callee;
206
+ if (_babel_core.types.isMemberExpression(callee) && _babel_core.types.isIdentifier(callee.object) && callee.object.name === "console") return;
207
+ if (_babel_core.types.isIdentifier(callee) && (callee.name === "useIntlayer" || callee.name === "t")) return;
208
+ if (callee.type === "Import") return;
209
+ if (_babel_core.types.isIdentifier(callee) && callee.name === "require") return;
210
+ }
211
+ const text = path.node.value;
212
+ if (shouldExtract?.(text) && generateKey) {
213
+ const key = generateKey(text, existingKeys);
214
+ existingKeys.add(key);
215
+ if (path.node.start != null && path.node.end != null) {
216
+ const ref = isDestructured ? key : `${varName}.${key}`;
217
+ replacements.push({
218
+ start: offset + path.node.start,
219
+ end: offset + path.node.end,
220
+ replacement: ref,
221
+ key,
222
+ value: text.trim()
223
+ });
224
+ }
225
+ }
226
+ } });
227
+ } catch (e) {
228
+ console.warn(`Vue extraction: Failed to parse script content for ${filename}`, e);
229
+ }
230
+ }
231
+ if (replacements.length === 0) return null;
232
+ replacements.sort((a, b) => b.start - a.start);
233
+ for (const { start, end, replacement, key, value } of replacements) {
234
+ magic.overwrite(start, end, replacement);
235
+ extractedContent[key] = value;
236
+ }
237
+ if (existingCallInfo?.isDestructured && existingCallInfo.closingBraceAbsolutePos >= 0) {
238
+ const missingKeys = Object.keys(extractedContent).filter((k) => !existingCallInfo.existingDestructuredKeys.includes(k));
239
+ if (missingKeys.length > 0) magic.appendLeft(existingCallInfo.lastPropAbsoluteEnd, `, ${missingKeys.join(", ")}`);
240
+ }
241
+ const finalScriptContent = scriptBlock?.content ?? "";
242
+ const hasUseIntlayerImport = /import\s*{[^}]*useIntlayer[^}]*}\s*from\s*['"][^'"]+['"]/.test(finalScriptContent) || /import\s+useIntlayer\s+from\s*['"][^'"]+['"]/.test(finalScriptContent);
243
+ const hasContentDeclaration = existingCallInfo !== null || /const\s+content\s*=\s*useIntlayer\s*\(/.test(finalScriptContent);
244
+ const importStmt = hasUseIntlayerImport ? "" : `import { useIntlayer } from '${packageName}';`;
245
+ const contentDecl = hasContentDeclaration ? "" : `const content = useIntlayer('${dictionaryKey}');`;
246
+ const injectionParts = [importStmt, contentDecl].filter(Boolean);
247
+ if (injectionParts.length > 0) {
248
+ const injection = `\n${injectionParts.join("\n")}\n`;
249
+ if (sfc.descriptor.scriptSetup) magic.appendLeft(sfc.descriptor.scriptSetup.loc.start.offset, injection);
250
+ else if (sfc.descriptor.script) magic.appendLeft(sfc.descriptor.script.loc.start.offset, injection);
251
+ else magic.prepend(`<script setup>\n${importStmt}\n${contentDecl}\n<\/script>\n`);
252
+ }
253
+ if (onExtract) onExtract({
254
+ dictionaryKey,
255
+ filePath: filename,
256
+ content: { ...extractedContent },
257
+ locale: defaultLocale
258
+ });
259
+ return {
260
+ code: magic.toString(),
261
+ map: magic.generateMap({
262
+ source: filename,
263
+ includeContent: true
264
+ }),
265
+ extracted: true
266
+ };
267
+ };
268
+ const processVueFile = (filePath, _componentKey, packageName, tools, save = true) => {
269
+ const code = (0, node_fs.readFileSync)(filePath, "utf-8");
270
+ let extractedContent = {};
271
+ const result = intlayerVueExtract(code, filePath, {
272
+ packageName,
273
+ dictionaryKey: _componentKey,
274
+ shouldExtract: tools.shouldExtract,
275
+ generateKey: tools.generateKey,
276
+ extractDictionaryKeyFromPath: tools.extractDictionaryKeyFromPath,
277
+ attributesToExtract: tools.attributesToExtract,
278
+ onExtract: (extractResult) => {
279
+ extractedContent = extractResult.content;
280
+ }
281
+ });
282
+ if (!result) return null;
283
+ if (save) (0, node_fs.writeFileSync)(filePath, result.code);
284
+ return {
285
+ extractedContent,
286
+ code: result.code,
287
+ map: result.map
288
+ };
289
+ };
290
+
291
+ //#endregion
292
+ exports.intlayerVueExtract = intlayerVueExtract;
293
+ exports.processVueFile = processVueFile;
294
+ exports.shouldProcessFile = shouldProcessFile;
295
+ //# sourceMappingURL=vue-intlayer-extract.cjs.map
@@ -0,0 +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): {\n extractedContent: Record<string, string>;\n code: string;\n map?: any;\n} | null => {\n const code = 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,MAAO;KAC5D,qBAAqB,iBAAiB,SAAS;KAChD;SAOD,QAAO;IACL,gBAAgB;IAChB,cANAA,kBAAE,qBAAqB,OAAO,IAAIA,kBAAE,aAAa,OAAO,GAAG,GACvD,OAAO,GAAG,OACV;IAKJ,0BAA0B,EAAE;IAC5B,yBAAyB;IACzB,qBAAqB;IACtB;AAGH,QAAK,MAAM;KAEd,CAAC;SACI;AAIR,QAAO;;AAgCT,MAAa,qBACX,UACA,cACY;AACZ,KAAI,CAAC,SA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BAAmB,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,SAKN;CACV,MAAM,iCAAoB,UAAU,QAAQ;CAC5C,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 +1,3 @@
1
- import{intlayerVueExtract as e,processVueFile as t,shouldProcessFile as n}from"./vue-intlayer-extract.mjs";export{e as intlayerVueExtract,t as processVueFile,n as shouldProcessFile};
1
+ import { intlayerVueExtract, processVueFile, shouldProcessFile } from "./vue-intlayer-extract.mjs";
2
+
3
+ export { intlayerVueExtract, processVueFile, shouldProcessFile };
@@ -1,3 +1,289 @@
1
- import{readFileSync as e,writeFileSync as t}from"node:fs";import{parse as n,traverse as r,types as i}from"@babel/core";import{DEFAULT_LOCALE as a}from"@intlayer/config/defaultValues";import o from"@vue/compiler-sfc";import s from"magic-string";const c=(e,t)=>{let a=null;try{let o=n(e,{parserOpts:{sourceType:`module`,plugins:[`typescript`,`jsx`]}});if(!o)return null;r(o,{CallExpression(e){let n=e.node.callee;if(!i.isIdentifier(n)||n.name!==`useIntlayer`&&n.name!==`getIntlayer`)return;let r=e.parent;if(i.isVariableDeclarator(r)&&i.isObjectPattern(r.id)){let e=r.id.properties,n=e.filter(e=>i.isObjectProperty(e)&&i.isIdentifier(e.key)).map(e=>e.key.name),o=e[e.length-1];a={isDestructured:!0,variableName:`content`,existingDestructuredKeys:n,closingBraceAbsolutePos:t+(r.id.end-1),lastPropAbsoluteEnd:t+o.end}}else a={isDestructured:!1,variableName:i.isVariableDeclarator(r)&&i.isIdentifier(r.id)?r.id.name:`content`,existingDestructuredKeys:[],closingBraceAbsolutePos:-1,lastPropAbsoluteEnd:-1};e.stop()}})}catch{}return a},l=(e,t)=>{if(!e)return!1;if(!t||t.length===0)return!0;let n=e.replace(/\\/g,`/`);return t.some(e=>e.replace(/\\/g,`/`)===n)},u={TEXT:2,ELEMENT:1,ATTRIBUTE:6,INTERPOLATION:5},d=(e,t,d={})=>{let{defaultLocale:f=a,packageName:p=`vue-intlayer`,filesList:m,shouldExtract:h,onExtract:g,dictionaryKey:_,attributesToExtract:v=[],extractDictionaryKeyFromPath:y,generateKey:b}=d;if(!l(t,m)||!t.endsWith(`.vue`))return null;let x;try{x=o.parse}catch{return console.warn(`Vue extraction: @vue/compiler-sfc not found.`),null}let S=x(e),C=new s(e),w={},T=new Set,E=_??y?.(t)??``,D=[],O=S.descriptor.scriptSetup??S.descriptor.script,k=O?c(O.content,O.loc.start.offset):null,A=k?.isDestructured??!1,j=k?.variableName??`content`;if(S.descriptor.template){let t=n=>{if(n.type===u.TEXT){let e=n.content??``;if(h?.(e)&&b){let t=b(e,T);T.add(t);let r=A?t:`${j}.${t}`;D.push({start:n.loc.start.offset,end:n.loc.end.offset,replacement:`{{ ${r} }}`,key:t,value:e.replace(/\s+/g,` `).trim()})}}else if(n.type===u.ELEMENT){let t=n.children??[];if(t.length>0&&t.some(e=>e.type===u.INTERPOLATION)){let r=[],i=!1,a=!0;for(let n of t)if(n.type===u.TEXT){let e=n.content??``;e.trim().length>0&&(i=!0),r.push({type:`text`,value:e,originalExpr:``})}else if(n.type===u.INTERPOLATION){let t=e.slice(n.loc.start.offset+2,n.loc.end.offset-2).trim(),i=t.includes(`.`)?t.split(`.`).pop().replace(/[^\w$]/g,``):t;r.push({type:`var`,value:i,originalExpr:t})}else{a=!1;break}if(a&&i&&r.some(e=>e.type===`var`)){let e=``;for(let t of r)e+=t.type===`var`?`{{${t.value}}}`:t.value;let i=e.replace(/\s+/g,` `).trim();if(h?.(i)&&b){let e=b(i,T);T.add(e);let a=`{{ ${A?e:`${j}.${e}`}({ ${[...new Set(r.filter(e=>e.type===`var`).map(e=>`${e.value}: ${e.originalExpr}`))].join(`, `)} }) }}`,o=t[0],s=t[t.length-1];D.push({start:o.loc.start.offset,end:s.loc.end.offset,replacement:a,key:e,value:i}),n.props?.forEach(e=>{if(e.type===u.ATTRIBUTE&&v.includes(e.name)&&e.value){let t=e.value.content;if(h?.(t)&&b){let n=b(t,T);T.add(n);let r=A?n:`${j}.${n}`;D.push({start:e.loc.start.offset,end:e.loc.end.offset,replacement:`:${e.name}="${r}"`,key:n,value:t.trim()})}}});return}}}n.props?.forEach(e=>{if(e.type===u.ATTRIBUTE&&v.includes(e.name)&&e.value){let t=e.value.content;if(h?.(t)&&b){let n=b(t,T);T.add(n);let r=A?n:`${j}.${n}`;D.push({start:e.loc.start.offset,end:e.loc.end.offset,replacement:`:${e.name}="${r}"`,key:n,value:t.trim()})}}})}n.children&&n.children.forEach(t)};t(S.descriptor.template.ast)}if(O){let e=O.content,a=O.loc.start.offset;try{let t=n(e,{parserOpts:{sourceType:`module`,plugins:[`typescript`,`jsx`]}});t&&r(t,{StringLiteral(e){if(e.parentPath.isImportDeclaration()||e.parentPath.isExportDeclaration()||e.parentPath.isImportSpecifier()||e.parentPath.isObjectProperty()&&e.key===`key`)return;if(e.parentPath.isCallExpression()){let t=e.parentPath.node.callee;if(i.isMemberExpression(t)&&i.isIdentifier(t.object)&&t.object.name===`console`||i.isIdentifier(t)&&(t.name===`useIntlayer`||t.name===`t`)||t.type===`Import`||i.isIdentifier(t)&&t.name===`require`)return}let t=e.node.value;if(h?.(t)&&b){let n=b(t,T);if(T.add(n),e.node.start!=null&&e.node.end!=null){let r=A?n:`${j}.${n}`;D.push({start:a+e.node.start,end:a+e.node.end,replacement:r,key:n,value:t.trim()})}}}})}catch(e){console.warn(`Vue extraction: Failed to parse script content for ${t}`,e)}}if(D.length===0)return null;D.sort((e,t)=>t.start-e.start);for(let{start:e,end:t,replacement:n,key:r,value:i}of D)C.overwrite(e,t,n),w[r]=i;if(k?.isDestructured&&k.closingBraceAbsolutePos>=0){let e=Object.keys(w).filter(e=>!k.existingDestructuredKeys.includes(e));e.length>0&&C.appendLeft(k.lastPropAbsoluteEnd,`, ${e.join(`, `)}`)}let M=O?.content??``,N=/import\s*{[^}]*useIntlayer[^}]*}\s*from\s*['"][^'"]+['"]/.test(M)||/import\s+useIntlayer\s+from\s*['"][^'"]+['"]/.test(M),P=k!==null||/const\s+content\s*=\s*useIntlayer\s*\(/.test(M),F=N?``:`import { useIntlayer } from '${p}';`,I=P?``:`const content = useIntlayer('${E}');`,L=[F,I].filter(Boolean);if(L.length>0){let e=`\n${L.join(`
2
- `)}\n`;S.descriptor.scriptSetup?C.appendLeft(S.descriptor.scriptSetup.loc.start.offset,e):S.descriptor.script?C.appendLeft(S.descriptor.script.loc.start.offset,e):C.prepend(`<script setup>\n${F}\n${I}\n<\/script>\n`)}return g&&g({dictionaryKey:E,filePath:t,content:{...w},locale:f}),{code:C.toString(),map:C.generateMap({source:t,includeContent:!0}),extracted:!0}},f=(n,r,i,a,o=!0)=>{let s=e(n,`utf-8`),c={},l=d(s,n,{packageName:i,dictionaryKey:r,shouldExtract:a.shouldExtract,generateKey:a.generateKey,extractDictionaryKeyFromPath:a.extractDictionaryKeyFromPath,attributesToExtract:a.attributesToExtract,onExtract:e=>{c=e.content}});return l?(o&&t(n,l.code),{extractedContent:c,code:l.code,map:l.map}):null};export{d as intlayerVueExtract,f as processVueFile,l as shouldProcessFile};
1
+ import { readFileSync, writeFileSync } from "node:fs";
2
+ import { parse, traverse, types } from "@babel/core";
3
+ import { DEFAULT_LOCALE } from "@intlayer/config/defaultValues";
4
+ import vueSfc from "@vue/compiler-sfc";
5
+ import MagicString from "magic-string";
6
+
7
+ //#region src/vue-intlayer-extract.ts
8
+ /**
9
+ * Detects whether the script block already contains a `useIntlayer` /
10
+ * `getIntlayer` call and, if so, whether its result is destructured.
11
+ *
12
+ * @param scriptText Raw text of the script block content.
13
+ * @param absoluteOffset Byte offset of `scriptText[0]` in the full SFC source.
14
+ */
15
+ const detectExistingIntlayerCall = (scriptText, absoluteOffset) => {
16
+ let info = null;
17
+ try {
18
+ const ast = parse(scriptText, { parserOpts: {
19
+ sourceType: "module",
20
+ plugins: ["typescript", "jsx"]
21
+ } });
22
+ if (!ast) return null;
23
+ traverse(ast, { CallExpression(path) {
24
+ const callee = path.node.callee;
25
+ if (!types.isIdentifier(callee) || callee.name !== "useIntlayer" && callee.name !== "getIntlayer") return;
26
+ const parent = path.parent;
27
+ if (types.isVariableDeclarator(parent) && types.isObjectPattern(parent.id)) {
28
+ const properties = parent.id.properties;
29
+ const existingDestructuredKeys = properties.filter((property) => types.isObjectProperty(property) && types.isIdentifier(property.key)).map((property) => property.key.name);
30
+ const lastProp = properties[properties.length - 1];
31
+ info = {
32
+ isDestructured: true,
33
+ variableName: "content",
34
+ existingDestructuredKeys,
35
+ closingBraceAbsolutePos: absoluteOffset + (parent.id.end - 1),
36
+ lastPropAbsoluteEnd: absoluteOffset + lastProp.end
37
+ };
38
+ } else info = {
39
+ isDestructured: false,
40
+ variableName: types.isVariableDeclarator(parent) && types.isIdentifier(parent.id) ? parent.id.name : "content",
41
+ existingDestructuredKeys: [],
42
+ closingBraceAbsolutePos: -1,
43
+ lastPropAbsoluteEnd: -1
44
+ };
45
+ path.stop();
46
+ } });
47
+ } catch {}
48
+ return info;
49
+ };
50
+ const shouldProcessFile = (filename, filesList) => {
51
+ if (!filename) return false;
52
+ if (!filesList || filesList.length === 0) return true;
53
+ const normalizedFilename = filename.replace(/\\/g, "/");
54
+ return filesList.some((f) => {
55
+ return f.replace(/\\/g, "/") === normalizedFilename;
56
+ });
57
+ };
58
+ const NODE_TYPES = {
59
+ TEXT: 2,
60
+ ELEMENT: 1,
61
+ ATTRIBUTE: 6,
62
+ INTERPOLATION: 5
63
+ };
64
+ const intlayerVueExtract = (code, filename, options = {}) => {
65
+ const { defaultLocale = DEFAULT_LOCALE, packageName = "vue-intlayer", filesList, shouldExtract, onExtract, dictionaryKey: dictionaryKeyOption, attributesToExtract = [], extractDictionaryKeyFromPath, generateKey } = options;
66
+ if (!shouldProcessFile(filename, filesList)) return null;
67
+ if (!filename.endsWith(".vue")) return null;
68
+ let parseVue;
69
+ try {
70
+ parseVue = vueSfc.parse;
71
+ } catch {
72
+ console.warn("Vue extraction: @vue/compiler-sfc not found.");
73
+ return null;
74
+ }
75
+ const sfc = parseVue(code);
76
+ const magic = new MagicString(code);
77
+ const extractedContent = {};
78
+ const existingKeys = /* @__PURE__ */ new Set();
79
+ const dictionaryKey = dictionaryKeyOption ?? extractDictionaryKeyFromPath?.(filename) ?? "";
80
+ const replacements = [];
81
+ const scriptBlock = sfc.descriptor.scriptSetup ?? sfc.descriptor.script;
82
+ const existingCallInfo = scriptBlock ? detectExistingIntlayerCall(scriptBlock.content, scriptBlock.loc.start.offset) : null;
83
+ const isDestructured = existingCallInfo?.isDestructured ?? false;
84
+ const varName = existingCallInfo?.variableName ?? "content";
85
+ if (sfc.descriptor.template) {
86
+ const walkVueAst = (node) => {
87
+ if (node.type === NODE_TYPES.TEXT) {
88
+ const text = node.content ?? "";
89
+ if (shouldExtract?.(text) && generateKey) {
90
+ const key = generateKey(text, existingKeys);
91
+ existingKeys.add(key);
92
+ const ref = isDestructured ? key : `${varName}.${key}`;
93
+ replacements.push({
94
+ start: node.loc.start.offset,
95
+ end: node.loc.end.offset,
96
+ replacement: `{{ ${ref} }}`,
97
+ key,
98
+ value: text.replace(/\s+/g, " ").trim()
99
+ });
100
+ }
101
+ } else if (node.type === NODE_TYPES.ELEMENT) {
102
+ const children = node.children ?? [];
103
+ if (children.length > 0 && children.some((c) => c.type === NODE_TYPES.INTERPOLATION)) {
104
+ const parts = [];
105
+ let hasSignificantText = false;
106
+ let isValid = true;
107
+ for (const child of children) if (child.type === NODE_TYPES.TEXT) {
108
+ const text = child.content ?? "";
109
+ if (text.trim().length > 0) hasSignificantText = true;
110
+ parts.push({
111
+ type: "text",
112
+ value: text,
113
+ originalExpr: ""
114
+ });
115
+ } else if (child.type === NODE_TYPES.INTERPOLATION) {
116
+ const exprCode = code.slice(child.loc.start.offset + 2, child.loc.end.offset - 2).trim();
117
+ const varName = exprCode.includes(".") ? exprCode.split(".").pop().replace(/[^\w$]/g, "") : exprCode;
118
+ parts.push({
119
+ type: "var",
120
+ value: varName,
121
+ originalExpr: exprCode
122
+ });
123
+ } else {
124
+ isValid = false;
125
+ break;
126
+ }
127
+ if (isValid && hasSignificantText && parts.some((p) => p.type === "var")) {
128
+ let combined = "";
129
+ for (const p of parts) combined += p.type === "var" ? `{{${p.value}}}` : p.value;
130
+ const cleanString = combined.replace(/\s+/g, " ").trim();
131
+ if (shouldExtract?.(cleanString) && generateKey) {
132
+ const key = generateKey(cleanString, existingKeys);
133
+ existingKeys.add(key);
134
+ const replacement = `{{ ${isDestructured ? key : `${varName}.${key}`}({ ${[...new Set(parts.filter((p) => p.type === "var").map((p) => `${p.value}: ${p.originalExpr}`))].join(", ")} }) }}`;
135
+ const firstChild = children[0];
136
+ const lastChild = children[children.length - 1];
137
+ replacements.push({
138
+ start: firstChild.loc.start.offset,
139
+ end: lastChild.loc.end.offset,
140
+ replacement,
141
+ key,
142
+ value: cleanString
143
+ });
144
+ node.props?.forEach((prop) => {
145
+ if (prop.type === NODE_TYPES.ATTRIBUTE && attributesToExtract.includes(prop.name) && prop.value) {
146
+ const text = prop.value.content;
147
+ if (shouldExtract?.(text) && generateKey) {
148
+ const propKey = generateKey(text, existingKeys);
149
+ existingKeys.add(propKey);
150
+ const propRef = isDestructured ? propKey : `${varName}.${propKey}`;
151
+ replacements.push({
152
+ start: prop.loc.start.offset,
153
+ end: prop.loc.end.offset,
154
+ replacement: `:${prop.name}="${propRef}"`,
155
+ key: propKey,
156
+ value: text.trim()
157
+ });
158
+ }
159
+ }
160
+ });
161
+ return;
162
+ }
163
+ }
164
+ }
165
+ node.props?.forEach((prop) => {
166
+ if (prop.type === NODE_TYPES.ATTRIBUTE && attributesToExtract.includes(prop.name) && prop.value) {
167
+ const text = prop.value.content;
168
+ if (shouldExtract?.(text) && generateKey) {
169
+ const key = generateKey(text, existingKeys);
170
+ existingKeys.add(key);
171
+ const ref = isDestructured ? key : `${varName}.${key}`;
172
+ replacements.push({
173
+ start: prop.loc.start.offset,
174
+ end: prop.loc.end.offset,
175
+ replacement: `:${prop.name}="${ref}"`,
176
+ key,
177
+ value: text.trim()
178
+ });
179
+ }
180
+ }
181
+ });
182
+ }
183
+ if (node.children) node.children.forEach(walkVueAst);
184
+ };
185
+ walkVueAst(sfc.descriptor.template.ast);
186
+ }
187
+ if (scriptBlock) {
188
+ const scriptText = scriptBlock.content;
189
+ const offset = scriptBlock.loc.start.offset;
190
+ try {
191
+ const ast = parse(scriptText, { parserOpts: {
192
+ sourceType: "module",
193
+ plugins: ["typescript", "jsx"]
194
+ } });
195
+ if (ast) traverse(ast, { StringLiteral(path) {
196
+ if (path.parentPath.isImportDeclaration()) return;
197
+ if (path.parentPath.isExportDeclaration()) return;
198
+ if (path.parentPath.isImportSpecifier()) return;
199
+ if (path.parentPath.isObjectProperty() && path.key === "key") return;
200
+ if (path.parentPath.isCallExpression()) {
201
+ const callee = path.parentPath.node.callee;
202
+ if (types.isMemberExpression(callee) && types.isIdentifier(callee.object) && callee.object.name === "console") return;
203
+ if (types.isIdentifier(callee) && (callee.name === "useIntlayer" || callee.name === "t")) return;
204
+ if (callee.type === "Import") return;
205
+ if (types.isIdentifier(callee) && callee.name === "require") return;
206
+ }
207
+ const text = path.node.value;
208
+ if (shouldExtract?.(text) && generateKey) {
209
+ const key = generateKey(text, existingKeys);
210
+ existingKeys.add(key);
211
+ if (path.node.start != null && path.node.end != null) {
212
+ const ref = isDestructured ? key : `${varName}.${key}`;
213
+ replacements.push({
214
+ start: offset + path.node.start,
215
+ end: offset + path.node.end,
216
+ replacement: ref,
217
+ key,
218
+ value: text.trim()
219
+ });
220
+ }
221
+ }
222
+ } });
223
+ } catch (e) {
224
+ console.warn(`Vue extraction: Failed to parse script content for ${filename}`, e);
225
+ }
226
+ }
227
+ if (replacements.length === 0) return null;
228
+ replacements.sort((a, b) => b.start - a.start);
229
+ for (const { start, end, replacement, key, value } of replacements) {
230
+ magic.overwrite(start, end, replacement);
231
+ extractedContent[key] = value;
232
+ }
233
+ if (existingCallInfo?.isDestructured && existingCallInfo.closingBraceAbsolutePos >= 0) {
234
+ const missingKeys = Object.keys(extractedContent).filter((k) => !existingCallInfo.existingDestructuredKeys.includes(k));
235
+ if (missingKeys.length > 0) magic.appendLeft(existingCallInfo.lastPropAbsoluteEnd, `, ${missingKeys.join(", ")}`);
236
+ }
237
+ const finalScriptContent = scriptBlock?.content ?? "";
238
+ const hasUseIntlayerImport = /import\s*{[^}]*useIntlayer[^}]*}\s*from\s*['"][^'"]+['"]/.test(finalScriptContent) || /import\s+useIntlayer\s+from\s*['"][^'"]+['"]/.test(finalScriptContent);
239
+ const hasContentDeclaration = existingCallInfo !== null || /const\s+content\s*=\s*useIntlayer\s*\(/.test(finalScriptContent);
240
+ const importStmt = hasUseIntlayerImport ? "" : `import { useIntlayer } from '${packageName}';`;
241
+ const contentDecl = hasContentDeclaration ? "" : `const content = useIntlayer('${dictionaryKey}');`;
242
+ const injectionParts = [importStmt, contentDecl].filter(Boolean);
243
+ if (injectionParts.length > 0) {
244
+ const injection = `\n${injectionParts.join("\n")}\n`;
245
+ if (sfc.descriptor.scriptSetup) magic.appendLeft(sfc.descriptor.scriptSetup.loc.start.offset, injection);
246
+ else if (sfc.descriptor.script) magic.appendLeft(sfc.descriptor.script.loc.start.offset, injection);
247
+ else magic.prepend(`<script setup>\n${importStmt}\n${contentDecl}\n<\/script>\n`);
248
+ }
249
+ if (onExtract) onExtract({
250
+ dictionaryKey,
251
+ filePath: filename,
252
+ content: { ...extractedContent },
253
+ locale: defaultLocale
254
+ });
255
+ return {
256
+ code: magic.toString(),
257
+ map: magic.generateMap({
258
+ source: filename,
259
+ includeContent: true
260
+ }),
261
+ extracted: true
262
+ };
263
+ };
264
+ const processVueFile = (filePath, _componentKey, packageName, tools, save = true) => {
265
+ const code = readFileSync(filePath, "utf-8");
266
+ let extractedContent = {};
267
+ const result = intlayerVueExtract(code, filePath, {
268
+ packageName,
269
+ dictionaryKey: _componentKey,
270
+ shouldExtract: tools.shouldExtract,
271
+ generateKey: tools.generateKey,
272
+ extractDictionaryKeyFromPath: tools.extractDictionaryKeyFromPath,
273
+ attributesToExtract: tools.attributesToExtract,
274
+ onExtract: (extractResult) => {
275
+ extractedContent = extractResult.content;
276
+ }
277
+ });
278
+ if (!result) return null;
279
+ if (save) writeFileSync(filePath, result.code);
280
+ return {
281
+ extractedContent,
282
+ code: result.code,
283
+ map: result.map
284
+ };
285
+ };
286
+
287
+ //#endregion
288
+ export { intlayerVueExtract, processVueFile, shouldProcessFile };
3
289
  //# sourceMappingURL=vue-intlayer-extract.mjs.map
@@ -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): {\n extractedContent: Record<string, string>;\n code: string;\n map?: any;\n} | null => {\n const code = 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":"oPAyBA,MAAM,GACJ,EACA,IACqB,CACrB,IAAI,EAAyB,KAE7B,GAAI,CACF,IAAM,EAAMA,EAAW,EAAY,CACjC,WAAY,CAAE,WAAY,SAAU,QAAS,CAAC,aAAc,MAAM,CAAE,CACrE,CAAC,CAEF,GAAI,CAAC,EAAK,OAAO,KAEjB,EAAS,EAAK,CACZ,eAAe,EAAW,CACxB,IAAM,EAAS,EAAK,KAAK,OAEzB,GACE,CAACC,EAAE,aAAa,EAAO,EACtB,EAAO,OAAS,eAAiB,EAAO,OAAS,cAElD,OAEF,IAAM,EAAS,EAAK,OAEpB,GAAIA,EAAE,qBAAqB,EAAO,EAAIA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AK,EAAe,KAAK;EAAK,CAAC,IAE7C,EAAI,WAAW,YACjB,EAAM,WAAW,EAAI,WAAW,YAAY,IAAI,MAAM,OAAQ,EAAU,CAC/D,EAAI,WAAW,OACxB,EAAM,WAAW,EAAI,WAAW,OAAO,IAAI,MAAM,OAAQ,EAAU,CAEnE,EAAM,QACJ,mBAAmB,EAAW,IAAI,EAAY,gBAC/C,CAaL,OATI,GACF,EAAU,CACR,gBACA,SAAU,EACV,QAAS,CAAE,GAAG,EAAkB,CAChC,OAAQ,EACT,CAAC,CAGG,CACL,KAAM,EAAM,UAAU,CACtB,IAAK,EAAM,YAAY,CAAE,OAAQ,EAAU,eAAgB,GAAM,CAAC,CAClE,UAAW,GACZ,EAWU,GACX,EACA,EACA,EACA,EACA,EAAgB,KAKN,CACV,IAAM,EAAO,EAAa,EAAU,QAAQ,CACxC,EAA2C,EAAE,CAE3C,EAAS,EAAmB,EAAM,EAAU,CAChD,cACA,cAAe,EACf,cAAe,EAAM,cACrB,YAAa,EAAM,YACnB,6BAA8B,EAAM,6BACpC,oBAAqB,EAAM,oBAC3B,UAAY,GAAkB,CAC5B,EAAmB,EAAc,SAEpC,CAAC,CAQF,OANK,GAED,GACF,EAAc,EAAU,EAAO,KAAK,CAG/B,CACL,mBACA,KAAM,EAAO,KACb,IAAK,EAAO,IACb,EAVmB"}
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): {\n extractedContent: Record<string, string>;\n code: string;\n map?: any;\n} | null => {\n const code = 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,I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,OAAO,KAAK;AAGtC,QAAO;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.4.4",
3
+ "version": "8.4.5",
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": [
@@ -81,8 +81,8 @@
81
81
  },
82
82
  "dependencies": {
83
83
  "@babel/core": "7.29.0",
84
- "@intlayer/config": "8.4.4",
85
- "@intlayer/types": "8.4.4",
84
+ "@intlayer/config": "8.4.5",
85
+ "@intlayer/types": "8.4.5",
86
86
  "@vue/compiler-sfc": ">=3.0.0",
87
87
  "fast-glob": "3.3.3",
88
88
  "magic-string": "0.30.21"
@@ -1,3 +0,0 @@
1
- var e=Object.create,t=Object.defineProperty,n=Object.getOwnPropertyDescriptor,r=Object.getOwnPropertyNames,i=Object.getPrototypeOf,a=Object.prototype.hasOwnProperty,o=(e,i,o,s)=>{if(i&&typeof i==`object`||typeof i==`function`)for(var c=r(i),l=0,u=c.length,d;l<u;l++)d=c[l],!a.call(e,d)&&d!==o&&t(e,d,{get:(e=>i[e]).bind(null,d),enumerable:!(s=n(i,d))||s.enumerable});return e},s=(n,r,a)=>(a=n==null?{}:e(i(n)),o(r||!n||!n.__esModule?t(a,`default`,{value:n,enumerable:!0}):a,n));let c=require(`node:fs`),l=require(`@babel/core`),u=require(`@intlayer/config/defaultValues`),d=require(`@vue/compiler-sfc`);d=s(d);let f=require(`magic-string`);f=s(f);const p=(e,t)=>{let n=null;try{let r=(0,l.parse)(e,{parserOpts:{sourceType:`module`,plugins:[`typescript`,`jsx`]}});if(!r)return null;(0,l.traverse)(r,{CallExpression(e){let r=e.node.callee;if(!l.types.isIdentifier(r)||r.name!==`useIntlayer`&&r.name!==`getIntlayer`)return;let i=e.parent;if(l.types.isVariableDeclarator(i)&&l.types.isObjectPattern(i.id)){let e=i.id.properties,r=e.filter(e=>l.types.isObjectProperty(e)&&l.types.isIdentifier(e.key)).map(e=>e.key.name),a=e[e.length-1];n={isDestructured:!0,variableName:`content`,existingDestructuredKeys:r,closingBraceAbsolutePos:t+(i.id.end-1),lastPropAbsoluteEnd:t+a.end}}else n={isDestructured:!1,variableName:l.types.isVariableDeclarator(i)&&l.types.isIdentifier(i.id)?i.id.name:`content`,existingDestructuredKeys:[],closingBraceAbsolutePos:-1,lastPropAbsoluteEnd:-1};e.stop()}})}catch{}return n},m=(e,t)=>{if(!e)return!1;if(!t||t.length===0)return!0;let n=e.replace(/\\/g,`/`);return t.some(e=>e.replace(/\\/g,`/`)===n)},h={TEXT:2,ELEMENT:1,ATTRIBUTE:6,INTERPOLATION:5},g=(e,t,n={})=>{let{defaultLocale:r=u.DEFAULT_LOCALE,packageName:i=`vue-intlayer`,filesList:a,shouldExtract:o,onExtract:s,dictionaryKey:c,attributesToExtract:g=[],extractDictionaryKeyFromPath:_,generateKey:v}=n;if(!m(t,a)||!t.endsWith(`.vue`))return null;let y;try{y=d.default.parse}catch{return console.warn(`Vue extraction: @vue/compiler-sfc not found.`),null}let b=y(e),x=new f.default(e),S={},C=new Set,w=c??_?.(t)??``,T=[],E=b.descriptor.scriptSetup??b.descriptor.script,D=E?p(E.content,E.loc.start.offset):null,O=D?.isDestructured??!1,k=D?.variableName??`content`;if(b.descriptor.template){let t=n=>{if(n.type===h.TEXT){let e=n.content??``;if(o?.(e)&&v){let t=v(e,C);C.add(t);let r=O?t:`${k}.${t}`;T.push({start:n.loc.start.offset,end:n.loc.end.offset,replacement:`{{ ${r} }}`,key:t,value:e.replace(/\s+/g,` `).trim()})}}else if(n.type===h.ELEMENT){let t=n.children??[];if(t.length>0&&t.some(e=>e.type===h.INTERPOLATION)){let r=[],i=!1,a=!0;for(let n of t)if(n.type===h.TEXT){let e=n.content??``;e.trim().length>0&&(i=!0),r.push({type:`text`,value:e,originalExpr:``})}else if(n.type===h.INTERPOLATION){let t=e.slice(n.loc.start.offset+2,n.loc.end.offset-2).trim(),i=t.includes(`.`)?t.split(`.`).pop().replace(/[^\w$]/g,``):t;r.push({type:`var`,value:i,originalExpr:t})}else{a=!1;break}if(a&&i&&r.some(e=>e.type===`var`)){let e=``;for(let t of r)e+=t.type===`var`?`{{${t.value}}}`:t.value;let i=e.replace(/\s+/g,` `).trim();if(o?.(i)&&v){let e=v(i,C);C.add(e);let a=`{{ ${O?e:`${k}.${e}`}({ ${[...new Set(r.filter(e=>e.type===`var`).map(e=>`${e.value}: ${e.originalExpr}`))].join(`, `)} }) }}`,s=t[0],c=t[t.length-1];T.push({start:s.loc.start.offset,end:c.loc.end.offset,replacement:a,key:e,value:i}),n.props?.forEach(e=>{if(e.type===h.ATTRIBUTE&&g.includes(e.name)&&e.value){let t=e.value.content;if(o?.(t)&&v){let n=v(t,C);C.add(n);let r=O?n:`${k}.${n}`;T.push({start:e.loc.start.offset,end:e.loc.end.offset,replacement:`:${e.name}="${r}"`,key:n,value:t.trim()})}}});return}}}n.props?.forEach(e=>{if(e.type===h.ATTRIBUTE&&g.includes(e.name)&&e.value){let t=e.value.content;if(o?.(t)&&v){let n=v(t,C);C.add(n);let r=O?n:`${k}.${n}`;T.push({start:e.loc.start.offset,end:e.loc.end.offset,replacement:`:${e.name}="${r}"`,key:n,value:t.trim()})}}})}n.children&&n.children.forEach(t)};t(b.descriptor.template.ast)}if(E){let e=E.content,n=E.loc.start.offset;try{let t=(0,l.parse)(e,{parserOpts:{sourceType:`module`,plugins:[`typescript`,`jsx`]}});t&&(0,l.traverse)(t,{StringLiteral(e){if(e.parentPath.isImportDeclaration()||e.parentPath.isExportDeclaration()||e.parentPath.isImportSpecifier()||e.parentPath.isObjectProperty()&&e.key===`key`)return;if(e.parentPath.isCallExpression()){let t=e.parentPath.node.callee;if(l.types.isMemberExpression(t)&&l.types.isIdentifier(t.object)&&t.object.name===`console`||l.types.isIdentifier(t)&&(t.name===`useIntlayer`||t.name===`t`)||t.type===`Import`||l.types.isIdentifier(t)&&t.name===`require`)return}let t=e.node.value;if(o?.(t)&&v){let r=v(t,C);if(C.add(r),e.node.start!=null&&e.node.end!=null){let i=O?r:`${k}.${r}`;T.push({start:n+e.node.start,end:n+e.node.end,replacement:i,key:r,value:t.trim()})}}}})}catch(e){console.warn(`Vue extraction: Failed to parse script content for ${t}`,e)}}if(T.length===0)return null;T.sort((e,t)=>t.start-e.start);for(let{start:e,end:t,replacement:n,key:r,value:i}of T)x.overwrite(e,t,n),S[r]=i;if(D?.isDestructured&&D.closingBraceAbsolutePos>=0){let e=Object.keys(S).filter(e=>!D.existingDestructuredKeys.includes(e));e.length>0&&x.appendLeft(D.lastPropAbsoluteEnd,`, ${e.join(`, `)}`)}let A=E?.content??``,j=/import\s*{[^}]*useIntlayer[^}]*}\s*from\s*['"][^'"]+['"]/.test(A)||/import\s+useIntlayer\s+from\s*['"][^'"]+['"]/.test(A),M=D!==null||/const\s+content\s*=\s*useIntlayer\s*\(/.test(A),N=j?``:`import { useIntlayer } from '${i}';`,P=M?``:`const content = useIntlayer('${w}');`,F=[N,P].filter(Boolean);if(F.length>0){let e=`\n${F.join(`
2
- `)}\n`;b.descriptor.scriptSetup?x.appendLeft(b.descriptor.scriptSetup.loc.start.offset,e):b.descriptor.script?x.appendLeft(b.descriptor.script.loc.start.offset,e):x.prepend(`<script setup>\n${N}\n${P}\n<\/script>\n`)}return s&&s({dictionaryKey:w,filePath:t,content:{...S},locale:r}),{code:x.toString(),map:x.generateMap({source:t,includeContent:!0}),extracted:!0}},_=(e,t,n,r,i=!0)=>{let a=(0,c.readFileSync)(e,`utf-8`),o={},s=g(a,e,{packageName:n,dictionaryKey:t,shouldExtract:r.shouldExtract,generateKey:r.generateKey,extractDictionaryKeyFromPath:r.extractDictionaryKeyFromPath,attributesToExtract:r.attributesToExtract,onExtract:e=>{o=e.content}});return s?(i&&(0,c.writeFileSync)(e,s.code),{extractedContent:o,code:s.code,map:s.map}):null};Object.defineProperty(exports,`n`,{enumerable:!0,get:function(){return _}}),Object.defineProperty(exports,`r`,{enumerable:!0,get:function(){return m}}),Object.defineProperty(exports,`t`,{enumerable:!0,get:function(){return g}});
3
- //# sourceMappingURL=vue-intlayer-extract-Dgb1qjP9.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"vue-intlayer-extract-Dgb1qjP9.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): {\n extractedContent: Record<string, string>;\n code: string;\n map?: any;\n} | null => {\n const code = 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":"uoBAyBA,MAAM,GACJ,EACA,IACqB,CACrB,IAAI,EAAyB,KAE7B,GAAI,CACF,IAAM,GAAA,EAAA,EAAA,OAAiB,EAAY,CACjC,WAAY,CAAE,WAAY,SAAU,QAAS,CAAC,aAAc,MAAM,CAAE,CACrE,CAAC,CAEF,GAAI,CAAC,EAAK,OAAO,MAEjB,EAAA,EAAA,UAAS,EAAK,CACZ,eAAe,EAAW,CACxB,IAAM,EAAS,EAAK,KAAK,OAEzB,GACE,CAACA,EAAAA,MAAE,aAAa,EAAO,EACtB,EAAO,OAAS,eAAiB,EAAO,OAAS,cAElD,OAEF,IAAM,EAAS,EAAK,OAEpB,GAAIA,EAAAA,MAAE,qBAAqB,EAAO,EAAIA,EAAAA,MAAE,gBAAgB,EAAO,GAAG,CAAE,CAClE,IAAM,EAAa,EAAO,GAAG,WACvB,EAA2B,EAC9B,OACE,GACCA,EAAAA,MAAE,iBAAiB,EAAS,EAAIA,EAAAA,MAAE,aAAa,EAAS,IAAI,CAC/D,CACA,IAAK,GAAmB,EAAS,IAAY,KAAe,CACzD,EAAW,EAAW,EAAW,OAAS,GAEhD,EAAO,CACL,eAAgB,GAChB,aAAc,UACd,2BACA,wBAAyB,GAAkB,EAAO,GAAG,IAAO,GAC5D,oBAAqB,EAAiB,EAAS,IAChD,MAOD,EAAO,CACL,eAAgB,GAChB,aANAA,EAAAA,MAAE,qBAAqB,EAAO,EAAIA,EAAAA,MAAE,aAAa,EAAO,GAAG,CACvD,EAAO,GAAG,KACV,UAKJ,yBAA0B,EAAE,CAC5B,wBAAyB,GACzB,oBAAqB,GACtB,CAGH,EAAK,MAAM,EAEd,CAAC,MACI,EAIR,OAA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