MCPcopy
hub / github.com/webpack/webpack / appropriatePlace

Function appropriatePlace

lib/html/syntax.js:4734–4776  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

4732
4733 // "appropriate place for inserting a node"
4734 const appropriatePlace = () => {
4735 const target = cur();
4736 if (
4737 fosterParenting &&
4738 TABLE_CONTEXT.has(target.tagName) &&
4739 target.namespace === NS_HTML
4740 ) {
4741 // find last template / last table
4742 let lastTemplate = -1;
4743 let lastTable = -1;
4744 for (let i = open.length - 1; i >= 0; i--) {
4745 if (
4746 open[i].tagName === "template" &&
4747 open[i].namespace === NS_HTML &&
4748 lastTemplate === -1
4749 ) {
4750 lastTemplate = i;
4751 }
4752 if (
4753 open[i].tagName === "table" &&
4754 open[i].namespace === NS_HTML &&
4755 lastTable === -1
4756 ) {
4757 lastTable = i;
4758 }
4759 }
4760 if (
4761 lastTemplate !== -1 &&
4762 (lastTable === -1 || lastTemplate > lastTable)
4763 ) {
4764 return placeAt(open[lastTemplate], null);
4765 }
4766 if (lastTable === -1) {
4767 return placeAt(open[0], null);
4768 }
4769 const table = open[lastTable];
4770 // find table's parent in tree
4771 const tp = findParent(table);
4772 if (tp) return placeAt(tp, table);
4773 return placeAt(open[lastTable - 1], null);
4774 }
4775 return placeAt(target, null);
4776 };
4777
4778 const findParent = (/** @type {HtmlNode} */ node) => {
4779 // search the whole document tree for the parent of node

Callers 5

insertCharactersFunction · 0.85
insertCommentFunction · 0.85
insertHtmlElementFunction · 0.85
insertForeignElementFunction · 0.85
reconstructAfeFunction · 0.85

Calls 4

curFunction · 0.85
placeAtFunction · 0.85
findParentFunction · 0.85
hasMethod · 0.45

Tested by

no test coverage detected