From 721e991d9063bd83a005dfb09e31b49ff64a12ce Mon Sep 17 00:00:00 2001 From: Denis Richard Date: Wed, 1 Sep 2021 08:00:51 +0200 Subject: [PATCH] check module scripts for message definitions - CLI --- src/cli/extract.ts | 25 +++++++++++++++---------- test/cli/extract.test.ts | 17 +++++++++++------ 2 files changed, 26 insertions(+), 16 deletions(-) diff --git a/src/cli/extract.ts b/src/cli/extract.ts index 5efd9c2..99097c1 100644 --- a/src/cli/extract.ts +++ b/src/cli/extract.ts @@ -50,12 +50,14 @@ function isMessagesDefinitionCall(node: Node, methodName: string) { } function getLibImportDeclarations(ast: Ast) { - return (ast.instance - ? ast.instance.content.body.filter( - (node) => - node.type === 'ImportDeclaration' && node.source.value === LIB_NAME, - ) - : []) as ImportDeclaration[]; + return ( + ast.instance + ? ast.instance.content.body.filter( + (node) => + node.type === 'ImportDeclaration' && node.source.value === LIB_NAME, + ) + : [] + ) as ImportDeclaration[]; } function getDefineMessagesSpecifier(decl: ImportDeclaration) { @@ -107,10 +109,10 @@ export function collectMessageDefinitions(ast: Ast) { if (defineImportDecl == null) return []; - const defineMethodName = getDefineMessagesSpecifier(defineImportDecl).local - .name; + const defineMethodName = + getDefineMessagesSpecifier(defineImportDecl).local.name; - walk(ast.instance as any, { + const nodeStepInstructions = { enter(node: Node) { if (isMessagesDefinitionCall(node, defineMethodName) === false) return; const [arg] = (node as CallExpression).arguments; @@ -120,7 +122,10 @@ export function collectMessageDefinitions(ast: Ast) { this.skip(); } }, - }); + }; + + walk(ast.instance as any, nodeStepInstructions); + walk(ast.module as any, nodeStepInstructions); return definitions.flatMap((definitionDict) => definitionDict.properties.map((propNode) => { diff --git a/test/cli/extract.test.ts b/test/cli/extract.test.ts index a2cc994..ca4ddf4 100644 --- a/test/cli/extract.test.ts +++ b/test/cli/extract.test.ts @@ -85,7 +85,13 @@ describe('collecting message definitions', () => { }); it('gets all message definition objects', () => { - const ast = parse(` +