diff --git a/packages/cli/src/api/extract.js b/packages/cli/src/api/extract.js index 42cf0972..80bf7219 100644 --- a/packages/cli/src/api/extract.js +++ b/packages/cli/src/api/extract.js @@ -414,40 +414,43 @@ function extractPhrases(file, relativeFile, options = {}) { }); }, - // Decorator + // Supported SDK Decorators Decorator({ node }) { const elem = node.expression; if (!elem || !elem.arguments || !elem.arguments.length) return; - if (!node.expression.callee.name === 'T') return; - let string = ''; - let key = ''; - const params = {}; - _.each(node.expression.arguments, (arg) => { - if (arg.type === 'StringLiteral') { - string = arg.value; - } else if (arg.type === 'ObjectExpression') { - _.each(arg.properties, (prop) => { - if (prop.key.name === '_key') { - key = prop.value.value; - } else { - params[prop.key.name] = prop.value.value; - } - }); - } - }); + // Angular SDK T Decorator + if (node && node.expression && node.expression.callee + && node.expression.callee.name === 'T') { + let string = ''; + let key = ''; + const params = {}; + _.each(node.expression.arguments, (arg) => { + if (arg.type === 'StringLiteral') { + string = arg.value; + } else if (arg.type === 'ObjectExpression') { + _.each(arg.properties, (prop) => { + if (prop.key.name === '_key') { + key = prop.value.value; + } else { + params[prop.key.name] = prop.value.value; + } + }); + } + }); - if (string) { - const partial = createPayload(string, params, relativeFile, options); - if (!isPayloadValid(partial, options)) return; + if (string) { + const partial = createPayload(string, params, relativeFile, options); + if (!isPayloadValid(partial, options)) return; - mergePayload(HASHES, { - [key || partial.key]: { - string: partial.string, - meta: partial.meta, - }, - }); + mergePayload(HASHES, { + [key || partial.key]: { + string: partial.string, + meta: partial.meta, + }, + }); + } } }, diff --git a/packages/cli/test/api/extract.hashedkeys.test.js b/packages/cli/test/api/extract.hashedkeys.test.js index 6287b672..ebde699d 100644 --- a/packages/cli/test/api/extract.hashedkeys.test.js +++ b/packages/cli/test/api/extract.hashedkeys.test.js @@ -207,7 +207,7 @@ describe('extractPhrases with hashed keys', () => { }); }); - it('works with typescript', async () => { + it('works with angular typescript', async () => { expect(await extractPhrases('test/fixtures/typescript.ts', 'typescript.ts', { useHashedKeys: true, })) diff --git a/packages/cli/test/api/extract.sourcekeys.test.js b/packages/cli/test/api/extract.sourcekeys.test.js index 32ab3ede..d42ffffb 100644 --- a/packages/cli/test/api/extract.sourcekeys.test.js +++ b/packages/cli/test/api/extract.sourcekeys.test.js @@ -198,7 +198,7 @@ describe('extractPhrases with source keys', () => { }); }); - it('works with typescript', async () => { + it('works with angular typescript', async () => { expect(await extractPhrases('test/fixtures/typescript.ts', 'typescript.ts')) .to.deep.equal({ 'text.monday': { diff --git a/packages/cli/test/fixtures/typescript.ts b/packages/cli/test/fixtures/typescript.ts index 4be05b2a..c6d4a919 100644 --- a/packages/cli/test/fixtures/typescript.ts +++ b/packages/cli/test/fixtures/typescript.ts @@ -12,6 +12,9 @@ class ItemRegistry { @T('Monday', { _key: 'text.monday' }) weekday: string; + @ViewChild('someInput', { static: true }) + someInputRef: ElementRef; + constructor(name: string, id: number) { this.name = name; this.id = id;