@generaltranslation/compiler 1.3.25-odysseus.1 → 1.3.25-odysseus.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.
- package/dist/processing/collection/processCallExpression.js +0 -1
- package/dist/processing/collection/processCallExpression.js.map +1 -1
- package/dist/state/StringCollector.d.ts +3 -3
- package/dist/state/StringCollector.d.ts.map +1 -1
- package/dist/state/StringCollector.js.map +1 -1
- package/dist/transform/injection/injectCallbackDeclaratorFunctionParameters.d.ts +1 -1
- package/dist/transform/injection/injectCallbackDeclaratorFunctionParameters.js +5 -5
- package/dist/transform/injection/injectCallbackDeclaratorFunctionParameters.js.map +1 -1
- package/dist/transform/registration/callbacks/registerUseGTCallback.d.ts.map +1 -1
- package/dist/transform/registration/callbacks/registerUseGTCallback.js +0 -1
- package/dist/transform/registration/callbacks/registerUseGTCallback.js.map +1 -1
- package/dist/transform/registration/registerStandaloneTranslation.d.ts.map +1 -1
- package/dist/transform/registration/registerStandaloneTranslation.js +0 -1
- package/dist/transform/registration/registerStandaloneTranslation.js.map +1 -1
- package/dist/utils/calculateHash.d.ts +1 -2
- package/dist/utils/calculateHash.d.ts.map +1 -1
- package/dist/utils/calculateHash.js +1 -3
- package/dist/utils/calculateHash.js.map +1 -1
- package/package.json +3 -3
|
@@ -129,7 +129,6 @@ function handleReactInvocation(callExprPath, state) {
|
|
|
129
129
|
const hash = hasDeriveContext ? "" : _hash || require_utils_calculateHash.default({
|
|
130
130
|
source: children,
|
|
131
131
|
...context && { context },
|
|
132
|
-
...id && { id },
|
|
133
132
|
...maxChars != null && { maxChars },
|
|
134
133
|
dataFormat: "JSX"
|
|
135
134
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"processCallExpression.js","names":["getCalleeNameFromExpression","getTrackedVariable","isTranslationFunctionCallback","isReactFunction","validateTranslationFunction","validateUseTranslationsCallback","validateUseMessagesCallback","createErrorLocation","t","getCalleeNameFromJsxExpressionParam","isTranslationComponent","validateTranslationComponentArgs","hashSource"],"sources":["../../../src/processing/collection/processCallExpression.ts"],"sourcesContent":["import { NodePath, VisitNode } from '@babel/traverse';\nimport * as t from '@babel/types';\nimport { TransformState } from '../../state/types';\nimport {\n isTranslationComponent,\n isTranslationFunctionCallback,\n} from '../../utils/constants/gt/helpers';\nimport { getCalleeNameFromExpression } from '../../utils/parsing/getCalleeNameFromExpression';\nimport {\n GT_ALL_FUNCTIONS,\n GT_CALLBACK_FUNCTIONS,\n GT_OTHER_FUNCTIONS,\n} from '../../utils/constants/gt/constants';\nimport {\n validateTranslationFunction,\n validateUseMessagesCallback,\n validateUseTranslationsCallback,\n} from '../../transform/validation/validateTranslationFunction';\nimport { registerUseGTCallback } from '../../transform/registration/callbacks/registerUseGTCallback';\nimport { registerUseTranslationsCallback } from '../../transform/registration/callbacks/registerUseTranslationsCallback';\nimport { registerUseMessagesCallback } from '../../transform/registration/callbacks/registerUseMessagesCallback';\nimport { getTrackedVariable } from '../../transform/getTrackedVariable';\nimport { isReactFunction } from '../../utils/constants/react/helpers';\nimport { validateTranslationComponentArgs } from '../../transform/validation/validateTranslationComponentArgs';\nimport { registerTranslationComponent } from '../../transform/registration/registerTranslationComponent';\nimport { getCalleeNameFromJsxExpressionParam } from '../../transform/jsx-children/utils/getCalleeNameFromJsxExpressionParam';\nimport { createErrorLocation } from '../../utils/errors';\nimport hashSource from '../../utils/calculateHash';\nimport { registerStandaloneTranslation } from '../../transform/registration/registerStandaloneTranslation';\n\n/**\n * Process call expressions\n * - register content from GT callback functions invocations (useGT_callback, etc.)\n * - register <T> + other component content (via jsxDev, jsx, jsxs invocations)\n * - register msg() function invocations?\n * - generally validate content\n */\nexport function processCallExpression(\n state: TransformState\n): VisitNode<t.Node, t.CallExpression> {\n return (callExprPath) => {\n // Get the call expression\n const callExpr = callExprPath.node;\n\n // Get function name from callee\n const { namespaceName, functionName } =\n getCalleeNameFromExpression(callExpr);\n if (!functionName) {\n return;\n }\n\n // Get the canonical function name\n const { canonicalName, identifier, type } = getTrackedVariable(\n state.scopeTracker,\n namespaceName,\n functionName\n );\n if (!canonicalName) {\n return;\n }\n\n // Handle each respective case\n if (\n type === 'generaltranslation' &&\n isTranslationFunctionCallback(canonicalName)\n ) {\n // Handle translation function callbacks (useGT_callback, etc.)\n handleTranslationCallbackInvocation(\n callExprPath,\n state,\n canonicalName,\n identifier!\n );\n } else if (type === 'react' && isReactFunction(canonicalName)) {\n // Handle react variables (jsxDEV, etc.)\n handleReactInvocation(callExprPath, state);\n } else if (\n type === 'generaltranslation' &&\n canonicalName === GT_OTHER_FUNCTIONS.msg\n ) {\n // msg() is runtime-only content; it must not advance the injection counter.\n handleStandaloneTranslation(callExprPath, state, { injectHash: false });\n } else if (\n type === 'generaltranslation' &&\n canonicalName === GT_OTHER_FUNCTIONS.t\n ) {\n // Standalone t() receives an injected $_hash, so collection reserves a\n // matching counter slot for the injection pass.\n handleStandaloneTranslation(callExprPath, state, { injectHash: true });\n }\n };\n}\n\n/* =============================== */\n/* Handlers */\n/* =============================== */\n\n/**\n * Handle general translation variables\n * useGTCallback(), useTranslationsCallback(), useMessagesCallback(), etc.\n */\nfunction handleTranslationCallbackInvocation(\n callExprPath: NodePath<t.CallExpression>,\n state: TransformState,\n canonicalName: GT_ALL_FUNCTIONS,\n identifier: number\n) {\n // Handle translation function callbacks ()\n switch (canonicalName) {\n case GT_CALLBACK_FUNCTIONS.useGT_callback:\n case GT_CALLBACK_FUNCTIONS.getGT_callback:\n handleUseGTCallback(callExprPath, state, identifier);\n break;\n case GT_CALLBACK_FUNCTIONS.useTranslations_callback:\n case GT_CALLBACK_FUNCTIONS.getTranslations_callback:\n handleUseTranslationsCallback(callExprPath, state, identifier);\n break;\n case GT_CALLBACK_FUNCTIONS.useMessages_callback:\n case GT_CALLBACK_FUNCTIONS.getMessages_callback:\n handleUseMessagesCallback(callExprPath, state, identifier);\n break;\n default:\n return;\n }\n}\n\n/**\n * Handle useGT_callback / getGT_callback\n */\nfunction handleUseGTCallback(\n callExprPath: NodePath<t.CallExpression>,\n state: TransformState,\n identifier: number\n) {\n // Check for violations\n const useGTCallbackParams = validateTranslationFunction(callExprPath, state);\n state.errorTracker.addErrors(useGTCallbackParams.errors);\n if (\n useGTCallbackParams.errors.length > 0 ||\n useGTCallbackParams.content === undefined\n ) {\n return;\n }\n\n // Track the function call\n // When context contains derive(), skip hash calculation (CLI handles resolution)\n const hash = useGTCallbackParams.hasDeriveContext\n ? ''\n : useGTCallbackParams.hash;\n\n registerUseGTCallback({\n identifier,\n state,\n content: useGTCallbackParams.content,\n context: useGTCallbackParams.context,\n id: useGTCallbackParams.id,\n maxChars: useGTCallbackParams.maxChars,\n hash,\n format: useGTCallbackParams.format,\n });\n}\n\n/**\n * Handle useTranslations_callback / getTranslations_callback\n */\nfunction handleUseTranslationsCallback(\n callExprPath: NodePath<t.CallExpression>,\n state: TransformState,\n identifier: number\n) {\n // Check for violations\n const callExpr = callExprPath.node;\n const useTranslationsCallbackParams =\n validateUseTranslationsCallback(callExpr);\n state.errorTracker.addErrors(useTranslationsCallbackParams.errors);\n if (useTranslationsCallbackParams.errors.length > 0) {\n return;\n }\n\n // Track the function call\n registerUseTranslationsCallback({\n identifier,\n state,\n });\n}\n\n/**\n * Handle useMessages_callback / getMessages_callback\n */\nfunction handleUseMessagesCallback(\n callExprPath: NodePath<t.CallExpression>,\n state: TransformState,\n identifier: number\n) {\n // Validate parameters\n const callExpr = callExprPath.node;\n const useMessagesCallbackParams = validateUseMessagesCallback(callExpr);\n\n // Check for violations\n state.errorTracker.addErrors(useMessagesCallbackParams.errors);\n if (useMessagesCallbackParams.errors.length > 0) {\n return;\n }\n\n // Track the function call\n registerUseMessagesCallback({\n identifier,\n state,\n });\n}\n\n/**\n * Handle react function invocations\n * jsxDEV, jsx, jsxs, ...\n *\n * We want to check these because they wrap <T> and other components\n */\nfunction handleReactInvocation(\n callExprPath: NodePath<t.CallExpression>,\n state: TransformState\n) {\n const callExpr = callExprPath.node;\n // Check if it contains a GT component (first argument)\n if (callExpr.arguments.length === 0) {\n state.errorTracker.addError(\n 'React invocation must have at least one argument' +\n createErrorLocation(callExpr)\n );\n return;\n }\n const firstArg = callExpr.arguments[0];\n if (!t.isExpression(firstArg)) {\n state.errorTracker.addError(\n 'React invocation first argument must be an expression' +\n createErrorLocation(callExpr)\n );\n return;\n }\n\n // Get function name from callee\n const { namespaceName, functionName } =\n getCalleeNameFromJsxExpressionParam(firstArg);\n if (!functionName) {\n state.errorTracker.addError(\n 'React invocation first argument must be a function' +\n createErrorLocation(callExpr)\n );\n return;\n }\n // Get the canonical function name\n const { canonicalName, type } = getTrackedVariable(\n state.scopeTracker,\n namespaceName,\n functionName\n );\n if (!canonicalName) {\n return;\n }\n\n // Filter out non-GT components\n if (type !== 'generaltranslation' || !isTranslationComponent(canonicalName)) {\n return;\n }\n\n // Validate the arguments\n const { errors, _hash, id, context, children, maxChars, hasDeriveContext } =\n validateTranslationComponentArgs(callExprPath, canonicalName, state);\n\n if (errors.length > 0) {\n state.errorTracker.addErrors(errors);\n return;\n }\n\n // Calculate hash (skip when context contains derive — CLI handles resolution)\n const hash = hasDeriveContext\n ? ''\n : _hash ||\n hashSource({\n source: children!,\n ...(context && { context }),\n ...(id && { id }),\n ...(maxChars != null && { maxChars }),\n dataFormat: 'JSX',\n });\n\n // Debug: record hash → children mapping\n // Note: children may be undefined when autoderive filters all dynamic-content\n // errors (the early return in constructJsxChildren means value is never set).\n // This is intentional — the compiler signals CLI resolution via hash=''.\n if (state.debugManifest) {\n state.debugManifest.set(hash, children ?? null);\n }\n\n // Track the component (increment counter, initialize aggregator, set hash)\n registerTranslationComponent(state, hash, { children, id, context });\n}\n\n/**\n * Handle standalone translation functions: t() and msg()\n * Same argument structure as useGT_callback (message string + options object).\n */\nfunction handleStandaloneTranslation(\n callExprPath: NodePath<t.CallExpression>,\n state: TransformState,\n { injectHash }: { injectHash: boolean }\n) {\n // Reuse the same validation as useGT_callback (identical argument structure)\n const params = validateTranslationFunction(callExprPath, state);\n state.errorTracker.addErrors(params.errors);\n if (params.errors.length > 0 || params.content === undefined) {\n return;\n }\n\n // Skip derive content\n if (params.hasDeriveContext) {\n return;\n }\n\n registerStandaloneTranslation({\n state,\n content: params.content,\n hash: params.hash,\n id: params.id,\n context: params.context,\n maxChars: params.maxChars,\n format: params.format,\n injectHash,\n });\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AAqCA,SAAgB,sBACd,OACqC;AACrC,SAAQ,iBAAiB;EAEvB,MAAM,WAAW,aAAa;EAG9B,MAAM,EAAE,eAAe,iBACrBA,kDAAAA,4BAA4B,SAAS;AACvC,MAAI,CAAC,aACH;EAIF,MAAM,EAAE,eAAe,YAAY,SAASC,qCAAAA,mBAC1C,MAAM,cACN,eACA,aACD;AACD,MAAI,CAAC,cACH;AAIF,MACE,SAAS,wBACTC,mCAAAA,8BAA8B,cAAc,CAG5C,qCACE,cACA,OACA,eACA,WACD;WACQ,SAAS,WAAWC,sCAAAA,gBAAgB,cAAc,CAE3D,uBAAsB,cAAc,MAAM;WAE1C,SAAS,wBACT,kBAAA,MAGA,6BAA4B,cAAc,OAAO,EAAE,YAAY,OAAO,CAAC;WAEvE,SAAS,wBACT,kBAAA,IAIA,6BAA4B,cAAc,OAAO,EAAE,YAAY,MAAM,CAAC;;;;;;;AAa5E,SAAS,oCACP,cACA,OACA,eACA,YACA;AAEA,SAAQ,eAAR;EACE,KAAA;EACA,KAAA;AACE,uBAAoB,cAAc,OAAO,WAAW;AACpD;EACF,KAAA;EACA,KAAA;AACE,iCAA8B,cAAc,OAAO,WAAW;AAC9D;EACF,KAAA;EACA,KAAA;AACE,6BAA0B,cAAc,OAAO,WAAW;AAC1D;EACF,QACE;;;;;;AAON,SAAS,oBACP,cACA,OACA,YACA;CAEA,MAAM,sBAAsBC,yDAAAA,4BAA4B,cAAc,MAAM;AAC5E,OAAM,aAAa,UAAU,oBAAoB,OAAO;AACxD,KACE,oBAAoB,OAAO,SAA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QAAQ,OAAO,IAAI,SAAS,UAAU,UAAU,qBACtDC,8DAAAA,iCAAiC,cAAc,eAAe,MAAM;AAEtE,KAAI,OAAO,SAAS,GAAG;AACrB,QAAM,aAAa,UAAU,OAAO;AACpC;;CAIF,MAAM,OAAO,mBACT,KACA,SACAC,4BAAAA,QAAW;EACT,QAAQ;EACR,GAAI,WAAW,EAAE,SAAS;EAC1B,GAAI,MAAM,EAAE,IAAI;EAChB,GAAI,YAAY,QAAQ,EAAE,UAAU;EACpC,YAAY;EACb,CAAC;AAMN,KAAI,MAAM,cACR,OAAM,cAAc,IAAI,MAAM,YAAY,KAAK;AAIjD,6DAAA,6BAA6B,OAAO,MAAM;EAAE;EAAU;EAAI;EAAS,CAAC;;;;;;AAOtE,SAAS,4BACP,cACA,OACA,EAAE,cACF;CAEA,MAAM,SAASR,yDAAAA,4BAA4B,cAAc,MAAM;AAC/D,OAAM,aAAa,UAAU,OAAO,OAAO;AAC3C,KAAI,OAAO,OAAO,SAAS,KAAK,OAAO,YAAY,KAAA,EACjD;AAIF,KAAI,OAAO,iBACT;AAGF,8DAAA,8BAA8B;EAC5B;EACA,SAAS,OAAO;EAChB,MAAM,OAAO;EACb,IAAI,OAAO;EACX,SAAS,OAAO;EAChB,UAAU,OAAO;EACjB,QAAQ,OAAO;EACf;EACD,CAAC"}
|
|
1
|
+
{"version":3,"file":"processCallExpression.js","names":["getCalleeNameFromExpression","getTrackedVariable","isTranslationFunctionCallback","isReactFunction","validateTranslationFunction","validateUseTranslationsCallback","validateUseMessagesCallback","createErrorLocation","t","getCalleeNameFromJsxExpressionParam","isTranslationComponent","validateTranslationComponentArgs","hashSource"],"sources":["../../../src/processing/collection/processCallExpression.ts"],"sourcesContent":["import { NodePath, VisitNode } from '@babel/traverse';\nimport * as t from '@babel/types';\nimport { TransformState } from '../../state/types';\nimport {\n isTranslationComponent,\n isTranslationFunctionCallback,\n} from '../../utils/constants/gt/helpers';\nimport { getCalleeNameFromExpression } from '../../utils/parsing/getCalleeNameFromExpression';\nimport {\n GT_ALL_FUNCTIONS,\n GT_CALLBACK_FUNCTIONS,\n GT_OTHER_FUNCTIONS,\n} from '../../utils/constants/gt/constants';\nimport {\n validateTranslationFunction,\n validateUseMessagesCallback,\n validateUseTranslationsCallback,\n} from '../../transform/validation/validateTranslationFunction';\nimport { registerUseGTCallback } from '../../transform/registration/callbacks/registerUseGTCallback';\nimport { registerUseTranslationsCallback } from '../../transform/registration/callbacks/registerUseTranslationsCallback';\nimport { registerUseMessagesCallback } from '../../transform/registration/callbacks/registerUseMessagesCallback';\nimport { getTrackedVariable } from '../../transform/getTrackedVariable';\nimport { isReactFunction } from '../../utils/constants/react/helpers';\nimport { validateTranslationComponentArgs } from '../../transform/validation/validateTranslationComponentArgs';\nimport { registerTranslationComponent } from '../../transform/registration/registerTranslationComponent';\nimport { getCalleeNameFromJsxExpressionParam } from '../../transform/jsx-children/utils/getCalleeNameFromJsxExpressionParam';\nimport { createErrorLocation } from '../../utils/errors';\nimport hashSource from '../../utils/calculateHash';\nimport { registerStandaloneTranslation } from '../../transform/registration/registerStandaloneTranslation';\n\n/**\n * Process call expressions\n * - register content from GT callback functions invocations (useGT_callback, etc.)\n * - register <T> + other component content (via jsxDev, jsx, jsxs invocations)\n * - register msg() function invocations?\n * - generally validate content\n */\nexport function processCallExpression(\n state: TransformState\n): VisitNode<t.Node, t.CallExpression> {\n return (callExprPath) => {\n // Get the call expression\n const callExpr = callExprPath.node;\n\n // Get function name from callee\n const { namespaceName, functionName } =\n getCalleeNameFromExpression(callExpr);\n if (!functionName) {\n return;\n }\n\n // Get the canonical function name\n const { canonicalName, identifier, type } = getTrackedVariable(\n state.scopeTracker,\n namespaceName,\n functionName\n );\n if (!canonicalName) {\n return;\n }\n\n // Handle each respective case\n if (\n type === 'generaltranslation' &&\n isTranslationFunctionCallback(canonicalName)\n ) {\n // Handle translation function callbacks (useGT_callback, etc.)\n handleTranslationCallbackInvocation(\n callExprPath,\n state,\n canonicalName,\n identifier!\n );\n } else if (type === 'react' && isReactFunction(canonicalName)) {\n // Handle react variables (jsxDEV, etc.)\n handleReactInvocation(callExprPath, state);\n } else if (\n type === 'generaltranslation' &&\n canonicalName === GT_OTHER_FUNCTIONS.msg\n ) {\n // msg() is runtime-only content; it must not advance the injection counter.\n handleStandaloneTranslation(callExprPath, state, { injectHash: false });\n } else if (\n type === 'generaltranslation' &&\n canonicalName === GT_OTHER_FUNCTIONS.t\n ) {\n // Standalone t() receives an injected $_hash, so collection reserves a\n // matching counter slot for the injection pass.\n handleStandaloneTranslation(callExprPath, state, { injectHash: true });\n }\n };\n}\n\n/* =============================== */\n/* Handlers */\n/* =============================== */\n\n/**\n * Handle general translation variables\n * useGTCallback(), useTranslationsCallback(), useMessagesCallback(), etc.\n */\nfunction handleTranslationCallbackInvocation(\n callExprPath: NodePath<t.CallExpression>,\n state: TransformState,\n canonicalName: GT_ALL_FUNCTIONS,\n identifier: number\n) {\n // Handle translation function callbacks ()\n switch (canonicalName) {\n case GT_CALLBACK_FUNCTIONS.useGT_callback:\n case GT_CALLBACK_FUNCTIONS.getGT_callback:\n handleUseGTCallback(callExprPath, state, identifier);\n break;\n case GT_CALLBACK_FUNCTIONS.useTranslations_callback:\n case GT_CALLBACK_FUNCTIONS.getTranslations_callback:\n handleUseTranslationsCallback(callExprPath, state, identifier);\n break;\n case GT_CALLBACK_FUNCTIONS.useMessages_callback:\n case GT_CALLBACK_FUNCTIONS.getMessages_callback:\n handleUseMessagesCallback(callExprPath, state, identifier);\n break;\n default:\n return;\n }\n}\n\n/**\n * Handle useGT_callback / getGT_callback\n */\nfunction handleUseGTCallback(\n callExprPath: NodePath<t.CallExpression>,\n state: TransformState,\n identifier: number\n) {\n // Check for violations\n const useGTCallbackParams = validateTranslationFunction(callExprPath, state);\n state.errorTracker.addErrors(useGTCallbackParams.errors);\n if (\n useGTCallbackParams.errors.length > 0 ||\n useGTCallbackParams.content === undefined\n ) {\n return;\n }\n\n // Track the function call\n // When context contains derive(), skip hash calculation (CLI handles resolution)\n const hash = useGTCallbackParams.hasDeriveContext\n ? ''\n : useGTCallbackParams.hash;\n\n registerUseGTCallback({\n identifier,\n state,\n content: useGTCallbackParams.content,\n context: useGTCallbackParams.context,\n id: useGTCallbackParams.id,\n maxChars: useGTCallbackParams.maxChars,\n hash,\n format: useGTCallbackParams.format,\n });\n}\n\n/**\n * Handle useTranslations_callback / getTranslations_callback\n */\nfunction handleUseTranslationsCallback(\n callExprPath: NodePath<t.CallExpression>,\n state: TransformState,\n identifier: number\n) {\n // Check for violations\n const callExpr = callExprPath.node;\n const useTranslationsCallbackParams =\n validateUseTranslationsCallback(callExpr);\n state.errorTracker.addErrors(useTranslationsCallbackParams.errors);\n if (useTranslationsCallbackParams.errors.length > 0) {\n return;\n }\n\n // Track the function call\n registerUseTranslationsCallback({\n identifier,\n state,\n });\n}\n\n/**\n * Handle useMessages_callback / getMessages_callback\n */\nfunction handleUseMessagesCallback(\n callExprPath: NodePath<t.CallExpression>,\n state: TransformState,\n identifier: number\n) {\n // Validate parameters\n const callExpr = callExprPath.node;\n const useMessagesCallbackParams = validateUseMessagesCallback(callExpr);\n\n // Check for violations\n state.errorTracker.addErrors(useMessagesCallbackParams.errors);\n if (useMessagesCallbackParams.errors.length > 0) {\n return;\n }\n\n // Track the function call\n registerUseMessagesCallback({\n identifier,\n state,\n });\n}\n\n/**\n * Handle react function invocations\n * jsxDEV, jsx, jsxs, ...\n *\n * We want to check these because they wrap <T> and other components\n */\nfunction handleReactInvocation(\n callExprPath: NodePath<t.CallExpression>,\n state: TransformState\n) {\n const callExpr = callExprPath.node;\n // Check if it contains a GT component (first argument)\n if (callExpr.arguments.length === 0) {\n state.errorTracker.addError(\n 'React invocation must have at least one argument' +\n createErrorLocation(callExpr)\n );\n return;\n }\n const firstArg = callExpr.arguments[0];\n if (!t.isExpression(firstArg)) {\n state.errorTracker.addError(\n 'React invocation first argument must be an expression' +\n createErrorLocation(callExpr)\n );\n return;\n }\n\n // Get function name from callee\n const { namespaceName, functionName } =\n getCalleeNameFromJsxExpressionParam(firstArg);\n if (!functionName) {\n state.errorTracker.addError(\n 'React invocation first argument must be a function' +\n createErrorLocation(callExpr)\n );\n return;\n }\n // Get the canonical function name\n const { canonicalName, type } = getTrackedVariable(\n state.scopeTracker,\n namespaceName,\n functionName\n );\n if (!canonicalName) {\n return;\n }\n\n // Filter out non-GT components\n if (type !== 'generaltranslation' || !isTranslationComponent(canonicalName)) {\n return;\n }\n\n // Validate the arguments\n const { errors, _hash, id, context, children, maxChars, hasDeriveContext } =\n validateTranslationComponentArgs(callExprPath, canonicalName, state);\n\n if (errors.length > 0) {\n state.errorTracker.addErrors(errors);\n return;\n }\n\n // Calculate hash (skip when context contains derive — CLI handles resolution)\n const hash = hasDeriveContext\n ? ''\n : _hash ||\n hashSource({\n source: children!,\n ...(context && { context }),\n ...(maxChars != null && { maxChars }),\n dataFormat: 'JSX',\n });\n\n // Debug: record hash → children mapping\n // Note: children may be undefined when autoderive filters all dynamic-content\n // errors (the early return in constructJsxChildren means value is never set).\n // This is intentional — the compiler signals CLI resolution via hash=''.\n if (state.debugManifest) {\n state.debugManifest.set(hash, children ?? null);\n }\n\n // Track the component (increment counter, initialize aggregator, set hash)\n registerTranslationComponent(state, hash, { children, id, context });\n}\n\n/**\n * Handle standalone translation functions: t() and msg()\n * Same argument structure as useGT_callback (message string + options object).\n */\nfunction handleStandaloneTranslation(\n callExprPath: NodePath<t.CallExpression>,\n state: TransformState,\n { injectHash }: { injectHash: boolean }\n) {\n // Reuse the same validation as useGT_callback (identical argument structure)\n const params = validateTranslationFunction(callExprPath, state);\n state.errorTracker.addErrors(params.errors);\n if (params.errors.length > 0 || params.content === undefined) {\n return;\n }\n\n // Skip derive content\n if (params.hasDeriveContext) {\n return;\n }\n\n registerStandaloneTranslation({\n state,\n content: params.content,\n hash: params.hash,\n id: params.id,\n context: params.context,\n maxChars: params.maxChars,\n format: params.format,\n injectHash,\n });\n}\n"],"mappings":";;;;;;;;;;;;;;;;;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QAAQ,EAAE,UAAU;EACpC,YAAY;EACb,CAAC;AAMN,KAAI,MAAM,cACR,OAAM,cAAc,IAAI,MAAM,YAAY,KAAK;AAIjD,6DAAA,6BAA6B,OAAO,MAAM;EAAE;EAAU;EAAI;EAAS,CAAC;;;;;;AAOtE,SAAS,4BACP,cACA,OACA,EAAE,cACF;CAEA,MAAM,SAASR,yDAAAA,4BAA4B,cAAc,MAAM;AAC/D,OAAM,aAAa,UAAU,OAAO,OAAO;AAC3C,KAAI,OAAO,OAAO,SAAS,KAAK,OAAO,YAAY,KAAA,EACjD;AAIF,KAAI,OAAO,iBACT;AAGF,8DAAA,8BAA8B;EAC5B;EACA,SAAS,OAAO;EAChB,MAAM,OAAO;EACb,IAAI,OAAO;EACX,SAAS,OAAO;EAChB,UAAU,OAAO;EACjB,QAAQ,OAAO;EACf;EACD,CAAC"}
|
|
@@ -12,11 +12,11 @@ export interface TranslationContent {
|
|
|
12
12
|
message: string;
|
|
13
13
|
/** Pre-calculated hash for this content */
|
|
14
14
|
hash: string;
|
|
15
|
-
/** Optional ID from options: t("text", {id: "greeting"}) → "greeting" */
|
|
15
|
+
/** Optional ID from options: t("text", {$id: "greeting"}) → "greeting" */
|
|
16
16
|
id?: string;
|
|
17
|
-
/** Optional context from options: t("text", {context: "nav"}) → "nav" */
|
|
17
|
+
/** Optional context from options: t("text", {$context: "nav"}) → "nav" */
|
|
18
18
|
context?: string;
|
|
19
|
-
/** Optional maxChars from options: t("text", {maxChars: 10}) → 10 */
|
|
19
|
+
/** Optional maxChars from options: t("text", {$maxChars: 10}) → 10 */
|
|
20
20
|
maxChars?: number;
|
|
21
21
|
/** Optional format from options: t("text", {$format: "STRING"}) → "STRING" */
|
|
22
22
|
format?: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"StringCollector.d.ts","sourceRoot":"","sources":["../../src/state/StringCollector.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH;;GAEG;AACH,MAAM,WAAW,kBAA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AAE;IAI7C;;OAEG;IACH,SAAS,IAAI,yBAAyB;IAUtC;;OAEG;IACH,WAAW,CAAC,KAAK,EAAE,yBAAyB,GAAG,IAAI;CAqBpD"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"StringCollector.js","names":[],"sources":["../../src/state/StringCollector.ts"],"sourcesContent":["/**\n * String Collector - Manages translation content across two-pass transformation\n *\n * Pass 1: Collects translation strings, JSX content, and hash data\n * Pass 2: Injects collected data back into useGT()/getGT() calls\n */\n\n/**\n * Content extracted from a t() function call\n */\nexport interface TranslationContent {\n /** The string message: t(\"Hello world\") → \"Hello world\" */\n message: string;\n /** Pre-calculated hash for this content */\n hash: string;\n /** Optional ID from options: t(\"text\", {id: \"greeting\"}) → \"greeting\" */\n id?: string;\n /** Optional context from options: t(\"text\", {context: \"nav\"}) → \"nav\" */\n context?: string;\n /** Optional maxChars from options: t(\"text\", {maxChars: 10}) → 10 */\n maxChars?: number;\n /** Optional format from options: t(\"text\", {$format: \"STRING\"}) → \"STRING\" */\n format?: string;\n}\n\n/**\n * Content extracted from JSX translation components like <T>\n */\nexport interface TranslationJsx {\n /** Pre-calculated hash for this JSX content */\n hash: string;\n /** JSX children structure (serializable) */\n children?: unknown;\n /** Optional ID from props */\n id?: string;\n /** Optional context from props */\n context?: string;\n}\n\n/**\n * Just a hash value for simple hash injection\n */\nexport interface TranslationHash {\n /** The hash value to inject */\n hash: string;\n}\n\ntype SerializedStringCollector = {\n contentAggregators: Record<string, TranslationContent[]>;\n jsxAggregators: Record<string, TranslationJsx>;\n hashAggregators: Record<string, TranslationHash>;\n globalCallCounter: number;\n};\n\n/**\n * String collector for two-pass transformation system\n */\nexport class StringCollector {\n /** Vector of translation calls indexed by counter ID */\n private contentAggregators: Map<number, TranslationContent[]> = new Map();\n private jsxAggregators: Map<number, TranslationJsx> = new Map();\n private hashAggregators: Map<number, TranslationHash> = new Map();\n /** Global counter incremented for each useGT/getGT call encountered */\n private globalCallCounter: number = 0;\n /** Runtime-only entries for standalone strings consumed by runtime translate */\n private runtimeOnlyEntries: TranslationContent[] = [];\n\n /**\n * Increment counter and return the current counter ID for a useGT/getGT call\n * These IDs are deterministic\n */\n incrementCounter(): number {\n this.globalCallCounter += 1;\n return this.globalCallCounter;\n }\n\n /**\n * Get current global counter value\n */\n getCounter(): number {\n return this.globalCallCounter;\n }\n\n /**\n * Pass 1: Add translation content from a gt() call to a specific useGT/getGT aggregator\n * Multiple content items can be added to the same call\n */\n pushTranslationContent(counterId: number, content: TranslationContent): void {\n if (counterId === -1) {\n throw new Error(\n 'Cannot have a counterId of -1. This likely means you are trying to register content from a namespace method invocation.'\n );\n }\n // Get the agreggator\n let aggregator = this.contentAggregators.get(counterId);\n if (!aggregator) {\n aggregator = [content];\n this.contentAggregators.set(counterId, aggregator);\n } else {\n aggregator.push(content);\n }\n }\n\n /**\n * Pass 1: Set JSX translation content for a specific useGT/getGT\n * Only one JSX item can be set per call (overwrites if called multiple times)\n */\n setTranslationJsx(counterId: number, jsx: TranslationJsx): void {\n this.jsxAggregators.set(counterId, jsx);\n }\n\n /**\n * Pass 1: Set hash-only content for a specific useGT/getGT\n * Only one hash can be set per call (overwrites if called multiple times)\n */\n setTranslationHash(counterId: number, hash: TranslationHash): void {\n this.hashAggregators.set(counterId, hash);\n }\n\n /**\n * Pass 2: Get translation call data for injection into a specific useGT/getGT call\n */\n getTranslationData(counterId: number):\n | {\n type: 'content' | 'jsx' | 'hash';\n value: TranslationContent[] | TranslationJsx | TranslationHash;\n }\n | undefined {\n if (this.contentAggregators.has(counterId)) {\n return {\n type: 'content',\n value: this.contentAggregators.get(counterId)!,\n };\n } else if (this.jsxAggregators.has(counterId)) {\n return { type: 'jsx', value: this.jsxAggregators.get(counterId)! };\n } else if (this.hashAggregators.has(counterId)) {\n return { type: 'hash', value: this.hashAggregators.get(counterId)! };\n }\n }\n\n /**\n * Get the translation content for a specific useGT/getGT call\n */\n getTranslationContent(counterId: number): TranslationContent[] | undefined {\n return this.contentAggregators.get(counterId);\n }\n\n /**\n * Get the translation JSX for a specific <T> component\n */\n getTranslationJsx(counterId: number): TranslationJsx | undefined {\n return this.jsxAggregators.get(counterId);\n }\n\n /**\n * Get the translation hash for a specific other call\n */\n getTranslationHash(counterId: number): TranslationHash | undefined {\n return this.hashAggregators.get(counterId);\n }\n\n /**\n * Reset all state (useful for testing)\n */\n clear(): void {\n this.contentAggregators.clear();\n this.jsxAggregators.clear();\n this.hashAggregators.clear();\n this.runtimeOnlyEntries = [];\n this.globalCallCounter = 0;\n }\n\n /**\n * Reset the counter to zero\n */\n resetCounter(): void {\n this.globalCallCounter = 0;\n }\n\n /**\n * Has content\n */\n hasContent(): boolean {\n return (\n this.contentAggregators.size +\n this.jsxAggregators.size +\n this.hashAggregators.size +\n this.runtimeOnlyEntries.length >\n 0\n );\n }\n\n /**\n * Get all translation content entries (flattened across all aggregators)\n */\n getAllTranslationContent(): TranslationContent[] {\n return Array.from(this.contentAggregators.values()).flat();\n }\n\n /**\n * Get all translation JSX entries\n */\n getAllTranslationJsx(): TranslationJsx[] {\n return Array.from(this.jsxAggregators.values());\n }\n\n /**\n * Add a runtime-only translation entry for the runtime translate pass.\n */\n pushRuntimeOnlyContent(content: TranslationContent): void {\n this.runtimeOnlyEntries.push(content);\n }\n\n /**\n * Get all runtime-only translation entries\n */\n getRuntimeOnlyContent(): TranslationContent[] {\n return this.runtimeOnlyEntries;\n }\n\n /**\n * Helper convert to string\n */\n serialize(): SerializedStringCollector {\n const output = {\n contentAggregators: Object.fromEntries(this.contentAggregators),\n jsxAggregators: Object.fromEntries(this.jsxAggregators),\n hashAggregators: Object.fromEntries(this.hashAggregators),\n globalCallCounter: this.globalCallCounter,\n };\n return output;\n }\n\n /**\n * Helper to repopulate\n */\n unserialize(input: SerializedStringCollector): void {\n this.contentAggregators = Object.entries(\n input.contentAggregators as Record<number, TranslationContent[]>\n ).reduce((acc, [key, value]) => {\n acc.set(Number(key), value);\n return acc;\n }, new Map<number, TranslationContent[]>());\n this.jsxAggregators = Object.entries(\n input.jsxAggregators as Record<number, TranslationJsx>\n ).reduce((acc, [key, value]) => {\n acc.set(Number(key), value);\n return acc;\n }, new Map<number, TranslationJsx>());\n this.hashAggregators = Object.entries(\n input.hashAggregators as Record<number, TranslationHash>\n ).reduce((acc, [key, value]) => {\n acc.set(Number(key), value);\n return acc;\n }, new Map<number, TranslationHash>());\n this.globalCallCounter = input.globalCallCounter;\n }\n}\n"],"mappings":";;;;;AAyDA,IAAa,kBAAb,MAA6B;;4CAEqC,IAAI,KAAK;wCACnB,IAAI,KAAK;yCACP,IAAI,KAAK;2BAE7B;4BAEe,EAAE;;;;;;CAMrD,mBAA2B;AACzB,OAAK,qBAAqB;AAC1B,SAAO,KAAK;;;;;CAMd,aAAqB;AACnB,SAAO,KAAK;;;;;;CAOd,uBAAuB,WAAmB,SAAmC;AAC3E,MAAI,cAAc,GAChB,OAAM,IAAI,MACR,0HACD;EAGH,IAAI,aAAa,KAAK,mBAAmB,IAAI,UAAU;AACvD,MAAI,CAAC,YAAY;AACf,gBAAa,CAAC,QAAQ;AACtB,QAAK,mBAAmB,IAAI,WAAW,WAAW;QAElD,YAAW,KAAK,QAAQ;;;;;;CAQ5B,kBAAkB,WAAmB,KAA2B;AAC9D,OAAK,eAAe,IAAI,WAAW,IAAI;;;;;;CAOzC,mBAAmB,WAAmB,MAA6B;AACjE,OAAK,gBAAgB,IAAI,WAAW,KAAK;;;;;CAM3C,mBAAmB,WAKL;AACZ,MAAI,KAAK,mBAAmB,IAAI,UAAU,CACxC,QAAO;GACL,MAAM;GACN,OAAO,KAAK,mBAAmB,IAAI,UAAU;GAC9C;WACQ,KAAK,eAAe,IAAI,UAAU,CAC3C,QAAO;GAAE,MAAM;GAAO,OAAO,KAAK,eAAe,IAAI,UAAU;GAAG;WACzD,KAAK,gBAAgB,IAAI,UAAU,CAC5C,QAAO;GAAE,MAAM;GAAQ,OAAO,KAAK,gBAAgB,IAAI,UAAU;GAAG;;;;;CAOxE,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AAC3B,UAAO;qBACN,IAAI,KAA6B,CAAC;AACrC,OAAK,kBAAkB,OAAO,QAC5B,MAAM,gBACP,CAAC,QAAQ,KAAK,CAAC,KAAK,WAAW;AAC9B,OAAI,IAAI,OAAO,IAAI,EAAE,MAAM;AAC3B,UAAO;qBACN,IAAI,KAA8B,CAAC;AACtC,OAAK,oBAAoB,MAAM"}
|
|
1
|
+
{"version":3,"file":"StringCollector.js","names":[],"sources":["../../src/state/StringCollector.ts"],"sourcesContent":["/**\n * String Collector - Manages translation content across two-pass transformation\n *\n * Pass 1: Collects translation strings, JSX content, and hash data\n * Pass 2: Injects collected data back into useGT()/getGT() calls\n */\n\n/**\n * Content extracted from a t() function call\n */\nexport interface TranslationContent {\n /** The string message: t(\"Hello world\") → \"Hello world\" */\n message: string;\n /** Pre-calculated hash for this content */\n hash: string;\n /** Optional ID from options: t(\"text\", {$id: \"greeting\"}) → \"greeting\" */\n id?: string;\n /** Optional context from options: t(\"text\", {$context: \"nav\"}) → \"nav\" */\n context?: string;\n /** Optional maxChars from options: t(\"text\", {$maxChars: 10}) → 10 */\n maxChars?: number;\n /** Optional format from options: t(\"text\", {$format: \"STRING\"}) → \"STRING\" */\n format?: string;\n}\n\n/**\n * Content extracted from JSX translation components like <T>\n */\nexport interface TranslationJsx {\n /** Pre-calculated hash for this JSX content */\n hash: string;\n /** JSX children structure (serializable) */\n children?: unknown;\n /** Optional ID from props */\n id?: string;\n /** Optional context from props */\n context?: string;\n}\n\n/**\n * Just a hash value for simple hash injection\n */\nexport interface TranslationHash {\n /** The hash value to inject */\n hash: string;\n}\n\ntype SerializedStringCollector = {\n contentAggregators: Record<string, TranslationContent[]>;\n jsxAggregators: Record<string, TranslationJsx>;\n hashAggregators: Record<string, TranslationHash>;\n globalCallCounter: number;\n};\n\n/**\n * String collector for two-pass transformation system\n */\nexport class StringCollector {\n /** Vector of translation calls indexed by counter ID */\n private contentAggregators: Map<number, TranslationContent[]> = new Map();\n private jsxAggregators: Map<number, TranslationJsx> = new Map();\n private hashAggregators: Map<number, TranslationHash> = new Map();\n /** Global counter incremented for each useGT/getGT call encountered */\n private globalCallCounter: number = 0;\n /** Runtime-only entries for standalone strings consumed by runtime translate */\n private runtimeOnlyEntries: TranslationContent[] = [];\n\n /**\n * Increment counter and return the current counter ID for a useGT/getGT call\n * These IDs are deterministic\n */\n incrementCounter(): number {\n this.globalCallCounter += 1;\n return this.globalCallCounter;\n }\n\n /**\n * Get current global counter value\n */\n getCounter(): number {\n return this.globalCallCounter;\n }\n\n /**\n * Pass 1: Add translation content from a gt() call to a specific useGT/getGT aggregator\n * Multiple content items can be added to the same call\n */\n pushTranslationContent(counterId: number, content: TranslationContent): void {\n if (counterId === -1) {\n throw new Error(\n 'Cannot have a counterId of -1. This likely means you are trying to register content from a namespace method invocation.'\n );\n }\n // Get the agreggator\n let aggregator = this.contentAggregators.get(counterId);\n if (!aggregator) {\n aggregator = [content];\n this.contentAggregators.set(counterId, aggregator);\n } else {\n aggregator.push(content);\n }\n }\n\n /**\n * Pass 1: Set JSX translation content for a specific useGT/getGT\n * Only one JSX item can be set per call (overwrites if called multiple times)\n */\n setTranslationJsx(counterId: number, jsx: TranslationJsx): void {\n this.jsxAggregators.set(counterId, jsx);\n }\n\n /**\n * Pass 1: Set hash-only content for a specific useGT/getGT\n * Only one hash can be set per call (overwrites if called multiple times)\n */\n setTranslationHash(counterId: number, hash: TranslationHash): void {\n this.hashAggregators.set(counterId, hash);\n }\n\n /**\n * Pass 2: Get translation call data for injection into a specific useGT/getGT call\n */\n getTranslationData(counterId: number):\n | {\n type: 'content' | 'jsx' | 'hash';\n value: TranslationContent[] | TranslationJsx | TranslationHash;\n }\n | undefined {\n if (this.contentAggregators.has(counterId)) {\n return {\n type: 'content',\n value: this.contentAggregators.get(counterId)!,\n };\n } else if (this.jsxAggregators.has(counterId)) {\n return { type: 'jsx', value: this.jsxAggregators.get(counterId)! };\n } else if (this.hashAggregators.has(counterId)) {\n return { type: 'hash', value: this.hashAggregators.get(counterId)! };\n }\n }\n\n /**\n * Get the translation content for a specific useGT/getGT call\n */\n getTranslationContent(counterId: number): TranslationContent[] | undefined {\n return this.contentAggregators.get(counterId);\n }\n\n /**\n * Get the translation JSX for a specific <T> component\n */\n getTranslationJsx(counterId: number): TranslationJsx | undefined {\n return this.jsxAggregators.get(counterId);\n }\n\n /**\n * Get the translation hash for a specific other call\n */\n getTranslationHash(counterId: number): TranslationHash | undefined {\n return this.hashAggregators.get(counterId);\n }\n\n /**\n * Reset all state (useful for testing)\n */\n clear(): void {\n this.contentAggregators.clear();\n this.jsxAggregators.clear();\n this.hashAggregators.clear();\n this.runtimeOnlyEntries = [];\n this.globalCallCounter = 0;\n }\n\n /**\n * Reset the counter to zero\n */\n resetCounter(): void {\n this.globalCallCounter = 0;\n }\n\n /**\n * Has content\n */\n hasContent(): boolean {\n return (\n this.contentAggregators.size +\n this.jsxAggregators.size +\n this.hashAggregators.size +\n this.runtimeOnlyEntries.length >\n 0\n );\n }\n\n /**\n * Get all translation content entries (flattened across all aggregators)\n */\n getAllTranslationContent(): TranslationContent[] {\n return Array.from(this.contentAggregators.values()).flat();\n }\n\n /**\n * Get all translation JSX entries\n */\n getAllTranslationJsx(): TranslationJsx[] {\n return Array.from(this.jsxAggregators.values());\n }\n\n /**\n * Add a runtime-only translation entry for the runtime translate pass.\n */\n pushRuntimeOnlyContent(content: TranslationContent): void {\n this.runtimeOnlyEntries.push(content);\n }\n\n /**\n * Get all runtime-only translation entries\n */\n getRuntimeOnlyContent(): TranslationContent[] {\n return this.runtimeOnlyEntries;\n }\n\n /**\n * Helper convert to string\n */\n serialize(): SerializedStringCollector {\n const output = {\n contentAggregators: Object.fromEntries(this.contentAggregators),\n jsxAggregators: Object.fromEntries(this.jsxAggregators),\n hashAggregators: Object.fromEntries(this.hashAggregators),\n globalCallCounter: this.globalCallCounter,\n };\n return output;\n }\n\n /**\n * Helper to repopulate\n */\n unserialize(input: SerializedStringCollector): void {\n this.contentAggregators = Object.entries(\n input.contentAggregators as Record<number, TranslationContent[]>\n ).reduce((acc, [key, value]) => {\n acc.set(Number(key), value);\n return acc;\n }, new Map<number, TranslationContent[]>());\n this.jsxAggregators = Object.entries(\n input.jsxAggregators as Record<number, TranslationJsx>\n ).reduce((acc, [key, value]) => {\n acc.set(Number(key), value);\n return acc;\n }, new Map<number, TranslationJsx>());\n this.hashAggregators = Object.entries(\n input.hashAggregators as Record<number, TranslationHash>\n ).reduce((acc, [key, value]) => {\n acc.set(Number(key), value);\n return acc;\n }, new Map<number, TranslationHash>());\n this.globalCallCounter = input.globalCallCounter;\n }\n}\n"],"mappings":";;;;;AAyDA,IAAa,kBAAb,MAA6B;;4CAEqC,IAAI,KAAK;wCACnB,IAAI,KAAK;yCACP,IAAI,KAAK;2BAE7B;4BAEe,EAAE;;;;;;CAMrD,mBAA2B;AACzB,OAAK,qBAAqB;AAC1B,SAAO,KAAK;;;;;CAMd,aAAqB;AACnB,SAAO,KAAK;;;;;;CAOd,uBAAuB,WAAmB,SAAmC;AAC3E,MAAI,cAAc,GAChB,OAAM,IAAI,MACR,0HACD;EAGH,IAAI,aAAa,KAAK,mBAAmB,IAAI,UAAU;AACvD,MAAI,CAAC,YAAY;AACf,gBAAa,CAAC,QAAQ;AACtB,QAAK,mBAAmB,IAAI,WAAW,WAAW;QAElD,YAAW,KAAK,QAAQ;;;;;;CAQ5B,kBAAkB,WAAmB,KAA2B;AAC9D,OAAK,eAAe,IAAI,WAAW,IAAI;;;;;;CAOzC,mBAAmB,WAAmB,MAA6B;AACjE,OAAK,gBAAgB,IAAI,WAAW,KAAK;;;;;CAM3C,mBAAmB,WAKL;AACZ,MAAI,KAAK,mBAAmB,IAAI,UAAU,CACxC,QAAO;GACL,MAAM;GACN,OAAO,KAAK,mBAAmB,IAAI,UAAU;GAC9C;WACQ,KAAK,eAAe,IAAI,UAAU,CAC3C,QAAO;GAAE,MAAM;GAAO,OAAO,KAAK,eAAe,IAAI,UAAU;GAAG;WACzD,KAAK,gBAAgB,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3B,MAAM,eACP,CAAC,QAAQ,KAAK,CAAC,KAAK,WAAW;AAC9B,OAAI,IAAI,OAAO,IAAI,EAAE,MAAM;AAC3B,UAAO;qBACN,IAAI,KAA6B,CAAC;AACrC,OAAK,kBAAkB,OAAO,QAC5B,MAAM,gBACP,CAAC,QAAQ,KAAK,CAAC,KAAK,WAAW;AAC9B,OAAI,IAAI,OAAO,IAAI,EAAE,MAAM;AAC3B,UAAO;qBACN,IAAI,KAA8B,CAAC;AACtC,OAAK,oBAAoB,MAAM"}
|
|
@@ -2,7 +2,7 @@ import { TransformState } from '../../state/types';
|
|
|
2
2
|
import * as t from '@babel/types';
|
|
3
3
|
/**
|
|
4
4
|
* inject parameters into invocation of translation function
|
|
5
|
-
* - useGT(messages=[{
|
|
5
|
+
* - useGT(messages=[{$_hash, message, $id, $context, $maxChars}])
|
|
6
6
|
*/
|
|
7
7
|
export declare function injectCallbackDeclaratorFunctionParameters(varDeclarator: t.VariableDeclarator, state: TransformState): void;
|
|
8
8
|
//# sourceMappingURL=injectCallbackDeclaratorFunctionParameters.d.ts.map
|
|
@@ -12,7 +12,7 @@ _babel_types = require_runtime.__toESM(_babel_types);
|
|
|
12
12
|
//#region src/transform/injection/injectCallbackDeclaratorFunctionParameters.ts
|
|
13
13
|
/**
|
|
14
14
|
* inject parameters into invocation of translation function
|
|
15
|
-
* - useGT(messages=[{
|
|
15
|
+
* - useGT(messages=[{$_hash, message, $id, $context, $maxChars}])
|
|
16
16
|
*/
|
|
17
17
|
function injectCallbackDeclaratorFunctionParameters(varDeclarator, state) {
|
|
18
18
|
var _state$scopeTracker$g;
|
|
@@ -61,11 +61,11 @@ function injectUseGTParameters(expression, state, id) {
|
|
|
61
61
|
const translationContent = state.stringCollector.getTranslationContent(id);
|
|
62
62
|
if (!translationContent) return;
|
|
63
63
|
expression.arguments = [_babel_types.arrayExpression(translationContent.map((content) => _babel_types.objectExpression([
|
|
64
|
-
_babel_types.objectProperty(_babel_types.identifier("
|
|
64
|
+
_babel_types.objectProperty(_babel_types.identifier("$_hash"), _babel_types.stringLiteral(content.hash)),
|
|
65
65
|
_babel_types.objectProperty(_babel_types.identifier("message"), _babel_types.stringLiteral(content.message)),
|
|
66
|
-
...content.id ? [_babel_types.objectProperty(_babel_types.identifier("id"), _babel_types.stringLiteral(content.id))] : [],
|
|
67
|
-
...content.context ? [_babel_types.objectProperty(_babel_types.identifier("context"), _babel_types.stringLiteral(content.context))] : [],
|
|
68
|
-
...content.maxChars != null ? [_babel_types.objectProperty(_babel_types.identifier("maxChars"), _babel_types.numericLiteral(content.maxChars))] : []
|
|
66
|
+
...content.id ? [_babel_types.objectProperty(_babel_types.identifier("$id"), _babel_types.stringLiteral(content.id))] : [],
|
|
67
|
+
...content.context ? [_babel_types.objectProperty(_babel_types.identifier("$context"), _babel_types.stringLiteral(content.context))] : [],
|
|
68
|
+
...content.maxChars != null ? [_babel_types.objectProperty(_babel_types.identifier("$maxChars"), _babel_types.numericLiteral(content.maxChars))] : []
|
|
69
69
|
])))];
|
|
70
70
|
}
|
|
71
71
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"injectCallbackDeclaratorFunctionParameters.js","names":["t","getCalleeNameFromExpressionWrapper","getTrackedVariable","extractIdentifiersFromLVal","isGTFunctionWithCallbacks","createErrorLocation"],"sources":["../../../src/transform/injection/injectCallbackDeclaratorFunctionParameters.ts"],"sourcesContent":["import { TransformState } from '../../state/types';\nimport * as t from '@babel/types';\nimport { getTrackedVariable } from '../getTrackedVariable';\nimport { getCalleeNameFromExpressionWrapper } from '../../utils/parsing/getCalleeNameFromExpressionWrapper';\nimport { isGTFunctionWithCallbacks } from '../../utils/constants/gt/helpers';\nimport { GT_FUNCTIONS_WITH_CALLBACKS } from '../../utils/constants/gt/constants';\nimport { extractIdentifiersFromLVal } from '../../utils/parsing/extractIdentifiersFromLVal';\nimport { trackOverridingVariable } from '../tracking/trackOverridingVariable';\nimport { createErrorLocation } from '../../utils/errors';\n\n/**\n * inject parameters into invocation of translation function\n * - useGT(messages=[{
|
|
1
|
+
{"version":3,"file":"injectCallbackDeclaratorFunctionParameters.js","names":["t","getCalleeNameFromExpressionWrapper","getTrackedVariable","extractIdentifiersFromLVal","isGTFunctionWithCallbacks","createErrorLocation"],"sources":["../../../src/transform/injection/injectCallbackDeclaratorFunctionParameters.ts"],"sourcesContent":["import { TransformState } from '../../state/types';\nimport * as t from '@babel/types';\nimport { getTrackedVariable } from '../getTrackedVariable';\nimport { getCalleeNameFromExpressionWrapper } from '../../utils/parsing/getCalleeNameFromExpressionWrapper';\nimport { isGTFunctionWithCallbacks } from '../../utils/constants/gt/helpers';\nimport { GT_FUNCTIONS_WITH_CALLBACKS } from '../../utils/constants/gt/constants';\nimport { extractIdentifiersFromLVal } from '../../utils/parsing/extractIdentifiersFromLVal';\nimport { trackOverridingVariable } from '../tracking/trackOverridingVariable';\nimport { createErrorLocation } from '../../utils/errors';\n\n/**\n * inject parameters into invocation of translation function\n * - useGT(messages=[{$_hash, message, $id, $context, $maxChars}])\n */\nexport function injectCallbackDeclaratorFunctionParameters(\n varDeclarator: t.VariableDeclarator,\n state: TransformState\n): void {\n // Ignore non-LVal assignments\n if (!t.isLVal(varDeclarator.id)) {\n return;\n }\n\n // Get function name from callee\n const { namespaceName, functionName } = getCalleeNameFromExpressionWrapper(\n varDeclarator.init\n );\n if (!functionName) {\n return;\n }\n\n // Get the canonical function name\n const { canonicalName, type } = getTrackedVariable(\n state.scopeTracker,\n namespaceName,\n functionName\n );\n if (!canonicalName) {\n return;\n }\n\n // Extract identifiers from the LVal\n const identifiers = extractIdentifiersFromLVal(varDeclarator.id);\n\n // Validate the type\n if (\n type !== 'generaltranslation' ||\n !isGTFunctionWithCallbacks(canonicalName)\n ) {\n // Track as an overriding variable\n for (const identifier of identifiers) {\n trackOverridingVariable(identifier, state.scopeTracker);\n }\n return;\n }\n\n // There can only be one callback defined for const gt = useGT()\n if (identifiers.length !== 1) {\n state.logger.logError(\n `Multiple identifiers found for GT function with callbacks: ${canonicalName}. Parameter injection failed.` +\n createErrorLocation(varDeclarator.id)\n );\n return;\n }\n const identifier = identifiers[0];\n\n // Inject the parameters into the call expression\n const expression = getFunctionInvocation(varDeclarator);\n if (!expression) {\n state.logger.logError(\n `No valid function invocation found for ${functionName}. Parameter injection failed.` +\n createErrorLocation(varDeclarator.id)\n );\n return;\n }\n if (expression.arguments.length > 0) {\n // Found existing arguments, skip injection\n return;\n }\n\n // Look up identifier\n const id = state.scopeTracker.getVariable(identifier)?.identifier;\n if (!id) {\n state.logger.logError(\n `No translation callback variable found for ${identifier}. Parameter injection failed.` +\n createErrorLocation(varDeclarator.id)\n );\n return;\n }\n // Inject into the callees\n switch (canonicalName) {\n case GT_FUNCTIONS_WITH_CALLBACKS.useGT:\n case GT_FUNCTIONS_WITH_CALLBACKS.getGT:\n injectUseGTParameters(expression, state, id);\n break;\n default:\n return;\n }\n}\n\n/**\n * Inject the parameters into the useGT/getGT call\n * @param arguments - The arguments\n * @param state - The state\n * @param identifier - The identifier\n * @param translationContent - The translation content\n */\nfunction injectUseGTParameters(\n expression: t.CallExpression,\n state: TransformState,\n id: number\n) {\n // Get the corresponding callback injection data\n const translationContent = state.stringCollector.getTranslationContent(id);\n if (!translationContent) {\n return;\n }\n\n // Inject the parameters into the call expression\n expression.arguments = [\n t.arrayExpression(\n translationContent.map((content) =>\n t.objectExpression([\n t.objectProperty(\n t.identifier('$_hash'),\n t.stringLiteral(content.hash)\n ),\n t.objectProperty(\n t.identifier('message'),\n t.stringLiteral(content.message)\n ),\n ...(content.id\n ? [\n t.objectProperty(\n t.identifier('$id'),\n t.stringLiteral(content.id)\n ),\n ]\n : []),\n ...(content.context\n ? [\n t.objectProperty(\n t.identifier('$context'),\n t.stringLiteral(content.context)\n ),\n ]\n : []),\n ...(content.maxChars != null\n ? [\n t.objectProperty(\n t.identifier('$maxChars'),\n t.numericLiteral(content.maxChars)\n ),\n ]\n : []),\n ])\n )\n ),\n ];\n}\n\n/**\n * Get the function invocation from the variable declarator\n * @param varDeclarator - The variable declarator\n */\nfunction getFunctionInvocation(\n varDeclarator: t.VariableDeclarator\n): t.CallExpression | undefined {\n const expression = varDeclarator.init;\n if (!expression) {\n // failed\n return;\n }\n if (t.isCallExpression(expression)) {\n return expression;\n }\n if (\n t.isAwaitExpression(expression) &&\n t.isCallExpression(expression.argument)\n ) {\n return expression.argument;\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAcA,SAAgB,2CACd,eACA,OACM;;AAEN,KAAI,CAACA,aAAE,OAAO,cAAc,GAAG,CAC7B;CAIF,MAAM,EAAE,eAAe,iBAAiBC,yDAAAA,mCACtC,cAAc,KACf;AACD,KAAI,CAAC,aACH;CAIF,MAAM,EAAE,eAAe,SAASC,qCAAAA,mBAC9B,MAAM,cACN,eACA,aACD;AACD,KAAI,CAAC,cACH;CAIF,MAAM,cAAcC,iDAAAA,2BAA2B,cAAc,GAAG;AAGhE,KACE,SAAS,wBACT,CAACC,mCAAAA,0BAA0B,cAAc,EACzC;AAEA,OAAK,MAAM,cAAc,YACvB,oDAAA,wBAAwB,YAAY,MAAM,aAAa;AAEzD;;AAIF,KAAI,YAAY,WAAW,GAAG;AAC5B,QAAM,OAAO,SACX,8DAA8D,cAAc,iCAC1EC,qBAAAA,oBAAoB,cAAc,GAAG,CACxC;AACD;;CAEF,MAAM,aAAa,YAAY;CAG/B,MAAM,aAAa,sBAAsB,cAAc;AACvD,KAAI,CAAC,YAAY;AACf,QAAM,OAAO,SACX,0CAA0C,aAAa,iCACrDA,qBAAAA,oBAAoB,cAAc,GAAG,CACxC;AACD;;AAEF,KAAI,WAAW,UAAU,SAAS,EAEhC;CAIF,MAAM,MAAA,wBAAK,MAAM,aAAa,YAAY,WAAW,MAAA,QAAA,0BAAA,KAAA,IAAA,KAAA,IAAA,sBAAE;AACvD,KAAI,CAAC,IAAI;AACP,QAAM,OAAO,SACX,8CAA8C,WAAW,iCACvDA,qBAAAA,oBAAoB,cAAc,GAAG,CACxC;AACD;;AAGF,SAAQ,eAAR;EACE,KAAA;EACA,KAAA;AACE,yBAAsB,YAAY,OAAO,GAAG;AAC5C;EACF,QACE;;;;;;;;;;AAWN,SAAS,sBACP,YACA,OACA,IACA;CAEA,MAAM,qBAAqB,MAAM,gBAAgB,sBAAsB,GAAG;AAC1E,KAAI,CAAC,mBACH;AAIF,YAAW,YAAY,CACrBL,aAAE,gBACA,mBAAmB,KAAK,YACtBA,aAAE,iBAAiB;EACjBA,aAAE,eACAA,aAAE,WAAW,SAAS,EACtBA,aAAE,cAAc,QAAQ,KAAK,CAC9B;EACDA,aAAE,eACAA,aAAE,WAAW,UAAU,EACvBA,aAAE,cAAc,QAAQ,QAAQ,CACjC;EACD,GAAI,QAAQ,KACR,CACEA,aAAE,eACAA,aAAE,WAAW,MAAM,EACnBA,aAAE,cAAc,QAAQ,GAAG,CAC5B,CACF,GACD,EAAE;EACN,GAAI,QAAQ,UACR,CACEA,aAAE,eACAA,aAAE,WAAW,WAAW,EACxBA,aAAE,cAAc,QAAQ,QAAQ,CACjC,CACF,GACD,EAAE;EACN,GAAI,QAAQ,YAAY,OACpB,CACEA,aAAE,eACAA,aAAE,WAAW,YAAY,EACzBA,aAAE,eAAe,QAAQ,SAAS,CACnC,CACF,GACD,EAAE;EACP,CAAC,CACH,CACF,CACF;;;;;;AAOH,SAAS,sBACP,eAC8B;CAC9B,MAAM,aAAa,cAAc;AACjC,KAAI,CAAC,WAEH;AAEF,KAAIA,aAAE,iBAAiB,WAAW,CAChC,QAAO;AAET,KACEA,aAAE,kBAAkB,WAAW,IAC/BA,aAAE,iBAAiB,WAAW,SAAS,CAEvC,QAAO,WAAW"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"registerUseGTCallback.d.ts","sourceRoot":"","sources":["../../../../src/transform/registration/callbacks/registerUseGTCallback.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAItD;;;GAGG;AACH,wBAAgB,qBAAqB,CAAC,EACpC,UAAU,EACV,KAAK,EACL,OAAO,EACP,OAAO,EACP,EAAE,EACF,QAAQ,EACR,IAAI,EACJ,MAAM,GACP,EAAE;IACD,UAAU,EAAE,MAAM,CAAC;IACnB,KAAK,EAAE,cAAc,CAAC;IACtB,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB,GAAG,IAAI,
|
|
1
|
+
{"version":3,"file":"registerUseGTCallback.d.ts","sourceRoot":"","sources":["../../../../src/transform/registration/callbacks/registerUseGTCallback.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAItD;;;GAGG;AACH,wBAAgB,qBAAqB,CAAC,EACpC,UAAU,EACV,KAAK,EACL,OAAO,EACP,OAAO,EACP,EAAE,EACF,QAAQ,EACR,IAAI,EACJ,MAAM,GACP,EAAE;IACD,UAAU,EAAE,MAAM,CAAC;IACnB,KAAK,EAAE,cAAc,CAAC;IACtB,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB,GAAG,IAAI,CA0BP"}
|
|
@@ -8,7 +8,6 @@ const require_utils_calculateHash = require("../../../utils/calculateHash.js");
|
|
|
8
8
|
function registerUseGTCallback({ identifier, state, content, context, id, maxChars, hash, format }) {
|
|
9
9
|
hash ??= require_utils_calculateHash.default({
|
|
10
10
|
source: content,
|
|
11
|
-
id,
|
|
12
11
|
context,
|
|
13
12
|
maxChars,
|
|
14
13
|
dataFormat: format || "ICU"
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"registerUseGTCallback.js","names":["hashSource"],"sources":["../../../../src/transform/registration/callbacks/registerUseGTCallback.ts"],"sourcesContent":["import { TransformState } from '../../../state/types';\nimport hashSource from '../../../utils/calculateHash';\nimport type { DataFormat } from '@generaltranslation/format/types';\n\n/**\n * Track gt() function invocations\n * - Adds the translation content to the string collector\n */\nexport function registerUseGTCallback({\n identifier,\n state,\n content,\n context,\n id,\n maxChars,\n hash,\n format,\n}: {\n identifier: number;\n state: TransformState;\n content: string;\n context?: string;\n id?: string;\n maxChars?: number;\n hash?: string;\n format?: string;\n}): void {\n // Calculate hash for the call expression (skip if already set, including empty string for derive context)\n hash ??= hashSource({\n source: content,\n
|
|
1
|
+
{"version":3,"file":"registerUseGTCallback.js","names":["hashSource"],"sources":["../../../../src/transform/registration/callbacks/registerUseGTCallback.ts"],"sourcesContent":["import { TransformState } from '../../../state/types';\nimport hashSource from '../../../utils/calculateHash';\nimport type { DataFormat } from '@generaltranslation/format/types';\n\n/**\n * Track gt() function invocations\n * - Adds the translation content to the string collector\n */\nexport function registerUseGTCallback({\n identifier,\n state,\n content,\n context,\n id,\n maxChars,\n hash,\n format,\n}: {\n identifier: number;\n state: TransformState;\n content: string;\n context?: string;\n id?: string;\n maxChars?: number;\n hash?: string;\n format?: string;\n}): void {\n // Calculate hash for the call expression (skip if already set, including empty string for derive context)\n hash ??= hashSource({\n source: content,\n context,\n maxChars,\n dataFormat: (format || 'ICU') as DataFormat,\n });\n\n // Add the translation content to the string collector (under identifier mapping to useGT call)\n state.stringCollector.pushTranslationContent(identifier, {\n message: content,\n hash,\n id,\n context,\n maxChars,\n format,\n });\n\n // Increment counter so we can revisit this same invocation on second pass\n const counterId = state.stringCollector.incrementCounter();\n\n // Register the hash under this counter\n state.stringCollector.setTranslationHash(counterId, {\n hash,\n });\n}\n"],"mappings":";;;;;;;AAQA,SAAgB,sBAAsB,EACpC,YACA,OACA,SACA,SACA,IACA,UACA,MACA,UAUO;AAEP,UAASA,4BAAAA,QAAW;EAClB,QAAQ;EACR;EACA;EACA,YAAa,UAAU;EACxB,CAAC;AAGF,OAAM,gBAAgB,uBAAuB,YAAY;EACvD,SAAS;EACT;EACA;EACA;EACA;EACA;EACD,CAAC;CAGF,MAAM,YAAY,MAAM,gBAAgB,kBAAkB;AAG1D,OAAM,gBAAgB,mBAAmB,WAAW,EAClD,MACD,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"registerStandaloneTranslation.d.ts","sourceRoot":"","sources":["../../../src/transform/registration/registerStandaloneTranslation.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAInD;;GAEG;AACH,wBAAgB,6BAA6B,CAAC,EAC5C,KAAK,EACL,OAAO,EACP,OAAO,EACP,EAAE,EACF,QAAQ,EACR,IAAI,EACJ,MAAM,EACN,UAAU,GACX,EAAE;IACD,KAAK,EAAE,cAAc,CAAC;IACtB,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,UAAU,CAAC,EAAE,OAAO,CAAC;CACtB,GAAG,IAAI,
|
|
1
|
+
{"version":3,"file":"registerStandaloneTranslation.d.ts","sourceRoot":"","sources":["../../../src/transform/registration/registerStandaloneTranslation.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAInD;;GAEG;AACH,wBAAgB,6BAA6B,CAAC,EAC5C,KAAK,EACL,OAAO,EACP,OAAO,EACP,EAAE,EACF,QAAQ,EACR,IAAI,EACJ,MAAM,EACN,UAAU,GACX,EAAE;IACD,KAAK,EAAE,cAAc,CAAC;IACtB,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,UAAU,CAAC,EAAE,OAAO,CAAC;CACtB,GAAG,IAAI,CA2BP"}
|
|
@@ -7,7 +7,6 @@ const require_utils_calculateHash = require("../../utils/calculateHash.js");
|
|
|
7
7
|
function registerStandaloneTranslation({ state, content, context, id, maxChars, hash, format, injectHash }) {
|
|
8
8
|
hash ??= require_utils_calculateHash.default({
|
|
9
9
|
source: content,
|
|
10
|
-
...id && { id },
|
|
11
10
|
...context && { context },
|
|
12
11
|
...maxChars != null && { maxChars },
|
|
13
12
|
dataFormat: format || "ICU"
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"registerStandaloneTranslation.js","names":["hashSource"],"sources":["../../../src/transform/registration/registerStandaloneTranslation.ts"],"sourcesContent":["import { TransformState } from '../../state/types';\nimport hashSource from '../../utils/calculateHash';\nimport type { DataFormat } from '@generaltranslation/format/types';\n\n/**\n * Track standalone string translation invocations such as t() and msg().\n */\nexport function registerStandaloneTranslation({\n state,\n content,\n context,\n id,\n maxChars,\n hash,\n format,\n injectHash,\n}: {\n state: TransformState;\n content: string;\n context?: string;\n id?: string;\n maxChars?: number;\n hash?: string;\n format?: string;\n injectHash?: boolean;\n}): void {\n hash ??= hashSource({\n source: content,\n ...(
|
|
1
|
+
{"version":3,"file":"registerStandaloneTranslation.js","names":["hashSource"],"sources":["../../../src/transform/registration/registerStandaloneTranslation.ts"],"sourcesContent":["import { TransformState } from '../../state/types';\nimport hashSource from '../../utils/calculateHash';\nimport type { DataFormat } from '@generaltranslation/format/types';\n\n/**\n * Track standalone string translation invocations such as t() and msg().\n */\nexport function registerStandaloneTranslation({\n state,\n content,\n context,\n id,\n maxChars,\n hash,\n format,\n injectHash,\n}: {\n state: TransformState;\n content: string;\n context?: string;\n id?: string;\n maxChars?: number;\n hash?: string;\n format?: string;\n injectHash?: boolean;\n}): void {\n hash ??= hashSource({\n source: content,\n ...(context && { context }),\n ...(maxChars != null && { maxChars }),\n dataFormat: (format || 'ICU') as DataFormat,\n });\n\n state.stringCollector.pushRuntimeOnlyContent({\n message: content,\n hash,\n id,\n context,\n maxChars,\n format,\n });\n\n // Runtime-only entries, including msg() and t`...`, stop here. Only\n // standalone t() sets injectHash so the injection pass sees a matching slot.\n if (!injectHash) {\n return;\n }\n\n const counterId = state.stringCollector.incrementCounter();\n state.stringCollector.setTranslationHash(counterId, {\n hash,\n });\n}\n"],"mappings":";;;;;;AAOA,SAAgB,8BAA8B,EAC5C,OACA,SACA,SACA,IACA,UACA,MACA,QACA,cAUO;AACP,UAASA,4BAAAA,QAAW;EAClB,QAAQ;EACR,GAAI,WAAW,EAAE,SAAS;EAC1B,GAAI,YAAY,QAAQ,EAAE,UAAU;EACpC,YAAa,UAAU;EACxB,CAAC;AAEF,OAAM,gBAAgB,uBAAuB;EAC3C,SAAS;EACT;EACA;EACA;EACA;EACA;EACD,CAAC;AAIF,KAAI,CAAC,WACH;CAGF,MAAM,YAAY,MAAM,gBAAgB,kBAAkB;AAC1D,OAAM,gBAAgB,mBAAmB,WAAW,EAClD,MACD,CAAC"}
|
|
@@ -2,10 +2,9 @@ import type { DataFormat, JsxChildren } from '@generaltranslation/format/types';
|
|
|
2
2
|
/**
|
|
3
3
|
* Given jsx children, calculate hash
|
|
4
4
|
*/
|
|
5
|
-
export default function hashSource({ source, context,
|
|
5
|
+
export default function hashSource({ source, context, maxChars, dataFormat, }: {
|
|
6
6
|
source: JsxChildren | string;
|
|
7
7
|
context?: string;
|
|
8
|
-
id?: string;
|
|
9
8
|
maxChars?: number;
|
|
10
9
|
dataFormat: DataFormat;
|
|
11
10
|
}): string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"calculateHash.d.ts","sourceRoot":"","sources":["../../src/utils/calculateHash.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,UAAU,EAEV,WAAW,EAIZ,MAAM,kCAAkC,CAAC;AAG1C;;GAEG;AACH,MAAM,CAAC,OAAO,UAAU,UAAU,CAAC,EACjC,MAAM,EACN,OAAO,EACP,
|
|
1
|
+
{"version":3,"file":"calculateHash.d.ts","sourceRoot":"","sources":["../../src/utils/calculateHash.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,UAAU,EAEV,WAAW,EAIZ,MAAM,kCAAkC,CAAC;AAG1C;;GAEG;AACH,MAAM,CAAC,OAAO,UAAU,UAAU,CAAC,EACjC,MAAM,EACN,OAAO,EACP,QAAQ,EACR,UAAU,GACX,EAAE;IACD,MAAM,EAAE,WAAW,GAAG,MAAM,CAAC;IAC7B,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,UAAU,EAAE,UAAU,CAAC;CACxB,GAAG,MAAM,CAUT"}
|
|
@@ -8,11 +8,10 @@ let generaltranslation_id = require("generaltranslation/id");
|
|
|
8
8
|
/**
|
|
9
9
|
* Given jsx children, calculate hash
|
|
10
10
|
*/
|
|
11
|
-
function hashSource({ source, context,
|
|
11
|
+
function hashSource({ source, context, maxChars, dataFormat }) {
|
|
12
12
|
if (dataFormat === "ICU" || dataFormat === "I18NEXT") return (0, generaltranslation_id.hashSource)({
|
|
13
13
|
source,
|
|
14
14
|
context,
|
|
15
|
-
id,
|
|
16
15
|
maxChars,
|
|
17
16
|
dataFormat
|
|
18
17
|
});
|
|
@@ -20,7 +19,6 @@ function hashSource({ source, context, id, maxChars, dataFormat }) {
|
|
|
20
19
|
return (0, generaltranslation_id.hashSource)({
|
|
21
20
|
source,
|
|
22
21
|
context,
|
|
23
|
-
id,
|
|
24
22
|
maxChars,
|
|
25
23
|
dataFormat
|
|
26
24
|
});
|
|
@@ -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
|
|
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 dataFormat,\n}: {\n source: JsxChildren | string;\n context?: string;\n maxChars?: number;\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({ source, context, maxChars, dataFormat });\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, 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,cAMS;AAET,KAAI,eAAe,SAAS,eAAe,UACzC,SAAA,GAAA,sBAAA,YAAmB;EAAE;EAAQ;EAAS;EAAU;EAAY,CAAC;AAG/D,KAAI,eAAe,OAAO,CACxB,QAAO;AAET,SAAA,GAAA,sBAAA,YAAmB;EAAE;EAAQ;EAAS;EAAU;EAAY,CAAC;;;;;;AAW/D,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.25-odysseus.
|
|
3
|
+
"version": "1.3.25-odysseus.5",
|
|
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",
|
|
@@ -24,8 +24,8 @@
|
|
|
24
24
|
"@babel/traverse": "^7.23.0",
|
|
25
25
|
"@babel/types": "^7.23.0",
|
|
26
26
|
"unplugin": "^2.3.10",
|
|
27
|
-
"@generaltranslation/format": "0.1.2-odysseus.
|
|
28
|
-
"generaltranslation": "9.0.0-odysseus.
|
|
27
|
+
"@generaltranslation/format": "0.1.2-odysseus.1",
|
|
28
|
+
"generaltranslation": "9.0.0-odysseus.4"
|
|
29
29
|
},
|
|
30
30
|
"devDependencies": {
|
|
31
31
|
"@types/babel__core": "^7.20.0",
|