just native, <function>

This commit is contained in:
Chris Wanstrath 2025-10-17 12:39:14 -07:00
parent 4d2ae1c9fe
commit 93eff53a76

View File

@ -20,7 +20,7 @@ export type Value =
named: boolean, named: boolean,
value: '<function>' value: '<function>'
} }
| { type: 'native_function', fn: NativeFunction, value: '<native>' } | { type: 'native', fn: NativeFunction, value: '<function>' }
export type Dict = Map<string, Value> export type Dict = Map<string, Value>
@ -40,10 +40,10 @@ export function toValue(v: any): Value /* throws */ {
if (v && typeof v === 'object' && 'type' in v && 'value' in v) if (v && typeof v === 'object' && 'type' in v && 'value' in v)
return v as Value return v as Value
if (Array.isArray(v)) if (Array.isArray(v))
return { type: 'array', value: v.map(toValue) } return { type: 'array', value: v.map(toValue) }
if (v instanceof RegExp) if (v instanceof RegExp)
return { type: 'regex', value: v } return { type: 'regex', value: v }
switch (typeof v) { switch (typeof v) {
@ -104,8 +104,8 @@ export function toString(v: Value): string {
return 'null' return 'null'
case 'function': case 'function':
return '<function>' return '<function>'
case 'native_function': case 'native':
return '<native>' return '<function>'
case 'array': case 'array':
return `[${v.value.map(toString).join(', ')}]` return `[${v.value.map(toString).join(', ')}]`
case 'dict': { case 'dict': {
@ -126,9 +126,7 @@ export function isEqual(a: Value, b: Value): boolean {
case 'null': case 'null':
return true return true
case 'boolean': case 'boolean':
return a.value === b.value
case 'number': case 'number':
return a.value === b.value
case 'string': case 'string':
return a.value === b.value return a.value === b.value
case 'array': { case 'array': {
@ -149,9 +147,8 @@ export function isEqual(a: Value, b: Value): boolean {
return String(a.value) === String(b.value) return String(a.value) === String(b.value)
} }
case 'function': case 'function':
case 'native':
return false // functions never equal return false // functions never equal
case 'native_function':
return false // native functions never equal
default: default:
return false return false
} }
@ -174,9 +171,8 @@ export function fromValue(v: Value): any {
case 'regex': case 'regex':
return v.value return v.value
case 'function': case 'function':
case 'native':
return '<function>' return '<function>'
case 'native_function':
return '<native>'
} }
} }