@formatjs/cli 6.16.18 → 6.16.19
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/formatjs +570 -149216
- package/bin/formatjs.map +1 -1
- package/bin/{gts_extractor-JTluP-2v.js → gts_extractor-DOSw_XT9.js} +3 -4
- package/bin/gts_extractor-DOSw_XT9.js.map +1 -0
- package/bin/hbs_extractor-l07vhPE4.js.map +1 -1
- package/bin/{svelte_extractor-Cw7uYcq_.js → svelte_extractor-B8ObxDzR.js} +9 -9
- package/bin/svelte_extractor-B8ObxDzR.js.map +1 -0
- package/bin/{vue_extractor-K7d16zI4.js → vue_extractor-C21ihtmN.js} +5 -5
- package/bin/vue_extractor-C21ihtmN.js.map +1 -0
- package/package.json +7 -7
- package/bin/gts_extractor-JTluP-2v.js.map +0 -1
- package/bin/svelte_extractor-Cw7uYcq_.js.map +0 -1
- package/bin/vue_extractor-K7d16zI4.js.map +0 -1
|
@@ -2,17 +2,16 @@ import { fileURLToPath as _furl } from "node:url";
|
|
|
2
2
|
import { dirname as _dname } from "node:path";
|
|
3
3
|
const __filename = _furl(import.meta.url);
|
|
4
4
|
_dname(__filename);
|
|
5
|
-
import { t as parseScript } from "./formatjs";
|
|
6
5
|
import { parseFile as parseFile$1 } from "./hbs_extractor-l07vhPE4.js";
|
|
7
6
|
import { Preprocessor } from "content-tag";
|
|
8
7
|
//#region packages/cli-lib/gts_extractor.ts
|
|
9
8
|
let p = new Preprocessor();
|
|
10
|
-
function parseFile(source, fileName, options) {
|
|
11
|
-
|
|
9
|
+
function parseFile(source, fileName, options, parseScriptFn) {
|
|
10
|
+
parseScriptFn(p.process(source, { filename: fileName }).code);
|
|
12
11
|
const parseResult = p.parse(source, { filename: fileName });
|
|
13
12
|
for (let parsed of parseResult) parseFile$1(parsed.contents, fileName, options);
|
|
14
13
|
}
|
|
15
14
|
//#endregion
|
|
16
15
|
export { parseFile };
|
|
17
16
|
|
|
18
|
-
//# sourceMappingURL=gts_extractor-
|
|
17
|
+
//# sourceMappingURL=gts_extractor-DOSw_XT9.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"gts_extractor-DOSw_XT9.js","names":[],"sources":["../gts_extractor.ts"],"sourcesContent":["import {Preprocessor} from 'content-tag'\nimport {parseFile as parseHbsFile} from '#packages/cli-lib/hbs_extractor.js'\nimport {type ScriptParseFn} from '#packages/cli-lib/svelte_extractor.js'\nlet p = new Preprocessor()\n\nexport function parseFile(\n source: string,\n fileName: string,\n options: any,\n parseScriptFn: ScriptParseFn\n): void {\n const transformedSource = p.process(source, {filename: fileName})\n\n parseScriptFn(transformedSource.code)\n\n // extract template from transformed source to then run through hbs processor\n const parseResult = p.parse(source, {filename: fileName})\n\n for (let parsed of parseResult) {\n parseHbsFile(parsed.contents, fileName, options)\n }\n}\n"],"mappings":";;;;;;;AAGA,IAAI,IAAI,IAAI,aAAa;AAEzB,SAAgB,UACd,QACA,UACA,SACA,eACM;CAGN,cAF0B,EAAE,QAAQ,QAAQ,EAAC,UAAU,SAAQ,CAEjC,CAAC,CAAC,IAAI;CAGpC,MAAM,cAAc,EAAE,MAAM,QAAQ,EAAC,UAAU,SAAQ,CAAC;CAExD,KAAK,IAAI,UAAU,aACjB,YAAa,OAAO,UAAU,UAAU,OAAO;AAEnD"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hbs_extractor-l07vhPE4.js","names":[],"sources":["../hbs_extractor.ts"],"sourcesContent":["import {type
|
|
1
|
+
{"version":3,"file":"hbs_extractor-l07vhPE4.js","names":[],"sources":["../hbs_extractor.ts"],"sourcesContent":["import {type ExtractTransformOptions} from '#packages/cli-lib/types.js'\nimport {preprocess, traverse, type AST, type ASTv1} from '@glimmer/syntax'\n\nfunction extractText(\n node: AST.MustacheStatement | AST.SubExpression,\n fileName: string,\n options: ExtractTransformOptions\n) {\n if (!options.onMsgExtracted) return\n if (!options.overrideIdFn) return\n\n if (node.path.type !== 'PathExpression') return\n\n if (['format-message', 'formatMessage'].includes(node.path.original)) {\n let [first, second] = node.params\n\n if (first.type !== 'StringLiteral') return\n\n let message = first?.value\n\n let desc: string | undefined\n if (second?.type === 'StringLiteral') {\n desc = second.value?.trim().replace(/\\s+/gm, ' ')\n }\n\n let defaultMessage = message?.trim().replace(/\\s+/gm, ' ')\n\n let id =\n typeof options.overrideIdFn === 'string'\n ? options.overrideIdFn\n : options.overrideIdFn(undefined, defaultMessage, desc, fileName)\n\n options.onMsgExtracted(fileName, [\n {\n id: id,\n defaultMessage: defaultMessage,\n description: desc,\n },\n ])\n }\n}\n\nexport function parseFile(\n source: string,\n fileName: string,\n options: any\n): void {\n const ast = preprocess(source)\n traverse(ast, {\n MustacheStatement(node: ASTv1.MustacheStatement) {\n extractText(node, fileName, options)\n },\n SubExpression(node: ASTv1.SubExpression) {\n extractText(node, fileName, options)\n },\n })\n}\n"],"mappings":";;;;;;AAGA,SAAS,YACP,MACA,UACA,SACA;CACA,IAAI,CAAC,QAAQ,gBAAgB;CAC7B,IAAI,CAAC,QAAQ,cAAc;CAE3B,IAAI,KAAK,KAAK,SAAS,kBAAkB;CAEzC,IAAI,CAAC,kBAAkB,eAAe,CAAC,CAAC,SAAS,KAAK,KAAK,QAAQ,GAAG;EACpE,IAAI,CAAC,OAAO,UAAU,KAAK;EAE3B,IAAI,MAAM,SAAS,iBAAiB;EAEpC,IAAI,UAAU,OAAO;EAErB,IAAI;EACJ,IAAI,QAAQ,SAAS,iBACnB,OAAO,OAAO,OAAO,KAAK,CAAC,CAAC,QAAQ,SAAS,GAAG;EAGlD,IAAI,iBAAiB,SAAS,KAAK,CAAC,CAAC,QAAQ,SAAS,GAAG;EAEzD,IAAI,KACF,OAAO,QAAQ,iBAAiB,WAC5B,QAAQ,eACR,QAAQ,aAAa,KAAA,GAAW,gBAAgB,MAAM,QAAQ;EAEpE,QAAQ,eAAe,UAAU,CAC/B;GACM;GACY;GAChB,aAAa;EACf,CACF,CAAC;CACH;AACF;AAEA,SAAgB,UACd,QACA,UACA,SACM;CACN,MAAM,MAAM,WAAW,MAAM;CAC7B,SAAS,KAAK;EACZ,kBAAkB,MAA+B;GAC/C,YAAY,MAAM,UAAU,OAAO;EACrC;EACA,cAAc,MAA2B;GACvC,YAAY,MAAM,UAAU,OAAO;EACrC;CACF,CAAC;AACH"}
|
|
@@ -20,7 +20,7 @@ function extractExpression(expression, source, parseScriptFn) {
|
|
|
20
20
|
if (!expression || expression.start == null || expression.end == null) return;
|
|
21
21
|
const content = source.slice(expression.start, expression.end);
|
|
22
22
|
try {
|
|
23
|
-
parseScriptFn(`(${content})
|
|
23
|
+
parseScriptFn(`(${content})`, expression.start, 1);
|
|
24
24
|
} catch (e) {
|
|
25
25
|
console.warn(`Failed to parse "${content}". Ignore this if content has no extractable message`, e);
|
|
26
26
|
}
|
|
@@ -49,15 +49,15 @@ function getAttributeExpression(attr, source) {
|
|
|
49
49
|
}
|
|
50
50
|
function extractMessageComponent(node, source, parseScriptFn) {
|
|
51
51
|
if (typeof node.name !== "string" || !isValidIdentifier(node.name)) return;
|
|
52
|
-
const
|
|
52
|
+
const attributes = [];
|
|
53
53
|
for (const attr of node.attributes || []) {
|
|
54
54
|
if (attr.type !== "Attribute" || typeof attr.name !== "string" || !MESSAGE_DESCRIPTOR_PROPS.has(attr.name)) continue;
|
|
55
55
|
const expression = getAttributeExpression(attr, source);
|
|
56
|
-
if (expression != null)
|
|
56
|
+
if (expression != null) attributes.push(`${attr.name}={${expression}}`);
|
|
57
57
|
}
|
|
58
|
-
if (!
|
|
58
|
+
if (!attributes.length) return;
|
|
59
59
|
try {
|
|
60
|
-
parseScriptFn(
|
|
60
|
+
parseScriptFn(`<${node.name} ${attributes.join(" ")} />`);
|
|
61
61
|
} catch (e) {
|
|
62
62
|
console.warn(`Failed to parse ${node.name} message component. Ignore this if component has no extractable message`, e);
|
|
63
63
|
}
|
|
@@ -71,7 +71,7 @@ function walkNode(node, source, parseScriptFn) {
|
|
|
71
71
|
if (node.declaration) {
|
|
72
72
|
const content = source.slice(node.declaration.start, node.declaration.end);
|
|
73
73
|
try {
|
|
74
|
-
parseScriptFn(content);
|
|
74
|
+
parseScriptFn(content, node.declaration.start);
|
|
75
75
|
} catch (e) {
|
|
76
76
|
console.warn(`Failed to parse const declaration. Ignore this if content has no extractable message`, e);
|
|
77
77
|
}
|
|
@@ -132,14 +132,14 @@ function parseFile(source, filename, parseScriptFn) {
|
|
|
132
132
|
walkFragment(ast.fragment, source, parseScriptFn);
|
|
133
133
|
if (ast.instance) {
|
|
134
134
|
const program = ast.instance.content;
|
|
135
|
-
parseScriptFn(source.slice(program.start, program.end));
|
|
135
|
+
parseScriptFn(source.slice(program.start, program.end), program.start);
|
|
136
136
|
}
|
|
137
137
|
if (ast.module) {
|
|
138
138
|
const program = ast.module.content;
|
|
139
|
-
parseScriptFn(source.slice(program.start, program.end));
|
|
139
|
+
parseScriptFn(source.slice(program.start, program.end), program.start);
|
|
140
140
|
}
|
|
141
141
|
}
|
|
142
142
|
//#endregion
|
|
143
143
|
export { parseFile };
|
|
144
144
|
|
|
145
|
-
//# sourceMappingURL=svelte_extractor-
|
|
145
|
+
//# sourceMappingURL=svelte_extractor-B8ObxDzR.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"svelte_extractor-B8ObxDzR.js","names":[],"sources":["../svelte_extractor.ts"],"sourcesContent":["import {parse} from 'svelte/compiler'\n\nexport type ScriptParseFn = (\n source: string,\n sourceOffset?: number,\n wrapperOffset?: number\n) => void\n\ninterface SvelteNode {\n type: string\n start: number\n end: number\n [key: string]: any\n}\n\nconst MESSAGE_DESCRIPTOR_PROPS = new Set([\n 'id',\n 'defaultMessage',\n 'description',\n])\n\nfunction isValidIdentifier(name: string): boolean {\n return /^[$A-Z_a-z][$\\w]*$/.test(name)\n}\n\nfunction walkFragment(\n fragment: SvelteNode | null | undefined,\n source: string,\n parseScriptFn: ScriptParseFn\n): void {\n if (!fragment || !fragment.nodes) {\n return\n }\n for (const node of fragment.nodes) {\n walkNode(node, source, parseScriptFn)\n }\n}\n\nfunction extractExpression(\n expression: SvelteNode | null | undefined,\n source: string,\n parseScriptFn: ScriptParseFn\n): void {\n if (!expression || expression.start == null || expression.end == null) {\n return\n }\n const content = source.slice(expression.start, expression.end)\n try {\n parseScriptFn(`(${content})`, expression.start, 1)\n } catch (e) {\n console.warn(\n `Failed to parse \"${content}\". Ignore this if content has no extractable message`,\n e\n )\n }\n}\n\nfunction getStringAttributeValue(value: SvelteNode): string {\n return value.data ?? value.raw ?? ''\n}\n\nfunction getAttributeExpression(\n attr: SvelteNode,\n source: string\n): string | undefined {\n if (attr.value === true || attr.value == null) {\n return undefined\n }\n\n if (!Array.isArray(attr.value)) {\n if (attr.value.type === 'ExpressionTag') {\n return source.slice(\n attr.value.expression.start,\n attr.value.expression.end\n )\n }\n return undefined\n }\n\n if (!attr.value.length) {\n return '\"\"'\n }\n\n if (attr.value.length === 1) {\n const [value] = attr.value\n if (value.type === 'ExpressionTag') {\n return source.slice(value.expression.start, value.expression.end)\n }\n return JSON.stringify(getStringAttributeValue(value))\n }\n\n let staticValue = ''\n for (const value of attr.value) {\n if (value.type === 'ExpressionTag') {\n return undefined\n }\n staticValue += getStringAttributeValue(value)\n }\n return JSON.stringify(staticValue)\n}\n\nfunction extractMessageComponent(\n node: SvelteNode,\n source: string,\n parseScriptFn: ScriptParseFn\n): void {\n if (typeof node.name !== 'string' || !isValidIdentifier(node.name)) {\n return\n }\n\n const attributes: string[] = []\n for (const attr of node.attributes || []) {\n if (\n attr.type !== 'Attribute' ||\n typeof attr.name !== 'string' ||\n !MESSAGE_DESCRIPTOR_PROPS.has(attr.name)\n ) {\n continue\n }\n\n const expression = getAttributeExpression(attr, source)\n if (expression != null) {\n attributes.push(`${attr.name}={${expression}}`)\n }\n }\n\n if (!attributes.length) {\n return\n }\n\n try {\n parseScriptFn(`<${node.name} ${attributes.join(' ')} />`)\n } catch (e) {\n console.warn(\n `Failed to parse ${node.name} message component. Ignore this if component has no extractable message`,\n e\n )\n }\n}\n\nfunction walkNode(\n node: SvelteNode,\n source: string,\n parseScriptFn: ScriptParseFn\n): void {\n switch (node.type) {\n case 'ExpressionTag':\n extractExpression(node.expression, source, parseScriptFn)\n break\n\n case 'ConstTag':\n // {@const x = expr} — the declaration contains the expression\n if (node.declaration) {\n const content = source.slice(\n node.declaration.start,\n node.declaration.end\n )\n try {\n parseScriptFn(content, node.declaration.start)\n } catch (e) {\n console.warn(\n `Failed to parse const declaration. Ignore this if content has no extractable message`,\n e\n )\n }\n }\n break\n\n case 'IfBlock':\n extractExpression(node.test, source, parseScriptFn)\n walkFragment(node.consequent, source, parseScriptFn)\n walkFragment(node.alternate, source, parseScriptFn)\n break\n\n case 'EachBlock':\n extractExpression(node.expression, source, parseScriptFn)\n if (node.key) {\n extractExpression(node.key, source, parseScriptFn)\n }\n walkFragment(node.body, source, parseScriptFn)\n walkFragment(node.fallback, source, parseScriptFn)\n break\n\n case 'AwaitBlock':\n extractExpression(node.expression, source, parseScriptFn)\n walkFragment(node.pending, source, parseScriptFn)\n walkFragment(node.then, source, parseScriptFn)\n walkFragment(node.catch, source, parseScriptFn)\n break\n\n case 'KeyBlock':\n extractExpression(node.expression, source, parseScriptFn)\n walkFragment(node.fragment, source, parseScriptFn)\n break\n\n case 'SnippetBlock':\n walkFragment(node.body, source, parseScriptFn)\n break\n\n case 'RegularElement':\n case 'Component':\n case 'SvelteComponent':\n case 'SvelteElement':\n case 'SvelteHead':\n case 'SvelteBody':\n case 'SvelteWindow':\n case 'SvelteDocument':\n case 'SlotElement':\n case 'SvelteSelf':\n case 'SvelteFragment':\n if (node.type === 'Component') {\n extractMessageComponent(node, source, parseScriptFn)\n }\n // Process attributes\n if (node.attributes) {\n for (const attr of node.attributes) {\n if (attr.type === 'Attribute') {\n if (Array.isArray(attr.value)) {\n for (const v of attr.value) {\n if (v.type === 'ExpressionTag') {\n extractExpression(v.expression, source, parseScriptFn)\n }\n }\n } else if (\n typeof attr.value === 'object' &&\n attr.value !== null &&\n attr.value.type === 'ExpressionTag'\n ) {\n extractExpression(attr.value.expression, source, parseScriptFn)\n }\n } else if (attr.type === 'SpreadAttribute') {\n extractExpression(attr.expression, source, parseScriptFn)\n } else if (attr.expression) {\n // Directive nodes (OnDirective, BindDirective, etc.)\n extractExpression(attr.expression, source, parseScriptFn)\n }\n }\n }\n // Process children\n walkFragment(node.fragment, source, parseScriptFn)\n break\n }\n}\n\nexport function parseFile(\n source: string,\n filename: string,\n parseScriptFn: ScriptParseFn\n): void {\n const ast = parse(source, {modern: true, filename})\n\n // Walk the template fragment\n walkFragment(ast.fragment as unknown as SvelteNode, source, parseScriptFn)\n\n // Process <script> block\n if (ast.instance) {\n const program = ast.instance.content as unknown as SvelteNode\n parseScriptFn(source.slice(program.start, program.end), program.start)\n }\n\n // Process <script context=\"module\"> / <script module> block\n if (ast.module) {\n const program = ast.module.content as unknown as SvelteNode\n parseScriptFn(source.slice(program.start, program.end), program.start)\n }\n}\n"],"mappings":";;;;;;AAeA,MAAM,2CAA2B,IAAI,IAAI;CACvC;CACA;CACA;AACF,CAAC;AAED,SAAS,kBAAkB,MAAuB;CAChD,OAAO,qBAAqB,KAAK,IAAI;AACvC;AAEA,SAAS,aACP,UACA,QACA,eACM;CACN,IAAI,CAAC,YAAY,CAAC,SAAS,OACzB;CAEF,KAAK,MAAM,QAAQ,SAAS,OAC1B,SAAS,MAAM,QAAQ,aAAa;AAExC;AAEA,SAAS,kBACP,YACA,QACA,eACM;CACN,IAAI,CAAC,cAAc,WAAW,SAAS,QAAQ,WAAW,OAAO,MAC/D;CAEF,MAAM,UAAU,OAAO,MAAM,WAAW,OAAO,WAAW,GAAG;CAC7D,IAAI;EACF,cAAc,IAAI,QAAQ,IAAI,WAAW,OAAO,CAAC;CACnD,SAAS,GAAG;EACV,QAAQ,KACN,oBAAoB,QAAQ,uDAC5B,CACF;CACF;AACF;AAEA,SAAS,wBAAwB,OAA2B;CAC1D,OAAO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AC7B,IAAI,MAAM,QAAQ,KAAK,KAAK,GACrB;WAAA,MAAM,KAAK,KAAK,OACnB,IAAI,EAAE,SAAS,iBACb,kBAAkB,EAAE,YAAY,QAAQ,aAAa;KAAA,OAGpD,IACL,OAAO,KAAK,UAAU,YACtB,KAAK,UAAU,QACf,KAAK,MAAM,SAAS,iBAEpB,kBAAkB,KAAK,MAAM,YAAY,QAAQ,aAAa;IAElE,OAAO,IAAI,KAAK,SAAS,mBACvB,kBAAkB,KAAK,YAAY,QAAQ,aAAa;SACnD,IAAI,KAAK,YAEd,kBAAkB,KAAK,YAAY,QAAQ,aAAa;GAAA;GAK9D,aAAa,KAAK,UAAU,QAAQ,aAAa;CAErD;AACF;AAEA,SAAgB,UACd,QACA,UACA,eACM;CACN,MAAM,MAAM,MAAM,QAAQ;EAAC,QAAQ;EAAM;CAAQ,CAAC;CAGlD,aAAa,IAAI,UAAmC,QAAQ,aAAa;CAGzE,IAAI,IAAI,UAAU;EAChB,MAAM,UAAU,IAAI,SAAS;EAC7B,cAAc,OAAO,MAAM,QAAQ,OAAO,QAAQ,GAAG,GAAG,QAAQ,KAAK;CACvE;CAGA,IAAI,IAAI,QAAQ;EACd,MAAM,UAAU,IAAI,OAAO;EAC3B,cAAc,OAAO,MAAM,QAAQ,OAAO,QAAQ,GAAG,GAAG,QAAQ,KAAK;CACvE;AACF"}
|
|
@@ -23,9 +23,9 @@ function templateSimpleExpressionNodeVisitor(parseScriptFn) {
|
|
|
23
23
|
return (n) => {
|
|
24
24
|
if (typeof n !== "object") return;
|
|
25
25
|
if (n.type !== NodeTypes.SIMPLE_EXPRESSION) return;
|
|
26
|
-
const { content } = n;
|
|
26
|
+
const { content, loc } = n;
|
|
27
27
|
try {
|
|
28
|
-
parseScriptFn(`(${content})
|
|
28
|
+
parseScriptFn(`(${content})`, loc.start.offset, 1);
|
|
29
29
|
} catch (e) {
|
|
30
30
|
console.warn(`Failed to parse "${content}". Ignore this if content has no extractable message`, e);
|
|
31
31
|
}
|
|
@@ -36,10 +36,10 @@ function parseFile(source, filename, parseScriptFn) {
|
|
|
36
36
|
if (errors.length) throw errors[0];
|
|
37
37
|
const { script, scriptSetup, template } = descriptor;
|
|
38
38
|
if (template) walk(template.ast, templateSimpleExpressionNodeVisitor(parseScriptFn));
|
|
39
|
-
if (script) parseScriptFn(script.content);
|
|
40
|
-
if (scriptSetup) parseScriptFn(scriptSetup.content);
|
|
39
|
+
if (script) parseScriptFn(script.content, script.loc.start.offset);
|
|
40
|
+
if (scriptSetup) parseScriptFn(scriptSetup.content, scriptSetup.loc.start.offset);
|
|
41
41
|
}
|
|
42
42
|
//#endregion
|
|
43
43
|
export { parseFile };
|
|
44
44
|
|
|
45
|
-
//# sourceMappingURL=vue_extractor-
|
|
45
|
+
//# sourceMappingURL=vue_extractor-C21ihtmN.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"vue_extractor-C21ihtmN.js","names":[],"sources":["../vue_extractor.ts"],"sourcesContent":["import {\n NodeTypes,\n type TextNode,\n type CompoundExpressionNode,\n type DirectiveNode,\n type ElementNode,\n type InterpolationNode,\n type RootNode,\n type SimpleExpressionNode,\n type TemplateChildNode,\n} from '@vue/compiler-core'\nimport {parse} from 'vue/compiler-sfc'\n\nexport type ScriptParseFn = (\n source: string,\n sourceOffset?: number,\n wrapperOffset?: number\n) => void\n\nfunction walk(\n node:\n | RootNode\n | TemplateChildNode\n | SimpleExpressionNode\n | CompoundExpressionNode\n | InterpolationNode\n | TextNode\n | string\n | symbol\n | undefined,\n visitor: (\n node:\n | ElementNode\n | InterpolationNode\n | CompoundExpressionNode\n | SimpleExpressionNode\n ) => void\n) {\n if (typeof node !== 'object' || node == null) {\n return\n }\n if (node.type === NodeTypes.ROOT) {\n node.children.forEach(n => walk(n, visitor))\n return\n }\n if (\n node.type !== NodeTypes.ELEMENT &&\n node.type !== NodeTypes.COMPOUND_EXPRESSION &&\n node.type !== NodeTypes.INTERPOLATION\n ) {\n return\n }\n visitor(node)\n if (node.type === NodeTypes.INTERPOLATION) {\n visitor(node.content)\n } else if (node.type === NodeTypes.ELEMENT) {\n node.children.forEach(n => walk(n, visitor))\n node.props\n .filter(\n (prop): prop is DirectiveNode => prop.type === NodeTypes.DIRECTIVE\n )\n .filter(prop => !!prop.exp)\n .forEach(prop => visitor(prop.exp!))\n } else {\n node.children.forEach(n => walk(n, visitor))\n }\n}\n\nfunction templateSimpleExpressionNodeVisitor(parseScriptFn: ScriptParseFn) {\n return (\n n:\n | ElementNode\n | CompoundExpressionNode\n | CompoundExpressionNode['children'][0]\n ) => {\n if (typeof n !== 'object') {\n return\n }\n if (n.type !== NodeTypes.SIMPLE_EXPRESSION) {\n return\n }\n\n const {content, loc} = n as SimpleExpressionNode\n // Wrap this in () since a vue comp node attribute can just be\n // an object literal which, by itself is invalid TS\n // but with () it becomes an ExpressionStatement\n try {\n parseScriptFn(`(${content})`, loc.start.offset, 1)\n } catch (e) {\n console.warn(\n `Failed to parse \"${content}\". Ignore this if content has no extractable message`,\n e\n )\n }\n }\n}\n\nexport function parseFile(\n source: string,\n filename: string,\n parseScriptFn: ScriptParseFn\n): void {\n const {descriptor, errors} = parse(source, {\n filename,\n })\n if (errors.length) {\n throw errors[0]\n }\n const {script, scriptSetup, template} = descriptor\n\n if (template) {\n walk(template.ast, templateSimpleExpressionNodeVisitor(parseScriptFn))\n }\n\n if (script) {\n parseScriptFn(script.content, script.loc.start.offset)\n }\n\n if (scriptSetup) {\n parseScriptFn(scriptSetup.content, scriptSetup.loc.start.offset)\n }\n}\n"],"mappings":";;;;;;;AAmBA,SAAS,KACP,MAUA,SAOA;CACA,IAAI,OAAO,SAAS,YAAY,QAAQ,MACtC;CAEF,IAAI,KAAK,SAAS,UAAU,MAAM;EAChC,KAAK,SAAS,SAAQ,MAAK,KAAK,GAAG,OAAO,CAAC;EAC3C;CACF;CACA,IACE,KAAK,SAAS,UAAU,WACxB,KAAK,SAAS,UAAU,uBACxB,KAAK,SAAS,UAAU,eAEx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|
@@ -60,12 +60,12 @@
|
|
|
60
60
|
}
|
|
61
61
|
},
|
|
62
62
|
"optionalDependencies": {
|
|
63
|
-
"@formatjs/cli-native-darwin-arm64": "1.1.
|
|
64
|
-
"@formatjs/cli-native-linux-arm64": "1.2.
|
|
65
|
-
"@formatjs/cli-native-linux-arm64-musl": "1.0.
|
|
66
|
-
"@formatjs/cli-native-linux-x64": "1.1.
|
|
67
|
-
"@formatjs/cli-native-linux-x64-musl": "1.0.
|
|
68
|
-
"@formatjs/cli-native-win32-x64": "1.1.
|
|
63
|
+
"@formatjs/cli-native-darwin-arm64": "1.1.13",
|
|
64
|
+
"@formatjs/cli-native-linux-arm64": "1.2.13",
|
|
65
|
+
"@formatjs/cli-native-linux-arm64-musl": "1.0.11",
|
|
66
|
+
"@formatjs/cli-native-linux-x64": "1.1.13",
|
|
67
|
+
"@formatjs/cli-native-linux-x64-musl": "1.0.11",
|
|
68
|
+
"@formatjs/cli-native-win32-x64": "1.1.14"
|
|
69
69
|
},
|
|
70
70
|
"engines": {
|
|
71
71
|
"node": ">= 20.12.0"
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"gts_extractor-JTluP-2v.js","names":[],"sources":["../gts_extractor.ts"],"sourcesContent":["import {Preprocessor} from 'content-tag'\nimport {parseFile as parseHbsFile} from '#packages/cli-lib/hbs_extractor.js'\nimport {parseScript} from '#packages/cli-lib/parse_script.js'\nlet p = new Preprocessor()\n\nexport function parseFile(\n source: string,\n fileName: string,\n options: any\n): void {\n const scriptParseFn = parseScript(options, fileName)\n const transformedSource = p.process(source, {filename: fileName})\n\n scriptParseFn(transformedSource.code)\n\n // extract template from transformed source to then run through hbs processor\n const parseResult = p.parse(source, {filename: fileName})\n\n for (let parsed of parseResult) {\n parseHbsFile(parsed.contents, fileName, options)\n }\n}\n"],"mappings":";;;;;;;;AAGA,IAAI,IAAI,IAAI,aAAa;AAEzB,SAAgB,UACd,QACA,UACA,SACM;CAIN,YAHkC,SAAS,QAG/B,CAAC,CAFa,EAAE,QAAQ,QAAQ,EAAC,UAAU,SAAQ,CAEjC,CAAC,CAAC,IAAI;CAGpC,MAAM,cAAc,EAAE,MAAM,QAAQ,EAAC,UAAU,SAAQ,CAAC;CAExD,KAAK,IAAI,UAAU,aACjB,YAAa,OAAO,UAAU,UAAU,OAAO;AAEnD"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"svelte_extractor-Cw7uYcq_.js","names":[],"sources":["../svelte_extractor.ts"],"sourcesContent":["import {parse} from 'svelte/compiler'\n\nexport type ScriptParseFn = (source: string) => void\n\ninterface SvelteNode {\n type: string\n start: number\n end: number\n [key: string]: any\n}\n\nconst MESSAGE_DESCRIPTOR_PROPS = new Set([\n 'id',\n 'defaultMessage',\n 'description',\n])\n\nfunction isValidIdentifier(name: string): boolean {\n return /^[$A-Z_a-z][$\\w]*$/.test(name)\n}\n\nfunction walkFragment(\n fragment: SvelteNode | null | undefined,\n source: string,\n parseScriptFn: ScriptParseFn\n): void {\n if (!fragment || !fragment.nodes) {\n return\n }\n for (const node of fragment.nodes) {\n walkNode(node, source, parseScriptFn)\n }\n}\n\nfunction extractExpression(\n expression: SvelteNode | null | undefined,\n source: string,\n parseScriptFn: ScriptParseFn\n): void {\n if (!expression || expression.start == null || expression.end == null) {\n return\n }\n const content = source.slice(expression.start, expression.end)\n try {\n parseScriptFn(`(${content})`)\n } catch (e) {\n console.warn(\n `Failed to parse \"${content}\". Ignore this if content has no extractable message`,\n e\n )\n }\n}\n\nfunction getStringAttributeValue(value: SvelteNode): string {\n return value.data ?? value.raw ?? ''\n}\n\nfunction getAttributeExpression(\n attr: SvelteNode,\n source: string\n): string | undefined {\n if (attr.value === true || attr.value == null) {\n return undefined\n }\n\n if (!Array.isArray(attr.value)) {\n if (attr.value.type === 'ExpressionTag') {\n return source.slice(\n attr.value.expression.start,\n attr.value.expression.end\n )\n }\n return undefined\n }\n\n if (!attr.value.length) {\n return '\"\"'\n }\n\n if (attr.value.length === 1) {\n const [value] = attr.value\n if (value.type === 'ExpressionTag') {\n return source.slice(value.expression.start, value.expression.end)\n }\n return JSON.stringify(getStringAttributeValue(value))\n }\n\n let staticValue = ''\n for (const value of attr.value) {\n if (value.type === 'ExpressionTag') {\n return undefined\n }\n staticValue += getStringAttributeValue(value)\n }\n return JSON.stringify(staticValue)\n}\n\nfunction extractMessageComponent(\n node: SvelteNode,\n source: string,\n parseScriptFn: ScriptParseFn\n): void {\n if (typeof node.name !== 'string' || !isValidIdentifier(node.name)) {\n return\n }\n\n const props: string[] = []\n for (const attr of node.attributes || []) {\n if (\n attr.type !== 'Attribute' ||\n typeof attr.name !== 'string' ||\n !MESSAGE_DESCRIPTOR_PROPS.has(attr.name)\n ) {\n continue\n }\n\n const expression = getAttributeExpression(attr, source)\n if (expression != null) {\n props.push(`${attr.name}: ${expression}`)\n }\n }\n\n if (!props.length) {\n return\n }\n\n try {\n parseScriptFn(`${node.name}({${props.join(', ')}})`)\n } catch (e) {\n console.warn(\n `Failed to parse ${node.name} message component. Ignore this if component has no extractable message`,\n e\n )\n }\n}\n\nfunction walkNode(\n node: SvelteNode,\n source: string,\n parseScriptFn: ScriptParseFn\n): void {\n switch (node.type) {\n case 'ExpressionTag':\n extractExpression(node.expression, source, parseScriptFn)\n break\n\n case 'ConstTag':\n // {@const x = expr} — the declaration contains the expression\n if (node.declaration) {\n const content = source.slice(\n node.declaration.start,\n node.declaration.end\n )\n try {\n parseScriptFn(content)\n } catch (e) {\n console.warn(\n `Failed to parse const declaration. Ignore this if content has no extractable message`,\n e\n )\n }\n }\n break\n\n case 'IfBlock':\n extractExpression(node.test, source, parseScriptFn)\n walkFragment(node.consequent, source, parseScriptFn)\n walkFragment(node.alternate, source, parseScriptFn)\n break\n\n case 'EachBlock':\n extractExpression(node.expression, source, parseScriptFn)\n if (node.key) {\n extractExpression(node.key, source, parseScriptFn)\n }\n walkFragment(node.body, source, parseScriptFn)\n walkFragment(node.fallback, source, parseScriptFn)\n break\n\n case 'AwaitBlock':\n extractExpression(node.expression, source, parseScriptFn)\n walkFragment(node.pending, source, parseScriptFn)\n walkFragment(node.then, source, parseScriptFn)\n walkFragment(node.catch, source, parseScriptFn)\n break\n\n case 'KeyBlock':\n extractExpression(node.expression, source, parseScriptFn)\n walkFragment(node.fragment, source, parseScriptFn)\n break\n\n case 'SnippetBlock':\n walkFragment(node.body, source, parseScriptFn)\n break\n\n case 'RegularElement':\n case 'Component':\n case 'SvelteComponent':\n case 'SvelteElement':\n case 'SvelteHead':\n case 'SvelteBody':\n case 'SvelteWindow':\n case 'SvelteDocument':\n case 'SlotElement':\n case 'SvelteSelf':\n case 'SvelteFragment':\n if (node.type === 'Component') {\n extractMessageComponent(node, source, parseScriptFn)\n }\n // Process attributes\n if (node.attributes) {\n for (const attr of node.attributes) {\n if (attr.type === 'Attribute') {\n if (Array.isArray(attr.value)) {\n for (const v of attr.value) {\n if (v.type === 'ExpressionTag') {\n extractExpression(v.expression, source, parseScriptFn)\n }\n }\n } else if (\n typeof attr.value === 'object' &&\n attr.value !== null &&\n attr.value.type === 'ExpressionTag'\n ) {\n extractExpression(attr.value.expression, source, parseScriptFn)\n }\n } else if (attr.type === 'SpreadAttribute') {\n extractExpression(attr.expression, source, parseScriptFn)\n } else if (attr.expression) {\n // Directive nodes (OnDirective, BindDirective, etc.)\n extractExpression(attr.expression, source, parseScriptFn)\n }\n }\n }\n // Process children\n walkFragment(node.fragment, source, parseScriptFn)\n break\n }\n}\n\nexport function parseFile(\n source: string,\n filename: string,\n parseScriptFn: ScriptParseFn\n): void {\n const ast = parse(source, {modern: true, filename})\n\n // Walk the template fragment\n walkFragment(ast.fragment as unknown as SvelteNode, source, parseScriptFn)\n\n // Process <script> block\n if (ast.instance) {\n const program = ast.instance.content as unknown as SvelteNode\n parseScriptFn(source.slice(program.start, program.end))\n }\n\n // Process <script context=\"module\"> / <script module> block\n if (ast.module) {\n const program = ast.module.content as unknown as SvelteNode\n parseScriptFn(source.slice(program.start, program.end))\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OAAO,QAAQ,GAAG,CAAC;CACxD;CAGA,IAAI,IAAI,QAAQ;EACd,MAAM,UAAU,IAAI,OAAO;EAC3B,cAAc,OAAO,MAAM,QAAQ,OAAO,QAAQ,GAAG,CAAC;CACxD;AACF"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"vue_extractor-K7d16zI4.js","names":[],"sources":["../vue_extractor.ts"],"sourcesContent":["import {\n NodeTypes,\n type TextNode,\n type CompoundExpressionNode,\n type DirectiveNode,\n type ElementNode,\n type InterpolationNode,\n type RootNode,\n type SimpleExpressionNode,\n type TemplateChildNode,\n} from '@vue/compiler-core'\nimport {parse} from 'vue/compiler-sfc'\n\nexport type ScriptParseFn = (source: string) => void\n\nfunction walk(\n node:\n | RootNode\n | TemplateChildNode\n | SimpleExpressionNode\n | CompoundExpressionNode\n | InterpolationNode\n | TextNode\n | string\n | symbol\n | undefined,\n visitor: (\n node:\n | ElementNode\n | InterpolationNode\n | CompoundExpressionNode\n | SimpleExpressionNode\n ) => void\n) {\n if (typeof node !== 'object' || node == null) {\n return\n }\n if (node.type === NodeTypes.ROOT) {\n node.children.forEach(n => walk(n, visitor))\n return\n }\n if (\n node.type !== NodeTypes.ELEMENT &&\n node.type !== NodeTypes.COMPOUND_EXPRESSION &&\n node.type !== NodeTypes.INTERPOLATION\n ) {\n return\n }\n visitor(node)\n if (node.type === NodeTypes.INTERPOLATION) {\n visitor(node.content)\n } else if (node.type === NodeTypes.ELEMENT) {\n node.children.forEach(n => walk(n, visitor))\n node.props\n .filter(\n (prop): prop is DirectiveNode => prop.type === NodeTypes.DIRECTIVE\n )\n .filter(prop => !!prop.exp)\n .forEach(prop => visitor(prop.exp!))\n } else {\n node.children.forEach(n => walk(n, visitor))\n }\n}\n\nfunction templateSimpleExpressionNodeVisitor(parseScriptFn: ScriptParseFn) {\n return (\n n:\n | ElementNode\n | CompoundExpressionNode\n | CompoundExpressionNode['children'][0]\n ) => {\n if (typeof n !== 'object') {\n return\n }\n if (n.type !== NodeTypes.SIMPLE_EXPRESSION) {\n return\n }\n\n const {content} = n as SimpleExpressionNode\n // Wrap this in () since a vue comp node attribute can just be\n // an object literal which, by itself is invalid TS\n // but with () it becomes an ExpressionStatement\n try {\n parseScriptFn(`(${content})`)\n } catch (e) {\n console.warn(\n `Failed to parse \"${content}\". Ignore this if content has no extractable message`,\n e\n )\n }\n }\n}\n\nexport function parseFile(\n source: string,\n filename: string,\n parseScriptFn: ScriptParseFn\n): void {\n const {descriptor, errors} = parse(source, {\n filename,\n })\n if (errors.length) {\n throw errors[0]\n }\n const {script, scriptSetup, template} = descriptor\n\n if (template) {\n walk(template.ast, templateSimpleExpressionNodeVisitor(parseScriptFn))\n }\n\n if (script) {\n parseScriptFn(script.content)\n }\n\n if (scriptSetup) {\n parseScriptFn(scriptSetup.content)\n }\n}\n"],"mappings":";;;;;;;AAeA,SAAS,KACP,MAUA,SAOA;CACA,IAAI,OAAO,SAAS,YAAY,QAAQ,MACtC;CAEF,IAAI,KAAK,SAAS,UAAU,MAAM;EAChC,KAAK,SAAS,SAAQ,MAAK,KAAK,GAAG,OAAO,CAAC;EAC3C;CACF;CACA,IACE,KAAK,SAAS,UAAU,WACxB,KAAK,SAAS,UAAU,uBACxB,KAAK,SAAS,UAAU,eAExB;CAEF,QAAQ,IAAI;CACZ,IAAI,KAAK,SAAS,UAAU,eAC1B,QAAQ,KAAK,OAAO;MACf,IAAI,KAAK,SAAS,UAAU,SAAS;EAC1C,KAAK,SAAS,SAAQ,MAAK,KAAK,GAAG,OAAO,CAAC;EAC3C,KAAK,MACF,QACE,SAAgC,KAAK,SAAS,UAAU,SAC3D,CAAC,CACA,QAAO,SAAQ,CAAC,CAAC,KAAK,GAAG,CAAC,CAC1B,SAAQ,SAAQ,QAAQ,KAAK,GAAI,CAAC;CACvC,OACE,KAAK,SAAS,SAAQ,MAAK,KAAK,GAAG,OAAO,CAAC;AAE/C;AAEA,SAAS,oCAAoC,eAA8B;CACzE,QACE,MAIG;E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