Update value.ts
This commit is contained in:
parent
77f86ce829
commit
82d727cc74
16
src/value.ts
16
src/value.ts
|
|
@ -11,13 +11,13 @@ export type Value =
|
||||||
| {
|
| {
|
||||||
type: 'function',
|
type: 'function',
|
||||||
params: string[],
|
params: string[],
|
||||||
defaults: Record<string, number>, // indices into constants
|
defaults: Record<string, number>, // indices into constants
|
||||||
body: number,
|
body: number,
|
||||||
parentScope: Scope,
|
parentScope: Scope,
|
||||||
variadic: boolean,
|
variadic: boolean,
|
||||||
named: boolean,
|
named: boolean,
|
||||||
value: '<function>'
|
value: '<function>'
|
||||||
}
|
}
|
||||||
|
|
||||||
export type Dict = Map<string, Value>
|
export type Dict = Map<string, Value>
|
||||||
|
|
||||||
|
|
@ -31,13 +31,17 @@ export type FunctionDef = {
|
||||||
}
|
}
|
||||||
|
|
||||||
export function toValue(v: any): Value /* throws */ {
|
export function toValue(v: any): Value /* throws */ {
|
||||||
if (v === null || v === undefined) return { type: 'null', value: null }
|
if (v === null || v === undefined)
|
||||||
|
return { type: 'null', value: null }
|
||||||
|
|
||||||
if (v && typeof v === 'object' && 'type' in v && 'value' in v) return v as Value
|
if (v && typeof v === 'object' && 'type' in v && 'value' in v)
|
||||||
|
return v as Value
|
||||||
|
|
||||||
if (Array.isArray(v)) return { type: 'array', value: v.map(toValue) }
|
if (Array.isArray(v))
|
||||||
|
return { type: 'array', value: v.map(toValue) }
|
||||||
|
|
||||||
if (v instanceof RegExp) return { type: 'regex', value: v }
|
if (v instanceof RegExp)
|
||||||
|
return { type: 'regex', value: v }
|
||||||
|
|
||||||
switch (typeof v) {
|
switch (typeof v) {
|
||||||
case 'boolean':
|
case 'boolean':
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user