Skip to content

Commit

Permalink
[fix] validate spread element iterator
Browse files Browse the repository at this point in the history
  • Loading branch information
Siubaak committed Feb 2, 2025
1 parent c4992d0 commit 2f6d094
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/evaluate/expression.ts
Original file line number Diff line number Diff line change
Expand Up @@ -554,6 +554,9 @@ export interface SpreadOptions {

export function* SpreadElement(node: acorn.SpreadElement, scope: Scope, options: SpreadOptions = {}) {
const result = yield* evaluate(node.argument, scope)
if (typeof Symbol === 'function' && typeof result[Symbol.iterator] !== 'function') {
throw new TypeError('Spread syntax requires ...iterable[Symbol.iterator] to be a function')
}
return options.spreadProps ? result : [...result]
}

Expand Down

0 comments on commit 2f6d094

Please sign in to comment.