From a72dbf0494033330021ab1194ea544bf5b9922fe Mon Sep 17 00:00:00 2001 From: Kim Biesbjerg Date: Tue, 17 Sep 2019 08:15:51 +0200 Subject: [PATCH] (refactor) rename variables --- src/parsers/directive.parser.ts | 8 ++++---- src/parsers/marker.parser.ts | 14 +++++++------- src/parsers/pipe.parser.ts | 8 ++++---- src/parsers/service.parser.ts | 20 ++++++++++---------- src/utils/ast-helpers.ts | 2 +- 5 files changed, 26 insertions(+), 26 deletions(-) diff --git a/src/parsers/directive.parser.ts b/src/parsers/directive.parser.ts index 7b7032d..26e691b 100644 --- a/src/parsers/directive.parser.ts +++ b/src/parsers/directive.parser.ts @@ -6,14 +6,14 @@ import { parseTemplate, TmplAstNode, TmplAstElement, TmplAstTextAttribute } from export class DirectiveParser implements ParserInterface { - public extract(template: string, path: string): TranslationCollection { - if (path && isPathAngularComponent(path)) { - template = extractComponentInlineTemplate(template); + public extract(source: string, filePath: string): TranslationCollection | null { + if (filePath && isPathAngularComponent(filePath)) { + source = extractComponentInlineTemplate(source); } let collection: TranslationCollection = new TranslationCollection(); - const nodes: TmplAstNode[] = this.parseTemplate(template, path); + const nodes: TmplAstNode[] = this.parseTemplate(source, filePath); this.getTranslatableElements(nodes).forEach(element => { const key = this.getElementTranslateAttrValue(element) || this.getElementContents(element); collection = collection.add(key); diff --git a/src/parsers/marker.parser.ts b/src/parsers/marker.parser.ts index 19bd52d..314e89a 100644 --- a/src/parsers/marker.parser.ts +++ b/src/parsers/marker.parser.ts @@ -12,20 +12,20 @@ export class MarkerParser implements ParserInterface { public extract(contents: string, filePath: string): TranslationCollection | null { const sourceFile = tsquery.ast(contents, filePath); - const markerFnName = getNamedImportAlias(sourceFile, MARKER_PACKAGE_MODULE_NAME, MARKER_PACKAGE_IMPORT_NAME); - if (!markerFnName) { + const markerImportName = getNamedImportAlias(sourceFile, MARKER_PACKAGE_MODULE_NAME, MARKER_PACKAGE_IMPORT_NAME); + if (!markerImportName) { return; } let collection: TranslationCollection = new TranslationCollection(); - const callNodes = findFunctionCallExpressions(sourceFile, markerFnName); - callNodes.forEach(callNode => { - const [firstArgNode] = callNode.arguments; - if (!firstArgNode) { + const callExpressions = findFunctionCallExpressions(sourceFile, markerImportName); + callExpressions.forEach(callExpression => { + const [firstArg] = callExpression.arguments; + if (!firstArg) { return; } - const strings = getStringsFromExpression(firstArgNode); + const strings = getStringsFromExpression(firstArg); collection = collection.addKeys(strings); }); return collection; diff --git a/src/parsers/pipe.parser.ts b/src/parsers/pipe.parser.ts index 4666012..a45572d 100644 --- a/src/parsers/pipe.parser.ts +++ b/src/parsers/pipe.parser.ts @@ -4,12 +4,12 @@ import { isPathAngularComponent, extractComponentInlineTemplate } from '../utils export class PipeParser implements ParserInterface { - public extract(template: string, path: string): TranslationCollection { - if (path && isPathAngularComponent(path)) { - template = extractComponentInlineTemplate(template); + public extract(source: string, filePath: string): TranslationCollection | null { + if (filePath && isPathAngularComponent(filePath)) { + source = extractComponentInlineTemplate(source); } - return this.parseTemplate(template); + return this.parseTemplate(source); } protected parseTemplate(template: string): TranslationCollection { diff --git a/src/parsers/service.parser.ts b/src/parsers/service.parser.ts index 64111dc..581477d 100644 --- a/src/parsers/service.parser.ts +++ b/src/parsers/service.parser.ts @@ -2,7 +2,7 @@ import { tsquery } from '@phenomnomnominal/tsquery'; import { ParserInterface } from './parser.interface'; import { TranslationCollection } from '../utils/translation.collection'; -import { findClasses, findClassPropertyByType, findMethodCallExpressions, getStringsFromExpression } from '../utils/ast-helpers'; +import { findClassDeclarations, findClassPropertyByType, findMethodCallExpressions, getStringsFromExpression } from '../utils/ast-helpers'; const TRANSLATE_SERVICE_TYPE_REFERENCE = 'TranslateService'; const TRANSLATE_SERVICE_METHOD_NAMES = ['get', 'instant', 'stream']; @@ -12,26 +12,26 @@ export class ServiceParser implements ParserInterface { public extract(source: string, filePath: string): TranslationCollection | null { const sourceFile = tsquery.ast(source, filePath); - const classNodes = findClasses(sourceFile); - if (!classNodes) { + const classDeclarations = findClassDeclarations(sourceFile); + if (!classDeclarations) { return; } let collection: TranslationCollection = new TranslationCollection(); - classNodes.forEach(classNode => { - const propName: string = findClassPropertyByType(classNode, TRANSLATE_SERVICE_TYPE_REFERENCE); + classDeclarations.forEach(classDeclaration => { + const propName: string = findClassPropertyByType(classDeclaration, TRANSLATE_SERVICE_TYPE_REFERENCE); if (!propName) { return; } - const callNodes = findMethodCallExpressions(classNode, propName, TRANSLATE_SERVICE_METHOD_NAMES); - callNodes.forEach(callNode => { - const [firstArgNode] = callNode.arguments; - if (!firstArgNode) { + const callExpressions = findMethodCallExpressions(classDeclaration, propName, TRANSLATE_SERVICE_METHOD_NAMES); + callExpressions.forEach(callExpression => { + const [firstArg] = callExpression.arguments; + if (!firstArg) { return; } - const strings = getStringsFromExpression(firstArgNode); + const strings = getStringsFromExpression(firstArg); collection = collection.addKeys(strings); }); }); diff --git a/src/utils/ast-helpers.ts b/src/utils/ast-helpers.ts index 65de82f..7526908 100644 --- a/src/utils/ast-helpers.ts +++ b/src/utils/ast-helpers.ts @@ -36,7 +36,7 @@ export function getNamedImportAlias(node: Node, moduleName: string, importName: return null; } -export function findClasses(node: Node): ClassDeclaration[] { +export function findClassDeclarations(node: Node): ClassDeclaration[] { const query = 'ClassDeclaration'; return tsquery(node, query); }