gt 2.14.8 → 2.14.9

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/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # gtx-cli
2
2
 
3
+ ## 2.14.9
4
+
5
+ ### Patch Changes
6
+
7
+ - [#1191](https://github.com/generaltranslation/gt/pull/1191) [`0c24b75`](https://github.com/generaltranslation/gt/commit/0c24b7563005a967a2b8916fabf60ee203466087) Thanks [@ErnestM1234](https://github.com/ErnestM1234)! - fix: Derive JSX tracing behavior for variable declarations
8
+
3
9
  ## 2.14.8
4
10
 
5
11
  ### Patch Changes
@@ -1 +1 @@
1
- export declare const PACKAGE_VERSION = "2.14.8";
1
+ export declare const PACKAGE_VERSION = "2.14.9";
@@ -1,2 +1,2 @@
1
1
  // This file is auto-generated. Do not edit manually.
2
- export const PACKAGE_VERSION = '2.14.8';
2
+ export const PACKAGE_VERSION = '2.14.9';
@@ -6,7 +6,7 @@ import * as t from '@babel/types';
6
6
  import fs from 'node:fs';
7
7
  import { parse } from '@babel/parser';
8
8
  import addGTIdentifierToSyntaxTree from './addGTIdentifierToSyntaxTree.js';
9
- import { warnHasUnwrappedExpressionSync, warnNestedTComponent, warnFunctionNotFoundSync, warnMissingReturnSync, warnDuplicateFunctionDefinitionSync, warnInvalidDeriveInitSync, warnRecursiveFunctionCallSync, warnDataAttrOnBranch, warnNestedInternalTComponent, } from '../../../../console/index.js';
9
+ import { warnHasUnwrappedExpressionSync, warnNestedTComponent, warnFunctionNotFoundSync, warnMissingReturnSync, warnDuplicateFunctionDefinitionSync, warnInvalidDeriveInitSync, warnRecursiveFunctionCallSync, warnDataAttrOnBranch, warnNestedInternalTComponent, warnDeriveNonConstVariableSync, warnDeriveDestructuringSync, } from '../../../../console/index.js';
10
10
  import { isAcceptedPluralForm } from 'generaltranslation/internal';
11
11
  import { isStaticExpression } from '../../evaluateJsx.js';
12
12
  import { DATA_ATTR_PREFIX, STATIC_COMPONENT, DERIVE_COMPONENT, TRANSLATION_COMPONENT, INTERNAL_TRANSLATION_COMPONENT, VARIABLE_COMPONENTS, } from '../constants.js';
@@ -25,7 +25,7 @@ import path from 'node:path';
25
25
  import { extractSourceCode } from '../extractSourceCode.js';
26
26
  import { SURROUNDING_LINE_COUNT } from '../../../../utils/constants.js';
27
27
  import { handleDerivation } from '../stringParsing/derivation/handleDerivation.js';
28
- import { nodeToStrings } from '../parseString.js';
28
+ import { parseStringExpression, nodeToStrings } from '../parseString.js';
29
29
  // Handle CommonJS/ESM interop
30
30
  const traverse = traverseModule.default || traverseModule;
31
31
  // TODO: currently we cover VariableDeclaration and FunctionDeclaration nodes, but are there others we should cover as well?
@@ -1058,6 +1058,60 @@ function processDeriveExpression({ config, state, output, expressionNodePath, sc
1058
1058
  };
1059
1059
  return result;
1060
1060
  }
1061
+ else if (t.isIdentifier(expressionNodePath.node)) {
1062
+ // Resolve variable declarations: const label = cond ? "boy" : "girl"
1063
+ const name = expressionNodePath.node.name;
1064
+ const binding = scopeNode.scope.getBinding(name);
1065
+ if (binding &&
1066
+ binding.path.isVariableDeclarator() &&
1067
+ binding.path.node.init) {
1068
+ // Reject destructuring patterns
1069
+ if (t.isObjectPattern(binding.path.node.id) ||
1070
+ t.isArrayPattern(binding.path.node.id)) {
1071
+ output.errors.push(warnDeriveDestructuringSync(config.file, name, `${expressionNodePath.node.loc?.start?.line}:${expressionNodePath.node.loc?.start?.column}`));
1072
+ return null;
1073
+ }
1074
+ // Enforce const-only
1075
+ const declaration = binding.path.parentPath;
1076
+ if (declaration?.isVariableDeclaration() &&
1077
+ declaration.node.kind !== 'const') {
1078
+ output.warnings.add(warnDeriveNonConstVariableSync(config.file, name, declaration.node.kind, `${expressionNodePath.node.loc?.start?.line}:${expressionNodePath.node.loc?.start?.column}`));
1079
+ return null;
1080
+ }
1081
+ // Resolve via parseStringExpression (handles all derivable expression types)
1082
+ const errorsBefore = output.errors.length;
1083
+ const stringNode = parseStringExpression(binding.path.node.init, binding.path, config.file, config.parsingOptions, output.warnings, output.errors);
1084
+ if (stringNode) {
1085
+ const strings = nodeToStrings(stringNode);
1086
+ if (strings.length === 0) {
1087
+ return null;
1088
+ }
1089
+ if (strings.length === 1) {
1090
+ return strings[0];
1091
+ }
1092
+ return {
1093
+ nodeType: 'multiplication',
1094
+ branches: strings.map((s) => s),
1095
+ };
1096
+ }
1097
+ // parseStringExpression returned null — if it already pushed errors,
1098
+ // avoid double-reporting by skipping the buildJSXTree fallthrough.
1099
+ if (output.errors.length > errorsBefore) {
1100
+ return null;
1101
+ }
1102
+ }
1103
+ // Not resolvable — fall through to existing buildJSXTree behavior
1104
+ return buildJSXTree({
1105
+ node: expressionNodePath.node,
1106
+ helperPath: expressionNodePath,
1107
+ scopeNode,
1108
+ insideT: true,
1109
+ inDerive: true,
1110
+ config,
1111
+ state,
1112
+ output,
1113
+ });
1114
+ }
1061
1115
  else {
1062
1116
  return buildJSXTree({
1063
1117
  node: expressionNodePath.node,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gt",
3
- "version": "2.14.8",
3
+ "version": "2.14.9",
4
4
  "main": "dist/index.js",
5
5
  "bin": "dist/main.js",
6
6
  "files": [