Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@journeyapps/evaluator

Package Overview
Dependencies
Maintainers
2
Versions
266
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@journeyapps/evaluator - npm Package Compare versions

Comparing version 0.0.0-dev.7b2d7c4 to 0.0.0-dev.7ca4865

dist/@types/definitions/VariableScope.d.ts

7

dist/@types/definitions/VariableFormatStringScope.d.ts
import { FormatStringScope } from './FormatStringScope';
import { TypeInterface } from './TypeInterface';
export type VariableScope = Record<string, any> & {
type: TypeInterface;
_display?(): Promise<string>;
_cached?(field: string): any;
_get?(field: string): Promise<any>;
};
import { VariableScope } from './VariableScope';
export declare class VariableFormatStringScope implements FormatStringScope {

@@ -10,0 +5,0 @@ variableScope: VariableScope;

@@ -7,4 +7,5 @@ export * from './parsers';

export * from './definitions/ObjectRefInterface';
export * from './definitions/VariableScope';
export * from './definitions/VariableFormatStringScope';
export * from './definitions/FormatStringScope';
export * from './definitions/VariableFormatStringScope';
export * from './tools';
import { BlockStatement } from '@babel/types';
import { ConstantTokenExpression } from '../token-expressions';
import { AbstractExpressionParser, ExpressionParserFactory, ExpressionNodeParseEvent } from './AbstractExpressionParser';
export declare class BlockStatementParser extends AbstractExpressionParser<BlockStatement> {
parse(event: ExpressionNodeParseEvent<BlockStatement>): import("../token-expressions").TokenExpression<import("../token-expressions").TokenExpressionOptions, any>;
parse(event: ExpressionNodeParseEvent<BlockStatement>): import("../token-expressions").TokenExpression<import("../token-expressions").TokenExpressionOptions, any> | ConstantTokenExpression<{
expression: string;
}>;
}

@@ -6,0 +9,0 @@ export declare class BlockStatementParserFactory extends ExpressionParserFactory<BlockStatementParser> {

export * from './AbstractExpressionParser';
export * from './ArrayExpressionParser';
export * from './BlockStatementParser';

@@ -8,3 +9,4 @@ export * from './CallExpressionParser';

export * from './LiteralExpressionParser';
export * from './LogicalExpressionParser';
export * from './MemberExpressionParser';
export * from './ObjectExpressionParser';

@@ -7,3 +7,5 @@ import { DirectiveLiteral, Literal } from '@babel/types';

export declare class LiteralExpressionParser extends AbstractExpressionParser<LiteralExpression, ParsedLiteralExpressionType> {
parse(event: ExpressionNodeParseEvent<LiteralExpression>): FunctionTokenExpression | ConstantTokenExpression;
parse(event: ExpressionNodeParseEvent<LiteralExpression>): FunctionTokenExpression | PrimitiveConstantTokenExpression | ConstantTokenExpression<{
expression: string;
}>;
}

@@ -10,0 +12,0 @@ export declare class LiteralExpressionParserFactory extends ExpressionParserFactory<LiteralExpressionParser> {

@@ -6,6 +6,6 @@ /**

import { FormatStringScope } from '../../definitions/FormatStringScope';
export declare class ConstantTokenExpression extends TokenExpression {
export declare class ConstantTokenExpression<O extends TokenExpressionOptions = TokenExpressionOptions> extends TokenExpression<O> {
static TYPE: string;
static isInstanceOf(obj: any): obj is ConstantTokenExpression;
constructor(options: TokenExpressionOptions);
constructor(options: O);
/**

@@ -12,0 +12,0 @@ * Concatenate a token to current token and return a new token.

@@ -8,7 +8,9 @@ /**

expression: any;
isNullLiteral?: boolean;
}
export declare class PrimitiveConstantTokenExpression extends ConstantTokenExpression {
export declare class PrimitiveConstantTokenExpression extends ConstantTokenExpression<PrimitiveConstantTokenExpressionOptions> {
static readonly TYPE = "primitive-constant-expression";
static isInstanceOf(obj: any): obj is PrimitiveConstantTokenExpression;
constructor(options: PrimitiveConstantTokenExpressionOptions);
isNullLiteral(): boolean;
/**

@@ -15,0 +17,0 @@ * Concatenate a token to current token and return a new token.

@@ -16,8 +16,7 @@ import { TokenExpression, TokenExpressionOptions } from '../TokenExpression';

static parse(source: string): FunctionTokenExpression;
rawExpression: string;
constructor(options: FunctionTokenExpressionOptions);
get arguments(): TokenExpression<TokenExpressionOptions, any>[];
get arguments(): TokenExpression[] | null;
functionName(): string;
setFunctionName(name: string): void;
isShorthand(): boolean;
isCallExpression(): boolean;
tokenEvaluatePromise(scope: FormatStringScope): Promise<any>;

@@ -24,0 +23,0 @@ /**

@@ -5,2 +5,3 @@ "use strict";

const FormatStringContext_1 = require("./context/FormatStringContext");
const FunctionExpressionContext_1 = require("./context/FunctionExpressionContext");
const token_expressions_1 = require("./token-expressions");

@@ -32,3 +33,7 @@ const TokenExpressionParser_1 = require("./TokenExpressionParser");

else {
const exp = `{${token.stringify()}}`;
let exp = '{';
if (token_expressions_1.FunctionTokenExpression.isInstanceOf(token)) {
exp += token_expressions_1.FunctionTokenExpression.PREFIX;
}
exp += `${token.stringify()}}`;
result.expression += exp;

@@ -79,7 +84,10 @@ start += exp.length;

// `spec` is everything between the curly braces "{" and "}".
const spec = expression.substring(i + 1, i + parsedBraces.length);
const spec = expression.substring(i + 1, i + parsedBraces.length).trim();
if (spec.indexOf('?') === 0) {
throw new Error('Usage of ? in expressions is not supported.');
}
const parsedToken = parser.parse({ source: spec, context: new FormatStringContext_1.FormatStringContext() });
const context = token_expressions_1.FunctionTokenExpression.hasPrefix(spec)
? new FunctionExpressionContext_1.FunctionExpressionContext()
: new FormatStringContext_1.FormatStringContext();
const parsedToken = parser.parse({ source: spec, context: context });
if (parsedToken) {

@@ -246,3 +254,3 @@ parsedToken.start = i;

const token = tokens[i];
if (token.isConstant()) {
if (token.isConstant() && !(token_expressions_1.PrimitiveConstantTokenExpression.isInstanceOf(token) && token.isNullLiteral())) {
result += `${token.valueOf()}`;

@@ -249,0 +257,0 @@ }

@@ -23,5 +23,6 @@ "use strict";

__exportStar(require("./definitions/ObjectRefInterface"), exports);
__exportStar(require("./definitions/VariableScope"), exports);
__exportStar(require("./definitions/VariableFormatStringScope"), exports);
__exportStar(require("./definitions/FormatStringScope"), exports);
__exportStar(require("./definitions/VariableFormatStringScope"), exports);
__exportStar(require("./tools"), exports);
//# sourceMappingURL=index.js.map

@@ -11,3 +11,7 @@ "use strict";

const args = node.arguments.map((arg) => parseNode({ node: arg, source: source }));
return new token_expressions_1.FunctionTokenExpression({ expression: source.slice(node.start, node.end), name: name, arguments: args });
return new token_expressions_1.FunctionTokenExpression({
expression: source.slice(node.start, node.end),
name: name,
arguments: args
});
}

@@ -14,0 +18,0 @@ }

@@ -11,10 +11,8 @@ "use strict";

const args = [test, consequent, alternate].map((arg) => parseNode({ node: arg, source }));
const argStrings = [
source.slice(test.start, test.end),
source.slice(consequent.start, consequent.end),
source.slice(alternate.start, alternate.end)
];
const fnName = `(function(test, consequent, alternate) { return test ? consequent : alternate; })`;
const expression = `${fnName}(${argStrings.join(', ')})`;
return new token_expressions_1.FunctionTokenExpression({ expression: expression, name: fnName, arguments: args });
return new token_expressions_1.FunctionTokenExpression({
expression: source.slice(node.start, node.end),
name: fnName,
arguments: args
});
}

@@ -21,0 +19,0 @@ }

@@ -18,4 +18,3 @@ "use strict";

return new token_expressions_1.FunctionTokenExpression({
expression: expression,
isShorthand: true
expression: expression
});

@@ -22,0 +21,0 @@ }

@@ -18,2 +18,3 @@ "use strict";

__exportStar(require("./AbstractExpressionParser"), exports);
__exportStar(require("./ArrayExpressionParser"), exports);
__exportStar(require("./BlockStatementParser"), exports);

@@ -25,4 +26,5 @@ __exportStar(require("./CallExpressionParser"), exports);

__exportStar(require("./LiteralExpressionParser"), exports);
__exportStar(require("./LogicalExpressionParser"), exports);
__exportStar(require("./MemberExpressionParser"), exports);
__exportStar(require("./ObjectExpressionParser"), exports);
//# sourceMappingURL=index.js.map

@@ -14,3 +14,3 @@ "use strict";

if (inFunctionContext) {
return new token_expressions_1.FunctionTokenExpression({ expression: `'${node.value}'`, isShorthand: true });
return new token_expressions_1.FunctionTokenExpression({ expression: `'${node.value}'` });
}

@@ -21,9 +21,9 @@ return new token_expressions_1.ConstantTokenExpression({ expression: node.value });

if (inFunctionContext) {
return new token_expressions_1.FunctionTokenExpression({ expression: 'null', isShorthand: true });
return new token_expressions_1.FunctionTokenExpression({ expression: 'null' });
}
return new token_expressions_1.ConstantTokenExpression({ expression: 'null' });
return new token_expressions_1.PrimitiveConstantTokenExpression({ expression: null, isNullLiteral: true });
}
if ('value' in node) {
if (inFunctionContext) {
return new token_expressions_1.FunctionTokenExpression({ expression: `${node.value}`, isShorthand: true });
return new token_expressions_1.FunctionTokenExpression({ expression: `${node.value}` });
}

@@ -30,0 +30,0 @@ return new token_expressions_1.PrimitiveConstantTokenExpression({ expression: node.value });

@@ -15,2 +15,6 @@ "use strict";

}
isNullLiteral() {
var _a;
return (_a = this.options.isNullLiteral) !== null && _a !== void 0 ? _a : false;
}
/**

@@ -17,0 +21,0 @@ * Concatenate a token to current token and return a new token.

@@ -13,17 +13,9 @@ "use strict";

static parse(source) {
const token = TokenExpressionParser_1.TokenExpressionParser.get().parse({
return TokenExpressionParser_1.TokenExpressionParser.get().parse({
source,
context: new FunctionExpressionContext_1.FunctionExpressionContext()
});
if (token == null) {
console.error(`Failed to parse function token expression: ${source}`);
return null;
}
token.rawExpression = source.trim();
return token;
}
constructor(options) {
var _a, _b;
super(FunctionTokenExpression.TYPE, Object.assign(Object.assign({}, options), { isFunction: true }));
this.rawExpression = (_a = this.expression) === null || _a === void 0 ? void 0 : _a.trim();
this.expression = FunctionTokenExpression.trimPrefix(this.expression);

@@ -34,3 +26,2 @@ if (!this.options.name) {

}
this.options.arguments = (_b = this.options.arguments) !== null && _b !== void 0 ? _b : [];
}

@@ -46,4 +37,4 @@ get arguments() {

}
isShorthand() {
return this.options.isShorthand;
isCallExpression() {
return this.arguments != null;
}

@@ -65,13 +56,7 @@ async tokenEvaluatePromise(scope) {

stringify() {
if (this.isShorthand()) {
return this.functionName();
if (!this.isCallExpression()) {
return this.expression;
}
const argStrings = this.arguments.map((arg) => {
const res = arg.stringify();
if (arg.isFunction()) {
return FunctionTokenExpression.trimPrefix(res);
}
return res;
});
return `${FunctionTokenExpression.PREFIX}${this.functionName()}(${argStrings.join(', ')})`;
const argStrings = this.arguments.map((arg) => arg.stringify());
return `${this.functionName()}(${argStrings.join(', ')})`;
}

@@ -78,0 +63,0 @@ static trimPrefix(expression) {

@@ -36,3 +36,3 @@ "use strict";

const parsers_1 = require("./parsers");
const ArrayExpressionParser_1 = require("./parsers/ArrayExpressionParser");
const FallbackExpressionParser_1 = require("./parsers/FallbackExpressionParser");
class TokenExpressionParser {

@@ -52,3 +52,4 @@ static get() {

}
throw new Error(`No parser found for node type '${nodeType}'`);
console.error(`No parser found for node type '${nodeType}'`);
return new FallbackExpressionParser_1.FallbackExpressionParser();
});

@@ -58,3 +59,3 @@ this.cache = new lru_cache_1.default({ max: 1000 });

this.parserFactories = [];
this.registerParserFactory(new ArrayExpressionParser_1.ArrayExpressionParserFactory());
this.registerParserFactory(new parsers_1.ArrayExpressionParserFactory());
this.registerParserFactory(new parsers_1.BlockStatementParserFactory());

@@ -65,2 +66,3 @@ this.registerParserFactory(new parsers_1.CallExpressionParserFactory());

this.registerParserFactory(new parsers_1.ExpressionNodeParserFactory());
this.registerParserFactory(new parsers_1.LogicalExpressionParserFactory());
this.registerParserFactory(new parsers_1.LiteralExpressionParserFactory());

@@ -67,0 +69,0 @@ this.registerParserFactory(new parsers_1.MemberExpressionParserFactory());

{
"name": "@journeyapps/evaluator",
"version": "0.0.0-dev.7b2d7c4",
"version": "0.0.0-dev.7ca4865",
"description": "Journey Evaluator library",

@@ -15,3 +15,3 @@ "main": "./dist/index.js",

"lodash": "^4.17.21",
"@journeyapps/core-xml": "0.0.0-dev.7b2d7c4"
"@journeyapps/core-xml": "0.0.0-dev.7ca4865"
},

@@ -18,0 +18,0 @@ "devDependencies": {

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

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

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