Skip to content

Commit f7c7d92

Browse files
committed
fix: render of JSX as expressions
1 parent 526d995 commit f7c7d92

6 files changed

Lines changed: 122 additions & 130 deletions

File tree

cmp/compiler/src/__test-utils__/mocks.ts

Lines changed: 1 addition & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -3,39 +3,10 @@
33
* Prevents duplication of test helper functions across test files
44
*/
55

6-
import type { LoaderConfig, MetadataSchema } from "../types";
6+
import type { LoaderConfig } from "../types";
77
import { createLoaderConfig } from "../utils/config-factory";
88
import { DictionarySchema } from "../translators";
99

10-
/**
11-
* Create a mock metadata schema for testing
12-
*
13-
* @param overrides - Partial metadata to override defaults
14-
* @returns Complete MetadataSchema
15-
*
16-
* @example
17-
* ```typescript
18-
* const metadata = createMockMetadata({
19-
* entries: {
20-
* "abc123": createMockTranslationEntry({ sourceText: "Hello" })
21-
* }
22-
* });
23-
* ```
24-
*/
25-
export function createMockMetadata(
26-
overrides?: Partial<MetadataSchema>,
27-
): MetadataSchema {
28-
return {
29-
version: "0.1",
30-
entries: {},
31-
stats: {
32-
totalEntries: 0,
33-
lastUpdated: new Date().toISOString(),
34-
},
35-
...overrides,
36-
};
37-
}
38-
3910
/**
4011
* Create a mock loader config for testing
4112
*

cmp/compiler/src/plugin/transform/__snapshots__/transform.test.ts.snap

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,26 @@ export const Button = function () {
210210
};"
211211
`;
212212

213+
exports[`transformComponent > corner cases > should handle separate fragments used in expressions correctly 1`] = `
214+
"import { useTranslation } from "@lingo.dev/_compiler/react";
215+
export default function Home() {
216+
const t = useTranslation(["4ea986f9331c", "f6c9a24ac814", "2c582e458cdf"]);
217+
const translatableText = <>Hello World</>;
218+
const translatableMixedContextFragment = <>{t("4ea986f9331c", "<b0>Mixed</b0> content <i0>fragment</i0>", {
219+
b0: chunks => <b>{chunks}</b>,
220+
i0: chunks => <i>{chunks}</i>
221+
})}</>;
222+
return <main>
223+
<div>{t("f6c9a24ac814", "To translate it you have to wrap it into the {translatableText}", {
224+
translatableText
225+
})}</div>
226+
<div>{t("2c582e458cdf", "Content that has text and other tags inside will br translated as a single entity: {translatableMixedContextFragment}", {
227+
translatableMixedContextFragment
228+
})}</div>
229+
</main>;
230+
}"
231+
`;
232+
213233
exports[`transformComponent > isomorphic hooks (unified useTranslation) > should handle mixed async and non-async components in same file 1`] = `
214234
"import { useTranslation } from "@lingo.dev/_compiler/react";
215235
import { getServerTranslations } from "@lingo.dev/_compiler/react/server";

0 commit comments

Comments
 (0)