Code coverage report for 6to5/lib/6to5/generation/generators/modules.js

Statements: 100% (56 / 56)      Branches: 100% (35 / 35)      Functions: 100% (7 / 7)      Lines: 100% (55 / 55)      Ignored: none     

All files » 6to5/lib/6to5/generation/generators/ » modules.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 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 971 1   1 20 5   15       1 34 34 18 18       1 2     1 37   37   37 10     37 21 21   16 2   14 14 13 13 13   14     16 9 9       23     1 16   16   16 16 14   14 22 8     22   22 9 9     22     14 9     14     16 16     1 2 2    
var t = require("../../types");
var _ = require("lodash");
 
exports.ImportSpecifier = function (node, print) {
  if (node.id && node.id.name === "default") {
    print(node.name);
  } else {
    return exports.ExportSpecifier.apply(this, arguments);
  }
};
 
exports.ExportSpecifier = function (node, print) {
  print(node.id);
  if (node.name) {
    this.push(" as ");
    print(node.name);
  }
};
 
exports.ExportBatchSpecifier = function () {
  this.push("*");
};
 
exports.ExportDeclaration = function (node, print) {
  this.push("export ");
 
  var specifiers = node.specifiers;
 
  if (node.default) {
    this.push("default ");
  }
 
  if (node.declaration) {
    print(node.declaration);
    if (t.isStatement(node.declaration)) return;
  } else {
    if (specifiers.length === 1 && t.isExportBatchSpecifier(specifiers[0])) {
      print(specifiers[0]);
    } else {
      this.push("{");
      if (specifiers.length) {
        this.space();
        print.join(specifiers, { separator: ", " });
        this.space();
      }
      this.push("}");
    }
 
    if (node.source) {
      this.push(" from ");
      print(node.source);
    }
  }
 
  this.ensureSemicolon();
};
 
exports.ImportDeclaration = function (node, print) {
  var self = this;
 
  this.push("import ");
 
  var specfiers = node.specifiers;
  if (specfiers && specfiers.length) {
    var foundImportSpecifier = false;
 
    _.each(node.specifiers, function (spec, i) {
      if (+i > 0) {
        self.push(", ");
      }
 
      var isDefault = spec.id && spec.id.name === "default";
 
      if (!isDefault && spec.type !== "ImportBatchSpecifier" && !foundImportSpecifier) {
        foundImportSpecifier = true;
        self.push("{ ");
      }
 
      print(spec);
    });
 
    if (foundImportSpecifier) {
      this.push(" }");
    }
 
    this.push(" from ");
  }
 
  print(node.source);
  this.semicolon();
};
 
exports.ImportBatchSpecifier = function (node, print) {
  this.push("* as ");
  print(node.name);
};