diff --git a/src/lib/lexer.ts b/src/lib/lexer.ts new file mode 100644 index 00000000..37154b30 --- /dev/null +++ b/src/lib/lexer.ts @@ -0,0 +1,7 @@ +import perplex from 'perplex' + +// Work around an issue with ESM and the perplex module. Explicitly re-export +// the .default to make it work. +// See https://github.com/evanw/esbuild/issues/1719 +// @ts-ignore +export const Lexer = perplex.default diff --git a/src/lib/predicateParser.ts b/src/lib/predicateParser.ts index c26ba9a6..7181625c 100644 --- a/src/lib/predicateParser.ts +++ b/src/lib/predicateParser.ts @@ -4,9 +4,9 @@ * * See https://docs.commercetools.com/api/predicates/query */ -import perplex from 'perplex' import { ITokenPosition, Parser } from 'pratt' import { haversineDistance } from './haversine' +import { Lexer } from './lexer' export class PredicateError { message: string @@ -104,7 +104,7 @@ const resolveValue = (obj: any, val: TypeSymbol): any => { } const getLexer = (value: string) => - new perplex(value) + new Lexer(value) .token('AND', /and(?![-_a-z0-9]+)/i) .token('OR', /or(?![-_a-z0-9]+)/i) diff --git a/src/lib/projectionSearchFilter.ts b/src/lib/projectionSearchFilter.ts index 6b512a83..fde82ead 100644 --- a/src/lib/projectionSearchFilter.ts +++ b/src/lib/projectionSearchFilter.ts @@ -3,10 +3,10 @@ */ import type { ProductProjection, ProductVariant } from '@commercetools/platform-sdk' -import perplex from 'perplex' import Parser from 'pratt' import { nestedLookup } from '../helpers' import type { Writable } from '../types' +import { Lexer } from './lexer' type MatchFunc = (target: any) => boolean @@ -72,7 +72,7 @@ export const parseFilterExpression = ( } const getLexer = (value: string) => - new perplex(value) + new Lexer(value) .token('MISSING', /missing(?![-_a-z0-9]+)/i) .token('EXISTS', /exists(?![-_a-z0-9]+)/i) .token('RANGE', /range(?![-_a-z0-9]+)/i) @@ -211,7 +211,7 @@ const parseFilter = (filter: string): ExpressionSet => { // Return a list of functions which matches the ranges. These functions // are processed as an OR clause return ranges.map((range: any) => { - let func = undefined + let func: (obj: any) => boolean if (range.start !== null && range.stop !== null) { func = (obj: any): boolean => obj >= range.start && obj <= range.stop