UNPKG

atom-nuclide

Version:

A unified developer experience for web and mobile development, built as a suite of features on top of Atom to provide hackability and the support of an active community.

52 lines (41 loc) 1.44 kB
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; } /* * Copyright (c) 2015-present, Facebook, Inc. * All rights reserved. * * This source code is licensed under the license found in the LICENSE file in * the root directory of this source tree. */ var _NewLine2; function _NewLine() { return _NewLine2 = _interopRequireDefault(require('./NewLine')); } function printRoot(root) { // Print the new source. var output = root.toSource({ quote: 'single', trailingComma: true }); // Remove all new lines between require fences that are not explicitly added // by the NewLine module. var lines = output.split('\n'); var first = lines.length - 1; var last = 0; for (var i = 0; i < lines.length; i++) { if (lines[i].indexOf((_NewLine2 || _NewLine()).default.literal) !== -1) { first = Math.min(first, i); last = Math.max(last, i); } } // Filter out the empty lines that are between NewLine markers. output = lines.filter(function (line, index) { return line || index < first || index > last; }).join('\n'); // Remove the NewLine markers. output = (_NewLine2 || _NewLine()).default.replace(output); // Remove new lines at the start. output = output.replace(/^\n{1,}/, ''); // Make sure there is a new line at the end. if (!/^[\w\W]*\n$/.test(output)) { output += '\n'; } return output; } module.exports = printRoot;