MCPcopy
hub / github.com/prettier/prettier / mergeSimpleElementIntoText

Function mergeSimpleElementIntoText

src/language-html/print-preprocess.js:141–185  ·  view source on GitHub ↗
(ast /* , options */)

Source from the content-addressed store, hash-verified

139}
140
141function mergeSimpleElementIntoText(ast /* , options */) {
142 const isSimpleElement = (node) =>
143 node.kind === "element" &&
144 node.attrs.length === 0 &&
145 !isNonEmptyArray(node.startTagComments) &&
146 node.children.length === 1 &&
147 node.firstChild.kind === "text" &&
148 !htmlWhitespace.hasWhitespaceCharacter(node.children[0].value) &&
149 !node.firstChild.hasLeadingSpaces &&
150 !node.firstChild.hasTrailingSpaces &&
151 node.isLeadingSpaceSensitive &&
152 !node.hasLeadingSpaces &&
153 node.isTrailingSpaceSensitive &&
154 !node.hasTrailingSpaces &&
155 node.prev?.kind === "text" &&
156 node.next?.kind === "text";
157 ast.walk((node) => {
158 if (node.children) {
159 for (let i = 0; i < node.children.length; i++) {
160 const child = node.children[i];
161 if (!isSimpleElement(child)) {
162 continue;
163 }
164
165 const prevChild = child.prev;
166 const nextChild = child.next;
167 prevChild.value +=
168 `<${child.rawName}>` +
169 child.firstChild.value +
170 `</${child.rawName}>` +
171 nextChild.value;
172 prevChild.sourceSpan = new ParseSourceSpan(
173 prevChild.sourceSpan.start,
174 nextChild.sourceSpan.end,
175 );
176 prevChild.isTrailingSpaceSensitive = nextChild.isTrailingSpaceSensitive;
177 prevChild.hasTrailingSpaces = nextChild.hasTrailingSpaces;
178
179 node.removeChild(child);
180 i--; // because a node was removed
181 node.removeChild(nextChild);
182 }
183 }
184 });
185}
186
187function extractInterpolation(ast, options) {
188 if (options.parser === "html") {

Callers

nothing calls this directly

Calls 3

isSimpleElementFunction · 0.85
walkMethod · 0.80
removeChildMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…