@vendure/ngx-translate-extract
Advanced tools
Comparing version 9.2.1 to 9.3.0
@@ -5,2 +5,3 @@ import { ParserInterface } from './parser.interface.js'; | ||
extract(source: string, filePath: string): TranslationCollection | null; | ||
private getMarkerImportNameFromSource; | ||
} |
import { TranslationCollection } from '../utils/translation.collection.js'; | ||
import { getNamedImportAlias, findFunctionCallExpressions, getStringsFromExpression, getAST } from '../utils/ast-helpers.js'; | ||
const MARKER_MODULE_NAME = 'ngx-translate-extract-marker'; | ||
const MARKER_MODULE_NAME = new RegExp('ngx-translate-extract-marker'); | ||
const MARKER_IMPORT_NAME = 'marker'; | ||
const NGX_TRANSLATE_MARKER_MODULE_NAME = '@ngx-translate/core'; | ||
const NGX_TRANSLATE_MARKER_IMPORT_NAME = '_'; | ||
export class MarkerParser { | ||
extract(source, filePath) { | ||
const sourceFile = getAST(source, filePath); | ||
const markerImportName = getNamedImportAlias(sourceFile, MARKER_IMPORT_NAME, new RegExp(MARKER_MODULE_NAME)); | ||
const markerImportName = this.getMarkerImportNameFromSource(sourceFile); | ||
if (!markerImportName) { | ||
@@ -24,3 +26,8 @@ return null; | ||
} | ||
getMarkerImportNameFromSource(sourceFile) { | ||
const markerImportName = getNamedImportAlias(sourceFile, MARKER_IMPORT_NAME, MARKER_MODULE_NAME) || | ||
getNamedImportAlias(sourceFile, NGX_TRANSLATE_MARKER_IMPORT_NAME, NGX_TRANSLATE_MARKER_MODULE_NAME); | ||
return markerImportName ?? ''; | ||
} | ||
} | ||
//# sourceMappingURL=marker.parser.js.map |
import { extname } from 'node:path'; | ||
import { ScriptKind, tsquery } from '@phenomnomnominal/tsquery'; | ||
import pkg from 'typescript'; | ||
import pkg, { isPropertyAccessExpression, isCallExpression } from 'typescript'; | ||
const { SyntaxKind, isStringLiteralLike, isArrayLiteralExpression, isBinaryExpression, isConditionalExpression } = pkg; | ||
@@ -88,10 +88,10 @@ export function getAST(source, fileName = '') { | ||
export function findClassPropertiesDeclarationByType(node, type) { | ||
const query = `PropertyDeclaration:has(TypeReference > Identifier[name="${type}"]) > Identifier`; | ||
const query = `PropertyDeclaration:has(TypeReference > Identifier[name="${type}"])`; | ||
const result = tsquery(node, query); | ||
return result.map((n) => n.text); | ||
return result.map((n) => n.name.getText()); | ||
} | ||
export function findClassPropertiesDeclarationByInject(node, type) { | ||
const query = `PropertyDeclaration:has(CallExpression > Identifier[name="inject"]):has(CallExpression > Identifier[name="${type}"]) > Identifier`; | ||
const query = `PropertyDeclaration:has(CallExpression > Identifier[name="inject"]):has(CallExpression > Identifier[name="${type}"])`; | ||
const result = tsquery(node, query); | ||
return result.map((n) => n.text); | ||
return result.map((n) => n.name.getText()); | ||
} | ||
@@ -121,14 +121,15 @@ export function findClassPropertiesGetterByType(node, type) { | ||
} | ||
const query = 'CallExpression > ' + | ||
`PropertyAccessExpression:has(Identifier[name=/^(${fnName})$/]):has(PropertyAccessExpression:has(Identifier[name="${prop}"]):has(ThisKeyword)) > ` + | ||
`PropertyAccessExpression:has(ThisKeyword) > Identifier[name="${prop}"]`; | ||
const nodes = tsquery(node, query); | ||
const filtered = nodes.reduce((result, n) => { | ||
if (tsquery(n.parent, 'PropertyAccessExpression > ThisKeyword').length > 0 && | ||
tsquery(n.parent.parent, `PropertyAccessExpression > Identifier[name=/^(${fnName})$/]`).length > 0) { | ||
result.push(n.parent.parent.parent); | ||
const query = `CallExpression > PropertyAccessExpression:has(Identifier[name=/^(${fnName})$/]):has(PropertyAccessExpression:has(ThisKeyword))`; | ||
const result = tsquery(node, query); | ||
const nodes = []; | ||
result.forEach((n) => { | ||
const identifier = isPropertyAccessExpression(n.expression) ? n.expression.name : null; | ||
const property = identifier?.parent; | ||
const method = property?.parent; | ||
const callExpression = method?.parent; | ||
if (identifier?.getText() === prop && isCallExpression(callExpression)) { | ||
nodes.push(callExpression); | ||
} | ||
return result; | ||
}, []); | ||
return filtered; | ||
}); | ||
return nodes; | ||
} | ||
@@ -135,0 +136,0 @@ export function getStringsFromExpression(expression) { |
{ | ||
"name": "@vendure/ngx-translate-extract", | ||
"version": "9.2.1", | ||
"version": "9.3.0", | ||
"description": "Extract strings from projects using ngx-translate", | ||
@@ -20,4 +20,4 @@ "author": "Kim Biesbjerg <kim@biesbjerg.com>", | ||
"gettext-parser": "^4.2.0", | ||
"glob": "^10.3.0", | ||
"json5": "^2.2.3", | ||
"glob": "^10.3.0", | ||
"json5": "^2.2.3", | ||
"tsconfig": "^7.0.0", | ||
@@ -24,0 +24,0 @@ "yargs": "^17.7.2" |
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
140611
1692