Skip to content

Commit

Permalink
fix: extract t from custom elements (#144)
Browse files Browse the repository at this point in the history
  • Loading branch information
stepan662 authored Jan 3, 2025
1 parent 31dde1a commit 5d9eee0
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
5 changes: 5 additions & 0 deletions src/extractor/parserNgx/ngxMapper.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import { Token } from '../parser/types.js';

export const ngxMapper = (token: Token) => {
// custom tag names have dynamic token names
if (token.type?.startsWith('entity.name.tag.html.ng.')) {
return 'tag.name';
}

switch (token.type) {
// ngx template tags
case 'punctuation.definition.tag.begin.html':
Expand Down
4 changes: 2 additions & 2 deletions test/e2e/formats.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ describe('push and pull with different formats', () => {
config: 'xliff-java',
inPlatform: 'You have {0} items',
fileLocation: 'en.xliff',
inFile: 'You have %s items',
inFile: 'You have %1$s items',
});
});

Expand Down Expand Up @@ -146,7 +146,7 @@ describe('push and pull with different formats', () => {
config: 'android-xml',
inPlatform: 'You have {0} items',
fileLocation: 'values-en/strings.xml',
inFile: 'You have %s items',
inFile: 'You have %1$s items',
});
});

Expand Down
12 changes: 12 additions & 0 deletions test/unit/extractor/ngx/elementWithT.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,18 @@ describe('element with t param', () => {
expect(extracted.keys).toEqual([{ keyName: 'key1', line: 3 }]);
});

it('extracts calls to t from custom element', async () => {
const code = `
<template>
<mat-error t key="key1"></mat-error>
</template>
`;

const extracted = await extractNgxKeys(code, 'test.component.html');
expect(extracted.warnings).toEqual([]);
expect(extracted.keys).toEqual([{ keyName: 'key1', line: 3 }]);
});

it('extracts keys specified binded properties', async () => {
const expected = [{ keyName: 'key1', line: 3 }];

Expand Down

0 comments on commit 5d9eee0

Please sign in to comment.