MCPcopy
hub / github.com/DHTMLX/gantt / findFatArrow

Function findFatArrow

samples/common/codehighlight/javascript.js:185–218  ·  view source on GitHub ↗
(stream, state)

Source from the content-addressed store, hash-verified

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

Callers 3

arrowBodyFunction · 0.85
arrowBodyNoCommaFunction · 0.85
javascript.jsFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected