Skip to content

Commit

Permalink
Fix ESM issue with perplex by introducing a workaround
Browse files Browse the repository at this point in the history
See evanw/esbuild#1719 for more info
  • Loading branch information
mvantellingen committed Jul 30, 2023
1 parent a5b8fd1 commit 857d9b3
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
7 changes: 7 additions & 0 deletions src/lib/lexer.ts
Original file line number Diff line number Diff line change
@@ -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
4 changes: 2 additions & 2 deletions src/lib/predicateParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions src/lib/projectionSearchFilter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 857d9b3

Please sign in to comment.