New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More β†’
Socket
Sign inDemoInstall
Socket

@jsverse/transloco-keys-manager

Package Overview
Dependencies
Maintainers
0
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@jsverse/transloco-keys-manager - npm Package Compare versions

Comparing version 5.1.0 to 6.0.0

3

keys-builder/template/directive.extractor.js
import { ASTWithSource, } from '@angular/compiler';
import { addKey } from '../add-key.js';
import { resolveAliasAndKey } from '../utils/resolvers.utils.js';
import { isBlockNode, isBoundAttribute, isConditionalExpression, isElement, isInterpolation, isLiteralExpression, isLiteralMap, isSupportedNode, isTemplate, isTextAttribute, parseTemplate, resolveBlockChildNodes, resolveKeysFromLiteralMap, } from './utils.js';
import { isBlockNode, isBoundAttribute, isElement, isInterpolation, isSupportedNode, isTemplate, isTextAttribute, parseTemplate, resolveBlockChildNodes, resolveKeysFromLiteralMap, } from './utils.js';
import { coerceArray } from '../../utils/collection.utils.js';
import { isConditionalExpression, isLiteralExpression, isLiteralMap } from '@jsverse/utils';
export function directiveExtractor(config) {

@@ -7,0 +8,0 @@ const ast = parseTemplate(config);

@@ -0,69 +1,20 @@

import { tmplAstVisitAll } from '@angular/compiler';
import { addKey } from '../add-key.js';
import { resolveAliasAndKey } from '../utils/resolvers.utils.js';
import { isBinaryExpression, isBindingPipe, isBoundText, isConditionalExpression, isElement, isInterpolation, isLiteralExpression, isLiteralMap, isCall, isPropertyRead, isTemplate, parseTemplate, isBlockNode, resolveBlockChildNodes, resolveKeysFromLiteralMap, } from './utils.js';
import { parseTemplate, resolveKeysFromLiteralMap } from './utils.js';
import { notNil } from '../../utils/validators.utils.js';
import { AstPipeCollector, isBindingPipe, isConditionalExpression, isLiteralExpression, isLiteralMap, TmplPipeCollector } from '@jsverse/utils';
export function pipeExtractor(config) {
const ast = parseTemplate(config);
traverse(ast.nodes, config);
}
function traverse(nodes, config) {
for (const node of nodes) {
if (isBlockNode(node)) {
traverse(resolveBlockChildNodes(node), config);
continue;
}
let astTrees = [];
if (isElement(node) || isTemplate(node)) {
astTrees = node.inputs.map((input) => input.value.ast);
traverse(node.children, config);
}
else if (isBoundText(node)) {
astTrees = [node.value.ast];
}
for (const ast of astTrees) {
const pipes = getTranslocoPipeAst(ast);
const keysWithParams = pipes
.map((p) => resolveKeyAndParam(p))
.flat()
.filter(notNil);
addKeysFromAst(keysWithParams, config);
}
const parsedTemplate = parseTemplate(config);
const tmplVisitor = new TmplPipeCollector('transloco');
tmplAstVisitAll(tmplVisitor, parsedTemplate.nodes);
const astVisitor = new AstPipeCollector();
astVisitor.visitAll([...tmplVisitor.astTrees], {});
const keysWithParams = astVisitor.pipes.get('transloco')?.map((p) => resolveKeyAndParam(p.node))
.flat()
.filter(notNil);
if (keysWithParams) {
addKeysFromAst(keysWithParams, config);
}
}
function isTranslocoPipe(ast) {
const isPipeChaining = isBindingPipe(ast.exp);
const isTransloco = ast.name === 'transloco' &&
(isPipeChaining ||
isLiteralExpression(ast.exp) ||
isConditionalExpression(ast.exp));
return isTransloco || (isPipeChaining && isTranslocoPipe(ast.exp));
}
function getTranslocoPipeAst(ast) {
let exp = [];
if (isBindingPipe(ast) && isTranslocoPipe(ast)) {
return [ast];
}
else if (isBindingPipe(ast)) {
exp = [...ast.args, ast.exp];
}
else if (isLiteralMap(ast)) {
exp = ast.values;
}
else if (isInterpolation(ast)) {
exp = ast.expressions;
}
else if (isConditionalExpression(ast)) {
exp = [ast.condition, ast.trueExp, ast.falseExp];
}
else if (isBinaryExpression(ast)) {
exp = [ast.left, ast.right];
}
else if (isCall(ast)) {
exp = [...ast.args, ast.receiver];
}
else if (isPropertyRead(ast)) {
exp = [ast.receiver];
}
return exp.map(getTranslocoPipeAst).flat();
}
function resolveKeyAndParam(pipe, paramsNode) {

@@ -70,0 +21,0 @@ const resolvedParams = paramsNode ?? pipe.args[0];

import { RecursiveAstVisitor, } from '@angular/compiler';
import { addKey } from '../add-key.js';
import { resolveAliasAndKey } from '../utils/resolvers.utils.js';
import { isBoundAttribute, isBoundText, isConditionalExpression, isElement, isInterpolation, isLiteralExpression, isCall, isNgTemplateTag, isSupportedNode, isTemplate, parseTemplate, isBlockNode, resolveBlockChildNodes, isLiteralMap, resolveKeysFromLiteralMap, } from './utils.js';
import { isBoundAttribute, isBoundText, isElement, isInterpolation, isCall, isNgTemplateTag, isSupportedNode, isTemplate, parseTemplate, isBlockNode, resolveBlockChildNodes, resolveKeysFromLiteralMap, } from './utils.js';
import { isConditionalExpression, isLiteralExpression, isLiteralMap } from '@jsverse/utils';
export function structuralDirectiveExtractor(config) {

@@ -6,0 +7,0 @@ const ast = parseTemplate(config);

@@ -1,2 +0,2 @@

import { Binary, BindingPipe, Conditional, Interpolation, LiteralMap, LiteralPrimitive, Call, ParseTemplateOptions, PropertyRead, TmplAstBoundAttribute, TmplAstBoundText, TmplAstElement, TmplAstTemplate, TmplAstTextAttribute, TmplAstNode, TmplAstDeferredBlock, TmplAstDeferredBlockError, TmplAstDeferredBlockLoading, TmplAstDeferredBlockPlaceholder, TmplAstForLoopBlock, TmplAstForLoopBlockEmpty, TmplAstIfBlockBranch, TmplAstSwitchBlockCase, TmplAstIfBlock, TmplAstSwitchBlock } from '@angular/compiler';
import { Call, Interpolation, LiteralMap, ParseTemplateOptions, PropertyRead, TmplAstBoundAttribute, TmplAstBoundText, TmplAstDeferredBlock, TmplAstDeferredBlockError, TmplAstDeferredBlockLoading, TmplAstDeferredBlockPlaceholder, TmplAstElement, TmplAstForLoopBlock, TmplAstForLoopBlockEmpty, TmplAstIfBlock, TmplAstIfBlockBranch, TmplAstNode, TmplAstSwitchBlock, TmplAstSwitchBlockCase, TmplAstTemplate, TmplAstTextAttribute } from '@angular/compiler';
import { TemplateExtractorConfig } from './types';

@@ -8,3 +8,2 @@ export declare function isTemplate(node: unknown): node is TmplAstTemplate;

export declare function isTextAttribute(node: unknown): node is TmplAstTextAttribute;
export declare function isBindingPipe(ast: unknown): ast is BindingPipe;
export declare function isInterpolation(ast: unknown): ast is Interpolation;

@@ -14,6 +13,2 @@ export declare function isCall(ast: unknown): ast is Call;

export declare function isNgTemplateTag(node: TmplAstTemplate): boolean;
export declare function isLiteralExpression(expression: unknown): expression is LiteralPrimitive;
export declare function isLiteralMap(expression: unknown): expression is LiteralMap;
export declare function isConditionalExpression(expression: unknown): expression is Conditional;
export declare function isBinaryExpression(expression: unknown): expression is Binary;
export declare function parseTemplate(config: TemplateExtractorConfig, options?: ParseTemplateOptions): import("@angular/compiler").ParsedTemplate;

@@ -20,0 +15,0 @@ type GuardedType<T> = T extends (x: any) => x is infer U ? U : never;

@@ -1,3 +0,4 @@

import { Binary, BindingPipe, Conditional, Interpolation, LiteralMap, LiteralPrimitive, Call, parseTemplate as ngParseTemplate, PropertyRead, TmplAstBoundAttribute, TmplAstBoundText, TmplAstElement, TmplAstTemplate, TmplAstTextAttribute, TmplAstDeferredBlock, TmplAstDeferredBlockError, TmplAstDeferredBlockLoading, TmplAstDeferredBlockPlaceholder, TmplAstForLoopBlock, TmplAstForLoopBlockEmpty, TmplAstIfBlockBranch, TmplAstSwitchBlockCase, TmplAstIfBlock, TmplAstSwitchBlock, } from '@angular/compiler';
import { Call, Interpolation, parseTemplate as ngParseTemplate, PropertyRead, TmplAstBoundAttribute, TmplAstBoundText, TmplAstDeferredBlock, TmplAstDeferredBlockError, TmplAstDeferredBlockLoading, TmplAstDeferredBlockPlaceholder, TmplAstElement, TmplAstForLoopBlock, TmplAstForLoopBlockEmpty, TmplAstIfBlock, TmplAstIfBlockBranch, TmplAstSwitchBlock, TmplAstSwitchBlockCase, TmplAstTemplate, TmplAstTextAttribute } from '@angular/compiler';
import { readFile } from '../../utils/file.utils.js';
import { isLiteralMap } from '@jsverse/utils';
export function isTemplate(node) {

@@ -18,5 +19,2 @@ return node instanceof TmplAstTemplate;

}
export function isBindingPipe(ast) {
return ast instanceof BindingPipe;
}
export function isInterpolation(ast) {

@@ -34,14 +32,2 @@ return ast instanceof Interpolation;

}
export function isLiteralExpression(expression) {
return expression instanceof LiteralPrimitive;
}
export function isLiteralMap(expression) {
return expression instanceof LiteralMap;
}
export function isConditionalExpression(expression) {
return expression instanceof Conditional;
}
export function isBinaryExpression(expression) {
return expression instanceof Binary;
}
export function parseTemplate(config, options) {

@@ -48,0 +34,0 @@ const { file, content } = config;

{
"name": "@jsverse/transloco-keys-manager",
"version": "5.1.0",
"version": "6.0.0",
"description": "Extract translatable keys from projects that uses Transloco",

@@ -48,4 +48,5 @@ "engines": {

"dependencies": {
"@angular/compiler": "17.2.0",
"@angular/compiler": "^18.1.0",
"@jsverse/transloco-utils": "7.0.1",
"@jsverse/utils": "1.0.0-beta.3",
"@phenomnomnominal/tsquery": "6.1.3",

@@ -52,0 +53,0 @@ "chalk": "5.3.0",

@@ -528,17 +528,10 @@ > [!IMPORTANT]

{
"i18n:extract": "DEBUG=* transloco-keys-manager extract",
"i18n:extract": "DEBUG=tkm:config,tkm:paths transloco-keys-manager extract",
"i18n:find": "DEBUG=* transloco-keys-manager find"
}
```
Supported namespaces: `*|config|paths|scopes|extraction`, setting `*` will print all the debugger logs.
Supported namespaces: `tkm:*|config|paths|scopes|extraction`, setting `tkm:*` will print all the debugger logs.
You can also chain several namespaces:
```json
{
"i18n:extract": "DEBUG=config,paths transloco-keys-manager extract"
}
```
## Contributors ✨
Thank goes to all these wonderful [people who contributed](https://github.com/jsverse/transloco-keys-manager/graphs/contributors) ❀️

@@ -15,3 +15,3 @@ import debug from 'debug';

export function devlog(namespace, tag, values) {
if (!debug.enabled(namespace))
if (!debug.enabled(`tkm:${namespace}`))
return;

@@ -18,0 +18,0 @@ console.log(`\n\x1b[4m🐞 DEBUG - ${tag}:\x1b[0m`);

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

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚑️ by Socket Inc