MCPcopy
hub / github.com/webpack/webpack / adoptionAgency

Function adoptionAgency

lib/html/syntax.js:5376–5496  ·  view source on GitHub ↗
(
		/** @type {string} */ subject,
		/** @type {TagPos | null} */ pos
	)

Source from the content-addressed store, hash-verified

5374
5375 // ---------- adoption agency algorithm ----------
5376 const adoptionAgency = (
5377 /** @type {string} */ subject,
5378 /** @type {TagPos | null} */ pos
5379 ) => {
5380 // step 1
5381 const c = cur();
5382 if (
5383 c.namespace === NS_HTML &&
5384 c.tagName === subject &&
5385 !afe.some((e) => !e.marker && e.element === c)
5386 ) {
5387 open.pop();
5388 return true;
5389 }
5390 let outer = 0;
5391 while (outer < 8) {
5392 outer++;
5393 // find formatting element
5394 let fmtIdx = -1;
5395 for (let i = afe.length - 1; i >= 0; i--) {
5396 if (afe[i].marker) break;
5397 if (
5398 afeEl(afe[i]).tagName === subject &&
5399 afeEl(afe[i]).namespace === NS_HTML
5400 ) {
5401 fmtIdx = i;
5402 break;
5403 }
5404 }
5405 if (fmtIdx === -1) return false; // act as any other end tag
5406 const fmt = afeEl(afe[fmtIdx]);
5407 const openIdx = open.indexOf(fmt);
5408 if (openIdx === -1) {
5409 afe.splice(fmtIdx, 1);
5410 return true;
5411 }
5412 if (!inScopeEl(fmt)) return true; // parse error, ignore
5413 // step: furthest block
5414 let furthestIdx = -1;
5415 for (let i = openIdx + 1; i < open.length; i++) {
5416 if (isSpecial(open[i])) {
5417 furthestIdx = i;
5418 break;
5419 }
5420 }
5421 if (furthestIdx === -1) {
5422 while (open.length > openIdx) open.pop();
5423 afe.splice(fmtIdx, 1);
5424 return true;
5425 }
5426 const furthest = open[furthestIdx];
5427 const commonAncestor = open[openIdx - 1];
5428 let bookmark = fmtIdx;
5429 let node = furthest;
5430 let lastNode = furthest;
5431 let nodeIdx = furthestIdx;
5432 let inner = 0;
5433 while (true) {

Callers 2

startTagInBodyFunction · 0.85
endTagInBodyFunction · 0.85

Calls 11

curFunction · 0.85
afeElFunction · 0.85
inScopeElFunction · 0.85
isSpecialFunction · 0.85
mkElFunction · 0.85
cloneAttrsFunction · 0.85
detachFunction · 0.85
appendToFunction · 0.85
placeForCommonAncestorFunction · 0.85
insertAtPlaceFunction · 0.85
popMethod · 0.80

Tested by

no test coverage detected