Skip to content

Commit

Permalink
Make full spread support
Browse files Browse the repository at this point in the history
  • Loading branch information
dy committed Mar 7, 2024
1 parent 59eda32 commit 234f2c0
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 9 deletions.
8 changes: 4 additions & 4 deletions feature/array.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { PREC_TOKEN } from '../src/const.js'
// [a,b,c]
group('[]', PREC_TOKEN)
operator('[]', (a, b) => (
!a ? () => [] : // []
a[0] === ',' ? (a = a.slice(1).map(compile), ctx => a.map(a => a(ctx))) : // [a,b,c]
(a = compile(a), ctx => [a(ctx)]) // [a]
))
a = !a ? [] : a[0] === ',' ? a.slice(1) : [a],
a = a.map(a => a[0] === '...' ? (a = compile(a[1]), ctx => a(ctx)) : (a = compile(a), ctx => [a(ctx)])),
ctx => a.flatMap(a => (a(ctx))))
)
2 changes: 1 addition & 1 deletion feature/spread.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ import { PREC_PREFIX } from "../src/const.js"
import { operator, compile } from "../src/compile.js"

unary('...', PREC_PREFIX)
operator('...', a => (a = compile(a), ctx => Object.entries(a(ctx))))
operator('...', (a) => (a = compile(a), ctx => Object.entries(a(ctx))))
3 changes: 2 additions & 1 deletion justin.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// no-keywords js, just in https://github.com/endojs/Jessie/issues/66
import { err, token, binary } from './src/parse.js'
import { err, token, binary, unary } from './src/parse.js'
import compile, { operator, prop } from './src/compile.js'

import subscript from './subscript.js'
Expand All @@ -11,6 +11,7 @@ import './feature/array.js'
import './feature/object.js'
import './feature/arrow.js'
import './feature/optional.js'
import './feature/spread.js'
import { PREC_ASSIGN, PREC_EQ, PREC_LOR, PREC_COMP } from './src/const.js'

binary('in', PREC_COMP), operator('in', (a, b) => b && (a = compile(a), b = compile(b), ctx => a(ctx) in b(ctx)))
Expand Down
2 changes: 1 addition & 1 deletion test/perf.js
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@ test.skip('subscript v5', async t => {
})


test.skip('new Function', async t => {
test('new Function', async t => {
console.time('new Function')
for (let n = 0; n < RUNS; n++) {
let fn = new Function('a', 'b', 'c', 'd', 'f', 'i', 'k', 'return ' + src(n))
Expand Down
6 changes: 4 additions & 2 deletions test/subscript.js
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ test.skip('ext: in operator', async t => {
throws(() => subscript('b inc'))
})

test('ext: list', async t => {
test('array', async t => {
await import('../feature/array.js')

is(subscript('[]')(), [])
Expand All @@ -358,6 +358,8 @@ test('ext: list', async t => {
is(subscript('[]')(), [])
is(subscript('[ ]')(), [])

is(subscript('[ 1, ...x ]')({ x: [2, 3] }), [1, 2, 3])

// TODO: prefix/postfix maybe?
// is(subscript('[1,]')({}),[1])
// is(subscript('[,]')({}),[undefined])
Expand Down Expand Up @@ -393,7 +395,7 @@ test.skip('ext: ternary', t => {
sameAsJs('a? b?c:d :e', { a: 0, c: 0, d: 1, e: 2 })
})

test.only('object', async t => {
test('object', async t => {
await import('../feature/object.js')
await import('../feature/ternary.js')

Expand Down

0 comments on commit 234f2c0

Please sign in to comment.