@generaltranslation/compiler 1.3.26 → 1.3.29
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/config.d.ts +12 -7
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +61 -6
- package/dist/index.js.map +1 -1
- package/dist/passes/basePass.d.ts.map +1 -1
- package/dist/passes/basePass.js +9 -10
- package/dist/passes/basePass.js.map +1 -1
- package/dist/processing/collection/processCallExpression.js +6 -3
- package/dist/processing/collection/processCallExpression.js.map +1 -1
- package/dist/processing/collection/processTaggedTemplateExpression.d.ts +1 -1
- package/dist/processing/collection/processTaggedTemplateExpression.js +1 -1
- package/dist/processing/collection/processTaggedTemplateExpression.js.map +1 -1
- package/dist/processing/jsx-insertion/processCallExpression.js.map +1 -1
- package/dist/processing/jsx-insertion/processProgram.d.ts.map +1 -1
- package/dist/processing/jsx-insertion/processProgram.js +1 -1
- package/dist/processing/jsx-insertion/processProgram.js.map +1 -1
- package/dist/processing/macro-expansion/processProgram.js +1 -1
- package/dist/processing/macro-expansion/processProgram.js.map +1 -1
- package/dist/processing/macro-expansion/processTaggedTemplateExpression.d.ts +1 -1
- package/dist/processing/macro-expansion/processTaggedTemplateExpression.js +1 -1
- package/dist/processing/macro-expansion/processTaggedTemplateExpression.js.map +1 -1
- package/dist/processing/processFunctionDeclaration.js +1 -1
- package/dist/processing/processFunctionExpression.js +1 -1
- package/dist/processing/runtime-translate/processProgram.d.ts.map +1 -1
- package/dist/processing/runtime-translate/processProgram.js +2 -1
- package/dist/processing/runtime-translate/processProgram.js.map +1 -1
- package/dist/state/StringCollector.d.ts +7 -3
- package/dist/state/StringCollector.d.ts.map +1 -1
- package/dist/state/StringCollector.js.map +1 -1
- package/dist/state/utils/initializeState.d.ts.map +1 -1
- package/dist/state/utils/initializeState.js +8 -5
- package/dist/state/utils/initializeState.js.map +1 -1
- package/dist/transform/injection/injectCallbackDeclaratorFunctionParameters.d.ts +1 -1
- package/dist/transform/injection/injectCallbackDeclaratorFunctionParameters.js +6 -5
- package/dist/transform/injection/injectCallbackDeclaratorFunctionParameters.js.map +1 -1
- package/dist/transform/jsx-children/constructJsxChildren.js.map +1 -1
- package/dist/transform/jsx-insertion/injectJsxInsertionImport.d.ts +2 -2
- package/dist/transform/jsx-insertion/injectJsxInsertionImport.d.ts.map +1 -1
- package/dist/transform/jsx-insertion/injectJsxInsertionImport.js +4 -3
- package/dist/transform/jsx-insertion/injectJsxInsertionImport.js.map +1 -1
- package/dist/transform/macro-expansion/injectMacroImport.d.ts +2 -2
- package/dist/transform/macro-expansion/injectMacroImport.d.ts.map +1 -1
- package/dist/transform/macro-expansion/injectMacroImport.js +4 -3
- package/dist/transform/macro-expansion/injectMacroImport.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 -2
- 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 -2
- 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/runtime-translate/injectRuntimeTranslateImport.d.ts +3 -2
- package/dist/transform/runtime-translate/injectRuntimeTranslateImport.d.ts.map +1 -1
- package/dist/transform/runtime-translate/injectRuntimeTranslateImport.js +4 -3
- package/dist/transform/runtime-translate/injectRuntimeTranslateImport.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 -1
- 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 +26 -4
- package/dist/transform/validation/validateTranslationFunction.js.map +1 -1
- package/dist/utils/calculateHash.d.ts +2 -2
- package/dist/utils/calculateHash.d.ts.map +1 -1
- package/dist/utils/calculateHash.js +3 -3
- package/dist/utils/calculateHash.js.map +1 -1
- package/dist/utils/constants/gt/constants.d.ts +3 -6
- package/dist/utils/constants/gt/constants.d.ts.map +1 -1
- package/dist/utils/constants/gt/constants.js +2 -5
- package/dist/utils/constants/gt/constants.js.map +1 -1
- package/dist/utils/constants/gt/helpers.d.ts +2 -1
- package/dist/utils/constants/gt/helpers.d.ts.map +1 -1
- package/dist/utils/constants/gt/helpers.js +15 -5
- package/dist/utils/constants/gt/helpers.js.map +1 -1
- package/dist/utils/constants/resolveIdentifier/isGTComponent.d.ts +1 -1
- package/dist/utils/constants/resolveIdentifier/isGTComponent.d.ts.map +1 -1
- package/dist/utils/constants/resolveIdentifier/isGTComponent.js +2 -3
- package/dist/utils/constants/resolveIdentifier/isGTComponent.js.map +1 -1
- package/dist/utils/parsing/isStringTranslationTaggedTemplate.d.ts +1 -1
- package/dist/utils/parsing/isStringTranslationTaggedTemplate.js +3 -3
- package/dist/utils/parsing/isStringTranslationTaggedTemplate.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 +3 -3
- package/dist/processing/index.d.ts +0 -15
- package/dist/processing/index.d.ts.map +0 -1
- package/dist/processing/index.js +0 -29
- package/dist/transform/jsx-children/index.d.ts +0 -2
- package/dist/transform/jsx-children/index.d.ts.map +0 -1
- package/dist/transform/jsx-children/index.js +0 -3
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constructJsxChildren.js","names":["IdObject","t","validateChildrenElement","dynamicContentError","generateDynamicContentErrorMessage","createErrorLocation","validateTemplateLiteral","validateUnaryExpression","structuralError","validateIdentifier","validateJsxCall","getCalleeNameFromJsxExpressionParam","getTrackedVariable","isVariableComponent","isGTComponent","isDeriveComponent","isReactComponent","validateChildrenFromArgs","isBranchComponent","getBranchComponentParameters","HTML_CONTENT_PROPS","validateStringLiteralPropertyFromArg","validateNameFieldForVarComponent","getVariableName","minifyCanonicalName"],"sources":["../../../src/transform/jsx-children/constructJsxChildren.ts"],"sourcesContent":["import {\n GTProp,\n HTML_CONTENT_PROPS,\n JsxChild,\n JsxChildren,\n JsxElement,\n Variable,\n VariableType as GTVariableType,\n} from '@generaltranslation/format/types';\nimport { TransformState } from '../../state/types';\nimport * as t from '@babel/types';\nimport type { NodePath } from '@babel/traverse';\nimport { validateIdentifier } from './validation/validateIdentifier';\nimport { validateTemplateLiteral } from './validation/validateTemplateLiteral';\nimport { validateChildrenElement } from './validation/validateChildrenElement';\nimport { getCalleeNameFromJsxExpressionParam } from './utils/getCalleeNameFromJsxExpressionParam';\nimport { getTrackedVariable } from '../getTrackedVariable';\nimport { isReactComponent } from '../../utils/constants/react/helpers';\nimport { REACT_COMPONENTS } from '../../utils/constants/react/constants';\nimport { validateChildrenFromArgs } from './validation/validateChildrenFromArgs';\nimport { IdObject } from './utils/id';\nimport { VariableType } from '../../state/ScopeTracker';\nimport {\n defaultVariableNames,\n getVariableName,\n isBranchComponent,\n isDeriveComponent,\n isGTComponent,\n isVariableComponent,\n minifyCanonicalName,\n} from '../../utils/constants/gt/helpers';\nimport { validateStringLiteralPropertyFromArg } from './validation/validateStringLiteralPropertyFromArg';\nimport { GT_COMPONENT_TYPES } from '../../utils/constants/gt/constants';\nimport { getBranchComponentParameters } from './utils/getBranchComponentParameters';\nimport { validateNameFieldForVarComponent } from './validation/validateNameFieldForVarComponent';\nimport { validateUnaryExpression } from './validation/validateUnaryExpression';\nimport {\n createErrorLocation,\n generateDynamicContentErrorMessage,\n} from '../../utils/errors';\nimport { validateJsxCall } from './validation/validateJsxCall';\nimport {\n JsxValidationError,\n dynamicContentError,\n structuralError,\n} from './errors';\n\n/**\n * Given the children of a <T> component, constructs a JsxChildren object.\n * Takes an Expression path.\n *\n * ONLY does JsxChildren construction + validation, no further processing on any children.\n *\n * On invalid children, quit immediately.\n *\n * The node checks intentionally happen before navigating with .get(). This\n * keeps runtime validation behavior stable while preserving NodePath scope for\n * future derivation work.\n */\nexport function constructJsxChildren(\n childrenPath: NodePath<t.Expression> | undefined,\n state: TransformState,\n id: IdObject = new IdObject()\n): { errors: JsxValidationError[]; value?: JsxChildren } {\n const errors: JsxValidationError[] = [];\n\n // Skip if no children\n if (!childrenPath) {\n return { errors, value: childrenPath };\n }\n\n const children = childrenPath.node;\n let value: JsxChildren | undefined;\n if (t.isArrayExpression(children)) {\n // Handle ArrayExpression\n value = [];\n const elementPaths = childrenPath.get('elements');\n\n for (let i = 0; i < children.elements.length; i++) {\n const child = children.elements[i];\n // Validate child\n if (!validateChildrenElement(child)) {\n errors.push(\n dynamicContentError(\n generateDynamicContentErrorMessage() +\n (child && createErrorLocation(child))\n )\n );\n return { errors };\n }\n\n // Special children edge cases: nullLiteral, booleanLiteral\n if (t.isBooleanLiteral(child) || t.isNullLiteral(child)) {\n continue;\n }\n\n // Construct JsxChild\n const childPath = elementPaths[i] as NodePath<\n Exclude<t.Expression, t.ArrayExpression>\n >;\n const validation = constructJsxChild(childPath, state, id);\n errors.push(...validation.errors);\n if (errors.length > 0) {\n return { errors };\n }\n // Skip if no value\n if (validation.value === undefined) continue;\n (value as JsxChild[]).push(validation.value);\n }\n } else {\n // Handle single child\n const validation = constructJsxChild(\n childrenPath as NodePath<Exclude<t.Expression, t.ArrayExpression>>,\n state,\n id\n );\n errors.push(...validation.errors);\n if (errors.length > 0) {\n return { errors };\n }\n value = validation.value;\n }\n\n return { errors, value };\n}\n\n/**\n * Given an Expression path, constructs a JsxChild.\n * @returns { errors: string[]; value?: JsxChild }\n */\nfunction constructJsxChild(\n childPath: NodePath<Exclude<t.Expression, t.ArrayExpression>>,\n state: TransformState,\n id: IdObject\n): { errors: JsxValidationError[]; value?: JsxChild } {\n const errors: JsxValidationError[] = [];\n const child = childPath.node;\n let value: JsxChild | undefined;\n\n if (t.isCallExpression(child)) {\n // Construct JsxElement\n const validation = constructJsxElement(\n childPath as NodePath<t.CallExpression>,\n state,\n id\n );\n errors.push(...validation.errors);\n if (errors.length > 0) {\n return { errors };\n }\n value = validation.value;\n } else if (t.isStringLiteral(child)) {\n value = child.value;\n } else if (t.isTemplateLiteral(child)) {\n const validation = validateTemplateLiteral(child);\n errors.push(...validation.errors.map((msg) => dynamicContentError(msg)));\n if (errors.length > 0) {\n return { errors };\n }\n value = validation.value;\n } else if (t.isNumericLiteral(child)) {\n value = child.value.toString();\n } else if (t.isBooleanLiteral(child)) {\n value = child.value as unknown as JsxChild;\n } else if (t.isNullLiteral(child)) {\n value = null as unknown as JsxChild;\n } else if (t.isUnaryExpression(child)) {\n const validation = validateUnaryExpression(child);\n errors.push(...validation.errors.map((msg) => structuralError(msg)));\n if (errors.length > 0) {\n return { errors };\n }\n value = validation.value;\n } else if (t.isIdentifier(child)) {\n // <T>{name}</T> or <T>{undefined}</T>\n const validation = validateIdentifier(child, state);\n errors.push(...validation.errors.map((msg) => dynamicContentError(msg)));\n if (errors.length > 0) {\n return { errors };\n }\n value = validation.value;\n } else {\n // Other cases fail\n errors.push(\n dynamicContentError(\n generateDynamicContentErrorMessage() + createErrorLocation(child)\n )\n );\n return { errors };\n }\n\n return { errors, value };\n}\n\n/**\n * Given a CallExpression path, constructs a JsxChild.\n * Handles: Jsx(T, ...children)\n */\nfunction constructJsxElement(\n callExprPath: NodePath<t.CallExpression>,\n state: TransformState,\n id: IdObject\n): { errors: JsxValidationError[]; value?: JsxElement | Variable } {\n const errors: JsxValidationError[] = [];\n const callExpr = callExprPath.node;\n\n // Validate that this is a jsx call\n const jsxValidation = validateJsxCall(callExpr, state);\n errors.push(...jsxValidation.map((msg) => dynamicContentError(msg)));\n if (jsxValidation.length > 0) {\n return { errors };\n }\n\n // Increment id\n id.increment();\n\n // Get first argument\n if (callExpr.arguments.length === 0) {\n return { errors };\n }\n const firstArg = callExpr.arguments[0];\n if (!t.isExpression(firstArg)) {\n errors.push(\n structuralError(\n `Failed to construct JsxElement! First argument must be an expression` +\n createErrorLocation(callExpr.arguments[0])\n )\n );\n return { errors };\n }\n\n // Resolve canonical name\n const { namespaceName, functionName } =\n getCalleeNameFromJsxExpressionParam(firstArg);\n if (!functionName) {\n errors.push(\n structuralError(\n `Failed to construct JsxElement! First argument must be a valid function` +\n createErrorLocation(callExpr.arguments[0])\n )\n );\n return { errors };\n }\n\n // Get the canonical function name\n const { canonicalName, type } = getTrackedVariable(\n state.scopeTracker,\n namespaceName,\n functionName\n );\n\n // Handle variable components\n if (\n canonicalName &&\n type === 'generaltranslation' &&\n isVariableComponent(canonicalName)\n ) {\n const variableValidation = constructVariable(\n canonicalName,\n callExpr.arguments,\n id\n );\n errors.push(\n ...variableValidation.errors.map((msg) => structuralError(msg))\n );\n if (variableValidation.errors.length > 0) {\n return { errors };\n }\n return { errors, value: variableValidation.value! };\n }\n\n // Set the component name\n let componentName: string;\n const idNumber: number = id.get();\n if (canonicalName && type === 'generaltranslation') {\n // Handle GT components: <Var>, <Num>, <Currency>, etc.\n\n // Check that this is a gt component\n if (!isGTComponent(canonicalName)) {\n errors.push(\n structuralError(\n `Failed to construct JsxElement! ${canonicalName} is not a valid GT component` +\n createErrorLocation(callExpr.arguments[0])\n )\n );\n return { errors };\n }\n // Derive/Static - opaque element, skip children validation\n // The compiler doesn't resolve Derive functions; the CLI handles that.\n if (isDeriveComponent(canonicalName)) {\n return {\n errors,\n value: { t: canonicalName, i: idNumber },\n };\n }\n // Get the name of the component\n componentName = canonicalName;\n } else if (canonicalName && type === 'react') {\n // Handle fragment + special react components\n if (!isReactComponent(canonicalName)) {\n errors.push(\n structuralError(\n `Failed to construct JsxElement! ${canonicalName} is not a valid React component` +\n createErrorLocation(callExpr.arguments[0])\n )\n );\n return { errors };\n }\n // Get the name of the component\n componentName =\n canonicalName === REACT_COMPONENTS.Fragment\n ? `C${id.get()}`\n : functionName;\n } else {\n // Handle all other components: div, etc.\n componentName = functionName;\n }\n\n // Get children from args\n const childrenValidation = validateChildrenFromArgs(callExprPath);\n if (childrenValidation.errors.length > 0) {\n errors.push(\n ...childrenValidation.errors.map((msg) => structuralError(msg))\n );\n return { errors };\n }\n\n // Construct JsxChildren\n // For branching components (Branch/Plural), use id.copy() so children and\n // branch props start counting from the same base independently.\n const jsxChildrenValidation = constructJsxChildrenForJsxElement(\n childrenValidation.value,\n state,\n isBranchComponent(canonicalName ?? '') ? id.copy() : id\n );\n errors.push(...jsxChildrenValidation.errors);\n if (jsxChildrenValidation.errors.length > 0) {\n return { errors };\n }\n const children: JsxChildren | undefined = jsxChildrenValidation.value;\n\n // Construct GT Tag\n const tagValidation = constructGTProp(\n callExprPath,\n id,\n state,\n canonicalName,\n type\n );\n errors.push(...tagValidation.errors);\n if (tagValidation.errors.length > 0) {\n return { errors };\n }\n const tag: GTProp | undefined = tagValidation.value;\n\n // Return result\n const value: JsxElement = {\n t: componentName,\n i: idNumber,\n ...(tag !== undefined && { d: tag }),\n ...(children !== undefined && { c: children }),\n };\n return { errors, value };\n}\n\n/**\n * Construct JsxChildren for a JsxElement\n * This is slightly different from constructJsxChildren in how it handles nullLiteral and booleanLiteral\n */\nfunction constructJsxChildrenForJsxElement(\n childrenPath: NodePath<t.Expression> | undefined,\n state: TransformState,\n id: IdObject\n): { errors: JsxValidationError[]; value?: JsxChildren } {\n const errors: JsxValidationError[] = [];\n const children = childrenPath?.node;\n\n // Special children edge cases: nullLiteral, booleanLiteral\n if (t.isNullLiteral(children)) {\n return { errors, value: undefined as unknown as JsxChildren };\n }\n if (t.isBooleanLiteral(children)) {\n return {\n errors,\n value: (children.value || undefined) as unknown as JsxChildren,\n };\n }\n\n // Construct JsxChildren\n return constructJsxChildren(childrenPath, state, id);\n}\n\n/**\n * Given a canonical name, constructs a GTProp\n */\nfunction constructGTProp(\n callExprPath: NodePath<t.CallExpression>,\n id: IdObject,\n state: TransformState,\n canonicalName?: string,\n type?: VariableType\n): { errors: JsxValidationError[]; value?: GTProp } {\n const errors: JsxValidationError[] = [];\n const value: GTProp = {};\n const args = callExprPath.node.arguments;\n\n // Validate Parameters\n if (args.length < 2) {\n errors.push(\n structuralError(\n 'Failed to construct GTProp! Missing parameters' +\n createErrorLocation(args[0])\n )\n );\n return { errors };\n }\n const parameters = args[1];\n if (!t.isObjectExpression(parameters)) {\n errors.push(\n structuralError(\n 'Failed to construct GTProp! Parameter field must be an object expression' +\n createErrorLocation(args[1])\n )\n );\n return { errors };\n }\n\n // For Branch and Plural, get the properties\n const parametersPath = callExprPath.get(\n 'arguments'\n )[1] as NodePath<t.ObjectExpression>;\n\n if (\n canonicalName &&\n type === 'generaltranslation' &&\n isBranchComponent(canonicalName)\n ) {\n // Get the branching parameters\n const branchingParameters = getBranchComponentParameters(\n parametersPath as NodePath<t.ObjectExpression>,\n canonicalName\n );\n // Add branch component branches\n const branches = {} as Record<string, JsxChildren>;\n\n for (const [name, parameterPath] of branchingParameters) {\n const parameter = parameterPath.node;\n // Special exceptions for branches:\n if (t.isNullLiteral(parameter)) {\n branches[name] = null as unknown as JsxChildren;\n continue;\n } else if (t.isBooleanLiteral(parameter)) {\n branches[name] = parameter.value as unknown as JsxChildren;\n continue;\n }\n\n // Otherwise, construct the JsxChildren\n const validation = constructJsxChildren(parameterPath, state, id.copy());\n errors.push(...validation.errors);\n if (validation.errors.length > 0) {\n return { errors };\n }\n if (validation.value === undefined) continue;\n branches[name] = validation.value;\n }\n\n if (Object.keys(branches).length > 0) {\n value['b'] = branches;\n value['t'] = canonicalName === GT_COMPONENT_TYPES.Branch ? 'b' : 'p';\n }\n } else {\n // Get the html content props\n Object.entries(HTML_CONTENT_PROPS).forEach(([prop, name]) => {\n const validation = validateStringLiteralPropertyFromArg(parameters, name);\n if (validation.errors.length > 0) {\n errors.push(...validation.errors.map((msg) => structuralError(msg)));\n return { errors };\n }\n if (validation.value === undefined) return;\n value[prop as keyof typeof HTML_CONTENT_PROPS] = validation.value;\n });\n }\n\n // Return result\n return { errors, value: Object.keys(value).length > 0 ? value : undefined };\n}\n\n/**\n * Construct Variable\n */\nfunction constructVariable(\n canonicalName: GT_COMPONENT_TYPES,\n args: (t.ArgumentPlaceholder | t.SpreadElement | t.Expression)[],\n id: IdObject\n): { errors: string[]; value?: Variable } {\n const errors: string[] = [];\n // Validate Parameters\n if (args.length < 2) {\n errors.push(\n 'Failed to construct GTProp! Missing parameters' +\n createErrorLocation(args[0])\n );\n return { errors };\n }\n const parameters = args[1];\n if (!t.isObjectExpression(parameters)) {\n errors.push(\n 'Failed to construct GTProp! Parameter field must be an object expression' +\n createErrorLocation(args[1])\n );\n return { errors };\n }\n\n // Validate Parameters\n const nameValidation = validateNameFieldForVarComponent(parameters);\n errors.push(...nameValidation.errors);\n if (nameValidation.errors.length > 0) {\n return { errors };\n }\n const name = nameValidation.value;\n\n // Check for name field\n const value: Variable = {\n i: id.get(),\n k: getVariableName(\n canonicalName as keyof typeof defaultVariableNames,\n id.get(),\n name\n ),\n v: minifyCanonicalName(canonicalName) as GTVariableType,\n };\n\n return { errors, value };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA2DA,SAAgB,qBACd,cACA,OACA,KAAe,IAAIA,wC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Object","t","validateChildrenElement","dynamicContentError","generateDynamicContentErrorMessage","createErrorLocation","validateTemplateLiteral","validateUnaryExpression","structuralError","validateIdentifier","validateJsxCall","getCalleeNameFromJsxExpressionParam","getTrackedVariable","isVariableComponent","isGTComponent","isDeriveComponent","isReactComponent","validateChildrenFromArgs","isBranchComponent","getBranchComponentParameters","HTML_CONTENT_PROPS","validateStringLiteralPropertyFromArg","validateNameFieldForVarComponent","getVariableName","minifyCanonicalName"],"sources":["../../../src/transform/jsx-children/constructJsxChildren.ts"],"sourcesContent":["import {\n GTProp,\n HTML_CONTENT_PROPS,\n JsxChild,\n JsxChildren,\n JsxElement,\n Variable,\n VariableType as GTVariableType,\n} from '@generaltranslation/format/types';\nimport { TransformState } from '../../state/types';\nimport * as t from '@babel/types';\nimport type { NodePath } from '@babel/traverse';\nimport { validateIdentifier } from './validation/validateIdentifier';\nimport { validateTemplateLiteral } from './validation/validateTemplateLiteral';\nimport { validateChildrenElement } from './validation/validateChildrenElement';\nimport { getCalleeNameFromJsxExpressionParam } from './utils/getCalleeNameFromJsxExpressionParam';\nimport { getTrackedVariable } from '../getTrackedVariable';\nimport { isReactComponent } from '../../utils/constants/react/helpers';\nimport { REACT_COMPONENTS } from '../../utils/constants/react/constants';\nimport { validateChildrenFromArgs } from './validation/validateChildrenFromArgs';\nimport { IdObject } from './utils/id';\nimport { VariableType } from '../../state/ScopeTracker';\nimport {\n defaultVariableNames,\n getVariableName,\n isBranchComponent,\n isDeriveComponent,\n isGTComponent,\n isVariableComponent,\n minifyCanonicalName,\n} from '../../utils/constants/gt/helpers';\nimport { validateStringLiteralPropertyFromArg } from './validation/validateStringLiteralPropertyFromArg';\nimport { GT_COMPONENT_TYPES } from '../../utils/constants/gt/constants';\nimport { getBranchComponentParameters } from './utils/getBranchComponentParameters';\nimport { validateNameFieldForVarComponent } from './validation/validateNameFieldForVarComponent';\nimport { validateUnaryExpression } from './validation/validateUnaryExpression';\nimport {\n createErrorLocation,\n generateDynamicContentErrorMessage,\n} from '../../utils/errors';\nimport { validateJsxCall } from './validation/validateJsxCall';\nimport {\n JsxValidationError,\n dynamicContentError,\n structuralError,\n} from './errors';\n\n/**\n * Given the children of a <T> component, constructs a JsxChildren object.\n * Takes an Expression path.\n *\n * ONLY does JsxChildren construction + validation, no further processing on any children.\n *\n * On invalid children, quit immediately.\n *\n * The node checks intentionally happen before navigating with .get(). This\n * keeps runtime validation behavior stable while preserving NodePath scope for\n * future derivation work.\n */\nexport function constructJsxChildren(\n childrenPath: NodePath<t.Expression> | undefined,\n state: TransformState,\n id: IdObject = new IdObject()\n): { errors: JsxValidationError[]; value?: JsxChildren } {\n const errors: JsxValidationError[] = [];\n\n // Skip if no children\n if (!childrenPath) {\n return { errors, value: childrenPath };\n }\n\n const children = childrenPath.node;\n let value: JsxChildren | undefined;\n if (t.isArrayExpression(children)) {\n // Handle ArrayExpression\n value = [];\n const elementPaths = childrenPath.get('elements');\n\n for (let i = 0; i < children.elements.length; i++) {\n const child = children.elements[i];\n // Validate child\n if (!validateChildrenElement(child)) {\n errors.push(\n dynamicContentError(\n generateDynamicContentErrorMessage() +\n (child && createErrorLocation(child))\n )\n );\n return { errors };\n }\n\n // Special children edge cases: nullLiteral, booleanLiteral\n if (t.isBooleanLiteral(child) || t.isNullLiteral(child)) {\n continue;\n }\n\n // Construct JsxChild\n const childPath = elementPaths[i] as NodePath<\n Exclude<t.Expression, t.ArrayExpression>\n >;\n const validation = constructJsxChild(childPath, state, id);\n errors.push(...validation.errors);\n if (errors.length > 0) {\n return { errors };\n }\n // Skip if no value\n if (validation.value === undefined) continue;\n (value as JsxChild[]).push(validation.value);\n }\n } else {\n // Handle single child\n const validation = constructJsxChild(\n childrenPath as NodePath<Exclude<t.Expression, t.ArrayExpression>>,\n state,\n id\n );\n errors.push(...validation.errors);\n if (errors.length > 0) {\n return { errors };\n }\n value = validation.value;\n }\n\n return { errors, value };\n}\n\n/**\n * Given an Expression path, constructs a JsxChild.\n * @returns { errors: string[]; value?: JsxChild }\n */\nfunction constructJsxChild(\n childPath: NodePath<Exclude<t.Expression, t.ArrayExpression>>,\n state: TransformState,\n id: IdObject\n): { errors: JsxValidationError[]; value?: JsxChild } {\n const errors: JsxValidationError[] = [];\n const child = childPath.node;\n let value: JsxChild | undefined;\n\n if (t.isCallExpression(child)) {\n // Construct JsxElement\n const validation = constructJsxElement(\n childPath as NodePath<t.CallExpression>,\n state,\n id\n );\n errors.push(...validation.errors);\n if (errors.length > 0) {\n return { errors };\n }\n value = validation.value;\n } else if (t.isStringLiteral(child)) {\n value = child.value;\n } else if (t.isTemplateLiteral(child)) {\n const validation = validateTemplateLiteral(child);\n errors.push(...validation.errors.map((msg) => dynamicContentError(msg)));\n if (errors.length > 0) {\n return { errors };\n }\n value = validation.value;\n } else if (t.isNumericLiteral(child)) {\n value = child.value.toString();\n } else if (t.isBooleanLiteral(child)) {\n value = child.value as unknown as JsxChild;\n } else if (t.isNullLiteral(child)) {\n value = null as unknown as JsxChild;\n } else if (t.isUnaryExpression(child)) {\n const validation = validateUnaryExpression(child);\n errors.push(...validation.errors.map((msg) => structuralError(msg)));\n if (errors.length > 0) {\n return { errors };\n }\n value = validation.value;\n } else if (t.isIdentifier(child)) {\n // <T>{name}</T> or <T>{undefined}</T>\n const validation = validateIdentifier(child, state);\n errors.push(...validation.errors.map((msg) => dynamicContentError(msg)));\n if (errors.length > 0) {\n return { errors };\n }\n value = validation.value;\n } else {\n // Other cases fail\n errors.push(\n dynamicContentError(\n generateDynamicContentErrorMessage() + createErrorLocation(child)\n )\n );\n return { errors };\n }\n\n return { errors, value };\n}\n\n/**\n * Given a CallExpression path, constructs a JsxChild.\n * Handles: Jsx(T, ...children)\n */\nfunction constructJsxElement(\n callExprPath: NodePath<t.CallExpression>,\n state: TransformState,\n id: IdObject\n): { errors: JsxValidationError[]; value?: JsxElement | Variable } {\n const errors: JsxValidationError[] = [];\n const callExpr = callExprPath.node;\n\n // Validate that this is a jsx call\n const jsxValidation = validateJsxCall(callExpr, state);\n errors.push(...jsxValidation.map((msg) => dynamicContentError(msg)));\n if (jsxValidation.length > 0) {\n return { errors };\n }\n\n // Increment id\n id.increment();\n\n // Get first argument\n if (callExpr.arguments.length === 0) {\n return { errors };\n }\n const firstArg = callExpr.arguments[0];\n if (!t.isExpression(firstArg)) {\n errors.push(\n structuralError(\n `Failed to construct JsxElement! First argument must be an expression` +\n createErrorLocation(callExpr.arguments[0])\n )\n );\n return { errors };\n }\n\n // Resolve canonical name\n const { namespaceName, functionName } =\n getCalleeNameFromJsxExpressionParam(firstArg);\n if (!functionName) {\n errors.push(\n structuralError(\n `Failed to construct JsxElement! First argument must be a valid function` +\n createErrorLocation(callExpr.arguments[0])\n )\n );\n return { errors };\n }\n\n // Get the canonical function name\n const { canonicalName, type } = getTrackedVariable(\n state.scopeTracker,\n namespaceName,\n functionName\n );\n\n // Handle variable components\n if (\n canonicalName &&\n type === 'generaltranslation' &&\n isVariableComponent(canonicalName)\n ) {\n const variableValidation = constructVariable(\n canonicalName,\n callExpr.arguments,\n id\n );\n errors.push(\n ...variableValidation.errors.map((msg) => structuralError(msg))\n );\n if (variableValidation.errors.length > 0) {\n return { errors };\n }\n return { errors, value: variableValidation.value! };\n }\n\n // Set the component name\n let componentName: string;\n const idNumber: number = id.get();\n if (canonicalName && type === 'generaltranslation') {\n // Handle GT components: <Var>, <Num>, <Currency>, etc.\n\n // Check that this is a gt component\n if (!isGTComponent(canonicalName)) {\n errors.push(\n structuralError(\n `Failed to construct JsxElement! ${canonicalName} is not a valid GT component` +\n createErrorLocation(callExpr.arguments[0])\n )\n );\n return { errors };\n }\n // Derive - opaque element, skip children validation\n // The compiler doesn't resolve Derive functions; the CLI handles that.\n if (isDeriveComponent(canonicalName)) {\n return {\n errors,\n value: { t: canonicalName, i: idNumber },\n };\n }\n // Get the name of the component\n componentName = canonicalName;\n } else if (canonicalName && type === 'react') {\n // Handle fragment + special react components\n if (!isReactComponent(canonicalName)) {\n errors.push(\n structuralError(\n `Failed to construct JsxElement! ${canonicalName} is not a valid React component` +\n createErrorLocation(callExpr.arguments[0])\n )\n );\n return { errors };\n }\n // Get the name of the component\n componentName =\n canonicalName === REACT_COMPONENTS.Fragment\n ? `C${id.get()}`\n : functionName;\n } else {\n // Handle all other components: div, etc.\n componentName = functionName;\n }\n\n // Get children from args\n const childrenValidation = validateChildrenFromArgs(callExprPath);\n if (childrenValidation.errors.length > 0) {\n errors.push(\n ...childrenValidation.errors.map((msg) => structuralError(msg))\n );\n return { errors };\n }\n\n // Construct JsxChildren\n // For branching components (Branch/Plural), use id.copy() so children and\n // branch props start counting from the same base independently.\n const jsxChildrenValidation = constructJsxChildrenForJsxElement(\n childrenValidation.value,\n state,\n isBranchComponent(canonicalName ?? '') ? id.copy() : id\n );\n errors.push(...jsxChildrenValidation.errors);\n if (jsxChildrenValidation.errors.length > 0) {\n return { errors };\n }\n const children: JsxChildren | undefined = jsxChildrenValidation.value;\n\n // Construct GT Tag\n const tagValidation = constructGTProp(\n callExprPath,\n id,\n state,\n canonicalName,\n type\n );\n errors.push(...tagValidation.errors);\n if (tagValidation.errors.length > 0) {\n return { errors };\n }\n const tag: GTProp | undefined = tagValidation.value;\n\n // Return result\n const value: JsxElement = {\n t: componentName,\n i: idNumber,\n ...(tag !== undefined && { d: tag }),\n ...(children !== undefined && { c: children }),\n };\n return { errors, value };\n}\n\n/**\n * Construct JsxChildren for a JsxElement\n * This is slightly different from constructJsxChildren in how it handles nullLiteral and booleanLiteral\n */\nfunction constructJsxChildrenForJsxElement(\n childrenPath: NodePath<t.Expression> | undefined,\n state: TransformState,\n id: IdObject\n): { errors: JsxValidationError[]; value?: JsxChildren } {\n const errors: JsxValidationError[] = [];\n const children = childrenPath?.node;\n\n // Special children edge cases: nullLiteral, booleanLiteral\n if (t.isNullLiteral(children)) {\n return { errors, value: undefined as unknown as JsxChildren };\n }\n if (t.isBooleanLiteral(children)) {\n return {\n errors,\n value: (children.value || undefined) as unknown as JsxChildren,\n };\n }\n\n // Construct JsxChildren\n return constructJsxChildren(childrenPath, state, id);\n}\n\n/**\n * Given a canonical name, constructs a GTProp\n */\nfunction constructGTProp(\n callExprPath: NodePath<t.CallExpression>,\n id: IdObject,\n state: TransformState,\n canonicalName?: string,\n type?: VariableType\n): { errors: JsxValidationError[]; value?: GTProp } {\n const errors: JsxValidationError[] = [];\n const value: GTProp = {};\n const args = callExprPath.node.arguments;\n\n // Validate Parameters\n if (args.length < 2) {\n errors.push(\n structuralError(\n 'Failed to construct GTProp! Missing parameters' +\n createErrorLocation(args[0])\n )\n );\n return { errors };\n }\n const parameters = args[1];\n if (!t.isObjectExpression(parameters)) {\n errors.push(\n structuralError(\n 'Failed to construct GTProp! Parameter field must be an object expression' +\n createErrorLocation(args[1])\n )\n );\n return { errors };\n }\n\n // For Branch and Plural, get the properties\n const parametersPath = callExprPath.get(\n 'arguments'\n )[1] as NodePath<t.ObjectExpression>;\n\n if (\n canonicalName &&\n type === 'generaltranslation' &&\n isBranchComponent(canonicalName)\n ) {\n // Get the branching parameters\n const branchingParameters = getBranchComponentParameters(\n parametersPath as NodePath<t.ObjectExpression>,\n canonicalName\n );\n // Add branch component branches\n const branches = {} as Record<string, JsxChildren>;\n\n for (const [name, parameterPath] of branchingParameters) {\n const parameter = parameterPath.node;\n // Special exceptions for branches:\n if (t.isNullLiteral(parameter)) {\n branches[name] = null as unknown as JsxChildren;\n continue;\n } else if (t.isBooleanLiteral(parameter)) {\n branches[name] = parameter.value as unknown as JsxChildren;\n continue;\n }\n\n // Otherwise, construct the JsxChildren\n const validation = constructJsxChildren(parameterPath, state, id.copy());\n errors.push(...validation.errors);\n if (validation.errors.length > 0) {\n return { errors };\n }\n if (validation.value === undefined) continue;\n branches[name] = validation.value;\n }\n\n if (Object.keys(branches).length > 0) {\n value['b'] = branches;\n value['t'] = canonicalName === GT_COMPONENT_TYPES.Branch ? 'b' : 'p';\n }\n } else {\n // Get the html content props\n Object.entries(HTML_CONTENT_PROPS).forEach(([prop, name]) => {\n const validation = validateStringLiteralPropertyFromArg(parameters, name);\n if (validation.errors.length > 0) {\n errors.push(...validation.errors.map((msg) => structuralError(msg)));\n return { errors };\n }\n if (validation.value === undefined) return;\n value[prop as keyof typeof HTML_CONTENT_PROPS] = validation.value;\n });\n }\n\n // Return result\n return { errors, value: Object.keys(value).length > 0 ? value : undefined };\n}\n\n/**\n * Construct Variable\n */\nfunction constructVariable(\n canonicalName: GT_COMPONENT_TYPES,\n args: (t.ArgumentPlaceholder | t.SpreadElement | t.Expression)[],\n id: IdObject\n): { errors: string[]; value?: Variable } {\n const errors: string[] = [];\n // Validate Parameters\n if (args.length < 2) {\n errors.push(\n 'Failed to construct GTProp! Missing parameters' +\n createErrorLocation(args[0])\n );\n return { errors };\n }\n const parameters = args[1];\n if (!t.isObjectExpression(parameters)) {\n errors.push(\n 'Failed to construct GTProp! Parameter field must be an object expression' +\n createErrorLocation(args[1])\n );\n return { errors };\n }\n\n // Validate Parameters\n const nameValidation = validateNameFieldForVarComponent(parameters);\n errors.push(...nameValidation.errors);\n if (nameValidation.errors.length > 0) {\n return { errors };\n }\n const name = nameValidation.value;\n\n // Check for name field\n const value: Variable = {\n i: id.get(),\n k: getVariableName(\n canonicalName as keyof typeof defaultVariableNames,\n id.get(),\n name\n ),\n v: minifyCanonicalName(canonicalName) as GTVariableType,\n };\n\n return { errors, value };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA2DA,SAAgB,qBACd,cACA,OACA,KAAe,IAAIA,wCAAAA,UAAU,EAC0B;CACvD,MAAM,SAA+B,EAAE;AAGvC,KAAI,CAAC,aACH,QAAO;EAAE;EAAQ,OAAO;EAAc;CAGxC,MAAM,WAAW,aAAa;CAC9B,IAAI;AACJ,KAAIC,aAAE,kBAAkB,SAAS,EAAE;AAEjC,UAAQ,EAAE;EACV,MAAM,eAAe,aAAa,IAAI,WAAW;AAEjD,OAAK,IAAI,IAAI,GAAG,IAAI,SAAS,SAAS,QAAQ,KAAK;GACjD,MAAM,Q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,sCAAAA,gBAAgB,IAAI,CAAC,CAAC;AACpE,UAAO,EAAE,QAAQ;;AAEnB,MAAI,WAAW,UAAU,KAAA,EAAW;AACpC,QAAM,QAA2C,WAAW;GAC5D;AAIJ,QAAO;EAAE;EAAQ,OAAO,OAAO,KAAK,MAAM,CAAC,SAAS,IAAI,QAAQ,KAAA;EAAW;;;;;AAM7E,SAAS,kBACP,eACA,MACA,IACwC;CACxC,MAAM,SAAmB,EAAE;AAE3B,KAAI,KAAK,SAAS,GAAG;AACnB,SAAO,KACL,mDACEH,qBAAAA,oBAAoB,KAAK,GAAG,CAC/B;AACD,SAAO,EAAE,QAAQ;;CAEnB,MAAM,aAAa,KAAK;AACxB,KAAI,CAACJ,aAAE,mBAAmB,WAAW,EAAE;AACrC,SAAO,KACL,6EACEI,qBAAAA,oBAAoB,KAAK,GAAG,CAC/B;AACD,SAAO,EAAE,QAAQ;;CAInB,MAAM,iBAAiBiB,2EAAAA,iCAAiC,WAAW;AACnE,QAAO,KAAK,GAAG,eAAe,OAAO;AACrC,KAAI,eAAe,OAAO,SAAS,EACjC,QAAO,EAAE,QAAQ;CAEnB,MAAM,OAAO,eAAe;AAa5B,QAAO;EAAE;EAAQ,OAAA;GATf,GAAG,GAAG,KAAK;GACX,GAAGC,mCAAAA,gBACD,eACA,GAAG,KAAK,EACR,KACD;GACD,GAAGC,mCAAAA,oBAAoB,cAAc;GAGjB;EAAE"}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import * as t from '@babel/types';
|
|
2
2
|
import { NodePath } from '@babel/traverse';
|
|
3
3
|
/**
|
|
4
|
-
* Inject `import { GtInternalTranslateJsx, GtInternalVar } from 'gt-react
|
|
4
|
+
* Inject `import { GtInternalTranslateJsx, GtInternalVar } from 'gt-react'`
|
|
5
5
|
* as the first statement in the program.
|
|
6
6
|
*/
|
|
7
|
-
export declare function injectJsxInsertionImport(path: NodePath<t.Program
|
|
7
|
+
export declare function injectJsxInsertionImport(path: NodePath<t.Program>, legacyGtReactImportSource: boolean): void;
|
|
8
8
|
//# sourceMappingURL=injectJsxInsertionImport.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"injectJsxInsertionImport.d.ts","sourceRoot":"","sources":["../../../src/transform/jsx-insertion/injectJsxInsertionImport.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,cAAc,CAAC;AAClC,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;
|
|
1
|
+
{"version":3,"file":"injectJsxInsertionImport.d.ts","sourceRoot":"","sources":["../../../src/transform/jsx-insertion/injectJsxInsertionImport.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,cAAc,CAAC;AAClC,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAI3C;;;GAGG;AACH,wBAAgB,wBAAwB,CACtC,IAAI,EAAE,QAAQ,CAAC,CAAC,CAAC,OAAO,CAAC,EACzB,yBAAyB,EAAE,OAAO,GACjC,IAAI,CAaN"}
|
|
@@ -1,17 +1,18 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
2
|
const require_runtime = require("../../_virtual/_rolldown/runtime.js");
|
|
3
3
|
require("../../utils/constants/gt/constants.js");
|
|
4
|
+
const require_utils_constants_gt_helpers = require("../../utils/constants/gt/helpers.js");
|
|
4
5
|
let _babel_types = require("@babel/types");
|
|
5
6
|
_babel_types = require_runtime.__toESM(_babel_types);
|
|
6
7
|
//#region src/transform/jsx-insertion/injectJsxInsertionImport.ts
|
|
7
8
|
/**
|
|
8
|
-
* Inject `import { GtInternalTranslateJsx, GtInternalVar } from 'gt-react
|
|
9
|
+
* Inject `import { GtInternalTranslateJsx, GtInternalVar } from 'gt-react'`
|
|
9
10
|
* as the first statement in the program.
|
|
10
11
|
*/
|
|
11
|
-
function injectJsxInsertionImport(path) {
|
|
12
|
+
function injectJsxInsertionImport(path, legacyGtReactImportSource) {
|
|
12
13
|
const tName = "GtInternalTranslateJsx";
|
|
13
14
|
const varName = "GtInternalVar";
|
|
14
|
-
const importDecl = _babel_types.importDeclaration([_babel_types.importSpecifier(_babel_types.identifier(tName), _babel_types.identifier(tName)), _babel_types.importSpecifier(_babel_types.identifier(varName), _babel_types.identifier(varName))], _babel_types.stringLiteral(
|
|
15
|
+
const importDecl = _babel_types.importDeclaration([_babel_types.importSpecifier(_babel_types.identifier(tName), _babel_types.identifier(tName)), _babel_types.importSpecifier(_babel_types.identifier(varName), _babel_types.identifier(varName))], _babel_types.stringLiteral(require_utils_constants_gt_helpers.getGtReactImportSource(legacyGtReactImportSource)));
|
|
15
16
|
path.unshiftContainer("body", importDecl);
|
|
16
17
|
}
|
|
17
18
|
//#endregion
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"injectJsxInsertionImport.js","names":["t"],"sources":["../../../src/transform/jsx-insertion/injectJsxInsertionImport.ts"],"sourcesContent":["import * as t from '@babel/types';\nimport { NodePath } from '@babel/traverse';\nimport {
|
|
1
|
+
{"version":3,"file":"injectJsxInsertionImport.js","names":["t","getGtReactImportSource"],"sources":["../../../src/transform/jsx-insertion/injectJsxInsertionImport.ts"],"sourcesContent":["import * as t from '@babel/types';\nimport { NodePath } from '@babel/traverse';\nimport { GT_COMPONENT_TYPES } from '../../utils/constants/gt/constants';\nimport { getGtReactImportSource } from '../../utils/constants/gt/helpers';\n\n/**\n * Inject `import { GtInternalTranslateJsx, GtInternalVar } from 'gt-react'`\n * as the first statement in the program.\n */\nexport function injectJsxInsertionImport(\n path: NodePath<t.Program>,\n legacyGtReactImportSource: boolean\n): void {\n const tName = GT_COMPONENT_TYPES.GtInternalTranslateJsx;\n const varName = GT_COMPONENT_TYPES.GtInternalVar;\n\n const importDecl = t.importDeclaration(\n [\n t.importSpecifier(t.identifier(tName), t.identifier(tName)),\n t.importSpecifier(t.identifier(varName), t.identifier(varName)),\n ],\n t.stringLiteral(getGtReactImportSource(legacyGtReactImportSource))\n );\n\n path.unshiftContainer('body', importDecl);\n}\n"],"mappings":";;;;;;;;;;;AASA,SAAgB,yBACd,MACA,2BACM;CACN,MAAM,QAAA;CACN,MAAM,UAAA;CAEN,MAAM,aAAaA,aAAE,kBACnB,CACEA,aAAE,gBAAgBA,aAAE,WAAW,MAAM,EAAEA,aAAE,WAAW,MAAM,CAAC,EAC3DA,aAAE,gBAAgBA,aAAE,WAAW,QAAQ,EAAEA,aAAE,WAAW,QAAQ,CAAC,CAChE,EACDA,aAAE,cAAcC,mCAAAA,uBAAuB,0BAA0B,CAAC,CACnE;AAED,MAAK,iBAAiB,QAAQ,WAAW"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as t from '@babel/types';
|
|
2
2
|
import { NodePath } from '@babel/traverse';
|
|
3
3
|
/**
|
|
4
|
-
* Inject `import { t } from 'gt-react
|
|
4
|
+
* Inject `import { t } from 'gt-react'` as the first statement in the program.
|
|
5
5
|
*/
|
|
6
|
-
export declare function injectMacroImport(path: NodePath<t.Program
|
|
6
|
+
export declare function injectMacroImport(path: NodePath<t.Program>, legacyGtReactImportSource: boolean): void;
|
|
7
7
|
//# sourceMappingURL=injectMacroImport.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"injectMacroImport.d.ts","sourceRoot":"","sources":["../../../src/transform/macro-expansion/injectMacroImport.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,cAAc,CAAC;AAClC,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;
|
|
1
|
+
{"version":3,"file":"injectMacroImport.d.ts","sourceRoot":"","sources":["../../../src/transform/macro-expansion/injectMacroImport.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,cAAc,CAAC;AAClC,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAI3C;;GAEG;AACH,wBAAgB,iBAAiB,CAC/B,IAAI,EAAE,QAAQ,CAAC,CAAC,CAAC,OAAO,CAAC,EACzB,yBAAyB,EAAE,OAAO,GACjC,IAAI,CASN"}
|
|
@@ -1,15 +1,16 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
2
|
const require_runtime = require("../../_virtual/_rolldown/runtime.js");
|
|
3
3
|
require("../../utils/constants/gt/constants.js");
|
|
4
|
+
const require_utils_constants_gt_helpers = require("../../utils/constants/gt/helpers.js");
|
|
4
5
|
let _babel_types = require("@babel/types");
|
|
5
6
|
_babel_types = require_runtime.__toESM(_babel_types);
|
|
6
7
|
//#region src/transform/macro-expansion/injectMacroImport.ts
|
|
7
8
|
/**
|
|
8
|
-
* Inject `import { t } from 'gt-react
|
|
9
|
+
* Inject `import { t } from 'gt-react'` as the first statement in the program.
|
|
9
10
|
*/
|
|
10
|
-
function injectMacroImport(path) {
|
|
11
|
+
function injectMacroImport(path, legacyGtReactImportSource) {
|
|
11
12
|
const tName = "t";
|
|
12
|
-
const importDecl = _babel_types.importDeclaration([_babel_types.importSpecifier(_babel_types.identifier(tName), _babel_types.identifier(tName))], _babel_types.stringLiteral(
|
|
13
|
+
const importDecl = _babel_types.importDeclaration([_babel_types.importSpecifier(_babel_types.identifier(tName), _babel_types.identifier(tName))], _babel_types.stringLiteral(require_utils_constants_gt_helpers.getGtReactImportSource(legacyGtReactImportSource)));
|
|
13
14
|
path.unshiftContainer("body", importDecl);
|
|
14
15
|
}
|
|
15
16
|
//#endregion
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"injectMacroImport.js","names":["t"],"sources":["../../../src/transform/macro-expansion/injectMacroImport.ts"],"sourcesContent":["import * as t from '@babel/types';\nimport { NodePath } from '@babel/traverse';\nimport {
|
|
1
|
+
{"version":3,"file":"injectMacroImport.js","names":["t","getGtReactImportSource"],"sources":["../../../src/transform/macro-expansion/injectMacroImport.ts"],"sourcesContent":["import * as t from '@babel/types';\nimport { NodePath } from '@babel/traverse';\nimport { GT_OTHER_FUNCTIONS } from '../../utils/constants/gt/constants';\nimport { getGtReactImportSource } from '../../utils/constants/gt/helpers';\n\n/**\n * Inject `import { t } from 'gt-react'` as the first statement in the program.\n */\nexport function injectMacroImport(\n path: NodePath<t.Program>,\n legacyGtReactImportSource: boolean\n): void {\n const tName = GT_OTHER_FUNCTIONS.t;\n\n const importDecl = t.importDeclaration(\n [t.importSpecifier(t.identifier(tName), t.identifier(tName))],\n t.stringLiteral(getGtReactImportSource(legacyGtReactImportSource))\n );\n\n path.unshiftContainer('body', importDecl);\n}\n"],"mappings":";;;;;;;;;;AAQA,SAAgB,kBACd,MACA,2BACM;CACN,MAAM,QAAA;CAEN,MAAM,aAAaA,aAAE,kBACnB,CAACA,aAAE,gBAAgBA,aAAE,WAAW,MAAM,EAAEA,aAAE,WAAW,MAAM,CAAC,CAAC,EAC7DA,aAAE,cAAcC,mCAAAA,uBAAuB,0BAA0B,CAAC,CACnE;AAED,MAAK,iBAAiB,QAAQ,WAAW"}
|
|
@@ -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,CA4BP"}
|
|
@@ -5,12 +5,12 @@ 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
|
-
id,
|
|
12
11
|
context,
|
|
13
12
|
maxChars,
|
|
13
|
+
requiresReview,
|
|
14
14
|
dataFormat: format || "ICU"
|
|
15
15
|
});
|
|
16
16
|
state.stringCollector.pushTranslationContent(identifier, {
|
|
@@ -19,6 +19,7 @@ function registerUseGTCallback({ identifier, state, content, context, id, maxCha
|
|
|
19
19
|
id,
|
|
20
20
|
context,
|
|
21
21
|
maxChars,
|
|
22
|
+
requiresReview,
|
|
22
23
|
format
|
|
23
24
|
});
|
|
24
25
|
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
|
|
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 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,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,CA6BP"}
|
|
@@ -4,12 +4,12 @@ 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
|
-
...id && { id },
|
|
11
10
|
...context && { context },
|
|
12
11
|
...maxChars != null && { maxChars },
|
|
12
|
+
...requiresReview === true && { requiresReview: true },
|
|
13
13
|
dataFormat: format || "ICU"
|
|
14
14
|
});
|
|
15
15
|
state.stringCollector.pushRuntimeOnlyContent({
|
|
@@ -18,6 +18,7 @@ function registerStandaloneTranslation({ state, content, context, id, maxChars,
|
|
|
18
18
|
id,
|
|
19
19
|
context,
|
|
20
20
|
maxChars,
|
|
21
|
+
requiresReview,
|
|
21
22
|
format
|
|
22
23
|
});
|
|
23
24
|
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 ...(
|
|
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 ...(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,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":";;;;;;;;;;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,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;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,CA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AAyC,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"}
|
|
@@ -2,10 +2,11 @@ import * as t from '@babel/types';
|
|
|
2
2
|
import { NodePath } from '@babel/traverse';
|
|
3
3
|
/**
|
|
4
4
|
* Inject runtime translate import with only the specifiers needed.
|
|
5
|
-
* `import { GtInternalRuntimeTranslateString, GtInternalRuntimeTranslateJsx } from 'gt-react
|
|
5
|
+
* `import { GtInternalRuntimeTranslateString, GtInternalRuntimeTranslateJsx } from 'gt-react'`
|
|
6
6
|
*/
|
|
7
|
-
export declare function injectRuntimeTranslateImport(path: NodePath<t.Program>, { needsString, needsJsx }: {
|
|
7
|
+
export declare function injectRuntimeTranslateImport(path: NodePath<t.Program>, { needsString, needsJsx, legacyGtReactImportSource, }: {
|
|
8
8
|
needsString: boolean;
|
|
9
9
|
needsJsx: boolean;
|
|
10
|
+
legacyGtReactImportSource: boolean;
|
|
10
11
|
}): NodePath<t.ImportDeclaration> | null;
|
|
11
12
|
//# sourceMappingURL=injectRuntimeTranslateImport.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"injectRuntimeTranslateImport.d.ts","sourceRoot":"","sources":["../../../src/transform/runtime-translate/injectRuntimeTranslateImport.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,cAAc,CAAC;AAClC,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;
|
|
1
|
+
{"version":3,"file":"injectRuntimeTranslateImport.d.ts","sourceRoot":"","sources":["../../../src/transform/runtime-translate/injectRuntimeTranslateImport.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,cAAc,CAAC;AAClC,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAI3C;;;GAGG;AACH,wBAAgB,4BAA4B,CAC1C,IAAI,EAAE,QAAQ,CAAC,CAAC,CAAC,OAAO,CAAC,EACzB,EACE,WAAW,EACX,QAAQ,EACR,yBAAyB,GAC1B,EAAE;IACD,WAAW,EAAE,OAAO,CAAC;IACrB,QAAQ,EAAE,OAAO,CAAC;IAClB,yBAAyB,EAAE,OAAO,CAAC;CACpC,GACA,QAAQ,CAAC,CAAC,CAAC,iBAAiB,CAAC,GAAG,IAAI,CAsBtC"}
|
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
2
|
const require_runtime = require("../../_virtual/_rolldown/runtime.js");
|
|
3
3
|
require("../../utils/constants/gt/constants.js");
|
|
4
|
+
const require_utils_constants_gt_helpers = require("../../utils/constants/gt/helpers.js");
|
|
4
5
|
let _babel_types = require("@babel/types");
|
|
5
6
|
_babel_types = require_runtime.__toESM(_babel_types);
|
|
6
7
|
//#region src/transform/runtime-translate/injectRuntimeTranslateImport.ts
|
|
7
8
|
/**
|
|
8
9
|
* Inject runtime translate import with only the specifiers needed.
|
|
9
|
-
* `import { GtInternalRuntimeTranslateString, GtInternalRuntimeTranslateJsx } from 'gt-react
|
|
10
|
+
* `import { GtInternalRuntimeTranslateString, GtInternalRuntimeTranslateJsx } from 'gt-react'`
|
|
10
11
|
*/
|
|
11
|
-
function injectRuntimeTranslateImport(path, { needsString, needsJsx }) {
|
|
12
|
+
function injectRuntimeTranslateImport(path, { needsString, needsJsx, legacyGtReactImportSource }) {
|
|
12
13
|
const specifiers = [];
|
|
13
14
|
if (needsString) {
|
|
14
15
|
const name = "GtInternalRuntimeTranslateString";
|
|
@@ -19,7 +20,7 @@ function injectRuntimeTranslateImport(path, { needsString, needsJsx }) {
|
|
|
19
20
|
specifiers.push(_babel_types.importSpecifier(_babel_types.identifier(name), _babel_types.identifier(name)));
|
|
20
21
|
}
|
|
21
22
|
if (specifiers.length === 0) return null;
|
|
22
|
-
const importDecl = _babel_types.importDeclaration(specifiers, _babel_types.stringLiteral(
|
|
23
|
+
const importDecl = _babel_types.importDeclaration(specifiers, _babel_types.stringLiteral(require_utils_constants_gt_helpers.getGtReactImportSource(legacyGtReactImportSource)));
|
|
23
24
|
const [inserted] = path.unshiftContainer("body", importDecl);
|
|
24
25
|
return inserted;
|
|
25
26
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"injectRuntimeTranslateImport.js","names":["t"],"sources":["../../../src/transform/runtime-translate/injectRuntimeTranslateImport.ts"],"sourcesContent":["import * as t from '@babel/types';\nimport { NodePath } from '@babel/traverse';\nimport {
|
|
1
|
+
{"version":3,"file":"injectRuntimeTranslateImport.js","names":["t","getGtReactImportSource"],"sources":["../../../src/transform/runtime-translate/injectRuntimeTranslateImport.ts"],"sourcesContent":["import * as t from '@babel/types';\nimport { NodePath } from '@babel/traverse';\nimport { GT_OTHER_FUNCTIONS } from '../../utils/constants/gt/constants';\nimport { getGtReactImportSource } from '../../utils/constants/gt/helpers';\n\n/**\n * Inject runtime translate import with only the specifiers needed.\n * `import { GtInternalRuntimeTranslateString, GtInternalRuntimeTranslateJsx } from 'gt-react'`\n */\nexport function injectRuntimeTranslateImport(\n path: NodePath<t.Program>,\n {\n needsString,\n needsJsx,\n legacyGtReactImportSource,\n }: {\n needsString: boolean;\n needsJsx: boolean;\n legacyGtReactImportSource: boolean;\n }\n): NodePath<t.ImportDeclaration> | null {\n const specifiers: t.ImportSpecifier[] = [];\n\n if (needsString) {\n const name = GT_OTHER_FUNCTIONS.GtInternalRuntimeTranslateString;\n specifiers.push(t.importSpecifier(t.identifier(name), t.identifier(name)));\n }\n\n if (needsJsx) {\n const name = GT_OTHER_FUNCTIONS.GtInternalRuntimeTranslateJsx;\n specifiers.push(t.importSpecifier(t.identifier(name), t.identifier(name)));\n }\n\n if (specifiers.length === 0) return null;\n\n const importDecl = t.importDeclaration(\n specifiers,\n t.stringLiteral(getGtReactImportSource(legacyGtReactImportSource))\n );\n\n const [inserted] = path.unshiftContainer('body', importDecl);\n return inserted as NodePath<t.ImportDeclaration>;\n}\n"],"mappings":";;;;;;;;;;;AASA,SAAgB,6BACd,MACA,EACE,aACA,UACA,6BAMoC;CACtC,MAAM,aAAkC,EAAE;AAE1C,KAAI,aAAa;EACf,MAAM,OAAA;AACN,aAAW,KAAKA,aAAE,gBAAgBA,aAAE,WAAW,KAAK,EAAEA,aAAE,WAAW,KAAK,CAAC,CAAC;;AAG5E,KAAI,UAAU;EACZ,MAAM,OAAA;AACN,aAAW,KAAKA,aAAE,gBAAgBA,aAAE,WAAW,KAAK,EAAEA,aAAE,WAAW,KAAK,CAAC,CAAC;;AAG5E,KAAI,WAAW,WAAW,EAAG,QAAO;CAEpC,MAAM,aAAaA,aAAE,kBACnB,YACAA,aAAE,cAAcC,mCAAAA,uBAAuB,0BAA0B,CAAC,CACnE;CAED,MAAM,CAAC,YAAY,KAAK,iBAAiB,QAAQ,WAAW;AAC5D,QAAO"}
|
|
@@ -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"}
|
|
@@ -6,8 +6,8 @@ const require_utils_parsing_getObjectPropertyFromObjectExpression = require("../
|
|
|
6
6
|
const require_utils_validation_validateExpressionIsStringLiteral = require("../../utils/validation/validateExpressionIsStringLiteral.js");
|
|
7
7
|
const require_utils_validation_validateChildrenFromObjectExpression = require("../../utils/validation/validateChildrenFromObjectExpression.js");
|
|
8
8
|
const require_transform_jsx_children_constructJsxChildren = require("../jsx-children/constructJsxChildren.js");
|
|
9
|
-
require("../jsx-children/index.js");
|
|
10
9
|
const require_utils_validation_validateExpressionIsNumericLiteral = require("../../utils/validation/validateExpressionIsNumericLiteral.js");
|
|
10
|
+
const require_utils_validation_validateExpressionIsBooleanLiteral = require("../../utils/validation/validateExpressionIsBooleanLiteral.js");
|
|
11
11
|
let _babel_types = require("@babel/types");
|
|
12
12
|
_babel_types = require_runtime.__toESM(_babel_types);
|
|
13
13
|
//#region src/transform/validation/validateTranslationComponentArgs.ts
|
|
@@ -39,6 +39,9 @@ function validateTComponentArgs(argsPath, state) {
|
|
|
39
39
|
const maxCharsValidation = validateNumberProperty(args, "maxChars");
|
|
40
40
|
errors.push(...maxCharsValidation.errors);
|
|
41
41
|
const maxChars = maxCharsValidation.value;
|
|
42
|
+
const requiresReviewValidation = validateBooleanProperty(args, "requiresReview");
|
|
43
|
+
errors.push(...requiresReviewValidation.errors);
|
|
44
|
+
const requiresReview = requiresReviewValidation.value;
|
|
42
45
|
const hashValidation = validateStringProperty(args, "_hash");
|
|
43
46
|
errors.push(...hashValidation.errors);
|
|
44
47
|
const _hash = hashValidation.value;
|
|
@@ -50,6 +53,7 @@ function validateTComponentArgs(argsPath, state) {
|
|
|
50
53
|
context,
|
|
51
54
|
_hash,
|
|
52
55
|
maxChars,
|
|
56
|
+
requiresReview,
|
|
53
57
|
children: childrenValidation.value,
|
|
54
58
|
hasDeriveContext: contextValidation.hasDeriveExpression || childrenValidation.hasAutoderive
|
|
55
59
|
};
|
|
@@ -179,6 +183,24 @@ function getNumberLiteralFromExpression(expr) {
|
|
|
179
183
|
function validateNumberLiteralIsInteger(value) {
|
|
180
184
|
return Number.isInteger(value);
|
|
181
185
|
}
|
|
186
|
+
/**
|
|
187
|
+
* Will validate and retrieve property from object expression and also try prefixing with a $.
|
|
188
|
+
* Only boolean literals are accepted — string "true"/"false" and dynamic
|
|
189
|
+
* expressions are rejected because the value is hash-changing.
|
|
190
|
+
*/
|
|
191
|
+
function validateBooleanProperty(args, name) {
|
|
192
|
+
const errors = [];
|
|
193
|
+
const property = require_utils_parsing_getObjectPropertyFromObjectExpression.getObjectPropertyFromObjectExpression(args, name) || require_utils_parsing_getObjectPropertyFromObjectExpression.getObjectPropertyFromObjectExpression(args, "$" + name);
|
|
194
|
+
if (!property) return { errors };
|
|
195
|
+
if (!_babel_types.isObjectProperty(property) || !_babel_types.isExpression(property.value) || !require_utils_validation_validateExpressionIsBooleanLiteral.validateExpressionIsBooleanLiteral(property.value)) {
|
|
196
|
+
errors.push(`The <T> component must have a boolean literal (true or false) in its ${name} field`);
|
|
197
|
+
return { errors };
|
|
198
|
+
}
|
|
199
|
+
return {
|
|
200
|
+
errors,
|
|
201
|
+
value: property.value.value
|
|
202
|
+
};
|
|
203
|
+
}
|
|
182
204
|
//#endregion
|
|
183
205
|
exports.validateChildrenProperty = validateChildrenProperty;
|
|
184
206
|
exports.validateTranslationComponentArgs = validateTranslationComponentArgs;
|