@vendure/ngx-translate-extract
Advanced tools
Comparing version 9.2.0 to 9.2.1
@@ -8,3 +8,3 @@ import { TranslationCollection } from '../utils/translation.collection.js'; | ||
const sourceFile = getAST(source, filePath); | ||
const markerImportName = getNamedImportAlias(sourceFile, MARKER_MODULE_NAME, MARKER_IMPORT_NAME); | ||
const markerImportName = getNamedImportAlias(sourceFile, MARKER_IMPORT_NAME, new RegExp(MARKER_MODULE_NAME)); | ||
if (!markerImportName) { | ||
@@ -11,0 +11,0 @@ return null; |
@@ -6,3 +6,3 @@ import path from 'node:path'; | ||
import { TranslationCollection } from '../utils/translation.collection.js'; | ||
import { findClassDeclarations, findClassPropertiesByType, findPropertyCallExpressions, findMethodCallExpressions, getStringsFromExpression, findMethodParameterByType, findConstructorDeclaration, getSuperClassName, getImportPath, findFunctionExpressions, findVariableNameByInjectType, getAST } from '../utils/ast-helpers.js'; | ||
import { findClassDeclarations, findClassPropertiesByType, findPropertyCallExpressions, findMethodCallExpressions, getStringsFromExpression, findMethodParameterByType, findConstructorDeclaration, getSuperClassName, getImportPath, findFunctionExpressions, findVariableNameByInjectType, getAST, getNamedImport } from '../utils/ast-helpers.js'; | ||
const TRANSLATE_SERVICE_TYPE_REFERENCE = 'TranslateService'; | ||
@@ -58,10 +58,11 @@ const TRANSLATE_SERVICE_METHOD_NAMES = ['get', 'instant', 'stream']; | ||
findParentClassProperties(classDeclaration, ast) { | ||
const superClassName = getSuperClassName(classDeclaration); | ||
if (!superClassName) { | ||
const superClassNameOrAlias = getSuperClassName(classDeclaration); | ||
if (!superClassNameOrAlias) { | ||
return []; | ||
} | ||
const importPath = getImportPath(ast, superClassName); | ||
const importPath = getImportPath(ast, superClassNameOrAlias); | ||
if (!importPath) { | ||
return []; | ||
} | ||
const superClassName = getNamedImport(ast, superClassNameOrAlias, importPath); | ||
const currDir = path.join(path.dirname(ast.fileName), '/'); | ||
@@ -68,0 +69,0 @@ const key = `${currDir}|${importPath}`; |
@@ -1,5 +0,6 @@ | ||
import pkg, { Node, NamedImports, ClassDeclaration, ConstructorDeclaration, CallExpression, Expression, SourceFile } from 'typescript'; | ||
import pkg, { Node, Identifier, ClassDeclaration, ConstructorDeclaration, CallExpression, Expression, SourceFile } from 'typescript'; | ||
export declare function getAST(source: string, fileName?: string): SourceFile; | ||
export declare function getNamedImports(node: Node, moduleName: string): NamedImports[]; | ||
export declare function getNamedImportAlias(node: Node, moduleName: string, importName: string): string | null; | ||
export declare function getNamedImportIdentifiers(node: Node, moduleName: string, importPath: string | RegExp): Identifier[]; | ||
export declare function getNamedImport(node: Node, importName: string, importPath: string | RegExp): string | null; | ||
export declare function getNamedImportAlias(node: Node, importName: string, importPath: string | RegExp): string | null; | ||
export declare function findClassDeclarations(node: Node, name?: string): ClassDeclaration[]; | ||
@@ -6,0 +7,0 @@ export declare function findFunctionExpressions(node: Node): pkg.Node[]; |
@@ -15,21 +15,15 @@ import { extname } from 'node:path'; | ||
} | ||
export function getNamedImports(node, moduleName) { | ||
const query = `ImportDeclaration[moduleSpecifier.text=/${moduleName}/] NamedImports`; | ||
export function getNamedImportIdentifiers(node, moduleName, importPath) { | ||
const importStringLiteralValue = importPath instanceof RegExp ? `value=${importPath.toString()}` : `value="${importPath}"`; | ||
const query = `ImportDeclaration:has(StringLiteral[${importStringLiteralValue}]) ImportSpecifier:has(Identifier[name="${moduleName}"]) > Identifier`; | ||
return tsquery(node, query); | ||
} | ||
export function getNamedImportAlias(node, moduleName, importName) { | ||
const [namedImportNode] = getNamedImports(node, moduleName); | ||
if (!namedImportNode) { | ||
return null; | ||
} | ||
const query = `ImportSpecifier:has(Identifier[name="${importName}"]) > Identifier`; | ||
const identifiers = tsquery(namedImportNode, query); | ||
if (identifiers.length === 1) { | ||
return identifiers[0].text; | ||
} | ||
if (identifiers.length > 1) { | ||
return identifiers[identifiers.length - 1].text; | ||
} | ||
return null; | ||
export function getNamedImport(node, importName, importPath) { | ||
const identifiers = getNamedImportIdentifiers(node, importName, importPath); | ||
return identifiers.at(0)?.text ?? null; | ||
} | ||
export function getNamedImportAlias(node, importName, importPath) { | ||
const identifiers = getNamedImportIdentifiers(node, importName, importPath); | ||
return identifiers.at(-1)?.text ?? null; | ||
} | ||
export function findClassDeclarations(node, name = null) { | ||
@@ -36,0 +30,0 @@ let query = 'ClassDeclaration'; |
{ | ||
"name": "@vendure/ngx-translate-extract", | ||
"version": "9.2.0", | ||
"version": "9.2.1", | ||
"description": "Extract strings from projects using ngx-translate", | ||
@@ -5,0 +5,0 @@ "author": "Kim Biesbjerg <kim@biesbjerg.com>", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
139826
1683