@journeyapps/evaluator
Advanced tools
Comparing version 0.0.0-dev.cad60fd to 0.0.0-dev.cc719a7
@@ -5,4 +5,2 @@ import { AttributeValidationError } from '@journeyapps/core-xml'; | ||
import { TokenExpression } from './token-expressions'; | ||
import { SourceTransformer } from './transformers'; | ||
export declare const DEFAULT_FORMAT_STRING_TRANSFORMERS: (typeof SourceTransformer)[]; | ||
export interface FormatStringOptions { | ||
@@ -21,2 +19,3 @@ expression: string; | ||
constructor(options: FormatStringOptions); | ||
static fromTokens(tokens: TokenExpression[]): FormatString; | ||
/** | ||
@@ -48,4 +47,8 @@ * Compile a format string expression into tokens. | ||
}; | ||
/** | ||
* Removes one set of curly braces from the string. | ||
* Example {{foo}} -> {foo} | ||
*/ | ||
static unescape(s: string): string; | ||
} | ||
export declare const parseEnclosingBraces: typeof FormatString.parseEnclosingBraces; |
export * from './parsers'; | ||
export * from './TokenExpressionParser'; | ||
export * from './context/ParseContext'; | ||
export * from './context/FormatStringContext'; | ||
export * from './context/FunctionExpressionContext'; | ||
export * from './FormatString'; | ||
@@ -7,4 +10,5 @@ export * from './token-expressions'; | ||
export * from './definitions/ObjectRefInterface'; | ||
export * from './definitions/VariableScope'; | ||
export * from './definitions/VariableFormatStringScope'; | ||
export * from './definitions/FormatStringScope'; | ||
export * from './scope/VariableFormatStringScope'; | ||
export * from './tools'; |
import { Node, Aliases } from '@babel/types'; | ||
import { TokenExpression } from '../token-expressions'; | ||
import { ParseNodeEvent } from '../TokenExpressionParser'; | ||
export type NodeType = Node['type'] | keyof Aliases; | ||
export interface ExpressionNodeEvent<N extends Node = Node> { | ||
source: string; | ||
node: N; | ||
parseNode(node: Node, source: string): TokenExpression | null; | ||
export interface ExpressionNodeParseEvent<N extends Node = Node> extends ParseNodeEvent<N> { | ||
parseNode(event: ParseNodeEvent): TokenExpression | null; | ||
} | ||
export interface AbstractExpressionParserOptions { | ||
} | ||
export declare abstract class AbstractExpressionParser<N extends Node = Node, T extends TokenExpression = TokenExpression, O extends AbstractExpressionParserOptions = AbstractExpressionParserOptions, E extends ExpressionNodeEvent<N> = ExpressionNodeEvent<N>> { | ||
options: O; | ||
constructor(options?: O); | ||
export declare abstract class AbstractExpressionParser<N extends Node = Node, T extends TokenExpression = TokenExpression, E extends ExpressionNodeParseEvent<N> = ExpressionNodeParseEvent<N>> { | ||
abstract parse(event: E): T; | ||
@@ -15,0 +10,0 @@ } |
@@ -1,6 +0,8 @@ | ||
import { BlockStatement, Statement } from '@babel/types'; | ||
import { AbstractExpressionParser, ExpressionParserFactory, ExpressionNodeEvent } from './AbstractExpressionParser'; | ||
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: ExpressionNodeEvent<BlockStatement>): import("../token-expressions").TokenExpression<import("../token-expressions").TokenExpressionOptions, any>; | ||
getFormatSpecifier(stm: Statement | null): string; | ||
parse(event: ExpressionNodeParseEvent<BlockStatement>): import("../token-expressions").TokenExpression<import("../token-expressions").TokenExpressionOptions, any> | ConstantTokenExpression<{ | ||
expression: string; | ||
}>; | ||
} | ||
@@ -7,0 +9,0 @@ export declare class BlockStatementParserFactory extends ExpressionParserFactory<BlockStatementParser> { |
import { CallExpression } from '@babel/types'; | ||
import { FunctionTokenExpression } from '../token-expressions'; | ||
import { AbstractExpressionParser, ExpressionParserFactory, ExpressionNodeEvent } from './AbstractExpressionParser'; | ||
import { AbstractExpressionParser, ExpressionParserFactory, ExpressionNodeParseEvent } from './AbstractExpressionParser'; | ||
export declare class CallExpressionParser extends AbstractExpressionParser<CallExpression, FunctionTokenExpression> { | ||
parse(event: ExpressionNodeEvent<CallExpression>): FunctionTokenExpression; | ||
parse(event: ExpressionNodeParseEvent<CallExpression>): FunctionTokenExpression<{ | ||
expression: string; | ||
name: string; | ||
arguments: import("../token-expressions").TokenExpression<import("../token-expressions").TokenExpressionOptions, any>[]; | ||
}>; | ||
} | ||
@@ -7,0 +11,0 @@ export declare class CallExpressionParserFactory extends ExpressionParserFactory<CallExpressionParser> { |
import { ConditionalExpression } from '@babel/types'; | ||
import { FunctionTokenExpression } from '../token-expressions'; | ||
import { AbstractExpressionParser, ExpressionParserFactory, ExpressionNodeEvent } from './AbstractExpressionParser'; | ||
import { AbstractExpressionParser, ExpressionParserFactory, ExpressionNodeParseEvent } from './AbstractExpressionParser'; | ||
export declare class ConditionalExpressionParser extends AbstractExpressionParser<ConditionalExpression, FunctionTokenExpression> { | ||
parse(event: ExpressionNodeEvent<ConditionalExpression>): FunctionTokenExpression; | ||
parse(event: ExpressionNodeParseEvent<ConditionalExpression>): FunctionTokenExpression; | ||
} | ||
@@ -7,0 +7,0 @@ export declare class ConditionalExpressionParserFactory extends ExpressionParserFactory<ConditionalExpressionParser> { |
import { Directive, ExpressionStatement, LabeledStatement } from '@babel/types'; | ||
import { AbstractExpressionParser, ExpressionParserFactory, ExpressionNodeEvent } from './AbstractExpressionParser'; | ||
import { AbstractExpressionParser, ExpressionParserFactory, ExpressionNodeParseEvent } from './AbstractExpressionParser'; | ||
export type ExpressionType = ExpressionStatement | Directive | LabeledStatement; | ||
export declare class ExpressionNodeParser extends AbstractExpressionParser<ExpressionType> { | ||
parse(event: ExpressionNodeEvent<ExpressionType>): import("..").TokenExpression<import("..").TokenExpressionOptions, any>; | ||
parse(event: ExpressionNodeParseEvent<ExpressionType>): import("..").TokenExpression<import("..").TokenExpressionOptions, any>; | ||
} | ||
@@ -7,0 +7,0 @@ export declare class ExpressionNodeParserFactory extends ExpressionParserFactory<ExpressionNodeParser> { |
import { Identifier } from '@babel/types'; | ||
import { FormatShorthandTokenExpression, FunctionTokenExpression, ShorthandTokenExpression } from '../token-expressions'; | ||
import { AbstractExpressionParser, ExpressionParserFactory, ExpressionNodeEvent } from './AbstractExpressionParser'; | ||
export type IdentifierExpressionParsedType = FunctionTokenExpression | ShorthandTokenExpression | FormatShorthandTokenExpression; | ||
export declare class IdentifierExpressionParser extends AbstractExpressionParser<Identifier, IdentifierExpressionParsedType> { | ||
parse(event: ExpressionNodeEvent<Identifier>): FunctionTokenExpression | ShorthandTokenExpression<{ | ||
import { AbstractExpressionParser, ExpressionParserFactory, ExpressionNodeParseEvent } from './AbstractExpressionParser'; | ||
export type ParsedIdentifierExpressionType = FunctionTokenExpression | ShorthandTokenExpression | FormatShorthandTokenExpression; | ||
export declare class IdentifierExpressionParser extends AbstractExpressionParser<Identifier, ParsedIdentifierExpressionType> { | ||
parse(event: ExpressionNodeParseEvent<Identifier>): FunctionTokenExpression<{ | ||
expression: string; | ||
}> | ShorthandTokenExpression<{ | ||
expression: string; | ||
}>; | ||
@@ -9,0 +11,0 @@ } |
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'; |
import { DirectiveLiteral, Literal } from '@babel/types'; | ||
import { ConstantTokenExpression } from '../token-expressions'; | ||
import { AbstractExpressionParser, ExpressionParserFactory, ExpressionNodeEvent } from './AbstractExpressionParser'; | ||
import { ConstantTokenExpression, FunctionTokenExpression, PrimitiveConstantTokenExpression } from '../token-expressions'; | ||
import { AbstractExpressionParser, ExpressionParserFactory, ExpressionNodeParseEvent } from './AbstractExpressionParser'; | ||
export type LiteralExpression = Literal | DirectiveLiteral; | ||
export declare class LiteralExpressionParser extends AbstractExpressionParser<LiteralExpression, ConstantTokenExpression> { | ||
parse(event: ExpressionNodeEvent<LiteralExpression>): ConstantTokenExpression; | ||
export type ParsedLiteralExpressionType = ConstantTokenExpression | FunctionTokenExpression | PrimitiveConstantTokenExpression; | ||
export declare class LiteralExpressionParser extends AbstractExpressionParser<LiteralExpression, ParsedLiteralExpressionType> { | ||
parse(event: ExpressionNodeParseEvent<LiteralExpression>): PrimitiveConstantTokenExpression | FunctionTokenExpression<{ | ||
expression: string; | ||
}> | ConstantTokenExpression<{ | ||
expression: string; | ||
}>; | ||
} | ||
@@ -8,0 +13,0 @@ export declare class LiteralExpressionParserFactory extends ExpressionParserFactory<LiteralExpressionParser> { |
import { MemberExpression } from '@babel/types'; | ||
import { FormatShorthandTokenExpression, FunctionTokenExpression, ShorthandTokenExpression } from '../token-expressions'; | ||
import { AbstractExpressionParser, ExpressionParserFactory, ExpressionNodeEvent } from './AbstractExpressionParser'; | ||
import { AbstractExpressionParser, ExpressionParserFactory, ExpressionNodeParseEvent } from './AbstractExpressionParser'; | ||
export type MemberExpressionParsedType = FunctionTokenExpression | ShorthandTokenExpression | FormatShorthandTokenExpression; | ||
export declare class MemberExpressionParser extends AbstractExpressionParser<MemberExpression, MemberExpressionParsedType> { | ||
parse(event: ExpressionNodeEvent<MemberExpression>): FunctionTokenExpression | ShorthandTokenExpression<{ | ||
parse(event: ExpressionNodeParseEvent<MemberExpression>): FunctionTokenExpression<{ | ||
expression: string; | ||
}> | ShorthandTokenExpression<{ | ||
expression: string; | ||
}>; | ||
@@ -9,0 +11,0 @@ } |
import { ObjectExpression } from '@babel/types'; | ||
import { ObjectTokenExpression } from '../token-expressions'; | ||
import { AbstractExpressionParser, ExpressionNodeEvent, ExpressionParserFactory } from './AbstractExpressionParser'; | ||
import { AbstractExpressionParser, ExpressionNodeParseEvent, ExpressionParserFactory } from './AbstractExpressionParser'; | ||
export declare class ObjectExpressionParser extends AbstractExpressionParser<ObjectExpression, ObjectTokenExpression> { | ||
parse(event: ExpressionNodeEvent<ObjectExpression>): ObjectTokenExpression; | ||
parse(event: ExpressionNodeParseEvent<ObjectExpression>): ObjectTokenExpression; | ||
} | ||
@@ -7,0 +7,0 @@ export declare class ObjectExpressionParserFactory extends ExpressionParserFactory<ObjectExpressionParser> { |
@@ -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); | ||
/** | ||
@@ -15,2 +15,3 @@ * Concatenate a token to current token and return a new token. | ||
concat(token: ConstantTokenExpression): ConstantTokenExpression; | ||
tokenEvaluatePromise(scope: FormatStringScope): Promise<string>; | ||
/** | ||
@@ -20,3 +21,4 @@ * Get the value of the constant token expression. | ||
valueOf(): string; | ||
tokenEvaluatePromise(scope: FormatStringScope): Promise<string>; | ||
stringify(): string; | ||
clone(): this; | ||
} |
@@ -8,7 +8,9 @@ /** | ||
expression: any; | ||
isNullLiteral?: boolean; | ||
} | ||
export declare class PrimitiveConstantTokenExpression extends ConstantTokenExpression { | ||
static TYPE: string; | ||
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; | ||
/** | ||
@@ -18,2 +20,4 @@ * Concatenate a token to current token and return a new token. | ||
concat(token: ConstantTokenExpression): ConstantTokenExpression; | ||
stringify(): string; | ||
clone(): this; | ||
} |
@@ -8,3 +8,3 @@ import { TokenExpression, TokenExpressionOptions } from '../TokenExpression'; | ||
} | ||
export declare class FunctionTokenExpression extends TokenExpression<FunctionTokenExpressionOptions> { | ||
export declare class FunctionTokenExpression<T extends FunctionTokenExpressionOptions = FunctionTokenExpressionOptions> extends TokenExpression<T> { | ||
static TYPE: string; | ||
@@ -16,6 +16,9 @@ static isInstanceOf(obj: any): obj is FunctionTokenExpression; | ||
static PREFIX: string; | ||
static parse(source: string): FunctionTokenExpression; | ||
constructor(options: FunctionTokenExpressionOptions); | ||
get arguments(): TokenExpression<TokenExpressionOptions, any>[]; | ||
static parse(source: string): FunctionTokenExpression<FunctionTokenExpressionOptions>; | ||
constructor(options: T); | ||
get arguments(): TokenExpression[] | null; | ||
functionName(): string; | ||
setFunctionName(name: string): void; | ||
isCallExpression(): boolean; | ||
tokenEvaluatePromise(scope: FormatStringScope): Promise<any>; | ||
/** | ||
@@ -26,4 +29,6 @@ * Generate a constant token expression from function token expression. | ||
toConstant(includeEscapeTags?: boolean): ConstantTokenExpression; | ||
tokenEvaluatePromise(scope: FormatStringScope): Promise<any>; | ||
stringify(): string; | ||
clone(): this; | ||
static trimPrefix(expression: string): string; | ||
static hasPrefix(expression: string): boolean; | ||
} |
@@ -8,3 +8,3 @@ /** | ||
export declare class LegacyFunctionTokenExpression extends TokenExpression { | ||
static TYPE: string; | ||
static readonly TYPE = "legacy-function-expression"; | ||
constructor(options: TokenExpressionOptions); | ||
@@ -17,2 +17,3 @@ /** | ||
tokenEvaluatePromise(scope: FormatStringScope): Promise<string>; | ||
clone(): this; | ||
} |
export * from './TokenExpression'; | ||
export * from './ObjectTokenExpression'; | ||
export * from './object/ObjectTokenExpression'; | ||
export * from './object/ArrayTokenExpression'; | ||
export * from './shorthand/ShorthandTokenExpression'; | ||
@@ -8,2 +9,3 @@ export * from './shorthand/FormatShorthandTokenExpression'; | ||
export * from './function/FunctionTokenExpression'; | ||
export * from './function/TernaryFunctionTokenExpression'; | ||
export * from './function/LegacyFunctionTokenExpression'; |
@@ -13,5 +13,6 @@ /** | ||
export declare class FormatShorthandTokenExpression extends ShorthandTokenExpression<FormatShorthandTokenExpressionOptions> { | ||
static TYPE: string; | ||
static readonly TYPE = "format-shorthand-expression"; | ||
constructor(options: FormatShorthandTokenExpressionOptions); | ||
stringify(): string; | ||
toString(): string; | ||
} |
@@ -11,3 +11,4 @@ import { FormatStringScope } from '../../definitions/FormatStringScope'; | ||
tokenEvaluatePromise(scope: FormatStringScope): Promise<string>; | ||
clone(): this; | ||
} | ||
export declare function formatValueAsync(value: any, type: TypeInterface, format: string): Promise<string>; |
@@ -21,2 +21,3 @@ import { FormatStringScope } from '../definitions/FormatStringScope'; | ||
abstract tokenEvaluatePromise(scope: FormatStringScope): Promise<V>; | ||
abstract clone(): this; | ||
get start(): number | null; | ||
@@ -23,0 +24,0 @@ set start(start: number); |
/// <reference types="lodash" /> | ||
import { Node } from '@babel/types'; | ||
import LRUCache from 'lru-cache'; | ||
import { ParseContext, ParseContextFactory } from './context/ParseContext'; | ||
import { AbstractExpressionParser, ExpressionParserFactory, NodeType } from './parsers'; | ||
import { TokenExpression } from './token-expressions'; | ||
import { SourceTransformer } from './transformers'; | ||
export interface TokenExpressionParseEvent { | ||
source: string; | ||
transformers?: (typeof SourceTransformer)[]; | ||
context?: ParseContext; | ||
} | ||
export interface ParseNodeEvent<N extends Node = Node> extends TokenExpressionParseEvent { | ||
node: N; | ||
} | ||
export declare class TokenExpressionParser { | ||
cache: LRUCache<string, TokenExpression>; | ||
factories: ExpressionParserFactory[]; | ||
transformers: Record<string, SourceTransformer>; | ||
parserFactories: ExpressionParserFactory[]; | ||
contextFactories: ParseContextFactory[]; | ||
static instance: TokenExpressionParser; | ||
@@ -19,7 +22,8 @@ static get(): TokenExpressionParser; | ||
parse<T extends TokenExpression = TokenExpression>(event: TokenExpressionParseEvent): T | null; | ||
parseNode(node: Node, source: string): TokenExpression | null; | ||
registerFactory(factory: ExpressionParserFactory): void; | ||
registerTransformer(transformer: SourceTransformer): void; | ||
parseNode(event: ParseNodeEvent): TokenExpression | null; | ||
registerParserFactory(factory: ExpressionParserFactory): void; | ||
registerContextFactory(factory: ParseContextFactory): void; | ||
transformSource(event: TokenExpressionParseEvent): string; | ||
getParser: ((nodeType: NodeType) => AbstractExpressionParser) & import("lodash").MemoizedFunction; | ||
transformSource(event: TokenExpressionParseEvent): string; | ||
inferContext(source: string): ParseContext | null; | ||
} |
@@ -11,3 +11,3 @@ import { TypeInterface } from './definitions/TypeInterface'; | ||
*/ | ||
export declare function functionTokenExpression(expression: string, allowLegacy?: boolean): FunctionTokenExpression | LegacyFunctionTokenExpression; | ||
export declare function functionTokenExpression(expression: string, allowLegacy?: boolean): FunctionTokenExpression<import("./token-expressions").FunctionTokenExpressionOptions> | LegacyFunctionTokenExpression; | ||
/** | ||
@@ -14,0 +14,0 @@ * Create a token expression that can be evaluated. |
@@ -1,2 +0,2 @@ | ||
import { SourceTransformer, TransformSourceEvent } from './SourceTransformer'; | ||
import { SourceTransformer } from './SourceTransformer'; | ||
/** | ||
@@ -8,3 +8,3 @@ * Wraps source code in a block statement if it is not already | ||
constructor(); | ||
transform(event: TransformSourceEvent): string; | ||
transform(source: string): string; | ||
} |
@@ -1,4 +0,4 @@ | ||
import { SourceTransformer, TransformSourceEvent } from './SourceTransformer'; | ||
import { SourceTransformer } from './SourceTransformer'; | ||
/** Transforms format specifiers in source code; | ||
* value:0n -> {value; $format = "0n"} | ||
* value:0n -> value; $format = "0n" | ||
*/ | ||
@@ -9,3 +9,3 @@ export declare class FormatSpecifierTransformer extends SourceTransformer { | ||
constructor(); | ||
transform(event: TransformSourceEvent): string; | ||
transform(source: string): string; | ||
} |
@@ -1,9 +0,5 @@ | ||
export interface TransformSourceEvent { | ||
source: string; | ||
} | ||
export declare abstract class SourceTransformer { | ||
static TYPE: string; | ||
readonly type: string; | ||
constructor(type: string); | ||
abstract transform(event: TransformSourceEvent): string; | ||
abstract transform(source: string): string; | ||
} |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.parseEnclosingBraces = exports.FormatString = exports.DEFAULT_FORMAT_STRING_TRANSFORMERS = void 0; | ||
exports.parseEnclosingBraces = exports.FormatString = void 0; | ||
const FormatStringContext_1 = require("./context/FormatStringContext"); | ||
const FunctionExpressionContext_1 = require("./context/FunctionExpressionContext"); | ||
const token_expressions_1 = require("./token-expressions"); | ||
const TokenExpressionParser_1 = require("./TokenExpressionParser"); | ||
const tools_1 = require("./tools"); | ||
const transformers_1 = require("./transformers"); | ||
exports.DEFAULT_FORMAT_STRING_TRANSFORMERS = [ | ||
transformers_1.FormatSpecifierTransformer, | ||
transformers_1.BlockStatementTransformer | ||
]; | ||
/** | ||
@@ -24,2 +21,25 @@ * Construct a new format string expression. | ||
} | ||
static fromTokens(tokens) { | ||
const result = new FormatString({ expression: '' }); | ||
result.tokens = []; | ||
let start = 0; | ||
tokens.forEach((token) => { | ||
token.start = start; | ||
if (token.isConstant() && !token.isPrimitive) { | ||
result.expression += token.expression; | ||
start += token.expression.length; | ||
} | ||
else { | ||
let exp = '{'; | ||
if (token_expressions_1.FunctionTokenExpression.isInstanceOf(token)) { | ||
exp += token_expressions_1.FunctionTokenExpression.PREFIX; | ||
} | ||
exp += `${token.stringify()}}`; | ||
result.expression += exp; | ||
start += exp.length; | ||
} | ||
result.tokens.push(token); | ||
}); | ||
return result; | ||
} | ||
/** | ||
@@ -44,5 +64,5 @@ * Compile a format string expression into tokens. | ||
// normal text in the gaps between curly braces | ||
const text = FormatString.unescape(expression.substring(start, i)); | ||
if (text.length > 0) { | ||
tokens.push(new token_expressions_1.ConstantTokenExpression({ expression: text, start })); | ||
const betweenText = FormatString.unescape(expression.substring(start, i)); | ||
if (betweenText.length > 0) { | ||
tokens.push(new token_expressions_1.ConstantTokenExpression({ expression: betweenText, start })); | ||
} | ||
@@ -64,7 +84,10 @@ if (expression[i + 1] == '{') { | ||
// `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, transformers: exports.DEFAULT_FORMAT_STRING_TRANSFORMERS }); | ||
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) { | ||
@@ -80,3 +103,3 @@ parsedToken.start = i; | ||
const token = tokens[j]; | ||
if (token instanceof token_expressions_1.ConstantTokenExpression) { | ||
if (token_expressions_1.ConstantTokenExpression.isInstanceOf(token) || token_expressions_1.PrimitiveConstantTokenExpression.isInstanceOf(token)) { | ||
if (last == null) { | ||
@@ -232,3 +255,3 @@ last = token; | ||
const token = tokens[i]; | ||
if (token.isConstant()) { | ||
if (token.isConstant() && !(token_expressions_1.PrimitiveConstantTokenExpression.isInstanceOf(token) && token.isNullLiteral())) { | ||
result += `${token.valueOf()}`; | ||
@@ -241,3 +264,3 @@ } | ||
else { | ||
let expression = token.expression; | ||
let expression = `${token.expression}`; | ||
if (expression.length > 0 && expression[0] == '?') { | ||
@@ -308,2 +331,6 @@ expression = expression.substring(1); | ||
} | ||
/** | ||
* Removes one set of curly braces from the string. | ||
* Example {{foo}} -> {foo} | ||
*/ | ||
static unescape(s) { | ||
@@ -310,0 +337,0 @@ let start = 0; |
@@ -19,2 +19,5 @@ "use strict"; | ||
__exportStar(require("./TokenExpressionParser"), exports); | ||
__exportStar(require("./context/ParseContext"), exports); | ||
__exportStar(require("./context/FormatStringContext"), exports); | ||
__exportStar(require("./context/FunctionExpressionContext"), exports); | ||
__exportStar(require("./FormatString"), exports); | ||
@@ -24,5 +27,6 @@ __exportStar(require("./token-expressions"), exports); | ||
__exportStar(require("./definitions/ObjectRefInterface"), exports); | ||
__exportStar(require("./definitions/VariableScope"), exports); | ||
__exportStar(require("./definitions/VariableFormatStringScope"), exports); | ||
__exportStar(require("./definitions/FormatStringScope"), exports); | ||
__exportStar(require("./scope/VariableFormatStringScope"), exports); | ||
__exportStar(require("./tools"), exports); | ||
//# sourceMappingURL=index.js.map |
@@ -6,5 +6,2 @@ "use strict"; | ||
class AbstractExpressionParser { | ||
constructor(options) { | ||
this.options = Object.assign({}, options); | ||
} | ||
} | ||
@@ -11,0 +8,0 @@ exports.AbstractExpressionParser = AbstractExpressionParser; |
@@ -5,2 +5,3 @@ "use strict"; | ||
const types_1 = require("@babel/types"); | ||
const FormatStringContext_1 = require("../context/FormatStringContext"); | ||
const token_expressions_1 = require("../token-expressions"); | ||
@@ -11,3 +12,3 @@ const AbstractExpressionParser_1 = require("./AbstractExpressionParser"); | ||
var _a; | ||
const { node, source, parseNode } = event; | ||
const { node, source, context, parseNode } = event; | ||
// If parent is also a BlockStatement means we have an escaped FormatString, e.g. {{value}} | ||
@@ -18,3 +19,2 @@ // and it will be handled by `ExpressionStatement` lower down | ||
} | ||
// TODO: FormatStatement extraction should be handled by a mutator | ||
const [body, formatStm] = node.body; | ||
@@ -24,24 +24,19 @@ if ((0, types_1.isBlockStatement)(body)) { | ||
} | ||
// Example `{$:foo()}` | ||
if ((0, types_1.isLabeledStatement)(body)) { | ||
// Example `{$:foo()}` | ||
const { body: child } = body; | ||
child.extra = Object.assign(Object.assign({}, child.extra), { parent: node }); | ||
return parseNode(child, source); | ||
return parseNode(Object.assign(Object.assign({}, event), { node: child })); | ||
} | ||
// Example `{item.price}` | ||
if ((0, types_1.isExpressionStatement)(body)) { | ||
const { expression: child } = body; | ||
child.extra = Object.assign(Object.assign({}, child.extra), { parent: node, format: this.getFormatSpecifier(formatStm) }); | ||
return parseNode(child, source); | ||
child.extra = Object.assign(Object.assign({}, child.extra), { parent: node }); | ||
// Example `{item.price; $format = ".2f"} | ||
if (FormatStringContext_1.FormatStringContext.isInstanceOf(context)) { | ||
child.extra.format = context.getFormatSpecifier(formatStm); | ||
} | ||
return parseNode(Object.assign(Object.assign({}, event), { node: child })); | ||
} | ||
} | ||
getFormatSpecifier(stm) { | ||
if (!(0, types_1.isExpressionStatement)(stm)) { | ||
return; | ||
} | ||
const { expression } = stm; | ||
if (!(0, types_1.isAssignmentExpression)(expression)) { | ||
return; | ||
} | ||
return (0, types_1.isStringLiteral)(expression.right) ? expression.right.value : null; | ||
} | ||
} | ||
@@ -48,0 +43,0 @@ exports.BlockStatementParser = BlockStatementParser; |
@@ -10,4 +10,8 @@ "use strict"; | ||
const name = source.slice(node.callee.start, node.callee.end); | ||
const args = node.arguments.map((arg) => parseNode(arg, source)); | ||
return new token_expressions_1.FunctionTokenExpression({ expression: source.slice(node.start, node.end), name: name, arguments: args }); | ||
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 | ||
}); | ||
} | ||
@@ -14,0 +18,0 @@ } |
@@ -10,10 +10,7 @@ "use strict"; | ||
const { test, consequent, alternate } = node; | ||
const args = [test, consequent, alternate].map((arg) => parseNode(arg, source)); | ||
const argStrings = [ | ||
source.slice(test.start, test.end), | ||
source.slice(consequent.start, consequent.end), | ||
source.slice(alternate.start, alternate.end) | ||
]; | ||
const expression = `(function(test, consequent, alternate) { return test ? consequent : alternate; })(${argStrings.join(', ')})`; | ||
return new token_expressions_1.FunctionTokenExpression({ expression: expression, arguments: args }); | ||
const args = [test, consequent, alternate].map((arg) => parseNode({ node: arg, source })); | ||
return new token_expressions_1.TernaryFunctionTokenExpression({ | ||
expression: source.slice(node.start, node.end), | ||
arguments: [args[0], args[1], args[2]] | ||
}); | ||
} | ||
@@ -20,0 +17,0 @@ } |
@@ -20,3 +20,3 @@ "use strict"; | ||
expression.extra = Object.assign(Object.assign({}, expression.extra), { parent: node }); | ||
return event.parseNode(expression, event.source); | ||
return event.parseNode(Object.assign(Object.assign({}, event), { node: expression })); | ||
} | ||
@@ -23,0 +23,0 @@ } |
@@ -5,9 +5,9 @@ "use strict"; | ||
const types_1 = require("@babel/types"); | ||
const FunctionExpressionContext_1 = require("../context/FunctionExpressionContext"); | ||
const token_expressions_1 = require("../token-expressions"); | ||
const AbstractExpressionParser_1 = require("./AbstractExpressionParser"); | ||
const utils_1 = require("./utils"); | ||
class IdentifierExpressionParser extends AbstractExpressionParser_1.AbstractExpressionParser { | ||
parse(event) { | ||
var _a, _b; | ||
const { node } = event; | ||
const { node, context } = event; | ||
if ((0, types_1.isLabeledStatement)((_a = node.extra) === null || _a === void 0 ? void 0 : _a.parent)) { | ||
@@ -17,9 +17,12 @@ return null; | ||
const { name: expression } = node; | ||
if ((0, utils_1.inFunctionExpression)(node)) { | ||
return new token_expressions_1.FunctionTokenExpression({ expression: expression }); | ||
if (FunctionExpressionContext_1.FunctionExpressionContext.isInstanceOf(context)) { | ||
return new token_expressions_1.FunctionTokenExpression({ | ||
expression: expression | ||
}); | ||
} | ||
const format = (_b = node.extra) === null || _b === void 0 ? void 0 : _b.format; | ||
return format != null | ||
? new token_expressions_1.FormatShorthandTokenExpression({ expression: expression, format: format }) | ||
: new token_expressions_1.ShorthandTokenExpression({ expression: expression }); | ||
if (format != null) { | ||
return new token_expressions_1.FormatShorthandTokenExpression({ expression: expression, format: format }); | ||
} | ||
return new token_expressions_1.ShorthandTokenExpression({ expression: expression }); | ||
} | ||
@@ -26,0 +29,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 |
@@ -5,2 +5,3 @@ "use strict"; | ||
const types_1 = require("@babel/types"); | ||
const FunctionExpressionContext_1 = require("../context/FunctionExpressionContext"); | ||
const token_expressions_1 = require("../token-expressions"); | ||
@@ -10,7 +11,20 @@ const AbstractExpressionParser_1 = require("./AbstractExpressionParser"); | ||
parse(event) { | ||
const { node } = event; | ||
const { node, context } = event; | ||
const inFunctionContext = FunctionExpressionContext_1.FunctionExpressionContext.isInstanceOf(context); | ||
if ((0, types_1.isStringLiteral)(node) || (0, types_1.isDirectiveLiteral)(node)) { | ||
if (inFunctionContext) { | ||
return new token_expressions_1.FunctionTokenExpression({ expression: `'${node.value}'` }); | ||
} | ||
return new token_expressions_1.ConstantTokenExpression({ expression: node.value }); | ||
} | ||
else if ('value' in node) { | ||
if ((0, types_1.isNullLiteral)(node)) { | ||
if (inFunctionContext) { | ||
return new token_expressions_1.FunctionTokenExpression({ 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}` }); | ||
} | ||
return new token_expressions_1.PrimitiveConstantTokenExpression({ expression: node.value }); | ||
@@ -17,0 +31,0 @@ } |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.MemberExpressionParserFactory = exports.MemberExpressionParser = void 0; | ||
const FunctionExpressionContext_1 = require("../context/FunctionExpressionContext"); | ||
const token_expressions_1 = require("../token-expressions"); | ||
const AbstractExpressionParser_1 = require("./AbstractExpressionParser"); | ||
const utils_1 = require("./utils"); | ||
class MemberExpressionParser extends AbstractExpressionParser_1.AbstractExpressionParser { | ||
parse(event) { | ||
var _a; | ||
const { node, source } = event; | ||
const { node, source, context } = event; | ||
const expr = source.slice(node.start, node.end); | ||
if ((0, utils_1.inFunctionExpression)(node)) { | ||
if (FunctionExpressionContext_1.FunctionExpressionContext.isInstanceOf(context)) { | ||
return new token_expressions_1.FunctionTokenExpression({ expression: expr }); | ||
@@ -14,0 +14,0 @@ } |
@@ -13,3 +13,3 @@ "use strict"; | ||
if ((0, types_1.isObjectProperty)(prop) && (0, types_1.isIdentifier)(prop.key)) { | ||
props[prop.key.name] = parseNode(prop.value, source); | ||
props[prop.key.name] = parseNode({ node: prop.value, source }); | ||
} | ||
@@ -16,0 +16,0 @@ } |
@@ -22,2 +22,5 @@ "use strict"; | ||
} | ||
async tokenEvaluatePromise(scope) { | ||
return this.expression; | ||
} | ||
/** | ||
@@ -29,5 +32,8 @@ * Get the value of the constant token expression. | ||
} | ||
async tokenEvaluatePromise(scope) { | ||
return this.expression; | ||
stringify() { | ||
return `'${this.expression}'`; | ||
} | ||
clone() { | ||
return new ConstantTokenExpression(this.options); | ||
} | ||
} | ||
@@ -34,0 +40,0 @@ exports.ConstantTokenExpression = ConstantTokenExpression; |
@@ -14,3 +14,8 @@ "use strict"; | ||
super(Object.assign(Object.assign({}, options), { isPrimitive: true })); | ||
this.type = PrimitiveConstantTokenExpression.TYPE; | ||
} | ||
isNullLiteral() { | ||
var _a; | ||
return (_a = this.options.isNullLiteral) !== null && _a !== void 0 ? _a : false; | ||
} | ||
/** | ||
@@ -26,2 +31,8 @@ * Concatenate a token to current token and return a new token. | ||
} | ||
stringify() { | ||
return `${this.expression}`; | ||
} | ||
clone() { | ||
return new PrimitiveConstantTokenExpression(this.options); | ||
} | ||
} | ||
@@ -28,0 +39,0 @@ exports.PrimitiveConstantTokenExpression = PrimitiveConstantTokenExpression; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.FunctionTokenExpression = void 0; | ||
const FunctionExpressionContext_1 = require("../../context/FunctionExpressionContext"); | ||
const TokenExpressionParser_1 = require("../../TokenExpressionParser"); | ||
@@ -12,15 +13,14 @@ const TokenExpression_1 = require("../TokenExpression"); | ||
static parse(source) { | ||
return TokenExpressionParser_1.TokenExpressionParser.get().parse({ source }); | ||
return TokenExpressionParser_1.TokenExpressionParser.get().parse({ | ||
source, | ||
context: new FunctionExpressionContext_1.FunctionExpressionContext() | ||
}); | ||
} | ||
constructor(options) { | ||
var _a, _b; | ||
super(FunctionTokenExpression.TYPE, Object.assign(Object.assign({}, options), { isFunction: true })); | ||
// remove indicator prefix from expression | ||
const prefix = FunctionTokenExpression.PREFIX; | ||
this.expression = this.expression.trim(); | ||
if (this.expression.indexOf(prefix) === 0) { | ||
this.expression = this.expression.slice(prefix.length); | ||
this.expression = FunctionTokenExpression.trimPrefix(this.expression); | ||
if (!this.options.name) { | ||
const startBracket = this.expression.indexOf('('); | ||
this.setFunctionName(this.expression.slice(0, startBracket > 0 ? startBracket : this.expression.length)); | ||
} | ||
this.options.name = (_a = this.options.name) !== null && _a !== void 0 ? _a : this.expression.slice(0, this.expression.indexOf('(')); | ||
this.options.arguments = (_b = this.options.arguments) !== null && _b !== void 0 ? _b : []; | ||
} | ||
@@ -33,2 +33,11 @@ get arguments() { | ||
} | ||
setFunctionName(name) { | ||
this.options.name = name; | ||
} | ||
isCallExpression() { | ||
return this.arguments != null; | ||
} | ||
async tokenEvaluatePromise(scope) { | ||
return scope.evaluateFunctionExpression(this.expression); | ||
} | ||
/** | ||
@@ -39,3 +48,3 @@ * Generate a constant token expression from function token expression. | ||
toConstant(includeEscapeTags = false) { | ||
let constantExpression = FunctionTokenExpression.PREFIX + this.expression; | ||
let constantExpression = `${FunctionTokenExpression.PREFIX}${this.expression}`; | ||
if (includeEscapeTags) { | ||
@@ -46,8 +55,23 @@ constantExpression = '{' + constantExpression + '}'; | ||
} | ||
async tokenEvaluatePromise(scope) { | ||
return scope.evaluateFunctionExpression(this.expression); | ||
} | ||
stringify() { | ||
return `${this.functionName()}(${this.arguments.map((arg) => arg.stringify()).join(', ')})`; | ||
if (!this.isCallExpression()) { | ||
return this.expression; | ||
} | ||
const argStrings = this.arguments.map((arg) => arg.stringify()); | ||
return `${this.functionName()}(${argStrings.join(', ')})`; | ||
} | ||
clone() { | ||
return new FunctionTokenExpression(Object.assign(Object.assign({}, this.options), { arguments: this.arguments != null ? [...this.arguments.map((a) => a.clone())] : undefined })); | ||
} | ||
static trimPrefix(expression) { | ||
// remove indicator prefix from expression | ||
expression = expression.trim(); | ||
if (FunctionTokenExpression.hasPrefix(expression)) { | ||
return expression.slice(FunctionTokenExpression.PREFIX.length); | ||
} | ||
return expression; | ||
} | ||
static hasPrefix(expression) { | ||
return expression.startsWith(FunctionTokenExpression.PREFIX); | ||
} | ||
} | ||
@@ -54,0 +78,0 @@ exports.FunctionTokenExpression = FunctionTokenExpression; |
@@ -27,2 +27,5 @@ "use strict"; | ||
} | ||
clone() { | ||
return new LegacyFunctionTokenExpression(this.options); | ||
} | ||
} | ||
@@ -29,0 +32,0 @@ exports.LegacyFunctionTokenExpression = LegacyFunctionTokenExpression; |
@@ -18,3 +18,4 @@ "use strict"; | ||
__exportStar(require("./TokenExpression"), exports); | ||
__exportStar(require("./ObjectTokenExpression"), exports); | ||
__exportStar(require("./object/ObjectTokenExpression"), exports); | ||
__exportStar(require("./object/ArrayTokenExpression"), exports); | ||
__exportStar(require("./shorthand/ShorthandTokenExpression"), exports); | ||
@@ -25,3 +26,4 @@ __exportStar(require("./shorthand/FormatShorthandTokenExpression"), exports); | ||
__exportStar(require("./function/FunctionTokenExpression"), exports); | ||
__exportStar(require("./function/TernaryFunctionTokenExpression"), exports); | ||
__exportStar(require("./function/LegacyFunctionTokenExpression"), exports); | ||
//# sourceMappingURL=index.js.map |
@@ -16,2 +16,5 @@ "use strict"; | ||
} | ||
stringify() { | ||
return `${super.stringify()}:${this.options.format}`; | ||
} | ||
toString() { | ||
@@ -18,0 +21,0 @@ return '[object ' + this.constructor.name + ' <' + this.expression + ', ' + this.start + ', ' + this.format + '>]'; |
@@ -22,2 +22,5 @@ "use strict"; | ||
} | ||
clone() { | ||
return new ShorthandTokenExpression(this.options); | ||
} | ||
} | ||
@@ -24,0 +27,0 @@ exports.ShorthandTokenExpression = ShorthandTokenExpression; |
@@ -33,4 +33,6 @@ "use strict"; | ||
const lru_cache_1 = __importDefault(require("lru-cache")); | ||
const FormatStringContext_1 = require("./context/FormatStringContext"); | ||
const FunctionExpressionContext_1 = require("./context/FunctionExpressionContext"); | ||
const parsers_1 = require("./parsers"); | ||
const transformers_1 = require("./transformers"); | ||
const FallbackExpressionParser_1 = require("./parsers/FallbackExpressionParser"); | ||
class TokenExpressionParser { | ||
@@ -45,3 +47,3 @@ static get() { | ||
this.getParser = (0, lodash_1.memoize)((nodeType) => { | ||
for (const factory of this.factories) { | ||
for (const factory of this.parserFactories) { | ||
if (factory.canParse(nodeType)) { | ||
@@ -51,19 +53,22 @@ return factory.getParser(); | ||
} | ||
throw new Error(`No parser found for node type '${nodeType}'`); | ||
console.error(`No parser found for node type '${nodeType}'`); | ||
return new FallbackExpressionParser_1.FallbackExpressionParser(); | ||
}); | ||
this.cache = new lru_cache_1.default({ max: 1000 }); | ||
// Parser factories | ||
this.factories = []; | ||
this.registerFactory(new parsers_1.BlockStatementParserFactory()); | ||
this.registerFactory(new parsers_1.CallExpressionParserFactory()); | ||
this.registerFactory(new parsers_1.ConditionalExpressionParserFactory()); | ||
this.registerFactory(new parsers_1.IdentifierExpressionParserFactory()); | ||
this.registerFactory(new parsers_1.ExpressionNodeParserFactory()); | ||
this.registerFactory(new parsers_1.LiteralExpressionParserFactory()); | ||
this.registerFactory(new parsers_1.MemberExpressionParserFactory()); | ||
this.registerFactory(new parsers_1.ObjectExpressionParserFactory()); | ||
// Transformers | ||
this.transformers = {}; | ||
this.registerTransformer(new transformers_1.BlockStatementTransformer()); | ||
this.registerTransformer(new transformers_1.FormatSpecifierTransformer()); | ||
this.parserFactories = []; | ||
this.registerParserFactory(new parsers_1.ArrayExpressionParserFactory()); | ||
this.registerParserFactory(new parsers_1.BlockStatementParserFactory()); | ||
this.registerParserFactory(new parsers_1.CallExpressionParserFactory()); | ||
this.registerParserFactory(new parsers_1.ConditionalExpressionParserFactory()); | ||
this.registerParserFactory(new parsers_1.IdentifierExpressionParserFactory()); | ||
this.registerParserFactory(new parsers_1.ExpressionNodeParserFactory()); | ||
this.registerParserFactory(new parsers_1.LogicalExpressionParserFactory()); | ||
this.registerParserFactory(new parsers_1.LiteralExpressionParserFactory()); | ||
this.registerParserFactory(new parsers_1.MemberExpressionParserFactory()); | ||
this.registerParserFactory(new parsers_1.ObjectExpressionParserFactory()); | ||
// ParseContext factories | ||
this.contextFactories = []; | ||
this.registerContextFactory(new FunctionExpressionContext_1.FunctionExpressionContextFactory()); | ||
this.registerContextFactory(new FormatStringContext_1.FormatStringContextFactory()); | ||
} | ||
@@ -73,2 +78,8 @@ // TODO: Better lifecycle control and dispose it afterwards | ||
var _a; | ||
if (event.source.trim() === '') { | ||
return null; | ||
} | ||
if (!event.context) { | ||
event.context = this.inferContext(event.source); | ||
} | ||
const source = this.transformSource(event); | ||
@@ -80,28 +91,31 @@ if (this.cache.has(source)) { | ||
const node = (_a = program.body[0]) !== null && _a !== void 0 ? _a : program.directives[0]; | ||
const parsed = this.parseNode(node, source); | ||
const parsed = this.parseNode({ node, source: source, context: event.context }); | ||
this.cache.set(source, parsed); | ||
return parsed; | ||
} | ||
parseNode(node, source) { | ||
const parser = this.getParser(node.type); | ||
return parser.parse({ node: node, source, parseNode: this.parseNode.bind(this) }); | ||
parseNode(event) { | ||
const parser = this.getParser(event.node.type); | ||
return parser.parse(Object.assign(Object.assign({}, event), { parseNode: this.parseNode.bind(this) })); | ||
} | ||
registerFactory(factory) { | ||
this.factories.push(factory); | ||
registerParserFactory(factory) { | ||
this.parserFactories.push(factory); | ||
} | ||
registerTransformer(transformer) { | ||
this.transformers[transformer.type] = transformer; | ||
registerContextFactory(factory) { | ||
this.contextFactories.push(factory); | ||
} | ||
transformSource(event) { | ||
var _a; | ||
const transformers = (_a = event.transformers) !== null && _a !== void 0 ? _a : []; | ||
let transformed = event.source; | ||
for (const transformerType of transformers) { | ||
const transformer = this.transformers[transformerType.TYPE]; | ||
if (!transformer) { | ||
throw new Error(`No transformer found for type '${transformerType}'`); | ||
if (!((_a = event.context) === null || _a === void 0 ? void 0 : _a.hasTransformers())) { | ||
return event.source; | ||
} | ||
return event.context.transformSource(event.source); | ||
} | ||
inferContext(source) { | ||
for (const factory of this.contextFactories) { | ||
const context = factory.inferParseContext(source); | ||
if (context != null) { | ||
return context; | ||
} | ||
transformed = transformer.transform({ source: transformed }); | ||
} | ||
return transformed; | ||
return null; | ||
} | ||
@@ -108,0 +122,0 @@ } |
@@ -46,3 +46,3 @@ "use strict"; | ||
const colon = expression.indexOf(':'); | ||
if (colon == -1) { | ||
if (colon === -1) { | ||
return new token_expressions_1.ShorthandTokenExpression({ expression }); | ||
@@ -49,0 +49,0 @@ } |
@@ -13,4 +13,3 @@ "use strict"; | ||
} | ||
transform(event) { | ||
const { source } = event; | ||
transform(source) { | ||
return !ENCLOSED_IN_CURLY_BRACKETS.test(source) ? `{${source}}` : source; | ||
@@ -20,3 +19,3 @@ } | ||
exports.BlockStatementTransformer = BlockStatementTransformer; | ||
BlockStatementTransformer.TYPE = 'to-block-statement'; | ||
BlockStatementTransformer.TYPE = 'block-statement-transformer'; | ||
//# sourceMappingURL=BlockStatementTransformer.js.map |
@@ -10,3 +10,3 @@ "use strict"; | ||
/** Transforms format specifiers in source code; | ||
* value:0n -> {value; $format = "0n"} | ||
* value:0n -> value; $format = "0n" | ||
*/ | ||
@@ -17,4 +17,3 @@ class FormatSpecifierTransformer extends SourceTransformer_1.SourceTransformer { | ||
} | ||
transform(event) { | ||
const { source } = event; | ||
transform(source) { | ||
// Regex matching is expensive, so we first check if the source at least contains a colon | ||
@@ -37,4 +36,4 @@ if (source.indexOf(':') === -1) { | ||
exports.FormatSpecifierTransformer = FormatSpecifierTransformer; | ||
FormatSpecifierTransformer.TYPE = 'format-specifier'; | ||
FormatSpecifierTransformer.TYPE = 'format-specifier-transformer'; | ||
FormatSpecifierTransformer.SOURCE_IDENTIFIER = `$format`; | ||
//# sourceMappingURL=FormatSpecifierTransformer.js.map |
{ | ||
"name": "@journeyapps/evaluator", | ||
"version": "0.0.0-dev.cad60fd", | ||
"version": "0.0.0-dev.cc719a7", | ||
"description": "Journey Evaluator library", | ||
@@ -15,3 +15,3 @@ "main": "./dist/index.js", | ||
"lodash": "^4.17.21", | ||
"@journeyapps/core-xml": "0.0.0-dev.cad60fd" | ||
"@journeyapps/core-xml": "0.0.0-dev.cc719a7" | ||
}, | ||
@@ -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
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
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
280095
123
2271
0
+ Added@journeyapps/core-xml@0.0.0-dev.cc719a7(transitive)
- Removed@journeyapps/core-xml@0.0.0-dev.cad60fd(transitive)