(refactor) rename variables
This commit is contained in:
parent
8fd157802b
commit
a72dbf0494
@ -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);
|
||||
|
@ -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;
|
||||
|
@ -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 {
|
||||
|
@ -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);
|
||||
});
|
||||
});
|
||||
|
@ -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<ClassDeclaration>(node, query);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user