MCPcopy
hub / github.com/jestjs/jest / dedentMarkup

Function dedentMarkup

packages/jest-snapshot/src/dedentLines.ts:80–123  ·  view source on GitHub ↗
(input: Array<string>, output: Array<string>)

Source from the content-addressed store, hash-verified

78// * text has more than one adjacent line
79// * markup does not close
80const dedentMarkup = (input: Array<string>, output: Array<string>): boolean => {
81 let line = input[output.length];
82
83 if (!dedentStartTag(input, output)) {
84 return false;
85 }
86
87 if (input[output.length - 1].includes('/>')) {
88 return true;
89 }
90
91 let isText = false;
92 const stack = [getIndentationLength(line)];
93
94 while (stack.length > 0 && output.length < input.length) {
95 line = input[output.length];
96
97 if (isFirstLineOfTag(line)) {
98 if (line.includes('</')) {
99 output.push(dedentLine(line));
100 stack.pop();
101 } else {
102 if (!dedentStartTag(input, output)) {
103 return false;
104 }
105
106 if (!input[output.length - 1].includes('/>')) {
107 stack.push(getIndentationLength(line));
108 }
109 }
110 isText = false;
111 } else {
112 if (isText) {
113 return false; // because text has more than one adjacent line
114 }
115
116 const indentationLengthOfTag = stack.at(-1)!;
117 output.push(line.slice(indentationLengthOfTag + 2));
118 isText = true;
119 }
120 }
121
122 return stack.length === 0;
123};
124
125// Return lines unindented by heuristic;
126// otherwise return null because:

Callers 2

dedentStartTagFunction · 0.85
dedentLinesFunction · 0.85

Calls 4

dedentStartTagFunction · 0.85
getIndentationLengthFunction · 0.85
isFirstLineOfTagFunction · 0.85
dedentLineFunction · 0.85

Tested by

no test coverage detected