diff --git a/index.js b/index.js index 9874a2473..b455bba18 100644 --- a/index.js +++ b/index.js @@ -56,6 +56,14 @@ function attachComments(text, ast, opts) { } function ensureAllCommentsPrinted(astComments) { + for (let i = 0; i < astComments.length; ++i) { + if (astComments[i].value.trim() === "prettier-ignore") { + // If there's a prettier-ignore, we're not printing that sub-tree so we + // don't know if the comments was printed or not. + return; + } + } + astComments.forEach(comment => { if (!comment.printed) { throw new Error( diff --git a/src/printer.js b/src/printer.js index 9199efe36..991c1862b 100644 --- a/src/printer.js +++ b/src/printer.js @@ -53,6 +53,17 @@ function genericPrint(path, options, printPath, args) { assert.ok(path instanceof FastPath); var node = path.getValue(); + + // Escape hatch + if ( + node && + node.comments && + node.comments.length > 0 && + node.comments.some(comment => comment.value.trim() === "prettier-ignore") + ) { + return options.originalText.slice(util.locStart(node), util.locEnd(node)); + } + var parts = []; var needsParens = false; var linesWithoutParens = genericPrintNoParens(path, options, printPath, args); @@ -61,15 +72,6 @@ function genericPrint(path, options, printPath, args) { return linesWithoutParens; } - // Escape hatch - if ( - node.comments && - node.comments.length > 0 && - node.comments.some(comment => comment.value.trim() === "prettier-ignore") - ) { - return options.originalText.slice(util.locStart(node), util.locEnd(node)); - } - if ( node.decorators && node.decorators.length > 0 &&