Skip to content

Commit 705be90

Browse files
committed
feat(evaluator): evaluateSync
1 parent 953c76d commit 705be90

File tree

13 files changed

+851
-594
lines changed

13 files changed

+851
-594
lines changed

Diff for: src/1.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
export {evaluate} from './evaluator'
1+
export {evaluate, evaluateSync} from './evaluator'
22
export type {GroqFunction, GroqFunctionArg, GroqPipeFunction} from './evaluator/functions'
33
export type {Scope} from './evaluator/scope'
44
export type {

Diff for: src/evaluator/constantEvaluate.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type {ExprNode} from '../nodeTypes'
2-
import {NULL_VALUE, type Value} from '../values'
2+
import {isPromiseLike, NULL_VALUE, type Value} from '../values'
33
import {evaluate} from './evaluate'
44
import {Scope} from './scope'
55

@@ -47,8 +47,8 @@ export function tryConstantEvaluate(node: ExprNode): Value | null {
4747
}
4848

4949
function constantEvaluate(node: ExprNode): Value {
50-
const value = evaluate(node, DUMMY_SCOPE, constantEvaluate)
51-
if ('then' in value) {
50+
const value = evaluate(node, DUMMY_SCOPE, 'sync')
51+
if (isPromiseLike(value)) {
5252
throw new Error('BUG: constant evaluate should never return a promise')
5353
}
5454
return value

0 commit comments

Comments
 (0)