From e08fa29099119a3e7e24ae20f9c66e19f184be48 Mon Sep 17 00:00:00 2001 From: Christian Kaisermann Date: Thu, 28 Nov 2019 23:16:15 -0300 Subject: [PATCH] =?UTF-8?q?test:=20=F0=9F=92=8D=20add=20missing=20test=20f?= =?UTF-8?q?or=20component=20without=20script?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/cli/extract.ts | 5 +---- src/cli/includes/getObjFromExpression.ts | 6 ++++-- test/cli/extract.test.ts | 6 ++++++ 3 files changed, 11 insertions(+), 6 deletions(-) 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(`