All files / source/Caffeine.SourceMap SourceNode.js

86.67% Statements 26/30
41.18% Branches 7/17
83.33% Functions 10/12
86.67% Lines 26/30

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 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119  4x 4x 4x                                                         4x     19x 19x 19x 19x 19x       4x 4x                 4x     9x           3x 3x   3x   1x       3x     4x 3x 3x   4x                                                     4x 6x 9x       6x              
"use strict";
let Caf = require("caffeine-script-runtime");
Caf.defMod(module, () => {
  return Caf.importInvoke(
    [
      "BaseClass",
      "toInspectedObjects",
      "compactFlatten",
      "merge",
      "deepMerge",
      "SourceMapGenerator",
      "binary",
      "String"
    ],
    [
      global,
      require("art-standard-lib"),
      require("art-class-system"),
      require("art-binary"),
      { SourceMapGenerator: require("./SourceMapGenerator") }
    ],
    (
      BaseClass,
      toInspectedObjects,
      compactFlatten,
      merge,
      deepMerge,
      SourceMapGenerator,
      binary,
      String
    ) => {
      let SourceNode;
      return (SourceNode = Caf.defClass(
        class SourceNode extends BaseClass {
          constructor(sourceIndex, children) {
            super(...arguments);
            this.sourceIndex = sourceIndex;
            this.children = children;
            this._props = null;
            this._flattenedChildren = null;
          }
        },
        function(SourceNode, classSuper, instanceSuper) {
          this.property("sourceIndex", "children", "props");
          this.getter({
            inspectedObjects: function() {
              return {
                sourceIndex: this.sourceIndex,
                props: this.props,
                children: toInspectedObjects(this.children)
              };
            }
          });
          this.getter({
            flattenedChildren: function() {
              let temp;
              return (temp = this._flattenedChildren) != null
                ? temp
                : (this._flattenedChildren = compactFlatten(this.children));
            },
            mergedProps: function() {
              let out;
              Eif (this._props) {
                out = merge(this._props);
              }
              Caf.each2(this.flattenedChildren, child => {
                let mergedProps;
                return (mergedProps = child.mergedProps)
                  ? (out = out ? deepMerge(out, mergedProps) : mergedProps)
                  : undefined;
              });
              return out;
            }
          });
          this.prototype.withProps = function(_props) {
            this._props = _props;
            return this;
          };
          this.prototype.generate = function(source, options) {
            let sourceFile, sourceRoot, inlineMap, js, sourceMap, out;
            ({ sourceFile, sourceRoot, inlineMap } = options);
            ({ js, sourceMap } = out = new SourceMapGenerator(
              source,
              options
            ).add(this));
            return inlineMap
              ? {
                  sourceMap,
                  js: [
                    js,
                    `//# sourceMappingURL=${Caf.toString(
                      binary(sourceMap).toDataUri("application/json", true)
                    )}`,
                    sourceFile
                      ? (sourceRoot
                          ? (sourceFile =
                              "./" +
                              require("path").relative(sourceRoot, sourceFile))
                          : undefined,
                        `//# sourceURL=${Caf.toString(sourceFile)}`)
                      : undefined
                  ].join("\n")
                }
              : out;
          };
          this.prototype.toString = function(output = { js: "" }) {
            Caf.each2(this.flattenedChildren, child =>
              Caf.is(child, String)
                ? (output.js += child)
                : child.toString(output)
            );
            return output.js;
          };
        }
      ));
    }
  );
});