Skip to content

Commit

Permalink
fix: interpolation with self-closing tag (#83)
Browse files Browse the repository at this point in the history
  • Loading branch information
stepan662 authored Jun 5, 2024
1 parent 0ec1b5b commit ed8c541
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 1 deletion.
7 changes: 7 additions & 0 deletions src/extractor/machines/shared/properties.ts
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,10 @@ export default createMachine<PropertiesContext>(
actions: 'markPropertyAsDynamic',
cond: (ctx) => ctx.jsxDepth === 0,
},
{
actions: 'decrementDoubleJsxDepth',
cond: (_ctx, e) => e.token === '/>',
},
{
actions: 'decrementJsxDepth',
},
Expand Down Expand Up @@ -412,6 +416,9 @@ export default createMachine<PropertiesContext>(
incrementJsxDepth: assign({
jsxDepth: (ctx, _evt) => ctx.jsxDepth + 2,
}),
decrementDoubleJsxDepth: assign({
jsxDepth: (ctx, _evt) => ctx.jsxDepth - 2,
}),
decrementJsxDepth: assign({
jsxDepth: (ctx, _evt) => ctx.jsxDepth - 1,
}),
Expand Down
7 changes: 6 additions & 1 deletion test/e2e/push.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { fileURLToPath } from 'url';
import { tolgeeDataToDict } from './utils/data.js';
import { run, runWithStdin } from './utils/run.js';
import {
DEFAULT_SCOPES,
createPak,
createProjectWithClient,
deleteProject,
Expand Down Expand Up @@ -187,12 +188,16 @@ describe('project 3', () => {
});

it('removes other keys', async () => {
const pakWithDelete = await createPak(client, [
...DEFAULT_SCOPES,
'keys.delete',
]);
const out = await run([
'--config',
PROJECT_3_DEPRECATED_CONFIG,
'push',
'--api-key',
pak,
pakWithDelete,
'--remove-other-keys',
]);

Expand Down
16 changes: 16 additions & 0 deletions test/unit/extractor/react.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -905,6 +905,22 @@ describe.each(['jsx', 'tsx'])('<T> (.%s)', (ext) => {
expect(extracted.keys).toEqual(expected);
});

it('does not get confused by self-closing tags interpolation', async () => {
const expected = [{ keyName: 'key1', line: 3 }];

const code = `
import '@tolgee/react'
<T
keyName='key1'
params={{ strong: <strong /> }}
/>
`;

const extracted = await extractKeys(code, FILE_NAME);
expect(extracted.warnings).toEqual([]);
expect(extracted.keys).toEqual(expected);
});

describe('dynamic data', () => {
it('emits warning on dynamic keys and skips', async () => {
const expected = [
Expand Down

0 comments on commit ed8c541

Please sign in to comment.