Skip to content

Commit

Permalink
fix: sonar lint issues
Browse files Browse the repository at this point in the history
  • Loading branch information
koladilip committed Jun 3, 2024
1 parent 0625be4 commit 9ca6100
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 19 deletions.
22 changes: 5 additions & 17 deletions src/engine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { JsonTemplateLexer } from './lexer';
import { JsonTemplateParser } from './parser';

Check failure on line 3 in src/engine.ts

View workflow job for this annotation

GitHub Actions / Check for formatting & lint errors

Dependency cycle detected
import { JsonTemplateReverseTranslator } from './reverse_translator';
import { JsonTemplateTranslator } from './translator';
import { EngineOptions, Expression, FlatMappingPaths } from './types';
import { EngineOptions, Expression, FlatMappingPaths, TemplateInput } from './types';
import { CreateAsyncFunction, convertToObjectMapping, isExpression } from './utils';

export class JsonTemplateEngine {
Expand All @@ -21,10 +21,7 @@ export class JsonTemplateEngine {
return Function(DATA_PARAM_KEY, BINDINGS_PARAM_KEY, this.translate(templateOrExpr, options));
}

private static compileAsAsync(
templateOrExpr: string | Expression | FlatMappingPaths[],
options?: EngineOptions,
): Function {
private static compileAsAsync(templateOrExpr: TemplateInput, options?: EngineOptions): Function {
return CreateAsyncFunction(
DATA_PARAM_KEY,
BINDINGS_PARAM_KEY,
Expand All @@ -49,10 +46,7 @@ export class JsonTemplateEngine {
return convertToObjectMapping(flatMappingAST);
}

static create(
templateOrExpr: string | Expression | FlatMappingPaths[],
options?: EngineOptions,
): JsonTemplateEngine {
static create(templateOrExpr: TemplateInput, options?: EngineOptions): JsonTemplateEngine {
return new JsonTemplateEngine(this.compileAsAsync(templateOrExpr, options));
}

Expand All @@ -63,10 +57,7 @@ export class JsonTemplateEngine {
return new JsonTemplateEngine(this.compileAsSync(templateOrExpr, options));
}

static parse(
template: string | Expression | FlatMappingPaths[],
options?: EngineOptions,
): Expression {
static parse(template: TemplateInput, options?: EngineOptions): Expression {
if (isExpression(template)) {
return template as Expression;
}
Expand All @@ -78,10 +69,7 @@ export class JsonTemplateEngine {
return this.parseMappingPaths(template as FlatMappingPaths[], options);
}

static translate(
template: string | Expression | FlatMappingPaths[],
options?: EngineOptions,
): string {
static translate(template: TemplateInput, options?: EngineOptions): string {
return this.translateExpression(this.parse(template, options));
}

Expand Down
3 changes: 2 additions & 1 deletion src/parser.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable import/no-cycle */
import { BINDINGS_PARAM_KEY, DATA_PARAM_KEY, EMPTY_EXPR } from './constants';
import { JsonTemplateEngine } from './engine';
import { JsonTemplateLexerError, JsonTemplateParserError } from './errors';
Expand Down Expand Up @@ -305,7 +306,7 @@ export class JsonTemplateParser {
}
return {
pathType: PathType.UNKNOWN,
inferredPathType: this.options?.defaultPathType || PathType.RICH,
inferredPathType: this.options?.defaultPathType ?? PathType.RICH,
};
}

Expand Down
2 changes: 1 addition & 1 deletion src/translator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -509,7 +509,7 @@ export class JsonTemplateTranslator {
code.push(`if(${functionName} && typeof ${functionName} === 'function'){`);
code.push(result, '=', functionName, '(', functionArgsStr, ');');
code.push('} else {');
code.push(result, '=', expr.id, '(', expr.parent || result, ',', functionArgsStr, ');');
code.push(result, '=', expr.id, '(', expr.parent ?? result, ',', functionArgsStr, ');');
code.push('}');
} else {
code.push(result, '=', functionName, '(', functionArgsStr, ');');
Expand Down
2 changes: 2 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -283,3 +283,5 @@ export type FlatMappingAST = FlatMappingPaths & {
inputExpr: PathExpression;
outputExpr: PathExpression;
};

export type TemplateInput = string | Expression | FlatMappingPaths[];

0 comments on commit 9ca6100

Please sign in to comment.