@n8n/tournament
Advanced tools
Comparing version 1.0.0 to 1.0.1
import type { ExpressionAnalysis } from './ExpressionBuilder'; | ||
import type { ExpressionEvaluatorClass } from './Evaluator'; | ||
export type { TmplDifference } from './Analysis'; | ||
export type { ExpressionEvaluator, ExpressionEvaluatorClass } from './Evaluator'; | ||
export type ReturnValue = string | null | (() => unknown); | ||
@@ -7,8 +9,8 @@ export declare class Tournament { | ||
private _dataNodeName; | ||
private _codeCache; | ||
constructor(errorHandler?: (error: Error) => void, _dataNodeName?: string); | ||
private evaluator; | ||
constructor(errorHandler?: (error: Error) => void, _dataNodeName?: string, Evaluator?: ExpressionEvaluatorClass); | ||
setEvaluator(Evaluator: ExpressionEvaluatorClass): void; | ||
getExpressionCode(expr: string): [string, ExpressionAnalysis]; | ||
tmplDiff(expr: string): import("./Analysis").TmplDifference; | ||
private getFunction; | ||
execute(expr: string, data: unknown): ReturnValue; | ||
} |
@@ -6,9 +6,13 @@ "use strict"; | ||
const Analysis_1 = require("./Analysis"); | ||
const FunctionEvaluator_1 = require("./FunctionEvaluator"); | ||
const DATA_NODE_NAME = '___n8n_data'; | ||
class Tournament { | ||
constructor(errorHandler = () => { }, _dataNodeName = DATA_NODE_NAME) { | ||
constructor(errorHandler = () => { }, _dataNodeName = DATA_NODE_NAME, Evaluator = FunctionEvaluator_1.FunctionEvaluator) { | ||
this.errorHandler = errorHandler; | ||
this._dataNodeName = _dataNodeName; | ||
this._codeCache = {}; | ||
this.setEvaluator(Evaluator); | ||
} | ||
setEvaluator(Evaluator) { | ||
this.evaluator = new Evaluator(this); | ||
} | ||
getExpressionCode(expr) { | ||
@@ -20,11 +24,2 @@ return (0, ExpressionBuilder_1.getExpressionCode)(expr, this._dataNodeName); | ||
} | ||
getFunction(expr) { | ||
if (expr in this._codeCache) { | ||
return this._codeCache[expr]; | ||
} | ||
const [code, analysis] = this.getExpressionCode(expr); | ||
const func = new Function('E', code + ';'); | ||
this._codeCache[expr] = [func, analysis]; | ||
return [func, analysis]; | ||
} | ||
execute(expr, data) { | ||
@@ -34,4 +29,3 @@ if (!expr) { | ||
} | ||
const fn = this.getFunction(expr)[0]; | ||
return fn.call(data, this.errorHandler); | ||
return this.evaluator.evaluate(expr, data); | ||
} | ||
@@ -38,0 +32,0 @@ } |
@@ -24,2 +24,3 @@ "use strict"; | ||
}; | ||
const polyfillExceptions = ['this', 'window', 'global']; | ||
const polyfillVar = (path, dataNode, force = false) => { | ||
@@ -31,2 +32,5 @@ if (!force) { | ||
} | ||
if (polyfillExceptions.includes(path.node.name)) { | ||
return; | ||
} | ||
path.replace(buildGlobalSwitch(path.node, dataNode)); | ||
@@ -33,0 +37,0 @@ }; |
{ | ||
"name": "@n8n/tournament", | ||
"version": "1.0.0", | ||
"description": "Output compatiable rewrite of riot tmpl", | ||
"version": "1.0.1", | ||
"description": "Output compatible rewrite of riot tmpl", | ||
"main": "dist/index.js", | ||
@@ -6,0 +6,0 @@ "module": "src/index.ts", |
import { getExpressionCode } from './ExpressionBuilder'; | ||
import type { ExpressionAnalysis } from './ExpressionBuilder'; | ||
import { getTmplDifference } from './Analysis'; | ||
import type { ExpressionEvaluator, ExpressionEvaluatorClass } from './Evaluator'; | ||
import { FunctionEvaluator } from './FunctionEvaluator'; | ||
export type { TmplDifference } from './Analysis'; | ||
export type { ExpressionEvaluator, ExpressionEvaluatorClass } from './Evaluator'; | ||
@@ -10,3 +13,3 @@ const DATA_NODE_NAME = '___n8n_data'; | ||
export class Tournament { | ||
private _codeCache: Record<string, [Function, ExpressionAnalysis]> = {}; | ||
private evaluator!: ExpressionEvaluator; | ||
@@ -16,4 +19,11 @@ constructor( | ||
private _dataNodeName: string = DATA_NODE_NAME, | ||
) {} | ||
Evaluator: ExpressionEvaluatorClass = FunctionEvaluator, | ||
) { | ||
this.setEvaluator(Evaluator); | ||
} | ||
setEvaluator(Evaluator: ExpressionEvaluatorClass) { | ||
this.evaluator = new Evaluator(this); | ||
} | ||
getExpressionCode(expr: string): [string, ExpressionAnalysis] { | ||
@@ -27,12 +37,2 @@ return getExpressionCode(expr, this._dataNodeName); | ||
private getFunction(expr: string): [Function, ExpressionAnalysis] { | ||
if (expr in this._codeCache) { | ||
return this._codeCache[expr]; | ||
} | ||
const [code, analysis] = this.getExpressionCode(expr); | ||
const func = new Function('E', code + ';'); | ||
this._codeCache[expr] = [func, analysis]; | ||
return [func, analysis]; | ||
} | ||
execute(expr: string, data: unknown): ReturnValue { | ||
@@ -44,5 +44,4 @@ // This is to match tmpl. This will only really happen if | ||
} | ||
const fn = this.getFunction(expr)[0]; | ||
return fn.call(data, this.errorHandler); | ||
return this.evaluator.evaluate(expr, data); | ||
} | ||
} |
@@ -42,2 +42,4 @@ import type { types } from 'recast'; | ||
const polyfillExceptions = ['this', 'window', 'global']; | ||
const polyfillVar = ( | ||
@@ -54,2 +56,6 @@ path: NodePath<types.namedTypes.Identifier>, | ||
} | ||
// For tmpl compat we ignore these identifiers | ||
if (polyfillExceptions.includes(path.node.name)) { | ||
return; | ||
} | ||
path.replace(buildGlobalSwitch(path.node, dataNode)); | ||
@@ -56,0 +62,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
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
Uses eval
Supply chain riskPackage uses dynamic code execution (e.g., eval()), which is a dangerous practice. This can prevent the code from running in certain environments and increases the risk that the code may contain exploits or malicious behavior.
Found 1 instance in 1 package
132349
44
1861