All files / src/elm parameters.coffee

100% Statements 13/13
37.5% Branches 3/8
100% Functions 5/5
100% Lines 12/12

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 3013x 1x   1x   232x 232x 232x 232x                         1x   266x 266x 266x     105x  
{ Expression } = require './expression'
{ build } = require './builder'
 
module.exports.ParameterDef = class ParameterDef extends Expression
  constructor: (json) ->
    super
    @name = json.name
    @default = build(json.default)
    @parameterTypeSpecifier = json.parameterTypeSpecifier
 
  exec: (ctx) ->
    # If context parameters contains the name, return value.
    if (ctx?.parameters[@name]?)
      ctx.parameters[@name]
    # If default type exists, execute the default type
    else if @default?
      @default?.execute(ctx)
    # Else, if context and context's parent exist return the value of the parent's parameters with the given name.
    else
      ctx.getParentParameter @name
 
module.exports.ParameterRef = class ParameterRef extends Expression
  constructor: (json) ->
    super
    @name = json.name
    @library = json.libraryName
 
  exec: (ctx) ->
    ctx = if @library then ctx.getLibraryContext(@library) else ctx
    ctx.getParameter(@name)?.execute(ctx)