MCPcopy Create free account
hub / github.com/OpenEndedGroup/Field2 / findFatArrow

Function findFatArrow

lib/web/CodeMirror/mode/javascript/javascript.js:184–217  ·  view source on GitHub ↗
(stream, state)

Source from the content-addressed store, hash-verified

182 // arrow, and not declare the arguments as locals for the arrow
183 // body.
184 function findFatArrow(stream, state) {
185 if (state.fatArrowAt) state.fatArrowAt = null;
186 var arrow = stream.string.indexOf("=>", stream.start);
187 if (arrow < 0) return;
188
189 if (isTS) { // Try to skip TypeScript return type declarations after the arguments
190 var m = /:\s*(?:\w+(?:<[^>]*>|\[\])?|\{[^}]*\})\s*$/.exec(stream.string.slice(stream.start, arrow))
191 if (m) arrow = m.index
192 }
193
194 var depth = 0, sawSomething = false;
195 for (var pos = arrow - 1; pos >= 0; --pos) {
196 var ch = stream.string.charAt(pos);
197 var bracket = brackets.indexOf(ch);
198 if (bracket >= 0 && bracket < 3) {
199 if (!depth) { ++pos; break; }
200 if (--depth == 0) { if (ch == "(") sawSomething = true; break; }
201 } else if (bracket >= 3 && bracket < 6) {
202 ++depth;
203 } else if (wordRE.test(ch)) {
204 sawSomething = true;
205 } else if (/["'\/`]/.test(ch)) {
206 for (;; --pos) {
207 if (pos == 0) return
208 var next = stream.string.charAt(pos - 1)
209 if (next == ch && stream.string.charAt(pos - 2) != "\\") { pos--; break }
210 }
211 } else if (sawSomething && !depth) {
212 ++pos;
213 break;
214 }
215 }
216 if (sawSomething && !depth) state.fatArrowAt = pos;
217 }
218
219 // Parser
220

Callers 3

arrowBodyFunction · 0.85
arrowBodyNoCommaFunction · 0.85
javascript.jsFile · 0.85

Calls 3

indexOfMethod · 0.80
execMethod · 0.65
testMethod · 0.45

Tested by

no test coverage detected