BVB Source Codes

prettier Show doc-debug.js Source code

Return Download prettier: download doc-debug.js Source code - Download prettier Source code - Type:.js
  1. "use strict";
  2.  
  3. function flattenDoc(doc) {
  4.   if (doc.type === "concat") {
  5.     const res = [];
  6.  
  7.     for (let i = 0; i < doc.parts.length; ++i) {
  8.       const doc2 = doc.parts[i];
  9.       if (typeof doc2 !== "string" && doc2.type === "concat") {
  10.         [].push.apply(res, flattenDoc(doc2).parts);
  11.       } else {
  12.         const flattened = flattenDoc(doc2);
  13.         if (flattened !== "") {
  14.           res.push(flattened);
  15.         }
  16.       }
  17.     }
  18.  
  19.     return Object.assign({}, doc, { parts: res });
  20.   } else if (doc.type === "if-break") {
  21.     return Object.assign({}, doc, {
  22.       breakContents: doc.breakContents != null
  23.         ? flattenDoc(doc.breakContents)
  24.         : null,
  25.       flatContents: doc.flatContents != null
  26.         ? flattenDoc(doc.flatContents)
  27.         : null
  28.     });
  29.   } else if (doc.type === "group") {
  30.     return Object.assign({}, doc, {
  31.       contents: flattenDoc(doc.contents),
  32.       expandedStates: doc.expandedStates
  33.         ? doc.expandedStates.map(flattenDoc)
  34.         : doc.expandedStates
  35.     });
  36.   } else if (doc.contents) {
  37.     return Object.assign({}, doc, { contents: flattenDoc(doc.contents) });
  38.   } else {
  39.     return doc;
  40.   }
  41. }
  42.  
  43. function printDoc(doc) {
  44.   if (typeof doc === "string") {
  45.     return JSON.stringify(doc);
  46.   }
  47.  
  48.   if (doc.type === "line") {
  49.     if (doc.literalline) {
  50.       return "literalline";
  51.     }
  52.     if (doc.hard) {
  53.       return "hardline";
  54.     }
  55.     if (doc.soft) {
  56.       return "softline";
  57.     }
  58.     return "line";
  59.   }
  60.  
  61.   if (doc.type === "break-parent") {
  62.     return "breakParent";
  63.   }
  64.  
  65.   if (doc.type === "concat") {
  66.     return "[" + doc.parts.map(printDoc).join(", ") + "]";
  67.   }
  68.  
  69.   if (doc.type === "indent") {
  70.     return "indent(" + printDoc(doc.contents) + ")";
  71.   }
  72.  
  73.   if (doc.type === "align") {
  74.     return "align(" + doc.n + ", " + printDoc(doc.contents) + ")";
  75.   }
  76.  
  77.   if (doc.type === "if-break") {
  78.     return (
  79.       "ifBreak(" +
  80.       printDoc(doc.breakContents) +
  81.       (doc.flatContents ? ", " + printDoc(doc.flatContents) : "") +
  82.       ")"
  83.     );
  84.   }
  85.  
  86.   if (doc.type === "group") {
  87.     if (doc.expandedStates) {
  88.       return (
  89.         "conditionalGroup(" +
  90.         "[" +
  91.         doc.expandedStates.map(printDoc).join(",") +
  92.         "])"
  93.       );
  94.     }
  95.  
  96.     return (
  97.       (doc.break ? "wrappedGroup" : "group") +
  98.       "(" +
  99.       printDoc(doc.contents) +
  100.       ")"
  101.     );
  102.   }
  103.  
  104.   if (doc.type === "fill") {
  105.     return "fill" + "(" + doc.parts.map(printDoc).join(", ") + ")";
  106.   }
  107.  
  108.   if (doc.type === "line-suffix") {
  109.     return "lineSuffix(" + printDoc(doc.contents) + ")";
  110.   }
  111.  
  112.   if (doc.type === "line-suffix-boundary") {
  113.     return "lineSuffixBoundary";
  114.   }
  115.  
  116.   throw new Error("Unknown doc type " + doc.type);
  117. }
  118.  
  119. module.exports = {
  120.   printDocToDebug: function(doc) {
  121.     return printDoc(flattenDoc(doc));
  122.   }
  123. };
  124.  
downloaddoc-debug.js Source code - Download prettier Source code
Related Source Codes/Software:
storybook - 2017-06-07
ionicons - The premium icon font for Ionic ... 2017-06-07
AsyncDisplayKit - Smooth asynchronous user interfaces for iOS apps. ... 2017-06-07
lottie-android - Render After Effects animations natively on Androi... 2017-06-07
parse-server - Parse-compatible API server module for Node/Expres... 2017-06-07
inferno - An extremely fast, React-like JavaScript library f... 2017-06-08
guetzli - Perceptual JPEG encoder 2017-06-08
cs-video-courses - List of Computer Science courses with video lectur... 2017-06-08
interviews - Everything you need to know to get the job. 2017-06-08
prepack - Prepack is a partial evaluator for JavaScript. Pre... 2017-06-08
CRYENGINE - CRYENGINE is a powerful real-time game development... 2017-06-11
postal - 2017-06-11
reactide - Reactide is the first dedicated IDE for React web ... 2017-06-11
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
redux-saga - An alternative side effect model for Redux apps ... 2017-06-10
angular-starter - 2017-06-10

 Back to top