diff --git a/src/print/index.ts b/src/print/index.ts index 4d2ab62d..6651aa0f 100644 --- a/src/print/index.ts +++ b/src/print/index.ts @@ -33,6 +33,9 @@ import { trimTextNodeRight, canOmitSoftlineBeforeClosingTag, getNextNode, + isIgnoreStartDirective, + isIgnoreEndDirective, + isNodeTopLevelHTML, } from './node-helpers'; import { ASTNode, @@ -71,6 +74,7 @@ declare module 'prettier' { } let ignoreNext = false; +let ignoreRange = false; let svelteOptionsDoc: Doc | undefined; function groupConcat(contents: doc.builders.Doc[]): doc.builders.Doc { @@ -95,8 +99,13 @@ export function print(path: FastPath, options: ParserOptions, print: PrintFn): D ]; const node = n as Node; - if (ignoreNext && (node.type !== 'Text' || !isEmptyTextNode(node))) { - ignoreNext = false; + if ( + (ignoreNext || (ignoreRange && !isIgnoreEndDirective(node))) && + (node.type !== 'Text' || !isEmptyTextNode(node)) + ) { + if (ignoreNext) { + ignoreNext = false; + } return concat( flatten( options.originalText @@ -578,14 +587,16 @@ export function print(path: FastPath, options: ParserOptions, print: PrintFn): D case 'Comment': { const nodeAfterComment = getNextNode(path); - /** - * If there is no sibling node that starts right after us but the parent indicates - * that there used to be, that means that node was actually an embedded `