Skip to content

Commit

Permalink
Merge pull request #9 from n8n-io/refactor-difference-reporting
Browse files Browse the repository at this point in the history
refactor: change how difference analysis works
  • Loading branch information
valya committed Aug 3, 2023
2 parents 7c11ccc + d40c397 commit 17e002a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 9 deletions.
9 changes: 6 additions & 3 deletions src/Analysis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ interface TmplOrTournament {
tmpl: boolean;
tournament: boolean;
}
type TmplSame = { same: true };
interface TmplSame {
same: true;
expression?: SanitizedString;
}
interface TmplDiff {
same: false;
expression: SanitizedString | 'UNPARSEABLE';
Expand All @@ -24,7 +27,7 @@ export const getTmplDifference = (expr: string, dataNodeName: string): TmplDiffe
return { same: true };
}
if (tmpl.brackets.settings.brackets !== '{{ }}') {
throw new Error('tmpl not initialized with correct brackets. Cannot do analysis.');
tmpl.brackets.set('{{ }}');
}
let tournParsed: string | null;
let tmplParsed: string | null;
Expand Down Expand Up @@ -80,7 +83,7 @@ export const getTmplDifference = (expr: string, dataNodeName: string): TmplDiffe
};
}
// Same, nothing to report
return { same: true };
return { same: true, expression: stripIdentifyingInformation(expr) };
};

const CHAR_REPLACE = /\S/gu;
Expand Down
7 changes: 1 addition & 6 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { getExpressionCode } from './ExpressionBuilder';
import type { ExpressionAnalysis } from './ExpressionBuilder';
import type { TmplDifference } from './Analysis';
import { getTmplDifference } from './Analysis';
export type { TmplDifference } from './Analysis';

Expand All @@ -13,18 +12,14 @@ export class Tournament {
constructor(
public errorHandler: (error: Error) => void = () => {},
private _dataNodeName: string = DATA_NODE_NAME,
public tmplDiffReporter: (diff: TmplDifference) => void = () => {},
) {}

getExpressionCode(expr: string): [string, ExpressionAnalysis] {
return getExpressionCode(expr, this._dataNodeName);
}

tmplDiff(expr: string) {
const diff = getTmplDifference(expr, this._dataNodeName);
if (!diff.same) {
this.tmplDiffReporter(diff);
}
return getTmplDifference(expr, this._dataNodeName);
}

private getFunction(expr: string): [Function, ExpressionAnalysis] {
Expand Down

0 comments on commit 17e002a

Please sign in to comment.