@generaltranslation/compiler 1.3.26 → 1.3.27
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 +6 -2
- package/dist/processing/collection/processCallExpression.js.map +1 -1
- package/dist/state/StringCollector.d.ts +4 -0
- package/dist/state/StringCollector.d.ts.map +1 -1
- package/dist/state/StringCollector.js.map +1 -1
- package/dist/transform/registration/callbacks/registerUseGTCallback.d.ts +2 -1
- package/dist/transform/registration/callbacks/registerUseGTCallback.d.ts.map +1 -1
- package/dist/transform/registration/callbacks/registerUseGTCallback.js +3 -1
- package/dist/transform/registration/callbacks/registerUseGTCallback.js.map +1 -1
- package/dist/transform/registration/registerStandaloneTranslation.d.ts +2 -1
- package/dist/transform/registration/registerStandaloneTranslation.d.ts.map +1 -1
- package/dist/transform/registration/registerStandaloneTranslation.js +3 -1
- package/dist/transform/registration/registerStandaloneTranslation.js.map +1 -1
- package/dist/transform/registration/registerTranslationComponent.d.ts +1 -0
- package/dist/transform/registration/registerTranslationComponent.d.ts.map +1 -1
- package/dist/transform/registration/registerTranslationComponent.js +2 -1
- package/dist/transform/registration/registerTranslationComponent.js.map +1 -1
- package/dist/transform/runtime-translate/buildRuntimeTranslateCalls.js +2 -0
- package/dist/transform/runtime-translate/buildRuntimeTranslateCalls.js.map +1 -1
- package/dist/transform/validation/validateTranslationComponentArgs.d.ts +1 -0
- package/dist/transform/validation/validateTranslationComponentArgs.d.ts.map +1 -1
- package/dist/transform/validation/validateTranslationComponentArgs.js +23 -0
- package/dist/transform/validation/validateTranslationComponentArgs.js.map +1 -1
- package/dist/transform/validation/validateTranslationFunction.d.ts +1 -0
- package/dist/transform/validation/validateTranslationFunction.d.ts.map +1 -1
- package/dist/transform/validation/validateTranslationFunction.js +23 -1
- package/dist/transform/validation/validateTranslationFunction.js.map +1 -1
- package/dist/utils/calculateHash.d.ts +2 -1
- package/dist/utils/calculateHash.d.ts.map +1 -1
- package/dist/utils/calculateHash.js +3 -1
- package/dist/utils/calculateHash.js.map +1 -1
- package/dist/utils/constants/gt/constants.d.ts +2 -1
- package/dist/utils/constants/gt/constants.d.ts.map +1 -1
- package/dist/utils/constants/gt/constants.js +1 -0
- package/dist/utils/constants/gt/constants.js.map +1 -1
- package/dist/utils/validation/validateExpressionIsBooleanLiteral.d.ts +8 -0
- package/dist/utils/validation/validateExpressionIsBooleanLiteral.d.ts.map +1 -0
- package/dist/utils/validation/validateExpressionIsBooleanLiteral.js +17 -0
- package/dist/utils/validation/validateExpressionIsBooleanLiteral.js.map +1 -0
- package/package.json +2 -2
|
@@ -74,6 +74,7 @@ function handleUseGTCallback(callExprPath, state, identifier) {
|
|
|
74
74
|
context: useGTCallbackParams.context,
|
|
75
75
|
id: useGTCallbackParams.id,
|
|
76
76
|
maxChars: useGTCallbackParams.maxChars,
|
|
77
|
+
requiresReview: useGTCallbackParams.requiresReview,
|
|
77
78
|
hash,
|
|
78
79
|
format: useGTCallbackParams.format
|
|
79
80
|
});
|
|
@@ -121,7 +122,7 @@ function handleReactInvocation(callExprPath, state) {
|
|
|
121
122
|
const { canonicalName, type } = require_transform_getTrackedVariable.getTrackedVariable(state.scopeTracker, namespaceName, functionName);
|
|
122
123
|
if (!canonicalName) return;
|
|
123
124
|
if (type !== "generaltranslation" || !require_utils_constants_gt_helpers.isTranslationComponent(canonicalName)) return;
|
|
124
|
-
const { errors, _hash, id, context, children, maxChars, hasDeriveContext } = require_transform_validation_validateTranslationComponentArgs.validateTranslationComponentArgs(callExprPath, canonicalName, state);
|
|
125
|
+
const { errors, _hash, id, context, children, maxChars, requiresReview, hasDeriveContext } = require_transform_validation_validateTranslationComponentArgs.validateTranslationComponentArgs(callExprPath, canonicalName, state);
|
|
125
126
|
if (errors.length > 0) {
|
|
126
127
|
state.errorTracker.addErrors(errors);
|
|
127
128
|
return;
|
|
@@ -131,13 +132,15 @@ function handleReactInvocation(callExprPath, state) {
|
|
|
131
132
|
...context && { context },
|
|
132
133
|
...id && { id },
|
|
133
134
|
...maxChars != null && { maxChars },
|
|
135
|
+
...requiresReview === true && { requiresReview: true },
|
|
134
136
|
dataFormat: "JSX"
|
|
135
137
|
});
|
|
136
138
|
if (state.debugManifest) state.debugManifest.set(hash, children ?? null);
|
|
137
139
|
require_transform_registration_registerTranslationComponent.registerTranslationComponent(state, hash, {
|
|
138
140
|
children,
|
|
139
141
|
id,
|
|
140
|
-
context
|
|
142
|
+
context,
|
|
143
|
+
requiresReview
|
|
141
144
|
});
|
|
142
145
|
}
|
|
143
146
|
/**
|
|
@@ -156,6 +159,7 @@ function handleStandaloneTranslation(callExprPath, state, { injectHash }) {
|
|
|
156
159
|
id: params.id,
|
|
157
160
|
context: params.context,
|
|
158
161
|
maxChars: params.maxChars,
|
|
162
|
+
requiresReview: params.requiresReview,
|
|
159
163
|
format: params.format,
|
|
160
164
|
injectHash
|
|
161
165
|
});
|
|
@@ -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,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A,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 requiresReview: useGTCallbackParams.requiresReview,\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 {\n errors,\n _hash,\n id,\n context,\n children,\n maxChars,\n requiresReview,\n 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 ...(requiresReview === true && { requiresReview: true }),\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, {\n children,\n id,\n context,\n requiresReview,\n });\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 requiresReview: params.requiresReview,\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,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AAc,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,gBAAgB,OAAO;EACvB,QAAQ,OAAO;EACf;EACD,CAAC"}
|
|
@@ -20,6 +20,8 @@ export interface TranslationContent {
|
|
|
20
20
|
maxChars?: number;
|
|
21
21
|
/** Optional format from options: t("text", {$format: "STRING"}) → "STRING" */
|
|
22
22
|
format?: string;
|
|
23
|
+
/** Optional requiresReview from options: t("text", {$requiresReview: true}) → true */
|
|
24
|
+
requiresReview?: boolean;
|
|
23
25
|
}
|
|
24
26
|
/**
|
|
25
27
|
* Content extracted from JSX translation components like <T>
|
|
@@ -33,6 +35,8 @@ export interface TranslationJsx {
|
|
|
33
35
|
id?: string;
|
|
34
36
|
/** Optional context from props */
|
|
35
37
|
context?: string;
|
|
38
|
+
/** Optional requiresReview from props */
|
|
39
|
+
requiresReview?: boolean;
|
|
36
40
|
}
|
|
37
41
|
/**
|
|
38
42
|
* Just a hash value for simple hash injection
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"StringCollector.d.ts","sourceRoot":"","sources":["../../src/state/StringCollector.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH;;GAEG;AACH,MAAM,WAAW,kBAAkB;IACjC,2DAA2D;IAC3D,OAAO,EAAE,MAAM,CAAC;IAChB,2CAA2C;IAC3C,IAAI,EAAE,MAAM,CAAC;IACb,yEAAyE;IACzE,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,yEAAyE;IACzE,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,qEAAqE;IACrE,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,8EAA8E;IAC9E,MAAM,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,qBAAqB,IAAI,kBAAkB,EAAE;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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,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"}
|
|
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 /** Optional requiresReview from options: t(\"text\", {$requiresReview: true}) → true */\n requiresReview?: boolean;\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 /** Optional requiresReview from props */\n requiresReview?: boolean;\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":";;;;;AA6DA,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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;AAC9B,OAAI,IAAI,OAAO,IAAI,EAAE,MAAM;AAC3B,UAAO;qBACN,IAAI,KAAmC,CAAC;AAC3C,OAAK,iBAAiB,OAAO,QAC3B,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"}
|
|
@@ -3,13 +3,14 @@ import { TransformState } from '../../../state/types';
|
|
|
3
3
|
* Track gt() function invocations
|
|
4
4
|
* - Adds the translation content to the string collector
|
|
5
5
|
*/
|
|
6
|
-
export declare function registerUseGTCallback({ identifier, state, content, context, id, maxChars, hash, format, }: {
|
|
6
|
+
export declare function registerUseGTCallback({ identifier, state, content, context, id, maxChars, requiresReview, hash, format, }: {
|
|
7
7
|
identifier: number;
|
|
8
8
|
state: TransformState;
|
|
9
9
|
content: string;
|
|
10
10
|
context?: string;
|
|
11
11
|
id?: string;
|
|
12
12
|
maxChars?: number;
|
|
13
|
+
requiresReview?: boolean;
|
|
13
14
|
hash?: string;
|
|
14
15
|
format?: string;
|
|
15
16
|
}): void;
|
|
@@ -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,cAAc,EACd,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,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB,GAAG,IAAI,CA6BP"}
|
|
@@ -5,12 +5,13 @@ const require_utils_calculateHash = require("../../../utils/calculateHash.js");
|
|
|
5
5
|
* Track gt() function invocations
|
|
6
6
|
* - Adds the translation content to the string collector
|
|
7
7
|
*/
|
|
8
|
-
function registerUseGTCallback({ identifier, state, content, context, id, maxChars, hash, format }) {
|
|
8
|
+
function registerUseGTCallback({ identifier, state, content, context, id, maxChars, requiresReview, hash, format }) {
|
|
9
9
|
hash ??= require_utils_calculateHash.default({
|
|
10
10
|
source: content,
|
|
11
11
|
id,
|
|
12
12
|
context,
|
|
13
13
|
maxChars,
|
|
14
|
+
requiresReview,
|
|
14
15
|
dataFormat: format || "ICU"
|
|
15
16
|
});
|
|
16
17
|
state.stringCollector.pushTranslationContent(identifier, {
|
|
@@ -19,6 +20,7 @@ function registerUseGTCallback({ identifier, state, content, context, id, maxCha
|
|
|
19
20
|
id,
|
|
20
21
|
context,
|
|
21
22
|
maxChars,
|
|
23
|
+
requiresReview,
|
|
22
24
|
format
|
|
23
25
|
});
|
|
24
26
|
const counterId = state.stringCollector.incrementCounter();
|
|
@@ -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 id,\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,
|
|
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 requiresReview,\n hash,\n format,\n}: {\n identifier: number;\n state: TransformState;\n content: string;\n context?: string;\n id?: string;\n maxChars?: number;\n requiresReview?: boolean;\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 id,\n context,\n maxChars,\n requiresReview,\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 requiresReview,\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,gBACA,MACA,UAWO;AAEP,UAASA,4BAAAA,QAAW;EAClB,QAAQ;EACR;EACA;EACA;EACA;EACA,YAAa,UAAU;EACxB,CAAC;AAGF,OAAM,gBAAgB,uBAAuB,YAAY;EACvD,SAAS;EACT;EACA;EACA;EACA;EACA;EACA;EACD,CAAC;CAGF,MAAM,YAAY,MAAM,gBAAgB,kBAAkB;AAG1D,OAAM,gBAAgB,mBAAmB,WAAW,EAClD,MACD,CAAC"}
|
|
@@ -2,12 +2,13 @@ import { TransformState } from '../../state/types';
|
|
|
2
2
|
/**
|
|
3
3
|
* Track standalone string translation invocations such as t() and msg().
|
|
4
4
|
*/
|
|
5
|
-
export declare function registerStandaloneTranslation({ state, content, context, id, maxChars, hash, format, injectHash, }: {
|
|
5
|
+
export declare function registerStandaloneTranslation({ state, content, context, id, maxChars, requiresReview, hash, format, injectHash, }: {
|
|
6
6
|
state: TransformState;
|
|
7
7
|
content: string;
|
|
8
8
|
context?: string;
|
|
9
9
|
id?: string;
|
|
10
10
|
maxChars?: number;
|
|
11
|
+
requiresReview?: boolean;
|
|
11
12
|
hash?: string;
|
|
12
13
|
format?: string;
|
|
13
14
|
injectHash?: boolean;
|
|
@@ -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,cAAc,EACd,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,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,UAAU,CAAC,EAAE,OAAO,CAAC;CACtB,GAAG,IAAI,CA8BP"}
|
|
@@ -4,12 +4,13 @@ const require_utils_calculateHash = require("../../utils/calculateHash.js");
|
|
|
4
4
|
/**
|
|
5
5
|
* Track standalone string translation invocations such as t() and msg().
|
|
6
6
|
*/
|
|
7
|
-
function registerStandaloneTranslation({ state, content, context, id, maxChars, hash, format, injectHash }) {
|
|
7
|
+
function registerStandaloneTranslation({ state, content, context, id, maxChars, requiresReview, hash, format, injectHash }) {
|
|
8
8
|
hash ??= require_utils_calculateHash.default({
|
|
9
9
|
source: content,
|
|
10
10
|
...id && { id },
|
|
11
11
|
...context && { context },
|
|
12
12
|
...maxChars != null && { maxChars },
|
|
13
|
+
...requiresReview === true && { requiresReview: true },
|
|
13
14
|
dataFormat: format || "ICU"
|
|
14
15
|
});
|
|
15
16
|
state.stringCollector.pushRuntimeOnlyContent({
|
|
@@ -18,6 +19,7 @@ function registerStandaloneTranslation({ state, content, context, id, maxChars,
|
|
|
18
19
|
id,
|
|
19
20
|
context,
|
|
20
21
|
maxChars,
|
|
22
|
+
requiresReview,
|
|
21
23
|
format
|
|
22
24
|
});
|
|
23
25
|
if (!injectHash) return;
|
|
@@ -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 ...(id && { id }),\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,
|
|
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 requiresReview,\n hash,\n format,\n injectHash,\n}: {\n state: TransformState;\n content: string;\n context?: string;\n id?: string;\n maxChars?: number;\n requiresReview?: boolean;\n hash?: string;\n format?: string;\n injectHash?: boolean;\n}): void {\n hash ??= hashSource({\n source: content,\n ...(id && { id }),\n ...(context && { context }),\n ...(maxChars != null && { maxChars }),\n ...(requiresReview === true && { requiresReview: true }),\n dataFormat: (format || 'ICU') as DataFormat,\n });\n\n state.stringCollector.pushRuntimeOnlyContent({\n message: content,\n hash,\n id,\n context,\n maxChars,\n requiresReview,\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,gBACA,MACA,QACA,cAWO;AACP,UAASA,4BAAAA,QAAW;EAClB,QAAQ;EACR,GAAI,MAAM,EAAE,IAAI;EAChB,GAAI,WAAW,EAAE,SAAS;EAC1B,GAAI,YAAY,QAAQ,EAAE,UAAU;EACpC,GAAI,mBAAmB,QAAQ,EAAE,gBAAgB,MAAM;EACvD,YAAa,UAAU;EACxB,CAAC;AAEF,OAAM,gBAAgB,uBAAuB;EAC3C,SAAS;EACT;EACA;EACA;EACA;EACA;EACA;EACD,CAAC;AAIF,KAAI,CAAC,WACH;CAGF,MAAM,YAAY,MAAM,gBAAgB,kBAAkB;AAC1D,OAAM,gBAAgB,mBAAmB,WAAW,EAClD,MACD,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"registerTranslationComponent.d.ts","sourceRoot":"","sources":["../../../src/transform/registration/registerTranslationComponent.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAEnD;;;GAGG;AACH,wBAAgB,4BAA4B,CAC1C,KAAK,EAAE,cAAc,EACrB,IAAI,EAAE,MAAM,EACZ,OAAO,CAAC,EAAE;IACR,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,OAAO,CAAC,EAAE,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"registerTranslationComponent.d.ts","sourceRoot":"","sources":["../../../src/transform/registration/registerTranslationComponent.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAEnD;;;GAGG;AACH,wBAAgB,4BAA4B,CAC1C,KAAK,EAAE,cAAc,EACrB,IAAI,EAAE,MAAM,EACZ,OAAO,CAAC,EAAE;IACR,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,cAAc,CAAC,EAAE,OAAO,CAAC;CAC1B,GACA,IAAI,CAWN"}
|
|
@@ -10,7 +10,8 @@ function registerTranslationComponent(state, hash, options) {
|
|
|
10
10
|
hash,
|
|
11
11
|
children: options === null || options === void 0 ? void 0 : options.children,
|
|
12
12
|
id: options === null || options === void 0 ? void 0 : options.id,
|
|
13
|
-
context: options === null || options === void 0 ? void 0 : options.context
|
|
13
|
+
context: options === null || options === void 0 ? void 0 : options.context,
|
|
14
|
+
requiresReview: options === null || options === void 0 ? void 0 : options.requiresReview
|
|
14
15
|
});
|
|
15
16
|
}
|
|
16
17
|
//#endregion
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"registerTranslationComponent.js","names":[],"sources":["../../../src/transform/registration/registerTranslationComponent.ts"],"sourcesContent":["import { TransformState } from '../../state/types';\n\n/**\n * Track gt() function invocations\n * - Adds the translation content to the string collector\n */\nexport function registerTranslationComponent(\n state: TransformState,\n hash: string,\n options?: {\n children?: unknown;\n id?: string;\n context?: string;\n }\n): void {\n // Increment counter\n const identifier = state.stringCollector.incrementCounter();\n // Add the translation content to the string collector\n state.stringCollector.setTranslationJsx(identifier, {\n hash,\n children: options?.children,\n id: options?.id,\n context: options?.context,\n });\n}\n"],"mappings":";;;;;;AAMA,SAAgB,6BACd,OACA,MACA,
|
|
1
|
+
{"version":3,"file":"registerTranslationComponent.js","names":[],"sources":["../../../src/transform/registration/registerTranslationComponent.ts"],"sourcesContent":["import { TransformState } from '../../state/types';\n\n/**\n * Track gt() function invocations\n * - Adds the translation content to the string collector\n */\nexport function registerTranslationComponent(\n state: TransformState,\n hash: string,\n options?: {\n children?: unknown;\n id?: string;\n context?: string;\n requiresReview?: boolean;\n }\n): void {\n // Increment counter\n const identifier = state.stringCollector.incrementCounter();\n // Add the translation content to the string collector\n state.stringCollector.setTranslationJsx(identifier, {\n hash,\n children: options?.children,\n id: options?.id,\n context: options?.context,\n requiresReview: options?.requiresReview,\n });\n}\n"],"mappings":";;;;;;AAMA,SAAgB,6BACd,OACA,MACA,SAMM;CAEN,MAAM,aAAa,MAAM,gBAAgB,kBAAkB;AAE3D,OAAM,gBAAgB,kBAAkB,YAAY;EAClD;EACA,UAAA,YAAA,QAAA,YAAA,KAAA,IAAA,KAAA,IAAU,QAAS;EACnB,IAAA,YAAA,QAAA,YAAA,KAAA,IAAA,KAAA,IAAI,QAAS;EACb,SAAA,YAAA,QAAA,YAAA,KAAA,IAAA,KAAA,IAAS,QAAS;EAClB,gBAAA,YAAA,QAAA,YAAA,KAAA,IAAA,KAAA,IAAgB,QAAS;EAC1B,CAAC"}
|
|
@@ -24,6 +24,7 @@ function buildStringCall(entry) {
|
|
|
24
24
|
if (entry.hash !== void 0) properties.push(_babel_types.objectProperty(_babel_types.stringLiteral("$_hash"), _babel_types.stringLiteral(entry.hash)));
|
|
25
25
|
if (entry.id !== void 0) properties.push(_babel_types.objectProperty(_babel_types.stringLiteral("$id"), _babel_types.stringLiteral(entry.id)));
|
|
26
26
|
if (entry.maxChars !== void 0) properties.push(_babel_types.objectProperty(_babel_types.stringLiteral("$maxChars"), _babel_types.numericLiteral(entry.maxChars)));
|
|
27
|
+
if (entry.requiresReview === true) properties.push(_babel_types.objectProperty(_babel_types.stringLiteral("$requiresReview"), _babel_types.booleanLiteral(true)));
|
|
27
28
|
if (entry.format !== void 0) properties.push(_babel_types.objectProperty(_babel_types.stringLiteral("$format"), _babel_types.stringLiteral(entry.format)));
|
|
28
29
|
return _babel_types.callExpression(_babel_types.identifier("GtInternalRuntimeTranslateString"), [_babel_types.stringLiteral(entry.message), _babel_types.objectExpression(properties)]);
|
|
29
30
|
}
|
|
@@ -34,6 +35,7 @@ function buildJsxCall(entry) {
|
|
|
34
35
|
const properties = [];
|
|
35
36
|
if (entry.context !== void 0) properties.push(_babel_types.objectProperty(_babel_types.stringLiteral("$context"), _babel_types.stringLiteral(entry.context)));
|
|
36
37
|
if (entry.id !== void 0) properties.push(_babel_types.objectProperty(_babel_types.stringLiteral("$id"), _babel_types.stringLiteral(entry.id)));
|
|
38
|
+
if (entry.requiresReview === true) properties.push(_babel_types.objectProperty(_babel_types.stringLiteral("$requiresReview"), _babel_types.booleanLiteral(true)));
|
|
37
39
|
const childrenNode = entry.children != null ? _babel_types.valueToNode(entry.children) : _babel_types.nullLiteral();
|
|
38
40
|
return _babel_types.callExpression(_babel_types.identifier("GtInternalRuntimeTranslateJsx"), [childrenNode, _babel_types.objectExpression(properties)]);
|
|
39
41
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"buildRuntimeTranslateCalls.js","names":["t"],"sources":["../../../src/transform/runtime-translate/buildRuntimeTranslateCalls.ts"],"sourcesContent":["import * as t from '@babel/types';\nimport {\n TranslationContent,\n TranslationJsx,\n} from '../../state/StringCollector';\nimport {\n GT_OTHER_FUNCTIONS,\n USEGT_CALLBACK_OPTIONS,\n} from '../../utils/constants/gt/constants';\n\n/**\n * Build a single `await Promise.all([...])` expression statement containing\n * runtime translate calls for all extracted strings and JSX content.\n */\nexport function buildRuntimeTranslateCalls({\n strings,\n jsx,\n}: {\n strings: TranslationContent[];\n jsx: TranslationJsx[];\n}): t.ExpressionStatement {\n const calls: t.CallExpression[] = [];\n\n // Build GtInternalRuntimeTranslateString calls\n for (const entry of strings) {\n calls.push(buildStringCall(entry));\n }\n\n // Build GtInternalRuntimeTranslateJsx calls\n for (const entry of jsx) {\n calls.push(buildJsxCall(entry));\n }\n\n // Wrap in await Promise.all([...])\n const promiseAll = t.callExpression(\n t.memberExpression(t.identifier('Promise'), t.identifier('all')),\n [t.arrayExpression(calls)]\n );\n\n return t.expressionStatement(t.awaitExpression(promiseAll));\n}\n\n/**\n * Build a single GtInternalRuntimeTranslateString(message, options) call\n */\nfunction buildStringCall(entry: TranslationContent): t.CallExpression {\n const properties: t.ObjectProperty[] = [];\n\n if (entry.context !== undefined) {\n properties.push(\n t.objectProperty(\n t.stringLiteral(USEGT_CALLBACK_OPTIONS.$context),\n t.stringLiteral(entry.context)\n )\n );\n }\n\n if (entry.hash !== undefined) {\n properties.push(\n t.objectProperty(\n t.stringLiteral(USEGT_CALLBACK_OPTIONS.$_hash),\n t.stringLiteral(entry.hash)\n )\n );\n }\n\n if (entry.id !== undefined) {\n properties.push(\n t.objectProperty(\n t.stringLiteral(USEGT_CALLBACK_OPTIONS.$id),\n t.stringLiteral(entry.id)\n )\n );\n }\n\n if (entry.maxChars !== undefined) {\n properties.push(\n t.objectProperty(\n t.stringLiteral(USEGT_CALLBACK_OPTIONS.$maxChars),\n t.numericLiteral(entry.maxChars)\n )\n );\n }\n\n if (entry.format !== undefined) {\n properties.push(\n t.objectProperty(\n t.stringLiteral(USEGT_CALLBACK_OPTIONS.$format),\n t.stringLiteral(entry.format)\n )\n );\n }\n\n return t.callExpression(\n t.identifier(GT_OTHER_FUNCTIONS.GtInternalRuntimeTranslateString),\n [t.stringLiteral(entry.message), t.objectExpression(properties)]\n );\n}\n\n/**\n * Build a single GtInternalRuntimeTranslateJsx(children, options) call\n */\nfunction buildJsxCall(entry: TranslationJsx): t.CallExpression {\n const properties: t.ObjectProperty[] = [];\n\n if (entry.context !== undefined) {\n properties.push(\n t.objectProperty(\n t.stringLiteral(USEGT_CALLBACK_OPTIONS.$context),\n t.stringLiteral(entry.context)\n )\n );\n }\n\n if (entry.id !== undefined) {\n properties.push(\n t.objectProperty(\n t.stringLiteral(USEGT_CALLBACK_OPTIONS.$id),\n t.stringLiteral(entry.id)\n )\n );\n }\n\n // Serialize children to AST — handles arrays, objects, strings, numbers, null\n const childrenNode =\n entry.children != null ? t.valueToNode(entry.children) : t.nullLiteral();\n\n return t.callExpression(\n t.identifier(GT_OTHER_FUNCTIONS.GtInternalRuntimeTranslateJsx),\n [childrenNode, t.objectExpression(properties)]\n );\n}\n"],"mappings":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C7D,MAAM,aAAiC,EAAE;AAEzC,KAAI,MAAM,YAAY,KAAA,EACpB,YAAW,KACTA,aAAE,eACAA,aAAE,cAAA,WAA8C,EAChDA,aAAE,cAAc,MAAM,QAAQ,CAC/B,CACF;AAGH,KAAI,MAAM,OAAO,KAAA,EACf,YAAW,KACTA,aAAE,eACAA,aAAE,cAAA,MAAyC,EAC3CA,aAAE,cAAc,MAAM,GAAG,CAC1B,CACF;CAIH,MAAM,eACJ,MAAM,YAAY,OAAOA,aAAE,YAAY,MAAM,SAAS,GAAGA,aAAE,aAAa;AAE1E,QAAOA,aAAE,eACPA,aAAE,WAAA,gCAA4D,EAC9D,CAAC,cAAcA,aAAE,iBAAiB,WAAW,CAAC,CAC/C"}
|
|
1
|
+
{"version":3,"file":"buildRuntimeTranslateCalls.js","names":["t"],"sources":["../../../src/transform/runtime-translate/buildRuntimeTranslateCalls.ts"],"sourcesContent":["import * as t from '@babel/types';\nimport {\n TranslationContent,\n TranslationJsx,\n} from '../../state/StringCollector';\nimport {\n GT_OTHER_FUNCTIONS,\n USEGT_CALLBACK_OPTIONS,\n} from '../../utils/constants/gt/constants';\n\n/**\n * Build a single `await Promise.all([...])` expression statement containing\n * runtime translate calls for all extracted strings and JSX content.\n */\nexport function buildRuntimeTranslateCalls({\n strings,\n jsx,\n}: {\n strings: TranslationContent[];\n jsx: TranslationJsx[];\n}): t.ExpressionStatement {\n const calls: t.CallExpression[] = [];\n\n // Build GtInternalRuntimeTranslateString calls\n for (const entry of strings) {\n calls.push(buildStringCall(entry));\n }\n\n // Build GtInternalRuntimeTranslateJsx calls\n for (const entry of jsx) {\n calls.push(buildJsxCall(entry));\n }\n\n // Wrap in await Promise.all([...])\n const promiseAll = t.callExpression(\n t.memberExpression(t.identifier('Promise'), t.identifier('all')),\n [t.arrayExpression(calls)]\n );\n\n return t.expressionStatement(t.awaitExpression(promiseAll));\n}\n\n/**\n * Build a single GtInternalRuntimeTranslateString(message, options) call\n */\nfunction buildStringCall(entry: TranslationContent): t.CallExpression {\n const properties: t.ObjectProperty[] = [];\n\n if (entry.context !== undefined) {\n properties.push(\n t.objectProperty(\n t.stringLiteral(USEGT_CALLBACK_OPTIONS.$context),\n t.stringLiteral(entry.context)\n )\n );\n }\n\n if (entry.hash !== undefined) {\n properties.push(\n t.objectProperty(\n t.stringLiteral(USEGT_CALLBACK_OPTIONS.$_hash),\n t.stringLiteral(entry.hash)\n )\n );\n }\n\n if (entry.id !== undefined) {\n properties.push(\n t.objectProperty(\n t.stringLiteral(USEGT_CALLBACK_OPTIONS.$id),\n t.stringLiteral(entry.id)\n )\n );\n }\n\n if (entry.maxChars !== undefined) {\n properties.push(\n t.objectProperty(\n t.stringLiteral(USEGT_CALLBACK_OPTIONS.$maxChars),\n t.numericLiteral(entry.maxChars)\n )\n );\n }\n\n if (entry.requiresReview === true) {\n properties.push(\n t.objectProperty(\n t.stringLiteral(USEGT_CALLBACK_OPTIONS.$requiresReview),\n t.booleanLiteral(true)\n )\n );\n }\n\n if (entry.format !== undefined) {\n properties.push(\n t.objectProperty(\n t.stringLiteral(USEGT_CALLBACK_OPTIONS.$format),\n t.stringLiteral(entry.format)\n )\n );\n }\n\n return t.callExpression(\n t.identifier(GT_OTHER_FUNCTIONS.GtInternalRuntimeTranslateString),\n [t.stringLiteral(entry.message), t.objectExpression(properties)]\n );\n}\n\n/**\n * Build a single GtInternalRuntimeTranslateJsx(children, options) call\n */\nfunction buildJsxCall(entry: TranslationJsx): t.CallExpression {\n const properties: t.ObjectProperty[] = [];\n\n if (entry.context !== undefined) {\n properties.push(\n t.objectProperty(\n t.stringLiteral(USEGT_CALLBACK_OPTIONS.$context),\n t.stringLiteral(entry.context)\n )\n );\n }\n\n if (entry.id !== undefined) {\n properties.push(\n t.objectProperty(\n t.stringLiteral(USEGT_CALLBACK_OPTIONS.$id),\n t.stringLiteral(entry.id)\n )\n );\n }\n\n // requiresReview is part of the review-aware hash; without it the runtime\n // recomputes a non-review hash and misses the cached entry\n if (entry.requiresReview === true) {\n properties.push(\n t.objectProperty(\n t.stringLiteral(USEGT_CALLBACK_OPTIONS.$requiresReview),\n t.booleanLiteral(true)\n )\n );\n }\n\n // Serialize children to AST — handles arrays, objects, strings, numbers, null\n const childrenNode =\n entry.children != null ? t.valueToNode(entry.children) : t.nullLiteral();\n\n return t.callExpression(\n t.identifier(GT_OTHER_FUNCTIONS.GtInternalRuntimeTranslateJsx),\n [childrenNode, t.objectExpression(properties)]\n );\n}\n"],"mappings":";;;;;;;;;;AAcA,SAAgB,2BAA2B,EACzC,SACA,OAIwB;CACxB,MAAM,QAA4B,EAAE;AAGpC,MAAK,MAAM,SAAS,QAClB,OAAM,KAAK,gBAAgB,MAAM,CAAC;AAIpC,MAAK,MAAM,SAAS,IAClB,OAAM,KAAK,aAAa,MAAM,CAAC;CAIjC,MAAM,aAAaA,aAAE,eACnBA,aAAE,iBAAiBA,aAAE,WAAW,UAAU,EAAEA,aAAE,WAAW,MAAM,CAAC,EAChE,CAACA,aAAE,gBAAgB,MAAM,CAAC,CAC3B;AAED,QAAOA,aAAE,oBAAoBA,aAAE,gBAAgB,WAAW,CAAC;;;;;AAM7D,SAAS,gBAAgB,OAA6C;CACpE,MAAM,aAAiC,EAAE;AAEzC,KAAI,MAAM,YAAY,KAAA,EACpB,YAAW,KACTA,aAAE,eACAA,aAAE,cAAA,WAA8C,EAChDA,aAAE,cAAc,MAAM,QAAQ,CAC/B,CACF;AAGH,KAAI,MAAM,SAAS,KAAA,EACjB,YAAW,KACTA,aAAE,eACAA,aAAE,cAAA,SAA4C,EAC9CA,aAAE,cAAc,MAAM,KAAK,CAC5B,CACF;AAGH,KAAI,MAAM,OAAO,KAAA,EACf,YAAW,KACTA,aAAE,eACAA,aAAE,cAAA,MAAyC,EAC3CA,aAAE,cAAc,MAAM,GAAG,CAC1B,CACF;AAGH,KAAI,MAAM,aAAa,KAAA,EACrB,YAAW,KACTA,aAAE,eACAA,aAAE,cAAA,YAA+C,EACjDA,aAAE,eAAe,MAAM,SAAS,CACjC,CACF;AAGH,KAAI,MAAM,mBAAmB,KAC3B,YAAW,KACTA,aAAE,eACAA,aAAE,cAAA,kBAAqD,EACvDA,aAAE,eAAe,KAAK,CACvB,CACF;AAGH,KAAI,MAAM,WAAW,KAAA,EACnB,YAAW,KACTA,aAAE,eACAA,aAAE,cAAA,UAA6C,EAC/CA,aAAE,cAAc,MAAM,OAAO,CAC9B,CACF;AAGH,QAAOA,aAAE,eACPA,aAAE,WAAA,mCAA+D,EACjE,CAACA,aAAE,cAAc,MAAM,QAAQ,EAAEA,aAAE,iBAAiB,WAAW,CAAC,CACjE;;;;;AAMH,SAAS,aAAa,OAAyC;CAC7D,MAAM,aAAiC,EAAE;AAEzC,KAAI,MAAM,YAAY,KAAA,EACpB,YAAW,KACTA,aAAE,eACAA,aAAE,cAAA,WAA8C,EAChDA,aAAE,cAAc,MAAM,QAAQ,CAC/B,CACF;AAGH,KAAI,MAAM,OAAO,KAAA,EACf,YAAW,KACTA,aAAE,eACAA,aAAE,cAAA,MAAyC,EAC3CA,aAAE,cAAc,MAAM,GAAG,CAC1B,CACF;AAKH,KAAI,MAAM,mBAAmB,KAC3B,YAAW,KACTA,aAAE,eACAA,aAAE,cAAA,kBAAqD,EACvDA,aAAE,eAAe,KAAK,CACvB,CACF;CAIH,MAAM,eACJ,MAAM,YAAY,OAAOA,aAAE,YAAY,MAAM,SAAS,GAAGA,aAAE,aAAa;AAE1E,QAAOA,aAAE,eACPA,aAAE,WAAA,gCAA4D,EAC9D,CAAC,cAAcA,aAAE,iBAAiB,WAAW,CAAC,CAC/C"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validateTranslationComponentArgs.d.ts","sourceRoot":"","sources":["../../../src/transform/validation/validateTranslationComponentArgs.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAEnD,OAAO,KAAK,CAAC,MAAM,cAAc,CAAC;AAClC,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAGhD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,kCAAkC,CAAC;
|
|
1
|
+
{"version":3,"file":"validateTranslationComponentArgs.d.ts","sourceRoot":"","sources":["../../../src/transform/validation/validateTranslationComponentArgs.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAEnD,OAAO,KAAK,CAAC,MAAM,cAAc,CAAC;AAClC,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAGhD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,kCAAkC,CAAC;AAOpE;;GAEG;AACH,wBAAgB,gCAAgC,CAC9C,YAAY,EAAE,QAAQ,CAAC,CAAC,CAAC,cAAc,CAAC,EACxC,aAAa,EAAE,MAAM,EACrB,KAAK,EAAE,cAAc,GACpB;IACD,MAAM,EAAE,MAAM,EAAE,CAAC;IACjB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,QAAQ,CAAC,EAAE,WAAW,CAAC;IACvB,gBAAgB,CAAC,EAAE,OAAO,CAAC;CAC5B,CAwCA;AAqED;;GAEG;AACH,wBAAgB,wBAAwB,CACtC,QAAQ,EAAE,QAAQ,CAAC,CAAC,CAAC,gBAAgB,CAAC,EACtC,KAAK,EAAE,cAAc,GACpB;IACD,MAAM,EAAE,MAAM,EAAE,CAAC;IACjB,KAAK,CAAC,EAAE,WAAW,CAAC;IACpB,aAAa,CAAC,EAAE,OAAO,CAAC;CACzB,CAkCA"}
|
|
@@ -8,6 +8,7 @@ const require_utils_validation_validateChildrenFromObjectExpression = require(".
|
|
|
8
8
|
const require_transform_jsx_children_constructJsxChildren = require("../jsx-children/constructJsxChildren.js");
|
|
9
9
|
require("../jsx-children/index.js");
|
|
10
10
|
const require_utils_validation_validateExpressionIsNumericLiteral = require("../../utils/validation/validateExpressionIsNumericLiteral.js");
|
|
11
|
+
const require_utils_validation_validateExpressionIsBooleanLiteral = require("../../utils/validation/validateExpressionIsBooleanLiteral.js");
|
|
11
12
|
let _babel_types = require("@babel/types");
|
|
12
13
|
_babel_types = require_runtime.__toESM(_babel_types);
|
|
13
14
|
//#region src/transform/validation/validateTranslationComponentArgs.ts
|
|
@@ -39,6 +40,9 @@ function validateTComponentArgs(argsPath, state) {
|
|
|
39
40
|
const maxCharsValidation = validateNumberProperty(args, "maxChars");
|
|
40
41
|
errors.push(...maxCharsValidation.errors);
|
|
41
42
|
const maxChars = maxCharsValidation.value;
|
|
43
|
+
const requiresReviewValidation = validateBooleanProperty(args, "requiresReview");
|
|
44
|
+
errors.push(...requiresReviewValidation.errors);
|
|
45
|
+
const requiresReview = requiresReviewValidation.value;
|
|
42
46
|
const hashValidation = validateStringProperty(args, "_hash");
|
|
43
47
|
errors.push(...hashValidation.errors);
|
|
44
48
|
const _hash = hashValidation.value;
|
|
@@ -50,6 +54,7 @@ function validateTComponentArgs(argsPath, state) {
|
|
|
50
54
|
context,
|
|
51
55
|
_hash,
|
|
52
56
|
maxChars,
|
|
57
|
+
requiresReview,
|
|
53
58
|
children: childrenValidation.value,
|
|
54
59
|
hasDeriveContext: contextValidation.hasDeriveExpression || childrenValidation.hasAutoderive
|
|
55
60
|
};
|
|
@@ -179,6 +184,24 @@ function getNumberLiteralFromExpression(expr) {
|
|
|
179
184
|
function validateNumberLiteralIsInteger(value) {
|
|
180
185
|
return Number.isInteger(value);
|
|
181
186
|
}
|
|
187
|
+
/**
|
|
188
|
+
* Will validate and retrieve property from object expression and also try prefixing with a $.
|
|
189
|
+
* Only boolean literals are accepted — string "true"/"false" and dynamic
|
|
190
|
+
* expressions are rejected because the value is hash-changing.
|
|
191
|
+
*/
|
|
192
|
+
function validateBooleanProperty(args, name) {
|
|
193
|
+
const errors = [];
|
|
194
|
+
const property = require_utils_parsing_getObjectPropertyFromObjectExpression.getObjectPropertyFromObjectExpression(args, name) || require_utils_parsing_getObjectPropertyFromObjectExpression.getObjectPropertyFromObjectExpression(args, "$" + name);
|
|
195
|
+
if (!property) return { errors };
|
|
196
|
+
if (!_babel_types.isObjectProperty(property) || !_babel_types.isExpression(property.value) || !require_utils_validation_validateExpressionIsBooleanLiteral.validateExpressionIsBooleanLiteral(property.value)) {
|
|
197
|
+
errors.push(`The <T> component must have a boolean literal (true or false) in its ${name} field`);
|
|
198
|
+
return { errors };
|
|
199
|
+
}
|
|
200
|
+
return {
|
|
201
|
+
errors,
|
|
202
|
+
value: property.value.value
|
|
203
|
+
};
|
|
204
|
+
}
|
|
182
205
|
//#endregion
|
|
183
206
|
exports.validateChildrenProperty = validateChildrenProperty;
|
|
184
207
|
exports.validateTranslationComponentArgs = validateTranslationComponentArgs;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validateTranslationComponentArgs.js","names":["t","validateChildrenPropertyFromObjectExpression","constructJsxChildren","getObjectPropertyFromObjectExpression","validateExpressionIsStringLiteral","validateExpressionIsNumericLiteral"],"sources":["../../../src/transform/validation/validateTranslationComponentArgs.ts"],"sourcesContent":["import { TransformState } from '../../state/types';\nimport { GT_COMPONENT_TYPES } from '../../utils/constants/gt/constants';\nimport * as t from '@babel/types';\nimport type { NodePath } from '@babel/traverse';\nimport { getObjectPropertyFromObjectExpression } from '../../utils/parsing/getObjectPropertyFromObjectExpression';\nimport { validateExpressionIsStringLiteral } from '../../utils/validation/validateExpressionIsStringLiteral';\nimport type { JsxChildren } from '@generaltranslation/format/types';\nimport { constructJsxChildren } from '../jsx-children';\nimport { validateChildrenPropertyFromObjectExpression } from '../../utils/validation/validateChildrenFromObjectExpression';\nimport { validateExpressionIsNumericLiteral } from '../../utils/validation/validateExpressionIsNumericLiteral';\nimport { validateDerive } from './validateTranslationFunction';\nimport { JsxValidationError } from '../jsx-children/errors';\n/**\n * Given a translation component, validate the arguments\n */\nexport function validateTranslationComponentArgs(\n callExprPath: NodePath<t.CallExpression>,\n canonicalName: string,\n state: TransformState\n): {\n errors: string[];\n _hash?: string;\n id?: string;\n context?: string;\n maxChars?: number;\n children?: JsxChildren;\n hasDeriveContext?: boolean;\n} {\n const callExpr = callExprPath.node;\n // Check that there are at least 2 arguments (identifier, args)\n if (callExpr.arguments.length < 2) {\n const errors = [\n 'Translation component must have at least 2 arguments (identifier, args)',\n ];\n return { errors };\n }\n\n // Get the component args\n const args = callExpr.arguments[1];\n if (!t.isObjectExpression(args)) {\n const errors = [\n 'Translation component must have an object expression as the second argument',\n ];\n return { errors };\n }\n const argsPath = callExprPath.get('arguments')[1];\n if (!argsPath?.isObjectExpression()) {\n const errors = [\n 'Translation component must have an object expression as the second argument',\n ];\n return { errors };\n }\n\n // Map to appropriate validation function\n switch (canonicalName) {\n case GT_COMPONENT_TYPES.T:\n case GT_COMPONENT_TYPES.GtInternalTranslateJsx:\n return validateTComponentArgs(\n argsPath as NodePath<t.ObjectExpression>,\n state\n );\n default:\n const errors = [\n `Invalid translation component: ${canonicalName}. You likely passed a non-translation component to validateTranslationComponentArgs`,\n ];\n return { errors };\n }\n}\n\n/* =============================== */\n/* Helper Functions */\n/* =============================== */\n\nfunction validateTComponentArgs(\n argsPath: NodePath<t.ObjectExpression>,\n state: TransformState\n): {\n errors: string[];\n _hash?: string;\n id?: string;\n context?: string;\n maxChars?: number;\n children?: JsxChildren;\n hasDeriveContext?: boolean;\n} {\n const errors: string[] = [];\n const args = argsPath.node;\n\n // Validate id\n const idValidation = validateStringProperty(args, 'id');\n errors.push(...idValidation.errors);\n const id = idValidation.value;\n\n // Validate context (with derive fallback)\n const contextValidation = validateStringProperty(args, 'context', state);\n errors.push(...contextValidation.errors);\n const context = contextValidation.value;\n // Validate maxChars\n const maxCharsValidation = validateNumberProperty(args, 'maxChars');\n errors.push(...maxCharsValidation.errors);\n const maxChars = maxCharsValidation.value;\n\n // Validate hash\n const hashValidation = validateStringProperty(args, '_hash');\n errors.push(...hashValidation.errors);\n const _hash = hashValidation.value;\n\n // Validate children\n const childrenValidation = validateChildrenProperty(argsPath, state);\n errors.push(...childrenValidation.errors);\n const children = childrenValidation.value;\n\n const hasDeriveContext =\n contextValidation.hasDeriveExpression || childrenValidation.hasAutoderive;\n\n return { errors, id, context, _hash, maxChars, children, hasDeriveContext };\n}\n\n/**\n * Validate that the children property is a string literal\n */\nexport function validateChildrenProperty(\n argsPath: NodePath<t.ObjectExpression>,\n state: TransformState\n): {\n errors: string[];\n value?: JsxChildren;\n hasAutoderive?: boolean;\n} {\n const errors: string[] = [];\n\n // Get the children property\n const childrenValidation =\n validateChildrenPropertyFromObjectExpression(argsPath);\n if (childrenValidation.errors.length > 0) {\n errors.push(...childrenValidation.errors);\n return { errors };\n }\n const children = childrenValidation.value;\n if (children === undefined) {\n errors.push(`The <${GT_COMPONENT_TYPES.T}> component must have children`);\n return { errors };\n }\n\n // constructJsxChildren now returns JsxValidationError[]\n const validation = constructJsxChildren(children, state);\n\n // Autoderive: filter out dynamic-content errors\n let hasAutoderive = false;\n let filteredErrors: JsxValidationError[] = validation.errors;\n if (state.settings.autoderive.jsx) {\n filteredErrors = validation.errors.filter(\n (e) => e.type !== 'dynamic-content'\n );\n hasAutoderive = filteredErrors.length < validation.errors.length;\n }\n\n // Convert structured errors back to strings\n errors.push(...filteredErrors.map((e) => e.message));\n const value = validation.value;\n\n return { errors, value, hasAutoderive };\n}\n\n// String Literal Functions\n\n/**\n * Will validate and retrieve property from object expression and also try prefixing with a $\n *\n */\nfunction validateStringProperty(\n args: t.ObjectExpression,\n name: string,\n state?: TransformState\n): {\n errors: string[];\n value?: string;\n hasDeriveExpression?: boolean;\n} {\n const errors: string[] = [];\n\n // Get the property\n const property =\n getObjectPropertyFromObjectExpression(args, name) ||\n getObjectPropertyFromObjectExpression(args, '$' + name);\n if (!property) {\n return { errors };\n }\n\n // Validate property\n const validation = validateObjectPropertyIsStringLiteral(property, name);\n if (validation.errors.length === 0) {\n return { errors, value: validation.value };\n }\n\n // String validation failed — check if it's a valid derive() expression\n if (state && t.isObjectProperty(property) && t.isExpression(property.value)) {\n const deriveErrors: string[] = [];\n validateDerive(property.value, state, deriveErrors);\n if (deriveErrors.length === 0) {\n return { errors, hasDeriveExpression: true };\n }\n }\n\n // Neither string nor derive — return original errors\n errors.push(...validation.errors);\n return { errors };\n}\n\n/**\n * Validate that an object property is a string literal\n */\nfunction validateObjectPropertyIsStringLiteral(\n arg: t.SpreadElement | t.ObjectMethod | t.ObjectProperty,\n name: string\n): {\n errors: string[];\n value?: string;\n} {\n const errors: string[] = [];\n\n // Validate the property is a string literal from an expression\n if (\n !t.isObjectProperty(arg) ||\n !t.isExpression(arg.value) ||\n !validateExpressionIsStringLiteral(arg.value)\n ) {\n errors.push(\n `The <${GT_COMPONENT_TYPES.T}> component must have a string literal in its ${name} field`\n );\n return { errors };\n }\n\n // Get the string literal\n const value = getStringLiteralFromExpression(arg.value);\n return { errors, value };\n}\n\n/**\n * Given an expression, return the string literal (throws an error if not a string literal)\n */\nfunction getStringLiteralFromExpression(\n expr: t.Expression\n): string | undefined {\n if (t.isStringLiteral(expr)) {\n return expr.value;\n }\n if (t.isTemplateLiteral(expr)) {\n if (expr.expressions.length === 0) {\n return expr.quasis[0]?.value.cooked || '';\n }\n }\n}\n\n// Number Literal Functions\n\n/**\n * Will validate and retrieve property from object expression and also try prefixing with a $\n */\nfunction validateNumberProperty(\n args: t.ObjectExpression,\n name: string\n): {\n errors: string[];\n value?: number;\n} {\n const errors: string[] = [];\n\n // Get the property\n const property =\n getObjectPropertyFromObjectExpression(args, name) ||\n getObjectPropertyFromObjectExpression(args, '$' + name);\n if (!property) {\n return { errors };\n }\n\n // Validate property\n const validation = validateObjectPropertyIsNumberLiteral(property, name);\n errors.push(...validation.errors);\n const value = validation.value;\n\n return { errors, value };\n}\n\n/**\n * Validate that an object property is a number literal\n */\nfunction validateObjectPropertyIsNumberLiteral(\n arg: t.SpreadElement | t.ObjectMethod | t.ObjectProperty,\n name: string\n): {\n errors: string[];\n value?: number;\n} {\n const errors: string[] = [];\n\n // Validate the property is a string literal from an expression\n if (\n !t.isObjectProperty(arg) ||\n !t.isExpression(arg.value) ||\n !validateExpressionIsNumericLiteral(arg.value)\n ) {\n errors.push(\n `The <${GT_COMPONENT_TYPES.T}> component must have a number literal in its ${name} field`\n );\n return { errors };\n }\n\n // Get the number literal\n const value = getNumberLiteralFromExpression(arg.value);\n\n // Validate it is an integer\n if (value !== undefined && !validateNumberLiteralIsInteger(value)) {\n errors.push(\n `The <${GT_COMPONENT_TYPES.T}> component must have an integer in its ${name} field`\n );\n return { errors };\n }\n\n return { errors, value };\n}\n\n/**\n * Given an expression, return the number literal (throws an error if not a number literal)\n */\nfunction getNumberLiteralFromExpression(\n expr: t.Expression\n): number | undefined {\n if (t.isNumericLiteral(expr)) {\n return expr.value;\n }\n // handle numbers with unary operators\n if (t.isUnaryExpression(expr) && t.isNumericLiteral(expr.argument)) {\n // On purpose, we are taking the absolute value of the number literal\n return expr.argument.value;\n }\n}\n\n/**\n * Validate that a number literal is an integer\n */\nfunction validateNumberLiteralIsInteger(value: number): boolean {\n return Number.isInteger(value);\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAeA,SAAgB,iCACd,cACA,eACA,OASA;CACA,MAAM,WAAW,aAAa;AAE9B,KAAI,SAAS,UAAU,SAAS,EAI9B,QAAO,EAAE,QAAA,CAFP,0EAEa,EAAE;CAInB,MAAM,OAAO,SAAS,UAAU;AAChC,KAAI,CAACA,aAAE,mBAAmB,KAAK,CAI7B,QAAO,EAAE,QAAA,CAFP,8EAEa,EAAE;CAEnB,MAAM,WAAW,aAAa,IAAI,YAAY,CAAC;AAC/C,KAAI,EAAA,aAAA,QAAA,aAAA,KAAA,IAAA,KAAA,IAAC,SAAU,oBAAoB,EAIjC,QAAO,EAAE,QAAA,CAFP,8EAEa,EAAE;AAInB,SAAQ,eAAR;EACE,KAA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AK;MACvB,KAAK,YAAY,WAAW,GAAG;;AACjC,YAAA,gBAAO,KAAK,OAAO,QAAA,QAAA,kBAAA,KAAA,IAAA,KAAA,IAAA,cAAI,MAAM,WAAU;;;;;;;AAU7C,SAAS,uBACP,MACA,MAIA;CACA,MAAM,SAAmB,EAAE;CAG3B,MAAM,WACJG,4DAAAA,sCAAsC,MAAM,KAAK,IACjDA,4DAAAA,sCAAsC,MAAM,MAAM,KAAK;AACzD,KAAI,CAAC,SACH,QAAO,EAAE,QAAQ;CAInB,MAAM,aAAa,sCAAsC,UAAU,KAAK;AACxE,QAAO,KAAK,GAAG,WAAW,OAAO;AAGjC,QAAO;EAAE;EAAQ,OAFH,WAAW;EAED;;;;;AAM1B,SAAS,sCACP,KACA,MAIA;CACA,MAAM,SAAmB,EAAE;AAG3B,KACE,CAACH,aAAE,iBAAiB,IAAI,IACxB,CAACA,aAAE,aAAa,IAAI,MAAM,IAC1B,CAACK,4DAAAA,mCAAmC,IAAI,MAAM,EAC9C;AACA,SAAO,KACL,uDAA6E,KAAK,QACnF;AACD,SAAO,EAAE,QAAQ;;CAInB,MAAM,QAAQ,+BAA+B,IAAI,MAAM;AAGvD,KAAI,UAAU,KAAA,KAAa,CAAC,+BAA+B,MAAM,EAAE;AACjE,SAAO,KACL,iDAAuE,KAAK,QAC7E;AACD,SAAO,EAAE,QAAQ;;AAGnB,QAAO;EAAE;EAAQ;EAAO;;;;;AAM1B,SAAS,+BACP,MACoB;AACpB,KAAIL,aAAE,iBAAiB,KAAK,CAC1B,QAAO,KAAK;AAGd,KAAIA,aAAE,kBAAkB,KAAK,IAAIA,aAAE,iBAAiB,KAAK,SAAS,CAEhE,QAAO,KAAK,SAAS;;;;;AAOzB,SAAS,+BAA+B,OAAwB;AAC9D,QAAO,OAAO,UAAU,MAAM"}
|
|
1
|
+
{"version":3,"file":"validateTranslationComponentArgs.js","names":["t","validateChildrenPropertyFromObjectExpression","constructJsxChildren","getObjectPropertyFromObjectExpression","validateExpressionIsStringLiteral","validateExpressionIsNumericLiteral","validateExpressionIsBooleanLiteral"],"sources":["../../../src/transform/validation/validateTranslationComponentArgs.ts"],"sourcesContent":["import { TransformState } from '../../state/types';\nimport { GT_COMPONENT_TYPES } from '../../utils/constants/gt/constants';\nimport * as t from '@babel/types';\nimport type { NodePath } from '@babel/traverse';\nimport { getObjectPropertyFromObjectExpression } from '../../utils/parsing/getObjectPropertyFromObjectExpression';\nimport { validateExpressionIsStringLiteral } from '../../utils/validation/validateExpressionIsStringLiteral';\nimport type { JsxChildren } from '@generaltranslation/format/types';\nimport { constructJsxChildren } from '../jsx-children';\nimport { validateChildrenPropertyFromObjectExpression } from '../../utils/validation/validateChildrenFromObjectExpression';\nimport { validateExpressionIsNumericLiteral } from '../../utils/validation/validateExpressionIsNumericLiteral';\nimport { validateExpressionIsBooleanLiteral } from '../../utils/validation/validateExpressionIsBooleanLiteral';\nimport { validateDerive } from './validateTranslationFunction';\nimport { JsxValidationError } from '../jsx-children/errors';\n/**\n * Given a translation component, validate the arguments\n */\nexport function validateTranslationComponentArgs(\n callExprPath: NodePath<t.CallExpression>,\n canonicalName: string,\n state: TransformState\n): {\n errors: string[];\n _hash?: string;\n id?: string;\n context?: string;\n maxChars?: number;\n requiresReview?: boolean;\n children?: JsxChildren;\n hasDeriveContext?: boolean;\n} {\n const callExpr = callExprPath.node;\n // Check that there are at least 2 arguments (identifier, args)\n if (callExpr.arguments.length < 2) {\n const errors = [\n 'Translation component must have at least 2 arguments (identifier, args)',\n ];\n return { errors };\n }\n\n // Get the component args\n const args = callExpr.arguments[1];\n if (!t.isObjectExpression(args)) {\n const errors = [\n 'Translation component must have an object expression as the second argument',\n ];\n return { errors };\n }\n const argsPath = callExprPath.get('arguments')[1];\n if (!argsPath?.isObjectExpression()) {\n const errors = [\n 'Translation component must have an object expression as the second argument',\n ];\n return { errors };\n }\n\n // Map to appropriate validation function\n switch (canonicalName) {\n case GT_COMPONENT_TYPES.T:\n case GT_COMPONENT_TYPES.GtInternalTranslateJsx:\n return validateTComponentArgs(\n argsPath as NodePath<t.ObjectExpression>,\n state\n );\n default:\n const errors = [\n `Invalid translation component: ${canonicalName}. You likely passed a non-translation component to validateTranslationComponentArgs`,\n ];\n return { errors };\n }\n}\n\n/* =============================== */\n/* Helper Functions */\n/* =============================== */\n\nfunction validateTComponentArgs(\n argsPath: NodePath<t.ObjectExpression>,\n state: TransformState\n): {\n errors: string[];\n _hash?: string;\n id?: string;\n context?: string;\n maxChars?: number;\n requiresReview?: boolean;\n children?: JsxChildren;\n hasDeriveContext?: boolean;\n} {\n const errors: string[] = [];\n const args = argsPath.node;\n\n // Validate id\n const idValidation = validateStringProperty(args, 'id');\n errors.push(...idValidation.errors);\n const id = idValidation.value;\n\n // Validate context (with derive fallback)\n const contextValidation = validateStringProperty(args, 'context', state);\n errors.push(...contextValidation.errors);\n const context = contextValidation.value;\n // Validate maxChars\n const maxCharsValidation = validateNumberProperty(args, 'maxChars');\n errors.push(...maxCharsValidation.errors);\n const maxChars = maxCharsValidation.value;\n\n // Validate requiresReview\n const requiresReviewValidation = validateBooleanProperty(\n args,\n 'requiresReview'\n );\n errors.push(...requiresReviewValidation.errors);\n const requiresReview = requiresReviewValidation.value;\n\n // Validate hash\n const hashValidation = validateStringProperty(args, '_hash');\n errors.push(...hashValidation.errors);\n const _hash = hashValidation.value;\n\n // Validate children\n const childrenValidation = validateChildrenProperty(argsPath, state);\n errors.push(...childrenValidation.errors);\n const children = childrenValidation.value;\n\n const hasDeriveContext =\n contextValidation.hasDeriveExpression || childrenValidation.hasAutoderive;\n\n return {\n errors,\n id,\n context,\n _hash,\n maxChars,\n requiresReview,\n children,\n hasDeriveContext,\n };\n}\n\n/**\n * Validate that the children property is a string literal\n */\nexport function validateChildrenProperty(\n argsPath: NodePath<t.ObjectExpression>,\n state: TransformState\n): {\n errors: string[];\n value?: JsxChildren;\n hasAutoderive?: boolean;\n} {\n const errors: string[] = [];\n\n // Get the children property\n const childrenValidation =\n validateChildrenPropertyFromObjectExpression(argsPath);\n if (childrenValidation.errors.length > 0) {\n errors.push(...childrenValidation.errors);\n return { errors };\n }\n const children = childrenValidation.value;\n if (children === undefined) {\n errors.push(`The <${GT_COMPONENT_TYPES.T}> component must have children`);\n return { errors };\n }\n\n // constructJsxChildren now returns JsxValidationError[]\n const validation = constructJsxChildren(children, state);\n\n // Autoderive: filter out dynamic-content errors\n let hasAutoderive = false;\n let filteredErrors: JsxValidationError[] = validation.errors;\n if (state.settings.autoderive.jsx) {\n filteredErrors = validation.errors.filter(\n (e) => e.type !== 'dynamic-content'\n );\n hasAutoderive = filteredErrors.length < validation.errors.length;\n }\n\n // Convert structured errors back to strings\n errors.push(...filteredErrors.map((e) => e.message));\n const value = validation.value;\n\n return { errors, value, hasAutoderive };\n}\n\n// String Literal Functions\n\n/**\n * Will validate and retrieve property from object expression and also try prefixing with a $\n *\n */\nfunction validateStringProperty(\n args: t.ObjectExpression,\n name: string,\n state?: TransformState\n): {\n errors: string[];\n value?: string;\n hasDeriveExpression?: boolean;\n} {\n const errors: string[] = [];\n\n // Get the property\n const property =\n getObjectPropertyFromObjectExpression(args, name) ||\n getObjectPropertyFromObjectExpression(args, '$' + name);\n if (!property) {\n return { errors };\n }\n\n // Validate property\n const validation = validateObjectPropertyIsStringLiteral(property, name);\n if (validation.errors.length === 0) {\n return { errors, value: validation.value };\n }\n\n // String validation failed — check if it's a valid derive() expression\n if (state && t.isObjectProperty(property) && t.isExpression(property.value)) {\n const deriveErrors: string[] = [];\n validateDerive(property.value, state, deriveErrors);\n if (deriveErrors.length === 0) {\n return { errors, hasDeriveExpression: true };\n }\n }\n\n // Neither string nor derive — return original errors\n errors.push(...validation.errors);\n return { errors };\n}\n\n/**\n * Validate that an object property is a string literal\n */\nfunction validateObjectPropertyIsStringLiteral(\n arg: t.SpreadElement | t.ObjectMethod | t.ObjectProperty,\n name: string\n): {\n errors: string[];\n value?: string;\n} {\n const errors: string[] = [];\n\n // Validate the property is a string literal from an expression\n if (\n !t.isObjectProperty(arg) ||\n !t.isExpression(arg.value) ||\n !validateExpressionIsStringLiteral(arg.value)\n ) {\n errors.push(\n `The <${GT_COMPONENT_TYPES.T}> component must have a string literal in its ${name} field`\n );\n return { errors };\n }\n\n // Get the string literal\n const value = getStringLiteralFromExpression(arg.value);\n return { errors, value };\n}\n\n/**\n * Given an expression, return the string literal (throws an error if not a string literal)\n */\nfunction getStringLiteralFromExpression(\n expr: t.Expression\n): string | undefined {\n if (t.isStringLiteral(expr)) {\n return expr.value;\n }\n if (t.isTemplateLiteral(expr)) {\n if (expr.expressions.length === 0) {\n return expr.quasis[0]?.value.cooked || '';\n }\n }\n}\n\n// Number Literal Functions\n\n/**\n * Will validate and retrieve property from object expression and also try prefixing with a $\n */\nfunction validateNumberProperty(\n args: t.ObjectExpression,\n name: string\n): {\n errors: string[];\n value?: number;\n} {\n const errors: string[] = [];\n\n // Get the property\n const property =\n getObjectPropertyFromObjectExpression(args, name) ||\n getObjectPropertyFromObjectExpression(args, '$' + name);\n if (!property) {\n return { errors };\n }\n\n // Validate property\n const validation = validateObjectPropertyIsNumberLiteral(property, name);\n errors.push(...validation.errors);\n const value = validation.value;\n\n return { errors, value };\n}\n\n/**\n * Validate that an object property is a number literal\n */\nfunction validateObjectPropertyIsNumberLiteral(\n arg: t.SpreadElement | t.ObjectMethod | t.ObjectProperty,\n name: string\n): {\n errors: string[];\n value?: number;\n} {\n const errors: string[] = [];\n\n // Validate the property is a string literal from an expression\n if (\n !t.isObjectProperty(arg) ||\n !t.isExpression(arg.value) ||\n !validateExpressionIsNumericLiteral(arg.value)\n ) {\n errors.push(\n `The <${GT_COMPONENT_TYPES.T}> component must have a number literal in its ${name} field`\n );\n return { errors };\n }\n\n // Get the number literal\n const value = getNumberLiteralFromExpression(arg.value);\n\n // Validate it is an integer\n if (value !== undefined && !validateNumberLiteralIsInteger(value)) {\n errors.push(\n `The <${GT_COMPONENT_TYPES.T}> component must have an integer in its ${name} field`\n );\n return { errors };\n }\n\n return { errors, value };\n}\n\n/**\n * Given an expression, return the number literal (throws an error if not a number literal)\n */\nfunction getNumberLiteralFromExpression(\n expr: t.Expression\n): number | undefined {\n if (t.isNumericLiteral(expr)) {\n return expr.value;\n }\n // handle numbers with unary operators\n if (t.isUnaryExpression(expr) && t.isNumericLiteral(expr.argument)) {\n // On purpose, we are taking the absolute value of the number literal\n return expr.argument.value;\n }\n}\n\n/**\n * Validate that a number literal is an integer\n */\nfunction validateNumberLiteralIsInteger(value: number): boolean {\n return Number.isInteger(value);\n}\n\n// Boolean Literal Functions\n\n/**\n * Will validate and retrieve property from object expression and also try prefixing with a $.\n * Only boolean literals are accepted — string \"true\"/\"false\" and dynamic\n * expressions are rejected because the value is hash-changing.\n */\nfunction validateBooleanProperty(\n args: t.ObjectExpression,\n name: string\n): {\n errors: string[];\n value?: boolean;\n} {\n const errors: string[] = [];\n\n // Get the property\n const property =\n getObjectPropertyFromObjectExpression(args, name) ||\n getObjectPropertyFromObjectExpression(args, '$' + name);\n if (!property) {\n return { errors };\n }\n\n if (\n !t.isObjectProperty(property) ||\n !t.isExpression(property.value) ||\n !validateExpressionIsBooleanLiteral(property.value)\n ) {\n errors.push(\n `The <${GT_COMPONENT_TYPES.T}> component must have a boolean literal (true or false) in its ${name} field`\n );\n return { errors };\n }\n\n return { errors, value: (property.value as t.BooleanLiteral).value };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AAgBA,SAAgB,iCACd,cACA,eACA,OAUA;CACA,MAAM,WAAW,aAAa;AAE9B,KAAI,SAAS,UAAU,SAAS,EAI9B,QAAO,EAAE,QAAA,CAFP,0EAEa,EAAE;CAInB,MAAM,OAAO,SAAS,UAAU;AAChC,KAAI,CAACA,aAAE,mBAAmB,KAAK,CAI7B,QAAO,EAAE,QAAA,CAFP,8EAEa,EAAE;CAEnB,MAAM,WAAW,aAAa,IAAI,YAAY,CAAC;AAC/C,KAAI,EAAA,aAAA,QAAA,aAAA,KAAA,IAAA,KAAA,IAAC,SAAU,oBAAoB,EAI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zB,SAAS,+BAA+B,OAAwB;AAC9D,QAAO,OAAO,UAAU,MAAM;;;;;;;AAUhC,SAAS,wBACP,MACA,MAIA;CACA,MAAM,SAAmB,EAAE;CAG3B,MAAM,WACJG,4DAAAA,sCAAsC,MAAM,KAAK,IACjDA,4DAAAA,sCAAsC,MAAM,MAAM,KAAK;AACzD,KAAI,CAAC,SACH,QAAO,EAAE,QAAQ;AAGnB,KACE,CAACH,aAAE,iBAAiB,SAAS,IAC7B,CAACA,aAAE,aAAa,SAAS,MAAM,IAC/B,CAACM,4DAAAA,mCAAmC,SAAS,MAAM,EACnD;AACA,SAAO,KACL,wEAA8F,KAAK,QACpG;AACD,SAAO,EAAE,QAAQ;;AAGnB,QAAO;EAAE;EAAQ,OAAQ,SAAS,MAA2B;EAAO"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validateTranslationFunction.d.ts","sourceRoot":"","sources":["../../../src/transform/validation/validateTranslationFunction.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,cAAc,CAAC;AAKlC,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAOnD,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAE3C;;;;;GAKG;AACH,wBAAgB,2BAA2B,CACzC,YAAY,EAAE,QAAQ,CAAC,CAAC,CAAC,cAAc,CAAC,EACxC,KAAK,EAAE,cAAc,GACpB;IACD,MAAM,EAAE,MAAM,EAAE,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,gBAAgB,CAAC,EAAE,OAAO,CAAC;CAC5B,
|
|
1
|
+
{"version":3,"file":"validateTranslationFunction.d.ts","sourceRoot":"","sources":["../../../src/transform/validation/validateTranslationFunction.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,cAAc,CAAC;AAKlC,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAOnD,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAE3C;;;;;GAKG;AACH,wBAAgB,2BAA2B,CACzC,YAAY,EAAE,QAAQ,CAAC,CAAC,CAAC,cAAc,CAAC,EACxC,KAAK,EAAE,cAAc,GACpB;IACD,MAAM,EAAE,MAAM,EAAE,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,gBAAgB,CAAC,EAAE,OAAO,CAAC;CAC5B,CAmIA;AAED;;;GAGG;AAEH,wBAAgB,+BAA+B,CAAC,SAAS,EAAE,CAAC,CAAC,cAAc,GAAG;IAC5E,MAAM,EAAE,MAAM,EAAE,CAAC;CAClB,CAGA;AAED;;;GAGG;AAEH,wBAAgB,2BAA2B,CAAC,SAAS,EAAE,CAAC,CAAC,cAAc,GAAG;IACxE,MAAM,EAAE,MAAM,EAAE,CAAC;CAClB,CAGA;AAgJD;;GAEG;AACH,wBAAgB,cAAc,CAC5B,IAAI,EAAE,CAAC,CAAC,UAAU,EAClB,KAAK,EAAE,cAAc,EACrB,MAAM,EAAE,MAAM,EAAE,GACf;IAAE,MAAM,EAAE,MAAM,EAAE,CAAA;CAAE,CAoFtB"}
|
|
@@ -43,6 +43,7 @@ function validateTranslationFunction(callExprPath, state) {
|
|
|
43
43
|
let hash;
|
|
44
44
|
let maxChars;
|
|
45
45
|
let format;
|
|
46
|
+
let requiresReview;
|
|
46
47
|
let hasDeriveContext;
|
|
47
48
|
if (callExpr.arguments.length === 1) return {
|
|
48
49
|
errors,
|
|
@@ -67,6 +68,9 @@ function validateTranslationFunction(callExprPath, state) {
|
|
|
67
68
|
const formatProperty = validatePropertyFromObjectExpression(objExprPath, "$format", "string");
|
|
68
69
|
errors.push(...formatProperty.errors);
|
|
69
70
|
format = formatProperty.value;
|
|
71
|
+
const requiresReviewProperty = validatePropertyFromObjectExpression(objExprPath, "$requiresReview", "boolean");
|
|
72
|
+
errors.push(...requiresReviewProperty.errors);
|
|
73
|
+
requiresReview = requiresReviewProperty.value;
|
|
70
74
|
}
|
|
71
75
|
return {
|
|
72
76
|
errors,
|
|
@@ -76,6 +80,7 @@ function validateTranslationFunction(callExprPath, state) {
|
|
|
76
80
|
hash,
|
|
77
81
|
maxChars,
|
|
78
82
|
format,
|
|
83
|
+
requiresReview,
|
|
79
84
|
hasDeriveContext
|
|
80
85
|
};
|
|
81
86
|
}
|
|
@@ -130,7 +135,7 @@ function validatePropertyFromObjectExpression(objExprPath, name, type, state) {
|
|
|
130
135
|
else result.errors.push(...getResolutionErrorMessages(resolved.errors), ...deriveErrors);
|
|
131
136
|
} else result.errors.push(...getResolutionErrorMessages(resolved.errors));
|
|
132
137
|
} else {
|
|
133
|
-
const validatedValue = type === "string" ? validateExpressionIsStringLiteral(value.value) : validateExpressionIsNumericLiteral(value.value);
|
|
138
|
+
const validatedValue = type === "string" ? validateExpressionIsStringLiteral(value.value) : type === "boolean" ? validateExpressionIsBooleanLiteral(value.value) : validateExpressionIsNumericLiteral(value.value);
|
|
134
139
|
result.errors.push(...validatedValue.errors);
|
|
135
140
|
result.value = validatedValue.value;
|
|
136
141
|
}
|
|
@@ -222,6 +227,23 @@ function validateDeclareStaticExpression(expr, errors) {
|
|
|
222
227
|
return { errors };
|
|
223
228
|
}
|
|
224
229
|
/**
|
|
230
|
+
* Validate that an expression is a boolean literal (strictly `true` or
|
|
231
|
+
* `false` — never string "true"/"false" or a dynamic expression).
|
|
232
|
+
*
|
|
233
|
+
* NOTE: a standalone predicate with the same logic exists at
|
|
234
|
+
* `../../utils/validation/validateExpressionIsBooleanLiteral` (returns a
|
|
235
|
+
* plain boolean). This local copy returns `{ errors, value }` to match the
|
|
236
|
+
* interface of the sibling string/number validators in this file — the same
|
|
237
|
+
* local-vs-utility duality those validators already have.
|
|
238
|
+
*/
|
|
239
|
+
function validateExpressionIsBooleanLiteral(expr) {
|
|
240
|
+
if (_babel_types.isBooleanLiteral(expr)) return {
|
|
241
|
+
errors: [],
|
|
242
|
+
value: expr.value
|
|
243
|
+
};
|
|
244
|
+
return { errors: ["Expression is not a boolean literal"] };
|
|
245
|
+
}
|
|
246
|
+
/**
|
|
225
247
|
* Validate that an expression is a number literal
|
|
226
248
|
*/
|
|
227
249
|
function validateExpressionIsNumericLiteral(expr) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validateTranslationFunction.js","names":["t","resolveStaticExpression","getCalleeNameFromExpression","getTrackedVariable"],"sources":["../../../src/transform/validation/validateTranslationFunction.ts"],"sourcesContent":["import * as t from '@babel/types';\nimport {\n GT_OTHER_FUNCTIONS,\n USEGT_CALLBACK_OPTIONS,\n} from '../../utils/constants/gt/constants';\nimport { TransformState } from '../../state/types';\nimport { getCalleeNameFromExpression } from '../../utils/parsing/getCalleeNameFromExpression';\nimport {\n resolveStaticExpression,\n type ResolveStaticExpressionError,\n} from '../../utils/string-expressions/resolveStaticExpression';\nimport { getTrackedVariable } from '../getTrackedVariable';\nimport { NodePath } from '@babel/traverse';\n\n/**\n * Validate useGT_callback / getGT_callback / msg() / t()\n * - first argument must be a statically resolvable string expression\n * (string literal, template literal, binary '+' concatenation, or derive() call)\n * - second argument, if present, $id field + $context field must be a string literal\n */\nexport function validateTranslationFunction(\n callExprPath: NodePath<t.CallExpression>,\n state: TransformState\n): {\n errors: string[];\n content?: string;\n context?: string;\n hash?: string;\n id?: string;\n maxChars?: number;\n format?: string;\n hasDeriveContext?: boolean;\n} {\n const callExpr = callExprPath.node;\n const errors: string[] = [];\n\n // Validate that the function has at least 1 argument\n if (callExpr.arguments.length < 1) {\n errors.push('registration function must have at least 1 argument');\n return { errors };\n }\n\n // Validate first argument\n if (!t.isExpression(callExpr.arguments[0])) {\n errors.push(\n 'registration function must use a string literal or derive() call as the first argument. Variable content is not allowed.'\n );\n return { errors };\n }\n\n // Try to resolve the expression to a static string (handles concat, nested templates, etc.)\n const resolvedStaticExpression = resolveStaticExpression(\n callExprPath.get('arguments')[0] as NodePath<t.Expression>\n );\n // TODO: until we implement derivation, we will only need to check the first value\n const content = resolvedStaticExpression.values?.[0];\n const resolutionErrors = getResolutionErrorMessages(\n resolvedStaticExpression.errors,\n false\n );\n\n if (resolutionErrors.length > 0) {\n return { errors: resolutionErrors };\n }\n\n if (content === undefined && !state.settings.autoderive.strings) {\n // Not a static expression — check if it contains a derive() function invocation\n validateDerive(callExpr.arguments[0], state, errors);\n if (errors.length > 0) {\n errors.push(\n ...getResolutionErrorMessages(resolvedStaticExpression.errors)\n );\n errors.push(\n 'registration function must use a string literal or derive() call as the first argument. Variable content is not allowed.'\n );\n return { errors };\n }\n }\n\n // TODO: hasDeriveContext should be refactored to enforce no hash generated HERE in this function\n // instead of passing that information outside of this function.\n // We skip hash gen with autoderive, derive in content, and derive in $context. This flag is being\n // reused for all 3 cases.\n const contentHasAutoderive =\n state.settings.autoderive.strings && content === undefined;\n\n // Validate second argument\n let context: string | undefined;\n let id: string | undefined;\n let hash: string | undefined;\n let maxChars: number | undefined;\n let format: string | undefined;\n let hasDeriveContext: boolean | undefined;\n if (callExpr.arguments.length === 1) {\n return {\n errors,\n content,\n hasDeriveContext: contentHasAutoderive || undefined,\n };\n }\n if (t.isObjectExpression(callExpr.arguments[1])) {\n const objExprPath = callExprPath.get(\n 'arguments'\n )[1] as NodePath<t.ObjectExpression>;\n const contextProperty = validatePropertyFromObjectExpression(\n objExprPath,\n USEGT_CALLBACK_OPTIONS.$context,\n 'string-or-derive',\n state\n );\n errors.push(...contextProperty.errors);\n context = contextProperty.value as string | undefined;\n hasDeriveContext =\n contentHasAutoderive || contextProperty.hasDeriveExpression;\n const idProperty = validatePropertyFromObjectExpression(\n objExprPath,\n USEGT_CALLBACK_OPTIONS.$id,\n 'string'\n );\n errors.push(...idProperty.errors);\n id = idProperty.value;\n const maxCharsProperty = validatePropertyFromObjectExpression(\n objExprPath,\n USEGT_CALLBACK_OPTIONS.$maxChars,\n 'number'\n );\n errors.push(...maxCharsProperty.errors);\n maxChars = maxCharsProperty.value;\n const hashProperty = validatePropertyFromObjectExpression(\n objExprPath,\n USEGT_CALLBACK_OPTIONS.$_hash,\n 'string'\n );\n errors.push(...hashProperty.errors);\n hash = hashProperty.value;\n const formatProperty = validatePropertyFromObjectExpression(\n objExprPath,\n USEGT_CALLBACK_OPTIONS.$format,\n 'string'\n );\n errors.push(...formatProperty.errors);\n format = formatProperty.value;\n }\n\n return {\n errors,\n content,\n context,\n id,\n hash,\n maxChars,\n format,\n hasDeriveContext,\n };\n}\n\n/**\n * Validate useTranslations_callback / getTranslations_callback\n * - always valid (arguments can be dynamic)\n */\n// eslint-disable-next-line no-unused-vars\nexport function validateUseTranslationsCallback(_callExpr: t.CallExpression): {\n errors: string[];\n} {\n const errors: string[] = [];\n return { errors };\n}\n\n/**\n * Validate useMessages_callback / getMessages_callback\n * - always valid\n */\n// eslint-disable-next-line no-unused-vars\nexport function validateUseMessagesCallback(_callExpr: t.CallExpression): {\n errors: string[];\n} {\n const errors: string[] = [];\n return { errors };\n}\n\n/* =============================== */\n/* Helper Functions */\n/* =============================== */\n\nfunction getResolutionErrorMessages(\n errors: ResolveStaticExpressionError[],\n includeDynamic = true\n): string[] {\n return errors\n .filter((error) => includeDynamic || error.kind !== 'dynamic-expression')\n .map(({ message }) => message);\n}\n\n/**\n * Validate a property from an object expression\n * @param objExpr - The object expression to validate\n * @param name - The name of the property to validate\n * @returns The validated property\n */\nfunction validatePropertyFromObjectExpression(\n objExprPath: NodePath<t.ObjectExpression>,\n name: string,\n type: 'string'\n): { errors: string[]; value?: string };\nfunction validatePropertyFromObjectExpression(\n objExprPath: NodePath<t.ObjectExpression>,\n name: string,\n type: 'number'\n): { errors: string[]; value?: number };\nfunction validatePropertyFromObjectExpression(\n objExprPath: NodePath<t.ObjectExpression>,\n name: string,\n type: 'string-or-derive',\n state: TransformState\n): { errors: string[]; value?: string; hasDeriveExpression?: boolean };\nfunction validatePropertyFromObjectExpression(\n objExprPath: NodePath<t.ObjectExpression>,\n name: string,\n type: 'string' | 'number' | 'string-or-derive',\n state?: TransformState\n): {\n errors: string[];\n value?: string | number;\n hasDeriveExpression?: boolean;\n} {\n const result: {\n errors: string[];\n value?: string | number;\n hasDeriveExpression?: boolean;\n } = { errors: [] };\n let valuePath: NodePath<t.ObjectProperty> | undefined;\n for (const propertyPath of objExprPath.get('properties')) {\n if (!propertyPath.isObjectProperty()) {\n continue;\n }\n const property = propertyPath.node;\n if (t.isIdentifier(property.key) && property.key.name === name) {\n valuePath = propertyPath;\n break;\n }\n if (t.isStringLiteral(property.key) && property.key.value === name) {\n valuePath = propertyPath;\n break;\n }\n }\n\n // return result if no value found\n if (!valuePath) {\n return result;\n }\n\n const value = valuePath.node;\n\n // validate value\n if (!t.isExpression(value.value)) {\n result.errors.push(\n `registration function must use a string literal for its ${name} field. Variable content is not allowed.`\n );\n return result;\n }\n\n // extract value\n if (type === 'string-or-derive') {\n const resolved = resolveStaticExpression(\n valuePath.get('value') as NodePath<t.Expression>\n );\n const resolutionErrors = getResolutionErrorMessages(resolved.errors, false);\n // TODO: until we implement derivation, we will only need to check the first value\n if (resolved.values?.[0] !== undefined) {\n result.value = resolved.values[0];\n } else if (resolutionErrors.length > 0) {\n result.errors.push(...resolutionErrors);\n } else if (state) {\n // Static resolution failed — check if it's a valid derive() expression\n const deriveErrors: string[] = [];\n validateDerive(value.value, state, deriveErrors);\n if (deriveErrors.length === 0) {\n result.hasDeriveExpression = true;\n } else {\n result.errors.push(\n ...getResolutionErrorMessages(resolved.errors),\n ...deriveErrors\n );\n }\n } else {\n result.errors.push(...getResolutionErrorMessages(resolved.errors));\n }\n } else {\n const validatedValue =\n type === 'string'\n ? validateExpressionIsStringLiteral(value.value)\n : validateExpressionIsNumericLiteral(value.value);\n result.errors.push(...validatedValue.errors);\n result.value = validatedValue.value;\n }\n\n return result;\n}\n\n/**\n * Validate that an expression is a string literal\n */\nfunction validateExpressionIsStringLiteral(expr: t.Expression): {\n errors: string[];\n value?: string;\n} {\n if (t.isStringLiteral(expr)) {\n return { errors: [], value: expr.value };\n }\n if (t.isTemplateLiteral(expr) && expr.expressions.length === 0) {\n return { errors: [], value: expr.quasis[0]?.value.cooked };\n }\n return { errors: ['Expression is not a string literal'] };\n}\n\n/**\n * Validates if an expression uses the derive() function correctly\n */\nexport function validateDerive(\n expr: t.Expression,\n state: TransformState,\n errors: string[]\n): { errors: string[] } {\n if (!expr) {\n errors.push('Expression is empty');\n return { errors };\n }\n\n // 1. Direct call: derive(node)\n if (t.isCallExpression(expr)) {\n // Find the canonical function name\n const { namespaceName, functionName } = getCalleeNameFromExpression(expr);\n // Get the canonical function name\n const { canonicalName, type } = getTrackedVariable(\n state.scopeTracker,\n namespaceName,\n functionName\n );\n if (!canonicalName) {\n errors.push('Expression does not use an allowed call expression');\n return { errors };\n }\n // Validate the function is actually the GT derive function\n if (\n type !== 'generaltranslation' ||\n (canonicalName !== GT_OTHER_FUNCTIONS.declareStatic &&\n canonicalName !== GT_OTHER_FUNCTIONS.derive)\n ) {\n errors.push('Expression does not use an allowed call expression');\n return { errors };\n }\n // Validate that the call expression has exactly one argument and the argument is a call expression\n validateDeclareStaticExpression(expr, errors);\n return { errors };\n }\n\n // 2. String concatenation: \"Hello there \" + derive(getName())\n if (t.isBinaryExpression(expr) && expr.operator === '+') {\n if (!t.isExpression(expr.left) || !t.isExpression(expr.right)) {\n errors.push('Operands must be expressions');\n return { errors };\n }\n validateDerive(expr.right, state, errors);\n validateDerive(expr.left, state, errors);\n return { errors };\n }\n\n // 3. Template literal: `Hello there ${derive(getName())}` or `static text`\n if (t.isTemplateLiteral(expr)) {\n if (expr.expressions.length === 0) {\n return { errors };\n }\n if (\n !expr.expressions.some(\n (expression) =>\n t.isExpression(expression) &&\n validateDerive(expression, state, errors).errors.length === 0\n )\n ) {\n errors.push('Expression does not use an allowed call expression');\n }\n return {\n errors,\n };\n }\n\n // 4. Static literals (string, number, boolean, null)\n if (t.isStringLiteral(expr)) {\n return { errors };\n }\n\n if (t.isNumericLiteral(expr)) {\n return { errors };\n }\n\n if (t.isBooleanLiteral(expr)) {\n return { errors };\n }\n\n if (t.isNullLiteral(expr)) {\n return { errors };\n }\n\n // Fallthrough: expression type not supported (e.g., plain identifiers/variables)\n errors.push('Variables are not allowed');\n return { errors };\n}\n\n/**\n * Takes in a call expression to check if:\n * - it has exactly one argument\n * - the argument is a call expression\n * Example: derive(getName())\n */\nfunction validateDeclareStaticExpression(\n expr: t.CallExpression,\n errors: string[]\n): {\n errors: string[];\n} {\n // Validate that the function has 1 argument\n if (expr.arguments.length !== 1) {\n errors.push('derive() must have one argument');\n return { errors };\n }\n const [onlyArg] = expr.arguments;\n\n // Await expression: derive(await ...)\n if (t.isAwaitExpression(onlyArg)) {\n // Validate that the awaited expression is a call expression\n if (!t.isCallExpression(onlyArg.argument)) {\n errors.push('derive() must have a call expression as the argument');\n return { errors };\n }\n // Valid: derive(await someFunction())\n return { errors };\n }\n\n // Validate that the argument is a call expression\n if (!t.isCallExpression(onlyArg)) {\n errors.push('derive() must have a call expression as the argument');\n return { errors };\n }\n\n return { errors };\n}\n\n/**\n * Validate that an expression is a number literal\n */\nfunction validateExpressionIsNumericLiteral(expr: t.Expression): {\n errors: string[];\n value?: number;\n} {\n let candidateValue: number | undefined;\n if (t.isNumericLiteral(expr)) {\n candidateValue = expr.value;\n } else if (t.isUnaryExpression(expr) && t.isNumericLiteral(expr.argument)) {\n // Note: taking the absolute value of the number literal\n candidateValue = expr.argument.value;\n }\n\n // validate is integer\n if (candidateValue !== undefined && !Number.isInteger(candidateValue)) {\n return { errors: ['Expression is not an integer'] };\n }\n\n // no value found\n if (candidateValue === undefined) {\n return { errors: ['Expression is not a number literal'] };\n }\n\n return { errors: [], value: candidateValue };\n}\n"],"mappings":";;;;;;;;;;;;;;;AAoBA,SAAgB,4BACd,cACA,OAUA;;CACA,MAAM,WAAW,aAAa;CAC9B,MAAM,SAAmB,EAAE;AAG3B,KAAI,SAAS,UAAU,SAAS,GAAG;AACjC,SAAO,KAAK,sDAAsD;AAClE,SAAO,EAAE,QAAQ;;AAInB,KAAI,CAACA,aAAE,aAAa,SAAS,UAAU,GAAG,EAAE;AAC1C,SAAO,KACL,2HACD;AACD,SAAO,EAAE,QAAQ;;CAInB,MAAM,2BAA2BC,yDAAAA,wBAC/B,aAAa,IAAI,YAAY,CAAC,GAC/B;CAED,MAAM,WAAA,wBAAU,yBAAyB,YAAA,QAAA,0BAAA,KAAA,IAAA,KAAA,IAAA,sBAAS;CAClD,MAAM,mBAAmB,2BACvB,yBAAyB,QACzB,MACD;AAED,KAAI,iBAAiB,SAAS,EAC5B,QAAO,EAAE,QAAQ,kBAAkB;AAGrC,KAAI,YAAY,KAAA,KAAa,CAAC,MAAM,SAAS,WAAW,SAAS;AAE/D,iBAAe,SAAS,UAAU,IAAI,OAAO,OAAO;AACpD,MAAI,OAAO,SAAS,GAAG;AACrB,UAAO,KACL,GAAG,2BAA2B,yBAAyB,OAAO,CAC/D;AACD,UAAO,KACL,2HACD;AACD,UAAO,EAAE,QAAQ;;;CAQrB,MAAM,uBACJ,MAAM,SAAS,WAAW,WAAW,YAAY,KAAA;CAGnD,IAAI;CACJ,IAAI;CACJ,IAAI;CACJ,IAAI;CACJ,IAAI;CACJ,IAAI;AACJ,KAAI,SAAS,UAAU,WAAW,EAChC,QAAO;EACL;EACA;EACA,kBAAkB,wBAAwB,KAAA;EAC3C;AAEH,KAAID,aAAE,mBAAmB,SAAS,UAAU,GAAG,EAAE;EA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E,iBAAiB,KAAK,CAC1B,QAAO,EAAE,QAAQ;AAGnB,KAAIA,aAAE,iBAAiB,KAAK,CAC1B,QAAO,EAAE,QAAQ;AAGnB,KAAIA,aAAE,cAAc,KAAK,CACvB,QAAO,EAAE,QAAQ;AAInB,QAAO,KAAK,4BAA4B;AACxC,QAAO,EAAE,QAAQ;;;;;;;;AASnB,SAAS,gCACP,MACA,QAGA;AAEA,KAAI,KAAK,UAAU,WAAW,GAAG;AAC/B,SAAO,KAAK,kCAAkC;AAC9C,SAAO,EAAE,QAAQ;;CAEnB,MAAM,CAAC,WAAW,KAAK;AAGvB,KAAIA,aAAE,kBAAkB,QAAQ,EAAE;AAEhC,MAAI,CAACA,aAAE,iBAAiB,QAAQ,SAAS,EAAE;AACzC,UAAO,KAAK,uDAAuD;AACnE,UAAO,EAAE,QAAQ;;AAGnB,SAAO,EAAE,QAAQ;;AAInB,KAAI,CAACA,aAAE,iBAAiB,QAAQ,EAAE;AAChC,SAAO,KAAK,uDAAuD;AACnE,SAAO,EAAE,QAAQ;;AAGnB,QAAO,EAAE,QAAQ;;;;;AAMnB,SAAS,mCAAmC,MAG1C;CACA,IAAI;AACJ,KAAIA,aAAE,iBAAiB,KAAK,CAC1B,kBAAiB,KAAK;UACbA,aAAE,kBAAkB,KAAK,IAAIA,aAAE,iBAAiB,KAAK,SAAS,CAEvE,kBAAiB,KAAK,SAAS;AAIjC,KAAI,mBAAmB,KAAA,KAAa,CAAC,OAAO,UAAU,eAAe,CACnE,QAAO,EAAE,QAAQ,CAAC,+BAA+B,EAAE;AAIrD,KAAI,mBAAmB,KAAA,EACrB,QAAO,EAAE,QAAQ,CAAC,qCAAqC,EAAE;AAG3D,QAAO;EAAE,QAAQ,EAAE;EAAE,OAAO;EAAgB"}
|
|
1
|
+
{"version":3,"file":"validateTranslationFunction.js","names":["t","resolveStaticExpression","getCalleeNameFromExpression","getTrackedVariable"],"sources":["../../../src/transform/validation/validateTranslationFunction.ts"],"sourcesContent":["import * as t from '@babel/types';\nimport {\n GT_OTHER_FUNCTIONS,\n USEGT_CALLBACK_OPTIONS,\n} from '../../utils/constants/gt/constants';\nimport { TransformState } from '../../state/types';\nimport { getCalleeNameFromExpression } from '../../utils/parsing/getCalleeNameFromExpression';\nimport {\n resolveStaticExpression,\n type ResolveStaticExpressionError,\n} from '../../utils/string-expressions/resolveStaticExpression';\nimport { getTrackedVariable } from '../getTrackedVariable';\nimport { NodePath } from '@babel/traverse';\n\n/**\n * Validate useGT_callback / getGT_callback / msg() / t()\n * - first argument must be a statically resolvable string expression\n * (string literal, template literal, binary '+' concatenation, or derive() call)\n * - second argument, if present, $id field + $context field must be a string literal\n */\nexport function validateTranslationFunction(\n callExprPath: NodePath<t.CallExpression>,\n state: TransformState\n): {\n errors: string[];\n content?: string;\n context?: string;\n hash?: string;\n id?: string;\n maxChars?: number;\n format?: string;\n requiresReview?: boolean;\n hasDeriveContext?: boolean;\n} {\n const callExpr = callExprPath.node;\n const errors: string[] = [];\n\n // Validate that the function has at least 1 argument\n if (callExpr.arguments.length < 1) {\n errors.push('registration function must have at least 1 argument');\n return { errors };\n }\n\n // Validate first argument\n if (!t.isExpression(callExpr.arguments[0])) {\n errors.push(\n 'registration function must use a string literal or derive() call as the first argument. Variable content is not allowed.'\n );\n return { errors };\n }\n\n // Try to resolve the expression to a static string (handles concat, nested templates, etc.)\n const resolvedStaticExpression = resolveStaticExpression(\n callExprPath.get('arguments')[0] as NodePath<t.Expression>\n );\n // TODO: until we implement derivation, we will only need to check the first value\n const content = resolvedStaticExpression.values?.[0];\n const resolutionErrors = getResolutionErrorMessages(\n resolvedStaticExpression.errors,\n false\n );\n\n if (resolutionErrors.length > 0) {\n return { errors: resolutionErrors };\n }\n\n if (content === undefined && !state.settings.autoderive.strings) {\n // Not a static expression — check if it contains a derive() function invocation\n validateDerive(callExpr.arguments[0], state, errors);\n if (errors.length > 0) {\n errors.push(\n ...getResolutionErrorMessages(resolvedStaticExpression.errors)\n );\n errors.push(\n 'registration function must use a string literal or derive() call as the first argument. Variable content is not allowed.'\n );\n return { errors };\n }\n }\n\n // TODO: hasDeriveContext should be refactored to enforce no hash generated HERE in this function\n // instead of passing that information outside of this function.\n // We skip hash gen with autoderive, derive in content, and derive in $context. This flag is being\n // reused for all 3 cases.\n const contentHasAutoderive =\n state.settings.autoderive.strings && content === undefined;\n\n // Validate second argument\n let context: string | undefined;\n let id: string | undefined;\n let hash: string | undefined;\n let maxChars: number | undefined;\n let format: string | undefined;\n let requiresReview: boolean | undefined;\n let hasDeriveContext: boolean | undefined;\n if (callExpr.arguments.length === 1) {\n return {\n errors,\n content,\n hasDeriveContext: contentHasAutoderive || undefined,\n };\n }\n if (t.isObjectExpression(callExpr.arguments[1])) {\n const objExprPath = callExprPath.get(\n 'arguments'\n )[1] as NodePath<t.ObjectExpression>;\n const contextProperty = validatePropertyFromObjectExpression(\n objExprPath,\n USEGT_CALLBACK_OPTIONS.$context,\n 'string-or-derive',\n state\n );\n errors.push(...contextProperty.errors);\n context = contextProperty.value as string | undefined;\n hasDeriveContext =\n contentHasAutoderive || contextProperty.hasDeriveExpression;\n const idProperty = validatePropertyFromObjectExpression(\n objExprPath,\n USEGT_CALLBACK_OPTIONS.$id,\n 'string'\n );\n errors.push(...idProperty.errors);\n id = idProperty.value;\n const maxCharsProperty = validatePropertyFromObjectExpression(\n objExprPath,\n USEGT_CALLBACK_OPTIONS.$maxChars,\n 'number'\n );\n errors.push(...maxCharsProperty.errors);\n maxChars = maxCharsProperty.value;\n const hashProperty = validatePropertyFromObjectExpression(\n objExprPath,\n USEGT_CALLBACK_OPTIONS.$_hash,\n 'string'\n );\n errors.push(...hashProperty.errors);\n hash = hashProperty.value;\n const formatProperty = validatePropertyFromObjectExpression(\n objExprPath,\n USEGT_CALLBACK_OPTIONS.$format,\n 'string'\n );\n errors.push(...formatProperty.errors);\n format = formatProperty.value;\n const requiresReviewProperty = validatePropertyFromObjectExpression(\n objExprPath,\n USEGT_CALLBACK_OPTIONS.$requiresReview,\n 'boolean'\n );\n errors.push(...requiresReviewProperty.errors);\n requiresReview = requiresReviewProperty.value;\n }\n\n return {\n errors,\n content,\n context,\n id,\n hash,\n maxChars,\n format,\n requiresReview,\n hasDeriveContext,\n };\n}\n\n/**\n * Validate useTranslations_callback / getTranslations_callback\n * - always valid (arguments can be dynamic)\n */\n// eslint-disable-next-line no-unused-vars\nexport function validateUseTranslationsCallback(_callExpr: t.CallExpression): {\n errors: string[];\n} {\n const errors: string[] = [];\n return { errors };\n}\n\n/**\n * Validate useMessages_callback / getMessages_callback\n * - always valid\n */\n// eslint-disable-next-line no-unused-vars\nexport function validateUseMessagesCallback(_callExpr: t.CallExpression): {\n errors: string[];\n} {\n const errors: string[] = [];\n return { errors };\n}\n\n/* =============================== */\n/* Helper Functions */\n/* =============================== */\n\nfunction getResolutionErrorMessages(\n errors: ResolveStaticExpressionError[],\n includeDynamic = true\n): string[] {\n return errors\n .filter((error) => includeDynamic || error.kind !== 'dynamic-expression')\n .map(({ message }) => message);\n}\n\n/**\n * Validate a property from an object expression\n * @param objExpr - The object expression to validate\n * @param name - The name of the property to validate\n * @returns The validated property\n */\nfunction validatePropertyFromObjectExpression(\n objExprPath: NodePath<t.ObjectExpression>,\n name: string,\n type: 'string'\n): { errors: string[]; value?: string };\nfunction validatePropertyFromObjectExpression(\n objExprPath: NodePath<t.ObjectExpression>,\n name: string,\n type: 'number'\n): { errors: string[]; value?: number };\nfunction validatePropertyFromObjectExpression(\n objExprPath: NodePath<t.ObjectExpression>,\n name: string,\n type: 'boolean'\n): { errors: string[]; value?: boolean };\nfunction validatePropertyFromObjectExpression(\n objExprPath: NodePath<t.ObjectExpression>,\n name: string,\n type: 'string-or-derive',\n state: TransformState\n): { errors: string[]; value?: string; hasDeriveExpression?: boolean };\nfunction validatePropertyFromObjectExpression(\n objExprPath: NodePath<t.ObjectExpression>,\n name: string,\n type: 'string' | 'number' | 'boolean' | 'string-or-derive',\n state?: TransformState\n): {\n errors: string[];\n value?: string | number | boolean;\n hasDeriveExpression?: boolean;\n} {\n const result: {\n errors: string[];\n value?: string | number | boolean;\n hasDeriveExpression?: boolean;\n } = { errors: [] };\n let valuePath: NodePath<t.ObjectProperty> | undefined;\n for (const propertyPath of objExprPath.get('properties')) {\n if (!propertyPath.isObjectProperty()) {\n continue;\n }\n const property = propertyPath.node;\n if (t.isIdentifier(property.key) && property.key.name === name) {\n valuePath = propertyPath;\n break;\n }\n if (t.isStringLiteral(property.key) && property.key.value === name) {\n valuePath = propertyPath;\n break;\n }\n }\n\n // return result if no value found\n if (!valuePath) {\n return result;\n }\n\n const value = valuePath.node;\n\n // validate value\n if (!t.isExpression(value.value)) {\n result.errors.push(\n `registration function must use a string literal for its ${name} field. Variable content is not allowed.`\n );\n return result;\n }\n\n // extract value\n if (type === 'string-or-derive') {\n const resolved = resolveStaticExpression(\n valuePath.get('value') as NodePath<t.Expression>\n );\n const resolutionErrors = getResolutionErrorMessages(resolved.errors, false);\n // TODO: until we implement derivation, we will only need to check the first value\n if (resolved.values?.[0] !== undefined) {\n result.value = resolved.values[0];\n } else if (resolutionErrors.length > 0) {\n result.errors.push(...resolutionErrors);\n } else if (state) {\n // Static resolution failed — check if it's a valid derive() expression\n const deriveErrors: string[] = [];\n validateDerive(value.value, state, deriveErrors);\n if (deriveErrors.length === 0) {\n result.hasDeriveExpression = true;\n } else {\n result.errors.push(\n ...getResolutionErrorMessages(resolved.errors),\n ...deriveErrors\n );\n }\n } else {\n result.errors.push(...getResolutionErrorMessages(resolved.errors));\n }\n } else {\n const validatedValue =\n type === 'string'\n ? validateExpressionIsStringLiteral(value.value)\n : type === 'boolean'\n ? validateExpressionIsBooleanLiteral(value.value)\n : validateExpressionIsNumericLiteral(value.value);\n result.errors.push(...validatedValue.errors);\n result.value = validatedValue.value;\n }\n\n return result;\n}\n\n/**\n * Validate that an expression is a string literal\n */\nfunction validateExpressionIsStringLiteral(expr: t.Expression): {\n errors: string[];\n value?: string;\n} {\n if (t.isStringLiteral(expr)) {\n return { errors: [], value: expr.value };\n }\n if (t.isTemplateLiteral(expr) && expr.expressions.length === 0) {\n return { errors: [], value: expr.quasis[0]?.value.cooked };\n }\n return { errors: ['Expression is not a string literal'] };\n}\n\n/**\n * Validates if an expression uses the derive() function correctly\n */\nexport function validateDerive(\n expr: t.Expression,\n state: TransformState,\n errors: string[]\n): { errors: string[] } {\n if (!expr) {\n errors.push('Expression is empty');\n return { errors };\n }\n\n // 1. Direct call: derive(node)\n if (t.isCallExpression(expr)) {\n // Find the canonical function name\n const { namespaceName, functionName } = getCalleeNameFromExpression(expr);\n // Get the canonical function name\n const { canonicalName, type } = getTrackedVariable(\n state.scopeTracker,\n namespaceName,\n functionName\n );\n if (!canonicalName) {\n errors.push('Expression does not use an allowed call expression');\n return { errors };\n }\n // Validate the function is actually the GT derive function\n if (\n type !== 'generaltranslation' ||\n (canonicalName !== GT_OTHER_FUNCTIONS.declareStatic &&\n canonicalName !== GT_OTHER_FUNCTIONS.derive)\n ) {\n errors.push('Expression does not use an allowed call expression');\n return { errors };\n }\n // Validate that the call expression has exactly one argument and the argument is a call expression\n validateDeclareStaticExpression(expr, errors);\n return { errors };\n }\n\n // 2. String concatenation: \"Hello there \" + derive(getName())\n if (t.isBinaryExpression(expr) && expr.operator === '+') {\n if (!t.isExpression(expr.left) || !t.isExpression(expr.right)) {\n errors.push('Operands must be expressions');\n return { errors };\n }\n validateDerive(expr.right, state, errors);\n validateDerive(expr.left, state, errors);\n return { errors };\n }\n\n // 3. Template literal: `Hello there ${derive(getName())}` or `static text`\n if (t.isTemplateLiteral(expr)) {\n if (expr.expressions.length === 0) {\n return { errors };\n }\n if (\n !expr.expressions.some(\n (expression) =>\n t.isExpression(expression) &&\n validateDerive(expression, state, errors).errors.length === 0\n )\n ) {\n errors.push('Expression does not use an allowed call expression');\n }\n return {\n errors,\n };\n }\n\n // 4. Static literals (string, number, boolean, null)\n if (t.isStringLiteral(expr)) {\n return { errors };\n }\n\n if (t.isNumericLiteral(expr)) {\n return { errors };\n }\n\n if (t.isBooleanLiteral(expr)) {\n return { errors };\n }\n\n if (t.isNullLiteral(expr)) {\n return { errors };\n }\n\n // Fallthrough: expression type not supported (e.g., plain identifiers/variables)\n errors.push('Variables are not allowed');\n return { errors };\n}\n\n/**\n * Takes in a call expression to check if:\n * - it has exactly one argument\n * - the argument is a call expression\n * Example: derive(getName())\n */\nfunction validateDeclareStaticExpression(\n expr: t.CallExpression,\n errors: string[]\n): {\n errors: string[];\n} {\n // Validate that the function has 1 argument\n if (expr.arguments.length !== 1) {\n errors.push('derive() must have one argument');\n return { errors };\n }\n const [onlyArg] = expr.arguments;\n\n // Await expression: derive(await ...)\n if (t.isAwaitExpression(onlyArg)) {\n // Validate that the awaited expression is a call expression\n if (!t.isCallExpression(onlyArg.argument)) {\n errors.push('derive() must have a call expression as the argument');\n return { errors };\n }\n // Valid: derive(await someFunction())\n return { errors };\n }\n\n // Validate that the argument is a call expression\n if (!t.isCallExpression(onlyArg)) {\n errors.push('derive() must have a call expression as the argument');\n return { errors };\n }\n\n return { errors };\n}\n\n/**\n * Validate that an expression is a boolean literal (strictly `true` or\n * `false` — never string \"true\"/\"false\" or a dynamic expression).\n *\n * NOTE: a standalone predicate with the same logic exists at\n * `../../utils/validation/validateExpressionIsBooleanLiteral` (returns a\n * plain boolean). This local copy returns `{ errors, value }` to match the\n * interface of the sibling string/number validators in this file — the same\n * local-vs-utility duality those validators already have.\n */\nfunction validateExpressionIsBooleanLiteral(expr: t.Expression): {\n errors: string[];\n value?: boolean;\n} {\n if (t.isBooleanLiteral(expr)) {\n return { errors: [], value: expr.value };\n }\n return { errors: ['Expression is not a boolean literal'] };\n}\n\n/**\n * Validate that an expression is a number literal\n */\nfunction validateExpressionIsNumericLiteral(expr: t.Expression): {\n errors: string[];\n value?: number;\n} {\n let candidateValue: number | undefined;\n if (t.isNumericLiteral(expr)) {\n candidateValue = expr.value;\n } else if (t.isUnaryExpression(expr) && t.isNumericLiteral(expr.argument)) {\n // Note: taking the absolute value of the number literal\n candidateValue = expr.argument.value;\n }\n\n // validate is integer\n if (candidateValue !== undefined && !Number.isInteger(candidateValue)) {\n return { errors: ['Expression is not an integer'] };\n }\n\n // no value found\n if (candidateValue === undefined) {\n return { errors: ['Expression is not a number literal'] };\n }\n\n return { errors: [], value: candidateValue };\n}\n"],"mappings":";;;;;;;;;;;;;;;AAoBA,SAAgB,4BACd,cACA,OAWA;;CACA,MAAM,WAAW,aAAa;CAC9B,MAAM,SAAmB,EAAE;AAG3B,KAAI,SAAS,UAAU,SAAS,GAAG;AACjC,SAAO,KAAK,sDAAsD;AAClE,SAAO,EAAE,QAAQ;;AAInB,KAAI,CAACA,aAAE,aAAa,SAAS,UAAU,GAAG,EAAE;AAC1C,SAAO,KACL,2HACD;AACD,SAAO,EAAE,QAAQ;;CAInB,MAAM,2BAA2BC,yDAAAA,wBAC/B,aAAa,IAAI,YAAY,CAAC,GAC/B;CAED,MAAM,WAAA,wBAAU,yBAAyB,YAAA,QAAA,0BAAA,KAAA,IAAA,KAAA,IAAA,sBAAS;CAClD,MAAM,mBAAmB,2BACvB,yBAAyB,QACzB,MACD;AAED,KAAI,iBAAiB,SAAS,EAC5B,QAAO,EAAE,QAAQ,kBAAkB;AAGrC,KAAI,YAAY,KAAA,KAAa,CAAC,MAAM,SAAS,WAAW,SAAS;AAE/D,iBAAe,SAAS,UAAU,IAAI,OAAO,OAAO;AACpD,MAAI,OAAO,SAAS,GAAG;AACrB,UAAO,KACL,GAAG,2BAA2B,yBAAyB,OAAO,CAC/D;AACD,UAAO,KACL,2HACD;AACD,UAAO,EAAE,QAAQ;;;CAQrB,MAAM,uBACJ,MAAM,SAAS,WAAW,WAAW,YAAY,KAAA;CAGnD,IAAI;CACJ,IAAI;CACJ,IAAI;CACJ,IAAI;CACJ,IAAI;CACJ,IAAI;CACJ,IAAI;AACJ,KAAI,SAAS,UAAU,WAAW,EAChC,QAAO;EACL;EACA;EACA,kBAAkB,wBAAwB,KAAA;EAC3C;AAEH,KAAID,aAAE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C,KAAI,mBAAmB,KAAA,KAAa,CAAC,OAAO,UAAU,eAAe,CACnE,QAAO,EAAE,QAAQ,CAAC,+BAA+B,EAAE;AAIrD,KAAI,mBAAmB,KAAA,EACrB,QAAO,EAAE,QAAQ,CAAC,qCAAqC,EAAE;AAG3D,QAAO;EAAE,QAAQ,EAAE;EAAE,OAAO;EAAgB"}
|
|
@@ -2,11 +2,12 @@ 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, id, maxChars, dataFormat, }: {
|
|
5
|
+
export default function hashSource({ source, context, id, maxChars, requiresReview, dataFormat, }: {
|
|
6
6
|
source: JsxChildren | string;
|
|
7
7
|
context?: string;
|
|
8
8
|
id?: string;
|
|
9
9
|
maxChars?: number;
|
|
10
|
+
requiresReview?: boolean;
|
|
10
11
|
dataFormat: DataFormat;
|
|
11
12
|
}): string;
|
|
12
13
|
//# sourceMappingURL=calculateHash.d.ts.map
|
|
@@ -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,EAAE,EACF,QAAQ,EACR,UAAU,GACX,EAAE;IACD,MAAM,EAAE,WAAW,GAAG,MAAM,CAAC;IAC7B,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,UAAU,EAAE,UAAU,CAAC;CACxB,GAAG,MAAM,
|
|
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,EAAE,EACF,QAAQ,EACR,cAAc,EACd,UAAU,GACX,EAAE;IACD,MAAM,EAAE,WAAW,GAAG,MAAM,CAAC;IAC7B,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,UAAU,EAAE,UAAU,CAAC;CACxB,GAAG,MAAM,CAwBT"}
|
|
@@ -8,12 +8,13 @@ let generaltranslation_id = require("generaltranslation/id");
|
|
|
8
8
|
/**
|
|
9
9
|
* Given jsx children, calculate hash
|
|
10
10
|
*/
|
|
11
|
-
function hashSource({ source, context, id, maxChars, dataFormat }) {
|
|
11
|
+
function hashSource({ source, context, id, maxChars, requiresReview, dataFormat }) {
|
|
12
12
|
if (dataFormat === "ICU" || dataFormat === "I18NEXT") return (0, generaltranslation_id.hashSource)({
|
|
13
13
|
source,
|
|
14
14
|
context,
|
|
15
15
|
id,
|
|
16
16
|
maxChars,
|
|
17
|
+
requiresReview,
|
|
17
18
|
dataFormat
|
|
18
19
|
});
|
|
19
20
|
if (containsStatic(source)) return "";
|
|
@@ -22,6 +23,7 @@ function hashSource({ source, context, id, maxChars, dataFormat }) {
|
|
|
22
23
|
context,
|
|
23
24
|
id,
|
|
24
25
|
maxChars,
|
|
26
|
+
requiresReview,
|
|
25
27
|
dataFormat
|
|
26
28
|
});
|
|
27
29
|
}
|
|
@@ -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 id,\n maxChars,\n dataFormat,\n}: {\n source: JsxChildren | string;\n context?: string;\n id?: string;\n maxChars?: number;\n dataFormat: DataFormat;\n}): string {\n // No change needed for ICU or I18NEXT\n if (dataFormat === 'ICU' || dataFormat === 'I18NEXT') {\n return _hashSource({
|
|
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 id,\n maxChars,\n requiresReview,\n dataFormat,\n}: {\n source: JsxChildren | string;\n context?: string;\n id?: string;\n maxChars?: number;\n requiresReview?: boolean;\n dataFormat: DataFormat;\n}): string {\n // No change needed for ICU or I18NEXT\n if (dataFormat === 'ICU' || dataFormat === 'I18NEXT') {\n return _hashSource({\n source,\n context,\n id,\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({\n source,\n context,\n id,\n maxChars,\n requiresReview,\n dataFormat,\n });\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,IACA,UACA,gBACA,cAQS;AAET,KAAI,eAAe,SAAS,eAAe,UACzC,SAAA,GAAA,sBAAA,YAAmB;EACjB;EACA;EACA;EACA;EACA;EACA;EACD,CAAC;AAGJ,KAAI,eAAe,OAAO,CACxB,QAAO;AAET,SAAA,GAAA,sBAAA,YAAmB;EACjB;EACA;EACA;EACA;EACA;EACA;EACD,CAAC;;;;;;AAWJ,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"}
|
|
@@ -104,7 +104,8 @@ export declare enum USEGT_CALLBACK_OPTIONS {
|
|
|
104
104
|
$context = "$context",
|
|
105
105
|
$maxChars = "$maxChars",
|
|
106
106
|
$_hash = "$_hash",
|
|
107
|
-
$format = "$format"
|
|
107
|
+
$format = "$format",
|
|
108
|
+
$requiresReview = "$requiresReview"
|
|
108
109
|
}
|
|
109
110
|
/**
|
|
110
111
|
* Maps GT Component Types to their minified names
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../../../src/utils/constants/gt/constants.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,oBAAY,kBAAkB;IAC5B,CAAC,MAAM;IACP,EAAE,OAAO;IACT,GAAG,QAAQ;IACX,QAAQ,aAAa;IACrB,QAAQ,aAAa;IACrB,YAAY,iBAAiB;IAC7B,GAAG,QAAQ;IACX,MAAM,WAAW;IACjB,M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ACH,eAAO,MAAM,oBAAoB,aAA4B,CAAC;AAE9D;;GAEG;AACH,eAAO,MAAM,YAAY,aAUvB,CAAC;AAEH;;GAEG;AACH,oBAAY,sBAAsB;IAChC,GAAG,QAAQ;IACX,QAAQ,aAAa;IACrB,SAAS,cAAc;IACvB,MAAM,WAAW;IACjB,OAAO,YAAY;
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../../../src/utils/constants/gt/constants.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,oBAAY,kBAAkB;IAC5B,CAAC,MAAM;IACP,EAAE,OAAO;IACT,GAAG,QAAQ;IACX,QAAQ,aAAa;IACrB,QAAQ,aAAa;IACrB,YAAY,iBAAiB;IAC7B,GAAG,QAAQ;IACX,MAAM,WAAW;IACjB,MAAM,WAAW;IACjB,MAAM,WAAW;IACjB,MAAM,WAAW;IACjB,cAAc,mBAAmB;IACjC,sBAAsB,2BAA2B;IACjD,aAAa,kBAAkB;IAC/B,aAAa,kBAAkB;IAC/B,kBAAkB,uBAAuB;IACzC,kBAAkB,uBAAuB;CAC1C;AAED;;GAEG;AACH,oBAAY,2BAA2B;IACrC,KAAK,UAAU;IACf,KAAK,UAAU;IACf,eAAe,oBAAoB;IACnC,eAAe,oBAAoB;IACnC,WAAW,gBAAgB;IAC3B,WAAW,gBAAgB;CAC5B;AAED;;GAEG;AACH,oBAAY,kBAAkB;IAC5B,GAAG,QAAQ;IACX,aAAa,kBAAkB;IAC/B,CAAC,MAAM;IACP,MAAM,WAAW;IACjB,gCAAgC,qCAAqC;IACrE,6BAA6B,kCAAkC;CAChE;AAED;;GAEG;AACH,MAAM,MAAM,YAAY,GAAG,2BAA2B,GAAG,kBAAkB,CAAC;AAC5E;;GAEG;AACH,oBAAY,qBAAqB;IAC/B,cAAc,mBAAmB;IACjC,cAAc,mBAAmB;IACjC,wBAAwB,6BAA6B;IACrD,wBAAwB,6BAA6B;IACrD,oBAAoB,yBAAyB;IAC7C,oBAAoB,yBAAyB;CAC9C;AAED;;GAEG;AACH,eAAO,MAAM,yBAAyB,EAAE,MAAM,CAC5C,2BAA2B,EAC3B,qBAAqB,CAYtB,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,0BAA0B,wEAG7B,CAAC;AAEX;;GAEG;AACH,MAAM,MAAM,gBAAgB,GACxB,YAAY,GACZ,qBAAqB,GACrB,kBAAkB,CAAC;AAEvB;;GAEG;AACH,oBAAY,iBAAiB;IAC3B,OAAO,YAAY;IACnB,cAAc,mBAAmB;IACjC,cAAc,mBAAmB;IACjC,QAAQ,aAAa;IACrB,eAAe,oBAAoB;IACnC,gBAAgB,qBAAqB;IACrC,OAAO,YAAY;CACpB;AAED;;;;GAIG;AACH,eAAO,MAAM,oBAAoB,aAAsB,CAAC;AAExD;;;GAGG;AACH,eAAO,MAAM,oBAAoB,aAA4B,CAAC;AAE9D;;GAEG;AACH,eAAO,MAAM,YAAY,aAUvB,CAAC;AAEH;;GAEG;AACH,oBAAY,sBAAsB;IAChC,GAAG,QAAQ;IACX,QAAQ,aAAa;IACrB,SAAS,cAAc;IACvB,MAAM,WAAW;IACjB,OAAO,YAAY;IACnB,eAAe,oBAAoB;CACpC;AAED;;GAEG;AACH,eAAO,MAAM,yBAAyB;;;;;;;;;;;;;;CAc5B,CAAC"}
|
|
@@ -121,6 +121,7 @@ let USEGT_CALLBACK_OPTIONS = /* @__PURE__ */ function(USEGT_CALLBACK_OPTIONS) {
|
|
|
121
121
|
USEGT_CALLBACK_OPTIONS["$maxChars"] = "$maxChars";
|
|
122
122
|
USEGT_CALLBACK_OPTIONS["$_hash"] = "$_hash";
|
|
123
123
|
USEGT_CALLBACK_OPTIONS["$format"] = "$format";
|
|
124
|
+
USEGT_CALLBACK_OPTIONS["$requiresReview"] = "$requiresReview";
|
|
124
125
|
return USEGT_CALLBACK_OPTIONS;
|
|
125
126
|
}({});
|
|
126
127
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.js","names":[],"sources":["../../../../src/utils/constants/gt/constants.ts"],"sourcesContent":["/**\n * Different gt components\n */\nexport enum GT_COMPONENT_TYPES {\n T = 'T',\n Tx = 'Tx',\n Var = 'Var',\n Currency = 'Currency',\n DateTime = 'DateTime',\n RelativeTime = 'RelativeTime',\n Num = 'Num',\n Static = 'Static',\n Derive = 'Derive',\n Branch = 'Branch',\n Plural = 'Plural',\n LocaleSelector = 'LocaleSelector',\n GtInternalTranslateJsx = 'GtInternalTranslateJsx',\n GtInternalVar = 'GtInternalVar',\n GtInternalNum = 'GtInternalNum',\n GtInternalCurrency = 'GtInternalCurrency',\n GtInternalDateTime = 'GtInternalDateTime',\n}\n\n/**\n * GT functions that produce callbacks\n */\nexport enum GT_FUNCTIONS_WITH_CALLBACKS {\n useGT = 'useGT',\n getGT = 'getGT',\n useTranslations = 'useTranslations',\n getTranslations = 'getTranslations',\n useMessages = 'useMessages',\n getMessages = 'getMessages',\n}\n\n/**\n * Other GT functions\n */\nexport enum GT_OTHER_FUNCTIONS {\n msg = 'msg',\n declareStatic = 'declareStatic',\n t = 't',\n derive = 'derive',\n GtInternalRuntimeTranslateString = 'GtInternalRuntimeTranslateString',\n GtInternalRuntimeTranslateJsx = 'GtInternalRuntimeTranslateJsx',\n}\n\n/**\n * Different gt functions\n */\nexport type GT_FUNCTIONS = GT_FUNCTIONS_WITH_CALLBACKS | GT_OTHER_FUNCTIONS;\n/**\n * gt callback functions\n */\nexport enum GT_CALLBACK_FUNCTIONS {\n useGT_callback = 'useGT_callback',\n getGT_callback = 'getGT_callback',\n useTranslations_callback = 'useTranslations_callback',\n getTranslations_callback = 'getTranslations_callback',\n useMessages_callback = 'useMessages_callback',\n getMessages_callback = 'getMessages_callback',\n}\n\n/**\n * Maps GT Functions to their callback functions\n */\nexport const GT_FUNCTIONS_TO_CALLBACKS: Record<\n GT_FUNCTIONS_WITH_CALLBACKS,\n GT_CALLBACK_FUNCTIONS\n> = {\n [GT_FUNCTIONS_WITH_CALLBACKS.useGT]: GT_CALLBACK_FUNCTIONS.useGT_callback,\n [GT_FUNCTIONS_WITH_CALLBACKS.getGT]: GT_CALLBACK_FUNCTIONS.getGT_callback,\n [GT_FUNCTIONS_WITH_CALLBACKS.useTranslations]:\n GT_CALLBACK_FUNCTIONS.useTranslations_callback,\n [GT_FUNCTIONS_WITH_CALLBACKS.getTranslations]:\n GT_CALLBACK_FUNCTIONS.getTranslations_callback,\n [GT_FUNCTIONS_WITH_CALLBACKS.useMessages]:\n GT_CALLBACK_FUNCTIONS.useMessages_callback,\n [GT_FUNCTIONS_WITH_CALLBACKS.getMessages]:\n GT_CALLBACK_FUNCTIONS.getMessages_callback,\n};\n\n/**\n * GT derive functions\n */\nexport const GT_DERIVE_STRING_FUNCTIONS = [\n GT_OTHER_FUNCTIONS.declareStatic,\n GT_OTHER_FUNCTIONS.derive,\n] as const;\n\n/**\n * All gt functions (both regular and callback functions)\n */\nexport type GT_ALL_FUNCTIONS =\n | GT_FUNCTIONS\n | GT_CALLBACK_FUNCTIONS\n | GT_COMPONENT_TYPES;\n\n/**\n * GT import sources\n */\nexport enum GT_IMPORT_SOURCES {\n GT_NEXT = 'gt-next',\n GT_NEXT_CLIENT = 'gt-next/client',\n GT_NEXT_SERVER = 'gt-next/server',\n GT_REACT = 'gt-react',\n GT_REACT_CLIENT = 'gt-react/client',\n GT_REACT_BROWSER = 'gt-react/browser',\n GT_I18N = 'gt-i18n',\n}\n\n/**\n * Branch control props — not translatable content.\n * `branch` is the selector key; `data-*` props are HTML attributes ignored at runtime.\n * `data-*` is handled as a prefix check, not listed here.\n */\nexport const BRANCH_CONTROL_PROPS = new Set(['branch']);\n\n/**\n * Plural control props — not translatable content.\n * `n` is the count, `locales` is the locale hint.\n */\nexport const PLURAL_CONTROL_PROPS = new Set(['n', 'locales']);\n\n/**\n * Set of valid plural forms for Plural components\n */\nexport const PLURAL_FORMS = new Set([\n 'singular',\n 'plural',\n 'dual',\n 'zero',\n 'one',\n 'two',\n 'few',\n 'many',\n 'other',\n]);\n\n/**\n * Fields that must be string literals for useGT_callback / getGT_callback\n */\nexport enum USEGT_CALLBACK_OPTIONS {\n $id = '$id',\n $context = '$context',\n $maxChars = '$maxChars',\n $_hash = '$_hash',\n $format = '$format',\n}\n\n/**\n * Maps GT Component Types to their minified names\n */\nexport const MINIFY_CANONICAL_NAME_MAP = {\n [GT_COMPONENT_TYPES.Var]: 'v',\n [GT_COMPONENT_TYPES.GtInternalVar]: 'v',\n [GT_COMPONENT_TYPES.Num]: 'n',\n [GT_COMPONENT_TYPES.GtInternalNum]: 'n',\n [GT_COMPONENT_TYPES.Currency]: 'c',\n [GT_COMPONENT_TYPES.GtInternalCurrency]: 'c',\n [GT_COMPONENT_TYPES.DateTime]: 'd',\n [GT_COMPONENT_TYPES.GtInternalDateTime]: 'd',\n [GT_COMPONENT_TYPES.RelativeTime]: 'rt',\n [GT_COMPONENT_TYPES.Static]: 's',\n [GT_COMPONENT_TYPES.Derive]: 's',\n [GT_COMPONENT_TYPES.Branch]: 'b',\n [GT_COMPONENT_TYPES.Plural]: 'p',\n} as const;\n"],"mappings":";;;;;AAGA,IAAY,qBAAL,yBAAA,oBAAA;AACL,oBAAA,OAAA;AACA,oBAAA,QAAA;AACA,oBAAA,SAAA;AACA,oBAAA,cAAA;AACA,oBAAA,cAAA;AACA,oBAAA,kBAAA;AACA,oBAAA,SAAA;AACA,oBAAA,YAAA;AACA,oBAAA,YAAA;AACA,oBAAA,YAAA;AACA,oBAAA,YAAA;AACA,oBAAA,oBAAA;AACA,oBAAA,4BAAA;AACA,oBAAA,mBAAA;AACA,oBAAA,mBAAA;AACA,oBAAA,wBAAA;AACA,oBAAA,wBAAA;;KACD;;;;AAKD,IAAY,8BAAL,yBAAA,6BAAA;AACL,6BAAA,WAAA;AACA,6BAAA,WAAA;AACA,6BAAA,qBAAA;AACA,6BAAA,qBAAA;AACA,6BAAA,iBAAA;AACA,6BAAA,iBAAA;;KACD;;;;AAKD,IAAY,qBAAL,yBAAA,oBAAA;AACL,oBAAA,SAAA;AACA,oBAAA,mBAAA;AACA,oBAAA,OAAA;AACA,oBAAA,YAAA;AACA,oBAAA,sCAAA;AACA,oBAAA,mCAAA;;KACD;;;;AASD,IAAY,wBAAL,yBAAA,uBAAA;AACL,uBAAA,oBAAA;AACA,uBAAA,oBAAA;AACA,uBAAA,8BAAA;AACA,uBAAA,8BAAA;AACA,uBAAA,0BAAA;AACA,uBAAA,0BAAA;;KACD;;;;AAKD,MAAa,4BAGT;;;;;;;CAWH;;;;AAKD,MAAa,6BAA6B,CAAA,iBAAA,SAGzC;;;;AAaD,IAAY,oBAAL,yBAAA,mBAAA;AACL,mBAAA,aAAA;AACA,mBAAA,oBAAA;AACA,mBAAA,oBAAA;AACA,mBAAA,cAAA;AACA,mBAAA,qBAAA;AACA,mBAAA,sBAAA;AACA,mBAAA,aAAA;;KACD;;;;;;AAOD,MAAa,uBAAuB,IAAI,IAAI,CAAC,SAAS,CAAC;;;;;AAMvD,MAAa,uBAAuB,IAAI,IAAI,CAAC,KAAK,UAAU,CAAC;;;;AAK7D,MAAa,eAAe,IAAI,IAAI;CAClC;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACD,CAAC;;;;AAKF,IAAY,yBAAL,yBAAA,wBAAA;AACL,wBAAA,SAAA;AACA,wBAAA,cAAA;AACA,wBAAA,eAAA;AACA,wBAAA,YAAA;AACA,wBAAA,aAAA;;KACD;;;;AAKD,MAAa,4BAA4B;UACb;oBACU;UACV;oBACU;eACL;yBACU;eACV;yBACU;mBACN;aACN;aACA;aACA;aACA;CAC9B"}
|
|
1
|
+
{"version":3,"file":"constants.js","names":[],"sources":["../../../../src/utils/constants/gt/constants.ts"],"sourcesContent":["/**\n * Different gt components\n */\nexport enum GT_COMPONENT_TYPES {\n T = 'T',\n Tx = 'Tx',\n Var = 'Var',\n Currency = 'Currency',\n DateTime = 'DateTime',\n RelativeTime = 'RelativeTime',\n Num = 'Num',\n Static = 'Static',\n Derive = 'Derive',\n Branch = 'Branch',\n Plural = 'Plural',\n LocaleSelector = 'LocaleSelector',\n GtInternalTranslateJsx = 'GtInternalTranslateJsx',\n GtInternalVar = 'GtInternalVar',\n GtInternalNum = 'GtInternalNum',\n GtInternalCurrency = 'GtInternalCurrency',\n GtInternalDateTime = 'GtInternalDateTime',\n}\n\n/**\n * GT functions that produce callbacks\n */\nexport enum GT_FUNCTIONS_WITH_CALLBACKS {\n useGT = 'useGT',\n getGT = 'getGT',\n useTranslations = 'useTranslations',\n getTranslations = 'getTranslations',\n useMessages = 'useMessages',\n getMessages = 'getMessages',\n}\n\n/**\n * Other GT functions\n */\nexport enum GT_OTHER_FUNCTIONS {\n msg = 'msg',\n declareStatic = 'declareStatic',\n t = 't',\n derive = 'derive',\n GtInternalRuntimeTranslateString = 'GtInternalRuntimeTranslateString',\n GtInternalRuntimeTranslateJsx = 'GtInternalRuntimeTranslateJsx',\n}\n\n/**\n * Different gt functions\n */\nexport type GT_FUNCTIONS = GT_FUNCTIONS_WITH_CALLBACKS | GT_OTHER_FUNCTIONS;\n/**\n * gt callback functions\n */\nexport enum GT_CALLBACK_FUNCTIONS {\n useGT_callback = 'useGT_callback',\n getGT_callback = 'getGT_callback',\n useTranslations_callback = 'useTranslations_callback',\n getTranslations_callback = 'getTranslations_callback',\n useMessages_callback = 'useMessages_callback',\n getMessages_callback = 'getMessages_callback',\n}\n\n/**\n * Maps GT Functions to their callback functions\n */\nexport const GT_FUNCTIONS_TO_CALLBACKS: Record<\n GT_FUNCTIONS_WITH_CALLBACKS,\n GT_CALLBACK_FUNCTIONS\n> = {\n [GT_FUNCTIONS_WITH_CALLBACKS.useGT]: GT_CALLBACK_FUNCTIONS.useGT_callback,\n [GT_FUNCTIONS_WITH_CALLBACKS.getGT]: GT_CALLBACK_FUNCTIONS.getGT_callback,\n [GT_FUNCTIONS_WITH_CALLBACKS.useTranslations]:\n GT_CALLBACK_FUNCTIONS.useTranslations_callback,\n [GT_FUNCTIONS_WITH_CALLBACKS.getTranslations]:\n GT_CALLBACK_FUNCTIONS.getTranslations_callback,\n [GT_FUNCTIONS_WITH_CALLBACKS.useMessages]:\n GT_CALLBACK_FUNCTIONS.useMessages_callback,\n [GT_FUNCTIONS_WITH_CALLBACKS.getMessages]:\n GT_CALLBACK_FUNCTIONS.getMessages_callback,\n};\n\n/**\n * GT derive functions\n */\nexport const GT_DERIVE_STRING_FUNCTIONS = [\n GT_OTHER_FUNCTIONS.declareStatic,\n GT_OTHER_FUNCTIONS.derive,\n] as const;\n\n/**\n * All gt functions (both regular and callback functions)\n */\nexport type GT_ALL_FUNCTIONS =\n | GT_FUNCTIONS\n | GT_CALLBACK_FUNCTIONS\n | GT_COMPONENT_TYPES;\n\n/**\n * GT import sources\n */\nexport enum GT_IMPORT_SOURCES {\n GT_NEXT = 'gt-next',\n GT_NEXT_CLIENT = 'gt-next/client',\n GT_NEXT_SERVER = 'gt-next/server',\n GT_REACT = 'gt-react',\n GT_REACT_CLIENT = 'gt-react/client',\n GT_REACT_BROWSER = 'gt-react/browser',\n GT_I18N = 'gt-i18n',\n}\n\n/**\n * Branch control props — not translatable content.\n * `branch` is the selector key; `data-*` props are HTML attributes ignored at runtime.\n * `data-*` is handled as a prefix check, not listed here.\n */\nexport const BRANCH_CONTROL_PROPS = new Set(['branch']);\n\n/**\n * Plural control props — not translatable content.\n * `n` is the count, `locales` is the locale hint.\n */\nexport const PLURAL_CONTROL_PROPS = new Set(['n', 'locales']);\n\n/**\n * Set of valid plural forms for Plural components\n */\nexport const PLURAL_FORMS = new Set([\n 'singular',\n 'plural',\n 'dual',\n 'zero',\n 'one',\n 'two',\n 'few',\n 'many',\n 'other',\n]);\n\n/**\n * Fields that must be string literals for useGT_callback / getGT_callback\n */\nexport enum USEGT_CALLBACK_OPTIONS {\n $id = '$id',\n $context = '$context',\n $maxChars = '$maxChars',\n $_hash = '$_hash',\n $format = '$format',\n $requiresReview = '$requiresReview',\n}\n\n/**\n * Maps GT Component Types to their minified names\n */\nexport const MINIFY_CANONICAL_NAME_MAP = {\n [GT_COMPONENT_TYPES.Var]: 'v',\n [GT_COMPONENT_TYPES.GtInternalVar]: 'v',\n [GT_COMPONENT_TYPES.Num]: 'n',\n [GT_COMPONENT_TYPES.GtInternalNum]: 'n',\n [GT_COMPONENT_TYPES.Currency]: 'c',\n [GT_COMPONENT_TYPES.GtInternalCurrency]: 'c',\n [GT_COMPONENT_TYPES.DateTime]: 'd',\n [GT_COMPONENT_TYPES.GtInternalDateTime]: 'd',\n [GT_COMPONENT_TYPES.RelativeTime]: 'rt',\n [GT_COMPONENT_TYPES.Static]: 's',\n [GT_COMPONENT_TYPES.Derive]: 's',\n [GT_COMPONENT_TYPES.Branch]: 'b',\n [GT_COMPONENT_TYPES.Plural]: 'p',\n} as const;\n"],"mappings":";;;;;AAGA,IAAY,qBAAL,yBAAA,oBAAA;AACL,oBAAA,OAAA;AACA,oBAAA,QAAA;AACA,oBAAA,SAAA;AACA,oBAAA,cAAA;AACA,oBAAA,cAAA;AACA,oBAAA,kBAAA;AACA,oBAAA,SAAA;AACA,oBAAA,YAAA;AACA,oBAAA,YAAA;AACA,oBAAA,YAAA;AACA,oBAAA,YAAA;AACA,oBAAA,oBAAA;AACA,oBAAA,4BAAA;AACA,oBAAA,mBAAA;AACA,oBAAA,mBAAA;AACA,oBAAA,wBAAA;AACA,oBAAA,wBAAA;;KACD;;;;AAKD,IAAY,8BAAL,yBAAA,6BAAA;AACL,6BAAA,WAAA;AACA,6BAAA,WAAA;AACA,6BAAA,qBAAA;AACA,6BAAA,qBAAA;AACA,6BAAA,iBAAA;AACA,6BAAA,iBAAA;;KACD;;;;AAKD,IAAY,qBAAL,yBAAA,oBAAA;AACL,oBAAA,SAAA;AACA,oBAAA,mBAAA;AACA,oBAAA,OAAA;AACA,oBAAA,YAAA;AACA,oBAAA,sCAAA;AACA,oBAAA,mCAAA;;KACD;;;;AASD,IAAY,wBAAL,yBAAA,uBAAA;AACL,uBAAA,oBAAA;AACA,uBAAA,oBAAA;AACA,uBAAA,8BAAA;AACA,uBAAA,8BAAA;AACA,uBAAA,0BAAA;AACA,uBAAA,0BAAA;;KACD;;;;AAKD,MAAa,4BAGT;;;;;;;CAWH;;;;AAKD,MAAa,6BAA6B,CAAA,iBAAA,SAGzC;;;;AAaD,IAAY,oBAAL,yBAAA,mBAAA;AACL,mBAAA,aAAA;AACA,mBAAA,oBAAA;AACA,mBAAA,oBAAA;AACA,mBAAA,cAAA;AACA,mBAAA,qBAAA;AACA,mBAAA,sBAAA;AACA,mBAAA,aAAA;;KACD;;;;;;AAOD,MAAa,uBAAuB,IAAI,IAAI,CAAC,SAAS,CAAC;;;;;AAMvD,MAAa,uBAAuB,IAAI,IAAI,CAAC,KAAK,UAAU,CAAC;;;;AAK7D,MAAa,eAAe,IAAI,IAAI;CAClC;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACD,CAAC;;;;AAKF,IAAY,yBAAL,yBAAA,wBAAA;AACL,wBAAA,SAAA;AACA,wBAAA,cAAA;AACA,wBAAA,eAAA;AACA,wBAAA,YAAA;AACA,wBAAA,aAAA;AACA,wBAAA,qBAAA;;KACD;;;;AAKD,MAAa,4BAA4B;UACb;oBACU;UACV;oBACU;eACL;yBACU;eACV;yBACU;mBACN;aACN;aACA;aACA;aACA;CAC9B"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import * as t from '@babel/types';
|
|
2
|
+
/**
|
|
3
|
+
* Given an expression, check if it is a boolean literal
|
|
4
|
+
* Valid: true, false
|
|
5
|
+
* Invalid: 'true', "false", !!flag, someVar, 1
|
|
6
|
+
*/
|
|
7
|
+
export declare function validateExpressionIsBooleanLiteral(expr: t.Expression): boolean;
|
|
8
|
+
//# sourceMappingURL=validateExpressionIsBooleanLiteral.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validateExpressionIsBooleanLiteral.d.ts","sourceRoot":"","sources":["../../../src/utils/validation/validateExpressionIsBooleanLiteral.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,cAAc,CAAC;AAElC;;;;GAIG;AACH,wBAAgB,kCAAkC,CAChD,IAAI,EAAE,CAAC,CAAC,UAAU,GACjB,OAAO,CAET"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_runtime = require("../../_virtual/_rolldown/runtime.js");
|
|
3
|
+
let _babel_types = require("@babel/types");
|
|
4
|
+
_babel_types = require_runtime.__toESM(_babel_types);
|
|
5
|
+
//#region src/utils/validation/validateExpressionIsBooleanLiteral.ts
|
|
6
|
+
/**
|
|
7
|
+
* Given an expression, check if it is a boolean literal
|
|
8
|
+
* Valid: true, false
|
|
9
|
+
* Invalid: 'true', "false", !!flag, someVar, 1
|
|
10
|
+
*/
|
|
11
|
+
function validateExpressionIsBooleanLiteral(expr) {
|
|
12
|
+
return _babel_types.isBooleanLiteral(expr);
|
|
13
|
+
}
|
|
14
|
+
//#endregion
|
|
15
|
+
exports.validateExpressionIsBooleanLiteral = validateExpressionIsBooleanLiteral;
|
|
16
|
+
|
|
17
|
+
//# sourceMappingURL=validateExpressionIsBooleanLiteral.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validateExpressionIsBooleanLiteral.js","names":["t"],"sources":["../../../src/utils/validation/validateExpressionIsBooleanLiteral.ts"],"sourcesContent":["import * as t from '@babel/types';\n\n/**\n * Given an expression, check if it is a boolean literal\n * Valid: true, false\n * Invalid: 'true', \"false\", !!flag, someVar, 1\n */\nexport function validateExpressionIsBooleanLiteral(\n expr: t.Expression\n): boolean {\n return t.isBooleanLiteral(expr);\n}\n"],"mappings":";;;;;;;;;;AAOA,SAAgB,mCACd,MACS;AACT,QAAOA,aAAE,iBAAiB,KAAK"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@generaltranslation/compiler",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.27",
|
|
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",
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
"@babel/types": "^7.23.0",
|
|
26
26
|
"unplugin": "^2.3.10",
|
|
27
27
|
"@generaltranslation/format": "0.1.1",
|
|
28
|
-
"generaltranslation": "8.2.
|
|
28
|
+
"generaltranslation": "8.2.19"
|
|
29
29
|
},
|
|
30
30
|
"devDependencies": {
|
|
31
31
|
"@types/babel__core": "^7.20.0",
|