Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(es/utils): Support for arrays using
cast_to_number
(#9212)
**Description:** This PR allows `ArrayLit`s to be converted to numbers in the `cast_to_number` function. This allows expressions using arrays to be converted to numbers. See some example expressions below that were previously not able to be computed, but are now able to due to this change. ```js +[] // 0 +[[]] // 0 +[1] // 1 +[undefined] // 0 +[null] // 0 +[[1]] // 1 +[,] // 0 +[,,] // NaN ``` Regarding the implementation, arrays are converted to strings, and the string is then parsed as a number. So arrays like `[]` and `[undefined]` return `""` which then return `0` when parsed as a string. This is also why arrays with more than one element can't be parsed because e.g. `[1, 2]` returns `"1,2"`. This procedure follows the ECMAScript specification. https://262.ecma-international.org/6.0/#sec-tonumber https://262.ecma-international.org/6.0/#sec-toprimitive
- Loading branch information