diff --git a/feature/array.js b/feature/array.js index 2082775..b6644d4 100644 --- a/feature/array.js +++ b/feature/array.js @@ -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)))) +) diff --git a/feature/spread.js b/feature/spread.js index 6225040..70c9d9c 100644 --- a/feature/spread.js +++ b/feature/spread.js @@ -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)))) diff --git a/justin.js b/justin.js index d46c0cb..46c1482 100644 --- a/justin.js +++ b/justin.js @@ -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' @@ -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))) diff --git a/test/perf.js b/test/perf.js index 99dedbf..e0b20e7 100644 --- a/test/perf.js +++ b/test/perf.js @@ -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)) diff --git a/test/subscript.js b/test/subscript.js index 0c430f5..47311db 100644 --- a/test/subscript.js +++ b/test/subscript.js @@ -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('[]')(), []) @@ -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]) @@ -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')