All files / src/elm structured.coffee

100% Statements 27/27
61.54% Branches 16/26
100% Functions 6/6
100% Lines 26/26

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 36 37 38 39 40 41 42 43 44 45 46 47 4833x 1x   1x   197x 197x 197x 197x     113x 58x 113x     2x 2x 2x 2x 2x 2x 2x     1x   2614x 5228x           1x         287x 574x 486x     1x   1x  
{ Expression, UnimplementedExpression } = require './expression'
{ build } = require './builder'
 
module.exports.Property = class Property extends Expression
  constructor: (json) ->
    super
    @scope = json.scope
    @source = build json.source
    @path = json.path
 
  exec: (ctx) ->
    obj = if @scope? then ctx.get(@scope) else @source
    if obj instanceof Expression then obj = obj.execute(ctx)
    val = obj?[@path] ? obj?.get?(@path)
 
    if !val
      parts = @path.split(".")
      curr_obj = obj
      curr_val = null
      for part in parts
        _obj = curr_obj?[part] ? curr_obj?.get?(part)
        curr_obj = if _obj instanceof Function then _obj.call(curr_obj) else _obj
      val = curr_obj ? null # convert undefined to null
    if val instanceof Function then val.call(obj) else val
 
module.exports.Tuple = class Tuple extends Expression
  constructor: (json) ->
    super
    @elements = for el in json.element
      name: el.name
      value: build el.value
 
  # Define a simple getter to allow type-checking of this class without instanceof
  # and in a way that survives minification (as opposed to checking constructor.name)
  Object.defineProperties @prototype,
    isTuple:
      get: -> true
 
  exec: (ctx) ->
    val = {}
    for el in @elements
      val[el.name] = el.value?.execute(ctx)
    val
 
module.exports.TupleElement = class TupleElement extends UnimplementedExpression
 
module.exports.TupleElementDefinition = class TupleElementDefinition extends UnimplementedExpression