All files / src/elm expression.coffee

80% Statements 12/15
25% Branches 1/4
57.14% Functions 4/7
76.92% Lines 10/13

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 367x 1x         33183x 20072x   162822x         24214x 24214x                 3505x 4564x       1x            
{ build } = require './builder'
{ typeIsArray } = require '../util/util'
 
module.exports.Expression = class Expression
  constructor: (json) ->
    if json.operand?
      op = build(json.operand)
      if typeIsArray(json.operand) then @args = op else @arg = op
    if json.localId?
      @localId = json.localId
 
  execute: (ctx) ->
    if @localId?
      # Store the localId and result on the root context of this library
      execValue = @exec(ctx)
      ctx.rootContext().setLocalIdWithResult @localId, execValue
      execValue
    else
      @exec(ctx)
 
  exec: (ctx) ->
    this
 
  execArgs: (ctx) ->
    switch
      when @args? then (arg.execute(ctx) for arg in @args)
      when @arg? then @arg.execute(ctx)
      else null
 
module.exports.UnimplementedExpression = class UnimplementedExpression extends Expression
  constructor: (@json) ->
    super
 
  exec: (ctx) ->
    throw new Error("Unimplemented Expression: #{@json.type}")