MCPcopy
hub / github.com/webpack/webpack / insertCharacters

Function insertCharacters

lib/html/syntax.js:4816–4845  ·  view source on GitHub ↗
(
		/** @type {string} */ data,
		/** @type {number} */ start,
		/** @type {number} */ end
	)

Source from the content-addressed store, hash-verified

4814 };
4815
4816 const insertCharacters = (
4817 /** @type {string} */ data,
4818 /** @type {number} */ start,
4819 /** @type {number} */ end
4820 ) => {
4821 const place = appropriatePlace();
4822 if (place.parent.type === NodeType.Document) return; // never insert text into document
4823 // Inlined text insert: when the run merges into the adjacent text sibling
4824 // (common with inline formatting) only the string is appended — no
4825 // throwaway text node is allocated. Mirrors `insertAtPlace`/`appendTo`,
4826 // including that the before-node merge does not bump `end`.
4827 const arr = childrenOf(place.parent);
4828 if (place.beforeNode) {
4829 const idx = arr.indexOf(place.beforeNode);
4830 const prev = idx > 0 ? arr[idx - 1] : undefined;
4831 if (prev && prev.type === NodeType.Text) {
4832 prev.data += data;
4833 return;
4834 }
4835 arr.splice(idx, 0, { type: NodeType.Text, data, start, end });
4836 } else {
4837 const last = arr[arr.length - 1];
4838 if (last && last.type === NodeType.Text) {
4839 last.data += data;
4840 last.end = end;
4841 return;
4842 }
4843 arr.push({ type: NodeType.Text, data, start, end });
4844 }
4845 };
4846
4847 /**
4848 * @param {string} data comment data

Callers 3

leadingWsFunction · 0.85
foreignContentFunction · 0.85
buildHtmlAstFunction · 0.85

Calls 3

appropriatePlaceFunction · 0.85
childrenOfFunction · 0.85
pushMethod · 0.45

Tested by

no test coverage detected