@generaltranslation/compiler 1.3.38-iris.0 → 1.3.38
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.
|
@@ -33,7 +33,6 @@ function containsStatic(source) {
|
|
|
33
33
|
return handleChildren(source);
|
|
34
34
|
}
|
|
35
35
|
function handleChildren(source) {
|
|
36
|
-
if (source === null || typeof source === "boolean") return false;
|
|
37
36
|
if (Array.isArray(source)) return source.some((child) => handleChild(child));
|
|
38
37
|
return handleChild(source);
|
|
39
38
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"calculateHash.js","names":[],"sources":["../../src/utils/calculateHash.ts"],"sourcesContent":["import type {\n DataFormat,\n JsxChild,\n JsxChildren,\n JsxElement,\n Variable,\n VariableType,\n} from '@generaltranslation/format/types';\nimport { hashSource as _hashSource } from 'generaltranslation/id';\n\n/**\n * Given jsx children, calculate hash\n */\nexport default function hashSource({\n source,\n context,\n maxChars,\n requiresReview,\n dataFormat,\n}: {\n source: JsxChildren | string;\n context?: string;\n maxChars?: number;\n requiresReview?: boolean;\n dataFormat: DataFormat;\n}): string {\n // Delegate to the shared hasher without custom ids; ids are metadata only.\n if (dataFormat === 'ICU' || dataFormat === 'I18NEXT') {\n return _hashSource({\n source,\n context,\n maxChars,\n requiresReview,\n dataFormat,\n });\n }\n // For Jsx, we set hash to empty string if it contains a static component\n if (containsStatic(source)) {\n return '';\n }\n return _hashSource({ source, context, maxChars, requiresReview, dataFormat });\n}\n\n/* =============================================== */\n/* =============== HELPER FUNCTIONS ============== */\n/* =============================================== */\n\n/**\n * Check if the given source contains a static component\n * @param source\n */\nfunction containsStatic(source: JsxChildren): boolean {\n return handleChildren(source);\n}\n\nfunction handleChildren(source: JsxChildren): boolean {\n if (
|
|
1
|
+
{"version":3,"file":"calculateHash.js","names":[],"sources":["../../src/utils/calculateHash.ts"],"sourcesContent":["import type {\n DataFormat,\n JsxChild,\n JsxChildren,\n JsxElement,\n Variable,\n VariableType,\n} from '@generaltranslation/format/types';\nimport { hashSource as _hashSource } from 'generaltranslation/id';\n\n/**\n * Given jsx children, calculate hash\n */\nexport default function hashSource({\n source,\n context,\n maxChars,\n requiresReview,\n dataFormat,\n}: {\n source: JsxChildren | string;\n context?: string;\n maxChars?: number;\n requiresReview?: boolean;\n dataFormat: DataFormat;\n}): string {\n // Delegate to the shared hasher without custom ids; ids are metadata only.\n if (dataFormat === 'ICU' || dataFormat === 'I18NEXT') {\n return _hashSource({\n source,\n context,\n maxChars,\n requiresReview,\n dataFormat,\n });\n }\n // For Jsx, we set hash to empty string if it contains a static component\n if (containsStatic(source)) {\n return '';\n }\n return _hashSource({ source, context, maxChars, requiresReview, dataFormat });\n}\n\n/* =============================================== */\n/* =============== HELPER FUNCTIONS ============== */\n/* =============================================== */\n\n/**\n * Check if the given source contains a static component\n * @param source\n */\nfunction containsStatic(source: JsxChildren): boolean {\n return handleChildren(source);\n}\n\nfunction handleChildren(source: JsxChildren): boolean {\n if (Array.isArray(source)) {\n return source.some((child) => handleChild(child));\n }\n return handleChild(source);\n}\n\nfunction handleChild(child: JsxChild): boolean {\n if (typeof child === 'string') {\n return false;\n }\n if (isVariable(child)) {\n return handleVariable(child);\n }\n return handleElement(child);\n}\n\nfunction handleVariable(variable: Variable): boolean {\n if (variable.v === ('s' as VariableType)) {\n return true;\n }\n return false;\n}\n\nfunction handleElement(element: JsxElement): boolean {\n // branches\n if (\n element.d &&\n element.d.t &&\n ['p', 'b'].includes(element.d.t) &&\n element.d.b\n ) {\n return Object.values(element.d.b).some((branch) => handleChildren(branch));\n }\n // children\n if (element.c) {\n return handleChildren(element.c);\n }\n return false;\n}\n\nfunction isVariable(obj: unknown): obj is Variable {\n const variableObj = obj as Variable;\n if (\n variableObj &&\n typeof variableObj === 'object' &&\n typeof (variableObj as Variable).k === 'string'\n ) {\n const k = Object.keys(variableObj);\n if (k.length === 1) return true;\n if (k.length === 2) {\n if (typeof variableObj.i === 'number') return true;\n if (typeof variableObj.v === 'string') return true;\n }\n if (k.length === 3) {\n if (\n typeof variableObj.v === 'string' &&\n typeof variableObj.i === 'number'\n )\n return true;\n }\n }\n return false;\n}\n"],"mappings":";;;;;;;;;;AAaA,SAAwB,WAAW,EACjC,QACA,SACA,UACA,gBACA,cAOS;AAET,KAAI,eAAe,SAAS,eAAe,UACzC,SAAA,GAAA,sBAAA,YAAmB;EACjB;EACA;EACA;EACA;EACA;EACD,CAAC;AAGJ,KAAI,eAAe,OAAO,CACxB,QAAO;AAET,SAAA,GAAA,sBAAA,YAAmB;EAAE;EAAQ;EAAS;EAAU;EAAgB;EAAY,CAAC;;;;;;AAW/E,SAAS,eAAe,QAA8B;AACpD,QAAO,eAAe,OAAO;;AAG/B,SAAS,eAAe,QAA8B;AACpD,KAAI,MAAM,QAAQ,OAAO,CACvB,QAAO,OAAO,MAAM,UAAU,YAAY,MAAM,CAAC;AAEnD,QAAO,YAAY,OAAO;;AAG5B,SAAS,YAAY,OAA0B;AAC7C,KAAI,OAAO,UAAU,SACnB,QAAO;AAET,KAAI,WAAW,MAAM,CACnB,QAAO,eAAe,MAAM;AAE9B,QAAO,cAAc,MAAM;;AAG7B,SAAS,eAAe,UAA6B;AACnD,KAAI,SAAS,MAAO,IAClB,QAAO;AAET,QAAO;;AAGT,SAAS,cAAc,SAA8B;AAEnD,KACE,QAAQ,KACR,QAAQ,EAAE,KACV,CAAC,KAAK,IAAI,CAAC,SAAS,QAAQ,EAAE,EAAE,IAChC,QAAQ,EAAE,EAEV,QAAO,OAAO,OAAO,QAAQ,EAAE,EAAE,CAAC,MAAM,WAAW,eAAe,OAAO,CAAC;AAG5E,KAAI,QAAQ,EACV,QAAO,eAAe,QAAQ,EAAE;AAElC,QAAO;;AAGT,SAAS,WAAW,KAA+B;CACjD,MAAM,cAAc;AACpB,KACE,eACA,OAAO,gBAAgB,YACvB,OAAQ,YAAyB,MAAM,UACvC;EACA,MAAM,IAAI,OAAO,KAAK,YAAY;AAClC,MAAI,EAAE,WAAW,EAAG,QAAO;AAC3B,MAAI,EAAE,WAAW,GAAG;AAClB,OAAI,OAAO,YAAY,MAAM,SAAU,QAAO;AAC9C,OAAI,OAAO,YAAY,MAAM,SAAU,QAAO;;AAEhD,MAAI,EAAE,WAAW;OAEb,OAAO,YAAY,MAAM,YACzB,OAAO,YAAY,MAAM,SAEzB,QAAO;;;AAGb,QAAO"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@generaltranslation/compiler",
|
|
3
|
-
"version": "1.3.38
|
|
3
|
+
"version": "1.3.38",
|
|
4
4
|
"description": "Universal plugin for compile-time optimization of GT translation components",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -26,8 +26,8 @@
|
|
|
26
26
|
"@babel/traverse": "^7.23.0",
|
|
27
27
|
"@babel/types": "^7.23.0",
|
|
28
28
|
"unplugin": "^2.3.10",
|
|
29
|
-
"@generaltranslation/format": "0.1.5
|
|
30
|
-
"generaltranslation": "9.1.3
|
|
29
|
+
"@generaltranslation/format": "0.1.5",
|
|
30
|
+
"generaltranslation": "9.1.3"
|
|
31
31
|
},
|
|
32
32
|
"devDependencies": {
|
|
33
33
|
"@types/babel__core": "^7.20.0",
|