diff --git a/packages/cli/test/api/extract.hashedkeys.test.js b/packages/cli/test/api/extract.hashedkeys.test.js index 2881387a..13bed81a 100644 --- a/packages/cli/test/api/extract.hashedkeys.test.js +++ b/packages/cli/test/api/extract.hashedkeys.test.js @@ -154,6 +154,34 @@ describe('extractPhrases with hashed keys', () => { string: 'HTML inline text', meta: { context: [], tags: [], occurrences: ['react.jsx'] }, }, + '57b0d93fc0e1c3af68a41214147efd97': { + string: 'Text 5', + meta: { context: [], tags: [], occurrences: ['react.jsx'] }, + }, + '404d0c0fef510bc89da7bc58ef160ccc': { + string: 'Text <1> 6 ', + meta: { context: [], tags: [], occurrences: ['react.jsx'] }, + }, + '4f5fe2d7356c474bd2f4c03176c6bc45': { + string: 'Text <1> <2> 7 ', + meta: { context: [], tags: [], occurrences: ['react.jsx'] }, + }, + '1ecaf4c087b894bf86987fc2972ddba7': { + string: 'Text 8', + meta: { context: ['foo'], tags: [], occurrences: ['react.jsx'] }, + }, + f9818c4a4b3772c365b8522ff29cb785: { + string: 'Text <1/> 9', + meta: { context: [], tags: [], occurrences: ['react.jsx'] }, + }, + '37678ce8d9c3a694ce19b947c64b9787': { + string: 'Text {msg}', + meta: { context: [], tags: [], occurrences: ['react.jsx'] }, + }, + '5c6622f57e93ed83011b45833a12b0aa': { + string: 'Text 10', + meta: { context: [], tags: ['tag1', 'tag2'], occurrences: ['react.jsx'] }, + }, }); }); diff --git a/packages/cli/test/api/extract.sourcekeys.test.js b/packages/cli/test/api/extract.sourcekeys.test.js index 7de31557..05125385 100644 --- a/packages/cli/test/api/extract.sourcekeys.test.js +++ b/packages/cli/test/api/extract.sourcekeys.test.js @@ -147,6 +147,34 @@ describe('extractPhrases with source keys', () => { string: 'HTML inline text', meta: { context: [], tags: [], occurrences: ['react.jsx'] }, }, + 'Text 5': { + string: 'Text 5', + meta: { context: [], tags: [], occurrences: ['react.jsx'] }, + }, + 'Text <1> 6 ': { + string: 'Text <1> 6 ', + meta: { context: [], tags: [], occurrences: ['react.jsx'] }, + }, + 'Text <1> <2> 7 ': { + string: 'Text <1> <2> 7 ', + meta: { context: [], tags: [], occurrences: ['react.jsx'] }, + }, + 'Text 8::foo': { + string: 'Text 8', + meta: { context: ['foo'], tags: [], occurrences: ['react.jsx'] }, + }, + 'Text <1/> 9': { + string: 'Text <1/> 9', + meta: { context: [], tags: [], occurrences: ['react.jsx'] }, + }, + 'Text {msg}': { + string: 'Text {msg}', + meta: { context: [], tags: [], occurrences: ['react.jsx'] }, + }, + 'Text 10': { + string: 'Text 10', + meta: { context: [], tags: ['tag1', 'tag2'], occurrences: ['react.jsx'] }, + }, }); }); diff --git a/packages/cli/test/fixtures/react.jsx b/packages/cli/test/fixtures/react.jsx index 48666399..44d28238 100644 --- a/packages/cli/test/fixtures/react.jsx +++ b/packages/cli/test/fixtures/react.jsx @@ -30,6 +30,13 @@ function foo() { {msg} {msg2} + Text 5 + Text 6 + Text 7 + Text 8 + Text
9
+ Text {'{msg}'} + Text 10 ); } diff --git a/packages/react/src/utils/toStr.js b/packages/react/src/utils/toStr.js index 7ad0169f..1738e912 100644 --- a/packages/react/src/utils/toStr.js +++ b/packages/react/src/utils/toStr.js @@ -109,7 +109,7 @@ export function toElement(translation, propsContainer) { if (rightSlash) { // Single tag, copy props and don't include children in the React element result.push(React.createElement(type, { ...props, key: lastKey })); - lastEnd += openingTag.length; + lastEnd += matchIndex + openingTag.length; } else { // Opening tag, find the closing tag which is guaranteed to be there and // to be unique diff --git a/packages/react/tests/T.test.js b/packages/react/tests/T.test.js index af864ead..a653cebc 100644 --- a/packages/react/tests/T.test.js +++ b/packages/react/tests/T.test.js @@ -44,4 +44,28 @@ describe('T', () => { render(world} />); expect(screen.getByText('world')).toBeTruthy(); }); + + it('renders body', () => { + render(hello safe text); + expect(screen.queryByText('hello')).toBeInTheDocument(); + expect(screen.queryByText('safe text')).toBeInTheDocument(); + }); + + it('renders body with single tags', () => { + render(hello
safe text
); + expect(screen.queryByText('hello')).toBeInTheDocument(); + expect(screen.queryByText('safe text')).toBeInTheDocument(); + }); + + it('renders nestedbody', () => { + render(hello safe text); + expect(screen.queryByText('hello')).toBeInTheDocument(); + expect(screen.queryByText('safe text')).toBeInTheDocument(); + }); + + it('renders body with params', () => { + render(hello mister {'{username}'}); + expect(screen.queryByText('hello')).toBeInTheDocument(); + expect(screen.queryByText('mister Bill')).toBeInTheDocument(); + }); });