printer.js 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.default = void 0;
  6. var _buffer = require("./buffer");
  7. var n = require("./node");
  8. var _t = require("@babel/types");
  9. var generatorFunctions = require("./generators");
  10. require("@jridgewell/trace-mapping");
  11. const {
  12. isFunction,
  13. isStatement,
  14. isClassBody,
  15. isTSInterfaceBody,
  16. isTSEnumDeclaration
  17. } = _t;
  18. const SCIENTIFIC_NOTATION = /e/i;
  19. const ZERO_DECIMAL_INTEGER = /\.0+$/;
  20. const NON_DECIMAL_LITERAL = /^0[box]/;
  21. const PURE_ANNOTATION_RE = /^\s*[@#]__PURE__\s*$/;
  22. const HAS_NEWLINE = /[\n\r\u2028\u2029]/;
  23. const HAS_BlOCK_COMMENT_END = /\*\//;
  24. const {
  25. needsParens
  26. } = n;
  27. class Printer {
  28. constructor(format, map) {
  29. this.inForStatementInitCounter = 0;
  30. this._printStack = [];
  31. this._indent = 0;
  32. this._indentChar = 0;
  33. this._indentRepeat = 0;
  34. this._insideAux = false;
  35. this._parenPushNewlineState = null;
  36. this._noLineTerminator = false;
  37. this._printAuxAfterOnNextUserNode = false;
  38. this._printedComments = new Set();
  39. this._endsWithInteger = false;
  40. this._endsWithWord = false;
  41. this._lastCommentLine = 0;
  42. this._endsWithInnerRaw = false;
  43. this._indentInnerComments = true;
  44. this.format = format;
  45. this._buf = new _buffer.default(map);
  46. this._indentChar = format.indent.style.charCodeAt(0);
  47. this._indentRepeat = format.indent.style.length;
  48. this._inputMap = map == null ? void 0 : map._inputMap;
  49. }
  50. generate(ast) {
  51. this.print(ast);
  52. this._maybeAddAuxComment();
  53. return this._buf.get();
  54. }
  55. indent() {
  56. if (this.format.compact || this.format.concise) return;
  57. this._indent++;
  58. }
  59. dedent() {
  60. if (this.format.compact || this.format.concise) return;
  61. this._indent--;
  62. }
  63. semicolon(force = false) {
  64. this._maybeAddAuxComment();
  65. if (force) {
  66. this._appendChar(59);
  67. } else {
  68. this._queue(59);
  69. }
  70. this._noLineTerminator = false;
  71. }
  72. rightBrace() {
  73. if (this.format.minified) {
  74. this._buf.removeLastSemicolon();
  75. }
  76. this.tokenChar(125);
  77. }
  78. space(force = false) {
  79. if (this.format.compact) return;
  80. if (force) {
  81. this._space();
  82. } else if (this._buf.hasContent()) {
  83. const lastCp = this.getLastChar();
  84. if (lastCp !== 32 && lastCp !== 10) {
  85. this._space();
  86. }
  87. }
  88. }
  89. word(str, noLineTerminatorAfter = false) {
  90. this._maybePrintInnerComments();
  91. if (this._endsWithWord || str.charCodeAt(0) === 47 && this.endsWith(47)) {
  92. this._space();
  93. }
  94. this._maybeAddAuxComment();
  95. this._append(str, false);
  96. this._endsWithWord = true;
  97. this._noLineTerminator = noLineTerminatorAfter;
  98. }
  99. number(str) {
  100. this.word(str);
  101. this._endsWithInteger = Number.isInteger(+str) && !NON_DECIMAL_LITERAL.test(str) && !SCIENTIFIC_NOTATION.test(str) && !ZERO_DECIMAL_INTEGER.test(str) && str.charCodeAt(str.length - 1) !== 46;
  102. }
  103. token(str, maybeNewline = false) {
  104. this._maybePrintInnerComments();
  105. const lastChar = this.getLastChar();
  106. const strFirst = str.charCodeAt(0);
  107. if (lastChar === 33 && str === "--" || strFirst === 43 && lastChar === 43 || strFirst === 45 && lastChar === 45 || strFirst === 46 && this._endsWithInteger) {
  108. this._space();
  109. }
  110. this._maybeAddAuxComment();
  111. this._append(str, maybeNewline);
  112. this._noLineTerminator = false;
  113. }
  114. tokenChar(char) {
  115. this._maybePrintInnerComments();
  116. const lastChar = this.getLastChar();
  117. if (char === 43 && lastChar === 43 || char === 45 && lastChar === 45 || char === 46 && this._endsWithInteger) {
  118. this._space();
  119. }
  120. this._maybeAddAuxComment();
  121. this._appendChar(char);
  122. this._noLineTerminator = false;
  123. }
  124. newline(i = 1, force) {
  125. if (i <= 0) return;
  126. if (!force) {
  127. if (this.format.retainLines || this.format.compact) return;
  128. if (this.format.concise) {
  129. this.space();
  130. return;
  131. }
  132. }
  133. if (i > 2) i = 2;
  134. i -= this._buf.getNewlineCount();
  135. for (let j = 0; j < i; j++) {
  136. this._newline();
  137. }
  138. return;
  139. }
  140. endsWith(char) {
  141. return this.getLastChar() === char;
  142. }
  143. getLastChar() {
  144. return this._buf.getLastChar();
  145. }
  146. endsWithCharAndNewline() {
  147. return this._buf.endsWithCharAndNewline();
  148. }
  149. removeTrailingNewline() {
  150. this._buf.removeTrailingNewline();
  151. }
  152. exactSource(loc, cb) {
  153. if (!loc) {
  154. cb();
  155. return;
  156. }
  157. this._catchUp("start", loc);
  158. this._buf.exactSource(loc, cb);
  159. }
  160. source(prop, loc) {
  161. if (!loc) return;
  162. this._catchUp(prop, loc);
  163. this._buf.source(prop, loc);
  164. }
  165. sourceWithOffset(prop, loc, lineOffset, columnOffset) {
  166. if (!loc) return;
  167. this._catchUp(prop, loc);
  168. this._buf.sourceWithOffset(prop, loc, lineOffset, columnOffset);
  169. }
  170. withSource(prop, loc, cb) {
  171. if (!loc) {
  172. cb();
  173. return;
  174. }
  175. this._catchUp(prop, loc);
  176. this._buf.withSource(prop, loc, cb);
  177. }
  178. sourceIdentifierName(identifierName, pos) {
  179. if (!this._buf._canMarkIdName) return;
  180. const sourcePosition = this._buf._sourcePosition;
  181. sourcePosition.identifierNamePos = pos;
  182. sourcePosition.identifierName = identifierName;
  183. }
  184. _space() {
  185. this._queue(32);
  186. }
  187. _newline() {
  188. this._queue(10);
  189. }
  190. _append(str, maybeNewline) {
  191. this._maybeAddParen(str);
  192. this._maybeIndent(str.charCodeAt(0));
  193. this._buf.append(str, maybeNewline);
  194. this._endsWithWord = false;
  195. this._endsWithInteger = false;
  196. }
  197. _appendChar(char) {
  198. this._maybeAddParenChar(char);
  199. this._maybeIndent(char);
  200. this._buf.appendChar(char);
  201. this._endsWithWord = false;
  202. this._endsWithInteger = false;
  203. }
  204. _queue(char) {
  205. this._maybeAddParenChar(char);
  206. this._maybeIndent(char);
  207. this._buf.queue(char);
  208. this._endsWithWord = false;
  209. this._endsWithInteger = false;
  210. }
  211. _maybeIndent(firstChar) {
  212. if (this._indent && firstChar !== 10 && this.endsWith(10)) {
  213. this._buf.queueIndentation(this._indentChar, this._getIndent());
  214. }
  215. }
  216. _shouldIndent(firstChar) {
  217. if (this._indent && firstChar !== 10 && this.endsWith(10)) {
  218. return true;
  219. }
  220. }
  221. _maybeAddParenChar(char) {
  222. const parenPushNewlineState = this._parenPushNewlineState;
  223. if (!parenPushNewlineState) return;
  224. if (char === 32) {
  225. return;
  226. }
  227. if (char !== 10) {
  228. this._parenPushNewlineState = null;
  229. return;
  230. }
  231. this.tokenChar(40);
  232. this.indent();
  233. parenPushNewlineState.printed = true;
  234. }
  235. _maybeAddParen(str) {
  236. const parenPushNewlineState = this._parenPushNewlineState;
  237. if (!parenPushNewlineState) return;
  238. const len = str.length;
  239. let i;
  240. for (i = 0; i < len && str.charCodeAt(i) === 32; i++) continue;
  241. if (i === len) {
  242. return;
  243. }
  244. const cha = str.charCodeAt(i);
  245. if (cha !== 10) {
  246. if (cha !== 47 || i + 1 === len) {
  247. this._parenPushNewlineState = null;
  248. return;
  249. }
  250. const chaPost = str.charCodeAt(i + 1);
  251. if (chaPost === 42) {
  252. if (PURE_ANNOTATION_RE.test(str.slice(i + 2, len - 2))) {
  253. return;
  254. }
  255. } else if (chaPost !== 47) {
  256. this._parenPushNewlineState = null;
  257. return;
  258. }
  259. }
  260. this.tokenChar(40);
  261. this.indent();
  262. parenPushNewlineState.printed = true;
  263. }
  264. catchUp(line) {
  265. if (!this.format.retainLines) return;
  266. const count = line - this._buf.getCurrentLine();
  267. for (let i = 0; i < count; i++) {
  268. this._newline();
  269. }
  270. }
  271. _catchUp(prop, loc) {
  272. if (!this.format.retainLines) return;
  273. const pos = loc ? loc[prop] : null;
  274. if ((pos == null ? void 0 : pos.line) != null) {
  275. const count = pos.line - this._buf.getCurrentLine();
  276. for (let i = 0; i < count; i++) {
  277. this._newline();
  278. }
  279. }
  280. }
  281. _getIndent() {
  282. return this._indentRepeat * this._indent;
  283. }
  284. printTerminatorless(node, parent, isLabel) {
  285. if (isLabel) {
  286. this._noLineTerminator = true;
  287. this.print(node, parent);
  288. } else {
  289. const terminatorState = {
  290. printed: false
  291. };
  292. this._parenPushNewlineState = terminatorState;
  293. this.print(node, parent);
  294. if (terminatorState.printed) {
  295. this.dedent();
  296. this.newline();
  297. this.tokenChar(41);
  298. }
  299. }
  300. }
  301. print(node, parent, noLineTerminatorAfter, trailingCommentsLineOffset, forceParens) {
  302. if (!node) return;
  303. this._endsWithInnerRaw = false;
  304. const nodeType = node.type;
  305. const format = this.format;
  306. const oldConcise = format.concise;
  307. if (node._compact) {
  308. format.concise = true;
  309. }
  310. const printMethod = this[nodeType];
  311. if (printMethod === undefined) {
  312. throw new ReferenceError(`unknown node of type ${JSON.stringify(nodeType)} with constructor ${JSON.stringify(node.constructor.name)}`);
  313. }
  314. this._printStack.push(node);
  315. const oldInAux = this._insideAux;
  316. this._insideAux = node.loc == undefined;
  317. this._maybeAddAuxComment(this._insideAux && !oldInAux);
  318. let shouldPrintParens = false;
  319. if (forceParens) {
  320. shouldPrintParens = true;
  321. } else if (format.retainFunctionParens && nodeType === "FunctionExpression" && node.extra && node.extra.parenthesized) {
  322. shouldPrintParens = true;
  323. } else {
  324. shouldPrintParens = needsParens(node, parent, this._printStack);
  325. }
  326. if (shouldPrintParens) {
  327. this.tokenChar(40);
  328. this._endsWithInnerRaw = false;
  329. }
  330. this._lastCommentLine = 0;
  331. this._printLeadingComments(node, parent);
  332. const loc = nodeType === "Program" || nodeType === "File" ? null : node.loc;
  333. this.exactSource(loc, printMethod.bind(this, node, parent));
  334. if (shouldPrintParens) {
  335. this._printTrailingComments(node, parent);
  336. this.tokenChar(41);
  337. this._noLineTerminator = noLineTerminatorAfter;
  338. } else if (noLineTerminatorAfter && !this._noLineTerminator) {
  339. this._noLineTerminator = true;
  340. this._printTrailingComments(node, parent);
  341. } else {
  342. this._printTrailingComments(node, parent, trailingCommentsLineOffset);
  343. }
  344. this._printStack.pop();
  345. format.concise = oldConcise;
  346. this._insideAux = oldInAux;
  347. this._endsWithInnerRaw = false;
  348. }
  349. _maybeAddAuxComment(enteredPositionlessNode) {
  350. if (enteredPositionlessNode) this._printAuxBeforeComment();
  351. if (!this._insideAux) this._printAuxAfterComment();
  352. }
  353. _printAuxBeforeComment() {
  354. if (this._printAuxAfterOnNextUserNode) return;
  355. this._printAuxAfterOnNextUserNode = true;
  356. const comment = this.format.auxiliaryCommentBefore;
  357. if (comment) {
  358. this._printComment({
  359. type: "CommentBlock",
  360. value: comment
  361. }, 0);
  362. }
  363. }
  364. _printAuxAfterComment() {
  365. if (!this._printAuxAfterOnNextUserNode) return;
  366. this._printAuxAfterOnNextUserNode = false;
  367. const comment = this.format.auxiliaryCommentAfter;
  368. if (comment) {
  369. this._printComment({
  370. type: "CommentBlock",
  371. value: comment
  372. }, 0);
  373. }
  374. }
  375. getPossibleRaw(node) {
  376. const extra = node.extra;
  377. if (extra && extra.raw != null && extra.rawValue != null && node.value === extra.rawValue) {
  378. return extra.raw;
  379. }
  380. }
  381. printJoin(nodes, parent, opts = {}) {
  382. if (!(nodes != null && nodes.length)) return;
  383. if (opts.indent) this.indent();
  384. const newlineOpts = {
  385. addNewlines: opts.addNewlines,
  386. nextNodeStartLine: 0
  387. };
  388. const separator = opts.separator ? opts.separator.bind(this) : null;
  389. const len = nodes.length;
  390. for (let i = 0; i < len; i++) {
  391. const node = nodes[i];
  392. if (!node) continue;
  393. if (opts.statement) this._printNewline(i === 0, newlineOpts);
  394. this.print(node, parent, undefined, opts.trailingCommentsLineOffset || 0);
  395. opts.iterator == null ? void 0 : opts.iterator(node, i);
  396. if (i < len - 1) separator == null ? void 0 : separator();
  397. if (opts.statement) {
  398. if (i + 1 === len) {
  399. this.newline(1);
  400. } else {
  401. var _nextNode$loc;
  402. const nextNode = nodes[i + 1];
  403. newlineOpts.nextNodeStartLine = ((_nextNode$loc = nextNode.loc) == null ? void 0 : _nextNode$loc.start.line) || 0;
  404. this._printNewline(true, newlineOpts);
  405. }
  406. }
  407. }
  408. if (opts.indent) this.dedent();
  409. }
  410. printAndIndentOnComments(node, parent) {
  411. const indent = node.leadingComments && node.leadingComments.length > 0;
  412. if (indent) this.indent();
  413. this.print(node, parent);
  414. if (indent) this.dedent();
  415. }
  416. printBlock(parent) {
  417. const node = parent.body;
  418. if (node.type !== "EmptyStatement") {
  419. this.space();
  420. }
  421. this.print(node, parent);
  422. }
  423. _printTrailingComments(node, parent, lineOffset) {
  424. const {
  425. innerComments,
  426. trailingComments
  427. } = node;
  428. if (innerComments != null && innerComments.length) {
  429. this._printComments(2, innerComments, node, parent, lineOffset);
  430. }
  431. if (trailingComments != null && trailingComments.length) {
  432. this._printComments(2, trailingComments, node, parent, lineOffset);
  433. }
  434. }
  435. _printLeadingComments(node, parent) {
  436. const comments = node.leadingComments;
  437. if (!(comments != null && comments.length)) return;
  438. this._printComments(0, comments, node, parent);
  439. }
  440. _maybePrintInnerComments() {
  441. if (this._endsWithInnerRaw) this.printInnerComments();
  442. this._endsWithInnerRaw = true;
  443. this._indentInnerComments = true;
  444. }
  445. printInnerComments() {
  446. const node = this._printStack[this._printStack.length - 1];
  447. const comments = node.innerComments;
  448. if (!(comments != null && comments.length)) return;
  449. const hasSpace = this.endsWith(32);
  450. const indent = this._indentInnerComments;
  451. const printedCommentsCount = this._printedComments.size;
  452. if (indent) this.indent();
  453. this._printComments(1, comments, node);
  454. if (hasSpace && printedCommentsCount !== this._printedComments.size) {
  455. this.space();
  456. }
  457. if (indent) this.dedent();
  458. }
  459. noIndentInnerCommentsHere() {
  460. this._indentInnerComments = false;
  461. }
  462. printSequence(nodes, parent, opts = {}) {
  463. opts.statement = true;
  464. this.printJoin(nodes, parent, opts);
  465. }
  466. printList(items, parent, opts = {}) {
  467. if (opts.separator == null) {
  468. opts.separator = commaSeparator;
  469. }
  470. this.printJoin(items, parent, opts);
  471. }
  472. _printNewline(newLine, opts) {
  473. if (this.format.retainLines || this.format.compact) return;
  474. if (this.format.concise) {
  475. this.space();
  476. return;
  477. }
  478. if (!newLine) {
  479. return;
  480. }
  481. const startLine = opts.nextNodeStartLine;
  482. const lastCommentLine = this._lastCommentLine;
  483. if (startLine > 0 && lastCommentLine > 0) {
  484. const offset = startLine - lastCommentLine;
  485. if (offset >= 0) {
  486. this.newline(offset || 1);
  487. return;
  488. }
  489. }
  490. if (this._buf.hasContent()) {
  491. this.newline(1);
  492. }
  493. }
  494. _shouldPrintComment(comment) {
  495. if (comment.ignore) return 0;
  496. if (this._printedComments.has(comment)) return 0;
  497. if (this._noLineTerminator && (HAS_NEWLINE.test(comment.value) || HAS_BlOCK_COMMENT_END.test(comment.value))) {
  498. return 2;
  499. }
  500. this._printedComments.add(comment);
  501. if (!this.format.shouldPrintComment(comment.value)) {
  502. return 0;
  503. }
  504. return 1;
  505. }
  506. _printComment(comment, skipNewLines) {
  507. const noLineTerminator = this._noLineTerminator;
  508. const isBlockComment = comment.type === "CommentBlock";
  509. const printNewLines = isBlockComment && skipNewLines !== 1 && !this._noLineTerminator;
  510. if (printNewLines && this._buf.hasContent() && skipNewLines !== 2) {
  511. this.newline(1);
  512. }
  513. const lastCharCode = this.getLastChar();
  514. if (lastCharCode !== 91 && lastCharCode !== 123) {
  515. this.space();
  516. }
  517. let val;
  518. if (isBlockComment) {
  519. val = `/*${comment.value}*/`;
  520. if (this.format.indent.adjustMultilineComment) {
  521. var _comment$loc;
  522. const offset = (_comment$loc = comment.loc) == null ? void 0 : _comment$loc.start.column;
  523. if (offset) {
  524. const newlineRegex = new RegExp("\\n\\s{1," + offset + "}", "g");
  525. val = val.replace(newlineRegex, "\n");
  526. }
  527. let indentSize = this.format.retainLines ? 0 : this._buf.getCurrentColumn();
  528. if (this._shouldIndent(47) || this.format.retainLines) {
  529. indentSize += this._getIndent();
  530. }
  531. val = val.replace(/\n(?!$)/g, `\n${" ".repeat(indentSize)}`);
  532. }
  533. } else if (!noLineTerminator) {
  534. val = `//${comment.value}`;
  535. } else {
  536. val = `/*${comment.value}*/`;
  537. }
  538. if (this.endsWith(47)) this._space();
  539. this.source("start", comment.loc);
  540. this._append(val, isBlockComment);
  541. if (!isBlockComment && !noLineTerminator) {
  542. this.newline(1, true);
  543. }
  544. if (printNewLines && skipNewLines !== 3) {
  545. this.newline(1);
  546. }
  547. }
  548. _printComments(type, comments, node, parent, lineOffset = 0) {
  549. const nodeLoc = node.loc;
  550. const len = comments.length;
  551. let hasLoc = !!nodeLoc;
  552. const nodeStartLine = hasLoc ? nodeLoc.start.line : 0;
  553. const nodeEndLine = hasLoc ? nodeLoc.end.line : 0;
  554. let lastLine = 0;
  555. let leadingCommentNewline = 0;
  556. const maybeNewline = this._noLineTerminator ? function () {} : this.newline.bind(this);
  557. for (let i = 0; i < len; i++) {
  558. const comment = comments[i];
  559. const shouldPrint = this._shouldPrintComment(comment);
  560. if (shouldPrint === 2) {
  561. hasLoc = false;
  562. break;
  563. }
  564. if (hasLoc && comment.loc && shouldPrint === 1) {
  565. const commentStartLine = comment.loc.start.line;
  566. const commentEndLine = comment.loc.end.line;
  567. if (type === 0) {
  568. let offset = 0;
  569. if (i === 0) {
  570. if (this._buf.hasContent() && (comment.type === "CommentLine" || commentStartLine != commentEndLine)) {
  571. offset = leadingCommentNewline = 1;
  572. }
  573. } else {
  574. offset = commentStartLine - lastLine;
  575. }
  576. lastLine = commentEndLine;
  577. maybeNewline(offset);
  578. this._printComment(comment, 1);
  579. if (i + 1 === len) {
  580. maybeNewline(Math.max(nodeStartLine - lastLine, leadingCommentNewline));
  581. lastLine = nodeStartLine;
  582. }
  583. } else if (type === 1) {
  584. const offset = commentStartLine - (i === 0 ? nodeStartLine : lastLine);
  585. lastLine = commentEndLine;
  586. maybeNewline(offset);
  587. this._printComment(comment, 1);
  588. if (i + 1 === len) {
  589. maybeNewline(Math.min(1, nodeEndLine - lastLine));
  590. lastLine = nodeEndLine;
  591. }
  592. } else {
  593. const offset = commentStartLine - (i === 0 ? nodeEndLine - lineOffset : lastLine);
  594. lastLine = commentEndLine;
  595. maybeNewline(offset);
  596. this._printComment(comment, 1);
  597. }
  598. } else {
  599. hasLoc = false;
  600. if (shouldPrint !== 1) {
  601. continue;
  602. }
  603. if (len === 1) {
  604. const singleLine = comment.loc ? comment.loc.start.line === comment.loc.end.line : !HAS_NEWLINE.test(comment.value);
  605. const shouldSkipNewline = singleLine && !isStatement(node) && !isClassBody(parent) && !isTSInterfaceBody(parent) && !isTSEnumDeclaration(parent);
  606. if (type === 0) {
  607. this._printComment(comment, shouldSkipNewline && node.type !== "ObjectExpression" || singleLine && isFunction(parent, {
  608. body: node
  609. }) ? 1 : 0);
  610. } else if (shouldSkipNewline && type === 2) {
  611. this._printComment(comment, 1);
  612. } else {
  613. this._printComment(comment, 0);
  614. }
  615. } else if (type === 1 && !(node.type === "ObjectExpression" && node.properties.length > 1) && node.type !== "ClassBody" && node.type !== "TSInterfaceBody") {
  616. this._printComment(comment, i === 0 ? 2 : i === len - 1 ? 3 : 0);
  617. } else {
  618. this._printComment(comment, 0);
  619. }
  620. }
  621. }
  622. if (type === 2 && hasLoc && lastLine) {
  623. this._lastCommentLine = lastLine;
  624. }
  625. }
  626. }
  627. Object.assign(Printer.prototype, generatorFunctions);
  628. {
  629. Printer.prototype.Noop = function Noop() {};
  630. }
  631. var _default = Printer;
  632. exports.default = _default;
  633. function commaSeparator() {
  634. this.tokenChar(44);
  635. this.space();
  636. }
  637. //# sourceMappingURL=printer.js.map