Skip to content

Commit

Permalink
feat(evaluator): evaluateSync
Browse files Browse the repository at this point in the history
  • Loading branch information
ricokahler committed Feb 18, 2025
1 parent 953c76d commit 705be90
Show file tree
Hide file tree
Showing 13 changed files with 851 additions and 594 deletions.
2 changes: 1 addition & 1 deletion src/1.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export {evaluate} from './evaluator'
export {evaluate, evaluateSync} from './evaluator'
export type {GroqFunction, GroqFunctionArg, GroqPipeFunction} from './evaluator/functions'
export type {Scope} from './evaluator/scope'
export type {
Expand Down
6 changes: 3 additions & 3 deletions src/evaluator/constantEvaluate.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type {ExprNode} from '../nodeTypes'
import {NULL_VALUE, type Value} from '../values'
import {isPromiseLike, NULL_VALUE, type Value} from '../values'
import {evaluate} from './evaluate'
import {Scope} from './scope'

Expand Down Expand Up @@ -47,8 +47,8 @@ export function tryConstantEvaluate(node: ExprNode): Value | null {
}

function constantEvaluate(node: ExprNode): Value {
const value = evaluate(node, DUMMY_SCOPE, constantEvaluate)
if ('then' in value) {
const value = evaluate(node, DUMMY_SCOPE, 'sync')
if (isPromiseLike(value)) {
throw new Error('BUG: constant evaluate should never return a promise')
}
return value
Expand Down
Loading

0 comments on commit 705be90

Please sign in to comment.