-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathadd.js
22 lines (17 loc) · 868 Bytes
/
add.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
import { binary, unary } from '../src/parse.js'
import { PREC_ADD, PREC_PREFIX, PREC_ASSIGN } from '../src/const.js'
import { compile, prop, operator } from '../src/compile.js'
binary('+', PREC_ADD), operator('+', (a, b) => b && (a = compile(a), b = compile(b), ctx => a(ctx) + b(ctx)))
binary('-', PREC_ADD), operator('-', (a, b) => b && (a = compile(a), b = compile(b), ctx => a(ctx) - b(ctx)))
unary('+', PREC_PREFIX), operator('+', (a, b) => !b && (a = compile(a), ctx => +a(ctx)))
unary('-', PREC_PREFIX), operator('-', (a, b) => !b && (a = compile(a), ctx => -a(ctx)))
binary('+=', PREC_ASSIGN, true)
operator('+=', (a, b) => (
b = compile(b),
prop(a, (container, path, ctx) => container[path] += b(ctx))
))
binary('-=', PREC_ASSIGN, true)
operator('-=', (a, b) => (
b = compile(b),
prop(a, (container, path, ctx) => (container[path] -= b(ctx)))
))