Compare commits
No commits in common. "eb4f103ba3693b3ff8137e1eb76f8c4caa81f320" and "a885a59140c554b0ecf29234cf7c2a5971a81ce5" have entirely different histories.
eb4f103ba3
...
a885a59140
16
src/vm.ts
16
src/vm.ts
|
|
@ -468,6 +468,14 @@ export class VM {
|
|||
}
|
||||
}
|
||||
|
||||
// Handle variadic parameter (TypeScript rest parameters)
|
||||
// For TypeScript functions with ...rest, we spread the remaining args
|
||||
// rather than wrapping them in an array
|
||||
if (paramInfo.variadic) {
|
||||
const remainingArgs = positionalArgs.slice(nativePositionalArgIndex)
|
||||
nativeArgs.push(...remainingArgs)
|
||||
}
|
||||
|
||||
// Handle named parameter (collect remaining unmatched named args)
|
||||
// Parameter names matching atXxx pattern (e.g., atOptions, atNamed) collect extra named args
|
||||
if (paramInfo.named) {
|
||||
|
|
@ -480,14 +488,6 @@ export class VM {
|
|||
nativeArgs.push(toValue(namedObj))
|
||||
}
|
||||
|
||||
// Handle variadic parameter (TypeScript rest parameters)
|
||||
// For TypeScript functions with ...rest, we spread the remaining args
|
||||
// rather than wrapping them in an array
|
||||
if (paramInfo.variadic) {
|
||||
const remainingArgs = positionalArgs.slice(nativePositionalArgIndex)
|
||||
nativeArgs.push(...remainingArgs)
|
||||
}
|
||||
|
||||
// Call the native function with bound args
|
||||
const result = await fn.fn(...nativeArgs)
|
||||
this.stack.push(result)
|
||||
|
|
|
|||
|
|
@ -534,31 +534,6 @@ test("@named pattern - basic atNamed parameter", async () => {
|
|||
expect(result).toEqual({ type: 'string', value: 'Hi, Alice! Extra: value' })
|
||||
})
|
||||
|
||||
test('@named pattern - atNamed parameters with varadic args', async () => {
|
||||
const bytecode = toBytecode(`
|
||||
TRY_LOAD cmd
|
||||
TRY_LOAD rest1
|
||||
TRY_LOAD rest2
|
||||
PUSH 'named'
|
||||
TRY_LOAD named-value
|
||||
PUSH 2
|
||||
PUSH 1
|
||||
CALL
|
||||
HALT
|
||||
`)
|
||||
|
||||
const vm = new VM(bytecode)
|
||||
vm.registerFunction('cmd', (atNamed: any = {}, ...rest: string[]) => {
|
||||
return { rest, namedArg: atNamed['named'] }
|
||||
})
|
||||
|
||||
const result = await vm.run()
|
||||
expect(result.type).toBe('dict')
|
||||
if (!(result.value instanceof Map)) throw new Error('Expected dict')
|
||||
expect(result.value.get('rest')).toEqual(toValue(['rest1', 'rest2']))
|
||||
expect(result.value.get('namedArg')).toEqual(toValue('named-value'))
|
||||
})
|
||||
|
||||
test("@named pattern - mixed positional and atOptions", async () => {
|
||||
const bytecode = toBytecode(`
|
||||
LOAD configure
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user