@n8n/tournament
Advanced tools
Comparing version 1.0.3 to 1.0.4
@@ -43,3 +43,3 @@ "use strict"; | ||
try { | ||
[tournParsed, analysis] = (0, ExpressionBuilder_1.getExpressionCode)(expr, dataNodeName); | ||
[tournParsed, analysis] = (0, ExpressionBuilder_1.getExpressionCode)(expr, dataNodeName, { before: [], after: [] }); | ||
} | ||
@@ -46,0 +46,0 @@ catch (e) { |
import type { types } from 'recast'; | ||
import type { ExpressionCode, ExpressionText } from './ExpressionSplitter'; | ||
import type { TournamentHooks } from './'; | ||
export interface ExpressionAnalysis { | ||
@@ -13,3 +14,3 @@ has: { | ||
export declare const getParsedExpression: (expr: string) => Array<ExpressionText | ParsedCode>; | ||
export declare const getExpressionCode: (expr: string, dataNodeName: string) => [string, ExpressionAnalysis]; | ||
export declare const getExpressionCode: (expr: string, dataNodeName: string, hooks: TournamentHooks) => [string, ExpressionAnalysis]; | ||
export {}; |
@@ -111,3 +111,3 @@ "use strict"; | ||
exports.getParsedExpression = getParsedExpression; | ||
const getExpressionCode = (expr, dataNodeName) => { | ||
const getExpressionCode = (expr, dataNodeName, hooks) => { | ||
var _a, _b; | ||
@@ -134,6 +134,13 @@ const chunks = (0, exports.getParsedExpression)(expr); | ||
else { | ||
const parsed = (_a = (0, VariablePolyfill_1.jsVariablePolyfill)(fixStringNewLines(chunk.parsed), dataNode)) === null || _a === void 0 ? void 0 : _a[0]; | ||
const fixed = fixStringNewLines(chunk.parsed); | ||
for (const hook of hooks.before) { | ||
hook(fixed, dataNode); | ||
} | ||
const parsed = (_a = (0, VariablePolyfill_1.jsVariablePolyfill)(fixed, dataNode)) === null || _a === void 0 ? void 0 : _a[0]; | ||
if (!parsed || parsed.type !== 'ExpressionStatement') { | ||
throw new SyntaxError('Not a expression statement'); | ||
} | ||
for (const hook of hooks.after) { | ||
hook(parsed, dataNode); | ||
} | ||
const functionBody = buildFunctionBody(parsed.expression); | ||
@@ -161,6 +168,13 @@ if (shouldWrapInTry(parsed)) { | ||
else { | ||
const parsed = (_b = (0, VariablePolyfill_1.jsVariablePolyfill)(fixStringNewLines(chunks[1].parsed), dataNode)) === null || _b === void 0 ? void 0 : _b[0]; | ||
const fixed = fixStringNewLines(chunks[1].parsed); | ||
for (const hook of hooks.before) { | ||
hook(fixed, dataNode); | ||
} | ||
const parsed = (_b = (0, VariablePolyfill_1.jsVariablePolyfill)(fixed, dataNode)) === null || _b === void 0 ? void 0 : _b[0]; | ||
if (!parsed || parsed.type !== 'ExpressionStatement') { | ||
throw new SyntaxError('Not a expression statement'); | ||
} | ||
for (const hook of hooks.after) { | ||
hook(parsed, dataNode); | ||
} | ||
let retData = ast_types_1.builders.returnStatement(parsed.expression); | ||
@@ -167,0 +181,0 @@ if (shouldWrapInTry(parsed)) { |
import type { ExpressionAnalysis } from './ExpressionBuilder'; | ||
import type { ExpressionEvaluatorClass } from './Evaluator'; | ||
import type { ASTBeforeHook, ASTAfterHook } from './ast'; | ||
export type { TmplDifference } from './Analysis'; | ||
export type { ExpressionEvaluator, ExpressionEvaluatorClass } from './Evaluator'; | ||
export * from './ast'; | ||
export type ReturnValue = string | null | (() => unknown); | ||
export interface TournamentHooks { | ||
before: ASTBeforeHook[]; | ||
after: ASTAfterHook[]; | ||
} | ||
export declare class Tournament { | ||
errorHandler: (error: Error) => void; | ||
private _dataNodeName; | ||
private astHooks; | ||
private evaluator; | ||
constructor(errorHandler?: (error: Error) => void, _dataNodeName?: string, Evaluator?: ExpressionEvaluatorClass); | ||
constructor(errorHandler?: (error: Error) => void, _dataNodeName?: string, Evaluator?: ExpressionEvaluatorClass, astHooks?: TournamentHooks); | ||
setEvaluator(Evaluator: ExpressionEvaluatorClass): void; | ||
@@ -12,0 +19,0 @@ getExpressionCode(expr: string): [string, ExpressionAnalysis]; |
"use strict"; | ||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
var desc = Object.getOwnPropertyDescriptor(m, k); | ||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { | ||
desc = { enumerable: true, get: function() { return m[k]; } }; | ||
} | ||
Object.defineProperty(o, k2, desc); | ||
}) : (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
o[k2] = m[k]; | ||
})); | ||
var __exportStar = (this && this.__exportStar) || function(m, exports) { | ||
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p); | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
@@ -7,7 +21,9 @@ exports.Tournament = void 0; | ||
const FunctionEvaluator_1 = require("./FunctionEvaluator"); | ||
__exportStar(require("./ast"), exports); | ||
const DATA_NODE_NAME = '___n8n_data'; | ||
class Tournament { | ||
constructor(errorHandler = () => { }, _dataNodeName = DATA_NODE_NAME, Evaluator = FunctionEvaluator_1.FunctionEvaluator) { | ||
constructor(errorHandler = () => { }, _dataNodeName = DATA_NODE_NAME, Evaluator = FunctionEvaluator_1.FunctionEvaluator, astHooks = { before: [], after: [] }) { | ||
this.errorHandler = errorHandler; | ||
this._dataNodeName = _dataNodeName; | ||
this.astHooks = astHooks; | ||
this.setEvaluator(Evaluator); | ||
@@ -19,3 +35,3 @@ } | ||
getExpressionCode(expr) { | ||
return (0, ExpressionBuilder_1.getExpressionCode)(expr, this._dataNodeName); | ||
return (0, ExpressionBuilder_1.getExpressionCode)(expr, this._dataNodeName, this.astHooks); | ||
} | ||
@@ -22,0 +38,0 @@ tmplDiff(expr) { |
{ | ||
"name": "@n8n/tournament", | ||
"version": "1.0.3", | ||
"version": "1.0.4", | ||
"description": "Output compatible rewrite of riot tmpl", | ||
@@ -24,4 +24,4 @@ "main": "dist/index.js", | ||
"engines": { | ||
"node": ">=18.10", | ||
"pnpm": ">=8.6" | ||
"node": ">=20.15", | ||
"pnpm": ">=9.5" | ||
}, | ||
@@ -35,3 +35,3 @@ "files": [ | ||
], | ||
"packageManager": "pnpm@8.6.1", | ||
"packageManager": "pnpm@9.6.0", | ||
"keywords": [], | ||
@@ -38,0 +38,0 @@ "author": "", |
@@ -36,3 +36,3 @@ import * as tmpl from '@n8n_io/riot-tmpl'; | ||
try { | ||
[tournParsed, analysis] = getExpressionCode(expr, dataNodeName); | ||
[tournParsed, analysis] = getExpressionCode(expr, dataNodeName, { before: [], after: [] }); | ||
} catch (e) { | ||
@@ -39,0 +39,0 @@ tournParsed = null; |
@@ -13,2 +13,3 @@ import type { namedTypes } from 'ast-types'; | ||
import { parseWithEsprimaNext } from './Parser'; | ||
import type { TournamentHooks } from './ast'; | ||
@@ -175,2 +176,3 @@ export interface ExpressionAnalysis { | ||
dataNodeName: string, | ||
hooks: TournamentHooks, | ||
): [string, ExpressionAnalysis] => { | ||
@@ -220,3 +222,7 @@ const chunks = getParsedExpression(expr); | ||
} else { | ||
const parsed = jsVariablePolyfill(fixStringNewLines(chunk.parsed), dataNode)?.[0]; | ||
const fixed = fixStringNewLines(chunk.parsed); | ||
for (const hook of hooks.before) { | ||
hook(fixed, dataNode); | ||
} | ||
const parsed = jsVariablePolyfill(fixed, dataNode)?.[0]; | ||
if (!parsed || parsed.type !== 'ExpressionStatement') { | ||
@@ -226,2 +232,6 @@ throw new SyntaxError('Not a expression statement'); | ||
for (const hook of hooks.after) { | ||
hook(parsed, dataNode); | ||
} | ||
const functionBody = buildFunctionBody(parsed.expression); | ||
@@ -270,6 +280,7 @@ | ||
} else { | ||
const parsed = jsVariablePolyfill( | ||
fixStringNewLines((chunks[1] as ParsedCode).parsed), | ||
dataNode, | ||
)?.[0]; | ||
const fixed = fixStringNewLines((chunks[1] as ParsedCode).parsed); | ||
for (const hook of hooks.before) { | ||
hook(fixed, dataNode); | ||
} | ||
const parsed = jsVariablePolyfill(fixed, dataNode)?.[0]; | ||
if (!parsed || parsed.type !== 'ExpressionStatement') { | ||
@@ -279,2 +290,6 @@ throw new SyntaxError('Not a expression statement'); | ||
for (const hook of hooks.after) { | ||
hook(parsed, dataNode); | ||
} | ||
let retData: StatementKind = b.returnStatement(parsed.expression); | ||
@@ -281,0 +296,0 @@ if (shouldWrapInTry(parsed)) { |
@@ -6,4 +6,7 @@ import { getExpressionCode } from './ExpressionBuilder'; | ||
import { FunctionEvaluator } from './FunctionEvaluator'; | ||
import type { TournamentHooks } from './ast'; | ||
export type { TmplDifference } from './Analysis'; | ||
export type { ExpressionEvaluator, ExpressionEvaluatorClass } from './Evaluator'; | ||
export * from './ast'; | ||
@@ -20,2 +23,3 @@ const DATA_NODE_NAME = '___n8n_data'; | ||
Evaluator: ExpressionEvaluatorClass = FunctionEvaluator, | ||
private readonly astHooks: TournamentHooks = { before: [], after: [] }, | ||
) { | ||
@@ -30,3 +34,3 @@ this.setEvaluator(Evaluator); | ||
getExpressionCode(expr: string): [string, ExpressionAnalysis] { | ||
return getExpressionCode(expr, this._dataNodeName); | ||
return getExpressionCode(expr, this._dataNodeName, this.astHooks); | ||
} | ||
@@ -33,0 +37,0 @@ |
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
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
137176
48
1957