BVB Source Codes

reactide Show index.js Source code

Return Download reactide: download index.js Source code - Download reactide Source code - Type:.js
  1. "use strict";
  2.  
  3. exports.__esModule = true;
  4. exports.File = undefined;
  5.  
  6. var _typeof2 = require("babel-runtime/helpers/typeof");
  7.  
  8. var _typeof3 = _interopRequireDefault(_typeof2);
  9.  
  10. var _getIterator2 = require("babel-runtime/core-js/get-iterator");
  11.  
  12. var _getIterator3 = _interopRequireDefault(_getIterator2);
  13.  
  14. var _create = require("babel-runtime/core-js/object/create");
  15.  
  16. var _create2 = _interopRequireDefault(_create);
  17.  
  18. var _assign = require("babel-runtime/core-js/object/assign");
  19.  
  20. var _assign2 = _interopRequireDefault(_assign);
  21.  
  22. var _classCallCheck2 = require("babel-runtime/helpers/classCallCheck");
  23.  
  24. var _classCallCheck3 = _interopRequireDefault(_classCallCheck2);
  25.  
  26. var _possibleConstructorReturn2 = require("babel-runtime/helpers/possibleConstructorReturn");
  27.  
  28. var _possibleConstructorReturn3 = _interopRequireDefault(_possibleConstructorReturn2);
  29.  
  30. var _inherits2 = require("babel-runtime/helpers/inherits");
  31.  
  32. var _inherits3 = _interopRequireDefault(_inherits2);
  33.  
  34. var _babelHelpers = require("babel-helpers");
  35.  
  36. var _babelHelpers2 = _interopRequireDefault(_babelHelpers);
  37.  
  38. var _metadata = require("./metadata");
  39.  
  40. var metadataVisitor = _interopRequireWildcard(_metadata);
  41.  
  42. var _convertSourceMap = require("convert-source-map");
  43.  
  44. var _convertSourceMap2 = _interopRequireDefault(_convertSourceMap);
  45.  
  46. var _optionManager = require("./options/option-manager");
  47.  
  48. var _optionManager2 = _interopRequireDefault(_optionManager);
  49.  
  50. var _pluginPass = require("../plugin-pass");
  51.  
  52. var _pluginPass2 = _interopRequireDefault(_pluginPass);
  53.  
  54. var _shebangRegex = require("shebang-regex");
  55.  
  56. var _shebangRegex2 = _interopRequireDefault(_shebangRegex);
  57.  
  58. var _babelTraverse = require("babel-traverse");
  59.  
  60. var _babelTraverse2 = _interopRequireDefault(_babelTraverse);
  61.  
  62. var _sourceMap = require("source-map");
  63.  
  64. var _sourceMap2 = _interopRequireDefault(_sourceMap);
  65.  
  66. var _babelGenerator = require("babel-generator");
  67.  
  68. var _babelGenerator2 = _interopRequireDefault(_babelGenerator);
  69.  
  70. var _babelCodeFrame = require("babel-code-frame");
  71.  
  72. var _babelCodeFrame2 = _interopRequireDefault(_babelCodeFrame);
  73.  
  74. var _defaults = require("lodash/defaults");
  75.  
  76. var _defaults2 = _interopRequireDefault(_defaults);
  77.  
  78. var _logger = require("./logger");
  79.  
  80. var _logger2 = _interopRequireDefault(_logger);
  81.  
  82. var _store = require("../../store");
  83.  
  84. var _store2 = _interopRequireDefault(_store);
  85.  
  86. var _babylon = require("babylon");
  87.  
  88. var _util = require("../../util");
  89.  
  90. var util = _interopRequireWildcard(_util);
  91.  
  92. var _path = require("path");
  93.  
  94. var _path2 = _interopRequireDefault(_path);
  95.  
  96. var _babelTypes = require("babel-types");
  97.  
  98. var t = _interopRequireWildcard(_babelTypes);
  99.  
  100. var _blockHoist = require("../internal-plugins/block-hoist");
  101.  
  102. var _blockHoist2 = _interopRequireDefault(_blockHoist);
  103.  
  104. var _shadowFunctions = require("../internal-plugins/shadow-functions");
  105.  
  106. var _shadowFunctions2 = _interopRequireDefault(_shadowFunctions);
  107.  
  108. function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }
  109.  
  110. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  111.  
  112. /* global BabelFileResult, BabelParserOptions, BabelFileMetadata */
  113. /* eslint max-len: 0 */
  114.  
  115. var INTERNAL_PLUGINS = [[_blockHoist2.default], [_shadowFunctions2.default]];
  116.  
  117. var errorVisitor = {
  118.   enter: function enter(path, state) {
  119.     var loc = path.node.loc;
  120.     if (loc) {
  121.       state.loc = loc;
  122.       path.stop();
  123.     }
  124.   }
  125. };
  126.  
  127. var File = function (_Store) {
  128.   (0, _inherits3.default)(File, _Store);
  129.  
  130.   function File() {
  131.     var opts = arguments.length <= 0 || arguments[0] === undefined ? {} : arguments[0];
  132.     var pipeline = arguments[1];
  133.     (0, _classCallCheck3.default)(this, File);
  134.  
  135.     var _this = (0, _possibleConstructorReturn3.default)(this, _Store.call(this));
  136.  
  137.     _this.pipeline = pipeline;
  138.  
  139.     _this.log = new _logger2.default(_this, opts.filename || "unknown");
  140.     _this.opts = _this.initOptions(opts);
  141.  
  142.     _this.parserOpts = {
  143.       highlightCode: _this.opts.highlightCode,
  144.       nonStandard: _this.opts.nonStandard,
  145.       sourceType: _this.opts.sourceType,
  146.       filename: _this.opts.filename,
  147.       plugins: []
  148.     };
  149.  
  150.     _this.pluginVisitors = [];
  151.     _this.pluginPasses = [];
  152.  
  153.     // Plugins for top-level options.
  154.     _this.buildPluginsForOptions(_this.opts);
  155.  
  156.     // If we are in the "pass per preset" mode, build
  157.     // also plugins for each preset.
  158.     if (_this.opts.passPerPreset) {
  159.       // All the "per preset" options are inherited from the main options.
  160.       _this.perPresetOpts = [];
  161.       _this.opts.presets.forEach(function (presetOpts) {
  162.         var perPresetOpts = (0, _assign2.default)((0, _create2.default)(_this.opts), presetOpts);
  163.         _this.perPresetOpts.push(perPresetOpts);
  164.         _this.buildPluginsForOptions(perPresetOpts);
  165.       });
  166.     }
  167.  
  168.     _this.metadata = {
  169.       usedHelpers: [],
  170.       marked: [],
  171.       modules: {
  172.         imports: [],
  173.         exports: {
  174.           exported: [],
  175.           specifiers: []
  176.         }
  177.       }
  178.     };
  179.  
  180.     _this.dynamicImportTypes = {};
  181.     _this.dynamicImportIds = {};
  182.     _this.dynamicImports = [];
  183.     _this.declarations = {};
  184.     _this.usedHelpers = {};
  185.  
  186.     _this.path = null;
  187.     _this.ast = {};
  188.  
  189.     _this.code = "";
  190.     _this.shebang = "";
  191.  
  192.     _this.hub = new _babelTraverse.Hub(_this);
  193.     return _this;
  194.   }
  195.  
  196.   File.prototype.getMetadata = function getMetadata() {
  197.     var has = false;
  198.     for (var _iterator = this.ast.program.body, _isArray = Array.isArray(_iterator), _i = 0, _iterator = _isArray ? _iterator : (0, _getIterator3.default)(_iterator);;) {
  199.       var _ref;
  200.  
  201.       if (_isArray) {
  202.         if (_i >= _iterator.length) break;
  203.         _ref = _iterator[_i++];
  204.       } else {
  205.         _i = _iterator.next();
  206.         if (_i.done) break;
  207.         _ref = _i.value;
  208.       }
  209.  
  210.       var node = _ref;
  211.  
  212.       if (t.isModuleDeclaration(node)) {
  213.         has = true;
  214.         break;
  215.       }
  216.     }
  217.     if (has) {
  218.       this.path.traverse(metadataVisitor, this);
  219.     }
  220.   };
  221.  
  222.   File.prototype.initOptions = function initOptions(opts) {
  223.     opts = new _optionManager2.default(this.log, this.pipeline).init(opts);
  224.  
  225.     if (opts.inputSourceMap) {
  226.       opts.sourceMaps = true;
  227.     }
  228.  
  229.     if (opts.moduleId) {
  230.       opts.moduleIds = true;
  231.     }
  232.  
  233.     opts.basename = _path2.default.basename(opts.filename, _path2.default.extname(opts.filename));
  234.  
  235.     opts.ignore = util.arrayify(opts.ignore, util.regexify);
  236.  
  237.     if (opts.only) opts.only = util.arrayify(opts.only, util.regexify);
  238.  
  239.     (0, _defaults2.default)(opts, {
  240.       moduleRoot: opts.sourceRoot
  241.     });
  242.  
  243.     (0, _defaults2.default)(opts, {
  244.       sourceRoot: opts.moduleRoot
  245.     });
  246.  
  247.     (0, _defaults2.default)(opts, {
  248.       filenameRelative: opts.filename
  249.     });
  250.  
  251.     var basenameRelative = _path2.default.basename(opts.filenameRelative);
  252.  
  253.     (0, _defaults2.default)(opts, {
  254.       sourceFileName: basenameRelative,
  255.       sourceMapTarget: basenameRelative
  256.     });
  257.  
  258.     return opts;
  259.   };
  260.  
  261.   File.prototype.buildPluginsForOptions = function buildPluginsForOptions(opts) {
  262.     if (!Array.isArray(opts.plugins)) {
  263.       return;
  264.     }
  265.  
  266.     var plugins = opts.plugins.concat(INTERNAL_PLUGINS);
  267.     var currentPluginVisitors = [];
  268.     var currentPluginPasses = [];
  269.  
  270.     // init plugins!
  271.     for (var _iterator2 = plugins, _isArray2 = Array.isArray(_iterator2), _i2 = 0, _iterator2 = _isArray2 ? _iterator2 : (0, _getIterator3.default)(_iterator2);;) {
  272.       var _ref2;
  273.  
  274.       if (_isArray2) {
  275.         if (_i2 >= _iterator2.length) break;
  276.         _ref2 = _iterator2[_i2++];
  277.       } else {
  278.         _i2 = _iterator2.next();
  279.         if (_i2.done) break;
  280.         _ref2 = _i2.value;
  281.       }
  282.  
  283.       var ref = _ref2;
  284.       var plugin = ref[0];
  285.       var pluginOpts = ref[1]; // todo: fix - can't embed in loop head because of flow bug
  286.  
  287.       currentPluginVisitors.push(plugin.visitor);
  288.       currentPluginPasses.push(new _pluginPass2.default(this, plugin, pluginOpts));
  289.  
  290.       if (plugin.manipulateOptions) {
  291.         plugin.manipulateOptions(opts, this.parserOpts, this);
  292.       }
  293.     }
  294.  
  295.     this.pluginVisitors.push(currentPluginVisitors);
  296.     this.pluginPasses.push(currentPluginPasses);
  297.   };
  298.  
  299.   File.prototype.getModuleName = function getModuleName() {
  300.     var opts = this.opts;
  301.     if (!opts.moduleIds) {
  302.       return null;
  303.     }
  304.  
  305.     // moduleId is n/a if a `getModuleId()` is provided
  306.     if (opts.moduleId != null && !opts.getModuleId) {
  307.       return opts.moduleId;
  308.     }
  309.  
  310.     var filenameRelative = opts.filenameRelative;
  311.     var moduleName = "";
  312.  
  313.     if (opts.moduleRoot != null) {
  314.       moduleName = opts.moduleRoot + "/";
  315.     }
  316.  
  317.     if (!opts.filenameRelative) {
  318.       return moduleName + opts.filename.replace(/^\//, "");
  319.     }
  320.  
  321.     if (opts.sourceRoot != null) {
  322.       // remove sourceRoot from filename
  323.       var sourceRootRegEx = new RegExp("^" + opts.sourceRoot + "\/?");
  324.       filenameRelative = filenameRelative.replace(sourceRootRegEx, "");
  325.     }
  326.  
  327.     // remove extension
  328.     filenameRelative = filenameRelative.replace(/\.(\w*?)$/, "");
  329.  
  330.     moduleName += filenameRelative;
  331.  
  332.     // normalize path separators
  333.     moduleName = moduleName.replace(/\\/g, "/");
  334.  
  335.     if (opts.getModuleId) {
  336.       // If return is falsy, assume they want us to use our generated default name
  337.       return opts.getModuleId(moduleName) || moduleName;
  338.     } else {
  339.       return moduleName;
  340.     }
  341.   };
  342.  
  343.   File.prototype.resolveModuleSource = function resolveModuleSource(source) {
  344.     var resolveModuleSource = this.opts.resolveModuleSource;
  345.     if (resolveModuleSource) source = resolveModuleSource(source, this.opts.filename);
  346.     return source;
  347.   };
  348.  
  349.   File.prototype.addImport = function addImport(source, imported) {
  350.     var name = arguments.length <= 2 || arguments[2] === undefined ? imported : arguments[2];
  351.  
  352.     var alias = source + ":" + imported;
  353.     var id = this.dynamicImportIds[alias];
  354.  
  355.     if (!id) {
  356.       source = this.resolveModuleSource(source);
  357.       id = this.dynamicImportIds[alias] = this.scope.generateUidIdentifier(name);
  358.  
  359.       var specifiers = [];
  360.  
  361.       if (imported === "*") {
  362.         specifiers.push(t.importNamespaceSpecifier(id));
  363.       } else if (imported === "default") {
  364.         specifiers.push(t.importDefaultSpecifier(id));
  365.       } else {
  366.         specifiers.push(t.importSpecifier(id, t.identifier(imported)));
  367.       }
  368.  
  369.       var declar = t.importDeclaration(specifiers, t.stringLiteral(source));
  370.       declar._blockHoist = 3;
  371.  
  372.       this.path.unshiftContainer("body", declar);
  373.     }
  374.  
  375.     return id;
  376.   };
  377.  
  378.   File.prototype.addHelper = function addHelper(name) {
  379.     var declar = this.declarations[name];
  380.     if (declar) return declar;
  381.  
  382.     if (!this.usedHelpers[name]) {
  383.       this.metadata.usedHelpers.push(name);
  384.       this.usedHelpers[name] = true;
  385.     }
  386.  
  387.     var generator = this.get("helperGenerator");
  388.     var runtime = this.get("helpersNamespace");
  389.     if (generator) {
  390.       var res = generator(name);
  391.       if (res) return res;
  392.     } else if (runtime) {
  393.       return t.memberExpression(runtime, t.identifier(name));
  394.     }
  395.  
  396.     var ref = (0, _babelHelpers2.default)(name);
  397.     var uid = this.declarations[name] = this.scope.generateUidIdentifier(name);
  398.  
  399.     if (t.isFunctionExpression(ref) && !ref.id) {
  400.       ref.body._compact = true;
  401.       ref._generated = true;
  402.       ref.id = uid;
  403.       ref.type = "FunctionDeclaration";
  404.       this.path.unshiftContainer("body", ref);
  405.     } else {
  406.       ref._compact = true;
  407.       this.scope.push({
  408.         id: uid,
  409.         init: ref,
  410.         unique: true
  411.       });
  412.     }
  413.  
  414.     return uid;
  415.   };
  416.  
  417.   File.prototype.addTemplateObject = function addTemplateObject(helperName, strings, raw) {
  418.     // Generate a unique name based on the string literals so we dedupe
  419.     // identical strings used in the program.
  420.     var stringIds = raw.elements.map(function (string) {
  421.       return string.value;
  422.     });
  423.     var name = helperName + "_" + raw.elements.length + "_" + stringIds.join(",");
  424.  
  425.     var declar = this.declarations[name];
  426.     if (declar) return declar;
  427.  
  428.     var uid = this.declarations[name] = this.scope.generateUidIdentifier("templateObject");
  429.  
  430.     var helperId = this.addHelper(helperName);
  431.     var init = t.callExpression(helperId, [strings, raw]);
  432.     init._compact = true;
  433.     this.scope.push({
  434.       id: uid,
  435.       init: init,
  436.       _blockHoist: 1.9 // This ensures that we don't fail if not using function expression helpers
  437.     });
  438.     return uid;
  439.   };
  440.  
  441.   File.prototype.buildCodeFrameError = function buildCodeFrameError(node, msg) {
  442.     var Error = arguments.length <= 2 || arguments[2] === undefined ? SyntaxError : arguments[2];
  443.  
  444.     var loc = node && (node.loc || node._loc);
  445.  
  446.     var err = new Error(msg);
  447.  
  448.     if (loc) {
  449.       err.loc = loc.start;
  450.     } else {
  451.       (0, _babelTraverse2.default)(node, errorVisitor, this.scope, err);
  452.  
  453.       err.message += " (This is an error on an internal node. Probably an internal error";
  454.  
  455.       if (err.loc) {
  456.         err.message += ". Location has been estimated.";
  457.       }
  458.  
  459.       err.message += ")";
  460.     }
  461.  
  462.     return err;
  463.   };
  464.  
  465.   File.prototype.mergeSourceMap = function mergeSourceMap(map) {
  466.     var inputMap = this.opts.inputSourceMap;
  467.  
  468.     if (inputMap) {
  469.       var _ret = function () {
  470.         var inputMapConsumer = new _sourceMap2.default.SourceMapConsumer(inputMap);
  471.         var outputMapConsumer = new _sourceMap2.default.SourceMapConsumer(map);
  472.  
  473.         var mergedGenerator = new _sourceMap2.default.SourceMapGenerator({
  474.           file: inputMapConsumer.file,
  475.           sourceRoot: inputMapConsumer.sourceRoot
  476.         });
  477.  
  478.         // This assumes the output map always has a single source, since Babel always compiles a single source file to a
  479.         // single output file.
  480.         var source = outputMapConsumer.sources[0];
  481.  
  482.         inputMapConsumer.eachMapping(function (mapping) {
  483.           var generatedPosition = outputMapConsumer.generatedPositionFor({
  484.             line: mapping.generatedLine,
  485.             column: mapping.generatedColumn,
  486.             source: source
  487.           });
  488.           if (generatedPosition.column != null) {
  489.             mergedGenerator.addMapping({
  490.               source: mapping.source,
  491.  
  492.               original: mapping.source == null ? null : {
  493.                 line: mapping.originalLine,
  494.                 column: mapping.originalColumn
  495.               },
  496.  
  497.               generated: generatedPosition
  498.             });
  499.           }
  500.         });
  501.  
  502.         var mergedMap = mergedGenerator.toJSON();
  503.         inputMap.mappings = mergedMap.mappings;
  504.         return {
  505.           v: inputMap
  506.         };
  507.       }();
  508.  
  509.       if ((typeof _ret === "undefined" ? "undefined" : (0, _typeof3.default)(_ret)) === "object") return _ret.v;
  510.     } else {
  511.       return map;
  512.     }
  513.   };
  514.  
  515.   File.prototype.parse = function parse(code) {
  516.     this.log.debug("Parse start");
  517.     var ast = (0, _babylon.parse)(code, this.parserOpts);
  518.     this.log.debug("Parse stop");
  519.     return ast;
  520.   };
  521.  
  522.   File.prototype._addAst = function _addAst(ast) {
  523.     this.path = _babelTraverse.NodePath.get({
  524.       hub: this.hub,
  525.       parentPath: null,
  526.       parent: ast,
  527.       container: ast,
  528.       key: "program"
  529.     }).setContext();
  530.     this.scope = this.path.scope;
  531.     this.ast = ast;
  532.     this.getMetadata();
  533.   };
  534.  
  535.   File.prototype.addAst = function addAst(ast) {
  536.     this.log.debug("Start set AST");
  537.     this._addAst(ast);
  538.     this.log.debug("End set AST");
  539.   };
  540.  
  541.   File.prototype.transform = function transform() {
  542.     // In the "pass per preset" mode, we have grouped passes.
  543.     // Otherwise, there is only one plain pluginPasses array.
  544.     for (var i = 0; i < this.pluginPasses.length; i++) {
  545.       var pluginPasses = this.pluginPasses[i];
  546.       this.call("pre", pluginPasses);
  547.       this.log.debug("Start transform traverse");
  548.       (0, _babelTraverse2.default)(this.ast, _babelTraverse2.default.visitors.merge(this.pluginVisitors[i], pluginPasses), this.scope);
  549.       this.log.debug("End transform traverse");
  550.       this.call("post", pluginPasses);
  551.     }
  552.  
  553.     return this.generate();
  554.   };
  555.  
  556.   File.prototype.wrap = function wrap(code, callback) {
  557.     code = code + "";
  558.  
  559.     try {
  560.       if (this.shouldIgnore()) {
  561.         return this.makeResult({ code: code, ignored: true });
  562.       } else {
  563.         return callback();
  564.       }
  565.     } catch (err) {
  566.       if (err._babel) {
  567.         throw err;
  568.       } else {
  569.         err._babel = true;
  570.       }
  571.  
  572.       var message = err.message = this.opts.filename + ": " + err.message;
  573.  
  574.       var loc = err.loc;
  575.       if (loc) {
  576.         err.codeFrame = (0, _babelCodeFrame2.default)(code, loc.line, loc.column + 1, this.opts);
  577.         message += "\n" + err.codeFrame;
  578.       }
  579.  
  580.       if (process.browser) {
  581.         // chrome has it's own pretty stringifier which doesn't use the stack property
  582.         // https://github.com/babel/babel/issues/2175
  583.         err.message = message;
  584.       }
  585.  
  586.       if (err.stack) {
  587.         var newStack = err.stack.replace(err.message, message);
  588.         err.stack = newStack;
  589.       }
  590.  
  591.       throw err;
  592.     }
  593.   };
  594.  
  595.   File.prototype.addCode = function addCode(code) {
  596.     code = (code || "") + "";
  597.     code = this.parseInputSourceMap(code);
  598.     this.code = code;
  599.   };
  600.  
  601.   File.prototype.parseCode = function parseCode() {
  602.     this.parseShebang();
  603.     var ast = this.parse(this.code);
  604.     this.addAst(ast);
  605.   };
  606.  
  607.   File.prototype.shouldIgnore = function shouldIgnore() {
  608.     var opts = this.opts;
  609.     return util.shouldIgnore(opts.filename, opts.ignore, opts.only);
  610.   };
  611.  
  612.   File.prototype.call = function call(key, pluginPasses) {
  613.     for (var _iterator3 = pluginPasses, _isArray3 = Array.isArray(_iterator3), _i3 = 0, _iterator3 = _isArray3 ? _iterator3 : (0, _getIterator3.default)(_iterator3);;) {
  614.       var _ref3;
  615.  
  616.       if (_isArray3) {
  617.         if (_i3 >= _iterator3.length) break;
  618.         _ref3 = _iterator3[_i3++];
  619.       } else {
  620.         _i3 = _iterator3.next();
  621.         if (_i3.done) break;
  622.         _ref3 = _i3.value;
  623.       }
  624.  
  625.       var pass = _ref3;
  626.  
  627.       var plugin = pass.plugin;
  628.       var fn = plugin[key];
  629.       if (fn) fn.call(pass, this);
  630.     }
  631.   };
  632.  
  633.   File.prototype.parseInputSourceMap = function parseInputSourceMap(code) {
  634.     var opts = this.opts;
  635.  
  636.     if (opts.inputSourceMap !== false) {
  637.       var inputMap = _convertSourceMap2.default.fromSource(code);
  638.       if (inputMap) {
  639.         opts.inputSourceMap = inputMap.toObject();
  640.         code = _convertSourceMap2.default.removeComments(code);
  641.       }
  642.     }
  643.  
  644.     return code;
  645.   };
  646.  
  647.   File.prototype.parseShebang = function parseShebang() {
  648.     var shebangMatch = _shebangRegex2.default.exec(this.code);
  649.     if (shebangMatch) {
  650.       this.shebang = shebangMatch[0];
  651.       this.code = this.code.replace(_shebangRegex2.default, "");
  652.     }
  653.   };
  654.  
  655.   File.prototype.makeResult = function makeResult(_ref4) {
  656.     var code = _ref4.code;
  657.     var map = _ref4.map;
  658.     var ast = _ref4.ast;
  659.     var ignored = _ref4.ignored;
  660.  
  661.     var result = {
  662.       metadata: null,
  663.       options: this.opts,
  664.       ignored: !!ignored,
  665.       code: null,
  666.       ast: null,
  667.       map: map || null
  668.     };
  669.  
  670.     if (this.opts.code) {
  671.       result.code = code;
  672.     }
  673.  
  674.     if (this.opts.ast) {
  675.       result.ast = ast;
  676.     }
  677.  
  678.     if (this.opts.metadata) {
  679.       result.metadata = this.metadata;
  680.     }
  681.  
  682.     return result;
  683.   };
  684.  
  685.   File.prototype.generate = function generate() {
  686.     var opts = this.opts;
  687.     var ast = this.ast;
  688.  
  689.     var result = { ast: ast };
  690.     if (!opts.code) return this.makeResult(result);
  691.  
  692.     this.log.debug("Generation start");
  693.  
  694.     var _result = (0, _babelGenerator2.default)(ast, opts, this.code);
  695.     result.code = _result.code;
  696.     result.map = _result.map;
  697.  
  698.     this.log.debug("Generation end");
  699.  
  700.     if (this.shebang) {
  701.       // add back shebang
  702.       result.code = this.shebang + "\n" + result.code;
  703.     }
  704.  
  705.     if (result.map) {
  706.       result.map = this.mergeSourceMap(result.map);
  707.     }
  708.  
  709.     if (opts.sourceMaps === "inline" || opts.sourceMaps === "both") {
  710.       result.code += "\n" + _convertSourceMap2.default.fromObject(result.map).toComment();
  711.     }
  712.  
  713.     if (opts.sourceMaps === "inline") {
  714.       result.map = null;
  715.     }
  716.  
  717.     return this.makeResult(result);
  718.   };
  719.  
  720.   return File;
  721. }(_store2.default);
  722.  
  723. exports.default = File;
  724. exports.File = File;
downloadindex.js Source code - Download reactide Source code
Related Source Codes/Software:
rkt - rkt is a pod-native container engine for Linux. It... 2017-06-11
uWebSockets - Tiny WebSockets https://for... 2017-06-11
realworld - TodoMVC for the RealWorld - Exemplary fullstack Me... 2017-06-11
goreplay - GoReplay is an open-source tool for capturing and ... 2017-06-10
pyenv - Simple Python version management 2017-06-10
postal - 2017-06-11
CRYENGINE - CRYENGINE is a powerful real-time game development... 2017-06-11
reactide - Reactide is the first dedicated IDE for React web ... 2017-06-11
redux-saga - An alternative side effect model for Redux apps ... 2017-06-10
angular-starter - 2017-06-10

 Back to top