@journeyapps/evaluator
Advanced tools
Comparing version 7.0.0 to 7.0.1
import { MemberExpression } from '@babel/types'; | ||
import { FormatShorthandTokenExpression, FunctionTokenExpression, ShorthandTokenExpression } from '../token-expressions'; | ||
import { FormatShorthandTokenExpression, FunctionTokenExpression, ShorthandTokenExpression, ShorthandTokenExpressionOptions, TokenExpression } from '../token-expressions'; | ||
import { AbstractExpressionParser, ExpressionParserFactory, ExpressionNodeParseEvent } from './AbstractExpressionParser'; | ||
export type MemberExpressionParsedType = FunctionTokenExpression | ShorthandTokenExpression | FormatShorthandTokenExpression; | ||
/** | ||
* Parses member expressions like: | ||
* | ||
* object.property1 | ||
* object[param].property2 | ||
* object['property1'].property2 | ||
*/ | ||
export declare class MemberExpressionParser extends AbstractExpressionParser<MemberExpression, MemberExpressionParsedType> { | ||
parse(event: ExpressionNodeParseEvent<MemberExpression>): FunctionTokenExpression<{ | ||
expression: string; | ||
}> | ShorthandTokenExpression<{ | ||
expression: string; | ||
}>; | ||
parse(event: ExpressionNodeParseEvent<MemberExpression>): ShorthandTokenExpression<ShorthandTokenExpressionOptions> | FunctionTokenExpression<ShorthandTokenExpressionOptions>; | ||
static parseMember(event: ExpressionNodeParseEvent<MemberExpression>, properties?: TokenExpression[]): { | ||
objectName: string; | ||
properties: TokenExpression[]; | ||
}; | ||
} | ||
@@ -12,0 +19,0 @@ export declare class MemberExpressionParserFactory extends ExpressionParserFactory<MemberExpressionParser> { |
@@ -7,2 +7,7 @@ import { TokenExpression, TokenExpressionOptions } from '../TokenExpression'; | ||
arguments?: TokenExpression[]; | ||
/** | ||
* Used for non-call expressions to store properties. | ||
* Example: `$:object.property` or `$:view.user['name']` | ||
*/ | ||
properties?: TokenExpression[]; | ||
} | ||
@@ -9,0 +14,0 @@ export declare class FunctionTokenExpression<T extends FunctionTokenExpressionOptions = FunctionTokenExpressionOptions> extends TokenExpression<T> { |
/** | ||
* Shorthand token expression with format specifier. | ||
*/ | ||
import { ShorthandTokenExpression } from './ShorthandTokenExpression'; | ||
import { TokenExpressionOptions } from '../TokenExpression'; | ||
export interface FormatShorthandTokenExpressionOptions extends TokenExpressionOptions { | ||
import { ShorthandTokenExpression, ShorthandTokenExpressionOptions } from './ShorthandTokenExpression'; | ||
export interface FormatShorthandTokenExpressionOptions extends ShorthandTokenExpressionOptions { | ||
format: string; | ||
@@ -8,0 +7,0 @@ } |
@@ -6,4 +6,16 @@ import { FormatStringScope } from '../../definitions/FormatStringScope'; | ||
* Shorthand token expression. | ||
* | ||
* <var name="my_user" type="user"> | ||
* | ||
* <info value="{my_user.name}" /> | ||
* | ||
* Above is a shorthand for | ||
* | ||
* <info value="{$:view.my_user.name}" /> | ||
*/ | ||
export declare class ShorthandTokenExpression<O extends TokenExpressionOptions = TokenExpressionOptions> extends TokenExpression<O> { | ||
export interface ShorthandTokenExpressionOptions extends TokenExpressionOptions { | ||
name?: string; | ||
properties?: TokenExpression[]; | ||
} | ||
export declare class ShorthandTokenExpression<O extends ShorthandTokenExpressionOptions = ShorthandTokenExpressionOptions> extends TokenExpression<O> { | ||
static TYPE: string; | ||
@@ -10,0 +22,0 @@ constructor(options: O); |
@@ -13,2 +13,3 @@ import { FormatStringScope } from '../definitions/FormatStringScope'; | ||
isFunction?: boolean; | ||
isComputed?: boolean; | ||
} | ||
@@ -15,0 +16,0 @@ export declare abstract class TokenExpression<O extends TokenExpressionOptions = TokenExpressionOptions, V extends any = any> { |
@@ -6,2 +6,3 @@ "use strict"; | ||
const FormatStringContext_1 = require("../context/FormatStringContext"); | ||
const FunctionExpressionContext_1 = require("../context/FunctionExpressionContext"); | ||
const token_expressions_1 = require("../token-expressions"); | ||
@@ -26,3 +27,3 @@ const AbstractExpressionParser_1 = require("./AbstractExpressionParser"); | ||
child.extra = Object.assign(Object.assign({}, child.extra), { parent: node }); | ||
return parseNode(Object.assign(Object.assign({}, event), { node: child })); | ||
return parseNode(Object.assign(Object.assign({}, event), { node: child, context: new FunctionExpressionContext_1.FunctionExpressionContext() })); | ||
} | ||
@@ -29,0 +30,0 @@ // Example `{item.price}` |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.MemberExpressionParserFactory = exports.MemberExpressionParser = void 0; | ||
const types_1 = require("@babel/types"); | ||
const FunctionExpressionContext_1 = require("../context/FunctionExpressionContext"); | ||
const token_expressions_1 = require("../token-expressions"); | ||
const AbstractExpressionParser_1 = require("./AbstractExpressionParser"); | ||
/** | ||
* Parses member expressions like: | ||
* | ||
* object.property1 | ||
* object[param].property2 | ||
* object['property1'].property2 | ||
*/ | ||
class MemberExpressionParser extends AbstractExpressionParser_1.AbstractExpressionParser { | ||
@@ -12,10 +20,39 @@ parse(event) { | ||
const expr = source.slice(node.start, node.end); | ||
const { objectName, properties } = MemberExpressionParser.parseMember(event); | ||
const options = { | ||
expression: expr, | ||
name: objectName, | ||
properties: properties | ||
}; | ||
if (FunctionExpressionContext_1.FunctionExpressionContext.isInstanceOf(context)) { | ||
return new token_expressions_1.FunctionTokenExpression({ expression: expr }); | ||
return new token_expressions_1.FunctionTokenExpression(options); | ||
} | ||
const format = (_a = node.extra) === null || _a === void 0 ? void 0 : _a.format; | ||
return format != null | ||
? new token_expressions_1.FormatShorthandTokenExpression({ expression: expr, format: format }) | ||
: new token_expressions_1.ShorthandTokenExpression({ expression: expr }); | ||
return format == null | ||
? new token_expressions_1.ShorthandTokenExpression(options) | ||
: new token_expressions_1.FormatShorthandTokenExpression(Object.assign(Object.assign({}, options), { format: format })); | ||
} | ||
static parseMember(event, properties = []) { | ||
const { node, source, parseNode } = event; | ||
if ((0, types_1.isIdentifier)(node.object)) { | ||
const propertyExpr = parseNode({ | ||
node: node.property, | ||
source: source.slice(node.property.start, node.property.end) | ||
}); | ||
propertyExpr.options.isComputed = node.computed; | ||
properties.push(propertyExpr); | ||
return { | ||
objectName: node.object.name, | ||
properties: properties | ||
}; | ||
} | ||
const result = MemberExpressionParser.parseMember(Object.assign(Object.assign({}, event), { node: node.object }), properties); | ||
const propertyExpr = parseNode({ | ||
node: node.property, | ||
source: source.slice(node.property.start, node.property.end) | ||
}); | ||
propertyExpr.options.isComputed = node.computed; | ||
result.properties.push(propertyExpr); | ||
return result; | ||
} | ||
} | ||
@@ -22,0 +59,0 @@ exports.MemberExpressionParser = MemberExpressionParser; |
@@ -53,7 +53,7 @@ "use strict"; | ||
stringify() { | ||
if (!this.isCallExpression()) { | ||
return this.expression; | ||
if (this.isCallExpression()) { | ||
const argStrings = this.arguments.map((arg) => arg.stringify()); | ||
return `${this.functionName()}(${argStrings.join(', ')})`; | ||
} | ||
const argStrings = this.arguments.map((arg) => arg.stringify()); | ||
return `${this.functionName()}(${argStrings.join(', ')})`; | ||
return this.expression; | ||
} | ||
@@ -60,0 +60,0 @@ clone() { |
@@ -6,8 +6,6 @@ "use strict"; | ||
const TokenExpression_1 = require("../TokenExpression"); | ||
/** | ||
* Shorthand token expression. | ||
*/ | ||
class ShorthandTokenExpression extends TokenExpression_1.TokenExpression { | ||
constructor(options) { | ||
super(ShorthandTokenExpression.TYPE, Object.assign(Object.assign({}, options), { isShorthand: true })); | ||
var _a; | ||
super(ShorthandTokenExpression.TYPE, Object.assign(Object.assign({}, options), { isShorthand: true, name: (_a = options.name) !== null && _a !== void 0 ? _a : options.expression })); | ||
} | ||
@@ -14,0 +12,0 @@ async tokenEvaluatePromise(scope) { |
@@ -10,3 +10,3 @@ "use strict"; | ||
this.type = type; | ||
this.options = Object.assign({ isPrimitive: false, isConstant: false, isShorthand: false, isFunction: false }, options); | ||
this.options = Object.assign({ isPrimitive: false, isConstant: false, isShorthand: false, isFunction: false, isComputed: false }, options); | ||
this.expression = this.options.expression; | ||
@@ -13,0 +13,0 @@ this.isPrimitive = this.options.isPrimitive; |
{ | ||
"name": "@journeyapps/evaluator", | ||
"version": "7.0.0", | ||
"version": "7.0.1", | ||
"description": "Journey Evaluator library", | ||
@@ -5,0 +5,0 @@ "main": "./dist/index.js", |
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
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
285837
2331
0