MCPcopy Index your code
hub / github.com/nodejs/node / firstPhasePreProcess

Method firstPhasePreProcess

deps/minimatch/index.js:1427–1488  ·  view source on GitHub ↗
(globParts)

Source from the content-addressed store, hash-verified

1425 // **/*/<rest> -> */**/<rest> <== not valid because ** doesn't follow
1426 // this WOULD be allowed if ** did follow symlinks, or * didn't
1427 firstPhasePreProcess(globParts) {
1428 let didSomething = false;
1429 do {
1430 didSomething = false;
1431 for (let parts of globParts) {
1432 let gs = -1;
1433 while (-1 !== (gs = parts.indexOf("**", gs + 1))) {
1434 let gss = gs;
1435 while (parts[gss + 1] === "**") {
1436 gss++;
1437 }
1438 if (gss > gs) {
1439 parts.splice(gs + 1, gss - gs);
1440 }
1441 let next = parts[gs + 1];
1442 const p = parts[gs + 2];
1443 const p2 = parts[gs + 3];
1444 if (next !== "..")
1445 continue;
1446 if (!p || p === "." || p === ".." || !p2 || p2 === "." || p2 === "..") {
1447 continue;
1448 }
1449 didSomething = true;
1450 parts.splice(gs, 1);
1451 const other = parts.slice(0);
1452 other[gs] = "**";
1453 globParts.push(other);
1454 gs--;
1455 }
1456 if (!this.preserveMultipleSlashes) {
1457 for (let i = 1; i < parts.length - 1; i++) {
1458 const p = parts[i];
1459 if (i === 1 && p === "" && parts[0] === "")
1460 continue;
1461 if (p === "." || p === "") {
1462 didSomething = true;
1463 parts.splice(i, 1);
1464 i--;
1465 }
1466 }
1467 if (parts[0] === "." && parts.length === 2 && (parts[1] === "." || parts[1] === "")) {
1468 didSomething = true;
1469 parts.pop();
1470 }
1471 }
1472 let dd = 0;
1473 while (-1 !== (dd = parts.indexOf("..", dd + 1))) {
1474 const p = parts[dd - 1];
1475 if (p && p !== "." && p !== ".." && p !== "**") {
1476 didSomething = true;
1477 const needDot = dd === 1 && parts[dd + 1] === "**";
1478 const splin = needDot ? ["."] : [];
1479 parts.splice(dd - 1, 2, ...splin);
1480 if (parts.length === 0)
1481 parts.push("");
1482 dd -= 2;
1483 }
1484 }

Callers 1

preprocessMethod · 0.80

Calls 4

popMethod · 0.80
sliceMethod · 0.65
indexOfMethod · 0.45
pushMethod · 0.45

Tested by

no test coverage detected