Skip to content

Commit e41a9d5

Browse files
committed
feat(cli): migrate a raw InternationalizationContext value to the provider
`astryx upgrade` runs `migrate-internationalization-context`, the codemod for the retirement that the stacked runtime change declares: a `<InternationalizationContext value={v}>` (or `.Provider`) whose value is a variable maps `locale`, `direction` (as `dir`) and `messages` to `<InternationalizationProvider>` with a TODO for `overrides` and `translate`; an inline object literal maps key by key with a TODO for `translate`; any other value — a call, a conditional, a literal with a spread, an empty literal — and any element that spreads props stay as written behind a TODO that says why (a spread after `value` may override it; a spread anywhere may carry `dir`, `messages` or `overrides`, which the context ignored but the provider would read). Only an element whose name resolves, unshadowed, to the Astryx import is touched: blocks, loop heads, catch clauses, parameters (private methods too), hoisted `var`s, named class and function expressions, `static {}` blocks, namespace bodies (including `export`, `import X =`, `declare function`, `enum`, nested and dotted namespaces) all shadow it; a type-only import proves nothing. The provider is imported under a free alias when the module already binds its name, and an emptied import goes with its comments carried forward and the directive left intact. A second run changes nothing. Fixtures cover each shape; one typechecks the rewritten output with tsc against the real i18n source types; one is the read-and-re-mount shape every real consumer found by a code search has (the transform leaves it alone).
1 parent 04e3c12 commit e41a9d5

3 files changed

Lines changed: 1180 additions & 0 deletions

File tree

‎.changeset/i18n-context-codemod.md‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
'@astryxdesign/cli': patch
3+
---
4+
5+
[feat] `astryx upgrade` runs `migrate-internationalization-context`, which rewrites `<InternationalizationContext value={…}>` (or its `.Provider`) to `<InternationalizationProvider locale dir messages overrides>`: a variable maps `locale`, `direction` (as `dir`) and `messages` — the fields every context value has — and its TODO names `overrides` and `translate`, which the variable's type may lack and the provider has no input for; an inline object literal maps key by key, `overrides` included, with a TODO for `translate` (a literal's `translate` key is kept beside it). Any other value — a call, a spread into a literal, a conditional — is left unchanged behind a TODO saying why. It rewrites JSX whose name resolves, unshadowed, to an Astryx import (named, aliased, or namespace), reuses the file's own provider import name, and leaves a reader of the context alone.
6+
7+
@vjeux

0 commit comments

Comments
 (0)