# Code coverage report for lib/parser/ast/script.js

## Statements: 100% (17 / 17) Branches: 100% (2 / 2) Functions: 100% (7 / 7) Lines: 100% (17 / 17) Ignored: none

All files » lib/parser/ast/ » script.js

    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
    391

    1
    246
    246

    1

    141
    458

    139

    132

    141
    132

    130

    141

    141

    141

    141

    1var BaseExpression = require("./base"),
    uniq               = require("../../utils/uniq");

    function ScriptExpression (value) {
      this.value = value;
      BaseExpression.apply(this, arguments);
    }

    BaseExpression.extend(ScriptExpression, {
      type: "script",
      toJavaScript: function () {

        var refs = this.filterAllChildren(function (child) {
          return child.type === "reference";
        }).filter(function (reference) {
          return !reference.unbound && reference.path;
        }).map(function (reference) {
          return reference.path;
        });

        // remove duplicate references
        refs = uniq(refs.map(function (ref) {
          return ref.join(".")
        })).map(function (ref) {
          return ref.split(".");
        });

        var buffer = "{";

        buffer += "run: function () { return " + this.value.toJavaScript() + "; }";

        buffer += ", refs: " + JSON.stringify(refs)

        return buffer + "}";
      }
    });

    module.exports = ScriptExpression;