diff --git a/src/document/builders.js b/src/document/builders.js index 36d062329..33132d644 100644 --- a/src/document/builders.js +++ b/src/document/builders.js @@ -208,7 +208,7 @@ const softline = { type: DOC_TYPE_LINE, soft: true }; const hardline = [hardlineWithoutBreakParent, breakParent]; const literalline = [literallineWithoutBreakParent, breakParent]; -const cursor = { type: DOC_TYPE_CURSOR, placeholder: Symbol("cursor") }; +const cursor = { type: DOC_TYPE_CURSOR }; /** * @param {Doc} sep diff --git a/src/document/printer.js b/src/document/printer.js index 534d4c73a..6a9b09b77 100644 --- a/src/document/printer.js +++ b/src/document/printer.js @@ -18,12 +18,7 @@ import { DOC_TYPE_LABEL, DOC_TYPE_BREAK_PARENT, } from "./constants.js"; -import { - fill, - cursor, - indent, - hardlineWithoutBreakParent, -} from "./builders.js"; +import { fill, indent, hardlineWithoutBreakParent } from "./builders.js"; import { getDocParts, getDocType } from "./utils.js"; import InvalidDocError from "./invalid-doc-error.js"; @@ -36,6 +31,8 @@ const MODE_BREAK = Symbol("MODE_BREAK"); /** @type {unique symbol} */ const MODE_FLAT = Symbol("MODE_FLAT"); +const CURSOR_PLACEHOLDER = Symbol("cursor"); + function rootIndent() { return { value: "", length: 0, queue: [] }; } @@ -316,7 +313,7 @@ function printDocToString(doc, options) { } case DOC_TYPE_CURSOR: - out.push(cursor.placeholder); + out.push(CURSOR_PLACEHOLDER); break; case DOC_TYPE_INDENT: @@ -605,10 +602,10 @@ function printDocToString(doc, options) { } } - const cursorPlaceholderIndex = out.indexOf(cursor.placeholder); + const cursorPlaceholderIndex = out.indexOf(CURSOR_PLACEHOLDER); if (cursorPlaceholderIndex !== -1) { const otherCursorPlaceholderIndex = out.indexOf( - cursor.placeholder, + CURSOR_PLACEHOLDER, cursorPlaceholderIndex + 1 ); const beforeCursor = out.slice(0, cursorPlaceholderIndex).join("");