diff options
Diffstat (limited to 'tools/node_modules/eslint/node_modules/@babel/generator/lib/printer.js')
-rw-r--r-- | tools/node_modules/eslint/node_modules/@babel/generator/lib/printer.js | 29 |
1 files changed, 15 insertions, 14 deletions
diff --git a/tools/node_modules/eslint/node_modules/@babel/generator/lib/printer.js b/tools/node_modules/eslint/node_modules/@babel/generator/lib/printer.js index 9b48449734..58a2954f78 100644 --- a/tools/node_modules/eslint/node_modules/@babel/generator/lib/printer.js +++ b/tools/node_modules/eslint/node_modules/@babel/generator/lib/printer.js @@ -70,12 +70,17 @@ class Printer { } this._noLineTerminator = false; } - rightBrace() { + rightBrace(node) { if (this.format.minified) { this._buf.removeLastSemicolon(); } + this.sourceWithOffset("end", node.loc, 0, -1); this.tokenChar(125); } + rightParens(node) { + this.sourceWithOffset("end", node.loc, 0, -1); + this.tokenChar(41); + } space(force = false) { if (this.format.compact) return; if (force) { @@ -270,10 +275,11 @@ class Printer { } } _catchUp(prop, loc) { + var _loc$prop; if (!this.format.retainLines) return; - const pos = loc ? loc[prop] : null; - if ((pos == null ? void 0 : pos.line) != null) { - const count = pos.line - this._buf.getCurrentLine(); + const line = loc == null ? void 0 : (_loc$prop = loc[prop]) == null ? void 0 : _loc$prop.line; + if (line != null) { + const count = line - this._buf.getCurrentLine(); for (let i = 0; i < count; i++) { this._newline(); } @@ -300,6 +306,7 @@ class Printer { } } print(node, parent, noLineTerminatorAfter, trailingCommentsLineOffset, forceParens) { + var _node$extra; if (!node) return; this._endsWithInnerRaw = false; const nodeType = node.type; @@ -316,14 +323,7 @@ class Printer { const oldInAux = this._insideAux; this._insideAux = node.loc == undefined; this._maybeAddAuxComment(this._insideAux && !oldInAux); - let shouldPrintParens = false; - if (forceParens) { - shouldPrintParens = true; - } else if (format.retainFunctionParens && nodeType === "FunctionExpression" && node.extra && node.extra.parenthesized) { - shouldPrintParens = true; - } else { - shouldPrintParens = needsParens(node, parent, this._printStack); - } + const shouldPrintParens = forceParens || format.retainFunctionParens && nodeType === "FunctionExpression" && ((_node$extra = node.extra) == null ? void 0 : _node$extra.parenthesized) || needsParens(node, parent, this._printStack); if (shouldPrintParens) { this.tokenChar(40); this._endsWithInnerRaw = false; @@ -471,8 +471,9 @@ class Printer { this.printJoin(items, parent, opts); } _printNewline(newLine, opts) { - if (this.format.retainLines || this.format.compact) return; - if (this.format.concise) { + const format = this.format; + if (format.retainLines || format.compact) return; + if (format.concise) { this.space(); return; } |