diff --git a/src/cli/extract.ts b/src/cli/extract.ts index 16e91ab..cdefadd 100644 --- a/src/cli/extract.ts +++ b/src/cli/extract.ts @@ -150,10 +150,7 @@ export function collectMessages(markup: string): Message[] { return messageObj } - return { - node, - meta: { id }, - } + return { node, meta: { id } } }), ].filter(Boolean) } diff --git a/src/cli/includes/getObjFromExpression.ts b/src/cli/includes/getObjFromExpression.ts index a992817..0bf435c 100644 --- a/src/cli/includes/getObjFromExpression.ts +++ b/src/cli/includes/getObjFromExpression.ts @@ -5,9 +5,11 @@ import { Message } from '../types' export function getObjFromExpression(exprNode: ObjectExpression) { return exprNode.properties.reduce( (acc, prop: Property) => { - if (prop.value.type !== 'Literal') return acc // we only want primitives - if (prop.value.value !== Object(prop.value.value)) { + if ( + prop.value.type === 'Literal' && + prop.value.value !== Object(prop.value.value) + ) { const key = (prop.key as Identifier).name as string acc.meta[key] = prop.value.value } diff --git a/test/cli/extract.test.ts b/test/cli/extract.test.ts index 3f56577..0711447 100644 --- a/test/cli/extract.test.ts +++ b/test/cli/extract.test.ts @@ -10,6 +10,12 @@ import { } from '../../src/cli/extract' describe('collecting format calls', () => { + test('returns nothing if there are no script tag', () => { + const ast = parse(`
Hey
`) + const calls = collectFormatCalls(ast) + expect(calls).toHaveLength(0) + }) + test('returns nothing if there are no imports', () => { const ast = parse(`