feat(cli): add auto derive to t() function - #1141
Merged
Merged
Conversation
Contributor
Author
|
@greptileai plz re-review |
Contributor
Author
|
@greptileai plz re-review |
brian-lou
approved these changes
Mar 21, 2026
eoinest
enabled auto-merge (squash)
March 21, 2026 01:50
Merged
eoinest
pushed a commit
that referenced
this pull request
Mar 21, 2026
This PR was opened by the [Changesets release](https://github.com/changesets/action) GitHub action. When you're ready to do a release, you can merge this and the packages will be published to npm automatically. If you're not ready to do a release yet, that's fine, whenever you add more changesets to main, this PR will be updated. # Releases ## gt@2.13.0 ### Minor Changes - [#1141](#1141) [`4820643`](4820643) Thanks [@ErnestM1234](https://github.com/ErnestM1234)! - feat: auto derive for the t() function ## @generaltranslation/compiler@1.1.34 ### Patch Changes - [#1141](#1141) [`4820643`](4820643) Thanks [@ErnestM1234](https://github.com/ErnestM1234)! - feat: auto derive for the t() function ## gtx-cli@2.13.0 ### Patch Changes - Updated dependencies \[[`4820643`](4820643)]: - gt@2.13.0 ## locadex@1.0.131 ### Patch Changes - Updated dependencies \[[`4820643`](4820643)]: - gt@2.13.0 ## gt-next@6.14.5 ### Patch Changes - Updated dependencies \[[`4820643`](4820643)]: - @generaltranslation/compiler@1.1.34 ## @generaltranslation/gt-next-lint@12.0.5 ### Patch Changes - Updated dependencies \[]: - gt-next@6.14.5 ## gt-next-middleware-e2e@0.1.17 ### Patch Changes - Updated dependencies \[]: - gt-next@6.14.5 Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
For the new
t()function, you no longer need to invokederive()to derive dynamic content. This feature is enabled automatically for thet()function, and can be disabled in thegt.config.jsonby settingfiles.gt.parsingFlags.autoDerive: false.Before
After
This does not affect the
tmacro.Greptile Summary
This PR adds auto-derive support to the
t()function in the CLI parser, allowing dynamic content (variables, ternary expressions, function return values) to be statically resolved without requiring an explicitderive()wrapper. The feature is enabled by default and can be disabled viafiles.gt.parsingFlags.autoDerive: falseingt.config.json.Key changes:
enableAutoDerive: 'ENABLED' | 'DISABLED' | 'AUTO'field is added toParsingConfig; thet()function getsENABLEDwhile all other string registration functions (msg, tagged templates, prop-drilled callbacks) stay atDISABLEDhandleDerivationgains askipDeriveInvocationflag that routes non-static expressions directly throughresolveCallStringVariants(the same resolution logic used insidederive())GTParsingFlagsis introduced intypes/parsing.tsto carry bothautoDeriveandincludeSourceCodeContexttogether, replacing the old ad-hocincludeSourceCodeContextboolean parameter throughout the call chain (createInlineUpdates,createUpdates,stage.ts,validate.ts)warnAutoDeriveNoResultsSyncmessage with context-appropriate wording is added — improving on the feedback from a prior review commentprocessCallExpression.tscompiler pass is cleaned up by deleting the file entirelyIssues found:
@deprecatedmigration path inFilesOptions.gt.includeSourceCodeContextJSDoc saysfiles.gtJson.parsingFlags...but should sayfiles.gt.parsingFlags...— inconsistent with the correct runtime warning ingenerateSettings.tswarnAutoDeriveNoResultsSync(fromhandleDerivation) andwarnNonStringSync(fromderiveExpression) are pushed tooutput.errors, surfacing duplicate messages to the user — more visible now since auto-derive is on by defaultparseStringFunction.ts: example usesgt('hello')instead oft('hello')Confidence Score: 4/5
skipDeriveInvocationis correctly threaded through binary, template-literal, and parenthesized expression branches; theenableAutoDerivetristate is cleanly mapped at each decision point; and the refactoring ofincludeSourceCodeContextintoGTParsingFlagsfixes the pre-existing silent-ignore regression. Tests cover basic auto-derive success and failure cases. Score is 4 rather than 5 due to the duplicate error messages on auto-derive failure (more impactful now that it's the default) and the misleading@deprecatedJSDoc path that would send users to a non-existent config key.packages/cli/src/react/jsx/utils/stringParsing/derivation/index.ts(duplicate error) andpackages/cli/src/types/index.ts(incorrect@deprecatedpath).Important Files Changed
skipDeriveInvocationflag that routes non-static expressions throughresolveCallStringVariantswithout requiring aderive()wrapper. Logic is sound; propagation through binary/template/parenthesized branches is correctly threaded.enableAutoDerive === 'ENABLED'toskipDeriveInvocation: true, but the existingwarnNonStringSyncfallback creates duplicate error messages whenhandleDerivationalready reported a specific auto-derive error.T_REGISTRATION_FUNCTIONdirect calls getENABLED, tagged templates and prop-drilled paths getDISABLED, and the globaltmacro forcesDISABLEDas stated in the PR description. Has a minor JSDoc typo (gtinstead oft).@deprecatedmigration path in theFilesOptions.gt.includeSourceCodeContextJSDoc is incorrect (files.gtJson...should befiles.gt...).GTParsingFlags,BaseParsingFlags, andParseFlagsByFileTypeintroduced cleanly.GTParsingFlagsrequiring bothautoDeriveandincludeSourceCodeContextis appropriate since it's only used internally (the user-facing type usesPartial<GTParsingFlags>).files.gt.includeSourceCodeContextis correctly placed and uses the accurate replacement path. Default parsing flags object is correctly initialized whenfilesconfig is absent.Settings['files']. GT-specific flags flow intogtJson.parsingFlagswith full defaults applied; other file type flags flow intoparsingFlags[fileType]withBASE_PARSING_FLAGS_DEFAULT. Logic is correct.GTParsingFlagsdirectly;includeSourceCodeContextandenableAutoDeriveare both now correctly read fromparsingFlags, fixing the previously reported silent-ignore regression.macroExpansionPass.ts). Clean removal with no dangling references.Flowchart
%%{init: {'theme': 'neutral'}}%% flowchart TD A["parseStrings(name, originalName, ...)"] --> B{originalName?} B -->|T_GLOBAL_MARKER| C["processTaggedTemplateCall\nenableAutoDerive: AUTO→DISABLED"] B -->|t / msg / etc| D{"Direct call?\nrefPath.parent = CallExpression"} D -->|No - tagged template| E["processTaggedTemplateCall\nenableAutoDerive: AUTO→DISABLED"] D -->|No - prop drilled| F["handleFunctionCall\nenableAutoDerive: AUTO→DISABLED"] D -->|Yes| G{originalName === T_REGISTRATION_FUNCTION?} G -->|No - msg etc| H["processTranslationCall\nenableAutoDerive: DISABLED"] G -->|Yes - t| I{config.enableAutoDerive === AUTO?} I -->|No| J["processTranslationCall\nenableAutoDerive: DISABLED"] I -->|Yes| K["processTranslationCall\nenableAutoDerive: ENABLED"] K --> L["deriveExpression\nskipDeriveInvocation: true"] H --> M["deriveExpression\nskipDeriveInvocation: false"] L --> N["handleDerivation\nskipDeriveInvocation=true"] M --> O["handleDerivation\nskipDeriveInvocation=false"] N --> P{Non-static expr?} P -->|Yes| Q["resolveCallStringVariants(expr)\nno derive() wrapper needed"] Q -->|resolved| R["StringNode ✓"] Q -->|null| S["warnAutoDeriveNoResultsSync ✗"] O --> T{Non-static expr?} T -->|Yes, runtimeInterp| U["{n} placeholder"] T -->|Yes, no runtimeInterp| V["return null (warnNonString)"]Comments Outside Diff (2)
packages/cli/src/fs/config/parseFilesConfig.ts, line 184-192 (link)includeSourceCodeContextvalue silently droppedThe deprecated
files.gt.includeSourceCodeContextflag is warned about ingenerateSettings.ts, but its value is never migrated into the newparsingFlags.includeSourceCodeContext. Any user withincludeSourceCodeContext: truein their config will silently lose this behavior after updating — the CLI will emit the deprecation warning yet continue running with the wrong value.A backward-compatible fix is to read the old field as a fallback:
Without this, the deprecation warning is misleading: the user sees "use the new field instead" but has no indication that the old setting is already being ignored.
Prompt To Fix With AI
packages/cli/src/react/jsx/utils/stringParsing/derivation/index.ts, line 60-69 (link)When
skipDeriveInvocationistrueandhandleDerivationcannot resolve the expression, two separate errors are pushed tooutput.errors:warnAutoDeriveNoResultsSync— pushed insidehandleDerivationbefore it returnsnullwarnNonStringSync— pushed here inderiveExpressionwhen!stringNodeSince auto-derive is now the default behavior (enabled by
autoDerive: trueinGT_PARSING_FLAGS_DEFAULT), every unresolvable expression in at()call will generate a duplicate error, which is confusing to users. Consider guardingwarnNonStringSyncso it only fires when no more-specific error was already added — e.g. check ifoutput.errors.lengthgrew before callinghandleDerivation:Prompt To Fix With AI
Prompt To Fix All With AI
Last reviewed commit: "chore: satisfy grept..."